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