summaryrefslogtreecommitdiff
authorchicken <chicken>2004-03-01 15:44:36 (UTC)
committer chicken <chicken>2004-03-01 15:44:36 (UTC)
commitc50e4c32d34a0550f167480b6306aac632fb201c (patch) (unidiff)
treea0795fa171d7410624717f120d1bd17f6c8f3224
parent01abceaeb00bc35fa9bf5792eb51aa70b68f110d (diff)
downloadopie-c50e4c32d34a0550f167480b6306aac632fb201c.zip
opie-c50e4c32d34a0550f167480b6306aac632fb201c.tar.gz
opie-c50e4c32d34a0550f167480b6306aac632fb201c.tar.bz2
fix includes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/colordialog.cpp2
-rw-r--r--libopie/colorpopupmenu.cpp1
-rw-r--r--libopie/ocheckitem.cpp1
-rw-r--r--libopie/ocolorbutton.cpp3
-rw-r--r--libopie/odevice.cpp1
-rw-r--r--libopie/odevicebutton.cpp2
-rw-r--r--libopie/ofiledialog.cc3
-rw-r--r--libopie/ofileselector.cpp5
-rw-r--r--libopie/ofontselector.cpp1
-rw-r--r--libopie/oprocctrl.cpp1
-rw-r--r--libopie/oprocess.cpp1
-rw-r--r--libopie/orecurrancewidget.cpp2
-rw-r--r--libopie/oticker.cpp9
-rw-r--r--libopie/otimepicker.cpp3
-rw-r--r--libopie/owait.cpp2
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.cpp5
-rw-r--r--libopie/pim/otodo.cpp3
17 files changed, 4 insertions, 41 deletions
diff --git a/libopie/colordialog.cpp b/libopie/colordialog.cpp
index c7421ec..d46da41 100644
--- a/libopie/colordialog.cpp
+++ b/libopie/colordialog.cpp
@@ -1,435 +1,433 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of OColorDialog class 4** Implementation of OColorDialog class
5** 5**
6** Created : 990222 6** Created : 990222
7** 7**
8** Copyright (C) 1999-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the dialogs module of the Qt GUI Toolkit. 10** This file is part of the dialogs module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "colordialog.h" 38#include "colordialog.h"
39 39
40#include "qpainter.h" 40#include "qpainter.h"
41#include "qlayout.h" 41#include "qlayout.h"
42#include "qlabel.h" 42#include "qlabel.h"
43#include "qpushbutton.h" 43#include "qpushbutton.h"
44#include "qlineedit.h" 44#include "qlineedit.h"
45#include "qimage.h" 45#include "qimage.h"
46#include "qpixmap.h" 46#include "qpixmap.h"
47#include "qdrawutil.h" 47#include "qdrawutil.h"
48#include "qvalidator.h" 48#include "qvalidator.h"
49#include "qdragobject.h"
50#include "qapplication.h" 49#include "qapplication.h"
51#include "qdragobject.h"
52 50
53static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) 51static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
54{ 52{
55 QColor c; 53 QColor c;
56 c.setRgb( rgb ); 54 c.setRgb( rgb );
57 c.getHsv(h,s,v); 55 c.getHsv(h,s,v);
58} 56}
59 57
60/* 58/*
61 * avoid clashes with the original Qt 59 * avoid clashes with the original Qt
62 */ 60 */
63namespace { 61namespace {
64 62
65class QColorPicker : public QFrame 63class QColorPicker : public QFrame
66{ 64{
67 Q_OBJECT 65 Q_OBJECT
68public: 66public:
69 QColorPicker(QWidget* parent=0, const char* name=0); 67 QColorPicker(QWidget* parent=0, const char* name=0);
70 ~QColorPicker(); 68 ~QColorPicker();
71 69
72public slots: 70public slots:
73 void setCol( int h, int s ); 71 void setCol( int h, int s );
74 72
75signals: 73signals:
76 void newCol( int h, int s ); 74 void newCol( int h, int s );
77 75
78protected: 76protected:
79 QSize sizeHint() const; 77 QSize sizeHint() const;
80 QSizePolicy sizePolicy() const; 78 QSizePolicy sizePolicy() const;
81 void drawContents(QPainter* p); 79 void drawContents(QPainter* p);
82 void mouseMoveEvent( QMouseEvent * ); 80 void mouseMoveEvent( QMouseEvent * );
83 void mousePressEvent( QMouseEvent * ); 81 void mousePressEvent( QMouseEvent * );
84 82
85private: 83private:
86 int hue; 84 int hue;
87 int sat; 85 int sat;
88 86
89 QPoint colPt(); 87 QPoint colPt();
90 int huePt( const QPoint &pt ); 88 int huePt( const QPoint &pt );
91 int satPt( const QPoint &pt ); 89 int satPt( const QPoint &pt );
92 void setCol( const QPoint &pt ); 90 void setCol( const QPoint &pt );
93 91
94 QPixmap *pix; 92 QPixmap *pix;
95}; 93};
96 94
97static int pWidth = 200; 95static int pWidth = 200;
98static int pHeight = 200; 96static int pHeight = 200;
99 97
100class QColorLuminancePicker : public QWidget 98class QColorLuminancePicker : public QWidget
101{ 99{
102 Q_OBJECT 100 Q_OBJECT
103public: 101public:
104 QColorLuminancePicker(QWidget* parent=0, const char* name=0); 102 QColorLuminancePicker(QWidget* parent=0, const char* name=0);
105 ~QColorLuminancePicker(); 103 ~QColorLuminancePicker();
106 104
107public slots: 105public slots:
108 void setCol( int h, int s, int v ); 106 void setCol( int h, int s, int v );
109 void setCol( int h, int s ); 107 void setCol( int h, int s );
110 108
111signals: 109signals:
112 void newHsv( int h, int s, int v ); 110 void newHsv( int h, int s, int v );
113 111
114protected: 112protected:
115// QSize sizeHint() const; 113// QSize sizeHint() const;
116// QSizePolicy sizePolicy() const; 114// QSizePolicy sizePolicy() const;
117 void paintEvent( QPaintEvent*); 115 void paintEvent( QPaintEvent*);
118 void mouseMoveEvent( QMouseEvent * ); 116 void mouseMoveEvent( QMouseEvent * );
119 void mousePressEvent( QMouseEvent * ); 117 void mousePressEvent( QMouseEvent * );
120 118
121private: 119private:
122 enum { foff = 3, coff = 4 }; //frame and contents offset 120 enum { foff = 3, coff = 4 }; //frame and contents offset
123 int val; 121 int val;
124 int hue; 122 int hue;
125 int sat; 123 int sat;
126 124
127 int y2val( int y ); 125 int y2val( int y );
128 int val2y( int val ); 126 int val2y( int val );
129 void setVal( int v ); 127 void setVal( int v );
130 128
131 QPixmap *pix; 129 QPixmap *pix;
132}; 130};
133 131
134 132
135int QColorLuminancePicker::y2val( int y ) 133int QColorLuminancePicker::y2val( int y )
136{ 134{
137 int d = height() - 2*coff - 1; 135 int d = height() - 2*coff - 1;
138 return 255 - (y - coff)*255/d; 136 return 255 - (y - coff)*255/d;
139} 137}
140 138
141int QColorLuminancePicker::val2y( int v ) 139int QColorLuminancePicker::val2y( int v )
142{ 140{
143 int d = height() - 2*coff - 1; 141 int d = height() - 2*coff - 1;
144 return coff + (255-v)*d/255; 142 return coff + (255-v)*d/255;
145} 143}
146 144
147QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, 145QColorLuminancePicker::QColorLuminancePicker(QWidget* parent,
148 const char* name) 146 const char* name)
149 :QWidget( parent, name ) 147 :QWidget( parent, name )
150{ 148{
151 hue = 100; val = 100; sat = 100; 149 hue = 100; val = 100; sat = 100;
152 pix = 0; 150 pix = 0;
153 // setBackgroundMode( NoBackground ); 151 // setBackgroundMode( NoBackground );
154} 152}
155 153
156QColorLuminancePicker::~QColorLuminancePicker() 154QColorLuminancePicker::~QColorLuminancePicker()
157{ 155{
158 delete pix; 156 delete pix;
159} 157}
160 158
161void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m ) 159void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m )
162{ 160{
163 setVal( y2val(m->y()) ); 161 setVal( y2val(m->y()) );
164} 162}
165void QColorLuminancePicker::mousePressEvent( QMouseEvent *m ) 163void QColorLuminancePicker::mousePressEvent( QMouseEvent *m )
166{ 164{
167 setVal( y2val(m->y()) ); 165 setVal( y2val(m->y()) );
168} 166}
169 167
170void QColorLuminancePicker::setVal( int v ) 168void QColorLuminancePicker::setVal( int v )
171{ 169{
172 if ( val == v ) 170 if ( val == v )
173 return; 171 return;
174 val = QMAX( 0, QMIN(v,255)); 172 val = QMAX( 0, QMIN(v,255));
175 delete pix; pix=0; 173 delete pix; pix=0;
176 repaint( FALSE ); //### 174 repaint( FALSE ); //###
177 emit newHsv( hue, sat, val ); 175 emit newHsv( hue, sat, val );
178} 176}
179 177
180//receives from a hue,sat chooser and relays. 178//receives from a hue,sat chooser and relays.
181void QColorLuminancePicker::setCol( int h, int s ) 179void QColorLuminancePicker::setCol( int h, int s )
182{ 180{
183 setCol( h, s, val ); 181 setCol( h, s, val );
184 emit newHsv( h, s, val ); 182 emit newHsv( h, s, val );
185} 183}
186 184
187void QColorLuminancePicker::paintEvent( QPaintEvent * ) 185void QColorLuminancePicker::paintEvent( QPaintEvent * )
188{ 186{
189 int w = width() - 5; 187 int w = width() - 5;
190 188
191 QRect r( 0, foff, w, height() - 2*foff ); 189 QRect r( 0, foff, w, height() - 2*foff );
192 int wi = r.width() - 2; 190 int wi = r.width() - 2;
193 int hi = r.height() - 2; 191 int hi = r.height() - 2;
194 if ( !pix || pix->height() != hi || pix->width() != wi ) { 192 if ( !pix || pix->height() != hi || pix->width() != wi ) {
195 delete pix; 193 delete pix;
196 QImage img( wi, hi, 32 ); 194 QImage img( wi, hi, 32 );
197 int y; 195 int y;
198 for ( y = 0; y < hi; y++ ) { 196 for ( y = 0; y < hi; y++ ) {
199 QColor c( hue, sat, y2val(y+coff), QColor::Hsv ); 197 QColor c( hue, sat, y2val(y+coff), QColor::Hsv );
200 QRgb r = c.rgb(); 198 QRgb r = c.rgb();
201 int x; 199 int x;
202 for ( x = 0; x < wi; x++ ) 200 for ( x = 0; x < wi; x++ )
203 img.setPixel( x, y, r ); 201 img.setPixel( x, y, r );
204 } 202 }
205 pix = new QPixmap; 203 pix = new QPixmap;
206 pix->convertFromImage(img); 204 pix->convertFromImage(img);
207 } 205 }
208 QPainter p(this); 206 QPainter p(this);
209 p.drawPixmap( 1, coff, *pix ); 207 p.drawPixmap( 1, coff, *pix );
210 QColorGroup g = colorGroup(); 208 QColorGroup g = colorGroup();
211 qDrawShadePanel( &p, r, g, TRUE ); 209 qDrawShadePanel( &p, r, g, TRUE );
212 p.setPen( g.foreground() ); 210 p.setPen( g.foreground() );
213 p.setBrush( g.foreground() ); 211 p.setBrush( g.foreground() );
214 QPointArray a; 212 QPointArray a;
215 int y = val2y(val); 213 int y = val2y(val);
216 a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 ); 214 a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 );
217 erase( w, 0, 5, height() ); 215 erase( w, 0, 5, height() );
218 p.drawPolygon( a ); 216 p.drawPolygon( a );
219} 217}
220 218
221void QColorLuminancePicker::setCol( int h, int s , int v ) 219void QColorLuminancePicker::setCol( int h, int s , int v )
222{ 220{
223 val = v; 221 val = v;
224 hue = h; 222 hue = h;
225 sat = s; 223 sat = s;
226 delete pix; pix=0; 224 delete pix; pix=0;
227 repaint( FALSE );//#### 225 repaint( FALSE );//####
228} 226}
229 227
230QPoint QColorPicker::colPt() 228QPoint QColorPicker::colPt()
231{ return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); } 229{ return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); }
232int QColorPicker::huePt( const QPoint &pt ) 230int QColorPicker::huePt( const QPoint &pt )
233{ return 360 - pt.x()*360/(pWidth-1); } 231{ return 360 - pt.x()*360/(pWidth-1); }
234int QColorPicker::satPt( const QPoint &pt ) 232int QColorPicker::satPt( const QPoint &pt )
235{ return 255 - pt.y()*255/(pHeight-1) ; } 233{ return 255 - pt.y()*255/(pHeight-1) ; }
236void QColorPicker::setCol( const QPoint &pt ) 234void QColorPicker::setCol( const QPoint &pt )
237{ setCol( huePt(pt), satPt(pt) ); } 235{ setCol( huePt(pt), satPt(pt) ); }
238 236
239QColorPicker::QColorPicker(QWidget* parent, const char* name ) 237QColorPicker::QColorPicker(QWidget* parent, const char* name )
240 : QFrame( parent, name ) 238 : QFrame( parent, name )
241{ 239{
242 hue = 0; sat = 0; 240 hue = 0; sat = 0;
243 setCol( 150, 255 ); 241 setCol( 150, 255 );
244 242
245 QImage img( pWidth, pHeight, 32 ); 243 QImage img( pWidth, pHeight, 32 );
246 int x,y; 244 int x,y;
247 for ( y = 0; y < pHeight; y++ ) 245 for ( y = 0; y < pHeight; y++ )
248 for ( x = 0; x < pWidth; x++ ) { 246 for ( x = 0; x < pWidth; x++ ) {
249 QPoint p( x, y ); 247 QPoint p( x, y );
250 img.setPixel( x, y, QColor(huePt(p), satPt(p), 248 img.setPixel( x, y, QColor(huePt(p), satPt(p),
251 200, QColor::Hsv).rgb() ); 249 200, QColor::Hsv).rgb() );
252 } 250 }
253 pix = new QPixmap; 251 pix = new QPixmap;
254 pix->convertFromImage(img); 252 pix->convertFromImage(img);
255 setBackgroundMode( NoBackground ); 253 setBackgroundMode( NoBackground );
256} 254}
257 255
258QColorPicker::~QColorPicker() 256QColorPicker::~QColorPicker()
259{ 257{
260 delete pix; 258 delete pix;
261} 259}
262 260
263QSize QColorPicker::sizeHint() const 261QSize QColorPicker::sizeHint() const
264{ 262{
265 return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() ); 263 return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() );
266} 264}
267 265
268QSizePolicy QColorPicker::sizePolicy() const 266QSizePolicy QColorPicker::sizePolicy() const
269{ 267{
270 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); 268 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
271} 269}
272 270
273void QColorPicker::setCol( int h, int s ) 271void QColorPicker::setCol( int h, int s )
274{ 272{
275 int nhue = QMIN( QMAX(0,h), 360 ); 273 int nhue = QMIN( QMAX(0,h), 360 );
276 int nsat = QMIN( QMAX(0,s), 255); 274 int nsat = QMIN( QMAX(0,s), 255);
277 if ( nhue == hue && nsat == sat ) 275 if ( nhue == hue && nsat == sat )
278 return; 276 return;
279 QRect r( colPt(), QSize(20,20) ); 277 QRect r( colPt(), QSize(20,20) );
280 hue = nhue; sat = nsat; 278 hue = nhue; sat = nsat;
281 r = r.unite( QRect( colPt(), QSize(20,20) ) ); 279 r = r.unite( QRect( colPt(), QSize(20,20) ) );
282 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); 280 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 );
283 // update( r ); 281 // update( r );
284 repaint( r, FALSE ); 282 repaint( r, FALSE );
285} 283}
286 284
287void QColorPicker::mouseMoveEvent( QMouseEvent *m ) 285void QColorPicker::mouseMoveEvent( QMouseEvent *m )
288{ 286{
289 QPoint p = m->pos() - contentsRect().topLeft(); 287 QPoint p = m->pos() - contentsRect().topLeft();
290 setCol( p ); 288 setCol( p );
291 emit newCol( hue, sat ); 289 emit newCol( hue, sat );
292} 290}
293 291
294void QColorPicker::mousePressEvent( QMouseEvent *m ) 292void QColorPicker::mousePressEvent( QMouseEvent *m )
295{ 293{
296 QPoint p = m->pos() - contentsRect().topLeft(); 294 QPoint p = m->pos() - contentsRect().topLeft();
297 setCol( p ); 295 setCol( p );
298 emit newCol( hue, sat ); 296 emit newCol( hue, sat );
299} 297}
300 298
301void QColorPicker::drawContents(QPainter* p) 299void QColorPicker::drawContents(QPainter* p)
302{ 300{
303 QRect r = contentsRect(); 301 QRect r = contentsRect();
304 302
305 p->drawPixmap( r.topLeft(), *pix ); 303 p->drawPixmap( r.topLeft(), *pix );
306 QPoint pt = colPt() + r.topLeft(); 304 QPoint pt = colPt() + r.topLeft();
307 p->setPen( QPen(black) ); 305 p->setPen( QPen(black) );
308 306
309 p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); 307 p->fillRect( pt.x()-9, pt.y(), 20, 2, black );
310 p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); 308 p->fillRect( pt.x(), pt.y()-9, 2, 20, black );
311 309
312} 310}
313 311
314class QColorShowLabel; 312class QColorShowLabel;
315 313
316 314
317 315
318class QColIntValidator: public QIntValidator 316class QColIntValidator: public QIntValidator
319{ 317{
320public: 318public:
321 QColIntValidator( int bottom, int top, 319 QColIntValidator( int bottom, int top,
322 QWidget * parent, const char *name = 0 ) 320 QWidget * parent, const char *name = 0 )
323 :QIntValidator( bottom, top, parent, name ) {} 321 :QIntValidator( bottom, top, parent, name ) {}
324 322
325 QValidator::State validate( QString &, int & ) const; 323 QValidator::State validate( QString &, int & ) const;
326}; 324};
327 325
328QValidator::State QColIntValidator::validate( QString &s, int &pos ) const 326QValidator::State QColIntValidator::validate( QString &s, int &pos ) const
329{ 327{
330 State state = QIntValidator::validate(s,pos); 328 State state = QIntValidator::validate(s,pos);
331 if ( state == Valid ) { 329 if ( state == Valid ) {
332 long int val = s.toLong(); 330 long int val = s.toLong();
333 // This is not a general solution, assumes that top() > 0 and 331 // This is not a general solution, assumes that top() > 0 and
334 // bottom >= 0 332 // bottom >= 0
335 if ( val < 0 ) { 333 if ( val < 0 ) {
336 s = "0"; 334 s = "0";
337 pos = 1; 335 pos = 1;
338 } else if ( val > top() ) { 336 } else if ( val > top() ) {
339 s.setNum( top() ); 337 s.setNum( top() );
340 pos = s.length(); 338 pos = s.length();
341 } 339 }
342 } 340 }
343 return state; 341 return state;
344} 342}
345 343
346 344
347 345
348class QColNumLineEdit : public QLineEdit 346class QColNumLineEdit : public QLineEdit
349{ 347{
350public: 348public:
351 QColNumLineEdit( QWidget *parent, const char* name = 0 ) 349 QColNumLineEdit( QWidget *parent, const char* name = 0 )
352 : QLineEdit( parent, name ) { setMaxLength( 3 );} 350 : QLineEdit( parent, name ) { setMaxLength( 3 );}
353 QSize sizeHint() const { 351 QSize sizeHint() const {
354 return QSize( 30, //##### 352 return QSize( 30, //#####
355 QLineEdit::sizeHint().height() ); } 353 QLineEdit::sizeHint().height() ); }
356 void setNum( int i ) { 354 void setNum( int i ) {
357 QString s; 355 QString s;
358 s.setNum(i); 356 s.setNum(i);
359 bool block = signalsBlocked(); 357 bool block = signalsBlocked();
360 blockSignals(TRUE); 358 blockSignals(TRUE);
361 setText( s ); 359 setText( s );
362 blockSignals(block); 360 blockSignals(block);
363 } 361 }
364 int val() const { return text().toInt(); } 362 int val() const { return text().toInt(); }
365}; 363};
366 364
367 365
368class QColorShower : public QWidget 366class QColorShower : public QWidget
369{ 367{
370 Q_OBJECT 368 Q_OBJECT
371public: 369public:
372 QColorShower( QWidget *parent, const char *name = 0 ); 370 QColorShower( QWidget *parent, const char *name = 0 );
373 371
374 //things that don't emit signals 372 //things that don't emit signals
375 void setHsv( int h, int s, int v ); 373 void setHsv( int h, int s, int v );
376 374
377 int currentAlpha() const { return alphaEd->val(); } 375 int currentAlpha() const { return alphaEd->val(); }
378 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } 376 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); }
379 void showAlpha( bool b ); 377 void showAlpha( bool b );
380 378
381 379
382 QRgb currentColor() const { return curCol; } 380 QRgb currentColor() const { return curCol; }
383 381
384public slots: 382public slots:
385 void setRgb( QRgb rgb ); 383 void setRgb( QRgb rgb );
386 384
387signals: 385signals:
388 void newCol( QRgb rgb ); 386 void newCol( QRgb rgb );
389private slots: 387private slots:
390 void rgbEd(); 388 void rgbEd();
391 void hsvEd(); 389 void hsvEd();
392private: 390private:
393 void showCurrentColor(); 391 void showCurrentColor();
394 int hue, sat, val; 392 int hue, sat, val;
395 QRgb curCol; 393 QRgb curCol;
396 QColNumLineEdit *hEd; 394 QColNumLineEdit *hEd;
397 QColNumLineEdit *sEd; 395 QColNumLineEdit *sEd;
398 QColNumLineEdit *vEd; 396 QColNumLineEdit *vEd;
399 QColNumLineEdit *rEd; 397 QColNumLineEdit *rEd;
400 QColNumLineEdit *gEd; 398 QColNumLineEdit *gEd;
401 QColNumLineEdit *bEd; 399 QColNumLineEdit *bEd;
402 QColNumLineEdit *alphaEd; 400 QColNumLineEdit *alphaEd;
403 QLabel *alphaLab; 401 QLabel *alphaLab;
404 QColorShowLabel *lab; 402 QColorShowLabel *lab;
405 bool rgbOriginal; 403 bool rgbOriginal;
406}; 404};
407 405
408class QColorShowLabel : public QFrame 406class QColorShowLabel : public QFrame
409{ 407{
410 Q_OBJECT 408 Q_OBJECT
411 409
412public: 410public:
413 QColorShowLabel( QWidget *parent ) :QFrame( parent ) { 411 QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
414 setFrameStyle( QFrame::Panel|QFrame::Sunken ); 412 setFrameStyle( QFrame::Panel|QFrame::Sunken );
415 setBackgroundMode( PaletteBackground ); 413 setBackgroundMode( PaletteBackground );
416 setAcceptDrops( TRUE ); 414 setAcceptDrops( TRUE );
417 mousePressed = FALSE; 415 mousePressed = FALSE;
418 } 416 }
419 void setColor( QColor c ) { col = c; } 417 void setColor( QColor c ) { col = c; }
420 418
421signals: 419signals:
422 void colorDropped( QRgb ); 420 void colorDropped( QRgb );
423 421
424protected: 422protected:
425 void drawContents( QPainter *p ); 423 void drawContents( QPainter *p );
426 void mousePressEvent( QMouseEvent *e ); 424 void mousePressEvent( QMouseEvent *e );
427 void mouseReleaseEvent( QMouseEvent *e ); 425 void mouseReleaseEvent( QMouseEvent *e );
428 426
429private: 427private:
430 QColor col; 428 QColor col;
431 bool mousePressed; 429 bool mousePressed;
432 QPoint pressPos; 430 QPoint pressPos;
433 431
434}; 432};
435 433
diff --git a/libopie/colorpopupmenu.cpp b/libopie/colorpopupmenu.cpp
index 5a8d77e..0d66fba 100644
--- a/libopie/colorpopupmenu.cpp
+++ b/libopie/colorpopupmenu.cpp
@@ -1,173 +1,172 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net> 4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net>
5              Dan Williams <williamsdr@acm.org> 5              Dan Williams <williamsdr@acm.org>
6 =. 6 =.
7 .=l. 7 .=l.
8           .>+-= 8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can 9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under 10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software 12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License, 13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version. 14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_. 15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that 16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of 18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more 21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details. 22++=   -.     .`     .: details.
23 :     =  ...= . :.=- 23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU 24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with 25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB. 26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation, 27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330, 28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30 30
31*/ 31*/
32 32
33#include "colorpopupmenu.h" 33#include "colorpopupmenu.h"
34#include "colordialog.h" 34#include "colordialog.h"
35 35
36#include <qaction.h>
37#include <qlayout.h> 36#include <qlayout.h>
38#include <qpainter.h> 37#include <qpainter.h>
39 38
40OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name ) 39OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name )
41 : QFrame( parent, name ) 40 : QFrame( parent, name )
42{ 41{
43 m_color = color; 42 m_color = color;
44 43
45 setFixedSize( 16, 16 ); 44 setFixedSize( 16, 16 );
46 setActive( FALSE ); 45 setActive( FALSE );
47} 46}
48 47
49OColorPanelButton::~OColorPanelButton() 48OColorPanelButton::~OColorPanelButton()
50{ 49{
51} 50}
52 51
53void OColorPanelButton::setActive( bool active ) 52void OColorPanelButton::setActive( bool active )
54{ 53{
55 m_active = active; 54 m_active = active;
56 55
57 if ( m_active ) { 56 if ( m_active ) {
58 setFrameStyle( Panel | Sunken ); 57 setFrameStyle( Panel | Sunken );
59 } else { 58 } else {
60 setFrameStyle( NoFrame ); 59 setFrameStyle( NoFrame );
61 } 60 }
62} 61}
63 62
64void OColorPanelButton::enterEvent( QEvent* ) 63void OColorPanelButton::enterEvent( QEvent* )
65{ 64{
66 if ( !m_active ) { 65 if ( !m_active ) {
67 setFrameStyle( Panel | Sunken ); 66 setFrameStyle( Panel | Sunken );
68 } 67 }
69} 68}
70 69
71void OColorPanelButton::leaveEvent( QEvent* ) 70void OColorPanelButton::leaveEvent( QEvent* )
72{ 71{
73 if ( !m_active ) { 72 if ( !m_active ) {
74 setFrameStyle( NoFrame ); 73 setFrameStyle( NoFrame );
75 } 74 }
76} 75}
77 76
78void OColorPanelButton::paintEvent( QPaintEvent* e ) 77void OColorPanelButton::paintEvent( QPaintEvent* e )
79{ 78{
80 QFrame::paintEvent( e ); 79 QFrame::paintEvent( e );
81 80
82 QPainter painter; 81 QPainter painter;
83 painter.begin( this ); 82 painter.begin( this );
84 painter.fillRect( 2, 2, 12, 12, m_color ); 83 painter.fillRect( 2, 2, 12, 12, m_color );
85 painter.setPen( Qt::black ); 84 painter.setPen( Qt::black );
86 painter.drawRect( 2, 2, 12, 12 ); 85 painter.drawRect( 2, 2, 12, 12 );
87 painter.end(); 86 painter.end();
88} 87}
89 88
90void OColorPanelButton::mouseReleaseEvent( QMouseEvent* ) 89void OColorPanelButton::mouseReleaseEvent( QMouseEvent* )
91{ 90{
92 emit selected( m_color ); 91 emit selected( m_color );
93} 92}
94 93
95OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name ) 94OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name )
96 : QPopupMenu( parent, name ) 95 : QPopupMenu( parent, name )
97{ 96{
98 m_color = color; 97 m_color = color;
99 98
100 colorPanel = new QWidget( this ); 99 colorPanel = new QWidget( this );
101 100
102 colorLayout = new QGridLayout(colorPanel, 5, 6); 101 colorLayout = new QGridLayout(colorPanel, 5, 6);
103 102
104 addColor(QColor(255, 255, 255), 0, 1); 103 addColor(QColor(255, 255, 255), 0, 1);
105 addColor(QColor(192, 192, 192), 0, 2); 104 addColor(QColor(192, 192, 192), 0, 2);
106 addColor(QColor(128, 128, 128), 0, 3); 105 addColor(QColor(128, 128, 128), 0, 3);
107 addColor(QColor(64, 64, 64), 0, 4); 106 addColor(QColor(64, 64, 64), 0, 4);
108 addColor(QColor(0, 0, 0), 0, 5); 107 addColor(QColor(0, 0, 0), 0, 5);
109 108
110 addColor(QColor(255, 0, 0), 1, 0); 109 addColor(QColor(255, 0, 0), 1, 0);
111 addColor(QColor(255, 128, 0), 1, 1); 110 addColor(QColor(255, 128, 0), 1, 1);
112 addColor(QColor(255, 255, 0), 1, 2); 111 addColor(QColor(255, 255, 0), 1, 2);
113 addColor(QColor(128, 255, 0), 1, 3); 112 addColor(QColor(128, 255, 0), 1, 3);
114 addColor(QColor(0, 255, 0), 1, 4); 113 addColor(QColor(0, 255, 0), 1, 4);
115 addColor(QColor(0, 255, 128), 1, 5); 114 addColor(QColor(0, 255, 128), 1, 5);
116 115
117 addColor(QColor(128, 0, 0), 2, 0); 116 addColor(QColor(128, 0, 0), 2, 0);
118 addColor(QColor(128, 64, 0), 2, 1); 117 addColor(QColor(128, 64, 0), 2, 1);
119 addColor(QColor(128, 128, 0), 2, 2); 118 addColor(QColor(128, 128, 0), 2, 2);
120 addColor(QColor(64, 128, 0), 2, 3); 119 addColor(QColor(64, 128, 0), 2, 3);
121 addColor(QColor(0, 128, 0), 2, 4); 120 addColor(QColor(0, 128, 0), 2, 4);
122 addColor(QColor(0, 128, 64), 2, 5); 121 addColor(QColor(0, 128, 64), 2, 5);
123 122
124 addColor(QColor(0, 255, 255), 3, 0); 123 addColor(QColor(0, 255, 255), 3, 0);
125 addColor(QColor(0, 128, 255), 3, 1); 124 addColor(QColor(0, 128, 255), 3, 1);
126 addColor(QColor(0, 0, 255), 3, 2); 125 addColor(QColor(0, 0, 255), 3, 2);
127 addColor(QColor(128, 0, 255), 3, 3); 126 addColor(QColor(128, 0, 255), 3, 3);
128 addColor(QColor(255, 0, 255), 3, 4); 127 addColor(QColor(255, 0, 255), 3, 4);
129 addColor(QColor(255, 0, 128), 3, 5); 128 addColor(QColor(255, 0, 128), 3, 5);
130 129
131 addColor(QColor(0, 128, 128), 4, 0); 130 addColor(QColor(0, 128, 128), 4, 0);
132 addColor(QColor(0, 64, 128), 4, 1); 131 addColor(QColor(0, 64, 128), 4, 1);
133 addColor(QColor(0, 0, 128), 4, 2); 132 addColor(QColor(0, 0, 128), 4, 2);
134 addColor(QColor(64, 0, 128), 4, 3); 133 addColor(QColor(64, 0, 128), 4, 3);
135 addColor(QColor(128, 0, 128), 4, 4); 134 addColor(QColor(128, 0, 128), 4, 4);
136 addColor(QColor(128, 0, 64), 4, 5); 135 addColor(QColor(128, 0, 64), 4, 5);
137 136
138 insertItem( colorPanel ); 137 insertItem( colorPanel );
139 insertSeparator(); 138 insertSeparator();
140 insertItem(tr("More"),this,SLOT( moreColorClicked())); 139 insertItem(tr("More"),this,SLOT( moreColorClicked()));
141 /* 140 /*
142 QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" ); 141 QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" );
143 connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) ); 142 connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) );
144 chooseColorAction->addTo( this ); 143 chooseColorAction->addTo( this );
145 */ 144 */
146 activateItemAt( 0 ); 145 activateItemAt( 0 );
147} 146}
148 147
149OColorPopupMenu::~OColorPopupMenu() 148OColorPopupMenu::~OColorPopupMenu()
150{ 149{
151} 150}
152 151
153void OColorPopupMenu::addColor( const QColor& color, int row, int col ) 152void OColorPopupMenu::addColor( const QColor& color, int row, int col )
154{ 153{
155 OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel ); 154 OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel );
156 connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) ); 155 connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) );
157 colorLayout->addWidget( panelButton, row, col ); 156 colorLayout->addWidget( panelButton, row, col );
158} 157}
159 158
160void OColorPopupMenu::buttonSelected( const QColor& color ) 159void OColorPopupMenu::buttonSelected( const QColor& color )
161{ 160{
162 m_color = color; 161 m_color = color;
163 emit colorSelected( color ); 162 emit colorSelected( color );
164 hide(); 163 hide();
165} 164}
166 165
167void OColorPopupMenu::moreColorClicked() 166void OColorPopupMenu::moreColorClicked()
168{ 167{
169 QColor color = OColorDialog::getColor( m_color ); 168 QColor color = OColorDialog::getColor( m_color );
170 m_color = color; 169 m_color = color;
171 emit colorSelected( color ); 170 emit colorSelected( color );
172 hide(); 171 hide();
173} 172}
diff --git a/libopie/ocheckitem.cpp b/libopie/ocheckitem.cpp
index 082d7a2..cd763c1 100644
--- a/libopie/ocheckitem.cpp
+++ b/libopie/ocheckitem.cpp
@@ -1,106 +1,105 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Stefan Eilers (se, eilers.stefan@epost.de 2** Copyright (C) 2002 Stefan Eilers (se, eilers.stefan@epost.de
3** 3**
4** This file may be distributed and/or modified under the terms of the 4** This file may be distributed and/or modified under the terms of the
5** GNU Library General Public License version 2 as published by the 5** GNU Library General Public License version 2 as published by the
6** Free Software Foundation and appearing in the file LICENSE.GPL 6** Free Software Foundation and appearing in the file LICENSE.GPL
7** included in the packaging of this file. 7** included in the packaging of this file.
8** 8**
9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11**********************************************************************/ 11**********************************************************************/
12 12
13#include <qpainter.h>
14 13
15#include "ocheckitem.h" 14#include "ocheckitem.h"
16 15
17/** 16/**
18 * Constructs an CheckItem with a QTable as parent 17 * Constructs an CheckItem with a QTable as parent
19 * and a sort key for. 18 * and a sort key for.
20 * The sort key will be used by QTable to sort the table later 19 * The sort key will be used by QTable to sort the table later
21 * @param t The parent QTable where the check item belongs 20 * @param t The parent QTable where the check item belongs
22 * @param key A sort key 21 * @param key A sort key
23 */ 22 */
24OCheckItem::OCheckItem( QTable *t, const QString &key ) 23OCheckItem::OCheckItem( QTable *t, const QString &key )
25 : QTableItem( t, Never, "" ), m_checked( FALSE ), m_sortKey( key ) 24 : QTableItem( t, Never, "" ), m_checked( FALSE ), m_sortKey( key )
26{ 25{
27} 26}
28 27
29/** 28/**
30 * reimplemted for internal reasons 29 * reimplemted for internal reasons
31 * @return Returns the sort key of the Item 30 * @return Returns the sort key of the Item
32 * @see QTableItem 31 * @see QTableItem
33 */ 32 */
34QString OCheckItem::key() const 33QString OCheckItem::key() const
35{ 34{
36 return m_sortKey; 35 return m_sortKey;
37} 36}
38 37
39/** 38/**
40 * This method can check or uncheck the item. It will 39 * This method can check or uncheck the item. It will
41 * call QTable to update the cell. 40 * call QTable to update the cell.
42 * 41 *
43 * @param b Whether to check or uncheck the item 42 * @param b Whether to check or uncheck the item
44 */ 43 */
45void OCheckItem::setChecked( bool b ) 44void OCheckItem::setChecked( bool b )
46{ 45{
47 m_checked = b; 46 m_checked = b;
48 table()->updateCell( row(), col() ); 47 table()->updateCell( row(), col() );
49} 48}
50 49
51/** 50/**
52 * This will toggle the item. If it is checked it'll get 51 * This will toggle the item. If it is checked it'll get
53 * unchecked by this method or vice versa. 52 * unchecked by this method or vice versa.
54 */ 53 */
55void OCheckItem::toggle() 54void OCheckItem::toggle()
56{ 55{
57 m_checked = !m_checked; 56 m_checked = !m_checked;
58} 57}
59 58
60/** 59/**
61 * This will return the state of the item. 60 * This will return the state of the item.
62 * 61 *
63 * @return Returns true if the item is checked 62 * @return Returns true if the item is checked
64 */ 63 */
65bool OCheckItem::isChecked() const 64bool OCheckItem::isChecked() const
66{ 65{
67 return m_checked; 66 return m_checked;
68} 67}
69 68
70/** 69/**
71 * @internal 70 * @internal
72 * This paints the item 71 * This paints the item
73 */ 72 */
74void OCheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, 73void OCheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr,
75 bool ) 74 bool )
76{ 75{
77 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 76 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
78 77
79 int marg = ( cr.width() - BoxSize ) / 2; 78 int marg = ( cr.width() - BoxSize ) / 2;
80 int x = 0; 79 int x = 0;
81 int y = ( cr.height() - BoxSize ) / 2; 80 int y = ( cr.height() - BoxSize ) / 2;
82 p->setPen( QPen( cg.text() ) ); 81 p->setPen( QPen( cg.text() ) );
83 p->drawRect( x + marg, y, BoxSize, BoxSize ); 82 p->drawRect( x + marg, y, BoxSize, BoxSize );
84 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 83 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
85 p->setPen( darkGreen ); 84 p->setPen( darkGreen );
86 x += 1; 85 x += 1;
87 y += 1; 86 y += 1;
88 if ( m_checked ) { 87 if ( m_checked ) {
89 QPointArray a( 7*2 ); 88 QPointArray a( 7*2 );
90 int i, xx, yy; 89 int i, xx, yy;
91 xx = x+1+marg; 90 xx = x+1+marg;
92 yy = y+2; 91 yy = y+2;
93 for ( i=0; i<3; i++ ) { 92 for ( i=0; i<3; i++ ) {
94 a.setPoint( 2*i, xx, yy ); 93 a.setPoint( 2*i, xx, yy );
95 a.setPoint( 2*i+1, xx, yy+2 ); 94 a.setPoint( 2*i+1, xx, yy+2 );
96 xx++; yy++; 95 xx++; yy++;
97 } 96 }
98 yy -= 2; 97 yy -= 2;
99 for ( i=3; i<7; i++ ) { 98 for ( i=3; i<7; i++ ) {
100 a.setPoint( 2*i, xx, yy ); 99 a.setPoint( 2*i, xx, yy );
101 a.setPoint( 2*i+1, xx, yy+2 ); 100 a.setPoint( 2*i+1, xx, yy+2 );
102 xx++; yy--; 101 xx++; yy--;
103 } 102 }
104 p->drawLineSegments( a ); 103 p->drawLineSegments( a );
105 } 104 }
106} 105}
diff --git a/libopie/ocolorbutton.cpp b/libopie/ocolorbutton.cpp
index 113a77a..93fe5d0 100644
--- a/libopie/ocolorbutton.cpp
+++ b/libopie/ocolorbutton.cpp
@@ -1,142 +1,139 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <opie/colorpopupmenu.h> 29#include <opie/colorpopupmenu.h>
30#include <opie/ocolorbutton.h> 30#include <opie/ocolorbutton.h>
31#include <qcolor.h>
32#include <qpixmap.h>
33#include <qimage.h>
34 31
35#include <qpe/resource.h> 32#include <qpe/resource.h>
36 33
37struct OColorButtonPrivate { 34struct OColorButtonPrivate {
38 QPopupMenu *m_menu; 35 QPopupMenu *m_menu;
39 QColor m_color; 36 QColor m_color;
40}; 37};
41 38
42 39
43/** 40/**
44 * This concstructs a Color Button with @param color as the start color 41 * This concstructs a Color Button with @param color as the start color
45 * It'll use a OColorPopupMenu internally 42 * It'll use a OColorPopupMenu internally
46 * 43 *
47 * @param parent The parent of the Color Button 44 * @param parent The parent of the Color Button
48 * @param color The color from where to start on 45 * @param color The color from where to start on
49 * @param name @see QObject 46 * @param name @see QObject
50 */ 47 */
51OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name ) 48OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name )
52 : QPushButton ( parent, name ) 49 : QPushButton ( parent, name )
53{ 50{
54 d = new OColorButtonPrivate; 51 d = new OColorButtonPrivate;
55 52
56 d-> m_menu = new OColorPopupMenu ( color, 0, 0 ); 53 d-> m_menu = new OColorPopupMenu ( color, 0, 0 );
57 setPopup ( d-> m_menu ); 54 setPopup ( d-> m_menu );
58 //setPopupDelay ( 0 ); 55 //setPopupDelay ( 0 );
59 connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & ))); 56 connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & )));
60 57
61 updateColor ( color ); 58 updateColor ( color );
62 59
63 QSize s = sizeHint ( ) + QSize ( 12, 0 ); 60 QSize s = sizeHint ( ) + QSize ( 12, 0 );
64 setMinimumSize ( s ); 61 setMinimumSize ( s );
65 setMaximumSize ( s. width ( ) * 2, s. height ( )); 62 setMaximumSize ( s. width ( ) * 2, s. height ( ));
66} 63}
67 64
68/** 65/**
69 * This destructs the object 66 * This destructs the object
70 */ 67 */
71OColorButton::~OColorButton ( ) 68OColorButton::~OColorButton ( )
72{ 69{
73 delete d; 70 delete d;
74} 71}
75 72
76/** 73/**
77 * @return Returns the current color of the button 74 * @return Returns the current color of the button
78 */ 75 */
79QColor OColorButton::color ( ) const 76QColor OColorButton::color ( ) const
80{ 77{
81 return d-> m_color; 78 return d-> m_color;
82} 79}
83 80
84/** 81/**
85 * This method sets the color of the button 82 * This method sets the color of the button
86 * @param c The color to be set. 83 * @param c The color to be set.
87 */ 84 */
88void OColorButton::setColor ( const QColor &c ) 85void OColorButton::setColor ( const QColor &c )
89{ 86{
90 updateColor ( c ); 87 updateColor ( c );
91} 88}
92 89
93/** 90/**
94 * @internal 91 * @internal
95 */ 92 */
96void OColorButton::updateColor ( const QColor &c ) 93void OColorButton::updateColor ( const QColor &c )
97{ 94{
98 d-> m_color = c; 95 d-> m_color = c;
99 96
100 QImage img ( 16, 16, 32 ); 97 QImage img ( 16, 16, 32 );
101 img. fill ( 0 ); 98 img. fill ( 0 );
102 99
103 int r, g, b; 100 int r, g, b;
104 c. rgb ( &r, &g, &b ); 101 c. rgb ( &r, &g, &b );
105 102
106 int w = img. width ( ); 103 int w = img. width ( );
107 int h = img. height ( ); 104 int h = img. height ( );
108 105
109 int dx = w * 20 / 100; // 15% 106 int dx = w * 20 / 100; // 15%
110 int dy = h * 20 / 100; 107 int dy = h * 20 / 100;
111 108
112 for ( int y = 0; y < h; y++ ) { 109 for ( int y = 0; y < h; y++ ) {
113 for ( int x = 0; x < w; x++ ) { 110 for ( int x = 0; x < w; x++ ) {
114 double alpha = 1.0; 111 double alpha = 1.0;
115 112
116 if ( x < dx ) 113 if ( x < dx )
117 alpha *= ( double ( x + 1 ) / dx ); 114 alpha *= ( double ( x + 1 ) / dx );
118 else if ( x >= w - dx ) 115 else if ( x >= w - dx )
119 alpha *= ( double ( w - x ) / dx ); 116 alpha *= ( double ( w - x ) / dx );
120 if ( y < dy ) 117 if ( y < dy )
121 alpha *= ( double ( y + 1 ) / dy ); 118 alpha *= ( double ( y + 1 ) / dy );
122 else if ( y >= h - dy ) 119 else if ( y >= h - dy )
123 alpha *= ( double ( h - y ) / dy ); 120 alpha *= ( double ( h - y ) / dy );
124 121
125 int a = int ( alpha * 255.0 ); 122 int a = int ( alpha * 255.0 );
126 if ( a < 0 ) 123 if ( a < 0 )
127 a = 0; 124 a = 0;
128 if ( a > 255 ) 125 if ( a > 255 )
129 a = 255; 126 a = 255;
130 127
131 img. setPixel ( x, y, qRgba ( r, g, b, a )); 128 img. setPixel ( x, y, qRgba ( r, g, b, a ));
132 } 129 }
133 } 130 }
134 img. setAlphaBuffer ( true ); 131 img. setAlphaBuffer ( true );
135 132
136 QPixmap pix; 133 QPixmap pix;
137 pix. convertFromImage ( img ); 134 pix. convertFromImage ( img );
138 setPixmap ( pix ); 135 setPixmap ( pix );
139 136
140 emit colorSelected ( c ); 137 emit colorSelected ( c );
141} 138}
142 139
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index c5342e1..c0b6efa 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,415 +1,414 @@
1/* This file is part of the OPIE libraries 1/* This file is part of the OPIE libraries
2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) 2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <stdlib.h> 20#include <stdlib.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <sys/ioctl.h> 23#include <sys/ioctl.h>
24#include <signal.h> 24#include <signal.h>
25#include <sys/time.h> 25#include <sys/time.h>
26#ifndef QT_NO_SOUND 26#ifndef QT_NO_SOUND
27#include <linux/soundcard.h> 27#include <linux/soundcard.h>
28#endif 28#endif
29#include <math.h> 29#include <math.h>
30 30
31#include <qapplication.h>
32 31
33#include <qfile.h> 32#include <qfile.h>
34#include <qtextstream.h> 33#include <qtextstream.h>
35#include <qpe/sound.h> 34#include <qpe/sound.h>
36#include <qpe/resource.h> 35#include <qpe/resource.h>
37#include <qpe/config.h> 36#include <qpe/config.h>
38#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
39 38
40#include "odevice.h" 39#include "odevice.h"
41 40
42#include <qwindowsystem_qws.h> 41#include <qwindowsystem_qws.h>
43 42
44#ifndef ARRAY_SIZE 43#ifndef ARRAY_SIZE
45#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 44#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
46#endif 45#endif
47 46
48// _IO and friends are only defined in kernel headers ... 47// _IO and friends are only defined in kernel headers ...
49 48
50#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 49#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
51 50
52#define OD_IO(type,number) OD_IOC(0,type,number,0) 51#define OD_IO(type,number) OD_IOC(0,type,number,0)
53#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 52#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
54#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 53#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
55#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 54#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
56 55
57using namespace Opie; 56using namespace Opie;
58 57
59class ODeviceData { 58class ODeviceData {
60public: 59public:
61 QString m_vendorstr; 60 QString m_vendorstr;
62 OVendor m_vendor; 61 OVendor m_vendor;
63 62
64 QString m_modelstr; 63 QString m_modelstr;
65 OModel m_model; 64 OModel m_model;
66 65
67 QString m_systemstr; 66 QString m_systemstr;
68 OSystem m_system; 67 OSystem m_system;
69 68
70 QString m_sysverstr; 69 QString m_sysverstr;
71 70
72 Transformation m_rotation; 71 Transformation m_rotation;
73 ODirection m_direction; 72 ODirection m_direction;
74 73
75 QValueList <ODeviceButton> *m_buttons; 74 QValueList <ODeviceButton> *m_buttons;
76 uint m_holdtime; 75 uint m_holdtime;
77 QStrList *m_cpu_frequencies; 76 QStrList *m_cpu_frequencies;
78 77
79}; 78};
80 79
81class iPAQ : public ODevice, public QWSServer::KeyboardFilter { 80class iPAQ : public ODevice, public QWSServer::KeyboardFilter {
82protected: 81protected:
83 virtual void init ( ); 82 virtual void init ( );
84 virtual void initButtons ( ); 83 virtual void initButtons ( );
85 84
86public: 85public:
87 virtual bool setSoftSuspend ( bool soft ); 86 virtual bool setSoftSuspend ( bool soft );
88 87
89 virtual bool setDisplayBrightness ( int b ); 88 virtual bool setDisplayBrightness ( int b );
90 virtual int displayBrightnessResolution ( ) const; 89 virtual int displayBrightnessResolution ( ) const;
91 90
92 virtual void alarmSound ( ); 91 virtual void alarmSound ( );
93 92
94 virtual QValueList <OLed> ledList ( ) const; 93 virtual QValueList <OLed> ledList ( ) const;
95 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 94 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
96 virtual OLedState ledState ( OLed led ) const; 95 virtual OLedState ledState ( OLed led ) const;
97 virtual bool setLedState ( OLed led, OLedState st ); 96 virtual bool setLedState ( OLed led, OLedState st );
98 97
99 virtual bool hasLightSensor ( ) const; 98 virtual bool hasLightSensor ( ) const;
100 virtual int readLightSensor ( ); 99 virtual int readLightSensor ( );
101 virtual int lightSensorResolution ( ) const; 100 virtual int lightSensorResolution ( ) const;
102 101
103protected: 102protected:
104 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 103 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
105 virtual void timerEvent ( QTimerEvent *te ); 104 virtual void timerEvent ( QTimerEvent *te );
106 105
107 int m_power_timer; 106 int m_power_timer;
108 107
109 OLedState m_leds [2]; 108 OLedState m_leds [2];
110}; 109};
111 110
112class Jornada : public ODevice { 111class Jornada : public ODevice {
113protected: 112protected:
114 virtual void init ( ); 113 virtual void init ( );
115 //virtual void initButtons ( ); 114 //virtual void initButtons ( );
116public: 115public:
117 virtual bool setSoftSuspend ( bool soft ); 116 virtual bool setSoftSuspend ( bool soft );
118 virtual bool setDisplayBrightness ( int b ); 117 virtual bool setDisplayBrightness ( int b );
119 virtual int displayBrightnessResolution ( ) const; 118 virtual int displayBrightnessResolution ( ) const;
120 static bool isJornada(); 119 static bool isJornada();
121 120
122}; 121};
123 122
124class Zaurus : public ODevice { 123class Zaurus : public ODevice {
125protected: 124protected:
126 virtual void init ( ); 125 virtual void init ( );
127 virtual void initButtons ( ); 126 virtual void initButtons ( );
128 127
129public: 128public:
130 virtual bool setSoftSuspend ( bool soft ); 129 virtual bool setSoftSuspend ( bool soft );
131 130
132 virtual bool setDisplayBrightness ( int b ); 131 virtual bool setDisplayBrightness ( int b );
133 virtual int displayBrightnessResolution ( ) const; 132 virtual int displayBrightnessResolution ( ) const;
134 133
135 virtual void alarmSound ( ); 134 virtual void alarmSound ( );
136 virtual void keySound ( ); 135 virtual void keySound ( );
137 virtual void touchSound ( ); 136 virtual void touchSound ( );
138 137
139 virtual QValueList <OLed> ledList ( ) const; 138 virtual QValueList <OLed> ledList ( ) const;
140 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 139 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
141 virtual OLedState ledState ( OLed led ) const; 140 virtual OLedState ledState ( OLed led ) const;
142 virtual bool setLedState ( OLed led, OLedState st ); 141 virtual bool setLedState ( OLed led, OLedState st );
143 142
144 bool hasHingeSensor() const; 143 bool hasHingeSensor() const;
145 OHingeStatus readHingeSensor(); 144 OHingeStatus readHingeSensor();
146 145
147 static bool isZaurus(); 146 static bool isZaurus();
148 147
149 // Does this break BC? 148 // Does this break BC?
150 virtual bool suspend ( ); 149 virtual bool suspend ( );
151 Transformation rotation ( ) const; 150 Transformation rotation ( ) const;
152 ODirection direction ( ) const; 151 ODirection direction ( ) const;
153 152
154protected: 153protected:
155 virtual void buzzer ( int snd ); 154 virtual void buzzer ( int snd );
156 155
157 OLedState m_leds [1]; 156 OLedState m_leds [1];
158 bool m_embedix; 157 bool m_embedix;
159 void virtual_hook( int id, void *data ); 158 void virtual_hook( int id, void *data );
160}; 159};
161 160
162class SIMpad : public ODevice, public QWSServer::KeyboardFilter { 161class SIMpad : public ODevice, public QWSServer::KeyboardFilter {
163protected: 162protected:
164 virtual void init ( ); 163 virtual void init ( );
165 virtual void initButtons ( ); 164 virtual void initButtons ( );
166 165
167public: 166public:
168 virtual bool setSoftSuspend ( bool soft ); 167 virtual bool setSoftSuspend ( bool soft );
169 virtual bool suspend(); 168 virtual bool suspend();
170 169
171 virtual bool setDisplayStatus( bool on ); 170 virtual bool setDisplayStatus( bool on );
172 virtual bool setDisplayBrightness ( int b ); 171 virtual bool setDisplayBrightness ( int b );
173 virtual int displayBrightnessResolution ( ) const; 172 virtual int displayBrightnessResolution ( ) const;
174 173
175 virtual void alarmSound ( ); 174 virtual void alarmSound ( );
176 175
177 virtual QValueList <OLed> ledList ( ) const; 176 virtual QValueList <OLed> ledList ( ) const;
178 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 177 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
179 virtual OLedState ledState ( OLed led ) const; 178 virtual OLedState ledState ( OLed led ) const;
180 virtual bool setLedState ( OLed led, OLedState st ); 179 virtual bool setLedState ( OLed led, OLedState st );
181 180
182protected: 181protected:
183 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 182 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
184 virtual void timerEvent ( QTimerEvent *te ); 183 virtual void timerEvent ( QTimerEvent *te );
185 184
186 int m_power_timer; 185 int m_power_timer;
187 186
188 OLedState m_leds [1]; //FIXME check if really only one 187 OLedState m_leds [1]; //FIXME check if really only one
189}; 188};
190 189
191class Ramses : public ODevice, public QWSServer::KeyboardFilter { 190class Ramses : public ODevice, public QWSServer::KeyboardFilter {
192protected: 191protected:
193 virtual void init ( ); 192 virtual void init ( );
194 193
195public: 194public:
196 virtual bool setSoftSuspend ( bool soft ); 195 virtual bool setSoftSuspend ( bool soft );
197 virtual bool suspend ( ); 196 virtual bool suspend ( );
198 197
199 virtual bool setDisplayStatus( bool on ); 198 virtual bool setDisplayStatus( bool on );
200 virtual bool setDisplayBrightness ( int b ); 199 virtual bool setDisplayBrightness ( int b );
201 virtual int displayBrightnessResolution ( ) const; 200 virtual int displayBrightnessResolution ( ) const;
202 virtual bool setDisplayContrast ( int b ); 201 virtual bool setDisplayContrast ( int b );
203 virtual int displayContrastResolution ( ) const; 202 virtual int displayContrastResolution ( ) const;
204 203
205protected: 204protected:
206 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 205 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
207 virtual void timerEvent ( QTimerEvent *te ); 206 virtual void timerEvent ( QTimerEvent *te );
208 207
209 int m_power_timer; 208 int m_power_timer;
210}; 209};
211 210
212struct i_button { 211struct i_button {
213 uint model; 212 uint model;
214 Qt::Key code; 213 Qt::Key code;
215 char *utext; 214 char *utext;
216 char *pix; 215 char *pix;
217 char *fpressedservice; 216 char *fpressedservice;
218 char *fpressedaction; 217 char *fpressedaction;
219 char *fheldservice; 218 char *fheldservice;
220 char *fheldaction; 219 char *fheldaction;
221} ipaq_buttons [] = { 220} ipaq_buttons [] = {
222 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 221 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
223 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 222 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
224 "devicebuttons/ipaq_calendar", 223 "devicebuttons/ipaq_calendar",
225 "datebook", "nextView()", 224 "datebook", "nextView()",
226 "today", "raise()" }, 225 "today", "raise()" },
227 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 226 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
228 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 227 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
229 "devicebuttons/ipaq_contact", 228 "devicebuttons/ipaq_contact",
230 "addressbook", "raise()", 229 "addressbook", "raise()",
231 "addressbook", "beamBusinessCard()" }, 230 "addressbook", "beamBusinessCard()" },
232 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, 231 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx,
233 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 232 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
234 "devicebuttons/ipaq_menu", 233 "devicebuttons/ipaq_menu",
235 "QPE/TaskBar", "toggleMenu()", 234 "QPE/TaskBar", "toggleMenu()",
236 "QPE/TaskBar", "toggleStartMenu()" }, 235 "QPE/TaskBar", "toggleStartMenu()" },
237 { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 236 { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
238 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 237 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
239 "devicebuttons/ipaq_mail", 238 "devicebuttons/ipaq_mail",
240 "mail", "raise()", 239 "mail", "raise()",
241 "mail", "newMail()" }, 240 "mail", "newMail()" },
242 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 241 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
243 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 242 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
244 "devicebuttons/ipaq_home", 243 "devicebuttons/ipaq_home",
245 "QPE/Launcher", "home()", 244 "QPE/Launcher", "home()",
246 "buttonsettings", "raise()" }, 245 "buttonsettings", "raise()" },
247 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 246 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
248 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), 247 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"),
249 "devicebuttons/ipaq_record", 248 "devicebuttons/ipaq_record",
250 "QPE/VMemo", "toggleRecord()", 249 "QPE/VMemo", "toggleRecord()",
251 "sound", "raise()" }, 250 "sound", "raise()" },
252}; 251};
253 252
254struct z_button { 253struct z_button {
255 Qt::Key code; 254 Qt::Key code;
256 char *utext; 255 char *utext;
257 char *pix; 256 char *pix;
258 char *fpressedservice; 257 char *fpressedservice;
259 char *fpressedaction; 258 char *fpressedaction;
260 char *fheldservice; 259 char *fheldservice;
261 char *fheldaction; 260 char *fheldaction;
262} z_buttons [] = { 261} z_buttons [] = {
263 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 262 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
264 "devicebuttons/z_calendar", 263 "devicebuttons/z_calendar",
265 "datebook", "nextView()", 264 "datebook", "nextView()",
266 "today", "raise()" }, 265 "today", "raise()" },
267 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 266 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
268 "devicebuttons/z_contact", 267 "devicebuttons/z_contact",
269 "addressbook", "raise()", 268 "addressbook", "raise()",
270 "addressbook", "beamBusinessCard()" }, 269 "addressbook", "beamBusinessCard()" },
271 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 270 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
272 "devicebuttons/z_home", 271 "devicebuttons/z_home",
273 "QPE/Launcher", "home()", 272 "QPE/Launcher", "home()",
274 "buttonsettings", "raise()" }, 273 "buttonsettings", "raise()" },
275 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 274 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
276 "devicebuttons/z_menu", 275 "devicebuttons/z_menu",
277 "QPE/TaskBar", "toggleMenu()", 276 "QPE/TaskBar", "toggleMenu()",
278 "QPE/TaskBar", "toggleStartMenu()" }, 277 "QPE/TaskBar", "toggleStartMenu()" },
279 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 278 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
280 "devicebuttons/z_mail", 279 "devicebuttons/z_mail",
281 "mail", "raise()", 280 "mail", "raise()",
282 "mail", "newMail()" }, 281 "mail", "newMail()" },
283}; 282};
284 283
285struct z_button z_buttons_c700 [] = { 284struct z_button z_buttons_c700 [] = {
286 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 285 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
287 "devicebuttons/z_calendar", 286 "devicebuttons/z_calendar",
288 "datebook", "nextView()", 287 "datebook", "nextView()",
289 "today", "raise()" }, 288 "today", "raise()" },
290 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 289 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
291 "devicebuttons/z_contact", 290 "devicebuttons/z_contact",
292 "addressbook", "raise()", 291 "addressbook", "raise()",
293 "addressbook", "beamBusinessCard()" }, 292 "addressbook", "beamBusinessCard()" },
294 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 293 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
295 "devicebuttons/z_home", 294 "devicebuttons/z_home",
296 "QPE/Launcher", "home()", 295 "QPE/Launcher", "home()",
297 "buttonsettings", "raise()" }, 296 "buttonsettings", "raise()" },
298 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 297 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
299 "devicebuttons/z_menu", 298 "devicebuttons/z_menu",
300 "QPE/TaskBar", "toggleMenu()", 299 "QPE/TaskBar", "toggleMenu()",
301 "QPE/TaskBar", "toggleStartMenu()" }, 300 "QPE/TaskBar", "toggleStartMenu()" },
302 { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"), 301 { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"),
303 "devicebuttons/z_hinge", 302 "devicebuttons/z_hinge",
304 "QPE/Rotation", "rotateDefault()", 303 "QPE/Rotation", "rotateDefault()",
305 "QPE/Dummy", "doNothing()" }, 304 "QPE/Dummy", "doNothing()" },
306}; 305};
307 306
308struct s_button { 307struct s_button {
309 uint model; 308 uint model;
310 Qt::Key code; 309 Qt::Key code;
311 char *utext; 310 char *utext;
312 char *pix; 311 char *pix;
313 char *fpressedservice; 312 char *fpressedservice;
314 char *fpressedaction; 313 char *fpressedaction;
315 char *fheldservice; 314 char *fheldservice;
316 char *fheldaction; 315 char *fheldaction;
317} simpad_buttons [] = { 316} simpad_buttons [] = {
318 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 317 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
319 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), 318 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"),
320 "devicebuttons/simpad_lower_up", 319 "devicebuttons/simpad_lower_up",
321 "datebook", "nextView()", 320 "datebook", "nextView()",
322 "today", "raise()" }, 321 "today", "raise()" },
323 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 322 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
324 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), 323 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"),
325 "devicebuttons/simpad_lower_down", 324 "devicebuttons/simpad_lower_down",
326 "addressbook", "raise()", 325 "addressbook", "raise()",
327 "addressbook", "beamBusinessCard()" }, 326 "addressbook", "beamBusinessCard()" },
328 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 327 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
329 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), 328 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"),
330 "devicebuttons/simpad_lower_right", 329 "devicebuttons/simpad_lower_right",
331 "QPE/TaskBar", "toggleMenu()", 330 "QPE/TaskBar", "toggleMenu()",
332 "QPE/TaskBar", "toggleStartMenu()" }, 331 "QPE/TaskBar", "toggleStartMenu()" },
333 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 332 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
334 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), 333 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"),
335 "devicebuttons/simpad_lower_left", 334 "devicebuttons/simpad_lower_left",
336 "mail", "raise()", 335 "mail", "raise()",
337 "mail", "newMail()" }, 336 "mail", "newMail()" },
338 337
339 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 338 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
340 Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), 339 Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"),
341 "devicebuttons/simpad_upper_up", 340 "devicebuttons/simpad_upper_up",
342 "QPE/Launcher", "home()", 341 "QPE/Launcher", "home()",
343 "buttonsettings", "raise()" }, 342 "buttonsettings", "raise()" },
344 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 343 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
345 Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), 344 Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"),
346 "devicebuttons/simpad_upper_down", 345 "devicebuttons/simpad_upper_down",
347 "addressbook", "raise()", 346 "addressbook", "raise()",
348 "addressbook", "beamBusinessCard()" }, 347 "addressbook", "beamBusinessCard()" },
349 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 348 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
350 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), 349 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"),
351 "devicebuttons/simpad_upper_right", 350 "devicebuttons/simpad_upper_right",
352 "QPE/TaskBar", "toggleMenu()", 351 "QPE/TaskBar", "toggleMenu()",
353 "QPE/TaskBar", "toggleStartMenu()" }, 352 "QPE/TaskBar", "toggleStartMenu()" },
354 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 353 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
355 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), 354 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"),
356 "devicebuttons/simpad_upper_left", 355 "devicebuttons/simpad_upper_left",
357 "QPE/Rotation", "flip()", 356 "QPE/Rotation", "flip()",
358 "QPE/Rotation", "flip()" }, 357 "QPE/Rotation", "flip()" },
359 /* 358 /*
360 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 359 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
361 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), 360 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"),
362 "devicebuttons/simpad_lower_upper", 361 "devicebuttons/simpad_lower_upper",
363 "QPE/Launcher", "home()", 362 "QPE/Launcher", "home()",
364 "buttonsettings", "raise()" }, 363 "buttonsettings", "raise()" },
365 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 364 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
366 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), 365 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"),
367 "devicebuttons/simpad_upper_lower", 366 "devicebuttons/simpad_upper_lower",
368 "QPE/Launcher", "home()", 367 "QPE/Launcher", "home()",
369 "buttonsettings", "raise()" }, 368 "buttonsettings", "raise()" },
370 */ 369 */
371}; 370};
372 371
373struct r_button { 372struct r_button {
374 uint model; 373 uint model;
375 Qt::Key code; 374 Qt::Key code;
376 char *utext; 375 char *utext;
377 char *pix; 376 char *pix;
378 char *fpressedservice; 377 char *fpressedservice;
379 char *fpressedaction; 378 char *fpressedaction;
380 char *fheldservice; 379 char *fheldservice;
381 char *fheldaction; 380 char *fheldaction;
382} ramses_buttons [] = { 381} ramses_buttons [] = {
383 { Model_Ramses_MNCI, 382 { Model_Ramses_MNCI,
384 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 383 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
385 "devicebuttons/z_menu", 384 "devicebuttons/z_menu",
386 "QPE/TaskBar", "toggleMenu()", 385 "QPE/TaskBar", "toggleMenu()",
387 "QPE/TaskBar", "toggleStartMenu()" }, 386 "QPE/TaskBar", "toggleStartMenu()" },
388 { Model_Ramses_MNCI, 387 { Model_Ramses_MNCI,
389 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 388 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
390 "devicebuttons/ipaq_home", 389 "devicebuttons/ipaq_home",
391 "QPE/Launcher", "home()", 390 "QPE/Launcher", "home()",
392 "buttonsettings", "raise()" }, 391 "buttonsettings", "raise()" },
393}; 392};
394 393
395class Yopy : public ODevice { 394class Yopy : public ODevice {
396protected: 395protected:
397 virtual void init ( ); 396 virtual void init ( );
398 virtual void initButtons ( ); 397 virtual void initButtons ( );
399 398
400public: 399public:
401 virtual bool suspend ( ); 400 virtual bool suspend ( );
402 401
403 virtual bool setDisplayBrightness ( int b ); 402 virtual bool setDisplayBrightness ( int b );
404 virtual int displayBrightnessResolution ( ) const; 403 virtual int displayBrightnessResolution ( ) const;
405 404
406 static bool isYopy ( ); 405 static bool isYopy ( );
407}; 406};
408 407
409struct yopy_button { 408struct yopy_button {
410 Qt::Key code; 409 Qt::Key code;
411 char *utext; 410 char *utext;
412 char *pix; 411 char *pix;
413 char *fpressedservice; 412 char *fpressedservice;
414 char *fpressedaction; 413 char *fpressedaction;
415 char *fheldservice; 414 char *fheldservice;
diff --git a/libopie/odevicebutton.cpp b/libopie/odevicebutton.cpp
index 314eb51..647ac4b 100644
--- a/libopie/odevicebutton.cpp
+++ b/libopie/odevicebutton.cpp
@@ -1,239 +1,237 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qpixmap.h>
22#include <qstring.h>
23 21
24#include <qpe/qcopenvelope_qws.h> 22#include <qpe/qcopenvelope_qws.h>
25#include <opie/odevicebutton.h> 23#include <opie/odevicebutton.h>
26 24
27using namespace Opie; 25using namespace Opie;
28 26
29 27
30class OQCopMessageData { 28class OQCopMessageData {
31public: 29public:
32 QCString m_channel; 30 QCString m_channel;
33 QCString m_message; 31 QCString m_message;
34 QByteArray m_data; 32 QByteArray m_data;
35}; 33};
36 34
37 35
38OQCopMessage::OQCopMessage ( ) 36OQCopMessage::OQCopMessage ( )
39 : d ( 0 ) 37 : d ( 0 )
40{ 38{
41 init ( QCString ( ), QCString ( ), QByteArray ( )); 39 init ( QCString ( ), QCString ( ), QByteArray ( ));
42} 40}
43 41
44OQCopMessage::OQCopMessage ( const OQCopMessage &copy ) 42OQCopMessage::OQCopMessage ( const OQCopMessage &copy )
45 : d ( 0 ) 43 : d ( 0 )
46{ 44{
47 init ( copy. channel ( ), copy. message ( ), copy. data ( )); 45 init ( copy. channel ( ), copy. message ( ), copy. data ( ));
48} 46}
49 47
50OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign ) 48OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign )
51{ 49{
52 init ( assign. channel ( ), assign. message ( ), assign. data ( )); 50 init ( assign. channel ( ), assign. message ( ), assign. data ( ));
53 return *this; 51 return *this;
54} 52}
55 53
56OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg ) 54OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg )
57 : d ( 0 ) 55 : d ( 0 )
58{ 56{
59 init ( ch, m, arg ); 57 init ( ch, m, arg );
60} 58}
61 59
62void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg ) 60void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg )
63{ 61{
64 if ( !d ) 62 if ( !d )
65 d = new OQCopMessageData ( ); 63 d = new OQCopMessageData ( );
66 d-> m_channel = ch; 64 d-> m_channel = ch;
67 d-> m_message = m; 65 d-> m_message = m;
68 d-> m_data = arg; 66 d-> m_data = arg;
69} 67}
70 68
71bool OQCopMessage::send ( ) 69bool OQCopMessage::send ( )
72{ 70{
73 if ( d-> m_channel. isEmpty ( ) || d-> m_message. isEmpty ( ) ) 71 if ( d-> m_channel. isEmpty ( ) || d-> m_message. isEmpty ( ) )
74 return false; 72 return false;
75 73
76 QCopEnvelope e ( d-> m_channel, d-> m_message ); 74 QCopEnvelope e ( d-> m_channel, d-> m_message );
77 75
78 if ( d-> m_data. size ( )) 76 if ( d-> m_data. size ( ))
79 e. writeRawBytes ( d-> m_data. data ( ), d-> m_data. size ( )); 77 e. writeRawBytes ( d-> m_data. data ( ), d-> m_data. size ( ));
80 78
81 return true; 79 return true;
82} 80}
83 81
84QCString OQCopMessage::channel ( ) const 82QCString OQCopMessage::channel ( ) const
85{ 83{
86 return d-> m_channel; 84 return d-> m_channel;
87} 85}
88 86
89QCString OQCopMessage::message ( ) const 87QCString OQCopMessage::message ( ) const
90{ 88{
91 return d-> m_message; 89 return d-> m_message;
92} 90}
93 91
94QByteArray OQCopMessage::data ( ) const 92QByteArray OQCopMessage::data ( ) const
95{ 93{
96 return d-> m_data; 94 return d-> m_data;
97} 95}
98 96
99bool OQCopMessage::isNull() const 97bool OQCopMessage::isNull() const
100{ 98{
101 return d-> m_message.isNull() || d-> m_channel.isNull(); 99 return d-> m_message.isNull() || d-> m_channel.isNull();
102} 100}
103void OQCopMessage::setChannel ( const QCString &ch ) 101void OQCopMessage::setChannel ( const QCString &ch )
104{ 102{
105 d-> m_channel = ch; 103 d-> m_channel = ch;
106} 104}
107 105
108void OQCopMessage::setMessage ( const QCString &m ) 106void OQCopMessage::setMessage ( const QCString &m )
109{ 107{
110 d-> m_message = m; 108 d-> m_message = m;
111} 109}
112 110
113void OQCopMessage::setData ( const QByteArray &data ) 111void OQCopMessage::setData ( const QByteArray &data )
114{ 112{
115 d-> m_data = data; 113 d-> m_data = data;
116} 114}
117 115
118/*! \class Opie::ODeviceButton 116/*! \class Opie::ODeviceButton
119 \brief The Opie::ODeviceButton class represents a physical user mappable button on a Qtopia device. 117 \brief The Opie::ODeviceButton class represents a physical user mappable button on a Qtopia device.
120 118
121 This class represents a physical button on a Qtopia device. A 119 This class represents a physical button on a Qtopia device. A
122 device may have "user programmable" buttons. 120 device may have "user programmable" buttons.
123 The location and number of buttons will vary from device to 121 The location and number of buttons will vary from device to
124 device. userText() and pixmap() may be used to describe this button 122 device. userText() and pixmap() may be used to describe this button
125 to the user in help documentation. 123 to the user in help documentation.
126 124
127 \ingroup qtopiaemb 125 \ingroup qtopiaemb
128 \internal 126 \internal
129*/ 127*/
130 128
131ODeviceButton::ODeviceButton() 129ODeviceButton::ODeviceButton()
132{ 130{
133} 131}
134 132
135ODeviceButton::~ODeviceButton() 133ODeviceButton::~ODeviceButton()
136{ 134{
137} 135}
138 136
139/*! 137/*!
140 Returns the button's keycode. 138 Returns the button's keycode.
141 */ 139 */
142ushort ODeviceButton::keycode() const 140ushort ODeviceButton::keycode() const
143{ 141{
144 return m_Keycode; 142 return m_Keycode;
145} 143}
146 144
147 145
148/*! 146/*!
149 This function returns a human readable, translated description of the button. 147 This function returns a human readable, translated description of the button.
150 */ 148 */
151QString ODeviceButton::userText() const 149QString ODeviceButton::userText() const
152{ 150{
153 return m_UserText; 151 return m_UserText;
154} 152}
155 153
156/*! 154/*!
157 This function returns the pixmap for this button. If there isn't one 155 This function returns the pixmap for this button. If there isn't one
158 it will return an empty (null) pixmap. 156 it will return an empty (null) pixmap.
159 */ 157 */
160QPixmap ODeviceButton::pixmap() const 158QPixmap ODeviceButton::pixmap() const
161{ 159{
162 return m_Pixmap; 160 return m_Pixmap;
163} 161}
164 162
165/*! 163/*!
166 This function returns the factory preset (default) action for when this button 164 This function returns the factory preset (default) action for when this button
167 is pressed. The return value is a legal QCop message. 165 is pressed. The return value is a legal QCop message.
168 */ 166 */
169OQCopMessage ODeviceButton::factoryPresetPressedAction() const 167OQCopMessage ODeviceButton::factoryPresetPressedAction() const
170{ 168{
171 return m_FactoryPresetPressedAction; 169 return m_FactoryPresetPressedAction;
172} 170}
173 171
174/*! 172/*!
175 This function returns the user assigned action for when this button is pressed. 173 This function returns the user assigned action for when this button is pressed.
176 If no action is assigned, factoryPresetAction() is returned. 174 If no action is assigned, factoryPresetAction() is returned.
177 */ 175 */
178OQCopMessage ODeviceButton::pressedAction() const 176OQCopMessage ODeviceButton::pressedAction() const
179{ 177{
180 if (m_PressedAction.channel().isEmpty()) 178 if (m_PressedAction.channel().isEmpty())
181 return factoryPresetPressedAction(); 179 return factoryPresetPressedAction();
182 return m_PressedAction; 180 return m_PressedAction;
183} 181}
184 182
185/*! 183/*!
186 This function returns the factory preset (default) action for when this button 184 This function returns the factory preset (default) action for when this button
187 is pressed and held. The return value is a legal QCop message. 185 is pressed and held. The return value is a legal QCop message.
188 */ 186 */
189OQCopMessage ODeviceButton::factoryPresetHeldAction() const 187OQCopMessage ODeviceButton::factoryPresetHeldAction() const
190{ 188{
191 return m_FactoryPresetHeldAction; 189 return m_FactoryPresetHeldAction;
192} 190}
193 191
194/*! 192/*!
195 This function returns the user assigned action for when this button is pressed 193 This function returns the user assigned action for when this button is pressed
196 and held. If no action is assigned, factoryPresetAction() is returned. 194 and held. If no action is assigned, factoryPresetAction() is returned.
197 */ 195 */
198OQCopMessage ODeviceButton::heldAction() const 196OQCopMessage ODeviceButton::heldAction() const
199{ 197{
200 if (m_HeldAction.channel().isEmpty()) 198 if (m_HeldAction.channel().isEmpty())
201 return factoryPresetHeldAction(); 199 return factoryPresetHeldAction();
202 return m_HeldAction; 200 return m_HeldAction;
203} 201}
204 202
205void ODeviceButton::setKeycode(ushort keycode) 203void ODeviceButton::setKeycode(ushort keycode)
206{ 204{
207 m_Keycode = keycode; 205 m_Keycode = keycode;
208} 206}
209 207
210void ODeviceButton::setUserText(const QString& text) 208void ODeviceButton::setUserText(const QString& text)
211{ 209{
212 m_UserText = text; 210 m_UserText = text;
213} 211}
214 212
215void ODeviceButton::setPixmap(const QPixmap& picture) 213void ODeviceButton::setPixmap(const QPixmap& picture)
216{ 214{
217 m_Pixmap = picture; 215 m_Pixmap = picture;
218} 216}
219 217
220void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action) 218void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action)
221{ 219{
222 m_FactoryPresetPressedAction = action; 220 m_FactoryPresetPressedAction = action;
223} 221}
224 222
225 223
226void ODeviceButton::setPressedAction(const OQCopMessage& action) 224void ODeviceButton::setPressedAction(const OQCopMessage& action)
227{ 225{
228 m_PressedAction = action; 226 m_PressedAction = action;
229} 227}
230 228
231void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action) 229void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action)
232{ 230{
233 m_FactoryPresetHeldAction = action; 231 m_FactoryPresetHeldAction = action;
234} 232}
235 233
236void ODeviceButton::setHeldAction(const OQCopMessage& action) 234void ODeviceButton::setHeldAction(const OQCopMessage& action)
237{ 235{
238 m_HeldAction = action; 236 m_HeldAction = action;
239} 237}
diff --git a/libopie/ofiledialog.cc b/libopie/ofiledialog.cc
index 5511b24..47306b6 100644
--- a/libopie/ofiledialog.cc
+++ b/libopie/ofiledialog.cc
@@ -1,215 +1,212 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002,2003 <zecke@handhelds.org> 3             .=l. Copyright (c) 2002,2003 <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <qpe/applnk.h>
30#include <qpe/config.h> 29#include <qpe/config.h>
31#include <qpe/qpeapplication.h> 30#include <qpe/qpeapplication.h>
32 31
33#include <qfileinfo.h> 32#include <qfileinfo.h>
34#include <qstring.h>
35#include <qapplication.h>
36#include <qlayout.h> 33#include <qlayout.h>
37 34
38 35
39#include "ofiledialog.h" 36#include "ofiledialog.h"
40 37
41 38
42namespace { 39namespace {
43 /* 40 /*
44 * helper functions to load the start dir 41 * helper functions to load the start dir
45 * and to save it 42 * and to save it
46 * helper to extract the dir out of a file name 43 * helper to extract the dir out of a file name
47 */ 44 */
48 /** 45 /**
49 * This method will use Config( argv[0] ); 46 * This method will use Config( argv[0] );
50 * @param key The group key used 47 * @param key The group key used
51 */ 48 */
52 QString lastUsedDir( const QString& key ) { 49 QString lastUsedDir( const QString& key ) {
53 if ( qApp->argc() < 1 ) 50 if ( qApp->argc() < 1 )
54 return QString::null; 51 return QString::null;
55 52
56 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname 53 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
57 cfg.setGroup( key ); 54 cfg.setGroup( key );
58 return cfg.readEntry("LastDir", QPEApplication::documentDir() ); 55 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
59 } 56 }
60 57
61 void saveLastDir( const QString& key, const QString& file ) { 58 void saveLastDir( const QString& key, const QString& file ) {
62 if ( qApp->argc() < 1 ) 59 if ( qApp->argc() < 1 )
63 return; 60 return;
64 61
65 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); 62 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
66 cfg.setGroup( key ); 63 cfg.setGroup( key );
67 QFileInfo inf( file ); 64 QFileInfo inf( file );
68 cfg.writeEntry("LastDir", inf.dirPath( true ) ); 65 cfg.writeEntry("LastDir", inf.dirPath( true ) );
69 } 66 }
70}; 67};
71 68
72/** 69/**
73 * This constructs a modal dialog 70 * This constructs a modal dialog
74 * 71 *
75 * @param caption The caption of the dialog 72 * @param caption The caption of the dialog
76 * @param wid The parent widget 73 * @param wid The parent widget
77 * @param mode The mode of the OFileSelector @see OFileSelector 74 * @param mode The mode of the OFileSelector @see OFileSelector
78 * @param selector The selector of the OFileSelector 75 * @param selector The selector of the OFileSelector
79 * @param dirName the dir or resource to start from 76 * @param dirName the dir or resource to start from
80 * @param fileName a proposed or existing filename 77 * @param fileName a proposed or existing filename
81 * @param mimetypes The mimeTypes 78 * @param mimetypes The mimeTypes
82 */ 79 */
83OFileDialog::OFileDialog(const QString &caption, 80OFileDialog::OFileDialog(const QString &caption,
84 QWidget *wid, int mode, int selector, 81 QWidget *wid, int mode, int selector,
85 const QString &dirName, 82 const QString &dirName,
86 const QString &fileName, 83 const QString &fileName,
87 const QMap<QString,QStringList>& mimetypes ) 84 const QMap<QString,QStringList>& mimetypes )
88 : QDialog( wid, "OFileDialog", true ) 85 : QDialog( wid, "OFileDialog", true )
89{ 86{
90 // QVBoxLayout *lay = new QVBoxLayout(this); 87 // QVBoxLayout *lay = new QVBoxLayout(this);
91 //showMaximized(); 88 //showMaximized();
92 QVBoxLayout *lay = new QVBoxLayout(this ); 89 QVBoxLayout *lay = new QVBoxLayout(this );
93 file = new OFileSelector(this , mode, selector, 90 file = new OFileSelector(this , mode, selector,
94 dirName, fileName, 91 dirName, fileName,
95 mimetypes ); 92 mimetypes );
96 lay->addWidget( file ); 93 lay->addWidget( file );
97 94
98 //lay->addWidget( file ); 95 //lay->addWidget( file );
99 //showFullScreen(); 96 //showFullScreen();
100 setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); 97 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
101 connect(file, SIGNAL(fileSelected(const QString&) ), 98 connect(file, SIGNAL(fileSelected(const QString&) ),
102 this, SLOT(slotFileSelected(const QString&) ) ); 99 this, SLOT(slotFileSelected(const QString&) ) );
103 connect(file, SIGNAL(ok() ), 100 connect(file, SIGNAL(ok() ),
104 this, SLOT(slotSelectorOk()) ) ; 101 this, SLOT(slotSelectorOk()) ) ;
105 102
106 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); 103 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
107 104
108#if 0 105#if 0
109 connect(file, SIGNAL(dirSelected(const QString &) ), 106 connect(file, SIGNAL(dirSelected(const QString &) ),
110 this, SLOT(slotDirSelected(const QString &) ) ); 107 this, SLOT(slotDirSelected(const QString &) ) );
111#endif 108#endif
112} 109}
113/** 110/**
114 * @returns the mimetype of the selected 111 * @returns the mimetype of the selected
115 * currently it return QString::null 112 * currently it return QString::null
116 */ 113 */
117QString OFileDialog::mimetype()const 114QString OFileDialog::mimetype()const
118{ 115{
119 return QString::null; 116 return QString::null;
120} 117}
121 118
122/** 119/**
123 * @return the fileName 120 * @return the fileName
124 */ 121 */
125QString OFileDialog::fileName()const 122QString OFileDialog::fileName()const
126{ 123{
127 return file->selectedName(); 124 return file->selectedName();
128} 125}
129 126
130/** 127/**
131 * return a DocLnk to the current file 128 * return a DocLnk to the current file
132 */ 129 */
133DocLnk OFileDialog::selectedDocument()const 130DocLnk OFileDialog::selectedDocument()const
134{ 131{
135 return file->selectedDocument(); 132 return file->selectedDocument();
136} 133}
137 134
138/** 135/**
139 * This opens up a filedialog in Open mode 136 * This opens up a filedialog in Open mode
140 * 137 *
141 * @param selector the Selector Mode 138 * @param selector the Selector Mode
142 * @param startDir Where to start from 139 * @param startDir Where to start from
143 * @param file A proposed filename 140 * @param file A proposed filename
144 * @param mimes A list of MimeTypes 141 * @param mimes A list of MimeTypes
145 * @param wid the parent 142 * @param wid the parent
146 * @param caption of the dialog if QString::null tr("Open") will be used 143 * @param caption of the dialog if QString::null tr("Open") will be used
147 * @return the fileName or QString::null 144 * @return the fileName or QString::null
148 */ 145 */
149QString OFileDialog::getOpenFileName(int selector, 146QString OFileDialog::getOpenFileName(int selector,
150 const QString &_startDir, 147 const QString &_startDir,
151 const QString &file, 148 const QString &file,
152 const MimeTypes &mimes, 149 const MimeTypes &mimes,
153 QWidget *wid, 150 QWidget *wid,
154 const QString &caption ) 151 const QString &caption )
155{ 152{
156 QString ret; 153 QString ret;
157 QString startDir = _startDir; 154 QString startDir = _startDir;
158 if (startDir.isEmpty() ) 155 if (startDir.isEmpty() )
159 startDir = lastUsedDir( "FileDialog-OPEN" ); 156 startDir = lastUsedDir( "FileDialog-OPEN" );
160 157
161 158
162 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, 159 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
163 wid, OFileSelector::Open, selector, startDir, file, mimes); 160 wid, OFileSelector::Open, selector, startDir, file, mimes);
164 dlg.showMaximized(); 161 dlg.showMaximized();
165 if( dlg.exec() ) { 162 if( dlg.exec() ) {
166 ret = dlg.fileName(); 163 ret = dlg.fileName();
167 saveLastDir( "FileDialog-OPEN", ret ); 164 saveLastDir( "FileDialog-OPEN", ret );
168 } 165 }
169 166
170 return ret; 167 return ret;
171} 168}
172 169
173/** 170/**
174 * This opens up a file dialog in save mode 171 * This opens up a file dialog in save mode
175 * @see getOpenFileName 172 * @see getOpenFileName
176 */ 173 */
177QString OFileDialog::getSaveFileName(int selector, 174QString OFileDialog::getSaveFileName(int selector,
178 const QString &_startDir, 175 const QString &_startDir,
179 const QString &file, 176 const QString &file,
180 const MimeTypes &mimes, 177 const MimeTypes &mimes,
181 QWidget *wid, 178 QWidget *wid,
182 const QString &caption ) 179 const QString &caption )
183{ 180{
184 QString ret; 181 QString ret;
185 QString startDir = _startDir; 182 QString startDir = _startDir;
186 if (startDir.isEmpty() ) 183 if (startDir.isEmpty() )
187 startDir = lastUsedDir( "FileDialog-SAVE" ); 184 startDir = lastUsedDir( "FileDialog-SAVE" );
188 185
189 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, 186 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
190 wid, OFileSelector::Save, selector, startDir, file, mimes); 187 wid, OFileSelector::Save, selector, startDir, file, mimes);
191 dlg.showMaximized(); 188 dlg.showMaximized();
192 if( dlg.exec() ) { 189 if( dlg.exec() ) {
193 ret = dlg.fileName(); 190 ret = dlg.fileName();
194 saveLastDir( "FileDialog-SAVE", ret ); 191 saveLastDir( "FileDialog-SAVE", ret );
195 } 192 }
196 193
197 return ret; 194 return ret;
198} 195}
199 196
200void OFileDialog::slotFileSelected(const QString & ) 197void OFileDialog::slotFileSelected(const QString & )
201{ 198{
202 accept(); 199 accept();
203} 200}
204 201
205void OFileDialog::slotSelectorOk( ) 202void OFileDialog::slotSelectorOk( )
206{ 203{
207 accept(); 204 accept();
208} 205}
209 206
210void OFileDialog::slotDirSelected(const QString &dir ) 207void OFileDialog::slotDirSelected(const QString &dir )
211{ 208{
212 setCaption( dir ); 209 setCaption( dir );
213 // if mode 210 // if mode
214 //accept(); 211 //accept();
215} 212}
diff --git a/libopie/ofileselector.cpp b/libopie/ofileselector.cpp
index 9ac2981..1ba94ae 100644
--- a/libopie/ofileselector.cpp
+++ b/libopie/ofileselector.cpp
@@ -1,396 +1,391 @@
1#include <qcombobox.h> 1#include <qcombobox.h>
2#include <qdir.h> 2#include <qdir.h>
3#include <qhbox.h>
4#include <qheader.h>
5#include <qlabel.h> 3#include <qlabel.h>
6#include <qlayout.h> 4#include <qlayout.h>
7#include <qlineedit.h> 5#include <qlineedit.h>
8#include <qlistview.h>
9#include <qpopupmenu.h> 6#include <qpopupmenu.h>
10#include <qwidgetstack.h> 7#include <qwidgetstack.h>
11#include <qregexp.h>
12#include <qobjectlist.h>
13 8
14/* hacky but we need to get FileSelector::filter */ 9/* hacky but we need to get FileSelector::filter */
15#define private public 10#define private public
16#include <qpe/fileselector.h> 11#include <qpe/fileselector.h>
17#undef private 12#undef private
18 13
19#include <qpe/qpeapplication.h> 14#include <qpe/qpeapplication.h>
20#include <qpe/mimetype.h> 15#include <qpe/mimetype.h>
21#include <qpe/resource.h> 16#include <qpe/resource.h>
22#include <qpe/storage.h> 17#include <qpe/storage.h>
23 18
24#include "ofileselector_p.h" 19#include "ofileselector_p.h"
25#include "ofileselector.h" 20#include "ofileselector.h"
26 21
27 22
28 23
29OFileViewInterface::OFileViewInterface( OFileSelector* selector ) 24OFileViewInterface::OFileViewInterface( OFileSelector* selector )
30 : m_selector( selector ) { 25 : m_selector( selector ) {
31} 26}
32OFileViewInterface::~OFileViewInterface() { 27OFileViewInterface::~OFileViewInterface() {
33} 28}
34QString OFileViewInterface::name()const{ 29QString OFileViewInterface::name()const{
35 return m_name; 30 return m_name;
36} 31}
37void OFileViewInterface::setName( const QString& name ) { 32void OFileViewInterface::setName( const QString& name ) {
38 m_name = name; 33 m_name = name;
39} 34}
40OFileSelector* OFileViewInterface::selector()const { 35OFileSelector* OFileViewInterface::selector()const {
41 return m_selector; 36 return m_selector;
42} 37}
43DocLnk OFileViewInterface::selectedDocument()const { 38DocLnk OFileViewInterface::selectedDocument()const {
44 return DocLnk( selectedName() ); 39 return DocLnk( selectedName() );
45} 40}
46bool OFileViewInterface::showNew()const { 41bool OFileViewInterface::showNew()const {
47 return selector()->showNew(); 42 return selector()->showNew();
48} 43}
49bool OFileViewInterface::showClose()const { 44bool OFileViewInterface::showClose()const {
50 return selector()->showClose(); 45 return selector()->showClose();
51} 46}
52MimeTypes OFileViewInterface::mimeTypes()const { 47MimeTypes OFileViewInterface::mimeTypes()const {
53 return selector()->mimeTypes(); 48 return selector()->mimeTypes();
54} 49}
55QStringList OFileViewInterface::currentMimeType()const { 50QStringList OFileViewInterface::currentMimeType()const {
56 return selector()->currentMimeType(); 51 return selector()->currentMimeType();
57} 52}
58void OFileViewInterface::activate( const QString& ) { 53void OFileViewInterface::activate( const QString& ) {
59 // not implemented here 54 // not implemented here
60} 55}
61void OFileViewInterface::ok() { 56void OFileViewInterface::ok() {
62 emit selector()->ok(); 57 emit selector()->ok();
63} 58}
64void OFileViewInterface::cancel() { 59void OFileViewInterface::cancel() {
65 emit selector()->cancel(); 60 emit selector()->cancel();
66} 61}
67void OFileViewInterface::closeMe() { 62void OFileViewInterface::closeMe() {
68 emit selector()->closeMe(); 63 emit selector()->closeMe();
69} 64}
70void OFileViewInterface::fileSelected( const QString& str) { 65void OFileViewInterface::fileSelected( const QString& str) {
71 emit selector()->fileSelected( str); 66 emit selector()->fileSelected( str);
72} 67}
73void OFileViewInterface::fileSelected( const DocLnk& lnk) { 68void OFileViewInterface::fileSelected( const DocLnk& lnk) {
74 emit selector()->fileSelected( lnk ); 69 emit selector()->fileSelected( lnk );
75} 70}
76void OFileViewInterface::setCurrentFileName( const QString& str ) { 71void OFileViewInterface::setCurrentFileName( const QString& str ) {
77 selector()->m_lneEdit->setText( str ); 72 selector()->m_lneEdit->setText( str );
78} 73}
79QString OFileViewInterface::currentFileName()const{ 74QString OFileViewInterface::currentFileName()const{
80 return selector()->m_lneEdit->text(); 75 return selector()->m_lneEdit->text();
81} 76}
82QString OFileViewInterface::startDirectory()const{ 77QString OFileViewInterface::startDirectory()const{
83 return selector()->m_startDir; 78 return selector()->m_startDir;
84} 79}
85 80
86 81
87ODocumentFileView::ODocumentFileView( OFileSelector* selector ) 82ODocumentFileView::ODocumentFileView( OFileSelector* selector )
88 : OFileViewInterface( selector ) { 83 : OFileViewInterface( selector ) {
89 m_selector = 0; 84 m_selector = 0;
90 setName( QObject::tr("Documents") ); 85 setName( QObject::tr("Documents") );
91} 86}
92ODocumentFileView::~ODocumentFileView() { 87ODocumentFileView::~ODocumentFileView() {
93 88
94} 89}
95QString ODocumentFileView::selectedName()const { 90QString ODocumentFileView::selectedName()const {
96 if (!m_selector) 91 if (!m_selector)
97 return QString::null; 92 return QString::null;
98 93
99 return m_selector->selectedDocument().file(); 94 return m_selector->selectedDocument().file();
100} 95}
101QString ODocumentFileView::selectedPath()const { 96QString ODocumentFileView::selectedPath()const {
102 return QPEApplication::documentDir(); 97 return QPEApplication::documentDir();
103} 98}
104QString ODocumentFileView::directory()const { 99QString ODocumentFileView::directory()const {
105 return selectedPath(); 100 return selectedPath();
106} 101}
107void ODocumentFileView::reread() { 102void ODocumentFileView::reread() {
108 if (!m_selector) 103 if (!m_selector)
109 return; 104 return;
110 105
111 m_selector->setNewVisible( showNew() ); 106 m_selector->setNewVisible( showNew() );
112 m_selector->setCloseVisible( showClose() ); 107 m_selector->setCloseVisible( showClose() );
113 m_selector->filter = currentMimeType().join(";"); 108 m_selector->filter = currentMimeType().join(";");
114 m_selector->reread(); 109 m_selector->reread();
115} 110}
116int ODocumentFileView::fileCount()const { 111int ODocumentFileView::fileCount()const {
117 if (!m_selector) 112 if (!m_selector)
118 return -1; 113 return -1;
119 114
120 return m_selector->fileCount(); 115 return m_selector->fileCount();
121} 116}
122DocLnk ODocumentFileView::selectedDocument()const { 117DocLnk ODocumentFileView::selectedDocument()const {
123 if (!m_selector) 118 if (!m_selector)
124 return DocLnk(); 119 return DocLnk();
125 120
126 return m_selector->selectedDocument(); 121 return m_selector->selectedDocument();
127} 122}
128QWidget* ODocumentFileView::widget( QWidget* parent ) { 123QWidget* ODocumentFileView::widget( QWidget* parent ) {
129 if (!m_selector ) { 124 if (!m_selector ) {
130 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); 125 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() );
131 QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ), 126 QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ),
132 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); 127 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) );
133 QObject::connect(m_selector, SIGNAL(closeMe() ), 128 QObject::connect(m_selector, SIGNAL(closeMe() ),
134 selector(), SIGNAL(closeMe() ) ); 129 selector(), SIGNAL(closeMe() ) );
135 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ), 130 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ),
136 selector(), SIGNAL(newSelected(const DocLnk& ) ) ); 131 selector(), SIGNAL(newSelected(const DocLnk& ) ) );
137 } 132 }
138 133
139 return m_selector; 134 return m_selector;
140} 135}
141 136
142/* 137/*
143 * This is the file system view used 138 * This is the file system view used
144 * we use a QListView + QListViewItems for it 139 * we use a QListView + QListViewItems for it
145 */ 140 */
146 141
147OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, 142OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap,
148 const QString& path, const QString& date, 143 const QString& path, const QString& date,
149 const QString& size, const QString& dir, 144 const QString& size, const QString& dir,
150 bool isLocked, bool isDir ) 145 bool isLocked, bool isDir )
151 : QListViewItem( view ) 146 : QListViewItem( view )
152{ 147{
153 setPixmap(0, pixmap ); 148 setPixmap(0, pixmap );
154 setText(1, path ); 149 setText(1, path );
155 setText(2, size ); 150 setText(2, size );
156 setText(3, date ); 151 setText(3, date );
157 m_isDir = isDir; 152 m_isDir = isDir;
158 m_dir = dir; 153 m_dir = dir;
159 m_locked = isLocked; 154 m_locked = isLocked;
160} 155}
161OFileSelectorItem::~OFileSelectorItem() { 156OFileSelectorItem::~OFileSelectorItem() {
162 157
163} 158}
164bool OFileSelectorItem::isLocked()const { 159bool OFileSelectorItem::isLocked()const {
165 return m_locked; 160 return m_locked;
166} 161}
167QString OFileSelectorItem::directory()const { 162QString OFileSelectorItem::directory()const {
168 return m_dir; 163 return m_dir;
169} 164}
170bool OFileSelectorItem::isDir()const { 165bool OFileSelectorItem::isDir()const {
171 return m_isDir; 166 return m_isDir;
172} 167}
173QString OFileSelectorItem::path()const { 168QString OFileSelectorItem::path()const {
174 return text( 1 ); 169 return text( 1 );
175} 170}
176QString OFileSelectorItem::key( int id, bool )const { 171QString OFileSelectorItem::key( int id, bool )const {
177 QString ke; 172 QString ke;
178 if( id == 0 || id == 1 ){ // name 173 if( id == 0 || id == 1 ){ // name
179 if( m_isDir ){ 174 if( m_isDir ){
180 ke.append("0" ); 175 ke.append("0" );
181 ke.append( text(1) ); 176 ke.append( text(1) );
182 }else{ 177 }else{
183 ke.append("1" ); 178 ke.append("1" );
184 ke.append( text(1) ); 179 ke.append( text(1) );
185 } 180 }
186 return ke; 181 return ke;
187 }else 182 }else
188 return text( id ); 183 return text( id );
189 184
190} 185}
191 186
192OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, 187OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir,
193 OFileSelector* sel) 188 OFileSelector* sel)
194 : QWidget( parent ), m_sel( sel ) { 189 : QWidget( parent ), m_sel( sel ) {
195 m_all = false; 190 m_all = false;
196 QVBoxLayout* lay = new QVBoxLayout( this ); 191 QVBoxLayout* lay = new QVBoxLayout( this );
197 m_currentDir = startDir; 192 m_currentDir = startDir;
198 193
199 /* 194 /*
200 * now we add a special bar 195 * now we add a special bar
201 * One Button For Up 196 * One Button For Up
202 * Home 197 * Home
203 * Doc 198 * Doc
204 * And a dropdown menu with FileSystems 199 * And a dropdown menu with FileSystems
205 * FUTURE: one to change dir with lineedit 200 * FUTURE: one to change dir with lineedit
206 * Bookmarks 201 * Bookmarks
207 * Create Dir 202 * Create Dir
208 */ 203 */
209 QHBox* box = new QHBox(this ); 204 QHBox* box = new QHBox(this );
210 box->setBackgroundMode( PaletteButton ); 205 box->setBackgroundMode( PaletteButton );
211 box->setSpacing( 0 ); 206 box->setSpacing( 0 );
212 207
213 QToolButton *btn = new QToolButton( box ); 208 QToolButton *btn = new QToolButton( box );
214 btn->setIconSet( Resource::loadIconSet("up") ); 209 btn->setIconSet( Resource::loadIconSet("up") );
215 connect(btn, SIGNAL(clicked() ), 210 connect(btn, SIGNAL(clicked() ),
216 this, SLOT( cdUP() ) ); 211 this, SLOT( cdUP() ) );
217 212
218 btn = new QToolButton( box ); 213 btn = new QToolButton( box );
219 btn->setIconSet( Resource::loadIconSet("home") ); 214 btn->setIconSet( Resource::loadIconSet("home") );
220 connect(btn, SIGNAL(clicked() ), 215 connect(btn, SIGNAL(clicked() ),
221 this, SLOT( cdHome() ) ); 216 this, SLOT( cdHome() ) );
222 217
223 btn = new QToolButton( box ); 218 btn = new QToolButton( box );
224 btn->setIconSet( Resource::loadIconSet("DocsIcon") ); 219 btn->setIconSet( Resource::loadIconSet("DocsIcon") );
225 connect(btn, SIGNAL(clicked() ), 220 connect(btn, SIGNAL(clicked() ),
226 this, SLOT(cdDoc() ) ); 221 this, SLOT(cdDoc() ) );
227 222
228 m_btnNew = new QToolButton( box ); 223 m_btnNew = new QToolButton( box );
229 m_btnNew->setIconSet( Resource::loadIconSet("new") ); 224 m_btnNew->setIconSet( Resource::loadIconSet("new") );
230 connect(m_btnNew, SIGNAL(clicked() ), 225 connect(m_btnNew, SIGNAL(clicked() ),
231 this, SLOT(slotNew() ) ); 226 this, SLOT(slotNew() ) );
232 227
233 228
234 m_btnClose = new QToolButton( box ); 229 m_btnClose = new QToolButton( box );
235 m_btnClose->setIconSet( Resource::loadIconSet("close") ); 230 m_btnClose->setIconSet( Resource::loadIconSet("close") );
236 connect(m_btnClose, SIGNAL(clicked() ), 231 connect(m_btnClose, SIGNAL(clicked() ),
237 selector(), SIGNAL(closeMe() ) ); 232 selector(), SIGNAL(closeMe() ) );
238 233
239 btn = new QToolButton( box ); 234 btn = new QToolButton( box );
240 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); 235 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") );
241 236
242 /* let's fill device parts */ 237 /* let's fill device parts */
243 QPopupMenu* pop = new QPopupMenu(this); 238 QPopupMenu* pop = new QPopupMenu(this);
244 connect(pop, SIGNAL( activated(int) ), 239 connect(pop, SIGNAL( activated(int) ),
245 this, SLOT(slotFSActivated(int) ) ); 240 this, SLOT(slotFSActivated(int) ) );
246 241
247 StorageInfo storage; 242 StorageInfo storage;
248 const QList<FileSystem> &fs = storage.fileSystems(); 243 const QList<FileSystem> &fs = storage.fileSystems();
249 QListIterator<FileSystem> it(fs); 244 QListIterator<FileSystem> it(fs);
250 for ( ; it.current(); ++it ) { 245 for ( ; it.current(); ++it ) {
251 const QString disk = (*it)->name(); 246 const QString disk = (*it)->name();
252 const QString path = (*it)->path(); 247 const QString path = (*it)->path();
253 m_dev.insert( disk, path ); 248 m_dev.insert( disk, path );
254 pop->insertItem( disk ); 249 pop->insertItem( disk );
255 } 250 }
256 m_fsPop = pop; 251 m_fsPop = pop;
257 252
258 253
259 btn->setPopup( pop ); 254 btn->setPopup( pop );
260 255
261 lay->addWidget( box ); 256 lay->addWidget( box );
262 257
263 m_view = new QListView( this ); 258 m_view = new QListView( this );
264 259
265 m_view->installEventFilter(this); 260 m_view->installEventFilter(this);
266 261
267 QPEApplication::setStylusOperation( m_view->viewport(), 262 QPEApplication::setStylusOperation( m_view->viewport(),
268 QPEApplication::RightOnHold); 263 QPEApplication::RightOnHold);
269 m_view->addColumn(" " ); 264 m_view->addColumn(" " );
270 m_view->addColumn(tr("Name"), 135 ); 265 m_view->addColumn(tr("Name"), 135 );
271 m_view->addColumn(tr("Size"), -1 ); 266 m_view->addColumn(tr("Size"), -1 );
272 m_view->addColumn(tr("Date"), 60 ); 267 m_view->addColumn(tr("Date"), 60 );
273 m_view->addColumn(tr("Mime Type"), -1 ); 268 m_view->addColumn(tr("Mime Type"), -1 );
274 269
275 270
276 m_view->setSorting( 1 ); 271 m_view->setSorting( 1 );
277 m_view->setAllColumnsShowFocus( TRUE ); 272 m_view->setAllColumnsShowFocus( TRUE );
278 273
279 lay->addWidget( m_view, 1000 ); 274 lay->addWidget( m_view, 1000 );
280 connectSlots(); 275 connectSlots();
281} 276}
282OFileViewFileListView::~OFileViewFileListView() { 277OFileViewFileListView::~OFileViewFileListView() {
283} 278}
284void OFileViewFileListView::slotNew() { 279void OFileViewFileListView::slotNew() {
285 DocLnk lnk; 280 DocLnk lnk;
286 emit selector()->newSelected( lnk ); 281 emit selector()->newSelected( lnk );
287} 282}
288OFileSelectorItem* OFileViewFileListView::currentItem()const{ 283OFileSelectorItem* OFileViewFileListView::currentItem()const{
289 QListViewItem* item = m_view->currentItem(); 284 QListViewItem* item = m_view->currentItem();
290 if (!item ) 285 if (!item )
291 return 0l; 286 return 0l;
292 287
293 return static_cast<OFileSelectorItem*>(item); 288 return static_cast<OFileSelectorItem*>(item);
294} 289}
295void OFileViewFileListView::reread( bool all ) { 290void OFileViewFileListView::reread( bool all ) {
296 m_view->clear(); 291 m_view->clear();
297 292
298 if (selector()->showClose() ) 293 if (selector()->showClose() )
299 m_btnClose->show(); 294 m_btnClose->show();
300 else 295 else
301 m_btnClose->hide(); 296 m_btnClose->hide();
302 297
303 if (selector()->showNew() ) 298 if (selector()->showNew() )
304 m_btnNew->show(); 299 m_btnNew->show();
305 else 300 else
306 m_btnNew->hide(); 301 m_btnNew->hide();
307 302
308 m_mimes = selector()->currentMimeType(); 303 m_mimes = selector()->currentMimeType();
309 m_all = all; 304 m_all = all;
310 305
311 QDir dir( m_currentDir ); 306 QDir dir( m_currentDir );
312 if (!dir.exists() ) 307 if (!dir.exists() )
313 return; 308 return;
314 309
315 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); 310 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
316 int filter; 311 int filter;
317 if (m_all ) 312 if (m_all )
318 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; 313 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
319 else 314 else
320 filter = QDir::Files | QDir::Dirs | QDir::All; 315 filter = QDir::Files | QDir::Dirs | QDir::All;
321 dir.setFilter( filter ); 316 dir.setFilter( filter );
322 317
323 // now go through all files 318 // now go through all files
324 const QFileInfoList *list = dir.entryInfoList(); 319 const QFileInfoList *list = dir.entryInfoList();
325 if (!list) { 320 if (!list) {
326 cdUP(); 321 cdUP();
327 return; 322 return;
328 } 323 }
329 QFileInfoListIterator it( *list ); 324 QFileInfoListIterator it( *list );
330 QFileInfo *fi; 325 QFileInfo *fi;
331 while( (fi=it.current() ) ){ 326 while( (fi=it.current() ) ){
332 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ 327 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){
333 ++it; 328 ++it;
334 continue; 329 continue;
335 } 330 }
336 331
337 /* 332 /*
338 * It is a symlink we try to resolve it now but don't let us attack by DOS 333 * It is a symlink we try to resolve it now but don't let us attack by DOS
339 * 334 *
340 */ 335 */
341 if( fi->isSymLink() ){ 336 if( fi->isSymLink() ){
342 QString file = fi->dirPath( true ) + "/" + fi->readLink(); 337 QString file = fi->dirPath( true ) + "/" + fi->readLink();
343 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos 338 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos
344 QFileInfo info( file ); 339 QFileInfo info( file );
345 if( !info.exists() ){ 340 if( !info.exists() ){
346 addSymlink( fi, TRUE ); 341 addSymlink( fi, TRUE );
347 break; 342 break;
348 }else if( info.isDir() ){ 343 }else if( info.isDir() ){
349 addDir( fi, TRUE ); 344 addDir( fi, TRUE );
350 break; 345 break;
351 }else if( info.isFile() ){ 346 }else if( info.isFile() ){
352 addFile( fi, TRUE ); 347 addFile( fi, TRUE );
353 break; 348 break;
354 }else if( info.isSymLink() ){ 349 }else if( info.isSymLink() ){
355 file = info.dirPath(true ) + "/" + info.readLink() ; 350 file = info.dirPath(true ) + "/" + info.readLink() ;
356 break; 351 break;
357 }else if( i == 4){ // couldn't resolve symlink add it as symlink 352 }else if( i == 4){ // couldn't resolve symlink add it as symlink
358 addSymlink( fi ); 353 addSymlink( fi );
359 } 354 }
360 } // off for loop for symlink resolving 355 } // off for loop for symlink resolving
361 }else if( fi->isDir() ) 356 }else if( fi->isDir() )
362 addDir( fi ); 357 addDir( fi );
363 else if( fi->isFile() ) 358 else if( fi->isFile() )
364 addFile( fi ); 359 addFile( fi );
365 360
366 ++it; 361 ++it;
367 } // of while loop 362 } // of while loop
368 m_view->sort(); 363 m_view->sort();
369 364
370} 365}
371int OFileViewFileListView::fileCount()const{ 366int OFileViewFileListView::fileCount()const{
372 return m_view->childCount(); 367 return m_view->childCount();
373} 368}
374QString OFileViewFileListView::currentDir()const{ 369QString OFileViewFileListView::currentDir()const{
375 return m_currentDir; 370 return m_currentDir;
376} 371}
377OFileSelector* OFileViewFileListView::selector() { 372OFileSelector* OFileViewFileListView::selector() {
378 return m_sel; 373 return m_sel;
379} 374}
380 375
381bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { 376bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) {
382 if ( e->type() == QEvent::KeyPress ) { 377 if ( e->type() == QEvent::KeyPress ) {
383 QKeyEvent *k = (QKeyEvent *)e; 378 QKeyEvent *k = (QKeyEvent *)e;
384 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { 379 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
385 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); 380 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
386 return true; 381 return true;
387 } 382 }
388 } 383 }
389 return false; 384 return false;
390} 385}
391 386
392 387
393void OFileViewFileListView::connectSlots() { 388void OFileViewFileListView::connectSlots() {
394 connect(m_view, SIGNAL(clicked(QListViewItem*) ), 389 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
395 this, SLOT(slotCurrentChanged(QListViewItem*) ) ); 390 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
396 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), 391 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ),
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp
index c8471cc..7e07008 100644
--- a/libopie/ofontselector.cpp
+++ b/libopie/ofontselector.cpp
@@ -1,412 +1,411 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qlistbox.h> 30#include <qlistbox.h>
31#include <qcombobox.h> 31#include <qcombobox.h>
32#include <qlabel.h> 32#include <qlabel.h>
33#include <qfont.h>
34#include <qmultilineedit.h> 33#include <qmultilineedit.h>
35 34
36#include <qpe/fontdatabase.h> 35#include <qpe/fontdatabase.h>
37 36
38#include "ofontselector.h" 37#include "ofontselector.h"
39 38
40class OFontSelectorPrivate { 39class OFontSelectorPrivate {
41public: 40public:
42 QListBox * m_font_family_list; 41 QListBox * m_font_family_list;
43 QComboBox * m_font_style_list; 42 QComboBox * m_font_style_list;
44 QComboBox * m_font_size_list; 43 QComboBox * m_font_size_list;
45 QMultiLineEdit *m_preview; 44 QMultiLineEdit *m_preview;
46 45
47 bool m_pointbug : 1; 46 bool m_pointbug : 1;
48 47
49 FontDatabase m_fdb; 48 FontDatabase m_fdb;
50}; 49};
51 50
52namespace { 51namespace {
53 52
54class FontListItem : public QListBoxText { 53class FontListItem : public QListBoxText {
55public: 54public:
56 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) 55 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( )
57 { 56 {
58 m_name = t; 57 m_name = t;
59 m_styles = styles; 58 m_styles = styles;
60 m_sizes = sizes; 59 m_sizes = sizes;
61 60
62 QString str = t; 61 QString str = t;
63 str [0] = str [0]. upper ( ); 62 str [0] = str [0]. upper ( );
64 setText ( str ); 63 setText ( str );
65 } 64 }
66 65
67 QString family ( ) const 66 QString family ( ) const
68 { 67 {
69 return m_name; 68 return m_name;
70 } 69 }
71 70
72 const QStringList &styles ( ) const 71 const QStringList &styles ( ) const
73 { 72 {
74 return m_styles; 73 return m_styles;
75 } 74 }
76 75
77 const QValueList<int> &sizes ( ) const 76 const QValueList<int> &sizes ( ) const
78 { 77 {
79 return m_sizes; 78 return m_sizes;
80 } 79 }
81 80
82private: 81private:
83 QStringList m_styles; 82 QStringList m_styles;
84 QValueList<int> m_sizes; 83 QValueList<int> m_sizes;
85 QString m_name; 84 QString m_name;
86}; 85};
87 86
88 87
89static int findItemCB ( QComboBox *box, const QString &str ) 88static int findItemCB ( QComboBox *box, const QString &str )
90{ 89{
91 for ( int i = 0; i < box-> count ( ); i++ ) { 90 for ( int i = 0; i < box-> count ( ); i++ ) {
92 if ( box-> text ( i ) == str ) 91 if ( box-> text ( i ) == str )
93 return i; 92 return i;
94 } 93 }
95 return -1; 94 return -1;
96} 95}
97 96
98} 97}
99/* static same as anon. namespace */ 98/* static same as anon. namespace */
100static int qt_version ( ) 99static int qt_version ( )
101{ 100{
102 const char *qver = qVersion ( ); 101 const char *qver = qVersion ( );
103 102
104 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); 103 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' );
105} 104}
106 105
107/** 106/**
108 * Constructs the Selector object 107 * Constructs the Selector object
109 * @param withpreview If a font preview should be given 108 * @param withpreview If a font preview should be given
110 * @param parent The parent of the Font Selector 109 * @param parent The parent of the Font Selector
111 * @param name The name of the object 110 * @param name The name of the object
112 * @param fl WidgetFlags 111 * @param fl WidgetFlags
113 */ 112 */
114OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) 113OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl )
115{ 114{
116 d = new OFontSelectorPrivate ( ); 115 d = new OFontSelectorPrivate ( );
117 116
118 QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); 117 QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 );
119 gridLayout->setRowStretch ( 4, 10 ); 118 gridLayout->setRowStretch ( 4, 10 );
120 119
121 d-> m_font_family_list = new QListBox( this, "FontListBox" ); 120 d-> m_font_family_list = new QListBox( this, "FontListBox" );
122 gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 ); 121 gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 );
123 connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); 122 connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) );
124 123
125 QLabel *label = new QLabel( tr( "Style" ), this ); 124 QLabel *label = new QLabel( tr( "Style" ), this );
126 gridLayout->addWidget( label, 0, 1 ); 125 gridLayout->addWidget( label, 0, 1 );
127 126
128 d-> m_font_style_list = new QComboBox( this, "StyleListBox" ); 127 d-> m_font_style_list = new QComboBox( this, "StyleListBox" );
129 connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); 128 connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) );
130 gridLayout->addWidget( d-> m_font_style_list, 1, 1 ); 129 gridLayout->addWidget( d-> m_font_style_list, 1, 1 );
131 130
132 label = new QLabel( tr( "Size" ), this ); 131 label = new QLabel( tr( "Size" ), this );
133 gridLayout->addWidget( label, 2, 1 ); 132 gridLayout->addWidget( label, 2, 1 );
134 133
135 d-> m_font_size_list = new QComboBox( this, "SizeListBox" ); 134 d-> m_font_size_list = new QComboBox( this, "SizeListBox" );
136 connect( d-> m_font_size_list, SIGNAL( activated( int ) ), 135 connect( d-> m_font_size_list, SIGNAL( activated( int ) ),
137 this, SLOT( fontSizeClicked( int ) ) ); 136 this, SLOT( fontSizeClicked( int ) ) );
138 gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); 137 gridLayout->addWidget( d-> m_font_size_list, 3, 1 );
139 138
140 d-> m_pointbug = ( qt_version ( ) <= 233 ); 139 d-> m_pointbug = ( qt_version ( ) <= 233 );
141 140
142 if ( withpreview ) { 141 if ( withpreview ) {
143 d-> m_preview = new QMultiLineEdit ( this, "Preview" ); 142 d-> m_preview = new QMultiLineEdit ( this, "Preview" );
144 d-> m_preview-> setAlignment ( AlignCenter ); 143 d-> m_preview-> setAlignment ( AlignCenter );
145 d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); 144 d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth );
146 d-> m_preview-> setMargin ( 3 ); 145 d-> m_preview-> setMargin ( 3 );
147 d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); 146 d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ));
148 gridLayout-> addRowSpacing ( 5, 4 ); 147 gridLayout-> addRowSpacing ( 5, 4 );
149 gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 ); 148 gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 );
150 gridLayout-> setRowStretch ( 6, 5 ); 149 gridLayout-> setRowStretch ( 6, 5 );
151 } 150 }
152 else 151 else
153 d-> m_preview = 0; 152 d-> m_preview = 0;
154 153
155 loadFonts ( d-> m_font_family_list ); 154 loadFonts ( d-> m_font_family_list );
156} 155}
157 156
158OFontSelector::~OFontSelector ( ) 157OFontSelector::~OFontSelector ( )
159{ 158{
160 delete d; 159 delete d;
161} 160}
162 161
163/** 162/**
164 * This methods tries to set the font 163 * This methods tries to set the font
165 * @param f The wishes font 164 * @param f The wishes font
166 * @return success or failure 165 * @return success or failure
167 */ 166 */
168bool OFontSelector::setSelectedFont ( const QFont &f ) 167bool OFontSelector::setSelectedFont ( const QFont &f )
169{ 168{
170 return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); 169 return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( )));
171} 170}
172 171
173 172
174/** 173/**
175 * This is an overloaded method @see setSelectedFont 174 * This is an overloaded method @see setSelectedFont
176 * @param familyStr The family of the font 175 * @param familyStr The family of the font
177 * @param styleStr The style of the font 176 * @param styleStr The style of the font
178 * @param sizeVal The size of font 177 * @param sizeVal The size of font
179 * @param charset The charset to be used. Will be deprecated by QT3 178 * @param charset The charset to be used. Will be deprecated by QT3
180 */ 179 */
181bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) 180bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset )
182{ 181{
183 QString sizeStr = QString::number ( sizeVal ); 182 QString sizeStr = QString::number ( sizeVal );
184 183
185 QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); 184 QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr );
186 if ( !family ) 185 if ( !family )
187 family = d-> m_font_family_list-> findItem ( "Helvetica" ); 186 family = d-> m_font_family_list-> findItem ( "Helvetica" );
188 if ( !family ) 187 if ( !family )
189 family = d-> m_font_family_list-> firstItem ( ); 188 family = d-> m_font_family_list-> firstItem ( );
190 d-> m_font_family_list-> setCurrentItem ( family ); 189 d-> m_font_family_list-> setCurrentItem ( family );
191 fontFamilyClicked ( d-> m_font_family_list-> index ( family )); 190 fontFamilyClicked ( d-> m_font_family_list-> index ( family ));
192 191
193 int style = findItemCB ( d-> m_font_style_list, styleStr ); 192 int style = findItemCB ( d-> m_font_style_list, styleStr );
194 if ( style < 0 ) 193 if ( style < 0 )
195 style = findItemCB ( d-> m_font_style_list, "Regular" ); 194 style = findItemCB ( d-> m_font_style_list, "Regular" );
196 if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 ) 195 if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 )
197 style = 0; 196 style = 0;
198 d-> m_font_style_list-> setCurrentItem ( style ); 197 d-> m_font_style_list-> setCurrentItem ( style );
199 fontStyleClicked ( style ); 198 fontStyleClicked ( style );
200 199
201 int size = findItemCB ( d-> m_font_size_list, sizeStr ); 200 int size = findItemCB ( d-> m_font_size_list, sizeStr );
202 if ( size < 0 ) 201 if ( size < 0 )
203 size = findItemCB ( d-> m_font_size_list, "10" ); 202 size = findItemCB ( d-> m_font_size_list, "10" );
204 if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 ) 203 if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 )
205 size = 0; 204 size = 0;
206 d-> m_font_size_list-> setCurrentItem ( size ); 205 d-> m_font_size_list-> setCurrentItem ( size );
207 fontSizeClicked ( size ); 206 fontSizeClicked ( size );
208 207
209 return (( family ) && ( style >= 0 ) && ( size >= 0 )); 208 return (( family ) && ( style >= 0 ) && ( size >= 0 ));
210} 209}
211 210
212/** 211/**
213 * This method returns the name, style and size of the currently selected 212 * This method returns the name, style and size of the currently selected
214 * font or false if no font is selected 213 * font or false if no font is selected
215 * @param family The font family will be written there 214 * @param family The font family will be written there
216 * @param style The style will be written there 215 * @param style The style will be written there
217 * @param size The size will be written there 216 * @param size The size will be written there
218 * @return success or failure 217 * @return success or failure
219 */ 218 */
220bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) 219bool OFontSelector::selectedFont ( QString &family, QString &style, int &size )
221{ 220{
222 QString dummy; 221 QString dummy;
223 return selectedFont ( family, style, size, dummy ); 222 return selectedFont ( family, style, size, dummy );
224} 223}
225 224
226 225
227/** 226/**
228 * This method does return the font family or QString::null if there is 227 * This method does return the font family or QString::null if there is
229 * no font item selected 228 * no font item selected
230 * @return the font family 229 * @return the font family
231 */ 230 */
232QString OFontSelector::fontFamily ( ) const 231QString OFontSelector::fontFamily ( ) const
233{ 232{
234 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); 233 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
235 234
236 return fli ? fli-> family ( ) : QString::null; 235 return fli ? fli-> family ( ) : QString::null;
237} 236}
238 237
239/** 238/**
240 * This method will return the style of the font or QString::null 239 * This method will return the style of the font or QString::null
241 * @return the style of the font 240 * @return the style of the font
242 */ 241 */
243QString OFontSelector::fontStyle ( ) const 242QString OFontSelector::fontStyle ( ) const
244{ 243{
245 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); 244 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
246 int fst = d-> m_font_style_list-> currentItem ( ); 245 int fst = d-> m_font_style_list-> currentItem ( );
247 246
248 return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; 247 return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null;
249} 248}
250 249
251/** 250/**
252 * This method will return the font size or 10 if no font size is available 251 * This method will return the font size or 10 if no font size is available
253 */ 252 */
254int OFontSelector::fontSize ( ) const 253int OFontSelector::fontSize ( ) const
255{ 254{
256 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); 255 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
257 int fsi = d-> m_font_size_list-> currentItem ( ); 256 int fsi = d-> m_font_size_list-> currentItem ( );
258 257
259 return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; 258 return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10;
260} 259}
261 260
262/** 261/**
263 * returns the charset of the font or QString::null 262 * returns the charset of the font or QString::null
264 */ 263 */
265QString OFontSelector::fontCharSet ( ) const 264QString OFontSelector::fontCharSet ( ) const
266{ 265{
267 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); 266 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
268 267
269 return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null; 268 return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null;
270} 269}
271 270
272/** 271/**
273 * Overloaded member function see above 272 * Overloaded member function see above
274 * @see selectedFont 273 * @see selectedFont
275 */ 274 */
276bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) 275bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset )
277{ 276{
278 int ffa = d-> m_font_family_list-> currentItem ( ); 277 int ffa = d-> m_font_family_list-> currentItem ( );
279 int fst = d-> m_font_style_list-> currentItem ( ); 278 int fst = d-> m_font_style_list-> currentItem ( );
280 int fsi = d-> m_font_size_list-> currentItem ( ); 279 int fsi = d-> m_font_size_list-> currentItem ( );
281 280
282 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); 281 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa );
283 282
284 if ( fli ) { 283 if ( fli ) {
285 family = fli-> family ( ); 284 family = fli-> family ( );
286 style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; 285 style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null;
287 size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; 286 size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10;
288 charset = d-> m_fdb. charSets ( fli-> family ( )) [0]; 287 charset = d-> m_fdb. charSets ( fli-> family ( )) [0];
289 288
290 return true; 289 return true;
291 } 290 }
292 else 291 else
293 return false; 292 return false;
294} 293}
295 294
296 295
297 296
298 297
299void OFontSelector::loadFonts ( QListBox *list ) 298void OFontSelector::loadFonts ( QListBox *list )
300{ 299{
301 QStringList f = d-> m_fdb. families ( ); 300 QStringList f = d-> m_fdb. families ( );
302 301
303 for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { 302 for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) {
304 QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); 303 QValueList <int> ps = d-> m_fdb. pointSizes ( *it );
305 304
306 if ( d-> m_pointbug ) { 305 if ( d-> m_pointbug ) {
307 for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ ) 306 for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ )
308 *it /= 10; 307 *it /= 10;
309 } 308 }
310 309
311 list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); 310 list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps ));
312 } 311 }
313} 312}
314 313
315void OFontSelector::fontFamilyClicked ( int index ) 314void OFontSelector::fontFamilyClicked ( int index )
316{ 315{
317 QString oldstyle = d-> m_font_style_list-> currentText ( ); 316 QString oldstyle = d-> m_font_style_list-> currentText ( );
318 QString oldsize = d-> m_font_size_list-> currentText ( ); 317 QString oldsize = d-> m_font_size_list-> currentText ( );
319 318
320 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); 319 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index );
321 320
322 d-> m_font_style_list-> clear ( ); 321 d-> m_font_style_list-> clear ( );
323 d-> m_font_style_list-> insertStringList ( fli-> styles ( )); 322 d-> m_font_style_list-> insertStringList ( fli-> styles ( ));
324 d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); 323 d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( ));
325 324
326 int i; 325 int i;
327 326
328 i = findItemCB ( d-> m_font_style_list, oldstyle ); 327 i = findItemCB ( d-> m_font_style_list, oldstyle );
329 if ( i < 0 ) 328 if ( i < 0 )
330 i = findItemCB ( d-> m_font_style_list, "Regular" ); 329 i = findItemCB ( d-> m_font_style_list, "Regular" );
331 if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 )) 330 if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 ))
332 i = 0; 331 i = 0;
333 332
334 if ( i >= 0 ) { 333 if ( i >= 0 ) {
335 d-> m_font_style_list-> setCurrentItem ( i ); 334 d-> m_font_style_list-> setCurrentItem ( i );
336 fontStyleClicked ( i ); 335 fontStyleClicked ( i );
337 } 336 }
338 337
339 d-> m_font_size_list-> clear ( ); 338 d-> m_font_size_list-> clear ( );
340 QValueList<int> sl = fli-> sizes ( ); 339 QValueList<int> sl = fli-> sizes ( );
341 340
342 for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 341 for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
343 d-> m_font_size_list-> insertItem ( QString::number ( *it )); 342 d-> m_font_size_list-> insertItem ( QString::number ( *it ));
344 343
345 i = findItemCB ( d-> m_font_size_list, oldsize ); 344 i = findItemCB ( d-> m_font_size_list, oldsize );
346 if ( i < 0 ) 345 if ( i < 0 )
347 i = findItemCB ( d-> m_font_size_list, "10" ); 346 i = findItemCB ( d-> m_font_size_list, "10" );
348 if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 )) 347 if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 ))
349 i = 0; 348 i = 0;
350 349
351 if ( i >= 0 ) { 350 if ( i >= 0 ) {
352 d-> m_font_size_list-> setCurrentItem ( i ); 351 d-> m_font_size_list-> setCurrentItem ( i );
353 fontSizeClicked ( i ); 352 fontSizeClicked ( i );
354 } 353 }
355 changeFont ( ); 354 changeFont ( );
356} 355}
357 356
358void OFontSelector::fontStyleClicked ( int /*index*/ ) 357void OFontSelector::fontStyleClicked ( int /*index*/ )
359{ 358{
360 changeFont ( ); 359 changeFont ( );
361} 360}
362 361
363void OFontSelector::fontSizeClicked ( int /*index*/ ) 362void OFontSelector::fontSizeClicked ( int /*index*/ )
364{ 363{
365 changeFont ( ); 364 changeFont ( );
366} 365}
367 366
368void OFontSelector::changeFont ( ) 367void OFontSelector::changeFont ( )
369{ 368{
370 QFont f = selectedFont ( ); 369 QFont f = selectedFont ( );
371 370
372 if ( d-> m_preview ) 371 if ( d-> m_preview )
373 d-> m_preview-> setFont ( f ); 372 d-> m_preview-> setFont ( f );
374 373
375 emit fontSelected ( f ); 374 emit fontSelected ( f );
376} 375}
377 376
378/** 377/**
379 * Return the selected font 378 * Return the selected font
380 */ 379 */
381QFont OFontSelector::selectedFont ( ) 380QFont OFontSelector::selectedFont ( )
382{ 381{
383 int ffa = d-> m_font_family_list-> currentItem ( ); 382 int ffa = d-> m_font_family_list-> currentItem ( );
384 int fst = d-> m_font_style_list-> currentItem ( ); 383 int fst = d-> m_font_style_list-> currentItem ( );
385 int fsi = d-> m_font_size_list-> currentItem ( ); 384 int fsi = d-> m_font_size_list-> currentItem ( );
386 385
387 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); 386 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa );
388 387
389 if ( fli ) { 388 if ( fli ) {
390 return d-> m_fdb. font ( fli-> family ( ), \ 389 return d-> m_fdb. font ( fli-> family ( ), \
391 fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ 390 fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \
392 fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ 391 fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \
393 d-> m_fdb. charSets ( fli-> family ( )) [0] ); 392 d-> m_fdb. charSets ( fli-> family ( )) [0] );
394 } 393 }
395 else 394 else
396 return QFont ( ); 395 return QFont ( );
397} 396}
398 397
399 398
400void OFontSelector::resizeEvent ( QResizeEvent *re ) 399void OFontSelector::resizeEvent ( QResizeEvent *re )
401{ 400{
402 if ( d-> m_preview ) { 401 if ( d-> m_preview ) {
403 d-> m_preview-> setMinimumHeight ( 1 ); 402 d-> m_preview-> setMinimumHeight ( 1 );
404 d-> m_preview-> setMaximumHeight ( 32767 ); 403 d-> m_preview-> setMaximumHeight ( 32767 );
405 } 404 }
406 405
407 QWidget::resizeEvent ( re ); 406 QWidget::resizeEvent ( re );
408 407
409 if ( d-> m_preview ) 408 if ( d-> m_preview )
410 d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); 409 d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( ));
411 410
412} 411}
diff --git a/libopie/oprocctrl.cpp b/libopie/oprocctrl.cpp
index e7db622..df8da1e 100644
--- a/libopie/oprocctrl.cpp
+++ b/libopie/oprocctrl.cpp
@@ -1,268 +1,267 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) 2 Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19// 19//
20// KPROCESSCONTROLLER -- A helper class for KProcess 20// KPROCESSCONTROLLER -- A helper class for KProcess
21// 21//
22// version 0.3.1, Jan, 8th 1997 22// version 0.3.1, Jan, 8th 1997
23// 23//
24// (C) Christian Czezatke 24// (C) Christian Czezatke
25// e9025461@student.tuwien.ac.at 25// e9025461@student.tuwien.ac.at
26// Ported by Holger Freyther 26// Ported by Holger Freyther
27// 27//
28 28
29//#include <config.h> 29//#include <config.h>
30 30
31#include <sys/types.h> 31#include <sys/types.h>
32#include <sys/socket.h> 32#include <sys/socket.h>
33 33
34#include <errno.h> 34#include <errno.h>
35#include <fcntl.h> 35#include <fcntl.h>
36#include <stdio.h> 36#include <stdio.h>
37#include <string.h> 37#include <string.h>
38#include <unistd.h> 38#include <unistd.h>
39#include <assert.h> 39#include <assert.h>
40 40
41#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
42#include "oprocess.h"
43#include "oprocctrl.h" 42#include "oprocctrl.h"
44 43
45OProcessController *OProcessController::theOProcessController = 0; 44OProcessController *OProcessController::theOProcessController = 0;
46 45
47struct sigaction OProcessController::oldChildHandlerData; 46struct sigaction OProcessController::oldChildHandlerData;
48bool OProcessController::handlerSet = false; 47bool OProcessController::handlerSet = false;
49 48
50OProcessController::OProcessController() 49OProcessController::OProcessController()
51{ 50{
52 assert( theOProcessController == 0 ); 51 assert( theOProcessController == 0 );
53 52
54 if (0 > pipe(fd)) 53 if (0 > pipe(fd))
55 printf(strerror(errno)); 54 printf(strerror(errno));
56 55
57 notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read); 56 notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read);
58 notifier->setEnabled(true); 57 notifier->setEnabled(true);
59 QObject::connect(notifier, SIGNAL(activated(int)), 58 QObject::connect(notifier, SIGNAL(activated(int)),
60 this, SLOT(slotDoHousekeeping(int))); 59 this, SLOT(slotDoHousekeeping(int)));
61 connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()), 60 connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()),
62 SLOT( delayedChildrenCleanup())); 61 SLOT( delayedChildrenCleanup()));
63 62
64 theOProcessController = this; 63 theOProcessController = this;
65 64
66 setupHandlers(); 65 setupHandlers();
67} 66}
68 67
69 68
70void OProcessController::setupHandlers() 69void OProcessController::setupHandlers()
71{ 70{
72 if( handlerSet ) 71 if( handlerSet )
73 return; 72 return;
74 struct sigaction act; 73 struct sigaction act;
75 act.sa_handler=theSigCHLDHandler; 74 act.sa_handler=theSigCHLDHandler;
76 sigemptyset(&(act.sa_mask)); 75 sigemptyset(&(act.sa_mask));
77 sigaddset(&(act.sa_mask), SIGCHLD); 76 sigaddset(&(act.sa_mask), SIGCHLD);
78 // Make sure we don't block this signal. gdb tends to do that :-( 77 // Make sure we don't block this signal. gdb tends to do that :-(
79 sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); 78 sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0);
80 79
81 act.sa_flags = SA_NOCLDSTOP; 80 act.sa_flags = SA_NOCLDSTOP;
82 81
83 // CC: take care of SunOS which automatically restarts interrupted system 82 // CC: take care of SunOS which automatically restarts interrupted system
84 // calls (and thus does not have SA_RESTART) 83 // calls (and thus does not have SA_RESTART)
85 84
86#ifdef SA_RESTART 85#ifdef SA_RESTART
87 act.sa_flags |= SA_RESTART; 86 act.sa_flags |= SA_RESTART;
88#endif 87#endif
89 88
90 sigaction( SIGCHLD, &act, &oldChildHandlerData ); 89 sigaction( SIGCHLD, &act, &oldChildHandlerData );
91 90
92 act.sa_handler=SIG_IGN; 91 act.sa_handler=SIG_IGN;
93 sigemptyset(&(act.sa_mask)); 92 sigemptyset(&(act.sa_mask));
94 sigaddset(&(act.sa_mask), SIGPIPE); 93 sigaddset(&(act.sa_mask), SIGPIPE);
95 act.sa_flags = 0; 94 act.sa_flags = 0;
96 sigaction( SIGPIPE, &act, 0L); 95 sigaction( SIGPIPE, &act, 0L);
97 handlerSet = true; 96 handlerSet = true;
98} 97}
99 98
100void OProcessController::resetHandlers() 99void OProcessController::resetHandlers()
101{ 100{
102 if( !handlerSet ) 101 if( !handlerSet )
103 return; 102 return;
104 sigaction( SIGCHLD, &oldChildHandlerData, 0 ); 103 sigaction( SIGCHLD, &oldChildHandlerData, 0 );
105 // there should be no problem with SIGPIPE staying SIG_IGN 104 // there should be no problem with SIGPIPE staying SIG_IGN
106 handlerSet = false; 105 handlerSet = false;
107} 106}
108 107
109// block SIGCHLD handler, because it accesses processList 108// block SIGCHLD handler, because it accesses processList
110void OProcessController::addOProcess( OProcess* p ) 109void OProcessController::addOProcess( OProcess* p )
111{ 110{
112 sigset_t newset, oldset; 111 sigset_t newset, oldset;
113 sigemptyset( &newset ); 112 sigemptyset( &newset );
114 sigaddset( &newset, SIGCHLD ); 113 sigaddset( &newset, SIGCHLD );
115 sigprocmask( SIG_BLOCK, &newset, &oldset ); 114 sigprocmask( SIG_BLOCK, &newset, &oldset );
116 processList.append( p ); 115 processList.append( p );
117 sigprocmask( SIG_SETMASK, &oldset, 0 ); 116 sigprocmask( SIG_SETMASK, &oldset, 0 );
118} 117}
119 118
120void OProcessController::removeOProcess( OProcess* p ) 119void OProcessController::removeOProcess( OProcess* p )
121{ 120{
122 sigset_t newset, oldset; 121 sigset_t newset, oldset;
123 sigemptyset( &newset ); 122 sigemptyset( &newset );
124 sigaddset( &newset, SIGCHLD ); 123 sigaddset( &newset, SIGCHLD );
125 sigprocmask( SIG_BLOCK, &newset, &oldset ); 124 sigprocmask( SIG_BLOCK, &newset, &oldset );
126 processList.remove( p ); 125 processList.remove( p );
127 sigprocmask( SIG_SETMASK, &oldset, 0 ); 126 sigprocmask( SIG_SETMASK, &oldset, 0 );
128} 127}
129 128
130//using a struct which contains both the pid and the status makes it easier to write 129//using a struct which contains both the pid and the status makes it easier to write
131//and read the data into the pipe 130//and read the data into the pipe
132//especially this solves a problem which appeared on my box where slotDoHouseKeeping() received 131//especially this solves a problem which appeared on my box where slotDoHouseKeeping() received
133//only 4 bytes (with some debug output around the write()'s it received all 8 bytes) 132//only 4 bytes (with some debug output around the write()'s it received all 8 bytes)
134//don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX 133//don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX
135struct waitdata 134struct waitdata
136{ 135{
137 pid_t pid; 136 pid_t pid;
138 int status; 137 int status;
139}; 138};
140 139
141void OProcessController::theSigCHLDHandler(int arg) 140void OProcessController::theSigCHLDHandler(int arg)
142{ 141{
143 struct waitdata wd; 142 struct waitdata wd;
144// int status; 143// int status;
145// pid_t this_pid; 144// pid_t this_pid;
146 int saved_errno; 145 int saved_errno;
147 146
148 saved_errno = errno; 147 saved_errno = errno;
149 // since waitpid and write change errno, we have to save it and restore it 148 // since waitpid and write change errno, we have to save it and restore it
150 // (Richard Stevens, Advanced programming in the Unix Environment) 149 // (Richard Stevens, Advanced programming in the Unix Environment)
151 150
152 bool found = false; 151 bool found = false;
153 if( theOProcessController != 0 ) { 152 if( theOProcessController != 0 ) {
154 // iterating the list doesn't perform any system call 153 // iterating the list doesn't perform any system call
155 for( QValueList<OProcess*>::ConstIterator it = theOProcessController->processList.begin(); 154 for( QValueList<OProcess*>::ConstIterator it = theOProcessController->processList.begin();
156 it != theOProcessController->processList.end(); 155 it != theOProcessController->processList.end();
157 ++it ) 156 ++it )
158 { 157 {
159 if( !(*it)->isRunning()) 158 if( !(*it)->isRunning())
160 continue; 159 continue;
161 wd.pid = waitpid( (*it)->pid(), &wd.status, WNOHANG ); 160 wd.pid = waitpid( (*it)->pid(), &wd.status, WNOHANG );
162 if ( wd.pid > 0 ) { 161 if ( wd.pid > 0 ) {
163 ::write(theOProcessController->fd[1], &wd, sizeof(wd)); 162 ::write(theOProcessController->fd[1], &wd, sizeof(wd));
164 found = true; 163 found = true;
165 } 164 }
166 } 165 }
167 } 166 }
168 if( !found && oldChildHandlerData.sa_handler != SIG_IGN 167 if( !found && oldChildHandlerData.sa_handler != SIG_IGN
169 && oldChildHandlerData.sa_handler != SIG_DFL ) 168 && oldChildHandlerData.sa_handler != SIG_DFL )
170 oldChildHandlerData.sa_handler( arg ); // call the old handler 169 oldChildHandlerData.sa_handler( arg ); // call the old handler
171 // handle the rest 170 // handle the rest
172 if( theOProcessController != 0 ) { 171 if( theOProcessController != 0 ) {
173 static const struct waitdata dwd = { 0, 0 }; // delayed waitpid() 172 static const struct waitdata dwd = { 0, 0 }; // delayed waitpid()
174 ::write(theOProcessController->fd[1], &dwd, sizeof(dwd)); 173 ::write(theOProcessController->fd[1], &dwd, sizeof(dwd));
175 } else { 174 } else {
176 int dummy; 175 int dummy;
177 while( waitpid( -1, &dummy, WNOHANG ) > 0 ) 176 while( waitpid( -1, &dummy, WNOHANG ) > 0 )
178 ; 177 ;
179 } 178 }
180 179
181 errno = saved_errno; 180 errno = saved_errno;
182} 181}
183 182
184 183
185 184
186void OProcessController::slotDoHousekeeping(int ) 185void OProcessController::slotDoHousekeeping(int )
187{ 186{
188 unsigned int bytes_read = 0; 187 unsigned int bytes_read = 0;
189 unsigned int errcnt=0; 188 unsigned int errcnt=0;
190 // read pid and status from the pipe. 189 // read pid and status from the pipe.
191 struct waitdata wd; 190 struct waitdata wd;
192 while ((bytes_read < sizeof(wd)) && (errcnt < 50)) { 191 while ((bytes_read < sizeof(wd)) && (errcnt < 50)) {
193 int r = ::read(fd[0], ((char *)&wd) + bytes_read, sizeof(wd) - bytes_read); 192 int r = ::read(fd[0], ((char *)&wd) + bytes_read, sizeof(wd) - bytes_read);
194 if (r > 0) bytes_read += r; 193 if (r > 0) bytes_read += r;
195 else if (r < 0) errcnt++; 194 else if (r < 0) errcnt++;
196 } 195 }
197 if (errcnt >= 50) { 196 if (errcnt >= 50) {
198 fprintf(stderr, 197 fprintf(stderr,
199 "Error: Max. error count for pipe read " 198 "Error: Max. error count for pipe read "
200 "exceeded in OProcessController::slotDoHousekeeping\n"); 199 "exceeded in OProcessController::slotDoHousekeeping\n");
201 return; // it makes no sense to continue here! 200 return; // it makes no sense to continue here!
202 } 201 }
203 if (bytes_read != sizeof(wd)) { 202 if (bytes_read != sizeof(wd)) {
204 fprintf(stderr, 203 fprintf(stderr,
205 "Error: Could not read info from signal handler %d <> %d!\n", 204 "Error: Could not read info from signal handler %d <> %d!\n",
206 bytes_read, sizeof(wd)); 205 bytes_read, sizeof(wd));
207 return; // it makes no sense to continue here! 206 return; // it makes no sense to continue here!
208 } 207 }
209 if (wd.pid==0) { // special case, see delayedChildrenCleanup() 208 if (wd.pid==0) { // special case, see delayedChildrenCleanup()
210 delayedChildrenCleanupTimer.start( 1000, true ); 209 delayedChildrenCleanupTimer.start( 1000, true );
211 return; 210 return;
212 } 211 }
213 212
214 for( QValueList<OProcess*>::ConstIterator it = processList.begin(); 213 for( QValueList<OProcess*>::ConstIterator it = processList.begin();
215 it != processList.end(); 214 it != processList.end();
216 ++it ) { 215 ++it ) {
217 OProcess* proc = *it; 216 OProcess* proc = *it;
218 if (proc->pid() == wd.pid) { 217 if (proc->pid() == wd.pid) {
219 // process has exited, so do emit the respective events 218 // process has exited, so do emit the respective events
220 if (proc->run_mode == OProcess::Block) { 219 if (proc->run_mode == OProcess::Block) {
221 // If the reads are done blocking then set the status in proc 220 // If the reads are done blocking then set the status in proc
222 // but do nothing else because OProcess will perform the other 221 // but do nothing else because OProcess will perform the other
223 // actions of processHasExited. 222 // actions of processHasExited.
224 proc->status = wd.status; 223 proc->status = wd.status;
225 proc->runs = false; 224 proc->runs = false;
226 } else { 225 } else {
227 proc->processHasExited(wd.status); 226 proc->processHasExited(wd.status);
228 } 227 }
229 return; 228 return;
230 } 229 }
231 } 230 }
232} 231}
233 232
234// this is needed e.g. for popen(), which calls waitpid() checking 233// this is needed e.g. for popen(), which calls waitpid() checking
235// for its forked child, if we did waitpid() directly in the SIGCHLD 234// for its forked child, if we did waitpid() directly in the SIGCHLD
236// handler, popen()'s waitpid() call would fail 235// handler, popen()'s waitpid() call would fail
237void OProcessController::delayedChildrenCleanup() 236void OProcessController::delayedChildrenCleanup()
238{ 237{
239 struct waitdata wd; 238 struct waitdata wd;
240 while(( wd.pid = waitpid( -1, &wd.status, WNOHANG ) ) > 0 ) { 239 while(( wd.pid = waitpid( -1, &wd.status, WNOHANG ) ) > 0 ) {
241 for( QValueList<OProcess*>::ConstIterator it = processList.begin(); 240 for( QValueList<OProcess*>::ConstIterator it = processList.begin();
242 it != processList.end(); 241 it != processList.end();
243 ++it ) 242 ++it )
244 { 243 {
245 if( !(*it)->isRunning() || (*it)->pid() != wd.pid ) 244 if( !(*it)->isRunning() || (*it)->pid() != wd.pid )
246 continue; 245 continue;
247 // it's OProcess, handle it 246 // it's OProcess, handle it
248 ::write(fd[1], &wd, sizeof(wd)); 247 ::write(fd[1], &wd, sizeof(wd));
249 break; 248 break;
250 } 249 }
251 } 250 }
252} 251}
253 252
254OProcessController::~OProcessController() 253OProcessController::~OProcessController()
255{ 254{
256 assert( theOProcessController == this ); 255 assert( theOProcessController == this );
257 resetHandlers(); 256 resetHandlers();
258 257
259 notifier->setEnabled(false); 258 notifier->setEnabled(false);
260 259
261 close(fd[0]); 260 close(fd[0]);
262 close(fd[1]); 261 close(fd[1]);
263 262
264 delete notifier; 263 delete notifier;
265 theOProcessController = 0; 264 theOProcessController = 0;
266} 265}
267 266
268//#include "kprocctrl.moc" 267//#include "kprocctrl.moc"
diff --git a/libopie/oprocess.cpp b/libopie/oprocess.cpp
index 5db2b6c..c19881a 100644
--- a/libopie/oprocess.cpp
+++ b/libopie/oprocess.cpp
@@ -1,440 +1,439 @@
1/* 1/*
2 2
3 $Id$ 3 $Id$
4 4
5 This file is part of the KDE libraries 5 This file is part of the KDE libraries
6 Copyright (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) 6 Copyright (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at)
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22 22
23*/ 23*/
24 24
25 25
26// 26//
27// KPROCESS -- A class for handling child processes in KDE without 27// KPROCESS -- A class for handling child processes in KDE without
28// having to take care of Un*x specific implementation details 28// having to take care of Un*x specific implementation details
29// 29//
30// version 0.3.1, Jan 8th 1998 30// version 0.3.1, Jan 8th 1998
31// 31//
32// (C) Christian Czezatke 32// (C) Christian Czezatke
33// e9025461@student.tuwien.ac.at 33// e9025461@student.tuwien.ac.at
34// 34//
35// Changes: 35// Changes:
36// 36//
37// March 2nd, 1998: Changed parameter list for KShellProcess: 37// March 2nd, 1998: Changed parameter list for KShellProcess:
38// Arguments are now placed in a single string so that 38// Arguments are now placed in a single string so that
39// <shell> -c <commandstring> is passed to the shell 39// <shell> -c <commandstring> is passed to the shell
40// to make the use of "operator<<" consistent with KProcess 40// to make the use of "operator<<" consistent with KProcess
41// 41//
42// 42//
43// Ported by Holger Freyther 43// Ported by Holger Freyther
44// <zekce> Harlekin: oprocess and say it was ported to Qt by the Opie developers an Qt 2 44// <zekce> Harlekin: oprocess and say it was ported to Qt by the Opie developers an Qt 2
45 45
46 46
47 47
48#include "oprocess.h" 48#include "oprocess.h"
49#define _MAY_INCLUDE_KPROCESSCONTROLLER_ 49#define _MAY_INCLUDE_KPROCESSCONTROLLER_
50#include "oprocctrl.h" 50#include "oprocctrl.h"
51 51
52//#include <config.h> 52//#include <config.h>
53 53
54#include <qfile.h> 54#include <qfile.h>
55#include <qsocketnotifier.h> 55#include <qsocketnotifier.h>
56#include <qregexp.h>
57 56
58#include <sys/time.h> 57#include <sys/time.h>
59#include <sys/types.h> 58#include <sys/types.h>
60#include <sys/stat.h> 59#include <sys/stat.h>
61#include <sys/socket.h> 60#include <sys/socket.h>
62 61
63#include <errno.h> 62#include <errno.h>
64#include <fcntl.h> 63#include <fcntl.h>
65#include <stdlib.h> 64#include <stdlib.h>
66#include <signal.h> 65#include <signal.h>
67#include <stdio.h> 66#include <stdio.h>
68#include <string.h> 67#include <string.h>
69#include <unistd.h> 68#include <unistd.h>
70#ifdef HAVE_SYS_SELECT_H 69#ifdef HAVE_SYS_SELECT_H
71#include <sys/select.h> 70#include <sys/select.h>
72#endif 71#endif
73#ifdef HAVE_INITGROUPS 72#ifdef HAVE_INITGROUPS
74#include <grp.h> 73#include <grp.h>
75#endif 74#endif
76#include <pwd.h> 75#include <pwd.h>
77 76
78#include <qapplication.h> 77#include <qapplication.h>
79#include <qmap.h> 78#include <qmap.h>
80//#include <kdebug.h> 79//#include <kdebug.h>
81 80
82///////////////////////////// 81/////////////////////////////
83// public member functions // 82// public member functions //
84///////////////////////////// 83/////////////////////////////
85 84
86class OProcessPrivate { 85class OProcessPrivate {
87public: 86public:
88 OProcessPrivate() : useShell(false) { } 87 OProcessPrivate() : useShell(false) { }
89 88
90 bool useShell; 89 bool useShell;
91 QMap<QString,QString> env; 90 QMap<QString,QString> env;
92 QString wd; 91 QString wd;
93 QCString shell; 92 QCString shell;
94}; 93};
95 94
96 95
97OProcess::OProcess(QObject *parent, const char *name) 96OProcess::OProcess(QObject *parent, const char *name)
98 : QObject(parent, name) 97 : QObject(parent, name)
99{ 98{
100 init ( ); 99 init ( );
101} 100}
102 101
103OProcess::OProcess(const QString &arg0, QObject *parent, const char *name) 102OProcess::OProcess(const QString &arg0, QObject *parent, const char *name)
104 : QObject(parent, name) 103 : QObject(parent, name)
105{ 104{
106 init ( ); 105 init ( );
107 *this << arg0; 106 *this << arg0;
108} 107}
109 108
110OProcess::OProcess(const QStringList &args, QObject *parent, const char *name) 109OProcess::OProcess(const QStringList &args, QObject *parent, const char *name)
111 : QObject(parent, name) 110 : QObject(parent, name)
112{ 111{
113 init ( ); 112 init ( );
114 *this << args; 113 *this << args;
115} 114}
116 115
117void OProcess::init ( ) 116void OProcess::init ( )
118{ 117{
119 run_mode = NotifyOnExit; 118 run_mode = NotifyOnExit;
120 runs = false; 119 runs = false;
121 pid_ = 0; 120 pid_ = 0;
122 status = 0; 121 status = 0;
123 keepPrivs = false; 122 keepPrivs = false;
124 innot = 0; 123 innot = 0;
125 outnot = 0; 124 outnot = 0;
126 errnot = 0; 125 errnot = 0;
127 communication = NoCommunication; 126 communication = NoCommunication;
128 input_data = 0; 127 input_data = 0;
129 input_sent = 0; 128 input_sent = 0;
130 input_total = 0; 129 input_total = 0;
131 d = 0; 130 d = 0;
132 131
133 if (0 == OProcessController::theOProcessController) { 132 if (0 == OProcessController::theOProcessController) {
134 (void) new OProcessController(); 133 (void) new OProcessController();
135 CHECK_PTR(OProcessController::theOProcessController); 134 CHECK_PTR(OProcessController::theOProcessController);
136 } 135 }
137 136
138 OProcessController::theOProcessController->addOProcess(this); 137 OProcessController::theOProcessController->addOProcess(this);
139 out[0] = out[1] = -1; 138 out[0] = out[1] = -1;
140 in[0] = in[1] = -1; 139 in[0] = in[1] = -1;
141 err[0] = err[1] = -1; 140 err[0] = err[1] = -1;
142} 141}
143 142
144void 143void
145OProcess::setEnvironment(const QString &name, const QString &value) 144OProcess::setEnvironment(const QString &name, const QString &value)
146{ 145{
147 if (!d) 146 if (!d)
148 d = new OProcessPrivate; 147 d = new OProcessPrivate;
149 d->env.insert(name, value); 148 d->env.insert(name, value);
150} 149}
151 150
152void 151void
153OProcess::setWorkingDirectory(const QString &dir) 152OProcess::setWorkingDirectory(const QString &dir)
154{ 153{
155 if (!d) 154 if (!d)
156 d = new OProcessPrivate; 155 d = new OProcessPrivate;
157 d->wd = dir; 156 d->wd = dir;
158} 157}
159 158
160void 159void
161OProcess::setupEnvironment() 160OProcess::setupEnvironment()
162{ 161{
163 if (d) 162 if (d)
164 { 163 {
165 QMap<QString,QString>::Iterator it; 164 QMap<QString,QString>::Iterator it;
166 for(it = d->env.begin(); it != d->env.end(); ++it) 165 for(it = d->env.begin(); it != d->env.end(); ++it)
167 setenv(QFile::encodeName(it.key()).data(), 166 setenv(QFile::encodeName(it.key()).data(),
168 QFile::encodeName(it.data()).data(), 1); 167 QFile::encodeName(it.data()).data(), 1);
169 if (!d->wd.isEmpty()) 168 if (!d->wd.isEmpty())
170 chdir(QFile::encodeName(d->wd).data()); 169 chdir(QFile::encodeName(d->wd).data());
171 } 170 }
172} 171}
173 172
174void 173void
175OProcess::setRunPrivileged(bool keepPrivileges) 174OProcess::setRunPrivileged(bool keepPrivileges)
176{ 175{
177 keepPrivs = keepPrivileges; 176 keepPrivs = keepPrivileges;
178} 177}
179 178
180bool 179bool
181OProcess::runPrivileged() const 180OProcess::runPrivileged() const
182{ 181{
183 return keepPrivs; 182 return keepPrivs;
184} 183}
185 184
186 185
187OProcess::~OProcess() 186OProcess::~OProcess()
188{ 187{
189 // destroying the OProcess instance sends a SIGKILL to the 188 // destroying the OProcess instance sends a SIGKILL to the
190 // child process (if it is running) after removing it from the 189 // child process (if it is running) after removing it from the
191 // list of valid processes (if the process is not started as 190 // list of valid processes (if the process is not started as
192 // "DontCare") 191 // "DontCare")
193 192
194 OProcessController::theOProcessController->removeOProcess(this); 193 OProcessController::theOProcessController->removeOProcess(this);
195 // this must happen before we kill the child 194 // this must happen before we kill the child
196 // TODO: block the signal while removing the current process from the process list 195 // TODO: block the signal while removing the current process from the process list
197 196
198 if (runs && (run_mode != DontCare)) 197 if (runs && (run_mode != DontCare))
199 kill(SIGKILL); 198 kill(SIGKILL);
200 199
201 // Clean up open fd's and socket notifiers. 200 // Clean up open fd's and socket notifiers.
202 closeStdin(); 201 closeStdin();
203 closeStdout(); 202 closeStdout();
204 closeStderr(); 203 closeStderr();
205 204
206 // TODO: restore SIGCHLD and SIGPIPE handler if this is the last OProcess 205 // TODO: restore SIGCHLD and SIGPIPE handler if this is the last OProcess
207 delete d; 206 delete d;
208} 207}
209 208
210void OProcess::detach() 209void OProcess::detach()
211{ 210{
212 OProcessController::theOProcessController->removeOProcess(this); 211 OProcessController::theOProcessController->removeOProcess(this);
213 212
214 runs = false; 213 runs = false;
215 pid_ = 0; 214 pid_ = 0;
216 215
217 // Clean up open fd's and socket notifiers. 216 // Clean up open fd's and socket notifiers.
218 closeStdin(); 217 closeStdin();
219 closeStdout(); 218 closeStdout();
220 closeStderr(); 219 closeStderr();
221} 220}
222 221
223bool OProcess::setExecutable(const QString& proc) 222bool OProcess::setExecutable(const QString& proc)
224{ 223{
225 if (runs) return false; 224 if (runs) return false;
226 225
227 if (proc.isEmpty()) return false; 226 if (proc.isEmpty()) return false;
228 227
229 if (!arguments.isEmpty()) 228 if (!arguments.isEmpty())
230 arguments.remove(arguments.begin()); 229 arguments.remove(arguments.begin());
231 arguments.prepend(QFile::encodeName(proc)); 230 arguments.prepend(QFile::encodeName(proc));
232 231
233 return true; 232 return true;
234} 233}
235 234
236OProcess &OProcess::operator<<(const QStringList& args) 235OProcess &OProcess::operator<<(const QStringList& args)
237{ 236{
238 QStringList::ConstIterator it = args.begin(); 237 QStringList::ConstIterator it = args.begin();
239 for ( ; it != args.end() ; ++it ) 238 for ( ; it != args.end() ; ++it )
240 arguments.append(QFile::encodeName(*it)); 239 arguments.append(QFile::encodeName(*it));
241 return *this; 240 return *this;
242} 241}
243 242
244OProcess &OProcess::operator<<(const QCString& arg) 243OProcess &OProcess::operator<<(const QCString& arg)
245{ 244{
246 return operator<< (arg.data()); 245 return operator<< (arg.data());
247} 246}
248 247
249OProcess &OProcess::operator<<(const char* arg) 248OProcess &OProcess::operator<<(const char* arg)
250{ 249{
251 arguments.append(arg); 250 arguments.append(arg);
252 return *this; 251 return *this;
253} 252}
254 253
255OProcess &OProcess::operator<<(const QString& arg) 254OProcess &OProcess::operator<<(const QString& arg)
256{ 255{
257 arguments.append(QFile::encodeName(arg)); 256 arguments.append(QFile::encodeName(arg));
258 return *this; 257 return *this;
259} 258}
260 259
261void OProcess::clearArguments() 260void OProcess::clearArguments()
262{ 261{
263 arguments.clear(); 262 arguments.clear();
264} 263}
265 264
266bool OProcess::start(RunMode runmode, Communication comm) 265bool OProcess::start(RunMode runmode, Communication comm)
267{ 266{
268 uint i; 267 uint i;
269 uint n = arguments.count(); 268 uint n = arguments.count();
270 char **arglist; 269 char **arglist;
271 270
272 if (runs || (0 == n)) { 271 if (runs || (0 == n)) {
273 return false; // cannot start a process that is already running 272 return false; // cannot start a process that is already running
274 // or if no executable has been assigned 273 // or if no executable has been assigned
275 } 274 }
276 run_mode = runmode; 275 run_mode = runmode;
277 status = 0; 276 status = 0;
278 277
279 QCString shellCmd; 278 QCString shellCmd;
280 if (d && d->useShell) 279 if (d && d->useShell)
281 { 280 {
282 if (d->shell.isEmpty()) 281 if (d->shell.isEmpty())
283 { 282 {
284 qWarning( "Could not find a valid shell" ); 283 qWarning( "Could not find a valid shell" );
285 return false; 284 return false;
286 } 285 }
287 286
288 arglist = static_cast<char **>(malloc( (4)*sizeof(char *))); 287 arglist = static_cast<char **>(malloc( (4)*sizeof(char *)));
289 for (i=0; i < n; i++) { 288 for (i=0; i < n; i++) {
290 shellCmd += arguments[i]; 289 shellCmd += arguments[i];
291 shellCmd += " "; // CC: to separate the arguments 290 shellCmd += " "; // CC: to separate the arguments
292 } 291 }
293 292
294 arglist[0] = d->shell.data(); 293 arglist[0] = d->shell.data();
295 arglist[1] = (char *) "-c"; 294 arglist[1] = (char *) "-c";
296 arglist[2] = shellCmd.data(); 295 arglist[2] = shellCmd.data();
297 arglist[3] = 0; 296 arglist[3] = 0;
298 } 297 }
299 else 298 else
300 { 299 {
301 arglist = static_cast<char **>(malloc( (n+1)*sizeof(char *))); 300 arglist = static_cast<char **>(malloc( (n+1)*sizeof(char *)));
302 for (i=0; i < n; i++) 301 for (i=0; i < n; i++)
303 arglist[i] = arguments[i].data(); 302 arglist[i] = arguments[i].data();
304 arglist[n]= 0; 303 arglist[n]= 0;
305 } 304 }
306 305
307 if (!setupCommunication(comm)) 306 if (!setupCommunication(comm))
308 qWarning( "Could not setup Communication!"); 307 qWarning( "Could not setup Communication!");
309 308
310 // We do this in the parent because if we do it in the child process 309 // We do this in the parent because if we do it in the child process
311 // gdb gets confused when the application runs from gdb. 310 // gdb gets confused when the application runs from gdb.
312 uid_t uid = getuid(); 311 uid_t uid = getuid();
313 gid_t gid = getgid(); 312 gid_t gid = getgid();
314#ifdef HAVE_INITGROUPS 313#ifdef HAVE_INITGROUPS
315 struct passwd *pw = getpwuid(uid); 314 struct passwd *pw = getpwuid(uid);
316#endif 315#endif
317 316
318 int fd[2]; 317 int fd[2];
319 if (0 > pipe(fd)) 318 if (0 > pipe(fd))
320 { 319 {
321 fd[0] = fd[1] = 0; // Pipe failed.. continue 320 fd[0] = fd[1] = 0; // Pipe failed.. continue
322 } 321 }
323 322
324 runs = true; 323 runs = true;
325 324
326 QApplication::flushX(); 325 QApplication::flushX();
327 326
328 // WABA: Note that we use fork() and not vfork() because 327 // WABA: Note that we use fork() and not vfork() because
329 // vfork() has unclear semantics and is not standardized. 328 // vfork() has unclear semantics and is not standardized.
330 pid_ = fork(); 329 pid_ = fork();
331 330
332 if (0 == pid_) { 331 if (0 == pid_) {
333 if (fd[0]) 332 if (fd[0])
334 close(fd[0]); 333 close(fd[0]);
335 if (!runPrivileged()) 334 if (!runPrivileged())
336 { 335 {
337 setgid(gid); 336 setgid(gid);
338#if defined( HAVE_INITGROUPS) 337#if defined( HAVE_INITGROUPS)
339 if(pw) 338 if(pw)
340 initgroups(pw->pw_name, pw->pw_gid); 339 initgroups(pw->pw_name, pw->pw_gid);
341#endif 340#endif
342 setuid(uid); 341 setuid(uid);
343 } 342 }
344 // The child process 343 // The child process
345 if(!commSetupDoneC()) 344 if(!commSetupDoneC())
346 qWarning( "Could not finish comm setup in child!" ); 345 qWarning( "Could not finish comm setup in child!" );
347 346
348 setupEnvironment(); 347 setupEnvironment();
349 348
350 // Matthias 349 // Matthias
351 if (run_mode == DontCare) 350 if (run_mode == DontCare)
352 setpgid(0,0); 351 setpgid(0,0);
353 // restore default SIGPIPE handler (Harri) 352 // restore default SIGPIPE handler (Harri)
354 struct sigaction act; 353 struct sigaction act;
355 sigemptyset(&(act.sa_mask)); 354 sigemptyset(&(act.sa_mask));
356 sigaddset(&(act.sa_mask), SIGPIPE); 355 sigaddset(&(act.sa_mask), SIGPIPE);
357 act.sa_handler = SIG_DFL; 356 act.sa_handler = SIG_DFL;
358 act.sa_flags = 0; 357 act.sa_flags = 0;
359 sigaction(SIGPIPE, &act, 0L); 358 sigaction(SIGPIPE, &act, 0L);
360 359
361 // We set the close on exec flag. 360 // We set the close on exec flag.
362 // Closing of fd[1] indicates that the execvp succeeded! 361 // Closing of fd[1] indicates that the execvp succeeded!
363 if (fd[1]) 362 if (fd[1])
364 fcntl(fd[1], F_SETFD, FD_CLOEXEC); 363 fcntl(fd[1], F_SETFD, FD_CLOEXEC);
365 execvp(arglist[0], arglist); 364 execvp(arglist[0], arglist);
366 char resultByte = 1; 365 char resultByte = 1;
367 if (fd[1]) 366 if (fd[1])
368 write(fd[1], &resultByte, 1); 367 write(fd[1], &resultByte, 1);
369 _exit(-1); 368 _exit(-1);
370 } else if (-1 == pid_) { 369 } else if (-1 == pid_) {
371 // forking failed 370 // forking failed
372 371
373 runs = false; 372 runs = false;
374 free(arglist); 373 free(arglist);
375 return false; 374 return false;
376 } else { 375 } else {
377 if (fd[1]) 376 if (fd[1])
378 close(fd[1]); 377 close(fd[1]);
379 // the parent continues here 378 // the parent continues here
380 379
381 // Discard any data for stdin that might still be there 380 // Discard any data for stdin that might still be there
382 input_data = 0; 381 input_data = 0;
383 382
384 // Check whether client could be started. 383 // Check whether client could be started.
385 if (fd[0]) for(;;) 384 if (fd[0]) for(;;)
386 { 385 {
387 char resultByte; 386 char resultByte;
388 int n = ::read(fd[0], &resultByte, 1); 387 int n = ::read(fd[0], &resultByte, 1);
389 if (n == 1) 388 if (n == 1)
390 { 389 {
391 // Error 390 // Error
392 runs = false; 391 runs = false;
393 close(fd[0]); 392 close(fd[0]);
394 free(arglist); 393 free(arglist);
395 pid_ = 0; 394 pid_ = 0;
396 return false; 395 return false;
397 } 396 }
398 if (n == -1) 397 if (n == -1)
399 { 398 {
400 if ((errno == ECHILD) || (errno == EINTR)) 399 if ((errno == ECHILD) || (errno == EINTR))
401 continue; // Ignore 400 continue; // Ignore
402 } 401 }
403 break; // success 402 break; // success
404 } 403 }
405 if (fd[0]) 404 if (fd[0])
406 close(fd[0]); 405 close(fd[0]);
407 406
408 if (!commSetupDoneP()) // finish communication socket setup for the parent 407 if (!commSetupDoneP()) // finish communication socket setup for the parent
409 qWarning( "Could not finish comm setup in parent!" ); 408 qWarning( "Could not finish comm setup in parent!" );
410 409
411 if (run_mode == Block) { 410 if (run_mode == Block) {
412 commClose(); 411 commClose();
413 412
414 // The SIGCHLD handler of the process controller will catch 413 // The SIGCHLD handler of the process controller will catch
415 // the exit and set the status 414 // the exit and set the status
416 while(runs) 415 while(runs)
417 { 416 {
418 OProcessController::theOProcessController-> 417 OProcessController::theOProcessController->
419 slotDoHousekeeping(0); 418 slotDoHousekeeping(0);
420 } 419 }
421 runs = FALSE; 420 runs = FALSE;
422 emit processExited(this); 421 emit processExited(this);
423 } 422 }
424 } 423 }
425 free(arglist); 424 free(arglist);
426 return true; 425 return true;
427} 426}
428 427
429 428
430 429
431bool OProcess::kill(int signo) 430bool OProcess::kill(int signo)
432{ 431{
433 bool rv=false; 432 bool rv=false;
434 433
435 if (0 != pid_) 434 if (0 != pid_)
436 rv= (-1 != ::kill(pid_, signo)); 435 rv= (-1 != ::kill(pid_, signo));
437 // probably store errno somewhere... 436 // probably store errno somewhere...
438 return rv; 437 return rv;
439} 438}
440 439
diff --git a/libopie/orecurrancewidget.cpp b/libopie/orecurrancewidget.cpp
index be8ec30..d81851e 100644
--- a/libopie/orecurrancewidget.cpp
+++ b/libopie/orecurrancewidget.cpp
@@ -1,390 +1,388 @@
1#include <qapplication.h> 1#include <qapplication.h>
2#include <qlabel.h> 2#include <qlabel.h>
3#include <qpopupmenu.h>
4#include <qspinbox.h> 3#include <qspinbox.h>
5 4
6#include <qpe/timestring.h>
7 5
8#include "orecurrancewidget.h" 6#include "orecurrancewidget.h"
9 7
10// Global Templates for use in setting up the repeat label... 8// Global Templates for use in setting up the repeat label...
11// the problem is these strings get initialized before QPEApplication can install the translator -zecke 9// the problem is these strings get initialized before QPEApplication can install the translator -zecke
12namespace { 10namespace {
13QString strDayTemplate; 11QString strDayTemplate;
14QString strYearTemplate; 12QString strYearTemplate;
15QString strMonthDateTemplate; 13QString strMonthDateTemplate;
16QString strMonthDayTemplate; 14QString strMonthDayTemplate;
17QString strWeekTemplate; 15QString strWeekTemplate;
18QString dayLabel[7]; 16QString dayLabel[7];
19} 17}
20 18
21/* 19/*
22 * static linkage to not polute the symbol table... 20 * static linkage to not polute the symbol table...
23 * The problem is that const and static linkage are resolved prior to installing a translator 21 * The problem is that const and static linkage are resolved prior to installing a translator
24 * leading to that the above strings are translted but to the original we delay the init of these strings... 22 * leading to that the above strings are translted but to the original we delay the init of these strings...
25 * -zecke 23 * -zecke
26 */ 24 */
27static void fillStrings() { 25static void fillStrings() {
28 strDayTemplate = QObject::tr("Every"); 26 strDayTemplate = QObject::tr("Every");
29 strYearTemplate = QObject::tr("%1 %2 every "); 27 strYearTemplate = QObject::tr("%1 %2 every ");
30 strMonthDateTemplate = QObject::tr("The %1 every "); 28 strMonthDateTemplate = QObject::tr("The %1 every ");
31 strMonthDayTemplate = QObject::tr("The %1 %2 of every"); 29 strMonthDayTemplate = QObject::tr("The %1 %2 of every");
32 strWeekTemplate = QObject::tr("Every "); 30 strWeekTemplate = QObject::tr("Every ");
33 dayLabel[0] = QObject::tr("Monday"); 31 dayLabel[0] = QObject::tr("Monday");
34 dayLabel[1] = QObject::tr("Tuesday"); 32 dayLabel[1] = QObject::tr("Tuesday");
35 dayLabel[2] = QObject::tr("Wednesday"); 33 dayLabel[2] = QObject::tr("Wednesday");
36 dayLabel[3] = QObject::tr("Thursday"); 34 dayLabel[3] = QObject::tr("Thursday");
37 dayLabel[4] = QObject::tr("Friday"); 35 dayLabel[4] = QObject::tr("Friday");
38 dayLabel[5] = QObject::tr("Saturday"); 36 dayLabel[5] = QObject::tr("Saturday");
39 dayLabel[6] = QObject::tr("Sunday"); 37 dayLabel[6] = QObject::tr("Sunday");
40} 38}
41 39
42 static QString numberPlacing( int x );// return the proper word format for 40 static QString numberPlacing( int x );// return the proper word format for
43 // x (1st, 2nd, etc) 41 // x (1st, 2nd, etc)
44static int week( const QDate &dt ); // what week in the month is dt? 42static int week( const QDate &dt ); // what week in the month is dt?
45 43
46/** 44/**
47 * Constructs the Widget 45 * Constructs the Widget
48 * @param startOnMonday Does the week start on monday 46 * @param startOnMonday Does the week start on monday
49 * @param newStart The start date of the recurrence 47 * @param newStart The start date of the recurrence
50 * @param parent The parent widget 48 * @param parent The parent widget
51 * @param name the name of object 49 * @param name the name of object
52 * @param modal if the dialog should be modal 50 * @param modal if the dialog should be modal
53 * @param fl Additional window flags 51 * @param fl Additional window flags
54 */ 52 */
55ORecurranceWidget::ORecurranceWidget( bool startOnMonday, 53ORecurranceWidget::ORecurranceWidget( bool startOnMonday,
56 const QDate& newStart, 54 const QDate& newStart,
57 QWidget* parent, 55 QWidget* parent,
58 const char* name, 56 const char* name,
59 bool modal, 57 bool modal,
60 WFlags fl ) 58 WFlags fl )
61 : ORecurranceBase( parent, name, modal, fl ), 59 : ORecurranceBase( parent, name, modal, fl ),
62 start( newStart ), 60 start( newStart ),
63 currInterval( None ), 61 currInterval( None ),
64 startWeekOnMonday( startOnMonday ) 62 startWeekOnMonday( startOnMonday )
65{ 63{
66 if (strDayTemplate.isEmpty() ) 64 if (strDayTemplate.isEmpty() )
67 fillStrings(); 65 fillStrings();
68 66
69 init(); 67 init();
70 fraType->setButton( currInterval ); 68 fraType->setButton( currInterval );
71 chkNoEnd->setChecked( TRUE ); 69 chkNoEnd->setChecked( TRUE );
72 setupNone(); 70 setupNone();
73} 71}
74 72
75/** 73/**
76 * Different constructor 74 * Different constructor
77 * @param startOnMonday Does the week start on monday? 75 * @param startOnMonday Does the week start on monday?
78 * @param rp Already set ORecur object 76 * @param rp Already set ORecur object
79 * @param startDate The start date 77 * @param startDate The start date
80 * @param parent The parent widget 78 * @param parent The parent widget
81 * @param name The name of the object 79 * @param name The name of the object
82 * @param modal 80 * @param modal
83 * @param fl The flags for window 81 * @param fl The flags for window
84 */ 82 */
85ORecurranceWidget::ORecurranceWidget( bool startOnMonday, 83ORecurranceWidget::ORecurranceWidget( bool startOnMonday,
86 const ORecur& rp, const QDate& startDate, 84 const ORecur& rp, const QDate& startDate,
87 QWidget* parent, const char* name, 85 QWidget* parent, const char* name,
88 bool modal, WFlags fl) 86 bool modal, WFlags fl)
89 : ORecurranceBase( parent, name, modal, fl ), 87 : ORecurranceBase( parent, name, modal, fl ),
90 start( startDate ), 88 start( startDate ),
91 end( rp.endDate() ), 89 end( rp.endDate() ),
92 startWeekOnMonday( startOnMonday ) 90 startWeekOnMonday( startOnMonday )
93{ 91{
94 if (strDayTemplate.isEmpty() ) 92 if (strDayTemplate.isEmpty() )
95 fillStrings(); 93 fillStrings();
96 // do some stuff with the repeat pattern 94 // do some stuff with the repeat pattern
97 init(); 95 init();
98 setRecurrence( rp ); 96 setRecurrence( rp );
99} 97}
100 98
101ORecurranceWidget::~ORecurranceWidget() { 99ORecurranceWidget::~ORecurranceWidget() {
102} 100}
103 101
104/** 102/**
105 * set the start date 103 * set the start date
106 * @param date the new start date 104 * @param date the new start date
107 */ 105 */
108void ORecurranceWidget::setStartDate( const QDate& date ) { 106void ORecurranceWidget::setStartDate( const QDate& date ) {
109 setRecurrence( recurrence(), date ); 107 setRecurrence( recurrence(), date );
110} 108}
111/** 109/**
112 * set the recurrence 110 * set the recurrence
113 * @param rp The ORecur object with the new recurrence rules 111 * @param rp The ORecur object with the new recurrence rules
114 */ 112 */
115void ORecurranceWidget::setRecurrence( const ORecur& rp ) { 113void ORecurranceWidget::setRecurrence( const ORecur& rp ) {
116 setRecurrence( rp, start ); 114 setRecurrence( rp, start );
117} 115}
118 116
119/** 117/**
120 * overloaded method taking ORecur and a new start date 118 * overloaded method taking ORecur and a new start date
121 * @param rp Recurrence rule 119 * @param rp Recurrence rule
122 * @param date The new start date 120 * @param date The new start date
123 */ 121 */
124void ORecurranceWidget::setRecurrence( const ORecur& rp, const QDate& date ) { 122void ORecurranceWidget::setRecurrence( const ORecur& rp, const QDate& date ) {
125 start = date; 123 start = date;
126 end = rp.endDate(); 124 end = rp.endDate();
127 switch ( rp.type() ) { 125 switch ( rp.type() ) {
128 default: 126 default:
129 case ORecur::NoRepeat: 127 case ORecur::NoRepeat:
130 currInterval = None; 128 currInterval = None;
131 setupNone(); 129 setupNone();
132 break; 130 break;
133 case ORecur::Daily: 131 case ORecur::Daily:
134 currInterval = Day; 132 currInterval = Day;
135 setupDaily(); 133 setupDaily();
136 break; 134 break;
137 case ORecur::Weekly: 135 case ORecur::Weekly:
138 currInterval = Week; 136 currInterval = Week;
139 setupWeekly(); 137 setupWeekly();
140 int day, buttons; 138 int day, buttons;
141 for ( day = 0x01, buttons = 0; buttons < 7; 139 for ( day = 0x01, buttons = 0; buttons < 7;
142 day = day << 1, buttons++ ) { 140 day = day << 1, buttons++ ) {
143 if ( rp.days() & day ) { 141 if ( rp.days() & day ) {
144 if ( startWeekOnMonday ) 142 if ( startWeekOnMonday )
145 fraExtra->setButton( buttons ); 143 fraExtra->setButton( buttons );
146 else { 144 else {
147 if ( buttons == 7 ) 145 if ( buttons == 7 )
148 fraExtra->setButton( 0 ); 146 fraExtra->setButton( 0 );
149 else 147 else
150 fraExtra->setButton( buttons + 1 ); 148 fraExtra->setButton( buttons + 1 );
151 } 149 }
152 } 150 }
153 } 151 }
154 slotWeekLabel(); 152 slotWeekLabel();
155 break; 153 break;
156 case ORecur::MonthlyDay: 154 case ORecur::MonthlyDay:
157 currInterval = Month; 155 currInterval = Month;
158 setupMonthly(); 156 setupMonthly();
159 fraExtra->setButton( 0 ); 157 fraExtra->setButton( 0 );
160 slotMonthLabel( 0 ); 158 slotMonthLabel( 0 );
161 break; 159 break;
162 case ORecur::MonthlyDate: 160 case ORecur::MonthlyDate:
163 currInterval = Month; 161 currInterval = Month;
164 setupMonthly(); 162 setupMonthly();
165 fraExtra->setButton( 1 ); 163 fraExtra->setButton( 1 );
166 slotMonthLabel( 1 ); 164 slotMonthLabel( 1 );
167 break; 165 break;
168 case ORecur::Yearly: 166 case ORecur::Yearly:
169 currInterval = Year; 167 currInterval = Year;
170 setupYearly(); 168 setupYearly();
171 break; 169 break;
172 } 170 }
173 fraType->setButton( currInterval ); 171 fraType->setButton( currInterval );
174 spinFreq->setValue( rp.frequency() ); 172 spinFreq->setValue( rp.frequency() );
175 if ( !rp.hasEndDate() ) { 173 if ( !rp.hasEndDate() ) {
176 cmdEnd->setText( tr("No End Date") ); 174 cmdEnd->setText( tr("No End Date") );
177 chkNoEnd->setChecked( TRUE ); 175 chkNoEnd->setChecked( TRUE );
178 } else 176 } else
179 cmdEnd->setText( TimeString::shortDate( end ) ); 177 cmdEnd->setText( TimeString::shortDate( end ) );
180} 178}
181 179
182/** 180/**
183 * the user selected recurrence rule. 181 * the user selected recurrence rule.
184 * @return The recurrence rule. 182 * @return The recurrence rule.
185 */ 183 */
186ORecur ORecurranceWidget::recurrence()const { 184ORecur ORecurranceWidget::recurrence()const {
187 QListIterator<QToolButton> it( listRTypeButtons ); 185 QListIterator<QToolButton> it( listRTypeButtons );
188 QListIterator<QToolButton> itExtra( listExtra ); 186 QListIterator<QToolButton> itExtra( listExtra );
189 ORecur rpTmp; 187 ORecur rpTmp;
190 int i; 188 int i;
191 for ( i = 0; *it; ++it, i++ ) { 189 for ( i = 0; *it; ++it, i++ ) {
192 if ( (*it)->isOn() ) { 190 if ( (*it)->isOn() ) {
193 switch ( i ) { 191 switch ( i ) {
194 case None: 192 case None:
195 rpTmp.setType( ORecur::NoRepeat ); 193 rpTmp.setType( ORecur::NoRepeat );
196 break; 194 break;
197 case Day: 195 case Day:
198 rpTmp.setType( ORecur::Daily ); 196 rpTmp.setType( ORecur::Daily );
199 break; 197 break;
200 case Week:{ 198 case Week:{
201 rpTmp.setType( ORecur::Weekly ); 199 rpTmp.setType( ORecur::Weekly );
202 int day; 200 int day;
203 int day2 = 0; 201 int day2 = 0;
204 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { 202 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) {
205 if ( (*itExtra)->isOn() ) { 203 if ( (*itExtra)->isOn() ) {
206 if ( startWeekOnMonday ) 204 if ( startWeekOnMonday )
207 day2 |= day; 205 day2 |= day;
208 else { 206 else {
209 if ( day == 1 ) 207 if ( day == 1 )
210 day2 |= Event::SUN; 208 day2 |= Event::SUN;
211 else 209 else
212 day2 |= day >> 1; 210 day2 |= day >> 1;
213 } 211 }
214 } 212 }
215 } 213 }
216 rpTmp.setDays( day2 ); 214 rpTmp.setDays( day2 );
217 } 215 }
218 break; 216 break;
219 case Month: 217 case Month:
220 if ( cmdExtra1->isOn() ) 218 if ( cmdExtra1->isOn() )
221 rpTmp.setType( ORecur::MonthlyDay ); 219 rpTmp.setType( ORecur::MonthlyDay );
222 else if ( cmdExtra2->isOn() ) 220 else if ( cmdExtra2->isOn() )
223 rpTmp.setType( ORecur::MonthlyDate ); 221 rpTmp.setType( ORecur::MonthlyDate );
224 // figure out the montly day... 222 // figure out the montly day...
225 rpTmp.setPosition( week( start ) ); 223 rpTmp.setPosition( week( start ) );
226 break; 224 break;
227 case Year: 225 case Year:
228 rpTmp.setType( ORecur::Yearly ); 226 rpTmp.setType( ORecur::Yearly );
229 break; 227 break;
230 } 228 }
231 break; // no need to keep looking! 229 break; // no need to keep looking!
232 } 230 }
233 } 231 }
234 rpTmp.setFrequency(spinFreq->value() ); 232 rpTmp.setFrequency(spinFreq->value() );
235 rpTmp.setHasEndDate( !chkNoEnd->isChecked() ); 233 rpTmp.setHasEndDate( !chkNoEnd->isChecked() );
236 if ( rpTmp.hasEndDate() ) { 234 if ( rpTmp.hasEndDate() ) {
237 rpTmp.setEndDate( end ); 235 rpTmp.setEndDate( end );
238 } 236 }
239 // timestamp it... 237 // timestamp it...
240// rpTmp.setCreateTime( ); current DateTime is already set -zecke 238// rpTmp.setCreateTime( ); current DateTime is already set -zecke
241 return rpTmp; 239 return rpTmp;
242} 240}
243 241
244/** 242/**
245 * Return the end date of the recurrence. This is only 243 * Return the end date of the recurrence. This is only
246 * valid if the recurrence rule does contain an enddate 244 * valid if the recurrence rule does contain an enddate
247 */ 245 */
248QDate ORecurranceWidget::endDate()const { 246QDate ORecurranceWidget::endDate()const {
249 return end; 247 return end;
250} 248}
251void ORecurranceWidget::slotSetRType(int rtype) { 249void ORecurranceWidget::slotSetRType(int rtype) {
252 // now call the right function based on the type... 250 // now call the right function based on the type...
253 currInterval = static_cast<repeatButtons>(rtype); 251 currInterval = static_cast<repeatButtons>(rtype);
254 switch ( currInterval ) { 252 switch ( currInterval ) {
255 case None: 253 case None:
256 setupNone(); 254 setupNone();
257 break; 255 break;
258 case Day: 256 case Day:
259 setupDaily(); 257 setupDaily();
260 break; 258 break;
261 case Week: 259 case Week:
262 setupWeekly(); 260 setupWeekly();
263 slotWeekLabel(); 261 slotWeekLabel();
264 break; 262 break;
265 case Month: 263 case Month:
266 setupMonthly(); 264 setupMonthly();
267 cmdExtra2->setOn( TRUE ); 265 cmdExtra2->setOn( TRUE );
268 slotMonthLabel( 1 ); 266 slotMonthLabel( 1 );
269 break; 267 break;
270 case Year: 268 case Year:
271 setupYearly(); 269 setupYearly();
272 break; 270 break;
273 } 271 }
274} 272}
275void ORecurranceWidget::endDateChanged(int y, int m, int d) { 273void ORecurranceWidget::endDateChanged(int y, int m, int d) {
276 end.setYMD( y, m, d ); 274 end.setYMD( y, m, d );
277 if ( end < start ) 275 if ( end < start )
278 end = start; 276 end = start;
279 cmdEnd->setText( TimeString::shortDate( end ) ); 277 cmdEnd->setText( TimeString::shortDate( end ) );
280 repeatPicker->setDate( end.year(), end.month(), end.day() ); 278 repeatPicker->setDate( end.year(), end.month(), end.day() );
281} 279}
282void ORecurranceWidget::slotNoEnd( bool unused) { 280void ORecurranceWidget::slotNoEnd( bool unused) {
283 // if the item was toggled, then go ahead and set it to the maximum date 281 // if the item was toggled, then go ahead and set it to the maximum date
284 if ( unused ) { 282 if ( unused ) {
285 end.setYMD( 3000, 12, 31 ); 283 end.setYMD( 3000, 12, 31 );
286 cmdEnd->setText( tr("No End Date") ); 284 cmdEnd->setText( tr("No End Date") );
287 } else { 285 } else {
288 end = start; 286 end = start;
289 cmdEnd->setText( TimeString::shortDate(end) ); 287 cmdEnd->setText( TimeString::shortDate(end) );
290 } 288 }
291} 289}
292void ORecurranceWidget::setupRepeatLabel( const QString& s) { 290void ORecurranceWidget::setupRepeatLabel( const QString& s) {
293 lblVar1->setText( s ); 291 lblVar1->setText( s );
294} 292}
295void ORecurranceWidget::setupRepeatLabel( int x) { 293void ORecurranceWidget::setupRepeatLabel( int x) {
296 // change the spelling based on the value of x 294 // change the spelling based on the value of x
297 QString strVar2; 295 QString strVar2;
298 296
299 if ( x > 1 ) 297 if ( x > 1 )
300 lblVar1->show(); 298 lblVar1->show();
301 else 299 else
302 lblVar1->hide(); 300 lblVar1->hide();
303 301
304 switch ( currInterval ) { 302 switch ( currInterval ) {
305 case None: 303 case None:
306 break; 304 break;
307 case Day: 305 case Day:
308 if ( x > 1 ) 306 if ( x > 1 )
309 strVar2 = tr( "days" ); 307 strVar2 = tr( "days" );
310 else 308 else
311 strVar2 = tr( "day" ); 309 strVar2 = tr( "day" );
312 break; 310 break;
313 case Week: 311 case Week:
314 if ( x > 1 ) 312 if ( x > 1 )
315 strVar2 = tr( "weeks" ); 313 strVar2 = tr( "weeks" );
316 else 314 else
317 strVar2 = tr( "week" ); 315 strVar2 = tr( "week" );
318 break; 316 break;
319 case Month: 317 case Month:
320 if ( x > 1 ) 318 if ( x > 1 )
321 strVar2 = tr( "months" ); 319 strVar2 = tr( "months" );
322 else 320 else
323 strVar2 = tr( "month" ); 321 strVar2 = tr( "month" );
324 break; 322 break;
325 case Year: 323 case Year:
326 if ( x > 1 ) 324 if ( x > 1 )
327 strVar2 = tr( "years" ); 325 strVar2 = tr( "years" );
328 else 326 else
329 strVar2 = tr( "year" ); 327 strVar2 = tr( "year" );
330 break; 328 break;
331 } 329 }
332 if ( !strVar2.isNull() ) 330 if ( !strVar2.isNull() )
333 lblVar2->setText( strVar2 ); 331 lblVar2->setText( strVar2 );
334} 332}
335void ORecurranceWidget::slotWeekLabel() { 333void ORecurranceWidget::slotWeekLabel() {
336 QString str; 334 QString str;
337 QListIterator<QToolButton> it( listExtra ); 335 QListIterator<QToolButton> it( listExtra );
338 unsigned int i; 336 unsigned int i;
339 unsigned int keepMe; 337 unsigned int keepMe;
340 bool bNeedCarriage = FALSE; 338 bool bNeedCarriage = FALSE;
341 // don't do something we'll regret!!! 339 // don't do something we'll regret!!!
342 if ( currInterval != Week ) 340 if ( currInterval != Week )
343 return; 341 return;
344 342
345 if ( startWeekOnMonday ) 343 if ( startWeekOnMonday )
346 keepMe = start.dayOfWeek() - 1; 344 keepMe = start.dayOfWeek() - 1;
347 else 345 else
348 keepMe = start.dayOfWeek() % 7; 346 keepMe = start.dayOfWeek() % 7;
349 347
350 QStringList list; 348 QStringList list;
351 for ( i = 0; *it; ++it, i++ ) { 349 for ( i = 0; *it; ++it, i++ ) {
352 // a crazy check, if you are repeating weekly, the current day 350 // a crazy check, if you are repeating weekly, the current day
353 // must be selected!!! 351 // must be selected!!!
354 if ( i == keepMe && !( (*it)->isOn() ) ) 352 if ( i == keepMe && !( (*it)->isOn() ) )
355 (*it)->setOn( TRUE ); 353 (*it)->setOn( TRUE );
356 if ( (*it)->isOn() ) { 354 if ( (*it)->isOn() ) {
357 if ( startWeekOnMonday ) 355 if ( startWeekOnMonday )
358 list.append( dayLabel[i] ); 356 list.append( dayLabel[i] );
359 else { 357 else {
360 if ( i == 0 ) 358 if ( i == 0 )
361 list.append( dayLabel[6] ); 359 list.append( dayLabel[6] );
362 else 360 else
363 list.append( dayLabel[i - 1] ); 361 list.append( dayLabel[i - 1] );
364 } 362 }
365 } 363 }
366 } 364 }
367 QStringList::Iterator itStr; 365 QStringList::Iterator itStr;
368 for ( i = 0, itStr = list.begin(); itStr != list.end(); ++itStr, i++ ) { 366 for ( i = 0, itStr = list.begin(); itStr != list.end(); ++itStr, i++ ) {
369 if ( i == 3 ) 367 if ( i == 3 )
370 bNeedCarriage = TRUE; 368 bNeedCarriage = TRUE;
371 else 369 else
372 bNeedCarriage = FALSE; 370 bNeedCarriage = FALSE;
373 if ( str.isNull() ) 371 if ( str.isNull() )
374 str = *itStr; 372 str = *itStr;
375 else if ( i == list.count() - 1 ) { 373 else if ( i == list.count() - 1 ) {
376 if ( i < 2 ) 374 if ( i < 2 )
377 str += tr(" and ") + *itStr; 375 str += tr(" and ") + *itStr;
378 else { 376 else {
379 if ( bNeedCarriage ) 377 if ( bNeedCarriage )
380 str += tr( ",\nand " ) + *itStr; 378 str += tr( ",\nand " ) + *itStr;
381 else 379 else
382 str += tr( ", and " ) + *itStr; 380 str += tr( ", and " ) + *itStr;
383 } 381 }
384 } else { 382 } else {
385 if ( bNeedCarriage ) 383 if ( bNeedCarriage )
386 str += ",\n" + *itStr; 384 str += ",\n" + *itStr;
387 else 385 else
388 str += ", " + *itStr; 386 str += ", " + *itStr;
389 } 387 }
390 } 388 }
diff --git a/libopie/oticker.cpp b/libopie/oticker.cpp
index 4fb5945..c05c2a8 100644
--- a/libopie/oticker.cpp
+++ b/libopie/oticker.cpp
@@ -1,139 +1,130 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 3 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public 9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#include <qpe/qpeapplication.h>
32#include <qpe/resource.h>
33#include <qpe/config.h> 31#include <qpe/config.h>
34 32
35#include <qwidget.h>
36#include <qpixmap.h>
37#include <qbutton.h>
38#include <qpainter.h>
39#include <qframe.h>
40#include <qlayout.h>
41#include <qdir.h>
42#include <stdlib.h> 33#include <stdlib.h>
43#include <stdio.h> 34#include <stdio.h>
44 35
45#include "oticker.h" 36#include "oticker.h"
46 37
47OTicker::OTicker( QWidget* parent ) 38OTicker::OTicker( QWidget* parent )
48 : QLabel( parent ) { 39 : QLabel( parent ) {
49 // : QFrame( parent ) { 40 // : QFrame( parent ) {
50 setTextFormat(Qt::RichText); 41 setTextFormat(Qt::RichText);
51 Config cfg("qpe"); 42 Config cfg("qpe");
52 cfg.setGroup("Appearance"); 43 cfg.setGroup("Appearance");
53 backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) ); 44 backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) );
54 foregroundcolor= Qt::black; 45 foregroundcolor= Qt::black;
55 updateTimerTime = 50; 46 updateTimerTime = 50;
56 scrollLength = 1; 47 scrollLength = 1;
57} 48}
58 49
59OTicker::~OTicker() { 50OTicker::~OTicker() {
60} 51}
61 52
62void OTicker::setBackgroundColor(const QColor& backcolor) { 53void OTicker::setBackgroundColor(const QColor& backcolor) {
63 backgroundcolor = backcolor; 54 backgroundcolor = backcolor;
64 update(); 55 update();
65} 56}
66 57
67void OTicker::setForegroundColor(const QColor& backcolor) { 58void OTicker::setForegroundColor(const QColor& backcolor) {
68 foregroundcolor = backcolor; 59 foregroundcolor = backcolor;
69 update(); 60 update();
70} 61}
71 62
72void OTicker::setFrame(int frameStyle) { 63void OTicker::setFrame(int frameStyle) {
73 setFrameStyle( frameStyle/*WinPanel | Sunken */); 64 setFrameStyle( frameStyle/*WinPanel | Sunken */);
74 update(); 65 update();
75} 66}
76 67
77void OTicker::setText( const QString& text ) { 68void OTicker::setText( const QString& text ) {
78 pos = 0; // reset it everytime the text is changed 69 pos = 0; // reset it everytime the text is changed
79 scrollText = text; 70 scrollText = text;
80qDebug(scrollText); 71qDebug(scrollText);
81 72
82 int pixelLen = 0; 73 int pixelLen = 0;
83 bool bigger = false; 74 bool bigger = false;
84 int contWidth = contentsRect().width(); 75 int contWidth = contentsRect().width();
85 int contHeight = contentsRect().height(); 76 int contHeight = contentsRect().height();
86 int pixelTextLen = fontMetrics().width( text ); 77 int pixelTextLen = fontMetrics().width( text );
87 printf("<<<<<<<height %d, width %d, text width %d %d\n", contHeight, contWidth, pixelTextLen, scrollText.length()); 78 printf("<<<<<<<height %d, width %d, text width %d %d\n", contHeight, contWidth, pixelTextLen, scrollText.length());
88 if( pixelTextLen < contWidth) 79 if( pixelTextLen < contWidth)
89 { 80 {
90 pixelLen = contWidth; 81 pixelLen = contWidth;
91 } 82 }
92 else 83 else
93 { 84 {
94 bigger = true; 85 bigger = true;
95 pixelLen = pixelTextLen; 86 pixelLen = pixelTextLen;
96 } 87 }
97 QPixmap pm( pixelLen, contHeight); 88 QPixmap pm( pixelLen, contHeight);
98// pm.fill( QColor( 167, 212, 167 )); 89// pm.fill( QColor( 167, 212, 167 ));
99 90
100 pm.fill(backgroundcolor); 91 pm.fill(backgroundcolor);
101 QPainter pmp( &pm ); 92 QPainter pmp( &pm );
102 pmp.setPen(foregroundcolor ); 93 pmp.setPen(foregroundcolor );
103 pmp.drawText( 0, 0, pixelTextLen, contHeight, AlignVCenter, scrollText ); 94 pmp.drawText( 0, 0, pixelTextLen, contHeight, AlignVCenter, scrollText );
104 pmp.end(); 95 pmp.end();
105 scrollTextPixmap = pm; 96 scrollTextPixmap = pm;
106 97
107 killTimers(); 98 killTimers();
108 // qDebug("Scrollupdate %d", updateTimerTime); 99 // qDebug("Scrollupdate %d", updateTimerTime);
109 if ( bigger /*pixelTextLen > contWidth*/ ) 100 if ( bigger /*pixelTextLen > contWidth*/ )
110 startTimer( updateTimerTime); 101 startTimer( updateTimerTime);
111 update(); 102 update();
112} 103}
113 104
114 105
115void OTicker::timerEvent( QTimerEvent * ) { 106void OTicker::timerEvent( QTimerEvent * ) {
116 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1; 107 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1;
117 repaint( FALSE ); 108 repaint( FALSE );
118} 109}
119 110
120void OTicker::drawContents( QPainter *p ) { 111void OTicker::drawContents( QPainter *p ) {
121 int pixelLen = scrollTextPixmap.width(); 112 int pixelLen = scrollTextPixmap.width();
122 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap ); 113 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap );
123 if ( pixelLen > contentsRect().width() ) // Scrolling 114 if ( pixelLen > contentsRect().width() ) // Scrolling
124 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap ); 115 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
125} 116}
126 117
127void OTicker::mouseReleaseEvent( QMouseEvent * ) { 118void OTicker::mouseReleaseEvent( QMouseEvent * ) {
128// qDebug("<<<<<<<>>>>>>>>>"); 119// qDebug("<<<<<<<>>>>>>>>>");
129 emit mousePressed(); 120 emit mousePressed();
130} 121}
131 122
132void OTicker::setUpdateTime(int time) { 123void OTicker::setUpdateTime(int time) {
133 updateTimerTime=time; 124 updateTimerTime=time;
134} 125}
135 126
136void OTicker::setScrollLength(int len) { 127void OTicker::setScrollLength(int len) {
137scrollLength=len; 128scrollLength=len;
138} 129}
139 130
diff --git a/libopie/otimepicker.cpp b/libopie/otimepicker.cpp
index 115d39b..1eca7c5 100644
--- a/libopie/otimepicker.cpp
+++ b/libopie/otimepicker.cpp
@@ -1,245 +1,242 @@
1#include "otimepicker.h" 1#include "otimepicker.h"
2 2
3#include <qbuttongroup.h>
4#include <qtoolbutton.h>
5#include <qlayout.h> 3#include <qlayout.h>
6#include <qstring.h>
7#include <stdio.h> 4#include <stdio.h>
8#include <qlineedit.h> 5#include <qlineedit.h>
9 6
10 7
11/** 8/**
12 * Constructs the widget 9 * Constructs the widget
13 * @param parent The parent of the OTimePicker 10 * @param parent The parent of the OTimePicker
14 * @param name The name of the object 11 * @param name The name of the object
15 * @param fl Window Flags 12 * @param fl Window Flags
16 */ 13 */
17OTimePicker::OTimePicker(QWidget* parent, const char* name, 14OTimePicker::OTimePicker(QWidget* parent, const char* name,
18 WFlags fl) : 15 WFlags fl) :
19 QWidget(parent,name,fl) 16 QWidget(parent,name,fl)
20{ 17{
21 18
22 QVBoxLayout *vbox=new QVBoxLayout(this); 19 QVBoxLayout *vbox=new QVBoxLayout(this);
23 20
24 OClickableLabel *r; 21 OClickableLabel *r;
25 QString s; 22 QString s;
26 23
27 // Hour Row 24 // Hour Row
28 QWidget *row=new QWidget(this); 25 QWidget *row=new QWidget(this);
29 QHBoxLayout *l=new QHBoxLayout(row); 26 QHBoxLayout *l=new QHBoxLayout(row);
30 vbox->addWidget(row); 27 vbox->addWidget(row);
31 28
32 29
33 for (int i=0; i<24; i++) { 30 for (int i=0; i<24; i++) {
34 r=new OClickableLabel(row); 31 r=new OClickableLabel(row);
35 hourLst.append(r); 32 hourLst.append(r);
36 s.sprintf("%.2d",i); 33 s.sprintf("%.2d",i);
37 r->setText(s); 34 r->setText(s);
38 r->setToggleButton(true); 35 r->setToggleButton(true);
39 r->setAlignment(AlignHCenter | AlignVCenter); 36 r->setAlignment(AlignHCenter | AlignVCenter);
40 l->addWidget(r); 37 l->addWidget(r);
41 connect(r, SIGNAL(toggled(bool)), 38 connect(r, SIGNAL(toggled(bool)),
42 this, SLOT(slotHour(bool))); 39 this, SLOT(slotHour(bool)));
43 40
44 if (i==11) { // Second row 41 if (i==11) { // Second row
45 row=new QWidget(this); 42 row=new QWidget(this);
46 l=new QHBoxLayout(row); 43 l=new QHBoxLayout(row);
47 vbox->addWidget(row); 44 vbox->addWidget(row);
48 } 45 }
49 } 46 }
50 47
51 // Minute Row 48 // Minute Row
52 row=new QWidget(this); 49 row=new QWidget(this);
53 l=new QHBoxLayout(row); 50 l=new QHBoxLayout(row);
54 vbox->addWidget(row); 51 vbox->addWidget(row);
55 52
56 for (int i=0; i<60; i+=5) { 53 for (int i=0; i<60; i+=5) {
57 r=new OClickableLabel(row); 54 r=new OClickableLabel(row);
58 minuteLst.append(r); 55 minuteLst.append(r);
59 s.sprintf("%.2d",i); 56 s.sprintf("%.2d",i);
60 r->setText(s); 57 r->setText(s);
61 r->setToggleButton(true); 58 r->setToggleButton(true);
62 r->setAlignment(AlignHCenter | AlignVCenter); 59 r->setAlignment(AlignHCenter | AlignVCenter);
63 l->addWidget(r); 60 l->addWidget(r);
64 connect(r, SIGNAL(toggled(bool)), 61 connect(r, SIGNAL(toggled(bool)),
65 this, SLOT(slotMinute(bool))); 62 this, SLOT(slotMinute(bool)));
66 } 63 }
67} 64}
68 65
69/** 66/**
70 * This method return the current time 67 * This method return the current time
71 * @return the time 68 * @return the time
72 */ 69 */
73QTime OTimePicker::time()const { 70QTime OTimePicker::time()const {
74 return tm; 71 return tm;
75} 72}
76 73
77void OTimePicker::slotHour(bool b) { 74void OTimePicker::slotHour(bool b) {
78 75
79 OClickableLabel *r = (OClickableLabel *) sender(); 76 OClickableLabel *r = (OClickableLabel *) sender();
80 77
81 if (b) { 78 if (b) {
82 QValueListIterator<OClickableLabel *> it; 79 QValueListIterator<OClickableLabel *> it;
83 for (it=hourLst.begin(); it!=hourLst.end(); it++) { 80 for (it=hourLst.begin(); it!=hourLst.end(); it++) {
84 if (*it != r) (*it)->setOn(false); 81 if (*it != r) (*it)->setOn(false);
85 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); 82 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
86 } 83 }
87 emit timeChanged(tm); 84 emit timeChanged(tm);
88 } else { 85 } else {
89 r->setOn(true); 86 r->setOn(true);
90 } 87 }
91 88
92} 89}
93 90
94void OTimePicker::slotMinute(bool b) { 91void OTimePicker::slotMinute(bool b) {
95 92
96 OClickableLabel *r = (OClickableLabel *) sender(); 93 OClickableLabel *r = (OClickableLabel *) sender();
97 94
98 if (b) { 95 if (b) {
99 QValueListIterator<OClickableLabel *> it; 96 QValueListIterator<OClickableLabel *> it;
100 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { 97 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
101 if (*it != r) (*it)->setOn(false); 98 if (*it != r) (*it)->setOn(false);
102 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); 99 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
103 } 100 }
104 emit timeChanged(tm); 101 emit timeChanged(tm);
105 } else { 102 } else {
106 r->setOn(true); 103 r->setOn(true);
107 } 104 }
108 105
109} 106}
110 107
111/** 108/**
112 * Method to set the time. No signal gets emitted during this method call 109 * Method to set the time. No signal gets emitted during this method call
113 * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) 110 * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... )
114 * @param t The time to be set 111 * @param t The time to be set
115 */ 112 */
116void OTimePicker::setTime( const QTime& t) { 113void OTimePicker::setTime( const QTime& t) {
117 setTime( t.hour(), t.minute() ); 114 setTime( t.hour(), t.minute() );
118} 115}
119 116
120/** 117/**
121 * Method to set the time. No signal gets emitted during this method call 118 * Method to set the time. No signal gets emitted during this method call
122 * @param h The hour 119 * @param h The hour
123 * @param m The minute. Minutes need to set by 5 minute steps 120 * @param m The minute. Minutes need to set by 5 minute steps
124 */ 121 */
125void OTimePicker::setTime( int h, int m ) { 122void OTimePicker::setTime( int h, int m ) {
126 setHour(h); 123 setHour(h);
127 setMinute(m); 124 setMinute(m);
128} 125}
129 126
130/* 127/*
131 * FIXME round minutes to the 5 minute arrangement -zecke 128 * FIXME round minutes to the 5 minute arrangement -zecke
132 */ 129 */
133/** 130/**
134 * Method to set the minutes 131 * Method to set the minutes
135 * @param m minutes 132 * @param m minutes
136 */ 133 */
137void OTimePicker::setMinute(int m) { 134void OTimePicker::setMinute(int m) {
138 135
139 QString minute; 136 QString minute;
140 minute.sprintf("%.2d",m); 137 minute.sprintf("%.2d",m);
141 138
142 QValueListIterator<OClickableLabel *> it; 139 QValueListIterator<OClickableLabel *> it;
143 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { 140 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
144 if ((*it)->text() == minute) (*it)->setOn(true); 141 if ((*it)->text() == minute) (*it)->setOn(true);
145 else (*it)->setOn(false); 142 else (*it)->setOn(false);
146 } 143 }
147 144
148 tm.setHMS(tm.hour(),m,0); 145 tm.setHMS(tm.hour(),m,0);
149} 146}
150 147
151/** 148/**
152 * Method to set the hour 149 * Method to set the hour
153 */ 150 */
154void OTimePicker::setHour(int h) { 151void OTimePicker::setHour(int h) {
155 152
156 QString hour; 153 QString hour;
157 hour.sprintf("%.2d",h); 154 hour.sprintf("%.2d",h);
158 155
159 QValueListIterator<OClickableLabel *> it; 156 QValueListIterator<OClickableLabel *> it;
160 for (it=hourLst.begin(); it!=hourLst.end(); it++) { 157 for (it=hourLst.begin(); it!=hourLst.end(); it++) {
161 if ((*it)->text() == hour) (*it)->setOn(true); 158 if ((*it)->text() == hour) (*it)->setOn(true);
162 else (*it)->setOn(false); 159 else (*it)->setOn(false);
163 } 160 }
164 tm.setHMS(h,tm.minute(),0); 161 tm.setHMS(h,tm.minute(),0);
165} 162}
166 163
167 164
168/** 165/**
169 * This is a modal Dialog. 166 * This is a modal Dialog.
170 * 167 *
171 * @param parent The parent widget 168 * @param parent The parent widget
172 * @param name The name of the object 169 * @param name The name of the object
173 * @param fl Possible window flags 170 * @param fl Possible window flags
174 */ 171 */
175OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) 172OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl )
176 : OTimePickerDialogBase (parent , name, true , fl) 173 : OTimePickerDialogBase (parent , name, true , fl)
177{ 174{
178 175
179 connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ), 176 connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ),
180 this, SLOT( setTime ( const QTime& ) ) ); 177 this, SLOT( setTime ( const QTime& ) ) );
181 connect ( minuteField, SIGNAL( textChanged ( const QString& ) ), 178 connect ( minuteField, SIGNAL( textChanged ( const QString& ) ),
182 this, SLOT ( setMinute ( const QString& ) ) ); 179 this, SLOT ( setMinute ( const QString& ) ) );
183 connect ( hourField, SIGNAL( textChanged ( const QString& ) ), 180 connect ( hourField, SIGNAL( textChanged ( const QString& ) ),
184 this, SLOT ( setHour ( const QString& ) ) ); 181 this, SLOT ( setHour ( const QString& ) ) );
185 182
186} 183}
187 184
188/** 185/**
189 * @return the time 186 * @return the time
190 */ 187 */
191QTime OTimePickerDialog::time()const 188QTime OTimePickerDialog::time()const
192{ 189{
193 return m_time; 190 return m_time;
194} 191}
195 192
196/** 193/**
197 * Set the time to time 194 * Set the time to time
198 * @param time The time to be set 195 * @param time The time to be set
199 */ 196 */
200void OTimePickerDialog::setTime( const QTime& time ) 197void OTimePickerDialog::setTime( const QTime& time )
201{ 198{
202 m_time = time; 199 m_time = time;
203 200
204 m_timePicker->setHour ( time.hour() ); 201 m_timePicker->setHour ( time.hour() );
205 m_timePicker->setMinute( time.minute() ); 202 m_timePicker->setMinute( time.minute() );
206 203
207 // Set Textfields 204 // Set Textfields
208 if ( time.hour() < 10 ) 205 if ( time.hour() < 10 )
209 hourField->setText( "0" + QString::number( time.hour() ) ); 206 hourField->setText( "0" + QString::number( time.hour() ) );
210 else 207 else
211 hourField->setText( QString::number( time.hour() ) ); 208 hourField->setText( QString::number( time.hour() ) );
212 209
213 if ( time.minute() < 10 ) 210 if ( time.minute() < 10 )
214 minuteField->setText( "0" + QString::number( time.minute() ) ); 211 minuteField->setText( "0" + QString::number( time.minute() ) );
215 else 212 else
216 minuteField->setText( QString::number( time.minute() ) ); 213 minuteField->setText( QString::number( time.minute() ) );
217 214
218} 215}
219 216
220/** 217/**
221 * This method takes the current minute and tries to set hour 218 * This method takes the current minute and tries to set hour
222 * to hour. This succeeds if the resulting date is valid 219 * to hour. This succeeds if the resulting date is valid
223 * @param hour The hour as a string 220 * @param hour The hour as a string
224 */ 221 */
225void OTimePickerDialog::setHour ( const QString& hour ) 222void OTimePickerDialog::setHour ( const QString& hour )
226{ 223{
227 if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ){ 224 if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ){
228 m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); 225 m_time.setHMS ( hour.toInt(), m_time.minute() , 00 );
229 setTime ( m_time ); 226 setTime ( m_time );
230 } 227 }
231 228
232} 229}
233 230
234/** 231/**
235 * Method to set a new minute. It tries to convert the string to int and 232 * Method to set a new minute. It tries to convert the string to int and
236 * if the resulting date is valid a new date is set. 233 * if the resulting date is valid a new date is set.
237 * @see setHour 234 * @see setHour
238 */ 235 */
239void OTimePickerDialog::setMinute ( const QString& minute ) 236void OTimePickerDialog::setMinute ( const QString& minute )
240{ 237{
241 if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ){ 238 if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ){
242 m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); 239 m_time.setHMS ( m_time.hour(), minute.toInt(), 00 );
243 setTime ( m_time ); 240 setTime ( m_time );
244 } 241 }
245} 242}
diff --git a/libopie/owait.cpp b/libopie/owait.cpp
index 0fdf08d..a0f3834 100644
--- a/libopie/owait.cpp
+++ b/libopie/owait.cpp
@@ -1,93 +1,91 @@
1/* This file is part of the OPIE libraries 1/* This file is part of the OPIE libraries
2 Copyright (C) 2003 Maximilian Reiss (harlekin@handhelds.org) 2 Copyright (C) 2003 Maximilian Reiss (harlekin@handhelds.org)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <qlabel.h>
21#include <qlayout.h> 20#include <qlayout.h>
22#include <qtimer.h>
23#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
24#include <qpainter.h> 22#include <qpainter.h>
25 23
26#include "owait.h" 24#include "owait.h"
27 25
28#include <qpe/resource.h> 26#include <qpe/resource.h>
29 27
30static int frame = 0; 28static int frame = 0;
31 29
32/** 30/**
33 * This will construct a modal dialog. 31 * This will construct a modal dialog.
34 * 32 *
35 * The default timer length is 10. 33 * The default timer length is 10.
36 * 34 *
37 * @param parent The parent of the widget 35 * @param parent The parent of the widget
38 * @param msg The name of the object 36 * @param msg The name of the object
39 * @param dispIcon Display Icon? 37 * @param dispIcon Display Icon?
40 */ 38 */
41OWait::OWait(QWidget *parent, const char* msg, bool dispIcon ) 39OWait::OWait(QWidget *parent, const char* msg, bool dispIcon )
42 :QDialog(parent, msg, TRUE,WStyle_Customize) { 40 :QDialog(parent, msg, TRUE,WStyle_Customize) {
43 41
44 42
45 QHBoxLayout *hbox = new QHBoxLayout( this ); 43 QHBoxLayout *hbox = new QHBoxLayout( this );
46 44
47 m_lb = new QLabel( this ); 45 m_lb = new QLabel( this );
48 m_lb->setBackgroundMode ( NoBackground ); 46 m_lb->setBackgroundMode ( NoBackground );
49 47
50 hbox->addWidget( m_lb ); 48 hbox->addWidget( m_lb );
51 hbox->activate(); 49 hbox->activate();
52 50
53 m_pix = Resource::loadPixmap( "BigBusy" ); 51 m_pix = Resource::loadPixmap( "BigBusy" );
54 m_aniSize = m_pix.height(); 52 m_aniSize = m_pix.height();
55 resize( m_aniSize, m_aniSize ); 53 resize( m_aniSize, m_aniSize );
56 54
57 m_timerLength = 10; 55 m_timerLength = 10;
58 56
59 m_waitTimer = new QTimer( this ); 57 m_waitTimer = new QTimer( this );
60 connect( m_waitTimer, SIGNAL( timeout() ), this, SLOT( hide() ) ); 58 connect( m_waitTimer, SIGNAL( timeout() ), this, SLOT( hide() ) );
61} 59}
62 60
63void OWait::timerEvent( QTimerEvent * ) { 61void OWait::timerEvent( QTimerEvent * ) {
64 frame = (++frame) % 4; 62 frame = (++frame) % 4;
65 repaint(); 63 repaint();
66} 64}
67 65
68void OWait::paintEvent( QPaintEvent * ) { 66void OWait::paintEvent( QPaintEvent * ) {
69 QPainter p( m_lb ); 67 QPainter p( m_lb );
70 p.drawPixmap( 0, 0, m_pix, m_aniSize * frame, 0, m_aniSize, m_aniSize ); 68 p.drawPixmap( 0, 0, m_pix, m_aniSize * frame, 0, m_aniSize, m_aniSize );
71} 69}
72 70
73void OWait::show() { 71void OWait::show() {
74 72
75 move( ( ( qApp->desktop()->width() ) / 2 ) - ( m_aniSize / 2 ), ( ( qApp->desktop()->height() ) / 2 ) - ( m_aniSize / 2 ) ); 73 move( ( ( qApp->desktop()->width() ) / 2 ) - ( m_aniSize / 2 ), ( ( qApp->desktop()->height() ) / 2 ) - ( m_aniSize / 2 ) );
76 startTimer( 300 ); 74 startTimer( 300 );
77 m_waitTimer->start( m_timerLength * 1000, true ); 75 m_waitTimer->start( m_timerLength * 1000, true );
78 QDialog::show(); 76 QDialog::show();
79} 77}
80 78
81void OWait::hide() { 79void OWait::hide() {
82 killTimers(); 80 killTimers();
83 m_waitTimer->stop(); 81 m_waitTimer->stop();
84 frame = 0; 82 frame = 0;
85 QDialog::hide(); 83 QDialog::hide();
86} 84}
87 85
88void OWait::setTimerLength( int length ) { 86void OWait::setTimerLength( int length ) {
89 m_timerLength = length; 87 m_timerLength = length;
90} 88}
91 89
92OWait::~OWait() { 90OWait::~OWait() {
93} 91}
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp
index aae7fca..2373ad6 100644
--- a/libopie/pim/ocontactaccessbackend_xml.cpp
+++ b/libopie/pim/ocontactaccessbackend_xml.cpp
@@ -1,497 +1,498 @@
1/* 1/*
2 * XML Backend for the OPIE-Contact Database. 2 * XML Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 5 *
6 * ===================================================================== 6 * =====================================================================
7 *This program is free software; you can redistribute it and/or 7 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 8 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 11 * =====================================================================
12 * 12 *
13 * ===================================================================== 13 * =====================================================================
14 * Version: $Id$ 14 * Version: $Id$
15 * ===================================================================== 15 * =====================================================================
16 * History: 16 * History:
17 * $Log$ 17 * $Log$
18 * Revision 1.10 2004/03/01 15:44:36 chicken
19 * fix includes
20 *
18 * Revision 1.9 2003/09/22 14:31:16 eilers 21 * Revision 1.9 2003/09/22 14:31:16 eilers
19 * Added first experimental incarnation of sql-backend for addressbook. 22 * Added first experimental incarnation of sql-backend for addressbook.
20 * Some modifications to be able to compile the todo sql-backend. 23 * Some modifications to be able to compile the todo sql-backend.
21 * A lot of changes fill follow... 24 * A lot of changes fill follow...
22 * 25 *
23 * Revision 1.8 2003/08/30 15:28:26 eilers 26 * Revision 1.8 2003/08/30 15:28:26 eilers
24 * Removed some unimportant debug output which causes slow down.. 27 * Removed some unimportant debug output which causes slow down..
25 * 28 *
26 * Revision 1.7 2003/08/01 12:30:16 eilers 29 * Revision 1.7 2003/08/01 12:30:16 eilers
27 * Merging changes from BRANCH_1_0 to HEAD 30 * Merging changes from BRANCH_1_0 to HEAD
28 * 31 *
29 * Revision 1.6 2003/07/07 16:19:47 eilers 32 * Revision 1.6 2003/07/07 16:19:47 eilers
30 * Fixing serious bug in hasQuerySettings() 33 * Fixing serious bug in hasQuerySettings()
31 * 34 *
32 * Revision 1.5 2003/04/13 18:07:10 zecke 35 * Revision 1.5 2003/04/13 18:07:10 zecke
33 * More API doc 36 * More API doc
34 * QString -> const QString& 37 * QString -> const QString&
35 * QString = 0l -> QString::null 38 * QString = 0l -> QString::null
36 * 39 *
37 * Revision 1.4 2003/03/21 14:32:54 mickeyl 40 * Revision 1.4 2003/03/21 14:32:54 mickeyl
38 * g++ compliance fix: default arguments belong into the declaration, but not the definition 41 * g++ compliance fix: default arguments belong into the declaration, but not the definition
39 * 42 *
40 * Revision 1.3 2003/03/21 12:26:28 eilers 43 * Revision 1.3 2003/03/21 12:26:28 eilers
41 * Fixing small bug: If we search a birthday from today to today, it returned 44 * Fixing small bug: If we search a birthday from today to today, it returned
42 * every contact .. 45 * every contact ..
43 * 46 *
44 * Revision 1.2 2003/03/21 10:33:09 eilers 47 * Revision 1.2 2003/03/21 10:33:09 eilers
45 * Merged speed optimized xml backend for contacts to main. 48 * Merged speed optimized xml backend for contacts to main.
46 * Added QDateTime to querybyexample. For instance, it is now possible to get 49 * Added QDateTime to querybyexample. For instance, it is now possible to get
47 * all Birthdays/Anniversaries between two dates. This should be used 50 * all Birthdays/Anniversaries between two dates. This should be used
48 * to show all birthdays in the datebook.. 51 * to show all birthdays in the datebook..
49 * This change is sourcecode backward compatible but you have to upgrade 52 * This change is sourcecode backward compatible but you have to upgrade
50 * the binaries for today-addressbook. 53 * the binaries for today-addressbook.
51 * 54 *
52 * Revision 1.1.2.2 2003/02/11 12:17:28 eilers 55 * Revision 1.1.2.2 2003/02/11 12:17:28 eilers
53 * Speed optimization. Removed the sequential search loops. 56 * Speed optimization. Removed the sequential search loops.
54 * 57 *
55 * Revision 1.1.2.1 2003/02/10 15:31:38 eilers 58 * Revision 1.1.2.1 2003/02/10 15:31:38 eilers
56 * Writing offsets to debug output.. 59 * Writing offsets to debug output..
57 * 60 *
58 * Revision 1.1 2003/02/09 15:05:01 eilers 61 * Revision 1.1 2003/02/09 15:05:01 eilers
59 * Nothing happened.. Just some cleanup before I will start.. 62 * Nothing happened.. Just some cleanup before I will start..
60 * 63 *
61 * Revision 1.12 2003/01/03 16:58:03 eilers 64 * Revision 1.12 2003/01/03 16:58:03 eilers
62 * Reenable debug output 65 * Reenable debug output
63 * 66 *
64 * Revision 1.11 2003/01/03 12:31:28 eilers 67 * Revision 1.11 2003/01/03 12:31:28 eilers
65 * Bugfix for calculating data diffs.. 68 * Bugfix for calculating data diffs..
66 * 69 *
67 * Revision 1.10 2003/01/02 14:27:12 eilers 70 * Revision 1.10 2003/01/02 14:27:12 eilers
68 * Improved query by example: Search by date is possible.. First step 71 * Improved query by example: Search by date is possible.. First step
69 * for a today plugin for birthdays.. 72 * for a today plugin for birthdays..
70 * 73 *
71 * Revision 1.9 2002/12/08 12:48:57 eilers 74 * Revision 1.9 2002/12/08 12:48:57 eilers
72 * Moved journal-enum from ocontact into i the xml-backend.. 75 * Moved journal-enum from ocontact into i the xml-backend..
73 * 76 *
74 * Revision 1.8 2002/11/14 17:04:24 eilers 77 * Revision 1.8 2002/11/14 17:04:24 eilers
75 * Sorting will now work if fullname is identical on some entries 78 * Sorting will now work if fullname is identical on some entries
76 * 79 *
77 * Revision 1.7 2002/11/13 15:02:46 eilers 80 * Revision 1.7 2002/11/13 15:02:46 eilers
78 * Small Bug in sorted fixed 81 * Small Bug in sorted fixed
79 * 82 *
80 * Revision 1.6 2002/11/13 14:14:51 eilers 83 * Revision 1.6 2002/11/13 14:14:51 eilers
81 * Added sorted for Contacts.. 84 * Added sorted for Contacts..
82 * 85 *
83 * Revision 1.5 2002/11/01 15:10:42 eilers 86 * Revision 1.5 2002/11/01 15:10:42 eilers
84 * Added regExp-search in database for all fields in a contact. 87 * Added regExp-search in database for all fields in a contact.
85 * 88 *
86 * Revision 1.4 2002/10/16 10:52:40 eilers 89 * Revision 1.4 2002/10/16 10:52:40 eilers
87 * Added some docu to the interface and now using the cache infrastucture by zecke.. :) 90 * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
88 * 91 *
89 * Revision 1.3 2002/10/14 16:21:54 eilers 92 * Revision 1.3 2002/10/14 16:21:54 eilers
90 * Some minor interface updates 93 * Some minor interface updates
91 * 94 *
92 * Revision 1.2 2002/10/07 17:34:24 eilers 95 * Revision 1.2 2002/10/07 17:34:24 eilers
93 * added OBackendFactory for advanced backend access 96 * added OBackendFactory for advanced backend access
94 * 97 *
95 * Revision 1.1 2002/09/27 17:11:44 eilers 98 * Revision 1.1 2002/09/27 17:11:44 eilers
96 * Added API for accessing the Contact-Database ! It is compiling, but 99 * Added API for accessing the Contact-Database ! It is compiling, but
97 * please do not expect that anything is working ! 100 * please do not expect that anything is working !
98 * I will debug that stuff in the next time .. 101 * I will debug that stuff in the next time ..
99 * Please read README_COMPILE for compiling ! 102 * Please read README_COMPILE for compiling !
100 * 103 *
101 * 104 *
102 */ 105 */
103 106
104#include "ocontactaccessbackend_xml.h" 107#include "ocontactaccessbackend_xml.h"
105 108
106#include <qasciidict.h> 109#include <qasciidict.h>
107#include <qdatetime.h>
108#include <qfile.h> 110#include <qfile.h>
109#include <qfileinfo.h> 111#include <qfileinfo.h>
110#include <qregexp.h> 112#include <qregexp.h>
111#include <qarray.h> 113#include <qarray.h>
112#include <qmap.h> 114#include <qmap.h>
113#include <qdatetime.h>
114 115
115#include <qpe/global.h> 116#include <qpe/global.h>
116 117
117#include <opie/xmltree.h> 118#include <opie/xmltree.h>
118#include "ocontactaccessbackend.h" 119#include "ocontactaccessbackend.h"
119#include "ocontactaccess.h" 120#include "ocontactaccess.h"
120 121
121#include <stdlib.h> 122#include <stdlib.h>
122#include <errno.h> 123#include <errno.h>
123 124
124using namespace Opie; 125using namespace Opie;
125 126
126 127
127OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): 128OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ):
128 m_changed( false ) 129 m_changed( false )
129{ 130{
130 // Just m_contactlist should call delete if an entry 131 // Just m_contactlist should call delete if an entry
131 // is removed. 132 // is removed.
132 m_contactList.setAutoDelete( true ); 133 m_contactList.setAutoDelete( true );
133 m_uidToContact.setAutoDelete( false ); 134 m_uidToContact.setAutoDelete( false );
134 135
135 m_appName = appname; 136 m_appName = appname;
136 137
137 /* Set journalfile name ... */ 138 /* Set journalfile name ... */
138 m_journalName = getenv("HOME"); 139 m_journalName = getenv("HOME");
139 m_journalName +="/.abjournal" + appname; 140 m_journalName +="/.abjournal" + appname;
140 141
141 /* Expecting to access the default filename if nothing else is set */ 142 /* Expecting to access the default filename if nothing else is set */
142 if ( filename.isEmpty() ){ 143 if ( filename.isEmpty() ){
143 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); 144 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
144 } else 145 } else
145 m_fileName = filename; 146 m_fileName = filename;
146 147
147 /* Load Database now */ 148 /* Load Database now */
148 load (); 149 load ();
149} 150}
150 151
151bool OContactAccessBackend_XML::save() 152bool OContactAccessBackend_XML::save()
152{ 153{
153 154
154 if ( !m_changed ) 155 if ( !m_changed )
155 return true; 156 return true;
156 157
157 QString strNewFile = m_fileName + ".new"; 158 QString strNewFile = m_fileName + ".new";
158 QFile f( strNewFile ); 159 QFile f( strNewFile );
159 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 160 if ( !f.open( IO_WriteOnly|IO_Raw ) )
160 return false; 161 return false;
161 162
162 int total_written; 163 int total_written;
163 int idx_offset = 0; 164 int idx_offset = 0;
164 QString out; 165 QString out;
165 166
166 // Write Header 167 // Write Header
167 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" 168 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
168 " <Groups>\n" 169 " <Groups>\n"
169 " </Groups>\n" 170 " </Groups>\n"
170 " <Contacts>\n"; 171 " <Contacts>\n";
171 QCString cstr = out.utf8(); 172 QCString cstr = out.utf8();
172 f.writeBlock( cstr.data(), cstr.length() ); 173 f.writeBlock( cstr.data(), cstr.length() );
173 idx_offset += cstr.length(); 174 idx_offset += cstr.length();
174 out = ""; 175 out = "";
175 176
176 // Write all contacts 177 // Write all contacts
177 QListIterator<OContact> it( m_contactList ); 178 QListIterator<OContact> it( m_contactList );
178 for ( ; it.current(); ++it ) { 179 for ( ; it.current(); ++it ) {
179 // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); 180 // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset );
180 out += "<Contact "; 181 out += "<Contact ";
181 (*it)->save( out ); 182 (*it)->save( out );
182 out += "/>\n"; 183 out += "/>\n";
183 cstr = out.utf8(); 184 cstr = out.utf8();
184 total_written = f.writeBlock( cstr.data(), cstr.length() ); 185 total_written = f.writeBlock( cstr.data(), cstr.length() );
185 idx_offset += cstr.length(); 186 idx_offset += cstr.length();
186 if ( total_written != int(cstr.length()) ) { 187 if ( total_written != int(cstr.length()) ) {
187 f.close(); 188 f.close();
188 QFile::remove( strNewFile ); 189 QFile::remove( strNewFile );
189 return false; 190 return false;
190 } 191 }
191 out = ""; 192 out = "";
192 } 193 }
193 out += " </Contacts>\n</AddressBook>\n"; 194 out += " </Contacts>\n</AddressBook>\n";
194 195
195 // Write Footer 196 // Write Footer
196 cstr = out.utf8(); 197 cstr = out.utf8();
197 total_written = f.writeBlock( cstr.data(), cstr.length() ); 198 total_written = f.writeBlock( cstr.data(), cstr.length() );
198 if ( total_written != int( cstr.length() ) ) { 199 if ( total_written != int( cstr.length() ) ) {
199 f.close(); 200 f.close();
200 QFile::remove( strNewFile ); 201 QFile::remove( strNewFile );
201 return false; 202 return false;
202 } 203 }
203 f.close(); 204 f.close();
204 205
205 // move the file over, I'm just going to use the system call 206 // move the file over, I'm just going to use the system call
206 // because, I don't feel like using QDir. 207 // because, I don't feel like using QDir.
207 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { 208 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
208 qWarning( "problem renaming file %s to %s, errno: %d", 209 qWarning( "problem renaming file %s to %s, errno: %d",
209 strNewFile.latin1(), m_journalName.latin1(), errno ); 210 strNewFile.latin1(), m_journalName.latin1(), errno );
210 // remove the tmp file... 211 // remove the tmp file...
211 QFile::remove( strNewFile ); 212 QFile::remove( strNewFile );
212 } 213 }
213 214
214 /* The journalfile should be removed now... */ 215 /* The journalfile should be removed now... */
215 removeJournal(); 216 removeJournal();
216 217
217 m_changed = false; 218 m_changed = false;
218 return true; 219 return true;
219} 220}
220 221
221bool OContactAccessBackend_XML::load () 222bool OContactAccessBackend_XML::load ()
222{ 223{
223 m_contactList.clear(); 224 m_contactList.clear();
224 m_uidToContact.clear(); 225 m_uidToContact.clear();
225 226
226 /* Load XML-File and journal if it exists */ 227 /* Load XML-File and journal if it exists */
227 if ( !load ( m_fileName, false ) ) 228 if ( !load ( m_fileName, false ) )
228 return false; 229 return false;
229 /* The returncode of the journalfile is ignored due to the 230 /* The returncode of the journalfile is ignored due to the
230 * fact that it does not exist when this class is instantiated ! 231 * fact that it does not exist when this class is instantiated !
231 * But there may such a file exist, if the application crashed. 232 * But there may such a file exist, if the application crashed.
232 * Therefore we try to load it to get the changes before the # 233 * Therefore we try to load it to get the changes before the #
233 * crash happened... 234 * crash happened...
234 */ 235 */
235 load (m_journalName, true); 236 load (m_journalName, true);
236 237
237 return true; 238 return true;
238} 239}
239 240
240void OContactAccessBackend_XML::clear () 241void OContactAccessBackend_XML::clear ()
241{ 242{
242 m_contactList.clear(); 243 m_contactList.clear();
243 m_uidToContact.clear(); 244 m_uidToContact.clear();
244 245
245 m_changed = false; 246 m_changed = false;
246} 247}
247 248
248bool OContactAccessBackend_XML::wasChangedExternally() 249bool OContactAccessBackend_XML::wasChangedExternally()
249{ 250{
250 QFileInfo fi( m_fileName ); 251 QFileInfo fi( m_fileName );
251 252
252 QDateTime lastmod = fi.lastModified (); 253 QDateTime lastmod = fi.lastModified ();
253 254
254 return (lastmod != m_readtime); 255 return (lastmod != m_readtime);
255} 256}
256 257
257QArray<int> OContactAccessBackend_XML::allRecords() const 258QArray<int> OContactAccessBackend_XML::allRecords() const
258{ 259{
259 QArray<int> uid_list( m_contactList.count() ); 260 QArray<int> uid_list( m_contactList.count() );
260 261
261 uint counter = 0; 262 uint counter = 0;
262 QListIterator<OContact> it( m_contactList ); 263 QListIterator<OContact> it( m_contactList );
263 for( ; it.current(); ++it ){ 264 for( ; it.current(); ++it ){
264 uid_list[counter++] = (*it)->uid(); 265 uid_list[counter++] = (*it)->uid();
265 } 266 }
266 267
267 return ( uid_list ); 268 return ( uid_list );
268} 269}
269 270
270OContact OContactAccessBackend_XML::find ( int uid ) const 271OContact OContactAccessBackend_XML::find ( int uid ) const
271{ 272{
272 OContact foundContact; //Create empty contact 273 OContact foundContact; //Create empty contact
273 274
274 OContact* found = m_uidToContact.find( QString().setNum( uid ) ); 275 OContact* found = m_uidToContact.find( QString().setNum( uid ) );
275 276
276 if ( found ){ 277 if ( found ){
277 foundContact = *found; 278 foundContact = *found;
278 } 279 }
279 280
280 return ( foundContact ); 281 return ( foundContact );
281} 282}
282 283
283QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, 284QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings,
284 const QDateTime& d ) 285 const QDateTime& d )
285{ 286{
286 287
287 QArray<int> m_currentQuery( m_contactList.count() ); 288 QArray<int> m_currentQuery( m_contactList.count() );
288 QListIterator<OContact> it( m_contactList ); 289 QListIterator<OContact> it( m_contactList );
289 uint arraycounter = 0; 290 uint arraycounter = 0;
290 291
291 for( ; it.current(); ++it ){ 292 for( ; it.current(); ++it ){
292 /* Search all fields and compare them with query object. Store them into list 293 /* Search all fields and compare them with query object. Store them into list
293 * if all fields matches. 294 * if all fields matches.
294 */ 295 */
295 QDate* queryDate = 0l; 296 QDate* queryDate = 0l;
296 QDate* checkDate = 0l; 297 QDate* checkDate = 0l;
297 bool allcorrect = true; 298 bool allcorrect = true;
298 for ( int i = 0; i < Qtopia::Groups; i++ ) { 299 for ( int i = 0; i < Qtopia::Groups; i++ ) {
299 // Birthday and anniversary are special nonstring fields and should 300 // Birthday and anniversary are special nonstring fields and should
300 // be handled specially 301 // be handled specially
301 switch ( i ){ 302 switch ( i ){
302 case Qtopia::Birthday: 303 case Qtopia::Birthday:
303 queryDate = new QDate( query.birthday() ); 304 queryDate = new QDate( query.birthday() );
304 checkDate = new QDate( (*it)->birthday() ); 305 checkDate = new QDate( (*it)->birthday() );
305 case Qtopia::Anniversary: 306 case Qtopia::Anniversary:
306 if ( queryDate == 0l ){ 307 if ( queryDate == 0l ){
307 queryDate = new QDate( query.anniversary() ); 308 queryDate = new QDate( query.anniversary() );
308 checkDate = new QDate( (*it)->anniversary() ); 309 checkDate = new QDate( (*it)->anniversary() );
309 } 310 }
310 311
311 if ( queryDate->isValid() ){ 312 if ( queryDate->isValid() ){
312 if( checkDate->isValid() ){ 313 if( checkDate->isValid() ){
313 if ( settings & OContactAccess::DateYear ){ 314 if ( settings & OContactAccess::DateYear ){
314 if ( queryDate->year() != checkDate->year() ) 315 if ( queryDate->year() != checkDate->year() )
315 allcorrect = false; 316 allcorrect = false;
316 } 317 }
317 if ( settings & OContactAccess::DateMonth ){ 318 if ( settings & OContactAccess::DateMonth ){
318 if ( queryDate->month() != checkDate->month() ) 319 if ( queryDate->month() != checkDate->month() )
319 allcorrect = false; 320 allcorrect = false;
320 } 321 }
321 if ( settings & OContactAccess::DateDay ){ 322 if ( settings & OContactAccess::DateDay ){
322 if ( queryDate->day() != checkDate->day() ) 323 if ( queryDate->day() != checkDate->day() )
323 allcorrect = false; 324 allcorrect = false;
324 } 325 }
325 if ( settings & OContactAccess::DateDiff ) { 326 if ( settings & OContactAccess::DateDiff ) {
326 QDate current; 327 QDate current;
327 // If we get an additional date, we 328 // If we get an additional date, we
328 // will take this date instead of 329 // will take this date instead of
329 // the current one.. 330 // the current one..
330 if ( !d.date().isValid() ) 331 if ( !d.date().isValid() )
331 current = QDate::currentDate(); 332 current = QDate::currentDate();
332 else 333 else
333 current = d.date(); 334 current = d.date();
334 335
335 // We have to equalize the year, otherwise 336 // We have to equalize the year, otherwise
336 // the search will fail.. 337 // the search will fail..
337 checkDate->setYMD( current.year(), 338 checkDate->setYMD( current.year(),
338 checkDate->month(), 339 checkDate->month(),
339 checkDate->day() ); 340 checkDate->day() );
340 if ( *checkDate < current ) 341 if ( *checkDate < current )
341 checkDate->setYMD( current.year()+1, 342 checkDate->setYMD( current.year()+1,
342 checkDate->month(), 343 checkDate->month(),
343 checkDate->day() ); 344 checkDate->day() );
344 345
345 // Check whether the birthday/anniversary date is between 346 // Check whether the birthday/anniversary date is between
346 // the current/given date and the maximum date 347 // the current/given date and the maximum date
347 // ( maximum time range ) ! 348 // ( maximum time range ) !
348 qWarning("Checking if %s is between %s and %s ! ", 349 qWarning("Checking if %s is between %s and %s ! ",
349 checkDate->toString().latin1(), 350 checkDate->toString().latin1(),
350 current.toString().latin1(), 351 current.toString().latin1(),
351 queryDate->toString().latin1() ); 352 queryDate->toString().latin1() );
352 if ( current.daysTo( *queryDate ) >= 0 ){ 353 if ( current.daysTo( *queryDate ) >= 0 ){
353 if ( !( ( *checkDate >= current ) && 354 if ( !( ( *checkDate >= current ) &&
354 ( *checkDate <= *queryDate ) ) ){ 355 ( *checkDate <= *queryDate ) ) ){
355 allcorrect = false; 356 allcorrect = false;
356 qWarning (" Nope!.."); 357 qWarning (" Nope!..");
357 } 358 }
358 } 359 }
359 } 360 }
360 } else{ 361 } else{
361 // checkDate is invalid. Therefore this entry is always rejected 362 // checkDate is invalid. Therefore this entry is always rejected
362 allcorrect = false; 363 allcorrect = false;
363 } 364 }
364 } 365 }
365 366
366 delete queryDate; 367 delete queryDate;
367 queryDate = 0l; 368 queryDate = 0l;
368 delete checkDate; 369 delete checkDate;
369 checkDate = 0l; 370 checkDate = 0l;
370 break; 371 break;
371 default: 372 default:
372 /* Just compare fields which are not empty in the query object */ 373 /* Just compare fields which are not empty in the query object */
373 if ( !query.field(i).isEmpty() ){ 374 if ( !query.field(i).isEmpty() ){
374 switch ( settings & ~( OContactAccess::IgnoreCase 375 switch ( settings & ~( OContactAccess::IgnoreCase
375 | OContactAccess::DateDiff 376 | OContactAccess::DateDiff
376 | OContactAccess::DateYear 377 | OContactAccess::DateYear
377 | OContactAccess::DateMonth 378 | OContactAccess::DateMonth
378 | OContactAccess::DateDay 379 | OContactAccess::DateDay
379 | OContactAccess::MatchOne 380 | OContactAccess::MatchOne
380 ) ){ 381 ) ){
381 382
382 case OContactAccess::RegExp:{ 383 case OContactAccess::RegExp:{
383 QRegExp expr ( query.field(i), 384 QRegExp expr ( query.field(i),
384 !(settings & OContactAccess::IgnoreCase), 385 !(settings & OContactAccess::IgnoreCase),
385 false ); 386 false );
386 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 387 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
387 allcorrect = false; 388 allcorrect = false;
388 } 389 }
389 break; 390 break;
390 case OContactAccess::WildCards:{ 391 case OContactAccess::WildCards:{
391 QRegExp expr ( query.field(i), 392 QRegExp expr ( query.field(i),
392 !(settings & OContactAccess::IgnoreCase), 393 !(settings & OContactAccess::IgnoreCase),
393 true ); 394 true );
394 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 395 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
395 allcorrect = false; 396 allcorrect = false;
396 } 397 }
397 break; 398 break;
398 case OContactAccess::ExactMatch:{ 399 case OContactAccess::ExactMatch:{
399 if (settings & OContactAccess::IgnoreCase){ 400 if (settings & OContactAccess::IgnoreCase){
400 if ( query.field(i).upper() != 401 if ( query.field(i).upper() !=
401 (*it)->field(i).upper() ) 402 (*it)->field(i).upper() )
402 allcorrect = false; 403 allcorrect = false;
403 }else{ 404 }else{
404 if ( query.field(i) != (*it)->field(i) ) 405 if ( query.field(i) != (*it)->field(i) )
405 allcorrect = false; 406 allcorrect = false;
406 } 407 }
407 } 408 }
408 break; 409 break;
409 } 410 }
410 } 411 }
411 } 412 }
412 } 413 }
413 if ( allcorrect ){ 414 if ( allcorrect ){
414 m_currentQuery[arraycounter++] = (*it)->uid(); 415 m_currentQuery[arraycounter++] = (*it)->uid();
415 } 416 }
416 } 417 }
417 418
418 // Shrink to fit.. 419 // Shrink to fit..
419 m_currentQuery.resize(arraycounter); 420 m_currentQuery.resize(arraycounter);
420 421
421 return m_currentQuery; 422 return m_currentQuery;
422} 423}
423 424
424QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const 425QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
425{ 426{
426 QArray<int> m_currentQuery( m_contactList.count() ); 427 QArray<int> m_currentQuery( m_contactList.count() );
427 QListIterator<OContact> it( m_contactList ); 428 QListIterator<OContact> it( m_contactList );
428 uint arraycounter = 0; 429 uint arraycounter = 0;
429 430
430 for( ; it.current(); ++it ){ 431 for( ; it.current(); ++it ){
431 if ( (*it)->match( r ) ){ 432 if ( (*it)->match( r ) ){
432 m_currentQuery[arraycounter++] = (*it)->uid(); 433 m_currentQuery[arraycounter++] = (*it)->uid();
433 } 434 }
434 435
435 } 436 }
436 // Shrink to fit.. 437 // Shrink to fit..
437 m_currentQuery.resize(arraycounter); 438 m_currentQuery.resize(arraycounter);
438 439
439 return m_currentQuery; 440 return m_currentQuery;
440} 441}
441 442
442const uint OContactAccessBackend_XML::querySettings() 443const uint OContactAccessBackend_XML::querySettings()
443{ 444{
444 return ( OContactAccess::WildCards 445 return ( OContactAccess::WildCards
445 | OContactAccess::IgnoreCase 446 | OContactAccess::IgnoreCase
446 | OContactAccess::RegExp 447 | OContactAccess::RegExp
447 | OContactAccess::ExactMatch 448 | OContactAccess::ExactMatch
448 | OContactAccess::DateDiff 449 | OContactAccess::DateDiff
449 | OContactAccess::DateYear 450 | OContactAccess::DateYear
450 | OContactAccess::DateMonth 451 | OContactAccess::DateMonth
451 | OContactAccess::DateDay 452 | OContactAccess::DateDay
452 ); 453 );
453} 454}
454 455
455bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const 456bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
456{ 457{
457 /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 458 /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
458 * may be added with any of the other settings. IgnoreCase should never used alone. 459 * may be added with any of the other settings. IgnoreCase should never used alone.
459 * Wildcards, RegExp, ExactMatch should never used at the same time... 460 * Wildcards, RegExp, ExactMatch should never used at the same time...
460 */ 461 */
461 462
462 // Step 1: Check whether the given settings are supported by this backend 463 // Step 1: Check whether the given settings are supported by this backend
463 if ( ( querySettings & ( 464 if ( ( querySettings & (
464 OContactAccess::IgnoreCase 465 OContactAccess::IgnoreCase
465 | OContactAccess::WildCards 466 | OContactAccess::WildCards
466 | OContactAccess::DateDiff 467 | OContactAccess::DateDiff
467 | OContactAccess::DateYear 468 | OContactAccess::DateYear
468 | OContactAccess::DateMonth 469 | OContactAccess::DateMonth
469 | OContactAccess::DateDay 470 | OContactAccess::DateDay
470 | OContactAccess::RegExp 471 | OContactAccess::RegExp
471 | OContactAccess::ExactMatch 472 | OContactAccess::ExactMatch
472 ) ) != querySettings ) 473 ) ) != querySettings )
473 return false; 474 return false;
474 475
475 // Step 2: Check whether the given combinations are ok.. 476 // Step 2: Check whether the given combinations are ok..
476 477
477 // IngoreCase alone is invalid 478 // IngoreCase alone is invalid
478 if ( querySettings == OContactAccess::IgnoreCase ) 479 if ( querySettings == OContactAccess::IgnoreCase )
479 return false; 480 return false;
480 481
481 // WildCards, RegExp and ExactMatch should never used at the same time 482 // WildCards, RegExp and ExactMatch should never used at the same time
482 switch ( querySettings & ~( OContactAccess::IgnoreCase 483 switch ( querySettings & ~( OContactAccess::IgnoreCase
483 | OContactAccess::DateDiff 484 | OContactAccess::DateDiff
484 | OContactAccess::DateYear 485 | OContactAccess::DateYear
485 | OContactAccess::DateMonth 486 | OContactAccess::DateMonth
486 | OContactAccess::DateDay 487 | OContactAccess::DateDay
487 ) 488 )
488 ){ 489 ){
489 case OContactAccess::RegExp: 490 case OContactAccess::RegExp:
490 return ( true ); 491 return ( true );
491 case OContactAccess::WildCards: 492 case OContactAccess::WildCards:
492 return ( true ); 493 return ( true );
493 case OContactAccess::ExactMatch: 494 case OContactAccess::ExactMatch:
494 return ( true ); 495 return ( true );
495 case 0: // one of the upper removed bits were set.. 496 case 0: // one of the upper removed bits were set..
496 return ( true ); 497 return ( true );
497 default: 498 default:
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index 189bf94..b2c76f8 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -1,396 +1,395 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 8#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 9#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 10#include <qpe/categoryselect.h>
11#include <qpe/stringutil.h>
13 12
14 13
15#include "opimstate.h" 14#include "opimstate.h"
16#include "orecur.h" 15#include "orecur.h"
17#include "opimmaintainer.h" 16#include "opimmaintainer.h"
18#include "opimnotifymanager.h" 17#include "opimnotifymanager.h"
19#include "opimresolver.h" 18#include "opimresolver.h"
20 19
21#include "otodo.h" 20#include "otodo.h"
22 21
23 22
24struct OTodo::OTodoData : public QShared { 23struct OTodo::OTodoData : public QShared {
25 OTodoData() : QShared() { 24 OTodoData() : QShared() {
26 recur = 0; 25 recur = 0;
27 state = 0; 26 state = 0;
28 maintainer = 0; 27 maintainer = 0;
29 notifiers = 0; 28 notifiers = 0;
30 }; 29 };
31 ~OTodoData() { 30 ~OTodoData() {
32 delete recur; 31 delete recur;
33 delete maintainer; 32 delete maintainer;
34 delete notifiers; 33 delete notifiers;
35 } 34 }
36 35
37 QDate date; 36 QDate date;
38 bool isCompleted:1; 37 bool isCompleted:1;
39 bool hasDate:1; 38 bool hasDate:1;
40 int priority; 39 int priority;
41 QString desc; 40 QString desc;
42 QString sum; 41 QString sum;
43 QMap<QString, QString> extra; 42 QMap<QString, QString> extra;
44 ushort prog; 43 ushort prog;
45 OPimState *state; 44 OPimState *state;
46 ORecur *recur; 45 ORecur *recur;
47 OPimMaintainer *maintainer; 46 OPimMaintainer *maintainer;
48 QDate start; 47 QDate start;
49 QDate completed; 48 QDate completed;
50 OPimNotifyManager *notifiers; 49 OPimNotifyManager *notifiers;
51}; 50};
52 51
53OTodo::OTodo(const OTodo &event ) 52OTodo::OTodo(const OTodo &event )
54 : OPimRecord( event ), data( event.data ) 53 : OPimRecord( event ), data( event.data )
55{ 54{
56 data->ref(); 55 data->ref();
57// qWarning("ref up"); 56// qWarning("ref up");
58} 57}
59OTodo::~OTodo() { 58OTodo::~OTodo() {
60 59
61// qWarning("~OTodo " ); 60// qWarning("~OTodo " );
62 if ( data->deref() ) { 61 if ( data->deref() ) {
63// qWarning("OTodo::dereffing"); 62// qWarning("OTodo::dereffing");
64 delete data; 63 delete data;
65 data = 0l; 64 data = 0l;
66 } 65 }
67} 66}
68OTodo::OTodo(bool completed, int priority, 67OTodo::OTodo(bool completed, int priority,
69 const QArray<int> &category, 68 const QArray<int> &category,
70 const QString& summary, 69 const QString& summary,
71 const QString &description, 70 const QString &description,
72 ushort progress, 71 ushort progress,
73 bool hasDate, QDate date, int uid ) 72 bool hasDate, QDate date, int uid )
74 : OPimRecord( uid ) 73 : OPimRecord( uid )
75{ 74{
76// qWarning("OTodoData " + summary); 75// qWarning("OTodoData " + summary);
77 setCategories( category ); 76 setCategories( category );
78 77
79 data = new OTodoData; 78 data = new OTodoData;
80 79
81 data->date = date; 80 data->date = date;
82 data->isCompleted = completed; 81 data->isCompleted = completed;
83 data->hasDate = hasDate; 82 data->hasDate = hasDate;
84 data->priority = priority; 83 data->priority = priority;
85 data->sum = summary; 84 data->sum = summary;
86 data->prog = progress; 85 data->prog = progress;
87 data->desc = Qtopia::simplifyMultiLineSpace(description ); 86 data->desc = Qtopia::simplifyMultiLineSpace(description );
88} 87}
89OTodo::OTodo(bool completed, int priority, 88OTodo::OTodo(bool completed, int priority,
90 const QStringList &category, 89 const QStringList &category,
91 const QString& summary, 90 const QString& summary,
92 const QString &description, 91 const QString &description,
93 ushort progress, 92 ushort progress,
94 bool hasDate, QDate date, int uid ) 93 bool hasDate, QDate date, int uid )
95 : OPimRecord( uid ) 94 : OPimRecord( uid )
96{ 95{
97// qWarning("OTodoData" + summary); 96// qWarning("OTodoData" + summary);
98 setCategories( idsFromString( category.join(";") ) ); 97 setCategories( idsFromString( category.join(";") ) );
99 98
100 data = new OTodoData; 99 data = new OTodoData;
101 100
102 data->date = date; 101 data->date = date;
103 data->isCompleted = completed; 102 data->isCompleted = completed;
104 data->hasDate = hasDate; 103 data->hasDate = hasDate;
105 data->priority = priority; 104 data->priority = priority;
106 data->sum = summary; 105 data->sum = summary;
107 data->prog = progress; 106 data->prog = progress;
108 data->desc = Qtopia::simplifyMultiLineSpace(description ); 107 data->desc = Qtopia::simplifyMultiLineSpace(description );
109} 108}
110bool OTodo::match( const QRegExp &regExp )const 109bool OTodo::match( const QRegExp &regExp )const
111{ 110{
112 if( QString::number( data->priority ).find( regExp ) != -1 ){ 111 if( QString::number( data->priority ).find( regExp ) != -1 ){
113 setLastHitField( Priority ); 112 setLastHitField( Priority );
114 return true; 113 return true;
115 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 114 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
116 setLastHitField( HasDate ); 115 setLastHitField( HasDate );
117 return true; 116 return true;
118 }else if(data->desc.find( regExp ) != -1 ){ 117 }else if(data->desc.find( regExp ) != -1 ){
119 setLastHitField( Description ); 118 setLastHitField( Description );
120 return true; 119 return true;
121 }else if(data->sum.find( regExp ) != -1 ) { 120 }else if(data->sum.find( regExp ) != -1 ) {
122 setLastHitField( Summary ); 121 setLastHitField( Summary );
123 return true; 122 return true;
124 } 123 }
125 return false; 124 return false;
126} 125}
127bool OTodo::isCompleted() const 126bool OTodo::isCompleted() const
128{ 127{
129 return data->isCompleted; 128 return data->isCompleted;
130} 129}
131bool OTodo::hasDueDate() const 130bool OTodo::hasDueDate() const
132{ 131{
133 return data->hasDate; 132 return data->hasDate;
134} 133}
135bool OTodo::hasStartDate()const { 134bool OTodo::hasStartDate()const {
136 return data->start.isValid(); 135 return data->start.isValid();
137} 136}
138bool OTodo::hasCompletedDate()const { 137bool OTodo::hasCompletedDate()const {
139 return data->completed.isValid(); 138 return data->completed.isValid();
140} 139}
141int OTodo::priority()const 140int OTodo::priority()const
142{ 141{
143 return data->priority; 142 return data->priority;
144} 143}
145QString OTodo::summary() const 144QString OTodo::summary() const
146{ 145{
147 return data->sum; 146 return data->sum;
148} 147}
149ushort OTodo::progress() const 148ushort OTodo::progress() const
150{ 149{
151 return data->prog; 150 return data->prog;
152} 151}
153QDate OTodo::dueDate()const 152QDate OTodo::dueDate()const
154{ 153{
155 return data->date; 154 return data->date;
156} 155}
157QDate OTodo::startDate()const { 156QDate OTodo::startDate()const {
158 return data->start; 157 return data->start;
159} 158}
160QDate OTodo::completedDate()const { 159QDate OTodo::completedDate()const {
161 return data->completed; 160 return data->completed;
162} 161}
163QString OTodo::description()const 162QString OTodo::description()const
164{ 163{
165 return data->desc; 164 return data->desc;
166} 165}
167bool OTodo::hasState() const{ 166bool OTodo::hasState() const{
168 if (!data->state ) return false; 167 if (!data->state ) return false;
169 return ( data->state->state() != OPimState::Undefined ); 168 return ( data->state->state() != OPimState::Undefined );
170} 169}
171OPimState OTodo::state()const { 170OPimState OTodo::state()const {
172 if (!data->state ) { 171 if (!data->state ) {
173 OPimState state; 172 OPimState state;
174 return state; 173 return state;
175 } 174 }
176 175
177 return (*data->state); 176 return (*data->state);
178} 177}
179bool OTodo::hasRecurrence()const { 178bool OTodo::hasRecurrence()const {
180 if (!data->recur) return false; 179 if (!data->recur) return false;
181 return data->recur->doesRecur(); 180 return data->recur->doesRecur();
182} 181}
183ORecur OTodo::recurrence()const { 182ORecur OTodo::recurrence()const {
184 if (!data->recur) return ORecur(); 183 if (!data->recur) return ORecur();
185 184
186 return (*data->recur); 185 return (*data->recur);
187} 186}
188bool OTodo::hasMaintainer()const { 187bool OTodo::hasMaintainer()const {
189 if (!data->maintainer) return false; 188 if (!data->maintainer) return false;
190 189
191 return (data->maintainer->mode() != OPimMaintainer::Undefined ); 190 return (data->maintainer->mode() != OPimMaintainer::Undefined );
192} 191}
193OPimMaintainer OTodo::maintainer()const { 192OPimMaintainer OTodo::maintainer()const {
194 if (!data->maintainer) return OPimMaintainer(); 193 if (!data->maintainer) return OPimMaintainer();
195 194
196 return (*data->maintainer); 195 return (*data->maintainer);
197} 196}
198void OTodo::setCompleted( bool completed ) 197void OTodo::setCompleted( bool completed )
199{ 198{
200 changeOrModify(); 199 changeOrModify();
201 data->isCompleted = completed; 200 data->isCompleted = completed;
202} 201}
203void OTodo::setHasDueDate( bool hasDate ) 202void OTodo::setHasDueDate( bool hasDate )
204{ 203{
205 changeOrModify(); 204 changeOrModify();
206 data->hasDate = hasDate; 205 data->hasDate = hasDate;
207} 206}
208void OTodo::setDescription(const QString &desc ) 207void OTodo::setDescription(const QString &desc )
209{ 208{
210// qWarning( "desc " + desc ); 209// qWarning( "desc " + desc );
211 changeOrModify(); 210 changeOrModify();
212 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 211 data->desc = Qtopia::simplifyMultiLineSpace(desc );
213} 212}
214void OTodo::setSummary( const QString& sum ) 213void OTodo::setSummary( const QString& sum )
215{ 214{
216 changeOrModify(); 215 changeOrModify();
217 data->sum = sum; 216 data->sum = sum;
218} 217}
219void OTodo::setPriority(int prio ) 218void OTodo::setPriority(int prio )
220{ 219{
221 changeOrModify(); 220 changeOrModify();
222 data->priority = prio; 221 data->priority = prio;
223} 222}
224void OTodo::setDueDate( const QDate& date ) 223void OTodo::setDueDate( const QDate& date )
225{ 224{
226 changeOrModify(); 225 changeOrModify();
227 data->date = date; 226 data->date = date;
228} 227}
229void OTodo::setStartDate( const QDate& date ) { 228void OTodo::setStartDate( const QDate& date ) {
230 changeOrModify(); 229 changeOrModify();
231 data->start = date; 230 data->start = date;
232} 231}
233void OTodo::setCompletedDate( const QDate& date ) { 232void OTodo::setCompletedDate( const QDate& date ) {
234 changeOrModify(); 233 changeOrModify();
235 data->completed = date; 234 data->completed = date;
236} 235}
237void OTodo::setState( const OPimState& state ) { 236void OTodo::setState( const OPimState& state ) {
238 changeOrModify(); 237 changeOrModify();
239 if (data->state ) 238 if (data->state )
240 (*data->state) = state; 239 (*data->state) = state;
241 else 240 else
242 data->state = new OPimState( state ); 241 data->state = new OPimState( state );
243} 242}
244void OTodo::setRecurrence( const ORecur& rec) { 243void OTodo::setRecurrence( const ORecur& rec) {
245 changeOrModify(); 244 changeOrModify();
246 if (data->recur ) 245 if (data->recur )
247 (*data->recur) = rec; 246 (*data->recur) = rec;
248 else 247 else
249 data->recur = new ORecur( rec ); 248 data->recur = new ORecur( rec );
250} 249}
251void OTodo::setMaintainer( const OPimMaintainer& pim ) { 250void OTodo::setMaintainer( const OPimMaintainer& pim ) {
252 changeOrModify(); 251 changeOrModify();
253 252
254 if (data->maintainer ) 253 if (data->maintainer )
255 (*data->maintainer) = pim; 254 (*data->maintainer) = pim;
256 else 255 else
257 data->maintainer = new OPimMaintainer( pim ); 256 data->maintainer = new OPimMaintainer( pim );
258} 257}
259bool OTodo::isOverdue( ) 258bool OTodo::isOverdue( )
260{ 259{
261 if( data->hasDate && !data->isCompleted) 260 if( data->hasDate && !data->isCompleted)
262 return QDate::currentDate() > data->date; 261 return QDate::currentDate() > data->date;
263 return false; 262 return false;
264} 263}
265void OTodo::setProgress(ushort progress ) 264void OTodo::setProgress(ushort progress )
266{ 265{
267 changeOrModify(); 266 changeOrModify();
268 data->prog = progress; 267 data->prog = progress;
269} 268}
270QString OTodo::toShortText() const { 269QString OTodo::toShortText() const {
271 return summary(); 270 return summary();
272} 271}
273/*! 272/*!
274 Returns a richt text string 273 Returns a richt text string
275*/ 274*/
276QString OTodo::toRichText() const 275QString OTodo::toRichText() const
277{ 276{
278 QString text; 277 QString text;
279 QStringList catlist; 278 QStringList catlist;
280 279
281 // summary 280 // summary
282 text += "<b><h3><img src=\"todo/TodoList\"> "; 281 text += "<b><h3><img src=\"todo/TodoList\"> ";
283 if ( !summary().isEmpty() ) { 282 if ( !summary().isEmpty() ) {
284 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" ); 283 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" );
285 } 284 }
286 text += "</h3></b><br><hr><br>"; 285 text += "</h3></b><br><hr><br>";
287 286
288 // description 287 // description
289 if( !description().isEmpty() ){ 288 if( !description().isEmpty() ){
290 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 289 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
291 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 290 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
292 } 291 }
293 292
294 // priority 293 // priority
295 int priorityval = priority(); 294 int priorityval = priority();
296 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" + 295 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" +
297 QString::number( priorityval ) + "\"> "; 296 QString::number( priorityval ) + "\"> ";
298 297
299 switch ( priorityval ) 298 switch ( priorityval )
300 { 299 {
301 case 1 : text += QObject::tr( "Very high" ); 300 case 1 : text += QObject::tr( "Very high" );
302 break; 301 break;
303 case 2 : text += QObject::tr( "High" ); 302 case 2 : text += QObject::tr( "High" );
304 break; 303 break;
305 case 3 : text += QObject::tr( "Normal" ); 304 case 3 : text += QObject::tr( "Normal" );
306 break; 305 break;
307 case 4 : text += QObject::tr( "Low" ); 306 case 4 : text += QObject::tr( "Low" );
308 break; 307 break;
309 case 5 : text += QObject::tr( "Very low" ); 308 case 5 : text += QObject::tr( "Very low" );
310 break; 309 break;
311 }; 310 };
312 text += "<br>"; 311 text += "<br>";
313 312
314 // progress 313 // progress
315 text += "<b>" + QObject::tr( "Progress:") + " </b>" 314 text += "<b>" + QObject::tr( "Progress:") + " </b>"
316 + QString::number( progress() ) + " %<br>"; 315 + QString::number( progress() ) + " %<br>";
317 316
318 // due date 317 // due date
319 if (hasDueDate() ){ 318 if (hasDueDate() ){
320 QDate dd = dueDate(); 319 QDate dd = dueDate();
321 int off = QDate::currentDate().daysTo( dd ); 320 int off = QDate::currentDate().daysTo( dd );
322 321
323 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; 322 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
324 if ( off < 0 ) 323 if ( off < 0 )
325 text += "#FF0000"; 324 text += "#FF0000";
326 else if ( off == 0 ) 325 else if ( off == 0 )
327 text += "#FFFF00"; 326 text += "#FFFF00";
328 else if ( off > 0 ) 327 else if ( off > 0 )
329 text += "#00FF00"; 328 text += "#00FF00";
330 329
331 text += "\">" + dd.toString() + "</font><br>"; 330 text += "\">" + dd.toString() + "</font><br>";
332 } 331 }
333 332
334 // categories 333 // categories
335 text += "<b>" + QObject::tr( "Category:") + "</b> "; 334 text += "<b>" + QObject::tr( "Category:") + "</b> ";
336 text += categoryNames( "Todo List" ).join(", "); 335 text += categoryNames( "Todo List" ).join(", ");
337 text += "<br>"; 336 text += "<br>";
338 337
339 return text; 338 return text;
340} 339}
341bool OTodo::hasNotifiers()const { 340bool OTodo::hasNotifiers()const {
342 if (!data->notifiers) return false; 341 if (!data->notifiers) return false;
343 return !data->notifiers->isEmpty(); 342 return !data->notifiers->isEmpty();
344} 343}
345OPimNotifyManager& OTodo::notifiers() { 344OPimNotifyManager& OTodo::notifiers() {
346 if (!data->notifiers ) 345 if (!data->notifiers )
347 data->notifiers = new OPimNotifyManager; 346 data->notifiers = new OPimNotifyManager;
348 return (*data->notifiers); 347 return (*data->notifiers);
349} 348}
350const OPimNotifyManager& OTodo::notifiers()const{ 349const OPimNotifyManager& OTodo::notifiers()const{
351 if (!data->notifiers ) 350 if (!data->notifiers )
352 data->notifiers = new OPimNotifyManager; 351 data->notifiers = new OPimNotifyManager;
353 352
354 return (*data->notifiers); 353 return (*data->notifiers);
355} 354}
356 355
357bool OTodo::operator<( const OTodo &toDoEvent )const{ 356bool OTodo::operator<( const OTodo &toDoEvent )const{
358 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 357 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
359 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 358 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
360 if( hasDueDate() && toDoEvent.hasDueDate() ){ 359 if( hasDueDate() && toDoEvent.hasDueDate() ){
361 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 360 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
362 return priority() < toDoEvent.priority(); 361 return priority() < toDoEvent.priority();
363 }else{ 362 }else{
364 return dueDate() < toDoEvent.dueDate(); 363 return dueDate() < toDoEvent.dueDate();
365 } 364 }
366 } 365 }
367 return false; 366 return false;
368} 367}
369bool OTodo::operator<=(const OTodo &toDoEvent )const 368bool OTodo::operator<=(const OTodo &toDoEvent )const
370{ 369{
371 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 370 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
372 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 371 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
373 if( hasDueDate() && toDoEvent.hasDueDate() ){ 372 if( hasDueDate() && toDoEvent.hasDueDate() ){
374 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 373 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
375 return priority() <= toDoEvent.priority(); 374 return priority() <= toDoEvent.priority();
376 }else{ 375 }else{
377 return dueDate() <= toDoEvent.dueDate(); 376 return dueDate() <= toDoEvent.dueDate();
378 } 377 }
379 } 378 }
380 return true; 379 return true;
381} 380}
382bool OTodo::operator>(const OTodo &toDoEvent )const 381bool OTodo::operator>(const OTodo &toDoEvent )const
383{ 382{
384 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 383 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
385 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 384 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
386 if( hasDueDate() && toDoEvent.hasDueDate() ){ 385 if( hasDueDate() && toDoEvent.hasDueDate() ){
387 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 386 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
388 return priority() > toDoEvent.priority(); 387 return priority() > toDoEvent.priority();
389 }else{ 388 }else{
390 return dueDate() > toDoEvent.dueDate(); 389 return dueDate() > toDoEvent.dueDate();
391 } 390 }
392 } 391 }
393 return false; 392 return false;
394} 393}
395bool OTodo::operator>=(const OTodo &toDoEvent )const 394bool OTodo::operator>=(const OTodo &toDoEvent )const
396{ 395{