-rw-r--r-- | libkdepim/ksyncmanager.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 038e032..fc0ac6b 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1,243 +1,244 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // $Id$ | 21 | // $Id$ |
22 | 22 | ||
23 | #include "ksyncmanager.h" | 23 | #include "ksyncmanager.h" |
24 | 24 | ||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | 31 | ||
32 | #include "ksyncprofile.h" | 32 | #include "ksyncprofile.h" |
33 | #include "ksyncprefsdialog.h" | 33 | #include "ksyncprefsdialog.h" |
34 | #include "kpimprefs.h" | 34 | #include "kpimprefs.h" |
35 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qprogressbar.h> | 38 | #include <qprogressbar.h> |
39 | #include <qpopupmenu.h> | 39 | #include <qpopupmenu.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qbuttongroup.h> | 42 | #include <qbuttongroup.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
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 | #include <qapplication.h> | ||
52 | 53 | ||
53 | #include <klocale.h> | 54 | #include <klocale.h> |
54 | #include <kglobal.h> | 55 | #include <kglobal.h> |
55 | #include <kconfig.h> | 56 | #include <kconfig.h> |
56 | #include <kfiledialog.h> | 57 | #include <kfiledialog.h> |
57 | 58 | ||
58 | QDateTime KSyncManager::mRequestedSyncEvent; | 59 | QDateTime KSyncManager::mRequestedSyncEvent; |
59 | 60 | ||
60 | 61 | ||
61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 62 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
62 | : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) | 63 | : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) |
63 | { | 64 | { |
64 | mServerSocket = 0; | 65 | mServerSocket = 0; |
65 | bar = new QProgressBar ( 1, 0 ); | 66 | bar = new QProgressBar ( 1, 0 ); |
66 | bar->setCaption (""); | 67 | bar->setCaption (""); |
67 | mWriteBackInPast = 2; | 68 | mWriteBackInPast = 2; |
68 | 69 | ||
69 | 70 | ||
70 | } | 71 | } |
71 | 72 | ||
72 | KSyncManager::~KSyncManager() | 73 | KSyncManager::~KSyncManager() |
73 | { | 74 | { |
74 | delete bar; | 75 | delete bar; |
75 | } | 76 | } |
76 | 77 | ||
77 | void KSyncManager::setDefaultFileName( QString s) | 78 | void KSyncManager::setDefaultFileName( QString s) |
78 | { | 79 | { |
79 | mDefFileName = s ; | 80 | mDefFileName = s ; |
80 | if ( mPrefs->mPassiveSyncAutoStart ) | 81 | if ( mPrefs->mPassiveSyncAutoStart ) |
81 | enableQuick( false ); | 82 | enableQuick( false ); |
82 | } | 83 | } |
83 | 84 | ||
84 | void KSyncManager::fillSyncMenu() | 85 | void KSyncManager::fillSyncMenu() |
85 | { | 86 | { |
86 | if ( mSyncMenu->count() ) | 87 | if ( mSyncMenu->count() ) |
87 | mSyncMenu->clear(); | 88 | mSyncMenu->clear(); |
88 | 89 | ||
89 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 90 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
90 | mSyncMenu->insertSeparator(); | 91 | mSyncMenu->insertSeparator(); |
91 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | 92 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); |
92 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | 93 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); |
93 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | 94 | clearMenu->insertItem( i18n("For all profiles"), 1 ); |
94 | clearMenu->insertSeparator(); | 95 | clearMenu->insertSeparator(); |
95 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | 96 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); |
96 | mSyncMenu->insertSeparator(); | 97 | mSyncMenu->insertSeparator(); |
97 | if ( mServerSocket == 0 ) { | 98 | if ( mServerSocket == 0 ) { |
98 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 99 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
99 | } else { | 100 | } else { |
100 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 101 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
101 | } | 102 | } |
102 | mSyncMenu->insertSeparator(); | 103 | mSyncMenu->insertSeparator(); |
103 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 104 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
104 | mSyncMenu->insertSeparator(); | 105 | mSyncMenu->insertSeparator(); |
105 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 106 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
106 | config.setGroup("General"); | 107 | config.setGroup("General"); |
107 | QStringList prof = config.readListEntry("SyncProfileNames"); | 108 | QStringList prof = config.readListEntry("SyncProfileNames"); |
108 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 109 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
109 | if ( prof.count() < 2 ) { | 110 | if ( prof.count() < 2 ) { |
110 | prof.clear(); | 111 | prof.clear(); |
111 | QString externalName; | 112 | QString externalName; |
112 | #ifdef DESKTOP_VERSION | 113 | #ifdef DESKTOP_VERSION |
113 | #ifdef _WIN32_ | 114 | #ifdef _WIN32_ |
114 | externalName = "OutLook(not_implemented)"; | 115 | externalName = "OutLook(not_implemented)"; |
115 | #else | 116 | #else |
116 | externalName = "KDE_Desktop"; | 117 | externalName = "KDE_Desktop"; |
117 | #endif | 118 | #endif |
118 | #else | 119 | #else |
119 | externalName = "Sharp_DTM"; | 120 | externalName = "Sharp_DTM"; |
120 | #endif | 121 | #endif |
121 | prof << externalName; | 122 | prof << externalName; |
122 | prof << i18n("Local_file"); | 123 | prof << i18n("Local_file"); |
123 | prof << i18n("Last_file"); | 124 | prof << i18n("Last_file"); |
124 | KSyncProfile* temp = new KSyncProfile (); | 125 | KSyncProfile* temp = new KSyncProfile (); |
125 | temp->setName( prof[0] ); | 126 | temp->setName( prof[0] ); |
126 | temp->writeConfig(&config); | 127 | temp->writeConfig(&config); |
127 | temp->setName( prof[1] ); | 128 | temp->setName( prof[1] ); |
128 | temp->writeConfig(&config); | 129 | temp->writeConfig(&config); |
129 | temp->setName( prof[2] ); | 130 | temp->setName( prof[2] ); |
130 | temp->writeConfig(&config); | 131 | temp->writeConfig(&config); |
131 | config.setGroup("General"); | 132 | config.setGroup("General"); |
132 | config.writeEntry("SyncProfileNames",prof); | 133 | config.writeEntry("SyncProfileNames",prof); |
133 | config.writeEntry("ExternSyncProfiles",externalName); | 134 | config.writeEntry("ExternSyncProfiles",externalName); |
134 | config.sync(); | 135 | config.sync(); |
135 | delete temp; | 136 | delete temp; |
136 | } | 137 | } |
137 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 138 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
138 | mSyncProfileNames = prof; | 139 | mSyncProfileNames = prof; |
139 | unsigned int i; | 140 | unsigned int i; |
140 | for ( i = 0; i < prof.count(); ++i ) { | 141 | for ( i = 0; i < prof.count(); ++i ) { |
141 | QString insertText = prof[i]; | 142 | QString insertText = prof[i]; |
142 | if ( i == 0 ) { | 143 | if ( i == 0 ) { |
143 | #ifdef DESKTOP_VERSION | 144 | #ifdef DESKTOP_VERSION |
144 | #ifdef _WIN32_ | 145 | #ifdef _WIN32_ |
145 | insertText = "OutLook(not_implemented)"; | 146 | insertText = "OutLook(not_implemented)"; |
146 | #else | 147 | #else |
147 | insertText = "KDE_Desktop"; | 148 | insertText = "KDE_Desktop"; |
148 | #endif | 149 | #endif |
149 | #else | 150 | #else |
150 | insertText = "Sharp_DTM"; | 151 | insertText = "Sharp_DTM"; |
151 | #endif | 152 | #endif |
152 | } | 153 | } |
153 | mSyncMenu->insertItem( insertText, 1000+i ); | 154 | mSyncMenu->insertItem( insertText, 1000+i ); |
154 | clearMenu->insertItem( insertText, 1000+i ); | 155 | clearMenu->insertItem( insertText, 1000+i ); |
155 | if ( i == 2 ) | 156 | if ( i == 2 ) |
156 | mSyncMenu->insertSeparator(); | 157 | mSyncMenu->insertSeparator(); |
157 | } | 158 | } |
158 | QDir app_dir; | 159 | QDir app_dir; |
159 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 160 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
160 | if ( mTargetApp == PWMPI) { | 161 | if ( mTargetApp == PWMPI) { |
161 | mSyncMenu->removeItem( 1000 ); | 162 | mSyncMenu->removeItem( 1000 ); |
162 | clearMenu->removeItem( 1000 ); | 163 | clearMenu->removeItem( 1000 ); |
163 | } | 164 | } |
164 | #ifndef DESKTOP_VERSION | 165 | #ifndef DESKTOP_VERSION |
165 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 166 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
166 | mSyncMenu->removeItem( 1000 ); | 167 | mSyncMenu->removeItem( 1000 ); |
167 | clearMenu->removeItem( 1000 ); | 168 | clearMenu->removeItem( 1000 ); |
168 | } | 169 | } |
169 | #endif | 170 | #endif |
170 | mSyncMenu->removeItem( 1002 ); | 171 | mSyncMenu->removeItem( 1002 ); |
171 | clearMenu->removeItem( 1002 ); | 172 | clearMenu->removeItem( 1002 ); |
172 | } | 173 | } |
173 | void KSyncManager::slotClearMenu( int action ) | 174 | void KSyncManager::slotClearMenu( int action ) |
174 | { | 175 | { |
175 | QString syncDevice; | 176 | QString syncDevice; |
176 | if ( action > 999 ) { | 177 | if ( action > 999 ) { |
177 | syncDevice = mSyncProfileNames[action - 1000] ; | 178 | syncDevice = mSyncProfileNames[action - 1000] ; |
178 | } | 179 | } |
179 | 180 | ||
180 | 181 | ||
181 | 182 | ||
182 | int result = 0; | 183 | int result = 0; |
183 | QString sd; | 184 | QString sd; |
184 | if ( syncDevice.isEmpty() ) | 185 | if ( syncDevice.isEmpty() ) |
185 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); | 186 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); |
186 | else | 187 | else |
187 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); | 188 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); |
188 | 189 | ||
189 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, | 190 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, |
190 | 0, 1 ); | 191 | 0, 1 ); |
191 | if ( result ) | 192 | if ( result ) |
192 | return; | 193 | return; |
193 | mImplementation->removeSyncInfo( syncDevice ); | 194 | mImplementation->removeSyncInfo( syncDevice ); |
194 | } | 195 | } |
195 | void KSyncManager::slotSyncMenu( int action ) | 196 | void KSyncManager::slotSyncMenu( int action ) |
196 | { | 197 | { |
197 | qDebug("KSM::syncaction %d ", action); | 198 | qDebug("KSM::syncaction %d ", action); |
198 | if ( action == 5000 ) | 199 | if ( action == 5000 ) |
199 | return; | 200 | return; |
200 | mSyncWithDesktop = false; | 201 | mSyncWithDesktop = false; |
201 | if ( action == 0 ) { | 202 | if ( action == 0 ) { |
202 | 203 | ||
203 | // seems to be a Qt2 event handling bug | 204 | // seems to be a Qt2 event handling bug |
204 | // syncmenu.clear causes a segfault at first time | 205 | // syncmenu.clear causes a segfault at first time |
205 | // when we call it after the main event loop, it is ok | 206 | // when we call it after the main event loop, it is ok |
206 | // same behaviour when calling OM/Pi via QCOP for the first time | 207 | // same behaviour when calling OM/Pi via QCOP for the first time |
207 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 208 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
208 | //confSync(); | 209 | //confSync(); |
209 | 210 | ||
210 | return; | 211 | return; |
211 | } | 212 | } |
212 | if ( action == 1 ) { | 213 | if ( action == 1 ) { |
213 | multiSync( true ); | 214 | multiSync( true ); |
214 | return; | 215 | return; |
215 | } | 216 | } |
216 | if ( action == 2 ) { | 217 | if ( action == 2 ) { |
217 | enableQuick(); | 218 | enableQuick(); |
218 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 219 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
219 | return; | 220 | return; |
220 | } | 221 | } |
221 | if ( action == 3 ) { | 222 | if ( action == 3 ) { |
222 | delete mServerSocket; | 223 | delete mServerSocket; |
223 | mServerSocket = 0; | 224 | mServerSocket = 0; |
224 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 225 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
225 | return; | 226 | return; |
226 | } | 227 | } |
227 | 228 | ||
228 | if (blockSave()) | 229 | if (blockSave()) |
229 | return; | 230 | return; |
230 | 231 | ||
231 | setBlockSave(true); | 232 | setBlockSave(true); |
232 | bool silent = false; | 233 | bool silent = false; |
233 | if ( action == 999 ) { | 234 | if ( action == 999 ) { |
234 | //special mode for silent syncing | 235 | //special mode for silent syncing |
235 | action = 1000; | 236 | action = 1000; |
236 | silent = true; | 237 | silent = true; |
237 | } | 238 | } |
238 | 239 | ||
239 | mCurrentSyncProfile = action - 1000 ; | 240 | mCurrentSyncProfile = action - 1000 ; |
240 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 241 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
241 | mCurrentSyncName = mLocalMachineName ; | 242 | mCurrentSyncName = mLocalMachineName ; |
242 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 243 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
243 | KSyncProfile* temp = new KSyncProfile (); | 244 | KSyncProfile* temp = new KSyncProfile (); |