~ubuntu-branches/ubuntu/hardy/nuapplet/hardy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 ** Copyright 2004-2007 - INL
 ** Written by Eric Leblond <eric.leblond@inl.fr>
 **            Vincent Deffontaines <vincent@inl.fr>
 ** INL http://www.inl.fr/
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation, version 2 of the License.
 **
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 **
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <nuclient.h>
#include <QtGui>

#include "systray.h"
#include "auth_dlg.h"
#include "auth_dlg.moc"

/*
 * See http://doc.trolltech.com/4.3/mainwindows-application.html
 */

NuAppAuthDialog::NuAppAuthDialog(QObject* _parent) : QDialog(NULL, Qt::Dialog),
	parent(_parent)
{
	createDialog();

	resize(10, 10);
}

void NuAppAuthDialog::createDialog()
{
	settings.sync();

	// Username
	QLabel *usernameLabel = new QLabel( tr("Username"));
	username = new QLineEdit();
	username->setFocus();

	// Password
	QLabel *passwordLabel = new QLabel( tr("Password"));
	password = new QLineEdit();
	password->setEchoMode(QLineEdit::Password);

	QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);

	QVBoxLayout *layout = new QVBoxLayout(this);
	layout->addWidget(usernameLabel);
	layout->addWidget(username);
	layout->addWidget(passwordLabel);
	layout->addWidget(password);
	layout->addWidget(buttonBox);

	QObject::connect(this, SIGNAL(start_auth(QString, QString)), parent, SLOT(start_auth(QString, QString)));
	QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(get_user_infos()));
	QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

	QIcon icon = QIcon(":/images/nuapplet2-running.png");
	setWindowIcon(icon);
	setWindowTitle(tr("Authentication"));
}

void NuAppAuthDialog::get_user_infos()
{
	settings.setValue("username", username->text());
	settings.sync();
	emit start_auth(username->text(), password->text());
	password->setText("");

	accept();
}

void NuAppAuthDialog::show()
{
	if(settings.value("username").toString() != "")
		password->setFocus();
	username->setText(settings.value("username").toString());
	QDialog::show();
}