summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/alarmserver.cpp5
-rw-r--r--library/applnk.cpp4
-rw-r--r--library/categoryedit_p.cpp3
-rw-r--r--library/categorymenu.cpp2
-rw-r--r--library/config.cpp2
-rw-r--r--library/datebookdb.cpp5
-rw-r--r--library/datebookmonth.cpp5
-rw-r--r--library/filemanager.cpp3
-rw-r--r--library/fileselector.cpp2
-rw-r--r--library/finddialog.cpp1
-rw-r--r--library/findwidget_p.cpp6
-rw-r--r--library/fontdatabase.cpp2
-rw-r--r--library/global.cpp2
-rw-r--r--library/imageedit.cpp1
-rw-r--r--library/ir.cpp2
-rw-r--r--library/lnkproperties.cpp3
-rw-r--r--library/mimetype.cpp4
-rw-r--r--library/qcopenvelope_qws.cpp2
-rw-r--r--library/qdawg.cpp2
-rw-r--r--library/qpeapplication.cpp1
-rw-r--r--library/qpemenubar.cpp1
-rw-r--r--library/qpestyle.cpp3
-rw-r--r--library/qpetoolbar.cpp2
-rw-r--r--library/qt_override.cpp2
-rw-r--r--library/resource.cpp3
-rw-r--r--library/sound.cpp2
-rw-r--r--library/storage.cpp4
-rw-r--r--library/tzselect.cpp1
28 files changed, 1 insertions, 74 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp
index 6f6f32d..48ab9c1 100644
--- a/library/alarmserver.cpp
+++ b/library/alarmserver.cpp
@@ -1,221 +1,216 @@
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>
23#include <qmessagebox.h>
24#include <qtextstream.h>
25 22
26 23
27#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
28#include "global.h"
29#include "resource.h"
30 25
31#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
32#include "alarmserver.h" 27#include "alarmserver.h"
33#include <qpe/timeconversion.h> 28#include <qpe/timeconversion.h>
34 29
35#include <sys/types.h> 30#include <sys/types.h>
36#include <sys/stat.h> 31#include <sys/stat.h>
37 32
38#include <stdlib.h> 33#include <stdlib.h>
39#include <unistd.h> 34#include <unistd.h>
40 35
41 36
42#undef USE_ATD // not used anymore -- we run opie-alarm on suspend/resume 37#undef USE_ATD // not used anymore -- we run opie-alarm on suspend/resume
43 38
44 39
45struct timerEventItem 40struct timerEventItem
46{ 41{
47 time_t UTCtime; 42 time_t UTCtime;
48 QCString channel, message; 43 QCString channel, message;
49 int data; 44 int data;
50 bool operator==( const timerEventItem &right ) const 45 bool operator==( const timerEventItem &right ) const
51 { 46 {
52 return ( UTCtime == right.UTCtime 47 return ( UTCtime == right.UTCtime
53 && channel == right.channel 48 && channel == right.channel
54 && message == right.message 49 && message == right.message
55 && data == right.data ); 50 && data == right.data );
56 } 51 }
57}; 52};
58 53
59class TimerReceiverObject : public QObject 54class TimerReceiverObject : public QObject
60{ 55{
61public: 56public:
62 TimerReceiverObject() 57 TimerReceiverObject()
63 { } 58 { }
64 ~TimerReceiverObject() 59 ~TimerReceiverObject()
65 { } 60 { }
66 void resetTimer(); 61 void resetTimer();
67 void setTimerEventItem(); 62 void setTimerEventItem();
68 void deleteTimer(); 63 void deleteTimer();
69protected: 64protected:
70 void timerEvent( QTimerEvent *te ); 65 void timerEvent( QTimerEvent *te );
71 66
72#ifdef USE_ATD 67#ifdef USE_ATD
73private: 68private:
74 QString atfilename; 69 QString atfilename;
75#endif 70#endif
76}; 71};
77 72
78TimerReceiverObject *timerEventReceiver = NULL; 73TimerReceiverObject *timerEventReceiver = NULL;
79QList<timerEventItem> timerEventList; 74QList<timerEventItem> timerEventList;
80timerEventItem *nearestTimerEvent = NULL; 75timerEventItem *nearestTimerEvent = NULL;
81 76
82 77
83// set the timer to go off on the next event in the list 78// set the timer to go off on the next event in the list
84void setNearestTimerEvent() 79void setNearestTimerEvent()
85{ 80{
86 nearestTimerEvent = NULL; 81 nearestTimerEvent = NULL;
87 QListIterator<timerEventItem> it( timerEventList ); 82 QListIterator<timerEventItem> it( timerEventList );
88 if ( *it ) 83 if ( *it )
89 nearestTimerEvent = *it; 84 nearestTimerEvent = *it;
90 for ( ; *it; ++it ) 85 for ( ; *it; ++it )
91 if ( (*it)->UTCtime < nearestTimerEvent->UTCtime ) 86 if ( (*it)->UTCtime < nearestTimerEvent->UTCtime )
92 nearestTimerEvent = *it; 87 nearestTimerEvent = *it;
93 if (nearestTimerEvent) 88 if (nearestTimerEvent)
94 timerEventReceiver->resetTimer(); 89 timerEventReceiver->resetTimer();
95 else 90 else
96 timerEventReceiver->deleteTimer(); 91 timerEventReceiver->deleteTimer();
97} 92}
98 93
99 94
100//store current state to file 95//store current state to file
101//Simple implementation. Should run on a timer. 96//Simple implementation. Should run on a timer.
102 97
103static void saveState() 98static void saveState()
104{ 99{
105 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); 100 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
106 if ( timerEventList.isEmpty() ) { 101 if ( timerEventList.isEmpty() ) {
107 unlink( savefilename ); 102 unlink( savefilename );
108 return ; 103 return ;
109 } 104 }
110 105
111 QFile savefile(savefilename + ".new"); 106 QFile savefile(savefilename + ".new");
112 if ( savefile.open(IO_WriteOnly) ) { 107 if ( savefile.open(IO_WriteOnly) ) {
113 QDataStream ds( &savefile ); 108 QDataStream ds( &savefile );
114 109
115 //save 110 //save
116 111
117 QListIterator<timerEventItem> it( timerEventList ); 112 QListIterator<timerEventItem> it( timerEventList );
118 for ( ; *it; ++it ) { 113 for ( ; *it; ++it ) {
119 ds << it.current()->UTCtime; 114 ds << it.current()->UTCtime;
120 ds << it.current()->channel; 115 ds << it.current()->channel;
121 ds << it.current()->message; 116 ds << it.current()->message;
122 ds << it.current()->data; 117 ds << it.current()->data;
123 } 118 }
124 119
125 120
126 savefile.close(); 121 savefile.close();
127 unlink( savefilename ); 122 unlink( savefilename );
128 QDir d; 123 QDir d;
129 d.rename(savefilename + ".new", savefilename); 124 d.rename(savefilename + ".new", savefilename);
130 125
131 } 126 }
132} 127}
133 128
134/*! 129/*!
135 Sets up the alarm server. Restoring to previous state (session management). 130 Sets up the alarm server. Restoring to previous state (session management).
136 */ 131 */
137void AlarmServer::initialize() 132void AlarmServer::initialize()
138{ 133{
139 //read autosave file and put events in timerEventList 134 //read autosave file and put events in timerEventList
140 135
141 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); 136 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
142 137
143 QFile savefile(savefilename); 138 QFile savefile(savefilename);
144 if ( savefile.open(IO_ReadOnly) ) { 139 if ( savefile.open(IO_ReadOnly) ) {
145 QDataStream ds( &savefile ); 140 QDataStream ds( &savefile );
146 while ( !ds.atEnd() ) { 141 while ( !ds.atEnd() ) {
147 timerEventItem *newTimerEventItem = new timerEventItem; 142 timerEventItem *newTimerEventItem = new timerEventItem;
148 ds >> newTimerEventItem->UTCtime; 143 ds >> newTimerEventItem->UTCtime;
149 ds >> newTimerEventItem->channel; 144 ds >> newTimerEventItem->channel;
150 ds >> newTimerEventItem->message; 145 ds >> newTimerEventItem->message;
151 ds >> newTimerEventItem->data; 146 ds >> newTimerEventItem->data;
152 timerEventList.append( newTimerEventItem ); 147 timerEventList.append( newTimerEventItem );
153 } 148 }
154 savefile.close(); 149 savefile.close();
155 if (!timerEventReceiver) 150 if (!timerEventReceiver)
156 timerEventReceiver = new TimerReceiverObject; 151 timerEventReceiver = new TimerReceiverObject;
157 setNearestTimerEvent(); 152 setNearestTimerEvent();
158 } 153 }
159} 154}
160 155
161 156
162#ifdef USE_ATD 157#ifdef USE_ATD
163 158
164static const char* atdir = "/var/spool/at/"; 159static const char* atdir = "/var/spool/at/";
165 160
166static bool triggerAtd( bool writeHWClock = FALSE ) 161static bool triggerAtd( bool writeHWClock = FALSE )
167{ 162{
168 QFile trigger(QString(atdir) + "trigger"); 163 QFile trigger(QString(atdir) + "trigger");
169 if ( trigger.open(IO_WriteOnly | IO_Raw) ) { 164 if ( trigger.open(IO_WriteOnly | IO_Raw) ) {
170 if ( trigger.writeBlock("\n", 2) != 2 ) { 165 if ( trigger.writeBlock("\n", 2) != 2 ) {
171 QMessageBox::critical( 0, QObject::tr( "Out of Space" ), 166 QMessageBox::critical( 0, QObject::tr( "Out of Space" ),
172 QObject::tr( "Unable to schedule alarm.\nFree some memory and try again." ) ); 167 QObject::tr( "Unable to schedule alarm.\nFree some memory and try again." ) );
173 trigger.close(); 168 trigger.close();
174 QFile::remove 169 QFile::remove
175 ( trigger.name() ); 170 ( trigger.name() );
176 return FALSE; 171 return FALSE;
177 } 172 }
178 return TRUE; 173 return TRUE;
179 } 174 }
180 return FALSE; 175 return FALSE;
181} 176}
182 177
183#else 178#else
184 179
185static bool writeResumeAt ( time_t wakeup ) 180static bool writeResumeAt ( time_t wakeup )
186{ 181{
187 FILE *fp = ::fopen ( "/var/run/resumeat", "w" ); 182 FILE *fp = ::fopen ( "/var/run/resumeat", "w" );
188 183
189 if ( fp ) { 184 if ( fp ) {
190 ::fprintf ( fp, "%d\n", (int) wakeup ); 185 ::fprintf ( fp, "%d\n", (int) wakeup );
191 ::fclose ( fp ); 186 ::fclose ( fp );
192 } 187 }
193 else 188 else
194 qWarning ( "Failed to write wakeup time to /var/run/resumeat" ); 189 qWarning ( "Failed to write wakeup time to /var/run/resumeat" );
195 190
196 return ( fp ); 191 return ( fp );
197} 192}
198 193
199#endif 194#endif
200 195
201void TimerReceiverObject::deleteTimer() 196void TimerReceiverObject::deleteTimer()
202{ 197{
203#ifdef USE_ATD 198#ifdef USE_ATD
204 if ( !atfilename.isEmpty() ) { 199 if ( !atfilename.isEmpty() ) {
205 unlink( atfilename ); 200 unlink( atfilename );
206 atfilename = QString::null; 201 atfilename = QString::null;
207 triggerAtd( FALSE ); 202 triggerAtd( FALSE );
208 } 203 }
209#else 204#else
210 writeResumeAt ( 0 ); 205 writeResumeAt ( 0 );
211#endif 206#endif
212} 207}
213 208
214void TimerReceiverObject::resetTimer() 209void TimerReceiverObject::resetTimer()
215{ 210{
216 const int maxsecs = 2147000; 211 const int maxsecs = 2147000;
217 QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime); 212 QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime);
218 QDateTime now = QDateTime::currentDateTime(); 213 QDateTime now = QDateTime::currentDateTime();
219 if ( nearest < now ) 214 if ( nearest < now )
220 nearest = now; 215 nearest = now;
221 int secs = TimeConversion::secsTo( now, nearest ); 216 int secs = TimeConversion::secsTo( now, nearest );
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 8763eb2..9c60f1a 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,233 +1,229 @@
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#include <qpe/qcopenvelope_qws.h> 30#include <qpe/qcopenvelope_qws.h>
31#include <qpe/global.h>
32#include <qpe/mimetype.h> 31#include <qpe/mimetype.h>
33#include <qpe/config.h> 32#include <qpe/config.h>
34#include <qpe/storage.h> 33#include <qpe/storage.h>
35#include <qpe/resource.h> 34#include <qpe/resource.h>
36 35
37#include <qdict.h>
38#include <qdir.h> 36#include <qdir.h>
39#include <qregexp.h>
40 37
41#include <qgfx_qws.h>
42 38
43#include <stdlib.h> 39#include <stdlib.h>
44 40
45int AppLnk::lastId = 5000; 41int AppLnk::lastId = 5000;
46 42
47static int smallSize = 14; 43static int smallSize = 14;
48static int bigSize = 32; 44static int bigSize = 32;
49 45
50static QString safeFileName(const QString& n) 46static QString safeFileName(const QString& n)
51{ 47{
52 QString safename=n; 48 QString safename=n;
53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); 49 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
54 safename.replace(QRegExp("^[^A-Za-z]*"),""); 50 safename.replace(QRegExp("^[^A-Za-z]*"),"");
55 if ( safename.isEmpty() ) 51 if ( safename.isEmpty() )
56 safename = "_"; 52 safename = "_";
57 return safename; 53 return safename;
58} 54}
59 55
60static bool prepareDirectories(const QString& lf) 56static bool prepareDirectories(const QString& lf)
61{ 57{
62 if ( !QFile::exists(lf) ) { 58 if ( !QFile::exists(lf) ) {
63 // May need to create directories 59 // May need to create directories
64 QFileInfo fi(lf); 60 QFileInfo fi(lf);
65 if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) 61 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
66 return FALSE; 62 return FALSE;
67 } 63 }
68 return TRUE; 64 return TRUE;
69} 65}
70 66
71class AppLnkPrivate 67class AppLnkPrivate
72{ 68{
73public: 69public:
74 /* the size of the Pixmap */ 70 /* the size of the Pixmap */
75 enum Size {Normal = 0, Big }; 71 enum Size {Normal = 0, Big };
76 AppLnkPrivate() { 72 AppLnkPrivate() {
77 /* we want one normal and one big item */ 73 /* we want one normal and one big item */
78 74
79 QPixmap pix; 75 QPixmap pix;
80 mPixmaps.insert(0, pix ); 76 mPixmaps.insert(0, pix );
81 mPixmaps.insert(1, pix); 77 mPixmaps.insert(1, pix);
82 } 78 }
83 79
84 QStringList mCatList; // always correct 80 QStringList mCatList; // always correct
85 QArray<int> mCat; // cached value; correct if not empty 81 QArray<int> mCat; // cached value; correct if not empty
86 QMap<int, QPixmap> mPixmaps; 82 QMap<int, QPixmap> mPixmaps;
87 83
88 void updateCatListFromArray() 84 void updateCatListFromArray()
89 { 85 {
90 Categories cat( 0 ); 86 Categories cat( 0 );
91 cat.load( categoryFileName() ); 87 cat.load( categoryFileName() );
92 // we need to update the names for the mCat... to mCatList 88 // we need to update the names for the mCat... to mCatList
93 mCatList.clear(); 89 mCatList.clear();
94 for (uint i = 0; i < mCat.count(); i++ ) 90 for (uint i = 0; i < mCat.count(); i++ )
95 mCatList << cat.label("Document View", mCat[i] ); 91 mCatList << cat.label("Document View", mCat[i] );
96 92
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
diff --git a/library/categoryedit_p.cpp b/library/categoryedit_p.cpp
index 9321259..14ac2e1 100644
--- a/library/categoryedit_p.cpp
+++ b/library/categoryedit_p.cpp
@@ -1,222 +1,219 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 "categoryedit_p.h" 21#include "categoryedit_p.h"
22 22
23#include <qpe/categories.h> 23#include <qpe/categories.h>
24 24
25#include <qdir.h> 25#include <qdir.h>
26#include <qcheckbox.h> 26#include <qcheckbox.h>
27#include <qlineedit.h> 27#include <qlineedit.h>
28#include <qlistview.h>
29#include <qstringlist.h>
30#include <qtoolbutton.h>
31 28
32#include <sys/types.h> 29#include <sys/types.h>
33#include <sys/stat.h> 30#include <sys/stat.h>
34 31
35#include <stdlib.h> 32#include <stdlib.h>
36 33
37 34
38using namespace Qtopia; 35using namespace Qtopia;
39 36
40class CategoryEditPrivate 37class CategoryEditPrivate
41{ 38{
42public: 39public:
43 CategoryEditPrivate( QWidget *parent, const QString &appName ) 40 CategoryEditPrivate( QWidget *parent, const QString &appName )
44 : mCategories( parent, "" ), 41 : mCategories( parent, "" ),
45 mStrApp( appName ) 42 mStrApp( appName )
46 { 43 {
47 editItem = 0; 44 editItem = 0;
48 mCategories.load( categoryFileName() ); 45 mCategories.load( categoryFileName() );
49 } 46 }
50 Categories mCategories; 47 Categories mCategories;
51 QListViewItem *editItem; 48 QListViewItem *editItem;
52 QString mStrApp; 49 QString mStrApp;
53 QString mVisible; 50 QString mVisible;
54}; 51};
55 52
56CategoryEdit::CategoryEdit( QWidget *parent, const char *name ) 53CategoryEdit::CategoryEdit( QWidget *parent, const char *name )
57 : CategoryEditBase( parent, name ) 54 : CategoryEditBase( parent, name )
58{ 55{
59 d = 0; 56 d = 0;
60} 57}
61 58
62CategoryEdit::CategoryEdit( const QArray<int> &recCats, 59CategoryEdit::CategoryEdit( const QArray<int> &recCats,
63 const QString &appName, const QString &visibleName, 60 const QString &appName, const QString &visibleName,
64 QWidget *parent, const char *name ) 61 QWidget *parent, const char *name )
65 : CategoryEditBase( parent, name ) 62 : CategoryEditBase( parent, name )
66{ 63{
67 d = 0; 64 d = 0;
68 setCategories( recCats, appName, visibleName ); 65 setCategories( recCats, appName, visibleName );
69} 66}
70 67
71void CategoryEdit::setCategories( const QArray<int> &recCats, 68void CategoryEdit::setCategories( const QArray<int> &recCats,
72 const QString &appName, const QString &visibleName ) 69 const QString &appName, const QString &visibleName )
73{ 70{
74 if ( !d ) 71 if ( !d )
75 d = new CategoryEditPrivate( (QWidget*)parent(), name() ); 72 d = new CategoryEditPrivate( (QWidget*)parent(), name() );
76 d->mStrApp = appName; 73 d->mStrApp = appName;
77 d->mVisible = visibleName; 74 d->mVisible = visibleName;
78 75
79 QStringList appCats = d->mCategories.labels( d->mStrApp ); 76 QStringList appCats = d->mCategories.labels( d->mStrApp );
80 QArray<int> cats = d->mCategories.ids(d->mStrApp, appCats); 77 QArray<int> cats = d->mCategories.ids(d->mStrApp, appCats);
81 lvView->clear(); 78 lvView->clear();
82 79
83 QStringList::ConstIterator it; 80 QStringList::ConstIterator it;
84 int i, j; 81 int i, j;
85 for ( i = 0, it = appCats.begin(); it != appCats.end(); i++, ++it ) { 82 for ( i = 0, it = appCats.begin(); it != appCats.end(); i++, ++it ) {
86 QCheckListItem *chk; 83 QCheckListItem *chk;
87 chk = new QCheckListItem( lvView, (*it), QCheckListItem::CheckBox ); 84 chk = new QCheckListItem( lvView, (*it), QCheckListItem::CheckBox );
88 if ( !d->mCategories.isGlobal((*it)) ) 85 if ( !d->mCategories.isGlobal((*it)) )
89 chk->setText( 1, tr(d->mVisible) ); 86 chk->setText( 1, tr(d->mVisible) );
90 else 87 else
91 chk->setText( 1, tr("All") ); 88 chk->setText( 1, tr("All") );
92 // Is this record using this category, then we should check it 89 // Is this record using this category, then we should check it
93 for ( j = 0; j < int(recCats.count()); j++ ) { 90 for ( j = 0; j < int(recCats.count()); j++ ) {
94 if ( cats[i] == recCats[j] ) { 91 if ( cats[i] == recCats[j] ) {
95 chk->setOn( true ); 92 chk->setOn( true );
96 break; 93 break;
97 } 94 }
98 } 95 }
99 } 96 }
100 lvView->setSorting( 0, TRUE ); 97 lvView->setSorting( 0, TRUE );
101 lvView->sort(); 98 lvView->sort();
102 if ( lvView->childCount() < 1 ) 99 if ( lvView->childCount() < 1 )
103 txtCat->setEnabled( FALSE ); 100 txtCat->setEnabled( FALSE );
104 else { 101 else {
105 lvView->setSelected( lvView->firstChild(), true ); 102 lvView->setSelected( lvView->firstChild(), true );
106 } 103 }
107} 104}
108 105
109CategoryEdit::~CategoryEdit() 106CategoryEdit::~CategoryEdit()
110{ 107{
111 if ( d ) 108 if ( d )
112 delete d; 109 delete d;
113} 110}
114 111
115void CategoryEdit::slotSetText( QListViewItem *selected ) 112void CategoryEdit::slotSetText( QListViewItem *selected )
116{ 113{
117 d->editItem = selected; 114 d->editItem = selected;
118 if ( !d->editItem ) 115 if ( !d->editItem )
119 return; 116 return;
120 txtCat->setText( d->editItem->text(0) ); 117 txtCat->setText( d->editItem->text(0) );
121 txtCat->setEnabled( true ); 118 txtCat->setEnabled( true );
122 if ( d->editItem->text(1) == tr("All") ) 119 if ( d->editItem->text(1) == tr("All") )
123 chkGlobal->setChecked( true ); 120 chkGlobal->setChecked( true );
124 else 121 else
125 chkGlobal->setChecked( false ); 122 chkGlobal->setChecked( false );
126} 123}
127 124
128void CategoryEdit::slotAdd() 125void CategoryEdit::slotAdd()
129{ 126{
130 QString name = tr( "New Category" ); 127 QString name = tr( "New Category" );
131 bool insertOk = FALSE; 128 bool insertOk = FALSE;
132 int num = 0; 129 int num = 0;
133 while ( !insertOk ) { 130 while ( !insertOk ) {
134 if ( num++ > 0 ) 131 if ( num++ > 0 )
135 name = tr("New Category ") + QString::number(num); 132 name = tr("New Category ") + QString::number(num);
136 insertOk = d->mCategories.addCategory( d->mStrApp, name ); 133 insertOk = d->mCategories.addCategory( d->mStrApp, name );
137 } 134 }
138 QCheckListItem *chk; 135 QCheckListItem *chk;
139 chk = new QCheckListItem( lvView, name, QCheckListItem::CheckBox ); 136 chk = new QCheckListItem( lvView, name, QCheckListItem::CheckBox );
140 if ( !chkGlobal->isChecked() ) 137 if ( !chkGlobal->isChecked() )
141 chk->setText( 1, tr(d->mVisible) ); 138 chk->setText( 1, tr(d->mVisible) );
142 else 139 else
143 chk->setText( 1, tr("All") ); 140 chk->setText( 1, tr("All") );
144 141
145 lvView->setSelected( chk, TRUE ); 142 lvView->setSelected( chk, TRUE );
146 txtCat->selectAll(); 143 txtCat->selectAll();
147 txtCat->setFocus(); 144 txtCat->setFocus();
148} 145}
149 146
150void CategoryEdit::slotRemove() 147void CategoryEdit::slotRemove()
151{ 148{
152 d->editItem = lvView->selectedItem(); 149 d->editItem = lvView->selectedItem();
153 if ( d->editItem ) { 150 if ( d->editItem ) {
154 QListViewItem *sibling = d->editItem->nextSibling(); 151 QListViewItem *sibling = d->editItem->nextSibling();
155 152
156 d->mCategories.removeCategory( d->mStrApp, d->editItem->text(0) ); 153 d->mCategories.removeCategory( d->mStrApp, d->editItem->text(0) );
157 154
158 delete d->editItem; 155 delete d->editItem;
159 d->editItem = 0; 156 d->editItem = 0;
160 157
161 if ( sibling ) 158 if ( sibling )
162 lvView->setSelected( sibling, TRUE ); 159 lvView->setSelected( sibling, TRUE );
163 } 160 }
164 if ( lvView->childCount() < 1 ) { 161 if ( lvView->childCount() < 1 ) {
165 txtCat->clear(); 162 txtCat->clear();
166 txtCat->setEnabled( FALSE ); 163 txtCat->setEnabled( FALSE );
167 } 164 }
168} 165}
169 166
170void CategoryEdit::slotSetGlobal( bool isChecked ) 167void CategoryEdit::slotSetGlobal( bool isChecked )
171{ 168{
172 if ( d->editItem ) { 169 if ( d->editItem ) {
173 if ( isChecked ) 170 if ( isChecked )
174 d->editItem->setText( 1, tr("All") ); 171 d->editItem->setText( 1, tr("All") );
175 else 172 else
176 d->editItem->setText( 1, tr(d->mVisible) ); 173 d->editItem->setText( 1, tr(d->mVisible) );
177 174
178 d->mCategories.setGlobal( d->mStrApp, d->editItem->text( 0 ), isChecked ); 175 d->mCategories.setGlobal( d->mStrApp, d->editItem->text( 0 ), isChecked );
179 } 176 }
180} 177}
181 178
182void CategoryEdit::slotTextChanged( const QString &strNew ) 179void CategoryEdit::slotTextChanged( const QString &strNew )
183{ 180{
184 if ( d->editItem ) { 181 if ( d->editItem ) {
185 if ( chkGlobal->isChecked() ) 182 if ( chkGlobal->isChecked() )
186 d->mCategories.renameGlobalCategory( d->editItem->text(0), strNew ); 183 d->mCategories.renameGlobalCategory( d->editItem->text(0), strNew );
187 else 184 else
188 d->mCategories.renameCategory( d->mStrApp, d->editItem->text(0), strNew ); 185 d->mCategories.renameCategory( d->mStrApp, d->editItem->text(0), strNew );
189 d->editItem->setText( 0, strNew ); 186 d->editItem->setText( 0, strNew );
190 } 187 }
191} 188}
192 189
193QArray<int> CategoryEdit::newCategories() 190QArray<int> CategoryEdit::newCategories()
194{ 191{
195 QArray<int> a; 192 QArray<int> a;
196 if ( d ) { 193 if ( d ) {
197 d->mCategories.save( categoryFileName() ); 194 d->mCategories.save( categoryFileName() );
198 QListViewItemIterator it( lvView ); 195 QListViewItemIterator it( lvView );
199 QValueList<int> l; 196 QValueList<int> l;
200 for ( ; it.current(); ++it ) { 197 for ( ; it.current(); ++it ) {
201 if ( reinterpret_cast<QCheckListItem*>(it.current())->isOn() ) 198 if ( reinterpret_cast<QCheckListItem*>(it.current())->isOn() )
202 l.append( d->mCategories.id( d->mStrApp, it.current()->text(0) ) ); 199 l.append( d->mCategories.id( d->mStrApp, it.current()->text(0) ) );
203 } 200 }
204 uint i = 0; 201 uint i = 0;
205 a.resize( l.count() ); 202 a.resize( l.count() );
206 for ( QValueList<int>::Iterator lit = l.begin(); lit != l.end(); ++lit ) 203 for ( QValueList<int>::Iterator lit = l.begin(); lit != l.end(); ++lit )
207 a[i++] = *lit; 204 a[i++] = *lit;
208 } 205 }
209 return a; 206 return a;
210} 207}
211 208
212void CategoryEdit::accept() 209void CategoryEdit::accept()
213{ 210{
214 // write our categories out... 211 // write our categories out...
215 d->mCategories.save( categoryFileName() ); 212 d->mCategories.save( categoryFileName() );
216 // QDialog::accept(); 213 // QDialog::accept();
217} 214}
218 215
219QString categoryFileName() 216QString categoryFileName()
220{ 217{
221 QDir dir = (QString(getenv("HOME")) + "/Settings"); 218 QDir dir = (QString(getenv("HOME")) + "/Settings");
222 if ( !dir.exists() ) 219 if ( !dir.exists() )
diff --git a/library/categorymenu.cpp b/library/categorymenu.cpp
index 5d7adf7..9bbb448 100644
--- a/library/categorymenu.cpp
+++ b/library/categorymenu.cpp
@@ -1,162 +1,160 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 "categorymenu.h" 21#include "categorymenu.h"
22#include "backend/categories.h" 22#include "backend/categories.h"
23#include "categoryselect.h" 23#include "categoryselect.h"
24#include <qstring.h>
25#include <qmap.h>
26 24
27/*! 25/*!
28 \class CategoryMenu 26 \class CategoryMenu
29 \brief The CategoryMenu widget aids in filtering records or files by Category. 27 \brief The CategoryMenu widget aids in filtering records or files by Category.
30 28
31 The CategoryMenu widget provides a popup menu that will make filtering records 29 The CategoryMenu widget provides a popup menu that will make filtering records
32 or files by category much easier. The widget will lookup the available 30 or files by category much easier. The widget will lookup the available
33 categories for an application, populate the menu, and keep a track of which 31 categories for an application, populate the menu, and keep a track of which
34 categories are being filtered against. A set of categories can be tested 32 categories are being filtered against. A set of categories can be tested
35 by the isSelected() function to see if a record or file containing those 33 by the isSelected() function to see if a record or file containing those
36 categories would be allowed through by the filter. 34 categories would be allowed through by the filter.
37 35
38 \warning Currently this class is not suitable for extending. 36 \warning Currently this class is not suitable for extending.
39 37
40 \ingroup qtopiaemb 38 \ingroup qtopiaemb
41*/ 39*/
42 40
43/*! 41/*!
44 \fn void CategoryMenu::categoryChange() 42 \fn void CategoryMenu::categoryChange()
45 This signal is emitted when the user selects a different category in the 43 This signal is emitted when the user selects a different category in the
46 menu, hence changing what records or files should be selected. 44 menu, hence changing what records or files should be selected.
47*/ 45*/
48 46
49/*! 47/*!
50 Creates a new CategoryMenu with \a parent and \a name. The menu will be 48 Creates a new CategoryMenu with \a parent and \a name. The menu will be
51 populated with the available categories for \a application. 49 populated with the available categories for \a application.
52 50
53 If \a globals is TRUE then it will also poplulate the menu with the 51 If \a globals is TRUE then it will also poplulate the menu with the
54 global categories. 52 global categories.
55*/ 53*/
56CategoryMenu::CategoryMenu( const QString &n, bool ig = TRUE, 54CategoryMenu::CategoryMenu( const QString &n, bool ig = TRUE,
57 QWidget *parent, const char *name ) : 55 QWidget *parent, const char *name ) :
58 QPopupMenu(parent, name), 56 QPopupMenu(parent, name),
59 appName(n), 57 appName(n),
60 includeGlobal(ig) 58 includeGlobal(ig)
61{ 59{
62 currentMid = 1; 60 currentMid = 1;
63 reload(); 61 reload();
64 connect(this, SIGNAL(activated(int)), this, SLOT(mapMenuId(int))); 62 connect(this, SIGNAL(activated(int)), this, SLOT(mapMenuId(int)));
65} 63}
66 64
67/*! 65/*!
68 Destroys a CategoryMenu. 66 Destroys a CategoryMenu.
69*/ 67*/
70CategoryMenu::~CategoryMenu( ) 68CategoryMenu::~CategoryMenu( )
71{ 69{
72} 70}
73 71
74/*! 72/*!
75 Repopulates the widget's list of available categories. 73 Repopulates the widget's list of available categories.
76*/ 74*/
77void CategoryMenu::reload() 75void CategoryMenu::reload()
78{ 76{
79 clear(); 77 clear();
80 Categories c; 78 Categories c;
81 79
82 c.load(categoryFileName()); 80 c.load(categoryFileName());
83 81
84 QStringList sl = c.labels(appName, includeGlobal); 82 QStringList sl = c.labels(appName, includeGlobal);
85 int mid = 1; 83 int mid = 1;
86 84
87 insertItem(tr("All"), mid); 85 insertItem(tr("All"), mid);
88 mid++; 86 mid++;
89 insertItem(tr("Unfiled"), mid); 87 insertItem(tr("Unfiled"), mid);
90 mid++; 88 mid++;
91 89
92 for (QStringList::Iterator it = sl.begin(); 90 for (QStringList::Iterator it = sl.begin();
93 it != sl.end(); ++it ) { 91 it != sl.end(); ++it ) {
94 int cid = c.id(appName, *it); 92 int cid = c.id(appName, *it);
95 insertItem(*it, mid); 93 insertItem(*it, mid);
96 menuToId.insert(mid, cid); 94 menuToId.insert(mid, cid);
97 idToMenu.insert(cid, mid); 95 idToMenu.insert(cid, mid);
98 mid++; 96 mid++;
99 } 97 }
100 98
101 setItemChecked(currentMid, TRUE ); 99 setItemChecked(currentMid, TRUE );
102} 100}
103 101
104/*! 102/*!
105 \internal 103 \internal
106*/ 104*/
107void CategoryMenu::mapMenuId(int id) 105void CategoryMenu::mapMenuId(int id)
108{ 106{
109 if (id == currentMid) 107 if (id == currentMid)
110 return; 108 return;
111 setItemChecked( currentMid, FALSE ); 109 setItemChecked( currentMid, FALSE );
112 setItemChecked( id, TRUE ); 110 setItemChecked( id, TRUE );
113 currentMid = id; 111 currentMid = id;
114 112
115 emit categoryChange(); 113 emit categoryChange();
116} 114}
117 115
118/*! 116/*!
119 Returns TRUE if a record or file with the set of category ids \a cUids 117 Returns TRUE if a record or file with the set of category ids \a cUids
120 is allowed by the current selection in the CategoryMenu. 118 is allowed by the current selection in the CategoryMenu.
121 Otherwise returns FALSE. 119 Otherwise returns FALSE.
122*/ 120*/
123bool CategoryMenu::isSelected(const QArray<int> &cUids) const 121bool CategoryMenu::isSelected(const QArray<int> &cUids) const
124{ 122{
125 if (currentMid == 1) 123 if (currentMid == 1)
126 return TRUE; 124 return TRUE;
127 125
128 if (currentMid == 2 && cUids.count() == 0) 126 if (currentMid == 2 && cUids.count() == 0)
129 return TRUE; 127 return TRUE;
130 128
131 if (cUids.contains(menuToId[currentMid])) 129 if (cUids.contains(menuToId[currentMid]))
132 return TRUE; 130 return TRUE;
133 131
134 return FALSE; 132 return FALSE;
135} 133}
136 134
137/*! 135/*!
138 Sets the menu to have \a newCatUid as the currently selected Category. 136 Sets the menu to have \a newCatUid as the currently selected Category.
139*/ 137*/
140void CategoryMenu::setCurrentCategory( int newCatUid ) 138void CategoryMenu::setCurrentCategory( int newCatUid )
141{ 139{
142 if (!idToMenu.contains(newCatUid)) 140 if (!idToMenu.contains(newCatUid))
143 return; 141 return;
144 142
145 mapMenuId(idToMenu[newCatUid]); 143 mapMenuId(idToMenu[newCatUid]);
146} 144}
147 145
148/*! 146/*!
149 Sets the menu to allow all category sets. 147 Sets the menu to allow all category sets.
150*/ 148*/
151void CategoryMenu::setCurrentCategoryAll( ) 149void CategoryMenu::setCurrentCategoryAll( )
152{ 150{
153 mapMenuId(1); 151 mapMenuId(1);
154} 152}
155 153
156/*! 154/*!
157 Sets the menu to allow only empty category sets. 155 Sets the menu to allow only empty category sets.
158*/ 156*/
159void CategoryMenu::setCurrentCategoryUnfiled( ) 157void CategoryMenu::setCurrentCategoryUnfiled( )
160{ 158{
161 mapMenuId(2); 159 mapMenuId(2);
162} 160}
diff --git a/library/config.cpp b/library/config.cpp
index b28c771..8b60f60 100644
--- a/library/config.cpp
+++ b/library/config.cpp
@@ -1,215 +1,213 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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>
23#include <qfileinfo.h>
24#include <qmessagebox.h> 22#include <qmessagebox.h>
25#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 23#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
26#include <qtextcodec.h> 24#include <qtextcodec.h>
27#endif 25#endif
28#include <qtextstream.h> 26#include <qtextstream.h>
29 27
30#include <sys/stat.h> 28#include <sys/stat.h>
31#include <sys/types.h> 29#include <sys/types.h>
32#include <fcntl.h> 30#include <fcntl.h>
33#include <stdlib.h> 31#include <stdlib.h>
34#include <unistd.h> 32#include <unistd.h>
35 33
36#define QTOPIA_INTERNAL_LANGLIST 34#define QTOPIA_INTERNAL_LANGLIST
37#include "config.h" 35#include "config.h"
38#include "global.h" 36#include "global.h"
39 37
40 38
41/*! 39/*!
42 \internal 40 \internal
43*/ 41*/
44QString Config::configFilename(const QString& name, Domain d) 42QString Config::configFilename(const QString& name, Domain d)
45{ 43{
46 switch (d) { 44 switch (d) {
47 case File: 45 case File:
48 return name; 46 return name;
49 case User: { 47 case User: {
50 QDir dir = (QString(getenv("HOME")) + "/Settings"); 48 QDir dir = (QString(getenv("HOME")) + "/Settings");
51 if ( !dir.exists() ) 49 if ( !dir.exists() )
52 mkdir(dir.path().local8Bit(),0700); 50 mkdir(dir.path().local8Bit(),0700);
53 return dir.path() + "/" + name + ".conf"; 51 return dir.path() + "/" + name + ".conf";
54 } 52 }
55 } 53 }
56 return name; 54 return name;
57} 55}
58 56
59/*! 57/*!
60 \class Config config.h 58 \class Config config.h
61 \brief The Config class provides for saving application cofniguration state. 59 \brief The Config class provides for saving application cofniguration state.
62 60
63 You should keep a Config in existence only while you do not want others 61 You should keep a Config in existence only while you do not want others
64 to be able to change the state. There is no locking currently, but there 62 to be able to change the state. There is no locking currently, but there
65 may be in the future. 63 may be in the future.
66*/ 64*/
67 65
68/*! 66/*!
69 \enum Config::ConfigGroup 67 \enum Config::ConfigGroup
70 \internal 68 \internal
71*/ 69*/
72 70
73/*! 71/*!
74 \enum Config::Domain 72 \enum Config::Domain
75 73
76 \value File 74 \value File
77 \value User 75 \value User
78 76
79 See Config for details. 77 See Config for details.
80*/ 78*/
81 79
82/*! 80/*!
83 Constructs a config that will load or create a configuration with the 81 Constructs a config that will load or create a configuration with the
84 given \a name in the given \a domain. 82 given \a name in the given \a domain.
85 83
86 You must call setGroup() before doing much else with the Config. 84 You must call setGroup() before doing much else with the Config.
87 85
88 In the default Domain, \e User, 86 In the default Domain, \e User,
89 the configuration is user-specific. \a name should not contain "/" in 87 the configuration is user-specific. \a name should not contain "/" in
90 this case, and in general should be the name of the C++ class that is 88 this case, and in general should be the name of the C++ class that is
91 primarily responsible for maintaining the configuration. 89 primarily responsible for maintaining the configuration.
92 90
93 In the File Domain, \a name is an absolute filename. 91 In the File Domain, \a name is an absolute filename.
94*/ 92*/
95Config::Config( const QString &name, Domain domain ) 93Config::Config( const QString &name, Domain domain )
96 : filename( configFilename(name,domain) ) 94 : filename( configFilename(name,domain) )
97{ 95{
98 git = groups.end(); 96 git = groups.end();
99 read(); 97 read();
100 QStringList l = Global::languageList(); 98 QStringList l = Global::languageList();
101 lang = l[0]; 99 lang = l[0];
102 glang = l[1]; 100 glang = l[1];
103} 101}
104 102
105 103
106// Sharp ROM compatibility 104// Sharp ROM compatibility
107Config::Config ( const QString &name, bool what ) 105Config::Config ( const QString &name, bool what )
108 : filename( configFilename(name,what ? User : File) ) 106 : filename( configFilename(name,what ? User : File) )
109{ 107{
110 git = groups.end(); 108 git = groups.end();
111 read(); 109 read();
112 QStringList l = Global::languageList(); 110 QStringList l = Global::languageList();
113 lang = l[0]; 111 lang = l[0];
114 glang = l[1]; 112 glang = l[1];
115} 113}
116 114
117/*! 115/*!
118 Writes any changes to disk and destroys the in-memory object. 116 Writes any changes to disk and destroys the in-memory object.
119*/ 117*/
120Config::~Config() 118Config::~Config()
121{ 119{
122 if ( changed ) 120 if ( changed )
123 write(); 121 write();
124} 122}
125 123
126/*! 124/*!
127 Returns whether the current group has an entry called \a key. 125 Returns whether the current group has an entry called \a key.
128*/ 126*/
129bool Config::hasKey( const QString &key ) const 127bool Config::hasKey( const QString &key ) const
130{ 128{
131 if ( groups.end() == git ) 129 if ( groups.end() == git )
132 return FALSE; 130 return FALSE;
133 ConfigGroup::ConstIterator it = ( *git ).find( key ); 131 ConfigGroup::ConstIterator it = ( *git ).find( key );
134 return it != ( *git ).end(); 132 return it != ( *git ).end();
135} 133}
136 134
137/*! 135/*!
138 Sets the current group for subsequent reading and writing of 136 Sets the current group for subsequent reading and writing of
139 entries to \a gname. Grouping allows the application to partition the namespace. 137 entries to \a gname. Grouping allows the application to partition the namespace.
140 138
141 This function must be called prior to any reading or writing 139 This function must be called prior to any reading or writing
142 of entries. 140 of entries.
143 141
144 The \a gname must not be empty. 142 The \a gname must not be empty.
145*/ 143*/
146void Config::setGroup( const QString &gname ) 144void Config::setGroup( const QString &gname )
147{ 145{
148 QMap< QString, ConfigGroup>::Iterator it = groups.find( gname ); 146 QMap< QString, ConfigGroup>::Iterator it = groups.find( gname );
149 if ( it == groups.end() ) { 147 if ( it == groups.end() ) {
150 git = groups.insert( gname, ConfigGroup() ); 148 git = groups.insert( gname, ConfigGroup() );
151 changed = TRUE; 149 changed = TRUE;
152 return; 150 return;
153 } 151 }
154 git = it; 152 git = it;
155} 153}
156 154
157/*! 155/*!
158 Writes a (\a key, \a value) entry to the current group. 156 Writes a (\a key, \a value) entry to the current group.
159 157
160 \sa readEntry() 158 \sa readEntry()
161*/ 159*/
162void Config::writeEntry( const QString &key, const char* value ) 160void Config::writeEntry( const QString &key, const char* value )
163{ 161{
164 writeEntry(key,QString(value)); 162 writeEntry(key,QString(value));
165} 163}
166 164
167/*! 165/*!
168 Writes a (\a key, \a value) entry to the current group. 166 Writes a (\a key, \a value) entry to the current group.
169 167
170 \sa readEntry() 168 \sa readEntry()
171*/ 169*/
172void Config::writeEntry( const QString &key, const QString &value ) 170void Config::writeEntry( const QString &key, const QString &value )
173{ 171{
174 if ( git == groups.end() ) { 172 if ( git == groups.end() ) {
175 qWarning( "no group set" ); 173 qWarning( "no group set" );
176 return; 174 return;
177 } 175 }
178 if ( (*git)[key] != value ) { 176 if ( (*git)[key] != value ) {
179 ( *git ).insert( key, value ); 177 ( *git ).insert( key, value );
180 changed = TRUE; 178 changed = TRUE;
181 } 179 }
182} 180}
183 181
184/* 182/*
185 Note that the degree of protection offered by the encryption here is 183 Note that the degree of protection offered by the encryption here is
186 only sufficient to avoid the most casual observation of the configuration 184 only sufficient to avoid the most casual observation of the configuration
187 files. People with access to the files can write down the contents and 185 files. People with access to the files can write down the contents and
188 decrypt it using this source code. 186 decrypt it using this source code.
189 187
190 Conceivably, and at some burden to the user, this encryption could 188 Conceivably, and at some burden to the user, this encryption could
191 be improved. 189 be improved.
192*/ 190*/
193static QString encipher(const QString& plain) 191static QString encipher(const QString& plain)
194{ 192{
195 // mainly, we make it long 193 // mainly, we make it long
196 QString cipher; 194 QString cipher;
197 int mix=28730492; 195 int mix=28730492;
198 for (int i=0; i<(int)plain.length(); i++) { 196 for (int i=0; i<(int)plain.length(); i++) {
199 int u = plain[i].unicode(); 197 int u = plain[i].unicode();
200 int c = u ^ mix; 198 int c = u ^ mix;
201 QString x = QString::number(c,36); 199 QString x = QString::number(c,36);
202 cipher.append(QChar('a'+x.length())); 200 cipher.append(QChar('a'+x.length()));
203 cipher.append(x); 201 cipher.append(x);
204 mix *= u; 202 mix *= u;
205 } 203 }
206 return cipher; 204 return cipher;
207} 205}
208 206
209static QString decipher(const QString& cipher) 207static QString decipher(const QString& cipher)
210{ 208{
211 QString plain; 209 QString plain;
212 int mix=28730492; 210 int mix=28730492;
213 for (int i=0; i<(int)cipher.length();) { 211 for (int i=0; i<(int)cipher.length();) {
214 int l = cipher[i].unicode()-'a'; 212 int l = cipher[i].unicode()-'a';
215 QString x = cipher.mid(i+1,l); i+=l+1; 213 QString x = cipher.mid(i+1,l); i+=l+1;
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp
index 188d8e1..e4ec2bf 100644
--- a/library/datebookdb.cpp
+++ b/library/datebookdb.cpp
@@ -1,225 +1,220 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 <qasciidict.h> 21#include <qasciidict.h>
22#include <qfile.h>
23#include <qmessagebox.h> 22#include <qmessagebox.h>
24#include <qstring.h>
25#include <qtextcodec.h>
26#include <qtextstream.h>
27#include <qtl.h> 23#include <qtl.h>
28 24
29#include <qpe/alarmserver.h> 25#include <qpe/alarmserver.h>
30#include <qpe/global.h> 26#include <qpe/global.h>
31#include "datebookdb.h" 27#include "datebookdb.h"
32#include <qpe/stringutil.h> 28#include <qpe/stringutil.h>
33#include <qpe/timeconversion.h>
34 29
35#include <errno.h> 30#include <errno.h>
36#include <stdlib.h> 31#include <stdlib.h>
37 32
38 33
39class DateBookDBPrivate 34class DateBookDBPrivate
40{ 35{
41public: 36public:
42 bool clean; // indcate whether we need to write to disk... 37 bool clean; // indcate whether we need to write to disk...
43}; 38};
44 39
45 40
46// Helper functions 41// Helper functions
47 42
48static QString dateBookJournalFile() 43static QString dateBookJournalFile()
49{ 44{
50 QString str = getenv("HOME"); 45 QString str = getenv("HOME");
51 return QString( str +"/.caljournal" ); 46 return QString( str +"/.caljournal" );
52} 47}
53 48
54static QString dateBookFilename() 49static QString dateBookFilename()
55{ 50{
56 return Global::applicationFileName("datebook","datebook.xml"); 51 return Global::applicationFileName("datebook","datebook.xml");
57} 52}
58 53
59/* Calculating the next event of a recuring event is actually 54/* Calculating the next event of a recuring event is actually
60 computationally inexpensive, esp. compared to checking each day 55 computationally inexpensive, esp. compared to checking each day
61 individually. There are bad worse cases for say the 29th of 56 individually. There are bad worse cases for say the 29th of
62 february or the 31st of some other months. However 57 february or the 31st of some other months. However
63 these are still bounded */ 58 these are still bounded */
64bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) 59bool nextOccurance(const Event &e, const QDate &from, QDateTime &next)
65{ 60{
66 // easy checks, first are we too far in the future or too far in the past? 61 // easy checks, first are we too far in the future or too far in the past?
67 QDate tmpDate; 62 QDate tmpDate;
68 int freq = e.repeatPattern().frequency; 63 int freq = e.repeatPattern().frequency;
69 int diff, diff2, a; 64 int diff, diff2, a;
70 int iday, imonth, iyear; 65 int iday, imonth, iyear;
71 int dayOfWeek = 0; 66 int dayOfWeek = 0;
72 int firstOfWeek = 0; 67 int firstOfWeek = 0;
73 int weekOfMonth; 68 int weekOfMonth;
74 69
75 70
76 if (e.repeatPattern().hasEndDate && e.repeatPattern().endDate() < from) 71 if (e.repeatPattern().hasEndDate && e.repeatPattern().endDate() < from)
77 return FALSE; 72 return FALSE;
78 73
79 if (e.start() >= from) { 74 if (e.start() >= from) {
80 next = e.start(); 75 next = e.start();
81 return TRUE; 76 return TRUE;
82 } 77 }
83 78
84 switch ( e.repeatPattern().type ) { 79 switch ( e.repeatPattern().type ) {
85 case Event::Weekly: 80 case Event::Weekly:
86 /* weekly is just daily by 7 */ 81 /* weekly is just daily by 7 */
87 /* first convert the repeatPattern.Days() mask to the next 82 /* first convert the repeatPattern.Days() mask to the next
88 day of week valid after from */ 83 day of week valid after from */
89 dayOfWeek = from.dayOfWeek(); 84 dayOfWeek = from.dayOfWeek();
90 dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ 85 dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */
91 86
92 /* this is done in case freq > 1 and from in week not 87 /* this is done in case freq > 1 and from in week not
93 for this round */ 88 for this round */
94 // firstOfWeek = 0; this is already done at decl. 89 // firstOfWeek = 0; this is already done at decl.
95 while(!((1 << firstOfWeek) & e.repeatPattern().days)) 90 while(!((1 << firstOfWeek) & e.repeatPattern().days))
96 firstOfWeek++; 91 firstOfWeek++;
97 92
98 93
99 94
100 /* there is at least one 'day', or there would be no event */ 95 /* there is at least one 'day', or there would be no event */
101 while(!((1 << (dayOfWeek % 7)) & e.repeatPattern().days)) 96 while(!((1 << (dayOfWeek % 7)) & e.repeatPattern().days))
102 dayOfWeek++; 97 dayOfWeek++;
103 98
104 99
105 dayOfWeek = dayOfWeek % 7; /* the actual day of week */ 100 dayOfWeek = dayOfWeek % 7; /* the actual day of week */
106 dayOfWeek -= e.start().date().dayOfWeek() -1; 101 dayOfWeek -= e.start().date().dayOfWeek() -1;
107 102
108 firstOfWeek = firstOfWeek % 7; /* the actual first of week */ 103 firstOfWeek = firstOfWeek % 7; /* the actual first of week */
109 firstOfWeek -= e.start().date().dayOfWeek() -1; 104 firstOfWeek -= e.start().date().dayOfWeek() -1;
110 105
111 // dayOfWeek may be negitive now 106 // dayOfWeek may be negitive now
112 // day of week is number of days to add to start day 107 // day of week is number of days to add to start day
113 108
114 freq *= 7; 109 freq *= 7;
115 // FALL-THROUGH !!!!! 110 // FALL-THROUGH !!!!!
116 case Event::Daily: 111 case Event::Daily:
117 // the add is for the possible fall through from weekly */ 112 // the add is for the possible fall through from weekly */
118 if(e.start().date().addDays(dayOfWeek) > from) { 113 if(e.start().date().addDays(dayOfWeek) > from) {
119 /* first week exception */ 114 /* first week exception */
120 next = QDateTime(e.start().date().addDays(dayOfWeek), 115 next = QDateTime(e.start().date().addDays(dayOfWeek),
121 e.start().time()); 116 e.start().time());
122 if ((next.date() > e.repeatPattern().endDate()) 117 if ((next.date() > e.repeatPattern().endDate())
123 && e.repeatPattern().hasEndDate) 118 && e.repeatPattern().hasEndDate)
124 return FALSE; 119 return FALSE;
125 return TRUE; 120 return TRUE;
126 } 121 }
127 /* if from is middle of a non-week */ 122 /* if from is middle of a non-week */
128 123
129 diff = e.start().date().addDays(dayOfWeek).daysTo(from) % freq; 124 diff = e.start().date().addDays(dayOfWeek).daysTo(from) % freq;
130 diff2 = e.start().date().addDays(firstOfWeek).daysTo(from) % freq; 125 diff2 = e.start().date().addDays(firstOfWeek).daysTo(from) % freq;
131 126
132 if(diff != 0) 127 if(diff != 0)
133 diff = freq - diff; 128 diff = freq - diff;
134 if(diff2 != 0) 129 if(diff2 != 0)
135 diff2 = freq - diff2; 130 diff2 = freq - diff2;
136 diff = QMIN(diff, diff2); 131 diff = QMIN(diff, diff2);
137 132
138 next = QDateTime(from.addDays(diff), e.start().time()); 133 next = QDateTime(from.addDays(diff), e.start().time());
139 if ( (next.date() > e.repeatPattern().endDate()) 134 if ( (next.date() > e.repeatPattern().endDate())
140 && e.repeatPattern().hasEndDate ) 135 && e.repeatPattern().hasEndDate )
141 return FALSE; 136 return FALSE;
142 return TRUE; 137 return TRUE;
143 case Event::MonthlyDay: 138 case Event::MonthlyDay:
144 iday = from.day(); 139 iday = from.day();
145 iyear = from.year(); 140 iyear = from.year();
146 imonth = from.month(); 141 imonth = from.month();
147 /* find equivelent day of month for this month */ 142 /* find equivelent day of month for this month */
148 dayOfWeek = e.start().date().dayOfWeek(); 143 dayOfWeek = e.start().date().dayOfWeek();
149 weekOfMonth = (e.start().date().day() - 1) / 7; 144 weekOfMonth = (e.start().date().day() - 1) / 7;
150 145
151 /* work out when the next valid month is */ 146 /* work out when the next valid month is */
152 a = from.year() - e.start().date().year(); 147 a = from.year() - e.start().date().year();
153 a *= 12; 148 a *= 12;
154 a = a + (imonth - e.start().date().month()); 149 a = a + (imonth - e.start().date().month());
155 /* a is e.start()monthsFrom(from); */ 150 /* a is e.start()monthsFrom(from); */
156 if(a % freq) { 151 if(a % freq) {
157 a = freq - (a % freq); 152 a = freq - (a % freq);
158 imonth = from.month() + a; 153 imonth = from.month() + a;
159 if (imonth > 12) { 154 if (imonth > 12) {
160 imonth--; 155 imonth--;
161 iyear += imonth / 12; 156 iyear += imonth / 12;
162 imonth = imonth % 12; 157 imonth = imonth % 12;
163 imonth++; 158 imonth++;
164 } 159 }
165 } 160 }
166 /* imonth is now the first month after or on 161 /* imonth is now the first month after or on
167 from that matches the frequency given */ 162 from that matches the frequency given */
168 163
169 /* find for this month */ 164 /* find for this month */
170 tmpDate = QDate( iyear, imonth, 1 ); 165 tmpDate = QDate( iyear, imonth, 1 );
171 166
172 iday = 1; 167 iday = 1;
173 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; 168 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
174 iday += 7 * weekOfMonth; 169 iday += 7 * weekOfMonth;
175 while (iday > tmpDate.daysInMonth()) { 170 while (iday > tmpDate.daysInMonth()) {
176 imonth += freq; 171 imonth += freq;
177 if (imonth > 12) { 172 if (imonth > 12) {
178 imonth--; 173 imonth--;
179 iyear += imonth / 12; 174 iyear += imonth / 12;
180 imonth = imonth % 12; 175 imonth = imonth % 12;
181 imonth++; 176 imonth++;
182 } 177 }
183 tmpDate = QDate( iyear, imonth, 1 ); 178 tmpDate = QDate( iyear, imonth, 1 );
184 /* these loops could go for a while, check end case now */ 179 /* these loops could go for a while, check end case now */
185 if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 180 if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
186 return FALSE; 181 return FALSE;
187 iday = 1; 182 iday = 1;
188 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; 183 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
189 iday += 7 * weekOfMonth; 184 iday += 7 * weekOfMonth;
190 } 185 }
191 tmpDate = QDate(iyear, imonth, iday); 186 tmpDate = QDate(iyear, imonth, iday);
192 187
193 if (tmpDate >= from) { 188 if (tmpDate >= from) {
194 next = QDateTime(tmpDate, e.start().time()); 189 next = QDateTime(tmpDate, e.start().time());
195 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 190 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
196 return FALSE; 191 return FALSE;
197 return TRUE; 192 return TRUE;
198 } 193 }
199 194
200 /* need to find the next iteration */ 195 /* need to find the next iteration */
201 do { 196 do {
202 imonth += freq; 197 imonth += freq;
203 if (imonth > 12) { 198 if (imonth > 12) {
204 imonth--; 199 imonth--;
205 iyear += imonth / 12; 200 iyear += imonth / 12;
206 imonth = imonth % 12; 201 imonth = imonth % 12;
207 imonth++; 202 imonth++;
208 } 203 }
209 tmpDate = QDate( iyear, imonth, 1 ); 204 tmpDate = QDate( iyear, imonth, 1 );
210 /* these loops could go for a while, check end case now */ 205 /* these loops could go for a while, check end case now */
211 if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 206 if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
212 return FALSE; 207 return FALSE;
213 iday = 1; 208 iday = 1;
214 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; 209 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
215 iday += 7 * weekOfMonth; 210 iday += 7 * weekOfMonth;
216 } while (iday > tmpDate.daysInMonth()); 211 } while (iday > tmpDate.daysInMonth());
217 tmpDate = QDate(iyear, imonth, iday); 212 tmpDate = QDate(iyear, imonth, iday);
218 213
219 next = QDateTime(tmpDate, e.start().time()); 214 next = QDateTime(tmpDate, e.start().time());
220 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 215 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
221 return FALSE; 216 return FALSE;
222 return TRUE; 217 return TRUE;
223 case Event::MonthlyDate: 218 case Event::MonthlyDate:
224 iday = e.start().date().day(); 219 iday = e.start().date().day();
225 iyear = from.year(); 220 iyear = from.year();
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index 728045f..76e022f 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,225 +1,220 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "config.h" 20#include "config.h"
21#include "datebookmonth.h" 21#include "datebookmonth.h"
22#include "datebookdb.h" 22#include "datebookdb.h"
23#include <qtopia/private/event.h>
24#include "resource.h" 23#include "resource.h"
25#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
26#include "timestring.h"
27 25
28#include <qtoolbutton.h> 26#include <qtoolbutton.h>
29#include <qspinbox.h> 27#include <qspinbox.h>
30#include <qcombobox.h> 28#include <qcombobox.h>
31#include <qdatetime.h>
32#include <qpainter.h>
33#include <qpopupmenu.h>
34#include <qvaluestack.h> 29#include <qvaluestack.h>
35#include <qwhatsthis.h> 30#include <qwhatsthis.h>
36 31
37 32
38DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) 33DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
39 : QHBox( parent, name ) 34 : QHBox( parent, name )
40{ 35{
41 setBackgroundMode( PaletteButton ); 36 setBackgroundMode( PaletteButton );
42 37
43 begin = new QToolButton( this ); 38 begin = new QToolButton( this );
44 begin->setFocusPolicy(NoFocus); 39 begin->setFocusPolicy(NoFocus);
45 begin->setPixmap( Resource::loadPixmap( "start" ) ); 40 begin->setPixmap( Resource::loadPixmap( "start" ) );
46 begin->setAutoRaise( TRUE ); 41 begin->setAutoRaise( TRUE );
47 begin->setFixedSize( begin->sizeHint() ); 42 begin->setFixedSize( begin->sizeHint() );
48 QWhatsThis::add( begin, tr("Show January in the selected year") ); 43 QWhatsThis::add( begin, tr("Show January in the selected year") );
49 44
50 back = new QToolButton( this ); 45 back = new QToolButton( this );
51 back->setFocusPolicy(NoFocus); 46 back->setFocusPolicy(NoFocus);
52 back->setPixmap( Resource::loadPixmap( "back" ) ); 47 back->setPixmap( Resource::loadPixmap( "back" ) );
53 back->setAutoRaise( TRUE ); 48 back->setAutoRaise( TRUE );
54 back->setFixedSize( back->sizeHint() ); 49 back->setFixedSize( back->sizeHint() );
55 QWhatsThis::add( back, tr("Show the previous month") ); 50 QWhatsThis::add( back, tr("Show the previous month") );
56 51
57 month = new QComboBox( FALSE, this ); 52 month = new QComboBox( FALSE, this );
58 for ( int i = 0; i < 12; ++i ) 53 for ( int i = 0; i < 12; ++i )
59 month->insertItem( Calendar::nameOfMonth( i + 1 ) ); 54 month->insertItem( Calendar::nameOfMonth( i + 1 ) );
60 55
61 year = new QSpinBox( 1752, 8000, 1, this ); 56 year = new QSpinBox( 1752, 8000, 1, this );
62 57
63 next = new QToolButton( this ); 58 next = new QToolButton( this );
64 next->setFocusPolicy(NoFocus); 59 next->setFocusPolicy(NoFocus);
65 next->setPixmap( Resource::loadPixmap( "forward" ) ); 60 next->setPixmap( Resource::loadPixmap( "forward" ) );
66 next->setAutoRaise( TRUE ); 61 next->setAutoRaise( TRUE );
67 next->setFixedSize( next->sizeHint() ); 62 next->setFixedSize( next->sizeHint() );
68 QWhatsThis::add( next, tr("Show the next month") ); 63 QWhatsThis::add( next, tr("Show the next month") );
69 64
70 end = new QToolButton( this ); 65 end = new QToolButton( this );
71 end->setFocusPolicy(NoFocus); 66 end->setFocusPolicy(NoFocus);
72 end->setPixmap( Resource::loadPixmap( "finish" ) ); 67 end->setPixmap( Resource::loadPixmap( "finish" ) );
73 end->setAutoRaise( TRUE ); 68 end->setAutoRaise( TRUE );
74 end->setFixedSize( end->sizeHint() ); 69 end->setFixedSize( end->sizeHint() );
75 QWhatsThis::add( end, tr("Show December in the selected year") ); 70 QWhatsThis::add( end, tr("Show December in the selected year") );
76 71
77 connect( month, SIGNAL( activated( int ) ), 72 connect( month, SIGNAL( activated( int ) ),
78 this, SLOT( updateDate() ) ); 73 this, SLOT( updateDate() ) );
79 connect( year, SIGNAL( valueChanged( int ) ), 74 connect( year, SIGNAL( valueChanged( int ) ),
80 this, SLOT( updateDate() ) ); 75 this, SLOT( updateDate() ) );
81 connect( begin, SIGNAL( clicked() ), 76 connect( begin, SIGNAL( clicked() ),
82 this, SLOT( firstMonth() ) ); 77 this, SLOT( firstMonth() ) );
83 connect( end, SIGNAL( clicked() ), 78 connect( end, SIGNAL( clicked() ),
84 this, SLOT( lastMonth() ) ); 79 this, SLOT( lastMonth() ) );
85 connect( back, SIGNAL( clicked() ), 80 connect( back, SIGNAL( clicked() ),
86 this, SLOT( monthBack() ) ); 81 this, SLOT( monthBack() ) );
87 connect( next, SIGNAL( clicked() ), 82 connect( next, SIGNAL( clicked() ),
88 this, SLOT( monthForward() ) ); 83 this, SLOT( monthForward() ) );
89 back->setAutoRepeat( TRUE ); 84 back->setAutoRepeat( TRUE );
90 next->setAutoRepeat( TRUE ); 85 next->setAutoRepeat( TRUE );
91} 86}
92 87
93 88
94DateBookMonthHeader::~DateBookMonthHeader() 89DateBookMonthHeader::~DateBookMonthHeader()
95{ 90{
96 91
97} 92}
98 93
99void DateBookMonthHeader::updateDate() 94void DateBookMonthHeader::updateDate()
100{ 95{
101 emit dateChanged( year->value(), month->currentItem() + 1 ); 96 emit dateChanged( year->value(), month->currentItem() + 1 );
102} 97}
103 98
104void DateBookMonthHeader::firstMonth() 99void DateBookMonthHeader::firstMonth()
105{ 100{
106 emit dateChanged( year->value(), 1 ); 101 emit dateChanged( year->value(), 1 );
107 month->setCurrentItem( 0 ); 102 month->setCurrentItem( 0 );
108} 103}
109 104
110void DateBookMonthHeader::lastMonth() 105void DateBookMonthHeader::lastMonth()
111{ 106{
112 emit dateChanged( year->value(), 12 ); 107 emit dateChanged( year->value(), 12 );
113 month->setCurrentItem( 11 ); 108 month->setCurrentItem( 11 );
114} 109}
115 110
116void DateBookMonthHeader::monthBack() 111void DateBookMonthHeader::monthBack()
117{ 112{
118 if ( month->currentItem() > 0 ) { 113 if ( month->currentItem() > 0 ) {
119 emit dateChanged( year->value(), month->currentItem() ); 114 emit dateChanged( year->value(), month->currentItem() );
120 month->setCurrentItem( month->currentItem() - 1 ); 115 month->setCurrentItem( month->currentItem() - 1 );
121 } else { 116 } else {
122 emit dateChanged( year->value() - 1, 12 ); 117 emit dateChanged( year->value() - 1, 12 );
123 // we have a signal set to a changed value in year so we only need to change 118 // we have a signal set to a changed value in year so we only need to change
124 // year to get the result... 119 // year to get the result...
125 month->setCurrentItem( 11 ); 120 month->setCurrentItem( 11 );
126 year->setValue( year->value() - 1 ); 121 year->setValue( year->value() - 1 );
127 } 122 }
128} 123}
129 124
130void DateBookMonthHeader::monthForward() 125void DateBookMonthHeader::monthForward()
131{ 126{
132 if ( month->currentItem() < 11 ) { 127 if ( month->currentItem() < 11 ) {
133 emit dateChanged( year->value(), month->currentItem() + 2 ); 128 emit dateChanged( year->value(), month->currentItem() + 2 );
134 month->setCurrentItem( month->currentItem() + 1 ); 129 month->setCurrentItem( month->currentItem() + 1 );
135 } else { 130 } else {
136 // we have a signal set to a changed value in year so we only need to change 131 // we have a signal set to a changed value in year so we only need to change
137 // year to get the result... 132 // year to get the result...
138 month->setCurrentItem( 0 ); 133 month->setCurrentItem( 0 );
139 year->setValue( year->value() + 1 ); 134 year->setValue( year->value() + 1 );
140 } 135 }
141} 136}
142 137
143void DateBookMonthHeader::setDate( int y, int m ) 138void DateBookMonthHeader::setDate( int y, int m )
144{ 139{
145 year->setValue( y ); 140 year->setValue( y );
146 month->setCurrentItem( m - 1 ); 141 month->setCurrentItem( m - 1 );
147} 142}
148 143
149//--------------------------------------------------------------------------- 144//---------------------------------------------------------------------------
150 145
151class DateBookMonthTablePrivate 146class DateBookMonthTablePrivate
152{ 147{
153public: 148public:
154 DateBookMonthTablePrivate() {}; 149 DateBookMonthTablePrivate() {};
155 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); }; 150 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); };
156 151
157 QValueList<EffectiveEvent> mMonthEvents; 152 QValueList<EffectiveEvent> mMonthEvents;
158 bool onMonday; 153 bool onMonday;
159}; 154};
160 155
161DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name, 156DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name,
162 DateBookDB *newDb ) 157 DateBookDB *newDb )
163 : QTable( 6, 7, parent, name ), 158 : QTable( 6, 7, parent, name ),
164 db( newDb ) 159 db( newDb )
165{ 160{
166 d = new DateBookMonthTablePrivate(); 161 d = new DateBookMonthTablePrivate();
167 selYear = -1; 162 selYear = -1;
168 selMonth = -1; 163 selMonth = -1;
169 selDay = -1; 164 selDay = -1;
170 165
171 /* init these as well make valgrind happy and be consistent with Qtopia1.6 -zecke */ 166 /* init these as well make valgrind happy and be consistent with Qtopia1.6 -zecke */
172 year = -1; 167 year = -1;
173 month = -1; 168 month = -1;
174 day = -1; 169 day = -1;
175 170
176 Config cfg( "qpe" ); 171 Config cfg( "qpe" );
177 cfg.setGroup( "Time" ); 172 cfg.setGroup( "Time" );
178 d->onMonday = cfg.readBoolEntry( "MONDAY" ); 173 d->onMonday = cfg.readBoolEntry( "MONDAY" );
179 174
180 horizontalHeader()->setResizeEnabled( FALSE ); 175 horizontalHeader()->setResizeEnabled( FALSE );
181 // we have to do this here... or suffer the consequences later... 176 // we have to do this here... or suffer the consequences later...
182 for ( int i = 0; i < 7; i++ ){ 177 for ( int i = 0; i < 7; i++ ){
183 horizontalHeader()->resizeSection( i, 30 ); 178 horizontalHeader()->resizeSection( i, 30 );
184 setColumnStretchable( i, TRUE ); 179 setColumnStretchable( i, TRUE );
185 } 180 }
186 setupLabels(); 181 setupLabels();
187 182
188 verticalHeader()->hide(); 183 verticalHeader()->hide();
189 setLeftMargin( 0 ); 184 setLeftMargin( 0 );
190 for ( int i = 0; i < 6; ++i ) 185 for ( int i = 0; i < 6; ++i )
191 setRowStretchable( i, TRUE ); 186 setRowStretchable( i, TRUE );
192 187
193 setSelectionMode( NoSelection ); 188 setSelectionMode( NoSelection );
194 189
195 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 190 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
196 this, SLOT( dayClicked( int, int ) ) ); 191 this, SLOT( dayClicked( int, int ) ) );
197 connect( this, SIGNAL( currentChanged( int, int ) ), 192 connect( this, SIGNAL( currentChanged( int, int ) ),
198 this, SLOT( dragDay( int, int ) ) ); 193 this, SLOT( dragDay( int, int ) ) );
199 setVScrollBarMode( AlwaysOff ); 194 setVScrollBarMode( AlwaysOff );
200 setHScrollBarMode( AlwaysOff ); 195 setHScrollBarMode( AlwaysOff );
201} 196}
202 197
203DateBookMonthTable::~DateBookMonthTable() 198DateBookMonthTable::~DateBookMonthTable()
204{ 199{
205 monthsEvents.clear(); 200 monthsEvents.clear();
206 delete d; 201 delete d;
207} 202}
208 203
209void DateBookMonthTable::setDate(int y, int m, int d) 204void DateBookMonthTable::setDate(int y, int m, int d)
210{ 205{
211 if (month == m && year == y) { 206 if (month == m && year == y) {
212 if ( selYear == -1 ) 207 if ( selYear == -1 )
213 year = selYear; 208 year = selYear;
214 if ( selMonth == -1 ) 209 if ( selMonth == -1 )
215 month = selMonth; 210 month = selMonth;
216 int r1, c1, r2, c2; 211 int r1, c1, r2, c2;
217 findDay(selDay, r1, c1); 212 findDay(selDay, r1, c1);
218 selDay = day = d; 213 selDay = day = d;
219 findDay(selDay, r2, c2); 214 findDay(selDay, r2, c2);
220 setCurrentCell( r2, c2 ); 215 setCurrentCell( r2, c2 );
221 //updateCell(r1,c1); 216 //updateCell(r1,c1);
222 //updateCell(r2,c2); 217 //updateCell(r2,c2);
223 } else { 218 } else {
224 selYear = year = y; 219 selYear = year = y;
225 selMonth = month = m; 220 selMonth = month = m;
diff --git a/library/filemanager.cpp b/library/filemanager.cpp
index 408be20..1e7384e 100644
--- a/library/filemanager.cpp
+++ b/library/filemanager.cpp
@@ -1,219 +1,216 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 "filemanager.h" 20#include "filemanager.h"
21#include "applnk.h" 21#include "applnk.h"
22 22
23#include <qdir.h>
24#include <qfile.h>
25#include <qfileinfo.h> 23#include <qfileinfo.h>
26#include <qtextstream.h> 24#include <qtextstream.h>
27#include <qtextcodec.h>
28 25
29#include <errno.h> 26#include <errno.h>
30#include <stdlib.h> 27#include <stdlib.h>
31#include <unistd.h> 28#include <unistd.h>
32#include <sys/stat.h> 29#include <sys/stat.h>
33#include <dirent.h> 30#include <dirent.h>
34#ifdef Q_OS_MACX 31#ifdef Q_OS_MACX
35// MacOS X does not have sendfile.. :( 32// MacOS X does not have sendfile.. :(
36// But maybe in the future.. !? 33// But maybe in the future.. !?
37# ifdef SENDFILE 34# ifdef SENDFILE
38# include <sys/types.h> 35# include <sys/types.h>
39# include <sys/socket.h> 36# include <sys/socket.h>
40# endif 37# endif
41#else 38#else
42# include <sys/sendfile.h> 39# include <sys/sendfile.h>
43#endif /* Q_OS_MACX */ 40#endif /* Q_OS_MACX */
44#include <fcntl.h> 41#include <fcntl.h>
45 42
46/*! 43/*!
47 \class FileManager 44 \class FileManager
48 \brief The FileManager class assists with AppLnk input/output. 45 \brief The FileManager class assists with AppLnk input/output.
49*/ 46*/
50 47
51/*! 48/*!
52 Constructs a FileManager. 49 Constructs a FileManager.
53*/ 50*/
54FileManager::FileManager() 51FileManager::FileManager()
55{ 52{
56} 53}
57 54
58/*! 55/*!
59 Destroys a FileManager. 56 Destroys a FileManager.
60*/ 57*/
61FileManager::~FileManager() 58FileManager::~FileManager()
62{ 59{
63 60
64} 61}
65 62
66/*! 63/*!
67 Saves \a data as the document specified by \a f. 64 Saves \a data as the document specified by \a f.
68 65
69 Returns whether the operation succeeded. 66 Returns whether the operation succeeded.
70*/ 67*/
71bool FileManager::saveFile( const DocLnk &f, const QByteArray &data ) 68bool FileManager::saveFile( const DocLnk &f, const QByteArray &data )
72{ 69{
73 QString fn = f.file() + ".new"; 70 QString fn = f.file() + ".new";
74 ensurePathExists( fn ); 71 ensurePathExists( fn );
75 QFile fl( fn ); 72 QFile fl( fn );
76 if ( !fl.open( IO_WriteOnly|IO_Raw ) ) { 73 if ( !fl.open( IO_WriteOnly|IO_Raw ) ) {
77 qWarning("open failed"); 74 qWarning("open failed");
78 return FALSE; 75 return FALSE;
79 } 76 }
80 int total_written = fl.writeBlock( data ); 77 int total_written = fl.writeBlock( data );
81 fl.close(); 78 fl.close();
82 if ( total_written != int(data.size()) || !f.writeLink() ) { 79 if ( total_written != int(data.size()) || !f.writeLink() ) {
83 QFile::remove( fn ); 80 QFile::remove( fn );
84 return FALSE; 81 return FALSE;
85 } 82 }
86 qDebug("total written %d out of %d", total_written, data.size()); 83 qDebug("total written %d out of %d", total_written, data.size());
87 // else rename the file... 84 // else rename the file...
88 if ( !renameFile( fn.latin1(), f.file().latin1() ) ) { 85 if ( !renameFile( fn.latin1(), f.file().latin1() ) ) {
89 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(), 86 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
90 f.file().latin1(), errno ); 87 f.file().latin1(), errno );
91 // remove the file... 88 // remove the file...
92 } 89 }
93 return TRUE; 90 return TRUE;
94} 91}
95 92
96/*! 93/*!
97 Saves \a text as the document specified by \a f. 94 Saves \a text as the document specified by \a f.
98 95
99 The text is saved in UTF8 format. 96 The text is saved in UTF8 format.
100 97
101 Returns whether the operation succeeded. 98 Returns whether the operation succeeded.
102*/ 99*/
103bool FileManager::saveFile( const DocLnk &f, const QString &text ) 100bool FileManager::saveFile( const DocLnk &f, const QString &text )
104{ 101{
105 QString fn = f.file() + ".new"; 102 QString fn = f.file() + ".new";
106 ensurePathExists( fn ); 103 ensurePathExists( fn );
107 QFile fl( fn ); 104 QFile fl( fn );
108 if ( !fl.open( IO_WriteOnly|IO_Raw ) ) { 105 if ( !fl.open( IO_WriteOnly|IO_Raw ) ) {
109 qWarning("open failed"); 106 qWarning("open failed");
110 return FALSE; 107 return FALSE;
111 } 108 }
112 109
113 QCString cstr = text.utf8(); 110 QCString cstr = text.utf8();
114 int total_written; 111 int total_written;
115 total_written = fl.writeBlock( cstr.data(), cstr.length() ); 112 total_written = fl.writeBlock( cstr.data(), cstr.length() );
116 fl.close(); 113 fl.close();
117 if ( total_written != int(cstr.length()) || !f.writeLink() ) { 114 if ( total_written != int(cstr.length()) || !f.writeLink() ) {
118 QFile::remove( fn ); 115 QFile::remove( fn );
119 return FALSE; 116 return FALSE;
120 } 117 }
121 // okay now rename the file.. 118 // okay now rename the file..
122 if ( !renameFile( fn.latin1(), f.file().latin1() ) ) { 119 if ( !renameFile( fn.latin1(), f.file().latin1() ) ) {
123 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(), 120 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
124 f.file().latin1(), errno ); 121 f.file().latin1(), errno );
125 122
126 } 123 }
127 return TRUE; 124 return TRUE;
128} 125}
129 126
130 127
131/*! 128/*!
132 Loads \a text from the document specified by \a f. 129 Loads \a text from the document specified by \a f.
133 130
134 The text is required to be in UTF8 format. 131 The text is required to be in UTF8 format.
135 132
136 Returns whether the operation succeeded. 133 Returns whether the operation succeeded.
137*/ 134*/
138bool FileManager::loadFile( const DocLnk &f, QString &text ) 135bool FileManager::loadFile( const DocLnk &f, QString &text )
139{ 136{
140 QString fn = f.file(); 137 QString fn = f.file();
141 QFile fl( fn ); 138 QFile fl( fn );
142 if ( !fl.open( IO_ReadOnly ) ) 139 if ( !fl.open( IO_ReadOnly ) )
143 return FALSE; 140 return FALSE;
144 QTextStream ts( &fl ); 141 QTextStream ts( &fl );
145#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 142#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
146 // The below should work, but doesn't in Qt 2.3.0 143 // The below should work, but doesn't in Qt 2.3.0
147 ts.setCodec( QTextCodec::codecForMib( 106 ) ); 144 ts.setCodec( QTextCodec::codecForMib( 106 ) );
148#else 145#else
149 ts.setEncoding( QTextStream::UnicodeUTF8 ); 146 ts.setEncoding( QTextStream::UnicodeUTF8 );
150#endif 147#endif
151 text = ts.read(); 148 text = ts.read();
152 fl.close(); 149 fl.close();
153 return TRUE; 150 return TRUE;
154} 151}
155 152
156 153
157/*! 154/*!
158 Loads \a ba from the document specified by \a f. 155 Loads \a ba from the document specified by \a f.
159 156
160 Returns whether the operation succeeded. 157 Returns whether the operation succeeded.
161*/ 158*/
162bool FileManager::loadFile( const DocLnk &f, QByteArray &ba ) 159bool FileManager::loadFile( const DocLnk &f, QByteArray &ba )
163{ 160{
164 QString fn = f.file(); 161 QString fn = f.file();
165 QFile fl( fn ); 162 QFile fl( fn );
166 if ( !fl.open( IO_ReadOnly ) ) 163 if ( !fl.open( IO_ReadOnly ) )
167 return FALSE; 164 return FALSE;
168 ba.resize( fl.size() ); 165 ba.resize( fl.size() );
169 if ( fl.size() > 0 ) 166 if ( fl.size() > 0 )
170 fl.readBlock( ba.data(), fl.size() ); 167 fl.readBlock( ba.data(), fl.size() );
171 fl.close(); 168 fl.close();
172 return TRUE; 169 return TRUE;
173} 170}
174 171
175/*! 172/*!
176 Copies the document specified by \a src to the document specified 173 Copies the document specified by \a src to the document specified
177 by \a dest. 174 by \a dest.
178 175
179 Returns whether the operation succeeded. 176 Returns whether the operation succeeded.
180*/ 177*/
181bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest ) 178bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest )
182{ 179{
183 QFile sf( src.file() ); 180 QFile sf( src.file() );
184 if ( !sf.open( IO_ReadOnly ) ) 181 if ( !sf.open( IO_ReadOnly ) )
185 return FALSE; 182 return FALSE;
186 183
187 QString fn = dest.file() + ".new"; 184 QString fn = dest.file() + ".new";
188 ensurePathExists( fn ); 185 ensurePathExists( fn );
189 QFile df( fn ); 186 QFile df( fn );
190 if ( !df.open( IO_WriteOnly|IO_Raw ) ) 187 if ( !df.open( IO_WriteOnly|IO_Raw ) )
191 return FALSE; 188 return FALSE;
192 189
193 const int bufsize = 16384; 190 const int bufsize = 16384;
194 char buffer[bufsize]; 191 char buffer[bufsize];
195 bool ok = TRUE; 192 bool ok = TRUE;
196 int bytesRead = 0; 193 int bytesRead = 0;
197 while ( ok && !sf.atEnd() ) { 194 while ( ok && !sf.atEnd() ) {
198 bytesRead = sf.readBlock( buffer, bufsize ); 195 bytesRead = sf.readBlock( buffer, bufsize );
199 if ( bytesRead < 0 ) 196 if ( bytesRead < 0 )
200 ok = FALSE; 197 ok = FALSE;
201 while ( ok && bytesRead > 0 ) { 198 while ( ok && bytesRead > 0 ) {
202 int bytesWritten = df.writeBlock( buffer, bytesRead ); 199 int bytesWritten = df.writeBlock( buffer, bytesRead );
203 if ( bytesWritten < 0 ) 200 if ( bytesWritten < 0 )
204 ok = FALSE; 201 ok = FALSE;
205 else 202 else
206 bytesRead -= bytesWritten; 203 bytesRead -= bytesWritten;
207 } 204 }
208 } 205 }
209 206
210 if ( ok ) 207 if ( ok )
211 ok = dest.writeLink(); 208 ok = dest.writeLink();
212 209
213 if ( ok ) { 210 if ( ok ) {
214 // okay now rename the file... 211 // okay now rename the file...
215 if ( !renameFile( fn.latin1(), dest.file().latin1() ) ) { 212 if ( !renameFile( fn.latin1(), dest.file().latin1() ) ) {
216 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(), 213 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
217 dest.file().latin1(), errno ); 214 dest.file().latin1(), errno );
218 // remove the tmp file, otherwise, it will just lay around... 215 // remove the tmp file, otherwise, it will just lay around...
219 QFile::remove( fn.latin1() ); 216 QFile::remove( fn.latin1() );
diff --git a/library/fileselector.cpp b/library/fileselector.cpp
index 4039243..7c29aba 100644
--- a/library/fileselector.cpp
+++ b/library/fileselector.cpp
@@ -1,227 +1,225 @@
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"
31#include "storage.h" 30#include "storage.h"
32#include "qpemenubar.h" 31#include "qpemenubar.h"
33#include <qcopchannel_qws.h> 32#include <qcopchannel_qws.h>
34#include "lnkproperties.h" 33#include "lnkproperties.h"
35#include "applnk.h"
36#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
37#include "categorymenu.h" 35#include "categorymenu.h"
38#include "categoryselect.h" 36#include "categoryselect.h"
39#include "mimetype.h" 37#include "mimetype.h"
40#include <qpe/categories.h> 38#include <qpe/categories.h>
41 39
42#include <stdlib.h> 40#include <stdlib.h>
43 41
44#include <qdir.h> 42#include <qdir.h>
45#include <qwidget.h> 43#include <qwidget.h>
46#include <qpopupmenu.h> 44#include <qpopupmenu.h>
47#include <qtoolbutton.h> 45#include <qtoolbutton.h>
48#include <qpushbutton.h> 46#include <qpushbutton.h>
49#include <qheader.h> 47#include <qheader.h>
50#include <qtooltip.h> 48#include <qtooltip.h>
51#include <qwhatsthis.h> 49#include <qwhatsthis.h>
52 50
53class TypeCombo : public QComboBox 51class TypeCombo : public QComboBox
54{ 52{
55 Q_OBJECT 53 Q_OBJECT
56public: 54public:
57 TypeCombo( QWidget *parent, const char *name=0 ) 55 TypeCombo( QWidget *parent, const char *name=0 )
58 : QComboBox( parent, name ) 56 : QComboBox( parent, name )
59 { 57 {
60 connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) ); 58 connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) );
61 } 59 }
62 60
63 void reread( DocLnkSet &files, const QString &filter ); 61 void reread( DocLnkSet &files, const QString &filter );
64 62
65signals: 63signals:
66 void selected( const QString & ); 64 void selected( const QString & );
67 65
68protected slots: 66protected slots:
69 void selectType( int idx ) { 67 void selectType( int idx ) {
70 emit selected( typelist[idx] ); 68 emit selected( typelist[idx] );
71 } 69 }
72 70
73protected: 71protected:
74 QStringList typelist; 72 QStringList typelist;
75 QString prev; 73 QString prev;
76}; 74};
77 75
78void TypeCombo::reread( DocLnkSet &files, const QString &filter ) 76void TypeCombo::reread( DocLnkSet &files, const QString &filter )
79{ 77{
80 typelist.clear(); 78 typelist.clear();
81 QStringList filters = QStringList::split( ';', filter ); 79 QStringList filters = QStringList::split( ';', filter );
82 int pos = filter.find( '/' ); 80 int pos = filter.find( '/' );
83 //### do for each filter 81 //### do for each filter
84 if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) { 82 if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) {
85 typelist.append( filter ); 83 typelist.append( filter );
86 clear(); 84 clear();
87 QString minor = filter.mid( pos+1 ); 85 QString minor = filter.mid( pos+1 );
88 minor[0] = minor[0].upper(); 86 minor[0] = minor[0].upper();
89 insertItem( tr("%1 files").arg(minor) ); 87 insertItem( tr("%1 files").arg(minor) );
90 setCurrentItem(0); 88 setCurrentItem(0);
91 setEnabled( FALSE ); 89 setEnabled( FALSE );
92 return; 90 return;
93 } 91 }
94 92
95 QListIterator<DocLnk> dit( files.children() ); 93 QListIterator<DocLnk> dit( files.children() );
96 for ( ; dit.current(); ++dit ) { 94 for ( ; dit.current(); ++dit ) {
97 if ( !typelist.contains( (*dit)->type() ) ) 95 if ( !typelist.contains( (*dit)->type() ) )
98 typelist.append( (*dit)->type() ); 96 typelist.append( (*dit)->type() );
99 } 97 }
100 98
101 QStringList types; 99 QStringList types;
102 QStringList::ConstIterator it; 100 QStringList::ConstIterator it;
103 for (it = typelist.begin(); it!=typelist.end(); ++it) { 101 for (it = typelist.begin(); it!=typelist.end(); ++it) {
104 QString t = *it; 102 QString t = *it;
105 if ( t.left(12) == "application/" ) { 103 if ( t.left(12) == "application/" ) {
106 MimeType mt(t); 104 MimeType mt(t);
107 const AppLnk* app = mt.application(); 105 const AppLnk* app = mt.application();
108 if ( app ) 106 if ( app )
109 t = app->name(); 107 t = app->name();
110 else 108 else
111 t = t.mid(12); 109 t = t.mid(12);
112 } else { 110 } else {
113 QString major, minor; 111 QString major, minor;
114 int pos = t.find( '/' ); 112 int pos = t.find( '/' );
115 if ( pos >= 0 ) { 113 if ( pos >= 0 ) {
116 major = t.left( pos ); 114 major = t.left( pos );
117 minor = t.mid( pos+1 ); 115 minor = t.mid( pos+1 );
118 } 116 }
119 if ( minor.find( "x-" ) == 0 ) 117 if ( minor.find( "x-" ) == 0 )
120 minor = minor.mid( 2 ); 118 minor = minor.mid( 2 );
121 minor[0] = minor[0].upper(); 119 minor[0] = minor[0].upper();
122 major[0] = major[0].upper(); 120 major[0] = major[0].upper();
123 if ( filters.count() > 1 ) 121 if ( filters.count() > 1 )
124 t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major); 122 t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major);
125 else 123 else
126 t = minor; 124 t = minor;
127 } 125 }
128 types += tr("%1 files").arg(t); 126 types += tr("%1 files").arg(t);
129 } 127 }
130 for (it = filters.begin(); it!=filters.end(); ++it) { 128 for (it = filters.begin(); it!=filters.end(); ++it) {
131 typelist.append( *it ); 129 typelist.append( *it );
132 int pos = (*it).find( '/' ); 130 int pos = (*it).find( '/' );
133 if ( pos >= 0 ) { 131 if ( pos >= 0 ) {
134 QString maj = (*it).left( pos ); 132 QString maj = (*it).left( pos );
135 maj[0] = maj[0].upper(); 133 maj[0] = maj[0].upper();
136 types << tr("All %1 files").arg(maj); 134 types << tr("All %1 files").arg(maj);
137 } 135 }
138 } 136 }
139 if ( filters.count() > 1 ) { 137 if ( filters.count() > 1 ) {
140 typelist.append( filter ); 138 typelist.append( filter );
141 types << tr("All files"); 139 types << tr("All files");
142 } 140 }
143 prev = currentText(); 141 prev = currentText();
144 clear(); 142 clear();
145 insertStringList(types); 143 insertStringList(types);
146 for (int i=0; i<count(); i++) { 144 for (int i=0; i<count(); i++) {
147 if ( text(i) == prev ) { 145 if ( text(i) == prev ) {
148 setCurrentItem(i); 146 setCurrentItem(i);
149 break; 147 break;
150 } 148 }
151 } 149 }
152 if ( prev.isNull() ) 150 if ( prev.isNull() )
153 setCurrentItem(count()-1); 151 setCurrentItem(count()-1);
154 setEnabled( TRUE ); 152 setEnabled( TRUE );
155} 153}
156 154
157 155
158//=========================================================================== 156//===========================================================================
159 157
160FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f ) 158FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f )
161 : QListViewItem( parent ), fl( f ) 159 : QListViewItem( parent ), fl( f )
162{ 160{
163 setText( 0, f.name() ); 161 setText( 0, f.name() );
164 setPixmap( 0, f.pixmap() ); 162 setPixmap( 0, f.pixmap() );
165} 163}
166 164
167FileSelectorItem::~FileSelectorItem() 165FileSelectorItem::~FileSelectorItem()
168{ 166{
169} 167}
170 168
171FileSelectorView::FileSelectorView( QWidget *parent, const char *name ) 169FileSelectorView::FileSelectorView( QWidget *parent, const char *name )
172 : QListView( parent, name ) 170 : QListView( parent, name )
173{ 171{
174 setAllColumnsShowFocus( TRUE ); 172 setAllColumnsShowFocus( TRUE );
175 addColumn( tr( "Name" ) ); 173 addColumn( tr( "Name" ) );
176 header()->hide(); 174 header()->hide();
177} 175}
178 176
179FileSelectorView::~FileSelectorView() 177FileSelectorView::~FileSelectorView()
180{ 178{
181} 179}
182 180
183void FileSelectorView::keyPressEvent( QKeyEvent *e ) 181void FileSelectorView::keyPressEvent( QKeyEvent *e )
184{ 182{
185 QString txt = e->text(); 183 QString txt = e->text();
186 if (e->key() == Key_Space) 184 if (e->key() == Key_Space)
187 emit returnPressed( currentItem() ); 185 emit returnPressed( currentItem() );
188 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) 186 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 )
189 e->ignore(); 187 e->ignore();
190 else 188 else
191 QListView::keyPressEvent(e); 189 QListView::keyPressEvent(e);
192} 190}
193 191
194class NewDocItem : public FileSelectorItem 192class NewDocItem : public FileSelectorItem
195{ 193{
196public: 194public:
197 NewDocItem( QListView *parent, const DocLnk &f ) 195 NewDocItem( QListView *parent, const DocLnk &f )
198 : FileSelectorItem( parent, f ) { 196 : FileSelectorItem( parent, f ) {
199 setText( 0, QObject::tr("New Document") ); 197 setText( 0, QObject::tr("New Document") );
200 QImage img( Resource::loadImage( "new" ) ); 198 QImage img( Resource::loadImage( "new" ) );
201 QPixmap pm; 199 QPixmap pm;
202 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 200 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
203 setPixmap( 0, pm ); 201 setPixmap( 0, pm );
204 } 202 }
205 QString key ( int, bool ) const { 203 QString key ( int, bool ) const {
206 return QString("\n"); 204 return QString("\n");
207 } 205 }
208 206
209 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { 207 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) {
210 QFont oldFont = p->font(); 208 QFont oldFont = p->font();
211 QFont newFont = p->font(); 209 QFont newFont = p->font();
212 newFont.setWeight( QFont::Bold ); 210 newFont.setWeight( QFont::Bold );
213 p->setFont( newFont ); 211 p->setFont( newFont );
214 FileSelectorItem::paintCell( p, cg, column, width, alignment ); 212 FileSelectorItem::paintCell( p, cg, column, width, alignment );
215 p->setFont( oldFont ); 213 p->setFont( oldFont );
216 } 214 }
217 215
218 int width( const QFontMetrics &fm, const QListView *v, int c ) const { 216 int width( const QFontMetrics &fm, const QListView *v, int c ) const {
219 return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font 217 return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font
220 } 218 }
221}; 219};
222 220
223//=========================================================================== 221//===========================================================================
224 222
225class FileSelectorPrivate 223class FileSelectorPrivate
226{ 224{
227public: 225public:
diff --git a/library/finddialog.cpp b/library/finddialog.cpp
index ddf41a7..64487c9 100644
--- a/library/finddialog.cpp
+++ b/library/finddialog.cpp
@@ -1,85 +1,84 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT 21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
22// have this class. 22// have this class.
23#define QTOPIA_INTERNAL_FD 23#define QTOPIA_INTERNAL_FD
24 24
25#include "finddialog.h" 25#include "finddialog.h"
26#include "findwidget_p.h" 26#include "findwidget_p.h"
27 27
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qpushbutton.h>
30 29
31/*! 30/*!
32 \class FindDialog finddialog.h 31 \class FindDialog finddialog.h
33 \brief A simple FindDialog 32 \brief A simple FindDialog
34 33
35 A find dialog. FIXME!!!! 34 A find dialog. FIXME!!!!
36 35
37*/ 36*/
38FindDialog::FindDialog( const QString &appName, QWidget *parent, 37FindDialog::FindDialog( const QString &appName, QWidget *parent,
39 const char *name, bool modal ) 38 const char *name, bool modal )
40 : QDialog( parent, name, modal ) 39 : QDialog( parent, name, modal )
41{ 40{
42 setCaption( tr("Find") ); 41 setCaption( tr("Find") );
43 QVBoxLayout *vb; 42 QVBoxLayout *vb;
44 vb = new QVBoxLayout( this ); 43 vb = new QVBoxLayout( this );
45 fw = new FindWidget( appName, this, "Find Widget" ); 44 fw = new FindWidget( appName, this, "Find Widget" );
46 vb->addWidget( fw ); 45 vb->addWidget( fw );
47 QObject::connect( fw, SIGNAL(signalFindClicked(const QString&, 46 QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,
48 bool,bool,int)), 47 bool,bool,int)),
49 this, SIGNAL(signalFindClicked(const QString&, 48 this, SIGNAL(signalFindClicked(const QString&,
50 bool,bool,int)) ); 49 bool,bool,int)) );
51 QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,const QDate&, 50 QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,const QDate&,
52 bool,bool,int)), 51 bool,bool,int)),
53 this, SIGNAL(signalFindClicked(const QString&, 52 this, SIGNAL(signalFindClicked(const QString&,
54 const QDate&,bool,bool,int)) ); 53 const QDate&,bool,bool,int)) );
55 d = 0; 54 d = 0;
56} 55}
57 56
58FindDialog::~FindDialog() 57FindDialog::~FindDialog()
59{ 58{
60} 59}
61 60
62QString FindDialog::findText() const 61QString FindDialog::findText() const
63{ 62{
64 return fw->findText(); 63 return fw->findText();
65} 64}
66 65
67void FindDialog::setUseDate( bool show ) 66void FindDialog::setUseDate( bool show )
68{ 67{
69 fw->setUseDate( show ); 68 fw->setUseDate( show );
70} 69}
71 70
72void FindDialog::setDate( const QDate &dt ) 71void FindDialog::setDate( const QDate &dt )
73{ 72{
74 fw->setDate( dt ); 73 fw->setDate( dt );
75} 74}
76 75
77void FindDialog::slotNotFound() 76void FindDialog::slotNotFound()
78{ 77{
79 fw->slotNotFound(); 78 fw->slotNotFound();
80} 79}
81 80
82void FindDialog::slotWrapAround() 81void FindDialog::slotWrapAround()
83{ 82{
84 fw->slotWrapAround(); 83 fw->slotWrapAround();
85} 84}
diff --git a/library/findwidget_p.cpp b/library/findwidget_p.cpp
index 287e125..e91d789 100644
--- a/library/findwidget_p.cpp
+++ b/library/findwidget_p.cpp
@@ -1,120 +1,114 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "findwidget_p.h" 21#include "findwidget_p.h"
22 22
23#include <qpe/categories.h>
24#include <qpe/categoryselect.h> 23#include <qpe/categoryselect.h>
25#include <qpe/datebookmonth.h> 24#include <qpe/datebookmonth.h>
26#include <qpe/timestring.h>
27 25
28#include <qcheckbox.h> 26#include <qcheckbox.h>
29#include <qlabel.h> 27#include <qlabel.h>
30#include <qlineedit.h> 28#include <qlineedit.h>
31#include <qmessagebox.h>
32#include <qpushbutton.h>
33#include <qpopupmenu.h>
34#include <qtoolbutton.h>
35 29
36FindWidget::FindWidget( const QString &appName, QWidget *parent, 30FindWidget::FindWidget( const QString &appName, QWidget *parent,
37 const char *name ) 31 const char *name )
38 : FindWidgetBase( parent, name ), 32 : FindWidgetBase( parent, name ),
39 mStrApp( appName ), 33 mStrApp( appName ),
40 mDate( QDate::currentDate() ) 34 mDate( QDate::currentDate() )
41{ 35{
42 setMaximumSize( sizeHint() ); 36 setMaximumSize( sizeHint() );
43 QArray<int> vl(0); 37 QArray<int> vl(0);
44 cmbCat->setCategories( vl, mStrApp ); 38 cmbCat->setCategories( vl, mStrApp );
45 cmbCat->setRemoveCategoryEdit( TRUE ); 39 cmbCat->setRemoveCategoryEdit( TRUE );
46 cmbCat->setAllCategories( TRUE ); 40 cmbCat->setAllCategories( TRUE );
47 // hide junk for the moment... 41 // hide junk for the moment...
48 lblStartDate->hide(); 42 lblStartDate->hide();
49 cmdStartDate->hide(); 43 cmdStartDate->hide();
50 QPopupMenu *m1 = new QPopupMenu( this ); 44 QPopupMenu *m1 = new QPopupMenu( this );
51 dtPicker = new DateBookMonth( m1, 0, TRUE ); 45 dtPicker = new DateBookMonth( m1, 0, TRUE );
52 dtPicker->setDate( mDate.year(), mDate.month(), mDate.day() ); 46 dtPicker->setDate( mDate.year(), mDate.month(), mDate.day() );
53 m1->insertItem( dtPicker ); 47 m1->insertItem( dtPicker );
54 cmdStartDate->setPopup( m1 ); 48 cmdStartDate->setPopup( m1 );
55 cmdStartDate->setText( TimeString::shortDate(mDate) ); 49 cmdStartDate->setText( TimeString::shortDate(mDate) );
56 QObject::connect( dtPicker, SIGNAL(dateClicked(int, int, int)), 50 QObject::connect( dtPicker, SIGNAL(dateClicked(int, int, int)),
57 this, SLOT(slotDateChanged(int, int, int)) ); 51 this, SLOT(slotDateChanged(int, int, int)) );
58 52
59 QObject::connect( cmdFind, SIGNAL(clicked()), 53 QObject::connect( cmdFind, SIGNAL(clicked()),
60 this, SLOT(slotFindClicked()) ); 54 this, SLOT(slotFindClicked()) );
61} 55}
62 56
63FindWidget::~FindWidget() 57FindWidget::~FindWidget()
64{ 58{
65} 59}
66 60
67QString FindWidget::findText() const 61QString FindWidget::findText() const
68{ 62{
69 return txtFind->text(); 63 return txtFind->text();
70} 64}
71 65
72void FindWidget::slotFindClicked() 66void FindWidget::slotFindClicked()
73{ 67{
74 lblStatus->setText( "" ); 68 lblStatus->setText( "" );
75 if ( cmdStartDate->isVisible() ) 69 if ( cmdStartDate->isVisible() )
76 emit signalFindClicked( findText(), 70 emit signalFindClicked( findText(),
77 mDate, 71 mDate,
78 chkCase->isChecked(), 72 chkCase->isChecked(),
79 chkBackwards->isChecked(), 73 chkBackwards->isChecked(),
80 cmbCat->currentCategory() ); 74 cmbCat->currentCategory() );
81 else 75 else
82 emit signalFindClicked( findText(), chkCase->isChecked(), 76 emit signalFindClicked( findText(), chkCase->isChecked(),
83 chkBackwards->isChecked(), 77 chkBackwards->isChecked(),
84 cmbCat->currentCategory() ); 78 cmbCat->currentCategory() );
85} 79}
86 80
87void FindWidget::setUseDate( bool show ) 81void FindWidget::setUseDate( bool show )
88{ 82{
89 if ( show ) { 83 if ( show ) {
90 lblStartDate->show(); 84 lblStartDate->show();
91 cmdStartDate->show(); 85 cmdStartDate->show();
92 } else { 86 } else {
93 lblStartDate->hide(); 87 lblStartDate->hide();
94 cmdStartDate->hide(); 88 cmdStartDate->hide();
95 } 89 }
96 chkBackwards->setDisabled( show ); 90 chkBackwards->setDisabled( show );
97} 91}
98 92
99void FindWidget::setDate( const QDate &dt ) 93void FindWidget::setDate( const QDate &dt )
100{ 94{
101 slotDateChanged( dt.year(), dt.month(), dt.day() ); 95 slotDateChanged( dt.year(), dt.month(), dt.day() );
102} 96}
103 97
104void FindWidget::slotNotFound() 98void FindWidget::slotNotFound()
105{ 99{
106 lblStatus->setText( tr("String Not Found.") ); 100 lblStatus->setText( tr("String Not Found.") );
107} 101}
108 102
109void FindWidget::slotWrapAround() 103void FindWidget::slotWrapAround()
110{ 104{
111 lblStatus->setText( tr("End reached, starting at %1", "Date using TimeString::shortDate") 105 lblStatus->setText( tr("End reached, starting at %1", "Date using TimeString::shortDate")
112 .arg(TimeString::shortDate( mDate ) ) ); 106 .arg(TimeString::shortDate( mDate ) ) );
113} 107}
114 108
115void FindWidget::slotDateChanged( int year, int month, int day ) 109void FindWidget::slotDateChanged( int year, int month, int day )
116{ 110{
117 mDate.setYMD( year, month, day ); 111 mDate.setYMD( year, month, day );
118 cmdStartDate->setText( TimeString::shortDate( mDate ) ); 112 cmdStartDate->setText( TimeString::shortDate( mDate ) );
119 dtPicker->setDate( year, month, day ); 113 dtPicker->setDate( year, month, day );
120} 114}
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp
index 2ad8e95..d94e338 100644
--- a/library/fontdatabase.cpp
+++ b/library/fontdatabase.cpp
@@ -1,221 +1,219 @@
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"
23#include "fontdatabase.h" 22#include "fontdatabase.h"
24 23
25#include <qpe/qlibrary.h> 24#include <qpe/qlibrary.h>
26 25
27#include <qfontmanager_qws.h> 26#include <qfontmanager_qws.h>
28#include <qdir.h> 27#include <qdir.h>
29#include <qdict.h>
30#include <stdio.h> 28#include <stdio.h>
31#include <stdlib.h> 29#include <stdlib.h>
32 30
33static QString fontDir() 31static QString fontDir()
34{ 32{
35 QString qtdir = getenv("QTDIR"); 33 QString qtdir = getenv("QTDIR");
36 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded"; 34 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded";
37 return qtdir+"/lib/fonts/"; 35 return qtdir+"/lib/fonts/";
38} 36}
39 37
40#ifdef QT_NO_FONTDATABASE 38#ifdef QT_NO_FONTDATABASE
41static QString fontFamily( const QString& key ) 39static QString fontFamily( const QString& key )
42{ 40{
43 int u0 = key.find('_'); 41 int u0 = key.find('_');
44 int u1 = key.find('_',u0+1); 42 int u1 = key.find('_',u0+1);
45 int u2 = key.find('_',u1+1); 43 int u2 = key.find('_',u1+1);
46 QString family = key.left(u0); 44 QString family = key.left(u0);
47 //int pointSize = key.mid(u0+1,u1-u0-1).toInt(); 45 //int pointSize = key.mid(u0+1,u1-u0-1).toInt();
48 //int weight = key.mid(u1+1,u2-u1-1).toInt(); 46 //int weight = key.mid(u1+1,u2-u1-1).toInt();
49 //bool italic = key.mid(u2-1,1) == "i"; 47 //bool italic = key.mid(u2-1,1) == "i";
50 // #### ignores _t and _I fields 48 // #### ignores _t and _I fields
51 return family; 49 return family;
52} 50}
53#endif 51#endif
54 52
55 53
56QValueList<FontFactory> *FontDatabase::factoryList = 0; 54QValueList<FontFactory> *FontDatabase::factoryList = 0;
57/*! 55/*!
58 \class FontDatabase fontdatabase.h 56 \class FontDatabase fontdatabase.h
59 \brief The FontDatabase class provides information about available fonts. 57 \brief The FontDatabase class provides information about available fonts.
60 58
61 Most often you will simply want to query the database for the 59 Most often you will simply want to query the database for the
62 available font families(). 60 available font families().
63 61
64 Use FontDatabase rather than QFontDatabase when you may need access 62 Use FontDatabase rather than QFontDatabase when you may need access
65 to fonts that are not normally available. For example, if the 63 to fonts that are not normally available. For example, if the
66 freetype library and the Qtopia freetype plugin are installed, 64 freetype library and the Qtopia freetype plugin are installed,
67 TrueType fonts will be available to your application. Font renderer 65 TrueType fonts will be available to your application. Font renderer
68 plugins have greater resource requirements than system fonts so they 66 plugins have greater resource requirements than system fonts so they
69 should be used only when necessary. You can force the loading of 67 should be used only when necessary. You can force the loading of
70 font renderer plugins with loadRenderers(). 68 font renderer plugins with loadRenderers().
71 69
72 \ingroup qtopiaemb 70 \ingroup qtopiaemb
73*/ 71*/
74 72
75/*! 73/*!
76 Constructs a FontDatabase object. 74 Constructs a FontDatabase object.
77*/ 75*/
78FontDatabase::FontDatabase() 76FontDatabase::FontDatabase()
79#ifndef QT_NO_FONTDATABASE 77#ifndef QT_NO_FONTDATABASE
80 : QFontDatabase() 78 : QFontDatabase()
81#endif 79#endif
82{ 80{
83 if ( !factoryList ) 81 if ( !factoryList )
84 loadRenderers(); 82 loadRenderers();
85} 83}
86 84
87/*! 85/*!
88 Returns a list of names of all the available font families. 86 Returns a list of names of all the available font families.
89*/ 87*/
90QStringList FontDatabase::families() const 88QStringList FontDatabase::families() const
91{ 89{
92#ifndef QT_NO_FONTDATABASE 90#ifndef QT_NO_FONTDATABASE
93 return QFontDatabase::families(); 91 return QFontDatabase::families();
94#else 92#else
95 93
96#ifndef QWS 94#ifndef QWS
97 QStringList list; 95 QStringList list;
98 return list; 96 return list;
99#else 97#else
100 QStringList list; 98 QStringList list;
101 QDict<void> familyDict; 99 QDict<void> familyDict;
102 QDiskFont *qdf; 100 QDiskFont *qdf;
103 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; 101 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
104 qdf=qt_fontmanager->diskfonts.next()) { 102 qdf=qt_fontmanager->diskfonts.next()) {
105 QString familyname = qdf->name; 103 QString familyname = qdf->name;
106 if ( !familyDict.find( familyname ) ) { 104 if ( !familyDict.find( familyname ) ) {
107 familyDict.insert( familyname, (void *)1 ); 105 familyDict.insert( familyname, (void *)1 );
108 list.append( familyname ); 106 list.append( familyname );
109 } 107 }
110 } 108 }
111 109
112 QDir dir(fontDir(),"*.qpf"); 110 QDir dir(fontDir(),"*.qpf");
113 for (int i=0; i<(int)dir.count(); i++) { 111 for (int i=0; i<(int)dir.count(); i++) {
114 QString familyname = fontFamily(dir[i]); 112 QString familyname = fontFamily(dir[i]);
115 if ( !familyDict.find( familyname ) ) { 113 if ( !familyDict.find( familyname ) ) {
116 familyDict.insert( familyname, (void *)1 ); 114 familyDict.insert( familyname, (void *)1 );
117 list.append( familyname ); 115 list.append( familyname );
118 } 116 }
119 } 117 }
120 118
121 return list; 119 return list;
122#endif 120#endif
123#endif 121#endif
124} 122}
125 123
126#ifdef QT_NO_FONTDATABASE 124#ifdef QT_NO_FONTDATABASE
127/*! 125/*!
128 Returns a list of standard fontsizes. 126 Returns a list of standard fontsizes.
129*/ 127*/
130QValueList<int> FontDatabase::standardSizes() 128QValueList<int> FontDatabase::standardSizes()
131{ 129{
132 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 130 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
133 36, 48, 72, 0 }; 131 36, 48, 72, 0 };
134 static bool first = TRUE; 132 static bool first = TRUE;
135 static QValueList<int> sList; 133 static QValueList<int> sList;
136 if ( first ) { 134 if ( first ) {
137 first = FALSE; 135 first = FALSE;
138 int i = 0; 136 int i = 0;
139 while( s[i] ) 137 while( s[i] )
140 sList.append( s[i++] ); 138 sList.append( s[i++] );
141 } 139 }
142 return sList; 140 return sList;
143} 141}
144 142
145#endif 143#endif
146 144
147/*! 145/*!
148 Load any font renderer plugins that are available and make the fonts 146 Load any font renderer plugins that are available and make the fonts
149 that the plugins can read available. 147 that the plugins can read available.
150*/ 148*/
151void FontDatabase::loadRenderers() 149void FontDatabase::loadRenderers()
152{ 150{
153#ifndef QWS 151#ifndef QWS
154 return; 152 return;
155#else 153#else
156 154
157#ifndef QT_NO_COMPONENT 155#ifndef QT_NO_COMPONENT
158 if ( !factoryList ) 156 if ( !factoryList )
159 factoryList = new QValueList<FontFactory>; 157 factoryList = new QValueList<FontFactory>;
160 158
161 QValueList<FontFactory>::Iterator mit; 159 QValueList<FontFactory>::Iterator mit;
162 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { 160 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
163 qt_fontmanager->factories.setAutoDelete( false ); 161 qt_fontmanager->factories.setAutoDelete( false );
164 qt_fontmanager->factories.removeRef( (*mit).factory ); 162 qt_fontmanager->factories.removeRef( (*mit).factory );
165 qt_fontmanager->factories.setAutoDelete( true ); 163 qt_fontmanager->factories.setAutoDelete( true );
166 (*mit).interface->release(); 164 (*mit).interface->release();
167 (*mit).library->unload(); 165 (*mit).library->unload();
168 delete (*mit).library; 166 delete (*mit).library;
169 } 167 }
170 factoryList->clear(); 168 factoryList->clear();
171 169
172 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; 170 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories";
173#ifdef Q_OS_MACX 171#ifdef Q_OS_MACX
174 QDir dir( path, "lib*.dylib" ); 172 QDir dir( path, "lib*.dylib" );
175#else 173#else
176 QDir dir( path, "lib*.so" ); 174 QDir dir( path, "lib*.so" );
177#endif 175#endif
178 176
179 if ( !dir.exists()) 177 if ( !dir.exists())
180 return; 178 return;
181 179
182 QStringList list = dir.entryList(); 180 QStringList list = dir.entryList();
183 QStringList::Iterator it; 181 QStringList::Iterator it;
184 for ( it = list.begin(); it != list.end(); ++it ) { 182 for ( it = list.begin(); it != list.end(); ++it ) {
185 FontFactoryInterface *iface = 0; 183 FontFactoryInterface *iface = 0;
186 QLibrary *lib = new QLibrary( path + "/" + *it ); 184 QLibrary *lib = new QLibrary( path + "/" + *it );
187 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { 185 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
188 FontFactory factory; 186 FontFactory factory;
189 factory.library = lib; 187 factory.library = lib;
190 factory.interface = iface; 188 factory.interface = iface;
191 factory.factory = factory.interface->fontFactory(); 189 factory.factory = factory.interface->fontFactory();
192 factoryList->append( factory ); 190 factoryList->append( factory );
193 qt_fontmanager->factories.append( factory.factory ); 191 qt_fontmanager->factories.append( factory.factory );
194 readFonts( factory.factory ); 192 readFonts( factory.factory );
195 } else { 193 } else {
196 delete lib; 194 delete lib;
197 } 195 }
198 } 196 }
199#endif 197#endif
200#endif 198#endif
201} 199}
202 200
203/*! 201/*!
204 \internal 202 \internal
205*/ 203*/
206void FontDatabase::readFonts( QFontFactory *factory ) 204void FontDatabase::readFonts( QFontFactory *factory )
207{ 205{
208#ifndef QWS 206#ifndef QWS
209return; 207return;
210#else 208#else
211 // Load in font definition file 209 // Load in font definition file
212 QString fn = fontDir() + "fontdir"; 210 QString fn = fontDir() + "fontdir";
213 FILE* fontdef=fopen(fn.local8Bit(),"r"); 211 FILE* fontdef=fopen(fn.local8Bit(),"r");
214 if(!fontdef) { 212 if(!fontdef) {
215 QCString temp=fn.local8Bit(); 213 QCString temp=fn.local8Bit();
216 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", 214 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
217 temp.data()); 215 temp.data());
218 return; 216 return;
219 } 217 }
220 char buf[200]=""; 218 char buf[200]="";
221 char name[200]=""; 219 char name[200]="";
diff --git a/library/global.cpp b/library/global.cpp
index a627348..5ac969b 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,243 +1,241 @@
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#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29#include <qpe/config.h> 29#include <qpe/config.h>
30 30
31#include <qfile.h>
32#include <qlabel.h> 31#include <qlabel.h>
33#include <qtimer.h> 32#include <qtimer.h>
34#include <qmap.h> 33#include <qmap.h>
35#include <qdict.h> 34#include <qdict.h>
36#include <qdir.h> 35#include <qdir.h>
37#include <qmessagebox.h> 36#include <qmessagebox.h>
38#include <qregexp.h> 37#include <qregexp.h>
39 38
40#include <stdlib.h> 39#include <stdlib.h>
41#include <sys/stat.h> 40#include <sys/stat.h>
42#include <sys/wait.h> 41#include <sys/wait.h>
43#include <sys/types.h> 42#include <sys/types.h>
44#include <fcntl.h> 43#include <fcntl.h>
45#include <unistd.h> 44#include <unistd.h>
46#include <errno.h> 45#include <errno.h>
47 46
48#include <qwindowsystem_qws.h> // for qwsServer 47#include <qwindowsystem_qws.h> // for qwsServer
49#include <qdatetime.h> 48#include <qdatetime.h>
50 49
51#include <qfile.h>
52 50
53//#include "quickexec_p.h" 51//#include "quickexec_p.h"
54 52
55class Emitter : public QObject { 53class Emitter : public QObject {
56 Q_OBJECT 54 Q_OBJECT
57public: 55public:
58 Emitter( QWidget* receiver, const QString& document ) 56 Emitter( QWidget* receiver, const QString& document )
59 { 57 {
60 connect(this, SIGNAL(setDocument(const QString&)), 58 connect(this, SIGNAL(setDocument(const QString&)),
61 receiver, SLOT(setDocument(const QString&))); 59 receiver, SLOT(setDocument(const QString&)));
62 emit setDocument(document); 60 emit setDocument(document);
63 disconnect(this, SIGNAL(setDocument(const QString&)), 61 disconnect(this, SIGNAL(setDocument(const QString&)),
64 receiver, SLOT(setDocument(const QString&))); 62 receiver, SLOT(setDocument(const QString&)));
65 } 63 }
66 64
67signals: 65signals:
68 void setDocument(const QString&); 66 void setDocument(const QString&);
69}; 67};
70 68
71 69
72class StartingAppList : public QObject { 70class StartingAppList : public QObject {
73 Q_OBJECT 71 Q_OBJECT
74public: 72public:
75 static void add( const QString& name ); 73 static void add( const QString& name );
76 static bool isStarting( const QString name ); 74 static bool isStarting( const QString name );
77private slots: 75private slots:
78 void handleNewChannel( const QString &); 76 void handleNewChannel( const QString &);
79private: 77private:
80 StartingAppList( QObject *parent=0, const char* name=0 ) ; 78 StartingAppList( QObject *parent=0, const char* name=0 ) ;
81 79
82 QDict<QTime> dict; 80 QDict<QTime> dict;
83 static StartingAppList *appl; 81 static StartingAppList *appl;
84}; 82};
85 83
86StartingAppList* StartingAppList::appl = 0; 84StartingAppList* StartingAppList::appl = 0;
87 85
88StartingAppList::StartingAppList( QObject *parent, const char* name ) 86StartingAppList::StartingAppList( QObject *parent, const char* name )
89 :QObject( parent, name ) 87 :QObject( parent, name )
90{ 88{
91#if QT_VERSION >= 232 && defined(QWS) 89#if QT_VERSION >= 232 && defined(QWS)
92 connect( qwsServer, SIGNAL( newChannel(const QString&)), 90 connect( qwsServer, SIGNAL( newChannel(const QString&)),
93 this, SLOT( handleNewChannel(const QString&)) ); 91 this, SLOT( handleNewChannel(const QString&)) );
94#endif 92#endif
95 dict.setAutoDelete( TRUE ); 93 dict.setAutoDelete( TRUE );
96} 94}
97 95
98void StartingAppList::add( const QString& name ) 96void StartingAppList::add( const QString& name )
99{ 97{
100#if QT_VERSION >= 232 && !defined(QT_NO_COP) 98#if QT_VERSION >= 232 && !defined(QT_NO_COP)
101 if ( !appl ) 99 if ( !appl )
102 appl = new StartingAppList; 100 appl = new StartingAppList;
103 QTime *t = new QTime; 101 QTime *t = new QTime;
104 t->start(); 102 t->start();
105 appl->dict.insert( "QPE/Application/" + name, t ); 103 appl->dict.insert( "QPE/Application/" + name, t );
106#endif 104#endif
107} 105}
108 106
109bool StartingAppList::isStarting( const QString name ) 107bool StartingAppList::isStarting( const QString name )
110{ 108{
111#if QT_VERSION >= 232 && !defined(QT_NO_COP) 109#if QT_VERSION >= 232 && !defined(QT_NO_COP)
112 if ( appl ) { 110 if ( appl ) {
113 QTime *t = appl->dict.find( "QPE/Application/" + name ); 111 QTime *t = appl->dict.find( "QPE/Application/" + name );
114 if ( !t ) 112 if ( !t )
115 return FALSE; 113 return FALSE;
116 if ( t->elapsed() > 10000 ) { 114 if ( t->elapsed() > 10000 ) {
117 // timeout in case of crash or something 115 // timeout in case of crash or something
118 appl->dict.remove( "QPE/Application/" + name ); 116 appl->dict.remove( "QPE/Application/" + name );
119 return FALSE; 117 return FALSE;
120 } 118 }
121 return TRUE; 119 return TRUE;
122 } 120 }
123#endif 121#endif
124 return FALSE; 122 return FALSE;
125} 123}
126 124
127void StartingAppList::handleNewChannel( const QString & name ) 125void StartingAppList::handleNewChannel( const QString & name )
128{ 126{
129#if QT_VERSION >= 232 && !defined(QT_NO_COP) 127#if QT_VERSION >= 232 && !defined(QT_NO_COP)
130 dict.remove( name ); 128 dict.remove( name );
131#endif 129#endif
132} 130}
133 131
134static bool docDirCreated = FALSE; 132static bool docDirCreated = FALSE;
135static QDawg* fixed_dawg = 0; 133static QDawg* fixed_dawg = 0;
136static QDict<QDawg> *named_dawg = 0; 134static QDict<QDawg> *named_dawg = 0;
137 135
138static QString qpeDir() 136static QString qpeDir()
139{ 137{
140 QString dir = getenv("OPIEDIR"); 138 QString dir = getenv("OPIEDIR");
141 if ( dir.isEmpty() ) dir = ".."; 139 if ( dir.isEmpty() ) dir = "..";
142 return dir; 140 return dir;
143} 141}
144 142
145static QString dictDir() 143static QString dictDir()
146{ 144{
147 return qpeDir() + "/etc/dict"; 145 return qpeDir() + "/etc/dict";
148} 146}
149 147
150/*! 148/*!
151 \class Global global.h 149 \class Global global.h
152 \brief The Global class provides application-wide global functions. 150 \brief The Global class provides application-wide global functions.
153 151
154 The Global functions are grouped as follows: 152 The Global functions are grouped as follows:
155 \tableofcontents 153 \tableofcontents
156 154
157 \section1 User Interface 155 \section1 User Interface
158 156
159 The statusMessage() function provides short-duration messages to the 157 The statusMessage() function provides short-duration messages to the
160 user. The showInputMethod() function shows the current input method, 158 user. The showInputMethod() function shows the current input method,
161 and hideInputMethod() hides the input method. 159 and hideInputMethod() hides the input method.
162 160
163 \section1 Document related 161 \section1 Document related
164 162
165 The findDocuments() function creates a set of \link doclnk.html 163 The findDocuments() function creates a set of \link doclnk.html
166 DocLnk\endlink objects in a particular folder. 164 DocLnk\endlink objects in a particular folder.
167 165
168 \section1 Filesystem related 166 \section1 Filesystem related
169 167
170 Global provides an applicationFileName() function that returns the 168 Global provides an applicationFileName() function that returns the
171 full path of an application-specific file. 169 full path of an application-specific file.
172 170
173 The execute() function runs an application. 171 The execute() function runs an application.
174 172
175 \section1 Word list related 173 \section1 Word list related
176 174
177 A list of words relevant to the current locale is maintained by the 175 A list of words relevant to the current locale is maintained by the
178 system. The list is held in a \link qdawg.html DAWG\endlink 176 system. The list is held in a \link qdawg.html DAWG\endlink
179 (implemented by the QDawg class). This list is used, for example, by 177 (implemented by the QDawg class). This list is used, for example, by
180 the pickboard input method. 178 the pickboard input method.
181 179
182 The global QDawg is returned by fixedDawg(); this cannot be updated. 180 The global QDawg is returned by fixedDawg(); this cannot be updated.
183 An updatable copy of the global QDawg is returned by addedDawg(). 181 An updatable copy of the global QDawg is returned by addedDawg().
184 Applications may have their own word lists stored in \l{QDawg}s 182 Applications may have their own word lists stored in \l{QDawg}s
185 which are returned by dawg(). Use addWords() to add words to the 183 which are returned by dawg(). Use addWords() to add words to the
186 updateable copy of the global QDawg or to named application 184 updateable copy of the global QDawg or to named application
187 \l{QDawg}s. 185 \l{QDawg}s.
188 186
189 \section1 Quoting 187 \section1 Quoting
190 188
191 The shellQuote() function quotes a string suitable for passing to a 189 The shellQuote() function quotes a string suitable for passing to a
192 shell. The stringQuote() function backslash escapes '\' and '"' 190 shell. The stringQuote() function backslash escapes '\' and '"'
193 characters. 191 characters.
194 192
195 \section1 Hardware 193 \section1 Hardware
196 194
197 The implementation of the writeHWClock() function depends on the AlarmServer 195 The implementation of the writeHWClock() function depends on the AlarmServer
198 implementation. If the AlarmServer is using atd the clock will be synced to 196 implementation. If the AlarmServer is using atd the clock will be synced to
199 hardware. If opie-alarm is used the hardware clock will be synced before 197 hardware. If opie-alarm is used the hardware clock will be synced before
200 suspending the device. opie-alarm is used by iPAQ and Zaurii implementation 198 suspending the device. opie-alarm is used by iPAQ and Zaurii implementation
201 199
202 \ingroup qtopiaemb 200 \ingroup qtopiaemb
203*/ 201*/
204 202
205/*! 203/*!
206 \internal 204 \internal
207*/ 205*/
208Global::Global() 206Global::Global()
209{ 207{
210} 208}
211 209
212/*! 210/*!
213 Returns the unchangeable QDawg that contains general 211 Returns the unchangeable QDawg that contains general
214 words for the current locale. 212 words for the current locale.
215 213
216 \sa addedDawg() 214 \sa addedDawg()
217*/ 215*/
218const QDawg& Global::fixedDawg() 216const QDawg& Global::fixedDawg()
219{ 217{
220 if ( !fixed_dawg ) { 218 if ( !fixed_dawg ) {
221 if ( !docDirCreated ) 219 if ( !docDirCreated )
222 createDocDir(); 220 createDocDir();
223 221
224 fixed_dawg = new QDawg; 222 fixed_dawg = new QDawg;
225 QString dawgfilename = dictDir() + "/dawg"; 223 QString dawgfilename = dictDir() + "/dawg";
226 QString words_lang; 224 QString words_lang;
227 QStringList langs = Global::languageList(); 225 QStringList langs = Global::languageList();
228 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 226 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
229 QString lang = *it; 227 QString lang = *it;
230 words_lang = dictDir() + "/words." + lang; 228 words_lang = dictDir() + "/words." + lang;
231 QString dawgfilename_lang = dawgfilename + "." + lang; 229 QString dawgfilename_lang = dawgfilename + "." + lang;
232 if ( QFile::exists(dawgfilename_lang) || 230 if ( QFile::exists(dawgfilename_lang) ||
233 QFile::exists(words_lang) ) { 231 QFile::exists(words_lang) ) {
234 dawgfilename = dawgfilename_lang; 232 dawgfilename = dawgfilename_lang;
235 break; 233 break;
236 } 234 }
237 } 235 }
238 QFile dawgfile(dawgfilename); 236 QFile dawgfile(dawgfilename);
239 237
240 if ( !dawgfile.exists() ) { 238 if ( !dawgfile.exists() ) {
241 QString fn = dictDir() + "/words"; 239 QString fn = dictDir() + "/words";
242 if ( QFile::exists(words_lang) ) 240 if ( QFile::exists(words_lang) )
243 fn = words_lang; 241 fn = words_lang;
diff --git a/library/imageedit.cpp b/library/imageedit.cpp
index caa538a..3a559f4 100644
--- a/library/imageedit.cpp
+++ b/library/imageedit.cpp
@@ -1,97 +1,96 @@
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 "imageedit.h" 20#include "imageedit.h"
21#include <qpainter.h>
22 21
23ImageEdit::ImageEdit( QWidget *parent, const char *name) 22ImageEdit::ImageEdit( QWidget *parent, const char *name)
24 : QScrollView( parent, name, WNorthWestGravity | WResizeNoErase ), buffer() 23 : QScrollView( parent, name, WNorthWestGravity | WResizeNoErase ), buffer()
25{ 24{
26 buffer.resize( size() ); 25 buffer.resize( size() );
27 buffer.fill( colorGroup().color( QColorGroup::Base ) ); 26 buffer.fill( colorGroup().color( QColorGroup::Base ) );
28} 27}
29 28
30ImageEdit::~ImageEdit() 29ImageEdit::~ImageEdit()
31{ 30{
32 31
33} 32}
34 33
35void ImageEdit::contentsMousePressEvent( QMouseEvent *e ) 34void ImageEdit::contentsMousePressEvent( QMouseEvent *e )
36{ 35{
37 lastPos = e->pos(); 36 lastPos = e->pos();
38} 37}
39 38
40void ImageEdit::contentsMouseMoveEvent( QMouseEvent *e ) 39void ImageEdit::contentsMouseMoveEvent( QMouseEvent *e )
41{ 40{
42 QPainter pw( viewport() ); 41 QPainter pw( viewport() );
43 QPainter pb( &buffer ); 42 QPainter pb( &buffer );
44 pb.drawLine( lastPos, e->pos() ); 43 pb.drawLine( lastPos, e->pos() );
45 pw.drawLine( contentsToViewport( lastPos ), 44 pw.drawLine( contentsToViewport( lastPos ),
46 contentsToViewport( e->pos() ) ); 45 contentsToViewport( e->pos() ) );
47 lastPos = e->pos(); 46 lastPos = e->pos();
48} 47}
49 48
50void ImageEdit::contentsMouseReleaseEvent( QMouseEvent * ) 49void ImageEdit::contentsMouseReleaseEvent( QMouseEvent * )
51{ 50{
52} 51}
53 52
54void ImageEdit::viewportResizeEvent( QResizeEvent *e ) 53void ImageEdit::viewportResizeEvent( QResizeEvent *e )
55{ 54{
56 enlargeBuffer(e->size()); 55 enlargeBuffer(e->size());
57} 56}
58 57
59void ImageEdit::enlargeBuffer( const QSize& sz ) 58void ImageEdit::enlargeBuffer( const QSize& sz )
60{ 59{
61 QSize osz = buffer.size(); 60 QSize osz = buffer.size();
62 QSize nsz( QMAX( osz.width(), sz.width() ), QMAX( osz.height(), sz.height() ) ); 61 QSize nsz( QMAX( osz.width(), sz.width() ), QMAX( osz.height(), sz.height() ) );
63 buffer.resize( nsz.width(), nsz.height() ); 62 buffer.resize( nsz.width(), nsz.height() );
64 // clear new area 63 // clear new area
65 QPainter p( &buffer ); 64 QPainter p( &buffer );
66 if ( sz.width() > osz.width() ) 65 if ( sz.width() > osz.width() )
67 p.fillRect( osz.width(), 0, sz.width() - osz.width(), nsz.height(), colorGroup().color( QColorGroup::Base ) ); 66 p.fillRect( osz.width(), 0, sz.width() - osz.width(), nsz.height(), colorGroup().color( QColorGroup::Base ) );
68 if ( sz.height() > osz.height() ) 67 if ( sz.height() > osz.height() )
69 p.fillRect( 0, osz.height(), nsz.width(), sz.height() - osz.height(), colorGroup().color( QColorGroup::Base ) ); 68 p.fillRect( 0, osz.height(), nsz.width(), sz.height() - osz.height(), colorGroup().color( QColorGroup::Base ) );
70 p.end(); 69 p.end();
71} 70}
72 71
73void ImageEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 72void ImageEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
74{ 73{
75 p->drawPixmap( cx, cy, buffer, cx, cy, cw, ch ); 74 p->drawPixmap( cx, cy, buffer, cx, cy, cw, ch );
76} 75}
77 76
78void ImageEdit::setPixmap( const QPixmap &pm ) 77void ImageEdit::setPixmap( const QPixmap &pm )
79{ 78{
80 QSize osz = buffer.size(); 79 QSize osz = buffer.size();
81 if ( pm.width() < osz.width() || pm.height() < osz.height() ) { 80 if ( pm.width() < osz.width() || pm.height() < osz.height() ) {
82 buffer.fill(white); 81 buffer.fill(white);
83 enlargeBuffer( pm.size() ); 82 enlargeBuffer( pm.size() );
84 QPainter p(&buffer); 83 QPainter p(&buffer);
85 p.drawPixmap(0,0,pm); 84 p.drawPixmap(0,0,pm);
86 } else { 85 } else {
87 buffer = pm; 86 buffer = pm;
88 } 87 }
89 resizeContents( buffer.width(), buffer.height() ); 88 resizeContents( buffer.width(), buffer.height() );
90 viewport()->repaint( FALSE ); 89 viewport()->repaint( FALSE );
91} 90}
92 91
93QPixmap ImageEdit::pixmap() const 92QPixmap ImageEdit::pixmap() const
94{ 93{
95 return buffer; 94 return buffer;
96} 95}
97 96
diff --git a/library/ir.cpp b/library/ir.cpp
index b5b726d..32c0925 100644
--- a/library/ir.cpp
+++ b/library/ir.cpp
@@ -1,118 +1,116 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "ir.h" 21#include "ir.h"
22 22
23#include <qstring.h>
24#include "qcopenvelope_qws.h" 23#include "qcopenvelope_qws.h"
25#include <qcopchannel_qws.h>
26#include "applnk.h" 24#include "applnk.h"
27 25
28/*! 26/*!
29 \class Ir ir.h 27 \class Ir ir.h
30 \brief The Ir class implements basic support for sending objects over an 28 \brief The Ir class implements basic support for sending objects over an
31 infrared communication link. 29 infrared communication link.
32 30
33 Both \link doclnk.html DocLnk\endlink objects and files can be 31 Both \link doclnk.html DocLnk\endlink objects and files can be
34 sent to another device via the infrared link using the send() 32 sent to another device via the infrared link using the send()
35 function. When the send has completed the done() signal is 33 function. When the send has completed the done() signal is
36 emitted. 34 emitted.
37 35
38 The supported() function returns whether the device supports 36 The supported() function returns whether the device supports
39 infrared communication or not. 37 infrared communication or not.
40 38
41 \ingroup qtopiaemb 39 \ingroup qtopiaemb
42*/ 40*/
43 41
44/*! 42/*!
45 Constructs an Ir object. The \a parent and \a name classes are the 43 Constructs an Ir object. The \a parent and \a name classes are the
46 standard QObject parameters. 44 standard QObject parameters.
47*/ 45*/
48Ir::Ir( QObject *parent, const char *name ) 46Ir::Ir( QObject *parent, const char *name )
49 : QObject( parent, name ) 47 : QObject( parent, name )
50{ 48{
51#ifndef QT_NO_COP 49#ifndef QT_NO_COP
52 ch = new QCopChannel( "QPE/Obex" ); 50 ch = new QCopChannel( "QPE/Obex" );
53 connect( ch, SIGNAL(received(const QCString &, const QByteArray &)), 51 connect( ch, SIGNAL(received(const QCString &, const QByteArray &)),
54 this, SLOT(obexMessage( const QCString &, const QByteArray &)) ); 52 this, SLOT(obexMessage( const QCString &, const QByteArray &)) );
55#endif 53#endif
56} 54}
57 55
58/*! 56/*!
59 Returns TRUE if the system supports infrared communication; 57 Returns TRUE if the system supports infrared communication;
60 otherwise returns FALSE. 58 otherwise returns FALSE.
61*/ 59*/
62bool Ir::supported() 60bool Ir::supported()
63{ 61{
64#ifndef QT_NO_COP 62#ifndef QT_NO_COP
65 return QCopChannel::isRegistered( "QPE/Obex" ); 63 return QCopChannel::isRegistered( "QPE/Obex" );
66#endif 64#endif
67} 65}
68 66
69/*! 67/*!
70 Sends the object in file \a fn over the infrared link. The \a 68 Sends the object in file \a fn over the infrared link. The \a
71 description is used in the text shown to the user while sending 69 description is used in the text shown to the user while sending
72 is in progress. The optional \a mimetype parameter specifies the 70 is in progress. The optional \a mimetype parameter specifies the
73 mimetype of the object. If this parameter is not set, it is 71 mimetype of the object. If this parameter is not set, it is
74 determined by the the filename's suffix. 72 determined by the the filename's suffix.
75 73
76 \sa done() 74 \sa done()
77*/ 75*/
78void Ir::send( const QString &fn, const QString &description, const QString &mimetype) 76void Ir::send( const QString &fn, const QString &description, const QString &mimetype)
79{ 77{
80 if ( !filename.isEmpty() ) return; 78 if ( !filename.isEmpty() ) return;
81 filename = fn; 79 filename = fn;
82#ifndef QT_NO_COP 80#ifndef QT_NO_COP
83 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); 81 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
84 e << description << filename << mimetype; 82 e << description << filename << mimetype;
85#endif 83#endif
86} 84}
87 85
88/*! 86/*!
89 \overload 87 \overload
90 88
91 Uses the DocLnk::file() and DocLnk::type() of \a doc. 89 Uses the DocLnk::file() and DocLnk::type() of \a doc.
92 90
93 \sa done() 91 \sa done()
94*/ 92*/
95void Ir::send( const DocLnk &doc, const QString &description ) 93void Ir::send( const DocLnk &doc, const QString &description )
96{ 94{
97 send( doc.file(), description, doc.type() ); 95 send( doc.file(), description, doc.type() );
98} 96}
99 97
100/*! 98/*!
101 \fn Ir::done( Ir *ir ); 99 \fn Ir::done( Ir *ir );
102 100
103 This signal is emitted by \a ir, when the send comand has been processed. 101 This signal is emitted by \a ir, when the send comand has been processed.
104*/ 102*/
105 103
106/*!\internal 104/*!\internal
107 */ 105 */
108void Ir::obexMessage( const QCString &msg, const QByteArray &data) 106void Ir::obexMessage( const QCString &msg, const QByteArray &data)
109{ 107{
110 if ( msg == "done(QString)" ) { 108 if ( msg == "done(QString)" ) {
111 QString fn; 109 QString fn;
112 QDataStream stream( data, IO_ReadOnly ); 110 QDataStream stream( data, IO_ReadOnly );
113 stream >> fn; 111 stream >> fn;
114 if ( fn == filename ) 112 if ( fn == filename )
115 emit done( this ); 113 emit done( this );
116 } 114 }
117} 115}
118 116
diff --git a/library/lnkproperties.cpp b/library/lnkproperties.cpp
index 8dca4ab..0661423 100644
--- a/library/lnkproperties.cpp
+++ b/library/lnkproperties.cpp
@@ -1,218 +1,217 @@
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"
25#include "lnkproperties.h"
26#include "lnkpropertiesbase_p.h" 24#include "lnkpropertiesbase_p.h"
25#include "lnkproperties.h"
27#include "ir.h" 26#include "ir.h"
28 27
29#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
30#include <qpe/applnk.h> 29#include <qpe/applnk.h>
31#include <qpe/global.h> 30#include <qpe/global.h>
32#include <qpe/categorywidget.h> 31#include <qpe/categorywidget.h>
33#include <qpe/qcopenvelope_qws.h> 32#include <qpe/qcopenvelope_qws.h>
34#include <qpe/filemanager.h> 33#include <qpe/filemanager.h>
35#include <qpe/config.h> 34#include <qpe/config.h>
36#include <qpe/storage.h> 35#include <qpe/storage.h>
37#include <qpe/qpemessagebox.h> 36#include <qpe/qpemessagebox.h>
38#include <qpe/mimetype.h> 37#include <qpe/mimetype.h>
39 38
40#include <qlineedit.h> 39#include <qlineedit.h>
41#include <qtoolbutton.h> 40#include <qtoolbutton.h>
42#include <qpushbutton.h> 41#include <qpushbutton.h>
43#include <qgroupbox.h> 42#include <qgroupbox.h>
44#include <qcheckbox.h> 43#include <qcheckbox.h>
45#include <qlabel.h> 44#include <qlabel.h>
46#include <qlayout.h> 45#include <qlayout.h>
47#include <qfile.h> 46#include <qfile.h>
48#include <qfileinfo.h> 47#include <qfileinfo.h>
49#include <qmessagebox.h> 48#include <qmessagebox.h>
50#include <qsize.h> 49#include <qsize.h>
51#include <qcombobox.h> 50#include <qcombobox.h>
52#include <qregexp.h> 51#include <qregexp.h>
53#include <qbuttongroup.h> 52#include <qbuttongroup.h>
54 53
55#include <stdlib.h> 54#include <stdlib.h>
56 55
57LnkProperties::LnkProperties( AppLnk* l, QWidget* parent ) 56LnkProperties::LnkProperties( AppLnk* l, QWidget* parent )
58 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 ) 57 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 )
59{ 58{
60 setCaption( tr("Properties") ); 59 setCaption( tr("Properties") );
61 60
62 QVBoxLayout *vbox = new QVBoxLayout( this ); 61 QVBoxLayout *vbox = new QVBoxLayout( this );
63 d = new LnkPropertiesBase( this ); 62 d = new LnkPropertiesBase( this );
64 vbox->add( d ); 63 vbox->add( d );
65 64
66 // hide custom rotation feature for now, need a new implementation to fit quicklauch, 65 // hide custom rotation feature for now, need a new implementation to fit quicklauch,
67 // is confusing for the user and doubtable useful since life rotation 66 // is confusing for the user and doubtable useful since life rotation
68 d->rotate->hide(); 67 d->rotate->hide();
69 d->rotateButtons->hide(); 68 d->rotateButtons->hide();
70 69
71 d->docname->setText(l->name()); 70 d->docname->setText(l->name());
72 QString inf; 71 QString inf;
73 if ( l->type().isEmpty() ) { 72 if ( l->type().isEmpty() ) {
74 d->type->hide(); 73 d->type->hide();
75 d->typeLabel->hide(); 74 d->typeLabel->hide();
76 } else { 75 } else {
77 d->type->setText( l->type() ); 76 d->type->setText( l->type() );
78 } 77 }
79 78
80 if ( l->comment().isEmpty() ) { 79 if ( l->comment().isEmpty() ) {
81 d->comment->hide(); 80 d->comment->hide();
82 d->commentLabel->hide(); 81 d->commentLabel->hide();
83 } else { 82 } else {
84 d->comment->setText( l->comment() ); 83 d->comment->setText( l->comment() );
85 } 84 }
86 85
87 connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk())); 86 connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk()));
88 if ( lnk->type().contains('/') ) { // A document? (#### better predicate needed) 87 if ( lnk->type().contains('/') ) { // A document? (#### better predicate needed)
89 connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk())); 88 connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk()));
90 connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk())); 89 connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk()));
91 90
92 d->docname->setReadOnly( FALSE ); 91 d->docname->setReadOnly( FALSE );
93 d->preload->hide(); 92 d->preload->hide();
94 d->rotate->hide(); 93 d->rotate->hide();
95 d->rotateButtons->hide(); 94 d->rotateButtons->hide();
96 d->labelspacer->hide(); 95 d->labelspacer->hide();
97 96
98 // ### THIS MUST GO, FIX WIERD BUG in QLAYOUT 97 // ### THIS MUST GO, FIX WIERD BUG in QLAYOUT
99 d->categoryEdit->kludge(); 98 d->categoryEdit->kludge();
100 99
101 d->categoryEdit->setCategories( lnk->categories(), 100 d->categoryEdit->setCategories( lnk->categories(),
102 "Document View", 101 "Document View",
103 tr("Document View") ); 102 tr("Document View") );
104 setupLocations(); 103 setupLocations();
105 } else { 104 } else {
106 d->unlink->hide(); 105 d->unlink->hide();
107 d->duplicate->hide(); 106 d->duplicate->hide();
108 d->beam->hide(); 107 d->beam->hide();
109 d->hline->hide(); 108 d->hline->hide();
110 d->locationLabel->hide(); 109 d->locationLabel->hide();
111 d->locationCombo->hide(); 110 d->locationCombo->hide();
112 111
113 // Can't edit categories, since the app .desktop files are global, 112 // Can't edit categories, since the app .desktop files are global,
114 // possibly read-only. 113 // possibly read-only.
115 d->categoryEdit->hide(); 114 d->categoryEdit->hide();
116 115
117 d->docname->setReadOnly( TRUE ); 116 d->docname->setReadOnly( TRUE );
118 117
119 if ( l->property("CanFastload") == "0" ) 118 if ( l->property("CanFastload") == "0" )
120 d->preload->hide(); 119 d->preload->hide();
121 if ( !l->property("Rotation"). isEmpty ()) { 120 if ( !l->property("Rotation"). isEmpty ()) {
122 d->rotate->setChecked ( true ); 121 d->rotate->setChecked ( true );
123 //don't use rotate buttons for now (see comment above) 122 //don't use rotate buttons for now (see comment above)
124 //d->rotateButtons->setButton((l->rotation().toInt()%360)/90); 123 //d->rotateButtons->setButton((l->rotation().toInt()%360)/90);
125 } 124 }
126 else { 125 else {
127 d->rotateButtons->setEnabled(false); 126 d->rotateButtons->setEnabled(false);
128 } 127 }
129 128
130 Config cfg("Launcher"); 129 Config cfg("Launcher");
131 cfg.setGroup("Preload"); 130 cfg.setGroup("Preload");
132 QStringList apps = cfg.readListEntry("Apps",','); 131 QStringList apps = cfg.readListEntry("Apps",',');
133 d->preload->setChecked( apps.contains(l->exec()) ); 132 d->preload->setChecked( apps.contains(l->exec()) );
134 if ( Global::isBuiltinCommand(lnk->exec()) ) 133 if ( Global::isBuiltinCommand(lnk->exec()) )
135 d->preload->hide(); // builtins are always fast 134 d->preload->hide(); // builtins are always fast
136 135
137 currentLocation = 0; // apps not movable (yet) 136 currentLocation = 0; // apps not movable (yet)
138 } 137 }
139} 138}
140 139
141LnkProperties::~LnkProperties() 140LnkProperties::~LnkProperties()
142{ 141{
143} 142}
144 143
145void LnkProperties::unlinkLnk() 144void LnkProperties::unlinkLnk()
146{ 145{
147 if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) { 146 if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) {
148 lnk->removeFiles(); 147 lnk->removeFiles();
149 if ( QFile::exists(lnk->file()) ) { 148 if ( QFile::exists(lnk->file()) ) {
150 QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") ); 149 QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") );
151 } else { 150 } else {
152 reject(); 151 reject();
153 } 152 }
154 } 153 }
155} 154}
156 155
157void LnkProperties::setupLocations() 156void LnkProperties::setupLocations()
158{ 157{
159 QFileInfo fi( lnk->file() ); 158 QFileInfo fi( lnk->file() );
160 fileSize = fi.size(); 159 fileSize = fi.size();
161 StorageInfo storage; 160 StorageInfo storage;
162 const QList<FileSystem> &fs = storage.fileSystems(); 161 const QList<FileSystem> &fs = storage.fileSystems();
163 QListIterator<FileSystem> it ( fs ); 162 QListIterator<FileSystem> it ( fs );
164 QString s; 163 QString s;
165 QString homeDir = getenv("HOME"); 164 QString homeDir = getenv("HOME");
166 QString hardDiskHome; 165 QString hardDiskHome;
167 QString hardDiskPath; 166 QString hardDiskPath;
168 int index = 0; 167 int index = 0;
169 currentLocation = -1; 168 currentLocation = -1;
170 for ( ; it.current(); ++it ) { 169 for ( ; it.current(); ++it ) {
171 // we add 10k to the file size so we are sure we can also save the desktop file 170 // we add 10k to the file size so we are sure we can also save the desktop file
172 if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) { 171 if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) {
173 if ( (*it)->isRemovable() || 172 if ( (*it)->isRemovable() ||
174 (*it)->disk() == "/dev/mtdblock1" || 173 (*it)->disk() == "/dev/mtdblock1" ||
175 (*it)->disk() == "/dev/mtdblock/1" || 174 (*it)->disk() == "/dev/mtdblock/1" ||
176 (*it)->disk().left(13) == "/dev/mtdblock" || 175 (*it)->disk().left(13) == "/dev/mtdblock" ||
177 (*it)->disk() == "/dev/mtdblock6" || 176 (*it)->disk() == "/dev/mtdblock6" ||
178 (*it )->disk() == "/dev/root" || 177 (*it )->disk() == "/dev/root" ||
179 (*it)->disk() == "tmpfs" ) { 178 (*it)->disk() == "tmpfs" ) {
180 d->locationCombo->insertItem( (*it)->name(), index ); 179 d->locationCombo->insertItem( (*it)->name(), index );
181 locations.append( ( ((*it)->isRemovable() || 180 locations.append( ( ((*it)->isRemovable() ||
182 (*it)->disk() == "/dev/mtdblock6" || 181 (*it)->disk() == "/dev/mtdblock6" ||
183 (*it)->disk() == "tmpfs" ) 182 (*it)->disk() == "tmpfs" )
184 ? (*it)->path() : homeDir) ); 183 ? (*it)->path() : homeDir) );
185 if ( lnk->file().contains( (*it)->path() ) ) { 184 if ( lnk->file().contains( (*it)->path() ) ) {
186 d->locationCombo->setCurrentItem( index ); 185 d->locationCombo->setCurrentItem( index );
187 currentLocation = index; 186 currentLocation = index;
188 } 187 }
189 index++; 188 index++;
190 } else if ( (*it)->name().contains( tr("Hard Disk") ) && 189 } else if ( (*it)->name().contains( tr("Hard Disk") ) &&
191 homeDir.contains( (*it)->path() ) && 190 homeDir.contains( (*it)->path() ) &&
192 (*it)->path().length() > hardDiskHome.length() ) { 191 (*it)->path().length() > hardDiskHome.length() ) {
193 hardDiskHome = (*it)->name(); 192 hardDiskHome = (*it)->name();
194 hardDiskPath = (*it)->path(); 193 hardDiskPath = (*it)->path();
195 } 194 }
196 } 195 }
197 } 196 }
198 if ( !hardDiskHome.isEmpty() ) { 197 if ( !hardDiskHome.isEmpty() ) {
199 d->locationCombo->insertItem( hardDiskHome ); 198 d->locationCombo->insertItem( hardDiskHome );
200 locations.append( hardDiskPath ); 199 locations.append( hardDiskPath );
201 if ( currentLocation == -1 ) { // assume it's the hard disk 200 if ( currentLocation == -1 ) { // assume it's the hard disk
202 d->locationCombo->setCurrentItem( index ); 201 d->locationCombo->setCurrentItem( index );
203 currentLocation = index; 202 currentLocation = index;
204 } 203 }
205 } 204 }
206} 205}
207 206
208void LnkProperties::duplicateLnk() 207void LnkProperties::duplicateLnk()
209{ 208{
210 // The duplicate takes the new properties. 209 // The duplicate takes the new properties.
211 DocLnk newdoc( *((DocLnk *)lnk) ); 210 DocLnk newdoc( *((DocLnk *)lnk) );
212 if ( d->docname->text() == lnk->name() ) 211 if ( d->docname->text() == lnk->name() )
213 newdoc.setName(tr("Copy of ")+d->docname->text()); 212 newdoc.setName(tr("Copy of ")+d->docname->text());
214 else 213 else
215 newdoc.setName(d->docname->text()); 214 newdoc.setName(d->docname->text());
216 215
217 if ( !copyFile( newdoc ) ) { 216 if ( !copyFile( newdoc ) ) {
218 QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") ); 217 QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") );
diff --git a/library/mimetype.cpp b/library/mimetype.cpp
index d0a578e..23de70b 100644
--- a/library/mimetype.cpp
+++ b/library/mimetype.cpp
@@ -1,225 +1,221 @@
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#include "mimetype.h" 22#include "mimetype.h"
23#include "applnk.h" 23#include "applnk.h"
24#include "resource.h" 24#include "resource.h"
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include "config.h" 26#include "config.h"
27 27
28#include <qfile.h> 28#include <qfile.h>
29#include <qdict.h>
30#include <qregexp.h>
31#include <qstringlist.h>
32#include <qtextstream.h> 29#include <qtextstream.h>
33#include <qmap.h>
34 30
35 31
36static void cleanupMime() 32static void cleanupMime()
37{ 33{
38 MimeType::clear(); 34 MimeType::clear();
39} 35}
40 36
41class MimeTypeData { 37class MimeTypeData {
42public: 38public:
43 MimeTypeData(const QString& i) : 39 MimeTypeData(const QString& i) :
44 id(i) 40 id(i)
45 { 41 {
46 apps.setAutoDelete(TRUE); 42 apps.setAutoDelete(TRUE);
47 } 43 }
48 QString id; 44 QString id;
49 QString extension; 45 QString extension;
50 QList<AppLnk> apps; 46 QList<AppLnk> apps;
51 47
52 QString description() 48 QString description()
53 { 49 {
54 if ( desc.isEmpty() ) 50 if ( desc.isEmpty() )
55 desc = QPEApplication::tr("%1 document").arg(apps.first()->name()); 51 desc = QPEApplication::tr("%1 document").arg(apps.first()->name());
56 return desc; 52 return desc;
57 } 53 }
58 54
59 QPixmap regIcon() 55 QPixmap regIcon()
60 { 56 {
61 if ( regicon.isNull() ) 57 if ( regicon.isNull() )
62 loadPixmaps(); 58 loadPixmaps();
63 return regicon; 59 return regicon;
64 } 60 }
65 61
66 QPixmap bigIcon() 62 QPixmap bigIcon()
67 { 63 {
68 if ( bigicon.isNull() ) 64 if ( bigicon.isNull() )
69 loadPixmaps(); 65 loadPixmaps();
70 return bigicon; 66 return bigicon;
71 } 67 }
72 68
73private: 69private:
74 void loadPixmaps() 70 void loadPixmaps()
75 { 71 {
76 if ( apps.count() ) { 72 if ( apps.count() ) {
77 QString icon; 73 QString icon;
78 for (AppLnk* lnk = apps.first(); icon.isNull() && lnk; lnk=apps.next()) { 74 for (AppLnk* lnk = apps.first(); icon.isNull() && lnk; lnk=apps.next()) {
79 QStringList icons = lnk->mimeTypeIcons(); 75 QStringList icons = lnk->mimeTypeIcons();
80 if ( icons.count() ) { 76 if ( icons.count() ) {
81 QStringList types = lnk->mimeTypes(); 77 QStringList types = lnk->mimeTypes();
82 for (QStringList::ConstIterator t=types.begin(),i=icons.begin(); t!=types.end() && i!=icons.end(); ++i,++t) { 78 for (QStringList::ConstIterator t=types.begin(),i=icons.begin(); t!=types.end() && i!=icons.end(); ++i,++t) {
83 if ( *t == id ) { 79 if ( *t == id ) {
84 icon = *i; 80 icon = *i;
85 break; 81 break;
86 } 82 }
87 } 83 }
88 } 84 }
89 } 85 }
90 if ( icon.isNull() ) { 86 if ( icon.isNull() ) {
91 AppLnk* lnk = apps.first(); 87 AppLnk* lnk = apps.first();
92 regicon = lnk->pixmap(); 88 regicon = lnk->pixmap();
93 bigicon = lnk->bigPixmap(); 89 bigicon = lnk->bigPixmap();
94 } else { 90 } else {
95 QImage unscaledIcon = Resource::loadImage( icon ); 91 QImage unscaledIcon = Resource::loadImage( icon );
96 regicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); 92 regicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
97 bigicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ) ); 93 bigicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ) );
98 } 94 }
99 } 95 }
100 } 96 }
101 97
102 QPixmap regicon; 98 QPixmap regicon;
103 QPixmap bigicon; 99 QPixmap bigicon;
104 QString desc; 100 QString desc;
105}; 101};
106 102
107class MimeType::Private : public QDict<MimeTypeData> { 103class MimeType::Private : public QDict<MimeTypeData> {
108public: 104public:
109 Private() {} 105 Private() {}
110 ~Private() {} 106 ~Private() {}
111 107
112 // ... 108 // ...
113}; 109};
114 110
115MimeType::Private* MimeType::d=0; 111MimeType::Private* MimeType::d=0;
116static QMap<QString,QString> *typeFor = 0; 112static QMap<QString,QString> *typeFor = 0;
117static QMap<QString,QStringList> *extFor = 0; 113static QMap<QString,QStringList> *extFor = 0;
118 114
119MimeType::Private& MimeType::data() 115MimeType::Private& MimeType::data()
120{ 116{
121 if ( !d ) { 117 if ( !d ) {
122 d = new Private; 118 d = new Private;
123 d->setAutoDelete(TRUE); 119 d->setAutoDelete(TRUE);
124 static bool setCleanup = FALSE; 120 static bool setCleanup = FALSE;
125 if ( !setCleanup ) { 121 if ( !setCleanup ) {
126 qAddPostRoutine( cleanupMime ); 122 qAddPostRoutine( cleanupMime );
127 setCleanup = TRUE; 123 setCleanup = TRUE;
128 } 124 }
129 } 125 }
130 return *d; 126 return *d;
131} 127}
132 128
133/*! 129/*!
134 \class MimeType mimetype.h 130 \class MimeType mimetype.h
135 \brief The MimeType class provides MIME type information. 131 \brief The MimeType class provides MIME type information.
136 132
137 A MimeType object is a light-weight value which 133 A MimeType object is a light-weight value which
138 provides information about a MIME type. 134 provides information about a MIME type.
139 135
140 \ingroup qtopiaemb 136 \ingroup qtopiaemb
141*/ 137*/
142 138
143/*! 139/*!
144 Constructs a MimeType. 140 Constructs a MimeType.
145 Normally, \a ext_or_id is a MIME type, 141 Normally, \a ext_or_id is a MIME type,
146 but if \a ext_or_id starts with / or contains no /, 142 but if \a ext_or_id starts with / or contains no /,
147 it is interpretted as a filename and the 143 it is interpretted as a filename and the
148 extension (eg. .txt) is used as the 144 extension (eg. .txt) is used as the
149 MIME type. 145 MIME type.
150*/ 146*/
151MimeType::MimeType( const QString& ext_or_id ) 147MimeType::MimeType( const QString& ext_or_id )
152{ 148{
153 init(ext_or_id); 149 init(ext_or_id);
154} 150}
155 151
156/*! 152/*!
157 Constructs a MimeType from the type() of \a lnk. 153 Constructs a MimeType from the type() of \a lnk.
158*/ 154*/
159MimeType::MimeType( const DocLnk& lnk ) 155MimeType::MimeType( const DocLnk& lnk )
160{ 156{
161 init(lnk.type()); 157 init(lnk.type());
162} 158}
163 159
164/*! 160/*!
165 Returns the MIME type identifier. 161 Returns the MIME type identifier.
166*/ 162*/
167QString MimeType::id() const 163QString MimeType::id() const
168{ 164{
169 return i; 165 return i;
170} 166}
171 167
172/*! 168/*!
173 Returns a description of the MIME Type. This is usually based 169 Returns a description of the MIME Type. This is usually based
174 on the application() associated with the type. 170 on the application() associated with the type.
175*/ 171*/
176QString MimeType::description() const 172QString MimeType::description() const
177{ 173{
178 MimeTypeData* d = data(i); 174 MimeTypeData* d = data(i);
179 return d ? d->description() : QString::null; 175 return d ? d->description() : QString::null;
180} 176}
181 177
182/*! 178/*!
183 Returns a small QPixmap appropriate for the MIME type. 179 Returns a small QPixmap appropriate for the MIME type.
184*/ 180*/
185QPixmap MimeType::pixmap() const 181QPixmap MimeType::pixmap() const
186{ 182{
187 MimeTypeData* d = data(i); 183 MimeTypeData* d = data(i);
188 return d ? d->regIcon() : QPixmap(); 184 return d ? d->regIcon() : QPixmap();
189} 185}
190 186
191/*! 187/*!
192 \internal 188 \internal
193 This function is not generally available. 189 This function is not generally available.
194*/ 190*/
195QString MimeType::extension() const 191QString MimeType::extension() const
196{ 192{
197 return extensions().first(); 193 return extensions().first();
198} 194}
199 195
200 196
201/*! 197/*!
202 \internal 198 \internal
203 This function is not generally available. 199 This function is not generally available.
204*/ 200*/
205QStringList MimeType::extensions() const 201QStringList MimeType::extensions() const
206{ 202{
207 loadExtensions(); 203 loadExtensions();
208 return *(*extFor).find(i); 204 return *(*extFor).find(i);
209} 205}
210 206
211/*! 207/*!
212 Returns a larger QPixmap appropriate for the MIME type. 208 Returns a larger QPixmap appropriate for the MIME type.
213*/ 209*/
214QPixmap MimeType::bigPixmap() const 210QPixmap MimeType::bigPixmap() const
215{ 211{
216 MimeTypeData* d = data(i); 212 MimeTypeData* d = data(i);
217 return d ? d->bigIcon() : QPixmap(); 213 return d ? d->bigIcon() : QPixmap();
218} 214}
219 215
220/*! 216/*!
221 Returns the AppLnk defining the application associated 217 Returns the AppLnk defining the application associated
222 with this MIME type, or 0 if none is associated. 218 with this MIME type, or 0 if none is associated.
223 219
224 The caller must not retain the pointer, 220 The caller must not retain the pointer,
225 but of course you can dereference it to take a copy if needed. 221 but of course you can dereference it to take a copy if needed.
diff --git a/library/qcopenvelope_qws.cpp b/library/qcopenvelope_qws.cpp
index 0aac32b..8f58787 100644
--- a/library/qcopenvelope_qws.cpp
+++ b/library/qcopenvelope_qws.cpp
@@ -1,147 +1,145 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef QT_NO_COP 21#ifndef QT_NO_COP
22#include "qcopenvelope_qws.h" 22#include "qcopenvelope_qws.h"
23#endif 23#endif
24#include "global.h"
25#include <qbuffer.h> 24#include <qbuffer.h>
26#include <qdatastream.h>
27#include <qfile.h> 25#include <qfile.h>
28#include <unistd.h> 26#include <unistd.h>
29#include <errno.h> 27#include <errno.h>
30#include <sys/file.h> 28#include <sys/file.h>
31#include <sys/types.h> 29#include <sys/types.h>
32#include <sys/stat.h> 30#include <sys/stat.h>
33#include <time.h> 31#include <time.h>
34 32
35#ifndef QT_NO_COP 33#ifndef QT_NO_COP
36 34
37/*! 35/*!
38 \class QCopEnvelope qcopenvelope_qws.h 36 \class QCopEnvelope qcopenvelope_qws.h
39 \brief The QCopEnvelope class encapsulates and sends QCop messages 37 \brief The QCopEnvelope class encapsulates and sends QCop messages
40 over QCopChannels. 38 over QCopChannels.
41 39
42 QCop messages allow applications to communicate with each other. 40 QCop messages allow applications to communicate with each other.
43 These messages are sent using QCopEnvelope, and received by connecting 41 These messages are sent using QCopEnvelope, and received by connecting
44 to a QCopChannel. 42 to a QCopChannel.
45 43
46 To send a message, use the following protocol: 44 To send a message, use the following protocol:
47 45
48 \code 46 \code
49 QCopEnvelope e(channelname, messagename); 47 QCopEnvelope e(channelname, messagename);
50 e << parameter1 << parameter2 << ...; 48 e << parameter1 << parameter2 << ...;
51 \endcode 49 \endcode
52 50
53 For messages without parameters, simply use: 51 For messages without parameters, simply use:
54 52
55 \code 53 \code
56 QCopEnvelope e(channelname, messagename); 54 QCopEnvelope e(channelname, messagename);
57 \endcode 55 \endcode
58 56
59 (Do not try to simplify this further as it may confuse some 57 (Do not try to simplify this further as it may confuse some
60 compilers.) 58 compilers.)
61 59
62 The \c{channelname} of channels within Qtopia all start with "QPE/". 60 The \c{channelname} of channels within Qtopia all start with "QPE/".
63 The \c{messagename} is a function identifier followed by a list of types 61 The \c{messagename} is a function identifier followed by a list of types
64 in parentheses. There is no whitespace in the message name. 62 in parentheses. There is no whitespace in the message name.
65 63
66 To receive a message, you will generally just use your application's 64 To receive a message, you will generally just use your application's
67 predefined QPE/Application/\e{appname} channel 65 predefined QPE/Application/\e{appname} channel
68 (see QPEApplication::appMessage()), but you can make another channel 66 (see QPEApplication::appMessage()), but you can make another channel
69 and connect it to a slot like this: 67 and connect it to a slot like this:
70 68
71 \code 69 \code
72 myChannel = new QCopChannel( "QPE/FooBar", this ); 70 myChannel = new QCopChannel( "QPE/FooBar", this );
73 connect( myChannel, SIGNAL(received(const QCString &, const QByteArray &)), 71 connect( myChannel, SIGNAL(received(const QCString &, const QByteArray &)),
74 this, SLOT(fooBarMessage( const QCString &, const QByteArray &)) ); 72 this, SLOT(fooBarMessage( const QCString &, const QByteArray &)) );
75 \endcode 73 \endcode
76 74
77 See also, the \link qcop.html list of Qtopia messages\endlink. 75 See also, the \link qcop.html list of Qtopia messages\endlink.
78*/ 76*/
79 77
80/*! 78/*!
81 Constructs a QCopEnvelope that will write \a message to \a channel. 79 Constructs a QCopEnvelope that will write \a message to \a channel.
82 If \a message has parameters, you must then use operator<<() to 80 If \a message has parameters, you must then use operator<<() to
83 add these parameters to the envelope. 81 add these parameters to the envelope.
84*/ 82*/
85QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) : 83QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) :
86 QDataStream(new QBuffer), 84 QDataStream(new QBuffer),
87 ch(channel), msg(message) 85 ch(channel), msg(message)
88{ 86{
89 device()->open(IO_WriteOnly); 87 device()->open(IO_WriteOnly);
90} 88}
91 89
92/*! 90/*!
93 Writes the message and then destroys the QCopEnvelope. 91 Writes the message and then destroys the QCopEnvelope.
94*/ 92*/
95QCopEnvelope::~QCopEnvelope() 93QCopEnvelope::~QCopEnvelope()
96{ 94{
97 QByteArray data = ((QBuffer*)device())->buffer(); 95 QByteArray data = ((QBuffer*)device())->buffer();
98 const int pref=16; 96 const int pref=16;
99 if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) { 97 if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) {
100 QString qcopfn("/tmp/qcop-msg-"); 98 QString qcopfn("/tmp/qcop-msg-");
101 qcopfn += ch.mid(pref); 99 qcopfn += ch.mid(pref);
102 QFile qcopfile(qcopfn); 100 QFile qcopfile(qcopfn);
103 101
104 if ( qcopfile.open(IO_WriteOnly | IO_Append) ) { 102 if ( qcopfile.open(IO_WriteOnly | IO_Append) ) {
105#ifndef Q_OS_WIN32 103#ifndef Q_OS_WIN32
106 if(flock(qcopfile.handle(), LOCK_EX)) { 104 if(flock(qcopfile.handle(), LOCK_EX)) {
107 /* some error occurred */ 105 /* some error occurred */
108 qWarning(QString("Failed to obtain file lock on %1 (%2)") 106 qWarning(QString("Failed to obtain file lock on %1 (%2)")
109 .arg(qcopfn).arg( errno )); 107 .arg(qcopfn).arg( errno ));
110 } 108 }
111#endif 109#endif
112 { 110 {
113 QDataStream ds(&qcopfile); 111 QDataStream ds(&qcopfile);
114 ds << ch << msg << data; 112 ds << ch << msg << data;
115 qcopfile.flush(); 113 qcopfile.flush();
116#ifndef Q_OS_WIN32 114#ifndef Q_OS_WIN32
117 flock(qcopfile.handle(), LOCK_UN); 115 flock(qcopfile.handle(), LOCK_UN);
118#endif 116#endif
119 qcopfile.close(); 117 qcopfile.close();
120 } 118 }
121 119
122 QByteArray b; 120 QByteArray b;
123 QDataStream stream(b, IO_WriteOnly); 121 QDataStream stream(b, IO_WriteOnly);
124 stream << QString(ch.mid(pref)); 122 stream << QString(ch.mid(pref));
125 QCopChannel::send("QPE/Server", "processQCop(QString)", b); 123 QCopChannel::send("QPE/Server", "processQCop(QString)", b);
126 delete device(); 124 delete device();
127 return; 125 return;
128 } else { 126 } else {
129 qWarning(QString("Failed to open file %1") 127 qWarning(QString("Failed to open file %1")
130 .arg(qcopfn)); 128 .arg(qcopfn));
131 } // endif open 129 } // endif open
132 } 130 }
133 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) { 131 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
134 // If this is a message that should go along the SOAP channel, we move the 132 // If this is a message that should go along the SOAP channel, we move the
135 // endpoint URL to the data section. 133 // endpoint URL to the data section.
136 QString endpoint = ch.mid(9); 134 QString endpoint = ch.mid(9);
137 135
138 ch = "QPE/SOAP"; 136 ch = "QPE/SOAP";
139 // Since byte arrays are explicitly shared, this is appended to the data variable.. 137 // Since byte arrays are explicitly shared, this is appended to the data variable..
140 *this << endpoint; 138 *this << endpoint;
141 } 139 }
142 140
143 QCopChannel::send(ch,msg,data); 141 QCopChannel::send(ch,msg,data);
144 delete device(); 142 delete device();
145} 143}
146 144
147#endif 145#endif
diff --git a/library/qdawg.cpp b/library/qdawg.cpp
index af5dc82..2ea5734 100644
--- a/library/qdawg.cpp
+++ b/library/qdawg.cpp
@@ -1,215 +1,213 @@
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 "qdawg.h" 20#include "qdawg.h"
21#include <qintdict.h> 21#include <qintdict.h>
22#include <qvaluelist.h>
23#include <qtextstream.h>
24#include <qfile.h> 22#include <qfile.h>
25#include <qtl.h> 23#include <qtl.h>
26 24
27#include <limits.h> 25#include <limits.h>
28#include <stdio.h> 26#include <stdio.h>
29 27
30// for mmap 28// for mmap
31#include <sys/types.h> 29#include <sys/types.h>
32#include <sys/stat.h> 30#include <sys/stat.h>
33#include <sys/mman.h> 31#include <sys/mman.h>
34#include <fcntl.h> 32#include <fcntl.h>
35#include <errno.h> 33#include <errno.h>
36#include <unistd.h> 34#include <unistd.h>
37 35
38class QDawgPrivate; 36class QDawgPrivate;
39class QTrie; 37class QTrie;
40 38
41typedef QValueList<QTrie*> TrieClub; 39typedef QValueList<QTrie*> TrieClub;
42typedef QIntDict<TrieClub> TrieClubDirectory; 40typedef QIntDict<TrieClub> TrieClubDirectory;
43 41
44class TriePtr { 42class TriePtr {
45public: 43public:
46 QChar letter; 44 QChar letter;
47 QTrie* p; 45 QTrie* p;
48 int operator <(const TriePtr& o) const; 46 int operator <(const TriePtr& o) const;
49 int operator >(const TriePtr& o) const; 47 int operator >(const TriePtr& o) const;
50 int operator <=(const TriePtr& o) const; 48 int operator <=(const TriePtr& o) const;
51}; 49};
52 50
53class TrieList : public QValueList<TriePtr> { 51class TrieList : public QValueList<TriePtr> {
54 bool sorted; 52 bool sorted;
55public: 53public:
56 TrieList() 54 TrieList()
57 { 55 {
58 sorted=TRUE; 56 sorted=TRUE;
59 } 57 }
60 58
61 QTrie* findAdd(QChar c); 59 QTrie* findAdd(QChar c);
62 bool equal(TrieList& l); 60 bool equal(TrieList& l);
63 61
64 void sort() 62 void sort()
65 { 63 {
66 if ( !sorted ) { 64 if ( !sorted ) {
67 qHeapSort(*this); 65 qHeapSort(*this);
68 sorted = TRUE; 66 sorted = TRUE;
69 } 67 }
70 } 68 }
71}; 69};
72 70
73// A fast but memory-wasting temporary class. The Dawg is the goal. 71// A fast but memory-wasting temporary class. The Dawg is the goal.
74class QTrie { 72class QTrie {
75public: 73public:
76 QTrie(); 74 QTrie();
77 ~QTrie(); 75 ~QTrie();
78 76
79 void insertWord(const QString& s, uint index=0); 77 void insertWord(const QString& s, uint index=0);
80 bool equal(QTrie* o); 78 bool equal(QTrie* o);
81 void dump(int indent=0); 79 void dump(int indent=0);
82 80
83private: 81private:
84 TrieList children; 82 TrieList children;
85 bool isword; 83 bool isword;
86 84
87 friend class QDawgPrivate; 85 friend class QDawgPrivate;
88 int maxdepth; 86 int maxdepth;
89 int decendants; 87 int decendants;
90 int key; 88 int key;
91 void distributeKeys(TrieClubDirectory& directory); 89 void distributeKeys(TrieClubDirectory& directory);
92 QTrie* clubLeader(TrieClubDirectory& directory); 90 QTrie* clubLeader(TrieClubDirectory& directory);
93 int collectKeys(); 91 int collectKeys();
94 friend class TriePtr; 92 friend class TriePtr;
95 friend class TrieList; 93 friend class TrieList;
96}; 94};
97 95
98QTrie::QTrie() 96QTrie::QTrie()
99{ 97{
100 key = 0; 98 key = 0;
101 isword = FALSE; 99 isword = FALSE;
102} 100}
103 101
104QTrie::~QTrie() 102QTrie::~QTrie()
105{ 103{
106 // NOTE: we do not delete the children - after conversion to DAWG 104 // NOTE: we do not delete the children - after conversion to DAWG
107 // it's too difficult. The QTrie's are deleted via the directory. 105 // it's too difficult. The QTrie's are deleted via the directory.
108} 106}
109 107
110void QTrie::insertWord(const QString& s, uint index) 108void QTrie::insertWord(const QString& s, uint index)
111{ 109{
112 if ( index == s.length() ) { 110 if ( index == s.length() ) {
113 isword = TRUE; 111 isword = TRUE;
114 } else { 112 } else {
115 QTrie* t = children.findAdd(s[index]); 113 QTrie* t = children.findAdd(s[index]);
116 t->insertWord(s,index+1); 114 t->insertWord(s,index+1);
117 } 115 }
118} 116}
119 117
120bool QTrie::equal(QTrie* o) 118bool QTrie::equal(QTrie* o)
121{ 119{
122 if ( o == this ) return TRUE; 120 if ( o == this ) return TRUE;
123 if ( isword != o->isword ) 121 if ( isword != o->isword )
124 return FALSE; 122 return FALSE;
125 return children.equal(o->children); 123 return children.equal(o->children);
126} 124}
127 125
128void QTrie::dump(int indent) 126void QTrie::dump(int indent)
129{ 127{
130 for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) { 128 for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) {
131 QTrie* s = (*it).p; 129 QTrie* s = (*it).p;
132 for (int in=0; in<indent; in++) 130 for (int in=0; in<indent; in++)
133 fputc(' ',stderr); 131 fputc(' ',stderr);
134 fprintf(stderr," %c %d %s %p\n",(*it).letter.unicode(), 132 fprintf(stderr," %c %d %s %p\n",(*it).letter.unicode(),
135 s->key,s->isword?"word":"",s); 133 s->key,s->isword?"word":"",s);
136 s->dump(indent+2); 134 s->dump(indent+2);
137 } 135 }
138} 136}
139 137
140void QTrie::distributeKeys(TrieClubDirectory& directory) 138void QTrie::distributeKeys(TrieClubDirectory& directory)
141{ 139{
142 maxdepth = INT_MIN; 140 maxdepth = INT_MIN;
143 decendants = children.count(); 141 decendants = children.count();
144 key = 0; 142 key = 0;
145 for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) { 143 for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) {
146 QTrie* s = (*it).p; 144 QTrie* s = (*it).p;
147 QChar l = (*it).letter; 145 QChar l = (*it).letter;
148 s->distributeKeys(directory); 146 s->distributeKeys(directory);
149 key = key*64+l.unicode()+s->key*5; 147 key = key*64+l.unicode()+s->key*5;
150 decendants += s->decendants; 148 decendants += s->decendants;
151 if ( s->maxdepth+1 > maxdepth ) 149 if ( s->maxdepth+1 > maxdepth )
152 maxdepth = s->maxdepth+1; 150 maxdepth = s->maxdepth+1;
153 } 151 }
154 if ( decendants ) { 152 if ( decendants ) {
155 key += decendants + maxdepth*256 + children.count() * 65536; 153 key += decendants + maxdepth*256 + children.count() * 65536;
156 if ( !key ) key++; // unlikely 154 if ( !key ) key++; // unlikely
157 } 155 }
158 TrieClub* c = directory[key]; 156 TrieClub* c = directory[key];
159 if ( !c ) directory.insert(key, (c = new TrieClub) ); 157 if ( !c ) directory.insert(key, (c = new TrieClub) );
160 c->prepend(this); 158 c->prepend(this);
161} 159}
162 160
163QTrie* QTrie::clubLeader(TrieClubDirectory& directory) 161QTrie* QTrie::clubLeader(TrieClubDirectory& directory)
164{ 162{
165 if ( !key ) return directory[0]->first(); 163 if ( !key ) return directory[0]->first();
166 for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) { 164 for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) {
167 QTrie* t= (*it).p->clubLeader(directory); 165 QTrie* t= (*it).p->clubLeader(directory);
168 (*it).p = t; 166 (*it).p = t;
169 } 167 }
170 TrieClub *club = directory[key]; 168 TrieClub *club = directory[key];
171 for (TrieClub::Iterator it = club->begin(); it != club->end(); ++it) { 169 for (TrieClub::Iterator it = club->begin(); it != club->end(); ++it) {
172 QTrie* o = *it; 170 QTrie* o = *it;
173 if ( o->equal(this) ) 171 if ( o->equal(this) )
174 return o; 172 return o;
175 } 173 }
176 return this; 174 return this;
177} 175}
178 176
179int QTrie::collectKeys() 177int QTrie::collectKeys()
180{ 178{
181 int n=0; 179 int n=0;
182 if ( key ) key=0,n+=children.count(); 180 if ( key ) key=0,n+=children.count();
183 for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) 181 for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it)
184 n += (*it).p->collectKeys(); 182 n += (*it).p->collectKeys();
185 return n; 183 return n;
186} 184}
187 185
188int TriePtr::operator <(const TriePtr& o) const 186int TriePtr::operator <(const TriePtr& o) const
189 { return letter < o.letter; } 187 { return letter < o.letter; }
190int TriePtr::operator >(const TriePtr& o) const 188int TriePtr::operator >(const TriePtr& o) const
191 { return letter > o.letter; } 189 { return letter > o.letter; }
192int TriePtr::operator <=(const TriePtr& o) const 190int TriePtr::operator <=(const TriePtr& o) const
193 { return letter <= o.letter; } 191 { return letter <= o.letter; }
194 192
195bool TrieList::equal(TrieList& l) 193bool TrieList::equal(TrieList& l)
196{ 194{
197 if ( count() != l.count() ) 195 if ( count() != l.count() )
198 return FALSE; 196 return FALSE;
199 sort(); l.sort(); 197 sort(); l.sort();
200 ConstIterator it2 = begin(); 198 ConstIterator it2 = begin();
201 ConstIterator it = l.begin(); 199 ConstIterator it = l.begin();
202 for( ; it != l.end(); ++it, ++it2 ) 200 for( ; it != l.end(); ++it, ++it2 )
203 if ( (*it).letter != (*it2).letter || ! (*it).p->equal((*it2).p) ) 201 if ( (*it).letter != (*it2).letter || ! (*it).p->equal((*it2).p) )
204 return FALSE; 202 return FALSE;
205 return TRUE; 203 return TRUE;
206} 204}
207QTrie* TrieList::findAdd(QChar c) 205QTrie* TrieList::findAdd(QChar c)
208{ 206{
209 for (Iterator it=begin(); it!=end(); ++it) { 207 for (Iterator it=begin(); it!=end(); ++it) {
210 if ( (*it).letter == c ) 208 if ( (*it).letter == c )
211 return (*it).p; 209 return (*it).p;
212 } 210 }
213 TriePtr p; 211 TriePtr p;
214 p.p = new QTrie; 212 p.p = new QTrie;
215 p.letter = c; 213 p.letter = c;
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index c7ef2b7..262221e 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -913,385 +913,384 @@ bool QPEApplication::qwsEventFilter( QWSEvent * e )
913 popup->close(); 913 popup->close();
914 if ( active->inherits( "QDialog" ) ) { 914 if ( active->inherits( "QDialog" ) ) {
915 HackDialog * d = ( HackDialog * ) active; 915 HackDialog * d = ( HackDialog * ) active;
916 d->acceptIt(); 916 d->acceptIt();
917 return TRUE; 917 return TRUE;
918 } 918 }
919 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 919 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
920 QSignal s; 920 QSignal s;
921 s.connect( active, SLOT( accept() ) ); 921 s.connect( active, SLOT( accept() ) );
922 s.activate(); 922 s.activate();
923 } 923 }
924 else { 924 else {
925 // do the same as with the select key: Map to the default action of the widget: 925 // do the same as with the select key: Map to the default action of the widget:
926 mapToDefaultAction( ke, Qt::Key_Return ); 926 mapToDefaultAction( ke, Qt::Key_Return );
927 } 927 }
928 } 928 }
929 } 929 }
930 } 930 }
931 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 931 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
932 // Use special "select" key to do whatever default action a widget has 932 // Use special "select" key to do whatever default action a widget has
933 mapToDefaultAction( ke, Qt::Key_Space ); 933 mapToDefaultAction( ke, Qt::Key_Space );
934 } 934 }
935 else if ( ke->simpleData.keycode == Qt::Key_Escape && 935 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
936 ke->simpleData.is_press ) { 936 ke->simpleData.is_press ) {
937 // Escape key closes app if focus on toplevel 937 // Escape key closes app if focus on toplevel
938 QWidget * active = activeWindow(); 938 QWidget * active = activeWindow();
939 if ( active && active->testWFlags( WType_TopLevel ) && 939 if ( active && active->testWFlags( WType_TopLevel ) &&
940 ( int ) active->winId() == ke->simpleData.window && 940 ( int ) active->winId() == ke->simpleData.window &&
941 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 941 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
942 if ( active->inherits( "QDialog" ) ) { 942 if ( active->inherits( "QDialog" ) ) {
943 HackDialog * d = ( HackDialog * ) active; 943 HackDialog * d = ( HackDialog * ) active;
944 d->rejectIt(); 944 d->rejectIt();
945 return TRUE; 945 return TRUE;
946 } 946 }
947 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { 947 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
948 active->close(); 948 active->close();
949 } 949 }
950 } 950 }
951 } 951 }
952 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 952 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
953 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 953 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
954 // but we cannot access libopie function within libqpe :( 954 // but we cannot access libopie function within libqpe :(
955 955
956 QWidget * active = activeWindow ( ); 956 QWidget * active = activeWindow ( );
957 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 957 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
958 if ( d-> kbgrabbed ) { // we grabbed the keyboard 958 if ( d-> kbgrabbed ) { // we grabbed the keyboard
959 QChar ch ( ke-> simpleData.unicode ); 959 QChar ch ( ke-> simpleData.unicode );
960 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 960 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
961 ke-> simpleData.keycode, 961 ke-> simpleData.keycode,
962 ch. latin1 ( ), 962 ch. latin1 ( ),
963 ke-> simpleData.modifiers, 963 ke-> simpleData.modifiers,
964 QString ( ch ), 964 QString ( ch ),
965 ke-> simpleData.is_auto_repeat, 1 ); 965 ke-> simpleData.is_auto_repeat, 1 );
966 966
967 QObject *which = QWidget::keyboardGrabber ( ); 967 QObject *which = QWidget::keyboardGrabber ( );
968 if ( !which ) 968 if ( !which )
969 which = QApplication::focusWidget ( ); 969 which = QApplication::focusWidget ( );
970 if ( !which ) 970 if ( !which )
971 which = QApplication::activeWindow ( ); 971 which = QApplication::activeWindow ( );
972 if ( !which ) 972 if ( !which )
973 which = qApp; 973 which = qApp;
974 974
975 QApplication::sendEvent ( which, &qke ); 975 QApplication::sendEvent ( which, &qke );
976 } 976 }
977 else { // we didn't grab the keyboard, so send the event to the launcher 977 else { // we didn't grab the keyboard, so send the event to the launcher
978 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 978 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
979 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 979 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
980 } 980 }
981 } 981 }
982 return true; 982 return true;
983 } 983 }
984 } 984 }
985 if ( e->type == QWSEvent::Focus ) { 985 if ( e->type == QWSEvent::Focus ) {
986 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 986 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
987 if ( !fe->simpleData.get_focus ) { 987 if ( !fe->simpleData.get_focus ) {
988 QWidget * active = activeWindow(); 988 QWidget * active = activeWindow();
989 while ( active && active->isPopup() ) { 989 while ( active && active->isPopup() ) {
990 active->close(); 990 active->close();
991 active = activeWindow(); 991 active = activeWindow();
992 } 992 }
993 } 993 }
994 else { 994 else {
995 // make sure our modal widget is ALWAYS on top 995 // make sure our modal widget is ALWAYS on top
996 QWidget *topm = activeModalWidget(); 996 QWidget *topm = activeModalWidget();
997 if ( topm ) { 997 if ( topm ) {
998 topm->raise(); 998 topm->raise();
999 } 999 }
1000 } 1000 }
1001 if ( fe->simpleData.get_focus && inputMethodDict ) { 1001 if ( fe->simpleData.get_focus && inputMethodDict ) {
1002 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1002 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1003 if ( m == AlwaysOff ) 1003 if ( m == AlwaysOff )
1004 Global::hideInputMethod(); 1004 Global::hideInputMethod();
1005 if ( m == AlwaysOn ) 1005 if ( m == AlwaysOn )
1006 Global::showInputMethod(); 1006 Global::showInputMethod();
1007 } 1007 }
1008 } 1008 }
1009 1009
1010 1010
1011 return QApplication::qwsEventFilter( e ); 1011 return QApplication::qwsEventFilter( e );
1012} 1012}
1013#endif 1013#endif
1014 1014
1015/*! 1015/*!
1016 Destroys the QPEApplication. 1016 Destroys the QPEApplication.
1017*/ 1017*/
1018QPEApplication::~QPEApplication() 1018QPEApplication::~QPEApplication()
1019{ 1019{
1020 ungrabKeyboard(); 1020 ungrabKeyboard();
1021#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1021#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1022 // Need to delete QCopChannels early, since the display will 1022 // Need to delete QCopChannels early, since the display will
1023 // be gone by the time we get to ~QObject(). 1023 // be gone by the time we get to ~QObject().
1024 delete sysChannel; 1024 delete sysChannel;
1025 delete pidChannel; 1025 delete pidChannel;
1026#endif 1026#endif
1027 1027
1028 delete d; 1028 delete d;
1029} 1029}
1030 1030
1031/*! 1031/*!
1032 Returns <tt>$OPIEDIR/</tt>. 1032 Returns <tt>$OPIEDIR/</tt>.
1033*/ 1033*/
1034QString QPEApplication::qpeDir() 1034QString QPEApplication::qpeDir()
1035{ 1035{
1036 const char * base = getenv( "OPIEDIR" ); 1036 const char * base = getenv( "OPIEDIR" );
1037 if ( base ) 1037 if ( base )
1038 return QString( base ) + "/"; 1038 return QString( base ) + "/";
1039 1039
1040 return QString( "../" ); 1040 return QString( "../" );
1041} 1041}
1042 1042
1043/*! 1043/*!
1044 Returns the user's current Document directory. There is a trailing "/". 1044 Returns the user's current Document directory. There is a trailing "/".
1045 .. well, it does now,, and there's no trailing '/' 1045 .. well, it does now,, and there's no trailing '/'
1046*/ 1046*/
1047QString QPEApplication::documentDir() 1047QString QPEApplication::documentDir()
1048{ 1048{
1049 const char* base = getenv( "HOME"); 1049 const char* base = getenv( "HOME");
1050 if ( base ) 1050 if ( base )
1051 return QString( base ) + "/Documents"; 1051 return QString( base ) + "/Documents";
1052 1052
1053 return QString( "../Documents" ); 1053 return QString( "../Documents" );
1054} 1054}
1055 1055
1056static int deforient = -1; 1056static int deforient = -1;
1057 1057
1058/*! 1058/*!
1059 \internal 1059 \internal
1060*/ 1060*/
1061int QPEApplication::defaultRotation() 1061int QPEApplication::defaultRotation()
1062{ 1062{
1063 if ( deforient < 0 ) { 1063 if ( deforient < 0 ) {
1064 QString d = getenv( "QWS_DISPLAY" ); 1064 QString d = getenv( "QWS_DISPLAY" );
1065 if ( d.contains( "Rot90" ) ) { 1065 if ( d.contains( "Rot90" ) ) {
1066 deforient = 90; 1066 deforient = 90;
1067 } 1067 }
1068 else if ( d.contains( "Rot180" ) ) { 1068 else if ( d.contains( "Rot180" ) ) {
1069 deforient = 180; 1069 deforient = 180;
1070 } 1070 }
1071 else if ( d.contains( "Rot270" ) ) { 1071 else if ( d.contains( "Rot270" ) ) {
1072 deforient = 270; 1072 deforient = 270;
1073 } 1073 }
1074 else { 1074 else {
1075 deforient = 0; 1075 deforient = 0;
1076 } 1076 }
1077 } 1077 }
1078 return deforient; 1078 return deforient;
1079} 1079}
1080 1080
1081/*! 1081/*!
1082 \internal 1082 \internal
1083*/ 1083*/
1084void QPEApplication::setDefaultRotation( int r ) 1084void QPEApplication::setDefaultRotation( int r )
1085{ 1085{
1086 if ( qApp->type() == GuiServer ) { 1086 if ( qApp->type() == GuiServer ) {
1087 deforient = r; 1087 deforient = r;
1088 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1088 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1089 Config config("qpe"); 1089 Config config("qpe");
1090 config.setGroup( "Rotation" ); 1090 config.setGroup( "Rotation" );
1091 config.writeEntry( "Rot", r ); 1091 config.writeEntry( "Rot", r );
1092 } 1092 }
1093 else { 1093 else {
1094#ifndef QT_NO_COP 1094#ifndef QT_NO_COP
1095 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1095 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1096 e << r; 1096 e << r;
1097 } 1097 }
1098#endif 1098#endif
1099 1099
1100 } 1100 }
1101} 1101}
1102 1102
1103#include <qgfx_qws.h> 1103#include <qgfx_qws.h>
1104#include <qwindowsystem_qws.h> 1104#include <qwindowsystem_qws.h>
1105#include <qpixmapcache.h>
1106 1105
1107extern void qws_clearLoadedFonts(); 1106extern void qws_clearLoadedFonts();
1108 1107
1109void QPEApplication::setCurrentMode( int x, int y, int depth ) 1108void QPEApplication::setCurrentMode( int x, int y, int depth )
1110{ 1109{
1111 // Reset the caches 1110 // Reset the caches
1112 qws_clearLoadedFonts(); 1111 qws_clearLoadedFonts();
1113 QPixmapCache::clear(); 1112 QPixmapCache::clear();
1114 1113
1115 // Change the screen mode 1114 // Change the screen mode
1116 qt_screen->setMode(x, y, depth); 1115 qt_screen->setMode(x, y, depth);
1117 1116
1118 if ( qApp->type() == GuiServer ) { 1117 if ( qApp->type() == GuiServer ) {
1119 // Reconfigure the GuiServer 1118 // Reconfigure the GuiServer
1120 qwsServer->beginDisplayReconfigure(); 1119 qwsServer->beginDisplayReconfigure();
1121 qwsServer->endDisplayReconfigure(); 1120 qwsServer->endDisplayReconfigure();
1122 1121
1123 // Get all the running apps to reset 1122 // Get all the running apps to reset
1124 QCopEnvelope env( "QPE/System", "reset()" ); 1123 QCopEnvelope env( "QPE/System", "reset()" );
1125 } 1124 }
1126} 1125}
1127 1126
1128void QPEApplication::reset() { 1127void QPEApplication::reset() {
1129 // Reconnect to the screen 1128 // Reconnect to the screen
1130 qt_screen->disconnect(); 1129 qt_screen->disconnect();
1131 qt_screen->connect( QString::null ); 1130 qt_screen->connect( QString::null );
1132 1131
1133 // Redraw everything 1132 // Redraw everything
1134 applyStyle(); 1133 applyStyle();
1135} 1134}
1136 1135
1137/*! 1136/*!
1138 \internal 1137 \internal
1139*/ 1138*/
1140void QPEApplication::applyStyle() 1139void QPEApplication::applyStyle()
1141{ 1140{
1142 Config config( "qpe" ); 1141 Config config( "qpe" );
1143 config.setGroup( "Appearance" ); 1142 config.setGroup( "Appearance" );
1144 1143
1145#if QT_VERSION > 233 1144#if QT_VERSION > 233
1146#if !defined(OPIE_NO_OVERRIDE_QT) 1145#if !defined(OPIE_NO_OVERRIDE_QT)
1147 // don't block ourselves ... 1146 // don't block ourselves ...
1148 Opie::force_appearance = 0; 1147 Opie::force_appearance = 0;
1149 1148
1150 static QString appname = Opie::binaryName ( ); 1149 static QString appname = Opie::binaryName ( );
1151 1150
1152 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 1151 QStringList ex = config. readListEntry ( "NoStyle", ';' );
1153 int nostyle = 0; 1152 int nostyle = 0;
1154 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 1153 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
1155 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 1154 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
1156 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 1155 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
1157 break; 1156 break;
1158 } 1157 }
1159 } 1158 }
1160#else 1159#else
1161 int nostyle = 0; 1160 int nostyle = 0;
1162#endif 1161#endif
1163 1162
1164 // Widget style 1163 // Widget style
1165 QString style = config.readEntry( "Style", "FlatStyle" ); 1164 QString style = config.readEntry( "Style", "FlatStyle" );
1166 1165
1167 // don't set a custom style 1166 // don't set a custom style
1168 if ( nostyle & Opie::Force_Style ) 1167 if ( nostyle & Opie::Force_Style )
1169 style = "FlatStyle"; 1168 style = "FlatStyle";
1170 1169
1171 internalSetStyle ( style ); 1170 internalSetStyle ( style );
1172 1171
1173 // Colors - from /etc/colors/Liquid.scheme 1172 // Colors - from /etc/colors/Liquid.scheme
1174 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1173 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1175 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1174 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1176 QPalette pal( btncolor, bgcolor ); 1175 QPalette pal( btncolor, bgcolor );
1177 QString color = config.readEntry( "Highlight", "#73adef" ); 1176 QString color = config.readEntry( "Highlight", "#73adef" );
1178 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1177 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1179 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1178 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1180 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1179 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1181 color = config.readEntry( "Text", "#000000" ); 1180 color = config.readEntry( "Text", "#000000" );
1182 pal.setColor( QColorGroup::Text, QColor( color ) ); 1181 pal.setColor( QColorGroup::Text, QColor( color ) );
1183 color = config.readEntry( "ButtonText", "#000000" ); 1182 color = config.readEntry( "ButtonText", "#000000" );
1184 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1183 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1185 color = config.readEntry( "Base", "#FFFFFF" ); 1184 color = config.readEntry( "Base", "#FFFFFF" );
1186 pal.setColor( QColorGroup::Base, QColor( color ) ); 1185 pal.setColor( QColorGroup::Base, QColor( color ) );
1187 1186
1188 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1187 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1189 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1188 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1190 1189
1191 setPalette( pal, TRUE ); 1190 setPalette( pal, TRUE );
1192 1191
1193 // Window Decoration 1192 // Window Decoration
1194 QString dec = config.readEntry( "Decoration", "Flat" ); 1193 QString dec = config.readEntry( "Decoration", "Flat" );
1195 1194
1196 // don't set a custom deco 1195 // don't set a custom deco
1197 if ( nostyle & Opie::Force_Decoration ) 1196 if ( nostyle & Opie::Force_Decoration )
1198 dec = ""; 1197 dec = "";
1199 1198
1200 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle); 1199 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle);
1201 1200
1202 if ( dec != d->decorationName ) { 1201 if ( dec != d->decorationName ) {
1203 qwsSetDecoration( new QPEDecoration( dec ) ); 1202 qwsSetDecoration( new QPEDecoration( dec ) );
1204 d->decorationName = dec; 1203 d->decorationName = dec;
1205 } 1204 }
1206 1205
1207 // Font 1206 // Font
1208 QString ff = config.readEntry( "FontFamily", font().family() ); 1207 QString ff = config.readEntry( "FontFamily", font().family() );
1209 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1208 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1210 1209
1211 // don't set a custom font 1210 // don't set a custom font
1212 if ( nostyle & Opie::Force_Font ) { 1211 if ( nostyle & Opie::Force_Font ) {
1213 ff = "Vera"; 1212 ff = "Vera";
1214 fs = 10; 1213 fs = 10;
1215 } 1214 }
1216 1215
1217 setFont ( QFont ( ff, fs ), true ); 1216 setFont ( QFont ( ff, fs ), true );
1218 1217
1219#if !defined(OPIE_NO_OVERRIDE_QT) 1218#if !defined(OPIE_NO_OVERRIDE_QT)
1220 // revert to global blocking policy ... 1219 // revert to global blocking policy ...
1221 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 1220 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
1222 Opie::force_appearance &= ~nostyle; 1221 Opie::force_appearance &= ~nostyle;
1223#endif 1222#endif
1224#endif 1223#endif
1225} 1224}
1226 1225
1227void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1226void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1228{ 1227{
1229#ifdef Q_WS_QWS 1228#ifdef Q_WS_QWS
1230 QDataStream stream( data, IO_ReadOnly ); 1229 QDataStream stream( data, IO_ReadOnly );
1231 if ( msg == "applyStyle()" ) { 1230 if ( msg == "applyStyle()" ) {
1232 applyStyle(); 1231 applyStyle();
1233 } 1232 }
1234 else if ( msg == "toggleApplicationMenu()" ) { 1233 else if ( msg == "toggleApplicationMenu()" ) {
1235 QWidget *active = activeWindow ( ); 1234 QWidget *active = activeWindow ( );
1236 1235
1237 if ( active ) { 1236 if ( active ) {
1238 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1237 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1239 bool oldactive = man-> isActive ( ); 1238 bool oldactive = man-> isActive ( );
1240 1239
1241 man-> setActive( !man-> isActive() ); 1240 man-> setActive( !man-> isActive() );
1242 1241
1243 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1242 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1244 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1243 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1245 } 1244 }
1246 } 1245 }
1247 } 1246 }
1248 else if ( msg == "setDefaultRotation(int)" ) { 1247 else if ( msg == "setDefaultRotation(int)" ) {
1249 if ( type() == GuiServer ) { 1248 if ( type() == GuiServer ) {
1250 int r; 1249 int r;
1251 stream >> r; 1250 stream >> r;
1252 setDefaultRotation( r ); 1251 setDefaultRotation( r );
1253 } 1252 }
1254 } 1253 }
1255 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> 1254 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
1256 if ( type() == GuiServer ) { 1255 if ( type() == GuiServer ) {
1257 int x, y, depth; 1256 int x, y, depth;
1258 stream >> x; 1257 stream >> x;
1259 stream >> y; 1258 stream >> y;
1260 stream >> depth; 1259 stream >> depth;
1261 setCurrentMode( x, y, depth ); 1260 setCurrentMode( x, y, depth );
1262 } 1261 }
1263 } 1262 }
1264 else if ( msg == "reset()" ) { 1263 else if ( msg == "reset()" ) {
1265 if ( type() != GuiServer ) 1264 if ( type() != GuiServer )
1266 reset(); 1265 reset();
1267 } 1266 }
1268 else if ( msg == "setCurrentRotation(int)" ) { 1267 else if ( msg == "setCurrentRotation(int)" ) {
1269 int r; 1268 int r;
1270 stream >> r; 1269 stream >> r;
1271 setCurrentRotation( r ); 1270 setCurrentRotation( r );
1272 } 1271 }
1273 else if ( msg == "shutdown()" ) { 1272 else if ( msg == "shutdown()" ) {
1274 if ( type() == GuiServer ) 1273 if ( type() == GuiServer )
1275 shutdown(); 1274 shutdown();
1276 } 1275 }
1277 else if ( msg == "quit()" ) { 1276 else if ( msg == "quit()" ) {
1278 if ( type() != GuiServer ) 1277 if ( type() != GuiServer )
1279 tryQuit(); 1278 tryQuit();
1280 } 1279 }
1281 else if ( msg == "forceQuit()" ) { 1280 else if ( msg == "forceQuit()" ) {
1282 if ( type() != GuiServer ) 1281 if ( type() != GuiServer )
1283 quit(); 1282 quit();
1284 } 1283 }
1285 else if ( msg == "restart()" ) { 1284 else if ( msg == "restart()" ) {
1286 if ( type() == GuiServer ) 1285 if ( type() == GuiServer )
1287 restart(); 1286 restart();
1288 } 1287 }
1289 else if ( msg == "language(QString)" ) { 1288 else if ( msg == "language(QString)" ) {
1290 if ( type() == GuiServer ) { 1289 if ( type() == GuiServer ) {
1291 QString l; 1290 QString l;
1292 stream >> l; 1291 stream >> l;
1293 QString cl = getenv( "LANG" ); 1292 QString cl = getenv( "LANG" );
1294 if ( cl != l ) { 1293 if ( cl != l ) {
1295 if ( l.isNull() ) 1294 if ( l.isNull() )
1296 unsetenv( "LANG" ); 1295 unsetenv( "LANG" );
1297 else 1296 else
diff --git a/library/qpemenubar.cpp b/library/qpemenubar.cpp
index 3e5bad5..1d8eff4 100644
--- a/library/qpemenubar.cpp
+++ b/library/qpemenubar.cpp
@@ -1,217 +1,216 @@
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 INCLUDE_MENUITEM_DEF 21#define INCLUDE_MENUITEM_DEF
22 22
23#include "qpemenubar.h" 23#include "qpemenubar.h"
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qguardedptr.h>
26#include <qtimer.h> 25#include <qtimer.h>
27 26
28 27
29class QMenuBarHack : public QMenuBar 28class QMenuBarHack : public QMenuBar
30{ 29{
31public: 30public:
32 int activeItem() const { return actItem; } 31 int activeItem() const { return actItem; }
33 32
34 void goodbye() 33 void goodbye()
35 { 34 {
36 activateItemAt(-1); 35 activateItemAt(-1);
37 for ( unsigned int i = 0; i < count(); i++ ) { 36 for ( unsigned int i = 0; i < count(); i++ ) {
38 QMenuItem *mi = findItem( idAt(i) ); 37 QMenuItem *mi = findItem( idAt(i) );
39 if ( mi->popup() ) { 38 if ( mi->popup() ) {
40 mi->popup()->hide(); 39 mi->popup()->hide();
41 } 40 }
42 } 41 }
43 } 42 }
44}; 43};
45 44
46 45
47// Sharp ROM compatibility 46// Sharp ROM compatibility
48void QPEMenuToolFocusManager::setMenukeyEnabled ( bool ) 47void QPEMenuToolFocusManager::setMenukeyEnabled ( bool )
49{ 48{
50} 49}
51int QPEMenuBar::getOldFocus ( ) 50int QPEMenuBar::getOldFocus ( )
52{ 51{
53 return 0; 52 return 0;
54} 53}
55 54
56QPEMenuToolFocusManager *QPEMenuToolFocusManager::me = 0; 55QPEMenuToolFocusManager *QPEMenuToolFocusManager::me = 0;
57 56
58QPEMenuToolFocusManager::QPEMenuToolFocusManager() : QObject() 57QPEMenuToolFocusManager::QPEMenuToolFocusManager() : QObject()
59{ 58{
60 qApp->installEventFilter( this ); 59 qApp->installEventFilter( this );
61} 60}
62 61
63void QPEMenuToolFocusManager::addWidget( QWidget *w ) 62void QPEMenuToolFocusManager::addWidget( QWidget *w )
64{ 63{
65 list.append( GuardedWidget(w) ); 64 list.append( GuardedWidget(w) );
66} 65}
67 66
68void QPEMenuToolFocusManager::removeWidget( QWidget *w ) 67void QPEMenuToolFocusManager::removeWidget( QWidget *w )
69{ 68{
70 list.remove( GuardedWidget(w) ); 69 list.remove( GuardedWidget(w) );
71} 70}
72 71
73void QPEMenuToolFocusManager::setActive( bool a ) 72void QPEMenuToolFocusManager::setActive( bool a )
74{ 73{
75 if ( a ) { 74 if ( a ) {
76 oldFocus = qApp->focusWidget(); 75 oldFocus = qApp->focusWidget();
77 QValueList<GuardedWidget>::Iterator it; 76 QValueList<GuardedWidget>::Iterator it;
78 it = list.begin(); 77 it = list.begin();
79 while ( it != list.end() ) { 78 while ( it != list.end() ) {
80 QWidget *w = (*it); 79 QWidget *w = (*it);
81 if ( w && w->isEnabled() && w->isVisible() && 80 if ( w && w->isEnabled() && w->isVisible() &&
82 w->topLevelWidget() == qApp->activeWindow() ) { 81 w->topLevelWidget() == qApp->activeWindow() ) {
83 setFocus( w ); 82 setFocus( w );
84 return; 83 return;
85 } 84 }
86 ++it; 85 ++it;
87 } 86 }
88 } else { 87 } else {
89 if ( inFocus ) { 88 if ( inFocus ) {
90 if ( inFocus->inherits( "QMenuBar" ) ) 89 if ( inFocus->inherits( "QMenuBar" ) )
91 ((QMenuBarHack *)(QWidget *)inFocus)->goodbye(); 90 ((QMenuBarHack *)(QWidget *)inFocus)->goodbye();
92 if ( inFocus->hasFocus() ) { 91 if ( inFocus->hasFocus() ) {
93 if ( oldFocus && oldFocus->isVisible() && oldFocus->isEnabled() ) { 92 if ( oldFocus && oldFocus->isVisible() && oldFocus->isEnabled() ) {
94 oldFocus->setFocus(); 93 oldFocus->setFocus();
95 } else { 94 } else {
96 inFocus->clearFocus(); 95 inFocus->clearFocus();
97 } 96 }
98 } 97 }
99 } 98 }
100 inFocus = 0; 99 inFocus = 0;
101 oldFocus = 0; 100 oldFocus = 0;
102 } 101 }
103} 102}
104 103
105bool QPEMenuToolFocusManager::isActive() const 104bool QPEMenuToolFocusManager::isActive() const
106{ 105{
107 return !inFocus.isNull(); 106 return !inFocus.isNull();
108} 107}
109 108
110void QPEMenuToolFocusManager::moveFocus( bool next ) 109void QPEMenuToolFocusManager::moveFocus( bool next )
111{ 110{
112 if ( !isActive() ) 111 if ( !isActive() )
113 return; 112 return;
114 113
115 int n = list.count(); 114 int n = list.count();
116 QValueList<GuardedWidget>::Iterator it; 115 QValueList<GuardedWidget>::Iterator it;
117 it = list.find( inFocus ); 116 it = list.find( inFocus );
118 if ( it == list.end() ) 117 if ( it == list.end() )
119 it = list.begin(); 118 it = list.begin();
120 while ( --n ) { 119 while ( --n ) {
121 if ( next ) { 120 if ( next ) {
122 ++it; 121 ++it;
123 if ( it == list.end() ) 122 if ( it == list.end() )
124 it = list.begin(); 123 it = list.begin();
125 } else { 124 } else {
126 if ( it == list.begin() ) 125 if ( it == list.begin() )
127 it = list.end(); 126 it = list.end();
128 --it; 127 --it;
129 } 128 }
130 QWidget *w = (*it); 129 QWidget *w = (*it);
131 if ( w && w->isEnabled() && w->isVisible() && !w->inherits("QToolBarSeparator") && 130 if ( w && w->isEnabled() && w->isVisible() && !w->inherits("QToolBarSeparator") &&
132 w->topLevelWidget() == qApp->activeWindow() ) { 131 w->topLevelWidget() == qApp->activeWindow() ) {
133 setFocus( w, next ); 132 setFocus( w, next );
134 return; 133 return;
135 } 134 }
136 } 135 }
137} 136}
138 137
139void QPEMenuToolFocusManager::initialize() 138void QPEMenuToolFocusManager::initialize()
140{ 139{
141 if ( !me ) 140 if ( !me )
142 me = new QPEMenuToolFocusManager; 141 me = new QPEMenuToolFocusManager;
143} 142}
144 143
145QPEMenuToolFocusManager *QPEMenuToolFocusManager::manager() 144QPEMenuToolFocusManager *QPEMenuToolFocusManager::manager()
146{ 145{
147 if ( !me ) 146 if ( !me )
148 me = new QPEMenuToolFocusManager; 147 me = new QPEMenuToolFocusManager;
149 148
150 return me; 149 return me;
151} 150}
152 151
153void QPEMenuToolFocusManager::setFocus( QWidget *w, bool next ) 152void QPEMenuToolFocusManager::setFocus( QWidget *w, bool next )
154{ 153{
155 inFocus = w; 154 inFocus = w;
156// qDebug( "Set focus on %s", w->className() ); 155// qDebug( "Set focus on %s", w->className() );
157 if ( inFocus->inherits( "QMenuBar" ) ) { 156 if ( inFocus->inherits( "QMenuBar" ) ) {
158 QMenuBar *mb = (QMenuBar *)(QWidget *)inFocus; 157 QMenuBar *mb = (QMenuBar *)(QWidget *)inFocus;
159 if ( next ) 158 if ( next )
160 mb->activateItemAt( 0 ); 159 mb->activateItemAt( 0 );
161 else 160 else
162 mb->activateItemAt( mb->count()-1 ); 161 mb->activateItemAt( mb->count()-1 );
163 } 162 }
164 inFocus->setFocus(); 163 inFocus->setFocus();
165} 164}
166 165
167bool QPEMenuToolFocusManager::eventFilter( QObject *object, QEvent *event ) 166bool QPEMenuToolFocusManager::eventFilter( QObject *object, QEvent *event )
168{ 167{
169 if ( event->type() == QEvent::KeyPress ) { 168 if ( event->type() == QEvent::KeyPress ) {
170 QKeyEvent *ke = (QKeyEvent *)event; 169 QKeyEvent *ke = (QKeyEvent *)event;
171 if ( isActive() ) { 170 if ( isActive() ) {
172 if ( object->inherits( "QButton" ) ) { 171 if ( object->inherits( "QButton" ) ) {
173 switch ( ke->key() ) { 172 switch ( ke->key() ) {
174 case Key_Left: 173 case Key_Left:
175 moveFocus( FALSE ); 174 moveFocus( FALSE );
176 return TRUE; 175 return TRUE;
177 176
178 case Key_Right: 177 case Key_Right:
179 moveFocus( TRUE ); 178 moveFocus( TRUE );
180 return TRUE; 179 return TRUE;
181 180
182 case Key_Up: 181 case Key_Up:
183 case Key_Down: 182 case Key_Down:
184 return TRUE; 183 return TRUE;
185 } 184 }
186 } else if ( object->inherits( "QPopupMenu" ) ) { 185 } else if ( object->inherits( "QPopupMenu" ) ) {
187 // Deactivate when a menu item is selected 186 // Deactivate when a menu item is selected
188 if ( ke->key() == Key_Enter || ke->key() == Key_Return || 187 if ( ke->key() == Key_Enter || ke->key() == Key_Return ||
189 ke->key() == Key_Escape ) { 188 ke->key() == Key_Escape ) {
190 QTimer::singleShot( 0, this, SLOT(deactivate()) ); 189 QTimer::singleShot( 0, this, SLOT(deactivate()) );
191 } 190 }
192 } else if ( object->inherits( "QMenuBar" ) ) { 191 } else if ( object->inherits( "QMenuBar" ) ) {
193 int dx = 0; 192 int dx = 0;
194 switch ( ke->key() ) { 193 switch ( ke->key() ) {
195 case Key_Left: 194 case Key_Left:
196 dx = -1; 195 dx = -1;
197 break; 196 break;
198 197
199 case Key_Right: 198 case Key_Right:
200 dx = 1; 199 dx = 1;
201 break; 200 break;
202 } 201 }
203 202
204 QMenuBarHack *mb = (QMenuBarHack *)object; 203 QMenuBarHack *mb = (QMenuBarHack *)object;
205 if ( dx && mb->activeItem() >= 0 ) { 204 if ( dx && mb->activeItem() >= 0 ) {
206 int i = mb->activeItem(); 205 int i = mb->activeItem();
207 int c = mb->count(); 206 int c = mb->count();
208 int n = c; 207 int n = c;
209 while ( n-- ) { 208 while ( n-- ) {
210 i = i + dx; 209 i = i + dx;
211 if ( i == c ) { 210 if ( i == c ) {
212 mb->goodbye(); 211 mb->goodbye();
213 moveFocus( TRUE ); 212 moveFocus( TRUE );
214 return TRUE; 213 return TRUE;
215 } else if ( i < 0 ) { 214 } else if ( i < 0 ) {
216 mb->goodbye(); 215 mb->goodbye();
217 moveFocus( FALSE ); 216 moveFocus( FALSE );
diff --git a/library/qpestyle.cpp b/library/qpestyle.cpp
index 665910c..b61ada4 100644
--- a/library/qpestyle.cpp
+++ b/library/qpestyle.cpp
@@ -1,217 +1,214 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 "qpestyle.h" 21#include "qpestyle.h"
22#include <qpe/qpeapplication.h>
23#include <qpushbutton.h>
24 22
25#include <qpainter.h>
26 23
27#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) 24#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
28 25
29#if QT_VERSION >= 300 26#if QT_VERSION >= 300
30 27
31#include <qdrawutil.h> 28#include <qdrawutil.h>
32#include <qcombobox.h> 29#include <qcombobox.h>
33#include <qtabbar.h> 30#include <qtabbar.h>
34 31
35QPEStyle::QPEStyle() 32QPEStyle::QPEStyle()
36{ 33{
37} 34}
38 35
39QPEStyle::~QPEStyle() 36QPEStyle::~QPEStyle()
40{ 37{
41} 38}
42 39
43void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, 40void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r,
44 const QColorGroup &cg, SFlags flags, const QStyleOption &data) const 41 const QColorGroup &cg, SFlags flags, const QStyleOption &data) const
45{ 42{
46 switch ( pe ) { 43 switch ( pe ) {
47 case PE_ButtonTool: 44 case PE_ButtonTool:
48 { 45 {
49 QColorGroup mycg = cg; 46 QColorGroup mycg = cg;
50 if ( flags & Style_On ) { 47 if ( flags & Style_On ) {
51 QBrush fill( cg.mid(), Dense4Pattern ); 48 QBrush fill( cg.mid(), Dense4Pattern );
52 mycg.setBrush( QColorGroup::Button, fill ); 49 mycg.setBrush( QColorGroup::Button, fill );
53 } 50 }
54 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data ); 51 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
55 break; 52 break;
56 } 53 }
57 case PE_ButtonCommand: 54 case PE_ButtonCommand:
58 case PE_ButtonDefault: 55 case PE_ButtonDefault:
59 case PE_ButtonBevel: 56 case PE_ButtonBevel:
60 case PE_HeaderSection: 57 case PE_HeaderSection:
61 { 58 {
62 QPen oldPen = p->pen(); 59 QPen oldPen = p->pen();
63 p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) ); 60 p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) );
64 61
65 int x2 = r.right(); 62 int x2 = r.right();
66 int y2 = r.bottom(); 63 int y2 = r.bottom();
67 64
68 if ( flags & (Style_Sunken | Style_Down | Style_On) ) 65 if ( flags & (Style_Sunken | Style_Down | Style_On) )
69 p->setPen( cg.dark() ); 66 p->setPen( cg.dark() );
70 else 67 else
71 p->setPen( cg.light() ); 68 p->setPen( cg.light() );
72 p->drawLine( r.x(), r.y()+1, r.x(), y2-1 ); 69 p->drawLine( r.x(), r.y()+1, r.x(), y2-1 );
73 p->drawLine( r.x()+1, r.y(), x2-1, r.y() ); 70 p->drawLine( r.x()+1, r.y(), x2-1, r.y() );
74 71
75 if ( flags & (Style_Sunken | Style_Down | Style_On) ) 72 if ( flags & (Style_Sunken | Style_Down | Style_On) )
76 p->setPen( cg.light() ); 73 p->setPen( cg.light() );
77 else 74 else
78 p->setPen( cg.dark() ); 75 p->setPen( cg.dark() );
79 p->drawLine( x2, r.y()+1, x2, y2-1 ); 76 p->drawLine( x2, r.y()+1, x2, y2-1 );
80 p->drawLine( r.x()+1, y2, x2-1, y2 ); 77 p->drawLine( r.x()+1, y2, x2-1, y2 );
81 p->setPen( oldPen ); 78 p->setPen( oldPen );
82 break; 79 break;
83 } 80 }
84 case PE_FocusRect: 81 case PE_FocusRect:
85 break; 82 break;
86 case PE_Indicator: 83 case PE_Indicator:
87 { 84 {
88 QColorGroup mycg( cg ); 85 QColorGroup mycg( cg );
89 QBrush fill; 86 QBrush fill;
90 if ( flags & Style_Down ) 87 if ( flags & Style_Down )
91 fill = cg.brush( QColorGroup::Button ); 88 fill = cg.brush( QColorGroup::Button );
92 else 89 else
93 fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background ); 90 fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background );
94 mycg.setBrush( QColorGroup::Button, fill ); 91 mycg.setBrush( QColorGroup::Button, fill );
95 if ( flags&Style_Enabled ) 92 if ( flags&Style_Enabled )
96 flags |= Style_Sunken; 93 flags |= Style_Sunken;
97 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags ); 94 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags );
98 if ( flags & Style_On ) { 95 if ( flags & Style_On ) {
99 QPointArray a( 7*2 ); 96 QPointArray a( 7*2 );
100 int i, xx, yy; 97 int i, xx, yy;
101 xx = r.x()+3; 98 xx = r.x()+3;
102 yy = r.y()+5; 99 yy = r.y()+5;
103 for ( i=0; i<3; i++ ) { 100 for ( i=0; i<3; i++ ) {
104 a.setPoint( 2*i, xx, yy ); 101 a.setPoint( 2*i, xx, yy );
105 a.setPoint( 2*i+1, xx, yy+2 ); 102 a.setPoint( 2*i+1, xx, yy+2 );
106 xx++; yy++; 103 xx++; yy++;
107 } 104 }
108 yy -= 2; 105 yy -= 2;
109 for ( i=3; i<7; i++ ) { 106 for ( i=3; i<7; i++ ) {
110 a.setPoint( 2*i, xx, yy ); 107 a.setPoint( 2*i, xx, yy );
111 a.setPoint( 2*i+1, xx, yy+2 ); 108 a.setPoint( 2*i+1, xx, yy+2 );
112 xx++; yy--; 109 xx++; yy--;
113 } 110 }
114 if ( flags & Style_NoChange ) { 111 if ( flags & Style_NoChange ) {
115 p->setPen( mycg.dark() ); 112 p->setPen( mycg.dark() );
116 } else { 113 } else {
117 p->setPen( mycg.text() ); 114 p->setPen( mycg.text() );
118 } 115 }
119 p->drawLineSegments( a ); 116 p->drawLineSegments( a );
120 } 117 }
121 break; 118 break;
122 } 119 }
123 case PE_ExclusiveIndicator: 120 case PE_ExclusiveIndicator:
124 { 121 {
125 static const QCOORD pts1[] = { // dark lines 122 static const QCOORD pts1[] = { // dark lines
126 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; 123 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
127 static const QCOORD pts4[] = { // white lines 124 static const QCOORD pts4[] = { // white lines
128 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 125 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
129 11,4, 10,3, 10,2 }; 126 11,4, 10,3, 10,2 };
130 static const QCOORD pts5[] = { // inner fill 127 static const QCOORD pts5[] = { // inner fill
131 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; 128 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
132 129
133 int x, y, w, h; 130 int x, y, w, h;
134 r.rect( &x, &y, &w, &h ); 131 r.rect( &x, &y, &w, &h );
135 p->eraseRect( x, y, w, h ); 132 p->eraseRect( x, y, w, h );
136 QPointArray a( QCOORDARRLEN(pts1), pts1 ); 133 QPointArray a( QCOORDARRLEN(pts1), pts1 );
137 a.translate( x, y ); 134 a.translate( x, y );
138 p->setPen( cg.dark() ); 135 p->setPen( cg.dark() );
139 p->drawPolyline( a ); 136 p->drawPolyline( a );
140 a.setPoints( QCOORDARRLEN(pts4), pts4 ); 137 a.setPoints( QCOORDARRLEN(pts4), pts4 );
141 a.translate( x, y ); 138 a.translate( x, y );
142 p->setPen( cg.light() ); 139 p->setPen( cg.light() );
143 p->drawPolyline( a ); 140 p->drawPolyline( a );
144 a.setPoints( QCOORDARRLEN(pts5), pts5 ); 141 a.setPoints( QCOORDARRLEN(pts5), pts5 );
145 a.translate( x, y ); 142 a.translate( x, y );
146 QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base(); 143 QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base();
147 p->setPen( fillColor ); 144 p->setPen( fillColor );
148 p->setBrush( fillColor ) ; 145 p->setBrush( fillColor ) ;
149 p->drawPolygon( a ); 146 p->drawPolygon( a );
150 if ( flags&Style_On ) { 147 if ( flags&Style_On ) {
151 p->setPen( NoPen ); 148 p->setPen( NoPen );
152 p->setBrush( cg.text() ); 149 p->setBrush( cg.text() );
153 p->drawRect( x+5, y+4, 2, 4 ); 150 p->drawRect( x+5, y+4, 2, 4 );
154 p->drawRect( x+4, y+5, 4, 2 ); 151 p->drawRect( x+4, y+5, 4, 2 );
155 } 152 }
156 break; 153 break;
157 } 154 }
158 default: 155 default:
159 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data ); 156 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data );
160 break; 157 break;
161 } 158 }
162} 159}
163 160
164void QPEStyle::drawControl( ControlElement ce, QPainter *p, 161void QPEStyle::drawControl( ControlElement ce, QPainter *p,
165 const QWidget *widget, const QRect &r, 162 const QWidget *widget, const QRect &r,
166 const QColorGroup &cg, SFlags how, const QStyleOption &data) const 163 const QColorGroup &cg, SFlags how, const QStyleOption &data) const
167{ 164{
168 switch ( ce ) { 165 switch ( ce ) {
169 case CE_PushButton: 166 case CE_PushButton:
170 { 167 {
171 const QPushButton *btn = (QPushButton*)widget; 168 const QPushButton *btn = (QPushButton*)widget;
172 SFlags flags; 169 SFlags flags;
173 flags = Style_Default; 170 flags = Style_Default;
174 if ( btn->isDown() ) 171 if ( btn->isDown() )
175 flags |= Style_Down; 172 flags |= Style_Down;
176 if ( btn->isOn() ) 173 if ( btn->isOn() )
177 flags |= Style_On; 174 flags |= Style_On;
178 if ( btn->isEnabled() ) 175 if ( btn->isEnabled() )
179 flags |= Style_Enabled; 176 flags |= Style_Enabled;
180 if ( btn->isDefault() ) 177 if ( btn->isDefault() )
181 flags |= Style_Default; 178 flags |= Style_Default;
182 if (! btn->isFlat() && !(flags & Style_Down)) 179 if (! btn->isFlat() && !(flags & Style_Down))
183 flags |= Style_Raised; 180 flags |= Style_Raised;
184 p->setPen( cg.foreground() ); 181 p->setPen( cg.foreground() );
185 p->setBrush( QBrush(cg.button(), NoBrush) ); 182 p->setBrush( QBrush(cg.button(), NoBrush) );
186 QColorGroup mycg( cg ); 183 QColorGroup mycg( cg );
187 if ( flags & Style_On ) { 184 if ( flags & Style_On ) {
188 QBrush fill = QBrush( cg.mid(), Dense4Pattern ); 185 QBrush fill = QBrush( cg.mid(), Dense4Pattern );
189 mycg.setBrush( QColorGroup::Button, fill ); 186 mycg.setBrush( QColorGroup::Button, fill );
190 } 187 }
191 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data ); 188 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
192 break; 189 break;
193 } 190 }
194 case CE_TabBarTab: 191 case CE_TabBarTab:
195 { 192 {
196 if ( !widget || !widget->parentWidget() ) 193 if ( !widget || !widget->parentWidget() )
197 break; 194 break;
198 195
199 const QTabBar *tb = (const QTabBar *) widget; 196 const QTabBar *tb = (const QTabBar *) widget;
200 bool selected = how & Style_Selected; 197 bool selected = how & Style_Selected;
201 198
202 QRect r2(r); 199 QRect r2(r);
203 if ( tb->shape() == QTabBar::RoundedAbove ) { 200 if ( tb->shape() == QTabBar::RoundedAbove ) {
204 p->setPen( cg.light() ); 201 p->setPen( cg.light() );
205 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); 202 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
206 if ( r2.left() == 0 ) 203 if ( r2.left() == 0 )
207 p->drawPoint( tb->rect().bottomLeft() ); 204 p->drawPoint( tb->rect().bottomLeft() );
208 else { 205 else {
209 p->setPen( cg.light() ); 206 p->setPen( cg.light() );
210 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); 207 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
211 } 208 }
212 209
213 if ( selected ) { 210 if ( selected ) {
214 p->setPen( cg.background() ); 211 p->setPen( cg.background() );
215 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 ); 212 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
216 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2), 213 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2),
217 cg.brush( QColorGroup::Background )); 214 cg.brush( QColorGroup::Background ));
diff --git a/library/qpetoolbar.cpp b/library/qpetoolbar.cpp
index 7f95eda..bd2c9b7 100644
--- a/library/qpetoolbar.cpp
+++ b/library/qpetoolbar.cpp
@@ -1,52 +1,50 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 "qpetoolbar.h" 21#include "qpetoolbar.h"
22#include "qpemenubar.h"
23#include <qtoolbutton.h>
24 22
25/*! 23/*!
26 \class QPEToolBar qpemenubar.h 24 \class QPEToolBar qpemenubar.h
27 \brief The QPEToolBar class is obsolete. Use QToolBar instead. 25 \brief The QPEToolBar class is obsolete. Use QToolBar instead.
28 26
29 \obsolete 27 \obsolete
30 28
31 The QPEToolBar class is obsolete. Use QToolBar instead. 29 The QPEToolBar class is obsolete. Use QToolBar instead.
32 30
33 \sa QToolBar 31 \sa QToolBar
34 */ 32 */
35 33
36/*! 34/*!
37 Constructs a QPEToolBar just as you would construct 35 Constructs a QPEToolBar just as you would construct
38 a QToolBar, passing \a parent and \a name. 36 a QToolBar, passing \a parent and \a name.
39 */ 37 */
40QPEToolBar::QPEToolBar( QMainWindow *parent, const char *name ) 38QPEToolBar::QPEToolBar( QMainWindow *parent, const char *name )
41 : QToolBar( parent, name ) 39 : QToolBar( parent, name )
42{ 40{
43} 41}
44 42
45/*! 43/*!
46 \internal 44 \internal
47*/ 45*/
48void QPEToolBar::childEvent( QChildEvent *e ) 46void QPEToolBar::childEvent( QChildEvent *e )
49{ 47{
50 QToolBar::childEvent( e ); 48 QToolBar::childEvent( e );
51} 49}
52 50
diff --git a/library/qt_override.cpp b/library/qt_override.cpp
index df5a419..4d1f475 100644
--- a/library/qt_override.cpp
+++ b/library/qt_override.cpp
@@ -1,177 +1,175 @@
1 1
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qwsdecoration_qws.h>
4#include <qcommonstyle.h>
5#include <qfontdatabase.h> 3#include <qfontdatabase.h>
6 4
7#include <unistd.h> 5#include <unistd.h>
8#include <stdlib.h> 6#include <stdlib.h>
9#include <stdio.h> 7#include <stdio.h>
10#include <limits.h> 8#include <limits.h>
11#include <sys/param.h> // for toolchains with old libc headers 9#include <sys/param.h> // for toolchains with old libc headers
12 10
13#include "qt_override_p.h" 11#include "qt_override_p.h"
14 12
15#if QT_VERSION > 233 13#if QT_VERSION > 233
16 14
17struct color_fix_t { 15struct color_fix_t {
18 char *m_app; 16 char *m_app;
19 char *m_class; 17 char *m_class;
20 char *m_name; 18 char *m_name;
21 QColorGroup::ColorRole m_set; 19 QColorGroup::ColorRole m_set;
22 QColorGroup::ColorRole m_get; 20 QColorGroup::ColorRole m_get;
23}; 21};
24 22
25#ifndef OPIE_NO_OVERRIDE_QT 23#ifndef OPIE_NO_OVERRIDE_QT
26 24
27static const color_fix_t apps_that_need_special_colors [] = { 25static const color_fix_t apps_that_need_special_colors [] = {
28 { "HancomMobileWord", "HTextEdit", 0, QColorGroup::Background, QColorGroup::Base }, 26 { "HancomMobileWord", "HTextEdit", 0, QColorGroup::Background, QColorGroup::Base },
29 { "neocal", "Display", 0, QColorGroup::Background, QColorGroup::Base }, 27 { "neocal", "Display", 0, QColorGroup::Background, QColorGroup::Base },
30 28
31 { 0, 0, 0, QColorGroup::Base, QColorGroup::Base } 29 { 0, 0, 0, QColorGroup::Base, QColorGroup::Base }
32}; 30};
33 31
34static const char * const apps_that_need_pointsizes_times_10 [] = { 32static const char * const apps_that_need_pointsizes_times_10 [] = {
35 "HancomMobileWord", 33 "HancomMobileWord",
36 "hancomsheet", 34 "hancomsheet",
37 "HancomPresenterViewer", 35 "HancomPresenterViewer",
38 36
39 0 37 0
40}; 38};
41 39
42 40
43 41
44 42
45int Opie::force_appearance = 0; 43int Opie::force_appearance = 0;
46 44
47 45
48// Return the *real* name of the binary - not just a quick guess 46// Return the *real* name of the binary - not just a quick guess
49// by looking at argv [0] (which could be anything) 47// by looking at argv [0] (which could be anything)
50 48
51static void binaryNameFree ( ) 49static void binaryNameFree ( )
52{ 50{
53 ::free ((void *) Opie::binaryName ( )); // we need to cast away the const here 51 ::free ((void *) Opie::binaryName ( )); // we need to cast away the const here
54} 52}
55 53
56const char *Opie::binaryName ( ) 54const char *Opie::binaryName ( )
57{ 55{
58 static const char *appname = 0; 56 static const char *appname = 0;
59 57
60 if ( !appname ) { 58 if ( !appname ) {
61 char dst [PATH_MAX + 1]; 59 char dst [PATH_MAX + 1];
62 int l = ::readlink ( "/proc/self/exe", dst, PATH_MAX ); 60 int l = ::readlink ( "/proc/self/exe", dst, PATH_MAX );
63 61
64 if ( l <= 0 ) 62 if ( l <= 0 )
65 l = 0; 63 l = 0;
66 64
67 dst [l] = 0; 65 dst [l] = 0;
68 const char *b = ::strrchr ( dst, '/' ); 66 const char *b = ::strrchr ( dst, '/' );
69 appname = ::strdup ( b ? b + 1 : dst ); 67 appname = ::strdup ( b ? b + 1 : dst );
70 68
71 ::atexit ( binaryNameFree ); 69 ::atexit ( binaryNameFree );
72 } 70 }
73 return appname; 71 return appname;
74} 72}
75 73
76#else 74#else
77int Opie::force_appearance = 0; 75int Opie::force_appearance = 0;
78#endif 76#endif
79 77
80// Fix for a toolchain incompatibility (binaries compiled with 78// Fix for a toolchain incompatibility (binaries compiled with
81// old tcs using shared libs compiled with newer tcs) 79// old tcs using shared libs compiled with newer tcs)
82 80
83extern "C" { 81extern "C" {
84 82
85extern void __gmon_start__ ( ) __attribute__(( weak )); 83extern void __gmon_start__ ( ) __attribute__(( weak ));
86 84
87extern void __gmon_start__ ( ) 85extern void __gmon_start__ ( )
88{ 86{
89} 87}
90 88
91} 89}
92 90
93 91
94// Fix for apps, that use QPainter::eraseRect() which doesn't work with styles 92// Fix for apps, that use QPainter::eraseRect() which doesn't work with styles
95// that set a background pixmap (it would be easier to fix eraseRect(), but 93// that set a background pixmap (it would be easier to fix eraseRect(), but
96// TT made it an inline ...) 94// TT made it an inline ...)
97 95
98void QPEApplication::polish ( QWidget *w ) 96void QPEApplication::polish ( QWidget *w )
99{ 97{
100#ifndef OPIE_NO_OVERRIDE_QT 98#ifndef OPIE_NO_OVERRIDE_QT
101 //qDebug ( "QPEApplication::polish()" ); 99 //qDebug ( "QPEApplication::polish()" );
102 100
103 for ( const color_fix_t *ptr = apps_that_need_special_colors; ptr-> m_app; ptr++ ) { 101 for ( const color_fix_t *ptr = apps_that_need_special_colors; ptr-> m_app; ptr++ ) {
104 if (( ::strcmp ( Opie::binaryName ( ), ptr-> m_app ) == 0 ) && 102 if (( ::strcmp ( Opie::binaryName ( ), ptr-> m_app ) == 0 ) &&
105 ( ptr-> m_class ? w-> inherits ( ptr-> m_class ) : true ) && 103 ( ptr-> m_class ? w-> inherits ( ptr-> m_class ) : true ) &&
106 ( ptr-> m_name ? ( ::strcmp ( w-> name ( ), ptr-> m_name ) == 0 ) : true )) { 104 ( ptr-> m_name ? ( ::strcmp ( w-> name ( ), ptr-> m_name ) == 0 ) : true )) {
107 QPalette pal = w-> palette ( ); 105 QPalette pal = w-> palette ( );
108 pal. setColor ( ptr-> m_set, pal. color ( QPalette::Active, ptr-> m_get )); 106 pal. setColor ( ptr-> m_set, pal. color ( QPalette::Active, ptr-> m_get ));
109 w-> setPalette ( pal ); 107 w-> setPalette ( pal );
110 } 108 }
111 } 109 }
112#endif 110#endif
113 QApplication::polish ( w ); 111 QApplication::polish ( w );
114} 112}
115 113
116 114
117#ifndef OPIE_NO_OVERRIDE_QT 115#ifndef OPIE_NO_OVERRIDE_QT
118// Fix for the binary incompatibility that TT introduced in Qt/E 2.3.4 -- point sizes 116// Fix for the binary incompatibility that TT introduced in Qt/E 2.3.4 -- point sizes
119// were multiplied by 10 (which was incorrect) 117// were multiplied by 10 (which was incorrect)
120 118
121QValueList <int> QFontDatabase::pointSizes ( QString const &family, QString const &style, QString const &charset ) 119QValueList <int> QFontDatabase::pointSizes ( QString const &family, QString const &style, QString const &charset )
122{ 120{
123 //qDebug ( "QFontDatabase::pointSizes()" ); 121 //qDebug ( "QFontDatabase::pointSizes()" );
124 122
125 QValueList <int> sl = pointSizes_NonWeak ( family, style, charset ); 123 QValueList <int> sl = pointSizes_NonWeak ( family, style, charset );
126 124
127 for ( const char * const *ptr = apps_that_need_pointsizes_times_10; *ptr; ptr++ ) { 125 for ( const char * const *ptr = apps_that_need_pointsizes_times_10; *ptr; ptr++ ) {
128 if ( ::strcmp ( Opie::binaryName ( ), *ptr ) == 0 ) { 126 if ( ::strcmp ( Opie::binaryName ( ), *ptr ) == 0 ) {
129 for ( QValueList <int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 127 for ( QValueList <int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
130 *it *= 10; 128 *it *= 10;
131 } 129 }
132 } 130 }
133 return sl; 131 return sl;
134} 132}
135 133
136 134
137// Various style/font/color related overrides for weak symbols in Qt/E, 135// Various style/font/color related overrides for weak symbols in Qt/E,
138// which allows us to force the usage of the global Opie appearance. 136// which allows us to force the usage of the global Opie appearance.
139 137
140void QApplication::setStyle ( QStyle *style ) 138void QApplication::setStyle ( QStyle *style )
141{ 139{
142 //qDebug ( "QApplication::setStyle()" ); 140 //qDebug ( "QApplication::setStyle()" );
143 141
144 if ( Opie::force_appearance & Opie::Force_Style ) 142 if ( Opie::force_appearance & Opie::Force_Style )
145 delete style; 143 delete style;
146 else 144 else
147 QApplication::setStyle_NonWeak ( style ); 145 QApplication::setStyle_NonWeak ( style );
148} 146}
149 147
150void QApplication::setPalette ( const QPalette &pal, bool informWidgets, const char *className ) 148void QApplication::setPalette ( const QPalette &pal, bool informWidgets, const char *className )
151{ 149{
152 //qDebug ( "QApplication::setPalette()" ); 150 //qDebug ( "QApplication::setPalette()" );
153 151
154 if (!( Opie::force_appearance & Opie::Force_Style )) 152 if (!( Opie::force_appearance & Opie::Force_Style ))
155 QApplication::setPalette_NonWeak ( pal, informWidgets, className ); 153 QApplication::setPalette_NonWeak ( pal, informWidgets, className );
156} 154}
157 155
158void QApplication::setFont ( const QFont &fnt, bool informWidgets, const char *className ) 156void QApplication::setFont ( const QFont &fnt, bool informWidgets, const char *className )
159{ 157{
160 //qDebug ( "QApplication::setFont()" ); 158 //qDebug ( "QApplication::setFont()" );
161 159
162 if (!( Opie::force_appearance & Opie::Force_Font )) 160 if (!( Opie::force_appearance & Opie::Force_Font ))
163 QApplication::setFont_NonWeak ( fnt, informWidgets, className ); 161 QApplication::setFont_NonWeak ( fnt, informWidgets, className );
164} 162}
165 163
166 164
167void QApplication::qwsSetDecoration ( QWSDecoration *deco ) 165void QApplication::qwsSetDecoration ( QWSDecoration *deco )
168{ 166{
169 //qDebug ( "QApplication::qwsSetDecoration()" ); 167 //qDebug ( "QApplication::qwsSetDecoration()" );
170 168
171 if ( Opie::force_appearance & Opie::Force_Decoration ) 169 if ( Opie::force_appearance & Opie::Force_Decoration )
172 delete deco; 170 delete deco;
173 else 171 else
174 QApplication::qwsSetDecoration_NonWeak ( deco ); 172 QApplication::qwsSetDecoration_NonWeak ( deco );
175} 173}
176#endif 174#endif
177#endif 175#endif
diff --git a/library/resource.cpp b/library/resource.cpp
index f70658d..cfa0d26 100644
--- a/library/resource.cpp
+++ b/library/resource.cpp
@@ -1,221 +1,218 @@
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#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
23#include "resource.h" 23#include "resource.h"
24#include "mimetype.h" 24#include "mimetype.h"
25#include <qdir.h> 25#include <qdir.h>
26#include <qfile.h>
27#include <qregexp.h>
28#include <qpixmapcache.h> 26#include <qpixmapcache.h>
29#include <qpainter.h>
30 27
31// this namespace is just a workaround for a gcc bug 28// this namespace is just a workaround for a gcc bug
32// gcc exports inline functions in the generated file 29// gcc exports inline functions in the generated file
33// inlinepics_p.h 30// inlinepics_p.h
34 31
35namespace { 32namespace {
36#include "inlinepics_p.h" 33#include "inlinepics_p.h"
37} 34}
38 35
39static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); 36static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET");
40 37
41/*! 38/*!
42 \class Resource resource.h 39 \class Resource resource.h
43 \brief The Resource class provides access to named resources. 40 \brief The Resource class provides access to named resources.
44 41
45 The resources may be provided from files or other sources. 42 The resources may be provided from files or other sources.
46 43
47 The allSounds() function returns a list of all the sounds available. 44 The allSounds() function returns a list of all the sounds available.
48 A particular sound can be searched for using findSound(). 45 A particular sound can be searched for using findSound().
49 46
50 Images can be loaded with loadImage(), loadPixmap(), loadBitmap() 47 Images can be loaded with loadImage(), loadPixmap(), loadBitmap()
51 and loadIconSet(). 48 and loadIconSet().
52 49
53 \ingroup qtopiaemb 50 \ingroup qtopiaemb
54*/ 51*/
55 52
56/*! 53/*!
57 \fn Resource::Resource() 54 \fn Resource::Resource()
58 \internal 55 \internal
59*/ 56*/
60 57
61/*! 58/*!
62 Returns the QPixmap called \a pix. You should avoid including 59 Returns the QPixmap called \a pix. You should avoid including
63 any filename type extension (e.g. .png, .xpm). 60 any filename type extension (e.g. .png, .xpm).
64*/ 61*/
65QPixmap Resource::loadPixmap( const QString &pix ) 62QPixmap Resource::loadPixmap( const QString &pix )
66{ 63{
67 QPixmap pm; 64 QPixmap pm;
68 QString key="QPE_"+pix; 65 QString key="QPE_"+pix;
69 if ( !QPixmapCache::find(key,pm) ) { 66 if ( !QPixmapCache::find(key,pm) ) {
70 pm.convertFromImage(loadImage(pix)); 67 pm.convertFromImage(loadImage(pix));
71 QPixmapCache::insert(key,pm); 68 QPixmapCache::insert(key,pm);
72 } 69 }
73 return pm; 70 return pm;
74} 71}
75 72
76/*! 73/*!
77 Returns the QBitmap called \a pix. You should avoid including 74 Returns the QBitmap called \a pix. You should avoid including
78 any filename type extension (e.g. .png, .xpm). 75 any filename type extension (e.g. .png, .xpm).
79*/ 76*/
80QBitmap Resource::loadBitmap( const QString &pix ) 77QBitmap Resource::loadBitmap( const QString &pix )
81{ 78{
82 QBitmap bm; 79 QBitmap bm;
83 bm = loadPixmap(pix); 80 bm = loadPixmap(pix);
84 return bm; 81 return bm;
85} 82}
86 83
87/*! 84/*!
88 Returns the filename of a pixmap called \a pix. You should avoid including 85 Returns the filename of a pixmap called \a pix. You should avoid including
89 any filename type extension (e.g. .png, .xpm). 86 any filename type extension (e.g. .png, .xpm).
90 87
91 Normally you will use loadPixmap() rather than this function. 88 Normally you will use loadPixmap() rather than this function.
92*/ 89*/
93QString Resource::findPixmap( const QString &pix ) 90QString Resource::findPixmap( const QString &pix )
94{ 91{
95 QString picsPath = QPEApplication::qpeDir() + "pics/"; 92 QString picsPath = QPEApplication::qpeDir() + "pics/";
96 93
97 QString f; 94 QString f;
98 95
99 // Common case optimizations... 96 // Common case optimizations...
100 f = picsPath + pix + ".png"; 97 f = picsPath + pix + ".png";
101 if ( QFile( f ).exists() ) 98 if ( QFile( f ).exists() )
102 return f; 99 return f;
103 f = picsPath + pix + ".xpm"; 100 f = picsPath + pix + ".xpm";
104 if ( QFile( f ).exists() ) 101 if ( QFile( f ).exists() )
105 return f; 102 return f;
106 103
107 104
108 // All formats... 105 // All formats...
109 QStrList fileFormats = QImageIO::inputFormats(); 106 QStrList fileFormats = QImageIO::inputFormats();
110 QString ff = fileFormats.first(); 107 QString ff = fileFormats.first();
111 while ( fileFormats.current() ) { 108 while ( fileFormats.current() ) {
112 QStringList exts = MimeType("image/"+ff.lower()).extensions(); 109 QStringList exts = MimeType("image/"+ff.lower()).extensions();
113 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { 110 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) {
114 QString f = picsPath + pix + "." + *it; 111 QString f = picsPath + pix + "." + *it;
115 if ( QFile(f).exists() ) 112 if ( QFile(f).exists() )
116 return f; 113 return f;
117 } 114 }
118 ff = fileFormats.next(); 115 ff = fileFormats.next();
119 } 116 }
120 117
121 // Finally, no (or existing) extension... 118 // Finally, no (or existing) extension...
122 if ( QFile( picsPath + pix ).exists() ) 119 if ( QFile( picsPath + pix ).exists() )
123 return picsPath + pix; 120 return picsPath + pix;
124 121
125 //qDebug("Cannot find pixmap: %s", pix.latin1()); 122 //qDebug("Cannot find pixmap: %s", pix.latin1());
126 return QString(); 123 return QString();
127} 124}
128 125
129/*! 126/*!
130 Returns a sound file for a sound called \a name. 127 Returns a sound file for a sound called \a name.
131 128
132 You should avoid including any filename type extension (e.g. .wav), 129 You should avoid including any filename type extension (e.g. .wav),
133 as the system will search for only those fileformats which are supported 130 as the system will search for only those fileformats which are supported
134 by the library. 131 by the library.
135 132
136 Currently, only WAV files are supported. 133 Currently, only WAV files are supported.
137*/ 134*/
138QString Resource::findSound( const QString &name ) 135QString Resource::findSound( const QString &name )
139{ 136{
140 QString picsPath = QPEApplication::qpeDir() + "sounds/"; 137 QString picsPath = QPEApplication::qpeDir() + "sounds/";
141 138
142 QString result; 139 QString result;
143 if ( QFile( (result = picsPath + name + ".wav") ).exists() ) 140 if ( QFile( (result = picsPath + name + ".wav") ).exists() )
144 return result; 141 return result;
145 142
146 return QString(); 143 return QString();
147} 144}
148 145
149/*! 146/*!
150 Returns a list of all sound names. 147 Returns a list of all sound names.
151*/ 148*/
152QStringList Resource::allSounds() 149QStringList Resource::allSounds()
153{ 150{
154 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); 151 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" );
155 QStringList entries = resourcedir.entryList(); 152 QStringList entries = resourcedir.entryList();
156 QStringList result; 153 QStringList result;
157 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) 154 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i)
158 result.append((*i).replace(QRegExp("\\.wav"),"")); 155 result.append((*i).replace(QRegExp("\\.wav"),""));
159 return result; 156 return result;
160} 157}
161 158
162static QImage load_image(const QString &name) 159static QImage load_image(const QString &name)
163{ 160{
164 if (g_notUseSet ) { 161 if (g_notUseSet ) {
165 // try file 162 // try file
166 QImage img; 163 QImage img;
167 QString f = Resource::findPixmap(name); 164 QString f = Resource::findPixmap(name);
168 if ( !f.isEmpty() ) 165 if ( !f.isEmpty() )
169 img.load(f); 166 img.load(f);
170 if (img.isNull() ) 167 if (img.isNull() )
171 img = qembed_findImage(name.latin1() ); 168 img = qembed_findImage(name.latin1() );
172 return img; 169 return img;
173 } 170 }
174 else{ 171 else{
175 QImage img = qembed_findImage(name.latin1()); 172 QImage img = qembed_findImage(name.latin1());
176 173
177 if ( img.isNull() ) { 174 if ( img.isNull() ) {
178 // No inlined image, try file 175 // No inlined image, try file
179 QString f = Resource::findPixmap(name); 176 QString f = Resource::findPixmap(name);
180 if ( !f.isEmpty() ) 177 if ( !f.isEmpty() )
181 img.load(f); 178 img.load(f);
182 } 179 }
183 return img; 180 return img;
184 } 181 }
185} 182}
186 183
187/*! 184/*!
188 Returns the QImage called \a name. You should avoid including 185 Returns the QImage called \a name. You should avoid including
189 any filename type extension (e.g. .png, .xpm). 186 any filename type extension (e.g. .png, .xpm).
190*/ 187*/
191QImage Resource::loadImage( const QString &name) 188QImage Resource::loadImage( const QString &name)
192{ 189{
193 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps 190 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps
194 static QImage last_enabled; 191 static QImage last_enabled;
195 static QString last_enabled_name; 192 static QString last_enabled_name;
196 if ( name == last_enabled_name ) 193 if ( name == last_enabled_name )
197 return last_enabled; 194 return last_enabled;
198#endif 195#endif
199 QImage img = load_image(name); 196 QImage img = load_image(name);
200 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps 197 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps
201 if ( img.isNull() ) { 198 if ( img.isNull() ) {
202 // No file, try generating 199 // No file, try generating
203 if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { 200 if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) {
204 last_enabled_name = name.left(name.length()-9); 201 last_enabled_name = name.left(name.length()-9);
205 last_enabled = load_image(last_enabled_name); 202 last_enabled = load_image(last_enabled_name);
206 if ( last_enabled.isNull() ) { 203 if ( last_enabled.isNull() ) {
207 last_enabled_name = QString::null; 204 last_enabled_name = QString::null;
208 } else { 205 } else {
209 img.detach(); 206 img.detach();
210 img.create( last_enabled.width(), last_enabled.height(), 32 ); 207 img.create( last_enabled.width(), last_enabled.height(), 32 );
211 for ( int y = 0; y < img.height(); y++ ) { 208 for ( int y = 0; y < img.height(); y++ ) {
212 for ( int x = 0; x < img.width(); x++ ) { 209 for ( int x = 0; x < img.width(); x++ ) {
213 QRgb p = last_enabled.pixel( x, y ); 210 QRgb p = last_enabled.pixel( x, y );
214 int a = qAlpha(p)/3; 211 int a = qAlpha(p)/3;
215 int g = qGray(qRed(p),qGreen(p),qBlue(p)); 212 int g = qGray(qRed(p),qGreen(p),qBlue(p));
216 img.setPixel( x, y, qRgba(g,g,g,a) ); 213 img.setPixel( x, y, qRgba(g,g,g,a) );
217 } 214 }
218 } 215 }
219 img.setAlphaBuffer( TRUE ); 216 img.setAlphaBuffer( TRUE );
220 } 217 }
221 } 218 }
diff --git a/library/sound.cpp b/library/sound.cpp
index 5b67995..ee2aabc 100644
--- a/library/sound.cpp
+++ b/library/sound.cpp
@@ -1,224 +1,222 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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/resource.h> 21#include <qpe/resource.h>
22#include <qpe/sound.h> 22#include <qpe/sound.h>
23#include <qpe/qcopenvelope_qws.h> 23#include <qpe/qcopenvelope_qws.h>
24 24
25#include <qsound.h> 25#include <qsound.h>
26#include <qfile.h> 26#include <qfile.h>
27 27
28#include <unistd.h> 28#include <unistd.h>
29#include <fcntl.h> 29#include <fcntl.h>
30#include <sys/ioctl.h> 30#include <sys/ioctl.h>
31 31
32#ifndef QT_NO_SOUND 32#ifndef QT_NO_SOUND
33#include <sys/soundcard.h> 33#include <sys/soundcard.h>
34#endif 34#endif
35 35
36#include "config.h"
37#include <qmessagebox.h>
38#ifndef QT_NO_SOUND 36#ifndef QT_NO_SOUND
39static int WAVsoundDuration(const QString& filename) 37static int WAVsoundDuration(const QString& filename)
40{ 38{
41 // bad solution 39 // bad solution
42 40
43 // most of this is copied from qsoundqss.cpp 41 // most of this is copied from qsoundqss.cpp
44 42
45 QFile input(filename); 43 QFile input(filename);
46 if ( !input.open(IO_ReadOnly) ) 44 if ( !input.open(IO_ReadOnly) )
47 return 0; 45 return 0;
48 46
49 struct QRiffChunk { 47 struct QRiffChunk {
50 char id[4]; 48 char id[4];
51 Q_UINT32 size; 49 Q_UINT32 size;
52 char data[4/*size*/]; 50 char data[4/*size*/];
53 } chunk; 51 } chunk;
54 52
55 struct { 53 struct {
56 Q_INT16 formatTag; 54 Q_INT16 formatTag;
57 Q_INT16 channels; 55 Q_INT16 channels;
58 Q_INT32 samplesPerSec; 56 Q_INT32 samplesPerSec;
59 Q_INT32 avgBytesPerSec; 57 Q_INT32 avgBytesPerSec;
60 Q_INT16 blockAlign; 58 Q_INT16 blockAlign;
61 Q_INT16 wBitsPerSample; 59 Q_INT16 wBitsPerSample;
62 } chunkdata; 60 } chunkdata;
63 61
64 int total = 0; 62 int total = 0;
65 63
66 while(1) { 64 while(1) {
67 // Keep reading chunks... 65 // Keep reading chunks...
68 const int n = sizeof(chunk)-sizeof(chunk.data); 66 const int n = sizeof(chunk)-sizeof(chunk.data);
69 if ( input.readBlock((char*)&chunk,n) != n ) 67 if ( input.readBlock((char*)&chunk,n) != n )
70 break; 68 break;
71 if ( qstrncmp(chunk.id,"data",4) == 0 ) { 69 if ( qstrncmp(chunk.id,"data",4) == 0 ) {
72 total += chunkdata.avgBytesPerSec ? 70 total += chunkdata.avgBytesPerSec ?
73 chunk.size * 1000 / chunkdata.avgBytesPerSec : 0; 71 chunk.size * 1000 / chunkdata.avgBytesPerSec : 0;
74//qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0); 72//qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0);
75 input.at(input.at()+chunk.size-4); 73 input.at(input.at()+chunk.size-4);
76 } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { 74 } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) {
77 char d[4]; 75 char d[4];
78 if ( input.readBlock(d,4) != 4 ) 76 if ( input.readBlock(d,4) != 4 )
79 return 0; 77 return 0;
80 if ( qstrncmp(d,"WAVE",4) != 0 ) { 78 if ( qstrncmp(d,"WAVE",4) != 0 ) {
81 // skip 79 // skip
82//qDebug("skip %.4s RIFF chunk",d); 80//qDebug("skip %.4s RIFF chunk",d);
83 if ( chunk.size < 10000000 ) 81 if ( chunk.size < 10000000 )
84 (void)input.at(input.at()+chunk.size-4); 82 (void)input.at(input.at()+chunk.size-4);
85 } 83 }
86 } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { 84 } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) {
87 if ( input.readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) 85 if ( input.readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) )
88 return 0; 86 return 0;
89#define WAVE_FORMAT_PCM 1 87#define WAVE_FORMAT_PCM 1
90 if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { 88 if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) {
91 //qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); 89 //qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag);
92 return 0; 90 return 0;
93 } 91 }
94 } else { 92 } else {
95//qDebug("skip %.4s chunk",chunk.id); 93//qDebug("skip %.4s chunk",chunk.id);
96 // ignored chunk 94 // ignored chunk
97 if ( chunk.size < 10000000 ) 95 if ( chunk.size < 10000000 )
98 (void)input.at(input.at()+chunk.size); 96 (void)input.at(input.at()+chunk.size);
99 } 97 }
100 } 98 }
101 99
102//qDebug("%dms",total); 100//qDebug("%dms",total);
103 return total; 101 return total;
104} 102}
105 103
106class SoundData : public QSound { 104class SoundData : public QSound {
107public: 105public:
108 SoundData ( const QString& name ) : 106 SoundData ( const QString& name ) :
109 QSound ( Resource::findSound ( name )), 107 QSound ( Resource::findSound ( name )),
110 filename ( Resource::findSound ( name )) 108 filename ( Resource::findSound ( name ))
111 { 109 {
112 loopsleft=0; 110 loopsleft=0;
113 ms = WAVsoundDuration(filename); 111 ms = WAVsoundDuration(filename);
114 } 112 }
115 113
116 void playLoop ( int loopcnt = -1 ) 114 void playLoop ( int loopcnt = -1 )
117 { 115 {
118 // needs server support 116 // needs server support
119 loopsleft = loopcnt; 117 loopsleft = loopcnt;
120 118
121 if ( ms ) 119 if ( ms )
122 startTimer ( ms > 50 ? ms-50 : 0 ); // 50 for latency 120 startTimer ( ms > 50 ? ms-50 : 0 ); // 50 for latency
123 play ( ); 121 play ( );
124 } 122 }
125 123
126 void timerEvent ( QTimerEvent *e ) 124 void timerEvent ( QTimerEvent *e )
127 { 125 {
128 if ( loopsleft >= 0 ) { 126 if ( loopsleft >= 0 ) {
129 if ( --loopsleft <= 0 ) { 127 if ( --loopsleft <= 0 ) {
130 killTimer ( e-> timerId ( )); 128 killTimer ( e-> timerId ( ));
131 loopsleft = 0; 129 loopsleft = 0;
132 return; 130 return;
133 } 131 }
134 } 132 }
135 play(); 133 play();
136 } 134 }
137 135
138 bool isFinished ( ) const 136 bool isFinished ( ) const
139 { 137 {
140 return ( loopsleft == 0 ); 138 return ( loopsleft == 0 );
141 } 139 }
142 140
143private: 141private:
144 QString filename; 142 QString filename;
145 int loopsleft; 143 int loopsleft;
146 int ms; 144 int ms;
147}; 145};
148 146
149#endif 147#endif
150 148
151/*! Opens a wave sound file \a name for playing 149/*! Opens a wave sound file \a name for playing
152 * Resource is used for finding the file 150 * Resource is used for finding the file
153 **/ 151 **/
154Sound::Sound(const QString& name) 152Sound::Sound(const QString& name)
155{ 153{
156#ifndef QT_NO_SOUND 154#ifndef QT_NO_SOUND
157 d = new SoundData(name); 155 d = new SoundData(name);
158#endif 156#endif
159} 157}
160 158
161/*! Destroys the sound */ 159/*! Destroys the sound */
162Sound::~Sound() 160Sound::~Sound()
163{ 161{
164#ifndef QT_NO_SOUND 162#ifndef QT_NO_SOUND
165 delete d; 163 delete d;
166#endif 164#endif
167} 165}
168 166
169/*! Play the sound once */ 167/*! Play the sound once */
170void Sound::play() 168void Sound::play()
171{ 169{
172#ifndef QT_NO_SOUND 170#ifndef QT_NO_SOUND
173 d->playLoop(1); 171 d->playLoop(1);
174#endif 172#endif
175} 173}
176 174
177/*! Play the sound, repeatedly until stop() is called */ 175/*! Play the sound, repeatedly until stop() is called */
178void Sound::playLoop() 176void Sound::playLoop()
179{ 177{
180#ifndef QT_NO_SOUND 178#ifndef QT_NO_SOUND
181 d->killTimers(); 179 d->killTimers();
182 d->playLoop(); 180 d->playLoop();
183#endif 181#endif
184} 182}
185 183
186/*! Do not repeat the sound after it finishes. This will end a playLoop() */ 184/*! Do not repeat the sound after it finishes. This will end a playLoop() */
187void Sound::stop() 185void Sound::stop()
188{ 186{
189#ifndef QT_NO_SOUND 187#ifndef QT_NO_SOUND
190 d->killTimers(); 188 d->killTimers();
191#endif 189#endif
192} 190}
193 191
194bool Sound::isFinished() const 192bool Sound::isFinished() const
195{ 193{
196#ifndef QT_NO_SOUND 194#ifndef QT_NO_SOUND
197 return d->isFinished(); 195 return d->isFinished();
198#else 196#else
199 return true; 197 return true;
200#endif 198#endif
201} 199}
202 200
203/*! Sounds the audible system alarm. This is used for applications such 201/*! Sounds the audible system alarm. This is used for applications such
204 as Calendar when it needs to alarm the user of an event. 202 as Calendar when it needs to alarm the user of an event.
205*/ 203*/
206void Sound::soundAlarm() 204void Sound::soundAlarm()
207{ 205{
208#ifndef QT_NO_COP 206#ifndef QT_NO_COP
209 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); 207 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" );
210#endif 208#endif
211} 209}
212 210
213 211
214/*! \class Sound 212/*! \class Sound
215 \brief The Sound class plays WAVE sound files and can invoke the audible alarm. 213 \brief The Sound class plays WAVE sound files and can invoke the audible alarm.
216 214
217 The Sound class is constructed with the .wav music file name. The Sound 215 The Sound class is constructed with the .wav music file name. The Sound
218 class retrieves the sound file from the shared Resource class. This class 216 class retrieves the sound file from the shared Resource class. This class
219 ties together QSound and the available sound resources. 217 ties together QSound and the available sound resources.
220 218
221 To sound an audible system alarm, call the static method soundAlarm() 219 To sound an audible system alarm, call the static method soundAlarm()
222 220
223 \ingroup qtopiaemb 221 \ingroup qtopiaemb
224*/ 222*/
diff --git a/library/storage.cpp b/library/storage.cpp
index d98139b..0ea465b 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,237 +1,233 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org> 2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org>
3** Copyright (C) Lorn Potter <llornkcor@handhelds.org> 3** Copyright (C) Lorn Potter <llornkcor@handhelds.org>
4** Copyright (C) 2000 Trolltech AS. All rights reserved. 4** Copyright (C) 2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of Opie Environment. 6** This file is part of Opie Environment.
7** 7**
8** This file may be distributed and/or modified under the terms of the 8** This file may be distributed and/or modified under the terms of the
9** GNU General Public License version 2 as published by the Free Software 9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the 10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file. 11** packaging of this file.
12** 12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15** 15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information. 16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17** 17**
18** Contact info@trolltech.com if any conditions of this licensing are 18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you. 19** not clear to you.
20** 20**
21**********************************************************************/ 21**********************************************************************/
22 22
23#include <qpe/storage.h> 23#include <qpe/storage.h>
24#include <qpe/custom.h>
25 24
26#include <qfile.h>
27#include <qtimer.h>
28#include <qcopchannel_qws.h> 25#include <qcopchannel_qws.h>
29 26
30#include <stdio.h> 27#include <stdio.h>
31 28
32#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 29#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
33#include <sys/vfs.h> 30#include <sys/vfs.h>
34#include <mntent.h> 31#include <mntent.h>
35#endif 32#endif
36 33
37#ifdef Q_OS_MACX 34#ifdef Q_OS_MACX
38# include <sys/param.h> 35# include <sys/param.h>
39# include <sys/ucred.h> 36# include <sys/ucred.h>
40# include <sys/mount.h> 37# include <sys/mount.h>
41# include <stdio.h> // For strerror() 38# include <stdio.h> // For strerror()
42# include <errno.h> 39# include <errno.h>
43#endif /* Q_OS_MACX */ 40#endif /* Q_OS_MACX */
44 41
45#include <qstringlist.h>
46 42
47// Shouldn't be here ! (eilers) 43// Shouldn't be here ! (eilers)
48// #include <sys/vfs.h> 44// #include <sys/vfs.h>
49// #include <mntent.h> 45// #include <mntent.h>
50 46
51 47
52static bool isCF(const QString& m) 48static bool isCF(const QString& m)
53{ 49{
54 50
55#ifndef Q_OS_MACX 51#ifndef Q_OS_MACX
56 FILE* f = fopen("/var/run/stab", "r"); 52 FILE* f = fopen("/var/run/stab", "r");
57 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 53 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
58 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 54 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
59 if ( f ) 55 if ( f )
60 { 56 {
61 char line[1024]; 57 char line[1024];
62 char devtype[80]; 58 char devtype[80];
63 char devname[80]; 59 char devname[80];
64 while ( fgets( line, 1024, f ) ) 60 while ( fgets( line, 1024, f ) )
65 { 61 {
66 // 0 ide ide-cs 0 hda 3 0 62 // 0 ide ide-cs 0 hda 3 0
67 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 63 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
68 { 64 {
69 if ( QString(devtype) == "ide" && m.find(devname)>0 ) 65 if ( QString(devtype) == "ide" && m.find(devname)>0 )
70 { 66 {
71 fclose(f); 67 fclose(f);
72 return TRUE; 68 return TRUE;
73 } 69 }
74 } 70 }
75 } 71 }
76 fclose(f); 72 fclose(f);
77 } 73 }
78#endif /* Q_OS_MACX */ 74#endif /* Q_OS_MACX */
79 return FALSE; 75 return FALSE;
80} 76}
81 77
82/*! \class StorageInfo storage.h 78/*! \class StorageInfo storage.h
83 \brief The StorageInfo class describes the disks mounted on the file system. 79 \brief The StorageInfo class describes the disks mounted on the file system.
84 80
85 This class provides access to the mount information for the Linux 81 This class provides access to the mount information for the Linux
86 filesystem. Each mount point is represented by the FileSystem class. 82 filesystem. Each mount point is represented by the FileSystem class.
87 To ensure this class has the most up to date size information, call 83 To ensure this class has the most up to date size information, call
88 the update() method. Note that this will automatically be signaled 84 the update() method. Note that this will automatically be signaled
89 by the operating system when a disk has been mounted or unmounted. 85 by the operating system when a disk has been mounted or unmounted.
90 86
91 \ingroup qtopiaemb 87 \ingroup qtopiaemb
92*/ 88*/
93 89
94/*! Constructor that determines the current mount points of the filesystem. 90/*! Constructor that determines the current mount points of the filesystem.
95 The standard \a parent parameters is passed on to QObject. 91 The standard \a parent parameters is passed on to QObject.
96 */ 92 */
97StorageInfo::StorageInfo( QObject *parent ) 93StorageInfo::StorageInfo( QObject *parent )
98 : QObject( parent ) 94 : QObject( parent )
99{ 95{
100 mFileSystems.setAutoDelete( TRUE ); 96 mFileSystems.setAutoDelete( TRUE );
101 channel = new QCopChannel( "QPE/Card", this ); 97 channel = new QCopChannel( "QPE/Card", this );
102 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 98 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
103 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 99 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
104 update(); 100 update();
105} 101}
106 102
107/*! Returns the longest matching FileSystem that starts with the 103/*! Returns the longest matching FileSystem that starts with the
108 same prefix as \a filename as its mount point. 104 same prefix as \a filename as its mount point.
109*/ 105*/
110const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 106const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
111{ 107{
112 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 108 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
113 { 109 {
114 if ( filename.startsWith( (*i)->path() ) ) 110 if ( filename.startsWith( (*i)->path() ) )
115 return (*i); 111 return (*i);
116 } 112 }
117 return 0; 113 return 0;
118} 114}
119 115
120 116
121void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 117void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
122{ 118{
123 if ( msg == "mtabChanged()" ) 119 if ( msg == "mtabChanged()" )
124 update(); 120 update();
125} 121}
126 122
127 123
128/*! Updates the mount and free space available information for each mount 124/*! Updates the mount and free space available information for each mount
129 point. This method is automatically called when a disk is mounted or 125 point. This method is automatically called when a disk is mounted or
130 unmounted. 126 unmounted.
131*/ 127*/
132// cause of the lack of a d pointer we need 128// cause of the lack of a d pointer we need
133// to store informations in a config file :( 129// to store informations in a config file :(
134void StorageInfo::update() 130void StorageInfo::update()
135{ 131{
136 //qDebug("StorageInfo::updating"); 132 //qDebug("StorageInfo::updating");
137#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 133#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
138 struct mntent *me; 134 struct mntent *me;
139 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 135 FILE *mntfp = setmntent( "/etc/mtab", "r" );
140 136
141 QStringList curdisks; 137 QStringList curdisks;
142 QStringList curopts; 138 QStringList curopts;
143 QStringList curfs; 139 QStringList curfs;
144 bool rebuild = FALSE; 140 bool rebuild = FALSE;
145 int n=0; 141 int n=0;
146 if ( mntfp ) 142 if ( mntfp )
147 { 143 {
148 while ( (me = getmntent( mntfp )) != 0 ) 144 while ( (me = getmntent( mntfp )) != 0 )
149 { 145 {
150 QString fs = me->mnt_fsname; 146 QString fs = me->mnt_fsname;
151 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 147 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
152 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 148 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
153 || fs.left( 14 ) == "/dev/mmc/part1" 149 || fs.left( 14 ) == "/dev/mmc/part1"
154 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) 150 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" )
155 { 151 {
156 n++; 152 n++;
157 curdisks.append(fs); 153 curdisks.append(fs);
158 curopts.append( me->mnt_opts ); 154 curopts.append( me->mnt_opts );
159 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); 155 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
160 curfs.append( me->mnt_dir ); 156 curfs.append( me->mnt_dir );
161 bool found = FALSE; 157 bool found = FALSE;
162 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 158 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
163 { 159 {
164 if ( (*i)->disk() == fs ) 160 if ( (*i)->disk() == fs )
165 { 161 {
166 found = TRUE; 162 found = TRUE;
167 break; 163 break;
168 } 164 }
169 } 165 }
170 if ( !found ) 166 if ( !found )
171 rebuild = TRUE; 167 rebuild = TRUE;
172 } 168 }
173 } 169 }
174 endmntent( mntfp ); 170 endmntent( mntfp );
175 } 171 }
176 if ( rebuild || n != (int)mFileSystems.count() ) 172 if ( rebuild || n != (int)mFileSystems.count() )
177 { 173 {
178 mFileSystems.clear(); 174 mFileSystems.clear();
179 QStringList::ConstIterator it=curdisks.begin(); 175 QStringList::ConstIterator it=curdisks.begin();
180 QStringList::ConstIterator fsit=curfs.begin(); 176 QStringList::ConstIterator fsit=curfs.begin();
181 QStringList::ConstIterator optsIt=curopts.begin(); 177 QStringList::ConstIterator optsIt=curopts.begin();
182 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) 178 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt)
183 { 179 {
184 QString opts = *optsIt; 180 QString opts = *optsIt;
185 181
186 QString disk = *it; 182 QString disk = *it;
187 QString humanname; 183 QString humanname;
188 bool removable = FALSE; 184 bool removable = FALSE;
189 if ( isCF(disk) ) 185 if ( isCF(disk) )
190 { 186 {
191 humanname = tr("CF Card"); 187 humanname = tr("CF Card");
192 removable = TRUE; 188 removable = TRUE;
193 } 189 }
194 else if ( disk == "/dev/hda1" ) 190 else if ( disk == "/dev/hda1" )
195 { 191 {
196 humanname = tr("Hard Disk"); 192 humanname = tr("Hard Disk");
197 } 193 }
198 else if ( disk.left(9) == "/dev/mmcd" ) 194 else if ( disk.left(9) == "/dev/mmcd" )
199 { 195 {
200 humanname = tr("SD Card"); 196 humanname = tr("SD Card");
201 removable = TRUE; 197 removable = TRUE;
202 } 198 }
203 else if ( disk.left( 14 ) == "/dev/mmc/part1" ) 199 else if ( disk.left( 14 ) == "/dev/mmc/part1" )
204 { 200 {
205 humanname = tr("MMC Card"); 201 humanname = tr("MMC Card");
206 removable = TRUE; 202 removable = TRUE;
207 } 203 }
208 else if ( disk.left(7) == "/dev/hd" ) 204 else if ( disk.left(7) == "/dev/hd" )
209 humanname = tr("Hard Disk") + " " + disk; 205 humanname = tr("Hard Disk") + " " + disk;
210 else if ( disk.left(7) == "/dev/sd" ) 206 else if ( disk.left(7) == "/dev/sd" )
211 humanname = tr("SCSI Hard Disk") + " " + disk; 207 humanname = tr("SCSI Hard Disk") + " " + disk;
212 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs 208 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
213 humanname = tr("Internal Memory"); 209 humanname = tr("Internal Memory");
214 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 210 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
215 humanname = tr("Internal Storage"); 211 humanname = tr("Internal Storage");
216 else if ( disk.left(14) == "/dev/mtdblock/" ) 212 else if ( disk.left(14) == "/dev/mtdblock/" )
217 humanname = tr("Internal Storage") + " " + disk; 213 humanname = tr("Internal Storage") + " " + disk;
218 else if ( disk.left(13) == "/dev/mtdblock" ) 214 else if ( disk.left(13) == "/dev/mtdblock" )
219 humanname = tr("Internal Storage") + " " + disk; 215 humanname = tr("Internal Storage") + " " + disk;
220 else if ( disk.left(9) == "/dev/root" ) 216 else if ( disk.left(9) == "/dev/root" )
221 humanname = tr("Internal Storage") + " " + disk; 217 humanname = tr("Internal Storage") + " " + disk;
222 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs 218 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
223 humanname = tr("Internal Memory"); 219 humanname = tr("Internal Memory");
224 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 220 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
225 mFileSystems.append( fs ); 221 mFileSystems.append( fs );
226 } 222 }
227 emit disksChanged(); 223 emit disksChanged();
228 } 224 }
229 else 225 else
230 { 226 {
231 // just update them 227 // just update them
232 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 228 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
233 i.current()->update(); 229 i.current()->update();
234 } 230 }
235#endif 231#endif
236} 232}
237 233
diff --git a/library/tzselect.cpp b/library/tzselect.cpp
index 4343eab..f28100b 100644
--- a/library/tzselect.cpp
+++ b/library/tzselect.cpp
@@ -1,217 +1,216 @@
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"
26#include "config.h" 25#include "config.h"
27#include <qtoolbutton.h> 26#include <qtoolbutton.h>
28#include <qfile.h> 27#include <qfile.h>
29#include <stdlib.h> 28#include <stdlib.h>
30 29
31#include <qcopchannel_qws.h> 30#include <qcopchannel_qws.h>
32#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
33#include <qmessagebox.h> 32#include <qmessagebox.h>
34 33
35/*! 34/*!
36 \class TimeZoneSelector 35 \class TimeZoneSelector
37 36
38 \brief The TimeZoneSelector widget allows users to configure their time zone information. 37 \brief The TimeZoneSelector widget allows users to configure their time zone information.
39 38
40 \ingroup qtopiaemb 39 \ingroup qtopiaemb
41*/ 40*/
42 41
43class TimeZoneSelectorPrivate 42class TimeZoneSelectorPrivate
44{ 43{
45public: 44public:
46 TimeZoneSelectorPrivate() : includeLocal(FALSE) {} 45 TimeZoneSelectorPrivate() : includeLocal(FALSE) {}
47 bool includeLocal; 46 bool includeLocal;
48}; 47};
49 48
50TZCombo::TZCombo( QWidget *p, const char* n ) 49TZCombo::TZCombo( QWidget *p, const char* n )
51 : QComboBox( p, n ) 50 : QComboBox( p, n )
52{ 51{
53 updateZones(); 52 updateZones();
54 // check to see if TZ is set, if it is set the current item to that 53 // check to see if TZ is set, if it is set the current item to that
55 QString tz = getenv("TZ"); 54 QString tz = getenv("TZ");
56 if (parent()->inherits("TimeZoneSelector")) { 55 if (parent()->inherits("TimeZoneSelector")) {
57 if ( ((TimeZoneSelector *)parent())->localIncluded() ) { 56 if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
58 // overide to the 'local' type. 57 // overide to the 'local' type.
59 tz = "None"; 58 tz = "None";
60 } 59 }
61 } 60 }
62 if ( !tz.isNull() ) { 61 if ( !tz.isNull() ) {
63 int n = 0, 62 int n = 0,
64 index = 0; 63 index = 0;
65 for ( QStringList::Iterator it=identifiers.begin(); 64 for ( QStringList::Iterator it=identifiers.begin();
66 it!=identifiers.end(); ++it) { 65 it!=identifiers.end(); ++it) {
67 if ( *it == tz ) 66 if ( *it == tz )
68 index = n; 67 index = n;
69 n++; 68 n++;
70 } 69 }
71 setCurrentItem(index); 70 setCurrentItem(index);
72 } else { 71 } else {
73 setCurrentItem(0); 72 setCurrentItem(0);
74 } 73 }
75 74
76 75
77 76
78 // listen on QPE/System 77 // listen on QPE/System
79#if !defined(QT_NO_COP) 78#if !defined(QT_NO_COP)
80 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 79 QCopChannel *channel = new QCopChannel( "QPE/System", this );
81 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 80 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
82 this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) ); 81 this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) );
83#endif 82#endif
84 83
85 84
86} 85}
87 86
88TZCombo::~TZCombo() 87TZCombo::~TZCombo()
89{ 88{
90} 89}
91 90
92void TZCombo::updateZones() 91void TZCombo::updateZones()
93{ 92{
94 QString cur = currentText(); 93 QString cur = currentText();
95 clear(); 94 clear();
96 identifiers.clear(); 95 identifiers.clear();
97 int curix=0; 96 int curix=0;
98 QString tz = getenv("TZ"); 97 QString tz = getenv("TZ");
99 bool tzFound = FALSE; 98 bool tzFound = FALSE;
100 Config cfg("CityTime"); 99 Config cfg("CityTime");
101 cfg.setGroup("TimeZones"); 100 cfg.setGroup("TimeZones");
102 int listIndex = 0; 101 int listIndex = 0;
103 if (parent()->inherits("TimeZoneSelector")) { 102 if (parent()->inherits("TimeZoneSelector")) {
104 if ( ((TimeZoneSelector *)parent())->localIncluded() ) { 103 if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
105 // overide to the 'local' type. 104 // overide to the 'local' type.
106 identifiers.append( "None" ); 105 identifiers.append( "None" );
107 insertItem( tr("None") ); 106 insertItem( tr("None") );
108 if ( cur == tr("None")) 107 if ( cur == tr("None"))
109 curix = 0; 108 curix = 0;
110 listIndex++; 109 listIndex++;
111 } 110 }
112 } 111 }
113 int cfgIndex = 0; 112 int cfgIndex = 0;
114 while (1) { 113 while (1) {
115 QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null); 114 QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null);
116 if ( zn.isNull() ) 115 if ( zn.isNull() )
117 break; 116 break;
118 if ( zn == tz ) 117 if ( zn == tz )
119 tzFound = TRUE; 118 tzFound = TRUE;
120 QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex)); 119 QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex));
121 identifiers.append(zn); 120 identifiers.append(zn);
122 insertItem(nm); 121 insertItem(nm);
123 if ( nm == cur ) 122 if ( nm == cur )
124 curix = listIndex; 123 curix = listIndex;
125 ++cfgIndex; 124 ++cfgIndex;
126 ++listIndex; 125 ++listIndex;
127 } 126 }
128 if ( !listIndex ) { 127 if ( !listIndex ) {
129 QStringList list = timezoneDefaults(); 128 QStringList list = timezoneDefaults();
130 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) { 129 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) {
131 QString zn = *it; 130 QString zn = *it;
132 QString nm = *++it; 131 QString nm = *++it;
133 if ( zn == tz ) 132 if ( zn == tz )
134 tzFound = TRUE; 133 tzFound = TRUE;
135 if ( nm == cur ) 134 if ( nm == cur )
136 curix = listIndex; 135 curix = listIndex;
137 identifiers.append(zn); 136 identifiers.append(zn);
138 insertItem(nm); 137 insertItem(nm);
139 ++listIndex; 138 ++listIndex;
140 } 139 }
141 } 140 }
142 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) { 141 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) {
143 insertItem(*it); 142 insertItem(*it);
144 identifiers.append(*it); 143 identifiers.append(*it);
145 if ( *it == cur ) 144 if ( *it == cur )
146 curix = listIndex; 145 curix = listIndex;
147 ++listIndex; 146 ++listIndex;
148 } 147 }
149 if ( !tzFound && !tz.isEmpty()) { 148 if ( !tzFound && !tz.isEmpty()) {
150 int i = tz.find( '/' ); 149 int i = tz.find( '/' );
151 QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " "); 150 QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " ");
152 identifiers.append(tz); 151 identifiers.append(tz);
153 insertItem(nm); 152 insertItem(nm);
154 if ( nm == cur ) 153 if ( nm == cur )
155 curix = listIndex; 154 curix = listIndex;
156 ++listIndex; 155 ++listIndex;
157 } 156 }
158 setCurrentItem(curix); 157 setCurrentItem(curix);
159} 158}
160 159
161 160
162void TZCombo::keyPressEvent( QKeyEvent *e ) 161void TZCombo::keyPressEvent( QKeyEvent *e )
163{ 162{
164 // ### should popup() in Qt 3.0 (it's virtual there) 163 // ### should popup() in Qt 3.0 (it's virtual there)
165// updateZones(); 164// updateZones();
166 QComboBox::keyPressEvent(e); 165 QComboBox::keyPressEvent(e);
167} 166}
168 167
169void TZCombo::mousePressEvent(QMouseEvent*e) 168void TZCombo::mousePressEvent(QMouseEvent*e)
170{ 169{
171 // ### should popup() in Qt 3.0 (it's virtual there) 170 // ### should popup() in Qt 3.0 (it's virtual there)
172// updateZones(); 171// updateZones();
173 QComboBox::mousePressEvent(e); 172 QComboBox::mousePressEvent(e);
174} 173}
175 174
176QString TZCombo::currZone() const 175QString TZCombo::currZone() const
177{ 176{
178 return identifiers[currentItem()]; 177 return identifiers[currentItem()];
179} 178}
180 179
181void TZCombo::setCurrZone( const QString& id ) 180void TZCombo::setCurrZone( const QString& id )
182{ 181{
183 for (int i=0; i< count(); i++) { 182 for (int i=0; i< count(); i++) {
184 if ( identifiers[i] == id ) { 183 if ( identifiers[i] == id ) {
185 setCurrentItem(i); 184 setCurrentItem(i);
186 return; 185 return;
187} 186}
188 } 187 }
189 insertItem(id); 188 insertItem(id);
190 setCurrentItem( count() - 1); 189 setCurrentItem( count() - 1);
191 identifiers.append(id); 190 identifiers.append(id);
192 extras.append(id); 191 extras.append(id);
193} 192}
194 193
195 194
196 195
197void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&) 196void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&)
198{ 197{
199 if ( msg == "timeZoneListChange()" ) { 198 if ( msg == "timeZoneListChange()" ) {
200 updateZones(); 199 updateZones();
201 } 200 }
202} 201}
203 202
204/*! 203/*!
205 Creates a new TimeZoneSelector with parent \a p and name \a n. The combobox will be 204 Creates a new TimeZoneSelector with parent \a p and name \a n. The combobox will be
206 populated with the available timezones. 205 populated with the available timezones.
207*/ 206*/
208 207
209TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) : 208TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) :
210 QHBox(p,n) 209 QHBox(p,n)
211{ 210{
212 d = new TimeZoneSelectorPrivate(); 211 d = new TimeZoneSelectorPrivate();
213 // build the combobox before we do any updates... 212 // build the combobox before we do any updates...
214 cmbTz = new TZCombo( this, "timezone combo" ); 213 cmbTz = new TZCombo( this, "timezone combo" );
215 214
216 cmdTz = new QToolButton( this, "timezone button" ); 215 cmdTz = new QToolButton( this, "timezone button" );
217 cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) ); 216 cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) );