2 * This file is part of Maemo 5 Office UI for KOffice
4 * Copyright (C) 2010 Manikandaprasad N C <maninc@gmail.com>.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include "loginwindow.h"
25 #include "googledocumentservice.h"
26 #include "googlelistdialog.h"
27 #include "slideshare.h"
28 #include "slidesharelistdialog.h"
29 #include "encryptsupport.h"
35 #include <QMaemo5InformationBox>
37 #include <X11/Xatom.h>
39 LoginWindow::LoginWindow(QWidget *parent)
41 m_authDialog(new Ui_Dialog),
42 settings(new QSettings("freoffice", "online-services-plugin", this)),
43 cipher(new encryptSupport(this))
45 m_authDialog->setupUi(this);
47 QStringList onlineServices;
48 onlineServices << "Google Documents";
50 onlineServices << "Slide Share";
51 m_authDialog->comboBox->addItems(onlineServices);
53 connect(m_authDialog->loginButton, SIGNAL(clicked()), this, SLOT(loginService()));
54 connect(m_authDialog->comboBox, SIGNAL(activated(int)), this, SLOT(serviceSelected(int)));
56 m_authDialog->userEdit->setInputMethodHints(Qt::ImhNoAutoUppercase);
57 m_authDialog->userEdit->setFocus();
61 LoginWindow::~LoginWindow()
66 void LoginWindow::setOpenDoc(const QString & openDocPath)
68 this->openDocPath = openDocPath;
71 void LoginWindow::loginService()
73 if("" == m_authDialog->userEdit->text() || "" == m_authDialog->passwordEdit->text()) {
74 QMaemo5InformationBox::information(this, "Enter both username and password", QMaemo5InformationBox::DefaultTimeout);
78 if(0 == m_authDialog->comboBox->currentIndex()) {
79 gdoc = new GoogleDocumentService();
80 setShowProgressIndicator(true);
81 gdoc->clientLogin(m_authDialog->userEdit->text(), m_authDialog->passwordEdit->text());
82 connect(gdoc, SIGNAL(userAuthenticated(bool)), this, SLOT(authenticated(bool)));
84 if(1 == m_authDialog->comboBox->currentIndex()) {
85 service = new SlideShare(this);
86 service->setApikey(new QString("KhSMYyiF"));
87 service->setsecretKey(new QString("HDXhAC5g"));
88 service->setUsername(new QString(m_authDialog->userEdit->text()));
89 service->setPassword(new QString(m_authDialog->passwordEdit->text()));
91 setShowProgressIndicator(true);
92 connect(service, SIGNAL(loginDone(bool)), this, SLOT(slideShareLoginDoneSlot(bool)));
96 void LoginWindow::serviceSelected(int index)
99 m_authDialog->userEdit->setText("@gmail.com");
100 m_authDialog->passwordEdit->clear();
101 } else if(index == 1) {
102 m_authDialog->userEdit->clear();
103 m_authDialog->passwordEdit->clear();
106 m_authDialog->userEdit->setFocus();
109 void LoginWindow::authenticated(bool success)
112 QString key("user/gdocs");
114 googleListDialog *ld = new googleListDialog(gdoc, this);
115 ld->setOpenDoc(openDocPath);
119 QMaemo5InformationBox::information(this, ("<p>Login Failed</p><p>Check your username & password</p>"), QMaemo5InformationBox::NoTimeout);
124 void LoginWindow::setShowProgressIndicator(bool visible)
126 unsigned long val = visible ? 1 : 0;
127 Atom atom = XInternAtom(QX11Info::display(),
128 "_HILDON_WM_WINDOW_PROGRESS_INDICATOR", False);
129 XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
131 (unsigned char *) &val, 1);
134 void LoginWindow::slideShareLoginDoneSlot(bool loginStatus)
136 if(loginStatus == false) {
137 QMaemo5InformationBox::information(this, "<p>Login Failed.</p><p>Check your username and password</p> ", QMaemo5InformationBox::NoTimeout);
140 QString key("user/slideshare");
142 slideshareListDialog * ld = new slideshareListDialog(service, this);
143 ld->setOpenDoc(openDocPath);
149 void LoginWindow::enableWidgets()
151 setShowProgressIndicator(false);
152 m_authDialog->loginButton->setEnabled(true);
153 m_authDialog->userEdit->setEnabled(true);
154 m_authDialog->passwordEdit->setEnabled(true);
155 m_authDialog->comboBox->setEnabled(true);
156 m_authDialog->saveCheckBox->setEnabled(true);
159 void LoginWindow::disableWidgets()
161 m_authDialog->loginButton->setEnabled(false);
162 m_authDialog->userEdit->setEnabled(false);
163 m_authDialog->passwordEdit->setEnabled(false);
164 m_authDialog->comboBox->setEnabled(false);
165 m_authDialog->saveCheckBox->setEnabled(false);
168 void LoginWindow::saveDetails(QString &key)
170 if(Qt::Checked == m_authDialog->saveCheckBox->checkState()) {
172 QString username = m_authDialog->userEdit->text();
173 QString password = m_authDialog->passwordEdit->text();
174 m.insert("username", username);
175 m.insert("password", cipher->encrypt(password));
176 settings->setValue(key, m);
178 settings->remove(key);
182 void LoginWindow::fillDetails()
185 if(0 == m_authDialog->comboBox->currentIndex())
187 else if(1 == m_authDialog->comboBox->currentIndex())
188 key = "user/slideshare";
191 if(settings->contains(key)) {
192 QVariantMap m = settings->value(key).value<QVariantMap>();
193 QString username = m.value("username").toString();
194 QString password = m.value("password").toString();
195 m_authDialog->userEdit->setText(username);
196 m_authDialog->passwordEdit->setText(cipher->decrypt(password));
197 m_authDialog->saveCheckBox->setCheckState(Qt::Checked);
199 m_authDialog->saveCheckBox->setCheckState(Qt::Unchecked);