-rw-r--r-- | core/pim/today/today.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index 2095174..f052a9f 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp | |||
@@ -1,281 +1,285 @@ | |||
1 | /* | 1 | /* |
2 | * today.cpp | 2 | * today.cpp |
3 | * | 3 | * |
4 | * copyright : (c) 2002 by Maximilian Reiß | 4 | * copyright : (c) 2002 by Maximilian Reiß |
5 | * email : harlekin@handhelds.org | 5 | * email : harlekin@handhelds.org |
6 | * | 6 | * |
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 | 17 | ||
18 | #include "today.h" | 18 | #include "today.h" |
19 | #include "configwidget.h" | 19 | #include "configwidget.h" |
20 | 20 | ||
21 | #include <qpe/config.h> | 21 | #include <qpe/config.h> |
22 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/global.h> | 24 | #include <qpe/global.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 <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qlabel.h> | 31 | #include <qlabel.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | #include <qpixmap.h> | 33 | #include <qpixmap.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qhbox.h> | 35 | #include <qhbox.h> |
36 | #include <qtabwidget.h> | 36 | #include <qtabwidget.h> |
37 | #include <qdialog.h> | 37 | #include <qdialog.h> |
38 | 38 | ||
39 | 39 | ||
40 | struct TodayPlugin { | 40 | struct TodayPlugin { |
41 | QLibrary *library; | 41 | QLibrary *library; |
42 | TodayPluginInterface *iface; | 42 | TodayPluginInterface *iface; |
43 | TodayPluginObject *guiPart; | 43 | TodayPluginObject *guiPart; |
44 | QHBox *guiBox; | 44 | QWidget *guiBox; |
45 | QString name; | 45 | QString name; |
46 | bool active; | 46 | bool active; |
47 | int pos; | 47 | int pos; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | static QValueList<TodayPlugin> pluginList; | 50 | static QValueList<TodayPlugin> pluginList; |
51 | 51 | ||
52 | Today::Today( QWidget* parent, const char* name, WFlags fl ) | 52 | Today::Today( QWidget* parent, const char* name, WFlags fl ) |
53 | : TodayBase( parent, name, fl ) { | 53 | : TodayBase( parent, name, fl ) { |
54 | 54 | ||
55 | QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); | 55 | QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); |
56 | QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); | 56 | QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); |
57 | 57 | ||
58 | #if defined(Q_WS_QWS) | 58 | #if defined(Q_WS_QWS) |
59 | #if !defined(QT_NO_COP) | 59 | #if !defined(QT_NO_COP) |
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 | 64 | #endif |
65 | 65 | ||
66 | // pluginLayout = 0l; | ||
67 | |||
68 | setOwnerField(); | 66 | setOwnerField(); |
69 | init(); | 67 | init(); |
70 | loadPlugins(); | 68 | loadPlugins(); |
71 | draw(); | 69 | draw(); |
72 | showMaximized(); | 70 | showMaximized(); |
73 | } | 71 | } |
74 | 72 | ||
75 | /** | 73 | /** |
76 | * Qcop receive method. | 74 | * Qcop receive method. |
77 | */ | 75 | */ |
78 | void Today::channelReceived( const QCString &msg, const QByteArray & data ) { | 76 | void Today::channelReceived( const QCString &msg, const QByteArray & data ) { |
79 | QDataStream stream( data, IO_ReadOnly ); | 77 | QDataStream stream( data, IO_ReadOnly ); |
80 | if ( msg == "message(QString)" ) { | 78 | if ( msg == "message(QString)" ) { |
81 | QString message; | 79 | QString message; |
82 | stream >> message; | 80 | stream >> message; |
83 | setOwnerField( message ); | 81 | setOwnerField( message ); |
84 | } | 82 | } |
85 | } | 83 | } |
86 | 84 | ||
87 | /** | 85 | /** |
88 | * Initialises the owner field with the default value, the username | 86 | * Initialises the owner field with the default value, the username |
89 | */ | 87 | */ |
90 | void Today::setOwnerField() { | 88 | void Today::setOwnerField() { |
91 | QString file = Global::applicationFileName( "addressbook", "businesscard.vcf" ); | 89 | QString file = Global::applicationFileName( "addressbook", "businesscard.vcf" ); |
92 | if ( QFile::exists( file ) ) { | 90 | if ( QFile::exists( file ) ) { |
93 | Contact cont = Contact::readVCard( file )[0]; | 91 | Contact cont = Contact::readVCard( file )[0]; |
94 | QString returnString = cont.fullName(); | 92 | QString returnString = cont.fullName(); |
95 | OwnerField->setText( "<b>" + tr ( "Owned by " ) + returnString + "</b>" ); | 93 | OwnerField->setText( "<b>" + tr ( "Owned by " ) + returnString + "</b>" ); |
96 | } else { | 94 | } else { |
97 | OwnerField->setText( "<b>" + tr ( "Please fill out the business card" ) + " </b>" ); | 95 | OwnerField->setText( "<b>" + tr ( "Please fill out the business card" ) + " </b>" ); |
98 | } | 96 | } |
99 | } | 97 | } |
100 | 98 | ||
101 | /** | 99 | /** |
102 | * Set the owner field with a given QString, for example per qcop. | 100 | * Set the owner field with a given QString, for example per qcop. |
103 | */ | 101 | */ |
104 | void Today::setOwnerField( QString &message ) { | 102 | void Today::setOwnerField( QString &message ) { |
105 | if ( !message.isEmpty() ) { | 103 | if ( !message.isEmpty() ) { |
106 | OwnerField->setText( "<b>" + message + "</b>" ); | 104 | OwnerField->setText( "<b>" + message + "</b>" ); |
107 | } | 105 | } |
108 | } | 106 | } |
109 | 107 | ||
110 | 108 | ||
111 | /** | 109 | /** |
112 | * Init stuff needed for today. Reads the config file. | 110 | * Init stuff needed for today. Reads the config file. |
113 | */ | 111 | */ |
114 | void Today::init() { | 112 | void Today::init() { |
115 | 113 | ||
116 | QDate date = QDate::currentDate(); | 114 | QDate date = QDate::currentDate(); |
117 | QString time = ( tr( date.toString() ) ); | 115 | QString time = ( tr( date.toString() ) ); |
118 | 116 | ||
119 | DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) ); | 117 | DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) ); |
120 | 118 | ||
121 | // read config | 119 | // read config |
122 | Config cfg( "today" ); | 120 | Config cfg( "today" ); |
123 | 121 | ||
124 | cfg.setGroup( "Applets" ); | 122 | cfg.setGroup( "Applets" ); |
125 | m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); | 123 | m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); |
126 | } | 124 | } |
127 | 125 | ||
128 | 126 | ||
129 | /** | 127 | /** |
130 | * Load the plugins | 128 | * Load the plugins |
131 | */ | 129 | */ |
132 | void Today::loadPlugins() { | 130 | void Today::loadPlugins() { |
133 | 131 | ||
134 | QValueList<TodayPlugin>::Iterator tit; | 132 | QValueList<TodayPlugin>::Iterator tit; |
135 | for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) { | 133 | for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) { |
136 | (*tit).library->unload(); | 134 | (*tit).library->unload(); |
137 | delete (*tit).library; | 135 | delete (*tit).library; |
138 | } | 136 | } |
139 | pluginList.clear(); | 137 | pluginList.clear(); |
140 | 138 | ||
141 | QString path = QPEApplication::qpeDir() + "/plugins/today"; | 139 | QString path = QPEApplication::qpeDir() + "/plugins/today"; |
142 | QDir dir( path, "lib*.so" ); | 140 | QDir dir( path, "lib*.so" ); |
143 | 141 | ||
144 | QStringList list = dir.entryList(); | 142 | QStringList list = dir.entryList(); |
145 | QStringList::Iterator it; | 143 | QStringList::Iterator it; |
146 | 144 | ||
147 | uint count = 0; | 145 | uint count = 0; |
148 | for ( it = list.begin(); it != list.end(); ++it ) { | 146 | for ( it = list.begin(); it != list.end(); ++it ) { |
149 | TodayPluginInterface *iface = 0; | 147 | TodayPluginInterface *iface = 0; |
150 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 148 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
151 | 149 | ||
152 | qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); | 150 | qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); |
153 | if ( lib->queryInterface( IID_TodayPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) { | 151 | if ( lib->queryInterface( IID_TodayPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) { |
154 | qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); | 152 | qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); |
155 | qDebug( QString(*it) ); | 153 | qDebug( QString(*it) ); |
156 | TodayPlugin plugin; | 154 | TodayPlugin plugin; |
157 | plugin.library = lib; | 155 | plugin.library = lib; |
158 | plugin.iface = iface; | 156 | plugin.iface = iface; |
159 | plugin.name = QString(*it); | 157 | plugin.name = QString(*it); |
160 | 158 | ||
161 | if ( m_excludeApplets.grep( *it ).isEmpty() ) { | 159 | if ( m_excludeApplets.grep( *it ).isEmpty() ) { |
162 | plugin.active = true; | 160 | plugin.active = true; |
163 | } else { | 161 | } else { |
164 | plugin.active = false; | 162 | plugin.active = false; |
165 | } | 163 | } |
166 | plugin.guiPart = plugin.iface->guiPart(); | 164 | plugin.guiPart = plugin.iface->guiPart(); |
167 | 165 | ||
168 | plugin.guiBox = new QHBox( this ); | 166 | // package the whole thing into a qwidget so it can be shown and hidden |
167 | plugin.guiBox = new QWidget( this ); | ||
168 | QHBoxLayout *boxLayout = new QHBoxLayout( plugin.guiBox ); | ||
169 | |||
169 | QPixmap plugPix; | 170 | QPixmap plugPix; |
170 | plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( 18, 18 ), 0 ); | 171 | plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( 18, 18 ), 0 ); |
171 | OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); | 172 | OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); |
172 | plugIcon->setPixmap( plugPix ); | 173 | plugIcon->setPixmap( plugPix ); |
174 | |||
175 | // a scrollview for each plugin | ||
173 | QScrollView* sv = new QScrollView( plugin.guiBox ); | 176 | QScrollView* sv = new QScrollView( plugin.guiBox ); |
174 | QWidget *plugWidget = plugin.guiPart->widget( sv->viewport() ); | 177 | QWidget *plugWidget = plugin.guiPart->widget( sv->viewport() ); |
175 | sv->setMinimumHeight( plugin.guiPart->minHeight() ); | 178 | sv->setMinimumHeight( plugin.guiPart->minHeight() ); |
176 | //sv->setMaximumHeight( plugin.guiPart->maxHeight() ); | 179 | //sv->setMaximumHeight( plugin.guiPart->maxHeight() ); |
177 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 180 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
178 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 181 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
179 | sv->setFrameShape( QFrame::NoFrame ); | 182 | sv->setFrameShape( QFrame::NoFrame ); |
180 | sv->addChild( plugWidget ); | 183 | sv->addChild( plugWidget ); |
181 | 184 | ||
182 | //plugin.guiBox->addWidget( plugIcon, 0, AlignTop ); | 185 | // make sure the icon is on the top alligned |
183 | //plugin.guiBox->addWidget( sv, 0, AlignTop ); | 186 | boxLayout->addWidget( plugIcon, 0, AlignTop ); |
184 | plugin.guiBox->setStretchFactor( plugIcon, 1 ); | 187 | boxLayout->addWidget( sv, 0, AlignTop ); |
185 | plugin.guiBox->setStretchFactor( sv, 9 ); | 188 | boxLayout->setStretchFactor( plugIcon, 1 ); |
189 | boxLayout->setStretchFactor( sv, 9 ); | ||
186 | layout->addWidget( plugin.guiBox ); | 190 | layout->addWidget( plugin.guiBox ); |
187 | 191 | ||
188 | pluginList.append( plugin ); | 192 | pluginList.append( plugin ); |
189 | count++; | 193 | count++; |
190 | } else { | 194 | } else { |
191 | qDebug( "could not recognize %s", QString( path + "/" + *it ).latin1() ); | 195 | qDebug( "could not recognize %s", QString( path + "/" + *it ).latin1() ); |
192 | delete lib; | 196 | delete lib; |
193 | } | 197 | } |
194 | } | 198 | } |
195 | } | 199 | } |
196 | 200 | ||
197 | 201 | ||
198 | /** | 202 | /** |
199 | * Repaint method. Reread all fields. | 203 | * Repaint method. Reread all fields. |
200 | */ | 204 | */ |
201 | void Today::draw() { | 205 | void Today::draw() { |
202 | 206 | ||
203 | if ( pluginList.count() == 0 ) { | 207 | if ( pluginList.count() == 0 ) { |
204 | QLabel *noPlugins = new QLabel( this ); | 208 | QLabel *noPlugins = new QLabel( this ); |
205 | noPlugins->setText( tr( "No plugins found" ) ); | 209 | noPlugins->setText( tr( "No plugins found" ) ); |
206 | layout->addWidget( noPlugins ); | 210 | layout->addWidget( noPlugins ); |
207 | return; | 211 | return; |
208 | } | 212 | } |
209 | 213 | ||
210 | uint count = 0; | 214 | uint count = 0; |
211 | TodayPlugin plugin; | 215 | TodayPlugin plugin; |
212 | for ( uint i = 0; i < pluginList.count(); i++ ) { | 216 | for ( uint i = 0; i < pluginList.count(); i++ ) { |
213 | plugin = pluginList[i]; | 217 | plugin = pluginList[i]; |
214 | 218 | ||
215 | if ( plugin.active ) { | 219 | if ( plugin.active ) { |
216 | qDebug( plugin.name + " is ACTIVE " ); | 220 | qDebug( plugin.name + " is ACTIVE " ); |
217 | plugin.guiBox->show(); | 221 | plugin.guiBox->show(); |
218 | } else { | 222 | } else { |
219 | qDebug( plugin.name + " is INACTIVE" ); | 223 | qDebug( plugin.name + " is INACTIVE" ); |
220 | plugin.guiBox->hide(); | 224 | plugin.guiBox->hide(); |
221 | } | 225 | } |
222 | count++; | 226 | count++; |
223 | } | 227 | } |
224 | 228 | ||
225 | if ( count == 0 ) { | 229 | if ( count == 0 ) { |
226 | QLabel *noPluginsActive = new QLabel( this ); | 230 | QLabel *noPluginsActive = new QLabel( this ); |
227 | noPluginsActive->setText( tr( "No plugins activated" ) ); | 231 | noPluginsActive->setText( tr( "No plugins activated" ) ); |
228 | layout->addWidget( noPluginsActive ); | 232 | layout->addWidget( noPluginsActive ); |
229 | } | 233 | } |
230 | 234 | ||
231 | layout->addItem( new QSpacerItem( 1,1, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 235 | layout->addItem( new QSpacerItem( 1,1, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
232 | } | 236 | } |
233 | 237 | ||
234 | 238 | ||
235 | /** | 239 | /** |
236 | * The method for the configuration dialog. | 240 | * The method for the configuration dialog. |
237 | */ | 241 | */ |
238 | void Today::startConfig() { | 242 | void Today::startConfig() { |
239 | 243 | ||
240 | TodayConfig conf( this, "dialog", true ); | 244 | TodayConfig conf( this, "dialog", true ); |
241 | 245 | ||
242 | TodayPlugin plugin; | 246 | TodayPlugin plugin; |
243 | 247 | ||
244 | QList<ConfigWidget> configWidgetList; | 248 | QList<ConfigWidget> configWidgetList; |
245 | for ( uint i = 0; i < pluginList.count(); i++ ) { | 249 | for ( uint i = 0; i < pluginList.count(); i++ ) { |
246 | plugin = pluginList[i]; | 250 | plugin = pluginList[i]; |
247 | 251 | ||
248 | // load the config widgets in the tabs | 252 | // load the config widgets in the tabs |
249 | if ( plugin.guiPart->configWidget( this ) != 0l ) { | 253 | if ( plugin.guiPart->configWidget( this ) != 0l ) { |
250 | ConfigWidget* widget = plugin.guiPart->configWidget( this ); | 254 | ConfigWidget* widget = plugin.guiPart->configWidget( this ); |
251 | configWidgetList.append( widget ); | 255 | configWidgetList.append( widget ); |
252 | conf.TabWidget3->insertTab( widget, plugin.guiPart->appName() ); | 256 | conf.TabWidget3->insertTab( widget, plugin.guiPart->appName() ); |
253 | } | 257 | } |
254 | // set the order/activate tab | 258 | // set the order/activate tab |
255 | conf.pluginManagement( plugin.name, plugin.guiPart->pluginName(), | 259 | conf.pluginManagement( plugin.name, plugin.guiPart->pluginName(), |
256 | Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) ); | 260 | Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) ); |
257 | } | 261 | } |
258 | 262 | ||
259 | if ( conf.exec() == QDialog::Accepted ) { | 263 | if ( conf.exec() == QDialog::Accepted ) { |
260 | conf.writeConfig(); | 264 | conf.writeConfig(); |
261 | ConfigWidget *confWidget; | 265 | ConfigWidget *confWidget; |
262 | for ( confWidget = configWidgetList.first(); confWidget != 0; | 266 | for ( confWidget = configWidgetList.first(); confWidget != 0; |
263 | confWidget = configWidgetList.next() ) { | 267 | confWidget = configWidgetList.next() ) { |
264 | confWidget->writeConfig(); | 268 | confWidget->writeConfig(); |
265 | } | 269 | } |
266 | 270 | ||
267 | init(); | 271 | init(); |
268 | 272 | ||
269 | TodayPlugin plugin; | 273 | TodayPlugin plugin; |
270 | QValueList<TodayPlugin> plugList; | 274 | QValueList<TodayPlugin> plugList; |
271 | for ( uint i = 0; i < pluginList.count(); i++ ) { | 275 | for ( uint i = 0; i < pluginList.count(); i++ ) { |
272 | plugin = pluginList[i]; | 276 | plugin = pluginList[i]; |
273 | 277 | ||
274 | if ( m_excludeApplets.grep( plugin.name ).isEmpty() ) { | 278 | if ( m_excludeApplets.grep( plugin.name ).isEmpty() ) { |
275 | qDebug("CONFIG " + plugin.name + " ACTIVE"); | 279 | qDebug("CONFIG " + plugin.name + " ACTIVE"); |
276 | plugin.active = true; | 280 | plugin.active = true; |
277 | } else { | 281 | } else { |
278 | qDebug("CONFIG " + plugin.name + " INACTIVE"); | 282 | qDebug("CONFIG " + plugin.name + " INACTIVE"); |
279 | plugin.active = false; | 283 | plugin.active = false; |
280 | } | 284 | } |
281 | plugList.append( plugin ); | 285 | plugList.append( plugin ); |