author | zecke <zecke> | 2004-09-21 00:21:17 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-21 00:21:17 (UTC) |
commit | ee21a12cded5c53f196a5183f39e8069a22ef835 (patch) (unidiff) | |
tree | 06141ef53b557986b5f70854f265e9460cda0962 | |
parent | 5c96d26bccfeeb34a639054bf8abe41af687d3c5 (diff) | |
download | opie-ee21a12cded5c53f196a5183f39e8069a22ef835.zip opie-ee21a12cded5c53f196a5183f39e8069a22ef835.tar.gz opie-ee21a12cded5c53f196a5183f39e8069a22ef835.tar.bz2 |
Update Opie Documentation
-rw-r--r-- | libopie2/opiecore/device/odevice.cpp | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/libopie2/opiecore/device/odevice.cpp b/libopie2/opiecore/device/odevice.cpp index 2b10034..ec861ee 100644 --- a/libopie2/opiecore/device/odevice.cpp +++ b/libopie2/opiecore/device/odevice.cpp | |||
@@ -1,794 +1,850 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_beagle.h" | 30 | #include "odevice_beagle.h" |
31 | #include "odevice_ipaq.h" | 31 | #include "odevice_ipaq.h" |
32 | #include "odevice_jornada.h" | 32 | #include "odevice_jornada.h" |
33 | #include "odevice_ramses.h" | 33 | #include "odevice_ramses.h" |
34 | #include "odevice_simpad.h" | 34 | #include "odevice_simpad.h" |
35 | #include "odevice_yopy.h" | 35 | #include "odevice_yopy.h" |
36 | #include "odevice_zaurus.h" | 36 | #include "odevice_zaurus.h" |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #include <qapplication.h> | 39 | #include <qapplication.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qwindowsystem_qws.h> | 42 | #include <qwindowsystem_qws.h> |
43 | 43 | ||
44 | /* OPIE */ | 44 | /* OPIE */ |
45 | #include <qpe/config.h> | 45 | #include <qpe/config.h> |
46 | #include <qpe/resource.h> | 46 | #include <qpe/resource.h> |
47 | #include <qpe/sound.h> | 47 | #include <qpe/sound.h> |
48 | #include <qpe/qcopenvelope_qws.h> | 48 | #include <qpe/qcopenvelope_qws.h> |
49 | #include <qpe/sound.h> | 49 | #include <qpe/sound.h> |
50 | #include <opie2/okeyfilter.h> | 50 | #include <opie2/okeyfilter.h> |
51 | 51 | ||
52 | /* STD */ | 52 | /* STD */ |
53 | #include <fcntl.h> | 53 | #include <fcntl.h> |
54 | #include <math.h> | 54 | #include <math.h> |
55 | #include <stdlib.h> | 55 | #include <stdlib.h> |
56 | #include <signal.h> | 56 | #include <signal.h> |
57 | #include <sys/ioctl.h> | 57 | #include <sys/ioctl.h> |
58 | #include <sys/time.h> | 58 | #include <sys/time.h> |
59 | #include <unistd.h> | 59 | #include <unistd.h> |
60 | #ifndef QT_NO_SOUND | 60 | #ifndef QT_NO_SOUND |
61 | #include <linux/soundcard.h> | 61 | #include <linux/soundcard.h> |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | namespace Opie { | 64 | namespace Opie { |
65 | namespace Core { | 65 | namespace Core { |
66 | 66 | ||
67 | static const char* PATH_PROC_CPUINFO = "/proc/cpuinfo"; | 67 | static const char* PATH_PROC_CPUINFO = "/proc/cpuinfo"; |
68 | 68 | ||
69 | 69 | ||
70 | /* STATIC and common implementation */ | 70 | /* STATIC and common implementation */ |
71 | /* EXPORT */ ODistribution distributions[] = { | 71 | /* EXPORT */ ODistribution distributions[] = { |
72 | { System_Familiar, "FamiliarLinux", "/etc/familiar-version" }, | 72 | { System_Familiar, "FamiliarLinux", "/etc/familiar-version" }, |
73 | { System_OpenZaurus, "OpenZaurus", "/etc/oz_version" }, | 73 | { System_OpenZaurus, "OpenZaurus", "/etc/oz_version" }, |
74 | { System_OpenEmbedded, "OpenEmbedded", "/etc/oe-version" }, | 74 | { System_OpenEmbedded, "OpenEmbedded", "/etc/oe-version" }, |
75 | { System_Unknown, "Linux", "/etc/issue" }, | 75 | { System_Unknown, "Linux", "/etc/issue" }, |
76 | }; | 76 | }; |
77 | 77 | ||
78 | 78 | ||
79 | /* EXPORT */ bool isQWS(){ | 79 | /* EXPORT */ bool isQWS(){ |
80 | return qApp ? ( qApp->type() == QApplication::GuiServer ) : false; | 80 | return qApp ? ( qApp->type() == QApplication::GuiServer ) : false; |
81 | } | 81 | } |
82 | 82 | ||
83 | /* EXPORT */ QCString makeChannel ( const char *str ){ | 83 | /* EXPORT */ QCString makeChannel ( const char *str ){ |
84 | if ( str && !::strchr ( str, '/' )) | 84 | if ( str && !::strchr ( str, '/' )) |
85 | return QCString ( "QPE/Application/" ) + str; | 85 | return QCString ( "QPE/Application/" ) + str; |
86 | else | 86 | else |
87 | return str; | 87 | return str; |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | 91 | ||
92 | /* Now the default implementation of ODevice */ | 92 | /* Now the default implementation of ODevice */ |
93 | 93 | ||
94 | struct default_button default_buttons [] = { | 94 | struct default_button default_buttons [] = { |
95 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 95 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
96 | "devicebuttons/z_calendar", | 96 | "devicebuttons/z_calendar", |
97 | "datebook", "nextView()", | 97 | "datebook", "nextView()", |
98 | "today", "raise()" }, | 98 | "today", "raise()" }, |
99 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 99 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
100 | "devicebuttons/z_contact", | 100 | "devicebuttons/z_contact", |
101 | "addressbook", "raise()", | 101 | "addressbook", "raise()", |
102 | "addressbook", "beamBusinessCard()" }, | 102 | "addressbook", "beamBusinessCard()" }, |
103 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 103 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
104 | "devicebuttons/z_home", | 104 | "devicebuttons/z_home", |
105 | "QPE/Launcher", "home()", | 105 | "QPE/Launcher", "home()", |
106 | "buttonsettings", "raise()" }, | 106 | "buttonsettings", "raise()" }, |
107 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | 107 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), |
108 | "devicebuttons/z_menu", | 108 | "devicebuttons/z_menu", |
109 | "QPE/TaskBar", "toggleMenu()", | 109 | "QPE/TaskBar", "toggleMenu()", |
110 | "QPE/TaskBar", "toggleStartMenu()" }, | 110 | "QPE/TaskBar", "toggleStartMenu()" }, |
111 | { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | 111 | { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), |
112 | "devicebuttons/z_mail", | 112 | "devicebuttons/z_mail", |
113 | "opiemail", "raise()", | 113 | "opiemail", "raise()", |
114 | "opiemail", "newMail()" }, | 114 | "opiemail", "newMail()" }, |
115 | }; | 115 | }; |
116 | 116 | ||
117 | ODevice *ODevice::inst() | 117 | ODevice *ODevice::inst() |
118 | { | 118 | { |
119 | static ODevice *dev = 0; | 119 | static ODevice *dev = 0; |
120 | 120 | ||
121 | // rewrite this to only use /proc/cpuinfo or so | 121 | // rewrite this to only use /proc/cpuinfo or so |
122 | QString cpu_info; | 122 | QString cpu_info; |
123 | 123 | ||
124 | if ( !dev ) | 124 | if ( !dev ) |
125 | { | 125 | { |
126 | QFile f( PATH_PROC_CPUINFO ); | 126 | QFile f( PATH_PROC_CPUINFO ); |
127 | if ( f.open( IO_ReadOnly ) ) | 127 | if ( f.open( IO_ReadOnly ) ) |
128 | { | 128 | { |
129 | QTextStream s( &f ); | 129 | QTextStream s( &f ); |
130 | while ( !s.atEnd() ) | 130 | while ( !s.atEnd() ) |
131 | { | 131 | { |
132 | QString line; | 132 | QString line; |
133 | line = s.readLine(); | 133 | line = s.readLine(); |
134 | if ( line.startsWith( "Hardware" ) ) | 134 | if ( line.startsWith( "Hardware" ) ) |
135 | { | 135 | { |
136 | qDebug( "ODevice() - found '%s'", (const char*) line ); | 136 | qDebug( "ODevice() - found '%s'", (const char*) line ); |
137 | cpu_info = line; | 137 | cpu_info = line; |
138 | if ( line.contains( "sharp", false ) ) dev = new Internal::Zaurus(); | 138 | if ( line.contains( "sharp", false ) ) dev = new Internal::Zaurus(); |
139 | else if ( line.contains( "ipaq", false ) ) dev = new Internal::iPAQ(); | 139 | else if ( line.contains( "ipaq", false ) ) dev = new Internal::iPAQ(); |
140 | else if ( line.contains( "simpad", false ) ) dev = new Internal::SIMpad(); | 140 | else if ( line.contains( "simpad", false ) ) dev = new Internal::SIMpad(); |
141 | else if ( line.contains( "jornada", false ) ) dev = new Internal::Jornada(); | 141 | else if ( line.contains( "jornada", false ) ) dev = new Internal::Jornada(); |
142 | else if ( line.contains( "ramses", false ) ) dev = new Internal::Ramses(); | 142 | else if ( line.contains( "ramses", false ) ) dev = new Internal::Ramses(); |
143 | else if ( line.contains( "Tradesquare.NL", false ) ) dev = new Internal::Beagle(); | 143 | else if ( line.contains( "Tradesquare.NL", false ) ) dev = new Internal::Beagle(); |
144 | else qWarning( "ODevice() - unknown hardware - using default." ); | 144 | else qWarning( "ODevice() - unknown hardware - using default." ); |
145 | break; | 145 | break; |
146 | } | 146 | } |
147 | } | 147 | } |
148 | } | 148 | } |
149 | else | 149 | else |
150 | { | 150 | { |
151 | qWarning( "ODevice() - can't open '%s' - unknown hardware - using default.", PATH_PROC_CPUINFO ); | 151 | qWarning( "ODevice() - can't open '%s' - unknown hardware - using default.", PATH_PROC_CPUINFO ); |
152 | } | 152 | } |
153 | if ( !dev ) dev = new ODevice(); | 153 | if ( !dev ) dev = new ODevice(); |
154 | dev->init(cpu_info); | 154 | dev->init(cpu_info); |
155 | } | 155 | } |
156 | return dev; | 156 | return dev; |
157 | } | 157 | } |
158 | 158 | ||
159 | ODevice::ODevice() | 159 | ODevice::ODevice() |
160 | { | 160 | { |
161 | d = new ODeviceData; | 161 | d = new ODeviceData; |
162 | 162 | ||
163 | d->m_modelstr = "Unknown"; | 163 | d->m_modelstr = "Unknown"; |
164 | d->m_model = Model_Unknown; | 164 | d->m_model = Model_Unknown; |
165 | d->m_vendorstr = "Unknown"; | 165 | d->m_vendorstr = "Unknown"; |
166 | d->m_vendor = Vendor_Unknown; | 166 | d->m_vendor = Vendor_Unknown; |
167 | d->m_systemstr = "Unknown"; | 167 | d->m_systemstr = "Unknown"; |
168 | d->m_system = System_Unknown; | 168 | d->m_system = System_Unknown; |
169 | d->m_sysverstr = "0.0"; | 169 | d->m_sysverstr = "0.0"; |
170 | d->m_rotation = Rot0; | 170 | d->m_rotation = Rot0; |
171 | d->m_direction = CW; | 171 | d->m_direction = CW; |
172 | 172 | ||
173 | d->m_holdtime = 1000; // 1000ms | 173 | d->m_holdtime = 1000; // 1000ms |
174 | d->m_buttons = 0; | 174 | d->m_buttons = 0; |
175 | d->m_cpu_frequencies = new QStrList; | 175 | d->m_cpu_frequencies = new QStrList; |
176 | 176 | ||
177 | 177 | ||
178 | /* mixer */ | 178 | /* mixer */ |
179 | d->m_sound = d->m_vol = d->m_mixer = -1; | 179 | d->m_sound = d->m_vol = d->m_mixer = -1; |
180 | 180 | ||
181 | // New distribution detection code first checks for legacy distributions, | 181 | // New distribution detection code first checks for legacy distributions, |
182 | // identified by /etc/familiar-version or /etc/oz_version. | 182 | // identified by /etc/familiar-version or /etc/oz_version. |
183 | // Then check for OpenEmbedded and lastly, read /etc/issue | 183 | // Then check for OpenEmbedded and lastly, read /etc/issue |
184 | 184 | ||
185 | for ( unsigned int i = 0; i < sizeof distributions; ++i ) | 185 | for ( unsigned int i = 0; i < sizeof distributions; ++i ) |
186 | { | 186 | { |
187 | if ( QFile::exists( distributions[i].sysvfile ) ) | 187 | if ( QFile::exists( distributions[i].sysvfile ) ) |
188 | { | 188 | { |
189 | d->m_systemstr = distributions[i].sysstr; | 189 | d->m_systemstr = distributions[i].sysstr; |
190 | d->m_system = distributions[i].system; | 190 | d->m_system = distributions[i].system; |
191 | d->m_sysverstr = "<Unknown>"; | 191 | d->m_sysverstr = "<Unknown>"; |
192 | QFile f( distributions[i].sysvfile ); | 192 | QFile f( distributions[i].sysvfile ); |
193 | if ( f.open( IO_ReadOnly ) ) | 193 | if ( f.open( IO_ReadOnly ) ) |
194 | { | 194 | { |
195 | QTextStream ts( &f ); | 195 | QTextStream ts( &f ); |
196 | d->m_sysverstr = ts.readLine().replace( QRegExp( "\\\\." ), "" ); | 196 | d->m_sysverstr = ts.readLine().replace( QRegExp( "\\\\." ), "" ); |
197 | } | 197 | } |
198 | break; | 198 | break; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | } | 201 | } |
202 | 202 | ||
203 | void ODevice::systemMessage( const QCString &msg, const QByteArray & ) | 203 | void ODevice::systemMessage( const QCString &msg, const QByteArray & ) |
204 | { | 204 | { |
205 | if ( msg == "deviceButtonMappingChanged()" ) { | 205 | if ( msg == "deviceButtonMappingChanged()" ) { |
206 | reloadButtonMapping(); | 206 | reloadButtonMapping(); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | void ODevice::init(const QString&) | 210 | void ODevice::init(const QString&) |
211 | { | 211 | { |
212 | } | 212 | } |
213 | 213 | ||
214 | /** | 214 | /** |
215 | * This method initialises the button mapping | 215 | * This method initialises the button mapping |
216 | */ | 216 | */ |
217 | void ODevice::initButtons() | 217 | void ODevice::initButtons() |
218 | { | 218 | { |
219 | if ( d->m_buttons ) | 219 | if ( d->m_buttons ) |
220 | return; | 220 | return; |
221 | 221 | ||
222 | qDebug ( "init Buttons" ); | 222 | qDebug ( "init Buttons" ); |
223 | d->m_buttons = new QValueList <ODeviceButton>; | 223 | d->m_buttons = new QValueList <ODeviceButton>; |
224 | for ( uint i = 0; i < ( sizeof( default_buttons ) / sizeof( default_button )); i++ ) { | 224 | for ( uint i = 0; i < ( sizeof( default_buttons ) / sizeof( default_button )); i++ ) { |
225 | default_button *db = default_buttons + i; | 225 | default_button *db = default_buttons + i; |
226 | ODeviceButton b; | 226 | ODeviceButton b; |
227 | b. setKeycode ( db->code ); | 227 | b. setKeycode ( db->code ); |
228 | b. setUserText ( QObject::tr ( "Button", db->utext )); | 228 | b. setUserText ( QObject::tr ( "Button", db->utext )); |
229 | b. setPixmap ( Resource::loadPixmap ( db->pix )); | 229 | b. setPixmap ( Resource::loadPixmap ( db->pix )); |
230 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( db->fpressedservice ), db->fpressedaction )); | 230 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( db->fpressedservice ), db->fpressedaction )); |
231 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( db->fheldservice ), db->fheldaction )); | 231 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( db->fheldservice ), db->fheldaction )); |
232 | d->m_buttons->append ( b ); | 232 | d->m_buttons->append ( b ); |
233 | } | 233 | } |
234 | 234 | ||
235 | reloadButtonMapping(); | 235 | reloadButtonMapping(); |
236 | 236 | ||
237 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 237 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
238 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | 238 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); |
239 | } | 239 | } |
240 | 240 | ||
241 | ODevice::~ODevice() | 241 | ODevice::~ODevice() |
242 | { | 242 | { |
243 | // we leak m_devicebuttons and m_cpu_frequency | 243 | // we leak m_devicebuttons and m_cpu_frequency |
244 | // but it's a singleton and it is not so importantant | 244 | // but it's a singleton and it is not so importantant |
245 | // -zecke | 245 | // -zecke |
246 | delete d; | 246 | delete d; |
247 | } | 247 | } |
248 | 248 | ||
249 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) | 249 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
250 | { | 250 | { |
251 | return false; | 251 | return false; |
252 | } | 252 | } |
253 | 253 | ||
254 | //#include <linux/apm_bios.h> | 254 | //#include <linux/apm_bios.h> |
255 | 255 | ||
256 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) | 256 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) |
257 | 257 | ||
258 | /** | 258 | /** |
259 | * This method will try to suspend the device | 259 | * This method will try to suspend the device |
260 | * It only works if the user is the QWS Server and the apm application | 260 | * It only works if the user is the QWS Server and the apm application |
261 | * is installed. | 261 | * is installed. |
262 | * It tries to suspend and then waits some time cause some distributions | 262 | * It tries to suspend and then waits some time cause some distributions |
263 | * do have asynchronus apm implementations. | 263 | * do have asynchronus apm implementations. |
264 | * This method will either fail and return false or it'll suspend the | 264 | * This method will either fail and return false or it'll suspend the |
265 | * device and return once the device got woken up | 265 | * device and return once the device got woken up |
266 | * | 266 | * |
267 | * @return if the device got suspended | 267 | * @return if the device got suspended |
268 | */ | 268 | */ |
269 | bool ODevice::suspend() | 269 | bool ODevice::suspend() |
270 | { | 270 | { |
271 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | 271 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend |
272 | return false; | 272 | return false; |
273 | 273 | ||
274 | if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | 274 | if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices |
275 | return false; | 275 | return false; |
276 | 276 | ||
277 | bool res = false; | 277 | bool res = false; |
278 | ODevice::sendSuspendmsg(); | 278 | ODevice::sendSuspendmsg(); |
279 | 279 | ||
280 | struct timeval tvs, tvn; | 280 | struct timeval tvs, tvn; |
281 | ::gettimeofday ( &tvs, 0 ); | 281 | ::gettimeofday ( &tvs, 0 ); |
282 | 282 | ||
283 | ::sync(); // flush fs caches | 283 | ::sync(); // flush fs caches |
284 | res = ( ::system ( "apm --suspend" ) == 0 ); | 284 | res = ( ::system ( "apm --suspend" ) == 0 ); |
285 | 285 | ||
286 | // This is needed because the iPAQ apm implementation is asynchronous and we | 286 | // This is needed because the iPAQ apm implementation is asynchronous and we |
287 | // can not be sure when exactly the device is really suspended | 287 | // can not be sure when exactly the device is really suspended |
288 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. | 288 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. |
289 | 289 | ||
290 | if ( res ) { | 290 | if ( res ) { |
291 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed | 291 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed |
292 | ::usleep ( 200 * 1000 ); | 292 | ::usleep ( 200 * 1000 ); |
293 | ::gettimeofday ( &tvn, 0 ); | 293 | ::gettimeofday ( &tvn, 0 ); |
294 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | 294 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); |
295 | } | 295 | } |
296 | 296 | ||
297 | return res; | 297 | return res; |
298 | } | 298 | } |
299 | 299 | ||
300 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... | 300 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... |
301 | 301 | ||
302 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 | 302 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 |
303 | 303 | ||
304 | /* VESA Blanking Levels */ | 304 | /* VESA Blanking Levels */ |
305 | #define VESA_NO_BLANKING 0 | 305 | #define VESA_NO_BLANKING 0 |
306 | #define VESA_VSYNC_SUSPEND 1 | 306 | #define VESA_VSYNC_SUSPEND 1 |
307 | #define VESA_HSYNC_SUSPEND 2 | 307 | #define VESA_HSYNC_SUSPEND 2 |
308 | #define VESA_POWERDOWN 3 | 308 | #define VESA_POWERDOWN 3 |
309 | 309 | ||
310 | /** | 310 | /** |
311 | * This sets the display on or off | 311 | * This sets the display on or off |
312 | */ | 312 | */ |
313 | bool ODevice::setDisplayStatus ( bool on ) | 313 | bool ODevice::setDisplayStatus ( bool on ) |
314 | { | 314 | { |
315 | qDebug("ODevice::setDisplayStatus(%d)", on); | 315 | qDebug("ODevice::setDisplayStatus(%d)", on); |
316 | 316 | ||
317 | if ( d->m_model == Model_Unknown ) | 317 | if ( d->m_model == Model_Unknown ) |
318 | return false; | 318 | return false; |
319 | 319 | ||
320 | bool res = false; | 320 | bool res = false; |
321 | int fd; | 321 | int fd; |
322 | 322 | ||
323 | #ifdef QT_QWS_DEVFS | 323 | #ifdef QT_QWS_DEVFS |
324 | if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) { | 324 | if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) { |
325 | #else | 325 | #else |
326 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { | 326 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { |
327 | #endif | 327 | #endif |
328 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); | 328 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); |
329 | ::close ( fd ); | 329 | ::close ( fd ); |
330 | } | 330 | } |
331 | return res; | 331 | return res; |
332 | } | 332 | } |
333 | 333 | ||
334 | /** | 334 | /** |
335 | * This sets the display brightness | 335 | * This sets the display brightness |
336 | * | 336 | * |
337 | * @param p The brightness to be set on a scale from 0 to 255 | 337 | * @param p The brightness to be set on a scale from 0 to 255 |
338 | * @return success or failure | 338 | * @return success or failure |
339 | */ | 339 | */ |
340 | bool ODevice::setDisplayBrightness ( int p) | 340 | bool ODevice::setDisplayBrightness ( int p) |
341 | { | 341 | { |
342 | Q_UNUSED( p ) | 342 | Q_UNUSED( p ) |
343 | return false; | 343 | return false; |
344 | } | 344 | } |
345 | 345 | ||
346 | /** | 346 | /** |
347 | * @return returns the number of steppings on the brightness slider | 347 | * |
348 | * in the Light-'n-Power settings. | 348 | * @return Returns the number of steppings on the brightness slider |
349 | */ | 349 | * in the Light-'n-Power settings. Values smaller zero and bigger |
350 | * than 255 do not make sense. | ||
351 | * | ||
352 | * \sa QSlider::setLineStep | ||
353 | * \sa QSlider::setPageStep | ||
354 | */ | ||
350 | int ODevice::displayBrightnessResolution() const | 355 | int ODevice::displayBrightnessResolution() const |
351 | { | 356 | { |
352 | return 16; | 357 | return 16; |
353 | } | 358 | } |
354 | 359 | ||
355 | /** | 360 | /** |
356 | * This sets the display contrast | 361 | * This sets the display contrast |
357 | * @param p The contrast to be set on a scale from 0 to 255 | 362 | * @param p The contrast to be set on a scale from 0 to 255 |
358 | * @return success or failure | 363 | * @return success or failure |
359 | */ | 364 | */ |
360 | bool ODevice::setDisplayContrast ( int p) | 365 | bool ODevice::setDisplayContrast ( int p) |
361 | { | 366 | { |
362 | Q_UNUSED( p ) | 367 | Q_UNUSED( p ) |
363 | return false; | 368 | return false; |
364 | } | 369 | } |
365 | 370 | ||
366 | /** | 371 | /** |
367 | * @return return the max value for the brightness settings slider | 372 | * @return return the max value for the brightness settings slider |
368 | * or 0 if the device doesn't support setting of a contrast | 373 | * or 0 if the device doesn't support setting of a contrast |
369 | */ | 374 | */ |
370 | int ODevice::displayContrastResolution() const | 375 | int ODevice::displayContrastResolution() const |
371 | { | 376 | { |
372 | return 0; | 377 | return 0; |
373 | } | 378 | } |
374 | 379 | ||
375 | /** | 380 | /** |
376 | * This returns the vendor as string | 381 | * This returns the vendor as string |
377 | * @return Vendor as QString | 382 | * @return Vendor as QString |
378 | */ | 383 | */ |
379 | QString ODevice::vendorString() const | 384 | QString ODevice::vendorString() const |
380 | { | 385 | { |
381 | return d->m_vendorstr; | 386 | return d->m_vendorstr; |
382 | } | 387 | } |
383 | 388 | ||
384 | /** | 389 | /** |
385 | * This returns the vendor as one of the values of OVendor | 390 | * This returns the vendor as one of the values of OVendor |
386 | * @return OVendor | 391 | * @return OVendor |
387 | */ | 392 | */ |
388 | OVendor ODevice::vendor() const | 393 | OVendor ODevice::vendor() const |
389 | { | 394 | { |
390 | return d->m_vendor; | 395 | return d->m_vendor; |
391 | } | 396 | } |
392 | 397 | ||
393 | /** | 398 | /** |
394 | * This returns the model as a string | 399 | * This returns the model as a string |
395 | * @return A string representing the model | 400 | * @return A string representing the model |
396 | */ | 401 | */ |
397 | QString ODevice::modelString() const | 402 | QString ODevice::modelString() const |
398 | { | 403 | { |
399 | return d->m_modelstr; | 404 | return d->m_modelstr; |
400 | } | 405 | } |
401 | 406 | ||
402 | /** | 407 | /** |
403 | * This does return the OModel used | 408 | * This does return the OModel used |
404 | */ | 409 | */ |
405 | OModel ODevice::model() const | 410 | OModel ODevice::model() const |
406 | { | 411 | { |
407 | return d->m_model; | 412 | return d->m_model; |
408 | } | 413 | } |
409 | 414 | ||
410 | /** | 415 | /** |
411 | * This does return the systen name | 416 | * This does return the systen name |
412 | */ | 417 | */ |
413 | QString ODevice::systemString() const | 418 | QString ODevice::systemString() const |
414 | { | 419 | { |
415 | return d->m_systemstr; | 420 | return d->m_systemstr; |
416 | } | 421 | } |
417 | 422 | ||
418 | /** | 423 | /** |
419 | * Return System as OSystem value | 424 | * Return System as OSystem value |
420 | */ | 425 | */ |
421 | OSystem ODevice::system() const | 426 | OSystem ODevice::system() const |
422 | { | 427 | { |
423 | return d->m_system; | 428 | return d->m_system; |
424 | } | 429 | } |
425 | 430 | ||
426 | /** | 431 | /** |
427 | * @return the version string of the base system | 432 | * @return the version string of the base system |
428 | */ | 433 | */ |
429 | QString ODevice::systemVersionString() const | 434 | QString ODevice::systemVersionString() const |
430 | { | 435 | { |
431 | return d->m_sysverstr; | 436 | return d->m_sysverstr; |
432 | } | 437 | } |
433 | 438 | ||
434 | /** | 439 | /** |
435 | * @return the current Transformation | 440 | * @return the current Transformation |
436 | */ | 441 | */ |
437 | Transformation ODevice::rotation() const | 442 | Transformation ODevice::rotation() const |
438 | { | 443 | { |
439 | return d->m_rotation; | 444 | return d->m_rotation; |
440 | } | 445 | } |
441 | 446 | ||
442 | /** | 447 | /** |
443 | * @return the current rotation direction | 448 | * @return the current rotation direction |
444 | */ | 449 | */ |
445 | ODirection ODevice::direction() const | 450 | ODirection ODevice::direction() const |
446 | { | 451 | { |
447 | return d->m_direction; | 452 | return d->m_direction; |
448 | } | 453 | } |
449 | 454 | ||
450 | /** | 455 | /** |
451 | * This plays an alarm sound | 456 | * This plays an alarm sound |
452 | */ | 457 | */ |
453 | void ODevice::playAlarmSound() | 458 | void ODevice::playAlarmSound() |
454 | { | 459 | { |
455 | #ifndef QT_NO_SOUND | 460 | #ifndef QT_NO_SOUND |
456 | static Sound snd ( "alarm" ); | 461 | static Sound snd ( "alarm" ); |
457 | 462 | ||
458 | if ( snd. isFinished()) | 463 | if ( snd. isFinished()) |
459 | snd. play(); | 464 | snd. play(); |
460 | #endif | 465 | #endif |
461 | } | 466 | } |
462 | 467 | ||
463 | /** | 468 | /** |
464 | * This plays a key sound | 469 | * This plays a key sound |
465 | */ | 470 | */ |
466 | void ODevice::playKeySound() | 471 | void ODevice::playKeySound() |
467 | { | 472 | { |
468 | #ifndef QT_NO_SOUND | 473 | #ifndef QT_NO_SOUND |
469 | static Sound snd ( "keysound" ); | 474 | static Sound snd ( "keysound" ); |
470 | 475 | ||
471 | if ( snd. isFinished()) | 476 | if ( snd. isFinished()) |
472 | snd. play(); | 477 | snd. play(); |
473 | #endif | 478 | #endif |
474 | } | 479 | } |
475 | 480 | ||
476 | /** | 481 | /** |
477 | * This plays a touch sound | 482 | * This plays a touch sound |
478 | */ | 483 | */ |
479 | void ODevice::playTouchSound() | 484 | void ODevice::playTouchSound() |
480 | { | 485 | { |
481 | #ifndef QT_NO_SOUND | 486 | #ifndef QT_NO_SOUND |
482 | static Sound snd ( "touchsound" ); | 487 | static Sound snd ( "touchsound" ); |
483 | 488 | ||
484 | if ( snd. isFinished()) | 489 | if ( snd. isFinished()) |
485 | snd. play(); | 490 | snd. play(); |
486 | #endif | 491 | #endif |
487 | } | 492 | } |
488 | 493 | ||
489 | /** | 494 | /** |
490 | * This method will return a list of leds | 495 | * This method will return a list of leds |
491 | * available on this device | 496 | * available on this device |
492 | * @return a list of LEDs. | 497 | * @return a list of LEDs. |
493 | */ | 498 | */ |
494 | QValueList <OLed> ODevice::ledList() const | 499 | QValueList <OLed> ODevice::ledList() const |
495 | { | 500 | { |
496 | return QValueList <OLed>(); | 501 | return QValueList <OLed>(); |
497 | } | 502 | } |
498 | 503 | ||
499 | /** | 504 | /** |
500 | * This does return the state of the LEDs | 505 | * This does return the state of the LEDs |
501 | */ | 506 | */ |
502 | QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const | 507 | QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const |
503 | { | 508 | { |
504 | return QValueList <OLedState>(); | 509 | return QValueList <OLedState>(); |
505 | } | 510 | } |
506 | 511 | ||
507 | /** | 512 | /** |
508 | * @return the state for a given OLed | 513 | * @return the state for a given OLed |
509 | */ | 514 | */ |
510 | OLedState ODevice::ledState ( OLed /*which*/ ) const | 515 | OLedState ODevice::ledState ( OLed /*which*/ ) const |
511 | { | 516 | { |
512 | return Led_Off; | 517 | return Led_Off; |
513 | } | 518 | } |
514 | 519 | ||
515 | /** | 520 | /** |
516 | * Set the state for a LED | 521 | * Set the state for a LED |
517 | * @param which Which OLed to use | 522 | * @param which Which OLed to use |
518 | * @param st The state to set | 523 | * @param st The state to set |
519 | * @return success or failure | 524 | * @return success or failure |
520 | */ | 525 | */ |
521 | bool ODevice::setLedState ( OLed which, OLedState st ) | 526 | bool ODevice::setLedState ( OLed which, OLedState st ) |
522 | { | 527 | { |
523 | Q_UNUSED( which ) | 528 | Q_UNUSED( which ) |
524 | Q_UNUSED( st ) | 529 | Q_UNUSED( st ) |
525 | return false; | 530 | return false; |
526 | } | 531 | } |
527 | 532 | ||
528 | /** | 533 | /** |
529 | * @return if the device has a light sensor | 534 | * @return if the device has a light sensor |
530 | */ | 535 | */ |
531 | bool ODevice::hasLightSensor() const | 536 | bool ODevice::hasLightSensor() const |
532 | { | 537 | { |
533 | return false; | 538 | return false; |
534 | } | 539 | } |
535 | 540 | ||
536 | /** | 541 | /** |
537 | * @return a value from the light sensor | 542 | * @return a value from the light sensor |
538 | */ | 543 | */ |
539 | int ODevice::readLightSensor() | 544 | int ODevice::readLightSensor() |
540 | { | 545 | { |
541 | return -1; | 546 | return -1; |
542 | } | 547 | } |
543 | 548 | ||
544 | /** | 549 | /** |
545 | * @return the light sensor resolution | 550 | * @return the light sensor resolution |
546 | */ | 551 | */ |
547 | int ODevice::lightSensorResolution() const | 552 | int ODevice::lightSensorResolution() const |
548 | { | 553 | { |
549 | return 0; | 554 | return 0; |
550 | } | 555 | } |
551 | 556 | ||
552 | /** | 557 | /** |
553 | * @return if the device has a hinge sensor | 558 | * @return if the device has a hinge sensor |
554 | */ | 559 | */ |
555 | bool ODevice::hasHingeSensor() const | 560 | bool ODevice::hasHingeSensor() const |
556 | { | 561 | { |
557 | return false; | 562 | return false; |
558 | } | 563 | } |
559 | 564 | ||
560 | /** | 565 | /** |
561 | * @return a value from the hinge sensor | 566 | * @return a value from the hinge sensor |
562 | */ | 567 | */ |
563 | OHingeStatus ODevice::readHingeSensor() | 568 | OHingeStatus ODevice::readHingeSensor() |
564 | { | 569 | { |
565 | return CASE_UNKNOWN; | 570 | return CASE_UNKNOWN; |
566 | } | 571 | } |
567 | 572 | ||
568 | /** | 573 | /** |
569 | * @return a list with CPU frequencies supported by the hardware | 574 | * @return a list with CPU frequencies supported by the hardware |
570 | */ | 575 | */ |
571 | const QStrList &ODevice::allowedCpuFrequencies() const | 576 | const QStrList &ODevice::allowedCpuFrequencies() const |
572 | { | 577 | { |
573 | return *d->m_cpu_frequencies; | 578 | return *d->m_cpu_frequencies; |
574 | } | 579 | } |
575 | 580 | ||
576 | 581 | ||
577 | /** | 582 | /** |
578 | * Set desired CPU frequency | 583 | * Set desired CPU frequency |
579 | * | 584 | * |
580 | * @param index index into d->m_cpu_frequencies of the frequency to be set | 585 | * @param index index into d->m_cpu_frequencies of the frequency to be set |
581 | */ | 586 | */ |
582 | bool ODevice::setCurrentCpuFrequency(uint index) | 587 | bool ODevice::setCurrentCpuFrequency(uint index) |
583 | { | 588 | { |
584 | if (index >= d->m_cpu_frequencies->count()) | 589 | if (index >= d->m_cpu_frequencies->count()) |
585 | return false; | 590 | return false; |
586 | 591 | ||
587 | char *freq = d->m_cpu_frequencies->at(index); | 592 | char *freq = d->m_cpu_frequencies->at(index); |
588 | qWarning("set freq to %s", freq); | 593 | qWarning("set freq to %s", freq); |
589 | 594 | ||
590 | int fd; | 595 | int fd; |
591 | 596 | ||
592 | if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { | 597 | if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { |
593 | char writeCommand[50]; | 598 | char writeCommand[50]; |
594 | const int count = sprintf(writeCommand, "%s\n", freq); | 599 | const int count = sprintf(writeCommand, "%s\n", freq); |
595 | int res = (::write(fd, writeCommand, count) != -1); | 600 | int res = (::write(fd, writeCommand, count) != -1); |
596 | ::close(fd); | 601 | ::close(fd); |
597 | return res; | 602 | return res; |
598 | } | 603 | } |
599 | 604 | ||
600 | return false; | 605 | return false; |
601 | } | 606 | } |
602 | 607 | ||
603 | 608 | ||
604 | /** | 609 | /** |
605 | * @return a list of hardware buttons | 610 | * @return a list of hardware buttons |
606 | */ | 611 | */ |
607 | const QValueList <ODeviceButton> &ODevice::buttons() | 612 | const QValueList <ODeviceButton> &ODevice::buttons() |
608 | { | 613 | { |
609 | initButtons(); | 614 | initButtons(); |
610 | 615 | ||
611 | return *d->m_buttons; | 616 | return *d->m_buttons; |
612 | } | 617 | } |
613 | 618 | ||
614 | /** | 619 | /** |
615 | * @return The amount of time that would count as a hold | 620 | * @return The amount of time that would count as a hold |
616 | */ | 621 | */ |
617 | uint ODevice::buttonHoldTime() const | 622 | uint ODevice::buttonHoldTime() const |
618 | { | 623 | { |
619 | return d->m_holdtime; | 624 | return d->m_holdtime; |
620 | } | 625 | } |
621 | 626 | ||
622 | /** | 627 | /** |
623 | * This method return a ODeviceButton for a key code | 628 | * This method return a ODeviceButton for a key code |
624 | * or 0 if no special hardware button is available for the device | 629 | * or 0 if no special hardware button is available for the device |
625 | * | 630 | * |
626 | * @return The devicebutton or 0l | 631 | * @return The devicebutton or 0l |
627 | * @see ODeviceButton | 632 | * @see ODeviceButton |
628 | */ | 633 | */ |
629 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) | 634 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) |
630 | { | 635 | { |
631 | initButtons(); | 636 | initButtons(); |
632 | 637 | ||
633 | for ( QValueListConstIterator<ODeviceButton> it = d->m_buttons->begin(); it != d->m_buttons->end(); ++it ) { | 638 | for ( QValueListConstIterator<ODeviceButton> it = d->m_buttons->begin(); it != d->m_buttons->end(); ++it ) { |
634 | if ( (*it). keycode() == code ) | 639 | if ( (*it). keycode() == code ) |
635 | return &(*it); | 640 | return &(*it); |
636 | } | 641 | } |
637 | return 0; | 642 | return 0; |
638 | } | 643 | } |
639 | 644 | ||
640 | void ODevice::reloadButtonMapping() | 645 | void ODevice::reloadButtonMapping() |
641 | { | 646 | { |
642 | initButtons(); | 647 | initButtons(); |
643 | 648 | ||
644 | Config cfg ( "ButtonSettings" ); | 649 | Config cfg ( "ButtonSettings" ); |
645 | 650 | ||
646 | for ( uint i = 0; i < d->m_buttons->count(); i++ ) { | 651 | for ( uint i = 0; i < d->m_buttons->count(); i++ ) { |
647 | ODeviceButton &b = ( *d->m_buttons ) [i]; | 652 | ODeviceButton &b = ( *d->m_buttons ) [i]; |
648 | QString group = "Button" + QString::number ( i ); | 653 | QString group = "Button" + QString::number ( i ); |
649 | 654 | ||
650 | QCString pch, hch; | 655 | QCString pch, hch; |
651 | QCString pm, hm; | 656 | QCString pm, hm; |
652 | QByteArray pdata, hdata; | 657 | QByteArray pdata, hdata; |
653 | 658 | ||
654 | if ( cfg. hasGroup ( group )) { | 659 | if ( cfg. hasGroup ( group )) { |
655 | cfg. setGroup ( group ); | 660 | cfg. setGroup ( group ); |
656 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1(); | 661 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1(); |
657 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1(); | 662 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1(); |
658 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); | 663 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); |
659 | 664 | ||
660 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1(); | 665 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1(); |
661 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1(); | 666 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1(); |
662 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); | 667 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); |
663 | } | 668 | } |
664 | 669 | ||
665 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); | 670 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); |
666 | 671 | ||
667 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); | 672 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); |
668 | } | 673 | } |
669 | } | 674 | } |
670 | 675 | ||
671 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) | 676 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) |
672 | { | 677 | { |
673 | initButtons(); | 678 | initButtons(); |
674 | 679 | ||
675 | QString mb_chan; | 680 | QString mb_chan; |
676 | 681 | ||
677 | if ( button >= (int) d->m_buttons->count()) | 682 | if ( button >= (int) d->m_buttons->count()) |
678 | return; | 683 | return; |
679 | 684 | ||
680 | ODeviceButton &b = ( *d->m_buttons ) [button]; | 685 | ODeviceButton &b = ( *d->m_buttons ) [button]; |
681 | b. setPressedAction ( action ); | 686 | b. setPressedAction ( action ); |
682 | 687 | ||
683 | mb_chan=b. pressedAction(). channel(); | 688 | mb_chan=b. pressedAction(). channel(); |
684 | 689 | ||
685 | Config buttonFile ( "ButtonSettings" ); | 690 | Config buttonFile ( "ButtonSettings" ); |
686 | buttonFile. setGroup ( "Button" + QString::number ( button )); | 691 | buttonFile. setGroup ( "Button" + QString::number ( button )); |
687 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); | 692 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); |
688 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction(). message()); | 693 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction(). message()); |
689 | 694 | ||
690 | // buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction(). data())); | 695 | // buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction(). data())); |
691 | 696 | ||
692 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | 697 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); |
693 | } | 698 | } |
694 | 699 | ||
695 | void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) | 700 | void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) |
696 | { | 701 | { |
697 | initButtons(); | 702 | initButtons(); |
698 | 703 | ||
699 | if ( button >= (int) d->m_buttons->count()) | 704 | if ( button >= (int) d->m_buttons->count()) |
700 | return; | 705 | return; |
701 | 706 | ||
702 | ODeviceButton &b = ( *d->m_buttons ) [button]; | 707 | ODeviceButton &b = ( *d->m_buttons ) [button]; |
703 | b. setHeldAction ( action ); | 708 | b. setHeldAction ( action ); |
704 | 709 | ||
705 | Config buttonFile ( "ButtonSettings" ); | 710 | Config buttonFile ( "ButtonSettings" ); |
706 | buttonFile. setGroup ( "Button" + QString::number ( button )); | 711 | buttonFile. setGroup ( "Button" + QString::number ( button )); |
707 | buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel()); | 712 | buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel()); |
708 | buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message()); | 713 | buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message()); |
709 | 714 | ||
710 | // buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data())); | 715 | // buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data())); |
711 | 716 | ||
712 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | 717 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); |
713 | } | 718 | } |
719 | |||
720 | /** | ||
721 | * @internal | ||
722 | */ | ||
714 | void ODevice::virtual_hook(int, void* ){ | 723 | void ODevice::virtual_hook(int, void* ){ |
715 | 724 | ||
716 | } | 725 | } |
717 | 726 | ||
718 | /** | 727 | /** |
728 | * \brief Send a QCOP Message before suspending | ||
729 | * | ||
719 | * Sends a QCOP message to channel QPE/System | 730 | * Sends a QCOP message to channel QPE/System |
720 | * with the message "aboutToSuspend()" if this | 731 | * with the message "aboutToSuspend()" if this |
721 | * is the windowing server | 732 | * is the windowing server. |
733 | * | ||
734 | * Call this in your custom \sa suspend() Method | ||
735 | * before going to suspend. | ||
736 | * | ||
722 | */ | 737 | */ |
723 | void ODevice::sendSuspendmsg() | 738 | void ODevice::sendSuspendmsg() |
724 | { | 739 | { |
725 | if ( isQWS() ) | 740 | if ( isQWS() ) |
726 | return; | 741 | return; |
727 | 742 | ||
728 | QCopEnvelope ( "QPE/System", "aboutToSuspend()" ); | 743 | QCopEnvelope ( "QPE/System", "aboutToSuspend()" ); |
729 | } | 744 | } |
730 | 745 | ||
731 | /** | 746 | /** |
732 | * \brief Prepend the QWSServer::KeyboardFilter to the list of installed KeyFilters | 747 | * \brief Prepend the QWSServer::KeyboardFilter to the list of installed KeyFilters |
733 | * | 748 | * |
734 | * Prepend a QWSServer::KeyboardFilter to the List of Keyboard | 749 | * Prepend a QWSServer::KeyboardFilter to the List of Keyboard |
735 | * Filters. This function is the only way to prepend a KeyFilter. | 750 | * Filters. This function is the only way to prepend a KeyFilter. |
736 | * | 751 | * |
737 | * @param aFilter The KeyFilter to be prepended to the list of filters | 752 | * @param aFilter The KeyFilter to be prepended to the list of filters |
738 | * | 753 | * |
739 | * @see Opie::Core::OKeyFilter | 754 | * @see Opie::Core::OKeyFilter |
740 | * @see Opie::Core::OKeyFilter::inst() | 755 | * @see Opie::Core::OKeyFilter::inst() |
741 | */ | 756 | */ |
742 | void ODevice::addPreHandler(QWSServer::KeyboardFilter*aFilter) | 757 | void ODevice::addPreHandler(QWSServer::KeyboardFilter*aFilter) |
743 | { | 758 | { |
744 | Opie::Core::OKeyFilter::inst()->addPreHandler(aFilter); | 759 | Opie::Core::OKeyFilter::inst()->addPreHandler(aFilter); |
745 | } | 760 | } |
746 | 761 | ||
747 | /** | 762 | /** |
748 | * \brief Remove the QWSServer::KeyboardFilter in the param from the list | 763 | * \brief Remove the QWSServer::KeyboardFilter in the param from the list |
749 | * | 764 | * |
750 | * Remove the QWSServer::KeyboardFilter \par aFilter from the List | 765 | * Remove the QWSServer::KeyboardFilter \par aFilter from the List |
751 | * of Keyfilters. Call this when you delete the KeyFilter! | 766 | * of Keyfilters. Call this when you delete the KeyFilter! |
752 | * | 767 | * |
753 | * @param aFilter The filter to be removed from the Opie::Core::OKeyFilter | 768 | * @param aFilter The filter to be removed from the Opie::Core::OKeyFilter |
754 | * @see Opie::Core::ODevice::addPreHandler | 769 | * @see Opie::Core::ODevice::addPreHandler |
755 | */ | 770 | */ |
756 | void ODevice::remPreHandler(QWSServer::KeyboardFilter*aFilter) | 771 | void ODevice::remPreHandler(QWSServer::KeyboardFilter*aFilter) |
757 | { | 772 | { |
758 | Opie::Core::OKeyFilter::inst()->remPreHandler(aFilter); | 773 | Opie::Core::OKeyFilter::inst()->remPreHandler(aFilter); |
759 | } | 774 | } |
760 | 775 | ||
776 | |||
777 | /** | ||
778 | * @internal | ||
779 | * | ||
780 | * @see changeMixerForAlarm | ||
781 | */ | ||
761 | void ODevice::playingStopped() { | 782 | void ODevice::playingStopped() { |
762 | const_cast<QObject*>(sender())->disconnect( this ); | 783 | const_cast<QObject*>(sender())->disconnect( this ); |
763 | #ifndef QT_NO_SOUND | 784 | #ifndef QT_NO_SOUND |
764 | if ( d->m_sound >= 0 ) { | 785 | if ( d->m_sound >= 0 ) { |
765 | ::ioctl ( d->m_sound, MIXER_WRITE( d->m_mixer ), &d->m_vol ); | 786 | ::ioctl ( d->m_sound, MIXER_WRITE( d->m_mixer ), &d->m_vol ); |
766 | ::close ( d->m_sound ); | 787 | ::close ( d->m_sound ); |
767 | } | 788 | } |
768 | #endif | 789 | #endif |
769 | } | 790 | } |
770 | 791 | ||
792 | |||
793 | /** | ||
794 | * \brief Change the Volume for the Alarm and set it back after playing is finished | ||
795 | * | ||
796 | * If you play an Alarm Sound you might want to change the Mixer to | ||
797 | * full volume and ignore the user setting. After it \sa Sound::isFinished | ||
798 | * you would turn the volume back to the user preference. | ||
799 | * The problem is that we used to enter the event loop while waiting | ||
800 | * for the sound to be finished triggering all kind of reentrance | ||
801 | * problems what a library shouldn't introduce. | ||
802 | * Instead of manually waiting for the sound to be finished use | ||
803 | * this Method and it will automatically restore the Mixer to | ||
804 | * the user configuration after the sound finished playing. | ||
805 | * | ||
806 | * Note: The onwership of \param snd is not transfered and playing | ||
807 | * is not started in this method. If 'snd' gets deleted before | ||
808 | * playing is finished the volume doesn't get set back to | ||
809 | * the user preference! | ||
810 | * | ||
811 | * \code | ||
812 | * static Sound snd("alarm"); | ||
813 | * if(!snd.isFinished()) | ||
814 | * return; | ||
815 | * | ||
816 | * changeMixerForAlarm( my_channel, "/dev/mixer", &snd ); | ||
817 | * snd.play() | ||
818 | * \endcode | ||
819 | * | ||
820 | * | ||
821 | * | ||
822 | * @param mixer The mixer number/channel to use | ||
823 | * @param file The file name. If you convert from QString use QFile::encodeName | ||
824 | * @param snd The sound to wait for finishing | ||
825 | * | ||
826 | */ | ||
771 | void ODevice::changeMixerForAlarm( int mixer, const char* file, Sound *snd ) { | 827 | void ODevice::changeMixerForAlarm( int mixer, const char* file, Sound *snd ) { |
772 | #ifndef QT_NO_SOUND | 828 | #ifndef QT_NO_SOUND |
773 | if (( d->m_sound = ::open ( file, O_RDWR )) >= 0 ) { | 829 | if (( d->m_sound = ::open ( file, O_RDWR )) >= 0 ) { |
774 | if ( ::ioctl ( d->m_sound, MIXER_READ( mixer ), &d->m_vol ) >= 0 ) { | 830 | if ( ::ioctl ( d->m_sound, MIXER_READ( mixer ), &d->m_vol ) >= 0 ) { |
775 | Config cfg ( "qpe" ); | 831 | Config cfg ( "qpe" ); |
776 | cfg. setGroup ( "Volume" ); | 832 | cfg. setGroup ( "Volume" ); |
777 | 833 | ||
778 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | 834 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); |
779 | if ( volalarm < 0 ) | 835 | if ( volalarm < 0 ) |
780 | volalarm = 0; | 836 | volalarm = 0; |
781 | else if ( volalarm > 100 ) | 837 | else if ( volalarm > 100 ) |
782 | volalarm = 100; | 838 | volalarm = 100; |
783 | volalarm |= ( volalarm << 8 ); | 839 | volalarm |= ( volalarm << 8 ); |
784 | 840 | ||
785 | if ( ::ioctl ( d->m_sound, MIXER_WRITE( mixer ), &volalarm ) >= 0 ) | 841 | if ( ::ioctl ( d->m_sound, MIXER_WRITE( mixer ), &volalarm ) >= 0 ) |
786 | register_qpe_sound_finished(snd, this, SLOT(playingStopped())); | 842 | register_qpe_sound_finished(snd, this, SLOT(playingStopped())); |
787 | } | 843 | } |
788 | d->m_mixer = mixer; | 844 | d->m_mixer = mixer; |
789 | } | 845 | } |
790 | #endif | 846 | #endif |
791 | } | 847 | } |
792 | 848 | ||
793 | } | 849 | } |
794 | } | 850 | } |