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 /core | |
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 @@ -10,9 +10,9 @@ <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>472</width> + <width>460</width> <height>341</height> </rect> </property> <property stdset="1"> @@ -42,16 +42,19 @@ </property> <property> <name>layoutMargin</name> </property> + <property> + <name>layoutSpacing</name> + </property> <vbox> <property stdset="1"> <name>margin</name> <number>4</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>4</number> </property> <widget> <class>QLabel</class> <property stdset="1"> @@ -65,18 +68,31 @@ <vsizetype>5</vsizetype> </sizepolicy> </property> <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> <bool>true</bool> </property> <property stdset="1"> <name>backgroundOrigin</name> <enum>ParentOrigin</enum> </property> <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> </widget> <widget> <class>QLayoutWidget</class> 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 @@ -19,8 +19,9 @@ #include <pwd.h> #include <grp.h> #include <unistd.h> #include <stdlib.h> +#include <signal.h> #ifdef USEPAM extern "C" { #include <security/pam_appl.h> @@ -36,8 +37,9 @@ extern "C" { LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) { QPopupMenu *pop = new QPopupMenu ( this ); pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); + pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); m_menu-> setPopup ( pop ); QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); m_input = new InputMethods ( m_taskbar ); @@ -56,9 +58,9 @@ LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_C if ( !bgpix. isNull ( )) setBackgroundPixmap ( bgpix ); - 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 ( ))); } LoginWindowImpl::~LoginWindowImpl ( ) { @@ -66,11 +68,11 @@ LoginWindowImpl::~LoginWindowImpl ( ) 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; default : e-> ignore ( ); break; } @@ -87,14 +89,14 @@ QStringList LoginWindowImpl::getAllUsers ( ) { struct passwd *pwd; QStringList sl; - while (( pwd = getpwent ( ))) { + while (( pwd = ::getpwent ( ))) { if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) sl << QString ( pwd-> pw_name ); } - endpwent ( ); + ::endpwent ( ); return sl; } @@ -107,25 +109,27 @@ void LoginWindowImpl::restart ( ) { qApp-> quit ( ); } -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)"); e << -3; // Force on } -} void LoginWindowImpl::backlight ( ) { - { QCopEnvelope e("QPE/System", "setBacklight(int)"); e << -2; // toggle } -} #ifdef USEPAM static const char *_PAM_SERVICE = "xdm"; @@ -257,38 +261,28 @@ bool LoginWindowImpl::changeIdentity ( const char *user ) bool fail = false; struct passwd *pw = getpwnam ( 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 ); return !fail; } 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; if ( !user || !user [0] ) return; @@ -302,14 +296,20 @@ void LoginWindowImpl::login ( ) #endif if ( ok ) { 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 ( ); } else { QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" )); 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 @@ -13,8 +13,9 @@ public: virtual ~LoginWindowImpl ( ); protected slots: void restart ( ); + void quit ( ); void showIM ( ); void suspend ( ); void backlight ( ); void login ( ); 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 @@ -5,11 +5,14 @@ #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> +#include <signal.h> #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> +#include <qpe/qpestyle.h> +#include <qpe/power.h> #include <opie/odevice.h> #include <qwindowsystem_qws.h> @@ -18,143 +21,174 @@ #include "loginwindowimpl.h" #include "calibrate.h" int login_main ( int argc, char **argv ); +void sigusr1 ( int sig ); +void exit_closelog ( ); + 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; } // 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; } else if ( child > 0 ) { int status = 0; - 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 ( ); } -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; } break; } - 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; } private: - OModel m_model; - int m_power_timer; -}; + bool m_lcd_status; + int m_backlight_bright; + bool m_backlight_forcedoff; +}; int login_main ( int argc, char **argv ) { QWSServer::setDesktopBackground( QImage() ); QPEApplication app ( argc, argv, QApplication::GuiServer ); - (void) new ModelKeyFilter ( ); + app. setFont ( QFont ( "Helvetica", 10 )); + app. setStyle ( new QPEStyle ( )); + + ODevice::inst ( )-> setSoftSuspend ( true ); { QCopEnvelope e("QPE/System", "setBacklight(int)" ); e << -3; // Forced on @@ -168,12 +202,23 @@ int login_main ( int argc, char **argv ) delete cal; } #endif + + LoginScreenSaver *saver = new LoginScreenSaver; + + saver-> setIntervals ( ); + QWSServer::setScreenSaver ( saver ); + + LoginWindowImpl *lw = new LoginWindowImpl ( ); app. setMainWidget ( lw ); lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( )); lw-> show ( ); - return app. exec ( ); + int rc = app. exec ( ); + + ODevice::inst ( )-> setSoftSuspend ( false ); + + return rc; } |