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