author | zautrix <zautrix> | 2004-09-17 19:45:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-17 19:45:31 (UTC) |
commit | df03bd8c7ff6a738dd386001679542ae4b493a07 (patch) (unidiff) | |
tree | f785901b1edbd1fd3075660ab2b556e3692b79b2 | |
parent | 603ad0a623dc72b8ccb9535f9907e0f2aa536328 (diff) | |
download | kdepimpi-df03bd8c7ff6a738dd386001679542ae4b493a07.zip kdepimpi-df03bd8c7ff6a738dd386001679542ae4b493a07.tar.gz kdepimpi-df03bd8c7ff6a738dd386001679542ae4b493a07.tar.bz2 |
first sync stuff in kaddressbook
-rw-r--r-- | kaddressbook/kabcore.cpp | 460 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 24 | ||||
-rw-r--r-- | kaddressbook/kabprefs.h | 18 |
3 files changed, 496 insertions, 6 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 32dd43a..49c3b19 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -29,12 +29,13 @@ $Id$ | |||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "kabcore.h" | 31 | #include "kabcore.h" |
32 | 32 | ||
33 | #include <stdaddressbook.h> | 33 | #include <stdaddressbook.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kfiledialog.h> | ||
35 | 36 | ||
36 | #ifndef KAB_EMBEDDED | 37 | #ifndef KAB_EMBEDDED |
37 | #include <qclipboard.h> | 38 | #include <qclipboard.h> |
38 | #include <qdir.h> | 39 | #include <qdir.h> |
39 | #include <qfile.h> | 40 | #include <qfile.h> |
40 | #include <qapplicaton.h> | 41 | #include <qapplicaton.h> |
@@ -139,13 +140,18 @@ $Id$ | |||
139 | #include "addresseeconfig.h" | 140 | #include "addresseeconfig.h" |
140 | #include <kcmultidialog.h> | 141 | #include <kcmultidialog.h> |
141 | 142 | ||
142 | #ifdef _WIN32_ | 143 | #ifdef _WIN32_ |
143 | 144 | ||
144 | #include "kaimportoldialog.h" | 145 | #include "kaimportoldialog.h" |
146 | #else | ||
147 | #include <unistd.h> | ||
145 | #endif | 148 | #endif |
149 | // sync includes | ||
150 | #include <libkdepim/ksyncprofile.h> | ||
151 | |||
146 | 152 | ||
147 | bool pasteWithNewUid = true; | 153 | bool pasteWithNewUid = true; |
148 | 154 | ||
149 | #ifdef KAB_EMBEDDED | 155 | #ifdef KAB_EMBEDDED |
150 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) | 156 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) |
151 | : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), | 157 | : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), |
@@ -156,12 +162,13 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const | |||
156 | : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), | 162 | : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), |
157 | mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), | 163 | mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), |
158 | mReadWrite( readWrite ), mModified( false ) | 164 | mReadWrite( readWrite ), mModified( false ) |
159 | #endif //KAB_EMBEDDED | 165 | #endif //KAB_EMBEDDED |
160 | { | 166 | { |
161 | 167 | ||
168 | mBlockSaveFlag = false; | ||
162 | mExtensionBarSplitter = 0; | 169 | mExtensionBarSplitter = 0; |
163 | mIsPart = !parent->inherits( "KAddressBookMain" ); | 170 | mIsPart = !parent->inherits( "KAddressBookMain" ); |
164 | 171 | ||
165 | mAddressBook = KABC::StdAddressBook::self(); | 172 | mAddressBook = KABC::StdAddressBook::self(); |
166 | KABC::StdAddressBook::setAutomaticSave( false ); | 173 | KABC::StdAddressBook::setAutomaticSave( false ); |
167 | 174 | ||
@@ -1058,12 +1065,15 @@ void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) | |||
1058 | } | 1065 | } |
1059 | 1066 | ||
1060 | } | 1067 | } |
1061 | 1068 | ||
1062 | void KABCore::save() | 1069 | void KABCore::save() |
1063 | { | 1070 | { |
1071 | if (mBlockSaveFlag) | ||
1072 | return; | ||
1073 | mBlockSaveFlag = true; | ||
1064 | if ( !mModified ) | 1074 | if ( !mModified ) |
1065 | return; | 1075 | return; |
1066 | QString text = i18n( "There was an error while attempting to save\n the " | 1076 | QString text = i18n( "There was an error while attempting to save\n the " |
1067 | "address book. Please check that some \nother application is " | 1077 | "address book. Please check that some \nother application is " |
1068 | "not using it. " ); | 1078 | "not using it. " ); |
1069 | statusMessage(i18n("Saving addressbook ... ")); | 1079 | statusMessage(i18n("Saving addressbook ... ")); |
@@ -1078,12 +1088,13 @@ void KABCore::save() | |||
1078 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); | 1088 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); |
1079 | } | 1089 | } |
1080 | #endif //KAB_EMBEDDED | 1090 | #endif //KAB_EMBEDDED |
1081 | 1091 | ||
1082 | statusMessage(i18n("Addressbook saved!")); | 1092 | statusMessage(i18n("Addressbook saved!")); |
1083 | setModified( false ); | 1093 | setModified( false ); |
1094 | mBlockSaveFlag = false; | ||
1084 | } | 1095 | } |
1085 | 1096 | ||
1086 | void KABCore::statusMessage(QString mess , int time ) | 1097 | void KABCore::statusMessage(QString mess , int time ) |
1087 | { | 1098 | { |
1088 | //topLevelWidget()->setCaption( mess ); | 1099 | //topLevelWidget()->setCaption( mess ); |
1089 | // pending setting timer to revome message | 1100 | // pending setting timer to revome message |
@@ -1433,13 +1444,13 @@ void KABCore::initGUI() | |||
1433 | // Viewmanager needs this menu to plugin submenues. | 1444 | // Viewmanager needs this menu to plugin submenues. |
1434 | viewMenu = new QPopupMenu( this ); | 1445 | viewMenu = new QPopupMenu( this ); |
1435 | settingsMenu = new QPopupMenu( this ); | 1446 | settingsMenu = new QPopupMenu( this ); |
1436 | //filterMenu = new QPopupMenu( this ); | 1447 | //filterMenu = new QPopupMenu( this ); |
1437 | ImportMenu = new QPopupMenu( this ); | 1448 | ImportMenu = new QPopupMenu( this ); |
1438 | ExportMenu = new QPopupMenu( this ); | 1449 | ExportMenu = new QPopupMenu( this ); |
1439 | 1450 | syncMenu = new QPopupMenu( this ); | |
1440 | changeMenu= new QPopupMenu( this ); | 1451 | changeMenu= new QPopupMenu( this ); |
1441 | 1452 | ||
1442 | //US since we have no splitter for the embedded system, setup | 1453 | //US since we have no splitter for the embedded system, setup |
1443 | // a layout with two frames. One left and one right. | 1454 | // a layout with two frames. One left and one right. |
1444 | 1455 | ||
1445 | QBoxLayout *topLayout; | 1456 | QBoxLayout *topLayout; |
@@ -1751,12 +1762,13 @@ void KABCore::addActionsManually() | |||
1751 | //US setup menubar. | 1762 | //US setup menubar. |
1752 | //Disable the following block if you do not want to have a menubar. | 1763 | //Disable the following block if you do not want to have a menubar. |
1753 | mb->insertItem( "&File", fileMenu ); | 1764 | mb->insertItem( "&File", fileMenu ); |
1754 | mb->insertItem( "&Edit", editMenu ); | 1765 | mb->insertItem( "&Edit", editMenu ); |
1755 | mb->insertItem( "&View", viewMenu ); | 1766 | mb->insertItem( "&View", viewMenu ); |
1756 | mb->insertItem( "&Settings", settingsMenu ); | 1767 | mb->insertItem( "&Settings", settingsMenu ); |
1768 | mb->insertItem( i18n("Synchronize"), syncMenu ); | ||
1757 | mb->insertItem( "&Change selected", changeMenu ); | 1769 | mb->insertItem( "&Change selected", changeMenu ); |
1758 | mb->insertItem( "&Help", helpMenu ); | 1770 | mb->insertItem( "&Help", helpMenu ); |
1759 | mIncSearchWidget = new IncSearchWidget( tb ); | 1771 | mIncSearchWidget = new IncSearchWidget( tb ); |
1760 | // tb->insertWidget(-1, 0, mIncSearchWidget); | 1772 | // tb->insertWidget(-1, 0, mIncSearchWidget); |
1761 | 1773 | ||
1762 | #else | 1774 | #else |
@@ -1769,12 +1781,13 @@ void KABCore::addActionsManually() | |||
1769 | 1781 | ||
1770 | tb->enableMoving(false); | 1782 | tb->enableMoving(false); |
1771 | popupBarTB->insertItem( "&File", fileMenu ); | 1783 | popupBarTB->insertItem( "&File", fileMenu ); |
1772 | popupBarTB->insertItem( "&Edit", editMenu ); | 1784 | popupBarTB->insertItem( "&Edit", editMenu ); |
1773 | popupBarTB->insertItem( "&View", viewMenu ); | 1785 | popupBarTB->insertItem( "&View", viewMenu ); |
1774 | popupBarTB->insertItem( "&Settings", settingsMenu ); | 1786 | popupBarTB->insertItem( "&Settings", settingsMenu ); |
1787 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); | ||
1775 | mViewManager->getFilterAction()->plug ( popupBarTB); | 1788 | mViewManager->getFilterAction()->plug ( popupBarTB); |
1776 | popupBarTB->insertItem( "&Change selected", changeMenu ); | 1789 | popupBarTB->insertItem( "&Change selected", changeMenu ); |
1777 | popupBarTB->insertItem( "&Help", helpMenu ); | 1790 | popupBarTB->insertItem( "&Help", helpMenu ); |
1778 | if (QApplication::desktop()->width() > 320 ) { | 1791 | if (QApplication::desktop()->width() > 320 ) { |
1779 | // mViewManager->getFilterAction()->plug ( tb); | 1792 | // mViewManager->getFilterAction()->plug ( tb); |
1780 | } | 1793 | } |
@@ -1880,12 +1893,16 @@ void KABCore::addActionsManually() | |||
1880 | 1893 | ||
1881 | //US topLayout->addWidget( mJumpButtonBar ); | 1894 | //US topLayout->addWidget( mJumpButtonBar ); |
1882 | this->layout()->add( mJumpButtonBar ); | 1895 | this->layout()->add( mJumpButtonBar ); |
1883 | */ | 1896 | */ |
1884 | 1897 | ||
1885 | #endif //KAB_EMBEDDED | 1898 | #endif //KAB_EMBEDDED |
1899 | |||
1900 | connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); | ||
1901 | fillSyncMenu(); | ||
1902 | |||
1886 | } | 1903 | } |
1887 | void KABCore::showLicence() | 1904 | void KABCore::showLicence() |
1888 | { | 1905 | { |
1889 | KApplication::showLicence(); | 1906 | KApplication::showLicence(); |
1890 | } | 1907 | } |
1891 | void KABCore::removeVoice() | 1908 | void KABCore::removeVoice() |
@@ -2081,11 +2098,446 @@ void KABCore::requestForDetails(const QString& sourceChannel, const QString& ses | |||
2081 | void KABCore::faq() | 2098 | void KABCore::faq() |
2082 | { | 2099 | { |
2083 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2100 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2084 | } | 2101 | } |
2085 | 2102 | ||
2086 | 2103 | ||
2104 | void KABCore::fillSyncMenu() | ||
2105 | { | ||
2106 | if ( syncMenu->count() ) | ||
2107 | syncMenu->clear(); | ||
2108 | syncMenu->insertItem( i18n("Configure..."), 0 ); | ||
2109 | syncMenu->insertSeparator(); | ||
2110 | syncMenu->insertItem( i18n("Multiple sync"), 1 ); | ||
2111 | syncMenu->insertSeparator(); | ||
2112 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | ||
2113 | config.setGroup("General"); | ||
2114 | QStringList prof = config.readListEntry("SyncProfileNames"); | ||
2115 | KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | ||
2116 | if ( prof.count() < 3 ) { | ||
2117 | prof.clear(); | ||
2118 | prof << i18n("Sharp_DTM"); | ||
2119 | prof << i18n("Local_file"); | ||
2120 | prof << i18n("Last_file"); | ||
2121 | KSyncProfile* temp = new KSyncProfile (); | ||
2122 | temp->setName( prof[0] ); | ||
2123 | temp->writeConfig(&config); | ||
2124 | temp->setName( prof[1] ); | ||
2125 | temp->writeConfig(&config); | ||
2126 | temp->setName( prof[2] ); | ||
2127 | temp->writeConfig(&config); | ||
2128 | config.setGroup("General"); | ||
2129 | config.writeEntry("SyncProfileNames",prof); | ||
2130 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | ||
2131 | config.sync(); | ||
2132 | delete temp; | ||
2133 | } | ||
2134 | KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | ||
2135 | KABPrefs::instance()->mSyncProfileNames = prof; | ||
2136 | int i; | ||
2137 | for ( i = 0; i < prof.count(); ++i ) { | ||
2138 | |||
2139 | syncMenu->insertItem( prof[i], 1000+i ); | ||
2140 | if ( i == 2 ) | ||
2141 | syncMenu->insertSeparator(); | ||
2142 | } | ||
2143 | QDir app_dir; | ||
2144 | if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | ||
2145 | syncMenu->setItemEnabled( false , 1000 ); | ||
2146 | } | ||
2147 | //probaly useless | ||
2148 | //mView->setupExternSyncProfiles(); | ||
2149 | } | ||
2150 | void KABCore::slotSyncMenu( int action ) | ||
2151 | { | ||
2152 | //qDebug("syncaction %d ", action); | ||
2153 | if ( action == 0 ) { | ||
2087 | 2154 | ||
2155 | // seems to be a Qt2 event handling bug | ||
2156 | // syncmenu.clear causes a segfault at first time | ||
2157 | // when we call it after the main event loop, it is ok | ||
2158 | // same behaviour when calling OM/Pi via QCOP for the first time | ||
2159 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | ||
2160 | //confSync(); | ||
2088 | 2161 | ||
2089 | #ifndef KAB_EMBEDDED | 2162 | return; |
2090 | #include "kabcore.moc" | 2163 | } |
2091 | #endif //KAB_EMBEDDED | 2164 | if ( action == 1 ) { |
2165 | multiSync( true ); | ||
2166 | return; | ||
2167 | } | ||
2168 | |||
2169 | if (mBlockSaveFlag) | ||
2170 | return; | ||
2171 | mBlockSaveFlag = true; | ||
2172 | mCurrentSyncProfile = action - 1000 ; | ||
2173 | mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; | ||
2174 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; | ||
2175 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | ||
2176 | KSyncProfile* temp = new KSyncProfile (); | ||
2177 | temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | ||
2178 | temp->readConfig(&config); | ||
2179 | KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | ||
2180 | KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); | ||
2181 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | ||
2182 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | ||
2183 | KABPrefs::instance()->mWriteBackInFuture = 0; | ||
2184 | if ( temp->getWriteBackFuture() ) | ||
2185 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | ||
2186 | KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); | ||
2187 | if ( action == 1000 ) { | ||
2188 | syncSharp(); | ||
2189 | |||
2190 | } else if ( action == 1001 ) { | ||
2191 | syncLocalFile(); | ||
2192 | |||
2193 | } else if ( action == 1002 ) { | ||
2194 | quickSyncLocalFile(); | ||
2195 | |||
2196 | } else if ( action >= 1003 ) { | ||
2197 | if ( temp->getIsLocalFileSync() ) { | ||
2198 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | ||
2199 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); | ||
2200 | } else { | ||
2201 | if ( temp->getIsPhoneSync() ) { | ||
2202 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | ||
2203 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | ||
2204 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | ||
2205 | syncPhone(); | ||
2206 | } else | ||
2207 | syncRemote( temp ); | ||
2208 | |||
2209 | } | ||
2210 | } | ||
2211 | delete temp; | ||
2212 | mBlockSaveFlag = false; | ||
2213 | } | ||
2214 | |||
2215 | void KABCore::syncLocalFile() | ||
2216 | { | ||
2217 | |||
2218 | QString fn =KABPrefs::instance()->mLastSyncedLocalFile; | ||
2219 | |||
2220 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); | ||
2221 | if ( fn == "" ) | ||
2222 | return; | ||
2223 | if ( syncWithFile( fn, false ) ) { | ||
2224 | qDebug("syncLocalFile() successful "); | ||
2225 | } | ||
2226 | |||
2227 | } | ||
2228 | bool KABCore::syncWithFile( QString fn , bool quick ) | ||
2229 | { | ||
2230 | bool ret = false; | ||
2231 | QFileInfo info; | ||
2232 | info.setFile( fn ); | ||
2233 | QString mess; | ||
2234 | bool loadbup = true; | ||
2235 | if ( !info. exists() ) { | ||
2236 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | ||
2237 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | ||
2238 | mess ); | ||
2239 | return ret; | ||
2240 | } | ||
2241 | int result = 0; | ||
2242 | if ( !quick ) { | ||
2243 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | ||
2244 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | ||
2245 | mess, | ||
2246 | i18n("Sync"), i18n("Cancel"), 0, | ||
2247 | 0, 1 ); | ||
2248 | if ( result ) | ||
2249 | return false; | ||
2250 | } | ||
2251 | if ( KABPrefs::instance()->mAskForPreferences ) | ||
2252 | edit_sync_options(); | ||
2253 | if ( result == 0 ) { | ||
2254 | //qDebug("Now sycing ... "); | ||
2255 | if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) | ||
2256 | setCaption( i18n("Synchronization successful") ); | ||
2257 | else | ||
2258 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | ||
2259 | if ( ! quick ) | ||
2260 | KABPrefs::instance()->mLastSyncedLocalFile = fn; | ||
2261 | setModified(); | ||
2262 | } | ||
2263 | return ret; | ||
2264 | } | ||
2265 | void KABCore::quickSyncLocalFile() | ||
2266 | { | ||
2267 | |||
2268 | if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { | ||
2269 | qDebug("quick syncLocalFile() successful "); | ||
2270 | |||
2271 | } | ||
2272 | } | ||
2273 | void KABCore::multiSync( bool askforPrefs ) | ||
2274 | { | ||
2275 | if (mBlockSaveFlag) | ||
2276 | return; | ||
2277 | mBlockSaveFlag = true; | ||
2278 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | ||
2279 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | ||
2280 | question, | ||
2281 | i18n("Yes"), i18n("No"), | ||
2282 | 0, 0 ) != 0 ) { | ||
2283 | mBlockSaveFlag = false; | ||
2284 | setCaption(i18n("Aborted! Nothing synced!")); | ||
2285 | return; | ||
2286 | } | ||
2287 | mCurrentSyncDevice = i18n("Multiple profiles") ; | ||
2288 | KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; | ||
2289 | if ( askforPrefs ) { | ||
2290 | edit_sync_options(); | ||
2291 | KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; | ||
2292 | } | ||
2293 | setCaption(i18n("Multiple sync started.") ); | ||
2294 | qApp->processEvents(); | ||
2295 | int num = ringSync() ; | ||
2296 | if ( num > 1 ) | ||
2297 | ringSync(); | ||
2298 | mBlockSaveFlag = false; | ||
2299 | if ( num ) | ||
2300 | save(); | ||
2301 | if ( num ) | ||
2302 | setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); | ||
2303 | else | ||
2304 | setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | ||
2305 | return; | ||
2306 | } | ||
2307 | int KABCore::ringSync() | ||
2308 | { | ||
2309 | int syncedProfiles = 0; | ||
2310 | int i; | ||
2311 | QTime timer; | ||
2312 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | ||
2313 | QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; | ||
2314 | KSyncProfile* temp = new KSyncProfile (); | ||
2315 | KABPrefs::instance()->mAskForPreferences = false; | ||
2316 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | ||
2317 | mCurrentSyncProfile = i; | ||
2318 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | ||
2319 | temp->readConfig(&config); | ||
2320 | if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) { | ||
2321 | setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | ||
2322 | ++syncedProfiles; | ||
2323 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | ||
2324 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | ||
2325 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | ||
2326 | KABPrefs::instance()->mWriteBackInFuture = 0; | ||
2327 | if ( temp->getWriteBackFuture() ) | ||
2328 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | ||
2329 | KABPrefs::instance()->mShowSyncSummary = false; | ||
2330 | mCurrentSyncDevice = syncProfileNames[i] ; | ||
2331 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; | ||
2332 | if ( i == 0 ) { | ||
2333 | syncSharp(); | ||
2334 | } else { | ||
2335 | if ( temp->getIsLocalFileSync() ) { | ||
2336 | if ( syncWithFile( temp->getRemoteFileName( ), true ) ) | ||
2337 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); | ||
2338 | } else { | ||
2339 | if ( temp->getIsPhoneSync() ) { | ||
2340 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | ||
2341 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | ||
2342 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | ||
2343 | syncPhone(); | ||
2344 | } else | ||
2345 | syncRemote( temp, false ); | ||
2346 | |||
2347 | } | ||
2348 | } | ||
2349 | timer.start(); | ||
2350 | setCaption(i18n("Multiple sync in progress ... please wait!") ); | ||
2351 | while ( timer.elapsed () < 2000 ) { | ||
2352 | qApp->processEvents(); | ||
2353 | #ifndef _WIN32_ | ||
2354 | sleep (1); | ||
2355 | #endif | ||
2356 | } | ||
2357 | |||
2358 | } | ||
2359 | |||
2360 | } | ||
2361 | delete temp; | ||
2362 | return syncedProfiles; | ||
2363 | } | ||
2364 | |||
2365 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) | ||
2366 | { | ||
2367 | QString question; | ||
2368 | if ( ask ) { | ||
2369 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | ||
2370 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | ||
2371 | question, | ||
2372 | i18n("Yes"), i18n("No"), | ||
2373 | 0, 0 ) != 0 ) | ||
2374 | return; | ||
2375 | } | ||
2376 | QString command = prof->getPreSyncCommand(); | ||
2377 | int fi; | ||
2378 | if ( (fi = command.find("$PWD$")) > 0 ) { | ||
2379 | QString pwd = getPassword(); | ||
2380 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | ||
2381 | |||
2382 | } | ||
2383 | int maxlen = 30; | ||
2384 | if ( QApplication::desktop()->width() > 320 ) | ||
2385 | maxlen += 25; | ||
2386 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | ||
2387 | int fileSize = 0; | ||
2388 | int result = system ( command ); | ||
2389 | // 0 : okay | ||
2390 | // 256: no such file or dir | ||
2391 | // | ||
2392 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | ||
2393 | if ( result != 0 ) { | ||
2394 | int len = maxlen; | ||
2395 | while ( len < command.length() ) { | ||
2396 | command.insert( len , "\n" ); | ||
2397 | len += maxlen +2; | ||
2398 | } | ||
2399 | 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) ; | ||
2400 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | ||
2401 | question, | ||
2402 | i18n("Okay!")) ; | ||
2403 | setCaption ("KO/Pi"); | ||
2404 | return; | ||
2405 | } | ||
2406 | setCaption ( i18n( "Copying succeed." ) ); | ||
2407 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | ||
2408 | if ( syncWithFile( prof->getLocalTempFile(), true ) ) { | ||
2409 | // Event* e = mView->getLastSyncEvent(); | ||
2410 | // e->setReadOnly( false ); | ||
2411 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | ||
2412 | // e->setReadOnly( true ); | ||
2413 | if ( KABPrefs::instance()->mWriteBackFile ) { | ||
2414 | command = prof->getPostSyncCommand(); | ||
2415 | int fi; | ||
2416 | if ( (fi = command.find("$PWD$")) > 0 ) { | ||
2417 | QString pwd = getPassword(); | ||
2418 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | ||
2419 | |||
2420 | } | ||
2421 | setCaption ( i18n( "Writing back file ..." ) ); | ||
2422 | result = system ( command ); | ||
2423 | qDebug("KO: Writing back file result: %d ", result); | ||
2424 | if ( result != 0 ) { | ||
2425 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | ||
2426 | return; | ||
2427 | } else { | ||
2428 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | ||
2429 | } | ||
2430 | } | ||
2431 | } | ||
2432 | return; | ||
2433 | } | ||
2434 | #include <qpushbutton.h> | ||
2435 | #include <qradiobutton.h> | ||
2436 | #include <qbuttongroup.h> | ||
2437 | void KABCore::edit_sync_options() | ||
2438 | { | ||
2439 | //mDialogManager->showSyncOptions(); | ||
2440 | //KABPrefs::instance()->mSyncAlgoPrefs | ||
2441 | QDialog dia( this, "dia", true ); | ||
2442 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | ||
2443 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | ||
2444 | QVBoxLayout lay ( &dia ); | ||
2445 | lay.setSpacing( 2 ); | ||
2446 | lay.setMargin( 3 ); | ||
2447 | lay.addWidget(&gr); | ||
2448 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | ||
2449 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | ||
2450 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | ||
2451 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | ||
2452 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | ||
2453 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | ||
2454 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | ||
2455 | QPushButton pb ( "OK", &dia); | ||
2456 | lay.addWidget( &pb ); | ||
2457 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | ||
2458 | switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { | ||
2459 | case 0: | ||
2460 | loc.setChecked( true); | ||
2461 | break; | ||
2462 | case 1: | ||
2463 | rem.setChecked( true ); | ||
2464 | break; | ||
2465 | case 2: | ||
2466 | newest.setChecked( true); | ||
2467 | break; | ||
2468 | case 3: | ||
2469 | ask.setChecked( true); | ||
2470 | break; | ||
2471 | case 4: | ||
2472 | f_loc.setChecked( true); | ||
2473 | break; | ||
2474 | case 5: | ||
2475 | f_rem.setChecked( true); | ||
2476 | break; | ||
2477 | case 6: | ||
2478 | // both.setChecked( true); | ||
2479 | break; | ||
2480 | default: | ||
2481 | break; | ||
2482 | } | ||
2483 | if ( dia.exec() ) { | ||
2484 | KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | ||
2485 | } | ||
2486 | |||
2487 | |||
2488 | } | ||
2489 | QString KABCore::getPassword( ) | ||
2490 | { | ||
2491 | QString retfile = ""; | ||
2492 | QDialog dia ( this, "input-dialog", true ); | ||
2493 | QLineEdit lab ( &dia ); | ||
2494 | lab.setEchoMode( QLineEdit::Password ); | ||
2495 | QVBoxLayout lay( &dia ); | ||
2496 | lay.setMargin(7); | ||
2497 | lay.setSpacing(7); | ||
2498 | lay.addWidget( &lab); | ||
2499 | dia.setFixedSize( 230,50 ); | ||
2500 | dia.setCaption( i18n("Enter password") ); | ||
2501 | QPushButton pb ( "OK", &dia); | ||
2502 | lay.addWidget( &pb ); | ||
2503 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | ||
2504 | dia.show(); | ||
2505 | int res = dia.exec(); | ||
2506 | if ( res ) | ||
2507 | retfile = lab.text(); | ||
2508 | dia.hide(); | ||
2509 | qApp->processEvents(); | ||
2510 | return retfile; | ||
2511 | |||
2512 | } | ||
2513 | |||
2514 | bool KABCore::syncAB(QString filename, int mode) | ||
2515 | { | ||
2516 | |||
2517 | } | ||
2518 | |||
2519 | |||
2520 | void KABCore::confSync() | ||
2521 | { | ||
2522 | //mView->confSync(); | ||
2523 | qDebug("pending KABCore::confSync() "); | ||
2524 | fillSyncMenu(); | ||
2525 | } | ||
2526 | void KABCore::syncSharp() | ||
2527 | { | ||
2528 | if ( mModified ) | ||
2529 | save(); | ||
2530 | qDebug("pending syncSharp() "); | ||
2531 | //mView->syncSharp(); | ||
2532 | mModified = true ; | ||
2533 | |||
2534 | } | ||
2535 | void KABCore::syncPhone() | ||
2536 | { | ||
2537 | if ( mModified ) | ||
2538 | save(); | ||
2539 | qDebug("pending syncPhone(); "); | ||
2540 | //mView->syncPhone(); | ||
2541 | setModified(); | ||
2542 | |||
2543 | } | ||
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 39d043f..10ce8f4 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h | |||
@@ -54,12 +54,13 @@ class XXPortManager; | |||
54 | class JumpButtonBar; | 54 | class JumpButtonBar; |
55 | class IncSearchWidget; | 55 | class IncSearchWidget; |
56 | class KDGanttMinimizeSplitter; | 56 | class KDGanttMinimizeSplitter; |
57 | class KAction; | 57 | class KAction; |
58 | class KActionCollection; | 58 | class KActionCollection; |
59 | class KToggleAction; | 59 | class KToggleAction; |
60 | class KSyncProfile; | ||
60 | 61 | ||
61 | class QAction; | 62 | class QAction; |
62 | class QMenuBar; | 63 | class QMenuBar; |
63 | class QSplitter; | 64 | class QSplitter; |
64 | class ViewContainer; | 65 | class ViewContainer; |
65 | class ViewManager; | 66 | class ViewManager; |
@@ -337,12 +338,13 @@ class KABCore : public QWidget | |||
337 | signals: | 338 | signals: |
338 | void contactSelected( const QString &name ); | 339 | void contactSelected( const QString &name ); |
339 | void contactSelected( const QPixmap &pixmap ); | 340 | void contactSelected( const QPixmap &pixmap ); |
340 | public slots: | 341 | public slots: |
341 | void setDetailsVisible( bool visible ); | 342 | void setDetailsVisible( bool visible ); |
342 | void setDetailsToState(); | 343 | void setDetailsToState(); |
344 | void slotSyncMenu( int ); | ||
343 | private slots: | 345 | private slots: |
344 | void setJumpButtonBarVisible( bool visible ); | 346 | void setJumpButtonBarVisible( bool visible ); |
345 | void importFromOL(); | 347 | void importFromOL(); |
346 | void extensionModified( const KABC::Addressee::List &list ); | 348 | void extensionModified( const KABC::Addressee::List &list ); |
347 | void extensionChanged( int id ); | 349 | void extensionChanged( int id ); |
348 | void clipboardDataChanged(); | 350 | void clipboardDataChanged(); |
@@ -429,13 +431,12 @@ class KABCore : public QWidget | |||
429 | KAction *mActionDeleteView; | 431 | KAction *mActionDeleteView; |
430 | 432 | ||
431 | QPopupMenu *viewMenu; | 433 | QPopupMenu *viewMenu; |
432 | QPopupMenu *filterMenu; | 434 | QPopupMenu *filterMenu; |
433 | QPopupMenu *settingsMenu; | 435 | QPopupMenu *settingsMenu; |
434 | QPopupMenu *changeMenu; | 436 | QPopupMenu *changeMenu; |
435 | |||
436 | //US QAction *mActionSave; | 437 | //US QAction *mActionSave; |
437 | QPopupMenu *ImportMenu; | 438 | QPopupMenu *ImportMenu; |
438 | QPopupMenu *ExportMenu; | 439 | QPopupMenu *ExportMenu; |
439 | //LR additional methods | 440 | //LR additional methods |
440 | KAction *mActionRemoveVoice; | 441 | KAction *mActionRemoveVoice; |
441 | KAction * mActionImportOL; | 442 | KAction * mActionImportOL; |
@@ -443,14 +444,35 @@ class KABCore : public QWidget | |||
443 | #ifndef KAB_EMBEDDED | 444 | #ifndef KAB_EMBEDDED |
444 | KAddressBookService *mAddressBookService; | 445 | KAddressBookService *mAddressBookService; |
445 | #endif //KAB_EMBEDDED | 446 | #endif //KAB_EMBEDDED |
446 | 447 | ||
447 | class KABCorePrivate; | 448 | class KABCorePrivate; |
448 | KABCorePrivate *d; | 449 | KABCorePrivate *d; |
450 | bool mBlockSaveFlag; | ||
449 | 451 | ||
450 | #ifdef KAB_EMBEDDED | 452 | #ifdef KAB_EMBEDDED |
451 | KAddressBookMain *mMainWindow; // should be the same like mGUIClient | 453 | KAddressBookMain *mMainWindow; // should be the same like mGUIClient |
452 | #endif //KAB_EMBEDDED | 454 | #endif //KAB_EMBEDDED |
455 | // LR ******************************* | ||
456 | // sync stuff! | ||
457 | QPopupMenu *syncMenu; | ||
458 | void fillSyncMenu(); | ||
459 | void confSync(); | ||
460 | QString mCurrentSyncDevice; | ||
461 | QString mCurrentSyncName; | ||
462 | void quickSyncLocalFile(); | ||
463 | bool syncWithFile( QString fn , bool quick ); | ||
464 | void KABCore::syncLocalFile(); | ||
465 | void KABCore::syncPhone(); | ||
466 | void KABCore::syncSharp(); | ||
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 | // ********************* | ||
453 | 475 | ||
454 | }; | 476 | }; |
455 | 477 | ||
456 | #endif | 478 | #endif |
diff --git a/kaddressbook/kabprefs.h b/kaddressbook/kabprefs.h index e4f359c..9926aa0 100644 --- a/kaddressbook/kabprefs.h +++ b/kaddressbook/kabprefs.h | |||
@@ -79,13 +79,29 @@ class KABPrefs : public KPimPrefs | |||
79 | QStringList mViewNames; | 79 | QStringList mViewNames; |
80 | 80 | ||
81 | // Filter | 81 | // Filter |
82 | int mCurrentFilter; | 82 | int mCurrentFilter; |
83 | 83 | ||
84 | void setCategoryDefaults(); | 84 | void setCategoryDefaults(); |
85 | 85 | // sync stuff | |
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! | ||
86 | private: | 102 | private: |
87 | KABPrefs(); | 103 | KABPrefs(); |
88 | 104 | ||
89 | static KABPrefs *sInstance; | 105 | static KABPrefs *sInstance; |
90 | }; | 106 | }; |
91 | 107 | ||