Commit 1fd48f2c authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

First import of the wizard to configure a Google Account

parent 1d44a3c8
......@@ -4,10 +4,15 @@ cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED)
find_package(KDE4 REQUIRED)
find_package(LibKGoogle REQUIRED)
add_definitions (${KDE4_DEFINITIONS}
-fexceptions
)
include(KDE4Defaults)
include(MacroOptionalAddSubdirectory)
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${LIBKGOOGLE_INCLUDE_DIR})
add_subdirectory(src)
\ No newline at end of file
......@@ -3,15 +3,20 @@
set(webaccounts_SRCS
webaccounts.cpp
create.cpp
google/google.cpp
google/credentials.cpp
google/oauth.cpp
google/services.cpp
google/serviceoption.cpp
)
qt4_automoc(${webaccounts_SRCS})
kde4_add_ui_files(webaccounts_SRCS kcm.ui types.ui)
kde4_add_ui_files(webaccounts_SRCS kcm.ui types.ui google/google.ui google/oauth.ui google/services.ui google/serviceoption.ui)
kde4_add_plugin(webaccounts ${webaccounts_SRCS})
target_link_libraries(webaccounts ${KDE4_KIO_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
target_link_libraries(webaccounts ${KDE4_KIO_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${LIBKGOOGLE_LIBRARY})
install(TARGETS webaccounts DESTINATION ${PLUGIN_INSTALL_DIR})
......
......@@ -17,12 +17,21 @@
*************************************************************************************/
#include "create.h"
#include "google/google.h"
#include "ui_types.h"
#include <QtCore/QDebug>
#include <QtGui/QWidget>
#include <libkgoogle/auth.h>
#include <libkgoogle/services/tasks.h>
#include <libkgoogle/services/contacts.h>
#include <libkgoogle/services/calendar.h>
using namespace KGoogle;
Create::Create(QWidget* parent)
: QObject(parent)
, m_form(0)
......@@ -60,7 +69,8 @@ void Create::stablishConnections()
void Create::startGoogle()
{
qDebug() << "Staring Google auth";
GoogleWizard *google = new GoogleWizard(m_parent);
google->show();
}
void Create::startFacebook()
......
......@@ -21,9 +21,15 @@
#include <QtCore/QObject>
#include <libkgoogle/account.h>
class QDialog;
class QWidget;
namespace Ui {
class Google;
class createForm;
}
class Create : public QObject
{
Q_OBJECT
......@@ -41,7 +47,10 @@ Q_OBJECT
void startLive();
private:
QDialog *m_dialog;
QWidget *m_parent;
Ui::Google *m_google;
Ui::createForm *m_form;
};
#endif// CREATE_H
\ No newline at end of file
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#include "credentials.h"
#include "google.h"
Credentials::Credentials(GoogleWizard* parent) : QWizardPage(parent)
{
setupUi(this);
googleIcon->setPixmap(QIcon::fromTheme("im-google-talk").pixmap(32, 32));
m_wizard = parent;
}
Credentials::~Credentials()
{
}
bool Credentials::validatePage()
{
if (email->text().isEmpty() || password->text().isEmpty()) {
return false;
}
m_wizard->setUsername(email->text());
m_wizard->setPassword(password->text());
return true;
}
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#ifndef GOOGLECREDENTIALS_H
#define GOOGLECREDENTIALS_H
#include "ui_google.h"
#include <QtGui/QWizardPage>
class GoogleWizard;
class Credentials : public QWizardPage, Ui::Google
{
Q_OBJECT
public:
Credentials(GoogleWizard *parent);
virtual ~Credentials();
virtual bool validatePage();
private:
GoogleWizard *m_wizard;
};
#endif //GOOGLECREDENTIALS_H
\ No newline at end of file
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#include "google.h"
#include "credentials.h"
#include "oauth.h"
#include "services.h"
GoogleWizard::GoogleWizard(QWidget* parent) : QWizard(parent)
{
Credentials *credentialsPage = new Credentials(this);
OAuth *oauth = new OAuth(this);
Services *services = new Services(this);
addPage(credentialsPage);
addPage(oauth);
addPage(services);
}
GoogleWizard::~GoogleWizard()
{
}
void GoogleWizard::setUsername(const QString& username)
{
m_username = username;
}
void GoogleWizard::setPassword(const QString& password)
{
m_password = password;
}
const QString GoogleWizard::username() const
{
return m_username;
}
const QString GoogleWizard::password() const
{
return m_password;
}
\ No newline at end of file
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#ifndef GOOGLEWIZARD_H
#define GOOGLEWIZARD_H
#include <QtGui/QWizard>
class GoogleWizard : public QWizard
{
Q_OBJECT
public:
GoogleWizard(QWidget *parent);
virtual ~GoogleWizard();
void setUsername(const QString &username);
void setPassword(const QString &password);
const QString username() const;
const QString password() const;
private:
QString m_username;
QString m_password;
};
#endif //GOOGLEWIZARD_H
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Google</class>
<widget class="QWidget" name="Google">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>333</width>
<height>106</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Google</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="googleIcon">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Email address:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="email"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#include "oauth.h"
#include "google/google.h"
#include <libkgoogle/auth.h>
#include <libkgoogle/services/tasks.h>
#include <libkgoogle/services/contacts.h>
#include <libkgoogle/services/calendar.h>
using namespace KGoogle;
OAuth::OAuth(GoogleWizard *parent)
: QWizardPage(parent)
, m_valid(false)
{
setupUi(this);
m_wizard = parent;
}
OAuth::~OAuth()
{
}
void OAuth::initializePage()
{
if (!accountExists()) {
getTokenForAccount();
return;
}
label->setText(i18n("Account already configured"));
m_valid = true;
Q_EMIT completeChanged();
}
bool OAuth::accountExists()
{
Auth::instance()->init("Akonadi Google",
"554041944266.apps.googleusercontent.com",
"mdT1DjzohxN3npUUzkENT0gO");
Account::Ptr acc;
try {
acc = Auth::instance()->getAccount(m_wizard->username());
} catch (Exception::BaseException &e) {
return false;
}
if (acc.isNull()) {
return false;
}
if (acc->accessToken().isEmpty() || acc->refreshToken().isEmpty()) {
return false;
}
return true;
}
void OAuth::getTokenForAccount()
{
Auth *auth = Auth::instance();
Account::Ptr acc(new KGoogle::Account());
acc->addScope(Services::Tasks::ScopeUrl);
acc->addScope(Services::Contacts::ScopeUrl);
acc->addScope(Services::Calendar::ScopeUrl);
acc->setAccountName(m_wizard->username());
auth->setUsername(m_wizard->username());
auth->setPassword(m_wizard->password());
auth->authenticate(acc, true);
connect(auth, SIGNAL(authenticated(KGoogle::Account::Ptr&)), this, SLOT(authenticated(KGoogle::Account::Ptr&)));
connect(auth, SIGNAL(error(KGoogle::Error,QString)), this, SLOT(error(KGoogle::Error,QString)));
}
void OAuth::authenticated(KGoogle::Account::Ptr& acc)
{
m_valid = true;
label->setText(i18n("Authenticated"));
}
void OAuth::error(Error , QString )
{
//TODO Show try again button
m_valid = false;
label->setText(i18n("Error trying to gain access"));
}
bool OAuth::validatePage()
{
return m_valid;
}
bool OAuth::isComplete() const
{
return m_valid;
}
\ No newline at end of file
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#ifndef GOOGLEOAUTH_H
#define GOOGLEOAUTH_H
#include "ui_oauth.h"
#include <libkgoogle/common.h>
#include <libkgoogle/account.h>
#include <QtGui/QWizardPage>
class GoogleWizard;
class OAuth : public QWizardPage, Ui::OAuth
{
Q_OBJECT
public:
OAuth(GoogleWizard *parent);
virtual ~OAuth();
virtual bool validatePage();
virtual void initializePage();
virtual bool isComplete() const;
private Q_SLOTS:
void error(KGoogle::Error, QString);
void authenticated(KGoogle::Account::Ptr& acc);
private:
bool accountExists();
void getTokenForAccount();
private:
bool m_valid;
GoogleWizard *m_wizard;
};
#endif //GOOGLEOAUTH_H
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OAuth</class>
<widget class="QWidget" name="OAuth">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>133</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Waiting for authorization...</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>132</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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; either version 2 *