-rw-r--r-- | core/pim/today/today.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index 91028c8..1f758f2 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp | |||
@@ -49,49 +49,50 @@ struct TodayPlugin { | |||
49 | bool excludeRefresh; | 49 | bool excludeRefresh; |
50 | int pos; | 50 | int pos; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | static QValueList<TodayPlugin> pluginList; | 53 | static QValueList<TodayPlugin> pluginList; |
54 | 54 | ||
55 | Today::Today( QWidget* parent, const char* name, WFlags fl ) | 55 | Today::Today( QWidget* parent, const char* name, WFlags fl ) |
56 | : TodayBase( parent, name, fl ) { | 56 | : TodayBase( parent, name, fl ) { |
57 | 57 | ||
58 | QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); | 58 | QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); |
59 | QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); | 59 | QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); |
60 | 60 | ||
61 | #if defined(Q_WS_QWS) | 61 | #if defined(Q_WS_QWS) |
62 | #if !defined(QT_NO_COP) | 62 | #if !defined(QT_NO_COP) |
63 | QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); | 63 | QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); |
64 | connect ( todayChannel, SIGNAL( received( const QCString &, const QByteArray &) ), | 64 | connect ( todayChannel, SIGNAL( received( const QCString &, const QByteArray &) ), |
65 | this, SLOT ( channelReceived( const QCString &, const QByteArray &) ) ); | 65 | this, SLOT ( channelReceived( const QCString &, const QByteArray &) ) ); |
66 | #endif | 66 | #endif |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | setOwnerField(); | 69 | setOwnerField(); |
70 | m_refreshTimer = new QTimer( this ); | 70 | m_refreshTimer = new QTimer( this ); |
71 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 71 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
72 | m_refreshTimer->start( 15000 ); | 72 | m_refreshTimer->start( 15000 ); |
73 | refresh(); | 73 | init(); |
74 | loadPlugins(); | ||
74 | showMaximized(); | 75 | showMaximized(); |
75 | } | 76 | } |
76 | 77 | ||
77 | /** | 78 | /** |
78 | * Qcop receive method. | 79 | * Qcop receive method. |
79 | */ | 80 | */ |
80 | void Today::channelReceived( const QCString &msg, const QByteArray & data ) { | 81 | void Today::channelReceived( const QCString &msg, const QByteArray & data ) { |
81 | QDataStream stream( data, IO_ReadOnly ); | 82 | QDataStream stream( data, IO_ReadOnly ); |
82 | if ( msg == "message(QString)" ) { | 83 | if ( msg == "message(QString)" ) { |
83 | QString message; | 84 | QString message; |
84 | stream >> message; | 85 | stream >> message; |
85 | setOwnerField( message ); | 86 | setOwnerField( message ); |
86 | } | 87 | } |
87 | } | 88 | } |
88 | 89 | ||
89 | void Today::setRefreshTimer( int interval ) { | 90 | void Today::setRefreshTimer( int interval ) { |
90 | 91 | ||
91 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 92 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
92 | 93 | ||
93 | // 0 is "never" case | 94 | // 0 is "never" case |
94 | if ( !interval == 0 ) { | 95 | if ( !interval == 0 ) { |
95 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 96 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
96 | m_refreshTimer->changeInterval( interval ); | 97 | m_refreshTimer->changeInterval( interval ); |
97 | } | 98 | } |
@@ -115,48 +116,63 @@ void Today::setOwnerField() { | |||
115 | /** | 116 | /** |
116 | * Set the owner field with a given QString, for example per qcop. | 117 | * Set the owner field with a given QString, for example per qcop. |
117 | */ | 118 | */ |
118 | void Today::setOwnerField( QString &message ) { | 119 | void Today::setOwnerField( QString &message ) { |
119 | if ( !message.isEmpty() ) { | 120 | if ( !message.isEmpty() ) { |
120 | OwnerField->setText( "<b>" + message + "</b>" ); | 121 | OwnerField->setText( "<b>" + message + "</b>" ); |
121 | } | 122 | } |
122 | } | 123 | } |
123 | 124 | ||
124 | 125 | ||
125 | /** | 126 | /** |
126 | * Init stuff needed for today. Reads the config file. | 127 | * Init stuff needed for today. Reads the config file. |
127 | */ | 128 | */ |
128 | void Today::init() { | 129 | void Today::init() { |
129 | // read config | 130 | // read config |
130 | Config cfg( "today" ); | 131 | Config cfg( "today" ); |
131 | 132 | ||
132 | cfg.setGroup( "Plugins" ); | 133 | cfg.setGroup( "Plugins" ); |
133 | m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); | 134 | m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); |
134 | m_allApplets = cfg.readListEntry( "AllApplets", ',' ); | 135 | m_allApplets = cfg.readListEntry( "AllApplets", ',' ); |
135 | 136 | ||
136 | cfg.setGroup( "General" ); | 137 | cfg.setGroup( "General" ); |
137 | m_iconSize = cfg.readNumEntry( "IconSize", 18 ); | 138 | m_iconSize = cfg.readNumEntry( "IconSize", 18 ); |
138 | setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); | 139 | setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); |
140 | |||
141 | |||
142 | // qDebug(" refresh "); | ||
143 | // set the date in top label | ||
144 | QDate date = QDate::currentDate(); | ||
145 | QString time = ( tr( date.toString() ) ); | ||
146 | |||
147 | DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) ); | ||
148 | |||
149 | if ( layout ) { | ||
150 | delete layout; | ||
151 | } | ||
152 | layout = new QVBoxLayout( this ); | ||
153 | layout->addWidget( Frame ); | ||
154 | layout->addWidget( OwnerField ); | ||
139 | } | 155 | } |
140 | 156 | ||
141 | 157 | ||
142 | /** | 158 | /** |
143 | * Load the plugins | 159 | * Load the plugins |
144 | */ | 160 | */ |
145 | void Today::loadPlugins() { | 161 | void Today::loadPlugins() { |
146 | 162 | ||
147 | // extra list for plugins that exclude themself from periodic refresh | 163 | // extra list for plugins that exclude themself from periodic refresh |
148 | QMap<QString, TodayPlugin> pluginListRefreshExclude; | 164 | QMap<QString, TodayPlugin> pluginListRefreshExclude; |
149 | 165 | ||
150 | QValueList<TodayPlugin>::Iterator tit; | 166 | QValueList<TodayPlugin>::Iterator tit; |
151 | if ( !pluginList.isEmpty() ) { | 167 | if ( !pluginList.isEmpty() ) { |
152 | for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) { | 168 | for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) { |
153 | if ( (*tit).excludeRefresh ) { | 169 | if ( (*tit).excludeRefresh ) { |
154 | pluginListRefreshExclude.insert( (*tit).name , (*tit) ); | 170 | pluginListRefreshExclude.insert( (*tit).name , (*tit) ); |
155 | qDebug( "Found a plugin that does not want refresh feature" ); | 171 | qDebug( "Found a plugin that does not want refresh feature" ); |
156 | } else { | 172 | } else { |
157 | (*tit).guiBox->hide(); | 173 | (*tit).guiBox->hide(); |
158 | (*tit).guiBox->reparent( 0, QPoint( 0, 0 ) ); | 174 | (*tit).guiBox->reparent( 0, QPoint( 0, 0 ) ); |
159 | (*tit).library->unload(); | 175 | (*tit).library->unload(); |
160 | delete (*tit).guiBox; | 176 | delete (*tit).guiBox; |
161 | delete (*tit).library; | 177 | delete (*tit).library; |
162 | } | 178 | } |
@@ -245,48 +261,49 @@ void Today::loadPlugins() { | |||
245 | // if plugin is not yet in the list, add it to the layout too | 261 | // if plugin is not yet in the list, add it to the layout too |
246 | else if ( !m_allApplets.contains( plugin.name ) ) { | 262 | else if ( !m_allApplets.contains( plugin.name ) ) { |
247 | layout->addWidget( plugin.guiBox ); | 263 | layout->addWidget( plugin.guiBox ); |
248 | pluginList.append( plugin ); | 264 | pluginList.append( plugin ); |
249 | } | 265 | } |
250 | } | 266 | } |
251 | } else { | 267 | } else { |
252 | qDebug( "could not recognize %s", QString( path + "/" + *it ).latin1() ); | 268 | qDebug( "could not recognize %s", QString( path + "/" + *it ).latin1() ); |
253 | delete lib; | 269 | delete lib; |
254 | } | 270 | } |
255 | } | 271 | } |
256 | 272 | ||
257 | if ( !m_allApplets.isEmpty() ) { | 273 | if ( !m_allApplets.isEmpty() ) { |
258 | TodayPlugin tempPlugin; | 274 | TodayPlugin tempPlugin; |
259 | QStringList::Iterator stringit; | 275 | QStringList::Iterator stringit; |
260 | 276 | ||
261 | for( stringit = m_allApplets.begin(); stringit != m_allApplets.end(); ++stringit ) { | 277 | for( stringit = m_allApplets.begin(); stringit != m_allApplets.end(); ++stringit ) { |
262 | tempPlugin = ( tempList.find( *stringit ) ).data(); | 278 | tempPlugin = ( tempList.find( *stringit ) ).data(); |
263 | if ( !( (tempPlugin.name).isEmpty() ) ) { | 279 | if ( !( (tempPlugin.name).isEmpty() ) ) { |
264 | layout->addWidget( tempPlugin.guiBox ); | 280 | layout->addWidget( tempPlugin.guiBox ); |
265 | pluginList.append( tempPlugin ); | 281 | pluginList.append( tempPlugin ); |
266 | } | 282 | } |
267 | } | 283 | } |
268 | } | 284 | } |
285 | draw(); | ||
269 | } | 286 | } |
270 | 287 | ||
271 | 288 | ||
272 | /** | 289 | /** |
273 | * Repaint method. Reread all fields. | 290 | * Repaint method. Reread all fields. |
274 | */ | 291 | */ |
275 | void Today::draw() { | 292 | void Today::draw() { |
276 | 293 | ||
277 | if ( pluginList.count() == 0 ) { | 294 | if ( pluginList.count() == 0 ) { |
278 | QLabel *noPlugins = new QLabel( this ); | 295 | QLabel *noPlugins = new QLabel( this ); |
279 | noPlugins->setText( tr( "No plugins found" ) ); | 296 | noPlugins->setText( tr( "No plugins found" ) ); |
280 | layout->addWidget( noPlugins ); | 297 | layout->addWidget( noPlugins ); |
281 | return; | 298 | return; |
282 | } | 299 | } |
283 | 300 | ||
284 | uint count = 0; | 301 | uint count = 0; |
285 | TodayPlugin plugin; | 302 | TodayPlugin plugin; |
286 | for ( uint i = 0; i < pluginList.count(); i++ ) { | 303 | for ( uint i = 0; i < pluginList.count(); i++ ) { |
287 | plugin = pluginList[i]; | 304 | plugin = pluginList[i]; |
288 | 305 | ||
289 | if ( plugin.active ) { | 306 | if ( plugin.active ) { |
290 | // qDebug( plugin.name + " is ACTIVE " ); | 307 | // qDebug( plugin.name + " is ACTIVE " ); |
291 | plugin.guiBox->show(); | 308 | plugin.guiBox->show(); |
292 | } else { | 309 | } else { |
@@ -319,72 +336,63 @@ void Today::startConfig() { | |||
319 | QList<TodayConfigWidget> configWidgetList; | 336 | QList<TodayConfigWidget> configWidgetList; |
320 | 337 | ||
321 | for ( int i = pluginList.count() - 1 ; i >= 0; i-- ) { | 338 | for ( int i = pluginList.count() - 1 ; i >= 0; i-- ) { |
322 | plugin = pluginList[i]; | 339 | plugin = pluginList[i]; |
323 | 340 | ||
324 | // load the config widgets in the tabs | 341 | // load the config widgets in the tabs |
325 | if ( plugin.guiPart->configWidget( this ) != 0l ) { | 342 | if ( plugin.guiPart->configWidget( this ) != 0l ) { |
326 | TodayConfigWidget* widget = plugin.guiPart->configWidget( conf.TabWidget3 ); | 343 | TodayConfigWidget* widget = plugin.guiPart->configWidget( conf.TabWidget3 ); |
327 | configWidgetList.append( widget ); | 344 | configWidgetList.append( widget ); |
328 | conf.TabWidget3->addTab( widget, plugin.guiPart->pixmapNameConfig() | 345 | conf.TabWidget3->addTab( widget, plugin.guiPart->pixmapNameConfig() |
329 | , plugin.guiPart->appName() ); | 346 | , plugin.guiPart->appName() ); |
330 | } | 347 | } |
331 | // set the order/activate tab | 348 | // set the order/activate tab |
332 | conf.pluginManagement( plugin.name, plugin.guiPart->pluginName(), | 349 | conf.pluginManagement( plugin.name, plugin.guiPart->pluginName(), |
333 | Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) ); | 350 | Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) ); |
334 | } | 351 | } |
335 | 352 | ||
336 | if ( conf.exec() == QDialog::Accepted ) { | 353 | if ( conf.exec() == QDialog::Accepted ) { |
337 | conf.writeConfig(); | 354 | conf.writeConfig(); |
338 | TodayConfigWidget *confWidget; | 355 | TodayConfigWidget *confWidget; |
339 | for ( confWidget = configWidgetList.first(); confWidget != 0; | 356 | for ( confWidget = configWidgetList.first(); confWidget != 0; |
340 | confWidget = configWidgetList.next() ) { | 357 | confWidget = configWidgetList.next() ) { |
341 | confWidget->writeConfig(); | 358 | confWidget->writeConfig(); |
342 | } | 359 | } |
343 | refresh(); | 360 | loadPlugins(); |
344 | } else { | 361 | } else { |
345 | // since refresh is not called in that case , reconnect the signal | 362 | // since refresh is not called in that case , reconnect the signal |
346 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 363 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
347 | } | 364 | } |
348 | } | 365 | } |
349 | 366 | ||
350 | 367 | ||
351 | /** | 368 | /** |
352 | * Refresh for the view. Reload all applets | 369 | * Refresh for the view. Reload all applets |
353 | * | 370 | * |
354 | */ | 371 | */ |
355 | void Today::refresh() { | 372 | void Today::refresh() { |
356 | init(); | 373 | init(); |
357 | 374 | ||
358 | // qDebug(" refresh "); | 375 | QValueList<TodayPlugin>::Iterator it; |
359 | // set the date in top label | 376 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { |
360 | QDate date = QDate::currentDate(); | 377 | if ( !(*it).excludeRefresh ) { |
361 | QString time = ( tr( date.toString() ) ); | 378 | (*it).guiPart->refresh(); |
362 | 379 | qDebug( "refresh" ); | |
363 | DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) ); | 380 | } |
364 | |||
365 | if ( layout ) { | ||
366 | delete layout; | ||
367 | } | 381 | } |
368 | layout = new QVBoxLayout( this ); | ||
369 | layout->addWidget( Frame ); | ||
370 | layout->addWidget( OwnerField ); | ||
371 | |||
372 | loadPlugins(); | ||
373 | draw(); | ||
374 | } | 382 | } |
375 | 383 | ||
376 | void Today::startApplication() { | 384 | void Today::startApplication() { |
377 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 385 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
378 | e << QString( sender()->name() ); | 386 | e << QString( sender()->name() ); |
379 | } | 387 | } |
380 | 388 | ||
381 | /** | 389 | /** |
382 | * launch addressbook (personal card) | 390 | * launch addressbook (personal card) |
383 | */ | 391 | */ |
384 | void Today::editCard() { | 392 | void Today::editCard() { |
385 | QCopEnvelope env( "QPE/Application/addressbook", "editPersonalAndClose()" ); | 393 | QCopEnvelope env( "QPE/Application/addressbook", "editPersonalAndClose()" ); |
386 | } | 394 | } |
387 | 395 | ||
388 | Today::~Today() { | 396 | Today::~Today() { |
389 | } | 397 | } |
390 | 398 | ||