summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2005-02-07 20:05:18 (UTC)
committer zautrix <zautrix>2005-02-07 20:05:18 (UTC)
commitda5e47069d88fa9aa656423ce4c60bf505728e1c (patch) (unidiff)
treefdbaf29835a028f1204a19fc10dea97d469c0b29 /libkdepim/ksyncmanager.cpp
parent456b0246521847635fe98471691ceecae211e0c3 (diff)
downloadkdepimpi-da5e47069d88fa9aa656423ce4c60bf505728e1c.zip
kdepimpi-da5e47069d88fa9aa656423ce4c60bf505728e1c.tar.gz
kdepimpi-da5e47069d88fa9aa656423ce4c60bf505728e1c.tar.bz2
fixes
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 3adbf61..df5a0d9 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,1485 +1,1484 @@
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(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), 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("KSM::syncaction %d ", action); 187 qDebug("KSM::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 mFilterInCal = temp->getFilterInCal(); 255 mFilterInCal = temp->getFilterInCal();
256 mFilterOutCal = temp->getFilterOutCal(); 256 mFilterOutCal = temp->getFilterOutCal();
257 mFilterInAB = temp->getFilterInAB(); 257 mFilterInAB = temp->getFilterInAB();
258 mFilterOutAB = temp->getFilterOutAB(); 258 mFilterOutAB = temp->getFilterOutAB();
259 259
260 if ( action == 1000 ) { 260 if ( action == 1000 ) {
261 mIsKapiFile = false; 261 mIsKapiFile = false;
262#ifdef DESKTOP_VERSION 262#ifdef DESKTOP_VERSION
263 syncKDE(); 263 syncKDE();
264#else 264#else
265 syncSharp(); 265 syncSharp();
266#endif 266#endif
267 267
268 } else if ( action == 1001 ) { 268 } else if ( action == 1001 ) {
269 syncLocalFile(); 269 syncLocalFile();
270 270
271 } else if ( action == 1002 ) { 271 } else if ( action == 1002 ) {
272 mWriteBackFile = false; 272 mWriteBackFile = false;
273 mAskForPreferences = false; 273 mAskForPreferences = false;
274 mShowSyncSummary = false; 274 mShowSyncSummary = false;
275 mSyncAlgoPrefs = 3; 275 mSyncAlgoPrefs = 3;
276 quickSyncLocalFile(); 276 quickSyncLocalFile();
277 277
278 } else if ( action >= 1003 ) { 278 } else if ( action >= 1003 ) {
279 if ( temp->getIsLocalFileSync() ) { 279 if ( temp->getIsLocalFileSync() ) {
280 switch(mTargetApp) 280 switch(mTargetApp)
281 { 281 {
282 case (KAPI): 282 case (KAPI):
283 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 283 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
285 break; 285 break;
286 case (KOPI): 286 case (KOPI):
287 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 287 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
288 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 288 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
289 break; 289 break;
290 case (PWMPI): 290 case (PWMPI):
291 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 291 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
292 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 292 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
293 break; 293 break;
294 default: 294 default:
295 qDebug("KSM::slotSyncMenu: invalid apptype selected"); 295 qDebug("KSM::slotSyncMenu: invalid apptype selected");
296 break; 296 break;
297 297
298 } 298 }
299 } else { 299 } else {
300 if ( temp->getIsPhoneSync() ) { 300 if ( temp->getIsPhoneSync() ) {
301 mPhoneDevice = temp->getPhoneDevice( ) ; 301 mPhoneDevice = temp->getPhoneDevice( ) ;
302 mPhoneConnection = temp->getPhoneConnection( ); 302 mPhoneConnection = temp->getPhoneConnection( );
303 mPhoneModel = temp->getPhoneModel( ); 303 mPhoneModel = temp->getPhoneModel( );
304 syncPhone(); 304 syncPhone();
305 } else if ( temp->getIsPiSync() ) { 305 } else if ( temp->getIsPiSync() ) {
306 if ( mTargetApp == KAPI ) { 306 if ( mTargetApp == KAPI ) {
307 mPassWordPiSync = temp->getRemotePwAB(); 307 mPassWordPiSync = temp->getRemotePwAB();
308 mActiveSyncPort = temp->getRemotePortAB(); 308 mActiveSyncPort = temp->getRemotePortAB();
309 mActiveSyncIP = temp->getRemoteIPAB(); 309 mActiveSyncIP = temp->getRemoteIPAB();
310 } else if ( mTargetApp == KOPI ) { 310 } else if ( mTargetApp == KOPI ) {
311 mPassWordPiSync = temp->getRemotePw(); 311 mPassWordPiSync = temp->getRemotePw();
312 mActiveSyncPort = temp->getRemotePort(); 312 mActiveSyncPort = temp->getRemotePort();
313 mActiveSyncIP = temp->getRemoteIP(); 313 mActiveSyncIP = temp->getRemoteIP();
314 } else { 314 } else {
315 mPassWordPiSync = temp->getRemotePwPWM(); 315 mPassWordPiSync = temp->getRemotePwPWM();
316 mActiveSyncPort = temp->getRemotePortPWM(); 316 mActiveSyncPort = temp->getRemotePortPWM();
317 mActiveSyncIP = temp->getRemoteIPPWM(); 317 mActiveSyncIP = temp->getRemoteIPPWM();
318 } 318 }
319 syncPi(); 319 syncPi();
320 while ( !mPisyncFinished ) { 320 while ( !mPisyncFinished ) {
321 //qDebug("waiting "); 321 //qDebug("waiting ");
322 qApp->processEvents(); 322 qApp->processEvents();
323 } 323 }
324 } else 324 } else
325 syncRemote( temp ); 325 syncRemote( temp );
326 326
327 } 327 }
328 } 328 }
329 delete temp; 329 delete temp;
330 setBlockSave(false); 330 setBlockSave(false);
331} 331}
332 332
333void KSyncManager::enableQuick( bool ask ) 333void KSyncManager::enableQuick( bool ask )
334{ 334{
335 bool autoStart; 335 bool autoStart;
336 bool changed = false; 336 bool changed = false;
337 if ( ask ) { 337 if ( ask ) {
338 QDialog dia ( 0, "input-dialog", true ); 338 QDialog dia ( 0, "input-dialog", true );
339 QLineEdit lab ( &dia ); 339 QLineEdit lab ( &dia );
340 QVBoxLayout lay( &dia ); 340 QVBoxLayout lay( &dia );
341 lab.setText( mPrefs->mPassiveSyncPort ); 341 lab.setText( mPrefs->mPassiveSyncPort );
342 lay.setMargin(7); 342 lay.setMargin(7);
343 lay.setSpacing(7); 343 lay.setSpacing(7);
344 int po = 9197+mTargetApp; 344 int po = 9197+mTargetApp;
345 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 345 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
346 lay.addWidget( &label); 346 lay.addWidget( &label);
347 lay.addWidget( &lab); 347 lay.addWidget( &lab);
348 348
349 QLineEdit lepw ( &dia ); 349 QLineEdit lepw ( &dia );
350 lepw.setText( mPrefs->mPassiveSyncPw ); 350 lepw.setText( mPrefs->mPassiveSyncPw );
351 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 351 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
352 lay.addWidget( &label2); 352 lay.addWidget( &label2);
353 lay.addWidget( &lepw); 353 lay.addWidget( &lepw);
354 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 354 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
355 lay.addWidget( &autostart); 355 lay.addWidget( &autostart);
356 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 356 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
357#ifdef DESKTOP_VERSION 357#ifdef DESKTOP_VERSION
358#ifdef _WIN32_ 358#ifdef _WIN32_
359 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 );
360 syncdesktop.hide();// not implemented! 360 syncdesktop.hide();// not implemented!
361#else 361#else
362 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 );
363#endif 363#endif
364 lay.addWidget( &syncdesktop); 364 lay.addWidget( &syncdesktop);
365#else 365#else
366 mPrefs->mPassiveSyncWithDesktop = false; 366 mPrefs->mPassiveSyncWithDesktop = false;
367 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 367 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
368 syncdesktop.hide(); 368 syncdesktop.hide();
369#endif 369#endif
370 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 370 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
371 371
372 dia.setFixedSize( 230,120 ); 372 dia.setFixedSize( 230,120 );
373 dia.setCaption( i18n("Enter port for Pi-Sync") ); 373 dia.setCaption( i18n("Enter port for Pi-Sync") );
374 QPushButton pb ( "OK", &dia); 374 QPushButton pb ( "OK", &dia);
375 lay.addWidget( &pb ); 375 lay.addWidget( &pb );
376 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 376 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
377 dia.show(); 377 dia.show();
378 if ( ! dia.exec() ) 378 if ( ! dia.exec() )
379 return; 379 return;
380 dia.hide(); 380 dia.hide();
381 qApp->processEvents(); 381 qApp->processEvents();
382 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 382 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
383 changed = true; 383 changed = true;
384 mPrefs->mPassiveSyncPw = lepw.text(); 384 mPrefs->mPassiveSyncPw = lepw.text();
385 } 385 }
386 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 386 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
387 mPrefs->mPassiveSyncPort = lab.text(); 387 mPrefs->mPassiveSyncPort = lab.text();
388 changed = true; 388 changed = true;
389 } 389 }
390 autoStart = autostart.isChecked(); 390 autoStart = autostart.isChecked();
391 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 391 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
392 changed = true; 392 changed = true;
393 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 393 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
394 } 394 }
395 } 395 }
396 else 396 else
397 autoStart = mPrefs->mPassiveSyncAutoStart; 397 autoStart = mPrefs->mPassiveSyncAutoStart;
398 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 398 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
399 changed = true; 399 changed = true;
400 bool ok; 400 bool ok;
401 mPrefs->mPassiveSyncAutoStart = false; 401 mPrefs->mPassiveSyncAutoStart = false;
402 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 402 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
403 if ( ! ok ) { 403 if ( ! ok ) {
404 KMessageBox::information( 0, i18n("No valid port")); 404 KMessageBox::information( 0, i18n("No valid port"));
405 return; 405 return;
406 } 406 }
407 //qDebug("port %d ", port); 407 //qDebug("port %d ", port);
408 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 408 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
409 mServerSocket->setFileName( defaultFileName() );//bbb 409 mServerSocket->setFileName( defaultFileName() );//bbb
410 //qDebug("connected "); 410 //qDebug("connected ");
411 if ( !mServerSocket->ok() ) { 411 if ( !mServerSocket->ok() ) {
412 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!"));
413 delete mServerSocket; 413 delete mServerSocket;
414 mServerSocket = 0; 414 mServerSocket = 0;
415 return; 415 return;
416 } 416 }
417 mPrefs->mPassiveSyncAutoStart = autoStart; 417 mPrefs->mPassiveSyncAutoStart = autoStart;
418 if ( changed ) { 418 if ( changed ) {
419 mPrefs->writeConfig(); 419 mPrefs->writeConfig();
420 } 420 }
421 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 421 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
422 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 422 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
423} 423}
424 424
425void KSyncManager::syncLocalFile() 425void KSyncManager::syncLocalFile()
426{ 426{
427 427
428 QString fn =mPrefs->mLastSyncedLocalFile; 428 QString fn =mPrefs->mLastSyncedLocalFile;
429 QString ext; 429 QString ext;
430 430
431 switch(mTargetApp) 431 switch(mTargetApp)
432 { 432 {
433 case (KAPI): 433 case (KAPI):
434 ext = "(*.vcf)"; 434 ext = "(*.vcf)";
435 break; 435 break;
436 case (KOPI): 436 case (KOPI):
437 ext = "(*.ics/*.vcs)"; 437 ext = "(*.ics/*.vcs)";
438 break; 438 break;
439 case (PWMPI): 439 case (PWMPI):
440 ext = "(*.pwm)"; 440 ext = "(*.pwm)";
441 break; 441 break;
442 default: 442 default:
443 qDebug("KSM::syncLocalFile: invalid apptype selected"); 443 qDebug("KSM::syncLocalFile: invalid apptype selected");
444 break; 444 break;
445 445
446 } 446 }
447 447
448 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 448 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
449 if ( fn == "" ) 449 if ( fn == "" )
450 return; 450 return;
451 if ( syncWithFile( fn, false ) ) { 451 if ( syncWithFile( fn, false ) ) {
452 qDebug("KSM::syncLocalFile() successful "); 452 qDebug("KSM::syncLocalFile() successful ");
453 } 453 }
454 454
455} 455}
456 456
457bool KSyncManager::syncWithFile( QString fn , bool quick ) 457bool KSyncManager::syncWithFile( QString fn , bool quick )
458{ 458{
459 bool ret = false; 459 bool ret = false;
460 QFileInfo info; 460 QFileInfo info;
461 info.setFile( fn ); 461 info.setFile( fn );
462 QString mess; 462 QString mess;
463 bool loadbup = true;
464 if ( !info. exists() ) { 463 if ( !info. exists() ) {
465 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 464 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
466 int result = QMessageBox::warning( mParent, i18n("Warning!"), 465 QMessageBox::warning( mParent, i18n("Warning!"),
467 mess ); 466 mess );
468 return ret; 467 return ret;
469 } 468 }
470 int result = 0; 469 int result = 0;
471 if ( !quick ) { 470 if ( !quick ) {
472 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 471 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
473 result = QMessageBox::warning( mParent, i18n("Warning!"), 472 result = QMessageBox::warning( mParent, i18n("Warning!"),
474 mess, 473 mess,
475 i18n("Sync"), i18n("Cancel"), 0, 474 i18n("Sync"), i18n("Cancel"), 0,
476 0, 1 ); 475 0, 1 );
477 if ( result ) 476 if ( result )
478 return false; 477 return false;
479 } 478 }
480 if ( mAskForPreferences ) 479 if ( mAskForPreferences )
481 if ( !edit_sync_options()) { 480 if ( !edit_sync_options()) {
482 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 481 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
483 return false; 482 return false;
484 } 483 }
485 if ( result == 0 ) { 484 if ( result == 0 ) {
486 //qDebug("Now sycing ... "); 485 //qDebug("Now sycing ... ");
487 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 486 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
488 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 487 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
489 else 488 else
490 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 489 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
491 if ( ! quick ) 490 if ( ! quick )
492 mPrefs->mLastSyncedLocalFile = fn; 491 mPrefs->mLastSyncedLocalFile = fn;
493 } 492 }
494 return ret; 493 return ret;
495} 494}
496 495
497void KSyncManager::quickSyncLocalFile() 496void KSyncManager::quickSyncLocalFile()
498{ 497{
499 498
500 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 499 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
501 qDebug("KSM::quick syncLocalFile() successful "); 500 qDebug("KSM::quick syncLocalFile() successful ");
502 501
503 } 502 }
504} 503}
505 504
506void KSyncManager::multiSync( bool askforPrefs ) 505void KSyncManager::multiSync( bool askforPrefs )
507{ 506{
508 if (blockSave()) 507 if (blockSave())
509 return; 508 return;
510 setBlockSave(true); 509 setBlockSave(true);
511 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 510 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
512 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 511 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
513 question, 512 question,
514 i18n("Yes"), i18n("No"), 513 i18n("Yes"), i18n("No"),
515 0, 0 ) != 0 ) { 514 0, 0 ) != 0 ) {
516 setBlockSave(false); 515 setBlockSave(false);
517 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 516 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
518 return; 517 return;
519 } 518 }
520 mCurrentSyncDevice = i18n("Multiple profiles") ; 519 mCurrentSyncDevice = i18n("Multiple profiles") ;
521 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 520 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
522 if ( askforPrefs ) { 521 if ( askforPrefs ) {
523 if ( !edit_sync_options()) { 522 if ( !edit_sync_options()) {
524 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); 523 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") );
525 return; 524 return;
526 } 525 }
527 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 526 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
528 } 527 }
529 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 528 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
530 qApp->processEvents(); 529 qApp->processEvents();
531 int num = ringSync() ; 530 int num = ringSync() ;
532 if ( num > 1 ) 531 if ( num > 1 )
533 ringSync(); 532 ringSync();
534 setBlockSave(false); 533 setBlockSave(false);
535 if ( num ) 534 if ( num )
536 emit save(); 535 emit save();
537 if ( num ) 536 if ( num )
538 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 537 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
539 else 538 else
540 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 539 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
541 return; 540 return;
542} 541}
543 542
544int KSyncManager::ringSync() 543int KSyncManager::ringSync()
545{ 544{
546 545
547 int syncedProfiles = 0; 546 int syncedProfiles = 0;
548 unsigned int i; 547 unsigned int i;
549 QTime timer; 548 QTime timer;
550 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 549 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
551 QStringList syncProfileNames = mSyncProfileNames; 550 QStringList syncProfileNames = mSyncProfileNames;
552 KSyncProfile* temp = new KSyncProfile (); 551 KSyncProfile* temp = new KSyncProfile ();
553 mAskForPreferences = false; 552 mAskForPreferences = false;
554 for ( i = 0; i < syncProfileNames.count(); ++i ) { 553 for ( i = 0; i < syncProfileNames.count(); ++i ) {
555 mCurrentSyncProfile = i; 554 mCurrentSyncProfile = i;
556 temp->setName(syncProfileNames[mCurrentSyncProfile]); 555 temp->setName(syncProfileNames[mCurrentSyncProfile]);
557 temp->readConfig(&config); 556 temp->readConfig(&config);
558 557
559 bool includeInRingSync; 558 bool includeInRingSync = false;
560 switch(mTargetApp) 559 switch(mTargetApp)
561 { 560 {
562 case (KAPI): 561 case (KAPI):
563 includeInRingSync = temp->getIncludeInRingSyncAB(); 562 includeInRingSync = temp->getIncludeInRingSyncAB();
564 break; 563 break;
565 case (KOPI): 564 case (KOPI):
566 includeInRingSync = temp->getIncludeInRingSync(); 565 includeInRingSync = temp->getIncludeInRingSync();
567 break; 566 break;
568 case (PWMPI): 567 case (PWMPI):
569 includeInRingSync = temp->getIncludeInRingSyncPWM(); 568 includeInRingSync = temp->getIncludeInRingSyncPWM();
570 break; 569 break;
571 default: 570 default:
572 qDebug("KSM::ringSync: invalid apptype selected"); 571 qDebug("KSM::ringSync: invalid apptype selected");
573 break; 572 break;
574 573
575 } 574 }
576 575
577 576
578 if ( includeInRingSync && ( i < 1 || i > 2 )) { 577 if ( includeInRingSync && ( i < 1 || i > 2 )) {
579 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 578 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
580 ++syncedProfiles; 579 ++syncedProfiles;
581 mSyncWithDesktop = false; 580 mSyncWithDesktop = false;
582 // mAskForPreferences = temp->getAskForPreferences(); 581 // mAskForPreferences = temp->getAskForPreferences();
583 mWriteBackFile = temp->getWriteBackFile(); 582 mWriteBackFile = temp->getWriteBackFile();
584 mWriteBackExistingOnly = temp->getWriteBackExisting(); 583 mWriteBackExistingOnly = temp->getWriteBackExisting();
585 mIsKapiFile = temp->getIsKapiFile(); 584 mIsKapiFile = temp->getIsKapiFile();
586 mWriteBackInFuture = 0; 585 mWriteBackInFuture = 0;
587 if ( temp->getWriteBackFuture() ) { 586 if ( temp->getWriteBackFuture() ) {
588 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 587 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
589 mWriteBackInPast = temp->getWriteBackPastWeeks( ); 588 mWriteBackInPast = temp->getWriteBackPastWeeks( );
590 } 589 }
591 mFilterInCal = temp->getFilterInCal(); 590 mFilterInCal = temp->getFilterInCal();
592 mFilterOutCal = temp->getFilterOutCal(); 591 mFilterOutCal = temp->getFilterOutCal();
593 mFilterInAB = temp->getFilterInAB(); 592 mFilterInAB = temp->getFilterInAB();
594 mFilterOutAB = temp->getFilterOutAB(); 593 mFilterOutAB = temp->getFilterOutAB();
595 mShowSyncSummary = false; 594 mShowSyncSummary = false;
596 mCurrentSyncDevice = syncProfileNames[i] ; 595 mCurrentSyncDevice = syncProfileNames[i] ;
597 mCurrentSyncName = mLocalMachineName; 596 mCurrentSyncName = mLocalMachineName;
598 if ( i == 0 ) { 597 if ( i == 0 ) {
599 mIsKapiFile = false; 598 mIsKapiFile = false;
600#ifdef DESKTOP_VERSION 599#ifdef DESKTOP_VERSION
601 syncKDE(); 600 syncKDE();
602#else 601#else
603 syncSharp(); 602 syncSharp();
604#endif 603#endif
605 } else { 604 } else {
606 if ( temp->getIsLocalFileSync() ) { 605 if ( temp->getIsLocalFileSync() ) {
607 switch(mTargetApp) 606 switch(mTargetApp)
608 { 607 {
609 case (KAPI): 608 case (KAPI):
610 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 609 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
611 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 610 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
612 break; 611 break;
613 case (KOPI): 612 case (KOPI):
614 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 613 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
615 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 614 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
616 break; 615 break;
617 case (PWMPI): 616 case (PWMPI):
618 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 617 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
619 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 618 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
620 break; 619 break;
621 default: 620 default:
622 qDebug("KSM: invalid apptype selected"); 621 qDebug("KSM: invalid apptype selected");
623 break; 622 break;
624 } 623 }
625 } else { 624 } else {
626 if ( temp->getIsPhoneSync() ) { 625 if ( temp->getIsPhoneSync() ) {
627 mPhoneDevice = temp->getPhoneDevice( ) ; 626 mPhoneDevice = temp->getPhoneDevice( ) ;
628 mPhoneConnection = temp->getPhoneConnection( ); 627 mPhoneConnection = temp->getPhoneConnection( );
629 mPhoneModel = temp->getPhoneModel( ); 628 mPhoneModel = temp->getPhoneModel( );
630 syncPhone(); 629 syncPhone();
631 } else if ( temp->getIsPiSync() ) { 630 } else if ( temp->getIsPiSync() ) {
632 if ( mTargetApp == KAPI ) { 631 if ( mTargetApp == KAPI ) {
633 mPassWordPiSync = temp->getRemotePwAB(); 632 mPassWordPiSync = temp->getRemotePwAB();
634 mActiveSyncPort = temp->getRemotePortAB(); 633 mActiveSyncPort = temp->getRemotePortAB();
635 mActiveSyncIP = temp->getRemoteIPAB(); 634 mActiveSyncIP = temp->getRemoteIPAB();
636 } else if ( mTargetApp == KOPI ) { 635 } else if ( mTargetApp == KOPI ) {
637 mPassWordPiSync = temp->getRemotePw(); 636 mPassWordPiSync = temp->getRemotePw();
638 mActiveSyncPort = temp->getRemotePort(); 637 mActiveSyncPort = temp->getRemotePort();
639 mActiveSyncIP = temp->getRemoteIP(); 638 mActiveSyncIP = temp->getRemoteIP();
640 } else { 639 } else {
641 mPassWordPiSync = temp->getRemotePwPWM(); 640 mPassWordPiSync = temp->getRemotePwPWM();
642 mActiveSyncPort = temp->getRemotePortPWM(); 641 mActiveSyncPort = temp->getRemotePortPWM();
643 mActiveSyncIP = temp->getRemoteIPPWM(); 642 mActiveSyncIP = temp->getRemoteIPPWM();
644 } 643 }
645 syncPi(); 644 syncPi();
646 while ( !mPisyncFinished ) { 645 while ( !mPisyncFinished ) {
647 //qDebug("waiting "); 646 //qDebug("waiting ");
648 qApp->processEvents(); 647 qApp->processEvents();
649 } 648 }
650 timer.start(); 649 timer.start();
651 while ( timer.elapsed () < 2000 ) { 650 while ( timer.elapsed () < 2000 ) {
652 qApp->processEvents(); 651 qApp->processEvents();
653 } 652 }
654 } else 653 } else
655 syncRemote( temp, false ); 654 syncRemote( temp, false );
656 655
657 } 656 }
658 } 657 }
659 timer.start(); 658 timer.start();
660 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 659 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
661 while ( timer.elapsed () < 2000 ) { 660 while ( timer.elapsed () < 2000 ) {
662 qApp->processEvents(); 661 qApp->processEvents();
663#ifndef _WIN32_ 662#ifndef _WIN32_
664 sleep (1); 663 sleep (1);
665#endif 664#endif
666 } 665 }
667 666
668 } 667 }
669 668
670 } 669 }
671 delete temp; 670 delete temp;
672 return syncedProfiles; 671 return syncedProfiles;
673} 672}
674 673
675void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 674void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
676{ 675{
677 QString question; 676 QString question;
678 if ( ask ) { 677 if ( ask ) {
679 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 678 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
680 if ( QMessageBox::information( mParent, i18n("Sync"), 679 if ( QMessageBox::information( mParent, i18n("Sync"),
681 question, 680 question,
682 i18n("Yes"), i18n("No"), 681 i18n("Yes"), i18n("No"),
683 0, 0 ) != 0 ) 682 0, 0 ) != 0 )
684 return; 683 return;
685 } 684 }
686 685
687 QString preCommand; 686 QString preCommand;
688 QString localTempFile; 687 QString localTempFile;
689 QString postCommand; 688 QString postCommand;
690 689
691 switch(mTargetApp) 690 switch(mTargetApp)
692 { 691 {
693 case (KAPI): 692 case (KAPI):
694 preCommand = prof->getPreSyncCommandAB(); 693 preCommand = prof->getPreSyncCommandAB();
695 postCommand = prof->getPostSyncCommandAB(); 694 postCommand = prof->getPostSyncCommandAB();
696 localTempFile = prof->getLocalTempFileAB(); 695 localTempFile = prof->getLocalTempFileAB();
697 break; 696 break;
698 case (KOPI): 697 case (KOPI):
699 preCommand = prof->getPreSyncCommand(); 698 preCommand = prof->getPreSyncCommand();
700 postCommand = prof->getPostSyncCommand(); 699 postCommand = prof->getPostSyncCommand();
701 localTempFile = prof->getLocalTempFile(); 700 localTempFile = prof->getLocalTempFile();
702 break; 701 break;
703 case (PWMPI): 702 case (PWMPI):
704 preCommand = prof->getPreSyncCommandPWM(); 703 preCommand = prof->getPreSyncCommandPWM();
705 postCommand = prof->getPostSyncCommandPWM(); 704 postCommand = prof->getPostSyncCommandPWM();
706 localTempFile = prof->getLocalTempFilePWM(); 705 localTempFile = prof->getLocalTempFilePWM();
707 break; 706 break;
708 default: 707 default:
709 qDebug("KSM::syncRemote: invalid apptype selected"); 708 qDebug("KSM::syncRemote: invalid apptype selected");
710 break; 709 break;
711 } 710 }
712 711
713 712
714 int fi; 713 int fi;
715 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 714 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
716 QString pwd = getPassword(); 715 QString pwd = getPassword();
717 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 716 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
718 717
719 } 718 }
720 int maxlen = 30; 719 int maxlen = 30;
721 if ( QApplication::desktop()->width() > 320 ) 720 if ( QApplication::desktop()->width() > 320 )
722 maxlen += 25; 721 maxlen += 25;
723 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 722 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
724 int fileSize = 0; 723 int fileSize = 0;
725 int result = system ( preCommand ); 724 int result = system ( preCommand );
726 // 0 : okay 725 // 0 : okay
727 // 256: no such file or dir 726 // 256: no such file or dir
728 // 727 //
729 qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); 728 qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result );
730 if ( result != 0 ) { 729 if ( result != 0 ) {
731 unsigned int len = maxlen; 730 unsigned int len = maxlen;
732 while ( len < preCommand.length() ) { 731 while ( len < preCommand.length() ) {
733 preCommand.insert( len , "\n" ); 732 preCommand.insert( len , "\n" );
734 len += maxlen +2; 733 len += maxlen +2;
735 } 734 }
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) ; 735 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) ;
737 QMessageBox::information( mParent, i18n("Sync - ERROR"), 736 QMessageBox::information( mParent, i18n("Sync - ERROR"),
738 question, 737 question,
739 i18n("Okay!")) ; 738 i18n("Okay!")) ;
740 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 739 mParent->topLevelWidget()->setCaption ("KDE-Pim");
741 return; 740 return;
742 } 741 }
743 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 742 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
744 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 743 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
745 744
746 if ( syncWithFile( localTempFile, true ) ) { 745 if ( syncWithFile( localTempFile, true ) ) {
747 746
748 if ( mWriteBackFile ) { 747 if ( mWriteBackFile ) {
749 int fi; 748 int fi;
750 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 749 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
751 QString pwd = getPassword(); 750 QString pwd = getPassword();
752 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 751 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
753 752
754 } 753 }
755 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 754 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
756 result = system ( postCommand ); 755 result = system ( postCommand );
757 qDebug("KSM::Sync:Writing back file result: %d ", result); 756 qDebug("KSM::Sync:Writing back file result: %d ", result);
758 if ( result != 0 ) { 757 if ( result != 0 ) {
759 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 758 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
760 return; 759 return;
761 } else { 760 } else {
762 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 761 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
763 } 762 }
764 } 763 }
765 } 764 }
766 return; 765 return;
767} 766}
768bool KSyncManager::edit_pisync_options() 767bool KSyncManager::edit_pisync_options()
769{ 768{
770 QDialog dia( mParent, "dia", true ); 769 QDialog dia( mParent, "dia", true );
771 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 770 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
772 QVBoxLayout lay ( &dia ); 771 QVBoxLayout lay ( &dia );
773 lay.setSpacing( 5 ); 772 lay.setSpacing( 5 );
774 lay.setMargin( 3 ); 773 lay.setMargin( 3 );
775 QLabel lab1 ( i18n("Password for remote access:"), &dia); 774 QLabel lab1 ( i18n("Password for remote access:"), &dia);
776 lay.addWidget( &lab1 ); 775 lay.addWidget( &lab1 );
777 QLineEdit le1 (&dia ); 776 QLineEdit le1 (&dia );
778 lay.addWidget( &le1 ); 777 lay.addWidget( &le1 );
779 QLabel lab2 ( i18n("Remote IP address:"), &dia); 778 QLabel lab2 ( i18n("Remote IP address:"), &dia);
780 lay.addWidget( &lab2 ); 779 lay.addWidget( &lab2 );
781 QLineEdit le2 (&dia ); 780 QLineEdit le2 (&dia );
782 lay.addWidget( &le2 ); 781 lay.addWidget( &le2 );
783 QLabel lab3 ( i18n("Remote port number:"), &dia); 782 QLabel lab3 ( i18n("Remote port number:"), &dia);
784 lay.addWidget( &lab3 ); 783 lay.addWidget( &lab3 );
785 QLineEdit le3 (&dia ); 784 QLineEdit le3 (&dia );
786 lay.addWidget( &le3 ); 785 lay.addWidget( &le3 );
787 QPushButton pb ( "OK", &dia); 786 QPushButton pb ( "OK", &dia);
788 lay.addWidget( &pb ); 787 lay.addWidget( &pb );
789 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 788 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
790 le1.setText( mPassWordPiSync ); 789 le1.setText( mPassWordPiSync );
791 le2.setText( mActiveSyncIP ); 790 le2.setText( mActiveSyncIP );
792 le3.setText( mActiveSyncPort ); 791 le3.setText( mActiveSyncPort );
793 if ( dia.exec() ) { 792 if ( dia.exec() ) {
794 mPassWordPiSync = le1.text(); 793 mPassWordPiSync = le1.text();
795 mActiveSyncPort = le3.text(); 794 mActiveSyncPort = le3.text();
796 mActiveSyncIP = le2.text(); 795 mActiveSyncIP = le2.text();
797 return true; 796 return true;
798 } 797 }
799 return false; 798 return false;
800} 799}
801bool KSyncManager::edit_sync_options() 800bool KSyncManager::edit_sync_options()
802{ 801{
803 802
804 QDialog dia( mParent, "dia", true ); 803 QDialog dia( mParent, "dia", true );
805 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 804 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
806 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 805 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
807 QVBoxLayout lay ( &dia ); 806 QVBoxLayout lay ( &dia );
808 lay.setSpacing( 2 ); 807 lay.setSpacing( 2 );
809 lay.setMargin( 3 ); 808 lay.setMargin( 3 );
810 lay.addWidget(&gr); 809 lay.addWidget(&gr);
811 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 810 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
812 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 811 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
813 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 812 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
814 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 813 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
815 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 814 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
816 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 815 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
817 //QRadioButton both( i18n("Take both on conflict"), &gr ); 816 //QRadioButton both( i18n("Take both on conflict"), &gr );
818 QPushButton pb ( "OK", &dia); 817 QPushButton pb ( "OK", &dia);
819 lay.addWidget( &pb ); 818 lay.addWidget( &pb );
820 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 819 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
821 switch ( mSyncAlgoPrefs ) { 820 switch ( mSyncAlgoPrefs ) {
822 case 0: 821 case 0:
823 loc.setChecked( true); 822 loc.setChecked( true);
824 break; 823 break;
825 case 1: 824 case 1:
826 rem.setChecked( true ); 825 rem.setChecked( true );
827 break; 826 break;
828 case 2: 827 case 2:
829 newest.setChecked( true); 828 newest.setChecked( true);
830 break; 829 break;
831 case 3: 830 case 3:
832 ask.setChecked( true); 831 ask.setChecked( true);
833 break; 832 break;
834 case 4: 833 case 4:
835 f_loc.setChecked( true); 834 f_loc.setChecked( true);
836 break; 835 break;
837 case 5: 836 case 5:
838 f_rem.setChecked( true); 837 f_rem.setChecked( true);
839 break; 838 break;
840 case 6: 839 case 6:
841 // both.setChecked( true); 840 // both.setChecked( true);
842 break; 841 break;
843 default: 842 default:
844 break; 843 break;
845 } 844 }
846 if ( dia.exec() ) { 845 if ( dia.exec() ) {
847 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 846 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
848 return true; 847 return true;
849 } 848 }
850 return false; 849 return false;
851} 850}
852 851
853QString KSyncManager::getPassword( ) 852QString KSyncManager::getPassword( )
854{ 853{
855 QString retfile = ""; 854 QString retfile = "";
856 QDialog dia ( mParent, "input-dialog", true ); 855 QDialog dia ( mParent, "input-dialog", true );
857 QLineEdit lab ( &dia ); 856 QLineEdit lab ( &dia );
858 lab.setEchoMode( QLineEdit::Password ); 857 lab.setEchoMode( QLineEdit::Password );
859 QVBoxLayout lay( &dia ); 858 QVBoxLayout lay( &dia );
860 lay.setMargin(7); 859 lay.setMargin(7);
861 lay.setSpacing(7); 860 lay.setSpacing(7);
862 lay.addWidget( &lab); 861 lay.addWidget( &lab);
863 dia.setFixedSize( 230,50 ); 862 dia.setFixedSize( 230,50 );
864 dia.setCaption( i18n("Enter password") ); 863 dia.setCaption( i18n("Enter password") );
865 QPushButton pb ( "OK", &dia); 864 QPushButton pb ( "OK", &dia);
866 lay.addWidget( &pb ); 865 lay.addWidget( &pb );
867 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 866 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
868 dia.show(); 867 dia.show();
869 int res = dia.exec(); 868 int res = dia.exec();
870 if ( res ) 869 if ( res )
871 retfile = lab.text(); 870 retfile = lab.text();
872 dia.hide(); 871 dia.hide();
873 qApp->processEvents(); 872 qApp->processEvents();
874 return retfile; 873 return retfile;
875 874
876} 875}
877 876
878 877
879void KSyncManager::confSync() 878void KSyncManager::confSync()
880{ 879{
881 static KSyncPrefsDialog* sp = 0; 880 static KSyncPrefsDialog* sp = 0;
882 if ( ! sp ) { 881 if ( ! sp ) {
883 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 882 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
884 } 883 }
885 sp->usrReadConfig(); 884 sp->usrReadConfig();
886#ifndef DESKTOP_VERSION 885#ifndef DESKTOP_VERSION
887 sp->showMaximized(); 886 sp->showMaximized();
888#else 887#else
889 sp->show(); 888 sp->show();
890#endif 889#endif
891 sp->exec(); 890 sp->exec();
892 QStringList oldSyncProfileNames = mSyncProfileNames; 891 QStringList oldSyncProfileNames = mSyncProfileNames;
893 mSyncProfileNames = sp->getSyncProfileNames(); 892 mSyncProfileNames = sp->getSyncProfileNames();
894 mLocalMachineName = sp->getLocalMachineName (); 893 mLocalMachineName = sp->getLocalMachineName ();
895 int ii; 894 int ii;
896 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { 895 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
897 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) 896 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
898 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); 897 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
899 } 898 }
900 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 899 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
901} 900}
902void KSyncManager::syncKDE() 901void KSyncManager::syncKDE()
903{ 902{
904 mSyncWithDesktop = true; 903 mSyncWithDesktop = true;
905 emit save(); 904 emit save();
906 switch(mTargetApp) 905 switch(mTargetApp)
907 { 906 {
908 case (KAPI): 907 case (KAPI):
909 { 908 {
910#ifdef DESKTOP_VERSION 909#ifdef DESKTOP_VERSION
911 QString command = qApp->applicationDirPath () + "/kdeabdump"; 910 QString command = qApp->applicationDirPath () + "/kdeabdump";
912#else 911#else
913 QString command = "kdeabdump"; 912 QString command = "kdeabdump";
914#endif 913#endif
915 if ( ! QFile::exists ( command ) ) 914 if ( ! QFile::exists ( command ) )
916 command = "kdeabdump"; 915 command = "kdeabdump";
917 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; 916 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
918 system ( command.latin1()); 917 system ( command.latin1());
919 if ( syncWithFile( fileName,true ) ) { 918 if ( syncWithFile( fileName,true ) ) {
920 if ( mWriteBackFile ) { 919 if ( mWriteBackFile ) {
921 command += " --read"; 920 command += " --read";
922 system ( command.latin1()); 921 system ( command.latin1());
923 } 922 }
924 } 923 }
925 924
926 } 925 }
927 break; 926 break;
928 case (KOPI): 927 case (KOPI):
929 { 928 {
930#ifdef DESKTOP_VERSION 929#ifdef DESKTOP_VERSION
931 QString command = qApp->applicationDirPath () + "/kdecaldump"; 930 QString command = qApp->applicationDirPath () + "/kdecaldump";
932#else 931#else
933 QString command = "kdecaldump"; 932 QString command = "kdecaldump";
934#endif 933#endif
935 if ( ! QFile::exists ( command ) ) 934 if ( ! QFile::exists ( command ) )
936 command = "kdecaldump"; 935 command = "kdecaldump";
937 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 936 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
938 system ( command.latin1()); 937 system ( command.latin1());
939 if ( syncWithFile( fileName,true ) ) { 938 if ( syncWithFile( fileName,true ) ) {
940 if ( mWriteBackFile ) { 939 if ( mWriteBackFile ) {
941 command += " --read"; 940 command += " --read";
942 system ( command.latin1()); 941 system ( command.latin1());
943 } 942 }
944 } 943 }
945 944
946 } 945 }
947 break; 946 break;
948 case (PWMPI): 947 case (PWMPI):
949 948
950 break; 949 break;
951 default: 950 default:
952 qDebug("KSM::slotSyncMenu: invalid apptype selected"); 951 qDebug("KSM::slotSyncMenu: invalid apptype selected");
953 break; 952 break;
954 953
955 } 954 }
956} 955}
957 956
958void KSyncManager::syncSharp() 957void KSyncManager::syncSharp()
959{ 958{
960 959
961 if ( ! syncExternalApplication("sharp") ) 960 if ( ! syncExternalApplication("sharp") )
962 qDebug("KSM::ERROR sync sharp "); 961 qDebug("KSM::ERROR sync sharp ");
963} 962}
964 963
965bool KSyncManager::syncExternalApplication(QString resource) 964bool KSyncManager::syncExternalApplication(QString resource)
966{ 965{
967 966
968 emit save(); 967 emit save();
969 968
970 if ( mAskForPreferences ) 969 if ( mAskForPreferences )
971 if ( !edit_sync_options()) { 970 if ( !edit_sync_options()) {
972 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 971 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
973 return false; 972 return false;
974 } 973 }
975 974
976 qDebug("KSM::Sync extern %s", resource.latin1()); 975 qDebug("KSM::Sync extern %s", resource.latin1());
977 976
978 bool syncOK = mImplementation->syncExternal(this, resource); 977 bool syncOK = mImplementation->syncExternal(this, resource);
979 978
980 return syncOK; 979 return syncOK;
981 980
982} 981}
983 982
984void KSyncManager::syncPhone() 983void KSyncManager::syncPhone()
985{ 984{
986 985
987 syncExternalApplication("phone"); 986 syncExternalApplication("phone");
988 987
989} 988}
990 989
991void KSyncManager::showProgressBar(int percentage, QString caption, int total) 990void KSyncManager::showProgressBar(int percentage, QString caption, int total)
992{ 991{
993 if (!bar->isVisible()) 992 if (!bar->isVisible())
994 { 993 {
995 bar->setCaption (caption); 994 bar->setCaption (caption);
996 bar->setTotalSteps ( total ) ; 995 bar->setTotalSteps ( total ) ;
997 bar->show(); 996 bar->show();
998 } 997 }
999 bar->raise(); 998 bar->raise();
1000 bar->setProgress( percentage ); 999 bar->setProgress( percentage );
1001 qApp->processEvents(); 1000 qApp->processEvents();
1002} 1001}
1003 1002
1004void KSyncManager::hideProgressBar() 1003void KSyncManager::hideProgressBar()
1005{ 1004{
1006 bar->hide(); 1005 bar->hide();
1007 qApp->processEvents(); 1006 qApp->processEvents();
1008} 1007}
1009 1008
1010bool KSyncManager::isProgressBarCanceled() 1009bool KSyncManager::isProgressBarCanceled()
1011{ 1010{
1012 return !bar->isVisible(); 1011 return !bar->isVisible();
1013} 1012}
1014 1013
1015QString KSyncManager::syncFileName() 1014QString KSyncManager::syncFileName()
1016{ 1015{
1017 1016
1018 QString fn = "tempfile"; 1017 QString fn = "tempfile";
1019 switch(mTargetApp) 1018 switch(mTargetApp)
1020 { 1019 {
1021 case (KAPI): 1020 case (KAPI):
1022 fn = "tempsyncab.vcf"; 1021 fn = "tempsyncab.vcf";
1023 break; 1022 break;
1024 case (KOPI): 1023 case (KOPI):
1025 fn = "tempsynccal.ics"; 1024 fn = "tempsynccal.ics";
1026 break; 1025 break;
1027 case (PWMPI): 1026 case (PWMPI):
1028 fn = "tempsyncpw.pwm"; 1027 fn = "tempsyncpw.pwm";
1029 break; 1028 break;
1030 default: 1029 default:
1031 break; 1030 break;
1032 } 1031 }
1033#ifdef _WIN32_ 1032#ifdef _WIN32_
1034 return locateLocal( "tmp", fn ); 1033 return locateLocal( "tmp", fn );
1035#else 1034#else
1036 return (QString( "/tmp/" )+ fn ); 1035 return (QString( "/tmp/" )+ fn );
1037#endif 1036#endif
1038} 1037}
1039 1038
1040void KSyncManager::syncPi() 1039void KSyncManager::syncPi()
1041{ 1040{
1042 mIsKapiFile = true; 1041 mIsKapiFile = true;
1043 mPisyncFinished = false; 1042 mPisyncFinished = false;
1044 qApp->processEvents(); 1043 qApp->processEvents();
1045 if ( mAskForPreferences ) 1044 if ( mAskForPreferences )
1046 if ( !edit_pisync_options()) { 1045 if ( !edit_pisync_options()) {
1047 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1046 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1048 return; 1047 return;
1049 } 1048 }
1050 bool ok; 1049 bool ok;
1051 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1050 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1052 if ( ! ok ) { 1051 if ( ! ok ) {
1053 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1052 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1054 return; 1053 return;
1055 } 1054 }
1056 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 1055 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
1057 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1056 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1058 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 1057 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
1059 commandSocket->readFile( syncFileName() ); 1058 commandSocket->readFile( syncFileName() );
1060} 1059}
1061 1060
1062void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1061void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1063{ 1062{
1064 //enum { success, errorW, errorR, quiet }; 1063 //enum { success, errorW, errorR, quiet };
1065 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1064 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1066 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1065 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1067 delete s; 1066 delete s;
1068 if ( state == KCommandSocket::errorR ) { 1067 if ( state == KCommandSocket::errorR ) {
1069 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1068 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1070 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1069 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1071 commandSocket->sendStop(); 1070 commandSocket->sendStop();
1072 } 1071 }
1073 mPisyncFinished = true; 1072 mPisyncFinished = true;
1074 return; 1073 return;
1075 1074
1076 } else if ( state == KCommandSocket::errorW ) { 1075 } else if ( state == KCommandSocket::errorW ) {
1077 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1076 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1078 mPisyncFinished = true; 1077 mPisyncFinished = true;
1079 1078
1080 } else if ( state == KCommandSocket::successR ) { 1079 } else if ( state == KCommandSocket::successR ) {
1081 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1080 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1082 1081
1083 } else if ( state == KCommandSocket::successW ) { 1082 } else if ( state == KCommandSocket::successW ) {
1084 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1083 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1085 mPisyncFinished = true; 1084 mPisyncFinished = true;
1086 } 1085 }
1087 1086
1088 delete s; 1087 delete s;
1089} 1088}
1090 1089
1091void KSyncManager::readFileFromSocket() 1090void KSyncManager::readFileFromSocket()
1092{ 1091{
1093 QString fileName = syncFileName(); 1092 QString fileName = syncFileName();
1094 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1093 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1095 if ( ! syncWithFile( fileName , true ) ) { 1094 if ( ! syncWithFile( fileName , true ) ) {
1096 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1095 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1097 mPisyncFinished = true; 1096 mPisyncFinished = true;
1098 return; 1097 return;
1099 } 1098 }
1100 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1099 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1101 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1100 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1102 if ( mWriteBackFile ) 1101 if ( mWriteBackFile )
1103 commandSocket->writeFile( fileName ); 1102 commandSocket->writeFile( fileName );
1104 else { 1103 else {
1105 commandSocket->sendStop(); 1104 commandSocket->sendStop();
1106 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1105 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1107 mPisyncFinished = true; 1106 mPisyncFinished = true;
1108 } 1107 }
1109} 1108}
1110 1109
1111KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1110KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1112{ 1111{
1113 mPassWord = pw; 1112 mPassWord = pw;
1114 mSocket = 0; 1113 mSocket = 0;
1115 mSyncActionDialog = 0; 1114 mSyncActionDialog = 0;
1116 blockRC = false; 1115 blockRC = false;
1117}; 1116};
1118 1117
1119void KServerSocket::newConnection ( int socket ) 1118void KServerSocket::newConnection ( int socket )
1120{ 1119{
1121 // qDebug("KServerSocket:New connection %d ", socket); 1120 // qDebug("KServerSocket:New connection %d ", socket);
1122 if ( mSocket ) { 1121 if ( mSocket ) {
1123 qDebug("KSS::newConnection Socket deleted! "); 1122 qDebug("KSS::newConnection Socket deleted! ");
1124 delete mSocket; 1123 delete mSocket;
1125 mSocket = 0; 1124 mSocket = 0;
1126 } 1125 }
1127 mSocket = new QSocket( this ); 1126 mSocket = new QSocket( this );
1128 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1127 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1129 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1128 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1130 mSocket->setSocket( socket ); 1129 mSocket->setSocket( socket );
1131} 1130}
1132 1131
1133void KServerSocket::discardClient() 1132void KServerSocket::discardClient()
1134{ 1133{
1135 //qDebug(" KServerSocket::discardClient()"); 1134 //qDebug(" KServerSocket::discardClient()");
1136 if ( mSocket ) { 1135 if ( mSocket ) {
1137 delete mSocket; 1136 delete mSocket;
1138 mSocket = 0; 1137 mSocket = 0;
1139 } 1138 }
1140 //emit endConnect(); 1139 //emit endConnect();
1141} 1140}
1142void KServerSocket::readClient() 1141void KServerSocket::readClient()
1143{ 1142{
1144 if ( blockRC ) 1143 if ( blockRC )
1145 return; 1144 return;
1146 if ( mSocket == 0 ) { 1145 if ( mSocket == 0 ) {
1147 qDebug("ERROR::KSS::readClient(): mSocket == 0 "); 1146 qDebug("ERROR::KSS::readClient(): mSocket == 0 ");
1148 return; 1147 return;
1149 } 1148 }
1150 //qDebug("KServerSocket::readClient()"); 1149 //qDebug("KServerSocket::readClient()");
1151 if ( mSocket->canReadLine() ) { 1150 if ( mSocket->canReadLine() ) {
1152 QString line = mSocket->readLine(); 1151 QString line = mSocket->readLine();
1153 //qDebug("KServerSocket readline: %s ", line.latin1()); 1152 //qDebug("KServerSocket readline: %s ", line.latin1());
1154 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1153 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1155 if ( tokens[0] == "GET" ) { 1154 if ( tokens[0] == "GET" ) {
1156 if ( tokens[1] == mPassWord ) { 1155 if ( tokens[1] == mPassWord ) {
1157 //emit sendFile( mSocket ); 1156 //emit sendFile( mSocket );
1158 bool ok = false; 1157 bool ok = false;
1159 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1158 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1160 if ( ok ) { 1159 if ( ok ) {
1161 KSyncManager::mRequestedSyncEvent = dt; 1160 KSyncManager::mRequestedSyncEvent = dt;
1162 } 1161 }
1163 else 1162 else
1164 KSyncManager::mRequestedSyncEvent = QDateTime(); 1163 KSyncManager::mRequestedSyncEvent = QDateTime();
1165 send_file(); 1164 send_file();
1166 } 1165 }
1167 else { 1166 else {
1168 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1167 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1169 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1168 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1170 } 1169 }
1171 } 1170 }
1172 if ( tokens[0] == "PUT" ) { 1171 if ( tokens[0] == "PUT" ) {
1173 if ( tokens[1] == mPassWord ) { 1172 if ( tokens[1] == mPassWord ) {
1174 //emit getFile( mSocket ); 1173 //emit getFile( mSocket );
1175 blockRC = true; 1174 blockRC = true;
1176 get_file(); 1175 get_file();
1177 } 1176 }
1178 else { 1177 else {
1179 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1178 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1180 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1179 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1181 } 1180 }
1182 } 1181 }
1183 if ( tokens[0] == "STOP" ) { 1182 if ( tokens[0] == "STOP" ) {
1184 //emit endConnect(); 1183 //emit endConnect();
1185 end_connect(); 1184 end_connect();
1186 } 1185 }
1187 } 1186 }
1188} 1187}
1189void KServerSocket::end_connect() 1188void KServerSocket::end_connect()
1190{ 1189{
1191 delete mSyncActionDialog; 1190 delete mSyncActionDialog;
1192 mSyncActionDialog = 0; 1191 mSyncActionDialog = 0;
1193} 1192}
1194void KServerSocket::send_file() 1193void KServerSocket::send_file()
1195{ 1194{
1196 //qDebug("MainWindow::sendFile(QSocket* s) "); 1195 //qDebug("MainWindow::sendFile(QSocket* s) ");
1197 if ( mSyncActionDialog ) 1196 if ( mSyncActionDialog )
1198 delete mSyncActionDialog; 1197 delete mSyncActionDialog;
1199 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1198 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1200 mSyncActionDialog->setCaption(i18n("Received sync request")); 1199 mSyncActionDialog->setCaption(i18n("Received sync request"));
1201 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1200 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1202 label->setAlignment ( Qt::AlignHCenter ); 1201 label->setAlignment ( Qt::AlignHCenter );
1203 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1202 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1204 lay->addWidget( label); 1203 lay->addWidget( label);
1205 lay->setMargin(7); 1204 lay->setMargin(7);
1206 lay->setSpacing(7); 1205 lay->setSpacing(7);
1207 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1206 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1208 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1207 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1209 if ( secs < 0 ) 1208 if ( secs < 0 )
1210 secs = secs * (-1); 1209 secs = secs * (-1);
1211 if ( secs > 30 ) 1210 if ( secs > 30 )
1212 //if ( true ) 1211 //if ( true )
1213 { 1212 {
1214 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1213 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1215 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1214 QLabel* label = new QLabel( warning, mSyncActionDialog );
1216 label->setAlignment ( Qt::AlignHCenter ); 1215 label->setAlignment ( Qt::AlignHCenter );
1217 lay->addWidget( label); 1216 lay->addWidget( label);
1218 if ( secs > 180 ) 1217 if ( secs > 180 )
1219 { 1218 {
1220 if ( secs > 300 ) { 1219 if ( secs > 300 ) {
1221 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { 1220 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) {
1222 qDebug("KSS::Sync cancelled ,cs"); 1221 qDebug("KSS::Sync cancelled ,cs");
1223 return ; 1222 return ;
1224 } 1223 }
1225 } 1224 }
1226 QFont f = label->font(); 1225 QFont f = label->font();
1227 f.setPointSize ( f.pointSize() *2 ); 1226 f.setPointSize ( f.pointSize() *2 );
1228 f. setBold (true ); 1227 f. setBold (true );
1229 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1228 QLabel* label = new QLabel( warning, mSyncActionDialog );
1230 label->setFont( f ); 1229 label->setFont( f );
1231 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1230 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1232 label->setText( warning ); 1231 label->setText( warning );
1233 label->setAlignment ( Qt::AlignHCenter ); 1232 label->setAlignment ( Qt::AlignHCenter );
1234 lay->addWidget( label); 1233 lay->addWidget( label);
1235 mSyncActionDialog->setFixedSize( 230, 300); 1234 mSyncActionDialog->setFixedSize( 230, 300);
1236 } else { 1235 } else {
1237 mSyncActionDialog->setFixedSize( 230, 200); 1236 mSyncActionDialog->setFixedSize( 230, 200);
1238 } 1237 }
1239 } else { 1238 } else {
1240 mSyncActionDialog->setFixedSize( 230, 120); 1239 mSyncActionDialog->setFixedSize( 230, 120);
1241 } 1240 }
1242 } else 1241 } else
1243 mSyncActionDialog->setFixedSize( 230, 120); 1242 mSyncActionDialog->setFixedSize( 230, 120);
1244 mSyncActionDialog->show(); 1243 mSyncActionDialog->show();
1245 mSyncActionDialog->raise(); 1244 mSyncActionDialog->raise();
1246 emit request_file(); 1245 emit request_file();
1247 qApp->processEvents(); 1246 qApp->processEvents();
1248 QString fileName = mFileName; 1247 QString fileName = mFileName;
1249 QFile file( fileName ); 1248 QFile file( fileName );
1250 if (!file.open( IO_ReadOnly ) ) { 1249 if (!file.open( IO_ReadOnly ) ) {
1251 delete mSyncActionDialog; 1250 delete mSyncActionDialog;
1252 mSyncActionDialog = 0; 1251 mSyncActionDialog = 0;
1253 qDebug("KSS::error open sync file: %s ", fileName.latin1()); 1252 qDebug("KSS::error open sync file: %s ", fileName.latin1());
1254 mSocket->close(); 1253 mSocket->close();
1255 if ( mSocket->state() == QSocket::Idle ) 1254 if ( mSocket->state() == QSocket::Idle )
1256 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1255 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1257 return ; 1256 return ;
1258 1257
1259 } 1258 }
1260 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1259 mSyncActionDialog->setCaption( i18n("Sending file...") );
1261 QTextStream ts( &file ); 1260 QTextStream ts( &file );
1262 ts.setEncoding( QTextStream::Latin1 ); 1261 ts.setEncoding( QTextStream::Latin1 );
1263 1262
1264 QTextStream os( mSocket ); 1263 QTextStream os( mSocket );
1265 os.setEncoding( QTextStream::Latin1 ); 1264 os.setEncoding( QTextStream::Latin1 );
1266 while ( ! ts.atEnd() ) { 1265 while ( ! ts.atEnd() ) {
1267 os << ts.readLine() << "\r\n"; 1266 os << ts.readLine() << "\r\n";
1268 } 1267 }
1269 //os << ts.read(); 1268 //os << ts.read();
1270 file.close(); 1269 file.close();
1271 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1270 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1272 mSocket->close(); 1271 mSocket->close();
1273 if ( mSocket->state() == QSocket::Idle ) 1272 if ( mSocket->state() == QSocket::Idle )
1274 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1273 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1275} 1274}
1276void KServerSocket::get_file() 1275void KServerSocket::get_file()
1277{ 1276{
1278 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1277 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1279 1278
1280 piTime.start(); 1279 piTime.start();
1281 piFileString = ""; 1280 piFileString = "";
1282 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1281 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1283} 1282}
1284 1283
1285 1284
1286void KServerSocket::readBackFileFromSocket() 1285void KServerSocket::readBackFileFromSocket()
1287{ 1286{
1288 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1287 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1289 while ( mSocket->canReadLine () ) { 1288 while ( mSocket->canReadLine () ) {
1290 piTime.restart(); 1289 piTime.restart();
1291 QString line = mSocket->readLine (); 1290 QString line = mSocket->readLine ();
1292 piFileString += line; 1291 piFileString += line;
1293 //qDebug("readline: %s ", line.latin1()); 1292 //qDebug("readline: %s ", line.latin1());
1294 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1293 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1295 1294
1296 } 1295 }
1297 if ( piTime.elapsed () < 3000 ) { 1296 if ( piTime.elapsed () < 3000 ) {
1298 // wait for more 1297 // wait for more
1299 //qDebug("waitformore "); 1298 //qDebug("waitformore ");
1300 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1299 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1301 return; 1300 return;
1302 } 1301 }
1303 QString fileName = mFileName; 1302 QString fileName = mFileName;
1304 QFile file ( fileName ); 1303 QFile file ( fileName );
1305 if (!file.open( IO_WriteOnly ) ) { 1304 if (!file.open( IO_WriteOnly ) ) {
1306 delete mSyncActionDialog; 1305 delete mSyncActionDialog;
1307 mSyncActionDialog = 0; 1306 mSyncActionDialog = 0;
1308 qDebug("KSS:Error open read back file "); 1307 qDebug("KSS:Error open read back file ");
1309 piFileString = ""; 1308 piFileString = "";
1310 emit file_received( false ); 1309 emit file_received( false );
1311 blockRC = false; 1310 blockRC = false;
1312 return ; 1311 return ;
1313 1312
1314 } 1313 }
1315 1314
1316 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1315 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1317 QTextStream ts ( &file ); 1316 QTextStream ts ( &file );
1318 ts.setEncoding( QTextStream::Latin1 ); 1317 ts.setEncoding( QTextStream::Latin1 );
1319 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1318 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1320 ts << piFileString; 1319 ts << piFileString;
1321 mSocket->close(); 1320 mSocket->close();
1322 if ( mSocket->state() == QSocket::Idle ) 1321 if ( mSocket->state() == QSocket::Idle )
1323 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1322 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1324 file.close(); 1323 file.close();
1325 piFileString = ""; 1324 piFileString = "";
1326 emit file_received( true ); 1325 emit file_received( true );
1327 delete mSyncActionDialog; 1326 delete mSyncActionDialog;
1328 mSyncActionDialog = 0; 1327 mSyncActionDialog = 0;
1329 blockRC = false; 1328 blockRC = false;
1330 1329
1331} 1330}
1332 1331
1333KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1332KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1334{ 1333{
1335 mPassWord = password; 1334 mPassWord = password;
1336 mSocket = 0; 1335 mSocket = 0;
1337 mPort = port; 1336 mPort = port;
1338 mHost = host; 1337 mHost = host;
1339 1338
1340 mRetVal = quiet; 1339 mRetVal = quiet;
1341 mTimerSocket = new QTimer ( this ); 1340 mTimerSocket = new QTimer ( this );
1342 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1341 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1343} 1342}
1344void KCommandSocket::readFile( QString fn ) 1343void KCommandSocket::readFile( QString fn )
1345{ 1344{
1346 if ( !mSocket ) { 1345 if ( !mSocket ) {
1347 mSocket = new QSocket( this ); 1346 mSocket = new QSocket( this );
1348 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1347 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1349 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1348 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1350 } 1349 }
1351 mFileString = ""; 1350 mFileString = "";
1352 mFileName = fn; 1351 mFileName = fn;
1353 mFirst = true; 1352 mFirst = true;
1354 mSocket->connectToHost( mHost, mPort ); 1353 mSocket->connectToHost( mHost, mPort );
1355 QTextStream os( mSocket ); 1354 QTextStream os( mSocket );
1356 os.setEncoding( QTextStream::Latin1 ); 1355 os.setEncoding( QTextStream::Latin1 );
1357 1356
1358 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); 1357 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1359 os << "GET " << mPassWord << curDt <<"\r\n"; 1358 os << "GET " << mPassWord << curDt <<"\r\n";
1360 mTimerSocket->start( 300000 ); 1359 mTimerSocket->start( 300000 );
1361} 1360}
1362 1361
1363void KCommandSocket::writeFile( QString fileName ) 1362void KCommandSocket::writeFile( QString fileName )
1364{ 1363{
1365 if ( !mSocket ) { 1364 if ( !mSocket ) {
1366 mSocket = new QSocket( this ); 1365 mSocket = new QSocket( this );
1367 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1366 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1368 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1367 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1369 } 1368 }
1370 mFileName = fileName ; 1369 mFileName = fileName ;
1371 mSocket->connectToHost( mHost, mPort ); 1370 mSocket->connectToHost( mHost, mPort );
1372} 1371}
1373void KCommandSocket::writeFileToSocket() 1372void KCommandSocket::writeFileToSocket()
1374{ 1373{
1375 QFile file2( mFileName ); 1374 QFile file2( mFileName );
1376 if (!file2.open( IO_ReadOnly ) ) { 1375 if (!file2.open( IO_ReadOnly ) ) {
1377 mRetVal= errorW; 1376 mRetVal= errorW;
1378 mSocket->close(); 1377 mSocket->close();
1379 if ( mSocket->state() == QSocket::Idle ) 1378 if ( mSocket->state() == QSocket::Idle )
1380 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1379 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1381 return ; 1380 return ;
1382 } 1381 }
1383 QTextStream ts2( &file2 ); 1382 QTextStream ts2( &file2 );
1384 ts2.setEncoding( QTextStream::Latin1 ); 1383 ts2.setEncoding( QTextStream::Latin1 );
1385 QTextStream os2( mSocket ); 1384 QTextStream os2( mSocket );
1386 os2.setEncoding( QTextStream::Latin1 ); 1385 os2.setEncoding( QTextStream::Latin1 );
1387 os2 << "PUT " << mPassWord << "\r\n";; 1386 os2 << "PUT " << mPassWord << "\r\n";;
1388 while ( ! ts2.atEnd() ) { 1387 while ( ! ts2.atEnd() ) {
1389 os2 << ts2.readLine() << "\r\n"; 1388 os2 << ts2.readLine() << "\r\n";
1390 } 1389 }
1391 mRetVal= successW; 1390 mRetVal= successW;
1392 file2.close(); 1391 file2.close();
1393 mSocket->close(); 1392 mSocket->close();
1394 if ( mSocket->state() == QSocket::Idle ) 1393 if ( mSocket->state() == QSocket::Idle )
1395 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1394 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1396} 1395}
1397void KCommandSocket::sendStop() 1396void KCommandSocket::sendStop()
1398{ 1397{
1399 if ( !mSocket ) { 1398 if ( !mSocket ) {
1400 mSocket = new QSocket( this ); 1399 mSocket = new QSocket( this );
1401 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1400 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1402 } 1401 }
1403 mSocket->connectToHost( mHost, mPort ); 1402 mSocket->connectToHost( mHost, mPort );
1404 QTextStream os2( mSocket ); 1403 QTextStream os2( mSocket );
1405 os2.setEncoding( QTextStream::Latin1 ); 1404 os2.setEncoding( QTextStream::Latin1 );
1406 os2 << "STOP\r\n"; 1405 os2 << "STOP\r\n";
1407 mSocket->close(); 1406 mSocket->close();
1408 if ( mSocket->state() == QSocket::Idle ) 1407 if ( mSocket->state() == QSocket::Idle )
1409 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1408 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1410} 1409}
1411 1410
1412void KCommandSocket::startReadFileFromSocket() 1411void KCommandSocket::startReadFileFromSocket()
1413{ 1412{
1414 if ( ! mFirst ) 1413 if ( ! mFirst )
1415 return; 1414 return;
1416 mFirst = false; 1415 mFirst = false;
1417 mTimerSocket->stop(); 1416 mTimerSocket->stop();
1418 mFileString = ""; 1417 mFileString = "";
1419 mTime.start(); 1418 mTime.start();
1420 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1419 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1421 1420
1422} 1421}
1423void KCommandSocket::readFileFromSocket() 1422void KCommandSocket::readFileFromSocket()
1424{ 1423{
1425 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1424 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1426 while ( mSocket->canReadLine () ) { 1425 while ( mSocket->canReadLine () ) {
1427 mTime.restart(); 1426 mTime.restart();
1428 QString line = mSocket->readLine (); 1427 QString line = mSocket->readLine ();
1429 mFileString += line; 1428 mFileString += line;
1430 //qDebug("readline: %s ", line.latin1()); 1429 //qDebug("readline: %s ", line.latin1());
1431 } 1430 }
1432 if ( mTime.elapsed () < 3000 ) { 1431 if ( mTime.elapsed () < 3000 ) {
1433 // wait for more 1432 // wait for more
1434 //qDebug("waitformore "); 1433 //qDebug("waitformore ");
1435 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1434 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1436 return; 1435 return;
1437 } 1436 }
1438 QString fileName = mFileName; 1437 QString fileName = mFileName;
1439 QFile file ( fileName ); 1438 QFile file ( fileName );
1440 if (!file.open( IO_WriteOnly ) ) { 1439 if (!file.open( IO_WriteOnly ) ) {
1441 mFileString = ""; 1440 mFileString = "";
1442 mRetVal = errorR; 1441 mRetVal = errorR;
1443 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1442 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1444 deleteSocket(); 1443 deleteSocket();
1445 return ; 1444 return ;
1446 1445
1447 } 1446 }
1448 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1447 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1449 QTextStream ts ( &file ); 1448 QTextStream ts ( &file );
1450 ts.setEncoding( QTextStream::Latin1 ); 1449 ts.setEncoding( QTextStream::Latin1 );
1451 ts << mFileString; 1450 ts << mFileString;
1452 file.close(); 1451 file.close();
1453 mFileString = ""; 1452 mFileString = "";
1454 mRetVal = successR; 1453 mRetVal = successR;
1455 mSocket->close(); 1454 mSocket->close();
1456 // if state is not idle, deleteSocket(); is called via 1455 // if state is not idle, deleteSocket(); is called via
1457 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1456 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1458 if ( mSocket->state() == QSocket::Idle ) 1457 if ( mSocket->state() == QSocket::Idle )
1459 deleteSocket(); 1458 deleteSocket();
1460} 1459}
1461 1460
1462void KCommandSocket::deleteSocket() 1461void KCommandSocket::deleteSocket()
1463{ 1462{
1464 //qDebug("KCommandSocket::deleteSocket() "); 1463 //qDebug("KCommandSocket::deleteSocket() ");
1465 if ( mTimerSocket->isActive () ) { 1464 if ( mTimerSocket->isActive () ) {
1466 mTimerSocket->stop(); 1465 mTimerSocket->stop();
1467 mRetVal = errorTO; 1466 mRetVal = errorTO;
1468 qDebug("KCS::Connection to remote host timed out"); 1467 qDebug("KCS::Connection to remote host timed out");
1469 if ( mSocket ) { 1468 if ( mSocket ) {
1470 mSocket->close(); 1469 mSocket->close();
1471 //if ( mSocket->state() == QSocket::Idle ) 1470 //if ( mSocket->state() == QSocket::Idle )
1472 // deleteSocket(); 1471 // deleteSocket();
1473 delete mSocket; 1472 delete mSocket;
1474 mSocket = 0; 1473 mSocket = 0;
1475 } 1474 }
1476 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1475 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1477 emit commandFinished( this, mRetVal ); 1476 emit commandFinished( this, mRetVal );
1478 return; 1477 return;
1479 } 1478 }
1480 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1479 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1481 if ( mSocket) 1480 if ( mSocket)
1482 delete mSocket; 1481 delete mSocket;
1483 mSocket = 0; 1482 mSocket = 0;
1484 emit commandFinished( this, mRetVal ); 1483 emit commandFinished( this, mRetVal );
1485} 1484}