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