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