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 c738ad8..b5d9419 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp | |||
@@ -1,741 +1,748 @@ | |||
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 <qapplication.h> | 63 | #include <qapplication.h> |
64 | #include <qwidgetstack.h> | 64 | #include <qwidgetstack.h> |
65 | 65 | ||
66 | #include <kabc/addressbook.h> | 66 | #include <kabc/addressbook.h> |
67 | #include "filtereditdialog.h" | 67 | #include "filtereditdialog.h" |
68 | #include "addviewdialog.h" | 68 | #include "addviewdialog.h" |
69 | #include "kabcore.h" | 69 | #include "kabcore.h" |
70 | #include "kabprefs.h" | 70 | #include "kabprefs.h" |
71 | #include "viewmanager.h" | 71 | #include "viewmanager.h" |
72 | 72 | ||
73 | ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) | 73 | ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) |
74 | : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) | 74 | : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) |
75 | { | 75 | { |
76 | initGUI(); | 76 | initGUI(); |
77 | initActions(); | 77 | initActions(); |
78 | 78 | ||
79 | mViewDict.setAutoDelete( true ); | 79 | mViewDict.setAutoDelete( true ); |
80 | 80 | ||
81 | createViewFactories(); | 81 | createViewFactories(); |
82 | } | 82 | } |
83 | 83 | ||
84 | ViewManager::~ViewManager() | 84 | ViewManager::~ViewManager() |
85 | { | 85 | { |
86 | unloadViews(); | 86 | unloadViews(); |
87 | mViewFactoryDict.clear(); | 87 | mViewFactoryDict.clear(); |
88 | } | 88 | } |
89 | void ViewManager::scrollUP() | 89 | void ViewManager::scrollUP() |
90 | { | 90 | { |
91 | if ( mActiveView ) | 91 | if ( mActiveView ) |
92 | mActiveView->scrollUP(); | 92 | mActiveView->scrollUP(); |
93 | } | 93 | } |
94 | void ViewManager::scrollDOWN() | 94 | void ViewManager::scrollDOWN() |
95 | { | 95 | { |
96 | if ( mActiveView ) | 96 | if ( mActiveView ) |
97 | mActiveView->scrollDOWN(); | 97 | mActiveView->scrollDOWN(); |
98 | } | 98 | } |
99 | void ViewManager::restoreSettings() | 99 | void ViewManager::restoreSettings() |
100 | { | 100 | { |
101 | mViewNameList = KABPrefs::instance()->mViewNames; | 101 | mViewNameList = KABPrefs::instance()->mViewNames; |
102 | QString activeViewName = KABPrefs::instance()->mCurrentView; | 102 | QString activeViewName = KABPrefs::instance()->mCurrentView; |
103 | 103 | ||
104 | mActionSelectView->setItems( mViewNameList ); | 104 | mActionSelectView->setItems( mViewNameList ); |
105 | 105 | ||
106 | // Filter | 106 | // Filter |
107 | mFilterList = Filter::restore( mCore->config(), "Filter" ); | 107 | mFilterList = Filter::restore( mCore->config(), "Filter" ); |
108 | mActionSelectFilter->setItems( filterNames() ); | 108 | mActionSelectFilter->setItems( filterNames() ); |
109 | mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); | 109 | mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); |
110 | int cw = 150; | 110 | int cw = 150; |
111 | if ( QApplication::desktop()->width() >= 800 ) | 111 | if ( QApplication::desktop()->width() >= 800 ) |
112 | cw = 200; | 112 | cw = 200; |
113 | if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) | 113 | if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) |
114 | cw = 0; | 114 | cw = 0; |
115 | mActionSelectFilter->setComboWidth( cw ); | 115 | mActionSelectFilter->setComboWidth( cw ); |
116 | // Tell the views to reread their config, since they may have | 116 | // Tell the views to reread their config, since they may have |
117 | // been modified by global settings | 117 | // been modified by global settings |
118 | QString _oldgroup = mCore->config()->group(); | 118 | QString _oldgroup = mCore->config()->group(); |
119 | 119 | ||
120 | QDictIterator<KAddressBookView> it( mViewDict ); | 120 | QDictIterator<KAddressBookView> it( mViewDict ); |
121 | for ( it.toFirst(); it.current(); ++it ) { | 121 | for ( it.toFirst(); it.current(); ++it ) { |
122 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); | 122 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); |
123 | it.current()->readConfig( mCore->config() ); | 123 | it.current()->readConfig( mCore->config() ); |
124 | } | 124 | } |
125 | setActiveView( activeViewName ); | 125 | setActiveView( activeViewName ); |
126 | 126 | ||
127 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 127 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
128 | } | 128 | } |
129 | 129 | ||
130 | void ViewManager::saveSettings() | 130 | void ViewManager::saveSettings() |
131 | { | 131 | { |
132 | QString _oldgroup = mCore->config()->group(); | 132 | QString _oldgroup = mCore->config()->group(); |
133 | 133 | ||
134 | QDictIterator<KAddressBookView> it( mViewDict ); | 134 | QDictIterator<KAddressBookView> it( mViewDict ); |
135 | for ( it.toFirst(); it.current(); ++it ) { | 135 | for ( it.toFirst(); it.current(); ++it ) { |
136 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); | 136 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); |
137 | #ifdef DESKTOP_VERSION | 137 | #ifdef DESKTOP_VERSION |
138 | (*it)->writeConfig( mCore->config() ); | 138 | (*it)->writeConfig( mCore->config() ); |
139 | #else | 139 | #else |
140 | (*it).writeConfig( mCore->config() ); | 140 | (*it).writeConfig( mCore->config() ); |
141 | #endif | 141 | #endif |
142 | } | 142 | } |
143 | 143 | ||
144 | Filter::save( mCore->config(), "Filter", mFilterList ); | 144 | Filter::save( mCore->config(), "Filter", mFilterList ); |
145 | KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); | 145 | KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); |
146 | 146 | ||
147 | // write the view name list | 147 | // write the view name list |
148 | KABPrefs::instance()->mViewNames = mViewNameList; | 148 | KABPrefs::instance()->mViewNames = mViewNameList; |
149 | KABPrefs::instance()->mCurrentView = mActiveView->caption(); | 149 | KABPrefs::instance()->mCurrentView = mActiveView->caption(); |
150 | 150 | ||
151 | } | 151 | } |
152 | 152 | ||
153 | QStringList ViewManager::selectedUids() const | 153 | QStringList ViewManager::selectedUids() const |
154 | { | 154 | { |
155 | if ( mActiveView ) | 155 | if ( mActiveView ) |
156 | return mActiveView->selectedUids(); | 156 | return mActiveView->selectedUids(); |
157 | else | 157 | else |
158 | return QStringList(); | 158 | return QStringList(); |
159 | } | 159 | } |
160 | 160 | ||
161 | QStringList ViewManager::selectedEmails() const | 161 | QStringList ViewManager::selectedEmails() const |
162 | { | 162 | { |
163 | if ( mActiveView ) | 163 | if ( mActiveView ) |
164 | return mActiveView->selectedEmails(); | 164 | return mActiveView->selectedEmails(); |
165 | else | 165 | else |
166 | return QStringList(); | 166 | return QStringList(); |
167 | } | 167 | } |
168 | 168 | ||
169 | KABC::Addressee::List ViewManager::selectedAddressees() const | 169 | KABC::Addressee::List ViewManager::selectedAddressees() const |
170 | { | 170 | { |
171 | KABC::Addressee::List list; | 171 | KABC::Addressee::List list; |
172 | if ( mActiveView ) { | 172 | if ( mActiveView ) { |
173 | QStringList uids = mActiveView->selectedUids(); | 173 | QStringList uids = mActiveView->selectedUids(); |
174 | QStringList::Iterator it; | 174 | QStringList::Iterator it; |
175 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 175 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
176 | KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); | 176 | KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); |
177 | if ( !addr.isEmpty() ) | 177 | if ( !addr.isEmpty() ) |
178 | list.append( addr ); | 178 | list.append( addr ); |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | return list; | 182 | return list; |
183 | } | 183 | } |
184 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 184 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
185 | void ViewManager::setSelected() | 185 | void ViewManager::setSelected() |
186 | { | 186 | { |
187 | setSelected( QString::null, true ); | 187 | setSelected( QString::null, true ); |
188 | } | 188 | } |
189 | 189 | ||
190 | void ViewManager::setSelected( const QString &uid, bool selected ) | 190 | void ViewManager::setSelected( const QString &uid, bool selected ) |
191 | { | 191 | { |
192 | if ( mActiveView ) | 192 | if ( mActiveView ) |
193 | mActiveView->setSelected( uid, selected ); | 193 | mActiveView->setSelected( uid, selected ); |
194 | } | 194 | } |
195 | 195 | ||
196 | void ViewManager::setListSelected(QStringList list) | 196 | void ViewManager::setListSelected(QStringList list) |
197 | { | 197 | { |
198 | int i, count = list.count(); | 198 | int i, count = list.count(); |
199 | for ( i = 0; i < count;++i ) | 199 | for ( i = 0; i < count;++i ) |
200 | setSelected( list[i], true ); | 200 | setSelected( list[i], true ); |
201 | 201 | ||
202 | } | 202 | } |
203 | void ViewManager::unloadViews() | 203 | void ViewManager::unloadViews() |
204 | { | 204 | { |
205 | mViewDict.clear(); | 205 | mViewDict.clear(); |
206 | mActiveView = 0; | 206 | mActiveView = 0; |
207 | } | 207 | } |
208 | 208 | ||
209 | void ViewManager::selectView( const QString &name ) | 209 | void ViewManager::selectView( const QString &name ) |
210 | { | 210 | { |
211 | setActiveView( name ); | 211 | setActiveView( name ); |
212 | mCore->saveSettings(); | 212 | mCore->saveSettings(); |
213 | } | 213 | } |
214 | void ViewManager::setActiveView( const QString &name ) | 214 | void ViewManager::setActiveView( const QString &name ) |
215 | { | 215 | { |
216 | KAddressBookView *view = 0; | 216 | KAddressBookView *view = 0; |
217 | 217 | ||
218 | // Check that this isn't the same as the current active view | 218 | // Check that this isn't the same as the current active view |
219 | if ( mActiveView && ( mActiveView->caption() == name ) ) | 219 | if ( mActiveView && ( mActiveView->caption() == name ) ) |
220 | return; | 220 | return; |
221 | 221 | ||
222 | // At this point we know the view that should be active is not | 222 | // At this point we know the view that should be active is not |
223 | // currently active. We will try to find the new on in the list. If | 223 | // currently active. We will try to find the new on in the list. If |
224 | // we can't find it, it means it hasn't been instantiated, so we will | 224 | // we can't find it, it means it hasn't been instantiated, so we will |
225 | // create it on demand. | 225 | // create it on demand. |
226 | 226 | ||
227 | view = mViewDict.find( name ); | 227 | view = mViewDict.find( name ); |
228 | 228 | ||
229 | // Check if we found the view. If we didn't, then we need to create it | 229 | // Check if we found the view. If we didn't, then we need to create it |
230 | if ( view == 0 ) { | 230 | if ( view == 0 ) { |
231 | KConfig *config = mCore->config(); | 231 | KConfig *config = mCore->config(); |
232 | 232 | ||
233 | KConfigGroupSaver saver( config, name ); | 233 | KConfigGroupSaver saver( config, name ); |
234 | 234 | ||
235 | QString type = config->readEntry( "Type", "Table" ); | 235 | QString type = config->readEntry( "Type", "Table" ); |
236 | 236 | ||
237 | kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; | 237 | kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; |
238 | 238 | ||
239 | ViewFactory *factory = mViewFactoryDict.find( type ); | 239 | ViewFactory *factory = mViewFactoryDict.find( type ); |
240 | if ( factory ) | 240 | if ( factory ) |
241 | view = factory->view( mCore->addressBook(), mViewWidgetStack ); | 241 | view = factory->view( mCore->addressBook(), mViewWidgetStack ); |
242 | 242 | ||
243 | if ( view ) { | 243 | if ( view ) { |
244 | if ( !mViewNameList.contains( name ) ) { | ||
245 | mViewNameList.append( name ); | ||
246 | } | ||
244 | view->setCaption( name ); | 247 | view->setCaption( name ); |
245 | mViewDict.insert( name, view ); | 248 | mViewDict.insert( name, view ); |
246 | //US my version needs an int as second parameter to addWidget | 249 | //US my version needs an int as second parameter to addWidget |
247 | mViewWidgetStack->addWidget( view, -1 ); | 250 | mViewWidgetStack->addWidget( view, -1 ); |
248 | view->readConfig( config ); | 251 | view->readConfig( config ); |
249 | 252 | ||
250 | // The manager just relays the signals | 253 | // The manager just relays the signals |
251 | connect( view, SIGNAL( selected( const QString& ) ), | 254 | connect( view, SIGNAL( selected( const QString& ) ), |
252 | SIGNAL( selected( const QString & ) ) ); | 255 | SIGNAL( selected( const QString & ) ) ); |
253 | connect( view, SIGNAL( executed( const QString& ) ), | 256 | connect( view, SIGNAL( executed( const QString& ) ), |
254 | SIGNAL( executed( const QString& ) ) ); | 257 | SIGNAL( executed( const QString& ) ) ); |
255 | 258 | ||
256 | connect( view, SIGNAL( deleteRequest( ) ), | 259 | connect( view, SIGNAL( deleteRequest( ) ), |
257 | SIGNAL( deleteRequest( ) ) ); | 260 | SIGNAL( deleteRequest( ) ) ); |
258 | 261 | ||
259 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); | 262 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); |
260 | connect( view, SIGNAL( dropped( QDropEvent* ) ), | 263 | connect( view, SIGNAL( dropped( QDropEvent* ) ), |
261 | SLOT( dropped( QDropEvent* ) ) ); | 264 | SLOT( dropped( QDropEvent* ) ) ); |
262 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); | 265 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); |
263 | } | 266 | } |
264 | } | 267 | } |
265 | 268 | ||
266 | // If we found or created the view, raise it and refresh it | 269 | // If we found or created the view, raise it and refresh it |
267 | if ( view ) { | 270 | if ( view ) { |
268 | mActiveView = view; | 271 | mActiveView = view; |
269 | mViewWidgetStack->raiseWidget( view ); | 272 | mViewWidgetStack->raiseWidget( view ); |
270 | // Set the proper filter in the view. By setting the combo | 273 | // Set the proper filter in the view. By setting the combo |
271 | // box, the activated slot will be called, which will push | 274 | // box, the activated slot will be called, which will push |
272 | // the filter to the view and refresh it. | 275 | // the filter to the view and refresh it. |
273 | 276 | ||
274 | if ( view->defaultFilterType() == KAddressBookView::None ) { | 277 | if ( view->defaultFilterType() == KAddressBookView::None ) { |
275 | 278 | ||
276 | mActionSelectFilter->setCurrentItem( 0 ); | 279 | mActionSelectFilter->setCurrentItem( 0 ); |
277 | setActiveFilter( 0 ); | 280 | setActiveFilter( 0 ); |
278 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { | 281 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { |
279 | setActiveFilter( mActionSelectFilter->currentItem() ); | 282 | setActiveFilter( mActionSelectFilter->currentItem() ); |
280 | } else { | 283 | } else { |
281 | uint pos = filterPosition( view->defaultFilterName() ); | 284 | uint pos = filterPosition( view->defaultFilterName() ); |
282 | mActionSelectFilter->setCurrentItem( pos ); | 285 | mActionSelectFilter->setCurrentItem( pos ); |
283 | setActiveFilter( pos ); | 286 | setActiveFilter( pos ); |
284 | } | 287 | } |
285 | //US qDebug("ViewManager::setActiveView 6" ); | 288 | //US qDebug("ViewManager::setActiveView 6" ); |
286 | 289 | ||
287 | // Update the inc search widget to show the fields in the new active | 290 | // Update the inc search widget to show the fields in the new active |
288 | // view. | 291 | // view. |
289 | mCore->setSearchFields( mActiveView->fields() ); | 292 | mCore->setSearchFields( mActiveView->fields() ); |
290 | 293 | ||
291 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 294 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
292 | //US mActiveView->refresh(); | 295 | //US mActiveView->refresh(); |
296 | |||
297 | mActionSelectView->setItems( mViewNameList ); | ||
298 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( mActiveView->caption() ) ); | ||
299 | |||
293 | } | 300 | } |
294 | else | 301 | else |
295 | { | 302 | { |
296 | qDebug("ViewManager::setActiveView: unable to find view" ); | 303 | qDebug("ViewManager::setActiveView: unable to find view" ); |
297 | } | 304 | } |
298 | } | 305 | } |
299 | 306 | ||
300 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 307 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
301 | void ViewManager::refreshView() | 308 | void ViewManager::refreshView() |
302 | { | 309 | { |
303 | refreshView( QString::null ); | 310 | refreshView( QString::null ); |
304 | } | 311 | } |
305 | 312 | ||
306 | void ViewManager::refreshView( const QString &uid ) | 313 | void ViewManager::refreshView( const QString &uid ) |
307 | { | 314 | { |
308 | if ( mActiveView ) | 315 | if ( mActiveView ) |
309 | mActiveView->refresh( uid ); | 316 | mActiveView->refresh( uid ); |
310 | } | 317 | } |
311 | 318 | ||
312 | void ViewManager::setFocusAV() | 319 | void ViewManager::setFocusAV() |
313 | { | 320 | { |
314 | if ( mActiveView ) | 321 | if ( mActiveView ) |
315 | mActiveView->setFocusAV(); | 322 | mActiveView->setFocusAV(); |
316 | } | 323 | } |
317 | void ViewManager::editView() | 324 | void ViewManager::editView() |
318 | { | 325 | { |
319 | if ( !mActiveView ) | 326 | if ( !mActiveView ) |
320 | return; | 327 | return; |
321 | 328 | ||
322 | ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); | 329 | ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); |
323 | ViewConfigureWidget *wdg = 0; | 330 | ViewConfigureWidget *wdg = 0; |
324 | ViewConfigureDialog* dlg = 0; | 331 | ViewConfigureDialog* dlg = 0; |
325 | if ( factory ) { | 332 | if ( factory ) { |
326 | // Save the filters so the dialog has the latest set | 333 | // Save the filters so the dialog has the latest set |
327 | Filter::save( mCore->config(), "Filter", mFilterList ); | 334 | Filter::save( mCore->config(), "Filter", mFilterList ); |
328 | dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); | 335 | dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); |
329 | wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); | 336 | wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); |
330 | } else { | 337 | } else { |
331 | qDebug("ViewManager::editView()::cannot find viewfactory "); | 338 | qDebug("ViewManager::editView()::cannot find viewfactory "); |
332 | return; | 339 | return; |
333 | } | 340 | } |
334 | if ( wdg ) { | 341 | if ( wdg ) { |
335 | dlg->setWidget( wdg ); | 342 | dlg->setWidget( wdg ); |
336 | 343 | ||
337 | #ifndef DESKTOP_VERSION | 344 | #ifndef DESKTOP_VERSION |
338 | //dlg.setMaximumSize( 640, 480 ); | 345 | //dlg.setMaximumSize( 640, 480 ); |
339 | //dlg->setGeometry( 40,40, 400, 300); | 346 | //dlg->setGeometry( 40,40, 400, 300); |
340 | dlg->showMaximized(); | 347 | dlg->showMaximized(); |
341 | #endif | 348 | #endif |
342 | 349 | ||
343 | KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); | 350 | KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); |
344 | 351 | ||
345 | dlg->restoreSettings( mCore->config() ); | 352 | dlg->restoreSettings( mCore->config() ); |
346 | 353 | ||
347 | if ( dlg->exec() ) { | 354 | if ( dlg->exec() ) { |
348 | dlg->saveSettings( mCore->config() ); | 355 | dlg->saveSettings( mCore->config() ); |
349 | mActiveView->readConfig( mCore->config() ); | 356 | mActiveView->readConfig( mCore->config() ); |
350 | 357 | ||
351 | // Set the proper filter in the view. By setting the combo | 358 | // Set the proper filter in the view. By setting the combo |
352 | // box, the activated slot will be called, which will push | 359 | // box, the activated slot will be called, which will push |
353 | // the filter to the view and refresh it. | 360 | // the filter to the view and refresh it. |
354 | if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { | 361 | if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { |
355 | mActionSelectFilter->setCurrentItem( 0 ); | 362 | mActionSelectFilter->setCurrentItem( 0 ); |
356 | setActiveFilter( 0 ); | 363 | setActiveFilter( 0 ); |
357 | } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { | 364 | } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { |
358 | setActiveFilter( mActionSelectFilter->currentItem() ); | 365 | setActiveFilter( mActionSelectFilter->currentItem() ); |
359 | } else { | 366 | } else { |
360 | uint pos = filterPosition( mActiveView->defaultFilterName() ); | 367 | uint pos = filterPosition( mActiveView->defaultFilterName() ); |
361 | mActionSelectFilter->setCurrentItem( pos ); | 368 | mActionSelectFilter->setCurrentItem( pos ); |
362 | setActiveFilter( pos ); | 369 | setActiveFilter( pos ); |
363 | } | 370 | } |
364 | mCore->setSearchFields( mActiveView->fields() ); | 371 | mCore->setSearchFields( mActiveView->fields() ); |
365 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 372 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
366 | //US mActiveView->refresh(); | 373 | //US mActiveView->refresh(); |
367 | 374 | ||
368 | 375 | ||
369 | //US this is a bugfix, that we get notified if we change a views configuration | 376 | //US this is a bugfix, that we get notified if we change a views configuration |
370 | emit modified(); | 377 | emit modified(); |
371 | 378 | ||
372 | } | 379 | } |
373 | 380 | ||
374 | } | 381 | } |
375 | delete dlg; | 382 | delete dlg; |
376 | } | 383 | } |
377 | 384 | ||
378 | void ViewManager::deleteView() | 385 | void ViewManager::deleteView() |
379 | { | 386 | { |
380 | QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) | 387 | QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) |
381 | .arg( mActiveView->caption() ); | 388 | .arg( mActiveView->caption() ); |
382 | QString caption = i18n( "Confirm Delete" ); | 389 | QString caption = i18n( "Confirm Delete" ); |
383 | 390 | ||
384 | 391 | ||
385 | if (QMessageBox::information( this, caption, | 392 | if (QMessageBox::information( this, caption, |
386 | text, | 393 | text, |
387 | i18n("Yes!"), i18n("No"), 0, 0 ) == 0) | 394 | i18n("Yes!"), i18n("No"), 0, 0 ) == 0) |
388 | { | 395 | { |
389 | mViewNameList.remove( mActiveView->caption() ); | 396 | mViewNameList.remove( mActiveView->caption() ); |
390 | 397 | ||
391 | // remove the view from the config file | 398 | // remove the view from the config file |
392 | KConfig *config = mCore->config(); | 399 | KConfig *config = mCore->config(); |
393 | config->deleteGroup( mActiveView->caption() ); | 400 | config->deleteGroup( mActiveView->caption() ); |
394 | 401 | ||
395 | mViewDict.remove( mActiveView->caption() ); | 402 | mViewDict.remove( mActiveView->caption() ); |
396 | mActiveView = 0; | 403 | mActiveView = 0; |
397 | 404 | ||
398 | // we are in an invalid state now, but that should be fixed after | 405 | // we are in an invalid state now, but that should be fixed after |
399 | // we emit the signal | 406 | // we emit the signal |
400 | mActionSelectView->setItems( mViewNameList ); | 407 | mActionSelectView->setItems( mViewNameList ); |
401 | if ( mViewNameList.count() > 0 ) { | 408 | if ( mViewNameList.count() > 0 ) { |
402 | mActionSelectView->setCurrentItem( 0 ); | 409 | mActionSelectView->setCurrentItem( 0 ); |
403 | setActiveView( mViewNameList[ 0 ] ); | 410 | setActiveView( mViewNameList[ 0 ] ); |
404 | } | 411 | } |
405 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 412 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
406 | } | 413 | } |
407 | } | 414 | } |
408 | 415 | ||
409 | void ViewManager::addView() | 416 | void ViewManager::addView() |
410 | { | 417 | { |
411 | AddViewDialog dialog( &mViewFactoryDict, this ); | 418 | AddViewDialog dialog( &mViewFactoryDict, this ); |
412 | 419 | ||
413 | if ( dialog.exec() ) { | 420 | if ( dialog.exec() ) { |
414 | QString newName = dialog.viewName(); | 421 | QString newName = dialog.viewName(); |
415 | QString type = dialog.viewType(); | 422 | QString type = dialog.viewType(); |
416 | 423 | ||
417 | // Check for name conflicts | 424 | // Check for name conflicts |
418 | bool firstConflict = true; | 425 | bool firstConflict = true; |
419 | int numTries = 1; | 426 | int numTries = 1; |
420 | while ( mViewNameList.contains( newName ) > 0 ) { | 427 | while ( mViewNameList.contains( newName ) > 0 ) { |
421 | if ( !firstConflict ) { | 428 | if ( !firstConflict ) { |
422 | newName = newName.left( newName.length() - 4 ); | 429 | newName = newName.left( newName.length() - 4 ); |
423 | firstConflict = false; | 430 | firstConflict = false; |
424 | } | 431 | } |
425 | 432 | ||
426 | newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); | 433 | newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); |
427 | numTries++; | 434 | numTries++; |
428 | } | 435 | } |
429 | 436 | ||
430 | // Add the new one to the list | 437 | // Add the new one to the list |
431 | mViewNameList.append( newName ); | 438 | mViewNameList.append( newName ); |
432 | 439 | ||
433 | // write the view to the config file, | 440 | // write the view to the config file, |
434 | KConfig *config = mCore->config(); | 441 | KConfig *config = mCore->config(); |
435 | 442 | ||
436 | config->deleteGroup( newName ); | 443 | config->deleteGroup( newName ); |
437 | 444 | ||
438 | KConfigGroupSaver saver( config, newName ); | 445 | KConfigGroupSaver saver( config, newName ); |
439 | 446 | ||
440 | config->writeEntry( "Type", type ); | 447 | config->writeEntry( "Type", type ); |
441 | 448 | ||
442 | // try to set the active view | 449 | // try to set the active view |
443 | mActionSelectView->setItems( mViewNameList ); | 450 | mActionSelectView->setItems( mViewNameList ); |
444 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); | 451 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); |
445 | setActiveView( newName ); | 452 | setActiveView( newName ); |
446 | 453 | ||
447 | editView(); | 454 | editView(); |
448 | 455 | ||
449 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 456 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
450 | } | 457 | } |
451 | } | 458 | } |
452 | 459 | ||
453 | void ViewManager::createViewFactories() | 460 | void ViewManager::createViewFactories() |
454 | { | 461 | { |
455 | #ifndef KAB_EMBEDDED | 462 | #ifndef KAB_EMBEDDED |
456 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); | 463 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); |
457 | KTrader::OfferList::ConstIterator it; | 464 | KTrader::OfferList::ConstIterator it; |
458 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 465 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
459 | if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) | 466 | if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) |
460 | continue; | 467 | continue; |
461 | 468 | ||
462 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); | 469 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); |
463 | 470 | ||
464 | if ( !factory ) { | 471 | if ( !factory ) { |
465 | kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; | 472 | kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; |
466 | continue; | 473 | continue; |
467 | } | 474 | } |
468 | 475 | ||
469 | ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); | 476 | ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); |
470 | 477 | ||
471 | if ( !viewFactory ) { | 478 | if ( !viewFactory ) { |
472 | kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; | 479 | kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; |
473 | continue; | 480 | continue; |
474 | } | 481 | } |
475 | 482 | ||
476 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 483 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
477 | } | 484 | } |
478 | 485 | ||
479 | #else //KAB_EMBEDDED | 486 | #else //KAB_EMBEDDED |
480 | ViewFactory* viewFactory = new IconViewFactory(); | 487 | ViewFactory* viewFactory = new IconViewFactory(); |
481 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 488 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
482 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 489 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
483 | 490 | ||
484 | viewFactory = new TableViewFactory(); | 491 | viewFactory = new TableViewFactory(); |
485 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 492 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
486 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 493 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
487 | 494 | ||
488 | viewFactory = new CardViewFactory(); | 495 | viewFactory = new CardViewFactory(); |
489 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 496 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
490 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 497 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
491 | 498 | ||
492 | #endif //KAB_EMBEDDED | 499 | #endif //KAB_EMBEDDED |
493 | 500 | ||
494 | } | 501 | } |
495 | 502 | ||
496 | void ViewManager::dropped( QDropEvent *e ) | 503 | void ViewManager::dropped( QDropEvent *e ) |
497 | { | 504 | { |
498 | 505 | ||
499 | #ifndef KAB_EMBEDDED | 506 | #ifndef KAB_EMBEDDED |
500 | 507 | ||
501 | QString clipText, vcards; | 508 | QString clipText, vcards; |
502 | KURL::List urls; | 509 | KURL::List urls; |
503 | 510 | ||
504 | if ( KURLDrag::decode( e, urls) ) { | 511 | if ( KURLDrag::decode( e, urls) ) { |
505 | KURL::List::Iterator it = urls.begin(); | 512 | KURL::List::Iterator it = urls.begin(); |
506 | int c = urls.count(); | 513 | int c = urls.count(); |
507 | if ( c > 1 ) { | 514 | if ( c > 1 ) { |
508 | QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); | 515 | QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); |
509 | if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { | 516 | if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { |
510 | for ( ; it != urls.end(); ++it ) | 517 | for ( ; it != urls.end(); ++it ) |
511 | emit urlDropped( *it ); | 518 | emit urlDropped( *it ); |
512 | } | 519 | } |
513 | } else if ( c == 1 ) | 520 | } else if ( c == 1 ) |
514 | emit urlDropped( *it ); | 521 | emit urlDropped( *it ); |
515 | } else if ( KVCardDrag::decode( e, vcards ) ) { | 522 | } else if ( KVCardDrag::decode( e, vcards ) ) { |
516 | KABC::Addressee addr; | 523 | KABC::Addressee addr; |
517 | KABC::VCardConverter converter; | 524 | KABC::VCardConverter converter; |
518 | QStringList list = QStringList::split( "\r\n\r\n", vcards ); | 525 | QStringList list = QStringList::split( "\r\n\r\n", vcards ); |
519 | QStringList::Iterator it; | 526 | QStringList::Iterator it; |
520 | for ( it = list.begin(); it != list.end(); ++it ) { | 527 | for ( it = list.begin(); it != list.end(); ++it ) { |
521 | if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { | 528 | if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { |
522 | KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); | 529 | KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); |
523 | if ( a.isEmpty() ) { | 530 | if ( a.isEmpty() ) { |
524 | mCore->addressBook()->insertAddressee( addr ); | 531 | mCore->addressBook()->insertAddressee( addr ); |
525 | emit modified(); | 532 | emit modified(); |
526 | } | 533 | } |
527 | } | 534 | } |
528 | } | 535 | } |
529 | 536 | ||
530 | mActiveView->refresh(); | 537 | mActiveView->refresh(); |
531 | } | 538 | } |
532 | #else //KAB_EMBEDDED | 539 | #else //KAB_EMBEDDED |
533 | qDebug("ViewManager::dropped() has to be changed!!" ); | 540 | qDebug("ViewManager::dropped() has to be changed!!" ); |
534 | #endif //KAB_EMBEDDED | 541 | #endif //KAB_EMBEDDED |
535 | 542 | ||
536 | } | 543 | } |
537 | 544 | ||
538 | void ViewManager::startDrag() | 545 | void ViewManager::startDrag() |
539 | { | 546 | { |
540 | kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; | 547 | kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; |
541 | 548 | ||
542 | #ifndef KAB_EMBEDDED | 549 | #ifndef KAB_EMBEDDED |
543 | 550 | ||
544 | // Get the list of all the selected addressees | 551 | // Get the list of all the selected addressees |
545 | KABC::Addressee::List addrList; | 552 | KABC::Addressee::List addrList; |
546 | QStringList uidList = selectedUids(); | 553 | QStringList uidList = selectedUids(); |
547 | QStringList::Iterator iter; | 554 | QStringList::Iterator iter; |
548 | for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) | 555 | for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) |
549 | addrList.append( mCore->addressBook()->findByUid( *iter ) ); | 556 | addrList.append( mCore->addressBook()->findByUid( *iter ) ); |
550 | 557 | ||
551 | KMultipleDrag *drag = new KMultipleDrag( this ); | 558 | KMultipleDrag *drag = new KMultipleDrag( this ); |
552 | drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); | 559 | drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); |
553 | KABC::Addressee::List::Iterator it; | 560 | KABC::Addressee::List::Iterator it; |
554 | QStringList vcards; | 561 | QStringList vcards; |
555 | for ( it = addrList.begin(); it != addrList.end(); ++it ) { | 562 | for ( it = addrList.begin(); it != addrList.end(); ++it ) { |
556 | QString vcard = QString::null; | 563 | QString vcard = QString::null; |
557 | KABC::VCardConverter converter; | 564 | KABC::VCardConverter converter; |
558 | if ( converter.addresseeToVCard( *it, vcard ) ) | 565 | if ( converter.addresseeToVCard( *it, vcard ) ) |
559 | vcards.append( vcard ); | 566 | vcards.append( vcard ); |
560 | } | 567 | } |
561 | drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); | 568 | drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); |
562 | 569 | ||
563 | drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); | 570 | drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); |
564 | drag->dragCopy(); | 571 | drag->dragCopy(); |
565 | 572 | ||
566 | #else //KAB_EMBEDDED | 573 | #else //KAB_EMBEDDED |
567 | qDebug("ViewManager::startDrag() has to be changed!!" ); | 574 | qDebug("ViewManager::startDrag() has to be changed!!" ); |
568 | #endif //KAB_EMBEDDED | 575 | #endif //KAB_EMBEDDED |
569 | 576 | ||
570 | } | 577 | } |
571 | void ViewManager::doSearch( const QString& s,KABC::Field *field ) | 578 | void ViewManager::doSearch( const QString& s,KABC::Field *field ) |
572 | { | 579 | { |
573 | if ( mActiveView ) | 580 | if ( mActiveView ) |
574 | mActiveView->doSearch( s, field ); | 581 | mActiveView->doSearch( s, field ); |
575 | 582 | ||
576 | } | 583 | } |
577 | void ViewManager::setActiveFilter( int index ) | 584 | void ViewManager::setActiveFilter( int index ) |
578 | { | 585 | { |
579 | Filter currentFilter; | 586 | Filter currentFilter; |
580 | 587 | ||
581 | if ( ( index - 1 ) < 0 ) | 588 | if ( ( index - 1 ) < 0 ) |
582 | currentFilter = Filter(); | 589 | currentFilter = Filter(); |
583 | else | 590 | else |
584 | currentFilter = mFilterList[ index - 1 ]; | 591 | currentFilter = mFilterList[ index - 1 ]; |
585 | 592 | ||
586 | // Check if we have a view. Since the filter combo is created before | 593 | // Check if we have a view. Since the filter combo is created before |
587 | // the view, this slot could be called before there is a valid view. | 594 | // the view, this slot could be called before there is a valid view. |
588 | if ( mActiveView ) { | 595 | if ( mActiveView ) { |
589 | mActiveView->setFilter( currentFilter ); | 596 | mActiveView->setFilter( currentFilter ); |
590 | mActiveView->refresh(); | 597 | mActiveView->refresh(); |
591 | emit selected( QString::null ); | 598 | emit selected( QString::null ); |
592 | } | 599 | } |
593 | } | 600 | } |
594 | 601 | ||
595 | void ViewManager::configureFilters() | 602 | void ViewManager::configureFilters() |
596 | { | 603 | { |
597 | FilterDialog dlg( this ); | 604 | FilterDialog dlg( this ); |
598 | 605 | ||
599 | dlg.setFilters( mFilterList ); | 606 | dlg.setFilters( mFilterList ); |
600 | 607 | ||
601 | if ( dlg.exec() ) | 608 | if ( dlg.exec() ) |
602 | mFilterList = dlg.filters(); | 609 | mFilterList = dlg.filters(); |
603 | 610 | ||
604 | uint pos = mActionSelectFilter->currentItem(); | 611 | uint pos = mActionSelectFilter->currentItem(); |
605 | mActionSelectFilter->setItems( filterNames() ); | 612 | mActionSelectFilter->setItems( filterNames() ); |
606 | mActionSelectFilter->setCurrentItem( pos ); | 613 | mActionSelectFilter->setCurrentItem( pos ); |
607 | setActiveFilter( pos ); | 614 | setActiveFilter( pos ); |
608 | int cw = 150; | 615 | int cw = 150; |
609 | if ( QApplication::desktop()->width() >= 800 ) | 616 | if ( QApplication::desktop()->width() >= 800 ) |
610 | cw = 200; | 617 | cw = 200; |
611 | if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) | 618 | if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) |
612 | cw = 0; | 619 | cw = 0; |
613 | mActionSelectFilter->setComboWidth( cw ); | 620 | mActionSelectFilter->setComboWidth( cw ); |
614 | saveSettings(); | 621 | saveSettings(); |
615 | } | 622 | } |
616 | 623 | ||
617 | QStringList ViewManager::filterNames() const | 624 | QStringList ViewManager::filterNames() const |
618 | { | 625 | { |
619 | QStringList names( i18n( "No Filter" ) ); | 626 | QStringList names( i18n( "No Filter" ) ); |
620 | 627 | ||
621 | Filter::List::ConstIterator it; | 628 | Filter::List::ConstIterator it; |
622 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) | 629 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) |
623 | names.append( (*it).name() ); | 630 | names.append( (*it).name() ); |
624 | 631 | ||
625 | return names; | 632 | return names; |
626 | } | 633 | } |
627 | Filter ViewManager::getFilterByName( const QString &name ) const | 634 | Filter ViewManager::getFilterByName( const QString &name ) const |
628 | { | 635 | { |
629 | Filter::List::ConstIterator it; | 636 | Filter::List::ConstIterator it; |
630 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) | 637 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) |
631 | if ( name == (*it).name() ) | 638 | if ( name == (*it).name() ) |
632 | return (*it); | 639 | return (*it); |
633 | 640 | ||
634 | return Filter(); | 641 | return Filter(); |
635 | } | 642 | } |
636 | 643 | ||
637 | int ViewManager::filterPosition( const QString &name ) const | 644 | int ViewManager::filterPosition( const QString &name ) const |
638 | { | 645 | { |
639 | int pos = 0; | 646 | int pos = 0; |
640 | 647 | ||
641 | Filter::List::ConstIterator it; | 648 | Filter::List::ConstIterator it; |
642 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) | 649 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) |
643 | if ( name == (*it).name() ) | 650 | if ( name == (*it).name() ) |
644 | return pos + 1; | 651 | return pos + 1; |
645 | 652 | ||
646 | return 0; | 653 | return 0; |
647 | } | 654 | } |
648 | 655 | ||
649 | void ViewManager::initActions() | 656 | void ViewManager::initActions() |
650 | { | 657 | { |
651 | //US <ActionList name="view_loadedviews"/> | 658 | //US <ActionList name="view_loadedviews"/> |
652 | //US <Separator/> | 659 | //US <Separator/> |
653 | 660 | ||
654 | #ifdef KAB_EMBEDDED | 661 | #ifdef KAB_EMBEDDED |
655 | QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); | 662 | QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); |
656 | QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); | 663 | QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); |
657 | QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); | 664 | QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); |
658 | #endif //KAB_EMBEDDED | 665 | #endif //KAB_EMBEDDED |
659 | 666 | ||
660 | mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); | 667 | mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); |
661 | #if KDE_VERSION >= 309 | 668 | #if KDE_VERSION >= 309 |
662 | mActionSelectView->setMenuAccelsEnabled( false ); | 669 | mActionSelectView->setMenuAccelsEnabled( false ); |
663 | #endif | 670 | #endif |
664 | connect( mActionSelectView, SIGNAL( activated( const QString& ) ), | 671 | connect( mActionSelectView, SIGNAL( activated( const QString& ) ), |
665 | SLOT( selectView( const QString& ) ) ); | 672 | SLOT( selectView( const QString& ) ) ); |
666 | 673 | ||
667 | 674 | ||
668 | #ifdef KAB_EMBEDDED | 675 | #ifdef KAB_EMBEDDED |
669 | mActionSelectView->plug(viewmenu); | 676 | mActionSelectView->plug(viewmenu); |
670 | viewmenu->insertSeparator(); | 677 | viewmenu->insertSeparator(); |
671 | #endif //KAB_EMBEDDED | 678 | #endif //KAB_EMBEDDED |
672 | 679 | ||
673 | KAction *action; | 680 | KAction *action; |
674 | 681 | ||
675 | action = new KAction( i18n( "Modify View..." ), "configure", 0, this, | 682 | action = new KAction( i18n( "Modify View..." ), "configure", 0, this, |
676 | SLOT( editView() ), mCore->actionCollection(), "view_modify" ); | 683 | SLOT( editView() ), mCore->actionCollection(), "view_modify" ); |
677 | #ifndef KAB_EMBEDDED | 684 | #ifndef KAB_EMBEDDED |
678 | action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) ); | 685 | action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) ); |
679 | #else //KAB_EMBEDDED | 686 | #else //KAB_EMBEDDED |
680 | action->plug(viewmenu); | 687 | action->plug(viewmenu); |
681 | #endif //KAB_EMBEDDED | 688 | #endif //KAB_EMBEDDED |
682 | 689 | ||
683 | action = new KAction( i18n( "Add View..." ), "window_new", 0, this, | 690 | action = new KAction( i18n( "Add View..." ), "window_new", 0, this, |
684 | SLOT( addView() ), mCore->actionCollection(), "view_add" ); | 691 | SLOT( addView() ), mCore->actionCollection(), "view_add" ); |
685 | #ifndef KAB_EMBEDDED | 692 | #ifndef KAB_EMBEDDED |
686 | action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) ); | 693 | action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) ); |
687 | #else //KAB_EMBEDDED | 694 | #else //KAB_EMBEDDED |
688 | action->plug(viewmenu); | 695 | action->plug(viewmenu); |
689 | #endif //KAB_EMBEDDED | 696 | #endif //KAB_EMBEDDED |
690 | 697 | ||
691 | mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0, | 698 | mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0, |
692 | this, SLOT( deleteView() ), | 699 | this, SLOT( deleteView() ), |
693 | mCore->actionCollection(), "view_delete" ); | 700 | mCore->actionCollection(), "view_delete" ); |
694 | #ifndef KAB_EMBEDDED | 701 | #ifndef KAB_EMBEDDED |
695 | mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) ); | 702 | mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) ); |
696 | #else //KAB_EMBEDDED | 703 | #else //KAB_EMBEDDED |
697 | mActionDeleteView->plug(viewmenu); | 704 | mActionDeleteView->plug(viewmenu); |
698 | viewmenu->insertSeparator(); | 705 | viewmenu->insertSeparator(); |
699 | #endif //KAB_EMBEDDED | 706 | #endif //KAB_EMBEDDED |
700 | 707 | ||
701 | #ifndef KAB_EMBEDDED | 708 | #ifndef KAB_EMBEDDED |
702 | action = new KAction( i18n( "Refresh View" ), "reload", 0, this, | 709 | action = new KAction( i18n( "Refresh View" ), "reload", 0, this, |
703 | SLOT( refreshView(const QString &) ), mCore->actionCollection(), | 710 | SLOT( refreshView(const QString &) ), mCore->actionCollection(), |
704 | "view_refresh" ); | 711 | "view_refresh" ); |
705 | action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) ); | 712 | action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) ); |
706 | #else //KAB_EMBEDDED | 713 | #else //KAB_EMBEDDED |
707 | action = new KAction( i18n( "Refresh View" ), "reload", 0, this, | 714 | action = new KAction( i18n( "Refresh View" ), "reload", 0, this, |
708 | SLOT( refreshView()), mCore->actionCollection(), | 715 | SLOT( refreshView()), mCore->actionCollection(), |
709 | "view_refresh" ); | 716 | "view_refresh" ); |
710 | action->plug(viewmenu); | 717 | action->plug(viewmenu); |
711 | //viewmenu->insertSeparator(); | 718 | //viewmenu->insertSeparator(); |
712 | #endif //KAB_EMBEDDED | 719 | #endif //KAB_EMBEDDED |
713 | 720 | ||
714 | action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this, | 721 | action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this, |
715 | SLOT( configureFilters() ), mCore->actionCollection(), | 722 | SLOT( configureFilters() ), mCore->actionCollection(), |
716 | "options_edit_filters" ); | 723 | "options_edit_filters" ); |
717 | 724 | ||
718 | mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" ); | 725 | mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" ); |
719 | #if KDE_VERSION >= 309 | 726 | #if KDE_VERSION >= 309 |
720 | mActionSelectFilter->setMenuAccelsEnabled( false ); | 727 | mActionSelectFilter->setMenuAccelsEnabled( false ); |
721 | #endif | 728 | #endif |
722 | connect( mActionSelectFilter, SIGNAL( activated( int ) ), | 729 | connect( mActionSelectFilter, SIGNAL( activated( int ) ), |
723 | SLOT( setActiveFilter( int ) ) ); | 730 | SLOT( setActiveFilter( int ) ) ); |
724 | 731 | ||
725 | #ifdef KAB_EMBEDDED | 732 | #ifdef KAB_EMBEDDED |
726 | action->plug(settingsmenu); | 733 | action->plug(settingsmenu); |
727 | mActionSelectFilter->plug(viewmenu,0); | 734 | mActionSelectFilter->plug(viewmenu,0); |
728 | #endif //KAB_EMBEDDED | 735 | #endif //KAB_EMBEDDED |
729 | 736 | ||
730 | } | 737 | } |
731 | 738 | ||
732 | void ViewManager::initGUI() | 739 | void ViewManager::initGUI() |
733 | { | 740 | { |
734 | QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 ); | 741 | QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 ); |
735 | mViewWidgetStack = new QWidgetStack( this ); | 742 | mViewWidgetStack = new QWidgetStack( this ); |
736 | layout->addWidget( mViewWidgetStack ); | 743 | layout->addWidget( mViewWidgetStack ); |
737 | } | 744 | } |
738 | 745 | ||
739 | #ifndef KAB_EMBEDDED | 746 | #ifndef KAB_EMBEDDED |
740 | #include "viewmanager.moc" | 747 | #include "viewmanager.moc" |
741 | #endif //KAB_EMBEDDED | 748 | #endif //KAB_EMBEDDED |