author | zecke <zecke> | 2004-09-12 20:31:20 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-12 20:31:20 (UTC) |
commit | b52e2e46ec535a5307276b8fdf1e578aa5d29283 (patch) (unidiff) | |
tree | f30d0fd2faaf89c2bc982e3f8a645645bf74edd8 /core/pim/today/today.cpp | |
parent | 90aaa298cc69522e88e1f81ade7d5259131b1544 (diff) | |
download | opie-b52e2e46ec535a5307276b8fdf1e578aa5d29283.zip opie-b52e2e46ec535a5307276b8fdf1e578aa5d29283.tar.gz opie-b52e2e46ec535a5307276b8fdf1e578aa5d29283.tar.bz2 |
-Only create configWidgets once per config dialog, properly delete them
-Delete the Widgets before we remove the plugin from our address space
some random clean ups
-rw-r--r-- | core/pim/today/today.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index a8c8651..be7cbce 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp | |||
@@ -7,105 +7,103 @@ | |||
7 | */ | 7 | */ |
8 | /*************************************************************************** | 8 | /*************************************************************************** |
9 | * * | 9 | * * |
10 | * This program is free software; you can redistribute it and/or modify * | 10 | * This program is free software; you can redistribute it and/or modify * |
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 | #include "today.h" | 17 | #include "today.h" |
18 | 18 | ||
19 | #include <opie2/odebug.h> | 19 | #include <opie2/odebug.h> |
20 | #include <opie2/opluginloader.h> | 20 | #include <opie2/opluginloader.h> |
21 | #include <opie2/oconfig.h> | 21 | #include <opie2/oconfig.h> |
22 | 22 | ||
23 | #include <qpe/qcopenvelope_qws.h> | 23 | #include <qpe/qcopenvelope_qws.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/contact.h> | 26 | #include <qpe/contact.h> |
27 | 27 | ||
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qtimer.h> | 29 | #include <qtimer.h> |
30 | #include <qwhatsthis.h> | 30 | #include <qwhatsthis.h> |
31 | #include <qmessagebox.h> | ||
31 | 32 | ||
32 | using namespace Opie::Ui; | 33 | using namespace Opie::Ui; |
33 | using Opie::Core::OPluginItem; | 34 | using Opie::Core::OPluginItem; |
34 | using Opie::Core::OPluginLoader; | 35 | using Opie::Core::OPluginLoader; |
35 | using Opie::Core::OPluginManager; | 36 | using Opie::Core::OPluginManager; |
36 | using Opie::Core::OConfig; | 37 | using Opie::Core::OConfig; |
37 | 38 | ||
38 | 39 | ||
39 | struct TodayPlugin { | 40 | struct TodayPlugin { |
40 | TodayPlugin() : iface( 0 ), guiPart( 0 ), guiBox( 0 ) {} | 41 | TodayPlugin() : iface( 0 ), guiPart( 0 ), guiBox( 0 ) {} |
41 | QInterfacePtr<TodayPluginInterface> iface; | 42 | QInterfacePtr<TodayPluginInterface> iface; |
42 | TodayPluginObject *guiPart; | 43 | TodayPluginObject *guiPart; |
43 | OPluginItem oplugin; | 44 | OPluginItem oplugin; |
44 | QWidget *guiBox; | 45 | QWidget *guiBox; |
45 | QString name; | 46 | QString name; |
46 | bool excludeRefresh; | 47 | bool excludeRefresh; |
47 | }; | 48 | }; |
48 | 49 | ||
49 | static QMap<QString, TodayPlugin> pluginList; | 50 | static QMap<QString, TodayPlugin> pluginList; |
50 | 51 | ||
51 | Today::Today( QWidget* parent, const char* name, WFlags fl ) | 52 | Today::Today( QWidget* parent, const char* name, WFlags fl ) |
52 | : TodayBase( parent, name, fl ) { | 53 | : TodayBase( parent, name, fl ) { |
53 | 54 | ||
54 | QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); | 55 | QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); |
55 | QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); | 56 | QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); |
56 | 57 | ||
57 | #if defined(Q_WS_QWS) | 58 | #if !defined(QT_NO_COP) |
58 | #if !defined(QT_NO_COP) | ||
59 | 59 | ||
60 | QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); | 60 | QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); |
61 | connect ( todayChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 61 | connect ( todayChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
62 | this, SLOT ( channelReceived(const QCString&,const QByteArray&) ) ); | 62 | this, SLOT ( channelReceived(const QCString&,const QByteArray&) ) ); |
63 | #endif | 63 | #endif |
64 | #endif | ||
65 | 64 | ||
66 | setOwnerField(); | 65 | setOwnerField(); |
67 | m_big_box = 0L; | 66 | m_big_box = 0L; |
68 | 67 | ||
69 | layout = new QVBoxLayout( this ); | 68 | layout = new QVBoxLayout( this ); |
70 | layout->addWidget( Frame ); | 69 | layout->addWidget( Frame ); |
71 | layout->addWidget( OwnerField ); | 70 | layout->addWidget( OwnerField ); |
72 | 71 | ||
73 | m_sv = new QScrollView( this ); | 72 | m_sv = new QScrollView( this ); |
74 | m_sv->setResizePolicy( QScrollView::AutoOneFit ); | 73 | m_sv->setResizePolicy( QScrollView::AutoOneFit ); |
75 | m_sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 74 | m_sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
76 | m_sv->setFrameShape( QFrame::NoFrame ); | 75 | m_sv->setFrameShape( QFrame::NoFrame ); |
77 | 76 | ||
78 | layout->addWidget( m_sv ); | 77 | layout->addWidget( m_sv ); |
79 | layout->setStretchFactor( m_sv,4 ); | 78 | layout->setStretchFactor( m_sv,4 ); |
80 | 79 | ||
81 | m_refreshTimer = new QTimer( this ); | 80 | m_refreshTimer = new QTimer( this ); |
82 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 81 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
83 | 82 | ||
84 | init(); | 83 | init(); |
85 | loadPlugins(); | 84 | loadPlugins(); |
86 | initialize(); | 85 | initialize(); |
87 | QPEApplication::showWidget( this ); | ||
88 | } | 86 | } |
89 | 87 | ||
90 | /** | 88 | /** |
91 | * Qcop receive method. | 89 | * Qcop receive method. |
92 | */ | 90 | */ |
93 | void Today::channelReceived( const QCString &msg, const QByteArray & data ) { | 91 | void Today::channelReceived( const QCString &msg, const QByteArray & data ) { |
94 | QDataStream stream( data, IO_ReadOnly ); | 92 | QDataStream stream( data, IO_ReadOnly ); |
95 | if ( msg == "message(QString)" ) { | 93 | if ( msg == "message(QString)" ) { |
96 | QString message; | 94 | QString message; |
97 | stream >> message; | 95 | stream >> message; |
98 | setOwnerField( message ); | 96 | setOwnerField( message ); |
99 | } | 97 | } |
100 | } | 98 | } |
101 | 99 | ||
102 | void Today::setRefreshTimer( int interval ) { | 100 | void Today::setRefreshTimer( int interval ) { |
103 | 101 | ||
104 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 102 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
105 | // 0 is "never" case | 103 | // 0 is "never" case |
106 | if ( !interval == 0 ) { | 104 | if ( !interval == 0 ) { |
107 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 105 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
108 | m_refreshTimer->changeInterval( interval ); | 106 | m_refreshTimer->changeInterval( interval ); |
109 | } | 107 | } |
110 | } | 108 | } |
111 | 109 | ||
@@ -158,53 +156,66 @@ void Today::init() { | |||
158 | TodayLabel->hide(); | 156 | TodayLabel->hide(); |
159 | } else { | 157 | } else { |
160 | Opiezilla->show(); | 158 | Opiezilla->show(); |
161 | TodayLabel->show(); | 159 | TodayLabel->show(); |
162 | } | 160 | } |
163 | 161 | ||
164 | if ( m_big_box ) { | 162 | if ( m_big_box ) { |
165 | delete m_big_box; | 163 | delete m_big_box; |
166 | } | 164 | } |
167 | 165 | ||
168 | m_big_box = new QWidget( m_sv->viewport() ); | 166 | m_big_box = new QWidget( m_sv->viewport() ); |
169 | m_sv->addChild( m_big_box ); | 167 | m_sv->addChild( m_big_box ); |
170 | m_bblayout = new QVBoxLayout ( m_big_box ); | 168 | m_bblayout = new QVBoxLayout ( m_big_box ); |
171 | } | 169 | } |
172 | 170 | ||
173 | 171 | ||
174 | /** | 172 | /** |
175 | * Load the plugins | 173 | * Load the plugins |
176 | */ | 174 | */ |
177 | void Today::loadPlugins() { | 175 | void Today::loadPlugins() { |
178 | 176 | ||
179 | m_pluginLoader = new OPluginLoader( "today", true ); | 177 | m_pluginLoader = new OPluginLoader( "today", true ); |
180 | m_pluginLoader->setAutoDelete( true ); | 178 | m_pluginLoader->setAutoDelete( true ); |
181 | 179 | ||
182 | OPluginItem::List lst = m_pluginLoader->allAvailable( true ); | ||
183 | |||
184 | m_manager = new OPluginManager( m_pluginLoader ); | 180 | m_manager = new OPluginManager( m_pluginLoader ); |
185 | m_manager->load(); | 181 | m_manager->load(); |
186 | 182 | ||
183 | /* | ||
184 | * check if loading of Plugins crashed | ||
185 | */ | ||
186 | if( m_pluginLoader->isInSafeMode() ) { | ||
187 | QMessageBox::information(this, tr("Today Error"), | ||
188 | tr("<qt>The plugin '%1' caused Today to crash." | ||
189 | " It could be that the plugin is not properly" | ||
190 | " installed.<br>Today tries to continue loading" | ||
191 | " plugins.</qt>") | ||
192 | .arg( m_manager->crashedPlugin().name())); | ||
193 | } | ||
194 | |||
195 | OPluginItem::List lst = m_pluginLoader->filtered( true ); | ||
196 | |||
197 | |||
187 | for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { | 198 | for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { |
188 | TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); | 199 | TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); |
189 | 200 | ||
190 | TodayPlugin plugin; | 201 | TodayPlugin plugin; |
191 | plugin.iface = iface; | 202 | plugin.iface = iface; |
192 | plugin.name = (*it).name(); | 203 | plugin.name = (*it).name(); |
193 | plugin.oplugin = (*it); | 204 | plugin.oplugin = (*it); |
194 | 205 | ||
195 | plugin.guiPart = plugin.iface->guiPart(); | 206 | plugin.guiPart = plugin.iface->guiPart(); |
196 | plugin.excludeRefresh = plugin.guiPart->excludeFromRefresh(); | 207 | plugin.excludeRefresh = plugin.guiPart->excludeFromRefresh(); |
197 | 208 | ||
198 | // package the whole thing into a qwidget so it can be shown and hidden | 209 | // package the whole thing into a qwidget so it can be shown and hidden |
199 | plugin.guiBox = new QWidget( m_big_box ); | 210 | plugin.guiBox = new QWidget( m_big_box ); |
200 | QHBoxLayout *boxLayout = new QHBoxLayout( plugin.guiBox ); | 211 | QHBoxLayout *boxLayout = new QHBoxLayout( plugin.guiBox ); |
201 | QPixmap plugPix; | 212 | QPixmap plugPix; |
202 | plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( m_iconSize, m_iconSize ), 0 ); | 213 | plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( m_iconSize, m_iconSize ), 0 ); |
203 | OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); | 214 | OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); |
204 | plugIcon->setPixmap( plugPix ); | 215 | plugIcon->setPixmap( plugPix ); |
205 | QWhatsThis::add | 216 | QWhatsThis::add |
206 | ( plugIcon, tr("Click here to launch the associated app") ); | 217 | ( plugIcon, tr("Click here to launch the associated app") ); |
207 | plugIcon->setName( plugin.guiPart->appName() ); | 218 | plugIcon->setName( plugin.guiPart->appName() ); |
208 | connect( plugIcon, SIGNAL( clicked() ), this, SLOT( startApplication() ) ); | 219 | connect( plugIcon, SIGNAL( clicked() ), this, SLOT( startApplication() ) ); |
209 | 220 | ||
210 | QWidget *plugWidget = plugin.guiPart->widget( plugin.guiBox ); | 221 | QWidget *plugWidget = plugin.guiPart->widget( plugin.guiBox ); |
@@ -212,49 +223,49 @@ void Today::loadPlugins() { | |||
212 | boxLayout->addWidget( plugWidget, 0, AlignTop ); | 223 | boxLayout->addWidget( plugWidget, 0, AlignTop ); |
213 | boxLayout->setStretchFactor( plugIcon, 1 ); | 224 | boxLayout->setStretchFactor( plugIcon, 1 ); |
214 | boxLayout->setStretchFactor( plugWidget, 9 ); | 225 | boxLayout->setStretchFactor( plugWidget, 9 ); |
215 | 226 | ||
216 | pluginList.insert( plugin.name, plugin ); | 227 | pluginList.insert( plugin.name, plugin ); |
217 | m_bblayout->addWidget(plugin.guiBox); | 228 | m_bblayout->addWidget(plugin.guiBox); |
218 | } | 229 | } |
219 | 230 | ||
220 | m_bblayout->addStretch( 1 ); | 231 | m_bblayout->addStretch( 1 ); |
221 | } | 232 | } |
222 | 233 | ||
223 | 234 | ||
224 | /** | 235 | /** |
225 | * The method for the configuration dialog. | 236 | * The method for the configuration dialog. |
226 | */ | 237 | */ |
227 | void Today::startConfig() { | 238 | void Today::startConfig() { |
228 | 239 | ||
229 | // disconnect timer to prevent problems while being on config dialog | 240 | // disconnect timer to prevent problems while being on config dialog |
230 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 241 | disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
231 | m_refreshTimer->stop( ); | 242 | m_refreshTimer->stop( ); |
232 | 243 | ||
233 | TodayConfig conf( this, "dialog", true ); | 244 | TodayConfig conf( this, "dialog", true ); |
234 | conf.setUpPlugins( m_manager, m_pluginLoader ); | 245 | conf.setUpPlugins( m_manager, m_pluginLoader ); |
235 | 246 | ||
236 | if ( conf.exec() == QDialog::Accepted ) { | 247 | if ( QPEApplication::execDialog(&conf) == QDialog::Accepted ) { |
237 | conf.writeConfig(); | 248 | conf.writeConfig(); |
238 | initialize(); | 249 | initialize(); |
239 | } else { | 250 | } else { |
240 | // since reinitialize is not called in that case , reconnect the signal | 251 | // since reinitialize is not called in that case , reconnect the signal |
241 | m_refreshTimer->start( 15000 ); // get the config value in here later | 252 | m_refreshTimer->start( 15000 ); // get the config value in here later |
242 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); | 253 | connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); |
243 | } | 254 | } |
244 | } | 255 | } |
245 | 256 | ||
246 | 257 | ||
247 | void Today::initialize() { | 258 | void Today::initialize() { |
248 | 259 | ||
249 | Config cfg( "today" ); | 260 | Config cfg( "today" ); |
250 | cfg.setGroup( "Plugins" ); | 261 | cfg.setGroup( "Plugins" ); |
251 | 262 | ||
252 | 263 | ||
253 | cfg.setGroup( "General" ); | 264 | cfg.setGroup( "General" ); |
254 | m_iconSize = cfg.readNumEntry( "IconSize", 18 ); | 265 | m_iconSize = cfg.readNumEntry( "IconSize", 18 ); |
255 | m_hideBanner = cfg.readNumEntry( "HideBanner", 0 ); | 266 | m_hideBanner = cfg.readNumEntry( "HideBanner", 0 ); |
256 | setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); | 267 | setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); |
257 | 268 | ||
258 | // set the date in top label | 269 | // set the date in top label |
259 | QDate date = QDate::currentDate(); | 270 | QDate date = QDate::currentDate(); |
260 | DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( date ) + "</font>" ) ); | 271 | DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( date ) + "</font>" ) ); |
@@ -323,32 +334,31 @@ void Today::refresh() { | |||
323 | } | 334 | } |
324 | 335 | ||
325 | DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( QDate::currentDate() ) + "</font>" ) ); | 336 | DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( QDate::currentDate() ) + "</font>" ) ); |
326 | 337 | ||
327 | updateGeometry(); | 338 | updateGeometry(); |
328 | repaint(); | 339 | repaint(); |
329 | } | 340 | } |
330 | 341 | ||
331 | 342 | ||
332 | void Today::startApplication() { | 343 | void Today::startApplication() { |
333 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 344 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
334 | e << QString( sender()->name() ); | 345 | e << QString( sender()->name() ); |
335 | } | 346 | } |
336 | 347 | ||
337 | 348 | ||
338 | /** | 349 | /** |
339 | * launch addressbook (personal card) | 350 | * launch addressbook (personal card) |
340 | */ | 351 | */ |
341 | void Today::editCard() { | 352 | void Today::editCard() { |
342 | QCopEnvelope env( "QPE/Application/addressbook", "editPersonalAndClose()" ); | 353 | QCopEnvelope env( "QPE/Application/addressbook", "editPersonalAndClose()" ); |
343 | } | 354 | } |
344 | 355 | ||
345 | 356 | ||
346 | Today::~Today() { | 357 | Today::~Today() { |
347 | if (m_pluginLoader) { | 358 | for(QMap<QString, TodayPlugin>::Iterator it = pluginList.begin(); it != pluginList.end(); ++it ) |
348 | delete m_pluginLoader; | 359 | delete it.data().guiBox; |
349 | } | 360 | |
350 | if (m_manager) { | 361 | delete m_pluginLoader; |
351 | delete m_manager; | 362 | delete m_manager; |
352 | } | ||
353 | } | 363 | } |
354 | 364 | ||