summaryrefslogtreecommitdiffstats
path: root/framework/accounts
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-05 15:04:00 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-05 15:04:00 +0200
commit4b1798f0cdf87361869e7cf2b341acacd056c410 (patch)
tree3ff780641acdcb20b81f9b41533afd50a2525d38 /framework/accounts
parent71721aa4f3e85bea1a2fe504e86d99f80a3106a9 (diff)
downloadkube-4b1798f0cdf87361869e7cf2b341acacd056c410.tar.gz
kube-4b1798f0cdf87361869e7cf2b341acacd056c410.zip
Moved cpp code into src directory
Diffstat (limited to 'framework/accounts')
-rw-r--r--framework/accounts/accountfactory.cpp71
-rw-r--r--framework/accounts/accountfactory.h53
-rw-r--r--framework/accounts/accountsmodel.cpp101
-rw-r--r--framework/accounts/accountsmodel.h67
-rw-r--r--framework/accounts/gmailcontroller.cpp89
-rw-r--r--framework/accounts/gmailcontroller.h55
6 files changed, 0 insertions, 436 deletions
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 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsystems.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include "accountfactory.h"
20
21#include <QDebug>
22
23#include <KPackage/PackageLoader>
24#include <KPackage/Package>
25#include <KPluginMetaData>
26
27#include "settings/settings.h"
28#include <sink/store.h>
29
30AccountFactory::AccountFactory(QObject *parent)
31 : QObject(parent)
32{
33}
34
35QString AccountFactory::name() const
36{
37 if (mName.isEmpty()) {
38 return tr("Account");
39 }
40 return mName;
41}
42
43void AccountFactory::setAccountId(const QString &accountId)
44{
45 mAccountId = accountId;
46 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query().filter(accountId.toUtf8()))
47 .then([this](const Sink::ApplicationDomain::SinkAccount &account) {
48 mAccountType = account.getProperty("type").toByteArray();
49 loadPackage();
50 }).exec();
51}
52
53void AccountFactory::setAccountType(const QString &type)
54{
55 mAccountType = type.toLatin1();
56 loadPackage();
57}
58
59void AccountFactory::loadPackage()
60{
61 auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + mAccountType);
62 if (!package.isValid()) {
63 qWarning() << "Failed to load account package: " << "org.kube.accounts." + mAccountType;
64 return;
65 }
66 Q_ASSERT(package.isValid());
67 mUiPath = package.filePath("mainscript");
68 mName = package.metadata().name();
69 mIcon = package.metadata().iconName();
70 emit accountLoaded();
71}
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 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsystems.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#pragma once
21
22#include <QObject>
23#include <QVariant>
24
25/**
26 * A factory to instantiate account-plugins.
27 */
28class AccountFactory : public QObject
29{
30 Q_OBJECT
31 Q_PROPERTY(QString accountId MEMBER mAccountId WRITE setAccountId);
32 Q_PROPERTY(QString accountType MEMBER mAccountType WRITE setAccountType);
33 Q_PROPERTY(QString name MEMBER mName READ name NOTIFY accountLoaded);
34 Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded);
35 Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded);
36public:
37 explicit AccountFactory(QObject *parent = Q_NULLPTR);
38
39 void setAccountId(const QString &);
40 void setAccountType(const QString &);
41 QString name() const;
42
43signals:
44 void accountLoaded();
45
46private:
47 void loadPackage();
48 QString mAccountId;
49 QString mName;
50 QString mIcon;
51 QString mUiPath;
52 QByteArray mAccountType;
53};
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 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include "accountsmodel.h"
20#include <sink/store.h>
21
22using namespace Sink;
23using namespace Sink::ApplicationDomain;
24
25AccountsModel::AccountsModel(QObject *parent) : QIdentityProxyModel()
26{
27 Sink::Query query;
28 query.setFlags(Query::LiveQuery);
29 query.request<SinkAccount::Name>();
30 query.request<SinkAccount::Icon>();
31 query.request<SinkAccount::Status>();
32 runQuery(query);
33}
34
35AccountsModel::~AccountsModel()
36{
37
38}
39
40QHash< int, QByteArray > AccountsModel::roleNames() const
41{
42 QHash<int, QByteArray> roles;
43
44 roles[Name] = "name";
45 roles[Icon] = "icon";
46 roles[AccountId] = "accountId";
47 roles[Status] = "status";
48
49 return roles;
50}
51
52QVariant AccountsModel::data(const QModelIndex &idx, int role) const
53{
54 auto srcIdx = mapToSource(idx);
55 auto account = srcIdx.data(Sink::Store::DomainObjectRole).value<SinkAccount::Ptr>();
56 switch (role) {
57 case Name:
58 return account->getName();
59 case Icon:
60 return account->getIcon();
61 case AccountId:
62 return account->identifier();
63 case Status:
64 switch (account->getStatus()) {
65 case Sink::ApplicationDomain::ErrorStatus:
66 return ErrorStatus;
67 case Sink::ApplicationDomain::BusyStatus:
68 return BusyStatus;
69 case Sink::ApplicationDomain::ConnectedStatus:
70 return ConnectedStatus;
71 case Sink::ApplicationDomain::OfflineStatus:
72 return OfflineStatus;
73 }
74 return NoStatus;
75 }
76 return QIdentityProxyModel::data(idx, role);
77}
78
79void AccountsModel::runQuery(const Sink::Query &query)
80{
81 mModel = Sink::Store::loadModel<SinkAccount>(query);
82 setSourceModel(mModel.data());
83}
84
85void AccountsModel::setAccountId(const QByteArray &accountId)
86{
87 qWarning() << "Setting account id" << accountId;
88 //Get all folders of an account
89 Sink::Query query;
90 query.filter(accountId);
91 query.setFlags(Query::LiveQuery);
92 query.request<SinkAccount::Name>();
93 query.request<SinkAccount::Icon>();
94 query.request<SinkAccount::Status>();
95 runQuery(query);
96}
97
98QByteArray AccountsModel::accountId() const
99{
100 return {};
101}
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 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#pragma once
21
22#include <QObject>
23#include <QIdentityProxyModel>
24#include <QSharedPointer>
25#include <QStringList>
26
27namespace Sink {
28 class Query;
29}
30
31class AccountsModel : public QIdentityProxyModel
32{
33 Q_OBJECT
34
35 Q_PROPERTY (QByteArray accountId READ accountId WRITE setAccountId)
36public:
37 enum Status {
38 OfflineStatus,
39 ConnectedStatus,
40 BusyStatus,
41 ErrorStatus,
42 NoStatus
43 };
44 Q_ENUMS(Status)
45
46 AccountsModel(QObject *parent = Q_NULLPTR);
47 ~AccountsModel();
48
49 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
50
51 enum Roles {
52 Name = Qt::UserRole + 1,
53 Icon,
54 AccountId,
55 Status
56 };
57 Q_ENUMS(Roles)
58
59 QHash<int, QByteArray> roleNames() const;
60
61 void setAccountId(const QByteArray &id);
62 QByteArray accountId() const;
63
64private:
65 void runQuery(const Sink::Query &query);
66 QSharedPointer<QAbstractItemModel> mModel;
67};
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 @@
1/*
2 * Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "gmailcontroller.h"
20
21#include <sink/store.h>
22
23using namespace Sink;
24using namespace Sink::ApplicationDomain;
25
26GmailController::GmailController() : Kube::Controller(),
27action_create{new Kube::ControllerAction{this, &GmailController::create}},
28action_modify{new Kube::ControllerAction{this, &GmailController::modify}},
29action_remove{new Kube::ControllerAction{this, &GmailController::remove}}
30{
31
32}
33
34void GmailController::create() {
35
36 //account
37 auto account = ApplicationDomainType::createEntity<SinkAccount>();
38 account.setProperty("type", "imap");
39 account.setProperty("name", getName());
40 Store::create(account).exec().waitForFinished();
41
42 //imap
43 auto resource = ApplicationDomainType::createEntity<SinkResource>();
44 resource.setResourceType("sink.imap");
45 resource.setAccount(account);
46 resource.setProperty("server","imaps://imap.gmail.com:993");
47 resource.setProperty("username", getEmailAddress());
48 resource.setProperty("password", getPassword());
49 Store::create(resource).exec().waitForFinished();
50
51 //smtp
52 resource = ApplicationDomainType::createEntity<SinkResource>();
53 resource.setResourceType("sink.mailtransport");
54 resource.setAccount(account);
55 resource.setProperty("server", "smtps://smtp.gmail.com:465");
56 resource.setProperty("username", getEmailAddress());
57 resource.setProperty("password", getPassword());
58 Store::create(resource).exec().waitForFinished();
59
60 //identity
61 auto identity = ApplicationDomainType::createEntity<Identity>();
62 m_identityId = identity.identifier();
63 identity.setAccount(account);
64 identity.setName(getIdentityName());
65 identity.setAddress(getEmailAddress());
66 Store::create(identity).exec();
67}
68
69void GmailController::modify() {
70 //TODO
71}
72
73void GmailController::remove() {
74 SinkAccount account(m_accountId);
75 Store::remove(account).exec();
76}
77
78void GmailController::load(const QByteArray &id) {
79
80 m_accountId = id;
81
82 Store::fetchOne<SinkAccount>(Query().filter(m_accountId))
83 .then([this](const SinkAccount &account) {
84 setName(account.getName());
85 }).exec();
86
87 //TODO
88}
89
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 @@
1/*
2 Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19#pragma once
20
21#include <QObject>
22#include <QString>
23#include <QByteArray>
24
25#include <domain/controller.h>
26
27class GmailController : public Kube::Controller
28{
29 Q_OBJECT
30
31 //Interface properties
32 KUBE_CONTROLLER_PROPERTY(QString, Name, name)
33
34 KUBE_CONTROLLER_PROPERTY(QString, EmailAddress, emailAddress)
35 KUBE_CONTROLLER_PROPERTY(QString, Password, password)
36 KUBE_CONTROLLER_PROPERTY(QString, IdentityName, identityName)
37
38 //Actions
39 KUBE_CONTROLLER_ACTION(create)
40 KUBE_CONTROLLER_ACTION(modify)
41 KUBE_CONTROLLER_ACTION(remove)
42
43public:
44 explicit GmailController();
45
46public slots:
47 void load(const QByteArray &id);
48
49private:
50 QByteArray m_accountId;
51 QByteArray m_smtpId;
52 QByteArray m_imapId;
53 QByteArray m_identityId;
54};
55