summaryrefslogtreecommitdiffabout
path: root/kaddressbook/viewmanager.cpp
Unidiff
Diffstat (limited to 'kaddressbook/viewmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/viewmanager.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index 9c3a641..4be860e 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -30,518 +30,517 @@ $Id$
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() == 480 ) 111 if (QApplication::desktop()->width() == 480 )
112 cw = 0; 112 cw = 0;
113 mActionSelectFilter->setComboWidth( cw ); 113 mActionSelectFilter->setComboWidth( cw );
114 // Tell the views to reread their config, since they may have 114 // Tell the views to reread their config, since they may have
115 // been modified by global settings 115 // been modified by global settings
116 QString _oldgroup = mCore->config()->group(); 116 QString _oldgroup = mCore->config()->group();
117 117
118 QDictIterator<KAddressBookView> it( mViewDict ); 118 QDictIterator<KAddressBookView> it( mViewDict );
119 for ( it.toFirst(); it.current(); ++it ) { 119 for ( it.toFirst(); it.current(); ++it ) {
120 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 120 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
121 it.current()->readConfig( mCore->config() ); 121 it.current()->readConfig( mCore->config() );
122 } 122 }
123 setActiveView( activeViewName ); 123 setActiveView( activeViewName );
124 124
125 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 125 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
126} 126}
127 127
128void ViewManager::saveSettings() 128void ViewManager::saveSettings()
129{ 129{
130 QString _oldgroup = mCore->config()->group(); 130 QString _oldgroup = mCore->config()->group();
131 131
132 QDictIterator<KAddressBookView> it( mViewDict ); 132 QDictIterator<KAddressBookView> it( mViewDict );
133 for ( it.toFirst(); it.current(); ++it ) { 133 for ( it.toFirst(); it.current(); ++it ) {
134 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 134 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
135#ifdef DESKTOP_VERSION 135#ifdef DESKTOP_VERSION
136 (*it)->writeConfig( mCore->config() ); 136 (*it)->writeConfig( mCore->config() );
137#else 137#else
138 (*it).writeConfig( mCore->config() ); 138 (*it).writeConfig( mCore->config() );
139#endif 139#endif
140 } 140 }
141 141
142 Filter::save( mCore->config(), "Filter", mFilterList ); 142 Filter::save( mCore->config(), "Filter", mFilterList );
143 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); 143 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
144 144
145 // write the view name list 145 // write the view name list
146 KABPrefs::instance()->mViewNames = mViewNameList; 146 KABPrefs::instance()->mViewNames = mViewNameList;
147 KABPrefs::instance()->mCurrentView = mActiveView->caption(); 147 KABPrefs::instance()->mCurrentView = mActiveView->caption();
148 148
149} 149}
150 150
151QStringList ViewManager::selectedUids() const 151QStringList ViewManager::selectedUids() const
152{ 152{
153 if ( mActiveView ) 153 if ( mActiveView )
154 return mActiveView->selectedUids(); 154 return mActiveView->selectedUids();
155 else 155 else
156 return QStringList(); 156 return QStringList();
157} 157}
158 158
159QStringList ViewManager::selectedEmails() const 159QStringList ViewManager::selectedEmails() const
160{ 160{
161 if ( mActiveView ) 161 if ( mActiveView )
162 return mActiveView->selectedEmails(); 162 return mActiveView->selectedEmails();
163 else 163 else
164 return QStringList(); 164 return QStringList();
165} 165}
166 166
167KABC::Addressee::List ViewManager::selectedAddressees() const 167KABC::Addressee::List ViewManager::selectedAddressees() const
168{ 168{
169 KABC::Addressee::List list; 169 KABC::Addressee::List list;
170 if ( mActiveView ) { 170 if ( mActiveView ) {
171 QStringList uids = mActiveView->selectedUids(); 171 QStringList uids = mActiveView->selectedUids();
172 QStringList::Iterator it; 172 QStringList::Iterator it;
173 for ( it = uids.begin(); it != uids.end(); ++it ) { 173 for ( it = uids.begin(); it != uids.end(); ++it ) {
174 KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); 174 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
175 if ( !addr.isEmpty() ) 175 if ( !addr.isEmpty() )
176 list.append( addr ); 176 list.append( addr );
177 } 177 }
178 } 178 }
179 179
180 return list; 180 return list;
181} 181}
182//US added another method with no parameter, since my moc compiler does not support default parameters. 182//US added another method with no parameter, since my moc compiler does not support default parameters.
183void ViewManager::setSelected() 183void ViewManager::setSelected()
184{ 184{
185 setSelected( QString::null, true ); 185 setSelected( QString::null, true );
186} 186}
187 187
188void ViewManager::setSelected( const QString &uid, bool selected ) 188void ViewManager::setSelected( const QString &uid, bool selected )
189{ 189{
190 if ( mActiveView ) 190 if ( mActiveView )
191 mActiveView->setSelected( uid, selected ); 191 mActiveView->setSelected( uid, selected );
192} 192}
193 193
194void ViewManager::setListSelected(QStringList list) 194void ViewManager::setListSelected(QStringList list)
195{ 195{
196 int i, count = list.count(); 196 int i, count = list.count();
197 for ( i = 0; i < count;++i ) 197 for ( i = 0; i < count;++i )
198 setSelected( list[i], true ); 198 setSelected( list[i], true );
199 199
200} 200}
201void ViewManager::unloadViews() 201void ViewManager::unloadViews()
202{ 202{
203 mViewDict.clear(); 203 mViewDict.clear();
204 mActiveView = 0; 204 mActiveView = 0;
205} 205}
206 206
207void ViewManager::setActiveView( const QString &name ) 207void ViewManager::setActiveView( const QString &name )
208{ 208{
209 KAddressBookView *view = 0; 209 KAddressBookView *view = 0;
210 210
211 // Check that this isn't the same as the current active view 211 // Check that this isn't the same as the current active view
212 if ( mActiveView && ( mActiveView->caption() == name ) ) 212 if ( mActiveView && ( mActiveView->caption() == name ) )
213 return; 213 return;
214 214
215 // At this point we know the view that should be active is not 215 // At this point we know the view that should be active is not
216 // currently active. We will try to find the new on in the list. If 216 // currently active. We will try to find the new on in the list. If
217 // we can't find it, it means it hasn't been instantiated, so we will 217 // we can't find it, it means it hasn't been instantiated, so we will
218 // create it on demand. 218 // create it on demand.
219 219
220 view = mViewDict.find( name ); 220 view = mViewDict.find( name );
221 221
222 // Check if we found the view. If we didn't, then we need to create it 222 // Check if we found the view. If we didn't, then we need to create it
223 if ( view == 0 ) { 223 if ( view == 0 ) {
224 KConfig *config = mCore->config(); 224 KConfig *config = mCore->config();
225 225
226 KConfigGroupSaver saver( config, name ); 226 KConfigGroupSaver saver( config, name );
227 227
228 QString type = config->readEntry( "Type", "Table" ); 228 QString type = config->readEntry( "Type", "Table" );
229 229
230 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; 230 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
231 231
232 ViewFactory *factory = mViewFactoryDict.find( type ); 232 ViewFactory *factory = mViewFactoryDict.find( type );
233 if ( factory ) 233 if ( factory )
234 view = factory->view( mCore->addressBook(), mViewWidgetStack ); 234 view = factory->view( mCore->addressBook(), mViewWidgetStack );
235 235
236 if ( view ) { 236 if ( view ) {
237 view->setCaption( name ); 237 view->setCaption( name );
238 mViewDict.insert( name, view ); 238 mViewDict.insert( name, view );
239//US my version needs an int as second parameter to addWidget 239//US my version needs an int as second parameter to addWidget
240 mViewWidgetStack->addWidget( view, -1 ); 240 mViewWidgetStack->addWidget( view, -1 );
241 view->readConfig( config ); 241 view->readConfig( config );
242 242
243 // The manager just relays the signals 243 // The manager just relays the signals
244 connect( view, SIGNAL( selected( const QString& ) ), 244 connect( view, SIGNAL( selected( const QString& ) ),
245 SIGNAL( selected( const QString & ) ) ); 245 SIGNAL( selected( const QString & ) ) );
246 connect( view, SIGNAL( executed( const QString& ) ), 246 connect( view, SIGNAL( executed( const QString& ) ),
247 SIGNAL( executed( const QString& ) ) ); 247 SIGNAL( executed( const QString& ) ) );
248 248
249 connect( view, SIGNAL( deleteRequest( ) ), 249 connect( view, SIGNAL( deleteRequest( ) ),
250 SIGNAL( deleteRequest( ) ) ); 250 SIGNAL( deleteRequest( ) ) );
251 251
252 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); 252 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
253 connect( view, SIGNAL( dropped( QDropEvent* ) ), 253 connect( view, SIGNAL( dropped( QDropEvent* ) ),
254 SLOT( dropped( QDropEvent* ) ) ); 254 SLOT( dropped( QDropEvent* ) ) );
255 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); 255 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
256 } 256 }
257 } 257 }
258 258
259 // If we found or created the view, raise it and refresh it 259 // If we found or created the view, raise it and refresh it
260 if ( view ) { 260 if ( view ) {
261 mActiveView = view; 261 mActiveView = view;
262 mViewWidgetStack->raiseWidget( view ); 262 mViewWidgetStack->raiseWidget( view );
263 // Set the proper filter in the view. By setting the combo 263 // Set the proper filter in the view. By setting the combo
264 // box, the activated slot will be called, which will push 264 // box, the activated slot will be called, which will push
265 // the filter to the view and refresh it. 265 // the filter to the view and refresh it.
266 266
267 if ( view->defaultFilterType() == KAddressBookView::None ) { 267 if ( view->defaultFilterType() == KAddressBookView::None ) {
268 268
269 mActionSelectFilter->setCurrentItem( 0 ); 269 mActionSelectFilter->setCurrentItem( 0 );
270 setActiveFilter( 0 ); 270 setActiveFilter( 0 );
271 } else if ( view->defaultFilterType() == KAddressBookView::Active ) { 271 } else if ( view->defaultFilterType() == KAddressBookView::Active ) {
272 setActiveFilter( mActionSelectFilter->currentItem() ); 272 setActiveFilter( mActionSelectFilter->currentItem() );
273 } else { 273 } else {
274 uint pos = filterPosition( view->defaultFilterName() ); 274 uint pos = filterPosition( view->defaultFilterName() );
275 mActionSelectFilter->setCurrentItem( pos ); 275 mActionSelectFilter->setCurrentItem( pos );
276 setActiveFilter( pos ); 276 setActiveFilter( pos );
277 } 277 }
278//US qDebug("ViewManager::setActiveView 6" ); 278//US qDebug("ViewManager::setActiveView 6" );
279 279
280 // Update the inc search widget to show the fields in the new active 280 // Update the inc search widget to show the fields in the new active
281 // view. 281 // view.
282 mCore->setSearchFields( mActiveView->fields() ); 282 mCore->setSearchFields( mActiveView->fields() );
283 283
284//US performance optimization. setActiveFilter calls also mActiveView->refresh() 284//US performance optimization. setActiveFilter calls also mActiveView->refresh()
285//US mActiveView->refresh(); 285//US mActiveView->refresh();
286 286 mCore->saveSettings();
287 } 287 }
288 else 288 else
289 { 289 {
290 qDebug("ViewManager::setActiveView: unable to find view" ); 290 qDebug("ViewManager::setActiveView: unable to find view" );
291 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n";
292 } 291 }
293} 292}
294 293
295//US added another method with no parameter, since my moc compiler does not support default parameters. 294//US added another method with no parameter, since my moc compiler does not support default parameters.
296void ViewManager::refreshView() 295void ViewManager::refreshView()
297{ 296{
298 refreshView( QString::null ); 297 refreshView( QString::null );
299} 298}
300 299
301void ViewManager::refreshView( const QString &uid ) 300void ViewManager::refreshView( const QString &uid )
302{ 301{
303 if ( mActiveView ) 302 if ( mActiveView )
304 mActiveView->refresh( uid ); 303 mActiveView->refresh( uid );
305} 304}
306 305
307void ViewManager::setFocusAV() 306void ViewManager::setFocusAV()
308{ 307{
309 if ( mActiveView ) 308 if ( mActiveView )
310 mActiveView->setFocusAV(); 309 mActiveView->setFocusAV();
311} 310}
312void ViewManager::editView() 311void ViewManager::editView()
313{ 312{
314 if ( !mActiveView ) 313 if ( !mActiveView )
315 return; 314 return;
316 315
317 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); 316 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() );
318 ViewConfigureWidget *wdg = 0; 317 ViewConfigureWidget *wdg = 0;
319 ViewConfigureDialog* dlg = 0; 318 ViewConfigureDialog* dlg = 0;
320 if ( factory ) { 319 if ( factory ) {
321 // Save the filters so the dialog has the latest set 320 // Save the filters so the dialog has the latest set
322 Filter::save( mCore->config(), "Filter", mFilterList ); 321 Filter::save( mCore->config(), "Filter", mFilterList );
323 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); 322 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" );
324 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); 323 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" );
325 } else { 324 } else {
326 qDebug("ViewManager::editView()::cannot find viewfactory "); 325 qDebug("ViewManager::editView()::cannot find viewfactory ");
327 return; 326 return;
328 } 327 }
329 if ( wdg ) { 328 if ( wdg ) {
330 dlg->setWidget( wdg ); 329 dlg->setWidget( wdg );
331 330
332#ifndef DESKTOP_VERSION 331#ifndef DESKTOP_VERSION
333 //dlg.setMaximumSize( 640, 480 ); 332 //dlg.setMaximumSize( 640, 480 );
334 //dlg->setGeometry( 40,40, 400, 300); 333 //dlg->setGeometry( 40,40, 400, 300);
335 dlg->showMaximized(); 334 dlg->showMaximized();
336#endif 335#endif
337 336
338 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); 337 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() );
339 338
340 dlg->restoreSettings( mCore->config() ); 339 dlg->restoreSettings( mCore->config() );
341 340
342 if ( dlg->exec() ) { 341 if ( dlg->exec() ) {
343 dlg->saveSettings( mCore->config() ); 342 dlg->saveSettings( mCore->config() );
344 mActiveView->readConfig( mCore->config() ); 343 mActiveView->readConfig( mCore->config() );
345 344
346 // Set the proper filter in the view. By setting the combo 345 // Set the proper filter in the view. By setting the combo
347 // box, the activated slot will be called, which will push 346 // box, the activated slot will be called, which will push
348 // the filter to the view and refresh it. 347 // the filter to the view and refresh it.
349 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { 348 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) {
350 mActionSelectFilter->setCurrentItem( 0 ); 349 mActionSelectFilter->setCurrentItem( 0 );
351 setActiveFilter( 0 ); 350 setActiveFilter( 0 );
352 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { 351 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) {
353 setActiveFilter( mActionSelectFilter->currentItem() ); 352 setActiveFilter( mActionSelectFilter->currentItem() );
354 } else { 353 } else {
355 uint pos = filterPosition( mActiveView->defaultFilterName() ); 354 uint pos = filterPosition( mActiveView->defaultFilterName() );
356 mActionSelectFilter->setCurrentItem( pos ); 355 mActionSelectFilter->setCurrentItem( pos );
357 setActiveFilter( pos ); 356 setActiveFilter( pos );
358 } 357 }
359 mCore->setSearchFields( mActiveView->fields() ); 358 mCore->setSearchFields( mActiveView->fields() );
360//US performance optimization. setActiveFilter calls also mActiveView->refresh() 359//US performance optimization. setActiveFilter calls also mActiveView->refresh()
361//US mActiveView->refresh(); 360//US mActiveView->refresh();
362 361
363 362
364 //US this is a bugfix, that we get notified if we change a views configuration 363 //US this is a bugfix, that we get notified if we change a views configuration
365 emit modified(); 364 emit modified();
366 365
367 } 366 }
368 367
369 } 368 }
370 delete dlg; 369 delete dlg;
371} 370}
372 371
373void ViewManager::deleteView() 372void ViewManager::deleteView()
374{ 373{
375 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) 374 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" )
376 .arg( mActiveView->caption() ); 375 .arg( mActiveView->caption() );
377 QString caption = i18n( "Confirm Delete" ); 376 QString caption = i18n( "Confirm Delete" );
378 377
379 378
380 if (QMessageBox::information( this, caption, 379 if (QMessageBox::information( this, caption,
381 text, 380 text,
382 i18n("Yes!"), i18n("No"), 0, 0 ) == 0) 381 i18n("Yes!"), i18n("No"), 0, 0 ) == 0)
383 { 382 {
384 mViewNameList.remove( mActiveView->caption() ); 383 mViewNameList.remove( mActiveView->caption() );
385 384
386 // remove the view from the config file 385 // remove the view from the config file
387 KConfig *config = mCore->config(); 386 KConfig *config = mCore->config();
388 config->deleteGroup( mActiveView->caption() ); 387 config->deleteGroup( mActiveView->caption() );
389 388
390 mViewDict.remove( mActiveView->caption() ); 389 mViewDict.remove( mActiveView->caption() );
391 mActiveView = 0; 390 mActiveView = 0;
392 391
393 // we are in an invalid state now, but that should be fixed after 392 // we are in an invalid state now, but that should be fixed after
394 // we emit the signal 393 // we emit the signal
395 mActionSelectView->setItems( mViewNameList ); 394 mActionSelectView->setItems( mViewNameList );
396 if ( mViewNameList.count() > 0 ) { 395 if ( mViewNameList.count() > 0 ) {
397 mActionSelectView->setCurrentItem( 0 ); 396 mActionSelectView->setCurrentItem( 0 );
398 setActiveView( mViewNameList[ 0 ] ); 397 setActiveView( mViewNameList[ 0 ] );
399 } 398 }
400 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 399 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
401 } 400 }
402} 401}
403 402
404void ViewManager::addView() 403void ViewManager::addView()
405{ 404{
406 AddViewDialog dialog( &mViewFactoryDict, this ); 405 AddViewDialog dialog( &mViewFactoryDict, this );
407 406
408 if ( dialog.exec() ) { 407 if ( dialog.exec() ) {
409 QString newName = dialog.viewName(); 408 QString newName = dialog.viewName();
410 QString type = dialog.viewType(); 409 QString type = dialog.viewType();
411 410
412 // Check for name conflicts 411 // Check for name conflicts
413 bool firstConflict = true; 412 bool firstConflict = true;
414 int numTries = 1; 413 int numTries = 1;
415 while ( mViewNameList.contains( newName ) > 0 ) { 414 while ( mViewNameList.contains( newName ) > 0 ) {
416 if ( !firstConflict ) { 415 if ( !firstConflict ) {
417 newName = newName.left( newName.length() - 4 ); 416 newName = newName.left( newName.length() - 4 );
418 firstConflict = false; 417 firstConflict = false;
419 } 418 }
420 419
421 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); 420 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries );
422 numTries++; 421 numTries++;
423 } 422 }
424 423
425 // Add the new one to the list 424 // Add the new one to the list
426 mViewNameList.append( newName ); 425 mViewNameList.append( newName );
427 426
428 // write the view to the config file, 427 // write the view to the config file,
429 KConfig *config = mCore->config(); 428 KConfig *config = mCore->config();
430 429
431 config->deleteGroup( newName ); 430 config->deleteGroup( newName );
432 431
433 KConfigGroupSaver saver( config, newName ); 432 KConfigGroupSaver saver( config, newName );
434 433
435 config->writeEntry( "Type", type ); 434 config->writeEntry( "Type", type );
436 435
437 // try to set the active view 436 // try to set the active view
438 mActionSelectView->setItems( mViewNameList ); 437 mActionSelectView->setItems( mViewNameList );
439 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); 438 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) );
440 setActiveView( newName ); 439 setActiveView( newName );
441 440
442 editView(); 441 editView();
443 442
444 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 443 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
445 } 444 }
446} 445}
447 446
448void ViewManager::createViewFactories() 447void ViewManager::createViewFactories()
449{ 448{
450#ifndef KAB_EMBEDDED 449#ifndef KAB_EMBEDDED
451 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); 450 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
452 KTrader::OfferList::ConstIterator it; 451 KTrader::OfferList::ConstIterator it;
453 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 452 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
454 if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) 453 if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
455 continue; 454 continue;
456 455
457 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 456 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
458 457
459 if ( !factory ) { 458 if ( !factory ) {
460 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; 459 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
461 continue; 460 continue;
462 } 461 }
463 462
464 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); 463 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory );
465 464
466 if ( !viewFactory ) { 465 if ( !viewFactory ) {
467 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; 466 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl;
468 continue; 467 continue;
469 } 468 }
470 469
471 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 470 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
472 } 471 }
473 472
474#else //KAB_EMBEDDED 473#else //KAB_EMBEDDED
475 ViewFactory* viewFactory = new IconViewFactory(); 474 ViewFactory* viewFactory = new IconViewFactory();
476 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 475 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
477// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 476// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
478 477
479 viewFactory = new TableViewFactory(); 478 viewFactory = new TableViewFactory();
480 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 479 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
481// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 480// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
482 481
483 viewFactory = new CardViewFactory(); 482 viewFactory = new CardViewFactory();
484 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 483 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
485// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 484// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
486 485
487#endif //KAB_EMBEDDED 486#endif //KAB_EMBEDDED
488 487
489} 488}
490 489
491void ViewManager::dropped( QDropEvent *e ) 490void ViewManager::dropped( QDropEvent *e )
492{ 491{
493 kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; 492 kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl;
494 493
495#ifndef KAB_EMBEDDED 494#ifndef KAB_EMBEDDED
496 495
497 QString clipText, vcards; 496 QString clipText, vcards;
498 KURL::List urls; 497 KURL::List urls;
499 498
500 if ( KURLDrag::decode( e, urls) ) { 499 if ( KURLDrag::decode( e, urls) ) {
501 KURL::List::Iterator it = urls.begin(); 500 KURL::List::Iterator it = urls.begin();
502 int c = urls.count(); 501 int c = urls.count();
503 if ( c > 1 ) { 502 if ( c > 1 ) {
504 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); 503 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c );
505 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { 504 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) {
506 for ( ; it != urls.end(); ++it ) 505 for ( ; it != urls.end(); ++it )
507 emit urlDropped( *it ); 506 emit urlDropped( *it );
508 } 507 }
509 } else if ( c == 1 ) 508 } else if ( c == 1 )
510 emit urlDropped( *it ); 509 emit urlDropped( *it );
511 } else if ( KVCardDrag::decode( e, vcards ) ) { 510 } else if ( KVCardDrag::decode( e, vcards ) ) {
512 KABC::Addressee addr; 511 KABC::Addressee addr;
513 KABC::VCardConverter converter; 512 KABC::VCardConverter converter;
514 QStringList list = QStringList::split( "\r\n\r\n", vcards ); 513 QStringList list = QStringList::split( "\r\n\r\n", vcards );
515 QStringList::Iterator it; 514 QStringList::Iterator it;
516 for ( it = list.begin(); it != list.end(); ++it ) { 515 for ( it = list.begin(); it != list.end(); ++it ) {
517 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { 516 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) {
518 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); 517 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() );
519 if ( a.isEmpty() ) { 518 if ( a.isEmpty() ) {
520 mCore->addressBook()->insertAddressee( addr ); 519 mCore->addressBook()->insertAddressee( addr );
521 emit modified(); 520 emit modified();
522 } 521 }
523 } 522 }
524 } 523 }
525 524
526 mActiveView->refresh(); 525 mActiveView->refresh();
527 } 526 }
528#else //KAB_EMBEDDED 527#else //KAB_EMBEDDED
529qDebug("ViewManager::dropped() has to be changed!!" ); 528qDebug("ViewManager::dropped() has to be changed!!" );
530#endif //KAB_EMBEDDED 529#endif //KAB_EMBEDDED
531 530
532} 531}
533 532
534void ViewManager::startDrag() 533void ViewManager::startDrag()
535{ 534{
536 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; 535 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
537 536
538#ifndef KAB_EMBEDDED 537#ifndef KAB_EMBEDDED
539 538
540 // Get the list of all the selected addressees 539 // Get the list of all the selected addressees
541 KABC::Addressee::List addrList; 540 KABC::Addressee::List addrList;
542 QStringList uidList = selectedUids(); 541 QStringList uidList = selectedUids();
543 QStringList::Iterator iter; 542 QStringList::Iterator iter;
544 for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) 543 for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
545 addrList.append( mCore->addressBook()->findByUid( *iter ) ); 544 addrList.append( mCore->addressBook()->findByUid( *iter ) );
546 545
547 KMultipleDrag *drag = new KMultipleDrag( this ); 546 KMultipleDrag *drag = new KMultipleDrag( this );