00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "loginform.h"
00021
00022 #include <player/lib/authentication.h>
00023
00024 #include <attica/provider.h>
00025
00026 #include <QDebug>
00027
00028 LoginForm::LoginForm( QWidget* parent, Qt::WindowFlags wFlags )
00029 : Overlay( parent, wFlags )
00030 , m_usernameLineEdit( new QLineEdit( this ) )
00031 , m_passwordLineEdit( new QLineEdit( this ) )
00032 , m_loginButton( new QPushButton( this ) )
00033 , m_busyWidget( new QProgressBar( this ) )
00034 , m_usernameLabel( new QLabel( this ) )
00035 , m_passwordLabel( new QLabel( this ) )
00036 , m_rememberMeCheckBox( new QCheckBox( this ) )
00037 {
00038 m_usernameLabel->setText( tr( "Username" ) );
00039 m_passwordLabel->setText( tr( "Password" ) );
00040 m_loginButton->setIcon( QIcon( "network-connect" ) );
00041 m_loginButton->setText( tr( "Login" ) );
00042 m_loginButton->setEnabled( false );
00043
00044 m_busyWidget->hide();
00045
00046 QGridLayout* layout1 = static_cast<QGridLayout*>(layout());
00047 layout1->addWidget( m_usernameLabel, 0, 0 );
00048 layout1->addWidget( m_passwordLabel, 0, 1);
00049 layout1->addWidget( m_usernameLineEdit, 1, 0 );
00050 layout1->addWidget( m_passwordLineEdit, 1, 1 );
00051 layout1->addWidget( m_loginButton, 2, 0 );
00052 layout1->addWidget( m_rememberMeCheckBox, 2, 1 );
00053
00054
00055
00056
00057
00058
00059
00060 connect( m_loginButton, SIGNAL( clicked() ), SLOT( doLogin() ) );
00061 connect( GluonPlayer::Authentication::instance(), SIGNAL( initialized() ), SLOT( initDone() ) );
00062 connect( GluonPlayer::Authentication::instance(), SIGNAL( initFailed() ), SLOT( initFailed() ) );
00063 connect( GluonPlayer::Authentication::instance(), SIGNAL( loggedIn() ), SLOT( loginDone() ) );
00064 connect( GluonPlayer::Authentication::instance(), SIGNAL( loginFailed() ), SLOT( loginFailed() ) );
00065
00066 initialize();
00067 }
00068
00069 void LoginForm::initialize()
00070 {
00071 GluonPlayer::Authentication::instance()->init();
00072 }
00073
00074 void LoginForm::initDone()
00075 {
00076 loadCredentials();
00077 m_loginButton->setEnabled( true );
00078 }
00079
00080 void LoginForm::initFailed()
00081 {
00082 qDebug() << "Initialization failed";
00083 }
00084
00085 void LoginForm::doLogin()
00086 {
00087 if( m_usernameLineEdit->text().isEmpty())
00088 {
00089 qDebug() << "Empty username";
00090 return;
00091 }
00092
00093 if ( m_passwordLineEdit->text().isEmpty() )
00094 {
00095 qDebug() << "Empty password";
00096 return;
00097 }
00098
00099 m_loginButton->setEnabled( false );
00100 m_busyWidget->show();
00101 GluonPlayer::Authentication::instance()->login( m_usernameLineEdit->text(), m_passwordLineEdit->text() );
00102
00103 m_resultLabel->setText( tr( "Logging in" ) );
00104 }
00105
00106 void LoginForm::loginDone()
00107 {
00108 m_busyWidget->hide();
00109 m_resultLabel->setText(tr( QString("Logged in as %1").arg(GluonPlayer::Authentication::instance()->username() ).toAscii() ) );
00110 m_loginButton->setEnabled( true );
00111 }
00112
00113 void LoginForm::loginFailed()
00114 {
00115 m_busyWidget->hide();
00116 m_resultLabel->setText( tr( "Login Failed" ) );
00117 m_loginButton->setEnabled( true );
00118 }
00119
00120 void LoginForm::loadCredentials()
00121 {
00122 m_usernameLineEdit->setText( GluonPlayer::Authentication::instance()->username() );
00123 m_passwordLineEdit->setText( GluonPlayer::Authentication::instance()->password() );
00124 }
00125
00126 #include "loginform.moc"