-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 | |||
@@ -16,4 +16,2 @@ | |||
16 | 16 | ||
17 | #define QTOPIA_INTERNAL_LANGLIST | ||
18 | |||
19 | #include "today.h" | 17 | #include "today.h" |
@@ -21,4 +19,5 @@ | |||
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> |
@@ -33,20 +32,22 @@ | |||
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 | ||
@@ -55,4 +56,5 @@ Today::Today( QWidget* parent, const char* name, WFlags fl ) | |||
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 ); |
@@ -60,12 +62,8 @@ Today::Today( QWidget* parent, const char* name, WFlags fl ) | |||
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 ); |
@@ -82,4 +80,8 @@ Today::Today( QWidget* parent, const char* name, WFlags fl ) | |||
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 ); |
@@ -102,3 +104,2 @@ void Today::setRefreshTimer( int interval ) { | |||
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 |
@@ -134,2 +135,3 @@ void Today::setOwnerField( QString &message ) { | |||
134 | 135 | ||
136 | |||
135 | /** | 137 | /** |
@@ -139,7 +141,6 @@ 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 | ||
@@ -171,2 +172,3 @@ void Today::init() { | |||
171 | 172 | ||
173 | |||
172 | /** | 174 | /** |
@@ -176,160 +178,44 @@ 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 | } |
@@ -347,20 +233,3 @@ void Today::startConfig() { | |||
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 | ||
@@ -368,14 +237,5 @@ void Today::startConfig() { | |||
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 |
@@ -386,4 +246,3 @@ void Today::startConfig() { | |||
386 | 246 | ||
387 | 247 | void Today::initialize() { | |
388 | void Today::reinitialize() { | ||
389 | 248 | ||
@@ -391,21 +250,3 @@ void Today::reinitialize() { | |||
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 | ||
@@ -428,15 +269,41 @@ void Today::reinitialize() { | |||
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 | } |
@@ -449,8 +316,8 @@ 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 | } |
@@ -463,2 +330,3 @@ void Today::refresh() { | |||
463 | 330 | ||
331 | |||
464 | void Today::startApplication() { | 332 | void Today::startApplication() { |
@@ -468,5 +336,6 @@ void Today::startApplication() { | |||
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() { |
@@ -475,3 +344,10 @@ void Today::editCard() { | |||
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 | } |