summaryrefslogtreecommitdiff
path: root/core/pim/today/today.cpp
Unidiff
Diffstat (limited to 'core/pim/today/today.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/today/today.cpp167
1 files changed, 90 insertions, 77 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp
index 09540bd..d78b5b5 100644
--- a/core/pim/today/today.cpp
+++ b/core/pim/today/today.cpp
@@ -11,73 +11,85 @@
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 <qtabwidget.h> 36#include <qtabwidget.h>
36#include <qdialog.h> 37#include <qdialog.h>
37 38
38 39
40struct TodayPlugin {
41 QLibrary *library;
42 TodayPluginInterface *iface;
43 TodayPluginObject *guiPart;
44 QHBox *guiBox;
45 QString name;
46 bool active;
47 int pos;
48};
49
39static QValueList<TodayPlugin> pluginList; 50static QValueList<TodayPlugin> pluginList;
40 51
41Today::Today( QWidget* parent, const char* name, WFlags fl ) 52Today::Today( QWidget* parent, const char* name, WFlags fl )
42 : TodayBase( parent, name, fl ) { 53 : TodayBase( parent, name, fl ) {
43 54
44 QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); 55 QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) );
45 QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); 56 QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) );
46 57
47#if defined(Q_WS_QWS) 58#if defined(Q_WS_QWS)
48#if !defined(QT_NO_COP) 59#if !defined(QT_NO_COP)
49 QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); 60 QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this );
50 connect ( todayChannel, SIGNAL( received( const QCString &, const QByteArray &) ), 61 connect ( todayChannel, SIGNAL( received( const QCString &, const QByteArray &) ),
51 this, SLOT ( channelReceived( const QCString &, const QByteArray &) ) ); 62 this, SLOT ( channelReceived( const QCString &, const QByteArray &) ) );
52#endif 63#endif
53#endif 64#endif
54 65
55 pluginLayout = 0l; 66 // pluginLayout = 0l;
56 67
57 setOwnerField(); 68 setOwnerField();
58 init(); 69 init();
59 refresh(); 70 loadPlugins();
71 draw();
60 showMaximized(); 72 showMaximized();
61} 73}
62 74
63/** 75/**
64 * Qcop receive method. 76 * Qcop receive method.
65 */ 77 */
66void Today::channelReceived( const QCString &msg, const QByteArray & data ) { 78void Today::channelReceived( const QCString &msg, const QByteArray & data ) {
67 QDataStream stream( data, IO_ReadOnly ); 79 QDataStream stream( data, IO_ReadOnly );
68 if ( msg == "message(QString)" ) { 80 if ( msg == "message(QString)" ) {
69 QString message; 81 QString message;
70 stream >> message; 82 stream >> message;
71 setOwnerField( message ); 83 setOwnerField( message );
72 } 84 }
73} 85}
74 86
75/** 87/**
76 * Initialises the owner field with the default value, the username 88 * Initialises the owner field with the default value, the username
77 */ 89 */
78void Today::setOwnerField() { 90void Today::setOwnerField() {
79 QString file = Global::applicationFileName( "addressbook", "businesscard.vcf" ); 91 QString file = Global::applicationFileName( "addressbook", "businesscard.vcf" );
80 if ( QFile::exists( file ) ) { 92 if ( QFile::exists( file ) ) {
81 Contact cont = Contact::readVCard( file )[0]; 93 Contact cont = Contact::readVCard( file )[0];
82 QString returnString = cont.fullName(); 94 QString returnString = cont.fullName();
83 OwnerField->setText( "<b>" + tr ( "Owned by " ) + returnString + "</b>" ); 95 OwnerField->setText( "<b>" + tr ( "Owned by " ) + returnString + "</b>" );
@@ -103,196 +115,197 @@ void Today::init() {
103 115
104 QDate date = QDate::currentDate(); 116 QDate date = QDate::currentDate();
105 QString time = ( tr( date.toString() ) ); 117 QString time = ( tr( date.toString() ) );
106 118
107 DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) ); 119 DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) );
108 120
109 // read config 121 // read config
110 Config cfg( "today" ); 122 Config cfg( "today" );
111 123
112 cfg.setGroup( "Applets" ); 124 cfg.setGroup( "Applets" );
113 m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); 125 m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' );
114} 126}
115 127
116 128
117/** 129/**
118 * Load the plugins 130 * Load the plugins
119 */ 131 */
120void Today::loadPlugins() { 132void Today::loadPlugins() {
121 133
122 QValueList<TodayPlugin>::Iterator tit; 134 QValueList<TodayPlugin>::Iterator tit;
123 for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) { 135 for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) {
124 (*tit).library->unload(); 136 (*tit).library->unload();
125 delete (*tit).library; 137 delete (*tit).library;
126 } 138 }
139 pluginList.clear();
127 140
128 QString path = QPEApplication::qpeDir() + "/plugins/today"; 141 QString path = QPEApplication::qpeDir() + "/plugins/today";
129 QDir dir( path, "lib*.so" ); 142 QDir dir( path, "lib*.so" );
130 143
131 QStringList list = dir.entryList(); 144 QStringList list = dir.entryList();
132 QStringList::Iterator it; 145 QStringList::Iterator it;
133 146
134 uint count = 0; 147 uint count = 0;
135 for ( it = list.begin(); it != list.end(); ++it ) { 148 for ( it = list.begin(); it != list.end(); ++it ) {
136 TodayPluginInterface *iface = 0; 149 TodayPluginInterface *iface = 0;
137 QLibrary *lib = new QLibrary( path + "/" + *it ); 150 QLibrary *lib = new QLibrary( path + "/" + *it );
138 151
139 qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); 152 qDebug( "querying: %s", QString( path + "/" + *it ).latin1() );
140 if ( lib->queryInterface( IID_TodayPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) { 153 if ( lib->queryInterface( IID_TodayPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) {
141 qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); 154 qDebug( "loading: %s", QString( path + "/" + *it ).latin1() );
142 qDebug( QString(*it).latin1() ); 155 qDebug( QString(*it) );
143 TodayPlugin plugin; 156 TodayPlugin plugin;
144 plugin.library = lib; 157 plugin.library = lib;
145 plugin.iface = iface; 158 plugin.iface = iface;
146 plugin.name = QString(*it).latin1(); 159 plugin.name = QString(*it);
147 160
148 if ( m_excludeApplets.grep( *it ).isEmpty() ) { 161 if ( m_excludeApplets.grep( *it ).isEmpty() ) {
149 plugin.active = true; 162 plugin.active = true;
150 } else { 163 } else {
151 plugin.active = false; 164 plugin.active = false;
152 } 165 }
153 plugin.guiPart = plugin.iface->guiPart(); 166 plugin.guiPart = plugin.iface->guiPart();
167
168 plugin.guiBox = new QHBox( this );
169 QPixmap plugPix;
170 plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( 18, 18 ), 0 );
171 OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox );
172 plugIcon->setPixmap( plugPix );
173 QScrollView* sv = new QScrollView( plugin.guiBox );
174 QWidget *plugWidget = plugin.guiPart->widget( sv->viewport() );
175 sv->setMinimumHeight( plugin.guiPart->minHeight() );
176 //sv->setMaximumHeight( plugin.guiPart->maxHeight() );
177 sv->setResizePolicy( QScrollView::AutoOneFit );
178 sv->setHScrollBarMode( QScrollView::AlwaysOff );
179 sv->setFrameShape( QFrame::NoFrame );
180 sv->addChild( plugWidget );
181
182 //plugin.guiBox->addWidget( plugIcon, 0, AlignTop );
183 //plugin.guiBox->addWidget( sv, 0, AlignTop );
184 plugin.guiBox->setStretchFactor( plugIcon, 1 );
185 plugin.guiBox->setStretchFactor( sv, 9 );
186 layout->addWidget( plugin.guiBox );
187
154 pluginList.append( plugin ); 188 pluginList.append( plugin );
155 count++; 189 count++;
156 } else { 190 } else {
157 qDebug( "could not recognize %s", QString( path + "/" + *it ).latin1() ); 191 qDebug( "could not recognize %s", QString( path + "/" + *it ).latin1() );
158 delete lib; 192 delete lib;
159 } 193 }
160 } 194 }
161} 195}
162 196
163 197
164/** 198/**
165 * Repaint method. Reread all fields. 199 * Repaint method. Reread all fields.
166 */ 200 */
167void Today::draw() { 201void Today::draw() {
168 202
169 if ( pluginLayout ) {
170 delete pluginLayout;
171 }
172 pluginLayout = new QVBoxLayout( layout );
173
174 if ( pluginList.count() == 0 ) { 203 if ( pluginList.count() == 0 ) {
175 QLabel *noPlugins = new QLabel( this ); 204 QLabel *noPlugins = new QLabel( this );
176 noPlugins->setText( tr( "No plugins found" ) ); 205 noPlugins->setText( tr( "No plugins found" ) );
177 layout->addWidget( noPlugins ); 206 layout->addWidget( noPlugins );
178 return; 207 return;
179 } 208 }
180 209
181 uint count = 0; 210 uint count = 0;
182 TodayPlugin plugin; 211 TodayPlugin plugin;
183 for ( uint i = 0; i < pluginList.count(); i++ ) { 212 for ( uint i = 0; i < pluginList.count(); i++ ) {
184 plugin = pluginList[i]; 213 plugin = pluginList[i];
185 214
186 if ( plugin.active ) { 215 if ( plugin.active ) {
187 QHBoxLayout* plugLayout = new QHBoxLayout( this ); 216 qDebug( plugin.name + " is ACTIVE " );
188 QPixmap plugPix; 217 // QHBoxLayout* plugLayout = new QHBoxLayout( this );
189 plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( 18, 18 ), 0 ); 218 plugin.guiBox->show();
190 OClickableLabel* plugIcon = new OClickableLabel( this ); 219 } else {
191 plugIcon->setPixmap( plugPix ); 220 // plugin.guiWidget->hide();
192 QScrollView* sv = new QScrollView( this ); 221 qDebug( plugin.name + " is INACTIVE" );
193 QWidget* plugWidget = plugin.guiPart->widget( sv->viewport() ); 222 plugin.guiBox->hide();
194 // plugWidget->reparent( sv->viewport(), QPoint( 0, 0 ) ); 223 }
195 sv->setMinimumHeight( plugin.guiPart->minHeight() ); 224 count++;
196 //sv->setMaximumHeight( plugin.guiPart->maxHeight() );
197
198 sv->setResizePolicy( QScrollView::AutoOneFit );
199 sv->setHScrollBarMode( QScrollView::AlwaysOff );
200 sv->setFrameShape( QFrame::NoFrame );
201 sv->addChild( plugWidget );
202
203 plugLayout->addWidget( plugIcon, 0, AlignTop );
204 plugLayout->addWidget( sv, 0, AlignTop );
205 plugLayout->setStretchFactor( plugIcon, 1 );
206 plugLayout->setStretchFactor( sv, 9 );
207 pluginLayout->addLayout( plugLayout );
208 count++;
209 }
210 } 225 }
211 226
212 if ( count == 0 ) { 227 if ( count == 0 ) {
213 QLabel *noPluginsActive = new QLabel( this ); 228 QLabel *noPluginsActive = new QLabel( this );
214 noPluginsActive->setText( tr( "No plugins activated" ) ); 229 noPluginsActive->setText( tr( "No plugins activated" ) );
215 layout->addWidget( noPluginsActive ); 230 layout->addWidget( noPluginsActive );
216 } 231 }
217 232
218 layout->addItem( new QSpacerItem( 1,1, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 233 layout->addItem( new QSpacerItem( 1,1, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
219
220
221 // how often refresh - later have qcop update calls in *db
222 // QTimer::singleShot( 20*1000, this, SLOT( draw() ) );
223}
224
225
226void Today::refresh() {
227 loadPlugins();
228 draw();
229 qDebug( "redraw" );
230// QTimer::singleShot( 30*1000, this, SLOT( refresh() ) );
231} 234}
232 235
233 236
234/** 237/**
235 * The method for the configuration dialog. 238 * The method for the configuration dialog.
236 */ 239 */
237void Today::startConfig() { 240void Today::startConfig() {
238 conf = new TodayConfig ( this, "", true ); 241
239 242 TodayConfig conf( this, "dialog", true );
240 uint count = 0; 243
241 TodayPlugin plugin; 244 TodayPlugin plugin;
242 245
243 QList<ConfigWidget> configWidgetList; 246 QList<ConfigWidget> configWidgetList;
244 for ( uint i = 0; i < pluginList.count(); i++ ) { 247 for ( uint i = 0; i < pluginList.count(); i++ ) {
245 plugin = pluginList[i]; 248 plugin = pluginList[i];
246 249
247 // load the config widgets in the tabs 250 // load the config widgets in the tabs
248 if ( plugin.guiPart->configWidget( this ) != 0l ) { 251 if ( plugin.guiPart->configWidget( this ) != 0l ) {
249 ConfigWidget* widget = plugin.guiPart->configWidget( this ); 252 ConfigWidget* widget = plugin.guiPart->configWidget( this );
250 widget->reparent( conf , QPoint( 0,0 ) ); 253 configWidgetList.append( widget );
251 configWidgetList.append( widget ); 254 conf.TabWidget3->insertTab( widget, plugin.guiPart->appName() );
252 conf->TabWidget3->insertTab( widget, plugin.guiPart->appName() ); 255 }
253 } 256 // set the order/activate tab
254 // set the order/activate tab 257 conf.pluginManagement( plugin.name, plugin.guiPart->pluginName(),
255 conf->pluginManagement( plugin.name, plugin.guiPart->pluginName(),
256 Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) ); 258 Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) );
257 count++; 259 }
258 }
259 260
260 conf->showMaximized(); 261 conf.exec();
262 if ( conf.exec() == QDialog::Accepted ) {
263 conf.writeConfig();
264 ConfigWidget *confWidget;
265 for ( confWidget = configWidgetList.first(); confWidget != 0;
266 confWidget = configWidgetList.next() ) {
267 confWidget->writeConfig();
268 }
269 init();
261 270
262 if ( conf->exec() == QDialog::Accepted ) {
263 ConfigWidget *confWidget;
264 for ( confWidget=configWidgetList.first(); confWidget != 0;
265 confWidget = configWidgetList.next() ) {
266 confWidget->writeConfig();
267 }
268 conf->writeConfig();
269 271
270 init(); 272 TodayPlugin plugin;
271 loadPlugins(); 273 for ( uint i = 0; i < pluginList.count(); i++ ) {
272 draw(); 274 plugin = pluginList[i];
273 } 275
274 delete conf; 276 if ( m_excludeApplets.grep( plugin.name ).isEmpty() ) {
277 qDebug("CONFIG" + plugin.name + "ACTIVE");
278 plugin.active = true;
279 } else {
280 qDebug("CONFIG" + plugin.name + "INACTIVE");
281
282 plugin.active = false;
283 }
284 }
285
286 draw();
287 }
275} 288}
276 289
277 290
278void Today::startAddressbook() { 291void Today::startAddressbook() {
279 QCopEnvelope e( "QPE/System", "execute(QString)" ); 292 QCopEnvelope e( "QPE/System", "execute(QString)" );
280 e << QString( "addressbook" ); 293 e << QString( "addressbook" );
281} 294}
282 295
283 296
284/** 297/**
285 * launch addressbook (personal card) 298 * launch addressbook (personal card)
286 */ 299 */
287void Today::editCard() { 300void Today::editCard() {
288 startAddressbook(); 301 startAddressbook();
289 while( !QCopChannel::isRegistered( "QPE/Addressbook" ) ) { 302 while( !QCopChannel::isRegistered( "QPE/Addressbook" ) ) {
290 qApp->processEvents(); 303 qApp->processEvents();
291 } 304 }
292 QCopEnvelope v( "QPE/Addressbook", "editPersonalAndClose()" ); 305 QCopEnvelope v( "QPE/Addressbook", "editPersonalAndClose()" );
293} 306}
294 307
295/* 308/*
296 * launches an App 309 * launches an App
297 */ 310 */
298void Today::launchApp( QString appName ) { 311void Today::launchApp( QString appName ) {