summaryrefslogtreecommitdiff
path: root/library
Unidiff
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/power.cpp2
-rw-r--r--library/qpeapplication.cpp10
-rw-r--r--library/storage.cpp2
3 files changed, 7 insertions, 7 deletions
diff --git a/library/power.cpp b/library/power.cpp
index 5310b47..e7e5b24 100644
--- a/library/power.cpp
+++ b/library/power.cpp
@@ -1,171 +1,171 @@
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 "power.h" 21#include "power.h"
22 22
23#ifdef QT_QWS_SL5XXX 23#if defined(QT_QWS_SL5XXX) || defined(QT_QWS_RAMSES)
24#include "custom.h" 24#include "custom.h"
25#endif 25#endif
26 26
27#include <unistd.h> 27#include <unistd.h>
28#include <stdlib.h> 28#include <stdlib.h>
29#include <stdio.h> 29#include <stdio.h>
30#include <fcntl.h> 30#include <fcntl.h>
31#include <sys/ioctl.h> 31#include <sys/ioctl.h>
32 32
33#ifdef QT_QWS_IPAQ_NO_APM 33#ifdef QT_QWS_IPAQ_NO_APM
34#include <linux/h3600_ts.h> 34#include <linux/h3600_ts.h>
35#endif 35#endif
36 36
37PowerStatusManager *PowerStatusManager::powerManager = 0; 37PowerStatusManager *PowerStatusManager::powerManager = 0;
38PowerStatus *PowerStatusManager::ps = 0; 38PowerStatus *PowerStatusManager::ps = 0;
39 39
40static bool haveProcApm = false; 40static bool haveProcApm = false;
41 41
42PowerStatusManager::PowerStatusManager() 42PowerStatusManager::PowerStatusManager()
43{ 43{
44 powerManager = this; 44 powerManager = this;
45 ps = new PowerStatus; 45 ps = new PowerStatus;
46 FILE *f = fopen("/proc/apm", "r"); 46 FILE *f = fopen("/proc/apm", "r");
47 if ( f ) { 47 if ( f ) {
48 fclose(f); 48 fclose(f);
49 haveProcApm = TRUE; 49 haveProcApm = TRUE;
50 } 50 }
51} 51}
52 52
53const PowerStatus &PowerStatusManager::readStatus() 53const PowerStatus &PowerStatusManager::readStatus()
54{ 54{
55 if ( !powerManager ) 55 if ( !powerManager )
56 (void)new PowerStatusManager; 56 (void)new PowerStatusManager;
57 57
58 powerManager->getStatus(); 58 powerManager->getStatus();
59 59
60 return *ps; 60 return *ps;
61} 61}
62 62
63// Standard /proc/apm reader 63// Standard /proc/apm reader
64bool PowerStatusManager::getProcApmStatus( int &ac, int &bs, int &bf, int &pc, int &sec ) 64bool PowerStatusManager::getProcApmStatus( int &ac, int &bs, int &bf, int &pc, int &sec )
65{ 65{
66 bool ok = false; 66 bool ok = false;
67 67
68 ac = 0xff; 68 ac = 0xff;
69 bs = 0xff; 69 bs = 0xff;
70 bf = 0xff; 70 bf = 0xff;
71 pc = -1; 71 pc = -1;
72 sec = -1; 72 sec = -1;
73 73
74 FILE *f = fopen("/proc/apm", "r"); 74 FILE *f = fopen("/proc/apm", "r");
75 if ( f ) { 75 if ( f ) {
76 //I 1.13 1.2 0x02 0x00 0xff 0xff 49% 147 sec 76 //I 1.13 1.2 0x02 0x00 0xff 0xff 49% 147 sec
77 char u; 77 char u;
78 fscanf(f, "%*[^ ] %*d.%*d 0x%*x 0x%x 0x%x 0x%x %d%% %i %c", 78 fscanf(f, "%*[^ ] %*d.%*d 0x%*x 0x%x 0x%x 0x%x %d%% %i %c",
79 &ac, &bs, &bf, &pc, &sec, &u); 79 &ac, &bs, &bf, &pc, &sec, &u);
80 fclose(f); 80 fclose(f);
81 switch ( u ) { 81 switch ( u ) {
82 case 'm': sec *= 60; 82 case 'm': sec *= 60;
83 case 's': break; // ok 83 case 's': break; // ok
84 default: sec = -1; // unknown 84 default: sec = -1; // unknown
85 } 85 }
86 86
87 // extract data 87 // extract data
88 switch ( bs ) { 88 switch ( bs ) {
89 case 0x00: 89 case 0x00:
90 ps->bs = PowerStatus::High; 90 ps->bs = PowerStatus::High;
91 break; 91 break;
92 case 0x01: 92 case 0x01:
93 ps->bs = PowerStatus::Low; 93 ps->bs = PowerStatus::Low;
94 break; 94 break;
95 case 0x7f: 95 case 0x7f:
96 ps->bs = PowerStatus::VeryLow; 96 ps->bs = PowerStatus::VeryLow;
97 break; 97 break;
98 case 0x02: 98 case 0x02:
99 ps->bs = PowerStatus::Critical; 99 ps->bs = PowerStatus::Critical;
100 break; 100 break;
101 case 0x03: 101 case 0x03:
102 ps->bs = PowerStatus::Charging; 102 ps->bs = PowerStatus::Charging;
103 break; 103 break;
104 case 0x04: 104 case 0x04:
105 case 0xff: // 0xff is Unknown but we map to NotPresent 105 case 0xff: // 0xff is Unknown but we map to NotPresent
106 default: 106 default:
107 ps->bs = PowerStatus::NotPresent; 107 ps->bs = PowerStatus::NotPresent;
108 break; 108 break;
109 } 109 }
110 110
111 switch ( ac ) { 111 switch ( ac ) {
112 case 0x00: 112 case 0x00:
113 ps->ac = PowerStatus::Offline; 113 ps->ac = PowerStatus::Offline;
114 break; 114 break;
115 case 0x01: 115 case 0x01:
116 ps->ac = PowerStatus::Online; 116 ps->ac = PowerStatus::Online;
117 break; 117 break;
118 case 0x02: 118 case 0x02:
119 ps->ac = PowerStatus::Backup; 119 ps->ac = PowerStatus::Backup;
120 break; 120 break;
121 } 121 }
122 122
123 if ( pc > 100 ) pc = 100; 123 if ( pc > 100 ) pc = 100;
124 if ( pc < 0 ) pc = 0; 124 if ( pc < 0 ) pc = 0;
125 125
126 ps->percentRemain = pc; 126 ps->percentRemain = pc;
127 ps->secsRemain = sec; 127 ps->secsRemain = sec;
128 128
129 ok = true; 129 ok = true;
130 } 130 }
131 131
132 return ok; 132 return ok;
133} 133}
134 134
135void PowerStatusManager::getStatus() 135void PowerStatusManager::getStatus()
136{ 136{
137 bool usedApm = FALSE; 137 bool usedApm = FALSE;
138 138
139 ps->percentAccurate = TRUE; 139 ps->percentAccurate = TRUE;
140 140
141 // Some iPAQ kernel builds don't have APM. If this is not the case we 141 // Some iPAQ kernel builds don't have APM. If this is not the case we
142 // save ourselves an ioctl by testing if /proc/apm exists in the 142 // save ourselves an ioctl by testing if /proc/apm exists in the
143 // constructor and we use /proc/apm instead 143 // constructor and we use /proc/apm instead
144 int ac, bs, bf, pc, sec; 144 int ac, bs, bf, pc, sec;
145 if ( haveProcApm ) 145 if ( haveProcApm )
146 usedApm = getProcApmStatus( ac, bs, bf, pc, sec ); 146 usedApm = getProcApmStatus( ac, bs, bf, pc, sec );
147 147
148 if ( !usedApm ) { 148 if ( !usedApm ) {
149#ifdef QT_QWS_IPAQ_NO_APM 149#ifdef QT_QWS_IPAQ_NO_APM
150 int fd; 150 int fd;
151 int err; 151 int err;
152 struct bat_dev batt_info; 152 struct bat_dev batt_info;
153 153
154 memset(&batt_info, 0, sizeof(batt_info)); 154 memset(&batt_info, 0, sizeof(batt_info));
155 155
156 fd = ::open("/dev/ts",O_RDONLY); 156 fd = ::open("/dev/ts",O_RDONLY);
157 if( fd < 0 ) 157 if( fd < 0 )
158 return; 158 return;
159 159
160 ioctl(fd, GET_BATTERY_STATUS, &batt_info); 160 ioctl(fd, GET_BATTERY_STATUS, &batt_info);
161 ac_status = batt_info.ac_status; 161 ac_status = batt_info.ac_status;
162 ps->percentRemain = ( 425 * batt_info.batt1_voltage ) / 1000 - 298; // from h3600_ts.c 162 ps->percentRemain = ( 425 * batt_info.batt1_voltage ) / 1000 - 298; // from h3600_ts.c
163 ps->secsRemain = -1; // seconds is bogus on iPAQ 163 ps->secsRemain = -1; // seconds is bogus on iPAQ
164 ::close (fd); 164 ::close (fd);
165#else 165#else
166 ps->percentRemain = 100; 166 ps->percentRemain = 100;
167 ps->secsRemain = -1; 167 ps->secsRemain = -1;
168 ps->percentAccurate = FALSE; 168 ps->percentAccurate = FALSE;
169#endif 169#endif
170 } 170 }
171} 171}
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 22d222a..4bc08b3 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,728 +1,728 @@
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** $Id$ 19** $Id$
20** 20**
21**********************************************************************/ 21**********************************************************************/
22#define QTOPIA_INTERNAL_LANGLIST 22#define QTOPIA_INTERNAL_LANGLIST
23#include <stdlib.h> 23#include <stdlib.h>
24#include <unistd.h> 24#include <unistd.h>
25#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 25#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
26#include <qfile.h> 26#include <qfile.h>
27#ifdef Q_WS_QWS 27#ifdef Q_WS_QWS
28#ifndef QT_NO_COP 28#ifndef QT_NO_COP
29#if QT_VERSION <= 231 29#if QT_VERSION <= 231
30#define private public 30#define private public
31#define sendLocally processEvent 31#define sendLocally processEvent
32#include "qcopenvelope_qws.h" 32#include "qcopenvelope_qws.h"
33#undef private 33#undef private
34#else 34#else
35#include "qcopenvelope_qws.h" 35#include "qcopenvelope_qws.h"
36#endif 36#endif
37#endif 37#endif
38#include <qwindowsystem_qws.h> 38#include <qwindowsystem_qws.h>
39#endif 39#endif
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qpalette.h> 41#include <qpalette.h>
42#include <qbuffer.h> 42#include <qbuffer.h>
43#include <qptrdict.h> 43#include <qptrdict.h>
44#include <qregexp.h> 44#include <qregexp.h>
45#include <qdir.h> 45#include <qdir.h>
46#include <qlabel.h> 46#include <qlabel.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qdragobject.h> 48#include <qdragobject.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qevent.h> 50#include <qevent.h>
51#include <qtooltip.h> 51#include <qtooltip.h>
52#include <qsignal.h> 52#include <qsignal.h>
53#include <qmainwindow.h> 53#include <qmainwindow.h>
54#include "qpeapplication.h" 54#include "qpeapplication.h"
55#include "qpestyle.h" 55#include "qpestyle.h"
56#include "styleinterface.h" 56#include "styleinterface.h"
57#if QT_VERSION >= 300 57#if QT_VERSION >= 300
58#include <qstylefactory.h> 58#include <qstylefactory.h>
59#else 59#else
60#include <qplatinumstyle.h> 60#include <qplatinumstyle.h>
61#include <qwindowsstyle.h> 61#include <qwindowsstyle.h>
62#include <qmotifstyle.h> 62#include <qmotifstyle.h>
63#include <qmotifplusstyle.h> 63#include <qmotifplusstyle.h>
64#include "lightstyle.h" 64#include "lightstyle.h"
65 65
66#include <qpe/qlibrary.h> 66#include <qpe/qlibrary.h>
67#endif 67#endif
68#include "global.h" 68#include "global.h"
69#include "resource.h" 69#include "resource.h"
70#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 70#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
71#include "qutfcodec.h" 71#include "qutfcodec.h"
72#endif 72#endif
73#include "config.h" 73#include "config.h"
74#include "network.h" 74#include "network.h"
75#ifdef QWS 75#ifdef QWS
76#include "fontmanager.h" 76#include "fontmanager.h"
77#endif 77#endif
78 78
79#include "alarmserver.h" 79#include "alarmserver.h"
80#include "applnk.h" 80#include "applnk.h"
81#include "qpemenubar.h" 81#include "qpemenubar.h"
82#include "textcodecinterface.h" 82#include "textcodecinterface.h"
83#include "imagecodecinterface.h" 83#include "imagecodecinterface.h"
84 84
85#include <unistd.h> 85#include <unistd.h>
86#include <sys/file.h> 86#include <sys/file.h>
87#include <sys/ioctl.h> 87#include <sys/ioctl.h>
88#include <sys/soundcard.h> 88#include <sys/soundcard.h>
89 89
90#include "qt_override_p.h" 90#include "qt_override_p.h"
91 91
92 92
93class QPEApplicationData 93class QPEApplicationData
94{ 94{
95public: 95public:
96 QPEApplicationData ( ) 96 QPEApplicationData ( )
97 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 97 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
98 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 98 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
99 keep_running( true ), qpe_main_widget( 0 ) 99 keep_running( true ), qpe_main_widget( 0 )
100 100
101 { 101 {
102 qcopq.setAutoDelete( TRUE ); 102 qcopq.setAutoDelete( TRUE );
103 } 103 }
104 104
105 int presstimer; 105 int presstimer;
106 QWidget* presswidget; 106 QWidget* presswidget;
107 QPoint presspos; 107 QPoint presspos;
108 108
109 bool rightpressed : 1; 109 bool rightpressed : 1;
110 bool kbgrabbed : 1; 110 bool kbgrabbed : 1;
111 bool notbusysent : 1; 111 bool notbusysent : 1;
112 bool preloaded : 1; 112 bool preloaded : 1;
113 bool forceshow : 1; 113 bool forceshow : 1;
114 bool nomaximize : 1; 114 bool nomaximize : 1;
115 bool keep_running : 1; 115 bool keep_running : 1;
116 116
117 QString appName; 117 QString appName;
118 struct QCopRec 118 struct QCopRec
119 { 119 {
120 QCopRec( const QCString &ch, const QCString &msg, 120 QCopRec( const QCString &ch, const QCString &msg,
121 const QByteArray &d ) : 121 const QByteArray &d ) :
122 channel( ch ), message( msg ), data( d ) 122 channel( ch ), message( msg ), data( d )
123 { } 123 { }
124 124
125 QCString channel; 125 QCString channel;
126 QCString message; 126 QCString message;
127 QByteArray data; 127 QByteArray data;
128 }; 128 };
129 QWidget* qpe_main_widget; 129 QWidget* qpe_main_widget;
130 QList<QCopRec> qcopq; 130 QList<QCopRec> qcopq;
131 131
132 void enqueueQCop( const QCString &ch, const QCString &msg, 132 void enqueueQCop( const QCString &ch, const QCString &msg,
133 const QByteArray &data ) 133 const QByteArray &data )
134 { 134 {
135 qcopq.append( new QCopRec( ch, msg, data ) ); 135 qcopq.append( new QCopRec( ch, msg, data ) );
136 } 136 }
137 void sendQCopQ() 137 void sendQCopQ()
138 { 138 {
139 QCopRec * r; 139 QCopRec * r;
140#ifndef QT_NO_COP 140#ifndef QT_NO_COP
141 141
142 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it ) 142 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it )
143 QCopChannel::sendLocally( r->channel, r->message, r->data ); 143 QCopChannel::sendLocally( r->channel, r->message, r->data );
144#endif 144#endif
145 145
146 qcopq.clear(); 146 qcopq.clear();
147 } 147 }
148 static void show_mx(QWidget* mw, bool nomaximize) 148 static void show_mx(QWidget* mw, bool nomaximize)
149 { 149 {
150 150
151 // ugly hack, remove that later after finding a sane solution 151 // ugly hack, remove that later after finding a sane solution
152 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, 152 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
153 // so this is only useful if QT_QWS_SHARP is defined. E.g. SIMpad has 800x600 but has 153 // so this is only useful if QT_QWS_SHARP is defined. E.g. SIMpad has 800x600 but has
154 // a (physically) large enough display to use the small icons 154 // a (physically) large enough display to use the small icons
155 #ifdef QT_QWS_SHARP 155#ifdef QT_QWS_SHARP
156 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { 156 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
157 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); 157 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
158 } 158 }
159 #endif 159#endif
160 160
161 if ( mw->layout() && mw->inherits("QDialog") ) { 161 if ( mw->layout() && mw->inherits("QDialog") ) {
162 QPEApplication::showDialog((QDialog*)mw, nomaximize); 162 QPEApplication::showDialog((QDialog*)mw, nomaximize);
163 } 163 }
164 else { 164 else {
165#ifdef Q_WS_QWS 165#ifdef Q_WS_QWS
166 if ( !nomaximize ) 166 if ( !nomaximize )
167 mw->showMaximized(); 167 mw->showMaximized();
168 else 168 else
169#endif 169#endif
170 170
171 mw->show(); 171 mw->show();
172 } 172 }
173 } 173 }
174 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 174 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
175 { 175 {
176 /* 176 /*
177 // This works but disable it for now until it is safe to apply 177 // This works but disable it for now until it is safe to apply
178 // What is does is scan the .desktop files of all the apps for 178 // What is does is scan the .desktop files of all the apps for
179 // the applnk that has the corresponding argv[0] as this program 179 // the applnk that has the corresponding argv[0] as this program
180 // then it uses the name stored in the .desktop file as the caption 180 // then it uses the name stored in the .desktop file as the caption
181 // for the main widget. This saves duplicating translations for 181 // for the main widget. This saves duplicating translations for
182 // the app name in the program and in the .desktop files. 182 // the app name in the program and in the .desktop files.
183 183
184 AppLnkSet apps( appsPath ); 184 AppLnkSet apps( appsPath );
185 185
186 QList<AppLnk> appsList = apps.children(); 186 QList<AppLnk> appsList = apps.children();
187 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 187 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
188 if ( (*it)->exec() == appName ) { 188 if ( (*it)->exec() == appName ) {
189 mw->setCaption( (*it)->name() ); 189 mw->setCaption( (*it)->name() );
190 return TRUE; 190 return TRUE;
191 } 191 }
192 } 192 }
193 */ 193 */
194 return FALSE; 194 return FALSE;
195 } 195 }
196 196
197 197
198 void show(QWidget* mw, bool nomax) 198 void show(QWidget* mw, bool nomax)
199 { 199 {
200 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 200 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
201 nomaximize = nomax; 201 nomaximize = nomax;
202 qpe_main_widget = mw; 202 qpe_main_widget = mw;
203#ifndef QT_NO_COP 203#ifndef QT_NO_COP
204 204
205 sendQCopQ(); 205 sendQCopQ();
206#endif 206#endif
207 207
208 if ( preloaded ) { 208 if ( preloaded ) {
209 if (forceshow) 209 if (forceshow)
210 show_mx(mw, nomax); 210 show_mx(mw, nomax);
211 } 211 }
212 else if ( keep_running ) { 212 else if ( keep_running ) {
213 show_mx(mw, nomax); 213 show_mx(mw, nomax);
214 } 214 }
215 } 215 }
216 216
217 void loadTextCodecs() 217 void loadTextCodecs()
218 { 218 {
219 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 219 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
220 QDir dir( path, "lib*.so" ); 220 QDir dir( path, "lib*.so" );
221 QStringList list; 221 QStringList list;
222 if ( dir. exists ( )) 222 if ( dir. exists ( ))
223 list = dir.entryList(); 223 list = dir.entryList();
224 QStringList::Iterator it; 224 QStringList::Iterator it;
225 for ( it = list.begin(); it != list.end(); ++it ) { 225 for ( it = list.begin(); it != list.end(); ++it ) {
226 TextCodecInterface *iface = 0; 226 TextCodecInterface *iface = 0;
227 QLibrary *lib = new QLibrary( path + "/" + *it ); 227 QLibrary *lib = new QLibrary( path + "/" + *it );
228 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 228 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
229 QValueList<int> mibs = iface->mibEnums(); 229 QValueList<int> mibs = iface->mibEnums();
230 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 230 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
231 (void)iface->createForMib(*i); 231 (void)iface->createForMib(*i);
232 // ### it exists now; need to remember if we can delete it 232 // ### it exists now; need to remember if we can delete it
233 } 233 }
234 } 234 }
235 else { 235 else {
236 lib->unload(); 236 lib->unload();
237 delete lib; 237 delete lib;
238 } 238 }
239 } 239 }
240 } 240 }
241 241
242 void loadImageCodecs() 242 void loadImageCodecs()
243 { 243 {
244 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 244 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
245 QDir dir( path, "lib*.so" ); 245 QDir dir( path, "lib*.so" );
246 QStringList list; 246 QStringList list;
247 if ( dir. exists ( )) 247 if ( dir. exists ( ))
248 list = dir.entryList(); 248 list = dir.entryList();
249 QStringList::Iterator it; 249 QStringList::Iterator it;
250 for ( it = list.begin(); it != list.end(); ++it ) { 250 for ( it = list.begin(); it != list.end(); ++it ) {
251 ImageCodecInterface *iface = 0; 251 ImageCodecInterface *iface = 0;
252 QLibrary *lib = new QLibrary( path + "/" + *it ); 252 QLibrary *lib = new QLibrary( path + "/" + *it );
253 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 253 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
254 QStringList formats = iface->keys(); 254 QStringList formats = iface->keys();
255 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 255 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
256 (void)iface->installIOHandler(*i); 256 (void)iface->installIOHandler(*i);
257 // ### it exists now; need to remember if we can delete it 257 // ### it exists now; need to remember if we can delete it
258 } 258 }
259 } 259 }
260 else { 260 else {
261 lib->unload(); 261 lib->unload();
262 delete lib; 262 delete lib;
263 } 263 }
264 } 264 }
265 } 265 }
266 QString styleName; 266 QString styleName;
267 QString decorationName; 267 QString decorationName;
268}; 268};
269 269
270class ResourceMimeFactory : public QMimeSourceFactory 270class ResourceMimeFactory : public QMimeSourceFactory
271{ 271{
272public: 272public:
273 ResourceMimeFactory() 273 ResourceMimeFactory()
274 { 274 {
275 setFilePath( Global::helpPath() ); 275 setFilePath( Global::helpPath() );
276 setExtensionType( "html", "text/html;charset=UTF-8" ); 276 setExtensionType( "html", "text/html;charset=UTF-8" );
277 } 277 }
278 278
279 const QMimeSource* data( const QString& abs_name ) const 279 const QMimeSource* data( const QString& abs_name ) const
280 { 280 {
281 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 281 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
282 if ( !r ) { 282 if ( !r ) {
283 int sl = abs_name.length(); 283 int sl = abs_name.length();
284 do { 284 do {
285 sl = abs_name.findRev( '/', sl - 1 ); 285 sl = abs_name.findRev( '/', sl - 1 );
286 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 286 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
287 int dot = name.findRev( '.' ); 287 int dot = name.findRev( '.' );
288 if ( dot >= 0 ) 288 if ( dot >= 0 )
289 name = name.left( dot ); 289 name = name.left( dot );
290 QImage img = Resource::loadImage( name ); 290 QImage img = Resource::loadImage( name );
291 if ( !img.isNull() ) 291 if ( !img.isNull() )
292 r = new QImageDrag( img ); 292 r = new QImageDrag( img );
293 } 293 }
294 while ( !r && sl > 0 ); 294 while ( !r && sl > 0 );
295 } 295 }
296 return r; 296 return r;
297 } 297 }
298}; 298};
299 299
300static int muted = 0; 300static int muted = 0;
301static int micMuted = 0; 301static int micMuted = 0;
302 302
303static void setVolume( int t = 0, int percent = -1 ) 303static void setVolume( int t = 0, int percent = -1 )
304{ 304{
305 switch ( t ) { 305 switch ( t ) {
306 case 0: { 306 case 0: {
307 Config cfg( "qpe" ); 307 Config cfg( "qpe" );
308 cfg.setGroup( "Volume" ); 308 cfg.setGroup( "Volume" );
309 if ( percent < 0 ) 309 if ( percent < 0 )
310 percent = cfg.readNumEntry( "VolumePercent", 50 ); 310 percent = cfg.readNumEntry( "VolumePercent", 50 );
311 int fd = 0; 311 int fd = 0;
312 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 312 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
313 int vol = muted ? 0 : percent; 313 int vol = muted ? 0 : percent;
314 // set both channels to same volume 314 // set both channels to same volume
315 vol |= vol << 8; 315 vol |= vol << 8;
316 ioctl( fd, MIXER_WRITE( 0 ), &vol ); 316 ioctl( fd, MIXER_WRITE( 0 ), &vol );
317 ::close( fd ); 317 ::close( fd );
318 } 318 }
319 } 319 }
320 break; 320 break;
321 } 321 }
322} 322}
323 323
324static void setMic( int t = 0, int percent = -1 ) 324static void setMic( int t = 0, int percent = -1 )
325{ 325{
326 switch ( t ) { 326 switch ( t ) {
327 case 0: { 327 case 0: {
328 Config cfg( "qpe" ); 328 Config cfg( "qpe" );
329 cfg.setGroup( "Volume" ); 329 cfg.setGroup( "Volume" );
330 if ( percent < 0 ) 330 if ( percent < 0 )
331 percent = cfg.readNumEntry( "Mic", 50 ); 331 percent = cfg.readNumEntry( "Mic", 50 );
332 332
333 int fd = 0; 333 int fd = 0;
334 int mic = micMuted ? 0 : percent; 334 int mic = micMuted ? 0 : percent;
335 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 335 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
336 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 336 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
337 ::close( fd ); 337 ::close( fd );
338 } 338 }
339 } 339 }
340 break; 340 break;
341 } 341 }
342} 342}
343 343
344 344
345static void setBass( int t = 0, int percent = -1 ) 345static void setBass( int t = 0, int percent = -1 )
346{ 346{
347 switch ( t ) { 347 switch ( t ) {
348 case 0: { 348 case 0: {
349 Config cfg( "qpe" ); 349 Config cfg( "qpe" );
350 cfg.setGroup( "Volume" ); 350 cfg.setGroup( "Volume" );
351 if ( percent < 0 ) 351 if ( percent < 0 )
352 percent = cfg.readNumEntry( "BassPercent", 50 ); 352 percent = cfg.readNumEntry( "BassPercent", 50 );
353 353
354 int fd = 0; 354 int fd = 0;
355 int bass = percent; 355 int bass = percent;
356 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 356 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
357 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 357 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
358 ::close( fd ); 358 ::close( fd );
359 } 359 }
360 } 360 }
361 break; 361 break;
362 } 362 }
363} 363}
364 364
365 365
366static void setTreble( int t = 0, int percent = -1 ) 366static void setTreble( int t = 0, int percent = -1 )
367{ 367{
368 switch ( t ) { 368 switch ( t ) {
369 case 0: { 369 case 0: {
370 Config cfg( "qpe" ); 370 Config cfg( "qpe" );
371 cfg.setGroup( "Volume" ); 371 cfg.setGroup( "Volume" );
372 if ( percent < 0 ) 372 if ( percent < 0 )
373 percent = cfg.readNumEntry( "TreblePercent", 50 ); 373 percent = cfg.readNumEntry( "TreblePercent", 50 );
374 374
375 int fd = 0; 375 int fd = 0;
376 int treble = percent; 376 int treble = percent;
377 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 377 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
378 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 378 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
379 ::close( fd ); 379 ::close( fd );
380 } 380 }
381 } 381 }
382 break; 382 break;
383 } 383 }
384} 384}
385 385
386 386
387/*! 387/*!
388 \class QPEApplication qpeapplication.h 388 \class QPEApplication qpeapplication.h
389 \brief The QPEApplication class implements various system services 389 \brief The QPEApplication class implements various system services
390 that are available to all Qtopia applications. 390 that are available to all Qtopia applications.
391 391
392 Simply by using QPEApplication instead of QApplication, a standard Qt 392 Simply by using QPEApplication instead of QApplication, a standard Qt
393 application becomes a Qtopia application. It automatically follows 393 application becomes a Qtopia application. It automatically follows
394 style changes, quits and raises, and in the 394 style changes, quits and raises, and in the
395 case of \link docwidget.html document-oriented\endlink applications, 395 case of \link docwidget.html document-oriented\endlink applications,
396 changes the currently displayed document in response to the environment. 396 changes the currently displayed document in response to the environment.
397 397
398 To create a \link docwidget.html document-oriented\endlink 398 To create a \link docwidget.html document-oriented\endlink
399 application use showMainDocumentWidget(); to create a 399 application use showMainDocumentWidget(); to create a
400 non-document-oriented application use showMainWidget(). The 400 non-document-oriented application use showMainWidget(). The
401 keepRunning() function indicates whether the application will 401 keepRunning() function indicates whether the application will
402 continue running after it's processed the last \link qcop.html 402 continue running after it's processed the last \link qcop.html
403 QCop\endlink message. This can be changed using setKeepRunning(). 403 QCop\endlink message. This can be changed using setKeepRunning().
404 404
405 A variety of signals are emitted when certain events occur, for 405 A variety of signals are emitted when certain events occur, for
406 example, timeChanged(), clockChanged(), weekChanged(), 406 example, timeChanged(), clockChanged(), weekChanged(),
407 dateFormatChanged() and volumeChanged(). If the application receives 407 dateFormatChanged() and volumeChanged(). If the application receives
408 a \link qcop.html QCop\endlink message on the application's 408 a \link qcop.html QCop\endlink message on the application's
409 QPE/Application/\e{appname} channel, the appMessage() signal is 409 QPE/Application/\e{appname} channel, the appMessage() signal is
410 emitted. There are also flush() and reload() signals, which 410 emitted. There are also flush() and reload() signals, which
411 are emitted when synching begins and ends respectively - upon these 411 are emitted when synching begins and ends respectively - upon these
412 signals, the application should save and reload any data 412 signals, the application should save and reload any data
413 files that are involved in synching. Most of these signals will initially 413 files that are involved in synching. Most of these signals will initially
414 be received and unfiltered through the appMessage() signal. 414 be received and unfiltered through the appMessage() signal.
415 415
416 This class also provides a set of useful static functions. The 416 This class also provides a set of useful static functions. The
417 qpeDir() and documentDir() functions return the respective paths. 417 qpeDir() and documentDir() functions return the respective paths.
418 The grabKeyboard() and ungrabKeyboard() functions are used to 418 The grabKeyboard() and ungrabKeyboard() functions are used to
419 control whether the application takes control of the device's 419 control whether the application takes control of the device's
420 physical buttons (e.g. application launch keys). The stylus' mode of 420 physical buttons (e.g. application launch keys). The stylus' mode of
421 operation is set with setStylusOperation() and retrieved with 421 operation is set with setStylusOperation() and retrieved with
422 stylusOperation(). There are also setInputMethodHint() and 422 stylusOperation(). There are also setInputMethodHint() and
423 inputMethodHint() functions. 423 inputMethodHint() functions.
424 424
425 \ingroup qtopiaemb 425 \ingroup qtopiaemb
426*/ 426*/
427 427
428/*! 428/*!
429 \fn void QPEApplication::clientMoused() 429 \fn void QPEApplication::clientMoused()
430 430
431 \internal 431 \internal
432*/ 432*/
433 433
434/*! 434/*!
435 \fn void QPEApplication::timeChanged(); 435 \fn void QPEApplication::timeChanged();
436 This signal is emitted when the time changes outside the normal 436 This signal is emitted when the time changes outside the normal
437 passage of time, i.e. if the time is set backwards or forwards. 437 passage of time, i.e. if the time is set backwards or forwards.
438*/ 438*/
439 439
440/*! 440/*!
441 \fn void QPEApplication::clockChanged( bool ampm ); 441 \fn void QPEApplication::clockChanged( bool ampm );
442 442
443 This signal is emitted when the user changes the clock's style. If 443 This signal is emitted when the user changes the clock's style. If
444 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 444 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
445 they want a 24-hour clock. 445 they want a 24-hour clock.
446*/ 446*/
447 447
448/*! 448/*!
449 \fn void QPEApplication::volumeChanged( bool muted ) 449 \fn void QPEApplication::volumeChanged( bool muted )
450 450
451 This signal is emitted whenever the mute state is changed. If \a 451 This signal is emitted whenever the mute state is changed. If \a
452 muted is TRUE, then sound output has been muted. 452 muted is TRUE, then sound output has been muted.
453*/ 453*/
454 454
455/*! 455/*!
456 \fn void QPEApplication::weekChanged( bool startOnMonday ) 456 \fn void QPEApplication::weekChanged( bool startOnMonday )
457 457
458 This signal is emitted if the week start day is changed. If \a 458 This signal is emitted if the week start day is changed. If \a
459 startOnMonday is TRUE then the first day of the week is Monday; if 459 startOnMonday is TRUE then the first day of the week is Monday; if
460 \a startOnMonday is FALSE then the first day of the week is 460 \a startOnMonday is FALSE then the first day of the week is
461 Sunday. 461 Sunday.
462*/ 462*/
463 463
464/*! 464/*!
465 \fn void QPEApplication::dateFormatChanged(DateFormat) 465 \fn void QPEApplication::dateFormatChanged(DateFormat)
466 466
467 This signal is emitted whenever the date format is changed. 467 This signal is emitted whenever the date format is changed.
468*/ 468*/
469 469
470/*! 470/*!
471 \fn void QPEApplication::flush() 471 \fn void QPEApplication::flush()
472 472
473 ### 473 ###
474*/ 474*/
475 475
476/*! 476/*!
477 \fn void QPEApplication::reload() 477 \fn void QPEApplication::reload()
478 478
479*/ 479*/
480 480
481/*! 481/*!
482 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 482 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
483 483
484 This signal is emitted when a message is received on this 484 This signal is emitted when a message is received on this
485 application's QPE/Application/<i>appname</i> \link qcop.html 485 application's QPE/Application/<i>appname</i> \link qcop.html
486 QCop\endlink channel. 486 QCop\endlink channel.
487 487
488 The slot to which you connect this signal uses \a msg and \a data 488 The slot to which you connect this signal uses \a msg and \a data
489 in the following way: 489 in the following way:
490 490
491\code 491\code
492 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 492 void MyWidget::receive( const QCString& msg, const QByteArray& data )
493 { 493 {
494 QDataStream stream( data, IO_ReadOnly ); 494 QDataStream stream( data, IO_ReadOnly );
495 if ( msg == "someMessage(int,int,int)" ) { 495 if ( msg == "someMessage(int,int,int)" ) {
496 int a,b,c; 496 int a,b,c;
497 stream >> a >> b >> c; 497 stream >> a >> b >> c;
498 ... 498 ...
499 } else if ( msg == "otherMessage(QString)" ) { 499 } else if ( msg == "otherMessage(QString)" ) {
500 ... 500 ...
501 } 501 }
502 } 502 }
503\endcode 503\endcode
504 504
505 \sa qcop.html 505 \sa qcop.html
506 Note that messages received here may be processed by qpe application 506 Note that messages received here may be processed by qpe application
507 and emitted as signals, such as flush() and reload(). 507 and emitted as signals, such as flush() and reload().
508*/ 508*/
509 509
510/*! 510/*!
511 Constructs a QPEApplication just as you would construct 511 Constructs a QPEApplication just as you would construct
512 a QApplication, passing \a argc, \a argv, and \a t. 512 a QApplication, passing \a argc, \a argv, and \a t.
513 513
514 For applications, \a t should be the default, GuiClient. Only 514 For applications, \a t should be the default, GuiClient. Only
515 the Qtopia server passes GuiServer. 515 the Qtopia server passes GuiServer.
516*/ 516*/
517QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 517QPEApplication::QPEApplication( int & argc, char **argv, Type t )
518 : QApplication( argc, argv, t ) 518 : QApplication( argc, argv, t )
519{ 519{
520 d = new QPEApplicationData; 520 d = new QPEApplicationData;
521 d->loadTextCodecs(); 521 d->loadTextCodecs();
522 d->loadImageCodecs(); 522 d->loadImageCodecs();
523 int dw = desktop() ->width(); 523 int dw = desktop() ->width();
524 524
525 if ( dw < 200 ) { 525 if ( dw < 200 ) {
526 setFont( QFont( "vera", 8 ) ); 526 setFont( QFont( "vera", 8 ) );
527 AppLnk::setSmallIconSize( 10 ); 527 AppLnk::setSmallIconSize( 10 );
528 AppLnk::setBigIconSize( 28 ); 528 AppLnk::setBigIconSize( 28 );
529 } 529 }
530 #ifdef QT_QWS_SHARP 530#ifdef QT_QWS_SHARP
531 else if ( dw > 600 ) { 531 else if ( dw > 600 ) {
532 setFont( QFont( "vera", 16 ) ); 532 setFont( QFont( "vera", 16 ) );
533 AppLnk::setSmallIconSize( 24 ); 533 AppLnk::setSmallIconSize( 24 );
534 AppLnk::setBigIconSize( 48 ); 534 AppLnk::setBigIconSize( 48 );
535 } 535 }
536 #endif 536#endif
537 else if ( dw > 200 ) { 537 else if ( dw > 200 ) {
538 setFont( QFont( "vera", 10 ) ); 538 setFont( QFont( "vera", 10 ) );
539 AppLnk::setSmallIconSize( 14 ); 539 AppLnk::setSmallIconSize( 14 );
540 AppLnk::setBigIconSize( 32 ); 540 AppLnk::setBigIconSize( 32 );
541 } 541 }
542 542
543 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 543 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
544 544
545 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 545 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
546#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 546#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
547 547
548 QString qcopfn( "/tmp/qcop-msg-" ); 548 QString qcopfn( "/tmp/qcop-msg-" );
549 qcopfn += QString( argv[ 0 ] ); // append command name 549 qcopfn += QString( argv[ 0 ] ); // append command name
550 550
551 QFile f( qcopfn ); 551 QFile f( qcopfn );
552 if ( f.open( IO_ReadOnly ) ) { 552 if ( f.open( IO_ReadOnly ) ) {
553 flock( f.handle(), LOCK_EX ); 553 flock( f.handle(), LOCK_EX );
554 } 554 }
555 555
556 sysChannel = new QCopChannel( "QPE/System", this ); 556 sysChannel = new QCopChannel( "QPE/System", this );
557 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 557 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
558 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); 558 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
559 559
560 QCString channel = QCString( argv[ 0 ] ); 560 QCString channel = QCString( argv[ 0 ] );
561 channel.replace( QRegExp( ".*/" ), "" ); 561 channel.replace( QRegExp( ".*/" ), "" );
562 d->appName = channel; 562 d->appName = channel;
563 channel = "QPE/Application/" + channel; 563 channel = "QPE/Application/" + channel;
564 pidChannel = new QCopChannel( channel, this ); 564 pidChannel = new QCopChannel( channel, this );
565 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 565 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
566 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) ); 566 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) );
567 567
568 if ( f.isOpen() ) { 568 if ( f.isOpen() ) {
569 d->keep_running = FALSE; 569 d->keep_running = FALSE;
570 QDataStream ds( &f ); 570 QDataStream ds( &f );
571 QCString channel, message; 571 QCString channel, message;
572 QByteArray data; 572 QByteArray data;
573 while ( !ds.atEnd() ) { 573 while ( !ds.atEnd() ) {
574 ds >> channel >> message >> data; 574 ds >> channel >> message >> data;
575 d->enqueueQCop( channel, message, data ); 575 d->enqueueQCop( channel, message, data );
576 } 576 }
577 577
578 flock( f.handle(), LOCK_UN ); 578 flock( f.handle(), LOCK_UN );
579 f.close(); 579 f.close();
580 f.remove(); 580 f.remove();
581 } 581 }
582 582
583 for ( int a = 0; a < argc; a++ ) { 583 for ( int a = 0; a < argc; a++ ) {
584 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 584 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
585 argv[ a ] = argv[ a + 1 ]; 585 argv[ a ] = argv[ a + 1 ];
586 a++; 586 a++;
587 d->preloaded = TRUE; 587 d->preloaded = TRUE;
588 argc -= 1; 588 argc -= 1;
589 } 589 }
590 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 590 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
591 argv[ a ] = argv[ a + 1 ]; 591 argv[ a ] = argv[ a + 1 ];
592 a++; 592 a++;
593 d->preloaded = TRUE; 593 d->preloaded = TRUE;
594 d->forceshow = TRUE; 594 d->forceshow = TRUE;
595 argc -= 1; 595 argc -= 1;
596 } 596 }
597 } 597 }
598 598
599 /* overide stored arguments */ 599 /* overide stored arguments */
600 setArgs( argc, argv ); 600 setArgs( argc, argv );
601 601
602#endif 602#endif
603 603
604 // qwsSetDecoration( new QPEDecoration() ); 604 // qwsSetDecoration( new QPEDecoration() );
605 605
606#ifndef QT_NO_TRANSLATION 606#ifndef QT_NO_TRANSLATION
607 607
608 QStringList langs = Global::languageList(); 608 QStringList langs = Global::languageList();
609 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { 609 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) {
610 QString lang = *it; 610 QString lang = *it;
611 611
612 installTranslation( lang + "/libopie.qm"); 612 installTranslation( lang + "/libopie.qm");
613 installTranslation( lang + "/libqpe.qm" ); 613 installTranslation( lang + "/libqpe.qm" );
614 installTranslation( lang + "/" + d->appName + ".qm" ); 614 installTranslation( lang + "/" + d->appName + ".qm" );
615 615
616 616
617 //###language/font hack; should look it up somewhere 617 //###language/font hack; should look it up somewhere
618#ifdef QWS 618#ifdef QWS
619 619
620 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 620 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
621 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 621 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
622 setFont( fn ); 622 setFont( fn );
623 } 623 }
624#endif 624#endif
625 625
626 } 626 }
627#endif 627#endif
628 628
629 applyStyle(); 629 applyStyle();
630 630
631 if ( type() == GuiServer ) { 631 if ( type() == GuiServer ) {
632 setVolume(); 632 setVolume();
633 } 633 }
634 634
635 installEventFilter( this ); 635 installEventFilter( this );
636 636
637 QPEMenuToolFocusManager::initialize(); 637 QPEMenuToolFocusManager::initialize();
638 638
639#ifdef QT_NO_QWS_CURSOR 639#ifdef QT_NO_QWS_CURSOR
640 // if we have no cursor, probably don't want tooltips 640 // if we have no cursor, probably don't want tooltips
641 QToolTip::setEnabled( FALSE ); 641 QToolTip::setEnabled( FALSE );
642#endif 642#endif
643} 643}
644 644
645static QPtrDict<void>* inputMethodDict = 0; 645static QPtrDict<void>* inputMethodDict = 0;
646static void createInputMethodDict() 646static void createInputMethodDict()
647{ 647{
648 if ( !inputMethodDict ) 648 if ( !inputMethodDict )
649 inputMethodDict = new QPtrDict<void>; 649 inputMethodDict = new QPtrDict<void>;
650} 650}
651 651
652/*! 652/*!
653 Returns the currently set hint to the system as to whether 653 Returns the currently set hint to the system as to whether
654 widget \a w has any use for text input methods. 654 widget \a w has any use for text input methods.
655 655
656 656
657 \sa setInputMethodHint() InputMethodHint 657 \sa setInputMethodHint() InputMethodHint
658*/ 658*/
659QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 659QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
660{ 660{
661 if ( inputMethodDict && w ) 661 if ( inputMethodDict && w )
662 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 662 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
663 return Normal; 663 return Normal;
664} 664}
665 665
666/*! 666/*!
667 \enum QPEApplication::InputMethodHint 667 \enum QPEApplication::InputMethodHint
668 668
669 \value Normal the application sometimes needs text input (the default). 669 \value Normal the application sometimes needs text input (the default).
670 \value AlwaysOff the application never needs text input. 670 \value AlwaysOff the application never needs text input.
671 \value AlwaysOn the application always needs text input. 671 \value AlwaysOn the application always needs text input.
672*/ 672*/
673 673
674/*! 674/*!
675 Hints to the system that widget \a w has use for text input methods 675 Hints to the system that widget \a w has use for text input methods
676 as specified by \a mode. 676 as specified by \a mode.
677 677
678 \sa inputMethodHint() InputMethodHint 678 \sa inputMethodHint() InputMethodHint
679*/ 679*/
680void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 680void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
681{ 681{
682 createInputMethodDict(); 682 createInputMethodDict();
683 if ( mode == Normal ) { 683 if ( mode == Normal ) {
684 inputMethodDict->remove 684 inputMethodDict->remove
685 ( w ); 685 ( w );
686 } 686 }
687 else { 687 else {
688 inputMethodDict->insert( w, ( void* ) mode ); 688 inputMethodDict->insert( w, ( void* ) mode );
689 } 689 }
690} 690}
691 691
692class HackDialog : public QDialog 692class HackDialog : public QDialog
693{ 693{
694public: 694public:
695 void acceptIt() 695 void acceptIt()
696 { 696 {
697 accept(); 697 accept();
698 } 698 }
699 void rejectIt() 699 void rejectIt()
700 { 700 {
701 reject(); 701 reject();
702 } 702 }
703}; 703};
704 704
705 705
706void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 706void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
707{ 707{
708 // specialised actions for certain widgets. May want to 708 // specialised actions for certain widgets. May want to
709 // add more stuff here. 709 // add more stuff here.
710 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 710 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
711 && activePopupWidget() ->parentWidget() 711 && activePopupWidget() ->parentWidget()
712 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 712 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
713 key = Qt::Key_Return; 713 key = Qt::Key_Return;
714 714
715 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 715 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
716 key = Qt::Key_Return; 716 key = Qt::Key_Return;
717 717
718#ifdef QWS 718#ifdef QWS
719 719
720 ke->simpleData.keycode = key; 720 ke->simpleData.keycode = key;
721#endif 721#endif
722} 722}
723 723
724class HackWidget : public QWidget 724class HackWidget : public QWidget
725{ 725{
726public: 726public:
727 bool needsOk() 727 bool needsOk()
728 { 728 {
@@ -1570,256 +1570,256 @@ bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1570 d->rightpressed = FALSE; 1570 d->rightpressed = FALSE;
1571 } 1571 }
1572 break; 1572 break;
1573 case QEvent::MouseMove: 1573 case QEvent::MouseMove:
1574 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 1574 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
1575 killTimer(d->presstimer); 1575 killTimer(d->presstimer);
1576 d->presstimer = 0; 1576 d->presstimer = 0;
1577 } 1577 }
1578 break; 1578 break;
1579 case QEvent::MouseButtonRelease: 1579 case QEvent::MouseButtonRelease:
1580 if ( me->button() == LeftButton ) { 1580 if ( me->button() == LeftButton ) {
1581 if ( d->presstimer ) { 1581 if ( d->presstimer ) {
1582 killTimer(d->presstimer); 1582 killTimer(d->presstimer);
1583 d->presstimer = 0; 1583 d->presstimer = 0;
1584 } 1584 }
1585 if ( d->rightpressed && d->presswidget ) { 1585 if ( d->rightpressed && d->presswidget ) {
1586 // Right released 1586 // Right released
1587 postEvent( d->presswidget, 1587 postEvent( d->presswidget,
1588 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 1588 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
1589 RightButton, LeftButton + RightButton ) ); 1589 RightButton, LeftButton + RightButton ) );
1590 // Left released, off-widget 1590 // Left released, off-widget
1591 postEvent( d->presswidget, 1591 postEvent( d->presswidget,
1592 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 1592 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
1593 LeftButton, LeftButton ) ); 1593 LeftButton, LeftButton ) );
1594 postEvent( d->presswidget, 1594 postEvent( d->presswidget,
1595 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 1595 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
1596 LeftButton, LeftButton ) ); 1596 LeftButton, LeftButton ) );
1597 d->rightpressed = FALSE; 1597 d->rightpressed = FALSE;
1598 return TRUE; // don't send the real Left release 1598 return TRUE; // don't send the real Left release
1599 } 1599 }
1600 } 1600 }
1601 break; 1601 break;
1602 default: 1602 default:
1603 break; 1603 break;
1604 } 1604 }
1605 break; 1605 break;
1606 default: 1606 default:
1607 ; 1607 ;
1608 } 1608 }
1609 } 1609 }
1610 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1610 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1611 QKeyEvent *ke = (QKeyEvent *)e; 1611 QKeyEvent *ke = (QKeyEvent *)e;
1612 if ( ke->key() == Key_Enter ) { 1612 if ( ke->key() == Key_Enter ) {
1613 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 1613 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
1614 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 1614 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
1615 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 1615 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
1616 return TRUE; 1616 return TRUE;
1617 } 1617 }
1618 } 1618 }
1619 } 1619 }
1620 return FALSE; 1620 return FALSE;
1621} 1621}
1622 1622
1623/*! 1623/*!
1624 \reimp 1624 \reimp
1625*/ 1625*/
1626void QPEApplication::timerEvent( QTimerEvent *e ) 1626void QPEApplication::timerEvent( QTimerEvent *e )
1627{ 1627{
1628 if ( e->timerId() == d->presstimer && d->presswidget ) { 1628 if ( e->timerId() == d->presstimer && d->presswidget ) {
1629 // Right pressed 1629 // Right pressed
1630 postEvent( d->presswidget, 1630 postEvent( d->presswidget,
1631 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 1631 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
1632 RightButton, LeftButton ) ); 1632 RightButton, LeftButton ) );
1633 killTimer( d->presstimer ); 1633 killTimer( d->presstimer );
1634 d->presstimer = 0; 1634 d->presstimer = 0;
1635 d->rightpressed = TRUE; 1635 d->rightpressed = TRUE;
1636 } 1636 }
1637} 1637}
1638 1638
1639void QPEApplication::removeSenderFromStylusDict() 1639void QPEApplication::removeSenderFromStylusDict()
1640{ 1640{
1641 stylusDict->remove 1641 stylusDict->remove
1642 ( ( void* ) sender() ); 1642 ( ( void* ) sender() );
1643 if ( d->presswidget == sender() ) 1643 if ( d->presswidget == sender() )
1644 d->presswidget = 0; 1644 d->presswidget = 0;
1645} 1645}
1646 1646
1647/*! 1647/*!
1648 \internal 1648 \internal
1649*/ 1649*/
1650bool QPEApplication::keyboardGrabbed() const 1650bool QPEApplication::keyboardGrabbed() const
1651{ 1651{
1652 return d->kbgrabbed; 1652 return d->kbgrabbed;
1653} 1653}
1654 1654
1655 1655
1656/*! 1656/*!
1657 Reverses the effect of grabKeyboard(). This is called automatically 1657 Reverses the effect of grabKeyboard(). This is called automatically
1658 on program exit. 1658 on program exit.
1659*/ 1659*/
1660void QPEApplication::ungrabKeyboard() 1660void QPEApplication::ungrabKeyboard()
1661{ 1661{
1662 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 1662 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
1663} 1663}
1664 1664
1665/*! 1665/*!
1666 Grabs the physical keyboard keys, e.g. the application's launching 1666 Grabs the physical keyboard keys, e.g. the application's launching
1667 keys. Instead of launching applications when these keys are pressed 1667 keys. Instead of launching applications when these keys are pressed
1668 the signals emitted are sent to this application instead. Some games 1668 the signals emitted are sent to this application instead. Some games
1669 programs take over the launch keys in this way to make interaction 1669 programs take over the launch keys in this way to make interaction
1670 easier. 1670 easier.
1671 1671
1672 \sa ungrabKeyboard() 1672 \sa ungrabKeyboard()
1673*/ 1673*/
1674void QPEApplication::grabKeyboard() 1674void QPEApplication::grabKeyboard()
1675{ 1675{
1676 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 1676 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
1677} 1677}
1678 1678
1679/*! 1679/*!
1680 \reimp 1680 \reimp
1681*/ 1681*/
1682int QPEApplication::exec() 1682int QPEApplication::exec()
1683{ 1683{
1684#ifndef QT_NO_COP 1684#ifndef QT_NO_COP
1685 d->sendQCopQ(); 1685 d->sendQCopQ();
1686#endif 1686#endif
1687 1687
1688 if ( d->keep_running ) 1688 if ( d->keep_running )
1689 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 1689 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
1690 return QApplication::exec(); 1690 return QApplication::exec();
1691 1691
1692#ifndef QT_NO_COP 1692#ifndef QT_NO_COP
1693 1693
1694 { 1694 {
1695 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1695 QCopEnvelope e( "QPE/System", "closing(QString)" );
1696 e << d->appName; 1696 e << d->appName;
1697 } 1697 }
1698#endif 1698#endif
1699 processEvents(); 1699 processEvents();
1700 return 0; 1700 return 0;
1701} 1701}
1702 1702
1703/*! 1703/*!
1704 \internal 1704 \internal
1705 External request for application to quit. Quits if possible without 1705 External request for application to quit. Quits if possible without
1706 loosing state. 1706 loosing state.
1707*/ 1707*/
1708void QPEApplication::tryQuit() 1708void QPEApplication::tryQuit()
1709{ 1709{
1710 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 1710 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
1711 return ; // Inside modal loop or konsole. Too hard to save state. 1711 return ; // Inside modal loop or konsole. Too hard to save state.
1712#ifndef QT_NO_COP 1712#ifndef QT_NO_COP
1713 1713
1714 { 1714 {
1715 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1715 QCopEnvelope e( "QPE/System", "closing(QString)" );
1716 e << d->appName; 1716 e << d->appName;
1717 } 1717 }
1718#endif 1718#endif
1719 processEvents(); 1719 processEvents();
1720 1720
1721 quit(); 1721 quit();
1722} 1722}
1723 1723
1724/*! 1724/*!
1725 \internal 1725 \internal
1726*/ 1726*/
1727void QPEApplication::installTranslation( const QString& baseName ) { 1727void QPEApplication::installTranslation( const QString& baseName ) {
1728 QTranslator* trans = new QTranslator(this); 1728 QTranslator* trans = new QTranslator(this);
1729 QString tfn = qpeDir() + "/i18n/"+baseName; 1729 QString tfn = qpeDir() + "/i18n/"+baseName;
1730 if ( trans->load( tfn ) ) 1730 if ( trans->load( tfn ) )
1731 installTranslator( trans ); 1731 installTranslator( trans );
1732 else 1732 else
1733 delete trans; 1733 delete trans;
1734} 1734}
1735 1735
1736/*! 1736/*!
1737 \internal 1737 \internal
1738 User initiated quit. Makes the window 'Go Away'. If preloaded this means 1738 User initiated quit. Makes the window 'Go Away'. If preloaded this means
1739 hiding the window. If not it means quitting the application. 1739 hiding the window. If not it means quitting the application.
1740 As this is user initiated we don't need to check state. 1740 As this is user initiated we don't need to check state.
1741*/ 1741*/
1742void QPEApplication::hideOrQuit() 1742void QPEApplication::hideOrQuit()
1743{ 1743{
1744 processEvents(); 1744 processEvents();
1745 1745
1746 // If we are a preloaded application we don't actually quit, so emit 1746 // If we are a preloaded application we don't actually quit, so emit
1747 // a System message indicating we're quasi-closing. 1747 // a System message indicating we're quasi-closing.
1748 if ( d->preloaded && d->qpe_main_widget ) 1748 if ( d->preloaded && d->qpe_main_widget )
1749#ifndef QT_NO_COP 1749#ifndef QT_NO_COP
1750 1750
1751 { 1751 {
1752 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 1752 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
1753 e << d->appName; 1753 e << d->appName;
1754 d->qpe_main_widget->hide(); 1754 d->qpe_main_widget->hide();
1755 } 1755 }
1756#endif 1756#endif
1757 else 1757 else
1758 quit(); 1758 quit();
1759} 1759}
1760 1760
1761 1761
1762#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) 1762#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) || defined(QT_QWS_RAMSES)
1763 1763
1764// The libraries with the skiff package (and possibly others) have 1764// The libraries with the skiff package (and possibly others) have
1765// completely useless implementations of builtin new and delete that 1765// completely useless implementations of builtin new and delete that
1766// use about 50% of your CPU. Here we revert to the simple libc 1766// use about 50% of your CPU. Here we revert to the simple libc
1767// functions. 1767// functions.
1768 1768
1769void* operator new[]( size_t size ) 1769void* operator new[]( size_t size )
1770{ 1770{
1771 return malloc( size ); 1771 return malloc( size );
1772} 1772}
1773 1773
1774void* operator new( size_t size ) 1774void* operator new( size_t size )
1775{ 1775{
1776 return malloc( size ); 1776 return malloc( size );
1777} 1777}
1778 1778
1779void operator delete[]( void* p ) 1779void operator delete[]( void* p )
1780{ 1780{
1781 free( p ); 1781 free( p );
1782} 1782}
1783 1783
1784void operator delete[]( void* p, size_t /*size*/ ) 1784void operator delete[]( void* p, size_t /*size*/ )
1785{ 1785{
1786 free( p ); 1786 free( p );
1787} 1787}
1788 1788
1789 1789
1790void operator delete( void* p ) 1790void operator delete( void* p )
1791{ 1791{
1792 free( p ); 1792 free( p );
1793} 1793}
1794 1794
1795void operator delete( void* p, size_t /*size*/ ) 1795void operator delete( void* p, size_t /*size*/ )
1796{ 1796{
1797 free( p ); 1797 free( p );
1798} 1798}
1799 1799
1800#endif 1800#endif
1801 1801
1802#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 1802#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
1803#include <qwidgetlist.h> 1803#include <qwidgetlist.h>
1804#ifdef QWS 1804#ifdef QWS
1805#include <qgfx_qws.h> 1805#include <qgfx_qws.h>
1806extern QRect qt_maxWindowRect; 1806extern QRect qt_maxWindowRect;
1807void qt_setMaxWindowRect(const QRect& r ) 1807void qt_setMaxWindowRect(const QRect& r )
1808{ 1808{
1809 qt_maxWindowRect = qt_screen->mapFromDevice( r, 1809 qt_maxWindowRect = qt_screen->mapFromDevice( r,
1810 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 1810 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
1811 // Re-resize any maximized windows 1811 // Re-resize any maximized windows
1812 QWidgetList* l = QApplication::topLevelWidgets(); 1812 QWidgetList* l = QApplication::topLevelWidgets();
1813 if ( l ) { 1813 if ( l ) {
1814 QWidget * w = l->first(); 1814 QWidget * w = l->first();
1815 while ( w ) { 1815 while ( w ) {
1816 if ( w->isVisible() && w->isMaximized() ) { 1816 if ( w->isVisible() && w->isMaximized() ) {
1817 w->showMaximized(); 1817 w->showMaximized();
1818 } 1818 }
1819 w = l->next(); 1819 w = l->next();
1820 } 1820 }
1821 delete l; 1821 delete l;
1822 } 1822 }
1823} 1823}
1824#endif 1824#endif
1825#endif 1825#endif
diff --git a/library/storage.cpp b/library/storage.cpp
index 12f9df9..4e07ec6 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,216 +1,216 @@
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#ifdef QT_QWS_SL5XXX 24#if defined(QT_QWS_SL5XXX)
25#include <qpe/custom.h> 25#include <qpe/custom.h>
26#endif 26#endif
27 27
28#include <qfile.h> 28#include <qfile.h>
29#include <qtimer.h> 29#include <qtimer.h>
30#include <qcopchannel_qws.h> 30#include <qcopchannel_qws.h>
31 31
32#include <stdio.h> 32#include <stdio.h>
33 33
34#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 34#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
35#include <sys/vfs.h> 35#include <sys/vfs.h>
36#include <mntent.h> 36#include <mntent.h>
37#endif 37#endif
38 38
39#include <qstringlist.h> 39#include <qstringlist.h>
40 40
41#include <sys/vfs.h> 41#include <sys/vfs.h>
42#include <mntent.h> 42#include <mntent.h>
43 43
44 44
45static bool isCF(const QString& m) 45static bool isCF(const QString& m)
46{ 46{
47 FILE* f = fopen("/var/run/stab", "r"); 47 FILE* f = fopen("/var/run/stab", "r");
48 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 48 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
49 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 49 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
50 if ( f ) { 50 if ( f ) {
51 char line[1024]; 51 char line[1024];
52 char devtype[80]; 52 char devtype[80];
53 char devname[80]; 53 char devname[80];
54 while ( fgets( line, 1024, f ) ) { 54 while ( fgets( line, 1024, f ) ) {
55 // 0 ide ide-cs 0 hda 3 0 55 // 0 ide ide-cs 0 hda 3 0
56 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 56 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
57 { 57 {
58 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 58 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
59 fclose(f); 59 fclose(f);
60 return TRUE; 60 return TRUE;
61 } 61 }
62 } 62 }
63 } 63 }
64 fclose(f); 64 fclose(f);
65 } 65 }
66 return FALSE; 66 return FALSE;
67} 67}
68 68
69StorageInfo::StorageInfo( QObject *parent ) 69StorageInfo::StorageInfo( QObject *parent )
70 : QObject( parent ) 70 : QObject( parent )
71{ 71{
72 mFileSystems.setAutoDelete( TRUE ); 72 mFileSystems.setAutoDelete( TRUE );
73 channel = new QCopChannel( "QPE/Card", this ); 73 channel = new QCopChannel( "QPE/Card", this );
74 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 74 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
75 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 75 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
76 update(); 76 update();
77} 77}
78 78
79const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 79const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
80{ 80{
81 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 81 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
82 if ( filename.startsWith( (*i)->path() ) ) 82 if ( filename.startsWith( (*i)->path() ) )
83 return (*i); 83 return (*i);
84 } 84 }
85 return 0; 85 return 0;
86} 86}
87 87
88 88
89void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 89void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
90{ 90{
91 if ( msg == "mtabChanged()" ) 91 if ( msg == "mtabChanged()" )
92 update(); 92 update();
93} 93}
94// cause of the lack of a d pointer we need 94// cause of the lack of a d pointer we need
95// to store informations in a config file :( 95// to store informations in a config file :(
96void StorageInfo::update() 96void StorageInfo::update()
97{ 97{
98 //qDebug("StorageInfo::updating"); 98 //qDebug("StorageInfo::updating");
99#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 99#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
100 struct mntent *me; 100 struct mntent *me;
101 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 101 FILE *mntfp = setmntent( "/etc/mtab", "r" );
102 102
103 QStringList curdisks; 103 QStringList curdisks;
104 QStringList curopts; 104 QStringList curopts;
105 QStringList curfs; 105 QStringList curfs;
106 bool rebuild = FALSE; 106 bool rebuild = FALSE;
107 int n=0; 107 int n=0;
108 if ( mntfp ) { 108 if ( mntfp ) {
109 while ( (me = getmntent( mntfp )) != 0 ) { 109 while ( (me = getmntent( mntfp )) != 0 ) {
110 QString fs = me->mnt_fsname; 110 QString fs = me->mnt_fsname;
111 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 111 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
112 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 112 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
113 || fs.left( 14 ) == "/dev/mmc/part1" 113 || fs.left( 14 ) == "/dev/mmc/part1"
114 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) 114 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" )
115 { 115 {
116 n++; 116 n++;
117 curdisks.append(fs); 117 curdisks.append(fs);
118 curopts.append( me->mnt_opts ); 118 curopts.append( me->mnt_opts );
119 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); 119 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
120 curfs.append( me->mnt_dir ); 120 curfs.append( me->mnt_dir );
121 bool found = FALSE; 121 bool found = FALSE;
122 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 122 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
123 if ( (*i)->disk() == fs ) { 123 if ( (*i)->disk() == fs ) {
124 found = TRUE; 124 found = TRUE;
125 break; 125 break;
126 } 126 }
127 } 127 }
128 if ( !found ) 128 if ( !found )
129 rebuild = TRUE; 129 rebuild = TRUE;
130 } 130 }
131 } 131 }
132 endmntent( mntfp ); 132 endmntent( mntfp );
133 } 133 }
134 if ( rebuild || n != (int)mFileSystems.count() ) { 134 if ( rebuild || n != (int)mFileSystems.count() ) {
135 mFileSystems.clear(); 135 mFileSystems.clear();
136 QStringList::ConstIterator it=curdisks.begin(); 136 QStringList::ConstIterator it=curdisks.begin();
137 QStringList::ConstIterator fsit=curfs.begin(); 137 QStringList::ConstIterator fsit=curfs.begin();
138 QStringList::ConstIterator optsIt=curopts.begin(); 138 QStringList::ConstIterator optsIt=curopts.begin();
139 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { 139 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) {
140 QString opts = *optsIt; 140 QString opts = *optsIt;
141 141
142 QString disk = *it; 142 QString disk = *it;
143 QString humanname; 143 QString humanname;
144 bool removable = FALSE; 144 bool removable = FALSE;
145 if ( isCF(disk) ) { 145 if ( isCF(disk) ) {
146 humanname = tr("CF Card"); 146 humanname = tr("CF Card");
147 removable = TRUE; 147 removable = TRUE;
148 } else if ( disk == "/dev/hda1" ) { 148 } else if ( disk == "/dev/hda1" ) {
149 humanname = tr("Hard Disk"); 149 humanname = tr("Hard Disk");
150 } else if ( disk.left(9) == "/dev/mmcd" ) { 150 } else if ( disk.left(9) == "/dev/mmcd" ) {
151 humanname = tr("SD Card"); 151 humanname = tr("SD Card");
152 removable = TRUE; 152 removable = TRUE;
153 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) { 153 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) {
154 humanname = tr("MMC Card"); 154 humanname = tr("MMC Card");
155 removable = TRUE; 155 removable = TRUE;
156 } else if ( disk.left(7) == "/dev/hd" ) 156 } else if ( disk.left(7) == "/dev/hd" )
157 humanname = tr("Hard Disk") + " " + disk; 157 humanname = tr("Hard Disk") + " " + disk;
158 else if ( disk.left(7) == "/dev/sd" ) 158 else if ( disk.left(7) == "/dev/sd" )
159 humanname = tr("SCSI Hard Disk") + " " + disk; 159 humanname = tr("SCSI Hard Disk") + " " + disk;
160 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs 160 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
161 humanname = tr("Internal Memory"); 161 humanname = tr("Internal Memory");
162 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 162 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
163 humanname = tr("Internal Storage"); 163 humanname = tr("Internal Storage");
164 else if ( disk.left(14) == "/dev/mtdblock/" ) 164 else if ( disk.left(14) == "/dev/mtdblock/" )
165 humanname = tr("Internal Storage") + " " + disk; 165 humanname = tr("Internal Storage") + " " + disk;
166 else if ( disk.left(13) == "/dev/mtdblock" ) 166 else if ( disk.left(13) == "/dev/mtdblock" )
167 humanname = tr("Internal Storage") + " " + disk; 167 humanname = tr("Internal Storage") + " " + disk;
168 else if ( disk.left(9) == "/dev/root" ) 168 else if ( disk.left(9) == "/dev/root" )
169 humanname = tr("Internal Storage") + " " + disk; 169 humanname = tr("Internal Storage") + " " + disk;
170 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs 170 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
171 humanname = tr("Internal Memory"); 171 humanname = tr("Internal Memory");
172 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 172 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
173 mFileSystems.append( fs ); 173 mFileSystems.append( fs );
174 } 174 }
175 emit disksChanged(); 175 emit disksChanged();
176 } else { 176 } else {
177 // just update them 177 // just update them
178 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 178 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
179 i.current()->update(); 179 i.current()->update();
180 } 180 }
181#endif 181#endif
182} 182}
183 183
184bool deviceTab( const char *device) { 184bool deviceTab( const char *device) {
185 QString name = device; 185 QString name = device;
186 bool hasDevice=false; 186 bool hasDevice=false;
187 struct mntent *me; 187 struct mntent *me;
188 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 188 FILE *mntfp = setmntent( "/etc/mtab", "r" );
189 if ( mntfp ) { 189 if ( mntfp ) {
190 while ( (me = getmntent( mntfp )) != 0 ) { 190 while ( (me = getmntent( mntfp )) != 0 ) {
191 QString deviceName = me->mnt_fsname; 191 QString deviceName = me->mnt_fsname;
192// qDebug(deviceName); 192// qDebug(deviceName);
193 if( deviceName.left(name.length()) == name) { 193 if( deviceName.left(name.length()) == name) {
194 hasDevice = true; 194 hasDevice = true;
195 } 195 }
196 } 196 }
197 } 197 }
198 endmntent( mntfp ); 198 endmntent( mntfp );
199 return hasDevice; 199 return hasDevice;
200} 200}
201 201
202/*! 202/*!
203 * @fn static bool StorageInfo::hasCf() 203 * @fn static bool StorageInfo::hasCf()
204 * @brief returns whether device has Cf mounted 204 * @brief returns whether device has Cf mounted
205 * 205 *
206 */ 206 */
207bool StorageInfo::hasCf() 207bool StorageInfo::hasCf()
208{ 208{
209 return deviceTab("/dev/hd"); 209 return deviceTab("/dev/hd");
210} 210}
211 211
212/*! 212/*!
213 * @fn static bool StorageInfo::hasSd() 213 * @fn static bool StorageInfo::hasSd()
214 * @brief returns whether device has SD mounted 214 * @brief returns whether device has SD mounted
215 * 215 *
216 */ 216 */