Git commit ca0f45a6ed4a0c26a6462e685eff04146dcb8877 by Alex Fiestas. Committed on 09/05/2012 at 06:57. Pushed by mklapetek into branch 'master'. Add custom "AccountWidgets" depending on the type A +144 -0 oaccountwidget.cpp [License: GPL (v2+)] A +57 -0 oaccountwidget.h [License: GPL (v2+)] http://commits.kde.org/kaccounts-providers/ca0f45a6ed4a0c26a6462e685eff0414= 6dcb8877 diff --git a/oaccountwidget.cpp b/oaccountwidget.cpp new file mode 100644 index 0000000..137c5ec --- /dev/null +++ b/oaccountwidget.cpp @@ -0,0 +1,144 @@ +/*************************************************************************= ************ + * Copyright (C) 2012 by Alejandro Fiestas Olivares = * + * = * + * 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-1= 301, USA * + *************************************************************************= ************/ +#include "oaccountwidget.h" + +#include "google/pages/serviceoption.h" +#include "owncloud/jobs/ocreatecontact.h" +#include "owncloud/jobs/ocreatecalendar.h" +#include "owncloud/jobs/ocreatefile.h" +#include "owncloud/jobs/oremovefile.h" +#include "owncloud/jobs/oremovecalendar.h" +#include "owncloud/jobs/oremovecontact.h" + +#include + +OAccountWidget::OAccountWidget(KConfigGroup group, QWidget* parent) + : QWidget(parent) + , m_config(group) +{ + setupUi(this); + + int status =3D 0; + KConfigGroup services =3D m_config.group("services"); + QStringList keys =3D services.keyList(); + Q_FOREACH(const QString &key, keys) { + status =3D services.readEntry(key, 0); + m_serviceWidgets[key] =3D new ServiceOption(key, key, this); + m_serviceWidgets[key]->setStatus(status); + connect(m_serviceWidgets[key], SIGNAL(toggled(QString,bool)), this, +SLOT(serviceChanged(QString,bool))); + d_layout->addWidget(m_serviceWidgets[key]); + } +} + +OAccountWidget::~OAccountWidget() +{ + +} + +void OAccountWidget::serviceChanged(const QString& service, bool enabled) +{ + if (service =3D=3D "Calendar") { + modifyCalendar(enabled); + return; + } + + if (service =3D=3D "Contact") { + modifyContact(enabled); + return; + } + + if (service =3D=3D "File") { + modifyFile(enabled); + return; + } + + qWarning() << "Not implemented service: " << service; +} + +void OAccountWidget::updateService(const QString& name) +{ + int status =3D m_config.group("services").readEntry(name, -1); + m_serviceWidgets[name]->setStatus(status); +} + +void OAccountWidget::modifyCalendar(bool enabled) +{ + if (!enabled) { + ORemoveCalendar *removeCalendar =3D new ORemoveCalendar(m_config, = this); + connect(removeCalendar, SIGNAL(finished(KJob*)), this, SLOT(update= Calendar())); + removeCalendar->start(); + return; + } + + OCreateCalendar *createCalendar =3D new OCreateCalendar(m_config, this= ); + connect(createCalendar, SIGNAL(finished(KJob*)), this, SLOT(updateCale= ndar())); + createCalendar->start(); +} + +void OAccountWidget::modifyFile(bool enabled) +{ + if (!enabled) { + ORemoveFile *removeFile =3D new ORemoveFile(m_config, this); + connect(removeFile, SIGNAL(finished(KJob*)), this, SLOT(updateFile= ())); + removeFile->start(); + return; + } + + OCreateFile *createFile =3D new OCreateFile(m_config, this); + connect(createFile, SIGNAL(finished(KJob*)), this, SLOT(updateFile())); + createFile->start(); +} + +void OAccountWidget::modifyContact(bool enabled) +{ + if (!enabled) { + ORemoveContact *removeContact =3D new ORemoveContact(m_config, thi= s); + connect(removeContact, SIGNAL(finished(KJob*)), this, SLOT(updateC= ontact())); + removeContact->start(); + return; + } + + OCreateContact *createContact =3D new OCreateContact(m_config, this); + connect(createContact, SIGNAL(finished(KJob*)), this, SLOT(updateConta= ct())); + createContact->start(); +} + +void OAccountWidget::updateCalendar() +{ + updateService("Calendar"); +} + +void OAccountWidget::updateFile() +{ + updateService("File"); +} + +void OAccountWidget::updateContact() +{ + updateService("Contact"); +} + +void OAccountWidget::updateAll() +{ + KConfigGroup services =3D m_config.group("services"); + QStringList keys =3D services.keyList(); + Q_FOREACH(const QString &key, keys) { + updateService(key); + } +} \ No newline at end of file diff --git a/oaccountwidget.h b/oaccountwidget.h new file mode 100644 index 0000000..cf343d9 --- /dev/null +++ b/oaccountwidget.h @@ -0,0 +1,57 @@ +/*************************************************************************= ************ + * Copyright (C) 2012 by Alejandro Fiestas Olivares = * + * = * + * 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-1= 301, USA * + *************************************************************************= ************/ + +#ifndef O_ACCOUNTWIDGET_H +#define O_ACCOUNTWIDGET_H + +#include "ui_services.h" + +#include + +#include + +class ServiceOption; +class OAccountWidget : public QWidget, Ui::Services +{ +Q_OBJECT + public: + explicit OAccountWidget(KConfigGroup group, QWidget* parent); + virtual ~OAccountWidget(); + + public Q_SLOTS: + void serviceChanged(const QString& service, bool enabled); + + private Q_SLOTS: + void updateCalendar(); + void updateContact(); + void updateFile(); + + void updateAll(); + + private: + void modifyCalendar(bool enabled); + void modifyContact(bool enabled); + void modifyFile(bool enabled); + + void updateService(const QString &name); + private: + KConfigGroup m_config; + QHash m_serviceWidgets; +}; + +#endif //O_ACCOUNTWIDGET_H \ No newline at end of file