summaryrefslogtreecommitdiffabout
path: root/libkdepim
Unidiff
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp10
-rw-r--r--libkdepim/ksyncmanager.h4
2 files changed, 13 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 33b4a65..6c1f444 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,970 +1,978 @@
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 mWriteBackInPast = 2; 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( ); 253 mWriteBackInPast = temp->getWriteBackPastWeeks( );
254 } 254 }
255 255 mFilterInCal = temp->getFilterInCal();
256 mFilterOutCal = temp->getFilterOutCal();
257 mFilterInAB = temp->getFilterInAB();
258 mFilterOutAB = temp->getFilterOutAB();
259
256 if ( action == 1000 ) { 260 if ( action == 1000 ) {
257 mIsKapiFile = false; 261 mIsKapiFile = false;
258#ifdef DESKTOP_VERSION 262#ifdef DESKTOP_VERSION
259 syncKDE(); 263 syncKDE();
260#else 264#else
261 syncSharp(); 265 syncSharp();
262#endif 266#endif
263 267
264 } else if ( action == 1001 ) { 268 } else if ( action == 1001 ) {
265 syncLocalFile(); 269 syncLocalFile();
266 270
267 } else if ( action == 1002 ) { 271 } else if ( action == 1002 ) {
268 mWriteBackFile = false; 272 mWriteBackFile = false;
269 mAskForPreferences = false; 273 mAskForPreferences = false;
270 mShowSyncSummary = false; 274 mShowSyncSummary = false;
271 mSyncAlgoPrefs = 3; 275 mSyncAlgoPrefs = 3;
272 quickSyncLocalFile(); 276 quickSyncLocalFile();
273 277
274 } else if ( action >= 1003 ) { 278 } else if ( action >= 1003 ) {
275 if ( temp->getIsLocalFileSync() ) { 279 if ( temp->getIsLocalFileSync() ) {
276 switch(mTargetApp) 280 switch(mTargetApp)
277 { 281 {
278 case (KAPI): 282 case (KAPI):
279 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 283 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
280 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
281 break; 285 break;
282 case (KOPI): 286 case (KOPI):
283 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 287 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 288 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
285 break; 289 break;
286 case (PWMPI): 290 case (PWMPI):
287 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 291 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
288 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 292 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
289 break; 293 break;
290 default: 294 default:
291 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 295 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
292 break; 296 break;
293 297
294 } 298 }
295 } else { 299 } else {
296 if ( temp->getIsPhoneSync() ) { 300 if ( temp->getIsPhoneSync() ) {
297 mPhoneDevice = temp->getPhoneDevice( ) ; 301 mPhoneDevice = temp->getPhoneDevice( ) ;
298 mPhoneConnection = temp->getPhoneConnection( ); 302 mPhoneConnection = temp->getPhoneConnection( );
299 mPhoneModel = temp->getPhoneModel( ); 303 mPhoneModel = temp->getPhoneModel( );
300 syncPhone(); 304 syncPhone();
301 } else if ( temp->getIsPiSync() ) { 305 } else if ( temp->getIsPiSync() ) {
302 if ( mTargetApp == KAPI ) { 306 if ( mTargetApp == KAPI ) {
303 mPassWordPiSync = temp->getRemotePwAB(); 307 mPassWordPiSync = temp->getRemotePwAB();
304 mActiveSyncPort = temp->getRemotePortAB(); 308 mActiveSyncPort = temp->getRemotePortAB();
305 mActiveSyncIP = temp->getRemoteIPAB(); 309 mActiveSyncIP = temp->getRemoteIPAB();
306 } else if ( mTargetApp == KOPI ) { 310 } else if ( mTargetApp == KOPI ) {
307 mPassWordPiSync = temp->getRemotePw(); 311 mPassWordPiSync = temp->getRemotePw();
308 mActiveSyncPort = temp->getRemotePort(); 312 mActiveSyncPort = temp->getRemotePort();
309 mActiveSyncIP = temp->getRemoteIP(); 313 mActiveSyncIP = temp->getRemoteIP();
310 } else { 314 } else {
311 mPassWordPiSync = temp->getRemotePwPWM(); 315 mPassWordPiSync = temp->getRemotePwPWM();
312 mActiveSyncPort = temp->getRemotePortPWM(); 316 mActiveSyncPort = temp->getRemotePortPWM();
313 mActiveSyncIP = temp->getRemoteIPPWM(); 317 mActiveSyncIP = temp->getRemoteIPPWM();
314 } 318 }
315 syncPi(); 319 syncPi();
316 while ( !mPisyncFinished ) { 320 while ( !mPisyncFinished ) {
317 //qDebug("waiting "); 321 //qDebug("waiting ");
318 qApp->processEvents(); 322 qApp->processEvents();
319 } 323 }
320 } else 324 } else
321 syncRemote( temp ); 325 syncRemote( temp );
322 326
323 } 327 }
324 } 328 }
325 delete temp; 329 delete temp;
326 setBlockSave(false); 330 setBlockSave(false);
327} 331}
328 332
329void KSyncManager::enableQuick( bool ask ) 333void KSyncManager::enableQuick( bool ask )
330{ 334{
331 bool autoStart; 335 bool autoStart;
332 bool changed = false; 336 bool changed = false;
333 if ( ask ) { 337 if ( ask ) {
334 QDialog dia ( 0, "input-dialog", true ); 338 QDialog dia ( 0, "input-dialog", true );
335 QLineEdit lab ( &dia ); 339 QLineEdit lab ( &dia );
336 QVBoxLayout lay( &dia ); 340 QVBoxLayout lay( &dia );
337 lab.setText( mPrefs->mPassiveSyncPort ); 341 lab.setText( mPrefs->mPassiveSyncPort );
338 lay.setMargin(7); 342 lay.setMargin(7);
339 lay.setSpacing(7); 343 lay.setSpacing(7);
340 int po = 9197+mTargetApp; 344 int po = 9197+mTargetApp;
341 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 345 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
342 lay.addWidget( &label); 346 lay.addWidget( &label);
343 lay.addWidget( &lab); 347 lay.addWidget( &lab);
344 348
345 QLineEdit lepw ( &dia ); 349 QLineEdit lepw ( &dia );
346 lepw.setText( mPrefs->mPassiveSyncPw ); 350 lepw.setText( mPrefs->mPassiveSyncPw );
347 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 351 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
348 lay.addWidget( &label2); 352 lay.addWidget( &label2);
349 lay.addWidget( &lepw); 353 lay.addWidget( &lepw);
350 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 354 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
351 lay.addWidget( &autostart); 355 lay.addWidget( &autostart);
352 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 356 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
353#ifdef DESKTOP_VERSION 357#ifdef DESKTOP_VERSION
354#ifdef _WIN32_ 358#ifdef _WIN32_
355 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 359 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
356 syncdesktop.hide();// not implemented! 360 syncdesktop.hide();// not implemented!
357#else 361#else
358 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 362 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
359#endif 363#endif
360 lay.addWidget( &syncdesktop); 364 lay.addWidget( &syncdesktop);
361#else 365#else
362 mPrefs->mPassiveSyncWithDesktop = false; 366 mPrefs->mPassiveSyncWithDesktop = false;
363 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 367 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
364 syncdesktop.hide(); 368 syncdesktop.hide();
365#endif 369#endif
366 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 370 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
367 371
368 dia.setFixedSize( 230,120 ); 372 dia.setFixedSize( 230,120 );
369 dia.setCaption( i18n("Enter port for Pi-Sync") ); 373 dia.setCaption( i18n("Enter port for Pi-Sync") );
370 QPushButton pb ( "OK", &dia); 374 QPushButton pb ( "OK", &dia);
371 lay.addWidget( &pb ); 375 lay.addWidget( &pb );
372 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 376 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
373 dia.show(); 377 dia.show();
374 if ( ! dia.exec() ) 378 if ( ! dia.exec() )
375 return; 379 return;
376 dia.hide(); 380 dia.hide();
377 qApp->processEvents(); 381 qApp->processEvents();
378 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 382 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
379 changed = true; 383 changed = true;
380 mPrefs->mPassiveSyncPw = lepw.text(); 384 mPrefs->mPassiveSyncPw = lepw.text();
381 } 385 }
382 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 386 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
383 mPrefs->mPassiveSyncPort = lab.text(); 387 mPrefs->mPassiveSyncPort = lab.text();
384 changed = true; 388 changed = true;
385 } 389 }
386 autoStart = autostart.isChecked(); 390 autoStart = autostart.isChecked();
387 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 391 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
388 changed = true; 392 changed = true;
389 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 393 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
390 } 394 }
391 } 395 }
392 else 396 else
393 autoStart = mPrefs->mPassiveSyncAutoStart; 397 autoStart = mPrefs->mPassiveSyncAutoStart;
394 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 398 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
395 changed = true; 399 changed = true;
396 bool ok; 400 bool ok;
397 mPrefs->mPassiveSyncAutoStart = false; 401 mPrefs->mPassiveSyncAutoStart = false;
398 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 402 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
399 if ( ! ok ) { 403 if ( ! ok ) {
400 KMessageBox::information( 0, i18n("No valid port")); 404 KMessageBox::information( 0, i18n("No valid port"));
401 return; 405 return;
402 } 406 }
403 //qDebug("port %d ", port); 407 //qDebug("port %d ", port);
404 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 408 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
405 mServerSocket->setFileName( defaultFileName() );//bbb 409 mServerSocket->setFileName( defaultFileName() );//bbb
406 //qDebug("connected "); 410 //qDebug("connected ");
407 if ( !mServerSocket->ok() ) { 411 if ( !mServerSocket->ok() ) {
408 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 412 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
409 delete mServerSocket; 413 delete mServerSocket;
410 mServerSocket = 0; 414 mServerSocket = 0;
411 return; 415 return;
412 } 416 }
413 mPrefs->mPassiveSyncAutoStart = autoStart; 417 mPrefs->mPassiveSyncAutoStart = autoStart;
414 if ( changed ) { 418 if ( changed ) {
415 mPrefs->writeConfig(); 419 mPrefs->writeConfig();
416 } 420 }
417 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 421 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
418 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 422 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
419} 423}
420 424
421void KSyncManager::syncLocalFile() 425void KSyncManager::syncLocalFile()
422{ 426{
423 427
424 QString fn =mPrefs->mLastSyncedLocalFile; 428 QString fn =mPrefs->mLastSyncedLocalFile;
425 QString ext; 429 QString ext;
426 430
427 switch(mTargetApp) 431 switch(mTargetApp)
428 { 432 {
429 case (KAPI): 433 case (KAPI):
430 ext = "(*.vcf)"; 434 ext = "(*.vcf)";
431 break; 435 break;
432 case (KOPI): 436 case (KOPI):
433 ext = "(*.ics/*.vcs)"; 437 ext = "(*.ics/*.vcs)";
434 break; 438 break;
435 case (PWMPI): 439 case (PWMPI):
436 ext = "(*.pwm)"; 440 ext = "(*.pwm)";
437 break; 441 break;
438 default: 442 default:
439 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 443 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
440 break; 444 break;
441 445
442 } 446 }
443 447
444 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 448 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
445 if ( fn == "" ) 449 if ( fn == "" )
446 return; 450 return;
447 if ( syncWithFile( fn, false ) ) { 451 if ( syncWithFile( fn, false ) ) {
448 qDebug("syncLocalFile() successful "); 452 qDebug("syncLocalFile() successful ");
449 } 453 }
450 454
451} 455}
452 456
453bool KSyncManager::syncWithFile( QString fn , bool quick ) 457bool KSyncManager::syncWithFile( QString fn , bool quick )
454{ 458{
455 bool ret = false; 459 bool ret = false;
456 QFileInfo info; 460 QFileInfo info;
457 info.setFile( fn ); 461 info.setFile( fn );
458 QString mess; 462 QString mess;
459 bool loadbup = true; 463 bool loadbup = true;
460 if ( !info. exists() ) { 464 if ( !info. exists() ) {
461 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 465 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
462 int result = QMessageBox::warning( mParent, i18n("Warning!"), 466 int result = QMessageBox::warning( mParent, i18n("Warning!"),
463 mess ); 467 mess );
464 return ret; 468 return ret;
465 } 469 }
466 int result = 0; 470 int result = 0;
467 if ( !quick ) { 471 if ( !quick ) {
468 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 472 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
469 result = QMessageBox::warning( mParent, i18n("Warning!"), 473 result = QMessageBox::warning( mParent, i18n("Warning!"),
470 mess, 474 mess,
471 i18n("Sync"), i18n("Cancel"), 0, 475 i18n("Sync"), i18n("Cancel"), 0,
472 0, 1 ); 476 0, 1 );
473 if ( result ) 477 if ( result )
474 return false; 478 return false;
475 } 479 }
476 if ( mAskForPreferences ) 480 if ( mAskForPreferences )
477 if ( !edit_sync_options()) { 481 if ( !edit_sync_options()) {
478 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 482 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
479 return false; 483 return false;
480 } 484 }
481 if ( result == 0 ) { 485 if ( result == 0 ) {
482 //qDebug("Now sycing ... "); 486 //qDebug("Now sycing ... ");
483 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 487 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
484 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 488 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
485 else 489 else
486 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 490 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
487 if ( ! quick ) 491 if ( ! quick )
488 mPrefs->mLastSyncedLocalFile = fn; 492 mPrefs->mLastSyncedLocalFile = fn;
489 } 493 }
490 return ret; 494 return ret;
491} 495}
492 496
493void KSyncManager::quickSyncLocalFile() 497void KSyncManager::quickSyncLocalFile()
494{ 498{
495 499
496 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 500 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
497 qDebug("quick syncLocalFile() successful "); 501 qDebug("quick syncLocalFile() successful ");
498 502
499 } 503 }
500} 504}
501 505
502void KSyncManager::multiSync( bool askforPrefs ) 506void KSyncManager::multiSync( bool askforPrefs )
503{ 507{
504 if (blockSave()) 508 if (blockSave())
505 return; 509 return;
506 setBlockSave(true); 510 setBlockSave(true);
507 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 511 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
508 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 512 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
509 question, 513 question,
510 i18n("Yes"), i18n("No"), 514 i18n("Yes"), i18n("No"),
511 0, 0 ) != 0 ) { 515 0, 0 ) != 0 ) {
512 setBlockSave(false); 516 setBlockSave(false);
513 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 517 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
514 return; 518 return;
515 } 519 }
516 mCurrentSyncDevice = i18n("Multiple profiles") ; 520 mCurrentSyncDevice = i18n("Multiple profiles") ;
517 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 521 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
518 if ( askforPrefs ) { 522 if ( askforPrefs ) {
519 if ( !edit_sync_options()) { 523 if ( !edit_sync_options()) {
520 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); 524 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") );
521 return; 525 return;
522 } 526 }
523 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 527 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
524 } 528 }
525 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 529 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
526 qApp->processEvents(); 530 qApp->processEvents();
527 int num = ringSync() ; 531 int num = ringSync() ;
528 if ( num > 1 ) 532 if ( num > 1 )
529 ringSync(); 533 ringSync();
530 setBlockSave(false); 534 setBlockSave(false);
531 if ( num ) 535 if ( num )
532 emit save(); 536 emit save();
533 if ( num ) 537 if ( num )
534 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 538 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
535 else 539 else
536 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 540 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
537 return; 541 return;
538} 542}
539 543
540int KSyncManager::ringSync() 544int KSyncManager::ringSync()
541{ 545{
542 546
543 int syncedProfiles = 0; 547 int syncedProfiles = 0;
544 unsigned int i; 548 unsigned int i;
545 QTime timer; 549 QTime timer;
546 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 550 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
547 QStringList syncProfileNames = mSyncProfileNames; 551 QStringList syncProfileNames = mSyncProfileNames;
548 KSyncProfile* temp = new KSyncProfile (); 552 KSyncProfile* temp = new KSyncProfile ();
549 mAskForPreferences = false; 553 mAskForPreferences = false;
550 for ( i = 0; i < syncProfileNames.count(); ++i ) { 554 for ( i = 0; i < syncProfileNames.count(); ++i ) {
551 mCurrentSyncProfile = i; 555 mCurrentSyncProfile = i;
552 temp->setName(syncProfileNames[mCurrentSyncProfile]); 556 temp->setName(syncProfileNames[mCurrentSyncProfile]);
553 temp->readConfig(&config); 557 temp->readConfig(&config);
554 558
555 bool includeInRingSync; 559 bool includeInRingSync;
556 switch(mTargetApp) 560 switch(mTargetApp)
557 { 561 {
558 case (KAPI): 562 case (KAPI):
559 includeInRingSync = temp->getIncludeInRingSyncAB(); 563 includeInRingSync = temp->getIncludeInRingSyncAB();
560 break; 564 break;
561 case (KOPI): 565 case (KOPI):
562 includeInRingSync = temp->getIncludeInRingSync(); 566 includeInRingSync = temp->getIncludeInRingSync();
563 break; 567 break;
564 case (PWMPI): 568 case (PWMPI):
565 includeInRingSync = temp->getIncludeInRingSyncPWM(); 569 includeInRingSync = temp->getIncludeInRingSyncPWM();
566 break; 570 break;
567 default: 571 default:
568 qDebug("KSyncManager::ringSync: invalid apptype selected"); 572 qDebug("KSyncManager::ringSync: invalid apptype selected");
569 break; 573 break;
570 574
571 } 575 }
572 576
573 577
574 if ( includeInRingSync && ( i < 1 || i > 2 )) { 578 if ( includeInRingSync && ( i < 1 || i > 2 )) {
575 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 579 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
576 ++syncedProfiles; 580 ++syncedProfiles;
577 mSyncWithDesktop = false; 581 mSyncWithDesktop = false;
578 // mAskForPreferences = temp->getAskForPreferences(); 582 // mAskForPreferences = temp->getAskForPreferences();
579 mWriteBackFile = temp->getWriteBackFile(); 583 mWriteBackFile = temp->getWriteBackFile();
580 mWriteBackExistingOnly = temp->getWriteBackExisting(); 584 mWriteBackExistingOnly = temp->getWriteBackExisting();
581 mIsKapiFile = temp->getIsKapiFile(); 585 mIsKapiFile = temp->getIsKapiFile();
582 mWriteBackInFuture = 0; 586 mWriteBackInFuture = 0;
583 if ( temp->getWriteBackFuture() ) { 587 if ( temp->getWriteBackFuture() ) {
584 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 588 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
585 mWriteBackInPast = temp->getWriteBackPastWeeks( ); 589 mWriteBackInPast = temp->getWriteBackPastWeeks( );
586 } 590 }
591 mFilterInCal = temp->getFilterInCal();
592 mFilterOutCal = temp->getFilterOutCal();
593 mFilterInAB = temp->getFilterInAB();
594 mFilterOutAB = temp->getFilterOutAB();
587 mShowSyncSummary = false; 595 mShowSyncSummary = false;
588 mCurrentSyncDevice = syncProfileNames[i] ; 596 mCurrentSyncDevice = syncProfileNames[i] ;
589 mCurrentSyncName = mLocalMachineName; 597 mCurrentSyncName = mLocalMachineName;
590 if ( i == 0 ) { 598 if ( i == 0 ) {
591 mIsKapiFile = false; 599 mIsKapiFile = false;
592#ifdef DESKTOP_VERSION 600#ifdef DESKTOP_VERSION
593 syncKDE(); 601 syncKDE();
594#else 602#else
595 syncSharp(); 603 syncSharp();
596#endif 604#endif
597 } else { 605 } else {
598 if ( temp->getIsLocalFileSync() ) { 606 if ( temp->getIsLocalFileSync() ) {
599 switch(mTargetApp) 607 switch(mTargetApp)
600 { 608 {
601 case (KAPI): 609 case (KAPI):
602 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 610 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
603 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 611 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
604 break; 612 break;
605 case (KOPI): 613 case (KOPI):
606 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 614 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
607 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 615 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
608 break; 616 break;
609 case (PWMPI): 617 case (PWMPI):
610 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 618 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
611 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 619 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
612 break; 620 break;
613 default: 621 default:
614 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 622 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
615 break; 623 break;
616 } 624 }
617 } else { 625 } else {
618 if ( temp->getIsPhoneSync() ) { 626 if ( temp->getIsPhoneSync() ) {
619 mPhoneDevice = temp->getPhoneDevice( ) ; 627 mPhoneDevice = temp->getPhoneDevice( ) ;
620 mPhoneConnection = temp->getPhoneConnection( ); 628 mPhoneConnection = temp->getPhoneConnection( );
621 mPhoneModel = temp->getPhoneModel( ); 629 mPhoneModel = temp->getPhoneModel( );
622 syncPhone(); 630 syncPhone();
623 } else if ( temp->getIsPiSync() ) { 631 } else if ( temp->getIsPiSync() ) {
624 if ( mTargetApp == KAPI ) { 632 if ( mTargetApp == KAPI ) {
625 mPassWordPiSync = temp->getRemotePwAB(); 633 mPassWordPiSync = temp->getRemotePwAB();
626 mActiveSyncPort = temp->getRemotePortAB(); 634 mActiveSyncPort = temp->getRemotePortAB();
627 mActiveSyncIP = temp->getRemoteIPAB(); 635 mActiveSyncIP = temp->getRemoteIPAB();
628 } else if ( mTargetApp == KOPI ) { 636 } else if ( mTargetApp == KOPI ) {
629 mPassWordPiSync = temp->getRemotePw(); 637 mPassWordPiSync = temp->getRemotePw();
630 mActiveSyncPort = temp->getRemotePort(); 638 mActiveSyncPort = temp->getRemotePort();
631 mActiveSyncIP = temp->getRemoteIP(); 639 mActiveSyncIP = temp->getRemoteIP();
632 } else { 640 } else {
633 mPassWordPiSync = temp->getRemotePwPWM(); 641 mPassWordPiSync = temp->getRemotePwPWM();
634 mActiveSyncPort = temp->getRemotePortPWM(); 642 mActiveSyncPort = temp->getRemotePortPWM();
635 mActiveSyncIP = temp->getRemoteIPPWM(); 643 mActiveSyncIP = temp->getRemoteIPPWM();
636 } 644 }
637 syncPi(); 645 syncPi();
638 while ( !mPisyncFinished ) { 646 while ( !mPisyncFinished ) {
639 //qDebug("waiting "); 647 //qDebug("waiting ");
640 qApp->processEvents(); 648 qApp->processEvents();
641 } 649 }
642 timer.start(); 650 timer.start();
643 while ( timer.elapsed () < 2000 ) { 651 while ( timer.elapsed () < 2000 ) {
644 qApp->processEvents(); 652 qApp->processEvents();
645 } 653 }
646 } else 654 } else
647 syncRemote( temp, false ); 655 syncRemote( temp, false );
648 656
649 } 657 }
650 } 658 }
651 timer.start(); 659 timer.start();
652 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 660 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
653 while ( timer.elapsed () < 2000 ) { 661 while ( timer.elapsed () < 2000 ) {
654 qApp->processEvents(); 662 qApp->processEvents();
655#ifndef _WIN32_ 663#ifndef _WIN32_
656 sleep (1); 664 sleep (1);
657#endif 665#endif
658 } 666 }
659 667
660 } 668 }
661 669
662 } 670 }
663 delete temp; 671 delete temp;
664 return syncedProfiles; 672 return syncedProfiles;
665} 673}
666 674
667void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 675void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
668{ 676{
669 QString question; 677 QString question;
670 if ( ask ) { 678 if ( ask ) {
671 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 679 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
672 if ( QMessageBox::information( mParent, i18n("Sync"), 680 if ( QMessageBox::information( mParent, i18n("Sync"),
673 question, 681 question,
674 i18n("Yes"), i18n("No"), 682 i18n("Yes"), i18n("No"),
675 0, 0 ) != 0 ) 683 0, 0 ) != 0 )
676 return; 684 return;
677 } 685 }
678 686
679 QString preCommand; 687 QString preCommand;
680 QString localTempFile; 688 QString localTempFile;
681 QString postCommand; 689 QString postCommand;
682 690
683 switch(mTargetApp) 691 switch(mTargetApp)
684 { 692 {
685 case (KAPI): 693 case (KAPI):
686 preCommand = prof->getPreSyncCommandAB(); 694 preCommand = prof->getPreSyncCommandAB();
687 postCommand = prof->getPostSyncCommandAB(); 695 postCommand = prof->getPostSyncCommandAB();
688 localTempFile = prof->getLocalTempFileAB(); 696 localTempFile = prof->getLocalTempFileAB();
689 break; 697 break;
690 case (KOPI): 698 case (KOPI):
691 preCommand = prof->getPreSyncCommand(); 699 preCommand = prof->getPreSyncCommand();
692 postCommand = prof->getPostSyncCommand(); 700 postCommand = prof->getPostSyncCommand();
693 localTempFile = prof->getLocalTempFile(); 701 localTempFile = prof->getLocalTempFile();
694 break; 702 break;
695 case (PWMPI): 703 case (PWMPI):
696 preCommand = prof->getPreSyncCommandPWM(); 704 preCommand = prof->getPreSyncCommandPWM();
697 postCommand = prof->getPostSyncCommandPWM(); 705 postCommand = prof->getPostSyncCommandPWM();
698 localTempFile = prof->getLocalTempFilePWM(); 706 localTempFile = prof->getLocalTempFilePWM();
699 break; 707 break;
700 default: 708 default:
701 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 709 qDebug("KSyncManager::syncRemote: invalid apptype selected");
702 break; 710 break;
703 } 711 }
704 712
705 713
706 int fi; 714 int fi;
707 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 715 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
708 QString pwd = getPassword(); 716 QString pwd = getPassword();
709 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 717 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
710 718
711 } 719 }
712 int maxlen = 30; 720 int maxlen = 30;
713 if ( QApplication::desktop()->width() > 320 ) 721 if ( QApplication::desktop()->width() > 320 )
714 maxlen += 25; 722 maxlen += 25;
715 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 723 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
716 int fileSize = 0; 724 int fileSize = 0;
717 int result = system ( preCommand ); 725 int result = system ( preCommand );
718 // 0 : okay 726 // 0 : okay
719 // 256: no such file or dir 727 // 256: no such file or dir
720 // 728 //
721 qDebug("Sync: Remote copy result(0 = okay): %d ",result ); 729 qDebug("Sync: Remote copy result(0 = okay): %d ",result );
722 if ( result != 0 ) { 730 if ( result != 0 ) {
723 unsigned int len = maxlen; 731 unsigned int len = maxlen;
724 while ( len < preCommand.length() ) { 732 while ( len < preCommand.length() ) {
725 preCommand.insert( len , "\n" ); 733 preCommand.insert( len , "\n" );
726 len += maxlen +2; 734 len += maxlen +2;
727 } 735 }
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) ; 736 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) ;
729 QMessageBox::information( mParent, i18n("Sync - ERROR"), 737 QMessageBox::information( mParent, i18n("Sync - ERROR"),
730 question, 738 question,
731 i18n("Okay!")) ; 739 i18n("Okay!")) ;
732 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 740 mParent->topLevelWidget()->setCaption ("KDE-Pim");
733 return; 741 return;
734 } 742 }
735 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 743 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
736 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 744 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
737 745
738 if ( syncWithFile( localTempFile, true ) ) { 746 if ( syncWithFile( localTempFile, true ) ) {
739 747
740 if ( mWriteBackFile ) { 748 if ( mWriteBackFile ) {
741 int fi; 749 int fi;
742 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 750 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
743 QString pwd = getPassword(); 751 QString pwd = getPassword();
744 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 752 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
745 753
746 } 754 }
747 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 755 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
748 result = system ( postCommand ); 756 result = system ( postCommand );
749 qDebug("Sync:Writing back file result: %d ", result); 757 qDebug("Sync:Writing back file result: %d ", result);
750 if ( result != 0 ) { 758 if ( result != 0 ) {
751 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 759 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
752 return; 760 return;
753 } else { 761 } else {
754 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 762 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
755 } 763 }
756 } 764 }
757 } 765 }
758 return; 766 return;
759} 767}
760bool KSyncManager::edit_pisync_options() 768bool KSyncManager::edit_pisync_options()
761{ 769{
762 QDialog dia( mParent, "dia", true ); 770 QDialog dia( mParent, "dia", true );
763 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 771 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
764 QVBoxLayout lay ( &dia ); 772 QVBoxLayout lay ( &dia );
765 lay.setSpacing( 5 ); 773 lay.setSpacing( 5 );
766 lay.setMargin( 3 ); 774 lay.setMargin( 3 );
767 QLabel lab1 ( i18n("Password for remote access:"), &dia); 775 QLabel lab1 ( i18n("Password for remote access:"), &dia);
768 lay.addWidget( &lab1 ); 776 lay.addWidget( &lab1 );
769 QLineEdit le1 (&dia ); 777 QLineEdit le1 (&dia );
770 lay.addWidget( &le1 ); 778 lay.addWidget( &le1 );
771 QLabel lab2 ( i18n("Remote IP address:"), &dia); 779 QLabel lab2 ( i18n("Remote IP address:"), &dia);
772 lay.addWidget( &lab2 ); 780 lay.addWidget( &lab2 );
773 QLineEdit le2 (&dia ); 781 QLineEdit le2 (&dia );
774 lay.addWidget( &le2 ); 782 lay.addWidget( &le2 );
775 QLabel lab3 ( i18n("Remote port number:"), &dia); 783 QLabel lab3 ( i18n("Remote port number:"), &dia);
776 lay.addWidget( &lab3 ); 784 lay.addWidget( &lab3 );
777 QLineEdit le3 (&dia ); 785 QLineEdit le3 (&dia );
778 lay.addWidget( &le3 ); 786 lay.addWidget( &le3 );
779 QPushButton pb ( "OK", &dia); 787 QPushButton pb ( "OK", &dia);
780 lay.addWidget( &pb ); 788 lay.addWidget( &pb );
781 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 789 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
782 le1.setText( mPassWordPiSync ); 790 le1.setText( mPassWordPiSync );
783 le2.setText( mActiveSyncIP ); 791 le2.setText( mActiveSyncIP );
784 le3.setText( mActiveSyncPort ); 792 le3.setText( mActiveSyncPort );
785 if ( dia.exec() ) { 793 if ( dia.exec() ) {
786 mPassWordPiSync = le1.text(); 794 mPassWordPiSync = le1.text();
787 mActiveSyncPort = le3.text(); 795 mActiveSyncPort = le3.text();
788 mActiveSyncIP = le2.text(); 796 mActiveSyncIP = le2.text();
789 return true; 797 return true;
790 } 798 }
791 return false; 799 return false;
792} 800}
793bool KSyncManager::edit_sync_options() 801bool KSyncManager::edit_sync_options()
794{ 802{
795 803
796 QDialog dia( mParent, "dia", true ); 804 QDialog dia( mParent, "dia", true );
797 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 805 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
798 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 806 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
799 QVBoxLayout lay ( &dia ); 807 QVBoxLayout lay ( &dia );
800 lay.setSpacing( 2 ); 808 lay.setSpacing( 2 );
801 lay.setMargin( 3 ); 809 lay.setMargin( 3 );
802 lay.addWidget(&gr); 810 lay.addWidget(&gr);
803 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 811 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
804 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 812 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
805 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 813 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
806 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 814 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
807 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 815 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
808 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 816 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
809 //QRadioButton both( i18n("Take both on conflict"), &gr ); 817 //QRadioButton both( i18n("Take both on conflict"), &gr );
810 QPushButton pb ( "OK", &dia); 818 QPushButton pb ( "OK", &dia);
811 lay.addWidget( &pb ); 819 lay.addWidget( &pb );
812 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 820 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
813 switch ( mSyncAlgoPrefs ) { 821 switch ( mSyncAlgoPrefs ) {
814 case 0: 822 case 0:
815 loc.setChecked( true); 823 loc.setChecked( true);
816 break; 824 break;
817 case 1: 825 case 1:
818 rem.setChecked( true ); 826 rem.setChecked( true );
819 break; 827 break;
820 case 2: 828 case 2:
821 newest.setChecked( true); 829 newest.setChecked( true);
822 break; 830 break;
823 case 3: 831 case 3:
824 ask.setChecked( true); 832 ask.setChecked( true);
825 break; 833 break;
826 case 4: 834 case 4:
827 f_loc.setChecked( true); 835 f_loc.setChecked( true);
828 break; 836 break;
829 case 5: 837 case 5:
830 f_rem.setChecked( true); 838 f_rem.setChecked( true);
831 break; 839 break;
832 case 6: 840 case 6:
833 // both.setChecked( true); 841 // both.setChecked( true);
834 break; 842 break;
835 default: 843 default:
836 break; 844 break;
837 } 845 }
838 if ( dia.exec() ) { 846 if ( dia.exec() ) {
839 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 847 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
840 return true; 848 return true;
841 } 849 }
842 return false; 850 return false;
843} 851}
844 852
845QString KSyncManager::getPassword( ) 853QString KSyncManager::getPassword( )
846{ 854{
847 QString retfile = ""; 855 QString retfile = "";
848 QDialog dia ( mParent, "input-dialog", true ); 856 QDialog dia ( mParent, "input-dialog", true );
849 QLineEdit lab ( &dia ); 857 QLineEdit lab ( &dia );
850 lab.setEchoMode( QLineEdit::Password ); 858 lab.setEchoMode( QLineEdit::Password );
851 QVBoxLayout lay( &dia ); 859 QVBoxLayout lay( &dia );
852 lay.setMargin(7); 860 lay.setMargin(7);
853 lay.setSpacing(7); 861 lay.setSpacing(7);
854 lay.addWidget( &lab); 862 lay.addWidget( &lab);
855 dia.setFixedSize( 230,50 ); 863 dia.setFixedSize( 230,50 );
856 dia.setCaption( i18n("Enter password") ); 864 dia.setCaption( i18n("Enter password") );
857 QPushButton pb ( "OK", &dia); 865 QPushButton pb ( "OK", &dia);
858 lay.addWidget( &pb ); 866 lay.addWidget( &pb );
859 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 867 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
860 dia.show(); 868 dia.show();
861 int res = dia.exec(); 869 int res = dia.exec();
862 if ( res ) 870 if ( res )
863 retfile = lab.text(); 871 retfile = lab.text();
864 dia.hide(); 872 dia.hide();
865 qApp->processEvents(); 873 qApp->processEvents();
866 return retfile; 874 return retfile;
867 875
868} 876}
869 877
870 878
871void KSyncManager::confSync() 879void KSyncManager::confSync()
872{ 880{
873 static KSyncPrefsDialog* sp = 0; 881 static KSyncPrefsDialog* sp = 0;
874 if ( ! sp ) { 882 if ( ! sp ) {
875 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 883 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
876 } 884 }
877 sp->usrReadConfig(); 885 sp->usrReadConfig();
878#ifndef DESKTOP_VERSION 886#ifndef DESKTOP_VERSION
879 sp->showMaximized(); 887 sp->showMaximized();
880#else 888#else
881 sp->show(); 889 sp->show();
882#endif 890#endif
883 sp->exec(); 891 sp->exec();
884 QStringList oldSyncProfileNames = mSyncProfileNames; 892 QStringList oldSyncProfileNames = mSyncProfileNames;
885 mSyncProfileNames = sp->getSyncProfileNames(); 893 mSyncProfileNames = sp->getSyncProfileNames();
886 mLocalMachineName = sp->getLocalMachineName (); 894 mLocalMachineName = sp->getLocalMachineName ();
887 int ii; 895 int ii;
888 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { 896 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
889 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) 897 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
890 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); 898 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
891 } 899 }
892 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 900 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
893} 901}
894void KSyncManager::syncKDE() 902void KSyncManager::syncKDE()
895{ 903{
896 mSyncWithDesktop = true; 904 mSyncWithDesktop = true;
897 emit save(); 905 emit save();
898 switch(mTargetApp) 906 switch(mTargetApp)
899 { 907 {
900 case (KAPI): 908 case (KAPI):
901 { 909 {
902#ifdef DESKTOP_VERSION 910#ifdef DESKTOP_VERSION
903 QString command = qApp->applicationDirPath () + "/kdeabdump"; 911 QString command = qApp->applicationDirPath () + "/kdeabdump";
904#else 912#else
905 QString command = "kdeabdump"; 913 QString command = "kdeabdump";
906#endif 914#endif
907 if ( ! QFile::exists ( command ) ) 915 if ( ! QFile::exists ( command ) )
908 command = "kdeabdump"; 916 command = "kdeabdump";
909 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; 917 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
910 system ( command.latin1()); 918 system ( command.latin1());
911 if ( syncWithFile( fileName,true ) ) { 919 if ( syncWithFile( fileName,true ) ) {
912 if ( mWriteBackFile ) { 920 if ( mWriteBackFile ) {
913 command += " --read"; 921 command += " --read";
914 system ( command.latin1()); 922 system ( command.latin1());
915 } 923 }
916 } 924 }
917 925
918 } 926 }
919 break; 927 break;
920 case (KOPI): 928 case (KOPI):
921 { 929 {
922#ifdef DESKTOP_VERSION 930#ifdef DESKTOP_VERSION
923 QString command = qApp->applicationDirPath () + "/kdecaldump"; 931 QString command = qApp->applicationDirPath () + "/kdecaldump";
924#else 932#else
925 QString command = "kdecaldump"; 933 QString command = "kdecaldump";
926#endif 934#endif
927 if ( ! QFile::exists ( command ) ) 935 if ( ! QFile::exists ( command ) )
928 command = "kdecaldump"; 936 command = "kdecaldump";
929 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 937 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
930 system ( command.latin1()); 938 system ( command.latin1());
931 if ( syncWithFile( fileName,true ) ) { 939 if ( syncWithFile( fileName,true ) ) {
932 if ( mWriteBackFile ) { 940 if ( mWriteBackFile ) {
933 command += " --read"; 941 command += " --read";
934 system ( command.latin1()); 942 system ( command.latin1());
935 } 943 }
936 } 944 }
937 945
938 } 946 }
939 break; 947 break;
940 case (PWMPI): 948 case (PWMPI):
941 949
942 break; 950 break;
943 default: 951 default:
944 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 952 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
945 break; 953 break;
946 954
947 } 955 }
948} 956}
949 957
950void KSyncManager::syncSharp() 958void KSyncManager::syncSharp()
951{ 959{
952 960
953 if ( ! syncExternalApplication("sharp") ) 961 if ( ! syncExternalApplication("sharp") )
954 qDebug("ERROR sync sharp "); 962 qDebug("ERROR sync sharp ");
955} 963}
956 964
957bool KSyncManager::syncExternalApplication(QString resource) 965bool KSyncManager::syncExternalApplication(QString resource)
958{ 966{
959 967
960 emit save(); 968 emit save();
961 969
962 if ( mAskForPreferences ) 970 if ( mAskForPreferences )
963 if ( !edit_sync_options()) { 971 if ( !edit_sync_options()) {
964 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 972 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
965 return false; 973 return false;
966 } 974 }
967 975
968 qDebug("Sync extern %s", resource.latin1()); 976 qDebug("Sync extern %s", resource.latin1());
969 977
970 bool syncOK = mImplementation->syncExternal(this, resource); 978 bool syncOK = mImplementation->syncExternal(this, resource);
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 2d0a4ab..6d89950 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -1,217 +1,221 @@
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
33class QPopupMenu; 33class QPopupMenu;
34class KSyncProfile; 34class KSyncProfile;
35class KPimPrefs; 35class KPimPrefs;
36class QWidget; 36class QWidget;
37class KSyncManager; 37class KSyncManager;
38class KSyncInterface; 38class KSyncInterface;
39class QProgressBar; 39class QProgressBar;
40 40
41 41
42class KServerSocket : public QServerSocket 42class 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 signals: 51 signals:
52 void file_received( bool ); 52 void file_received( bool );
53 void request_file(); 53 void request_file();
54 void saveFile(); 54 void saveFile();
55 void endConnect(); 55 void endConnect();
56 private slots: 56 private slots:
57 void discardClient(); 57 void discardClient();
58 void readClient(); 58 void readClient();
59 void readBackFileFromSocket(); 59 void readBackFileFromSocket();
60 private : 60 private :
61 bool blockRC; 61 bool blockRC;
62 void send_file(); 62 void send_file();
63 void get_file(); 63 void get_file();
64 void end_connect(); 64 void end_connect();
65 QDialog* mSyncActionDialog; 65 QDialog* mSyncActionDialog;
66 QSocket* mSocket; 66 QSocket* mSocket;
67 QString mPassWord; 67 QString mPassWord;
68 QString mFileName; 68 QString mFileName;
69 QTime piTime; 69 QTime piTime;
70 QString piFileString; 70 QString piFileString;
71}; 71};
72 72
73class KCommandSocket : public QObject 73class KCommandSocket : public QObject
74{ 74{
75 Q_OBJECT 75 Q_OBJECT
76 public: 76 public:
77 enum state { successR, errorR, successW, errorW, errorTO, quiet }; 77 enum state { successR, errorR, successW, errorW, errorTO, quiet };
78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
79 void readFile( QString ); 79 void readFile( QString );
80 void writeFile( QString ); 80 void writeFile( QString );
81 void sendStop(); 81 void sendStop();
82 82
83 signals: 83 signals:
84 void commandFinished( KCommandSocket*, int ); 84 void commandFinished( KCommandSocket*, int );
85 private slots: 85 private slots:
86 void startReadFileFromSocket(); 86 void startReadFileFromSocket();
87 void readFileFromSocket(); 87 void readFileFromSocket();
88 void deleteSocket(); 88 void deleteSocket();
89 void writeFileToSocket(); 89 void writeFileToSocket();
90 private : 90 private :
91 QSocket* mSocket; 91 QSocket* mSocket;
92 QString mPassWord; 92 QString mPassWord;
93 Q_UINT16 mPort; 93 Q_UINT16 mPort;
94 QString mHost; 94 QString mHost;
95 QString mFileName; 95 QString mFileName;
96 QTimer* mTimerSocket; 96 QTimer* mTimerSocket;
97 int mRetVal; 97 int mRetVal;
98 QTime mTime; 98 QTime mTime;
99 QString mFileString; 99 QString mFileString;
100 bool mFirst; 100 bool mFirst;
101}; 101};
102 102
103 103
104class KSyncManager : public QObject 104class KSyncManager : public QObject
105{ 105{
106 Q_OBJECT 106 Q_OBJECT
107 107
108 public: 108 public:
109 enum TargetApp { 109 enum TargetApp {
110 KOPI = 0, 110 KOPI = 0,
111 KAPI = 1, 111 KAPI = 1,
112 PWMPI = 2 }; 112 PWMPI = 2 };
113 113
114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
115 ~KSyncManager() ; 115 ~KSyncManager() ;
116 116
117 void multiSync( bool askforPrefs ); 117 void multiSync( bool askforPrefs );
118 bool blockSave() { return mBlockSaveFlag; } 118 bool blockSave() { return mBlockSaveFlag; }
119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
120 void setDefaultFileName( QString s) { mDefFileName = s ;} 120 void setDefaultFileName( QString s) { mDefFileName = s ;}
121 QString defaultFileName() { return mDefFileName ;} 121 QString defaultFileName() { return mDefFileName ;}
122 QString syncFileName(); 122 QString syncFileName();
123 void enableQuick( bool ask = true); 123 void enableQuick( bool ask = true);
124 124
125 bool syncWithDesktop () { return mSyncWithDesktop;} 125 bool syncWithDesktop () { return mSyncWithDesktop;}
126 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 126 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
127 QString getCurrentSyncName() { return mCurrentSyncName; } 127 QString getCurrentSyncName() { return mCurrentSyncName; }
128 128
129 void showProgressBar(int percentage, QString caption = QString::null, int total=100); 129 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
130 void hideProgressBar(); 130 void hideProgressBar();
131 bool isProgressBarCanceled(); 131 bool isProgressBarCanceled();
132 132
133 // sync stuff 133 // sync stuff
134 QString mLocalMachineName; 134 QString mLocalMachineName;
135 QStringList mExternSyncProfiles; 135 QStringList mExternSyncProfiles;
136 QStringList mSyncProfileNames; 136 QStringList mSyncProfileNames;
137 bool mAskForPreferences; 137 bool mAskForPreferences;
138 bool mShowSyncSummary; 138 bool mShowSyncSummary;
139 bool mIsKapiFile; 139 bool mIsKapiFile;
140 bool mWriteBackExistingOnly; 140 bool mWriteBackExistingOnly;
141 int mSyncAlgoPrefs; 141 int mSyncAlgoPrefs;
142 bool mWriteBackFile; 142 bool mWriteBackFile;
143 int mWriteBackInFuture; 143 int mWriteBackInFuture;
144 int mWriteBackInPast; 144 int mWriteBackInPast;
145 QString mPhoneDevice; 145 QString mPhoneDevice;
146 QString mPhoneConnection; 146 QString mPhoneConnection;
147 QString mPhoneModel; 147 QString mPhoneModel;
148 QString mPassWordPiSync; 148 QString mPassWordPiSync;
149 QString mActiveSyncPort; 149 QString mActiveSyncPort;
150 QString mActiveSyncIP ; 150 QString mActiveSyncIP ;
151 QString mFilterInCal;
152 QString mFilterOutCal;
153 QString mFilterInAB;
154 QString mFilterOutAB;
151 static QDateTime mRequestedSyncEvent; 155 static QDateTime mRequestedSyncEvent;
152 156
153 signals: 157 signals:
154 void save(); 158 void save();
155 void request_file(); 159 void request_file();
156 void getFile( bool ); 160 void getFile( bool );
157 161
158 public slots: 162 public slots:
159 void slotSyncMenu( int ); 163 void slotSyncMenu( int );
160 void slotClearMenu( int action ); 164 void slotClearMenu( int action );
161 void deleteCommandSocket(KCommandSocket*s, int state); 165 void deleteCommandSocket(KCommandSocket*s, int state);
162 void readFileFromSocket(); 166 void readFileFromSocket();
163 void fillSyncMenu(); 167 void fillSyncMenu();
164 168
165 private: 169 private:
166 void syncPi(); 170 void syncPi();
167 KServerSocket * mServerSocket; 171 KServerSocket * mServerSocket;
168 KPimPrefs* mPrefs; 172 KPimPrefs* mPrefs;
169 QString mDefFileName; 173 QString mDefFileName;
170 QString mCurrentSyncDevice; 174 QString mCurrentSyncDevice;
171 QString mCurrentSyncName; 175 QString mCurrentSyncName;
172 void quickSyncLocalFile(); 176 void quickSyncLocalFile();
173 bool syncWithFile( QString fn , bool quick ); 177 bool syncWithFile( QString fn , bool quick );
174 void syncLocalFile(); 178 void syncLocalFile();
175 void syncPhone(); 179 void syncPhone();
176 void syncSharp(); 180 void syncSharp();
177 void syncKDE(); 181 void syncKDE();
178 bool syncExternalApplication(QString); 182 bool syncExternalApplication(QString);
179 int mCurrentSyncProfile ; 183 int mCurrentSyncProfile ;
180 void syncRemote( KSyncProfile* prof, bool ask = true); 184 void syncRemote( KSyncProfile* prof, bool ask = true);
181 bool edit_sync_options(); 185 bool edit_sync_options();
182 bool edit_pisync_options(); 186 bool edit_pisync_options();
183 int ringSync(); 187 int ringSync();
184 QString getPassword( ); 188 QString getPassword( );
185 bool mPisyncFinished; 189 bool mPisyncFinished;
186 bool mBlockSaveFlag; 190 bool mBlockSaveFlag;
187 QWidget* mParent; 191 QWidget* mParent;
188 KSyncInterface* mImplementation; 192 KSyncInterface* mImplementation;
189 TargetApp mTargetApp; 193 TargetApp mTargetApp;
190 QPopupMenu* mSyncMenu; 194 QPopupMenu* mSyncMenu;
191 QProgressBar* bar; 195 QProgressBar* bar;
192 bool mSyncWithDesktop; 196 bool mSyncWithDesktop;
193 197
194private slots: 198private slots:
195 void confSync(); 199 void confSync();
196 200
197 201
198}; 202};
199 203
200 204
201class KSyncInterface 205class KSyncInterface
202{ 206{
203 public : 207 public :
204 virtual void removeSyncInfo( QString syncProfile) = 0; 208 virtual void removeSyncInfo( QString syncProfile) = 0;
205 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 209 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
206 virtual bool syncExternal(KSyncManager* manager, QString resource) 210 virtual bool syncExternal(KSyncManager* manager, QString resource)
207 { 211 {
208 // empty implementation, because some syncable applications do not 212 // empty implementation, because some syncable applications do not
209 // have an external(sharpdtm) syncmode, like pwmanager. 213 // have an external(sharpdtm) syncmode, like pwmanager.
210 return false; 214 return false;
211 } 215 }
212 216
213 217
214}; 218};
215 219
216 220
217#endif 221#endif