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 "simpleaddresseeeditor.h"
00032
#include "core.h"
00033
#include "kabprefs.h"
00034
00035
#include "extensionmanager.h"
00036
00037 ExtensionManager::ExtensionManager( KAB::Core *core,
QWidget *parent,
00038
const char *name )
00039 :
QHBox( parent, name ), mCore( core ), mCurrentExtensionWidget( 0 )
00040 {
00041 mActionExtensions =
new KSelectAction( i18n(
"Show Extension Bar" ), 0,
00042 mCore->actionCollection(),
00043
"options_show_extensions" );
00044
00045 connect( mActionExtensions, SIGNAL( activated(
int ) ),
00046 SLOT( setActiveExtension(
int ) ) );
00047
00048 createExtensionWidgets();
00049 }
00050
00051 ExtensionManager::~ExtensionManager()
00052 {
00053 }
00054
00055
void ExtensionManager::restoreSettings()
00056 {
00057
int index = 0;
00058
for (
int index = 0; index < mExtensionList.size(); ++index ) {
00059 ExtensionData data = mExtensionList[ index ];
00060
if ( data.identifier == KABPrefs::instance()->mCurrentExtension ) {
00061 mActionExtensions->setCurrentItem( index );
00062 setActiveExtension( index );
00063
return;
00064 }
00065 }
00066
00067 mActionExtensions->setCurrentItem( 0 );
00068 setActiveExtension( 0 );
00069 }
00070
00071
void ExtensionManager::saveSettings()
00072 {
00073
int index = mActionExtensions->currentItem();
00074
00075 Q_ASSERT( index < mExtensionList.size() );
00076
00077 KABPrefs::instance()->mCurrentExtension = mExtensionList[ index ].identifier;
00078 }
00079
00080
void ExtensionManager::reconfigure()
00081 {
00082 saveSettings();
00083 createExtensionWidgets();
00084 restoreSettings();
00085 }
00086
00087
bool ExtensionManager::isQuickEditVisible()
const
00088
{
00089
return ( mCurrentExtensionWidget &&
00090 mCurrentExtensionWidget->identifier() ==
"contact_editor" );
00091 }
00092
00093
void ExtensionManager::setSelectionChanged()
00094 {
00095
if ( mCurrentExtensionWidget )
00096 mCurrentExtensionWidget->contactsSelectionChanged();
00097 }
00098
00099
void ExtensionManager::setActiveExtension(
int id )
00100 {
00101
if (
id == 0 ) {
00102 hide();
00103
if ( mCurrentExtensionWidget )
00104 mCurrentExtensionWidget->hide();
00105 mCurrentExtensionWidget = 0;
00106 }
else if (
id > 0 ) {
00107
if ( mCurrentExtensionWidget )
00108 mCurrentExtensionWidget->hide();
00109
00110 mCurrentExtensionWidget = mExtensionList[
id ].widget;
00111
if ( mCurrentExtensionWidget ) {
00112 show();
00113 mCurrentExtensionWidget->show();
00114 mCurrentExtensionWidget->contactsSelectionChanged();
00115 }
else {
00116 hide();
00117 mCurrentExtensionWidget = 0;
00118 }
00119 }
00120 }
00121
00122
void ExtensionManager::createExtensionWidgets()
00123 {
00124
00125 ExtensionData::List::Iterator dataIt;
00126
for ( dataIt = mExtensionList.begin(); dataIt != mExtensionList.end(); ++dataIt )
00127
delete (*dataIt).widget;
00128 mExtensionList.clear();
00129
00130 KAB::ExtensionWidget *wdg = 0;
00131
00132 {
00133
00134 ExtensionData data;
00135 data.identifier =
"none";
00136 data.title = i18n(
"None" );
00137 data.widget = 0;
00138 mExtensionList.append( data );
00139 }
00140
00141 {
00142
00143
if ( KABPrefs::instance()->mEditorType == KABPrefs::SimpleEditor ) {
00144 wdg =
new SimpleAddresseeEditor( mCore,
true,
this );
00145 }
else {
00146 wdg =
new AddresseeEditorWidget( mCore,
true,
this );
00147 }
00148 wdg->hide();
00149
00150 connect( wdg, SIGNAL( modified(
const KABC::Addressee::List& ) ),
00151 SIGNAL( modified(
const KABC::Addressee::List& ) ) );
00152
00153 ExtensionData data;
00154 data.identifier = wdg->identifier();
00155 data.title = wdg->title();
00156 data.widget = wdg;
00157 mExtensionList.append( data );
00158 }
00159
00160
00161 KTrader::OfferList plugins = KTrader::self()->query(
"KAddressBook/Extension" );
00162 KTrader::OfferList::ConstIterator it;
00163
00164
for ( it = plugins.begin(); it != plugins.end(); ++it ) {
00165 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
00166
if ( !factory ) {
00167 kdDebug(5720) <<
"ExtensionManager::loadExtensions(): Factory creation failed" << endl;
00168
continue;
00169 }
00170
00171 KAB::ExtensionFactory *extensionFactory = static_cast<KAB::ExtensionFactory*>( factory );
00172
00173
if ( !extensionFactory ) {
00174 kdDebug(5720) <<
"ExtensionManager::loadExtensions(): Cast failed" << endl;
00175
continue;
00176 }
00177
00178 wdg = extensionFactory->extension( mCore,
this );
00179
if ( wdg ) {
00180 wdg->hide();
00181 connect( wdg, SIGNAL( modified(
const KABC::Addressee::List& ) ),
00182 SIGNAL( modified(
const KABC::Addressee::List& ) ) );
00183
00184 ExtensionData data;
00185 data.identifier = wdg->identifier();
00186 data.title = wdg->title();
00187 data.widget = wdg;
00188 mExtensionList.append( data );
00189 }
00190 }
00191
00192
QStringList extensionTitles;
00193
for ( dataIt = mExtensionList.begin(); dataIt != mExtensionList.end(); ++dataIt )
00194 extensionTitles.append( (*dataIt).title );
00195
00196 mActionExtensions->setItems( extensionTitles );
00197 mCurrentExtensionWidget = 0;
00198 }
00199
00200
#include "extensionmanager.moc"