author | zecke <zecke> | 2003-10-04 07:28:05 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-10-04 07:28:05 (UTC) |
commit | 23f729eb7487ad189591c3b0c9af9d3afecd3b91 (patch) (unidiff) | |
tree | 83b7efa5996ffcbf22f36b370505eb11fdece4ff | |
parent | 364d30ca7c212a531b79bb7cbceb8af7a0130f2c (diff) | |
download | opie-23f729eb7487ad189591c3b0c9af9d3afecd3b91.zip opie-23f729eb7487ad189591c3b0c9af9d3afecd3b91.tar.gz opie-23f729eb7487ad189591c3b0c9af9d3afecd3b91.tar.bz2 |
Avoid crashing on no mouse driver
-rw-r--r-- | core/apps/calibrate/main.cpp | 3 | ||||
-rw-r--r-- | core/opie-login/main.cpp | 13 |
2 files changed, 9 insertions, 7 deletions
diff --git a/core/apps/calibrate/main.cpp b/core/apps/calibrate/main.cpp index 1c295eb..ec9b5ec 100644 --- a/core/apps/calibrate/main.cpp +++ b/core/apps/calibrate/main.cpp | |||
@@ -1,46 +1,47 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "calibrate.h" | 21 | #include "calibrate.h" |
22 | 22 | ||
23 | #include <qfile.h> | 23 | #include <qfile.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | 25 | ||
26 | #ifdef QWS | 26 | #ifdef QWS |
27 | #include <qwindowsystem_qws.h> | 27 | #include <qwindowsystem_qws.h> |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | int main( int argc, char ** argv ) | 30 | int main( int argc, char ** argv ) |
31 | { | 31 | { |
32 | QPEApplication a( argc, argv ); | 32 | QPEApplication a( argc, argv ); |
33 | int retval = 0; | 33 | int retval = 0; |
34 | 34 | ||
35 | #ifdef QWS | 35 | #ifdef QWS |
36 | if ( QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { | 36 | if ( QWSServer::mouseHandler() && |
37 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { | ||
37 | #endif | 38 | #endif |
38 | // Make sure calibration widget starts on top. | 39 | // Make sure calibration widget starts on top. |
39 | Calibrate cal; | 40 | Calibrate cal; |
40 | a.setMainWidget(&cal); | 41 | a.setMainWidget(&cal); |
41 | a.showMainWidget(&cal); | 42 | a.showMainWidget(&cal); |
42 | return a.exec(); | 43 | return a.exec(); |
43 | #ifdef QWS | 44 | #ifdef QWS |
44 | } | 45 | } |
45 | #endif | 46 | #endif |
46 | } | 47 | } |
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 7dcb5f6..2103216 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp | |||
@@ -1,385 +1,386 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This file is free software; you can | 5 | _;:, .> :=|. This file is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This file is distributed in the hope that | 12 | .i_,=:_. -<s. This file is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
17 | ..}^=.= = ; Public License for more details. | 17 | ..}^=.= = ; Public License for more details. |
18 | ++= -. .` .: | 18 | ++= -. .` .: |
19 | : = ...= . :.=- You should have received a copy of the GNU | 19 | : = ...= . :.=- You should have received a copy of the GNU |
20 | -. .:....=;==+<; General Public License along with this file; | 20 | -. .:....=;==+<; General Public License along with this file; |
21 | -_. . . )=. = see the file COPYING. If not, write to the | 21 | -_. . . )=. = see the file COPYING. If not, write to the |
22 | -- :-=` Free Software Foundation, Inc., | 22 | -- :-=` Free Software Foundation, Inc., |
23 | 59 Temple Place - Suite 330, | 23 | 59 Temple Place - Suite 330, |
24 | Boston, MA 02111-1307, USA. | 24 | Boston, MA 02111-1307, USA. |
25 | 25 | ||
26 | */ | 26 | */ |
27 | 27 | ||
28 | #define _GNU_SOURCE | 28 | #define _GNU_SOURCE |
29 | 29 | ||
30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
31 | #include <time.h> | 31 | #include <time.h> |
32 | #include <sys/time.h> | 32 | #include <sys/time.h> |
33 | #include <sys/resource.h> | 33 | #include <sys/resource.h> |
34 | #include <unistd.h> | 34 | #include <unistd.h> |
35 | #include <syslog.h> | 35 | #include <syslog.h> |
36 | #include <sys/wait.h> | 36 | #include <sys/wait.h> |
37 | #include <stdio.h> | 37 | #include <stdio.h> |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
39 | #include <signal.h> | 39 | #include <signal.h> |
40 | #include <getopt.h> | 40 | #include <getopt.h> |
41 | #include <string.h> | 41 | #include <string.h> |
42 | 42 | ||
43 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
44 | #include <qpe/qcopenvelope_qws.h> | 44 | #include <qpe/qcopenvelope_qws.h> |
45 | #include <qpe/qpestyle.h> | 45 | #include <qpe/qpestyle.h> |
46 | #include <qpe/power.h> | 46 | #include <qpe/power.h> |
47 | #include <qpe/config.h> | 47 | #include <qpe/config.h> |
48 | 48 | ||
49 | #include <opie/odevice.h> | 49 | #include <opie/odevice.h> |
50 | 50 | ||
51 | #include <qwindowsystem_qws.h> | 51 | #include <qwindowsystem_qws.h> |
52 | #include <qwsmouse_qws.h> | 52 | #include <qwsmouse_qws.h> |
53 | #include <qmessagebox.h> | 53 | #include <qmessagebox.h> |
54 | #include <qlabel.h> | 54 | #include <qlabel.h> |
55 | #include <qtimer.h> | 55 | #include <qtimer.h> |
56 | #include <qfile.h> | 56 | #include <qfile.h> |
57 | #include <qtextstream.h> | 57 | #include <qtextstream.h> |
58 | 58 | ||
59 | #include "loginapplication.h" | 59 | #include "loginapplication.h" |
60 | #include "loginwindowimpl.h" | 60 | #include "loginwindowimpl.h" |
61 | #include "calibrate.h" | 61 | #include "calibrate.h" |
62 | 62 | ||
63 | using namespace Opie; | 63 | using namespace Opie; |
64 | 64 | ||
65 | int login_main ( int argc, char **argv, pid_t ppid ); | 65 | int login_main ( int argc, char **argv, pid_t ppid ); |
66 | void sigterm ( int sig ); | 66 | void sigterm ( int sig ); |
67 | void sigint ( int sig ); | 67 | void sigint ( int sig ); |
68 | void exit_closelog ( ); | 68 | void exit_closelog ( ); |
69 | 69 | ||
70 | static struct option long_options [] = { | 70 | static struct option long_options [] = { |
71 | { "autologin", 1, 0, 'a' }, | 71 | { "autologin", 1, 0, 'a' }, |
72 | { 0, 0, 0, 0 } | 72 | { 0, 0, 0, 0 } |
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | int main ( int argc, char **argv ) | 76 | int main ( int argc, char **argv ) |
77 | { | 77 | { |
78 | int userExited = 0; | 78 | int userExited = 0; |
79 | pid_t ppid = ::getpid ( ); | 79 | pid_t ppid = ::getpid ( ); |
80 | 80 | ||
81 | if ( ::geteuid ( ) != 0 ) { | 81 | if ( ::geteuid ( ) != 0 ) { |
82 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); | 82 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); |
83 | return 1; | 83 | return 1; |
84 | } | 84 | } |
85 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and | 85 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and |
86 | ::setuid ( 0 ); // messes up things like config files | 86 | ::setuid ( 0 ); // messes up things like config files |
87 | 87 | ||
88 | char *autolog = 0; | 88 | char *autolog = 0; |
89 | int c; | 89 | int c; |
90 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { | 90 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { |
91 | switch ( c ) { | 91 | switch ( c ) { |
92 | case 'a': | 92 | case 'a': |
93 | autolog = optarg; | 93 | autolog = optarg; |
94 | break; | 94 | break; |
95 | default: | 95 | default: |
96 | ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); | 96 | ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); |
97 | return 2; | 97 | return 2; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | //struct rlimit rl; | 101 | //struct rlimit rl; |
102 | //::getrlimit ( RLIMIT_NOFILE, &rl ); | 102 | //::getrlimit ( RLIMIT_NOFILE, &rl ); |
103 | 103 | ||
104 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) | 104 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) |
105 | // ::close ( i ); | 105 | // ::close ( i ); |
106 | 106 | ||
107 | ::setpgid ( 0, 0 ); | 107 | ::setpgid ( 0, 0 ); |
108 | ::setsid ( ); | 108 | ::setsid ( ); |
109 | 109 | ||
110 | ::signal ( SIGTERM, sigterm ); | 110 | ::signal ( SIGTERM, sigterm ); |
111 | ::signal ( SIGINT, sigterm ); | 111 | ::signal ( SIGINT, sigterm ); |
112 | 112 | ||
113 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); | 113 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); |
114 | ::atexit ( exit_closelog ); | 114 | ::atexit ( exit_closelog ); |
115 | 115 | ||
116 | while ( true ) { | 116 | while ( true ) { |
117 | pid_t child = ::fork ( ); | 117 | pid_t child = ::fork ( ); |
118 | 118 | ||
119 | if ( child < 0 ) { | 119 | if ( child < 0 ) { |
120 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); | 120 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); |
121 | break; | 121 | break; |
122 | } | 122 | } |
123 | else if ( child > 0 ) { | 123 | else if ( child > 0 ) { |
124 | int status = 0; | 124 | int status = 0; |
125 | time_t started = ::time ( 0 ); | 125 | time_t started = ::time ( 0 ); |
126 | 126 | ||
127 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } | 127 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } |
128 | 128 | ||
129 | LoginApplication::logout ( ); | 129 | LoginApplication::logout ( ); |
130 | 130 | ||
131 | if (( ::time ( 0 ) - started ) < 3 ) { | 131 | if (( ::time ( 0 ) - started ) < 3 ) { |
132 | if ( autolog ) { | 132 | if ( autolog ) { |
133 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); | 133 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); |
134 | autolog = 0; | 134 | autolog = 0; |
135 | } | 135 | } |
136 | else { | 136 | else { |
137 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); | 137 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); |
138 | break; | 138 | break; |
139 | } | 139 | } |
140 | } | 140 | } |
141 | int killedbysig = 0; | 141 | int killedbysig = 0; |
142 | userExited=0; | 142 | userExited=0; |
143 | if (WIFEXITED(status)!=0 ) { | 143 | if (WIFEXITED(status)!=0 ) { |
144 | if (WEXITSTATUS(status)==137) { | 144 | if (WEXITSTATUS(status)==137) { |
145 | userExited=1; | 145 | userExited=1; |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | if ( WIFSIGNALED( status )) { | 149 | if ( WIFSIGNALED( status )) { |
150 | switch ( WTERMSIG( status )) { | 150 | switch ( WTERMSIG( status )) { |
151 | case SIGTERM: | 151 | case SIGTERM: |
152 | case SIGINT : | 152 | case SIGINT : |
153 | case SIGKILL: | 153 | case SIGKILL: |
154 | break; | 154 | break; |
155 | 155 | ||
156 | default : | 156 | default : |
157 | killedbysig = WTERMSIG( status ); | 157 | killedbysig = WTERMSIG( status ); |
158 | break; | 158 | break; |
159 | } | 159 | } |
160 | } | 160 | } |
161 | if ( killedbysig ) { // qpe was killed by an uncaught signal | 161 | if ( killedbysig ) { // qpe was killed by an uncaught signal |
162 | qApp = 0; | 162 | qApp = 0; |
163 | 163 | ||
164 | ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); | 164 | ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); |
165 | 165 | ||
166 | QWSServer::setDesktopBackground ( QImage ( )); | 166 | QWSServer::setDesktopBackground ( QImage ( )); |
167 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); | 167 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); |
168 | app-> setFont ( QFont ( "Helvetica", 10 )); | 168 | app-> setFont ( QFont ( "Helvetica", 10 )); |
169 | app-> setStyle ( new QPEStyle ( )); | 169 | app-> setStyle ( new QPEStyle ( )); |
170 | 170 | ||
171 | const char *sig = ::strsignal ( killedbysig ); | 171 | const char *sig = ::strsignal ( killedbysig ); |
172 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); | 172 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); |
173 | l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); | 173 | l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); |
174 | l-> setAlignment ( Qt::AlignCenter ); | 174 | l-> setAlignment ( Qt::AlignCenter ); |
175 | l-> move ( 0, 0 ); | 175 | l-> move ( 0, 0 ); |
176 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 176 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); |
177 | l-> show ( ); | 177 | l-> show ( ); |
178 | QTimer::singleShot ( 3000, app, SLOT( quit ( ))); | 178 | QTimer::singleShot ( 3000, app, SLOT( quit ( ))); |
179 | app-> exec ( ); | 179 | app-> exec ( ); |
180 | delete app; | 180 | delete app; |
181 | qApp = 0; | 181 | qApp = 0; |
182 | } | 182 | } |
183 | } | 183 | } |
184 | else { | 184 | else { |
185 | if ( !autolog ) { | 185 | if ( !autolog ) { |
186 | QString confFile=QPEApplication::qpeDir() + "/etc/opie-login.conf"; | 186 | QString confFile=QPEApplication::qpeDir() + "/etc/opie-login.conf"; |
187 | Config cfg ( confFile, Config::File ); | 187 | Config cfg ( confFile, Config::File ); |
188 | cfg. setGroup ( "General" ); | 188 | cfg. setGroup ( "General" ); |
189 | QString user = cfg. readEntry ( "AutoLogin" ); | 189 | QString user = cfg. readEntry ( "AutoLogin" ); |
190 | 190 | ||
191 | if ( !user. isEmpty ( )) | 191 | if ( !user. isEmpty ( )) |
192 | autolog = ::strdup ( user. latin1 ( )); | 192 | autolog = ::strdup ( user. latin1 ( )); |
193 | } | 193 | } |
194 | 194 | ||
195 | if ( autolog && !userExited ) { | 195 | if ( autolog && !userExited ) { |
196 | 196 | ||
197 | QWSServer::setDesktopBackground( QImage() ); | 197 | QWSServer::setDesktopBackground( QImage() ); |
198 | ODevice::inst ( )-> setDisplayStatus ( true ); | 198 | ODevice::inst ( )-> setDisplayStatus ( true ); |
199 | ODevice::inst ( )-> setSoftSuspend ( false ); | 199 | ODevice::inst ( )-> setSoftSuspend ( false ); |
200 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); | 200 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); |
201 | LoginApplication::setLoginAs ( autolog ); | 201 | LoginApplication::setLoginAs ( autolog ); |
202 | 202 | ||
203 | 203 | ||
204 | if ( LoginApplication::changeIdentity ( )) | 204 | if ( LoginApplication::changeIdentity ( )) |
205 | ::exit ( LoginApplication::login ( )); | 205 | ::exit ( LoginApplication::login ( )); |
206 | else | 206 | else |
207 | ::exit ( 0 ); | 207 | ::exit ( 0 ); |
208 | } | 208 | } |
209 | else { | 209 | else { |
210 | ::exit ( login_main ( argc, argv, ppid )); | 210 | ::exit ( login_main ( argc, argv, ppid )); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | } | 213 | } |
214 | return 0; | 214 | return 0; |
215 | } | 215 | } |
216 | 216 | ||
217 | void sigterm ( int /*sig*/ ) | 217 | void sigterm ( int /*sig*/ ) |
218 | { | 218 | { |
219 | ::exit ( 0 ); | 219 | ::exit ( 0 ); |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | void exit_closelog ( ) | 223 | void exit_closelog ( ) |
224 | { | 224 | { |
225 | ::closelog ( ); | 225 | ::closelog ( ); |
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | class LoginScreenSaver : public QWSScreenSaver | 229 | class LoginScreenSaver : public QWSScreenSaver |
230 | { | 230 | { |
231 | public: | 231 | public: |
232 | LoginScreenSaver ( ) | 232 | LoginScreenSaver ( ) |
233 | { | 233 | { |
234 | m_lcd_status = true; | 234 | m_lcd_status = true; |
235 | 235 | ||
236 | m_backlight_bright = -1; | 236 | m_backlight_bright = -1; |
237 | m_backlight_forcedoff = false; | 237 | m_backlight_forcedoff = false; |
238 | 238 | ||
239 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 239 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
240 | ODevice::inst ( )-> setDisplayStatus ( true ); | 240 | ODevice::inst ( )-> setDisplayStatus ( true ); |
241 | } | 241 | } |
242 | void restore() | 242 | void restore() |
243 | { | 243 | { |
244 | if ( !m_lcd_status ) // We must have turned it off | 244 | if ( !m_lcd_status ) // We must have turned it off |
245 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 245 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
246 | 246 | ||
247 | setBacklight ( -3 ); | 247 | setBacklight ( -3 ); |
248 | } | 248 | } |
249 | bool save( int level ) | 249 | bool save( int level ) |
250 | { | 250 | { |
251 | switch ( level ) { | 251 | switch ( level ) { |
252 | case 0: | 252 | case 0: |
253 | if ( backlight() > 1 ) | 253 | if ( backlight() > 1 ) |
254 | setBacklight( 1 ); // lowest non-off | 254 | setBacklight( 1 ); // lowest non-off |
255 | return true; | 255 | return true; |
256 | break; | 256 | break; |
257 | case 1: | 257 | case 1: |
258 | setBacklight( 0 ); // off | 258 | setBacklight( 0 ); // off |
259 | return true; | 259 | return true; |
260 | break; | 260 | break; |
261 | case 2: | 261 | case 2: |
262 | // We're going to suspend the whole machine | 262 | // We're going to suspend the whole machine |
263 | if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { | 263 | if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { |
264 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 264 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
265 | return true; | 265 | return true; |
266 | } | 266 | } |
267 | break; | 267 | break; |
268 | } | 268 | } |
269 | return false; | 269 | return false; |
270 | } | 270 | } |
271 | 271 | ||
272 | private: | 272 | private: |
273 | public: | 273 | public: |
274 | void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) | 274 | void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) |
275 | { | 275 | { |
276 | int v [4]; | 276 | int v [4]; |
277 | 277 | ||
278 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | 278 | v [ 0 ] = QMAX( 1000 * i1, 100 ); |
279 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | 279 | v [ 1 ] = QMAX( 1000 * i2, 100 ); |
280 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | 280 | v [ 2 ] = QMAX( 1000 * i3, 100 ); |
281 | v [ 3 ] = 0; | 281 | v [ 3 ] = 0; |
282 | 282 | ||
283 | if ( !i1 && !i2 && !i3 ) | 283 | if ( !i1 && !i2 && !i3 ) |
284 | QWSServer::setScreenSaverInterval ( 0 ); | 284 | QWSServer::setScreenSaverInterval ( 0 ); |
285 | else | 285 | else |
286 | QWSServer::setScreenSaverIntervals ( v ); | 286 | QWSServer::setScreenSaverIntervals ( v ); |
287 | } | 287 | } |
288 | 288 | ||
289 | int backlight ( ) | 289 | int backlight ( ) |
290 | { | 290 | { |
291 | if ( m_backlight_bright == -1 ) | 291 | if ( m_backlight_bright == -1 ) |
292 | m_backlight_bright = 255; | 292 | m_backlight_bright = 255; |
293 | 293 | ||
294 | return m_backlight_bright; | 294 | return m_backlight_bright; |
295 | } | 295 | } |
296 | 296 | ||
297 | void setBacklight ( int bright ) | 297 | void setBacklight ( int bright ) |
298 | { | 298 | { |
299 | if ( bright == -3 ) { | 299 | if ( bright == -3 ) { |
300 | // Forced on | 300 | // Forced on |
301 | m_backlight_forcedoff = false; | 301 | m_backlight_forcedoff = false; |
302 | bright = -1; | 302 | bright = -1; |
303 | } | 303 | } |
304 | if ( m_backlight_forcedoff && bright != -2 ) | 304 | if ( m_backlight_forcedoff && bright != -2 ) |
305 | return ; | 305 | return ; |
306 | if ( bright == -2 ) { | 306 | if ( bright == -2 ) { |
307 | // Toggle between off and on | 307 | // Toggle between off and on |
308 | bright = m_backlight_bright ? 0 : -1; | 308 | bright = m_backlight_bright ? 0 : -1; |
309 | m_backlight_forcedoff = !bright; | 309 | m_backlight_forcedoff = !bright; |
310 | } | 310 | } |
311 | 311 | ||
312 | m_backlight_bright = bright; | 312 | m_backlight_bright = bright; |
313 | 313 | ||
314 | bright = backlight ( ); | 314 | bright = backlight ( ); |
315 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); | 315 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); |
316 | 316 | ||
317 | m_backlight_bright = bright; | 317 | m_backlight_bright = bright; |
318 | } | 318 | } |
319 | 319 | ||
320 | private: | 320 | private: |
321 | bool m_lcd_status; | 321 | bool m_lcd_status; |
322 | 322 | ||
323 | int m_backlight_bright; | 323 | int m_backlight_bright; |
324 | bool m_backlight_forcedoff; | 324 | bool m_backlight_forcedoff; |
325 | }; | 325 | }; |
326 | 326 | ||
327 | 327 | ||
328 | namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting | 328 | namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting |
329 | 329 | ||
330 | 330 | ||
331 | int login_main ( int argc, char **argv, pid_t ppid ) | 331 | int login_main ( int argc, char **argv, pid_t ppid ) |
332 | { | 332 | { |
333 | QWSServer::setDesktopBackground( QImage() ); | 333 | QWSServer::setDesktopBackground( QImage() ); |
334 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); | 334 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); |
335 | 335 | ||
336 | Opie::force_appearance = 0; | 336 | Opie::force_appearance = 0; |
337 | 337 | ||
338 | app-> setFont ( QFont ( "Helvetica", 10 )); | 338 | app-> setFont ( QFont ( "Helvetica", 10 )); |
339 | app-> setStyle ( new QPEStyle ( )); | 339 | app-> setStyle ( new QPEStyle ( )); |
340 | 340 | ||
341 | ODevice::inst ( )-> setSoftSuspend ( true ); | 341 | ODevice::inst ( )-> setSoftSuspend ( true ); |
342 | 342 | ||
343 | if ( QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { | 343 | if ( QWSServer::mouseHandler() && |
344 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { | ||
344 | if ( !QFile::exists ( "/etc/pointercal" )) { | 345 | if ( !QFile::exists ( "/etc/pointercal" )) { |
345 | // Make sure calibration widget starts on top. | 346 | // Make sure calibration widget starts on top. |
346 | Calibrate *cal = new Calibrate; | 347 | Calibrate *cal = new Calibrate; |
347 | cal-> exec ( ); | 348 | cal-> exec ( ); |
348 | delete cal; | 349 | delete cal; |
349 | } | 350 | } |
350 | } | 351 | } |
351 | 352 | ||
352 | LoginScreenSaver *saver = new LoginScreenSaver; | 353 | LoginScreenSaver *saver = new LoginScreenSaver; |
353 | 354 | ||
354 | saver-> setIntervals ( ); | 355 | saver-> setIntervals ( ); |
355 | QWSServer::setScreenSaver ( saver ); | 356 | QWSServer::setScreenSaver ( saver ); |
356 | saver-> restore ( ); | 357 | saver-> restore ( ); |
357 | 358 | ||
358 | 359 | ||
359 | LoginWindowImpl *lw = new LoginWindowImpl ( ); | 360 | LoginWindowImpl *lw = new LoginWindowImpl ( ); |
360 | app-> setMainWidget ( lw ); | 361 | app-> setMainWidget ( lw ); |
361 | lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 362 | lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); |
362 | lw-> show ( ); | 363 | lw-> show ( ); |
363 | 364 | ||
364 | int rc = app-> exec ( ); | 365 | int rc = app-> exec ( ); |
365 | 366 | ||
366 | ODevice::inst ( )-> setSoftSuspend ( false ); | 367 | ODevice::inst ( )-> setSoftSuspend ( false ); |
367 | 368 | ||
368 | if ( app-> loginAs ( )) { | 369 | if ( app-> loginAs ( )) { |
369 | if ( app-> changeIdentity ( )) { | 370 | if ( app-> changeIdentity ( )) { |
370 | app-> login ( ); | 371 | app-> login ( ); |
371 | 372 | ||
372 | // if login succeeds, it never comes back | 373 | // if login succeeds, it never comes back |
373 | 374 | ||
374 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); | 375 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); |
375 | rc = 1; | 376 | rc = 1; |
376 | } | 377 | } |
377 | else { | 378 | else { |
378 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); | 379 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); |
379 | rc = 2; | 380 | rc = 2; |
380 | } | 381 | } |
381 | 382 | ||
382 | } | 383 | } |
383 | return rc; | 384 | return rc; |
384 | } | 385 | } |
385 | 386 | ||