diff options
-rw-r--r-- | akonadish/CMakeLists.txt | 1 | ||||
-rw-r--r-- | akonadish/syntax_modules/akonadi_remove.cpp | 82 |
2 files changed, 83 insertions, 0 deletions
diff --git a/akonadish/CMakeLists.txt b/akonadish/CMakeLists.txt index 0aad28d..e5ad667 100644 --- a/akonadish/CMakeLists.txt +++ b/akonadish/CMakeLists.txt | |||
@@ -11,6 +11,7 @@ set(akonadi2_cli_SRCS | |||
11 | syntax_modules/akonadi_clear.cpp | 11 | syntax_modules/akonadi_clear.cpp |
12 | syntax_modules/akonadi_count.cpp | 12 | syntax_modules/akonadi_count.cpp |
13 | syntax_modules/akonadi_create.cpp | 13 | syntax_modules/akonadi_create.cpp |
14 | syntax_modules/akonadi_remove.cpp | ||
14 | syntax_modules/akonadi_stat.cpp | 15 | syntax_modules/akonadi_stat.cpp |
15 | syntax_modules/akonadi_sync.cpp | 16 | syntax_modules/akonadi_sync.cpp |
16 | akonadish_utils.cpp | 17 | akonadish_utils.cpp |
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 | |||
39 | namespace AkonadiRemove | ||
40 | { | ||
41 | |||
42 | bool 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 | |||
69 | Syntax::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 | |||
80 | REGISTER_SYNTAX(AkonadiRemove) | ||
81 | |||
82 | } | ||