author | harlekin <harlekin> | 2004-06-03 20:36:44 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-06-03 20:36:44 (UTC) |
commit | 52f849d3031f9d2fad2272ad069e7a1456c0ee54 (patch) (unidiff) | |
tree | 7d03d229363b81c40d180ee99d168e99c4f6c06e /core/pim/today/today.cpp | |
parent | 74109985fd9ebdffd6cf0416207a69b17b563fd6 (diff) | |
download | opie-52f849d3031f9d2fad2272ad069e7a1456c0ee54.zip opie-52f849d3031f9d2fad2272ad069e7a1456c0ee54.tar.gz opie-52f849d3031f9d2fad2272ad069e7a1456c0ee54.tar.bz2 |
updated today to use the new opluginloader, migration not finished yet but mostly working
-rw-r--r-- | core/pim/today/today.cpp | 372 |
1 files changed, 124 insertions, 248 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index 0a6269e..a8c8651 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp | |||
@@ -11,80 +11,82 @@ | |||
11 | * it under the terms of the GNU General Public License as published by * | 11 | * it under the terms of the GNU General Public License as published by * |
12 | * the Free Software Foundation; either version 2 of the License, or * | 12 | * the Free Software Foundation; either version 2 of the License, or * |
13 | * (at your option) any later version. * | 13 | * (at your option) any later version. * |
14 | * * | 14 | * * |
15 | ***************************************************************************/ | 15 | ***************************************************************************/ |
16 | 16 | ||
17 | #define QTOPIA_INTERNAL_LANGLIST | ||
18 | |||
19 | #include "today.h" | 17 | #include "today.h" |
20 | 18 | ||
21 | #include <opie2/odebug.h> | 19 | #include <opie2/odebug.h> |
20 | #include <opie2/opluginloader.h> | ||
21 | #include <opie2/oconfig.h> | ||
22 | 22 | ||
23 | #include <qpe/config.h> | ||
24 | #include <qpe/qcopenvelope_qws.h> | 23 | #include <qpe/qcopenvelope_qws.h> |
25 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
26 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
27 | #include <qpe/contact.h> | 26 | #include <qpe/contact.h> |
28 | 27 | ||
29 | #include <qdir.h> | 28 | #include <qdir.h> |
30 | #include <qtimer.h> | 29 | #include <qtimer.h> |
31 | #include <qwhatsthis.h> | 30 | #include <qwhatsthis.h> |
32 | 31 | ||
33 | using namespace Opie::Ui; | 32 | using namespace Opie::Ui; |
33 | using Opie::Core::OPluginItem; | ||
34 | using Opie::Core::OPluginLoader; | ||
35 | using Opie::Core::OPluginManager; | ||
36 | using Opie::Core::OConfig; | ||
37 | |||
38 | |||
34 | struct TodayPlugin { | 39 | struct TodayPlugin { |
35 | TodayPlugin() : library( 0 ), iface( 0 ), guiPart( 0 ), guiBox( 0 ) {} | 40 | TodayPlugin() : iface( 0 ), guiPart( 0 ), guiBox( 0 ) {} |
36 | QLibrary *library; | ||
37 | QInterfacePtr<TodayPluginInterface> iface; | 41 | QInterfacePtr<TodayPluginInterface> iface; |
38 | TodayPluginObject *guiPart; | 42 | TodayPluginObject *guiPart; |
43 | OPluginItem oplugin; | ||
39 | QWidget *guiBox; | 44 | QWidget *guiBox; |
40 | QString name; | 45 | QString name; |
41 | bool active; | ||
42 | bool excludeRefresh; | 46 | bool excludeRefresh; |
43 | int pos; | ||
44 | }; | 47 | }; |
45 | 48 | ||
46 | static QValueList<TodayPlugin> pluginList; | 49 | static QMap<QString, TodayPlugin> pluginList; |
47 | |||
48 | static QMap<QString, TodayPlugin> tempList; | ||
49 | 50 | ||
50 | Today::Today( QWidget* parent, const char* name, WFlags fl ) | 51 | Today::Today( QWidget* parent, const char* name, WFlags fl ) |
51 | : TodayBase( parent, name, fl ) { | 52 | : TodayBase( parent, name, fl ) { |
52 | 53 | ||
53 | QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); | 54 | QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); |
54 | QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); | 55 | QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); |
55 | 56 | ||
56 | #if defined(Q_WS_QWS) | 57 | #if defined(Q_WS_QWS) |
57 | #if !defined(QT_NO_COP) | 58 | #if !defined(QT_NO_COP) |
59 | |||
58 | QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); | 60 | QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); |
59 | connect ( todayChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 61 | connect ( todayChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
60 | this, SLOT ( channelReceived(const QCString&,const QByteArray&) ) ); | 62 | this, SLOT ( channelReceived(const QCString&,const QByteArray&) ) ); |
61 | #endif | 63 | #endif |
62 | #endif | 64 | #endif |
63 | 65 | ||
64 | setOwnerField(); | 66 | setOwnerField(); |
65 | m_refreshTimer = new QTimer( this ); | ||
66 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | ||
67 | m_refreshTimer->start( 15000 ); | ||
68 | m_big_box = 0L; | 67 | m_big_box = 0L; |
69 | 68 | ||
70 | |||
71 | layout = new QVBoxLayout( this ); | 69 | layout = new QVBoxLayout( this ); |
72 | layout->addWidget( Frame ); | 70 | layout->addWidget( Frame ); |
73 | layout->addWidget( OwnerField ); | 71 | layout->addWidget( OwnerField ); |
74 | 72 | ||
75 | m_sv = new QScrollView( this ); | 73 | m_sv = new QScrollView( this ); |
76 | m_sv->setResizePolicy( QScrollView::AutoOneFit ); | 74 | m_sv->setResizePolicy( QScrollView::AutoOneFit ); |
77 | m_sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 75 | m_sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
78 | m_sv->setFrameShape( QFrame::NoFrame ); | 76 | m_sv->setFrameShape( QFrame::NoFrame ); |
79 | 77 | ||
80 | layout->addWidget( m_sv ); | 78 | layout->addWidget( m_sv ); |
81 | layout->setStretchFactor( m_sv,4 ); | 79 | layout->setStretchFactor( m_sv,4 ); |
82 | 80 | ||
83 | qApp->processEvents(); | 81 | m_refreshTimer = new QTimer( this ); |
82 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | ||
83 | |||
84 | init(); | ||
84 | loadPlugins(); | 85 | loadPlugins(); |
86 | initialize(); | ||
85 | QPEApplication::showWidget( this ); | 87 | QPEApplication::showWidget( this ); |
86 | } | 88 | } |
87 | 89 | ||
88 | /** | 90 | /** |
89 | * Qcop receive method. | 91 | * Qcop receive method. |
90 | */ | 92 | */ |
@@ -97,13 +99,12 @@ void Today::channelReceived( const QCString &msg, const QByteArray & data ) { | |||
97 | } | 99 | } |
98 | } | 100 | } |
99 | 101 | ||
100 | void Today::setRefreshTimer( int interval ) { | 102 | void Today::setRefreshTimer( int interval ) { |
101 | 103 | ||
102 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 104 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
103 | |||
104 | // 0 is "never" case | 105 | // 0 is "never" case |
105 | if ( !interval == 0 ) { | 106 | if ( !interval == 0 ) { |
106 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 107 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
107 | m_refreshTimer->changeInterval( interval ); | 108 | m_refreshTimer->changeInterval( interval ); |
108 | } | 109 | } |
109 | } | 110 | } |
@@ -129,22 +130,22 @@ void Today::setOwnerField() { | |||
129 | void Today::setOwnerField( QString &message ) { | 130 | void Today::setOwnerField( QString &message ) { |
130 | if ( !message.isEmpty() ) { | 131 | if ( !message.isEmpty() ) { |
131 | OwnerField->setText( "<b>" + message + "</b>" ); | 132 | OwnerField->setText( "<b>" + message + "</b>" ); |
132 | } | 133 | } |
133 | } | 134 | } |
134 | 135 | ||
136 | |||
135 | /** | 137 | /** |
136 | * Init stuff needed for today. Reads the config file. | 138 | * Init stuff needed for today. Reads the config file. |
137 | */ | 139 | */ |
138 | void Today::init() { | 140 | void Today::init() { |
139 | // read config | 141 | // read config |
140 | Config cfg( "today" ); | 142 | OConfig cfg( "today" ); |
141 | |||
142 | cfg.setGroup( "Plugins" ); | 143 | cfg.setGroup( "Plugins" ); |
143 | m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); | 144 | // m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); |
144 | m_allApplets = cfg.readListEntry( "AllApplets", ',' ); | 145 | // m_allApplets = cfg.readListEntry( "AllApplets", ',' ); |
145 | 146 | ||
146 | cfg.setGroup( "General" ); | 147 | cfg.setGroup( "General" ); |
147 | m_iconSize = cfg.readNumEntry( "IconSize", 18 ); | 148 | m_iconSize = cfg.readNumEntry( "IconSize", 18 ); |
148 | m_hideBanner = cfg.readNumEntry( "HideBanner", 0 ); | 149 | m_hideBanner = cfg.readNumEntry( "HideBanner", 0 ); |
149 | setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); | 150 | setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); |
150 | 151 | ||
@@ -166,175 +167,60 @@ void Today::init() { | |||
166 | 167 | ||
167 | m_big_box = new QWidget( m_sv->viewport() ); | 168 | m_big_box = new QWidget( m_sv->viewport() ); |
168 | m_sv->addChild( m_big_box ); | 169 | m_sv->addChild( m_big_box ); |
169 | m_bblayout = new QVBoxLayout ( m_big_box ); | 170 | m_bblayout = new QVBoxLayout ( m_big_box ); |
170 | } | 171 | } |
171 | 172 | ||
173 | |||
172 | /** | 174 | /** |
173 | * Load the plugins | 175 | * Load the plugins |
174 | */ | 176 | */ |
175 | void Today::loadPlugins() { | 177 | void Today::loadPlugins() { |
176 | 178 | ||
177 | init(); | 179 | m_pluginLoader = new OPluginLoader( "today", true ); |
178 | 180 | m_pluginLoader->setAutoDelete( true ); | |
179 | QValueList<TodayPlugin>::Iterator tit; | 181 | |
180 | if ( !pluginList.isEmpty() ) { | 182 | OPluginItem::List lst = m_pluginLoader->allAvailable( true ); |
181 | for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) { | 183 | |
182 | (*tit).guiBox->hide(); | 184 | m_manager = new OPluginManager( m_pluginLoader ); |
183 | (*tit).guiBox->reparent( 0, QPoint( 0, 0 ) ); | 185 | m_manager->load(); |
184 | delete (*tit).guiBox; | 186 | |
185 | (*tit).library->unload(); | 187 | for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { |
186 | delete (*tit).library; | 188 | TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); |
187 | } | 189 | |
188 | pluginList.clear(); | 190 | TodayPlugin plugin; |
191 | plugin.iface = iface; | ||
192 | plugin.name = (*it).name(); | ||
193 | plugin.oplugin = (*it); | ||
194 | |||
195 | plugin.guiPart = plugin.iface->guiPart(); | ||
196 | plugin.excludeRefresh = plugin.guiPart->excludeFromRefresh(); | ||
197 | |||
198 | // package the whole thing into a qwidget so it can be shown and hidden | ||
199 | plugin.guiBox = new QWidget( m_big_box ); | ||
200 | QHBoxLayout *boxLayout = new QHBoxLayout( plugin.guiBox ); | ||
201 | QPixmap plugPix; | ||
202 | plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( m_iconSize, m_iconSize ), 0 ); | ||
203 | OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); | ||
204 | plugIcon->setPixmap( plugPix ); | ||
205 | QWhatsThis::add | ||
206 | ( plugIcon, tr("Click here to launch the associated app") ); | ||
207 | plugIcon->setName( plugin.guiPart->appName() ); | ||
208 | connect( plugIcon, SIGNAL( clicked() ), this, SLOT( startApplication() ) ); | ||
209 | |||
210 | QWidget *plugWidget = plugin.guiPart->widget( plugin.guiBox ); | ||
211 | boxLayout->addWidget( plugIcon, 0, AlignTop ); | ||
212 | boxLayout->addWidget( plugWidget, 0, AlignTop ); | ||
213 | boxLayout->setStretchFactor( plugIcon, 1 ); | ||
214 | boxLayout->setStretchFactor( plugWidget, 9 ); | ||
215 | |||
216 | pluginList.insert( plugin.name, plugin ); | ||
217 | m_bblayout->addWidget(plugin.guiBox); | ||
189 | } | 218 | } |
190 | 219 | ||
191 | QString path = QPEApplication::qpeDir() + "/plugins/today"; | 220 | m_bblayout->addStretch( 1 ); |
192 | #ifdef Q_OS_MACX | ||
193 | owarn << "Searching for Plugins in: " << path << oendl; | ||
194 | QDir dir( path, "lib*.dylib" ); | ||
195 | #else | ||
196 | QDir dir( path, "lib*.so" ); | ||
197 | #endif | ||
198 | |||
199 | QStringList list = dir.entryList(); | ||
200 | QStringList::Iterator it; | ||
201 | |||
202 | // QMap<QString, TodayPlugin> tempList; | ||
203 | |||
204 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
205 | QInterfacePtr<TodayPluginInterface> iface; | ||
206 | QLibrary *lib = new QLibrary( path + "/" + *it ); | ||
207 | |||
208 | odebug << "querying: " << path + "/" + *it << oendl; | ||
209 | if ( lib->queryInterface( IID_TodayPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) { | ||
210 | odebug << "accepted: " << path + "/" + *it << oendl; | ||
211 | odebug << *it << oendl; | ||
212 | |||
213 | TodayPlugin plugin; | ||
214 | plugin.library = lib; | ||
215 | plugin.iface = iface; | ||
216 | plugin.name = QString(*it); | ||
217 | |||
218 | QString type = (*it).left( (*it).find(".") ); | ||
219 | |||
220 | QString lang; | ||
221 | Config config("locale"); | ||
222 | config.setGroup("Language"); | ||
223 | lang = config.readEntry( "Language", "en" ); | ||
224 | |||
225 | odebug << "Languages: " << lang << oendl; | ||
226 | QTranslator * trans = new QTranslator( qApp ); | ||
227 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + lang + "/" + type + ".qm"; | ||
228 | if ( trans->load( tfn ) ) { | ||
229 | qApp->installTranslator( trans ); | ||
230 | } else { | ||
231 | delete trans; | ||
232 | } | ||
233 | |||
234 | |||
235 | // find out if plugins should be shown | ||
236 | if ( m_excludeApplets.grep( *it ).isEmpty() ) { | ||
237 | plugin.active = true; | ||
238 | } else { | ||
239 | plugin.active = false; | ||
240 | } | ||
241 | |||
242 | plugin.guiPart = plugin.iface->guiPart(); | ||
243 | plugin.excludeRefresh = plugin.guiPart->excludeFromRefresh(); | ||
244 | |||
245 | // package the whole thing into a qwidget so it can be shown and hidden | ||
246 | plugin.guiBox = new QWidget( m_big_box ); | ||
247 | QHBoxLayout *boxLayout = new QHBoxLayout( plugin.guiBox ); | ||
248 | QPixmap plugPix; | ||
249 | plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( m_iconSize, m_iconSize ), 0 ); | ||
250 | OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); | ||
251 | plugIcon->setPixmap( plugPix ); | ||
252 | QWhatsThis::add( plugIcon, tr("Click here to launch the associated app") ); | ||
253 | plugIcon->setName( plugin.guiPart->appName() ); | ||
254 | connect( plugIcon, SIGNAL( clicked() ), this, SLOT( startApplication() ) ); | ||
255 | |||
256 | QWidget *plugWidget = plugin.guiPart->widget( plugin.guiBox ); | ||
257 | boxLayout->addWidget( plugIcon, 0, AlignTop ); | ||
258 | boxLayout->addWidget( plugWidget, 0, AlignTop ); | ||
259 | boxLayout->setStretchFactor( plugIcon, 1 ); | ||
260 | boxLayout->setStretchFactor( plugWidget, 9 ); | ||
261 | |||
262 | // "prebuffer" it in one more list, to get the sorting done | ||
263 | tempList.insert( plugin.name, plugin ); | ||
264 | |||
265 | // on first start the list is off course empty | ||
266 | if ( m_allApplets.isEmpty() ) { | ||
267 | pluginList.append( plugin ); | ||
268 | m_bblayout->addWidget( plugin.guiBox ); | ||
269 | } | ||
270 | |||
271 | // if plugin is not yet in the list, add it to the layout too | ||
272 | else if ( !m_allApplets.contains( plugin.name ) ) { | ||
273 | pluginList.append( plugin ); | ||
274 | } | ||
275 | } else { | ||
276 | odebug << "could not recognize " << path + "/" + *it << oendl; | ||
277 | delete lib; | ||
278 | } | ||
279 | |||
280 | } | ||
281 | |||
282 | |||
283 | if ( !m_allApplets.isEmpty() ) { | ||
284 | TodayPlugin tempPlugin; | ||
285 | QStringList::Iterator stringit; | ||
286 | |||
287 | for( stringit = m_allApplets.begin(); stringit != m_allApplets.end(); ++stringit ) { | ||
288 | tempPlugin = ( tempList.find( *stringit ) ).data(); | ||
289 | if ( !( (tempPlugin.name).isEmpty() ) ) { | ||
290 | pluginList.append( tempPlugin ); | ||
291 | m_bblayout->addWidget( tempPlugin.guiBox ); | ||
292 | } | ||
293 | } | ||
294 | } | ||
295 | m_bblayout->addStretch( 2 ); | ||
296 | draw(); | ||
297 | } | ||
298 | |||
299 | |||
300 | |||
301 | |||
302 | /** | ||
303 | * Repaint method. Reread all fields. | ||
304 | */ | ||
305 | void Today::draw() { | ||
306 | |||
307 | if ( pluginList.count() == 0 ) { | ||
308 | QLabel *noPlugins = new QLabel( this ); | ||
309 | noPlugins->setText( tr( "No plugins found" ) ); | ||
310 | layout->addWidget( noPlugins ); | ||
311 | return; | ||
312 | } | ||
313 | |||
314 | uint count = 0; | ||
315 | TodayPlugin plugin; | ||
316 | for ( uint i = 0; i < pluginList.count(); i++ ) { | ||
317 | plugin = pluginList[i]; | ||
318 | |||
319 | if ( plugin.active ) { | ||
320 | //odebug << plugin.name << " is ACTIVE " << oendl; | ||
321 | plugin.guiBox->show(); | ||
322 | } else { | ||
323 | //odebug << plugin.name << " is INACTIVE " << oendl; | ||
324 | plugin.guiBox->hide(); | ||
325 | } | ||
326 | count++; | ||
327 | } | ||
328 | |||
329 | if ( count == 0 ) { | ||
330 | QLabel *noPluginsActive = new QLabel( this ); | ||
331 | noPluginsActive->setText( tr( "No plugins activated" ) ); | ||
332 | layout->addWidget( noPluginsActive ); | ||
333 | } | ||
334 | repaint(); | ||
335 | } | 221 | } |
336 | 222 | ||
337 | 223 | ||
338 | /** | 224 | /** |
339 | * The method for the configuration dialog. | 225 | * The method for the configuration dialog. |
340 | */ | 226 | */ |
@@ -342,75 +228,30 @@ void Today::startConfig() { | |||
342 | 228 | ||
343 | // disconnect timer to prevent problems while being on config dialog | 229 | // disconnect timer to prevent problems while being on config dialog |
344 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 230 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
345 | m_refreshTimer->stop( ); | 231 | m_refreshTimer->stop( ); |
346 | 232 | ||
347 | TodayConfig conf( this, "dialog", true ); | 233 | TodayConfig conf( this, "dialog", true ); |
348 | 234 | conf.setUpPlugins( m_manager, m_pluginLoader ); | |
349 | TodayPlugin plugin; | ||
350 | QList<TodayConfigWidget> configWidgetList; | ||
351 | |||
352 | for ( int i = pluginList.count() - 1; i >= 0; i-- ) { | ||
353 | plugin = pluginList[i]; | ||
354 | |||
355 | // load the config widgets in the tabs | ||
356 | if ( plugin.guiPart->configWidget( this ) != 0l ) { | ||
357 | TodayConfigWidget* widget = plugin.guiPart->configWidget( conf.TabWidget3 ); | ||
358 | configWidgetList.append( widget ); | ||
359 | conf.TabWidget3->addTab( widget, plugin.guiPart->pixmapNameConfig() | ||
360 | , plugin.guiPart->appName() ); | ||
361 | } | ||
362 | // set the order/activate tab | ||
363 | conf.pluginManagement( plugin.name, plugin.guiPart->pluginName(), | ||
364 | Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) ); | ||
365 | } | ||
366 | 235 | ||
367 | if ( conf.exec() == QDialog::Accepted ) { | 236 | if ( conf.exec() == QDialog::Accepted ) { |
368 | conf.writeConfig(); | 237 | conf.writeConfig(); |
369 | TodayConfigWidget *confWidget; | 238 | initialize(); |
370 | for ( confWidget = configWidgetList.first(); confWidget != 0; | ||
371 | confWidget = configWidgetList.next() ) { | ||
372 | confWidget->writeConfig(); | ||
373 | } | ||
374 | |||
375 | // make the plugins to reinitialize ( reread its configs ) | ||
376 | reinitialize(); | ||
377 | draw(); | ||
378 | |||
379 | } else { | 239 | } else { |
380 | // since refresh is not called in that case , reconnect the signal | 240 | // since reinitialize is not called in that case , reconnect the signal |
381 | m_refreshTimer->start( 15000 ); // get the config value in here later | 241 | m_refreshTimer->start( 15000 ); // get the config value in here later |
382 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 242 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
383 | } | 243 | } |
384 | } | 244 | } |
385 | 245 | ||
386 | 246 | ||
387 | 247 | void Today::initialize() { | |
388 | void Today::reinitialize() { | ||
389 | 248 | ||
390 | Config cfg( "today" ); | 249 | Config cfg( "today" ); |
391 | cfg.setGroup( "Plugins" ); | 250 | cfg.setGroup( "Plugins" ); |
392 | m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); | ||
393 | m_allApplets = cfg.readListEntry( "AllApplets", ',' ); | ||
394 | |||
395 | /* reinitialize all plugins */ | ||
396 | QValueList<TodayPlugin>::Iterator it; | ||
397 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { | ||
398 | if ( !(*it).excludeRefresh ) { | ||
399 | (*it).guiPart->reinitialize(); | ||
400 | odebug << "reinit" << oendl; | ||
401 | } | ||
402 | 251 | ||
403 | /* check if plugins is still to be shown */ | ||
404 | if ( m_excludeApplets.grep( (*it).name ).isEmpty() ) { | ||
405 | (*it).active = true; | ||
406 | } else { | ||
407 | (*it).active = false; | ||
408 | } | ||
409 | |||
410 | } | ||
411 | 252 | ||
412 | cfg.setGroup( "General" ); | 253 | cfg.setGroup( "General" ); |
413 | m_iconSize = cfg.readNumEntry( "IconSize", 18 ); | 254 | m_iconSize = cfg.readNumEntry( "IconSize", 18 ); |
414 | m_hideBanner = cfg.readNumEntry( "HideBanner", 0 ); | 255 | m_hideBanner = cfg.readNumEntry( "HideBanner", 0 ); |
415 | setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); | 256 | setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); |
416 | 257 | ||
@@ -423,56 +264,91 @@ void Today::reinitialize() { | |||
423 | TodayLabel->hide(); | 264 | TodayLabel->hide(); |
424 | } else { | 265 | } else { |
425 | Opiezilla->show(); | 266 | Opiezilla->show(); |
426 | TodayLabel->show(); | 267 | TodayLabel->show(); |
427 | } | 268 | } |
428 | 269 | ||
429 | delete m_bblayout; | 270 | if ( m_bblayout ) { |
430 | m_bblayout = new QVBoxLayout( m_big_box ); | 271 | delete m_bblayout; |
431 | TodayPlugin tempPlugin; | 272 | } |
432 | QStringList::Iterator stringit; | 273 | m_bblayout = new QVBoxLayout ( m_big_box ); |
274 | |||
275 | if ( pluginList.count() == 0 ) { | ||
276 | QLabel *noPlugins = new QLabel( this ); | ||
277 | noPlugins->setText( tr( "No plugins found" ) ); | ||
278 | layout->addWidget( noPlugins ); | ||
279 | } else { | ||
280 | |||
281 | uint count = 0; | ||
282 | TodayPlugin tempPlugin; | ||
283 | OPluginItem::List lst = m_pluginLoader->allAvailable( true ); | ||
284 | for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { | ||
433 | 285 | ||
434 | for( stringit = m_allApplets.begin(); stringit != m_allApplets.end(); ++stringit ) { | 286 | TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); |
435 | tempPlugin = ( tempList.find( *stringit ) ).data(); | 287 | |
436 | if ( !( (tempPlugin.name).isEmpty() ) ) { | 288 | tempPlugin = ( pluginList.find( (*it).name() ).data() ); |
437 | m_bblayout->addWidget( tempPlugin.guiBox ); | 289 | if ( !( (tempPlugin.name).isEmpty() ) ) { |
290 | if ( (*it).isEnabled() ) { | ||
291 | iface->guiPart()->reinitialize(); | ||
292 | odebug << "reinit" << oendl; | ||
293 | tempPlugin.guiBox->show(); | ||
294 | m_bblayout->addWidget(tempPlugin.guiBox); | ||
295 | count++; | ||
296 | } else { | ||
297 | tempPlugin.guiBox->hide(); | ||
298 | } | ||
299 | } | ||
300 | } | ||
301 | if ( count == 0 ) { | ||
302 | QLabel *noPluginsActive = new QLabel( this ); | ||
303 | noPluginsActive->setText( tr( "No plugins activated" ) ); | ||
304 | layout->addWidget( noPluginsActive ); | ||
438 | } | 305 | } |
439 | } | 306 | } |
440 | m_bblayout->addStretch( 2 ); | 307 | m_bblayout->addStretch( 1 ); |
441 | 308 | repaint(); | |
442 | } | 309 | } |
443 | 310 | ||
444 | /** | 311 | /** |
445 | * Refresh for the view. Reload all applets | 312 | * Refresh for the view. Reload all applets |
446 | * | 313 | * |
447 | */ | 314 | */ |
448 | void Today::refresh() { | 315 | void Today::refresh() { |
449 | 316 | ||
450 | QValueList<TodayPlugin>::Iterator it; | 317 | OPluginItem::List lst = m_pluginLoader->filtered( true ); |
451 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { | 318 | |
452 | if ( !(*it).excludeRefresh ) { | 319 | for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { |
453 | (*it).guiPart->refresh(); | 320 | TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); |
454 | odebug << "refresh" << oendl; | 321 | iface->guiPart()->refresh(); |
455 | } | 322 | odebug << "refresh" << oendl; |
456 | } | 323 | } |
457 | 324 | ||
458 | DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( QDate::currentDate() ) + "</font>" ) ); | 325 | DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( QDate::currentDate() ) + "</font>" ) ); |
459 | 326 | ||
460 | updateGeometry(); | 327 | updateGeometry(); |
461 | repaint(); | 328 | repaint(); |
462 | } | 329 | } |
463 | 330 | ||
331 | |||
464 | void Today::startApplication() { | 332 | void Today::startApplication() { |
465 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 333 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
466 | e << QString( sender()->name() ); | 334 | e << QString( sender()->name() ); |
467 | } | 335 | } |
468 | 336 | ||
337 | |||
469 | /** | 338 | /** |
470 | * launch addressbook (personal card) | 339 | * launch addressbook (personal card) |
471 | */ | 340 | */ |
472 | void Today::editCard() { | 341 | void Today::editCard() { |
473 | QCopEnvelope env( "QPE/Application/addressbook", "editPersonalAndClose()" ); | 342 | QCopEnvelope env( "QPE/Application/addressbook", "editPersonalAndClose()" ); |
474 | } | 343 | } |
475 | 344 | ||
345 | |||
476 | Today::~Today() { | 346 | Today::~Today() { |
347 | if (m_pluginLoader) { | ||
348 | delete m_pluginLoader; | ||
349 | } | ||
350 | if (m_manager) { | ||
351 | delete m_manager; | ||
352 | } | ||
477 | } | 353 | } |
478 | 354 | ||