summaryrefslogtreecommitdiffstats
path: root/akonadish/syntax_modules/akonadi_remove.cpp
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2015-12-25 19:51:34 +0100
committerAaron Seigo <aseigo@kde.org>2015-12-25 19:51:34 +0100
commit55e5d310fb1cf1c85359bbb6f3d64120da9b226b (patch)
treed41f19c64250f27c545fc7390f80a5c1b3db6c66 /akonadish/syntax_modules/akonadi_remove.cpp
parent5333d2560ecce9795382800fb84117da1a56d8c4 (diff)
downloadsink-55e5d310fb1cf1c85359bbb6f3d64120da9b226b.tar.gz
sink-55e5d310fb1cf1c85359bbb6f3d64120da9b226b.zip
remove resource
Diffstat (limited to 'akonadish/syntax_modules/akonadi_remove.cpp')
-rw-r--r--akonadish/syntax_modules/akonadi_remove.cpp82
1 files changed, 82 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..f58fa7d
--- /dev/null
+++ b/akonadish/syntax_modules/akonadi_remove.cpp
@@ -0,0 +1,82 @@
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 resource(const QStringList &args, State &state)
43{
44 if (args.isEmpty()) {
45 state.printError(QObject::tr("A resource can not be removed without an id"), "akonadi_remove/01");
46 }
47
48 auto &store = AkonadishUtils::getStore("resource");
49
50 auto resourceId = args.at(0);
51 Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject("", resourceId.toLatin1());
52
53 auto map = AkonadishUtils::keyValueMapFromArgs(args);
54 for (auto i = map.begin(); i != map.end(); ++i) {
55 object->setProperty(i.key().toLatin1(), i.value());
56 }
57
58 auto result = store.remove(*object).exec();
59 result.waitForFinished();
60 if (result.errorCode()) {
61 state.printError(QObject::tr("An error occurred while removing the resource %1: %2").arg(resourceId).arg(result.errorMessage()),
62 "akonaid_create_" + QString::number(result.errorCode()));
63 }
64
65 return true;
66}
67
68
69Syntax::List syntax()
70{
71 Syntax::List syntax;
72
73 Syntax create("remove");
74 create.children << Syntax("resource", QObject::tr("Removes a resource"), &AkonadiRemove::resource);//, Syntax::EventDriven);
75
76 syntax << create;
77 return syntax;
78}
79
80REGISTER_SYNTAX(AkonadiRemove)
81
82}