First draft, credentials are still saved to settings
[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     connect(cancelButton, SIGNAL(clicked()),
56             this, SLOT(cancelPressed()));
57
58     setLayout(gridLayout);
59 }
60
61 void LoginDialog::cancelPressed()
62 {
63     qDebug() << __PRETTY_FUNCTION__;
64     this->deleteLater();
65     reject();
66 }
67
68 void LoginDialog::connectPressed()
69 {
70     qDebug() << __PRETTY_FUNCTION__;
71
72     emit loginDialogDone(m_emailEdit->text(), m_passwordEdit->text());
73     this->deleteLater();
74     accept();
75 }
76
77 void LoginDialog::setEmailField(const QString &email)
78 {
79     qDebug() << __PRETTY_FUNCTION__;
80     if(!email.isEmpty()) {
81         m_emailEdit->setText(email);
82         m_passwordEdit->setFocus(Qt::OtherFocusReason);
83     }
84 }
85
86 void LoginDialog::clearTextFields()
87 {
88     qDebug() << __PRETTY_FUNCTION__;
89
90     m_passwordEdit->clearFocus();
91     m_emailEdit->setText(""); // clear() method bugging in Qt 4.6, it leaves "dead" cursor
92     m_emailEdit->setFocus(Qt::OtherFocusReason);
93     m_passwordEdit->setText("");
94
95 }