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