28 #include <tqlistview.h>
30 #include <tqtextstream.h>
31 #include <tqmessagebox.h>
33 #include <tqtextedit.h>
34 #include <tqgroupbox.h>
35 #include <tqpushbutton.h>
38 #include <tdefiledialog.h>
39 #include <tdemessagebox.h>
40 #include <tdelocale.h>
41 #include <tdeapplication.h>
42 #include <kstatusbar.h>
44 #include <tdeabc/stdaddressbook.h>
47 #include "atcommand.h"
48 #include "commandscheduler.h"
50 #include "mobilegui.h"
51 #include "mobilegui.moc"
52 #include "mobilemain.h"
62 mToBeInserted =
false;
71 class SyncEntryKab :
public SyncEntry
74 SyncEntryKab(
bool on,
const TQString &index,
const TQString &name,
75 const TQString &phone )
84 mPhoneNumberIndex = -1;
91 TDEABC::Addressee mAddressee;
93 int mPhoneNumberIndex;
97 class SyncEntryMobile :
public SyncEntry
100 SyncEntryMobile(
bool on,
const TQString &index,
const TQString &phone,
101 const TQString &name )
104 mToBeDeleted =
false;
119 class SyncEntryCommon :
public SyncEntry
122 SyncEntryCommon(
bool on, SyncEntryKab *kabEntry,
123 SyncEntryMobile *mobileEntry )
126 mKabEntry = kabEntry;
127 mMobileEntry = mobileEntry;
130 SyncEntryKab *mKabEntry;
131 SyncEntryMobile *mMobileEntry;
140 mKabEntries.setAutoDelete(
true );
141 mMobileEntries.setAutoDelete(
true );
142 mCommonEntries.setAutoDelete(
true );
145 TQPtrList<SyncEntryKab> mKabEntries;
146 TQPtrList<SyncEntryMobile> mMobileEntries;
147 TQPtrList<SyncEntryCommon> mCommonEntries;
151 class PhoneBookItem :
public TQCheckListItem
154 PhoneBookItem( TQListView *v ) :
155 TQCheckListItem( v,
"", TQCheckListItem::CheckBox )
160 PhoneBookItem( TQListView *v, SyncEntry *syncEntry,
const TQString &name,
161 const TQString &phone,
const TQString &index ) :
162 TQCheckListItem( v, index, TQCheckListItem::CheckBox )
164 mSyncEntry = syncEntry;
171 SyncEntry *syncEntry() {
return mSyncEntry; }
174 SyncEntry *mSyncEntry;
185 MobileGui::MobileGui( CommandScheduler *scheduler, KandyPrefs *kprefs,
186 TQWidget* parent,
const char* name, WFlags fl ) :
187 DCOPObject(
"KandyIface" ), MobileGui_base( parent, name, fl )
190 mScheduler = scheduler;
191 mSyncer =
new AddressSyncer;
196 mMobManufacturer =
"";
201 mPBIndexOccupied.resize( 0,
false );
213 mComingFromToggleConnection =
false;
214 mComingFromReadPhonebook =
false;
215 mComingFromSyncPhonebooks =
false;
216 mComingFromExit =
false;
219 setKabState( UNLOADED );
220 setMobState( UNLOADED );
223 connect( mScheduler, TQ_SIGNAL( commandProcessed(
ATCommand * ) ),
224 TQ_SLOT( processResult(
ATCommand * ) ) );
225 connect( mScheduler->modem(), TQ_SIGNAL( gotLine(
const char * ) ),
226 TQ_SLOT( termAddOutput(
const char * ) ) );
230 MobileGui::~MobileGui()
236 void MobileGui::exit()
238 warnKabState( UNLOADED );
240 mComingFromExit =
true;
241 if ( !warnMobState( UNLOADED ) ) {
242 mComingFromExit =
false;
248 void MobileGui::readModelInformation()
251 mScheduler->executeId(
"+cgmi" );
252 mScheduler->executeId(
"+cgmm" );
253 mScheduler->executeId(
"+cgmr" );
254 mScheduler->executeId(
"+cgsn" );
258 cmd->setAutoDelete(
true );
259 mScheduler->execute( cmd );
263 cmd->setAutoDelete(
true );
264 cmd->addParameter(
new ATParameter(
"SM" ) );
265 mScheduler->execute( cmd );
268 mScheduler->executeId(
"+cpbr=?" );
269 mScheduler->executeId(
"+cpbs?" );
272 if ( (*mPrefs).autoSetClock() )
277 void MobileGui::readPhonebook()
279 if ( mMobState == LOADED )
282 mComingFromReadPhonebook =
true;
283 if ( !warnMobState( LOADED ) ) {
284 mComingFromReadPhonebook =
false;
288 cmd->setAutoDelete(
true );
289 cmd->addParameter(
new ATParameter( tmp.setNum( mPBStartIndex ) ) );
290 cmd->addParameter(
new ATParameter( tmp.setNum( mPBStartIndex +
293 mScheduler->execute( cmd );
295 emit statusMessage( i18n(
"Reading mobile phonebook..." ) );
300 void MobileGui::writePhonebook()
302 bool ModemCommandScheduled =
false;
305 if ( mMobState != MODIFIED )
308 PushButton12->setEnabled(
false );
316 for ( uint i = 0; i < mSyncer->mMobileEntries.count(); i++ ) {
317 SyncEntryMobile *entry = mSyncer->mMobileEntries.at( i );
320 if ( entry->mToBeDeleted )
321 if ( entry->mIndex.isEmpty() ) {
327 mSyncer->mMobileEntries.remove( i );
336 uint theIndex = entry->mIndex.toUInt();
337 mPBIndexOccupied[ theIndex - mPBStartIndex ] =
false;
346 for ( uint i = 0; i < mSyncer->mMobileEntries.count(); i++ ) {
347 SyncEntryMobile *entry = mSyncer->mMobileEntries.at( i );
353 if ( entry->mToBeUpdated || entry->mToBeInserted ) {
357 if ( entry->mToBeUpdated ) {
358 id =
"+cpbw=" + entry->mIndex;
360 int index = firstFreeIndex();
363 mPBIndexOccupied[ index ] =
true;
364 id =
"+cpbw=" + tmp.setNum( index + mPBStartIndex );
367 entry->mToBeUpdated =
false;
368 entry->mToBeInserted =
false;
371 cmd->setAutoDelete(
true );
372 cmd->addParameter(
new ATParameter( quote( entry->mPhone ) ) );
374 if ( entry->mPhone.left( 1 ) ==
"+" )
375 cmd->addParameter(
new ATParameter(
"145" ) );
377 cmd->addParameter(
new ATParameter(
"129" ) );
379 cmd->addParameter(
new ATParameter(
380 quote( string2GSM( entry->mName ) ) ) );
382 mScheduler->execute( cmd );
383 ModemCommandScheduled =
true;
395 for ( uint i = 0; i < mSyncer->mMobileEntries.count(); i++ ) {
396 SyncEntryMobile *entry = mSyncer->mMobileEntries.at( i );
399 if ( entry->mToBeDeleted ) {
400 uint theIndex = entry->mIndex.toUInt();
403 if ( !mPBIndexOccupied[ theIndex - mPBStartIndex ] ) {
406 TQString
id =
"+cpbw=" + entry->mIndex;
411 cmd->setAutoDelete(
true );
413 mScheduler->execute( cmd );
414 ModemCommandScheduled =
true;
418 mSyncer->mMobileEntries.remove( i );
423 if ( ModemCommandScheduled )
424 emit statusMessage( i18n(
"Writing mobile phonebook..." ) );
426 writePhonebookPostProcessing();
430 void MobileGui::writePhonebookPostProcessing()
433 emit transienStatusMessage( i18n(
"Wrote mobile phonebook." ) );
434 PushButton12->setEnabled(
true );
435 setMobState( LOADED );
438 if ( mComingFromToggleConnection ) {
439 mComingFromToggleConnection =
false;
442 if ( mComingFromReadPhonebook ) {
443 mComingFromReadPhonebook =
false;
447 cmd->setAutoDelete(
true );
448 cmd->addParameter(
new ATParameter( tmp.setNum( mPBStartIndex ) ) );
449 cmd->addParameter(
new ATParameter( tmp.setNum( mPBStartIndex +
452 mScheduler->execute( cmd );
454 emit statusMessage( i18n(
"Reading mobile phonebook..." ) );
456 if ( mComingFromExit ) {
457 mComingFromExit =
false;
463 void MobileGui::setClock()
465 char *timeStr =
new char[50];
466 TQString
id =
"+cclk=";
470 cmd->setAutoDelete(
true );
474 struct tm *theTime = localtime( &tloc );
475 strftime( timeStr, 50,
"%y/%m/%d,%T+00", theTime );
477 TQString Time = timeStr;
478 cmd->addParameter(
new ATParameter( quote( Time ) ) );
480 mScheduler->execute( cmd );
486 void MobileGui::readKabc()
488 if ( mKabState == LOADED )
491 warnKabState( LOADED );
493 emit statusMessage( i18n(
"Reading TDE address book..." ) );
495 mSyncer->mKabEntries.clear();
497 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self(
true );
498 TDEABC::AddressBook::Iterator it;
501 for ( it = addressBook->begin(); it != addressBook->end();
503 TQString index, name;
504 TDEABC::PhoneNumber phoneNumber;
505 TDEABC::PhoneNumber::List phoneNumbers = (*it).phoneNumbers();
506 TDEABC::PhoneNumber::List::Iterator it2;
507 int phoneNumberIndex = 0;
511 for ( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end();
512 it2++, phoneNumberIndex++ ) {
513 bool excludeNumber =
false;
514 phoneNumber = (*it2);
515 TQString phone = phoneNumber.number();
518 if ( (*mPrefs).excludeHome() &&
519 ( phoneNumber.type() & TDEABC::PhoneNumber::Home ) )
520 excludeNumber =
true;
521 if ( (*mPrefs).excludeWork() &&
522 ( phoneNumber.type() & TDEABC::PhoneNumber::Work ) )
523 excludeNumber =
true;
524 if ( (*mPrefs).excludeMessaging() &&
525 ( phoneNumber.type() & TDEABC::PhoneNumber::Msg ) )
526 excludeNumber =
true;
527 if ( (*mPrefs).excludeFax() &&
528 ( phoneNumber.type() & TDEABC::PhoneNumber::Fax ) )
529 excludeNumber =
true;
530 if ( (*mPrefs).excludeCell() &&
531 ( phoneNumber.type() & TDEABC::PhoneNumber::Cell ) )
532 excludeNumber =
true;
533 if ( (*mPrefs).excludeVideo() &&
534 ( phoneNumber.type() & TDEABC::PhoneNumber::Video ) )
535 excludeNumber =
true;
536 if ( (*mPrefs).excludeMailbox() &&
537 ( phoneNumber.type() & TDEABC::PhoneNumber::Bbs ) )
538 excludeNumber =
true;
539 if ( (*mPrefs).excludeModem() &&
540 ( phoneNumber.type() & TDEABC::PhoneNumber::Modem ) )
541 excludeNumber =
true;
542 if ( (*mPrefs).excludeCar() &&
543 ( phoneNumber.type() & TDEABC::PhoneNumber::Car ) )
544 excludeNumber =
true;
545 if ( (*mPrefs).excludeISDN() &&
546 ( phoneNumber.type() & TDEABC::PhoneNumber::Isdn ) )
547 excludeNumber =
true;
548 if ( (*mPrefs).excludePager() &&
549 ( phoneNumber.type() & TDEABC::PhoneNumber::Pager ) )
550 excludeNumber =
true;
552 if ( excludeNumber ==
false ) {
553 SyncEntryKab *kabEntry;
557 name = (*it).familyName();
559 TDEABC::AddressBook::Iterator it3;
560 TDEABC::Addressee::List tmp;
561 bool firstCharIsUnique =
true;
562 for ( it3 = addressBook->begin(); it3 != addressBook->end(); ++it3 )
563 if ( ( (*it3).familyName() == name ) && ( it3 != it ) ) {
564 tmp.append( (*it3) );
565 if ( (*it3).givenName()[0] == (*it).givenName()[0] )
566 firstCharIsUnique =
false;
572 if ( ( tmp.size() > 0 ) && !(*it).givenName().isEmpty() ) {
575 if ( firstCharIsUnique )
576 name += (*it).givenName()[0] +
".";
578 name += (*it).givenName();
582 if ( name.length() > mPBNameLength )
583 name = name.remove( mPBNameLength, name.length() - mPBNameLength );
586 if ( (*mPrefs).useHomeSuff() &&
587 ( phoneNumber.type() & TDEABC::PhoneNumber::Home ) )
588 formatPBName( &name, (*mPrefs).homeSuff() );
590 if ( (*mPrefs).useWorkSuff() &&
591 ( phoneNumber.type() & TDEABC::PhoneNumber::Work ) )
592 formatPBName( &name, (*mPrefs).workSuff() );
594 if ( (*mPrefs).useMessagingSuff() &&
595 ( phoneNumber.type() & TDEABC::PhoneNumber::Msg ) )
596 formatPBName( &name, (*mPrefs).messagingSuff() );
598 if ( (*mPrefs).useFaxSuff() &&
599 ( phoneNumber.type() & TDEABC::PhoneNumber::Fax ) )
600 formatPBName( &name, (*mPrefs).faxSuff() );
602 if ( (*mPrefs).useCellSuff() &&
603 ( phoneNumber.type() & TDEABC::PhoneNumber::Cell ) )
604 formatPBName( &name, (*mPrefs).cellSuff() );
606 if ( (*mPrefs).useVideoSuff() &&
607 ( phoneNumber.type() & TDEABC::PhoneNumber::Video ) )
608 formatPBName( &name, (*mPrefs).videoSuff() );
610 if ( (*mPrefs).useMailboxSuff() &&
611 ( phoneNumber.type() & TDEABC::PhoneNumber::Bbs ) )
612 formatPBName( &name, (*mPrefs).mailboxSuff() );
614 if ( (*mPrefs).useModemSuff() &&
615 ( phoneNumber.type() & TDEABC::PhoneNumber::Modem ) )
616 formatPBName( &name, (*mPrefs).modemSuff() );
618 if ( (*mPrefs).useCarSuff() &&
619 ( phoneNumber.type() & TDEABC::PhoneNumber::Car ) )
620 formatPBName( &name, (*mPrefs).carSuff() );
622 if ( (*mPrefs).useISDNSuff() &&
623 ( phoneNumber.type() & TDEABC::PhoneNumber::Isdn ) )
624 formatPBName( &name, (*mPrefs).iSDNSuff() );
626 if ( (*mPrefs).usePagerSuff() &&
627 ( phoneNumber.type() & TDEABC::PhoneNumber::Pager ) )
628 formatPBName( &name, (*mPrefs).pagerSuff() );
630 kabEntry =
new SyncEntryKab(
true, index, name, phone );
631 kabEntry->mKABindex = kabIndex;
632 kabEntry->mPhoneNumberIndex = phoneNumberIndex;
634 kabEntry->mAddressee = (*it);
635 mSyncer->mKabEntries.append( kabEntry );
643 emit transienStatusMessage( i18n(
"Read TDE address book." ) );
645 setKabState( LOADED );
649 TQString MobileGui::decodeSuffix(
const TQString &suffix )
651 TQString theSuffix = suffix;
656 if ( ( theSuffix.left( 1 ) ==
"\"" ) && ( theSuffix.right( 1 ) ==
"\"" ) ) {
658 char suffixNumber = (char) dequote( suffix ).toUInt( 0, 16 );
661 theSuffix = GSM2String( tmp );
668 void MobileGui::formatPBName( TQString *name, TQString suffix )
670 TQString theSuffix = decodeSuffix( suffix );
673 if ( name->length() + theSuffix.length() > mPBNameLength ) {
675 unsigned int toolong = name->length() + theSuffix.length() - mPBNameLength;
676 (*name) = name->remove( name->length() - toolong, toolong );
678 if ( name->length() + theSuffix.length() < mPBNameLength )
680 while ( name->length() + theSuffix.length() != mPBNameLength )
683 (*name) += theSuffix;
687 TQString MobileGui::stripWhiteSpaces(
const TQString &theString )
690 int len = theString.length();
693 for (
unsigned int i = 0; i < theString.length(); i++ )
694 if ( theString[ i ].latin1() ==
' ' ) {
703 for (
int i = theString.length() - 1; i >= 0; i-- )
704 if ( theString[ i ].latin1() ==
' ' )
709 return theString.mid( pos, len );
713 void MobileGui::writeKabc()
715 if ( mKabState != MODIFIED )
718 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self(
true );
719 TDEABC::Ticket *ticket = addressBook->requestSaveTicket();
722 kdDebug() <<
"Error! No ticket to save." << endl;
727 for ( uint i = 0; i < mSyncer->mKabEntries.count(); i++ ) {
728 SyncEntryKab *kabEntry = mSyncer->mKabEntries.at( i );
729 TQString phoneNumber = kabEntry->mPhone;
732 if ( kabEntry->mToBeUpdated ) {
734 TDEABC::AddressBook::Iterator it = addressBook->begin();
735 for (
int KABindex = 0; KABindex != kabEntry->mKABindex;
739 TDEABC::PhoneNumber::List phoneNumbers = (*it).phoneNumbers();
740 TDEABC::PhoneNumber::List::Iterator it2 = phoneNumbers.begin();
741 for (
int phoneNumberIndex = 0;
742 phoneNumberIndex != kabEntry->mPhoneNumberIndex;
743 it2++, phoneNumberIndex++ ) ;
745 (*it2).setNumber( phoneNumber );
746 (*it).insertPhoneNumber( (*it2) );
749 if ( kabEntry->mToBeInserted ) {
752 TDEABC::AddressBook::Iterator it;
753 bool equivalentEntryFound =
false;
754 TQString name = kabEntry->mName;
761 if ( goon && (*mPrefs).useHomeSuff() ) {
762 TQString theSuffix = decodeSuffix( (*mPrefs).homeSuff() );
763 if ( name.right( theSuffix.length() ) == theSuffix ) {
764 phoneType = TDEABC::PhoneNumber::Home;
765 name = stripWhiteSpaces(
766 name.left( name.length() - theSuffix.length() ) );
770 if ( goon && (*mPrefs).useWorkSuff() ) {
771 TQString theSuffix = decodeSuffix( (*mPrefs).workSuff() );
772 if ( name.right( theSuffix.length() ) == theSuffix ) {
773 phoneType = TDEABC::PhoneNumber::Work;
774 name = stripWhiteSpaces(
775 name.left( name.length() - theSuffix.length() ) );
779 if ( goon && (*mPrefs).useMessagingSuff() ) {
780 TQString theSuffix = decodeSuffix( (*mPrefs).messagingSuff() );
781 if ( name.right( theSuffix.length() ) == theSuffix ) {
782 phoneType = TDEABC::PhoneNumber::Msg;
783 name = stripWhiteSpaces(
784 name.left( name.length() - theSuffix.length() ) );
788 if ( goon && (*mPrefs).useFaxSuff() ) {
789 TQString theSuffix = decodeSuffix( (*mPrefs).faxSuff() );
790 if ( name.right( theSuffix.length() ) == theSuffix ) {
791 phoneType = TDEABC::PhoneNumber::Fax;
792 name = stripWhiteSpaces(
793 name.left( name.length() - theSuffix.length() ) );
797 if ( goon && (*mPrefs).useCellSuff() ) {
798 TQString theSuffix = decodeSuffix( (*mPrefs).cellSuff() );
799 if ( name.right( theSuffix.length() ) == theSuffix ) {
800 phoneType = TDEABC::PhoneNumber::Cell;
801 name = stripWhiteSpaces(
802 name.left( name.length() - theSuffix.length() ) );
806 if ( goon && (*mPrefs).useVideoSuff() ) {
807 TQString theSuffix = decodeSuffix( (*mPrefs).videoSuff() );
808 if ( name.right( theSuffix.length() ) == theSuffix ) {
809 phoneType = TDEABC::PhoneNumber::Video;
810 name = stripWhiteSpaces(
811 name.left( name.length() - theSuffix.length() ) );
815 if ( goon && (*mPrefs).useMailboxSuff() ) {
816 TQString theSuffix = decodeSuffix( (*mPrefs).mailboxSuff() );
817 if ( name.right( theSuffix.length() ) == theSuffix ) {
818 phoneType = TDEABC::PhoneNumber::Bbs;
819 name = stripWhiteSpaces(
820 name.left( name.length() - theSuffix.length() ) );
824 if ( goon && (*mPrefs).useModemSuff() ) {
825 TQString theSuffix = decodeSuffix( (*mPrefs).modemSuff() );
826 if ( name.right( theSuffix.length() ) == theSuffix ) {
827 phoneType = TDEABC::PhoneNumber::Modem;
828 name = stripWhiteSpaces(
829 name.left( name.length() - theSuffix.length() ) );
833 if ( goon && (*mPrefs).useCarSuff() ) {
834 TQString theSuffix = decodeSuffix( (*mPrefs).carSuff() );
835 if ( name.right( theSuffix.length() ) == theSuffix ) {
836 phoneType = TDEABC::PhoneNumber::Car;
837 name = stripWhiteSpaces(
838 name.left( name.length() - theSuffix.length() ) );
842 if ( goon && (*mPrefs).useISDNSuff() ) {
843 TQString theSuffix = decodeSuffix( (*mPrefs).iSDNSuff() );
844 if ( name.right( theSuffix.length() ) == theSuffix ) {
845 phoneType = TDEABC::PhoneNumber::Isdn;
846 name = stripWhiteSpaces(
847 name.left( name.length() - theSuffix.length() ) );
851 if ( goon && (*mPrefs).usePagerSuff() ) {
852 TQString theSuffix = decodeSuffix( (*mPrefs).pagerSuff() );
853 if ( name.right( theSuffix.length() ) == theSuffix ) {
854 phoneType = TDEABC::PhoneNumber::Pager;
855 name = stripWhiteSpaces(
856 name.left( name.length() - theSuffix.length() ) );
867 for ( it = addressBook->begin(); it != addressBook->end(); it++ ) {
868 TQString kabName = (*it).familyName();
869 TDEABC::AddressBook::Iterator it3;
870 TDEABC::Addressee::List tmp;
871 bool firstCharIsUnique =
true;
872 unsigned int minLength;
875 for ( it3 = addressBook->begin(); it3 != addressBook->end(); it3++ )
876 if ( ( (*it3).familyName() == kabName ) && ( it3 != it ) ) {
877 tmp.append( (*it3) );
878 if ( (*it3).givenName()[0] == (*it).givenName()[0] )
879 firstCharIsUnique =
false;
885 if ( ( tmp.size() > 0 ) && !(*it).givenName().isEmpty() ) {
888 if ( firstCharIsUnique )
889 kabName += (*it).givenName()[0] +
".";
891 kabName += (*it).givenName();
895 if ( kabName.length() > mPBNameLength )
896 kabName = kabName.remove( mPBNameLength,
897 kabName.length() - mPBNameLength );
899 minLength = kabName.length();
900 if ( name.length() < minLength )
901 minLength = name.length();
903 if ( name.left( minLength ) == kabName.left( minLength ) ) {
904 (*it).insertPhoneNumber( TDEABC::PhoneNumber( phoneNumber,
907 equivalentEntryFound =
true;
917 if ( !equivalentEntryFound ) {
918 TDEABC::Addressee entry;
919 TQStringList *fields =
new TQStringList;
922 *fields = TQStringList::split(
',', name );
924 if ( fields->count() > 1 ) {
927 TQString givenName =
"";
930 entry.setFamilyName( stripWhiteSpaces( (*fields)[ 0 ] ) );
932 for (
unsigned int i = 1; i < fields->count(); i++ )
933 givenName += stripWhiteSpaces( (*fields)[ i ] ) +
" ";
934 entry.setGivenName( stripWhiteSpaces( givenName ) );
937 entry.setFamilyName( stripWhiteSpaces( name ) );
939 entry.insertPhoneNumber( TDEABC::PhoneNumber( phoneNumber, phoneType ) );
941 addressBook->insertAddressee( entry );
945 kabEntry->mToBeUpdated =
false;
946 kabEntry->mToBeInserted =
false;
949 addressBook->save( ticket );
951 emit transienStatusMessage( i18n(
"Wrote TDE address book." ) );
953 setKabState( LOADED );
957 void MobileGui::refreshStatus()
959 mScheduler->executeId(
"+cbc" );
960 mScheduler->executeId(
"+csq" );
964 void MobileGui::processResult(
ATCommand *command )
966 if ( command->id() ==
"+cbc" )
967 mBatteryChargeLabel->setText( command->resultField( 1 ) +
" %" );
969 if ( command->id() ==
"+csq" )
970 mSignalQualityLabel->setText( command->resultField( 0 ) );
972 if ( command->id() ==
"+cgmi" ) {
973 mMobManufacturer = command->resultField( 0 );
974 mManufacturerLabel->setText( mMobManufacturer );
976 if ( command->id() ==
"+cgmm" ) {
977 mMobModel = command->resultField( 0 );
978 mModelLabel->setText( mMobModel );
980 if ( command->id() ==
"+cgmr" )
981 mGSMVersionLabel->setText( command->resultField( 0 ) );
983 if ( command->id() ==
"+cgsn" )
984 mSerialNumberLabel->setText( command->resultField( 0 ) );
986 if ( command->id() ==
"+cpbr=?" )
988 TQStringList tmpList = TQStringList::split(
"-", command->resultField( 0 ) );
989 TQString tmpString = tmpList.first().right( tmpList.first().length() - 1 );
990 mPBStartIndex = tmpString.toUInt();
991 mPBNameLength = command->resultField( 2 ).toUInt();
993 if ( command->id() ==
"+cpbs?" ) {
994 mPBLength = command->resultField( 2 ).toUInt();
997 mPBIndexOccupied.resize( mPBLength,
false );
998 for (
unsigned int i = 0; i < mPBLength; i++ )
999 mPBIndexOccupied[ i ] =
false;
1001 if ( command->id() ==
"+cpbr=" ) {
1002 fillPhonebook( command );
1004 if ( mComingFromSyncPhonebooks ) {
1005 mComingFromSyncPhonebooks =
false;
1009 if ( command->id() == mLastWriteId )
1010 writePhonebookPostProcessing();
1012 if ( command->id() ==
"+cpbs=?" ) {
1013 TQPtrList<TQStringList> *list = command->resultFields();
1014 TQStringList *fields = list->first();
1018 for (
unsigned int i = 0; i < fields->count(); i++ ) {
1019 TQString memory = dequote( (*fields)[ i ] );
1022 if ( memory ==
"FD" )
1025 if ( memory ==
"LD" )
1028 if ( memory ==
"ME" )
1031 if ( memory ==
"MT" )
1034 if ( memory ==
"TA" )
1037 if ( ( memory ==
"OW" ) ||
1038 ( ( memory ==
"ON" ) && ( mMobManufacturer ==
"SIEMENS" ) ) )
1041 if ( ( mMobManufacturer ==
"SIEMENS" ) && ( memory ==
"MC" ) )
1044 if ( ( mMobManufacturer ==
"SIEMENS" ) && ( memory ==
"RC" ) )
1048 fields = list->next();
1054 TQString MobileGui::noSpaces(
const TQString &theString )
1056 TQString result =
"";
1059 for (
unsigned int i = 0; i < theString.length(); i++ )
1060 if ( theString[ i ].latin1() !=
' ' )
1061 result += theString[ i ];
1067 int MobileGui::firstFreeIndex()
1072 if ( mPBIndexOccupied.capacity() == 0 )
1075 for ( i = 1; i < mPBLength; i++ )
1076 if ( !mPBIndexOccupied[ i ] )
1079 if ( i < mPBLength )
1086 TQString MobileGui::string2GSM(
const TQString &theString )
1088 TQString result =
"";
1091 for (
unsigned int i = 0; i < theString.length(); i++ )
1092 switch ( theString[ i ].latin1() ) {
1093 case 'Ä': result +=
'[';
break;
1094 case 'ä': result +=
'{';
break;
1095 case 'Ö': result += 92;
break;
1096 case 'ö': result +=
'|';
break;
1097 case 'Ü': result +=
'^';
break;
1098 case 'ü': result +=
'~';
break;
1099 case 'ß': result += 30;
break;
1100 case 'è': result += 4;
break;
1101 case 'é': result += 5;
break;
1103 default: result += theString[ i ];
1110 TQString MobileGui::GSM2String(
const TQString &theString )
1112 TQString result =
"";
1115 for (
unsigned int i = 0; i < theString.length(); i++ )
1116 switch ( theString[ i ].latin1() ) {
1117 case '[': result +=
'Ä';
break;
1118 case '{': result +=
'ä';
break;
1119 case 92: result +=
'Ö';
break;
1120 case '|': result +=
'ö';
break;
1121 case '^': result +=
'Ü';
break;
1122 case '~': result +=
'ü';
break;
1123 case 30: result +=
'ß';
break;
1124 case 4: result +=
'è';
break;
1125 case 5: result +=
'é';
break;
1127 default: result += theString[ i ];
1134 void MobileGui::fillPhonebook(
ATCommand *cmd )
1136 mSyncer->mMobileEntries.clear();
1138 TQPtrList<TQStringList> *list = cmd->resultFields();
1139 TQStringList *fields = list->first();
1142 if ( fields->count() != 4 )
1143 kdDebug() <<
"Error! Unexpected number of address fields." << endl;
1145 TQString index = (*fields)[0];
1146 TQString phone = (*fields)[1];
1147 TQString type = (*fields)[2];
1148 TQString name = GSM2String( (*fields)[3] );
1150 SyncEntryMobile *phoneEntry =
new SyncEntryMobile(
true, dequote( index ),
1153 mPBIndexOccupied[ index.toUInt() - mPBStartIndex ] =
true;
1154 mSyncer->mMobileEntries.append( phoneEntry );
1156 fields = list->next();
1162 emit transienStatusMessage(i18n(
"Read mobile phonebook."));
1163 emit phonebookRead();
1165 setMobState( LOADED );
1169 TQString MobileGui::quote(
const TQString &str )
1171 if ( ( str.left(1) ==
"\"" ) && ( str.right(1) ==
"\"" ) )
1174 return "\"" + str +
"\"";
1178 TQString MobileGui::dequote(
const TQString &str )
1181 int len = str.length();
1184 if ( str.left(1) ==
"\"" ) {
1189 if ( str.right(1) ==
"\"" )
1192 return str.mid( pos, len );
1196 void MobileGui::savePhonebook()
1198 if ( mMobState == UNLOADED )
1201 TQString fileName = KFileDialog::getSaveFileName(
"phonebook.csv" );
1202 TQFile outFile( fileName );
1204 if ( outFile.open( IO_WriteOnly ) ) {
1205 TQTextStream t( &outFile );
1207 for( uint i = 0; i < mSyncer->mMobileEntries.count(); i++) {
1208 SyncEntryMobile *e = mSyncer->mMobileEntries.at( i );
1211 if ( !e->mToBeDeleted )
1212 t << e->mIndex <<
"," << e->mPhone <<
"," << e->mName << endl;
1220 void MobileGui::deleteMobPhonebook()
1227 PhoneBookItem *item = (PhoneBookItem *) mMobileBook->firstChild();
1229 if ( item->isOn() ) {
1230 SyncEntryMobile *mobileItem = (SyncEntryMobile *) item->syncEntry();
1234 item->setOn(
false );
1235 mobileItem->mOn =
false;
1238 mobileItem->mToBeDeleted =
true;
1241 item = (PhoneBookItem *) item->nextSibling();
1246 setMobState( MODIFIED );
1250 void MobileGui::mergePhonebooks()
1259 PhoneBookItem *item = (PhoneBookItem *) mKabBook->firstChild();
1261 item->syncEntry()->mOn = item->isOn();
1262 item = (PhoneBookItem *) item->nextSibling();
1265 item = (PhoneBookItem *) mMobileBook->firstChild();
1267 item->syncEntry()->mOn = item->isOn();
1268 item = (PhoneBookItem *) item->nextSibling();
1271 mSyncer->mCommonEntries.clear();
1278 for ( i = 0; i < mSyncer->mKabEntries.count(); i++ )
1279 if ( mSyncer->mKabEntries.at( i )->mOn ) {
1280 mSyncer->mCommonEntries.append(
1281 new SyncEntryCommon(
true, mSyncer->mKabEntries.at( i ), 0 ) );
1282 mSyncer->mKabEntries.at( i )->mOn =
false;
1290 for ( i = 0; i < mSyncer->mMobileEntries.count(); i++ ) {
1291 SyncEntryMobile *mobileEntry = mSyncer->mMobileEntries.at( i );
1292 bool equivalentEntryFound =
false;
1296 if( !mobileEntry->mToBeDeleted )
1297 for ( j = 0; j < mSyncer->mCommonEntries.count(); j++ ) {
1298 SyncEntryCommon *theCommonEntry = mSyncer->mCommonEntries.at( j );
1301 if ( theCommonEntry->mKabEntry &&
1302 ( theCommonEntry->mKabEntry->mName == mobileEntry->mName ) ) {
1303 theCommonEntry->mMobileEntry = mobileEntry;
1304 equivalentEntryFound =
true;
1306 if ( noSpaces( theCommonEntry->mKabEntry->mPhone ) ==
1307 mobileEntry->mPhone ) {
1308 mobileEntry->mOn =
false;
1313 TQString text =
"<qt><b>" + i18n(
"Kab Entry:" ) +
"</b><br>";
1314 text +=
" " + theCommonEntry->mKabEntry->mName +
" " +
1315 theCommonEntry->mKabEntry->mPhone +
"<br>";
1316 text +=
"<b>" + i18n(
"Mobile Entry:" ) +
"</b><br>";
1317 text +=
" " + mobileEntry->mName +
" " + mobileEntry->mPhone;
1321 new TQMessageBox( i18n(
"Conflicting Entries" ), text,
1322 TQMessageBox::Warning, 1, 2, 0,
this );
1323 msg->setButtonText( 1, i18n(
"Use Kab Entry" ) );
1324 msg->setButtonText( 2, i18n(
"Use Mobile Entry" ) );
1326 switch ( msg->exec() ) {
1329 mobileEntry->mPhone = theCommonEntry->mKabEntry->mPhone;
1330 mobileEntry->mName = theCommonEntry->mKabEntry->mName;
1331 mobileEntry->mOn =
true;
1332 mobileEntry->mToBeUpdated =
true;
1334 setMobState( MODIFIED );
1339 theCommonEntry->mKabEntry->mPhone = mobileEntry->mPhone;
1340 theCommonEntry->mKabEntry->mName = mobileEntry->mName;
1341 theCommonEntry->mKabEntry->mOn =
true;
1342 theCommonEntry->mKabEntry->mToBeUpdated =
true;
1344 mobileEntry->mOn =
false;
1346 setKabState( MODIFIED );
1353 if ( !equivalentEntryFound && mobileEntry->mOn ) {
1355 mSyncer->mCommonEntries.append(
1356 new SyncEntryCommon(
true, 0, mobileEntry ) );
1357 mobileEntry->mOn =
false;
1366 for ( i = 0; i < mSyncer->mCommonEntries.count(); i++ ) {
1367 SyncEntryCommon *entry = mSyncer->mCommonEntries.at( i );
1368 SyncEntryKab *kabEntry = entry->mKabEntry;
1369 SyncEntryMobile *mobileEntry = entry->mMobileEntry;
1372 if ( kabEntry && !mobileEntry ) {
1374 entry->mMobileEntry =
new SyncEntryMobile(
true,
"", kabEntry->mPhone,
1376 entry->mMobileEntry->mToBeInserted =
true;
1377 mSyncer->mMobileEntries.append( entry->mMobileEntry );
1379 setMobState( MODIFIED );
1381 if ( mobileEntry && !kabEntry ) {
1383 entry->mKabEntry =
new SyncEntryKab(
true, mobileEntry->mIndex,
1385 mobileEntry->mPhone );
1386 entry->mKabEntry->mToBeInserted =
true;
1387 mSyncer->mKabEntries.append( entry->mKabEntry );
1389 setKabState( MODIFIED );
1401 emit transienStatusMessage( i18n(
"Synced phonebooks." ) );
1402 PushButton8_3->setEnabled(
true );
1406 void MobileGui::syncPhonebooks()
1408 PushButton8_3->setEnabled(
false );
1410 if ( mKabState == UNLOADED )
1412 if ( mMobState == UNLOADED ) {
1413 mComingFromSyncPhonebooks =
true;
1420 void MobileGui::updateKabBook()
1424 for ( uint i = 0; i < mSyncer->mKabEntries.count(); i++ ) {
1425 SyncEntryKab *kabEntry = mSyncer->mKabEntries.at( i );
1426 PhoneBookItem *item =
new PhoneBookItem( mKabBook, kabEntry,
1427 kabEntry->mName, kabEntry->mPhone,
1429 item->setOn( kabEntry->mOn );
1434 void MobileGui::updateMobileBook()
1436 mMobileBook->clear();
1438 for ( uint i = 0; i < mSyncer->mMobileEntries.count(); i++ ) {
1439 SyncEntryMobile *entry = mSyncer->mMobileEntries.at( i );
1441 if ( !entry->mToBeDeleted ) {
1442 PhoneBookItem *item =
new PhoneBookItem( mMobileBook, entry, entry->mName,
1443 entry->mPhone, entry->mIndex );
1444 item->setOn( entry->mOn );
1450 void MobileGui::toggleConnection()
1452 if ( mConnectButton->text() == i18n(
"Connect" ) ) {
1453 emit connectModem();
1455 readModelInformation();
1458 mConnectButton->setText( tr2i18n(
"Disconnect" ) );
1459 PushButton1->setEnabled(
true );
1460 PushButton5_3->setEnabled(
true );
1462 mABTab->setEnabled(
true );
1463 setKabState( UNLOADED );
1464 setMobState( UNLOADED );
1466 ((
MobileMain *) mparent)->statusBar()->changeItem( i18n(
" Connected "), 1 );
1468 warnKabState( UNLOADED );
1470 mComingFromToggleConnection =
true;
1471 if ( !warnMobState( UNLOADED ) ) {
1472 mComingFromToggleConnection =
false;
1479 void MobileGui::disconnectGUI()
1481 emit disconnectModem();
1483 mManufacturerLabel->setText(
"x" );
1484 mModelLabel->setText(
"x" );
1485 mGSMVersionLabel->setText(
"x" );
1486 mSerialNumberLabel->setText(
"x" );
1488 mBatteryChargeLabel->setText(
"xx %" );
1489 mSignalQualityLabel->setText(
"x" );
1491 mConnectButton->setText( tr2i18n(
"Connect" ) );
1492 PushButton1->setEnabled(
false );
1493 PushButton5_3->setEnabled(
false );
1496 mMobileBook->clear();
1497 setKabState( UNLOADED );
1498 setMobState( UNLOADED );
1500 mABTab->setEnabled(
false );
1511 mPBIndexOccupied.resize( 0,
false );
1513 ((
MobileMain *) mparent)->statusBar()->changeItem( i18n(
" Disconnected "),
1518 void MobileGui::termAddOutput(
const char *line )
1520 mTermIO->append( line );
1521 mTermIO->setCursorPosition( mTermIO->paragraphs() - 1, 0 );
1525 void MobileGui::setKabState( ABState newState )
1527 switch ( mKabState ) {
1529 groupBox3->setTitle( tr2i18n(
"TDE Address Book" ) );
1530 mReadKabButton->setEnabled(
true );
1531 PushButton8->setEnabled(
false );
1535 if ( newState == MODIFIED ) {
1536 groupBox3->setTitle( tr2i18n(
"TDE Address Book (modified)" ) );
1537 mReadKabButton->setEnabled(
true );
1538 PushButton8->setEnabled(
true );
1540 if ( newState == UNLOADED ) {
1541 groupBox3->setTitle( tr2i18n(
"TDE Address Book" ) );
1542 mReadKabButton->setEnabled(
true );
1543 PushButton8->setEnabled(
false );
1548 if ( newState != MODIFIED ) {
1549 groupBox3->setTitle( tr2i18n(
"TDE Address Book" ) );
1550 mReadKabButton->setEnabled(
true );
1551 PushButton8->setEnabled(
false );
1556 mKabState = newState;
1560 void MobileGui::warnKabState( ABState newState )
1562 if ( ( mKabState == MODIFIED ) && ( newState != MODIFIED ) ) {
1563 TQString text =
"<qt><b>" + i18n(
"Warning" ) +
"</b><br>";
1564 text += i18n(
"The TDE address book contains unsaved changes." ) +
1567 TQMessageBox *msg =
new TQMessageBox( i18n(
"Unsaved Changes" ), text,
1568 TQMessageBox::Critical, 1, 2, 0,
this );
1569 msg->setButtonText( 1, i18n(
"Save" ) );
1570 msg->setButtonText( 2, i18n(
"Discard" ) );
1572 switch ( msg->exec() ) {
1585 void MobileGui::setMobState( ABState newState )
1587 switch ( mMobState ) {
1589 if ( newState == UNLOADED ) {
1590 groupBox4->setTitle( tr2i18n(
"Mobile Phone Book" ) );
1591 PushButton3->setEnabled(
true );
1592 PushButton12->setEnabled(
false );
1593 PushButton4_2->setEnabled(
false );
1594 MobDeleteButton->setEnabled(
false );
1596 if ( newState == LOADED ) {
1597 groupBox4->setTitle( tr2i18n(
"Mobile Phone Book" ) );
1598 PushButton3->setEnabled(
true );
1599 PushButton12->setEnabled(
false );
1600 PushButton4_2->setEnabled(
true );
1601 MobDeleteButton->setEnabled(
true );
1606 if ( newState == MODIFIED ) {
1607 groupBox4->setTitle( tr2i18n(
"Mobile Phone Book (modified)" ) );
1608 PushButton3->setEnabled(
true );
1609 PushButton12->setEnabled(
true );
1610 PushButton4_2->setEnabled(
true );
1611 MobDeleteButton->setEnabled(
true );
1613 if ( newState == UNLOADED ) {
1614 groupBox4->setTitle( tr2i18n(
"Mobile Phone Book" ) );
1615 PushButton3->setEnabled(
true );
1616 PushButton12->setEnabled(
false );
1617 PushButton4_2->setEnabled(
false );
1618 MobDeleteButton->setEnabled(
false );
1623 if ( newState == UNLOADED ) {
1624 groupBox4->setTitle( tr2i18n(
"Mobile Phone Book" ) );
1625 PushButton3->setEnabled(
true );
1626 PushButton12->setEnabled(
false );
1627 PushButton4_2->setEnabled(
false );
1628 MobDeleteButton->setEnabled(
false );
1630 if ( newState == LOADED ) {
1631 groupBox4->setTitle( tr2i18n(
"Mobile Phone Book" ) );
1632 PushButton3->setEnabled(
true );
1633 PushButton12->setEnabled(
false );
1634 PushButton4_2->setEnabled(
true );
1635 MobDeleteButton->setEnabled(
true );
1640 mMobState = newState;
1644 bool MobileGui::warnMobState( ABState newState )
1646 if ( ( mMobState == MODIFIED ) && ( newState != MODIFIED ) )
1648 TQString text =
"<qt><b>" + i18n(
"Warning" ) +
"</b><br>";
1649 text += i18n(
"The mobile phone book contains unsaved changes." ) +
1652 TQMessageBox *msg =
new TQMessageBox( i18n(
"Unsaved Changes" ), text,
1653 TQMessageBox::Critical, 1, 2, 0,
this );
1654 msg->setButtonText( 1, i18n(
"Save" ) );
1655 msg->setButtonText( 2, i18n(
"Discard" ) );
1657 switch ( msg->exec() ) {
This class provides an abstraction of an AT command.
This class serves as the main window for MobileMain.