summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 6baa2ee..5175f94 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -55,256 +55,257 @@
55#include <kfiledialog.h> 55#include <kfiledialog.h>
56 56
57KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 57KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
58 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 58 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
59{ 59{
60 mServerSocket = 0; 60 mServerSocket = 0;
61 bar = new QProgressBar ( 1, 0 ); 61 bar = new QProgressBar ( 1, 0 );
62 bar->setCaption (""); 62 bar->setCaption ("");
63 63
64 int w = 300; 64 int w = 300;
65 if ( QApplication::desktop()->width() < 320 ) 65 if ( QApplication::desktop()->width() < 320 )
66 w = 220; 66 w = 220;
67 int h = bar->sizeHint().height() ; 67 int h = bar->sizeHint().height() ;
68 int dw = QApplication::desktop()->width(); 68 int dw = QApplication::desktop()->width();
69 int dh = QApplication::desktop()->height(); 69 int dh = QApplication::desktop()->height();
70 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 70 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
71 71
72} 72}
73 73
74KSyncManager::~KSyncManager() 74KSyncManager::~KSyncManager()
75{ 75{
76 delete bar; 76 delete bar;
77} 77}
78 78
79 79
80void KSyncManager::fillSyncMenu() 80void KSyncManager::fillSyncMenu()
81{ 81{
82 if ( mSyncMenu->count() ) 82 if ( mSyncMenu->count() )
83 mSyncMenu->clear(); 83 mSyncMenu->clear();
84 84
85 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 85 mSyncMenu->insertItem( i18n("Configure..."), 0 );
86 mSyncMenu->insertSeparator(); 86 mSyncMenu->insertSeparator();
87 if ( mServerSocket == 0 ) { 87 if ( mServerSocket == 0 ) {
88 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 88 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
89 } else { 89 } else {
90 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 90 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
91 } 91 }
92 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
93 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 93 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
94 mSyncMenu->insertSeparator(); 94 mSyncMenu->insertSeparator();
95 95
96 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 96 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
97 config.setGroup("General"); 97 config.setGroup("General");
98 QStringList prof = config.readListEntry("SyncProfileNames"); 98 QStringList prof = config.readListEntry("SyncProfileNames");
99 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 99 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
100 if ( prof.count() < 2 ) { 100 if ( prof.count() < 2 ) {
101 prof.clear(); 101 prof.clear();
102 prof << i18n("Sharp_DTM"); 102 prof << i18n("Sharp_DTM");
103 prof << i18n("Local_file"); 103 prof << i18n("Local_file");
104 prof << i18n("Last_file"); 104 prof << i18n("Last_file");
105 KSyncProfile* temp = new KSyncProfile (); 105 KSyncProfile* temp = new KSyncProfile ();
106 temp->setName( prof[0] ); 106 temp->setName( prof[0] );
107 temp->writeConfig(&config); 107 temp->writeConfig(&config);
108 temp->setName( prof[1] ); 108 temp->setName( prof[1] );
109 temp->writeConfig(&config); 109 temp->writeConfig(&config);
110 temp->setName( prof[2] ); 110 temp->setName( prof[2] );
111 temp->writeConfig(&config); 111 temp->writeConfig(&config);
112 config.setGroup("General"); 112 config.setGroup("General");
113 config.writeEntry("SyncProfileNames",prof); 113 config.writeEntry("SyncProfileNames",prof);
114 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 114 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
115 config.sync(); 115 config.sync();
116 delete temp; 116 delete temp;
117 } 117 }
118 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 118 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
119 mSyncProfileNames = prof; 119 mSyncProfileNames = prof;
120 unsigned int i; 120 unsigned int i;
121 for ( i = 0; i < prof.count(); ++i ) { 121 for ( i = 0; i < prof.count(); ++i ) {
122 mSyncMenu->insertItem( prof[i], 1000+i ); 122 mSyncMenu->insertItem( prof[i], 1000+i );
123 if ( i == 2 ) 123 if ( i == 2 )
124 mSyncMenu->insertSeparator(); 124 mSyncMenu->insertSeparator();
125 } 125 }
126 QDir app_dir; 126 QDir app_dir;
127 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 127 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
128 if ( mTargetApp == PWMPI) { 128 if ( mTargetApp == PWMPI) {
129 mSyncMenu->removeItem( 1000 ); 129 mSyncMenu->removeItem( 1000 );
130 } 130 }
131 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 131 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
132 mSyncMenu->removeItem( 1000 ); 132 mSyncMenu->removeItem( 1000 );
133 } 133 }
134 mSyncMenu->removeItem( 1002 ); 134 mSyncMenu->removeItem( 1002 );
135} 135}
136 136
137void KSyncManager::slotSyncMenu( int action ) 137void KSyncManager::slotSyncMenu( int action )
138{ 138{
139 //qDebug("syncaction %d ", action); 139 //qDebug("syncaction %d ", action);
140 if ( action == 0 ) { 140 if ( action == 0 ) {
141 141
142 // seems to be a Qt2 event handling bug 142 // seems to be a Qt2 event handling bug
143 // syncmenu.clear causes a segfault at first time 143 // syncmenu.clear causes a segfault at first time
144 // when we call it after the main event loop, it is ok 144 // when we call it after the main event loop, it is ok
145 // same behaviour when calling OM/Pi via QCOP for the first time 145 // same behaviour when calling OM/Pi via QCOP for the first time
146 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 146 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
147 //confSync(); 147 //confSync();
148 148
149 return; 149 return;
150 } 150 }
151 if ( action == 1 ) { 151 if ( action == 1 ) {
152 multiSync( true ); 152 multiSync( true );
153 return; 153 return;
154 } 154 }
155 if ( action == 2 ) { 155 if ( action == 2 ) {
156 enableQuick(); 156 enableQuick();
157 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 157 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
158 return; 158 return;
159 } 159 }
160 if ( action == 3 ) { 160 if ( action == 3 ) {
161 delete mServerSocket; 161 delete mServerSocket;
162 mServerSocket = 0; 162 mServerSocket = 0;
163 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 163 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
164 return; 164 return;
165 } 165 }
166 166
167 if (blockSave()) 167 if (blockSave())
168 return; 168 return;
169 169
170 setBlockSave(true); 170 setBlockSave(true);
171 171
172 mCurrentSyncProfile = action - 1000 ; 172 mCurrentSyncProfile = action - 1000 ;
173 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 173 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
174 mCurrentSyncName = mLocalMachineName ; 174 mCurrentSyncName = mLocalMachineName ;
175 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 175 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
176 KSyncProfile* temp = new KSyncProfile (); 176 KSyncProfile* temp = new KSyncProfile ();
177 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 177 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
178 temp->readConfig(&config); 178 temp->readConfig(&config);
179 mAskForPreferences = temp->getAskForPreferences(); 179 mAskForPreferences = temp->getAskForPreferences();
180 mSyncAlgoPrefs = temp->getSyncPrefs(); 180 mSyncAlgoPrefs = temp->getSyncPrefs();
181 mWriteBackFile = temp->getWriteBackFile(); 181 mWriteBackFile = temp->getWriteBackFile();
182 mWriteBackExistingOnly = temp->getWriteBackExisting(); 182 mWriteBackExistingOnly = temp->getWriteBackExisting();
183 mIsKapiFile = temp->getIsKapiFile();
183 mWriteBackInFuture = 0; 184 mWriteBackInFuture = 0;
184 if ( temp->getWriteBackFuture() ) 185 if ( temp->getWriteBackFuture() )
185 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 186 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
186 mShowSyncSummary = temp->getShowSummaryAfterSync(); 187 mShowSyncSummary = temp->getShowSummaryAfterSync();
187 if ( action == 1000 ) { 188 if ( action == 1000 ) {
188 syncSharp(); 189 syncSharp();
189 190
190 } else if ( action == 1001 ) { 191 } else if ( action == 1001 ) {
191 syncLocalFile(); 192 syncLocalFile();
192 193
193 } else if ( action == 1002 ) { 194 } else if ( action == 1002 ) {
194 mWriteBackFile = false; 195 mWriteBackFile = false;
195 mAskForPreferences = false; 196 mAskForPreferences = false;
196 mShowSyncSummary = false; 197 mShowSyncSummary = false;
197 mSyncAlgoPrefs = 3; 198 mSyncAlgoPrefs = 3;
198 quickSyncLocalFile(); 199 quickSyncLocalFile();
199 200
200 } else if ( action >= 1003 ) { 201 } else if ( action >= 1003 ) {
201 if ( temp->getIsLocalFileSync() ) { 202 if ( temp->getIsLocalFileSync() ) {
202 switch(mTargetApp) 203 switch(mTargetApp)
203 { 204 {
204 case (KAPI): 205 case (KAPI):
205 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 206 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
206 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 207 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
207 break; 208 break;
208 case (KOPI): 209 case (KOPI):
209 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 210 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
210 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 211 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
211 break; 212 break;
212 case (PWMPI): 213 case (PWMPI):
213 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 214 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
214 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 215 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
215 break; 216 break;
216 default: 217 default:
217 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 218 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
218 break; 219 break;
219 220
220 } 221 }
221 } else { 222 } else {
222 if ( temp->getIsPhoneSync() ) { 223 if ( temp->getIsPhoneSync() ) {
223 mPhoneDevice = temp->getPhoneDevice( ) ; 224 mPhoneDevice = temp->getPhoneDevice( ) ;
224 mPhoneConnection = temp->getPhoneConnection( ); 225 mPhoneConnection = temp->getPhoneConnection( );
225 mPhoneModel = temp->getPhoneModel( ); 226 mPhoneModel = temp->getPhoneModel( );
226 syncPhone(); 227 syncPhone();
227 } else if ( temp->getIsPiSync() ) { 228 } else if ( temp->getIsPiSync() ) {
228 if ( mTargetApp == KAPI ) { 229 if ( mTargetApp == KAPI ) {
229 mPassWordPiSync = temp->getRemotePwAB(); 230 mPassWordPiSync = temp->getRemotePwAB();
230 mActiveSyncPort = temp->getRemotePortAB(); 231 mActiveSyncPort = temp->getRemotePortAB();
231 mActiveSyncIP = temp->getRemoteIPAB(); 232 mActiveSyncIP = temp->getRemoteIPAB();
232 } else if ( mTargetApp == KOPI ) { 233 } else if ( mTargetApp == KOPI ) {
233 mPassWordPiSync = temp->getRemotePw(); 234 mPassWordPiSync = temp->getRemotePw();
234 mActiveSyncPort = temp->getRemotePort(); 235 mActiveSyncPort = temp->getRemotePort();
235 mActiveSyncIP = temp->getRemoteIP(); 236 mActiveSyncIP = temp->getRemoteIP();
236 } else { 237 } else {
237 mPassWordPiSync = temp->getRemotePwPWM(); 238 mPassWordPiSync = temp->getRemotePwPWM();
238 mActiveSyncPort = temp->getRemotePortPWM(); 239 mActiveSyncPort = temp->getRemotePortPWM();
239 mActiveSyncIP = temp->getRemoteIPPWM(); 240 mActiveSyncIP = temp->getRemoteIPPWM();
240 } 241 }
241 syncPi(); 242 syncPi();
242 } else 243 } else
243 syncRemote( temp ); 244 syncRemote( temp );
244 245
245 } 246 }
246 } 247 }
247 delete temp; 248 delete temp;
248 setBlockSave(false); 249 setBlockSave(false);
249} 250}
250 251
251void KSyncManager::enableQuick() 252void KSyncManager::enableQuick()
252{ 253{
253 QDialog dia ( 0, "input-dialog", true ); 254 QDialog dia ( 0, "input-dialog", true );
254 QLineEdit lab ( &dia ); 255 QLineEdit lab ( &dia );
255 QVBoxLayout lay( &dia ); 256 QVBoxLayout lay( &dia );
256 lab.setText( mPrefs->mPassiveSyncPort ); 257 lab.setText( mPrefs->mPassiveSyncPort );
257 lay.setMargin(7); 258 lay.setMargin(7);
258 lay.setSpacing(7); 259 lay.setSpacing(7);
259 int po = 9197+mTargetApp; 260 int po = 9197+mTargetApp;
260 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 261 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
261 lay.addWidget( &label); 262 lay.addWidget( &label);
262 lay.addWidget( &lab); 263 lay.addWidget( &lab);
263 264
264 QLineEdit lepw ( &dia ); 265 QLineEdit lepw ( &dia );
265 lepw.setText( mPrefs->mPassiveSyncPw ); 266 lepw.setText( mPrefs->mPassiveSyncPw );
266 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 267 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
267 lay.addWidget( &label2); 268 lay.addWidget( &label2);
268 lay.addWidget( &lepw); 269 lay.addWidget( &lepw);
269 dia.setFixedSize( 230,80 ); 270 dia.setFixedSize( 230,80 );
270 dia.setCaption( i18n("Enter port for Pi-Sync") ); 271 dia.setCaption( i18n("Enter port for Pi-Sync") );
271 QPushButton pb ( "OK", &dia); 272 QPushButton pb ( "OK", &dia);
272 lay.addWidget( &pb ); 273 lay.addWidget( &pb );
273 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 274 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
274 dia.show(); 275 dia.show();
275 if ( ! dia.exec() ) 276 if ( ! dia.exec() )
276 return; 277 return;
277 dia.hide(); 278 dia.hide();
278 qApp->processEvents(); 279 qApp->processEvents();
279 mPrefs->mPassiveSyncPw = lepw.text(); 280 mPrefs->mPassiveSyncPw = lepw.text();
280 mPrefs->mPassiveSyncPort = lab.text(); 281 mPrefs->mPassiveSyncPort = lab.text();
281 bool ok; 282 bool ok;
282 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 283 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
283 if ( ! ok ) { 284 if ( ! ok ) {
284 KMessageBox::information( 0, i18n("No valid port")); 285 KMessageBox::information( 0, i18n("No valid port"));
285 return; 286 return;
286 } 287 }
287 //qDebug("port %d ", port); 288 //qDebug("port %d ", port);
288 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 289 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
289 mServerSocket->setFileName( defaultFileName() ); 290 mServerSocket->setFileName( defaultFileName() );
290 //qDebug("connected "); 291 //qDebug("connected ");
291 if ( !mServerSocket->ok() ) { 292 if ( !mServerSocket->ok() ) {
292 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 293 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
293 delete mServerSocket; 294 delete mServerSocket;
294 mServerSocket = 0; 295 mServerSocket = 0;
295 return; 296 return;
296 } 297 }
297 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 298 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
298 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 299 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
299} 300}
300 301
301void KSyncManager::syncLocalFile() 302void KSyncManager::syncLocalFile()
302{ 303{
303 304
304 QString fn =mPrefs->mLastSyncedLocalFile; 305 QString fn =mPrefs->mLastSyncedLocalFile;
305 QString ext; 306 QString ext;
306 307
307 switch(mTargetApp) 308 switch(mTargetApp)
308 { 309 {
309 case (KAPI): 310 case (KAPI):
310 ext = "(*.vcf)"; 311 ext = "(*.vcf)";