author | zautrix <zautrix> | 2004-09-03 09:23:23 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-03 09:23:23 (UTC) |
commit | d171ed3b09665db0f511310d6c84a23d75135f50 (patch) (unidiff) | |
tree | 557b3fd423a022559971ceafa61def5adbb7e828 /kaddressbook/viewmanager.cpp | |
parent | f6b72fd55671131cd81a3357940c9337ea5d7494 (diff) | |
download | kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.zip kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.tar.gz kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.tar.bz2 |
Much better search possibility in kapi
Diffstat (limited to 'kaddressbook/viewmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/viewmanager.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index 45c7b55..c93d51a 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp | |||
@@ -1,564 +1,571 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program 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 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | 31 | ||
32 | #ifndef KAB_EMBEDDED | 32 | #ifndef KAB_EMBEDDED |
33 | #include <libkdepim/kvcarddrag.h> | 33 | #include <libkdepim/kvcarddrag.h> |
34 | #include <kabc/vcardconverter.h> | 34 | #include <kabc/vcardconverter.h> |
35 | #include <kconfig.h> | 35 | #include <kconfig.h> |
36 | #include <kdeversion.h> | 36 | #include <kdeversion.h> |
37 | #include <kiconloader.h> | 37 | #include <kiconloader.h> |
38 | #include <klocale.h> | 38 | #include <klocale.h> |
39 | #include <kmessagebox.h> | 39 | #include <kmessagebox.h> |
40 | #include <kmultipledrag.h> | 40 | #include <kmultipledrag.h> |
41 | #include <ktrader.h> | 41 | #include <ktrader.h> |
42 | #include <kurldrag.h> | 42 | #include <kurldrag.h> |
43 | 43 | ||
44 | #include "addresseeutil.h" | 44 | #include "addresseeutil.h" |
45 | #else //KAB_EMBEDDED | 45 | #else //KAB_EMBEDDED |
46 | #include "views/kaddressbookiconview.h" | 46 | #include "views/kaddressbookiconview.h" |
47 | #include "views/kaddressbooktableview.h" | 47 | #include "views/kaddressbooktableview.h" |
48 | #include "views/kaddressbookcardview.h" | 48 | #include "views/kaddressbookcardview.h" |
49 | #include "kaddressbookview.h" | 49 | #include "kaddressbookview.h" |
50 | 50 | ||
51 | #include <qaction.h> | 51 | #include <qaction.h> |
52 | #include <qmessagebox.h> | 52 | #include <qmessagebox.h> |
53 | #include <qpopupmenu.h> | 53 | #include <qpopupmenu.h> |
54 | #include <kconfigbase.h> | 54 | #include <kconfigbase.h> |
55 | 55 | ||
56 | #endif //KAB_EMBEDDED | 56 | #endif //KAB_EMBEDDED |
57 | 57 | ||
58 | 58 | ||
59 | #include <kdebug.h> | 59 | #include <kdebug.h> |
60 | #include <kactionclasses.h> | 60 | #include <kactionclasses.h> |
61 | 61 | ||
62 | #include <qlayout.h> | 62 | #include <qlayout.h> |
63 | #include <qwidgetstack.h> | 63 | #include <qwidgetstack.h> |
64 | 64 | ||
65 | #include <kabc/addressbook.h> | 65 | #include <kabc/addressbook.h> |
66 | #include "filtereditdialog.h" | 66 | #include "filtereditdialog.h" |
67 | #include "addviewdialog.h" | 67 | #include "addviewdialog.h" |
68 | #include "kabcore.h" | 68 | #include "kabcore.h" |
69 | #include "kabprefs.h" | 69 | #include "kabprefs.h" |
70 | #include "viewmanager.h" | 70 | #include "viewmanager.h" |
71 | 71 | ||
72 | ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) | 72 | ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) |
73 | : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) | 73 | : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) |
74 | { | 74 | { |
75 | initGUI(); | 75 | initGUI(); |
76 | initActions(); | 76 | initActions(); |
77 | 77 | ||
78 | mViewDict.setAutoDelete( true ); | 78 | mViewDict.setAutoDelete( true ); |
79 | 79 | ||
80 | createViewFactories(); | 80 | createViewFactories(); |
81 | } | 81 | } |
82 | 82 | ||
83 | ViewManager::~ViewManager() | 83 | ViewManager::~ViewManager() |
84 | { | 84 | { |
85 | unloadViews(); | 85 | unloadViews(); |
86 | mViewFactoryDict.clear(); | 86 | mViewFactoryDict.clear(); |
87 | } | 87 | } |
88 | 88 | ||
89 | void ViewManager::restoreSettings() | 89 | void ViewManager::restoreSettings() |
90 | { | 90 | { |
91 | mViewNameList = KABPrefs::instance()->mViewNames; | 91 | mViewNameList = KABPrefs::instance()->mViewNames; |
92 | QString activeViewName = KABPrefs::instance()->mCurrentView; | 92 | QString activeViewName = KABPrefs::instance()->mCurrentView; |
93 | 93 | ||
94 | mActionSelectView->setItems( mViewNameList ); | 94 | mActionSelectView->setItems( mViewNameList ); |
95 | 95 | ||
96 | // Filter | 96 | // Filter |
97 | mFilterList = Filter::restore( mCore->config(), "Filter" ); | 97 | mFilterList = Filter::restore( mCore->config(), "Filter" ); |
98 | mActionSelectFilter->setItems( filterNames() ); | 98 | mActionSelectFilter->setItems( filterNames() ); |
99 | mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); | 99 | mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); |
100 | 100 | ||
101 | // Tell the views to reread their config, since they may have | 101 | // Tell the views to reread their config, since they may have |
102 | // been modified by global settings | 102 | // been modified by global settings |
103 | QString _oldgroup = mCore->config()->group(); | 103 | QString _oldgroup = mCore->config()->group(); |
104 | 104 | ||
105 | QDictIterator<KAddressBookView> it( mViewDict ); | 105 | QDictIterator<KAddressBookView> it( mViewDict ); |
106 | for ( it.toFirst(); it.current(); ++it ) { | 106 | for ( it.toFirst(); it.current(); ++it ) { |
107 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); | 107 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); |
108 | it.current()->readConfig( mCore->config() ); | 108 | it.current()->readConfig( mCore->config() ); |
109 | } | 109 | } |
110 | setActiveView( activeViewName ); | 110 | setActiveView( activeViewName ); |
111 | 111 | ||
112 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 112 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
113 | } | 113 | } |
114 | 114 | ||
115 | void ViewManager::saveSettings() | 115 | void ViewManager::saveSettings() |
116 | { | 116 | { |
117 | QString _oldgroup = mCore->config()->group(); | 117 | QString _oldgroup = mCore->config()->group(); |
118 | 118 | ||
119 | QDictIterator<KAddressBookView> it( mViewDict ); | 119 | QDictIterator<KAddressBookView> it( mViewDict ); |
120 | for ( it.toFirst(); it.current(); ++it ) { | 120 | for ( it.toFirst(); it.current(); ++it ) { |
121 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); | 121 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); |
122 | #ifdef DESKTOP_VERSION | 122 | #ifdef DESKTOP_VERSION |
123 | (*it)->writeConfig( mCore->config() ); | 123 | (*it)->writeConfig( mCore->config() ); |
124 | #else | 124 | #else |
125 | (*it).writeConfig( mCore->config() ); | 125 | (*it).writeConfig( mCore->config() ); |
126 | #endif | 126 | #endif |
127 | } | 127 | } |
128 | 128 | ||
129 | Filter::save( mCore->config(), "Filter", mFilterList ); | 129 | Filter::save( mCore->config(), "Filter", mFilterList ); |
130 | KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); | 130 | KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); |
131 | 131 | ||
132 | // write the view name list | 132 | // write the view name list |
133 | KABPrefs::instance()->mViewNames = mViewNameList; | 133 | KABPrefs::instance()->mViewNames = mViewNameList; |
134 | KABPrefs::instance()->mCurrentView = mActiveView->caption(); | 134 | KABPrefs::instance()->mCurrentView = mActiveView->caption(); |
135 | 135 | ||
136 | } | 136 | } |
137 | 137 | ||
138 | QStringList ViewManager::selectedUids() const | 138 | QStringList ViewManager::selectedUids() const |
139 | { | 139 | { |
140 | if ( mActiveView ) | 140 | if ( mActiveView ) |
141 | return mActiveView->selectedUids(); | 141 | return mActiveView->selectedUids(); |
142 | else | 142 | else |
143 | return QStringList(); | 143 | return QStringList(); |
144 | } | 144 | } |
145 | 145 | ||
146 | QStringList ViewManager::selectedEmails() const | 146 | QStringList ViewManager::selectedEmails() const |
147 | { | 147 | { |
148 | if ( mActiveView ) | 148 | if ( mActiveView ) |
149 | return mActiveView->selectedEmails(); | 149 | return mActiveView->selectedEmails(); |
150 | else | 150 | else |
151 | return QStringList(); | 151 | return QStringList(); |
152 | } | 152 | } |
153 | 153 | ||
154 | KABC::Addressee::List ViewManager::selectedAddressees() const | 154 | KABC::Addressee::List ViewManager::selectedAddressees() const |
155 | { | 155 | { |
156 | KABC::Addressee::List list; | 156 | KABC::Addressee::List list; |
157 | if ( mActiveView ) { | 157 | if ( mActiveView ) { |
158 | QStringList uids = mActiveView->selectedUids(); | 158 | QStringList uids = mActiveView->selectedUids(); |
159 | QStringList::Iterator it; | 159 | QStringList::Iterator it; |
160 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 160 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
161 | KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); | 161 | KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); |
162 | if ( !addr.isEmpty() ) | 162 | if ( !addr.isEmpty() ) |
163 | list.append( addr ); | 163 | list.append( addr ); |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | return list; | 167 | return list; |
168 | } | 168 | } |
169 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 169 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
170 | void ViewManager::setSelected() | 170 | void ViewManager::setSelected() |
171 | { | 171 | { |
172 | setSelected( QString::null, true ); | 172 | setSelected( QString::null, true ); |
173 | } | 173 | } |
174 | 174 | ||
175 | void ViewManager::setSelected( const QString &uid, bool selected ) | 175 | void ViewManager::setSelected( const QString &uid, bool selected ) |
176 | { | 176 | { |
177 | if ( mActiveView ) | 177 | if ( mActiveView ) |
178 | mActiveView->setSelected( uid, selected ); | 178 | mActiveView->setSelected( uid, selected ); |
179 | } | 179 | } |
180 | 180 | ||
181 | void ViewManager::setListSelected(QStringList list) | ||
182 | { | ||
183 | int i, count = list.count(); | ||
184 | for ( i = 0; i < count;++i ) | ||
185 | setSelected( list[i], true ); | ||
186 | |||
187 | } | ||
181 | void ViewManager::unloadViews() | 188 | void ViewManager::unloadViews() |
182 | { | 189 | { |
183 | mViewDict.clear(); | 190 | mViewDict.clear(); |
184 | mActiveView = 0; | 191 | mActiveView = 0; |
185 | } | 192 | } |
186 | 193 | ||
187 | void ViewManager::setActiveView( const QString &name ) | 194 | void ViewManager::setActiveView( const QString &name ) |
188 | { | 195 | { |
189 | KAddressBookView *view = 0; | 196 | KAddressBookView *view = 0; |
190 | 197 | ||
191 | // Check that this isn't the same as the current active view | 198 | // Check that this isn't the same as the current active view |
192 | if ( mActiveView && ( mActiveView->caption() == name ) ) | 199 | if ( mActiveView && ( mActiveView->caption() == name ) ) |
193 | return; | 200 | return; |
194 | 201 | ||
195 | // At this point we know the view that should be active is not | 202 | // At this point we know the view that should be active is not |
196 | // currently active. We will try to find the new on in the list. If | 203 | // currently active. We will try to find the new on in the list. If |
197 | // we can't find it, it means it hasn't been instantiated, so we will | 204 | // we can't find it, it means it hasn't been instantiated, so we will |
198 | // create it on demand. | 205 | // create it on demand. |
199 | 206 | ||
200 | view = mViewDict.find( name ); | 207 | view = mViewDict.find( name ); |
201 | 208 | ||
202 | // Check if we found the view. If we didn't, then we need to create it | 209 | // Check if we found the view. If we didn't, then we need to create it |
203 | if ( view == 0 ) { | 210 | if ( view == 0 ) { |
204 | KConfig *config = mCore->config(); | 211 | KConfig *config = mCore->config(); |
205 | 212 | ||
206 | KConfigGroupSaver saver( config, name ); | 213 | KConfigGroupSaver saver( config, name ); |
207 | 214 | ||
208 | QString type = config->readEntry( "Type", "Table" ); | 215 | QString type = config->readEntry( "Type", "Table" ); |
209 | 216 | ||
210 | kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; | 217 | kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; |
211 | 218 | ||
212 | ViewFactory *factory = mViewFactoryDict.find( type ); | 219 | ViewFactory *factory = mViewFactoryDict.find( type ); |
213 | if ( factory ) | 220 | if ( factory ) |
214 | view = factory->view( mCore->addressBook(), mViewWidgetStack ); | 221 | view = factory->view( mCore->addressBook(), mViewWidgetStack ); |
215 | 222 | ||
216 | if ( view ) { | 223 | if ( view ) { |
217 | view->setCaption( name ); | 224 | view->setCaption( name ); |
218 | mViewDict.insert( name, view ); | 225 | mViewDict.insert( name, view ); |
219 | //US my version needs an int as second parameter to addWidget | 226 | //US my version needs an int as second parameter to addWidget |
220 | mViewWidgetStack->addWidget( view, -1 ); | 227 | mViewWidgetStack->addWidget( view, -1 ); |
221 | view->readConfig( config ); | 228 | view->readConfig( config ); |
222 | 229 | ||
223 | // The manager just relays the signals | 230 | // The manager just relays the signals |
224 | connect( view, SIGNAL( selected( const QString& ) ), | 231 | connect( view, SIGNAL( selected( const QString& ) ), |
225 | SIGNAL( selected( const QString & ) ) ); | 232 | SIGNAL( selected( const QString & ) ) ); |
226 | connect( view, SIGNAL( executed( const QString& ) ), | 233 | connect( view, SIGNAL( executed( const QString& ) ), |
227 | SIGNAL( executed( const QString& ) ) ); | 234 | SIGNAL( executed( const QString& ) ) ); |
228 | 235 | ||
229 | connect( view, SIGNAL( deleteRequest( ) ), | 236 | connect( view, SIGNAL( deleteRequest( ) ), |
230 | SIGNAL( deleteRequest( ) ) ); | 237 | SIGNAL( deleteRequest( ) ) ); |
231 | 238 | ||
232 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); | 239 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); |
233 | connect( view, SIGNAL( dropped( QDropEvent* ) ), | 240 | connect( view, SIGNAL( dropped( QDropEvent* ) ), |
234 | SLOT( dropped( QDropEvent* ) ) ); | 241 | SLOT( dropped( QDropEvent* ) ) ); |
235 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); | 242 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); |
236 | } | 243 | } |
237 | } | 244 | } |
238 | 245 | ||
239 | // If we found or created the view, raise it and refresh it | 246 | // If we found or created the view, raise it and refresh it |
240 | if ( view ) { | 247 | if ( view ) { |
241 | mActiveView = view; | 248 | mActiveView = view; |
242 | mViewWidgetStack->raiseWidget( view ); | 249 | mViewWidgetStack->raiseWidget( view ); |
243 | // Set the proper filter in the view. By setting the combo | 250 | // Set the proper filter in the view. By setting the combo |
244 | // box, the activated slot will be called, which will push | 251 | // box, the activated slot will be called, which will push |
245 | // the filter to the view and refresh it. | 252 | // the filter to the view and refresh it. |
246 | 253 | ||
247 | if ( view->defaultFilterType() == KAddressBookView::None ) { | 254 | if ( view->defaultFilterType() == KAddressBookView::None ) { |
248 | 255 | ||
249 | mActionSelectFilter->setCurrentItem( 0 ); | 256 | mActionSelectFilter->setCurrentItem( 0 ); |
250 | setActiveFilter( 0 ); | 257 | setActiveFilter( 0 ); |
251 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { | 258 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { |
252 | setActiveFilter( mActionSelectFilter->currentItem() ); | 259 | setActiveFilter( mActionSelectFilter->currentItem() ); |
253 | } else { | 260 | } else { |
254 | uint pos = filterPosition( view->defaultFilterName() ); | 261 | uint pos = filterPosition( view->defaultFilterName() ); |
255 | mActionSelectFilter->setCurrentItem( pos ); | 262 | mActionSelectFilter->setCurrentItem( pos ); |
256 | setActiveFilter( pos ); | 263 | setActiveFilter( pos ); |
257 | } | 264 | } |
258 | //US qDebug("ViewManager::setActiveView 6" ); | 265 | //US qDebug("ViewManager::setActiveView 6" ); |
259 | 266 | ||
260 | // Update the inc search widget to show the fields in the new active | 267 | // Update the inc search widget to show the fields in the new active |
261 | // view. | 268 | // view. |
262 | mCore->setSearchFields( mActiveView->fields() ); | 269 | mCore->setSearchFields( mActiveView->fields() ); |
263 | 270 | ||
264 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 271 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
265 | //US mActiveView->refresh(); | 272 | //US mActiveView->refresh(); |
266 | 273 | ||
267 | } | 274 | } |
268 | else | 275 | else |
269 | { | 276 | { |
270 | qDebug("ViewManager::setActiveView: unable to find view" ); | 277 | qDebug("ViewManager::setActiveView: unable to find view" ); |
271 | kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; | 278 | kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; |
272 | } | 279 | } |
273 | } | 280 | } |
274 | 281 | ||
275 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 282 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
276 | void ViewManager::refreshView() | 283 | void ViewManager::refreshView() |
277 | { | 284 | { |
278 | refreshView( QString::null ); | 285 | refreshView( QString::null ); |
279 | } | 286 | } |
280 | 287 | ||
281 | void ViewManager::refreshView( const QString &uid ) | 288 | void ViewManager::refreshView( const QString &uid ) |
282 | { | 289 | { |
283 | if ( mActiveView ) | 290 | if ( mActiveView ) |
284 | mActiveView->refresh( uid ); | 291 | mActiveView->refresh( uid ); |
285 | } | 292 | } |
286 | 293 | ||
287 | void ViewManager::editView() | 294 | void ViewManager::editView() |
288 | { | 295 | { |
289 | if ( !mActiveView ) | 296 | if ( !mActiveView ) |
290 | return; | 297 | return; |
291 | 298 | ||
292 | ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); | 299 | ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); |
293 | ViewConfigureWidget *wdg = 0; | 300 | ViewConfigureWidget *wdg = 0; |
294 | ViewConfigureDialog* dlg = 0; | 301 | ViewConfigureDialog* dlg = 0; |
295 | if ( factory ) { | 302 | if ( factory ) { |
296 | // Save the filters so the dialog has the latest set | 303 | // Save the filters so the dialog has the latest set |
297 | Filter::save( mCore->config(), "Filter", mFilterList ); | 304 | Filter::save( mCore->config(), "Filter", mFilterList ); |
298 | dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); | 305 | dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); |
299 | wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); | 306 | wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); |
300 | } else { | 307 | } else { |
301 | qDebug("ViewManager::editView()::cannot find viewfactory "); | 308 | qDebug("ViewManager::editView()::cannot find viewfactory "); |
302 | return; | 309 | return; |
303 | } | 310 | } |
304 | if ( wdg ) { | 311 | if ( wdg ) { |
305 | dlg->setWidget( wdg ); | 312 | dlg->setWidget( wdg ); |
306 | 313 | ||
307 | #ifndef DESKTOP_VERSION | 314 | #ifndef DESKTOP_VERSION |
308 | //dlg.setMaximumSize( 640, 480 ); | 315 | //dlg.setMaximumSize( 640, 480 ); |
309 | //dlg->setGeometry( 40,40, 400, 300); | 316 | //dlg->setGeometry( 40,40, 400, 300); |
310 | dlg->showMaximized(); | 317 | dlg->showMaximized(); |
311 | #endif | 318 | #endif |
312 | 319 | ||
313 | KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); | 320 | KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); |
314 | 321 | ||
315 | dlg->restoreSettings( mCore->config() ); | 322 | dlg->restoreSettings( mCore->config() ); |
316 | 323 | ||
317 | if ( dlg->exec() ) { | 324 | if ( dlg->exec() ) { |
318 | dlg->saveSettings( mCore->config() ); | 325 | dlg->saveSettings( mCore->config() ); |
319 | mActiveView->readConfig( mCore->config() ); | 326 | mActiveView->readConfig( mCore->config() ); |
320 | 327 | ||
321 | // Set the proper filter in the view. By setting the combo | 328 | // Set the proper filter in the view. By setting the combo |
322 | // box, the activated slot will be called, which will push | 329 | // box, the activated slot will be called, which will push |
323 | // the filter to the view and refresh it. | 330 | // the filter to the view and refresh it. |
324 | if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { | 331 | if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { |
325 | mActionSelectFilter->setCurrentItem( 0 ); | 332 | mActionSelectFilter->setCurrentItem( 0 ); |
326 | setActiveFilter( 0 ); | 333 | setActiveFilter( 0 ); |
327 | } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { | 334 | } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { |
328 | setActiveFilter( mActionSelectFilter->currentItem() ); | 335 | setActiveFilter( mActionSelectFilter->currentItem() ); |
329 | } else { | 336 | } else { |
330 | uint pos = filterPosition( mActiveView->defaultFilterName() ); | 337 | uint pos = filterPosition( mActiveView->defaultFilterName() ); |
331 | mActionSelectFilter->setCurrentItem( pos ); | 338 | mActionSelectFilter->setCurrentItem( pos ); |
332 | setActiveFilter( pos ); | 339 | setActiveFilter( pos ); |
333 | } | 340 | } |
334 | mCore->setSearchFields( mActiveView->fields() ); | 341 | mCore->setSearchFields( mActiveView->fields() ); |
335 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 342 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
336 | //US mActiveView->refresh(); | 343 | //US mActiveView->refresh(); |
337 | 344 | ||
338 | 345 | ||
339 | //US this is a bugfix, that we get notified if we change a views configuration | 346 | //US this is a bugfix, that we get notified if we change a views configuration |
340 | emit modified(); | 347 | emit modified(); |
341 | 348 | ||
342 | } | 349 | } |
343 | 350 | ||
344 | } | 351 | } |
345 | delete dlg; | 352 | delete dlg; |
346 | } | 353 | } |
347 | 354 | ||
348 | void ViewManager::deleteView() | 355 | void ViewManager::deleteView() |
349 | { | 356 | { |
350 | QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) | 357 | QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) |
351 | .arg( mActiveView->caption() ); | 358 | .arg( mActiveView->caption() ); |
352 | QString caption = i18n( "Confirm Delete" ); | 359 | QString caption = i18n( "Confirm Delete" ); |
353 | 360 | ||
354 | 361 | ||
355 | if (QMessageBox::information( this, caption, | 362 | if (QMessageBox::information( this, caption, |
356 | text, | 363 | text, |
357 | i18n("Yes!"), i18n("No"), 0, 0 ) == 0) | 364 | i18n("Yes!"), i18n("No"), 0, 0 ) == 0) |
358 | { | 365 | { |
359 | mViewNameList.remove( mActiveView->caption() ); | 366 | mViewNameList.remove( mActiveView->caption() ); |
360 | 367 | ||
361 | // remove the view from the config file | 368 | // remove the view from the config file |
362 | KConfig *config = mCore->config(); | 369 | KConfig *config = mCore->config(); |
363 | config->deleteGroup( mActiveView->caption() ); | 370 | config->deleteGroup( mActiveView->caption() ); |
364 | 371 | ||
365 | mViewDict.remove( mActiveView->caption() ); | 372 | mViewDict.remove( mActiveView->caption() ); |
366 | mActiveView = 0; | 373 | mActiveView = 0; |
367 | 374 | ||
368 | // we are in an invalid state now, but that should be fixed after | 375 | // we are in an invalid state now, but that should be fixed after |
369 | // we emit the signal | 376 | // we emit the signal |
370 | mActionSelectView->setItems( mViewNameList ); | 377 | mActionSelectView->setItems( mViewNameList ); |
371 | if ( mViewNameList.count() > 0 ) { | 378 | if ( mViewNameList.count() > 0 ) { |
372 | mActionSelectView->setCurrentItem( 0 ); | 379 | mActionSelectView->setCurrentItem( 0 ); |
373 | setActiveView( mViewNameList[ 0 ] ); | 380 | setActiveView( mViewNameList[ 0 ] ); |
374 | } | 381 | } |
375 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 382 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
376 | } | 383 | } |
377 | } | 384 | } |
378 | 385 | ||
379 | void ViewManager::addView() | 386 | void ViewManager::addView() |
380 | { | 387 | { |
381 | AddViewDialog dialog( &mViewFactoryDict, this ); | 388 | AddViewDialog dialog( &mViewFactoryDict, this ); |
382 | 389 | ||
383 | if ( dialog.exec() ) { | 390 | if ( dialog.exec() ) { |
384 | QString newName = dialog.viewName(); | 391 | QString newName = dialog.viewName(); |
385 | QString type = dialog.viewType(); | 392 | QString type = dialog.viewType(); |
386 | 393 | ||
387 | // Check for name conflicts | 394 | // Check for name conflicts |
388 | bool firstConflict = true; | 395 | bool firstConflict = true; |
389 | int numTries = 1; | 396 | int numTries = 1; |
390 | while ( mViewNameList.contains( newName ) > 0 ) { | 397 | while ( mViewNameList.contains( newName ) > 0 ) { |
391 | if ( !firstConflict ) { | 398 | if ( !firstConflict ) { |
392 | newName = newName.left( newName.length() - 4 ); | 399 | newName = newName.left( newName.length() - 4 ); |
393 | firstConflict = false; | 400 | firstConflict = false; |
394 | } | 401 | } |
395 | 402 | ||
396 | newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); | 403 | newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); |
397 | numTries++; | 404 | numTries++; |
398 | } | 405 | } |
399 | 406 | ||
400 | // Add the new one to the list | 407 | // Add the new one to the list |
401 | mViewNameList.append( newName ); | 408 | mViewNameList.append( newName ); |
402 | 409 | ||
403 | // write the view to the config file, | 410 | // write the view to the config file, |
404 | KConfig *config = mCore->config(); | 411 | KConfig *config = mCore->config(); |
405 | 412 | ||
406 | config->deleteGroup( newName ); | 413 | config->deleteGroup( newName ); |
407 | 414 | ||
408 | KConfigGroupSaver saver( config, newName ); | 415 | KConfigGroupSaver saver( config, newName ); |
409 | 416 | ||
410 | config->writeEntry( "Type", type ); | 417 | config->writeEntry( "Type", type ); |
411 | 418 | ||
412 | // try to set the active view | 419 | // try to set the active view |
413 | mActionSelectView->setItems( mViewNameList ); | 420 | mActionSelectView->setItems( mViewNameList ); |
414 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); | 421 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); |
415 | setActiveView( newName ); | 422 | setActiveView( newName ); |
416 | 423 | ||
417 | editView(); | 424 | editView(); |
418 | 425 | ||
419 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 426 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
420 | } | 427 | } |
421 | } | 428 | } |
422 | 429 | ||
423 | void ViewManager::createViewFactories() | 430 | void ViewManager::createViewFactories() |
424 | { | 431 | { |
425 | #ifndef KAB_EMBEDDED | 432 | #ifndef KAB_EMBEDDED |
426 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); | 433 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); |
427 | KTrader::OfferList::ConstIterator it; | 434 | KTrader::OfferList::ConstIterator it; |
428 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 435 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
429 | if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) | 436 | if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) |
430 | continue; | 437 | continue; |
431 | 438 | ||
432 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); | 439 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); |
433 | 440 | ||
434 | if ( !factory ) { | 441 | if ( !factory ) { |
435 | kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; | 442 | kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; |
436 | continue; | 443 | continue; |
437 | } | 444 | } |
438 | 445 | ||
439 | ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); | 446 | ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); |
440 | 447 | ||
441 | if ( !viewFactory ) { | 448 | if ( !viewFactory ) { |
442 | kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; | 449 | kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; |
443 | continue; | 450 | continue; |
444 | } | 451 | } |
445 | 452 | ||
446 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 453 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
447 | } | 454 | } |
448 | 455 | ||
449 | #else //KAB_EMBEDDED | 456 | #else //KAB_EMBEDDED |
450 | ViewFactory* viewFactory = new IconViewFactory(); | 457 | ViewFactory* viewFactory = new IconViewFactory(); |
451 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 458 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
452 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 459 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
453 | 460 | ||
454 | viewFactory = new TableViewFactory(); | 461 | viewFactory = new TableViewFactory(); |
455 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 462 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
456 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 463 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
457 | 464 | ||
458 | viewFactory = new CardViewFactory(); | 465 | viewFactory = new CardViewFactory(); |
459 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 466 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
460 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 467 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
461 | 468 | ||
462 | #endif //KAB_EMBEDDED | 469 | #endif //KAB_EMBEDDED |
463 | 470 | ||
464 | } | 471 | } |
465 | 472 | ||
466 | void ViewManager::dropped( QDropEvent *e ) | 473 | void ViewManager::dropped( QDropEvent *e ) |
467 | { | 474 | { |
468 | kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; | 475 | kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; |
469 | 476 | ||
470 | #ifndef KAB_EMBEDDED | 477 | #ifndef KAB_EMBEDDED |
471 | 478 | ||
472 | QString clipText, vcards; | 479 | QString clipText, vcards; |
473 | KURL::List urls; | 480 | KURL::List urls; |
474 | 481 | ||
475 | if ( KURLDrag::decode( e, urls) ) { | 482 | if ( KURLDrag::decode( e, urls) ) { |
476 | KURL::List::Iterator it = urls.begin(); | 483 | KURL::List::Iterator it = urls.begin(); |
477 | int c = urls.count(); | 484 | int c = urls.count(); |
478 | if ( c > 1 ) { | 485 | if ( c > 1 ) { |
479 | QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); | 486 | QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); |
480 | if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { | 487 | if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { |
481 | for ( ; it != urls.end(); ++it ) | 488 | for ( ; it != urls.end(); ++it ) |
482 | emit urlDropped( *it ); | 489 | emit urlDropped( *it ); |
483 | } | 490 | } |
484 | } else if ( c == 1 ) | 491 | } else if ( c == 1 ) |
485 | emit urlDropped( *it ); | 492 | emit urlDropped( *it ); |
486 | } else if ( KVCardDrag::decode( e, vcards ) ) { | 493 | } else if ( KVCardDrag::decode( e, vcards ) ) { |
487 | KABC::Addressee addr; | 494 | KABC::Addressee addr; |
488 | KABC::VCardConverter converter; | 495 | KABC::VCardConverter converter; |
489 | QStringList list = QStringList::split( "\r\n\r\n", vcards ); | 496 | QStringList list = QStringList::split( "\r\n\r\n", vcards ); |
490 | QStringList::Iterator it; | 497 | QStringList::Iterator it; |
491 | for ( it = list.begin(); it != list.end(); ++it ) { | 498 | for ( it = list.begin(); it != list.end(); ++it ) { |
492 | if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { | 499 | if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { |
493 | KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); | 500 | KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); |
494 | if ( a.isEmpty() ) { | 501 | if ( a.isEmpty() ) { |
495 | mCore->addressBook()->insertAddressee( addr ); | 502 | mCore->addressBook()->insertAddressee( addr ); |
496 | emit modified(); | 503 | emit modified(); |
497 | } | 504 | } |
498 | } | 505 | } |
499 | } | 506 | } |
500 | 507 | ||
501 | mActiveView->refresh(); | 508 | mActiveView->refresh(); |
502 | } | 509 | } |
503 | #else //KAB_EMBEDDED | 510 | #else //KAB_EMBEDDED |
504 | qDebug("ViewManager::dropped() has to be changed!!" ); | 511 | qDebug("ViewManager::dropped() has to be changed!!" ); |
505 | #endif //KAB_EMBEDDED | 512 | #endif //KAB_EMBEDDED |
506 | 513 | ||
507 | } | 514 | } |
508 | 515 | ||
509 | void ViewManager::startDrag() | 516 | void ViewManager::startDrag() |
510 | { | 517 | { |
511 | kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; | 518 | kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; |
512 | 519 | ||
513 | #ifndef KAB_EMBEDDED | 520 | #ifndef KAB_EMBEDDED |
514 | 521 | ||
515 | // Get the list of all the selected addressees | 522 | // Get the list of all the selected addressees |
516 | KABC::Addressee::List addrList; | 523 | KABC::Addressee::List addrList; |
517 | QStringList uidList = selectedUids(); | 524 | QStringList uidList = selectedUids(); |
518 | QStringList::Iterator iter; | 525 | QStringList::Iterator iter; |
519 | for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) | 526 | for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) |
520 | addrList.append( mCore->addressBook()->findByUid( *iter ) ); | 527 | addrList.append( mCore->addressBook()->findByUid( *iter ) ); |
521 | 528 | ||
522 | KMultipleDrag *drag = new KMultipleDrag( this ); | 529 | KMultipleDrag *drag = new KMultipleDrag( this ); |
523 | drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); | 530 | drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); |
524 | KABC::Addressee::List::Iterator it; | 531 | KABC::Addressee::List::Iterator it; |
525 | QStringList vcards; | 532 | QStringList vcards; |
526 | for ( it = addrList.begin(); it != addrList.end(); ++it ) { | 533 | for ( it = addrList.begin(); it != addrList.end(); ++it ) { |
527 | QString vcard = QString::null; | 534 | QString vcard = QString::null; |
528 | KABC::VCardConverter converter; | 535 | KABC::VCardConverter converter; |
529 | if ( converter.addresseeToVCard( *it, vcard ) ) | 536 | if ( converter.addresseeToVCard( *it, vcard ) ) |
530 | vcards.append( vcard ); | 537 | vcards.append( vcard ); |
531 | } | 538 | } |
532 | drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); | 539 | drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); |
533 | 540 | ||
534 | drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); | 541 | drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); |
535 | drag->dragCopy(); | 542 | drag->dragCopy(); |
536 | 543 | ||
537 | #else //KAB_EMBEDDED | 544 | #else //KAB_EMBEDDED |
538 | qDebug("ViewManager::startDrag() has to be changed!!" ); | 545 | qDebug("ViewManager::startDrag() has to be changed!!" ); |
539 | #endif //KAB_EMBEDDED | 546 | #endif //KAB_EMBEDDED |
540 | 547 | ||
541 | } | 548 | } |
542 | 549 | ||
543 | void ViewManager::setActiveFilter( int index ) | 550 | void ViewManager::setActiveFilter( int index ) |
544 | { | 551 | { |
545 | Filter currentFilter; | 552 | Filter currentFilter; |
546 | 553 | ||
547 | if ( ( index - 1 ) < 0 ) | 554 | if ( ( index - 1 ) < 0 ) |
548 | currentFilter = Filter(); | 555 | currentFilter = Filter(); |
549 | else | 556 | else |
550 | currentFilter = mFilterList[ index - 1 ]; | 557 | currentFilter = mFilterList[ index - 1 ]; |
551 | 558 | ||
552 | // Check if we have a view. Since the filter combo is created before | 559 | // Check if we have a view. Since the filter combo is created before |
553 | // the view, this slot could be called before there is a valid view. | 560 | // the view, this slot could be called before there is a valid view. |
554 | if ( mActiveView ) { | 561 | if ( mActiveView ) { |
555 | mActiveView->setFilter( currentFilter ); | 562 | mActiveView->setFilter( currentFilter ); |
556 | mActiveView->refresh(); | 563 | mActiveView->refresh(); |
557 | emit selected( QString::null ); | 564 | emit selected( QString::null ); |
558 | } | 565 | } |
559 | } | 566 | } |
560 | 567 | ||
561 | void ViewManager::configureFilters() | 568 | void ViewManager::configureFilters() |
562 | { | 569 | { |
563 | FilterDialog dlg( this ); | 570 | FilterDialog dlg( this ); |
564 | 571 | ||