24 #include <tdeactionclasses.h>
25 #include <tdeconfig.h>
27 #include <tdelocale.h>
31 #include <tqobjectlist.h>
32 #include <tqsignalmapper.h>
33 #include <tqsplitter.h>
35 #include <tqwidgetstack.h>
37 #include "addresseeeditorextension.h"
41 #include "extensionmanager.h"
43 ExtensionData::ExtensionData() : action( 0 ), widget( 0 ), weight( 0 ), isDetailsExtension( false )
47 ExtensionManager::ExtensionManager( TQWidget* extensionBar, TQWidgetStack* detailsStack, KAB::Core *core, TQObject *parent,
49 : TQObject( parent, name ), mExtensionBar( extensionBar ), mCore( core ),
50 mMapper( 0 ), mDetailsStack( detailsStack ), mActiveDetailsWidget( 0 )
52 Q_ASSERT( mExtensionBar );
53 TQVBoxLayout* layout =
new TQVBoxLayout( mExtensionBar );
54 mSplitter =
new TQSplitter( mExtensionBar );
55 mSplitter->setOrientation( TQt::Vertical );
56 layout->addWidget( mSplitter );
58 createExtensionWidgets();
60 mActionCollection =
new TDEActionCollection(
this,
"ActionCollection" );
62 extensionBar->setShown(
false );
63 TQTimer::singleShot( 0,
this, TQ_SLOT( createActions() ) );
66 ExtensionManager::~ExtensionManager()
71 void ExtensionManager::restoreSettings()
73 const TQStringList activeExtensions = KABPrefs::instance()->activeExtensions();
75 typedef TQMap<TQString, ExtensionData>::ConstIterator ConstIterator;
76 for ( ConstIterator it = mExtensionMap.begin(), end = mExtensionMap.end(); it != end; ++it ) {
77 if ( activeExtensions.contains( it.data().identifier ) ) {
78 TDEToggleAction *action =
static_cast<TDEToggleAction*
>( it.data().action );
80 action->setChecked(
true );
81 setExtensionActive( it.data().identifier,
true );
84 const TQValueList<int> sizes = KABPrefs::instance()->extensionsSplitterSizes();
85 mSplitter->setSizes( sizes );
88 void ExtensionManager::saveSettings()
90 KABPrefs::instance()->setActiveExtensions( mActiveExtensions );
91 KABPrefs::instance()->setExtensionsSplitterSizes( mSplitter->sizes() );
94 void ExtensionManager::reconfigure()
97 createExtensionWidgets();
100 mExtensionBar->setShown( !mActiveExtensions.isEmpty() );
103 bool ExtensionManager::isQuickEditVisible()
const
105 return mActiveExtensions.contains(
"contact_editor" );
108 void ExtensionManager::setSelectionChanged()
110 for ( TQStringList::ConstIterator it = mActiveExtensions.begin(), end = mActiveExtensions.end(); it != end; ++it ) {
111 if ( mExtensionMap.contains( *it ) && mExtensionMap[*it].widget )
112 mExtensionMap[*it].widget->contactsSelectionChanged();
116 void ExtensionManager::activationToggled(
const TQString &extid )
118 if ( !mExtensionMap.contains( extid ) )
120 const ExtensionData data = mExtensionMap[ extid ];
121 const bool activated = data.action->isChecked();
122 setExtensionActive( extid, activated );
125 void ExtensionManager::setExtensionActive(
const TQString& extid,
bool active )
127 if ( !mExtensionMap.contains( extid ) )
129 if ( mActiveExtensions.contains( extid ) == active )
131 const ExtensionData data = mExtensionMap[ extid ];
133 mActiveExtensions.append( extid );
135 if ( data.isDetailsExtension ) {
136 mActiveDetailsWidget = data.widget;
137 emit detailsWidgetActivated( data.widget );
141 data.widget->contactsSelectionChanged();
144 mActiveExtensions.remove( extid );
145 if ( data.widget && !data.isDetailsExtension ) {
148 if ( data.isDetailsExtension ) {
149 mActiveDetailsWidget = 0;
150 emit detailsWidgetDeactivated( data.widget );
153 mExtensionBar->setShown( !mActiveExtensions.isEmpty() );
156 void ExtensionManager::createActions()
158 mCore->guiClient()->unplugActionList(
"extensions_list" );
159 mActionList.setAutoDelete(
true );
161 mActionList.setAutoDelete(
false );
164 mMapper =
new TQSignalMapper(
this,
"SignalMapper" );
165 connect( mMapper, TQ_SIGNAL( mapped(
const TQString& ) ),
166 this, TQ_SLOT( activationToggled(
const TQString& ) ) );
168 ExtensionData::List::ConstIterator it;
169 for ( TQMap<TQString, ExtensionData>::Iterator it = mExtensionMap.begin(), end = mExtensionMap.end(); it != end; ++it ) {
170 ExtensionData& data = it.data();
171 data.action =
new TDEToggleAction( data.title, 0, mMapper, TQ_SLOT( map() ),
173 TQString( data.identifier +
"_extension" ).latin1() );
174 mMapper->setMapping( data.action, data.identifier );
175 mActionList.append( data.action );
177 if ( mActiveExtensions.contains( data.identifier ) )
178 data.action->setChecked(
true );
181 mActionList.append(
new TDEActionSeparator( mActionCollection ) );
182 mCore->guiClient()->plugActionList(
"extensions_list", mActionList );
185 TQWidget* ExtensionManager::activeDetailsWidget()
const
187 return mActiveDetailsWidget;
190 void ExtensionManager::createExtensionWidgets()
193 for ( TQMap<TQString, ExtensionData>::ConstIterator it = mExtensionMap.begin(), end = mExtensionMap.end(); it != end; ++it ) {
194 delete it.data().widget;
196 mExtensionMap.clear();
198 KAB::ExtensionWidget *wdg = 0;
202 wdg =
new AddresseeEditorExtension( mCore, mDetailsStack );
205 connect( wdg, TQ_SIGNAL( modified(
const TDEABC::Addressee::List& ) ),
206 TQ_SIGNAL( modified(
const TDEABC::Addressee::List& ) ) );
207 connect( wdg, TQ_SIGNAL( deleted(
const TQStringList& ) ),
208 TQ_SIGNAL( deleted(
const TQStringList& ) ) );
211 data.identifier = wdg->identifier();
212 data.title = wdg->title();
214 data.isDetailsExtension =
true;
215 mExtensionMap.insert( data.identifier, data );
219 const TDETrader::OfferList plugins = TDETrader::self()->query(
"KAddressBook/Extension",
220 TQString(
"[X-TDE-KAddressBook-ExtensionPluginVersion] == %1" ).arg( KAB_EXTENSIONWIDGET_PLUGIN_VERSION ) );
222 TDETrader::OfferList::ConstIterator it;
223 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
224 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
226 kdDebug(5720) <<
"ExtensionManager::loadExtensions(): Factory creation failed" << endl;
230 KAB::ExtensionFactory *extensionFactory =
static_cast<KAB::ExtensionFactory*
>( factory );
232 if ( !extensionFactory ) {
233 kdDebug(5720) <<
"ExtensionManager::loadExtensions(): Cast failed" << endl;
237 wdg = extensionFactory->extension( mCore, mSplitter );
239 if ( wdg->identifier() ==
"distribution_list_editor_ng" )
240 mSplitter->moveToFirst( wdg );
242 connect( wdg, TQ_SIGNAL( modified(
const TDEABC::Addressee::List& ) ),
243 TQ_SIGNAL( modified(
const TDEABC::Addressee::List& ) ) );
244 connect( wdg, TQ_SIGNAL( deleted(
const TQStringList& ) ),
245 TQ_SIGNAL( deleted(
const TQStringList& ) ) );
248 data.identifier = wdg->identifier();
249 data.title = wdg->title();
251 mExtensionMap.insert( data.identifier, data );
256 #include "extensionmanager.moc"