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,858 +1,856 @@
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
436void QColorShowLabel::drawContents( QPainter *p ) 434void QColorShowLabel::drawContents( QPainter *p )
437{ 435{
438 p->fillRect( contentsRect(), col ); 436 p->fillRect( contentsRect(), col );
439} 437}
440 438
441void QColorShower::showAlpha( bool b ) 439void QColorShower::showAlpha( bool b )
442{ 440{
443 if ( b ) { 441 if ( b ) {
444 alphaLab->show(); 442 alphaLab->show();
445 alphaEd->show(); 443 alphaEd->show();
446 } else { 444 } else {
447 alphaLab->hide(); 445 alphaLab->hide();
448 alphaEd->hide(); 446 alphaEd->hide();
449 } 447 }
450} 448}
451 449
452void QColorShowLabel::mousePressEvent( QMouseEvent *e ) 450void QColorShowLabel::mousePressEvent( QMouseEvent *e )
453{ 451{
454 mousePressed = TRUE; 452 mousePressed = TRUE;
455 pressPos = e->pos(); 453 pressPos = e->pos();
456} 454}
457 455
458void QColorShowLabel::mouseReleaseEvent( QMouseEvent * ) 456void QColorShowLabel::mouseReleaseEvent( QMouseEvent * )
459{ 457{
460 if ( !mousePressed ) 458 if ( !mousePressed )
461 return; 459 return;
462 mousePressed = FALSE; 460 mousePressed = FALSE;
463} 461}
464 462
465QColorShower::QColorShower( QWidget *parent, const char *name ) 463QColorShower::QColorShower( QWidget *parent, const char *name )
466 :QWidget( parent, name) 464 :QWidget( parent, name)
467{ 465{
468 curCol = qRgb( -1, -1, -1 ); 466 curCol = qRgb( -1, -1, -1 );
469 QColIntValidator *val256 = new QColIntValidator( 0, 255, this ); 467 QColIntValidator *val256 = new QColIntValidator( 0, 255, this );
470 QColIntValidator *val360 = new QColIntValidator( 0, 360, this ); 468 QColIntValidator *val360 = new QColIntValidator( 0, 360, this );
471 469
472 QGridLayout *gl = new QGridLayout( this, 1, 1, 2 ); 470 QGridLayout *gl = new QGridLayout( this, 1, 1, 2 );
473 gl->setMargin( 0 ); 471 gl->setMargin( 0 );
474 lab = new QColorShowLabel( this ); 472 lab = new QColorShowLabel( this );
475 lab->setMinimumWidth( 60 ); //### 473 lab->setMinimumWidth( 60 ); //###
476 gl->addMultiCellWidget(lab, 0,-1,0,0); 474 gl->addMultiCellWidget(lab, 0,-1,0,0);
477 connect( lab, SIGNAL( colorDropped( QRgb ) ), 475 connect( lab, SIGNAL( colorDropped( QRgb ) ),
478 this, SIGNAL( newCol( QRgb ) ) ); 476 this, SIGNAL( newCol( QRgb ) ) );
479 connect( lab, SIGNAL( colorDropped( QRgb ) ), 477 connect( lab, SIGNAL( colorDropped( QRgb ) ),
480 this, SLOT( setRgb( QRgb ) ) ); 478 this, SLOT( setRgb( QRgb ) ) );
481 479
482 hEd = new QColNumLineEdit( this ); 480 hEd = new QColNumLineEdit( this );
483 hEd->setValidator( val360 ); 481 hEd->setValidator( val360 );
484 QLabel *l = new QLabel( hEd, OColorDialog::tr("Hue:"), this ); 482 QLabel *l = new QLabel( hEd, OColorDialog::tr("Hue:"), this );
485 l->setAlignment( AlignRight|AlignVCenter ); 483 l->setAlignment( AlignRight|AlignVCenter );
486 gl->addWidget( l, 0, 1 ); 484 gl->addWidget( l, 0, 1 );
487 gl->addWidget( hEd, 0, 2 ); 485 gl->addWidget( hEd, 0, 2 );
488 486
489 sEd = new QColNumLineEdit( this ); 487 sEd = new QColNumLineEdit( this );
490 sEd->setValidator( val256 ); 488 sEd->setValidator( val256 );
491 l = new QLabel( sEd, OColorDialog::tr("Sat:"), this ); 489 l = new QLabel( sEd, OColorDialog::tr("Sat:"), this );
492 l->setAlignment( AlignRight|AlignVCenter ); 490 l->setAlignment( AlignRight|AlignVCenter );
493 gl->addWidget( l, 1, 1 ); 491 gl->addWidget( l, 1, 1 );
494 gl->addWidget( sEd, 1, 2 ); 492 gl->addWidget( sEd, 1, 2 );
495 493
496 vEd = new QColNumLineEdit( this ); 494 vEd = new QColNumLineEdit( this );
497 vEd->setValidator( val256 ); 495 vEd->setValidator( val256 );
498 l = new QLabel( vEd, OColorDialog::tr("Val:"), this ); 496 l = new QLabel( vEd, OColorDialog::tr("Val:"), this );
499 l->setAlignment( AlignRight|AlignVCenter ); 497 l->setAlignment( AlignRight|AlignVCenter );
500 gl->addWidget( l, 2, 1 ); 498 gl->addWidget( l, 2, 1 );
501 gl->addWidget( vEd, 2, 2 ); 499 gl->addWidget( vEd, 2, 2 );
502 500
503 rEd = new QColNumLineEdit( this ); 501 rEd = new QColNumLineEdit( this );
504 rEd->setValidator( val256 ); 502 rEd->setValidator( val256 );
505 l = new QLabel( rEd, OColorDialog::tr("Red:"), this ); 503 l = new QLabel( rEd, OColorDialog::tr("Red:"), this );
506 l->setAlignment( AlignRight|AlignVCenter ); 504 l->setAlignment( AlignRight|AlignVCenter );
507 gl->addWidget( l, 0, 3 ); 505 gl->addWidget( l, 0, 3 );
508 gl->addWidget( rEd, 0, 4 ); 506 gl->addWidget( rEd, 0, 4 );
509 507
510 gEd = new QColNumLineEdit( this ); 508 gEd = new QColNumLineEdit( this );
511 gEd->setValidator( val256 ); 509 gEd->setValidator( val256 );
512 l = new QLabel( gEd, OColorDialog::tr("Green:"), this ); 510 l = new QLabel( gEd, OColorDialog::tr("Green:"), this );
513 l->setAlignment( AlignRight|AlignVCenter ); 511 l->setAlignment( AlignRight|AlignVCenter );
514 gl->addWidget( l, 1, 3 ); 512 gl->addWidget( l, 1, 3 );
515 gl->addWidget( gEd, 1, 4 ); 513 gl->addWidget( gEd, 1, 4 );
516 514
517 bEd = new QColNumLineEdit( this ); 515 bEd = new QColNumLineEdit( this );
518 bEd->setValidator( val256 ); 516 bEd->setValidator( val256 );
519 l = new QLabel( bEd, OColorDialog::tr("Blue:"), this ); 517 l = new QLabel( bEd, OColorDialog::tr("Blue:"), this );
520 l->setAlignment( AlignRight|AlignVCenter ); 518 l->setAlignment( AlignRight|AlignVCenter );
521 gl->addWidget( l, 2, 3 ); 519 gl->addWidget( l, 2, 3 );
522 gl->addWidget( bEd, 2, 4 ); 520 gl->addWidget( bEd, 2, 4 );
523 521
524 alphaEd = new QColNumLineEdit( this ); 522 alphaEd = new QColNumLineEdit( this );
525 alphaEd->setValidator( val256 ); 523 alphaEd->setValidator( val256 );
526 alphaLab = new QLabel( alphaEd, OColorDialog::tr("Alpha channel:"), this ); 524 alphaLab = new QLabel( alphaEd, OColorDialog::tr("Alpha channel:"), this );
527 alphaLab->setAlignment( AlignRight|AlignVCenter ); 525 alphaLab->setAlignment( AlignRight|AlignVCenter );
528 gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 ); 526 gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 );
529 gl->addWidget( alphaEd, 3, 4 ); 527 gl->addWidget( alphaEd, 3, 4 );
530 alphaEd->hide(); 528 alphaEd->hide();
531 alphaLab->hide(); 529 alphaLab->hide();
532 530
533 connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); 531 connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
534 connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); 532 connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
535 connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); 533 connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
536 534
537 connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); 535 connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
538 connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); 536 connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
539 connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); 537 connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
540} 538}
541 539
542void QColorShower::showCurrentColor() 540void QColorShower::showCurrentColor()
543{ 541{
544 lab->setColor( currentColor() ); 542 lab->setColor( currentColor() );
545 lab->repaint(FALSE); //### 543 lab->repaint(FALSE); //###
546} 544}
547 545
548void QColorShower::rgbEd() 546void QColorShower::rgbEd()
549{ 547{
550 rgbOriginal = TRUE; 548 rgbOriginal = TRUE;
551 curCol = qRgb( rEd->val(), gEd->val(), bEd->val() ); 549 curCol = qRgb( rEd->val(), gEd->val(), bEd->val() );
552 rgb2hsv(currentColor(), hue, sat, val ); 550 rgb2hsv(currentColor(), hue, sat, val );
553 551
554 hEd->setNum( hue ); 552 hEd->setNum( hue );
555 sEd->setNum( sat ); 553 sEd->setNum( sat );
556 vEd->setNum( val ); 554 vEd->setNum( val );
557 555
558 showCurrentColor(); 556 showCurrentColor();
559 emit newCol( currentColor() ); 557 emit newCol( currentColor() );
560} 558}
561 559
562void QColorShower::hsvEd() 560void QColorShower::hsvEd()
563{ 561{
564 rgbOriginal = FALSE; 562 rgbOriginal = FALSE;
565 hue = hEd->val(); 563 hue = hEd->val();
566 sat = sEd->val(); 564 sat = sEd->val();
567 val = vEd->val(); 565 val = vEd->val();
568 566
569 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); 567 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
570 568
571 rEd->setNum( qRed(currentColor()) ); 569 rEd->setNum( qRed(currentColor()) );
572 gEd->setNum( qGreen(currentColor()) ); 570 gEd->setNum( qGreen(currentColor()) );
573 bEd->setNum( qBlue(currentColor()) ); 571 bEd->setNum( qBlue(currentColor()) );
574 572
575 showCurrentColor(); 573 showCurrentColor();
576 emit newCol( currentColor() ); 574 emit newCol( currentColor() );
577} 575}
578 576
579void QColorShower::setRgb( QRgb rgb ) 577void QColorShower::setRgb( QRgb rgb )
580{ 578{
581 rgbOriginal = TRUE; 579 rgbOriginal = TRUE;
582 curCol = rgb; 580 curCol = rgb;
583 581
584 rgb2hsv( currentColor(), hue, sat, val ); 582 rgb2hsv( currentColor(), hue, sat, val );
585 583
586 hEd->setNum( hue ); 584 hEd->setNum( hue );
587 sEd->setNum( sat ); 585 sEd->setNum( sat );
588 vEd->setNum( val ); 586 vEd->setNum( val );
589 587
590 rEd->setNum( qRed(currentColor()) ); 588 rEd->setNum( qRed(currentColor()) );
591 gEd->setNum( qGreen(currentColor()) ); 589 gEd->setNum( qGreen(currentColor()) );
592 bEd->setNum( qBlue(currentColor()) ); 590 bEd->setNum( qBlue(currentColor()) );
593 591
594 showCurrentColor(); 592 showCurrentColor();
595} 593}
596 594
597void QColorShower::setHsv( int h, int s, int v ) 595void QColorShower::setHsv( int h, int s, int v )
598{ 596{
599 rgbOriginal = FALSE; 597 rgbOriginal = FALSE;
600 hue = h; val = v; sat = s; //Range check### 598 hue = h; val = v; sat = s; //Range check###
601 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); 599 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
602 600
603 hEd->setNum( hue ); 601 hEd->setNum( hue );
604 sEd->setNum( sat ); 602 sEd->setNum( sat );
605 vEd->setNum( val ); 603 vEd->setNum( val );
606 604
607 rEd->setNum( qRed(currentColor()) ); 605 rEd->setNum( qRed(currentColor()) );
608 gEd->setNum( qGreen(currentColor()) ); 606 gEd->setNum( qGreen(currentColor()) );
609 bEd->setNum( qBlue(currentColor()) ); 607 bEd->setNum( qBlue(currentColor()) );
610 608
611 609
612 showCurrentColor(); 610 showCurrentColor();
613} 611}
614 612
615} 613}
616 614
617class OColorDialogPrivate : public QObject 615class OColorDialogPrivate : public QObject
618{ 616{
619Q_OBJECT 617Q_OBJECT
620public: 618public:
621 OColorDialogPrivate( OColorDialog *p ); 619 OColorDialogPrivate( OColorDialog *p );
622 QRgb currentColor() const { return cs->currentColor(); } 620 QRgb currentColor() const { return cs->currentColor(); }
623 void setCurrentColor( const QRgb& rgb ); 621 void setCurrentColor( const QRgb& rgb );
624 622
625 int currentAlpha() const { return cs->currentAlpha(); } 623 int currentAlpha() const { return cs->currentAlpha(); }
626 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } 624 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
627 void showAlpha( bool b ) { cs->showAlpha( b ); } 625 void showAlpha( bool b ) { cs->showAlpha( b ); }
628 626
629private slots: 627private slots:
630 void newHsv( int h, int s, int v ); 628 void newHsv( int h, int s, int v );
631 void newColorTypedIn( QRgb rgb ); 629 void newColorTypedIn( QRgb rgb );
632private: 630private:
633 QColorPicker *cp; 631 QColorPicker *cp;
634 QColorLuminancePicker *lp; 632 QColorLuminancePicker *lp;
635 QColorShower *cs; 633 QColorShower *cs;
636}; 634};
637 635
638//sets all widgets to display h,s,v 636//sets all widgets to display h,s,v
639void OColorDialogPrivate::newHsv( int h, int s, int v ) 637void OColorDialogPrivate::newHsv( int h, int s, int v )
640{ 638{
641 cs->setHsv( h, s, v ); 639 cs->setHsv( h, s, v );
642 cp->setCol( h, s ); 640 cp->setCol( h, s );
643 lp->setCol( h, s, v ); 641 lp->setCol( h, s, v );
644} 642}
645 643
646//sets all widgets to display rgb 644//sets all widgets to display rgb
647void OColorDialogPrivate::setCurrentColor( const QRgb& rgb ) 645void OColorDialogPrivate::setCurrentColor( const QRgb& rgb )
648{ 646{
649 cs->setRgb( rgb ); 647 cs->setRgb( rgb );
650 newColorTypedIn( rgb ); 648 newColorTypedIn( rgb );
651} 649}
652 650
653//sets all widgets exept cs to display rgb 651//sets all widgets exept cs to display rgb
654void OColorDialogPrivate::newColorTypedIn( QRgb rgb ) 652void OColorDialogPrivate::newColorTypedIn( QRgb rgb )
655{ 653{
656 int h, s, v; 654 int h, s, v;
657 rgb2hsv(rgb, h, s, v ); 655 rgb2hsv(rgb, h, s, v );
658 cp->setCol( h, s ); 656 cp->setCol( h, s );
659 lp->setCol( h, s, v); 657 lp->setCol( h, s, v);
660} 658}
661 659
662OColorDialogPrivate::OColorDialogPrivate( OColorDialog *dialog ) : 660OColorDialogPrivate::OColorDialogPrivate( OColorDialog *dialog ) :
663 QObject(dialog) 661 QObject(dialog)
664{ 662{
665 int border = 2; 663 int border = 2;
666 QVBoxLayout *topLay = new QVBoxLayout( dialog, border, 2 ); 664 QVBoxLayout *topLay = new QVBoxLayout( dialog, border, 2 );
667 665
668 QHBoxLayout *pickLay = new QHBoxLayout( topLay ); 666 QHBoxLayout *pickLay = new QHBoxLayout( topLay );
669 667
670 668
671 cp = new QColorPicker( dialog ); 669 cp = new QColorPicker( dialog );
672 cp->setFrameStyle( QFrame::Panel + QFrame::Sunken ); 670 cp->setFrameStyle( QFrame::Panel + QFrame::Sunken );
673 pickLay->addWidget( cp ); 671 pickLay->addWidget( cp );
674 672
675 pickLay->addStretch(); 673 pickLay->addStretch();
676 674
677 lp = new QColorLuminancePicker( dialog ); 675 lp = new QColorLuminancePicker( dialog );
678 lp->setFixedWidth( 20 ); //### 676 lp->setFixedWidth( 20 ); //###
679 pickLay->addWidget( lp ); 677 pickLay->addWidget( lp );
680 678
681 connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) ); 679 connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) );
682 connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) ); 680 connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) );
683 681
684 topLay->addStretch(); 682 topLay->addStretch();
685 683
686 cs = new QColorShower( dialog ); 684 cs = new QColorShower( dialog );
687 connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb))); 685 connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb)));
688 topLay->addWidget( cs ); 686 topLay->addWidget( cs );
689 687
690} 688}
691 689
692 690
693// BEING REVISED: jo 691// BEING REVISED: jo
694/*! 692/*!
695 \class ColorDialog ColorDialog.h 693 \class ColorDialog ColorDialog.h
696 \brief The OColorDialog class provides a dialog widget for specifying colors. 694 \brief The OColorDialog class provides a dialog widget for specifying colors.
697 \ingroup dialogs 695 \ingroup dialogs
698 696
699 The color dialog's function is to allow users to choose colors - 697 The color dialog's function is to allow users to choose colors -
700 for instance, you might use this in a drawing program to allow the 698 for instance, you might use this in a drawing program to allow the
701 user to set the brush color. 699 user to set the brush color.
702 700
703 This version of Qt only provides modal color dialogs. The static 701 This version of Qt only provides modal color dialogs. The static
704 getColor() function shows the dialog and allows the user to specify a color, 702 getColor() function shows the dialog and allows the user to specify a color,
705 while getRgba() does the same but allows the user to specify a color with an 703 while getRgba() does the same but allows the user to specify a color with an
706 alpha channel (transparency) value. 704 alpha channel (transparency) value.
707 705
708 The user can store customCount() different custom colors. The custom 706 The user can store customCount() different custom colors. The custom
709 colors are shared by all color dialogs, and remembered during the 707 colors are shared by all color dialogs, and remembered during the
710 execution of the program. Use setCustomColor() to set the 708 execution of the program. Use setCustomColor() to set the
711 custom colors, and customColor() to get them. 709 custom colors, and customColor() to get them.
712 710
713 <img src=qcolordlg-m.png> <img src=qcolordlg-w.png> 711 <img src=qcolordlg-m.png> <img src=qcolordlg-w.png>
714*/ 712*/
715 713
716/*! 714/*!
717 Constructs a default color dialog. Use setColor() for setting an initial value. 715 Constructs a default color dialog. Use setColor() for setting an initial value.
718 716
719 \sa getColor() 717 \sa getColor()
720*/ 718*/
721 719
722OColorDialog::OColorDialog(QWidget* parent, const char* name, bool modal) : 720OColorDialog::OColorDialog(QWidget* parent, const char* name, bool modal) :
723 QDialog(parent, name, modal ) 721 QDialog(parent, name, modal )
724{ 722{
725 d = new OColorDialogPrivate( this ); 723 d = new OColorDialogPrivate( this );
726} 724}
727 725
728 726
729/*! 727/*!
730 Pops up a modal color dialog letting the user choose a color and returns 728 Pops up a modal color dialog letting the user choose a color and returns
731 that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels 729 that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels
732 the dialog. All colors allocated by the dialog will be deallocated 730 the dialog. All colors allocated by the dialog will be deallocated
733 before this function returns. 731 before this function returns.
734*/ 732*/
735 733
736QColor OColorDialog::getColor( const QColor& initial, QWidget *parent, 734QColor OColorDialog::getColor( const QColor& initial, QWidget *parent,
737 const char *name ) 735 const char *name )
738{ 736{
739 int allocContext = QColor::enterAllocContext(); 737 int allocContext = QColor::enterAllocContext();
740 OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal 738 OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal
741 if ( parent && parent->icon() && !parent->icon()->isNull() ) 739 if ( parent && parent->icon() && !parent->icon()->isNull() )
742 dlg->setIcon( *parent->icon() ); 740 dlg->setIcon( *parent->icon() );
743 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) 741 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
744 dlg->setIcon( *qApp->mainWidget()->icon() ); 742 dlg->setIcon( *qApp->mainWidget()->icon() );
745 743
746 dlg->setCaption( OColorDialog::tr( "Select color" ) ); 744 dlg->setCaption( OColorDialog::tr( "Select color" ) );
747 dlg->setColor( initial ); 745 dlg->setColor( initial );
748 dlg->showMaximized(); 746 dlg->showMaximized();
749 int resultCode = dlg->exec(); 747 int resultCode = dlg->exec();
750 QColor::leaveAllocContext(); 748 QColor::leaveAllocContext();
751 QColor result; 749 QColor result;
752 if ( resultCode == QDialog::Accepted ) { 750 if ( resultCode == QDialog::Accepted ) {
753 result = dlg->color(); 751 result = dlg->color();
754 } else { 752 } else {
755 result = initial; 753 result = initial;
756 } 754 }
757 QColor::destroyAllocContext(allocContext); 755 QColor::destroyAllocContext(allocContext);
758 delete dlg; 756 delete dlg;
759 return result; 757 return result;
760} 758}
761 759
762 760
763/*! 761/*!
764 Pops up a modal color dialog, letting the user choose a color and an 762 Pops up a modal color dialog, letting the user choose a color and an
765 alpha channel value. The color+alpha is initially set to \a initial. 763 alpha channel value. The color+alpha is initially set to \a initial.
766 764
767 If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK, 765 If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK,
768 and FALSE if the user clicked Cancel. 766 and FALSE if the user clicked Cancel.
769 767
770 If the user clicks Cancel the \a initial value is returned. 768 If the user clicks Cancel the \a initial value is returned.
771*/ 769*/
772 770
773QRgb OColorDialog::getRgba( const QRgb& initial, bool *ok, 771QRgb OColorDialog::getRgba( const QRgb& initial, bool *ok,
774 QWidget *parent, const char* name ) 772 QWidget *parent, const char* name )
775{ 773{
776 int allocContext = QColor::enterAllocContext(); 774 int allocContext = QColor::enterAllocContext();
777 OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal 775 OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal
778 dlg->setColor( initial ); 776 dlg->setColor( initial );
779 dlg->setSelectedAlpha( qAlpha(initial) ); 777 dlg->setSelectedAlpha( qAlpha(initial) );
780 dlg->showMaximized(); 778 dlg->showMaximized();
781 int resultCode = dlg->exec(); 779 int resultCode = dlg->exec();
782 QColor::leaveAllocContext(); 780 QColor::leaveAllocContext();
783 QRgb result = initial; 781 QRgb result = initial;
784 if ( resultCode == QDialog::Accepted ) { 782 if ( resultCode == QDialog::Accepted ) {
785 QRgb c = dlg->color().rgb(); 783 QRgb c = dlg->color().rgb();
786 int alpha = dlg->selectedAlpha(); 784 int alpha = dlg->selectedAlpha();
787 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); 785 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha );
788 } 786 }
789 if ( ok ) 787 if ( ok )
790 *ok = resultCode == QDialog::Accepted; 788 *ok = resultCode == QDialog::Accepted;
791 789
792 QColor::destroyAllocContext(allocContext); 790 QColor::destroyAllocContext(allocContext);
793 delete dlg; 791 delete dlg;
794 return result; 792 return result;
795} 793}
796 794
797 795
798 796
799 797
800 798
801/*! 799/*!
802 Returns the color currently selected in the dialog. 800 Returns the color currently selected in the dialog.
803 801
804 \sa setColor() 802 \sa setColor()
805*/ 803*/
806 804
807QColor OColorDialog::color() const 805QColor OColorDialog::color() const
808{ 806{
809 return QColor(d->currentColor()); 807 return QColor(d->currentColor());
810} 808}
811 809
812 810
813/*! Destructs the dialog and frees any memory it allocated. 811/*! Destructs the dialog and frees any memory it allocated.
814 812
815*/ 813*/
816 814
817OColorDialog::~OColorDialog() 815OColorDialog::~OColorDialog()
818{ 816{
819 //d inherits QObject, so it is deleted by Qt. 817 //d inherits QObject, so it is deleted by Qt.
820} 818}
821 819
822 820
823/*! 821/*!
824 Sets the color shown in the dialog to \a c. 822 Sets the color shown in the dialog to \a c.
825 823
826 \sa color() 824 \sa color()
827*/ 825*/
828 826
829void OColorDialog::setColor( const QColor& c ) 827void OColorDialog::setColor( const QColor& c )
830{ 828{
831 d->setCurrentColor( c.rgb() ); 829 d->setCurrentColor( c.rgb() );
832} 830}
833 831
834 832
835 833
836 834
837/*! 835/*!
838 Sets the initial alpha channel value to \a a, and show the alpha channel 836 Sets the initial alpha channel value to \a a, and show the alpha channel
839 entry box. 837 entry box.
840*/ 838*/
841 839
842void OColorDialog::setSelectedAlpha( int a ) 840void OColorDialog::setSelectedAlpha( int a )
843{ 841{
844 d->showAlpha( TRUE ); 842 d->showAlpha( TRUE );
845 d->setCurrentAlpha( a ); 843 d->setCurrentAlpha( a );
846} 844}
847 845
848 846
849/*! 847/*!
850 Returns the value selected for the alpha channel. 848 Returns the value selected for the alpha channel.
851*/ 849*/
852 850
853int OColorDialog::selectedAlpha() const 851int OColorDialog::selectedAlpha() const
854{ 852{
855 return d->currentAlpha(); 853 return d->currentAlpha();
856} 854}
857 855
858#include "colordialog.moc" 856#include "colordialog.moc"
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,2847 +1,2846 @@
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;
416 char *fheldaction; 415 char *fheldaction;
417} yopy_buttons [] = { 416} yopy_buttons [] = {
418 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"), 417 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"),
419 "devicebuttons/yopy_action", 418 "devicebuttons/yopy_action",
420 "datebook", "nextView()", 419 "datebook", "nextView()",
421 "today", "raise()" }, 420 "today", "raise()" },
422 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"), 421 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"),
423 "devicebuttons/yopy_ok", 422 "devicebuttons/yopy_ok",
424 "addressbook", "raise()", 423 "addressbook", "raise()",
425 "addressbook", "beamBusinessCard()" }, 424 "addressbook", "beamBusinessCard()" },
426 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"), 425 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"),
427 "devicebuttons/yopy_end", 426 "devicebuttons/yopy_end",
428 "QPE/Launcher", "home()", 427 "QPE/Launcher", "home()",
429 "buttonsettings", "raise()" }, 428 "buttonsettings", "raise()" },
430}; 429};
431 430
432static QCString makeChannel ( const char *str ) 431static QCString makeChannel ( const char *str )
433{ 432{
434 if ( str && !::strchr ( str, '/' )) 433 if ( str && !::strchr ( str, '/' ))
435 return QCString ( "QPE/Application/" ) + str; 434 return QCString ( "QPE/Application/" ) + str;
436 else 435 else
437 return str; 436 return str;
438} 437}
439 438
440static inline bool isQWS() 439static inline bool isQWS()
441{ 440{
442 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 441 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
443} 442}
444 443
445ODevice *ODevice::inst ( ) 444ODevice *ODevice::inst ( )
446{ 445{
447 static ODevice *dev = 0; 446 static ODevice *dev = 0;
448 447
449 if ( !dev ) { 448 if ( !dev ) {
450 if ( QFile::exists ( "/proc/hal/model" )) 449 if ( QFile::exists ( "/proc/hal/model" ))
451 dev = new iPAQ ( ); 450 dev = new iPAQ ( );
452 else if ( Zaurus::isZaurus() ) 451 else if ( Zaurus::isZaurus() )
453 dev = new Zaurus ( ); 452 dev = new Zaurus ( );
454 else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) 453 else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" ))
455 dev = new SIMpad ( ); 454 dev = new SIMpad ( );
456 else if ( QFile::exists ( "/proc/sys/board/name" )) 455 else if ( QFile::exists ( "/proc/sys/board/name" ))
457 dev = new Ramses ( ); 456 dev = new Ramses ( );
458 else if ( Yopy::isYopy() ) 457 else if ( Yopy::isYopy() )
459 dev = new Yopy ( ); 458 dev = new Yopy ( );
460 else if ( Jornada::isJornada() ) 459 else if ( Jornada::isJornada() )
461 dev = new Jornada ( ); 460 dev = new Jornada ( );
462 else 461 else
463 dev = new ODevice ( ); 462 dev = new ODevice ( );
464 dev-> init ( ); 463 dev-> init ( );
465 } 464 }
466 return dev; 465 return dev;
467} 466}
468 467
469 468
470/************************************************** 469/**************************************************
471 * 470 *
472 * common 471 * common
473 * 472 *
474 **************************************************/ 473 **************************************************/
475 474
476 475
477ODevice::ODevice ( ) 476ODevice::ODevice ( )
478{ 477{
479 d = new ODeviceData; 478 d = new ODeviceData;
480 479
481 d-> m_modelstr = "Unknown"; 480 d-> m_modelstr = "Unknown";
482 d-> m_model = Model_Unknown; 481 d-> m_model = Model_Unknown;
483 d-> m_vendorstr = "Unknown"; 482 d-> m_vendorstr = "Unknown";
484 d-> m_vendor = Vendor_Unknown; 483 d-> m_vendor = Vendor_Unknown;
485 d-> m_systemstr = "Unknown"; 484 d-> m_systemstr = "Unknown";
486 d-> m_system = System_Unknown; 485 d-> m_system = System_Unknown;
487 d-> m_sysverstr = "0.0"; 486 d-> m_sysverstr = "0.0";
488 d-> m_rotation = Rot0; 487 d-> m_rotation = Rot0;
489 d-> m_direction = CW; 488 d-> m_direction = CW;
490 489
491 d-> m_holdtime = 1000; // 1000ms 490 d-> m_holdtime = 1000; // 1000ms
492 d-> m_buttons = 0; 491 d-> m_buttons = 0;
493 d-> m_cpu_frequencies = new QStrList; 492 d-> m_cpu_frequencies = new QStrList;
494} 493}
495 494
496void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 495void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
497{ 496{
498 if ( msg == "deviceButtonMappingChanged()" ) { 497 if ( msg == "deviceButtonMappingChanged()" ) {
499 reloadButtonMapping ( ); 498 reloadButtonMapping ( );
500 } 499 }
501} 500}
502 501
503void ODevice::init ( ) 502void ODevice::init ( )
504{ 503{
505} 504}
506 505
507/** 506/**
508 * This method initialises the button mapping 507 * This method initialises the button mapping
509 */ 508 */
510void ODevice::initButtons ( ) 509void ODevice::initButtons ( )
511{ 510{
512 if ( d-> m_buttons ) 511 if ( d-> m_buttons )
513 return; 512 return;
514 513
515 // Simulation uses iPAQ 3660 device buttons 514 // Simulation uses iPAQ 3660 device buttons
516 515
517 qDebug ( "init Buttons" ); 516 qDebug ( "init Buttons" );
518 d-> m_buttons = new QValueList <ODeviceButton>; 517 d-> m_buttons = new QValueList <ODeviceButton>;
519 518
520 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 519 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
521 i_button *ib = ipaq_buttons + i; 520 i_button *ib = ipaq_buttons + i;
522 ODeviceButton b; 521 ODeviceButton b;
523 522
524 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 523 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
525 b. setKeycode ( ib-> code ); 524 b. setKeycode ( ib-> code );
526 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 525 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
527 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 526 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
528 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 527 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
529 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 528 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
530 d-> m_buttons-> append ( b ); 529 d-> m_buttons-> append ( b );
531 } 530 }
532 } 531 }
533 reloadButtonMapping ( ); 532 reloadButtonMapping ( );
534 533
535 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 534 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
536 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 535 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
537} 536}
538 537
539ODevice::~ODevice ( ) 538ODevice::~ODevice ( )
540{ 539{
541// we leak m_devicebuttons and m_cpu_frequency 540// we leak m_devicebuttons and m_cpu_frequency
542// but it's a singleton and it is not so importantant 541// but it's a singleton and it is not so importantant
543// -zecke 542// -zecke
544 delete d; 543 delete d;
545} 544}
546 545
547bool ODevice::setSoftSuspend ( bool /*soft*/ ) 546bool ODevice::setSoftSuspend ( bool /*soft*/ )
548{ 547{
549 return false; 548 return false;
550} 549}
551 550
552//#include <linux/apm_bios.h> 551//#include <linux/apm_bios.h>
553 552
554#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 553#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
555 554
556/** 555/**
557 * This method will try to suspend the device 556 * This method will try to suspend the device
558 * It only works if the user is the QWS Server and the apm application 557 * It only works if the user is the QWS Server and the apm application
559 * is installed. 558 * is installed.
560 * It tries to suspend and then waits some time cause some distributions 559 * It tries to suspend and then waits some time cause some distributions
561 * do have asynchronus apm implementations. 560 * do have asynchronus apm implementations.
562 * This method will either fail and return false or it'll suspend the 561 * This method will either fail and return false or it'll suspend the
563 * device and return once the device got woken up 562 * device and return once the device got woken up
564 * 563 *
565 * @return if the device got suspended 564 * @return if the device got suspended
566 */ 565 */
567bool ODevice::suspend ( ) 566bool ODevice::suspend ( )
568{ 567{
569 qDebug("ODevice::suspend"); 568 qDebug("ODevice::suspend");
570 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 569 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
571 return false; 570 return false;
572 571
573 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 572 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
574 return false; 573 return false;
575 574
576 bool res = false; 575 bool res = false;
577 576
578 struct timeval tvs, tvn; 577 struct timeval tvs, tvn;
579 ::gettimeofday ( &tvs, 0 ); 578 ::gettimeofday ( &tvs, 0 );
580 579
581 ::sync ( ); // flush fs caches 580 ::sync ( ); // flush fs caches
582 res = ( ::system ( "apm --suspend" ) == 0 ); 581 res = ( ::system ( "apm --suspend" ) == 0 );
583 582
584 // This is needed because the iPAQ apm implementation is asynchronous and we 583 // This is needed because the iPAQ apm implementation is asynchronous and we
585 // can not be sure when exactly the device is really suspended 584 // can not be sure when exactly the device is really suspended
586 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 585 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
587 586
588 if ( res ) { 587 if ( res ) {
589 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 588 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
590 ::usleep ( 200 * 1000 ); 589 ::usleep ( 200 * 1000 );
591 ::gettimeofday ( &tvn, 0 ); 590 ::gettimeofday ( &tvn, 0 );
592 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 591 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
593 } 592 }
594 593
595 return res; 594 return res;
596} 595}
597 596
598//#include <linux/fb.h> better not rely on kernel headers in userspace ... 597//#include <linux/fb.h> better not rely on kernel headers in userspace ...
599 598
600#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 599#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
601 600
602/* VESA Blanking Levels */ 601/* VESA Blanking Levels */
603#define VESA_NO_BLANKING 0 602#define VESA_NO_BLANKING 0
604#define VESA_VSYNC_SUSPEND 1 603#define VESA_VSYNC_SUSPEND 1
605#define VESA_HSYNC_SUSPEND 2 604#define VESA_HSYNC_SUSPEND 2
606#define VESA_POWERDOWN 3 605#define VESA_POWERDOWN 3
607 606
608/** 607/**
609 * This sets the display on or off 608 * This sets the display on or off
610 */ 609 */
611bool ODevice::setDisplayStatus ( bool on ) 610bool ODevice::setDisplayStatus ( bool on )
612{ 611{
613 qDebug("ODevice::setDisplayStatus(%d)", on); 612 qDebug("ODevice::setDisplayStatus(%d)", on);
614 613
615 if ( d-> m_model == Model_Unknown ) 614 if ( d-> m_model == Model_Unknown )
616 return false; 615 return false;
617 616
618 bool res = false; 617 bool res = false;
619 int fd; 618 int fd;
620 619
621 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 620 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
622 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 621 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
623 ::close ( fd ); 622 ::close ( fd );
624 } 623 }
625 return res; 624 return res;
626} 625}
627 626
628/** 627/**
629 * This sets the display brightness 628 * This sets the display brightness
630 * 629 *
631 * @param p The brightness to be set on a scale from 0 to 255 630 * @param p The brightness to be set on a scale from 0 to 255
632 * @return success or failure 631 * @return success or failure
633 */ 632 */
634bool ODevice::setDisplayBrightness ( int p) 633bool ODevice::setDisplayBrightness ( int p)
635{ 634{
636 Q_UNUSED( p ) 635 Q_UNUSED( p )
637 return false; 636 return false;
638} 637}
639 638
640/** 639/**
641 * @return returns the number of steppings on the brightness slider 640 * @return returns the number of steppings on the brightness slider
642 * in the Light-'n-Power settings. 641 * in the Light-'n-Power settings.
643 */ 642 */
644int ODevice::displayBrightnessResolution ( ) const 643int ODevice::displayBrightnessResolution ( ) const
645{ 644{
646 return 16; 645 return 16;
647} 646}
648 647
649/** 648/**
650 * This sets the display contrast 649 * This sets the display contrast
651 * @param p The contrast to be set on a scale from 0 to 255 650 * @param p The contrast to be set on a scale from 0 to 255
652 * @return success or failure 651 * @return success or failure
653 */ 652 */
654bool ODevice::setDisplayContrast ( int p) 653bool ODevice::setDisplayContrast ( int p)
655{ 654{
656 Q_UNUSED( p ) 655 Q_UNUSED( p )
657 return false; 656 return false;
658} 657}
659 658
660/** 659/**
661 * @return return the max value for the brightness settings slider 660 * @return return the max value for the brightness settings slider
662 * or 0 if the device doesn't support setting of a contrast 661 * or 0 if the device doesn't support setting of a contrast
663 */ 662 */
664int ODevice::displayContrastResolution ( ) const 663int ODevice::displayContrastResolution ( ) const
665{ 664{
666 return 0; 665 return 0;
667} 666}
668 667
669/** 668/**
670 * This returns the vendor as string 669 * This returns the vendor as string
671 * @return Vendor as QString 670 * @return Vendor as QString
672 */ 671 */
673QString ODevice::vendorString ( ) const 672QString ODevice::vendorString ( ) const
674{ 673{
675 return d-> m_vendorstr; 674 return d-> m_vendorstr;
676} 675}
677 676
678/** 677/**
679 * This returns the vendor as one of the values of OVendor 678 * This returns the vendor as one of the values of OVendor
680 * @return OVendor 679 * @return OVendor
681 */ 680 */
682OVendor ODevice::vendor ( ) const 681OVendor ODevice::vendor ( ) const
683{ 682{
684 return d-> m_vendor; 683 return d-> m_vendor;
685} 684}
686 685
687/** 686/**
688 * This returns the model as a string 687 * This returns the model as a string
689 * @return A string representing the model 688 * @return A string representing the model
690 */ 689 */
691QString ODevice::modelString ( ) const 690QString ODevice::modelString ( ) const
692{ 691{
693 return d-> m_modelstr; 692 return d-> m_modelstr;
694} 693}
695 694
696/** 695/**
697 * This does return the OModel used 696 * This does return the OModel used
698 */ 697 */
699OModel ODevice::model ( ) const 698OModel ODevice::model ( ) const
700{ 699{
701 return d-> m_model; 700 return d-> m_model;
702} 701}
703 702
704/** 703/**
705 * This does return the systen name 704 * This does return the systen name
706 */ 705 */
707QString ODevice::systemString ( ) const 706QString ODevice::systemString ( ) const
708{ 707{
709 return d-> m_systemstr; 708 return d-> m_systemstr;
710} 709}
711 710
712/** 711/**
713 * Return System as OSystem value 712 * Return System as OSystem value
714 */ 713 */
715OSystem ODevice::system ( ) const 714OSystem ODevice::system ( ) const
716{ 715{
717 return d-> m_system; 716 return d-> m_system;
718} 717}
719 718
720/** 719/**
721 * @return the version string of the base system 720 * @return the version string of the base system
722 */ 721 */
723QString ODevice::systemVersionString ( ) const 722QString ODevice::systemVersionString ( ) const
724{ 723{
725 return d-> m_sysverstr; 724 return d-> m_sysverstr;
726} 725}
727 726
728/** 727/**
729 * @return the current Transformation 728 * @return the current Transformation
730 */ 729 */
731Transformation ODevice::rotation ( ) const 730Transformation ODevice::rotation ( ) const
732{ 731{
733 VirtRotation rot; 732 VirtRotation rot;
734 ODevice* that =(ODevice* )this; 733 ODevice* that =(ODevice* )this;
735 that->virtual_hook( VIRTUAL_ROTATION, &rot ); 734 that->virtual_hook( VIRTUAL_ROTATION, &rot );
736 return rot.trans; 735 return rot.trans;
737} 736}
738 737
739/** 738/**
740 * @return the current rotation direction 739 * @return the current rotation direction
741 */ 740 */
742ODirection ODevice::direction ( ) const 741ODirection ODevice::direction ( ) const
743{ 742{
744 VirtDirection dir; 743 VirtDirection dir;
745 ODevice* that =(ODevice* )this; 744 ODevice* that =(ODevice* )this;
746 that->virtual_hook( VIRTUAL_DIRECTION, &dir ); 745 that->virtual_hook( VIRTUAL_DIRECTION, &dir );
747 return dir.direct; 746 return dir.direct;
748} 747}
749 748
750/** 749/**
751 * This plays an alarmSound 750 * This plays an alarmSound
752 */ 751 */
753void ODevice::alarmSound ( ) 752void ODevice::alarmSound ( )
754{ 753{
755#ifndef QT_NO_SOUND 754#ifndef QT_NO_SOUND
756 static Sound snd ( "alarm" ); 755 static Sound snd ( "alarm" );
757 756
758 if ( snd. isFinished ( )) 757 if ( snd. isFinished ( ))
759 snd. play ( ); 758 snd. play ( );
760#endif 759#endif
761} 760}
762 761
763/** 762/**
764 * This plays a key sound 763 * This plays a key sound
765 */ 764 */
766void ODevice::keySound ( ) 765void ODevice::keySound ( )
767{ 766{
768#ifndef QT_NO_SOUND 767#ifndef QT_NO_SOUND
769 static Sound snd ( "keysound" ); 768 static Sound snd ( "keysound" );
770 769
771 if ( snd. isFinished ( )) 770 if ( snd. isFinished ( ))
772 snd. play ( ); 771 snd. play ( );
773#endif 772#endif
774} 773}
775 774
776/** 775/**
777 * This plays a touch sound 776 * This plays a touch sound
778 */ 777 */
779void ODevice::touchSound ( ) 778void ODevice::touchSound ( )
780{ 779{
781#ifndef QT_NO_SOUND 780#ifndef QT_NO_SOUND
782 static Sound snd ( "touchsound" ); 781 static Sound snd ( "touchsound" );
783 782
784 if ( snd. isFinished ( )) 783 if ( snd. isFinished ( ))
785 snd. play ( ); 784 snd. play ( );
786#endif 785#endif
787} 786}
788 787
789/** 788/**
790 * This method will return a list of leds 789 * This method will return a list of leds
791 * available on this device 790 * available on this device
792 * @return a list of LEDs. 791 * @return a list of LEDs.
793 */ 792 */
794QValueList <OLed> ODevice::ledList ( ) const 793QValueList <OLed> ODevice::ledList ( ) const
795{ 794{
796 return QValueList <OLed> ( ); 795 return QValueList <OLed> ( );
797} 796}
798 797
799/** 798/**
800 * This does return the state of the LEDs 799 * This does return the state of the LEDs
801 */ 800 */
802QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 801QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
803{ 802{
804 return QValueList <OLedState> ( ); 803 return QValueList <OLedState> ( );
805} 804}
806 805
807/** 806/**
808 * @return the state for a given OLed 807 * @return the state for a given OLed
809 */ 808 */
810OLedState ODevice::ledState ( OLed /*which*/ ) const 809OLedState ODevice::ledState ( OLed /*which*/ ) const
811{ 810{
812 return Led_Off; 811 return Led_Off;
813} 812}
814 813
815/** 814/**
816 * Set the state for a LED 815 * Set the state for a LED
817 * @param which Which OLed to use 816 * @param which Which OLed to use
818 * @param st The state to set 817 * @param st The state to set
819 * @return success or failure 818 * @return success or failure
820 */ 819 */
821bool ODevice::setLedState ( OLed which, OLedState st ) 820bool ODevice::setLedState ( OLed which, OLedState st )
822{ 821{
823 Q_UNUSED( which ) 822 Q_UNUSED( which )
824 Q_UNUSED( st ) 823 Q_UNUSED( st )
825 return false; 824 return false;
826} 825}
827 826
828/** 827/**
829 * @return if the device has a light sensor 828 * @return if the device has a light sensor
830 */ 829 */
831bool ODevice::hasLightSensor ( ) const 830bool ODevice::hasLightSensor ( ) const
832{ 831{
833 return false; 832 return false;
834} 833}
835 834
836/** 835/**
837 * @return a value from the light sensor 836 * @return a value from the light sensor
838 */ 837 */
839int ODevice::readLightSensor ( ) 838int ODevice::readLightSensor ( )
840{ 839{
841 return -1; 840 return -1;
842} 841}
843 842
844/** 843/**
845 * @return the light sensor resolution 844 * @return the light sensor resolution
846 */ 845 */
847int ODevice::lightSensorResolution ( ) const 846int ODevice::lightSensorResolution ( ) const
848{ 847{
849 return 0; 848 return 0;
850} 849}
851 850
852/** 851/**
853 * @return if the device has a hinge sensor 852 * @return if the device has a hinge sensor
854 */ 853 */
855bool ODevice::hasHingeSensor ( ) const 854bool ODevice::hasHingeSensor ( ) const
856{ 855{
857 VirtHasHinge hing; 856 VirtHasHinge hing;
858 ODevice* that =(ODevice* )this; 857 ODevice* that =(ODevice* )this;
859 that->virtual_hook( VIRTUAL_HAS_HINGE, &hing ); 858 that->virtual_hook( VIRTUAL_HAS_HINGE, &hing );
860 return hing.hasHinge; 859 return hing.hasHinge;
861} 860}
862 861
863/** 862/**
864 * @return a value from the hinge sensor 863 * @return a value from the hinge sensor
865 */ 864 */
866OHingeStatus ODevice::readHingeSensor ( ) 865OHingeStatus ODevice::readHingeSensor ( )
867{ 866{
868 VirtHingeStatus hing; 867 VirtHingeStatus hing;
869 virtual_hook( VIRTUAL_HINGE, &hing ); 868 virtual_hook( VIRTUAL_HINGE, &hing );
870 return hing.hingeStat; 869 return hing.hingeStat;
871} 870}
872 871
873/** 872/**
874 * @return a list with CPU frequencies supported by the hardware 873 * @return a list with CPU frequencies supported by the hardware
875 */ 874 */
876const QStrList &ODevice::allowedCpuFrequencies ( ) const 875const QStrList &ODevice::allowedCpuFrequencies ( ) const
877{ 876{
878 return *d->m_cpu_frequencies; 877 return *d->m_cpu_frequencies;
879} 878}
880 879
881 880
882/** 881/**
883 * Set desired CPU frequency 882 * Set desired CPU frequency
884 * 883 *
885 * @param index index into d->m_cpu_frequencies of the frequency to be set 884 * @param index index into d->m_cpu_frequencies of the frequency to be set
886 */ 885 */
887bool ODevice::setCurrentCpuFrequency(uint index) 886bool ODevice::setCurrentCpuFrequency(uint index)
888{ 887{
889 if (index >= d->m_cpu_frequencies->count()) 888 if (index >= d->m_cpu_frequencies->count())
890 return false; 889 return false;
891 890
892 char *freq = d->m_cpu_frequencies->at(index); 891 char *freq = d->m_cpu_frequencies->at(index);
893 qWarning("set freq to %s", freq); 892 qWarning("set freq to %s", freq);
894 893
895 int fd; 894 int fd;
896 895
897 if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { 896 if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) {
898 char writeCommand[50]; 897 char writeCommand[50];
899 const int count = sprintf(writeCommand, "%s\n", freq); 898 const int count = sprintf(writeCommand, "%s\n", freq);
900 int res = (::write(fd, writeCommand, count) != -1); 899 int res = (::write(fd, writeCommand, count) != -1);
901 ::close(fd); 900 ::close(fd);
902 return res; 901 return res;
903 } 902 }
904 903
905 return false; 904 return false;
906} 905}
907 906
908 907
909/** 908/**
910 * @return a list of hardware buttons 909 * @return a list of hardware buttons
911 */ 910 */
912const QValueList <ODeviceButton> &ODevice::buttons ( ) 911const QValueList <ODeviceButton> &ODevice::buttons ( )
913{ 912{
914 initButtons ( ); 913 initButtons ( );
915 914
916 return *d-> m_buttons; 915 return *d-> m_buttons;
917} 916}
918 917
919/** 918/**
920 * @return The amount of time that would count as a hold 919 * @return The amount of time that would count as a hold
921 */ 920 */
922uint ODevice::buttonHoldTime ( ) const 921uint ODevice::buttonHoldTime ( ) const
923{ 922{
924 return d-> m_holdtime; 923 return d-> m_holdtime;
925} 924}
926 925
927/** 926/**
928 * This method return a ODeviceButton for a key code 927 * This method return a ODeviceButton for a key code
929 * or 0 if no special hardware button is available for the device 928 * or 0 if no special hardware button is available for the device
930 * 929 *
931 * @return The devicebutton or 0l 930 * @return The devicebutton or 0l
932 * @see ODeviceButton 931 * @see ODeviceButton
933 */ 932 */
934const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) 933const ODeviceButton *ODevice::buttonForKeycode ( ushort code )
935{ 934{
936 initButtons ( ); 935 initButtons ( );
937 936
938 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { 937 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) {
939 if ( (*it). keycode ( ) == code ) 938 if ( (*it). keycode ( ) == code )
940 return &(*it); 939 return &(*it);
941 } 940 }
942 return 0; 941 return 0;
943} 942}
944 943
945void ODevice::reloadButtonMapping ( ) 944void ODevice::reloadButtonMapping ( )
946{ 945{
947 initButtons ( ); 946 initButtons ( );
948 947
949 Config cfg ( "ButtonSettings" ); 948 Config cfg ( "ButtonSettings" );
950 949
951 for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { 950 for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) {
952 ODeviceButton &b = ( *d-> m_buttons ) [i]; 951 ODeviceButton &b = ( *d-> m_buttons ) [i];
953 QString group = "Button" + QString::number ( i ); 952 QString group = "Button" + QString::number ( i );
954 953
955 QCString pch, hch; 954 QCString pch, hch;
956 QCString pm, hm; 955 QCString pm, hm;
957 QByteArray pdata, hdata; 956 QByteArray pdata, hdata;
958 957
959 if ( cfg. hasGroup ( group )) { 958 if ( cfg. hasGroup ( group )) {
960 cfg. setGroup ( group ); 959 cfg. setGroup ( group );
961 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); 960 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( );
962 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); 961 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( );
963 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); 962 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" ));
964 963
965 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); 964 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( );
966 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); 965 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( );
967 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); 966 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" ));
968 } 967 }
969 968
970 b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); 969 b. setPressedAction ( OQCopMessage ( pch, pm, pdata ));
971 970
972 b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); 971 b. setHeldAction ( OQCopMessage ( hch, hm, hdata ));
973 } 972 }
974} 973}
975 974
976void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) 975void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
977{ 976{
978 initButtons ( ); 977 initButtons ( );
979 978
980 QString mb_chan; 979 QString mb_chan;
981 980
982 if ( button >= (int) d-> m_buttons-> count ( )) 981 if ( button >= (int) d-> m_buttons-> count ( ))
983 return; 982 return;
984 983
985 ODeviceButton &b = ( *d-> m_buttons ) [button]; 984 ODeviceButton &b = ( *d-> m_buttons ) [button];
986 b. setPressedAction ( action ); 985 b. setPressedAction ( action );
987 986
988 mb_chan=b. pressedAction ( ). channel ( ); 987 mb_chan=b. pressedAction ( ). channel ( );
989 988
990 Config buttonFile ( "ButtonSettings" ); 989 Config buttonFile ( "ButtonSettings" );
991 buttonFile. setGroup ( "Button" + QString::number ( button )); 990 buttonFile. setGroup ( "Button" + QString::number ( button ));
992 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); 991 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan);
993 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); 992 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( ));
994 993
995 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); 994 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( )));
996 995
997 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 996 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
998} 997}
999 998
1000void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 999void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
1001{ 1000{
1002 initButtons ( ); 1001 initButtons ( );
1003 1002
1004 if ( button >= (int) d-> m_buttons-> count ( )) 1003 if ( button >= (int) d-> m_buttons-> count ( ))
1005 return; 1004 return;
1006 1005
1007 ODeviceButton &b = ( *d-> m_buttons ) [button]; 1006 ODeviceButton &b = ( *d-> m_buttons ) [button];
1008 b. setHeldAction ( action ); 1007 b. setHeldAction ( action );
1009 1008
1010 Config buttonFile ( "ButtonSettings" ); 1009 Config buttonFile ( "ButtonSettings" );
1011 buttonFile. setGroup ( "Button" + QString::number ( button )); 1010 buttonFile. setGroup ( "Button" + QString::number ( button ));
1012 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); 1011 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( ));
1013 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); 1012 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( ));
1014 1013
1015 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); 1014 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( )));
1016 1015
1017 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 1016 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
1018} 1017}
1019void ODevice::virtual_hook(int id, void* data){ 1018void ODevice::virtual_hook(int id, void* data){
1020 switch( id ) { 1019 switch( id ) {
1021 case VIRTUAL_ROTATION:{ 1020 case VIRTUAL_ROTATION:{
1022 VirtRotation* rot = reinterpret_cast<VirtRotation*>( data ); 1021 VirtRotation* rot = reinterpret_cast<VirtRotation*>( data );
1023 rot->trans = d->m_rotation; 1022 rot->trans = d->m_rotation;
1024 break; 1023 break;
1025 } 1024 }
1026 case VIRTUAL_DIRECTION:{ 1025 case VIRTUAL_DIRECTION:{
1027 VirtDirection *dir = reinterpret_cast<VirtDirection*>( data ); 1026 VirtDirection *dir = reinterpret_cast<VirtDirection*>( data );
1028 dir->direct = d->m_direction; 1027 dir->direct = d->m_direction;
1029 break; 1028 break;
1030 } 1029 }
1031 case VIRTUAL_HAS_HINGE:{ 1030 case VIRTUAL_HAS_HINGE:{
1032 VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data ); 1031 VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data );
1033 hin->hasHinge = false; 1032 hin->hasHinge = false;
1034 break; 1033 break;
1035 } 1034 }
1036 case VIRTUAL_HINGE:{ 1035 case VIRTUAL_HINGE:{
1037 VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data ); 1036 VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data );
1038 hin->hingeStat = CASE_UNKNOWN; 1037 hin->hingeStat = CASE_UNKNOWN;
1039 break; 1038 break;
1040 } 1039 }
1041 } 1040 }
1042} 1041}
1043 1042
1044/************************************************** 1043/**************************************************
1045 * 1044 *
1046 * Yopy 3500/3700 1045 * Yopy 3500/3700
1047 * 1046 *
1048 **************************************************/ 1047 **************************************************/
1049 1048
1050bool Yopy::isYopy ( ) 1049bool Yopy::isYopy ( )
1051{ 1050{
1052 QFile f( "/proc/cpuinfo" ); 1051 QFile f( "/proc/cpuinfo" );
1053 if ( f. open ( IO_ReadOnly ) ) { 1052 if ( f. open ( IO_ReadOnly ) ) {
1054 QTextStream ts ( &f ); 1053 QTextStream ts ( &f );
1055 QString line; 1054 QString line;
1056 while( line = ts. readLine ( ) ) { 1055 while( line = ts. readLine ( ) ) {
1057 if ( line. left ( 8 ) == "Hardware" ) { 1056 if ( line. left ( 8 ) == "Hardware" ) {
1058 int loc = line. find ( ":" ); 1057 int loc = line. find ( ":" );
1059 if ( loc != -1 ) { 1058 if ( loc != -1 ) {
1060 QString model = 1059 QString model =
1061 line. mid ( loc + 2 ). simplifyWhiteSpace( ); 1060 line. mid ( loc + 2 ). simplifyWhiteSpace( );
1062 return ( model == "Yopy" ); 1061 return ( model == "Yopy" );
1063 } 1062 }
1064 } 1063 }
1065 } 1064 }
1066 } 1065 }
1067 return false; 1066 return false;
1068} 1067}
1069 1068
1070void Yopy::init ( ) 1069void Yopy::init ( )
1071{ 1070{
1072 d-> m_vendorstr = "G.Mate"; 1071 d-> m_vendorstr = "G.Mate";
1073 d-> m_vendor = Vendor_GMate; 1072 d-> m_vendor = Vendor_GMate;
1074 d-> m_modelstr = "Yopy3700"; 1073 d-> m_modelstr = "Yopy3700";
1075 d-> m_model = Model_Yopy_3700; 1074 d-> m_model = Model_Yopy_3700;
1076 d-> m_rotation = Rot0; 1075 d-> m_rotation = Rot0;
1077 1076
1078 d-> m_systemstr = "Linupy"; 1077 d-> m_systemstr = "Linupy";
1079 d-> m_system = System_Linupy; 1078 d-> m_system = System_Linupy;
1080 1079
1081 QFile f ( "/etc/issue" ); 1080 QFile f ( "/etc/issue" );
1082 if ( f. open ( IO_ReadOnly )) { 1081 if ( f. open ( IO_ReadOnly )) {
1083 QTextStream ts ( &f ); 1082 QTextStream ts ( &f );
1084 ts.readLine(); 1083 ts.readLine();
1085 d-> m_sysverstr = ts. readLine ( ); 1084 d-> m_sysverstr = ts. readLine ( );
1086 f. close ( ); 1085 f. close ( );
1087 } 1086 }
1088} 1087}
1089 1088
1090void Yopy::initButtons ( ) 1089void Yopy::initButtons ( )
1091{ 1090{
1092 if ( d-> m_buttons ) 1091 if ( d-> m_buttons )
1093 return; 1092 return;
1094 1093
1095 d-> m_buttons = new QValueList <ODeviceButton>; 1094 d-> m_buttons = new QValueList <ODeviceButton>;
1096 1095
1097 for (uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof(yopy_button)); i++) { 1096 for (uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof(yopy_button)); i++) {
1098 1097
1099 yopy_button *ib = yopy_buttons + i; 1098 yopy_button *ib = yopy_buttons + i;
1100 1099
1101 ODeviceButton b; 1100 ODeviceButton b;
1102 1101
1103 b. setKeycode ( ib-> code ); 1102 b. setKeycode ( ib-> code );
1104 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 1103 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
1105 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 1104 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
1106 b. setFactoryPresetPressedAction 1105 b. setFactoryPresetPressedAction
1107 (OQCopMessage(makeChannel(ib->fpressedservice), ib->fpressedaction)); 1106 (OQCopMessage(makeChannel(ib->fpressedservice), ib->fpressedaction));
1108 b. setFactoryPresetHeldAction 1107 b. setFactoryPresetHeldAction
1109 (OQCopMessage(makeChannel(ib->fheldservice), ib->fheldaction)); 1108 (OQCopMessage(makeChannel(ib->fheldservice), ib->fheldaction));
1110 1109
1111 d-> m_buttons-> append ( b ); 1110 d-> m_buttons-> append ( b );
1112 } 1111 }
1113 reloadButtonMapping ( ); 1112 reloadButtonMapping ( );
1114 1113
1115 QCopChannel *sysch = new QCopChannel("QPE/System", this); 1114 QCopChannel *sysch = new QCopChannel("QPE/System", this);
1116 connect(sysch, SIGNAL(received(const QCString &, const QByteArray & )), 1115 connect(sysch, SIGNAL(received(const QCString &, const QByteArray & )),
1117 this, SLOT(systemMessage(const QCString &, const QByteArray & ))); 1116 this, SLOT(systemMessage(const QCString &, const QByteArray & )));
1118} 1117}
1119 1118
1120bool Yopy::suspend() 1119bool Yopy::suspend()
1121{ 1120{
1122 /* Opie for Yopy does not implement its own power management at the 1121 /* Opie for Yopy does not implement its own power management at the
1123 moment. The public version runs parallel to X, and relies on the 1122 moment. The public version runs parallel to X, and relies on the
1124 existing power management features. */ 1123 existing power management features. */
1125 return false; 1124 return false;
1126} 1125}
1127 1126
1128bool Yopy::setDisplayBrightness(int bright) 1127bool Yopy::setDisplayBrightness(int bright)
1129{ 1128{
1130 /* The code here works, but is disabled as the current version runs 1129 /* The code here works, but is disabled as the current version runs
1131 parallel to X, and relies on the existing backlight demon. */ 1130 parallel to X, and relies on the existing backlight demon. */
1132#if 0 1131#if 0
1133 if ( QFile::exists("/proc/sys/pm/light") ) { 1132 if ( QFile::exists("/proc/sys/pm/light") ) {
1134 int fd = ::open("/proc/sys/pm/light", O_WRONLY); 1133 int fd = ::open("/proc/sys/pm/light", O_WRONLY);
1135 if (fd >= 0 ) { 1134 if (fd >= 0 ) {
1136 if (bright) 1135 if (bright)
1137 ::write(fd, "1\n", 2); 1136 ::write(fd, "1\n", 2);
1138 else 1137 else
1139 ::write(fd, "0\n", 2); 1138 ::write(fd, "0\n", 2);
1140 ::close(fd); 1139 ::close(fd);
1141 return true; 1140 return true;
1142 } 1141 }
1143 } 1142 }
1144#endif 1143#endif
1145 return false; 1144 return false;
1146} 1145}
1147 1146
1148int Yopy::displayBrightnessResolution() const 1147int Yopy::displayBrightnessResolution() const
1149{ 1148{
1150 return 2; 1149 return 2;
1151} 1150}
1152 1151
1153/************************************************** 1152/**************************************************
1154 * 1153 *
1155 * iPAQ 1154 * iPAQ
1156 * 1155 *
1157 **************************************************/ 1156 **************************************************/
1158 1157
1159void iPAQ::init ( ) 1158void iPAQ::init ( )
1160{ 1159{
1161 d-> m_vendorstr = "HP"; 1160 d-> m_vendorstr = "HP";
1162 d-> m_vendor = Vendor_HP; 1161 d-> m_vendor = Vendor_HP;
1163 1162
1164 QFile f ( "/proc/hal/model" ); 1163 QFile f ( "/proc/hal/model" );
1165 1164
1166 if ( f. open ( IO_ReadOnly )) { 1165 if ( f. open ( IO_ReadOnly )) {
1167 QTextStream ts ( &f ); 1166 QTextStream ts ( &f );
1168 1167
1169 d-> m_modelstr = "H" + ts. readLine ( ); 1168 d-> m_modelstr = "H" + ts. readLine ( );
1170 1169
1171 if ( d-> m_modelstr == "H3100" ) 1170 if ( d-> m_modelstr == "H3100" )
1172 d-> m_model = Model_iPAQ_H31xx; 1171 d-> m_model = Model_iPAQ_H31xx;
1173 else if ( d-> m_modelstr == "H3600" ) 1172 else if ( d-> m_modelstr == "H3600" )
1174 d-> m_model = Model_iPAQ_H36xx; 1173 d-> m_model = Model_iPAQ_H36xx;
1175 else if ( d-> m_modelstr == "H3700" ) 1174 else if ( d-> m_modelstr == "H3700" )
1176 d-> m_model = Model_iPAQ_H37xx; 1175 d-> m_model = Model_iPAQ_H37xx;
1177 else if ( d-> m_modelstr == "H3800" ) 1176 else if ( d-> m_modelstr == "H3800" )
1178 d-> m_model = Model_iPAQ_H38xx; 1177 d-> m_model = Model_iPAQ_H38xx;
1179 else if ( d-> m_modelstr == "H3900" ) 1178 else if ( d-> m_modelstr == "H3900" )
1180 d-> m_model = Model_iPAQ_H39xx; 1179 d-> m_model = Model_iPAQ_H39xx;
1181 else if ( d-> m_modelstr == "H5400" ) 1180 else if ( d-> m_modelstr == "H5400" )
1182 d-> m_model = Model_iPAQ_H5xxx; 1181 d-> m_model = Model_iPAQ_H5xxx;
1183 else 1182 else
1184 d-> m_model = Model_Unknown; 1183 d-> m_model = Model_Unknown;
1185 1184
1186 f. close ( ); 1185 f. close ( );
1187 } 1186 }
1188 1187
1189 switch ( d-> m_model ) { 1188 switch ( d-> m_model ) {
1190 case Model_iPAQ_H31xx: 1189 case Model_iPAQ_H31xx:
1191 case Model_iPAQ_H38xx: 1190 case Model_iPAQ_H38xx:
1192 d-> m_rotation = Rot90; 1191 d-> m_rotation = Rot90;
1193 break; 1192 break;
1194 case Model_iPAQ_H36xx: 1193 case Model_iPAQ_H36xx:
1195 case Model_iPAQ_H37xx: 1194 case Model_iPAQ_H37xx:
1196 case Model_iPAQ_H39xx: 1195 case Model_iPAQ_H39xx:
1197 1196
1198 default: 1197 default:
1199 d-> m_rotation = Rot270; 1198 d-> m_rotation = Rot270;
1200 break; 1199 break;
1201 case Model_iPAQ_H5xxx: 1200 case Model_iPAQ_H5xxx:
1202 d-> m_rotation = Rot0; 1201 d-> m_rotation = Rot0;
1203 } 1202 }
1204 1203
1205 f. setName ( "/etc/familiar-version" ); 1204 f. setName ( "/etc/familiar-version" );
1206 if ( f. open ( IO_ReadOnly )) { 1205 if ( f. open ( IO_ReadOnly )) {
1207 d-> m_systemstr = "Familiar"; 1206 d-> m_systemstr = "Familiar";
1208 d-> m_system = System_Familiar; 1207 d-> m_system = System_Familiar;
1209 1208
1210 QTextStream ts ( &f ); 1209 QTextStream ts ( &f );
1211 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 1210 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
1212 1211
1213 f. close ( ); 1212 f. close ( );
1214 } else { 1213 } else {
1215 f. setName ( "/etc/oz_version" ); 1214 f. setName ( "/etc/oz_version" );
1216 1215
1217 if ( f. open ( IO_ReadOnly )) { 1216 if ( f. open ( IO_ReadOnly )) {
1218 d-> m_systemstr = "OpenEmbedded/iPaq"; 1217 d-> m_systemstr = "OpenEmbedded/iPaq";
1219 d-> m_system = System_Familiar; 1218 d-> m_system = System_Familiar;
1220 1219
1221 QTextStream ts ( &f ); 1220 QTextStream ts ( &f );
1222 ts.setDevice ( &f ); 1221 ts.setDevice ( &f );
1223 d-> m_sysverstr = ts. readLine ( ); 1222 d-> m_sysverstr = ts. readLine ( );
1224 f. close ( ); 1223 f. close ( );
1225 } 1224 }
1226 } 1225 }
1227 1226
1228 1227
1229 1228
1230 1229
1231 1230
1232 m_leds [0] = m_leds [1] = Led_Off; 1231 m_leds [0] = m_leds [1] = Led_Off;
1233 1232
1234 m_power_timer = 0; 1233 m_power_timer = 0;
1235 1234
1236} 1235}
1237 1236
1238void iPAQ::initButtons ( ) 1237void iPAQ::initButtons ( )
1239{ 1238{
1240 if ( d-> m_buttons ) 1239 if ( d-> m_buttons )
1241 return; 1240 return;
1242 1241
1243 if ( isQWS( ) ) 1242 if ( isQWS( ) )
1244 QWSServer::setKeyboardFilter ( this ); 1243 QWSServer::setKeyboardFilter ( this );
1245 1244
1246 d-> m_buttons = new QValueList <ODeviceButton>; 1245 d-> m_buttons = new QValueList <ODeviceButton>;
1247 1246
1248 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 1247 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
1249 i_button *ib = ipaq_buttons + i; 1248 i_button *ib = ipaq_buttons + i;
1250 ODeviceButton b; 1249 ODeviceButton b;
1251 1250
1252 if (( ib-> model & d-> m_model ) == d-> m_model ) { 1251 if (( ib-> model & d-> m_model ) == d-> m_model ) {
1253 b. setKeycode ( ib-> code ); 1252 b. setKeycode ( ib-> code );
1254 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 1253 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
1255 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 1254 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
1256 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 1255 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
1257 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 1256 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
1258 1257
1259 d-> m_buttons-> append ( b ); 1258 d-> m_buttons-> append ( b );
1260 } 1259 }
1261 } 1260 }
1262 reloadButtonMapping ( ); 1261 reloadButtonMapping ( );
1263 1262
1264 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 1263 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
1265 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 1264 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
1266} 1265}
1267 1266
1268 1267
1269//#include <linux/h3600_ts.h> // including kernel headers is evil ... 1268//#include <linux/h3600_ts.h> // including kernel headers is evil ...
1270 1269
1271typedef struct { 1270typedef struct {
1272 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 1271 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
1273 unsigned char TotalTime; /* Units of 5 seconds */ 1272 unsigned char TotalTime; /* Units of 5 seconds */
1274 unsigned char OnTime; /* units of 100m/s */ 1273 unsigned char OnTime; /* units of 100m/s */
1275 unsigned char OffTime; /* units of 100m/s */ 1274 unsigned char OffTime; /* units of 100m/s */
1276} LED_IN; 1275} LED_IN;
1277 1276
1278typedef struct { 1277typedef struct {
1279 unsigned char mode; 1278 unsigned char mode;
1280 unsigned char pwr; 1279 unsigned char pwr;
1281 unsigned char brightness; 1280 unsigned char brightness;
1282} FLITE_IN; 1281} FLITE_IN;
1283 1282
1284#define LED_ON OD_IOW( 'f', 5, LED_IN ) 1283#define LED_ON OD_IOW( 'f', 5, LED_IN )
1285#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 1284#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
1286 1285
1287 1286
1288QValueList <OLed> iPAQ::ledList ( ) const 1287QValueList <OLed> iPAQ::ledList ( ) const
1289{ 1288{
1290 QValueList <OLed> vl; 1289 QValueList <OLed> vl;
1291 vl << Led_Power; 1290 vl << Led_Power;
1292 1291
1293 if ( d-> m_model == Model_iPAQ_H38xx ) 1292 if ( d-> m_model == Model_iPAQ_H38xx )
1294 vl << Led_BlueTooth; 1293 vl << Led_BlueTooth;
1295 return vl; 1294 return vl;
1296} 1295}
1297 1296
1298QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const 1297QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const
1299{ 1298{
1300 QValueList <OLedState> vl; 1299 QValueList <OLedState> vl;
1301 1300
1302 if ( l == Led_Power ) 1301 if ( l == Led_Power )
1303 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; 1302 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast;
1304 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) 1303 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx )
1305 vl << Led_Off; // << Led_On << ??? 1304 vl << Led_Off; // << Led_On << ???
1306 1305
1307 return vl; 1306 return vl;
1308} 1307}
1309 1308
1310OLedState iPAQ::ledState ( OLed l ) const 1309OLedState iPAQ::ledState ( OLed l ) const
1311{ 1310{
1312 switch ( l ) { 1311 switch ( l ) {
1313 case Led_Power: 1312 case Led_Power:
1314 return m_leds [0]; 1313 return m_leds [0];
1315 case Led_BlueTooth: 1314 case Led_BlueTooth:
1316 return m_leds [1]; 1315 return m_leds [1];
1317 default: 1316 default:
1318 return Led_Off; 1317 return Led_Off;
1319 } 1318 }
1320} 1319}
1321 1320
1322bool iPAQ::setLedState ( OLed l, OLedState st ) 1321bool iPAQ::setLedState ( OLed l, OLedState st )
1323{ 1322{
1324 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); 1323 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK );
1325 1324
1326 if ( l == Led_Power ) { 1325 if ( l == Led_Power ) {
1327 if ( fd >= 0 ) { 1326 if ( fd >= 0 ) {
1328 LED_IN leds; 1327 LED_IN leds;
1329 ::memset ( &leds, 0, sizeof( leds )); 1328 ::memset ( &leds, 0, sizeof( leds ));
1330 leds. TotalTime = 0; 1329 leds. TotalTime = 0;
1331 leds. OnTime = 0; 1330 leds. OnTime = 0;
1332 leds. OffTime = 1; 1331 leds. OffTime = 1;
1333 leds. OffOnBlink = 2; 1332 leds. OffOnBlink = 2;
1334 1333
1335 switch ( st ) { 1334 switch ( st ) {
1336 case Led_Off : leds. OffOnBlink = 0; break; 1335 case Led_Off : leds. OffOnBlink = 0; break;
1337 case Led_On : leds. OffOnBlink = 1; break; 1336 case Led_On : leds. OffOnBlink = 1; break;
1338 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 1337 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
1339 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 1338 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
1340 } 1339 }
1341 1340
1342 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 1341 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
1343 m_leds [0] = st; 1342 m_leds [0] = st;
1344 return true; 1343 return true;
1345 } 1344 }
1346 } 1345 }
1347 } 1346 }
1348 return false; 1347 return false;
1349} 1348}
1350 1349
1351 1350
1352bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 1351bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
1353{ 1352{
1354 int newkeycode = keycode; 1353 int newkeycode = keycode;
1355 1354
1356 switch ( keycode ) { 1355 switch ( keycode ) {
1357 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key 1356 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key
1358 case HardKey_Menu: { 1357 case HardKey_Menu: {
1359 if (( d-> m_model == Model_iPAQ_H38xx ) || 1358 if (( d-> m_model == Model_iPAQ_H38xx ) ||
1360 ( d-> m_model == Model_iPAQ_H39xx ) || 1359 ( d-> m_model == Model_iPAQ_H39xx ) ||
1361 ( d-> m_model == Model_iPAQ_H5xxx)) { 1360 ( d-> m_model == Model_iPAQ_H5xxx)) {
1362 newkeycode = HardKey_Mail; 1361 newkeycode = HardKey_Mail;
1363 } 1362 }
1364 break; 1363 break;
1365 } 1364 }
1366 1365
1367 // Rotate cursor keys 180° or 270° 1366 // Rotate cursor keys 180° or 270°
1368 case Key_Left : 1367 case Key_Left :
1369 case Key_Right: 1368 case Key_Right:
1370 case Key_Up : 1369 case Key_Up :
1371 case Key_Down : { 1370 case Key_Down : {
1372 1371
1373 if (( d-> m_model == Model_iPAQ_H31xx ) || 1372 if (( d-> m_model == Model_iPAQ_H31xx ) ||
1374 ( d-> m_model == Model_iPAQ_H38xx )) { 1373 ( d-> m_model == Model_iPAQ_H38xx )) {
1375 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; 1374 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4;
1376 } 1375 }
1377 // Rotate the cursor keys by 270° 1376 // Rotate the cursor keys by 270°
1378 // keycode - Key_Left = position of the button starting from left clockwise 1377 // keycode - Key_Left = position of the button starting from left clockwise
1379 // add the rotation to it and modolo. No we've the original offset 1378 // add the rotation to it and modolo. No we've the original offset
1380 // add the offset to the Key_Left key 1379 // add the offset to the Key_Left key
1381 if ( d-> m_model == Model_iPAQ_H5xxx ) 1380 if ( d-> m_model == Model_iPAQ_H5xxx )
1382 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; 1381 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4;
1383 break; 1382 break;
1384 } 1383 }
1385 1384
1386 // map Power Button short/long press to F34/F35 1385 // map Power Button short/long press to F34/F35
1387 case Key_SysReq: { 1386 case Key_SysReq: {
1388 if ( isPress ) { 1387 if ( isPress ) {
1389 if ( m_power_timer ) 1388 if ( m_power_timer )
1390 killTimer ( m_power_timer ); 1389 killTimer ( m_power_timer );
1391 m_power_timer = startTimer ( 500 ); 1390 m_power_timer = startTimer ( 500 );
1392 } 1391 }
1393 else if ( m_power_timer ) { 1392 else if ( m_power_timer ) {
1394 killTimer ( m_power_timer ); 1393 killTimer ( m_power_timer );
1395 m_power_timer = 0; 1394 m_power_timer = 0;
1396 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 1395 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
1397 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 1396 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
1398 } 1397 }
1399 newkeycode = Key_unknown; 1398 newkeycode = Key_unknown;
1400 break; 1399 break;
1401 } 1400 }
1402 } 1401 }
1403 1402
1404 if ( newkeycode != keycode ) { 1403 if ( newkeycode != keycode ) {
1405 if ( newkeycode != Key_unknown ) 1404 if ( newkeycode != Key_unknown )
1406 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 1405 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
1407 return true; 1406 return true;
1408 } 1407 }
1409 else 1408 else
1410 return false; 1409 return false;
1411} 1410}
1412 1411
1413void iPAQ::timerEvent ( QTimerEvent * ) 1412void iPAQ::timerEvent ( QTimerEvent * )
1414{ 1413{
1415 killTimer ( m_power_timer ); 1414 killTimer ( m_power_timer );
1416 m_power_timer = 0; 1415 m_power_timer = 0;
1417 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 1416 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
1418 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 1417 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
1419} 1418}
1420 1419
1421 1420
1422void iPAQ::alarmSound ( ) 1421void iPAQ::alarmSound ( )
1423{ 1422{
1424#ifndef QT_NO_SOUND 1423#ifndef QT_NO_SOUND
1425 static Sound snd ( "alarm" ); 1424 static Sound snd ( "alarm" );
1426 int fd; 1425 int fd;
1427 int vol; 1426 int vol;
1428 bool vol_reset = false; 1427 bool vol_reset = false;
1429 1428
1430 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 1429 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
1431 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 1430 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
1432 Config cfg ( "qpe" ); 1431 Config cfg ( "qpe" );
1433 cfg. setGroup ( "Volume" ); 1432 cfg. setGroup ( "Volume" );
1434 1433
1435 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 1434 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
1436 if ( volalarm < 0 ) 1435 if ( volalarm < 0 )
1437 volalarm = 0; 1436 volalarm = 0;
1438 else if ( volalarm > 100 ) 1437 else if ( volalarm > 100 )
1439 volalarm = 100; 1438 volalarm = 100;
1440 volalarm |= ( volalarm << 8 ); 1439 volalarm |= ( volalarm << 8 );
1441 1440
1442 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 1441 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
1443 vol_reset = true; 1442 vol_reset = true;
1444 } 1443 }
1445 } 1444 }
1446 1445
1447 snd. play ( ); 1446 snd. play ( );
1448 while ( !snd. isFinished ( )) 1447 while ( !snd. isFinished ( ))
1449 qApp-> processEvents ( ); 1448 qApp-> processEvents ( );
1450 1449
1451 if ( fd >= 0 ) { 1450 if ( fd >= 0 ) {
1452 if ( vol_reset ) 1451 if ( vol_reset )
1453 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 1452 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
1454 ::close ( fd ); 1453 ::close ( fd );
1455 } 1454 }
1456#endif 1455#endif
1457} 1456}
1458 1457
1459 1458
1460bool iPAQ::setSoftSuspend ( bool soft ) 1459bool iPAQ::setSoftSuspend ( bool soft )
1461{ 1460{
1462 bool res = false; 1461 bool res = false;
1463 int fd; 1462 int fd;
1464 1463
1465 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 1464 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
1466 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) 1465 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 )
1467 res = true; 1466 res = true;
1468 else 1467 else
1469 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 1468 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
1470 1469
1471 ::close ( fd ); 1470 ::close ( fd );
1472 } 1471 }
1473 else 1472 else
1474 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 1473 ::perror ( "/proc/sys/ts/suspend_button_mode" );
1475 1474
1476 return res; 1475 return res;
1477} 1476}
1478 1477
1479 1478
1480bool iPAQ::setDisplayBrightness ( int bright ) 1479bool iPAQ::setDisplayBrightness ( int bright )
1481{ 1480{
1482 bool res = false; 1481 bool res = false;
1483 int fd; 1482 int fd;
1484 1483
1485 if ( bright > 255 ) 1484 if ( bright > 255 )
1486 bright = 255; 1485 bright = 255;
1487 if ( bright < 0 ) 1486 if ( bright < 0 )
1488 bright = 0; 1487 bright = 0;
1489 1488
1490 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 1489 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
1491 FLITE_IN bl; 1490 FLITE_IN bl;
1492 bl. mode = 1; 1491 bl. mode = 1;
1493 bl. pwr = bright ? 1 : 0; 1492 bl. pwr = bright ? 1 : 0;
1494 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; 1493 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255;
1495 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 1494 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
1496 ::close ( fd ); 1495 ::close ( fd );
1497 } 1496 }
1498 return res; 1497 return res;
1499} 1498}
1500 1499
1501int iPAQ::displayBrightnessResolution ( ) const 1500int iPAQ::displayBrightnessResolution ( ) const
1502{ 1501{
1503 switch ( model ( )) { 1502 switch ( model ( )) {
1504 case Model_iPAQ_H31xx: 1503 case Model_iPAQ_H31xx:
1505 case Model_iPAQ_H36xx: 1504 case Model_iPAQ_H36xx:
1506 case Model_iPAQ_H37xx: 1505 case Model_iPAQ_H37xx:
1507 return 128; // really 256, but >128 could damage the LCD 1506 return 128; // really 256, but >128 could damage the LCD
1508 1507
1509 case Model_iPAQ_H38xx: 1508 case Model_iPAQ_H38xx:
1510 case Model_iPAQ_H39xx: 1509 case Model_iPAQ_H39xx:
1511 return 64; 1510 return 64;
1512 case Model_iPAQ_H5xxx: 1511 case Model_iPAQ_H5xxx:
1513 return 255; 1512 return 255;
1514 1513
1515 default: 1514 default:
1516 return 2; 1515 return 2;
1517 } 1516 }
1518} 1517}
1519 1518
1520 1519
1521bool iPAQ::hasLightSensor ( ) const 1520bool iPAQ::hasLightSensor ( ) const
1522{ 1521{
1523 return true; 1522 return true;
1524} 1523}
1525 1524
1526int iPAQ::readLightSensor ( ) 1525int iPAQ::readLightSensor ( )
1527{ 1526{
1528 int fd; 1527 int fd;
1529 int val = -1; 1528 int val = -1;
1530 1529
1531 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 1530 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
1532 char buffer [8]; 1531 char buffer [8];
1533 1532
1534 if ( ::read ( fd, buffer, 5 ) == 5 ) { 1533 if ( ::read ( fd, buffer, 5 ) == 5 ) {
1535 char *endptr; 1534 char *endptr;
1536 1535
1537 buffer [4] = 0; 1536 buffer [4] = 0;
1538 val = ::strtol ( buffer + 2, &endptr, 16 ); 1537 val = ::strtol ( buffer + 2, &endptr, 16 );
1539 1538
1540 if ( *endptr != 0 ) 1539 if ( *endptr != 0 )
1541 val = -1; 1540 val = -1;
1542 } 1541 }
1543 ::close ( fd ); 1542 ::close ( fd );
1544 } 1543 }
1545 1544
1546 return val; 1545 return val;
1547} 1546}
1548 1547
1549int iPAQ::lightSensorResolution ( ) const 1548int iPAQ::lightSensorResolution ( ) const
1550{ 1549{
1551 return 256; 1550 return 256;
1552} 1551}
1553 1552
1554/************************************************** 1553/**************************************************
1555 * 1554 *
1556 * Zaurus 1555 * Zaurus
1557 * 1556 *
1558 **************************************************/ 1557 **************************************************/
1559 1558
1560// Check whether this device is the sharp zaurus.. 1559// Check whether this device is the sharp zaurus..
1561// FIXME This gets unnecessary complicated. We should think about splitting the Zaurus 1560// FIXME This gets unnecessary complicated. We should think about splitting the Zaurus
1562// class up into individual classes. We need three classes 1561// class up into individual classes. We need three classes
1563// 1562//
1564// Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000) 1563// Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000)
1565// Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600) 1564// Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600)
1566// Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, and C860) 1565// Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, and C860)
1567// 1566//
1568// Only question right now is: Do we really need to do it? Because as soon 1567// Only question right now is: Do we really need to do it? Because as soon
1569// as the OpenZaurus kernel is ready, there will be a unified interface for all 1568// as the OpenZaurus kernel is ready, there will be a unified interface for all
1570// Zaurus models (concerning apm, backlight, buttons, etc.) 1569// Zaurus models (concerning apm, backlight, buttons, etc.)
1571// 1570//
1572// Comments? - mickeyl. 1571// Comments? - mickeyl.
1573 1572
1574bool Zaurus::isZaurus() 1573bool Zaurus::isZaurus()
1575{ 1574{
1576 1575
1577 // If the special devices by embedix exist, it is quite simple: it is a Zaurus ! 1576 // If the special devices by embedix exist, it is quite simple: it is a Zaurus !
1578 if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ) ){ 1577 if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ) ){
1579 return true; 1578 return true;
1580 } 1579 }
1581 1580
1582 // On non-embedix kernels, we have to look closer. 1581 // On non-embedix kernels, we have to look closer.
1583 bool is_zaurus = false; 1582 bool is_zaurus = false;
1584 QFile f ( "/proc/cpuinfo" ); 1583 QFile f ( "/proc/cpuinfo" );
1585 if ( f. open ( IO_ReadOnly ) ) { 1584 if ( f. open ( IO_ReadOnly ) ) {
1586 QString model; 1585 QString model;
1587 QFile f ( "/proc/cpuinfo" ); 1586 QFile f ( "/proc/cpuinfo" );
1588 1587
1589 QTextStream ts ( &f ); 1588 QTextStream ts ( &f );
1590 QString line; 1589 QString line;
1591 while( line = ts. readLine ( ) ) { 1590 while( line = ts. readLine ( ) ) {
1592 if ( line. left ( 8 ) == "Hardware" ) 1591 if ( line. left ( 8 ) == "Hardware" )
1593 break; 1592 break;
1594 } 1593 }
1595 int loc = line. find ( ":" ); 1594 int loc = line. find ( ":" );
1596 if ( loc != -1 ) 1595 if ( loc != -1 )
1597 model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); 1596 model = line. mid ( loc + 2 ). simplifyWhiteSpace( );
1598 1597
1599 if ( model == "Sharp-Collie" 1598 if ( model == "Sharp-Collie"
1600 || model == "Collie" 1599 || model == "Collie"
1601 || model == "SHARP Corgi" 1600 || model == "SHARP Corgi"
1602 || model == "SHARP Shepherd" 1601 || model == "SHARP Shepherd"
1603 || model == "SHARP Poodle" 1602 || model == "SHARP Poodle"
1604 || model == "SHARP Husky" 1603 || model == "SHARP Husky"
1605 ) 1604 )
1606 is_zaurus = true; 1605 is_zaurus = true;
1607 1606
1608 } 1607 }
1609 return is_zaurus; 1608 return is_zaurus;
1610} 1609}
1611 1610
1612 1611
1613void Zaurus::init ( ) 1612void Zaurus::init ( )
1614{ 1613{
1615 d-> m_vendorstr = "Sharp"; 1614 d-> m_vendorstr = "Sharp";
1616 d-> m_vendor = Vendor_Sharp; 1615 d-> m_vendor = Vendor_Sharp;
1617 m_embedix = true; // Not openzaurus means: It has an embedix kernel ! 1616 m_embedix = true; // Not openzaurus means: It has an embedix kernel !
1618 1617
1619 // QFile f ( "/proc/filesystems" ); 1618 // QFile f ( "/proc/filesystems" );
1620 QString model; 1619 QString model;
1621 1620
1622 // It isn't a good idea to check the system configuration to 1621 // It isn't a good idea to check the system configuration to
1623 // detect the distribution ! 1622 // detect the distribution !
1624 // Otherwise it may happen that any other distribution is detected as openzaurus, just 1623 // Otherwise it may happen that any other distribution is detected as openzaurus, just
1625 // because it uses a jffs2 filesystem.. 1624 // because it uses a jffs2 filesystem..
1626 // (eilers) 1625 // (eilers)
1627 // if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 1626 // if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
1628 QFile f ("/etc/oz_version"); 1627 QFile f ("/etc/oz_version");
1629 if ( f.exists() ){ 1628 if ( f.exists() ){
1630 d-> m_vendorstr = "OpenZaurus Team"; 1629 d-> m_vendorstr = "OpenZaurus Team";
1631 d-> m_systemstr = "OpenZaurus"; 1630 d-> m_systemstr = "OpenZaurus";
1632 d-> m_system = System_OpenZaurus; 1631 d-> m_system = System_OpenZaurus;
1633 1632
1634 if ( f. open ( IO_ReadOnly )) { 1633 if ( f. open ( IO_ReadOnly )) {
1635 QTextStream ts ( &f ); 1634 QTextStream ts ( &f );
1636 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 ); 1635 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 );
1637 f. close ( ); 1636 f. close ( );
1638 } 1637 }
1639 1638
1640 // Openzaurus sometimes uses the embedix kernel! 1639 // Openzaurus sometimes uses the embedix kernel!
1641 // => Check whether this is an embedix kernel 1640 // => Check whether this is an embedix kernel
1642 FILE *uname = popen("uname -r", "r"); 1641 FILE *uname = popen("uname -r", "r");
1643 QString line; 1642 QString line;
1644 if ( f.open(IO_ReadOnly, uname) ) { 1643 if ( f.open(IO_ReadOnly, uname) ) {
1645 QTextStream ts ( &f ); 1644 QTextStream ts ( &f );
1646 line = ts. readLine ( ); 1645 line = ts. readLine ( );
1647 int loc = line. find ( "embedix" ); 1646 int loc = line. find ( "embedix" );
1648 if ( loc != -1 ) 1647 if ( loc != -1 )
1649 m_embedix = true; 1648 m_embedix = true;
1650 else 1649 else
1651 m_embedix = false; 1650 m_embedix = false;
1652 f. close ( ); 1651 f. close ( );
1653 } 1652 }
1654 pclose(uname); 1653 pclose(uname);
1655 } 1654 }
1656 else { 1655 else {
1657 d-> m_systemstr = "Zaurus"; 1656 d-> m_systemstr = "Zaurus";
1658 d-> m_system = System_Zaurus; 1657 d-> m_system = System_Zaurus;
1659 } 1658 }
1660 1659
1661 f. setName ( "/proc/cpuinfo" ); 1660 f. setName ( "/proc/cpuinfo" );
1662 if ( f. open ( IO_ReadOnly ) ) { 1661 if ( f. open ( IO_ReadOnly ) ) {
1663 QTextStream ts ( &f ); 1662 QTextStream ts ( &f );
1664 QString line; 1663 QString line;
1665 while( line = ts. readLine ( ) ) { 1664 while( line = ts. readLine ( ) ) {
1666 if ( line. left ( 8 ) == "Hardware" ) 1665 if ( line. left ( 8 ) == "Hardware" )
1667 break; 1666 break;
1668 } 1667 }
1669 int loc = line. find ( ":" ); 1668 int loc = line. find ( ":" );
1670 if ( loc != -1 ) 1669 if ( loc != -1 )
1671 model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); 1670 model = line. mid ( loc + 2 ). simplifyWhiteSpace( );
1672 } 1671 }
1673 1672
1674 if ( model == "SHARP Corgi" ) { 1673 if ( model == "SHARP Corgi" ) {
1675 d-> m_model = Model_Zaurus_SLC7x0; 1674 d-> m_model = Model_Zaurus_SLC7x0;
1676 d-> m_modelstr = "Zaurus SL-C700"; 1675 d-> m_modelstr = "Zaurus SL-C700";
1677 } else if ( model == "SHARP Shepherd" ) { 1676 } else if ( model == "SHARP Shepherd" ) {
1678 d-> m_model = Model_Zaurus_SLC7x0; 1677 d-> m_model = Model_Zaurus_SLC7x0;
1679 d-> m_modelstr = "Zaurus SL-C750"; 1678 d-> m_modelstr = "Zaurus SL-C750";
1680 } else if ( model == "SHARP Husky" ) { 1679 } else if ( model == "SHARP Husky" ) {
1681 d-> m_model = Model_Zaurus_SLC7x0; 1680 d-> m_model = Model_Zaurus_SLC7x0;
1682 d-> m_modelstr = "Zaurus SL-C760"; 1681 d-> m_modelstr = "Zaurus SL-C760";
1683 } else if ( model == "SHARP Poodle" ) { 1682 } else if ( model == "SHARP Poodle" ) {
1684 d-> m_model = Model_Zaurus_SLB600; 1683 d-> m_model = Model_Zaurus_SLB600;
1685 d-> m_modelstr = "Zaurus SL-B500 or SL-5600"; 1684 d-> m_modelstr = "Zaurus SL-B500 or SL-5600";
1686 } else if ( model == "Sharp-Collie" || model == "Collie" ) { 1685 } else if ( model == "Sharp-Collie" || model == "Collie" ) {
1687 d-> m_model = Model_Zaurus_SL5500; 1686 d-> m_model = Model_Zaurus_SL5500;
1688 d-> m_modelstr = "Zaurus SL-5500 or SL-5000d"; 1687 d-> m_modelstr = "Zaurus SL-5500 or SL-5000d";
1689 } else { 1688 } else {
1690 d-> m_model = Model_Zaurus_SL5500; 1689 d-> m_model = Model_Zaurus_SL5500;
1691 d-> m_modelstr = "Zaurus (Model unknown)"; 1690 d-> m_modelstr = "Zaurus (Model unknown)";
1692 } 1691 }
1693 1692
1694 bool flipstate = false; 1693 bool flipstate = false;
1695 switch ( d-> m_model ) { 1694 switch ( d-> m_model ) {
1696 case Model_Zaurus_SLA300: 1695 case Model_Zaurus_SLA300:
1697 d-> m_rotation = Rot0; 1696 d-> m_rotation = Rot0;
1698 break; 1697 break;
1699 case Model_Zaurus_SLC7x0: 1698 case Model_Zaurus_SLC7x0:
1700 d-> m_rotation = rotation(); 1699 d-> m_rotation = rotation();
1701 d-> m_direction = direction(); 1700 d-> m_direction = direction();
1702 break; 1701 break;
1703 case Model_Zaurus_SLB600: 1702 case Model_Zaurus_SLB600:
1704 case Model_Zaurus_SL5500: 1703 case Model_Zaurus_SL5500:
1705 case Model_Zaurus_SL5000: 1704 case Model_Zaurus_SL5000:
1706 default: 1705 default:
1707 d-> m_rotation = Rot270; 1706 d-> m_rotation = Rot270;
1708 break; 1707 break;
1709 } 1708 }
1710 m_leds [0] = Led_Off; 1709 m_leds [0] = Led_Off;
1711} 1710}
1712 1711
1713void Zaurus::initButtons ( ) 1712void Zaurus::initButtons ( )
1714{ 1713{
1715 if ( d-> m_buttons ) 1714 if ( d-> m_buttons )
1716 return; 1715 return;
1717 1716
1718 d-> m_buttons = new QValueList <ODeviceButton>; 1717 d-> m_buttons = new QValueList <ODeviceButton>;
1719 1718
1720 struct z_button * pz_buttons; 1719 struct z_button * pz_buttons;
1721 int buttoncount; 1720 int buttoncount;
1722 switch ( d-> m_model ) { 1721 switch ( d-> m_model ) {
1723 case Model_Zaurus_SLC7x0: 1722 case Model_Zaurus_SLC7x0:
1724 pz_buttons = z_buttons_c700; 1723 pz_buttons = z_buttons_c700;
1725 buttoncount = ARRAY_SIZE(z_buttons_c700); 1724 buttoncount = ARRAY_SIZE(z_buttons_c700);
1726 break; 1725 break;
1727 default: 1726 default:
1728 pz_buttons = z_buttons; 1727 pz_buttons = z_buttons;
1729 buttoncount = ARRAY_SIZE(z_buttons); 1728 buttoncount = ARRAY_SIZE(z_buttons);
1730 break; 1729 break;
1731 } 1730 }
1732 1731
1733 for ( int i = 0; i < buttoncount; i++ ) { 1732 for ( int i = 0; i < buttoncount; i++ ) {
1734 struct z_button *zb = pz_buttons + i; 1733 struct z_button *zb = pz_buttons + i;
1735 ODeviceButton b; 1734 ODeviceButton b;
1736 1735
1737 b. setKeycode ( zb-> code ); 1736 b. setKeycode ( zb-> code );
1738 b. setUserText ( QObject::tr ( "Button", zb-> utext )); 1737 b. setUserText ( QObject::tr ( "Button", zb-> utext ));
1739 b. setPixmap ( Resource::loadPixmap ( zb-> pix )); 1738 b. setPixmap ( Resource::loadPixmap ( zb-> pix ));
1740 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), 1739 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ),
1741 zb-> fpressedaction )); 1740 zb-> fpressedaction ));
1742 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), 1741 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ),
1743 zb-> fheldaction )); 1742 zb-> fheldaction ));
1744 1743
1745 d-> m_buttons-> append ( b ); 1744 d-> m_buttons-> append ( b );
1746 } 1745 }
1747 1746
1748 reloadButtonMapping ( ); 1747 reloadButtonMapping ( );
1749 1748
1750 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 1749 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
1751 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), 1750 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )),
1752 this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 1751 this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
1753} 1752}
1754 1753
1755#include <unistd.h> 1754#include <unistd.h>
1756#include <fcntl.h> 1755#include <fcntl.h>
1757#include <sys/ioctl.h> 1756#include <sys/ioctl.h>
1758 1757
1759//#include <asm/sharp_char.h> // including kernel headers is evil ... 1758//#include <asm/sharp_char.h> // including kernel headers is evil ...
1760 1759
1761#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 1760#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
1762 1761
1763 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1762 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1764#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 1763#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
1765 1764
1766#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 1765#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
1767#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 1766#define SHARP_BUZ_KEYSOUND 2 /* key sound */
1768#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 1767#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
1769 1768
1770/* --- for SHARP_BUZZER device --- */ 1769/* --- for SHARP_BUZZER device --- */
1771 1770
1772 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1771 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1773//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 1772//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
1774 1773
1775#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 1774#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
1776#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 1775#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
1777#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 1776#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
1778#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 1777#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
1779#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 1778#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
1780 1779
1781//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 1780//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
1782//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 1781//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
1783 1782
1784//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 1783//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
1785//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 1784//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
1786//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 1785//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
1787//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 1786//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
1788//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 1787//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
1789//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 1788//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
1790//#define SHARP_PDA_APPSTART 9 /* application start */ 1789//#define SHARP_PDA_APPSTART 9 /* application start */
1791//#define SHARP_PDA_APPQUIT 10 /* application ends */ 1790//#define SHARP_PDA_APPQUIT 10 /* application ends */
1792 1791
1793//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 1792//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
1794//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 1793//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
1795//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 1794//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
1796//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 1795//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
1797// 1796//
1798 1797
1799 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1798 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1800#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 1799#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
1801 1800
1802#define SHARP_IOCTL_GET_ROTATION 0x413c 1801#define SHARP_IOCTL_GET_ROTATION 0x413c
1803 1802
1804typedef struct sharp_led_status { 1803typedef struct sharp_led_status {
1805 int which; /* select which LED status is wanted. */ 1804 int which; /* select which LED status is wanted. */
1806 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 1805 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
1807} sharp_led_status; 1806} sharp_led_status;
1808 1807
1809#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 1808#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
1810 1809
1811#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 1810#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
1812#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 1811#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
1813#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 1812#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
1814 1813
1815// #include <asm/sharp_apm.h> // including kernel headers is evil ... 1814// #include <asm/sharp_apm.h> // including kernel headers is evil ...
1816 1815
1817#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) 1816#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
1818#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) 1817#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
1819#define APM_EVT_POWER_BUTTON (1 << 0) 1818#define APM_EVT_POWER_BUTTON (1 << 0)
1820 1819
1821#define FL_IOCTL_STEP_CONTRAST 100 1820#define FL_IOCTL_STEP_CONTRAST 100
1822 1821
1823 1822
1824void Zaurus::buzzer ( int sound ) 1823void Zaurus::buzzer ( int sound )
1825{ 1824{
1826#ifndef QT_NO_SOUND 1825#ifndef QT_NO_SOUND
1827 QString soundname; 1826 QString soundname;
1828 1827
1829 // Not all devices have real sound 1828 // Not all devices have real sound
1830 if ( d->m_model == Model_Zaurus_SLC7x0 1829 if ( d->m_model == Model_Zaurus_SLC7x0
1831 || d->m_model == Model_Zaurus_SLB600 ){ 1830 || d->m_model == Model_Zaurus_SLB600 ){
1832 1831
1833 switch ( sound ){ 1832 switch ( sound ){
1834 case SHARP_BUZ_SCHEDULE_ALARM: 1833 case SHARP_BUZ_SCHEDULE_ALARM:
1835 soundname = "alarm"; 1834 soundname = "alarm";
1836 break; 1835 break;
1837 case SHARP_BUZ_TOUCHSOUND: 1836 case SHARP_BUZ_TOUCHSOUND:
1838 soundname = "touchsound"; 1837 soundname = "touchsound";
1839 break; 1838 break;
1840 case SHARP_BUZ_KEYSOUND: 1839 case SHARP_BUZ_KEYSOUND:
1841 soundname = "keysound"; 1840 soundname = "keysound";
1842 break; 1841 break;
1843 default: 1842 default:
1844 soundname = "alarm"; 1843 soundname = "alarm";
1845 1844
1846 } 1845 }
1847 } 1846 }
1848 1847
1849 // If a soundname is defined, we expect that this device has 1848 // If a soundname is defined, we expect that this device has
1850 // sound capabilities.. Otherwise we expect to have the buzzer 1849 // sound capabilities.. Otherwise we expect to have the buzzer
1851 // device.. 1850 // device..
1852 if ( !soundname.isEmpty() ){ 1851 if ( !soundname.isEmpty() ){
1853 int fd; 1852 int fd;
1854 int vol; 1853 int vol;
1855 bool vol_reset = false; 1854 bool vol_reset = false;
1856 1855
1857 Sound snd ( soundname ); 1856 Sound snd ( soundname );
1858 1857
1859 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 1858 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
1860 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 1859 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
1861 Config cfg ( "qpe" ); 1860 Config cfg ( "qpe" );
1862 cfg. setGroup ( "Volume" ); 1861 cfg. setGroup ( "Volume" );
1863 1862
1864 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 1863 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
1865 if ( volalarm < 0 ) 1864 if ( volalarm < 0 )
1866 volalarm = 0; 1865 volalarm = 0;
1867 else if ( volalarm > 100 ) 1866 else if ( volalarm > 100 )
1868 volalarm = 100; 1867 volalarm = 100;
1869 volalarm |= ( volalarm << 8 ); 1868 volalarm |= ( volalarm << 8 );
1870 1869
1871 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 1870 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
1872 vol_reset = true; 1871 vol_reset = true;
1873 } 1872 }
1874 } 1873 }
1875 1874
1876 snd. play ( ); 1875 snd. play ( );
1877 while ( !snd. isFinished ( )) 1876 while ( !snd. isFinished ( ))
1878 qApp-> processEvents ( ); 1877 qApp-> processEvents ( );
1879 1878
1880 if ( fd >= 0 ) { 1879 if ( fd >= 0 ) {
1881 if ( vol_reset ) 1880 if ( vol_reset )
1882 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 1881 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
1883 ::close ( fd ); 1882 ::close ( fd );
1884 } 1883 }
1885 } else { 1884 } else {
1886 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); 1885 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK );
1887 1886
1888 if ( fd >= 0 ) { 1887 if ( fd >= 0 ) {
1889 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 1888 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
1890 ::close ( fd ); 1889 ::close ( fd );
1891 } 1890 }
1892 1891
1893 } 1892 }
1894#endif 1893#endif
1895} 1894}
1896 1895
1897 1896
1898void Zaurus::alarmSound ( ) 1897void Zaurus::alarmSound ( )
1899{ 1898{
1900 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 1899 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
1901} 1900}
1902 1901
1903void Zaurus::touchSound ( ) 1902void Zaurus::touchSound ( )
1904{ 1903{
1905 buzzer ( SHARP_BUZ_TOUCHSOUND ); 1904 buzzer ( SHARP_BUZ_TOUCHSOUND );
1906} 1905}
1907 1906
1908void Zaurus::keySound ( ) 1907void Zaurus::keySound ( )
1909{ 1908{
1910 buzzer ( SHARP_BUZ_KEYSOUND ); 1909 buzzer ( SHARP_BUZ_KEYSOUND );
1911} 1910}
1912 1911
1913 1912
1914QValueList <OLed> Zaurus::ledList ( ) const 1913QValueList <OLed> Zaurus::ledList ( ) const
1915{ 1914{
1916 QValueList <OLed> vl; 1915 QValueList <OLed> vl;
1917 vl << Led_Mail; 1916 vl << Led_Mail;
1918 return vl; 1917 return vl;
1919} 1918}
1920 1919
1921QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const 1920QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const
1922{ 1921{
1923 QValueList <OLedState> vl; 1922 QValueList <OLedState> vl;
1924 1923
1925 if ( l == Led_Mail ) 1924 if ( l == Led_Mail )
1926 vl << Led_Off << Led_On << Led_BlinkSlow; 1925 vl << Led_Off << Led_On << Led_BlinkSlow;
1927 return vl; 1926 return vl;
1928} 1927}
1929 1928
1930OLedState Zaurus::ledState ( OLed which ) const 1929OLedState Zaurus::ledState ( OLed which ) const
1931{ 1930{
1932 if ( which == Led_Mail ) 1931 if ( which == Led_Mail )
1933 return m_leds [0]; 1932 return m_leds [0];
1934 else 1933 else
1935 return Led_Off; 1934 return Led_Off;
1936} 1935}
1937 1936
1938bool Zaurus::setLedState ( OLed which, OLedState st ) 1937bool Zaurus::setLedState ( OLed which, OLedState st )
1939{ 1938{
1940 if (!m_embedix) // Currently not supported on non_embedix kernels 1939 if (!m_embedix) // Currently not supported on non_embedix kernels
1941 return false; 1940 return false;
1942 1941
1943 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 1942 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
1944 1943
1945 if ( which == Led_Mail ) { 1944 if ( which == Led_Mail ) {
1946 if ( fd >= 0 ) { 1945 if ( fd >= 0 ) {
1947 struct sharp_led_status leds; 1946 struct sharp_led_status leds;
1948 ::memset ( &leds, 0, sizeof( leds )); 1947 ::memset ( &leds, 0, sizeof( leds ));
1949 leds. which = SHARP_LED_MAIL_EXISTS; 1948 leds. which = SHARP_LED_MAIL_EXISTS;
1950 bool ok = true; 1949 bool ok = true;
1951 1950
1952 switch ( st ) { 1951 switch ( st ) {
1953 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 1952 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
1954 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 1953 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
1955 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 1954 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
1956 default : ok = false; 1955 default : ok = false;
1957 } 1956 }
1958 1957
1959 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { 1958 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) {
1960 m_leds [0] = st; 1959 m_leds [0] = st;
1961 return true; 1960 return true;
1962 } 1961 }
1963 } 1962 }
1964 } 1963 }
1965 return false; 1964 return false;
1966} 1965}
1967 1966
1968bool Zaurus::setSoftSuspend ( bool soft ) 1967bool Zaurus::setSoftSuspend ( bool soft )
1969{ 1968{
1970 if (!m_embedix) { 1969 if (!m_embedix) {
1971 /* non-Embedix kernels dont have kernel autosuspend */ 1970 /* non-Embedix kernels dont have kernel autosuspend */
1972 return ODevice::setSoftSuspend( soft ); 1971 return ODevice::setSoftSuspend( soft );
1973 } 1972 }
1974 1973
1975 bool res = false; 1974 bool res = false;
1976 int fd; 1975 int fd;
1977 1976
1978 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 1977 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
1979 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 1978 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
1980 1979
1981 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 1980 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
1982 1981
1983 if ( sources >= 0 ) { 1982 if ( sources >= 0 ) {
1984 if ( soft ) 1983 if ( soft )
1985 sources &= ~APM_EVT_POWER_BUTTON; 1984 sources &= ~APM_EVT_POWER_BUTTON;
1986 else 1985 else
1987 sources |= APM_EVT_POWER_BUTTON; 1986 sources |= APM_EVT_POWER_BUTTON;
1988 1987
1989 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources 1988 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
1990 res = true; 1989 res = true;
1991 else 1990 else
1992 perror ( "APM_IOCGEVTSRC" ); 1991 perror ( "APM_IOCGEVTSRC" );
1993 } 1992 }
1994 else 1993 else
1995 perror ( "APM_IOCGEVTSRC" ); 1994 perror ( "APM_IOCGEVTSRC" );
1996 1995
1997 ::close ( fd ); 1996 ::close ( fd );
1998 } 1997 }
1999 else 1998 else
2000 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 1999 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
2001 2000
2002 return res; 2001 return res;
2003} 2002}
2004 2003
2005 2004
2006bool Zaurus::setDisplayBrightness ( int bright ) 2005bool Zaurus::setDisplayBrightness ( int bright )
2007{ 2006{
2008 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright ); 2007 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright );
2009 bool res = false; 2008 bool res = false;
2010 int fd; 2009 int fd;
2011 2010
2012 if ( bright > 255 ) bright = 255; 2011 if ( bright > 255 ) bright = 255;
2013 if ( bright < 0 ) bright = 0; 2012 if ( bright < 0 ) bright = 0;
2014 2013
2015 if ( m_embedix ) 2014 if ( m_embedix )
2016 { 2015 {
2017 if ( d->m_model == Model_Zaurus_SLC7x0 ) 2016 if ( d->m_model == Model_Zaurus_SLC7x0 )
2018 { 2017 {
2019 //qDebug( "using special treatment for devices with the corgi backlight interface" ); 2018 //qDebug( "using special treatment for devices with the corgi backlight interface" );
2020 // special treatment for devices with the corgi backlight interface 2019 // special treatment for devices with the corgi backlight interface
2021 if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 ) 2020 if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 )
2022 { 2021 {
2023 int value = ( bright == 1 ) ? 1 : bright * ( 17.0 / 255.0 ); 2022 int value = ( bright == 1 ) ? 1 : bright * ( 17.0 / 255.0 );
2024 char writeCommand[100]; 2023 char writeCommand[100];
2025 const int count = sprintf( writeCommand, "0x%x\n", value ); 2024 const int count = sprintf( writeCommand, "0x%x\n", value );
2026 res = ( ::write ( fd, writeCommand, count ) != -1 ); 2025 res = ( ::write ( fd, writeCommand, count ) != -1 );
2027 ::close ( fd ); 2026 ::close ( fd );
2028 } 2027 }
2029 return res; 2028 return res;
2030 } 2029 }
2031 else 2030 else
2032 { 2031 {
2033 // standard treatment for devices with the dumb embedix frontlight interface 2032 // standard treatment for devices with the dumb embedix frontlight interface
2034 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 2033 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
2035 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 2034 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
2036 if ( bright && !bl ) 2035 if ( bright && !bl )
2037 bl = 1; 2036 bl = 1;
2038 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 2037 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
2039 ::close ( fd ); 2038 ::close ( fd );
2040 } 2039 }
2041 } 2040 }
2042 } 2041 }
2043 else 2042 else
2044 { 2043 {
2045 // special treatment for the OpenZaurus unified interface 2044 // special treatment for the OpenZaurus unified interface
2046 #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */ 2045 #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */
2047 if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) { 2046 if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) {
2048 res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 ); 2047 res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 );
2049 ::close ( fd ); 2048 ::close ( fd );
2050 } 2049 }
2051 } 2050 }
2052 return res; 2051 return res;
2053} 2052}
2054 2053
2055bool Zaurus::suspend ( ) 2054bool Zaurus::suspend ( )
2056{ 2055{
2057 qDebug("ODevice::suspend"); 2056 qDebug("ODevice::suspend");
2058 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 2057 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
2059 return false; 2058 return false;
2060 2059
2061 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 2060 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
2062 return false; 2061 return false;
2063 2062
2064 bool res = false; 2063 bool res = false;
2065 2064
2066 struct timeval tvs, tvn; 2065 struct timeval tvs, tvn;
2067 ::gettimeofday ( &tvs, 0 ); 2066 ::gettimeofday ( &tvs, 0 );
2068 2067
2069 ::sync ( ); // flush fs caches 2068 ::sync ( ); // flush fs caches
2070 res = ( ::system ( "apm --suspend" ) == 0 ); 2069 res = ( ::system ( "apm --suspend" ) == 0 );
2071 2070
2072 // This is needed because the iPAQ apm implementation is asynchronous and we 2071 // This is needed because the iPAQ apm implementation is asynchronous and we
2073 // can not be sure when exactly the device is really suspended 2072 // can not be sure when exactly the device is really suspended
2074 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 2073 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
2075 2074
2076 if ( res ) { 2075 if ( res ) {
2077 do { // Yes, wait 15 seconds. This APM bug sucks big time. 2076 do { // Yes, wait 15 seconds. This APM bug sucks big time.
2078 ::usleep ( 200 * 1000 ); 2077 ::usleep ( 200 * 1000 );
2079 ::gettimeofday ( &tvn, 0 ); 2078 ::gettimeofday ( &tvn, 0 );
2080 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 ); 2079 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 );
2081 } 2080 }
2082 2081
2083 QCopEnvelope ( "QPE/Rotation", "rotateDefault()" ); 2082 QCopEnvelope ( "QPE/Rotation", "rotateDefault()" );
2084 return res; 2083 return res;
2085} 2084}
2086 2085
2087 2086
2088Transformation Zaurus::rotation ( ) const 2087Transformation Zaurus::rotation ( ) const
2089{ 2088{
2090 Transformation rot; 2089 Transformation rot;
2091 int handle = 0; 2090 int handle = 0;
2092 int retval = 0; 2091 int retval = 0;
2093 2092
2094 switch ( d-> m_model ) { 2093 switch ( d-> m_model ) {
2095 case Model_Zaurus_SLC7x0: 2094 case Model_Zaurus_SLC7x0:
2096 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 2095 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
2097 if (handle == -1) { 2096 if (handle == -1) {
2098 return Rot270; 2097 return Rot270;
2099 } else { 2098 } else {
2100 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 2099 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
2101 ::close (handle); 2100 ::close (handle);
2102 2101
2103 if (retval == 2 ) 2102 if (retval == 2 )
2104 rot = Rot0; 2103 rot = Rot0;
2105 else 2104 else
2106 rot = Rot270; 2105 rot = Rot270;
2107 } 2106 }
2108 break; 2107 break;
2109 case Model_Zaurus_SLA300: 2108 case Model_Zaurus_SLA300:
2110 case Model_Zaurus_SLB600: 2109 case Model_Zaurus_SLB600:
2111 case Model_Zaurus_SL5500: 2110 case Model_Zaurus_SL5500:
2112 case Model_Zaurus_SL5000: 2111 case Model_Zaurus_SL5000:
2113 default: 2112 default:
2114 rot = d-> m_rotation; 2113 rot = d-> m_rotation;
2115 break; 2114 break;
2116 } 2115 }
2117 2116
2118 return rot; 2117 return rot;
2119} 2118}
2120ODirection Zaurus::direction ( ) const 2119ODirection Zaurus::direction ( ) const
2121{ 2120{
2122 ODirection dir; 2121 ODirection dir;
2123 int handle = 0; 2122 int handle = 0;
2124 int retval = 0; 2123 int retval = 0;
2125 switch ( d-> m_model ) { 2124 switch ( d-> m_model ) {
2126 case Model_Zaurus_SLC7x0: 2125 case Model_Zaurus_SLC7x0:
2127 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 2126 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
2128 if (handle == -1) { 2127 if (handle == -1) {
2129 dir = CW; 2128 dir = CW;
2130 } else { 2129 } else {
2131 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 2130 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
2132 ::close (handle); 2131 ::close (handle);
2133 if (retval == 2 ) 2132 if (retval == 2 )
2134 dir = CCW; 2133 dir = CCW;
2135 else 2134 else
2136 dir = CW; 2135 dir = CW;
2137 } 2136 }
2138 break; 2137 break;
2139 case Model_Zaurus_SLA300: 2138 case Model_Zaurus_SLA300:
2140 case Model_Zaurus_SLB600: 2139 case Model_Zaurus_SLB600:
2141 case Model_Zaurus_SL5500: 2140 case Model_Zaurus_SL5500:
2142 case Model_Zaurus_SL5000: 2141 case Model_Zaurus_SL5000:
2143 default: 2142 default:
2144 dir = d-> m_direction; 2143 dir = d-> m_direction;
2145 break; 2144 break;
2146 } 2145 }
2147 return dir; 2146 return dir;
2148 2147
2149} 2148}
2150 2149
2151int Zaurus::displayBrightnessResolution ( ) const 2150int Zaurus::displayBrightnessResolution ( ) const
2152{ 2151{
2153 if (m_embedix) 2152 if (m_embedix)
2154 return d->m_model == Model_Zaurus_SLC7x0 ? 18 : 5; 2153 return d->m_model == Model_Zaurus_SLC7x0 ? 18 : 5;
2155 else 2154 else
2156 return 256; 2155 return 256;
2157} 2156}
2158 2157
2159bool Zaurus::hasHingeSensor() const 2158bool Zaurus::hasHingeSensor() const
2160{ 2159{
2161 return d->m_model == Model_Zaurus_SLC7x0; 2160 return d->m_model == Model_Zaurus_SLC7x0;
2162} 2161}
2163 2162
2164OHingeStatus Zaurus::readHingeSensor() 2163OHingeStatus Zaurus::readHingeSensor()
2165{ 2164{
2166 int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 2165 int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
2167 if (handle == -1) 2166 if (handle == -1)
2168 { 2167 {
2169 qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror 2168 qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror
2170 return CASE_UNKNOWN; 2169 return CASE_UNKNOWN;
2171 } 2170 }
2172 else 2171 else
2173 { 2172 {
2174 int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 2173 int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
2175 ::close (handle); 2174 ::close (handle);
2176 if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE ) 2175 if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE )
2177 { 2176 {
2178 qDebug( "Zaurus::readHingeSensor() - result = %d", retval ); 2177 qDebug( "Zaurus::readHingeSensor() - result = %d", retval );
2179 return static_cast<OHingeStatus>( retval ); 2178 return static_cast<OHingeStatus>( retval );
2180 } 2179 }
2181 else 2180 else
2182 { 2181 {
2183 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); 2182 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
2184 return CASE_UNKNOWN; 2183 return CASE_UNKNOWN;
2185 } 2184 }
2186 } 2185 }
2187} 2186}
2188 2187
2189 2188
2190void Zaurus::virtual_hook( int id, void *data ) { 2189void Zaurus::virtual_hook( int id, void *data ) {
2191 switch( id ) { 2190 switch( id ) {
2192 case VIRTUAL_ROTATION:{ 2191 case VIRTUAL_ROTATION:{
2193 VirtRotation* rot = reinterpret_cast<VirtRotation*>( data ); 2192 VirtRotation* rot = reinterpret_cast<VirtRotation*>( data );
2194 rot->trans = rotation(); 2193 rot->trans = rotation();
2195 break; 2194 break;
2196 } 2195 }
2197 case VIRTUAL_DIRECTION:{ 2196 case VIRTUAL_DIRECTION:{
2198 VirtDirection *dir = reinterpret_cast<VirtDirection*>( data ); 2197 VirtDirection *dir = reinterpret_cast<VirtDirection*>( data );
2199 dir->direct = direction(); 2198 dir->direct = direction();
2200 break; 2199 break;
2201 } 2200 }
2202 case VIRTUAL_HAS_HINGE:{ 2201 case VIRTUAL_HAS_HINGE:{
2203 VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data ); 2202 VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data );
2204 hin->hasHinge = hasHingeSensor(); 2203 hin->hasHinge = hasHingeSensor();
2205 break; 2204 break;
2206 } 2205 }
2207 case VIRTUAL_HINGE:{ 2206 case VIRTUAL_HINGE:{
2208 VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data ); 2207 VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data );
2209 hin->hingeStat = readHingeSensor(); 2208 hin->hingeStat = readHingeSensor();
2210 break; 2209 break;
2211 } 2210 }
2212 default: 2211 default:
2213 ODevice::virtual_hook( id, data ); 2212 ODevice::virtual_hook( id, data );
2214 break; 2213 break;
2215 } 2214 }
2216} 2215}
2217 2216
2218/************************************************** 2217/**************************************************
2219 * 2218 *
2220 * SIMpad 2219 * SIMpad
2221 * 2220 *
2222 **************************************************/ 2221 **************************************************/
2223 2222
2224void SIMpad::init ( ) 2223void SIMpad::init ( )
2225{ 2224{
2226 d-> m_vendorstr = "SIEMENS"; 2225 d-> m_vendorstr = "SIEMENS";
2227 d-> m_vendor = Vendor_SIEMENS; 2226 d-> m_vendor = Vendor_SIEMENS;
2228 2227
2229 QFile f ( "/proc/hal/model" ); 2228 QFile f ( "/proc/hal/model" );
2230 2229
2231 //TODO Implement model checking 2230 //TODO Implement model checking
2232 //FIXME For now we assume an SL4 2231 //FIXME For now we assume an SL4
2233 2232
2234 d-> m_modelstr = "SL4"; 2233 d-> m_modelstr = "SL4";
2235 d-> m_model = Model_SIMpad_SL4; 2234 d-> m_model = Model_SIMpad_SL4;
2236 2235
2237 switch ( d-> m_model ) { 2236 switch ( d-> m_model ) {
2238 default: 2237 default:
2239 d-> m_rotation = Rot0; 2238 d-> m_rotation = Rot0;
2240 d-> m_direction = CCW; 2239 d-> m_direction = CCW;
2241 d-> m_holdtime = 1000; // 1000ms 2240 d-> m_holdtime = 1000; // 1000ms
2242 2241
2243 break; 2242 break;
2244 } 2243 }
2245 2244
2246 f. setName ( "/etc/familiar-version" ); 2245 f. setName ( "/etc/familiar-version" );
2247 if ( f. open ( IO_ReadOnly )) { 2246 if ( f. open ( IO_ReadOnly )) {
2248 d-> m_systemstr = "Familiar"; 2247 d-> m_systemstr = "Familiar";
2249 d-> m_system = System_Familiar; 2248 d-> m_system = System_Familiar;
2250 2249
2251 QTextStream ts ( &f ); 2250 QTextStream ts ( &f );
2252 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 2251 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
2253 2252
2254 f. close ( ); 2253 f. close ( );
2255 } else { 2254 } else {
2256 f. setName ( "/etc/oz_version" ); 2255 f. setName ( "/etc/oz_version" );
2257 2256
2258 if ( f. open ( IO_ReadOnly )) { 2257 if ( f. open ( IO_ReadOnly )) {
2259 d-> m_systemstr = "OpenEmbedded/SIMpad"; 2258 d-> m_systemstr = "OpenEmbedded/SIMpad";
2260 d-> m_system = System_OpenZaurus; 2259 d-> m_system = System_OpenZaurus;
2261 2260
2262 QTextStream ts ( &f ); 2261 QTextStream ts ( &f );
2263 ts.setDevice ( &f ); 2262 ts.setDevice ( &f );
2264 d-> m_sysverstr = ts. readLine ( ); 2263 d-> m_sysverstr = ts. readLine ( );
2265 f. close ( ); 2264 f. close ( );
2266 } 2265 }
2267 } 2266 }
2268 2267
2269 m_leds [0] = m_leds [1] = Led_Off; 2268 m_leds [0] = m_leds [1] = Led_Off;
2270 2269
2271 m_power_timer = 0; 2270 m_power_timer = 0;
2272 2271
2273} 2272}
2274 2273
2275void SIMpad::initButtons ( ) 2274void SIMpad::initButtons ( )
2276{ 2275{
2277 if ( d-> m_buttons ) 2276 if ( d-> m_buttons )
2278 return; 2277 return;
2279 2278
2280 if ( isQWS( ) ) 2279 if ( isQWS( ) )
2281 QWSServer::setKeyboardFilter ( this ); 2280 QWSServer::setKeyboardFilter ( this );
2282 2281
2283 d-> m_buttons = new QValueList <ODeviceButton>; 2282 d-> m_buttons = new QValueList <ODeviceButton>;
2284 2283
2285 for ( uint i = 0; i < ( sizeof( simpad_buttons ) / sizeof( s_button )); i++ ) { 2284 for ( uint i = 0; i < ( sizeof( simpad_buttons ) / sizeof( s_button )); i++ ) {
2286 s_button *sb = simpad_buttons + i; 2285 s_button *sb = simpad_buttons + i;
2287 ODeviceButton b; 2286 ODeviceButton b;
2288 2287
2289 if (( sb-> model & d-> m_model ) == d-> m_model ) { 2288 if (( sb-> model & d-> m_model ) == d-> m_model ) {
2290 b. setKeycode ( sb-> code ); 2289 b. setKeycode ( sb-> code );
2291 b. setUserText ( QObject::tr ( "Button", sb-> utext )); 2290 b. setUserText ( QObject::tr ( "Button", sb-> utext ));
2292 b. setPixmap ( Resource::loadPixmap ( sb-> pix )); 2291 b. setPixmap ( Resource::loadPixmap ( sb-> pix ));
2293 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb-> fpressedservice ), sb-> fpressedaction )); 2292 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb-> fpressedservice ), sb-> fpressedaction ));
2294 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb-> fheldservice ), sb-> fheldaction )); 2293 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb-> fheldservice ), sb-> fheldaction ));
2295 2294
2296 d-> m_buttons-> append ( b ); 2295 d-> m_buttons-> append ( b );
2297 } 2296 }
2298 } 2297 }
2299 reloadButtonMapping ( ); 2298 reloadButtonMapping ( );
2300 2299
2301 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 2300 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
2302 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 2301 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
2303} 2302}
2304 2303
2305// SIMpad boardcontrol register CS3 2304// SIMpad boardcontrol register CS3
2306#define SIMPAD_BOARDCONTROL "/proc/cs3" 2305#define SIMPAD_BOARDCONTROL "/proc/cs3"
2307#define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA 2306#define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA
2308#define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA 2307#define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA
2309#define SIMPAD_EN1 0x0004 // This is only for EPROM's 2308#define SIMPAD_EN1 0x0004 // This is only for EPROM's
2310#define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V 2309#define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V
2311#define SIMPAD_DISPLAY_ON 0x0010 2310#define SIMPAD_DISPLAY_ON 0x0010
2312#define SIMPAD_PCMCIA_BUFF_DIS 0x0020 2311#define SIMPAD_PCMCIA_BUFF_DIS 0x0020
2313#define SIMPAD_MQ_RESET 0x0040 2312#define SIMPAD_MQ_RESET 0x0040
2314#define SIMPAD_PCMCIA_RESET 0x0080 2313#define SIMPAD_PCMCIA_RESET 0x0080
2315#define SIMPAD_DECT_POWER_ON 0x0100 2314#define SIMPAD_DECT_POWER_ON 0x0100
2316#define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave 2315#define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave
2317#define SIMPAD_RS232_ON 0x0400 2316#define SIMPAD_RS232_ON 0x0400
2318#define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave 2317#define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave
2319#define SIMPAD_LED2_ON 0x1000 2318#define SIMPAD_LED2_ON 0x1000
2320#define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode 2319#define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode
2321#define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit 2320#define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit
2322#define SIMPAD_RESET_SIMCARD 0x8000 2321#define SIMPAD_RESET_SIMCARD 0x8000
2323 2322
2324//SIMpad touchscreen backlight strength control 2323//SIMpad touchscreen backlight strength control
2325#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL" 2324#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL"
2326#define SIMPAD_BACKLIGHT_MASK 0x00a10044 2325#define SIMPAD_BACKLIGHT_MASK 0x00a10044
2327 2326
2328QValueList <OLed> SIMpad::ledList ( ) const 2327QValueList <OLed> SIMpad::ledList ( ) const
2329{ 2328{
2330 QValueList <OLed> vl; 2329 QValueList <OLed> vl;
2331 vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? 2330 vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one?
2332 //vl << Led_Mail; //TODO find out if LED1 is accessible anyway 2331 //vl << Led_Mail; //TODO find out if LED1 is accessible anyway
2333 return vl; 2332 return vl;
2334} 2333}
2335 2334
2336QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const 2335QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const
2337{ 2336{
2338 QValueList <OLedState> vl; 2337 QValueList <OLedState> vl;
2339 2338
2340 if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? 2339 if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one?
2341 vl << Led_Off << Led_On; 2340 vl << Led_Off << Led_On;
2342 //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway 2341 //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway
2343 //vl << Led_Off; 2342 //vl << Led_Off;
2344 return vl; 2343 return vl;
2345} 2344}
2346 2345
2347OLedState SIMpad::ledState ( OLed l ) const 2346OLedState SIMpad::ledState ( OLed l ) const
2348{ 2347{
2349 switch ( l ) { 2348 switch ( l ) {
2350 case Led_Power: 2349 case Led_Power:
2351 return m_leds [0]; 2350 return m_leds [0];
2352 //case Led_Mail: 2351 //case Led_Mail:
2353 //return m_leds [1]; 2352 //return m_leds [1];
2354 default: 2353 default:
2355 return Led_Off; 2354 return Led_Off;
2356 } 2355 }
2357} 2356}
2358 2357
2359bool SIMpad::setLedState ( OLed l, OLedState st ) 2358bool SIMpad::setLedState ( OLed l, OLedState st )
2360{ 2359{
2361 static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); 2360 static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK );
2362 2361
2363 if ( l == Led_Power ) { 2362 if ( l == Led_Power ) {
2364 if ( fd >= 0 ) { 2363 if ( fd >= 0 ) {
2365 LED_IN leds; 2364 LED_IN leds;
2366 ::memset ( &leds, 0, sizeof( leds )); 2365 ::memset ( &leds, 0, sizeof( leds ));
2367 leds. TotalTime = 0; 2366 leds. TotalTime = 0;
2368 leds. OnTime = 0; 2367 leds. OnTime = 0;
2369 leds. OffTime = 1; 2368 leds. OffTime = 1;
2370 leds. OffOnBlink = 2; 2369 leds. OffOnBlink = 2;
2371 2370
2372 switch ( st ) { 2371 switch ( st ) {
2373 case Led_Off : leds. OffOnBlink = 0; break; 2372 case Led_Off : leds. OffOnBlink = 0; break;
2374 case Led_On : leds. OffOnBlink = 1; break; 2373 case Led_On : leds. OffOnBlink = 1; break;
2375 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 2374 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
2376 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 2375 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
2377 } 2376 }
2378 2377
2379 { 2378 {
2380 /*TODO Implement this like that: 2379 /*TODO Implement this like that:
2381 read from cs3 2380 read from cs3
2382 && with SIMPAD_LED2_ON 2381 && with SIMPAD_LED2_ON
2383 write to cs3 */ 2382 write to cs3 */
2384 m_leds [0] = st; 2383 m_leds [0] = st;
2385 return true; 2384 return true;
2386 } 2385 }
2387 } 2386 }
2388 } 2387 }
2389 return false; 2388 return false;
2390} 2389}
2391 2390
2392 2391
2393bool SIMpad::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 2392bool SIMpad::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
2394{ 2393{
2395 //TODO 2394 //TODO
2396 return false; 2395 return false;
2397} 2396}
2398 2397
2399void SIMpad::timerEvent ( QTimerEvent * ) 2398void SIMpad::timerEvent ( QTimerEvent * )
2400{ 2399{
2401 killTimer ( m_power_timer ); 2400 killTimer ( m_power_timer );
2402 m_power_timer = 0; 2401 m_power_timer = 0;
2403 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 2402 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
2404 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 2403 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
2405} 2404}
2406 2405
2407 2406
2408void SIMpad::alarmSound ( ) 2407void SIMpad::alarmSound ( )
2409{ 2408{
2410#ifndef QT_NO_SOUND 2409#ifndef QT_NO_SOUND
2411 static Sound snd ( "alarm" ); 2410 static Sound snd ( "alarm" );
2412 int fd; 2411 int fd;
2413 int vol; 2412 int vol;
2414 bool vol_reset = false; 2413 bool vol_reset = false;
2415 2414
2416 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 2415 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
2417 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 2416 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
2418 Config cfg ( "qpe" ); 2417 Config cfg ( "qpe" );
2419 cfg. setGroup ( "Volume" ); 2418 cfg. setGroup ( "Volume" );
2420 2419
2421 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 2420 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
2422 if ( volalarm < 0 ) 2421 if ( volalarm < 0 )
2423 volalarm = 0; 2422 volalarm = 0;
2424 else if ( volalarm > 100 ) 2423 else if ( volalarm > 100 )
2425 volalarm = 100; 2424 volalarm = 100;
2426 volalarm |= ( volalarm << 8 ); 2425 volalarm |= ( volalarm << 8 );
2427 2426
2428 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 2427 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
2429 vol_reset = true; 2428 vol_reset = true;
2430 } 2429 }
2431 } 2430 }
2432 2431
2433 snd. play ( ); 2432 snd. play ( );
2434 while ( !snd. isFinished ( )) 2433 while ( !snd. isFinished ( ))
2435 qApp-> processEvents ( ); 2434 qApp-> processEvents ( );
2436 2435
2437 if ( fd >= 0 ) { 2436 if ( fd >= 0 ) {
2438 if ( vol_reset ) 2437 if ( vol_reset )
2439 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 2438 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
2440 ::close ( fd ); 2439 ::close ( fd );
2441 } 2440 }
2442#endif 2441#endif
2443} 2442}
2444 2443
2445 2444
2446bool SIMpad::suspend ( ) // Must override because SIMpad does NOT have apm 2445bool SIMpad::suspend ( ) // Must override because SIMpad does NOT have apm
2447{ 2446{
2448 qDebug( "ODevice for SIMpad: suspend()" ); 2447 qDebug( "ODevice for SIMpad: suspend()" );
2449 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 2448 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
2450 return false; 2449 return false;
2451 2450
2452 bool res = false; 2451 bool res = false;
2453 2452
2454 struct timeval tvs, tvn; 2453 struct timeval tvs, tvn;
2455 ::gettimeofday ( &tvs, 0 ); 2454 ::gettimeofday ( &tvs, 0 );
2456 2455
2457 ::sync ( ); // flush fs caches 2456 ::sync ( ); // flush fs caches
2458 res = ( ::system ( "cat /dev/fb/0 >/tmp/.buffer; echo > /proc/sys/pm/suspend; cat /tmp/.buffer >/dev/fb/0" ) == 0 ); //TODO make better :) 2457 res = ( ::system ( "cat /dev/fb/0 >/tmp/.buffer; echo > /proc/sys/pm/suspend; cat /tmp/.buffer >/dev/fb/0" ) == 0 ); //TODO make better :)
2459 2458
2460 return res; 2459 return res;
2461} 2460}
2462 2461
2463 2462
2464bool SIMpad::setSoftSuspend ( bool soft ) 2463bool SIMpad::setSoftSuspend ( bool soft )
2465{ 2464{
2466 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); 2465 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" );
2467 return false; 2466 return false;
2468} 2467}
2469 2468
2470 2469
2471bool SIMpad::setDisplayStatus ( bool on ) 2470bool SIMpad::setDisplayStatus ( bool on )
2472{ 2471{
2473 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); 2472 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" );
2474 2473
2475 bool res = false; 2474 bool res = false;
2476 int fd; 2475 int fd;
2477 2476
2478 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) 2477 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :)
2479 2478
2480 res = ( ::system( (const char*) cmdline ) == 0 ); 2479 res = ( ::system( (const char*) cmdline ) == 0 );
2481 2480
2482 return res; 2481 return res;
2483} 2482}
2484 2483
2485 2484
2486bool SIMpad::setDisplayBrightness ( int bright ) 2485bool SIMpad::setDisplayBrightness ( int bright )
2487{ 2486{
2488 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); 2487 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright );
2489 bool res = false; 2488 bool res = false;
2490 int fd; 2489 int fd;
2491 2490
2492 if ( bright > 255 ) 2491 if ( bright > 255 )
2493 bright = 255; 2492 bright = 255;
2494 if ( bright < 1 ) 2493 if ( bright < 1 )
2495 bright = 0; 2494 bright = 0;
2496 2495
2497 if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { 2496 if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) {
2498 int value = 255 - bright; 2497 int value = 255 - bright;
2499 const int mask = SIMPAD_BACKLIGHT_MASK; 2498 const int mask = SIMPAD_BACKLIGHT_MASK;
2500 value = value << 8; 2499 value = value << 8;
2501 value += mask; 2500 value += mask;
2502 char writeCommand[100]; 2501 char writeCommand[100];
2503 const int count = sprintf( writeCommand, "0x%x\n", value ); 2502 const int count = sprintf( writeCommand, "0x%x\n", value );
2504 res = ( ::write ( fd, writeCommand, count ) != -1 ); 2503 res = ( ::write ( fd, writeCommand, count ) != -1 );
2505 ::close ( fd ); 2504 ::close ( fd );
2506 } 2505 }
2507 return res; 2506 return res;
2508} 2507}
2509 2508
2510 2509
2511int SIMpad::displayBrightnessResolution ( ) const 2510int SIMpad::displayBrightnessResolution ( ) const
2512{ 2511{
2513 return 255; // All SIMpad models share the same display 2512 return 255; // All SIMpad models share the same display
2514} 2513}
2515 2514
2516/************************************************** 2515/**************************************************
2517 * 2516 *
2518 * Ramses 2517 * Ramses
2519 * 2518 *
2520 **************************************************/ 2519 **************************************************/
2521 2520
2522void Ramses::init() 2521void Ramses::init()
2523{ 2522{
2524 d->m_vendorstr = "M und N"; 2523 d->m_vendorstr = "M und N";
2525 d->m_vendor = Vendor_MundN; 2524 d->m_vendor = Vendor_MundN;
2526 2525
2527 QFile f("/proc/sys/board/ramses"); 2526 QFile f("/proc/sys/board/ramses");
2528 2527
2529 d->m_modelstr = "Ramses"; 2528 d->m_modelstr = "Ramses";
2530 d->m_model = Model_Ramses_MNCI; 2529 d->m_model = Model_Ramses_MNCI;
2531 2530
2532 d->m_rotation = Rot0; 2531 d->m_rotation = Rot0;
2533 d->m_holdtime = 1000; 2532 d->m_holdtime = 1000;
2534 2533
2535 f.setName("/etc/oz_version"); 2534 f.setName("/etc/oz_version");
2536 2535
2537 if (f.open(IO_ReadOnly)) { 2536 if (f.open(IO_ReadOnly)) {
2538 d->m_systemstr = "OpenEmbedded/Ramses"; 2537 d->m_systemstr = "OpenEmbedded/Ramses";
2539 d->m_system = System_OpenZaurus; 2538 d->m_system = System_OpenZaurus;
2540 2539
2541 QTextStream ts(&f); 2540 QTextStream ts(&f);
2542 ts.setDevice(&f); 2541 ts.setDevice(&f);
2543 d->m_sysverstr = ts.readLine(); 2542 d->m_sysverstr = ts.readLine();
2544 f.close(); 2543 f.close();
2545 } 2544 }
2546 2545
2547 m_power_timer = 0; 2546 m_power_timer = 0;
2548 2547
2549#ifdef QT_QWS_ALLOW_OVERCLOCK 2548#ifdef QT_QWS_ALLOW_OVERCLOCK
2550#warning *** Overclocking enabled - this may fry your hardware - you have been warned *** 2549#warning *** Overclocking enabled - this may fry your hardware - you have been warned ***
2551#define OC(x...) x 2550#define OC(x...) x
2552#else 2551#else
2553#define OC(x...) 2552#define OC(x...)
2554#endif 2553#endif
2555 2554
2556 2555
2557 // This table is true for a Intel XScale PXA 255 2556 // This table is true for a Intel XScale PXA 255
2558 2557
2559 d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50 2558 d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50
2560 OC(d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem 2559 OC(d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem
2561 d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99 2560 d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99
2562 OC(d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem 2561 OC(d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem
2563 d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99 2562 d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99
2564 OC(d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem 2563 OC(d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem
2565 d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99 2564 d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99
2566 d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196 2565 d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196
2567 OC(d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus 2566 OC(d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus
2568 2567
2569} 2568}
2570 2569
2571bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat) 2570bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat)
2572{ 2571{
2573 Q_UNUSED( keycode ); 2572 Q_UNUSED( keycode );
2574 Q_UNUSED( modifiers ); 2573 Q_UNUSED( modifiers );
2575 Q_UNUSED( isPress ); 2574 Q_UNUSED( isPress );
2576 Q_UNUSED( autoRepeat ); 2575 Q_UNUSED( autoRepeat );
2577 return false; 2576 return false;
2578} 2577}
2579 2578
2580void Ramses::timerEvent(QTimerEvent *) 2579void Ramses::timerEvent(QTimerEvent *)
2581{ 2580{
2582 killTimer(m_power_timer); 2581 killTimer(m_power_timer);
2583 m_power_timer = 0; 2582 m_power_timer = 0;
2584 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false); 2583 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false);
2585 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false); 2584 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false);
2586} 2585}
2587 2586
2588 2587
2589bool Ramses::setSoftSuspend(bool soft) 2588bool Ramses::setSoftSuspend(bool soft)
2590{ 2589{
2591 qDebug("Ramses::setSoftSuspend(%d)", soft); 2590 qDebug("Ramses::setSoftSuspend(%d)", soft);
2592#if 0 2591#if 0
2593 bool res = false; 2592 bool res = false;
2594 int fd; 2593 int fd;
2595 2594
2596 if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) || 2595 if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) ||
2597 ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) { 2596 ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) {
2598 2597
2599 int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources 2598 int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources
2600 2599
2601 if (sources >= 0) { 2600 if (sources >= 0) {
2602 if (soft) 2601 if (soft)
2603 sources &= ~APM_EVT_POWER_BUTTON; 2602 sources &= ~APM_EVT_POWER_BUTTON;
2604 else 2603 else
2605 sources |= APM_EVT_POWER_BUTTON; 2604 sources |= APM_EVT_POWER_BUTTON;
2606 2605
2607 if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources 2606 if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources
2608 res = true; 2607 res = true;
2609 else 2608 else
2610 perror("APM_IOCGEVTSRC"); 2609 perror("APM_IOCGEVTSRC");
2611 } 2610 }
2612 else 2611 else
2613 perror("APM_IOCGEVTSRC"); 2612 perror("APM_IOCGEVTSRC");
2614 2613
2615 ::close(fd); 2614 ::close(fd);
2616 } 2615 }
2617 else 2616 else
2618 perror("/dev/apm_bios or /dev/misc/apm_bios"); 2617 perror("/dev/apm_bios or /dev/misc/apm_bios");
2619 2618
2620 return res; 2619 return res;
2621#else 2620#else
2622 return true; 2621 return true;
2623#endif 2622#endif
2624} 2623}
2625 2624
2626bool Ramses::suspend ( ) 2625bool Ramses::suspend ( )
2627{ 2626{
2628 qDebug("Ramses::suspend"); 2627 qDebug("Ramses::suspend");
2629 return false; 2628 return false;
2630} 2629}
2631 2630
2632/** 2631/**
2633 * This sets the display on or off 2632 * This sets the display on or off
2634 */ 2633 */
2635bool Ramses::setDisplayStatus(bool on) 2634bool Ramses::setDisplayStatus(bool on)
2636{ 2635{
2637 qDebug("Ramses::setDisplayStatus(%d)", on); 2636 qDebug("Ramses::setDisplayStatus(%d)", on);
2638#if 0 2637#if 0
2639 bool res = false; 2638 bool res = false;
2640 int fd; 2639 int fd;
2641 2640
2642 if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) { 2641 if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) {
2643 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0); 2642 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0);
2644 ::close(fd); 2643 ::close(fd);
2645 } 2644 }
2646 return res; 2645 return res;
2647#else 2646#else
2648 return true; 2647 return true;
2649#endif 2648#endif
2650} 2649}
2651 2650
2652 2651
2653/* 2652/*
2654 * We get something between 0..255 into us 2653 * We get something between 0..255 into us
2655*/ 2654*/
2656bool Ramses::setDisplayBrightness(int bright) 2655bool Ramses::setDisplayBrightness(int bright)
2657{ 2656{
2658 qDebug("Ramses::setDisplayBrightness(%d)", bright); 2657 qDebug("Ramses::setDisplayBrightness(%d)", bright);
2659 bool res = false; 2658 bool res = false;
2660 int fd; 2659 int fd;
2661 2660
2662 // pwm1 brighness: 20 steps 500..0 (dunkel->hell) 2661 // pwm1 brighness: 20 steps 500..0 (dunkel->hell)
2663 2662
2664 if (bright > 255 ) 2663 if (bright > 255 )
2665 bright = 255; 2664 bright = 255;
2666 if (bright < 0) 2665 if (bright < 0)
2667 bright = 0; 2666 bright = 0;
2668 2667
2669 // Turn backlight completely off 2668 // Turn backlight completely off
2670 if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) { 2669 if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) {
2671 char writeCommand[10]; 2670 char writeCommand[10];
2672 const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0); 2671 const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0);
2673 res = (::write(fd, writeCommand, count) != -1); 2672 res = (::write(fd, writeCommand, count) != -1);
2674 ::close(fd); 2673 ::close(fd);
2675 } 2674 }
2676 2675
2677 // scale backlight brightness to hardware 2676 // scale backlight brightness to hardware
2678 bright = 500-(bright * 500 / 255); 2677 bright = 500-(bright * 500 / 255);
2679 if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) { 2678 if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) {
2680 qDebug(" %d -> pwm1", bright); 2679 qDebug(" %d -> pwm1", bright);
2681 char writeCommand[100]; 2680 char writeCommand[100];
2682 const int count = sprintf(writeCommand, "%d\n", bright); 2681 const int count = sprintf(writeCommand, "%d\n", bright);
2683 res = (::write(fd, writeCommand, count) != -1); 2682 res = (::write(fd, writeCommand, count) != -1);
2684 ::close(fd); 2683 ::close(fd);
2685 } 2684 }
2686 return res; 2685 return res;
2687} 2686}
2688 2687
2689 2688
2690int Ramses::displayBrightnessResolution() const 2689int Ramses::displayBrightnessResolution() const
2691{ 2690{
2692 return 32; 2691 return 32;
2693} 2692}
2694 2693
2695bool Ramses::setDisplayContrast(int contr) 2694bool Ramses::setDisplayContrast(int contr)
2696{ 2695{
2697 qDebug("Ramses::setDisplayContrast(%d)", contr); 2696 qDebug("Ramses::setDisplayContrast(%d)", contr);
2698 bool res = false; 2697 bool res = false;
2699 int fd; 2698 int fd;
2700 2699
2701 // pwm0 contrast: 20 steps 79..90 (dunkel->hell) 2700 // pwm0 contrast: 20 steps 79..90 (dunkel->hell)
2702 2701
2703 if (contr > 255 ) 2702 if (contr > 255 )
2704 contr = 255; 2703 contr = 255;
2705 if (contr < 0) 2704 if (contr < 0)
2706 contr = 0; 2705 contr = 0;
2707 contr = 90 - (contr * 20 / 255); 2706 contr = 90 - (contr * 20 / 255);
2708 2707
2709 if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) { 2708 if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) {
2710 qDebug(" %d -> pwm0", contr); 2709 qDebug(" %d -> pwm0", contr);
2711 char writeCommand[100]; 2710 char writeCommand[100];
2712 const int count = sprintf(writeCommand, "%d\n", contr); 2711 const int count = sprintf(writeCommand, "%d\n", contr);
2713 res = (::write(fd, writeCommand, count) != -1); 2712 res = (::write(fd, writeCommand, count) != -1);
2714 res = true; 2713 res = true;
2715 ::close(fd); 2714 ::close(fd);
2716 } 2715 }
2717 return res; 2716 return res;
2718} 2717}
2719 2718
2720 2719
2721int Ramses::displayContrastResolution() const 2720int Ramses::displayContrastResolution() const
2722{ 2721{
2723 return 20; 2722 return 20;
2724} 2723}
2725 2724
2726 2725
2727/************************************************** 2726/**************************************************
2728 * * 2727 * *
2729 * Jornada * 2728 * Jornada *
2730 * * 2729 * *
2731 **************************************************/ 2730 **************************************************/
2732 2731
2733 2732
2734bool Jornada::isJornada ( ) 2733bool Jornada::isJornada ( )
2735{ 2734{
2736 QFile f( "/proc/cpuinfo" ); 2735 QFile f( "/proc/cpuinfo" );
2737 if ( f. open ( IO_ReadOnly ) ) { 2736 if ( f. open ( IO_ReadOnly ) ) {
2738 QTextStream ts ( &f ); 2737 QTextStream ts ( &f );
2739 QString line; 2738 QString line;
2740 while( line = ts. readLine ( ) ) { 2739 while( line = ts. readLine ( ) ) {
2741 if ( line. left ( 8 ) == "Hardware" ) { 2740 if ( line. left ( 8 ) == "Hardware" ) {
2742 int loc = line. find ( ":" ); 2741 int loc = line. find ( ":" );
2743 if ( loc != -1 ) { 2742 if ( loc != -1 ) {
2744 QString model = 2743 QString model =
2745 line. mid ( loc + 2 ). simplifyWhiteSpace( ); 2744 line. mid ( loc + 2 ). simplifyWhiteSpace( );
2746 return ( model == "HP Jornada 56x" ); 2745 return ( model == "HP Jornada 56x" );
2747 } 2746 }
2748 } 2747 }
2749 } 2748 }
2750 } 2749 }
2751 return false; 2750 return false;
2752} 2751}
2753 2752
2754void Jornada::init ( ) 2753void Jornada::init ( )
2755{ 2754{
2756 d-> m_vendorstr = "HP"; 2755 d-> m_vendorstr = "HP";
2757 d-> m_vendor = Vendor_HP; 2756 d-> m_vendor = Vendor_HP;
2758 d-> m_modelstr = "Jornada 56x"; 2757 d-> m_modelstr = "Jornada 56x";
2759 d-> m_model = Model_Jornada_56x; 2758 d-> m_model = Model_Jornada_56x;
2760 d-> m_systemstr = "Familiar"; 2759 d-> m_systemstr = "Familiar";
2761 d-> m_system = System_Familiar; 2760 d-> m_system = System_Familiar;
2762 d-> m_rotation = Rot0; 2761 d-> m_rotation = Rot0;
2763 2762
2764 QFile f ( "/etc/familiar-version" ); 2763 QFile f ( "/etc/familiar-version" );
2765 f. setName ( "/etc/familiar-version" ); 2764 f. setName ( "/etc/familiar-version" );
2766 if ( f. open ( IO_ReadOnly )) { 2765 if ( f. open ( IO_ReadOnly )) {
2767 2766
2768 QTextStream ts ( &f ); 2767 QTextStream ts ( &f );
2769 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 2768 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
2770 2769
2771 f. close ( ); 2770 f. close ( );
2772 } 2771 }
2773} 2772}
2774 2773
2775#if 0 2774#if 0
2776void Jornada::initButtons ( ) 2775void Jornada::initButtons ( )
2777{ 2776{
2778 if ( d-> m_buttons ) 2777 if ( d-> m_buttons )
2779 return; 2778 return;
2780 2779
2781 // Simulation uses iPAQ 3660 device buttons 2780 // Simulation uses iPAQ 3660 device buttons
2782 2781
2783 qDebug ( "init Buttons" ); 2782 qDebug ( "init Buttons" );
2784 d-> m_buttons = new QValueList <ODeviceButton>; 2783 d-> m_buttons = new QValueList <ODeviceButton>;
2785 2784
2786 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 2785 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
2787 i_button *ib = ipaq_buttons + i; 2786 i_button *ib = ipaq_buttons + i;
2788 ODeviceButton b; 2787 ODeviceButton b;
2789 2788
2790 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 2789 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
2791 b. setKeycode ( ib-> code ); 2790 b. setKeycode ( ib-> code );
2792 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 2791 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
2793 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 2792 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
2794 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 2793 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
2795 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 2794 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
2796 d-> m_buttons-> append ( b ); 2795 d-> m_buttons-> append ( b );
2797 } 2796 }
2798 } 2797 }
2799 reloadButtonMapping ( ); 2798 reloadButtonMapping ( );
2800 2799
2801 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 2800 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
2802 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 2801 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
2803} 2802}
2804#endif 2803#endif
2805int Jornada::displayBrightnessResolution ( ) const 2804int Jornada::displayBrightnessResolution ( ) const
2806{ 2805{
2807} 2806}
2808 2807
2809bool Jornada::setDisplayBrightness ( int bright ) 2808bool Jornada::setDisplayBrightness ( int bright )
2810{ 2809{
2811 bool res = false; 2810 bool res = false;
2812 int fd; 2811 int fd;
2813 2812
2814 if ( bright > 255 ) 2813 if ( bright > 255 )
2815 bright = 255; 2814 bright = 255;
2816 if ( bright < 0 ) 2815 if ( bright < 0 )
2817 bright = 0; 2816 bright = 0;
2818 2817
2819 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 2818 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
2820 FLITE_IN bl; 2819 FLITE_IN bl;
2821 bl. mode = 1; 2820 bl. mode = 1;
2822 bl. pwr = bright ? 1 : 0; 2821 bl. pwr = bright ? 1 : 0;
2823 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; 2822 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255;
2824 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 2823 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
2825 ::close ( fd ); 2824 ::close ( fd );
2826 } 2825 }
2827 return res; 2826 return res;
2828} 2827}
2829 2828
2830bool Jornada::setSoftSuspend ( bool soft ) 2829bool Jornada::setSoftSuspend ( bool soft )
2831{ 2830{
2832 bool res = false; 2831 bool res = false;
2833 int fd; 2832 int fd;
2834 2833
2835 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 2834 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
2836 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) 2835 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 )
2837 res = true; 2836 res = true;
2838 else 2837 else
2839 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 2838 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
2840 2839
2841 ::close ( fd ); 2840 ::close ( fd );
2842 } 2841 }
2843 else 2842 else
2844 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 2843 ::perror ( "/proc/sys/ts/suspend_button_mode" );
2845 2844
2846 return res; 2845 return res;
2847} 2846}
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,934 +1,929 @@
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 ) ),
397 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); 392 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) );
398} 393}
399void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { 394void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) {
400 if (!item) 395 if (!item)
401 return; 396 return;
402#if 0 397#if 0
403 398
404 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 399 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
405 400
406 if (!sel->isDir() ) { 401 if (!sel->isDir() ) {
407 selector()->m_lneEdit->setText( sel->text(1) ); 402 selector()->m_lneEdit->setText( sel->text(1) );
408 // if in fileselector mode we will emit selected 403 // if in fileselector mode we will emit selected
409 if ( selector()->mode() == OFileSelector::FileSelector ) { 404 if ( selector()->mode() == OFileSelector::FileSelector ) {
410 qWarning("slot Current Changed"); 405 qWarning("slot Current Changed");
411 QStringList str = QStringList::split("->", sel->text(1) ); 406 QStringList str = QStringList::split("->", sel->text(1) );
412 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 407 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
413 emit selector()->fileSelected( path ); 408 emit selector()->fileSelected( path );
414 DocLnk lnk( path ); 409 DocLnk lnk( path );
415 emit selector()->fileSelected( lnk ); 410 emit selector()->fileSelected( lnk );
416 } 411 }
417 } 412 }
418#endif 413#endif
419} 414}
420void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { 415void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) {
421 if (!item || ( button != Qt::LeftButton) ) 416 if (!item || ( button != Qt::LeftButton) )
422 return; 417 return;
423 418
424 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 419 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
425 if (!sel->isLocked() ) { 420 if (!sel->isLocked() ) {
426 QStringList str = QStringList::split("->", sel->text(1) ); 421 QStringList str = QStringList::split("->", sel->text(1) );
427 if (sel->isDir() ) { 422 if (sel->isDir() ) {
428 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); 423 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
429 emit selector()->dirSelected( m_currentDir ); 424 emit selector()->dirSelected( m_currentDir );
430 reread( m_all ); 425 reread( m_all );
431 }else { // file 426 }else { // file
432 qWarning("slot Clicked"); 427 qWarning("slot Clicked");
433 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); 428 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
434 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 429 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
435 emit selector()->fileSelected( path ); 430 emit selector()->fileSelected( path );
436 DocLnk lnk( path ); 431 DocLnk lnk( path );
437 emit selector()->fileSelected( lnk ); 432 emit selector()->fileSelected( lnk );
438 } 433 }
439 } // not locked 434 } // not locked
440} 435}
441void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { 436void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) {
442 MimeType type( info->absFilePath() ); 437 MimeType type( info->absFilePath() );
443 if (!compliesMime( type.id() ) ) 438 if (!compliesMime( type.id() ) )
444 return; 439 return;
445 440
446 QPixmap pix = type.pixmap(); 441 QPixmap pix = type.pixmap();
447 QString dir, name; bool locked; 442 QString dir, name; bool locked;
448 if ( pix.isNull() ) { 443 if ( pix.isNull() ) {
449 QWMatrix matrix; 444 QWMatrix matrix;
450 QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); 445 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
451 matrix.scale( .4, .4 ); 446 matrix.scale( .4, .4 );
452 pix = pixer.xForm( matrix ); 447 pix = pixer.xForm( matrix );
453 } 448 }
454 dir = info->dirPath( true ); 449 dir = info->dirPath( true );
455 locked = false; 450 locked = false;
456 if ( symlink ) 451 if ( symlink )
457 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); 452 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
458 else{ 453 else{
459 name = info->fileName(); 454 name = info->fileName();
460 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || 455 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
461 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { 456 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) {
462 locked = true; pix = Resource::loadPixmap("locked"); 457 locked = true; pix = Resource::loadPixmap("locked");
463 } 458 }
464 } 459 }
465 (void)new OFileSelectorItem( m_view, pix, name, 460 (void)new OFileSelectorItem( m_view, pix, name,
466 info->lastModified().toString(), QString::number( info->size() ), 461 info->lastModified().toString(), QString::number( info->size() ),
467 dir, locked ); 462 dir, locked );
468} 463}
469void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { 464void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) {
470 bool locked = false; QString name; QPixmap pix; 465 bool locked = false; QString name; QPixmap pix;
471 466
472 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || 467 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
473 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { 468 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) {
474 locked = true; 469 locked = true;
475 if ( symlink ) 470 if ( symlink )
476 pix = Resource::loadPixmap( "opie/symlink" ); 471 pix = Resource::loadPixmap( "opie/symlink" );
477 else 472 else
478 pix = Resource::loadPixmap( "lockedfolder" ); 473 pix = Resource::loadPixmap( "lockedfolder" );
479 }else 474 }else
480 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); 475 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
481 476
482 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : 477 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
483 info->fileName(); 478 info->fileName();
484 479
485 (void)new OFileSelectorItem( m_view, pix, name, 480 (void)new OFileSelectorItem( m_view, pix, name,
486 info->lastModified().toString(), 481 info->lastModified().toString(),
487 QString::number( info->size() ), 482 QString::number( info->size() ),
488 info->dirPath( true ), locked, true ); 483 info->dirPath( true ), locked, true );
489 484
490 485
491} 486}
492void OFileViewFileListView::addSymlink( QFileInfo* , bool ) { 487void OFileViewFileListView::addSymlink( QFileInfo* , bool ) {
493 488
494} 489}
495void OFileViewFileListView::cdUP() { 490void OFileViewFileListView::cdUP() {
496 QDir dir( m_currentDir ); 491 QDir dir( m_currentDir );
497 dir.cdUp(); 492 dir.cdUp();
498 493
499 if (!dir.exists() ) 494 if (!dir.exists() )
500 m_currentDir = "/"; 495 m_currentDir = "/";
501 else 496 else
502 m_currentDir = dir.absPath(); 497 m_currentDir = dir.absPath();
503 498
504 emit selector()->dirSelected( m_currentDir ); 499 emit selector()->dirSelected( m_currentDir );
505 reread( m_all ); 500 reread( m_all );
506} 501}
507void OFileViewFileListView::cdHome() { 502void OFileViewFileListView::cdHome() {
508 m_currentDir = QDir::homeDirPath(); 503 m_currentDir = QDir::homeDirPath();
509 emit selector()->dirSelected( m_currentDir ); 504 emit selector()->dirSelected( m_currentDir );
510 reread( m_all ); 505 reread( m_all );
511} 506}
512void OFileViewFileListView::cdDoc() { 507void OFileViewFileListView::cdDoc() {
513 m_currentDir = QPEApplication::documentDir(); 508 m_currentDir = QPEApplication::documentDir();
514 emit selector()->dirSelected( m_currentDir ); 509 emit selector()->dirSelected( m_currentDir );
515 reread( m_all ); 510 reread( m_all );
516} 511}
517void OFileViewFileListView::changeDir( const QString& dir ) { 512void OFileViewFileListView::changeDir( const QString& dir ) {
518 m_currentDir = dir; 513 m_currentDir = dir;
519 emit selector()->dirSelected( m_currentDir ); 514 emit selector()->dirSelected( m_currentDir );
520 reread( m_all ); 515 reread( m_all );
521} 516}
522void OFileViewFileListView::slotFSActivated( int id ) { 517void OFileViewFileListView::slotFSActivated( int id ) {
523 changeDir ( m_dev[m_fsPop->text(id)] ); 518 changeDir ( m_dev[m_fsPop->text(id)] );
524} 519}
525 520
526/* check if the mimetype in mime 521/* check if the mimetype in mime
527 * complies with the one which is current 522 * complies with the one which is current
528 */ 523 */
529/* 524/*
530 * We've the mimetype of the file 525 * We've the mimetype of the file
531 * We need to get the stringlist of the current mimetype 526 * We need to get the stringlist of the current mimetype
532 * 527 *
533 * mime = image@slashjpeg 528 * mime = image@slashjpeg
534 * QStringList = 'image@slash*' 529 * QStringList = 'image@slash*'
535 * or QStringList = image/jpeg;image/png;application/x-ogg 530 * or QStringList = image/jpeg;image/png;application/x-ogg
536 * or QStringList = application/x-ogg;image@slash*; 531 * or QStringList = application/x-ogg;image@slash*;
537 * with all these mime filters it should get acceptes 532 * with all these mime filters it should get acceptes
538 * to do so we need to look if mime is contained inside 533 * to do so we need to look if mime is contained inside
539 * the stringlist 534 * the stringlist
540 * if it's contained return true 535 * if it's contained return true
541 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' 536 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*'
542 * is contained in the mimefilter and then we will 537 * is contained in the mimefilter and then we will
543 * look if both are equal until the '/' 538 * look if both are equal until the '/'
544 */ 539 */
545bool OFileViewFileListView::compliesMime( const QString& str) { 540bool OFileViewFileListView::compliesMime( const QString& str) {
546 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) 541 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
547 return true; 542 return true;
548 543
549 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) { 544 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) {
550 QRegExp reg( (*it) ); 545 QRegExp reg( (*it) );
551 reg.setWildcard( true ); 546 reg.setWildcard( true );
552 if ( str.find( reg ) != -1 ) 547 if ( str.find( reg ) != -1 )
553 return true; 548 return true;
554 549
555 } 550 }
556 return false; 551 return false;
557} 552}
558/* 553/*
559 * The listView giving access to the file system! 554 * The listView giving access to the file system!
560 */ 555 */
561class OFileViewFileSystem : public OFileViewInterface { 556class OFileViewFileSystem : public OFileViewInterface {
562public: 557public:
563 OFileViewFileSystem( OFileSelector* ); 558 OFileViewFileSystem( OFileSelector* );
564 ~OFileViewFileSystem(); 559 ~OFileViewFileSystem();
565 560
566 QString selectedName() const; 561 QString selectedName() const;
567 QString selectedPath() const; 562 QString selectedPath() const;
568 563
569 QString directory()const; 564 QString directory()const;
570 void reread(); 565 void reread();
571 int fileCount()const; 566 int fileCount()const;
572 567
573 QWidget* widget( QWidget* parent ); 568 QWidget* widget( QWidget* parent );
574 void activate( const QString& ); 569 void activate( const QString& );
575private: 570private:
576 OFileViewFileListView* m_view; 571 OFileViewFileListView* m_view;
577 bool m_all : 1; 572 bool m_all : 1;
578}; 573};
579OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) 574OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
580 : OFileViewInterface( sel ) { 575 : OFileViewInterface( sel ) {
581 m_view = 0; 576 m_view = 0;
582 m_all = false; 577 m_all = false;
583} 578}
584OFileViewFileSystem::~OFileViewFileSystem() { 579OFileViewFileSystem::~OFileViewFileSystem() {
585} 580}
586QString OFileViewFileSystem::selectedName()const{ 581QString OFileViewFileSystem::selectedName()const{
587 if (!m_view ) 582 if (!m_view )
588 return QString::null; 583 return QString::null;
589 584
590 QString cFN=currentFileName(); 585 QString cFN=currentFileName();
591 if (cFN.startsWith("/")) return cFN; 586 if (cFN.startsWith("/")) return cFN;
592 return m_view->currentDir() + "/" + cFN; 587 return m_view->currentDir() + "/" + cFN;
593} 588}
594QString OFileViewFileSystem::selectedPath()const{ 589QString OFileViewFileSystem::selectedPath()const{
595 return QString::null; 590 return QString::null;
596} 591}
597QString OFileViewFileSystem::directory()const{ 592QString OFileViewFileSystem::directory()const{
598 if (!m_view) 593 if (!m_view)
599 return QString::null; 594 return QString::null;
600 595
601 OFileSelectorItem* item = m_view->currentItem(); 596 OFileSelectorItem* item = m_view->currentItem();
602 if (!item ) 597 if (!item )
603 return QString::null; 598 return QString::null;
604 599
605 return QDir(item->directory() ).absPath(); 600 return QDir(item->directory() ).absPath();
606} 601}
607void OFileViewFileSystem::reread() { 602void OFileViewFileSystem::reread() {
608 if (!m_view) 603 if (!m_view)
609 return; 604 return;
610 605
611 m_view->reread( m_all ); 606 m_view->reread( m_all );
612} 607}
613int OFileViewFileSystem::fileCount()const{ 608int OFileViewFileSystem::fileCount()const{
614 if (!m_view ) 609 if (!m_view )
615 return -1; 610 return -1;
616 return m_view->fileCount(); 611 return m_view->fileCount();
617} 612}
618QWidget* OFileViewFileSystem::widget( QWidget* parent ) { 613QWidget* OFileViewFileSystem::widget( QWidget* parent ) {
619 if (!m_view ) { 614 if (!m_view ) {
620 m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); 615 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
621 } 616 }
622 return m_view; 617 return m_view;
623} 618}
624void OFileViewFileSystem::activate( const QString& str) { 619void OFileViewFileSystem::activate( const QString& str) {
625 m_all = (str != QObject::tr("Files") ); 620 m_all = (str != QObject::tr("Files") );
626 621
627 622
628} 623}
629 624
630/* Selector */ 625/* Selector */
631/** 626/**
632 * @short new and complete c'tor 627 * @short new and complete c'tor
633 * 628 *
634 * Create a OFileSelector to let the user select a file. It can 629 * Create a OFileSelector to let the user select a file. It can
635 * either be used to open a file, select a save name in a dir or 630 * either be used to open a file, select a save name in a dir or
636 * as a dropin for the FileSelector. 631 * as a dropin for the FileSelector.
637 * 632 *
638 * <pre> 633 * <pre>
639 * QMap<QString, QStringList> mimeTypes; 634 * QMap<QString, QStringList> mimeTypes;
640 * QStringList types; 635 * QStringList types;
641 * types << "text@slash* "; 636 * types << "text@slash* ";
642 * types << "audio@slash*"; 637 * types << "audio@slash*";
643 * mimeTypes.insert( tr("Audio and Text"), types ); 638 * mimeTypes.insert( tr("Audio and Text"), types );
644 * mimeTypes.insert( tr("All"), "*@slash*); 639 * mimeTypes.insert( tr("All"), "*@slash*);
645 * 640 *
646 * now you could create your fileselector 641 * now you could create your fileselector
647 * </pre> 642 * </pre>
648 * 643 *
649 * 644 *
650 * @param parent the parent of this widget 645 * @param parent the parent of this widget
651 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) 646 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR)
652 * @param sel The selector to be used 647 * @param sel The selector to be used
653 * @param dirName The name of the dir to start int 648 * @param dirName The name of the dir to start int
654 * @param fileName The fileName placed in the fileselector lineedit 649 * @param fileName The fileName placed in the fileselector lineedit
655 * @param mimetypes The MimeType map of used mimetypes 650 * @param mimetypes The MimeType map of used mimetypes
656 * @param showNew Show a New Button. Most likely to be used in the FileSelector view. 651 * @param showNew Show a New Button. Most likely to be used in the FileSelector view.
657 * @param showClose Show a Close Button. Most likely to be used in FileSelector view. 652 * @param showClose Show a Close Button. Most likely to be used in FileSelector view.
658 * 653 *
659 */ 654 */
660OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, 655OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
661 const QString& dirName, const QString& fileName, 656 const QString& dirName, const QString& fileName,
662 const MimeTypes& mimetypes, 657 const MimeTypes& mimetypes,
663 bool showNew, bool showClose) 658 bool showNew, bool showClose)
664 : QWidget( parent, "OFileSelector" ) 659 : QWidget( parent, "OFileSelector" )
665{ 660{
666 m_current = 0; 661 m_current = 0;
667 m_shNew = showNew; 662 m_shNew = showNew;
668 m_shClose = showClose; 663 m_shClose = showClose;
669 m_mimeType = mimetypes; 664 m_mimeType = mimetypes;
670 m_startDir = dirName; 665 m_startDir = dirName;
671 666
672 m_mode = mode; 667 m_mode = mode;
673 m_selector = sel; 668 m_selector = sel;
674 669
675 initUI(); 670 initUI();
676 m_lneEdit->setText( fileName ); 671 m_lneEdit->setText( fileName );
677 initMime(); 672 initMime();
678 initViews(); 673 initViews();
679 674
680 QString str; 675 QString str;
681 switch ( m_selector ) { 676 switch ( m_selector ) {
682 default: 677 default:
683 case Normal: 678 case Normal:
684 str = QObject::tr("Documents"); 679 str = QObject::tr("Documents");
685 m_cmbView->setCurrentItem( 0 ); 680 m_cmbView->setCurrentItem( 0 );
686 break; 681 break;
687 case Extended: 682 case Extended:
688 str = QObject::tr("Files"); 683 str = QObject::tr("Files");
689 m_cmbView->setCurrentItem( 1 ); 684 m_cmbView->setCurrentItem( 1 );
690 break; 685 break;
691 case ExtendedAll: 686 case ExtendedAll:
692 str = QObject::tr("All Files"); 687 str = QObject::tr("All Files");
693 m_cmbView->setCurrentItem( 2 ); 688 m_cmbView->setCurrentItem( 2 );
694 break; 689 break;
695 } 690 }
696 slotViewChange( str ); 691 slotViewChange( str );
697 692
698} 693}
699 694
700/** 695/**
701 * This a convience c'tor to just substitute the use of FileSelector 696 * This a convience c'tor to just substitute the use of FileSelector
702 */ 697 */
703OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, 698OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
704 bool showNew, bool showClose ) 699 bool showNew, bool showClose )
705 : QWidget( parent, name ) 700 : QWidget( parent, name )
706{ 701{
707 m_current = 0; 702 m_current = 0;
708 m_shNew = showNew; 703 m_shNew = showNew;
709 m_shClose = showClose; 704 m_shClose = showClose;
710 m_startDir = QPEApplication::documentDir(); 705 m_startDir = QPEApplication::documentDir();
711 706
712 if (!mimeFilter.isEmpty() ) 707 if (!mimeFilter.isEmpty() )
713 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); 708 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
714 709
715 m_mode = OFileSelector::FileSelector; 710 m_mode = OFileSelector::FileSelector;
716 m_selector = OFileSelector::Normal; 711 m_selector = OFileSelector::Normal;
717 712
718 initUI(); 713 initUI();
719 initMime(); 714 initMime();
720 initViews(); 715 initViews();
721 m_cmbView->setCurrentItem( 0 ); 716 m_cmbView->setCurrentItem( 0 );
722 slotViewChange( QObject::tr("Documents") ); 717 slotViewChange( QObject::tr("Documents") );
723} 718}
724/* 719/*
725 * INIT UI will set up the basic GUI 720 * INIT UI will set up the basic GUI
726 * Layout: Simple VBoxLayout 721 * Layout: Simple VBoxLayout
727 * On top a WidgetStack containing the Views... 722 * On top a WidgetStack containing the Views...
728 * - List View 723 * - List View
729 * - Document View 724 * - Document View
730 * Below we will have a Label + LineEdit 725 * Below we will have a Label + LineEdit
731 * Below we will have two ComoBoxes one for choosing the view one for 726 * Below we will have two ComoBoxes one for choosing the view one for
732 * choosing the mimetype 727 * choosing the mimetype
733 */ 728 */
734void OFileSelector::initUI() { 729void OFileSelector::initUI() {
735 QVBoxLayout* lay = new QVBoxLayout( this ); 730 QVBoxLayout* lay = new QVBoxLayout( this );
736 731
737 m_stack = new QWidgetStack( this ); 732 m_stack = new QWidgetStack( this );
738 lay->addWidget( m_stack, 1000 ); 733 lay->addWidget( m_stack, 1000 );
739 734
740 m_nameBox = new QHBox( this ); 735 m_nameBox = new QHBox( this );
741 (void)new QLabel( tr("Name:"), m_nameBox ); 736 (void)new QLabel( tr("Name:"), m_nameBox );
742 m_lneEdit = new QLineEdit( m_nameBox ); 737 m_lneEdit = new QLineEdit( m_nameBox );
743 m_lneEdit ->installEventFilter(this); 738 m_lneEdit ->installEventFilter(this);
744 lay->addWidget( m_nameBox ); 739 lay->addWidget( m_nameBox );
745 740
746 m_cmbBox = new QHBox( this ); 741 m_cmbBox = new QHBox( this );
747 m_cmbView = new QComboBox( m_cmbBox ); 742 m_cmbView = new QComboBox( m_cmbBox );
748 m_cmbMime = new QComboBox( m_cmbBox ); 743 m_cmbMime = new QComboBox( m_cmbBox );
749 lay->addWidget( m_cmbBox ); 744 lay->addWidget( m_cmbBox );
750} 745}
751 746
752/* 747/*
753 * This will make sure that the return key in the name edit causes dialogs to close 748 * This will make sure that the return key in the name edit causes dialogs to close
754 */ 749 */
755 750
756bool OFileSelector::eventFilter (QObject *o, QEvent *e) { 751bool OFileSelector::eventFilter (QObject *o, QEvent *e) {
757 if ( e->type() == QEvent::KeyPress ) { 752 if ( e->type() == QEvent::KeyPress ) {
758 QKeyEvent *k = (QKeyEvent *)e; 753 QKeyEvent *k = (QKeyEvent *)e;
759 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { 754 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
760 emit ok(); 755 emit ok();
761 return true; 756 return true;
762 } 757 }
763 } 758 }
764 return false; 759 return false;
765} 760}
766 761
767/* 762/*
768 * This will insert the MimeTypes into the Combo Box 763 * This will insert the MimeTypes into the Combo Box
769 * And also connect the changed signal 764 * And also connect the changed signal
770 * 765 *
771 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes 766 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
772 */ 767 */
773void OFileSelector::initMime() { 768void OFileSelector::initMime() {
774 MimeTypes::Iterator it; 769 MimeTypes::Iterator it;
775 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { 770 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) {
776 m_cmbMime->insertItem( it.key() ); 771 m_cmbMime->insertItem( it.key() );
777 } 772 }
778 m_cmbMime->setCurrentItem( 0 ); 773 m_cmbMime->setCurrentItem( 0 );
779 774
780 connect( m_cmbMime, SIGNAL(activated(int) ), 775 connect( m_cmbMime, SIGNAL(activated(int) ),
781 this, SLOT(slotMimeTypeChanged() ) ); 776 this, SLOT(slotMimeTypeChanged() ) );
782 777
783} 778}
784void OFileSelector::initViews() { 779void OFileSelector::initViews() {
785 m_cmbView->insertItem( QObject::tr("Documents") ); 780 m_cmbView->insertItem( QObject::tr("Documents") );
786 m_cmbView->insertItem( QObject::tr("Files") ); 781 m_cmbView->insertItem( QObject::tr("Files") );
787 m_cmbView->insertItem( QObject::tr("All Files") ); 782 m_cmbView->insertItem( QObject::tr("All Files") );
788 connect(m_cmbView, SIGNAL(activated( const QString& ) ), 783 connect(m_cmbView, SIGNAL(activated( const QString& ) ),
789 this, SLOT(slotViewChange( const QString& ) ) ); 784 this, SLOT(slotViewChange( const QString& ) ) );
790 785
791 786
792 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); 787 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
793 788
794 /* see above why add both */ 789 /* see above why add both */
795 OFileViewInterface* in = new OFileViewFileSystem( this ); 790 OFileViewInterface* in = new OFileViewFileSystem( this );
796 m_views.insert( QObject::tr("Files"), in ); 791 m_views.insert( QObject::tr("Files"), in );
797 m_views.insert( QObject::tr("All Files"), in ); 792 m_views.insert( QObject::tr("All Files"), in );
798} 793}
799 794
800/** 795/**
801 * d'tor 796 * d'tor
802 */ 797 */
803OFileSelector::~OFileSelector() { 798OFileSelector::~OFileSelector() {
804 799
805} 800}
806 801
807/** 802/**
808 * Convience function for the fileselector 803 * Convience function for the fileselector
809 * make sure to delete the DocLnk 804 * make sure to delete the DocLnk
810 * 805 *
811 * @see DocLnk 806 * @see DocLnk
812 * @todo remove in ODP 807 * @todo remove in ODP
813 */ 808 */
814const DocLnk* OFileSelector::selected() { 809const DocLnk* OFileSelector::selected() {
815 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); 810 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
816 return lnk; 811 return lnk;
817} 812}
818 813
819/** 814/**
820 * 815 *
821 * @return the name of the selected file 816 * @return the name of the selected file
822 */ 817 */
823QString OFileSelector::selectedName()const{ 818QString OFileSelector::selectedName()const{
824 return currentView()->selectedName(); 819 return currentView()->selectedName();
825} 820}
826 821
827/** 822/**
828 * @return the selected path 823 * @return the selected path
829 */ 824 */
830QString OFileSelector::selectedPath()const { 825QString OFileSelector::selectedPath()const {
831 return currentView()->selectedPath(); 826 return currentView()->selectedPath();
832} 827}
833 828
834/** 829/**
835 * @return the directory name 830 * @return the directory name
836 */ 831 */
837QString OFileSelector::directory()const { 832QString OFileSelector::directory()const {
838 return currentView()->directory(); 833 return currentView()->directory();
839} 834}
840 835
841/** 836/**
842 * @return a DocLnk for the selected document 837 * @return a DocLnk for the selected document
843 */ 838 */
844DocLnk OFileSelector::selectedDocument()const { 839DocLnk OFileSelector::selectedDocument()const {
845 return currentView()->selectedDocument(); 840 return currentView()->selectedDocument();
846} 841}
847 842
848/** 843/**
849 * @return the number of items for the current view 844 * @return the number of items for the current view
850 */ 845 */
851int OFileSelector::fileCount()const { 846int OFileSelector::fileCount()const {
852 return currentView()->fileCount(); 847 return currentView()->fileCount();
853} 848}
854 849
855/** 850/**
856 * @return reparse the file content 851 * @return reparse the file content
857 */ 852 */
858void OFileSelector::reread() { 853void OFileSelector::reread() {
859 return currentView()->reread(); 854 return currentView()->reread();
860} 855}
861OFileViewInterface* OFileSelector::currentView()const{ 856OFileViewInterface* OFileSelector::currentView()const{
862 return m_current; 857 return m_current;
863} 858}
864bool OFileSelector::showNew()const { 859bool OFileSelector::showNew()const {
865 return m_shNew; 860 return m_shNew;
866} 861}
867bool OFileSelector::showClose()const { 862bool OFileSelector::showClose()const {
868 return m_shClose; 863 return m_shClose;
869} 864}
870MimeTypes OFileSelector::mimeTypes()const { 865MimeTypes OFileSelector::mimeTypes()const {
871 return m_mimeType; 866 return m_mimeType;
872} 867}
873 868
874/** 869/**
875 * @return the Mode of the OFileSelector 870 * @return the Mode of the OFileSelector
876 */ 871 */
877int OFileSelector::mode()const{ 872int OFileSelector::mode()const{
878 return m_mode; 873 return m_mode;
879} 874}
880 875
881/** 876/**
882 * @return the Selector of the OFileSelector 877 * @return the Selector of the OFileSelector
883 */ 878 */
884int OFileSelector::selector()const{ 879int OFileSelector::selector()const{
885 return m_selector; 880 return m_selector;
886} 881}
887QStringList OFileSelector::currentMimeType()const { 882QStringList OFileSelector::currentMimeType()const {
888 return m_mimeType[m_cmbMime->currentText()]; 883 return m_mimeType[m_cmbMime->currentText()];
889} 884}
890void OFileSelector::slotMimeTypeChanged() { 885void OFileSelector::slotMimeTypeChanged() {
891 reread(); 886 reread();
892} 887}
893void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { 888void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) {
894 m_lneEdit->setText( lnk.name() ); 889 m_lneEdit->setText( lnk.name() );
895 emit fileSelected( lnk ); 890 emit fileSelected( lnk );
896 emit fileSelected( lnk.name() ); 891 emit fileSelected( lnk.name() );
897} 892}
898void OFileSelector::slotFileBridge( const QString& str) { 893void OFileSelector::slotFileBridge( const QString& str) {
899 DocLnk lnk( str ); 894 DocLnk lnk( str );
900 emit fileSelected( lnk ); 895 emit fileSelected( lnk );
901} 896}
902void OFileSelector::slotViewChange( const QString& view ) { 897void OFileSelector::slotViewChange( const QString& view ) {
903 OFileViewInterface* interface = m_views[view]; 898 OFileViewInterface* interface = m_views[view];
904 if (!interface) 899 if (!interface)
905 return; 900 return;
906 901
907 interface->activate( view ); 902 interface->activate( view );
908 if (m_current) 903 if (m_current)
909 m_stack->removeWidget( m_current->widget( m_stack ) ); 904 m_stack->removeWidget( m_current->widget( m_stack ) );
910 905
911 static int id = 1; 906 static int id = 1;
912 907
913 m_stack->addWidget( interface->widget(m_stack), id ); 908 m_stack->addWidget( interface->widget(m_stack), id );
914 m_stack->raiseWidget( id ); 909 m_stack->raiseWidget( id );
915 910
916 interface->reread(); 911 interface->reread();
917 m_current = interface; 912 m_current = interface;
918 913
919 id++; 914 id++;
920} 915}
921void OFileSelector::setNewVisible( bool b ) { 916void OFileSelector::setNewVisible( bool b ) {
922 m_shNew = b; 917 m_shNew = b;
923 currentView()->reread(); 918 currentView()->reread();
924} 919}
925void OFileSelector::setCloseVisible( bool b ) { 920void OFileSelector::setCloseVisible( bool b ) {
926 m_shClose = b; 921 m_shClose = b;
927 currentView()->reread(); 922 currentView()->reread();
928} 923}
929void OFileSelector::setNameVisible( bool b ) { 924void OFileSelector::setNameVisible( bool b ) {
930 if ( b ) 925 if ( b )
931 m_nameBox->show(); 926 m_nameBox->show();
932 else 927 else
933 m_nameBox->hide(); 928 m_nameBox->hide();
934} 929}
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,926 +1,925 @@
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
441 440
442 441
443bool OProcess::isRunning() const 442bool OProcess::isRunning() const
444{ 443{
445 return runs; 444 return runs;
446} 445}
447 446
448 447
449 448
450pid_t OProcess::pid() const 449pid_t OProcess::pid() const
451{ 450{
452 return pid_; 451 return pid_;
453} 452}
454 453
455 454
456 455
457bool OProcess::normalExit() const 456bool OProcess::normalExit() const
458{ 457{
459 int _status = status; 458 int _status = status;
460 return (pid_ != 0) && (!runs) && (WIFEXITED((_status))); 459 return (pid_ != 0) && (!runs) && (WIFEXITED((_status)));
461} 460}
462 461
463 462
464 463
465int OProcess::exitStatus() const 464int OProcess::exitStatus() const
466{ 465{
467 int _status = status; 466 int _status = status;
468 return WEXITSTATUS((_status)); 467 return WEXITSTATUS((_status));
469} 468}
470 469
471 470
472 471
473bool OProcess::writeStdin(const char *buffer, int buflen) 472bool OProcess::writeStdin(const char *buffer, int buflen)
474{ 473{
475 bool rv; 474 bool rv;
476 475
477 // if there is still data pending, writing new data 476 // if there is still data pending, writing new data
478 // to stdout is not allowed (since it could also confuse 477 // to stdout is not allowed (since it could also confuse
479 // kprocess... 478 // kprocess...
480 if (0 != input_data) 479 if (0 != input_data)
481 return false; 480 return false;
482 481
483 if (runs && (communication & Stdin)) { 482 if (runs && (communication & Stdin)) {
484 input_data = buffer; 483 input_data = buffer;
485 input_sent = 0; 484 input_sent = 0;
486 input_total = buflen; 485 input_total = buflen;
487 slotSendData(0); 486 slotSendData(0);
488 innot->setEnabled(true); 487 innot->setEnabled(true);
489 rv = true; 488 rv = true;
490 } else 489 } else
491 rv = false; 490 rv = false;
492 return rv; 491 return rv;
493} 492}
494 493
495void OProcess::flushStdin ( ) 494void OProcess::flushStdin ( )
496{ 495{
497 if ( !input_data || ( input_sent == input_total )) 496 if ( !input_data || ( input_sent == input_total ))
498 return; 497 return;
499 498
500 int d1, d2; 499 int d1, d2;
501 500
502 do { 501 do {
503 d1 = input_total - input_sent; 502 d1 = input_total - input_sent;
504 slotSendData ( 0 ); 503 slotSendData ( 0 );
505 d2 = input_total - input_sent; 504 d2 = input_total - input_sent;
506 } while ( d2 <= d1 ); 505 } while ( d2 <= d1 );
507} 506}
508 507
509void OProcess::suspend() 508void OProcess::suspend()
510{ 509{
511 if ((communication & Stdout) && outnot) 510 if ((communication & Stdout) && outnot)
512 outnot->setEnabled(false); 511 outnot->setEnabled(false);
513} 512}
514 513
515void OProcess::resume() 514void OProcess::resume()
516{ 515{
517 if ((communication & Stdout) && outnot) 516 if ((communication & Stdout) && outnot)
518 outnot->setEnabled(true); 517 outnot->setEnabled(true);
519} 518}
520 519
521bool OProcess::closeStdin() 520bool OProcess::closeStdin()
522{ 521{
523 bool rv; 522 bool rv;
524 523
525 if (communication & Stdin) { 524 if (communication & Stdin) {
526 communication = (Communication) (communication & ~Stdin); 525 communication = (Communication) (communication & ~Stdin);
527 delete innot; 526 delete innot;
528 innot = 0; 527 innot = 0;
529 close(in[1]); 528 close(in[1]);
530 rv = true; 529 rv = true;
531 } else 530 } else
532 rv = false; 531 rv = false;
533 return rv; 532 return rv;
534} 533}
535 534
536bool OProcess::closeStdout() 535bool OProcess::closeStdout()
537{ 536{
538 bool rv; 537 bool rv;
539 538
540 if (communication & Stdout) { 539 if (communication & Stdout) {
541 communication = (Communication) (communication & ~Stdout); 540 communication = (Communication) (communication & ~Stdout);
542 delete outnot; 541 delete outnot;
543 outnot = 0; 542 outnot = 0;
544 close(out[0]); 543 close(out[0]);
545 rv = true; 544 rv = true;
546 } else 545 } else
547 rv = false; 546 rv = false;
548 return rv; 547 return rv;
549} 548}
550 549
551bool OProcess::closeStderr() 550bool OProcess::closeStderr()
552{ 551{
553 bool rv; 552 bool rv;
554 553
555 if (communication & Stderr) { 554 if (communication & Stderr) {
556 communication = static_cast<Communication>(communication & ~Stderr); 555 communication = static_cast<Communication>(communication & ~Stderr);
557 delete errnot; 556 delete errnot;
558 errnot = 0; 557 errnot = 0;
559 close(err[0]); 558 close(err[0]);
560 rv = true; 559 rv = true;
561 } else 560 } else
562 rv = false; 561 rv = false;
563 return rv; 562 return rv;
564} 563}
565 564
566 565
567///////////////////////////// 566/////////////////////////////
568// protected slots // 567// protected slots //
569///////////////////////////// 568/////////////////////////////
570 569
571 570
572 571
573void OProcess::slotChildOutput(int fdno) 572void OProcess::slotChildOutput(int fdno)
574{ 573{
575 if (!childOutput(fdno)) 574 if (!childOutput(fdno))
576 closeStdout(); 575 closeStdout();
577} 576}
578 577
579 578
580void OProcess::slotChildError(int fdno) 579void OProcess::slotChildError(int fdno)
581{ 580{
582 if (!childError(fdno)) 581 if (!childError(fdno))
583 closeStderr(); 582 closeStderr();
584} 583}
585 584
586 585
587void OProcess::slotSendData(int) 586void OProcess::slotSendData(int)
588{ 587{
589 if (input_sent == input_total) { 588 if (input_sent == input_total) {
590 innot->setEnabled(false); 589 innot->setEnabled(false);
591 input_data = 0; 590 input_data = 0;
592 emit wroteStdin(this); 591 emit wroteStdin(this);
593 } else 592 } else
594 input_sent += ::write(in[1], input_data+input_sent, input_total-input_sent); 593 input_sent += ::write(in[1], input_data+input_sent, input_total-input_sent);
595} 594}
596 595
597 596
598 597
599////////////////////////////// 598//////////////////////////////
600// private member functions // 599// private member functions //
601////////////////////////////// 600//////////////////////////////
602 601
603 602
604 603
605void OProcess::processHasExited(int state) 604void OProcess::processHasExited(int state)
606{ 605{
607 if (runs) 606 if (runs)
608 { 607 {
609 runs = false; 608 runs = false;
610 status = state; 609 status = state;
611 610
612 commClose(); // cleanup communication sockets 611 commClose(); // cleanup communication sockets
613 612
614 // also emit a signal if the process was run Blocking 613 // also emit a signal if the process was run Blocking
615 if (DontCare != run_mode) 614 if (DontCare != run_mode)
616 { 615 {
617 emit processExited(this); 616 emit processExited(this);
618 } 617 }
619 } 618 }
620} 619}
621 620
622 621
623 622
624int OProcess::childOutput(int fdno) 623int OProcess::childOutput(int fdno)
625{ 624{
626 if (communication & NoRead) { 625 if (communication & NoRead) {
627 int len = -1; 626 int len = -1;
628 emit receivedStdout(fdno, len); 627 emit receivedStdout(fdno, len);
629 errno = 0; // Make sure errno doesn't read "EAGAIN" 628 errno = 0; // Make sure errno doesn't read "EAGAIN"
630 return len; 629 return len;
631 } 630 }
632 else 631 else
633 { 632 {
634 char buffer[1024]; 633 char buffer[1024];
635 int len; 634 int len;
636 635
637 len = ::read(fdno, buffer, 1024); 636 len = ::read(fdno, buffer, 1024);
638 637
639 if ( 0 < len) { 638 if ( 0 < len) {
640 emit receivedStdout(this, buffer, len); 639 emit receivedStdout(this, buffer, len);
641 } 640 }
642 return len; 641 return len;
643 } 642 }
644} 643}
645 644
646 645
647 646
648int OProcess::childError(int fdno) 647int OProcess::childError(int fdno)
649{ 648{
650 char buffer[1024]; 649 char buffer[1024];
651 int len; 650 int len;
652 651
653 len = ::read(fdno, buffer, 1024); 652 len = ::read(fdno, buffer, 1024);
654 653
655 if ( 0 < len) 654 if ( 0 < len)
656 emit receivedStderr(this, buffer, len); 655 emit receivedStderr(this, buffer, len);
657 return len; 656 return len;
658} 657}
659 658
660 659
661 660
662int OProcess::setupCommunication(Communication comm) 661int OProcess::setupCommunication(Communication comm)
663{ 662{
664 int ok; 663 int ok;
665 664
666 communication = comm; 665 communication = comm;
667 666
668 ok = 1; 667 ok = 1;
669 if (comm & Stdin) 668 if (comm & Stdin)
670 ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, in) >= 0; 669 ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, in) >= 0;
671 670
672 if (comm & Stdout) 671 if (comm & Stdout)
673 ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, out) >= 0; 672 ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, out) >= 0;
674 673
675 if (comm & Stderr) 674 if (comm & Stderr)
676 ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, err) >= 0; 675 ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, err) >= 0;
677 676
678 return ok; 677 return ok;
679} 678}
680 679
681 680
682 681
683int OProcess::commSetupDoneP() 682int OProcess::commSetupDoneP()
684{ 683{
685 int ok = 1; 684 int ok = 1;
686 685
687 if (communication != NoCommunication) { 686 if (communication != NoCommunication) {
688 if (communication & Stdin) 687 if (communication & Stdin)
689 close(in[0]); 688 close(in[0]);
690 if (communication & Stdout) 689 if (communication & Stdout)
691 close(out[1]); 690 close(out[1]);
692 if (communication & Stderr) 691 if (communication & Stderr)
693 close(err[1]); 692 close(err[1]);
694 693
695 // Don't create socket notifiers and set the sockets non-blocking if 694 // Don't create socket notifiers and set the sockets non-blocking if
696 // blocking is requested. 695 // blocking is requested.
697 if (run_mode == Block) return ok; 696 if (run_mode == Block) return ok;
698 697
699 if (communication & Stdin) { 698 if (communication & Stdin) {
700// ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK)); 699// ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK));
701 innot = new QSocketNotifier(in[1], QSocketNotifier::Write, this); 700 innot = new QSocketNotifier(in[1], QSocketNotifier::Write, this);
702 CHECK_PTR(innot); 701 CHECK_PTR(innot);
703 innot->setEnabled(false); // will be enabled when data has to be sent 702 innot->setEnabled(false); // will be enabled when data has to be sent
704 QObject::connect(innot, SIGNAL(activated(int)), 703 QObject::connect(innot, SIGNAL(activated(int)),
705 this, SLOT(slotSendData(int))); 704 this, SLOT(slotSendData(int)));
706 } 705 }
707 706
708 if (communication & Stdout) { 707 if (communication & Stdout) {
709// ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK)); 708// ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK));
710 outnot = new QSocketNotifier(out[0], QSocketNotifier::Read, this); 709 outnot = new QSocketNotifier(out[0], QSocketNotifier::Read, this);
711 CHECK_PTR(outnot); 710 CHECK_PTR(outnot);
712 QObject::connect(outnot, SIGNAL(activated(int)), 711 QObject::connect(outnot, SIGNAL(activated(int)),
713 this, SLOT(slotChildOutput(int))); 712 this, SLOT(slotChildOutput(int)));
714 if (communication & NoRead) 713 if (communication & NoRead)
715 suspend(); 714 suspend();
716 } 715 }
717 716
718 if (communication & Stderr) { 717 if (communication & Stderr) {
719// ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK)); 718// ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK));
720 errnot = new QSocketNotifier(err[0], QSocketNotifier::Read, this ); 719 errnot = new QSocketNotifier(err[0], QSocketNotifier::Read, this );
721 CHECK_PTR(errnot); 720 CHECK_PTR(errnot);
722 QObject::connect(errnot, SIGNAL(activated(int)), 721 QObject::connect(errnot, SIGNAL(activated(int)),
723 this, SLOT(slotChildError(int))); 722 this, SLOT(slotChildError(int)));
724 } 723 }
725 } 724 }
726 return ok; 725 return ok;
727} 726}
728 727
729 728
730 729
731int OProcess::commSetupDoneC() 730int OProcess::commSetupDoneC()
732{ 731{
733 int ok = 1; 732 int ok = 1;
734 struct linger so; 733 struct linger so;
735 memset(&so, 0, sizeof(so)); 734 memset(&so, 0, sizeof(so));
736 735
737 if (communication & Stdin) 736 if (communication & Stdin)
738 close(in[1]); 737 close(in[1]);
739 if (communication & Stdout) 738 if (communication & Stdout)
740 close(out[0]); 739 close(out[0]);
741 if (communication & Stderr) 740 if (communication & Stderr)
742 close(err[0]); 741 close(err[0]);
743 742
744 if (communication & Stdin) 743 if (communication & Stdin)
745 ok &= dup2(in[0], STDIN_FILENO) != -1; 744 ok &= dup2(in[0], STDIN_FILENO) != -1;
746 else { 745 else {
747 int null_fd = open( "/dev/null", O_RDONLY ); 746 int null_fd = open( "/dev/null", O_RDONLY );
748 ok &= dup2( null_fd, STDIN_FILENO ) != -1; 747 ok &= dup2( null_fd, STDIN_FILENO ) != -1;
749 close( null_fd ); 748 close( null_fd );
750 } 749 }
751 if (communication & Stdout) { 750 if (communication & Stdout) {
752 ok &= dup2(out[1], STDOUT_FILENO) != -1; 751 ok &= dup2(out[1], STDOUT_FILENO) != -1;
753 ok &= !setsockopt(out[1], SOL_SOCKET, SO_LINGER, (char*)&so, sizeof(so)); 752 ok &= !setsockopt(out[1], SOL_SOCKET, SO_LINGER, (char*)&so, sizeof(so));
754 } 753 }
755 else { 754 else {
756 int null_fd = open( "/dev/null", O_WRONLY ); 755 int null_fd = open( "/dev/null", O_WRONLY );
757 ok &= dup2( null_fd, STDOUT_FILENO ) != -1; 756 ok &= dup2( null_fd, STDOUT_FILENO ) != -1;
758 close( null_fd ); 757 close( null_fd );
759 } 758 }
760 if (communication & Stderr) { 759 if (communication & Stderr) {
761 ok &= dup2(err[1], STDERR_FILENO) != -1; 760 ok &= dup2(err[1], STDERR_FILENO) != -1;
762 ok &= !setsockopt(err[1], SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>(&so), sizeof(so)); 761 ok &= !setsockopt(err[1], SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>(&so), sizeof(so));
763 } 762 }
764 else { 763 else {
765 int null_fd = open( "/dev/null", O_WRONLY ); 764 int null_fd = open( "/dev/null", O_WRONLY );
766 ok &= dup2( null_fd, STDERR_FILENO ) != -1; 765 ok &= dup2( null_fd, STDERR_FILENO ) != -1;
767 close( null_fd ); 766 close( null_fd );
768 } 767 }
769 return ok; 768 return ok;
770} 769}
771 770
772 771
773 772
774void OProcess::commClose() 773void OProcess::commClose()
775{ 774{
776 if (NoCommunication != communication) { 775 if (NoCommunication != communication) {
777 bool b_in = (communication & Stdin); 776 bool b_in = (communication & Stdin);
778 bool b_out = (communication & Stdout); 777 bool b_out = (communication & Stdout);
779 bool b_err = (communication & Stderr); 778 bool b_err = (communication & Stderr);
780 if (b_in) 779 if (b_in)
781 delete innot; 780 delete innot;
782 781
783 if (b_out || b_err) { 782 if (b_out || b_err) {
784 // If both channels are being read we need to make sure that one socket buffer 783 // If both channels are being read we need to make sure that one socket buffer
785 // doesn't fill up whilst we are waiting for data on the other (causing a deadlock). 784 // doesn't fill up whilst we are waiting for data on the other (causing a deadlock).
786 // Hence we need to use select. 785 // Hence we need to use select.
787 786
788 // Once one or other of the channels has reached EOF (or given an error) go back 787 // Once one or other of the channels has reached EOF (or given an error) go back
789 // to the usual mechanism. 788 // to the usual mechanism.
790 789
791 int fds_ready = 1; 790 int fds_ready = 1;
792 fd_set rfds; 791 fd_set rfds;
793 792
794 int max_fd = 0; 793 int max_fd = 0;
795 if (b_out) { 794 if (b_out) {
796 fcntl(out[0], F_SETFL, O_NONBLOCK); 795 fcntl(out[0], F_SETFL, O_NONBLOCK);
797 if (out[0] > max_fd) 796 if (out[0] > max_fd)
798 max_fd = out[0]; 797 max_fd = out[0];
799 delete outnot; 798 delete outnot;
800 outnot = 0; 799 outnot = 0;
801 } 800 }
802 if (b_err) { 801 if (b_err) {
803 fcntl(err[0], F_SETFL, O_NONBLOCK); 802 fcntl(err[0], F_SETFL, O_NONBLOCK);
804 if (err[0] > max_fd) 803 if (err[0] > max_fd)
805 max_fd = err[0]; 804 max_fd = err[0];
806 delete errnot; 805 delete errnot;
807 errnot = 0; 806 errnot = 0;
808 } 807 }
809 808
810 809
811 while (b_out || b_err) { 810 while (b_out || b_err) {
812 // * If the process is still running we block until we 811 // * If the process is still running we block until we
813 // receive data. (p_timeout = 0, no timeout) 812 // receive data. (p_timeout = 0, no timeout)
814 // * If the process has already exited, we only check 813 // * If the process has already exited, we only check
815 // the available data, we don't wait for more. 814 // the available data, we don't wait for more.
816 // (p_timeout = &timeout, timeout immediately) 815 // (p_timeout = &timeout, timeout immediately)
817 struct timeval timeout; 816 struct timeval timeout;
818 timeout.tv_sec = 0; 817 timeout.tv_sec = 0;
819 timeout.tv_usec = 0; 818 timeout.tv_usec = 0;
820 struct timeval *p_timeout = runs ? 0 : &timeout; 819 struct timeval *p_timeout = runs ? 0 : &timeout;
821 820
822 FD_ZERO(&rfds); 821 FD_ZERO(&rfds);
823 if (b_out) 822 if (b_out)
824 FD_SET(out[0], &rfds); 823 FD_SET(out[0], &rfds);
825 824
826 if (b_err) 825 if (b_err)
827 FD_SET(err[0], &rfds); 826 FD_SET(err[0], &rfds);
828 827
829 fds_ready = select(max_fd+1, &rfds, 0, 0, p_timeout); 828 fds_ready = select(max_fd+1, &rfds, 0, 0, p_timeout);
830 if (fds_ready <= 0) break; 829 if (fds_ready <= 0) break;
831 830
832 if (b_out && FD_ISSET(out[0], &rfds)) { 831 if (b_out && FD_ISSET(out[0], &rfds)) {
833 int ret = 1; 832 int ret = 1;
834 while (ret > 0) ret = childOutput(out[0]); 833 while (ret > 0) ret = childOutput(out[0]);
835 if ((ret == -1 && errno != EAGAIN) || ret == 0) 834 if ((ret == -1 && errno != EAGAIN) || ret == 0)
836 b_out = false; 835 b_out = false;
837 } 836 }
838 837
839 if (b_err && FD_ISSET(err[0], &rfds)) { 838 if (b_err && FD_ISSET(err[0], &rfds)) {
840 int ret = 1; 839 int ret = 1;
841 while (ret > 0) ret = childError(err[0]); 840 while (ret > 0) ret = childError(err[0]);
842 if ((ret == -1 && errno != EAGAIN) || ret == 0) 841 if ((ret == -1 && errno != EAGAIN) || ret == 0)
843 b_err = false; 842 b_err = false;
844 } 843 }
845 } 844 }
846 } 845 }
847 846
848 if (b_in) { 847 if (b_in) {
849 communication = (Communication) (communication & ~Stdin); 848 communication = (Communication) (communication & ~Stdin);
850 close(in[1]); 849 close(in[1]);
851 } 850 }
852 if (b_out) { 851 if (b_out) {
853 communication = (Communication) (communication & ~Stdout); 852 communication = (Communication) (communication & ~Stdout);
854 close(out[0]); 853 close(out[0]);
855 } 854 }
856 if (b_err) { 855 if (b_err) {
857 communication = (Communication) (communication & ~Stderr); 856 communication = (Communication) (communication & ~Stderr);
858 close(err[0]); 857 close(err[0]);
859 } 858 }
860 } 859 }
861} 860}
862 861
863void OProcess::setUseShell(bool useShell, const char *shell) 862void OProcess::setUseShell(bool useShell, const char *shell)
864{ 863{
865 if (!d) 864 if (!d)
866 d = new OProcessPrivate; 865 d = new OProcessPrivate;
867 d->useShell = useShell; 866 d->useShell = useShell;
868 d->shell = shell; 867 d->shell = shell;
869 if (d->shell.isEmpty()) 868 if (d->shell.isEmpty())
870 d->shell = searchShell(); 869 d->shell = searchShell();
871} 870}
872 871
873QString OProcess::quote(const QString &arg) 872QString OProcess::quote(const QString &arg)
874{ 873{
875 QString res = arg; 874 QString res = arg;
876 res.replace(QRegExp(QString::fromLatin1("\'")), 875 res.replace(QRegExp(QString::fromLatin1("\'")),
877 QString::fromLatin1("'\"'\"'")); 876 QString::fromLatin1("'\"'\"'"));
878 res.prepend('\''); 877 res.prepend('\'');
879 res.append('\''); 878 res.append('\'');
880 return res; 879 return res;
881} 880}
882 881
883QCString OProcess::searchShell() 882QCString OProcess::searchShell()
884{ 883{
885 QCString tmpShell = QCString(getenv("SHELL")).stripWhiteSpace(); 884 QCString tmpShell = QCString(getenv("SHELL")).stripWhiteSpace();
886 if (!isExecutable(tmpShell)) 885 if (!isExecutable(tmpShell))
887 { 886 {
888 tmpShell = "/bin/sh"; 887 tmpShell = "/bin/sh";
889 } 888 }
890 889
891 return tmpShell; 890 return tmpShell;
892} 891}
893 892
894bool OProcess::isExecutable(const QCString &filename) 893bool OProcess::isExecutable(const QCString &filename)
895{ 894{
896 struct stat fileinfo; 895 struct stat fileinfo;
897 896
898 if (filename.isEmpty()) return false; 897 if (filename.isEmpty()) return false;
899 898
900 // CC: we've got a valid filename, now let's see whether we can execute that file 899 // CC: we've got a valid filename, now let's see whether we can execute that file
901 900
902 if (-1 == stat(filename.data(), &fileinfo)) return false; 901 if (-1 == stat(filename.data(), &fileinfo)) return false;
903 // CC: return false if the file does not exist 902 // CC: return false if the file does not exist
904 903
905 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets 904 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets
906 if ( (S_ISDIR(fileinfo.st_mode)) || 905 if ( (S_ISDIR(fileinfo.st_mode)) ||
907 (S_ISCHR(fileinfo.st_mode)) || 906 (S_ISCHR(fileinfo.st_mode)) ||
908 (S_ISBLK(fileinfo.st_mode)) || 907 (S_ISBLK(fileinfo.st_mode)) ||
909#ifdef S_ISSOCK 908#ifdef S_ISSOCK
910 // CC: SYSVR4 systems don't have that macro 909 // CC: SYSVR4 systems don't have that macro
911 (S_ISSOCK(fileinfo.st_mode)) || 910 (S_ISSOCK(fileinfo.st_mode)) ||
912#endif 911#endif
913 (S_ISFIFO(fileinfo.st_mode)) || 912 (S_ISFIFO(fileinfo.st_mode)) ||
914 (S_ISDIR(fileinfo.st_mode)) ) { 913 (S_ISDIR(fileinfo.st_mode)) ) {
915 return false; 914 return false;
916 } 915 }
917 916
918 // CC: now check for permission to execute the file 917 // CC: now check for permission to execute the file
919 if (access(filename.data(), X_OK) != 0) return false; 918 if (access(filename.data(), X_OK) != 0) return false;
920 919
921 // CC: we've passed all the tests... 920 // CC: we've passed all the tests...
922 return true; 921 return true;
923} 922}
924 923
925 924
926 925
diff --git a/libopie/orecurrancewidget.cpp b/libopie/orecurrancewidget.cpp
index be8ec30..d81851e 100644
--- a/libopie/orecurrancewidget.cpp
+++ b/libopie/orecurrancewidget.cpp
@@ -1,634 +1,632 @@
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 }
391 str = str.prepend( tr("on ") ); 389 str = str.prepend( tr("on ") );
392 390
393 lblWeekVar->setText( str ); 391 lblWeekVar->setText( str );
394} 392}
395void ORecurranceWidget::slotMonthLabel(int type) { 393void ORecurranceWidget::slotMonthLabel(int type) {
396 QString str; 394 QString str;
397 if ( currInterval != Month || type > 1 ) 395 if ( currInterval != Month || type > 1 )
398 return; 396 return;
399 if ( type == 1 ) 397 if ( type == 1 )
400 str = strMonthDateTemplate.arg( numberPlacing(start.day()) ); 398 str = strMonthDateTemplate.arg( numberPlacing(start.day()) );
401 else 399 else
402 str = strMonthDayTemplate.arg( numberPlacing(week(start))) 400 str = strMonthDayTemplate.arg( numberPlacing(week(start)))
403 .arg( dayLabel[start.dayOfWeek() - 1] ); 401 .arg( dayLabel[start.dayOfWeek() - 1] );
404 lblRepeat->setText( str ); 402 lblRepeat->setText( str );
405} 403}
406void ORecurranceWidget::slotChangeStartOfWeek( bool onMonday ) { 404void ORecurranceWidget::slotChangeStartOfWeek( bool onMonday ) {
407 startWeekOnMonday = onMonday; 405 startWeekOnMonday = onMonday;
408 // we need to make this unintrusive as possible... 406 // we need to make this unintrusive as possible...
409 int saveSpin = spinFreq->value(); 407 int saveSpin = spinFreq->value();
410 char days = 0; 408 char days = 0;
411 int day; 409 int day;
412 QListIterator<QToolButton> itExtra( listExtra ); 410 QListIterator<QToolButton> itExtra( listExtra );
413 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { 411 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) {
414 if ( (*itExtra)->isOn() ) { 412 if ( (*itExtra)->isOn() ) {
415 if ( !startWeekOnMonday ) 413 if ( !startWeekOnMonday )
416 days |= day; 414 days |= day;
417 else { 415 else {
418 if ( day == 1 ) 416 if ( day == 1 )
419 days |= ORecur::SUN; 417 days |= ORecur::SUN;
420 else 418 else
421 days |= day >> 1; 419 days |= day >> 1;
422 } 420 }
423 } 421 }
424 } 422 }
425 setupWeekly(); 423 setupWeekly();
426 spinFreq->setValue( saveSpin ); 424 spinFreq->setValue( saveSpin );
427 int buttons; 425 int buttons;
428 for ( day = 0x01, buttons = 0; buttons < 7; 426 for ( day = 0x01, buttons = 0; buttons < 7;
429 day = day << 1, buttons++ ) { 427 day = day << 1, buttons++ ) {
430 if ( days & day ) { 428 if ( days & day ) {
431 if ( startWeekOnMonday ) 429 if ( startWeekOnMonday )
432 fraExtra->setButton( buttons ); 430 fraExtra->setButton( buttons );
433 else { 431 else {
434 if ( buttons == 7 ) 432 if ( buttons == 7 )
435 fraExtra->setButton( 0 ); 433 fraExtra->setButton( 0 );
436 else 434 else
437 fraExtra->setButton( buttons + 1 ); 435 fraExtra->setButton( buttons + 1 );
438 } 436 }
439 } 437 }
440 } 438 }
441 slotWeekLabel(); 439 slotWeekLabel();
442} 440}
443void ORecurranceWidget::setupNone() { 441void ORecurranceWidget::setupNone() {
444 lblRepeat->setText( tr("No Repeat") ); 442 lblRepeat->setText( tr("No Repeat") );
445 lblVar1->hide(); 443 lblVar1->hide();
446 lblVar2->hide(); 444 lblVar2->hide();
447 hideExtras(); 445 hideExtras();
448 cmdEnd->hide(); 446 cmdEnd->hide();
449 lblFreq->hide(); 447 lblFreq->hide();
450 lblEvery->hide(); 448 lblEvery->hide();
451 lblFreq->hide(); 449 lblFreq->hide();
452 spinFreq->hide(); 450 spinFreq->hide();
453 lblEnd->hide(); 451 lblEnd->hide();
454 lblWeekVar->hide(); 452 lblWeekVar->hide();
455} 453}
456void ORecurranceWidget::setupDaily() { 454void ORecurranceWidget::setupDaily() {
457 hideExtras(); 455 hideExtras();
458 lblWeekVar->hide(); 456 lblWeekVar->hide();
459 spinFreq->setValue( 1 ); 457 spinFreq->setValue( 1 );
460 lblFreq->setText( tr("day(s)") ); 458 lblFreq->setText( tr("day(s)") );
461 lblVar2->show(); 459 lblVar2->show();
462 showRepeatStuff(); 460 showRepeatStuff();
463 lblRepeat->setText( strDayTemplate ); 461 lblRepeat->setText( strDayTemplate );
464 setupRepeatLabel( 1 ); 462 setupRepeatLabel( 1 );
465} 463}
466void ORecurranceWidget::setupWeekly() { 464void ORecurranceWidget::setupWeekly() {
467// reshow the buttons... 465// reshow the buttons...
468 fraExtra->setTitle( tr("Repeat On") ); 466 fraExtra->setTitle( tr("Repeat On") );
469 fraExtra->setExclusive( FALSE ); 467 fraExtra->setExclusive( FALSE );
470 fraExtra->show(); 468 fraExtra->show();
471 if ( startWeekOnMonday ) { 469 if ( startWeekOnMonday ) {
472 cmdExtra1->setText( tr("Mon") ); 470 cmdExtra1->setText( tr("Mon") );
473 cmdExtra2->setText( tr("Tue") ); 471 cmdExtra2->setText( tr("Tue") );
474 cmdExtra3->setText( tr("Wed") ); 472 cmdExtra3->setText( tr("Wed") );
475 cmdExtra4->setText( tr("Thu") ); 473 cmdExtra4->setText( tr("Thu") );
476 cmdExtra5->setText( tr("Fri") ); 474 cmdExtra5->setText( tr("Fri") );
477 cmdExtra6->setText( tr("Sat") ); 475 cmdExtra6->setText( tr("Sat") );
478 cmdExtra7->setText( tr("Sun") ); 476 cmdExtra7->setText( tr("Sun") );
479 } else { 477 } else {
480 cmdExtra1->setText( tr("Sun") ); 478 cmdExtra1->setText( tr("Sun") );
481 cmdExtra2->setText( tr("Mon") ); 479 cmdExtra2->setText( tr("Mon") );
482 cmdExtra3->setText( tr("Tue") ); 480 cmdExtra3->setText( tr("Tue") );
483 cmdExtra4->setText( tr("Wed") ); 481 cmdExtra4->setText( tr("Wed") );
484 cmdExtra5->setText( tr("Thu") ); 482 cmdExtra5->setText( tr("Thu") );
485 cmdExtra6->setText( tr("Fri") ); 483 cmdExtra6->setText( tr("Fri") );
486 cmdExtra7->setText( tr("Sat") ); 484 cmdExtra7->setText( tr("Sat") );
487 } 485 }
488 // I hope clustering these improve performance.... 486 // I hope clustering these improve performance....
489 cmdExtra1->setOn( FALSE ); 487 cmdExtra1->setOn( FALSE );
490 cmdExtra2->setOn( FALSE ); 488 cmdExtra2->setOn( FALSE );
491 cmdExtra3->setOn( FALSE ); 489 cmdExtra3->setOn( FALSE );
492 cmdExtra4->setOn( FALSE ); 490 cmdExtra4->setOn( FALSE );
493 cmdExtra5->setOn( FALSE ); 491 cmdExtra5->setOn( FALSE );
494 cmdExtra6->setOn( FALSE ); 492 cmdExtra6->setOn( FALSE );
495 cmdExtra7->setOn( FALSE ); 493 cmdExtra7->setOn( FALSE );
496 494
497 cmdExtra1->show(); 495 cmdExtra1->show();
498 cmdExtra2->show(); 496 cmdExtra2->show();
499 cmdExtra3->show(); 497 cmdExtra3->show();
500 cmdExtra4->show(); 498 cmdExtra4->show();
501 cmdExtra5->show(); 499 cmdExtra5->show();
502 cmdExtra6->show(); 500 cmdExtra6->show();
503 cmdExtra7->show(); 501 cmdExtra7->show();
504 502
505 lblWeekVar->show(); 503 lblWeekVar->show();
506 spinFreq->setValue( 1 ); 504 spinFreq->setValue( 1 );
507 // might as well set the day too... 505 // might as well set the day too...
508 if ( startWeekOnMonday ) { 506 if ( startWeekOnMonday ) {
509 fraExtra->setButton( start.dayOfWeek() - 1 ); 507 fraExtra->setButton( start.dayOfWeek() - 1 );
510 } else { 508 } else {
511 fraExtra->setButton( start.dayOfWeek() % 7 ); 509 fraExtra->setButton( start.dayOfWeek() % 7 );
512 } 510 }
513 lblFreq->setText( tr("week(s)") ); 511 lblFreq->setText( tr("week(s)") );
514 lblVar2->show(); 512 lblVar2->show();
515 showRepeatStuff(); 513 showRepeatStuff();
516 setupRepeatLabel( 1 ); 514 setupRepeatLabel( 1 );
517} 515}
518void ORecurranceWidget::setupMonthly() { 516void ORecurranceWidget::setupMonthly() {
519 hideExtras(); 517 hideExtras();
520 lblWeekVar->hide(); 518 lblWeekVar->hide();
521 fraExtra->setTitle( tr("Repeat By") ); 519 fraExtra->setTitle( tr("Repeat By") );
522 fraExtra->setExclusive( TRUE ); 520 fraExtra->setExclusive( TRUE );
523 fraExtra->show(); 521 fraExtra->show();
524 cmdExtra1->setText( tr("Day") ); 522 cmdExtra1->setText( tr("Day") );
525 cmdExtra1->show(); 523 cmdExtra1->show();
526 cmdExtra2->setText( tr("Date") ); 524 cmdExtra2->setText( tr("Date") );
527 cmdExtra2->show(); 525 cmdExtra2->show();
528 spinFreq->setValue( 1 ); 526 spinFreq->setValue( 1 );
529 lblFreq->setText( tr("month(s)") ); 527 lblFreq->setText( tr("month(s)") );
530 lblVar2->show(); 528 lblVar2->show();
531 showRepeatStuff(); 529 showRepeatStuff();
532 setupRepeatLabel( 1 ); 530 setupRepeatLabel( 1 );
533} 531}
534void ORecurranceWidget::setupYearly() { 532void ORecurranceWidget::setupYearly() {
535hideExtras(); 533hideExtras();
536 lblWeekVar->hide(); 534 lblWeekVar->hide();
537 spinFreq->setValue( 1 ); 535 spinFreq->setValue( 1 );
538 lblFreq->setText( tr("year(s)") ); 536 lblFreq->setText( tr("year(s)") );
539 lblFreq->show(); 537 lblFreq->show();
540 lblFreq->show(); 538 lblFreq->show();
541 showRepeatStuff(); 539 showRepeatStuff();
542 lblVar2->show(); 540 lblVar2->show();
543 QString strEvery = strYearTemplate.arg( start.monthName(start.month()) ).arg( numberPlacing(start.day()) ); 541 QString strEvery = strYearTemplate.arg( start.monthName(start.month()) ).arg( numberPlacing(start.day()) );
544 lblRepeat->setText( strEvery ); 542 lblRepeat->setText( strEvery );
545 setupRepeatLabel( 1 ); 543 setupRepeatLabel( 1 );
546 544
547} 545}
548void ORecurranceWidget::init() { 546void ORecurranceWidget::init() {
549 QPopupMenu *m1 = new QPopupMenu( this ); 547 QPopupMenu *m1 = new QPopupMenu( this );
550 repeatPicker = new DateBookMonth( m1, 0, TRUE ); 548 repeatPicker = new DateBookMonth( m1, 0, TRUE );
551 m1->insertItem( repeatPicker ); 549 m1->insertItem( repeatPicker );
552 cmdEnd->setPopup( m1 ); 550 cmdEnd->setPopup( m1 );
553 cmdEnd->setPopupDelay( 0 ); 551 cmdEnd->setPopupDelay( 0 );
554 552
555 QObject::connect( repeatPicker, SIGNAL(dateClicked(int, int, int)), 553 QObject::connect( repeatPicker, SIGNAL(dateClicked(int, int, int)),
556 this, SLOT(endDateChanged(int, int, int)) ); 554 this, SLOT(endDateChanged(int, int, int)) );
557 QObject::connect( qApp, SIGNAL(weekChanged(bool)), 555 QObject::connect( qApp, SIGNAL(weekChanged(bool)),
558 this, SLOT(slotChangeStartOfWeek(bool)) ); 556 this, SLOT(slotChangeStartOfWeek(bool)) );
559 557
560 listRTypeButtons.setAutoDelete( TRUE ); 558 listRTypeButtons.setAutoDelete( TRUE );
561 listRTypeButtons.append( cmdNone ); 559 listRTypeButtons.append( cmdNone );
562 listRTypeButtons.append( cmdDay ); 560 listRTypeButtons.append( cmdDay );
563 listRTypeButtons.append( cmdWeek ); 561 listRTypeButtons.append( cmdWeek );
564 listRTypeButtons.append( cmdMonth ); 562 listRTypeButtons.append( cmdMonth );
565 listRTypeButtons.append( cmdYear ); 563 listRTypeButtons.append( cmdYear );
566 564
567 listExtra.setAutoDelete( TRUE ); 565 listExtra.setAutoDelete( TRUE );
568 listExtra.append( cmdExtra1 ); 566 listExtra.append( cmdExtra1 );
569 listExtra.append( cmdExtra2 ); 567 listExtra.append( cmdExtra2 );
570 listExtra.append( cmdExtra3 ); 568 listExtra.append( cmdExtra3 );
571 listExtra.append( cmdExtra4 ); 569 listExtra.append( cmdExtra4 );
572 listExtra.append( cmdExtra5 ); 570 listExtra.append( cmdExtra5 );
573 listExtra.append( cmdExtra6 ); 571 listExtra.append( cmdExtra6 );
574 listExtra.append( cmdExtra7 ); 572 listExtra.append( cmdExtra7 );
575} 573}
576void ORecurranceWidget::hideExtras() { 574void ORecurranceWidget::hideExtras() {
577 // hide the extra buttons... 575 // hide the extra buttons...
578 fraExtra->hide(); 576 fraExtra->hide();
579 chkNoEnd->hide(); 577 chkNoEnd->hide();
580 QListIterator<QToolButton> it( listExtra ); 578 QListIterator<QToolButton> it( listExtra );
581 for ( ; *it; ++it ) { 579 for ( ; *it; ++it ) {
582 (*it)->hide(); 580 (*it)->hide();
583 (*it)->setOn( FALSE ); 581 (*it)->setOn( FALSE );
584 } 582 }
585} 583}
586void ORecurranceWidget::showRepeatStuff() { 584void ORecurranceWidget::showRepeatStuff() {
587 cmdEnd->show(); 585 cmdEnd->show();
588 chkNoEnd->show(); 586 chkNoEnd->show();
589 lblFreq->show(); 587 lblFreq->show();
590 lblEvery->show(); 588 lblEvery->show();
591 lblFreq->show(); 589 lblFreq->show();
592 spinFreq->show(); 590 spinFreq->show();
593 lblEnd->show(); 591 lblEnd->show();
594 lblRepeat->setText( tr("Every") ); 592 lblRepeat->setText( tr("Every") );
595} 593}
596 594
597 595
598static int week( const QDate &start ) 596static int week( const QDate &start )
599{ 597{
600 // figure out the week... 598 // figure out the week...
601 int stop = start.day(), 599 int stop = start.day(),
602 sentinel = start.dayOfWeek(), 600 sentinel = start.dayOfWeek(),
603 dayOfWeek = QDate( start.year(), start.month(), 1 ).dayOfWeek(), 601 dayOfWeek = QDate( start.year(), start.month(), 1 ).dayOfWeek(),
604 week = 1, 602 week = 1,
605 i; 603 i;
606 for ( i = 1; i < stop; i++ ) { 604 for ( i = 1; i < stop; i++ ) {
607 if ( dayOfWeek++ == sentinel ) 605 if ( dayOfWeek++ == sentinel )
608 week++; 606 week++;
609 if ( dayOfWeek > 7 ) 607 if ( dayOfWeek > 7 )
610 dayOfWeek = 0; 608 dayOfWeek = 0;
611 } 609 }
612 return week; 610 return week;
613} 611}
614 612
615static QString numberPlacing( int x ) 613static QString numberPlacing( int x )
616{ 614{
617 // I hope this works in other languages besides english... 615 // I hope this works in other languages besides english...
618 QString str = QString::number( x ); 616 QString str = QString::number( x );
619 switch ( x % 10 ) { 617 switch ( x % 10 ) {
620 case 1: 618 case 1:
621 str += QWidget::tr( "st" ); 619 str += QWidget::tr( "st" );
622 break; 620 break;
623 case 2: 621 case 2:
624 str += QWidget::tr( "nd" ); 622 str += QWidget::tr( "nd" );
625 break; 623 break;
626 case 3: 624 case 3:
627 str += QWidget::tr( "rd" ); 625 str += QWidget::tr( "rd" );
628 break; 626 break;
629 default: 627 default:
630 str += QWidget::tr( "th" ); 628 str += QWidget::tr( "th" );
631 break; 629 break;
632 } 630 }
633 return str; 631 return str;
634} 632}
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,820 +1,821 @@
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:
498 return ( false ); 499 return ( false );
499 } 500 }
500} 501}
501 502
502// Currently only asc implemented.. 503// Currently only asc implemented..
503QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) 504QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
504{ 505{
505 QMap<QString, int> nameToUid; 506 QMap<QString, int> nameToUid;
506 QStringList names; 507 QStringList names;
507 QArray<int> m_currentQuery( m_contactList.count() ); 508 QArray<int> m_currentQuery( m_contactList.count() );
508 509
509 // First fill map and StringList with all Names 510 // First fill map and StringList with all Names
510 // Afterwards sort namelist and use map to fill array to return.. 511 // Afterwards sort namelist and use map to fill array to return..
511 QListIterator<OContact> it( m_contactList ); 512 QListIterator<OContact> it( m_contactList );
512 for( ; it.current(); ++it ){ 513 for( ; it.current(); ++it ){
513 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); 514 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) );
514 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); 515 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() );
515 } 516 }
516 names.sort(); 517 names.sort();
517 518
518 int i = 0; 519 int i = 0;
519 if ( asc ){ 520 if ( asc ){
520 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) 521 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
521 m_currentQuery[i++] = nameToUid[ (*it) ]; 522 m_currentQuery[i++] = nameToUid[ (*it) ];
522 }else{ 523 }else{
523 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) 524 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
524 m_currentQuery[i++] = nameToUid[ (*it) ]; 525 m_currentQuery[i++] = nameToUid[ (*it) ];
525 } 526 }
526 527
527 return m_currentQuery; 528 return m_currentQuery;
528 529
529} 530}
530 531
531bool OContactAccessBackend_XML::add ( const OContact &newcontact ) 532bool OContactAccessBackend_XML::add ( const OContact &newcontact )
532{ 533{
533 //qWarning("odefaultbackend: ACTION::ADD"); 534 //qWarning("odefaultbackend: ACTION::ADD");
534 updateJournal (newcontact, ACTION_ADD); 535 updateJournal (newcontact, ACTION_ADD);
535 addContact_p( newcontact ); 536 addContact_p( newcontact );
536 537
537 m_changed = true; 538 m_changed = true;
538 539
539 return true; 540 return true;
540} 541}
541 542
542bool OContactAccessBackend_XML::replace ( const OContact &contact ) 543bool OContactAccessBackend_XML::replace ( const OContact &contact )
543{ 544{
544 m_changed = true; 545 m_changed = true;
545 546
546 OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); 547 OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
547 548
548 if ( found ) { 549 if ( found ) {
549 OContact* newCont = new OContact( contact ); 550 OContact* newCont = new OContact( contact );
550 551
551 updateJournal ( *newCont, ACTION_REPLACE); 552 updateJournal ( *newCont, ACTION_REPLACE);
552 m_contactList.removeRef ( found ); 553 m_contactList.removeRef ( found );
553 m_contactList.append ( newCont ); 554 m_contactList.append ( newCont );
554 m_uidToContact.remove( QString().setNum( contact.uid() ) ); 555 m_uidToContact.remove( QString().setNum( contact.uid() ) );
555 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); 556 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
556 557
557 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); 558 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid());
558 559
559 return true; 560 return true;
560 } else 561 } else
561 return false; 562 return false;
562} 563}
563 564
564bool OContactAccessBackend_XML::remove ( int uid ) 565bool OContactAccessBackend_XML::remove ( int uid )
565{ 566{
566 m_changed = true; 567 m_changed = true;
567 568
568 OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); 569 OContact* found = m_uidToContact.find ( QString().setNum( uid ) );
569 570
570 if ( found ) { 571 if ( found ) {
571 updateJournal ( *found, ACTION_REMOVE); 572 updateJournal ( *found, ACTION_REMOVE);
572 m_contactList.removeRef ( found ); 573 m_contactList.removeRef ( found );
573 m_uidToContact.remove( QString().setNum( uid ) ); 574 m_uidToContact.remove( QString().setNum( uid ) );
574 575
575 return true; 576 return true;
576 } else 577 } else
577 return false; 578 return false;
578} 579}
579 580
580bool OContactAccessBackend_XML::reload(){ 581bool OContactAccessBackend_XML::reload(){
581 /* Reload is the same as load in this implementation */ 582 /* Reload is the same as load in this implementation */
582 return ( load() ); 583 return ( load() );
583} 584}
584 585
585void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) 586void OContactAccessBackend_XML::addContact_p( const OContact &newcontact )
586{ 587{
587 OContact* contRef = new OContact( newcontact ); 588 OContact* contRef = new OContact( newcontact );
588 589
589 m_contactList.append ( contRef ); 590 m_contactList.append ( contRef );
590 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); 591 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
591} 592}
592 593
593/* This function loads the xml-database and the journalfile */ 594/* This function loads the xml-database and the journalfile */
594bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) 595bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
595{ 596{
596 597
597 /* We use the time of the last read to check if the file was 598 /* We use the time of the last read to check if the file was
598 * changed externally. 599 * changed externally.
599 */ 600 */
600 if ( !isJournal ){ 601 if ( !isJournal ){
601 QFileInfo fi( filename ); 602 QFileInfo fi( filename );
602 m_readtime = fi.lastModified (); 603 m_readtime = fi.lastModified ();
603 } 604 }
604 605
605 const int JOURNALACTION = Qtopia::Notes + 1; 606 const int JOURNALACTION = Qtopia::Notes + 1;
606 const int JOURNALROW = JOURNALACTION + 1; 607 const int JOURNALROW = JOURNALACTION + 1;
607 608
608 bool foundAction = false; 609 bool foundAction = false;
609 journal_action action = ACTION_ADD; 610 journal_action action = ACTION_ADD;
610 int journalKey = 0; 611 int journalKey = 0;
611 QMap<int, QString> contactMap; 612 QMap<int, QString> contactMap;
612 QMap<QString, QString> customMap; 613 QMap<QString, QString> customMap;
613 QMap<QString, QString>::Iterator customIt; 614 QMap<QString, QString>::Iterator customIt;
614 QAsciiDict<int> dict( 47 ); 615 QAsciiDict<int> dict( 47 );
615 616
616 dict.setAutoDelete( TRUE ); 617 dict.setAutoDelete( TRUE );
617 dict.insert( "Uid", new int(Qtopia::AddressUid) ); 618 dict.insert( "Uid", new int(Qtopia::AddressUid) );
618 dict.insert( "Title", new int(Qtopia::Title) ); 619 dict.insert( "Title", new int(Qtopia::Title) );
619 dict.insert( "FirstName", new int(Qtopia::FirstName) ); 620 dict.insert( "FirstName", new int(Qtopia::FirstName) );
620 dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); 621 dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
621 dict.insert( "LastName", new int(Qtopia::LastName) ); 622 dict.insert( "LastName", new int(Qtopia::LastName) );
622 dict.insert( "Suffix", new int(Qtopia::Suffix) ); 623 dict.insert( "Suffix", new int(Qtopia::Suffix) );
623 dict.insert( "FileAs", new int(Qtopia::FileAs) ); 624 dict.insert( "FileAs", new int(Qtopia::FileAs) );
624 dict.insert( "Categories", new int(Qtopia::AddressCategory) ); 625 dict.insert( "Categories", new int(Qtopia::AddressCategory) );
625 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); 626 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
626 dict.insert( "Emails", new int(Qtopia::Emails) ); 627 dict.insert( "Emails", new int(Qtopia::Emails) );
627 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); 628 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
628 dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); 629 dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
629 dict.insert( "HomeState", new int(Qtopia::HomeState) ); 630 dict.insert( "HomeState", new int(Qtopia::HomeState) );
630 dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); 631 dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
631 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); 632 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
632 dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); 633 dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
633 dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); 634 dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
634 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); 635 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
635 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); 636 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
636 dict.insert( "Company", new int(Qtopia::Company) ); 637 dict.insert( "Company", new int(Qtopia::Company) );
637 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); 638 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
638 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); 639 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
639 dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); 640 dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
640 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); 641 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
641 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); 642 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
642 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); 643 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
643 dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); 644 dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
644 dict.insert( "Department", new int(Qtopia::Department) ); 645 dict.insert( "Department", new int(Qtopia::Department) );
645 dict.insert( "Office", new int(Qtopia::Office) ); 646 dict.insert( "Office", new int(Qtopia::Office) );
646 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); 647 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
647 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); 648 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
648 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); 649 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
649 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); 650 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
650 dict.insert( "Profession", new int(Qtopia::Profession) ); 651 dict.insert( "Profession", new int(Qtopia::Profession) );
651 dict.insert( "Assistant", new int(Qtopia::Assistant) ); 652 dict.insert( "Assistant", new int(Qtopia::Assistant) );
652 dict.insert( "Manager", new int(Qtopia::Manager) ); 653 dict.insert( "Manager", new int(Qtopia::Manager) );
653 dict.insert( "Spouse", new int(Qtopia::Spouse) ); 654 dict.insert( "Spouse", new int(Qtopia::Spouse) );
654 dict.insert( "Children", new int(Qtopia::Children) ); 655 dict.insert( "Children", new int(Qtopia::Children) );
655 dict.insert( "Gender", new int(Qtopia::Gender) ); 656 dict.insert( "Gender", new int(Qtopia::Gender) );
656 dict.insert( "Birthday", new int(Qtopia::Birthday) ); 657 dict.insert( "Birthday", new int(Qtopia::Birthday) );
657 dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); 658 dict.insert( "Anniversary", new int(Qtopia::Anniversary) );
658 dict.insert( "Nickname", new int(Qtopia::Nickname) ); 659 dict.insert( "Nickname", new int(Qtopia::Nickname) );
659 dict.insert( "Notes", new int(Qtopia::Notes) ); 660 dict.insert( "Notes", new int(Qtopia::Notes) );
660 dict.insert( "action", new int(JOURNALACTION) ); 661 dict.insert( "action", new int(JOURNALACTION) );
661 dict.insert( "actionrow", new int(JOURNALROW) ); 662 dict.insert( "actionrow", new int(JOURNALROW) );
662 663
663 //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); 664 //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() );
664 665
665 XMLElement *root = XMLElement::load( filename ); 666 XMLElement *root = XMLElement::load( filename );
666 if(root != 0l ){ // start parsing 667 if(root != 0l ){ // start parsing
667 /* Parse all XML-Elements and put the data into the 668 /* Parse all XML-Elements and put the data into the
668 * Contact-Class 669 * Contact-Class
669 */ 670 */
670 XMLElement *element = root->firstChild(); 671 XMLElement *element = root->firstChild();
671 //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); 672 //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() );
672 element = element->firstChild(); 673 element = element->firstChild();
673 674
674 /* Search Tag "Contacts" which is the parent of all Contacts */ 675 /* Search Tag "Contacts" which is the parent of all Contacts */
675 while( element && !isJournal ){ 676 while( element && !isJournal ){
676 if( element->tagName() != QString::fromLatin1("Contacts") ){ 677 if( element->tagName() != QString::fromLatin1("Contacts") ){
677 //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", 678 //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s",
678 // element->tagName().latin1()); 679 // element->tagName().latin1());
679 element = element->nextChild(); 680 element = element->nextChild();
680 } else { 681 } else {
681 element = element->firstChild(); 682 element = element->firstChild();
682 break; 683 break;
683 } 684 }
684 } 685 }
685 /* Parse all Contacts and ignore unknown tags */ 686 /* Parse all Contacts and ignore unknown tags */
686 while( element ){ 687 while( element ){
687 if( element->tagName() != QString::fromLatin1("Contact") ){ 688 if( element->tagName() != QString::fromLatin1("Contact") ){
688 //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", 689 //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s",
689 // element->tagName().latin1()); 690 // element->tagName().latin1());
690 element = element->nextChild(); 691 element = element->nextChild();
691 continue; 692 continue;
692 } 693 }
693 /* Found alement with tagname "contact", now parse and store all 694 /* Found alement with tagname "contact", now parse and store all
694 * attributes contained 695 * attributes contained
695 */ 696 */
696 //qWarning("OContactDefBack::load element tagName() : %s", 697 //qWarning("OContactDefBack::load element tagName() : %s",
697 // element->tagName().latin1() ); 698 // element->tagName().latin1() );
698 QString dummy; 699 QString dummy;
699 foundAction = false; 700 foundAction = false;
700 701
701 XMLElement::AttributeMap aMap = element->attributes(); 702 XMLElement::AttributeMap aMap = element->attributes();
702 XMLElement::AttributeMap::Iterator it; 703 XMLElement::AttributeMap::Iterator it;
703 contactMap.clear(); 704 contactMap.clear();
704 customMap.clear(); 705 customMap.clear();
705 for( it = aMap.begin(); it != aMap.end(); ++it ){ 706 for( it = aMap.begin(); it != aMap.end(); ++it ){
706 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); 707 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1());
707 708
708 int *find = dict[ it.key() ]; 709 int *find = dict[ it.key() ];
709 /* Unknown attributes will be stored as "Custom" elements */ 710 /* Unknown attributes will be stored as "Custom" elements */
710 if ( !find ) { 711 if ( !find ) {
711 // qWarning("Attribute %s not known.", it.key().latin1()); 712 // qWarning("Attribute %s not known.", it.key().latin1());
712 //contact.setCustomField(it.key(), it.data()); 713 //contact.setCustomField(it.key(), it.data());
713 customMap.insert( it.key(), it.data() ); 714 customMap.insert( it.key(), it.data() );
714 continue; 715 continue;
715 } 716 }
716 717
717 /* Check if special conversion is needed and add attribute 718 /* Check if special conversion is needed and add attribute
718 * into Contact class 719 * into Contact class
719 */ 720 */
720 switch( *find ) { 721 switch( *find ) {
721 /* 722 /*
722 case Qtopia::AddressUid: 723 case Qtopia::AddressUid:
723 contact.setUid( it.data().toInt() ); 724 contact.setUid( it.data().toInt() );
724 break; 725 break;
725 case Qtopia::AddressCategory: 726 case Qtopia::AddressCategory:
726 contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); 727 contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
727 break; 728 break;
728 */ 729 */
729 case JOURNALACTION: 730 case JOURNALACTION:
730 action = journal_action(it.data().toInt()); 731 action = journal_action(it.data().toInt());
731 foundAction = true; 732 foundAction = true;
732 qWarning ("ODefBack(journal)::ACTION found: %d", action); 733 qWarning ("ODefBack(journal)::ACTION found: %d", action);
733 break; 734 break;
734 case JOURNALROW: 735 case JOURNALROW:
735 journalKey = it.data().toInt(); 736 journalKey = it.data().toInt();
736 break; 737 break;
737 default: // no conversion needed add them to the map 738 default: // no conversion needed add them to the map
738 contactMap.insert( *find, it.data() ); 739 contactMap.insert( *find, it.data() );
739 break; 740 break;
740 } 741 }
741 } 742 }
742 /* now generate the Contact contact */ 743 /* now generate the Contact contact */
743 OContact contact( contactMap ); 744 OContact contact( contactMap );
744 745
745 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { 746 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
746 contact.setCustomField( customIt.key(), customIt.data() ); 747 contact.setCustomField( customIt.key(), customIt.data() );
747 } 748 }
748 749
749 if (foundAction){ 750 if (foundAction){
750 foundAction = false; 751 foundAction = false;
751 switch ( action ) { 752 switch ( action ) {
752 case ACTION_ADD: 753 case ACTION_ADD:
753 addContact_p (contact); 754 addContact_p (contact);
754 break; 755 break;
755 case ACTION_REMOVE: 756 case ACTION_REMOVE:
756 if ( !remove (contact.uid()) ) 757 if ( !remove (contact.uid()) )
757 qWarning ("ODefBack(journal)::Unable to remove uid: %d", 758 qWarning ("ODefBack(journal)::Unable to remove uid: %d",
758 contact.uid() ); 759 contact.uid() );
759 break; 760 break;
760 case ACTION_REPLACE: 761 case ACTION_REPLACE:
761 if ( !replace ( contact ) ) 762 if ( !replace ( contact ) )
762 qWarning ("ODefBack(journal)::Unable to replace uid: %d", 763 qWarning ("ODefBack(journal)::Unable to replace uid: %d",
763 contact.uid() ); 764 contact.uid() );
764 break; 765 break;
765 default: 766 default:
766 qWarning ("Unknown action: ignored !"); 767 qWarning ("Unknown action: ignored !");
767 break; 768 break;
768 } 769 }
769 }else{ 770 }else{
770 /* Add contact to list */ 771 /* Add contact to list */
771 addContact_p (contact); 772 addContact_p (contact);
772 } 773 }
773 774
774 /* Move to next element */ 775 /* Move to next element */
775 element = element->nextChild(); 776 element = element->nextChild();
776 } 777 }
777 }else { 778 }else {
778 qWarning("ODefBack::could not load"); 779 qWarning("ODefBack::could not load");
779 } 780 }
780 delete root; 781 delete root;
781 qWarning("returning from loading" ); 782 qWarning("returning from loading" );
782 return true; 783 return true;
783} 784}
784 785
785 786
786void OContactAccessBackend_XML::updateJournal( const OContact& cnt, 787void OContactAccessBackend_XML::updateJournal( const OContact& cnt,
787 journal_action action ) 788 journal_action action )
788{ 789{
789 QFile f( m_journalName ); 790 QFile f( m_journalName );
790 bool created = !f.exists(); 791 bool created = !f.exists();
791 if ( !f.open(IO_WriteOnly|IO_Append) ) 792 if ( !f.open(IO_WriteOnly|IO_Append) )
792 return; 793 return;
793 794
794 QString buf; 795 QString buf;
795 QCString str; 796 QCString str;
796 797
797 // if the file was created, we have to set the Tag "<CONTACTS>" to 798 // if the file was created, we have to set the Tag "<CONTACTS>" to
798 // get a XML-File which is readable by our parser. 799 // get a XML-File which is readable by our parser.
799 // This is just a cheat, but better than rewrite the parser. 800 // This is just a cheat, but better than rewrite the parser.
800 if ( created ){ 801 if ( created ){
801 buf = "<Contacts>"; 802 buf = "<Contacts>";
802 QCString cstr = buf.utf8(); 803 QCString cstr = buf.utf8();
803 f.writeBlock( cstr.data(), cstr.length() ); 804 f.writeBlock( cstr.data(), cstr.length() );
804 } 805 }
805 806
806 buf = "<Contact "; 807 buf = "<Contact ";
807 cnt.save( buf ); 808 cnt.save( buf );
808 buf += " action=\"" + QString::number( (int)action ) + "\" "; 809 buf += " action=\"" + QString::number( (int)action ) + "\" ";
809 buf += "/>\n"; 810 buf += "/>\n";
810 QCString cstr = buf.utf8(); 811 QCString cstr = buf.utf8();
811 f.writeBlock( cstr.data(), cstr.length() ); 812 f.writeBlock( cstr.data(), cstr.length() );
812} 813}
813 814
814void OContactAccessBackend_XML::removeJournal() 815void OContactAccessBackend_XML::removeJournal()
815{ 816{
816 QFile f ( m_journalName ); 817 QFile f ( m_journalName );
817 if ( f.exists() ) 818 if ( f.exists() )
818 f.remove(); 819 f.remove();
819} 820}
820 821
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,520 +1,519 @@
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{
397 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 396 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
398 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 397 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
399 if( hasDueDate() && toDoEvent.hasDueDate() ){ 398 if( hasDueDate() && toDoEvent.hasDueDate() ){
400 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 399 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
401 return priority() > toDoEvent.priority(); 400 return priority() > toDoEvent.priority();
402 }else{ 401 }else{
403 return dueDate() > toDoEvent.dueDate(); 402 return dueDate() > toDoEvent.dueDate();
404 } 403 }
405 } 404 }
406 return true; 405 return true;
407} 406}
408bool OTodo::operator==(const OTodo &toDoEvent )const 407bool OTodo::operator==(const OTodo &toDoEvent )const
409{ 408{
410 if ( data->priority != toDoEvent.data->priority ) return false; 409 if ( data->priority != toDoEvent.data->priority ) return false;
411 if ( data->priority != toDoEvent.data->prog ) return false; 410 if ( data->priority != toDoEvent.data->prog ) return false;
412 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 411 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
413 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 412 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
414 if ( data->date != toDoEvent.data->date ) return false; 413 if ( data->date != toDoEvent.data->date ) return false;
415 if ( data->sum != toDoEvent.data->sum ) return false; 414 if ( data->sum != toDoEvent.data->sum ) return false;
416 if ( data->desc != toDoEvent.data->desc ) return false; 415 if ( data->desc != toDoEvent.data->desc ) return false;
417 if ( data->maintainer != toDoEvent.data->maintainer ) 416 if ( data->maintainer != toDoEvent.data->maintainer )
418 return false; 417 return false;
419 418
420 return OPimRecord::operator==( toDoEvent ); 419 return OPimRecord::operator==( toDoEvent );
421} 420}
422void OTodo::deref() { 421void OTodo::deref() {
423 422
424// qWarning("deref in ToDoEvent"); 423// qWarning("deref in ToDoEvent");
425 if ( data->deref() ) { 424 if ( data->deref() ) {
426// qWarning("deleting"); 425// qWarning("deleting");
427 delete data; 426 delete data;
428 data= 0; 427 data= 0;
429 } 428 }
430} 429}
431OTodo &OTodo::operator=(const OTodo &item ) 430OTodo &OTodo::operator=(const OTodo &item )
432{ 431{
433 if ( this == &item ) return *this; 432 if ( this == &item ) return *this;
434 433
435 OPimRecord::operator=( item ); 434 OPimRecord::operator=( item );
436 //qWarning("operator= ref "); 435 //qWarning("operator= ref ");
437 item.data->ref(); 436 item.data->ref();
438 deref(); 437 deref();
439 data = item.data; 438 data = item.data;
440 439
441 return *this; 440 return *this;
442} 441}
443 442
444QMap<int, QString> OTodo::toMap() const { 443QMap<int, QString> OTodo::toMap() const {
445 QMap<int, QString> map; 444 QMap<int, QString> map;
446 445
447 map.insert( Uid, QString::number( uid() ) ); 446 map.insert( Uid, QString::number( uid() ) );
448 map.insert( Category, idsToString( categories() ) ); 447 map.insert( Category, idsToString( categories() ) );
449 map.insert( HasDate, QString::number( data->hasDate ) ); 448 map.insert( HasDate, QString::number( data->hasDate ) );
450 map.insert( Completed, QString::number( data->isCompleted ) ); 449 map.insert( Completed, QString::number( data->isCompleted ) );
451 map.insert( Description, data->desc ); 450 map.insert( Description, data->desc );
452 map.insert( Summary, data->sum ); 451 map.insert( Summary, data->sum );
453 map.insert( Priority, QString::number( data->priority ) ); 452 map.insert( Priority, QString::number( data->priority ) );
454 map.insert( DateDay, QString::number( data->date.day() ) ); 453 map.insert( DateDay, QString::number( data->date.day() ) );
455 map.insert( DateMonth, QString::number( data->date.month() ) ); 454 map.insert( DateMonth, QString::number( data->date.month() ) );
456 map.insert( DateYear, QString::number( data->date.year() ) ); 455 map.insert( DateYear, QString::number( data->date.year() ) );
457 map.insert( Progress, QString::number( data->prog ) ); 456 map.insert( Progress, QString::number( data->prog ) );
458// map.insert( CrossReference, crossToString() ); 457// map.insert( CrossReference, crossToString() );
459 /* FIXME!!! map.insert( State, ); 458 /* FIXME!!! map.insert( State, );
460 map.insert( Recurrence, ); 459 map.insert( Recurrence, );
461 map.insert( Reminders, ); 460 map.insert( Reminders, );
462 map. 461 map.
463 */ 462 */
464 return map; 463 return map;
465} 464}
466 465
467/** 466/**
468 * change or modify looks at the ref count and either 467 * change or modify looks at the ref count and either
469 * creates a new QShared Object or it can modify it 468 * creates a new QShared Object or it can modify it
470 * right in place 469 * right in place
471 */ 470 */
472void OTodo::changeOrModify() { 471void OTodo::changeOrModify() {
473 if ( data->count != 1 ) { 472 if ( data->count != 1 ) {
474 qWarning("changeOrModify"); 473 qWarning("changeOrModify");
475 data->deref(); 474 data->deref();
476 OTodoData* d2 = new OTodoData(); 475 OTodoData* d2 = new OTodoData();
477 copy(data, d2 ); 476 copy(data, d2 );
478 data = d2; 477 data = d2;
479 } 478 }
480} 479}
481// WATCHOUT 480// WATCHOUT
482/* 481/*
483 * if you add something to the Data struct 482 * if you add something to the Data struct
484 * be sure to copy it here 483 * be sure to copy it here
485 */ 484 */
486void OTodo::copy( OTodoData* src, OTodoData* dest ) { 485void OTodo::copy( OTodoData* src, OTodoData* dest ) {
487 dest->date = src->date; 486 dest->date = src->date;
488 dest->isCompleted = src->isCompleted; 487 dest->isCompleted = src->isCompleted;
489 dest->hasDate = src->hasDate; 488 dest->hasDate = src->hasDate;
490 dest->priority = src->priority; 489 dest->priority = src->priority;
491 dest->desc = src->desc; 490 dest->desc = src->desc;
492 dest->sum = src->sum; 491 dest->sum = src->sum;
493 dest->extra = src->extra; 492 dest->extra = src->extra;
494 dest->prog = src->prog; 493 dest->prog = src->prog;
495 494
496 if (src->state ) 495 if (src->state )
497 dest->state = new OPimState( *src->state ); 496 dest->state = new OPimState( *src->state );
498 497
499 if (src->recur ) 498 if (src->recur )
500 dest->recur = new ORecur( *src->recur ); 499 dest->recur = new ORecur( *src->recur );
501 500
502 if (src->maintainer ) 501 if (src->maintainer )
503 dest->maintainer = new OPimMaintainer( *src->maintainer ) 502 dest->maintainer = new OPimMaintainer( *src->maintainer )
504 ; 503 ;
505 dest->start = src->start; 504 dest->start = src->start;
506 dest->completed = src->completed; 505 dest->completed = src->completed;
507 506
508 if (src->notifiers ) 507 if (src->notifiers )
509 dest->notifiers = new OPimNotifyManager( *src->notifiers ); 508 dest->notifiers = new OPimNotifyManager( *src->notifiers );
510} 509}
511QString OTodo::type() const { 510QString OTodo::type() const {
512 return QString::fromLatin1("OTodo"); 511 return QString::fromLatin1("OTodo");
513} 512}
514QString OTodo::recordField(int /*id*/ )const { 513QString OTodo::recordField(int /*id*/ )const {
515 return QString::null; 514 return QString::null;
516} 515}
517 516
518int OTodo::rtti(){ 517int OTodo::rtti(){
519 return OPimResolver::TodoList; 518 return OPimResolver::TodoList;
520} 519}