summaryrefslogtreecommitdiffabout
path: root/kaddressbook/extensionmanager.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kaddressbook/extensionmanager.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kaddressbook/extensionmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/extensionmanager.cpp246
1 files changed, 246 insertions, 0 deletions
diff --git a/kaddressbook/extensionmanager.cpp b/kaddressbook/extensionmanager.cpp
new file mode 100644
index 0000000..9114cdc
--- a/dev/null
+++ b/kaddressbook/extensionmanager.cpp
@@ -0,0 +1,246 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23#include <qlayout.h>
24#include <qapplication.h>
25#include <kactionclasses.h>
26#include <kconfig.h>
27#include <kdebug.h>
28#include <klocale.h>
29
30#ifndef KAB_EMBEDDED
31#include <ktrader.h>
32#else //KAB_EMBEDDED
33#include <features/mergewidget.h>
34#include <features/distributionlistwidget.h>
35#endif //KAB_EMBEDDED
36
37#include "addresseeeditorwidget.h"
38#include "kabcore.h"
39#include "kabprefs.h"
40
41#include "extensionmanager.h"
42
43ExtensionManager::ExtensionManager( KABCore *core, QWidget *parent,
44 const char *name )
45 : QScrollView( parent, name ), mCore( core ), mCurrentExtensionWidget( 0 )
46{
47#ifdef KAB_EMBEDDED
48//US QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
49 QWidget *settingsmenu = (QWidget*)mCore->getSettingsMenu();
50#endif //KAB_EMBEDDED
51
52 mActionExtensions = new KSelectAction( i18n( "Show Extension Bar" ), 0,
53 mCore->actionCollection(),
54 "options_show_extensions" );
55
56 mActionExtensions->plug( settingsmenu );
57
58 connect( mActionExtensions, SIGNAL( activated( int ) ),
59 SLOT( setActiveExtension( int ) ) );
60 mWidgetBox = new QWidget( viewport() );
61 addChild( mWidgetBox );
62 setResizePolicy(AutoOneFit);
63 createExtensionWidgets();
64 hide();
65}
66
67ExtensionManager::~ExtensionManager()
68{
69}
70
71void ExtensionManager::restoreSettings()
72{
73 mActionExtensions->setCurrentItem( KABPrefs::instance()->mCurrentExtension );
74 int i = 1;
75 mCurrentExtensionWidget = mExtensionWidgetList.at( i-1 );
76 while ( mCurrentExtensionWidget ) {
77 if( i != KABPrefs::instance()->mCurrentExtension )
78 mCurrentExtensionWidget->hide();
79 mCurrentExtensionWidget = mExtensionWidgetList.at( ++i-1 );
80
81 }
82 setActiveExtension( mActionExtensions->currentItem() );
83}
84
85void ExtensionManager::saveSettings()
86{
87 KABPrefs::instance()->mCurrentExtension = mActionExtensions->currentItem();
88}
89
90void ExtensionManager::reconfigure()
91{
92 saveSettings();
93 createExtensionWidgets();
94 restoreSettings();
95}
96
97bool ExtensionManager::isQuickEditVisible() const
98{
99 return ( mCurrentExtensionWidget &&
100 mCurrentExtensionWidget->identifier() == "contact_editor" );
101}
102
103void ExtensionManager::setSelectionChanged()
104{
105 if ( mCurrentExtensionWidget )
106 mCurrentExtensionWidget->contactsSelectionChanged();
107}
108
109void ExtensionManager::setActiveExtension( int id )
110{
111 //qDebug("+++++++++++++++++++ExtensionManager::setActiveExtension %d ", id);
112 if ( id == 0 ) {
113 hide();
114 mCurrentExtensionWidget = 0;
115#ifndef DESKTOP_VERSION
116//US our screen is so small, that we better hide the detailscreen, just in case.
117 mCore->setDetailsToState( );
118#endif //KAB_EMBEDDED
119 } else if ( id > 0 ) {
120 if ( mCurrentExtensionWidget )
121 mCurrentExtensionWidget->hide();
122
123 mCurrentExtensionWidget = mExtensionWidgetList.at( id - 1 );
124
125 if ( mCurrentExtensionWidget ) {
126#ifndef DESKTOP_VERSION
127//US our screen is so small, that we better hide the detailscreen, just in case.
128 mCore->setDetailsVisible( false );
129#endif //KAB_EMBEDDED
130 show();
131 mWidgetBox->show();
132 mCurrentExtensionWidget->show();
133 } else {
134 hide();
135 mCurrentExtensionWidget = 0;
136#ifndef DESKTOP_VERSION
137//US our screen is so small, that we better hide the detailscreen, just in case.
138 mCore->setDetailsToState( );
139#endif //KAB_EMBEDDED
140 }
141 }
142}
143
144void ExtensionManager::createExtensionWidgets()
145{
146 // clear extension widget list
147 mExtensionWidgetList.setAutoDelete( true );
148 QPtrListIterator<ExtensionWidget> wdgIt( mExtensionWidgetList );
149 ExtensionWidget *wdg = 0;
150 while ( ( wdg = wdgIt.current() ) != 0 )
151 mExtensionWidgetList.remove( wdg );
152
153 mExtensionWidgetList.setAutoDelete( false );
154
155 QStringList extensionNames( i18n( "None" ) );
156
157 // add addressee editor as default
158
159 QHBoxLayout *hbl = new QHBoxLayout (mWidgetBox );
160
161 wdg = new AddresseeEditorWidget( mCore, true, mWidgetBox );
162 hbl->addWidget( wdg );
163 //wdg->hide();
164 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
165 SIGNAL( modified( const KABC::Addressee::List& ) ) );
166 mExtensionWidgetList.append( wdg );
167 extensionNames.append( wdg->title() );
168
169 // load the other extensions
170 QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions;
171
172#ifndef KAB_EMBEDDED
173 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" );
174 KTrader::OfferList::ConstIterator it;
175 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
176 if ( !(*it)->hasServiceType( "KAddressBook/Extension" ) )
177 continue;
178
179 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
180 if ( !factory ) {
181 kdDebug(5720) << "ExtensionManager::loadExtensions(): Factory creation failed" << endl;
182 continue;
183 }
184
185 ExtensionFactory *extensionFactory = static_cast<ExtensionFactory*>( factory );
186
187 if ( !extensionFactory ) {
188 kdDebug(5720) << "ExtensionManager::loadExtensions(): Cast failed" << endl;
189 continue;
190 }
191
192 if ( !activeExtensions.contains( extensionFactory->identifier() ) )
193 continue;
194
195 wdg = extensionFactory->extension( mCore, this );
196 if ( wdg ) {
197 //wdg->hide();
198 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
199 SIGNAL( modified( const KABC::Addressee::List& ) ) );
200 mExtensionWidgetList.append( wdg );
201 extensionNames.append( wdg->title() );
202 }
203 }
204#else //KAB_EMBEDDED
205 //load Mergefactory/extension
206 ExtensionFactory *extensionFactory = new MergeFactory();
207 if ( activeExtensions.contains( extensionFactory->identifier() ) )
208 {
209 wdg = extensionFactory->extension( mCore, mWidgetBox );
210 if ( wdg ) {
211 hbl->addWidget( wdg );
212 //wdg->hide();
213 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
214 SIGNAL( modified( const KABC::Addressee::List& ) ) );
215 mExtensionWidgetList.append( wdg );
216 extensionNames.append( wdg->title() );
217 }
218 }
219
220 //load DistributionListfactory/extension
221 extensionFactory = new DistributionListFactory();
222 if (activeExtensions.contains( extensionFactory->identifier() ) )
223 {
224 wdg = extensionFactory->extension( mCore, mWidgetBox );
225 if ( wdg ) {
226 hbl->addWidget( wdg );
227 //wdg->hide();
228 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
229 SIGNAL( modified( const KABC::Addressee::List& ) ) );
230 mExtensionWidgetList.append( wdg );
231 extensionNames.append( wdg->title() );
232 }
233 }
234
235 hbl->addStretch();
236
237#endif //KAB_EMBEDDED
238
239
240 mActionExtensions->setItems( extensionNames );
241 mCurrentExtensionWidget = 0;
242}
243
244#ifndef KAB_EMBEDDED
245#include "extensionmanager.moc"
246#endif //KAB_EMBEDDED