From 4b1798f0cdf87361869e7cf2b341acacd056c410 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 5 Apr 2017 15:04:00 +0200 Subject: Moved cpp code into src directory --- framework/accounts/accountfactory.cpp | 71 ----------------------- framework/accounts/accountfactory.h | 53 ----------------- framework/accounts/accountsmodel.cpp | 101 --------------------------------- framework/accounts/accountsmodel.h | 67 ---------------------- framework/accounts/gmailcontroller.cpp | 89 ----------------------------- framework/accounts/gmailcontroller.h | 55 ------------------ 6 files changed, 436 deletions(-) delete mode 100644 framework/accounts/accountfactory.cpp delete mode 100644 framework/accounts/accountfactory.h delete mode 100644 framework/accounts/accountsmodel.cpp delete mode 100644 framework/accounts/accountsmodel.h delete mode 100644 framework/accounts/gmailcontroller.cpp delete mode 100644 framework/accounts/gmailcontroller.h (limited to 'framework/accounts') diff --git a/framework/accounts/accountfactory.cpp b/framework/accounts/accountfactory.cpp deleted file mode 100644 index 9dbb402b..00000000 --- a/framework/accounts/accountfactory.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright (c) 2016 Christian Mollekopf - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ -#include "accountfactory.h" - -#include - -#include -#include -#include - -#include "settings/settings.h" -#include - -AccountFactory::AccountFactory(QObject *parent) - : QObject(parent) -{ -} - -QString AccountFactory::name() const -{ - if (mName.isEmpty()) { - return tr("Account"); - } - return mName; -} - -void AccountFactory::setAccountId(const QString &accountId) -{ - mAccountId = accountId; - Sink::Store::fetchOne(Sink::Query().filter(accountId.toUtf8())) - .then([this](const Sink::ApplicationDomain::SinkAccount &account) { - mAccountType = account.getProperty("type").toByteArray(); - loadPackage(); - }).exec(); -} - -void AccountFactory::setAccountType(const QString &type) -{ - mAccountType = type.toLatin1(); - loadPackage(); -} - -void AccountFactory::loadPackage() -{ - auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + mAccountType); - if (!package.isValid()) { - qWarning() << "Failed to load account package: " << "org.kube.accounts." + mAccountType; - return; - } - Q_ASSERT(package.isValid()); - mUiPath = package.filePath("mainscript"); - mName = package.metadata().name(); - mIcon = package.metadata().iconName(); - emit accountLoaded(); -} diff --git a/framework/accounts/accountfactory.h b/framework/accounts/accountfactory.h deleted file mode 100644 index b57854e5..00000000 --- a/framework/accounts/accountfactory.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright (c) 2016 Christian Mollekopf - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#pragma once - -#include -#include - -/** - * A factory to instantiate account-plugins. - */ -class AccountFactory : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString accountId MEMBER mAccountId WRITE setAccountId); - Q_PROPERTY(QString accountType MEMBER mAccountType WRITE setAccountType); - Q_PROPERTY(QString name MEMBER mName READ name NOTIFY accountLoaded); - Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded); - Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded); -public: - explicit AccountFactory(QObject *parent = Q_NULLPTR); - - void setAccountId(const QString &); - void setAccountType(const QString &); - QString name() const; - -signals: - void accountLoaded(); - -private: - void loadPackage(); - QString mAccountId; - QString mName; - QString mIcon; - QString mUiPath; - QByteArray mAccountType; -}; diff --git a/framework/accounts/accountsmodel.cpp b/framework/accounts/accountsmodel.cpp deleted file mode 100644 index f98e8ca3..00000000 --- a/framework/accounts/accountsmodel.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - Copyright (c) 2016 Christian Mollekopf - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ -#include "accountsmodel.h" -#include - -using namespace Sink; -using namespace Sink::ApplicationDomain; - -AccountsModel::AccountsModel(QObject *parent) : QIdentityProxyModel() -{ - Sink::Query query; - query.setFlags(Query::LiveQuery); - query.request(); - query.request(); - query.request(); - runQuery(query); -} - -AccountsModel::~AccountsModel() -{ - -} - -QHash< int, QByteArray > AccountsModel::roleNames() const -{ - QHash roles; - - roles[Name] = "name"; - roles[Icon] = "icon"; - roles[AccountId] = "accountId"; - roles[Status] = "status"; - - return roles; -} - -QVariant AccountsModel::data(const QModelIndex &idx, int role) const -{ - auto srcIdx = mapToSource(idx); - auto account = srcIdx.data(Sink::Store::DomainObjectRole).value(); - switch (role) { - case Name: - return account->getName(); - case Icon: - return account->getIcon(); - case AccountId: - return account->identifier(); - case Status: - switch (account->getStatus()) { - case Sink::ApplicationDomain::ErrorStatus: - return ErrorStatus; - case Sink::ApplicationDomain::BusyStatus: - return BusyStatus; - case Sink::ApplicationDomain::ConnectedStatus: - return ConnectedStatus; - case Sink::ApplicationDomain::OfflineStatus: - return OfflineStatus; - } - return NoStatus; - } - return QIdentityProxyModel::data(idx, role); -} - -void AccountsModel::runQuery(const Sink::Query &query) -{ - mModel = Sink::Store::loadModel(query); - setSourceModel(mModel.data()); -} - -void AccountsModel::setAccountId(const QByteArray &accountId) -{ - qWarning() << "Setting account id" << accountId; - //Get all folders of an account - Sink::Query query; - query.filter(accountId); - query.setFlags(Query::LiveQuery); - query.request(); - query.request(); - query.request(); - runQuery(query); -} - -QByteArray AccountsModel::accountId() const -{ - return {}; -} diff --git a/framework/accounts/accountsmodel.h b/framework/accounts/accountsmodel.h deleted file mode 100644 index 2c82a8b9..00000000 --- a/framework/accounts/accountsmodel.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - Copyright (c) 2016 Christian Mollekopf - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#pragma once - -#include -#include -#include -#include - -namespace Sink { - class Query; -} - -class AccountsModel : public QIdentityProxyModel -{ - Q_OBJECT - - Q_PROPERTY (QByteArray accountId READ accountId WRITE setAccountId) -public: - enum Status { - OfflineStatus, - ConnectedStatus, - BusyStatus, - ErrorStatus, - NoStatus - }; - Q_ENUMS(Status) - - AccountsModel(QObject *parent = Q_NULLPTR); - ~AccountsModel(); - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - enum Roles { - Name = Qt::UserRole + 1, - Icon, - AccountId, - Status - }; - Q_ENUMS(Roles) - - QHash roleNames() const; - - void setAccountId(const QByteArray &id); - QByteArray accountId() const; - -private: - void runQuery(const Sink::Query &query); - QSharedPointer mModel; -}; diff --git a/framework/accounts/gmailcontroller.cpp b/framework/accounts/gmailcontroller.cpp deleted file mode 100644 index fda24b26..00000000 --- a/framework/accounts/gmailcontroller.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2017 Michael Bohlender, - * - * 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 "gmailcontroller.h" - -#include - -using namespace Sink; -using namespace Sink::ApplicationDomain; - -GmailController::GmailController() : Kube::Controller(), -action_create{new Kube::ControllerAction{this, &GmailController::create}}, -action_modify{new Kube::ControllerAction{this, &GmailController::modify}}, -action_remove{new Kube::ControllerAction{this, &GmailController::remove}} -{ - -} - -void GmailController::create() { - - //account - auto account = ApplicationDomainType::createEntity(); - account.setProperty("type", "imap"); - account.setProperty("name", getName()); - Store::create(account).exec().waitForFinished(); - - //imap - auto resource = ApplicationDomainType::createEntity(); - resource.setResourceType("sink.imap"); - resource.setAccount(account); - resource.setProperty("server","imaps://imap.gmail.com:993"); - resource.setProperty("username", getEmailAddress()); - resource.setProperty("password", getPassword()); - Store::create(resource).exec().waitForFinished(); - - //smtp - resource = ApplicationDomainType::createEntity(); - resource.setResourceType("sink.mailtransport"); - resource.setAccount(account); - resource.setProperty("server", "smtps://smtp.gmail.com:465"); - resource.setProperty("username", getEmailAddress()); - resource.setProperty("password", getPassword()); - Store::create(resource).exec().waitForFinished(); - - //identity - auto identity = ApplicationDomainType::createEntity(); - m_identityId = identity.identifier(); - identity.setAccount(account); - identity.setName(getIdentityName()); - identity.setAddress(getEmailAddress()); - Store::create(identity).exec(); -} - -void GmailController::modify() { - //TODO -} - -void GmailController::remove() { - SinkAccount account(m_accountId); - Store::remove(account).exec(); -} - -void GmailController::load(const QByteArray &id) { - - m_accountId = id; - - Store::fetchOne(Query().filter(m_accountId)) - .then([this](const SinkAccount &account) { - setName(account.getName()); - }).exec(); - - //TODO -} - diff --git a/framework/accounts/gmailcontroller.h b/framework/accounts/gmailcontroller.h deleted file mode 100644 index 2a5ead65..00000000 --- a/framework/accounts/gmailcontroller.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (C) 2017 Michael Bohlender, - - 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. -*/ - -#pragma once - -#include -#include -#include - -#include - -class GmailController : public Kube::Controller -{ - Q_OBJECT - - //Interface properties - KUBE_CONTROLLER_PROPERTY(QString, Name, name) - - KUBE_CONTROLLER_PROPERTY(QString, EmailAddress, emailAddress) - KUBE_CONTROLLER_PROPERTY(QString, Password, password) - KUBE_CONTROLLER_PROPERTY(QString, IdentityName, identityName) - - //Actions - KUBE_CONTROLLER_ACTION(create) - KUBE_CONTROLLER_ACTION(modify) - KUBE_CONTROLLER_ACTION(remove) - -public: - explicit GmailController(); - -public slots: - void load(const QByteArray &id); - -private: - QByteArray m_accountId; - QByteArray m_smtpId; - QByteArray m_imapId; - QByteArray m_identityId; -}; - -- cgit v1.2.3