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