Emit error signal when login fails
[situare] / src / ui / logindialog.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #include <QDebug>
23 #include <QDialogButtonBox>
24 #include <QFormLayout>
25 #include <QLabel>
26 #include <QLineEdit>
27 #include <QPushButton>
28
29 #include "logindialog.h"
30
31 LoginDialog::LoginDialog(QWidget *parent)
32     : QDialog(parent)
33 {
34     qDebug() << __PRETTY_FUNCTION__;
35
36     setWindowTitle(tr("Login to Situare with Facebook account"));
37
38     m_emailEdit = new QLineEdit();
39     m_passwordEdit = new QLineEdit();
40     m_passwordEdit->setEchoMode(QLineEdit::Password);
41
42     QGridLayout *gridLayout = new QGridLayout(this);
43     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
44     QPushButton *connectButton = buttonBox->addButton(QDialogButtonBox::Ok);
45     QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
46     connectButton->setText(tr("Login"));
47
48     QFormLayout *form = new QFormLayout();
49     form->addRow(new QLabel(tr("E-mail:")), m_emailEdit);
50     form->addRow(new QLabel(tr("Password:")), m_passwordEdit);
51
52     gridLayout->addLayout(form, 0, 0, 2, 1);
53     gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
54
55     connect(connectButton, SIGNAL(clicked()),
56             this, SLOT(accept()));
57     connect(cancelButton, SIGNAL(clicked()),
58             this, SLOT(reject()));
59
60     setLayout(gridLayout);
61 }
62
63 void LoginDialog::setEmailField(const QString &email)
64 {
65     qDebug() << __PRETTY_FUNCTION__;
66     if(!email.isEmpty()) {
67         m_emailEdit->setText(email);
68         m_passwordEdit->setFocus(Qt::OtherFocusReason);
69     }
70 }
71
72 void LoginDialog::clearTextFields()
73 {
74     qDebug() << __PRETTY_FUNCTION__;
75
76     m_passwordEdit->clearFocus();
77     m_emailEdit->setText(""); // clear() method bugging in Qt 4.6, it leaves "dead" cursor
78     m_emailEdit->setFocus(Qt::OtherFocusReason);
79     m_passwordEdit->setText("");
80
81 }
82
83 void LoginDialog::userInput(QString &email, QString &password)
84 {
85     qDebug() << __PRETTY_FUNCTION__;
86
87     email = m_emailEdit->text();
88     password = m_passwordEdit->text();
89 }