summaryrefslogtreecommitdiffabout
path: root/kaddressbook/viewmanager.cpp
Unidiff
Diffstat (limited to 'kaddressbook/viewmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/viewmanager.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index c6baeac..f4fb08b 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -1,280 +1,289 @@
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/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (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
72ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) 72ViewManager::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
83ViewManager::~ViewManager() 83ViewManager::~ViewManager()
84{ 84{
85 unloadViews(); 85 unloadViews();
86 mViewFactoryDict.clear(); 86 mViewFactoryDict.clear();
87} 87}
88 88void ViewManager::scrollUP()
89{
90 if ( mActiveView )
91 mActiveView->scrollUP();
92}
93void ViewManager::scrollDOWN()
94{
95 if ( mActiveView )
96 mActiveView->scrollDOWN();
97}
89void ViewManager::restoreSettings() 98void ViewManager::restoreSettings()
90{ 99{
91 mViewNameList = KABPrefs::instance()->mViewNames; 100 mViewNameList = KABPrefs::instance()->mViewNames;
92 QString activeViewName = KABPrefs::instance()->mCurrentView; 101 QString activeViewName = KABPrefs::instance()->mCurrentView;
93 102
94 mActionSelectView->setItems( mViewNameList ); 103 mActionSelectView->setItems( mViewNameList );
95 104
96 // Filter 105 // Filter
97 mFilterList = Filter::restore( mCore->config(), "Filter" ); 106 mFilterList = Filter::restore( mCore->config(), "Filter" );
98 mActionSelectFilter->setItems( filterNames() ); 107 mActionSelectFilter->setItems( filterNames() );
99 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); 108 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter );
100 109
101 // Tell the views to reread their config, since they may have 110 // Tell the views to reread their config, since they may have
102 // been modified by global settings 111 // been modified by global settings
103 QString _oldgroup = mCore->config()->group(); 112 QString _oldgroup = mCore->config()->group();
104 113
105 QDictIterator<KAddressBookView> it( mViewDict ); 114 QDictIterator<KAddressBookView> it( mViewDict );
106 for ( it.toFirst(); it.current(); ++it ) { 115 for ( it.toFirst(); it.current(); ++it ) {
107 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 116 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
108 it.current()->readConfig( mCore->config() ); 117 it.current()->readConfig( mCore->config() );
109 } 118 }
110 setActiveView( activeViewName ); 119 setActiveView( activeViewName );
111 120
112 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 121 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
113} 122}
114 123
115void ViewManager::saveSettings() 124void ViewManager::saveSettings()
116{ 125{
117 QString _oldgroup = mCore->config()->group(); 126 QString _oldgroup = mCore->config()->group();
118 127
119 QDictIterator<KAddressBookView> it( mViewDict ); 128 QDictIterator<KAddressBookView> it( mViewDict );
120 for ( it.toFirst(); it.current(); ++it ) { 129 for ( it.toFirst(); it.current(); ++it ) {
121 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 130 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
122#ifdef DESKTOP_VERSION 131#ifdef DESKTOP_VERSION
123 (*it)->writeConfig( mCore->config() ); 132 (*it)->writeConfig( mCore->config() );
124#else 133#else
125 (*it).writeConfig( mCore->config() ); 134 (*it).writeConfig( mCore->config() );
126#endif 135#endif
127 } 136 }
128 137
129 Filter::save( mCore->config(), "Filter", mFilterList ); 138 Filter::save( mCore->config(), "Filter", mFilterList );
130 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); 139 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
131 140
132 // write the view name list 141 // write the view name list
133 KABPrefs::instance()->mViewNames = mViewNameList; 142 KABPrefs::instance()->mViewNames = mViewNameList;
134 KABPrefs::instance()->mCurrentView = mActiveView->caption(); 143 KABPrefs::instance()->mCurrentView = mActiveView->caption();
135 144
136} 145}
137 146
138QStringList ViewManager::selectedUids() const 147QStringList ViewManager::selectedUids() const
139{ 148{
140 if ( mActiveView ) 149 if ( mActiveView )
141 return mActiveView->selectedUids(); 150 return mActiveView->selectedUids();
142 else 151 else
143 return QStringList(); 152 return QStringList();
144} 153}
145 154
146QStringList ViewManager::selectedEmails() const 155QStringList ViewManager::selectedEmails() const
147{ 156{
148 if ( mActiveView ) 157 if ( mActiveView )
149 return mActiveView->selectedEmails(); 158 return mActiveView->selectedEmails();
150 else 159 else
151 return QStringList(); 160 return QStringList();
152} 161}
153 162
154KABC::Addressee::List ViewManager::selectedAddressees() const 163KABC::Addressee::List ViewManager::selectedAddressees() const
155{ 164{
156 KABC::Addressee::List list; 165 KABC::Addressee::List list;
157 if ( mActiveView ) { 166 if ( mActiveView ) {
158 QStringList uids = mActiveView->selectedUids(); 167 QStringList uids = mActiveView->selectedUids();
159 QStringList::Iterator it; 168 QStringList::Iterator it;
160 for ( it = uids.begin(); it != uids.end(); ++it ) { 169 for ( it = uids.begin(); it != uids.end(); ++it ) {
161 KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); 170 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
162 if ( !addr.isEmpty() ) 171 if ( !addr.isEmpty() )
163 list.append( addr ); 172 list.append( addr );
164 } 173 }
165 } 174 }
166 175
167 return list; 176 return list;
168} 177}
169//US added another method with no parameter, since my moc compiler does not support default parameters. 178//US added another method with no parameter, since my moc compiler does not support default parameters.
170void ViewManager::setSelected() 179void ViewManager::setSelected()
171{ 180{
172 setSelected( QString::null, true ); 181 setSelected( QString::null, true );
173} 182}
174 183
175void ViewManager::setSelected( const QString &uid, bool selected ) 184void ViewManager::setSelected( const QString &uid, bool selected )
176{ 185{
177 if ( mActiveView ) 186 if ( mActiveView )
178 mActiveView->setSelected( uid, selected ); 187 mActiveView->setSelected( uid, selected );
179} 188}
180 189
181void ViewManager::setListSelected(QStringList list) 190void ViewManager::setListSelected(QStringList list)
182{ 191{
183 int i, count = list.count(); 192 int i, count = list.count();
184 for ( i = 0; i < count;++i ) 193 for ( i = 0; i < count;++i )
185 setSelected( list[i], true ); 194 setSelected( list[i], true );
186 195
187} 196}
188void ViewManager::unloadViews() 197void ViewManager::unloadViews()
189{ 198{
190 mViewDict.clear(); 199 mViewDict.clear();
191 mActiveView = 0; 200 mActiveView = 0;
192} 201}
193 202
194void ViewManager::setActiveView( const QString &name ) 203void ViewManager::setActiveView( const QString &name )
195{ 204{
196 KAddressBookView *view = 0; 205 KAddressBookView *view = 0;
197 206
198 // Check that this isn't the same as the current active view 207 // Check that this isn't the same as the current active view
199 if ( mActiveView && ( mActiveView->caption() == name ) ) 208 if ( mActiveView && ( mActiveView->caption() == name ) )
200 return; 209 return;
201 210
202 // At this point we know the view that should be active is not 211 // At this point we know the view that should be active is not
203 // currently active. We will try to find the new on in the list. If 212 // currently active. We will try to find the new on in the list. If
204 // we can't find it, it means it hasn't been instantiated, so we will 213 // we can't find it, it means it hasn't been instantiated, so we will
205 // create it on demand. 214 // create it on demand.
206 215
207 view = mViewDict.find( name ); 216 view = mViewDict.find( name );
208 217
209 // Check if we found the view. If we didn't, then we need to create it 218 // Check if we found the view. If we didn't, then we need to create it
210 if ( view == 0 ) { 219 if ( view == 0 ) {
211 KConfig *config = mCore->config(); 220 KConfig *config = mCore->config();
212 221
213 KConfigGroupSaver saver( config, name ); 222 KConfigGroupSaver saver( config, name );
214 223
215 QString type = config->readEntry( "Type", "Table" ); 224 QString type = config->readEntry( "Type", "Table" );
216 225
217 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; 226 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
218 227
219 ViewFactory *factory = mViewFactoryDict.find( type ); 228 ViewFactory *factory = mViewFactoryDict.find( type );
220 if ( factory ) 229 if ( factory )
221 view = factory->view( mCore->addressBook(), mViewWidgetStack ); 230 view = factory->view( mCore->addressBook(), mViewWidgetStack );
222 231
223 if ( view ) { 232 if ( view ) {
224 view->setCaption( name ); 233 view->setCaption( name );
225 mViewDict.insert( name, view ); 234 mViewDict.insert( name, view );
226//US my version needs an int as second parameter to addWidget 235//US my version needs an int as second parameter to addWidget
227 mViewWidgetStack->addWidget( view, -1 ); 236 mViewWidgetStack->addWidget( view, -1 );
228 view->readConfig( config ); 237 view->readConfig( config );
229 238
230 // The manager just relays the signals 239 // The manager just relays the signals
231 connect( view, SIGNAL( selected( const QString& ) ), 240 connect( view, SIGNAL( selected( const QString& ) ),
232 SIGNAL( selected( const QString & ) ) ); 241 SIGNAL( selected( const QString & ) ) );
233 connect( view, SIGNAL( executed( const QString& ) ), 242 connect( view, SIGNAL( executed( const QString& ) ),
234 SIGNAL( executed( const QString& ) ) ); 243 SIGNAL( executed( const QString& ) ) );
235 244
236 connect( view, SIGNAL( deleteRequest( ) ), 245 connect( view, SIGNAL( deleteRequest( ) ),
237 SIGNAL( deleteRequest( ) ) ); 246 SIGNAL( deleteRequest( ) ) );
238 247
239 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); 248 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
240 connect( view, SIGNAL( dropped( QDropEvent* ) ), 249 connect( view, SIGNAL( dropped( QDropEvent* ) ),
241 SLOT( dropped( QDropEvent* ) ) ); 250 SLOT( dropped( QDropEvent* ) ) );
242 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); 251 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
243 } 252 }
244 } 253 }
245 254
246 // If we found or created the view, raise it and refresh it 255 // If we found or created the view, raise it and refresh it
247 if ( view ) { 256 if ( view ) {
248 mActiveView = view; 257 mActiveView = view;
249 mViewWidgetStack->raiseWidget( view ); 258 mViewWidgetStack->raiseWidget( view );
250 // Set the proper filter in the view. By setting the combo 259 // Set the proper filter in the view. By setting the combo
251 // box, the activated slot will be called, which will push 260 // box, the activated slot will be called, which will push
252 // the filter to the view and refresh it. 261 // the filter to the view and refresh it.
253 262
254 if ( view->defaultFilterType() == KAddressBookView::None ) { 263 if ( view->defaultFilterType() == KAddressBookView::None ) {
255 264
256 mActionSelectFilter->setCurrentItem( 0 ); 265 mActionSelectFilter->setCurrentItem( 0 );
257 setActiveFilter( 0 ); 266 setActiveFilter( 0 );
258 } else if ( view->defaultFilterType() == KAddressBookView::Active ) { 267 } else if ( view->defaultFilterType() == KAddressBookView::Active ) {
259 setActiveFilter( mActionSelectFilter->currentItem() ); 268 setActiveFilter( mActionSelectFilter->currentItem() );
260 } else { 269 } else {
261 uint pos = filterPosition( view->defaultFilterName() ); 270 uint pos = filterPosition( view->defaultFilterName() );
262 mActionSelectFilter->setCurrentItem( pos ); 271 mActionSelectFilter->setCurrentItem( pos );
263 setActiveFilter( pos ); 272 setActiveFilter( pos );
264 } 273 }
265//US qDebug("ViewManager::setActiveView 6" ); 274//US qDebug("ViewManager::setActiveView 6" );
266 275
267 // Update the inc search widget to show the fields in the new active 276 // Update the inc search widget to show the fields in the new active
268 // view. 277 // view.
269 mCore->setSearchFields( mActiveView->fields() ); 278 mCore->setSearchFields( mActiveView->fields() );
270 279
271//US performance optimization. setActiveFilter calls also mActiveView->refresh() 280//US performance optimization. setActiveFilter calls also mActiveView->refresh()
272//US mActiveView->refresh(); 281//US mActiveView->refresh();
273 282
274 } 283 }
275 else 284 else
276 { 285 {
277 qDebug("ViewManager::setActiveView: unable to find view" ); 286 qDebug("ViewManager::setActiveView: unable to find view" );
278 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; 287 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n";
279 } 288 }
280} 289}