summaryrefslogtreecommitdiffabout
path: root/kaddressbook/viewmanager.cpp
Unidiff
Diffstat (limited to 'kaddressbook/viewmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/viewmanager.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index 0614d06..c738ad8 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -1,302 +1,304 @@
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 <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
73ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) 73ViewManager::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
84ViewManager::~ViewManager() 84ViewManager::~ViewManager()
85{ 85{
86 unloadViews(); 86 unloadViews();
87 mViewFactoryDict.clear(); 87 mViewFactoryDict.clear();
88} 88}
89void ViewManager::scrollUP() 89void ViewManager::scrollUP()
90{ 90{
91 if ( mActiveView ) 91 if ( mActiveView )
92 mActiveView->scrollUP(); 92 mActiveView->scrollUP();
93} 93}
94void ViewManager::scrollDOWN() 94void ViewManager::scrollDOWN()
95{ 95{
96 if ( mActiveView ) 96 if ( mActiveView )
97 mActiveView->scrollDOWN(); 97 mActiveView->scrollDOWN();
98} 98}
99void ViewManager::restoreSettings() 99void 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 )
112 cw = 200;
111 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) 113 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch)
112 cw = 0; 114 cw = 0;
113 mActionSelectFilter->setComboWidth( cw ); 115 mActionSelectFilter->setComboWidth( cw );
114 // Tell the views to reread their config, since they may have 116 // Tell the views to reread their config, since they may have
115 // been modified by global settings 117 // been modified by global settings
116 QString _oldgroup = mCore->config()->group(); 118 QString _oldgroup = mCore->config()->group();
117 119
118 QDictIterator<KAddressBookView> it( mViewDict ); 120 QDictIterator<KAddressBookView> it( mViewDict );
119 for ( it.toFirst(); it.current(); ++it ) { 121 for ( it.toFirst(); it.current(); ++it ) {
120 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 122 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
121 it.current()->readConfig( mCore->config() ); 123 it.current()->readConfig( mCore->config() );
122 } 124 }
123 setActiveView( activeViewName ); 125 setActiveView( activeViewName );
124 126
125 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 127 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
126} 128}
127 129
128void ViewManager::saveSettings() 130void ViewManager::saveSettings()
129{ 131{
130 QString _oldgroup = mCore->config()->group(); 132 QString _oldgroup = mCore->config()->group();
131 133
132 QDictIterator<KAddressBookView> it( mViewDict ); 134 QDictIterator<KAddressBookView> it( mViewDict );
133 for ( it.toFirst(); it.current(); ++it ) { 135 for ( it.toFirst(); it.current(); ++it ) {
134 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 136 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
135#ifdef DESKTOP_VERSION 137#ifdef DESKTOP_VERSION
136 (*it)->writeConfig( mCore->config() ); 138 (*it)->writeConfig( mCore->config() );
137#else 139#else
138 (*it).writeConfig( mCore->config() ); 140 (*it).writeConfig( mCore->config() );
139#endif 141#endif
140 } 142 }
141 143
142 Filter::save( mCore->config(), "Filter", mFilterList ); 144 Filter::save( mCore->config(), "Filter", mFilterList );
143 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); 145 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
144 146
145 // write the view name list 147 // write the view name list
146 KABPrefs::instance()->mViewNames = mViewNameList; 148 KABPrefs::instance()->mViewNames = mViewNameList;
147 KABPrefs::instance()->mCurrentView = mActiveView->caption(); 149 KABPrefs::instance()->mCurrentView = mActiveView->caption();
148 150
149} 151}
150 152
151QStringList ViewManager::selectedUids() const 153QStringList ViewManager::selectedUids() const
152{ 154{
153 if ( mActiveView ) 155 if ( mActiveView )
154 return mActiveView->selectedUids(); 156 return mActiveView->selectedUids();
155 else 157 else
156 return QStringList(); 158 return QStringList();
157} 159}
158 160
159QStringList ViewManager::selectedEmails() const 161QStringList ViewManager::selectedEmails() const
160{ 162{
161 if ( mActiveView ) 163 if ( mActiveView )
162 return mActiveView->selectedEmails(); 164 return mActiveView->selectedEmails();
163 else 165 else
164 return QStringList(); 166 return QStringList();
165} 167}
166 168
167KABC::Addressee::List ViewManager::selectedAddressees() const 169KABC::Addressee::List ViewManager::selectedAddressees() const
168{ 170{
169 KABC::Addressee::List list; 171 KABC::Addressee::List list;
170 if ( mActiveView ) { 172 if ( mActiveView ) {
171 QStringList uids = mActiveView->selectedUids(); 173 QStringList uids = mActiveView->selectedUids();
172 QStringList::Iterator it; 174 QStringList::Iterator it;
173 for ( it = uids.begin(); it != uids.end(); ++it ) { 175 for ( it = uids.begin(); it != uids.end(); ++it ) {
174 KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); 176 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
175 if ( !addr.isEmpty() ) 177 if ( !addr.isEmpty() )
176 list.append( addr ); 178 list.append( addr );
177 } 179 }
178 } 180 }
179 181
180 return list; 182 return list;
181} 183}
182//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.
183void ViewManager::setSelected() 185void ViewManager::setSelected()
184{ 186{
185 setSelected( QString::null, true ); 187 setSelected( QString::null, true );
186} 188}
187 189
188void ViewManager::setSelected( const QString &uid, bool selected ) 190void ViewManager::setSelected( const QString &uid, bool selected )
189{ 191{
190 if ( mActiveView ) 192 if ( mActiveView )
191 mActiveView->setSelected( uid, selected ); 193 mActiveView->setSelected( uid, selected );
192} 194}
193 195
194void ViewManager::setListSelected(QStringList list) 196void ViewManager::setListSelected(QStringList list)
195{ 197{
196 int i, count = list.count(); 198 int i, count = list.count();
197 for ( i = 0; i < count;++i ) 199 for ( i = 0; i < count;++i )
198 setSelected( list[i], true ); 200 setSelected( list[i], true );
199 201
200} 202}
201void ViewManager::unloadViews() 203void ViewManager::unloadViews()
202{ 204{
203 mViewDict.clear(); 205 mViewDict.clear();
204 mActiveView = 0; 206 mActiveView = 0;
205} 207}
206 208
207void ViewManager::selectView( const QString &name ) 209void ViewManager::selectView( const QString &name )
208{ 210{
209 setActiveView( name ); 211 setActiveView( name );
210 mCore->saveSettings(); 212 mCore->saveSettings();
211} 213}
212void ViewManager::setActiveView( const QString &name ) 214void ViewManager::setActiveView( const QString &name )
213{ 215{
214 KAddressBookView *view = 0; 216 KAddressBookView *view = 0;
215 217
216 // 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
217 if ( mActiveView && ( mActiveView->caption() == name ) ) 219 if ( mActiveView && ( mActiveView->caption() == name ) )
218 return; 220 return;
219 221
220 // 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
221 // 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
222 // 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
223 // create it on demand. 225 // create it on demand.
224 226
225 view = mViewDict.find( name ); 227 view = mViewDict.find( name );
226 228
227 // 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
228 if ( view == 0 ) { 230 if ( view == 0 ) {
229 KConfig *config = mCore->config(); 231 KConfig *config = mCore->config();
230 232
231 KConfigGroupSaver saver( config, name ); 233 KConfigGroupSaver saver( config, name );
232 234
233 QString type = config->readEntry( "Type", "Table" ); 235 QString type = config->readEntry( "Type", "Table" );
234 236
235 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; 237 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
236 238
237 ViewFactory *factory = mViewFactoryDict.find( type ); 239 ViewFactory *factory = mViewFactoryDict.find( type );
238 if ( factory ) 240 if ( factory )
239 view = factory->view( mCore->addressBook(), mViewWidgetStack ); 241 view = factory->view( mCore->addressBook(), mViewWidgetStack );
240 242
241 if ( view ) { 243 if ( view ) {
242 view->setCaption( name ); 244 view->setCaption( name );
243 mViewDict.insert( name, view ); 245 mViewDict.insert( name, view );
244//US my version needs an int as second parameter to addWidget 246//US my version needs an int as second parameter to addWidget
245 mViewWidgetStack->addWidget( view, -1 ); 247 mViewWidgetStack->addWidget( view, -1 );
246 view->readConfig( config ); 248 view->readConfig( config );
247 249
248 // The manager just relays the signals 250 // The manager just relays the signals
249 connect( view, SIGNAL( selected( const QString& ) ), 251 connect( view, SIGNAL( selected( const QString& ) ),
250 SIGNAL( selected( const QString & ) ) ); 252 SIGNAL( selected( const QString & ) ) );
251 connect( view, SIGNAL( executed( const QString& ) ), 253 connect( view, SIGNAL( executed( const QString& ) ),
252 SIGNAL( executed( const QString& ) ) ); 254 SIGNAL( executed( const QString& ) ) );
253 255
254 connect( view, SIGNAL( deleteRequest( ) ), 256 connect( view, SIGNAL( deleteRequest( ) ),
255 SIGNAL( deleteRequest( ) ) ); 257 SIGNAL( deleteRequest( ) ) );
256 258
257 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); 259 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
258 connect( view, SIGNAL( dropped( QDropEvent* ) ), 260 connect( view, SIGNAL( dropped( QDropEvent* ) ),
259 SLOT( dropped( QDropEvent* ) ) ); 261 SLOT( dropped( QDropEvent* ) ) );
260 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); 262 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
261 } 263 }
262 } 264 }
263 265
264 // If we found or created the view, raise it and refresh it 266 // If we found or created the view, raise it and refresh it
265 if ( view ) { 267 if ( view ) {
266 mActiveView = view; 268 mActiveView = view;
267 mViewWidgetStack->raiseWidget( view ); 269 mViewWidgetStack->raiseWidget( view );
268 // Set the proper filter in the view. By setting the combo 270 // Set the proper filter in the view. By setting the combo
269 // box, the activated slot will be called, which will push 271 // box, the activated slot will be called, which will push
270 // the filter to the view and refresh it. 272 // the filter to the view and refresh it.
271 273
272 if ( view->defaultFilterType() == KAddressBookView::None ) { 274 if ( view->defaultFilterType() == KAddressBookView::None ) {
273 275
274 mActionSelectFilter->setCurrentItem( 0 ); 276 mActionSelectFilter->setCurrentItem( 0 );
275 setActiveFilter( 0 ); 277 setActiveFilter( 0 );
276 } else if ( view->defaultFilterType() == KAddressBookView::Active ) { 278 } else if ( view->defaultFilterType() == KAddressBookView::Active ) {
277 setActiveFilter( mActionSelectFilter->currentItem() ); 279 setActiveFilter( mActionSelectFilter->currentItem() );
278 } else { 280 } else {
279 uint pos = filterPosition( view->defaultFilterName() ); 281 uint pos = filterPosition( view->defaultFilterName() );
280 mActionSelectFilter->setCurrentItem( pos ); 282 mActionSelectFilter->setCurrentItem( pos );
281 setActiveFilter( pos ); 283 setActiveFilter( pos );
282 } 284 }
283//US qDebug("ViewManager::setActiveView 6" ); 285//US qDebug("ViewManager::setActiveView 6" );
284 286
285 // Update the inc search widget to show the fields in the new active 287 // Update the inc search widget to show the fields in the new active
286 // view. 288 // view.
287 mCore->setSearchFields( mActiveView->fields() ); 289 mCore->setSearchFields( mActiveView->fields() );
288 290
289//US performance optimization. setActiveFilter calls also mActiveView->refresh() 291//US performance optimization. setActiveFilter calls also mActiveView->refresh()
290//US mActiveView->refresh(); 292//US mActiveView->refresh();
291 } 293 }
292 else 294 else
293 { 295 {
294 qDebug("ViewManager::setActiveView: unable to find view" ); 296 qDebug("ViewManager::setActiveView: unable to find view" );
295 } 297 }
296} 298}
297 299
298//US added another method with no parameter, since my moc compiler does not support default parameters. 300//US added another method with no parameter, since my moc compiler does not support default parameters.
299void ViewManager::refreshView() 301void ViewManager::refreshView()
300{ 302{
301 refreshView( QString::null ); 303 refreshView( QString::null );
302} 304}
@@ -415,323 +417,325 @@ void ViewManager::addView()
415 // Check for name conflicts 417 // Check for name conflicts
416 bool firstConflict = true; 418 bool firstConflict = true;
417 int numTries = 1; 419 int numTries = 1;
418 while ( mViewNameList.contains( newName ) > 0 ) { 420 while ( mViewNameList.contains( newName ) > 0 ) {
419 if ( !firstConflict ) { 421 if ( !firstConflict ) {
420 newName = newName.left( newName.length() - 4 ); 422 newName = newName.left( newName.length() - 4 );
421 firstConflict = false; 423 firstConflict = false;
422 } 424 }
423 425
424 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); 426 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries );
425 numTries++; 427 numTries++;
426 } 428 }
427 429
428 // Add the new one to the list 430 // Add the new one to the list
429 mViewNameList.append( newName ); 431 mViewNameList.append( newName );
430 432
431 // write the view to the config file, 433 // write the view to the config file,
432 KConfig *config = mCore->config(); 434 KConfig *config = mCore->config();
433 435
434 config->deleteGroup( newName ); 436 config->deleteGroup( newName );
435 437
436 KConfigGroupSaver saver( config, newName ); 438 KConfigGroupSaver saver( config, newName );
437 439
438 config->writeEntry( "Type", type ); 440 config->writeEntry( "Type", type );
439 441
440 // try to set the active view 442 // try to set the active view
441 mActionSelectView->setItems( mViewNameList ); 443 mActionSelectView->setItems( mViewNameList );
442 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); 444 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) );
443 setActiveView( newName ); 445 setActiveView( newName );
444 446
445 editView(); 447 editView();
446 448
447 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 449 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
448 } 450 }
449} 451}
450 452
451void ViewManager::createViewFactories() 453void ViewManager::createViewFactories()
452{ 454{
453#ifndef KAB_EMBEDDED 455#ifndef KAB_EMBEDDED
454 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); 456 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
455 KTrader::OfferList::ConstIterator it; 457 KTrader::OfferList::ConstIterator it;
456 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 458 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
457 if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) 459 if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
458 continue; 460 continue;
459 461
460 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 462 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
461 463
462 if ( !factory ) { 464 if ( !factory ) {
463 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; 465 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
464 continue; 466 continue;
465 } 467 }
466 468
467 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); 469 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory );
468 470
469 if ( !viewFactory ) { 471 if ( !viewFactory ) {
470 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; 472 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl;
471 continue; 473 continue;
472 } 474 }
473 475
474 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 476 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
475 } 477 }
476 478
477#else //KAB_EMBEDDED 479#else //KAB_EMBEDDED
478 ViewFactory* viewFactory = new IconViewFactory(); 480 ViewFactory* viewFactory = new IconViewFactory();
479 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 481 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
480// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 482// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
481 483
482 viewFactory = new TableViewFactory(); 484 viewFactory = new TableViewFactory();
483 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 485 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
484// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 486// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
485 487
486 viewFactory = new CardViewFactory(); 488 viewFactory = new CardViewFactory();
487 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 489 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
488// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 490// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
489 491
490#endif //KAB_EMBEDDED 492#endif //KAB_EMBEDDED
491 493
492} 494}
493 495
494void ViewManager::dropped( QDropEvent *e ) 496void ViewManager::dropped( QDropEvent *e )
495{ 497{
496 498
497#ifndef KAB_EMBEDDED 499#ifndef KAB_EMBEDDED
498 500
499 QString clipText, vcards; 501 QString clipText, vcards;
500 KURL::List urls; 502 KURL::List urls;
501 503
502 if ( KURLDrag::decode( e, urls) ) { 504 if ( KURLDrag::decode( e, urls) ) {
503 KURL::List::Iterator it = urls.begin(); 505 KURL::List::Iterator it = urls.begin();
504 int c = urls.count(); 506 int c = urls.count();
505 if ( c > 1 ) { 507 if ( c > 1 ) {
506 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); 508 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c );
507 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { 509 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) {
508 for ( ; it != urls.end(); ++it ) 510 for ( ; it != urls.end(); ++it )
509 emit urlDropped( *it ); 511 emit urlDropped( *it );
510 } 512 }
511 } else if ( c == 1 ) 513 } else if ( c == 1 )
512 emit urlDropped( *it ); 514 emit urlDropped( *it );
513 } else if ( KVCardDrag::decode( e, vcards ) ) { 515 } else if ( KVCardDrag::decode( e, vcards ) ) {
514 KABC::Addressee addr; 516 KABC::Addressee addr;
515 KABC::VCardConverter converter; 517 KABC::VCardConverter converter;
516 QStringList list = QStringList::split( "\r\n\r\n", vcards ); 518 QStringList list = QStringList::split( "\r\n\r\n", vcards );
517 QStringList::Iterator it; 519 QStringList::Iterator it;
518 for ( it = list.begin(); it != list.end(); ++it ) { 520 for ( it = list.begin(); it != list.end(); ++it ) {
519 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { 521 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) {
520 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); 522 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() );
521 if ( a.isEmpty() ) { 523 if ( a.isEmpty() ) {
522 mCore->addressBook()->insertAddressee( addr ); 524 mCore->addressBook()->insertAddressee( addr );
523 emit modified(); 525 emit modified();
524 } 526 }
525 } 527 }
526 } 528 }
527 529
528 mActiveView->refresh(); 530 mActiveView->refresh();
529 } 531 }
530#else //KAB_EMBEDDED 532#else //KAB_EMBEDDED
531qDebug("ViewManager::dropped() has to be changed!!" ); 533qDebug("ViewManager::dropped() has to be changed!!" );
532#endif //KAB_EMBEDDED 534#endif //KAB_EMBEDDED
533 535
534} 536}
535 537
536void ViewManager::startDrag() 538void ViewManager::startDrag()
537{ 539{
538 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; 540 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
539 541
540#ifndef KAB_EMBEDDED 542#ifndef KAB_EMBEDDED
541 543
542 // Get the list of all the selected addressees 544 // Get the list of all the selected addressees
543 KABC::Addressee::List addrList; 545 KABC::Addressee::List addrList;
544 QStringList uidList = selectedUids(); 546 QStringList uidList = selectedUids();
545 QStringList::Iterator iter; 547 QStringList::Iterator iter;
546 for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) 548 for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
547 addrList.append( mCore->addressBook()->findByUid( *iter ) ); 549 addrList.append( mCore->addressBook()->findByUid( *iter ) );
548 550
549 KMultipleDrag *drag = new KMultipleDrag( this ); 551 KMultipleDrag *drag = new KMultipleDrag( this );
550 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); 552 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) );
551 KABC::Addressee::List::Iterator it; 553 KABC::Addressee::List::Iterator it;
552 QStringList vcards; 554 QStringList vcards;
553 for ( it = addrList.begin(); it != addrList.end(); ++it ) { 555 for ( it = addrList.begin(); it != addrList.end(); ++it ) {
554 QString vcard = QString::null; 556 QString vcard = QString::null;
555 KABC::VCardConverter converter; 557 KABC::VCardConverter converter;
556 if ( converter.addresseeToVCard( *it, vcard ) ) 558 if ( converter.addresseeToVCard( *it, vcard ) )
557 vcards.append( vcard ); 559 vcards.append( vcard );
558 } 560 }
559 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); 561 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) );
560 562
561 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); 563 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) );
562 drag->dragCopy(); 564 drag->dragCopy();
563 565
564#else //KAB_EMBEDDED 566#else //KAB_EMBEDDED
565qDebug("ViewManager::startDrag() has to be changed!!" ); 567qDebug("ViewManager::startDrag() has to be changed!!" );
566#endif //KAB_EMBEDDED 568#endif //KAB_EMBEDDED
567 569
568} 570}
569void ViewManager::doSearch( const QString& s,KABC::Field *field ) 571void ViewManager::doSearch( const QString& s,KABC::Field *field )
570{ 572{
571 if ( mActiveView ) 573 if ( mActiveView )
572 mActiveView->doSearch( s, field ); 574 mActiveView->doSearch( s, field );
573 575
574} 576}
575void ViewManager::setActiveFilter( int index ) 577void ViewManager::setActiveFilter( int index )
576{ 578{
577 Filter currentFilter; 579 Filter currentFilter;
578 580
579 if ( ( index - 1 ) < 0 ) 581 if ( ( index - 1 ) < 0 )
580 currentFilter = Filter(); 582 currentFilter = Filter();
581 else 583 else
582 currentFilter = mFilterList[ index - 1 ]; 584 currentFilter = mFilterList[ index - 1 ];
583 585
584 // Check if we have a view. Since the filter combo is created before 586 // Check if we have a view. Since the filter combo is created before
585 // the view, this slot could be called before there is a valid view. 587 // the view, this slot could be called before there is a valid view.
586 if ( mActiveView ) { 588 if ( mActiveView ) {
587 mActiveView->setFilter( currentFilter ); 589 mActiveView->setFilter( currentFilter );
588 mActiveView->refresh(); 590 mActiveView->refresh();
589 emit selected( QString::null ); 591 emit selected( QString::null );
590 } 592 }
591} 593}
592 594
593void ViewManager::configureFilters() 595void ViewManager::configureFilters()
594{ 596{
595 FilterDialog dlg( this ); 597 FilterDialog dlg( this );
596 598
597 dlg.setFilters( mFilterList ); 599 dlg.setFilters( mFilterList );
598 600
599 if ( dlg.exec() ) 601 if ( dlg.exec() )
600 mFilterList = dlg.filters(); 602 mFilterList = dlg.filters();
601 603
602 uint pos = mActionSelectFilter->currentItem(); 604 uint pos = mActionSelectFilter->currentItem();
603 mActionSelectFilter->setItems( filterNames() ); 605 mActionSelectFilter->setItems( filterNames() );
604 mActionSelectFilter->setCurrentItem( pos ); 606 mActionSelectFilter->setCurrentItem( pos );
605 setActiveFilter( pos ); 607 setActiveFilter( pos );
606 int cw = 150; 608 int cw = 150;
609 if ( QApplication::desktop()->width() >= 800 )
610 cw = 200;
607 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) 611 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch)
608 cw = 0; 612 cw = 0;
609 mActionSelectFilter->setComboWidth( cw ); 613 mActionSelectFilter->setComboWidth( cw );
610 saveSettings(); 614 saveSettings();
611} 615}
612 616
613QStringList ViewManager::filterNames() const 617QStringList ViewManager::filterNames() const
614{ 618{
615 QStringList names( i18n( "No Filter" ) ); 619 QStringList names( i18n( "No Filter" ) );
616 620
617 Filter::List::ConstIterator it; 621 Filter::List::ConstIterator it;
618 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) 622 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
619 names.append( (*it).name() ); 623 names.append( (*it).name() );
620 624
621 return names; 625 return names;
622} 626}
623Filter ViewManager::getFilterByName( const QString &name ) const 627Filter ViewManager::getFilterByName( const QString &name ) const
624{ 628{
625 Filter::List::ConstIterator it; 629 Filter::List::ConstIterator it;
626 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) 630 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
627 if ( name == (*it).name() ) 631 if ( name == (*it).name() )
628 return (*it); 632 return (*it);
629 633
630 return Filter(); 634 return Filter();
631} 635}
632 636
633int ViewManager::filterPosition( const QString &name ) const 637int ViewManager::filterPosition( const QString &name ) const
634{ 638{
635 int pos = 0; 639 int pos = 0;
636 640
637 Filter::List::ConstIterator it; 641 Filter::List::ConstIterator it;
638 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) 642 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos )
639 if ( name == (*it).name() ) 643 if ( name == (*it).name() )
640 return pos + 1; 644 return pos + 1;
641 645
642 return 0; 646 return 0;
643} 647}
644 648
645void ViewManager::initActions() 649void ViewManager::initActions()
646{ 650{
647//US <ActionList name="view_loadedviews"/> 651//US <ActionList name="view_loadedviews"/>
648//US <Separator/> 652//US <Separator/>
649 653
650#ifdef KAB_EMBEDDED 654#ifdef KAB_EMBEDDED
651 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); 655 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu();
652 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); 656 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
653 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); 657 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu();
654#endif //KAB_EMBEDDED 658#endif //KAB_EMBEDDED
655 659
656 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); 660 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" );
657#if KDE_VERSION >= 309 661#if KDE_VERSION >= 309
658 mActionSelectView->setMenuAccelsEnabled( false ); 662 mActionSelectView->setMenuAccelsEnabled( false );
659#endif 663#endif
660 connect( mActionSelectView, SIGNAL( activated( const QString& ) ), 664 connect( mActionSelectView, SIGNAL( activated( const QString& ) ),
661 SLOT( selectView( const QString& ) ) ); 665 SLOT( selectView( const QString& ) ) );
662 666
663 667
664#ifdef KAB_EMBEDDED 668#ifdef KAB_EMBEDDED
665 mActionSelectView->plug(viewmenu); 669 mActionSelectView->plug(viewmenu);
666 viewmenu->insertSeparator(); 670 viewmenu->insertSeparator();
667#endif //KAB_EMBEDDED 671#endif //KAB_EMBEDDED
668 672
669 KAction *action; 673 KAction *action;
670 674
671 action = new KAction( i18n( "Modify View..." ), "configure", 0, this, 675 action = new KAction( i18n( "Modify View..." ), "configure", 0, this,
672 SLOT( editView() ), mCore->actionCollection(), "view_modify" ); 676 SLOT( editView() ), mCore->actionCollection(), "view_modify" );
673#ifndef KAB_EMBEDDED 677#ifndef KAB_EMBEDDED
674 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." ) ); 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." ) );
675#else //KAB_EMBEDDED 679#else //KAB_EMBEDDED
676 action->plug(viewmenu); 680 action->plug(viewmenu);
677#endif //KAB_EMBEDDED 681#endif //KAB_EMBEDDED
678 682
679 action = new KAction( i18n( "Add View..." ), "window_new", 0, this, 683 action = new KAction( i18n( "Add View..." ), "window_new", 0, this,
680 SLOT( addView() ), mCore->actionCollection(), "view_add" ); 684 SLOT( addView() ), mCore->actionCollection(), "view_add" );
681#ifndef KAB_EMBEDDED 685#ifndef KAB_EMBEDDED
682 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." ) ); 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." ) );
683#else //KAB_EMBEDDED 687#else //KAB_EMBEDDED
684 action->plug(viewmenu); 688 action->plug(viewmenu);
685#endif //KAB_EMBEDDED 689#endif //KAB_EMBEDDED
686 690
687 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0, 691 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0,
688 this, SLOT( deleteView() ), 692 this, SLOT( deleteView() ),
689 mCore->actionCollection(), "view_delete" ); 693 mCore->actionCollection(), "view_delete" );
690#ifndef KAB_EMBEDDED 694#ifndef KAB_EMBEDDED
691 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) ); 695 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) );
692#else //KAB_EMBEDDED 696#else //KAB_EMBEDDED
693 mActionDeleteView->plug(viewmenu); 697 mActionDeleteView->plug(viewmenu);
694 viewmenu->insertSeparator(); 698 viewmenu->insertSeparator();
695#endif //KAB_EMBEDDED 699#endif //KAB_EMBEDDED
696 700
697#ifndef KAB_EMBEDDED 701#ifndef KAB_EMBEDDED
698 action = new KAction( i18n( "Refresh View" ), "reload", 0, this, 702 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
699 SLOT( refreshView(const QString &) ), mCore->actionCollection(), 703 SLOT( refreshView(const QString &) ), mCore->actionCollection(),
700 "view_refresh" ); 704 "view_refresh" );
701 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) ); 705 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) );
702#else //KAB_EMBEDDED 706#else //KAB_EMBEDDED
703 action = new KAction( i18n( "Refresh View" ), "reload", 0, this, 707 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
704 SLOT( refreshView()), mCore->actionCollection(), 708 SLOT( refreshView()), mCore->actionCollection(),
705 "view_refresh" ); 709 "view_refresh" );
706 action->plug(viewmenu); 710 action->plug(viewmenu);
707 //viewmenu->insertSeparator(); 711 //viewmenu->insertSeparator();
708#endif //KAB_EMBEDDED 712#endif //KAB_EMBEDDED
709 713
710 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this, 714 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this,
711 SLOT( configureFilters() ), mCore->actionCollection(), 715 SLOT( configureFilters() ), mCore->actionCollection(),
712 "options_edit_filters" ); 716 "options_edit_filters" );
713 717
714 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" ); 718 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" );
715#if KDE_VERSION >= 309 719#if KDE_VERSION >= 309
716 mActionSelectFilter->setMenuAccelsEnabled( false ); 720 mActionSelectFilter->setMenuAccelsEnabled( false );
717#endif 721#endif
718 connect( mActionSelectFilter, SIGNAL( activated( int ) ), 722 connect( mActionSelectFilter, SIGNAL( activated( int ) ),
719 SLOT( setActiveFilter( int ) ) ); 723 SLOT( setActiveFilter( int ) ) );
720 724
721#ifdef KAB_EMBEDDED 725#ifdef KAB_EMBEDDED
722 action->plug(settingsmenu); 726 action->plug(settingsmenu);
723 mActionSelectFilter->plug(viewmenu,0); 727 mActionSelectFilter->plug(viewmenu,0);
724#endif //KAB_EMBEDDED 728#endif //KAB_EMBEDDED
725 729
726} 730}
727 731
728void ViewManager::initGUI() 732void ViewManager::initGUI()
729{ 733{
730 QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 ); 734 QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 );
731 mViewWidgetStack = new QWidgetStack( this ); 735 mViewWidgetStack = new QWidgetStack( this );
732 layout->addWidget( mViewWidgetStack ); 736 layout->addWidget( mViewWidgetStack );
733} 737}
734 738
735#ifndef KAB_EMBEDDED 739#ifndef KAB_EMBEDDED
736#include "viewmanager.moc" 740#include "viewmanager.moc"
737#endif //KAB_EMBEDDED 741#endif //KAB_EMBEDDED