Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

authwidget.cpp

Go to the documentation of this file.
00001 #include "auth.h"
00002 #include "authwidget.h"
00003 #include "edit.h"
00004 #include "pppdata.h"
00005 
00006 /* OPIE */
00007 #include <opie2/odebug.h>
00008 using namespace Opie::Core;
00009 
00010 /* QT */
00011 #include <qlayout.h>
00012 #include <qmessagebox.h>
00013 #include <qtoolbutton.h>
00014 #include <qwhatsthis.h>
00015 
00016 /* XPM */
00017 static const char* const image0_data[] = {
00018 "16 16 2 1",
00019 ". c None",
00020 "# c #000000",
00021 "................",
00022 "...#...###...##.",
00023 "..#.#..#..#.##..",
00024 "..###..###.##...",
00025 ".#...#.#..##....",
00026 ".#...#.#.##.....",
00027 "........##.#..#.",
00028 "..##...##...##..",
00029 ".#..#.###...##..",
00030 ".#...##..#.#..#.",
00031 ".#..##..........",
00032 ".#.##.#..#.#..#.",
00033 "..##...##...##..",
00034 ".##....##...##..",
00035 ".#....#..#.#..#.",
00036 "................"};
00037 
00038 
00039 AuthWidget::AuthWidget(PPPData *pd, QWidget *parent, bool isnewaccount, const char *name )
00040     : QWidget( parent, name),
00041       scriptWidget(0),
00042       _pppdata(pd),
00043       isNewAccount(isnewaccount)
00044 {
00045     layout = new QGridLayout(this);
00046 
00047     auth_l = new QLabel(tr("Authentication: "), this);
00048     layout->addWidget(auth_l, 0, 0);
00049 
00050     auth = new QComboBox(this);
00051     auth->insertItem(tr("Script-based"));
00052     auth->insertItem(tr("PAP"));
00053     auth->insertItem(tr("Terminal-based"));
00054     auth->insertItem(tr("CHAP"));
00055     auth->insertItem(tr("PAP/CHAP"));
00056     layout->addWidget(auth, 0, 1);
00057 
00058     connect( auth, SIGNAL(activated(const QString&)),
00059              SLOT(authChanged(const QString&)));
00060 
00061     QString tmp = tr("<p>Specifies the method used to identify yourself to\n"
00062              "the PPP server. Most universities still use\n"
00063              "<b>Terminal</b>- or <b>Script</b>-based authentication,\n"
00064              "while most ISP use <b>PAP</b> and/or <b>CHAP</b>. If\n"
00065              "unsure, contact your ISP.\n"
00066              "\n"
00067              "If you can choose between PAP and CHAP,\n"
00068              "choose CHAP, because it's much safer. If you don't know\n"
00069              "whether PAP or CHAP is right, choose PAP/CHAP.");
00070 
00071     QWhatsThis::add(auth_l,tmp);
00072     QWhatsThis::add(auth,tmp);
00073 
00074     user_l = new QLabel( tr("Username: "), this);
00075     layout->addWidget( user_l, 1, 0 );
00076     userName = new QLineEdit( this, "usernameEdit" );
00077     layout->addWidget( userName, 1, 1 );
00078     tmp = tr("Enter your username here...");
00079     QWhatsThis::add( user_l, tmp );
00080     QWhatsThis::add( userName, tmp );
00081 
00082     pw_l = new QLabel( tr("Password: "), this);
00083     layout->addWidget( pw_l, 2, 0 );
00084     passWord = new QLineEdit( this, "pw" );
00085     passWord->setAutoMask( true );
00086     passWord->setEchoMode( QLineEdit::Password );
00087     layout->addWidget( passWord, 2, 1 );
00088     hidePw = new QToolButton( this );
00089     hidePw->setPixmap( QPixmap( ( const char** ) image0_data ) );
00090     hidePw->setToggleButton( true );
00091     layout->addWidget( hidePw, 2, 2 );
00092 
00093     connect(hidePw, SIGNAL(toggled(bool)), SLOT(toggleEchoMode(bool)));
00094 
00095     tmp = tr("Enter your password here");
00096     QWhatsThis::add( pw_l, tmp );
00097     QWhatsThis::add( passWord, tmp );
00098 
00099     store_password = new QCheckBox(tr("Store password"), this);
00100     layout->addMultiCellWidget(store_password, 3, 3, 0, 1, AlignRight);
00101     QWhatsThis::add(store_password,
00102                   tr("<p>When this is turned on, your ISP password\n"
00103                        "will be saved in <i>kppp</i>'s config file, so\n"
00104                        "you do not need to type it in every time.\n"
00105                        "\n"
00106                        "<b><font color=\"red\">Warning:</font> your password will be stored as\n"
00107                        "plain text in the config file, which is\n"
00108                        "readable only to you. Make sure nobody\n"
00109                        "gains access to this file!"));
00110 
00111     if (isNewAccount){
00112         // select PAP/CHAP as default
00113         auth->setCurrentItem(AUTH_PAPCHAP);
00114         store_password->setChecked(true);
00115     }else{
00116         auth->setCurrentItem(_pppdata->authMethod());
00117         authChanged( auth->currentText() );
00118         userName->setText( _pppdata->storedUsername() );
00119         store_password->setChecked(_pppdata->storePassword());
00120         if (store_password->isChecked())
00121             passWord->setText( _pppdata->storedPassword() );
00122     }
00123 }
00124 
00125 bool AuthWidget::check()
00126 {
00127     bool ret = true;
00128     if (scriptWidget){
00129         if (!scriptWidget->check()){
00130             QMessageBox::critical(this, tr("error"), tr("<qt>Login script has unbalanced loop Start/End<qt>"));
00131             ret = false;
00132         }
00133     }
00134     return ret;
00135 }
00136 
00137 void AuthWidget::save()
00138 {
00139     _pppdata->setAuthMethod(auth->currentItem());
00140     if (scriptWidget) scriptWidget->save();
00141     _pppdata->setStoredUsername( userName->text() );
00142     _pppdata->setStorePassword(store_password->isChecked());
00143     if (store_password->isChecked())
00144         _pppdata->setStoredPassword( passWord->text() );
00145 }
00146 
00147 void AuthWidget::authChanged( const QString &authStr )
00148 {
00149     odebug << "AuthWidget::authChanged( " << authStr.latin1() << " )" << oendl; 
00150     if ( authStr.contains( tr("Script-based") ) ){
00151         showUsernamePassword( false );
00152         showScriptWindow( true );
00153     } else if ( authStr.contains( tr("PAP") ) ||
00154                 authStr.contains( tr("CHAP") ) ){
00155         showUsernamePassword( true );
00156         showScriptWindow( false );
00157     } else {
00158         odebug << "do not really know how to handle" << oendl; 
00159         showUsernamePassword( false );
00160         showScriptWindow( false );
00161     }
00162 }
00163 
00164 
00165 void AuthWidget::showUsernamePassword( bool show )
00166 {
00167     if (show){
00168         user_l->show();
00169         userName->show();
00170         pw_l->show();
00171         passWord->show();
00172         store_password->show();
00173         hidePw->show();
00174     }else{
00175         user_l->hide();
00176         userName->hide();
00177         pw_l->hide();
00178         passWord->hide();
00179         store_password->hide();
00180         hidePw->hide();
00181     }
00182 }
00183 
00184 void AuthWidget::showScriptWindow( bool show )
00185 {
00186     if (show){
00187         if (!scriptWidget){
00188             scriptWidget = new ScriptWidget( _pppdata, this, isNewAccount, "scriptWid");
00189             layout->addMultiCellWidget( scriptWidget, 1, 4, 0, 1 );
00190         }
00191         scriptWidget->show();
00192     }else{ // !show
00193         if (scriptWidget) scriptWidget->hide();
00194     }
00195 }
00196 
00197 void AuthWidget::toggleEchoMode( bool t )
00198 {
00199     passWord->setEchoMode( t ? QLineEdit::Normal : QLineEdit::Password );
00200 }
00201 

Generated on Sat Nov 5 16:17:49 2005 for OPIE by  doxygen 1.4.2