kaddressbook Library API Documentation

extensionmanager.cpp

00001 /* 00002 This file is part of KAddressbook. 00003 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 00022 */ 00023 00024 #include <kactionclasses.h> 00025 #include <kconfig.h> 00026 #include <kdebug.h> 00027 #include <klocale.h> 00028 #include <ktrader.h> 00029 00030 #include "addresseeeditorwidget.h" 00031 #include "core.h" 00032 #include "kabprefs.h" 00033 00034 #include "extensionmanager.h" 00035 00036 ExtensionManager::ExtensionManager( KAB::Core *core, QWidget *parent, 00037 const char *name ) 00038 : QHBox( parent, name ), mCore( core ), mCurrentExtensionWidget( 0 ) 00039 { 00040 mActionExtensions = new KSelectAction( i18n( "Show Extension Bar" ), 0, 00041 mCore->actionCollection(), 00042 "options_show_extensions" ); 00043 00044 connect( mActionExtensions, SIGNAL( activated( int ) ), 00045 SLOT( setActiveExtension( int ) ) ); 00046 00047 createExtensionWidgets(); 00048 } 00049 00050 ExtensionManager::~ExtensionManager() 00051 { 00052 } 00053 00054 void ExtensionManager::restoreSettings() 00055 { 00056 mActionExtensions->setCurrentItem( KABPrefs::instance()->mCurrentExtension ); 00057 setActiveExtension( mActionExtensions->currentItem() ); 00058 } 00059 00060 void ExtensionManager::saveSettings() 00061 { 00062 KABPrefs::instance()->mCurrentExtension = mActionExtensions->currentItem(); 00063 } 00064 00065 void ExtensionManager::reconfigure() 00066 { 00067 saveSettings(); 00068 createExtensionWidgets(); 00069 restoreSettings(); 00070 } 00071 00072 bool ExtensionManager::isQuickEditVisible() const 00073 { 00074 return ( mCurrentExtensionWidget && 00075 mCurrentExtensionWidget->identifier() == "contact_editor" ); 00076 } 00077 00078 void ExtensionManager::setSelectionChanged() 00079 { 00080 if ( mCurrentExtensionWidget ) 00081 mCurrentExtensionWidget->contactsSelectionChanged(); 00082 } 00083 00084 void ExtensionManager::setActiveExtension( int id ) 00085 { 00086 if ( id == 0 ) { 00087 hide(); 00088 if ( mCurrentExtensionWidget ) 00089 mCurrentExtensionWidget->hide(); 00090 mCurrentExtensionWidget = 0; 00091 } else if ( id > 0 ) { 00092 if ( mCurrentExtensionWidget ) 00093 mCurrentExtensionWidget->hide(); 00094 00095 mCurrentExtensionWidget = mExtensionWidgetList.at( id - 1 ); 00096 if ( mCurrentExtensionWidget ) { 00097 show(); 00098 mCurrentExtensionWidget->show(); 00099 mCurrentExtensionWidget->contactsSelectionChanged(); 00100 } else { 00101 hide(); 00102 mCurrentExtensionWidget = 0; 00103 } 00104 } 00105 } 00106 00107 void ExtensionManager::createExtensionWidgets() 00108 { 00109 // clear extension widget list 00110 mExtensionWidgetList.setAutoDelete( true ); 00111 QPtrListIterator<KAB::ExtensionWidget> wdgIt( mExtensionWidgetList ); 00112 KAB::ExtensionWidget *wdg = 0; 00113 while ( ( wdg = wdgIt.current() ) != 0 ) 00114 mExtensionWidgetList.remove( wdg ); 00115 00116 mExtensionWidgetList.setAutoDelete( false ); 00117 00118 QStringList extensionNames( i18n( "None" ) ); 00119 00120 // add addressee editor as default 00121 wdg = new AddresseeEditorWidget( mCore, true, this ); 00122 wdg->hide(); 00123 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), 00124 SIGNAL( modified( const KABC::Addressee::List& ) ) ); 00125 mExtensionWidgetList.append( wdg ); 00126 extensionNames.append( wdg->title() ); 00127 00128 // load the other extensions 00129 QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions; 00130 00131 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" ); 00132 KTrader::OfferList::ConstIterator it; 00133 00134 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 00135 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 00136 if ( !factory ) { 00137 kdDebug(5720) << "ExtensionManager::loadExtensions(): Factory creation failed" << endl; 00138 continue; 00139 } 00140 00141 KAB::ExtensionFactory *extensionFactory = static_cast<KAB::ExtensionFactory*>( factory ); 00142 00143 if ( !extensionFactory ) { 00144 kdDebug(5720) << "ExtensionManager::loadExtensions(): Cast failed" << endl; 00145 continue; 00146 } 00147 00148 if ( !activeExtensions.contains( extensionFactory->identifier() ) ) 00149 continue; 00150 00151 wdg = extensionFactory->extension( mCore, this ); 00152 if ( wdg ) { 00153 wdg->hide(); 00154 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), 00155 SIGNAL( modified( const KABC::Addressee::List& ) ) ); 00156 mExtensionWidgetList.append( wdg ); 00157 extensionNames.append( wdg->title() ); 00158 } 00159 } 00160 00161 mActionExtensions->setItems( extensionNames ); 00162 mCurrentExtensionWidget = 0; 00163 } 00164 00165 #include "extensionmanager.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:08 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003