summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 08b1a3d..80fb147 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,1210 +1,1214 @@
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 51
52#include <klocale.h> 52#include <klocale.h>
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kconfig.h> 54#include <kconfig.h>
55#include <kfiledialog.h> 55#include <kfiledialog.h>
56 56
57KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 57KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
58 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 58 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
59{ 59{
60 mServerSocket = 0; 60 mServerSocket = 0;
61 bar = new QProgressBar ( 1, 0 ); 61 bar = new QProgressBar ( 1, 0 );
62 bar->setCaption (""); 62 bar->setCaption ("");
63 63
64 int w = 300; 64 int w = 300;
65 if ( QApplication::desktop()->width() < 320 ) 65 if ( QApplication::desktop()->width() < 320 )
66 w = 220; 66 w = 220;
67 int h = bar->sizeHint().height() ; 67 int h = bar->sizeHint().height() ;
68 int dw = QApplication::desktop()->width(); 68 int dw = QApplication::desktop()->width();
69 int dh = QApplication::desktop()->height(); 69 int dh = QApplication::desktop()->height();
70 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 70 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
71 71
72} 72}
73 73
74KSyncManager::~KSyncManager() 74KSyncManager::~KSyncManager()
75{ 75{
76 delete bar; 76 delete bar;
77} 77}
78 78
79 79
80void KSyncManager::fillSyncMenu() 80void KSyncManager::fillSyncMenu()
81{ 81{
82 if ( mSyncMenu->count() ) 82 if ( mSyncMenu->count() )
83 mSyncMenu->clear(); 83 mSyncMenu->clear();
84 84
85 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 85 mSyncMenu->insertItem( i18n("Configure..."), 0 );
86 mSyncMenu->insertSeparator(); 86 mSyncMenu->insertSeparator();
87 if ( mServerSocket == 0 ) { 87 if ( mServerSocket == 0 ) {
88 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 88 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
89 } else { 89 } else {
90 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 90 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
91 } 91 }
92 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
93 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 93 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
94 mSyncMenu->insertSeparator(); 94 mSyncMenu->insertSeparator();
95 95
96 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 96 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
97 config.setGroup("General"); 97 config.setGroup("General");
98 QStringList prof = config.readListEntry("SyncProfileNames"); 98 QStringList prof = config.readListEntry("SyncProfileNames");
99 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 99 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
100 if ( prof.count() < 2 ) { 100 if ( prof.count() < 2 ) {
101 prof.clear(); 101 prof.clear();
102 prof << i18n("Sharp_DTM"); 102 prof << i18n("Sharp_DTM");
103 prof << i18n("Local_file"); 103 prof << i18n("Local_file");
104 prof << i18n("Last_file"); 104 prof << i18n("Last_file");
105 KSyncProfile* temp = new KSyncProfile (); 105 KSyncProfile* temp = new KSyncProfile ();
106 temp->setName( prof[0] ); 106 temp->setName( prof[0] );
107 temp->writeConfig(&config); 107 temp->writeConfig(&config);
108 temp->setName( prof[1] ); 108 temp->setName( prof[1] );
109 temp->writeConfig(&config); 109 temp->writeConfig(&config);
110 temp->setName( prof[2] ); 110 temp->setName( prof[2] );
111 temp->writeConfig(&config); 111 temp->writeConfig(&config);
112 config.setGroup("General"); 112 config.setGroup("General");
113 config.writeEntry("SyncProfileNames",prof); 113 config.writeEntry("SyncProfileNames",prof);
114 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 114 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
115 config.sync(); 115 config.sync();
116 delete temp; 116 delete temp;
117 } 117 }
118 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 118 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
119 mSyncProfileNames = prof; 119 mSyncProfileNames = prof;
120 unsigned int i; 120 unsigned int i;
121 for ( i = 0; i < prof.count(); ++i ) { 121 for ( i = 0; i < prof.count(); ++i ) {
122 mSyncMenu->insertItem( prof[i], 1000+i ); 122 mSyncMenu->insertItem( prof[i], 1000+i );
123 if ( i == 2 ) 123 if ( i == 2 )
124 mSyncMenu->insertSeparator(); 124 mSyncMenu->insertSeparator();
125 } 125 }
126 QDir app_dir; 126 QDir app_dir;
127 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 127 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
128 if ( mTargetApp == PWMPI) { 128 if ( mTargetApp == PWMPI) {
129 mSyncMenu->removeItem( 1000 ); 129 mSyncMenu->removeItem( 1000 );
130 } 130 }
131 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 131 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
132 mSyncMenu->removeItem( 1000 ); 132 mSyncMenu->removeItem( 1000 );
133 } 133 }
134 mSyncMenu->removeItem( 1002 ); 134 mSyncMenu->removeItem( 1002 );
135} 135}
136 136
137void KSyncManager::slotSyncMenu( int action ) 137void KSyncManager::slotSyncMenu( int action )
138{ 138{
139 //qDebug("syncaction %d ", action); 139 //qDebug("syncaction %d ", action);
140 if ( action == 0 ) { 140 if ( action == 0 ) {
141 141
142 // seems to be a Qt2 event handling bug 142 // seems to be a Qt2 event handling bug
143 // syncmenu.clear causes a segfault at first time 143 // syncmenu.clear causes a segfault at first time
144 // when we call it after the main event loop, it is ok 144 // when we call it after the main event loop, it is ok
145 // same behaviour when calling OM/Pi via QCOP for the first time 145 // same behaviour when calling OM/Pi via QCOP for the first time
146 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 146 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
147 //confSync(); 147 //confSync();
148 148
149 return; 149 return;
150 } 150 }
151 if ( action == 1 ) { 151 if ( action == 1 ) {
152 multiSync( true ); 152 multiSync( true );
153 return; 153 return;
154 } 154 }
155 if ( action == 2 ) { 155 if ( action == 2 ) {
156 enableQuick(); 156 enableQuick();
157 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 157 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
158 return; 158 return;
159 } 159 }
160 if ( action == 3 ) { 160 if ( action == 3 ) {
161 delete mServerSocket; 161 delete mServerSocket;
162 mServerSocket = 0; 162 mServerSocket = 0;
163 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 163 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
164 return; 164 return;
165 } 165 }
166 166
167 if (blockSave()) 167 if (blockSave())
168 return; 168 return;
169 169
170 setBlockSave(true); 170 setBlockSave(true);
171 171
172 mCurrentSyncProfile = action - 1000 ; 172 mCurrentSyncProfile = action - 1000 ;
173 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 173 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
174 mCurrentSyncName = mLocalMachineName ; 174 mCurrentSyncName = mLocalMachineName ;
175 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 175 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
176 KSyncProfile* temp = new KSyncProfile (); 176 KSyncProfile* temp = new KSyncProfile ();
177 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 177 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
178 temp->readConfig(&config); 178 temp->readConfig(&config);
179 mAskForPreferences = temp->getAskForPreferences(); 179 mAskForPreferences = temp->getAskForPreferences();
180 mSyncAlgoPrefs = temp->getSyncPrefs(); 180 mSyncAlgoPrefs = temp->getSyncPrefs();
181 mWriteBackFile = temp->getWriteBackFile(); 181 mWriteBackFile = temp->getWriteBackFile();
182 mWriteBackExistingOnly = temp->getWriteBackExisting(); 182 mWriteBackExistingOnly = temp->getWriteBackExisting();
183 mWriteBackInFuture = 0; 183 mWriteBackInFuture = 0;
184 if ( temp->getWriteBackFuture() ) 184 if ( temp->getWriteBackFuture() )
185 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 185 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
186 mShowSyncSummary = temp->getShowSummaryAfterSync(); 186 mShowSyncSummary = temp->getShowSummaryAfterSync();
187 if ( action == 1000 ) { 187 if ( action == 1000 ) {
188 syncSharp(); 188 syncSharp();
189 189
190 } else if ( action == 1001 ) { 190 } else if ( action == 1001 ) {
191 syncLocalFile(); 191 syncLocalFile();
192 192
193 } else if ( action == 1002 ) { 193 } else if ( action == 1002 ) {
194 mWriteBackFile = false;
195 mAskForPreferences = false;
196 mShowSyncSummary = false;
197 mSyncAlgoPrefs = 3;
194 quickSyncLocalFile(); 198 quickSyncLocalFile();
195 199
196 } else if ( action >= 1003 ) { 200 } else if ( action >= 1003 ) {
197 if ( temp->getIsLocalFileSync() ) { 201 if ( temp->getIsLocalFileSync() ) {
198 switch(mTargetApp) 202 switch(mTargetApp)
199 { 203 {
200 case (KAPI): 204 case (KAPI):
201 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 205 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
202 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 206 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
203 break; 207 break;
204 case (KOPI): 208 case (KOPI):
205 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 209 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
206 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 210 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
207 break; 211 break;
208 case (PWMPI): 212 case (PWMPI):
209 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 213 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
210 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 214 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
211 break; 215 break;
212 default: 216 default:
213 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 217 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
214 break; 218 break;
215 219
216 } 220 }
217 } else { 221 } else {
218 if ( temp->getIsPhoneSync() ) { 222 if ( temp->getIsPhoneSync() ) {
219 mPhoneDevice = temp->getPhoneDevice( ) ; 223 mPhoneDevice = temp->getPhoneDevice( ) ;
220 mPhoneConnection = temp->getPhoneConnection( ); 224 mPhoneConnection = temp->getPhoneConnection( );
221 mPhoneModel = temp->getPhoneModel( ); 225 mPhoneModel = temp->getPhoneModel( );
222 syncPhone(); 226 syncPhone();
223 } else if ( temp->getIsPiSync() ) { 227 } else if ( temp->getIsPiSync() ) {
224 if ( mTargetApp == KAPI ) { 228 if ( mTargetApp == KAPI ) {
225 mPassWordPiSync = temp->getRemotePwAB(); 229 mPassWordPiSync = temp->getRemotePwAB();
226 mActiveSyncPort = temp->getRemotePortAB(); 230 mActiveSyncPort = temp->getRemotePortAB();
227 mActiveSyncIP = temp->getRemoteIPAB(); 231 mActiveSyncIP = temp->getRemoteIPAB();
228 } else if ( mTargetApp == KOPI ) { 232 } else if ( mTargetApp == KOPI ) {
229 mPassWordPiSync = temp->getRemotePw(); 233 mPassWordPiSync = temp->getRemotePw();
230 mActiveSyncPort = temp->getRemotePort(); 234 mActiveSyncPort = temp->getRemotePort();
231 mActiveSyncIP = temp->getRemoteIP(); 235 mActiveSyncIP = temp->getRemoteIP();
232 } else { 236 } else {
233 mPassWordPiSync = temp->getRemotePwPWM(); 237 mPassWordPiSync = temp->getRemotePwPWM();
234 mActiveSyncPort = temp->getRemotePortPWM(); 238 mActiveSyncPort = temp->getRemotePortPWM();
235 mActiveSyncIP = temp->getRemoteIPPWM(); 239 mActiveSyncIP = temp->getRemoteIPPWM();
236 } 240 }
237 syncPi(); 241 syncPi();
238 } else 242 } else
239 syncRemote( temp ); 243 syncRemote( temp );
240 244
241 } 245 }
242 } 246 }
243 delete temp; 247 delete temp;
244 setBlockSave(false); 248 setBlockSave(false);
245} 249}
246 250
247void KSyncManager::enableQuick() 251void KSyncManager::enableQuick()
248{ 252{
249 QDialog dia ( 0, "input-dialog", true ); 253 QDialog dia ( 0, "input-dialog", true );
250 QLineEdit lab ( &dia ); 254 QLineEdit lab ( &dia );
251 QVBoxLayout lay( &dia ); 255 QVBoxLayout lay( &dia );
252 lab.setText( mPrefs->mPassiveSyncPort ); 256 lab.setText( mPrefs->mPassiveSyncPort );
253 lay.setMargin(7); 257 lay.setMargin(7);
254 lay.setSpacing(7); 258 lay.setSpacing(7);
255 int po = 9197+mTargetApp; 259 int po = 9197+mTargetApp;
256 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 260 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
257 lay.addWidget( &label); 261 lay.addWidget( &label);
258 lay.addWidget( &lab); 262 lay.addWidget( &lab);
259 263
260 QLineEdit lepw ( &dia ); 264 QLineEdit lepw ( &dia );
261 lepw.setText( mPrefs->mPassiveSyncPw ); 265 lepw.setText( mPrefs->mPassiveSyncPw );
262 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 266 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
263 lay.addWidget( &label2); 267 lay.addWidget( &label2);
264 lay.addWidget( &lepw); 268 lay.addWidget( &lepw);
265 dia.setFixedSize( 230,80 ); 269 dia.setFixedSize( 230,80 );
266 dia.setCaption( i18n("Enter port for Pi-Sync") ); 270 dia.setCaption( i18n("Enter port for Pi-Sync") );
267 QPushButton pb ( "OK", &dia); 271 QPushButton pb ( "OK", &dia);
268 lay.addWidget( &pb ); 272 lay.addWidget( &pb );
269 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 273 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
270 dia.show(); 274 dia.show();
271 if ( ! dia.exec() ) 275 if ( ! dia.exec() )
272 return; 276 return;
273 dia.hide(); 277 dia.hide();
274 qApp->processEvents(); 278 qApp->processEvents();
275 mPrefs->mPassiveSyncPw = lepw.text(); 279 mPrefs->mPassiveSyncPw = lepw.text();
276 mPrefs->mPassiveSyncPort = lab.text(); 280 mPrefs->mPassiveSyncPort = lab.text();
277 bool ok; 281 bool ok;
278 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 282 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
279 if ( ! ok ) { 283 if ( ! ok ) {
280 KMessageBox::information( 0, i18n("No valid port")); 284 KMessageBox::information( 0, i18n("No valid port"));
281 return; 285 return;
282 } 286 }
283 //qDebug("port %d ", port); 287 //qDebug("port %d ", port);
284 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 288 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
285 mServerSocket->setFileName( defaultFileName() ); 289 mServerSocket->setFileName( defaultFileName() );
286 //qDebug("connected "); 290 //qDebug("connected ");
287 if ( !mServerSocket->ok() ) { 291 if ( !mServerSocket->ok() ) {
288 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 292 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
289 delete mServerSocket; 293 delete mServerSocket;
290 mServerSocket = 0; 294 mServerSocket = 0;
291 return; 295 return;
292 } 296 }
293 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 297 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
294 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 298 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
295} 299}
296 300
297void KSyncManager::syncLocalFile() 301void KSyncManager::syncLocalFile()
298{ 302{
299 303
300 QString fn =mPrefs->mLastSyncedLocalFile; 304 QString fn =mPrefs->mLastSyncedLocalFile;
301 QString ext; 305 QString ext;
302 306
303 switch(mTargetApp) 307 switch(mTargetApp)
304 { 308 {
305 case (KAPI): 309 case (KAPI):
306 ext = "(*.vcf)"; 310 ext = "(*.vcf)";
307 break; 311 break;
308 case (KOPI): 312 case (KOPI):
309 ext = "(*.ics/*.vcs)"; 313 ext = "(*.ics/*.vcs)";
310 break; 314 break;
311 case (PWMPI): 315 case (PWMPI):
312 ext = "(*.pwm)"; 316 ext = "(*.pwm)";
313 break; 317 break;
314 default: 318 default:
315 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 319 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
316 break; 320 break;
317 321
318 } 322 }
319 323
320 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 324 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
321 if ( fn == "" ) 325 if ( fn == "" )
322 return; 326 return;
323 if ( syncWithFile( fn, false ) ) { 327 if ( syncWithFile( fn, false ) ) {
324 qDebug("syncLocalFile() successful "); 328 qDebug("syncLocalFile() successful ");
325 } 329 }
326 330
327} 331}
328 332
329bool KSyncManager::syncWithFile( QString fn , bool quick ) 333bool KSyncManager::syncWithFile( QString fn , bool quick )
330{ 334{
331 bool ret = false; 335 bool ret = false;
332 QFileInfo info; 336 QFileInfo info;
333 info.setFile( fn ); 337 info.setFile( fn );
334 QString mess; 338 QString mess;
335 bool loadbup = true; 339 bool loadbup = true;
336 if ( !info. exists() ) { 340 if ( !info. exists() ) {
337 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 341 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
338 int result = QMessageBox::warning( mParent, i18n("Warning!"), 342 int result = QMessageBox::warning( mParent, i18n("Warning!"),
339 mess ); 343 mess );
340 return ret; 344 return ret;
341 } 345 }
342 int result = 0; 346 int result = 0;
343 if ( !quick ) { 347 if ( !quick ) {
344 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 348 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
345 result = QMessageBox::warning( mParent, i18n("Warning!"), 349 result = QMessageBox::warning( mParent, i18n("Warning!"),
346 mess, 350 mess,
347 i18n("Sync"), i18n("Cancel"), 0, 351 i18n("Sync"), i18n("Cancel"), 0,
348 0, 1 ); 352 0, 1 );
349 if ( result ) 353 if ( result )
350 return false; 354 return false;
351 } 355 }
352 if ( mAskForPreferences ) 356 if ( mAskForPreferences )
353 edit_sync_options(); 357 edit_sync_options();
354 if ( result == 0 ) { 358 if ( result == 0 ) {
355 //qDebug("Now sycing ... "); 359 //qDebug("Now sycing ... ");
356 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 360 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
357 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 361 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
358 else 362 else
359 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 363 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
360 if ( ! quick ) 364 if ( ! quick )
361 mPrefs->mLastSyncedLocalFile = fn; 365 mPrefs->mLastSyncedLocalFile = fn;
362 } 366 }
363 return ret; 367 return ret;
364} 368}
365 369
366void KSyncManager::quickSyncLocalFile() 370void KSyncManager::quickSyncLocalFile()
367{ 371{
368 372
369 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, false ) ) { 373 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
370 qDebug("quick syncLocalFile() successful "); 374 qDebug("quick syncLocalFile() successful ");
371 375
372 } 376 }
373} 377}
374 378
375void KSyncManager::multiSync( bool askforPrefs ) 379void KSyncManager::multiSync( bool askforPrefs )
376{ 380{
377 if (blockSave()) 381 if (blockSave())
378 return; 382 return;
379 setBlockSave(true); 383 setBlockSave(true);
380 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 384 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
381 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 385 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
382 question, 386 question,
383 i18n("Yes"), i18n("No"), 387 i18n("Yes"), i18n("No"),
384 0, 0 ) != 0 ) { 388 0, 0 ) != 0 ) {
385 setBlockSave(false); 389 setBlockSave(false);
386 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 390 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
387 return; 391 return;
388 } 392 }
389 mCurrentSyncDevice = i18n("Multiple profiles") ; 393 mCurrentSyncDevice = i18n("Multiple profiles") ;
390 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 394 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
391 if ( askforPrefs ) { 395 if ( askforPrefs ) {
392 edit_sync_options(); 396 edit_sync_options();
393 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 397 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
394 } 398 }
395 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 399 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
396 qApp->processEvents(); 400 qApp->processEvents();
397 int num = ringSync() ; 401 int num = ringSync() ;
398 if ( num > 1 ) 402 if ( num > 1 )
399 ringSync(); 403 ringSync();
400 setBlockSave(false); 404 setBlockSave(false);
401 if ( num ) 405 if ( num )
402 emit save(); 406 emit save();
403 if ( num ) 407 if ( num )
404 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 408 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
405 else 409 else
406 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 410 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
407 return; 411 return;
408} 412}
409 413
410int KSyncManager::ringSync() 414int KSyncManager::ringSync()
411{ 415{
412 int syncedProfiles = 0; 416 int syncedProfiles = 0;
413 unsigned int i; 417 unsigned int i;
414 QTime timer; 418 QTime timer;
415 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 419 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
416 QStringList syncProfileNames = mSyncProfileNames; 420 QStringList syncProfileNames = mSyncProfileNames;
417 KSyncProfile* temp = new KSyncProfile (); 421 KSyncProfile* temp = new KSyncProfile ();
418 mAskForPreferences = false; 422 mAskForPreferences = false;
419 for ( i = 0; i < syncProfileNames.count(); ++i ) { 423 for ( i = 0; i < syncProfileNames.count(); ++i ) {
420 mCurrentSyncProfile = i; 424 mCurrentSyncProfile = i;
421 temp->setName(syncProfileNames[mCurrentSyncProfile]); 425 temp->setName(syncProfileNames[mCurrentSyncProfile]);
422 temp->readConfig(&config); 426 temp->readConfig(&config);
423 427
424 bool includeInRingSync; 428 bool includeInRingSync;
425 switch(mTargetApp) 429 switch(mTargetApp)
426 { 430 {
427 case (KAPI): 431 case (KAPI):
428 includeInRingSync = temp->getIncludeInRingSyncAB(); 432 includeInRingSync = temp->getIncludeInRingSyncAB();
429 break; 433 break;
430 case (KOPI): 434 case (KOPI):
431 includeInRingSync = temp->getIncludeInRingSync(); 435 includeInRingSync = temp->getIncludeInRingSync();
432 break; 436 break;
433 case (PWMPI): 437 case (PWMPI):
434 includeInRingSync = temp->getIncludeInRingSyncPWM(); 438 includeInRingSync = temp->getIncludeInRingSyncPWM();
435 break; 439 break;
436 default: 440 default:
437 qDebug("KSyncManager::ringSync: invalid apptype selected"); 441 qDebug("KSyncManager::ringSync: invalid apptype selected");
438 break; 442 break;
439 443
440 } 444 }
441 445
442 446
443 if ( includeInRingSync && ( i < 1 || i > 2 )) { 447 if ( includeInRingSync && ( i < 1 || i > 2 )) {
444 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 448 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
445 ++syncedProfiles; 449 ++syncedProfiles;
446 // mAskForPreferences = temp->getAskForPreferences(); 450 // mAskForPreferences = temp->getAskForPreferences();
447 mWriteBackFile = temp->getWriteBackFile(); 451 mWriteBackFile = temp->getWriteBackFile();
448 mWriteBackExistingOnly = temp->getWriteBackExisting(); 452 mWriteBackExistingOnly = temp->getWriteBackExisting();
449 mWriteBackInFuture = 0; 453 mWriteBackInFuture = 0;
450 if ( temp->getWriteBackFuture() ) 454 if ( temp->getWriteBackFuture() )
451 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 455 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
452 mShowSyncSummary = false; 456 mShowSyncSummary = false;
453 mCurrentSyncDevice = syncProfileNames[i] ; 457 mCurrentSyncDevice = syncProfileNames[i] ;
454 mCurrentSyncName = mLocalMachineName; 458 mCurrentSyncName = mLocalMachineName;
455 if ( i == 0 ) { 459 if ( i == 0 ) {
456 syncSharp(); 460 syncSharp();
457 } else { 461 } else {
458 if ( temp->getIsLocalFileSync() ) { 462 if ( temp->getIsLocalFileSync() ) {
459 switch(mTargetApp) 463 switch(mTargetApp)
460 { 464 {
461 case (KAPI): 465 case (KAPI):
462 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 466 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
463 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 467 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
464 break; 468 break;
465 case (KOPI): 469 case (KOPI):
466 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 470 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
467 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 471 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
468 break; 472 break;
469 case (PWMPI): 473 case (PWMPI):
470 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 474 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
471 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 475 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
472 break; 476 break;
473 default: 477 default:
474 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 478 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
475 break; 479 break;
476 } 480 }
477 } else { 481 } else {
478 if ( temp->getIsPhoneSync() ) { 482 if ( temp->getIsPhoneSync() ) {
479 mPhoneDevice = temp->getPhoneDevice( ) ; 483 mPhoneDevice = temp->getPhoneDevice( ) ;
480 mPhoneConnection = temp->getPhoneConnection( ); 484 mPhoneConnection = temp->getPhoneConnection( );
481 mPhoneModel = temp->getPhoneModel( ); 485 mPhoneModel = temp->getPhoneModel( );
482 syncPhone(); 486 syncPhone();
483 } else if ( temp->getIsPiSync() ) { 487 } else if ( temp->getIsPiSync() ) {
484 if ( mTargetApp == KAPI ) { 488 if ( mTargetApp == KAPI ) {
485 mPassWordPiSync = temp->getRemotePwAB(); 489 mPassWordPiSync = temp->getRemotePwAB();
486 mActiveSyncPort = temp->getRemotePortAB(); 490 mActiveSyncPort = temp->getRemotePortAB();
487 mActiveSyncIP = temp->getRemoteIPAB(); 491 mActiveSyncIP = temp->getRemoteIPAB();
488 } else if ( mTargetApp == KOPI ) { 492 } else if ( mTargetApp == KOPI ) {
489 mPassWordPiSync = temp->getRemotePw(); 493 mPassWordPiSync = temp->getRemotePw();
490 mActiveSyncPort = temp->getRemotePort(); 494 mActiveSyncPort = temp->getRemotePort();
491 mActiveSyncIP = temp->getRemoteIP(); 495 mActiveSyncIP = temp->getRemoteIP();
492 } else { 496 } else {
493 mPassWordPiSync = temp->getRemotePwPWM(); 497 mPassWordPiSync = temp->getRemotePwPWM();
494 mActiveSyncPort = temp->getRemotePortPWM(); 498 mActiveSyncPort = temp->getRemotePortPWM();
495 mActiveSyncIP = temp->getRemoteIPPWM(); 499 mActiveSyncIP = temp->getRemoteIPPWM();
496 } 500 }
497 syncPi(); 501 syncPi();
498 } else 502 } else
499 syncRemote( temp, false ); 503 syncRemote( temp, false );
500 504
501 } 505 }
502 } 506 }
503 timer.start(); 507 timer.start();
504 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 508 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
505 while ( timer.elapsed () < 2000 ) { 509 while ( timer.elapsed () < 2000 ) {
506 qApp->processEvents(); 510 qApp->processEvents();
507#ifndef _WIN32_ 511#ifndef _WIN32_
508 sleep (1); 512 sleep (1);
509#endif 513#endif
510 } 514 }
511 515
512 } 516 }
513 517
514 } 518 }
515 delete temp; 519 delete temp;
516 return syncedProfiles; 520 return syncedProfiles;
517} 521}
518 522
519void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 523void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
520{ 524{
521 QString question; 525 QString question;
522 if ( ask ) { 526 if ( ask ) {
523 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 527 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
524 if ( QMessageBox::information( mParent, i18n("Sync"), 528 if ( QMessageBox::information( mParent, i18n("Sync"),
525 question, 529 question,
526 i18n("Yes"), i18n("No"), 530 i18n("Yes"), i18n("No"),
527 0, 0 ) != 0 ) 531 0, 0 ) != 0 )
528 return; 532 return;
529 } 533 }
530 534
531 QString preCommand; 535 QString preCommand;
532 QString localTempFile; 536 QString localTempFile;
533 QString postCommand; 537 QString postCommand;
534 538
535 switch(mTargetApp) 539 switch(mTargetApp)
536 { 540 {
537 case (KAPI): 541 case (KAPI):
538 preCommand = prof->getPreSyncCommandAB(); 542 preCommand = prof->getPreSyncCommandAB();
539 postCommand = prof->getPostSyncCommandAB(); 543 postCommand = prof->getPostSyncCommandAB();
540 localTempFile = prof->getLocalTempFileAB(); 544 localTempFile = prof->getLocalTempFileAB();
541 break; 545 break;
542 case (KOPI): 546 case (KOPI):
543 preCommand = prof->getPreSyncCommand(); 547 preCommand = prof->getPreSyncCommand();
544 postCommand = prof->getPostSyncCommand(); 548 postCommand = prof->getPostSyncCommand();
545 localTempFile = prof->getLocalTempFile(); 549 localTempFile = prof->getLocalTempFile();
546 break; 550 break;
547 case (PWMPI): 551 case (PWMPI):
548 preCommand = prof->getPreSyncCommandPWM(); 552 preCommand = prof->getPreSyncCommandPWM();
549 postCommand = prof->getPostSyncCommandPWM(); 553 postCommand = prof->getPostSyncCommandPWM();
550 localTempFile = prof->getLocalTempFilePWM(); 554 localTempFile = prof->getLocalTempFilePWM();
551 break; 555 break;
552 default: 556 default:
553 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 557 qDebug("KSyncManager::syncRemote: invalid apptype selected");
554 break; 558 break;
555 } 559 }
556 560
557 561
558 int fi; 562 int fi;
559 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 563 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
560 QString pwd = getPassword(); 564 QString pwd = getPassword();
561 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 565 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
562 566
563 } 567 }
564 int maxlen = 30; 568 int maxlen = 30;
565 if ( QApplication::desktop()->width() > 320 ) 569 if ( QApplication::desktop()->width() > 320 )
566 maxlen += 25; 570 maxlen += 25;
567 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 571 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
568 int fileSize = 0; 572 int fileSize = 0;
569 int result = system ( preCommand ); 573 int result = system ( preCommand );
570 // 0 : okay 574 // 0 : okay
571 // 256: no such file or dir 575 // 256: no such file or dir
572 // 576 //
573 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 577 qDebug("KO: Remote copy result(0 = okay): %d ",result );
574 if ( result != 0 ) { 578 if ( result != 0 ) {
575 unsigned int len = maxlen; 579 unsigned int len = maxlen;
576 while ( len < preCommand.length() ) { 580 while ( len < preCommand.length() ) {
577 preCommand.insert( len , "\n" ); 581 preCommand.insert( len , "\n" );
578 len += maxlen +2; 582 len += maxlen +2;
579 } 583 }
580 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) ; 584 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) ;
581 QMessageBox::information( mParent, i18n("Sync - ERROR"), 585 QMessageBox::information( mParent, i18n("Sync - ERROR"),
582 question, 586 question,
583 i18n("Okay!")) ; 587 i18n("Okay!")) ;
584 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 588 mParent->topLevelWidget()->setCaption ("KDE-Pim");
585 return; 589 return;
586 } 590 }
587 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 591 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
588 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 592 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
589 593
590 if ( syncWithFile( localTempFile, true ) ) { 594 if ( syncWithFile( localTempFile, true ) ) {
591 595
592 if ( mWriteBackFile ) { 596 if ( mWriteBackFile ) {
593 int fi; 597 int fi;
594 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 598 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
595 QString pwd = getPassword(); 599 QString pwd = getPassword();
596 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 600 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
597 601
598 } 602 }
599 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 603 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
600 result = system ( postCommand ); 604 result = system ( postCommand );
601 qDebug("Writing back file result: %d ", result); 605 qDebug("Writing back file result: %d ", result);
602 if ( result != 0 ) { 606 if ( result != 0 ) {
603 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 607 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
604 return; 608 return;
605 } else { 609 } else {
606 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 610 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
607 } 611 }
608 } 612 }
609 } 613 }
610 return; 614 return;
611} 615}
612void KSyncManager::edit_pisync_options() 616void KSyncManager::edit_pisync_options()
613{ 617{
614 QDialog dia( mParent, "dia", true ); 618 QDialog dia( mParent, "dia", true );
615 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 619 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
616 QVBoxLayout lay ( &dia ); 620 QVBoxLayout lay ( &dia );
617 lay.setSpacing( 5 ); 621 lay.setSpacing( 5 );
618 lay.setMargin( 3 ); 622 lay.setMargin( 3 );
619 QLabel lab1 ( i18n("Password for remote access:"), &dia); 623 QLabel lab1 ( i18n("Password for remote access:"), &dia);
620 lay.addWidget( &lab1 ); 624 lay.addWidget( &lab1 );
621 QLineEdit le1 (&dia ); 625 QLineEdit le1 (&dia );
622 lay.addWidget( &le1 ); 626 lay.addWidget( &le1 );
623 QLabel lab2 ( i18n("Remote IP address:"), &dia); 627 QLabel lab2 ( i18n("Remote IP address:"), &dia);
624 lay.addWidget( &lab2 ); 628 lay.addWidget( &lab2 );
625 QLineEdit le2 (&dia ); 629 QLineEdit le2 (&dia );
626 lay.addWidget( &le2 ); 630 lay.addWidget( &le2 );
627 QLabel lab3 ( i18n("Remote port number:"), &dia); 631 QLabel lab3 ( i18n("Remote port number:"), &dia);
628 lay.addWidget( &lab3 ); 632 lay.addWidget( &lab3 );
629 QLineEdit le3 (&dia ); 633 QLineEdit le3 (&dia );
630 lay.addWidget( &le3 ); 634 lay.addWidget( &le3 );
631 QPushButton pb ( "OK", &dia); 635 QPushButton pb ( "OK", &dia);
632 lay.addWidget( &pb ); 636 lay.addWidget( &pb );
633 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 637 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
634 le1.setText( mPassWordPiSync ); 638 le1.setText( mPassWordPiSync );
635 le2.setText( mActiveSyncIP ); 639 le2.setText( mActiveSyncIP );
636 le3.setText( mActiveSyncPort ); 640 le3.setText( mActiveSyncPort );
637 if ( dia.exec() ) { 641 if ( dia.exec() ) {
638 mPassWordPiSync = le1.text(); 642 mPassWordPiSync = le1.text();
639 mActiveSyncPort = le3.text(); 643 mActiveSyncPort = le3.text();
640 mActiveSyncIP = le2.text(); 644 mActiveSyncIP = le2.text();
641 } 645 }
642 646
643} 647}
644void KSyncManager::edit_sync_options() 648void KSyncManager::edit_sync_options()
645{ 649{
646 650
647 QDialog dia( mParent, "dia", true ); 651 QDialog dia( mParent, "dia", true );
648 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 652 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
649 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 653 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
650 QVBoxLayout lay ( &dia ); 654 QVBoxLayout lay ( &dia );
651 lay.setSpacing( 2 ); 655 lay.setSpacing( 2 );
652 lay.setMargin( 3 ); 656 lay.setMargin( 3 );
653 lay.addWidget(&gr); 657 lay.addWidget(&gr);
654 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 658 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
655 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 659 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
656 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 660 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
657 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 661 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
658 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 662 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
659 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 663 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
660 //QRadioButton both( i18n("Take both on conflict"), &gr ); 664 //QRadioButton both( i18n("Take both on conflict"), &gr );
661 QPushButton pb ( "OK", &dia); 665 QPushButton pb ( "OK", &dia);
662 lay.addWidget( &pb ); 666 lay.addWidget( &pb );
663 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 667 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
664 switch ( mSyncAlgoPrefs ) { 668 switch ( mSyncAlgoPrefs ) {
665 case 0: 669 case 0:
666 loc.setChecked( true); 670 loc.setChecked( true);
667 break; 671 break;
668 case 1: 672 case 1:
669 rem.setChecked( true ); 673 rem.setChecked( true );
670 break; 674 break;
671 case 2: 675 case 2:
672 newest.setChecked( true); 676 newest.setChecked( true);
673 break; 677 break;
674 case 3: 678 case 3:
675 ask.setChecked( true); 679 ask.setChecked( true);
676 break; 680 break;
677 case 4: 681 case 4:
678 f_loc.setChecked( true); 682 f_loc.setChecked( true);
679 break; 683 break;
680 case 5: 684 case 5:
681 f_rem.setChecked( true); 685 f_rem.setChecked( true);
682 break; 686 break;
683 case 6: 687 case 6:
684 // both.setChecked( true); 688 // both.setChecked( true);
685 break; 689 break;
686 default: 690 default:
687 break; 691 break;
688 } 692 }
689 if ( dia.exec() ) { 693 if ( dia.exec() ) {
690 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 694 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
691 } 695 }
692 696
693 697
694} 698}
695 699
696QString KSyncManager::getPassword( ) 700QString KSyncManager::getPassword( )
697{ 701{
698 QString retfile = ""; 702 QString retfile = "";
699 QDialog dia ( mParent, "input-dialog", true ); 703 QDialog dia ( mParent, "input-dialog", true );
700 QLineEdit lab ( &dia ); 704 QLineEdit lab ( &dia );
701 lab.setEchoMode( QLineEdit::Password ); 705 lab.setEchoMode( QLineEdit::Password );
702 QVBoxLayout lay( &dia ); 706 QVBoxLayout lay( &dia );
703 lay.setMargin(7); 707 lay.setMargin(7);
704 lay.setSpacing(7); 708 lay.setSpacing(7);
705 lay.addWidget( &lab); 709 lay.addWidget( &lab);
706 dia.setFixedSize( 230,50 ); 710 dia.setFixedSize( 230,50 );
707 dia.setCaption( i18n("Enter password") ); 711 dia.setCaption( i18n("Enter password") );
708 QPushButton pb ( "OK", &dia); 712 QPushButton pb ( "OK", &dia);
709 lay.addWidget( &pb ); 713 lay.addWidget( &pb );
710 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 714 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
711 dia.show(); 715 dia.show();
712 int res = dia.exec(); 716 int res = dia.exec();
713 if ( res ) 717 if ( res )
714 retfile = lab.text(); 718 retfile = lab.text();
715 dia.hide(); 719 dia.hide();
716 qApp->processEvents(); 720 qApp->processEvents();
717 return retfile; 721 return retfile;
718 722
719} 723}
720 724
721 725
722void KSyncManager::confSync() 726void KSyncManager::confSync()
723{ 727{
724 static KSyncPrefsDialog* sp = 0; 728 static KSyncPrefsDialog* sp = 0;
725 if ( ! sp ) { 729 if ( ! sp ) {
726 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 730 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
727 } 731 }
728 sp->usrReadConfig(); 732 sp->usrReadConfig();
729#ifndef DESKTOP_VERSION 733#ifndef DESKTOP_VERSION
730 sp->showMaximized(); 734 sp->showMaximized();
731#else 735#else
732 sp->show(); 736 sp->show();
733#endif 737#endif
734 sp->exec(); 738 sp->exec();
735 mSyncProfileNames = sp->getSyncProfileNames(); 739 mSyncProfileNames = sp->getSyncProfileNames();
736 mLocalMachineName = sp->getLocalMachineName (); 740 mLocalMachineName = sp->getLocalMachineName ();
737 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 741 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
738} 742}
739 743
740void KSyncManager::syncSharp() 744void KSyncManager::syncSharp()
741{ 745{
742 746
743 if ( ! syncExternalApplication("sharp") ) 747 if ( ! syncExternalApplication("sharp") )
744 qDebug("ERROR sync sharp ");; 748 qDebug("ERROR sync sharp ");;
745} 749}
746 750
747bool KSyncManager::syncExternalApplication(QString resource) 751bool KSyncManager::syncExternalApplication(QString resource)
748{ 752{
749 753
750 emit save(); 754 emit save();
751 755
752 if ( mAskForPreferences ) 756 if ( mAskForPreferences )
753 edit_sync_options(); 757 edit_sync_options();
754 758
755 qDebug("sync %s", resource.latin1()); 759 qDebug("sync %s", resource.latin1());
756 760
757 bool syncOK = mImplementation->syncExternal(this, resource); 761 bool syncOK = mImplementation->syncExternal(this, resource);
758 762
759 return syncOK; 763 return syncOK;
760 764
761} 765}
762 766
763void KSyncManager::syncPhone() 767void KSyncManager::syncPhone()
764{ 768{
765 769
766 syncExternalApplication("phone"); 770 syncExternalApplication("phone");
767 771
768} 772}
769 773
770void KSyncManager::showProgressBar(int percentage, QString caption, int total) 774void KSyncManager::showProgressBar(int percentage, QString caption, int total)
771{ 775{
772 if (!bar->isVisible()) 776 if (!bar->isVisible())
773 { 777 {
774 bar->setCaption (caption); 778 bar->setCaption (caption);
775 bar->setTotalSteps ( total ) ; 779 bar->setTotalSteps ( total ) ;
776 780
777 bar->show(); 781 bar->show();
778 } 782 }
779 783
780 bar->setProgress( percentage ); 784 bar->setProgress( percentage );
781} 785}
782 786
783void KSyncManager::hideProgressBar() 787void KSyncManager::hideProgressBar()
784{ 788{
785 bar->hide(); 789 bar->hide();
786} 790}
787 791
788bool KSyncManager::isProgressBarCanceled() 792bool KSyncManager::isProgressBarCanceled()
789{ 793{
790 return !bar->isVisible(); 794 return !bar->isVisible();
791} 795}
792 796
793QString KSyncManager::syncFileName() 797QString KSyncManager::syncFileName()
794{ 798{
795 799
796 QString fn = "tempfile"; 800 QString fn = "tempfile";
797 switch(mTargetApp) 801 switch(mTargetApp)
798 { 802 {
799 case (KAPI): 803 case (KAPI):
800 fn = "tempsyncab.vcf"; 804 fn = "tempsyncab.vcf";
801 break; 805 break;
802 case (KOPI): 806 case (KOPI):
803 fn = "tempsynccal.ics"; 807 fn = "tempsynccal.ics";
804 break; 808 break;
805 case (PWMPI): 809 case (PWMPI):
806 fn = "tempsyncpw.pwm"; 810 fn = "tempsyncpw.pwm";
807 break; 811 break;
808 default: 812 default:
809 break; 813 break;
810 } 814 }
811#ifdef _WIN32_ 815#ifdef _WIN32_
812 return locateLocal( "tmp", fn ); 816 return locateLocal( "tmp", fn );
813#else 817#else
814 return (QString( "/tmp/" )+ fn ); 818 return (QString( "/tmp/" )+ fn );
815#endif 819#endif
816} 820}
817 821
818void KSyncManager::syncPi() 822void KSyncManager::syncPi()
819{ 823{
820 qApp->processEvents(); 824 qApp->processEvents();
821 if ( mAskForPreferences ) 825 if ( mAskForPreferences )
822 edit_pisync_options(); 826 edit_pisync_options();
823 bool ok; 827 bool ok;
824 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 828 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
825 if ( ! ok ) { 829 if ( ! ok ) {
826 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 830 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
827 return; 831 return;
828 } 832 }
829 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 833 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
830 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 834 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
831 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 835 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
832 commandSocket->readFile( syncFileName() ); 836 commandSocket->readFile( syncFileName() );
833} 837}
834 838
835void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 839void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
836{ 840{
837 qDebug("MainWindow::deleteCommandSocket %d", state); 841 qDebug("MainWindow::deleteCommandSocket %d", state);
838 842
839 //enum { success, errorW, errorR, quiet }; 843 //enum { success, errorW, errorR, quiet };
840 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 844 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
841 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 845 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
842 delete s; 846 delete s;
843 if ( state == KCommandSocket::errorR ) { 847 if ( state == KCommandSocket::errorR ) {
844 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 848 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
845 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 849 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
846 commandSocket->sendStop(); 850 commandSocket->sendStop();
847 } 851 }
848 return; 852 return;
849 853
850 } else if ( state == KCommandSocket::errorW ) { 854 } else if ( state == KCommandSocket::errorW ) {
851 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 855 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
852 856
853 } else if ( state == KCommandSocket::successR ) { 857 } else if ( state == KCommandSocket::successR ) {
854 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 858 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
855 859
856 } else if ( state == KCommandSocket::successW ) { 860 } else if ( state == KCommandSocket::successW ) {
857 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 861 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
858 } 862 }
859 863
860 delete s; 864 delete s;
861} 865}
862 866
863void KSyncManager::readFileFromSocket() 867void KSyncManager::readFileFromSocket()
864{ 868{
865 QString fileName = syncFileName(); 869 QString fileName = syncFileName();
866 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 870 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
867 if ( ! syncWithFile( fileName , true ) ) { 871 if ( ! syncWithFile( fileName , true ) ) {
868 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 872 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
869 qDebug("Syncing failed "); 873 qDebug("Syncing failed ");
870 return; 874 return;
871 } 875 }
872 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 876 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
873 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 877 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
874 if ( mWriteBackFile ) 878 if ( mWriteBackFile )
875 commandSocket->writeFile( fileName ); 879 commandSocket->writeFile( fileName );
876 else { 880 else {
877 commandSocket->sendStop(); 881 commandSocket->sendStop();
878 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 882 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
879 } 883 }
880} 884}
881 885
882KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 886KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
883{ 887{
884 mPassWord = pw; 888 mPassWord = pw;
885 mSocket = 0; 889 mSocket = 0;
886 mSyncActionDialog = 0; 890 mSyncActionDialog = 0;
887 blockRC = false; 891 blockRC = false;
888}; 892};
889 893
890void KServerSocket::newConnection ( int socket ) 894void KServerSocket::newConnection ( int socket )
891{ 895{
892 // qDebug("KServerSocket:New connection %d ", socket); 896 // qDebug("KServerSocket:New connection %d ", socket);
893 if ( mSocket ) { 897 if ( mSocket ) {
894 qDebug("KServerSocket::newConnection Socket deleted! "); 898 qDebug("KServerSocket::newConnection Socket deleted! ");
895 delete mSocket; 899 delete mSocket;
896 mSocket = 0; 900 mSocket = 0;
897 } 901 }
898 mSocket = new QSocket( this ); 902 mSocket = new QSocket( this );
899 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 903 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
900 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 904 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
901 mSocket->setSocket( socket ); 905 mSocket->setSocket( socket );
902} 906}
903 907
904void KServerSocket::discardClient() 908void KServerSocket::discardClient()
905{ 909{
906 //qDebug(" KServerSocket::discardClient()"); 910 //qDebug(" KServerSocket::discardClient()");
907 if ( mSocket ) { 911 if ( mSocket ) {
908 delete mSocket; 912 delete mSocket;
909 mSocket = 0; 913 mSocket = 0;
910 } 914 }
911 //emit endConnect(); 915 //emit endConnect();
912} 916}
913void KServerSocket::readClient() 917void KServerSocket::readClient()
914{ 918{
915 if ( blockRC ) 919 if ( blockRC )
916 return; 920 return;
917 if ( mSocket == 0 ) { 921 if ( mSocket == 0 ) {
918 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 922 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
919 return; 923 return;
920 } 924 }
921 qDebug("KServerSocket readClient()"); 925 qDebug("KServerSocket readClient()");
922 if ( mSocket->canReadLine() ) { 926 if ( mSocket->canReadLine() ) {
923 QString line = mSocket->readLine(); 927 QString line = mSocket->readLine();
924 qDebug("KServerSocket readline: %s ", line.latin1()); 928 qDebug("KServerSocket readline: %s ", line.latin1());
925 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 929 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
926 if ( tokens[0] == "GET" ) { 930 if ( tokens[0] == "GET" ) {
927 if ( tokens[1] == mPassWord ) 931 if ( tokens[1] == mPassWord )
928 //emit sendFile( mSocket ); 932 //emit sendFile( mSocket );
929 send_file(); 933 send_file();
930 else { 934 else {
931 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 935 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
932 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 936 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
933 } 937 }
934 } 938 }
935 if ( tokens[0] == "PUT" ) { 939 if ( tokens[0] == "PUT" ) {
936 if ( tokens[1] == mPassWord ) { 940 if ( tokens[1] == mPassWord ) {
937 //emit getFile( mSocket ); 941 //emit getFile( mSocket );
938 blockRC = true; 942 blockRC = true;
939 get_file(); 943 get_file();
940 } 944 }
941 else { 945 else {
942 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 946 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
943 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 947 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
944 } 948 }
945 } 949 }
946 if ( tokens[0] == "STOP" ) { 950 if ( tokens[0] == "STOP" ) {
947 //emit endConnect(); 951 //emit endConnect();
948 end_connect(); 952 end_connect();
949 } 953 }
950 } 954 }
951} 955}
952void KServerSocket::end_connect() 956void KServerSocket::end_connect()
953{ 957{
954 delete mSyncActionDialog; 958 delete mSyncActionDialog;
955 mSyncActionDialog = 0; 959 mSyncActionDialog = 0;
956} 960}
957void KServerSocket::send_file() 961void KServerSocket::send_file()
958{ 962{
959 //qDebug("MainWindow::sendFile(QSocket* s) "); 963 //qDebug("MainWindow::sendFile(QSocket* s) ");
960 if ( mSyncActionDialog ) 964 if ( mSyncActionDialog )
961 delete mSyncActionDialog; 965 delete mSyncActionDialog;
962 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 966 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
963 mSyncActionDialog->setCaption(i18n("Received sync request")); 967 mSyncActionDialog->setCaption(i18n("Received sync request"));
964 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 968 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
965 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 969 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
966 lay->addWidget( label); 970 lay->addWidget( label);
967 lay->setMargin(7); 971 lay->setMargin(7);
968 lay->setSpacing(7); 972 lay->setSpacing(7);
969 mSyncActionDialog->setFixedSize( 230, 120); 973 mSyncActionDialog->setFixedSize( 230, 120);
970 mSyncActionDialog->show(); 974 mSyncActionDialog->show();
971 mSyncActionDialog->raise(); 975 mSyncActionDialog->raise();
972 qDebug("KSS::saving ... "); 976 qDebug("KSS::saving ... ");
973 emit request_file(); 977 emit request_file();
974 qApp->processEvents(); 978 qApp->processEvents();
975 QString fileName = mFileName; 979 QString fileName = mFileName;
976 QFile file( fileName ); 980 QFile file( fileName );
977 if (!file.open( IO_ReadOnly ) ) { 981 if (!file.open( IO_ReadOnly ) ) {
978 delete mSyncActionDialog; 982 delete mSyncActionDialog;
979 mSyncActionDialog = 0; 983 mSyncActionDialog = 0;
980 qDebug("KSS::error open file "); 984 qDebug("KSS::error open file ");
981 mSocket->close(); 985 mSocket->close();
982 if ( mSocket->state() == QSocket::Idle ) 986 if ( mSocket->state() == QSocket::Idle )
983 QTimer::singleShot( 10, this , SLOT ( discardClient())); 987 QTimer::singleShot( 10, this , SLOT ( discardClient()));
984 return ; 988 return ;
985 989
986 } 990 }
987 mSyncActionDialog->setCaption( i18n("Sending file...") ); 991 mSyncActionDialog->setCaption( i18n("Sending file...") );
988 QTextStream ts( &file ); 992 QTextStream ts( &file );
989 ts.setEncoding( QTextStream::Latin1 ); 993 ts.setEncoding( QTextStream::Latin1 );
990 994
991 QTextStream os( mSocket ); 995 QTextStream os( mSocket );
992 os.setEncoding( QTextStream::Latin1 ); 996 os.setEncoding( QTextStream::Latin1 );
993 while ( ! ts.atEnd() ) { 997 while ( ! ts.atEnd() ) {
994 os << ts.readLine() << "\n"; 998 os << ts.readLine() << "\n";
995 } 999 }
996 //os << ts.read(); 1000 //os << ts.read();
997 file.close(); 1001 file.close();
998 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1002 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
999 mSocket->close(); 1003 mSocket->close();
1000 if ( mSocket->state() == QSocket::Idle ) 1004 if ( mSocket->state() == QSocket::Idle )
1001 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1005 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1002} 1006}
1003void KServerSocket::get_file() 1007void KServerSocket::get_file()
1004{ 1008{
1005 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1009 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1006 1010
1007 piTime.start(); 1011 piTime.start();
1008 piFileString = ""; 1012 piFileString = "";
1009 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1013 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1010} 1014}
1011 1015
1012 1016
1013void KServerSocket::readBackFileFromSocket() 1017void KServerSocket::readBackFileFromSocket()
1014{ 1018{
1015 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1019 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1016 while ( mSocket->canReadLine () ) { 1020 while ( mSocket->canReadLine () ) {
1017 piTime.restart(); 1021 piTime.restart();
1018 QString line = mSocket->readLine (); 1022 QString line = mSocket->readLine ();
1019 piFileString += line; 1023 piFileString += line;
1020 //qDebug("readline: %s ", line.latin1()); 1024 //qDebug("readline: %s ", line.latin1());
1021 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1025 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1022 1026
1023 } 1027 }
1024 if ( piTime.elapsed () < 3000 ) { 1028 if ( piTime.elapsed () < 3000 ) {
1025 // wait for more 1029 // wait for more
1026 //qDebug("waitformore "); 1030 //qDebug("waitformore ");
1027 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1031 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1028 return; 1032 return;
1029 } 1033 }
1030 QString fileName = mFileName; 1034 QString fileName = mFileName;
1031 QFile file ( fileName ); 1035 QFile file ( fileName );
1032 if (!file.open( IO_WriteOnly ) ) { 1036 if (!file.open( IO_WriteOnly ) ) {
1033 delete mSyncActionDialog; 1037 delete mSyncActionDialog;
1034 mSyncActionDialog = 0; 1038 mSyncActionDialog = 0;
1035 qDebug("error open cal file "); 1039 qDebug("error open cal file ");
1036 piFileString = ""; 1040 piFileString = "";
1037 emit file_received( false ); 1041 emit file_received( false );
1038 blockRC = false; 1042 blockRC = false;
1039 return ; 1043 return ;
1040 1044
1041 } 1045 }
1042 1046
1043 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1047 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1044 QTextStream ts ( &file ); 1048 QTextStream ts ( &file );
1045 ts.setEncoding( QTextStream::Latin1 ); 1049 ts.setEncoding( QTextStream::Latin1 );
1046 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1050 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1047 ts << piFileString; 1051 ts << piFileString;
1048 mSocket->close(); 1052 mSocket->close();
1049 if ( mSocket->state() == QSocket::Idle ) 1053 if ( mSocket->state() == QSocket::Idle )
1050 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1054 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1051 file.close(); 1055 file.close();
1052 delete mSyncActionDialog; 1056 delete mSyncActionDialog;
1053 mSyncActionDialog = 0; 1057 mSyncActionDialog = 0;
1054 piFileString = ""; 1058 piFileString = "";
1055 blockRC = false; 1059 blockRC = false;
1056 emit file_received( true ); 1060 emit file_received( true );
1057 1061
1058} 1062}
1059 1063
1060KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1064KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1061{ 1065{
1062 mPassWord = password; 1066 mPassWord = password;
1063 mSocket = 0; 1067 mSocket = 0;
1064 mPort = port; 1068 mPort = port;
1065 mHost = host; 1069 mHost = host;
1066 1070
1067 mRetVal = quiet; 1071 mRetVal = quiet;
1068 mTimerSocket = new QTimer ( this ); 1072 mTimerSocket = new QTimer ( this );
1069 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1073 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1070} 1074}
1071void KCommandSocket::readFile( QString fn ) 1075void KCommandSocket::readFile( QString fn )
1072{ 1076{
1073 if ( !mSocket ) { 1077 if ( !mSocket ) {
1074 mSocket = new QSocket( this ); 1078 mSocket = new QSocket( this );
1075 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1079 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1076 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1080 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1077 } 1081 }
1078 mFileString = ""; 1082 mFileString = "";
1079 mFileName = fn; 1083 mFileName = fn;
1080 mFirst = true; 1084 mFirst = true;
1081 mSocket->connectToHost( mHost, mPort ); 1085 mSocket->connectToHost( mHost, mPort );
1082 QTextStream os( mSocket ); 1086 QTextStream os( mSocket );
1083 os.setEncoding( QTextStream::Latin1 ); 1087 os.setEncoding( QTextStream::Latin1 );
1084 os << "GET " << mPassWord << "\r\n"; 1088 os << "GET " << mPassWord << "\r\n";
1085 mTimerSocket->start( 10000 ); 1089 mTimerSocket->start( 10000 );
1086} 1090}
1087 1091
1088void KCommandSocket::writeFile( QString fileName ) 1092void KCommandSocket::writeFile( QString fileName )
1089{ 1093{
1090 if ( !mSocket ) { 1094 if ( !mSocket ) {
1091 mSocket = new QSocket( this ); 1095 mSocket = new QSocket( this );
1092 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1096 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1093 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1097 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1094 } 1098 }
1095 mFileName = fileName ; 1099 mFileName = fileName ;
1096 mSocket->connectToHost( mHost, mPort ); 1100 mSocket->connectToHost( mHost, mPort );
1097} 1101}
1098void KCommandSocket::writeFileToSocket() 1102void KCommandSocket::writeFileToSocket()
1099{ 1103{
1100 QFile file2( mFileName ); 1104 QFile file2( mFileName );
1101 if (!file2.open( IO_ReadOnly ) ) { 1105 if (!file2.open( IO_ReadOnly ) ) {
1102 mRetVal= errorW; 1106 mRetVal= errorW;
1103 mSocket->close(); 1107 mSocket->close();
1104 if ( mSocket->state() == QSocket::Idle ) 1108 if ( mSocket->state() == QSocket::Idle )
1105 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1109 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1106 return ; 1110 return ;
1107 } 1111 }
1108 QTextStream ts2( &file2 ); 1112 QTextStream ts2( &file2 );
1109 ts2.setEncoding( QTextStream::Latin1 ); 1113 ts2.setEncoding( QTextStream::Latin1 );
1110 QTextStream os2( mSocket ); 1114 QTextStream os2( mSocket );
1111 os2.setEncoding( QTextStream::Latin1 ); 1115 os2.setEncoding( QTextStream::Latin1 );
1112 os2 << "PUT " << mPassWord << "\r\n";; 1116 os2 << "PUT " << mPassWord << "\r\n";;
1113 while ( ! ts2.atEnd() ) { 1117 while ( ! ts2.atEnd() ) {
1114 os2 << ts2.readLine() << "\n"; 1118 os2 << ts2.readLine() << "\n";
1115 } 1119 }
1116 mRetVal= successW; 1120 mRetVal= successW;
1117 file2.close(); 1121 file2.close();
1118 mSocket->close(); 1122 mSocket->close();
1119 if ( mSocket->state() == QSocket::Idle ) 1123 if ( mSocket->state() == QSocket::Idle )
1120 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1124 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1121} 1125}
1122void KCommandSocket::sendStop() 1126void KCommandSocket::sendStop()
1123{ 1127{
1124 if ( !mSocket ) { 1128 if ( !mSocket ) {
1125 mSocket = new QSocket( this ); 1129 mSocket = new QSocket( this );
1126 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1130 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1127 } 1131 }
1128 mSocket->connectToHost( mHost, mPort ); 1132 mSocket->connectToHost( mHost, mPort );
1129 QTextStream os2( mSocket ); 1133 QTextStream os2( mSocket );
1130 os2.setEncoding( QTextStream::Latin1 ); 1134 os2.setEncoding( QTextStream::Latin1 );
1131 os2 << "STOP\r\n"; 1135 os2 << "STOP\r\n";
1132 mSocket->close(); 1136 mSocket->close();
1133 if ( mSocket->state() == QSocket::Idle ) 1137 if ( mSocket->state() == QSocket::Idle )
1134 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1138 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1135} 1139}
1136 1140
1137void KCommandSocket::startReadFileFromSocket() 1141void KCommandSocket::startReadFileFromSocket()
1138{ 1142{
1139 if ( ! mFirst ) 1143 if ( ! mFirst )
1140 return; 1144 return;
1141 mFirst = false; 1145 mFirst = false;
1142 mTimerSocket->stop(); 1146 mTimerSocket->stop();
1143 mFileString = ""; 1147 mFileString = "";
1144 mTime.start(); 1148 mTime.start();
1145 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1149 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1146 1150
1147} 1151}
1148void KCommandSocket::readFileFromSocket() 1152void KCommandSocket::readFileFromSocket()
1149{ 1153{
1150 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1154 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1151 while ( mSocket->canReadLine () ) { 1155 while ( mSocket->canReadLine () ) {
1152 mTime.restart(); 1156 mTime.restart();
1153 QString line = mSocket->readLine (); 1157 QString line = mSocket->readLine ();
1154 mFileString += line; 1158 mFileString += line;
1155 //qDebug("readline: %s ", line.latin1()); 1159 //qDebug("readline: %s ", line.latin1());
1156 } 1160 }
1157 if ( mTime.elapsed () < 3000 ) { 1161 if ( mTime.elapsed () < 3000 ) {
1158 // wait for more 1162 // wait for more
1159 //qDebug("waitformore "); 1163 //qDebug("waitformore ");
1160 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1164 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1161 return; 1165 return;
1162 } 1166 }
1163 QString fileName = mFileName; 1167 QString fileName = mFileName;
1164 QFile file ( fileName ); 1168 QFile file ( fileName );
1165 if (!file.open( IO_WriteOnly ) ) { 1169 if (!file.open( IO_WriteOnly ) ) {
1166 mFileString = ""; 1170 mFileString = "";
1167 mRetVal = errorR; 1171 mRetVal = errorR;
1168 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 1172 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
1169 deleteSocket(); 1173 deleteSocket();
1170 return ; 1174 return ;
1171 1175
1172 } 1176 }
1173 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1177 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1174 QTextStream ts ( &file ); 1178 QTextStream ts ( &file );
1175 ts.setEncoding( QTextStream::Latin1 ); 1179 ts.setEncoding( QTextStream::Latin1 );
1176 ts << mFileString; 1180 ts << mFileString;
1177 file.close(); 1181 file.close();
1178 mFileString = ""; 1182 mFileString = "";
1179 mRetVal = successR; 1183 mRetVal = successR;
1180 mSocket->close(); 1184 mSocket->close();
1181 // if state is not idle, deleteSocket(); is called via 1185 // if state is not idle, deleteSocket(); is called via
1182 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1186 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1183 if ( mSocket->state() == QSocket::Idle ) 1187 if ( mSocket->state() == QSocket::Idle )
1184 deleteSocket(); 1188 deleteSocket();
1185} 1189}
1186 1190
1187void KCommandSocket::deleteSocket() 1191void KCommandSocket::deleteSocket()
1188{ 1192{
1189 //qDebug("KCommandSocket::deleteSocket() "); 1193 //qDebug("KCommandSocket::deleteSocket() ");
1190 if ( mTimerSocket->isActive () ) { 1194 if ( mTimerSocket->isActive () ) {
1191 mTimerSocket->stop(); 1195 mTimerSocket->stop();
1192 mRetVal = errorTO; 1196 mRetVal = errorTO;
1193 qDebug("Connection to remote host timed out"); 1197 qDebug("Connection to remote host timed out");
1194 if ( mSocket ) { 1198 if ( mSocket ) {
1195 mSocket->close(); 1199 mSocket->close();
1196 //if ( mSocket->state() == QSocket::Idle ) 1200 //if ( mSocket->state() == QSocket::Idle )
1197 // deleteSocket(); 1201 // deleteSocket();
1198 delete mSocket; 1202 delete mSocket;
1199 mSocket = 0; 1203 mSocket = 0;
1200 } 1204 }
1201 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1205 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1202 emit commandFinished( this, mRetVal ); 1206 emit commandFinished( this, mRetVal );
1203 return; 1207 return;
1204 } 1208 }
1205 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1209 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1206 if ( mSocket) 1210 if ( mSocket)
1207 delete mSocket; 1211 delete mSocket;
1208 mSocket = 0; 1212 mSocket = 0;
1209 emit commandFinished( this, mRetVal ); 1213 emit commandFinished( this, mRetVal );
1210} 1214}