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