author | sandman <sandman> | 2002-09-30 00:29:12 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-30 00:29:12 (UTC) |
commit | f6e9cebd79044b1ca54648ecdadd13db8c4673dc (patch) (side-by-side diff) | |
tree | e29985455734329ee31e14d04b2d613eafabb6a0 | |
parent | b53db7a5a334fdd53bd86e8b50587f1dae41cfba (diff) | |
download | opie-f6e9cebd79044b1ca54648ecdadd13db8c4673dc.zip opie-f6e9cebd79044b1ca54648ecdadd13db8c4673dc.tar.gz opie-f6e9cebd79044b1ca54648ecdadd13db8c4673dc.tar.bz2 |
- added an option to quit to console
- launcher is now started via a login shell
- font is "hardcoded" to helvetica
- screen saver is "hardcoded" to 30/20/60 secs
(this should make opie-login usable, regardless of any
(miss)-configuration of the normal OPIE appearance)
-rw-r--r-- | core/opie-login/loginwindow.ui | 22 | ||||
-rw-r--r-- | core/opie-login/loginwindowimpl.cpp | 54 | ||||
-rw-r--r-- | core/opie-login/loginwindowimpl.h | 1 | ||||
-rw-r--r-- | core/opie-login/main.cpp | 197 |
4 files changed, 168 insertions, 106 deletions
diff --git a/core/opie-login/loginwindow.ui b/core/opie-login/loginwindow.ui index 86d5469..edd0819 100644 --- a/core/opie-login/loginwindow.ui +++ b/core/opie-login/loginwindow.ui @@ -13,3 +13,3 @@ <y>0</y> - <width>472</width> + <width>460</width> <height>341</height> @@ -45,2 +45,5 @@ </property> + <property> + <name>layoutSpacing</name> + </property> <vbox> @@ -52,3 +55,3 @@ <name>spacing</name> - <number>6</number> + <number>4</number> </property> @@ -68,2 +71,11 @@ <property stdset="1"> + <name>font</name> + <font> + <family>helvetica</family> + <pointsize>18</pointsize> + <bold>1</bold> + <underline>1</underline> + </font> + </property> + <property stdset="1"> <name>autoMask</name> @@ -76,4 +88,8 @@ <property stdset="1"> + <name>margin</name> + <number>1</number> + </property> + <property stdset="1"> <name>text</name> - <string><center><h1>Welcome to OPIE</h1></center></string> + <string><center>Welcome to OPIE</center></string> </property> diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp index 3265b46..f24ebb3 100644 --- a/core/opie-login/loginwindowimpl.cpp +++ b/core/opie-login/loginwindowimpl.cpp @@ -22,2 +22,3 @@ #include <stdlib.h> +#include <signal.h> @@ -39,2 +40,3 @@ LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_C pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); + pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); m_menu-> setPopup ( pop ); @@ -59,3 +61,3 @@ LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_C - m_caption-> setText ( m_caption-> text ( ) + tr( "<center><h1><u>%1 %2</u></h1></center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); + m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); } @@ -69,5 +71,5 @@ void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) switch ( e-> key ( )) { - case Key_F34: suspend ( ); + case HardKey_Suspend: suspend ( ); break; - case Key_F35: backlight ( ); + case HardKey_Backlight: backlight ( ); break; @@ -90,3 +92,3 @@ QStringList LoginWindowImpl::getAllUsers ( ) - while (( pwd = getpwent ( ))) { + while (( pwd = ::getpwent ( ))) { if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) @@ -95,3 +97,3 @@ QStringList LoginWindowImpl::getAllUsers ( ) - endpwent ( ); + ::endpwent ( ); @@ -110,7 +112,12 @@ void LoginWindowImpl::restart ( ) -void LoginWindowImpl::suspend ( ) +void LoginWindowImpl::quit ( ) { - system ( "apm -s" ); - usleep ( 1 * 1000 * 1000 ); + qApp-> quit ( ); + ::kill ( ::getppid ( ), SIGUSR1 ); +} + +void LoginWindowImpl::suspend ( ) { + ODevice::inst ( )-> suspend ( ); + QCopEnvelope e("QPE/System", "setBacklight(int)"); @@ -118,3 +125,2 @@ void LoginWindowImpl::suspend ( ) } -} @@ -122,3 +128,2 @@ void LoginWindowImpl::backlight ( ) { - { QCopEnvelope e("QPE/System", "setBacklight(int)"); @@ -126,3 +131,2 @@ void LoginWindowImpl::backlight ( ) } -} @@ -260,24 +264,14 @@ bool LoginWindowImpl::changeIdentity ( const char *user ) fail |= ( pw == 0 ); - printf ( "1 %d\n", fail ); fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid )); endgrent ( ); - printf ( "2 %d\n", fail ); fail |= ( setgid ( pw-> pw_gid )); - printf ( "3 %d\n", fail ); fail |= ( setuid ( pw-> pw_uid )); - printf ( "4 %d\n", fail ); fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" )); - printf ( "5 %d\n", fail ); fail |= ( setenv ( "HOME", pw-> pw_dir, 1 )); - printf ( "6 %d\n", fail ); fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 )); - printf ( "7 %d\n", fail ); fail |= ( setenv ( "USER", pw-> pw_name, 1 )); - printf ( "8 %d\n", fail ); fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 )); - printf ( "9 %d\n", fail ); fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); - printf ( "10 %d\n", fail ); @@ -288,4 +282,4 @@ void LoginWindowImpl::login ( ) { - const char *user = strdup ( m_user-> currentText ( ). local8Bit ( )); - const char *pass = strdup ( m_password-> text ( ). local8Bit ( )); + const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); + const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); bool ok; @@ -305,8 +299,14 @@ void LoginWindowImpl::login ( ) if ( changeIdentity ( user )) { - QString opie = getenv ( "OPIEDIR" ); - opie += "/bin/qpe"; + char *opie = ::getenv ( "OPIEDIR" ); + char *arg = new char [::strlen ( opie ) + 8 + 1]; + + ::strcpy ( arg, opie ); + ::strcat ( arg, "/bin/qpe" ); + + // start qpe via a login shell + ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); - execl ( opie. latin1 ( ), "qpe", 0 ); + QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE\n(%1)." ). arg ( arg )); + delete [] arg; - QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE." )); restart ( ); diff --git a/core/opie-login/loginwindowimpl.h b/core/opie-login/loginwindowimpl.h index 16c42e6..2e2ba0d 100644 --- a/core/opie-login/loginwindowimpl.h +++ b/core/opie-login/loginwindowimpl.h @@ -16,2 +16,3 @@ protected slots: void restart ( ); + void quit ( ); void showIM ( ); diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 44d6f8d..718009a 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp @@ -8,2 +8,3 @@ #include <stdlib.h> +#include <signal.h> @@ -11,2 +12,4 @@ #include <qpe/qcopenvelope_qws.h> +#include <qpe/qpestyle.h> +#include <qpe/power.h> @@ -21,2 +24,5 @@ int login_main ( int argc, char **argv ); +void sigusr1 ( int sig ); +void exit_closelog ( ); + @@ -25,4 +31,4 @@ int main ( int argc, char **argv ) { - if ( geteuid ( ) != 0 ) { - fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); + if ( ::geteuid ( ) != 0 ) { + ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); return 1; @@ -31,17 +37,20 @@ int main ( int argc, char **argv ) // struct rlimit rl; -// getrlimit ( RLIMIT_NOFILE, &rl ); +// ::getrlimit ( RLIMIT_NOFILE, &rl ); // for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) -// close ( i ); +// ::close ( i ); + + ::setpgid ( 0, 0 ); + ::setsid ( ); - setpgid ( 0, 0 ); - setsid ( ); + ::signal ( SIGUSR1, sigusr1 ); - openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); + ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); + ::atexit ( exit_closelog ); while ( true ) { - pid_t child = fork ( ); + pid_t child = ::fork ( ); if ( child < 0 ) { - syslog ( LOG_ERR, "Could not fork process" ); + ::syslog ( LOG_ERR, "Could not fork process" ); break; @@ -52,9 +61,19 @@ int main ( int argc, char **argv ) - while ( waitpid ( child, &status, 0 ) < 0 ) { } + while ( ::waitpid ( child, &status, 0 ) < 0 ) { } } else { - exit ( login_main ( argc, argv )); + ::exit ( login_main ( argc, argv )); + } } + return 0; +} + +void sigusr1 ( int /*sig*/ ) +{ + ::exit ( 0 ); } - closelog ( ); + +void exit_closelog ( ) +{ + ::closelog ( ); } @@ -62,43 +81,39 @@ int main ( int argc, char **argv ) -class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter +class LoginScreenSaver : public QWSScreenSaver { public: - ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" ) + LoginScreenSaver ( ) { - bool doinst = false; + m_lcd_status = true; - m_model = ODevice::inst ( )-> model ( ); - m_power_timer = 0; + m_backlight_bright = -1; + m_backlight_forcedoff = false; - switch ( m_model ) { - case OMODEL_iPAQ_H31xx: - case OMODEL_iPAQ_H36xx: - case OMODEL_iPAQ_H37xx: - case OMODEL_iPAQ_H38xx: doinst = true; - break; - default : break; - } - if ( doinst ) - QWSServer::setKeyboardFilter ( this ); + // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) + ODevice::inst ( ) -> setDisplayStatus ( true ); } - - virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) + void restore() { - bool kill = false; - - // Rotate cursor keys 180° - switch ( m_model ) { - case OMODEL_iPAQ_H31xx: - case OMODEL_iPAQ_H38xx: { - int newkeycode = keycode; + if ( !m_lcd_status ) // We must have turned it off + ODevice::inst ( ) -> setDisplayStatus ( true ); - switch ( keycode ) { - case Key_Left : newkeycode = Key_Right; break; - case Key_Right: newkeycode = Key_Left; break; - case Key_Up : newkeycode = Key_Down; break; - case Key_Down : newkeycode = Key_Up; break; + setBacklight ( -1 ); } - if ( newkeycode != keycode ) { - QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); - kill = true; + bool save( int level ) + { + switch ( level ) { + case 0: + if ( backlight() > 1 ) + setBacklight( 1 ); // lowest non-off + return true; + break; + case 1: + setBacklight( 0 ); // off + return true; + break; + case 2: + // We're going to suspend the whole machine + if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { + QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); + return true; } @@ -106,36 +121,51 @@ public: } - default: break; + return false; } - // map Power Button short/long press to F34/F35 - switch ( m_model ) { - case OMODEL_iPAQ_H31xx: - case OMODEL_iPAQ_H36xx: - case OMODEL_iPAQ_H37xx: - case OMODEL_iPAQ_H38xx: { - if ( keycode == Key_SysReq ) { - if ( isPress ) { - m_power_timer = startTimer ( 500 ); - } - else if ( m_power_timer ) { - killTimer ( m_power_timer ); - m_power_timer = 0; - QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false ); - QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false ); - } - kill = true; +private: +public: + void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) + { + int v [4]; + + v [ 0 ] = QMAX( 1000 * i1, 100 ); + v [ 1 ] = QMAX( 1000 * i2, 100 ); + v [ 2 ] = QMAX( 1000 * i3, 100 ); + v [ 3 ] = 0; + + if ( !i1 && !i2 && !i3 ) + QWSServer::setScreenSaverInterval ( 0 ); + else + QWSServer::setScreenSaverIntervals ( v ); } - break; + + int backlight ( ) + { + if ( m_backlight_bright == -1 ) + m_backlight_bright = 255; + + return m_backlight_bright; } - default: break; + + void setBacklight ( int bright ) + { + if ( bright == -3 ) { + // Forced on + m_backlight_forcedoff = false; + bright = -1; } - return kill; + if ( m_backlight_forcedoff && bright != -2 ) + return ; + if ( bright == -2 ) { + // Toggle between off and on + bright = m_backlight_bright ? 0 : -1; + m_backlight_forcedoff = !bright; } - virtual void timerEvent ( QTimerEvent * ) - { - killTimer ( m_power_timer ); - m_power_timer = 0; - QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false ); - QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false ); + m_backlight_bright = bright; + + bright = backlight ( ); + ODevice::inst ( ) -> setDisplayBrightness ( bright ); + + m_backlight_bright = bright; } @@ -143,6 +173,7 @@ public: private: - OModel m_model; - int m_power_timer; -}; + bool m_lcd_status; + int m_backlight_bright; + bool m_backlight_forcedoff; +}; @@ -155,3 +186,6 @@ int login_main ( int argc, char **argv ) - (void) new ModelKeyFilter ( ); + app. setFont ( QFont ( "Helvetica", 10 )); + app. setStyle ( new QPEStyle ( )); + + ODevice::inst ( )-> setSoftSuspend ( true ); @@ -171,2 +205,9 @@ int login_main ( int argc, char **argv ) + + LoginScreenSaver *saver = new LoginScreenSaver; + + saver-> setIntervals ( ); + QWSServer::setScreenSaver ( saver ); + + LoginWindowImpl *lw = new LoginWindowImpl ( ); @@ -176,3 +217,7 @@ int login_main ( int argc, char **argv ) - return app. exec ( ); + int rc = app. exec ( ); + + ODevice::inst ( )-> setSoftSuspend ( false ); + + return rc; } |