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