2
This file is part of KDE.
4
Copyright (c) 2009 Frederik Gladhorn <gladhorn@kde.org>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program 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.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22
#include "loginwidget.h"
24
#include <QtGui/QGraphicsGridLayout>
25
#include <QtGui/QGraphicsLinearLayout>
27
#include <KConfigGroup>
28
#include <KIconLoader>
31
#include <KCMultiDialog>
34
#include <Plasma/IconWidget>
35
#include <Plasma/Service>
36
#include <Plasma/ServiceJob>
38
#include "contactimage.h"
42
using namespace Plasma;
44
LoginWidget::LoginWidget(DataEngine* engine, QGraphicsWidget* parent)
45
: QGraphicsWidget(parent),
48
//int avatarSize = KIconLoader::SizeMedium;
49
//int actionSize = KIconLoader::SizeSmallMedium;
51
m_serverLabel = new Label;
52
m_serverLabel->setText(i18n("<b>Login to \"openDesktop.org\"</b>"));
54
m_userLabel = new Label;
55
m_passwordLabel = new Label;
56
m_userLabel->setText(i18n("Username:"));
57
m_passwordLabel->setText(i18n("Password:"));
59
m_userEdit = new LineEdit;
60
m_passwordEdit = new LineEdit;
61
m_passwordEdit->nativeWidget()->setPasswordMode(true);
63
QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this);
64
layout->addItem(m_serverLabel);
65
layout->addItem(m_userLabel);
66
layout->addItem(m_userEdit);
67
layout->addItem(m_passwordLabel);
68
layout->addItem(m_passwordEdit);
71
int buttonsize = KIconLoader::SizeMedium + 4;
72
Plasma::IconWidget* loginButton = new Plasma::IconWidget;
73
loginButton->setIcon("dialog-ok");
74
loginButton->setText(i18n("Login"));
75
loginButton->setOrientation(Qt::Horizontal);
76
loginButton->setMaximumHeight(buttonsize);
77
loginButton->setDrawBackground(true);
78
loginButton->setTextBackgroundColor(QColor(Qt::transparent));
79
loginButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
80
layout->addItem(loginButton);
82
Plasma::IconWidget* registerButton = new Plasma::IconWidget;
83
registerButton->setIcon("list-add-user");
84
registerButton->setText(i18n("Register new account..."));
85
registerButton->setOrientation(Qt::Horizontal);
86
registerButton->setMaximumHeight(buttonsize);
87
registerButton->setDrawBackground(true);
88
registerButton->setTextBackgroundColor(QColor(Qt::transparent));
89
registerButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
90
layout->addItem(registerButton);
92
connect(loginButton, SIGNAL(clicked()), SLOT(login()));
93
connect(registerButton, SIGNAL(clicked()), SLOT(registerNewAccount()));
96
void LoginWidget::setProvider(const QString& provider)
98
m_provider = provider;
101
void LoginWidget::login()
103
if (!m_userEdit->text().isEmpty()) {
104
kDebug() << "set credentials: " << m_provider << m_userEdit->text() << m_passwordEdit->text();
105
Service* service = m_engine->serviceForSource(settingsQuery(m_provider, "setCredentials"));
106
KConfigGroup cg = service->operationDescription("setCredentials");
107
cg.writeEntry("username", m_userEdit->text());
108
cg.writeEntry("password", m_passwordEdit->text());
109
ServiceJob* job = service->startOperationCall(cg);
110
connect(job, SIGNAL(finished(KJob*)), this, SLOT(loginJobFinished(KJob*)));
114
void LoginWidget::loginJobFinished(KJob* job)
116
kDebug() << "Login Job finished: " << job->error();
118
emit loginFinished();
122
void LoginWidget::registerNewAccount()
124
KToolInvocation::invokeBrowser("https://www.opendesktop.org/usermanager/new.php");
126
/* TODO: use the kcm instead
128
KCM.setWindowTitle( i18n( "Open Collaboration Providers" ) );
129
KCM.addModule( "kcm_attica" );
136
#include "loginwidget.moc"