summaryrefslogtreecommitdiffstats
path: root/akonadish/syntax_modules/akonadi_remove.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-26 19:19:11 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-26 19:19:11 +0100
commit8ef8b8dee60aa0a81fbb2cbba30c00d3b15bb771 (patch)
tree06be3618505d45e6e2886fb614c96689a5555364 /akonadish/syntax_modules/akonadi_remove.cpp
parentfc7052f0970465d41dfd67c7e5db080498fd060f (diff)
parent67a19008d078a067ceb3424c00553c33b918970e (diff)
downloadsink-8ef8b8dee60aa0a81fbb2cbba30c00d3b15bb771.tar.gz
sink-8ef8b8dee60aa0a81fbb2cbba30c00d3b15bb771.zip
Merge branch 'feature/new_cli' into develop
Diffstat (limited to 'akonadish/syntax_modules/akonadi_remove.cpp')
-rw-r--r--akonadish/syntax_modules/akonadi_remove.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/akonadish/syntax_modules/akonadi_remove.cpp b/akonadish/syntax_modules/akonadi_remove.cpp
new file mode 100644
index 0000000..bf09e2e
--- /dev/null
+++ b/akonadish/syntax_modules/akonadi_remove.cpp
@@ -0,0 +1,111 @@
1/*
2 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
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
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <QCoreApplication>
21#include <QDebug>
22#include <QObject> // tr()
23#include <QModelIndex>
24#include <QTime>
25
26#include "common/resource.h"
27#include "common/storage.h"
28#include "common/domain/event.h"
29#include "common/domain/folder.h"
30#include "common/resourceconfig.h"
31#include "common/log.h"
32#include "common/storage.h"
33#include "common/definitions.h"
34
35#include "akonadish_utils.h"
36#include "state.h"
37#include "syntaxtree.h"
38
39namespace AkonadiRemove
40{
41
42bool remove(const QStringList &args, State &state)
43{
44 if (args.isEmpty()) {
45 state.printError(QObject::tr("A type is required"), "akonadi_remove/02");
46 return false;
47 }
48
49 if (args.count() < 2) {
50 state.printError(QObject::tr("A resource ID is required to remove items"), "akonadi_remove/03");
51 return false;
52 }
53
54 if (args.count() < 3) {
55 state.printError(QObject::tr("An object ID is required to remove items"), "akonadi_remove/03");
56 return false;
57 }
58
59 auto type = args[0];
60 auto resourceId = args[1];
61 auto identifier = args[2];
62
63 auto &store = AkonadishUtils::getStore(type);
64 Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject(resourceId.toUtf8(), identifier.toUtf8());
65
66 auto result = store.remove(*object).exec();
67 result.waitForFinished();
68 if (result.errorCode()) {
69 state.printError(QObject::tr("An error occurred while removing %1 from %1: %2").arg(identifier).arg(resourceId).arg(result.errorMessage()),
70 "akonaid_remove_e" + QString::number(result.errorCode()));
71 }
72
73 return true;
74}
75
76bool resource(const QStringList &args, State &state)
77{
78 if (args.isEmpty()) {
79 state.printError(QObject::tr("A resource can not be removed without an id"), "akonadi_remove/01");
80 }
81
82 auto &store = AkonadishUtils::getStore("resource");
83
84 auto resourceId = args.at(0);
85 Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject("", resourceId.toLatin1());
86
87 auto result = store.remove(*object).exec();
88 result.waitForFinished();
89 if (result.errorCode()) {
90 state.printError(QObject::tr("An error occurred while removing the resource %1: %2").arg(resourceId).arg(result.errorMessage()),
91 "akonaid_remove_e" + QString::number(result.errorCode()));
92 }
93
94 return true;
95}
96
97
98Syntax::List syntax()
99{
100 Syntax::List syntax;
101
102 Syntax remove("remove", QObject::tr("Remove items in a resource"), &AkonadiRemove::remove);
103 remove.children << Syntax("resource", QObject::tr("Removes a resource"), &AkonadiRemove::resource);//, Syntax::EventDriven);
104
105 syntax << remove;
106 return syntax;
107}
108
109REGISTER_SYNTAX(AkonadiRemove)
110
111}