author | zautrix <zautrix> | 2005-03-18 17:56:55 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-18 17:56:55 (UTC) |
commit | d6438efc4c7cff39024b65bfd1d2f810212da544 (patch) (unidiff) | |
tree | badb4c48d83477dd1027af1807cb2b6ed09db52a | |
parent | f9f521c487143641b2cf077d04fe1c475001bce2 (diff) | |
download | kdepimpi-d6438efc4c7cff39024b65bfd1d2f810212da544.zip kdepimpi-d6438efc4c7cff39024b65bfd1d2f810212da544.tar.gz kdepimpi-d6438efc4c7cff39024b65bfd1d2f810212da544.tar.bz2 |
kde sync fixes
-rw-r--r-- | kde2file/abdump/main.cpp | 5 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 14 |
2 files changed, 16 insertions, 3 deletions
diff --git a/kde2file/abdump/main.cpp b/kde2file/abdump/main.cpp index 9ad78e5..b359cfe 100644 --- a/kde2file/abdump/main.cpp +++ b/kde2file/abdump/main.cpp | |||
@@ -1,193 +1,196 @@ | |||
1 | /******************************************************************************* | 1 | /******************************************************************************* |
2 | * main.cpp * | 2 | * main.cpp * |
3 | * * | 3 | * * |
4 | * | 4 | * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * | 7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * | 8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * | 9 | * (at your option) any later version. * |
10 | * * | 10 | * * |
11 | * This program is distributed in the hope that it will be useful, * | 11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * | 14 | * GNU General Public License for more details. * |
15 | * * | 15 | * * |
16 | * You should have received a copy of the GNU General Public License * | 16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * | 17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | * * | 19 | * * |
20 | * As a special exception, permission is given to link this program * | 20 | * As a special exception, permission is given to link this program * |
21 | * with any edition of Qt, and distribute the resulting executable, * | 21 | * with any edition of Qt, and distribute the resulting executable, * |
22 | * without including the source code for Qt in the source distribution. * | 22 | * without including the source code for Qt in the source distribution. * |
23 | * * | 23 | * * |
24 | ******************************************************************************/ | 24 | ******************************************************************************/ |
25 | 25 | ||
26 | #include <kcmdlineargs.h> | 26 | #include <kcmdlineargs.h> |
27 | #include <kaboutdata.h> | 27 | #include <kaboutdata.h> |
28 | #include <klocale.h> | 28 | #include <klocale.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <kconfig.h> | 30 | #include <kconfig.h> |
31 | #include <kstandarddirs.h> | 31 | #include <kstandarddirs.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | 33 | ||
34 | #include <kabc/addressbook.h> | 34 | #include <kabc/addressbook.h> |
35 | #include <kabc/stdaddressbook.h> | 35 | #include <kabc/stdaddressbook.h> |
36 | #include <kabc/resource.h> | 36 | #include <kabc/resource.h> |
37 | #include <kabc/vcardconverter.h> | 37 | #include <kabc/vcardconverter.h> |
38 | 38 | ||
39 | #include <qdatetime.h> | 39 | #include <qdatetime.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qdir.h> | 41 | #include <qdir.h> |
42 | #include <qapplication.h> | 42 | #include <qapplication.h> |
43 | 43 | ||
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | #include <iostream> | 45 | #include <iostream> |
46 | 46 | ||
47 | using namespace std; | 47 | using namespace std; |
48 | 48 | ||
49 | static const char progName[] = "kdecalendar"; | 49 | static const char progName[] = "kdecalendar"; |
50 | static const char progDisplay[] = "KDE_Addressbook"; | 50 | static const char progDisplay[] = "KDE_Addressbook"; |
51 | static const char progVersion[] = "33.1/3"; | 51 | static const char progVersion[] = "33.1/3"; |
52 | static const char progDesc[] = "A command line interface to KDE addressbooks"; | 52 | static const char progDesc[] = "A command line interface to KDE addressbooks"; |
53 | 53 | ||
54 | 54 | ||
55 | static KCmdLineOptions options[] = | 55 | static KCmdLineOptions options[] = |
56 | { | 56 | { |
57 | { "dump", | 57 | { "dump", |
58 | I18N_NOOP( "Dumps addressbook" ), 0 }, | 58 | I18N_NOOP( "Dumps addressbook" ), 0 }, |
59 | { "read", | 59 | { "read", |
60 | I18N_NOOP( "Reads addressbook" ), 0 }, | 60 | I18N_NOOP( "Reads addressbook" ), 0 }, |
61 | KCmdLineLastOption | 61 | KCmdLineLastOption |
62 | }; | 62 | }; |
63 | 63 | ||
64 | int main( int argc, char *argv[] ) | 64 | int main( int argc, char *argv[] ) |
65 | { | 65 | { |
66 | KAboutData aboutData( | 66 | KAboutData aboutData( |
67 | progName, // internal program name | 67 | progName, // internal program name |
68 | I18N_NOOP( progDisplay ), // displayable program name. | 68 | I18N_NOOP( progDisplay ), // displayable program name. |
69 | progVersion, // version string | 69 | progVersion, // version string |
70 | I18N_NOOP( progDesc ), // short porgram description | 70 | I18N_NOOP( progDesc ), // short porgram description |
71 | KAboutData::License_GPL, // license type | 71 | KAboutData::License_GPL, // license type |
72 | "(c) 2004, Lutz Rogowski", // copyright statement | 72 | "(c) 2004, Lutz Rogowski", // copyright statement |
73 | 0, // any free form text | 73 | 0, // any free form text |
74 | "", // program home page address | 74 | "", // program home page address |
75 | "bugs.kde.org" // bug report email address | 75 | "bugs.kde.org" // bug report email address |
76 | ); | 76 | ); |
77 | 77 | ||
78 | 78 | ||
79 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options | 79 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options |
80 | // for QApplication/KApplication (no KDE or Qt options) | 80 | // for QApplication/KApplication (no KDE or Qt options) |
81 | KCmdLineArgs::init( argc, argv, &aboutData, true ); | 81 | KCmdLineArgs::init( argc, argv, &aboutData, true ); |
82 | KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. | 82 | KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. |
83 | 83 | ||
84 | KInstance ins ( progName ); | 84 | KInstance ins ( progName ); |
85 | 85 | ||
86 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); | 86 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); |
87 | 87 | ||
88 | bool read = false; | 88 | bool read = false; |
89 | if ( args->isSet( "read" ) ) { | 89 | if ( args->isSet( "read" ) ) { |
90 | read = true; | 90 | read = true; |
91 | qDebug("read "); | 91 | qDebug("read "); |
92 | } | 92 | } |
93 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 93 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
94 | 94 | ||
95 | KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self(); | 95 | KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self(); |
96 | standardAddressBook->setAutomaticSave( false ); | 96 | standardAddressBook->setAutomaticSave( false ); |
97 | qDebug("************************************* "); | 97 | qDebug("************************************* "); |
98 | qDebug("***************kdeABdump************* "); | 98 | qDebug("***************kdeABdump************* "); |
99 | qDebug("************************************* "); | 99 | qDebug("************************************* "); |
100 | if ( !read ) { | 100 | if ( !read ) { |
101 | KABC::AddressBook::Iterator it; | 101 | KABC::AddressBook::Iterator it; |
102 | KABC::VCardConverter converter; | 102 | KABC::VCardConverter converter; |
103 | QString datastream; | 103 | QString datastream; |
104 | for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) { | 104 | for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) { |
105 | if ( (*it).isEmpty() || ! (*it).resource() ) | 105 | if ( (*it).isEmpty() || ! (*it).resource() ) |
106 | continue; | 106 | continue; |
107 | KABC::Addressee a = ( *it ); | 107 | KABC::Addressee a = ( *it ); |
108 | QString vcard = converter.createVCard( a ); | 108 | QString vcard = converter.createVCard( a ); |
109 | vcard += QString("\r\n"); | 109 | vcard += QString("\r\n"); |
110 | datastream += vcard; | 110 | datastream += vcard; |
111 | } | 111 | } |
112 | QFile outFile(fileName); | 112 | QFile outFile(fileName); |
113 | if ( outFile.open(IO_WriteOnly) ) { | 113 | if ( outFile.open(IO_WriteOnly) ) { |
114 | QTextStream t( &outFile ); // use a text stream | 114 | QTextStream t( &outFile ); // use a text stream |
115 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 115 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
116 | t <<datastream; | 116 | t <<datastream; |
117 | t << "\r\n\r\n"; | 117 | t << "\r\n\r\n"; |
118 | outFile.close(); | 118 | outFile.close(); |
119 | } | 119 | } |
120 | } else { | 120 | } else { |
121 | //Addressee::List aList;//parseVCards( const QString& vcard ); | 121 | //Addressee::List aList;//parseVCards( const QString& vcard ); |
122 | KABC::Addressee::List list; | 122 | KABC::Addressee::List list; |
123 | int added = 0, changedC = 0, deleted = 0; | 123 | int added = 0, changedC = 0, deleted = 0; |
124 | QFile file( fileName ); | 124 | QFile file( fileName ); |
125 | if ( file.open( IO_ReadOnly ) ) { | 125 | if ( file.open( IO_ReadOnly ) ) { |
126 | QTextStream t( &file ); // use a text stream | 126 | QTextStream t( &file ); // use a text stream |
127 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 127 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
128 | QString data; | 128 | QString data; |
129 | data = t.read(); | 129 | data = t.read(); |
130 | file.close(); | 130 | file.close(); |
131 | KABC::VCardConverter converter; | 131 | KABC::VCardConverter converter; |
132 | list = converter.parseVCards( data ); | 132 | list = converter.parseVCards( data ); |
133 | qDebug("kdeABdump::file has %d entries", list.count()); | 133 | qDebug("kdeABdump::file has %d entries", list.count()); |
134 | 134 | ||
135 | KABC::Addressee::List::Iterator it; | 135 | KABC::Addressee::List::Iterator it; |
136 | for ( it = list.begin();it != list.end();++it) { | 136 | for ( it = list.begin();it != list.end();++it) { |
137 | (*it).setChanged( true ); | 137 | (*it).setChanged( true ); |
138 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); | 138 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); |
139 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 139 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
140 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); | 140 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); |
141 | if ( changed ) { | 141 | if ( changed ) { |
142 | //qDebug("changed Addressee found! "); | 142 | //qDebug("changed Addressee found! "); |
143 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 143 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
144 | if ( ! std.isEmpty() ) | 144 | if ( ! std.isEmpty() ) |
145 | (*it).setResource(std.resource()); | 145 | (*it).setResource(std.resource()); |
146 | standardAddressBook->insertAddressee( (*it) ); | 146 | standardAddressBook->insertAddressee( (*it) ); |
147 | ++changedC; | 147 | ++changedC; |
148 | } else { | 148 | } else { |
149 | //maybe added? | 149 | //maybe added? |
150 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 150 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
151 | if ( std.isEmpty() ) { | 151 | if ( std.isEmpty() ) { |
152 | standardAddressBook->insertAddressee( (*it) ); | 152 | standardAddressBook->insertAddressee( (*it) ); |
153 | ++added; | 153 | ++added; |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |
157 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); | 157 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); |
158 | KABC::AddressBook::Iterator it2 ; | 158 | KABC::AddressBook::Iterator it2 ; |
159 | while ( itA != standardAddressBook->end() ) { | 159 | while ( itA != standardAddressBook->end() ) { |
160 | bool found = false; | 160 | bool found = false; |
161 | KABC::Addressee::List::Iterator itL; | 161 | KABC::Addressee::List::Iterator itL; |
162 | for ( itL = list.begin();itL != list.end();++itL) { | 162 | for ( itL = list.begin();itL != list.end();++itL) { |
163 | if ( (*itL).uid() == (*itA).uid() ) { | 163 | if ( (*itL).uid() == (*itA).uid() ) { |
164 | found = true; | 164 | found = true; |
165 | break; | 165 | break; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | if ( !found ) { | 168 | if ( !found ) { |
169 | it2 = itA; | 169 | it2 = itA; |
170 | ++itA; | 170 | ++itA; |
171 | standardAddressBook->removeAddressee( it2 ); | 171 | standardAddressBook->removeAddressee( it2 ); |
172 | ++deleted; | 172 | ++deleted; |
173 | } else { | 173 | } else { |
174 | ++itA; | 174 | ++itA; |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | //standardAddressBook->saveAll(); | 178 | //standardAddressBook->saveAll(); |
179 | standardAddressBook->setAutomaticSave( true ); | 179 | standardAddressBook->setAutomaticSave( true ); |
180 | qDebug("************************************* "); | 180 | qDebug("************************************* "); |
181 | qDebug("*************kdeABdump*************** "); | 181 | qDebug("*************kdeABdump*************** "); |
182 | qDebug("************************************* "); | 182 | qDebug("************************************* "); |
183 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); | 183 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); |
184 | } else | 184 | } else |
185 | qDebug("error open file "); | 185 | qDebug("error open file "); |
186 | } | 186 | } |
187 | standardAddressBook->close(); | ||
188 | // line not needed by KDE 3.4: | ||
189 | // delete standardAddressBook; | ||
190 | |||
187 | 191 | ||
188 | delete standardAddressBook; | ||
189 | //KABC::StdAddressBook::close(); | 192 | //KABC::StdAddressBook::close(); |
190 | //StdAddressBook::mSelf = 0; | 193 | //StdAddressBook::mSelf = 0; |
191 | qDebug("ente "); | 194 | qDebug("ente "); |
192 | return 0; | 195 | return 0; |
193 | } | 196 | } |
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index d59f4a4..7319285 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -541,789 +541,799 @@ void KSyncManager::multiSync( bool askforPrefs ) | |||
541 | setBlockSave(false); | 541 | setBlockSave(false); |
542 | if ( num ) | 542 | if ( num ) |
543 | emit save(); | 543 | emit save(); |
544 | if ( num ) | 544 | if ( num ) |
545 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 545 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
546 | else | 546 | else |
547 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 547 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
548 | return; | 548 | return; |
549 | } | 549 | } |
550 | 550 | ||
551 | int KSyncManager::ringSync() | 551 | int KSyncManager::ringSync() |
552 | { | 552 | { |
553 | 553 | ||
554 | int syncedProfiles = 0; | 554 | int syncedProfiles = 0; |
555 | unsigned int i; | 555 | unsigned int i; |
556 | QTime timer; | 556 | QTime timer; |
557 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 557 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
558 | QStringList syncProfileNames = mSyncProfileNames; | 558 | QStringList syncProfileNames = mSyncProfileNames; |
559 | KSyncProfile* temp = new KSyncProfile (); | 559 | KSyncProfile* temp = new KSyncProfile (); |
560 | mAskForPreferences = false; | 560 | mAskForPreferences = false; |
561 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 561 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
562 | mCurrentSyncProfile = i; | 562 | mCurrentSyncProfile = i; |
563 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 563 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
564 | temp->readConfig(&config); | 564 | temp->readConfig(&config); |
565 | 565 | ||
566 | bool includeInRingSync = false; | 566 | bool includeInRingSync = false; |
567 | switch(mTargetApp) | 567 | switch(mTargetApp) |
568 | { | 568 | { |
569 | case (KAPI): | 569 | case (KAPI): |
570 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 570 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
571 | break; | 571 | break; |
572 | case (KOPI): | 572 | case (KOPI): |
573 | includeInRingSync = temp->getIncludeInRingSync(); | 573 | includeInRingSync = temp->getIncludeInRingSync(); |
574 | break; | 574 | break; |
575 | case (PWMPI): | 575 | case (PWMPI): |
576 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 576 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
577 | break; | 577 | break; |
578 | default: | 578 | default: |
579 | qDebug("KSM::ringSync: invalid apptype selected"); | 579 | qDebug("KSM::ringSync: invalid apptype selected"); |
580 | break; | 580 | break; |
581 | 581 | ||
582 | } | 582 | } |
583 | 583 | ||
584 | 584 | ||
585 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 585 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
586 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 586 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
587 | ++syncedProfiles; | 587 | ++syncedProfiles; |
588 | mSyncWithDesktop = false; | 588 | mSyncWithDesktop = false; |
589 | // mAskForPreferences = temp->getAskForPreferences(); | 589 | // mAskForPreferences = temp->getAskForPreferences(); |
590 | mWriteBackFile = temp->getWriteBackFile(); | 590 | mWriteBackFile = temp->getWriteBackFile(); |
591 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 591 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
592 | mIsKapiFile = temp->getIsKapiFile(); | 592 | mIsKapiFile = temp->getIsKapiFile(); |
593 | mWriteBackInFuture = 0; | 593 | mWriteBackInFuture = 0; |
594 | if ( temp->getWriteBackFuture() ) { | 594 | if ( temp->getWriteBackFuture() ) { |
595 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 595 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
596 | mWriteBackInPast = temp->getWriteBackPastWeeks( ); | 596 | mWriteBackInPast = temp->getWriteBackPastWeeks( ); |
597 | } | 597 | } |
598 | mFilterInCal = temp->getFilterInCal(); | 598 | mFilterInCal = temp->getFilterInCal(); |
599 | mFilterOutCal = temp->getFilterOutCal(); | 599 | mFilterOutCal = temp->getFilterOutCal(); |
600 | mFilterInAB = temp->getFilterInAB(); | 600 | mFilterInAB = temp->getFilterInAB(); |
601 | mFilterOutAB = temp->getFilterOutAB(); | 601 | mFilterOutAB = temp->getFilterOutAB(); |
602 | mShowSyncSummary = false; | 602 | mShowSyncSummary = false; |
603 | mCurrentSyncDevice = syncProfileNames[i] ; | 603 | mCurrentSyncDevice = syncProfileNames[i] ; |
604 | mCurrentSyncName = mLocalMachineName; | 604 | mCurrentSyncName = mLocalMachineName; |
605 | if ( i == 0 ) { | 605 | if ( i == 0 ) { |
606 | mIsKapiFile = false; | 606 | mIsKapiFile = false; |
607 | #ifdef DESKTOP_VERSION | 607 | #ifdef DESKTOP_VERSION |
608 | syncKDE(); | 608 | syncKDE(); |
609 | #else | 609 | #else |
610 | syncSharp(); | 610 | syncSharp(); |
611 | #endif | 611 | #endif |
612 | } else { | 612 | } else { |
613 | if ( temp->getIsLocalFileSync() ) { | 613 | if ( temp->getIsLocalFileSync() ) { |
614 | switch(mTargetApp) | 614 | switch(mTargetApp) |
615 | { | 615 | { |
616 | case (KAPI): | 616 | case (KAPI): |
617 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 617 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
618 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 618 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
619 | break; | 619 | break; |
620 | case (KOPI): | 620 | case (KOPI): |
621 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 621 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
622 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 622 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
623 | break; | 623 | break; |
624 | case (PWMPI): | 624 | case (PWMPI): |
625 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 625 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
626 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 626 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
627 | break; | 627 | break; |
628 | default: | 628 | default: |
629 | qDebug("KSM: invalid apptype selected"); | 629 | qDebug("KSM: invalid apptype selected"); |
630 | break; | 630 | break; |
631 | } | 631 | } |
632 | } else { | 632 | } else { |
633 | if ( temp->getIsPhoneSync() ) { | 633 | if ( temp->getIsPhoneSync() ) { |
634 | mPhoneDevice = temp->getPhoneDevice( ) ; | 634 | mPhoneDevice = temp->getPhoneDevice( ) ; |
635 | mPhoneConnection = temp->getPhoneConnection( ); | 635 | mPhoneConnection = temp->getPhoneConnection( ); |
636 | mPhoneModel = temp->getPhoneModel( ); | 636 | mPhoneModel = temp->getPhoneModel( ); |
637 | syncPhone(); | 637 | syncPhone(); |
638 | } else if ( temp->getIsPiSync() ) { | 638 | } else if ( temp->getIsPiSync() ) { |
639 | if ( mTargetApp == KAPI ) { | 639 | if ( mTargetApp == KAPI ) { |
640 | mPassWordPiSync = temp->getRemotePwAB(); | 640 | mPassWordPiSync = temp->getRemotePwAB(); |
641 | mActiveSyncPort = temp->getRemotePortAB(); | 641 | mActiveSyncPort = temp->getRemotePortAB(); |
642 | mActiveSyncIP = temp->getRemoteIPAB(); | 642 | mActiveSyncIP = temp->getRemoteIPAB(); |
643 | } else if ( mTargetApp == KOPI ) { | 643 | } else if ( mTargetApp == KOPI ) { |
644 | mPassWordPiSync = temp->getRemotePw(); | 644 | mPassWordPiSync = temp->getRemotePw(); |
645 | mActiveSyncPort = temp->getRemotePort(); | 645 | mActiveSyncPort = temp->getRemotePort(); |
646 | mActiveSyncIP = temp->getRemoteIP(); | 646 | mActiveSyncIP = temp->getRemoteIP(); |
647 | } else { | 647 | } else { |
648 | mPassWordPiSync = temp->getRemotePwPWM(); | 648 | mPassWordPiSync = temp->getRemotePwPWM(); |
649 | mActiveSyncPort = temp->getRemotePortPWM(); | 649 | mActiveSyncPort = temp->getRemotePortPWM(); |
650 | mActiveSyncIP = temp->getRemoteIPPWM(); | 650 | mActiveSyncIP = temp->getRemoteIPPWM(); |
651 | } | 651 | } |
652 | syncPi(); | 652 | syncPi(); |
653 | while ( !mPisyncFinished ) { | 653 | while ( !mPisyncFinished ) { |
654 | //qDebug("waiting "); | 654 | //qDebug("waiting "); |
655 | qApp->processEvents(); | 655 | qApp->processEvents(); |
656 | } | 656 | } |
657 | timer.start(); | 657 | timer.start(); |
658 | while ( timer.elapsed () < 2000 ) { | 658 | while ( timer.elapsed () < 2000 ) { |
659 | qApp->processEvents(); | 659 | qApp->processEvents(); |
660 | } | 660 | } |
661 | } else | 661 | } else |
662 | syncRemote( temp, false ); | 662 | syncRemote( temp, false ); |
663 | 663 | ||
664 | } | 664 | } |
665 | } | 665 | } |
666 | timer.start(); | 666 | timer.start(); |
667 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 667 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
668 | while ( timer.elapsed () < 2000 ) { | 668 | while ( timer.elapsed () < 2000 ) { |
669 | qApp->processEvents(); | 669 | qApp->processEvents(); |
670 | #ifndef _WIN32_ | 670 | #ifndef _WIN32_ |
671 | sleep (1); | 671 | sleep (1); |
672 | #endif | 672 | #endif |
673 | } | 673 | } |
674 | 674 | ||
675 | } | 675 | } |
676 | 676 | ||
677 | } | 677 | } |
678 | delete temp; | 678 | delete temp; |
679 | return syncedProfiles; | 679 | return syncedProfiles; |
680 | } | 680 | } |
681 | 681 | ||
682 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 682 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
683 | { | 683 | { |
684 | QString question; | 684 | QString question; |
685 | if ( ask ) { | 685 | if ( ask ) { |
686 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 686 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
687 | if ( QMessageBox::information( mParent, i18n("Sync"), | 687 | if ( QMessageBox::information( mParent, i18n("Sync"), |
688 | question, | 688 | question, |
689 | i18n("Yes"), i18n("No"), | 689 | i18n("Yes"), i18n("No"), |
690 | 0, 0 ) != 0 ) | 690 | 0, 0 ) != 0 ) |
691 | return; | 691 | return; |
692 | } | 692 | } |
693 | 693 | ||
694 | QString preCommand; | 694 | QString preCommand; |
695 | QString localTempFile; | 695 | QString localTempFile; |
696 | QString postCommand; | 696 | QString postCommand; |
697 | 697 | ||
698 | switch(mTargetApp) | 698 | switch(mTargetApp) |
699 | { | 699 | { |
700 | case (KAPI): | 700 | case (KAPI): |
701 | preCommand = prof->getPreSyncCommandAB(); | 701 | preCommand = prof->getPreSyncCommandAB(); |
702 | postCommand = prof->getPostSyncCommandAB(); | 702 | postCommand = prof->getPostSyncCommandAB(); |
703 | localTempFile = prof->getLocalTempFileAB(); | 703 | localTempFile = prof->getLocalTempFileAB(); |
704 | break; | 704 | break; |
705 | case (KOPI): | 705 | case (KOPI): |
706 | preCommand = prof->getPreSyncCommand(); | 706 | preCommand = prof->getPreSyncCommand(); |
707 | postCommand = prof->getPostSyncCommand(); | 707 | postCommand = prof->getPostSyncCommand(); |
708 | localTempFile = prof->getLocalTempFile(); | 708 | localTempFile = prof->getLocalTempFile(); |
709 | break; | 709 | break; |
710 | case (PWMPI): | 710 | case (PWMPI): |
711 | preCommand = prof->getPreSyncCommandPWM(); | 711 | preCommand = prof->getPreSyncCommandPWM(); |
712 | postCommand = prof->getPostSyncCommandPWM(); | 712 | postCommand = prof->getPostSyncCommandPWM(); |
713 | localTempFile = prof->getLocalTempFilePWM(); | 713 | localTempFile = prof->getLocalTempFilePWM(); |
714 | break; | 714 | break; |
715 | default: | 715 | default: |
716 | qDebug("KSM::syncRemote: invalid apptype selected"); | 716 | qDebug("KSM::syncRemote: invalid apptype selected"); |
717 | break; | 717 | break; |
718 | } | 718 | } |
719 | 719 | ||
720 | 720 | ||
721 | int fi; | 721 | int fi; |
722 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 722 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
723 | QString pwd = getPassword(); | 723 | QString pwd = getPassword(); |
724 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 724 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
725 | 725 | ||
726 | } | 726 | } |
727 | int maxlen = 30; | 727 | int maxlen = 30; |
728 | if ( QApplication::desktop()->width() > 320 ) | 728 | if ( QApplication::desktop()->width() > 320 ) |
729 | maxlen += 25; | 729 | maxlen += 25; |
730 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 730 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
731 | int fileSize = 0; | 731 | int fileSize = 0; |
732 | int result = system ( preCommand ); | 732 | int result = system ( preCommand ); |
733 | // 0 : okay | 733 | // 0 : okay |
734 | // 256: no such file or dir | 734 | // 256: no such file or dir |
735 | // | 735 | // |
736 | qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); | 736 | qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); |
737 | if ( result != 0 ) { | 737 | if ( result != 0 ) { |
738 | unsigned int len = maxlen; | 738 | unsigned int len = maxlen; |
739 | while ( len < preCommand.length() ) { | 739 | while ( len < preCommand.length() ) { |
740 | preCommand.insert( len , "\n" ); | 740 | preCommand.insert( len , "\n" ); |
741 | len += maxlen +2; | 741 | len += maxlen +2; |
742 | } | 742 | } |
743 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; | 743 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; |
744 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 744 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
745 | question, | 745 | question, |
746 | i18n("Okay!")) ; | 746 | i18n("Okay!")) ; |
747 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 747 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
748 | return; | 748 | return; |
749 | } | 749 | } |
750 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 750 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
751 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 751 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
752 | 752 | ||
753 | if ( syncWithFile( localTempFile, true ) ) { | 753 | if ( syncWithFile( localTempFile, true ) ) { |
754 | 754 | ||
755 | if ( mWriteBackFile ) { | 755 | if ( mWriteBackFile ) { |
756 | int fi; | 756 | int fi; |
757 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 757 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
758 | QString pwd = getPassword(); | 758 | QString pwd = getPassword(); |
759 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 759 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
760 | 760 | ||
761 | } | 761 | } |
762 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 762 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
763 | result = system ( postCommand ); | 763 | result = system ( postCommand ); |
764 | qDebug("KSM::Sync:Writing back file result: %d ", result); | 764 | qDebug("KSM::Sync:Writing back file result: %d ", result); |
765 | if ( result != 0 ) { | 765 | if ( result != 0 ) { |
766 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 766 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
767 | return; | 767 | return; |
768 | } else { | 768 | } else { |
769 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 769 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
770 | } | 770 | } |
771 | } | 771 | } |
772 | } | 772 | } |
773 | return; | 773 | return; |
774 | } | 774 | } |
775 | bool KSyncManager::edit_pisync_options() | 775 | bool KSyncManager::edit_pisync_options() |
776 | { | 776 | { |
777 | QDialog dia( mParent, "dia", true ); | 777 | QDialog dia( mParent, "dia", true ); |
778 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 778 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
779 | QVBoxLayout lay ( &dia ); | 779 | QVBoxLayout lay ( &dia ); |
780 | lay.setSpacing( 5 ); | 780 | lay.setSpacing( 5 ); |
781 | lay.setMargin( 3 ); | 781 | lay.setMargin( 3 ); |
782 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 782 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
783 | lay.addWidget( &lab1 ); | 783 | lay.addWidget( &lab1 ); |
784 | QLineEdit le1 (&dia ); | 784 | QLineEdit le1 (&dia ); |
785 | lay.addWidget( &le1 ); | 785 | lay.addWidget( &le1 ); |
786 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 786 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
787 | lay.addWidget( &lab2 ); | 787 | lay.addWidget( &lab2 ); |
788 | QLineEdit le2 (&dia ); | 788 | QLineEdit le2 (&dia ); |
789 | lay.addWidget( &le2 ); | 789 | lay.addWidget( &le2 ); |
790 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 790 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
791 | lay.addWidget( &lab3 ); | 791 | lay.addWidget( &lab3 ); |
792 | QLineEdit le3 (&dia ); | 792 | QLineEdit le3 (&dia ); |
793 | lay.addWidget( &le3 ); | 793 | lay.addWidget( &le3 ); |
794 | QPushButton pb ( "OK", &dia); | 794 | QPushButton pb ( "OK", &dia); |
795 | lay.addWidget( &pb ); | 795 | lay.addWidget( &pb ); |
796 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 796 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
797 | le1.setText( mPassWordPiSync ); | 797 | le1.setText( mPassWordPiSync ); |
798 | le2.setText( mActiveSyncIP ); | 798 | le2.setText( mActiveSyncIP ); |
799 | le3.setText( mActiveSyncPort ); | 799 | le3.setText( mActiveSyncPort ); |
800 | if ( dia.exec() ) { | 800 | if ( dia.exec() ) { |
801 | mPassWordPiSync = le1.text(); | 801 | mPassWordPiSync = le1.text(); |
802 | mActiveSyncPort = le3.text(); | 802 | mActiveSyncPort = le3.text(); |
803 | mActiveSyncIP = le2.text(); | 803 | mActiveSyncIP = le2.text(); |
804 | return true; | 804 | return true; |
805 | } | 805 | } |
806 | return false; | 806 | return false; |
807 | } | 807 | } |
808 | bool KSyncManager::edit_sync_options() | 808 | bool KSyncManager::edit_sync_options() |
809 | { | 809 | { |
810 | 810 | ||
811 | QDialog dia( mParent, "dia", true ); | 811 | QDialog dia( mParent, "dia", true ); |
812 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 812 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
813 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 813 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
814 | QVBoxLayout lay ( &dia ); | 814 | QVBoxLayout lay ( &dia ); |
815 | lay.setSpacing( 2 ); | 815 | lay.setSpacing( 2 ); |
816 | lay.setMargin( 3 ); | 816 | lay.setMargin( 3 ); |
817 | lay.addWidget(&gr); | 817 | lay.addWidget(&gr); |
818 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 818 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
819 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 819 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
820 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 820 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
821 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 821 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
822 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 822 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
823 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 823 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
824 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 824 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
825 | QPushButton pb ( "OK", &dia); | 825 | QPushButton pb ( "OK", &dia); |
826 | lay.addWidget( &pb ); | 826 | lay.addWidget( &pb ); |
827 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 827 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
828 | switch ( mSyncAlgoPrefs ) { | 828 | switch ( mSyncAlgoPrefs ) { |
829 | case 0: | 829 | case 0: |
830 | loc.setChecked( true); | 830 | loc.setChecked( true); |
831 | break; | 831 | break; |
832 | case 1: | 832 | case 1: |
833 | rem.setChecked( true ); | 833 | rem.setChecked( true ); |
834 | break; | 834 | break; |
835 | case 2: | 835 | case 2: |
836 | newest.setChecked( true); | 836 | newest.setChecked( true); |
837 | break; | 837 | break; |
838 | case 3: | 838 | case 3: |
839 | ask.setChecked( true); | 839 | ask.setChecked( true); |
840 | break; | 840 | break; |
841 | case 4: | 841 | case 4: |
842 | f_loc.setChecked( true); | 842 | f_loc.setChecked( true); |
843 | break; | 843 | break; |
844 | case 5: | 844 | case 5: |
845 | f_rem.setChecked( true); | 845 | f_rem.setChecked( true); |
846 | break; | 846 | break; |
847 | case 6: | 847 | case 6: |
848 | // both.setChecked( true); | 848 | // both.setChecked( true); |
849 | break; | 849 | break; |
850 | default: | 850 | default: |
851 | break; | 851 | break; |
852 | } | 852 | } |
853 | if ( dia.exec() ) { | 853 | if ( dia.exec() ) { |
854 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 854 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
855 | return true; | 855 | return true; |
856 | } | 856 | } |
857 | return false; | 857 | return false; |
858 | } | 858 | } |
859 | 859 | ||
860 | QString KSyncManager::getPassword( ) | 860 | QString KSyncManager::getPassword( ) |
861 | { | 861 | { |
862 | QString retfile = ""; | 862 | QString retfile = ""; |
863 | QDialog dia ( mParent, "input-dialog", true ); | 863 | QDialog dia ( mParent, "input-dialog", true ); |
864 | QLineEdit lab ( &dia ); | 864 | QLineEdit lab ( &dia ); |
865 | lab.setEchoMode( QLineEdit::Password ); | 865 | lab.setEchoMode( QLineEdit::Password ); |
866 | QVBoxLayout lay( &dia ); | 866 | QVBoxLayout lay( &dia ); |
867 | lay.setMargin(7); | 867 | lay.setMargin(7); |
868 | lay.setSpacing(7); | 868 | lay.setSpacing(7); |
869 | lay.addWidget( &lab); | 869 | lay.addWidget( &lab); |
870 | dia.setFixedSize( 230,50 ); | 870 | dia.setFixedSize( 230,50 ); |
871 | dia.setCaption( i18n("Enter password") ); | 871 | dia.setCaption( i18n("Enter password") ); |
872 | QPushButton pb ( "OK", &dia); | 872 | QPushButton pb ( "OK", &dia); |
873 | lay.addWidget( &pb ); | 873 | lay.addWidget( &pb ); |
874 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 874 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
875 | dia.show(); | 875 | dia.show(); |
876 | int res = dia.exec(); | 876 | int res = dia.exec(); |
877 | if ( res ) | 877 | if ( res ) |
878 | retfile = lab.text(); | 878 | retfile = lab.text(); |
879 | dia.hide(); | 879 | dia.hide(); |
880 | qApp->processEvents(); | 880 | qApp->processEvents(); |
881 | return retfile; | 881 | return retfile; |
882 | 882 | ||
883 | } | 883 | } |
884 | 884 | ||
885 | 885 | ||
886 | void KSyncManager::confSync() | 886 | void KSyncManager::confSync() |
887 | { | 887 | { |
888 | static KSyncPrefsDialog* sp = 0; | 888 | static KSyncPrefsDialog* sp = 0; |
889 | if ( ! sp ) { | 889 | if ( ! sp ) { |
890 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 890 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
891 | } | 891 | } |
892 | sp->usrReadConfig(); | 892 | sp->usrReadConfig(); |
893 | #ifndef DESKTOP_VERSION | 893 | #ifndef DESKTOP_VERSION |
894 | sp->showMaximized(); | 894 | sp->showMaximized(); |
895 | #else | 895 | #else |
896 | sp->show(); | 896 | sp->show(); |
897 | #endif | 897 | #endif |
898 | sp->exec(); | 898 | sp->exec(); |
899 | QStringList oldSyncProfileNames = mSyncProfileNames; | 899 | QStringList oldSyncProfileNames = mSyncProfileNames; |
900 | mSyncProfileNames = sp->getSyncProfileNames(); | 900 | mSyncProfileNames = sp->getSyncProfileNames(); |
901 | mLocalMachineName = sp->getLocalMachineName (); | 901 | mLocalMachineName = sp->getLocalMachineName (); |
902 | int ii; | 902 | int ii; |
903 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | 903 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { |
904 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | 904 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) |
905 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | 905 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); |
906 | } | 906 | } |
907 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 907 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
908 | } | 908 | } |
909 | void KSyncManager::syncKDE() | 909 | void KSyncManager::syncKDE() |
910 | { | 910 | { |
911 | mSyncWithDesktop = true; | 911 | mSyncWithDesktop = true; |
912 | emit save(); | 912 | emit save(); |
913 | switch(mTargetApp) | 913 | switch(mTargetApp) |
914 | { | 914 | { |
915 | case (KAPI): | 915 | case (KAPI): |
916 | { | 916 | { |
917 | #ifdef DESKTOP_VERSION | 917 | #ifdef DESKTOP_VERSION |
918 | QString command = qApp->applicationDirPath () + "/kdeabdump"; | 918 | QString command = qApp->applicationDirPath () + "/kdeabdump"; |
919 | #else | 919 | #else |
920 | QString command = "kdeabdump"; | 920 | QString command = "kdeabdump"; |
921 | #endif | 921 | #endif |
922 | if ( ! QFile::exists ( command ) ) | 922 | if ( ! QFile::exists ( command ) ) |
923 | command = "kdeabdump"; | 923 | command = "kdeabdump"; |
924 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 924 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
925 | system ( command.latin1()); | 925 | int result = system ( command.latin1()); |
926 | qDebug("AB dump command call result: %d ", result); | ||
927 | if ( result != 0 ) { | ||
928 | KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n/opt/kdepimpi/kdeabdump\nexists.The standard version of this file\nis for syncing with KDE 3.4.x.\nIf you are running KDE 3.3.x please\ndownload the KDE 3.3.x version of this file\nat http://sourceforge.net/projects/kdepimpi/\nsection: general files for KDE/Pim.")); | ||
929 | return; | ||
930 | } | ||
926 | if ( syncWithFile( fileName,true ) ) { | 931 | if ( syncWithFile( fileName,true ) ) { |
927 | if ( mWriteBackFile ) { | 932 | if ( mWriteBackFile ) { |
928 | command += " --read"; | 933 | command += " --read"; |
929 | system ( command.latin1()); | 934 | system ( command.latin1()); |
930 | } | 935 | } |
931 | } | 936 | } |
932 | 937 | ||
933 | } | 938 | } |
934 | break; | 939 | break; |
935 | case (KOPI): | 940 | case (KOPI): |
936 | { | 941 | { |
937 | #ifdef DESKTOP_VERSION | 942 | #ifdef DESKTOP_VERSION |
938 | QString command = qApp->applicationDirPath () + "/kdecaldump"; | 943 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
939 | #else | 944 | #else |
940 | QString command = "kdecaldump"; | 945 | QString command = "kdecaldump"; |
941 | #endif | 946 | #endif |
942 | if ( ! QFile::exists ( command ) ) | 947 | if ( ! QFile::exists ( command ) ) |
943 | command = "kdecaldump"; | 948 | command = "kdecaldump"; |
944 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 949 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
945 | system ( command.latin1()); | 950 | int result = system ( command.latin1()); |
951 | qDebug("Cal dump command call result result: %d ", result); | ||
952 | if ( result != 0 ) { | ||
953 | KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n/opt/kdepimpi/kdecaldump\nexists.The standard version of this file\nis for syncing with KDE 3.4.x.\nIf you are running KDE 3.3.x please\ndownload the KDE 3.3.x version of this file\nat http://sourceforge.net/projects/kdepimpi/\nsection: general files for KDE/Pim.")); | ||
954 | return; | ||
955 | } | ||
946 | if ( syncWithFile( fileName,true ) ) { | 956 | if ( syncWithFile( fileName,true ) ) { |
947 | if ( mWriteBackFile ) { | 957 | if ( mWriteBackFile ) { |
948 | command += " --read"; | 958 | command += " --read"; |
949 | system ( command.latin1()); | 959 | system ( command.latin1()); |
950 | } | 960 | } |
951 | } | 961 | } |
952 | 962 | ||
953 | } | 963 | } |
954 | break; | 964 | break; |
955 | case (PWMPI): | 965 | case (PWMPI): |
956 | 966 | ||
957 | break; | 967 | break; |
958 | default: | 968 | default: |
959 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); | 969 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); |
960 | break; | 970 | break; |
961 | 971 | ||
962 | } | 972 | } |
963 | } | 973 | } |
964 | 974 | ||
965 | void KSyncManager::syncSharp() | 975 | void KSyncManager::syncSharp() |
966 | { | 976 | { |
967 | 977 | ||
968 | if ( ! syncExternalApplication("sharp") ) | 978 | if ( ! syncExternalApplication("sharp") ) |
969 | qDebug("KSM::ERROR sync sharp "); | 979 | qDebug("KSM::ERROR sync sharp "); |
970 | } | 980 | } |
971 | 981 | ||
972 | bool KSyncManager::syncExternalApplication(QString resource) | 982 | bool KSyncManager::syncExternalApplication(QString resource) |
973 | { | 983 | { |
974 | 984 | ||
975 | emit save(); | 985 | emit save(); |
976 | 986 | ||
977 | if ( mAskForPreferences ) | 987 | if ( mAskForPreferences ) |
978 | if ( !edit_sync_options()) { | 988 | if ( !edit_sync_options()) { |
979 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 989 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
980 | return false; | 990 | return false; |
981 | } | 991 | } |
982 | 992 | ||
983 | qDebug("KSM::Sync extern %s", resource.latin1()); | 993 | qDebug("KSM::Sync extern %s", resource.latin1()); |
984 | 994 | ||
985 | bool syncOK = mImplementation->syncExternal(this, resource); | 995 | bool syncOK = mImplementation->syncExternal(this, resource); |
986 | 996 | ||
987 | return syncOK; | 997 | return syncOK; |
988 | 998 | ||
989 | } | 999 | } |
990 | 1000 | ||
991 | void KSyncManager::syncPhone() | 1001 | void KSyncManager::syncPhone() |
992 | { | 1002 | { |
993 | 1003 | ||
994 | syncExternalApplication("phone"); | 1004 | syncExternalApplication("phone"); |
995 | 1005 | ||
996 | } | 1006 | } |
997 | 1007 | ||
998 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 1008 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
999 | { | 1009 | { |
1000 | if (!bar->isVisible()) | 1010 | if (!bar->isVisible()) |
1001 | { | 1011 | { |
1002 | bar->setCaption (caption); | 1012 | bar->setCaption (caption); |
1003 | bar->setTotalSteps ( total ) ; | 1013 | bar->setTotalSteps ( total ) ; |
1004 | bar->show(); | 1014 | bar->show(); |
1005 | } | 1015 | } |
1006 | bar->raise(); | 1016 | bar->raise(); |
1007 | bar->setProgress( percentage ); | 1017 | bar->setProgress( percentage ); |
1008 | qApp->processEvents(); | 1018 | qApp->processEvents(); |
1009 | } | 1019 | } |
1010 | 1020 | ||
1011 | void KSyncManager::hideProgressBar() | 1021 | void KSyncManager::hideProgressBar() |
1012 | { | 1022 | { |
1013 | bar->hide(); | 1023 | bar->hide(); |
1014 | qApp->processEvents(); | 1024 | qApp->processEvents(); |
1015 | } | 1025 | } |
1016 | 1026 | ||
1017 | bool KSyncManager::isProgressBarCanceled() | 1027 | bool KSyncManager::isProgressBarCanceled() |
1018 | { | 1028 | { |
1019 | return !bar->isVisible(); | 1029 | return !bar->isVisible(); |
1020 | } | 1030 | } |
1021 | 1031 | ||
1022 | QString KSyncManager::syncFileName() | 1032 | QString KSyncManager::syncFileName() |
1023 | { | 1033 | { |
1024 | 1034 | ||
1025 | QString fn = "tempfile"; | 1035 | QString fn = "tempfile"; |
1026 | switch(mTargetApp) | 1036 | switch(mTargetApp) |
1027 | { | 1037 | { |
1028 | case (KAPI): | 1038 | case (KAPI): |
1029 | fn = "tempsyncab.vcf"; | 1039 | fn = "tempsyncab.vcf"; |
1030 | break; | 1040 | break; |
1031 | case (KOPI): | 1041 | case (KOPI): |
1032 | fn = "tempsynccal.ics"; | 1042 | fn = "tempsynccal.ics"; |
1033 | break; | 1043 | break; |
1034 | case (PWMPI): | 1044 | case (PWMPI): |
1035 | fn = "tempsyncpw.pwm"; | 1045 | fn = "tempsyncpw.pwm"; |
1036 | break; | 1046 | break; |
1037 | default: | 1047 | default: |
1038 | break; | 1048 | break; |
1039 | } | 1049 | } |
1040 | #ifdef _WIN32_ | 1050 | #ifdef _WIN32_ |
1041 | return locateLocal( "tmp", fn ); | 1051 | return locateLocal( "tmp", fn ); |
1042 | #else | 1052 | #else |
1043 | return (QString( "/tmp/" )+ fn ); | 1053 | return (QString( "/tmp/" )+ fn ); |
1044 | #endif | 1054 | #endif |
1045 | } | 1055 | } |
1046 | 1056 | ||
1047 | void KSyncManager::syncPi() | 1057 | void KSyncManager::syncPi() |
1048 | { | 1058 | { |
1049 | mIsKapiFile = true; | 1059 | mIsKapiFile = true; |
1050 | mPisyncFinished = false; | 1060 | mPisyncFinished = false; |
1051 | qApp->processEvents(); | 1061 | qApp->processEvents(); |
1052 | if ( mAskForPreferences ) | 1062 | if ( mAskForPreferences ) |
1053 | if ( !edit_pisync_options()) { | 1063 | if ( !edit_pisync_options()) { |
1054 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1064 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1055 | mPisyncFinished = true; | 1065 | mPisyncFinished = true; |
1056 | return; | 1066 | return; |
1057 | } | 1067 | } |
1058 | bool ok; | 1068 | bool ok; |
1059 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1069 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1060 | if ( ! ok ) { | 1070 | if ( ! ok ) { |
1061 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1071 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1062 | mPisyncFinished = true; | 1072 | mPisyncFinished = true; |
1063 | return; | 1073 | return; |
1064 | } | 1074 | } |
1065 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); | 1075 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1066 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1076 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1067 | commandSocket->readFile( syncFileName() ); | 1077 | commandSocket->readFile( syncFileName() ); |
1068 | } | 1078 | } |
1069 | 1079 | ||
1070 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1080 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1071 | { | 1081 | { |
1072 | //enum { success, errorW, errorR, quiet }; | 1082 | //enum { success, errorW, errorR, quiet }; |
1073 | 1083 | ||
1074 | 1084 | ||
1075 | 1085 | ||
1076 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || | 1086 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || |
1077 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { | 1087 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { |
1078 | if ( state == KCommandSocket::errorPW ) | 1088 | if ( state == KCommandSocket::errorPW ) |
1079 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); | 1089 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); |
1080 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) | 1090 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) |
1081 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1091 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1082 | else if ( state == KCommandSocket::errorCA ) | 1092 | else if ( state == KCommandSocket::errorCA ) |
1083 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); | 1093 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); |
1084 | else if ( state == KCommandSocket::errorFI ) | 1094 | else if ( state == KCommandSocket::errorFI ) |
1085 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); | 1095 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); |
1086 | else if ( state == KCommandSocket::errorED ) | 1096 | else if ( state == KCommandSocket::errorED ) |
1087 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); | 1097 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); |
1088 | else if ( state == KCommandSocket::errorUN ) | 1098 | else if ( state == KCommandSocket::errorUN ) |
1089 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); | 1099 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); |
1090 | delete s; | 1100 | delete s; |
1091 | if ( state == KCommandSocket::errorR ) { | 1101 | if ( state == KCommandSocket::errorR ) { |
1092 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); | 1102 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); |
1093 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1103 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1094 | commandSocket->sendStop(); | 1104 | commandSocket->sendStop(); |
1095 | } | 1105 | } |
1096 | mPisyncFinished = true; | 1106 | mPisyncFinished = true; |
1097 | return; | 1107 | return; |
1098 | 1108 | ||
1099 | } else if ( state == KCommandSocket::errorW ) { | 1109 | } else if ( state == KCommandSocket::errorW ) { |
1100 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1110 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1101 | mPisyncFinished = true; | 1111 | mPisyncFinished = true; |
1102 | 1112 | ||
1103 | } else if ( state == KCommandSocket::successR ) { | 1113 | } else if ( state == KCommandSocket::successR ) { |
1104 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1114 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1105 | 1115 | ||
1106 | } else if ( state == KCommandSocket::successW ) { | 1116 | } else if ( state == KCommandSocket::successW ) { |
1107 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 1117 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); |
1108 | mPisyncFinished = true; | 1118 | mPisyncFinished = true; |
1109 | } else if ( state == KCommandSocket::quiet ){ | 1119 | } else if ( state == KCommandSocket::quiet ){ |
1110 | qDebug("KSS: quiet "); | 1120 | qDebug("KSS: quiet "); |
1111 | mPisyncFinished = true; | 1121 | mPisyncFinished = true; |
1112 | } else { | 1122 | } else { |
1113 | qDebug("KSS: Error: unknown state: %d ", state); | 1123 | qDebug("KSS: Error: unknown state: %d ", state); |
1114 | mPisyncFinished = true; | 1124 | mPisyncFinished = true; |
1115 | } | 1125 | } |
1116 | 1126 | ||
1117 | delete s; | 1127 | delete s; |
1118 | } | 1128 | } |
1119 | 1129 | ||
1120 | void KSyncManager::readFileFromSocket() | 1130 | void KSyncManager::readFileFromSocket() |
1121 | { | 1131 | { |
1122 | QString fileName = syncFileName(); | 1132 | QString fileName = syncFileName(); |
1123 | bool syncOK = true; | 1133 | bool syncOK = true; |
1124 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1134 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1125 | if ( ! syncWithFile( fileName , true ) ) { | 1135 | if ( ! syncWithFile( fileName , true ) ) { |
1126 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1136 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1127 | syncOK = false; | 1137 | syncOK = false; |
1128 | } | 1138 | } |
1129 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); | 1139 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1130 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1140 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1131 | if ( mWriteBackFile && syncOK ) | 1141 | if ( mWriteBackFile && syncOK ) |
1132 | commandSocket->writeFile( fileName ); | 1142 | commandSocket->writeFile( fileName ); |
1133 | else { | 1143 | else { |
1134 | commandSocket->sendStop(); | 1144 | commandSocket->sendStop(); |
1135 | if ( syncOK ) | 1145 | if ( syncOK ) |
1136 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1146 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1137 | mPisyncFinished = true; | 1147 | mPisyncFinished = true; |
1138 | } | 1148 | } |
1139 | } | 1149 | } |
1140 | 1150 | ||
1141 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1151 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1142 | { | 1152 | { |
1143 | mPassWord = pw; | 1153 | mPassWord = pw; |
1144 | mSocket = 0; | 1154 | mSocket = 0; |
1145 | mSyncActionDialog = 0; | 1155 | mSyncActionDialog = 0; |
1146 | blockRC = false; | 1156 | blockRC = false; |
1147 | mErrorMessage = 0; | 1157 | mErrorMessage = 0; |
1148 | } | 1158 | } |
1149 | 1159 | ||
1150 | void KServerSocket::newConnection ( int socket ) | 1160 | void KServerSocket::newConnection ( int socket ) |
1151 | { | 1161 | { |
1152 | // qDebug("KServerSocket:New connection %d ", socket); | 1162 | // qDebug("KServerSocket:New connection %d ", socket); |
1153 | if ( mSocket ) { | 1163 | if ( mSocket ) { |
1154 | qDebug("KSS::newConnection Socket deleted! "); | 1164 | qDebug("KSS::newConnection Socket deleted! "); |
1155 | delete mSocket; | 1165 | delete mSocket; |
1156 | mSocket = 0; | 1166 | mSocket = 0; |
1157 | } | 1167 | } |
1158 | mSocket = new QSocket( this ); | 1168 | mSocket = new QSocket( this ); |
1159 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1169 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1160 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1170 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1161 | mSocket->setSocket( socket ); | 1171 | mSocket->setSocket( socket ); |
1162 | } | 1172 | } |
1163 | 1173 | ||
1164 | void KServerSocket::discardClient() | 1174 | void KServerSocket::discardClient() |
1165 | { | 1175 | { |
1166 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1176 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1167 | } | 1177 | } |
1168 | void KServerSocket::deleteSocket() | 1178 | void KServerSocket::deleteSocket() |
1169 | { | 1179 | { |
1170 | qDebug("KSS::deleteSocket"); | 1180 | qDebug("KSS::deleteSocket"); |
1171 | if ( mSocket ) { | 1181 | if ( mSocket ) { |
1172 | delete mSocket; | 1182 | delete mSocket; |
1173 | mSocket = 0; | 1183 | mSocket = 0; |
1174 | } | 1184 | } |
1175 | if ( mErrorMessage ) | 1185 | if ( mErrorMessage ) |
1176 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); | 1186 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); |
1177 | } | 1187 | } |
1178 | void KServerSocket::readClient() | 1188 | void KServerSocket::readClient() |
1179 | { | 1189 | { |
1180 | if ( blockRC ) | 1190 | if ( blockRC ) |
1181 | return; | 1191 | return; |
1182 | if ( mSocket == 0 ) { | 1192 | if ( mSocket == 0 ) { |
1183 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); | 1193 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); |
1184 | return; | 1194 | return; |
1185 | } | 1195 | } |
1186 | if ( mErrorMessage ) { | 1196 | if ( mErrorMessage ) { |
1187 | mErrorMessage = 999; | 1197 | mErrorMessage = 999; |
1188 | error_connect("ERROR_ED\r\n\r\n"); | 1198 | error_connect("ERROR_ED\r\n\r\n"); |
1189 | return; | 1199 | return; |
1190 | } | 1200 | } |
1191 | mErrorMessage = 0; | 1201 | mErrorMessage = 0; |
1192 | //qDebug("KServerSocket::readClient()"); | 1202 | //qDebug("KServerSocket::readClient()"); |
1193 | if ( mSocket->canReadLine() ) { | 1203 | if ( mSocket->canReadLine() ) { |
1194 | QString line = mSocket->readLine(); | 1204 | QString line = mSocket->readLine(); |
1195 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1205 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1196 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1206 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1197 | if ( tokens[0] == "GET" ) { | 1207 | if ( tokens[0] == "GET" ) { |
1198 | if ( tokens[1] == mPassWord ) { | 1208 | if ( tokens[1] == mPassWord ) { |
1199 | //emit sendFile( mSocket ); | 1209 | //emit sendFile( mSocket ); |
1200 | bool ok = false; | 1210 | bool ok = false; |
1201 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1211 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1202 | if ( ok ) { | 1212 | if ( ok ) { |
1203 | KSyncManager::mRequestedSyncEvent = dt; | 1213 | KSyncManager::mRequestedSyncEvent = dt; |
1204 | } | 1214 | } |
1205 | else | 1215 | else |
1206 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1216 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1207 | send_file(); | 1217 | send_file(); |
1208 | } | 1218 | } |
1209 | else { | 1219 | else { |
1210 | mErrorMessage = 1; | 1220 | mErrorMessage = 1; |
1211 | error_connect("ERROR_PW\r\n\r\n"); | 1221 | error_connect("ERROR_PW\r\n\r\n"); |
1212 | } | 1222 | } |
1213 | } | 1223 | } |
1214 | if ( tokens[0] == "PUT" ) { | 1224 | if ( tokens[0] == "PUT" ) { |
1215 | if ( tokens[1] == mPassWord ) { | 1225 | if ( tokens[1] == mPassWord ) { |
1216 | //emit getFile( mSocket ); | 1226 | //emit getFile( mSocket ); |
1217 | blockRC = true; | 1227 | blockRC = true; |
1218 | get_file(); | 1228 | get_file(); |
1219 | } | 1229 | } |
1220 | else { | 1230 | else { |
1221 | mErrorMessage = 2; | 1231 | mErrorMessage = 2; |
1222 | error_connect("ERROR_PW\r\n\r\n"); | 1232 | error_connect("ERROR_PW\r\n\r\n"); |
1223 | end_connect(); | 1233 | end_connect(); |
1224 | } | 1234 | } |
1225 | } | 1235 | } |
1226 | if ( tokens[0] == "STOP" ) { | 1236 | if ( tokens[0] == "STOP" ) { |
1227 | //emit endConnect(); | 1237 | //emit endConnect(); |
1228 | end_connect(); | 1238 | end_connect(); |
1229 | } | 1239 | } |
1230 | } | 1240 | } |
1231 | } | 1241 | } |
1232 | void KServerSocket::displayErrorMessage() | 1242 | void KServerSocket::displayErrorMessage() |
1233 | { | 1243 | { |
1234 | if ( mErrorMessage == 1 ) { | 1244 | if ( mErrorMessage == 1 ) { |
1235 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1245 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1236 | mErrorMessage = 0; | 1246 | mErrorMessage = 0; |
1237 | } | 1247 | } |
1238 | else if ( mErrorMessage == 2 ) { | 1248 | else if ( mErrorMessage == 2 ) { |
1239 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1249 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1240 | mErrorMessage = 0; | 1250 | mErrorMessage = 0; |
1241 | } | 1251 | } |
1242 | } | 1252 | } |
1243 | void KServerSocket::error_connect( QString errmess ) | 1253 | void KServerSocket::error_connect( QString errmess ) |
1244 | { | 1254 | { |
1245 | QTextStream os( mSocket ); | 1255 | QTextStream os( mSocket ); |
1246 | os.setEncoding( QTextStream::Latin1 ); | 1256 | os.setEncoding( QTextStream::Latin1 ); |
1247 | os << errmess ; | 1257 | os << errmess ; |
1248 | mSocket->close(); | 1258 | mSocket->close(); |
1249 | if ( mSocket->state() == QSocket::Idle ) { | 1259 | if ( mSocket->state() == QSocket::Idle ) { |
1250 | QTimer::singleShot( 0, this , SLOT ( discardClient())); | 1260 | QTimer::singleShot( 0, this , SLOT ( discardClient())); |
1251 | } | 1261 | } |
1252 | } | 1262 | } |
1253 | void KServerSocket::end_connect() | 1263 | void KServerSocket::end_connect() |
1254 | { | 1264 | { |
1255 | delete mSyncActionDialog; | 1265 | delete mSyncActionDialog; |
1256 | mSyncActionDialog = 0; | 1266 | mSyncActionDialog = 0; |
1257 | } | 1267 | } |
1258 | void KServerSocket::send_file() | 1268 | void KServerSocket::send_file() |
1259 | { | 1269 | { |
1260 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1270 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1261 | if ( mSyncActionDialog ) | 1271 | if ( mSyncActionDialog ) |
1262 | delete mSyncActionDialog; | 1272 | delete mSyncActionDialog; |
1263 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1273 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1264 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1274 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1265 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1275 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1266 | label->setAlignment ( Qt::AlignHCenter ); | 1276 | label->setAlignment ( Qt::AlignHCenter ); |
1267 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1277 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1268 | lay->addWidget( label); | 1278 | lay->addWidget( label); |
1269 | lay->setMargin(7); | 1279 | lay->setMargin(7); |
1270 | lay->setSpacing(7); | 1280 | lay->setSpacing(7); |
1271 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1281 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1272 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); | 1282 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); |
1273 | //secs = 333; | 1283 | //secs = 333; |
1274 | if ( secs < 0 ) | 1284 | if ( secs < 0 ) |
1275 | secs = secs * (-1); | 1285 | secs = secs * (-1); |
1276 | if ( secs > 30 ) | 1286 | if ( secs > 30 ) |
1277 | //if ( true ) | 1287 | //if ( true ) |
1278 | { | 1288 | { |
1279 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); | 1289 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); |
1280 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1290 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1281 | label->setAlignment ( Qt::AlignHCenter ); | 1291 | label->setAlignment ( Qt::AlignHCenter ); |
1282 | lay->addWidget( label); | 1292 | lay->addWidget( label); |
1283 | if ( secs > 180 ) | 1293 | if ( secs > 180 ) |
1284 | { | 1294 | { |
1285 | if ( secs > 300 ) { | 1295 | if ( secs > 300 ) { |
1286 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { | 1296 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { |
1287 | qDebug("KSS::Sync cancelled ,cs"); | 1297 | qDebug("KSS::Sync cancelled ,cs"); |
1288 | mErrorMessage = 0; | 1298 | mErrorMessage = 0; |
1289 | end_connect(); | 1299 | end_connect(); |
1290 | error_connect("ERROR_CA\r\n\r\n"); | 1300 | error_connect("ERROR_CA\r\n\r\n"); |
1291 | return ; | 1301 | return ; |
1292 | } | 1302 | } |
1293 | } | 1303 | } |
1294 | QFont f = label->font(); | 1304 | QFont f = label->font(); |
1295 | f.setPointSize ( f.pointSize() *2 ); | 1305 | f.setPointSize ( f.pointSize() *2 ); |
1296 | f. setBold (true ); | 1306 | f. setBold (true ); |
1297 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1307 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1298 | label->setFont( f ); | 1308 | label->setFont( f ); |
1299 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); | 1309 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); |
1300 | label->setText( warning ); | 1310 | label->setText( warning ); |
1301 | label->setAlignment ( Qt::AlignHCenter ); | 1311 | label->setAlignment ( Qt::AlignHCenter ); |
1302 | lay->addWidget( label); | 1312 | lay->addWidget( label); |
1303 | mSyncActionDialog->setFixedSize( 230, 300); | 1313 | mSyncActionDialog->setFixedSize( 230, 300); |
1304 | } else { | 1314 | } else { |
1305 | mSyncActionDialog->setFixedSize( 230, 200); | 1315 | mSyncActionDialog->setFixedSize( 230, 200); |
1306 | } | 1316 | } |
1307 | } else { | 1317 | } else { |
1308 | mSyncActionDialog->setFixedSize( 230, 120); | 1318 | mSyncActionDialog->setFixedSize( 230, 120); |
1309 | } | 1319 | } |
1310 | } else | 1320 | } else |
1311 | mSyncActionDialog->setFixedSize( 230, 120); | 1321 | mSyncActionDialog->setFixedSize( 230, 120); |
1312 | mSyncActionDialog->show(); | 1322 | mSyncActionDialog->show(); |
1313 | mSyncActionDialog->raise(); | 1323 | mSyncActionDialog->raise(); |
1314 | emit request_file(); | 1324 | emit request_file(); |
1315 | qApp->processEvents(); | 1325 | qApp->processEvents(); |
1316 | QString fileName = mFileName; | 1326 | QString fileName = mFileName; |
1317 | QFile file( fileName ); | 1327 | QFile file( fileName ); |
1318 | if (!file.open( IO_ReadOnly ) ) { | 1328 | if (!file.open( IO_ReadOnly ) ) { |
1319 | mErrorMessage = 0; | 1329 | mErrorMessage = 0; |
1320 | end_connect(); | 1330 | end_connect(); |
1321 | error_connect("ERROR_FI\r\n\r\n"); | 1331 | error_connect("ERROR_FI\r\n\r\n"); |
1322 | return ; | 1332 | return ; |
1323 | } | 1333 | } |
1324 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1334 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1325 | QTextStream ts( &file ); | 1335 | QTextStream ts( &file ); |
1326 | ts.setEncoding( QTextStream::Latin1 ); | 1336 | ts.setEncoding( QTextStream::Latin1 ); |
1327 | 1337 | ||
1328 | QTextStream os( mSocket ); | 1338 | QTextStream os( mSocket ); |
1329 | os.setEncoding( QTextStream::Latin1 ); | 1339 | os.setEncoding( QTextStream::Latin1 ); |