~ubuntu-branches/ubuntu/trusty/kdeplasma-addons/trusty

« back to all changes in this revision

Viewing changes to applets/community/loginwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mfrom: (1.1.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100525095014-6mlrm9z9bkws0zkt
Tags: 4:4.4.80-0ubuntu1
* New upstream beta release:
  - Bump kde-sc-dev-latest build-dep version to 4.4.80
  - Refresh kubuntu_04_kimpanel_disable_scim.diff
  - Update various .install files
  - Drop liblancelot0a and liblancelot-dev packages; Upstream has broken ABI
    without an .so version bump, and after discussion with Debian it was
    decided it was not worth it to ship an unstable library.
  - Add liblancelot files to plasma-widget-lancelot, adding appropriate
    Replaces: entries
* Switch to source format 3.0 (quilt):
  - Bump debhelper build-depend version to 7.3.16 or greater

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of KDE.
 
3
 
 
4
    Copyright (c) 2009 Frederik Gladhorn <gladhorn@kde.org>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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,
 
19
    USA.
 
20
*/
 
21
 
 
22
#include "loginwidget.h"
 
23
 
 
24
#include <QtGui/QGraphicsGridLayout>
 
25
#include <QtGui/QGraphicsLinearLayout>
 
26
 
 
27
#include <KConfigGroup>
 
28
#include <KIconLoader>
 
29
#include <KTextEdit>
 
30
#include <KJob>
 
31
#include <KCMultiDialog>
 
32
#include <KLineEdit>
 
33
 
 
34
#include <Plasma/IconWidget>
 
35
#include <Plasma/Service>
 
36
#include <Plasma/ServiceJob>
 
37
 
 
38
#include "contactimage.h"
 
39
#include "utils.h"
 
40
 
 
41
 
 
42
using namespace Plasma;
 
43
 
 
44
LoginWidget::LoginWidget(DataEngine* engine, QGraphicsWidget* parent)
 
45
        : QGraphicsWidget(parent),
 
46
        m_engine(engine)
 
47
{
 
48
    //int avatarSize = KIconLoader::SizeMedium;
 
49
    //int actionSize = KIconLoader::SizeSmallMedium;
 
50
    
 
51
    m_serverLabel = new Label;
 
52
    m_serverLabel->setText(i18n("<b>Login to \"openDesktop.org\"</b>"));
 
53
    
 
54
    m_userLabel = new Label;
 
55
    m_passwordLabel = new Label;
 
56
    m_userLabel->setText(i18n("Username:"));
 
57
    m_passwordLabel->setText(i18n("Password:"));
 
58
    
 
59
    m_userEdit = new LineEdit;
 
60
    m_passwordEdit = new LineEdit;
 
61
    m_passwordEdit->nativeWidget()->setPasswordMode(true);
 
62
 
 
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);
 
69
    
 
70
    
 
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);
 
81
 
 
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);
 
91
    
 
92
    connect(loginButton, SIGNAL(clicked()), SLOT(login()));
 
93
    connect(registerButton, SIGNAL(clicked()), SLOT(registerNewAccount()));
 
94
}
 
95
 
 
96
void LoginWidget::setProvider(const QString& provider)
 
97
{
 
98
    m_provider = provider;
 
99
}
 
100
 
 
101
void LoginWidget::login()
 
102
{
 
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*)));
 
111
    }
 
112
}
 
113
 
 
114
void LoginWidget::loginJobFinished(KJob* job)
 
115
{
 
116
    kDebug() << "Login Job finished: " << job->error();
 
117
    if (!job->error()) {
 
118
        emit loginFinished();
 
119
    }
 
120
}
 
121
 
 
122
void LoginWidget::registerNewAccount()
 
123
{
 
124
    KToolInvocation::invokeBrowser("https://www.opendesktop.org/usermanager/new.php");
 
125
 
 
126
    /* TODO: use the kcm instead
 
127
    KCMultiDialog KCM;
 
128
    KCM.setWindowTitle( i18n( "Open Collaboration Providers" ) );
 
129
    KCM.addModule( "kcm_attica" );
 
130
 
 
131
    KCM.exec();
 
132
    */
 
133
}
 
134
 
 
135
 
 
136
#include "loginwidget.moc"