Diffstat (limited to 'kaddressbook/extensionmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/extensionmanager.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/kaddressbook/extensionmanager.cpp b/kaddressbook/extensionmanager.cpp index efbdf17..46defa1 100644 --- a/kaddressbook/extensionmanager.cpp +++ b/kaddressbook/extensionmanager.cpp | |||
@@ -1,249 +1,249 @@ | |||
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 | #include <kactionclasses.h> | 25 | #include <kactionclasses.h> |
26 | #include <kconfig.h> | 26 | #include <kconfig.h> |
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <klocale.h> | 28 | #include <klocale.h> |
29 | 29 | ||
30 | #ifndef KAB_EMBEDDED | 30 | #ifndef KAB_EMBEDDED |
31 | #include <ktrader.h> | 31 | #include <ktrader.h> |
32 | #else //KAB_EMBEDDED | 32 | #else //KAB_EMBEDDED |
33 | #include <features/mergewidget.h> | 33 | #include <features/mergewidget.h> |
34 | #include <features/distributionlistwidget.h> | 34 | #include <features/distributionlistwidget.h> |
35 | #endif //KAB_EMBEDDED | 35 | #endif //KAB_EMBEDDED |
36 | 36 | ||
37 | #include "addresseeeditorwidget.h" | 37 | #include "addresseeeditorwidget.h" |
38 | #include "kabcore.h" | 38 | #include "kabcore.h" |
39 | #include "kabprefs.h" | 39 | #include "kabprefs.h" |
40 | 40 | ||
41 | #include "extensionmanager.h" | 41 | #include "extensionmanager.h" |
42 | 42 | ||
43 | ExtensionManager::ExtensionManager( KABCore *core, QWidget *parent, | 43 | ExtensionManager::ExtensionManager( KABCore *core, QWidget *parent, |
44 | const char *name ) | 44 | const char *name ) |
45 | : QScrollView( parent, name ), mCore( core ), mCurrentExtensionWidget( 0 ) | 45 | : QScrollView( parent, name ), mCore( core ), mCurrentExtensionWidget( 0 ) |
46 | { | 46 | { |
47 | #ifdef KAB_EMBEDDED | 47 | #ifdef KAB_EMBEDDED |
48 | //US QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); | 48 | //US QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); |
49 | QWidget *settingsmenu = (QWidget*)mCore->getSettingsMenu(); | 49 | QWidget *settingsmenu = (QWidget*)mCore->getViewMenu(); |
50 | #endif //KAB_EMBEDDED | 50 | #endif //KAB_EMBEDDED |
51 | 51 | ||
52 | mActionExtensions = new KSelectAction( i18n( "Show Extension Bar" ), 0, | 52 | mActionExtensions = new KSelectAction( i18n( "Show Extension Bar" ), 0, |
53 | mCore->actionCollection(), | 53 | mCore->actionCollection(), |
54 | "options_show_extensions" ); | 54 | "options_show_extensions" ); |
55 | 55 | ||
56 | mActionExtensions->plug( settingsmenu ); | 56 | mActionExtensions->plug( settingsmenu ,0); |
57 | 57 | ||
58 | connect( mActionExtensions, SIGNAL( activated( int ) ), | 58 | connect( mActionExtensions, SIGNAL( activated( int ) ), |
59 | SLOT( setActiveExtension( int ) ) ); | 59 | SLOT( setActiveExtension( int ) ) ); |
60 | mWidgetBox = new QWidget( viewport() ); | 60 | mWidgetBox = new QWidget( viewport() ); |
61 | new QHBoxLayout (mWidgetBox ); | 61 | new QHBoxLayout (mWidgetBox ); |
62 | addChild( mWidgetBox ); | 62 | addChild( mWidgetBox ); |
63 | setResizePolicy(AutoOneFit); | 63 | setResizePolicy(AutoOneFit); |
64 | createExtensionWidgets(); | 64 | createExtensionWidgets(); |
65 | hide(); | 65 | hide(); |
66 | } | 66 | } |
67 | 67 | ||
68 | ExtensionManager::~ExtensionManager() | 68 | ExtensionManager::~ExtensionManager() |
69 | { | 69 | { |
70 | } | 70 | } |
71 | 71 | ||
72 | void ExtensionManager::restoreSettings() | 72 | void ExtensionManager::restoreSettings() |
73 | { | 73 | { |
74 | mActionExtensions->setCurrentItem( KABPrefs::instance()->mCurrentExtension ); | 74 | mActionExtensions->setCurrentItem( KABPrefs::instance()->mCurrentExtension ); |
75 | int i = 1; | 75 | int i = 1; |
76 | mCurrentExtensionWidget = mExtensionWidgetList.at( i-1 ); | 76 | mCurrentExtensionWidget = mExtensionWidgetList.at( i-1 ); |
77 | while ( mCurrentExtensionWidget ) { | 77 | while ( mCurrentExtensionWidget ) { |
78 | if( i != KABPrefs::instance()->mCurrentExtension ) | 78 | if( i != KABPrefs::instance()->mCurrentExtension ) |
79 | mCurrentExtensionWidget->hide(); | 79 | mCurrentExtensionWidget->hide(); |
80 | mCurrentExtensionWidget = mExtensionWidgetList.at( ++i-1 ); | 80 | mCurrentExtensionWidget = mExtensionWidgetList.at( ++i-1 ); |
81 | 81 | ||
82 | } | 82 | } |
83 | setActiveExtension( mActionExtensions->currentItem() ); | 83 | setActiveExtension( mActionExtensions->currentItem() ); |
84 | } | 84 | } |
85 | 85 | ||
86 | void ExtensionManager::saveSettings() | 86 | void ExtensionManager::saveSettings() |
87 | { | 87 | { |
88 | KABPrefs::instance()->mCurrentExtension = mActionExtensions->currentItem(); | 88 | KABPrefs::instance()->mCurrentExtension = mActionExtensions->currentItem(); |
89 | } | 89 | } |
90 | 90 | ||
91 | void ExtensionManager::reconfigure() | 91 | void ExtensionManager::reconfigure() |
92 | { | 92 | { |
93 | saveSettings(); | 93 | saveSettings(); |
94 | createExtensionWidgets(); | 94 | createExtensionWidgets(); |
95 | restoreSettings(); | 95 | restoreSettings(); |
96 | } | 96 | } |
97 | 97 | ||
98 | bool ExtensionManager::isQuickEditVisible() const | 98 | bool ExtensionManager::isQuickEditVisible() const |
99 | { | 99 | { |
100 | return ( mCurrentExtensionWidget && | 100 | return ( mCurrentExtensionWidget && |
101 | mCurrentExtensionWidget->identifier() == "contact_editor" ); | 101 | mCurrentExtensionWidget->identifier() == "contact_editor" ); |
102 | } | 102 | } |
103 | 103 | ||
104 | void ExtensionManager::setSelectionChanged() | 104 | void ExtensionManager::setSelectionChanged() |
105 | { | 105 | { |
106 | if ( mCurrentExtensionWidget ) | 106 | if ( mCurrentExtensionWidget ) |
107 | mCurrentExtensionWidget->contactsSelectionChanged(); | 107 | mCurrentExtensionWidget->contactsSelectionChanged(); |
108 | } | 108 | } |
109 | 109 | ||
110 | void ExtensionManager::setActiveExtension( int id ) | 110 | void ExtensionManager::setActiveExtension( int id ) |
111 | { | 111 | { |
112 | //qDebug("+++++++++++++++++++ExtensionManager::setActiveExtension %d ", id); | 112 | //qDebug("+++++++++++++++++++ExtensionManager::setActiveExtension %d ", id); |
113 | if ( id == 0 ) { | 113 | if ( id == 0 ) { |
114 | hide(); | 114 | hide(); |
115 | mCurrentExtensionWidget = 0; | 115 | mCurrentExtensionWidget = 0; |
116 | #ifndef DESKTOP_VERSION | 116 | #ifndef DESKTOP_VERSION |
117 | //US our screen is so small, that we better hide the detailscreen, just in case. | 117 | //US our screen is so small, that we better hide the detailscreen, just in case. |
118 | //US mCore->setDetailsToState( ); | 118 | //US mCore->setDetailsToState( ); |
119 | #endif //KAB_EMBEDDED | 119 | #endif //KAB_EMBEDDED |
120 | } else if ( id > 0 ) { | 120 | } else if ( id > 0 ) { |
121 | if ( mCurrentExtensionWidget ) | 121 | if ( mCurrentExtensionWidget ) |
122 | mCurrentExtensionWidget->hide(); | 122 | mCurrentExtensionWidget->hide(); |
123 | 123 | ||
124 | mCurrentExtensionWidget = mExtensionWidgetList.at( id - 1 ); | 124 | mCurrentExtensionWidget = mExtensionWidgetList.at( id - 1 ); |
125 | 125 | ||
126 | if ( mCurrentExtensionWidget ) { | 126 | if ( mCurrentExtensionWidget ) { |
127 | #ifndef DESKTOP_VERSION | 127 | #ifndef DESKTOP_VERSION |
128 | //US our screen is so small, that we better hide the detailscreen, just in case. | 128 | //US our screen is so small, that we better hide the detailscreen, just in case. |
129 | //US mCore->setDetailsVisible( false ); | 129 | //US mCore->setDetailsVisible( false ); |
130 | #endif //KAB_EMBEDDED | 130 | #endif //KAB_EMBEDDED |
131 | show(); | 131 | show(); |
132 | mWidgetBox->show(); | 132 | mWidgetBox->show(); |
133 | mCurrentExtensionWidget->show(); | 133 | mCurrentExtensionWidget->show(); |
134 | } else { | 134 | } else { |
135 | hide(); | 135 | hide(); |
136 | mCurrentExtensionWidget = 0; | 136 | mCurrentExtensionWidget = 0; |
137 | #ifndef DESKTOP_VERSION | 137 | #ifndef DESKTOP_VERSION |
138 | //US our screen is so small, that we better hide the detailscreen, just in case. | 138 | //US our screen is so small, that we better hide the detailscreen, just in case. |
139 | //US mCore->setDetailsToState( ); | 139 | //US mCore->setDetailsToState( ); |
140 | #endif //KAB_EMBEDDED | 140 | #endif //KAB_EMBEDDED |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | emit changedActiveExtension( id ); | 144 | emit changedActiveExtension( id ); |
145 | } | 145 | } |
146 | 146 | ||
147 | void ExtensionManager::createExtensionWidgets() | 147 | void ExtensionManager::createExtensionWidgets() |
148 | { | 148 | { |
149 | // clear extension widget list | 149 | // clear extension widget list |
150 | mExtensionWidgetList.setAutoDelete( true ); | 150 | mExtensionWidgetList.setAutoDelete( true ); |
151 | QPtrListIterator<ExtensionWidget> wdgIt( mExtensionWidgetList ); | 151 | QPtrListIterator<ExtensionWidget> wdgIt( mExtensionWidgetList ); |
152 | ExtensionWidget *wdg = 0; | 152 | ExtensionWidget *wdg = 0; |
153 | while ( ( wdg = wdgIt.current() ) != 0 ) | 153 | while ( ( wdg = wdgIt.current() ) != 0 ) |
154 | mExtensionWidgetList.remove( wdg ); | 154 | mExtensionWidgetList.remove( wdg ); |
155 | 155 | ||
156 | mExtensionWidgetList.setAutoDelete( false ); | 156 | mExtensionWidgetList.setAutoDelete( false ); |
157 | 157 | ||
158 | QStringList extensionNames( i18n( "None" ) ); | 158 | QStringList extensionNames( i18n( "None" ) ); |
159 | 159 | ||
160 | // add addressee editor as default | 160 | // add addressee editor as default |
161 | 161 | ||
162 | QHBoxLayout *hbl = (QHBoxLayout *) mWidgetBox->layout();; | 162 | QHBoxLayout *hbl = (QHBoxLayout *) mWidgetBox->layout();; |
163 | 163 | ||
164 | wdg = new AddresseeEditorWidget( mCore, true, mWidgetBox ); | 164 | wdg = new AddresseeEditorWidget( mCore, true, mWidgetBox ); |
165 | hbl->addWidget( wdg ); | 165 | hbl->addWidget( wdg ); |
166 | //wdg->hide(); | 166 | //wdg->hide(); |
167 | connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), | 167 | connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), |
168 | SIGNAL( modified( const KABC::Addressee::List& ) ) ); | 168 | SIGNAL( modified( const KABC::Addressee::List& ) ) ); |
169 | mExtensionWidgetList.append( wdg ); | 169 | mExtensionWidgetList.append( wdg ); |
170 | extensionNames.append( wdg->title() ); | 170 | extensionNames.append( wdg->title() ); |
171 | 171 | ||
172 | // load the other extensions | 172 | // load the other extensions |
173 | QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions; | 173 | QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions; |
174 | 174 | ||
175 | #ifndef KAB_EMBEDDED | 175 | #ifndef KAB_EMBEDDED |
176 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" ); | 176 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" ); |
177 | KTrader::OfferList::ConstIterator it; | 177 | KTrader::OfferList::ConstIterator it; |
178 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 178 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
179 | if ( !(*it)->hasServiceType( "KAddressBook/Extension" ) ) | 179 | if ( !(*it)->hasServiceType( "KAddressBook/Extension" ) ) |
180 | continue; | 180 | continue; |
181 | 181 | ||
182 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); | 182 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); |
183 | if ( !factory ) { | 183 | if ( !factory ) { |
184 | //kdDebug(5720) << "ExtensionManager::loadExtensions(): Factory creation failed" << endl; | 184 | //kdDebug(5720) << "ExtensionManager::loadExtensions(): Factory creation failed" << endl; |
185 | continue; | 185 | continue; |
186 | } | 186 | } |
187 | 187 | ||
188 | ExtensionFactory *extensionFactory = static_cast<ExtensionFactory*>( factory ); | 188 | ExtensionFactory *extensionFactory = static_cast<ExtensionFactory*>( factory ); |
189 | 189 | ||
190 | if ( !extensionFactory ) { | 190 | if ( !extensionFactory ) { |
191 | //kdDebug(5720) << "ExtensionManager::loadExtensions(): Cast failed" << endl; | 191 | //kdDebug(5720) << "ExtensionManager::loadExtensions(): Cast failed" << endl; |
192 | continue; | 192 | continue; |
193 | } | 193 | } |
194 | 194 | ||
195 | if ( !activeExtensions.contains( extensionFactory->identifier() ) ) | 195 | if ( !activeExtensions.contains( extensionFactory->identifier() ) ) |
196 | continue; | 196 | continue; |
197 | 197 | ||
198 | wdg = extensionFactory->extension( mCore, this ); | 198 | wdg = extensionFactory->extension( mCore, this ); |
199 | if ( wdg ) { | 199 | if ( wdg ) { |
200 | //wdg->hide(); | 200 | //wdg->hide(); |
201 | connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), | 201 | connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), |
202 | SIGNAL( modified( const KABC::Addressee::List& ) ) ); | 202 | SIGNAL( modified( const KABC::Addressee::List& ) ) ); |
203 | mExtensionWidgetList.append( wdg ); | 203 | mExtensionWidgetList.append( wdg ); |
204 | extensionNames.append( wdg->title() ); | 204 | extensionNames.append( wdg->title() ); |
205 | } | 205 | } |
206 | } | 206 | } |
207 | #else //KAB_EMBEDDED | 207 | #else //KAB_EMBEDDED |
208 | //load Mergefactory/extension | 208 | //load Mergefactory/extension |
209 | ExtensionFactory *extensionFactory = new MergeFactory(); | 209 | ExtensionFactory *extensionFactory = new MergeFactory(); |
210 | if ( activeExtensions.contains( extensionFactory->identifier() ) ) | 210 | if ( activeExtensions.contains( extensionFactory->identifier() ) ) |
211 | { | 211 | { |
212 | wdg = extensionFactory->extension( mCore, mWidgetBox ); | 212 | wdg = extensionFactory->extension( mCore, mWidgetBox ); |
213 | if ( wdg ) { | 213 | if ( wdg ) { |
214 | hbl->addWidget( wdg ); | 214 | hbl->addWidget( wdg ); |
215 | //wdg->hide(); | 215 | //wdg->hide(); |
216 | connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), | 216 | connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), |
217 | SIGNAL( modified( const KABC::Addressee::List& ) ) ); | 217 | SIGNAL( modified( const KABC::Addressee::List& ) ) ); |
218 | mExtensionWidgetList.append( wdg ); | 218 | mExtensionWidgetList.append( wdg ); |
219 | extensionNames.append( wdg->title() ); | 219 | extensionNames.append( wdg->title() ); |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | //load DistributionListfactory/extension | 223 | //load DistributionListfactory/extension |
224 | extensionFactory = new DistributionListFactory(); | 224 | extensionFactory = new DistributionListFactory(); |
225 | if (activeExtensions.contains( extensionFactory->identifier() ) ) | 225 | if (activeExtensions.contains( extensionFactory->identifier() ) ) |
226 | { | 226 | { |
227 | wdg = extensionFactory->extension( mCore, mWidgetBox ); | 227 | wdg = extensionFactory->extension( mCore, mWidgetBox ); |
228 | if ( wdg ) { | 228 | if ( wdg ) { |
229 | hbl->addWidget( wdg ); | 229 | hbl->addWidget( wdg ); |
230 | //wdg->hide(); | 230 | //wdg->hide(); |
231 | connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), | 231 | connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ), |
232 | SIGNAL( modified( const KABC::Addressee::List& ) ) ); | 232 | SIGNAL( modified( const KABC::Addressee::List& ) ) ); |
233 | mExtensionWidgetList.append( wdg ); | 233 | mExtensionWidgetList.append( wdg ); |
234 | extensionNames.append( wdg->title() ); | 234 | extensionNames.append( wdg->title() ); |
235 | } | 235 | } |
236 | } | 236 | } |
237 | 237 | ||
238 | hbl->addStretch(); | 238 | hbl->addStretch(); |
239 | 239 | ||
240 | #endif //KAB_EMBEDDED | 240 | #endif //KAB_EMBEDDED |
241 | 241 | ||
242 | 242 | ||
243 | mActionExtensions->setItems( extensionNames ); | 243 | mActionExtensions->setItems( extensionNames ); |
244 | mCurrentExtensionWidget = 0; | 244 | mCurrentExtensionWidget = 0; |
245 | } | 245 | } |
246 | 246 | ||
247 | #ifndef KAB_EMBEDDED | 247 | #ifndef KAB_EMBEDDED |
248 | #include "extensionmanager.moc" | 248 | #include "extensionmanager.moc" |
249 | #endif //KAB_EMBEDDED | 249 | #endif //KAB_EMBEDDED |