summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp274
1 files changed, 174 insertions, 100 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 52e3bd9..87f200a 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,455 +1,529 @@
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 26
26KSyncManager::KSyncManager(TargetApp ta, QPopupMenu* syncmenu) 27#ifndef _WIN32_
27 : mSyncMenu(syncmenu), mTargetApp(ta) 28#include <unistd.h>
29#endif
30
31
32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h"
35
36#include <qdir.h>
37#include <qpopupmenu.h>
38#include <qpushbutton.h>
39#include <qradiobutton.h>
40#include <qbuttongroup.h>
41#include <qtimer.h>
42#include <qmessagebox.h>
43#include <qapplication.h>
44#include <qlineedit.h>
45#include <qdialog.h>
46#include <qlayout.h>
47
48#include <klocale.h>
49#include <kglobal.h>
50#include <kconfig.h>
51#include <kfiledialog.h>
52
53KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
54 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs), mSyncMenu(syncmenu)
28{ 55{
29 56
30} 57}
31 58
32KSyncManager::~KSyncManager() 59KSyncManager::~KSyncManager()
33{ 60{
34 61
35} 62}
36 63
37 64
38void KABCore::fillSyncMenu() 65void KSyncManager::fillSyncMenu()
39{ 66{
40 if ( mSyncMenu->count() ) 67 if ( mSyncMenu->count() )
41 msyncMenu->clear(); 68 mSyncMenu->clear();
42 69
43 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 70 mSyncMenu->insertItem( i18n("Configure..."), 0 );
44 mSyncMenu->insertSeparator(); 71 mSyncMenu->insertSeparator();
45 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 72 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
46 mSyncMenu->insertSeparator(); 73 mSyncMenu->insertSeparator();
47 74
48 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 75 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
49 config.setGroup("General"); 76 config.setGroup("General");
50 QStringList prof = config.readListEntry("SyncProfileNames"); 77 QStringList prof = config.readListEntry("SyncProfileNames");
51 //US KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 78 mPrefs->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
52 if ( prof.count() < 3 ) { 79 if ( prof.count() < 3 ) {
53 prof.clear(); 80 prof.clear();
54 prof << i18n("Sharp_DTM"); 81 prof << i18n("Sharp_DTM");
55 prof << i18n("Local_file"); 82 prof << i18n("Local_file");
56 prof << i18n("Last_file"); 83 prof << i18n("Last_file");
57 KSyncProfile* temp = new KSyncProfile (); 84 KSyncProfile* temp = new KSyncProfile ();
58 temp->setName( prof[0] ); 85 temp->setName( prof[0] );
59 temp->writeConfig(&config); 86 temp->writeConfig(&config);
60 temp->setName( prof[1] ); 87 temp->setName( prof[1] );
61 temp->writeConfig(&config); 88 temp->writeConfig(&config);
62 temp->setName( prof[2] ); 89 temp->setName( prof[2] );
63 temp->writeConfig(&config); 90 temp->writeConfig(&config);
64 config.setGroup("General"); 91 config.setGroup("General");
65 config.writeEntry("SyncProfileNames",prof); 92 config.writeEntry("SyncProfileNames",prof);
66 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 93 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
67 config.sync(); 94 config.sync();
68 delete temp; 95 delete temp;
69 } 96 }
70 /*US 97 mPrefs->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
71 KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 98 mPrefs->mSyncProfileNames = prof;
72 KABPrefs::instance()->mSyncProfileNames = prof; 99 unsigned int i;
73 */
74 int i;
75 for ( i = 0; i < prof.count(); ++i ) { 100 for ( i = 0; i < prof.count(); ++i ) {
76 101
77 mSyncMenu->insertItem( prof[i], 1000+i ); 102 mSyncMenu->insertItem( prof[i], 1000+i );
78 if ( i == 2 ) 103 if ( i == 2 )
79 mSyncMenu->insertSeparator(); 104 mSyncMenu->insertSeparator();
80 } 105 }
81 QDir app_dir; 106 QDir app_dir;
82 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 107 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
83 mSyncMenu->setItemEnabled( false , 1000 ); 108 mSyncMenu->setItemEnabled( false , 1000 );
84 } 109 }
85 //probaly useless 110 //probaly useless
86 //mView->setupExternSyncProfiles(); 111 //mView->setupExternSyncProfiles();
87} 112}
88void KABCore::slotSyncMenu( int action ) 113
114void KSyncManager::slotSyncMenu( int action )
89{ 115{
90 //qDebug("syncaction %d ", action); 116 //qDebug("syncaction %d ", action);
91 if ( action == 0 ) { 117 if ( action == 0 ) {
92 118
93 // seems to be a Qt2 event handling bug 119 // seems to be a Qt2 event handling bug
94 // syncmenu.clear causes a segfault at first time 120 // syncmenu.clear causes a segfault at first time
95 // when we call it after the main event loop, it is ok 121 // when we call it after the main event loop, it is ok
96 // same behaviour when calling OM/Pi via QCOP for the first time 122 // same behaviour when calling OM/Pi via QCOP for the first time
97 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 123 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
98 //confSync(); 124 //confSync();
99 125
100 return; 126 return;
101 } 127 }
102 if ( action == 1 ) { 128 if ( action == 1 ) {
103 multiSync( true ); 129 multiSync( true );
104 return; 130 return;
105 } 131 }
106 132
107 if (mBlockSaveFlag) 133 if (blockSave())
108 return; 134 return;
109 mBlockSaveFlag = true; 135
136 setBlockSave(true);
137
110 mCurrentSyncProfile = action - 1000 ; 138 mCurrentSyncProfile = action - 1000 ;
111 //US mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; 139 mCurrentSyncDevice = mPrefs->mSyncProfileNames[mCurrentSyncProfile] ;
112 //US mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; 140 mCurrentSyncName = mPrefs->mLocalMachineName ;
113 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 141 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
114 KSyncProfile* temp = new KSyncProfile (); 142 KSyncProfile* temp = new KSyncProfile ();
115 //US temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 143 temp->setName(mPrefs->mSyncProfileNames[mCurrentSyncProfile]);
116 temp->readConfig(&config); 144 temp->readConfig(&config);
117 /*US 145 mPrefs->mAskForPreferences = temp->getAskForPreferences();
118 KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 146 mPrefs->mSyncAlgoPrefs = temp->getSyncPrefs();
119 KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 147 mPrefs->mWriteBackFile = temp->getWriteBackFile();
120 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 148 mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting();
121 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 149 mPrefs->mWriteBackInFuture = 0;
122 KABPrefs::instance()->mWriteBackInFuture = 0;
123 if ( temp->getWriteBackFuture() ) 150 if ( temp->getWriteBackFuture() )
124 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 151 mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
125 KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 152 mPrefs->mShowSyncSummary = temp->getShowSummaryAfterSync();
126 */
127 if ( action == 1000 ) { 153 if ( action == 1000 ) {
128 syncSharp(); 154 syncSharp();
129 155
130 } else if ( action == 1001 ) { 156 } else if ( action == 1001 ) {
131 syncLocalFile(); 157 syncLocalFile();
132 158
133 } else if ( action == 1002 ) { 159 } else if ( action == 1002 ) {
134 quickSyncLocalFile(); 160 quickSyncLocalFile();
135 161
136 } else if ( action >= 1003 ) { 162 } else if ( action >= 1003 ) {
137 if ( temp->getIsLocalFileSync() ) { 163 if ( temp->getIsLocalFileSync() ) {
138 /*US if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 164 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
139 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 165 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
140 */ 166
141 } else { 167 } else {
142 if ( temp->getIsPhoneSync() ) { 168 if ( temp->getIsPhoneSync() ) {
143 /* 169 mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ;
144 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 170 mPrefs->mPhoneConnection = temp->getPhoneConnection( );
145 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 171 mPrefs->mPhoneModel = temp->getPhoneModel( );
146 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
147 */
148 syncPhone(); 172 syncPhone();
149 } else 173 } else
150 syncRemote( temp ); 174 syncRemote( temp );
151 175
152 } 176 }
153 } 177 }
154 delete temp; 178 delete temp;
155 mBlockSaveFlag = false; 179 setBlockSave(false);
156} 180}
157 181
158void KABCore::syncLocalFile() 182void KSyncManager::syncLocalFile()
159{ 183{
160 184
161 QString fn =KABPrefs::instance()->mLastSyncedLocalFile; 185 QString fn =mPrefs->mLastSyncedLocalFile;
162 186
163 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 187 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), mParent );
164 if ( fn == "" ) 188 if ( fn == "" )
165 return; 189 return;
166 if ( syncWithFile( fn, false ) ) { 190 if ( syncWithFile( fn, false ) ) {
167 qDebug("syncLocalFile() successful "); 191 qDebug("syncLocalFile() successful ");
168 } 192 }
169 193
170} 194}
171bool KABCore::syncWithFile( QString fn , bool quick ) 195bool KSyncManager::syncWithFile( QString fn , bool quick )
172{ 196{
173 bool ret = false; 197 bool ret = false;
174 QFileInfo info; 198 QFileInfo info;
175 info.setFile( fn ); 199 info.setFile( fn );
176 QString mess; 200 QString mess;
177 bool loadbup = true; 201 bool loadbup = true;
178 if ( !info. exists() ) { 202 if ( !info. exists() ) {
179 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 203 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
180 int result = QMessageBox::warning( this, i18n("Warning!"), 204 int result = QMessageBox::warning( mParent, i18n("Warning!"),
181 mess ); 205 mess );
182 return ret; 206 return ret;
183 } 207 }
184 int result = 0; 208 int result = 0;
185 if ( !quick ) { 209 if ( !quick ) {
186 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 210 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
187 result = QMessageBox::warning( this, i18n("Warning!"), 211 result = QMessageBox::warning( mParent, i18n("Warning!"),
188 mess, 212 mess,
189 i18n("Sync"), i18n("Cancel"), 0, 213 i18n("Sync"), i18n("Cancel"), 0,
190 0, 1 ); 214 0, 1 );
191 if ( result ) 215 if ( result )
192 return false; 216 return false;
193 } 217 }
194 if ( KABPrefs::instance()->mAskForPreferences ) 218 if ( mPrefs->mAskForPreferences )
195 edit_sync_options(); 219 edit_sync_options();
196 if ( result == 0 ) { 220 if ( result == 0 ) {
197 //qDebug("Now sycing ... "); 221 //qDebug("Now sycing ... ");
198 if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) 222 if ( ret = mImplementation->sync( this, fn, mPrefs->mSyncAlgoPrefs ) )
199 setCaption( i18n("Synchronization successful") ); 223 mParent->setCaption( i18n("Synchronization successful") );
200 else 224 else
201 setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 225 mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
202 if ( ! quick ) 226 if ( ! quick )
203 KABPrefs::instance()->mLastSyncedLocalFile = fn; 227 mPrefs->mLastSyncedLocalFile = fn;
204 setModified(); 228 mImplementation->sync_setModified();
205 } 229 }
206 return ret; 230 return ret;
207} 231}
208void KABCore::quickSyncLocalFile() 232void KSyncManager::quickSyncLocalFile()
209{ 233{
210 234
211 if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { 235 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, false ) ) {
212 qDebug("quick syncLocalFile() successful "); 236 qDebug("quick syncLocalFile() successful ");
213 237
214 } 238 }
215} 239}
216void KABCore::multiSync( bool askforPrefs ) 240void KSyncManager::multiSync( bool askforPrefs )
217{ 241{
218 if (mBlockSaveFlag) 242 if (blockSave())
219 return; 243 return;
220 mBlockSaveFlag = true; 244 setBlockSave(true);
221 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 245 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
222 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 246 if ( QMessageBox::information( mParent, i18n("Sync"),
223 question, 247 question,
224 i18n("Yes"), i18n("No"), 248 i18n("Yes"), i18n("No"),
225 0, 0 ) != 0 ) { 249 0, 0 ) != 0 ) {
226 mBlockSaveFlag = false; 250 setBlockSave(false);
227 setCaption(i18n("Aborted! Nothing synced!")); 251 mParent->setCaption(i18n("Aborted! Nothing synced!"));
228 return; 252 return;
229 } 253 }
230 mCurrentSyncDevice = i18n("Multiple profiles") ; 254 mCurrentSyncDevice = i18n("Multiple profiles") ;
231 KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; 255 mPrefs->mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
232 if ( askforPrefs ) { 256 if ( askforPrefs ) {
233 edit_sync_options(); 257 edit_sync_options();
234 KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; 258 mPrefs->mRingSyncAlgoPrefs = mPrefs->mSyncAlgoPrefs;
235 } 259 }
236 setCaption(i18n("Multiple sync started.") ); 260 mParent->setCaption(i18n("Multiple sync started.") );
237 qApp->processEvents(); 261 qApp->processEvents();
238 int num = ringSync() ; 262 int num = ringSync() ;
239 if ( num > 1 ) 263 if ( num > 1 )
240 ringSync(); 264 ringSync();
241 mBlockSaveFlag = false; 265 setBlockSave(false);
242 if ( num ) 266 if ( num )
243 save(); 267 mImplementation->sync_save();
244 if ( num ) 268 if ( num )
245 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 269 mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
246 else 270 else
247 setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 271 mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
248 return; 272 return;
249} 273}
250int KABCore::ringSync() 274int KSyncManager::ringSync()
251{ 275{
252 int syncedProfiles = 0; 276 int syncedProfiles = 0;
253 int i; 277 unsigned int i;
254 QTime timer; 278 QTime timer;
255 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 279 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
256 QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; 280 QStringList syncProfileNames = mPrefs->mSyncProfileNames;
257 KSyncProfile* temp = new KSyncProfile (); 281 KSyncProfile* temp = new KSyncProfile ();
258 KABPrefs::instance()->mAskForPreferences = false; 282 mPrefs->mAskForPreferences = false;
259 for ( i = 0; i < syncProfileNames.count(); ++i ) { 283 for ( i = 0; i < syncProfileNames.count(); ++i ) {
260 mCurrentSyncProfile = i; 284 mCurrentSyncProfile = i;
261 temp->setName(syncProfileNames[mCurrentSyncProfile]); 285 temp->setName(syncProfileNames[mCurrentSyncProfile]);
262 temp->readConfig(&config); 286 temp->readConfig(&config);
263 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { 287 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) {
264 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 288 mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
265 ++syncedProfiles; 289 ++syncedProfiles;
266 // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 290 // mPrefs->mAskForPreferences = temp->getAskForPreferences();
267 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 291 mPrefs->mWriteBackFile = temp->getWriteBackFile();
268 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 292 mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting();
269 KABPrefs::instance()->mWriteBackInFuture = 0; 293 mPrefs->mWriteBackInFuture = 0;
270 if ( temp->getWriteBackFuture() ) 294 if ( temp->getWriteBackFuture() )
271 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 295 mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
272 KABPrefs::instance()->mShowSyncSummary = false; 296 mPrefs->mShowSyncSummary = false;
273 mCurrentSyncDevice = syncProfileNames[i] ; 297 mCurrentSyncDevice = syncProfileNames[i] ;
274 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; 298 mCurrentSyncName = mPrefs->mLocalMachineName;
275 if ( i == 0 ) { 299 if ( i == 0 ) {
276 syncSharp(); 300 syncSharp();
277 } else { 301 } else {
278 if ( temp->getIsLocalFileSync() ) { 302 if ( temp->getIsLocalFileSync() ) {
279 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) 303 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) )
280 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 304 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
281 } else { 305 } else {
282 if ( temp->getIsPhoneSync() ) { 306 if ( temp->getIsPhoneSync() ) {
283 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 307 mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ;
284 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 308 mPrefs->mPhoneConnection = temp->getPhoneConnection( );
285 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 309 mPrefs->mPhoneModel = temp->getPhoneModel( );
286 syncPhone(); 310 syncPhone();
287 } else 311 } else
288 syncRemote( temp, false ); 312 syncRemote( temp, false );
289 313
290 } 314 }
291 } 315 }
292 timer.start(); 316 timer.start();
293 setCaption(i18n("Multiple sync in progress ... please wait!") ); 317 mParent->setCaption(i18n("Multiple sync in progress ... please wait!") );
294 while ( timer.elapsed () < 2000 ) { 318 while ( timer.elapsed () < 2000 ) {
295 qApp->processEvents(); 319 qApp->processEvents();
296#ifndef _WIN32_ 320#ifndef _WIN32_
297 sleep (1); 321 sleep (1);
298#endif 322#endif
299 } 323 }
300 324
301 } 325 }
302 326
303 } 327 }
304 delete temp; 328 delete temp;
305 return syncedProfiles; 329 return syncedProfiles;
306} 330}
307 331
308void KABCore::syncRemote( KSyncProfile* prof, bool ask) 332void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
309{ 333{
310 QString question; 334 QString question;
311 if ( ask ) { 335 if ( ask ) {
312 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 336 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
313 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 337 if ( QMessageBox::information( mParent, i18n("Sync"),
314 question, 338 question,
315 i18n("Yes"), i18n("No"), 339 i18n("Yes"), i18n("No"),
316 0, 0 ) != 0 ) 340 0, 0 ) != 0 )
317 return; 341 return;
318 } 342 }
319 QString command = prof->getPreSyncCommandAB(); 343 QString command = prof->getPreSyncCommandAB();
320 int fi; 344 int fi;
321 if ( (fi = command.find("$PWD$")) > 0 ) { 345 if ( (fi = command.find("$PWD$")) > 0 ) {
322 QString pwd = getPassword(); 346 QString pwd = getPassword();
323 command = command.left( fi )+ pwd + command.mid( fi+5 ); 347 command = command.left( fi )+ pwd + command.mid( fi+5 );
324 348
325 } 349 }
326 int maxlen = 30; 350 int maxlen = 30;
327 if ( QApplication::desktop()->width() > 320 ) 351 if ( QApplication::desktop()->width() > 320 )
328 maxlen += 25; 352 maxlen += 25;
329 setCaption ( i18n( "Copy remote file to local machine..." ) ); 353 mParent->setCaption ( i18n( "Copy remote file to local machine..." ) );
330 int fileSize = 0; 354 int fileSize = 0;
331 int result = system ( command ); 355 int result = system ( command );
332 // 0 : okay 356 // 0 : okay
333 // 256: no such file or dir 357 // 256: no such file or dir
334 // 358 //
335 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 359 qDebug("KO: Remote copy result(0 = okay): %d ",result );
336 if ( result != 0 ) { 360 if ( result != 0 ) {
337 int len = maxlen; 361 unsigned int len = maxlen;
338 while ( len < command.length() ) { 362 while ( len < command.length() ) {
339 command.insert( len , "\n" ); 363 command.insert( len , "\n" );
340 len += maxlen +2; 364 len += maxlen +2;
341 } 365 }
342 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 (command) ; 366 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 (command) ;
343 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 367 QMessageBox::information( mParent, i18n("Sync - ERROR"),
344 question, 368 question,
345 i18n("Okay!")) ; 369 i18n("Okay!")) ;
346 setCaption ("KO/Pi"); 370 mParent->setCaption ("");
347 return; 371 return;
348 } 372 }
349 setCaption ( i18n( "Copying succeed." ) ); 373 mParent->setCaption ( i18n( "Copying succeed." ) );
350 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 374 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
351 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { 375 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
352// Event* e = mView->getLastSyncEvent(); 376// Event* e = mView->getLastSyncEvent();
353// e->setReadOnly( false ); 377// e->setReadOnly( false );
354// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 378// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
355// e->setReadOnly( true ); 379// e->setReadOnly( true );
356 if ( KABPrefs::instance()->mWriteBackFile ) { 380 if ( mPrefs->mWriteBackFile ) {
357 command = prof->getPostSyncCommandAB(); 381 command = prof->getPostSyncCommandAB();
358 int fi; 382 int fi;
359 if ( (fi = command.find("$PWD$")) > 0 ) { 383 if ( (fi = command.find("$PWD$")) > 0 ) {
360 QString pwd = getPassword(); 384 QString pwd = getPassword();
361 command = command.left( fi )+ pwd + command.mid( fi+5 ); 385 command = command.left( fi )+ pwd + command.mid( fi+5 );
362 386
363 } 387 }
364 setCaption ( i18n( "Writing back file ..." ) ); 388 mParent->setCaption ( i18n( "Writing back file ..." ) );
365 result = system ( command ); 389 result = system ( command );
366 qDebug("KO: Writing back file result: %d ", result); 390 qDebug("Writing back file result: %d ", result);
367 if ( result != 0 ) { 391 if ( result != 0 ) {
368 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 392 mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
369 return; 393 return;
370 } else { 394 } else {
371 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 395 mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) );
372 } 396 }
373 } 397 }
374 } 398 }
375 return; 399 return;
376} 400}
377#include <qpushbutton.h> 401
378#include <qradiobutton.h> 402void KSyncManager::edit_sync_options()
379#include <qbuttongroup.h>
380void KABCore::edit_sync_options()
381{ 403{
382 //mDialogManager->showSyncOptions(); 404 //mDialogManager->showSyncOptions();
383 //KABPrefs::instance()->mSyncAlgoPrefs 405 //mPrefs->mSyncAlgoPrefs
384 QDialog dia( this, "dia", true ); 406 QDialog dia( mParent, "dia", true );
385 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 407 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
386 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 408 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
387 QVBoxLayout lay ( &dia ); 409 QVBoxLayout lay ( &dia );
388 lay.setSpacing( 2 ); 410 lay.setSpacing( 2 );
389 lay.setMargin( 3 ); 411 lay.setMargin( 3 );
390 lay.addWidget(&gr); 412 lay.addWidget(&gr);
391 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 413 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
392 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 414 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
393 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 415 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
394 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 416 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
395 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 417 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
396 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 418 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
397 //QRadioButton both( i18n("Take both on conflict"), &gr ); 419 //QRadioButton both( i18n("Take both on conflict"), &gr );
398 QPushButton pb ( "OK", &dia); 420 QPushButton pb ( "OK", &dia);
399 lay.addWidget( &pb ); 421 lay.addWidget( &pb );
400 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 422 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
401 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { 423 switch ( mPrefs->mSyncAlgoPrefs ) {
402 case 0: 424 case 0:
403 loc.setChecked( true); 425 loc.setChecked( true);
404 break; 426 break;
405 case 1: 427 case 1:
406 rem.setChecked( true ); 428 rem.setChecked( true );
407 break; 429 break;
408 case 2: 430 case 2:
409 newest.setChecked( true); 431 newest.setChecked( true);
410 break; 432 break;
411 case 3: 433 case 3:
412 ask.setChecked( true); 434 ask.setChecked( true);
413 break; 435 break;
414 case 4: 436 case 4:
415 f_loc.setChecked( true); 437 f_loc.setChecked( true);
416 break; 438 break;
417 case 5: 439 case 5:
418 f_rem.setChecked( true); 440 f_rem.setChecked( true);
419 break; 441 break;
420 case 6: 442 case 6:
421 // both.setChecked( true); 443 // both.setChecked( true);
422 break; 444 break;
423 default: 445 default:
424 break; 446 break;
425 } 447 }
426 if ( dia.exec() ) { 448 if ( dia.exec() ) {
427 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 449 mPrefs->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
428 } 450 }
429 451
430 452
431} 453}
432QString KABCore::getPassword( ) 454QString KSyncManager::getPassword( )
433{ 455{
434 QString retfile = ""; 456 QString retfile = "";
435 QDialog dia ( this, "input-dialog", true ); 457 QDialog dia ( mParent, "input-dialog", true );
436 QLineEdit lab ( &dia ); 458 QLineEdit lab ( &dia );
437 lab.setEchoMode( QLineEdit::Password ); 459 lab.setEchoMode( QLineEdit::Password );
438 QVBoxLayout lay( &dia ); 460 QVBoxLayout lay( &dia );
439 lay.setMargin(7); 461 lay.setMargin(7);
440 lay.setSpacing(7); 462 lay.setSpacing(7);
441 lay.addWidget( &lab); 463 lay.addWidget( &lab);
442 dia.setFixedSize( 230,50 ); 464 dia.setFixedSize( 230,50 );
443 dia.setCaption( i18n("Enter password") ); 465 dia.setCaption( i18n("Enter password") );
444 QPushButton pb ( "OK", &dia); 466 QPushButton pb ( "OK", &dia);
445 lay.addWidget( &pb ); 467 lay.addWidget( &pb );
446 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 468 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
447 dia.show(); 469 dia.show();
448 int res = dia.exec(); 470 int res = dia.exec();
449 if ( res ) 471 if ( res )
450 retfile = lab.text(); 472 retfile = lab.text();
451 dia.hide(); 473 dia.hide();
452 qApp->processEvents(); 474 qApp->processEvents();
453 return retfile; 475 return retfile;
454 476
455} 477}
478
479
480void KSyncManager::confSync()
481{
482 static KSyncPrefsDialog* sp = 0;
483 if ( ! sp ) {
484 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
485 }
486 sp->usrReadConfig();
487#ifndef DESKTOP_VERSION
488 sp->showMaximized();
489#else
490 sp->show();
491#endif
492 sp->exec();
493 mPrefs->mSyncProfileNames = sp->getSyncProfileNames();
494 mPrefs->mLocalMachineName = sp->getLocalMachineName ();
495 fillSyncMenu();
496}
497
498void KSyncManager::syncSharp()
499{
500 if ( ! syncExternalApplication("sharp") )
501 qDebug("ERROR sync sharp ");;
502}
503
504bool KSyncManager::syncExternalApplication(QString resource)
505{
506 if ( mImplementation->sync_isModified() )
507 mImplementation->sync_save();
508
509 if ( mPrefs->mAskForPreferences )
510 edit_sync_options();
511
512 qDebug("sync %s", resource.latin1());
513
514 bool syncOK = mImplementation->syncExternal(this, resource);
515
516 return syncOK;
517
518}
519
520void KSyncManager::syncPhone()
521{
522 if ( mImplementation->sync_isModified() )
523 mImplementation->sync_save();
524
525 qDebug("pending syncPhone(); ");
526 //mView->syncPhone();
527 mImplementation->sync_setModified();
528
529}