extensionmanager.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
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
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"
This file is part of the documentation for kaddressbook Library Version 3.2.2.