summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 6f68d84..33b4a65 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,1094 +1,1098 @@
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 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <qbuttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52 52
53#include <klocale.h> 53#include <klocale.h>
54#include <kglobal.h> 54#include <kglobal.h>
55#include <kconfig.h> 55#include <kconfig.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57 57
58QDateTime KSyncManager::mRequestedSyncEvent; 58QDateTime KSyncManager::mRequestedSyncEvent;
59 59
60 60
61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
62 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 62 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
63{ 63{
64 mServerSocket = 0; 64 mServerSocket = 0;
65 bar = new QProgressBar ( 1, 0 ); 65 bar = new QProgressBar ( 1, 0 );
66 bar->setCaption (""); 66 bar->setCaption ("");
67 67 mWriteBackInPast = 2;
68 int w = 300; 68 int w = 300;
69 if ( QApplication::desktop()->width() < 320 ) 69 if ( QApplication::desktop()->width() < 320 )
70 w = 220; 70 w = 220;
71 int h = bar->sizeHint().height() ; 71 int h = bar->sizeHint().height() ;
72 int dw = QApplication::desktop()->width(); 72 int dw = QApplication::desktop()->width();
73 int dh = QApplication::desktop()->height(); 73 int dh = QApplication::desktop()->height();
74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
75 if ( mPrefs->mPassiveSyncAutoStart ) 75 if ( mPrefs->mPassiveSyncAutoStart )
76 enableQuick( false ); 76 enableQuick( false );
77 77
78} 78}
79 79
80KSyncManager::~KSyncManager() 80KSyncManager::~KSyncManager()
81{ 81{
82 delete bar; 82 delete bar;
83} 83}
84 84
85 85
86void KSyncManager::fillSyncMenu() 86void KSyncManager::fillSyncMenu()
87{ 87{
88 if ( mSyncMenu->count() ) 88 if ( mSyncMenu->count() )
89 mSyncMenu->clear(); 89 mSyncMenu->clear();
90 90
91 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 91 mSyncMenu->insertItem( i18n("Configure..."), 0 );
92 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
95 clearMenu->insertItem( i18n("For all profiles"), 1 ); 95 clearMenu->insertItem( i18n("For all profiles"), 1 );
96 clearMenu->insertSeparator(); 96 clearMenu->insertSeparator();
97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
98 mSyncMenu->insertSeparator(); 98 mSyncMenu->insertSeparator();
99 if ( mServerSocket == 0 ) { 99 if ( mServerSocket == 0 ) {
100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
101 } else { 101 } else {
102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
103 } 103 }
104 mSyncMenu->insertSeparator(); 104 mSyncMenu->insertSeparator();
105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
106 mSyncMenu->insertSeparator(); 106 mSyncMenu->insertSeparator();
107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
108 config.setGroup("General"); 108 config.setGroup("General");
109 QStringList prof = config.readListEntry("SyncProfileNames"); 109 QStringList prof = config.readListEntry("SyncProfileNames");
110 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 110 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
111 if ( prof.count() < 2 ) { 111 if ( prof.count() < 2 ) {
112 prof.clear(); 112 prof.clear();
113 QString externalName; 113 QString externalName;
114#ifdef DESKTOP_VERSION 114#ifdef DESKTOP_VERSION
115#ifdef _WIN32_ 115#ifdef _WIN32_
116 externalName = "OutLook(not_implemented)"; 116 externalName = "OutLook(not_implemented)";
117#else 117#else
118 externalName = "KDE_Desktop"; 118 externalName = "KDE_Desktop";
119#endif 119#endif
120#else 120#else
121 externalName = "Sharp_DTM"; 121 externalName = "Sharp_DTM";
122#endif 122#endif
123 prof << externalName; 123 prof << externalName;
124 prof << i18n("Local_file"); 124 prof << i18n("Local_file");
125 prof << i18n("Last_file"); 125 prof << i18n("Last_file");
126 KSyncProfile* temp = new KSyncProfile (); 126 KSyncProfile* temp = new KSyncProfile ();
127 temp->setName( prof[0] ); 127 temp->setName( prof[0] );
128 temp->writeConfig(&config); 128 temp->writeConfig(&config);
129 temp->setName( prof[1] ); 129 temp->setName( prof[1] );
130 temp->writeConfig(&config); 130 temp->writeConfig(&config);
131 temp->setName( prof[2] ); 131 temp->setName( prof[2] );
132 temp->writeConfig(&config); 132 temp->writeConfig(&config);
133 config.setGroup("General"); 133 config.setGroup("General");
134 config.writeEntry("SyncProfileNames",prof); 134 config.writeEntry("SyncProfileNames",prof);
135 config.writeEntry("ExternSyncProfiles",externalName); 135 config.writeEntry("ExternSyncProfiles",externalName);
136 config.sync(); 136 config.sync();
137 delete temp; 137 delete temp;
138 } 138 }
139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
140 mSyncProfileNames = prof; 140 mSyncProfileNames = prof;
141 unsigned int i; 141 unsigned int i;
142 for ( i = 0; i < prof.count(); ++i ) { 142 for ( i = 0; i < prof.count(); ++i ) {
143 mSyncMenu->insertItem( prof[i], 1000+i ); 143 mSyncMenu->insertItem( prof[i], 1000+i );
144 clearMenu->insertItem( prof[i], 1000+i ); 144 clearMenu->insertItem( prof[i], 1000+i );
145 if ( i == 2 ) 145 if ( i == 2 )
146 mSyncMenu->insertSeparator(); 146 mSyncMenu->insertSeparator();
147 } 147 }
148 QDir app_dir; 148 QDir app_dir;
149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
150 if ( mTargetApp == PWMPI) { 150 if ( mTargetApp == PWMPI) {
151 mSyncMenu->removeItem( 1000 ); 151 mSyncMenu->removeItem( 1000 );
152 clearMenu->removeItem( 1000 ); 152 clearMenu->removeItem( 1000 );
153 } 153 }
154#ifndef DESKTOP_VERSION 154#ifndef DESKTOP_VERSION
155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
156 mSyncMenu->removeItem( 1000 ); 156 mSyncMenu->removeItem( 1000 );
157 clearMenu->removeItem( 1000 ); 157 clearMenu->removeItem( 1000 );
158 } 158 }
159#endif 159#endif
160 mSyncMenu->removeItem( 1002 ); 160 mSyncMenu->removeItem( 1002 );
161 clearMenu->removeItem( 1002 ); 161 clearMenu->removeItem( 1002 );
162} 162}
163void KSyncManager::slotClearMenu( int action ) 163void KSyncManager::slotClearMenu( int action )
164{ 164{
165 QString syncDevice; 165 QString syncDevice;
166 if ( action > 999 ) { 166 if ( action > 999 ) {
167 syncDevice = mSyncProfileNames[action - 1000] ; 167 syncDevice = mSyncProfileNames[action - 1000] ;
168 } 168 }
169 169
170 170
171 171
172 int result = 0; 172 int result = 0;
173 QString sd; 173 QString sd;
174 if ( syncDevice.isEmpty() ) 174 if ( syncDevice.isEmpty() )
175 sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); 175 sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
176 else 176 else
177 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); 177 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
178 178
179 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, 179 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
180 0, 1 ); 180 0, 1 );
181 if ( result ) 181 if ( result )
182 return; 182 return;
183 mImplementation->removeSyncInfo( syncDevice ); 183 mImplementation->removeSyncInfo( syncDevice );
184} 184}
185void KSyncManager::slotSyncMenu( int action ) 185void KSyncManager::slotSyncMenu( int action )
186{ 186{
187 qDebug("syncaction %d ", action); 187 qDebug("syncaction %d ", action);
188 if ( action == 5000 ) 188 if ( action == 5000 )
189 return; 189 return;
190 mSyncWithDesktop = false; 190 mSyncWithDesktop = false;
191 if ( action == 0 ) { 191 if ( action == 0 ) {
192 192
193 // seems to be a Qt2 event handling bug 193 // seems to be a Qt2 event handling bug
194 // syncmenu.clear causes a segfault at first time 194 // syncmenu.clear causes a segfault at first time
195 // when we call it after the main event loop, it is ok 195 // when we call it after the main event loop, it is ok
196 // same behaviour when calling OM/Pi via QCOP for the first time 196 // same behaviour when calling OM/Pi via QCOP for the first time
197 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 197 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
198 //confSync(); 198 //confSync();
199 199
200 return; 200 return;
201 } 201 }
202 if ( action == 1 ) { 202 if ( action == 1 ) {
203 multiSync( true ); 203 multiSync( true );
204 return; 204 return;
205 } 205 }
206 if ( action == 2 ) { 206 if ( action == 2 ) {
207 enableQuick(); 207 enableQuick();
208 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 208 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
209 return; 209 return;
210 } 210 }
211 if ( action == 3 ) { 211 if ( action == 3 ) {
212 delete mServerSocket; 212 delete mServerSocket;
213 mServerSocket = 0; 213 mServerSocket = 0;
214 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 214 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
215 return; 215 return;
216 } 216 }
217 217
218 if (blockSave()) 218 if (blockSave())
219 return; 219 return;
220 220
221 setBlockSave(true); 221 setBlockSave(true);
222 bool silent = false; 222 bool silent = false;
223 if ( action == 999 ) { 223 if ( action == 999 ) {
224 //special mode for silent syncing 224 //special mode for silent syncing
225 action = 1000; 225 action = 1000;
226 silent = true; 226 silent = true;
227 } 227 }
228 228
229 mCurrentSyncProfile = action - 1000 ; 229 mCurrentSyncProfile = action - 1000 ;
230 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 230 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
231 mCurrentSyncName = mLocalMachineName ; 231 mCurrentSyncName = mLocalMachineName ;
232 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 232 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
233 KSyncProfile* temp = new KSyncProfile (); 233 KSyncProfile* temp = new KSyncProfile ();
234 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 234 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
235 temp->readConfig(&config); 235 temp->readConfig(&config);
236 if (silent) { 236 if (silent) {
237 mAskForPreferences = false; 237 mAskForPreferences = false;
238 mShowSyncSummary = false; 238 mShowSyncSummary = false;
239 mWriteBackFile = true; 239 mWriteBackFile = true;
240 mSyncAlgoPrefs = 2;// take newest 240 mSyncAlgoPrefs = 2;// take newest
241 } 241 }
242 else { 242 else {
243 mAskForPreferences = temp->getAskForPreferences(); 243 mAskForPreferences = temp->getAskForPreferences();
244 mShowSyncSummary = temp->getShowSummaryAfterSync(); 244 mShowSyncSummary = temp->getShowSummaryAfterSync();
245 mWriteBackFile = temp->getWriteBackFile(); 245 mWriteBackFile = temp->getWriteBackFile();
246 mSyncAlgoPrefs = temp->getSyncPrefs(); 246 mSyncAlgoPrefs = temp->getSyncPrefs();
247 } 247 }
248 mWriteBackExistingOnly = temp->getWriteBackExisting(); 248 mWriteBackExistingOnly = temp->getWriteBackExisting();
249 mIsKapiFile = temp->getIsKapiFile(); 249 mIsKapiFile = temp->getIsKapiFile();
250 mWriteBackInFuture = 0; 250 mWriteBackInFuture = 0;
251 if ( temp->getWriteBackFuture() ) 251 if ( temp->getWriteBackFuture() ) {
252 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 252 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
253 mWriteBackInPast = temp->getWriteBackPastWeeks( );
254 }
253 255
254 if ( action == 1000 ) { 256 if ( action == 1000 ) {
255 mIsKapiFile = false; 257 mIsKapiFile = false;
256#ifdef DESKTOP_VERSION 258#ifdef DESKTOP_VERSION
257 syncKDE(); 259 syncKDE();
258#else 260#else
259 syncSharp(); 261 syncSharp();
260#endif 262#endif
261 263
262 } else if ( action == 1001 ) { 264 } else if ( action == 1001 ) {
263 syncLocalFile(); 265 syncLocalFile();
264 266
265 } else if ( action == 1002 ) { 267 } else if ( action == 1002 ) {
266 mWriteBackFile = false; 268 mWriteBackFile = false;
267 mAskForPreferences = false; 269 mAskForPreferences = false;
268 mShowSyncSummary = false; 270 mShowSyncSummary = false;
269 mSyncAlgoPrefs = 3; 271 mSyncAlgoPrefs = 3;
270 quickSyncLocalFile(); 272 quickSyncLocalFile();
271 273
272 } else if ( action >= 1003 ) { 274 } else if ( action >= 1003 ) {
273 if ( temp->getIsLocalFileSync() ) { 275 if ( temp->getIsLocalFileSync() ) {
274 switch(mTargetApp) 276 switch(mTargetApp)
275 { 277 {
276 case (KAPI): 278 case (KAPI):
277 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 279 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
278 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 280 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
279 break; 281 break;
280 case (KOPI): 282 case (KOPI):
281 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 283 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
282 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
283 break; 285 break;
284 case (PWMPI): 286 case (PWMPI):
285 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 287 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
286 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 288 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
287 break; 289 break;
288 default: 290 default:
289 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 291 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
290 break; 292 break;
291 293
292 } 294 }
293 } else { 295 } else {
294 if ( temp->getIsPhoneSync() ) { 296 if ( temp->getIsPhoneSync() ) {
295 mPhoneDevice = temp->getPhoneDevice( ) ; 297 mPhoneDevice = temp->getPhoneDevice( ) ;
296 mPhoneConnection = temp->getPhoneConnection( ); 298 mPhoneConnection = temp->getPhoneConnection( );
297 mPhoneModel = temp->getPhoneModel( ); 299 mPhoneModel = temp->getPhoneModel( );
298 syncPhone(); 300 syncPhone();
299 } else if ( temp->getIsPiSync() ) { 301 } else if ( temp->getIsPiSync() ) {
300 if ( mTargetApp == KAPI ) { 302 if ( mTargetApp == KAPI ) {
301 mPassWordPiSync = temp->getRemotePwAB(); 303 mPassWordPiSync = temp->getRemotePwAB();
302 mActiveSyncPort = temp->getRemotePortAB(); 304 mActiveSyncPort = temp->getRemotePortAB();
303 mActiveSyncIP = temp->getRemoteIPAB(); 305 mActiveSyncIP = temp->getRemoteIPAB();
304 } else if ( mTargetApp == KOPI ) { 306 } else if ( mTargetApp == KOPI ) {
305 mPassWordPiSync = temp->getRemotePw(); 307 mPassWordPiSync = temp->getRemotePw();
306 mActiveSyncPort = temp->getRemotePort(); 308 mActiveSyncPort = temp->getRemotePort();
307 mActiveSyncIP = temp->getRemoteIP(); 309 mActiveSyncIP = temp->getRemoteIP();
308 } else { 310 } else {
309 mPassWordPiSync = temp->getRemotePwPWM(); 311 mPassWordPiSync = temp->getRemotePwPWM();
310 mActiveSyncPort = temp->getRemotePortPWM(); 312 mActiveSyncPort = temp->getRemotePortPWM();
311 mActiveSyncIP = temp->getRemoteIPPWM(); 313 mActiveSyncIP = temp->getRemoteIPPWM();
312 } 314 }
313 syncPi(); 315 syncPi();
314 while ( !mPisyncFinished ) { 316 while ( !mPisyncFinished ) {
315 //qDebug("waiting "); 317 //qDebug("waiting ");
316 qApp->processEvents(); 318 qApp->processEvents();
317 } 319 }
318 } else 320 } else
319 syncRemote( temp ); 321 syncRemote( temp );
320 322
321 } 323 }
322 } 324 }
323 delete temp; 325 delete temp;
324 setBlockSave(false); 326 setBlockSave(false);
325} 327}
326 328
327void KSyncManager::enableQuick( bool ask ) 329void KSyncManager::enableQuick( bool ask )
328{ 330{
329 bool autoStart; 331 bool autoStart;
330 bool changed = false; 332 bool changed = false;
331 if ( ask ) { 333 if ( ask ) {
332 QDialog dia ( 0, "input-dialog", true ); 334 QDialog dia ( 0, "input-dialog", true );
333 QLineEdit lab ( &dia ); 335 QLineEdit lab ( &dia );
334 QVBoxLayout lay( &dia ); 336 QVBoxLayout lay( &dia );
335 lab.setText( mPrefs->mPassiveSyncPort ); 337 lab.setText( mPrefs->mPassiveSyncPort );
336 lay.setMargin(7); 338 lay.setMargin(7);
337 lay.setSpacing(7); 339 lay.setSpacing(7);
338 int po = 9197+mTargetApp; 340 int po = 9197+mTargetApp;
339 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 341 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
340 lay.addWidget( &label); 342 lay.addWidget( &label);
341 lay.addWidget( &lab); 343 lay.addWidget( &lab);
342 344
343 QLineEdit lepw ( &dia ); 345 QLineEdit lepw ( &dia );
344 lepw.setText( mPrefs->mPassiveSyncPw ); 346 lepw.setText( mPrefs->mPassiveSyncPw );
345 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 347 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
346 lay.addWidget( &label2); 348 lay.addWidget( &label2);
347 lay.addWidget( &lepw); 349 lay.addWidget( &lepw);
348 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 350 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
349 lay.addWidget( &autostart); 351 lay.addWidget( &autostart);
350 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 352 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
351#ifdef DESKTOP_VERSION 353#ifdef DESKTOP_VERSION
352#ifdef _WIN32_ 354#ifdef _WIN32_
353 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 355 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
354 syncdesktop.hide();// not implemented! 356 syncdesktop.hide();// not implemented!
355#else 357#else
356 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 358 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
357#endif 359#endif
358 lay.addWidget( &syncdesktop); 360 lay.addWidget( &syncdesktop);
359#else 361#else
360 mPrefs->mPassiveSyncWithDesktop = false; 362 mPrefs->mPassiveSyncWithDesktop = false;
361 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 363 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
362 syncdesktop.hide(); 364 syncdesktop.hide();
363#endif 365#endif
364 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 366 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
365 367
366 dia.setFixedSize( 230,120 ); 368 dia.setFixedSize( 230,120 );
367 dia.setCaption( i18n("Enter port for Pi-Sync") ); 369 dia.setCaption( i18n("Enter port for Pi-Sync") );
368 QPushButton pb ( "OK", &dia); 370 QPushButton pb ( "OK", &dia);
369 lay.addWidget( &pb ); 371 lay.addWidget( &pb );
370 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 372 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
371 dia.show(); 373 dia.show();
372 if ( ! dia.exec() ) 374 if ( ! dia.exec() )
373 return; 375 return;
374 dia.hide(); 376 dia.hide();
375 qApp->processEvents(); 377 qApp->processEvents();
376 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 378 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
377 changed = true; 379 changed = true;
378 mPrefs->mPassiveSyncPw = lepw.text(); 380 mPrefs->mPassiveSyncPw = lepw.text();
379 } 381 }
380 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 382 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
381 mPrefs->mPassiveSyncPort = lab.text(); 383 mPrefs->mPassiveSyncPort = lab.text();
382 changed = true; 384 changed = true;
383 } 385 }
384 autoStart = autostart.isChecked(); 386 autoStart = autostart.isChecked();
385 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 387 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
386 changed = true; 388 changed = true;
387 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 389 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
388 } 390 }
389 } 391 }
390 else 392 else
391 autoStart = mPrefs->mPassiveSyncAutoStart; 393 autoStart = mPrefs->mPassiveSyncAutoStart;
392 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 394 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
393 changed = true; 395 changed = true;
394 bool ok; 396 bool ok;
395 mPrefs->mPassiveSyncAutoStart = false; 397 mPrefs->mPassiveSyncAutoStart = false;
396 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 398 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
397 if ( ! ok ) { 399 if ( ! ok ) {
398 KMessageBox::information( 0, i18n("No valid port")); 400 KMessageBox::information( 0, i18n("No valid port"));
399 return; 401 return;
400 } 402 }
401 //qDebug("port %d ", port); 403 //qDebug("port %d ", port);
402 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 404 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
403 mServerSocket->setFileName( defaultFileName() );//bbb 405 mServerSocket->setFileName( defaultFileName() );//bbb
404 //qDebug("connected "); 406 //qDebug("connected ");
405 if ( !mServerSocket->ok() ) { 407 if ( !mServerSocket->ok() ) {
406 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 408 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
407 delete mServerSocket; 409 delete mServerSocket;
408 mServerSocket = 0; 410 mServerSocket = 0;
409 return; 411 return;
410 } 412 }
411 mPrefs->mPassiveSyncAutoStart = autoStart; 413 mPrefs->mPassiveSyncAutoStart = autoStart;
412 if ( changed ) { 414 if ( changed ) {
413 mPrefs->writeConfig(); 415 mPrefs->writeConfig();
414 } 416 }
415 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 417 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
416 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 418 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
417} 419}
418 420
419void KSyncManager::syncLocalFile() 421void KSyncManager::syncLocalFile()
420{ 422{
421 423
422 QString fn =mPrefs->mLastSyncedLocalFile; 424 QString fn =mPrefs->mLastSyncedLocalFile;
423 QString ext; 425 QString ext;
424 426
425 switch(mTargetApp) 427 switch(mTargetApp)
426 { 428 {
427 case (KAPI): 429 case (KAPI):
428 ext = "(*.vcf)"; 430 ext = "(*.vcf)";
429 break; 431 break;
430 case (KOPI): 432 case (KOPI):
431 ext = "(*.ics/*.vcs)"; 433 ext = "(*.ics/*.vcs)";
432 break; 434 break;
433 case (PWMPI): 435 case (PWMPI):
434 ext = "(*.pwm)"; 436 ext = "(*.pwm)";
435 break; 437 break;
436 default: 438 default:
437 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 439 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
438 break; 440 break;
439 441
440 } 442 }
441 443
442 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 444 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
443 if ( fn == "" ) 445 if ( fn == "" )
444 return; 446 return;
445 if ( syncWithFile( fn, false ) ) { 447 if ( syncWithFile( fn, false ) ) {
446 qDebug("syncLocalFile() successful "); 448 qDebug("syncLocalFile() successful ");
447 } 449 }
448 450
449} 451}
450 452
451bool KSyncManager::syncWithFile( QString fn , bool quick ) 453bool KSyncManager::syncWithFile( QString fn , bool quick )
452{ 454{
453 bool ret = false; 455 bool ret = false;
454 QFileInfo info; 456 QFileInfo info;
455 info.setFile( fn ); 457 info.setFile( fn );
456 QString mess; 458 QString mess;
457 bool loadbup = true; 459 bool loadbup = true;
458 if ( !info. exists() ) { 460 if ( !info. exists() ) {
459 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 461 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
460 int result = QMessageBox::warning( mParent, i18n("Warning!"), 462 int result = QMessageBox::warning( mParent, i18n("Warning!"),
461 mess ); 463 mess );
462 return ret; 464 return ret;
463 } 465 }
464 int result = 0; 466 int result = 0;
465 if ( !quick ) { 467 if ( !quick ) {
466 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 468 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
467 result = QMessageBox::warning( mParent, i18n("Warning!"), 469 result = QMessageBox::warning( mParent, i18n("Warning!"),
468 mess, 470 mess,
469 i18n("Sync"), i18n("Cancel"), 0, 471 i18n("Sync"), i18n("Cancel"), 0,
470 0, 1 ); 472 0, 1 );
471 if ( result ) 473 if ( result )
472 return false; 474 return false;
473 } 475 }
474 if ( mAskForPreferences ) 476 if ( mAskForPreferences )
475 if ( !edit_sync_options()) { 477 if ( !edit_sync_options()) {
476 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 478 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
477 return false; 479 return false;
478 } 480 }
479 if ( result == 0 ) { 481 if ( result == 0 ) {
480 //qDebug("Now sycing ... "); 482 //qDebug("Now sycing ... ");
481 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 483 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
482 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 484 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
483 else 485 else
484 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 486 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
485 if ( ! quick ) 487 if ( ! quick )
486 mPrefs->mLastSyncedLocalFile = fn; 488 mPrefs->mLastSyncedLocalFile = fn;
487 } 489 }
488 return ret; 490 return ret;
489} 491}
490 492
491void KSyncManager::quickSyncLocalFile() 493void KSyncManager::quickSyncLocalFile()
492{ 494{
493 495
494 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 496 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
495 qDebug("quick syncLocalFile() successful "); 497 qDebug("quick syncLocalFile() successful ");
496 498
497 } 499 }
498} 500}
499 501
500void KSyncManager::multiSync( bool askforPrefs ) 502void KSyncManager::multiSync( bool askforPrefs )
501{ 503{
502 if (blockSave()) 504 if (blockSave())
503 return; 505 return;
504 setBlockSave(true); 506 setBlockSave(true);
505 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 507 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
506 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 508 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
507 question, 509 question,
508 i18n("Yes"), i18n("No"), 510 i18n("Yes"), i18n("No"),
509 0, 0 ) != 0 ) { 511 0, 0 ) != 0 ) {
510 setBlockSave(false); 512 setBlockSave(false);
511 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 513 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
512 return; 514 return;
513 } 515 }
514 mCurrentSyncDevice = i18n("Multiple profiles") ; 516 mCurrentSyncDevice = i18n("Multiple profiles") ;
515 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 517 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
516 if ( askforPrefs ) { 518 if ( askforPrefs ) {
517 if ( !edit_sync_options()) { 519 if ( !edit_sync_options()) {
518 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); 520 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") );
519 return; 521 return;
520 } 522 }
521 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 523 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
522 } 524 }
523 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 525 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
524 qApp->processEvents(); 526 qApp->processEvents();
525 int num = ringSync() ; 527 int num = ringSync() ;
526 if ( num > 1 ) 528 if ( num > 1 )
527 ringSync(); 529 ringSync();
528 setBlockSave(false); 530 setBlockSave(false);
529 if ( num ) 531 if ( num )
530 emit save(); 532 emit save();
531 if ( num ) 533 if ( num )
532 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 534 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
533 else 535 else
534 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 536 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
535 return; 537 return;
536} 538}
537 539
538int KSyncManager::ringSync() 540int KSyncManager::ringSync()
539{ 541{
540 542
541 int syncedProfiles = 0; 543 int syncedProfiles = 0;
542 unsigned int i; 544 unsigned int i;
543 QTime timer; 545 QTime timer;
544 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 546 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
545 QStringList syncProfileNames = mSyncProfileNames; 547 QStringList syncProfileNames = mSyncProfileNames;
546 KSyncProfile* temp = new KSyncProfile (); 548 KSyncProfile* temp = new KSyncProfile ();
547 mAskForPreferences = false; 549 mAskForPreferences = false;
548 for ( i = 0; i < syncProfileNames.count(); ++i ) { 550 for ( i = 0; i < syncProfileNames.count(); ++i ) {
549 mCurrentSyncProfile = i; 551 mCurrentSyncProfile = i;
550 temp->setName(syncProfileNames[mCurrentSyncProfile]); 552 temp->setName(syncProfileNames[mCurrentSyncProfile]);
551 temp->readConfig(&config); 553 temp->readConfig(&config);
552 554
553 bool includeInRingSync; 555 bool includeInRingSync;
554 switch(mTargetApp) 556 switch(mTargetApp)
555 { 557 {
556 case (KAPI): 558 case (KAPI):
557 includeInRingSync = temp->getIncludeInRingSyncAB(); 559 includeInRingSync = temp->getIncludeInRingSyncAB();
558 break; 560 break;
559 case (KOPI): 561 case (KOPI):
560 includeInRingSync = temp->getIncludeInRingSync(); 562 includeInRingSync = temp->getIncludeInRingSync();
561 break; 563 break;
562 case (PWMPI): 564 case (PWMPI):
563 includeInRingSync = temp->getIncludeInRingSyncPWM(); 565 includeInRingSync = temp->getIncludeInRingSyncPWM();
564 break; 566 break;
565 default: 567 default:
566 qDebug("KSyncManager::ringSync: invalid apptype selected"); 568 qDebug("KSyncManager::ringSync: invalid apptype selected");
567 break; 569 break;
568 570
569 } 571 }
570 572
571 573
572 if ( includeInRingSync && ( i < 1 || i > 2 )) { 574 if ( includeInRingSync && ( i < 1 || i > 2 )) {
573 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 575 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
574 ++syncedProfiles; 576 ++syncedProfiles;
575 mSyncWithDesktop = false; 577 mSyncWithDesktop = false;
576 // mAskForPreferences = temp->getAskForPreferences(); 578 // mAskForPreferences = temp->getAskForPreferences();
577 mWriteBackFile = temp->getWriteBackFile(); 579 mWriteBackFile = temp->getWriteBackFile();
578 mWriteBackExistingOnly = temp->getWriteBackExisting(); 580 mWriteBackExistingOnly = temp->getWriteBackExisting();
579 mIsKapiFile = temp->getIsKapiFile(); 581 mIsKapiFile = temp->getIsKapiFile();
580 mWriteBackInFuture = 0; 582 mWriteBackInFuture = 0;
581 if ( temp->getWriteBackFuture() ) 583 if ( temp->getWriteBackFuture() ) {
582 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 584 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
585 mWriteBackInPast = temp->getWriteBackPastWeeks( );
586 }
583 mShowSyncSummary = false; 587 mShowSyncSummary = false;
584 mCurrentSyncDevice = syncProfileNames[i] ; 588 mCurrentSyncDevice = syncProfileNames[i] ;
585 mCurrentSyncName = mLocalMachineName; 589 mCurrentSyncName = mLocalMachineName;
586 if ( i == 0 ) { 590 if ( i == 0 ) {
587 mIsKapiFile = false; 591 mIsKapiFile = false;
588#ifdef DESKTOP_VERSION 592#ifdef DESKTOP_VERSION
589 syncKDE(); 593 syncKDE();
590#else 594#else
591 syncSharp(); 595 syncSharp();
592#endif 596#endif
593 } else { 597 } else {
594 if ( temp->getIsLocalFileSync() ) { 598 if ( temp->getIsLocalFileSync() ) {
595 switch(mTargetApp) 599 switch(mTargetApp)
596 { 600 {
597 case (KAPI): 601 case (KAPI):
598 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 602 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
599 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 603 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
600 break; 604 break;
601 case (KOPI): 605 case (KOPI):
602 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 606 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
603 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 607 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
604 break; 608 break;
605 case (PWMPI): 609 case (PWMPI):
606 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 610 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
607 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 611 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
608 break; 612 break;
609 default: 613 default:
610 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 614 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
611 break; 615 break;
612 } 616 }
613 } else { 617 } else {
614 if ( temp->getIsPhoneSync() ) { 618 if ( temp->getIsPhoneSync() ) {
615 mPhoneDevice = temp->getPhoneDevice( ) ; 619 mPhoneDevice = temp->getPhoneDevice( ) ;
616 mPhoneConnection = temp->getPhoneConnection( ); 620 mPhoneConnection = temp->getPhoneConnection( );
617 mPhoneModel = temp->getPhoneModel( ); 621 mPhoneModel = temp->getPhoneModel( );
618 syncPhone(); 622 syncPhone();
619 } else if ( temp->getIsPiSync() ) { 623 } else if ( temp->getIsPiSync() ) {
620 if ( mTargetApp == KAPI ) { 624 if ( mTargetApp == KAPI ) {
621 mPassWordPiSync = temp->getRemotePwAB(); 625 mPassWordPiSync = temp->getRemotePwAB();
622 mActiveSyncPort = temp->getRemotePortAB(); 626 mActiveSyncPort = temp->getRemotePortAB();
623 mActiveSyncIP = temp->getRemoteIPAB(); 627 mActiveSyncIP = temp->getRemoteIPAB();
624 } else if ( mTargetApp == KOPI ) { 628 } else if ( mTargetApp == KOPI ) {
625 mPassWordPiSync = temp->getRemotePw(); 629 mPassWordPiSync = temp->getRemotePw();
626 mActiveSyncPort = temp->getRemotePort(); 630 mActiveSyncPort = temp->getRemotePort();
627 mActiveSyncIP = temp->getRemoteIP(); 631 mActiveSyncIP = temp->getRemoteIP();
628 } else { 632 } else {
629 mPassWordPiSync = temp->getRemotePwPWM(); 633 mPassWordPiSync = temp->getRemotePwPWM();
630 mActiveSyncPort = temp->getRemotePortPWM(); 634 mActiveSyncPort = temp->getRemotePortPWM();
631 mActiveSyncIP = temp->getRemoteIPPWM(); 635 mActiveSyncIP = temp->getRemoteIPPWM();
632 } 636 }
633 syncPi(); 637 syncPi();
634 while ( !mPisyncFinished ) { 638 while ( !mPisyncFinished ) {
635 //qDebug("waiting "); 639 //qDebug("waiting ");
636 qApp->processEvents(); 640 qApp->processEvents();
637 } 641 }
638 timer.start(); 642 timer.start();
639 while ( timer.elapsed () < 2000 ) { 643 while ( timer.elapsed () < 2000 ) {
640 qApp->processEvents(); 644 qApp->processEvents();
641 } 645 }
642 } else 646 } else
643 syncRemote( temp, false ); 647 syncRemote( temp, false );
644 648
645 } 649 }
646 } 650 }
647 timer.start(); 651 timer.start();
648 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 652 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
649 while ( timer.elapsed () < 2000 ) { 653 while ( timer.elapsed () < 2000 ) {
650 qApp->processEvents(); 654 qApp->processEvents();
651#ifndef _WIN32_ 655#ifndef _WIN32_
652 sleep (1); 656 sleep (1);
653#endif 657#endif
654 } 658 }
655 659
656 } 660 }
657 661
658 } 662 }
659 delete temp; 663 delete temp;
660 return syncedProfiles; 664 return syncedProfiles;
661} 665}
662 666
663void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 667void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
664{ 668{
665 QString question; 669 QString question;
666 if ( ask ) { 670 if ( ask ) {
667 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 671 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
668 if ( QMessageBox::information( mParent, i18n("Sync"), 672 if ( QMessageBox::information( mParent, i18n("Sync"),
669 question, 673 question,
670 i18n("Yes"), i18n("No"), 674 i18n("Yes"), i18n("No"),
671 0, 0 ) != 0 ) 675 0, 0 ) != 0 )
672 return; 676 return;
673 } 677 }
674 678
675 QString preCommand; 679 QString preCommand;
676 QString localTempFile; 680 QString localTempFile;
677 QString postCommand; 681 QString postCommand;
678 682
679 switch(mTargetApp) 683 switch(mTargetApp)
680 { 684 {
681 case (KAPI): 685 case (KAPI):
682 preCommand = prof->getPreSyncCommandAB(); 686 preCommand = prof->getPreSyncCommandAB();
683 postCommand = prof->getPostSyncCommandAB(); 687 postCommand = prof->getPostSyncCommandAB();
684 localTempFile = prof->getLocalTempFileAB(); 688 localTempFile = prof->getLocalTempFileAB();
685 break; 689 break;
686 case (KOPI): 690 case (KOPI):
687 preCommand = prof->getPreSyncCommand(); 691 preCommand = prof->getPreSyncCommand();
688 postCommand = prof->getPostSyncCommand(); 692 postCommand = prof->getPostSyncCommand();
689 localTempFile = prof->getLocalTempFile(); 693 localTempFile = prof->getLocalTempFile();
690 break; 694 break;
691 case (PWMPI): 695 case (PWMPI):
692 preCommand = prof->getPreSyncCommandPWM(); 696 preCommand = prof->getPreSyncCommandPWM();
693 postCommand = prof->getPostSyncCommandPWM(); 697 postCommand = prof->getPostSyncCommandPWM();
694 localTempFile = prof->getLocalTempFilePWM(); 698 localTempFile = prof->getLocalTempFilePWM();
695 break; 699 break;
696 default: 700 default:
697 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 701 qDebug("KSyncManager::syncRemote: invalid apptype selected");
698 break; 702 break;
699 } 703 }
700 704
701 705
702 int fi; 706 int fi;
703 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 707 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
704 QString pwd = getPassword(); 708 QString pwd = getPassword();
705 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 709 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
706 710
707 } 711 }
708 int maxlen = 30; 712 int maxlen = 30;
709 if ( QApplication::desktop()->width() > 320 ) 713 if ( QApplication::desktop()->width() > 320 )
710 maxlen += 25; 714 maxlen += 25;
711 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 715 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
712 int fileSize = 0; 716 int fileSize = 0;
713 int result = system ( preCommand ); 717 int result = system ( preCommand );
714 // 0 : okay 718 // 0 : okay
715 // 256: no such file or dir 719 // 256: no such file or dir
716 // 720 //
717 qDebug("Sync: Remote copy result(0 = okay): %d ",result ); 721 qDebug("Sync: Remote copy result(0 = okay): %d ",result );
718 if ( result != 0 ) { 722 if ( result != 0 ) {
719 unsigned int len = maxlen; 723 unsigned int len = maxlen;
720 while ( len < preCommand.length() ) { 724 while ( len < preCommand.length() ) {
721 preCommand.insert( len , "\n" ); 725 preCommand.insert( len , "\n" );
722 len += maxlen +2; 726 len += maxlen +2;
723 } 727 }
724 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; 728 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ;
725 QMessageBox::information( mParent, i18n("Sync - ERROR"), 729 QMessageBox::information( mParent, i18n("Sync - ERROR"),
726 question, 730 question,
727 i18n("Okay!")) ; 731 i18n("Okay!")) ;
728 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 732 mParent->topLevelWidget()->setCaption ("KDE-Pim");
729 return; 733 return;
730 } 734 }
731 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 735 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
732 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 736 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
733 737
734 if ( syncWithFile( localTempFile, true ) ) { 738 if ( syncWithFile( localTempFile, true ) ) {
735 739
736 if ( mWriteBackFile ) { 740 if ( mWriteBackFile ) {
737 int fi; 741 int fi;
738 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 742 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
739 QString pwd = getPassword(); 743 QString pwd = getPassword();
740 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 744 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
741 745
742 } 746 }
743 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 747 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
744 result = system ( postCommand ); 748 result = system ( postCommand );
745 qDebug("Sync:Writing back file result: %d ", result); 749 qDebug("Sync:Writing back file result: %d ", result);
746 if ( result != 0 ) { 750 if ( result != 0 ) {
747 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 751 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
748 return; 752 return;
749 } else { 753 } else {
750 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 754 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
751 } 755 }
752 } 756 }
753 } 757 }
754 return; 758 return;
755} 759}
756bool KSyncManager::edit_pisync_options() 760bool KSyncManager::edit_pisync_options()
757{ 761{
758 QDialog dia( mParent, "dia", true ); 762 QDialog dia( mParent, "dia", true );
759 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 763 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
760 QVBoxLayout lay ( &dia ); 764 QVBoxLayout lay ( &dia );
761 lay.setSpacing( 5 ); 765 lay.setSpacing( 5 );
762 lay.setMargin( 3 ); 766 lay.setMargin( 3 );
763 QLabel lab1 ( i18n("Password for remote access:"), &dia); 767 QLabel lab1 ( i18n("Password for remote access:"), &dia);
764 lay.addWidget( &lab1 ); 768 lay.addWidget( &lab1 );
765 QLineEdit le1 (&dia ); 769 QLineEdit le1 (&dia );
766 lay.addWidget( &le1 ); 770 lay.addWidget( &le1 );
767 QLabel lab2 ( i18n("Remote IP address:"), &dia); 771 QLabel lab2 ( i18n("Remote IP address:"), &dia);
768 lay.addWidget( &lab2 ); 772 lay.addWidget( &lab2 );
769 QLineEdit le2 (&dia ); 773 QLineEdit le2 (&dia );
770 lay.addWidget( &le2 ); 774 lay.addWidget( &le2 );
771 QLabel lab3 ( i18n("Remote port number:"), &dia); 775 QLabel lab3 ( i18n("Remote port number:"), &dia);
772 lay.addWidget( &lab3 ); 776 lay.addWidget( &lab3 );
773 QLineEdit le3 (&dia ); 777 QLineEdit le3 (&dia );
774 lay.addWidget( &le3 ); 778 lay.addWidget( &le3 );
775 QPushButton pb ( "OK", &dia); 779 QPushButton pb ( "OK", &dia);
776 lay.addWidget( &pb ); 780 lay.addWidget( &pb );
777 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 781 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
778 le1.setText( mPassWordPiSync ); 782 le1.setText( mPassWordPiSync );
779 le2.setText( mActiveSyncIP ); 783 le2.setText( mActiveSyncIP );
780 le3.setText( mActiveSyncPort ); 784 le3.setText( mActiveSyncPort );
781 if ( dia.exec() ) { 785 if ( dia.exec() ) {
782 mPassWordPiSync = le1.text(); 786 mPassWordPiSync = le1.text();
783 mActiveSyncPort = le3.text(); 787 mActiveSyncPort = le3.text();
784 mActiveSyncIP = le2.text(); 788 mActiveSyncIP = le2.text();
785 return true; 789 return true;
786 } 790 }
787 return false; 791 return false;
788} 792}
789bool KSyncManager::edit_sync_options() 793bool KSyncManager::edit_sync_options()
790{ 794{
791 795
792 QDialog dia( mParent, "dia", true ); 796 QDialog dia( mParent, "dia", true );
793 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 797 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
794 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 798 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
795 QVBoxLayout lay ( &dia ); 799 QVBoxLayout lay ( &dia );
796 lay.setSpacing( 2 ); 800 lay.setSpacing( 2 );
797 lay.setMargin( 3 ); 801 lay.setMargin( 3 );
798 lay.addWidget(&gr); 802 lay.addWidget(&gr);
799 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 803 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
800 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 804 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
801 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 805 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
802 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 806 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
803 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 807 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
804 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 808 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
805 //QRadioButton both( i18n("Take both on conflict"), &gr ); 809 //QRadioButton both( i18n("Take both on conflict"), &gr );
806 QPushButton pb ( "OK", &dia); 810 QPushButton pb ( "OK", &dia);
807 lay.addWidget( &pb ); 811 lay.addWidget( &pb );
808 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 812 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
809 switch ( mSyncAlgoPrefs ) { 813 switch ( mSyncAlgoPrefs ) {
810 case 0: 814 case 0:
811 loc.setChecked( true); 815 loc.setChecked( true);
812 break; 816 break;
813 case 1: 817 case 1:
814 rem.setChecked( true ); 818 rem.setChecked( true );
815 break; 819 break;
816 case 2: 820 case 2:
817 newest.setChecked( true); 821 newest.setChecked( true);
818 break; 822 break;
819 case 3: 823 case 3:
820 ask.setChecked( true); 824 ask.setChecked( true);
821 break; 825 break;
822 case 4: 826 case 4:
823 f_loc.setChecked( true); 827 f_loc.setChecked( true);
824 break; 828 break;
825 case 5: 829 case 5:
826 f_rem.setChecked( true); 830 f_rem.setChecked( true);
827 break; 831 break;
828 case 6: 832 case 6:
829 // both.setChecked( true); 833 // both.setChecked( true);
830 break; 834 break;
831 default: 835 default:
832 break; 836 break;
833 } 837 }
834 if ( dia.exec() ) { 838 if ( dia.exec() ) {
835 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 839 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
836 return true; 840 return true;
837 } 841 }
838 return false; 842 return false;
839} 843}
840 844
841QString KSyncManager::getPassword( ) 845QString KSyncManager::getPassword( )
842{ 846{
843 QString retfile = ""; 847 QString retfile = "";
844 QDialog dia ( mParent, "input-dialog", true ); 848 QDialog dia ( mParent, "input-dialog", true );
845 QLineEdit lab ( &dia ); 849 QLineEdit lab ( &dia );
846 lab.setEchoMode( QLineEdit::Password ); 850 lab.setEchoMode( QLineEdit::Password );
847 QVBoxLayout lay( &dia ); 851 QVBoxLayout lay( &dia );
848 lay.setMargin(7); 852 lay.setMargin(7);
849 lay.setSpacing(7); 853 lay.setSpacing(7);
850 lay.addWidget( &lab); 854 lay.addWidget( &lab);
851 dia.setFixedSize( 230,50 ); 855 dia.setFixedSize( 230,50 );
852 dia.setCaption( i18n("Enter password") ); 856 dia.setCaption( i18n("Enter password") );
853 QPushButton pb ( "OK", &dia); 857 QPushButton pb ( "OK", &dia);
854 lay.addWidget( &pb ); 858 lay.addWidget( &pb );
855 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 859 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
856 dia.show(); 860 dia.show();
857 int res = dia.exec(); 861 int res = dia.exec();
858 if ( res ) 862 if ( res )
859 retfile = lab.text(); 863 retfile = lab.text();
860 dia.hide(); 864 dia.hide();
861 qApp->processEvents(); 865 qApp->processEvents();
862 return retfile; 866 return retfile;
863 867
864} 868}
865 869
866 870
867void KSyncManager::confSync() 871void KSyncManager::confSync()
868{ 872{
869 static KSyncPrefsDialog* sp = 0; 873 static KSyncPrefsDialog* sp = 0;
870 if ( ! sp ) { 874 if ( ! sp ) {
871 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 875 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
872 } 876 }
873 sp->usrReadConfig(); 877 sp->usrReadConfig();
874#ifndef DESKTOP_VERSION 878#ifndef DESKTOP_VERSION
875 sp->showMaximized(); 879 sp->showMaximized();
876#else 880#else
877 sp->show(); 881 sp->show();
878#endif 882#endif
879 sp->exec(); 883 sp->exec();
880 QStringList oldSyncProfileNames = mSyncProfileNames; 884 QStringList oldSyncProfileNames = mSyncProfileNames;
881 mSyncProfileNames = sp->getSyncProfileNames(); 885 mSyncProfileNames = sp->getSyncProfileNames();
882 mLocalMachineName = sp->getLocalMachineName (); 886 mLocalMachineName = sp->getLocalMachineName ();
883 int ii; 887 int ii;
884 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { 888 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
885 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) 889 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
886 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); 890 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
887 } 891 }
888 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 892 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
889} 893}
890void KSyncManager::syncKDE() 894void KSyncManager::syncKDE()
891{ 895{
892 mSyncWithDesktop = true; 896 mSyncWithDesktop = true;
893 emit save(); 897 emit save();
894 switch(mTargetApp) 898 switch(mTargetApp)
895 { 899 {
896 case (KAPI): 900 case (KAPI):
897 { 901 {
898#ifdef DESKTOP_VERSION 902#ifdef DESKTOP_VERSION
899 QString command = qApp->applicationDirPath () + "/kdeabdump"; 903 QString command = qApp->applicationDirPath () + "/kdeabdump";
900#else 904#else
901 QString command = "kdeabdump"; 905 QString command = "kdeabdump";
902#endif 906#endif
903 if ( ! QFile::exists ( command ) ) 907 if ( ! QFile::exists ( command ) )
904 command = "kdeabdump"; 908 command = "kdeabdump";
905 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; 909 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
906 system ( command.latin1()); 910 system ( command.latin1());
907 if ( syncWithFile( fileName,true ) ) { 911 if ( syncWithFile( fileName,true ) ) {
908 if ( mWriteBackFile ) { 912 if ( mWriteBackFile ) {
909 command += " --read"; 913 command += " --read";
910 system ( command.latin1()); 914 system ( command.latin1());
911 } 915 }
912 } 916 }
913 917
914 } 918 }
915 break; 919 break;
916 case (KOPI): 920 case (KOPI):
917 { 921 {
918#ifdef DESKTOP_VERSION 922#ifdef DESKTOP_VERSION
919 QString command = qApp->applicationDirPath () + "/kdecaldump"; 923 QString command = qApp->applicationDirPath () + "/kdecaldump";
920#else 924#else
921 QString command = "kdecaldump"; 925 QString command = "kdecaldump";
922#endif 926#endif
923 if ( ! QFile::exists ( command ) ) 927 if ( ! QFile::exists ( command ) )
924 command = "kdecaldump"; 928 command = "kdecaldump";
925 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 929 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
926 system ( command.latin1()); 930 system ( command.latin1());
927 if ( syncWithFile( fileName,true ) ) { 931 if ( syncWithFile( fileName,true ) ) {
928 if ( mWriteBackFile ) { 932 if ( mWriteBackFile ) {
929 command += " --read"; 933 command += " --read";
930 system ( command.latin1()); 934 system ( command.latin1());
931 } 935 }
932 } 936 }
933 937
934 } 938 }
935 break; 939 break;
936 case (PWMPI): 940 case (PWMPI):
937 941
938 break; 942 break;
939 default: 943 default:
940 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 944 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
941 break; 945 break;
942 946
943 } 947 }
944} 948}
945 949
946void KSyncManager::syncSharp() 950void KSyncManager::syncSharp()
947{ 951{
948 952
949 if ( ! syncExternalApplication("sharp") ) 953 if ( ! syncExternalApplication("sharp") )
950 qDebug("ERROR sync sharp "); 954 qDebug("ERROR sync sharp ");
951} 955}
952 956
953bool KSyncManager::syncExternalApplication(QString resource) 957bool KSyncManager::syncExternalApplication(QString resource)
954{ 958{
955 959
956 emit save(); 960 emit save();
957 961
958 if ( mAskForPreferences ) 962 if ( mAskForPreferences )
959 if ( !edit_sync_options()) { 963 if ( !edit_sync_options()) {
960 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 964 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
961 return false; 965 return false;
962 } 966 }
963 967
964 qDebug("Sync extern %s", resource.latin1()); 968 qDebug("Sync extern %s", resource.latin1());
965 969
966 bool syncOK = mImplementation->syncExternal(this, resource); 970 bool syncOK = mImplementation->syncExternal(this, resource);
967 971
968 return syncOK; 972 return syncOK;
969 973
970} 974}
971 975
972void KSyncManager::syncPhone() 976void KSyncManager::syncPhone()
973{ 977{
974 978
975 syncExternalApplication("phone"); 979 syncExternalApplication("phone");
976 980
977} 981}
978 982
979void KSyncManager::showProgressBar(int percentage, QString caption, int total) 983void KSyncManager::showProgressBar(int percentage, QString caption, int total)
980{ 984{
981 if (!bar->isVisible()) 985 if (!bar->isVisible())
982 { 986 {
983 bar->setCaption (caption); 987 bar->setCaption (caption);
984 bar->setTotalSteps ( total ) ; 988 bar->setTotalSteps ( total ) ;
985 989
986 bar->show(); 990 bar->show();
987 } 991 }
988 992
989 bar->setProgress( percentage ); 993 bar->setProgress( percentage );
990} 994}
991 995
992void KSyncManager::hideProgressBar() 996void KSyncManager::hideProgressBar()
993{ 997{
994 bar->hide(); 998 bar->hide();
995} 999}
996 1000
997bool KSyncManager::isProgressBarCanceled() 1001bool KSyncManager::isProgressBarCanceled()
998{ 1002{
999 return !bar->isVisible(); 1003 return !bar->isVisible();
1000} 1004}
1001 1005
1002QString KSyncManager::syncFileName() 1006QString KSyncManager::syncFileName()
1003{ 1007{
1004 1008
1005 QString fn = "tempfile"; 1009 QString fn = "tempfile";
1006 switch(mTargetApp) 1010 switch(mTargetApp)
1007 { 1011 {
1008 case (KAPI): 1012 case (KAPI):
1009 fn = "tempsyncab.vcf"; 1013 fn = "tempsyncab.vcf";
1010 break; 1014 break;
1011 case (KOPI): 1015 case (KOPI):
1012 fn = "tempsynccal.ics"; 1016 fn = "tempsynccal.ics";
1013 break; 1017 break;
1014 case (PWMPI): 1018 case (PWMPI):
1015 fn = "tempsyncpw.pwm"; 1019 fn = "tempsyncpw.pwm";
1016 break; 1020 break;
1017 default: 1021 default:
1018 break; 1022 break;
1019 } 1023 }
1020#ifdef _WIN32_ 1024#ifdef _WIN32_
1021 return locateLocal( "tmp", fn ); 1025 return locateLocal( "tmp", fn );
1022#else 1026#else
1023 return (QString( "/tmp/" )+ fn ); 1027 return (QString( "/tmp/" )+ fn );
1024#endif 1028#endif
1025} 1029}
1026 1030
1027void KSyncManager::syncPi() 1031void KSyncManager::syncPi()
1028{ 1032{
1029 mIsKapiFile = true; 1033 mIsKapiFile = true;
1030 mPisyncFinished = false; 1034 mPisyncFinished = false;
1031 qApp->processEvents(); 1035 qApp->processEvents();
1032 if ( mAskForPreferences ) 1036 if ( mAskForPreferences )
1033 if ( !edit_pisync_options()) { 1037 if ( !edit_pisync_options()) {
1034 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1038 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1035 return; 1039 return;
1036 } 1040 }
1037 bool ok; 1041 bool ok;
1038 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1042 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1039 if ( ! ok ) { 1043 if ( ! ok ) {
1040 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1044 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1041 return; 1045 return;
1042 } 1046 }
1043 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 1047 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
1044 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1048 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1045 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 1049 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
1046 commandSocket->readFile( syncFileName() ); 1050 commandSocket->readFile( syncFileName() );
1047} 1051}
1048 1052
1049void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1053void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1050{ 1054{
1051 //enum { success, errorW, errorR, quiet }; 1055 //enum { success, errorW, errorR, quiet };
1052 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1056 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1053 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1057 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1054 delete s; 1058 delete s;
1055 if ( state == KCommandSocket::errorR ) { 1059 if ( state == KCommandSocket::errorR ) {
1056 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1060 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1057 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1061 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1058 commandSocket->sendStop(); 1062 commandSocket->sendStop();
1059 } 1063 }
1060 mPisyncFinished = true; 1064 mPisyncFinished = true;
1061 return; 1065 return;
1062 1066
1063 } else if ( state == KCommandSocket::errorW ) { 1067 } else if ( state == KCommandSocket::errorW ) {
1064 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1068 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1065 mPisyncFinished = true; 1069 mPisyncFinished = true;
1066 1070
1067 } else if ( state == KCommandSocket::successR ) { 1071 } else if ( state == KCommandSocket::successR ) {
1068 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1072 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1069 1073
1070 } else if ( state == KCommandSocket::successW ) { 1074 } else if ( state == KCommandSocket::successW ) {
1071 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1075 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1072 mPisyncFinished = true; 1076 mPisyncFinished = true;
1073 } 1077 }
1074 1078
1075 delete s; 1079 delete s;
1076} 1080}
1077 1081
1078void KSyncManager::readFileFromSocket() 1082void KSyncManager::readFileFromSocket()
1079{ 1083{
1080 QString fileName = syncFileName(); 1084 QString fileName = syncFileName();
1081 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1085 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1082 if ( ! syncWithFile( fileName , true ) ) { 1086 if ( ! syncWithFile( fileName , true ) ) {
1083 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1087 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1084 mPisyncFinished = true; 1088 mPisyncFinished = true;
1085 return; 1089 return;
1086 } 1090 }
1087 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1091 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1088 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1092 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1089 if ( mWriteBackFile ) 1093 if ( mWriteBackFile )
1090 commandSocket->writeFile( fileName ); 1094 commandSocket->writeFile( fileName );
1091 else { 1095 else {
1092 commandSocket->sendStop(); 1096 commandSocket->sendStop();
1093 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1097 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1094 mPisyncFinished = true; 1098 mPisyncFinished = true;