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