summaryrefslogtreecommitdiffabout
path: root/kaddressbook/viewmanager.cpp
Side-by-side diff
Diffstat (limited to 'kaddressbook/viewmanager.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/viewmanager.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index 4be860e..04759a7 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -159,176 +159,180 @@ QStringList ViewManager::selectedUids() const
QStringList ViewManager::selectedEmails() const
{
if ( mActiveView )
return mActiveView->selectedEmails();
else
return QStringList();
}
KABC::Addressee::List ViewManager::selectedAddressees() const
{
KABC::Addressee::List list;
if ( mActiveView ) {
QStringList uids = mActiveView->selectedUids();
QStringList::Iterator it;
for ( it = uids.begin(); it != uids.end(); ++it ) {
KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
if ( !addr.isEmpty() )
list.append( addr );
}
}
return list;
}
//US added another method with no parameter, since my moc compiler does not support default parameters.
void ViewManager::setSelected()
{
setSelected( QString::null, true );
}
void ViewManager::setSelected( const QString &uid, bool selected )
{
if ( mActiveView )
mActiveView->setSelected( uid, selected );
}
void ViewManager::setListSelected(QStringList list)
{
int i, count = list.count();
for ( i = 0; i < count;++i )
setSelected( list[i], true );
}
void ViewManager::unloadViews()
{
mViewDict.clear();
mActiveView = 0;
}
+void ViewManager::selectView( const QString &name )
+{
+ setActiveView( name );
+ mCore->saveSettings();
+}
void ViewManager::setActiveView( const QString &name )
{
KAddressBookView *view = 0;
// Check that this isn't the same as the current active view
if ( mActiveView && ( mActiveView->caption() == name ) )
return;
// At this point we know the view that should be active is not
// currently active. We will try to find the new on in the list. If
// we can't find it, it means it hasn't been instantiated, so we will
// create it on demand.
view = mViewDict.find( name );
// Check if we found the view. If we didn't, then we need to create it
if ( view == 0 ) {
KConfig *config = mCore->config();
KConfigGroupSaver saver( config, name );
QString type = config->readEntry( "Type", "Table" );
kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
ViewFactory *factory = mViewFactoryDict.find( type );
if ( factory )
view = factory->view( mCore->addressBook(), mViewWidgetStack );
if ( view ) {
view->setCaption( name );
mViewDict.insert( name, view );
//US my version needs an int as second parameter to addWidget
mViewWidgetStack->addWidget( view, -1 );
view->readConfig( config );
// The manager just relays the signals
connect( view, SIGNAL( selected( const QString& ) ),
SIGNAL( selected( const QString & ) ) );
connect( view, SIGNAL( executed( const QString& ) ),
SIGNAL( executed( const QString& ) ) );
connect( view, SIGNAL( deleteRequest( ) ),
SIGNAL( deleteRequest( ) ) );
connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
connect( view, SIGNAL( dropped( QDropEvent* ) ),
SLOT( dropped( QDropEvent* ) ) );
connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
}
}
// If we found or created the view, raise it and refresh it
if ( view ) {
mActiveView = view;
mViewWidgetStack->raiseWidget( view );
// Set the proper filter in the view. By setting the combo
// box, the activated slot will be called, which will push
// the filter to the view and refresh it.
if ( view->defaultFilterType() == KAddressBookView::None ) {
mActionSelectFilter->setCurrentItem( 0 );
setActiveFilter( 0 );
} else if ( view->defaultFilterType() == KAddressBookView::Active ) {
setActiveFilter( mActionSelectFilter->currentItem() );
} else {
uint pos = filterPosition( view->defaultFilterName() );
mActionSelectFilter->setCurrentItem( pos );
setActiveFilter( pos );
}
//US qDebug("ViewManager::setActiveView 6" );
// Update the inc search widget to show the fields in the new active
// view.
mCore->setSearchFields( mActiveView->fields() );
//US performance optimization. setActiveFilter calls also mActiveView->refresh()
//US mActiveView->refresh();
- mCore->saveSettings();
}
else
{
qDebug("ViewManager::setActiveView: unable to find view" );
}
}
//US added another method with no parameter, since my moc compiler does not support default parameters.
void ViewManager::refreshView()
{
refreshView( QString::null );
}
void ViewManager::refreshView( const QString &uid )
{
if ( mActiveView )
mActiveView->refresh( uid );
}
void ViewManager::setFocusAV()
{
if ( mActiveView )
mActiveView->setFocusAV();
}
void ViewManager::editView()
{
if ( !mActiveView )
return;
ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() );
ViewConfigureWidget *wdg = 0;
ViewConfigureDialog* dlg = 0;
if ( factory ) {
// Save the filters so the dialog has the latest set
Filter::save( mCore->config(), "Filter", mFilterList );
dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" );
wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" );
} else {
qDebug("ViewManager::editView()::cannot find viewfactory ");
return;
}
if ( wdg ) {
dlg->setWidget( wdg );
#ifndef DESKTOP_VERSION
//dlg.setMaximumSize( 640, 480 );
//dlg->setGeometry( 40,40, 400, 300);
dlg->showMaximized();
@@ -444,97 +448,96 @@ void ViewManager::addView()
}
}
void ViewManager::createViewFactories()
{
#ifndef KAB_EMBEDDED
KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
KTrader::OfferList::ConstIterator it;
for ( it = plugins.begin(); it != plugins.end(); ++it ) {
if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
continue;
KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
if ( !factory ) {
kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
continue;
}
ViewFactory *viewFactory = static_cast<ViewFactory*>( factory );
if ( !viewFactory ) {
kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl;
continue;
}
mViewFactoryDict.insert( viewFactory->type(), viewFactory );
}
#else //KAB_EMBEDDED
ViewFactory* viewFactory = new IconViewFactory();
mViewFactoryDict.insert( viewFactory->type(), viewFactory );
// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
viewFactory = new TableViewFactory();
mViewFactoryDict.insert( viewFactory->type(), viewFactory );
// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
viewFactory = new CardViewFactory();
mViewFactoryDict.insert( viewFactory->type(), viewFactory );
// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
#endif //KAB_EMBEDDED
}
void ViewManager::dropped( QDropEvent *e )
{
- kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl;
#ifndef KAB_EMBEDDED
QString clipText, vcards;
KURL::List urls;
if ( KURLDrag::decode( e, urls) ) {
KURL::List::Iterator it = urls.begin();
int c = urls.count();
if ( c > 1 ) {
QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c );
if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) {
for ( ; it != urls.end(); ++it )
emit urlDropped( *it );
}
} else if ( c == 1 )
emit urlDropped( *it );
} else if ( KVCardDrag::decode( e, vcards ) ) {
KABC::Addressee addr;
KABC::VCardConverter converter;
QStringList list = QStringList::split( "\r\n\r\n", vcards );
QStringList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) {
KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() );
if ( a.isEmpty() ) {
mCore->addressBook()->insertAddressee( addr );
emit modified();
}
}
}
mActiveView->refresh();
}
#else //KAB_EMBEDDED
qDebug("ViewManager::dropped() has to be changed!!" );
#endif //KAB_EMBEDDED
}
void ViewManager::startDrag()
{
kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
#ifndef KAB_EMBEDDED
// Get the list of all the selected addressees
KABC::Addressee::List addrList;
@@ -610,97 +613,97 @@ void ViewManager::configureFilters()
QStringList ViewManager::filterNames() const
{
QStringList names( i18n( "No Filter" ) );
Filter::List::ConstIterator it;
for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
names.append( (*it).name() );
return names;
}
Filter ViewManager::getFilterByName( const QString &name ) const
{
Filter::List::ConstIterator it;
for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
if ( name == (*it).name() )
return (*it);
return Filter();
}
int ViewManager::filterPosition( const QString &name ) const
{
int pos = 0;
Filter::List::ConstIterator it;
for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos )
if ( name == (*it).name() )
return pos + 1;
return 0;
}
void ViewManager::initActions()
{
//US <ActionList name="view_loadedviews"/>
//US <Separator/>
#ifdef KAB_EMBEDDED
QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu();
QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu();
#endif //KAB_EMBEDDED
mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" );
#if KDE_VERSION >= 309
mActionSelectView->setMenuAccelsEnabled( false );
#endif
connect( mActionSelectView, SIGNAL( activated( const QString& ) ),
- SLOT( setActiveView( const QString& ) ) );
+ SLOT( selectView( const QString& ) ) );
#ifdef KAB_EMBEDDED
mActionSelectView->plug(viewmenu);
viewmenu->insertSeparator();
#endif //KAB_EMBEDDED
KAction *action;
action = new KAction( i18n( "Modify View..." ), "configure", 0, this,
SLOT( editView() ), mCore->actionCollection(), "view_modify" );
#ifndef KAB_EMBEDDED
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." ) );
#else //KAB_EMBEDDED
action->plug(viewmenu);
#endif //KAB_EMBEDDED
action = new KAction( i18n( "Add View..." ), "window_new", 0, this,
SLOT( addView() ), mCore->actionCollection(), "view_add" );
#ifndef KAB_EMBEDDED
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." ) );
#else //KAB_EMBEDDED
action->plug(viewmenu);
#endif //KAB_EMBEDDED
mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0,
this, SLOT( deleteView() ),
mCore->actionCollection(), "view_delete" );
#ifndef KAB_EMBEDDED
mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) );
#else //KAB_EMBEDDED
mActionDeleteView->plug(viewmenu);
viewmenu->insertSeparator();
#endif //KAB_EMBEDDED
#ifndef KAB_EMBEDDED
action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
SLOT( refreshView(const QString &) ), mCore->actionCollection(),
"view_refresh" );
action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) );
#else //KAB_EMBEDDED
action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
SLOT( refreshView()), mCore->actionCollection(),
"view_refresh" );
action->plug(viewmenu);
viewmenu->insertSeparator();
#endif //KAB_EMBEDDED