2
* Copyright (C) 2016 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Kyle Nitzsche <kyle.nitzsche@canonical.com>
19
#include "libertine-scope/action.h"
20
#include "libertine-scope/config.h"
21
#include <unity/scopes/ActivationResponse.h>
22
#include <unity/scopes/CannedQuery.h>
23
#include <url-dispatcher.h>
26
#include <QTextStream>
28
namespace usc = unity::scopes;
34
write_apps_to_hidden(QFile &hidden_f, QStringList const& hidden)
36
hidden_f.open(QIODevice::WriteOnly | QIODevice::Text);
37
QTextStream out(&hidden_f);
38
for (auto const& app : hidden)
46
} //anonymous namespace
50
Action(usc::Result const& result,
51
usc::ActionMetadata const& metadata,
52
std::string const& action_id,
53
std::string const& cache_dir)
54
: usc::ActivationQueryBase(result, metadata),
55
action_id_(action_id),
60
usc::ActivationResponse
63
if (action_id_ == "open")
65
url_dispatch_send(result().uri().c_str() , NULL, NULL);
66
return usc::ActivationResponse(usc::ActivationResponse::Status::NotHandled);
68
else if (action_id_ == "hide")
70
QFile file(QString("%1/%2").arg(QString::fromStdString(cache_dir_),"hidden"));
71
file.open(QIODevice::Append | QIODevice::Text);
72
QTextStream out(&file);
73
out << QString::fromStdString(result()["app_id"].get_string());
76
usc::CannedQuery cq(SCOPE_PKG + "_" + SCOPE_APP);
77
return usc::ActivationResponse(cq);
79
else if (action_id_ == "show")
81
QFile hidden_f(QString("%1/%2").arg(QString::fromStdString(cache_dir_), QString::fromStdString("hidden")));
82
if (hidden_f.exists()) {
84
if (hidden_f.open(QIODevice::ReadOnly | QIODevice::Text))
86
QTextStream in(&hidden_f);
89
QString line(in.readLine());
90
hidden.append(line.trimmed());
94
QString app_id = QString::fromStdString(result()["app_id"].get_string());
95
if (hidden.contains(app_id))
97
hidden.removeAll(app_id);
98
write_apps_to_hidden(hidden_f, hidden);
101
usc::CannedQuery cq(SCOPE_PKG + "_" + SCOPE_APP);
102
return usc::ActivationResponse(cq);
104
return usc::ActivationResponse(usc::ActivationResponse::Status::NotHandled);