summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 7197b30..b7929ec 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1061,256 +1061,257 @@ bool KSyncManager::syncExternalApplication(QString resource)
1061} 1061}
1062 1062
1063void KSyncManager::syncPhone() 1063void KSyncManager::syncPhone()
1064{ 1064{
1065 1065
1066 syncExternalApplication("phone"); 1066 syncExternalApplication("phone");
1067 1067
1068} 1068}
1069 1069
1070void KSyncManager::showProgressBar(int percentage, QString caption, int total) 1070void KSyncManager::showProgressBar(int percentage, QString caption, int total)
1071{ 1071{
1072 if (!bar->isVisible()) 1072 if (!bar->isVisible())
1073 { 1073 {
1074 int w = 300; 1074 int w = 300;
1075 if ( QApplication::desktop()->width() < 320 ) 1075 if ( QApplication::desktop()->width() < 320 )
1076 w = 220; 1076 w = 220;
1077 int h = bar->sizeHint().height() ; 1077 int h = bar->sizeHint().height() ;
1078 int dw = QApplication::desktop()->width(); 1078 int dw = QApplication::desktop()->width();
1079 int dh = QApplication::desktop()->height(); 1079 int dh = QApplication::desktop()->height();
1080 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1080 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1081 bar->setCaption (caption); 1081 bar->setCaption (caption);
1082 bar->setTotalSteps ( total ) ; 1082 bar->setTotalSteps ( total ) ;
1083 bar->show(); 1083 bar->show();
1084 } 1084 }
1085 bar->raise(); 1085 bar->raise();
1086 bar->setProgress( percentage ); 1086 bar->setProgress( percentage );
1087 qApp->processEvents(); 1087 qApp->processEvents();
1088} 1088}
1089 1089
1090void KSyncManager::hideProgressBar() 1090void KSyncManager::hideProgressBar()
1091{ 1091{
1092 bar->hide(); 1092 bar->hide();
1093 qApp->processEvents(); 1093 qApp->processEvents();
1094} 1094}
1095 1095
1096bool KSyncManager::isProgressBarCanceled() 1096bool KSyncManager::isProgressBarCanceled()
1097{ 1097{
1098 return !bar->isVisible(); 1098 return !bar->isVisible();
1099} 1099}
1100 1100
1101QString KSyncManager::syncFileName() 1101QString KSyncManager::syncFileName()
1102{ 1102{
1103 1103
1104 QString fn = "tempfile"; 1104 QString fn = "tempfile";
1105 switch(mTargetApp) 1105 switch(mTargetApp)
1106 { 1106 {
1107 case (KAPI): 1107 case (KAPI):
1108 fn = "tempsyncab.vcf"; 1108 fn = "tempsyncab.vcf";
1109 break; 1109 break;
1110 case (KOPI): 1110 case (KOPI):
1111 fn = "tempsynccal.ics"; 1111 fn = "tempsynccal.ics";
1112 break; 1112 break;
1113 case (PWMPI): 1113 case (PWMPI):
1114 fn = "tempsyncpw.pwm"; 1114 fn = "tempsyncpw.pwm";
1115 break; 1115 break;
1116 default: 1116 default:
1117 break; 1117 break;
1118 } 1118 }
1119#ifdef DESKTOP_VERSION 1119#ifdef DESKTOP_VERSION
1120 return locateLocal( "tmp", fn ); 1120 return locateLocal( "tmp", fn );
1121#else 1121#else
1122 return (QString( "/tmp/" )+ fn ); 1122 return (QString( "/tmp/" )+ fn );
1123#endif 1123#endif
1124} 1124}
1125 1125
1126void KSyncManager::syncPi() 1126void KSyncManager::syncPi()
1127{ 1127{
1128 mIsKapiFile = true; 1128 mIsKapiFile = true;
1129 mPisyncFinished = false; 1129 mPisyncFinished = false;
1130 qApp->processEvents(); 1130 qApp->processEvents();
1131 if ( mAskForPreferences ) 1131 if ( mAskForPreferences )
1132 if ( !edit_pisync_options()) { 1132 if ( !edit_pisync_options()) {
1133 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1133 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1134 mPisyncFinished = true; 1134 mPisyncFinished = true;
1135 return; 1135 return;
1136 } 1136 }
1137 bool ok; 1137 bool ok;
1138 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1138 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1139 if ( ! ok ) { 1139 if ( ! ok ) {
1140 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1140 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1141 mPisyncFinished = true; 1141 mPisyncFinished = true;
1142 return; 1142 return;
1143 } 1143 }
1144 mCurrentResourceLocal = ""; 1144 mCurrentResourceLocal = "";
1145 mCurrentResourceRemote = ""; 1145 mCurrentResourceRemote = "";
1146 if ( mSpecificResources.count() ) { 1146 if ( mSpecificResources.count() ) {
1147 uint lastSyncRes = mSpecificResources.count()/2; 1147 uint lastSyncRes = mSpecificResources.count()/2;
1148 int ccc = mSpecificResources.count()-1; 1148 int ccc = mSpecificResources.count()-1;
1149 while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) { 1149 while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) {
1150 --ccc; 1150 --ccc;
1151 --lastSyncRes; 1151 --lastSyncRes;
1152 //qDebug ( "KSM: sync pi %d",ccc ); 1152 //qDebug ( "KSM: sync pi %d",ccc );
1153 } 1153 }
1154 uint startLocal = 0; 1154 uint startLocal = 0;
1155 uint startRemote = mSpecificResources.count()/2; 1155 uint startRemote = mSpecificResources.count()/2;
1156 emit multiResourceSyncStart( true ); 1156 emit multiResourceSyncStart( true );
1157 while ( startLocal < mSpecificResources.count()/2 ) { 1157 while ( startLocal < mSpecificResources.count()/2 ) {
1158 if ( startLocal+1 >= lastSyncRes ) 1158 if ( startLocal+1 >= lastSyncRes )
1159 emit multiResourceSyncStart( false ); 1159 emit multiResourceSyncStart( false );
1160 mPisyncFinished = false; 1160 mPisyncFinished = false;
1161 mCurrentResourceLocal = mSpecificResources[ startLocal ]; 1161 mCurrentResourceLocal = mSpecificResources[ startLocal ];
1162 mCurrentResourceRemote = mSpecificResources[ startRemote ]; 1162 mCurrentResourceRemote = mSpecificResources[ startRemote ];
1163 //qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); 1163 //qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() );
1164 if ( !mCurrentResourceRemote.isEmpty() ) { 1164 if ( !mCurrentResourceRemote.isEmpty() ) {
1165 qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); 1165 qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() );
1166 1166
1167 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1167 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1168 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1168 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1169 commandSocket->readFile( syncFileName() ); 1169 commandSocket->readFile( syncFileName() );
1170 mParent->topLevelWidget()->setCaption( i18n("Syncing %1 <-> %2").arg( mCurrentResourceLocal ).arg( mCurrentResourceRemote ) ); 1170 mParent->topLevelWidget()->setCaption( i18n("Syncing %1 <-> %2").arg( mCurrentResourceLocal ).arg( mCurrentResourceRemote ) );
1171 while ( !mPisyncFinished ) { 1171 while ( !mPisyncFinished ) {
1172 //qDebug("waiting "); 1172 //qDebug("waiting ");
1173 qApp->processEvents(); 1173 qApp->processEvents();
1174 } 1174 }
1175 if ( startLocal+1 < mSpecificResources.count()/2 ) { 1175 if ( startLocal+1 < mSpecificResources.count()/2 ) {
1176 mParent->topLevelWidget()->setCaption( i18n("Waiting a second before syncing next resource...") ); 1176 mParent->topLevelWidget()->setCaption( i18n("Waiting a second before syncing next resource...") );
1177 QTime timer; 1177 QTime timer;
1178 timer.start(); 1178 timer.start();
1179 while ( timer.elapsed () < 1000 ) { 1179 while ( timer.elapsed () < 1000 ) {
1180 qApp->processEvents(); 1180 qApp->processEvents();
1181 } 1181 }
1182 } 1182 }
1183 } 1183 }
1184 ++startRemote; 1184 ++startRemote;
1185 ++startLocal; 1185 ++startLocal;
1186 mAskForPreferences = false; 1186 mAskForPreferences = false;
1187 } 1187 }
1188 mPisyncFinished = true; 1188 mPisyncFinished = true;
1189 mParent->topLevelWidget()->setCaption( i18n("Multi-resource Pi-sync finished") );
1189 } else { 1190 } else {
1190 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1191 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1191 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1192 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1192 commandSocket->readFile( syncFileName() ); 1193 commandSocket->readFile( syncFileName() );
1193 } 1194 }
1194} 1195}
1195 1196
1196void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1197void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1197{ 1198{
1198 //enum { success, errorW, errorR, quiet }; 1199 //enum { success, errorW, errorR, quiet };
1199 1200
1200 1201
1201 1202
1202 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || 1203 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW ||
1203 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { 1204 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) {
1204 if ( state == KCommandSocket::errorPW ) 1205 if ( state == KCommandSocket::errorPW )
1205 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); 1206 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") );
1206 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) 1207 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO )
1207 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1208 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1208 else if ( state == KCommandSocket::errorCA ) 1209 else if ( state == KCommandSocket::errorCA )
1209 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); 1210 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") );
1210 else if ( state == KCommandSocket::errorFI ) 1211 else if ( state == KCommandSocket::errorFI )
1211 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); 1212 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") );
1212 else if ( state == KCommandSocket::errorED ) 1213 else if ( state == KCommandSocket::errorED )
1213 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); 1214 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") );
1214 else if ( state == KCommandSocket::errorUN ) 1215 else if ( state == KCommandSocket::errorUN )
1215 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); 1216 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") );
1216 delete s; 1217 delete s;
1217 if ( state == KCommandSocket::errorR ) { 1218 if ( state == KCommandSocket::errorR ) {
1218 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); 1219 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget());
1219 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1220 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1220 commandSocket->sendStop(); 1221 commandSocket->sendStop();
1221 } 1222 }
1222 mPisyncFinished = true; 1223 mPisyncFinished = true;
1223 return; 1224 return;
1224 1225
1225 } else if ( state == KCommandSocket::errorW ) { 1226 } else if ( state == KCommandSocket::errorW ) {
1226 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1227 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1227 mPisyncFinished = true; 1228 mPisyncFinished = true;
1228 1229
1229 } else if ( state == KCommandSocket::successR ) { 1230 } else if ( state == KCommandSocket::successR ) {
1230 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1231 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1231 1232
1232 } else if ( state == KCommandSocket::successW ) { 1233 } else if ( state == KCommandSocket::successW ) {
1233 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 1234 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
1234 mPisyncFinished = true; 1235 mPisyncFinished = true;
1235 } else if ( state == KCommandSocket::quiet ){ 1236 } else if ( state == KCommandSocket::quiet ){
1236 qDebug("KSS: quiet "); 1237 qDebug("KSS: quiet ");
1237 mPisyncFinished = true; 1238 mPisyncFinished = true;
1238 } else { 1239 } else {
1239 qDebug("KSS: Error: unknown state: %d ", state); 1240 qDebug("KSS: Error: unknown state: %d ", state);
1240 mPisyncFinished = true; 1241 mPisyncFinished = true;
1241 } 1242 }
1242 1243
1243 delete s; 1244 delete s;
1244} 1245}
1245 1246
1246void KSyncManager::readFileFromSocket() 1247void KSyncManager::readFileFromSocket()
1247{ 1248{
1248 QString fileName = syncFileName(); 1249 QString fileName = syncFileName();
1249 bool syncOK = true; 1250 bool syncOK = true;
1250 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1251 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1251 if ( ! syncWithFile( fileName , true ) ) { 1252 if ( ! syncWithFile( fileName , true ) ) {
1252 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1253 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1253 syncOK = false; 1254 syncOK = false;
1254 } 1255 }
1255 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1256 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1256 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1257 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1257 if ( mWriteBackFile && syncOK ) { 1258 if ( mWriteBackFile && syncOK ) {
1258 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); 1259 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
1259 commandSocket->writeFile( fileName ); 1260 commandSocket->writeFile( fileName );
1260 } 1261 }
1261 else { 1262 else {
1262 commandSocket->sendStop(); 1263 commandSocket->sendStop();
1263 if ( syncOK ) 1264 if ( syncOK )
1264 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1265 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1265 mPisyncFinished = true; 1266 mPisyncFinished = true;
1266 } 1267 }
1267} 1268}
1268 1269
1269KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1270KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1270{ 1271{
1271 mPendingConnect = 0; 1272 mPendingConnect = 0;
1272 mPassWord = pw; 1273 mPassWord = pw;
1273 mSocket = 0; 1274 mSocket = 0;
1274 mSyncActionDialog = 0; 1275 mSyncActionDialog = 0;
1275 blockRC = false; 1276 blockRC = false;
1276 mErrorMessage = 0; 1277 mErrorMessage = 0;
1277} 1278}
1278void KServerSocket::waitForSocketFinish() 1279void KServerSocket::waitForSocketFinish()
1279{ 1280{
1280 if ( mSocket ) { 1281 if ( mSocket ) {
1281 //qDebug("KSS:: waiting for finish operation"); 1282 //qDebug("KSS:: waiting for finish operation");
1282 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); 1283 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish()));
1283 return; 1284 return;
1284 } 1285 }
1285 mSocket = new QSocket( this ); 1286 mSocket = new QSocket( this );
1286 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1287 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1287 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1288 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1288 mSocket->setSocket( mPendingConnect ); 1289 mSocket->setSocket( mPendingConnect );
1289 mPendingConnect = 0; 1290 mPendingConnect = 0;
1290} 1291}
1291void KServerSocket::newConnection ( int socket ) 1292void KServerSocket::newConnection ( int socket )
1292{ 1293{
1293 // qDebug("KServerSocket:New connection %d ", socket); 1294 // qDebug("KServerSocket:New connection %d ", socket);
1294 if ( mPendingConnect ) { 1295 if ( mPendingConnect ) {
1295 qDebug("KSS::Error : new Connection"); 1296 qDebug("KSS::Error : new Connection");
1296 return; 1297 return;
1297 } 1298 }
1298 if ( mSocket ) { 1299 if ( mSocket ) {
1299 mPendingConnect = socket; 1300 mPendingConnect = socket;
1300 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); 1301 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish()));
1301 return; 1302 return;
1302 qDebug("KSS::newConnection Socket deleted! "); 1303 qDebug("KSS::newConnection Socket deleted! ");
1303 delete mSocket; 1304 delete mSocket;
1304 mSocket = 0; 1305 mSocket = 0;
1305 } 1306 }
1306 mPendingConnect = 0; 1307 mPendingConnect = 0;
1307 mSocket = new QSocket( this ); 1308 mSocket = new QSocket( this );
1308 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1309 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1309 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1310 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1310 mSocket->setSocket( socket ); 1311 mSocket->setSocket( socket );
1311} 1312}
1312 1313
1313void KServerSocket::discardClient() 1314void KServerSocket::discardClient()
1314{ 1315{
1315 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1316 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1316} 1317}