-rw-r--r-- | kaddressbook/kabcore.cpp | 509 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 38 | ||||
-rw-r--r-- | kaddressbook/kabprefs.h | 18 | ||||
-rw-r--r-- | libkdepim/kpimprefs.h | 21 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 274 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 79 | ||||
-rw-r--r-- | libkdepim/libkdepimE.pro | 2 |
7 files changed, 335 insertions, 606 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index df634d0..f222234 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -158,18 +158,18 @@ bool pasteWithNewUid = true; | |||
158 | 158 | ||
159 | #ifdef KAB_EMBEDDED | 159 | #ifdef KAB_EMBEDDED |
160 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) | 160 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) |
161 | : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), | 161 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), |
162 | mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ | 162 | mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ |
163 | mReadWrite( readWrite ), mModified( false ), mMainWindow(client) | 163 | mReadWrite( readWrite ), mModified( false ), mMainWindow(client) |
164 | #else //KAB_EMBEDDED | 164 | #else //KAB_EMBEDDED |
165 | KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) | 165 | KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) |
166 | : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), | 166 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), |
167 | mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), | 167 | mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), |
168 | mReadWrite( readWrite ), mModified( false ) | 168 | mReadWrite( readWrite ), mModified( false ) |
169 | #endif //KAB_EMBEDDED | 169 | #endif //KAB_EMBEDDED |
170 | { | 170 | { |
171 | 171 | // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | |
172 | mBlockSaveFlag = false; | 172 | // syncManager->setBlockSave(false); |
173 | mExtensionBarSplitter = 0; | 173 | mExtensionBarSplitter = 0; |
174 | mIsPart = !parent->inherits( "KAddressBookMain" ); | 174 | mIsPart = !parent->inherits( "KAddressBookMain" ); |
175 | 175 | ||
@@ -269,6 +269,8 @@ KABCore::~KABCore() | |||
269 | delete AddresseeConfig::instance(); | 269 | delete AddresseeConfig::instance(); |
270 | mAddressBook = 0; | 270 | mAddressBook = 0; |
271 | KABC::StdAddressBook::close(); | 271 | KABC::StdAddressBook::close(); |
272 | |||
273 | delete syncManager; | ||
272 | } | 274 | } |
273 | 275 | ||
274 | void KABCore::restoreSettings() | 276 | void KABCore::restoreSettings() |
@@ -1074,9 +1076,9 @@ void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) | |||
1074 | 1076 | ||
1075 | void KABCore::save() | 1077 | void KABCore::save() |
1076 | { | 1078 | { |
1077 | if (mBlockSaveFlag) | 1079 | if (syncManager->blockSave()) |
1078 | return; | 1080 | return; |
1079 | mBlockSaveFlag = true; | 1081 | syncManager->setBlockSave(true); |
1080 | if ( !mModified ) | 1082 | if ( !mModified ) |
1081 | return; | 1083 | return; |
1082 | QString text = i18n( "There was an error while attempting to save\n the " | 1084 | QString text = i18n( "There was an error while attempting to save\n the " |
@@ -1097,7 +1099,7 @@ void KABCore::save() | |||
1097 | 1099 | ||
1098 | statusMessage(i18n("Addressbook saved!")); | 1100 | statusMessage(i18n("Addressbook saved!")); |
1099 | setModified( false ); | 1101 | setModified( false ); |
1100 | mBlockSaveFlag = false; | 1102 | syncManager->setBlockSave(false); |
1101 | } | 1103 | } |
1102 | 1104 | ||
1103 | void KABCore::statusMessage(QString mess , int time ) | 1105 | void KABCore::statusMessage(QString mess , int time ) |
@@ -1536,6 +1538,9 @@ void KABCore::initGUI() | |||
1536 | #endif //KAB_NOSPLITTER | 1538 | #endif //KAB_NOSPLITTER |
1537 | */ | 1539 | */ |
1538 | 1540 | ||
1541 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | ||
1542 | syncManager->setBlockSave(false); | ||
1543 | |||
1539 | 1544 | ||
1540 | #endif //KAB_EMBEDDED | 1545 | #endif //KAB_EMBEDDED |
1541 | initActions(); | 1546 | initActions(); |
@@ -1898,8 +1903,8 @@ void KABCore::addActionsManually() | |||
1898 | 1903 | ||
1899 | #endif //KAB_EMBEDDED | 1904 | #endif //KAB_EMBEDDED |
1900 | 1905 | ||
1901 | connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); | 1906 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
1902 | fillSyncMenu(); | 1907 | syncManager->fillSyncMenu(); |
1903 | 1908 | ||
1904 | } | 1909 | } |
1905 | void KABCore::showLicence() | 1910 | void KABCore::showLicence() |
@@ -2101,421 +2106,13 @@ void KABCore::faq() | |||
2101 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2106 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2102 | } | 2107 | } |
2103 | 2108 | ||
2104 | |||
2105 | void KABCore::fillSyncMenu() | ||
2106 | { | ||
2107 | if ( syncMenu->count() ) | ||
2108 | syncMenu->clear(); | ||
2109 | syncMenu->insertItem( i18n("Configure..."), 0 ); | ||
2110 | syncMenu->insertSeparator(); | ||
2111 | syncMenu->insertItem( i18n("Multiple sync"), 1 ); | ||
2112 | syncMenu->insertSeparator(); | ||
2113 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | ||
2114 | config.setGroup("General"); | ||
2115 | QStringList prof = config.readListEntry("SyncProfileNames"); | ||
2116 | KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | ||
2117 | if ( prof.count() < 3 ) { | ||
2118 | prof.clear(); | ||
2119 | prof << i18n("Sharp_DTM"); | ||
2120 | prof << i18n("Local_file"); | ||
2121 | prof << i18n("Last_file"); | ||
2122 | KSyncProfile* temp = new KSyncProfile (); | ||
2123 | temp->setName( prof[0] ); | ||
2124 | temp->writeConfig(&config); | ||
2125 | temp->setName( prof[1] ); | ||
2126 | temp->writeConfig(&config); | ||
2127 | temp->setName( prof[2] ); | ||
2128 | temp->writeConfig(&config); | ||
2129 | config.setGroup("General"); | ||
2130 | config.writeEntry("SyncProfileNames",prof); | ||
2131 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | ||
2132 | config.sync(); | ||
2133 | delete temp; | ||
2134 | } | ||
2135 | KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | ||
2136 | KABPrefs::instance()->mSyncProfileNames = prof; | ||
2137 | int i; | ||
2138 | for ( i = 0; i < prof.count(); ++i ) { | ||
2139 | |||
2140 | syncMenu->insertItem( prof[i], 1000+i ); | ||
2141 | if ( i == 2 ) | ||
2142 | syncMenu->insertSeparator(); | ||
2143 | } | ||
2144 | QDir app_dir; | ||
2145 | if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | ||
2146 | syncMenu->setItemEnabled( false , 1000 ); | ||
2147 | } | ||
2148 | //probaly useless | ||
2149 | //mView->setupExternSyncProfiles(); | ||
2150 | } | ||
2151 | void KABCore::slotSyncMenu( int action ) | ||
2152 | { | ||
2153 | //qDebug("syncaction %d ", action); | ||
2154 | if ( action == 0 ) { | ||
2155 | |||
2156 | // seems to be a Qt2 event handling bug | ||
2157 | // syncmenu.clear causes a segfault at first time | ||
2158 | // when we call it after the main event loop, it is ok | ||
2159 | // same behaviour when calling OM/Pi via QCOP for the first time | ||
2160 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | ||
2161 | //confSync(); | ||
2162 | |||
2163 | return; | ||
2164 | } | ||
2165 | if ( action == 1 ) { | ||
2166 | multiSync( true ); | ||
2167 | return; | ||
2168 | } | ||
2169 | |||
2170 | if (mBlockSaveFlag) | ||
2171 | return; | ||
2172 | mBlockSaveFlag = true; | ||
2173 | mCurrentSyncProfile = action - 1000 ; | ||
2174 | mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; | ||
2175 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; | ||
2176 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | ||
2177 | KSyncProfile* temp = new KSyncProfile (); | ||
2178 | temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | ||
2179 | temp->readConfig(&config); | ||
2180 | KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | ||
2181 | KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); | ||
2182 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | ||
2183 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | ||
2184 | KABPrefs::instance()->mWriteBackInFuture = 0; | ||
2185 | if ( temp->getWriteBackFuture() ) | ||
2186 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | ||
2187 | KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); | ||
2188 | if ( action == 1000 ) { | ||
2189 | syncSharp(); | ||
2190 | |||
2191 | } else if ( action == 1001 ) { | ||
2192 | syncLocalFile(); | ||
2193 | |||
2194 | } else if ( action == 1002 ) { | ||
2195 | quickSyncLocalFile(); | ||
2196 | |||
2197 | } else if ( action >= 1003 ) { | ||
2198 | if ( temp->getIsLocalFileSync() ) { | ||
2199 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | ||
2200 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | ||
2201 | } else { | ||
2202 | if ( temp->getIsPhoneSync() ) { | ||
2203 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | ||
2204 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | ||
2205 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | ||
2206 | syncPhone(); | ||
2207 | } else | ||
2208 | syncRemote( temp ); | ||
2209 | |||
2210 | } | ||
2211 | } | ||
2212 | delete temp; | ||
2213 | mBlockSaveFlag = false; | ||
2214 | } | ||
2215 | |||
2216 | void KABCore::syncLocalFile() | ||
2217 | { | ||
2218 | |||
2219 | QString fn =KABPrefs::instance()->mLastSyncedLocalFile; | ||
2220 | |||
2221 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); | ||
2222 | if ( fn == "" ) | ||
2223 | return; | ||
2224 | if ( syncWithFile( fn, false ) ) { | ||
2225 | qDebug("syncLocalFile() successful "); | ||
2226 | } | ||
2227 | |||
2228 | } | ||
2229 | bool KABCore::syncWithFile( QString fn , bool quick ) | ||
2230 | { | ||
2231 | bool ret = false; | ||
2232 | QFileInfo info; | ||
2233 | info.setFile( fn ); | ||
2234 | QString mess; | ||
2235 | bool loadbup = true; | ||
2236 | if ( !info. exists() ) { | ||
2237 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | ||
2238 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | ||
2239 | mess ); | ||
2240 | return ret; | ||
2241 | } | ||
2242 | int result = 0; | ||
2243 | if ( !quick ) { | ||
2244 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | ||
2245 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | ||
2246 | mess, | ||
2247 | i18n("Sync"), i18n("Cancel"), 0, | ||
2248 | 0, 1 ); | ||
2249 | if ( result ) | ||
2250 | return false; | ||
2251 | } | ||
2252 | if ( KABPrefs::instance()->mAskForPreferences ) | ||
2253 | edit_sync_options(); | ||
2254 | if ( result == 0 ) { | ||
2255 | //qDebug("Now sycing ... "); | ||
2256 | if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) | ||
2257 | setCaption( i18n("Synchronization successful") ); | ||
2258 | else | ||
2259 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | ||
2260 | if ( ! quick ) | ||
2261 | KABPrefs::instance()->mLastSyncedLocalFile = fn; | ||
2262 | setModified(); | ||
2263 | } | ||
2264 | return ret; | ||
2265 | } | ||
2266 | void KABCore::quickSyncLocalFile() | ||
2267 | { | ||
2268 | |||
2269 | if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { | ||
2270 | qDebug("quick syncLocalFile() successful "); | ||
2271 | |||
2272 | } | ||
2273 | } | ||
2274 | void KABCore::multiSync( bool askforPrefs ) | ||
2275 | { | ||
2276 | if (mBlockSaveFlag) | ||
2277 | return; | ||
2278 | mBlockSaveFlag = true; | ||
2279 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | ||
2280 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | ||
2281 | question, | ||
2282 | i18n("Yes"), i18n("No"), | ||
2283 | 0, 0 ) != 0 ) { | ||
2284 | mBlockSaveFlag = false; | ||
2285 | setCaption(i18n("Aborted! Nothing synced!")); | ||
2286 | return; | ||
2287 | } | ||
2288 | mCurrentSyncDevice = i18n("Multiple profiles") ; | ||
2289 | KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; | ||
2290 | if ( askforPrefs ) { | ||
2291 | edit_sync_options(); | ||
2292 | KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; | ||
2293 | } | ||
2294 | setCaption(i18n("Multiple sync started.") ); | ||
2295 | qApp->processEvents(); | ||
2296 | int num = ringSync() ; | ||
2297 | if ( num > 1 ) | ||
2298 | ringSync(); | ||
2299 | mBlockSaveFlag = false; | ||
2300 | if ( num ) | ||
2301 | save(); | ||
2302 | if ( num ) | ||
2303 | setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); | ||
2304 | else | ||
2305 | setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | ||
2306 | return; | ||
2307 | } | ||
2308 | int KABCore::ringSync() | ||
2309 | { | ||
2310 | int syncedProfiles = 0; | ||
2311 | int i; | ||
2312 | QTime timer; | ||
2313 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | ||
2314 | QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; | ||
2315 | KSyncProfile* temp = new KSyncProfile (); | ||
2316 | KABPrefs::instance()->mAskForPreferences = false; | ||
2317 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | ||
2318 | mCurrentSyncProfile = i; | ||
2319 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | ||
2320 | temp->readConfig(&config); | ||
2321 | if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { | ||
2322 | setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | ||
2323 | ++syncedProfiles; | ||
2324 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | ||
2325 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | ||
2326 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | ||
2327 | KABPrefs::instance()->mWriteBackInFuture = 0; | ||
2328 | if ( temp->getWriteBackFuture() ) | ||
2329 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | ||
2330 | KABPrefs::instance()->mShowSyncSummary = false; | ||
2331 | mCurrentSyncDevice = syncProfileNames[i] ; | ||
2332 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; | ||
2333 | if ( i == 0 ) { | ||
2334 | syncSharp(); | ||
2335 | } else { | ||
2336 | if ( temp->getIsLocalFileSync() ) { | ||
2337 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) | ||
2338 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | ||
2339 | } else { | ||
2340 | if ( temp->getIsPhoneSync() ) { | ||
2341 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | ||
2342 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | ||
2343 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | ||
2344 | syncPhone(); | ||
2345 | } else | ||
2346 | syncRemote( temp, false ); | ||
2347 | |||
2348 | } | ||
2349 | } | ||
2350 | timer.start(); | ||
2351 | setCaption(i18n("Multiple sync in progress ... please wait!") ); | ||
2352 | while ( timer.elapsed () < 2000 ) { | ||
2353 | qApp->processEvents(); | ||
2354 | #ifndef _WIN32_ | ||
2355 | sleep (1); | ||
2356 | #endif | ||
2357 | } | ||
2358 | |||
2359 | } | ||
2360 | |||
2361 | } | ||
2362 | delete temp; | ||
2363 | return syncedProfiles; | ||
2364 | } | ||
2365 | |||
2366 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) | ||
2367 | { | ||
2368 | QString question; | ||
2369 | if ( ask ) { | ||
2370 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | ||
2371 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | ||
2372 | question, | ||
2373 | i18n("Yes"), i18n("No"), | ||
2374 | 0, 0 ) != 0 ) | ||
2375 | return; | ||
2376 | } | ||
2377 | QString command = prof->getPreSyncCommandAB(); | ||
2378 | int fi; | ||
2379 | if ( (fi = command.find("$PWD$")) > 0 ) { | ||
2380 | QString pwd = getPassword(); | ||
2381 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | ||
2382 | |||
2383 | } | ||
2384 | int maxlen = 30; | ||
2385 | if ( QApplication::desktop()->width() > 320 ) | ||
2386 | maxlen += 25; | ||
2387 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | ||
2388 | int fileSize = 0; | ||
2389 | int result = system ( command ); | ||
2390 | // 0 : okay | ||
2391 | // 256: no such file or dir | ||
2392 | // | ||
2393 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | ||
2394 | if ( result != 0 ) { | ||
2395 | int len = maxlen; | ||
2396 | while ( len < command.length() ) { | ||
2397 | command.insert( len , "\n" ); | ||
2398 | len += maxlen +2; | ||
2399 | } | ||
2400 | 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) ; | ||
2401 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | ||
2402 | question, | ||
2403 | i18n("Okay!")) ; | ||
2404 | setCaption ("KO/Pi"); | ||
2405 | return; | ||
2406 | } | ||
2407 | setCaption ( i18n( "Copying succeed." ) ); | ||
2408 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | ||
2409 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { | ||
2410 | // Event* e = mView->getLastSyncEvent(); | ||
2411 | // e->setReadOnly( false ); | ||
2412 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | ||
2413 | // e->setReadOnly( true ); | ||
2414 | if ( KABPrefs::instance()->mWriteBackFile ) { | ||
2415 | command = prof->getPostSyncCommandAB(); | ||
2416 | int fi; | ||
2417 | if ( (fi = command.find("$PWD$")) > 0 ) { | ||
2418 | QString pwd = getPassword(); | ||
2419 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | ||
2420 | |||
2421 | } | ||
2422 | setCaption ( i18n( "Writing back file ..." ) ); | ||
2423 | result = system ( command ); | ||
2424 | qDebug("KO: Writing back file result: %d ", result); | ||
2425 | if ( result != 0 ) { | ||
2426 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | ||
2427 | return; | ||
2428 | } else { | ||
2429 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | ||
2430 | } | ||
2431 | } | ||
2432 | } | ||
2433 | return; | ||
2434 | } | ||
2435 | #include <qpushbutton.h> | ||
2436 | #include <qradiobutton.h> | ||
2437 | #include <qbuttongroup.h> | ||
2438 | void KABCore::edit_sync_options() | ||
2439 | { | ||
2440 | //mDialogManager->showSyncOptions(); | ||
2441 | //KABPrefs::instance()->mSyncAlgoPrefs | ||
2442 | QDialog dia( this, "dia", true ); | ||
2443 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | ||
2444 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | ||
2445 | QVBoxLayout lay ( &dia ); | ||
2446 | lay.setSpacing( 2 ); | ||
2447 | lay.setMargin( 3 ); | ||
2448 | lay.addWidget(&gr); | ||
2449 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | ||
2450 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | ||
2451 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | ||
2452 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | ||
2453 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | ||
2454 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | ||
2455 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | ||
2456 | QPushButton pb ( "OK", &dia); | ||
2457 | lay.addWidget( &pb ); | ||
2458 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | ||
2459 | switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { | ||
2460 | case 0: | ||
2461 | loc.setChecked( true); | ||
2462 | break; | ||
2463 | case 1: | ||
2464 | rem.setChecked( true ); | ||
2465 | break; | ||
2466 | case 2: | ||
2467 | newest.setChecked( true); | ||
2468 | break; | ||
2469 | case 3: | ||
2470 | ask.setChecked( true); | ||
2471 | break; | ||
2472 | case 4: | ||
2473 | f_loc.setChecked( true); | ||
2474 | break; | ||
2475 | case 5: | ||
2476 | f_rem.setChecked( true); | ||
2477 | break; | ||
2478 | case 6: | ||
2479 | // both.setChecked( true); | ||
2480 | break; | ||
2481 | default: | ||
2482 | break; | ||
2483 | } | ||
2484 | if ( dia.exec() ) { | ||
2485 | KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | ||
2486 | } | ||
2487 | |||
2488 | |||
2489 | } | ||
2490 | QString KABCore::getPassword( ) | ||
2491 | { | ||
2492 | QString retfile = ""; | ||
2493 | QDialog dia ( this, "input-dialog", true ); | ||
2494 | QLineEdit lab ( &dia ); | ||
2495 | lab.setEchoMode( QLineEdit::Password ); | ||
2496 | QVBoxLayout lay( &dia ); | ||
2497 | lay.setMargin(7); | ||
2498 | lay.setSpacing(7); | ||
2499 | lay.addWidget( &lab); | ||
2500 | dia.setFixedSize( 230,50 ); | ||
2501 | dia.setCaption( i18n("Enter password") ); | ||
2502 | QPushButton pb ( "OK", &dia); | ||
2503 | lay.addWidget( &pb ); | ||
2504 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | ||
2505 | dia.show(); | ||
2506 | int res = dia.exec(); | ||
2507 | if ( res ) | ||
2508 | retfile = lab.text(); | ||
2509 | dia.hide(); | ||
2510 | qApp->processEvents(); | ||
2511 | return retfile; | ||
2512 | |||
2513 | } | ||
2514 | #include <libkcal/syncdefines.h> | 2109 | #include <libkcal/syncdefines.h> |
2515 | 2110 | ||
2516 | KABC::Addressee KABCore::getLastSyncAddressee() | 2111 | KABC::Addressee KABCore::getLastSyncAddressee() |
2517 | { | 2112 | { |
2518 | Addressee lse; | 2113 | Addressee lse; |
2114 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | ||
2115 | |||
2519 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 2116 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
2520 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2117 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2521 | if (lse.isEmpty()) { | 2118 | if (lse.isEmpty()) { |
@@ -2547,6 +2144,9 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i | |||
2547 | QDateTime lastSync = mLastAddressbookSync; | 2144 | QDateTime lastSync = mLastAddressbookSync; |
2548 | QDateTime localMod = local->revision(); | 2145 | QDateTime localMod = local->revision(); |
2549 | QDateTime remoteMod = remote->revision(); | 2146 | QDateTime remoteMod = remote->revision(); |
2147 | |||
2148 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | ||
2149 | |||
2550 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2150 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2551 | bool remCh, locCh; | 2151 | bool remCh, locCh; |
2552 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 2152 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
@@ -2653,6 +2253,8 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i | |||
2653 | } | 2253 | } |
2654 | return 0; | 2254 | return 0; |
2655 | } | 2255 | } |
2256 | |||
2257 | |||
2656 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2258 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2657 | { | 2259 | { |
2658 | bool syncOK = true; | 2260 | bool syncOK = true; |
@@ -2662,6 +2264,10 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2662 | int deletedAddresseeL = 0; | 2264 | int deletedAddresseeL = 0; |
2663 | int changedLocal = 0; | 2265 | int changedLocal = 0; |
2664 | int changedRemote = 0; | 2266 | int changedRemote = 0; |
2267 | |||
2268 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | ||
2269 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | ||
2270 | |||
2665 | //QPtrList<Addressee> el = local->rawAddressees(); | 2271 | //QPtrList<Addressee> el = local->rawAddressees(); |
2666 | Addressee addresseeR; | 2272 | Addressee addresseeR; |
2667 | QString uid; | 2273 | QString uid; |
@@ -2921,12 +2527,16 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2921 | return syncOK; | 2527 | return syncOK; |
2922 | } | 2528 | } |
2923 | 2529 | ||
2924 | bool KABCore::syncAB(QString filename, int mode) | 2530 | |
2531 | //this is a overwritten callbackmethods from the syncinterface | ||
2532 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | ||
2925 | { | 2533 | { |
2926 | 2534 | ||
2927 | //pending prepare addresseeview for output | 2535 | //pending prepare addresseeview for output |
2928 | //pending detect, if remote file has REV field. if not switch to external sync | 2536 | //pending detect, if remote file has REV field. if not switch to external sync |
2929 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2537 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2538 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | ||
2539 | |||
2930 | AddressBook abLocal(filename,"syncContact"); | 2540 | AddressBook abLocal(filename,"syncContact"); |
2931 | bool syncOK = false; | 2541 | bool syncOK = false; |
2932 | if ( abLocal.load() ) { | 2542 | if ( abLocal.load() ) { |
@@ -3008,41 +2618,19 @@ bool KABCore::syncAB(QString filename, int mode) | |||
3008 | #endif | 2618 | #endif |
3009 | } | 2619 | } |
3010 | 2620 | ||
3011 | void KABCore::confSync() | 2621 | |
3012 | { | 2622 | //this is a overwritten callbackmethods from the syncinterface |
3013 | static KSyncPrefsDialog* sp = 0; | 2623 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
3014 | if ( ! sp ) { | ||
3015 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | ||
3016 | } | ||
3017 | sp->usrReadConfig(); | ||
3018 | #ifndef DESKTOP_VERSION | ||
3019 | sp->showMaximized(); | ||
3020 | #else | ||
3021 | sp->show(); | ||
3022 | #endif | ||
3023 | sp->exec(); | ||
3024 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | ||
3025 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | ||
3026 | fillSyncMenu(); | ||
3027 | } | ||
3028 | void KABCore::syncSharp() | ||
3029 | { | ||
3030 | if ( ! syncExternal("sharp") ) | ||
3031 | qDebug("ERROR sync sharp ");; | ||
3032 | } | ||
3033 | bool KABCore::syncExternal(QString resource) | ||
3034 | { | 2624 | { |
3035 | if ( mModified ) | 2625 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3036 | save(); | 2626 | |
3037 | if ( KABPrefs::instance()->mAskForPreferences ) | ||
3038 | edit_sync_options(); | ||
3039 | qDebug("syncSharp() "); | ||
3040 | AddressBook abLocal( resource,"syncContact"); | 2627 | AddressBook abLocal( resource,"syncContact"); |
3041 | bool syncOK = false; | 2628 | bool syncOK = false; |
3042 | if ( abLocal.load() ) { | 2629 | if ( abLocal.load() ) { |
3043 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2630 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
3044 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2631 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3045 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2632 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2633 | qDebug("KABCore::syncExternal: why do we acces here KABPrefs and not somehow KSyncProfile? "); | ||
3046 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, KABPrefs::instance()->mSyncAlgoPrefs ); | 2634 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, KABPrefs::instance()->mSyncAlgoPrefs ); |
3047 | if ( syncOK ) { | 2635 | if ( syncOK ) { |
3048 | if ( KABPrefs::instance()->mWriteBackFile ) { | 2636 | if ( KABPrefs::instance()->mWriteBackFile ) { |
@@ -3057,12 +2645,25 @@ bool KABCore::syncExternal(QString resource) | |||
3057 | return syncOK; | 2645 | return syncOK; |
3058 | 2646 | ||
3059 | } | 2647 | } |
3060 | void KABCore::syncPhone() | 2648 | |
2649 | //called by the syncmanager to indicate that the work has to marked as dirty. | ||
2650 | void KABCore::sync_setModified() | ||
3061 | { | 2651 | { |
3062 | if ( mModified ) | 2652 | setModified(); |
3063 | save(); | 2653 | } |
3064 | qDebug("pending syncPhone(); "); | ||
3065 | //mView->syncPhone(); | ||
3066 | setModified(); | ||
3067 | 2654 | ||
2655 | //called by the syncmanager to ask if the dirty flag is set. | ||
2656 | bool KABCore::sync_isModified() | ||
2657 | { | ||
2658 | return mModified; | ||
3068 | } | 2659 | } |
2660 | |||
2661 | |||
2662 | //called by the syncmanager to indicate that the work has to be saved. | ||
2663 | void KABCore::sync_save() | ||
2664 | { | ||
2665 | save(); | ||
2666 | } | ||
2667 | |||
2668 | |||
2669 | |||
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index e89bf41..ef61d6d 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h | |||
@@ -32,6 +32,7 @@ | |||
32 | 32 | ||
33 | #include <qwidget.h> | 33 | #include <qwidget.h> |
34 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
35 | #include <ksyncmanager.h> | ||
35 | 36 | ||
36 | namespace KABC { | 37 | namespace KABC { |
37 | class AddressBook; | 38 | class AddressBook; |
@@ -67,7 +68,7 @@ class ViewManager; | |||
67 | class AddresseeEditorDialog; | 68 | class AddresseeEditorDialog; |
68 | class Ir; | 69 | class Ir; |
69 | 70 | ||
70 | class KABCore : public QWidget | 71 | class KABCore : public QWidget, public KSyncInterface |
71 | { | 72 | { |
72 | Q_OBJECT | 73 | Q_OBJECT |
73 | 74 | ||
@@ -341,7 +342,7 @@ class KABCore : public QWidget | |||
341 | public slots: | 342 | public slots: |
342 | void setDetailsVisible( bool visible ); | 343 | void setDetailsVisible( bool visible ); |
343 | void setDetailsToState(); | 344 | void setDetailsToState(); |
344 | void slotSyncMenu( int ); | 345 | // void slotSyncMenu( int ); |
345 | private slots: | 346 | private slots: |
346 | void setJumpButtonBarVisible( bool visible ); | 347 | void setJumpButtonBarVisible( bool visible ); |
347 | void importFromOL(); | 348 | void importFromOL(); |
@@ -447,37 +448,32 @@ class KABCore : public QWidget | |||
447 | 448 | ||
448 | class KABCorePrivate; | 449 | class KABCorePrivate; |
449 | KABCorePrivate *d; | 450 | KABCorePrivate *d; |
450 | bool mBlockSaveFlag; | 451 | //US bool mBlockSaveFlag; |
451 | 452 | ||
452 | #ifdef KAB_EMBEDDED | 453 | #ifdef KAB_EMBEDDED |
453 | KAddressBookMain *mMainWindow; // should be the same like mGUIClient | 454 | KAddressBookMain *mMainWindow; // should be the same like mGUIClient |
454 | #endif //KAB_EMBEDDED | 455 | #endif //KAB_EMBEDDED |
456 | |||
457 | //this are the overwritten callbackmethods from the syncinterface | ||
458 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | ||
459 | virtual bool syncExternal(KSyncManager* manager, QString resource); | ||
460 | |||
461 | //called by the syncmanager to indicate that the work has to marked as dirty. | ||
462 | virtual void sync_setModified(); | ||
463 | //called by the syncmanager to ask if the dirty flag is set. | ||
464 | virtual bool KABCore::sync_isModified(); | ||
465 | //called by the syncmanager to indicate that the work has to be saved. | ||
466 | virtual void sync_save(); | ||
467 | |||
455 | // LR ******************************* | 468 | // LR ******************************* |
456 | // sync stuff! | 469 | // sync stuff! |
457 | QPopupMenu *syncMenu; | 470 | QPopupMenu *syncMenu; |
458 | void fillSyncMenu(); | 471 | KSyncManager* syncManager; |
459 | QString mCurrentSyncDevice; | ||
460 | QString mCurrentSyncName; | ||
461 | void quickSyncLocalFile(); | ||
462 | bool syncWithFile( QString fn , bool quick ); | ||
463 | void syncLocalFile(); | ||
464 | void syncPhone(); | ||
465 | void syncSharp(); | ||
466 | bool syncExternal(QString); | ||
467 | void multiSync( bool askforPrefs ); | ||
468 | int mCurrentSyncProfile ; | ||
469 | void syncRemote( KSyncProfile* prof, bool ask = true); | ||
470 | void edit_sync_options(); | ||
471 | bool syncAB(QString filename, int mode); | ||
472 | int ringSync(); | ||
473 | QString getPassword( ); | ||
474 | int mGlobalSyncMode; | 472 | int mGlobalSyncMode; |
475 | bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); | 473 | bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); |
476 | KABC::Addressee getLastSyncAddressee(); | 474 | KABC::Addressee getLastSyncAddressee(); |
477 | QDateTime mLastAddressbookSync; | 475 | QDateTime mLastAddressbookSync; |
478 | int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); | 476 | int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); |
479 | public slots: | ||
480 | void confSync(); | ||
481 | // ********************* | 477 | // ********************* |
482 | 478 | ||
483 | }; | 479 | }; |
diff --git a/kaddressbook/kabprefs.h b/kaddressbook/kabprefs.h index 9926aa0..e4f359c 100644 --- a/kaddressbook/kabprefs.h +++ b/kaddressbook/kabprefs.h | |||
@@ -82,23 +82,7 @@ class KABPrefs : public KPimPrefs | |||
82 | int mCurrentFilter; | 82 | int mCurrentFilter; |
83 | 83 | ||
84 | void setCategoryDefaults(); | 84 | void setCategoryDefaults(); |
85 | // sync stuff | 85 | |
86 | QString mLocalMachineName; | ||
87 | QStringList mExternSyncProfiles; | ||
88 | QStringList mSyncProfileNames; | ||
89 | bool mAskForPreferences; | ||
90 | bool mShowSyncSummary; | ||
91 | bool mShowSyncEvents; | ||
92 | bool mShowTodoInAgenda; | ||
93 | bool mWriteBackExistingOnly; | ||
94 | int mSyncAlgoPrefs; | ||
95 | int mRingSyncAlgoPrefs; | ||
96 | bool mWriteBackFile; | ||
97 | int mWriteBackInFuture; | ||
98 | QString mPhoneDevice; | ||
99 | QString mPhoneConnection; | ||
100 | QString mPhoneModel; | ||
101 | QString mLastSyncedLocalFile; // save! | ||
102 | private: | 86 | private: |
103 | KABPrefs(); | 87 | KABPrefs(); |
104 | 88 | ||
diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h index 860665b..01c57a3 100644 --- a/libkdepim/kpimprefs.h +++ b/libkdepim/kpimprefs.h | |||
@@ -56,9 +56,30 @@ class KPimPrefs : public KPrefs | |||
56 | public: | 56 | public: |
57 | QStringList mCustomCategories; | 57 | QStringList mCustomCategories; |
58 | 58 | ||
59 | // sync stuff | ||
60 | QString mLocalMachineName; | ||
61 | QStringList mExternSyncProfiles; | ||
62 | QStringList mSyncProfileNames; | ||
63 | bool mAskForPreferences; | ||
64 | bool mShowSyncSummary; | ||
65 | bool mShowSyncEvents; | ||
66 | bool mShowTodoInAgenda; | ||
67 | bool mWriteBackExistingOnly; | ||
68 | int mSyncAlgoPrefs; | ||
69 | int mRingSyncAlgoPrefs; | ||
70 | bool mWriteBackFile; | ||
71 | int mWriteBackInFuture; | ||
72 | QString mPhoneDevice; | ||
73 | QString mPhoneConnection; | ||
74 | QString mPhoneModel; | ||
75 | QString mLastSyncedLocalFile; // save! | ||
76 | |||
59 | 77 | ||
60 | protected: | 78 | protected: |
61 | virtual void setCategoryDefaults(); | 79 | virtual void setCategoryDefaults(); |
80 | |||
81 | |||
82 | |||
62 | }; | 83 | }; |
63 | 84 | ||
64 | #endif | 85 | #endif |
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 52e3bd9..87f200a 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -22,9 +22,36 @@ | |||
22 | 22 | ||
23 | #include "ksyncmanager.h" | 23 | #include "ksyncmanager.h" |
24 | 24 | ||
25 | #include <stdlib.h> | ||
25 | 26 | ||
26 | KSyncManager::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 | |||
53 | KSyncManager::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 | } |
@@ -35,10 +62,10 @@ KSyncManager::~KSyncManager() | |||
35 | } | 62 | } |
36 | 63 | ||
37 | 64 | ||
38 | void KABCore::fillSyncMenu() | 65 | void 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(); |
@@ -48,7 +75,7 @@ void KABCore::fillSyncMenu() | |||
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"); |
@@ -67,11 +94,9 @@ void KABCore::fillSyncMenu() | |||
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 ); |
@@ -85,7 +110,8 @@ void KABCore::fillSyncMenu() | |||
85 | //probaly useless | 110 | //probaly useless |
86 | //mView->setupExternSyncProfiles(); | 111 | //mView->setupExternSyncProfiles(); |
87 | } | 112 | } |
88 | void KABCore::slotSyncMenu( int action ) | 113 | |
114 | void KSyncManager::slotSyncMenu( int action ) | ||
89 | { | 115 | { |
90 | //qDebug("syncaction %d ", action); | 116 | //qDebug("syncaction %d ", action); |
91 | if ( action == 0 ) { | 117 | if ( action == 0 ) { |
@@ -104,26 +130,26 @@ void KABCore::slotSyncMenu( int action ) | |||
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 | ||
@@ -135,16 +161,14 @@ void KABCore::slotSyncMenu( int action ) | |||
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 ); |
@@ -152,15 +176,15 @@ void KABCore::slotSyncMenu( int action ) | |||
152 | } | 176 | } |
153 | } | 177 | } |
154 | delete temp; | 178 | delete temp; |
155 | mBlockSaveFlag = false; | 179 | setBlockSave(false); |
156 | } | 180 | } |
157 | 181 | ||
158 | void KABCore::syncLocalFile() | 182 | void 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 ) ) { |
@@ -168,7 +192,7 @@ void KABCore::syncLocalFile() | |||
168 | } | 192 | } |
169 | 193 | ||
170 | } | 194 | } |
171 | bool KABCore::syncWithFile( QString fn , bool quick ) | 195 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
172 | { | 196 | { |
173 | bool ret = false; | 197 | bool ret = false; |
174 | QFileInfo info; | 198 | QFileInfo info; |
@@ -177,112 +201,112 @@ bool KABCore::syncWithFile( QString fn , bool quick ) | |||
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 | } |
208 | void KABCore::quickSyncLocalFile() | 232 | void 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 | } |
216 | void KABCore::multiSync( bool askforPrefs ) | 240 | void 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 | } |
250 | int KABCore::ringSync() | 274 | int 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 ); |
@@ -290,7 +314,7 @@ int KABCore::ringSync() | |||
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_ |
@@ -305,12 +329,12 @@ int KABCore::ringSync() | |||
305 | return syncedProfiles; | 329 | return syncedProfiles; |
306 | } | 330 | } |
307 | 331 | ||
308 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) | 332 | void 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 ) |
@@ -326,7 +350,7 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) | |||
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 |
@@ -334,26 +358,26 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) | |||
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 ) { |
@@ -361,27 +385,25 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) | |||
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> | 402 | void KSyncManager::edit_sync_options() |
379 | #include <qbuttongroup.h> | ||
380 | void 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 ); |
@@ -398,7 +420,7 @@ void KABCore::edit_sync_options() | |||
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; |
@@ -424,15 +446,15 @@ void KABCore::edit_sync_options() | |||
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 | } |
432 | QString KABCore::getPassword( ) | 454 | QString 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 ); |
@@ -453,3 +475,55 @@ QString KABCore::getPassword( ) | |||
453 | return retfile; | 475 | return retfile; |
454 | 476 | ||
455 | } | 477 | } |
478 | |||
479 | |||
480 | void 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 | |||
498 | void KSyncManager::syncSharp() | ||
499 | { | ||
500 | if ( ! syncExternalApplication("sharp") ) | ||
501 | qDebug("ERROR sync sharp ");; | ||
502 | } | ||
503 | |||
504 | bool 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 | |||
520 | void 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 | } | ||
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index d7c2a02..389a005 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h | |||
@@ -22,47 +22,98 @@ $Id$ | |||
22 | #ifndef _KSYNCMANAGER_H | 22 | #ifndef _KSYNCMANAGER_H |
23 | #define _KSYNCMANAGER_H | 23 | #define _KSYNCMANAGER_H |
24 | 24 | ||
25 | #include <qobject.h> | ||
25 | #include <qstring.h> | 26 | #include <qstring.h> |
26 | 27 | ||
27 | class QPopupMenu; | 28 | class QPopupMenu; |
28 | class KSyncProfile; | 29 | class KSyncProfile; |
30 | class KPimPrefs; | ||
31 | class QWidget; | ||
32 | class KSyncManager; | ||
33 | class KSyncInterface; | ||
29 | 34 | ||
30 | 35 | class KSyncManager : public QObject | |
31 | |||
32 | class KSyncManager | ||
33 | { | 36 | { |
34 | 37 | Q_OBJECT | |
35 | public: | ||
36 | KSyncManager(TargetApp ta, QPopupMenu* syncmenu); | ||
37 | ~KSyncManager() ; | ||
38 | 38 | ||
39 | public: | ||
39 | enum TargetApp { | 40 | enum TargetApp { |
40 | KOPI = 0, | 41 | KOPI = 0, |
41 | KAPI = 1, | 42 | KAPI = 1, |
42 | PWMPI = 2 }; | 43 | PWMPI = 2 }; |
43 | 44 | ||
44 | private: | 45 | |
46 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); | ||
47 | ~KSyncManager() ; | ||
48 | |||
49 | bool blockSave() { return mBlockSaveFlag; } | ||
50 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } | ||
51 | |||
45 | void fillSyncMenu(); | 52 | void fillSyncMenu(); |
46 | void syncLocalFile(); | 53 | |
47 | bool syncWithFile( QString fn , bool quick ); | 54 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } |
55 | QString getCurrentSyncName() { return mCurrentSyncName; } | ||
56 | |||
57 | public slots: | ||
58 | void slotSyncMenu( int ); | ||
59 | |||
60 | private: | ||
61 | // LR ******************************* | ||
62 | // sync stuff! | ||
63 | QString mCurrentSyncDevice; | ||
64 | QString mCurrentSyncName; | ||
48 | void quickSyncLocalFile(); | 65 | void quickSyncLocalFile(); |
66 | bool syncWithFile( QString fn , bool quick ); | ||
67 | void syncLocalFile(); | ||
68 | void syncPhone(); | ||
69 | void syncSharp(); | ||
70 | bool syncExternalApplication(QString); | ||
49 | void multiSync( bool askforPrefs ); | 71 | void multiSync( bool askforPrefs ); |
50 | int ringSync(); | 72 | int mCurrentSyncProfile ; |
51 | void syncRemote( KSyncProfile* prof, bool ask); | 73 | void syncRemote( KSyncProfile* prof, bool ask = true); |
52 | void edit_sync_options(); | 74 | void edit_sync_options(); |
53 | QString getPassword(); | 75 | int ringSync(); |
76 | QString getPassword( ); | ||
77 | |||
78 | private slots: | ||
79 | void confSync(); | ||
80 | // ********************* | ||
54 | 81 | ||
55 | private: | 82 | private: |
56 | QPopupMenu* mSyncMenu; | 83 | bool mBlockSaveFlag; |
84 | |||
85 | |||
86 | QWidget* mParent; | ||
87 | KSyncInterface* mImplementation; | ||
57 | TargetApp mTargetApp; | 88 | TargetApp mTargetApp; |
89 | KPimPrefs* mPrefs; | ||
90 | QPopupMenu* mSyncMenu; | ||
91 | |||
58 | 92 | ||
59 | 93 | ||
60 | 94 | ||
61 | 95 | ||
62 | 96 | ||
63 | 97 | ||
98 | }; | ||
99 | |||
100 | |||
101 | class KSyncInterface | ||
102 | { | ||
103 | public: | ||
104 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; | ||
105 | virtual bool syncExternal(KSyncManager* manager, QString resource) = 0; | ||
64 | 106 | ||
65 | 107 | ||
108 | //called by the syncmanager to indicate that the work has to be marked as dirty. | ||
109 | virtual void sync_setModified() = 0; | ||
110 | |||
111 | //called by the syncmanager to ask if the dirty flag is set. | ||
112 | virtual bool sync_isModified() = 0; | ||
113 | |||
114 | //called by the syncmanager to indicate that the work has to be saved. | ||
115 | virtual void sync_save() = 0; | ||
66 | }; | 116 | }; |
67 | 117 | ||
118 | |||
68 | #endif | 119 | #endif |
diff --git a/libkdepim/libkdepimE.pro b/libkdepim/libkdepimE.pro index 2a30ee8..156e247 100644 --- a/libkdepim/libkdepimE.pro +++ b/libkdepim/libkdepimE.pro | |||
@@ -25,6 +25,7 @@ HEADERS = \ | |||
25 | kpimglobalprefs.h \ | 25 | kpimglobalprefs.h \ |
26 | kprefsdialog.h \ | 26 | kprefsdialog.h \ |
27 | kprefswidget.h \ | 27 | kprefswidget.h \ |
28 | ksyncmanager.h \ | ||
28 | ksyncprofile.h \ | 29 | ksyncprofile.h \ |
29 | ksyncprefsdialog.h \ | 30 | ksyncprefsdialog.h \ |
30 | kcmconfigs/kcmkdepimconfig.h \ | 31 | kcmconfigs/kcmkdepimconfig.h \ |
@@ -45,6 +46,7 @@ SOURCES = \ | |||
45 | kpimglobalprefs.cpp \ | 46 | kpimglobalprefs.cpp \ |
46 | kprefsdialog.cpp \ | 47 | kprefsdialog.cpp \ |
47 | kprefswidget.cpp \ | 48 | kprefswidget.cpp \ |
49 | ksyncmanager.cpp \ | ||
48 | ksyncprofile.cpp \ | 50 | ksyncprofile.cpp \ |
49 | ksyncprefsdialog.cpp \ | 51 | ksyncprefsdialog.cpp \ |
50 | kcmconfigs/kcmkdepimconfig.cpp \ | 52 | kcmconfigs/kcmkdepimconfig.cpp \ |