summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index a64eb34..719d80b 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,828 +1,831 @@
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#include <qapplication.h> 52#include <qapplication.h>
53 53
54#include <klocale.h> 54#include <klocale.h>
55#include <kglobal.h> 55#include <kglobal.h>
56#include <kconfig.h> 56#include <kconfig.h>
57#include <kfiledialog.h> 57#include <kfiledialog.h>
58 58
59QDateTime KSyncManager::mRequestedSyncEvent; 59QDateTime KSyncManager::mRequestedSyncEvent;
60 60
61 61
62KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 62KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
63 : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) 63 : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu)
64{ 64{
65 mServerSocket = 0; 65 mServerSocket = 0;
66 bar = new QProgressBar ( 1, 0 ); 66 bar = new QProgressBar ( 1, 0 );
67 bar->setCaption (""); 67 bar->setCaption ("");
68 mWriteBackInPast = 2; 68 mWriteBackInPast = 2;
69 69
70 70
71} 71}
72 72
73KSyncManager::~KSyncManager() 73KSyncManager::~KSyncManager()
74{ 74{
75 delete bar; 75 delete bar;
76} 76}
77 77
78void KSyncManager::setDefaultFileName( QString s) 78void KSyncManager::setDefaultFileName( QString s)
79{ 79{
80 mDefFileName = s ; 80 mDefFileName = s ;
81 if ( mPrefs->mPassiveSyncAutoStart ) 81 if ( mPrefs->mPassiveSyncAutoStart )
82 enableQuick( false ); 82 enableQuick( false );
83} 83}
84 84
85void KSyncManager::fillSyncMenu() 85void KSyncManager::fillSyncMenu()
86{ 86{
87 if ( mSyncMenu->count() ) 87 if ( mSyncMenu->count() )
88 mSyncMenu->clear(); 88 mSyncMenu->clear();
89 89
90 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 90 mSyncMenu->insertItem( i18n("Configure..."), 0 );
91 mSyncMenu->insertSeparator(); 91 mSyncMenu->insertSeparator();
92 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 92 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
93 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 93 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
94 clearMenu->insertItem( i18n("For all profiles"), 1 ); 94 clearMenu->insertItem( i18n("For all profiles"), 1 );
95 clearMenu->insertSeparator(); 95 clearMenu->insertSeparator();
96 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 96 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
97 mSyncMenu->insertSeparator(); 97 mSyncMenu->insertSeparator();
98 if ( mServerSocket == 0 ) { 98 if ( mServerSocket == 0 ) {
99 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 99 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
100 } else { 100 } else {
101 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 101 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
102 } 102 }
103 mSyncMenu->insertSeparator(); 103 mSyncMenu->insertSeparator();
104 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 104 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
105 mSyncMenu->insertSeparator(); 105 mSyncMenu->insertSeparator();
106 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 106 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
107 config.setGroup("General"); 107 config.setGroup("General");
108 QStringList prof = config.readListEntry("SyncProfileNames"); 108 QStringList prof = config.readListEntry("SyncProfileNames");
109 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 109 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
110 if ( prof.count() < 2 ) { 110 if ( prof.count() < 2 ) {
111 prof.clear(); 111 prof.clear();
112 QString externalName; 112 QString externalName;
113#ifdef DESKTOP_VERSION 113#ifdef DESKTOP_VERSION
114#ifdef _WIN32_ 114#ifdef _WIN32_
115 externalName = "OutLook(not_implemented)"; 115 externalName = "OutLook(not_implemented)";
116#else 116#else
117 externalName = "KDE_Desktop"; 117 externalName = "KDE_Desktop";
118#endif 118#endif
119#else 119#else
120 externalName = "Sharp_DTM"; 120 externalName = "Sharp_DTM";
121#endif 121#endif
122 prof << externalName; 122 prof << externalName;
123 prof << i18n("Local_file"); 123 prof << i18n("Local_file");
124 prof << i18n("Last_file"); 124 prof << i18n("Last_file");
125 KSyncProfile* temp = new KSyncProfile (); 125 KSyncProfile* temp = new KSyncProfile ();
126 temp->setName( prof[0] ); 126 temp->setName( prof[0] );
127 temp->writeConfig(&config); 127 temp->writeConfig(&config);
128 temp->setName( prof[1] ); 128 temp->setName( prof[1] );
129 temp->writeConfig(&config); 129 temp->writeConfig(&config);
130 temp->setName( prof[2] ); 130 temp->setName( prof[2] );
131 temp->writeConfig(&config); 131 temp->writeConfig(&config);
132 config.setGroup("General"); 132 config.setGroup("General");
133 config.writeEntry("SyncProfileNames",prof); 133 config.writeEntry("SyncProfileNames",prof);
134 config.writeEntry("ExternSyncProfiles",externalName); 134 config.writeEntry("ExternSyncProfiles",externalName);
135 config.sync(); 135 config.sync();
136 delete temp; 136 delete temp;
137 } 137 }
138 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 138 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
139 mSyncProfileNames = prof; 139 mSyncProfileNames = prof;
140 unsigned int i; 140 unsigned int i;
141 for ( i = 0; i < prof.count(); ++i ) { 141 for ( i = 0; i < prof.count(); ++i ) {
142 QString insertText = prof[i]; 142 QString insertText = prof[i];
143 if ( i == 0 ) { 143 if ( i == 0 ) {
144#ifdef DESKTOP_VERSION 144#ifdef DESKTOP_VERSION
145#ifdef _WIN32_ 145#ifdef _WIN32_
146 insertText = "OutLook(not_implemented)"; 146 insertText = "OutLook(not_implemented)";
147#else 147#else
148 insertText = "KDE_Desktop"; 148 insertText = "KDE_Desktop";
149#endif 149#endif
150#else 150#else
151 insertText = "Sharp_DTM"; 151 insertText = "Sharp_DTM";
152#endif 152#endif
153 } 153 }
154 mSyncMenu->insertItem( insertText, 1000+i ); 154 mSyncMenu->insertItem( insertText, 1000+i );
155 clearMenu->insertItem( insertText, 1000+i ); 155 clearMenu->insertItem( insertText, 1000+i );
156 if ( i == 2 ) 156 if ( i == 2 )
157 mSyncMenu->insertSeparator(); 157 mSyncMenu->insertSeparator();
158 } 158 }
159 QDir app_dir; 159 QDir app_dir;
160 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 160 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
161 if ( mTargetApp == PWMPI) { 161 if ( mTargetApp == PWMPI) {
162 mSyncMenu->removeItem( 1000 ); 162 mSyncMenu->removeItem( 1000 );
163 clearMenu->removeItem( 1000 ); 163 clearMenu->removeItem( 1000 );
164 } 164 }
165#ifndef DESKTOP_VERSION 165#ifndef DESKTOP_VERSION
166 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 166 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
167 mSyncMenu->removeItem( 1000 ); 167 mSyncMenu->removeItem( 1000 );
168 clearMenu->removeItem( 1000 ); 168 clearMenu->removeItem( 1000 );
169 } 169 }
170#endif 170#endif
171 mSyncMenu->removeItem( 1002 ); 171 mSyncMenu->removeItem( 1002 );
172 clearMenu->removeItem( 1002 ); 172 clearMenu->removeItem( 1002 );
173} 173}
174void KSyncManager::slotClearMenu( int action ) 174void KSyncManager::slotClearMenu( int action )
175{ 175{
176 QString syncDevice; 176 QString syncDevice;
177 if ( action > 999 ) { 177 if ( action > 999 ) {
178 syncDevice = mSyncProfileNames[action - 1000] ; 178 syncDevice = mSyncProfileNames[action - 1000] ;
179 } 179 }
180 180
181 181
182 182
183 int result = 0; 183 int result = 0;
184 QString sd; 184 QString sd;
185 if ( syncDevice.isEmpty() ) 185 if ( syncDevice.isEmpty() )
186 sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); 186 sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
187 else 187 else
188 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); 188 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
189 189
190 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, 190 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
191 0, 1 ); 191 0, 1 );
192 if ( result ) 192 if ( result )
193 return; 193 return;
194 mImplementation->removeSyncInfo( syncDevice ); 194 mImplementation->removeSyncInfo( syncDevice );
195} 195}
196void KSyncManager::slotSyncMenu( int action ) 196void KSyncManager::slotSyncMenu( int action )
197{ 197{
198 qDebug("KSM::syncaction %d ", action); 198 qDebug("KSM::syncaction %d ", action);
199 mCurrentResourceLocal = ""; 199 mCurrentResourceLocal = "";
200 emit multiResourceSyncStart( false );
200 if ( action == 5000 ) 201 if ( action == 5000 )
201 return; 202 return;
202 mSyncWithDesktop = false; 203 mSyncWithDesktop = false;
203 if ( action == 0 ) { 204 if ( action == 0 ) {
204 205
205 // seems to be a Qt2 event handling bug 206 // seems to be a Qt2 event handling bug
206 // syncmenu.clear causes a segfault at first time 207 // syncmenu.clear causes a segfault at first time
207 // when we call it after the main event loop, it is ok 208 // when we call it after the main event loop, it is ok
208 // same behaviour when calling OM/Pi via QCOP for the first time 209 // same behaviour when calling OM/Pi via QCOP for the first time
209 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 210 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
210 //confSync(); 211 //confSync();
211 212
212 return; 213 return;
213 } 214 }
214 if ( action == 1 ) { 215 if ( action == 1 ) {
215 multiSync( true ); 216 multiSync( true );
216 return; 217 return;
217 } 218 }
218 if ( action == 2 ) { 219 if ( action == 2 ) {
219 enableQuick(); 220 enableQuick();
220 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 221 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
221 return; 222 return;
222 } 223 }
223 if ( action == 3 ) { 224 if ( action == 3 ) {
224 delete mServerSocket; 225 delete mServerSocket;
225 mServerSocket = 0; 226 mServerSocket = 0;
226 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 227 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
227 return; 228 return;
228 } 229 }
229 230
230 if (blockSave()) 231 if (blockSave())
231 return; 232 return;
232 233
233 setBlockSave(true); 234 setBlockSave(true);
234 bool silent = false; 235 bool silent = false;
235 if ( action == 999 ) { 236 if ( action == 999 ) {
236 //special mode for silent syncing 237 //special mode for silent syncing
237 action = 1000; 238 action = 1000;
238 silent = true; 239 silent = true;
239 } 240 }
240 241
241 mCurrentSyncProfile = action - 1000 ; 242 mCurrentSyncProfile = action - 1000 ;
242 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 243 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
243 mCurrentSyncName = mLocalMachineName ; 244 mCurrentSyncName = mLocalMachineName ;
244 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 245 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
245 KSyncProfile* temp = new KSyncProfile (); 246 KSyncProfile* temp = new KSyncProfile ();
246 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 247 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
247 temp->readConfig(&config); 248 temp->readConfig(&config);
248 if (silent) { 249 if (silent) {
249 mAskForPreferences = false; 250 mAskForPreferences = false;
250 mShowSyncSummary = false; 251 mShowSyncSummary = false;
251 mWriteBackFile = true; 252 mWriteBackFile = true;
252 mSyncAlgoPrefs = 2;// take newest 253 mSyncAlgoPrefs = 2;// take newest
253 } 254 }
254 else { 255 else {
255 mAskForPreferences = temp->getAskForPreferences(); 256 mAskForPreferences = temp->getAskForPreferences();
256 mShowSyncSummary = temp->getShowSummaryAfterSync(); 257 mShowSyncSummary = temp->getShowSummaryAfterSync();
257 mWriteBackFile = temp->getWriteBackFile(); 258 mWriteBackFile = temp->getWriteBackFile();
258 mSyncAlgoPrefs = temp->getSyncPrefs(); 259 mSyncAlgoPrefs = temp->getSyncPrefs();
259 } 260 }
260 mWriteBackExistingOnly = temp->getWriteBackExisting(); 261 mWriteBackExistingOnly = temp->getWriteBackExisting();
261 mIsKapiFile = temp->getIsKapiFile(); 262 mIsKapiFile = temp->getIsKapiFile();
262 mWriteBackInFuture = 0; 263 mWriteBackInFuture = 0;
263 if ( temp->getWriteBackFuture() ) { 264 if ( temp->getWriteBackFuture() ) {
264 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 265 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
265 mWriteBackInPast = temp->getWriteBackPastWeeks( ); 266 mWriteBackInPast = temp->getWriteBackPastWeeks( );
266 } 267 }
267 mFilterInCal = temp->getFilterInCal(); 268 mFilterInCal = temp->getFilterInCal();
268 mFilterOutCal = temp->getFilterOutCal(); 269 mFilterOutCal = temp->getFilterOutCal();
269 mFilterInAB = temp->getFilterInAB(); 270 mFilterInAB = temp->getFilterInAB();
270 mFilterOutAB = temp->getFilterOutAB(); 271 mFilterOutAB = temp->getFilterOutAB();
271 272
272 if ( action == 1000 ) { 273 if ( action == 1000 ) {
273 mIsKapiFile = false; 274 mIsKapiFile = false;
274#ifdef DESKTOP_VERSION 275#ifdef DESKTOP_VERSION
275 syncKDE(); 276 syncKDE();
276#else 277#else
277 syncSharp(); 278 syncSharp();
278#endif 279#endif
279 280
280 } else if ( action == 1001 ) { 281 } else if ( action == 1001 ) {
281 syncLocalFile(); 282 syncLocalFile();
282 283
283 } else if ( action == 1002 ) { 284 } else if ( action == 1002 ) {
284 mWriteBackFile = false; 285 mWriteBackFile = false;
285 mAskForPreferences = false; 286 mAskForPreferences = false;
286 mShowSyncSummary = false; 287 mShowSyncSummary = false;
287 mSyncAlgoPrefs = 3; 288 mSyncAlgoPrefs = 3;
288 quickSyncLocalFile(); 289 quickSyncLocalFile();
289 290
290 } else if ( action >= 1003 ) { 291 } else if ( action >= 1003 ) {
291 if ( temp->getIsLocalFileSync() ) { 292 if ( temp->getIsLocalFileSync() ) {
292 switch(mTargetApp) 293 switch(mTargetApp)
293 { 294 {
294 case (KAPI): 295 case (KAPI):
295 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 296 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
296 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 297 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
297 break; 298 break;
298 case (KOPI): 299 case (KOPI):
299 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 300 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
300 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 301 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
301 break; 302 break;
302 case (PWMPI): 303 case (PWMPI):
303 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 304 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
304 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 305 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
305 break; 306 break;
306 default: 307 default:
307 qDebug("KSM::slotSyncMenu: invalid apptype selected"); 308 qDebug("KSM::slotSyncMenu: invalid apptype selected");
308 break; 309 break;
309 310
310 } 311 }
311 } else { 312 } else {
312 if ( temp->getIsPhoneSync() ) { 313 if ( temp->getIsPhoneSync() ) {
313 mPhoneDevice = temp->getPhoneDevice( ) ; 314 mPhoneDevice = temp->getPhoneDevice( ) ;
314 mPhoneConnection = temp->getPhoneConnection( ); 315 mPhoneConnection = temp->getPhoneConnection( );
315 mPhoneModel = temp->getPhoneModel( ); 316 mPhoneModel = temp->getPhoneModel( );
316 syncPhone(); 317 syncPhone();
317 } else if ( temp->getIsPiSync()|| temp->getIsPiSyncSpec()) { 318 } else if ( temp->getIsPiSync()|| temp->getIsPiSyncSpec()) {
318 mSpecificResources.clear(); 319 mSpecificResources.clear();
319 if ( mTargetApp == KAPI ) { 320 if ( mTargetApp == KAPI ) {
320 mPassWordPiSync = temp->getRemotePwAB(); 321 mPassWordPiSync = temp->getRemotePwAB();
321 mActiveSyncPort = temp->getRemotePortAB(); 322 mActiveSyncPort = temp->getRemotePortAB();
322 mActiveSyncIP = temp->getRemoteIPAB(); 323 mActiveSyncIP = temp->getRemoteIPAB();
323 } else if ( mTargetApp == KOPI ) { 324 } else if ( mTargetApp == KOPI ) {
324 if ( temp->getIsPiSyncSpec() ) 325 if ( temp->getIsPiSyncSpec() )
325 mSpecificResources = QStringList::split( ":", temp->getResSpecKopi() ); 326 mSpecificResources = QStringList::split( ":", temp->getResSpecKopi() );
326 mPassWordPiSync = temp->getRemotePw(); 327 mPassWordPiSync = temp->getRemotePw();
327 mActiveSyncPort = temp->getRemotePort(); 328 mActiveSyncPort = temp->getRemotePort();
328 mActiveSyncIP = temp->getRemoteIP(); 329 mActiveSyncIP = temp->getRemoteIP();
329 } else { 330 } else {
330 mPassWordPiSync = temp->getRemotePwPWM(); 331 mPassWordPiSync = temp->getRemotePwPWM();
331 mActiveSyncPort = temp->getRemotePortPWM(); 332 mActiveSyncPort = temp->getRemotePortPWM();
332 mActiveSyncIP = temp->getRemoteIPPWM(); 333 mActiveSyncIP = temp->getRemoteIPPWM();
333 } 334 }
334 syncPi(); 335 syncPi();
335 while ( !mPisyncFinished ) { 336 while ( !mPisyncFinished ) {
336 //qDebug("waiting "); 337 //qDebug("waiting ");
337 qApp->processEvents(); 338 qApp->processEvents();
338 } 339 }
339 } else 340 } else
340 syncRemote( temp ); 341 syncRemote( temp );
341 342
342 } 343 }
343 } 344 }
344 delete temp; 345 delete temp;
345 setBlockSave(false); 346 setBlockSave(false);
346} 347}
347 348
348void KSyncManager::enableQuick( bool ask ) 349void KSyncManager::enableQuick( bool ask )
349{ 350{
350 bool autoStart; 351 bool autoStart;
351 bool changed = false; 352 bool changed = false;
352 if ( ask ) { 353 if ( ask ) {
353 QDialog dia ( 0, "input-dialog", true ); 354 QDialog dia ( 0, "input-dialog", true );
354 QLineEdit lab ( &dia ); 355 QLineEdit lab ( &dia );
355 QVBoxLayout lay( &dia ); 356 QVBoxLayout lay( &dia );
356 lab.setText( mPrefs->mPassiveSyncPort ); 357 lab.setText( mPrefs->mPassiveSyncPort );
357 lay.setMargin(7); 358 lay.setMargin(7);
358 lay.setSpacing(7); 359 lay.setSpacing(7);
359 int po = 9197+mTargetApp; 360 int po = 9197+mTargetApp;
360 QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia ); 361 QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia );
361 lay.addWidget( &label); 362 lay.addWidget( &label);
362 lay.addWidget( &lab); 363 lay.addWidget( &lab);
363 364
364 QLineEdit lepw ( &dia ); 365 QLineEdit lepw ( &dia );
365 lepw.setText( mPrefs->mPassiveSyncPw ); 366 lepw.setText( mPrefs->mPassiveSyncPw );
366 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 367 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
367 lay.addWidget( &label2); 368 lay.addWidget( &label2);
368 lay.addWidget( &lepw); 369 lay.addWidget( &lepw);
369 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 370 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
370 lay.addWidget( &autostart); 371 lay.addWidget( &autostart);
371 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 372 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
372#ifdef DESKTOP_VERSION 373#ifdef DESKTOP_VERSION
373#ifdef _WIN32_ 374#ifdef _WIN32_
374 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 375 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
375 syncdesktop.hide();// not implemented! 376 syncdesktop.hide();// not implemented!
376#else 377#else
377 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 378 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
378#endif 379#endif
379 lay.addWidget( &syncdesktop); 380 lay.addWidget( &syncdesktop);
380#else 381#else
381 mPrefs->mPassiveSyncWithDesktop = false; 382 mPrefs->mPassiveSyncWithDesktop = false;
382 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 383 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
383 syncdesktop.hide(); 384 syncdesktop.hide();
384#endif 385#endif
385 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 386 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
386 387
387 QPushButton pb ( "OK", &dia); 388 QPushButton pb ( "OK", &dia);
388 lay.addWidget( &pb ); 389 lay.addWidget( &pb );
389 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 390 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
390 dia.resize( 230,120 ); 391 dia.resize( 230,120 );
391 dia.setCaption( i18n("Enter port for Pi-Sync") ); 392 dia.setCaption( i18n("Enter port for Pi-Sync") );
392 dia.show(); 393 dia.show();
393#ifndef DESKTOP_VERSION 394#ifndef DESKTOP_VERSION
394 int dw = QApplication::desktop()->width(); 395 int dw = QApplication::desktop()->width();
395 int dh = QApplication::desktop()->height(); 396 int dh = QApplication::desktop()->height();
396 dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); 397 dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 );
397#endif 398#endif
398 if ( ! dia.exec() ) 399 if ( ! dia.exec() )
399 return; 400 return;
400 dia.hide(); 401 dia.hide();
401 qApp->processEvents(); 402 qApp->processEvents();
402 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 403 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
403 changed = true; 404 changed = true;
404 mPrefs->mPassiveSyncPw = lepw.text(); 405 mPrefs->mPassiveSyncPw = lepw.text();
405 } 406 }
406 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 407 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
407 mPrefs->mPassiveSyncPort = lab.text(); 408 mPrefs->mPassiveSyncPort = lab.text();
408 changed = true; 409 changed = true;
409 } 410 }
410 autoStart = autostart.isChecked(); 411 autoStart = autostart.isChecked();
411 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 412 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
412 changed = true; 413 changed = true;
413 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 414 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
414 } 415 }
415 } 416 }
416 else 417 else
417 autoStart = mPrefs->mPassiveSyncAutoStart; 418 autoStart = mPrefs->mPassiveSyncAutoStart;
418 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 419 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
419 changed = true; 420 changed = true;
420 bool ok; 421 bool ok;
421 mPrefs->mPassiveSyncAutoStart = false; 422 mPrefs->mPassiveSyncAutoStart = false;
422 Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok); 423 Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok);
423 qDebug("%d ", port_t); 424 qDebug("%d ", port_t);
424 if ( ! ok || port_t > 65535 ) { 425 if ( ! ok || port_t > 65535 ) {
425 KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error")); 426 KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error"));
426 return; 427 return;
427 } 428 }
428 Q_UINT16 port = port_t; 429 Q_UINT16 port = port_t;
429 //qDebug("port %d ", port); 430 //qDebug("port %d ", port);
430 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 431 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
431 mServerSocket->setFileName( defaultFileName() );//bbb 432 mServerSocket->setFileName( defaultFileName() );//bbb
432 if ( !mServerSocket->ok() ) { 433 if ( !mServerSocket->ok() ) {
433 QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) ); 434 QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) );
434 delete mServerSocket; 435 delete mServerSocket;
435 mServerSocket = 0; 436 mServerSocket = 0;
436 return; 437 return;
437 } 438 }
438 mPrefs->mPassiveSyncAutoStart = autoStart; 439 mPrefs->mPassiveSyncAutoStart = autoStart;
439 if ( changed ) { 440 if ( changed ) {
440 mPrefs->writeConfig(); 441 mPrefs->writeConfig();
441 } 442 }
442 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 443 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
443 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 444 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
445 connect( mServerSocket, SIGNAL ( request_file(const QString &) ),this, SIGNAL ( request_file(const QString &) ) );
446 connect( mServerSocket, SIGNAL ( file_received( bool ,const QString &) ), this, SIGNAL ( getFile( bool,const QString & ) ) );
444} 447}
445void KSyncManager::displayErrorPort() 448void KSyncManager::displayErrorPort()
446{ 449{
447 KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error")); 450 KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error"));
448} 451}
449void KSyncManager::syncLocalFile() 452void KSyncManager::syncLocalFile()
450{ 453{
451 454
452 QString fn =mPrefs->mLastSyncedLocalFile; 455 QString fn =mPrefs->mLastSyncedLocalFile;
453 QString ext; 456 QString ext;
454 457
455 switch(mTargetApp) 458 switch(mTargetApp)
456 { 459 {
457 case (KAPI): 460 case (KAPI):
458 ext = "(*.vcf)"; 461 ext = "(*.vcf)";
459 break; 462 break;
460 case (KOPI): 463 case (KOPI):
461 ext = "(*.ics/*.vcs)"; 464 ext = "(*.ics/*.vcs)";
462 break; 465 break;
463 case (PWMPI): 466 case (PWMPI):
464 ext = "(*.pwm)"; 467 ext = "(*.pwm)";
465 break; 468 break;
466 default: 469 default:
467 qDebug("KSM::syncLocalFile: invalid apptype selected"); 470 qDebug("KSM::syncLocalFile: invalid apptype selected");
468 break; 471 break;
469 472
470 } 473 }
471 474
472 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 475 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
473 if ( fn == "" ) 476 if ( fn == "" )
474 return; 477 return;
475 if ( syncWithFile( fn, false ) ) { 478 if ( syncWithFile( fn, false ) ) {
476 qDebug("KSM::syncLocalFile() successful "); 479 qDebug("KSM::syncLocalFile() successful ");
477 } 480 }
478 481
479} 482}
480 483
481bool KSyncManager::syncWithFile( QString fn , bool quick ) 484bool KSyncManager::syncWithFile( QString fn , bool quick )
482{ 485{
483 bool ret = false; 486 bool ret = false;
484 QFileInfo info; 487 QFileInfo info;
485 info.setFile( fn ); 488 info.setFile( fn );
486 QString mess; 489 QString mess;
487 if ( !info. exists() ) { 490 if ( !info. exists() ) {
488 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 491 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
489 QMessageBox::warning( mParent, i18n("Warning!"), 492 QMessageBox::warning( mParent, i18n("Warning!"),
490 mess ); 493 mess );
491 return ret; 494 return ret;
492 } 495 }
493 int result = 0; 496 int result = 0;
494 if ( !quick ) { 497 if ( !quick ) {
495 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 498 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
496 result = QMessageBox::warning( mParent, i18n("Warning!"), 499 result = QMessageBox::warning( mParent, i18n("Warning!"),
497 mess, 500 mess,
498 i18n("Sync"), i18n("Cancel"), 0, 501 i18n("Sync"), i18n("Cancel"), 0,
499 0, 1 ); 502 0, 1 );
500 if ( result ) 503 if ( result )
501 return false; 504 return false;
502 } 505 }
503 if ( mAskForPreferences ) 506 if ( mAskForPreferences )
504 if ( !edit_sync_options()) { 507 if ( !edit_sync_options()) {
505 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 508 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
506 return false; 509 return false;
507 } 510 }
508 if ( result == 0 ) { 511 if ( result == 0 ) {
509 //qDebug("Now sycing ... "); 512 //qDebug("Now sycing ... ");
510 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ,mCurrentResourceLocal ) ) 513 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ,mCurrentResourceLocal ) )
511 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 514 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
512 else 515 else
513 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 516 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
514 if ( ! quick ) 517 if ( ! quick )
515 mPrefs->mLastSyncedLocalFile = fn; 518 mPrefs->mLastSyncedLocalFile = fn;
516 } 519 }
517 return ret; 520 return ret;
518} 521}
519 522
520void KSyncManager::quickSyncLocalFile() 523void KSyncManager::quickSyncLocalFile()
521{ 524{
522 525
523 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 526 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
524 qDebug("KSM::quick syncLocalFile() successful "); 527 qDebug("KSM::quick syncLocalFile() successful ");
525 528
526 } 529 }
527} 530}
528 531
529void KSyncManager::multiSync( bool askforPrefs ) 532void KSyncManager::multiSync( bool askforPrefs )
530{ 533{
531 if (blockSave()) 534 if (blockSave())
532 return; 535 return;
533 setBlockSave(true); 536 setBlockSave(true);
534 mCurrentResourceLocal = ""; 537 mCurrentResourceLocal = "";
535 if ( askforPrefs ) { 538 if ( askforPrefs ) {
536 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 539 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
537 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 540 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
538 question, 541 question,
539 i18n("Yes"), i18n("No"), 542 i18n("Yes"), i18n("No"),
540 0, 0 ) != 0 ) { 543 0, 0 ) != 0 ) {
541 setBlockSave(false); 544 setBlockSave(false);
542 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 545 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
543 return; 546 return;
544 } 547 }
545 } 548 }
546 mCurrentSyncDevice = i18n("Multiple profiles") ; 549 mCurrentSyncDevice = i18n("Multiple profiles") ;
547 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 550 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
548 if ( askforPrefs ) { 551 if ( askforPrefs ) {
549 if ( !edit_sync_options()) { 552 if ( !edit_sync_options()) {
550 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); 553 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") );
551 return; 554 return;
552 } 555 }
553 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 556 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
554 } 557 }
555 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 558 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
556 qApp->processEvents(); 559 qApp->processEvents();
557 int num = ringSync() ; 560 int num = ringSync() ;
558 if ( num > 1 ) 561 if ( num > 1 )
559 ringSync(); 562 ringSync();
560 setBlockSave(false); 563 setBlockSave(false);
561 if ( num ) 564 if ( num )
562 emit save(); 565 emit save();
563 if ( num ) 566 if ( num )
564 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 567 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
565 else 568 else
566 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 569 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
567 return; 570 return;
568} 571}
569 572
570int KSyncManager::ringSync() 573int KSyncManager::ringSync()
571{ 574{
572 575 emit multiResourceSyncStart( false );
573 int syncedProfiles = 0; 576 int syncedProfiles = 0;
574 unsigned int i; 577 unsigned int i;
575 QTime timer; 578 QTime timer;
576 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 579 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
577 QStringList syncProfileNames = mSyncProfileNames; 580 QStringList syncProfileNames = mSyncProfileNames;
578 KSyncProfile* temp = new KSyncProfile (); 581 KSyncProfile* temp = new KSyncProfile ();
579 mAskForPreferences = false; 582 mAskForPreferences = false;
580 mCurrentResourceLocal = ""; 583 mCurrentResourceLocal = "";
581 for ( i = 0; i < syncProfileNames.count(); ++i ) { 584 for ( i = 0; i < syncProfileNames.count(); ++i ) {
582 mCurrentSyncProfile = i; 585 mCurrentSyncProfile = i;
583 temp->setName(syncProfileNames[mCurrentSyncProfile]); 586 temp->setName(syncProfileNames[mCurrentSyncProfile]);
584 temp->readConfig(&config); 587 temp->readConfig(&config);
585 588
586 bool includeInRingSync = false; 589 bool includeInRingSync = false;
587 switch(mTargetApp) 590 switch(mTargetApp)
588 { 591 {
589 case (KAPI): 592 case (KAPI):
590 includeInRingSync = temp->getIncludeInRingSyncAB(); 593 includeInRingSync = temp->getIncludeInRingSyncAB();
591 break; 594 break;
592 case (KOPI): 595 case (KOPI):
593 includeInRingSync = temp->getIncludeInRingSync(); 596 includeInRingSync = temp->getIncludeInRingSync();
594 break; 597 break;
595 case (PWMPI): 598 case (PWMPI):
596 includeInRingSync = temp->getIncludeInRingSyncPWM(); 599 includeInRingSync = temp->getIncludeInRingSyncPWM();
597 break; 600 break;
598 default: 601 default:
599 qDebug("KSM::ringSync: invalid apptype selected"); 602 qDebug("KSM::ringSync: invalid apptype selected");
600 break; 603 break;
601 604
602 } 605 }
603 606
604 607
605 if ( includeInRingSync && ( i < 1 || i > 2 )) { 608 if ( includeInRingSync && ( i < 1 || i > 2 )) {
606 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 609 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
607 ++syncedProfiles; 610 ++syncedProfiles;
608 mSyncWithDesktop = false; 611 mSyncWithDesktop = false;
609 // mAskForPreferences = temp->getAskForPreferences(); 612 // mAskForPreferences = temp->getAskForPreferences();
610 mWriteBackFile = temp->getWriteBackFile(); 613 mWriteBackFile = temp->getWriteBackFile();
611 mWriteBackExistingOnly = temp->getWriteBackExisting(); 614 mWriteBackExistingOnly = temp->getWriteBackExisting();
612 mIsKapiFile = temp->getIsKapiFile(); 615 mIsKapiFile = temp->getIsKapiFile();
613 mWriteBackInFuture = 0; 616 mWriteBackInFuture = 0;
614 if ( temp->getWriteBackFuture() ) { 617 if ( temp->getWriteBackFuture() ) {
615 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 618 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
616 mWriteBackInPast = temp->getWriteBackPastWeeks( ); 619 mWriteBackInPast = temp->getWriteBackPastWeeks( );
617 } 620 }
618 mFilterInCal = temp->getFilterInCal(); 621 mFilterInCal = temp->getFilterInCal();
619 mFilterOutCal = temp->getFilterOutCal(); 622 mFilterOutCal = temp->getFilterOutCal();
620 mFilterInAB = temp->getFilterInAB(); 623 mFilterInAB = temp->getFilterInAB();
621 mFilterOutAB = temp->getFilterOutAB(); 624 mFilterOutAB = temp->getFilterOutAB();
622 mShowSyncSummary = false; 625 mShowSyncSummary = false;
623 mCurrentSyncDevice = syncProfileNames[i] ; 626 mCurrentSyncDevice = syncProfileNames[i] ;
624 mCurrentSyncName = mLocalMachineName; 627 mCurrentSyncName = mLocalMachineName;
625 if ( i == 0 ) { 628 if ( i == 0 ) {
626 mIsKapiFile = false; 629 mIsKapiFile = false;
627#ifdef DESKTOP_VERSION 630#ifdef DESKTOP_VERSION
628 syncKDE(); 631 syncKDE();
629#else 632#else
630 syncSharp(); 633 syncSharp();
631#endif 634#endif
632 } else { 635 } else {
633 if ( temp->getIsLocalFileSync() ) { 636 if ( temp->getIsLocalFileSync() ) {
634 switch(mTargetApp) 637 switch(mTargetApp)
635 { 638 {
636 case (KAPI): 639 case (KAPI):
637 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 640 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
638 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 641 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
639 break; 642 break;
640 case (KOPI): 643 case (KOPI):
641 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 644 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
642 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 645 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
643 break; 646 break;
644 case (PWMPI): 647 case (PWMPI):
645 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 648 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
646 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 649 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
647 break; 650 break;
648 default: 651 default:
649 qDebug("KSM: invalid apptype selected"); 652 qDebug("KSM: invalid apptype selected");
650 break; 653 break;
651 } 654 }
652 } else { 655 } else {
653 if ( temp->getIsPhoneSync() ) { 656 if ( temp->getIsPhoneSync() ) {
654 mPhoneDevice = temp->getPhoneDevice( ) ; 657 mPhoneDevice = temp->getPhoneDevice( ) ;
655 mPhoneConnection = temp->getPhoneConnection( ); 658 mPhoneConnection = temp->getPhoneConnection( );
656 mPhoneModel = temp->getPhoneModel( ); 659 mPhoneModel = temp->getPhoneModel( );
657 syncPhone(); 660 syncPhone();
658 } else if ( temp->getIsPiSync() || temp->getIsPiSyncSpec()) { 661 } else if ( temp->getIsPiSync() || temp->getIsPiSyncSpec()) {
659 mSpecificResources.clear(); 662 mSpecificResources.clear();
660 if ( mTargetApp == KAPI ) { 663 if ( mTargetApp == KAPI ) {
661 mPassWordPiSync = temp->getRemotePwAB(); 664 mPassWordPiSync = temp->getRemotePwAB();
662 mActiveSyncPort = temp->getRemotePortAB(); 665 mActiveSyncPort = temp->getRemotePortAB();
663 mActiveSyncIP = temp->getRemoteIPAB(); 666 mActiveSyncIP = temp->getRemoteIPAB();
664 } else if ( mTargetApp == KOPI ) { 667 } else if ( mTargetApp == KOPI ) {
665 mSpecificResources = QStringList::split( ":", temp->getResSpecKopi() ); 668 mSpecificResources = QStringList::split( ":", temp->getResSpecKopi() );
666 mPassWordPiSync = temp->getRemotePw(); 669 mPassWordPiSync = temp->getRemotePw();
667 mActiveSyncPort = temp->getRemotePort(); 670 mActiveSyncPort = temp->getRemotePort();
668 mActiveSyncIP = temp->getRemoteIP(); 671 mActiveSyncIP = temp->getRemoteIP();
669 } else { 672 } else {
670 mPassWordPiSync = temp->getRemotePwPWM(); 673 mPassWordPiSync = temp->getRemotePwPWM();
671 mActiveSyncPort = temp->getRemotePortPWM(); 674 mActiveSyncPort = temp->getRemotePortPWM();
672 mActiveSyncIP = temp->getRemoteIPPWM(); 675 mActiveSyncIP = temp->getRemoteIPPWM();
673 } 676 }
674 syncPi(); 677 syncPi();
675 while ( !mPisyncFinished ) { 678 while ( !mPisyncFinished ) {
676 //qDebug("waiting "); 679 //qDebug("waiting ");
677 qApp->processEvents(); 680 qApp->processEvents();
678 } 681 }
679 timer.start(); 682 timer.start();
680 while ( timer.elapsed () < 2000 ) { 683 while ( timer.elapsed () < 2000 ) {
681 qApp->processEvents(); 684 qApp->processEvents();
682 } 685 }
683 } else 686 } else
684 syncRemote( temp, false ); 687 syncRemote( temp, false );
685 688
686 } 689 }
687 } 690 }
688 timer.start(); 691 timer.start();
689 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 692 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
690 while ( timer.elapsed () < 2000 ) { 693 while ( timer.elapsed () < 2000 ) {
691 qApp->processEvents(); 694 qApp->processEvents();
692#ifndef _WIN32_ 695#ifndef _WIN32_
693 sleep (1); 696 sleep (1);
694#endif 697#endif
695 } 698 }
696 699
697 } 700 }
698 701
699 } 702 }
700 delete temp; 703 delete temp;
701 return syncedProfiles; 704 return syncedProfiles;
702} 705}
703 706
704void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 707void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
705{ 708{
706 QString question; 709 QString question;
707 if ( ask ) { 710 if ( ask ) {
708 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 711 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
709 if ( QMessageBox::information( mParent, i18n("Sync"), 712 if ( QMessageBox::information( mParent, i18n("Sync"),
710 question, 713 question,
711 i18n("Yes"), i18n("No"), 714 i18n("Yes"), i18n("No"),
712 0, 0 ) != 0 ) 715 0, 0 ) != 0 )
713 return; 716 return;
714 } 717 }
715 718
716 QString preCommand; 719 QString preCommand;
717 QString localTempFile; 720 QString localTempFile;
718 QString postCommand; 721 QString postCommand;
719 722
720 switch(mTargetApp) 723 switch(mTargetApp)
721 { 724 {
722 case (KAPI): 725 case (KAPI):
723 preCommand = prof->getPreSyncCommandAB(); 726 preCommand = prof->getPreSyncCommandAB();
724 postCommand = prof->getPostSyncCommandAB(); 727 postCommand = prof->getPostSyncCommandAB();
725 localTempFile = prof->getLocalTempFileAB(); 728 localTempFile = prof->getLocalTempFileAB();
726 break; 729 break;
727 case (KOPI): 730 case (KOPI):
728 preCommand = prof->getPreSyncCommand(); 731 preCommand = prof->getPreSyncCommand();
729 postCommand = prof->getPostSyncCommand(); 732 postCommand = prof->getPostSyncCommand();
730 localTempFile = prof->getLocalTempFile(); 733 localTempFile = prof->getLocalTempFile();
731 break; 734 break;
732 case (PWMPI): 735 case (PWMPI):
733 preCommand = prof->getPreSyncCommandPWM(); 736 preCommand = prof->getPreSyncCommandPWM();
734 postCommand = prof->getPostSyncCommandPWM(); 737 postCommand = prof->getPostSyncCommandPWM();
735 localTempFile = prof->getLocalTempFilePWM(); 738 localTempFile = prof->getLocalTempFilePWM();
736 break; 739 break;
737 default: 740 default:
738 qDebug("KSM::syncRemote: invalid apptype selected"); 741 qDebug("KSM::syncRemote: invalid apptype selected");
739 break; 742 break;
740 } 743 }
741 744
742 745
743 int fi; 746 int fi;
744 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 747 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
745 QString pwd = getPassword(); 748 QString pwd = getPassword();
746 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 749 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
747 750
748 } 751 }
749 int maxlen = 30; 752 int maxlen = 30;
750 if ( QApplication::desktop()->width() > 320 ) 753 if ( QApplication::desktop()->width() > 320 )
751 maxlen += 25; 754 maxlen += 25;
752 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 755 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
753 int fileSize = 0; 756 int fileSize = 0;
754 int result = system ( preCommand ); 757 int result = system ( preCommand );
755 // 0 : okay 758 // 0 : okay
756 // 256: no such file or dir 759 // 256: no such file or dir
757 // 760 //
758 qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); 761 qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result );
759 if ( result != 0 ) { 762 if ( result != 0 ) {
760 unsigned int len = maxlen; 763 unsigned int len = maxlen;
761 while ( len < preCommand.length() ) { 764 while ( len < preCommand.length() ) {
762 preCommand.insert( len , "\n" ); 765 preCommand.insert( len , "\n" );
763 len += maxlen +2; 766 len += maxlen +2;
764 } 767 }
765 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) ; 768 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) ;
766 QMessageBox::information( mParent, i18n("Sync - ERROR"), 769 QMessageBox::information( mParent, i18n("Sync - ERROR"),
767 question, 770 question,
768 i18n("Okay!")) ; 771 i18n("Okay!")) ;
769 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 772 mParent->topLevelWidget()->setCaption ("KDE-Pim");
770 return; 773 return;
771 } 774 }
772 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 775 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
773 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 776 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
774 777
775 if ( syncWithFile( localTempFile, true ) ) { 778 if ( syncWithFile( localTempFile, true ) ) {
776 779
777 if ( mWriteBackFile ) { 780 if ( mWriteBackFile ) {
778 int fi; 781 int fi;
779 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 782 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
780 QString pwd = getPassword(); 783 QString pwd = getPassword();
781 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 784 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
782 785
783 } 786 }
784 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 787 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
785 result = system ( postCommand ); 788 result = system ( postCommand );
786 qDebug("KSM::Sync:Writing back file result: %d ", result); 789 qDebug("KSM::Sync:Writing back file result: %d ", result);
787 if ( result != 0 ) { 790 if ( result != 0 ) {
788 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 791 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
789 return; 792 return;
790 } else { 793 } else {
791 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 794 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
792 } 795 }
793 } 796 }
794 } 797 }
795 return; 798 return;
796} 799}
797bool KSyncManager::edit_pisync_options() 800bool KSyncManager::edit_pisync_options()
798{ 801{
799 QDialog dia( mParent, "dia", true ); 802 QDialog dia( mParent, "dia", true );
800 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 803 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
801 QVBoxLayout lay ( &dia ); 804 QVBoxLayout lay ( &dia );
802 lay.setSpacing( 5 ); 805 lay.setSpacing( 5 );
803 lay.setMargin( 3 ); 806 lay.setMargin( 3 );
804 QLabel lab1 ( i18n("Password for remote access:"), &dia); 807 QLabel lab1 ( i18n("Password for remote access:"), &dia);
805 lay.addWidget( &lab1 ); 808 lay.addWidget( &lab1 );
806 QLineEdit le1 (&dia ); 809 QLineEdit le1 (&dia );
807 lay.addWidget( &le1 ); 810 lay.addWidget( &le1 );
808 QLabel lab2 ( i18n("Remote IP address:"), &dia); 811 QLabel lab2 ( i18n("Remote IP address:"), &dia);
809 lay.addWidget( &lab2 ); 812 lay.addWidget( &lab2 );
810 QLineEdit le2 (&dia ); 813 QLineEdit le2 (&dia );
811 lay.addWidget( &le2 ); 814 lay.addWidget( &le2 );
812 QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia); 815 QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia);
813 lay.addWidget( &lab3 ); 816 lay.addWidget( &lab3 );
814 QLineEdit le3 (&dia ); 817 QLineEdit le3 (&dia );
815 lay.addWidget( &le3 ); 818 lay.addWidget( &le3 );
816 QPushButton pb ( "OK", &dia); 819 QPushButton pb ( "OK", &dia);
817 lay.addWidget( &pb ); 820 lay.addWidget( &pb );
818 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 821 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
819 le1.setText( mPassWordPiSync ); 822 le1.setText( mPassWordPiSync );
820 le2.setText( mActiveSyncIP ); 823 le2.setText( mActiveSyncIP );
821 le3.setText( mActiveSyncPort ); 824 le3.setText( mActiveSyncPort );
822 if ( dia.exec() ) { 825 if ( dia.exec() ) {
823 mPassWordPiSync = le1.text(); 826 mPassWordPiSync = le1.text();
824 mActiveSyncPort = le3.text(); 827 mActiveSyncPort = le3.text();
825 mActiveSyncIP = le2.text(); 828 mActiveSyncIP = le2.text();
826 return true; 829 return true;
827 } 830 }
828 return false; 831 return false;
@@ -887,865 +890,874 @@ QString KSyncManager::getPassword( )
887 lab.setEchoMode( QLineEdit::Password ); 890 lab.setEchoMode( QLineEdit::Password );
888 QVBoxLayout lay( &dia ); 891 QVBoxLayout lay( &dia );
889 lay.setMargin(7); 892 lay.setMargin(7);
890 lay.setSpacing(7); 893 lay.setSpacing(7);
891 lay.addWidget( &lab); 894 lay.addWidget( &lab);
892 dia.setFixedSize( 230,50 ); 895 dia.setFixedSize( 230,50 );
893 dia.setCaption( i18n("Enter password") ); 896 dia.setCaption( i18n("Enter password") );
894 QPushButton pb ( "OK", &dia); 897 QPushButton pb ( "OK", &dia);
895 lay.addWidget( &pb ); 898 lay.addWidget( &pb );
896 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 899 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
897 dia.show(); 900 dia.show();
898 int res = dia.exec(); 901 int res = dia.exec();
899 if ( res ) 902 if ( res )
900 retfile = lab.text(); 903 retfile = lab.text();
901 dia.hide(); 904 dia.hide();
902 qApp->processEvents(); 905 qApp->processEvents();
903 return retfile; 906 return retfile;
904 907
905} 908}
906 909
907 910
908void KSyncManager::confSync() 911void KSyncManager::confSync()
909{ 912{
910 static KSyncPrefsDialog* sp = 0; 913 static KSyncPrefsDialog* sp = 0;
911 if ( ! sp ) { 914 if ( ! sp ) {
912 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 915 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
913 } 916 }
914 sp->usrReadConfig(); 917 sp->usrReadConfig();
915#ifndef DESKTOP_VERSION 918#ifndef DESKTOP_VERSION
916 sp->showMaximized(); 919 sp->showMaximized();
917#else 920#else
918 sp->show(); 921 sp->show();
919#endif 922#endif
920 sp->exec(); 923 sp->exec();
921 QStringList oldSyncProfileNames = mSyncProfileNames; 924 QStringList oldSyncProfileNames = mSyncProfileNames;
922 mSyncProfileNames = sp->getSyncProfileNames(); 925 mSyncProfileNames = sp->getSyncProfileNames();
923 mLocalMachineName = sp->getLocalMachineName (); 926 mLocalMachineName = sp->getLocalMachineName ();
924 int ii; 927 int ii;
925 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { 928 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
926 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) 929 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
927 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); 930 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
928 } 931 }
929 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 932 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
930} 933}
931void KSyncManager::syncKDE() 934void KSyncManager::syncKDE()
932{ 935{
933 mSyncWithDesktop = true; 936 mSyncWithDesktop = true;
934 emit save(); 937 emit save();
935 switch(mTargetApp) 938 switch(mTargetApp)
936 { 939 {
937 case (KAPI): 940 case (KAPI):
938 { 941 {
939#ifdef DESKTOP_VERSION 942#ifdef DESKTOP_VERSION
940 QString command = "kdeabdump33"; 943 QString command = "kdeabdump33";
941 QString commandfile = "kdeabdump33"; 944 QString commandfile = "kdeabdump33";
942 QString commandpath = qApp->applicationDirPath () + "/"; 945 QString commandpath = qApp->applicationDirPath () + "/";
943#else 946#else
944 QString command = "kdeabdump33"; 947 QString command = "kdeabdump33";
945 QString commandfile = "kdeabdump33"; 948 QString commandfile = "kdeabdump33";
946 QString commandpath = QDir::homeDirPath ()+"/"; 949 QString commandpath = QDir::homeDirPath ()+"/";
947#endif 950#endif
948 if ( ! QFile::exists ( commandpath+commandfile ) ) 951 if ( ! QFile::exists ( commandpath+commandfile ) )
949 command = commandfile; 952 command = commandfile;
950 else 953 else
951 command = commandpath+commandfile; 954 command = commandpath+commandfile;
952 955
953 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; 956 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
954 int result = system ( command.latin1()); 957 int result = system ( command.latin1());
955 qDebug("AB dump 33 command call result: %d ", result); 958 qDebug("AB dump 33 command call result: %d ", result);
956 if ( result != 0 ) { 959 if ( result != 0 ) {
957 qDebug("Calling AB dump version 33 failed. Trying 34... "); 960 qDebug("Calling AB dump version 33 failed. Trying 34... ");
958 commandfile = "kdeabdump34"; 961 commandfile = "kdeabdump34";
959 if ( ! QFile::exists ( commandpath+commandfile ) ) 962 if ( ! QFile::exists ( commandpath+commandfile ) )
960 command = commandfile; 963 command = commandfile;
961 else 964 else
962 command = commandpath+commandfile; 965 command = commandpath+commandfile;
963 result = system ( command.latin1()); 966 result = system ( command.latin1());
964 qDebug("AB dump 34 command call result: %d ", result); 967 qDebug("AB dump 34 command call result: %d ", result);
965 if ( result != 0 ) { 968 if ( result != 0 ) {
966 KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); 969 KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath ));
967 return; 970 return;
968 } 971 }
969 } 972 }
970 if ( syncWithFile( fileName,true ) ) { 973 if ( syncWithFile( fileName,true ) ) {
971 if ( mWriteBackFile ) { 974 if ( mWriteBackFile ) {
972 command += " --read"; 975 command += " --read";
973 system ( command.latin1()); 976 system ( command.latin1());
974 } 977 }
975 } 978 }
976 979
977 } 980 }
978 break; 981 break;
979 case (KOPI): 982 case (KOPI):
980 { 983 {
981#ifdef DESKTOP_VERSION 984#ifdef DESKTOP_VERSION
982 QString command = "kdecaldump33"; 985 QString command = "kdecaldump33";
983 QString commandfile = "kdecaldump33"; 986 QString commandfile = "kdecaldump33";
984 QString commandpath = qApp->applicationDirPath () + "/"; 987 QString commandpath = qApp->applicationDirPath () + "/";
985#else 988#else
986 QString command = "kdecaldump33"; 989 QString command = "kdecaldump33";
987 QString commandfile = "kdecaldump33"; 990 QString commandfile = "kdecaldump33";
988 QString commandpath = QDir::homeDirPath ()+"/"; 991 QString commandpath = QDir::homeDirPath ()+"/";
989#endif 992#endif
990 if ( ! QFile::exists ( commandpath+commandfile ) ) 993 if ( ! QFile::exists ( commandpath+commandfile ) )
991 command = commandfile; 994 command = commandfile;
992 else 995 else
993 command = commandpath+commandfile; 996 command = commandpath+commandfile;
994 997
995 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 998 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
996 int result = system ( command.latin1()); 999 int result = system ( command.latin1());
997 qDebug("Cal dump 33 command call result result: %d ", result); 1000 qDebug("Cal dump 33 command call result result: %d ", result);
998 if ( result != 0 ) { 1001 if ( result != 0 ) {
999 qDebug("Calling CAL dump version 33 failed. Trying 34... "); 1002 qDebug("Calling CAL dump version 33 failed. Trying 34... ");
1000 commandfile = "kdecaldump34"; 1003 commandfile = "kdecaldump34";
1001 if ( ! QFile::exists ( commandpath+commandfile ) ) 1004 if ( ! QFile::exists ( commandpath+commandfile ) )
1002 command = commandfile; 1005 command = commandfile;
1003 else 1006 else
1004 command = commandpath+commandfile; 1007 command = commandpath+commandfile;
1005 result = system ( command.latin1()); 1008 result = system ( command.latin1());
1006 qDebug("Cal dump 34 command call result result: %d ", result); 1009 qDebug("Cal dump 34 command call result result: %d ", result);
1007 if ( result != 0 ) { 1010 if ( result != 0 ) {
1008 KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); 1011 KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath ));
1009 return; 1012 return;
1010 } 1013 }
1011 } 1014 }
1012 if ( syncWithFile( fileName,true ) ) { 1015 if ( syncWithFile( fileName,true ) ) {
1013 if ( mWriteBackFile ) { 1016 if ( mWriteBackFile ) {
1014 command += " --read"; 1017 command += " --read";
1015 system ( command.latin1()); 1018 system ( command.latin1());
1016 } 1019 }
1017 } 1020 }
1018 1021
1019 } 1022 }
1020 break; 1023 break;
1021 case (PWMPI): 1024 case (PWMPI):
1022 1025
1023 break; 1026 break;
1024 default: 1027 default:
1025 qDebug("KSM::slotSyncMenu: invalid apptype selected"); 1028 qDebug("KSM::slotSyncMenu: invalid apptype selected");
1026 break; 1029 break;
1027 1030
1028 } 1031 }
1029} 1032}
1030 1033
1031void KSyncManager::syncSharp() 1034void KSyncManager::syncSharp()
1032{ 1035{
1033 1036
1034 if ( ! syncExternalApplication("sharp") ) 1037 if ( ! syncExternalApplication("sharp") )
1035 qDebug("KSM::ERROR sync sharp "); 1038 qDebug("KSM::ERROR sync sharp ");
1036} 1039}
1037 1040
1038bool KSyncManager::syncExternalApplication(QString resource) 1041bool KSyncManager::syncExternalApplication(QString resource)
1039{ 1042{
1040 1043
1041 emit save(); 1044 emit save();
1042 1045
1043 if ( mAskForPreferences ) 1046 if ( mAskForPreferences )
1044 if ( !edit_sync_options()) { 1047 if ( !edit_sync_options()) {
1045 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1048 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1046 return false; 1049 return false;
1047 } 1050 }
1048 1051
1049 qDebug("KSM::Sync extern %s", resource.latin1()); 1052 qDebug("KSM::Sync extern %s", resource.latin1());
1050 1053
1051 bool syncOK = mImplementation->syncExternal(this, resource); 1054 bool syncOK = mImplementation->syncExternal(this, resource);
1052 1055
1053 return syncOK; 1056 return syncOK;
1054 1057
1055} 1058}
1056 1059
1057void KSyncManager::syncPhone() 1060void KSyncManager::syncPhone()
1058{ 1061{
1059 1062
1060 syncExternalApplication("phone"); 1063 syncExternalApplication("phone");
1061 1064
1062} 1065}
1063 1066
1064void KSyncManager::showProgressBar(int percentage, QString caption, int total) 1067void KSyncManager::showProgressBar(int percentage, QString caption, int total)
1065{ 1068{
1066 if (!bar->isVisible()) 1069 if (!bar->isVisible())
1067 { 1070 {
1068 int w = 300; 1071 int w = 300;
1069 if ( QApplication::desktop()->width() < 320 ) 1072 if ( QApplication::desktop()->width() < 320 )
1070 w = 220; 1073 w = 220;
1071 int h = bar->sizeHint().height() ; 1074 int h = bar->sizeHint().height() ;
1072 int dw = QApplication::desktop()->width(); 1075 int dw = QApplication::desktop()->width();
1073 int dh = QApplication::desktop()->height(); 1076 int dh = QApplication::desktop()->height();
1074 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1077 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1075 bar->setCaption (caption); 1078 bar->setCaption (caption);
1076 bar->setTotalSteps ( total ) ; 1079 bar->setTotalSteps ( total ) ;
1077 bar->show(); 1080 bar->show();
1078 } 1081 }
1079 bar->raise(); 1082 bar->raise();
1080 bar->setProgress( percentage ); 1083 bar->setProgress( percentage );
1081 qApp->processEvents(); 1084 qApp->processEvents();
1082} 1085}
1083 1086
1084void KSyncManager::hideProgressBar() 1087void KSyncManager::hideProgressBar()
1085{ 1088{
1086 bar->hide(); 1089 bar->hide();
1087 qApp->processEvents(); 1090 qApp->processEvents();
1088} 1091}
1089 1092
1090bool KSyncManager::isProgressBarCanceled() 1093bool KSyncManager::isProgressBarCanceled()
1091{ 1094{
1092 return !bar->isVisible(); 1095 return !bar->isVisible();
1093} 1096}
1094 1097
1095QString KSyncManager::syncFileName() 1098QString KSyncManager::syncFileName()
1096{ 1099{
1097 1100
1098 QString fn = "tempfile"; 1101 QString fn = "tempfile";
1099 switch(mTargetApp) 1102 switch(mTargetApp)
1100 { 1103 {
1101 case (KAPI): 1104 case (KAPI):
1102 fn = "tempsyncab.vcf"; 1105 fn = "tempsyncab.vcf";
1103 break; 1106 break;
1104 case (KOPI): 1107 case (KOPI):
1105 fn = "tempsynccal.ics"; 1108 fn = "tempsynccal.ics";
1106 break; 1109 break;
1107 case (PWMPI): 1110 case (PWMPI):
1108 fn = "tempsyncpw.pwm"; 1111 fn = "tempsyncpw.pwm";
1109 break; 1112 break;
1110 default: 1113 default:
1111 break; 1114 break;
1112 } 1115 }
1113#ifdef DESKTOP_VERSION 1116#ifdef DESKTOP_VERSION
1114 return locateLocal( "tmp", fn ); 1117 return locateLocal( "tmp", fn );
1115#else 1118#else
1116 return (QString( "/tmp/" )+ fn ); 1119 return (QString( "/tmp/" )+ fn );
1117#endif 1120#endif
1118} 1121}
1119 1122
1120void KSyncManager::syncPi() 1123void KSyncManager::syncPi()
1121{ 1124{
1122 mIsKapiFile = true; 1125 mIsKapiFile = true;
1123 mPisyncFinished = false; 1126 mPisyncFinished = false;
1124 qApp->processEvents(); 1127 qApp->processEvents();
1125 if ( mAskForPreferences ) 1128 if ( mAskForPreferences )
1126 if ( !edit_pisync_options()) { 1129 if ( !edit_pisync_options()) {
1127 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1130 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1128 mPisyncFinished = true; 1131 mPisyncFinished = true;
1129 return; 1132 return;
1130 } 1133 }
1131 bool ok; 1134 bool ok;
1132 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1135 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1133 if ( ! ok ) { 1136 if ( ! ok ) {
1134 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1137 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1135 mPisyncFinished = true; 1138 mPisyncFinished = true;
1136 return; 1139 return;
1137 } 1140 }
1138 mCurrentResourceLocal = ""; 1141 mCurrentResourceLocal = "";
1139 mCurrentResourceRemote = ""; 1142 mCurrentResourceRemote = "";
1140 if ( mSpecificResources.count() ) { 1143 if ( mSpecificResources.count() ) {
1141 int startLocal = 0; 1144 int startLocal = 0;
1142 int startRemote = mSpecificResources.count()/2; 1145 int startRemote = mSpecificResources.count()/2;
1146 emit multiResourceSyncStart( true );
1143 while ( startLocal < mSpecificResources.count()/2 ) { 1147 while ( startLocal < mSpecificResources.count()/2 ) {
1148 if ( startLocal+1 >= mSpecificResources.count()/2 )
1149 emit multiResourceSyncStart( false );
1144 mPisyncFinished = false; 1150 mPisyncFinished = false;
1145 mCurrentResourceLocal = mSpecificResources[ startLocal ]; 1151 mCurrentResourceLocal = mSpecificResources[ startLocal ];
1146 mCurrentResourceRemote = mSpecificResources[ startRemote ]; 1152 mCurrentResourceRemote = mSpecificResources[ startRemote ];
1147 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1153 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1148 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1154 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1149 commandSocket->readFile( syncFileName() ); 1155 commandSocket->readFile( syncFileName() );
1150 while ( !mPisyncFinished ) { 1156 while ( !mPisyncFinished ) {
1151 //qDebug("waiting "); 1157 //qDebug("waiting ");
1152 qApp->processEvents(); 1158 qApp->processEvents();
1153 } 1159 }
1154 ++startLocal; 1160 ++startLocal;
1155 } 1161 }
1156 } else { 1162 } else {
1157 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1163 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1158 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1164 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1159 commandSocket->readFile( syncFileName() ); 1165 commandSocket->readFile( syncFileName() );
1160 } 1166 }
1161} 1167}
1162 1168
1163void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1169void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1164{ 1170{
1165 //enum { success, errorW, errorR, quiet }; 1171 //enum { success, errorW, errorR, quiet };
1166 1172
1167 1173
1168 1174
1169 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || 1175 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW ||
1170 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { 1176 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) {
1171 if ( state == KCommandSocket::errorPW ) 1177 if ( state == KCommandSocket::errorPW )
1172 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); 1178 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") );
1173 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) 1179 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO )
1174 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1180 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1175 else if ( state == KCommandSocket::errorCA ) 1181 else if ( state == KCommandSocket::errorCA )
1176 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); 1182 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") );
1177 else if ( state == KCommandSocket::errorFI ) 1183 else if ( state == KCommandSocket::errorFI )
1178 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); 1184 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") );
1179 else if ( state == KCommandSocket::errorED ) 1185 else if ( state == KCommandSocket::errorED )
1180 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); 1186 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") );
1181 else if ( state == KCommandSocket::errorUN ) 1187 else if ( state == KCommandSocket::errorUN )
1182 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); 1188 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") );
1183 delete s; 1189 delete s;
1184 if ( state == KCommandSocket::errorR ) { 1190 if ( state == KCommandSocket::errorR ) {
1185 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); 1191 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget());
1186 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1192 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1187 commandSocket->sendStop(); 1193 commandSocket->sendStop();
1188 } 1194 }
1189 mPisyncFinished = true; 1195 mPisyncFinished = true;
1190 return; 1196 return;
1191 1197
1192 } else if ( state == KCommandSocket::errorW ) { 1198 } else if ( state == KCommandSocket::errorW ) {
1193 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1199 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1194 mPisyncFinished = true; 1200 mPisyncFinished = true;
1195 1201
1196 } else if ( state == KCommandSocket::successR ) { 1202 } else if ( state == KCommandSocket::successR ) {
1197 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1203 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1198 1204
1199 } else if ( state == KCommandSocket::successW ) { 1205 } else if ( state == KCommandSocket::successW ) {
1200 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 1206 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
1201 mPisyncFinished = true; 1207 mPisyncFinished = true;
1202 } else if ( state == KCommandSocket::quiet ){ 1208 } else if ( state == KCommandSocket::quiet ){
1203 qDebug("KSS: quiet "); 1209 qDebug("KSS: quiet ");
1204 mPisyncFinished = true; 1210 mPisyncFinished = true;
1205 } else { 1211 } else {
1206 qDebug("KSS: Error: unknown state: %d ", state); 1212 qDebug("KSS: Error: unknown state: %d ", state);
1207 mPisyncFinished = true; 1213 mPisyncFinished = true;
1208 } 1214 }
1209 1215
1210 delete s; 1216 delete s;
1211} 1217}
1212 1218
1213void KSyncManager::readFileFromSocket() 1219void KSyncManager::readFileFromSocket()
1214{ 1220{
1215 QString fileName = syncFileName(); 1221 QString fileName = syncFileName();
1216 bool syncOK = true; 1222 bool syncOK = true;
1217 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1223 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1218 if ( ! syncWithFile( fileName , true ) ) { 1224 if ( ! syncWithFile( fileName , true ) ) {
1219 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1225 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1220 syncOK = false; 1226 syncOK = false;
1221 } 1227 }
1222 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1228 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1223 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1229 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1224 if ( mWriteBackFile && syncOK ) { 1230 if ( mWriteBackFile && syncOK ) {
1225 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); 1231 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
1226 commandSocket->writeFile( fileName ); 1232 commandSocket->writeFile( fileName );
1227 } 1233 }
1228 else { 1234 else {
1229 commandSocket->sendStop(); 1235 commandSocket->sendStop();
1230 if ( syncOK ) 1236 if ( syncOK )
1231 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1237 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1232 mPisyncFinished = true; 1238 mPisyncFinished = true;
1233 } 1239 }
1234} 1240}
1235 1241
1236KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1242KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1237{ 1243{
1238 mPassWord = pw; 1244 mPassWord = pw;
1239 mSocket = 0; 1245 mSocket = 0;
1240 mSyncActionDialog = 0; 1246 mSyncActionDialog = 0;
1241 blockRC = false; 1247 blockRC = false;
1242 mErrorMessage = 0; 1248 mErrorMessage = 0;
1243} 1249}
1244 1250
1245void KServerSocket::newConnection ( int socket ) 1251void KServerSocket::newConnection ( int socket )
1246{ 1252{
1247 // qDebug("KServerSocket:New connection %d ", socket); 1253 // qDebug("KServerSocket:New connection %d ", socket);
1248 if ( mSocket ) { 1254 if ( mSocket ) {
1249 qDebug("KSS::newConnection Socket deleted! "); 1255 qDebug("KSS::newConnection Socket deleted! ");
1250 delete mSocket; 1256 delete mSocket;
1251 mSocket = 0; 1257 mSocket = 0;
1252 } 1258 }
1253 mSocket = new QSocket( this ); 1259 mSocket = new QSocket( this );
1254 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1260 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1255 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1261 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1256 mSocket->setSocket( socket ); 1262 mSocket->setSocket( socket );
1257} 1263}
1258 1264
1259void KServerSocket::discardClient() 1265void KServerSocket::discardClient()
1260{ 1266{
1261 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1267 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1262} 1268}
1263void KServerSocket::deleteSocket() 1269void KServerSocket::deleteSocket()
1264{ 1270{
1265 qDebug("KSS::deleteSocket"); 1271 qDebug("KSS::deleteSocket");
1266 if ( mSocket ) { 1272 if ( mSocket ) {
1267 delete mSocket; 1273 delete mSocket;
1268 mSocket = 0; 1274 mSocket = 0;
1269 } 1275 }
1270 if ( mErrorMessage ) 1276 if ( mErrorMessage )
1271 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); 1277 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage()));
1272} 1278}
1273void KServerSocket::readClient() 1279void KServerSocket::readClient()
1274{ 1280{
1275 if ( blockRC ) 1281 if ( blockRC )
1276 return; 1282 return;
1277 if ( mSocket == 0 ) { 1283 if ( mSocket == 0 ) {
1278 qDebug("ERROR::KSS::readClient(): mSocket == 0 "); 1284 qDebug("ERROR::KSS::readClient(): mSocket == 0 ");
1279 return; 1285 return;
1280 } 1286 }
1281 if ( mErrorMessage ) { 1287 if ( mErrorMessage ) {
1282 mErrorMessage = 999; 1288 mErrorMessage = 999;
1283 error_connect("ERROR_ED\r\n\r\n"); 1289 error_connect("ERROR_ED\r\n\r\n");
1284 return; 1290 return;
1285 } 1291 }
1292 mResource = "";
1286 mErrorMessage = 0; 1293 mErrorMessage = 0;
1287 //qDebug("KServerSocket::readClient()"); 1294 //qDebug("KServerSocket::readClient()");
1288 if ( mSocket->canReadLine() ) { 1295 if ( mSocket->canReadLine() ) {
1289 QString line = mSocket->readLine(); 1296 QString line = mSocket->readLine();
1290 //qDebug("KServerSocket readline: %s ", line.latin1()); 1297 //qDebug("KServerSocket readline: %s ", line.latin1());
1291 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1298 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1292 if ( tokens[0] == "GET" ) { 1299 if ( tokens[0] == "GET" ) {
1293 if ( tokens[1] == mPassWord ) { 1300 if ( tokens[1] == mPassWord ) {
1294 //emit sendFile( mSocket ); 1301 //emit sendFile( mSocket );
1295 bool ok = false; 1302 bool ok = false;
1296 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1303 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1297 if ( ok ) { 1304 if ( ok ) {
1298 KSyncManager::mRequestedSyncEvent = dt; 1305 KSyncManager::mRequestedSyncEvent = dt;
1299 } 1306 }
1300 else 1307 else
1301 KSyncManager::mRequestedSyncEvent = QDateTime(); 1308 KSyncManager::mRequestedSyncEvent = QDateTime();
1309 mResource =tokens[3];
1302 send_file(); 1310 send_file();
1303 } 1311 }
1304 else { 1312 else {
1305 mErrorMessage = 1; 1313 mErrorMessage = 1;
1306 error_connect("ERROR_PW\r\n\r\n"); 1314 error_connect("ERROR_PW\r\n\r\n");
1307 } 1315 }
1308 } 1316 }
1309 if ( tokens[0] == "PUT" ) { 1317 if ( tokens[0] == "PUT" ) {
1310 if ( tokens[1] == mPassWord ) { 1318 if ( tokens[1] == mPassWord ) {
1311 //emit getFile( mSocket ); 1319 //emit getFile( mSocket );
1312 blockRC = true; 1320 blockRC = true;
1321 mResource =tokens[2];
1313 get_file(); 1322 get_file();
1314 } 1323 }
1315 else { 1324 else {
1316 mErrorMessage = 2; 1325 mErrorMessage = 2;
1317 error_connect("ERROR_PW\r\n\r\n"); 1326 error_connect("ERROR_PW\r\n\r\n");
1318 end_connect(); 1327 end_connect();
1319 } 1328 }
1320 } 1329 }
1321 if ( tokens[0] == "STOP" ) { 1330 if ( tokens[0] == "STOP" ) {
1322 //emit endConnect(); 1331 //emit endConnect();
1323 end_connect(); 1332 end_connect();
1324 } 1333 }
1325 } 1334 }
1326} 1335}
1327void KServerSocket::displayErrorMessage() 1336void KServerSocket::displayErrorMessage()
1328{ 1337{
1329 if ( mErrorMessage == 1 ) { 1338 if ( mErrorMessage == 1 ) {
1330 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); 1339 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error"));
1331 mErrorMessage = 0; 1340 mErrorMessage = 0;
1332 } 1341 }
1333 else if ( mErrorMessage == 2 ) { 1342 else if ( mErrorMessage == 2 ) {
1334 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); 1343 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error"));
1335 mErrorMessage = 0; 1344 mErrorMessage = 0;
1336 } 1345 }
1337} 1346}
1338void KServerSocket::error_connect( QString errmess ) 1347void KServerSocket::error_connect( QString errmess )
1339{ 1348{
1340 QTextStream os( mSocket ); 1349 QTextStream os( mSocket );
1341 os.setEncoding( QTextStream::Latin1 ); 1350 os.setEncoding( QTextStream::Latin1 );
1342 os << errmess ; 1351 os << errmess ;
1343 mSocket->close(); 1352 mSocket->close();
1344 if ( mSocket->state() == QSocket::Idle ) { 1353 if ( mSocket->state() == QSocket::Idle ) {
1345 QTimer::singleShot( 0, this , SLOT ( discardClient())); 1354 QTimer::singleShot( 0, this , SLOT ( discardClient()));
1346 } 1355 }
1347} 1356}
1348void KServerSocket::end_connect() 1357void KServerSocket::end_connect()
1349{ 1358{
1350 delete mSyncActionDialog; 1359 delete mSyncActionDialog;
1351 mSyncActionDialog = 0; 1360 mSyncActionDialog = 0;
1352} 1361}
1353void KServerSocket::send_file() 1362void KServerSocket::send_file()
1354{ 1363{
1355 //qDebug("MainWindow::sendFile(QSocket* s) "); 1364 //qDebug("MainWindow::sendFile(QSocket* s) ");
1356 if ( mSyncActionDialog ) 1365 if ( mSyncActionDialog )
1357 delete mSyncActionDialog; 1366 delete mSyncActionDialog;
1358 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1367 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1359 mSyncActionDialog->setCaption(i18n("Received sync request")); 1368 mSyncActionDialog->setCaption(i18n("Received sync request"));
1360 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1369 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1361 label->setAlignment ( Qt::AlignHCenter ); 1370 label->setAlignment ( Qt::AlignHCenter );
1362 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1371 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1363 lay->addWidget( label); 1372 lay->addWidget( label);
1364 lay->setMargin(7); 1373 lay->setMargin(7);
1365 lay->setSpacing(7); 1374 lay->setSpacing(7);
1366 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1375 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1367 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1376 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1368 //secs = 333; 1377 //secs = 333;
1369 if ( secs < 0 ) 1378 if ( secs < 0 )
1370 secs = secs * (-1); 1379 secs = secs * (-1);
1371 if ( secs > 30 ) 1380 if ( secs > 30 )
1372 //if ( true ) 1381 //if ( true )
1373 { 1382 {
1374 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1383 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1375 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1384 QLabel* label = new QLabel( warning, mSyncActionDialog );
1376 label->setAlignment ( Qt::AlignHCenter ); 1385 label->setAlignment ( Qt::AlignHCenter );
1377 lay->addWidget( label); 1386 lay->addWidget( label);
1378 if ( secs > 180 ) 1387 if ( secs > 180 )
1379 { 1388 {
1380 if ( secs > 300 ) { 1389 if ( secs > 300 ) {
1381 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { 1390 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) {
1382 qDebug("KSS::Sync cancelled ,cs"); 1391 qDebug("KSS::Sync cancelled ,cs");
1383 mErrorMessage = 0; 1392 mErrorMessage = 0;
1384 end_connect(); 1393 end_connect();
1385 error_connect("ERROR_CA\r\n\r\n"); 1394 error_connect("ERROR_CA\r\n\r\n");
1386 return ; 1395 return ;
1387 } 1396 }
1388 } 1397 }
1389 QFont f = label->font(); 1398 QFont f = label->font();
1390 f.setPointSize ( f.pointSize() *2 ); 1399 f.setPointSize ( f.pointSize() *2 );
1391 f. setBold (true ); 1400 f. setBold (true );
1392 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1401 QLabel* label = new QLabel( warning, mSyncActionDialog );
1393 label->setFont( f ); 1402 label->setFont( f );
1394 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1403 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1395 label->setText( warning ); 1404 label->setText( warning );
1396 label->setAlignment ( Qt::AlignHCenter ); 1405 label->setAlignment ( Qt::AlignHCenter );
1397 lay->addWidget( label); 1406 lay->addWidget( label);
1398 mSyncActionDialog->setFixedSize( 230, 300); 1407 mSyncActionDialog->setFixedSize( 230, 300);
1399 } else { 1408 } else {
1400 mSyncActionDialog->setFixedSize( 230, 200); 1409 mSyncActionDialog->setFixedSize( 230, 200);
1401 } 1410 }
1402 } else { 1411 } else {
1403 mSyncActionDialog->setFixedSize( 230, 120); 1412 mSyncActionDialog->setFixedSize( 230, 120);
1404 } 1413 }
1405 } else 1414 } else
1406 mSyncActionDialog->setFixedSize( 230, 120); 1415 mSyncActionDialog->setFixedSize( 230, 120);
1407 mSyncActionDialog->show(); 1416 mSyncActionDialog->show();
1408 mSyncActionDialog->raise(); 1417 mSyncActionDialog->raise();
1418 emit request_file(mResource);
1409 emit request_file(); 1419 emit request_file();
1410 qApp->processEvents(); 1420 qApp->processEvents();
1411 QString fileName = mFileName; 1421 QString fileName = mFileName;
1412 QFile file( fileName ); 1422 QFile file( fileName );
1413 if (!file.open( IO_ReadOnly ) ) { 1423 if (!file.open( IO_ReadOnly ) ) {
1414 mErrorMessage = 0; 1424 mErrorMessage = 0;
1415 end_connect(); 1425 end_connect();
1416 error_connect("ERROR_FI\r\n\r\n"); 1426 error_connect("ERROR_FI\r\n\r\n");
1417 return ; 1427 return ;
1418 } 1428 }
1419 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1429 mSyncActionDialog->setCaption( i18n("Sending file...") );
1420 QTextStream ts( &file ); 1430 QTextStream ts( &file );
1421 ts.setEncoding( QTextStream::Latin1 ); 1431 ts.setEncoding( QTextStream::Latin1 );
1422 1432
1423 QTextStream os( mSocket ); 1433 QTextStream os( mSocket );
1424 os.setEncoding( QTextStream::Latin1 ); 1434 os.setEncoding( QTextStream::Latin1 );
1425 while ( ! ts.atEnd() ) { 1435 while ( ! ts.atEnd() ) {
1426 os << ts.readLine() << "\r\n"; 1436 os << ts.readLine() << "\r\n";
1427 } 1437 }
1428 os << "\r\n"; 1438 os << "\r\n";
1429 //os << ts.read(); 1439 //os << ts.read();
1430 file.close(); 1440 file.close();
1431 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1441 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1432 mSocket->close(); 1442 mSocket->close();
1433 if ( mSocket->state() == QSocket::Idle ) 1443 if ( mSocket->state() == QSocket::Idle )
1434 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1444 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1435} 1445}
1436void KServerSocket::get_file() 1446void KServerSocket::get_file()
1437{ 1447{
1438 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1448 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1439 1449
1440 piTime.start(); 1450 piTime.start();
1441 piFileString = ""; 1451 piFileString = "";
1442 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1452 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1443} 1453}
1444 1454
1445 1455
1446void KServerSocket::readBackFileFromSocket() 1456void KServerSocket::readBackFileFromSocket()
1447{ 1457{
1448 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1458 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1449 while ( mSocket->canReadLine () ) { 1459 while ( mSocket->canReadLine () ) {
1450 piTime.restart(); 1460 piTime.restart();
1451 QString line = mSocket->readLine (); 1461 QString line = mSocket->readLine ();
1452 piFileString += line; 1462 piFileString += line;
1453 //qDebug("readline: %s ", line.latin1()); 1463 //qDebug("readline: %s ", line.latin1());
1454 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1464 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1455 1465
1456 } 1466 }
1457 if ( piTime.elapsed () < 3000 ) { 1467 if ( piTime.elapsed () < 3000 ) {
1458 // wait for more 1468 // wait for more
1459 //qDebug("waitformore "); 1469 //qDebug("waitformore ");
1460 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1470 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1461 return; 1471 return;
1462 } 1472 }
1463 QString fileName = mFileName; 1473 QString fileName = mFileName;
1464 QFile file ( fileName ); 1474 QFile file ( fileName );
1465 if (!file.open( IO_WriteOnly ) ) { 1475 if (!file.open( IO_WriteOnly ) ) {
1466 delete mSyncActionDialog; 1476 delete mSyncActionDialog;
1467 mSyncActionDialog = 0; 1477 mSyncActionDialog = 0;
1468 qDebug("KSS:Error open read back file "); 1478 qDebug("KSS:Error open read back file ");
1469 piFileString = ""; 1479 piFileString = "";
1470 emit file_received( false ); 1480 emit file_received( false, mResource);
1481 emit file_received( false);
1471 blockRC = false; 1482 blockRC = false;
1472 return ; 1483 return ;
1473 1484
1474 } 1485 }
1475 1486
1476 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1487 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1477 QTextStream ts ( &file ); 1488 QTextStream ts ( &file );
1478 ts.setEncoding( QTextStream::Latin1 ); 1489 ts.setEncoding( QTextStream::Latin1 );
1479 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1490 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1480 ts << piFileString; 1491 ts << piFileString;
1481 mSocket->close(); 1492 mSocket->close();
1482 if ( mSocket->state() == QSocket::Idle ) 1493 if ( mSocket->state() == QSocket::Idle )
1483 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1494 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1484 file.close(); 1495 file.close();
1485 piFileString = ""; 1496 piFileString = "";
1486 emit file_received( true ); 1497 emit file_received( true, mResource );
1498 emit file_received( true);
1487 delete mSyncActionDialog; 1499 delete mSyncActionDialog;
1488 mSyncActionDialog = 0; 1500 mSyncActionDialog = 0;
1489 blockRC = false; 1501 blockRC = false;
1490 1502
1491} 1503}
1492 1504
1493KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) 1505KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
1494{ 1506{
1495 mRemoteResource = remres; 1507 mRemoteResource = remres;
1496 if ( mRemoteResource.isEmpty() ) 1508 if ( mRemoteResource.isEmpty() )
1497 mRemoteResource = "ALL"; 1509 mRemoteResource = "ALL";
1498 mPassWord = password; 1510 mPassWord = password;
1499 mSocket = 0; 1511 mSocket = 0;
1500 mFirst = false; 1512 mFirst = false;
1501 mFirstLine = true; 1513 mFirstLine = true;
1502 mPort = port; 1514 mPort = port;
1503 mHost = host; 1515 mHost = host;
1504 tlw = cap; 1516 tlw = cap;
1505 mRetVal = quiet; 1517 mRetVal = quiet;
1506 mTimerSocket = new QTimer ( this ); 1518 mTimerSocket = new QTimer ( this );
1507 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); 1519 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
1508 mConnectProgress.setCaption( i18n("Pi-Sync") ); 1520 mConnectProgress.setCaption( i18n("Pi-Sync") );
1509 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); 1521 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
1510 mConnectCount = -1; 1522 mConnectCount = -1;
1511} 1523}
1512void KCommandSocket::sendFileRequest() 1524void KCommandSocket::sendFileRequest()
1513{ 1525{
1514 if ( tlw ) 1526 if ( tlw )
1515 tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); 1527 tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
1516 mConnectProgress.hide(); 1528 mConnectProgress.hide();
1517 mConnectCount = 300;mConnectMax = 300; 1529 mConnectCount = 300;mConnectMax = 300;
1518 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); 1530 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") );
1519 mTimerSocket->start( 100, true ); 1531 mTimerSocket->start( 100, true );
1520 QTextStream os( mSocket ); 1532 QTextStream os( mSocket );
1521 os.setEncoding( QTextStream::Latin1 ); 1533 os.setEncoding( QTextStream::Latin1 );
1522 1534
1523 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); 1535 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1524 os << "GET " << mPassWord << curDt << mRemoteResource << "\r\n\r\n"; 1536 os << "GET " << mPassWord << curDt << mRemoteResource << "\r\n\r\n";
1525} 1537}
1526 1538
1527void KCommandSocket::readFile( QString fn ) 1539void KCommandSocket::readFile( QString fn )
1528{ 1540{
1529 if ( !mSocket ) { 1541 if ( !mSocket ) {
1530 mSocket = new QSocket( this ); 1542 mSocket = new QSocket( this );
1531 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1543 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1532 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1544 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1533 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); 1545 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() ));
1534 } 1546 }
1535 mFileString = ""; 1547 mFileString = "";
1536 mFileName = fn; 1548 mFileName = fn;
1537 mFirst = true; 1549 mFirst = true;
1538 if ( tlw ) 1550 if ( tlw )
1539 tlw->setCaption( i18n("Trying to connect to remote...") ); 1551 tlw->setCaption( i18n("Trying to connect to remote...") );
1540 mConnectCount = 30;mConnectMax = 30; 1552 mConnectCount = 30;mConnectMax = 30;
1541 mTimerSocket->start( 1000, true ); 1553 mTimerSocket->start( 1000, true );
1542 mSocket->connectToHost( mHost, mPort ); 1554 mSocket->connectToHost( mHost, mPort );
1543 qDebug("KSS: Waiting for connection"); 1555 qDebug("KSS: Waiting for connection");
1544} 1556}
1545void KCommandSocket::updateConnectDialog() 1557void KCommandSocket::updateConnectDialog()
1546{ 1558{
1547 1559
1548 if ( mConnectCount == mConnectMax ) { 1560 if ( mConnectCount == mConnectMax ) {
1549 //qDebug("MAXX %d", mConnectMax); 1561 //qDebug("MAXX %d", mConnectMax);
1550 mConnectProgress.setTotalSteps ( 30 ); 1562 mConnectProgress.setTotalSteps ( 30 );
1551 mConnectProgress.show(); 1563 mConnectProgress.show();
1552 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); 1564 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") );
1553 } 1565 }
1554 //qDebug("updateConnectDialog() %d", mConnectCount); 1566 //qDebug("updateConnectDialog() %d", mConnectCount);
1555 mConnectProgress.raise(); 1567 mConnectProgress.raise();
1556 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); 1568 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 );
1557 --mConnectCount; 1569 --mConnectCount;
1558 if ( mConnectCount > 0 ) 1570 if ( mConnectCount > 0 )
1559 mTimerSocket->start( 1000, true ); 1571 mTimerSocket->start( 1000, true );
1560 else 1572 else
1561 deleteSocket(); 1573 deleteSocket();
1562 1574
1563} 1575}
1564void KCommandSocket::writeFile( QString fileName ) 1576void KCommandSocket::writeFile( QString fileName )
1565{ 1577{
1566 if ( !mSocket ) { 1578 if ( !mSocket ) {
1567 mSocket = new QSocket( this ); 1579 mSocket = new QSocket( this );
1568 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1580 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1569 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1581 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1570 } 1582 }
1571 mFileName = fileName ; 1583 mFileName = fileName ;
1572 mConnectCount = 30;mConnectMax = 30; 1584 mConnectCount = 30;mConnectMax = 30;
1573 mTimerSocket->start( 1000, true ); 1585 mTimerSocket->start( 1000, true );
1574 mSocket->connectToHost( mHost, mPort ); 1586 mSocket->connectToHost( mHost, mPort );
1575} 1587}
1576void KCommandSocket::writeFileToSocket() 1588void KCommandSocket::writeFileToSocket()
1577{ 1589{
1578 mTimerSocket->stop(); 1590 mTimerSocket->stop();
1579 QFile file2( mFileName ); 1591 QFile file2( mFileName );
1580 if (!file2.open( IO_ReadOnly ) ) { 1592 if (!file2.open( IO_ReadOnly ) ) {
1581 mConnectProgress.hide(); 1593 mConnectProgress.hide();
1582 mConnectCount = -1; 1594 mConnectCount = -1;
1583 mRetVal= errorW; 1595 mRetVal= errorW;
1584 mSocket->close(); 1596 mSocket->close();
1585 if ( mSocket->state() == QSocket::Idle ) 1597 if ( mSocket->state() == QSocket::Idle )
1586 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1598 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1587 return ; 1599 return ;
1588 } 1600 }
1589 mConnectProgress.setTotalSteps ( file2.size() ); 1601 mConnectProgress.setTotalSteps ( file2.size() );
1590 mConnectProgress.show(); 1602 mConnectProgress.show();
1591 int count = 0; 1603 int count = 0;
1592 mConnectProgress.setLabelText( i18n("Sending back synced file...") ); 1604 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1593 mConnectProgress.setProgress( count ); 1605 mConnectProgress.setProgress( count );
1594 mConnectProgress.blockSignals( true ); 1606 mConnectProgress.blockSignals( true );
1595 QTextStream ts2( &file2 ); 1607 QTextStream ts2( &file2 );
1596 ts2.setEncoding( QTextStream::Latin1 ); 1608 ts2.setEncoding( QTextStream::Latin1 );
1597 QTextStream os2( mSocket ); 1609 QTextStream os2( mSocket );
1598 os2.setEncoding( QTextStream::Latin1 ); 1610 os2.setEncoding( QTextStream::Latin1 );
1599 os2 << "PUT " << mPassWord << "\r\n\r\n";; 1611 os2 << "PUT " << mPassWord << mRemoteResource << "\r\n\r\n";;
1600 int byteCount = 0; 1612 int byteCount = 0;
1601 int byteMax = file2.size()/53; 1613 int byteMax = file2.size()/53;
1602 while ( ! ts2.atEnd() ) { 1614 while ( ! ts2.atEnd() ) {
1603 qApp->processEvents(); 1615 qApp->processEvents();
1604 if ( byteCount > byteMax ) { 1616 if ( byteCount > byteMax ) {
1605 byteCount = 0; 1617 byteCount = 0;
1606 mConnectProgress.setProgress( count ); 1618 mConnectProgress.setProgress( count );
1607 } 1619 }
1608 QString temp = ts2.readLine(); 1620 QString temp = ts2.readLine();
1609 count += temp.length(); 1621 count += temp.length();
1610 byteCount += temp.length(); 1622 byteCount += temp.length();
1611 os2 << temp << "\r\n"; 1623 os2 << temp << "\r\n";
1612 } 1624 }
1613 file2.close(); 1625 file2.close();
1614 mConnectProgress.hide(); 1626 mConnectProgress.hide();
1615 mConnectCount = -1; 1627 mConnectCount = -1;
1616 os2 << "\r\n"; 1628 os2 << "\r\n";
1617 mRetVal= successW; 1629 mRetVal= successW;
1618 mSocket->close(); 1630 mSocket->close();
1619 if ( mSocket->state() == QSocket::Idle ) 1631 if ( mSocket->state() == QSocket::Idle )
1620 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1632 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1621 mConnectProgress.blockSignals( false ); 1633 mConnectProgress.blockSignals( false );
1622} 1634}
1623void KCommandSocket::sendStop() 1635void KCommandSocket::sendStop()
1624{ 1636{
1625 if ( !mSocket ) { 1637 if ( !mSocket ) {
1626 mSocket = new QSocket( this ); 1638 mSocket = new QSocket( this );
1627 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1639 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1628 } 1640 }
1629 mSocket->connectToHost( mHost, mPort ); 1641 mSocket->connectToHost( mHost, mPort );
1630 QTextStream os2( mSocket ); 1642 QTextStream os2( mSocket );
1631 os2.setEncoding( QTextStream::Latin1 ); 1643 os2.setEncoding( QTextStream::Latin1 );
1632 os2 << "STOP\r\n\r\n"; 1644 os2 << "STOP\r\n\r\n";
1633 mSocket->close(); 1645 mSocket->close();
1634 if ( mSocket->state() == QSocket::Idle ) 1646 if ( mSocket->state() == QSocket::Idle )
1635 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1647 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1636} 1648}
1637 1649
1638void KCommandSocket::startReadFileFromSocket() 1650void KCommandSocket::startReadFileFromSocket()
1639{ 1651{
1640 if ( ! mFirst ) 1652 if ( ! mFirst )
1641 return; 1653 return;
1642 mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); 1654 mConnectProgress.setLabelText( i18n("Receiving file from remote...") );
1643 mFirst = false; 1655 mFirst = false;
1644 mFileString = ""; 1656 mFileString = "";
1645 mTime.start(); 1657 mTime.start();
1646 mFirstLine = true; 1658 mFirstLine = true;
1647 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1659 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1648 1660
1649} 1661}
1650void KCommandSocket::readFileFromSocket() 1662void KCommandSocket::readFileFromSocket()
1651{ 1663{
1652 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1664 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1653 while ( mSocket->canReadLine () ) { 1665 while ( mSocket->canReadLine () ) {
1654 mTime.restart(); 1666 mTime.restart();
1655 QString line = mSocket->readLine (); 1667 QString line = mSocket->readLine ();
1656 if ( mFirstLine ) { 1668 if ( mFirstLine ) {
1657 mFirstLine = false; 1669 mFirstLine = false;
1658 if ( line.left( 6 ) == "ERROR_" ) { 1670 if ( line.left( 6 ) == "ERROR_" ) {
1659 mTimerSocket->stop(); 1671 mTimerSocket->stop();
1660 mConnectCount = -1; 1672 mConnectCount = -1;
1661 if ( line.left( 8 ) == "ERROR_PW" ) { 1673 if ( line.left( 8 ) == "ERROR_PW" ) {
1662 mRetVal = errorPW; 1674 mRetVal = errorPW;
1663 deleteSocket(); 1675 deleteSocket();
1664 return ; 1676 return ;
1665 } 1677 }
1666 if ( line.left( 8 ) == "ERROR_CA" ) { 1678 if ( line.left( 8 ) == "ERROR_CA" ) {
1667 mRetVal = errorCA; 1679 mRetVal = errorCA;
1668 deleteSocket(); 1680 deleteSocket();
1669 return ; 1681 return ;
1670 } 1682 }
1671 if ( line.left( 8 ) == "ERROR_FI" ) { 1683 if ( line.left( 8 ) == "ERROR_FI" ) {
1672 mRetVal = errorFI; 1684 mRetVal = errorFI;
1673 deleteSocket(); 1685 deleteSocket();
1674 return ; 1686 return ;
1675 } 1687 }
1676 if ( line.left( 8 ) == "ERROR_ED" ) { 1688 if ( line.left( 8 ) == "ERROR_ED" ) {
1677 mRetVal = errorED; 1689 mRetVal = errorED;
1678 deleteSocket(); 1690 deleteSocket();
1679 return ; 1691 return ;
1680 } 1692 }
1681 mRetVal = errorUN; 1693 mRetVal = errorUN;
1682 deleteSocket(); 1694 deleteSocket();
1683 return ; 1695 return ;
1684 } 1696 }
1685 } 1697 }
1686 mFileString += line; 1698 mFileString += line;
1687 //qDebug("readline: %s ", line.latin1()); 1699 //qDebug("readline: %s ", line.latin1());
1688 } 1700 }
1689 if ( mTime.elapsed () < 3000 ) { 1701 if ( mTime.elapsed () < 3000 ) {
1690 // wait for more 1702 // wait for more
1691 //qDebug("waitformore "); 1703 //qDebug("waitformore ");
1692 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1704 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1693 return; 1705 return;
1694 } 1706 }
1695 mTimerSocket->stop(); 1707 mTimerSocket->stop();
1696 mConnectCount = -1; 1708 mConnectCount = -1;
1697 mConnectProgress.hide(); 1709 mConnectProgress.hide();
1698 QString fileName = mFileName; 1710 QString fileName = mFileName;
1699 QFile file ( fileName ); 1711 QFile file ( fileName );
1700 if (!file.open( IO_WriteOnly ) ) { 1712 if (!file.open( IO_WriteOnly ) ) {
1701 mFileString = ""; 1713 mFileString = "";
1702 mRetVal = errorR; 1714 mRetVal = errorR;
1703 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1715 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1704 deleteSocket(); 1716 deleteSocket();
1705 return ; 1717 return ;
1706 1718
1707 } 1719 }
1708 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1720 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1709 QTextStream ts ( &file ); 1721 QTextStream ts ( &file );
1710 ts.setEncoding( QTextStream::Latin1 ); 1722 ts.setEncoding( QTextStream::Latin1 );
1711 ts << mFileString; 1723 ts << mFileString;
1712 file.close(); 1724 file.close();
1713 mFileString = ""; 1725 mFileString = "";
1714 mRetVal = successR; 1726 mRetVal = successR;
1715 mSocket->close(); 1727 mSocket->close();
1716 // if state is not idle, deleteSocket(); is called via 1728 // if state is not idle, deleteSocket(); is called via
1717 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1729 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1718 if ( mSocket->state() == QSocket::Idle ) 1730 if ( mSocket->state() == QSocket::Idle )
1719 deleteSocket(); 1731 deleteSocket();
1720} 1732}
1721 1733
1722void KCommandSocket::deleteSocket() 1734void KCommandSocket::deleteSocket()
1723{ 1735{
1724 //qDebug("KCommandSocket::deleteSocket() "); 1736 //qDebug("KCommandSocket::deleteSocket() ");
1725 mConnectProgress.hide(); 1737 mConnectProgress.hide();
1726 1738
1727 if ( mConnectCount >= 0 ) { 1739 if ( mConnectCount >= 0 ) {
1728 mTimerSocket->stop(); 1740 mTimerSocket->stop();
1729 mRetVal = errorTO; 1741 mRetVal = errorTO;
1730 qDebug("KCS::Connection to remote host timed out"); 1742 qDebug("KCS::Connection to remote host timed out");
1731 if ( mSocket ) { 1743 if ( mSocket ) {
1732 mSocket->close(); 1744 mSocket->close();
1733 //if ( mSocket->state() == QSocket::Idle ) 1745 //if ( mSocket->state() == QSocket::Idle )
1734 // deleteSocket(); 1746 // deleteSocket();
1735 delete mSocket; 1747 delete mSocket;
1736 mSocket = 0; 1748 mSocket = 0;
1737 } 1749 }
1738 if ( mConnectCount == 0 ) 1750 if ( mConnectCount == 0 )
1739 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); 1751 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?"));
1740 else if ( tlw ) 1752 else if ( tlw )
1741 tlw->setCaption( i18n("Connection to remote host cancelled!") ); 1753 tlw->setCaption( i18n("Connection to remote host cancelled!") );
1742 emit commandFinished( this, mRetVal ); 1754 emit commandFinished( this, mRetVal );
1743 return; 1755 return;
1744 } 1756 }
1745 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1757 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1746 if ( mSocket) 1758 if ( mSocket)
1747 delete mSocket; 1759 delete mSocket;
1748 mSocket = 0; 1760 mSocket = 0;
1749 qDebug("commandFinished "); 1761 qDebug("commandFinished ");
1750 emit commandFinished( this, mRetVal ); 1762 emit commandFinished( this, mRetVal );
1751} 1763}