00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <qpe/version.h>
00028 #include <qpushbutton.h>
00029 #include <qlayout.h>
00030 #include <qlineedit.h>
00031 #include <qtimer.h>
00032 #include <qcombobox.h>
00033 #include <qlabel.h>
00034 #include <qpopupmenu.h>
00035 #include <qmessagebox.h>
00036 #if QT_VERSION < 0x030000
00037 #include <qgfx_qws.h>
00038 #endif
00039 #include <qwindowsystem_qws.h>
00040
00041 #include <qpe/qcopenvelope_qws.h>
00042 #include <qpe/config.h>
00043
00044 #include <opie2/odevice.h>
00045 #include <opie2/oresource.h>
00046
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049
00050 #include "passworddialogimpl.h"
00051 #include "loginwindowimpl.h"
00052 #include "loginapplication.h"
00053 #include "inputmethods.h"
00054
00055 using namespace Opie::Core;
00056
00057
00058 LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose )
00059 {
00060 QPopupMenu *pop = new QPopupMenu ( this );
00061 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart()));
00062 pop-> insertItem ( tr( "Quit" ), this, SLOT( quit()));
00063 m_menu-> setPopup ( pop );
00064
00065 QCopChannel *channel = new QCopChannel ( "QPE/TaskBar", this );
00066 connect ( channel, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( receive(const QCString&,const QByteArray&)));
00067
00068 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 );
00069 m_input = new InputMethods ( m_taskbar );
00070 connect ( m_input, SIGNAL( inputToggled(bool)), this, SLOT( calcMaxWindowRect()));
00071 lay-> addWidget ( m_input );
00072 lay-> addStretch ( 10 );
00073
00074 setActiveWindow ( );
00075 m_password-> setFocus ( );
00076
00077 m_user-> insertStringList ( lApp-> allUsers ( ));
00078
00079
00080 if (ODevice::inst ( )-> series ( ) != Model_Zaurus){
00081 QTimer::singleShot ( 0, this, SLOT( showIM()));
00082 }
00083
00084 QString opiedir = ::getenv ( "OPIEDIR" );
00085 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" );
00086
00087 if ( !bgpix. isNull ( )) {
00088 setBackgroundPixmap ( bgpix );
00089 m_caption-> setBackgroundPixmap ( bgpix);
00090 TextLabel1-> setBackgroundPixmap ( bgpix);
00091 TextLabel2-> setBackgroundPixmap ( bgpix);
00092 }
00093
00094
00095
00096 Config cfg ( "opie-login" );
00097 cfg. setGroup ( "General" );
00098 QString last = cfg. readEntry ( "LastLogin" );
00099
00100 if ( !last. isEmpty ( ))
00101 m_user-> setEditText ( last );
00102
00103 calcMaxWindowRect ( );
00104
00105 if ( PasswordDialogImpl::needDialog() )
00106 QTimer::singleShot(10, this, SLOT(showPasswordDialog()) );
00107
00108
00109 }
00110
00111 LoginWindowImpl::~LoginWindowImpl ( )
00112 {
00113 }
00114
00115
00116 void LoginWindowImpl::receive ( const QCString &msg, const QByteArray &data )
00117 {
00118 QDataStream stream ( data, IO_ReadOnly );
00119
00120 if ( msg == "hideInputMethod()" )
00121 m_input-> hideInputMethod ( );
00122 else if ( msg == "showInputMethod()" )
00123 m_input-> showInputMethod ( );
00124 else if ( msg == "reloadInputMethods()" )
00125 m_input-> loadInputMethods ( );
00126 }
00127
00128 void LoginWindowImpl::calcMaxWindowRect ( )
00129 {
00130 #ifdef Q_WS_QWS
00131 QRect wr;
00132 int displayWidth = qApp-> desktop ( )-> width ( );
00133 QRect ir = m_input-> inputRect ( );
00134 if ( ir.isValid() )
00135 wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 );
00136 else
00137 wr.setCoords( 0, 0, displayWidth-1, m_taskbar->y()-1 );
00138
00139 #if QT_VERSION < 0x030000
00140 wr = qt_screen-> mapToDevice ( wr, QSize ( qt_screen-> width ( ), qt_screen-> height ( )));
00141 #endif
00142
00143 QWSServer::setMaxWindowRect( wr );
00144 #endif
00145 }
00146
00147
00148 void LoginWindowImpl::keyPressEvent ( QKeyEvent *e )
00149 {
00150 switch ( e-> key ( )) {
00151 case HardKey_Suspend: suspend ( );
00152 break;
00153 case HardKey_Backlight: backlight ( );
00154 break;
00155 default: e-> ignore ( );
00156 break;
00157 }
00158 LoginWindow::keyPressEvent ( e );
00159 }
00160
00161
00162 void LoginWindowImpl::toggleEchoMode ( bool t )
00163 {
00164 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password );
00165 }
00166
00167 void LoginWindowImpl::showIM ( )
00168 {
00169 m_input-> showInputMethod ( );
00170 }
00171
00172 void LoginWindowImpl::restart ( )
00173 {
00174 qApp-> quit ( );
00175 }
00176
00177 void LoginWindowImpl::quit ( )
00178 {
00179 lApp-> quitToConsole ( );
00180 }
00181
00182 void LoginWindowImpl::suspend ( )
00183 {
00184 ODevice::inst ( )-> suspend ( );
00185
00186 QCopEnvelope e("QPE/System", "setBacklight(int)");
00187 e << -3;
00188 }
00189
00190 void LoginWindowImpl::backlight ( )
00191 {
00192 QCopEnvelope e("QPE/System", "setBacklight(int)");
00193 e << -2;
00194 }
00195
00196 class WaitLogo : public QLabel {
00197 public:
00198 WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool )
00199 {
00200 setPixmap( Opie::Core::OResource::loadPixmap( "launcher/new_wait" ) );
00201 setAlignment ( AlignCenter );
00202 move ( 0, 0 );
00203 resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( ));
00204
00205 m_visible = false;
00206 show ( );
00207 }
00208
00209 virtual void showEvent ( QShowEvent *e )
00210 {
00211 QLabel::showEvent ( e );
00212 m_visible = true;
00213 }
00214
00215 virtual void paintEvent ( QPaintEvent *e )
00216 {
00217 QLabel::paintEvent ( e );
00218 if ( m_visible )
00219 qApp-> quit ( );
00220 }
00221
00222 private:
00223 bool m_visible;
00224 };
00225
00226 void LoginWindowImpl::login ( )
00227 {
00228 const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( ));
00229 const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( ));
00230
00231 if ( !user || !user [0] )
00232 return;
00233 if ( !pass )
00234 pass = "";
00235
00236 if ( lApp-> checkPassword ( user, pass )) {
00237 Config cfg ( "opie-login" );
00238 cfg. setGroup ( "General" );
00239 cfg. writeEntry ( "LastLogin", user );
00240 cfg. write ( );
00241
00242 lApp-> setLoginAs ( user );
00243
00244
00245 m_input-> hideInputMethod ( );
00246 new WaitLogo ( );
00247
00248 }
00249 else {
00250 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." ));
00251 m_password-> clear ( );
00252 }
00253 }
00254
00255 void LoginWindowImpl::showPasswordDialog() {
00256 PasswordDialogImpl dia( this );
00257 dia.showMaximized();
00258 dia.exec();
00259 }