2
* Copyright (C) 2015 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Pawel Stolowski <pawel.stolowski@canonical.com>
19
#include <unity/scopes/CategorisedResult.h>
20
#include <unity/scopes/OptionSelectorFilter.h>
21
#include <unity/scopes/RangeInputFilter.h>
22
#include <unity/scopes/ValueSliderFilter.h>
23
#include <unity/scopes/ValueSliderLabels.h>
24
#include <unity/scopes/ScopeBase.h>
25
#include <unity/scopes/SearchReply.h>
29
#define EXPORT __attribute__ ((visibility ("default")))
32
using namespace unity::scopes;
34
class MyQuery : public SearchQueryBase
37
MyQuery(CannedQuery const& query, SearchMetadata const& metadata) :
38
SearchQueryBase(query, metadata)
46
virtual void cancelled() override
50
virtual void run(SearchReplyProxy const& reply) override
52
OptionSelectorFilter::UPtr filter1 = OptionSelectorFilter::create("f1", "Filter1");
53
if (query().query_string() == "test_primary_filter") {
54
filter1->set_display_hints(FilterBase::DisplayHints::Primary);
57
auto opt1 = filter1->add_option("o1", "Option1");
58
filter1->add_option("o2", "Option2");
60
RangeInputFilter::SPtr filter2 = RangeInputFilter::create("f2", Variant(2.0f), Variant::null(), "start", "", "", "end", "");
62
auto cat1 = reply->register_category("cat1", "Category 1", "");
63
CategorisedResult res1(cat1);
64
res1.set_uri("test:uri");
66
auto selected = filter1->active_options(query().filter_state());
67
if (selected.size() == 1) {
68
res1.set_title("result for option " + (*selected.begin())->id());
70
res1.set_title("result for: \"" + query().query_string() + "\"");
73
bool has_start_val = filter2->has_start_value(query().filter_state());
74
bool has_end_val = filter2->has_end_value(query().filter_state());
76
if (has_start_val || has_end_val)
78
res1.set_title("result for range: " +
79
(has_start_val ? std::to_string(filter2->start_value(query().filter_state())) : "***") + " - " +
80
(has_end_val ? std::to_string(filter2->end_value(query().filter_state())) : "***"));
83
ValueSliderFilter::SPtr filter3 = ValueSliderFilter::create("f3", 1, 99, 50, ValueSliderLabels("Min", "Max", {{33, "One third"}}));
86
filters.push_back(std::move(filter1));
87
filters.push_back(std::move(filter2));
88
filters.push_back(std::move(filter3));
90
reply->push(filters, query().filter_state());
95
class MyScope : public ScopeBase
102
virtual SearchQueryBase::UPtr search(CannedQuery const& q, SearchMetadata const& metadata) override
104
return SearchQueryBase::UPtr(new MyQuery(q, metadata));
107
virtual PreviewQueryBase::UPtr preview(Result const&, ActionMetadata const&) override
117
unity::scopes::ScopeBase*
118
// cppcheck-suppress unusedFunction
119
UNITY_SCOPE_CREATE_FUNCTION()
126
// cppcheck-suppress unusedFunction
127
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)