Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/weboob/weboob.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * This file is part of KMyMoney, A Personal Finance Manager by KDE | 2 | * This file is part of KMyMoney, A Personal Finance Manager by KDE | ||
3 | * Copyright (C) 2014-2015 Romain Bignon <romain@symlink.me> | 3 | * Copyright (C) 2014-2015 Romain Bignon <romain@symlink.me> | ||
4 | * Copyright (C) 2014-2015 Florent Fourcot <weboob@flo.fourcot.fr> | 4 | * Copyright (C) 2014-2015 Florent Fourcot <weboob@flo.fourcot.fr> | ||
5 | * Copyright (C) 2016 Christian David <christian-david@web.de> | 5 | * Copyright (C) 2016 Christian David <christian-david@web.de> | ||
6 | * (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
6 | * | 7 | * | ||
7 | * This program is free software; you can redistribute it and/or | 8 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | 9 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version 2 | 10 | * as published by the Free Software Foundation; either version 2 | ||
10 | * of the License, or (at your option) any later version. | 11 | * of the License, or (at your option) any later version. | ||
11 | * | 12 | * | ||
12 | * This program is distributed in the hope that it will be useful, | 13 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. | ||
16 | * | 17 | * | ||
17 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 20 | */ | ||
20 | 21 | | |||
21 | #include "weboob.h" | 22 | #include "weboob.h" | ||
22 | #include "weboobext.h" | 23 | | ||
24 | #include <memory> | ||||
25 | | ||||
26 | // ---------------------------------------------------------------------------- | ||||
27 | // QT Includes | ||||
23 | 28 | | |||
24 | #include <QtConcurrentRun> | 29 | #include <QtConcurrentRun> | ||
25 | #include <QFutureWatcher> | 30 | #include <QFutureWatcher> | ||
26 | #include <QProgressDialog> | 31 | #include <QProgressDialog> | ||
27 | 32 | | |||
33 | // ---------------------------------------------------------------------------- | ||||
34 | // KDE Includes | ||||
35 | | ||||
28 | #include <KPluginFactory> | 36 | #include <KPluginFactory> | ||
29 | #include <KLocalizedString> | 37 | #include <KLocalizedString> | ||
30 | 38 | | |||
31 | #include "dialogs/mapaccount.h" | 39 | // ---------------------------------------------------------------------------- | ||
32 | #include "dialogs/webaccount.h" | 40 | // Project Includes | ||
33 | 41 | | |||
42 | #include "mapaccountwizard.h" | ||||
43 | #include "accountsettings.h" | ||||
44 | #include "weboobinterface.h" | ||||
45 | | ||||
46 | #include "mymoneyaccount.h" | ||||
47 | #include "mymoneykeyvaluecontainer.h" | ||||
34 | #include "mymoneystatement.h" | 48 | #include "mymoneystatement.h" | ||
35 | #include "statementinterface.h" | 49 | #include "statementinterface.h" | ||
36 | #include "kmymoneyglobalsettings.h" | 50 | #include "kmymoneyglobalsettings.h" | ||
37 | 51 | | |||
38 | struct Weboob::Private | 52 | class WeboobPrivate | ||
53 | { | ||||
54 | public: | ||||
55 | WeboobPrivate() | ||||
56 | { | ||||
57 | } | ||||
58 | | ||||
59 | ~WeboobPrivate() | ||||
39 | { | 60 | { | ||
40 | QFutureWatcher<WeboobExt::Account> watcher; | 61 | } | ||
62 | | ||||
63 | WeboobInterface weboob; | ||||
64 | QFutureWatcher<WeboobInterface::Account> watcher; | ||||
41 | std::unique_ptr<QProgressDialog> progress; | 65 | std::unique_ptr<QProgressDialog> progress; | ||
42 | WebAccountSettings* accountSettings; | 66 | AccountSettings* accountSettings; | ||
43 | }; | 67 | }; | ||
44 | 68 | | |||
45 | Weboob::Weboob(QObject *parent, const QVariantList &args) : | 69 | Weboob::Weboob(QObject *parent, const QVariantList &args) : | ||
46 | KMyMoneyPlugin::Plugin(parent, "weboob"), | 70 | KMyMoneyPlugin::Plugin(parent, "weboob"), | ||
47 | d(new Private()) | 71 | d_ptr(new WeboobPrivate) | ||
48 | { | 72 | { | ||
49 | Q_UNUSED(args) | 73 | Q_UNUSED(args) | ||
50 | setComponentName("weboob", i18n("Weboob")); | 74 | setComponentName("weboob", i18n("Weboob")); | ||
51 | setXMLFile("weboob.rc"); | 75 | setXMLFile("weboob.rc"); | ||
52 | 76 | | |||
53 | qDebug("Plugins: weboob loaded"); | 77 | qDebug("Plugins: weboob loaded"); | ||
54 | } | 78 | } | ||
55 | 79 | | |||
56 | Weboob::~Weboob() | 80 | Weboob::~Weboob() | ||
57 | { | 81 | { | ||
82 | Q_D(Weboob); | ||||
83 | delete d; | ||||
58 | qDebug("Plugins: weboob unloaded"); | 84 | qDebug("Plugins: weboob unloaded"); | ||
59 | } | 85 | } | ||
60 | 86 | | |||
61 | void Weboob::injectExternalSettings(KMyMoneySettings* p) | 87 | void Weboob::injectExternalSettings(KMyMoneySettings* p) | ||
62 | { | 88 | { | ||
63 | KMyMoneyGlobalSettings::injectExternalSettings(p); | 89 | KMyMoneyGlobalSettings::injectExternalSettings(p); | ||
64 | } | 90 | } | ||
65 | 91 | | |||
66 | void Weboob::plug() | 92 | void Weboob::plug() | ||
67 | { | 93 | { | ||
68 | connect(&d->watcher, &QFutureWatcher<WeboobExt::Account>::finished, this, &Weboob::gotAccount); | 94 | Q_D(Weboob); | ||
95 | connect(&d->watcher, &QFutureWatcher<WeboobInterface::Account>::finished, this, &Weboob::gotAccount); | ||||
69 | } | 96 | } | ||
70 | 97 | | |||
71 | void Weboob::unplug() | 98 | void Weboob::unplug() | ||
72 | { | 99 | { | ||
73 | disconnect(&d->watcher, &QFutureWatcher<WeboobExt::Account>::finished, this, &Weboob::gotAccount); | 100 | Q_D(Weboob); | ||
101 | disconnect(&d->watcher, &QFutureWatcher<WeboobInterface::Account>::finished, this, &Weboob::gotAccount); | ||||
74 | } | 102 | } | ||
75 | 103 | | |||
76 | void Weboob::protocols(QStringList& protocolList) const | 104 | void Weboob::protocols(QStringList& protocolList) const | ||
77 | { | 105 | { | ||
78 | protocolList << "weboob"; | 106 | protocolList << "weboob"; | ||
79 | } | 107 | } | ||
80 | 108 | | |||
81 | QWidget* Weboob::accountConfigTab(const MyMoneyAccount& account, QString& tabName) | 109 | QWidget* Weboob::accountConfigTab(const MyMoneyAccount& account, QString& tabName) | ||
82 | { | 110 | { | ||
111 | Q_D(Weboob); | ||||
83 | const MyMoneyKeyValueContainer& kvp = account.onlineBankingSettings(); | 112 | const MyMoneyKeyValueContainer& kvp = account.onlineBankingSettings(); | ||
84 | tabName = i18n("Weboob configuration"); | 113 | tabName = i18n("Weboob configuration"); | ||
85 | 114 | | |||
86 | d->accountSettings = new WebAccountSettings(account, 0); | 115 | d->accountSettings = new AccountSettings(account, 0); | ||
87 | d->accountSettings->loadUi(kvp); | 116 | d->accountSettings->loadUi(kvp); | ||
88 | 117 | | |||
89 | return d->accountSettings; | 118 | return d->accountSettings; | ||
90 | } | 119 | } | ||
91 | 120 | | |||
92 | MyMoneyKeyValueContainer Weboob::onlineBankingSettings(const MyMoneyKeyValueContainer& current) | 121 | MyMoneyKeyValueContainer Weboob::onlineBankingSettings(const MyMoneyKeyValueContainer& current) | ||
93 | { | 122 | { | ||
123 | Q_D(Weboob); | ||||
94 | MyMoneyKeyValueContainer kvp(current); | 124 | MyMoneyKeyValueContainer kvp(current); | ||
95 | kvp["provider"] = objectName().toLower(); | 125 | kvp["provider"] = objectName().toLower(); | ||
96 | if (d->accountSettings) { | 126 | if (d->accountSettings) { | ||
97 | d->accountSettings->loadKvp(kvp); | 127 | d->accountSettings->loadKvp(kvp); | ||
98 | } | 128 | } | ||
99 | return kvp; | 129 | return kvp; | ||
100 | } | 130 | } | ||
101 | 131 | | |||
102 | bool Weboob::mapAccount(const MyMoneyAccount& acc, MyMoneyKeyValueContainer& onlineBankingSettings) | 132 | bool Weboob::mapAccount(const MyMoneyAccount& acc, MyMoneyKeyValueContainer& onlineBankingSettings) | ||
103 | { | 133 | { | ||
134 | Q_D(Weboob); | ||||
104 | Q_UNUSED(acc); | 135 | Q_UNUSED(acc); | ||
105 | 136 | | |||
106 | WbMapAccountDialog w; | 137 | MapAccountWizard w(nullptr, &d->weboob); | ||
107 | w.weboob = &weboob; | | |||
108 | if (w.exec() == QDialog::Accepted) { | 138 | if (w.exec() == QDialog::Accepted) { | ||
109 | onlineBankingSettings.setValue("wb-backend", w.backendsList->currentItem()->text(0)); | 139 | onlineBankingSettings.setValue("wb-backend", w.currentBackend()); | ||
110 | onlineBankingSettings.setValue("wb-id", w.accountsList->currentItem()->text(0)); | 140 | onlineBankingSettings.setValue("wb-id", w.currentAccount()); | ||
111 | onlineBankingSettings.setValue("wb-max", "0"); | 141 | onlineBankingSettings.setValue("wb-max", "0"); | ||
112 | return true; | 142 | return true; | ||
113 | } | 143 | } | ||
114 | return false; | 144 | return false; | ||
115 | } | 145 | } | ||
116 | 146 | | |||
117 | bool Weboob::updateAccount(const MyMoneyAccount& kacc, bool moreAccounts) | 147 | bool Weboob::updateAccount(const MyMoneyAccount& kacc, bool moreAccounts) | ||
118 | { | 148 | { | ||
149 | Q_D(Weboob); | ||||
119 | Q_UNUSED(moreAccounts); | 150 | Q_UNUSED(moreAccounts); | ||
120 | 151 | | |||
121 | QString bname = kacc.onlineBankingSettings().value("wb-backend"); | 152 | QString bname = kacc.onlineBankingSettings().value("wb-backend"); | ||
122 | QString id = kacc.onlineBankingSettings().value("wb-id"); | 153 | QString id = kacc.onlineBankingSettings().value("wb-id"); | ||
123 | QString max = kacc.onlineBankingSettings().value("wb-max"); | 154 | QString max = kacc.onlineBankingSettings().value("wb-max"); | ||
124 | 155 | | |||
125 | //! @todo C++14 use make_unique() | 156 | d->progress = std::make_unique<QProgressDialog>(nullptr); | ||
126 | d->progress = std::unique_ptr<QProgressDialog>(new QProgressDialog()); | | |||
127 | d->progress->setWindowTitle(i18n("Connecting to bank...")); | 157 | d->progress->setWindowTitle(i18n("Connecting to bank...")); | ||
128 | d->progress->setLabelText(i18n("Retrieving transactions...")); | 158 | d->progress->setLabelText(i18n("Retrieving transactions...")); | ||
129 | d->progress->setModal(true); | 159 | d->progress->setModal(true); | ||
130 | d->progress->setCancelButton(nullptr); | 160 | d->progress->setCancelButton(nullptr); | ||
131 | d->progress->setMinimum(0); | 161 | d->progress->setMinimum(0); | ||
132 | d->progress->setMaximum(0); | 162 | d->progress->setMaximum(0); | ||
133 | d->progress->setMinimumDuration(0); | 163 | d->progress->setMinimumDuration(0); | ||
134 | 164 | | |||
135 | QFuture<WeboobExt::Account> future = QtConcurrent::run(&weboob, &WeboobExt::getAccount, bname, id, max); | 165 | QFuture<WeboobInterface::Account> future = QtConcurrent::run(&d->weboob, &WeboobInterface::getAccount, bname, id, max); | ||
136 | d->watcher.setFuture(future); | 166 | d->watcher.setFuture(future); | ||
137 | 167 | | |||
138 | d->progress->exec(); | 168 | d->progress->exec(); | ||
139 | d->progress.reset(); | 169 | d->progress.reset(); | ||
140 | 170 | | |||
141 | return true; | 171 | return true; | ||
142 | } | 172 | } | ||
143 | 173 | | |||
144 | void Weboob::gotAccount() | 174 | void Weboob::gotAccount() | ||
145 | { | 175 | { | ||
146 | WeboobExt::Account acc = d->watcher.result(); | 176 | Q_D(Weboob); | ||
177 | WeboobInterface::Account acc = d->watcher.result(); | ||||
147 | 178 | | |||
148 | MyMoneyAccount kacc = statementInterface()->account("wb-id", acc.id); | 179 | MyMoneyAccount kacc = statementInterface()->account("wb-id", acc.id); | ||
149 | MyMoneyStatement ks; | 180 | MyMoneyStatement ks; | ||
150 | 181 | | |||
151 | ks.m_accountId = kacc.id(); | 182 | ks.m_accountId = kacc.id(); | ||
152 | ks.m_strAccountName = acc.name; | 183 | ks.m_strAccountName = acc.name; | ||
153 | ks.m_closingBalance = acc.balance; | 184 | ks.m_closingBalance = acc.balance; | ||
154 | if (acc.transactions.length() > 0) | 185 | if (acc.transactions.length() > 0) | ||
Show All 13 Lines | 189 | switch (acc.type) { | |||
168 | case Weboob::Account::TYPE_DEPOSIT: | 199 | case Weboob::Account::TYPE_DEPOSIT: | ||
169 | case Weboob::Account::TYPE_LOAN: | 200 | case Weboob::Account::TYPE_LOAN: | ||
170 | case Weboob::Account::TYPE_JOINT: | 201 | case Weboob::Account::TYPE_JOINT: | ||
171 | case Weboob::Account::TYPE_UNKNOWN: | 202 | case Weboob::Account::TYPE_UNKNOWN: | ||
172 | break; | 203 | break; | ||
173 | } | 204 | } | ||
174 | #endif | 205 | #endif | ||
175 | 206 | | |||
176 | for (QListIterator<WeboobExt::Transaction> it(acc.transactions); it.hasNext();) { | 207 | for (QListIterator<WeboobInterface::Transaction> it(acc.transactions); it.hasNext();) { | ||
177 | WeboobExt::Transaction tr = it.next(); | 208 | WeboobInterface::Transaction tr = it.next(); | ||
178 | MyMoneyStatement::Transaction kt; | 209 | MyMoneyStatement::Transaction kt; | ||
179 | 210 | | |||
180 | kt.m_strBankID = QLatin1String("ID ") + tr.id; | 211 | kt.m_strBankID = QLatin1String("ID ") + tr.id; | ||
181 | kt.m_datePosted = tr.rdate; | 212 | kt.m_datePosted = tr.rdate; | ||
182 | kt.m_amount = tr.amount; | 213 | kt.m_amount = tr.amount; | ||
183 | kt.m_strMemo = tr.raw; | 214 | kt.m_strMemo = tr.raw; | ||
184 | kt.m_strPayee = tr.label; | 215 | kt.m_strPayee = tr.label; | ||
185 | 216 | | |||
Show All 11 Lines |