-rw-r--r-- | libkdepim/ksyncmanager.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 85a2aeb..db815d6 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -45,194 +45,206 @@ | |||
45 | #include <qapplication.h> | 45 | #include <qapplication.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qdialog.h> | 47 | #include <qdialog.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qtextcodec.h> | 49 | #include <qtextcodec.h> |
50 | #include <qlabel.h> | 50 | #include <qlabel.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | 52 | ||
53 | #include <klocale.h> | 53 | #include <klocale.h> |
54 | #include <kglobal.h> | 54 | #include <kglobal.h> |
55 | #include <kconfig.h> | 55 | #include <kconfig.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | 57 | ||
58 | QDateTime KSyncManager::mRequestedSyncEvent; | 58 | QDateTime KSyncManager::mRequestedSyncEvent; |
59 | 59 | ||
60 | 60 | ||
61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
62 | : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) | 62 | : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) |
63 | { | 63 | { |
64 | mServerSocket = 0; | 64 | mServerSocket = 0; |
65 | bar = new QProgressBar ( 1, 0 ); | 65 | bar = new QProgressBar ( 1, 0 ); |
66 | bar->setCaption (""); | 66 | bar->setCaption (""); |
67 | mWriteBackInPast = 2; | 67 | mWriteBackInPast = 2; |
68 | 68 | ||
69 | 69 | ||
70 | } | 70 | } |
71 | 71 | ||
72 | KSyncManager::~KSyncManager() | 72 | KSyncManager::~KSyncManager() |
73 | { | 73 | { |
74 | delete bar; | 74 | delete bar; |
75 | } | 75 | } |
76 | 76 | ||
77 | void KSyncManager::setDefaultFileName( QString s) | 77 | void KSyncManager::setDefaultFileName( QString s) |
78 | { | 78 | { |
79 | mDefFileName = s ; | 79 | mDefFileName = s ; |
80 | if ( mPrefs->mPassiveSyncAutoStart ) | 80 | if ( mPrefs->mPassiveSyncAutoStart ) |
81 | enableQuick( false ); | 81 | enableQuick( false ); |
82 | } | 82 | } |
83 | 83 | ||
84 | void KSyncManager::fillSyncMenu() | 84 | void KSyncManager::fillSyncMenu() |
85 | { | 85 | { |
86 | if ( mSyncMenu->count() ) | 86 | if ( mSyncMenu->count() ) |
87 | mSyncMenu->clear(); | 87 | mSyncMenu->clear(); |
88 | 88 | ||
89 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 89 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
90 | mSyncMenu->insertSeparator(); | 90 | mSyncMenu->insertSeparator(); |
91 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | 91 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); |
92 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | 92 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); |
93 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | 93 | clearMenu->insertItem( i18n("For all profiles"), 1 ); |
94 | clearMenu->insertSeparator(); | 94 | clearMenu->insertSeparator(); |
95 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | 95 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); |
96 | mSyncMenu->insertSeparator(); | 96 | mSyncMenu->insertSeparator(); |
97 | if ( mServerSocket == 0 ) { | 97 | if ( mServerSocket == 0 ) { |
98 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 98 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
99 | } else { | 99 | } else { |
100 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 100 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
101 | } | 101 | } |
102 | mSyncMenu->insertSeparator(); | 102 | mSyncMenu->insertSeparator(); |
103 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 103 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
104 | mSyncMenu->insertSeparator(); | 104 | mSyncMenu->insertSeparator(); |
105 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 105 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
106 | config.setGroup("General"); | 106 | config.setGroup("General"); |
107 | QStringList prof = config.readListEntry("SyncProfileNames"); | 107 | QStringList prof = config.readListEntry("SyncProfileNames"); |
108 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 108 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
109 | if ( prof.count() < 2 ) { | 109 | if ( prof.count() < 2 ) { |
110 | prof.clear(); | 110 | prof.clear(); |
111 | QString externalName; | 111 | QString externalName; |
112 | #ifdef DESKTOP_VERSION | 112 | #ifdef DESKTOP_VERSION |
113 | #ifdef _WIN32_ | 113 | #ifdef _WIN32_ |
114 | externalName = "OutLook(not_implemented)"; | 114 | externalName = "OutLook(not_implemented)"; |
115 | #else | 115 | #else |
116 | externalName = "KDE_Desktop"; | 116 | externalName = "KDE_Desktop"; |
117 | #endif | 117 | #endif |
118 | #else | 118 | #else |
119 | externalName = "Sharp_DTM"; | 119 | externalName = "Sharp_DTM"; |
120 | #endif | 120 | #endif |
121 | prof << externalName; | 121 | prof << externalName; |
122 | prof << i18n("Local_file"); | 122 | prof << i18n("Local_file"); |
123 | prof << i18n("Last_file"); | 123 | prof << i18n("Last_file"); |
124 | KSyncProfile* temp = new KSyncProfile (); | 124 | KSyncProfile* temp = new KSyncProfile (); |
125 | temp->setName( prof[0] ); | 125 | temp->setName( prof[0] ); |
126 | temp->writeConfig(&config); | 126 | temp->writeConfig(&config); |
127 | temp->setName( prof[1] ); | 127 | temp->setName( prof[1] ); |
128 | temp->writeConfig(&config); | 128 | temp->writeConfig(&config); |
129 | temp->setName( prof[2] ); | 129 | temp->setName( prof[2] ); |
130 | temp->writeConfig(&config); | 130 | temp->writeConfig(&config); |
131 | config.setGroup("General"); | 131 | config.setGroup("General"); |
132 | config.writeEntry("SyncProfileNames",prof); | 132 | config.writeEntry("SyncProfileNames",prof); |
133 | config.writeEntry("ExternSyncProfiles",externalName); | 133 | config.writeEntry("ExternSyncProfiles",externalName); |
134 | config.sync(); | 134 | config.sync(); |
135 | delete temp; | 135 | delete temp; |
136 | } | 136 | } |
137 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 137 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
138 | mSyncProfileNames = prof; | 138 | mSyncProfileNames = prof; |
139 | unsigned int i; | 139 | unsigned int i; |
140 | for ( i = 0; i < prof.count(); ++i ) { | 140 | for ( i = 0; i < prof.count(); ++i ) { |
141 | mSyncMenu->insertItem( prof[i], 1000+i ); | 141 | QString insertText = prof[i]; |
142 | clearMenu->insertItem( prof[i], 1000+i ); | 142 | if ( i == 0 ) { |
143 | #ifdef DESKTOP_VERSION | ||
144 | #ifdef _WIN32_ | ||
145 | insertText = "OutLook(not_implemented)"; | ||
146 | #else | ||
147 | insertText = "KDE_Desktop"; | ||
148 | #endif | ||
149 | #else | ||
150 | insertText = "Sharp_DTM"; | ||
151 | #endif | ||
152 | } | ||
153 | mSyncMenu->insertItem( insertText, 1000+i ); | ||
154 | clearMenu->insertItem( insertText, 1000+i ); | ||
143 | if ( i == 2 ) | 155 | if ( i == 2 ) |
144 | mSyncMenu->insertSeparator(); | 156 | mSyncMenu->insertSeparator(); |
145 | } | 157 | } |
146 | QDir app_dir; | 158 | QDir app_dir; |
147 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 159 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
148 | if ( mTargetApp == PWMPI) { | 160 | if ( mTargetApp == PWMPI) { |
149 | mSyncMenu->removeItem( 1000 ); | 161 | mSyncMenu->removeItem( 1000 ); |
150 | clearMenu->removeItem( 1000 ); | 162 | clearMenu->removeItem( 1000 ); |
151 | } | 163 | } |
152 | #ifndef DESKTOP_VERSION | 164 | #ifndef DESKTOP_VERSION |
153 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 165 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
154 | mSyncMenu->removeItem( 1000 ); | 166 | mSyncMenu->removeItem( 1000 ); |
155 | clearMenu->removeItem( 1000 ); | 167 | clearMenu->removeItem( 1000 ); |
156 | } | 168 | } |
157 | #endif | 169 | #endif |
158 | mSyncMenu->removeItem( 1002 ); | 170 | mSyncMenu->removeItem( 1002 ); |
159 | clearMenu->removeItem( 1002 ); | 171 | clearMenu->removeItem( 1002 ); |
160 | } | 172 | } |
161 | void KSyncManager::slotClearMenu( int action ) | 173 | void KSyncManager::slotClearMenu( int action ) |
162 | { | 174 | { |
163 | QString syncDevice; | 175 | QString syncDevice; |
164 | if ( action > 999 ) { | 176 | if ( action > 999 ) { |
165 | syncDevice = mSyncProfileNames[action - 1000] ; | 177 | syncDevice = mSyncProfileNames[action - 1000] ; |
166 | } | 178 | } |
167 | 179 | ||
168 | 180 | ||
169 | 181 | ||
170 | int result = 0; | 182 | int result = 0; |
171 | QString sd; | 183 | QString sd; |
172 | if ( syncDevice.isEmpty() ) | 184 | if ( syncDevice.isEmpty() ) |
173 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); | 185 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); |
174 | else | 186 | else |
175 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); | 187 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); |
176 | 188 | ||
177 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, | 189 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, |
178 | 0, 1 ); | 190 | 0, 1 ); |
179 | if ( result ) | 191 | if ( result ) |
180 | return; | 192 | return; |
181 | mImplementation->removeSyncInfo( syncDevice ); | 193 | mImplementation->removeSyncInfo( syncDevice ); |
182 | } | 194 | } |
183 | void KSyncManager::slotSyncMenu( int action ) | 195 | void KSyncManager::slotSyncMenu( int action ) |
184 | { | 196 | { |
185 | qDebug("KSM::syncaction %d ", action); | 197 | qDebug("KSM::syncaction %d ", action); |
186 | if ( action == 5000 ) | 198 | if ( action == 5000 ) |
187 | return; | 199 | return; |
188 | mSyncWithDesktop = false; | 200 | mSyncWithDesktop = false; |
189 | if ( action == 0 ) { | 201 | if ( action == 0 ) { |
190 | 202 | ||
191 | // seems to be a Qt2 event handling bug | 203 | // seems to be a Qt2 event handling bug |
192 | // syncmenu.clear causes a segfault at first time | 204 | // syncmenu.clear causes a segfault at first time |
193 | // when we call it after the main event loop, it is ok | 205 | // when we call it after the main event loop, it is ok |
194 | // same behaviour when calling OM/Pi via QCOP for the first time | 206 | // same behaviour when calling OM/Pi via QCOP for the first time |
195 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 207 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
196 | //confSync(); | 208 | //confSync(); |
197 | 209 | ||
198 | return; | 210 | return; |
199 | } | 211 | } |
200 | if ( action == 1 ) { | 212 | if ( action == 1 ) { |
201 | multiSync( true ); | 213 | multiSync( true ); |
202 | return; | 214 | return; |
203 | } | 215 | } |
204 | if ( action == 2 ) { | 216 | if ( action == 2 ) { |
205 | enableQuick(); | 217 | enableQuick(); |
206 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 218 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
207 | return; | 219 | return; |
208 | } | 220 | } |
209 | if ( action == 3 ) { | 221 | if ( action == 3 ) { |
210 | delete mServerSocket; | 222 | delete mServerSocket; |
211 | mServerSocket = 0; | 223 | mServerSocket = 0; |
212 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 224 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
213 | return; | 225 | return; |
214 | } | 226 | } |
215 | 227 | ||
216 | if (blockSave()) | 228 | if (blockSave()) |
217 | return; | 229 | return; |
218 | 230 | ||
219 | setBlockSave(true); | 231 | setBlockSave(true); |
220 | bool silent = false; | 232 | bool silent = false; |
221 | if ( action == 999 ) { | 233 | if ( action == 999 ) { |
222 | //special mode for silent syncing | 234 | //special mode for silent syncing |
223 | action = 1000; | 235 | action = 1000; |
224 | silent = true; | 236 | silent = true; |
225 | } | 237 | } |
226 | 238 | ||
227 | mCurrentSyncProfile = action - 1000 ; | 239 | mCurrentSyncProfile = action - 1000 ; |
228 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 240 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
229 | mCurrentSyncName = mLocalMachineName ; | 241 | mCurrentSyncName = mLocalMachineName ; |
230 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 242 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
231 | KSyncProfile* temp = new KSyncProfile (); | 243 | KSyncProfile* temp = new KSyncProfile (); |
232 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 244 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
233 | temp->readConfig(&config); | 245 | temp->readConfig(&config); |
234 | if (silent) { | 246 | if (silent) { |
235 | mAskForPreferences = false; | 247 | mAskForPreferences = false; |
236 | mShowSyncSummary = false; | 248 | mShowSyncSummary = false; |
237 | mWriteBackFile = true; | 249 | mWriteBackFile = true; |
238 | mSyncAlgoPrefs = 2;// take newest | 250 | mSyncAlgoPrefs = 2;// take newest |