a274a80b02b3de98f9fa725a905ddcbbe8ba1442
[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(accept()));
53     connect(cancelButton, SIGNAL(clicked()),
54             this, SLOT(reject()));
55
56     setLayout(gridLayout);
57 }
58
59 void LoginDialog::setEmailField(const QString &email)
60 {
61     qDebug() << __PRETTY_FUNCTION__;
62     if(!email.isEmpty()) {
63         m_emailEdit->setText(email);
64         m_passwordEdit->setFocus(Qt::OtherFocusReason);
65     }
66 }
67
68 void LoginDialog::clearTextFields()
69 {
70     qDebug() << __PRETTY_FUNCTION__;
71
72     m_passwordEdit->clearFocus();
73     m_emailEdit->setText(""); // clear() method bugging in Qt 4.6, it leaves "dead" cursor
74     m_emailEdit->setFocus(Qt::OtherFocusReason);
75     m_passwordEdit->setText("");
76
77 }
78
79 void LoginDialog::userInput(QString &email, QString &password)
80 {
81     qDebug() << __PRETTY_FUNCTION__;
82
83     email = m_emailEdit->text();
84     password = m_passwordEdit->text();
85 }