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, 6 insertions, 4 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 554c6e5..4390a06 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,509 +1,511 @@
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
58KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 58KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
59 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 59 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
60{ 60{
61 mServerSocket = 0; 61 mServerSocket = 0;
62 bar = new QProgressBar ( 1, 0 ); 62 bar = new QProgressBar ( 1, 0 );
63 bar->setCaption (""); 63 bar->setCaption ("");
64 64
65 int w = 300; 65 int w = 300;
66 if ( QApplication::desktop()->width() < 320 ) 66 if ( QApplication::desktop()->width() < 320 )
67 w = 220; 67 w = 220;
68 int h = bar->sizeHint().height() ; 68 int h = bar->sizeHint().height() ;
69 int dw = QApplication::desktop()->width(); 69 int dw = QApplication::desktop()->width();
70 int dh = QApplication::desktop()->height(); 70 int dh = QApplication::desktop()->height();
71 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 71 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
72 if ( mPrefs->mPassiveSyncAutoStart ) 72 if ( mPrefs->mPassiveSyncAutoStart )
73 enableQuick( false ); 73 enableQuick( false );
74 74
75} 75}
76 76
77KSyncManager::~KSyncManager() 77KSyncManager::~KSyncManager()
78{ 78{
79 delete bar; 79 delete bar;
80} 80}
81 81
82 82
83void KSyncManager::fillSyncMenu() 83void KSyncManager::fillSyncMenu()
84{ 84{
85 if ( mSyncMenu->count() ) 85 if ( mSyncMenu->count() )
86 mSyncMenu->clear(); 86 mSyncMenu->clear();
87 87
88 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 88 mSyncMenu->insertItem( i18n("Configure..."), 0 );
89 mSyncMenu->insertSeparator(); 89 mSyncMenu->insertSeparator();
90 if ( mServerSocket == 0 ) { 90 if ( mServerSocket == 0 ) {
91 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 91 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
92 } else { 92 } else {
93 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 93 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
94 } 94 }
95 mSyncMenu->insertSeparator(); 95 mSyncMenu->insertSeparator();
96 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 96 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
97 mSyncMenu->insertSeparator(); 97 mSyncMenu->insertSeparator();
98 98
99 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 99 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
100 config.setGroup("General"); 100 config.setGroup("General");
101 QStringList prof = config.readListEntry("SyncProfileNames"); 101 QStringList prof = config.readListEntry("SyncProfileNames");
102 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 102 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
103 if ( prof.count() < 2 ) { 103 if ( prof.count() < 2 ) {
104 prof.clear(); 104 prof.clear();
105 QString externalName;
105#ifdef DESKTOP_VERSION 106#ifdef DESKTOP_VERSION
106#ifdef _WIN32_ 107#ifdef _WIN32_
107 prof << i18n("OutLook(not_implemented)"); 108 externalName = "OutLook(not_implemented)";
108#else 109#else
109 prof << i18n("KDE_Desktop"); 110 externalName = "KDE_Desktop";
110#endif 111#endif
111#else 112#else
112 prof << i18n("Sharp_DTM"); 113 externalName = "Sharp_DTM";
113#endif 114#endif
115 prof << externalName;
114 prof << i18n("Local_file"); 116 prof << i18n("Local_file");
115 prof << i18n("Last_file"); 117 prof << i18n("Last_file");
116 KSyncProfile* temp = new KSyncProfile (); 118 KSyncProfile* temp = new KSyncProfile ();
117 temp->setName( prof[0] ); 119 temp->setName( prof[0] );
118 temp->writeConfig(&config); 120 temp->writeConfig(&config);
119 temp->setName( prof[1] ); 121 temp->setName( prof[1] );
120 temp->writeConfig(&config); 122 temp->writeConfig(&config);
121 temp->setName( prof[2] ); 123 temp->setName( prof[2] );
122 temp->writeConfig(&config); 124 temp->writeConfig(&config);
123 config.setGroup("General"); 125 config.setGroup("General");
124 config.writeEntry("SyncProfileNames",prof); 126 config.writeEntry("SyncProfileNames",prof);
125 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 127 config.writeEntry("ExternSyncProfiles",externalName);
126 config.sync(); 128 config.sync();
127 delete temp; 129 delete temp;
128 } 130 }
129 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 131 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
130 mSyncProfileNames = prof; 132 mSyncProfileNames = prof;
131 unsigned int i; 133 unsigned int i;
132 for ( i = 0; i < prof.count(); ++i ) { 134 for ( i = 0; i < prof.count(); ++i ) {
133 mSyncMenu->insertItem( prof[i], 1000+i ); 135 mSyncMenu->insertItem( prof[i], 1000+i );
134 if ( i == 2 ) 136 if ( i == 2 )
135 mSyncMenu->insertSeparator(); 137 mSyncMenu->insertSeparator();
136 } 138 }
137 QDir app_dir; 139 QDir app_dir;
138 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 140 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
139 if ( mTargetApp == PWMPI) { 141 if ( mTargetApp == PWMPI) {
140 mSyncMenu->removeItem( 1000 ); 142 mSyncMenu->removeItem( 1000 );
141 } 143 }
142#ifndef DESKTOP_VERSION 144#ifndef DESKTOP_VERSION
143 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 145 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
144 mSyncMenu->removeItem( 1000 ); 146 mSyncMenu->removeItem( 1000 );
145 } 147 }
146#endif 148#endif
147 mSyncMenu->removeItem( 1002 ); 149 mSyncMenu->removeItem( 1002 );
148} 150}
149 151
150void KSyncManager::slotSyncMenu( int action ) 152void KSyncManager::slotSyncMenu( int action )
151{ 153{
152 qDebug("syncaction %d ", action); 154 qDebug("syncaction %d ", action);
153 if ( action == 0 ) { 155 if ( action == 0 ) {
154 156
155 // seems to be a Qt2 event handling bug 157 // seems to be a Qt2 event handling bug
156 // syncmenu.clear causes a segfault at first time 158 // syncmenu.clear causes a segfault at first time
157 // when we call it after the main event loop, it is ok 159 // when we call it after the main event loop, it is ok
158 // same behaviour when calling OM/Pi via QCOP for the first time 160 // same behaviour when calling OM/Pi via QCOP for the first time
159 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 161 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
160 //confSync(); 162 //confSync();
161 163
162 return; 164 return;
163 } 165 }
164 if ( action == 1 ) { 166 if ( action == 1 ) {
165 multiSync( true ); 167 multiSync( true );
166 return; 168 return;
167 } 169 }
168 if ( action == 2 ) { 170 if ( action == 2 ) {
169 enableQuick(); 171 enableQuick();
170 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 172 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
171 return; 173 return;
172 } 174 }
173 if ( action == 3 ) { 175 if ( action == 3 ) {
174 delete mServerSocket; 176 delete mServerSocket;
175 mServerSocket = 0; 177 mServerSocket = 0;
176 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 178 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
177 return; 179 return;
178 } 180 }
179 181
180 if (blockSave()) 182 if (blockSave())
181 return; 183 return;
182 184
183 setBlockSave(true); 185 setBlockSave(true);
184 bool silent = false; 186 bool silent = false;
185 if ( action == 999 ) { 187 if ( action == 999 ) {
186 //special mode for silent syncing 188 //special mode for silent syncing
187 action = 1000; 189 action = 1000;
188 silent = true; 190 silent = true;
189 } 191 }
190 192
191 mCurrentSyncProfile = action - 1000 ; 193 mCurrentSyncProfile = action - 1000 ;
192 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 194 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
193 mCurrentSyncName = mLocalMachineName ; 195 mCurrentSyncName = mLocalMachineName ;
194 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 196 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
195 KSyncProfile* temp = new KSyncProfile (); 197 KSyncProfile* temp = new KSyncProfile ();
196 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 198 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
197 temp->readConfig(&config); 199 temp->readConfig(&config);
198 if (silent) { 200 if (silent) {
199 mAskForPreferences = false; 201 mAskForPreferences = false;
200 mShowSyncSummary = false; 202 mShowSyncSummary = false;
201 mWriteBackFile = true; 203 mWriteBackFile = true;
202 mSyncAlgoPrefs = 2;// take newest 204 mSyncAlgoPrefs = 2;// take newest
203 } 205 }
204 else { 206 else {
205 mAskForPreferences = temp->getAskForPreferences(); 207 mAskForPreferences = temp->getAskForPreferences();
206 mShowSyncSummary = temp->getShowSummaryAfterSync(); 208 mShowSyncSummary = temp->getShowSummaryAfterSync();
207 mWriteBackFile = temp->getWriteBackFile(); 209 mWriteBackFile = temp->getWriteBackFile();
208 mSyncAlgoPrefs = temp->getSyncPrefs(); 210 mSyncAlgoPrefs = temp->getSyncPrefs();
209 } 211 }
210 mWriteBackExistingOnly = temp->getWriteBackExisting(); 212 mWriteBackExistingOnly = temp->getWriteBackExisting();
211 mIsKapiFile = temp->getIsKapiFile(); 213 mIsKapiFile = temp->getIsKapiFile();
212 mWriteBackInFuture = 0; 214 mWriteBackInFuture = 0;
213 if ( temp->getWriteBackFuture() ) 215 if ( temp->getWriteBackFuture() )
214 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 216 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
215 217
216 if ( action == 1000 ) { 218 if ( action == 1000 ) {
217#ifdef DESKTOP_VERSION 219#ifdef DESKTOP_VERSION
218 syncKDE(); 220 syncKDE();
219#else 221#else
220 syncSharp(); 222 syncSharp();
221#endif 223#endif
222 224
223 } else if ( action == 1001 ) { 225 } else if ( action == 1001 ) {
224 syncLocalFile(); 226 syncLocalFile();
225 227
226 } else if ( action == 1002 ) { 228 } else if ( action == 1002 ) {
227 mWriteBackFile = false; 229 mWriteBackFile = false;
228 mAskForPreferences = false; 230 mAskForPreferences = false;
229 mShowSyncSummary = false; 231 mShowSyncSummary = false;
230 mSyncAlgoPrefs = 3; 232 mSyncAlgoPrefs = 3;
231 quickSyncLocalFile(); 233 quickSyncLocalFile();
232 234
233 } else if ( action >= 1003 ) { 235 } else if ( action >= 1003 ) {
234 if ( temp->getIsLocalFileSync() ) { 236 if ( temp->getIsLocalFileSync() ) {
235 switch(mTargetApp) 237 switch(mTargetApp)
236 { 238 {
237 case (KAPI): 239 case (KAPI):
238 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 240 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
239 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 241 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
240 break; 242 break;
241 case (KOPI): 243 case (KOPI):
242 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 244 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
243 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 245 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
244 break; 246 break;
245 case (PWMPI): 247 case (PWMPI):
246 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 248 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
247 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 249 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
248 break; 250 break;
249 default: 251 default:
250 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 252 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
251 break; 253 break;
252 254
253 } 255 }
254 } else { 256 } else {
255 if ( temp->getIsPhoneSync() ) { 257 if ( temp->getIsPhoneSync() ) {
256 mPhoneDevice = temp->getPhoneDevice( ) ; 258 mPhoneDevice = temp->getPhoneDevice( ) ;
257 mPhoneConnection = temp->getPhoneConnection( ); 259 mPhoneConnection = temp->getPhoneConnection( );
258 mPhoneModel = temp->getPhoneModel( ); 260 mPhoneModel = temp->getPhoneModel( );
259 syncPhone(); 261 syncPhone();
260 } else if ( temp->getIsPiSync() ) { 262 } else if ( temp->getIsPiSync() ) {
261 if ( mTargetApp == KAPI ) { 263 if ( mTargetApp == KAPI ) {
262 mPassWordPiSync = temp->getRemotePwAB(); 264 mPassWordPiSync = temp->getRemotePwAB();
263 mActiveSyncPort = temp->getRemotePortAB(); 265 mActiveSyncPort = temp->getRemotePortAB();
264 mActiveSyncIP = temp->getRemoteIPAB(); 266 mActiveSyncIP = temp->getRemoteIPAB();
265 } else if ( mTargetApp == KOPI ) { 267 } else if ( mTargetApp == KOPI ) {
266 mPassWordPiSync = temp->getRemotePw(); 268 mPassWordPiSync = temp->getRemotePw();
267 mActiveSyncPort = temp->getRemotePort(); 269 mActiveSyncPort = temp->getRemotePort();
268 mActiveSyncIP = temp->getRemoteIP(); 270 mActiveSyncIP = temp->getRemoteIP();
269 } else { 271 } else {
270 mPassWordPiSync = temp->getRemotePwPWM(); 272 mPassWordPiSync = temp->getRemotePwPWM();
271 mActiveSyncPort = temp->getRemotePortPWM(); 273 mActiveSyncPort = temp->getRemotePortPWM();
272 mActiveSyncIP = temp->getRemoteIPPWM(); 274 mActiveSyncIP = temp->getRemoteIPPWM();
273 } 275 }
274 syncPi(); 276 syncPi();
275 while ( !mPisyncFinished ) { 277 while ( !mPisyncFinished ) {
276 //qDebug("waiting "); 278 //qDebug("waiting ");
277 qApp->processEvents(); 279 qApp->processEvents();
278 } 280 }
279 } else 281 } else
280 syncRemote( temp ); 282 syncRemote( temp );
281 283
282 } 284 }
283 } 285 }
284 delete temp; 286 delete temp;
285 setBlockSave(false); 287 setBlockSave(false);
286} 288}
287 289
288void KSyncManager::enableQuick( bool ask ) 290void KSyncManager::enableQuick( bool ask )
289{ 291{
290 bool autoStart; 292 bool autoStart;
291 bool changed = false; 293 bool changed = false;
292 if ( ask ) { 294 if ( ask ) {
293 QDialog dia ( 0, "input-dialog", true ); 295 QDialog dia ( 0, "input-dialog", true );
294 QLineEdit lab ( &dia ); 296 QLineEdit lab ( &dia );
295 QVBoxLayout lay( &dia ); 297 QVBoxLayout lay( &dia );
296 lab.setText( mPrefs->mPassiveSyncPort ); 298 lab.setText( mPrefs->mPassiveSyncPort );
297 lay.setMargin(7); 299 lay.setMargin(7);
298 lay.setSpacing(7); 300 lay.setSpacing(7);
299 int po = 9197+mTargetApp; 301 int po = 9197+mTargetApp;
300 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 302 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
301 lay.addWidget( &label); 303 lay.addWidget( &label);
302 lay.addWidget( &lab); 304 lay.addWidget( &lab);
303 305
304 QLineEdit lepw ( &dia ); 306 QLineEdit lepw ( &dia );
305 lepw.setText( mPrefs->mPassiveSyncPw ); 307 lepw.setText( mPrefs->mPassiveSyncPw );
306 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 308 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
307 lay.addWidget( &label2); 309 lay.addWidget( &label2);
308 lay.addWidget( &lepw); 310 lay.addWidget( &lepw);
309 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 311 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
310 lay.addWidget( &autostart); 312 lay.addWidget( &autostart);
311 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 313 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
312#ifdef DESKTOP_VERSION 314#ifdef DESKTOP_VERSION
313#ifdef _WIN32_ 315#ifdef _WIN32_
314 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 316 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
315#else 317#else
316 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 318 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
317#endif 319#endif
318 lay.addWidget( &syncdesktop); 320 lay.addWidget( &syncdesktop);
319#else 321#else
320 mPrefs->mPassiveSyncWithDesktop = false; 322 mPrefs->mPassiveSyncWithDesktop = false;
321 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 323 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
322 syncdesktop.hide(); 324 syncdesktop.hide();
323#endif 325#endif
324 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 326 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
325 327
326 dia.setFixedSize( 230,120 ); 328 dia.setFixedSize( 230,120 );
327 dia.setCaption( i18n("Enter port for Pi-Sync") ); 329 dia.setCaption( i18n("Enter port for Pi-Sync") );
328 QPushButton pb ( "OK", &dia); 330 QPushButton pb ( "OK", &dia);
329 lay.addWidget( &pb ); 331 lay.addWidget( &pb );
330 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 332 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
331 dia.show(); 333 dia.show();
332 if ( ! dia.exec() ) 334 if ( ! dia.exec() )
333 return; 335 return;
334 dia.hide(); 336 dia.hide();
335 qApp->processEvents(); 337 qApp->processEvents();
336 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 338 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
337 changed = true; 339 changed = true;
338 mPrefs->mPassiveSyncPw = lepw.text(); 340 mPrefs->mPassiveSyncPw = lepw.text();
339 } 341 }
340 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 342 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
341 mPrefs->mPassiveSyncPort = lab.text(); 343 mPrefs->mPassiveSyncPort = lab.text();
342 changed = true; 344 changed = true;
343 } 345 }
344 autoStart = autostart.isChecked(); 346 autoStart = autostart.isChecked();
345 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 347 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
346 changed = true; 348 changed = true;
347 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 349 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
348 } 350 }
349 } 351 }
350 else 352 else
351 autoStart = mPrefs->mPassiveSyncAutoStart; 353 autoStart = mPrefs->mPassiveSyncAutoStart;
352 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 354 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
353 changed = true; 355 changed = true;
354 bool ok; 356 bool ok;
355 mPrefs->mPassiveSyncAutoStart = false; 357 mPrefs->mPassiveSyncAutoStart = false;
356 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 358 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
357 if ( ! ok ) { 359 if ( ! ok ) {
358 KMessageBox::information( 0, i18n("No valid port")); 360 KMessageBox::information( 0, i18n("No valid port"));
359 return; 361 return;
360 } 362 }
361 //qDebug("port %d ", port); 363 //qDebug("port %d ", port);
362 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 364 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
363 mServerSocket->setFileName( defaultFileName() ); 365 mServerSocket->setFileName( defaultFileName() );
364 //qDebug("connected "); 366 //qDebug("connected ");
365 if ( !mServerSocket->ok() ) { 367 if ( !mServerSocket->ok() ) {
366 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 368 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
367 delete mServerSocket; 369 delete mServerSocket;
368 mServerSocket = 0; 370 mServerSocket = 0;
369 return; 371 return;
370 } 372 }
371 mPrefs->mPassiveSyncAutoStart = autoStart; 373 mPrefs->mPassiveSyncAutoStart = autoStart;
372 if ( changed ) { 374 if ( changed ) {
373 mPrefs->writeConfig(); 375 mPrefs->writeConfig();
374 } 376 }
375 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 377 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
376 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 378 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
377} 379}
378 380
379void KSyncManager::syncLocalFile() 381void KSyncManager::syncLocalFile()
380{ 382{
381 383
382 QString fn =mPrefs->mLastSyncedLocalFile; 384 QString fn =mPrefs->mLastSyncedLocalFile;
383 QString ext; 385 QString ext;
384 386
385 switch(mTargetApp) 387 switch(mTargetApp)
386 { 388 {
387 case (KAPI): 389 case (KAPI):
388 ext = "(*.vcf)"; 390 ext = "(*.vcf)";
389 break; 391 break;
390 case (KOPI): 392 case (KOPI):
391 ext = "(*.ics/*.vcs)"; 393 ext = "(*.ics/*.vcs)";
392 break; 394 break;
393 case (PWMPI): 395 case (PWMPI):
394 ext = "(*.pwm)"; 396 ext = "(*.pwm)";
395 break; 397 break;
396 default: 398 default:
397 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 399 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
398 break; 400 break;
399 401
400 } 402 }
401 403
402 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 404 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
403 if ( fn == "" ) 405 if ( fn == "" )
404 return; 406 return;
405 if ( syncWithFile( fn, false ) ) { 407 if ( syncWithFile( fn, false ) ) {
406 qDebug("syncLocalFile() successful "); 408 qDebug("syncLocalFile() successful ");
407 } 409 }
408 410
409} 411}
410 412
411bool KSyncManager::syncWithFile( QString fn , bool quick ) 413bool KSyncManager::syncWithFile( QString fn , bool quick )
412{ 414{
413 bool ret = false; 415 bool ret = false;
414 QFileInfo info; 416 QFileInfo info;
415 info.setFile( fn ); 417 info.setFile( fn );
416 QString mess; 418 QString mess;
417 bool loadbup = true; 419 bool loadbup = true;
418 if ( !info. exists() ) { 420 if ( !info. exists() ) {
419 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 421 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
420 int result = QMessageBox::warning( mParent, i18n("Warning!"), 422 int result = QMessageBox::warning( mParent, i18n("Warning!"),
421 mess ); 423 mess );
422 return ret; 424 return ret;
423 } 425 }
424 int result = 0; 426 int result = 0;
425 if ( !quick ) { 427 if ( !quick ) {
426 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 428 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
427 result = QMessageBox::warning( mParent, i18n("Warning!"), 429 result = QMessageBox::warning( mParent, i18n("Warning!"),
428 mess, 430 mess,
429 i18n("Sync"), i18n("Cancel"), 0, 431 i18n("Sync"), i18n("Cancel"), 0,
430 0, 1 ); 432 0, 1 );
431 if ( result ) 433 if ( result )
432 return false; 434 return false;
433 } 435 }
434 if ( mAskForPreferences ) 436 if ( mAskForPreferences )
435 if ( !edit_sync_options()) { 437 if ( !edit_sync_options()) {
436 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 438 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
437 return false; 439 return false;
438 } 440 }
439 if ( result == 0 ) { 441 if ( result == 0 ) {
440 //qDebug("Now sycing ... "); 442 //qDebug("Now sycing ... ");
441 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 443 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
442 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 444 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
443 else 445 else
444 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 446 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
445 if ( ! quick ) 447 if ( ! quick )
446 mPrefs->mLastSyncedLocalFile = fn; 448 mPrefs->mLastSyncedLocalFile = fn;
447 } 449 }
448 return ret; 450 return ret;
449} 451}
450 452
451void KSyncManager::quickSyncLocalFile() 453void KSyncManager::quickSyncLocalFile()
452{ 454{
453 455
454 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 456 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
455 qDebug("quick syncLocalFile() successful "); 457 qDebug("quick syncLocalFile() successful ");
456 458
457 } 459 }
458} 460}
459 461
460void KSyncManager::multiSync( bool askforPrefs ) 462void KSyncManager::multiSync( bool askforPrefs )
461{ 463{
462 if (blockSave()) 464 if (blockSave())
463 return; 465 return;
464 setBlockSave(true); 466 setBlockSave(true);
465 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 467 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
466 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 468 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
467 question, 469 question,
468 i18n("Yes"), i18n("No"), 470 i18n("Yes"), i18n("No"),
469 0, 0 ) != 0 ) { 471 0, 0 ) != 0 ) {
470 setBlockSave(false); 472 setBlockSave(false);
471 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 473 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
472 return; 474 return;
473 } 475 }
474 mCurrentSyncDevice = i18n("Multiple profiles") ; 476 mCurrentSyncDevice = i18n("Multiple profiles") ;
475 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 477 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
476 if ( askforPrefs ) { 478 if ( askforPrefs ) {
477 if ( !edit_sync_options()) { 479 if ( !edit_sync_options()) {
478 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 480 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
479 return; 481 return;
480 } 482 }
481 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 483 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
482 } 484 }
483 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 485 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
484 qApp->processEvents(); 486 qApp->processEvents();
485 int num = ringSync() ; 487 int num = ringSync() ;
486 if ( num > 1 ) 488 if ( num > 1 )
487 ringSync(); 489 ringSync();
488 setBlockSave(false); 490 setBlockSave(false);
489 if ( num ) 491 if ( num )
490 emit save(); 492 emit save();
491 if ( num ) 493 if ( num )
492 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 494 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
493 else 495 else
494 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 496 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
495 return; 497 return;
496} 498}
497 499
498int KSyncManager::ringSync() 500int KSyncManager::ringSync()
499{ 501{
500 int syncedProfiles = 0; 502 int syncedProfiles = 0;
501 unsigned int i; 503 unsigned int i;
502 QTime timer; 504 QTime timer;
503 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 505 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
504 QStringList syncProfileNames = mSyncProfileNames; 506 QStringList syncProfileNames = mSyncProfileNames;
505 KSyncProfile* temp = new KSyncProfile (); 507 KSyncProfile* temp = new KSyncProfile ();
506 mAskForPreferences = false; 508 mAskForPreferences = false;
507 for ( i = 0; i < syncProfileNames.count(); ++i ) { 509 for ( i = 0; i < syncProfileNames.count(); ++i ) {
508 mCurrentSyncProfile = i; 510 mCurrentSyncProfile = i;
509 temp->setName(syncProfileNames[mCurrentSyncProfile]); 511 temp->setName(syncProfileNames[mCurrentSyncProfile]);