Merge branch 'master' into userinfo
[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 <QtGui>
23 #include <QDebug>
24 #include <QFormLayout>
25 #include "logindialog.h"
26
27 LoginDialog::LoginDialog(QWidget *parent)
28     : QDialog(parent)
29 {
30     qDebug() << __PRETTY_FUNCTION__;
31
32     setWindowTitle(tr("Login to Situare with Facebook account"));
33
34     m_emailEdit = new QLineEdit();
35     m_passwordEdit = new QLineEdit();
36     m_passwordEdit->setEchoMode(QLineEdit::Password);
37
38     QGridLayout *gridLayout = new QGridLayout(this);
39     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
40     QPushButton *connectButton = buttonBox->addButton(QDialogButtonBox::Ok);
41     QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
42     connectButton->setText(tr("Connect"));
43
44     QFormLayout *form = new QFormLayout();
45     form->addRow(new QLabel(tr("E-mail:")), m_emailEdit);
46     form->addRow(new QLabel(tr("Password:")), m_passwordEdit);
47
48     gridLayout->addLayout(form, 0, 0, 2, 1);
49     gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
50
51     connect(connectButton, SIGNAL(clicked()),
52             this, SLOT(connectPressed()));
53     connect(cancelButton, SIGNAL(clicked()),
54             this, SLOT(reject()));
55
56     setLayout(gridLayout);
57 }
58
59 void LoginDialog::connectPressed()
60 {
61     qDebug() << __PRETTY_FUNCTION__;
62
63     emit loginDialogDone(m_emailEdit->text(), m_passwordEdit->text());
64
65     accept();
66 }
67
68 void LoginDialog::setEmailField(const QString &email)
69 {
70     qDebug() << __PRETTY_FUNCTION__;
71     if(!email.isEmpty()) {
72         m_emailEdit->setText(email);
73         m_passwordEdit->setFocus(Qt::OtherFocusReason);
74     }
75 }
76
77 void LoginDialog::clearTextFields()
78 {
79     qDebug() << __PRETTY_FUNCTION__;
80
81     m_passwordEdit->clearFocus();
82     m_emailEdit->setText(""); // clear() method bugging in Qt 4.6.0, it leaves "dead" cursor
83     m_emailEdit->setFocus(Qt::OtherFocusReason);
84     m_passwordEdit->setText("");
85
86 }