summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2005-01-16 10:26:46 (UTC)
committer zautrix <zautrix>2005-01-16 10:26:46 (UTC)
commit5138d4edea4189100ddc8bf6bd82bccbdcaebf95 (patch) (unidiff)
treec4ec0d0552d06065a1e9f8eb12c44fcbfdd19f4a /libkdepim/ksyncmanager.cpp
parent62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0 (diff)
downloadkdepimpi-5138d4edea4189100ddc8bf6bd82bccbdcaebf95.zip
kdepimpi-5138d4edea4189100ddc8bf6bd82bccbdcaebf95.tar.gz
kdepimpi-5138d4edea4189100ddc8bf6bd82bccbdcaebf95.tar.bz2
filter setings changed
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 33b4a65..6c1f444 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,1354 +1,1362 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <qbuttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52 52
53#include <klocale.h> 53#include <klocale.h>
54#include <kglobal.h> 54#include <kglobal.h>
55#include <kconfig.h> 55#include <kconfig.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57 57
58QDateTime KSyncManager::mRequestedSyncEvent; 58QDateTime KSyncManager::mRequestedSyncEvent;
59 59
60 60
61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
62 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 62 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
63{ 63{
64 mServerSocket = 0; 64 mServerSocket = 0;
65 bar = new QProgressBar ( 1, 0 ); 65 bar = new QProgressBar ( 1, 0 );
66 bar->setCaption (""); 66 bar->setCaption ("");
67 mWriteBackInPast = 2; 67 mWriteBackInPast = 2;
68 int w = 300; 68 int w = 300;
69 if ( QApplication::desktop()->width() < 320 ) 69 if ( QApplication::desktop()->width() < 320 )
70 w = 220; 70 w = 220;
71 int h = bar->sizeHint().height() ; 71 int h = bar->sizeHint().height() ;
72 int dw = QApplication::desktop()->width(); 72 int dw = QApplication::desktop()->width();
73 int dh = QApplication::desktop()->height(); 73 int dh = QApplication::desktop()->height();
74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
75 if ( mPrefs->mPassiveSyncAutoStart ) 75 if ( mPrefs->mPassiveSyncAutoStart )
76 enableQuick( false ); 76 enableQuick( false );
77 77
78} 78}
79 79
80KSyncManager::~KSyncManager() 80KSyncManager::~KSyncManager()
81{ 81{
82 delete bar; 82 delete bar;
83} 83}
84 84
85 85
86void KSyncManager::fillSyncMenu() 86void KSyncManager::fillSyncMenu()
87{ 87{
88 if ( mSyncMenu->count() ) 88 if ( mSyncMenu->count() )
89 mSyncMenu->clear(); 89 mSyncMenu->clear();
90 90
91 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 91 mSyncMenu->insertItem( i18n("Configure..."), 0 );
92 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
95 clearMenu->insertItem( i18n("For all profiles"), 1 ); 95 clearMenu->insertItem( i18n("For all profiles"), 1 );
96 clearMenu->insertSeparator(); 96 clearMenu->insertSeparator();
97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
98 mSyncMenu->insertSeparator(); 98 mSyncMenu->insertSeparator();
99 if ( mServerSocket == 0 ) { 99 if ( mServerSocket == 0 ) {
100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
101 } else { 101 } else {
102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
103 } 103 }
104 mSyncMenu->insertSeparator(); 104 mSyncMenu->insertSeparator();
105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
106 mSyncMenu->insertSeparator(); 106 mSyncMenu->insertSeparator();
107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
108 config.setGroup("General"); 108 config.setGroup("General");
109 QStringList prof = config.readListEntry("SyncProfileNames"); 109 QStringList prof = config.readListEntry("SyncProfileNames");
110 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 110 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
111 if ( prof.count() < 2 ) { 111 if ( prof.count() < 2 ) {
112 prof.clear(); 112 prof.clear();
113 QString externalName; 113 QString externalName;
114#ifdef DESKTOP_VERSION 114#ifdef DESKTOP_VERSION
115#ifdef _WIN32_ 115#ifdef _WIN32_
116 externalName = "OutLook(not_implemented)"; 116 externalName = "OutLook(not_implemented)";
117#else 117#else
118 externalName = "KDE_Desktop"; 118 externalName = "KDE_Desktop";
119#endif 119#endif
120#else 120#else
121 externalName = "Sharp_DTM"; 121 externalName = "Sharp_DTM";
122#endif 122#endif
123 prof << externalName; 123 prof << externalName;
124 prof << i18n("Local_file"); 124 prof << i18n("Local_file");
125 prof << i18n("Last_file"); 125 prof << i18n("Last_file");
126 KSyncProfile* temp = new KSyncProfile (); 126 KSyncProfile* temp = new KSyncProfile ();
127 temp->setName( prof[0] ); 127 temp->setName( prof[0] );
128 temp->writeConfig(&config); 128 temp->writeConfig(&config);
129 temp->setName( prof[1] ); 129 temp->setName( prof[1] );
130 temp->writeConfig(&config); 130 temp->writeConfig(&config);
131 temp->setName( prof[2] ); 131 temp->setName( prof[2] );
132 temp->writeConfig(&config); 132 temp->writeConfig(&config);
133 config.setGroup("General"); 133 config.setGroup("General");
134 config.writeEntry("SyncProfileNames",prof); 134 config.writeEntry("SyncProfileNames",prof);
135 config.writeEntry("ExternSyncProfiles",externalName); 135 config.writeEntry("ExternSyncProfiles",externalName);
136 config.sync(); 136 config.sync();
137 delete temp; 137 delete temp;
138 } 138 }
139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
140 mSyncProfileNames = prof; 140 mSyncProfileNames = prof;
141 unsigned int i; 141 unsigned int i;
142 for ( i = 0; i < prof.count(); ++i ) { 142 for ( i = 0; i < prof.count(); ++i ) {
143 mSyncMenu->insertItem( prof[i], 1000+i ); 143 mSyncMenu->insertItem( prof[i], 1000+i );
144 clearMenu->insertItem( prof[i], 1000+i ); 144 clearMenu->insertItem( prof[i], 1000+i );
145 if ( i == 2 ) 145 if ( i == 2 )
146 mSyncMenu->insertSeparator(); 146 mSyncMenu->insertSeparator();
147 } 147 }
148 QDir app_dir; 148 QDir app_dir;
149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
150 if ( mTargetApp == PWMPI) { 150 if ( mTargetApp == PWMPI) {
151 mSyncMenu->removeItem( 1000 ); 151 mSyncMenu->removeItem( 1000 );
152 clearMenu->removeItem( 1000 ); 152 clearMenu->removeItem( 1000 );
153 } 153 }
154#ifndef DESKTOP_VERSION 154#ifndef DESKTOP_VERSION
155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
156 mSyncMenu->removeItem( 1000 ); 156 mSyncMenu->removeItem( 1000 );
157 clearMenu->removeItem( 1000 ); 157 clearMenu->removeItem( 1000 );
158 } 158 }
159#endif 159#endif
160 mSyncMenu->removeItem( 1002 ); 160 mSyncMenu->removeItem( 1002 );
161 clearMenu->removeItem( 1002 ); 161 clearMenu->removeItem( 1002 );
162} 162}
163void KSyncManager::slotClearMenu( int action ) 163void KSyncManager::slotClearMenu( int action )
164{ 164{
165 QString syncDevice; 165 QString syncDevice;
166 if ( action > 999 ) { 166 if ( action > 999 ) {
167 syncDevice = mSyncProfileNames[action - 1000] ; 167 syncDevice = mSyncProfileNames[action - 1000] ;
168 } 168 }
169 169
170 170
171 171
172 int result = 0; 172 int result = 0;
173 QString sd; 173 QString sd;
174 if ( syncDevice.isEmpty() ) 174 if ( syncDevice.isEmpty() )
175 sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); 175 sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
176 else 176 else
177 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); 177 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
178 178
179 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, 179 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
180 0, 1 ); 180 0, 1 );
181 if ( result ) 181 if ( result )
182 return; 182 return;
183 mImplementation->removeSyncInfo( syncDevice ); 183 mImplementation->removeSyncInfo( syncDevice );
184} 184}
185void KSyncManager::slotSyncMenu( int action ) 185void KSyncManager::slotSyncMenu( int action )
186{ 186{
187 qDebug("syncaction %d ", action); 187 qDebug("syncaction %d ", action);
188 if ( action == 5000 ) 188 if ( action == 5000 )
189 return; 189 return;
190 mSyncWithDesktop = false; 190 mSyncWithDesktop = false;
191 if ( action == 0 ) { 191 if ( action == 0 ) {
192 192
193 // seems to be a Qt2 event handling bug 193 // seems to be a Qt2 event handling bug
194 // syncmenu.clear causes a segfault at first time 194 // syncmenu.clear causes a segfault at first time
195 // when we call it after the main event loop, it is ok 195 // when we call it after the main event loop, it is ok
196 // same behaviour when calling OM/Pi via QCOP for the first time 196 // same behaviour when calling OM/Pi via QCOP for the first time
197 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 197 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
198 //confSync(); 198 //confSync();
199 199
200 return; 200 return;
201 } 201 }
202 if ( action == 1 ) { 202 if ( action == 1 ) {
203 multiSync( true ); 203 multiSync( true );
204 return; 204 return;
205 } 205 }
206 if ( action == 2 ) { 206 if ( action == 2 ) {
207 enableQuick(); 207 enableQuick();
208 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 208 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
209 return; 209 return;
210 } 210 }
211 if ( action == 3 ) { 211 if ( action == 3 ) {
212 delete mServerSocket; 212 delete mServerSocket;
213 mServerSocket = 0; 213 mServerSocket = 0;
214 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 214 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
215 return; 215 return;
216 } 216 }
217 217
218 if (blockSave()) 218 if (blockSave())
219 return; 219 return;
220 220
221 setBlockSave(true); 221 setBlockSave(true);
222 bool silent = false; 222 bool silent = false;
223 if ( action == 999 ) { 223 if ( action == 999 ) {
224 //special mode for silent syncing 224 //special mode for silent syncing
225 action = 1000; 225 action = 1000;
226 silent = true; 226 silent = true;
227 } 227 }
228 228
229 mCurrentSyncProfile = action - 1000 ; 229 mCurrentSyncProfile = action - 1000 ;
230 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 230 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
231 mCurrentSyncName = mLocalMachineName ; 231 mCurrentSyncName = mLocalMachineName ;
232 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 232 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
233 KSyncProfile* temp = new KSyncProfile (); 233 KSyncProfile* temp = new KSyncProfile ();
234 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 234 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
235 temp->readConfig(&config); 235 temp->readConfig(&config);
236 if (silent) { 236 if (silent) {
237 mAskForPreferences = false; 237 mAskForPreferences = false;
238 mShowSyncSummary = false; 238 mShowSyncSummary = false;
239 mWriteBackFile = true; 239 mWriteBackFile = true;
240 mSyncAlgoPrefs = 2;// take newest 240 mSyncAlgoPrefs = 2;// take newest
241 } 241 }
242 else { 242 else {
243 mAskForPreferences = temp->getAskForPreferences(); 243 mAskForPreferences = temp->getAskForPreferences();
244 mShowSyncSummary = temp->getShowSummaryAfterSync(); 244 mShowSyncSummary = temp->getShowSummaryAfterSync();
245 mWriteBackFile = temp->getWriteBackFile(); 245 mWriteBackFile = temp->getWriteBackFile();
246 mSyncAlgoPrefs = temp->getSyncPrefs(); 246 mSyncAlgoPrefs = temp->getSyncPrefs();
247 } 247 }
248 mWriteBackExistingOnly = temp->getWriteBackExisting(); 248 mWriteBackExistingOnly = temp->getWriteBackExisting();
249 mIsKapiFile = temp->getIsKapiFile(); 249 mIsKapiFile = temp->getIsKapiFile();
250 mWriteBackInFuture = 0; 250 mWriteBackInFuture = 0;
251 if ( temp->getWriteBackFuture() ) { 251 if ( temp->getWriteBackFuture() ) {
252 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 252 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
253 mWriteBackInPast = temp->getWriteBackPastWeeks( ); 253 mWriteBackInPast = temp->getWriteBackPastWeeks( );
254 } 254 }
255 255 mFilterInCal = temp->getFilterInCal();
256 mFilterOutCal = temp->getFilterOutCal();
257 mFilterInAB = temp->getFilterInAB();
258 mFilterOutAB = temp->getFilterOutAB();
259
256 if ( action == 1000 ) { 260 if ( action == 1000 ) {
257 mIsKapiFile = false; 261 mIsKapiFile = false;
258#ifdef DESKTOP_VERSION 262#ifdef DESKTOP_VERSION
259 syncKDE(); 263 syncKDE();
260#else 264#else
261 syncSharp(); 265 syncSharp();
262#endif 266#endif
263 267
264 } else if ( action == 1001 ) { 268 } else if ( action == 1001 ) {
265 syncLocalFile(); 269 syncLocalFile();
266 270
267 } else if ( action == 1002 ) { 271 } else if ( action == 1002 ) {
268 mWriteBackFile = false; 272 mWriteBackFile = false;
269 mAskForPreferences = false; 273 mAskForPreferences = false;
270 mShowSyncSummary = false; 274 mShowSyncSummary = false;
271 mSyncAlgoPrefs = 3; 275 mSyncAlgoPrefs = 3;
272 quickSyncLocalFile(); 276 quickSyncLocalFile();
273 277
274 } else if ( action >= 1003 ) { 278 } else if ( action >= 1003 ) {
275 if ( temp->getIsLocalFileSync() ) { 279 if ( temp->getIsLocalFileSync() ) {
276 switch(mTargetApp) 280 switch(mTargetApp)
277 { 281 {
278 case (KAPI): 282 case (KAPI):
279 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 283 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
280 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
281 break; 285 break;
282 case (KOPI): 286 case (KOPI):
283 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 287 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 288 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
285 break; 289 break;
286 case (PWMPI): 290 case (PWMPI):
287 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 291 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
288 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 292 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
289 break; 293 break;
290 default: 294 default:
291 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 295 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
292 break; 296 break;
293 297
294 } 298 }
295 } else { 299 } else {
296 if ( temp->getIsPhoneSync() ) { 300 if ( temp->getIsPhoneSync() ) {
297 mPhoneDevice = temp->getPhoneDevice( ) ; 301 mPhoneDevice = temp->getPhoneDevice( ) ;
298 mPhoneConnection = temp->getPhoneConnection( ); 302 mPhoneConnection = temp->getPhoneConnection( );
299 mPhoneModel = temp->getPhoneModel( ); 303 mPhoneModel = temp->getPhoneModel( );
300 syncPhone(); 304 syncPhone();
301 } else if ( temp->getIsPiSync() ) { 305 } else if ( temp->getIsPiSync() ) {
302 if ( mTargetApp == KAPI ) { 306 if ( mTargetApp == KAPI ) {
303 mPassWordPiSync = temp->getRemotePwAB(); 307 mPassWordPiSync = temp->getRemotePwAB();
304 mActiveSyncPort = temp->getRemotePortAB(); 308 mActiveSyncPort = temp->getRemotePortAB();
305 mActiveSyncIP = temp->getRemoteIPAB(); 309 mActiveSyncIP = temp->getRemoteIPAB();
306 } else if ( mTargetApp == KOPI ) { 310 } else if ( mTargetApp == KOPI ) {
307 mPassWordPiSync = temp->getRemotePw(); 311 mPassWordPiSync = temp->getRemotePw();
308 mActiveSyncPort = temp->getRemotePort(); 312 mActiveSyncPort = temp->getRemotePort();
309 mActiveSyncIP = temp->getRemoteIP(); 313 mActiveSyncIP = temp->getRemoteIP();
310 } else { 314 } else {
311 mPassWordPiSync = temp->getRemotePwPWM(); 315 mPassWordPiSync = temp->getRemotePwPWM();
312 mActiveSyncPort = temp->getRemotePortPWM(); 316 mActiveSyncPort = temp->getRemotePortPWM();
313 mActiveSyncIP = temp->getRemoteIPPWM(); 317 mActiveSyncIP = temp->getRemoteIPPWM();
314 } 318 }
315 syncPi(); 319 syncPi();
316 while ( !mPisyncFinished ) { 320 while ( !mPisyncFinished ) {
317 //qDebug("waiting "); 321 //qDebug("waiting ");
318 qApp->processEvents(); 322 qApp->processEvents();
319 } 323 }
320 } else 324 } else
321 syncRemote( temp ); 325 syncRemote( temp );
322 326
323 } 327 }
324 } 328 }
325 delete temp; 329 delete temp;
326 setBlockSave(false); 330 setBlockSave(false);
327} 331}
328 332
329void KSyncManager::enableQuick( bool ask ) 333void KSyncManager::enableQuick( bool ask )
330{ 334{
331 bool autoStart; 335 bool autoStart;
332 bool changed = false; 336 bool changed = false;
333 if ( ask ) { 337 if ( ask ) {
334 QDialog dia ( 0, "input-dialog", true ); 338 QDialog dia ( 0, "input-dialog", true );
335 QLineEdit lab ( &dia ); 339 QLineEdit lab ( &dia );
336 QVBoxLayout lay( &dia ); 340 QVBoxLayout lay( &dia );
337 lab.setText( mPrefs->mPassiveSyncPort ); 341 lab.setText( mPrefs->mPassiveSyncPort );
338 lay.setMargin(7); 342 lay.setMargin(7);
339 lay.setSpacing(7); 343 lay.setSpacing(7);
340 int po = 9197+mTargetApp; 344 int po = 9197+mTargetApp;
341 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 345 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
342 lay.addWidget( &label); 346 lay.addWidget( &label);
343 lay.addWidget( &lab); 347 lay.addWidget( &lab);
344 348
345 QLineEdit lepw ( &dia ); 349 QLineEdit lepw ( &dia );
346 lepw.setText( mPrefs->mPassiveSyncPw ); 350 lepw.setText( mPrefs->mPassiveSyncPw );
347 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 351 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
348 lay.addWidget( &label2); 352 lay.addWidget( &label2);
349 lay.addWidget( &lepw); 353 lay.addWidget( &lepw);
350 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 354 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
351 lay.addWidget( &autostart); 355 lay.addWidget( &autostart);
352 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 356 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
353#ifdef DESKTOP_VERSION 357#ifdef DESKTOP_VERSION
354#ifdef _WIN32_ 358#ifdef _WIN32_
355 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 359 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
356 syncdesktop.hide();// not implemented! 360 syncdesktop.hide();// not implemented!
357#else 361#else
358 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 362 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
359#endif 363#endif
360 lay.addWidget( &syncdesktop); 364 lay.addWidget( &syncdesktop);
361#else 365#else
362 mPrefs->mPassiveSyncWithDesktop = false; 366 mPrefs->mPassiveSyncWithDesktop = false;
363 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 367 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
364 syncdesktop.hide(); 368 syncdesktop.hide();
365#endif 369#endif
366 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 370 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
367 371
368 dia.setFixedSize( 230,120 ); 372 dia.setFixedSize( 230,120 );
369 dia.setCaption( i18n("Enter port for Pi-Sync") ); 373 dia.setCaption( i18n("Enter port for Pi-Sync") );
370 QPushButton pb ( "OK", &dia); 374 QPushButton pb ( "OK", &dia);
371 lay.addWidget( &pb ); 375 lay.addWidget( &pb );
372 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 376 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
373 dia.show(); 377 dia.show();
374 if ( ! dia.exec() ) 378 if ( ! dia.exec() )
375 return; 379 return;
376 dia.hide(); 380 dia.hide();
377 qApp->processEvents(); 381 qApp->processEvents();
378 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 382 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
379 changed = true; 383 changed = true;
380 mPrefs->mPassiveSyncPw = lepw.text(); 384 mPrefs->mPassiveSyncPw = lepw.text();
381 } 385 }
382 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 386 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
383 mPrefs->mPassiveSyncPort = lab.text(); 387 mPrefs->mPassiveSyncPort = lab.text();
384 changed = true; 388 changed = true;
385 } 389 }
386 autoStart = autostart.isChecked(); 390 autoStart = autostart.isChecked();
387 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 391 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
388 changed = true; 392 changed = true;
389 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 393 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
390 } 394 }
391 } 395 }
392 else 396 else
393 autoStart = mPrefs->mPassiveSyncAutoStart; 397 autoStart = mPrefs->mPassiveSyncAutoStart;
394 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 398 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
395 changed = true; 399 changed = true;
396 bool ok; 400 bool ok;
397 mPrefs->mPassiveSyncAutoStart = false; 401 mPrefs->mPassiveSyncAutoStart = false;
398 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 402 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
399 if ( ! ok ) { 403 if ( ! ok ) {
400 KMessageBox::information( 0, i18n("No valid port")); 404 KMessageBox::information( 0, i18n("No valid port"));
401 return; 405 return;
402 } 406 }
403 //qDebug("port %d ", port); 407 //qDebug("port %d ", port);
404 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 408 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
405 mServerSocket->setFileName( defaultFileName() );//bbb 409 mServerSocket->setFileName( defaultFileName() );//bbb
406 //qDebug("connected "); 410 //qDebug("connected ");
407 if ( !mServerSocket->ok() ) { 411 if ( !mServerSocket->ok() ) {
408 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 412 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
409 delete mServerSocket; 413 delete mServerSocket;
410 mServerSocket = 0; 414 mServerSocket = 0;
411 return; 415 return;
412 } 416 }
413 mPrefs->mPassiveSyncAutoStart = autoStart; 417 mPrefs->mPassiveSyncAutoStart = autoStart;
414 if ( changed ) { 418 if ( changed ) {
415 mPrefs->writeConfig(); 419 mPrefs->writeConfig();
416 } 420 }
417 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 421 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
418 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 422 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
419} 423}
420 424
421void KSyncManager::syncLocalFile() 425void KSyncManager::syncLocalFile()
422{ 426{
423 427
424 QString fn =mPrefs->mLastSyncedLocalFile; 428 QString fn =mPrefs->mLastSyncedLocalFile;
425 QString ext; 429 QString ext;
426 430
427 switch(mTargetApp) 431 switch(mTargetApp)
428 { 432 {
429 case (KAPI): 433 case (KAPI):
430 ext = "(*.vcf)"; 434 ext = "(*.vcf)";
431 break; 435 break;
432 case (KOPI): 436 case (KOPI):
433 ext = "(*.ics/*.vcs)"; 437 ext = "(*.ics/*.vcs)";
434 break; 438 break;
435 case (PWMPI): 439 case (PWMPI):
436 ext = "(*.pwm)"; 440 ext = "(*.pwm)";
437 break; 441 break;
438 default: 442 default:
439 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 443 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
440 break; 444 break;
441 445
442 } 446 }
443 447
444 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 448 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
445 if ( fn == "" ) 449 if ( fn == "" )
446 return; 450 return;
447 if ( syncWithFile( fn, false ) ) { 451 if ( syncWithFile( fn, false ) ) {
448 qDebug("syncLocalFile() successful "); 452 qDebug("syncLocalFile() successful ");
449 } 453 }
450 454
451} 455}
452 456
453bool KSyncManager::syncWithFile( QString fn , bool quick ) 457bool KSyncManager::syncWithFile( QString fn , bool quick )
454{ 458{
455 bool ret = false; 459 bool ret = false;
456 QFileInfo info; 460 QFileInfo info;
457 info.setFile( fn ); 461 info.setFile( fn );
458 QString mess; 462 QString mess;
459 bool loadbup = true; 463 bool loadbup = true;
460 if ( !info. exists() ) { 464 if ( !info. exists() ) {
461 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 465 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
462 int result = QMessageBox::warning( mParent, i18n("Warning!"), 466 int result = QMessageBox::warning( mParent, i18n("Warning!"),
463 mess ); 467 mess );
464 return ret; 468 return ret;
465 } 469 }
466 int result = 0; 470 int result = 0;
467 if ( !quick ) { 471 if ( !quick ) {
468 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 472 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
469 result = QMessageBox::warning( mParent, i18n("Warning!"), 473 result = QMessageBox::warning( mParent, i18n("Warning!"),
470 mess, 474 mess,
471 i18n("Sync"), i18n("Cancel"), 0, 475 i18n("Sync"), i18n("Cancel"), 0,
472 0, 1 ); 476 0, 1 );
473 if ( result ) 477 if ( result )
474 return false; 478 return false;
475 } 479 }
476 if ( mAskForPreferences ) 480 if ( mAskForPreferences )
477 if ( !edit_sync_options()) { 481 if ( !edit_sync_options()) {
478 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 482 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
479 return false; 483 return false;
480 } 484 }
481 if ( result == 0 ) { 485 if ( result == 0 ) {
482 //qDebug("Now sycing ... "); 486 //qDebug("Now sycing ... ");
483 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 487 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
484 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 488 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
485 else 489 else
486 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 490 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
487 if ( ! quick ) 491 if ( ! quick )
488 mPrefs->mLastSyncedLocalFile = fn; 492 mPrefs->mLastSyncedLocalFile = fn;
489 } 493 }
490 return ret; 494 return ret;
491} 495}
492 496
493void KSyncManager::quickSyncLocalFile() 497void KSyncManager::quickSyncLocalFile()
494{ 498{
495 499
496 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 500 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
497 qDebug("quick syncLocalFile() successful "); 501 qDebug("quick syncLocalFile() successful ");
498 502
499 } 503 }
500} 504}
501 505
502void KSyncManager::multiSync( bool askforPrefs ) 506void KSyncManager::multiSync( bool askforPrefs )
503{ 507{
504 if (blockSave()) 508 if (blockSave())
505 return; 509 return;
506 setBlockSave(true); 510 setBlockSave(true);
507 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 511 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
508 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 512 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
509 question, 513 question,
510 i18n("Yes"), i18n("No"), 514 i18n("Yes"), i18n("No"),
511 0, 0 ) != 0 ) { 515 0, 0 ) != 0 ) {
512 setBlockSave(false); 516 setBlockSave(false);
513 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 517 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
514 return; 518 return;
515 } 519 }
516 mCurrentSyncDevice = i18n("Multiple profiles") ; 520 mCurrentSyncDevice = i18n("Multiple profiles") ;
517 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 521 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
518 if ( askforPrefs ) { 522 if ( askforPrefs ) {
519 if ( !edit_sync_options()) { 523 if ( !edit_sync_options()) {
520 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); 524 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") );
521 return; 525 return;
522 } 526 }
523 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 527 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
524 } 528 }
525 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 529 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
526 qApp->processEvents(); 530 qApp->processEvents();
527 int num = ringSync() ; 531 int num = ringSync() ;
528 if ( num > 1 ) 532 if ( num > 1 )
529 ringSync(); 533 ringSync();
530 setBlockSave(false); 534 setBlockSave(false);
531 if ( num ) 535 if ( num )
532 emit save(); 536 emit save();
533 if ( num ) 537 if ( num )
534 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 538 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
535 else 539 else
536 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 540 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
537 return; 541 return;
538} 542}
539 543
540int KSyncManager::ringSync() 544int KSyncManager::ringSync()
541{ 545{
542 546
543 int syncedProfiles = 0; 547 int syncedProfiles = 0;
544 unsigned int i; 548 unsigned int i;
545 QTime timer; 549 QTime timer;
546 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 550 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
547 QStringList syncProfileNames = mSyncProfileNames; 551 QStringList syncProfileNames = mSyncProfileNames;
548 KSyncProfile* temp = new KSyncProfile (); 552 KSyncProfile* temp = new KSyncProfile ();
549 mAskForPreferences = false; 553 mAskForPreferences = false;
550 for ( i = 0; i < syncProfileNames.count(); ++i ) { 554 for ( i = 0; i < syncProfileNames.count(); ++i ) {
551 mCurrentSyncProfile = i; 555 mCurrentSyncProfile = i;
552 temp->setName(syncProfileNames[mCurrentSyncProfile]); 556 temp->setName(syncProfileNames[mCurrentSyncProfile]);
553 temp->readConfig(&config); 557 temp->readConfig(&config);
554 558
555 bool includeInRingSync; 559 bool includeInRingSync;
556 switch(mTargetApp) 560 switch(mTargetApp)
557 { 561 {
558 case (KAPI): 562 case (KAPI):
559 includeInRingSync = temp->getIncludeInRingSyncAB(); 563 includeInRingSync = temp->getIncludeInRingSyncAB();
560 break; 564 break;
561 case (KOPI): 565 case (KOPI):
562 includeInRingSync = temp->getIncludeInRingSync(); 566 includeInRingSync = temp->getIncludeInRingSync();
563 break; 567 break;
564 case (PWMPI): 568 case (PWMPI):
565 includeInRingSync = temp->getIncludeInRingSyncPWM(); 569 includeInRingSync = temp->getIncludeInRingSyncPWM();
566 break; 570 break;
567 default: 571 default:
568 qDebug("KSyncManager::ringSync: invalid apptype selected"); 572 qDebug("KSyncManager::ringSync: invalid apptype selected");
569 break; 573 break;
570 574
571 } 575 }
572 576
573 577
574 if ( includeInRingSync && ( i < 1 || i > 2 )) { 578 if ( includeInRingSync && ( i < 1 || i > 2 )) {
575 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 579 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
576 ++syncedProfiles; 580 ++syncedProfiles;
577 mSyncWithDesktop = false; 581 mSyncWithDesktop = false;
578 // mAskForPreferences = temp->getAskForPreferences(); 582 // mAskForPreferences = temp->getAskForPreferences();
579 mWriteBackFile = temp->getWriteBackFile(); 583 mWriteBackFile = temp->getWriteBackFile();
580 mWriteBackExistingOnly = temp->getWriteBackExisting(); 584 mWriteBackExistingOnly = temp->getWriteBackExisting();
581 mIsKapiFile = temp->getIsKapiFile(); 585 mIsKapiFile = temp->getIsKapiFile();
582 mWriteBackInFuture = 0; 586 mWriteBackInFuture = 0;
583 if ( temp->getWriteBackFuture() ) { 587 if ( temp->getWriteBackFuture() ) {
584 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 588 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
585 mWriteBackInPast = temp->getWriteBackPastWeeks( ); 589 mWriteBackInPast = temp->getWriteBackPastWeeks( );
586 } 590 }
591 mFilterInCal = temp->getFilterInCal();
592 mFilterOutCal = temp->getFilterOutCal();
593 mFilterInAB = temp->getFilterInAB();
594 mFilterOutAB = temp->getFilterOutAB();
587 mShowSyncSummary = false; 595 mShowSyncSummary = false;
588 mCurrentSyncDevice = syncProfileNames[i] ; 596 mCurrentSyncDevice = syncProfileNames[i] ;
589 mCurrentSyncName = mLocalMachineName; 597 mCurrentSyncName = mLocalMachineName;
590 if ( i == 0 ) { 598 if ( i == 0 ) {
591 mIsKapiFile = false; 599 mIsKapiFile = false;
592#ifdef DESKTOP_VERSION 600#ifdef DESKTOP_VERSION
593 syncKDE(); 601 syncKDE();
594#else 602#else
595 syncSharp(); 603 syncSharp();
596#endif 604#endif
597 } else { 605 } else {
598 if ( temp->getIsLocalFileSync() ) { 606 if ( temp->getIsLocalFileSync() ) {
599 switch(mTargetApp) 607 switch(mTargetApp)
600 { 608 {
601 case (KAPI): 609 case (KAPI):
602 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 610 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
603 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 611 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
604 break; 612 break;
605 case (KOPI): 613 case (KOPI):
606 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 614 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
607 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 615 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
608 break; 616 break;
609 case (PWMPI): 617 case (PWMPI):
610 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 618 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
611 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 619 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
612 break; 620 break;
613 default: 621 default:
614 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 622 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
615 break; 623 break;
616 } 624 }
617 } else { 625 } else {
618 if ( temp->getIsPhoneSync() ) { 626 if ( temp->getIsPhoneSync() ) {
619 mPhoneDevice = temp->getPhoneDevice( ) ; 627 mPhoneDevice = temp->getPhoneDevice( ) ;
620 mPhoneConnection = temp->getPhoneConnection( ); 628 mPhoneConnection = temp->getPhoneConnection( );
621 mPhoneModel = temp->getPhoneModel( ); 629 mPhoneModel = temp->getPhoneModel( );
622 syncPhone(); 630 syncPhone();
623 } else if ( temp->getIsPiSync() ) { 631 } else if ( temp->getIsPiSync() ) {
624 if ( mTargetApp == KAPI ) { 632 if ( mTargetApp == KAPI ) {
625 mPassWordPiSync = temp->getRemotePwAB(); 633 mPassWordPiSync = temp->getRemotePwAB();
626 mActiveSyncPort = temp->getRemotePortAB(); 634 mActiveSyncPort = temp->getRemotePortAB();
627 mActiveSyncIP = temp->getRemoteIPAB(); 635 mActiveSyncIP = temp->getRemoteIPAB();
628 } else if ( mTargetApp == KOPI ) { 636 } else if ( mTargetApp == KOPI ) {
629 mPassWordPiSync = temp->getRemotePw(); 637 mPassWordPiSync = temp->getRemotePw();
630 mActiveSyncPort = temp->getRemotePort(); 638 mActiveSyncPort = temp->getRemotePort();
631 mActiveSyncIP = temp->getRemoteIP(); 639 mActiveSyncIP = temp->getRemoteIP();
632 } else { 640 } else {
633 mPassWordPiSync = temp->getRemotePwPWM(); 641 mPassWordPiSync = temp->getRemotePwPWM();
634 mActiveSyncPort = temp->getRemotePortPWM(); 642 mActiveSyncPort = temp->getRemotePortPWM();
635 mActiveSyncIP = temp->getRemoteIPPWM(); 643 mActiveSyncIP = temp->getRemoteIPPWM();
636 } 644 }
637 syncPi(); 645 syncPi();
638 while ( !mPisyncFinished ) { 646 while ( !mPisyncFinished ) {
639 //qDebug("waiting "); 647 //qDebug("waiting ");
640 qApp->processEvents(); 648 qApp->processEvents();
641 } 649 }
642 timer.start(); 650 timer.start();
643 while ( timer.elapsed () < 2000 ) { 651 while ( timer.elapsed () < 2000 ) {
644 qApp->processEvents(); 652 qApp->processEvents();
645 } 653 }
646 } else 654 } else
647 syncRemote( temp, false ); 655 syncRemote( temp, false );
648 656
649 } 657 }
650 } 658 }
651 timer.start(); 659 timer.start();
652 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 660 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
653 while ( timer.elapsed () < 2000 ) { 661 while ( timer.elapsed () < 2000 ) {
654 qApp->processEvents(); 662 qApp->processEvents();
655#ifndef _WIN32_ 663#ifndef _WIN32_
656 sleep (1); 664 sleep (1);
657#endif 665#endif
658 } 666 }
659 667
660 } 668 }
661 669
662 } 670 }
663 delete temp; 671 delete temp;
664 return syncedProfiles; 672 return syncedProfiles;
665} 673}
666 674
667void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 675void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
668{ 676{
669 QString question; 677 QString question;
670 if ( ask ) { 678 if ( ask ) {
671 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 679 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
672 if ( QMessageBox::information( mParent, i18n("Sync"), 680 if ( QMessageBox::information( mParent, i18n("Sync"),
673 question, 681 question,
674 i18n("Yes"), i18n("No"), 682 i18n("Yes"), i18n("No"),
675 0, 0 ) != 0 ) 683 0, 0 ) != 0 )
676 return; 684 return;
677 } 685 }
678 686
679 QString preCommand; 687 QString preCommand;
680 QString localTempFile; 688 QString localTempFile;
681 QString postCommand; 689 QString postCommand;
682 690
683 switch(mTargetApp) 691 switch(mTargetApp)
684 { 692 {
685 case (KAPI): 693 case (KAPI):
686 preCommand = prof->getPreSyncCommandAB(); 694 preCommand = prof->getPreSyncCommandAB();
687 postCommand = prof->getPostSyncCommandAB(); 695 postCommand = prof->getPostSyncCommandAB();
688 localTempFile = prof->getLocalTempFileAB(); 696 localTempFile = prof->getLocalTempFileAB();
689 break; 697 break;
690 case (KOPI): 698 case (KOPI):
691 preCommand = prof->getPreSyncCommand(); 699 preCommand = prof->getPreSyncCommand();
692 postCommand = prof->getPostSyncCommand(); 700 postCommand = prof->getPostSyncCommand();
693 localTempFile = prof->getLocalTempFile(); 701 localTempFile = prof->getLocalTempFile();
694 break; 702 break;
695 case (PWMPI): 703 case (PWMPI):
696 preCommand = prof->getPreSyncCommandPWM(); 704 preCommand = prof->getPreSyncCommandPWM();
697 postCommand = prof->getPostSyncCommandPWM(); 705 postCommand = prof->getPostSyncCommandPWM();
698 localTempFile = prof->getLocalTempFilePWM(); 706 localTempFile = prof->getLocalTempFilePWM();
699 break; 707 break;
700 default: 708 default:
701 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 709 qDebug("KSyncManager::syncRemote: invalid apptype selected");
702 break; 710 break;
703 } 711 }
704 712
705 713
706 int fi; 714 int fi;
707 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 715 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
708 QString pwd = getPassword(); 716 QString pwd = getPassword();
709 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 717 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
710 718
711 } 719 }
712 int maxlen = 30; 720 int maxlen = 30;
713 if ( QApplication::desktop()->width() > 320 ) 721 if ( QApplication::desktop()->width() > 320 )
714 maxlen += 25; 722 maxlen += 25;
715 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 723 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
716 int fileSize = 0; 724 int fileSize = 0;
717 int result = system ( preCommand ); 725 int result = system ( preCommand );
718 // 0 : okay 726 // 0 : okay
719 // 256: no such file or dir 727 // 256: no such file or dir
720 // 728 //
721 qDebug("Sync: Remote copy result(0 = okay): %d ",result ); 729 qDebug("Sync: Remote copy result(0 = okay): %d ",result );
722 if ( result != 0 ) { 730 if ( result != 0 ) {
723 unsigned int len = maxlen; 731 unsigned int len = maxlen;
724 while ( len < preCommand.length() ) { 732 while ( len < preCommand.length() ) {
725 preCommand.insert( len , "\n" ); 733 preCommand.insert( len , "\n" );
726 len += maxlen +2; 734 len += maxlen +2;
727 } 735 }
728 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; 736 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ;
729 QMessageBox::information( mParent, i18n("Sync - ERROR"), 737 QMessageBox::information( mParent, i18n("Sync - ERROR"),
730 question, 738 question,
731 i18n("Okay!")) ; 739 i18n("Okay!")) ;
732 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 740 mParent->topLevelWidget()->setCaption ("KDE-Pim");
733 return; 741 return;
734 } 742 }
735 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 743 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
736 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 744 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
737 745
738 if ( syncWithFile( localTempFile, true ) ) { 746 if ( syncWithFile( localTempFile, true ) ) {
739 747
740 if ( mWriteBackFile ) { 748 if ( mWriteBackFile ) {
741 int fi; 749 int fi;
742 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 750 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
743 QString pwd = getPassword(); 751 QString pwd = getPassword();
744 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 752 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
745 753
746 } 754 }
747 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 755 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
748 result = system ( postCommand ); 756 result = system ( postCommand );
749 qDebug("Sync:Writing back file result: %d ", result); 757 qDebug("Sync:Writing back file result: %d ", result);
750 if ( result != 0 ) { 758 if ( result != 0 ) {
751 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 759 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
752 return; 760 return;
753 } else { 761 } else {
754 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 762 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
755 } 763 }
756 } 764 }
757 } 765 }
758 return; 766 return;
759} 767}
760bool KSyncManager::edit_pisync_options() 768bool KSyncManager::edit_pisync_options()
761{ 769{
762 QDialog dia( mParent, "dia", true ); 770 QDialog dia( mParent, "dia", true );
763 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 771 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
764 QVBoxLayout lay ( &dia ); 772 QVBoxLayout lay ( &dia );
765 lay.setSpacing( 5 ); 773 lay.setSpacing( 5 );
766 lay.setMargin( 3 ); 774 lay.setMargin( 3 );
767 QLabel lab1 ( i18n("Password for remote access:"), &dia); 775 QLabel lab1 ( i18n("Password for remote access:"), &dia);
768 lay.addWidget( &lab1 ); 776 lay.addWidget( &lab1 );
769 QLineEdit le1 (&dia ); 777 QLineEdit le1 (&dia );
770 lay.addWidget( &le1 ); 778 lay.addWidget( &le1 );
771 QLabel lab2 ( i18n("Remote IP address:"), &dia); 779 QLabel lab2 ( i18n("Remote IP address:"), &dia);
772 lay.addWidget( &lab2 ); 780 lay.addWidget( &lab2 );
773 QLineEdit le2 (&dia ); 781 QLineEdit le2 (&dia );
774 lay.addWidget( &le2 ); 782 lay.addWidget( &le2 );
775 QLabel lab3 ( i18n("Remote port number:"), &dia); 783 QLabel lab3 ( i18n("Remote port number:"), &dia);
776 lay.addWidget( &lab3 ); 784 lay.addWidget( &lab3 );
777 QLineEdit le3 (&dia ); 785 QLineEdit le3 (&dia );
778 lay.addWidget( &le3 ); 786 lay.addWidget( &le3 );
779 QPushButton pb ( "OK", &dia); 787 QPushButton pb ( "OK", &dia);
780 lay.addWidget( &pb ); 788 lay.addWidget( &pb );
781 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 789 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
782 le1.setText( mPassWordPiSync ); 790 le1.setText( mPassWordPiSync );
783 le2.setText( mActiveSyncIP ); 791 le2.setText( mActiveSyncIP );
784 le3.setText( mActiveSyncPort ); 792 le3.setText( mActiveSyncPort );
785 if ( dia.exec() ) { 793 if ( dia.exec() ) {
786 mPassWordPiSync = le1.text(); 794 mPassWordPiSync = le1.text();
787 mActiveSyncPort = le3.text(); 795 mActiveSyncPort = le3.text();
788 mActiveSyncIP = le2.text(); 796 mActiveSyncIP = le2.text();
789 return true; 797 return true;
790 } 798 }
791 return false; 799 return false;
792} 800}
793bool KSyncManager::edit_sync_options() 801bool KSyncManager::edit_sync_options()
794{ 802{
795 803
796 QDialog dia( mParent, "dia", true ); 804 QDialog dia( mParent, "dia", true );
797 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 805 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
798 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 806 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
799 QVBoxLayout lay ( &dia ); 807 QVBoxLayout lay ( &dia );
800 lay.setSpacing( 2 ); 808 lay.setSpacing( 2 );
801 lay.setMargin( 3 ); 809 lay.setMargin( 3 );
802 lay.addWidget(&gr); 810 lay.addWidget(&gr);
803 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 811 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
804 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 812 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
805 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 813 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
806 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 814 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
807 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 815 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
808 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 816 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
809 //QRadioButton both( i18n("Take both on conflict"), &gr ); 817 //QRadioButton both( i18n("Take both on conflict"), &gr );
810 QPushButton pb ( "OK", &dia); 818 QPushButton pb ( "OK", &dia);
811 lay.addWidget( &pb ); 819 lay.addWidget( &pb );
812 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 820 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
813 switch ( mSyncAlgoPrefs ) { 821 switch ( mSyncAlgoPrefs ) {
814 case 0: 822 case 0:
815 loc.setChecked( true); 823 loc.setChecked( true);
816 break; 824 break;
817 case 1: 825 case 1:
818 rem.setChecked( true ); 826 rem.setChecked( true );
819 break; 827 break;
820 case 2: 828 case 2:
821 newest.setChecked( true); 829 newest.setChecked( true);
822 break; 830 break;
823 case 3: 831 case 3:
824 ask.setChecked( true); 832 ask.setChecked( true);
825 break; 833 break;
826 case 4: 834 case 4:
827 f_loc.setChecked( true); 835 f_loc.setChecked( true);
828 break; 836 break;
829 case 5: 837 case 5:
830 f_rem.setChecked( true); 838 f_rem.setChecked( true);
831 break; 839 break;
832 case 6: 840 case 6:
833 // both.setChecked( true); 841 // both.setChecked( true);
834 break; 842 break;
835 default: 843 default:
836 break; 844 break;
837 } 845 }
838 if ( dia.exec() ) { 846 if ( dia.exec() ) {
839 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 847 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
840 return true; 848 return true;
841 } 849 }
842 return false; 850 return false;
843} 851}
844 852
845QString KSyncManager::getPassword( ) 853QString KSyncManager::getPassword( )
846{ 854{
847 QString retfile = ""; 855 QString retfile = "";
848 QDialog dia ( mParent, "input-dialog", true ); 856 QDialog dia ( mParent, "input-dialog", true );
849 QLineEdit lab ( &dia ); 857 QLineEdit lab ( &dia );
850 lab.setEchoMode( QLineEdit::Password ); 858 lab.setEchoMode( QLineEdit::Password );
851 QVBoxLayout lay( &dia ); 859 QVBoxLayout lay( &dia );
852 lay.setMargin(7); 860 lay.setMargin(7);
853 lay.setSpacing(7); 861 lay.setSpacing(7);
854 lay.addWidget( &lab); 862 lay.addWidget( &lab);
855 dia.setFixedSize( 230,50 ); 863 dia.setFixedSize( 230,50 );
856 dia.setCaption( i18n("Enter password") ); 864 dia.setCaption( i18n("Enter password") );
857 QPushButton pb ( "OK", &dia); 865 QPushButton pb ( "OK", &dia);
858 lay.addWidget( &pb ); 866 lay.addWidget( &pb );
859 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 867 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
860 dia.show(); 868 dia.show();
861 int res = dia.exec(); 869 int res = dia.exec();
862 if ( res ) 870 if ( res )
863 retfile = lab.text(); 871 retfile = lab.text();
864 dia.hide(); 872 dia.hide();
865 qApp->processEvents(); 873 qApp->processEvents();
866 return retfile; 874 return retfile;
867 875
868} 876}
869 877
870 878
871void KSyncManager::confSync() 879void KSyncManager::confSync()
872{ 880{
873 static KSyncPrefsDialog* sp = 0; 881 static KSyncPrefsDialog* sp = 0;
874 if ( ! sp ) { 882 if ( ! sp ) {
875 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 883 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
876 } 884 }
877 sp->usrReadConfig(); 885 sp->usrReadConfig();
878#ifndef DESKTOP_VERSION 886#ifndef DESKTOP_VERSION
879 sp->showMaximized(); 887 sp->showMaximized();
880#else 888#else
881 sp->show(); 889 sp->show();
882#endif 890#endif
883 sp->exec(); 891 sp->exec();
884 QStringList oldSyncProfileNames = mSyncProfileNames; 892 QStringList oldSyncProfileNames = mSyncProfileNames;
885 mSyncProfileNames = sp->getSyncProfileNames(); 893 mSyncProfileNames = sp->getSyncProfileNames();
886 mLocalMachineName = sp->getLocalMachineName (); 894 mLocalMachineName = sp->getLocalMachineName ();
887 int ii; 895 int ii;
888 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { 896 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
889 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) 897 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
890 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); 898 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
891 } 899 }
892 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 900 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
893} 901}
894void KSyncManager::syncKDE() 902void KSyncManager::syncKDE()
895{ 903{
896 mSyncWithDesktop = true; 904 mSyncWithDesktop = true;
897 emit save(); 905 emit save();
898 switch(mTargetApp) 906 switch(mTargetApp)
899 { 907 {
900 case (KAPI): 908 case (KAPI):
901 { 909 {
902#ifdef DESKTOP_VERSION 910#ifdef DESKTOP_VERSION
903 QString command = qApp->applicationDirPath () + "/kdeabdump"; 911 QString command = qApp->applicationDirPath () + "/kdeabdump";
904#else 912#else
905 QString command = "kdeabdump"; 913 QString command = "kdeabdump";
906#endif 914#endif
907 if ( ! QFile::exists ( command ) ) 915 if ( ! QFile::exists ( command ) )
908 command = "kdeabdump"; 916 command = "kdeabdump";
909 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; 917 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
910 system ( command.latin1()); 918 system ( command.latin1());
911 if ( syncWithFile( fileName,true ) ) { 919 if ( syncWithFile( fileName,true ) ) {
912 if ( mWriteBackFile ) { 920 if ( mWriteBackFile ) {
913 command += " --read"; 921 command += " --read";
914 system ( command.latin1()); 922 system ( command.latin1());
915 } 923 }
916 } 924 }
917 925
918 } 926 }
919 break; 927 break;
920 case (KOPI): 928 case (KOPI):
921 { 929 {
922#ifdef DESKTOP_VERSION 930#ifdef DESKTOP_VERSION
923 QString command = qApp->applicationDirPath () + "/kdecaldump"; 931 QString command = qApp->applicationDirPath () + "/kdecaldump";
924#else 932#else
925 QString command = "kdecaldump"; 933 QString command = "kdecaldump";
926#endif 934#endif
927 if ( ! QFile::exists ( command ) ) 935 if ( ! QFile::exists ( command ) )
928 command = "kdecaldump"; 936 command = "kdecaldump";
929 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 937 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
930 system ( command.latin1()); 938 system ( command.latin1());
931 if ( syncWithFile( fileName,true ) ) { 939 if ( syncWithFile( fileName,true ) ) {
932 if ( mWriteBackFile ) { 940 if ( mWriteBackFile ) {
933 command += " --read"; 941 command += " --read";
934 system ( command.latin1()); 942 system ( command.latin1());
935 } 943 }
936 } 944 }
937 945
938 } 946 }
939 break; 947 break;
940 case (PWMPI): 948 case (PWMPI):
941 949
942 break; 950 break;
943 default: 951 default:
944 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 952 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
945 break; 953 break;
946 954
947 } 955 }
948} 956}
949 957
950void KSyncManager::syncSharp() 958void KSyncManager::syncSharp()
951{ 959{
952 960
953 if ( ! syncExternalApplication("sharp") ) 961 if ( ! syncExternalApplication("sharp") )
954 qDebug("ERROR sync sharp "); 962 qDebug("ERROR sync sharp ");
955} 963}
956 964
957bool KSyncManager::syncExternalApplication(QString resource) 965bool KSyncManager::syncExternalApplication(QString resource)
958{ 966{
959 967
960 emit save(); 968 emit save();
961 969
962 if ( mAskForPreferences ) 970 if ( mAskForPreferences )
963 if ( !edit_sync_options()) { 971 if ( !edit_sync_options()) {
964 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 972 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
965 return false; 973 return false;
966 } 974 }
967 975
968 qDebug("Sync extern %s", resource.latin1()); 976 qDebug("Sync extern %s", resource.latin1());
969 977
970 bool syncOK = mImplementation->syncExternal(this, resource); 978 bool syncOK = mImplementation->syncExternal(this, resource);
971 979
972 return syncOK; 980 return syncOK;
973 981
974} 982}
975 983
976void KSyncManager::syncPhone() 984void KSyncManager::syncPhone()
977{ 985{
978 986
979 syncExternalApplication("phone"); 987 syncExternalApplication("phone");
980 988
981} 989}
982 990
983void KSyncManager::showProgressBar(int percentage, QString caption, int total) 991void KSyncManager::showProgressBar(int percentage, QString caption, int total)
984{ 992{
985 if (!bar->isVisible()) 993 if (!bar->isVisible())
986 { 994 {
987 bar->setCaption (caption); 995 bar->setCaption (caption);
988 bar->setTotalSteps ( total ) ; 996 bar->setTotalSteps ( total ) ;
989 997
990 bar->show(); 998 bar->show();
991 } 999 }
992 1000
993 bar->setProgress( percentage ); 1001 bar->setProgress( percentage );
994} 1002}
995 1003
996void KSyncManager::hideProgressBar() 1004void KSyncManager::hideProgressBar()
997{ 1005{
998 bar->hide(); 1006 bar->hide();
999} 1007}
1000 1008
1001bool KSyncManager::isProgressBarCanceled() 1009bool KSyncManager::isProgressBarCanceled()
1002{ 1010{
1003 return !bar->isVisible(); 1011 return !bar->isVisible();
1004} 1012}
1005 1013
1006QString KSyncManager::syncFileName() 1014QString KSyncManager::syncFileName()
1007{ 1015{
1008 1016
1009 QString fn = "tempfile"; 1017 QString fn = "tempfile";
1010 switch(mTargetApp) 1018 switch(mTargetApp)
1011 { 1019 {
1012 case (KAPI): 1020 case (KAPI):
1013 fn = "tempsyncab.vcf"; 1021 fn = "tempsyncab.vcf";
1014 break; 1022 break;
1015 case (KOPI): 1023 case (KOPI):
1016 fn = "tempsynccal.ics"; 1024 fn = "tempsynccal.ics";
1017 break; 1025 break;
1018 case (PWMPI): 1026 case (PWMPI):
1019 fn = "tempsyncpw.pwm"; 1027 fn = "tempsyncpw.pwm";
1020 break; 1028 break;
1021 default: 1029 default:
1022 break; 1030 break;
1023 } 1031 }
1024#ifdef _WIN32_ 1032#ifdef _WIN32_
1025 return locateLocal( "tmp", fn ); 1033 return locateLocal( "tmp", fn );
1026#else 1034#else
1027 return (QString( "/tmp/" )+ fn ); 1035 return (QString( "/tmp/" )+ fn );
1028#endif 1036#endif
1029} 1037}
1030 1038
1031void KSyncManager::syncPi() 1039void KSyncManager::syncPi()
1032{ 1040{
1033 mIsKapiFile = true; 1041 mIsKapiFile = true;
1034 mPisyncFinished = false; 1042 mPisyncFinished = false;
1035 qApp->processEvents(); 1043 qApp->processEvents();
1036 if ( mAskForPreferences ) 1044 if ( mAskForPreferences )
1037 if ( !edit_pisync_options()) { 1045 if ( !edit_pisync_options()) {
1038 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1046 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1039 return; 1047 return;
1040 } 1048 }
1041 bool ok; 1049 bool ok;
1042 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1050 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1043 if ( ! ok ) { 1051 if ( ! ok ) {
1044 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1052 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1045 return; 1053 return;
1046 } 1054 }
1047 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 1055 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
1048 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1056 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1049 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 1057 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
1050 commandSocket->readFile( syncFileName() ); 1058 commandSocket->readFile( syncFileName() );
1051} 1059}
1052 1060
1053void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1061void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1054{ 1062{
1055 //enum { success, errorW, errorR, quiet }; 1063 //enum { success, errorW, errorR, quiet };
1056 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1064 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1057 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1065 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1058 delete s; 1066 delete s;
1059 if ( state == KCommandSocket::errorR ) { 1067 if ( state == KCommandSocket::errorR ) {
1060 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1068 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1061 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1069 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1062 commandSocket->sendStop(); 1070 commandSocket->sendStop();
1063 } 1071 }
1064 mPisyncFinished = true; 1072 mPisyncFinished = true;
1065 return; 1073 return;
1066 1074
1067 } else if ( state == KCommandSocket::errorW ) { 1075 } else if ( state == KCommandSocket::errorW ) {
1068 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1076 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1069 mPisyncFinished = true; 1077 mPisyncFinished = true;
1070 1078
1071 } else if ( state == KCommandSocket::successR ) { 1079 } else if ( state == KCommandSocket::successR ) {
1072 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1080 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1073 1081
1074 } else if ( state == KCommandSocket::successW ) { 1082 } else if ( state == KCommandSocket::successW ) {
1075 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1083 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1076 mPisyncFinished = true; 1084 mPisyncFinished = true;
1077 } 1085 }
1078 1086
1079 delete s; 1087 delete s;
1080} 1088}
1081 1089
1082void KSyncManager::readFileFromSocket() 1090void KSyncManager::readFileFromSocket()
1083{ 1091{
1084 QString fileName = syncFileName(); 1092 QString fileName = syncFileName();
1085 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1093 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1086 if ( ! syncWithFile( fileName , true ) ) { 1094 if ( ! syncWithFile( fileName , true ) ) {
1087 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1095 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1088 mPisyncFinished = true; 1096 mPisyncFinished = true;
1089 return; 1097 return;
1090 } 1098 }
1091 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1099 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1092 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1100 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1093 if ( mWriteBackFile ) 1101 if ( mWriteBackFile )
1094 commandSocket->writeFile( fileName ); 1102 commandSocket->writeFile( fileName );
1095 else { 1103 else {
1096 commandSocket->sendStop(); 1104 commandSocket->sendStop();
1097 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1105 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1098 mPisyncFinished = true; 1106 mPisyncFinished = true;
1099 } 1107 }
1100} 1108}
1101 1109
1102KServerSocket:: 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 )
1103{ 1111{
1104 mPassWord = pw; 1112 mPassWord = pw;
1105 mSocket = 0; 1113 mSocket = 0;
1106 mSyncActionDialog = 0; 1114 mSyncActionDialog = 0;
1107 blockRC = false; 1115 blockRC = false;
1108}; 1116};
1109 1117
1110void KServerSocket::newConnection ( int socket ) 1118void KServerSocket::newConnection ( int socket )
1111{ 1119{
1112 // qDebug("KServerSocket:New connection %d ", socket); 1120 // qDebug("KServerSocket:New connection %d ", socket);
1113 if ( mSocket ) { 1121 if ( mSocket ) {
1114 qDebug("KServerSocket::newConnection Socket deleted! "); 1122 qDebug("KServerSocket::newConnection Socket deleted! ");
1115 delete mSocket; 1123 delete mSocket;
1116 mSocket = 0; 1124 mSocket = 0;
1117 } 1125 }
1118 mSocket = new QSocket( this ); 1126 mSocket = new QSocket( this );
1119 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1127 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1120 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1128 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1121 mSocket->setSocket( socket ); 1129 mSocket->setSocket( socket );
1122} 1130}
1123 1131
1124void KServerSocket::discardClient() 1132void KServerSocket::discardClient()
1125{ 1133{
1126 //qDebug(" KServerSocket::discardClient()"); 1134 //qDebug(" KServerSocket::discardClient()");
1127 if ( mSocket ) { 1135 if ( mSocket ) {
1128 delete mSocket; 1136 delete mSocket;
1129 mSocket = 0; 1137 mSocket = 0;
1130 } 1138 }
1131 //emit endConnect(); 1139 //emit endConnect();
1132} 1140}
1133void KServerSocket::readClient() 1141void KServerSocket::readClient()
1134{ 1142{
1135 if ( blockRC ) 1143 if ( blockRC )
1136 return; 1144 return;
1137 if ( mSocket == 0 ) { 1145 if ( mSocket == 0 ) {
1138 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 1146 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
1139 return; 1147 return;
1140 } 1148 }
1141 //qDebug("KServerSocket::readClient()"); 1149 //qDebug("KServerSocket::readClient()");
1142 if ( mSocket->canReadLine() ) { 1150 if ( mSocket->canReadLine() ) {
1143 QString line = mSocket->readLine(); 1151 QString line = mSocket->readLine();
1144 //qDebug("KServerSocket readline: %s ", line.latin1()); 1152 //qDebug("KServerSocket readline: %s ", line.latin1());
1145 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1153 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1146 if ( tokens[0] == "GET" ) { 1154 if ( tokens[0] == "GET" ) {
1147 if ( tokens[1] == mPassWord ) { 1155 if ( tokens[1] == mPassWord ) {
1148 //emit sendFile( mSocket ); 1156 //emit sendFile( mSocket );
1149 bool ok = false; 1157 bool ok = false;
1150 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1158 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1151 if ( ok ) { 1159 if ( ok ) {
1152 KSyncManager::mRequestedSyncEvent = dt; 1160 KSyncManager::mRequestedSyncEvent = dt;
1153 } 1161 }
1154 else 1162 else
1155 KSyncManager::mRequestedSyncEvent = QDateTime(); 1163 KSyncManager::mRequestedSyncEvent = QDateTime();
1156 send_file(); 1164 send_file();
1157 } 1165 }
1158 else { 1166 else {
1159 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1167 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1160 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1168 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1161 } 1169 }
1162 } 1170 }
1163 if ( tokens[0] == "PUT" ) { 1171 if ( tokens[0] == "PUT" ) {
1164 if ( tokens[1] == mPassWord ) { 1172 if ( tokens[1] == mPassWord ) {
1165 //emit getFile( mSocket ); 1173 //emit getFile( mSocket );
1166 blockRC = true; 1174 blockRC = true;
1167 get_file(); 1175 get_file();
1168 } 1176 }
1169 else { 1177 else {
1170 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1178 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1171 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1179 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1172 } 1180 }
1173 } 1181 }
1174 if ( tokens[0] == "STOP" ) { 1182 if ( tokens[0] == "STOP" ) {
1175 //emit endConnect(); 1183 //emit endConnect();
1176 end_connect(); 1184 end_connect();
1177 } 1185 }
1178 } 1186 }
1179} 1187}
1180void KServerSocket::end_connect() 1188void KServerSocket::end_connect()
1181{ 1189{
1182 delete mSyncActionDialog; 1190 delete mSyncActionDialog;
1183 mSyncActionDialog = 0; 1191 mSyncActionDialog = 0;
1184} 1192}
1185void KServerSocket::send_file() 1193void KServerSocket::send_file()
1186{ 1194{
1187 //qDebug("MainWindow::sendFile(QSocket* s) "); 1195 //qDebug("MainWindow::sendFile(QSocket* s) ");
1188 if ( mSyncActionDialog ) 1196 if ( mSyncActionDialog )
1189 delete mSyncActionDialog; 1197 delete mSyncActionDialog;
1190 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1198 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1191 mSyncActionDialog->setCaption(i18n("Received sync request")); 1199 mSyncActionDialog->setCaption(i18n("Received sync request"));
1192 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 );
1193 label->setAlignment ( Qt::AlignHCenter ); 1201 label->setAlignment ( Qt::AlignHCenter );
1194 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1202 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1195 lay->addWidget( label); 1203 lay->addWidget( label);
1196 lay->setMargin(7); 1204 lay->setMargin(7);
1197 lay->setSpacing(7); 1205 lay->setSpacing(7);
1198 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1206 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1199 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1207 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1200 if ( secs < 0 ) 1208 if ( secs < 0 )
1201 secs = secs * (-1); 1209 secs = secs * (-1);
1202 if ( secs > 30 ) 1210 if ( secs > 30 )
1203 //if ( true ) 1211 //if ( true )
1204 { 1212 {
1205 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 );
1206 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1214 QLabel* label = new QLabel( warning, mSyncActionDialog );
1207 label->setAlignment ( Qt::AlignHCenter ); 1215 label->setAlignment ( Qt::AlignHCenter );
1208 lay->addWidget( label); 1216 lay->addWidget( label);
1209 if ( secs > 180 ) 1217 if ( secs > 180 )
1210 { 1218 {
1211 if ( secs > 300 ) { 1219 if ( secs > 300 ) {
1212 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!"))) {
1213 qDebug("cancelled "); 1221 qDebug("cancelled ");
1214 return ; 1222 return ;
1215 } 1223 }
1216 } 1224 }
1217 QFont f = label->font(); 1225 QFont f = label->font();
1218 f.setPointSize ( f.pointSize() *2 ); 1226 f.setPointSize ( f.pointSize() *2 );
1219 f. setBold (true ); 1227 f. setBold (true );
1220 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1228 QLabel* label = new QLabel( warning, mSyncActionDialog );
1221 label->setFont( f ); 1229 label->setFont( f );
1222 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1230 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1223 label->setText( warning ); 1231 label->setText( warning );
1224 label->setAlignment ( Qt::AlignHCenter ); 1232 label->setAlignment ( Qt::AlignHCenter );
1225 lay->addWidget( label); 1233 lay->addWidget( label);
1226 mSyncActionDialog->setFixedSize( 230, 300); 1234 mSyncActionDialog->setFixedSize( 230, 300);
1227 } else { 1235 } else {
1228 mSyncActionDialog->setFixedSize( 230, 200); 1236 mSyncActionDialog->setFixedSize( 230, 200);
1229 } 1237 }
1230 } else { 1238 } else {
1231 mSyncActionDialog->setFixedSize( 230, 120); 1239 mSyncActionDialog->setFixedSize( 230, 120);
1232 } 1240 }
1233 } else 1241 } else
1234 mSyncActionDialog->setFixedSize( 230, 120); 1242 mSyncActionDialog->setFixedSize( 230, 120);
1235 mSyncActionDialog->show(); 1243 mSyncActionDialog->show();
1236 mSyncActionDialog->raise(); 1244 mSyncActionDialog->raise();
1237 emit request_file(); 1245 emit request_file();
1238 qApp->processEvents(); 1246 qApp->processEvents();
1239 QString fileName = mFileName; 1247 QString fileName = mFileName;
1240 QFile file( fileName ); 1248 QFile file( fileName );
1241 if (!file.open( IO_ReadOnly ) ) { 1249 if (!file.open( IO_ReadOnly ) ) {
1242 delete mSyncActionDialog; 1250 delete mSyncActionDialog;
1243 mSyncActionDialog = 0; 1251 mSyncActionDialog = 0;
1244 qDebug("KSS::error open sync file: %s ", fileName.latin1()); 1252 qDebug("KSS::error open sync file: %s ", fileName.latin1());
1245 mSocket->close(); 1253 mSocket->close();
1246 if ( mSocket->state() == QSocket::Idle ) 1254 if ( mSocket->state() == QSocket::Idle )
1247 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1255 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1248 return ; 1256 return ;
1249 1257
1250 } 1258 }
1251 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1259 mSyncActionDialog->setCaption( i18n("Sending file...") );
1252 QTextStream ts( &file ); 1260 QTextStream ts( &file );
1253 ts.setEncoding( QTextStream::Latin1 ); 1261 ts.setEncoding( QTextStream::Latin1 );
1254 1262
1255 QTextStream os( mSocket ); 1263 QTextStream os( mSocket );
1256 os.setEncoding( QTextStream::Latin1 ); 1264 os.setEncoding( QTextStream::Latin1 );
1257 while ( ! ts.atEnd() ) { 1265 while ( ! ts.atEnd() ) {
1258 os << ts.readLine() << "\r\n"; 1266 os << ts.readLine() << "\r\n";
1259 } 1267 }
1260 //os << ts.read(); 1268 //os << ts.read();
1261 file.close(); 1269 file.close();
1262 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1270 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1263 mSocket->close(); 1271 mSocket->close();
1264 if ( mSocket->state() == QSocket::Idle ) 1272 if ( mSocket->state() == QSocket::Idle )
1265 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1273 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1266} 1274}
1267void KServerSocket::get_file() 1275void KServerSocket::get_file()
1268{ 1276{
1269 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1277 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1270 1278
1271 piTime.start(); 1279 piTime.start();
1272 piFileString = ""; 1280 piFileString = "";
1273 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1281 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1274} 1282}
1275 1283
1276 1284
1277void KServerSocket::readBackFileFromSocket() 1285void KServerSocket::readBackFileFromSocket()
1278{ 1286{
1279 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1287 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1280 while ( mSocket->canReadLine () ) { 1288 while ( mSocket->canReadLine () ) {
1281 piTime.restart(); 1289 piTime.restart();
1282 QString line = mSocket->readLine (); 1290 QString line = mSocket->readLine ();
1283 piFileString += line; 1291 piFileString += line;
1284 //qDebug("readline: %s ", line.latin1()); 1292 //qDebug("readline: %s ", line.latin1());
1285 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1293 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1286 1294
1287 } 1295 }
1288 if ( piTime.elapsed () < 3000 ) { 1296 if ( piTime.elapsed () < 3000 ) {
1289 // wait for more 1297 // wait for more
1290 //qDebug("waitformore "); 1298 //qDebug("waitformore ");
1291 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1299 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1292 return; 1300 return;
1293 } 1301 }
1294 QString fileName = mFileName; 1302 QString fileName = mFileName;
1295 QFile file ( fileName ); 1303 QFile file ( fileName );
1296 if (!file.open( IO_WriteOnly ) ) { 1304 if (!file.open( IO_WriteOnly ) ) {
1297 delete mSyncActionDialog; 1305 delete mSyncActionDialog;
1298 mSyncActionDialog = 0; 1306 mSyncActionDialog = 0;
1299 qDebug("KSS:Error open read back file "); 1307 qDebug("KSS:Error open read back file ");
1300 piFileString = ""; 1308 piFileString = "";
1301 emit file_received( false ); 1309 emit file_received( false );
1302 blockRC = false; 1310 blockRC = false;
1303 return ; 1311 return ;
1304 1312
1305 } 1313 }
1306 1314
1307 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1315 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1308 QTextStream ts ( &file ); 1316 QTextStream ts ( &file );
1309 ts.setEncoding( QTextStream::Latin1 ); 1317 ts.setEncoding( QTextStream::Latin1 );
1310 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1318 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1311 ts << piFileString; 1319 ts << piFileString;
1312 mSocket->close(); 1320 mSocket->close();
1313 if ( mSocket->state() == QSocket::Idle ) 1321 if ( mSocket->state() == QSocket::Idle )
1314 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1322 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1315 file.close(); 1323 file.close();
1316 piFileString = ""; 1324 piFileString = "";
1317 emit file_received( true ); 1325 emit file_received( true );
1318 delete mSyncActionDialog; 1326 delete mSyncActionDialog;
1319 mSyncActionDialog = 0; 1327 mSyncActionDialog = 0;
1320 blockRC = false; 1328 blockRC = false;
1321 1329
1322} 1330}
1323 1331
1324KCommandSocket::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 )
1325{ 1333{
1326 mPassWord = password; 1334 mPassWord = password;
1327 mSocket = 0; 1335 mSocket = 0;
1328 mPort = port; 1336 mPort = port;
1329 mHost = host; 1337 mHost = host;
1330 1338
1331 mRetVal = quiet; 1339 mRetVal = quiet;
1332 mTimerSocket = new QTimer ( this ); 1340 mTimerSocket = new QTimer ( this );
1333 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1341 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1334} 1342}
1335void KCommandSocket::readFile( QString fn ) 1343void KCommandSocket::readFile( QString fn )
1336{ 1344{
1337 if ( !mSocket ) { 1345 if ( !mSocket ) {
1338 mSocket = new QSocket( this ); 1346 mSocket = new QSocket( this );
1339 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1347 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1340 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1348 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1341 } 1349 }
1342 mFileString = ""; 1350 mFileString = "";
1343 mFileName = fn; 1351 mFileName = fn;
1344 mFirst = true; 1352 mFirst = true;
1345 mSocket->connectToHost( mHost, mPort ); 1353 mSocket->connectToHost( mHost, mPort );
1346 QTextStream os( mSocket ); 1354 QTextStream os( mSocket );
1347 os.setEncoding( QTextStream::Latin1 ); 1355 os.setEncoding( QTextStream::Latin1 );
1348 1356
1349 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 );
1350 os << "GET " << mPassWord << curDt <<"\r\n"; 1358 os << "GET " << mPassWord << curDt <<"\r\n";
1351 mTimerSocket->start( 300000 ); 1359 mTimerSocket->start( 300000 );
1352} 1360}
1353 1361
1354void KCommandSocket::writeFile( QString fileName ) 1362void KCommandSocket::writeFile( QString fileName )