summaryrefslogtreecommitdiff
path: root/library
Unidiff
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/alarmserver.cpp2
-rw-r--r--library/applnk.cpp4
-rw-r--r--library/fileselector.cpp2
-rw-r--r--library/fontdatabase.cpp2
-rw-r--r--library/fontmanager.cpp2
-rw-r--r--library/global.cpp28
-rw-r--r--library/ir.cpp2
-rw-r--r--library/lnkproperties.cpp2
-rw-r--r--library/network.cpp2
-rw-r--r--library/networkinterface.cpp2
-rw-r--r--library/password.cpp2
-rw-r--r--library/qpedecoration_qws.cpp2
-rw-r--r--library/tzselect.cpp4
13 files changed, 11 insertions, 45 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp
index 177a0cb..02bca3d 100644
--- a/library/alarmserver.cpp
+++ b/library/alarmserver.cpp
@@ -1,403 +1,401 @@
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 <qdir.h> 21#include <qdir.h>
22#include <qfile.h> 22#include <qfile.h>
23#include <qmessagebox.h> 23#include <qmessagebox.h>
24#include <qtextstream.h> 24#include <qtextstream.h>
25 25
26 26
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include "global.h" 28#include "global.h"
29#include "resource.h" 29#include "resource.h"
30 30
31#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
32#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
33#endif
34#include "alarmserver.h" 32#include "alarmserver.h"
35#include <qpe/timeconversion.h> 33#include <qpe/timeconversion.h>
36 34
37#include <sys/types.h> 35#include <sys/types.h>
38#include <sys/stat.h> 36#include <sys/stat.h>
39 37
40#include <stdlib.h> 38#include <stdlib.h>
41#include <unistd.h> 39#include <unistd.h>
42 40
43struct timerEventItem { 41struct timerEventItem {
44 time_t UTCtime; 42 time_t UTCtime;
45 QCString channel, message; 43 QCString channel, message;
46 int data; 44 int data;
47 bool operator==( const timerEventItem &right ) const 45 bool operator==( const timerEventItem &right ) const
48 { 46 {
49 return ( UTCtime == right.UTCtime 47 return ( UTCtime == right.UTCtime
50 && channel == right.channel 48 && channel == right.channel
51 && message == right.message 49 && message == right.message
52 && data == right.data ); 50 && data == right.data );
53 } 51 }
54}; 52};
55 53
56class TimerReceiverObject : public QObject 54class TimerReceiverObject : public QObject
57{ 55{
58public: 56public:
59 TimerReceiverObject() { } 57 TimerReceiverObject() { }
60 ~TimerReceiverObject() { } 58 ~TimerReceiverObject() { }
61 void resetTimer(); 59 void resetTimer();
62 void setTimerEventItem(); 60 void setTimerEventItem();
63 void deleteTimer(); 61 void deleteTimer();
64protected: 62protected:
65 void timerEvent( QTimerEvent *te ); 63 void timerEvent( QTimerEvent *te );
66private: 64private:
67 QString atfilename; 65 QString atfilename;
68}; 66};
69 67
70TimerReceiverObject *timerEventReceiver = NULL; 68TimerReceiverObject *timerEventReceiver = NULL;
71QList<timerEventItem> timerEventList; 69QList<timerEventItem> timerEventList;
72timerEventItem *nearestTimerEvent = NULL; 70timerEventItem *nearestTimerEvent = NULL;
73 71
74 72
75// set the timer to go off on the next event in the list 73// set the timer to go off on the next event in the list
76void setNearestTimerEvent() 74void setNearestTimerEvent()
77{ 75{
78 nearestTimerEvent = NULL; 76 nearestTimerEvent = NULL;
79 QListIterator<timerEventItem> it( timerEventList ); 77 QListIterator<timerEventItem> it( timerEventList );
80 if ( *it ) 78 if ( *it )
81 nearestTimerEvent = *it; 79 nearestTimerEvent = *it;
82 for ( ; *it; ++it ) 80 for ( ; *it; ++it )
83 if ( (*it)->UTCtime < nearestTimerEvent->UTCtime ) 81 if ( (*it)->UTCtime < nearestTimerEvent->UTCtime )
84 nearestTimerEvent = *it; 82 nearestTimerEvent = *it;
85 if (nearestTimerEvent) 83 if (nearestTimerEvent)
86 timerEventReceiver->resetTimer(); 84 timerEventReceiver->resetTimer();
87 else 85 else
88 timerEventReceiver->deleteTimer(); 86 timerEventReceiver->deleteTimer();
89} 87}
90 88
91 89
92//store current state to file 90//store current state to file
93//Simple implementation. Should run on a timer. 91//Simple implementation. Should run on a timer.
94 92
95static void saveState() 93static void saveState()
96{ 94{
97 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); 95 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
98 if ( timerEventList.isEmpty() ) { 96 if ( timerEventList.isEmpty() ) {
99 unlink( savefilename ); 97 unlink( savefilename );
100 return; 98 return;
101 } 99 }
102 100
103 QFile savefile(savefilename+".new"); 101 QFile savefile(savefilename+".new");
104 if ( savefile.open(IO_WriteOnly) ) { 102 if ( savefile.open(IO_WriteOnly) ) {
105 QDataStream ds( &savefile ); 103 QDataStream ds( &savefile );
106 104
107 //save 105 //save
108 106
109 QListIterator<timerEventItem> it( timerEventList ); 107 QListIterator<timerEventItem> it( timerEventList );
110 for ( ; *it; ++it ) { 108 for ( ; *it; ++it ) {
111 ds << it.current()->UTCtime; 109 ds << it.current()->UTCtime;
112 ds << it.current()->channel; 110 ds << it.current()->channel;
113 ds << it.current()->message; 111 ds << it.current()->message;
114 ds << it.current()->data; 112 ds << it.current()->data;
115 } 113 }
116 114
117 115
118 savefile.close(); 116 savefile.close();
119 unlink( savefilename ); 117 unlink( savefilename );
120 QDir d; d.rename(savefilename+".new",savefilename); 118 QDir d; d.rename(savefilename+".new",savefilename);
121 119
122 } 120 }
123} 121}
124 122
125/*! 123/*!
126 Sets up the alarm server. Restoring to previous state (session management). 124 Sets up the alarm server. Restoring to previous state (session management).
127 */ 125 */
128void AlarmServer::initialize() 126void AlarmServer::initialize()
129{ 127{
130 //read autosave file and put events in timerEventList 128 //read autosave file and put events in timerEventList
131 129
132 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); 130 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
133 131
134 QFile savefile(savefilename); 132 QFile savefile(savefilename);
135 if ( savefile.open(IO_ReadOnly) ) { 133 if ( savefile.open(IO_ReadOnly) ) {
136 QDataStream ds( &savefile ); 134 QDataStream ds( &savefile );
137 while ( !ds.atEnd() ) { 135 while ( !ds.atEnd() ) {
138 timerEventItem *newTimerEventItem = new timerEventItem; 136 timerEventItem *newTimerEventItem = new timerEventItem;
139 ds >> newTimerEventItem->UTCtime; 137 ds >> newTimerEventItem->UTCtime;
140 ds >> newTimerEventItem->channel; 138 ds >> newTimerEventItem->channel;
141 ds >> newTimerEventItem->message; 139 ds >> newTimerEventItem->message;
142 ds >> newTimerEventItem->data; 140 ds >> newTimerEventItem->data;
143 timerEventList.append( newTimerEventItem ); 141 timerEventList.append( newTimerEventItem );
144 } 142 }
145 savefile.close(); 143 savefile.close();
146 if (!timerEventReceiver) 144 if (!timerEventReceiver)
147 timerEventReceiver = new TimerReceiverObject; 145 timerEventReceiver = new TimerReceiverObject;
148 setNearestTimerEvent(); 146 setNearestTimerEvent();
149 } 147 }
150} 148}
151 149
152 150
153 151
154 152
155static const char* atdir = "/var/spool/at/"; 153static const char* atdir = "/var/spool/at/";
156 154
157static bool triggerAtd( bool writeHWClock = FALSE ) 155static bool triggerAtd( bool writeHWClock = FALSE )
158{ 156{
159 QFile trigger(QString(atdir) + "trigger"); 157 QFile trigger(QString(atdir) + "trigger");
160 if ( trigger.open(IO_WriteOnly|IO_Raw) ) { 158 if ( trigger.open(IO_WriteOnly|IO_Raw) ) {
161 159
162 const char* data = 160 const char* data =
163#ifdef QT_QWS_CUSTOM 161#ifdef QT_QWS_CUSTOM
164 //custom atd only writes HW Clock if we write a 'W' 162 //custom atd only writes HW Clock if we write a 'W'
165 ( writeHWClock ) ? "W\n" : 163 ( writeHWClock ) ? "W\n" :
166#endif 164#endif
167 data = "\n"; 165 data = "\n";
168 int len = strlen(data); 166 int len = strlen(data);
169 int total_written = trigger.writeBlock(data,len); 167 int total_written = trigger.writeBlock(data,len);
170 if ( total_written != len ) { 168 if ( total_written != len ) {
171 QMessageBox::critical( 0, QObject::tr( "Out of Space" ), 169 QMessageBox::critical( 0, QObject::tr( "Out of Space" ),
172 QObject::tr( "Unable to schedule alarm.\nFree some memory and try again." ) ); 170 QObject::tr( "Unable to schedule alarm.\nFree some memory and try again." ) );
173 trigger.close(); 171 trigger.close();
174 QFile::remove( trigger.name() ); 172 QFile::remove( trigger.name() );
175 return FALSE; 173 return FALSE;
176 } 174 }
177 return TRUE; 175 return TRUE;
178 } 176 }
179 return FALSE; 177 return FALSE;
180} 178}
181 179
182void TimerReceiverObject::deleteTimer() 180void TimerReceiverObject::deleteTimer()
183{ 181{
184 if ( !atfilename.isEmpty() ) { 182 if ( !atfilename.isEmpty() ) {
185 unlink( atfilename ); 183 unlink( atfilename );
186 atfilename = QString::null; 184 atfilename = QString::null;
187 triggerAtd( FALSE ); 185 triggerAtd( FALSE );
188 } 186 }
189} 187}
190 188
191void TimerReceiverObject::resetTimer() 189void TimerReceiverObject::resetTimer()
192{ 190{
193 const int maxsecs = 2147000; 191 const int maxsecs = 2147000;
194 int total_written; 192 int total_written;
195 QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime); 193 QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime);
196 QDateTime now = QDateTime::currentDateTime(); 194 QDateTime now = QDateTime::currentDateTime();
197 if ( nearest < now ) 195 if ( nearest < now )
198 nearest = now; 196 nearest = now;
199 int secs = TimeConversion::secsTo( now, nearest ); 197 int secs = TimeConversion::secsTo( now, nearest );
200 if ( secs > maxsecs ) { 198 if ( secs > maxsecs ) {
201 // too far for millisecond timing 199 // too far for millisecond timing
202 secs = maxsecs; 200 secs = maxsecs;
203 } 201 }
204 202
205 // System timer (needed so that we wake from deep sleep), 203 // System timer (needed so that we wake from deep sleep),
206 // from the Epoch in seconds. 204 // from the Epoch in seconds.
207 // 205 //
208 int at_secs = TimeConversion::toUTC(nearest); 206 int at_secs = TimeConversion::toUTC(nearest);
209 // qDebug("reset timer to %d seconds from Epoch",at_secs); 207 // qDebug("reset timer to %d seconds from Epoch",at_secs);
210 QString fn = atdir + QString::number(at_secs) + "." 208 QString fn = atdir + QString::number(at_secs) + "."
211 + QString::number(getpid()); 209 + QString::number(getpid());
212 if ( fn != atfilename ) { 210 if ( fn != atfilename ) {
213 QFile atfile(fn+".new"); 211 QFile atfile(fn+".new");
214 if ( atfile.open(IO_WriteOnly|IO_Raw) ) { 212 if ( atfile.open(IO_WriteOnly|IO_Raw) ) {
215 // just wake up and delete the at file 213 // just wake up and delete the at file
216 QString cmd = "#!/bin/sh\nrm " + fn; 214 QString cmd = "#!/bin/sh\nrm " + fn;
217 total_written = atfile.writeBlock(cmd.latin1(),cmd.length()); 215 total_written = atfile.writeBlock(cmd.latin1(),cmd.length());
218 if ( total_written != int(cmd.length()) ) { 216 if ( total_written != int(cmd.length()) ) {
219 QMessageBox::critical( 0, tr("Out of Space"), 217 QMessageBox::critical( 0, tr("Out of Space"),
220 tr("Unable to schedule alarm.\n" 218 tr("Unable to schedule alarm.\n"
221 "Please free up space and try again") ); 219 "Please free up space and try again") );
222 atfile.close(); 220 atfile.close();
223 QFile::remove( atfile.name() ); 221 QFile::remove( atfile.name() );
224 return; 222 return;
225 } 223 }
226 atfile.close(); 224 atfile.close();
227 unlink( atfilename ); 225 unlink( atfilename );
228 QDir d; d.rename(fn+".new",fn); 226 QDir d; d.rename(fn+".new",fn);
229 chmod(fn.latin1(),0755); 227 chmod(fn.latin1(),0755);
230 atfilename = fn; 228 atfilename = fn;
231 triggerAtd( FALSE ); 229 triggerAtd( FALSE );
232 } else { 230 } else {
233 qWarning("Cannot open atd file %s",fn.latin1()); 231 qWarning("Cannot open atd file %s",fn.latin1());
234 } 232 }
235 } 233 }
236 // Qt timers (does the actual alarm) 234 // Qt timers (does the actual alarm)
237 // from now in milliseconds 235 // from now in milliseconds
238 // 236 //
239 qDebug("AlarmServer waiting %d seconds",secs); 237 qDebug("AlarmServer waiting %d seconds",secs);
240 startTimer( 1000 * secs + 500 ); 238 startTimer( 1000 * secs + 500 );
241} 239}
242 240
243void TimerReceiverObject::timerEvent( QTimerEvent * ) 241void TimerReceiverObject::timerEvent( QTimerEvent * )
244{ 242{
245 bool needSave = FALSE; 243 bool needSave = FALSE;
246 killTimers(); 244 killTimers();
247 if (nearestTimerEvent) { 245 if (nearestTimerEvent) {
248 if ( nearestTimerEvent->UTCtime 246 if ( nearestTimerEvent->UTCtime
249 <= TimeConversion::toUTC(QDateTime::currentDateTime()) ) { 247 <= TimeConversion::toUTC(QDateTime::currentDateTime()) ) {
250#ifndef QT_NO_COP 248#ifndef QT_NO_COP
251 QCopEnvelope e( nearestTimerEvent->channel, 249 QCopEnvelope e( nearestTimerEvent->channel,
252 nearestTimerEvent->message ); 250 nearestTimerEvent->message );
253 e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime ) 251 e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime )
254 << nearestTimerEvent->data; 252 << nearestTimerEvent->data;
255#endif 253#endif
256 timerEventList.remove( nearestTimerEvent ); 254 timerEventList.remove( nearestTimerEvent );
257 needSave = TRUE; 255 needSave = TRUE;
258 } 256 }
259 setNearestTimerEvent(); 257 setNearestTimerEvent();
260 } else { 258 } else {
261 resetTimer(); 259 resetTimer();
262 } 260 }
263 if ( needSave ) 261 if ( needSave )
264 saveState(); 262 saveState();
265} 263}
266 264
267/*! 265/*!
268 \class AlarmServer alarmserver.h 266 \class AlarmServer alarmserver.h
269 \brief The AlarmServer class allows alarms to be scheduled and unscheduled. 267 \brief The AlarmServer class allows alarms to be scheduled and unscheduled.
270 268
271 Applications can schedule alarms with addAlarm() and can 269 Applications can schedule alarms with addAlarm() and can
272 unschedule alarms with deleteAlarm(). When the time for an alarm 270 unschedule alarms with deleteAlarm(). When the time for an alarm
273 to go off is reached the specified \link qcop.html QCop\endlink 271 to go off is reached the specified \link qcop.html QCop\endlink
274 message is sent on the specified channel (optionally with 272 message is sent on the specified channel (optionally with
275 additional data). 273 additional data).
276 274
277 Scheduling an alarm using this class is important (rather just using 275 Scheduling an alarm using this class is important (rather just using
278 a QTimer) since the machine may be asleep and needs to get woken up using 276 a QTimer) since the machine may be asleep and needs to get woken up using
279 the Linux kernel which implements this at the kernel level to minimize 277 the Linux kernel which implements this at the kernel level to minimize
280 battery usage while asleep. 278 battery usage while asleep.
281 279
282 \ingroup qtopiaemb 280 \ingroup qtopiaemb
283 \sa QCopEnvelope 281 \sa QCopEnvelope
284*/ 282*/
285 283
286/*! 284/*!
287 Schedules an alarm to go off at (or soon after) time \a when. When 285 Schedules an alarm to go off at (or soon after) time \a when. When
288 the alarm goes off, the \link qcop.html QCop\endlink \a message will 286 the alarm goes off, the \link qcop.html QCop\endlink \a message will
289 be sent to \a channel, with \a data as a parameter. 287 be sent to \a channel, with \a data as a parameter.
290 288
291 If this function is called with exactly the same data as a previous 289 If this function is called with exactly the same data as a previous
292 call the subsequent call is ignored, so there is only ever one alarm 290 call the subsequent call is ignored, so there is only ever one alarm
293 with a given set of parameters. 291 with a given set of parameters.
294 292
295 \sa deleteAlarm() 293 \sa deleteAlarm()
296*/ 294*/
297void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, 295void AlarmServer::addAlarm ( QDateTime when, const QCString& channel,
298 const QCString& message, int data) 296 const QCString& message, int data)
299{ 297{
300 if ( qApp->type() == QApplication::GuiServer ) { 298 if ( qApp->type() == QApplication::GuiServer ) {
301 bool needSave = FALSE; 299 bool needSave = FALSE;
302 // Here we are the server so either it has been directly called from 300 // Here we are the server so either it has been directly called from
303 // within the server or it has been sent to us from a client via QCop 301 // within the server or it has been sent to us from a client via QCop
304 if (!timerEventReceiver) 302 if (!timerEventReceiver)
305 timerEventReceiver = new TimerReceiverObject; 303 timerEventReceiver = new TimerReceiverObject;
306 304
307 timerEventItem *newTimerEventItem = new timerEventItem; 305 timerEventItem *newTimerEventItem = new timerEventItem;
308 newTimerEventItem->UTCtime = TimeConversion::toUTC( when ); 306 newTimerEventItem->UTCtime = TimeConversion::toUTC( when );
309 newTimerEventItem->channel = channel; 307 newTimerEventItem->channel = channel;
310 newTimerEventItem->message = message; 308 newTimerEventItem->message = message;
311 newTimerEventItem->data = data; 309 newTimerEventItem->data = data;
312 // explore the case of already having the event in here... 310 // explore the case of already having the event in here...
313 QListIterator<timerEventItem> it( timerEventList ); 311 QListIterator<timerEventItem> it( timerEventList );
314 for ( ; *it; ++it ) 312 for ( ; *it; ++it )
315 if ( *(*it) == *newTimerEventItem ) 313 if ( *(*it) == *newTimerEventItem )
316 return; 314 return;
317 // if we made it here, it is okay to add the item... 315 // if we made it here, it is okay to add the item...
318 timerEventList.append( newTimerEventItem ); 316 timerEventList.append( newTimerEventItem );
319 needSave = TRUE; 317 needSave = TRUE;
320 // quicker than using setNearestTimerEvent() 318 // quicker than using setNearestTimerEvent()
321 if ( nearestTimerEvent ) { 319 if ( nearestTimerEvent ) {
322 if (newTimerEventItem->UTCtime < nearestTimerEvent->UTCtime) { 320 if (newTimerEventItem->UTCtime < nearestTimerEvent->UTCtime) {
323 nearestTimerEvent = newTimerEventItem; 321 nearestTimerEvent = newTimerEventItem;
324 timerEventReceiver->killTimers(); 322 timerEventReceiver->killTimers();
325 timerEventReceiver->resetTimer(); 323 timerEventReceiver->resetTimer();
326 } 324 }
327 } else { 325 } else {
328 nearestTimerEvent = newTimerEventItem; 326 nearestTimerEvent = newTimerEventItem;
329 timerEventReceiver->resetTimer(); 327 timerEventReceiver->resetTimer();
330 } 328 }
331 if ( needSave ) 329 if ( needSave )
332 saveState(); 330 saveState();
333 } else { 331 } else {
334#ifndef QT_NO_COP 332#ifndef QT_NO_COP
335 QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" ); 333 QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" );
336 e << when << channel << message << data; 334 e << when << channel << message << data;
337#endif 335#endif
338 } 336 }
339} 337}
340 338
341/*! 339/*!
342 Deletes previously scheduled alarms which match \a when, \a channel, 340 Deletes previously scheduled alarms which match \a when, \a channel,
343 \a message, and \a data. 341 \a message, and \a data.
344 342
345 Passing null values for \a when, \a channel, or for the \link 343 Passing null values for \a when, \a channel, or for the \link
346 qcop.html QCop\endlink \a message, acts as a wildcard meaning "any". 344 qcop.html QCop\endlink \a message, acts as a wildcard meaning "any".
347 Similarly, passing -1 for \a data indicates "any". 345 Similarly, passing -1 for \a data indicates "any".
348 346
349 If there is no matching alarm, nothing happens. 347 If there is no matching alarm, nothing happens.
350 348
351 \sa addAlarm() 349 \sa addAlarm()
352 350
353*/ 351*/
354void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data) 352void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data)
355{ 353{
356 if ( qApp->type() == QApplication::GuiServer) { 354 if ( qApp->type() == QApplication::GuiServer) {
357 bool needSave = FALSE; 355 bool needSave = FALSE;
358 if ( timerEventReceiver != NULL ) { 356 if ( timerEventReceiver != NULL ) {
359 timerEventReceiver->killTimers(); 357 timerEventReceiver->killTimers();
360 358
361 // iterate over the list of events 359 // iterate over the list of events
362 QListIterator<timerEventItem> it( timerEventList ); 360 QListIterator<timerEventItem> it( timerEventList );
363 time_t deleteTime = TimeConversion::toUTC( when ); 361 time_t deleteTime = TimeConversion::toUTC( when );
364 for ( ; *it; ++it ) { 362 for ( ; *it; ++it ) {
365 // if its a match, delete it 363 // if its a match, delete it
366 if ( ( (*it)->UTCtime == deleteTime || when.isNull() ) 364 if ( ( (*it)->UTCtime == deleteTime || when.isNull() )
367 && ( channel.isNull() || (*it)->channel == channel ) 365 && ( channel.isNull() || (*it)->channel == channel )
368 && ( message.isNull() || (*it)->message == message ) 366 && ( message.isNull() || (*it)->message == message )
369 && ( data==-1 || (*it)->data == data ) ) 367 && ( data==-1 || (*it)->data == data ) )
370 { 368 {
371 // if it's first, then we need to update the timer 369 // if it's first, then we need to update the timer
372 if ( (*it) == nearestTimerEvent ) { 370 if ( (*it) == nearestTimerEvent ) {
373 timerEventList.remove(*it); 371 timerEventList.remove(*it);
374 setNearestTimerEvent(); 372 setNearestTimerEvent();
375 } else { 373 } else {
376 timerEventList.remove(*it); 374 timerEventList.remove(*it);
377 } 375 }
378 needSave = TRUE; 376 needSave = TRUE;
379 } 377 }
380 } 378 }
381 if ( nearestTimerEvent ) 379 if ( nearestTimerEvent )
382 timerEventReceiver->resetTimer(); 380 timerEventReceiver->resetTimer();
383 } 381 }
384 if ( needSave ) 382 if ( needSave )
385 saveState(); 383 saveState();
386 } else { 384 } else {
387#ifndef QT_NO_COP 385#ifndef QT_NO_COP
388 QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" ); 386 QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" );
389 e << when << channel << message << data; 387 e << when << channel << message << data;
390#endif 388#endif
391 } 389 }
392} 390}
393 391
394/*! 392/*!
395 Writes the system clock to the hardware clock. 393 Writes the system clock to the hardware clock.
396*/ 394*/
397void Global::writeHWClock() 395void Global::writeHWClock()
398{ 396{
399 if ( !triggerAtd( TRUE ) ) { 397 if ( !triggerAtd( TRUE ) ) {
400 // atd not running? set it ourselves 398 // atd not running? set it ourselves
401 system("/sbin/hwclock --systohc"); // ##### UTC? 399 system("/sbin/hwclock --systohc"); // ##### UTC?
402 } 400 }
403} 401}
diff --git a/library/applnk.cpp b/library/applnk.cpp
index a56da5d..5763c62 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,1069 +1,1065 @@
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_MIMEEXT 21#define QTOPIA_INTERNAL_MIMEEXT
22#define QTOPIA_INTERNAL_PRELOADACCESS 22#define QTOPIA_INTERNAL_PRELOADACCESS
23#define QTOPIA_INTERNAL_APPLNKASSIGN 23#define QTOPIA_INTERNAL_APPLNKASSIGN
24 24
25#include "applnk.h" 25#include "applnk.h"
26 26
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/categories.h> 28#include <qpe/categories.h>
29#include <qpe/categoryselect.h> 29#include <qpe/categoryselect.h>
30#ifdef QWS
31#include <qpe/qcopenvelope_qws.h> 30#include <qpe/qcopenvelope_qws.h>
32#endif
33#include <qpe/global.h> 31#include <qpe/global.h>
34#include <qpe/mimetype.h> 32#include <qpe/mimetype.h>
35#include <qpe/config.h> 33#include <qpe/config.h>
36#include <qpe/storage.h> 34#include <qpe/storage.h>
37#include <qpe/resource.h> 35#include <qpe/resource.h>
38 36
39#include <qdict.h> 37#include <qdict.h>
40#include <qdir.h> 38#include <qdir.h>
41#include <qregexp.h> 39#include <qregexp.h>
42 40
43#ifdef Q_WS_QWS
44#include <qgfx_qws.h> 41#include <qgfx_qws.h>
45#endif
46 42
47#include <stdlib.h> 43#include <stdlib.h>
48 44
49int AppLnk::lastId = 5000; 45int AppLnk::lastId = 5000;
50 46
51static int smallSize = 14; 47static int smallSize = 14;
52static int bigSize = 32; 48static int bigSize = 32;
53 49
54static QString safeFileName(const QString& n) 50static QString safeFileName(const QString& n)
55{ 51{
56 QString safename=n; 52 QString safename=n;
57 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); 53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
58 safename.replace(QRegExp("^[^A-Za-z]*"),""); 54 safename.replace(QRegExp("^[^A-Za-z]*"),"");
59 if ( safename.isEmpty() ) 55 if ( safename.isEmpty() )
60 safename = "_"; 56 safename = "_";
61 return safename; 57 return safename;
62} 58}
63 59
64static bool prepareDirectories(const QString& lf) 60static bool prepareDirectories(const QString& lf)
65{ 61{
66 if ( !QFile::exists(lf) ) { 62 if ( !QFile::exists(lf) ) {
67 // May need to create directories 63 // May need to create directories
68 QFileInfo fi(lf); 64 QFileInfo fi(lf);
69 if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) 65 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
70 return FALSE; 66 return FALSE;
71 } 67 }
72 return TRUE; 68 return TRUE;
73} 69}
74 70
75class AppLnkPrivate 71class AppLnkPrivate
76{ 72{
77public: 73public:
78 /* the size of the Pixmap */ 74 /* the size of the Pixmap */
79 enum Size {Normal = 0, Big }; 75 enum Size {Normal = 0, Big };
80 AppLnkPrivate() { 76 AppLnkPrivate() {
81 /* we want one normal and one big item */ 77 /* we want one normal and one big item */
82 78
83 QPixmap pix; 79 QPixmap pix;
84 mPixmaps.insert(0, pix ); 80 mPixmaps.insert(0, pix );
85 mPixmaps.insert(1, pix); 81 mPixmaps.insert(1, pix);
86 } 82 }
87 83
88 QStringList mCatList; // always correct 84 QStringList mCatList; // always correct
89 QArray<int> mCat; // cached value; correct if not empty 85 QArray<int> mCat; // cached value; correct if not empty
90 QMap<int, QPixmap> mPixmaps; 86 QMap<int, QPixmap> mPixmaps;
91 87
92 void updateCatListFromArray() 88 void updateCatListFromArray()
93 { 89 {
94 Categories cat( 0 ); 90 Categories cat( 0 );
95 cat.load( categoryFileName() ); 91 cat.load( categoryFileName() );
96 mCatList = cat.labels("Document View",mCat); 92 mCatList = cat.labels("Document View",mCat);
97 } 93 }
98 94
99 void setCatArrayDirty() 95 void setCatArrayDirty()
100 { 96 {
101 mCat.resize(0); 97 mCat.resize(0);
102 } 98 }
103 99
104 void ensureCatArray() 100 void ensureCatArray()
105 { 101 {
106 if ( mCat.count() > 0 || mCatList.count()==0 ) 102 if ( mCat.count() > 0 || mCatList.count()==0 )
107 return; 103 return;
108 104
109 Categories cat( 0 ); 105 Categories cat( 0 );
110 cat.load( categoryFileName() ); 106 cat.load( categoryFileName() );
111 mCat.resize( mCatList.count() ); 107 mCat.resize( mCatList.count() );
112 int i; 108 int i;
113 QStringList::ConstIterator it; 109 QStringList::ConstIterator it;
114 for ( i = 0, it = mCatList.begin(); it != mCatList.end(); 110 for ( i = 0, it = mCatList.begin(); it != mCatList.end();
115 ++it, i++ ) { 111 ++it, i++ ) {
116 112
117 bool number; 113 bool number;
118 int id = (*it).toInt( &number ); 114 int id = (*it).toInt( &number );
119 if ( !number ) { 115 if ( !number ) {
120 id = cat.id( "Document View", *it ); 116 id = cat.id( "Document View", *it );
121 if ( id == 0 ) 117 if ( id == 0 )
122 id = cat.addCategory( "Document View", *it ); 118 id = cat.addCategory( "Document View", *it );
123 } 119 }
124 mCat[i] = id; 120 mCat[i] = id;
125 } 121 }
126 } 122 }
127}; 123};
128 124
129/*! 125/*!
130 \class AppLnk applnk.h 126 \class AppLnk applnk.h
131 \brief The AppLnk class represents an application available on the system. 127 \brief The AppLnk class represents an application available on the system.
132 128
133 Every Qtopia application \e app has a corresponding \e app.desktop 129 Every Qtopia application \e app has a corresponding \e app.desktop
134 file. When one of these files is read its data is stored as an 130 file. When one of these files is read its data is stored as an
135 AppLnk object. 131 AppLnk object.
136 132
137 The AppLnk class introduces some Qtopia-specific concepts, and 133 The AppLnk class introduces some Qtopia-specific concepts, and
138 provides a variety of functions, as described in the following 134 provides a variety of functions, as described in the following
139 sections. 135 sections.
140 \tableofcontents 136 \tableofcontents
141 137
142 \target Types 138 \target Types
143 \section1 Types 139 \section1 Types
144 140
145 Every AppLnk object has a \e type. For applications, games and 141 Every AppLnk object has a \e type. For applications, games and
146 settings the type is \c Application; for documents the 142 settings the type is \c Application; for documents the
147 type is the document's MIME type. 143 type is the document's MIME type.
148 144
149 \target files-and-links 145 \target files-and-links
150 \section1 Files and Links 146 \section1 Files and Links
151 147
152 When you create an AppLnk (or more likely, a \link doclnk.html 148 When you create an AppLnk (or more likely, a \link doclnk.html
153 DocLnk\endlink), you don't deal directly with filenames in the 149 DocLnk\endlink), you don't deal directly with filenames in the
154 filesystem. Instead you do this: 150 filesystem. Instead you do this:
155 \code 151 \code
156 DocLnk d; 152 DocLnk d;
157 d.setType("text/plain"); 153 d.setType("text/plain");
158 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. 154 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal.
159 \endcode 155 \endcode
160 At this point, the file() and linkFile() are unknown. Normally 156 At this point, the file() and linkFile() are unknown. Normally
161 this is uninteresting, and the names become automatically known, 157 this is uninteresting, and the names become automatically known,
162 and more importantly, becomes reserved, when you ask what they are: 158 and more importantly, becomes reserved, when you ask what they are:
163 159
164 \code 160 \code
165 QString fn = d.file(); 161 QString fn = d.file();
166 \endcode 162 \endcode
167 This invents a filename, and creates the file on disk (an empty 163 This invents a filename, and creates the file on disk (an empty
168 reservation file) to prevent the name being used by another 164 reservation file) to prevent the name being used by another
169 application. 165 application.
170 166
171 In some circumstances, you don't want to create the file if it 167 In some circumstances, you don't want to create the file if it
172 doesn't already exist (e.g. in the Document tab, some of the \link 168 doesn't already exist (e.g. in the Document tab, some of the \link
173 doclnk.html DocLnk\endlink objects represented by icons are 169 doclnk.html DocLnk\endlink objects represented by icons are
174 DocLnk's created just for that view - they don't have 170 DocLnk's created just for that view - they don't have
175 corresponding \c .desktop files. To avoid littering empty 171 corresponding \c .desktop files. To avoid littering empty
176 reservation files around, we check in a few places to see whether 172 reservation files around, we check in a few places to see whether
177 the file really needs to exist). 173 the file really needs to exist).
178 174
179 \section1 Functionality 175 \section1 Functionality
180 176
181 AppLnk objects are created by calling the constructor with the 177 AppLnk objects are created by calling the constructor with the
182 name of a \e .desktop file. The object can be checked for validity 178 name of a \e .desktop file. The object can be checked for validity
183 using isValid(). 179 using isValid().
184 180
185 The following functions are used to set or retrieve information 181 The following functions are used to set or retrieve information
186 about the application: 182 about the application:
187 \table 183 \table
188 \header \i Get Function \i Set Function \i Short Description 184 \header \i Get Function \i Set Function \i Short Description
189 \row \i \l name() \i \l setName() \i application's name 185 \row \i \l name() \i \l setName() \i application's name
190 \row \i \l pixmap() \i \e none \i application's icon 186 \row \i \l pixmap() \i \e none \i application's icon
191 \row \i \l bigPixmap() \i \e none \i application's large icon 187 \row \i \l bigPixmap() \i \e none \i application's large icon
192 \row \i \e none \i setIcon() \i sets the icon's filename 188 \row \i \e none \i setIcon() \i sets the icon's filename
193 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above 189 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above
194 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees 190 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees
195 \row \i \l comment() \i \l setComment() \i text for the Details dialog 191 \row \i \l comment() \i \l setComment() \i text for the Details dialog
196 \row \i \l exec() \i \l setExec() \i executable's filename 192 \row \i \l exec() \i \l setExec() \i executable's filename
197 \row \i \l file() \i \e none \i document's filename 193 \row \i \l file() \i \e none \i document's filename
198 \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename 194 \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename
199 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit 195 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit
200 \row \i \l categories() \i \l setCategories()\i \e{see the function descriptions} 196 \row \i \l categories() \i \l setCategories()\i \e{see the function descriptions}
201 \row \i \l fileKnown() \i \e none \i see \link 197 \row \i \l fileKnown() \i \e none \i see \link
202#files-and-links Files and Links\endlink above 198#files-and-links Files and Links\endlink above
203 \row \i \l linkFileKnown() \i \e none \i see \link 199 \row \i \l linkFileKnown() \i \e none \i see \link
204#files-and-links Files and Links\endlink above 200#files-and-links Files and Links\endlink above
205 \row \i \l property() \i \l setProperty()\i any AppLnk property 201 \row \i \l property() \i \l setProperty()\i any AppLnk property
206 can be retrieved or set (if writeable) using these 202 can be retrieved or set (if writeable) using these
207 \endtable 203 \endtable
208 204
209 To save an AppLnk to disk use writeLink(). To execute the 205 To save an AppLnk to disk use writeLink(). To execute the
210 application that the AppLnk object refers to, use execute(). 206 application that the AppLnk object refers to, use execute().
211 207
212 AppLnk's can be deleted from disk using removeLinkFile(). To 208 AppLnk's can be deleted from disk using removeLinkFile(). To
213 remove both the link and the application's executable use 209 remove both the link and the application's executable use
214 removeFiles(). 210 removeFiles().
215 211
216 Icon sizes can be globally changed (but only for AppLnk objects 212 Icon sizes can be globally changed (but only for AppLnk objects
217 created after the calls) with setSmallIconSize() and 213 created after the calls) with setSmallIconSize() and
218 setBigIconSize(). 214 setBigIconSize().
219 215
220 \ingroup qtopiaemb 216 \ingroup qtopiaemb
221*/ 217*/
222 218
223/*! 219/*!
224 Sets the size used for small icons to \a small pixels. 220 Sets the size used for small icons to \a small pixels.
225 Only affects AppLnk objects created after the call. 221 Only affects AppLnk objects created after the call.
226 222
227 \sa smallIconSize() setIcon() 223 \sa smallIconSize() setIcon()
228*/ 224*/
229void AppLnk::setSmallIconSize(int small) 225void AppLnk::setSmallIconSize(int small)
230{ 226{
231 smallSize = small; 227 smallSize = small;
232} 228}
233 229
234/*! 230/*!
235 Returns the size used for small icons. 231 Returns the size used for small icons.
236 232
237 \sa setSmallIconSize() setIcon() 233 \sa setSmallIconSize() setIcon()
238*/ 234*/
239int AppLnk::smallIconSize() 235int AppLnk::smallIconSize()
240{ 236{
241 return smallSize; 237 return smallSize;
242} 238}
243 239
244 240
245/*! 241/*!
246 Sets the size used for large icons to \a big pixels. 242 Sets the size used for large icons to \a big pixels.
247 Only affects AppLnk objects created after the call. 243 Only affects AppLnk objects created after the call.
248 244
249 \sa bigIconSize() setIcon() 245 \sa bigIconSize() setIcon()
250*/ 246*/
251void AppLnk::setBigIconSize(int big) 247void AppLnk::setBigIconSize(int big)
252{ 248{
253 bigSize = big; 249 bigSize = big;
254} 250}
255 251
256/*! 252/*!
257 Returns the size used for large icons. 253 Returns the size used for large icons.
258 254
259 \sa setBigIconSize() setIcon() 255 \sa setBigIconSize() setIcon()
260*/ 256*/
261int AppLnk::bigIconSize() 257int AppLnk::bigIconSize()
262{ 258{
263 return bigSize; 259 return bigSize;
264} 260}
265 261
266 262
267/*! 263/*!
268 \fn QString AppLnk::name() const 264 \fn QString AppLnk::name() const
269 265
270 Returns the Name property. This is the user-visible name for the 266 Returns the Name property. This is the user-visible name for the
271 document or application, not the filename. 267 document or application, not the filename.
272 268
273 See \link #files-and-links Files and Links\endlink. 269 See \link #files-and-links Files and Links\endlink.
274 270
275 \sa setName() 271 \sa setName()
276*/ 272*/
277/*! 273/*!
278 \fn QString AppLnk::exec() const 274 \fn QString AppLnk::exec() const
279 275
280 Returns the Exec property. This is the name of the executable 276 Returns the Exec property. This is the name of the executable
281 program associated with the AppLnk. 277 program associated with the AppLnk.
282 278
283 \sa setExec() 279 \sa setExec()
284*/ 280*/
285/*! 281/*!
286 \fn QString AppLnk::rotation() const 282 \fn QString AppLnk::rotation() const
287 283
288 Returns the Rotation property. The value is 0, 90, 180 or 270 284 Returns the Rotation property. The value is 0, 90, 180 or 270
289 degrees. 285 degrees.
290*/ 286*/
291/*! 287/*!
292 \fn QString AppLnk::comment() const 288 \fn QString AppLnk::comment() const
293 289
294 Returns the Comment property. 290 Returns the Comment property.
295 291
296 \sa setComment() 292 \sa setComment()
297*/ 293*/
298/*! 294/*!
299 \fn QStringList AppLnk::mimeTypes() const 295 \fn QStringList AppLnk::mimeTypes() const
300 296
301 Returns the MimeTypes property. This is the list of MIME types 297 Returns the MimeTypes property. This is the list of MIME types
302 that the application can view or edit. 298 that the application can view or edit.
303*/ 299*/
304/*! 300/*!
305 \fn const QArray<int>& AppLnk::categories() const 301 \fn const QArray<int>& AppLnk::categories() const
306 302
307 Returns the Categories property. 303 Returns the Categories property.
308 304
309 See the CategoryWidget for more details. 305 See the CategoryWidget for more details.
310 306
311 \sa setCategories() 307 \sa setCategories()
312*/ 308*/
313 309
314const QArray<int>& AppLnk::categories() const 310const QArray<int>& AppLnk::categories() const
315{ 311{
316 d->ensureCatArray(); 312 d->ensureCatArray();
317 return d->mCat; 313 return d->mCat;
318} 314}
319 315
320/*! 316/*!
321 \fn int AppLnk::id() const 317 \fn int AppLnk::id() const
322 318
323 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, 319 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet,
324 this value is 0, otherwise it is a value that is unique for the 320 this value is 0, otherwise it is a value that is unique for the
325 duration of the current process. 321 duration of the current process.
326 322
327 \sa AppLnkSet::find() 323 \sa AppLnkSet::find()
328*/ 324*/
329 325
330/*! 326/*!
331 \fn bool AppLnk::isValid() const 327 \fn bool AppLnk::isValid() const
332 328
333 Returns TRUE if this AppLnk is valid; otherwise returns FALSE. 329 Returns TRUE if this AppLnk is valid; otherwise returns FALSE.
334*/ 330*/
335 331
336/*! 332/*!
337 Creates an invalid AppLnk. 333 Creates an invalid AppLnk.
338 334
339 \sa isValid() 335 \sa isValid()
340*/ 336*/
341AppLnk::AppLnk() 337AppLnk::AppLnk()
342{ 338{
343 mId = 0; 339 mId = 0;
344 d = new AppLnkPrivate(); 340 d = new AppLnkPrivate();
345} 341}
346 342
347/*! 343/*!
348 Loads \a file (e.g. \e app.desktop) as an AppLnk. 344 Loads \a file (e.g. \e app.desktop) as an AppLnk.
349 345
350 \sa writeLink() 346 \sa writeLink()
351*/ 347*/
352AppLnk::AppLnk( const QString &file ) 348AppLnk::AppLnk( const QString &file )
353{ 349{
354 QStringList sl; 350 QStringList sl;
355 d = new AppLnkPrivate(); 351 d = new AppLnkPrivate();
356 if ( !file.isNull() ) { 352 if ( !file.isNull() ) {
357 Config config( file, Config::File ); 353 Config config( file, Config::File );
358 354
359 if ( config.isValid() ) { 355 if ( config.isValid() ) {
360 config.setGroup( "Desktop Entry" ); 356 config.setGroup( "Desktop Entry" );
361 357
362 mName = config.readEntry( "Name", file ); 358 mName = config.readEntry( "Name", file );
363 mExec = config.readEntry( "Exec" ); 359 mExec = config.readEntry( "Exec" );
364 mType = config.readEntry( "Type", QString::null ); 360 mType = config.readEntry( "Type", QString::null );
365 mIconFile = config.readEntry( "Icon", QString::null ); 361 mIconFile = config.readEntry( "Icon", QString::null );
366 mRotation = config.readEntry( "Rotation", "" ); 362 mRotation = config.readEntry( "Rotation", "" );
367 mComment = config.readEntry( "Comment", QString::null ); 363 mComment = config.readEntry( "Comment", QString::null );
368 // MIME types are case-insensitive. 364 // MIME types are case-insensitive.
369 mMimeTypes = config.readListEntry( "MimeType", ';' ); 365 mMimeTypes = config.readListEntry( "MimeType", ';' );
370 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) 366 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
371 *it = (*it).lower(); 367 *it = (*it).lower();
372 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 368 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
373 mLinkFile = file; 369 mLinkFile = file;
374 mFile = config.readEntry("File", QString::null); 370 mFile = config.readEntry("File", QString::null);
375 if ( !mExec. isEmpty ( )) { 371 if ( !mExec. isEmpty ( )) {
376 mFile = QString::null; 372 mFile = QString::null;
377 } 373 }
378 else if ( mFile[0] != '/' ) { 374 else if ( mFile[0] != '/' ) {
379 int slash = file.findRev('/'); 375 int slash = file.findRev('/');
380 if ( slash >= 0 ) { 376 if ( slash >= 0 ) {
381 mFile = file.left(slash) + '/' + mFile; 377 mFile = file.left(slash) + '/' + mFile;
382 } 378 }
383 } 379 }
384 d->mCatList = config.readListEntry("Categories", ';'); 380 d->mCatList = config.readListEntry("Categories", ';');
385 if ( d->mCatList[0].toInt() < -1 ) { 381 if ( d->mCatList[0].toInt() < -1 ) {
386 // numeric cats in file! convert to text 382 // numeric cats in file! convert to text
387 Categories cat( 0 ); 383 Categories cat( 0 );
388 cat.load( categoryFileName() ); 384 cat.load( categoryFileName() );
389 d->mCat.resize( d->mCatList.count() ); 385 d->mCat.resize( d->mCatList.count() );
390 int i; 386 int i;
391 QStringList::ConstIterator it; 387 QStringList::ConstIterator it;
392 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); 388 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
393 ++it, i++ ) { 389 ++it, i++ ) {
394 bool number; 390 bool number;
395 int id = (*it).toInt( &number ); 391 int id = (*it).toInt( &number );
396 if ( !number ) { 392 if ( !number ) {
397 // convert from text 393 // convert from text
398 id = cat.id( "Document View", *it ); 394 id = cat.id( "Document View", *it );
399 if ( id == 0 ) 395 if ( id == 0 )
400 id = cat.addCategory( "Document View", *it ); 396 id = cat.addCategory( "Document View", *it );
401 } 397 }
402 d->mCat[i] = id; 398 d->mCat[i] = id;
403 } 399 }
404 d->updateCatListFromArray(); 400 d->updateCatListFromArray();
405 } 401 }
406 } 402 }
407 } 403 }
408 mId = 0; 404 mId = 0;
409} 405}
410 406
411AppLnk& AppLnk::operator=(const AppLnk &copy) 407AppLnk& AppLnk::operator=(const AppLnk &copy)
412{ 408{
413 if ( mId ) 409 if ( mId )
414 qWarning("Deleting AppLnk that is in an AppLnkSet"); 410 qWarning("Deleting AppLnk that is in an AppLnkSet");
415 if ( d ) 411 if ( d )
416 delete d; 412 delete d;
417 413
418 414
419 mName = copy.mName; 415 mName = copy.mName;
420 416
421 /* remove for Qtopia 3.0 -zecke */ 417 /* remove for Qtopia 3.0 -zecke */
422 mPixmap = copy.mPixmap; 418 mPixmap = copy.mPixmap;
423 mBigPixmap = copy.mBigPixmap; 419 mBigPixmap = copy.mBigPixmap;
424 420
425 mExec = copy.mExec; 421 mExec = copy.mExec;
426 mType = copy.mType; 422 mType = copy.mType;
427 mRotation = copy.mRotation; 423 mRotation = copy.mRotation;
428 mComment = copy.mComment; 424 mComment = copy.mComment;
429 mFile = copy.mFile; 425 mFile = copy.mFile;
430 mLinkFile = copy.mLinkFile; 426 mLinkFile = copy.mLinkFile;
431 mIconFile = copy.mIconFile; 427 mIconFile = copy.mIconFile;
432 mMimeTypes = copy.mMimeTypes; 428 mMimeTypes = copy.mMimeTypes;
433 mMimeTypeIcons = copy.mMimeTypeIcons; 429 mMimeTypeIcons = copy.mMimeTypeIcons;
434 mId = 0; 430 mId = 0;
435 d = new AppLnkPrivate(); 431 d = new AppLnkPrivate();
436 d->mCat = copy.d->mCat; 432 d->mCat = copy.d->mCat;
437 d->mCatList = copy.d->mCatList; 433 d->mCatList = copy.d->mCatList;
438 d->mPixmaps = copy.d->mPixmaps; 434 d->mPixmaps = copy.d->mPixmaps;
439 435
440 return *this; 436 return *this;
441} 437}
442/*! 438/*!
443 protected internally to share code 439 protected internally to share code
444 should I document that at all? 440 should I document that at all?
445 I don't know the TT style for that 441 I don't know the TT style for that
446*/ 442*/
447const QPixmap& AppLnk::pixmap( int pos, int size ) const { 443const QPixmap& AppLnk::pixmap( int pos, int size ) const {
448 if ( d->mPixmaps[pos].isNull() ) { 444 if ( d->mPixmaps[pos].isNull() ) {
449 AppLnk* that = (AppLnk*)this; 445 AppLnk* that = (AppLnk*)this;
450 if ( mIconFile.isEmpty() ) { 446 if ( mIconFile.isEmpty() ) {
451 MimeType mt(type()); 447 MimeType mt(type());
452 that->d->mPixmaps[pos] = mt.pixmap(); 448 that->d->mPixmaps[pos] = mt.pixmap();
453 if ( that->d->mPixmaps[pos].isNull() ) 449 if ( that->d->mPixmaps[pos].isNull() )
454 that->d->mPixmaps[pos].convertFromImage( 450 that->d->mPixmaps[pos].convertFromImage(
455 Resource::loadImage("UnknownDocument") 451 Resource::loadImage("UnknownDocument")
456 .smoothScale( size, size ) ); 452 .smoothScale( size, size ) );
457 return that->d->mPixmaps[pos]; 453 return that->d->mPixmaps[pos];
458 } 454 }
459 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 455 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
460 if ( unscaledIcon.isNull() ) { 456 if ( unscaledIcon.isNull() ) {
461 qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); 457 qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
462 that->d->mPixmaps[pos].convertFromImage( 458 that->d->mPixmaps[pos].convertFromImage(
463 Resource::loadImage("UnknownDocument") 459 Resource::loadImage("UnknownDocument")
464 .smoothScale( size, size ) ); 460 .smoothScale( size, size ) );
465 } else { 461 } else {
466 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 462 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
467 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 463 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
468 } 464 }
469 return that->d->mPixmaps[pos]; 465 return that->d->mPixmaps[pos];
470 } 466 }
471 return d->mPixmaps[pos]; 467 return d->mPixmaps[pos];
472} 468}
473 469
474/*! 470/*!
475 Returns a small pixmap associated with the application. 471 Returns a small pixmap associated with the application.
476 472
477 \sa bigPixmap() setIcon() 473 \sa bigPixmap() setIcon()
478*/ 474*/
479const QPixmap& AppLnk::pixmap() const 475const QPixmap& AppLnk::pixmap() const
480{ 476{
481 if ( d->mPixmaps[0].isNull() ) { 477 if ( d->mPixmaps[0].isNull() ) {
482 return pixmap(AppLnkPrivate::Normal, smallSize ); 478 return pixmap(AppLnkPrivate::Normal, smallSize );
483 } 479 }
484 return d->mPixmaps[0]; 480 return d->mPixmaps[0];
485} 481}
486 482
487/*! 483/*!
488 Returns a large pixmap associated with the application. 484 Returns a large pixmap associated with the application.
489 485
490 \sa pixmap() setIcon() 486 \sa pixmap() setIcon()
491*/ 487*/
492const QPixmap& AppLnk::bigPixmap() const 488const QPixmap& AppLnk::bigPixmap() const
493{ 489{
494 if ( d->mPixmaps[1].isNull() ) { 490 if ( d->mPixmaps[1].isNull() ) {
495 return pixmap( AppLnkPrivate::Big, bigSize ); 491 return pixmap( AppLnkPrivate::Big, bigSize );
496 } 492 }
497 return d->mPixmaps[1]; 493 return d->mPixmaps[1];
498} 494}
499 495
500/*! 496/*!
501 Returns the type of the AppLnk. For applications, games and 497 Returns the type of the AppLnk. For applications, games and
502 settings the type is \c Application; for documents the type is the 498 settings the type is \c Application; for documents the type is the
503 document's MIME type. 499 document's MIME type.
504*/ 500*/
505QString AppLnk::type() const 501QString AppLnk::type() const
506{ 502{
507 if ( mType.isNull() ) { 503 if ( mType.isNull() ) {
508 AppLnk* that = (AppLnk*)this; 504 AppLnk* that = (AppLnk*)this;
509 QString f = file(); 505 QString f = file();
510 if ( !f.isNull() ) { 506 if ( !f.isNull() ) {
511 MimeType mt(f); 507 MimeType mt(f);
512 that->mType = mt.id(); 508 that->mType = mt.id();
513 return that->mType; 509 return that->mType;
514 } 510 }
515 } 511 }
516 return mType; 512 return mType;
517} 513}
518 514
519/*! 515/*!
520 Returns the file associated with the AppLnk. 516 Returns the file associated with the AppLnk.
521 517
522 \sa exec() name() 518 \sa exec() name()
523*/ 519*/
524QString AppLnk::file() const 520QString AppLnk::file() const
525{ 521{
526 if ( mExec.isEmpty ( ) && mFile.isNull() ) { 522 if ( mExec.isEmpty ( ) && mFile.isNull() ) {
527 AppLnk* that = (AppLnk*)this; 523 AppLnk* that = (AppLnk*)this;
528 QString ext = MimeType(mType).extension(); 524 QString ext = MimeType(mType).extension();
529 if ( !ext.isEmpty() ) 525 if ( !ext.isEmpty() )
530 ext = "." + ext; 526 ext = "." + ext;
531 if ( !mLinkFile.isEmpty() ) { 527 if ( !mLinkFile.isEmpty() ) {
532 that->mFile = 528 that->mFile =
533 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 529 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
534 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; 530 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
535 qDebug("mFile now == %s", mFile.latin1()); 531 qDebug("mFile now == %s", mFile.latin1());
536 } else if ( mType.contains('/') ) { 532 } else if ( mType.contains('/') ) {
537 that->mFile = 533 that->mFile =
538 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 534 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
539 /* 535 /*
540 * A file with the same name or a .desktop file already exists 536 * A file with the same name or a .desktop file already exists
541 */ 537 */
542 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { 538 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {
543 int n=1; 539 int n=1;
544 QString nn; 540 QString nn;
545 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) 541 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
546 || QFile::exists(nn+".desktop")) 542 || QFile::exists(nn+".desktop"))
547 n++; 543 n++;
548 that->mFile = nn; 544 that->mFile = nn;
549 } 545 }
550 that->mLinkFile = that->mFile+".desktop"; 546 that->mLinkFile = that->mFile+".desktop";
551 that->mFile += ext; 547 that->mFile += ext;
552 } 548 }
553 prepareDirectories(that->mFile); 549 prepareDirectories(that->mFile);
554 if ( !that->mFile.isEmpty() ) { 550 if ( !that->mFile.isEmpty() ) {
555 QFile f(that->mFile); 551 QFile f(that->mFile);
556 if ( !f.open(IO_WriteOnly) ) 552 if ( !f.open(IO_WriteOnly) )
557 that->mFile = QString::null; 553 that->mFile = QString::null;
558 return that->mFile; 554 return that->mFile;
559 } 555 }
560 } 556 }
561 return mFile; 557 return mFile;
562} 558}
563 559
564/*! 560/*!
565 Returns the desktop file corresponding to this AppLnk. 561 Returns the desktop file corresponding to this AppLnk.
566 562
567 \sa file() exec() name() 563 \sa file() exec() name()
568*/ 564*/
569QString AppLnk::linkFile() const 565QString AppLnk::linkFile() const
570{ 566{
571 if ( mLinkFile.isNull() ) { 567 if ( mLinkFile.isNull() ) {
572 AppLnk* that = (AppLnk*)this; 568 AppLnk* that = (AppLnk*)this;
573 if ( type().contains('/') ) { 569 if ( type().contains('/') ) {
574 StorageInfo storage; 570 StorageInfo storage;
575 const FileSystem *fs = storage.fileSystemOf( that->mFile ); 571 const FileSystem *fs = storage.fileSystemOf( that->mFile );
576 /* tmpfs + and ramfs are available too but not removable 572 /* tmpfs + and ramfs are available too but not removable
577 * either we fix storage or add this 573 * either we fix storage or add this
578 */ 574 */
579 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { 575 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) {
580 that->mLinkFile = fs->path(); 576 that->mLinkFile = fs->path();
581 } else 577 } else
582 that->mLinkFile = getenv( "HOME" ); 578 that->mLinkFile = getenv( "HOME" );
583 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); 579 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
584 580
585 /* the desktop file exists make sure we don't point to the same file */ 581 /* the desktop file exists make sure we don't point to the same file */
586 if ( QFile::exists(that->mLinkFile+".desktop") ) { 582 if ( QFile::exists(that->mLinkFile+".desktop") ) {
587 AppLnk lnk( that->mLinkFile + ".desktop" ); 583 AppLnk lnk( that->mLinkFile + ".desktop" );
588 584
589 /* the linked is different */ 585 /* the linked is different */
590 if(that->file() != lnk.file() ) { 586 if(that->file() != lnk.file() ) {
591 int n = 1; 587 int n = 1;
592 QString nn; 588 QString nn;
593 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { 589 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) {
594 n++; 590 n++;
595 /* just to be sure */ 591 /* just to be sure */
596 AppLnk lnk(nn ); 592 AppLnk lnk(nn );
597 if (lnk.file() == that->file() ) 593 if (lnk.file() == that->file() )
598 break; 594 break;
599 } 595 }
600 that->mLinkFile = nn; 596 that->mLinkFile = nn;
601 } 597 }
602 } 598 }
603 that->mLinkFile += ".desktop"; 599 that->mLinkFile += ".desktop";
604 storeLink(); 600 storeLink();
605 } 601 }
606 return that->mLinkFile; 602 return that->mLinkFile;
607 } 603 }
608 return mLinkFile; 604 return mLinkFile;
609} 605}
610 606
611/*! 607/*!
612 Copies \a copy. 608 Copies \a copy.
613*/ 609*/
614AppLnk::AppLnk( const AppLnk &copy ) 610AppLnk::AppLnk( const AppLnk &copy )
615{ 611{
616 mName = copy.mName; 612 mName = copy.mName;
617 mPixmap = copy.mPixmap; 613 mPixmap = copy.mPixmap;
618 mBigPixmap = copy.mBigPixmap; 614 mBigPixmap = copy.mBigPixmap;
619 mExec = copy.mExec; 615 mExec = copy.mExec;
620 mType = copy.mType; 616 mType = copy.mType;
621 mRotation = copy.mRotation; 617 mRotation = copy.mRotation;
622 mComment = copy.mComment; 618 mComment = copy.mComment;
623 mFile = copy.mFile; 619 mFile = copy.mFile;
624 mLinkFile = copy.mLinkFile; 620 mLinkFile = copy.mLinkFile;
625 mIconFile = copy.mIconFile; 621 mIconFile = copy.mIconFile;
626 mMimeTypes = copy.mMimeTypes; 622 mMimeTypes = copy.mMimeTypes;
627 mMimeTypeIcons = copy.mMimeTypeIcons; 623 mMimeTypeIcons = copy.mMimeTypeIcons;
628 mId = 0; 624 mId = 0;
629 d = new AppLnkPrivate(); 625 d = new AppLnkPrivate();
630 d->mCat = copy.d->mCat; 626 d->mCat = copy.d->mCat;
631 d->mCatList = copy.d->mCatList; 627 d->mCatList = copy.d->mCatList;
632 d->mPixmaps = copy.d->mPixmaps; 628 d->mPixmaps = copy.d->mPixmaps;
633} 629}
634 630
635/*! 631/*!
636 Destroys the AppLnk. Note that if the AppLnk is currently a member 632 Destroys the AppLnk. Note that if the AppLnk is currently a member
637 of an AppLnkSet, this will produce a run-time warning. 633 of an AppLnkSet, this will produce a run-time warning.
638 634
639 \sa AppLnkSet::add() AppLnkSet::remove() 635 \sa AppLnkSet::add() AppLnkSet::remove()
640*/ 636*/
641AppLnk::~AppLnk() 637AppLnk::~AppLnk()
642{ 638{
643 if ( mId ) 639 if ( mId )
644 qWarning("Deleting AppLnk that is in an AppLnkSet"); 640 qWarning("Deleting AppLnk that is in an AppLnkSet");
645 if ( d ) 641 if ( d )
646 delete d; 642 delete d;
647} 643}
648 644
649/*! 645/*!
650 \overload 646 \overload
651 Executes the application associated with this AppLnk. 647 Executes the application associated with this AppLnk.
652 648
653 \sa exec() 649 \sa exec()
654*/ 650*/
655void AppLnk::execute() const 651void AppLnk::execute() const
656{ 652{
657 execute(QStringList()); 653 execute(QStringList());
658} 654}
659 655
660/*! 656/*!
661 Executes the application associated with this AppLnk, with 657 Executes the application associated with this AppLnk, with
662 \a args as arguments. 658 \a args as arguments.
663 659
664 \sa exec() 660 \sa exec()
665*/ 661*/
666void AppLnk::execute(const QStringList& args) const 662void AppLnk::execute(const QStringList& args) const
667{ 663{
668#ifdef Q_WS_QWS 664#ifdef Q_WS_QWS
669 if ( !mRotation.isEmpty() ) { 665 if ( !mRotation.isEmpty() ) {
670 // ######## this will only work in the server 666 // ######## this will only work in the server
671 int rot = QPEApplication::defaultRotation(); 667 int rot = QPEApplication::defaultRotation();
672 rot = (rot+mRotation.toInt())%360; 668 rot = (rot+mRotation.toInt())%360;
673 QCString old = getenv("QWS_DISPLAY"); 669 QCString old = getenv("QWS_DISPLAY");
674 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 670 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
675 invoke(args); 671 invoke(args);
676 setenv("QWS_DISPLAY", old.data(), 1); 672 setenv("QWS_DISPLAY", old.data(), 1);
677 } else 673 } else
678#endif 674#endif
679 invoke(args); 675 invoke(args);
680} 676}
681 677
682/*! 678/*!
683 Invokes the application associated with this AppLnk, with 679 Invokes the application associated with this AppLnk, with
684 \a args as arguments. Rotation is not taken into account by 680 \a args as arguments. Rotation is not taken into account by
685 this function, so you should not call it directly. 681 this function, so you should not call it directly.
686 682
687 \sa execute() 683 \sa execute()
688*/ 684*/
689void AppLnk::invoke(const QStringList& args) const 685void AppLnk::invoke(const QStringList& args) const
690{ 686{
691 Global::execute( exec(), args[0] ); 687 Global::execute( exec(), args[0] );
692} 688}
693 689
694/*! 690/*!
695 Sets the Exec property to \a exec. 691 Sets the Exec property to \a exec.
696 692
697 \sa exec() name() 693 \sa exec() name()
698*/ 694*/
699void AppLnk::setExec( const QString& exec ) 695void AppLnk::setExec( const QString& exec )
700{ 696{
701 mExec = exec; 697 mExec = exec;
702} 698}
703 699
704#if 0 // this was inlined for better BC 700#if 0 // this was inlined for better BC
705/*! 701/*!
706 Sets the Rotation property to \a rot. 702 Sets the Rotation property to \a rot.
707 703
708 \sa rotation() 704 \sa rotation()
709*/ 705*/
710void AppLnk::setRotation ( const QString &rot ) 706void AppLnk::setRotation ( const QString &rot )
711{ 707{
712 mRotation = rot; 708 mRotation = rot;
713} 709}
714#endif 710#endif
715 711
716/*! 712/*!
717 Sets the Name property to \a docname. 713 Sets the Name property to \a docname.
718 714
719 \sa name() 715 \sa name()
720*/ 716*/
721void AppLnk::setName( const QString& docname ) 717void AppLnk::setName( const QString& docname )
722{ 718{
723 mName = docname; 719 mName = docname;
724} 720}
725 721
726/*! 722/*!
727 Sets the File property to \a filename. 723 Sets the File property to \a filename.
728 724
729 \sa file() name() 725 \sa file() name()
730*/ 726*/
731void AppLnk::setFile( const QString& filename ) 727void AppLnk::setFile( const QString& filename )
732{ 728{
733 mFile = filename; 729 mFile = filename;
734} 730}
735 731
736/*! 732/*!
737 Sets the LinkFile property to \a filename. 733 Sets the LinkFile property to \a filename.
738 734
739 \sa linkFile() 735 \sa linkFile()
740*/ 736*/
741void AppLnk::setLinkFile( const QString& filename ) 737void AppLnk::setLinkFile( const QString& filename )
742{ 738{
743 mLinkFile = filename; 739 mLinkFile = filename;
744} 740}
745 741
746/*! 742/*!
747 Sets the Comment property to \a comment. 743 Sets the Comment property to \a comment.
748 744
749 This text is displayed in the 'Details Dialog', for example if the 745 This text is displayed in the 'Details Dialog', for example if the
750 user uses the 'press-and-hold' gesture. 746 user uses the 'press-and-hold' gesture.
751 747
752 \sa comment() 748 \sa comment()
753*/ 749*/
754void AppLnk::setComment( const QString& comment ) 750void AppLnk::setComment( const QString& comment )
755{ 751{
756 mComment = comment; 752 mComment = comment;
757} 753}
758 754
759/*! 755/*!
760 Sets the Type property to \a type. 756 Sets the Type property to \a type.
761 757
762 For applications, games and settings the type should be \c 758 For applications, games and settings the type should be \c
763 Application; for documents the type should be the document's MIME 759 Application; for documents the type should be the document's MIME
764 type. 760 type.
765 761
766 \sa type() 762 \sa type()
767*/ 763*/
768void AppLnk::setType( const QString& type ) 764void AppLnk::setType( const QString& type )
769{ 765{
770 mType = type; 766 mType = type;
771} 767}
772 768
773/*! 769/*!
774 \fn QString AppLnk::icon() const 770 \fn QString AppLnk::icon() const
775 771
776 Returns the Icon property. 772 Returns the Icon property.
777 773
778 \sa setIcon() 774 \sa setIcon()
779*/ 775*/
780 776
781/*! 777/*!
782 Sets the Icon property to \a iconname. This is the filename from 778 Sets the Icon property to \a iconname. This is the filename from
783 which the pixmap() and bigPixmap() are obtained. 779 which the pixmap() and bigPixmap() are obtained.
784 780
785 \sa icon() setSmallIconSize() setBigIconSize() 781 \sa icon() setSmallIconSize() setBigIconSize()
786*/ 782*/
787void AppLnk::setIcon( const QString& iconname ) 783void AppLnk::setIcon( const QString& iconname )
788{ 784{
789 mIconFile = iconname; 785 mIconFile = iconname;
790 QImage unscaledIcon = Resource::loadImage( mIconFile ); 786 QImage unscaledIcon = Resource::loadImage( mIconFile );
791 d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 787 d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
792 d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 788 d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
793} 789}
794 790
795/*! 791/*!
796 Sets the Categories property to \a c. 792 Sets the Categories property to \a c.
797 793
798 See the CategoryWidget for more details. 794 See the CategoryWidget for more details.
799 795
800 \sa categories() 796 \sa categories()
801*/ 797*/
802void AppLnk::setCategories( const QArray<int>& c ) 798void AppLnk::setCategories( const QArray<int>& c )
803{ 799{
804 d->mCat = c; 800 d->mCat = c;
805 d->updateCatListFromArray(); 801 d->updateCatListFromArray();
806} 802}
807 803
808/*! 804/*!
809 \fn QStringList AppLnk::mimeTypeIcons() const 805 \fn QStringList AppLnk::mimeTypeIcons() const
810 806
811 Returns the MimeTypeIcons property of the AppLnk. 807 Returns the MimeTypeIcons property of the AppLnk.
812*/ 808*/
813 809
814/*! 810/*!
815 Attempts to ensure that the link file for this AppLnk exists, 811 Attempts to ensure that the link file for this AppLnk exists,
816 including creating any required directories. Returns TRUE if 812 including creating any required directories. Returns TRUE if
817 successful; otherwise returns FALSE. 813 successful; otherwise returns FALSE.
818 814
819 You should not need to use this function. 815 You should not need to use this function.
820*/ 816*/
821bool AppLnk::ensureLinkExists() const 817bool AppLnk::ensureLinkExists() const
822{ 818{
823 QString lf = linkFile(); 819 QString lf = linkFile();
824 return prepareDirectories(lf); 820 return prepareDirectories(lf);
825} 821}
826 822
827/*! 823/*!
828 Commits the AppLnk to disk. Returns TRUE if the operation succeeded; 824 Commits the AppLnk to disk. Returns TRUE if the operation succeeded;
829 otherwise returns FALSE. 825 otherwise returns FALSE.
830 826
831 In addition, the "linkChanged(QString)" message is sent to the 827 In addition, the "linkChanged(QString)" message is sent to the
832 "QPE/System" \link qcop.html QCop\endlink channel. 828 "QPE/System" \link qcop.html QCop\endlink channel.
833*/ 829*/
834bool AppLnk::writeLink() const 830bool AppLnk::writeLink() const
835{ 831{
836 // Only re-writes settable parts 832 // Only re-writes settable parts
837 QString lf = linkFile(); 833 QString lf = linkFile();
838 if ( !ensureLinkExists() ) 834 if ( !ensureLinkExists() )
839 return FALSE; 835 return FALSE;
840 storeLink(); 836 storeLink();
841 return TRUE; 837 return TRUE;
842} 838}
843 839
844/*! 840/*!
845 \internal 841 \internal
846*/ 842*/
847void AppLnk::storeLink() const 843void AppLnk::storeLink() const
848{ 844{
849 Config config( mLinkFile, Config::File ); 845 Config config( mLinkFile, Config::File );
850 config.setGroup("Desktop Entry"); 846 config.setGroup("Desktop Entry");
851 config.writeEntry("Name",mName); 847 config.writeEntry("Name",mName);
852 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); 848 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
853 config.writeEntry("Type",type()); 849 config.writeEntry("Type",type());
854 if(!rotation().isEmpty()) 850 if(!rotation().isEmpty())
855 config.writeEntry("Rotation",rotation()); 851 config.writeEntry("Rotation",rotation());
856 else 852 else
857 config.removeEntry("Rotation"); 853 config.removeEntry("Rotation");
858 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); 854 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
859 QString f = file(); 855 QString f = file();
860 int i = 0; 856 int i = 0;
861 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) 857 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )
862 i++; 858 i++;
863 while ( i && f[i] != '/' ) 859 while ( i && f[i] != '/' )
864 i--; 860 i--;
865 // simple case where in the same directory 861 // simple case where in the same directory
866 if ( mLinkFile.find( '/', i + 1 ) < 0 ) 862 if ( mLinkFile.find( '/', i + 1 ) < 0 )
867 f = f.mid(i+1); 863 f = f.mid(i+1);
868 // ### could do relative ie ../../otherDocs/file.doc 864 // ### could do relative ie ../../otherDocs/file.doc
869 config.writeEntry("File",f); 865 config.writeEntry("File",f);
870 config.writeEntry( "Categories", d->mCatList, ';' ); 866 config.writeEntry( "Categories", d->mCatList, ';' );
871 867
872#ifndef QT_NO_COP 868#ifndef QT_NO_COP
873 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 869 QCopEnvelope e("QPE/System", "linkChanged(QString)");
874 e << mLinkFile; 870 e << mLinkFile;
875#endif 871#endif
876} 872}
877 873
878/*! 874/*!
879 Sets the property named \a key to \a value. 875 Sets the property named \a key to \a value.
880 876
881 \sa property() 877 \sa property()
882*/ 878*/
883void AppLnk::setProperty(const QString& key, const QString& value) 879void AppLnk::setProperty(const QString& key, const QString& value)
884{ 880{
885 if ( ensureLinkExists() ) { 881 if ( ensureLinkExists() ) {
886 Config cfg(linkFile(), Config::File); 882 Config cfg(linkFile(), Config::File);
887 cfg.writeEntry(key,value); 883 cfg.writeEntry(key,value);
888 } 884 }
889} 885}
890 886
891/*! 887/*!
892 Returns the property named \a key. 888 Returns the property named \a key.
893 889
894 \sa setProperty() 890 \sa setProperty()
895*/ 891*/
896QString AppLnk::property(const QString& key) const 892QString AppLnk::property(const QString& key) const
897{ 893{
898 QString lf = linkFile(); 894 QString lf = linkFile();
899 if ( !QFile::exists(lf) ) 895 if ( !QFile::exists(lf) )
900 return QString::null; 896 return QString::null;
901 Config cfg(lf, Config::File); 897 Config cfg(lf, Config::File);
902 return cfg.readEntry(key); 898 return cfg.readEntry(key);
903} 899}
904 900
905bool AppLnk::isPreloaded() const { 901bool AppLnk::isPreloaded() const {
906 // Preload information is stored in the Launcher config in v1.5. 902 // Preload information is stored in the Launcher config in v1.5.
907 Config cfg("Launcher"); 903 Config cfg("Launcher");
908 cfg.setGroup("Preload"); 904 cfg.setGroup("Preload");
909 QStringList apps = cfg.readListEntry("Apps",','); 905 QStringList apps = cfg.readListEntry("Apps",',');
910 if (apps.contains(exec())) 906 if (apps.contains(exec()))
911 return true; 907 return true;
912 return false; 908 return false;
913} 909}
914 910
915void AppLnk::setPreloaded(bool yesNo) { 911void AppLnk::setPreloaded(bool yesNo) {
916 // Preload information is stored in the Launcher config in v1.5. 912 // Preload information is stored in the Launcher config in v1.5.
917 Config cfg("Launcher"); 913 Config cfg("Launcher");
918 cfg.setGroup("Preload"); 914 cfg.setGroup("Preload");
919 QStringList apps = cfg.readListEntry("Apps", ','); 915 QStringList apps = cfg.readListEntry("Apps", ',');
920 if (apps.contains(exec()) && !yesNo) 916 if (apps.contains(exec()) && !yesNo)
921 apps.remove(exec()); 917 apps.remove(exec());
922 else if (yesNo && !apps.contains(exec())) 918 else if (yesNo && !apps.contains(exec()))
923 apps.append(exec()); 919 apps.append(exec());
924 cfg.writeEntry("Apps", apps, ','); 920 cfg.writeEntry("Apps", apps, ',');
925} 921}
926 922
927 923
928/*! 924/*!
929 Deletes both the linkFile() and the file() associated with this AppLnk. 925 Deletes both the linkFile() and the file() associated with this AppLnk.
930 926
931 \sa removeLinkFile() 927 \sa removeLinkFile()
932*/ 928*/
933void AppLnk::removeFiles() 929void AppLnk::removeFiles()
934{ 930{
935 bool valid = isValid(); 931 bool valid = isValid();
936 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { 932 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
937 if ( QFile::remove(file()) ) { 933 if ( QFile::remove(file()) ) {
938#ifndef QT_NO_COP 934#ifndef QT_NO_COP
939 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 935 QCopEnvelope e("QPE/System", "linkChanged(QString)");
940 if ( linkFileKnown() ) 936 if ( linkFileKnown() )
941 e << linkFile(); 937 e << linkFile();
942 else 938 else
943 e << file(); 939 e << file();
944#endif 940#endif
945 } else if ( valid ) { 941 } else if ( valid ) {
946 // restore link 942 // restore link
947 writeLink(); 943 writeLink();
948 } 944 }
949 } 945 }
950} 946}
951 947
952/*! 948/*!
953 Deletes the linkFile(), leaving any file() untouched. 949 Deletes the linkFile(), leaving any file() untouched.
954 950
955 \sa removeFiles() 951 \sa removeFiles()
956*/ 952*/
957void AppLnk::removeLinkFile() 953void AppLnk::removeLinkFile()
958{ 954{
959 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { 955 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
960#ifndef QT_NO_COP 956#ifndef QT_NO_COP
961 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 957 QCopEnvelope e("QPE/System", "linkChanged(QString)");
962 e << linkFile(); 958 e << linkFile();
963#endif 959#endif
964 } 960 }
965} 961}
966 962
967class AppLnkSetPrivate { 963class AppLnkSetPrivate {
968public: 964public:
969 AppLnkSetPrivate() 965 AppLnkSetPrivate()
970 { 966 {
971 typPix.setAutoDelete(TRUE); 967 typPix.setAutoDelete(TRUE);
972 typPixBig.setAutoDelete(TRUE); 968 typPixBig.setAutoDelete(TRUE);
973 typName.setAutoDelete(TRUE); 969 typName.setAutoDelete(TRUE);
974 } 970 }
975 971
976 QDict<QPixmap> typPix; 972 QDict<QPixmap> typPix;
977 QDict<QPixmap> typPixBig; 973 QDict<QPixmap> typPixBig;
978 QDict<QString> typName; 974 QDict<QString> typName;
979}; 975};
980 976
981/*! 977/*!
982 \class AppLnkSet applnk.h 978 \class AppLnkSet applnk.h
983 \brief The AppLnkSet class is a set of AppLnk objects. 979 \brief The AppLnkSet class is a set of AppLnk objects.
984*/ 980*/
985 981
986/*! 982/*!
987 \fn QStringList AppLnkSet::types() const 983 \fn QStringList AppLnkSet::types() const
988 984
989 Returns the list of \link applnk.html#Types types\endlink in the set. 985 Returns the list of \link applnk.html#Types types\endlink in the set.
990 986
991 For applications, games and settings the type is \c Application; 987 For applications, games and settings the type is \c Application;
992 for documents the type is the document's MIME type. 988 for documents the type is the document's MIME type.
993 989
994 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() 990 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap()
995*/ 991*/
996 992
997/*! 993/*!
998 \fn const QList<AppLnk>& AppLnkSet::children() const 994 \fn const QList<AppLnk>& AppLnkSet::children() const
999 995
1000 Returns the members of the set. 996 Returns the members of the set.
1001*/ 997*/
1002 998
1003/*! 999/*!
1004 Constructs an empty AppLnkSet. 1000 Constructs an empty AppLnkSet.
1005*/ 1001*/
1006AppLnkSet::AppLnkSet() : 1002AppLnkSet::AppLnkSet() :
1007 d(new AppLnkSetPrivate) 1003 d(new AppLnkSetPrivate)
1008{ 1004{
1009} 1005}
1010 1006
1011/*! 1007/*!
1012 Constructs an AppLnkSet that contains AppLnk objects representing 1008 Constructs an AppLnkSet that contains AppLnk objects representing
1013 all the files in the given \a directory (and any subdirectories 1009 all the files in the given \a directory (and any subdirectories
1014 recursively). 1010 recursively).
1015 1011
1016 \omit 1012 \omit
1017 The directories may contain ".directory" files which override 1013 The directories may contain ".directory" files which override
1018 any AppLnk::type() values for AppLnk objects found in the directory. 1014 any AppLnk::type() values for AppLnk objects found in the directory.
1019 This allows simple localization of application types. 1015 This allows simple localization of application types.
1020 \endomit 1016 \endomit
1021*/ 1017*/
1022AppLnkSet::AppLnkSet( const QString &directory ) : 1018AppLnkSet::AppLnkSet( const QString &directory ) :
1023 d(new AppLnkSetPrivate) 1019 d(new AppLnkSetPrivate)
1024{ 1020{
1025 QDir dir( directory ); 1021 QDir dir( directory );
1026 mFile = directory; 1022 mFile = directory;
1027 findChildren(directory,QString::null,QString::null); 1023 findChildren(directory,QString::null,QString::null);
1028} 1024}
1029 1025
1030/*! 1026/*!
1031 Detaches all AppLnk objects from the set. The set become empty and 1027 Detaches all AppLnk objects from the set. The set become empty and
1032 the caller becomes responsible for deleting the AppLnk objects. 1028 the caller becomes responsible for deleting the AppLnk objects.
1033*/ 1029*/
1034void AppLnkSet::detachChildren() 1030void AppLnkSet::detachChildren()
1035{ 1031{
1036 QListIterator<AppLnk> it( mApps ); 1032 QListIterator<AppLnk> it( mApps );
1037 for ( ; it.current(); ) { 1033 for ( ; it.current(); ) {
1038 AppLnk* a = *it; 1034 AppLnk* a = *it;
1039 ++it; 1035 ++it;
1040 a->mId = 0; 1036 a->mId = 0;
1041 } 1037 }
1042 mApps.clear(); 1038 mApps.clear();
1043} 1039}
1044 1040
1045/*! 1041/*!
1046 Destroys the set, deleting all the AppLnk objects it contains. 1042 Destroys the set, deleting all the AppLnk objects it contains.
1047 1043
1048 \sa detachChildren() 1044 \sa detachChildren()
1049*/ 1045*/
1050AppLnkSet::~AppLnkSet() 1046AppLnkSet::~AppLnkSet()
1051{ 1047{
1052 QListIterator<AppLnk> it( mApps ); 1048 QListIterator<AppLnk> it( mApps );
1053 for ( ; it.current(); ) { 1049 for ( ; it.current(); ) {
1054 AppLnk* a = *it; 1050 AppLnk* a = *it;
1055 ++it; 1051 ++it;
1056 a->mId = 0; 1052 a->mId = 0;
1057 delete a; 1053 delete a;
1058 } 1054 }
1059 delete d; 1055 delete d;
1060} 1056}
1061 1057
1062void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) 1058void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth)
1063{ 1059{
1064 depth++; 1060 depth++;
1065 if ( depth > 10 ) 1061 if ( depth > 10 )
1066 return; 1062 return;
1067 1063
1068 QDir dir( dr ); 1064 QDir dir( dr );
1069 QString typNameLocal = typName; 1065 QString typNameLocal = typName;
diff --git a/library/fileselector.cpp b/library/fileselector.cpp
index 052a29e..4039243 100644
--- a/library/fileselector.cpp
+++ b/library/fileselector.cpp
@@ -1,583 +1,581 @@
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 "applnk.h" 30#include "applnk.h"
31#include "storage.h" 31#include "storage.h"
32#include "qpemenubar.h" 32#include "qpemenubar.h"
33#ifdef QWS
34#include <qcopchannel_qws.h> 33#include <qcopchannel_qws.h>
35#endif
36#include "lnkproperties.h" 34#include "lnkproperties.h"
37#include "applnk.h" 35#include "applnk.h"
38#include <qpe/qpeapplication.h> 36#include <qpe/qpeapplication.h>
39#include "categorymenu.h" 37#include "categorymenu.h"
40#include "categoryselect.h" 38#include "categoryselect.h"
41#include "mimetype.h" 39#include "mimetype.h"
42#include <qpe/categories.h> 40#include <qpe/categories.h>
43 41
44#include <stdlib.h> 42#include <stdlib.h>
45 43
46#include <qdir.h> 44#include <qdir.h>
47#include <qwidget.h> 45#include <qwidget.h>
48#include <qpopupmenu.h> 46#include <qpopupmenu.h>
49#include <qtoolbutton.h> 47#include <qtoolbutton.h>
50#include <qpushbutton.h> 48#include <qpushbutton.h>
51#include <qheader.h> 49#include <qheader.h>
52#include <qtooltip.h> 50#include <qtooltip.h>
53#include <qwhatsthis.h> 51#include <qwhatsthis.h>
54 52
55class TypeCombo : public QComboBox 53class TypeCombo : public QComboBox
56{ 54{
57 Q_OBJECT 55 Q_OBJECT
58public: 56public:
59 TypeCombo( QWidget *parent, const char *name=0 ) 57 TypeCombo( QWidget *parent, const char *name=0 )
60 : QComboBox( parent, name ) 58 : QComboBox( parent, name )
61 { 59 {
62 connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) ); 60 connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) );
63 } 61 }
64 62
65 void reread( DocLnkSet &files, const QString &filter ); 63 void reread( DocLnkSet &files, const QString &filter );
66 64
67signals: 65signals:
68 void selected( const QString & ); 66 void selected( const QString & );
69 67
70protected slots: 68protected slots:
71 void selectType( int idx ) { 69 void selectType( int idx ) {
72 emit selected( typelist[idx] ); 70 emit selected( typelist[idx] );
73 } 71 }
74 72
75protected: 73protected:
76 QStringList typelist; 74 QStringList typelist;
77 QString prev; 75 QString prev;
78}; 76};
79 77
80void TypeCombo::reread( DocLnkSet &files, const QString &filter ) 78void TypeCombo::reread( DocLnkSet &files, const QString &filter )
81{ 79{
82 typelist.clear(); 80 typelist.clear();
83 QStringList filters = QStringList::split( ';', filter ); 81 QStringList filters = QStringList::split( ';', filter );
84 int pos = filter.find( '/' ); 82 int pos = filter.find( '/' );
85 //### do for each filter 83 //### do for each filter
86 if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) { 84 if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) {
87 typelist.append( filter ); 85 typelist.append( filter );
88 clear(); 86 clear();
89 QString minor = filter.mid( pos+1 ); 87 QString minor = filter.mid( pos+1 );
90 minor[0] = minor[0].upper(); 88 minor[0] = minor[0].upper();
91 insertItem( tr("%1 files").arg(minor) ); 89 insertItem( tr("%1 files").arg(minor) );
92 setCurrentItem(0); 90 setCurrentItem(0);
93 setEnabled( FALSE ); 91 setEnabled( FALSE );
94 return; 92 return;
95 } 93 }
96 94
97 QListIterator<DocLnk> dit( files.children() ); 95 QListIterator<DocLnk> dit( files.children() );
98 for ( ; dit.current(); ++dit ) { 96 for ( ; dit.current(); ++dit ) {
99 if ( !typelist.contains( (*dit)->type() ) ) 97 if ( !typelist.contains( (*dit)->type() ) )
100 typelist.append( (*dit)->type() ); 98 typelist.append( (*dit)->type() );
101 } 99 }
102 100
103 QStringList types; 101 QStringList types;
104 QStringList::ConstIterator it; 102 QStringList::ConstIterator it;
105 for (it = typelist.begin(); it!=typelist.end(); ++it) { 103 for (it = typelist.begin(); it!=typelist.end(); ++it) {
106 QString t = *it; 104 QString t = *it;
107 if ( t.left(12) == "application/" ) { 105 if ( t.left(12) == "application/" ) {
108 MimeType mt(t); 106 MimeType mt(t);
109 const AppLnk* app = mt.application(); 107 const AppLnk* app = mt.application();
110 if ( app ) 108 if ( app )
111 t = app->name(); 109 t = app->name();
112 else 110 else
113 t = t.mid(12); 111 t = t.mid(12);
114 } else { 112 } else {
115 QString major, minor; 113 QString major, minor;
116 int pos = t.find( '/' ); 114 int pos = t.find( '/' );
117 if ( pos >= 0 ) { 115 if ( pos >= 0 ) {
118 major = t.left( pos ); 116 major = t.left( pos );
119 minor = t.mid( pos+1 ); 117 minor = t.mid( pos+1 );
120 } 118 }
121 if ( minor.find( "x-" ) == 0 ) 119 if ( minor.find( "x-" ) == 0 )
122 minor = minor.mid( 2 ); 120 minor = minor.mid( 2 );
123 minor[0] = minor[0].upper(); 121 minor[0] = minor[0].upper();
124 major[0] = major[0].upper(); 122 major[0] = major[0].upper();
125 if ( filters.count() > 1 ) 123 if ( filters.count() > 1 )
126 t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major); 124 t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major);
127 else 125 else
128 t = minor; 126 t = minor;
129 } 127 }
130 types += tr("%1 files").arg(t); 128 types += tr("%1 files").arg(t);
131 } 129 }
132 for (it = filters.begin(); it!=filters.end(); ++it) { 130 for (it = filters.begin(); it!=filters.end(); ++it) {
133 typelist.append( *it ); 131 typelist.append( *it );
134 int pos = (*it).find( '/' ); 132 int pos = (*it).find( '/' );
135 if ( pos >= 0 ) { 133 if ( pos >= 0 ) {
136 QString maj = (*it).left( pos ); 134 QString maj = (*it).left( pos );
137 maj[0] = maj[0].upper(); 135 maj[0] = maj[0].upper();
138 types << tr("All %1 files").arg(maj); 136 types << tr("All %1 files").arg(maj);
139 } 137 }
140 } 138 }
141 if ( filters.count() > 1 ) { 139 if ( filters.count() > 1 ) {
142 typelist.append( filter ); 140 typelist.append( filter );
143 types << tr("All files"); 141 types << tr("All files");
144 } 142 }
145 prev = currentText(); 143 prev = currentText();
146 clear(); 144 clear();
147 insertStringList(types); 145 insertStringList(types);
148 for (int i=0; i<count(); i++) { 146 for (int i=0; i<count(); i++) {
149 if ( text(i) == prev ) { 147 if ( text(i) == prev ) {
150 setCurrentItem(i); 148 setCurrentItem(i);
151 break; 149 break;
152 } 150 }
153 } 151 }
154 if ( prev.isNull() ) 152 if ( prev.isNull() )
155 setCurrentItem(count()-1); 153 setCurrentItem(count()-1);
156 setEnabled( TRUE ); 154 setEnabled( TRUE );
157} 155}
158 156
159 157
160//=========================================================================== 158//===========================================================================
161 159
162FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f ) 160FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f )
163 : QListViewItem( parent ), fl( f ) 161 : QListViewItem( parent ), fl( f )
164{ 162{
165 setText( 0, f.name() ); 163 setText( 0, f.name() );
166 setPixmap( 0, f.pixmap() ); 164 setPixmap( 0, f.pixmap() );
167} 165}
168 166
169FileSelectorItem::~FileSelectorItem() 167FileSelectorItem::~FileSelectorItem()
170{ 168{
171} 169}
172 170
173FileSelectorView::FileSelectorView( QWidget *parent, const char *name ) 171FileSelectorView::FileSelectorView( QWidget *parent, const char *name )
174 : QListView( parent, name ) 172 : QListView( parent, name )
175{ 173{
176 setAllColumnsShowFocus( TRUE ); 174 setAllColumnsShowFocus( TRUE );
177 addColumn( tr( "Name" ) ); 175 addColumn( tr( "Name" ) );
178 header()->hide(); 176 header()->hide();
179} 177}
180 178
181FileSelectorView::~FileSelectorView() 179FileSelectorView::~FileSelectorView()
182{ 180{
183} 181}
184 182
185void FileSelectorView::keyPressEvent( QKeyEvent *e ) 183void FileSelectorView::keyPressEvent( QKeyEvent *e )
186{ 184{
187 QString txt = e->text(); 185 QString txt = e->text();
188 if (e->key() == Key_Space) 186 if (e->key() == Key_Space)
189 emit returnPressed( currentItem() ); 187 emit returnPressed( currentItem() );
190 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) 188 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 )
191 e->ignore(); 189 e->ignore();
192 else 190 else
193 QListView::keyPressEvent(e); 191 QListView::keyPressEvent(e);
194} 192}
195 193
196class NewDocItem : public FileSelectorItem 194class NewDocItem : public FileSelectorItem
197{ 195{
198public: 196public:
199 NewDocItem( QListView *parent, const DocLnk &f ) 197 NewDocItem( QListView *parent, const DocLnk &f )
200 : FileSelectorItem( parent, f ) { 198 : FileSelectorItem( parent, f ) {
201 setText( 0, QObject::tr("New Document") ); 199 setText( 0, QObject::tr("New Document") );
202 QImage img( Resource::loadImage( "new" ) ); 200 QImage img( Resource::loadImage( "new" ) );
203 QPixmap pm; 201 QPixmap pm;
204 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 202 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
205 setPixmap( 0, pm ); 203 setPixmap( 0, pm );
206 } 204 }
207 QString key ( int, bool ) const { 205 QString key ( int, bool ) const {
208 return QString("\n"); 206 return QString("\n");
209 } 207 }
210 208
211 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { 209 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) {
212 QFont oldFont = p->font(); 210 QFont oldFont = p->font();
213 QFont newFont = p->font(); 211 QFont newFont = p->font();
214 newFont.setWeight( QFont::Bold ); 212 newFont.setWeight( QFont::Bold );
215 p->setFont( newFont ); 213 p->setFont( newFont );
216 FileSelectorItem::paintCell( p, cg, column, width, alignment ); 214 FileSelectorItem::paintCell( p, cg, column, width, alignment );
217 p->setFont( oldFont ); 215 p->setFont( oldFont );
218 } 216 }
219 217
220 int width( const QFontMetrics &fm, const QListView *v, int c ) const { 218 int width( const QFontMetrics &fm, const QListView *v, int c ) const {
221 return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font 219 return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font
222 } 220 }
223}; 221};
224 222
225//=========================================================================== 223//===========================================================================
226 224
227class FileSelectorPrivate 225class FileSelectorPrivate
228{ 226{
229public: 227public:
230 TypeCombo *typeCombo; 228 TypeCombo *typeCombo;
231 CategorySelect *catSelect; 229 CategorySelect *catSelect;
232 QValueList<QRegExp> mimeFilters; 230 QValueList<QRegExp> mimeFilters;
233 int catId; 231 int catId;
234 bool showNew; 232 bool showNew;
235 NewDocItem *newDocItem; 233 NewDocItem *newDocItem;
236 DocLnkSet files; 234 DocLnkSet files;
237 QHBox *toolbar; 235 QHBox *toolbar;
238}; 236};
239 237
240/*! 238/*!
241 \class FileSelector fileselector.h 239 \class FileSelector fileselector.h
242 \brief The FileSelector widget allows the user to select DocLnk objects. 240 \brief The FileSelector widget allows the user to select DocLnk objects.
243 241
244 This class presents a file selection dialog to the user. This widget 242 This class presents a file selection dialog to the user. This widget
245 is usually the first widget seen in a \link docwidget.html 243 is usually the first widget seen in a \link docwidget.html
246 document-oriented application\endlink. The developer will most often 244 document-oriented application\endlink. The developer will most often
247 create this widget in combination with a <a 245 create this widget in combination with a <a
248 href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate 246 href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate
249 editor and/or viewer widget for their application. This widget 247 editor and/or viewer widget for their application. This widget
250 should be shown first and the user can the select which document 248 should be shown first and the user can the select which document
251 they wish to operate on. Please refer to the implementation of 249 they wish to operate on. Please refer to the implementation of
252 texteditor for an example of how to tie these classes together. 250 texteditor for an example of how to tie these classes together.
253 251
254 Use setNewVisible() depending on whether the application can be used 252 Use setNewVisible() depending on whether the application can be used
255 to create new files or not. Use setCloseVisible() depending on 253 to create new files or not. Use setCloseVisible() depending on
256 whether the user may leave the dialog without creating or selecting 254 whether the user may leave the dialog without creating or selecting
257 a document or not. The number of files in the view is available from 255 a document or not. The number of files in the view is available from
258 fileCount(). To force the view to be updated call reread(). 256 fileCount(). To force the view to be updated call reread().
259 257
260 If the user presses the 'New Document' button the newSelected() 258 If the user presses the 'New Document' button the newSelected()
261 signal is emitted. If the user selects an existing file the 259 signal is emitted. If the user selects an existing file the
262 fileSelected() signal is emitted. The selected file's \link 260 fileSelected() signal is emitted. The selected file's \link
263 doclnk.html DocLnk\endlink is available from the selected() 261 doclnk.html DocLnk\endlink is available from the selected()
264 function. If the file selector is no longer necessary the closeMe() 262 function. If the file selector is no longer necessary the closeMe()
265 signal is emitted. 263 signal is emitted.
266 264
267 \ingroup qtopiaemb 265 \ingroup qtopiaemb
268 \sa FileManager 266 \sa FileManager
269*/ 267*/
270 268
271/*! 269/*!
272 Constructs a FileSelector with mime filter \a f. 270 Constructs a FileSelector with mime filter \a f.
273 The standard Qt \a parent and \a name parameters are passed to the 271 The standard Qt \a parent and \a name parameters are passed to the
274 parent widget. 272 parent widget.
275 273
276 If \a newVisible is TRUE, the widget has a button to allow the user 274 If \a newVisible is TRUE, the widget has a button to allow the user
277 the create "new" documents; this is useful for applications that can 275 the create "new" documents; this is useful for applications that can
278 create and edit documents but not suitable for applications that 276 create and edit documents but not suitable for applications that
279 only provide viewing. 277 only provide viewing.
280 278
281 \a closeVisible is deprecated 279 \a closeVisible is deprecated
282 280
283 \sa DocLnkSet::DocLnkSet() 281 \sa DocLnkSet::DocLnkSet()
284*/ 282*/
285FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) 283FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible )
286 : QVBox( parent, name ), filter( f ) 284 : QVBox( parent, name ), filter( f )
287{ 285{
288 setMargin( 0 ); 286 setMargin( 0 );
289 setSpacing( 0 ); 287 setSpacing( 0 );
290 288
291 d = new FileSelectorPrivate(); 289 d = new FileSelectorPrivate();
292 d->newDocItem = 0; 290 d->newDocItem = 0;
293 d->showNew = newVisible; 291 d->showNew = newVisible;
294 d->catId = -2; // All files 292 d->catId = -2; // All files
295 293
296 d->toolbar = new QHBox( this ); 294 d->toolbar = new QHBox( this );
297 d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars 295 d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars
298 d->toolbar->setSpacing( 0 ); 296 d->toolbar->setSpacing( 0 );
299 d->toolbar->hide(); 297 d->toolbar->hide();
300 298
301 QWidget *spacer = new QWidget( d->toolbar ); 299 QWidget *spacer = new QWidget( d->toolbar );
302 spacer->setBackgroundMode( PaletteButton ); 300 spacer->setBackgroundMode( PaletteButton );
303 301
304 QToolButton *tb = new QToolButton( d->toolbar ); 302 QToolButton *tb = new QToolButton( d->toolbar );
305 tb->setPixmap( Resource::loadPixmap( "close" ) ); 303 tb->setPixmap( Resource::loadPixmap( "close" ) );
306 connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) ); 304 connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) );
307 buttonClose = tb; 305 buttonClose = tb;
308 tb->setFixedSize( 18, 20 ); // tb->sizeHint() ); 306 tb->setFixedSize( 18, 20 ); // tb->sizeHint() );
309 tb->setAutoRaise( TRUE ); 307 tb->setAutoRaise( TRUE );
310 QToolTip::add( tb, tr( "Close the File Selector" ) ); 308 QToolTip::add( tb, tr( "Close the File Selector" ) );
311 QPEMenuToolFocusManager::manager()->addWidget( tb ); 309 QPEMenuToolFocusManager::manager()->addWidget( tb );
312 310
313 view = new FileSelectorView( this, "fileview" ); 311 view = new FileSelectorView( this, "fileview" );
314 QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold ); 312 QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold );
315 connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), 313 connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ),
316 this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) ); 314 this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) );
317 connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ), 315 connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ),
318 this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) ); 316 this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) );
319 connect( view, SIGNAL( returnPressed( QListViewItem * ) ), 317 connect( view, SIGNAL( returnPressed( QListViewItem * ) ),
320 this, SLOT( fileClicked( QListViewItem * ) ) ); 318 this, SLOT( fileClicked( QListViewItem * ) ) );
321 319
322 QHBox *hb = new QHBox( this ); 320 QHBox *hb = new QHBox( this );
323 321
324 d->typeCombo = new TypeCombo( hb ); 322 d->typeCombo = new TypeCombo( hb );
325 connect( d->typeCombo, SIGNAL(selected(const QString&)), 323 connect( d->typeCombo, SIGNAL(selected(const QString&)),
326 this, SLOT(typeSelected(const QString&)) ); 324 this, SLOT(typeSelected(const QString&)) );
327 QWhatsThis::add( d->typeCombo, tr("Show documents of this type") ); 325 QWhatsThis::add( d->typeCombo, tr("Show documents of this type") );
328 326
329 Categories c; 327 Categories c;
330 c.load(categoryFileName()); 328 c.load(categoryFileName());
331 QArray<int> vl( 0 ); 329 QArray<int> vl( 0 );
332 d->catSelect = new CategorySelect( hb ); 330 d->catSelect = new CategorySelect( hb );
333 d->catSelect->setRemoveCategoryEdit( TRUE ); 331 d->catSelect->setRemoveCategoryEdit( TRUE );
334 d->catSelect->setCategories( vl, "Document View", tr("Document View") ); 332 d->catSelect->setCategories( vl, "Document View", tr("Document View") );
335 d->catSelect->setAllCategories( TRUE ); 333 d->catSelect->setAllCategories( TRUE );
336 connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) ); 334 connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) );
337 QWhatsThis::add( d->catSelect, tr("Show documents in this category") ); 335 QWhatsThis::add( d->catSelect, tr("Show documents in this category") );
338 336
339 setCloseVisible( closeVisible ); 337 setCloseVisible( closeVisible );
340 338
341 QCopChannel *channel = new QCopChannel( "QPE/Card", this ); 339 QCopChannel *channel = new QCopChannel( "QPE/Card", this );
342 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 340 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
343 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 341 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
344 342
345 reread(); 343 reread();
346 updateWhatsThis(); 344 updateWhatsThis();
347} 345}
348 346
349/*! 347/*!
350 Destroys the widget. 348 Destroys the widget.
351*/ 349*/
352FileSelector::~FileSelector() 350FileSelector::~FileSelector()
353{ 351{
354 delete d; 352 delete d;
355} 353}
356 354
357/*! 355/*!
358 Returns the number of files in the view. If this is zero, an editor 356 Returns the number of files in the view. If this is zero, an editor
359 application might bypass the selector and immediately start with 357 application might bypass the selector and immediately start with
360 a "new" document. 358 a "new" document.
361*/ 359*/
362int FileSelector::fileCount() 360int FileSelector::fileCount()
363{ 361{
364 return d->files.children().count();; 362 return d->files.children().count();;
365} 363}
366 364
367/*! 365/*!
368 Calling this function is the programmatic equivalent of the user 366 Calling this function is the programmatic equivalent of the user
369 pressing the "new" button. 367 pressing the "new" button.
370 368
371 \sa newSelected(), closeMe() 369 \sa newSelected(), closeMe()
372*/ 370*/
373void FileSelector::createNew() 371void FileSelector::createNew()
374{ 372{
375 DocLnk f; 373 DocLnk f;
376 emit newSelected( f ); 374 emit newSelected( f );
377 emit closeMe(); 375 emit closeMe();
378} 376}
379 377
380void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) 378void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int )
381{ 379{
382 if ( !i ) 380 if ( !i )
383 return; 381 return;
384 if ( button == Qt::LeftButton ) { 382 if ( button == Qt::LeftButton ) {
385 fileClicked( i ); 383 fileClicked( i );
386 } 384 }
387} 385}
388 386
389void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int ) 387void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int )
390{ 388{
391 if ( !i || i == d->newDocItem ) 389 if ( !i || i == d->newDocItem )
392 return; 390 return;
393 if ( button == Qt::RightButton ) { 391 if ( button == Qt::RightButton ) {
394 DocLnk l = ((FileSelectorItem *)i)->file(); 392 DocLnk l = ((FileSelectorItem *)i)->file();
395 LnkProperties prop( &l ); 393 LnkProperties prop( &l );
396 prop.showMaximized(); 394 prop.showMaximized();
397 prop.exec(); 395 prop.exec();
398 reread(); 396 reread();
399 } 397 }
400} 398}
401 399
402void FileSelector::fileClicked( QListViewItem *i ) 400void FileSelector::fileClicked( QListViewItem *i )
403{ 401{
404 if ( !i ) 402 if ( !i )
405 return; 403 return;
406 if ( i == d->newDocItem ) { 404 if ( i == d->newDocItem ) {
407 createNew(); 405 createNew();
408 } else { 406 } else {
409 emit fileSelected( ( (FileSelectorItem*)i )->file() ); 407 emit fileSelected( ( (FileSelectorItem*)i )->file() );
410 emit closeMe(); 408 emit closeMe();
411 } 409 }
412} 410}
413 411
414void FileSelector::typeSelected( const QString &type ) 412void FileSelector::typeSelected( const QString &type )
415{ 413{
416 d->mimeFilters.clear(); 414 d->mimeFilters.clear();
417 QStringList subFilter = QStringList::split(";", type); 415 QStringList subFilter = QStringList::split(";", type);
418 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it ) 416 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it )
419 d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); 417 d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
420 updateView(); 418 updateView();
421} 419}
422 420
423void FileSelector::catSelected( int c ) 421void FileSelector::catSelected( int c )
424{ 422{
425 d->catId = c; 423 d->catId = c;
426 updateView(); 424 updateView();
427} 425}
428 426
429void FileSelector::cardMessage( const QCString &msg, const QByteArray &) 427void FileSelector::cardMessage( const QCString &msg, const QByteArray &)
430{ 428{
431 if ( msg == "mtabChanged()" ) 429 if ( msg == "mtabChanged()" )
432 reread(); 430 reread();
433} 431}
434 432
435 433
436/*! 434/*!
437 Returns the selected \link doclnk.html DocLnk\endlink. The caller is 435 Returns the selected \link doclnk.html DocLnk\endlink. The caller is
438 responsible for deleting the returned value. 436 responsible for deleting the returned value.
439*/ 437*/
440const DocLnk *FileSelector::selected() 438const DocLnk *FileSelector::selected()
441{ 439{
442 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); 440 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
443 if ( item && item != d->newDocItem ) 441 if ( item && item != d->newDocItem )
444 return new DocLnk( item->file() ); 442 return new DocLnk( item->file() );
445 return NULL; 443 return NULL;
446} 444}
447 445
448/*! 446/*!
449 \fn void FileSelector::fileSelected( const DocLnk &f ) 447 \fn void FileSelector::fileSelected( const DocLnk &f )
450 448
451 This signal is emitted when the user selects a document. 449 This signal is emitted when the user selects a document.
452 \a f is the document. 450 \a f is the document.
453*/ 451*/
454 452
455/*! 453/*!
456 \fn void FileSelector::newSelected( const DocLnk &f ) 454 \fn void FileSelector::newSelected( const DocLnk &f )
457 455
458 This signal is emitted when the user selects a "new" document. 456 This signal is emitted when the user selects a "new" document.
459 \a f is a DocLnk for the document. You will need to set the type 457 \a f is a DocLnk for the document. You will need to set the type
460 of the document after copying it. 458 of the document after copying it.
461*/ 459*/
462 460
463/*! 461/*!
464 \fn void FileSelector::closeMe() 462 \fn void FileSelector::closeMe()
465 463
466 This signal is emitted when the user no longer needs to view the widget. 464 This signal is emitted when the user no longer needs to view the widget.
467*/ 465*/
468 466
469 467
470/*! 468/*!
471 If \a b is TRUE a "new document" entry is visible; if \a b is FALSE 469 If \a b is TRUE a "new document" entry is visible; if \a b is FALSE
472 this entry is not visible and the user is unable to create new 470 this entry is not visible and the user is unable to create new
473 documents from the dialog. 471 documents from the dialog.
474*/ 472*/
475void FileSelector::setNewVisible( bool b ) 473void FileSelector::setNewVisible( bool b )
476{ 474{
477 if ( d->showNew != b ) { 475 if ( d->showNew != b ) {
478 d->showNew = b; 476 d->showNew = b;
479 updateView(); 477 updateView();
480 updateWhatsThis(); 478 updateWhatsThis();
481 } 479 }
482} 480}
483 481
484/*! 482/*!
485 If \a b is TRUE a "close" or "no document" button is visible; if \a 483 If \a b is TRUE a "close" or "no document" button is visible; if \a
486 b is FALSE this button is not visible and the user is unable to 484 b is FALSE this button is not visible and the user is unable to
487 leave the dialog without creating or selecting a document. 485 leave the dialog without creating or selecting a document.
488 486
489 This function is deprecated. 487 This function is deprecated.
490*/ 488*/
491void FileSelector::setCloseVisible( bool b ) 489void FileSelector::setCloseVisible( bool b )
492{ 490{
493 if ( b ) 491 if ( b )
494 d->toolbar->show(); 492 d->toolbar->show();
495 else 493 else
496 d->toolbar->hide(); 494 d->toolbar->hide();
497} 495}
498 496
499/*! 497/*!
500 498
501*/ 499*/
502void FileSelector::setTypeComboVisible( bool b ) { 500void FileSelector::setTypeComboVisible( bool b ) {
503 if ( b ) 501 if ( b )
504 d->typeCombo->show(); 502 d->typeCombo->show();
505 else 503 else
506 d->typeCombo->hide(); 504 d->typeCombo->hide();
507} 505}
508/*! 506/*!
509 507
510*/ 508*/
511void FileSelector::setCategorySelectVisible( bool b ) { 509void FileSelector::setCategorySelectVisible( bool b ) {
512 if ( b ) 510 if ( b )
513 d->catSelect->show(); 511 d->catSelect->show();
514 else 512 else
515 d->catSelect->hide(); 513 d->catSelect->hide();
516} 514}
517 515
518/*! 516/*!
519 Rereads the list of documents. 517 Rereads the list of documents.
520*/ 518*/
521void FileSelector::reread() 519void FileSelector::reread()
522{ 520{
523 d->files.clear(); 521 d->files.clear();
524 Global::findDocuments(&d->files, filter); 522 Global::findDocuments(&d->files, filter);
525 d->typeCombo->reread( d->files, filter ); 523 d->typeCombo->reread( d->files, filter );
526 updateView(); 524 updateView();
527} 525}
528 526
529void FileSelector::updateView() 527void FileSelector::updateView()
530{ 528{
531 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); 529 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
532 if ( item == d->newDocItem ) 530 if ( item == d->newDocItem )
533 item = 0; 531 item = 0;
534 QString oldFile; 532 QString oldFile;
535 if ( item ) 533 if ( item )
536 oldFile = item->file().file(); 534 oldFile = item->file().file();
537 view->clear(); 535 view->clear();
538 QListIterator<DocLnk> dit( d->files.children() ); 536 QListIterator<DocLnk> dit( d->files.children() );
539 for ( ; dit.current(); ++dit ) { 537 for ( ; dit.current(); ++dit ) {
540 bool mimeMatch = FALSE; 538 bool mimeMatch = FALSE;
541 if ( d->mimeFilters.count() ) { 539 if ( d->mimeFilters.count() ) {
542 QValueList<QRegExp>::Iterator it; 540 QValueList<QRegExp>::Iterator it;
543 for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) { 541 for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) {
544 if ( (*it).match((*dit)->type()) >= 0 ) { 542 if ( (*it).match((*dit)->type()) >= 0 ) {
545 mimeMatch = TRUE; 543 mimeMatch = TRUE;
546 break; 544 break;
547 } 545 }
548 } 546 }
549 } else { 547 } else {
550 mimeMatch = TRUE; 548 mimeMatch = TRUE;
551 } 549 }
552 if ( mimeMatch && 550 if ( mimeMatch &&
553 (d->catId == -2 || (*dit)->categories().contains(d->catId) || 551 (d->catId == -2 || (*dit)->categories().contains(d->catId) ||
554 (d->catId == -1 && (*dit)->categories().isEmpty())) ) { 552 (d->catId == -1 && (*dit)->categories().isEmpty())) ) {
555 item = new FileSelectorItem( view, **dit ); 553 item = new FileSelectorItem( view, **dit );
556 if ( item->file().file() == oldFile ) 554 if ( item->file().file() == oldFile )
557 view->setCurrentItem( item ); 555 view->setCurrentItem( item );
558 } 556 }
559 } 557 }
560 558
561 if ( d->showNew ) 559 if ( d->showNew )
562 d->newDocItem = new NewDocItem( view, DocLnk() ); 560 d->newDocItem = new NewDocItem( view, DocLnk() );
563 else 561 else
564 d->newDocItem = 0; 562 d->newDocItem = 0;
565 563
566 if ( !view->selectedItem() || view->childCount() == 1 ) { 564 if ( !view->selectedItem() || view->childCount() == 1 ) {
567 view->setCurrentItem( view->firstChild() ); 565 view->setCurrentItem( view->firstChild() );
568 view->setSelected( view->firstChild(), TRUE ); 566 view->setSelected( view->firstChild(), TRUE );
569 } 567 }
570} 568}
571 569
572void FileSelector::updateWhatsThis() 570void FileSelector::updateWhatsThis()
573{ 571{
574 QWhatsThis::remove( this ); 572 QWhatsThis::remove( this );
575 QString text = tr("Click to select a document from the list"); 573 QString text = tr("Click to select a document from the list");
576 if ( d->showNew ) 574 if ( d->showNew )
577 text += tr(", or select <b>New Document</b> to create a new document."); 575 text += tr(", or select <b>New Document</b> to create a new document.");
578 text += tr("<br><br>Click and hold for document properties."); 576 text += tr("<br><br>Click and hold for document properties.");
579 QWhatsThis::add( this, text ); 577 QWhatsThis::add( this, text );
580} 578}
581 579
582#include "fileselector.moc" 580#include "fileselector.moc"
583 581
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp
index 2b5e0d2..147134c 100644
--- a/library/fontdatabase.cpp
+++ b/library/fontdatabase.cpp
@@ -1,232 +1,230 @@
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 <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include "fontfactoryinterface.h" 22#include "fontfactoryinterface.h"
23#include "fontdatabase.h" 23#include "fontdatabase.h"
24 24
25#include <qpe/qlibrary.h> 25#include <qpe/qlibrary.h>
26 26
27#ifdef QWS
28#include <qfontmanager_qws.h> 27#include <qfontmanager_qws.h>
29#endif
30#include <qdir.h> 28#include <qdir.h>
31#include <qdict.h> 29#include <qdict.h>
32#include <stdio.h> 30#include <stdio.h>
33#include <stdlib.h> 31#include <stdlib.h>
34 32
35static QString fontDir() 33static QString fontDir()
36{ 34{
37 QString qtdir = getenv("QTDIR"); 35 QString qtdir = getenv("QTDIR");
38 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded"; 36 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded";
39 return qtdir+"/lib/fonts/"; 37 return qtdir+"/lib/fonts/";
40} 38}
41 39
42#ifdef QT_NO_FONTDATABASE 40#ifdef QT_NO_FONTDATABASE
43static QString fontFamily( const QString& key ) 41static QString fontFamily( const QString& key )
44{ 42{
45 int u0 = key.find('_'); 43 int u0 = key.find('_');
46 int u1 = key.find('_',u0+1); 44 int u1 = key.find('_',u0+1);
47 int u2 = key.find('_',u1+1); 45 int u2 = key.find('_',u1+1);
48 QString family = key.left(u0); 46 QString family = key.left(u0);
49 //int pointSize = key.mid(u0+1,u1-u0-1).toInt(); 47 //int pointSize = key.mid(u0+1,u1-u0-1).toInt();
50 //int weight = key.mid(u1+1,u2-u1-1).toInt(); 48 //int weight = key.mid(u1+1,u2-u1-1).toInt();
51 //bool italic = key.mid(u2-1,1) == "i"; 49 //bool italic = key.mid(u2-1,1) == "i";
52 // #### ignores _t and _I fields 50 // #### ignores _t and _I fields
53 return family; 51 return family;
54} 52}
55#endif 53#endif
56 54
57QValueList<FontFactory> *FontDatabase::factoryList = 0; 55QValueList<FontFactory> *FontDatabase::factoryList = 0;
58 56
59/*! 57/*!
60 \class FontDatabase fontdatabase.h 58 \class FontDatabase fontdatabase.h
61 \brief The FontDatabase class provides information about available fonts. 59 \brief The FontDatabase class provides information about available fonts.
62 60
63 Most often you will simply want to query the database for the 61 Most often you will simply want to query the database for the
64 available font families(). 62 available font families().
65 63
66 Use FontDatabase rather than QFontDatabase when you may need access 64 Use FontDatabase rather than QFontDatabase when you may need access
67 to fonts that are not normally available. For example, if the 65 to fonts that are not normally available. For example, if the
68 freetype library and the Qtopia freetype plugin are installed, 66 freetype library and the Qtopia freetype plugin are installed,
69 TrueType fonts will be available to your application. Font renderer 67 TrueType fonts will be available to your application. Font renderer
70 plugins have greater resource requirements than system fonts so they 68 plugins have greater resource requirements than system fonts so they
71 should be used only when necessary. You can force the loading of 69 should be used only when necessary. You can force the loading of
72 font renderer plugins with loadRenderers(). 70 font renderer plugins with loadRenderers().
73 71
74 \ingroup qtopiaemb 72 \ingroup qtopiaemb
75*/ 73*/
76 74
77/*! 75/*!
78 Constructs a FontDatabase object. 76 Constructs a FontDatabase object.
79*/ 77*/
80FontDatabase::FontDatabase() 78FontDatabase::FontDatabase()
81#ifndef QT_NO_FONTDATABASE 79#ifndef QT_NO_FONTDATABASE
82 : QFontDatabase() 80 : QFontDatabase()
83#endif 81#endif
84{ 82{
85 if ( !factoryList ) 83 if ( !factoryList )
86 loadRenderers(); 84 loadRenderers();
87} 85}
88 86
89/*! 87/*!
90 Returns a list of names of all the available font families. 88 Returns a list of names of all the available font families.
91*/ 89*/
92QStringList FontDatabase::families() const 90QStringList FontDatabase::families() const
93{ 91{
94#ifndef QT_NO_FONTDATABASE 92#ifndef QT_NO_FONTDATABASE
95 return QFontDatabase::families(); 93 return QFontDatabase::families();
96#else 94#else
97 QStringList list; 95 QStringList list;
98 QDict<void> familyDict; 96 QDict<void> familyDict;
99 QDiskFont *qdf; 97 QDiskFont *qdf;
100 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; 98 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
101 qdf=qt_fontmanager->diskfonts.next()) { 99 qdf=qt_fontmanager->diskfonts.next()) {
102 QString familyname = qdf->name; 100 QString familyname = qdf->name;
103 if ( !familyDict.find( familyname ) ) { 101 if ( !familyDict.find( familyname ) ) {
104 familyDict.insert( familyname, (void *)1 ); 102 familyDict.insert( familyname, (void *)1 );
105 list.append( familyname ); 103 list.append( familyname );
106 } 104 }
107 } 105 }
108 106
109 QDir dir(fontDir(),"*.qpf"); 107 QDir dir(fontDir(),"*.qpf");
110 for (int i=0; i<(int)dir.count(); i++) { 108 for (int i=0; i<(int)dir.count(); i++) {
111 QString familyname = fontFamily(dir[i]); 109 QString familyname = fontFamily(dir[i]);
112 if ( !familyDict.find( familyname ) ) { 110 if ( !familyDict.find( familyname ) ) {
113 familyDict.insert( familyname, (void *)1 ); 111 familyDict.insert( familyname, (void *)1 );
114 list.append( familyname ); 112 list.append( familyname );
115 } 113 }
116 } 114 }
117 115
118 return list; 116 return list;
119#endif 117#endif
120} 118}
121 119
122#ifdef QT_NO_FONTDATABASE 120#ifdef QT_NO_FONTDATABASE
123/*! 121/*!
124 Returns a list of standard fontsizes. 122 Returns a list of standard fontsizes.
125*/ 123*/
126QValueList<int> FontDatabase::standardSizes() 124QValueList<int> FontDatabase::standardSizes()
127{ 125{
128 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 126 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
129 36, 48, 72, 0 }; 127 36, 48, 72, 0 };
130 static bool first = TRUE; 128 static bool first = TRUE;
131 static QValueList<int> sList; 129 static QValueList<int> sList;
132 if ( first ) { 130 if ( first ) {
133 first = FALSE; 131 first = FALSE;
134 int i = 0; 132 int i = 0;
135 while( s[i] ) 133 while( s[i] )
136 sList.append( s[i++] ); 134 sList.append( s[i++] );
137 } 135 }
138 return sList; 136 return sList;
139} 137}
140 138
141#endif 139#endif
142 140
143/*! 141/*!
144 Load any font renderer plugins that are available and make the fonts 142 Load any font renderer plugins that are available and make the fonts
145 that the plugins can read available. 143 that the plugins can read available.
146*/ 144*/
147void FontDatabase::loadRenderers() 145void FontDatabase::loadRenderers()
148{ 146{
149#ifndef QT_NO_COMPONENT 147#ifndef QT_NO_COMPONENT
150 if ( !factoryList ) 148 if ( !factoryList )
151 factoryList = new QValueList<FontFactory>; 149 factoryList = new QValueList<FontFactory>;
152 150
153 QValueList<FontFactory>::Iterator mit; 151 QValueList<FontFactory>::Iterator mit;
154 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { 152 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
155 qt_fontmanager->factories.setAutoDelete( false ); 153 qt_fontmanager->factories.setAutoDelete( false );
156 qt_fontmanager->factories.removeRef( (*mit).factory ); 154 qt_fontmanager->factories.removeRef( (*mit).factory );
157 qt_fontmanager->factories.setAutoDelete( true ); 155 qt_fontmanager->factories.setAutoDelete( true );
158 (*mit).interface->release(); 156 (*mit).interface->release();
159 (*mit).library->unload(); 157 (*mit).library->unload();
160 delete (*mit).library; 158 delete (*mit).library;
161 } 159 }
162 factoryList->clear(); 160 factoryList->clear();
163 161
164 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; 162 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories";
165 QDir dir( path, "lib*.so" ); 163 QDir dir( path, "lib*.so" );
166 QStringList list = dir.entryList(); 164 QStringList list = dir.entryList();
167 QStringList::Iterator it; 165 QStringList::Iterator it;
168 for ( it = list.begin(); it != list.end(); ++it ) { 166 for ( it = list.begin(); it != list.end(); ++it ) {
169 FontFactoryInterface *iface = 0; 167 FontFactoryInterface *iface = 0;
170 QLibrary *lib = new QLibrary( path + "/" + *it ); 168 QLibrary *lib = new QLibrary( path + "/" + *it );
171 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { 169 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
172 FontFactory factory; 170 FontFactory factory;
173 factory.library = lib; 171 factory.library = lib;
174 factory.interface = iface; 172 factory.interface = iface;
175 factory.factory = factory.interface->fontFactory(); 173 factory.factory = factory.interface->fontFactory();
176 factoryList->append( factory ); 174 factoryList->append( factory );
177 qt_fontmanager->factories.append( factory.factory ); 175 qt_fontmanager->factories.append( factory.factory );
178 readFonts( factory.factory ); 176 readFonts( factory.factory );
179 } else { 177 } else {
180 delete lib; 178 delete lib;
181 } 179 }
182 } 180 }
183#endif 181#endif
184} 182}
185 183
186/*! 184/*!
187 \internal 185 \internal
188*/ 186*/
189void FontDatabase::readFonts( QFontFactory *factory ) 187void FontDatabase::readFonts( QFontFactory *factory )
190{ 188{
191 // Load in font definition file 189 // Load in font definition file
192 QString fn = fontDir() + "fontdir"; 190 QString fn = fontDir() + "fontdir";
193 FILE* fontdef=fopen(fn.local8Bit(),"r"); 191 FILE* fontdef=fopen(fn.local8Bit(),"r");
194 if(!fontdef) { 192 if(!fontdef) {
195 QCString temp=fn.local8Bit(); 193 QCString temp=fn.local8Bit();
196 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", 194 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
197 temp.data()); 195 temp.data());
198 return; 196 return;
199 } 197 }
200 char buf[200]=""; 198 char buf[200]="";
201 char name[200]=""; 199 char name[200]="";
202 char render[200]=""; 200 char render[200]="";
203 char file[200]=""; 201 char file[200]="";
204 char flags[200]=""; 202 char flags[200]="";
205 char isitalic[10]=""; 203 char isitalic[10]="";
206 fgets(buf,200,fontdef); 204 fgets(buf,200,fontdef);
207 while(!feof(fontdef)) { 205 while(!feof(fontdef)) {
208 if ( buf[0] != '#' ) { 206 if ( buf[0] != '#' ) {
209 int weight=50; 207 int weight=50;
210 int size=0; 208 int size=0;
211 flags[0]=0; 209 flags[0]=0;
212 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); 210 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
213 QString filename; 211 QString filename;
214 if ( file[0] != '/' ) 212 if ( file[0] != '/' )
215 filename = fontDir(); 213 filename = fontDir();
216 filename += file; 214 filename += file;
217 if ( QFile::exists(filename) ) { 215 if ( QFile::exists(filename) ) {
218 if( factory->name() == render ) { 216 if( factory->name() == render ) {
219 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', 217 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y',
220 weight,size,flags,filename); 218 weight,size,flags,filename);
221 qt_fontmanager->diskfonts.append(qdf); 219 qt_fontmanager->diskfonts.append(qdf);
222#if QT_VERSION >= 232 220#if QT_VERSION >= 232
223 QFontDatabase::qwsAddDiskFont( qdf ); 221 QFontDatabase::qwsAddDiskFont( qdf );
224#endif 222#endif
225 } 223 }
226 } 224 }
227 } 225 }
228 fgets(buf,200,fontdef); 226 fgets(buf,200,fontdef);
229 } 227 }
230 fclose(fontdef); 228 fclose(fontdef);
231} 229}
232 230
diff --git a/library/fontmanager.cpp b/library/fontmanager.cpp
index 28a5212..c854133 100644
--- a/library/fontmanager.cpp
+++ b/library/fontmanager.cpp
@@ -1,103 +1,101 @@
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#ifdef QWS
22#include "fontmanager.h" 21#include "fontmanager.h"
23#include <qfile.h> 22#include <qfile.h>
24#include <stdlib.h> 23#include <stdlib.h>
25#include <qgfx_qws.h> 24#include <qgfx_qws.h>
26 25
27 26
28 27
29/* 28/*
30 QFontInfo doesn't work in QWS at the moment, 29 QFontInfo doesn't work in QWS at the moment,
31 otherwise we would just have used that to check 30 otherwise we would just have used that to check
32 the real values 31 the real values
33 32
34 For now, there are only two Unicode fonts in 33 For now, there are only two Unicode fonts in
35 the known universe... 34 the known universe...
36 35
37*/ 36*/
38 37
39bool FontManager::hasUnicodeFont() 38bool FontManager::hasUnicodeFont()
40{ 39{
41 QString fontDir = getenv("QTDIR") + QString("/lib/fonts/"); 40 QString fontDir = getenv("QTDIR") + QString("/lib/fonts/");
42 41
43 QString suffix; 42 QString suffix;
44 if ( qt_screen->isTransformed() ) { 43 if ( qt_screen->isTransformed() ) {
45 suffix += "_t"; 44 suffix += "_t";
46 QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2)); 45 QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2));
47 QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2)); 46 QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2));
48 suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) ); 47 suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) );
49 } 48 }
50 suffix += ".qpf"; 49 suffix += ".qpf";
51 50
52 return QFile::exists( fontDir+"cyberbit_120_50"+suffix ) 51 return QFile::exists( fontDir+"cyberbit_120_50"+suffix )
53 || QFile::exists( fontDir+"unifont_160_50"+suffix ) || 52 || QFile::exists( fontDir+"unifont_160_50"+suffix ) ||
54 QFile::exists( fontDir+"arial_140_50" + suffix ); 53 QFile::exists( fontDir+"arial_140_50" + suffix );
55} 54}
56 55
57QFont FontManager::unicodeFont( Spacing sp ) 56QFont FontManager::unicodeFont( Spacing sp )
58{ 57{
59 QString key; 58 QString key;
60 QString fontName; 59 QString fontName;
61 QString fontDir = getenv("QTDIR") + QString("/lib/fonts/"); 60 QString fontDir = getenv("QTDIR") + QString("/lib/fonts/");
62 61
63 int size; 62 int size;
64 if ( sp == Proportional ) { 63 if ( sp == Proportional ) {
65 fontName = "Arial"; 64 fontName = "Arial";
66 size=14; 65 size=14;
67 key = "arial_140_50"; 66 key = "arial_140_50";
68 } else { 67 } else {
69 fontName = "Unifont"; 68 fontName = "Unifont";
70 size=16; 69 size=16;
71 key = "unifont_160_50"; 70 key = "unifont_160_50";
72 } 71 }
73 72
74 QString suffix; 73 QString suffix;
75 if ( qt_screen->isTransformed() ) { 74 if ( qt_screen->isTransformed() ) {
76 suffix += "_t"; 75 suffix += "_t";
77 QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2)); 76 QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2));
78 QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2)); 77 QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2));
79 suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) ); 78 suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) );
80 } 79 }
81 suffix += ".qpf"; 80 suffix += ".qpf";
82 81
83 // if we cannot find it, try the other one 82 // if we cannot find it, try the other one
84 83
85 if ( !QFile::exists(fontDir+key+suffix) ) { 84 if ( !QFile::exists(fontDir+key+suffix) ) {
86 key = (sp == Fixed ) ? "arial_140_50" : "unifont_160_50"; 85 key = (sp == Fixed ) ? "arial_140_50" : "unifont_160_50";
87 if ( QFile::exists(fontDir+key+suffix) ) { 86 if ( QFile::exists(fontDir+key+suffix) ) {
88 fontName = (sp == Fixed) ? "Arial" : "Unifont"; 87 fontName = (sp == Fixed) ? "Arial" : "Unifont";
89 size = (sp == Fixed) ? 14 : 16; 88 size = (sp == Fixed) ? 14 : 16;
90 } else { 89 } else {
91 key = "cyberbit_120_50"; 90 key = "cyberbit_120_50";
92 if ( QFile::exists(fontDir+key+suffix) ) { 91 if ( QFile::exists(fontDir+key+suffix) ) {
93 fontName = "Cyberbit"; 92 fontName = "Cyberbit";
94 size = 12; 93 size = 12;
95 } else { 94 } else {
96 fontName = "Helvetica"; 95 fontName = "Helvetica";
97 size = 14; 96 size = 14;
98 } 97 }
99 } 98 }
100 } 99 }
101 return QFont(fontName,size); 100 return QFont(fontName,size);
102} 101}
103#endif
diff --git a/library/global.cpp b/library/global.cpp
index 9b908bf..d02e711 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,812 +1,806 @@
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#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
21#include <qpe/qpedebug.h> 21#include <qpe/qpedebug.h>
22#include <qpe/global.h> 22#include <qpe/global.h>
23#include <qpe/qdawg.h> 23#include <qpe/qdawg.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/storage.h> 26#include <qpe/storage.h>
27#include <qpe/applnk.h> 27#include <qpe/applnk.h>
28#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 28#include <qpe/qcopenvelope_qws.h>
29#include "qpe/qcopenvelope_qws.h"
30#endif
31 29
32#include <qfile.h> 30#include <qfile.h>
33#include <qlabel.h> 31#include <qlabel.h>
34#include <qtimer.h> 32#include <qtimer.h>
35#include <qmap.h> 33#include <qmap.h>
36#include <qdict.h> 34#include <qdict.h>
37#include <qdir.h> 35#include <qdir.h>
38#include <qmessagebox.h> 36#include <qmessagebox.h>
39#include <qregexp.h> 37#include <qregexp.h>
40 38
41#include <stdlib.h> 39#include <stdlib.h>
42#include <sys/stat.h> 40#include <sys/stat.h>
43#include <sys/wait.h> 41#include <sys/wait.h>
44#include <sys/types.h> 42#include <sys/types.h>
45#include <fcntl.h> 43#include <fcntl.h>
46#include <unistd.h> 44#include <unistd.h>
47 45
48#ifdef QWS
49#include <qwindowsystem_qws.h> // for qwsServer 46#include <qwindowsystem_qws.h> // for qwsServer
50#endif
51#include <qdatetime.h> 47#include <qdatetime.h>
52 48
53#include <qfile.h> 49#include <qfile.h>
54 50
55namespace { 51namespace {
56 // checks if the storage should be searched 52 // checks if the storage should be searched
57 bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke 53 bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke
58 QFile file(path ); 54 QFile file(path );
59 if(!file.open(IO_ReadOnly ) ) 55 if(!file.open(IO_ReadOnly ) )
60 return true; 56 return true;
61 57
62 QByteArray array = file.readAll(); 58 QByteArray array = file.readAll();
63 QStringList list = QStringList::split('\n', QString( array ) ); 59 QStringList list = QStringList::split('\n', QString( array ) );
64 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ 60 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
65 if( (*it).startsWith("autocheck = 0" ) ){ 61 if( (*it).startsWith("autocheck = 0" ) ){
66 return false; 62 return false;
67 }else if( (*it).startsWith("autocheck = 1" ) ){ 63 }else if( (*it).startsWith("autocheck = 1" ) ){
68 return true; 64 return true;
69 } 65 }
70 } 66 }
71 return true; 67 return true;
72 } 68 }
73} 69}
74 70
75//#include "quickexec_p.h" 71//#include "quickexec_p.h"
76 72
77class Emitter : public QObject { 73class Emitter : public QObject {
78 Q_OBJECT 74 Q_OBJECT
79public: 75public:
80 Emitter( QWidget* receiver, const QString& document ) 76 Emitter( QWidget* receiver, const QString& document )
81 { 77 {
82 connect(this, SIGNAL(setDocument(const QString&)), 78 connect(this, SIGNAL(setDocument(const QString&)),
83 receiver, SLOT(setDocument(const QString&))); 79 receiver, SLOT(setDocument(const QString&)));
84 emit setDocument(document); 80 emit setDocument(document);
85 disconnect(this, SIGNAL(setDocument(const QString&)), 81 disconnect(this, SIGNAL(setDocument(const QString&)),
86 receiver, SLOT(setDocument(const QString&))); 82 receiver, SLOT(setDocument(const QString&)));
87 } 83 }
88 84
89signals: 85signals:
90 void setDocument(const QString&); 86 void setDocument(const QString&);
91}; 87};
92 88
93 89
94class StartingAppList : public QObject { 90class StartingAppList : public QObject {
95 Q_OBJECT 91 Q_OBJECT
96public: 92public:
97 static void add( const QString& name ); 93 static void add( const QString& name );
98 static bool isStarting( const QString name ); 94 static bool isStarting( const QString name );
99private slots: 95private slots:
100 void handleNewChannel( const QString &); 96 void handleNewChannel( const QString &);
101private: 97private:
102 StartingAppList( QObject *parent=0, const char* name=0 ) ; 98 StartingAppList( QObject *parent=0, const char* name=0 ) ;
103 99
104 QDict<QTime> dict; 100 QDict<QTime> dict;
105 static StartingAppList *appl; 101 static StartingAppList *appl;
106}; 102};
107 103
108StartingAppList* StartingAppList::appl = 0; 104StartingAppList* StartingAppList::appl = 0;
109 105
110StartingAppList::StartingAppList( QObject *parent, const char* name ) 106StartingAppList::StartingAppList( QObject *parent, const char* name )
111 :QObject( parent, name ) 107 :QObject( parent, name )
112{ 108{
113#ifdef QWS
114#if QT_VERSION >= 232 && !defined(QT_NO_COP) 109#if QT_VERSION >= 232 && !defined(QT_NO_COP)
115 connect( qwsServer, SIGNAL( newChannel(const QString&)), 110 connect( qwsServer, SIGNAL( newChannel(const QString&)),
116 this, SLOT( handleNewChannel(const QString&)) ); 111 this, SLOT( handleNewChannel(const QString&)) );
117 dict.setAutoDelete( TRUE ); 112 dict.setAutoDelete( TRUE );
118#endif 113#endif
119#endif
120} 114}
121 115
122void StartingAppList::add( const QString& name ) 116void StartingAppList::add( const QString& name )
123{ 117{
124#if QT_VERSION >= 232 && !defined(QT_NO_COP) 118#if QT_VERSION >= 232 && !defined(QT_NO_COP)
125 if ( !appl ) 119 if ( !appl )
126 appl = new StartingAppList; 120 appl = new StartingAppList;
127 QTime *t = new QTime; 121 QTime *t = new QTime;
128 t->start(); 122 t->start();
129 appl->dict.insert( "QPE/Application/" + name, t ); 123 appl->dict.insert( "QPE/Application/" + name, t );
130#endif 124#endif
131} 125}
132 126
133bool StartingAppList::isStarting( const QString name ) 127bool StartingAppList::isStarting( const QString name )
134{ 128{
135#if QT_VERSION >= 232 && !defined(QT_NO_COP) 129#if QT_VERSION >= 232 && !defined(QT_NO_COP)
136 if ( appl ) { 130 if ( appl ) {
137 QTime *t = appl->dict.find( "QPE/Application/" + name ); 131 QTime *t = appl->dict.find( "QPE/Application/" + name );
138 if ( !t ) 132 if ( !t )
139 return FALSE; 133 return FALSE;
140 if ( t->elapsed() > 10000 ) { 134 if ( t->elapsed() > 10000 ) {
141 // timeout in case of crash or something 135 // timeout in case of crash or something
142 appl->dict.remove( "QPE/Application/" + name ); 136 appl->dict.remove( "QPE/Application/" + name );
143 return FALSE; 137 return FALSE;
144 } 138 }
145 return TRUE; 139 return TRUE;
146 } 140 }
147#endif 141#endif
148 return FALSE; 142 return FALSE;
149} 143}
150 144
151void StartingAppList::handleNewChannel( const QString & name ) 145void StartingAppList::handleNewChannel( const QString & name )
152{ 146{
153#if QT_VERSION >= 232 && !defined(QT_NO_COP) 147#if QT_VERSION >= 232 && !defined(QT_NO_COP)
154 dict.remove( name ); 148 dict.remove( name );
155#endif 149#endif
156} 150}
157 151
158static bool docDirCreated = FALSE; 152static bool docDirCreated = FALSE;
159static QDawg* fixed_dawg = 0; 153static QDawg* fixed_dawg = 0;
160static QDict<QDawg> *named_dawg = 0; 154static QDict<QDawg> *named_dawg = 0;
161 155
162static QString qpeDir() 156static QString qpeDir()
163{ 157{
164 QString dir = getenv("OPIEDIR"); 158 QString dir = getenv("OPIEDIR");
165 if ( dir.isEmpty() ) dir = ".."; 159 if ( dir.isEmpty() ) dir = "..";
166 return dir; 160 return dir;
167} 161}
168 162
169static QString dictDir() 163static QString dictDir()
170{ 164{
171 return qpeDir() + "/etc/dict"; 165 return qpeDir() + "/etc/dict";
172} 166}
173 167
174/*! 168/*!
175 \class Global global.h 169 \class Global global.h
176 \brief The Global class provides application-wide global functions. 170 \brief The Global class provides application-wide global functions.
177 171
178 The Global functions are grouped as follows: 172 The Global functions are grouped as follows:
179 \tableofcontents 173 \tableofcontents
180 174
181 \section1 User Interface 175 \section1 User Interface
182 176
183 The statusMessage() function provides short-duration messages to the 177 The statusMessage() function provides short-duration messages to the
184 user. The showInputMethod() function shows the current input method, 178 user. The showInputMethod() function shows the current input method,
185 and hideInputMethod() hides the input method. 179 and hideInputMethod() hides the input method.
186 180
187 \section1 Document related 181 \section1 Document related
188 182
189 The findDocuments() function creates a set of \link doclnk.html 183 The findDocuments() function creates a set of \link doclnk.html
190 DocLnk\endlink objects in a particular folder. 184 DocLnk\endlink objects in a particular folder.
191 185
192 \section1 Filesystem related 186 \section1 Filesystem related
193 187
194 Global provides an applicationFileName() function that returns the 188 Global provides an applicationFileName() function that returns the
195 full path of an application-specific file. 189 full path of an application-specific file.
196 190
197 The execute() function runs an application. 191 The execute() function runs an application.
198 192
199 \section1 Word list related 193 \section1 Word list related
200 194
201 A list of words relevant to the current locale is maintained by the 195 A list of words relevant to the current locale is maintained by the
202 system. The list is held in a \link qdawg.html DAWG\endlink 196 system. The list is held in a \link qdawg.html DAWG\endlink
203 (implemented by the QDawg class). This list is used, for example, by 197 (implemented by the QDawg class). This list is used, for example, by
204 the pickboard input method. 198 the pickboard input method.
205 199
206 The global QDawg is returned by fixedDawg(); this cannot be updated. 200 The global QDawg is returned by fixedDawg(); this cannot be updated.
207 An updatable copy of the global QDawg is returned by addedDawg(). 201 An updatable copy of the global QDawg is returned by addedDawg().
208 Applications may have their own word lists stored in \l{QDawg}s 202 Applications may have their own word lists stored in \l{QDawg}s
209 which are returned by dawg(). Use addWords() to add words to the 203 which are returned by dawg(). Use addWords() to add words to the
210 updateable copy of the global QDawg or to named application 204 updateable copy of the global QDawg or to named application
211 \l{QDawg}s. 205 \l{QDawg}s.
212 206
213 \section1 Quoting 207 \section1 Quoting
214 208
215 The shellQuote() function quotes a string suitable for passing to a 209 The shellQuote() function quotes a string suitable for passing to a
216 shell. The stringQuote() function backslash escapes '\' and '"' 210 shell. The stringQuote() function backslash escapes '\' and '"'
217 characters. 211 characters.
218 212
219 \section1 Hardware 213 \section1 Hardware
220 214
221 The writeHWClock() function sets the hardware clock to the system 215 The writeHWClock() function sets the hardware clock to the system
222 clock's date and time. 216 clock's date and time.
223 217
224 \ingroup qtopiaemb 218 \ingroup qtopiaemb
225*/ 219*/
226 220
227/*! 221/*!
228 \internal 222 \internal
229*/ 223*/
230Global::Global() 224Global::Global()
231{ 225{
232} 226}
233 227
234/*! 228/*!
235 Returns the unchangeable QDawg that contains general 229 Returns the unchangeable QDawg that contains general
236 words for the current locale. 230 words for the current locale.
237 231
238 \sa addedDawg() 232 \sa addedDawg()
239*/ 233*/
240const QDawg& Global::fixedDawg() 234const QDawg& Global::fixedDawg()
241{ 235{
242 if ( !fixed_dawg ) { 236 if ( !fixed_dawg ) {
243 if ( !docDirCreated ) 237 if ( !docDirCreated )
244 createDocDir(); 238 createDocDir();
245 239
246 fixed_dawg = new QDawg; 240 fixed_dawg = new QDawg;
247 QString dawgfilename = dictDir() + "/dawg"; 241 QString dawgfilename = dictDir() + "/dawg";
248 QString words_lang; 242 QString words_lang;
249 QStringList langs = Global::languageList(); 243 QStringList langs = Global::languageList();
250 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 244 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
251 QString lang = *it; 245 QString lang = *it;
252 words_lang = dictDir() + "/words." + lang; 246 words_lang = dictDir() + "/words." + lang;
253 QString dawgfilename_lang = dawgfilename + "." + lang; 247 QString dawgfilename_lang = dawgfilename + "." + lang;
254 if ( QFile::exists(dawgfilename_lang) || 248 if ( QFile::exists(dawgfilename_lang) ||
255 QFile::exists(words_lang) ) { 249 QFile::exists(words_lang) ) {
256 dawgfilename = dawgfilename_lang; 250 dawgfilename = dawgfilename_lang;
257 break; 251 break;
258 } 252 }
259 } 253 }
260 QFile dawgfile(dawgfilename); 254 QFile dawgfile(dawgfilename);
261 255
262 if ( !dawgfile.exists() ) { 256 if ( !dawgfile.exists() ) {
263 QString fn = dictDir() + "/words"; 257 QString fn = dictDir() + "/words";
264 if ( QFile::exists(words_lang) ) 258 if ( QFile::exists(words_lang) )
265 fn = words_lang; 259 fn = words_lang;
266 QFile in(fn); 260 QFile in(fn);
267 if ( in.open(IO_ReadOnly) ) { 261 if ( in.open(IO_ReadOnly) ) {
268 fixed_dawg->createFromWords(&in); 262 fixed_dawg->createFromWords(&in);
269 dawgfile.open(IO_WriteOnly); 263 dawgfile.open(IO_WriteOnly);
270 fixed_dawg->write(&dawgfile); 264 fixed_dawg->write(&dawgfile);
271 dawgfile.close(); 265 dawgfile.close();
272 } 266 }
273 } else { 267 } else {
274 fixed_dawg->readFile(dawgfilename); 268 fixed_dawg->readFile(dawgfilename);
275 } 269 }
276 } 270 }
277 271
278 return *fixed_dawg; 272 return *fixed_dawg;
279} 273}
280 274
281/*! 275/*!
282 Returns the changeable QDawg that contains general 276 Returns the changeable QDawg that contains general
283 words for the current locale. 277 words for the current locale.
284 278
285 \sa fixedDawg() 279 \sa fixedDawg()
286*/ 280*/
287const QDawg& Global::addedDawg() 281const QDawg& Global::addedDawg()
288{ 282{
289 return dawg("local"); 283 return dawg("local");
290} 284}
291 285
292/*! 286/*!
293 Returns the QDawg with the given \a name. 287 Returns the QDawg with the given \a name.
294 This is an application-specific word list. 288 This is an application-specific word list.
295 289
296 \a name should not contain "/". 290 \a name should not contain "/".
297*/ 291*/
298const QDawg& Global::dawg(const QString& name) 292const QDawg& Global::dawg(const QString& name)
299{ 293{
300 createDocDir(); 294 createDocDir();
301 if ( !named_dawg ) 295 if ( !named_dawg )
302 named_dawg = new QDict<QDawg>; 296 named_dawg = new QDict<QDawg>;
303 QDawg* r = named_dawg->find(name); 297 QDawg* r = named_dawg->find(name);
304 if ( !r ) { 298 if ( !r ) {
305 r = new QDawg; 299 r = new QDawg;
306 named_dawg->insert(name,r); 300 named_dawg->insert(name,r);
307 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; 301 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg";
308 QFile dawgfile(dawgfilename); 302 QFile dawgfile(dawgfilename);
309 if ( dawgfile.open(IO_ReadOnly) ) 303 if ( dawgfile.open(IO_ReadOnly) )
310 r->readFile(dawgfilename); 304 r->readFile(dawgfilename);
311 } 305 }
312 return *r; 306 return *r;
313} 307}
314 308
315/*! 309/*!
316 \overload 310 \overload
317 Adds \a wordlist to the addedDawg(). 311 Adds \a wordlist to the addedDawg().
318 312
319 Note that the addition of words persists between program executions 313 Note that the addition of words persists between program executions
320 (they are saved in the dictionary files), so you should confirm the 314 (they are saved in the dictionary files), so you should confirm the
321 words with the user before adding them. 315 words with the user before adding them.
322*/ 316*/
323void Global::addWords(const QStringList& wordlist) 317void Global::addWords(const QStringList& wordlist)
324{ 318{
325 addWords("local",wordlist); 319 addWords("local",wordlist);
326} 320}
327 321
328/*! 322/*!
329 \overload 323 \overload
330 Adds \a wordlist to the addedDawg(). 324 Adds \a wordlist to the addedDawg().
331 325
332 Note that the addition of words persists between program executions 326 Note that the addition of words persists between program executions
333 (they are saved in the dictionary files), so you should confirm the 327 (they are saved in the dictionary files), so you should confirm the
334 words with the user before adding them. 328 words with the user before adding them.
335*/ 329*/
336void Global::addWords(const QString& dictname, const QStringList& wordlist) 330void Global::addWords(const QString& dictname, const QStringList& wordlist)
337{ 331{
338 QDawg& d = (QDawg&)dawg(dictname); 332 QDawg& d = (QDawg&)dawg(dictname);
339 QStringList all = d.allWords() + wordlist; 333 QStringList all = d.allWords() + wordlist;
340 d.createFromWords(all); 334 d.createFromWords(all);
341 335
342 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; 336 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg";
343 QFile dawgfile(dawgfilename); 337 QFile dawgfile(dawgfilename);
344 if ( dawgfile.open(IO_WriteOnly) ) { 338 if ( dawgfile.open(IO_WriteOnly) ) {
345 d.write(&dawgfile); 339 d.write(&dawgfile);
346 dawgfile.close(); 340 dawgfile.close();
347 } 341 }
348 342
349 // #### Re-read the dawg here if we use mmap(). 343 // #### Re-read the dawg here if we use mmap().
350 344
351 // #### Signal other processes to re-read. 345 // #### Signal other processes to re-read.
352} 346}
353 347
354 348
355/*! 349/*!
356 Returns the full path for the application called \a appname, with the 350 Returns the full path for the application called \a appname, with the
357 given \a filename. Returns QString::null if there was a problem creating 351 given \a filename. Returns QString::null if there was a problem creating
358 the directory tree for \a appname. 352 the directory tree for \a appname.
359 If \a filename contains "/", it is the caller's responsibility to 353 If \a filename contains "/", it is the caller's responsibility to
360 ensure that those directories exist. 354 ensure that those directories exist.
361*/ 355*/
362QString Global::applicationFileName(const QString& appname, const QString& filename) 356QString Global::applicationFileName(const QString& appname, const QString& filename)
363{ 357{
364 QDir d; 358 QDir d;
365 QString r = getenv("HOME"); 359 QString r = getenv("HOME");
366 r += "/Applications/"; 360 r += "/Applications/";
367 if ( !QFile::exists( r ) ) 361 if ( !QFile::exists( r ) )
368 if ( d.mkdir(r) == false ) 362 if ( d.mkdir(r) == false )
369 return QString::null; 363 return QString::null;
370 r += appname; 364 r += appname;
371 if ( !QFile::exists( r ) ) 365 if ( !QFile::exists( r ) )
372 if ( d.mkdir(r) == false ) 366 if ( d.mkdir(r) == false )
373 return QString::null; 367 return QString::null;
374 r += "/"; r += filename; 368 r += "/"; r += filename;
375 return r; 369 return r;
376} 370}
377 371
378/*! 372/*!
379 \internal 373 \internal
380*/ 374*/
381void Global::createDocDir() 375void Global::createDocDir()
382{ 376{
383 if ( !docDirCreated ) { 377 if ( !docDirCreated ) {
384 docDirCreated = TRUE; 378 docDirCreated = TRUE;
385 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 379 mkdir( QPEApplication::documentDir().latin1(), 0755 );
386 } 380 }
387} 381}
388 382
389 383
390/*! 384/*!
391 Displays a status \a message to the user. This usually appears 385 Displays a status \a message to the user. This usually appears
392 in the taskbar for a short amount of time, then disappears. 386 in the taskbar for a short amount of time, then disappears.
393*/ 387*/
394void Global::statusMessage(const QString& message) 388void Global::statusMessage(const QString& message)
395{ 389{
396#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 390#if!defined(QT_NO_COP)
397 QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); 391 QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
398 e << message; 392 e << message;
399#endif 393#endif
400} 394}
401 395
402/*! 396/*!
403 \internal 397 \internal
404*/ 398*/
405void Global::applyStyle() 399void Global::applyStyle()
406{ 400{
407#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 401#if !defined(QT_NO_COP)
408 QCopChannel::send( "QPE/System", "applyStyle()" ); 402 QCopChannel::send( "QPE/System", "applyStyle()" );
409#else 403#else
410 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version 404 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version
411#endif 405#endif
412} 406}
413 407
414/*! 408/*!
415 \internal 409 \internal
416*/ 410*/
417QWidget *Global::shutdown( bool ) 411QWidget *Global::shutdown( bool )
418{ 412{
419#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 413#if !defined(QT_NO_COP)
420 QCopChannel::send( "QPE/System", "shutdown()" ); 414 QCopChannel::send( "QPE/System", "shutdown()" );
421#endif 415#endif
422 return 0; 416 return 0;
423} 417}
424 418
425/*! 419/*!
426 \internal 420 \internal
427*/ 421*/
428QWidget *Global::restart( bool ) 422QWidget *Global::restart( bool )
429{ 423{
430#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 424#if !defined(QT_NO_COP)
431 QCopChannel::send( "QPE/System", "restart()" ); 425 QCopChannel::send( "QPE/System", "restart()" );
432#endif 426#endif
433 return 0; 427 return 0;
434} 428}
435 429
436/*! 430/*!
437 Explicitly show the current input method. 431 Explicitly show the current input method.
438 432
439 Input methods are indicated in the taskbar by a small icon. If the 433 Input methods are indicated in the taskbar by a small icon. If the
440 input method is activated (shown) then it takes up some proportion 434 input method is activated (shown) then it takes up some proportion
441 of the bottom of the screen, to allow the user to interact (input 435 of the bottom of the screen, to allow the user to interact (input
442 characters) with it. 436 characters) with it.
443 437
444 \sa hideInputMethod() 438 \sa hideInputMethod()
445*/ 439*/
446void Global::showInputMethod() 440void Global::showInputMethod()
447{ 441{
448#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 442#if !defined(QT_NO_COP)
449 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); 443 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" );
450#endif 444#endif
451} 445}
452 446
453/*! 447/*!
454 Explicitly hide the current input method. 448 Explicitly hide the current input method.
455 449
456 The current input method is still indicated in the taskbar, but no 450 The current input method is still indicated in the taskbar, but no
457 longer takes up screen space, and can no longer be interacted with. 451 longer takes up screen space, and can no longer be interacted with.
458 452
459 \sa showInputMethod() 453 \sa showInputMethod()
460*/ 454*/
461void Global::hideInputMethod() 455void Global::hideInputMethod()
462{ 456{
463#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 457#if !defined(QT_NO_COP)
464 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); 458 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" );
465#endif 459#endif
466} 460}
467 461
468 462
469/*! 463/*!
470 \internal 464 \internal
471*/ 465*/
472bool Global::isBuiltinCommand( const QString &name ) 466bool Global::isBuiltinCommand( const QString &name )
473{ 467{
474 if(!builtin) 468 if(!builtin)
475 return FALSE; // yes, it can happen 469 return FALSE; // yes, it can happen
476 for (int i = 0; builtin[i].file; i++) { 470 for (int i = 0; builtin[i].file; i++) {
477 if ( builtin[i].file == name ) { 471 if ( builtin[i].file == name ) {
478 return TRUE; 472 return TRUE;
479 } 473 }
480 } 474 }
481 return FALSE; 475 return FALSE;
482} 476}
483 477
484Global::Command* Global::builtin=0; 478Global::Command* Global::builtin=0;
485QGuardedPtr<QWidget> *Global::running=0; 479QGuardedPtr<QWidget> *Global::running=0;
486 480
487/*! 481/*!
488 \class Global::Command 482 \class Global::Command
489 \brief The Global::Command class is internal. 483 \brief The Global::Command class is internal.
490 \internal 484 \internal
491*/ 485*/
492 486
493/*! 487/*!
494 \internal 488 \internal
495*/ 489*/
496void Global::setBuiltinCommands( Command* list ) 490void Global::setBuiltinCommands( Command* list )
497{ 491{
498 if ( running ) 492 if ( running )
499 delete [] running; 493 delete [] running;
500 494
501 builtin = list; 495 builtin = list;
502 int count = 0; 496 int count = 0;
503 if (!builtin) 497 if (!builtin)
504 return; 498 return;
505 while ( builtin[count].file ) 499 while ( builtin[count].file )
506 count++; 500 count++;
507 501
508 running = new QGuardedPtr<QWidget> [ count ]; 502 running = new QGuardedPtr<QWidget> [ count ];
509} 503}
510 504
511/*! 505/*!
512 \internal 506 \internal
513*/ 507*/
514void Global::setDocument( QWidget* receiver, const QString& document ) 508void Global::setDocument( QWidget* receiver, const QString& document )
515{ 509{
516 Emitter emitter(receiver,document); 510 Emitter emitter(receiver,document);
517} 511}
518 512
519/*! 513/*!
520 \internal 514 \internal
521*/ 515*/
522bool Global::terminateBuiltin( const QString& n ) 516bool Global::terminateBuiltin( const QString& n )
523{ 517{
524 if (!builtin) 518 if (!builtin)
525 return FALSE; 519 return FALSE;
526 for (int i = 0; builtin[i].file; i++) { 520 for (int i = 0; builtin[i].file; i++) {
527 if ( builtin[i].file == n ) { 521 if ( builtin[i].file == n ) {
528 delete running[i]; 522 delete running[i];
529 return TRUE; 523 return TRUE;
530 } 524 }
531 } 525 }
532 return FALSE; 526 return FALSE;
533} 527}
534 528
535/*! 529/*!
536 \internal 530 \internal
537*/ 531*/
538void Global::terminate( const AppLnk* app ) 532void Global::terminate( const AppLnk* app )
539{ 533{
540 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this 534 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
541 535
542#ifndef QT_NO_COP 536#ifndef QT_NO_COP
543 QCString channel = "QPE/Application/" + app->exec().utf8(); 537 QCString channel = "QPE/Application/" + app->exec().utf8();
544 if ( QCopChannel::isRegistered(channel) ) { 538 if ( QCopChannel::isRegistered(channel) ) {
545 QCopEnvelope e(channel, "quit()"); 539 QCopEnvelope e(channel, "quit()");
546 } 540 }
547#endif 541#endif
548} 542}
549 543
550/*! 544/*!
551 Low-level function to run command \a c. 545 Low-level function to run command \a c.
552 546
553 \warning Do not use this function. Use execute instead. 547 \warning Do not use this function. Use execute instead.
554 548
555 \sa execute() 549 \sa execute()
556*/ 550*/
557void Global::invoke(const QString &c) 551void Global::invoke(const QString &c)
558{ 552{
559 // Convert the command line in to a list of arguments 553 // Convert the command line in to a list of arguments
560 QStringList list = QStringList::split(QRegExp(" *"),c); 554 QStringList list = QStringList::split(QRegExp(" *"),c);
561 555
562#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 556#if !defined(QT_NO_COP)
563 QString ap=list[0]; 557 QString ap=list[0];
564 // see if the application is already running 558 // see if the application is already running
565 // XXX should lock file /tmp/qcop-msg-ap 559 // XXX should lock file /tmp/qcop-msg-ap
566 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 560 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
567 // If the channel is already register, the app is already running, so show it. 561 // If the channel is already register, the app is already running, so show it.
568 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 562 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
569 563
570 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 564 QCopEnvelope e("QPE/System", "notBusy(QString)" );
571 e << ap; 565 e << ap;
572 return; 566 return;
573 } 567 }
574 // XXX should unlock file /tmp/qcop-msg-ap 568 // XXX should unlock file /tmp/qcop-msg-ap
575 //see if it is being started 569 //see if it is being started
576 if ( StartingAppList::isStarting( ap ) ) { 570 if ( StartingAppList::isStarting( ap ) ) {
577 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 571 QCopEnvelope e("QPE/System", "notBusy(QString)" );
578 e << ap; 572 e << ap;
579 return; 573 return;
580 } 574 }
581 575
582#endif 576#endif
583 577
584#ifdef QT_NO_QWS_MULTIPROCESS 578#ifdef QT_NO_QWS_MULTIPROCESS
585 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); 579 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
586#else 580#else
587 581
588 QStrList slist; 582 QStrList slist;
589 unsigned int j; 583 unsigned int j;
590 for ( j = 0; j < list.count(); j++ ) 584 for ( j = 0; j < list.count(); j++ )
591 slist.append( list[j].utf8() ); 585 slist.append( list[j].utf8() );
592 586
593 const char **args = new (const char *)[slist.count() + 1]; 587 const char **args = new (const char *)[slist.count() + 1];
594 for ( j = 0; j < slist.count(); j++ ) 588 for ( j = 0; j < slist.count(); j++ )
595 args[j] = slist.at(j); 589 args[j] = slist.at(j);
596 args[j] = NULL; 590 args[j] = NULL;
597 591
598#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 592#if !defined(QT_NO_COP)
599 // an attempt to show a wait... 593 // an attempt to show a wait...
600 // more logic should be used, but this will be fine for the moment... 594 // more logic should be used, but this will be fine for the moment...
601 QCopEnvelope ( "QPE/System", "busy()" ); 595 QCopEnvelope ( "QPE/System", "busy()" );
602#endif 596#endif
603 597
604#ifdef HAVE_QUICKEXEC 598#ifdef HAVE_QUICKEXEC
605 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; 599 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
606 qDebug("libfile = %s", libexe.latin1() ); 600 qDebug("libfile = %s", libexe.latin1() );
607 if ( QFile::exists( libexe ) ) { 601 if ( QFile::exists( libexe ) ) {
608 qDebug("calling quickexec %s", libexe.latin1() ); 602 qDebug("calling quickexec %s", libexe.latin1() );
609 quickexecv( libexe.utf8().data(), (const char **)args ); 603 quickexecv( libexe.utf8().data(), (const char **)args );
610 } else 604 } else
611#endif 605#endif
612 { 606 {
613 if ( !::vfork() ) { 607 if ( !::vfork() ) {
614 for ( int fd = 3; fd < 100; fd++ ) 608 for ( int fd = 3; fd < 100; fd++ )
615 ::close( fd ); 609 ::close( fd );
616 ::setpgid( ::getpid(), ::getppid() ); 610 ::setpgid( ::getpid(), ::getppid() );
617 // Try bindir first, so that foo/bar works too 611 // Try bindir first, so that foo/bar works too
618 ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); 612 ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args );
619 ::execvp( args[0], (char * const *)args ); 613 ::execvp( args[0], (char * const *)args );
620 _exit( -1 ); 614 _exit( -1 );
621 } 615 }
622 } 616 }
623 StartingAppList::add( list[0] ); 617 StartingAppList::add( list[0] );
624#endif //QT_NO_QWS_MULTIPROCESS 618#endif //QT_NO_QWS_MULTIPROCESS
625} 619}
626 620
627 621
628/*! 622/*!
629 Executes the application identfied by \a c, passing \a 623 Executes the application identfied by \a c, passing \a
630 document if it isn't null. 624 document if it isn't null.
631 625
632 Note that a better approach might be to send a QCop message to the 626 Note that a better approach might be to send a QCop message to the
633 application's QPE/Application/\e{appname} channel. 627 application's QPE/Application/\e{appname} channel.
634*/ 628*/
635void Global::execute( const QString &c, const QString& document ) 629void Global::execute( const QString &c, const QString& document )
636{ 630{
637 if ( qApp->type() != QApplication::GuiServer ) { 631 if ( qApp->type() != QApplication::GuiServer ) {
638 // ask the server to do the work 632 // ask the server to do the work
639#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 633#if !defined(QT_NO_COP)
640 if ( document.isNull() ) { 634 if ( document.isNull() ) {
641 QCopEnvelope e( "QPE/System", "execute(QString)" ); 635 QCopEnvelope e( "QPE/System", "execute(QString)" );
642 e << c; 636 e << c;
643 } else { 637 } else {
644 QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); 638 QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
645 e << c << document; 639 e << c << document;
646 } 640 }
647#endif 641#endif
648 return; 642 return;
649 } 643 }
650 644
651 // Attempt to execute the app using a builtin class for the app first 645 // Attempt to execute the app using a builtin class for the app first
652 // else try and find it in the bin directory 646 // else try and find it in the bin directory
653 if (builtin) { 647 if (builtin) {
654 for (int i = 0; builtin[i].file; i++) { 648 for (int i = 0; builtin[i].file; i++) {
655 if ( builtin[i].file == c ) { 649 if ( builtin[i].file == c ) {
656 if ( running[i] ) { 650 if ( running[i] ) {
657 if ( !document.isNull() && builtin[i].documentary ) 651 if ( !document.isNull() && builtin[i].documentary )
658 setDocument(running[i], document); 652 setDocument(running[i], document);
659 running[i]->raise(); 653 running[i]->raise();
660 running[i]->show(); 654 running[i]->show();
661 running[i]->setActiveWindow(); 655 running[i]->setActiveWindow();
662 } else { 656 } else {
663 running[i] = builtin[i].func( builtin[i].maximized ); 657 running[i] = builtin[i].func( builtin[i].maximized );
664 } 658 }
665#ifndef QT_NO_COP 659#ifndef QT_NO_COP
666 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 660 QCopEnvelope e("QPE/System", "notBusy(QString)" );
667 e << c; // that was quick ;-) 661 e << c; // that was quick ;-)
668#endif 662#endif
669 return; 663 return;
670 } 664 }
671 } 665 }
672 } 666 }
673 667
674 //Global::invoke(c, document); 668 //Global::invoke(c, document);
675 669
676 // Convert the command line in to a list of arguments 670 // Convert the command line in to a list of arguments
677 QStringList list = QStringList::split(QRegExp(" *"),c); 671 QStringList list = QStringList::split(QRegExp(" *"),c);
678 672
679#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 673#if !defined(QT_NO_COP)
680 QString ap=list[0]; 674 QString ap=list[0];
681 675
682 qDebug("executing %s", ap.latin1() ); 676 qDebug("executing %s", ap.latin1() );
683 677
684 /* if need be, sending a qcop message will result in an invoke, see 678 /* if need be, sending a qcop message will result in an invoke, see
685 preceeding function */ 679 preceeding function */
686 invoke( ap ); 680 invoke( ap );
687 //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 681 //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
688 if ( !document.isEmpty() ) { 682 if ( !document.isEmpty() ) {
689 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); 683 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" );
690 env << document; 684 env << document;
691 } 685 }
692#endif 686#endif
693} 687}
694 688
695/*! 689/*!
696 Returns the string \a s with the characters '\', '"', and '$' quoted 690 Returns the string \a s with the characters '\', '"', and '$' quoted
697 by a preceeding '\'. 691 by a preceeding '\'.
698 692
699 \sa stringQuote() 693 \sa stringQuote()
700*/ 694*/
701QString Global::shellQuote(const QString& s) 695QString Global::shellQuote(const QString& s)
702{ 696{
703 QString r="\""; 697 QString r="\"";
704 for (int i=0; i<(int)s.length(); i++) { 698 for (int i=0; i<(int)s.length(); i++) {
705 char c = s[i].latin1(); 699 char c = s[i].latin1();
706 switch (c) { 700 switch (c) {
707 case '\\': case '"': case '$': 701 case '\\': case '"': case '$':
708 r+="\\"; 702 r+="\\";
709 } 703 }
710 r += s[i]; 704 r += s[i];
711 } 705 }
712 r += "\""; 706 r += "\"";
713 return r; 707 return r;
714} 708}
715 709
716/*! 710/*!
717 Returns the string \a s with the characters '\' and '"' quoted by a 711 Returns the string \a s with the characters '\' and '"' quoted by a
718 preceeding '\'. 712 preceeding '\'.
719 713
720 \sa shellQuote() 714 \sa shellQuote()
721*/ 715*/
722QString Global::stringQuote(const QString& s) 716QString Global::stringQuote(const QString& s)
723{ 717{
724 QString r="\""; 718 QString r="\"";
725 for (int i=0; i<(int)s.length(); i++) { 719 for (int i=0; i<(int)s.length(); i++) {
726 char c = s[i].latin1(); 720 char c = s[i].latin1();
727 switch (c) { 721 switch (c) {
728 case '\\': case '"': 722 case '\\': case '"':
729 r+="\\"; 723 r+="\\";
730 } 724 }
731 r += s[i]; 725 r += s[i];
732 } 726 }
733 r += "\""; 727 r += "\"";
734 return r; 728 return r;
735} 729}
736 730
737/*! 731/*!
738 Finds all documents on the system's document directories which 732 Finds all documents on the system's document directories which
739 match the filter \a mimefilter, and appends the resulting DocLnk 733 match the filter \a mimefilter, and appends the resulting DocLnk
740 objects to \a folder. 734 objects to \a folder.
741*/ 735*/
742void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) 736void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
743{ 737{
744 QString homedocs = QString(getenv("HOME")) + "/Documents"; 738 QString homedocs = QString(getenv("HOME")) + "/Documents";
745 DocLnkSet d(homedocs,mimefilter); 739 DocLnkSet d(homedocs,mimefilter);
746 folder->appendFrom(d); 740 folder->appendFrom(d);
747 /** let's do intellegint way of searching these files 741 /** let's do intellegint way of searching these files
748 * a) the user don't want to check mediums global 742 * a) the user don't want to check mediums global
749 * b) the user wants to check but use the global options for it 743 * b) the user wants to check but use the global options for it
750 * c) the user wants to check it but not this medium 744 * c) the user wants to check it but not this medium
751 * d) the user wants to check and this medium as well 745 * d) the user wants to check and this medium as well
752 * 746 *
753 * In all cases we need to apply a different mimefilter to 747 * In all cases we need to apply a different mimefilter to
754 * the medium. 748 * the medium.
755 * a) mimefilter.isEmpty() we need to apply the responding filter 749 * a) mimefilter.isEmpty() we need to apply the responding filter
756 * either the global or the one on the medium 750 * either the global or the one on the medium
757 * 751 *
758 * b) mimefilter is set to an application we need to find out if the 752 * b) mimefilter is set to an application we need to find out if the
759 * mimetypes are included in the mime mask of the medium 753 * mimetypes are included in the mime mask of the medium
760 */ 754 */
761 StorageInfo storage; 755 StorageInfo storage;
762 const QList<FileSystem> &fs = storage.fileSystems(); 756 const QList<FileSystem> &fs = storage.fileSystems();
763 QListIterator<FileSystem> it ( fs ); 757 QListIterator<FileSystem> it ( fs );
764 for ( ; it.current(); ++it ) { 758 for ( ; it.current(); ++it ) {
765 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 759 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
766 // this is a candidate look at the cf and see if we should search on it 760 // this is a candidate look at the cf and see if we should search on it
767 QString path = (*it)->path(); 761 QString path = (*it)->path();
768 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) 762 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) )
769 continue; 763 continue;
770 DocLnkSet ide( path, mimefilter ); 764 DocLnkSet ide( path, mimefilter );
771 folder->appendFrom(ide); 765 folder->appendFrom(ide);
772 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { 766 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) {
773 QString path = (*it)->path() + "/Documents"; 767 QString path = (*it)->path() + "/Documents";
774 DocLnkSet ide( path, mimefilter ); 768 DocLnkSet ide( path, mimefilter );
775 folder->appendFrom(ide); 769 folder->appendFrom(ide);
776 } 770 }
777 } 771 }
778} 772}
779 773
780QStringList Global::languageList() 774QStringList Global::languageList()
781{ 775{
782 QString lang = getenv("LANG"); 776 QString lang = getenv("LANG");
783 QStringList langs; 777 QStringList langs;
784 langs.append(lang); 778 langs.append(lang);
785 int i = lang.find("."); 779 int i = lang.find(".");
786 if ( i > 0 ) 780 if ( i > 0 )
787 lang = lang.left( i ); 781 lang = lang.left( i );
788 i = lang.find( "_" ); 782 i = lang.find( "_" );
789 if ( i > 0 ) 783 if ( i > 0 )
790 langs.append(lang.left(i)); 784 langs.append(lang.left(i));
791 return langs; 785 return langs;
792} 786}
793 787
794QStringList Global::helpPath() 788QStringList Global::helpPath()
795{ 789{
796 QStringList path; 790 QStringList path;
797 QStringList langs = Global::languageList(); 791 QStringList langs = Global::languageList();
798 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { 792 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
799 QString lang = *it; 793 QString lang = *it;
800 if ( !lang.isEmpty() ) 794 if ( !lang.isEmpty() )
801 path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; 795 path += QPEApplication::qpeDir() + "/help/" + lang + "/html";
802 } 796 }
803 path += QPEApplication::qpeDir() + "/pics"; 797 path += QPEApplication::qpeDir() + "/pics";
804 path += QPEApplication::qpeDir() + "/help/html"; 798 path += QPEApplication::qpeDir() + "/help/html";
805 path += QPEApplication::qpeDir() + "/docs"; 799 path += QPEApplication::qpeDir() + "/docs";
806 800
807 801
808 return path; 802 return path;
809} 803}
810 804
811 805
812#include "global.moc" 806#include "global.moc"
diff --git a/library/ir.cpp b/library/ir.cpp
index a7cf7b1..b5b726d 100644
--- a/library/ir.cpp
+++ b/library/ir.cpp
@@ -1,120 +1,118 @@
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 <qstring.h> 23#include <qstring.h>
24#ifdef QWS
25#include "qcopenvelope_qws.h" 24#include "qcopenvelope_qws.h"
26#include <qcopchannel_qws.h> 25#include <qcopchannel_qws.h>
27#endif
28#include "applnk.h" 26#include "applnk.h"
29 27
30/*! 28/*!
31 \class Ir ir.h 29 \class Ir ir.h
32 \brief The Ir class implements basic support for sending objects over an 30 \brief The Ir class implements basic support for sending objects over an
33 infrared communication link. 31 infrared communication link.
34 32
35 Both \link doclnk.html DocLnk\endlink objects and files can be 33 Both \link doclnk.html DocLnk\endlink objects and files can be
36 sent to another device via the infrared link using the send() 34 sent to another device via the infrared link using the send()
37 function. When the send has completed the done() signal is 35 function. When the send has completed the done() signal is
38 emitted. 36 emitted.
39 37
40 The supported() function returns whether the device supports 38 The supported() function returns whether the device supports
41 infrared communication or not. 39 infrared communication or not.
42 40
43 \ingroup qtopiaemb 41 \ingroup qtopiaemb
44*/ 42*/
45 43
46/*! 44/*!
47 Constructs an Ir object. The \a parent and \a name classes are the 45 Constructs an Ir object. The \a parent and \a name classes are the
48 standard QObject parameters. 46 standard QObject parameters.
49*/ 47*/
50Ir::Ir( QObject *parent, const char *name ) 48Ir::Ir( QObject *parent, const char *name )
51 : QObject( parent, name ) 49 : QObject( parent, name )
52{ 50{
53#ifndef QT_NO_COP 51#ifndef QT_NO_COP
54 ch = new QCopChannel( "QPE/Obex" ); 52 ch = new QCopChannel( "QPE/Obex" );
55 connect( ch, SIGNAL(received(const QCString &, const QByteArray &)), 53 connect( ch, SIGNAL(received(const QCString &, const QByteArray &)),
56 this, SLOT(obexMessage( const QCString &, const QByteArray &)) ); 54 this, SLOT(obexMessage( const QCString &, const QByteArray &)) );
57#endif 55#endif
58} 56}
59 57
60/*! 58/*!
61 Returns TRUE if the system supports infrared communication; 59 Returns TRUE if the system supports infrared communication;
62 otherwise returns FALSE. 60 otherwise returns FALSE.
63*/ 61*/
64bool Ir::supported() 62bool Ir::supported()
65{ 63{
66#ifndef QT_NO_COP 64#ifndef QT_NO_COP
67 return QCopChannel::isRegistered( "QPE/Obex" ); 65 return QCopChannel::isRegistered( "QPE/Obex" );
68#endif 66#endif
69} 67}
70 68
71/*! 69/*!
72 Sends the object in file \a fn over the infrared link. The \a 70 Sends the object in file \a fn over the infrared link. The \a
73 description is used in the text shown to the user while sending 71 description is used in the text shown to the user while sending
74 is in progress. The optional \a mimetype parameter specifies the 72 is in progress. The optional \a mimetype parameter specifies the
75 mimetype of the object. If this parameter is not set, it is 73 mimetype of the object. If this parameter is not set, it is
76 determined by the the filename's suffix. 74 determined by the the filename's suffix.
77 75
78 \sa done() 76 \sa done()
79*/ 77*/
80void Ir::send( const QString &fn, const QString &description, const QString &mimetype) 78void Ir::send( const QString &fn, const QString &description, const QString &mimetype)
81{ 79{
82 if ( !filename.isEmpty() ) return; 80 if ( !filename.isEmpty() ) return;
83 filename = fn; 81 filename = fn;
84#ifndef QT_NO_COP 82#ifndef QT_NO_COP
85 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); 83 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
86 e << description << filename << mimetype; 84 e << description << filename << mimetype;
87#endif 85#endif
88} 86}
89 87
90/*! 88/*!
91 \overload 89 \overload
92 90
93 Uses the DocLnk::file() and DocLnk::type() of \a doc. 91 Uses the DocLnk::file() and DocLnk::type() of \a doc.
94 92
95 \sa done() 93 \sa done()
96*/ 94*/
97void Ir::send( const DocLnk &doc, const QString &description ) 95void Ir::send( const DocLnk &doc, const QString &description )
98{ 96{
99 send( doc.file(), description, doc.type() ); 97 send( doc.file(), description, doc.type() );
100} 98}
101 99
102/*! 100/*!
103 \fn Ir::done( Ir *ir ); 101 \fn Ir::done( Ir *ir );
104 102
105 This signal is emitted by \a ir, when the send comand has been processed. 103 This signal is emitted by \a ir, when the send comand has been processed.
106*/ 104*/
107 105
108/*!\internal 106/*!\internal
109 */ 107 */
110void Ir::obexMessage( const QCString &msg, const QByteArray &data) 108void Ir::obexMessage( const QCString &msg, const QByteArray &data)
111{ 109{
112 if ( msg == "done(QString)" ) { 110 if ( msg == "done(QString)" ) {
113 QString fn; 111 QString fn;
114 QDataStream stream( data, IO_ReadOnly ); 112 QDataStream stream( data, IO_ReadOnly );
115 stream >> fn; 113 stream >> fn;
116 if ( fn == filename ) 114 if ( fn == filename )
117 emit done( this ); 115 emit done( this );
118 } 116 }
119} 117}
120 118
diff --git a/library/lnkproperties.cpp b/library/lnkproperties.cpp
index 0b50bae..50cf5af 100644
--- a/library/lnkproperties.cpp
+++ b/library/lnkproperties.cpp
@@ -1,342 +1,340 @@
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#include "lnkproperties.h" 24#include "lnkproperties.h"
25#include "lnkproperties.h" 25#include "lnkproperties.h"
26#include "lnkpropertiesbase_p.h" 26#include "lnkpropertiesbase_p.h"
27#include "ir.h" 27#include "ir.h"
28 28
29#include <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
30#include <qpe/applnk.h> 30#include <qpe/applnk.h>
31#include <qpe/global.h> 31#include <qpe/global.h>
32#include <qpe/categorywidget.h> 32#include <qpe/categorywidget.h>
33#ifdef QWS
34#include <qpe/qcopenvelope_qws.h> 33#include <qpe/qcopenvelope_qws.h>
35#endif
36#include <qpe/filemanager.h> 34#include <qpe/filemanager.h>
37#include <qpe/config.h> 35#include <qpe/config.h>
38#include <qpe/storage.h> 36#include <qpe/storage.h>
39#include <qpe/qpemessagebox.h> 37#include <qpe/qpemessagebox.h>
40#include <qpe/mimetype.h> 38#include <qpe/mimetype.h>
41 39
42#include <qlineedit.h> 40#include <qlineedit.h>
43#include <qtoolbutton.h> 41#include <qtoolbutton.h>
44#include <qpushbutton.h> 42#include <qpushbutton.h>
45#include <qgroupbox.h> 43#include <qgroupbox.h>
46#include <qcheckbox.h> 44#include <qcheckbox.h>
47#include <qlabel.h> 45#include <qlabel.h>
48#include <qlayout.h> 46#include <qlayout.h>
49#include <qfile.h> 47#include <qfile.h>
50#include <qfileinfo.h> 48#include <qfileinfo.h>
51#include <qmessagebox.h> 49#include <qmessagebox.h>
52#include <qsize.h> 50#include <qsize.h>
53#include <qcombobox.h> 51#include <qcombobox.h>
54#include <qregexp.h> 52#include <qregexp.h>
55#include <qbuttongroup.h> 53#include <qbuttongroup.h>
56 54
57#include <stdlib.h> 55#include <stdlib.h>
58 56
59LnkProperties::LnkProperties( AppLnk* l, QWidget* parent ) 57LnkProperties::LnkProperties( AppLnk* l, QWidget* parent )
60 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 ) 58 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 )
61{ 59{
62 setCaption( tr("Properties") ); 60 setCaption( tr("Properties") );
63 61
64 QVBoxLayout *vbox = new QVBoxLayout( this ); 62 QVBoxLayout *vbox = new QVBoxLayout( this );
65 d = new LnkPropertiesBase( this ); 63 d = new LnkPropertiesBase( this );
66 vbox->add( d ); 64 vbox->add( d );
67 65
68 d->docname->setText(l->name()); 66 d->docname->setText(l->name());
69 QString inf; 67 QString inf;
70 if ( l->type().isEmpty() ) { 68 if ( l->type().isEmpty() ) {
71 d->type->hide(); 69 d->type->hide();
72 d->typeLabel->hide(); 70 d->typeLabel->hide();
73 } else { 71 } else {
74 d->type->setText( l->type() ); 72 d->type->setText( l->type() );
75 } 73 }
76 74
77 if ( l->comment().isEmpty() ) { 75 if ( l->comment().isEmpty() ) {
78 d->comment->hide(); 76 d->comment->hide();
79 d->commentLabel->hide(); 77 d->commentLabel->hide();
80 } else { 78 } else {
81 d->comment->setText( l->comment() ); 79 d->comment->setText( l->comment() );
82 } 80 }
83 81
84 connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk())); 82 connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk()));
85 if ( lnk->type().contains('/') ) { // A document? (#### better predicate needed) 83 if ( lnk->type().contains('/') ) { // A document? (#### better predicate needed)
86 connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk())); 84 connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk()));
87 connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk())); 85 connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk()));
88 86
89 d->docname->setReadOnly( FALSE ); 87 d->docname->setReadOnly( FALSE );
90 d->preload->hide(); 88 d->preload->hide();
91 d->rotate->hide(); 89 d->rotate->hide();
92 d->rotateButtons->hide(); 90 d->rotateButtons->hide();
93 d->labelspacer->hide(); 91 d->labelspacer->hide();
94 92
95 // ### THIS MUST GO, FIX WIERD BUG in QLAYOUT 93 // ### THIS MUST GO, FIX WIERD BUG in QLAYOUT
96 d->categoryEdit->kludge(); 94 d->categoryEdit->kludge();
97 95
98 d->categoryEdit->setCategories( lnk->categories(), 96 d->categoryEdit->setCategories( lnk->categories(),
99 "Document View", 97 "Document View",
100 tr("Document View") ); 98 tr("Document View") );
101 setupLocations(); 99 setupLocations();
102 } else { 100 } else {
103 d->unlink->hide(); 101 d->unlink->hide();
104 d->duplicate->hide(); 102 d->duplicate->hide();
105 d->beam->hide(); 103 d->beam->hide();
106 d->hline->hide(); 104 d->hline->hide();
107 d->locationLabel->hide(); 105 d->locationLabel->hide();
108 d->locationCombo->hide(); 106 d->locationCombo->hide();
109 107
110 // Can't edit categories, since the app .desktop files are global, 108 // Can't edit categories, since the app .desktop files are global,
111 // possibly read-only. 109 // possibly read-only.
112 d->categoryEdit->hide(); 110 d->categoryEdit->hide();
113 111
114 d->docname->setReadOnly( TRUE ); 112 d->docname->setReadOnly( TRUE );
115 113
116 if ( l->property("CanFastload") == "0" ) 114 if ( l->property("CanFastload") == "0" )
117 d->preload->hide(); 115 d->preload->hide();
118 if ( !l->property("Rotation"). isEmpty ()) { 116 if ( !l->property("Rotation"). isEmpty ()) {
119 d->rotate->setChecked ( true ); 117 d->rotate->setChecked ( true );
120 d->rotateButtons->setButton((l->rotation().toInt()%360)/90); 118 d->rotateButtons->setButton((l->rotation().toInt()%360)/90);
121 } 119 }
122 else { 120 else {
123 d->rotateButtons->setEnabled(false); 121 d->rotateButtons->setEnabled(false);
124 } 122 }
125 123
126 Config cfg("Launcher"); 124 Config cfg("Launcher");
127 cfg.setGroup("Preload"); 125 cfg.setGroup("Preload");
128 QStringList apps = cfg.readListEntry("Apps",','); 126 QStringList apps = cfg.readListEntry("Apps",',');
129 d->preload->setChecked( apps.contains(l->exec()) ); 127 d->preload->setChecked( apps.contains(l->exec()) );
130 if ( Global::isBuiltinCommand(lnk->exec()) ) 128 if ( Global::isBuiltinCommand(lnk->exec()) )
131 d->preload->hide(); // builtins are always fast 129 d->preload->hide(); // builtins are always fast
132 130
133 currentLocation = 0; // apps not movable (yet) 131 currentLocation = 0; // apps not movable (yet)
134 } 132 }
135} 133}
136 134
137LnkProperties::~LnkProperties() 135LnkProperties::~LnkProperties()
138{ 136{
139} 137}
140 138
141void LnkProperties::unlinkLnk() 139void LnkProperties::unlinkLnk()
142{ 140{
143 if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) { 141 if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) {
144 lnk->removeFiles(); 142 lnk->removeFiles();
145 if ( QFile::exists(lnk->file()) ) { 143 if ( QFile::exists(lnk->file()) ) {
146 QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") ); 144 QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") );
147 } else { 145 } else {
148 reject(); 146 reject();
149 } 147 }
150 } 148 }
151} 149}
152 150
153void LnkProperties::setupLocations() 151void LnkProperties::setupLocations()
154{ 152{
155 QFileInfo fi( lnk->file() ); 153 QFileInfo fi( lnk->file() );
156 fileSize = fi.size(); 154 fileSize = fi.size();
157 StorageInfo storage; 155 StorageInfo storage;
158 const QList<FileSystem> &fs = storage.fileSystems(); 156 const QList<FileSystem> &fs = storage.fileSystems();
159 QListIterator<FileSystem> it ( fs ); 157 QListIterator<FileSystem> it ( fs );
160 QString s; 158 QString s;
161 QString homeDir = getenv("HOME"); 159 QString homeDir = getenv("HOME");
162 QString hardDiskHome; 160 QString hardDiskHome;
163 QString hardDiskPath; 161 QString hardDiskPath;
164 int index = 0; 162 int index = 0;
165 currentLocation = -1; 163 currentLocation = -1;
166 for ( ; it.current(); ++it ) { 164 for ( ; it.current(); ++it ) {
167 // we add 10k to the file size so we are sure we can also save the desktop file 165 // we add 10k to the file size so we are sure we can also save the desktop file
168 if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) { 166 if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) {
169 if ( (*it)->isRemovable() || 167 if ( (*it)->isRemovable() ||
170 (*it)->disk() == "/dev/mtdblock1" || 168 (*it)->disk() == "/dev/mtdblock1" ||
171 (*it)->disk() == "/dev/mtdblock/1" || 169 (*it)->disk() == "/dev/mtdblock/1" ||
172 (*it)->disk().left(13) == "/dev/mtdblock" || 170 (*it)->disk().left(13) == "/dev/mtdblock" ||
173 (*it)->disk() == "/dev/mtdblock6" || 171 (*it)->disk() == "/dev/mtdblock6" ||
174 (*it)->disk() == "tmpfs" ) { 172 (*it)->disk() == "tmpfs" ) {
175 d->locationCombo->insertItem( (*it)->name(), index ); 173 d->locationCombo->insertItem( (*it)->name(), index );
176 locations.append( ( ((*it)->isRemovable() || 174 locations.append( ( ((*it)->isRemovable() ||
177 (*it)->disk() == "/dev/mtdblock6" || 175 (*it)->disk() == "/dev/mtdblock6" ||
178 (*it)->disk() == "tmpfs" ) 176 (*it)->disk() == "tmpfs" )
179 ? (*it)->path() : homeDir) ); 177 ? (*it)->path() : homeDir) );
180 if ( lnk->file().contains( (*it)->path() ) ) { 178 if ( lnk->file().contains( (*it)->path() ) ) {
181 d->locationCombo->setCurrentItem( index ); 179 d->locationCombo->setCurrentItem( index );
182 currentLocation = index; 180 currentLocation = index;
183 } 181 }
184 index++; 182 index++;
185 } else if ( (*it)->name().contains( tr("Hard Disk") ) && 183 } else if ( (*it)->name().contains( tr("Hard Disk") ) &&
186 homeDir.contains( (*it)->path() ) && 184 homeDir.contains( (*it)->path() ) &&
187 (*it)->path().length() > hardDiskHome.length() ) { 185 (*it)->path().length() > hardDiskHome.length() ) {
188 hardDiskHome = (*it)->name(); 186 hardDiskHome = (*it)->name();
189 hardDiskPath = (*it)->path(); 187 hardDiskPath = (*it)->path();
190 } 188 }
191 } 189 }
192 } 190 }
193 if ( !hardDiskHome.isEmpty() ) { 191 if ( !hardDiskHome.isEmpty() ) {
194 d->locationCombo->insertItem( hardDiskHome ); 192 d->locationCombo->insertItem( hardDiskHome );
195 locations.append( hardDiskPath ); 193 locations.append( hardDiskPath );
196 if ( currentLocation == -1 ) { // assume it's the hard disk 194 if ( currentLocation == -1 ) { // assume it's the hard disk
197 d->locationCombo->setCurrentItem( index ); 195 d->locationCombo->setCurrentItem( index );
198 currentLocation = index; 196 currentLocation = index;
199 } 197 }
200 } 198 }
201} 199}
202 200
203void LnkProperties::duplicateLnk() 201void LnkProperties::duplicateLnk()
204{ 202{
205 // The duplicate takes the new properties. 203 // The duplicate takes the new properties.
206 DocLnk newdoc( *((DocLnk *)lnk) ); 204 DocLnk newdoc( *((DocLnk *)lnk) );
207 if ( d->docname->text() == lnk->name() ) 205 if ( d->docname->text() == lnk->name() )
208 newdoc.setName(tr("Copy of ")+d->docname->text()); 206 newdoc.setName(tr("Copy of ")+d->docname->text());
209 else 207 else
210 newdoc.setName(d->docname->text()); 208 newdoc.setName(d->docname->text());
211 209
212 if ( !copyFile( newdoc ) ) { 210 if ( !copyFile( newdoc ) ) {
213 QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") ); 211 QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") );
214 return; 212 return;
215 } 213 }
216 reject(); 214 reject();
217} 215}
218 216
219bool LnkProperties::moveLnk() 217bool LnkProperties::moveLnk()
220{ 218{
221 DocLnk newdoc( *((DocLnk *)lnk) ); 219 DocLnk newdoc( *((DocLnk *)lnk) );
222 newdoc.setName(d->docname->text()); 220 newdoc.setName(d->docname->text());
223 221
224 if ( !copyFile( newdoc ) ) { 222 if ( !copyFile( newdoc ) ) {
225 QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") ); 223 QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") );
226 return FALSE; 224 return FALSE;
227 } 225 }
228 // remove old lnk 226 // remove old lnk
229 lnk->removeFiles(); 227 lnk->removeFiles();
230 228
231 return TRUE; 229 return TRUE;
232} 230}
233 231
234void LnkProperties::beamLnk() 232void LnkProperties::beamLnk()
235{ 233{
236 Ir ir; 234 Ir ir;
237 DocLnk doc( *((DocLnk *)lnk) ); 235 DocLnk doc( *((DocLnk *)lnk) );
238 doc.setName(d->docname->text()); 236 doc.setName(d->docname->text());
239 reject(); 237 reject();
240 ir.send( doc, doc.comment() ); 238 ir.send( doc, doc.comment() );
241} 239}
242 240
243bool LnkProperties::copyFile( DocLnk &newdoc ) 241bool LnkProperties::copyFile( DocLnk &newdoc )
244{ 242{
245 const char *linkExtn = ".desktop"; 243 const char *linkExtn = ".desktop";
246 QString fileExtn; 244 QString fileExtn;
247 int extnPos = lnk->file().findRev( '.' ); 245 int extnPos = lnk->file().findRev( '.' );
248 if ( extnPos > 0 ) 246 if ( extnPos > 0 )
249 fileExtn = lnk->file().mid( extnPos ); 247 fileExtn = lnk->file().mid( extnPos );
250 248
251 QString safename = newdoc.name(); 249 QString safename = newdoc.name();
252 safename.replace(QRegExp("/"),"_"); 250 safename.replace(QRegExp("/"),"_");
253 251
254 QString fn = locations[ d->locationCombo->currentItem() ] 252 QString fn = locations[ d->locationCombo->currentItem() ]
255 + "/Documents/" + newdoc.type() + "/" + safename; 253 + "/Documents/" + newdoc.type() + "/" + safename;
256 if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) { 254 if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) {
257 int n=1; 255 int n=1;
258 QString nn = fn + "_" + QString::number(n); 256 QString nn = fn + "_" + QString::number(n);
259 while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) { 257 while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) {
260 n++; 258 n++;
261 nn = fn + "_" + QString::number(n); 259 nn = fn + "_" + QString::number(n);
262 } 260 }
263 fn = nn; 261 fn = nn;
264 } 262 }
265 newdoc.setFile( fn + fileExtn ); 263 newdoc.setFile( fn + fileExtn );
266 newdoc.setLinkFile( fn + linkExtn ); 264 newdoc.setLinkFile( fn + linkExtn );
267 265
268 // Copy file 266 // Copy file
269 FileManager fm; 267 FileManager fm;
270 if ( !fm.copyFile( *lnk, newdoc ) ) 268 if ( !fm.copyFile( *lnk, newdoc ) )
271 return FALSE; 269 return FALSE;
272 return TRUE; 270 return TRUE;
273} 271}
274 272
275void LnkProperties::done(int ok) 273void LnkProperties::done(int ok)
276{ 274{
277 if ( ok ) { 275 if ( ok ) {
278 bool changed=FALSE; 276 bool changed=FALSE;
279 bool reloadMime=FALSE; 277 bool reloadMime=FALSE;
280 278
281 if ( lnk->name() != d->docname->text() ) { 279 if ( lnk->name() != d->docname->text() ) {
282 lnk->setName(d->docname->text()); 280 lnk->setName(d->docname->text());
283 changed=TRUE; 281 changed=TRUE;
284 } 282 }
285 if ( d->categoryEdit->isVisible() ) { 283 if ( d->categoryEdit->isVisible() ) {
286 QArray<int> tmp = d->categoryEdit->newCategories(); 284 QArray<int> tmp = d->categoryEdit->newCategories();
287 if ( lnk->categories() != tmp ) { 285 if ( lnk->categories() != tmp ) {
288 lnk->setCategories( tmp ); 286 lnk->setCategories( tmp );
289 changed = TRUE; 287 changed = TRUE;
290 } 288 }
291 } 289 }
292 if ( !d->rotate->isHidden()) { 290 if ( !d->rotate->isHidden()) {
293 QString newrot; 291 QString newrot;
294 292
295 if ( d->rotate->isChecked() ) { 293 if ( d->rotate->isChecked() ) {
296 int rot=0; 294 int rot=0;
297 for(; rot<4; rot++) { 295 for(; rot<4; rot++) {
298 if (d->rotateButtons->find(rot)->isOn()) 296 if (d->rotateButtons->find(rot)->isOn())
299 break; 297 break;
300 } 298 }
301 newrot = QString::number((rot*90)%360); 299 newrot = QString::number((rot*90)%360);
302 } 300 }
303 if ( newrot != lnk->rotation() ) { 301 if ( newrot != lnk->rotation() ) {
304 lnk-> setRotation(newrot); 302 lnk-> setRotation(newrot);
305 changed = TRUE; 303 changed = TRUE;
306 reloadMime = TRUE; 304 reloadMime = TRUE;
307 } 305 }
308 } 306 }
309 if ( d->preload->isHidden() && d->locationCombo->currentItem() != currentLocation ) { 307 if ( d->preload->isHidden() && d->locationCombo->currentItem() != currentLocation ) {
310 moveLnk(); 308 moveLnk();
311 } else if ( changed ) { 309 } else if ( changed ) {
312 lnk->writeLink(); 310 lnk->writeLink();
313 } 311 }
314 312
315 if ( !d->preload->isHidden() ) { 313 if ( !d->preload->isHidden() ) {
316 Config cfg("Launcher"); 314 Config cfg("Launcher");
317 cfg.setGroup("Preload"); 315 cfg.setGroup("Preload");
318 QStringList apps = cfg.readListEntry("Apps",','); 316 QStringList apps = cfg.readListEntry("Apps",',');
319 QString exe = lnk->exec(); 317 QString exe = lnk->exec();
320 if ( apps.contains(exe) != d->preload->isChecked() ) { 318 if ( apps.contains(exe) != d->preload->isChecked() ) {
321 if ( d->preload->isChecked() ) { 319 if ( d->preload->isChecked() ) {
322 apps.append(exe); 320 apps.append(exe);
323#ifndef QT_NO_COP 321#ifndef QT_NO_COP
324 QCopEnvelope e("QPE/Application/"+exe.local8Bit(), 322 QCopEnvelope e("QPE/Application/"+exe.local8Bit(),
325 "enablePreload()"); 323 "enablePreload()");
326#endif 324#endif
327 } else { 325 } else {
328 apps.remove(exe); 326 apps.remove(exe);
329#ifndef QT_NO_COP 327#ifndef QT_NO_COP
330 QCopEnvelope e("QPE/Application/"+exe.local8Bit(), 328 QCopEnvelope e("QPE/Application/"+exe.local8Bit(),
331 "quitIfInvisible()"); 329 "quitIfInvisible()");
332#endif 330#endif
333 } 331 }
334 cfg.writeEntry("Apps",apps,','); 332 cfg.writeEntry("Apps",apps,',');
335 } 333 }
336 } 334 }
337 if ( reloadMime ) 335 if ( reloadMime )
338 MimeType::updateApplications ( ); 336 MimeType::updateApplications ( );
339 } 337 }
340 QDialog::done( ok ); 338 QDialog::done( ok );
341} 339}
342 340
diff --git a/library/network.cpp b/library/network.cpp
index 185b147..3568809 100644
--- a/library/network.cpp
+++ b/library/network.cpp
@@ -1,446 +1,444 @@
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#ifdef QWS
29#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
30#endif
31#include <qpe/qlibrary.h> 29#include <qpe/qlibrary.h>
32 30
33#include <qlistbox.h> 31#include <qlistbox.h>
34#include <qdir.h> 32#include <qdir.h>
35#include <qlayout.h> 33#include <qlayout.h>
36#include <qdict.h> 34#include <qdict.h>
37#include <qtranslator.h> 35#include <qtranslator.h>
38 36
39#include <stdlib.h> 37#include <stdlib.h>
40 38
41#ifndef QT_NO_COP 39#ifndef QT_NO_COP
42class NetworkEmitter : public QCopChannel { 40class NetworkEmitter : public QCopChannel {
43 Q_OBJECT 41 Q_OBJECT
44public: 42public:
45 NetworkEmitter() : QCopChannel("QPE/Network",qApp) 43 NetworkEmitter() : QCopChannel("QPE/Network",qApp)
46 { 44 {
47 } 45 }
48 46
49 void receive(const QCString &msg, const QByteArray&) 47 void receive(const QCString &msg, const QByteArray&)
50 { 48 {
51 if ( msg == "choicesChanged()" ) 49 if ( msg == "choicesChanged()" )
52 emit changed(); 50 emit changed();
53 } 51 }
54 52
55signals: 53signals:
56 void changed(); 54 void changed();
57}; 55};
58 56
59/*! 57/*!
60 \internal 58 \internal
61 59
62 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
63 the password to use if required. 61 the password to use if required.
64*/ 62*/
65void Network::start(const QString& choice, const QString& password) 63void Network::start(const QString& choice, const QString& password)
66{ 64{
67 QCopEnvelope e("QPE/Network", "start(QString,QString)"); 65 QCopEnvelope e("QPE/Network", "start(QString,QString)");
68 e << choice << password; 66 e << choice << password;
69} 67}
70 68
71/*! 69/*!
72 \class Network network.h 70 \class Network network.h
73 \brief The Network class provides network access functionality. 71 \brief The Network class provides network access functionality.
74 \internal 72 \internal
75*/ 73*/
76 74
77// 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
78/*! 76/*!
79 \internal 77 \internal
80*/ 78*/
81void Network::writeProxySettings( Config &cfg ) 79void Network::writeProxySettings( Config &cfg )
82{ 80{
83 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File ); 81 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File );
84 proxy.setGroup("Properties"); 82 proxy.setGroup("Properties");
85 cfg.setGroup("Proxy"); 83 cfg.setGroup("Proxy");
86 proxy.writeEntry("type", cfg.readEntry("type") ); 84 proxy.writeEntry("type", cfg.readEntry("type") );
87 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") ); 85 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") );
88 proxy.writeEntry("httphost", cfg.readEntry("httphost") ); 86 proxy.writeEntry("httphost", cfg.readEntry("httphost") );
89 proxy.writeEntry("httpport", cfg.readEntry("httpport") ); 87 proxy.writeEntry("httpport", cfg.readEntry("httpport") );
90 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") ); 88 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") );
91 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") ); 89 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") );
92 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") ); 90 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") );
93 cfg.setGroup("Properties"); 91 cfg.setGroup("Properties");
94} 92}
95 93
96 94
97 95
98/*! 96/*!
99 \internal 97 \internal
100 98
101 Stops the current network service. 99 Stops the current network service.
102*/ 100*/
103void Network::stop() 101void Network::stop()
104{ 102{
105 QCopEnvelope e("QPE/Network", "stop()"); 103 QCopEnvelope e("QPE/Network", "stop()");
106} 104}
107 105
108static NetworkEmitter *emitter = 0; 106static NetworkEmitter *emitter = 0;
109 107
110/*! 108/*!
111 \internal 109 \internal
112*/ 110*/
113void Network::connectChoiceChange(QObject* receiver, const char* slot) 111void Network::connectChoiceChange(QObject* receiver, const char* slot)
114{ 112{
115 if ( !emitter ) 113 if ( !emitter )
116 emitter = new NetworkEmitter; 114 emitter = new NetworkEmitter;
117 QObject::connect(emitter,SIGNAL(changed()),receiver,slot); 115 QObject::connect(emitter,SIGNAL(changed()),receiver,slot);
118} 116}
119 117
120 #endif// QT_NO_COP 118 #endif// QT_NO_COP
121/*! 119/*!
122 \internal 120 \internal
123*/ 121*/
124QString Network::settingsDir() 122QString Network::settingsDir()
125{ 123{
126 return Global::applicationFileName("Network", "modules"); 124 return Global::applicationFileName("Network", "modules");
127} 125}
128 126
129#ifndef QT_NO_COP 127#ifndef QT_NO_COP
130/*! 128/*!
131 \internal 129 \internal
132*/ 130*/
133QStringList Network::choices(QListBox* lb, const QString& dir) 131QStringList Network::choices(QListBox* lb, const QString& dir)
134{ 132{
135 QStringList list; 133 QStringList list;
136 134
137 if ( lb ) 135 if ( lb )
138 lb->clear(); 136 lb->clear();
139 137
140 QString adir = dir.isEmpty() ? settingsDir() : dir; 138 QString adir = dir.isEmpty() ? settingsDir() : dir;
141 QDir settingsdir(adir); 139 QDir settingsdir(adir);
142 settingsdir.mkdir(adir); 140 settingsdir.mkdir(adir);
143 141
144 QStringList files = settingsdir.entryList("*.conf"); 142 QStringList files = settingsdir.entryList("*.conf");
145 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) { 143 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) {
146 QString filename = settingsdir.filePath(*it); 144 QString filename = settingsdir.filePath(*it);
147 Config cfg(filename, Config::File); 145 Config cfg(filename, Config::File);
148 cfg.setGroup("Info"); 146 cfg.setGroup("Info");
149 if ( lb ) 147 if ( lb )
150 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")), 148 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")),
151 cfg.readEntry("Name")); 149 cfg.readEntry("Name"));
152 list.append(filename); 150 list.append(filename);
153 } 151 }
154 152
155 return list; 153 return list;
156} 154}
157 155
158class NetworkServer : public QCopChannel { 156class NetworkServer : public QCopChannel {
159 Q_OBJECT 157 Q_OBJECT
160public: 158public:
161 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0) 159 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0)
162 { 160 {
163 up = FALSE; 161 up = FALSE;
164 examineNetworks( TRUE ); 162 examineNetworks( TRUE );
165 QCopChannel* card = new QCopChannel("QPE/Card",parent); 163 QCopChannel* card = new QCopChannel("QPE/Card",parent);
166 connect(card,SIGNAL(received(const QCString &, const QByteArray&)), 164 connect(card,SIGNAL(received(const QCString &, const QByteArray&)),
167 this,SLOT(cardMessage(const QCString &, const QByteArray&))); 165 this,SLOT(cardMessage(const QCString &, const QByteArray&)));
168 } 166 }
169 167
170 ~NetworkServer() 168 ~NetworkServer()
171 { 169 {
172 stop(); 170 stop();
173 } 171 }
174 172
175 bool networkOnline() const 173 bool networkOnline() const
176 { 174 {
177 return up; 175 return up;
178 } 176 }
179 177
180private: 178private:
181 void receive(const QCString &msg, const QByteArray& data) 179 void receive(const QCString &msg, const QByteArray& data)
182 { 180 {
183 if ( msg == "start(QString,QString)" ) { 181 if ( msg == "start(QString,QString)" ) {
184 QDataStream stream(data,IO_ReadOnly); 182 QDataStream stream(data,IO_ReadOnly);
185 QString file,password; 183 QString file,password;
186 stream >> file >> password; 184 stream >> file >> password;
187 if ( file.isEmpty() ) { 185 if ( file.isEmpty() ) {
188 QStringList l = Network::choices(); 186 QStringList l = Network::choices();
189 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) { 187 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) {
190 Config cfg(*i,Config::File); 188 Config cfg(*i,Config::File);
191 cfg.setGroup("Info"); 189 cfg.setGroup("Info");
192 QString type = cfg.readEntry("Type"); 190 QString type = cfg.readEntry("Type");
193 NetworkInterface* plugin = Network::loadPlugin(type); 191 NetworkInterface* plugin = Network::loadPlugin(type);
194 cfg.setGroup("Properties"); 192 cfg.setGroup("Properties");
195 if ( plugin && plugin->isAvailable(cfg) ) { 193 if ( plugin && plugin->isAvailable(cfg) ) {
196 file = *i; 194 file = *i;
197 break; 195 break;
198 } 196 }
199 } 197 }
200 if ( file.isEmpty() ) { 198 if ( file.isEmpty() ) {
201 QCopEnvelope("QPE/Network", "failed()"); 199 QCopEnvelope("QPE/Network", "failed()");
202 return; 200 return;
203 } 201 }
204 } 202 }
205 start(file,password); 203 start(file,password);
206 } else if ( msg == "stop()" ) { 204 } else if ( msg == "stop()" ) {
207 stop(); 205 stop();
208 } else if ( msg == "choicesChanged()" ) { 206 } else if ( msg == "choicesChanged()" ) {
209 examineNetworks(); 207 examineNetworks();
210 } 208 }
211 } 209 }
212 210
213private slots: 211private slots:
214 void cardMessage(const QCString &msg, const QByteArray&) 212 void cardMessage(const QCString &msg, const QByteArray&)
215 { 213 {
216 if ( msg == "stabChanged()" ) 214 if ( msg == "stabChanged()" )
217 examineNetworks(); 215 examineNetworks();
218 } 216 }
219 217
220private: 218private:
221 void examineNetworks( bool firstStart = FALSE ) 219 void examineNetworks( bool firstStart = FALSE )
222 { 220 {
223 QStringList l = Network::choices(); 221 QStringList l = Network::choices();
224 bool wasup = up; up=FALSE; 222 bool wasup = up; up=FALSE;
225 QStringList pavailable = available; 223 QStringList pavailable = available;
226 available.clear(); 224 available.clear();
227 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 225 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
228 Config cfg(*it,Config::File); 226 Config cfg(*it,Config::File);
229 cfg.setGroup("Info"); 227 cfg.setGroup("Info");
230 QString type = cfg.readEntry("Type"); 228 QString type = cfg.readEntry("Type");
231 NetworkInterface* plugin = Network::loadPlugin(type); 229 NetworkInterface* plugin = Network::loadPlugin(type);
232 cfg.setGroup("Properties"); 230 cfg.setGroup("Properties");
233 if ( plugin ) { 231 if ( plugin ) {
234 if ( plugin->isActive(cfg) ) { 232 if ( plugin->isActive(cfg) ) {
235 up = TRUE; 233 up = TRUE;
236 if ( firstStart ) 234 if ( firstStart )
237 plugin->start( cfg ); 235 plugin->start( cfg );
238 } 236 }
239 if ( plugin->isAvailable(cfg) ) 237 if ( plugin->isAvailable(cfg) )
240 available.append(*it); 238 available.append(*it);
241 } 239 }
242 } 240 }
243 241
244 // Try to work around unreproducible bug whereby 242 // Try to work around unreproducible bug whereby
245 // the netmon applet shows wrong state. 243 // the netmon applet shows wrong state.
246 bool reannounce = wait<0; 244 bool reannounce = wait<0;
247 245
248 if ( available != pavailable || reannounce ) { 246 if ( available != pavailable || reannounce ) {
249 QCopEnvelope e("QPE/Network", "available(QStringList)"); 247 QCopEnvelope e("QPE/Network", "available(QStringList)");
250 e << available; 248 e << available;
251 } 249 }
252 if ( up != wasup || reannounce ) { 250 if ( up != wasup || reannounce ) {
253 QCopEnvelope("QPE/Network", up ? "up()" : "down()"); 251 QCopEnvelope("QPE/Network", up ? "up()" : "down()");
254 } 252 }
255 } 253 }
256 254
257 void start( const QString& file, const QString& password ) 255 void start( const QString& file, const QString& password )
258 { 256 {
259 if ( !current.isEmpty() ) 257 if ( !current.isEmpty() )
260 stop(); 258 stop();
261 current = QString::null; 259 current = QString::null;
262 Config cfg(file, Config::File); 260 Config cfg(file, Config::File);
263 cfg.setGroup("Info"); 261 cfg.setGroup("Info");
264 QString type = cfg.readEntry("Type"); 262 QString type = cfg.readEntry("Type");
265 NetworkInterface* plugin = Network::loadPlugin(type); 263 NetworkInterface* plugin = Network::loadPlugin(type);
266 bool started = FALSE; 264 bool started = FALSE;
267 if ( plugin ) { 265 if ( plugin ) {
268 cfg.setGroup("Properties"); 266 cfg.setGroup("Properties");
269 if ( plugin->start(cfg,password) ) { 267 if ( plugin->start(cfg,password) ) {
270 Network::writeProxySettings( cfg ); 268 Network::writeProxySettings( cfg );
271 current = file; 269 current = file;
272 wait=0; 270 wait=0;
273 startTimer(400); 271 startTimer(400);
274 started = TRUE; 272 started = TRUE;
275 } 273 }
276 } 274 }
277 if ( !started ) { 275 if ( !started ) {
278 QCopEnvelope("QPE/Network", "failed()"); 276 QCopEnvelope("QPE/Network", "failed()");
279 } 277 }
280 } 278 }
281 279
282 void stop() 280 void stop()
283 { 281 {
284 bool stopped = FALSE; 282 bool stopped = FALSE;
285 if ( !current.isEmpty() ) { 283 if ( !current.isEmpty() ) {
286 Config cfg(current, Config::File); 284 Config cfg(current, Config::File);
287 cfg.setGroup("Info"); 285 cfg.setGroup("Info");
288 QString type = cfg.readEntry("Type"); 286 QString type = cfg.readEntry("Type");
289 NetworkInterface* plugin = Network::loadPlugin(type); 287 NetworkInterface* plugin = Network::loadPlugin(type);
290 if ( plugin ) { 288 if ( plugin ) {
291 cfg.setGroup("Properties"); 289 cfg.setGroup("Properties");
292 if ( plugin->stop(cfg) ) { 290 if ( plugin->stop(cfg) ) {
293 current = QString::null; 291 current = QString::null;
294 wait=0; 292 wait=0;
295 startTimer(400); 293 startTimer(400);
296 stopped = TRUE; 294 stopped = TRUE;
297 } 295 }
298 } 296 }
299 } 297 }
300 if ( !stopped ) { 298 if ( !stopped ) {
301 QCopEnvelope("QPE/Network", "failed()"); 299 QCopEnvelope("QPE/Network", "failed()");
302 } 300 }
303 } 301 }
304 302
305 void timerEvent(QTimerEvent*) 303 void timerEvent(QTimerEvent*)
306 { 304 {
307 examineNetworks(); 305 examineNetworks();
308 if ( wait >= 0 ) { 306 if ( wait >= 0 ) {
309 if ( up == !current.isNull() ) { 307 if ( up == !current.isNull() ) {
310 // done 308 // done
311 killTimers(); 309 killTimers();
312 if ( up ) { 310 if ( up ) {
313 startTimer(3000); // monitor link 311 startTimer(3000); // monitor link
314 wait = -1; 312 wait = -1;
315 } 313 }
316 } else { 314 } else {
317 wait++; 315 wait++;
318 if ( wait == 600 ) { 316 if ( wait == 600 ) {
319 killTimers(); // forget about it after 240 s 317 killTimers(); // forget about it after 240 s
320 QCopEnvelope("QPE/Network", "failed()"); 318 QCopEnvelope("QPE/Network", "failed()");
321 up = !current.isNull(); 319 up = !current.isNull();
322 } 320 }
323 } 321 }
324 } else if ( !up ) { 322 } else if ( !up ) {
325 killTimers(); 323 killTimers();
326 } 324 }
327 } 325 }
328 326
329private: 327private:
330 QStringList available; 328 QStringList available;
331 QString current; 329 QString current;
332 bool up; 330 bool up;
333 int wait; 331 int wait;
334}; 332};
335 333
336static NetworkServer* ns=0; 334static NetworkServer* ns=0;
337 335
338/*! 336/*!
339 \internal 337 \internal
340*/ 338*/
341QString Network::serviceName(const QString& service) 339QString Network::serviceName(const QString& service)
342{ 340{
343 Config cfg(service, Config::File); 341 Config cfg(service, Config::File);
344 cfg.setGroup("Info"); 342 cfg.setGroup("Info");
345 return cfg.readEntry("Name"); 343 return cfg.readEntry("Name");
346} 344}
347 345
348/*! 346/*!
349 \internal 347 \internal
350*/ 348*/
351QString Network::serviceType(const QString& service) 349QString Network::serviceType(const QString& service)
352{ 350{
353 Config cfg(service, Config::File); 351 Config cfg(service, Config::File);
354 cfg.setGroup("Info"); 352 cfg.setGroup("Info");
355 return cfg.readEntry("Type"); 353 return cfg.readEntry("Type");
356} 354}
357 355
358/*! 356/*!
359 \internal 357 \internal
360*/ 358*/
361bool Network::serviceNeedsPassword(const QString& service) 359bool Network::serviceNeedsPassword(const QString& service)
362{ 360{
363 Config cfg(service,Config::File); 361 Config cfg(service,Config::File);
364 cfg.setGroup("Info"); 362 cfg.setGroup("Info");
365 QString type = cfg.readEntry("Type"); 363 QString type = cfg.readEntry("Type");
366 NetworkInterface* plugin = Network::loadPlugin(type); 364 NetworkInterface* plugin = Network::loadPlugin(type);
367 cfg.setGroup("Properties"); 365 cfg.setGroup("Properties");
368 return plugin ? plugin->needPassword(cfg) : FALSE; 366 return plugin ? plugin->needPassword(cfg) : FALSE;
369} 367}
370 368
371/*! 369/*!
372 \internal 370 \internal
373*/ 371*/
374bool Network::networkOnline() 372bool Network::networkOnline()
375{ 373{
376 return ns && ns->networkOnline(); 374 return ns && ns->networkOnline();
377} 375}
378 376
379/*! 377/*!
380 \internal 378 \internal
381*/ 379*/
382void Network::createServer(QObject* parent) 380void Network::createServer(QObject* parent)
383{ 381{
384 ns = new NetworkServer(parent); 382 ns = new NetworkServer(parent);
385} 383}
386 384
387/*! 385/*!
388 \internal 386 \internal
389*/ 387*/
390int Network::addStateWidgets(QWidget* parent) 388int Network::addStateWidgets(QWidget* parent)
391{ 389{
392 int n=0; 390 int n=0;
393 QStringList l = Network::choices(); 391 QStringList l = Network::choices();
394 QVBoxLayout* vb = new QVBoxLayout(parent); 392 QVBoxLayout* vb = new QVBoxLayout(parent);
395 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 393 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
396 Config cfg(*it,Config::File); 394 Config cfg(*it,Config::File);
397 cfg.setGroup("Info"); 395 cfg.setGroup("Info");
398 QString type = cfg.readEntry("Type"); 396 QString type = cfg.readEntry("Type");
399 NetworkInterface* plugin = Network::loadPlugin(type); 397 NetworkInterface* plugin = Network::loadPlugin(type);
400 cfg.setGroup("Properties"); 398 cfg.setGroup("Properties");
401 if ( plugin ) { 399 if ( plugin ) {
402 QWidget* w; 400 QWidget* w;
403 if ( (w=plugin->addStateWidget(parent,cfg)) ) { 401 if ( (w=plugin->addStateWidget(parent,cfg)) ) {
404 n++; 402 n++;
405 vb->addWidget(w); 403 vb->addWidget(w);
406 } 404 }
407 } 405 }
408 } 406 }
409 return n; 407 return n;
410} 408}
411 409
412static QDict<NetworkInterface> *ifaces; 410static QDict<NetworkInterface> *ifaces;
413 411
414/*! 412/*!
415 \internal 413 \internal
416*/ 414*/
417NetworkInterface* Network::loadPlugin(const QString& type) 415NetworkInterface* Network::loadPlugin(const QString& type)
418{ 416{
419#ifndef QT_NO_COMPONENT 417#ifndef QT_NO_COMPONENT
420 if ( !ifaces ) ifaces = new QDict<NetworkInterface>; 418 if ( !ifaces ) ifaces = new QDict<NetworkInterface>;
421 NetworkInterface *iface = ifaces->find(type); 419 NetworkInterface *iface = ifaces->find(type);
422 if ( !iface ) { 420 if ( !iface ) {
423 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so"; 421 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so";
424 QLibrary lib(libfile); 422 QLibrary lib(libfile);
425 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK ) 423 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK )
426 return 0; 424 return 0;
427 ifaces->insert(type,iface); 425 ifaces->insert(type,iface);
428 QStringList langs = Global::languageList(); 426 QStringList langs = Global::languageList();
429 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 427 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
430 QString lang = *it; 428 QString lang = *it;
431 QTranslator * trans = new QTranslator(qApp); 429 QTranslator * trans = new QTranslator(qApp);
432 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm"; 430 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm";
433 if ( trans->load( tfn )) 431 if ( trans->load( tfn ))
434 qApp->installTranslator( trans ); 432 qApp->installTranslator( trans );
435 else 433 else
436 delete trans; 434 delete trans;
437 } 435 }
438 } 436 }
439 return iface; 437 return iface;
440#else 438#else
441 return 0; 439 return 0;
442#endif 440#endif
443} 441}
444 442
445#include "network.moc" 443#include "network.moc"
446 #endif// QT_NO_COP 444 #endif// QT_NO_COP
diff --git a/library/networkinterface.cpp b/library/networkinterface.cpp
index 2b5c77e..0ba773a 100644
--- a/library/networkinterface.cpp
+++ b/library/networkinterface.cpp
@@ -1,106 +1,104 @@
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 "networkinterface.h" 21#include "networkinterface.h"
22#include "network.h" 22#include "network.h"
23#include "config.h" 23#include "config.h"
24#include <stdio.h> 24#include <stdio.h>
25 25
26QString NetworkInterface::device( Config& cfg ) const 26QString NetworkInterface::device( Config& cfg ) const
27{ 27{
28 return cfg.readEntry("Device"); 28 return cfg.readEntry("Device");
29} 29}
30 30
31bool NetworkInterface::isActive( Config& cfg ) const 31bool NetworkInterface::isActive( Config& cfg ) const
32{ 32{
33 QString dev = device(cfg); 33 QString dev = device(cfg);
34 if ( dev.isEmpty() ) 34 if ( dev.isEmpty() )
35 return FALSE; 35 return FALSE;
36 QString dev0 = dev+'0'; 36 QString dev0 = dev+'0';
37 37
38 FILE* f; 38 FILE* f;
39 f = fopen("/proc/net/dev", "r"); 39 f = fopen("/proc/net/dev", "r");
40 if ( f ) { 40 if ( f ) {
41 char line[1024]; 41 char line[1024];
42 char devname[80]; 42 char devname[80];
43 while ( fgets( line, 1024, f ) ) { 43 while ( fgets( line, 1024, f ) ) {
44 if ( sscanf(line," %[^:]:", devname)==1 ) 44 if ( sscanf(line," %[^:]:", devname)==1 )
45 { 45 {
46 if ( devname == dev || devname == dev0 ) { 46 if ( devname == dev || devname == dev0 ) {
47 fclose(f); 47 fclose(f);
48#ifdef QWS
49 Network::writeProxySettings( cfg ); 48 Network::writeProxySettings( cfg );
50#endif
51 return TRUE; 49 return TRUE;
52 } 50 }
53 } 51 }
54 } 52 }
55 fclose(f); 53 fclose(f);
56 } 54 }
57 return FALSE; 55 return FALSE;
58} 56}
59 57
60QString NetworkInterface::cardType( Config& cfg ) const 58QString NetworkInterface::cardType( Config& cfg ) const
61{ 59{
62 return cfg.readEntry("CardType"); 60 return cfg.readEntry("CardType");
63} 61}
64 62
65bool NetworkInterface::isAvailable( Config& cfg ) const 63bool NetworkInterface::isAvailable( Config& cfg ) const
66{ 64{
67 QString ct = cardType(cfg); 65 QString ct = cardType(cfg);
68 if ( ct.isEmpty() ) 66 if ( ct.isEmpty() )
69 return FALSE; 67 return FALSE;
70 68
71 FILE* f = fopen("/var/run/stab", "r"); 69 FILE* f = fopen("/var/run/stab", "r");
72 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 70 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
73 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 71 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
74 72
75 if ( f ) { 73 if ( f ) {
76 char line[1024]; 74 char line[1024];
77 char devtype[80]; 75 char devtype[80];
78 while ( fgets( line, 1024, f ) ) { 76 while ( fgets( line, 1024, f ) ) {
79 if ( sscanf(line,"%*d %s %*s", devtype )==1 ) 77 if ( sscanf(line,"%*d %s %*s", devtype )==1 )
80 { 78 {
81 if ( ct == devtype ) { 79 if ( ct == devtype ) {
82 fclose(f); 80 fclose(f);
83 return TRUE; 81 return TRUE;
84 } 82 }
85 } 83 }
86 } 84 }
87 fclose(f); 85 fclose(f);
88 } 86 }
89 87
90 return FALSE; 88 return FALSE;
91} 89}
92 90
93bool NetworkInterface::start( Config& cfg, const QString& /*password*/ ) 91bool NetworkInterface::start( Config& cfg, const QString& /*password*/ )
94{ 92{
95 return start(cfg); 93 return start(cfg);
96} 94}
97 95
98bool NetworkInterface::needPassword( Config& ) const 96bool NetworkInterface::needPassword( Config& ) const
99{ 97{
100 return FALSE; 98 return FALSE;
101} 99}
102 100
103QWidget* NetworkInterface::addStateWidget( QWidget*, Config& ) const 101QWidget* NetworkInterface::addStateWidget( QWidget*, Config& ) const
104{ 102{
105 return 0; 103 return 0;
106} 104}
diff --git a/library/password.cpp b/library/password.cpp
index 41b3358..4b22b65 100644
--- a/library/password.cpp
+++ b/library/password.cpp
@@ -1,335 +1,333 @@
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 "password.h" 20#include "password.h"
21#include "config.h" 21#include "config.h"
22#include "global.h" 22#include "global.h"
23#include "backend/contact.h" 23#include "backend/contact.h"
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qlineedit.h> 25#include <qlineedit.h>
26#include <qtextview.h> 26#include <qtextview.h>
27#include <qstring.h> 27#include <qstring.h>
28#include <qapplication.h> 28#include <qapplication.h>
29#include <qfile.h> 29#include <qfile.h>
30#ifdef QWS
31#include <qwindowsystem_qws.h> 30#include <qwindowsystem_qws.h>
32#endif
33 31
34#include <qdialog.h> 32#include <qdialog.h>
35 33
36#include <unistd.h> //for sleep 34#include <unistd.h> //for sleep
37#include "passwordbase_p.h" 35#include "passwordbase_p.h"
38 36
39class PasswordDialog : public PasswordBase 37class PasswordDialog : public PasswordBase
40{ 38{
41 Q_OBJECT 39 Q_OBJECT
42 40
43public: 41public:
44 PasswordDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 42 PasswordDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
45 ~PasswordDialog(); 43 ~PasswordDialog();
46 44
47 void clear(); 45 void clear();
48 void setPrompt( const QString& ); 46 void setPrompt( const QString& );
49 47
50signals: 48signals:
51 void passwordEntered( const QString& ); 49 void passwordEntered( const QString& );
52 50
53protected: 51protected:
54 bool eventFilter( QObject*, QEvent* ); 52 bool eventFilter( QObject*, QEvent* );
55 void keyPressEvent( QKeyEvent * ); 53 void keyPressEvent( QKeyEvent * );
56 54
57private: 55private:
58 void input( QString ); 56 void input( QString );
59 friend class Password; 57 friend class Password;
60 QString text; 58 QString text;
61}; 59};
62 60
63 61
64extern "C" char *crypt(const char *key, const char *salt); 62extern "C" char *crypt(const char *key, const char *salt);
65static QString qcrypt(const QString& k, const char *salt) 63static QString qcrypt(const QString& k, const char *salt)
66{ 64{
67 return QString::fromUtf8(crypt(k.utf8(),salt)); 65 return QString::fromUtf8(crypt(k.utf8(),salt));
68} 66}
69 67
70/* 68/*
71 * Constructs a PasswordDialog which is a child of 'parent', with the 69 * Constructs a PasswordDialog which is a child of 'parent', with the
72 * name 'name' and widget flags set to 'f' 70 * name 'name' and widget flags set to 'f'
73 */ 71 */
74PasswordDialog::PasswordDialog( QWidget* parent, const char* name, WFlags fl ) 72PasswordDialog::PasswordDialog( QWidget* parent, const char* name, WFlags fl )
75 : PasswordBase( parent, name, fl ) 73 : PasswordBase( parent, name, fl )
76{ 74{
77 QRect desk = qApp->desktop()->geometry(); 75 QRect desk = qApp->desktop()->geometry();
78 76
79 if ( desk.width() < 220 ) { 77 if ( desk.width() < 220 ) {
80 QFont f( font() ); 78 QFont f( font() );
81 f.setPointSize( 18 ); 79 f.setPointSize( 18 );
82 setFont( f ); 80 setFont( f );
83 f.setPointSize( 12 ); 81 f.setPointSize( 12 );
84 prompt->setFont( f ); 82 prompt->setFont( f );
85 } 83 }
86 84
87 button_0->installEventFilter( this ); 85 button_0->installEventFilter( this );
88 button_1->installEventFilter( this ); 86 button_1->installEventFilter( this );
89 button_2->installEventFilter( this ); 87 button_2->installEventFilter( this );
90 button_3->installEventFilter( this ); 88 button_3->installEventFilter( this );
91 button_4->installEventFilter( this ); 89 button_4->installEventFilter( this );
92 button_5->installEventFilter( this ); 90 button_5->installEventFilter( this );
93 button_6->installEventFilter( this ); 91 button_6->installEventFilter( this );
94 button_7->installEventFilter( this ); 92 button_7->installEventFilter( this );
95 button_8->installEventFilter( this ); 93 button_8->installEventFilter( this );
96 button_9->installEventFilter( this ); 94 button_9->installEventFilter( this );
97 button_OK->installEventFilter( this ); 95 button_OK->installEventFilter( this );
98 setFocus(); 96 setFocus();
99} 97}
100 98
101/* 99/*
102 * Destroys the object and frees any allocated resources 100 * Destroys the object and frees any allocated resources
103 */ 101 */
104PasswordDialog::~PasswordDialog() 102PasswordDialog::~PasswordDialog()
105{ 103{
106 // no need to delete child widgets, Qt does it all for us 104 // no need to delete child widgets, Qt does it all for us
107} 105}
108 106
109 107
110 108
111/*! 109/*!
112 \reimp 110 \reimp
113*/ 111*/
114 112
115bool PasswordDialog::eventFilter( QObject*o, QEvent*e ) 113bool PasswordDialog::eventFilter( QObject*o, QEvent*e )
116{ 114{
117 if ( e->type() == QEvent::MouseButtonRelease ) { 115 if ( e->type() == QEvent::MouseButtonRelease ) {
118 if ( o == button_OK ) { 116 if ( o == button_OK ) {
119 emit passwordEntered( text ); 117 emit passwordEntered( text );
120 } else { 118 } else {
121 QLabel *l = (QLabel*)o; 119 QLabel *l = (QLabel*)o;
122 input(l->text()); 120 input(l->text());
123 } 121 }
124 } 122 }
125 return FALSE; 123 return FALSE;
126} 124}
127 125
128 126
129/*! 127/*!
130 \reimp 128 \reimp
131*/ 129*/
132 130
133void PasswordDialog::keyPressEvent( QKeyEvent * ) 131void PasswordDialog::keyPressEvent( QKeyEvent * )
134{ 132{
135#if 0 133#if 0
136 if ( e->key() == Key_Enter || e->key() == Key_Return ) 134 if ( e->key() == Key_Enter || e->key() == Key_Return )
137 emit passwordEntered( text ); 135 emit passwordEntered( text );
138 else 136 else
139 input( e->text() ); 137 input( e->text() );
140#endif 138#endif
141} 139}
142 140
143 141
144/*! 142/*!
145 143
146*/ 144*/
147 145
148void PasswordDialog::input( QString c ) 146void PasswordDialog::input( QString c )
149{ 147{
150 text += c; 148 text += c;
151 display->setText( text ); 149 display->setText( text );
152} 150}
153 151
154/*! 152/*!
155 153
156*/ 154*/
157 155
158void PasswordDialog::setPrompt( const QString& s ) 156void PasswordDialog::setPrompt( const QString& s )
159{ 157{
160 prompt->setText( s ); 158 prompt->setText( s );
161} 159}
162 160
163void PasswordDialog::clear() 161void PasswordDialog::clear()
164{ 162{
165 text = ""; 163 text = "";
166 input(""); 164 input("");
167} 165}
168 166
169class PasswdDlg : public QDialog 167class PasswdDlg : public QDialog
170{ 168{
171public: 169public:
172 PasswdDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE ) 170 PasswdDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE )
173 : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ), 171 : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ),
174 modl(modal) 172 modl(modal)
175 { 173 {
176 passw = new PasswordDialog( this ); 174 passw = new PasswordDialog( this );
177 175
178 if ( fullscreen ) { 176 if ( fullscreen ) {
179 QRect desk = qApp->desktop()->geometry(); 177 QRect desk = qApp->desktop()->geometry();
180 setGeometry( 0, 0, desk.width(), desk.height() ); 178 setGeometry( 0, 0, desk.width(), desk.height() );
181 } 179 }
182 180
183 connect( passw, SIGNAL(passwordEntered(const QString&)), 181 connect( passw, SIGNAL(passwordEntered(const QString&)),
184 this, SLOT(accept()) ); 182 this, SLOT(accept()) );
185 } 183 }
186 184
187 void resizeEvent( QResizeEvent * ) 185 void resizeEvent( QResizeEvent * )
188 { 186 {
189 passw->resize( size() ); 187 passw->resize( size() );
190 } 188 }
191 189
192 void reset() 190 void reset()
193 { 191 {
194 passw->clear(); 192 passw->clear();
195 } 193 }
196 194
197 void execNonModal() 195 void execNonModal()
198 { 196 {
199 if ( !modl ) { 197 if ( !modl ) {
200 reset(); 198 reset();
201 showFullScreen(); 199 showFullScreen();
202 do { 200 do {
203 qApp->enter_loop(); 201 qApp->enter_loop();
204 } while (result()!=1); 202 } while (result()!=1);
205 } 203 }
206 } 204 }
207 205
208 void accept() 206 void accept()
209 { 207 {
210 if ( !modl ) 208 if ( !modl )
211 qApp->exit_loop(); 209 qApp->exit_loop();
212 QDialog::accept(); 210 QDialog::accept();
213 } 211 }
214 212
215 PasswordDialog *passw; 213 PasswordDialog *passw;
216 bool modl; 214 bool modl;
217}; 215};
218 216
219class OwnerDlg : public QDialog 217class OwnerDlg : public QDialog
220{ 218{
221public: 219public:
222 220
223 OwnerDlg( QWidget *parent, const char * name, Contact c, 221 OwnerDlg( QWidget *parent, const char * name, Contact c,
224 bool modal, bool fullscreen = FALSE ) 222 bool modal, bool fullscreen = FALSE )
225 : QDialog( parent, name, modal, 223 : QDialog( parent, name, modal,
226 fullscreen ? 224 fullscreen ?
227 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ) 225 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 )
228 { 226 {
229 if ( fullscreen ) { 227 if ( fullscreen ) {
230 QRect desk = qApp->desktop()->geometry(); 228 QRect desk = qApp->desktop()->geometry();
231 setGeometry( 0, 0, desk.width(), desk.height() ); 229 setGeometry( 0, 0, desk.width(), desk.height() );
232 } 230 }
233 231
234 // set up contents. 232 // set up contents.
235 QString text = "<H1>" + tr("Owner Information") + "</H1>"; 233 QString text = "<H1>" + tr("Owner Information") + "</H1>";
236 text += c.toRichText(); 234 text += c.toRichText();
237 tv = new QTextView(this); 235 tv = new QTextView(this);
238 tv->setText(text); 236 tv->setText(text);
239 237
240 tv->viewport()->installEventFilter(this); 238 tv->viewport()->installEventFilter(this);
241 } 239 }
242 240
243 void resizeEvent( QResizeEvent * ) 241 void resizeEvent( QResizeEvent * )
244 { 242 {
245 tv->resize( size() ); 243 tv->resize( size() );
246 } 244 }
247 245
248 bool eventFilter(QObject *o, QEvent *e) 246 bool eventFilter(QObject *o, QEvent *e)
249 { 247 {
250 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) { 248 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) {
251 accept(); 249 accept();
252 return TRUE; 250 return TRUE;
253 } 251 }
254 return QWidget::eventFilter(o, e); 252 return QWidget::eventFilter(o, e);
255 } 253 }
256 254
257 void mousePressEvent( QMouseEvent * ) { accept(); } 255 void mousePressEvent( QMouseEvent * ) { accept(); }
258 256
259private: 257private:
260 QTextView *tv; 258 QTextView *tv;
261}; 259};
262 260
263/*! 261/*!
264 Returns a crypted password entered by the user when prompted with \a prompt 262 Returns a crypted password entered by the user when prompted with \a prompt
265 The returned value is QString::null if the user cancels the operation, 263 The returned value is QString::null if the user cancels the operation,
266 or the empty string if the user enters no password (but confirms the 264 or the empty string if the user enters no password (but confirms the
267 dialog). 265 dialog).
268*/ 266*/
269 267
270QString Password::getPassword( const QString& prompt ) 268QString Password::getPassword( const QString& prompt )
271{ 269{
272 PasswdDlg pd(0,0,TRUE); 270 PasswdDlg pd(0,0,TRUE);
273 pd.passw->setPrompt( prompt ); 271 pd.passw->setPrompt( prompt );
274 272
275 pd.showMaximized(); 273 pd.showMaximized();
276 int r = pd.exec(); 274 int r = pd.exec();
277 275
278 if ( r == QDialog::Accepted ) { 276 if ( r == QDialog::Accepted ) {
279 if (pd.passw->text.isEmpty()) 277 if (pd.passw->text.isEmpty())
280 return ""; 278 return "";
281 else 279 else
282 return qcrypt(pd.passw->text,"a0"); 280 return qcrypt(pd.passw->text,"a0");
283 } else { 281 } else {
284 return QString::null; 282 return QString::null;
285 } 283 }
286} 284}
287 285
288 286
289/*! 287/*!
290 Prompt, fullscreen, for the user's passcode until they get it right. 288 Prompt, fullscreen, for the user's passcode until they get it right.
291 289
292 If \a at_poweron is TRUE, the dialog is only used if the user's 290 If \a at_poweron is TRUE, the dialog is only used if the user's
293 preference request it at poweron; either way, the screen is always repainted 291 preference request it at poweron; either way, the screen is always repainted
294 by this function. (this functionality may move to the caller of this function). 292 by this function. (this functionality may move to the caller of this function).
295*/ 293*/
296 294
297void Password::authenticate(bool at_poweron) 295void Password::authenticate(bool at_poweron)
298{ 296{
299 Config cfg("Security"); 297 Config cfg("Security");
300 cfg.setGroup("Passcode"); 298 cfg.setGroup("Passcode");
301 QString passcode = cfg.readEntry("passcode"); 299 QString passcode = cfg.readEntry("passcode");
302 if ( !passcode.isEmpty() 300 if ( !passcode.isEmpty()
303 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) ) 301 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) )
304 { 302 {
305 // Do it as a fullscreen modal dialog 303 // Do it as a fullscreen modal dialog
306 PasswdDlg pd(0,0,TRUE,TRUE); 304 PasswdDlg pd(0,0,TRUE,TRUE);
307 305
308 // see if there is contact information. 306 // see if there is contact information.
309 OwnerDlg *oi = 0; 307 OwnerDlg *oi = 0;
310 QString vfilename = Global::applicationFileName("addressbook", 308 QString vfilename = Global::applicationFileName("addressbook",
311 "businesscard.vcf"); 309 "businesscard.vcf");
312 if (QFile::exists(vfilename)) { 310 if (QFile::exists(vfilename)) {
313 Contact c; 311 Contact c;
314 c = Contact::readVCard( vfilename )[0]; 312 c = Contact::readVCard( vfilename )[0];
315 313
316 oi = new OwnerDlg(0, 0, c, TRUE, TRUE); 314 oi = new OwnerDlg(0, 0, c, TRUE, TRUE);
317 } 315 }
318 316
319 pd.reset(); 317 pd.reset();
320 pd.exec(); 318 pd.exec();
321 while (qcrypt(pd.passw->text, "a0") != passcode) { 319 while (qcrypt(pd.passw->text, "a0") != passcode) {
322 if (oi) 320 if (oi)
323 oi->exec(); 321 oi->exec();
324 pd.reset(); 322 pd.reset();
325 pd.exec(); 323 pd.exec();
326 } 324 }
327 } else if ( at_poweron ) { 325 } else if ( at_poweron ) {
328 // refresh screen #### should probably be in caller 326 // refresh screen #### should probably be in caller
329 // Not needed (we took away the screen blacking) 327 // Not needed (we took away the screen blacking)
330 //if ( qwsServer ) 328 //if ( qwsServer )
331 //qwsServer->refresh(); 329 //qwsServer->refresh();
332 } 330 }
333} 331}
334 332
335#include "password.moc" 333#include "password.moc"
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index 214c721..9cbe92b 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -1,914 +1,912 @@
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#ifdef QWS
21#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
22#include <qapplication.h> 21#include <qapplication.h>
23#include <qstyle.h> 22#include <qstyle.h>
24#include <qwidget.h> 23#include <qwidget.h>
25#include <qpainter.h> 24#include <qpainter.h>
26#include <qtimer.h> 25#include <qtimer.h>
27#include <qwhatsthis.h> 26#include <qwhatsthis.h>
28#include "qcopenvelope_qws.h" 27#include "qcopenvelope_qws.h"
29#include "qpedecoration_qws.h" 28#include "qpedecoration_qws.h"
30#include <qdialog.h> 29#include <qdialog.h>
31#include <qdrawutil.h> 30#include <qdrawutil.h>
32#include <qgfx_qws.h> 31#include <qgfx_qws.h>
33#include "qpeapplication.h" 32#include "qpeapplication.h"
34#include "resource.h" 33#include "resource.h"
35#include "global.h" 34#include "global.h"
36#include "qlibrary.h" 35#include "qlibrary.h"
37#include "windowdecorationinterface.h" 36#include "windowdecorationinterface.h"
38#include <qfile.h> 37#include <qfile.h>
39#include <qsignal.h> 38#include <qsignal.h>
40 39
41#include <stdlib.h> 40#include <stdlib.h>
42 41
43extern QRect qt_maxWindowRect; 42extern QRect qt_maxWindowRect;
44 43
45#define WHATSTHIS_MODE 44#define WHATSTHIS_MODE
46 45
47#ifndef QT_NO_QWS_QPE_WM_STYLE 46#ifndef QT_NO_QWS_QPE_WM_STYLE
48 47
49#ifndef QT_NO_IMAGEIO_XPM 48#ifndef QT_NO_IMAGEIO_XPM
50 49
51/* XPM */ 50/* XPM */
52static const char * const qpe_close_xpm[] = { 51static const char * const qpe_close_xpm[] = {
53"16 16 3 1", 52"16 16 3 1",
54" c None", 53" c None",
55". c #FFFFFF", 54". c #FFFFFF",
56"+ c #000000", 55"+ c #000000",
57" ", 56" ",
58" ", 57" ",
59" ..... ", 58" ..... ",
60" ..+++++.. ", 59" ..+++++.. ",
61" .+++++++++. ", 60" .+++++++++. ",
62" .+..+++..+. ", 61" .+..+++..+. ",
63" .++...+...++. ", 62" .++...+...++. ",
64" .+++.....+++. ", 63" .+++.....+++. ",
65" .++++...++++. ", 64" .++++...++++. ",
66" .+++.....+++. ", 65" .+++.....+++. ",
67" .++...+...++. ", 66" .++...+...++. ",
68" .+..+++..+. ", 67" .+..+++..+. ",
69" .+++++++++. ", 68" .+++++++++. ",
70" ..+++++.. ", 69" ..+++++.. ",
71" ..... ", 70" ..... ",
72" "}; 71" "};
73 72
74/* XPM */ 73/* XPM */
75static const char * const qpe_accept_xpm[] = { 74static const char * const qpe_accept_xpm[] = {
76"16 16 3 1", 75"16 16 3 1",
77" c None", 76" c None",
78". c #FFFFFF", 77". c #FFFFFF",
79"+ c #000000", 78"+ c #000000",
80" ", 79" ",
81" ", 80" ",
82" ..... ", 81" ..... ",
83" ..+++++.. ", 82" ..+++++.. ",
84" .+++++++++. ", 83" .+++++++++. ",
85" .+++++++++. ", 84" .+++++++++. ",
86" .+++++++..++. ", 85" .+++++++..++. ",
87" .++.+++...++. ", 86" .++.+++...++. ",
88" .+...+...+++. ", 87" .+...+...+++. ",
89" .+......++++. ", 88" .+......++++. ",
90" .++....+++++. ", 89" .++....+++++. ",
91" .++..+++++. ", 90" .++..+++++. ",
92" .+++++++++. ", 91" .+++++++++. ",
93" ..+++++.. ", 92" ..+++++.. ",
94" ..... ", 93" ..... ",
95" "}; 94" "};
96 95
97#endif // QT_NO_IMAGEIO_XPM 96#endif // QT_NO_IMAGEIO_XPM
98 97
99class HackWidget : public QWidget 98class HackWidget : public QWidget
100{ 99{
101public: 100public:
102 bool needsOk() { 101 bool needsOk() {
103 return (getWState() & WState_Reserved1 ) || 102 return (getWState() & WState_Reserved1 ) ||
104 (inherits( "QDialog" ) && !inherits( "QMessageBox" ) ); 103 (inherits( "QDialog" ) && !inherits( "QMessageBox" ) );
105 } 104 }
106}; 105};
107 106
108static QImage scaleButton( const QImage &img, int height ) 107static QImage scaleButton( const QImage &img, int height )
109{ 108{
110 if ( img.height() != 0 && img.height() != height ) { 109 if ( img.height() != 0 && img.height() != height ) {
111 return img.smoothScale( img.width()*height/img.height(), height ); 110 return img.smoothScale( img.width()*height/img.height(), height );
112 } else { 111 } else {
113 return img; 112 return img;
114 } 113 }
115} 114}
116 115
117class TLWidget : public QWidget 116class TLWidget : public QWidget
118{ 117{
119public: 118public:
120 QWSManager *manager() 119 QWSManager *manager()
121 { 120 {
122 return topData()->qwsManager; 121 return topData()->qwsManager;
123 } 122 }
124 123
125 QTLWExtra *topExtra() 124 QTLWExtra *topExtra()
126 { 125 {
127 return topData(); 126 return topData();
128 } 127 }
129 128
130 void setWState( uint s ) { QWidget::setWState( s ); } 129 void setWState( uint s ) { QWidget::setWState( s ); }
131 void clearWState( uint s ) { QWidget::clearWState( s ); } 130 void clearWState( uint s ) { QWidget::clearWState( s ); }
132}; 131};
133 132
134 133
135QPEManager::QPEManager( QPEDecoration *d, QObject *parent ) 134QPEManager::QPEManager( QPEDecoration *d, QObject *parent )
136 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE) 135 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE)
137{ 136{
138 wtTimer = new QTimer( this ); 137 wtTimer = new QTimer( this );
139 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) ); 138 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) );
140} 139}
141 140
142 141
143void QPEManager::updateActive() 142void QPEManager::updateActive()
144{ 143{
145 QWidget *newActive = qApp->activeWindow(); 144 QWidget *newActive = qApp->activeWindow();
146 if ( newActive && (QWidget*)active == newActive ) 145 if ( newActive && (QWidget*)active == newActive )
147 return; 146 return;
148 147
149 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) { 148 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) {
150 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this ); 149 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this );
151 } 150 }
152 151
153 if ( newActive && ((TLWidget *)newActive)->manager() ) { 152 if ( newActive && ((TLWidget *)newActive)->manager() ) {
154 active = newActive; 153 active = newActive;
155 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this ); 154 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this );
156 } else if ( !newActive ) { 155 } else if ( !newActive ) {
157 active = 0; 156 active = 0;
158 } 157 }
159} 158}
160 159
161int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p ) 160int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p )
162{ 161{
163 QRect rect(w->geometry()); 162 QRect rect(w->geometry());
164 163
165 if ( decoration->region( w, rect, 164 if ( decoration->region( w, rect,
166 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) ) 165 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) )
167 return QPEDecoration::Help; 166 return QPEDecoration::Help;
168 167
169 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) { 168 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) {
170 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p)) 169 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p))
171 return (QWSDecoration::Region)i; 170 return (QWSDecoration::Region)i;
172 } 171 }
173 172
174 return QWSDecoration::None; 173 return QWSDecoration::None;
175} 174}
176 175
177bool QPEManager::eventFilter( QObject *o, QEvent *e ) 176bool QPEManager::eventFilter( QObject *o, QEvent *e )
178{ 177{
179 QWSManager *mgr = (QWSManager *)o; 178 QWSManager *mgr = (QWSManager *)o;
180 QWidget *w = mgr->widget(); 179 QWidget *w = mgr->widget();
181 switch ( e->type() ) { 180 switch ( e->type() ) {
182 case QEvent::MouseButtonPress: 181 case QEvent::MouseButtonPress:
183 { 182 {
184 pressTime = QTime::currentTime(); 183 pressTime = QTime::currentTime();
185 QPoint p = ((QMouseEvent*)e)->globalPos(); 184 QPoint p = ((QMouseEvent*)e)->globalPos();
186 int inRegion = pointInQpeRegion( w, p ); 185 int inRegion = pointInQpeRegion( w, p );
187#ifdef WHATSTHIS_MODE 186#ifdef WHATSTHIS_MODE
188 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) { 187 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) {
189 QString text; 188 QString text;
190 switch ( inRegion ) { 189 switch ( inRegion ) {
191 case QWSDecoration::Close: 190 case QWSDecoration::Close:
192 if ( ((HackWidget*)w)->needsOk() ) 191 if ( ((HackWidget*)w)->needsOk() )
193 text = tr("Click to close this window, discarding changes."); 192 text = tr("Click to close this window, discarding changes.");
194 else 193 else
195 text = tr("Click to close this window."); 194 text = tr("Click to close this window.");
196 break; 195 break;
197 case QWSDecoration::Minimize: 196 case QWSDecoration::Minimize:
198 text = tr("Click to close this window and apply changes."); 197 text = tr("Click to close this window and apply changes.");
199 break; 198 break;
200 case QWSDecoration::Maximize: 199 case QWSDecoration::Maximize:
201 if ( w->isMaximized() ) 200 if ( w->isMaximized() )
202 text = tr("Click to make this window moveable."); 201 text = tr("Click to make this window moveable.");
203 else 202 else
204 text = tr("Click to make this window use all available screen area."); 203 text = tr("Click to make this window use all available screen area.");
205 break; 204 break;
206 default: 205 default:
207 break; 206 break;
208 } 207 }
209 QWhatsThis::leaveWhatsThisMode( text ); 208 QWhatsThis::leaveWhatsThisMode( text );
210 whatsThisTimeout(); 209 whatsThisTimeout();
211 helpState = 0; 210 helpState = 0;
212 return true; 211 return true;
213 } 212 }
214#endif 213#endif
215 if ( inRegion == QPEDecoration::Help ) { 214 if ( inRegion == QPEDecoration::Help ) {
216#ifdef WHATSTHIS_MODE 215#ifdef WHATSTHIS_MODE
217 wtTimer->start( 400, TRUE ); 216 wtTimer->start( 400, TRUE );
218#endif 217#endif
219 helpState = QWSButton::Clicked|QWSButton::MouseOver; 218 helpState = QWSButton::Clicked|QWSButton::MouseOver;
220 drawButton( w, QPEDecoration::Help, helpState ); 219 drawButton( w, QPEDecoration::Help, helpState );
221 return true; 220 return true;
222 } 221 }
223 } 222 }
224 break; 223 break;
225 case QEvent::MouseButtonRelease: 224 case QEvent::MouseButtonRelease:
226 if ( helpState & QWSButton::Clicked ) { 225 if ( helpState & QWSButton::Clicked ) {
227 wtTimer->stop(); 226 wtTimer->stop();
228 helpState = 0; 227 helpState = 0;
229 drawButton( w, QPEDecoration::Help, helpState ); 228 drawButton( w, QPEDecoration::Help, helpState );
230 QPoint p = ((QMouseEvent*)e)->globalPos(); 229 QPoint p = ((QMouseEvent*)e)->globalPos();
231 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 230 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
232 decoration->help( w ); 231 decoration->help( w );
233 } 232 }
234 return true; 233 return true;
235 } 234 }
236 break; 235 break;
237 case QEvent::MouseMove: 236 case QEvent::MouseMove:
238 if ( helpState & QWSButton::Clicked ) { 237 if ( helpState & QWSButton::Clicked ) {
239 int oldState = helpState; 238 int oldState = helpState;
240 QPoint p = ((QMouseEvent*)e)->globalPos(); 239 QPoint p = ((QMouseEvent*)e)->globalPos();
241 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 240 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
242 helpState = QWSButton::Clicked|QWSButton::MouseOver; 241 helpState = QWSButton::Clicked|QWSButton::MouseOver;
243 } else { 242 } else {
244 helpState = 0; 243 helpState = 0;
245 } 244 }
246 if ( helpState != oldState ) 245 if ( helpState != oldState )
247 drawButton( w, QPEDecoration::Help, helpState ); 246 drawButton( w, QPEDecoration::Help, helpState );
248 } 247 }
249 break; 248 break;
250 default: 249 default:
251 break; 250 break;
252 } 251 }
253 return QObject::eventFilter( o, e ); 252 return QObject::eventFilter( o, e );
254} 253}
255 254
256void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ) 255void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state )
257{ 256{
258 QPainter painter(w); 257 QPainter painter(w);
259 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 258 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
260 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 259 painter.internalGfx()->setWidgetDeviceRegion( rgn );
261 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 260 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
262 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state ); 261 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state );
263} 262}
264 263
265void QPEManager::drawTitle( QWidget *w ) 264void QPEManager::drawTitle( QWidget *w )
266{ 265{
267 QPainter painter(w); 266 QPainter painter(w);
268 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 267 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
269 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 268 painter.internalGfx()->setWidgetDeviceRegion( rgn );
270 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 269 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
271 decoration->paint( &painter, w ); 270 decoration->paint( &painter, w );
272 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0); 271 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0);
273 decoration->paintButton(&painter, w, QWSDecoration::Close, 0); 272 decoration->paintButton(&painter, w, QWSDecoration::Close, 0);
274 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0); 273 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0);
275 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0); 274 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0);
276} 275}
277 276
278void QPEManager::whatsThisTimeout() 277void QPEManager::whatsThisTimeout()
279{ 278{
280 if ( !QWhatsThis::inWhatsThisMode() ) { 279 if ( !QWhatsThis::inWhatsThisMode() ) {
281 if ( inWhatsThis ) { 280 if ( inWhatsThis ) {
282 if ( whatsThis ) { 281 if ( whatsThis ) {
283 QWidget *w = whatsThis; 282 QWidget *w = whatsThis;
284 whatsThis = 0; 283 whatsThis = 0;
285 drawTitle( w ); 284 drawTitle( w );
286 } 285 }
287 wtTimer->stop(); 286 wtTimer->stop();
288 } else { 287 } else {
289 QWhatsThis::enterWhatsThisMode(); 288 QWhatsThis::enterWhatsThisMode();
290 helpState = 0; 289 helpState = 0;
291 updateActive(); 290 updateActive();
292 if ( active ) { 291 if ( active ) {
293 whatsThis = active; 292 whatsThis = active;
294 drawTitle( active ); 293 drawTitle( active );
295 // check periodically to see if we've left whats this mode 294 // check periodically to see if we've left whats this mode
296 wtTimer->start( 250 ); 295 wtTimer->start( 250 );
297 } 296 }
298 } 297 }
299 inWhatsThis = !inWhatsThis; 298 inWhatsThis = !inWhatsThis;
300 } 299 }
301} 300}
302 301
303//=========================================================================== 302//===========================================================================
304 303
305static QImage *okImage( int th ) 304static QImage *okImage( int th )
306{ 305{
307 static QImage *i = 0; 306 static QImage *i = 0;
308 if ( !i || i->height() != th ) { 307 if ( !i || i->height() != th ) {
309 delete i; 308 delete i;
310 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th)); 309 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th));
311 } 310 }
312 return i; 311 return i;
313} 312}
314 313
315static QImage *closeImage( int th ) 314static QImage *closeImage( int th )
316{ 315{
317 static QImage *i = 0; 316 static QImage *i = 0;
318 if ( !i || i->height() != th ) { 317 if ( !i || i->height() != th ) {
319 delete i; 318 delete i;
320 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th)); 319 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th));
321 } 320 }
322 return i; 321 return i;
323} 322}
324 323
325static QImage *helpImage( int th ) 324static QImage *helpImage( int th )
326{ 325{
327 static QImage *i = 0; 326 static QImage *i = 0;
328 if ( !i || i->height() != th ) { 327 if ( !i || i->height() != th ) {
329 delete i; 328 delete i;
330 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th)); 329 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th));
331 } 330 }
332 return i; 331 return i;
333} 332}
334 333
335static QImage *maximizeImage( int th ) 334static QImage *maximizeImage( int th )
336{ 335{
337 static QImage *i = 0; 336 static QImage *i = 0;
338 if ( !i || i->height() != th ) { 337 if ( !i || i->height() != th ) {
339 delete i; 338 delete i;
340 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th)); 339 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th));
341 } 340 }
342 return i; 341 return i;
343} 342}
344 343
345int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const 344int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const
346{ 345{
347 switch ( m ) { 346 switch ( m ) {
348 case TitleHeight: 347 case TitleHeight:
349 if ( QApplication::desktop()->height() > 320 ) 348 if ( QApplication::desktop()->height() > 320 )
350 return 19; 349 return 19;
351 else 350 else
352 return 15; 351 return 15;
353 case LeftBorder: 352 case LeftBorder:
354 case RightBorder: 353 case RightBorder:
355 case TopBorder: 354 case TopBorder:
356 case BottomBorder: 355 case BottomBorder:
357 return 4; 356 return 4;
358 case OKWidth: 357 case OKWidth:
359 return okImage(metric(TitleHeight,wd))->width(); 358 return okImage(metric(TitleHeight,wd))->width();
360 case CloseWidth: 359 case CloseWidth:
361 return closeImage(metric(TitleHeight,wd))->width(); 360 return closeImage(metric(TitleHeight,wd))->width();
362 case HelpWidth: 361 case HelpWidth:
363 return helpImage(metric(TitleHeight,wd))->width(); 362 return helpImage(metric(TitleHeight,wd))->width();
364 case MaximizeWidth: 363 case MaximizeWidth:
365 return maximizeImage(metric(TitleHeight,wd))->width(); 364 return maximizeImage(metric(TitleHeight,wd))->width();
366 case CornerGrabSize: 365 case CornerGrabSize:
367 return 16; 366 return 16;
368 } 367 }
369 368
370 return 0; 369 return 0;
371} 370}
372 371
373void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const 372void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const
374{ 373{
375 int th = metric( TitleHeight, wd ); 374 int th = metric( TitleHeight, wd );
376 QRect r = wd->rect; 375 QRect r = wd->rect;
377 376
378 switch ( a ) { 377 switch ( a ) {
379 case Border: 378 case Border:
380 { 379 {
381 const QColorGroup &cg = wd->palette.active(); 380 const QColorGroup &cg = wd->palette.active();
382 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd), 381 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd),
383 r.y()-th-metric(TopBorder,wd), 382 r.y()-th-metric(TopBorder,wd),
384 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd), 383 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd),
385 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd), 384 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd),
386 cg, FALSE, &cg.brush(QColorGroup::Background)); 385 cg, FALSE, &cg.brush(QColorGroup::Background));
387 } 386 }
388 break; 387 break;
389 case Title: 388 case Title:
390 { 389 {
391 const QColorGroup &cg = wd->palette.active(); 390 const QColorGroup &cg = wd->palette.active();
392 QBrush titleBrush; 391 QBrush titleBrush;
393 QPen titleLines; 392 QPen titleLines;
394 393
395 if ( wd->flags & WindowData::Active ) { 394 if ( wd->flags & WindowData::Active ) {
396 titleBrush = cg.brush(QColorGroup::Highlight); 395 titleBrush = cg.brush(QColorGroup::Highlight);
397 titleLines = titleBrush.color().dark(); 396 titleLines = titleBrush.color().dark();
398 } else { 397 } else {
399 titleBrush = cg.brush(QColorGroup::Background); 398 titleBrush = cg.brush(QColorGroup::Background);
400 titleLines = titleBrush.color(); 399 titleLines = titleBrush.color();
401 } 400 }
402 401
403 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush); 402 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush);
404 403
405 p->setPen( titleLines ); 404 p->setPen( titleLines );
406 for ( int i = r.y()-th; i < r.y(); i += 2 ) 405 for ( int i = r.y()-th; i < r.y(); i += 2 )
407 p->drawLine( r.left(), i, r.right(), i ); 406 p->drawLine( r.left(), i, r.right(), i );
408 } 407 }
409 break; 408 break;
410 case TitleText: 409 case TitleText:
411 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th, 410 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th,
412 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd), 411 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd),
413 th, QPainter::AlignVCenter, wd->caption); 412 th, QPainter::AlignVCenter, wd->caption);
414 break; 413 break;
415 } 414 }
416} 415}
417 416
418void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const 417void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const
419{ 418{
420 QImage *img = 0; 419 QImage *img = 0;
421 switch ( b ) { 420 switch ( b ) {
422 case OK: 421 case OK:
423 img = okImage(metric(TitleHeight,wd)); 422 img = okImage(metric(TitleHeight,wd));
424 break; 423 break;
425 case Close: 424 case Close:
426 img = closeImage(metric(TitleHeight,wd)); 425 img = closeImage(metric(TitleHeight,wd));
427 break; 426 break;
428 case Help: 427 case Help:
429 img = helpImage(metric(TitleHeight,wd)); 428 img = helpImage(metric(TitleHeight,wd));
430 break; 429 break;
431 case Maximize: 430 case Maximize:
432 img = maximizeImage(metric(TitleHeight,wd)); 431 img = maximizeImage(metric(TitleHeight,wd));
433 break; 432 break;
434 } 433 }
435 434
436 if ( img ) { 435 if ( img ) {
437 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) 436 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked))
438 p->drawImage(x+2, y+2, *img); 437 p->drawImage(x+2, y+2, *img);
439 else 438 else
440 p->drawImage(x+1, y+1, *img); 439 p->drawImage(x+1, y+1, *img);
441 } 440 }
442} 441}
443 442
444QRegion WindowDecorationInterface::mask( const WindowData *wd ) const 443QRegion WindowDecorationInterface::mask( const WindowData *wd ) const
445{ 444{
446 int th = metric(TitleHeight,wd); 445 int th = metric(TitleHeight,wd);
447 QRect rect( wd->rect ); 446 QRect rect( wd->rect );
448 QRect r(rect.left() - metric(LeftBorder,wd), 447 QRect r(rect.left() - metric(LeftBorder,wd),
449 rect.top() - th - metric(TopBorder,wd), 448 rect.top() - th - metric(TopBorder,wd),
450 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd), 449 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd),
451 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd)); 450 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd));
452 return QRegion(r) - rect; 451 return QRegion(r) - rect;
453} 452}
454 453
455class DefaultWindowDecoration : public WindowDecorationInterface 454class DefaultWindowDecoration : public WindowDecorationInterface
456{ 455{
457public: 456public:
458 DefaultWindowDecoration() : ref(0) {} 457 DefaultWindowDecoration() : ref(0) {}
459 QString name() const { 458 QString name() const {
460 return "Default"; 459 return "Default";
461 } 460 }
462 QPixmap icon() const { 461 QPixmap icon() const {
463 return QPixmap(); 462 return QPixmap();
464 } 463 }
465 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { 464 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
466 *iface = 0; 465 *iface = 0;
467 if ( uuid == IID_QUnknown ) 466 if ( uuid == IID_QUnknown )
468 *iface = this; 467 *iface = this;
469 else if ( uuid == IID_WindowDecoration ) 468 else if ( uuid == IID_WindowDecoration )
470 *iface = this; 469 *iface = this;
471 470
472 if ( *iface ) 471 if ( *iface )
473 (*iface)->addRef(); 472 (*iface)->addRef();
474 return QS_OK; 473 return QS_OK;
475 } 474 }
476 Q_REFCOUNT 475 Q_REFCOUNT
477 476
478private: 477private:
479 ulong ref; 478 ulong ref;
480}; 479};
481 480
482static WindowDecorationInterface *wdiface = 0; 481static WindowDecorationInterface *wdiface = 0;
483static QLibrary *wdlib = 0; 482static QLibrary *wdlib = 0;
484 483
485//=========================================================================== 484//===========================================================================
486 485
487QPEDecoration::QPEDecoration() 486QPEDecoration::QPEDecoration()
488 : QWSDefaultDecoration() 487 : QWSDefaultDecoration()
489{ 488{
490 if ( wdlib ) { 489 if ( wdlib ) {
491 wdiface->release(); 490 wdiface->release();
492 wdlib->unload(); 491 wdlib->unload();
493 delete wdlib; 492 delete wdlib;
494 wdlib = 0; 493 wdlib = 0;
495 } else { 494 } else {
496 delete wdiface; 495 delete wdiface;
497 } 496 }
498 wdiface = new DefaultWindowDecoration; 497 wdiface = new DefaultWindowDecoration;
499 498
500 helpFile = QString(qApp->argv()[0]) + ".html"; 499 helpFile = QString(qApp->argv()[0]) + ".html";
501 QStringList helpPath = Global::helpPath(); 500 QStringList helpPath = Global::helpPath();
502 helpExists = FALSE; 501 helpExists = FALSE;
503 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) { 502 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) {
504 helpExists = QFile::exists( *it + "/" + helpFile ); 503 helpExists = QFile::exists( *it + "/" + helpFile );
505 qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); 504 qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists);
506 } 505 }
507 qpeManager = new QPEManager( this ); 506 qpeManager = new QPEManager( this );
508} 507}
509 508
510QPEDecoration::QPEDecoration( const QString &plugin ) 509QPEDecoration::QPEDecoration( const QString &plugin )
511 : QWSDefaultDecoration() 510 : QWSDefaultDecoration()
512{ 511{
513 if ( wdlib ) { 512 if ( wdlib ) {
514 wdiface->release(); 513 wdiface->release();
515 wdlib->unload(); 514 wdlib->unload();
516 delete wdlib; 515 delete wdlib;
517 wdlib = 0; 516 wdlib = 0;
518 } else { 517 } else {
519 delete wdiface; 518 delete wdiface;
520 } 519 }
521 WindowDecorationInterface *iface = 0; 520 WindowDecorationInterface *iface = 0;
522 QString path = QPEApplication::qpeDir() + "/plugins/decorations"; 521 QString path = QPEApplication::qpeDir() + "/plugins/decorations";
523 QLibrary *lib = new QLibrary( path + "/" + plugin ); 522 QLibrary *lib = new QLibrary( path + "/" + plugin );
524 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 523 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
525 wdiface = iface; 524 wdiface = iface;
526 wdlib = lib; 525 wdlib = lib;
527 } else { 526 } else {
528 delete lib; 527 delete lib;
529 wdiface = new DefaultWindowDecoration; 528 wdiface = new DefaultWindowDecoration;
530 } 529 }
531 530
532 helpFile = QString(qApp->argv()[0]) + ".html"; 531 helpFile = QString(qApp->argv()[0]) + ".html";
533 QStringList helpPath = Global::helpPath(); 532 QStringList helpPath = Global::helpPath();
534 helpExists = FALSE; 533 helpExists = FALSE;
535 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) { 534 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) {
536 helpExists = QFile::exists( *it + "/" + helpFile ); 535 helpExists = QFile::exists( *it + "/" + helpFile );
537 qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); } 536 qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); }
538 qpeManager = new QPEManager( this ); 537 qpeManager = new QPEManager( this );
539} 538}
540 539
541QPEDecoration::~QPEDecoration() 540QPEDecoration::~QPEDecoration()
542{ 541{
543 delete qpeManager; 542 delete qpeManager;
544} 543}
545 544
546const char **QPEDecoration::menuPixmap() 545const char **QPEDecoration::menuPixmap()
547{ 546{
548 return (const char **)0; 547 return (const char **)0;
549} 548}
550 549
551const char **QPEDecoration::closePixmap() 550const char **QPEDecoration::closePixmap()
552{ 551{
553 return (const char **)qpe_close_xpm; 552 return (const char **)qpe_close_xpm;
554} 553}
555 554
556const char **QPEDecoration::minimizePixmap() 555const char **QPEDecoration::minimizePixmap()
557{ 556{
558 return (const char **)qpe_accept_xpm; 557 return (const char **)qpe_accept_xpm;
559} 558}
560 559
561const char **QPEDecoration::maximizePixmap() 560const char **QPEDecoration::maximizePixmap()
562{ 561{
563 return (const char **)0; 562 return (const char **)0;
564} 563}
565 564
566const char **QPEDecoration::normalizePixmap() 565const char **QPEDecoration::normalizePixmap()
567{ 566{
568 return (const char **)0; 567 return (const char **)0;
569} 568}
570 569
571int QPEDecoration::getTitleHeight( const QWidget *w ) 570int QPEDecoration::getTitleHeight( const QWidget *w )
572{ 571{
573 WindowDecorationInterface::WindowData wd; 572 WindowDecorationInterface::WindowData wd;
574 windowData( w, wd ); 573 windowData( w, wd );
575 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 574 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
576} 575}
577 576
578/* 577/*
579 If rect is empty, no frame is added. (a hack, really) 578 If rect is empty, no frame is added. (a hack, really)
580*/ 579*/
581QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) 580QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type)
582{ 581{
583 qpeManager->updateActive(); 582 qpeManager->updateActive();
584 583
585 WindowDecorationInterface::WindowData wd; 584 WindowDecorationInterface::WindowData wd;
586 windowData( widget, wd ); 585 windowData( widget, wd );
587 wd.rect = rect; 586 wd.rect = rect;
588 587
589 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 588 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
590 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd); 589 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd);
591 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd); 590 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd);
592 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd); 591 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd);
593 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd); 592 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd);
594 593
595 QRegion region; 594 QRegion region;
596 595
597 switch ((int)type) { 596 switch ((int)type) {
598 case Menu: 597 case Menu:
599 break; 598 break;
600 case Maximize: 599 case Maximize:
601 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) { 600 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) {
602 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd); 601 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd);
603 int left = rect.right() - maximizeWidth - closeWidth; 602 int left = rect.right() - maximizeWidth - closeWidth;
604 if ( ((HackWidget *)widget)->needsOk() ) 603 if ( ((HackWidget *)widget)->needsOk() )
605 left -= okWidth; 604 left -= okWidth;
606 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 605 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
607 region = r; 606 region = r;
608 } 607 }
609 break; 608 break;
610 case Minimize: 609 case Minimize:
611 if ( ((HackWidget *)widget)->needsOk() ) { 610 if ( ((HackWidget *)widget)->needsOk() ) {
612 QRect r(rect.right() - okWidth, 611 QRect r(rect.right() - okWidth,
613 rect.top() - titleHeight, okWidth, titleHeight); 612 rect.top() - titleHeight, okWidth, titleHeight);
614 if (r.left() > rect.left() + titleHeight) 613 if (r.left() > rect.left() + titleHeight)
615 region = r; 614 region = r;
616 } 615 }
617 break; 616 break;
618 case Close: 617 case Close:
619 { 618 {
620 int left = rect.right() - closeWidth; 619 int left = rect.right() - closeWidth;
621 if ( ((HackWidget *)widget)->needsOk() ) 620 if ( ((HackWidget *)widget)->needsOk() )
622 left -= okWidth; 621 left -= okWidth;
623 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 622 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
624 region = r; 623 region = r;
625 } 624 }
626 break; 625 break;
627 case Title: 626 case Title:
628 if ( !widget->isMaximized() ) { 627 if ( !widget->isMaximized() ) {
629 int width = rect.width() - helpWidth - closeWidth; 628 int width = rect.width() - helpWidth - closeWidth;
630 if ( ((HackWidget *)widget)->needsOk() ) 629 if ( ((HackWidget *)widget)->needsOk() )
631 width -= okWidth; 630 width -= okWidth;
632 QRect r(rect.left()+helpWidth, rect.top() - titleHeight, 631 QRect r(rect.left()+helpWidth, rect.top() - titleHeight,
633 width, titleHeight); 632 width, titleHeight);
634 if (r.width() > 0) 633 if (r.width() > 0)
635 region = r; 634 region = r;
636 } 635 }
637 break; 636 break;
638 case Help: 637 case Help:
639 if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) { 638 if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) {
640 QRect r(rect.left(), rect.top() - titleHeight, 639 QRect r(rect.left(), rect.top() - titleHeight,
641 helpWidth, titleHeight); 640 helpWidth, titleHeight);
642 region = r; 641 region = r;
643 } 642 }
644 break; 643 break;
645 case Top: 644 case Top:
646 if ( !widget->isMaximized() ) { 645 if ( !widget->isMaximized() ) {
647 QRegion m = wdiface->mask(&wd); 646 QRegion m = wdiface->mask(&wd);
648 QRect br = m.boundingRect(); 647 QRect br = m.boundingRect();
649 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 648 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
650 region = m & QRect( br.left()+grab, br.top(), 649 region = m & QRect( br.left()+grab, br.top(),
651 br.width()-2*grab, b ); 650 br.width()-2*grab, b );
652 } 651 }
653 break; 652 break;
654 case Left: 653 case Left:
655 if ( !widget->isMaximized() ) { 654 if ( !widget->isMaximized() ) {
656 QRegion m = wdiface->mask(&wd); 655 QRegion m = wdiface->mask(&wd);
657 QRect br = m.boundingRect(); 656 QRect br = m.boundingRect();
658 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 657 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
659 region = m & QRect( br.left(), br.top()+grab, 658 region = m & QRect( br.left(), br.top()+grab,
660 b, br.height()-2*grab ); 659 b, br.height()-2*grab );
661 } 660 }
662 break; 661 break;
663 case Right: 662 case Right:
664 if ( !widget->isMaximized() ) { 663 if ( !widget->isMaximized() ) {
665 QRegion m = wdiface->mask(&wd); 664 QRegion m = wdiface->mask(&wd);
666 QRect br = m.boundingRect(); 665 QRect br = m.boundingRect();
667 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 666 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
668 region = m & QRect( rect.right(), br.top()+grab, 667 region = m & QRect( rect.right(), br.top()+grab,
669 b, br.height()-2*grab ); 668 b, br.height()-2*grab );
670 } 669 }
671 break; 670 break;
672 case Bottom: 671 case Bottom:
673 if ( !widget->isMaximized() ) { 672 if ( !widget->isMaximized() ) {
674 QRegion m = wdiface->mask(&wd); 673 QRegion m = wdiface->mask(&wd);
675 QRect br = m.boundingRect(); 674 QRect br = m.boundingRect();
676 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd); 675 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd);
677 region = m & QRect( br.left()+grab, rect.bottom(), 676 region = m & QRect( br.left()+grab, rect.bottom(),
678 br.width()-2*grab, b ); 677 br.width()-2*grab, b );
679 } 678 }
680 break; 679 break;
681 case TopLeft: 680 case TopLeft:
682 if ( !widget->isMaximized() ) { 681 if ( !widget->isMaximized() ) {
683 QRegion m = wdiface->mask(&wd); 682 QRegion m = wdiface->mask(&wd);
684 QRect br = m.boundingRect(); 683 QRect br = m.boundingRect();
685 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 684 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
686 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 685 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
687 QRegion crgn( br.left(), br.top(), grab, tb ); 686 QRegion crgn( br.left(), br.top(), grab, tb );
688 crgn |= QRect( br.left(), br.top(), lb, grab ); 687 crgn |= QRect( br.left(), br.top(), lb, grab );
689 region = m & crgn; 688 region = m & crgn;
690 } 689 }
691 break; 690 break;
692 case TopRight: 691 case TopRight:
693 if ( !widget->isMaximized() ) { 692 if ( !widget->isMaximized() ) {
694 QRegion m = wdiface->mask(&wd); 693 QRegion m = wdiface->mask(&wd);
695 QRect br = m.boundingRect(); 694 QRect br = m.boundingRect();
696 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 695 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
697 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 696 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
698 QRegion crgn( br.right()-grab, br.top(), grab, tb ); 697 QRegion crgn( br.right()-grab, br.top(), grab, tb );
699 crgn |= QRect( br.right()-rb, br.top(), rb, grab ); 698 crgn |= QRect( br.right()-rb, br.top(), rb, grab );
700 region = m & crgn; 699 region = m & crgn;
701 } 700 }
702 break; 701 break;
703 case BottomLeft: 702 case BottomLeft:
704 if ( !widget->isMaximized() ) { 703 if ( !widget->isMaximized() ) {
705 QRegion m = wdiface->mask(&wd); 704 QRegion m = wdiface->mask(&wd);
706 QRect br = m.boundingRect(); 705 QRect br = m.boundingRect();
707 region = m & QRect( br.left(), br.bottom()-grab, grab, grab ); 706 region = m & QRect( br.left(), br.bottom()-grab, grab, grab );
708 } 707 }
709 break; 708 break;
710 case BottomRight: 709 case BottomRight:
711 if ( !widget->isMaximized() ) { 710 if ( !widget->isMaximized() ) {
712 QRegion m = wdiface->mask(&wd); 711 QRegion m = wdiface->mask(&wd);
713 QRect br = m.boundingRect(); 712 QRect br = m.boundingRect();
714 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab ); 713 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab );
715 } 714 }
716 break; 715 break;
717 case All: 716 case All:
718 if ( widget->isMaximized() ) 717 if ( widget->isMaximized() )
719 region = QWSDefaultDecoration::region(widget, rect, type); 718 region = QWSDefaultDecoration::region(widget, rect, type);
720 else 719 else
721 region = wdiface->mask(&wd) - rect; 720 region = wdiface->mask(&wd) - rect;
722 break; 721 break;
723 default: 722 default:
724 region = QWSDefaultDecoration::region(widget, rect, type); 723 region = QWSDefaultDecoration::region(widget, rect, type);
725 break; 724 break;
726 } 725 }
727 726
728 return region; 727 return region;
729} 728}
730 729
731void QPEDecoration::paint(QPainter *painter, const QWidget *widget) 730void QPEDecoration::paint(QPainter *painter, const QWidget *widget)
732{ 731{
733 WindowDecorationInterface::WindowData wd; 732 WindowDecorationInterface::WindowData wd;
734 windowData( widget, wd ); 733 windowData( widget, wd );
735 734
736 int titleWidth = getTitleWidth(widget); 735 int titleWidth = getTitleWidth(widget);
737 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 736 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
738 737
739 QRect rect(widget->rect()); 738 QRect rect(widget->rect());
740 739
741 // title bar rect 740 // title bar rect
742 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 741 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
743 742
744#ifndef QT_NO_PALETTE 743#ifndef QT_NO_PALETTE
745 QRegion oldClip = painter->clipRegion(); 744 QRegion oldClip = painter->clipRegion();
746 painter->setClipRegion( oldClip - QRegion( tr ) );// reduce flicker 745 painter->setClipRegion( oldClip - QRegion( tr ) );// reduce flicker
747 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd ); 746 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd );
748 painter->setClipRegion( oldClip ); 747 painter->setClipRegion( oldClip );
749 748
750 if (titleWidth > 0) { 749 if (titleWidth > 0) {
751 const QColorGroup &cg = widget->palette().active(); 750 const QColorGroup &cg = widget->palette().active();
752 QBrush titleBrush; 751 QBrush titleBrush;
753 QPen titlePen; 752 QPen titlePen;
754 753
755 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) { 754 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) {
756 titleBrush = cg.brush(QColorGroup::Highlight); 755 titleBrush = cg.brush(QColorGroup::Highlight);
757 titlePen = cg.color(QColorGroup::HighlightedText); 756 titlePen = cg.color(QColorGroup::HighlightedText);
758 } else { 757 } else {
759 titleBrush = cg.brush(QColorGroup::Background); 758 titleBrush = cg.brush(QColorGroup::Background);
760 titlePen = cg.color(QColorGroup::Text); 759 titlePen = cg.color(QColorGroup::Text);
761 } 760 }
762 761
763 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 762 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
764 763
765 // Draw caption 764 // Draw caption
766 painter->setPen(titlePen); 765 painter->setPen(titlePen);
767 QFont f( QApplication::font() ); 766 QFont f( QApplication::font() );
768 f.setWeight( QFont::Bold ); 767 f.setWeight( QFont::Bold );
769 painter->setFont(f); 768 painter->setFont(f);
770 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd ); 769 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd );
771 } 770 }
772#endif //QT_NO_PALETTE 771#endif //QT_NO_PALETTE
773 772
774 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 ); 773 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 );
775} 774}
776 775
777void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, 776void QPEDecoration::paintButton(QPainter *painter, const QWidget *w,
778 QWSDecoration::Region type, int state) 777 QWSDecoration::Region type, int state)
779{ 778{
780 WindowDecorationInterface::Button b; 779 WindowDecorationInterface::Button b;
781 switch ((int)type) { 780 switch ((int)type) {
782 case Close: 781 case Close:
783 b = WindowDecorationInterface::Close; 782 b = WindowDecorationInterface::Close;
784 break; 783 break;
785 case Minimize: 784 case Minimize:
786 if ( ((HackWidget *)w)->needsOk() ) 785 if ( ((HackWidget *)w)->needsOk() )
787 b = WindowDecorationInterface::OK; 786 b = WindowDecorationInterface::OK;
788 else if ( helpExists ) 787 else if ( helpExists )
789 b = WindowDecorationInterface::Help; 788 b = WindowDecorationInterface::Help;
790 else 789 else
791 return; 790 return;
792 break; 791 break;
793 case Help: 792 case Help:
794 b = WindowDecorationInterface::Help; 793 b = WindowDecorationInterface::Help;
795 break; 794 break;
796 case Maximize: 795 case Maximize:
797 b = WindowDecorationInterface::Maximize; 796 b = WindowDecorationInterface::Maximize;
798 break; 797 break;
799 default: 798 default:
800 return; 799 return;
801 } 800 }
802 801
803 WindowDecorationInterface::WindowData wd; 802 WindowDecorationInterface::WindowData wd;
804 windowData( w, wd ); 803 windowData( w, wd );
805 804
806 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 805 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
807 QRect rect(w->rect()); 806 QRect rect(w->rect());
808 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 807 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
809 QRect brect(region(w, w->rect(), type).boundingRect()); 808 QRect brect(region(w, w->rect(), type).boundingRect());
810 809
811 const QColorGroup &cg = w->palette().active(); 810 const QColorGroup &cg = w->palette().active();
812 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) 811 if ( wd.flags & WindowDecorationInterface::WindowData::Active )
813 painter->setPen( cg.color(QColorGroup::HighlightedText) ); 812 painter->setPen( cg.color(QColorGroup::HighlightedText) );
814 else 813 else
815 painter->setPen( cg.color(QColorGroup::Text) ); 814 painter->setPen( cg.color(QColorGroup::Text) );
816 815
817 QRegion oldClip = painter->clipRegion(); 816 QRegion oldClip = painter->clipRegion();
818 painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker 817 painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker
819 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 818 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
820 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state ); 819 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state );
821 painter->setClipRegion( oldClip ); 820 painter->setClipRegion( oldClip );
822} 821}
823 822
824//#define QPE_DONT_SHOW_TITLEBAR 823//#define QPE_DONT_SHOW_TITLEBAR
825 824
826void QPEDecoration::maximize( QWidget *widget ) 825void QPEDecoration::maximize( QWidget *widget )
827{ 826{
828#ifdef QPE_DONT_SHOW_TITLEBAR 827#ifdef QPE_DONT_SHOW_TITLEBAR
829 if ( !widget->inherits( "QDialog" ) ) { 828 if ( !widget->inherits( "QDialog" ) ) {
830 widget->setGeometry( qt_maxWindowRect ); 829 widget->setGeometry( qt_maxWindowRect );
831 } else 830 } else
832#endif 831#endif
833 { 832 {
834 QWSDecoration::maximize( widget ); 833 QWSDecoration::maximize( widget );
835 } 834 }
836} 835}
837 836
838#ifndef QT_NO_DIALOG 837#ifndef QT_NO_DIALOG
839class HackDialog : public QDialog 838class HackDialog : public QDialog
840{ 839{
841public: 840public:
842 void acceptIt() { 841 void acceptIt() {
843 if ( isA( "QMessageBox" ) ) 842 if ( isA( "QMessageBox" ) )
844 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) ); 843 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) );
845 else 844 else
846 accept(); 845 accept();
847 } 846 }
848}; 847};
849#endif 848#endif
850 849
851 850
852void QPEDecoration::minimize( QWidget *widget ) 851void QPEDecoration::minimize( QWidget *widget )
853{ 852{
854#ifndef QT_NO_DIALOG 853#ifndef QT_NO_DIALOG
855 // We use the minimize button as an "accept" button. 854 // We use the minimize button as an "accept" button.
856 if ( widget->inherits( "QDialog" ) ) { 855 if ( widget->inherits( "QDialog" ) ) {
857 HackDialog *d = (HackDialog *)widget; 856 HackDialog *d = (HackDialog *)widget;
858 d->acceptIt(); 857 d->acceptIt();
859 } 858 }
860#endif 859#endif
861 else if ( ((HackWidget *)widget)->needsOk() ) { 860 else if ( ((HackWidget *)widget)->needsOk() ) {
862 QSignal s; 861 QSignal s;
863 s.connect( widget, SLOT( accept() ) ); 862 s.connect( widget, SLOT( accept() ) );
864 s.activate(); 863 s.activate();
865 } else { 864 } else {
866 help( widget ); 865 help( widget );
867 } 866 }
868} 867}
869 868
870void QPEDecoration::help( QWidget *w ) 869void QPEDecoration::help( QWidget *w )
871{ 870{
872 if ( helpExists ) { 871 if ( helpExists ) {
873 Global::execute( "helpbrowser", helpFile ); 872 Global::execute( "helpbrowser", helpFile );
874 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) { 873 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) {
875 QWhatsThis::enterWhatsThisMode(); 874 QWhatsThis::enterWhatsThisMode();
876 QWhatsThis::leaveWhatsThisMode( qApp->tr( 875 QWhatsThis::leaveWhatsThisMode( qApp->tr(
877 "<Qt>Comprehensive help is not available for this application, " 876 "<Qt>Comprehensive help is not available for this application, "
878 "however there is context-sensitive help.<p>To use context-sensitive help:<p>" 877 "however there is context-sensitive help.<p>To use context-sensitive help:<p>"
879 "<ol><li>click and hold the help button." 878 "<ol><li>click and hold the help button."
880 "<li>when the title bar shows <b>What's this...</b>, " 879 "<li>when the title bar shows <b>What's this...</b>, "
881 "click on any control.</ol></Qt>" ) ); 880 "click on any control.</ol></Qt>" ) );
882 } 881 }
883} 882}
884 883
885void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const 884void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const
886{ 885{
887 wd.rect = w->rect(); 886 wd.rect = w->rect();
888 if ( qpeManager->whatsThisWidget() == w ) 887 if ( qpeManager->whatsThisWidget() == w )
889 wd.caption = qApp->tr("What's this..." ); 888 wd.caption = qApp->tr("What's this..." );
890 else 889 else
891 wd.caption = w->caption(); 890 wd.caption = w->caption();
892 wd.palette = qApp->palette(); 891 wd.palette = qApp->palette();
893 wd.flags = 0; 892 wd.flags = 0;
894 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0; 893 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0;
895 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0; 894 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0;
896 const QWidget *active = qpeManager->activeWidget(); 895 const QWidget *active = qpeManager->activeWidget();
897 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0; 896 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0;
898 wd.reserved = 1; 897 wd.reserved = 1;
899} 898}
900 899
901/* 900/*
902#ifndef QT_NO_POPUPMENU 901#ifndef QT_NO_POPUPMENU
903QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) 902QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&)
904{ 903{
905 return 0; 904 return 0;
906} 905}
907#endif 906#endif
908*/ 907*/
909 908
910 909
911 910
912 911
913#endif // QT_NO_QWS_QPE_WM_STYLE 912#endif // QT_NO_QWS_QPE_WM_STYLE
914#endif
diff --git a/library/tzselect.cpp b/library/tzselect.cpp
index 9436867..2e5a433 100644
--- a/library/tzselect.cpp
+++ b/library/tzselect.cpp
@@ -1,275 +1,271 @@
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 "global.h" 25#include "global.h"
26#include "config.h" 26#include "config.h"
27#include <qtoolbutton.h> 27#include <qtoolbutton.h>
28#include <qfile.h> 28#include <qfile.h>
29#include <stdlib.h> 29#include <stdlib.h>
30 30
31#ifdef Q_WS_QWS
32#include <qcopchannel_qws.h> 31#include <qcopchannel_qws.h>
33#endif
34 32
35class TimeZoneSelectorPrivate 33class TimeZoneSelectorPrivate
36{ 34{
37public: 35public:
38 TimeZoneSelectorPrivate() : includeLocal(FALSE) {} 36 TimeZoneSelectorPrivate() : includeLocal(FALSE) {}
39 bool includeLocal; 37 bool includeLocal;
40}; 38};
41 39
42TZCombo::TZCombo( QWidget *p, const char* n ) 40TZCombo::TZCombo( QWidget *p, const char* n )
43 : QComboBox( p, n ) 41 : QComboBox( p, n )
44{ 42{
45 updateZones(); 43 updateZones();
46 // check to see if TZ is set, if it is set the current item to that 44 // check to see if TZ is set, if it is set the current item to that
47 QString tz = getenv("TZ"); 45 QString tz = getenv("TZ");
48 if (parent()->inherits("TimeZoneSelector")) { 46 if (parent()->inherits("TimeZoneSelector")) {
49 if ( ((TimeZoneSelector *)parent())->localIncluded() ) { 47 if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
50 // overide to the 'local' type. 48 // overide to the 'local' type.
51 tz = "None"; 49 tz = "None";
52 } 50 }
53 } 51 }
54 if ( !tz.isNull() ) { 52 if ( !tz.isNull() ) {
55 int n = 0, 53 int n = 0,
56 index = 0; 54 index = 0;
57 for ( QStringList::Iterator it=identifiers.begin(); 55 for ( QStringList::Iterator it=identifiers.begin();
58 it!=identifiers.end(); ++it) { 56 it!=identifiers.end(); ++it) {
59 if ( *it == tz ) 57 if ( *it == tz )
60 index = n; 58 index = n;
61 n++; 59 n++;
62 } 60 }
63 setCurrentItem(index); 61 setCurrentItem(index);
64 } else { 62 } else {
65 setCurrentItem(0); 63 setCurrentItem(0);
66 } 64 }
67 65
68 66
69 67
70 // listen on QPE/System 68 // listen on QPE/System
71#if defined(Q_WS_QWS)
72#if !defined(QT_NO_COP) 69#if !defined(QT_NO_COP)
73 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 70 QCopChannel *channel = new QCopChannel( "QPE/System", this );
74 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 71 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
75 this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) ); 72 this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) );
76#endif 73#endif
77#endif
78 74
79 75
80} 76}
81 77
82TZCombo::~TZCombo() 78TZCombo::~TZCombo()
83{ 79{
84} 80}
85 81
86void TZCombo::updateZones() 82void TZCombo::updateZones()
87{ 83{
88 QString cur = currentText(); 84 QString cur = currentText();
89 clear(); 85 clear();
90 identifiers.clear(); 86 identifiers.clear();
91 int curix=0; 87 int curix=0;
92 QString tz = getenv("TZ"); 88 QString tz = getenv("TZ");
93 bool tzFound = FALSE; 89 bool tzFound = FALSE;
94 Config cfg("CityTime"); 90 Config cfg("CityTime");
95 cfg.setGroup("TimeZones"); 91 cfg.setGroup("TimeZones");
96 int listIndex = 0; 92 int listIndex = 0;
97 if (parent()->inherits("TimeZoneSelector")) { 93 if (parent()->inherits("TimeZoneSelector")) {
98 if ( ((TimeZoneSelector *)parent())->localIncluded() ) { 94 if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
99 // overide to the 'local' type. 95 // overide to the 'local' type.
100 identifiers.append( "None" ); 96 identifiers.append( "None" );
101 insertItem( tr("None") ); 97 insertItem( tr("None") );
102 if ( cur == tr("None")) 98 if ( cur == tr("None"))
103 curix = 0; 99 curix = 0;
104 listIndex++; 100 listIndex++;
105 } 101 }
106 } 102 }
107 int cfgIndex = 0; 103 int cfgIndex = 0;
108 while (1) { 104 while (1) {
109 QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null); 105 QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null);
110 if ( zn.isNull() ) 106 if ( zn.isNull() )
111 break; 107 break;
112 if ( zn == tz ) 108 if ( zn == tz )
113 tzFound = TRUE; 109 tzFound = TRUE;
114 QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex)); 110 QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex));
115 identifiers.append(zn); 111 identifiers.append(zn);
116 insertItem(nm); 112 insertItem(nm);
117 if ( nm == cur ) 113 if ( nm == cur )
118 curix = listIndex; 114 curix = listIndex;
119 ++cfgIndex; 115 ++cfgIndex;
120 ++listIndex; 116 ++listIndex;
121 } 117 }
122 if ( !listIndex ) { 118 if ( !listIndex ) {
123 QStringList list = timezoneDefaults(); 119 QStringList list = timezoneDefaults();
124 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) { 120 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) {
125 QString zn = *it; 121 QString zn = *it;
126 QString nm = *++it; 122 QString nm = *++it;
127 if ( zn == tz ) 123 if ( zn == tz )
128 tzFound = TRUE; 124 tzFound = TRUE;
129 if ( nm == cur ) 125 if ( nm == cur )
130 curix = listIndex; 126 curix = listIndex;
131 identifiers.append(zn); 127 identifiers.append(zn);
132 insertItem(nm); 128 insertItem(nm);
133 ++listIndex; 129 ++listIndex;
134 } 130 }
135 } 131 }
136 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) { 132 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) {
137 insertItem(*it); 133 insertItem(*it);
138 identifiers.append(*it); 134 identifiers.append(*it);
139 if ( *it == cur ) 135 if ( *it == cur )
140 curix = listIndex; 136 curix = listIndex;
141 ++listIndex; 137 ++listIndex;
142 } 138 }
143 if ( !tzFound && !tz.isEmpty()) { 139 if ( !tzFound && !tz.isEmpty()) {
144 int i = tz.find( '/' ); 140 int i = tz.find( '/' );
145 QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " "); 141 QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " ");
146 identifiers.append(tz); 142 identifiers.append(tz);
147 insertItem(nm); 143 insertItem(nm);
148 if ( nm == cur ) 144 if ( nm == cur )
149 curix = listIndex; 145 curix = listIndex;
150 ++listIndex; 146 ++listIndex;
151 } 147 }
152 setCurrentItem(curix); 148 setCurrentItem(curix);
153} 149}
154 150
155 151
156void TZCombo::keyPressEvent( QKeyEvent *e ) 152void TZCombo::keyPressEvent( QKeyEvent *e )
157{ 153{
158 // ### should popup() in Qt 3.0 (it's virtual there) 154 // ### should popup() in Qt 3.0 (it's virtual there)
159// updateZones(); 155// updateZones();
160 QComboBox::keyPressEvent(e); 156 QComboBox::keyPressEvent(e);
161} 157}
162 158
163void TZCombo::mousePressEvent(QMouseEvent*e) 159void TZCombo::mousePressEvent(QMouseEvent*e)
164{ 160{
165 // ### should popup() in Qt 3.0 (it's virtual there) 161 // ### should popup() in Qt 3.0 (it's virtual there)
166// updateZones(); 162// updateZones();
167 QComboBox::mousePressEvent(e); 163 QComboBox::mousePressEvent(e);
168} 164}
169 165
170QString TZCombo::currZone() const 166QString TZCombo::currZone() const
171{ 167{
172 return identifiers[currentItem()]; 168 return identifiers[currentItem()];
173} 169}
174 170
175void TZCombo::setCurrZone( const QString& id ) 171void TZCombo::setCurrZone( const QString& id )
176{ 172{
177 for (int i=0; i< count(); i++) { 173 for (int i=0; i< count(); i++) {
178 if ( identifiers[i] == id ) { 174 if ( identifiers[i] == id ) {
179 setCurrentItem(i); 175 setCurrentItem(i);
180 return; 176 return;
181} 177}
182 } 178 }
183 insertItem(id); 179 insertItem(id);
184 setCurrentItem( count() - 1); 180 setCurrentItem( count() - 1);
185 identifiers.append(id); 181 identifiers.append(id);
186 extras.append(id); 182 extras.append(id);
187} 183}
188 184
189 185
190 186
191void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&) 187void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&)
192{ 188{
193 if ( msg == "timeZoneListChange()" ) { 189 if ( msg == "timeZoneListChange()" ) {
194 updateZones(); 190 updateZones();
195 } 191 }
196} 192}
197 193
198 194
199TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) : 195TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) :
200 QHBox(p,n) 196 QHBox(p,n)
201{ 197{
202 d = new TimeZoneSelectorPrivate(); 198 d = new TimeZoneSelectorPrivate();
203 // build the combobox before we do any updates... 199 // build the combobox before we do any updates...
204 cmbTz = new TZCombo( this, "timezone combo" ); 200 cmbTz = new TZCombo( this, "timezone combo" );
205 201
206 cmdTz = new QToolButton( this, "timezone button" ); 202 cmdTz = new QToolButton( this, "timezone button" );
207 cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) ); 203 cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) );
208 cmdTz->setMaximumSize( cmdTz->sizeHint() ); 204 cmdTz->setMaximumSize( cmdTz->sizeHint() );
209 205
210 // set up a connection to catch a newly selected item and throw our 206 // set up a connection to catch a newly selected item and throw our
211 // signal 207 // signal
212 QObject::connect( cmbTz, SIGNAL( activated( int ) ), 208 QObject::connect( cmbTz, SIGNAL( activated( int ) ),
213 this, SLOT( slotTzActive( int ) ) ); 209 this, SLOT( slotTzActive( int ) ) );
214 QObject::connect( cmdTz, SIGNAL( clicked() ), 210 QObject::connect( cmdTz, SIGNAL( clicked() ),
215 this, SLOT( slotExecute() ) ); 211 this, SLOT( slotExecute() ) );
216} 212}
217 213
218TimeZoneSelector::~TimeZoneSelector() 214TimeZoneSelector::~TimeZoneSelector()
219{ 215{
220} 216}
221 217
222void TimeZoneSelector::setLocalIncluded(bool b) 218void TimeZoneSelector::setLocalIncluded(bool b)
223{ 219{
224 d->includeLocal = b; 220 d->includeLocal = b;
225 cmbTz->updateZones(); 221 cmbTz->updateZones();
226} 222}
227 223
228bool TimeZoneSelector::localIncluded() const 224bool TimeZoneSelector::localIncluded() const
229{ 225{
230 return d->includeLocal; 226 return d->includeLocal;
231} 227}
232 228
233 229
234QString TimeZoneSelector::currentZone() const 230QString TimeZoneSelector::currentZone() const
235{ 231{
236 return cmbTz->currZone(); 232 return cmbTz->currZone();
237} 233}
238 234
239void TimeZoneSelector::setCurrentZone( const QString& id ) 235void TimeZoneSelector::setCurrentZone( const QString& id )
240{ 236{
241 cmbTz->setCurrZone( id ); 237 cmbTz->setCurrZone( id );
242} 238}
243 239
244void TimeZoneSelector::slotTzActive( int ) 240void TimeZoneSelector::slotTzActive( int )
245{ 241{
246 emit signalNewTz( cmbTz->currZone() ); 242 emit signalNewTz( cmbTz->currZone() );
247} 243}
248 244
249void TimeZoneSelector::slotExecute( void ) 245void TimeZoneSelector::slotExecute( void )
250{ 246{
251 // execute the world time application... 247 // execute the world time application...
252 Global::execute( "citytime" ); 248 Global::execute( "citytime" );
253} 249}
254 250
255QStringList timezoneDefaults( void ) 251QStringList timezoneDefaults( void )
256{ 252{
257 QStringList tzs; 253 QStringList tzs;
258 // load up the list just like the file format (citytime.cpp) 254 // load up the list just like the file format (citytime.cpp)
259 tzs.append( "America/New_York" ); 255 tzs.append( "America/New_York" );
260 tzs.append( "New York" ); 256 tzs.append( "New York" );
261 tzs.append( "America/Los_Angeles" ); 257 tzs.append( "America/Los_Angeles" );
262 tzs.append( "Los Angeles" ); 258 tzs.append( "Los Angeles" );
263 tzs.append( "Australia/Brisbane" ); 259 tzs.append( "Australia/Brisbane" );
264 tzs.append( "Brisbane" ); 260 tzs.append( "Brisbane" );
265 tzs.append( "Europe/Berlin" ); 261 tzs.append( "Europe/Berlin" );
266 tzs.append( "Berlin" ); 262 tzs.append( "Berlin" );
267 tzs.append( "Asia/Tokyo" ); 263 tzs.append( "Asia/Tokyo" );
268 tzs.append( "Tokyo" ); 264 tzs.append( "Tokyo" );
269 tzs.append( "America/Denver" ); 265 tzs.append( "America/Denver" );
270 tzs.append( "Denver" ); 266 tzs.append( "Denver" );
271 267
272 return tzs; 268 return tzs;
273} 269}
274 270
275 271