summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2005-11-25 17:41:25 (UTC)
committer zautrix <zautrix>2005-11-25 17:41:25 (UTC)
commit279e183c0325cd9565605f60af0215bb9bfdc825 (patch) (unidiff)
tree43ab776cd108874819e7c6e73070a7d989a9078f /libkdepim/ksyncmanager.cpp
parent794a5204686ad9bfc16172b01db35f1f3b7683e5 (diff)
downloadkdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.zip
kdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.tar.gz
kdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.tar.bz2
sync
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index a64eb34..719d80b 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -175,49 +175,50 @@ void KSyncManager::slotClearMenu( int action )
175{ 175{
176 QString syncDevice; 176 QString syncDevice;
177 if ( action > 999 ) { 177 if ( action > 999 ) {
178 syncDevice = mSyncProfileNames[action - 1000] ; 178 syncDevice = mSyncProfileNames[action - 1000] ;
179 } 179 }
180 180
181 181
182 182
183 int result = 0; 183 int result = 0;
184 QString sd; 184 QString sd;
185 if ( syncDevice.isEmpty() ) 185 if ( syncDevice.isEmpty() )
186 sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); 186 sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
187 else 187 else
188 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); 188 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
189 189
190 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, 190 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
191 0, 1 ); 191 0, 1 );
192 if ( result ) 192 if ( result )
193 return; 193 return;
194 mImplementation->removeSyncInfo( syncDevice ); 194 mImplementation->removeSyncInfo( syncDevice );
195} 195}
196void KSyncManager::slotSyncMenu( int action ) 196void KSyncManager::slotSyncMenu( int action )
197{ 197{
198 qDebug("KSM::syncaction %d ", action); 198 qDebug("KSM::syncaction %d ", action);
199 mCurrentResourceLocal = ""; 199 mCurrentResourceLocal = "";
200 emit multiResourceSyncStart( false );
200 if ( action == 5000 ) 201 if ( action == 5000 )
201 return; 202 return;
202 mSyncWithDesktop = false; 203 mSyncWithDesktop = false;
203 if ( action == 0 ) { 204 if ( action == 0 ) {
204 205
205 // seems to be a Qt2 event handling bug 206 // seems to be a Qt2 event handling bug
206 // syncmenu.clear causes a segfault at first time 207 // syncmenu.clear causes a segfault at first time
207 // when we call it after the main event loop, it is ok 208 // when we call it after the main event loop, it is ok
208 // same behaviour when calling OM/Pi via QCOP for the first time 209 // same behaviour when calling OM/Pi via QCOP for the first time
209 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 210 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
210 //confSync(); 211 //confSync();
211 212
212 return; 213 return;
213 } 214 }
214 if ( action == 1 ) { 215 if ( action == 1 ) {
215 multiSync( true ); 216 multiSync( true );
216 return; 217 return;
217 } 218 }
218 if ( action == 2 ) { 219 if ( action == 2 ) {
219 enableQuick(); 220 enableQuick();
220 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 221 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
221 return; 222 return;
222 } 223 }
223 if ( action == 3 ) { 224 if ( action == 3 ) {
@@ -420,48 +421,50 @@ void KSyncManager::enableQuick( bool ask )
420 bool ok; 421 bool ok;
421 mPrefs->mPassiveSyncAutoStart = false; 422 mPrefs->mPassiveSyncAutoStart = false;
422 Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok); 423 Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok);
423 qDebug("%d ", port_t); 424 qDebug("%d ", port_t);
424 if ( ! ok || port_t > 65535 ) { 425 if ( ! ok || port_t > 65535 ) {
425 KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error")); 426 KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error"));
426 return; 427 return;
427 } 428 }
428 Q_UINT16 port = port_t; 429 Q_UINT16 port = port_t;
429 //qDebug("port %d ", port); 430 //qDebug("port %d ", port);
430 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 431 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
431 mServerSocket->setFileName( defaultFileName() );//bbb 432 mServerSocket->setFileName( defaultFileName() );//bbb
432 if ( !mServerSocket->ok() ) { 433 if ( !mServerSocket->ok() ) {
433 QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) ); 434 QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) );
434 delete mServerSocket; 435 delete mServerSocket;
435 mServerSocket = 0; 436 mServerSocket = 0;
436 return; 437 return;
437 } 438 }
438 mPrefs->mPassiveSyncAutoStart = autoStart; 439 mPrefs->mPassiveSyncAutoStart = autoStart;
439 if ( changed ) { 440 if ( changed ) {
440 mPrefs->writeConfig(); 441 mPrefs->writeConfig();
441 } 442 }
442 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 443 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
443 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 444 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
445 connect( mServerSocket, SIGNAL ( request_file(const QString &) ),this, SIGNAL ( request_file(const QString &) ) );
446 connect( mServerSocket, SIGNAL ( file_received( bool ,const QString &) ), this, SIGNAL ( getFile( bool,const QString & ) ) );
444} 447}
445void KSyncManager::displayErrorPort() 448void KSyncManager::displayErrorPort()
446{ 449{
447 KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error")); 450 KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error"));
448} 451}
449void KSyncManager::syncLocalFile() 452void KSyncManager::syncLocalFile()
450{ 453{
451 454
452 QString fn =mPrefs->mLastSyncedLocalFile; 455 QString fn =mPrefs->mLastSyncedLocalFile;
453 QString ext; 456 QString ext;
454 457
455 switch(mTargetApp) 458 switch(mTargetApp)
456 { 459 {
457 case (KAPI): 460 case (KAPI):
458 ext = "(*.vcf)"; 461 ext = "(*.vcf)";
459 break; 462 break;
460 case (KOPI): 463 case (KOPI):
461 ext = "(*.ics/*.vcs)"; 464 ext = "(*.ics/*.vcs)";
462 break; 465 break;
463 case (PWMPI): 466 case (PWMPI):
464 ext = "(*.pwm)"; 467 ext = "(*.pwm)";
465 break; 468 break;
466 default: 469 default:
467 qDebug("KSM::syncLocalFile: invalid apptype selected"); 470 qDebug("KSM::syncLocalFile: invalid apptype selected");
@@ -548,49 +551,49 @@ void KSyncManager::multiSync( bool askforPrefs )
548 if ( askforPrefs ) { 551 if ( askforPrefs ) {
549 if ( !edit_sync_options()) { 552 if ( !edit_sync_options()) {
550 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); 553 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") );
551 return; 554 return;
552 } 555 }
553 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 556 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
554 } 557 }
555 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 558 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
556 qApp->processEvents(); 559 qApp->processEvents();
557 int num = ringSync() ; 560 int num = ringSync() ;
558 if ( num > 1 ) 561 if ( num > 1 )
559 ringSync(); 562 ringSync();
560 setBlockSave(false); 563 setBlockSave(false);
561 if ( num ) 564 if ( num )
562 emit save(); 565 emit save();
563 if ( num ) 566 if ( num )
564 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 567 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
565 else 568 else
566 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 569 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
567 return; 570 return;
568} 571}
569 572
570int KSyncManager::ringSync() 573int KSyncManager::ringSync()
571{ 574{
572 575 emit multiResourceSyncStart( false );
573 int syncedProfiles = 0; 576 int syncedProfiles = 0;
574 unsigned int i; 577 unsigned int i;
575 QTime timer; 578 QTime timer;
576 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 579 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
577 QStringList syncProfileNames = mSyncProfileNames; 580 QStringList syncProfileNames = mSyncProfileNames;
578 KSyncProfile* temp = new KSyncProfile (); 581 KSyncProfile* temp = new KSyncProfile ();
579 mAskForPreferences = false; 582 mAskForPreferences = false;
580 mCurrentResourceLocal = ""; 583 mCurrentResourceLocal = "";
581 for ( i = 0; i < syncProfileNames.count(); ++i ) { 584 for ( i = 0; i < syncProfileNames.count(); ++i ) {
582 mCurrentSyncProfile = i; 585 mCurrentSyncProfile = i;
583 temp->setName(syncProfileNames[mCurrentSyncProfile]); 586 temp->setName(syncProfileNames[mCurrentSyncProfile]);
584 temp->readConfig(&config); 587 temp->readConfig(&config);
585 588
586 bool includeInRingSync = false; 589 bool includeInRingSync = false;
587 switch(mTargetApp) 590 switch(mTargetApp)
588 { 591 {
589 case (KAPI): 592 case (KAPI):
590 includeInRingSync = temp->getIncludeInRingSyncAB(); 593 includeInRingSync = temp->getIncludeInRingSyncAB();
591 break; 594 break;
592 case (KOPI): 595 case (KOPI):
593 includeInRingSync = temp->getIncludeInRingSync(); 596 includeInRingSync = temp->getIncludeInRingSync();
594 break; 597 break;
595 case (PWMPI): 598 case (PWMPI):
596 includeInRingSync = temp->getIncludeInRingSyncPWM(); 599 includeInRingSync = temp->getIncludeInRingSyncPWM();
@@ -1119,49 +1122,52 @@ QString KSyncManager::syncFileName()
1119 1122
1120void KSyncManager::syncPi() 1123void KSyncManager::syncPi()
1121{ 1124{
1122 mIsKapiFile = true; 1125 mIsKapiFile = true;
1123 mPisyncFinished = false; 1126 mPisyncFinished = false;
1124 qApp->processEvents(); 1127 qApp->processEvents();
1125 if ( mAskForPreferences ) 1128 if ( mAskForPreferences )
1126 if ( !edit_pisync_options()) { 1129 if ( !edit_pisync_options()) {
1127 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1130 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1128 mPisyncFinished = true; 1131 mPisyncFinished = true;
1129 return; 1132 return;
1130 } 1133 }
1131 bool ok; 1134 bool ok;
1132 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1135 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1133 if ( ! ok ) { 1136 if ( ! ok ) {
1134 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1137 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1135 mPisyncFinished = true; 1138 mPisyncFinished = true;
1136 return; 1139 return;
1137 } 1140 }
1138 mCurrentResourceLocal = ""; 1141 mCurrentResourceLocal = "";
1139 mCurrentResourceRemote = ""; 1142 mCurrentResourceRemote = "";
1140 if ( mSpecificResources.count() ) { 1143 if ( mSpecificResources.count() ) {
1141 int startLocal = 0; 1144 int startLocal = 0;
1142 int startRemote = mSpecificResources.count()/2; 1145 int startRemote = mSpecificResources.count()/2;
1146 emit multiResourceSyncStart( true );
1143 while ( startLocal < mSpecificResources.count()/2 ) { 1147 while ( startLocal < mSpecificResources.count()/2 ) {
1148 if ( startLocal+1 >= mSpecificResources.count()/2 )
1149 emit multiResourceSyncStart( false );
1144 mPisyncFinished = false; 1150 mPisyncFinished = false;
1145 mCurrentResourceLocal = mSpecificResources[ startLocal ]; 1151 mCurrentResourceLocal = mSpecificResources[ startLocal ];
1146 mCurrentResourceRemote = mSpecificResources[ startRemote ]; 1152 mCurrentResourceRemote = mSpecificResources[ startRemote ];
1147 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1153 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1148 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1154 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1149 commandSocket->readFile( syncFileName() ); 1155 commandSocket->readFile( syncFileName() );
1150 while ( !mPisyncFinished ) { 1156 while ( !mPisyncFinished ) {
1151 //qDebug("waiting "); 1157 //qDebug("waiting ");
1152 qApp->processEvents(); 1158 qApp->processEvents();
1153 } 1159 }
1154 ++startLocal; 1160 ++startLocal;
1155 } 1161 }
1156 } else { 1162 } else {
1157 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1163 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1158 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1164 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1159 commandSocket->readFile( syncFileName() ); 1165 commandSocket->readFile( syncFileName() );
1160 } 1166 }
1161} 1167}
1162 1168
1163void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1169void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1164{ 1170{
1165 //enum { success, errorW, errorR, quiet }; 1171 //enum { success, errorW, errorR, quiet };
1166 1172
1167 1173
@@ -1198,49 +1204,49 @@ void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1198 1204
1199 } else if ( state == KCommandSocket::successW ) { 1205 } else if ( state == KCommandSocket::successW ) {
1200 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 1206 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
1201 mPisyncFinished = true; 1207 mPisyncFinished = true;
1202 } else if ( state == KCommandSocket::quiet ){ 1208 } else if ( state == KCommandSocket::quiet ){
1203 qDebug("KSS: quiet "); 1209 qDebug("KSS: quiet ");
1204 mPisyncFinished = true; 1210 mPisyncFinished = true;
1205 } else { 1211 } else {
1206 qDebug("KSS: Error: unknown state: %d ", state); 1212 qDebug("KSS: Error: unknown state: %d ", state);
1207 mPisyncFinished = true; 1213 mPisyncFinished = true;
1208 } 1214 }
1209 1215
1210 delete s; 1216 delete s;
1211} 1217}
1212 1218
1213void KSyncManager::readFileFromSocket() 1219void KSyncManager::readFileFromSocket()
1214{ 1220{
1215 QString fileName = syncFileName(); 1221 QString fileName = syncFileName();
1216 bool syncOK = true; 1222 bool syncOK = true;
1217 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1223 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1218 if ( ! syncWithFile( fileName , true ) ) { 1224 if ( ! syncWithFile( fileName , true ) ) {
1219 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1225 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1220 syncOK = false; 1226 syncOK = false;
1221 } 1227 }
1222 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1228 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1223 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1229 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1224 if ( mWriteBackFile && syncOK ) { 1230 if ( mWriteBackFile && syncOK ) {
1225 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); 1231 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
1226 commandSocket->writeFile( fileName ); 1232 commandSocket->writeFile( fileName );
1227 } 1233 }
1228 else { 1234 else {
1229 commandSocket->sendStop(); 1235 commandSocket->sendStop();
1230 if ( syncOK ) 1236 if ( syncOK )
1231 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1237 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1232 mPisyncFinished = true; 1238 mPisyncFinished = true;
1233 } 1239 }
1234} 1240}
1235 1241
1236KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1242KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1237{ 1243{
1238 mPassWord = pw; 1244 mPassWord = pw;
1239 mSocket = 0; 1245 mSocket = 0;
1240 mSyncActionDialog = 0; 1246 mSyncActionDialog = 0;
1241 blockRC = false; 1247 blockRC = false;
1242 mErrorMessage = 0; 1248 mErrorMessage = 0;
1243} 1249}
1244 1250
1245void KServerSocket::newConnection ( int socket ) 1251void KServerSocket::newConnection ( int socket )
1246{ 1252{
@@ -1262,75 +1268,78 @@ void KServerSocket::discardClient()
1262} 1268}
1263void KServerSocket::deleteSocket() 1269void KServerSocket::deleteSocket()
1264{ 1270{
1265 qDebug("KSS::deleteSocket"); 1271 qDebug("KSS::deleteSocket");
1266 if ( mSocket ) { 1272 if ( mSocket ) {
1267 delete mSocket; 1273 delete mSocket;
1268 mSocket = 0; 1274 mSocket = 0;
1269 } 1275 }
1270 if ( mErrorMessage ) 1276 if ( mErrorMessage )
1271 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); 1277 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage()));
1272} 1278}
1273void KServerSocket::readClient() 1279void KServerSocket::readClient()
1274{ 1280{
1275 if ( blockRC ) 1281 if ( blockRC )
1276 return; 1282 return;
1277 if ( mSocket == 0 ) { 1283 if ( mSocket == 0 ) {
1278 qDebug("ERROR::KSS::readClient(): mSocket == 0 "); 1284 qDebug("ERROR::KSS::readClient(): mSocket == 0 ");
1279 return; 1285 return;
1280 } 1286 }
1281 if ( mErrorMessage ) { 1287 if ( mErrorMessage ) {
1282 mErrorMessage = 999; 1288 mErrorMessage = 999;
1283 error_connect("ERROR_ED\r\n\r\n"); 1289 error_connect("ERROR_ED\r\n\r\n");
1284 return; 1290 return;
1285 } 1291 }
1292 mResource = "";
1286 mErrorMessage = 0; 1293 mErrorMessage = 0;
1287 //qDebug("KServerSocket::readClient()"); 1294 //qDebug("KServerSocket::readClient()");
1288 if ( mSocket->canReadLine() ) { 1295 if ( mSocket->canReadLine() ) {
1289 QString line = mSocket->readLine(); 1296 QString line = mSocket->readLine();
1290 //qDebug("KServerSocket readline: %s ", line.latin1()); 1297 //qDebug("KServerSocket readline: %s ", line.latin1());
1291 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1298 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1292 if ( tokens[0] == "GET" ) { 1299 if ( tokens[0] == "GET" ) {
1293 if ( tokens[1] == mPassWord ) { 1300 if ( tokens[1] == mPassWord ) {
1294 //emit sendFile( mSocket ); 1301 //emit sendFile( mSocket );
1295 bool ok = false; 1302 bool ok = false;
1296 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1303 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1297 if ( ok ) { 1304 if ( ok ) {
1298 KSyncManager::mRequestedSyncEvent = dt; 1305 KSyncManager::mRequestedSyncEvent = dt;
1299 } 1306 }
1300 else 1307 else
1301 KSyncManager::mRequestedSyncEvent = QDateTime(); 1308 KSyncManager::mRequestedSyncEvent = QDateTime();
1309 mResource =tokens[3];
1302 send_file(); 1310 send_file();
1303 } 1311 }
1304 else { 1312 else {
1305 mErrorMessage = 1; 1313 mErrorMessage = 1;
1306 error_connect("ERROR_PW\r\n\r\n"); 1314 error_connect("ERROR_PW\r\n\r\n");
1307 } 1315 }
1308 } 1316 }
1309 if ( tokens[0] == "PUT" ) { 1317 if ( tokens[0] == "PUT" ) {
1310 if ( tokens[1] == mPassWord ) { 1318 if ( tokens[1] == mPassWord ) {
1311 //emit getFile( mSocket ); 1319 //emit getFile( mSocket );
1312 blockRC = true; 1320 blockRC = true;
1321 mResource =tokens[2];
1313 get_file(); 1322 get_file();
1314 } 1323 }
1315 else { 1324 else {
1316 mErrorMessage = 2; 1325 mErrorMessage = 2;
1317 error_connect("ERROR_PW\r\n\r\n"); 1326 error_connect("ERROR_PW\r\n\r\n");
1318 end_connect(); 1327 end_connect();
1319 } 1328 }
1320 } 1329 }
1321 if ( tokens[0] == "STOP" ) { 1330 if ( tokens[0] == "STOP" ) {
1322 //emit endConnect(); 1331 //emit endConnect();
1323 end_connect(); 1332 end_connect();
1324 } 1333 }
1325 } 1334 }
1326} 1335}
1327void KServerSocket::displayErrorMessage() 1336void KServerSocket::displayErrorMessage()
1328{ 1337{
1329 if ( mErrorMessage == 1 ) { 1338 if ( mErrorMessage == 1 ) {
1330 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); 1339 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error"));
1331 mErrorMessage = 0; 1340 mErrorMessage = 0;
1332 } 1341 }
1333 else if ( mErrorMessage == 2 ) { 1342 else if ( mErrorMessage == 2 ) {
1334 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); 1343 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error"));
1335 mErrorMessage = 0; 1344 mErrorMessage = 0;
1336 } 1345 }
@@ -1385,48 +1394,49 @@ void KServerSocket::send_file()
1385 error_connect("ERROR_CA\r\n\r\n"); 1394 error_connect("ERROR_CA\r\n\r\n");
1386 return ; 1395 return ;
1387 } 1396 }
1388 } 1397 }
1389 QFont f = label->font(); 1398 QFont f = label->font();
1390 f.setPointSize ( f.pointSize() *2 ); 1399 f.setPointSize ( f.pointSize() *2 );
1391 f. setBold (true ); 1400 f. setBold (true );
1392 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1401 QLabel* label = new QLabel( warning, mSyncActionDialog );
1393 label->setFont( f ); 1402 label->setFont( f );
1394 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1403 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1395 label->setText( warning ); 1404 label->setText( warning );
1396 label->setAlignment ( Qt::AlignHCenter ); 1405 label->setAlignment ( Qt::AlignHCenter );
1397 lay->addWidget( label); 1406 lay->addWidget( label);
1398 mSyncActionDialog->setFixedSize( 230, 300); 1407 mSyncActionDialog->setFixedSize( 230, 300);
1399 } else { 1408 } else {
1400 mSyncActionDialog->setFixedSize( 230, 200); 1409 mSyncActionDialog->setFixedSize( 230, 200);
1401 } 1410 }
1402 } else { 1411 } else {
1403 mSyncActionDialog->setFixedSize( 230, 120); 1412 mSyncActionDialog->setFixedSize( 230, 120);
1404 } 1413 }
1405 } else 1414 } else
1406 mSyncActionDialog->setFixedSize( 230, 120); 1415 mSyncActionDialog->setFixedSize( 230, 120);
1407 mSyncActionDialog->show(); 1416 mSyncActionDialog->show();
1408 mSyncActionDialog->raise(); 1417 mSyncActionDialog->raise();
1418 emit request_file(mResource);
1409 emit request_file(); 1419 emit request_file();
1410 qApp->processEvents(); 1420 qApp->processEvents();
1411 QString fileName = mFileName; 1421 QString fileName = mFileName;
1412 QFile file( fileName ); 1422 QFile file( fileName );
1413 if (!file.open( IO_ReadOnly ) ) { 1423 if (!file.open( IO_ReadOnly ) ) {
1414 mErrorMessage = 0; 1424 mErrorMessage = 0;
1415 end_connect(); 1425 end_connect();
1416 error_connect("ERROR_FI\r\n\r\n"); 1426 error_connect("ERROR_FI\r\n\r\n");
1417 return ; 1427 return ;
1418 } 1428 }
1419 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1429 mSyncActionDialog->setCaption( i18n("Sending file...") );
1420 QTextStream ts( &file ); 1430 QTextStream ts( &file );
1421 ts.setEncoding( QTextStream::Latin1 ); 1431 ts.setEncoding( QTextStream::Latin1 );
1422 1432
1423 QTextStream os( mSocket ); 1433 QTextStream os( mSocket );
1424 os.setEncoding( QTextStream::Latin1 ); 1434 os.setEncoding( QTextStream::Latin1 );
1425 while ( ! ts.atEnd() ) { 1435 while ( ! ts.atEnd() ) {
1426 os << ts.readLine() << "\r\n"; 1436 os << ts.readLine() << "\r\n";
1427 } 1437 }
1428 os << "\r\n"; 1438 os << "\r\n";
1429 //os << ts.read(); 1439 //os << ts.read();
1430 file.close(); 1440 file.close();
1431 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1441 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1432 mSocket->close(); 1442 mSocket->close();
@@ -1446,65 +1456,67 @@ void KServerSocket::get_file()
1446void KServerSocket::readBackFileFromSocket() 1456void KServerSocket::readBackFileFromSocket()
1447{ 1457{
1448 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1458 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1449 while ( mSocket->canReadLine () ) { 1459 while ( mSocket->canReadLine () ) {
1450 piTime.restart(); 1460 piTime.restart();
1451 QString line = mSocket->readLine (); 1461 QString line = mSocket->readLine ();
1452 piFileString += line; 1462 piFileString += line;
1453 //qDebug("readline: %s ", line.latin1()); 1463 //qDebug("readline: %s ", line.latin1());
1454 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1464 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1455 1465
1456 } 1466 }
1457 if ( piTime.elapsed () < 3000 ) { 1467 if ( piTime.elapsed () < 3000 ) {
1458 // wait for more 1468 // wait for more
1459 //qDebug("waitformore "); 1469 //qDebug("waitformore ");
1460 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1470 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1461 return; 1471 return;
1462 } 1472 }
1463 QString fileName = mFileName; 1473 QString fileName = mFileName;
1464 QFile file ( fileName ); 1474 QFile file ( fileName );
1465 if (!file.open( IO_WriteOnly ) ) { 1475 if (!file.open( IO_WriteOnly ) ) {
1466 delete mSyncActionDialog; 1476 delete mSyncActionDialog;
1467 mSyncActionDialog = 0; 1477 mSyncActionDialog = 0;
1468 qDebug("KSS:Error open read back file "); 1478 qDebug("KSS:Error open read back file ");
1469 piFileString = ""; 1479 piFileString = "";
1470 emit file_received( false ); 1480 emit file_received( false, mResource);
1481 emit file_received( false);
1471 blockRC = false; 1482 blockRC = false;
1472 return ; 1483 return ;
1473 1484
1474 } 1485 }
1475 1486
1476 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1487 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1477 QTextStream ts ( &file ); 1488 QTextStream ts ( &file );
1478 ts.setEncoding( QTextStream::Latin1 ); 1489 ts.setEncoding( QTextStream::Latin1 );
1479 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1490 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1480 ts << piFileString; 1491 ts << piFileString;
1481 mSocket->close(); 1492 mSocket->close();
1482 if ( mSocket->state() == QSocket::Idle ) 1493 if ( mSocket->state() == QSocket::Idle )
1483 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1494 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1484 file.close(); 1495 file.close();
1485 piFileString = ""; 1496 piFileString = "";
1486 emit file_received( true ); 1497 emit file_received( true, mResource );
1498 emit file_received( true);
1487 delete mSyncActionDialog; 1499 delete mSyncActionDialog;
1488 mSyncActionDialog = 0; 1500 mSyncActionDialog = 0;
1489 blockRC = false; 1501 blockRC = false;
1490 1502
1491} 1503}
1492 1504
1493KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) 1505KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
1494{ 1506{
1495 mRemoteResource = remres; 1507 mRemoteResource = remres;
1496 if ( mRemoteResource.isEmpty() ) 1508 if ( mRemoteResource.isEmpty() )
1497 mRemoteResource = "ALL"; 1509 mRemoteResource = "ALL";
1498 mPassWord = password; 1510 mPassWord = password;
1499 mSocket = 0; 1511 mSocket = 0;
1500 mFirst = false; 1512 mFirst = false;
1501 mFirstLine = true; 1513 mFirstLine = true;
1502 mPort = port; 1514 mPort = port;
1503 mHost = host; 1515 mHost = host;
1504 tlw = cap; 1516 tlw = cap;
1505 mRetVal = quiet; 1517 mRetVal = quiet;
1506 mTimerSocket = new QTimer ( this ); 1518 mTimerSocket = new QTimer ( this );
1507 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); 1519 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
1508 mConnectProgress.setCaption( i18n("Pi-Sync") ); 1520 mConnectProgress.setCaption( i18n("Pi-Sync") );
1509 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); 1521 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
1510 mConnectCount = -1; 1522 mConnectCount = -1;
@@ -1575,49 +1587,49 @@ void KCommandSocket::writeFile( QString fileName )
1575} 1587}
1576void KCommandSocket::writeFileToSocket() 1588void KCommandSocket::writeFileToSocket()
1577{ 1589{
1578 mTimerSocket->stop(); 1590 mTimerSocket->stop();
1579 QFile file2( mFileName ); 1591 QFile file2( mFileName );
1580 if (!file2.open( IO_ReadOnly ) ) { 1592 if (!file2.open( IO_ReadOnly ) ) {
1581 mConnectProgress.hide(); 1593 mConnectProgress.hide();
1582 mConnectCount = -1; 1594 mConnectCount = -1;
1583 mRetVal= errorW; 1595 mRetVal= errorW;
1584 mSocket->close(); 1596 mSocket->close();
1585 if ( mSocket->state() == QSocket::Idle ) 1597 if ( mSocket->state() == QSocket::Idle )
1586 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1598 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1587 return ; 1599 return ;
1588 } 1600 }
1589 mConnectProgress.setTotalSteps ( file2.size() ); 1601 mConnectProgress.setTotalSteps ( file2.size() );
1590 mConnectProgress.show(); 1602 mConnectProgress.show();
1591 int count = 0; 1603 int count = 0;
1592 mConnectProgress.setLabelText( i18n("Sending back synced file...") ); 1604 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1593 mConnectProgress.setProgress( count ); 1605 mConnectProgress.setProgress( count );
1594 mConnectProgress.blockSignals( true ); 1606 mConnectProgress.blockSignals( true );
1595 QTextStream ts2( &file2 ); 1607 QTextStream ts2( &file2 );
1596 ts2.setEncoding( QTextStream::Latin1 ); 1608 ts2.setEncoding( QTextStream::Latin1 );
1597 QTextStream os2( mSocket ); 1609 QTextStream os2( mSocket );
1598 os2.setEncoding( QTextStream::Latin1 ); 1610 os2.setEncoding( QTextStream::Latin1 );
1599 os2 << "PUT " << mPassWord << "\r\n\r\n";; 1611 os2 << "PUT " << mPassWord << mRemoteResource << "\r\n\r\n";;
1600 int byteCount = 0; 1612 int byteCount = 0;
1601 int byteMax = file2.size()/53; 1613 int byteMax = file2.size()/53;
1602 while ( ! ts2.atEnd() ) { 1614 while ( ! ts2.atEnd() ) {
1603 qApp->processEvents(); 1615 qApp->processEvents();
1604 if ( byteCount > byteMax ) { 1616 if ( byteCount > byteMax ) {
1605 byteCount = 0; 1617 byteCount = 0;
1606 mConnectProgress.setProgress( count ); 1618 mConnectProgress.setProgress( count );
1607 } 1619 }
1608 QString temp = ts2.readLine(); 1620 QString temp = ts2.readLine();
1609 count += temp.length(); 1621 count += temp.length();
1610 byteCount += temp.length(); 1622 byteCount += temp.length();
1611 os2 << temp << "\r\n"; 1623 os2 << temp << "\r\n";
1612 } 1624 }
1613 file2.close(); 1625 file2.close();
1614 mConnectProgress.hide(); 1626 mConnectProgress.hide();
1615 mConnectCount = -1; 1627 mConnectCount = -1;
1616 os2 << "\r\n"; 1628 os2 << "\r\n";
1617 mRetVal= successW; 1629 mRetVal= successW;
1618 mSocket->close(); 1630 mSocket->close();
1619 if ( mSocket->state() == QSocket::Idle ) 1631 if ( mSocket->state() == QSocket::Idle )
1620 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1632 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1621 mConnectProgress.blockSignals( false ); 1633 mConnectProgress.blockSignals( false );
1622} 1634}
1623void KCommandSocket::sendStop() 1635void KCommandSocket::sendStop()