Unity Scopes API
CannedQuery.h
1 /*
2  * Copyright (C) 2013 Canonical Ltd
3  *
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.
7  *
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.
12  *
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/>.
15  *
16  * Authored by: Pawel Stolowski <pawel.stolowski@canonical.com>
17  */
18 
19 #pragma once
20 
21 #include <unity/util/DefinesPtrs.h>
22 #include <string>
23 #include <memory>
24 #include <unity/scopes/FilterState.h>
25 #include <unity/scopes/Variant.h>
26 
27 namespace unity
28 {
29 
30 namespace scopes
31 {
32 
33 namespace internal
34 {
35 class CannedQueryImpl;
36 }
37 
49 class CannedQuery final
50 {
51 public:
53  UNITY_DEFINES_PTRS(CannedQuery);
55 
59  explicit CannedQuery(std::string const& scope_id);
60 
64  CannedQuery(std::string const& scope_id, std::string const& query_str, std::string const& department_id);
65 
69  //{@
70  CannedQuery(CannedQuery const &other);
72  CannedQuery& operator=(CannedQuery const& other);
73  CannedQuery& operator=(CannedQuery&&);
75 
77  ~CannedQuery();
79 
83  void set_department_id(std::string const& dep_id);
84 
88  void set_query_string(std::string const& query_str);
89 
94 
99  std::string scope_id() const;
100 
105  std::string department_id() const;
106 
111  std::string query_string() const;
112 
114  VariantMap serialize() const;
116 
121  std::string to_uri() const;
122 
130  FilterState filter_state() const;
131 
138  static CannedQuery from_uri(std::string const& uri);
139 
145  void set_user_data(Variant const& value);
146 
152  bool has_user_data() const;
153 
160  Variant user_data() const;
161 
162 private:
163  CannedQuery(internal::CannedQueryImpl *impl);
164  std::unique_ptr<internal::CannedQueryImpl> p;
165  friend class internal::CannedQueryImpl;
166 };
167 
168 } // namespace scopes
169 
170 } // namespace unity
CannedQuery(std::string const &scope_id)
Creates a query for given scope with empty query string.
Definition: CannedQuery.cpp:29
void set_department_id(std::string const &dep_id)
Sets or updates the department.
Definition: CannedQuery.cpp:71
Simple variant class that can hold an integer, boolean, string, double, dictionary, array or null value.
Definition: Variant.h:57
std::string query_string() const
Returns the query string of this CannedQuery.
Definition: CannedQuery.cpp:96
Variant user_data() const
Get user data attached to this query.
Definition: CannedQuery.cpp:126
void set_query_string(std::string const &query_str)
Sets or updates the query string.
Definition: CannedQuery.cpp:76
FilterState filter_state() const
Get state of the filters for this CannedQuery.
Definition: CannedQuery.cpp:101
static CannedQuery from_uri(std::string const &uri)
Recreates a CannedQuery object from a scope:// URI.
Definition: CannedQuery.cpp:111
std::string department_id() const
Returns the department id of this CannedQuery.
Definition: CannedQuery.cpp:91
bool has_user_data() const
Checks if user data has been attached to this query.
Definition: CannedQuery.cpp:121
Top-level namespace for all things Unity-related.
Definition: Version.h:49
std::map< std::string, Variant > VariantMap
A dictionary of (string, Variant) pairs.
Definition: Variant.h:38
void set_user_data(Variant const &value)
Attach arbitrary data.
Definition: CannedQuery.cpp:116
Definition: ActionMetadata.h:31
std::string scope_id() const
Returns the scope identifier of this CannedQuery.
Definition: CannedQuery.cpp:86
void set_filter_state(FilterState const &filter_state)
Sets filter state.
Definition: CannedQuery.cpp:81
Parameters of a search query.
Definition: CannedQuery.h:49
Captures state of multiple filters.
Definition: FilterState.h:46
std::string to_uri() const
Returns a string representation of this CannedQuery object as a URI using scope:// schema...
Definition: CannedQuery.cpp:106