summaryrefslogtreecommitdiff
path: root/library
Unidiff
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/datebookmonth.cpp28
-rw-r--r--library/fileselector.cpp16
-rw-r--r--library/finddialog.cpp12
-rw-r--r--library/findwidget_p.cpp4
-rw-r--r--library/ir.cpp4
-rw-r--r--library/network.cpp4
-rw-r--r--library/qcopenvelope_qws.cpp4
-rw-r--r--library/qpeapplication.cpp12
-rw-r--r--library/qpedialog.cpp4
-rw-r--r--library/storage.cpp4
-rw-r--r--library/timestring.cpp2
-rw-r--r--library/tzselect.cpp8
12 files changed, 49 insertions, 53 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index 76e022f..421559e 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,762 +1,762 @@
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#include "config.h" 20#include "config.h"
21#include "datebookmonth.h" 21#include "datebookmonth.h"
22#include "datebookdb.h" 22#include "datebookdb.h"
23#include "resource.h" 23#include "resource.h"
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25 25
26#include <qtoolbutton.h> 26#include <qtoolbutton.h>
27#include <qspinbox.h> 27#include <qspinbox.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qvaluestack.h> 29#include <qvaluestack.h>
30#include <qwhatsthis.h> 30#include <qwhatsthis.h>
31 31
32 32
33DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) 33DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
34 : QHBox( parent, name ) 34 : QHBox( parent, name )
35{ 35{
36 setBackgroundMode( PaletteButton ); 36 setBackgroundMode( PaletteButton );
37 37
38 begin = new QToolButton( this ); 38 begin = new QToolButton( this );
39 begin->setFocusPolicy(NoFocus); 39 begin->setFocusPolicy(NoFocus);
40 begin->setPixmap( Resource::loadPixmap( "start" ) ); 40 begin->setPixmap( Resource::loadPixmap( "start" ) );
41 begin->setAutoRaise( TRUE ); 41 begin->setAutoRaise( TRUE );
42 begin->setFixedSize( begin->sizeHint() ); 42 begin->setFixedSize( begin->sizeHint() );
43 QWhatsThis::add( begin, tr("Show January in the selected year") ); 43 QWhatsThis::add( begin, tr("Show January in the selected year") );
44 44
45 back = new QToolButton( this ); 45 back = new QToolButton( this );
46 back->setFocusPolicy(NoFocus); 46 back->setFocusPolicy(NoFocus);
47 back->setPixmap( Resource::loadPixmap( "back" ) ); 47 back->setPixmap( Resource::loadPixmap( "back" ) );
48 back->setAutoRaise( TRUE ); 48 back->setAutoRaise( TRUE );
49 back->setFixedSize( back->sizeHint() ); 49 back->setFixedSize( back->sizeHint() );
50 QWhatsThis::add( back, tr("Show the previous month") ); 50 QWhatsThis::add( back, tr("Show the previous month") );
51 51
52 month = new QComboBox( FALSE, this ); 52 month = new QComboBox( FALSE, this );
53 for ( int i = 0; i < 12; ++i ) 53 for ( int i = 0; i < 12; ++i )
54 month->insertItem( Calendar::nameOfMonth( i + 1 ) ); 54 month->insertItem( Calendar::nameOfMonth( i + 1 ) );
55 55
56 year = new QSpinBox( 1752, 8000, 1, this ); 56 year = new QSpinBox( 1752, 8000, 1, this );
57 57
58 next = new QToolButton( this ); 58 next = new QToolButton( this );
59 next->setFocusPolicy(NoFocus); 59 next->setFocusPolicy(NoFocus);
60 next->setPixmap( Resource::loadPixmap( "forward" ) ); 60 next->setPixmap( Resource::loadPixmap( "forward" ) );
61 next->setAutoRaise( TRUE ); 61 next->setAutoRaise( TRUE );
62 next->setFixedSize( next->sizeHint() ); 62 next->setFixedSize( next->sizeHint() );
63 QWhatsThis::add( next, tr("Show the next month") ); 63 QWhatsThis::add( next, tr("Show the next month") );
64 64
65 end = new QToolButton( this ); 65 end = new QToolButton( this );
66 end->setFocusPolicy(NoFocus); 66 end->setFocusPolicy(NoFocus);
67 end->setPixmap( Resource::loadPixmap( "finish" ) ); 67 end->setPixmap( Resource::loadPixmap( "finish" ) );
68 end->setAutoRaise( TRUE ); 68 end->setAutoRaise( TRUE );
69 end->setFixedSize( end->sizeHint() ); 69 end->setFixedSize( end->sizeHint() );
70 QWhatsThis::add( end, tr("Show December in the selected year") ); 70 QWhatsThis::add( end, tr("Show December in the selected year") );
71 71
72 connect( month, SIGNAL( activated( int ) ), 72 connect( month, SIGNAL( activated(int) ),
73 this, SLOT( updateDate() ) ); 73 this, SLOT( updateDate() ) );
74 connect( year, SIGNAL( valueChanged( int ) ), 74 connect( year, SIGNAL( valueChanged(int) ),
75 this, SLOT( updateDate() ) ); 75 this, SLOT( updateDate() ) );
76 connect( begin, SIGNAL( clicked() ), 76 connect( begin, SIGNAL( clicked() ),
77 this, SLOT( firstMonth() ) ); 77 this, SLOT( firstMonth() ) );
78 connect( end, SIGNAL( clicked() ), 78 connect( end, SIGNAL( clicked() ),
79 this, SLOT( lastMonth() ) ); 79 this, SLOT( lastMonth() ) );
80 connect( back, SIGNAL( clicked() ), 80 connect( back, SIGNAL( clicked() ),
81 this, SLOT( monthBack() ) ); 81 this, SLOT( monthBack() ) );
82 connect( next, SIGNAL( clicked() ), 82 connect( next, SIGNAL( clicked() ),
83 this, SLOT( monthForward() ) ); 83 this, SLOT( monthForward() ) );
84 back->setAutoRepeat( TRUE ); 84 back->setAutoRepeat( TRUE );
85 next->setAutoRepeat( TRUE ); 85 next->setAutoRepeat( TRUE );
86} 86}
87 87
88 88
89DateBookMonthHeader::~DateBookMonthHeader() 89DateBookMonthHeader::~DateBookMonthHeader()
90{ 90{
91 91
92} 92}
93 93
94void DateBookMonthHeader::updateDate() 94void DateBookMonthHeader::updateDate()
95{ 95{
96 emit dateChanged( year->value(), month->currentItem() + 1 ); 96 emit dateChanged( year->value(), month->currentItem() + 1 );
97} 97}
98 98
99void DateBookMonthHeader::firstMonth() 99void DateBookMonthHeader::firstMonth()
100{ 100{
101 emit dateChanged( year->value(), 1 ); 101 emit dateChanged( year->value(), 1 );
102 month->setCurrentItem( 0 ); 102 month->setCurrentItem( 0 );
103} 103}
104 104
105void DateBookMonthHeader::lastMonth() 105void DateBookMonthHeader::lastMonth()
106{ 106{
107 emit dateChanged( year->value(), 12 ); 107 emit dateChanged( year->value(), 12 );
108 month->setCurrentItem( 11 ); 108 month->setCurrentItem( 11 );
109} 109}
110 110
111void DateBookMonthHeader::monthBack() 111void DateBookMonthHeader::monthBack()
112{ 112{
113 if ( month->currentItem() > 0 ) { 113 if ( month->currentItem() > 0 ) {
114 emit dateChanged( year->value(), month->currentItem() ); 114 emit dateChanged( year->value(), month->currentItem() );
115 month->setCurrentItem( month->currentItem() - 1 ); 115 month->setCurrentItem( month->currentItem() - 1 );
116 } else { 116 } else {
117 emit dateChanged( year->value() - 1, 12 ); 117 emit dateChanged( year->value() - 1, 12 );
118 // we have a signal set to a changed value in year so we only need to change 118 // we have a signal set to a changed value in year so we only need to change
119 // year to get the result... 119 // year to get the result...
120 month->setCurrentItem( 11 ); 120 month->setCurrentItem( 11 );
121 year->setValue( year->value() - 1 ); 121 year->setValue( year->value() - 1 );
122 } 122 }
123} 123}
124 124
125void DateBookMonthHeader::monthForward() 125void DateBookMonthHeader::monthForward()
126{ 126{
127 if ( month->currentItem() < 11 ) { 127 if ( month->currentItem() < 11 ) {
128 emit dateChanged( year->value(), month->currentItem() + 2 ); 128 emit dateChanged( year->value(), month->currentItem() + 2 );
129 month->setCurrentItem( month->currentItem() + 1 ); 129 month->setCurrentItem( month->currentItem() + 1 );
130 } else { 130 } else {
131 // we have a signal set to a changed value in year so we only need to change 131 // we have a signal set to a changed value in year so we only need to change
132 // year to get the result... 132 // year to get the result...
133 month->setCurrentItem( 0 ); 133 month->setCurrentItem( 0 );
134 year->setValue( year->value() + 1 ); 134 year->setValue( year->value() + 1 );
135 } 135 }
136} 136}
137 137
138void DateBookMonthHeader::setDate( int y, int m ) 138void DateBookMonthHeader::setDate( int y, int m )
139{ 139{
140 year->setValue( y ); 140 year->setValue( y );
141 month->setCurrentItem( m - 1 ); 141 month->setCurrentItem( m - 1 );
142} 142}
143 143
144//--------------------------------------------------------------------------- 144//---------------------------------------------------------------------------
145 145
146class DateBookMonthTablePrivate 146class DateBookMonthTablePrivate
147{ 147{
148public: 148public:
149 DateBookMonthTablePrivate() {}; 149 DateBookMonthTablePrivate() {};
150 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); }; 150 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); };
151 151
152 QValueList<EffectiveEvent> mMonthEvents; 152 QValueList<EffectiveEvent> mMonthEvents;
153 bool onMonday; 153 bool onMonday;
154}; 154};
155 155
156DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name, 156DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name,
157 DateBookDB *newDb ) 157 DateBookDB *newDb )
158 : QTable( 6, 7, parent, name ), 158 : QTable( 6, 7, parent, name ),
159 db( newDb ) 159 db( newDb )
160{ 160{
161 d = new DateBookMonthTablePrivate(); 161 d = new DateBookMonthTablePrivate();
162 selYear = -1; 162 selYear = -1;
163 selMonth = -1; 163 selMonth = -1;
164 selDay = -1; 164 selDay = -1;
165 165
166 /* init these as well make valgrind happy and be consistent with Qtopia1.6 -zecke */ 166 /* init these as well make valgrind happy and be consistent with Qtopia1.6 -zecke */
167 year = -1; 167 year = -1;
168 month = -1; 168 month = -1;
169 day = -1; 169 day = -1;
170 170
171 Config cfg( "qpe" ); 171 Config cfg( "qpe" );
172 cfg.setGroup( "Time" ); 172 cfg.setGroup( "Time" );
173 d->onMonday = cfg.readBoolEntry( "MONDAY" ); 173 d->onMonday = cfg.readBoolEntry( "MONDAY" );
174 174
175 horizontalHeader()->setResizeEnabled( FALSE ); 175 horizontalHeader()->setResizeEnabled( FALSE );
176 // we have to do this here... or suffer the consequences later... 176 // we have to do this here... or suffer the consequences later...
177 for ( int i = 0; i < 7; i++ ){ 177 for ( int i = 0; i < 7; i++ ){
178 horizontalHeader()->resizeSection( i, 30 ); 178 horizontalHeader()->resizeSection( i, 30 );
179 setColumnStretchable( i, TRUE ); 179 setColumnStretchable( i, TRUE );
180 } 180 }
181 setupLabels(); 181 setupLabels();
182 182
183 verticalHeader()->hide(); 183 verticalHeader()->hide();
184 setLeftMargin( 0 ); 184 setLeftMargin( 0 );
185 for ( int i = 0; i < 6; ++i ) 185 for ( int i = 0; i < 6; ++i )
186 setRowStretchable( i, TRUE ); 186 setRowStretchable( i, TRUE );
187 187
188 setSelectionMode( NoSelection ); 188 setSelectionMode( NoSelection );
189 189
190 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 190 connect( this, SIGNAL( clicked(int,int,int,const QPoint&) ),
191 this, SLOT( dayClicked( int, int ) ) ); 191 this, SLOT( dayClicked(int,int) ) );
192 connect( this, SIGNAL( currentChanged( int, int ) ), 192 connect( this, SIGNAL( currentChanged(int,int) ),
193 this, SLOT( dragDay( int, int ) ) ); 193 this, SLOT( dragDay(int,int) ) );
194 setVScrollBarMode( AlwaysOff ); 194 setVScrollBarMode( AlwaysOff );
195 setHScrollBarMode( AlwaysOff ); 195 setHScrollBarMode( AlwaysOff );
196} 196}
197 197
198DateBookMonthTable::~DateBookMonthTable() 198DateBookMonthTable::~DateBookMonthTable()
199{ 199{
200 monthsEvents.clear(); 200 monthsEvents.clear();
201 delete d; 201 delete d;
202} 202}
203 203
204void DateBookMonthTable::setDate(int y, int m, int d) 204void DateBookMonthTable::setDate(int y, int m, int d)
205{ 205{
206 if (month == m && year == y) { 206 if (month == m && year == y) {
207 if ( selYear == -1 ) 207 if ( selYear == -1 )
208 year = selYear; 208 year = selYear;
209 if ( selMonth == -1 ) 209 if ( selMonth == -1 )
210 month = selMonth; 210 month = selMonth;
211 int r1, c1, r2, c2; 211 int r1, c1, r2, c2;
212 findDay(selDay, r1, c1); 212 findDay(selDay, r1, c1);
213 selDay = day = d; 213 selDay = day = d;
214 findDay(selDay, r2, c2); 214 findDay(selDay, r2, c2);
215 setCurrentCell( r2, c2 ); 215 setCurrentCell( r2, c2 );
216 //updateCell(r1,c1); 216 //updateCell(r1,c1);
217 //updateCell(r2,c2); 217 //updateCell(r2,c2);
218 } else { 218 } else {
219 selYear = year = y; 219 selYear = year = y;
220 selMonth = month = m; 220 selMonth = month = m;
221 selDay = day = d; 221 selDay = day = d;
222 setupTable(); 222 setupTable();
223 } 223 }
224} 224}
225 225
226void DateBookMonthTable::redraw() 226void DateBookMonthTable::redraw()
227{ 227{
228 setupLabels(); 228 setupLabels();
229 setupTable(); 229 setupTable();
230} 230}
231 231
232void DateBookMonthTable::setWeekStart( bool onMonday ) 232void DateBookMonthTable::setWeekStart( bool onMonday )
233{ 233{
234 d->onMonday = onMonday; 234 d->onMonday = onMonday;
235 setupLabels(); 235 setupLabels();
236 setupTable(); 236 setupTable();
237} 237}
238 238
239void DateBookMonthTable::setupTable() 239void DateBookMonthTable::setupTable()
240{ 240{
241 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); 241 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday );
242 QValueList<Calendar::Day>::Iterator it = days.begin(); 242 QValueList<Calendar::Day>::Iterator it = days.begin();
243 int row = 0, col = 0; 243 int row = 0, col = 0;
244 int crow = 0; 244 int crow = 0;
245 int ccol = 0; 245 int ccol = 0;
246 for ( ; it != days.end(); ++it ) { 246 for ( ; it != days.end(); ++it ) {
247 DayItemMonth *i = (DayItemMonth *)item( row, col ); 247 DayItemMonth *i = (DayItemMonth *)item( row, col );
248 if ( !i ) { 248 if ( !i ) {
249 i = new DayItemMonth( this, QTableItem::Never, "" ); 249 i = new DayItemMonth( this, QTableItem::Never, "" );
250 setItem( row, col, i ); 250 setItem( row, col, i );
251 } 251 }
252 Calendar::Day calDay = *it; 252 Calendar::Day calDay = *it;
253 i->clearEffEvents(); 253 i->clearEffEvents();
254 i->setDay( calDay.date ); 254 i->setDay( calDay.date );
255 i->setType( calDay.type ); 255 i->setType( calDay.type );
256 if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) { 256 if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) {
257 crow = row; 257 crow = row;
258 ccol = col; 258 ccol = col;
259 } 259 }
260 260
261 updateCell( row, col ); 261 updateCell( row, col );
262 262
263 if ( col == 6 ) { 263 if ( col == 6 ) {
264 ++row; 264 ++row;
265 col = 0; 265 col = 0;
266 } else { 266 } else {
267 ++col; 267 ++col;
268 } 268 }
269 } 269 }
270 setCurrentCell( crow, ccol ); 270 setCurrentCell( crow, ccol );
271 getEvents(); 271 getEvents();
272} 272}
273 273
274void DateBookMonthTable::findDay( int day, int &row, int &col ) 274void DateBookMonthTable::findDay( int day, int &row, int &col )
275{ 275{
276 QDate dtBegin( year, month, 1 ); 276 QDate dtBegin( year, month, 1 );
277 int skips = dtBegin.dayOfWeek(); 277 int skips = dtBegin.dayOfWeek();
278 int effective_day = day + skips - 1; // row/columns begin at 0 278 int effective_day = day + skips - 1; // row/columns begin at 0
279 // make an extra adjustment if we start on Mondays. 279 // make an extra adjustment if we start on Mondays.
280 if ( d->onMonday ) 280 if ( d->onMonday )
281 effective_day--; 281 effective_day--;
282 row = effective_day / 7; 282 row = effective_day / 7;
283 col = effective_day % 7; 283 col = effective_day % 7;
284} 284}
285 285
286void DateBookMonthTable::dayClicked( int row, int col ) 286void DateBookMonthTable::dayClicked( int row, int col )
287{ 287{
288 changeDaySelection( row, col ); 288 changeDaySelection( row, col );
289 emit dateClicked( selYear, selMonth, selDay ); 289 emit dateClicked( selYear, selMonth, selDay );
290} 290}
291 291
292void DateBookMonthTable::dragDay( int row, int col ) 292void DateBookMonthTable::dragDay( int row, int col )
293{ 293{
294 changeDaySelection( row, col ); 294 changeDaySelection( row, col );
295} 295}
296 296
297void DateBookMonthTable::changeDaySelection( int row, int col ) 297void DateBookMonthTable::changeDaySelection( int row, int col )
298{ 298{
299 DayItemMonth *i = (DayItemMonth*)item( row, col ); 299 DayItemMonth *i = (DayItemMonth*)item( row, col );
300 if ( !i ) 300 if ( !i )
301 return; 301 return;
302 switch ( i->type() ) { 302 switch ( i->type() ) {
303 case Calendar::Day::ThisMonth: 303 case Calendar::Day::ThisMonth:
304 selMonth = month; 304 selMonth = month;
305 break; 305 break;
306 case Calendar::Day::PrevMonth: 306 case Calendar::Day::PrevMonth:
307 selMonth = month-1; 307 selMonth = month-1;
308 break; 308 break;
309 default: 309 default:
310 selMonth = month+1; 310 selMonth = month+1;
311 } 311 }
312 312
313 selYear = year; 313 selYear = year;
314 if ( selMonth <= 0 ) { 314 if ( selMonth <= 0 ) {
315 selMonth = 12; 315 selMonth = 12;
316 selYear--; 316 selYear--;
317 } else if ( selMonth > 12 ) { 317 } else if ( selMonth > 12 ) {
318 selMonth = 1; 318 selMonth = 1;
319 selYear++; 319 selYear++;
320 } 320 }
321 selDay = i->day(); 321 selDay = i->day();
322} 322}
323 323
324 324
325void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) 325void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * )
326{ 326{
327 dayClicked( currentRow(), currentColumn() ); 327 dayClicked( currentRow(), currentColumn() );
328} 328}
329 329
330void DateBookMonthTable::getEvents() 330void DateBookMonthTable::getEvents()
331{ 331{
332 if ( !db ) 332 if ( !db )
333 return; 333 return;
334 334
335 QDate dtStart( year, month, 1 ); 335 QDate dtStart( year, month, 1 );
336 d->mMonthEvents = db->getEffectiveEvents( dtStart, 336 d->mMonthEvents = db->getEffectiveEvents( dtStart,
337 QDate( year, month, 337 QDate( year, month,
338 dtStart.daysInMonth() ) ); 338 dtStart.daysInMonth() ) );
339 QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin(); 339 QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin();
340 // now that the events are sorted, basically go through the list, make 340 // now that the events are sorted, basically go through the list, make
341 // a small list for every day and set it for each item... 341 // a small list for every day and set it for each item...
342 // clear all the items... 342 // clear all the items...
343 while ( it != d->mMonthEvents.end() ) { 343 while ( it != d->mMonthEvents.end() ) {
344 QValueList<EffectiveEvent> dayEvent; 344 QValueList<EffectiveEvent> dayEvent;
345 EffectiveEvent e = *it; 345 EffectiveEvent e = *it;
346 ++it; 346 ++it;
347 dayEvent.append( e ); 347 dayEvent.append( e );
348 while ( it != d->mMonthEvents.end() 348 while ( it != d->mMonthEvents.end()
349 && e.date() == (*it).date() ) { 349 && e.date() == (*it).date() ) {
350 dayEvent.append( *it ); 350 dayEvent.append( *it );
351 ++it; 351 ++it;
352 } 352 }
353 int row, col; 353 int row, col;
354 findDay( e.date().day(), row, col ); 354 findDay( e.date().day(), row, col );
355 DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) ); 355 DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) );
356 w->setEvents( dayEvent ); 356 w->setEvents( dayEvent );
357 updateCell( row, col ); 357 updateCell( row, col );
358 dayEvent.clear(); 358 dayEvent.clear();
359 } 359 }
360} 360}
361 361
362 362
363void DateBookMonthTable::setupLabels() 363void DateBookMonthTable::setupLabels()
364{ 364{
365 for ( int i = 0; i < 7; ++i ) { 365 for ( int i = 0; i < 7; ++i ) {
366 // horizontalHeader()->resizeSection( i, 30 ); 366 // horizontalHeader()->resizeSection( i, 30 );
367 // setColumnStretchable( i, TRUE ); 367 // setColumnStretchable( i, TRUE );
368 if ( d->onMonday ) 368 if ( d->onMonday )
369 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) ); 369 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) );
370 else { 370 else {
371 if ( i == 0 ) 371 if ( i == 0 )
372 horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) ); 372 horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) );
373 else 373 else
374 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) ); 374 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) );
375 } 375 }
376 } 376 }
377} 377}
378 378
379 379
380//--------------------------------------------------------------------------- 380//---------------------------------------------------------------------------
381 381
382DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac, 382DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac,
383 DateBookDB *data ) 383 DateBookDB *data )
384 : QVBox( parent, name ), 384 : QVBox( parent, name ),
385 autoClose( ac ) 385 autoClose( ac )
386{ 386{
387 setFocusPolicy(StrongFocus); 387 setFocusPolicy(StrongFocus);
388 year = QDate::currentDate().year(); 388 year = QDate::currentDate().year();
389 month = QDate::currentDate().month(); 389 month = QDate::currentDate().month();
390 day = QDate::currentDate().day(); 390 day = QDate::currentDate().day();
391 header = new DateBookMonthHeader( this, "DateBookMonthHeader" ); 391 header = new DateBookMonthHeader( this, "DateBookMonthHeader" );
392 table = new DateBookMonthTable( this, "DateBookMonthTable", data ); 392 table = new DateBookMonthTable( this, "DateBookMonthTable", data );
393 header->setDate( year, month ); 393 header->setDate( year, month );
394 table->setDate( year, month, QDate::currentDate().day() ); 394 table->setDate( year, month, QDate::currentDate().day() );
395 header->setFocusPolicy(NoFocus); 395 header->setFocusPolicy(NoFocus);
396 table->setFocusPolicy(NoFocus); 396 table->setFocusPolicy(NoFocus);
397 connect( header, SIGNAL( dateChanged( int, int ) ), 397 connect( header, SIGNAL( dateChanged(int,int) ),
398 this, SLOT( setDate( int, int ) ) ); 398 this, SLOT( setDate(int,int) ) );
399 connect( table, SIGNAL( dateClicked( int, int, int ) ), 399 connect( table, SIGNAL( dateClicked(int,int,int) ),
400 this, SLOT( finalDate(int, int, int) ) ); 400 this, SLOT( finalDate(int,int,int) ) );
401 connect( qApp, SIGNAL(weekChanged(bool)), this, 401 connect( qApp, SIGNAL(weekChanged(bool)), this,
402 SLOT(slotWeekChange(bool)) ); 402 SLOT(slotWeekChange(bool)) );
403 table->setFocus(); 403 table->setFocus();
404} 404}
405 405
406DateBookMonth::~DateBookMonth() 406DateBookMonth::~DateBookMonth()
407{ 407{
408 408
409} 409}
410 410
411void DateBookMonth::setDate( int y, int m ) 411void DateBookMonth::setDate( int y, int m )
412{ 412{
413 /* only change the date if this is a different date, 413 /* only change the date if this is a different date,
414 * other wise we may mistakenly overide the day */ 414 * other wise we may mistakenly overide the day */
415 if ( (y != year) || (m != month) ) { 415 if ( (y != year) || (m != month) ) {
416 year = y; 416 year = y;
417 month = m; 417 month = m;
418 QDate nd( y, m, 1 ); 418 QDate nd( y, m, 1 );
419 if ( nd.daysInMonth() < day ) 419 if ( nd.daysInMonth() < day )
420 day = nd.daysInMonth(); 420 day = nd.daysInMonth();
421 table->setDate( year, month, day ); 421 table->setDate( year, month, day );
422 } 422 }
423} 423}
424 424
425void DateBookMonth::setDate( int y, int m, int d ) 425void DateBookMonth::setDate( int y, int m, int d )
426{ 426{
427 header->setDate( y, m); 427 header->setDate( y, m);
428 table->setDate( y, m, d); 428 table->setDate( y, m, d);
429 year = y; 429 year = y;
430 month = m; 430 month = m;
431 day = d; 431 day = d;
432} 432}
433 433
434/* called when we wish to close or pass back the date */ 434/* called when we wish to close or pass back the date */
435void DateBookMonth::finalDate(int y, int m, int d) 435void DateBookMonth::finalDate(int y, int m, int d)
436{ 436{
437 setDate( y, m, d ); 437 setDate( y, m, d );
438 438
439 emit dateClicked(y, m, d); 439 emit dateClicked(y, m, d);
440 // emit dateClicked(QDate(y, m, d).toString()); 440 // emit dateClicked(QDate(y, m, d).toString());
441 441
442 if ( autoClose && parentWidget() ) 442 if ( autoClose && parentWidget() )
443 parentWidget()->close(); 443 parentWidget()->close();
444} 444}
445 445
446void DateBookMonth::setDate( QDate d) 446void DateBookMonth::setDate( QDate d)
447{ 447{
448 setDate(d.year(), d.month(), d.day()); 448 setDate(d.year(), d.month(), d.day());
449} 449}
450 450
451void DateBookMonth::redraw() 451void DateBookMonth::redraw()
452{ 452{
453 table->setDate( year, month, day ); 453 table->setDate( year, month, day );
454 table->redraw(); 454 table->redraw();
455} 455}
456 456
457QDate DateBookMonth::selectedDate() const 457QDate DateBookMonth::selectedDate() const
458{ 458{
459 if ( !table ) 459 if ( !table )
460 return QDate::currentDate(); 460 return QDate::currentDate();
461 int y, m, d; 461 int y, m, d;
462 table->getDate( y, m, d ); 462 table->getDate( y, m, d );
463 return QDate( y, m, d ); 463 return QDate( y, m, d );
464} 464}
465 465
466void DateBookMonth::slotWeekChange( bool startOnMonday ) 466void DateBookMonth::slotWeekChange( bool startOnMonday )
467{ 467{
468 table->setWeekStart( startOnMonday ); 468 table->setWeekStart( startOnMonday );
469} 469}
470 470
471void DateBookMonth::keyPressEvent( QKeyEvent *e ) 471void DateBookMonth::keyPressEvent( QKeyEvent *e )
472{ 472{
473 switch(e->key()) { 473 switch(e->key()) {
474 case Key_Up: 474 case Key_Up:
475 setDate(QDate(year, month, day).addDays(-7)); 475 setDate(QDate(year, month, day).addDays(-7));
476 break; 476 break;
477 case Key_Down: 477 case Key_Down:
478 setDate(QDate(year, month, day).addDays(7)); 478 setDate(QDate(year, month, day).addDays(7));
479 break; 479 break;
480 case Key_Left: 480 case Key_Left:
481 setDate(QDate(year, month, day).addDays(-1)); 481 setDate(QDate(year, month, day).addDays(-1));
482 break; 482 break;
483 case Key_Right: 483 case Key_Right:
484 setDate(QDate(year, month, day).addDays(1)); 484 setDate(QDate(year, month, day).addDays(1));
485 break; 485 break;
486 case Key_Space: 486 case Key_Space:
487 qWarning("space"); 487 qWarning("space");
488 emit dateClicked(year, month, day); 488 emit dateClicked(year, month, day);
489 if ( autoClose && parentWidget() ) 489 if ( autoClose && parentWidget() )
490 parentWidget()->close(); 490 parentWidget()->close();
491 break; 491 break;
492 default: 492 default:
493 qWarning("ignore"); 493 qWarning("ignore");
494 e->ignore(); 494 e->ignore();
495 break; 495 break;
496 } 496 }
497} 497}
498 498
499//--------------------------------------------------------------------------- 499//---------------------------------------------------------------------------
500class DayItemMonthPrivate 500class DayItemMonthPrivate
501{ 501{
502public: 502public:
503 DayItemMonthPrivate() {}; 503 DayItemMonthPrivate() {};
504 ~DayItemMonthPrivate() { mDayEvents.clear(); }; 504 ~DayItemMonthPrivate() { mDayEvents.clear(); };
505 QValueList<EffectiveEvent> mDayEvents; 505 QValueList<EffectiveEvent> mDayEvents;
506}; 506};
507 507
508DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t ) 508DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t )
509 : QTableItem( table, et, t ) 509 : QTableItem( table, et, t )
510{ 510{
511 d = new DayItemMonthPrivate(); 511 d = new DayItemMonthPrivate();
512} 512}
513 513
514DayItemMonth::~DayItemMonth() 514DayItemMonth::~DayItemMonth()
515{ 515{
516 daysEvents.clear(); 516 daysEvents.clear();
517 delete d; 517 delete d;
518} 518}
519 519
520void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv ) 520void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv )
521{ 521{
522 d->mDayEvents = effEv; 522 d->mDayEvents = effEv;
523} 523}
524 524
525void DayItemMonth::clearEffEvents() 525void DayItemMonth::clearEffEvents()
526{ 526{
527 d->mDayEvents.clear(); 527 d->mDayEvents.clear();
528} 528}
529 529
530void DayItemMonth::paint( QPainter *p, const QColorGroup &cg, 530void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
531 const QRect &cr, bool selected ) 531 const QRect &cr, bool selected )
532{ 532{
533 p->save(); 533 p->save();
534 534
535 QColorGroup g( cg ); 535 QColorGroup g( cg );
536 g.setBrush( QColorGroup::Base, back ); 536 g.setBrush( QColorGroup::Base, back );
537 g.setColor( QColorGroup::Text, forg ); 537 g.setColor( QColorGroup::Text, forg );
538 if ( selected ) 538 if ( selected )
539 p->setPen( g.highlightedText() ); 539 p->setPen( g.highlightedText() );
540 else 540 else
541 p->setPen( g.text() ); 541 p->setPen( g.text() );
542 542
543 QValueStack<int> normalLine; 543 QValueStack<int> normalLine;
544 QValueStack<int> repeatLine; 544 QValueStack<int> repeatLine;
545 QValueStack<int> travelLine; 545 QValueStack<int> travelLine;
546 546
547 bool normalAllDay = FALSE; 547 bool normalAllDay = FALSE;
548 bool repeatAllDay = FALSE; 548 bool repeatAllDay = FALSE;
549 bool travelAllDay = FALSE; 549 bool travelAllDay = FALSE;
550 550
551 QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin(); 551 QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin();
552 552
553 for ( ; itDays != d->mDayEvents.end(); ++itDays ) { 553 for ( ; itDays != d->mDayEvents.end(); ++itDays ) {
554 int w = cr.width(); 554 int w = cr.width();
555 Event ev = (*itDays).event(); 555 Event ev = (*itDays).event();
556 556
557 int f = (*itDays).start().hour(); // assume Effective event 557 int f = (*itDays).start().hour(); // assume Effective event
558 int t = (*itDays).end().hour(); // is truncated. 558 int t = (*itDays).end().hour(); // is truncated.
559 559
560 if (ev.isAllDay()) { 560 if (ev.isAllDay()) {
561 if (!ev.hasRepeat()) 561 if (!ev.hasRepeat())
562 normalAllDay = TRUE; 562 normalAllDay = TRUE;
563 else 563 else
564 repeatAllDay = TRUE; 564 repeatAllDay = TRUE;
565 } else { 565 } else {
566 int sLine, eLine; 566 int sLine, eLine;
567 if (f == 0) 567 if (f == 0)
568 sLine = 0; 568 sLine = 0;
569 else if (f < 8 ) 569 else if (f < 8 )
570 sLine = 1; 570 sLine = 1;
571 else if (f >= 17) 571 else if (f >= 17)
572 sLine = w - 4; 572 sLine = w - 4;
573 else { 573 else {
574 sLine = (f - 8) * (w - 8); 574 sLine = (f - 8) * (w - 8);
575 if (sLine) 575 if (sLine)
576 sLine /= 8; 576 sLine /= 8;
577 sLine += 4; 577 sLine += 4;
578 } 578 }
579 if (t == 23) 579 if (t == 23)
580 eLine = w; 580 eLine = w;
581 else if (t < 8) 581 else if (t < 8)
582 eLine = 4; 582 eLine = 4;
583 else if (t >= 17) 583 else if (t >= 17)
584 eLine = w - 1; 584 eLine = w - 1;
585 else { 585 else {
586 eLine = (t - 8) * (w - 8); 586 eLine = (t - 8) * (w - 8);
587 if (eLine) 587 if (eLine)
588 eLine /= 8; 588 eLine /= 8;
589 eLine += 4; 589 eLine += 4;
590 } 590 }
591 if (!ev.hasRepeat()) { 591 if (!ev.hasRepeat()) {
592 normalLine.push(sLine); 592 normalLine.push(sLine);
593 normalLine.push(eLine); 593 normalLine.push(eLine);
594 } else { 594 } else {
595 repeatLine.push(sLine); 595 repeatLine.push(sLine);
596 repeatLine.push(eLine); 596 repeatLine.push(eLine);
597 } 597 }
598 } 598 }
599 } 599 }
600 600
601 // draw the background 601 // draw the background
602 if (normalAllDay || repeatAllDay || travelAllDay) { 602 if (normalAllDay || repeatAllDay || travelAllDay) {
603 p->save(); 603 p->save();
604 604
605 if (normalAllDay) 605 if (normalAllDay)
606 if (repeatAllDay) { 606 if (repeatAllDay) {
607 p->fillRect( 0, 0, cr.width(), cr.height() / 2, 607 p->fillRect( 0, 0, cr.width(), cr.height() / 2,
608 colorNormalLight ); 608 colorNormalLight );
609 p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2, 609 p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2,
610 colorRepeatLight ); 610 colorRepeatLight );
611 } else 611 } else
612 p->fillRect( 0, 0, cr.width(), cr.height(), 612 p->fillRect( 0, 0, cr.width(), cr.height(),
613 colorNormalLight ); 613 colorNormalLight );
614 else if (repeatAllDay) 614 else if (repeatAllDay)
615 p->fillRect( 0, 0, cr.width(), cr.height(), 615 p->fillRect( 0, 0, cr.width(), cr.height(),
616 colorRepeatLight ); 616 colorRepeatLight );
617 } else { 617 } else {
618 p->fillRect( 0, 0, cr.width(), 618 p->fillRect( 0, 0, cr.width(),
619 cr.height(), selected 619 cr.height(), selected
620 ? g.brush( QColorGroup::Highlight ) 620 ? g.brush( QColorGroup::Highlight )
621 : g.brush( QColorGroup::Base ) ); 621 : g.brush( QColorGroup::Base ) );
622 } 622 }
623 623
624 // The lines 624 // The lines
625 // now for the lines. 625 // now for the lines.
626 int h = 5; 626 int h = 5;
627 int y = cr.height() / 2 - h; 627 int y = cr.height() / 2 - h;
628 628
629 while(normalLine.count() >= 2) { 629 while(normalLine.count() >= 2) {
630 int x2 = normalLine.pop(); 630 int x2 = normalLine.pop();
631 int x1 = normalLine.pop(); 631 int x1 = normalLine.pop();
632 if (x2 < x1 + 2) 632 if (x2 < x1 + 2)
633 x2 = x1 + 2; 633 x2 = x1 + 2;
634 p->fillRect(x1, y, x2 - x1, h, colorNormal); 634 p->fillRect(x1, y, x2 - x1, h, colorNormal);
635 } 635 }
636 636
637 y += h; 637 y += h;
638 638
639 while(repeatLine.count() >= 2) { 639 while(repeatLine.count() >= 2) {
640 int x2 = repeatLine.pop(); 640 int x2 = repeatLine.pop();
641 int x1 = repeatLine.pop(); 641 int x1 = repeatLine.pop();
642 if (x2 < x1 + 2) 642 if (x2 < x1 + 2)
643 x2 = x1 + 2; 643 x2 = x1 + 2;
644 p->fillRect(x1, y, x2 - x1, h, colorRepeat); 644 p->fillRect(x1, y, x2 - x1, h, colorRepeat);
645 } 645 }
646 646
647 647
648 // Finally, draw the number. 648 // Finally, draw the number.
649 QFont f = p->font(); 649 QFont f = p->font();
650 f.setPointSize( ( f.pointSize() / 3 ) * 2 ); 650 f.setPointSize( ( f.pointSize() / 3 ) * 2 );
651 p->setFont( f ); 651 p->setFont( f );
652 QFontMetrics fm( f ); 652 QFontMetrics fm( f );
653 p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); 653 p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) );
654 654
655 p->restore(); 655 p->restore();
656} 656}
657 657
658 658
659 659
660void DayItemMonth::setType( Calendar::Day::Type t ) 660void DayItemMonth::setType( Calendar::Day::Type t )
661{ 661{
662 switch ( t ) { 662 switch ( t ) {
663 case Calendar::Day::PrevMonth: 663 case Calendar::Day::PrevMonth:
664 case Calendar::Day::NextMonth: 664 case Calendar::Day::NextMonth:
665 back = QBrush( QColor( 224, 224, 224 ) ); 665 back = QBrush( QColor( 224, 224, 224 ) );
666 forg = black; 666 forg = black;
667 break; 667 break;
668 case Calendar::Day::ThisMonth: 668 case Calendar::Day::ThisMonth:
669 back = QBrush( white ); 669 back = QBrush( white );
670 forg = black; 670 forg = black;
671 break; 671 break;
672 } 672 }
673 typ = t; 673 typ = t;
674} 674}
675 675
676 676
677 677
678DateButton::DateButton( bool longDate, QWidget *parent, const char * name ) 678DateButton::DateButton( bool longDate, QWidget *parent, const char * name )
679 :QPushButton( parent, name ) 679 :QPushButton( parent, name )
680{ 680{
681 longFormat = longDate; 681 longFormat = longDate;
682 df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear); 682 df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear);
683 setDate( QDate::currentDate() ); 683 setDate( QDate::currentDate() );
684 684
685 connect(this,SIGNAL(pressed()),this,SLOT(pickDate())); 685 connect(this,SIGNAL(pressed()),this,SLOT(pickDate()));
686 686
687 687
688} 688}
689 689
690 690
691void DateButton::pickDate() 691void DateButton::pickDate()
692{ 692{
693 static QPopupMenu *m1 = 0; 693 static QPopupMenu *m1 = 0;
694 static DateBookMonth *picker = 0; 694 static DateBookMonth *picker = 0;
695 if ( !m1 ) { 695 if ( !m1 ) {
696 m1 = new QPopupMenu( this ); 696 m1 = new QPopupMenu( this );
697 picker = new DateBookMonth( m1, 0, TRUE ); 697 picker = new DateBookMonth( m1, 0, TRUE );
698 m1->insertItem( picker ); 698 m1->insertItem( picker );
699 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 699 connect( picker, SIGNAL( dateClicked(int,int,int) ),
700 this, SLOT( setDate( int, int, int ) ) ); 700 this, SLOT( setDate(int,int,int) ) );
701 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 701 connect( picker, SIGNAL( dateClicked(int,int,int) ),
702 this, SIGNAL( dateSelected( int, int, int ) ) ); 702 this, SIGNAL( dateSelected(int,int,int) ) );
703 connect( m1, SIGNAL( aboutToHide() ), 703 connect( m1, SIGNAL( aboutToHide() ),
704 this, SLOT( gotHide() ) ); 704 this, SLOT( gotHide() ) );
705 } 705 }
706 picker->slotWeekChange( weekStartsMonday ); 706 picker->slotWeekChange( weekStartsMonday );
707 picker->setDate( currDate.year(), currDate.month(), currDate.day() ); 707 picker->setDate( currDate.year(), currDate.month(), currDate.day() );
708 m1->popup(mapToGlobal(QPoint(0,height()))); 708 m1->popup(mapToGlobal(QPoint(0,height())));
709 picker->setFocus(); 709 picker->setFocus();
710} 710}
711 711
712 712
713void DateButton::gotHide() 713void DateButton::gotHide()
714{ 714{
715 // we have to redo the button... 715 // we have to redo the button...
716 setDown( false ); 716 setDown( false );
717} 717}
718 718
719 719
720// void dateSelected( int year, int month, int day ); 720// void dateSelected( int year, int month, int day );
721 721
722void DateButton::setWeekStartsMonday( int b ) 722void DateButton::setWeekStartsMonday( int b )
723{ 723{
724 weekStartsMonday = b; 724 weekStartsMonday = b;
725} 725}
726 726
727void DateButton::setDate( int y, int m, int d ) 727void DateButton::setDate( int y, int m, int d )
728{ 728{
729 setDate( QDate( y,m,d) ); 729 setDate( QDate( y,m,d) );
730} 730}
731 731
732void DateButton::setDate( QDate d ) 732void DateButton::setDate( QDate d )
733{ 733{
734 currDate = d; 734 currDate = d;
735 setText( longFormat ? TimeString::longDateString( d, df ) : 735 setText( longFormat ? TimeString::longDateString( d, df ) :
736 TimeString::shortDate( d, df ) ); 736 TimeString::shortDate( d, df ) );
737 737
738} 738}
739 739
740void DateButton::setDateFormat( DateFormat f ) 740void DateButton::setDateFormat( DateFormat f )
741{ 741{
742 df = f; 742 df = f;
743 setDate( currDate ); 743 setDate( currDate );
744} 744}
745 745
746bool DateButton::customWhatsThis() const 746bool DateButton::customWhatsThis() const
747{ 747{
748 return TRUE; 748 return TRUE;
749} 749}
750 750
751 751
752// this class is only here for Sharp ROM compatibility 752// this class is only here for Sharp ROM compatibility
753// I have reverse engineered this class and it seems to 753// I have reverse engineered this class and it seems to
754// work (only qtmail seems to use it) - sandman 754// work (only qtmail seems to use it) - sandman
755// DO NOT USE IT IN NEW CODE !! 755// DO NOT USE IT IN NEW CODE !!
756 756
757DateBookMonthPopup::DateBookMonthPopup ( QWidget *w ) 757DateBookMonthPopup::DateBookMonthPopup ( QWidget *w )
758 : QPopupMenu ( w ) 758 : QPopupMenu ( w )
759{ 759{
760 m_dbm = new DateBookMonth( this, 0, TRUE ); 760 m_dbm = new DateBookMonth( this, 0, TRUE );
761 insertItem( m_dbm ); 761 insertItem( m_dbm );
762} 762}
diff --git a/library/fileselector.cpp b/library/fileselector.cpp
index 7c29aba..93fb429 100644
--- a/library/fileselector.cpp
+++ b/library/fileselector.cpp
@@ -1,579 +1,579 @@
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// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT 21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
22// have this class. 22// have this class.
23#define QTOPIA_INTERNAL_FSLP 23#define QTOPIA_INTERNAL_FSLP
24 24
25#include "fileselector.h" 25#include "fileselector.h"
26#include "fileselector_p.h" 26#include "fileselector_p.h"
27#include "global.h" 27#include "global.h"
28#include "resource.h" 28#include "resource.h"
29#include "config.h" 29#include "config.h"
30#include "storage.h" 30#include "storage.h"
31#include "qpemenubar.h" 31#include "qpemenubar.h"
32#include <qcopchannel_qws.h> 32#include <qcopchannel_qws.h>
33#include "lnkproperties.h" 33#include "lnkproperties.h"
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include "categorymenu.h" 35#include "categorymenu.h"
36#include "categoryselect.h" 36#include "categoryselect.h"
37#include "mimetype.h" 37#include "mimetype.h"
38#include <qpe/categories.h> 38#include <qpe/categories.h>
39 39
40#include <stdlib.h> 40#include <stdlib.h>
41 41
42#include <qdir.h> 42#include <qdir.h>
43#include <qwidget.h> 43#include <qwidget.h>
44#include <qpopupmenu.h> 44#include <qpopupmenu.h>
45#include <qtoolbutton.h> 45#include <qtoolbutton.h>
46#include <qpushbutton.h> 46#include <qpushbutton.h>
47#include <qheader.h> 47#include <qheader.h>
48#include <qtooltip.h> 48#include <qtooltip.h>
49#include <qwhatsthis.h> 49#include <qwhatsthis.h>
50 50
51class TypeCombo : public QComboBox 51class TypeCombo : public QComboBox
52{ 52{
53 Q_OBJECT 53 Q_OBJECT
54public: 54public:
55 TypeCombo( QWidget *parent, const char *name=0 ) 55 TypeCombo( QWidget *parent, const char *name=0 )
56 : QComboBox( parent, name ) 56 : QComboBox( parent, name )
57 { 57 {
58 connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) ); 58 connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) );
59 } 59 }
60 60
61 void reread( DocLnkSet &files, const QString &filter ); 61 void reread( DocLnkSet &files, const QString &filter );
62 62
63signals: 63signals:
64 void selected( const QString & ); 64 void selected( const QString & );
65 65
66protected slots: 66protected slots:
67 void selectType( int idx ) { 67 void selectType( int idx ) {
68 emit selected( typelist[idx] ); 68 emit selected( typelist[idx] );
69 } 69 }
70 70
71protected: 71protected:
72 QStringList typelist; 72 QStringList typelist;
73 QString prev; 73 QString prev;
74}; 74};
75 75
76void TypeCombo::reread( DocLnkSet &files, const QString &filter ) 76void TypeCombo::reread( DocLnkSet &files, const QString &filter )
77{ 77{
78 typelist.clear(); 78 typelist.clear();
79 QStringList filters = QStringList::split( ';', filter ); 79 QStringList filters = QStringList::split( ';', filter );
80 int pos = filter.find( '/' ); 80 int pos = filter.find( '/' );
81 //### do for each filter 81 //### do for each filter
82 if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) { 82 if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) {
83 typelist.append( filter ); 83 typelist.append( filter );
84 clear(); 84 clear();
85 QString minor = filter.mid( pos+1 ); 85 QString minor = filter.mid( pos+1 );
86 minor[0] = minor[0].upper(); 86 minor[0] = minor[0].upper();
87 insertItem( tr("%1 files").arg(minor) ); 87 insertItem( tr("%1 files").arg(minor) );
88 setCurrentItem(0); 88 setCurrentItem(0);
89 setEnabled( FALSE ); 89 setEnabled( FALSE );
90 return; 90 return;
91 } 91 }
92 92
93 QListIterator<DocLnk> dit( files.children() ); 93 QListIterator<DocLnk> dit( files.children() );
94 for ( ; dit.current(); ++dit ) { 94 for ( ; dit.current(); ++dit ) {
95 if ( !typelist.contains( (*dit)->type() ) ) 95 if ( !typelist.contains( (*dit)->type() ) )
96 typelist.append( (*dit)->type() ); 96 typelist.append( (*dit)->type() );
97 } 97 }
98 98
99 QStringList types; 99 QStringList types;
100 QStringList::ConstIterator it; 100 QStringList::ConstIterator it;
101 for (it = typelist.begin(); it!=typelist.end(); ++it) { 101 for (it = typelist.begin(); it!=typelist.end(); ++it) {
102 QString t = *it; 102 QString t = *it;
103 if ( t.left(12) == "application/" ) { 103 if ( t.left(12) == "application/" ) {
104 MimeType mt(t); 104 MimeType mt(t);
105 const AppLnk* app = mt.application(); 105 const AppLnk* app = mt.application();
106 if ( app ) 106 if ( app )
107 t = app->name(); 107 t = app->name();
108 else 108 else
109 t = t.mid(12); 109 t = t.mid(12);
110 } else { 110 } else {
111 QString major, minor; 111 QString major, minor;
112 int pos = t.find( '/' ); 112 int pos = t.find( '/' );
113 if ( pos >= 0 ) { 113 if ( pos >= 0 ) {
114 major = t.left( pos ); 114 major = t.left( pos );
115 minor = t.mid( pos+1 ); 115 minor = t.mid( pos+1 );
116 } 116 }
117 if ( minor.find( "x-" ) == 0 ) 117 if ( minor.find( "x-" ) == 0 )
118 minor = minor.mid( 2 ); 118 minor = minor.mid( 2 );
119 minor[0] = minor[0].upper(); 119 minor[0] = minor[0].upper();
120 major[0] = major[0].upper(); 120 major[0] = major[0].upper();
121 if ( filters.count() > 1 ) 121 if ( filters.count() > 1 )
122 t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major); 122 t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major);
123 else 123 else
124 t = minor; 124 t = minor;
125 } 125 }
126 types += tr("%1 files").arg(t); 126 types += tr("%1 files").arg(t);
127 } 127 }
128 for (it = filters.begin(); it!=filters.end(); ++it) { 128 for (it = filters.begin(); it!=filters.end(); ++it) {
129 typelist.append( *it ); 129 typelist.append( *it );
130 int pos = (*it).find( '/' ); 130 int pos = (*it).find( '/' );
131 if ( pos >= 0 ) { 131 if ( pos >= 0 ) {
132 QString maj = (*it).left( pos ); 132 QString maj = (*it).left( pos );
133 maj[0] = maj[0].upper(); 133 maj[0] = maj[0].upper();
134 types << tr("All %1 files").arg(maj); 134 types << tr("All %1 files").arg(maj);
135 } 135 }
136 } 136 }
137 if ( filters.count() > 1 ) { 137 if ( filters.count() > 1 ) {
138 typelist.append( filter ); 138 typelist.append( filter );
139 types << tr("All files"); 139 types << tr("All files");
140 } 140 }
141 prev = currentText(); 141 prev = currentText();
142 clear(); 142 clear();
143 insertStringList(types); 143 insertStringList(types);
144 for (int i=0; i<count(); i++) { 144 for (int i=0; i<count(); i++) {
145 if ( text(i) == prev ) { 145 if ( text(i) == prev ) {
146 setCurrentItem(i); 146 setCurrentItem(i);
147 break; 147 break;
148 } 148 }
149 } 149 }
150 if ( prev.isNull() ) 150 if ( prev.isNull() )
151 setCurrentItem(count()-1); 151 setCurrentItem(count()-1);
152 setEnabled( TRUE ); 152 setEnabled( TRUE );
153} 153}
154 154
155 155
156//=========================================================================== 156//===========================================================================
157 157
158FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f ) 158FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f )
159 : QListViewItem( parent ), fl( f ) 159 : QListViewItem( parent ), fl( f )
160{ 160{
161 setText( 0, f.name() ); 161 setText( 0, f.name() );
162 setPixmap( 0, f.pixmap() ); 162 setPixmap( 0, f.pixmap() );
163} 163}
164 164
165FileSelectorItem::~FileSelectorItem() 165FileSelectorItem::~FileSelectorItem()
166{ 166{
167} 167}
168 168
169FileSelectorView::FileSelectorView( QWidget *parent, const char *name ) 169FileSelectorView::FileSelectorView( QWidget *parent, const char *name )
170 : QListView( parent, name ) 170 : QListView( parent, name )
171{ 171{
172 setAllColumnsShowFocus( TRUE ); 172 setAllColumnsShowFocus( TRUE );
173 addColumn( tr( "Name" ) ); 173 addColumn( tr( "Name" ) );
174 header()->hide(); 174 header()->hide();
175} 175}
176 176
177FileSelectorView::~FileSelectorView() 177FileSelectorView::~FileSelectorView()
178{ 178{
179} 179}
180 180
181void FileSelectorView::keyPressEvent( QKeyEvent *e ) 181void FileSelectorView::keyPressEvent( QKeyEvent *e )
182{ 182{
183 QString txt = e->text(); 183 QString txt = e->text();
184 if (e->key() == Key_Space) 184 if (e->key() == Key_Space)
185 emit returnPressed( currentItem() ); 185 emit returnPressed( currentItem() );
186 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) 186 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 )
187 e->ignore(); 187 e->ignore();
188 else 188 else
189 QListView::keyPressEvent(e); 189 QListView::keyPressEvent(e);
190} 190}
191 191
192class NewDocItem : public FileSelectorItem 192class NewDocItem : public FileSelectorItem
193{ 193{
194public: 194public:
195 NewDocItem( QListView *parent, const DocLnk &f ) 195 NewDocItem( QListView *parent, const DocLnk &f )
196 : FileSelectorItem( parent, f ) { 196 : FileSelectorItem( parent, f ) {
197 setText( 0, QObject::tr("New Document") ); 197 setText( 0, QObject::tr("New Document") );
198 QImage img( Resource::loadImage( "new" ) ); 198 QImage img( Resource::loadImage( "new" ) );
199 QPixmap pm; 199 QPixmap pm;
200 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 200 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
201 setPixmap( 0, pm ); 201 setPixmap( 0, pm );
202 } 202 }
203 QString key ( int, bool ) const { 203 QString key ( int, bool ) const {
204 return QString("\n"); 204 return QString("\n");
205 } 205 }
206 206
207 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { 207 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) {
208 QFont oldFont = p->font(); 208 QFont oldFont = p->font();
209 QFont newFont = p->font(); 209 QFont newFont = p->font();
210 newFont.setWeight( QFont::Bold ); 210 newFont.setWeight( QFont::Bold );
211 p->setFont( newFont ); 211 p->setFont( newFont );
212 FileSelectorItem::paintCell( p, cg, column, width, alignment ); 212 FileSelectorItem::paintCell( p, cg, column, width, alignment );
213 p->setFont( oldFont ); 213 p->setFont( oldFont );
214 } 214 }
215 215
216 int width( const QFontMetrics &fm, const QListView *v, int c ) const { 216 int width( const QFontMetrics &fm, const QListView *v, int c ) const {
217 return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font 217 return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font
218 } 218 }
219}; 219};
220 220
221//=========================================================================== 221//===========================================================================
222 222
223class FileSelectorPrivate 223class FileSelectorPrivate
224{ 224{
225public: 225public:
226 TypeCombo *typeCombo; 226 TypeCombo *typeCombo;
227 CategorySelect *catSelect; 227 CategorySelect *catSelect;
228 QValueList<QRegExp> mimeFilters; 228 QValueList<QRegExp> mimeFilters;
229 int catId; 229 int catId;
230 bool showNew; 230 bool showNew;
231 NewDocItem *newDocItem; 231 NewDocItem *newDocItem;
232 DocLnkSet files; 232 DocLnkSet files;
233 QHBox *toolbar; 233 QHBox *toolbar;
234}; 234};
235 235
236/*! 236/*!
237 \class FileSelector fileselector.h 237 \class FileSelector fileselector.h
238 \brief The FileSelector widget allows the user to select DocLnk objects. 238 \brief The FileSelector widget allows the user to select DocLnk objects.
239 239
240 This class presents a file selection dialog to the user. This widget 240 This class presents a file selection dialog to the user. This widget
241 is usually the first widget seen in a \link docwidget.html 241 is usually the first widget seen in a \link docwidget.html
242 document-oriented application\endlink. The developer will most often 242 document-oriented application\endlink. The developer will most often
243 create this widget in combination with a <a 243 create this widget in combination with a <a
244 href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate 244 href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate
245 editor and/or viewer widget for their application. This widget 245 editor and/or viewer widget for their application. This widget
246 should be shown first and the user can the select which document 246 should be shown first and the user can the select which document
247 they wish to operate on. Please refer to the implementation of 247 they wish to operate on. Please refer to the implementation of
248 texteditor for an example of how to tie these classes together. 248 texteditor for an example of how to tie these classes together.
249 249
250 Use setNewVisible() depending on whether the application can be used 250 Use setNewVisible() depending on whether the application can be used
251 to create new files or not. Use setCloseVisible() depending on 251 to create new files or not. Use setCloseVisible() depending on
252 whether the user may leave the dialog without creating or selecting 252 whether the user may leave the dialog without creating or selecting
253 a document or not. The number of files in the view is available from 253 a document or not. The number of files in the view is available from
254 fileCount(). To force the view to be updated call reread(). 254 fileCount(). To force the view to be updated call reread().
255 255
256 If the user presses the 'New Document' button the newSelected() 256 If the user presses the 'New Document' button the newSelected()
257 signal is emitted. If the user selects an existing file the 257 signal is emitted. If the user selects an existing file the
258 fileSelected() signal is emitted. The selected file's \link 258 fileSelected() signal is emitted. The selected file's \link
259 doclnk.html DocLnk\endlink is available from the selected() 259 doclnk.html DocLnk\endlink is available from the selected()
260 function. If the file selector is no longer necessary the closeMe() 260 function. If the file selector is no longer necessary the closeMe()
261 signal is emitted. 261 signal is emitted.
262 262
263 \ingroup qtopiaemb 263 \ingroup qtopiaemb
264 \sa FileManager 264 \sa FileManager
265*/ 265*/
266 266
267/*! 267/*!
268 Constructs a FileSelector with mime filter \a f. 268 Constructs a FileSelector with mime filter \a f.
269 The standard Qt \a parent and \a name parameters are passed to the 269 The standard Qt \a parent and \a name parameters are passed to the
270 parent widget. 270 parent widget.
271 271
272 If \a newVisible is TRUE, the widget has a button to allow the user 272 If \a newVisible is TRUE, the widget has a button to allow the user
273 the create "new" documents; this is useful for applications that can 273 the create "new" documents; this is useful for applications that can
274 create and edit documents but not suitable for applications that 274 create and edit documents but not suitable for applications that
275 only provide viewing. 275 only provide viewing.
276 276
277 \a closeVisible is deprecated 277 \a closeVisible is deprecated
278 278
279 \sa DocLnkSet::DocLnkSet() 279 \sa DocLnkSet::DocLnkSet()
280*/ 280*/
281FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) 281FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible )
282 : QVBox( parent, name ), filter( f ) 282 : QVBox( parent, name ), filter( f )
283{ 283{
284 setMargin( 0 ); 284 setMargin( 0 );
285 setSpacing( 0 ); 285 setSpacing( 0 );
286 286
287 d = new FileSelectorPrivate(); 287 d = new FileSelectorPrivate();
288 d->newDocItem = 0; 288 d->newDocItem = 0;
289 d->showNew = newVisible; 289 d->showNew = newVisible;
290 d->catId = -2; // All files 290 d->catId = -2; // All files
291 291
292 d->toolbar = new QHBox( this ); 292 d->toolbar = new QHBox( this );
293 d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars 293 d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars
294 d->toolbar->setSpacing( 0 ); 294 d->toolbar->setSpacing( 0 );
295 d->toolbar->hide(); 295 d->toolbar->hide();
296 296
297 QWidget *spacer = new QWidget( d->toolbar ); 297 QWidget *spacer = new QWidget( d->toolbar );
298 spacer->setBackgroundMode( PaletteButton ); 298 spacer->setBackgroundMode( PaletteButton );
299 299
300 QToolButton *tb = new QToolButton( d->toolbar ); 300 QToolButton *tb = new QToolButton( d->toolbar );
301 tb->setPixmap( Resource::loadPixmap( "close" ) ); 301 tb->setPixmap( Resource::loadPixmap( "close" ) );
302 connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) ); 302 connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) );
303 buttonClose = tb; 303 buttonClose = tb;
304 tb->setFixedSize( 18, 20 ); // tb->sizeHint() ); 304 tb->setFixedSize( 18, 20 ); // tb->sizeHint() );
305 tb->setAutoRaise( TRUE ); 305 tb->setAutoRaise( TRUE );
306 QToolTip::add( tb, tr( "Close the File Selector" ) ); 306 QToolTip::add( tb, tr( "Close the File Selector" ) );
307 QPEMenuToolFocusManager::manager()->addWidget( tb ); 307 QPEMenuToolFocusManager::manager()->addWidget( tb );
308 308
309 view = new FileSelectorView( this, "fileview" ); 309 view = new FileSelectorView( this, "fileview" );
310 QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold ); 310 QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold );
311 connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), 311 connect( view, SIGNAL( mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),
312 this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) ); 312 this, SLOT( fileClicked(int,QListViewItem*,const QPoint&,int) ) );
313 connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ), 313 connect( view, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
314 this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) ); 314 this, SLOT( filePressed(int,QListViewItem*,const QPoint&,int) ) );
315 connect( view, SIGNAL( returnPressed( QListViewItem * ) ), 315 connect( view, SIGNAL( returnPressed(QListViewItem*) ),
316 this, SLOT( fileClicked( QListViewItem * ) ) ); 316 this, SLOT( fileClicked(QListViewItem*) ) );
317 317
318 QHBox *hb = new QHBox( this ); 318 QHBox *hb = new QHBox( this );
319 319
320 d->typeCombo = new TypeCombo( hb ); 320 d->typeCombo = new TypeCombo( hb );
321 connect( d->typeCombo, SIGNAL(selected(const QString&)), 321 connect( d->typeCombo, SIGNAL(selected(const QString&)),
322 this, SLOT(typeSelected(const QString&)) ); 322 this, SLOT(typeSelected(const QString&)) );
323 QWhatsThis::add( d->typeCombo, tr("Show documents of this type") ); 323 QWhatsThis::add( d->typeCombo, tr("Show documents of this type") );
324 324
325 Categories c; 325 Categories c;
326 c.load(categoryFileName()); 326 c.load(categoryFileName());
327 QArray<int> vl( 0 ); 327 QArray<int> vl( 0 );
328 d->catSelect = new CategorySelect( hb ); 328 d->catSelect = new CategorySelect( hb );
329 d->catSelect->setRemoveCategoryEdit( TRUE ); 329 d->catSelect->setRemoveCategoryEdit( TRUE );
330 d->catSelect->setCategories( vl, "Document View", tr("Document View") ); 330 d->catSelect->setCategories( vl, "Document View", tr("Document View") );
331 d->catSelect->setAllCategories( TRUE ); 331 d->catSelect->setAllCategories( TRUE );
332 connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) ); 332 connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) );
333 QWhatsThis::add( d->catSelect, tr("Show documents in this category") ); 333 QWhatsThis::add( d->catSelect, tr("Show documents in this category") );
334 334
335 setCloseVisible( closeVisible ); 335 setCloseVisible( closeVisible );
336 336
337 QCopChannel *channel = new QCopChannel( "QPE/Card", this ); 337 QCopChannel *channel = new QCopChannel( "QPE/Card", this );
338 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 338 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
339 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 339 this, SLOT(cardMessage(const QCString&,const QByteArray&)) );
340 340
341 reread(); 341 reread();
342 updateWhatsThis(); 342 updateWhatsThis();
343} 343}
344 344
345/*! 345/*!
346 Destroys the widget. 346 Destroys the widget.
347*/ 347*/
348FileSelector::~FileSelector() 348FileSelector::~FileSelector()
349{ 349{
350 delete d; 350 delete d;
351} 351}
352 352
353/*! 353/*!
354 Returns the number of files in the view. If this is zero, an editor 354 Returns the number of files in the view. If this is zero, an editor
355 application might bypass the selector and immediately start with 355 application might bypass the selector and immediately start with
356 a "new" document. 356 a "new" document.
357*/ 357*/
358int FileSelector::fileCount() 358int FileSelector::fileCount()
359{ 359{
360 return d->files.children().count();; 360 return d->files.children().count();;
361} 361}
362 362
363/*! 363/*!
364 Calling this function is the programmatic equivalent of the user 364 Calling this function is the programmatic equivalent of the user
365 pressing the "new" button. 365 pressing the "new" button.
366 366
367 \sa newSelected(), closeMe() 367 \sa newSelected(), closeMe()
368*/ 368*/
369void FileSelector::createNew() 369void FileSelector::createNew()
370{ 370{
371 DocLnk f; 371 DocLnk f;
372 emit newSelected( f ); 372 emit newSelected( f );
373 emit closeMe(); 373 emit closeMe();
374} 374}
375 375
376void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) 376void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int )
377{ 377{
378 if ( !i ) 378 if ( !i )
379 return; 379 return;
380 if ( button == Qt::LeftButton ) { 380 if ( button == Qt::LeftButton ) {
381 fileClicked( i ); 381 fileClicked( i );
382 } 382 }
383} 383}
384 384
385void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int ) 385void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int )
386{ 386{
387 if ( !i || i == d->newDocItem ) 387 if ( !i || i == d->newDocItem )
388 return; 388 return;
389 if ( button == Qt::RightButton ) { 389 if ( button == Qt::RightButton ) {
390 DocLnk l = ((FileSelectorItem *)i)->file(); 390 DocLnk l = ((FileSelectorItem *)i)->file();
391 LnkProperties prop( &l ); 391 LnkProperties prop( &l );
392 prop.showMaximized(); 392 prop.showMaximized();
393 prop.exec(); 393 prop.exec();
394 reread(); 394 reread();
395 } 395 }
396} 396}
397 397
398void FileSelector::fileClicked( QListViewItem *i ) 398void FileSelector::fileClicked( QListViewItem *i )
399{ 399{
400 if ( !i ) 400 if ( !i )
401 return; 401 return;
402 if ( i == d->newDocItem ) { 402 if ( i == d->newDocItem ) {
403 createNew(); 403 createNew();
404 } else { 404 } else {
405 emit fileSelected( ( (FileSelectorItem*)i )->file() ); 405 emit fileSelected( ( (FileSelectorItem*)i )->file() );
406 emit closeMe(); 406 emit closeMe();
407 } 407 }
408} 408}
409 409
410void FileSelector::typeSelected( const QString &type ) 410void FileSelector::typeSelected( const QString &type )
411{ 411{
412 d->mimeFilters.clear(); 412 d->mimeFilters.clear();
413 QStringList subFilter = QStringList::split(";", type); 413 QStringList subFilter = QStringList::split(";", type);
414 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it ) 414 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it )
415 d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); 415 d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
416 updateView(); 416 updateView();
417} 417}
418 418
419void FileSelector::catSelected( int c ) 419void FileSelector::catSelected( int c )
420{ 420{
421 d->catId = c; 421 d->catId = c;
422 updateView(); 422 updateView();
423} 423}
424 424
425void FileSelector::cardMessage( const QCString &msg, const QByteArray &) 425void FileSelector::cardMessage( const QCString &msg, const QByteArray &)
426{ 426{
427 if ( msg == "mtabChanged()" ) 427 if ( msg == "mtabChanged()" )
428 reread(); 428 reread();
429} 429}
430 430
431 431
432/*! 432/*!
433 Returns the selected \link doclnk.html DocLnk\endlink. The caller is 433 Returns the selected \link doclnk.html DocLnk\endlink. The caller is
434 responsible for deleting the returned value. 434 responsible for deleting the returned value.
435*/ 435*/
436const DocLnk *FileSelector::selected() 436const DocLnk *FileSelector::selected()
437{ 437{
438 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); 438 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
439 if ( item && item != d->newDocItem ) 439 if ( item && item != d->newDocItem )
440 return new DocLnk( item->file() ); 440 return new DocLnk( item->file() );
441 return NULL; 441 return NULL;
442} 442}
443 443
444/*! 444/*!
445 \fn void FileSelector::fileSelected( const DocLnk &f ) 445 \fn void FileSelector::fileSelected( const DocLnk &f )
446 446
447 This signal is emitted when the user selects a document. 447 This signal is emitted when the user selects a document.
448 \a f is the document. 448 \a f is the document.
449*/ 449*/
450 450
451/*! 451/*!
452 \fn void FileSelector::newSelected( const DocLnk &f ) 452 \fn void FileSelector::newSelected( const DocLnk &f )
453 453
454 This signal is emitted when the user selects a "new" document. 454 This signal is emitted when the user selects a "new" document.
455 \a f is a DocLnk for the document. You will need to set the type 455 \a f is a DocLnk for the document. You will need to set the type
456 of the document after copying it. 456 of the document after copying it.
457*/ 457*/
458 458
459/*! 459/*!
460 \fn void FileSelector::closeMe() 460 \fn void FileSelector::closeMe()
461 461
462 This signal is emitted when the user no longer needs to view the widget. 462 This signal is emitted when the user no longer needs to view the widget.
463*/ 463*/
464 464
465 465
466/*! 466/*!
467 If \a b is TRUE a "new document" entry is visible; if \a b is FALSE 467 If \a b is TRUE a "new document" entry is visible; if \a b is FALSE
468 this entry is not visible and the user is unable to create new 468 this entry is not visible and the user is unable to create new
469 documents from the dialog. 469 documents from the dialog.
470*/ 470*/
471void FileSelector::setNewVisible( bool b ) 471void FileSelector::setNewVisible( bool b )
472{ 472{
473 if ( d->showNew != b ) { 473 if ( d->showNew != b ) {
474 d->showNew = b; 474 d->showNew = b;
475 updateView(); 475 updateView();
476 updateWhatsThis(); 476 updateWhatsThis();
477 } 477 }
478} 478}
479 479
480/*! 480/*!
481 If \a b is TRUE a "close" or "no document" button is visible; if \a 481 If \a b is TRUE a "close" or "no document" button is visible; if \a
482 b is FALSE this button is not visible and the user is unable to 482 b is FALSE this button is not visible and the user is unable to
483 leave the dialog without creating or selecting a document. 483 leave the dialog without creating or selecting a document.
484 484
485 This function is deprecated. 485 This function is deprecated.
486*/ 486*/
487void FileSelector::setCloseVisible( bool b ) 487void FileSelector::setCloseVisible( bool b )
488{ 488{
489 if ( b ) 489 if ( b )
490 d->toolbar->show(); 490 d->toolbar->show();
491 else 491 else
492 d->toolbar->hide(); 492 d->toolbar->hide();
493} 493}
494 494
495/*! 495/*!
496 496
497*/ 497*/
498void FileSelector::setTypeComboVisible( bool b ) { 498void FileSelector::setTypeComboVisible( bool b ) {
499 if ( b ) 499 if ( b )
500 d->typeCombo->show(); 500 d->typeCombo->show();
501 else 501 else
502 d->typeCombo->hide(); 502 d->typeCombo->hide();
503} 503}
504/*! 504/*!
505 505
506*/ 506*/
507void FileSelector::setCategorySelectVisible( bool b ) { 507void FileSelector::setCategorySelectVisible( bool b ) {
508 if ( b ) 508 if ( b )
509 d->catSelect->show(); 509 d->catSelect->show();
510 else 510 else
511 d->catSelect->hide(); 511 d->catSelect->hide();
512} 512}
513 513
514/*! 514/*!
515 Rereads the list of documents. 515 Rereads the list of documents.
516*/ 516*/
517void FileSelector::reread() 517void FileSelector::reread()
518{ 518{
519 d->files.clear(); 519 d->files.clear();
520 Global::findDocuments(&d->files, filter); 520 Global::findDocuments(&d->files, filter);
521 d->typeCombo->reread( d->files, filter ); 521 d->typeCombo->reread( d->files, filter );
522 updateView(); 522 updateView();
523} 523}
524 524
525void FileSelector::updateView() 525void FileSelector::updateView()
526{ 526{
527 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); 527 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
528 if ( item == d->newDocItem ) 528 if ( item == d->newDocItem )
529 item = 0; 529 item = 0;
530 QString oldFile; 530 QString oldFile;
531 if ( item ) 531 if ( item )
532 oldFile = item->file().file(); 532 oldFile = item->file().file();
533 view->clear(); 533 view->clear();
534 QListIterator<DocLnk> dit( d->files.children() ); 534 QListIterator<DocLnk> dit( d->files.children() );
535 for ( ; dit.current(); ++dit ) { 535 for ( ; dit.current(); ++dit ) {
536 bool mimeMatch = FALSE; 536 bool mimeMatch = FALSE;
537 if ( d->mimeFilters.count() ) { 537 if ( d->mimeFilters.count() ) {
538 QValueList<QRegExp>::Iterator it; 538 QValueList<QRegExp>::Iterator it;
539 for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) { 539 for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) {
540 if ( (*it).match((*dit)->type()) >= 0 ) { 540 if ( (*it).match((*dit)->type()) >= 0 ) {
541 mimeMatch = TRUE; 541 mimeMatch = TRUE;
542 break; 542 break;
543 } 543 }
544 } 544 }
545 } else { 545 } else {
546 mimeMatch = TRUE; 546 mimeMatch = TRUE;
547 } 547 }
548 if ( mimeMatch && 548 if ( mimeMatch &&
549 (d->catId == -2 || (*dit)->categories().contains(d->catId) || 549 (d->catId == -2 || (*dit)->categories().contains(d->catId) ||
550 (d->catId == -1 && (*dit)->categories().isEmpty())) ) { 550 (d->catId == -1 && (*dit)->categories().isEmpty())) ) {
551 item = new FileSelectorItem( view, **dit ); 551 item = new FileSelectorItem( view, **dit );
552 if ( item->file().file() == oldFile ) 552 if ( item->file().file() == oldFile )
553 view->setCurrentItem( item ); 553 view->setCurrentItem( item );
554 } 554 }
555 } 555 }
556 556
557 if ( d->showNew ) 557 if ( d->showNew )
558 d->newDocItem = new NewDocItem( view, DocLnk() ); 558 d->newDocItem = new NewDocItem( view, DocLnk() );
559 else 559 else
560 d->newDocItem = 0; 560 d->newDocItem = 0;
561 561
562 if ( !view->selectedItem() || view->childCount() == 1 ) { 562 if ( !view->selectedItem() || view->childCount() == 1 ) {
563 view->setCurrentItem( view->firstChild() ); 563 view->setCurrentItem( view->firstChild() );
564 view->setSelected( view->firstChild(), TRUE ); 564 view->setSelected( view->firstChild(), TRUE );
565 } 565 }
566} 566}
567 567
568void FileSelector::updateWhatsThis() 568void FileSelector::updateWhatsThis()
569{ 569{
570 QWhatsThis::remove( this ); 570 QWhatsThis::remove( this );
571 QString text = tr("Click to select a document from the list"); 571 QString text = tr("Click to select a document from the list");
572 if ( d->showNew ) 572 if ( d->showNew )
573 text += tr(", or select <b>New Document</b> to create a new document."); 573 text += tr(", or select <b>New Document</b> to create a new document.");
574 text += tr("<br><br>Click and hold for document properties."); 574 text += tr("<br><br>Click and hold for document properties.");
575 QWhatsThis::add( this, text ); 575 QWhatsThis::add( this, text );
576} 576}
577 577
578#include "fileselector.moc" 578#include "fileselector.moc"
579 579
diff --git a/library/finddialog.cpp b/library/finddialog.cpp
index 64487c9..9417179 100644
--- a/library/finddialog.cpp
+++ b/library/finddialog.cpp
@@ -1,84 +1,80 @@
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// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT 21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
22// have this class. 22// have this class.
23#define QTOPIA_INTERNAL_FD 23#define QTOPIA_INTERNAL_FD
24 24
25#include "finddialog.h" 25#include "finddialog.h"
26#include "findwidget_p.h" 26#include "findwidget_p.h"
27 27
28#include <qlayout.h> 28#include <qlayout.h>
29 29
30/*! 30/*!
31 \class FindDialog finddialog.h 31 \class FindDialog finddialog.h
32 \brief A simple FindDialog 32 \brief A simple FindDialog
33 33
34 A find dialog. FIXME!!!! 34 A find dialog. FIXME!!!!
35 35
36*/ 36*/
37FindDialog::FindDialog( const QString &appName, QWidget *parent, 37FindDialog::FindDialog( const QString &appName, QWidget *parent,
38 const char *name, bool modal ) 38 const char *name, bool modal )
39 : QDialog( parent, name, modal ) 39 : QDialog( parent, name, modal )
40{ 40{
41 setCaption( tr("Find") ); 41 setCaption( tr("Find") );
42 QVBoxLayout *vb; 42 QVBoxLayout *vb;
43 vb = new QVBoxLayout( this ); 43 vb = new QVBoxLayout( this );
44 fw = new FindWidget( appName, this, "Find Widget" ); 44 fw = new FindWidget( appName, this, "Find Widget" );
45 vb->addWidget( fw ); 45 vb->addWidget( fw );
46 QObject::connect( fw, SIGNAL(signalFindClicked(const QString&, 46 QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,bool,bool,int)),
47 bool,bool,int)), 47 this, SIGNAL(signalFindClicked(const QString&,bool,bool,int)) );
48 this, SIGNAL(signalFindClicked(const QString&, 48 QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)),
49 bool,bool,int)) ); 49 this, SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)) );
50 QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,const QDate&,
51 bool,bool,int)),
52 this, SIGNAL(signalFindClicked(const QString&,
53 const QDate&,bool,bool,int)) );
54 d = 0; 50 d = 0;
55} 51}
56 52
57FindDialog::~FindDialog() 53FindDialog::~FindDialog()
58{ 54{
59} 55}
60 56
61QString FindDialog::findText() const 57QString FindDialog::findText() const
62{ 58{
63 return fw->findText(); 59 return fw->findText();
64} 60}
65 61
66void FindDialog::setUseDate( bool show ) 62void FindDialog::setUseDate( bool show )
67{ 63{
68 fw->setUseDate( show ); 64 fw->setUseDate( show );
69} 65}
70 66
71void FindDialog::setDate( const QDate &dt ) 67void FindDialog::setDate( const QDate &dt )
72{ 68{
73 fw->setDate( dt ); 69 fw->setDate( dt );
74} 70}
75 71
76void FindDialog::slotNotFound() 72void FindDialog::slotNotFound()
77{ 73{
78 fw->slotNotFound(); 74 fw->slotNotFound();
79} 75}
80 76
81void FindDialog::slotWrapAround() 77void FindDialog::slotWrapAround()
82{ 78{
83 fw->slotWrapAround(); 79 fw->slotWrapAround();
84} 80}
diff --git a/library/findwidget_p.cpp b/library/findwidget_p.cpp
index e91d789..0591f07 100644
--- a/library/findwidget_p.cpp
+++ b/library/findwidget_p.cpp
@@ -1,114 +1,114 @@
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 "findwidget_p.h" 21#include "findwidget_p.h"
22 22
23#include <qpe/categoryselect.h> 23#include <qpe/categoryselect.h>
24#include <qpe/datebookmonth.h> 24#include <qpe/datebookmonth.h>
25 25
26#include <qcheckbox.h> 26#include <qcheckbox.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qlineedit.h> 28#include <qlineedit.h>
29 29
30FindWidget::FindWidget( const QString &appName, QWidget *parent, 30FindWidget::FindWidget( const QString &appName, QWidget *parent,
31 const char *name ) 31 const char *name )
32 : FindWidgetBase( parent, name ), 32 : FindWidgetBase( parent, name ),
33 mStrApp( appName ), 33 mStrApp( appName ),
34 mDate( QDate::currentDate() ) 34 mDate( QDate::currentDate() )
35{ 35{
36 setMaximumSize( sizeHint() ); 36 setMaximumSize( sizeHint() );
37 QArray<int> vl(0); 37 QArray<int> vl(0);
38 cmbCat->setCategories( vl, mStrApp ); 38 cmbCat->setCategories( vl, mStrApp );
39 cmbCat->setRemoveCategoryEdit( TRUE ); 39 cmbCat->setRemoveCategoryEdit( TRUE );
40 cmbCat->setAllCategories( TRUE ); 40 cmbCat->setAllCategories( TRUE );
41 // hide junk for the moment... 41 // hide junk for the moment...
42 lblStartDate->hide(); 42 lblStartDate->hide();
43 cmdStartDate->hide(); 43 cmdStartDate->hide();
44 QPopupMenu *m1 = new QPopupMenu( this ); 44 QPopupMenu *m1 = new QPopupMenu( this );
45 dtPicker = new DateBookMonth( m1, 0, TRUE ); 45 dtPicker = new DateBookMonth( m1, 0, TRUE );
46 dtPicker->setDate( mDate.year(), mDate.month(), mDate.day() ); 46 dtPicker->setDate( mDate.year(), mDate.month(), mDate.day() );
47 m1->insertItem( dtPicker ); 47 m1->insertItem( dtPicker );
48 cmdStartDate->setPopup( m1 ); 48 cmdStartDate->setPopup( m1 );
49 cmdStartDate->setText( TimeString::shortDate(mDate) ); 49 cmdStartDate->setText( TimeString::shortDate(mDate) );
50 QObject::connect( dtPicker, SIGNAL(dateClicked(int, int, int)), 50 QObject::connect( dtPicker, SIGNAL(dateClicked(int,int,int)),
51 this, SLOT(slotDateChanged(int, int, int)) ); 51 this, SLOT(slotDateChanged(int,int,int)) );
52 52
53 QObject::connect( cmdFind, SIGNAL(clicked()), 53 QObject::connect( cmdFind, SIGNAL(clicked()),
54 this, SLOT(slotFindClicked()) ); 54 this, SLOT(slotFindClicked()) );
55} 55}
56 56
57FindWidget::~FindWidget() 57FindWidget::~FindWidget()
58{ 58{
59} 59}
60 60
61QString FindWidget::findText() const 61QString FindWidget::findText() const
62{ 62{
63 return txtFind->text(); 63 return txtFind->text();
64} 64}
65 65
66void FindWidget::slotFindClicked() 66void FindWidget::slotFindClicked()
67{ 67{
68 lblStatus->setText( "" ); 68 lblStatus->setText( "" );
69 if ( cmdStartDate->isVisible() ) 69 if ( cmdStartDate->isVisible() )
70 emit signalFindClicked( findText(), 70 emit signalFindClicked( findText(),
71 mDate, 71 mDate,
72 chkCase->isChecked(), 72 chkCase->isChecked(),
73 chkBackwards->isChecked(), 73 chkBackwards->isChecked(),
74 cmbCat->currentCategory() ); 74 cmbCat->currentCategory() );
75 else 75 else
76 emit signalFindClicked( findText(), chkCase->isChecked(), 76 emit signalFindClicked( findText(), chkCase->isChecked(),
77 chkBackwards->isChecked(), 77 chkBackwards->isChecked(),
78 cmbCat->currentCategory() ); 78 cmbCat->currentCategory() );
79} 79}
80 80
81void FindWidget::setUseDate( bool show ) 81void FindWidget::setUseDate( bool show )
82{ 82{
83 if ( show ) { 83 if ( show ) {
84 lblStartDate->show(); 84 lblStartDate->show();
85 cmdStartDate->show(); 85 cmdStartDate->show();
86 } else { 86 } else {
87 lblStartDate->hide(); 87 lblStartDate->hide();
88 cmdStartDate->hide(); 88 cmdStartDate->hide();
89 } 89 }
90 chkBackwards->setDisabled( show ); 90 chkBackwards->setDisabled( show );
91} 91}
92 92
93void FindWidget::setDate( const QDate &dt ) 93void FindWidget::setDate( const QDate &dt )
94{ 94{
95 slotDateChanged( dt.year(), dt.month(), dt.day() ); 95 slotDateChanged( dt.year(), dt.month(), dt.day() );
96} 96}
97 97
98void FindWidget::slotNotFound() 98void FindWidget::slotNotFound()
99{ 99{
100 lblStatus->setText( tr("String Not Found.") ); 100 lblStatus->setText( tr("String Not Found.") );
101} 101}
102 102
103void FindWidget::slotWrapAround() 103void FindWidget::slotWrapAround()
104{ 104{
105 lblStatus->setText( tr("End reached, starting at %1", "Date using TimeString::shortDate") 105 lblStatus->setText( tr("End reached, starting at %1", "Date using TimeString::shortDate")
106 .arg(TimeString::shortDate( mDate ) ) ); 106 .arg(TimeString::shortDate( mDate ) ) );
107} 107}
108 108
109void FindWidget::slotDateChanged( int year, int month, int day ) 109void FindWidget::slotDateChanged( int year, int month, int day )
110{ 110{
111 mDate.setYMD( year, month, day ); 111 mDate.setYMD( year, month, day );
112 cmdStartDate->setText( TimeString::shortDate( mDate ) ); 112 cmdStartDate->setText( TimeString::shortDate( mDate ) );
113 dtPicker->setDate( year, month, day ); 113 dtPicker->setDate( year, month, day );
114} 114}
diff --git a/library/ir.cpp b/library/ir.cpp
index 32c0925..c581eb1 100644
--- a/library/ir.cpp
+++ b/library/ir.cpp
@@ -1,116 +1,116 @@
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 "ir.h" 21#include "ir.h"
22 22
23#include "qcopenvelope_qws.h" 23#include "qcopenvelope_qws.h"
24#include "applnk.h" 24#include "applnk.h"
25 25
26/*! 26/*!
27 \class Ir ir.h 27 \class Ir ir.h
28 \brief The Ir class implements basic support for sending objects over an 28 \brief The Ir class implements basic support for sending objects over an
29 infrared communication link. 29 infrared communication link.
30 30
31 Both \link doclnk.html DocLnk\endlink objects and files can be 31 Both \link doclnk.html DocLnk\endlink objects and files can be
32 sent to another device via the infrared link using the send() 32 sent to another device via the infrared link using the send()
33 function. When the send has completed the done() signal is 33 function. When the send has completed the done() signal is
34 emitted. 34 emitted.
35 35
36 The supported() function returns whether the device supports 36 The supported() function returns whether the device supports
37 infrared communication or not. 37 infrared communication or not.
38 38
39 \ingroup qtopiaemb 39 \ingroup qtopiaemb
40*/ 40*/
41 41
42/*! 42/*!
43 Constructs an Ir object. The \a parent and \a name classes are the 43 Constructs an Ir object. The \a parent and \a name classes are the
44 standard QObject parameters. 44 standard QObject parameters.
45*/ 45*/
46Ir::Ir( QObject *parent, const char *name ) 46Ir::Ir( QObject *parent, const char *name )
47 : QObject( parent, name ) 47 : QObject( parent, name )
48{ 48{
49#ifndef QT_NO_COP 49#ifndef QT_NO_COP
50 ch = new QCopChannel( "QPE/Obex" ); 50 ch = new QCopChannel( "QPE/Obex" );
51 connect( ch, SIGNAL(received(const QCString &, const QByteArray &)), 51 connect( ch, SIGNAL(received(const QCString&,const QByteArray&)),
52 this, SLOT(obexMessage( const QCString &, const QByteArray &)) ); 52 this, SLOT(obexMessage(const QCString&,const QByteArray&)) );
53#endif 53#endif
54} 54}
55 55
56/*! 56/*!
57 Returns TRUE if the system supports infrared communication; 57 Returns TRUE if the system supports infrared communication;
58 otherwise returns FALSE. 58 otherwise returns FALSE.
59*/ 59*/
60bool Ir::supported() 60bool Ir::supported()
61{ 61{
62#ifndef QT_NO_COP 62#ifndef QT_NO_COP
63 return QCopChannel::isRegistered( "QPE/Obex" ); 63 return QCopChannel::isRegistered( "QPE/Obex" );
64#endif 64#endif
65} 65}
66 66
67/*! 67/*!
68 Sends the object in file \a fn over the infrared link. The \a 68 Sends the object in file \a fn over the infrared link. The \a
69 description is used in the text shown to the user while sending 69 description is used in the text shown to the user while sending
70 is in progress. The optional \a mimetype parameter specifies the 70 is in progress. The optional \a mimetype parameter specifies the
71 mimetype of the object. If this parameter is not set, it is 71 mimetype of the object. If this parameter is not set, it is
72 determined by the the filename's suffix. 72 determined by the the filename's suffix.
73 73
74 \sa done() 74 \sa done()
75*/ 75*/
76void Ir::send( const QString &fn, const QString &description, const QString &mimetype) 76void Ir::send( const QString &fn, const QString &description, const QString &mimetype)
77{ 77{
78 if ( !filename.isEmpty() ) return; 78 if ( !filename.isEmpty() ) return;
79 filename = fn; 79 filename = fn;
80#ifndef QT_NO_COP 80#ifndef QT_NO_COP
81 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); 81 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
82 e << description << filename << mimetype; 82 e << description << filename << mimetype;
83#endif 83#endif
84} 84}
85 85
86/*! 86/*!
87 \overload 87 \overload
88 88
89 Uses the DocLnk::file() and DocLnk::type() of \a doc. 89 Uses the DocLnk::file() and DocLnk::type() of \a doc.
90 90
91 \sa done() 91 \sa done()
92*/ 92*/
93void Ir::send( const DocLnk &doc, const QString &description ) 93void Ir::send( const DocLnk &doc, const QString &description )
94{ 94{
95 send( doc.file(), description, doc.type() ); 95 send( doc.file(), description, doc.type() );
96} 96}
97 97
98/*! 98/*!
99 \fn Ir::done( Ir *ir ); 99 \fn Ir::done( Ir *ir );
100 100
101 This signal is emitted by \a ir, when the send comand has been processed. 101 This signal is emitted by \a ir, when the send comand has been processed.
102*/ 102*/
103 103
104/*!\internal 104/*!\internal
105 */ 105 */
106void Ir::obexMessage( const QCString &msg, const QByteArray &data) 106void Ir::obexMessage( const QCString &msg, const QByteArray &data)
107{ 107{
108 if ( msg == "done(QString)" ) { 108 if ( msg == "done(QString)" ) {
109 QString fn; 109 QString fn;
110 QDataStream stream( data, IO_ReadOnly ); 110 QDataStream stream( data, IO_ReadOnly );
111 stream >> fn; 111 stream >> fn;
112 if ( fn == filename ) 112 if ( fn == filename )
113 emit done( this ); 113 emit done( this );
114 } 114 }
115} 115}
116 116
diff --git a/library/network.cpp b/library/network.cpp
index 991e11a..df28857 100644
--- a/library/network.cpp
+++ b/library/network.cpp
@@ -1,448 +1,448 @@
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#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include "qpe/network.h" 22#include "qpe/network.h"
23#include "qpe/networkinterface.h" 23#include "qpe/networkinterface.h"
24#include "qpe/global.h" 24#include "qpe/global.h"
25#include "qpe/config.h" 25#include "qpe/config.h"
26#include "qpe/resource.h" 26#include "qpe/resource.h"
27#include "qpe/qpeapplication.h" 27#include "qpe/qpeapplication.h"
28#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29#include <qpe/qlibrary.h> 29#include <qpe/qlibrary.h>
30 30
31#include <qlistbox.h> 31#include <qlistbox.h>
32#include <qdir.h> 32#include <qdir.h>
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qdict.h> 34#include <qdict.h>
35#include <qtranslator.h> 35#include <qtranslator.h>
36 36
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39#ifndef QT_NO_COP 39#ifndef QT_NO_COP
40class NetworkEmitter : public QCopChannel { 40class NetworkEmitter : public QCopChannel {
41 Q_OBJECT 41 Q_OBJECT
42public: 42public:
43 NetworkEmitter() : QCopChannel("QPE/Network",qApp) 43 NetworkEmitter() : QCopChannel("QPE/Network",qApp)
44 { 44 {
45 } 45 }
46 46
47 void receive(const QCString &msg, const QByteArray&) 47 void receive(const QCString &msg, const QByteArray&)
48 { 48 {
49 if ( msg == "choicesChanged()" ) 49 if ( msg == "choicesChanged()" )
50 emit changed(); 50 emit changed();
51 } 51 }
52 52
53signals: 53signals:
54 void changed(); 54 void changed();
55}; 55};
56 56
57/*! 57/*!
58 \internal 58 \internal
59 59
60 Requests that the service \a choice be started. The \a password is 60 Requests that the service \a choice be started. The \a password is
61 the password to use if required. 61 the password to use if required.
62*/ 62*/
63void Network::start(const QString& choice, const QString& password) 63void Network::start(const QString& choice, const QString& password)
64{ 64{
65 QCopEnvelope e("QPE/Network", "start(QString,QString)"); 65 QCopEnvelope e("QPE/Network", "start(QString,QString)");
66 e << choice << password; 66 e << choice << password;
67} 67}
68 68
69/*! 69/*!
70 \class Network network.h 70 \class Network network.h
71 \brief The Network class provides network access functionality. 71 \brief The Network class provides network access functionality.
72 \internal 72 \internal
73*/ 73*/
74 74
75// copy the proxy settings of the active config over to the Proxies.conf file 75// copy the proxy settings of the active config over to the Proxies.conf file
76/*! 76/*!
77 \internal 77 \internal
78*/ 78*/
79void Network::writeProxySettings( Config &cfg ) 79void Network::writeProxySettings( Config &cfg )
80{ 80{
81 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File ); 81 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File );
82 proxy.setGroup("Properties"); 82 proxy.setGroup("Properties");
83 cfg.setGroup("Proxy"); 83 cfg.setGroup("Proxy");
84 proxy.writeEntry("type", cfg.readEntry("type") ); 84 proxy.writeEntry("type", cfg.readEntry("type") );
85 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") ); 85 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") );
86 proxy.writeEntry("httphost", cfg.readEntry("httphost") ); 86 proxy.writeEntry("httphost", cfg.readEntry("httphost") );
87 proxy.writeEntry("httpport", cfg.readEntry("httpport") ); 87 proxy.writeEntry("httpport", cfg.readEntry("httpport") );
88 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") ); 88 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") );
89 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") ); 89 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") );
90 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") ); 90 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") );
91 cfg.setGroup("Properties"); 91 cfg.setGroup("Properties");
92} 92}
93 93
94 94
95 95
96/*! 96/*!
97 \internal 97 \internal
98 98
99 Stops the current network service. 99 Stops the current network service.
100*/ 100*/
101void Network::stop() 101void Network::stop()
102{ 102{
103 QCopEnvelope e("QPE/Network", "stop()"); 103 QCopEnvelope e("QPE/Network", "stop()");
104} 104}
105 105
106static NetworkEmitter *emitter = 0; 106static NetworkEmitter *emitter = 0;
107 107
108/*! 108/*!
109 \internal 109 \internal
110*/ 110*/
111void Network::connectChoiceChange(QObject* receiver, const char* slot) 111void Network::connectChoiceChange(QObject* receiver, const char* slot)
112{ 112{
113 if ( !emitter ) 113 if ( !emitter )
114 emitter = new NetworkEmitter; 114 emitter = new NetworkEmitter;
115 QObject::connect(emitter,SIGNAL(changed()),receiver,slot); 115 QObject::connect(emitter,SIGNAL(changed()),receiver,slot);
116} 116}
117 117
118 #endif// QT_NO_COP 118 #endif// QT_NO_COP
119/*! 119/*!
120 \internal 120 \internal
121*/ 121*/
122QString Network::settingsDir() 122QString Network::settingsDir()
123{ 123{
124 return Global::applicationFileName("Network", "modules"); 124 return Global::applicationFileName("Network", "modules");
125} 125}
126 126
127#ifndef QT_NO_COP 127#ifndef QT_NO_COP
128/*! 128/*!
129 \internal 129 \internal
130*/ 130*/
131QStringList Network::choices(QListBox* lb, const QString& dir) 131QStringList Network::choices(QListBox* lb, const QString& dir)
132{ 132{
133 QStringList list; 133 QStringList list;
134 134
135 if ( lb ) 135 if ( lb )
136 lb->clear(); 136 lb->clear();
137 137
138 QString adir = dir.isEmpty() ? settingsDir() : dir; 138 QString adir = dir.isEmpty() ? settingsDir() : dir;
139 QDir settingsdir(adir); 139 QDir settingsdir(adir);
140 settingsdir.mkdir(adir); 140 settingsdir.mkdir(adir);
141 141
142 QStringList files = settingsdir.entryList("*.conf"); 142 QStringList files = settingsdir.entryList("*.conf");
143 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) { 143 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) {
144 QString filename = settingsdir.filePath(*it); 144 QString filename = settingsdir.filePath(*it);
145 Config cfg(filename, Config::File); 145 Config cfg(filename, Config::File);
146 cfg.setGroup("Info"); 146 cfg.setGroup("Info");
147 if ( lb ) 147 if ( lb )
148 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")), 148 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")),
149 cfg.readEntry("Name")); 149 cfg.readEntry("Name"));
150 list.append(filename); 150 list.append(filename);
151 } 151 }
152 152
153 return list; 153 return list;
154} 154}
155 155
156class NetworkServer : public QCopChannel { 156class NetworkServer : public QCopChannel {
157 Q_OBJECT 157 Q_OBJECT
158public: 158public:
159 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0) 159 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0)
160 { 160 {
161 up = FALSE; 161 up = FALSE;
162 examineNetworks( TRUE ); 162 examineNetworks( TRUE );
163 QCopChannel* card = new QCopChannel("QPE/Card",parent); 163 QCopChannel* card = new QCopChannel("QPE/Card",parent);
164 connect(card,SIGNAL(received(const QCString &, const QByteArray&)), 164 connect(card,SIGNAL(received(const QCString&,const QByteArray&)),
165 this,SLOT(cardMessage(const QCString &, const QByteArray&))); 165 this,SLOT(cardMessage(const QCString&,const QByteArray&)));
166 } 166 }
167 167
168 ~NetworkServer() 168 ~NetworkServer()
169 { 169 {
170 stop(); 170 stop();
171 } 171 }
172 172
173 bool networkOnline() const 173 bool networkOnline() const
174 { 174 {
175 return up; 175 return up;
176 } 176 }
177 177
178private: 178private:
179 void receive(const QCString &msg, const QByteArray& data) 179 void receive(const QCString &msg, const QByteArray& data)
180 { 180 {
181 if ( msg == "start(QString,QString)" ) { 181 if ( msg == "start(QString,QString)" ) {
182 QDataStream stream(data,IO_ReadOnly); 182 QDataStream stream(data,IO_ReadOnly);
183 QString file,password; 183 QString file,password;
184 stream >> file >> password; 184 stream >> file >> password;
185 if ( file.isEmpty() ) { 185 if ( file.isEmpty() ) {
186 QStringList l = Network::choices(); 186 QStringList l = Network::choices();
187 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) { 187 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) {
188 Config cfg(*i,Config::File); 188 Config cfg(*i,Config::File);
189 cfg.setGroup("Info"); 189 cfg.setGroup("Info");
190 QString type = cfg.readEntry("Type"); 190 QString type = cfg.readEntry("Type");
191 NetworkInterface* plugin = Network::loadPlugin(type); 191 NetworkInterface* plugin = Network::loadPlugin(type);
192 cfg.setGroup("Properties"); 192 cfg.setGroup("Properties");
193 if ( plugin && plugin->isAvailable(cfg) ) { 193 if ( plugin && plugin->isAvailable(cfg) ) {
194 file = *i; 194 file = *i;
195 break; 195 break;
196 } 196 }
197 } 197 }
198 if ( file.isEmpty() ) { 198 if ( file.isEmpty() ) {
199 QCopEnvelope("QPE/Network", "failed()"); 199 QCopEnvelope("QPE/Network", "failed()");
200 return; 200 return;
201 } 201 }
202 } 202 }
203 start(file,password); 203 start(file,password);
204 } else if ( msg == "stop()" ) { 204 } else if ( msg == "stop()" ) {
205 stop(); 205 stop();
206 } else if ( msg == "choicesChanged()" ) { 206 } else if ( msg == "choicesChanged()" ) {
207 examineNetworks(); 207 examineNetworks();
208 } 208 }
209 } 209 }
210 210
211private slots: 211private slots:
212 void cardMessage(const QCString &msg, const QByteArray&) 212 void cardMessage(const QCString &msg, const QByteArray&)
213 { 213 {
214 if ( msg == "stabChanged()" ) 214 if ( msg == "stabChanged()" )
215 examineNetworks(); 215 examineNetworks();
216 } 216 }
217 217
218private: 218private:
219 void examineNetworks( bool firstStart = FALSE ) 219 void examineNetworks( bool firstStart = FALSE )
220 { 220 {
221 QStringList l = Network::choices(); 221 QStringList l = Network::choices();
222 bool wasup = up; up=FALSE; 222 bool wasup = up; up=FALSE;
223 QStringList pavailable = available; 223 QStringList pavailable = available;
224 available.clear(); 224 available.clear();
225 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 225 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
226 Config cfg(*it,Config::File); 226 Config cfg(*it,Config::File);
227 cfg.setGroup("Info"); 227 cfg.setGroup("Info");
228 QString type = cfg.readEntry("Type"); 228 QString type = cfg.readEntry("Type");
229 NetworkInterface* plugin = Network::loadPlugin(type); 229 NetworkInterface* plugin = Network::loadPlugin(type);
230 cfg.setGroup("Properties"); 230 cfg.setGroup("Properties");
231 if ( plugin ) { 231 if ( plugin ) {
232 if ( plugin->isActive(cfg) ) { 232 if ( plugin->isActive(cfg) ) {
233 up = TRUE; 233 up = TRUE;
234 if ( firstStart ) 234 if ( firstStart )
235 plugin->start( cfg ); 235 plugin->start( cfg );
236 } 236 }
237 if ( plugin->isAvailable(cfg) ) 237 if ( plugin->isAvailable(cfg) )
238 available.append(*it); 238 available.append(*it);
239 } 239 }
240 } 240 }
241 241
242 // Try to work around unreproducible bug whereby 242 // Try to work around unreproducible bug whereby
243 // the netmon applet shows wrong state. 243 // the netmon applet shows wrong state.
244 bool reannounce = wait<0; 244 bool reannounce = wait<0;
245 245
246 if ( available != pavailable || reannounce ) { 246 if ( available != pavailable || reannounce ) {
247 QCopEnvelope e("QPE/Network", "available(QStringList)"); 247 QCopEnvelope e("QPE/Network", "available(QStringList)");
248 e << available; 248 e << available;
249 } 249 }
250 if ( up != wasup || reannounce ) { 250 if ( up != wasup || reannounce ) {
251 QCopEnvelope("QPE/Network", up ? "up()" : "down()"); 251 QCopEnvelope("QPE/Network", up ? "up()" : "down()");
252 } 252 }
253 } 253 }
254 254
255 void start( const QString& file, const QString& password ) 255 void start( const QString& file, const QString& password )
256 { 256 {
257 if ( !current.isEmpty() ) 257 if ( !current.isEmpty() )
258 stop(); 258 stop();
259 current = QString::null; 259 current = QString::null;
260 Config cfg(file, Config::File); 260 Config cfg(file, Config::File);
261 cfg.setGroup("Info"); 261 cfg.setGroup("Info");
262 QString type = cfg.readEntry("Type"); 262 QString type = cfg.readEntry("Type");
263 NetworkInterface* plugin = Network::loadPlugin(type); 263 NetworkInterface* plugin = Network::loadPlugin(type);
264 bool started = FALSE; 264 bool started = FALSE;
265 if ( plugin ) { 265 if ( plugin ) {
266 cfg.setGroup("Properties"); 266 cfg.setGroup("Properties");
267 if ( plugin->start(cfg,password) ) { 267 if ( plugin->start(cfg,password) ) {
268 Network::writeProxySettings( cfg ); 268 Network::writeProxySettings( cfg );
269 current = file; 269 current = file;
270 wait=0; 270 wait=0;
271 startTimer(400); 271 startTimer(400);
272 started = TRUE; 272 started = TRUE;
273 } 273 }
274 } 274 }
275 if ( !started ) { 275 if ( !started ) {
276 QCopEnvelope("QPE/Network", "failed()"); 276 QCopEnvelope("QPE/Network", "failed()");
277 } 277 }
278 } 278 }
279 279
280 void stop() 280 void stop()
281 { 281 {
282 bool stopped = FALSE; 282 bool stopped = FALSE;
283 if ( !current.isEmpty() ) { 283 if ( !current.isEmpty() ) {
284 Config cfg(current, Config::File); 284 Config cfg(current, Config::File);
285 cfg.setGroup("Info"); 285 cfg.setGroup("Info");
286 QString type = cfg.readEntry("Type"); 286 QString type = cfg.readEntry("Type");
287 NetworkInterface* plugin = Network::loadPlugin(type); 287 NetworkInterface* plugin = Network::loadPlugin(type);
288 if ( plugin ) { 288 if ( plugin ) {
289 cfg.setGroup("Properties"); 289 cfg.setGroup("Properties");
290 if ( plugin->stop(cfg) ) { 290 if ( plugin->stop(cfg) ) {
291 current = QString::null; 291 current = QString::null;
292 wait=0; 292 wait=0;
293 startTimer(400); 293 startTimer(400);
294 stopped = TRUE; 294 stopped = TRUE;
295 } 295 }
296 } 296 }
297 } 297 }
298 if ( !stopped ) { 298 if ( !stopped ) {
299 QCopEnvelope("QPE/Network", "failed()"); 299 QCopEnvelope("QPE/Network", "failed()");
300 } 300 }
301 } 301 }
302 302
303 void timerEvent(QTimerEvent*) 303 void timerEvent(QTimerEvent*)
304 { 304 {
305 examineNetworks(); 305 examineNetworks();
306 if ( wait >= 0 ) { 306 if ( wait >= 0 ) {
307 if ( up == !current.isNull() ) { 307 if ( up == !current.isNull() ) {
308 // done 308 // done
309 killTimers(); 309 killTimers();
310 if ( up ) { 310 if ( up ) {
311 startTimer(3000); // monitor link 311 startTimer(3000); // monitor link
312 wait = -1; 312 wait = -1;
313 } 313 }
314 } else { 314 } else {
315 wait++; 315 wait++;
316 if ( wait == 600 ) { 316 if ( wait == 600 ) {
317 killTimers(); // forget about it after 240 s 317 killTimers(); // forget about it after 240 s
318 QCopEnvelope("QPE/Network", "failed()"); 318 QCopEnvelope("QPE/Network", "failed()");
319 up = !current.isNull(); 319 up = !current.isNull();
320 } 320 }
321 } 321 }
322 } else if ( !up ) { 322 } else if ( !up ) {
323 killTimers(); 323 killTimers();
324 } 324 }
325 } 325 }
326 326
327private: 327private:
328 QStringList available; 328 QStringList available;
329 QString current; 329 QString current;
330 bool up; 330 bool up;
331 int wait; 331 int wait;
332}; 332};
333 333
334static NetworkServer* ns=0; 334static NetworkServer* ns=0;
335 335
336/*! 336/*!
337 \internal 337 \internal
338*/ 338*/
339QString Network::serviceName(const QString& service) 339QString Network::serviceName(const QString& service)
340{ 340{
341 Config cfg(service, Config::File); 341 Config cfg(service, Config::File);
342 cfg.setGroup("Info"); 342 cfg.setGroup("Info");
343 return cfg.readEntry("Name"); 343 return cfg.readEntry("Name");
344} 344}
345 345
346/*! 346/*!
347 \internal 347 \internal
348*/ 348*/
349QString Network::serviceType(const QString& service) 349QString Network::serviceType(const QString& service)
350{ 350{
351 Config cfg(service, Config::File); 351 Config cfg(service, Config::File);
352 cfg.setGroup("Info"); 352 cfg.setGroup("Info");
353 return cfg.readEntry("Type"); 353 return cfg.readEntry("Type");
354} 354}
355 355
356/*! 356/*!
357 \internal 357 \internal
358*/ 358*/
359bool Network::serviceNeedsPassword(const QString& service) 359bool Network::serviceNeedsPassword(const QString& service)
360{ 360{
361 Config cfg(service,Config::File); 361 Config cfg(service,Config::File);
362 cfg.setGroup("Info"); 362 cfg.setGroup("Info");
363 QString type = cfg.readEntry("Type"); 363 QString type = cfg.readEntry("Type");
364 NetworkInterface* plugin = Network::loadPlugin(type); 364 NetworkInterface* plugin = Network::loadPlugin(type);
365 cfg.setGroup("Properties"); 365 cfg.setGroup("Properties");
366 return plugin ? plugin->needPassword(cfg) : FALSE; 366 return plugin ? plugin->needPassword(cfg) : FALSE;
367} 367}
368 368
369/*! 369/*!
370 \internal 370 \internal
371*/ 371*/
372bool Network::networkOnline() 372bool Network::networkOnline()
373{ 373{
374 return ns && ns->networkOnline(); 374 return ns && ns->networkOnline();
375} 375}
376 376
377/*! 377/*!
378 \internal 378 \internal
379*/ 379*/
380void Network::createServer(QObject* parent) 380void Network::createServer(QObject* parent)
381{ 381{
382 ns = new NetworkServer(parent); 382 ns = new NetworkServer(parent);
383} 383}
384 384
385/*! 385/*!
386 \internal 386 \internal
387*/ 387*/
388int Network::addStateWidgets(QWidget* parent) 388int Network::addStateWidgets(QWidget* parent)
389{ 389{
390 int n=0; 390 int n=0;
391 QStringList l = Network::choices(); 391 QStringList l = Network::choices();
392 QVBoxLayout* vb = new QVBoxLayout(parent); 392 QVBoxLayout* vb = new QVBoxLayout(parent);
393 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 393 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
394 Config cfg(*it,Config::File); 394 Config cfg(*it,Config::File);
395 cfg.setGroup("Info"); 395 cfg.setGroup("Info");
396 QString type = cfg.readEntry("Type"); 396 QString type = cfg.readEntry("Type");
397 NetworkInterface* plugin = Network::loadPlugin(type); 397 NetworkInterface* plugin = Network::loadPlugin(type);
398 cfg.setGroup("Properties"); 398 cfg.setGroup("Properties");
399 if ( plugin ) { 399 if ( plugin ) {
400 QWidget* w; 400 QWidget* w;
401 if ( (w=plugin->addStateWidget(parent,cfg)) ) { 401 if ( (w=plugin->addStateWidget(parent,cfg)) ) {
402 n++; 402 n++;
403 vb->addWidget(w); 403 vb->addWidget(w);
404 } 404 }
405 } 405 }
406 } 406 }
407 return n; 407 return n;
408} 408}
409 409
410static QDict<NetworkInterface> *ifaces; 410static QDict<NetworkInterface> *ifaces;
411 411
412/*! 412/*!
413 \internal 413 \internal
414*/ 414*/
415NetworkInterface* Network::loadPlugin(const QString& type) 415NetworkInterface* Network::loadPlugin(const QString& type)
416{ 416{
417#ifndef QT_NO_COMPONENT 417#ifndef QT_NO_COMPONENT
418 if ( !ifaces ) ifaces = new QDict<NetworkInterface>; 418 if ( !ifaces ) ifaces = new QDict<NetworkInterface>;
419 NetworkInterface *iface = ifaces->find(type); 419 NetworkInterface *iface = ifaces->find(type);
420 if ( !iface ) { 420 if ( !iface ) {
421#ifdef Q_OS_MACX 421#ifdef Q_OS_MACX
422 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".dylib"; 422 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".dylib";
423#else 423#else
424 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so"; 424 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so";
425#endif 425#endif
426 QLibrary lib(libfile); 426 QLibrary lib(libfile);
427 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK ) 427 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK )
428 return 0; 428 return 0;
429 ifaces->insert(type,iface); 429 ifaces->insert(type,iface);
430 QStringList langs = Global::languageList(); 430 QStringList langs = Global::languageList();
431 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 431 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
432 QString lang = *it; 432 QString lang = *it;
433 QTranslator * trans = new QTranslator(qApp); 433 QTranslator * trans = new QTranslator(qApp);
434 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm"; 434 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm";
435 if ( trans->load( tfn )) 435 if ( trans->load( tfn ))
436 qApp->installTranslator( trans ); 436 qApp->installTranslator( trans );
437 else 437 else
438 delete trans; 438 delete trans;
439 } 439 }
440 } 440 }
441 return iface; 441 return iface;
442#else 442#else
443 return 0; 443 return 0;
444#endif 444#endif
445} 445}
446 446
447#include "network.moc" 447#include "network.moc"
448 #endif// QT_NO_COP 448 #endif// QT_NO_COP
diff --git a/library/qcopenvelope_qws.cpp b/library/qcopenvelope_qws.cpp
index 8f58787..63efb13 100644
--- a/library/qcopenvelope_qws.cpp
+++ b/library/qcopenvelope_qws.cpp
@@ -1,145 +1,145 @@
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#ifndef QT_NO_COP 21#ifndef QT_NO_COP
22#include "qcopenvelope_qws.h" 22#include "qcopenvelope_qws.h"
23#endif 23#endif
24#include <qbuffer.h> 24#include <qbuffer.h>
25#include <qfile.h> 25#include <qfile.h>
26#include <unistd.h> 26#include <unistd.h>
27#include <errno.h> 27#include <errno.h>
28#include <sys/file.h> 28#include <sys/file.h>
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/stat.h> 30#include <sys/stat.h>
31#include <time.h> 31#include <time.h>
32 32
33#ifndef QT_NO_COP 33#ifndef QT_NO_COP
34 34
35/*! 35/*!
36 \class QCopEnvelope qcopenvelope_qws.h 36 \class QCopEnvelope qcopenvelope_qws.h
37 \brief The QCopEnvelope class encapsulates and sends QCop messages 37 \brief The QCopEnvelope class encapsulates and sends QCop messages
38 over QCopChannels. 38 over QCopChannels.
39 39
40 QCop messages allow applications to communicate with each other. 40 QCop messages allow applications to communicate with each other.
41 These messages are sent using QCopEnvelope, and received by connecting 41 These messages are sent using QCopEnvelope, and received by connecting
42 to a QCopChannel. 42 to a QCopChannel.
43 43
44 To send a message, use the following protocol: 44 To send a message, use the following protocol:
45 45
46 \code 46 \code
47 QCopEnvelope e(channelname, messagename); 47 QCopEnvelope e(channelname, messagename);
48 e << parameter1 << parameter2 << ...; 48 e << parameter1 << parameter2 << ...;
49 \endcode 49 \endcode
50 50
51 For messages without parameters, simply use: 51 For messages without parameters, simply use:
52 52
53 \code 53 \code
54 QCopEnvelope e(channelname, messagename); 54 QCopEnvelope e(channelname, messagename);
55 \endcode 55 \endcode
56 56
57 (Do not try to simplify this further as it may confuse some 57 (Do not try to simplify this further as it may confuse some
58 compilers.) 58 compilers.)
59 59
60 The \c{channelname} of channels within Qtopia all start with "QPE/". 60 The \c{channelname} of channels within Qtopia all start with "QPE/".
61 The \c{messagename} is a function identifier followed by a list of types 61 The \c{messagename} is a function identifier followed by a list of types
62 in parentheses. There is no whitespace in the message name. 62 in parentheses. There is no whitespace in the message name.
63 63
64 To receive a message, you will generally just use your application's 64 To receive a message, you will generally just use your application's
65 predefined QPE/Application/\e{appname} channel 65 predefined QPE/Application/\e{appname} channel
66 (see QPEApplication::appMessage()), but you can make another channel 66 (see QPEApplication::appMessage()), but you can make another channel
67 and connect it to a slot like this: 67 and connect it to a slot like this:
68 68
69 \code 69 \code
70 myChannel = new QCopChannel( "QPE/FooBar", this ); 70 myChannel = new QCopChannel( "QPE/FooBar", this );
71 connect( myChannel, SIGNAL(received(const QCString &, const QByteArray &)), 71 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)),
72 this, SLOT(fooBarMessage( const QCString &, const QByteArray &)) ); 72 this, SLOT(fooBarMessage(const QCString&,const QByteArray&)) );
73 \endcode 73 \endcode
74 74
75 See also, the \link qcop.html list of Qtopia messages\endlink. 75 See also, the \link qcop.html list of Qtopia messages\endlink.
76*/ 76*/
77 77
78/*! 78/*!
79 Constructs a QCopEnvelope that will write \a message to \a channel. 79 Constructs a QCopEnvelope that will write \a message to \a channel.
80 If \a message has parameters, you must then use operator<<() to 80 If \a message has parameters, you must then use operator<<() to
81 add these parameters to the envelope. 81 add these parameters to the envelope.
82*/ 82*/
83QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) : 83QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) :
84 QDataStream(new QBuffer), 84 QDataStream(new QBuffer),
85 ch(channel), msg(message) 85 ch(channel), msg(message)
86{ 86{
87 device()->open(IO_WriteOnly); 87 device()->open(IO_WriteOnly);
88} 88}
89 89
90/*! 90/*!
91 Writes the message and then destroys the QCopEnvelope. 91 Writes the message and then destroys the QCopEnvelope.
92*/ 92*/
93QCopEnvelope::~QCopEnvelope() 93QCopEnvelope::~QCopEnvelope()
94{ 94{
95 QByteArray data = ((QBuffer*)device())->buffer(); 95 QByteArray data = ((QBuffer*)device())->buffer();
96 const int pref=16; 96 const int pref=16;
97 if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) { 97 if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) {
98 QString qcopfn("/tmp/qcop-msg-"); 98 QString qcopfn("/tmp/qcop-msg-");
99 qcopfn += ch.mid(pref); 99 qcopfn += ch.mid(pref);
100 QFile qcopfile(qcopfn); 100 QFile qcopfile(qcopfn);
101 101
102 if ( qcopfile.open(IO_WriteOnly | IO_Append) ) { 102 if ( qcopfile.open(IO_WriteOnly | IO_Append) ) {
103#ifndef Q_OS_WIN32 103#ifndef Q_OS_WIN32
104 if(flock(qcopfile.handle(), LOCK_EX)) { 104 if(flock(qcopfile.handle(), LOCK_EX)) {
105 /* some error occurred */ 105 /* some error occurred */
106 qWarning(QString("Failed to obtain file lock on %1 (%2)") 106 qWarning(QString("Failed to obtain file lock on %1 (%2)")
107 .arg(qcopfn).arg( errno )); 107 .arg(qcopfn).arg( errno ));
108 } 108 }
109#endif 109#endif
110 { 110 {
111 QDataStream ds(&qcopfile); 111 QDataStream ds(&qcopfile);
112 ds << ch << msg << data; 112 ds << ch << msg << data;
113 qcopfile.flush(); 113 qcopfile.flush();
114#ifndef Q_OS_WIN32 114#ifndef Q_OS_WIN32
115 flock(qcopfile.handle(), LOCK_UN); 115 flock(qcopfile.handle(), LOCK_UN);
116#endif 116#endif
117 qcopfile.close(); 117 qcopfile.close();
118 } 118 }
119 119
120 QByteArray b; 120 QByteArray b;
121 QDataStream stream(b, IO_WriteOnly); 121 QDataStream stream(b, IO_WriteOnly);
122 stream << QString(ch.mid(pref)); 122 stream << QString(ch.mid(pref));
123 QCopChannel::send("QPE/Server", "processQCop(QString)", b); 123 QCopChannel::send("QPE/Server", "processQCop(QString)", b);
124 delete device(); 124 delete device();
125 return; 125 return;
126 } else { 126 } else {
127 qWarning(QString("Failed to open file %1") 127 qWarning(QString("Failed to open file %1")
128 .arg(qcopfn)); 128 .arg(qcopfn));
129 } // endif open 129 } // endif open
130 } 130 }
131 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) { 131 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
132 // If this is a message that should go along the SOAP channel, we move the 132 // If this is a message that should go along the SOAP channel, we move the
133 // endpoint URL to the data section. 133 // endpoint URL to the data section.
134 QString endpoint = ch.mid(9); 134 QString endpoint = ch.mid(9);
135 135
136 ch = "QPE/SOAP"; 136 ch = "QPE/SOAP";
137 // Since byte arrays are explicitly shared, this is appended to the data variable.. 137 // Since byte arrays are explicitly shared, this is appended to the data variable..
138 *this << endpoint; 138 *this << endpoint;
139 } 139 }
140 140
141 QCopChannel::send(ch,msg,data); 141 QCopChannel::send(ch,msg,data);
142 delete device(); 142 delete device();
143} 143}
144 144
145#endif 145#endif
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 262221e..c339a78 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -119,1149 +119,1149 @@ public:
119 bool nomaximize : 1; 119 bool nomaximize : 1;
120 bool keep_running : 1; 120 bool keep_running : 1;
121 bool qcopQok : 1; 121 bool qcopQok : 1;
122 122
123 123
124 QStringList langs; 124 QStringList langs;
125 QString appName; 125 QString appName;
126 struct QCopRec 126 struct QCopRec
127 { 127 {
128 QCopRec( const QCString &ch, const QCString &msg, 128 QCopRec( const QCString &ch, const QCString &msg,
129 const QByteArray &d ) : 129 const QByteArray &d ) :
130 channel( ch ), message( msg ), data( d ) 130 channel( ch ), message( msg ), data( d )
131 { } 131 { }
132 132
133 QCString channel; 133 QCString channel;
134 QCString message; 134 QCString message;
135 QByteArray data; 135 QByteArray data;
136 }; 136 };
137 QWidget* qpe_main_widget; 137 QWidget* qpe_main_widget;
138 QGuardedPtr<QWidget> lastraised; 138 QGuardedPtr<QWidget> lastraised;
139 QQueue<QCopRec> qcopq; 139 QQueue<QCopRec> qcopq;
140 QString styleName; 140 QString styleName;
141 QString decorationName; 141 QString decorationName;
142 142
143 void enqueueQCop( const QCString &ch, const QCString &msg, 143 void enqueueQCop( const QCString &ch, const QCString &msg,
144 const QByteArray &data ) 144 const QByteArray &data )
145 { 145 {
146 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 146 qcopq.enqueue( new QCopRec( ch, msg, data ) );
147 } 147 }
148 void sendQCopQ() 148 void sendQCopQ()
149 { 149 {
150 if (!qcopQok ) 150 if (!qcopQok )
151 return; 151 return;
152 152
153 QCopRec * r; 153 QCopRec * r;
154 154
155 while((r=qcopq.dequeue())) { 155 while((r=qcopq.dequeue())) {
156 // remove from queue before sending... 156 // remove from queue before sending...
157 // event loop can come around again before getting 157 // event loop can come around again before getting
158 // back from sendLocally 158 // back from sendLocally
159#ifndef QT_NO_COP 159#ifndef QT_NO_COP
160 QCopChannel::sendLocally( r->channel, r->message, r->data ); 160 QCopChannel::sendLocally( r->channel, r->message, r->data );
161#endif 161#endif
162 162
163 delete r; 163 delete r;
164 } 164 }
165 } 165 }
166 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null ) 166 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null )
167 { 167 {
168 168
169 // ugly hack, remove that later after finding a sane solution 169 // ugly hack, remove that later after finding a sane solution
170 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, 170 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
171 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has 171 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has
172 // a (physically) large enough display to use the small icons 172 // a (physically) large enough display to use the small icons
173#if defined(OPIE_HIGH_RES_SMALL_PHY) 173#if defined(OPIE_HIGH_RES_SMALL_PHY)
174 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { 174 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
175 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); 175 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
176 } 176 }
177#endif 177#endif
178 178
179 if ( mw->layout() && mw->inherits("QDialog") ) { 179 if ( mw->layout() && mw->inherits("QDialog") ) {
180 QPEApplication::showDialog((QDialog*)mw, nomaximize); 180 QPEApplication::showDialog((QDialog*)mw, nomaximize);
181 } 181 }
182 else { 182 else {
183#ifdef Q_WS_QWS 183#ifdef Q_WS_QWS
184 if ( !nomaximize ) 184 if ( !nomaximize )
185 mw->showMaximized(); 185 mw->showMaximized();
186 else 186 else
187#endif 187#endif
188 188
189 mw->show(); 189 mw->show();
190 } 190 }
191 } 191 }
192 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 192 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
193 { 193 {
194 /* 194 /*
195 // This works but disable it for now until it is safe to apply 195 // This works but disable it for now until it is safe to apply
196 // What is does is scan the .desktop files of all the apps for 196 // What is does is scan the .desktop files of all the apps for
197 // the applnk that has the corresponding argv[0] as this program 197 // the applnk that has the corresponding argv[0] as this program
198 // then it uses the name stored in the .desktop file as the caption 198 // then it uses the name stored in the .desktop file as the caption
199 // for the main widget. This saves duplicating translations for 199 // for the main widget. This saves duplicating translations for
200 // the app name in the program and in the .desktop files. 200 // the app name in the program and in the .desktop files.
201 201
202 AppLnkSet apps( appsPath ); 202 AppLnkSet apps( appsPath );
203 203
204 QList<AppLnk> appsList = apps.children(); 204 QList<AppLnk> appsList = apps.children();
205 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 205 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
206 if ( (*it)->exec() == appName ) { 206 if ( (*it)->exec() == appName ) {
207 mw->setCaption( (*it)->name() ); 207 mw->setCaption( (*it)->name() );
208 return TRUE; 208 return TRUE;
209 } 209 }
210 } 210 }
211 */ 211 */
212 return FALSE; 212 return FALSE;
213 } 213 }
214 214
215 215
216 void show(QWidget* mw, bool nomax) 216 void show(QWidget* mw, bool nomax)
217 { 217 {
218 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 218 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
219 nomaximize = nomax; 219 nomaximize = nomax;
220 qpe_main_widget = mw; 220 qpe_main_widget = mw;
221 qcopQok = TRUE; 221 qcopQok = TRUE;
222#ifndef QT_NO_COP 222#ifndef QT_NO_COP
223 223
224 sendQCopQ(); 224 sendQCopQ();
225#endif 225#endif
226 226
227 if ( preloaded ) { 227 if ( preloaded ) {
228 if (forceshow) 228 if (forceshow)
229 show_mx(mw, nomax); 229 show_mx(mw, nomax);
230 } 230 }
231 else if ( keep_running ) { 231 else if ( keep_running ) {
232 show_mx(mw, nomax); 232 show_mx(mw, nomax);
233 } 233 }
234 } 234 }
235 235
236 void loadTextCodecs() 236 void loadTextCodecs()
237 { 237 {
238 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 238 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
239#ifdef Q_OS_MACX 239#ifdef Q_OS_MACX
240 QDir dir( path, "lib*.dylib" ); 240 QDir dir( path, "lib*.dylib" );
241#else 241#else
242 QDir dir( path, "lib*.so" ); 242 QDir dir( path, "lib*.so" );
243#endif 243#endif
244 QStringList list; 244 QStringList list;
245 if ( dir. exists ( )) 245 if ( dir. exists ( ))
246 list = dir.entryList(); 246 list = dir.entryList();
247 QStringList::Iterator it; 247 QStringList::Iterator it;
248 for ( it = list.begin(); it != list.end(); ++it ) { 248 for ( it = list.begin(); it != list.end(); ++it ) {
249 TextCodecInterface *iface = 0; 249 TextCodecInterface *iface = 0;
250 QLibrary *lib = new QLibrary( path + "/" + *it ); 250 QLibrary *lib = new QLibrary( path + "/" + *it );
251 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 251 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
252 QValueList<int> mibs = iface->mibEnums(); 252 QValueList<int> mibs = iface->mibEnums();
253 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 253 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
254 (void)iface->createForMib(*i); 254 (void)iface->createForMib(*i);
255 // ### it exists now; need to remember if we can delete it 255 // ### it exists now; need to remember if we can delete it
256 } 256 }
257 } 257 }
258 else { 258 else {
259 lib->unload(); 259 lib->unload();
260 delete lib; 260 delete lib;
261 } 261 }
262 } 262 }
263 } 263 }
264 264
265 void loadImageCodecs() 265 void loadImageCodecs()
266 { 266 {
267 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 267 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
268#ifdef Q_OS_MACX 268#ifdef Q_OS_MACX
269 QDir dir( path, "lib*.dylib" ); 269 QDir dir( path, "lib*.dylib" );
270#else 270#else
271 QDir dir( path, "lib*.so" ); 271 QDir dir( path, "lib*.so" );
272#endif 272#endif
273 QStringList list; 273 QStringList list;
274 if ( dir. exists ( )) 274 if ( dir. exists ( ))
275 list = dir.entryList(); 275 list = dir.entryList();
276 QStringList::Iterator it; 276 QStringList::Iterator it;
277 for ( it = list.begin(); it != list.end(); ++it ) { 277 for ( it = list.begin(); it != list.end(); ++it ) {
278 ImageCodecInterface *iface = 0; 278 ImageCodecInterface *iface = 0;
279 QLibrary *lib = new QLibrary( path + "/" + *it ); 279 QLibrary *lib = new QLibrary( path + "/" + *it );
280 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 280 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
281 QStringList formats = iface->keys(); 281 QStringList formats = iface->keys();
282 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 282 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
283 (void)iface->installIOHandler(*i); 283 (void)iface->installIOHandler(*i);
284 // ### it exists now; need to remember if we can delete it 284 // ### it exists now; need to remember if we can delete it
285 } 285 }
286 } 286 }
287 else { 287 else {
288 lib->unload(); 288 lib->unload();
289 delete lib; 289 delete lib;
290 } 290 }
291 } 291 }
292 } 292 }
293}; 293};
294 294
295class ResourceMimeFactory : public QMimeSourceFactory 295class ResourceMimeFactory : public QMimeSourceFactory
296{ 296{
297public: 297public:
298 ResourceMimeFactory() : resImage( 0 ) 298 ResourceMimeFactory() : resImage( 0 )
299 { 299 {
300 setFilePath( Global::helpPath() ); 300 setFilePath( Global::helpPath() );
301 setExtensionType( "html", "text/html;charset=UTF-8" ); 301 setExtensionType( "html", "text/html;charset=UTF-8" );
302 } 302 }
303 ~ResourceMimeFactory() { 303 ~ResourceMimeFactory() {
304 delete resImage; 304 delete resImage;
305 } 305 }
306 306
307 const QMimeSource* data( const QString& abs_name ) const 307 const QMimeSource* data( const QString& abs_name ) const
308 { 308 {
309 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 309 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
310 if ( !r ) { 310 if ( !r ) {
311 int sl = abs_name.length(); 311 int sl = abs_name.length();
312 do { 312 do {
313 sl = abs_name.findRev( '/', sl - 1 ); 313 sl = abs_name.findRev( '/', sl - 1 );
314 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 314 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
315 int dot = name.findRev( '.' ); 315 int dot = name.findRev( '.' );
316 if ( dot >= 0 ) 316 if ( dot >= 0 )
317 name = name.left( dot ); 317 name = name.left( dot );
318 QImage img = Resource::loadImage( name ); 318 QImage img = Resource::loadImage( name );
319 if ( !img.isNull() ) { 319 if ( !img.isNull() ) {
320 delete resImage; 320 delete resImage;
321 resImage = new QImageDrag( img ); 321 resImage = new QImageDrag( img );
322 r = resImage; 322 r = resImage;
323 } 323 }
324 } 324 }
325 while ( !r && sl > 0 ); 325 while ( !r && sl > 0 );
326 } 326 }
327 return r; 327 return r;
328 } 328 }
329private: 329private:
330 mutable QImageDrag *resImage; 330 mutable QImageDrag *resImage;
331}; 331};
332 332
333static int& hack(int& i) 333static int& hack(int& i)
334{ 334{
335#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 335#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
336 // These should be created, but aren't in Qt 2.3.0 336 // These should be created, but aren't in Qt 2.3.0
337 (void)new QUtf8Codec; 337 (void)new QUtf8Codec;
338 (void)new QUtf16Codec; 338 (void)new QUtf16Codec;
339#endif 339#endif
340 return i; 340 return i;
341} 341}
342 342
343static int muted = 0; 343static int muted = 0;
344static int micMuted = 0; 344static int micMuted = 0;
345 345
346static void setVolume( int t = 0, int percent = -1 ) 346static void setVolume( int t = 0, int percent = -1 )
347{ 347{
348 switch ( t ) { 348 switch ( t ) {
349 case 0: { 349 case 0: {
350 Config cfg( "qpe" ); 350 Config cfg( "qpe" );
351 cfg.setGroup( "Volume" ); 351 cfg.setGroup( "Volume" );
352 if ( percent < 0 ) 352 if ( percent < 0 )
353 percent = cfg.readNumEntry( "VolumePercent", 50 ); 353 percent = cfg.readNumEntry( "VolumePercent", 50 );
354#ifndef QT_NO_SOUND 354#ifndef QT_NO_SOUND
355 int fd = 0; 355 int fd = 0;
356 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 356 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
357 int vol = muted ? 0 : percent; 357 int vol = muted ? 0 : percent;
358 // set both channels to same volume 358 // set both channels to same volume
359 vol |= vol << 8; 359 vol |= vol << 8;
360 ioctl( fd, MIXER_WRITE( 0 ), &vol ); 360 ioctl( fd, MIXER_WRITE( 0 ), &vol );
361 ::close( fd ); 361 ::close( fd );
362 } 362 }
363#endif 363#endif
364 } 364 }
365 break; 365 break;
366 } 366 }
367} 367}
368 368
369static void setMic( int t = 0, int percent = -1 ) 369static void setMic( int t = 0, int percent = -1 )
370{ 370{
371 switch ( t ) { 371 switch ( t ) {
372 case 0: { 372 case 0: {
373 Config cfg( "qpe" ); 373 Config cfg( "qpe" );
374 cfg.setGroup( "Volume" ); 374 cfg.setGroup( "Volume" );
375 if ( percent < 0 ) 375 if ( percent < 0 )
376 percent = cfg.readNumEntry( "Mic", 50 ); 376 percent = cfg.readNumEntry( "Mic", 50 );
377 377
378#ifndef QT_NO_SOUND 378#ifndef QT_NO_SOUND
379 int fd = 0; 379 int fd = 0;
380 int mic = micMuted ? 0 : percent; 380 int mic = micMuted ? 0 : percent;
381 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 381 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
382 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 382 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
383 ::close( fd ); 383 ::close( fd );
384 } 384 }
385#endif 385#endif
386 } 386 }
387 break; 387 break;
388 } 388 }
389} 389}
390 390
391 391
392static void setBass( int t = 0, int percent = -1 ) 392static void setBass( int t = 0, int percent = -1 )
393{ 393{
394 switch ( t ) { 394 switch ( t ) {
395 case 0: { 395 case 0: {
396 Config cfg( "qpe" ); 396 Config cfg( "qpe" );
397 cfg.setGroup( "Volume" ); 397 cfg.setGroup( "Volume" );
398 if ( percent < 0 ) 398 if ( percent < 0 )
399 percent = cfg.readNumEntry( "BassPercent", 50 ); 399 percent = cfg.readNumEntry( "BassPercent", 50 );
400 400
401#ifndef QT_NO_SOUND 401#ifndef QT_NO_SOUND
402 int fd = 0; 402 int fd = 0;
403 int bass = percent; 403 int bass = percent;
404 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 404 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
405 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 405 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
406 ::close( fd ); 406 ::close( fd );
407 } 407 }
408#endif 408#endif
409 } 409 }
410 break; 410 break;
411 } 411 }
412} 412}
413 413
414 414
415static void setTreble( int t = 0, int percent = -1 ) 415static void setTreble( int t = 0, int percent = -1 )
416{ 416{
417 switch ( t ) { 417 switch ( t ) {
418 case 0: { 418 case 0: {
419 Config cfg( "qpe" ); 419 Config cfg( "qpe" );
420 cfg.setGroup( "Volume" ); 420 cfg.setGroup( "Volume" );
421 if ( percent < 0 ) 421 if ( percent < 0 )
422 percent = cfg.readNumEntry( "TreblePercent", 50 ); 422 percent = cfg.readNumEntry( "TreblePercent", 50 );
423 423
424#ifndef QT_NO_SOUND 424#ifndef QT_NO_SOUND
425 int fd = 0; 425 int fd = 0;
426 int treble = percent; 426 int treble = percent;
427 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 427 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
428 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 428 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
429 ::close( fd ); 429 ::close( fd );
430 } 430 }
431#endif 431#endif
432 } 432 }
433 break; 433 break;
434 } 434 }
435} 435}
436 436
437 437
438/** 438/**
439 \class QPEApplication 439 \class QPEApplication
440 \brief The QPEApplication class implements various system services 440 \brief The QPEApplication class implements various system services
441 that are available to all Qtopia applications. 441 that are available to all Qtopia applications.
442 442
443 Simply by using QPEApplication instead of QApplication, a standard Qt 443 Simply by using QPEApplication instead of QApplication, a standard Qt
444 application becomes a Qtopia application. It automatically follows 444 application becomes a Qtopia application. It automatically follows
445 style changes, quits and raises, and in the 445 style changes, quits and raises, and in the
446 case of \link docwidget.html document-oriented\endlink applications, 446 case of \link docwidget.html document-oriented\endlink applications,
447 changes the currently displayed document in response to the environment. 447 changes the currently displayed document in response to the environment.
448 448
449 To create a \link docwidget.html document-oriented\endlink 449 To create a \link docwidget.html document-oriented\endlink
450 application use showMainDocumentWidget(); to create a 450 application use showMainDocumentWidget(); to create a
451 non-document-oriented application use showMainWidget(). The 451 non-document-oriented application use showMainWidget(). The
452 keepRunning() function indicates whether the application will 452 keepRunning() function indicates whether the application will
453 continue running after it's processed the last \link qcop.html 453 continue running after it's processed the last \link qcop.html
454 QCop\endlink message. This can be changed using setKeepRunning(). 454 QCop\endlink message. This can be changed using setKeepRunning().
455 455
456 A variety of signals are emitted when certain events occur, for 456 A variety of signals are emitted when certain events occur, for
457 example, timeChanged(), clockChanged(), weekChanged(), 457 example, timeChanged(), clockChanged(), weekChanged(),
458 dateFormatChanged() and volumeChanged(). If the application receives 458 dateFormatChanged() and volumeChanged(). If the application receives
459 a \link qcop.html QCop\endlink message on the application's 459 a \link qcop.html QCop\endlink message on the application's
460 QPE/Application/\e{appname} channel, the appMessage() signal is 460 QPE/Application/\e{appname} channel, the appMessage() signal is
461 emitted. There are also flush() and reload() signals, which 461 emitted. There are also flush() and reload() signals, which
462 are emitted when synching begins and ends respectively - upon these 462 are emitted when synching begins and ends respectively - upon these
463 signals, the application should save and reload any data 463 signals, the application should save and reload any data
464 files that are involved in synching. Most of these signals will initially 464 files that are involved in synching. Most of these signals will initially
465 be received and unfiltered through the appMessage() signal. 465 be received and unfiltered through the appMessage() signal.
466 466
467 This class also provides a set of useful static functions. The 467 This class also provides a set of useful static functions. The
468 qpeDir() and documentDir() functions return the respective paths. 468 qpeDir() and documentDir() functions return the respective paths.
469 The grabKeyboard() and ungrabKeyboard() functions are used to 469 The grabKeyboard() and ungrabKeyboard() functions are used to
470 control whether the application takes control of the device's 470 control whether the application takes control of the device's
471 physical buttons (e.g. application launch keys). The stylus' mode of 471 physical buttons (e.g. application launch keys). The stylus' mode of
472 operation is set with setStylusOperation() and retrieved with 472 operation is set with setStylusOperation() and retrieved with
473 stylusOperation(). There are also setInputMethodHint() and 473 stylusOperation(). There are also setInputMethodHint() and
474 inputMethodHint() functions. 474 inputMethodHint() functions.
475 475
476 \ingroup qtopiaemb 476 \ingroup qtopiaemb
477*/ 477*/
478 478
479/*! 479/*!
480 \fn void QPEApplication::clientMoused() 480 \fn void QPEApplication::clientMoused()
481 481
482 \internal 482 \internal
483*/ 483*/
484 484
485/*! 485/*!
486 \fn void QPEApplication::timeChanged(); 486 \fn void QPEApplication::timeChanged();
487 This signal is emitted when the time changes outside the normal 487 This signal is emitted when the time changes outside the normal
488 passage of time, i.e. if the time is set backwards or forwards. 488 passage of time, i.e. if the time is set backwards or forwards.
489*/ 489*/
490 490
491/*! 491/*!
492 \fn void QPEApplication::clockChanged( bool ampm ); 492 \fn void QPEApplication::clockChanged( bool ampm );
493 493
494 This signal is emitted when the user changes the clock's style. If 494 This signal is emitted when the user changes the clock's style. If
495 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 495 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
496 they want a 24-hour clock. 496 they want a 24-hour clock.
497*/ 497*/
498 498
499/*! 499/*!
500 \fn void QPEApplication::volumeChanged( bool muted ) 500 \fn void QPEApplication::volumeChanged( bool muted )
501 501
502 This signal is emitted whenever the mute state is changed. If \a 502 This signal is emitted whenever the mute state is changed. If \a
503 muted is TRUE, then sound output has been muted. 503 muted is TRUE, then sound output has been muted.
504*/ 504*/
505 505
506/*! 506/*!
507 \fn void QPEApplication::weekChanged( bool startOnMonday ) 507 \fn void QPEApplication::weekChanged( bool startOnMonday )
508 508
509 This signal is emitted if the week start day is changed. If \a 509 This signal is emitted if the week start day is changed. If \a
510 startOnMonday is TRUE then the first day of the week is Monday; if 510 startOnMonday is TRUE then the first day of the week is Monday; if
511 \a startOnMonday is FALSE then the first day of the week is 511 \a startOnMonday is FALSE then the first day of the week is
512 Sunday. 512 Sunday.
513*/ 513*/
514 514
515/*! 515/*!
516 \fn void QPEApplication::dateFormatChanged(DateFormat) 516 \fn void QPEApplication::dateFormatChanged(DateFormat)
517 517
518 This signal is emitted whenever the date format is changed. 518 This signal is emitted whenever the date format is changed.
519*/ 519*/
520 520
521/*! 521/*!
522 \fn void QPEApplication::flush() 522 \fn void QPEApplication::flush()
523 523
524 ### 524 ###
525*/ 525*/
526 526
527/*! 527/*!
528 \fn void QPEApplication::reload() 528 \fn void QPEApplication::reload()
529 529
530*/ 530*/
531 531
532 532
533 533
534void QPEApplication::processQCopFile() 534void QPEApplication::processQCopFile()
535{ 535{
536 QString qcopfn("/tmp/qcop-msg-"); 536 QString qcopfn("/tmp/qcop-msg-");
537 qcopfn += d->appName; // append command name 537 qcopfn += d->appName; // append command name
538 538
539 QFile f(qcopfn); 539 QFile f(qcopfn);
540 if ( f.open(IO_ReadWrite) ) { 540 if ( f.open(IO_ReadWrite) ) {
541#ifndef Q_OS_WIN32 541#ifndef Q_OS_WIN32
542 flock(f.handle(), LOCK_EX); 542 flock(f.handle(), LOCK_EX);
543#endif 543#endif
544 QDataStream ds(&f); 544 QDataStream ds(&f);
545 QCString channel, message; 545 QCString channel, message;
546 QByteArray data; 546 QByteArray data;
547 while(!ds.atEnd()) { 547 while(!ds.atEnd()) {
548 ds >> channel >> message >> data; 548 ds >> channel >> message >> data;
549 d->enqueueQCop(channel,message,data); 549 d->enqueueQCop(channel,message,data);
550 } 550 }
551 ::ftruncate(f.handle(), 0); 551 ::ftruncate(f.handle(), 0);
552#ifndef Q_OS_WIN32 552#ifndef Q_OS_WIN32
553 f.flush(); 553 f.flush();
554 flock(f.handle(), LOCK_UN); 554 flock(f.handle(), LOCK_UN);
555#endif 555#endif
556 } 556 }
557#endif 557#endif
558} 558}
559 559
560 560
561/*! 561/*!
562 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 562 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
563 563
564 This signal is emitted when a message is received on this 564 This signal is emitted when a message is received on this
565 application's QPE/Application/<i>appname</i> \link qcop.html 565 application's QPE/Application/<i>appname</i> \link qcop.html
566 QCop\endlink channel. 566 QCop\endlink channel.
567 567
568 The slot to which you connect this signal uses \a msg and \a data 568 The slot to which you connect this signal uses \a msg and \a data
569 in the following way: 569 in the following way:
570 570
571\code 571\code
572 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 572 void MyWidget::receive( const QCString& msg, const QByteArray& data )
573 { 573 {
574 QDataStream stream( data, IO_ReadOnly ); 574 QDataStream stream( data, IO_ReadOnly );
575 if ( msg == "someMessage(int,int,int)" ) { 575 if ( msg == "someMessage(int,int,int)" ) {
576 int a,b,c; 576 int a,b,c;
577 stream >> a >> b >> c; 577 stream >> a >> b >> c;
578 ... 578 ...
579 } else if ( msg == "otherMessage(QString)" ) { 579 } else if ( msg == "otherMessage(QString)" ) {
580 ... 580 ...
581 } 581 }
582 } 582 }
583\endcode 583\endcode
584 584
585 \sa qcop.html 585 \sa qcop.html
586 Note that messages received here may be processed by qpe application 586 Note that messages received here may be processed by qpe application
587 and emitted as signals, such as flush() and reload(). 587 and emitted as signals, such as flush() and reload().
588*/ 588*/
589 589
590/*! 590/*!
591 Constructs a QPEApplication just as you would construct 591 Constructs a QPEApplication just as you would construct
592 a QApplication, passing \a argc, \a argv, and \a t. 592 a QApplication, passing \a argc, \a argv, and \a t.
593 593
594 For applications, \a t should be the default, GuiClient. Only 594 For applications, \a t should be the default, GuiClient. Only
595 the Qtopia server passes GuiServer. 595 the Qtopia server passes GuiServer.
596*/ 596*/
597QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 597QPEApplication::QPEApplication( int & argc, char **argv, Type t )
598 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 598 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
599{ 599{
600 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. 600 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
601 601
602 d = new QPEApplicationData; 602 d = new QPEApplicationData;
603 d->loadTextCodecs(); 603 d->loadTextCodecs();
604 d->loadImageCodecs(); 604 d->loadImageCodecs();
605 int dw = desktop() ->width(); 605 int dw = desktop() ->width();
606 606
607 if ( dw < 200 ) { 607 if ( dw < 200 ) {
608 setFont( QFont( "vera", 8 ) ); 608 setFont( QFont( "vera", 8 ) );
609 AppLnk::setSmallIconSize( 10 ); 609 AppLnk::setSmallIconSize( 10 );
610 AppLnk::setBigIconSize( 28 ); 610 AppLnk::setBigIconSize( 28 );
611 } 611 }
612#if defined(OPIE_HIGH_RES_SMALL_PHY) 612#if defined(OPIE_HIGH_RES_SMALL_PHY)
613 else if ( dw > 600 ) { 613 else if ( dw > 600 ) {
614 setFont( QFont( "vera", 16 ) ); 614 setFont( QFont( "vera", 16 ) );
615 AppLnk::setSmallIconSize( 24 ); 615 AppLnk::setSmallIconSize( 24 );
616 AppLnk::setBigIconSize( 48 ); 616 AppLnk::setBigIconSize( 48 );
617 } 617 }
618#endif 618#endif
619 else if ( dw > 200 ) { 619 else if ( dw > 200 ) {
620 setFont( QFont( "vera", 10 ) ); 620 setFont( QFont( "vera", 10 ) );
621 AppLnk::setSmallIconSize( 14 ); 621 AppLnk::setSmallIconSize( 14 );
622 AppLnk::setBigIconSize( 32 ); 622 AppLnk::setBigIconSize( 32 );
623 } 623 }
624 624
625 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 625 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
626 626
627 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 627 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
628 628
629 629
630 sysChannel = new QCopChannel( "QPE/System", this ); 630 sysChannel = new QCopChannel( "QPE/System", this );
631 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 631 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
632 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); 632 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) );
633 633
634/* COde now in initapp */ 634/* COde now in initapp */
635#if 0 635#if 0
636#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 636#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
637 637
638 QString qcopfn( "/tmp/qcop-msg-" ); 638 QString qcopfn( "/tmp/qcop-msg-" );
639 qcopfn += QString( argv[ 0 ] ); // append command name 639 qcopfn += QString( argv[ 0 ] ); // append command name
640 640
641 QFile f( qcopfn ); 641 QFile f( qcopfn );
642 if ( f.open( IO_ReadOnly ) ) { 642 if ( f.open( IO_ReadOnly ) ) {
643 flock( f.handle(), LOCK_EX ); 643 flock( f.handle(), LOCK_EX );
644 } 644 }
645 645
646 646
647 647
648 QCString channel = QCString( argv[ 0 ] ); 648 QCString channel = QCString( argv[ 0 ] );
649 channel.replace( QRegExp( ".*/" ), "" ); 649 channel.replace( QRegExp( ".*/" ), "" );
650 d->appName = channel; 650 d->appName = channel;
651 channel = "QPE/Application/" + channel; 651 channel = "QPE/Application/" + channel;
652 pidChannel = new QCopChannel( channel, this ); 652 pidChannel = new QCopChannel( channel, this );
653 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 653 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
654 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) ); 654 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
655 655
656 if ( f.isOpen() ) { 656 if ( f.isOpen() ) {
657 d->keep_running = FALSE; 657 d->keep_running = FALSE;
658 QDataStream ds( &f ); 658 QDataStream ds( &f );
659 QCString channel, message; 659 QCString channel, message;
660 QByteArray data; 660 QByteArray data;
661 while ( !ds.atEnd() ) { 661 while ( !ds.atEnd() ) {
662 ds >> channel >> message >> data; 662 ds >> channel >> message >> data;
663 d->enqueueQCop( channel, message, data ); 663 d->enqueueQCop( channel, message, data );
664 } 664 }
665 665
666 flock( f.handle(), LOCK_UN ); 666 flock( f.handle(), LOCK_UN );
667 f.close(); 667 f.close();
668 f.remove(); 668 f.remove();
669 } 669 }
670 670
671 for ( int a = 0; a < argc; a++ ) { 671 for ( int a = 0; a < argc; a++ ) {
672 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 672 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
673 argv[ a ] = argv[ a + 1 ]; 673 argv[ a ] = argv[ a + 1 ];
674 a++; 674 a++;
675 d->preloaded = TRUE; 675 d->preloaded = TRUE;
676 argc -= 1; 676 argc -= 1;
677 } 677 }
678 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 678 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
679 argv[ a ] = argv[ a + 1 ]; 679 argv[ a ] = argv[ a + 1 ];
680 a++; 680 a++;
681 d->preloaded = TRUE; 681 d->preloaded = TRUE;
682 d->forceshow = TRUE; 682 d->forceshow = TRUE;
683 argc -= 1; 683 argc -= 1;
684 } 684 }
685 } 685 }
686 686
687 /* overide stored arguments */ 687 /* overide stored arguments */
688 setArgs( argc, argv ); 688 setArgs( argc, argv );
689 689
690#endif 690#endif
691#else 691#else
692 initApp( argc, argv ); 692 initApp( argc, argv );
693#endif 693#endif
694 // qwsSetDecoration( new QPEDecoration() ); 694 // qwsSetDecoration( new QPEDecoration() );
695 695
696#ifndef QT_NO_TRANSLATION 696#ifndef QT_NO_TRANSLATION
697 697
698 d->langs = Global::languageList(); 698 d->langs = Global::languageList();
699 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { 699 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
700 QString lang = *it; 700 QString lang = *it;
701 701
702 installTranslation( lang + "/libopie.qm"); 702 installTranslation( lang + "/libopie.qm");
703 installTranslation( lang + "/libqpe.qm" ); 703 installTranslation( lang + "/libqpe.qm" );
704 installTranslation( lang + "/" + d->appName + ".qm" ); 704 installTranslation( lang + "/" + d->appName + ".qm" );
705 705
706 706
707 //###language/font hack; should look it up somewhere 707 //###language/font hack; should look it up somewhere
708#ifdef QWS 708#ifdef QWS
709 709
710 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 710 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
711 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 711 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
712 setFont( fn ); 712 setFont( fn );
713 } 713 }
714#endif 714#endif
715 } 715 }
716#endif 716#endif
717 717
718 applyStyle(); 718 applyStyle();
719 719
720 if ( type() == GuiServer ) { 720 if ( type() == GuiServer ) {
721 setVolume(); 721 setVolume();
722 } 722 }
723 723
724 installEventFilter( this ); 724 installEventFilter( this );
725 725
726 QPEMenuToolFocusManager::initialize(); 726 QPEMenuToolFocusManager::initialize();
727 727
728#ifdef QT_NO_QWS_CURSOR 728#ifdef QT_NO_QWS_CURSOR
729 // if we have no cursor, probably don't want tooltips 729 // if we have no cursor, probably don't want tooltips
730 QToolTip::setEnabled( FALSE ); 730 QToolTip::setEnabled( FALSE );
731#endif 731#endif
732} 732}
733 733
734 734
735#ifdef QTOPIA_INTERNAL_INITAPP 735#ifdef QTOPIA_INTERNAL_INITAPP
736void QPEApplication::initApp( int argc, char **argv ) 736void QPEApplication::initApp( int argc, char **argv )
737{ 737{
738 delete pidChannel; 738 delete pidChannel;
739 d->keep_running = TRUE; 739 d->keep_running = TRUE;
740 d->preloaded = FALSE; 740 d->preloaded = FALSE;
741 d->forceshow = FALSE; 741 d->forceshow = FALSE;
742 742
743 QCString channel = QCString(argv[0]); 743 QCString channel = QCString(argv[0]);
744 744
745 channel.replace(QRegExp(".*/"),""); 745 channel.replace(QRegExp(".*/"),"");
746 d->appName = channel; 746 d->appName = channel;
747 747
748 #if QT_VERSION > 235 748 #if QT_VERSION > 235
749 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 749 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
750 #endif 750 #endif
751 751
752 channel = "QPE/Application/" + channel; 752 channel = "QPE/Application/" + channel;
753 pidChannel = new QCopChannel( channel, this); 753 pidChannel = new QCopChannel( channel, this);
754 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), 754 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)),
755 this, SLOT(pidMessage(const QCString &, const QByteArray &))); 755 this, SLOT(pidMessage(const QCString&,const QByteArray&)));
756 756
757 757
758 758
759 processQCopFile(); 759 processQCopFile();
760 d->keep_running = d->qcopq.isEmpty(); 760 d->keep_running = d->qcopq.isEmpty();
761 761
762 for (int a=0; a<argc; a++) { 762 for (int a=0; a<argc; a++) {
763 if ( qstrcmp(argv[a],"-preload")==0 ) { 763 if ( qstrcmp(argv[a],"-preload")==0 ) {
764 argv[a] = argv[a+1]; 764 argv[a] = argv[a+1];
765 a++; 765 a++;
766 d->preloaded = TRUE; 766 d->preloaded = TRUE;
767 argc-=1; 767 argc-=1;
768 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 768 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
769 argv[a] = argv[a+1]; 769 argv[a] = argv[a+1];
770 a++; 770 a++;
771 d->preloaded = TRUE; 771 d->preloaded = TRUE;
772 d->forceshow = TRUE; 772 d->forceshow = TRUE;
773 argc-=1; 773 argc-=1;
774 } 774 }
775 } 775 }
776 776
777 /* overide stored arguments */ 777 /* overide stored arguments */
778 setArgs(argc, argv); 778 setArgs(argc, argv);
779 779
780 /* install translation here */ 780 /* install translation here */
781 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) 781 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
782 installTranslation( (*it) + "/" + d->appName + ".qm" ); 782 installTranslation( (*it) + "/" + d->appName + ".qm" );
783} 783}
784#endif 784#endif
785 785
786 786
787static QPtrDict<void>* inputMethodDict = 0; 787static QPtrDict<void>* inputMethodDict = 0;
788static void createInputMethodDict() 788static void createInputMethodDict()
789{ 789{
790 if ( !inputMethodDict ) 790 if ( !inputMethodDict )
791 inputMethodDict = new QPtrDict<void>; 791 inputMethodDict = new QPtrDict<void>;
792} 792}
793 793
794/*! 794/*!
795 Returns the currently set hint to the system as to whether 795 Returns the currently set hint to the system as to whether
796 widget \a w has any use for text input methods. 796 widget \a w has any use for text input methods.
797 797
798 798
799 \sa setInputMethodHint() InputMethodHint 799 \sa setInputMethodHint() InputMethodHint
800*/ 800*/
801QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 801QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
802{ 802{
803 if ( inputMethodDict && w ) 803 if ( inputMethodDict && w )
804 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 804 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
805 return Normal; 805 return Normal;
806} 806}
807 807
808/*! 808/*!
809 \enum QPEApplication::InputMethodHint 809 \enum QPEApplication::InputMethodHint
810 810
811 \value Normal the application sometimes needs text input (the default). 811 \value Normal the application sometimes needs text input (the default).
812 \value AlwaysOff the application never needs text input. 812 \value AlwaysOff the application never needs text input.
813 \value AlwaysOn the application always needs text input. 813 \value AlwaysOn the application always needs text input.
814*/ 814*/
815 815
816/*! 816/*!
817 Hints to the system that widget \a w has use for text input methods 817 Hints to the system that widget \a w has use for text input methods
818 as specified by \a mode. 818 as specified by \a mode.
819 819
820 \sa inputMethodHint() InputMethodHint 820 \sa inputMethodHint() InputMethodHint
821*/ 821*/
822void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 822void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
823{ 823{
824 createInputMethodDict(); 824 createInputMethodDict();
825 if ( mode == Normal ) { 825 if ( mode == Normal ) {
826 inputMethodDict->remove 826 inputMethodDict->remove
827 ( w ); 827 ( w );
828 } 828 }
829 else { 829 else {
830 inputMethodDict->insert( w, ( void* ) mode ); 830 inputMethodDict->insert( w, ( void* ) mode );
831 } 831 }
832} 832}
833 833
834class HackDialog : public QDialog 834class HackDialog : public QDialog
835{ 835{
836public: 836public:
837 void acceptIt() 837 void acceptIt()
838 { 838 {
839 accept(); 839 accept();
840 } 840 }
841 void rejectIt() 841 void rejectIt()
842 { 842 {
843 reject(); 843 reject();
844 } 844 }
845}; 845};
846 846
847 847
848void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 848void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
849{ 849{
850 // specialised actions for certain widgets. May want to 850 // specialised actions for certain widgets. May want to
851 // add more stuff here. 851 // add more stuff here.
852 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 852 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
853 && activePopupWidget() ->parentWidget() 853 && activePopupWidget() ->parentWidget()
854 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 854 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
855 key = Qt::Key_Return; 855 key = Qt::Key_Return;
856 856
857 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 857 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
858 key = Qt::Key_Return; 858 key = Qt::Key_Return;
859 859
860#ifdef QWS 860#ifdef QWS
861 861
862 ke->simpleData.keycode = key; 862 ke->simpleData.keycode = key;
863#endif 863#endif
864} 864}
865 865
866class HackWidget : public QWidget 866class HackWidget : public QWidget
867{ 867{
868public: 868public:
869 bool needsOk() 869 bool needsOk()
870 { 870 {
871 return ( getWState() & WState_Reserved1 ); 871 return ( getWState() & WState_Reserved1 );
872 } 872 }
873}; 873};
874 874
875/*! 875/*!
876 \internal 876 \internal
877*/ 877*/
878 878
879#ifdef QWS 879#ifdef QWS
880bool QPEApplication::qwsEventFilter( QWSEvent * e ) 880bool QPEApplication::qwsEventFilter( QWSEvent * e )
881{ 881{
882 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 882 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
883 if ( qApp->type() != QApplication::GuiServer ) { 883 if ( qApp->type() != QApplication::GuiServer ) {
884 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 884 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
885 e << d->appName; 885 e << d->appName;
886 } 886 }
887 d->notbusysent = TRUE; 887 d->notbusysent = TRUE;
888 } 888 }
889 if ( type() == GuiServer ) { 889 if ( type() == GuiServer ) {
890 switch ( e->type ) { 890 switch ( e->type ) {
891 case QWSEvent::Mouse: 891 case QWSEvent::Mouse:
892 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 892 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
893 emit clientMoused(); 893 emit clientMoused();
894 break; 894 break;
895 default: 895 default:
896 break; 896 break;
897 } 897 }
898 } 898 }
899 if ( e->type == QWSEvent::Key ) { 899 if ( e->type == QWSEvent::Key ) {
900 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 900 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
901 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 901 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
902 // Use special "OK" key to press "OK" on top level widgets 902 // Use special "OK" key to press "OK" on top level widgets
903 QWidget * active = activeWindow(); 903 QWidget * active = activeWindow();
904 QWidget *popup = 0; 904 QWidget *popup = 0;
905 if ( active && active->isPopup() ) { 905 if ( active && active->isPopup() ) {
906 popup = active; 906 popup = active;
907 active = active->parentWidget(); 907 active = active->parentWidget();
908 } 908 }
909 if ( active && ( int ) active->winId() == ke->simpleData.window && 909 if ( active && ( int ) active->winId() == ke->simpleData.window &&
910 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 910 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
911 if ( ke->simpleData.is_press ) { 911 if ( ke->simpleData.is_press ) {
912 if ( popup ) 912 if ( popup )
913 popup->close(); 913 popup->close();
914 if ( active->inherits( "QDialog" ) ) { 914 if ( active->inherits( "QDialog" ) ) {
915 HackDialog * d = ( HackDialog * ) active; 915 HackDialog * d = ( HackDialog * ) active;
916 d->acceptIt(); 916 d->acceptIt();
917 return TRUE; 917 return TRUE;
918 } 918 }
919 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 919 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
920 QSignal s; 920 QSignal s;
921 s.connect( active, SLOT( accept() ) ); 921 s.connect( active, SLOT( accept() ) );
922 s.activate(); 922 s.activate();
923 } 923 }
924 else { 924 else {
925 // do the same as with the select key: Map to the default action of the widget: 925 // do the same as with the select key: Map to the default action of the widget:
926 mapToDefaultAction( ke, Qt::Key_Return ); 926 mapToDefaultAction( ke, Qt::Key_Return );
927 } 927 }
928 } 928 }
929 } 929 }
930 } 930 }
931 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 931 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
932 // Use special "select" key to do whatever default action a widget has 932 // Use special "select" key to do whatever default action a widget has
933 mapToDefaultAction( ke, Qt::Key_Space ); 933 mapToDefaultAction( ke, Qt::Key_Space );
934 } 934 }
935 else if ( ke->simpleData.keycode == Qt::Key_Escape && 935 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
936 ke->simpleData.is_press ) { 936 ke->simpleData.is_press ) {
937 // Escape key closes app if focus on toplevel 937 // Escape key closes app if focus on toplevel
938 QWidget * active = activeWindow(); 938 QWidget * active = activeWindow();
939 if ( active && active->testWFlags( WType_TopLevel ) && 939 if ( active && active->testWFlags( WType_TopLevel ) &&
940 ( int ) active->winId() == ke->simpleData.window && 940 ( int ) active->winId() == ke->simpleData.window &&
941 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 941 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
942 if ( active->inherits( "QDialog" ) ) { 942 if ( active->inherits( "QDialog" ) ) {
943 HackDialog * d = ( HackDialog * ) active; 943 HackDialog * d = ( HackDialog * ) active;
944 d->rejectIt(); 944 d->rejectIt();
945 return TRUE; 945 return TRUE;
946 } 946 }
947 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { 947 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
948 active->close(); 948 active->close();
949 } 949 }
950 } 950 }
951 } 951 }
952 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 952 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
953 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 953 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
954 // but we cannot access libopie function within libqpe :( 954 // but we cannot access libopie function within libqpe :(
955 955
956 QWidget * active = activeWindow ( ); 956 QWidget * active = activeWindow ( );
957 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 957 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
958 if ( d-> kbgrabbed ) { // we grabbed the keyboard 958 if ( d-> kbgrabbed ) { // we grabbed the keyboard
959 QChar ch ( ke-> simpleData.unicode ); 959 QChar ch ( ke-> simpleData.unicode );
960 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 960 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
961 ke-> simpleData.keycode, 961 ke-> simpleData.keycode,
962 ch. latin1 ( ), 962 ch. latin1 ( ),
963 ke-> simpleData.modifiers, 963 ke-> simpleData.modifiers,
964 QString ( ch ), 964 QString ( ch ),
965 ke-> simpleData.is_auto_repeat, 1 ); 965 ke-> simpleData.is_auto_repeat, 1 );
966 966
967 QObject *which = QWidget::keyboardGrabber ( ); 967 QObject *which = QWidget::keyboardGrabber ( );
968 if ( !which ) 968 if ( !which )
969 which = QApplication::focusWidget ( ); 969 which = QApplication::focusWidget ( );
970 if ( !which ) 970 if ( !which )
971 which = QApplication::activeWindow ( ); 971 which = QApplication::activeWindow ( );
972 if ( !which ) 972 if ( !which )
973 which = qApp; 973 which = qApp;
974 974
975 QApplication::sendEvent ( which, &qke ); 975 QApplication::sendEvent ( which, &qke );
976 } 976 }
977 else { // we didn't grab the keyboard, so send the event to the launcher 977 else { // we didn't grab the keyboard, so send the event to the launcher
978 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 978 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
979 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 979 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
980 } 980 }
981 } 981 }
982 return true; 982 return true;
983 } 983 }
984 } 984 }
985 if ( e->type == QWSEvent::Focus ) { 985 if ( e->type == QWSEvent::Focus ) {
986 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 986 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
987 if ( !fe->simpleData.get_focus ) { 987 if ( !fe->simpleData.get_focus ) {
988 QWidget * active = activeWindow(); 988 QWidget * active = activeWindow();
989 while ( active && active->isPopup() ) { 989 while ( active && active->isPopup() ) {
990 active->close(); 990 active->close();
991 active = activeWindow(); 991 active = activeWindow();
992 } 992 }
993 } 993 }
994 else { 994 else {
995 // make sure our modal widget is ALWAYS on top 995 // make sure our modal widget is ALWAYS on top
996 QWidget *topm = activeModalWidget(); 996 QWidget *topm = activeModalWidget();
997 if ( topm ) { 997 if ( topm ) {
998 topm->raise(); 998 topm->raise();
999 } 999 }
1000 } 1000 }
1001 if ( fe->simpleData.get_focus && inputMethodDict ) { 1001 if ( fe->simpleData.get_focus && inputMethodDict ) {
1002 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1002 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1003 if ( m == AlwaysOff ) 1003 if ( m == AlwaysOff )
1004 Global::hideInputMethod(); 1004 Global::hideInputMethod();
1005 if ( m == AlwaysOn ) 1005 if ( m == AlwaysOn )
1006 Global::showInputMethod(); 1006 Global::showInputMethod();
1007 } 1007 }
1008 } 1008 }
1009 1009
1010 1010
1011 return QApplication::qwsEventFilter( e ); 1011 return QApplication::qwsEventFilter( e );
1012} 1012}
1013#endif 1013#endif
1014 1014
1015/*! 1015/*!
1016 Destroys the QPEApplication. 1016 Destroys the QPEApplication.
1017*/ 1017*/
1018QPEApplication::~QPEApplication() 1018QPEApplication::~QPEApplication()
1019{ 1019{
1020 ungrabKeyboard(); 1020 ungrabKeyboard();
1021#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1021#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1022 // Need to delete QCopChannels early, since the display will 1022 // Need to delete QCopChannels early, since the display will
1023 // be gone by the time we get to ~QObject(). 1023 // be gone by the time we get to ~QObject().
1024 delete sysChannel; 1024 delete sysChannel;
1025 delete pidChannel; 1025 delete pidChannel;
1026#endif 1026#endif
1027 1027
1028 delete d; 1028 delete d;
1029} 1029}
1030 1030
1031/*! 1031/*!
1032 Returns <tt>$OPIEDIR/</tt>. 1032 Returns <tt>$OPIEDIR/</tt>.
1033*/ 1033*/
1034QString QPEApplication::qpeDir() 1034QString QPEApplication::qpeDir()
1035{ 1035{
1036 const char * base = getenv( "OPIEDIR" ); 1036 const char * base = getenv( "OPIEDIR" );
1037 if ( base ) 1037 if ( base )
1038 return QString( base ) + "/"; 1038 return QString( base ) + "/";
1039 1039
1040 return QString( "../" ); 1040 return QString( "../" );
1041} 1041}
1042 1042
1043/*! 1043/*!
1044 Returns the user's current Document directory. There is a trailing "/". 1044 Returns the user's current Document directory. There is a trailing "/".
1045 .. well, it does now,, and there's no trailing '/' 1045 .. well, it does now,, and there's no trailing '/'
1046*/ 1046*/
1047QString QPEApplication::documentDir() 1047QString QPEApplication::documentDir()
1048{ 1048{
1049 const char* base = getenv( "HOME"); 1049 const char* base = getenv( "HOME");
1050 if ( base ) 1050 if ( base )
1051 return QString( base ) + "/Documents"; 1051 return QString( base ) + "/Documents";
1052 1052
1053 return QString( "../Documents" ); 1053 return QString( "../Documents" );
1054} 1054}
1055 1055
1056static int deforient = -1; 1056static int deforient = -1;
1057 1057
1058/*! 1058/*!
1059 \internal 1059 \internal
1060*/ 1060*/
1061int QPEApplication::defaultRotation() 1061int QPEApplication::defaultRotation()
1062{ 1062{
1063 if ( deforient < 0 ) { 1063 if ( deforient < 0 ) {
1064 QString d = getenv( "QWS_DISPLAY" ); 1064 QString d = getenv( "QWS_DISPLAY" );
1065 if ( d.contains( "Rot90" ) ) { 1065 if ( d.contains( "Rot90" ) ) {
1066 deforient = 90; 1066 deforient = 90;
1067 } 1067 }
1068 else if ( d.contains( "Rot180" ) ) { 1068 else if ( d.contains( "Rot180" ) ) {
1069 deforient = 180; 1069 deforient = 180;
1070 } 1070 }
1071 else if ( d.contains( "Rot270" ) ) { 1071 else if ( d.contains( "Rot270" ) ) {
1072 deforient = 270; 1072 deforient = 270;
1073 } 1073 }
1074 else { 1074 else {
1075 deforient = 0; 1075 deforient = 0;
1076 } 1076 }
1077 } 1077 }
1078 return deforient; 1078 return deforient;
1079} 1079}
1080 1080
1081/*! 1081/*!
1082 \internal 1082 \internal
1083*/ 1083*/
1084void QPEApplication::setDefaultRotation( int r ) 1084void QPEApplication::setDefaultRotation( int r )
1085{ 1085{
1086 if ( qApp->type() == GuiServer ) { 1086 if ( qApp->type() == GuiServer ) {
1087 deforient = r; 1087 deforient = r;
1088 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1088 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1089 Config config("qpe"); 1089 Config config("qpe");
1090 config.setGroup( "Rotation" ); 1090 config.setGroup( "Rotation" );
1091 config.writeEntry( "Rot", r ); 1091 config.writeEntry( "Rot", r );
1092 } 1092 }
1093 else { 1093 else {
1094#ifndef QT_NO_COP 1094#ifndef QT_NO_COP
1095 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1095 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1096 e << r; 1096 e << r;
1097 } 1097 }
1098#endif 1098#endif
1099 1099
1100 } 1100 }
1101} 1101}
1102 1102
1103#include <qgfx_qws.h> 1103#include <qgfx_qws.h>
1104#include <qwindowsystem_qws.h> 1104#include <qwindowsystem_qws.h>
1105 1105
1106extern void qws_clearLoadedFonts(); 1106extern void qws_clearLoadedFonts();
1107 1107
1108void QPEApplication::setCurrentMode( int x, int y, int depth ) 1108void QPEApplication::setCurrentMode( int x, int y, int depth )
1109{ 1109{
1110 // Reset the caches 1110 // Reset the caches
1111 qws_clearLoadedFonts(); 1111 qws_clearLoadedFonts();
1112 QPixmapCache::clear(); 1112 QPixmapCache::clear();
1113 1113
1114 // Change the screen mode 1114 // Change the screen mode
1115 qt_screen->setMode(x, y, depth); 1115 qt_screen->setMode(x, y, depth);
1116 1116
1117 if ( qApp->type() == GuiServer ) { 1117 if ( qApp->type() == GuiServer ) {
1118 // Reconfigure the GuiServer 1118 // Reconfigure the GuiServer
1119 qwsServer->beginDisplayReconfigure(); 1119 qwsServer->beginDisplayReconfigure();
1120 qwsServer->endDisplayReconfigure(); 1120 qwsServer->endDisplayReconfigure();
1121 1121
1122 // Get all the running apps to reset 1122 // Get all the running apps to reset
1123 QCopEnvelope env( "QPE/System", "reset()" ); 1123 QCopEnvelope env( "QPE/System", "reset()" );
1124 } 1124 }
1125} 1125}
1126 1126
1127void QPEApplication::reset() { 1127void QPEApplication::reset() {
1128 // Reconnect to the screen 1128 // Reconnect to the screen
1129 qt_screen->disconnect(); 1129 qt_screen->disconnect();
1130 qt_screen->connect( QString::null ); 1130 qt_screen->connect( QString::null );
1131 1131
1132 // Redraw everything 1132 // Redraw everything
1133 applyStyle(); 1133 applyStyle();
1134} 1134}
1135 1135
1136/*! 1136/*!
1137 \internal 1137 \internal
1138*/ 1138*/
1139void QPEApplication::applyStyle() 1139void QPEApplication::applyStyle()
1140{ 1140{
1141 Config config( "qpe" ); 1141 Config config( "qpe" );
1142 config.setGroup( "Appearance" ); 1142 config.setGroup( "Appearance" );
1143 1143
1144#if QT_VERSION > 233 1144#if QT_VERSION > 233
1145#if !defined(OPIE_NO_OVERRIDE_QT) 1145#if !defined(OPIE_NO_OVERRIDE_QT)
1146 // don't block ourselves ... 1146 // don't block ourselves ...
1147 Opie::force_appearance = 0; 1147 Opie::force_appearance = 0;
1148 1148
1149 static QString appname = Opie::binaryName ( ); 1149 static QString appname = Opie::binaryName ( );
1150 1150
1151 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 1151 QStringList ex = config. readListEntry ( "NoStyle", ';' );
1152 int nostyle = 0; 1152 int nostyle = 0;
1153 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 1153 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
1154 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 1154 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
1155 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 1155 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
1156 break; 1156 break;
1157 } 1157 }
1158 } 1158 }
1159#else 1159#else
1160 int nostyle = 0; 1160 int nostyle = 0;
1161#endif 1161#endif
1162 1162
1163 // Widget style 1163 // Widget style
1164 QString style = config.readEntry( "Style", "FlatStyle" ); 1164 QString style = config.readEntry( "Style", "FlatStyle" );
1165 1165
1166 // don't set a custom style 1166 // don't set a custom style
1167 if ( nostyle & Opie::Force_Style ) 1167 if ( nostyle & Opie::Force_Style )
1168 style = "FlatStyle"; 1168 style = "FlatStyle";
1169 1169
1170 internalSetStyle ( style ); 1170 internalSetStyle ( style );
1171 1171
1172 // Colors - from /etc/colors/Liquid.scheme 1172 // Colors - from /etc/colors/Liquid.scheme
1173 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1173 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1174 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1174 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1175 QPalette pal( btncolor, bgcolor ); 1175 QPalette pal( btncolor, bgcolor );
1176 QString color = config.readEntry( "Highlight", "#73adef" ); 1176 QString color = config.readEntry( "Highlight", "#73adef" );
1177 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1177 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1178 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1178 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1179 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1179 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1180 color = config.readEntry( "Text", "#000000" ); 1180 color = config.readEntry( "Text", "#000000" );
1181 pal.setColor( QColorGroup::Text, QColor( color ) ); 1181 pal.setColor( QColorGroup::Text, QColor( color ) );
1182 color = config.readEntry( "ButtonText", "#000000" ); 1182 color = config.readEntry( "ButtonText", "#000000" );
1183 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1183 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1184 color = config.readEntry( "Base", "#FFFFFF" ); 1184 color = config.readEntry( "Base", "#FFFFFF" );
1185 pal.setColor( QColorGroup::Base, QColor( color ) ); 1185 pal.setColor( QColorGroup::Base, QColor( color ) );
1186 1186
1187 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1187 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1188 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1188 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1189 1189
1190 setPalette( pal, TRUE ); 1190 setPalette( pal, TRUE );
1191 1191
1192 // Window Decoration 1192 // Window Decoration
1193 QString dec = config.readEntry( "Decoration", "Flat" ); 1193 QString dec = config.readEntry( "Decoration", "Flat" );
1194 1194
1195 // don't set a custom deco 1195 // don't set a custom deco
1196 if ( nostyle & Opie::Force_Decoration ) 1196 if ( nostyle & Opie::Force_Decoration )
1197 dec = ""; 1197 dec = "";
1198 1198
1199 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle); 1199 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle);
1200 1200
1201 if ( dec != d->decorationName ) { 1201 if ( dec != d->decorationName ) {
1202 qwsSetDecoration( new QPEDecoration( dec ) ); 1202 qwsSetDecoration( new QPEDecoration( dec ) );
1203 d->decorationName = dec; 1203 d->decorationName = dec;
1204 } 1204 }
1205 1205
1206 // Font 1206 // Font
1207 QString ff = config.readEntry( "FontFamily", font().family() ); 1207 QString ff = config.readEntry( "FontFamily", font().family() );
1208 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1208 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1209 1209
1210 // don't set a custom font 1210 // don't set a custom font
1211 if ( nostyle & Opie::Force_Font ) { 1211 if ( nostyle & Opie::Force_Font ) {
1212 ff = "Vera"; 1212 ff = "Vera";
1213 fs = 10; 1213 fs = 10;
1214 } 1214 }
1215 1215
1216 setFont ( QFont ( ff, fs ), true ); 1216 setFont ( QFont ( ff, fs ), true );
1217 1217
1218#if !defined(OPIE_NO_OVERRIDE_QT) 1218#if !defined(OPIE_NO_OVERRIDE_QT)
1219 // revert to global blocking policy ... 1219 // revert to global blocking policy ...
1220 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 1220 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
1221 Opie::force_appearance &= ~nostyle; 1221 Opie::force_appearance &= ~nostyle;
1222#endif 1222#endif
1223#endif 1223#endif
1224} 1224}
1225 1225
1226void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1226void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1227{ 1227{
1228#ifdef Q_WS_QWS 1228#ifdef Q_WS_QWS
1229 QDataStream stream( data, IO_ReadOnly ); 1229 QDataStream stream( data, IO_ReadOnly );
1230 if ( msg == "applyStyle()" ) { 1230 if ( msg == "applyStyle()" ) {
1231 applyStyle(); 1231 applyStyle();
1232 } 1232 }
1233 else if ( msg == "toggleApplicationMenu()" ) { 1233 else if ( msg == "toggleApplicationMenu()" ) {
1234 QWidget *active = activeWindow ( ); 1234 QWidget *active = activeWindow ( );
1235 1235
1236 if ( active ) { 1236 if ( active ) {
1237 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1237 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1238 bool oldactive = man-> isActive ( ); 1238 bool oldactive = man-> isActive ( );
1239 1239
1240 man-> setActive( !man-> isActive() ); 1240 man-> setActive( !man-> isActive() );
1241 1241
1242 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1242 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1243 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1243 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1244 } 1244 }
1245 } 1245 }
1246 } 1246 }
1247 else if ( msg == "setDefaultRotation(int)" ) { 1247 else if ( msg == "setDefaultRotation(int)" ) {
1248 if ( type() == GuiServer ) { 1248 if ( type() == GuiServer ) {
1249 int r; 1249 int r;
1250 stream >> r; 1250 stream >> r;
1251 setDefaultRotation( r ); 1251 setDefaultRotation( r );
1252 } 1252 }
1253 } 1253 }
1254 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> 1254 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
1255 if ( type() == GuiServer ) { 1255 if ( type() == GuiServer ) {
1256 int x, y, depth; 1256 int x, y, depth;
1257 stream >> x; 1257 stream >> x;
1258 stream >> y; 1258 stream >> y;
1259 stream >> depth; 1259 stream >> depth;
1260 setCurrentMode( x, y, depth ); 1260 setCurrentMode( x, y, depth );
1261 } 1261 }
1262 } 1262 }
1263 else if ( msg == "reset()" ) { 1263 else if ( msg == "reset()" ) {
1264 if ( type() != GuiServer ) 1264 if ( type() != GuiServer )
1265 reset(); 1265 reset();
1266 } 1266 }
1267 else if ( msg == "setCurrentRotation(int)" ) { 1267 else if ( msg == "setCurrentRotation(int)" ) {
diff --git a/library/qpedialog.cpp b/library/qpedialog.cpp
index ac42972..da461b7 100644
--- a/library/qpedialog.cpp
+++ b/library/qpedialog.cpp
@@ -1,74 +1,74 @@
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#define protected public 21#define protected public
22#include <qdialog.h> 22#include <qdialog.h>
23#undef protected 23#undef protected
24 24
25#include "qpedialog.h" 25#include "qpedialog.h"
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27 27
28 28
29/** 29/**
30 * \brief This is the only c'tor. 30 * \brief This is the only c'tor.
31 * 31 *
32 * The parent of this Listener is the Dialog you pass. This means once 32 * The parent of this Listener is the Dialog you pass. This means once
33 * the dialog is deleted this listener will be deleted too. 33 * the dialog is deleted this listener will be deleted too.
34 * This Listener listens on QPEApplication::appMessage signal and implements 34 * This Listener listens on QPEApplication::appMessage signal and implements
35 * accept() and reject(). 35 * accept() and reject().
36 * 36 *
37 * \code 37 * \code
38 *QDialog *dialog = new YourDialog(); 38 *QDialog *dialog = new YourDialog();
39 (void)new QPEDialogListener(dialog); 39 (void)new QPEDialogListener(dialog);
40 if( QPEApplication::execDialog(dialog) == QDialog::Accept ){ 40 if( QPEApplication::execDialog(dialog) == QDialog::Accept ){
41 // do some stuff 41 // do some stuff
42 } 42 }
43 delete dialog; 43 delete dialog;
44 44
45 * \endcode 45 * \endcode
46 * 46 *
47 * @param di The dialog to handle 47 * @param di The dialog to handle
48 */ 48 */
49QPEDialogListener::QPEDialogListener(QDialog *di ) : QObject(di) 49QPEDialogListener::QPEDialogListener(QDialog *di ) : QObject(di)
50{ 50{
51 dialog = di; 51 dialog = di;
52 connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 52 connect(qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
53 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 53 this, SLOT(appMessage(const QCString&,const QByteArray&)) );
54} 54}
55 55
56 56
57/** 57/**
58 * d'tor 58 * d'tor
59 */ 59 */
60QPEDialogListener::~QPEDialogListener() {} 60QPEDialogListener::~QPEDialogListener() {}
61 61
62/** 62/**
63 * \internal 63 * \internal
64 */ 64 */
65void QPEDialogListener::appMessage( const QCString &msg, const QByteArray & ) 65void QPEDialogListener::appMessage( const QCString &msg, const QByteArray & )
66{ 66{
67 if (!dialog) 67 if (!dialog)
68 return; 68 return;
69 if (msg == "accept()") { 69 if (msg == "accept()") {
70 dialog->accept(); 70 dialog->accept();
71 } else if (msg == "reject()") { 71 } else if (msg == "reject()") {
72 dialog->reject(); 72 dialog->reject();
73 } 73 }
74} 74}
diff --git a/library/storage.cpp b/library/storage.cpp
index 0ea465b..fcee689 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,401 +1,401 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org> 2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org>
3** Copyright (C) Lorn Potter <llornkcor@handhelds.org> 3** Copyright (C) Lorn Potter <llornkcor@handhelds.org>
4** Copyright (C) 2000 Trolltech AS. All rights reserved. 4** Copyright (C) 2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of Opie Environment. 6** This file is part of Opie Environment.
7** 7**
8** This file may be distributed and/or modified under the terms of the 8** This file may be distributed and/or modified under the terms of the
9** GNU General Public License version 2 as published by the Free Software 9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the 10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file. 11** packaging of this file.
12** 12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15** 15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information. 16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17** 17**
18** Contact info@trolltech.com if any conditions of this licensing are 18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you. 19** not clear to you.
20** 20**
21**********************************************************************/ 21**********************************************************************/
22 22
23#include <qpe/storage.h> 23#include <qpe/storage.h>
24 24
25#include <qcopchannel_qws.h> 25#include <qcopchannel_qws.h>
26 26
27#include <stdio.h> 27#include <stdio.h>
28 28
29#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 29#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
30#include <sys/vfs.h> 30#include <sys/vfs.h>
31#include <mntent.h> 31#include <mntent.h>
32#endif 32#endif
33 33
34#ifdef Q_OS_MACX 34#ifdef Q_OS_MACX
35# include <sys/param.h> 35# include <sys/param.h>
36# include <sys/ucred.h> 36# include <sys/ucred.h>
37# include <sys/mount.h> 37# include <sys/mount.h>
38# include <stdio.h> // For strerror() 38# include <stdio.h> // For strerror()
39# include <errno.h> 39# include <errno.h>
40#endif /* Q_OS_MACX */ 40#endif /* Q_OS_MACX */
41 41
42 42
43// Shouldn't be here ! (eilers) 43// Shouldn't be here ! (eilers)
44// #include <sys/vfs.h> 44// #include <sys/vfs.h>
45// #include <mntent.h> 45// #include <mntent.h>
46 46
47 47
48static bool isCF(const QString& m) 48static bool isCF(const QString& m)
49{ 49{
50 50
51#ifndef Q_OS_MACX 51#ifndef Q_OS_MACX
52 FILE* f = fopen("/var/run/stab", "r"); 52 FILE* f = fopen("/var/run/stab", "r");
53 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 53 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
54 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 54 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
55 if ( f ) 55 if ( f )
56 { 56 {
57 char line[1024]; 57 char line[1024];
58 char devtype[80]; 58 char devtype[80];
59 char devname[80]; 59 char devname[80];
60 while ( fgets( line, 1024, f ) ) 60 while ( fgets( line, 1024, f ) )
61 { 61 {
62 // 0 ide ide-cs 0 hda 3 0 62 // 0 ide ide-cs 0 hda 3 0
63 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 63 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
64 { 64 {
65 if ( QString(devtype) == "ide" && m.find(devname)>0 ) 65 if ( QString(devtype) == "ide" && m.find(devname)>0 )
66 { 66 {
67 fclose(f); 67 fclose(f);
68 return TRUE; 68 return TRUE;
69 } 69 }
70 } 70 }
71 } 71 }
72 fclose(f); 72 fclose(f);
73 } 73 }
74#endif /* Q_OS_MACX */ 74#endif /* Q_OS_MACX */
75 return FALSE; 75 return FALSE;
76} 76}
77 77
78/*! \class StorageInfo storage.h 78/*! \class StorageInfo storage.h
79 \brief The StorageInfo class describes the disks mounted on the file system. 79 \brief The StorageInfo class describes the disks mounted on the file system.
80 80
81 This class provides access to the mount information for the Linux 81 This class provides access to the mount information for the Linux
82 filesystem. Each mount point is represented by the FileSystem class. 82 filesystem. Each mount point is represented by the FileSystem class.
83 To ensure this class has the most up to date size information, call 83 To ensure this class has the most up to date size information, call
84 the update() method. Note that this will automatically be signaled 84 the update() method. Note that this will automatically be signaled
85 by the operating system when a disk has been mounted or unmounted. 85 by the operating system when a disk has been mounted or unmounted.
86 86
87 \ingroup qtopiaemb 87 \ingroup qtopiaemb
88*/ 88*/
89 89
90/*! Constructor that determines the current mount points of the filesystem. 90/*! Constructor that determines the current mount points of the filesystem.
91 The standard \a parent parameters is passed on to QObject. 91 The standard \a parent parameters is passed on to QObject.
92 */ 92 */
93StorageInfo::StorageInfo( QObject *parent ) 93StorageInfo::StorageInfo( QObject *parent )
94 : QObject( parent ) 94 : QObject( parent )
95{ 95{
96 mFileSystems.setAutoDelete( TRUE ); 96 mFileSystems.setAutoDelete( TRUE );
97 channel = new QCopChannel( "QPE/Card", this ); 97 channel = new QCopChannel( "QPE/Card", this );
98 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 98 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
99 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 99 this, SLOT(cardMessage(const QCString&,const QByteArray&)) );
100 update(); 100 update();
101} 101}
102 102
103/*! Returns the longest matching FileSystem that starts with the 103/*! Returns the longest matching FileSystem that starts with the
104 same prefix as \a filename as its mount point. 104 same prefix as \a filename as its mount point.
105*/ 105*/
106const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 106const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
107{ 107{
108 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 108 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
109 { 109 {
110 if ( filename.startsWith( (*i)->path() ) ) 110 if ( filename.startsWith( (*i)->path() ) )
111 return (*i); 111 return (*i);
112 } 112 }
113 return 0; 113 return 0;
114} 114}
115 115
116 116
117void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 117void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
118{ 118{
119 if ( msg == "mtabChanged()" ) 119 if ( msg == "mtabChanged()" )
120 update(); 120 update();
121} 121}
122 122
123 123
124/*! Updates the mount and free space available information for each mount 124/*! Updates the mount and free space available information for each mount
125 point. This method is automatically called when a disk is mounted or 125 point. This method is automatically called when a disk is mounted or
126 unmounted. 126 unmounted.
127*/ 127*/
128// cause of the lack of a d pointer we need 128// cause of the lack of a d pointer we need
129// to store informations in a config file :( 129// to store informations in a config file :(
130void StorageInfo::update() 130void StorageInfo::update()
131{ 131{
132 //qDebug("StorageInfo::updating"); 132 //qDebug("StorageInfo::updating");
133#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 133#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
134 struct mntent *me; 134 struct mntent *me;
135 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 135 FILE *mntfp = setmntent( "/etc/mtab", "r" );
136 136
137 QStringList curdisks; 137 QStringList curdisks;
138 QStringList curopts; 138 QStringList curopts;
139 QStringList curfs; 139 QStringList curfs;
140 bool rebuild = FALSE; 140 bool rebuild = FALSE;
141 int n=0; 141 int n=0;
142 if ( mntfp ) 142 if ( mntfp )
143 { 143 {
144 while ( (me = getmntent( mntfp )) != 0 ) 144 while ( (me = getmntent( mntfp )) != 0 )
145 { 145 {
146 QString fs = me->mnt_fsname; 146 QString fs = me->mnt_fsname;
147 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 147 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
148 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 148 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
149 || fs.left( 14 ) == "/dev/mmc/part1" 149 || fs.left( 14 ) == "/dev/mmc/part1"
150 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) 150 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" )
151 { 151 {
152 n++; 152 n++;
153 curdisks.append(fs); 153 curdisks.append(fs);
154 curopts.append( me->mnt_opts ); 154 curopts.append( me->mnt_opts );
155 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); 155 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
156 curfs.append( me->mnt_dir ); 156 curfs.append( me->mnt_dir );
157 bool found = FALSE; 157 bool found = FALSE;
158 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 158 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
159 { 159 {
160 if ( (*i)->disk() == fs ) 160 if ( (*i)->disk() == fs )
161 { 161 {
162 found = TRUE; 162 found = TRUE;
163 break; 163 break;
164 } 164 }
165 } 165 }
166 if ( !found ) 166 if ( !found )
167 rebuild = TRUE; 167 rebuild = TRUE;
168 } 168 }
169 } 169 }
170 endmntent( mntfp ); 170 endmntent( mntfp );
171 } 171 }
172 if ( rebuild || n != (int)mFileSystems.count() ) 172 if ( rebuild || n != (int)mFileSystems.count() )
173 { 173 {
174 mFileSystems.clear(); 174 mFileSystems.clear();
175 QStringList::ConstIterator it=curdisks.begin(); 175 QStringList::ConstIterator it=curdisks.begin();
176 QStringList::ConstIterator fsit=curfs.begin(); 176 QStringList::ConstIterator fsit=curfs.begin();
177 QStringList::ConstIterator optsIt=curopts.begin(); 177 QStringList::ConstIterator optsIt=curopts.begin();
178 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) 178 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt)
179 { 179 {
180 QString opts = *optsIt; 180 QString opts = *optsIt;
181 181
182 QString disk = *it; 182 QString disk = *it;
183 QString humanname; 183 QString humanname;
184 bool removable = FALSE; 184 bool removable = FALSE;
185 if ( isCF(disk) ) 185 if ( isCF(disk) )
186 { 186 {
187 humanname = tr("CF Card"); 187 humanname = tr("CF Card");
188 removable = TRUE; 188 removable = TRUE;
189 } 189 }
190 else if ( disk == "/dev/hda1" ) 190 else if ( disk == "/dev/hda1" )
191 { 191 {
192 humanname = tr("Hard Disk"); 192 humanname = tr("Hard Disk");
193 } 193 }
194 else if ( disk.left(9) == "/dev/mmcd" ) 194 else if ( disk.left(9) == "/dev/mmcd" )
195 { 195 {
196 humanname = tr("SD Card"); 196 humanname = tr("SD Card");
197 removable = TRUE; 197 removable = TRUE;
198 } 198 }
199 else if ( disk.left( 14 ) == "/dev/mmc/part1" ) 199 else if ( disk.left( 14 ) == "/dev/mmc/part1" )
200 { 200 {
201 humanname = tr("MMC Card"); 201 humanname = tr("MMC Card");
202 removable = TRUE; 202 removable = TRUE;
203 } 203 }
204 else if ( disk.left(7) == "/dev/hd" ) 204 else if ( disk.left(7) == "/dev/hd" )
205 humanname = tr("Hard Disk") + " " + disk; 205 humanname = tr("Hard Disk") + " " + disk;
206 else if ( disk.left(7) == "/dev/sd" ) 206 else if ( disk.left(7) == "/dev/sd" )
207 humanname = tr("SCSI Hard Disk") + " " + disk; 207 humanname = tr("SCSI Hard Disk") + " " + disk;
208 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs 208 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
209 humanname = tr("Internal Memory"); 209 humanname = tr("Internal Memory");
210 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 210 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
211 humanname = tr("Internal Storage"); 211 humanname = tr("Internal Storage");
212 else if ( disk.left(14) == "/dev/mtdblock/" ) 212 else if ( disk.left(14) == "/dev/mtdblock/" )
213 humanname = tr("Internal Storage") + " " + disk; 213 humanname = tr("Internal Storage") + " " + disk;
214 else if ( disk.left(13) == "/dev/mtdblock" ) 214 else if ( disk.left(13) == "/dev/mtdblock" )
215 humanname = tr("Internal Storage") + " " + disk; 215 humanname = tr("Internal Storage") + " " + disk;
216 else if ( disk.left(9) == "/dev/root" ) 216 else if ( disk.left(9) == "/dev/root" )
217 humanname = tr("Internal Storage") + " " + disk; 217 humanname = tr("Internal Storage") + " " + disk;
218 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs 218 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
219 humanname = tr("Internal Memory"); 219 humanname = tr("Internal Memory");
220 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 220 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
221 mFileSystems.append( fs ); 221 mFileSystems.append( fs );
222 } 222 }
223 emit disksChanged(); 223 emit disksChanged();
224 } 224 }
225 else 225 else
226 { 226 {
227 // just update them 227 // just update them
228 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 228 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
229 i.current()->update(); 229 i.current()->update();
230 } 230 }
231#endif 231#endif
232} 232}
233 233
234bool deviceTab( const char *device) 234bool deviceTab( const char *device)
235{ 235{
236 QString name = device; 236 QString name = device;
237 bool hasDevice=false; 237 bool hasDevice=false;
238 238
239#ifdef Q_OS_MACX 239#ifdef Q_OS_MACX
240 // Darwin (MacOS X) 240 // Darwin (MacOS X)
241 struct statfs** mntbufp; 241 struct statfs** mntbufp;
242 int count = 0; 242 int count = 0;
243 if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 ) 243 if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 )
244 { 244 {
245 qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) ); 245 qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) );
246 hasDevice = false; 246 hasDevice = false;
247 } 247 }
248 for( int i = 0; i < count; i++ ) 248 for( int i = 0; i < count; i++ )
249 { 249 {
250 QString deviceName = mntbufp[i]->f_mntfromname; 250 QString deviceName = mntbufp[i]->f_mntfromname;
251 qDebug(deviceName); 251 qDebug(deviceName);
252 if( deviceName.left( name.length() ) == name ) 252 if( deviceName.left( name.length() ) == name )
253 hasDevice = true; 253 hasDevice = true;
254 } 254 }
255#else 255#else
256 // Linux 256 // Linux
257 struct mntent *me; 257 struct mntent *me;
258 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 258 FILE *mntfp = setmntent( "/etc/mtab", "r" );
259 if ( mntfp ) 259 if ( mntfp )
260 { 260 {
261 while ( (me = getmntent( mntfp )) != 0 ) 261 while ( (me = getmntent( mntfp )) != 0 )
262 { 262 {
263 QString deviceName = me->mnt_fsname; 263 QString deviceName = me->mnt_fsname;
264 // qDebug(deviceName); 264 // qDebug(deviceName);
265 if( deviceName.left(name.length()) == name) 265 if( deviceName.left(name.length()) == name)
266 { 266 {
267 hasDevice = true; 267 hasDevice = true;
268 } 268 }
269 } 269 }
270 } 270 }
271 endmntent( mntfp ); 271 endmntent( mntfp );
272#endif /* Q_OS_MACX */ 272#endif /* Q_OS_MACX */
273 273
274 274
275 return hasDevice; 275 return hasDevice;
276} 276}
277 277
278/*! 278/*!
279 * @fn static bool StorageInfo::hasCf() 279 * @fn static bool StorageInfo::hasCf()
280 * @brief returns whether device has Cf mounted 280 * @brief returns whether device has Cf mounted
281 * 281 *
282 */ 282 */
283bool StorageInfo::hasCf() 283bool StorageInfo::hasCf()
284{ 284{
285 return deviceTab("/dev/hd"); 285 return deviceTab("/dev/hd");
286} 286}
287 287
288/*! 288/*!
289 * @fn static bool StorageInfo::hasSd() 289 * @fn static bool StorageInfo::hasSd()
290 * @brief returns whether device has SD mounted 290 * @brief returns whether device has SD mounted
291 * 291 *
292 */ 292 */
293bool StorageInfo::hasSd() 293bool StorageInfo::hasSd()
294{ 294{
295 return deviceTab("/dev/mmcd"); 295 return deviceTab("/dev/mmcd");
296} 296}
297 297
298/*! 298/*!
299 * @fn static bool StorageInfo::hasMmc() 299 * @fn static bool StorageInfo::hasMmc()
300 * @brief returns whether device has mmc mounted 300 * @brief returns whether device has mmc mounted
301 * 301 *
302 */ 302 */
303bool StorageInfo::hasMmc() 303bool StorageInfo::hasMmc()
304{ 304{
305 bool hasMmc=false; 305 bool hasMmc=false;
306 if( deviceTab("/dev/mmc/part")) 306 if( deviceTab("/dev/mmc/part"))
307 hasMmc=true; 307 hasMmc=true;
308 if( deviceTab("/dev/mmcd")) 308 if( deviceTab("/dev/mmcd"))
309 hasMmc=true; 309 hasMmc=true;
310 return hasMmc; 310 return hasMmc;
311} 311}
312 312
313/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const 313/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const
314 Returns a list of all available mounted file systems. 314 Returns a list of all available mounted file systems.
315 315
316 \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp) 316 \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp)
317*/ 317*/
318 318
319/*! \fn void StorageInfo::disksChanged() 319/*! \fn void StorageInfo::disksChanged()
320 Gets emitted when a disk has been mounted or unmounted, such as when 320 Gets emitted when a disk has been mounted or unmounted, such as when
321 a CF c 321 a CF c
322*/ 322*/
323//--------------------------------------------------------------------------- 323//---------------------------------------------------------------------------
324 324
325FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) 325FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o )
326 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) 326 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o )
327{ 327{
328 update(); 328 update();
329} 329}
330 330
331void FileSystem::update() 331void FileSystem::update()
332{ 332{
333#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 333#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
334 struct statfs fs; 334 struct statfs fs;
335 if ( !statfs( fspath.latin1(), &fs ) ) 335 if ( !statfs( fspath.latin1(), &fs ) )
336 { 336 {
337 blkSize = fs.f_bsize; 337 blkSize = fs.f_bsize;
338 totalBlks = fs.f_blocks; 338 totalBlks = fs.f_blocks;
339 availBlks = fs.f_bavail; 339 availBlks = fs.f_bavail;
340 } 340 }
341 else 341 else
342 { 342 {
343 blkSize = 0; 343 blkSize = 0;
344 totalBlks = 0; 344 totalBlks = 0;
345 availBlks = 0; 345 availBlks = 0;
346 } 346 }
347#endif 347#endif
348} 348}
349 349
350/*! \class FileSystem storage.h 350/*! \class FileSystem storage.h
351 \brief The FileSystem class describes a single mount point. 351 \brief The FileSystem class describes a single mount point.
352 352
353 This class simply returns information about a mount point, including 353 This class simply returns information about a mount point, including
354 file system name, mount point, human readable name, size information 354 file system name, mount point, human readable name, size information
355 and mount options information. 355 and mount options information.
356 \ingroup qtopiaemb 356 \ingroup qtopiaemb
357 357
358 \sa StorageInfo 358 \sa StorageInfo
359*/ 359*/
360 360
361/*! \fn const QString &FileSystem::disk() const 361/*! \fn const QString &FileSystem::disk() const
362 Returns the file system name, such as /dev/hda3 362 Returns the file system name, such as /dev/hda3
363*/ 363*/
364 364
365/*! \fn const QString &FileSystem::path() const 365/*! \fn const QString &FileSystem::path() const
366 Returns the mount path, such as /home 366 Returns the mount path, such as /home
367*/ 367*/
368 368
369/*! \fn const QString &FileSystem::name() const 369/*! \fn const QString &FileSystem::name() const
370 Returns the translated, human readable name for the mount directory. 370 Returns the translated, human readable name for the mount directory.
371*/ 371*/
372 372
373/*! \fn const QString &FileSystem::options() const 373/*! \fn const QString &FileSystem::options() const
374 Returns the mount options 374 Returns the mount options
375*/ 375*/
376 376
377/*! \fn long FileSystem::blockSize() const 377/*! \fn long FileSystem::blockSize() const
378 Returns the size of each block on the file system. 378 Returns the size of each block on the file system.
379*/ 379*/
380 380
381/*! \fn long FileSystem::totalBlocks() const 381/*! \fn long FileSystem::totalBlocks() const
382 Returns the total number of blocks on the file system 382 Returns the total number of blocks on the file system
383*/ 383*/
384 384
385/*! \fn long FileSystem::availBlocks() const 385/*! \fn long FileSystem::availBlocks() const
386 Returns the number of available blocks on the file system 386 Returns the number of available blocks on the file system
387 */ 387 */
388 388
389/*! \fn bool FileSystem::isRemovable() const 389/*! \fn bool FileSystem::isRemovable() const
390 Returns flag whether the file system can be removed, such as a CF card 390 Returns flag whether the file system can be removed, such as a CF card
391 would be removable, but the internal memory wouldn't 391 would be removable, but the internal memory wouldn't
392*/ 392*/
393 393
394/*! \fn bool FileSystem::isWritable() const 394/*! \fn bool FileSystem::isWritable() const
395 Returns flag whether the file system is mounted as writable or read-only. 395 Returns flag whether the file system is mounted as writable or read-only.
396 Returns FALSE if read-only, TRUE if read and write. 396 Returns FALSE if read-only, TRUE if read and write.
397*/ 397*/
398 398
399/*! \fn QStringList StorageInfo::fileSystemNames() const 399/*! \fn QStringList StorageInfo::fileSystemNames() const
400 Returns a list of filesystem names. 400 Returns a list of filesystem names.
401*/ 401*/
diff --git a/library/timestring.cpp b/library/timestring.cpp
index 2fd0191..91c29ae 100644
--- a/library/timestring.cpp
+++ b/library/timestring.cpp
@@ -1,365 +1,365 @@
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 "timestring.h" 21#include "timestring.h"
22#include <qobject.h> 22#include <qobject.h>
23#include <qpe/qpeapplication.h> //for qApp 23#include <qpe/qpeapplication.h> //for qApp
24#include "config.h" 24#include "config.h"
25 25
26 26
27class TimeStringFormatKeeper : public QObject 27class TimeStringFormatKeeper : public QObject
28{ 28{
29 Q_OBJECT 29 Q_OBJECT
30public: 30public:
31 static DateFormat currentFormat() 31 static DateFormat currentFormat()
32 { 32 {
33 if ( !self ) 33 if ( !self )
34 self = new TimeStringFormatKeeper; 34 self = new TimeStringFormatKeeper;
35 return self->format; 35 return self->format;
36 } 36 }
37private slots: 37private slots:
38 void formatChanged( DateFormat f ) 38 void formatChanged( DateFormat f )
39 { 39 {
40 format = f; 40 format = f;
41 } 41 }
42private: 42private:
43 static TimeStringFormatKeeper *self; 43 static TimeStringFormatKeeper *self;
44 DateFormat format; 44 DateFormat format;
45 45
46 TimeStringFormatKeeper() 46 TimeStringFormatKeeper()
47 : QObject( qApp ) 47 : QObject( qApp )
48 { 48 {
49 Config config("qpe"); 49 Config config("qpe");
50 config.setGroup( "Date" ); 50 config.setGroup( "Date" );
51 format = DateFormat(QChar(config.readEntry("Separator", "/")[0]), 51 format = DateFormat(QChar(config.readEntry("Separator", "/")[0]),
52 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), 52 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
53 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); 53 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
54 54
55 connect( qApp, SIGNAL( dateFormatChanged(DateFormat) ), 55 connect( qApp, SIGNAL( dateFormatChanged(DateFormat) ),
56 this, SLOT( formatChanged( DateFormat ) ) ); 56 this, SLOT( formatChanged(DateFormat) ) );
57 } 57 }
58}; 58};
59 59
60TimeStringFormatKeeper *TimeStringFormatKeeper::self = 0; 60TimeStringFormatKeeper *TimeStringFormatKeeper::self = 0;
61 61
62QString DateFormat::toNumberString() const 62QString DateFormat::toNumberString() const
63{ 63{
64 QString buf = ""; 64 QString buf = "";
65 // for each part of the order 65 // for each part of the order
66 for (int i = 0; i < 3; i++) { 66 for (int i = 0; i < 3; i++) {
67 // switch on the relavent 3 bits. 67 // switch on the relavent 3 bits.
68 switch((_shortOrder >> (i * 3)) & 0x0007) { 68 switch((_shortOrder >> (i * 3)) & 0x0007) {
69 case 0x0001: 69 case 0x0001:
70 buf += QObject::tr( "D" , "Shortcut for Day"); 70 buf += QObject::tr( "D" , "Shortcut for Day");
71 break; 71 break;
72 case 0x0002: 72 case 0x0002:
73 buf += QObject::tr( "M", "Shortcur for Month" ); 73 buf += QObject::tr( "M", "Shortcur for Month" );
74 break; 74 break;
75 case 0x0004: 75 case 0x0004:
76 buf += QObject::tr( "Y" ); 76 buf += QObject::tr( "Y" );
77 break; 77 break;
78 } 78 }
79 if (i < 2) 79 if (i < 2)
80 buf += _shortSeparator; 80 buf += _shortSeparator;
81 } 81 }
82 return buf; 82 return buf;
83} 83}
84 84
85QString DateFormat::toWordString() const 85QString DateFormat::toWordString() const
86{ 86{
87 QString buf = ""; 87 QString buf = "";
88 // for each part of the order 88 // for each part of the order
89 for (int i = 0; i < 3; i++) { 89 for (int i = 0; i < 3; i++) {
90 // switch on the relavent 3 bits. 90 // switch on the relavent 3 bits.
91 switch((_longOrder >> (i * 3)) & 0x0007) { 91 switch((_longOrder >> (i * 3)) & 0x0007) {
92 case 0x0001: 92 case 0x0001:
93 buf += QObject::tr( "day" ); 93 buf += QObject::tr( "day" );
94 if (i < 2) { 94 if (i < 2) {
95 if ((_shortOrder << ((i+1) * 3)) & 0x0007) 95 if ((_shortOrder << ((i+1) * 3)) & 0x0007)
96 buf += ", "; 96 buf += ", ";
97 else 97 else
98 buf += " "; 98 buf += " ";
99 } 99 }
100 break; 100 break;
101 case 0x0002: 101 case 0x0002:
102 buf += QObject::tr( "month" ); 102 buf += QObject::tr( "month" );
103 if (i < 2) 103 if (i < 2)
104 buf += " "; 104 buf += " ";
105 break; 105 break;
106 case 0x0004: 106 case 0x0004:
107 buf += QObject::tr( "year" ); 107 buf += QObject::tr( "year" );
108 if (i < 2) 108 if (i < 2)
109 buf += ", "; 109 buf += ", ";
110 break; 110 break;
111 } 111 }
112 } 112 }
113 return buf; 113 return buf;
114} 114}
115 115
116QString DateFormat::numberDate(const QDate &d, int v) const 116QString DateFormat::numberDate(const QDate &d, int v) const
117{ 117{
118 QString buf = ""; 118 QString buf = "";
119 119
120 int pad = 2; 120 int pad = 2;
121 121
122 // for each part of the order 122 // for each part of the order
123 for (int i = 0; i < 3; i++) { 123 for (int i = 0; i < 3; i++) {
124 // switch on the relavent 3 bits. 124 // switch on the relavent 3 bits.
125 switch((_shortOrder >> (i * 3)) & 0x0007) { 125 switch((_shortOrder >> (i * 3)) & 0x0007) {
126 case 0x0001: 126 case 0x0001:
127 if (pad==2) buf += QString().sprintf("%02d",d.day()); 127 if (pad==2) buf += QString().sprintf("%02d",d.day());
128 else buf += QString().sprintf("%d",d.day()); 128 else buf += QString().sprintf("%d",d.day());
129 break; 129 break;
130 case 0x0002: 130 case 0x0002:
131 if (i==0) { // no padding with only MM/DD/YY format 131 if (i==0) { // no padding with only MM/DD/YY format
132 pad=0; 132 pad=0;
133 } 133 }
134 if (pad==2) buf += QString().sprintf("%02d",d.month()); 134 if (pad==2) buf += QString().sprintf("%02d",d.month());
135 else buf += QString().sprintf("%d",d.month()); 135 else buf += QString().sprintf("%d",d.month());
136 break; 136 break;
137 case 0x0004: 137 case 0x0004:
138 { 138 {
139 int year = d.year(); 139 int year = d.year();
140 if (!(v & longNumber)) 140 if (!(v & longNumber))
141 year = year % 100; 141 year = year % 100;
142 buf += QString().sprintf("%02d",year); 142 buf += QString().sprintf("%02d",year);
143 } 143 }
144 break; 144 break;
145 } 145 }
146 if (i < 2) 146 if (i < 2)
147 buf += _shortSeparator; 147 buf += _shortSeparator;
148 } 148 }
149 return buf; 149 return buf;
150} 150}
151 151
152QString DateFormat::wordDate(const QDate &d, int v) const 152QString DateFormat::wordDate(const QDate &d, int v) const
153{ 153{
154 QString buf = ""; 154 QString buf = "";
155 // for each part of the order 155 // for each part of the order
156 if (v & showWeekDay) { 156 if (v & showWeekDay) {
157 QString weekDay = d.dayName(d.dayOfWeek()); 157 QString weekDay = d.dayName(d.dayOfWeek());
158 if (!(v & longWord)) { 158 if (!(v & longWord)) {
159 weekDay = weekDay.left(3); 159 weekDay = weekDay.left(3);
160 } 160 }
161 buf += weekDay; 161 buf += weekDay;
162 if ((_longOrder & 0x0007) == 0x0002) 162 if ((_longOrder & 0x0007) == 0x0002)
163 buf += ' '; 163 buf += ' ';
164 else 164 else
165 buf += ", "; 165 buf += ", ";
166 } 166 }
167 167
168 for (int i = 0; i < 3; i++) { 168 for (int i = 0; i < 3; i++) {
169 // switch on the relavent 3 bits. 169 // switch on the relavent 3 bits.
170 switch((_longOrder >> (i * 3)) & 0x0007) { 170 switch((_longOrder >> (i * 3)) & 0x0007) {
171 case 0x0001: 171 case 0x0001:
172 if (i==1) { 172 if (i==1) {
173 buf += QString().sprintf("%02d, ",d.day()); 173 buf += QString().sprintf("%02d, ",d.day());
174 } else { 174 } else {
175 buf += QString().sprintf("%2d",d.day()); 175 buf += QString().sprintf("%2d",d.day());
176 if (separator()=='.') // 2002/1/11 176 if (separator()=='.') // 2002/1/11
177 buf += ". "; 177 buf += ". ";
178 else 178 else
179 buf += " "; 179 buf += " ";
180 } 180 }
181 break; 181 break;
182 case 0x0002: 182 case 0x0002:
183 { 183 {
184 QString monthName = d.monthName(d.month()); 184 QString monthName = d.monthName(d.month());
185 if (!(v & longWord)) { 185 if (!(v & longWord)) {
186 monthName = monthName.left(3); 186 monthName = monthName.left(3);
187 } 187 }
188 buf += monthName; 188 buf += monthName;
189 } 189 }
190 if (i < 2) 190 if (i < 2)
191 buf += " "; 191 buf += " ";
192 break; 192 break;
193 case 0x0004: 193 case 0x0004:
194 { 194 {
195 int year = d.year(); 195 int year = d.year();
196 if (!(v & longNumber)) 196 if (!(v & longNumber))
197 year = year % 100; 197 year = year % 100;
198 198
199 if (year < 10) 199 if (year < 10)
200 buf += "0"; 200 buf += "0";
201 201
202 buf += QString::number(year); 202 buf += QString::number(year);
203 } 203 }
204 if (i < 2) 204 if (i < 2)
205 buf += ", "; 205 buf += ", ";
206 break; 206 break;
207 } 207 }
208 } 208 }
209 return buf; 209 return buf;
210} 210}
211 211
212#ifndef QT_NO_DATASTREAM 212#ifndef QT_NO_DATASTREAM
213void DateFormat::save(QDataStream &d) const 213void DateFormat::save(QDataStream &d) const
214{ 214{
215 d << _shortSeparator.unicode(); 215 d << _shortSeparator.unicode();
216 uint v= _shortOrder; 216 uint v= _shortOrder;
217 d << v; 217 d << v;
218 v = _longOrder; 218 v = _longOrder;
219 d << v; 219 d << v;
220} 220}
221 221
222void DateFormat::load(QDataStream &d) 222void DateFormat::load(QDataStream &d)
223{ 223{
224 ushort value; 224 ushort value;
225 d >> value; 225 d >> value;
226 _shortSeparator = QChar(value); 226 _shortSeparator = QChar(value);
227 uint v = 0; 227 uint v = 0;
228 d >> v; 228 d >> v;
229 _shortOrder = (Order)v; 229 _shortOrder = (Order)v;
230 v = 0; 230 v = 0;
231 d >> v; 231 d >> v;
232 _longOrder = (Order)v; 232 _longOrder = (Order)v;
233} 233}
234 234
235QDataStream &operator<<(QDataStream &s, const DateFormat&df) 235QDataStream &operator<<(QDataStream &s, const DateFormat&df)
236{ 236{
237 df.save(s); 237 df.save(s);
238 return s; 238 return s;
239} 239}
240QDataStream &operator>>(QDataStream &s, DateFormat&df) 240QDataStream &operator>>(QDataStream &s, DateFormat&df)
241{ 241{
242 df.load(s); 242 df.load(s);
243 return s; 243 return s;
244} 244}
245#endif 245#endif
246 246
247QString TimeString::shortDate( const QDate &d, DateFormat dtf ) 247QString TimeString::shortDate( const QDate &d, DateFormat dtf )
248{ 248{
249 return dtf.wordDate(d); 249 return dtf.wordDate(d);
250} 250}
251 251
252QString TimeString::dateString( const QDate &d, DateFormat dtf ) 252QString TimeString::dateString( const QDate &d, DateFormat dtf )
253{ 253{
254 return QObject::tr( dtf.wordDate(d, DateFormat::longNumber | DateFormat::longWord) ); 254 return QObject::tr( dtf.wordDate(d, DateFormat::longNumber | DateFormat::longWord) );
255} 255}
256 256
257 257
258QString TimeString::longDateString( const QDate &d, DateFormat dtf ) 258QString TimeString::longDateString( const QDate &d, DateFormat dtf )
259{ 259{
260 return QObject::tr( dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber 260 return QObject::tr( dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber
261 | DateFormat::longWord) ); 261 | DateFormat::longWord) );
262} 262}
263 263
264DateFormat TimeString::currentDateFormat() 264DateFormat TimeString::currentDateFormat()
265{ 265{
266 return TimeStringFormatKeeper::currentFormat(); 266 return TimeStringFormatKeeper::currentFormat();
267} 267}
268 268
269 269
270QString TimeString::dateString( const QDateTime &dt, bool ampm, bool seconds, DateFormat dtf ) 270QString TimeString::dateString( const QDateTime &dt, bool ampm, bool seconds, DateFormat dtf )
271{ 271{
272 const QDate& d = dt.date(); 272 const QDate& d = dt.date();
273 const QTime& t = dt.time(); 273 const QTime& t = dt.time();
274 274
275 // based on QDateTime::toString() 275 // based on QDateTime::toString()
276 QString buf = timeString(t,ampm,seconds); 276 QString buf = timeString(t,ampm,seconds);
277 buf += " "; 277 buf += " ";
278 buf += longDateString( d, dtf ); 278 buf += longDateString( d, dtf );
279 279
280 return buf; 280 return buf;
281} 281}
282 282
283QString TimeString::timeString( const QTime &t, bool ampm, bool seconds ) 283QString TimeString::timeString( const QTime &t, bool ampm, bool seconds )
284{ 284{
285 if ( !ampm ) { 285 if ( !ampm ) {
286 if ( seconds ) 286 if ( seconds )
287 return t.toString(); 287 return t.toString();
288 QString r = QString::number(t.hour()); 288 QString r = QString::number(t.hour());
289 if ( t.hour() < 10 ) r.prepend( "0" ); 289 if ( t.hour() < 10 ) r.prepend( "0" );
290 r.append( ":" ); 290 r.append( ":" );
291 if ( t.minute() < 10 ) r.append( "0" ); 291 if ( t.minute() < 10 ) r.append( "0" );
292 r.append(QString::number(t.minute())); 292 r.append(QString::number(t.minute()));
293 return r; 293 return r;
294 } 294 }
295 // ### else the hard case that should disappear in Qt 3.0 295 // ### else the hard case that should disappear in Qt 3.0
296 QString argString = seconds ? "%4:%5:%6 %7" : "%4:%5 %7"; 296 QString argString = seconds ? "%4:%5:%6 %7" : "%4:%5 %7";
297 int hour = t.hour(); 297 int hour = t.hour();
298 QString strMin = QString::number( t.minute() ); 298 QString strMin = QString::number( t.minute() );
299 QString strSec = QString::number( t.second() ); 299 QString strSec = QString::number( t.second() );
300 if ( hour > 12 ) 300 if ( hour > 12 )
301 argString = argString.arg( hour - 12, 2 ); 301 argString = argString.arg( hour - 12, 2 );
302 else { 302 else {
303 if ( hour == 0 ) 303 if ( hour == 0 )
304 argString = argString.arg( 12 ); 304 argString = argString.arg( 12 );
305 else 305 else
306 argString = argString.arg( hour, 2 ); 306 argString = argString.arg( hour, 2 );
307 } 307 }
308 if ( t.minute() < 10 ) 308 if ( t.minute() < 10 )
309 strMin.prepend( "0" ); 309 strMin.prepend( "0" );
310 if ( t.second() < 10 ) 310 if ( t.second() < 10 )
311 strSec.prepend( "0" ); 311 strSec.prepend( "0" );
312 argString = argString.arg( strMin ); 312 argString = argString.arg( strMin );
313 if ( seconds ) 313 if ( seconds )
314 argString = argString.arg( strSec ); 314 argString = argString.arg( strSec );
315 if ( hour >= 12 ) 315 if ( hour >= 12 )
316 argString = argString.arg( QObject::tr("PM") ); 316 argString = argString.arg( QObject::tr("PM") );
317 else 317 else
318 argString = argString.arg( QObject::tr("AM") ); 318 argString = argString.arg( QObject::tr("AM") );
319 return argString; 319 return argString;
320} 320}
321 321
322QString TimeString::shortTime( bool ampm, bool seconds ) 322QString TimeString::shortTime( bool ampm, bool seconds )
323{ 323{
324 static const char* const day[] = { 324 static const char* const day[] = {
325 QT_TRANSLATE_NOOP( "QObject", "Mon" ), 325 QT_TRANSLATE_NOOP( "QObject", "Mon" ),
326 QT_TRANSLATE_NOOP( "QObject", "Tue" ), 326 QT_TRANSLATE_NOOP( "QObject", "Tue" ),
327 QT_TRANSLATE_NOOP( "QObject", "Wed" ), 327 QT_TRANSLATE_NOOP( "QObject", "Wed" ),
328 QT_TRANSLATE_NOOP( "QObject", "Thu" ), 328 QT_TRANSLATE_NOOP( "QObject", "Thu" ),
329 QT_TRANSLATE_NOOP( "QObject", "Fri" ), 329 QT_TRANSLATE_NOOP( "QObject", "Fri" ),
330 QT_TRANSLATE_NOOP( "QObject", "Sat" ), 330 QT_TRANSLATE_NOOP( "QObject", "Sat" ),
331 QT_TRANSLATE_NOOP( "QObject", "Sun" ) 331 QT_TRANSLATE_NOOP( "QObject", "Sun" )
332 }; 332 };
333 // just create a shorter time String 333 // just create a shorter time String
334 QDateTime dtTmp = QDateTime::currentDateTime(); 334 QDateTime dtTmp = QDateTime::currentDateTime();
335 QString strTime; 335 QString strTime;
336 strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " + 336 strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " +
337 timeString( dtTmp.time(), ampm, seconds ); 337 timeString( dtTmp.time(), ampm, seconds );
338 return strTime; 338 return strTime;
339} 339}
340 340
341QString TimeString::dateString( const QDateTime &t, bool ampm ) 341QString TimeString::dateString( const QDateTime &t, bool ampm )
342{ 342{
343 return dateString(t,ampm,FALSE); 343 return dateString(t,ampm,FALSE);
344} 344}
345 345
346QString TimeString::timeString( const QTime &t, bool ampm) 346QString TimeString::timeString( const QTime &t, bool ampm)
347{ 347{
348 return timeString(t,ampm,FALSE); 348 return timeString(t,ampm,FALSE);
349} 349}
350 350
351QString TimeString::shortTime( bool ampm ) 351QString TimeString::shortTime( bool ampm )
352{ 352{
353 return shortTime(ampm,FALSE); 353 return shortTime(ampm,FALSE);
354} 354}
355 355
356QString TimeString::numberDateString( const QDate &d, DateFormat dtf ) 356QString TimeString::numberDateString( const QDate &d, DateFormat dtf )
357{ 357{
358 return dtf.numberDate(d); 358 return dtf.numberDate(d);
359} 359}
360QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf ) 360QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf )
361{ 361{
362 return dtf.numberDate(d,DateFormat::longNumber); 362 return dtf.numberDate(d,DateFormat::longNumber);
363} 363}
364 364
365#include "timestring.moc" 365#include "timestring.moc"
diff --git a/library/tzselect.cpp b/library/tzselect.cpp
index f28100b..848dfb7 100644
--- a/library/tzselect.cpp
+++ b/library/tzselect.cpp
@@ -1,302 +1,302 @@
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#define QTOPIA_INTERNAL_TZSELECT_INC_LOCAL 21#define QTOPIA_INTERNAL_TZSELECT_INC_LOCAL
22 22
23#include "tzselect.h" 23#include "tzselect.h"
24#include "resource.h" 24#include "resource.h"
25#include "config.h" 25#include "config.h"
26#include <qtoolbutton.h> 26#include <qtoolbutton.h>
27#include <qfile.h> 27#include <qfile.h>
28#include <stdlib.h> 28#include <stdlib.h>
29 29
30#include <qcopchannel_qws.h> 30#include <qcopchannel_qws.h>
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#include <qmessagebox.h> 32#include <qmessagebox.h>
33 33
34/*! 34/*!
35 \class TimeZoneSelector 35 \class TimeZoneSelector
36 36
37 \brief The TimeZoneSelector widget allows users to configure their time zone information. 37 \brief The TimeZoneSelector widget allows users to configure their time zone information.
38 38
39 \ingroup qtopiaemb 39 \ingroup qtopiaemb
40*/ 40*/
41 41
42class TimeZoneSelectorPrivate 42class TimeZoneSelectorPrivate
43{ 43{
44public: 44public:
45 TimeZoneSelectorPrivate() : includeLocal(FALSE) {} 45 TimeZoneSelectorPrivate() : includeLocal(FALSE) {}
46 bool includeLocal; 46 bool includeLocal;
47}; 47};
48 48
49TZCombo::TZCombo( QWidget *p, const char* n ) 49TZCombo::TZCombo( QWidget *p, const char* n )
50 : QComboBox( p, n ) 50 : QComboBox( p, n )
51{ 51{
52 updateZones(); 52 updateZones();
53 // check to see if TZ is set, if it is set the current item to that 53 // check to see if TZ is set, if it is set the current item to that
54 QString tz = getenv("TZ"); 54 QString tz = getenv("TZ");
55 if (parent()->inherits("TimeZoneSelector")) { 55 if (parent()->inherits("TimeZoneSelector")) {
56 if ( ((TimeZoneSelector *)parent())->localIncluded() ) { 56 if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
57 // overide to the 'local' type. 57 // overide to the 'local' type.
58 tz = "None"; 58 tz = "None";
59 } 59 }
60 } 60 }
61 if ( !tz.isNull() ) { 61 if ( !tz.isNull() ) {
62 int n = 0, 62 int n = 0,
63 index = 0; 63 index = 0;
64 for ( QStringList::Iterator it=identifiers.begin(); 64 for ( QStringList::Iterator it=identifiers.begin();
65 it!=identifiers.end(); ++it) { 65 it!=identifiers.end(); ++it) {
66 if ( *it == tz ) 66 if ( *it == tz )
67 index = n; 67 index = n;
68 n++; 68 n++;
69 } 69 }
70 setCurrentItem(index); 70 setCurrentItem(index);
71 } else { 71 } else {
72 setCurrentItem(0); 72 setCurrentItem(0);
73 } 73 }
74 74
75 75
76 76
77 // listen on QPE/System 77 // listen on QPE/System
78#if !defined(QT_NO_COP) 78#if !defined(QT_NO_COP)
79 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 79 QCopChannel *channel = new QCopChannel( "QPE/System", this );
80 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 80 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
81 this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) ); 81 this, SLOT(handleSystemChannel(const QCString&,const QByteArray&)) );
82#endif 82#endif
83 83
84 84
85} 85}
86 86
87TZCombo::~TZCombo() 87TZCombo::~TZCombo()
88{ 88{
89} 89}
90 90
91void TZCombo::updateZones() 91void TZCombo::updateZones()
92{ 92{
93 QString cur = currentText(); 93 QString cur = currentText();
94 clear(); 94 clear();
95 identifiers.clear(); 95 identifiers.clear();
96 int curix=0; 96 int curix=0;
97 QString tz = getenv("TZ"); 97 QString tz = getenv("TZ");
98 bool tzFound = FALSE; 98 bool tzFound = FALSE;
99 Config cfg("CityTime"); 99 Config cfg("CityTime");
100 cfg.setGroup("TimeZones"); 100 cfg.setGroup("TimeZones");
101 int listIndex = 0; 101 int listIndex = 0;
102 if (parent()->inherits("TimeZoneSelector")) { 102 if (parent()->inherits("TimeZoneSelector")) {
103 if ( ((TimeZoneSelector *)parent())->localIncluded() ) { 103 if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
104 // overide to the 'local' type. 104 // overide to the 'local' type.
105 identifiers.append( "None" ); 105 identifiers.append( "None" );
106 insertItem( tr("None") ); 106 insertItem( tr("None") );
107 if ( cur == tr("None")) 107 if ( cur == tr("None"))
108 curix = 0; 108 curix = 0;
109 listIndex++; 109 listIndex++;
110 } 110 }
111 } 111 }
112 int cfgIndex = 0; 112 int cfgIndex = 0;
113 while (1) { 113 while (1) {
114 QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null); 114 QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null);
115 if ( zn.isNull() ) 115 if ( zn.isNull() )
116 break; 116 break;
117 if ( zn == tz ) 117 if ( zn == tz )
118 tzFound = TRUE; 118 tzFound = TRUE;
119 QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex)); 119 QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex));
120 identifiers.append(zn); 120 identifiers.append(zn);
121 insertItem(nm); 121 insertItem(nm);
122 if ( nm == cur ) 122 if ( nm == cur )
123 curix = listIndex; 123 curix = listIndex;
124 ++cfgIndex; 124 ++cfgIndex;
125 ++listIndex; 125 ++listIndex;
126 } 126 }
127 if ( !listIndex ) { 127 if ( !listIndex ) {
128 QStringList list = timezoneDefaults(); 128 QStringList list = timezoneDefaults();
129 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) { 129 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) {
130 QString zn = *it; 130 QString zn = *it;
131 QString nm = *++it; 131 QString nm = *++it;
132 if ( zn == tz ) 132 if ( zn == tz )
133 tzFound = TRUE; 133 tzFound = TRUE;
134 if ( nm == cur ) 134 if ( nm == cur )
135 curix = listIndex; 135 curix = listIndex;
136 identifiers.append(zn); 136 identifiers.append(zn);
137 insertItem(nm); 137 insertItem(nm);
138 ++listIndex; 138 ++listIndex;
139 } 139 }
140 } 140 }
141 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) { 141 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) {
142 insertItem(*it); 142 insertItem(*it);
143 identifiers.append(*it); 143 identifiers.append(*it);
144 if ( *it == cur ) 144 if ( *it == cur )
145 curix = listIndex; 145 curix = listIndex;
146 ++listIndex; 146 ++listIndex;
147 } 147 }
148 if ( !tzFound && !tz.isEmpty()) { 148 if ( !tzFound && !tz.isEmpty()) {
149 int i = tz.find( '/' ); 149 int i = tz.find( '/' );
150 QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " "); 150 QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " ");
151 identifiers.append(tz); 151 identifiers.append(tz);
152 insertItem(nm); 152 insertItem(nm);
153 if ( nm == cur ) 153 if ( nm == cur )
154 curix = listIndex; 154 curix = listIndex;
155 ++listIndex; 155 ++listIndex;
156 } 156 }
157 setCurrentItem(curix); 157 setCurrentItem(curix);
158} 158}
159 159
160 160
161void TZCombo::keyPressEvent( QKeyEvent *e ) 161void TZCombo::keyPressEvent( QKeyEvent *e )
162{ 162{
163 // ### should popup() in Qt 3.0 (it's virtual there) 163 // ### should popup() in Qt 3.0 (it's virtual there)
164// updateZones(); 164// updateZones();
165 QComboBox::keyPressEvent(e); 165 QComboBox::keyPressEvent(e);
166} 166}
167 167
168void TZCombo::mousePressEvent(QMouseEvent*e) 168void TZCombo::mousePressEvent(QMouseEvent*e)
169{ 169{
170 // ### should popup() in Qt 3.0 (it's virtual there) 170 // ### should popup() in Qt 3.0 (it's virtual there)
171// updateZones(); 171// updateZones();
172 QComboBox::mousePressEvent(e); 172 QComboBox::mousePressEvent(e);
173} 173}
174 174
175QString TZCombo::currZone() const 175QString TZCombo::currZone() const
176{ 176{
177 return identifiers[currentItem()]; 177 return identifiers[currentItem()];
178} 178}
179 179
180void TZCombo::setCurrZone( const QString& id ) 180void TZCombo::setCurrZone( const QString& id )
181{ 181{
182 for (int i=0; i< count(); i++) { 182 for (int i=0; i< count(); i++) {
183 if ( identifiers[i] == id ) { 183 if ( identifiers[i] == id ) {
184 setCurrentItem(i); 184 setCurrentItem(i);
185 return; 185 return;
186} 186}
187 } 187 }
188 insertItem(id); 188 insertItem(id);
189 setCurrentItem( count() - 1); 189 setCurrentItem( count() - 1);
190 identifiers.append(id); 190 identifiers.append(id);
191 extras.append(id); 191 extras.append(id);
192} 192}
193 193
194 194
195 195
196void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&) 196void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&)
197{ 197{
198 if ( msg == "timeZoneListChange()" ) { 198 if ( msg == "timeZoneListChange()" ) {
199 updateZones(); 199 updateZones();
200 } 200 }
201} 201}
202 202
203/*! 203/*!
204 Creates a new TimeZoneSelector with parent \a p and name \a n. The combobox will be 204 Creates a new TimeZoneSelector with parent \a p and name \a n. The combobox will be
205 populated with the available timezones. 205 populated with the available timezones.
206*/ 206*/
207 207
208TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) : 208TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) :
209 QHBox(p,n) 209 QHBox(p,n)
210{ 210{
211 d = new TimeZoneSelectorPrivate(); 211 d = new TimeZoneSelectorPrivate();
212 // build the combobox before we do any updates... 212 // build the combobox before we do any updates...
213 cmbTz = new TZCombo( this, "timezone combo" ); 213 cmbTz = new TZCombo( this, "timezone combo" );
214 214
215 cmdTz = new QToolButton( this, "timezone button" ); 215 cmdTz = new QToolButton( this, "timezone button" );
216 cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) ); 216 cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) );
217 cmdTz->setMaximumSize( cmdTz->sizeHint() ); 217 cmdTz->setMaximumSize( cmdTz->sizeHint() );
218 218
219 // set up a connection to catch a newly selected item and throw our 219 // set up a connection to catch a newly selected item and throw our
220 // signal 220 // signal
221 QObject::connect( cmbTz, SIGNAL( activated( int ) ), 221 QObject::connect( cmbTz, SIGNAL( activated(int) ),
222 this, SLOT( slotTzActive( int ) ) ); 222 this, SLOT( slotTzActive(int) ) );
223 QObject::connect( cmdTz, SIGNAL( clicked() ), 223 QObject::connect( cmdTz, SIGNAL( clicked() ),
224 this, SLOT( slotExecute() ) ); 224 this, SLOT( slotExecute() ) );
225} 225}
226 226
227/*! 227/*!
228 Destroys a TimeZoneSelector. 228 Destroys a TimeZoneSelector.
229*/ 229*/
230TimeZoneSelector::~TimeZoneSelector() 230TimeZoneSelector::~TimeZoneSelector()
231{ 231{
232} 232}
233 233
234void TimeZoneSelector::setLocalIncluded(bool b) 234void TimeZoneSelector::setLocalIncluded(bool b)
235{ 235{
236 d->includeLocal = b; 236 d->includeLocal = b;
237 cmbTz->updateZones(); 237 cmbTz->updateZones();
238} 238}
239 239
240bool TimeZoneSelector::localIncluded() const 240bool TimeZoneSelector::localIncluded() const
241{ 241{
242 return d->includeLocal; 242 return d->includeLocal;
243} 243}
244 244
245/*! 245/*!
246 Returns the currently selected timezone as a string in location format, e.g. 246 Returns the currently selected timezone as a string in location format, e.g.
247 \code Australia/Brisbane \endcode 247 \code Australia/Brisbane \endcode
248*/ 248*/
249QString TimeZoneSelector::currentZone() const 249QString TimeZoneSelector::currentZone() const
250{ 250{
251 return cmbTz->currZone(); 251 return cmbTz->currZone();
252} 252}
253 253
254/*! 254/*!
255 Sets the current timezone to \a id. 255 Sets the current timezone to \a id.
256*/ 256*/
257void TimeZoneSelector::setCurrentZone( const QString& id ) 257void TimeZoneSelector::setCurrentZone( const QString& id )
258{ 258{
259 cmbTz->setCurrZone( id ); 259 cmbTz->setCurrZone( id );
260} 260}
261/*! \fn void TimeZoneSelector::signalNewTz( const QString& id ) 261/*! \fn void TimeZoneSelector::signalNewTz( const QString& id )
262 This signal is emitted when a timezone has been selected by the user. The id 262 This signal is emitted when a timezone has been selected by the user. The id
263 is a \l QString in location format, eg \code Australia/Brisbane \endcode 263 is a \l QString in location format, eg \code Australia/Brisbane \endcode
264*/ 264*/
265 265
266 266
267void TimeZoneSelector::slotTzActive( int ) 267void TimeZoneSelector::slotTzActive( int )
268{ 268{
269 emit signalNewTz( cmbTz->currZone() ); 269 emit signalNewTz( cmbTz->currZone() );
270} 270}
271 271
272void TimeZoneSelector::slotExecute( void ) 272void TimeZoneSelector::slotExecute( void )
273{ 273{
274 // execute the world time application... 274 // execute the world time application...
275 if (QFile::exists(QPEApplication::qpeDir()+"bin/citytime")) 275 if (QFile::exists(QPEApplication::qpeDir()+"bin/citytime"))
276 Global::execute( "citytime" ); 276 Global::execute( "citytime" );
277 else 277 else
278 QMessageBox::warning(this,tr("citytime executable not found"), 278 QMessageBox::warning(this,tr("citytime executable not found"),
279 tr("In order to choose the time zones,\nplease install citytime.")); 279 tr("In order to choose the time zones,\nplease install citytime."));
280} 280}
281 281
282QStringList timezoneDefaults( void ) 282QStringList timezoneDefaults( void )
283{ 283{
284 QStringList tzs; 284 QStringList tzs;
285 // load up the list just like the file format (citytime.cpp) 285 // load up the list just like the file format (citytime.cpp)
286 tzs.append( "America/New_York" ); 286 tzs.append( "America/New_York" );
287 tzs.append( "New York" ); 287 tzs.append( "New York" );
288 tzs.append( "America/Los_Angeles" ); 288 tzs.append( "America/Los_Angeles" );
289 tzs.append( "Los Angeles" ); 289 tzs.append( "Los Angeles" );
290 tzs.append( "Australia/Brisbane" ); 290 tzs.append( "Australia/Brisbane" );
291 tzs.append( "Brisbane" ); 291 tzs.append( "Brisbane" );
292 tzs.append( "Europe/Berlin" ); 292 tzs.append( "Europe/Berlin" );
293 tzs.append( "Berlin" ); 293 tzs.append( "Berlin" );
294 tzs.append( "Asia/Tokyo" ); 294 tzs.append( "Asia/Tokyo" );
295 tzs.append( "Tokyo" ); 295 tzs.append( "Tokyo" );
296 tzs.append( "America/Denver" ); 296 tzs.append( "America/Denver" );
297 tzs.append( "Denver" ); 297 tzs.append( "Denver" );
298 298
299 return tzs; 299 return tzs;
300} 300}
301 301
302 302