-rw-r--r-- | libkdepim/ksyncmanager.cpp | 5 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 5 |
2 files changed, 5 insertions, 5 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 5d48884..ea543dd 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -86,385 +86,386 @@ void KSyncManager::fillSyncMenu() | |||
86 | mSyncMenu->insertSeparator(); | 86 | mSyncMenu->insertSeparator(); |
87 | if ( mServerSocket == 0 ) { | 87 | if ( mServerSocket == 0 ) { |
88 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 88 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
89 | } else { | 89 | } else { |
90 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 90 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
91 | } | 91 | } |
92 | mSyncMenu->insertSeparator(); | 92 | mSyncMenu->insertSeparator(); |
93 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 93 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
94 | mSyncMenu->insertSeparator(); | 94 | mSyncMenu->insertSeparator(); |
95 | 95 | ||
96 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 96 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
97 | config.setGroup("General"); | 97 | config.setGroup("General"); |
98 | QStringList prof = config.readListEntry("SyncProfileNames"); | 98 | QStringList prof = config.readListEntry("SyncProfileNames"); |
99 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 99 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
100 | if ( prof.count() < 2 ) { | 100 | if ( prof.count() < 2 ) { |
101 | prof.clear(); | 101 | prof.clear(); |
102 | prof << i18n("Sharp_DTM"); | 102 | prof << i18n("Sharp_DTM"); |
103 | prof << i18n("Local_file"); | 103 | prof << i18n("Local_file"); |
104 | KSyncProfile* temp = new KSyncProfile (); | 104 | KSyncProfile* temp = new KSyncProfile (); |
105 | temp->setName( prof[0] ); | 105 | temp->setName( prof[0] ); |
106 | temp->writeConfig(&config); | 106 | temp->writeConfig(&config); |
107 | temp->setName( prof[1] ); | 107 | temp->setName( prof[1] ); |
108 | temp->writeConfig(&config); | 108 | temp->writeConfig(&config); |
109 | config.setGroup("General"); | 109 | config.setGroup("General"); |
110 | config.writeEntry("SyncProfileNames",prof); | 110 | config.writeEntry("SyncProfileNames",prof); |
111 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | 111 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); |
112 | config.sync(); | 112 | config.sync(); |
113 | delete temp; | 113 | delete temp; |
114 | } | 114 | } |
115 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 115 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
116 | mSyncProfileNames = prof; | 116 | mSyncProfileNames = prof; |
117 | unsigned int i; | 117 | unsigned int i; |
118 | for ( i = 0; i < prof.count(); ++i ) { | 118 | for ( i = 0; i < prof.count(); ++i ) { |
119 | mSyncMenu->insertItem( prof[i], 1000+i ); | 119 | mSyncMenu->insertItem( prof[i], 1000+i ); |
120 | if ( i == 2 ) | 120 | if ( i == 2 ) |
121 | mSyncMenu->insertSeparator(); | 121 | mSyncMenu->insertSeparator(); |
122 | } | 122 | } |
123 | QDir app_dir; | 123 | QDir app_dir; |
124 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 124 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
125 | if ( mTargetApp == PWMPI) { | 125 | if ( mTargetApp == PWMPI) { |
126 | mSyncMenu->removeItem( 1000 ); | 126 | mSyncMenu->removeItem( 1000 ); |
127 | } | 127 | } |
128 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 128 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
129 | mSyncMenu->setItemEnabled( 1000, false ); | 129 | mSyncMenu->setItemEnabled( 1000, false ); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | void KSyncManager::slotSyncMenu( int action ) | 133 | void KSyncManager::slotSyncMenu( int action ) |
134 | { | 134 | { |
135 | //qDebug("syncaction %d ", action); | 135 | //qDebug("syncaction %d ", action); |
136 | if ( action == 0 ) { | 136 | if ( action == 0 ) { |
137 | 137 | ||
138 | // seems to be a Qt2 event handling bug | 138 | // seems to be a Qt2 event handling bug |
139 | // syncmenu.clear causes a segfault at first time | 139 | // syncmenu.clear causes a segfault at first time |
140 | // when we call it after the main event loop, it is ok | 140 | // when we call it after the main event loop, it is ok |
141 | // same behaviour when calling OM/Pi via QCOP for the first time | 141 | // same behaviour when calling OM/Pi via QCOP for the first time |
142 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 142 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
143 | //confSync(); | 143 | //confSync(); |
144 | 144 | ||
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | if ( action == 1 ) { | 147 | if ( action == 1 ) { |
148 | multiSync( true ); | 148 | multiSync( true ); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | if ( action == 2 ) { | 151 | if ( action == 2 ) { |
152 | enableQuick(); | 152 | enableQuick(); |
153 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 153 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | if ( action == 3 ) { | 156 | if ( action == 3 ) { |
157 | delete mServerSocket; | 157 | delete mServerSocket; |
158 | mServerSocket = 0; | 158 | mServerSocket = 0; |
159 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 159 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
160 | return; | 160 | return; |
161 | } | 161 | } |
162 | 162 | ||
163 | if (blockSave()) | 163 | if (blockSave()) |
164 | return; | 164 | return; |
165 | 165 | ||
166 | setBlockSave(true); | 166 | setBlockSave(true); |
167 | 167 | ||
168 | mCurrentSyncProfile = action - 1000 ; | 168 | mCurrentSyncProfile = action - 1000 ; |
169 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 169 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
170 | mCurrentSyncName = mLocalMachineName ; | 170 | mCurrentSyncName = mLocalMachineName ; |
171 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 171 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
172 | KSyncProfile* temp = new KSyncProfile (); | 172 | KSyncProfile* temp = new KSyncProfile (); |
173 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 173 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
174 | temp->readConfig(&config); | 174 | temp->readConfig(&config); |
175 | mAskForPreferences = temp->getAskForPreferences(); | 175 | mAskForPreferences = temp->getAskForPreferences(); |
176 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 176 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
177 | mWriteBackFile = temp->getWriteBackFile(); | 177 | mWriteBackFile = temp->getWriteBackFile(); |
178 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 178 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
179 | mWriteBackInFuture = 0; | 179 | mWriteBackInFuture = 0; |
180 | if ( temp->getWriteBackFuture() ) | 180 | if ( temp->getWriteBackFuture() ) |
181 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 181 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
182 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 182 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
183 | if ( action == 1000 ) { | 183 | if ( action == 1000 ) { |
184 | syncSharp(); | 184 | syncSharp(); |
185 | 185 | ||
186 | } else if ( action == 1001 ) { | 186 | } else if ( action == 1001 ) { |
187 | syncLocalFile(); | 187 | syncLocalFile(); |
188 | 188 | ||
189 | } else if ( action == 1002 ) { | 189 | } else if ( action == 1002 ) { |
190 | quickSyncLocalFile(); | 190 | quickSyncLocalFile(); |
191 | 191 | ||
192 | } else if ( action >= 1003 ) { | 192 | } else if ( action >= 1003 ) { |
193 | if ( temp->getIsLocalFileSync() ) { | 193 | if ( temp->getIsLocalFileSync() ) { |
194 | switch(mTargetApp) | 194 | switch(mTargetApp) |
195 | { | 195 | { |
196 | case (KAPI): | 196 | case (KAPI): |
197 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 197 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
198 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 198 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
199 | break; | 199 | break; |
200 | case (KOPI): | 200 | case (KOPI): |
201 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 201 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
202 | mLastSyncedLocalFile = temp->getRemoteFileName(); | 202 | mLastSyncedLocalFile = temp->getRemoteFileName(); |
203 | break; | 203 | break; |
204 | case (PWMPI): | 204 | case (PWMPI): |
205 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 205 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
206 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 206 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
207 | break; | 207 | break; |
208 | default: | 208 | default: |
209 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 209 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
210 | break; | 210 | break; |
211 | 211 | ||
212 | } | 212 | } |
213 | } else { | 213 | } else { |
214 | if ( temp->getIsPhoneSync() ) { | 214 | if ( temp->getIsPhoneSync() ) { |
215 | mPhoneDevice = temp->getPhoneDevice( ) ; | 215 | mPhoneDevice = temp->getPhoneDevice( ) ; |
216 | mPhoneConnection = temp->getPhoneConnection( ); | 216 | mPhoneConnection = temp->getPhoneConnection( ); |
217 | mPhoneModel = temp->getPhoneModel( ); | 217 | mPhoneModel = temp->getPhoneModel( ); |
218 | syncPhone(); | 218 | syncPhone(); |
219 | } else if ( temp->getIsPiSync() ) { | 219 | } else if ( temp->getIsPiSync() ) { |
220 | mPassWordPiSync = temp->getRemotePw(); | 220 | mPassWordPiSync = temp->getRemotePw(); |
221 | mActiveSyncPort = temp->getRemotePort(); | 221 | mActiveSyncPort = temp->getRemotePort(); |
222 | mActiveSyncIP = temp->getRemoteIP(); | 222 | mActiveSyncIP = temp->getRemoteIP(); |
223 | syncPi(); | 223 | syncPi(); |
224 | } | 224 | } |
225 | syncRemote( temp ); | 225 | syncRemote( temp ); |
226 | 226 | ||
227 | } | 227 | } |
228 | } | 228 | } |
229 | delete temp; | 229 | delete temp; |
230 | setBlockSave(false); | 230 | setBlockSave(false); |
231 | } | 231 | } |
232 | void KSyncManager::enableQuick() | 232 | void KSyncManager::enableQuick() |
233 | { | 233 | { |
234 | QDialog dia ( 0, "input-dialog", true ); | 234 | QDialog dia ( 0, "input-dialog", true ); |
235 | QLineEdit lab ( &dia ); | 235 | QLineEdit lab ( &dia ); |
236 | QVBoxLayout lay( &dia ); | 236 | QVBoxLayout lay( &dia ); |
237 | lab.setText( mPrefs->mPassiveSyncPort ); | 237 | lab.setText( mPrefs->mPassiveSyncPort ); |
238 | lay.setMargin(7); | 238 | lay.setMargin(7); |
239 | lay.setSpacing(7); | 239 | lay.setSpacing(7); |
240 | int po = 9197+mTargetApp; | 240 | int po = 9197+mTargetApp; |
241 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 241 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
242 | lay.addWidget( &label); | 242 | lay.addWidget( &label); |
243 | lay.addWidget( &lab); | 243 | lay.addWidget( &lab); |
244 | 244 | ||
245 | QLineEdit lepw ( &dia ); | 245 | QLineEdit lepw ( &dia ); |
246 | lepw.setText( mPrefs->mPassiveSyncPw ); | 246 | lepw.setText( mPrefs->mPassiveSyncPw ); |
247 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 247 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
248 | lay.addWidget( &label2); | 248 | lay.addWidget( &label2); |
249 | lay.addWidget( &lepw); | 249 | lay.addWidget( &lepw); |
250 | dia.setFixedSize( 230,80 ); | 250 | dia.setFixedSize( 230,80 ); |
251 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 251 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
252 | QPushButton pb ( "OK", &dia); | 252 | QPushButton pb ( "OK", &dia); |
253 | lay.addWidget( &pb ); | 253 | lay.addWidget( &pb ); |
254 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 254 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
255 | dia.show(); | 255 | dia.show(); |
256 | if ( ! dia.exec() ) | 256 | if ( ! dia.exec() ) |
257 | return; | 257 | return; |
258 | dia.hide(); | 258 | dia.hide(); |
259 | qApp->processEvents(); | 259 | qApp->processEvents(); |
260 | mPrefs->mPassiveSyncPw = lepw.text(); | 260 | mPrefs->mPassiveSyncPw = lepw.text(); |
261 | mPrefs->mPassiveSyncPort = lab.text(); | 261 | mPrefs->mPassiveSyncPort = lab.text(); |
262 | bool ok; | 262 | bool ok; |
263 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 263 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
264 | if ( ! ok ) { | 264 | if ( ! ok ) { |
265 | KMessageBox::information( 0, i18n("No valid port")); | 265 | KMessageBox::information( 0, i18n("No valid port")); |
266 | return; | 266 | return; |
267 | } | 267 | } |
268 | //qDebug("port %d ", port); | 268 | //qDebug("port %d ", port); |
269 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 269 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
270 | mServerSocket->setFileName( defaultFileName() ); | 270 | mServerSocket->setFileName( defaultFileName() ); |
271 | //qDebug("connected "); | 271 | //qDebug("connected "); |
272 | if ( !mServerSocket->ok() ) { | 272 | if ( !mServerSocket->ok() ) { |
273 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 273 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
274 | delete mServerSocket; | 274 | delete mServerSocket; |
275 | mServerSocket = 0; | 275 | mServerSocket = 0; |
276 | return; | 276 | return; |
277 | } | 277 | } |
278 | connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); | 278 | //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); |
279 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | ||
279 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 280 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
280 | } | 281 | } |
281 | 282 | ||
282 | void KSyncManager::syncLocalFile() | 283 | void KSyncManager::syncLocalFile() |
283 | { | 284 | { |
284 | 285 | ||
285 | QString fn =mLastSyncedLocalFile; | 286 | QString fn =mLastSyncedLocalFile; |
286 | QString ext; | 287 | QString ext; |
287 | 288 | ||
288 | switch(mTargetApp) | 289 | switch(mTargetApp) |
289 | { | 290 | { |
290 | case (KAPI): | 291 | case (KAPI): |
291 | ext = "(*.vcf)"; | 292 | ext = "(*.vcf)"; |
292 | break; | 293 | break; |
293 | case (KOPI): | 294 | case (KOPI): |
294 | ext = "(*.ics/*.vcs)"; | 295 | ext = "(*.ics/*.vcs)"; |
295 | break; | 296 | break; |
296 | case (PWMPI): | 297 | case (PWMPI): |
297 | ext = "(*.pwm)"; | 298 | ext = "(*.pwm)"; |
298 | break; | 299 | break; |
299 | default: | 300 | default: |
300 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 301 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
301 | break; | 302 | break; |
302 | 303 | ||
303 | } | 304 | } |
304 | 305 | ||
305 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 306 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
306 | if ( fn == "" ) | 307 | if ( fn == "" ) |
307 | return; | 308 | return; |
308 | if ( syncWithFile( fn, false ) ) { | 309 | if ( syncWithFile( fn, false ) ) { |
309 | qDebug("syncLocalFile() successful "); | 310 | qDebug("syncLocalFile() successful "); |
310 | } | 311 | } |
311 | 312 | ||
312 | } | 313 | } |
313 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 314 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
314 | { | 315 | { |
315 | bool ret = false; | 316 | bool ret = false; |
316 | QFileInfo info; | 317 | QFileInfo info; |
317 | info.setFile( fn ); | 318 | info.setFile( fn ); |
318 | QString mess; | 319 | QString mess; |
319 | bool loadbup = true; | 320 | bool loadbup = true; |
320 | if ( !info. exists() ) { | 321 | if ( !info. exists() ) { |
321 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 322 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
322 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 323 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
323 | mess ); | 324 | mess ); |
324 | return ret; | 325 | return ret; |
325 | } | 326 | } |
326 | int result = 0; | 327 | int result = 0; |
327 | if ( !quick ) { | 328 | if ( !quick ) { |
328 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 329 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
329 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 330 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
330 | mess, | 331 | mess, |
331 | i18n("Sync"), i18n("Cancel"), 0, | 332 | i18n("Sync"), i18n("Cancel"), 0, |
332 | 0, 1 ); | 333 | 0, 1 ); |
333 | if ( result ) | 334 | if ( result ) |
334 | return false; | 335 | return false; |
335 | } | 336 | } |
336 | if ( mAskForPreferences ) | 337 | if ( mAskForPreferences ) |
337 | edit_sync_options(); | 338 | edit_sync_options(); |
338 | if ( result == 0 ) { | 339 | if ( result == 0 ) { |
339 | //qDebug("Now sycing ... "); | 340 | //qDebug("Now sycing ... "); |
340 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 341 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
341 | mParent->setCaption( i18n("Synchronization successful") ); | 342 | mParent->setCaption( i18n("Synchronization successful") ); |
342 | else | 343 | else |
343 | mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 344 | mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
344 | if ( ! quick ) | 345 | if ( ! quick ) |
345 | mLastSyncedLocalFile = fn; | 346 | mLastSyncedLocalFile = fn; |
346 | } | 347 | } |
347 | return ret; | 348 | return ret; |
348 | } | 349 | } |
349 | void KSyncManager::quickSyncLocalFile() | 350 | void KSyncManager::quickSyncLocalFile() |
350 | { | 351 | { |
351 | 352 | ||
352 | if ( syncWithFile( mLastSyncedLocalFile, false ) ) { | 353 | if ( syncWithFile( mLastSyncedLocalFile, false ) ) { |
353 | qDebug("quick syncLocalFile() successful "); | 354 | qDebug("quick syncLocalFile() successful "); |
354 | 355 | ||
355 | } | 356 | } |
356 | } | 357 | } |
357 | void KSyncManager::multiSync( bool askforPrefs ) | 358 | void KSyncManager::multiSync( bool askforPrefs ) |
358 | { | 359 | { |
359 | if (blockSave()) | 360 | if (blockSave()) |
360 | return; | 361 | return; |
361 | setBlockSave(true); | 362 | setBlockSave(true); |
362 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 363 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
363 | if ( QMessageBox::information( mParent, i18n("Sync"), | 364 | if ( QMessageBox::information( mParent, i18n("Sync"), |
364 | question, | 365 | question, |
365 | i18n("Yes"), i18n("No"), | 366 | i18n("Yes"), i18n("No"), |
366 | 0, 0 ) != 0 ) { | 367 | 0, 0 ) != 0 ) { |
367 | setBlockSave(false); | 368 | setBlockSave(false); |
368 | mParent->setCaption(i18n("Aborted! Nothing synced!")); | 369 | mParent->setCaption(i18n("Aborted! Nothing synced!")); |
369 | return; | 370 | return; |
370 | } | 371 | } |
371 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 372 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
372 | mSyncAlgoPrefs = mRingSyncAlgoPrefs; | 373 | mSyncAlgoPrefs = mRingSyncAlgoPrefs; |
373 | if ( askforPrefs ) { | 374 | if ( askforPrefs ) { |
374 | edit_sync_options(); | 375 | edit_sync_options(); |
375 | mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 376 | mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
376 | } | 377 | } |
377 | mParent->setCaption(i18n("Multiple sync started.") ); | 378 | mParent->setCaption(i18n("Multiple sync started.") ); |
378 | qApp->processEvents(); | 379 | qApp->processEvents(); |
379 | int num = ringSync() ; | 380 | int num = ringSync() ; |
380 | if ( num > 1 ) | 381 | if ( num > 1 ) |
381 | ringSync(); | 382 | ringSync(); |
382 | setBlockSave(false); | 383 | setBlockSave(false); |
383 | if ( num ) | 384 | if ( num ) |
384 | emit save(); | 385 | emit save(); |
385 | if ( num ) | 386 | if ( num ) |
386 | mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); | 387 | mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); |
387 | else | 388 | else |
388 | mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 389 | mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
389 | return; | 390 | return; |
390 | } | 391 | } |
391 | int KSyncManager::ringSync() | 392 | int KSyncManager::ringSync() |
392 | { | 393 | { |
393 | int syncedProfiles = 0; | 394 | int syncedProfiles = 0; |
394 | unsigned int i; | 395 | unsigned int i; |
395 | QTime timer; | 396 | QTime timer; |
396 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 397 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
397 | QStringList syncProfileNames = mSyncProfileNames; | 398 | QStringList syncProfileNames = mSyncProfileNames; |
398 | KSyncProfile* temp = new KSyncProfile (); | 399 | KSyncProfile* temp = new KSyncProfile (); |
399 | mAskForPreferences = false; | 400 | mAskForPreferences = false; |
400 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 401 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
401 | mCurrentSyncProfile = i; | 402 | mCurrentSyncProfile = i; |
402 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 403 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
403 | temp->readConfig(&config); | 404 | temp->readConfig(&config); |
404 | 405 | ||
405 | QString includeInRingSync; | 406 | QString includeInRingSync; |
406 | switch(mTargetApp) | 407 | switch(mTargetApp) |
407 | { | 408 | { |
408 | case (KAPI): | 409 | case (KAPI): |
409 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 410 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
410 | break; | 411 | break; |
411 | case (KOPI): | 412 | case (KOPI): |
412 | includeInRingSync = temp->getIncludeInRingSync(); | 413 | includeInRingSync = temp->getIncludeInRingSync(); |
413 | break; | 414 | break; |
414 | case (PWMPI): | 415 | case (PWMPI): |
415 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 416 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
416 | break; | 417 | break; |
417 | default: | 418 | default: |
418 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 419 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
419 | break; | 420 | break; |
420 | 421 | ||
421 | } | 422 | } |
422 | 423 | ||
423 | 424 | ||
424 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 425 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
425 | mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 426 | mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
426 | ++syncedProfiles; | 427 | ++syncedProfiles; |
427 | // mAskForPreferences = temp->getAskForPreferences(); | 428 | // mAskForPreferences = temp->getAskForPreferences(); |
428 | mWriteBackFile = temp->getWriteBackFile(); | 429 | mWriteBackFile = temp->getWriteBackFile(); |
429 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 430 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
430 | mWriteBackInFuture = 0; | 431 | mWriteBackInFuture = 0; |
431 | if ( temp->getWriteBackFuture() ) | 432 | if ( temp->getWriteBackFuture() ) |
432 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 433 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
433 | mShowSyncSummary = false; | 434 | mShowSyncSummary = false; |
434 | mCurrentSyncDevice = syncProfileNames[i] ; | 435 | mCurrentSyncDevice = syncProfileNames[i] ; |
435 | mCurrentSyncName = mLocalMachineName; | 436 | mCurrentSyncName = mLocalMachineName; |
436 | if ( i == 0 ) { | 437 | if ( i == 0 ) { |
437 | syncSharp(); | 438 | syncSharp(); |
438 | } else { | 439 | } else { |
439 | if ( temp->getIsLocalFileSync() ) { | 440 | if ( temp->getIsLocalFileSync() ) { |
440 | switch(mTargetApp) | 441 | switch(mTargetApp) |
441 | { | 442 | { |
442 | case (KAPI): | 443 | case (KAPI): |
443 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 444 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
444 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 445 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
445 | break; | 446 | break; |
446 | case (KOPI): | 447 | case (KOPI): |
447 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 448 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
448 | mLastSyncedLocalFile = temp->getRemoteFileName(); | 449 | mLastSyncedLocalFile = temp->getRemoteFileName(); |
449 | break; | 450 | break; |
450 | case (PWMPI): | 451 | case (PWMPI): |
451 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 452 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
452 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 453 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
453 | break; | 454 | break; |
454 | default: | 455 | default: |
455 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 456 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
456 | break; | 457 | break; |
457 | } | 458 | } |
458 | } else { | 459 | } else { |
459 | if ( temp->getIsPhoneSync() ) { | 460 | if ( temp->getIsPhoneSync() ) { |
460 | mPhoneDevice = temp->getPhoneDevice( ) ; | 461 | mPhoneDevice = temp->getPhoneDevice( ) ; |
461 | mPhoneConnection = temp->getPhoneConnection( ); | 462 | mPhoneConnection = temp->getPhoneConnection( ); |
462 | mPhoneModel = temp->getPhoneModel( ); | 463 | mPhoneModel = temp->getPhoneModel( ); |
463 | syncPhone(); | 464 | syncPhone(); |
464 | } else | 465 | } else |
465 | syncRemote( temp, false ); | 466 | syncRemote( temp, false ); |
466 | 467 | ||
467 | } | 468 | } |
468 | } | 469 | } |
469 | timer.start(); | 470 | timer.start(); |
470 | mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 471 | mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
@@ -739,385 +740,385 @@ QString KSyncManager::syncFileName() | |||
739 | { | 740 | { |
740 | case (KAPI): | 741 | case (KAPI): |
741 | fn = "addressbook.vcf"; | 742 | fn = "addressbook.vcf"; |
742 | break; | 743 | break; |
743 | case (KOPI): | 744 | case (KOPI): |
744 | fn = "synccalendar.ics"; | 745 | fn = "synccalendar.ics"; |
745 | break; | 746 | break; |
746 | case (PWMPI): | 747 | case (PWMPI): |
747 | fn = "manager.pwm"; | 748 | fn = "manager.pwm"; |
748 | break; | 749 | break; |
749 | default: | 750 | default: |
750 | break; | 751 | break; |
751 | } | 752 | } |
752 | #ifdef _WIN32_ | 753 | #ifdef _WIN32_ |
753 | return locateLocal( "tmp", fn ); | 754 | return locateLocal( "tmp", fn ); |
754 | #else | 755 | #else |
755 | return (QString( "/tmp/" )+ fn ); | 756 | return (QString( "/tmp/" )+ fn ); |
756 | #endif | 757 | #endif |
757 | } | 758 | } |
758 | 759 | ||
759 | void KSyncManager::syncPi() | 760 | void KSyncManager::syncPi() |
760 | { | 761 | { |
761 | qApp->processEvents(); | 762 | qApp->processEvents(); |
762 | bool ok; | 763 | bool ok; |
763 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 764 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
764 | if ( ! ok ) { | 765 | if ( ! ok ) { |
765 | mParent->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 766 | mParent->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
766 | return; | 767 | return; |
767 | } | 768 | } |
768 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 769 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
769 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 770 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
770 | mParent->setCaption( i18n("Sending request for remote file ...") ); | 771 | mParent->setCaption( i18n("Sending request for remote file ...") ); |
771 | commandSocket->readFile( syncFileName() ); | 772 | commandSocket->readFile( syncFileName() ); |
772 | } | 773 | } |
773 | 774 | ||
774 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 775 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
775 | { | 776 | { |
776 | qDebug("MainWindow::deleteCommandSocket %d", state); | 777 | qDebug("MainWindow::deleteCommandSocket %d", state); |
777 | 778 | ||
778 | //enum { success, errorW, errorR, quiet }; | 779 | //enum { success, errorW, errorR, quiet }; |
779 | if ( state == KCommandSocket::errorR ) { | 780 | if ( state == KCommandSocket::errorR ) { |
780 | mParent->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 781 | mParent->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
781 | delete s; | 782 | delete s; |
782 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 783 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
783 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 784 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
784 | commandSocket->sendStop(); | 785 | commandSocket->sendStop(); |
785 | return; | 786 | return; |
786 | 787 | ||
787 | } else if ( state == KCommandSocket::errorW ) { | 788 | } else if ( state == KCommandSocket::errorW ) { |
788 | mParent->setCaption( i18n("ERROR:Writing back file failed.") ); | 789 | mParent->setCaption( i18n("ERROR:Writing back file failed.") ); |
789 | 790 | ||
790 | } else if ( state == KCommandSocket::successR ) { | 791 | } else if ( state == KCommandSocket::successR ) { |
791 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 792 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
792 | 793 | ||
793 | } else if ( state == KCommandSocket::successW ) { | 794 | } else if ( state == KCommandSocket::successW ) { |
794 | mParent->setCaption( i18n("Pi-Sync succesful!") ); | 795 | mParent->setCaption( i18n("Pi-Sync succesful!") ); |
795 | } | 796 | } |
796 | 797 | ||
797 | delete s; | 798 | delete s; |
798 | } | 799 | } |
799 | 800 | ||
800 | void KSyncManager::readFileFromSocket() | 801 | void KSyncManager::readFileFromSocket() |
801 | { | 802 | { |
802 | QString fileName = syncFileName(); | 803 | QString fileName = syncFileName(); |
803 | mParent->setCaption( i18n("Remote file saved to temp file.") ); | 804 | mParent->setCaption( i18n("Remote file saved to temp file.") ); |
804 | if ( ! syncWithFile( fileName , true ) ) { | 805 | if ( ! syncWithFile( fileName , true ) ) { |
805 | mParent->setCaption( i18n("Syncing failed.") ); | 806 | mParent->setCaption( i18n("Syncing failed.") ); |
806 | qDebug("Syncing failed "); | 807 | qDebug("Syncing failed "); |
807 | return; | 808 | return; |
808 | } | 809 | } |
809 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 810 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
810 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 811 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
811 | if ( mWriteBackFile ) | 812 | if ( mWriteBackFile ) |
812 | commandSocket->writeFile( fileName ); | 813 | commandSocket->writeFile( fileName ); |
813 | else { | 814 | else { |
814 | commandSocket->sendStop(); | 815 | commandSocket->sendStop(); |
815 | mParent->setCaption( i18n("Pi-Sync succesful!") ); | 816 | mParent->setCaption( i18n("Pi-Sync succesful!") ); |
816 | } | 817 | } |
817 | } | 818 | } |
818 | 819 | ||
819 | 820 | ||
820 | 821 | ||
821 | 822 | ||
822 | 823 | ||
823 | 824 | ||
824 | 825 | ||
825 | 826 | ||
826 | 827 | ||
827 | 828 | ||
828 | 829 | ||
829 | 830 | ||
830 | 831 | ||
831 | 832 | ||
832 | 833 | ||
833 | 834 | ||
834 | 835 | ||
835 | 836 | ||
836 | 837 | ||
837 | 838 | ||
838 | 839 | ||
839 | 840 | ||
840 | 841 | ||
841 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 842 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
842 | { | 843 | { |
843 | mPassWord = pw; | 844 | mPassWord = pw; |
844 | mSocket = 0; | 845 | mSocket = 0; |
845 | mSyncActionDialog = 0; | 846 | mSyncActionDialog = 0; |
846 | blockRC = false; | 847 | blockRC = false; |
847 | }; | 848 | }; |
848 | 849 | ||
849 | void KServerSocket::newConnection ( int socket ) | 850 | void KServerSocket::newConnection ( int socket ) |
850 | { | 851 | { |
851 | // qDebug("KServerSocket:New connection %d ", socket); | 852 | // qDebug("KServerSocket:New connection %d ", socket); |
852 | if ( mSocket ) { | 853 | if ( mSocket ) { |
853 | qDebug("KServerSocket::newConnection Socket deleted! "); | 854 | qDebug("KServerSocket::newConnection Socket deleted! "); |
854 | delete mSocket; | 855 | delete mSocket; |
855 | mSocket = 0; | 856 | mSocket = 0; |
856 | } | 857 | } |
857 | mSocket = new QSocket( this ); | 858 | mSocket = new QSocket( this ); |
858 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 859 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
859 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 860 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
860 | mSocket->setSocket( socket ); | 861 | mSocket->setSocket( socket ); |
861 | } | 862 | } |
862 | 863 | ||
863 | void KServerSocket::discardClient() | 864 | void KServerSocket::discardClient() |
864 | { | 865 | { |
865 | //qDebug(" KServerSocket::discardClient()"); | 866 | //qDebug(" KServerSocket::discardClient()"); |
866 | if ( mSocket ) { | 867 | if ( mSocket ) { |
867 | delete mSocket; | 868 | delete mSocket; |
868 | mSocket = 0; | 869 | mSocket = 0; |
869 | } | 870 | } |
870 | //emit endConnect(); | 871 | //emit endConnect(); |
871 | } | 872 | } |
872 | void KServerSocket::readClient() | 873 | void KServerSocket::readClient() |
873 | { | 874 | { |
874 | if ( blockRC ) | 875 | if ( blockRC ) |
875 | return; | 876 | return; |
876 | if ( mSocket == 0 ) { | 877 | if ( mSocket == 0 ) { |
877 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 878 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
878 | return; | 879 | return; |
879 | } | 880 | } |
880 | qDebug("KServerSocket readClient()"); | 881 | qDebug("KServerSocket readClient()"); |
881 | if ( mSocket->canReadLine() ) { | 882 | if ( mSocket->canReadLine() ) { |
882 | QString line = mSocket->readLine(); | 883 | QString line = mSocket->readLine(); |
883 | qDebug("KServerSocket readline: %s ", line.latin1()); | 884 | qDebug("KServerSocket readline: %s ", line.latin1()); |
884 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 885 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
885 | if ( tokens[0] == "GET" ) { | 886 | if ( tokens[0] == "GET" ) { |
886 | if ( tokens[1] == mPassWord ) | 887 | if ( tokens[1] == mPassWord ) |
887 | //emit sendFile( mSocket ); | 888 | //emit sendFile( mSocket ); |
888 | send_file(); | 889 | send_file(); |
889 | else { | 890 | else { |
890 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); | 891 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); |
891 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 892 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
892 | } | 893 | } |
893 | } | 894 | } |
894 | if ( tokens[0] == "PUT" ) { | 895 | if ( tokens[0] == "PUT" ) { |
895 | if ( tokens[1] == mPassWord ) { | 896 | if ( tokens[1] == mPassWord ) { |
896 | //emit getFile( mSocket ); | 897 | //emit getFile( mSocket ); |
897 | blockRC = true; | 898 | blockRC = true; |
898 | get_file(); | 899 | get_file(); |
899 | } | 900 | } |
900 | else { | 901 | else { |
901 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); | 902 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); |
902 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 903 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
903 | } | 904 | } |
904 | } | 905 | } |
905 | if ( tokens[0] == "STOP" ) { | 906 | if ( tokens[0] == "STOP" ) { |
906 | //emit endConnect(); | 907 | //emit endConnect(); |
907 | end_connect(); | 908 | end_connect(); |
908 | } | 909 | } |
909 | } | 910 | } |
910 | } | 911 | } |
911 | void KServerSocket::end_connect() | 912 | void KServerSocket::end_connect() |
912 | { | 913 | { |
913 | delete mSyncActionDialog; | 914 | delete mSyncActionDialog; |
914 | mSyncActionDialog = 0; | 915 | mSyncActionDialog = 0; |
915 | } | 916 | } |
916 | void KServerSocket::send_file() | 917 | void KServerSocket::send_file() |
917 | { | 918 | { |
918 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 919 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
919 | if ( mSyncActionDialog ) | 920 | if ( mSyncActionDialog ) |
920 | delete mSyncActionDialog; | 921 | delete mSyncActionDialog; |
921 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 922 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
922 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 923 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
923 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 924 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
924 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 925 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
925 | lay->addWidget( label); | 926 | lay->addWidget( label); |
926 | lay->setMargin(7); | 927 | lay->setMargin(7); |
927 | lay->setSpacing(7); | 928 | lay->setSpacing(7); |
928 | mSyncActionDialog->setFixedSize( 230, 120); | 929 | mSyncActionDialog->setFixedSize( 230, 120); |
929 | mSyncActionDialog->show(); | 930 | mSyncActionDialog->show(); |
930 | qDebug("KSS::saving ... "); | 931 | qDebug("KSS::saving ... "); |
931 | emit saveFile(); | 932 | emit request_file(); |
932 | qApp->processEvents(); | 933 | qApp->processEvents(); |
933 | QString fileName = mFileName; | 934 | QString fileName = mFileName; |
934 | QFile file( fileName ); | 935 | QFile file( fileName ); |
935 | if (!file.open( IO_ReadOnly ) ) { | 936 | if (!file.open( IO_ReadOnly ) ) { |
936 | delete mSyncActionDialog; | 937 | delete mSyncActionDialog; |
937 | mSyncActionDialog = 0; | 938 | mSyncActionDialog = 0; |
938 | qDebug("KSS::error open file "); | 939 | qDebug("KSS::error open file "); |
939 | mSocket->close(); | 940 | mSocket->close(); |
940 | if ( mSocket->state() == QSocket::Idle ) | 941 | if ( mSocket->state() == QSocket::Idle ) |
941 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 942 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
942 | return ; | 943 | return ; |
943 | 944 | ||
944 | } | 945 | } |
945 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 946 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
946 | QTextStream ts( &file ); | 947 | QTextStream ts( &file ); |
947 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 948 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
948 | QTextStream os( mSocket ); | 949 | QTextStream os( mSocket ); |
949 | os.setCodec( QTextCodec::codecForName("utf8") ); | 950 | os.setCodec( QTextCodec::codecForName("utf8") ); |
950 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 951 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
951 | while ( ! ts.atEnd() ) { | 952 | while ( ! ts.atEnd() ) { |
952 | os << ts.readLine() << "\n"; | 953 | os << ts.readLine() << "\n"; |
953 | } | 954 | } |
954 | //os << ts.read(); | 955 | //os << ts.read(); |
955 | file.close(); | 956 | file.close(); |
956 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 957 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
957 | mSocket->close(); | 958 | mSocket->close(); |
958 | if ( mSocket->state() == QSocket::Idle ) | 959 | if ( mSocket->state() == QSocket::Idle ) |
959 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 960 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
960 | } | 961 | } |
961 | void KServerSocket::get_file() | 962 | void KServerSocket::get_file() |
962 | { | 963 | { |
963 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 964 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
964 | 965 | ||
965 | piTime.start(); | 966 | piTime.start(); |
966 | piFileString = ""; | 967 | piFileString = ""; |
967 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 968 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
968 | } | 969 | } |
969 | 970 | ||
970 | 971 | ||
971 | void KServerSocket::readBackFileFromSocket() | 972 | void KServerSocket::readBackFileFromSocket() |
972 | { | 973 | { |
973 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 974 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
974 | while ( mSocket->canReadLine () ) { | 975 | while ( mSocket->canReadLine () ) { |
975 | piTime.restart(); | 976 | piTime.restart(); |
976 | QString line = mSocket->readLine (); | 977 | QString line = mSocket->readLine (); |
977 | piFileString += line; | 978 | piFileString += line; |
978 | //qDebug("readline: %s ", line.latin1()); | 979 | //qDebug("readline: %s ", line.latin1()); |
979 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 980 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
980 | 981 | ||
981 | } | 982 | } |
982 | if ( piTime.elapsed () < 3000 ) { | 983 | if ( piTime.elapsed () < 3000 ) { |
983 | // wait for more | 984 | // wait for more |
984 | //qDebug("waitformore "); | 985 | //qDebug("waitformore "); |
985 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 986 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
986 | return; | 987 | return; |
987 | } | 988 | } |
988 | QString fileName = mFileName; | 989 | QString fileName = mFileName; |
989 | QFile file ( fileName ); | 990 | QFile file ( fileName ); |
990 | if (!file.open( IO_WriteOnly ) ) { | 991 | if (!file.open( IO_WriteOnly ) ) { |
991 | delete mSyncActionDialog; | 992 | delete mSyncActionDialog; |
992 | mSyncActionDialog = 0; | 993 | mSyncActionDialog = 0; |
993 | qDebug("error open cal file "); | 994 | qDebug("error open cal file "); |
994 | piFileString = ""; | 995 | piFileString = ""; |
995 | emit file_received( false ); | 996 | emit file_received( false ); |
996 | blockRC = false; | 997 | blockRC = false; |
997 | return ; | 998 | return ; |
998 | 999 | ||
999 | } | 1000 | } |
1000 | 1001 | ||
1001 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1002 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1002 | QTextStream ts ( &file ); | 1003 | QTextStream ts ( &file ); |
1003 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 1004 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
1004 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1005 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1005 | ts << piFileString; | 1006 | ts << piFileString; |
1006 | mSocket->close(); | 1007 | mSocket->close(); |
1007 | if ( mSocket->state() == QSocket::Idle ) | 1008 | if ( mSocket->state() == QSocket::Idle ) |
1008 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1009 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1009 | file.close(); | 1010 | file.close(); |
1010 | delete mSyncActionDialog; | 1011 | delete mSyncActionDialog; |
1011 | mSyncActionDialog = 0; | 1012 | mSyncActionDialog = 0; |
1012 | piFileString = ""; | 1013 | piFileString = ""; |
1013 | blockRC = false; | 1014 | blockRC = false; |
1014 | emit file_received( true ); | 1015 | emit file_received( true ); |
1015 | 1016 | ||
1016 | } | 1017 | } |
1017 | 1018 | ||
1018 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1019 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1019 | { | 1020 | { |
1020 | mPassWord = password; | 1021 | mPassWord = password; |
1021 | mSocket = 0; | 1022 | mSocket = 0; |
1022 | mPort = port; | 1023 | mPort = port; |
1023 | mHost = host; | 1024 | mHost = host; |
1024 | 1025 | ||
1025 | mRetVal = quiet; | 1026 | mRetVal = quiet; |
1026 | mTimerSocket = new QTimer ( this ); | 1027 | mTimerSocket = new QTimer ( this ); |
1027 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1028 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1028 | } | 1029 | } |
1029 | void KCommandSocket::readFile( QString fn ) | 1030 | void KCommandSocket::readFile( QString fn ) |
1030 | { | 1031 | { |
1031 | if ( !mSocket ) { | 1032 | if ( !mSocket ) { |
1032 | mSocket = new QSocket( this ); | 1033 | mSocket = new QSocket( this ); |
1033 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1034 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1034 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1035 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1035 | } | 1036 | } |
1036 | mFileString = ""; | 1037 | mFileString = ""; |
1037 | mFileName = fn; | 1038 | mFileName = fn; |
1038 | mFirst = true; | 1039 | mFirst = true; |
1039 | mSocket->connectToHost( mHost, mPort ); | 1040 | mSocket->connectToHost( mHost, mPort ); |
1040 | QTextStream os( mSocket ); | 1041 | QTextStream os( mSocket ); |
1041 | os.setEncoding( QTextStream::UnicodeUTF8 ); | 1042 | os.setEncoding( QTextStream::UnicodeUTF8 ); |
1042 | os << "GET " << mPassWord << "\r\n"; | 1043 | os << "GET " << mPassWord << "\r\n"; |
1043 | mTimerSocket->start( 10000 ); | 1044 | mTimerSocket->start( 10000 ); |
1044 | } | 1045 | } |
1045 | 1046 | ||
1046 | void KCommandSocket::writeFile( QString fileName ) | 1047 | void KCommandSocket::writeFile( QString fileName ) |
1047 | { | 1048 | { |
1048 | if ( !mSocket ) { | 1049 | if ( !mSocket ) { |
1049 | mSocket = new QSocket( this ); | 1050 | mSocket = new QSocket( this ); |
1050 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1051 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1051 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1052 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1052 | } | 1053 | } |
1053 | mFileName = fileName ; | 1054 | mFileName = fileName ; |
1054 | mSocket->connectToHost( mHost, mPort ); | 1055 | mSocket->connectToHost( mHost, mPort ); |
1055 | } | 1056 | } |
1056 | void KCommandSocket::writeFileToSocket() | 1057 | void KCommandSocket::writeFileToSocket() |
1057 | { | 1058 | { |
1058 | QFile file2( mFileName ); | 1059 | QFile file2( mFileName ); |
1059 | if (!file2.open( IO_ReadOnly ) ) { | 1060 | if (!file2.open( IO_ReadOnly ) ) { |
1060 | mRetVal= errorW; | 1061 | mRetVal= errorW; |
1061 | mSocket->close(); | 1062 | mSocket->close(); |
1062 | if ( mSocket->state() == QSocket::Idle ) | 1063 | if ( mSocket->state() == QSocket::Idle ) |
1063 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1064 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1064 | return ; | 1065 | return ; |
1065 | } | 1066 | } |
1066 | QTextStream ts2( &file2 ); | 1067 | QTextStream ts2( &file2 ); |
1067 | ts2.setCodec( QTextCodec::codecForName("utf8") ); | 1068 | ts2.setCodec( QTextCodec::codecForName("utf8") ); |
1068 | QTextStream os2( mSocket ); | 1069 | QTextStream os2( mSocket ); |
1069 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 1070 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
1070 | os2 << "PUT " << mPassWord << "\r\n";; | 1071 | os2 << "PUT " << mPassWord << "\r\n";; |
1071 | while ( ! ts2.atEnd() ) { | 1072 | while ( ! ts2.atEnd() ) { |
1072 | os2 << ts2.readLine() << "\n"; | 1073 | os2 << ts2.readLine() << "\n"; |
1073 | } | 1074 | } |
1074 | mRetVal= successW; | 1075 | mRetVal= successW; |
1075 | file2.close(); | 1076 | file2.close(); |
1076 | mSocket->close(); | 1077 | mSocket->close(); |
1077 | if ( mSocket->state() == QSocket::Idle ) | 1078 | if ( mSocket->state() == QSocket::Idle ) |
1078 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1079 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1079 | } | 1080 | } |
1080 | void KCommandSocket::sendStop() | 1081 | void KCommandSocket::sendStop() |
1081 | { | 1082 | { |
1082 | if ( !mSocket ) { | 1083 | if ( !mSocket ) { |
1083 | mSocket = new QSocket( this ); | 1084 | mSocket = new QSocket( this ); |
1084 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1085 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1085 | } | 1086 | } |
1086 | mSocket->connectToHost( mHost, mPort ); | 1087 | mSocket->connectToHost( mHost, mPort ); |
1087 | QTextStream os2( mSocket ); | 1088 | QTextStream os2( mSocket ); |
1088 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 1089 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
1089 | os2 << "STOP\r\n"; | 1090 | os2 << "STOP\r\n"; |
1090 | mSocket->close(); | 1091 | mSocket->close(); |
1091 | if ( mSocket->state() == QSocket::Idle ) | 1092 | if ( mSocket->state() == QSocket::Idle ) |
1092 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1093 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1093 | } | 1094 | } |
1094 | 1095 | ||
1095 | void KCommandSocket::startReadFileFromSocket() | 1096 | void KCommandSocket::startReadFileFromSocket() |
1096 | { | 1097 | { |
1097 | if ( ! mFirst ) | 1098 | if ( ! mFirst ) |
1098 | return; | 1099 | return; |
1099 | mFirst = false; | 1100 | mFirst = false; |
1100 | mTimerSocket->stop(); | 1101 | mTimerSocket->stop(); |
1101 | mFileString = ""; | 1102 | mFileString = ""; |
1102 | mTime.start(); | 1103 | mTime.start(); |
1103 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1104 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1104 | 1105 | ||
1105 | } | 1106 | } |
1106 | void KCommandSocket::readFileFromSocket() | 1107 | void KCommandSocket::readFileFromSocket() |
1107 | { | 1108 | { |
1108 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1109 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1109 | while ( mSocket->canReadLine () ) { | 1110 | while ( mSocket->canReadLine () ) { |
1110 | mTime.restart(); | 1111 | mTime.restart(); |
1111 | QString line = mSocket->readLine (); | 1112 | QString line = mSocket->readLine (); |
1112 | mFileString += line; | 1113 | mFileString += line; |
1113 | //qDebug("readline: %s ", line.latin1()); | 1114 | //qDebug("readline: %s ", line.latin1()); |
1114 | } | 1115 | } |
1115 | if ( mTime.elapsed () < 3000 ) { | 1116 | if ( mTime.elapsed () < 3000 ) { |
1116 | // wait for more | 1117 | // wait for more |
1117 | //qDebug("waitformore "); | 1118 | //qDebug("waitformore "); |
1118 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1119 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1119 | return; | 1120 | return; |
1120 | } | 1121 | } |
1121 | QString fileName = mFileName; | 1122 | QString fileName = mFileName; |
1122 | QFile file ( fileName ); | 1123 | QFile file ( fileName ); |
1123 | if (!file.open( IO_WriteOnly ) ) { | 1124 | if (!file.open( IO_WriteOnly ) ) { |
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 52e2772..0eb3323 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h | |||
@@ -1,228 +1,227 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | $Id$ | 20 | $Id$ |
21 | */ | 21 | */ |
22 | #ifndef _KSYNCMANAGER_H | 22 | #ifndef _KSYNCMANAGER_H |
23 | #define _KSYNCMANAGER_H | 23 | #define _KSYNCMANAGER_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qsocket.h> | 27 | #include <qsocket.h> |
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qserversocket.h> | 29 | #include <qserversocket.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | 32 | ||
33 | class QPopupMenu; | 33 | class QPopupMenu; |
34 | class KSyncProfile; | 34 | class KSyncProfile; |
35 | class KPimPrefs; | 35 | class KPimPrefs; |
36 | class QWidget; | 36 | class QWidget; |
37 | class KSyncManager; | 37 | class KSyncManager; |
38 | class KSyncInterface; | 38 | class KSyncInterface; |
39 | class QProgressBar; | 39 | class QProgressBar; |
40 | 40 | ||
41 | 41 | ||
42 | class KServerSocket : public QServerSocket | 42 | class KServerSocket : public QServerSocket |
43 | { | 43 | { |
44 | Q_OBJECT | 44 | Q_OBJECT |
45 | 45 | ||
46 | public: | 46 | public: |
47 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); | 47 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); |
48 | 48 | ||
49 | void newConnection ( int socket ) ; | 49 | void newConnection ( int socket ) ; |
50 | void setFileName( QString fn ) {mFileName = fn;}; | 50 | void setFileName( QString fn ) {mFileName = fn;}; |
51 | 51 | ||
52 | signals: | 52 | signals: |
53 | //void sendFile(QSocket*); | ||
54 | //void getFile(QSocket*); | ||
55 | void file_received( bool ); | 53 | void file_received( bool ); |
56 | //void file_sent(); | 54 | void request_file(); |
57 | void saveFile(); | 55 | void saveFile(); |
58 | void endConnect(); | 56 | void endConnect(); |
59 | private slots: | 57 | private slots: |
60 | void discardClient(); | 58 | void discardClient(); |
61 | void readClient(); | 59 | void readClient(); |
62 | void readBackFileFromSocket(); | 60 | void readBackFileFromSocket(); |
63 | private : | 61 | private : |
64 | bool blockRC; | 62 | bool blockRC; |
65 | void send_file(); | 63 | void send_file(); |
66 | void get_file(); | 64 | void get_file(); |
67 | void end_connect(); | 65 | void end_connect(); |
68 | QDialog* mSyncActionDialog; | 66 | QDialog* mSyncActionDialog; |
69 | QSocket* mSocket; | 67 | QSocket* mSocket; |
70 | QString mPassWord; | 68 | QString mPassWord; |
71 | QString mFileName; | 69 | QString mFileName; |
72 | QTime piTime; | 70 | QTime piTime; |
73 | QString piFileString; | 71 | QString piFileString; |
74 | }; | 72 | }; |
75 | 73 | ||
76 | class KCommandSocket : public QObject | 74 | class KCommandSocket : public QObject |
77 | { | 75 | { |
78 | Q_OBJECT | 76 | Q_OBJECT |
79 | public: | 77 | public: |
80 | enum state { successR, errorR, successW, errorW, quiet }; | 78 | enum state { successR, errorR, successW, errorW, quiet }; |
81 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); | 79 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); |
82 | void readFile( QString ); | 80 | void readFile( QString ); |
83 | void writeFile( QString ); | 81 | void writeFile( QString ); |
84 | void sendStop(); | 82 | void sendStop(); |
85 | 83 | ||
86 | 84 | ||
87 | signals: | 85 | signals: |
88 | void commandFinished( KCommandSocket*, int ); | 86 | void commandFinished( KCommandSocket*, int ); |
89 | private slots: | 87 | private slots: |
90 | void startReadFileFromSocket(); | 88 | void startReadFileFromSocket(); |
91 | void readFileFromSocket(); | 89 | void readFileFromSocket(); |
92 | void deleteSocket(); | 90 | void deleteSocket(); |
93 | void writeFileToSocket(); | 91 | void writeFileToSocket(); |
94 | private : | 92 | private : |
95 | QSocket* mSocket; | 93 | QSocket* mSocket; |
96 | QString mPassWord; | 94 | QString mPassWord; |
97 | Q_UINT16 mPort; | 95 | Q_UINT16 mPort; |
98 | QString mHost; | 96 | QString mHost; |
99 | QString mFileName; | 97 | QString mFileName; |
100 | QTimer* mTimerSocket; | 98 | QTimer* mTimerSocket; |
101 | int mRetVal; | 99 | int mRetVal; |
102 | QTime mTime; | 100 | QTime mTime; |
103 | QString mFileString; | 101 | QString mFileString; |
104 | bool mFirst; | 102 | bool mFirst; |
105 | }; | 103 | }; |
106 | 104 | ||
107 | 105 | ||
108 | class KSyncManager : public QObject | 106 | class KSyncManager : public QObject |
109 | { | 107 | { |
110 | Q_OBJECT | 108 | Q_OBJECT |
111 | 109 | ||
112 | public: | 110 | public: |
113 | enum TargetApp { | 111 | enum TargetApp { |
114 | KOPI = 0, | 112 | KOPI = 0, |
115 | KAPI = 1, | 113 | KAPI = 1, |
116 | PWMPI = 2 }; | 114 | PWMPI = 2 }; |
117 | 115 | ||
118 | 116 | ||
119 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); | 117 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); |
120 | ~KSyncManager() ; | 118 | ~KSyncManager() ; |
121 | 119 | ||
122 | bool blockSave() { return mBlockSaveFlag; } | 120 | bool blockSave() { return mBlockSaveFlag; } |
123 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } | 121 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } |
124 | void setDefaultFileName( QString s) { mDefFileName = s ;} | 122 | void setDefaultFileName( QString s) { mDefFileName = s ;} |
125 | QString defaultFileName() { return mDefFileName ;} | 123 | QString defaultFileName() { return mDefFileName ;} |
126 | QString syncFileName(); | 124 | QString syncFileName(); |
127 | void fillSyncMenu(); | 125 | void fillSyncMenu(); |
128 | 126 | ||
129 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } | 127 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } |
130 | QString getCurrentSyncName() { return mCurrentSyncName; } | 128 | QString getCurrentSyncName() { return mCurrentSyncName; } |
131 | 129 | ||
132 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); | 130 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); |
133 | void hideProgressBar(); | 131 | void hideProgressBar(); |
134 | bool isProgressBarCanceled(); | 132 | bool isProgressBarCanceled(); |
135 | 133 | ||
136 | // sync stuff | 134 | // sync stuff |
137 | QString mLocalMachineName; | 135 | QString mLocalMachineName; |
138 | QStringList mExternSyncProfiles; | 136 | QStringList mExternSyncProfiles; |
139 | QStringList mSyncProfileNames; | 137 | QStringList mSyncProfileNames; |
140 | bool mAskForPreferences; | 138 | bool mAskForPreferences; |
141 | bool mShowSyncSummary; | 139 | bool mShowSyncSummary; |
142 | bool mShowSyncEvents; | 140 | bool mShowSyncEvents; |
143 | bool mShowTodoInAgenda; | 141 | bool mShowTodoInAgenda; |
144 | bool mWriteBackExistingOnly; | 142 | bool mWriteBackExistingOnly; |
145 | int mSyncAlgoPrefs; | 143 | int mSyncAlgoPrefs; |
146 | int mRingSyncAlgoPrefs; | 144 | int mRingSyncAlgoPrefs; |
147 | bool mWriteBackFile; | 145 | bool mWriteBackFile; |
148 | int mWriteBackInFuture; | 146 | int mWriteBackInFuture; |
149 | QString mPhoneDevice; | 147 | QString mPhoneDevice; |
150 | QString mPhoneConnection; | 148 | QString mPhoneConnection; |
151 | QString mPhoneModel; | 149 | QString mPhoneModel; |
152 | QString mLastSyncedLocalFile; // save! | 150 | QString mLastSyncedLocalFile; // save! |
153 | QString mPassWordPiSync; | 151 | QString mPassWordPiSync; |
154 | QString mActiveSyncPort; | 152 | QString mActiveSyncPort; |
155 | QString mActiveSyncIP ; | 153 | QString mActiveSyncIP ; |
156 | 154 | ||
157 | signals: | 155 | signals: |
158 | void save(); | 156 | void save(); |
157 | void request_file(); | ||
159 | void getFile( bool ); | 158 | void getFile( bool ); |
160 | 159 | ||
161 | public slots: | 160 | public slots: |
162 | void slotSyncMenu( int ); | 161 | void slotSyncMenu( int ); |
163 | 162 | ||
164 | private: | 163 | private: |
165 | // LR ******************************* | 164 | // LR ******************************* |
166 | // sync stuff! | 165 | // sync stuff! |
167 | void syncPi(); | 166 | void syncPi(); |
168 | void deleteCommandSocket(KCommandSocket*s, int state); | 167 | void deleteCommandSocket(KCommandSocket*s, int state); |
169 | void readFileFromSocket(); | 168 | void readFileFromSocket(); |
170 | KServerSocket * mServerSocket; | 169 | KServerSocket * mServerSocket; |
171 | void enableQuick(); | 170 | void enableQuick(); |
172 | KPimPrefs* mPrefs; | 171 | KPimPrefs* mPrefs; |
173 | QString mDefFileName; | 172 | QString mDefFileName; |
174 | QString mCurrentSyncDevice; | 173 | QString mCurrentSyncDevice; |
175 | QString mCurrentSyncName; | 174 | QString mCurrentSyncName; |
176 | void quickSyncLocalFile(); | 175 | void quickSyncLocalFile(); |
177 | bool syncWithFile( QString fn , bool quick ); | 176 | bool syncWithFile( QString fn , bool quick ); |
178 | void syncLocalFile(); | 177 | void syncLocalFile(); |
179 | void syncPhone(); | 178 | void syncPhone(); |
180 | void syncSharp(); | 179 | void syncSharp(); |
181 | bool syncExternalApplication(QString); | 180 | bool syncExternalApplication(QString); |
182 | void multiSync( bool askforPrefs ); | 181 | void multiSync( bool askforPrefs ); |
183 | int mCurrentSyncProfile ; | 182 | int mCurrentSyncProfile ; |
184 | void syncRemote( KSyncProfile* prof, bool ask = true); | 183 | void syncRemote( KSyncProfile* prof, bool ask = true); |
185 | void edit_sync_options(); | 184 | void edit_sync_options(); |
186 | int ringSync(); | 185 | int ringSync(); |
187 | QString getPassword( ); | 186 | QString getPassword( ); |
188 | 187 | ||
189 | private slots: | 188 | private slots: |
190 | void confSync(); | 189 | void confSync(); |
191 | // ********************* | 190 | // ********************* |
192 | 191 | ||
193 | private: | 192 | private: |
194 | bool mBlockSaveFlag; | 193 | bool mBlockSaveFlag; |
195 | 194 | ||
196 | 195 | ||
197 | QWidget* mParent; | 196 | QWidget* mParent; |
198 | KSyncInterface* mImplementation; | 197 | KSyncInterface* mImplementation; |
199 | TargetApp mTargetApp; | 198 | TargetApp mTargetApp; |
200 | QPopupMenu* mSyncMenu; | 199 | QPopupMenu* mSyncMenu; |
201 | 200 | ||
202 | QProgressBar* bar; | 201 | QProgressBar* bar; |
203 | 202 | ||
204 | 203 | ||
205 | 204 | ||
206 | 205 | ||
207 | 206 | ||
208 | }; | 207 | }; |
209 | 208 | ||
210 | 209 | ||
211 | class KSyncInterface | 210 | class KSyncInterface |
212 | { | 211 | { |
213 | 212 | ||
214 | 213 | ||
215 | public : | 214 | public : |
216 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; | 215 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; |
217 | 216 | ||
218 | virtual bool syncExternal(KSyncManager* manager, QString resource) | 217 | virtual bool syncExternal(KSyncManager* manager, QString resource) |
219 | { | 218 | { |
220 | // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. | 219 | // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. |
221 | return false; | 220 | return false; |
222 | } | 221 | } |
223 | 222 | ||
224 | 223 | ||
225 | }; | 224 | }; |
226 | 225 | ||
227 | 226 | ||
228 | #endif | 227 | #endif |