diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-20 19:07:07 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-20 19:07:07 +0100 |
commit | bdb01c2c068df326f5a8328ed1492ab1bea388c5 (patch) | |
tree | 25c2ee1b29bc481b6914c244ed9ca194b1415d16 /sinksh/syntax_modules/sink_remove.cpp | |
parent | 17e7ee40c9185c0505883853345fd6024c675b1a (diff) | |
download | sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.tar.gz sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.zip |
Renamed Akonadi2 to Sink
(except for documentation).
Diffstat (limited to 'sinksh/syntax_modules/sink_remove.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_remove.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/sinksh/syntax_modules/sink_remove.cpp b/sinksh/syntax_modules/sink_remove.cpp new file mode 100644 index 0000000..b374824 --- /dev/null +++ b/sinksh/syntax_modules/sink_remove.cpp | |||
@@ -0,0 +1,110 @@ | |||
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 "sinksh_utils.h" | ||
36 | #include "state.h" | ||
37 | #include "syntaxtree.h" | ||
38 | |||
39 | namespace SinkRemove | ||
40 | { | ||
41 | |||
42 | bool remove(const QStringList &args, State &state) | ||
43 | { | ||
44 | if (args.isEmpty()) { | ||
45 | state.printError(QObject::tr("A type is required"), "sink_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"), "sink_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"), "sink_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 = SinkshUtils::getStore(type); | ||
64 | Sink::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 | |||
76 | bool 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"), "sink_remove/01"); | ||
80 | } | ||
81 | |||
82 | auto &store = SinkshUtils::getStore("resource"); | ||
83 | |||
84 | auto resourceId = args.at(0); | ||
85 | Sink::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 | |||
98 | Syntax::List syntax() | ||
99 | { | ||
100 | Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); | ||
101 | Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource);//, Syntax::EventDriven); | ||
102 | resource.completer = &SinkshUtils::resourceCompleter; | ||
103 | remove.children << resource; | ||
104 | |||
105 | return Syntax::List() << remove; | ||
106 | } | ||
107 | |||
108 | REGISTER_SYNTAX(SinkRemove) | ||
109 | |||
110 | } | ||