Changeset View
Changeset View
Standalone View
Standalone View
src/lib/removeaccountjob.cpp
- This file was copied from src/lib/accountservicetogglejob.h.
Show All 10 Lines | |||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
12 | * GNU General Public License for more details. * | 12 | * GNU General Public License for more details. * | ||
13 | * * | 13 | * * | ||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the Free Software * | 15 | * along with this program; if not, write to the Free Software * | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | ||
17 | *************************************************************************************/ | 17 | *************************************************************************************/ | ||
18 | 18 | | |||
19 | #ifndef ACCOUNTSERVICETOGGLE_H | 19 | #include "removeaccountjob.h" | ||
20 | #define ACCOUNTSERVICETOGGLE_H | | |||
21 | 20 | | |||
22 | #include "kaccounts_export.h" | 21 | #include <QDebug> | ||
22 | #include "core.h" | ||||
23 | #include <Accounts/Manager> | ||||
24 | #include <SignOn/Identity> | ||||
23 | 25 | | |||
24 | #include <kjob.h> | 26 | class RemoveAccountJob::Private { | ||
27 | public: | ||||
28 | Private() {} | ||||
29 | QString accountId; | ||||
30 | }; | ||||
25 | 31 | | |||
26 | #include <QStringList> | 32 | RemoveAccountJob::RemoveAccountJob(QObject* parent) | ||
33 | : KJob(parent) | ||||
34 | , d(new Private) | ||||
35 | { } | ||||
27 | 36 | | |||
28 | class KACCOUNTS_EXPORT AccountServiceToggleJob : public KJob | 37 | RemoveAccountJob::~RemoveAccountJob() | ||
29 | { | 38 | { | ||
30 | Q_OBJECT | 39 | delete d; | ||
31 | Q_PROPERTY(QString accountId READ accountId WRITE setAccountId NOTIFY accountIdChanged) | 40 | } | ||
32 | Q_PROPERTY(QString serviceId READ serviceId WRITE setServiceId NOTIFY serviceIdChanged) | 41 | | ||
33 | Q_PROPERTY(bool serviceEnabled READ serviceEnabled WRITE setServiceEnabled NOTIFY serviceEnabledChanged) | 42 | QString RemoveAccountJob::accountId() const | ||
34 | public: | 43 | { | ||
35 | explicit AccountServiceToggleJob(QObject* parent = nullptr); | 44 | return d->accountId; | ||
36 | virtual ~AccountServiceToggleJob(); | 45 | } | ||
37 | 46 | | |||
38 | void start() override; | 47 | void RemoveAccountJob::setAccountId(const QString& accountId) | ||
48 | { | ||||
49 | d->accountId = accountId; | ||||
50 | Q_EMIT accountIdChanged(); | ||||
51 | } | ||||
39 | 52 | | |||
40 | QString accountId() const; | 53 | void RemoveAccountJob::start() | ||
41 | void setAccountId(const QString& accountId); | 54 | { | ||
42 | Q_SIGNAL void accountIdChanged(); | 55 | Accounts::Manager* accountsManager = KAccounts::accountsManager(); | ||
43 | 56 | if (accountsManager) { | |||
44 | QString serviceId() const; | 57 | Accounts::Account *account = accountsManager->account(d->accountId.toInt()); | ||
45 | void setServiceId(const QString& serviceId); | 58 | if (account) { | ||
46 | Q_SIGNAL void serviceIdChanged(); | 59 | connect(account, &Accounts::Account::synced, this, [this](){ emitResult(); }); | ||
47 | 60 | SignOn::Identity *identity = SignOn::Identity::existingIdentity(account->credentialsId(), this); | |||
48 | bool serviceEnabled() const; | 61 | if (identity) { | ||
49 | void setServiceEnabled(bool serviceEnabled); | 62 | identity->remove(); | ||
50 | Q_SIGNAL void serviceEnabledChanged(); | 63 | identity->deleteLater(); | ||
51 | private: | 64 | } | ||
52 | class Private; | 65 | account->remove(); | ||
53 | Private* d; | 66 | account->sync(); | ||
54 | }; | 67 | } else { | ||
55 | #endif//ACCOUNTSERVICETOGGLE_H | 68 | qWarning() << "No account found with the ID" << d->accountId; | ||
69 | emitResult(); | ||||
70 | } | ||||
71 | } else { | ||||
72 | qWarning() << "No accounts manager, this is not awesome."; | ||||
73 | emitResult(); | ||||
74 | } | ||||
75 | } |