Merge lp:~unity-team/unity/unity.complete-places-api into lp:unity

Proposed by Mikkel Kamstrup Erlandsen
Status: Merged
Merge reported by: Mikkel Kamstrup Erlandsen
Merged at revision: not available
Proposed branch: lp:~unity-team/unity/unity.complete-places-api
Merge into: lp:unity
Diff against target: 264 lines (+108/-87)
1 file modified
unity/unity-place.vala (+108/-87)
To merge this branch: bzr merge lp:~unity-team/unity/unity.complete-places-api
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+26943@code.launchpad.net

Description of the change

Please see last commit message for details

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good. Approved.

review: Approve
Revision history for this message
Neil J. Patel (njpatel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity/unity-place.vala'
2--- unity/unity-place.vala 2010-06-04 11:59:49 +0000
3+++ unity/unity-place.vala 2010-06-07 12:56:23 +0000
4@@ -24,7 +24,7 @@
5 * some good reasons.
6 *
7 * Firstly we want to hide away Vala's internal DBus marshalling which would
8- * expose raw structs in the. These structs are hidden away in _RendererInfo,
9+ * expose raw structs in the API. These structs are hidden away in _RendererInfo,
10 * and _EntryInfo. We wrap these in handy GObjects with properties and what not.
11 * In fact we want to hide all DBusisms, which is also why the DBus interfaces
12 * are declared private.
13@@ -134,7 +134,64 @@
14 {
15 info.hints.remove_all ();
16 }
17- }
18+
19+ public uint num_hints ()
20+ {
21+ return info.hints.size ();
22+ }
23+ }
24+
25+ /**
26+ *
27+ */
28+ public class Search : InitiallyUnowned {
29+
30+ private string search;
31+ private HashTable<string,string> hints;
32+
33+ /*
34+ * Public API
35+ */
36+
37+ public Search (string search, HashTable<string,string> hints)
38+ {
39+ GLib.Object();
40+ this.search = search;
41+ this.hints = hints;
42+ }
43+
44+ public string get_search_string ()
45+ {
46+ return search;
47+ }
48+
49+ public void set_hint (string hint, string val)
50+ {
51+ hints.insert (hint, val);
52+ }
53+
54+ public string? get_hint (string hint)
55+ {
56+ return hints.lookup (hint);
57+ }
58+
59+ public void clear_hint (string hint)
60+ {
61+ hints.remove (hint);
62+ }
63+
64+ public void clear_hints ()
65+ {
66+ hints.remove_all ();
67+ }
68+
69+ public uint num_hints ()
70+ {
71+ return hints.size ();
72+ }
73+ }
74+
75+ public delegate uint SearchHandler (Search search);
76
77 /**
78 * UnityPlace_EntryInfo:
79@@ -162,6 +219,10 @@
80 private RendererInfo _entry_renderer_info;
81 private RendererInfo _global_renderer_info;
82 private Dee.Model _sections_model;
83+ private SearchHandler _search_handler = null;
84+ private SearchHandler _global_search_handler = null;
85+ private bool _active = false;
86+ private uint _active_section = 0;
87
88 /*
89 * Properties
90@@ -218,6 +279,26 @@
91 }
92 }
93
94+ public bool active {
95+ get { return _active; }
96+ set { _active = value; }
97+ }
98+
99+ public uint active_section {
100+ get { return _active_section; }
101+ set { _active_section = value; }
102+ }
103+
104+ public SearchHandler search_handler {
105+ get { return _search_handler; }
106+ set { _search_handler = value; }
107+ }
108+
109+ public SearchHandler global_search_handler {
110+ get { return _global_search_handler; }
111+ set { _global_search_handler = value; }
112+ }
113+
114 /*
115 * Constructors
116 */
117@@ -288,6 +369,11 @@
118 info.hints.remove_all ();
119 }
120
121+ public uint num_hints ()
122+ {
123+ return info.hints.size ();
124+ }
125+
126 /*
127 * Internal API
128 */
129@@ -531,23 +617,37 @@
130 public uint set_global_search (string search,
131 HashTable<string,string> hints)
132 {
133- return 0;
134+ if (_entry_info.global_search_handler != null)
135+ return _entry_info.global_search_handler (new Search (search, hints));
136+ else
137+ {
138+ warning ("No global search handler installed for %s",
139+ _entry_info.dbus_path);
140+ return 0;
141+ }
142 }
143-
144+
145 public uint set_search (string search,
146 HashTable<string,string> hints)
147 {
148- return 0;
149+ if (_entry_info.search_handler != null)
150+ return _entry_info.search_handler (new Search (search, hints));
151+ else
152+ {
153+ warning ("No search handler installed for %s",
154+ _entry_info.dbus_path);
155+ return 0;
156+ }
157 }
158
159 public void set_active (bool is_active)
160 {
161- // pass
162+ this._entry_info.active = is_active;
163 }
164
165 public void set_active_section (uint section_id)
166 {
167- // pass
168+ this._entry_info.active_section = section_id;
169 }
170
171 /*
172@@ -597,7 +697,7 @@
173
174 public bool exported {
175 get { return _exported; }
176- }
177+ }
178
179 /*
180 * Constructors
181@@ -671,83 +771,4 @@
182 }
183 }
184
185- /*public class TestPlaceDaemon : GLib.Object, PlaceService
186- {
187- private static string[] supported_mimetypes = {"text/plain", "text/html"};
188-
189- public TestPlaceDaemon()
190- {
191- try {
192- var conn = DBus.Bus.get (DBus.BusType. SESSION);
193-
194- dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
195- "/org/freedesktop/DBus",
196- "org.freedesktop.DBus");
197-
198- // try to register service in session bus
199- uint request_name_result = bus.request_name ("org.ayatana.TestPlace", (uint) 0);
200-
201- if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER) {
202- conn.register_object ("/org/ayatana/places/test", this);
203- } else {
204- stderr.printf ("Unable to grab DBus name. Another test server is probably running\n");
205- }
206- } catch (DBus.Error e) {
207- stderr.printf ("Oops: %s\n", e.message);
208- }
209- }
210-
211- public _EntryInfo[] get_entries () throws DBus.Error
212- {
213- var entry = _EntryInfo();
214- entry.dbus_path = "/org/foo/bar";
215- entry.name = "My Entry Name";
216- entry.icon = "__icon__";
217- entry.position = 0;
218- entry.mimetypes = supported_mimetypes;
219- entry.sensitive = true;
220- entry.sections_model = "org.ayatana.MySectionsModel";
221- entry.hints = new HashTable<string, string> (str_hash, str_equal);
222- entry.entry_renderer_info.default_renderer = "DefaultRenderer";
223- entry.entry_renderer_info.groups_model = "org.ayatana.MyGroupsModel";
224- entry.entry_renderer_info.results_model = "org.ayatana.MyResultsModel";
225- entry.entry_renderer_info.hints = new HashTable<string, string> (str_hash, str_equal);
226- entry.global_renderer_info.default_renderer = "DefaultRenderer";
227- entry.global_renderer_info.groups_model = "org.ayatana.MyGlobalGroupsModel";
228- entry.global_renderer_info.results_model = "org.ayatana.MyGlobalResultsModel";
229- entry.global_renderer_info.hints = new HashTable<string, string> (str_hash, str_equal);
230-
231- _EntryInfo[] entries = new _EntryInfo[1];
232- entries[0] = entry;
233- return entries;
234- }
235-
236- public static int main (string[] args)
237- {
238- var loop = new MainLoop (null, false);
239- var daemon = new TestPlaceDaemon();
240- loop.run ();
241-
242- return 0;
243- }
244- }*/
245- /*
246- public static int main (string[] args)
247- {
248- var loop = new MainLoop (null, false);
249- var ctl = new Controller ("/foo/bar");
250- ctl.export();
251-
252- var entry = new EntryInfo();
253- entry.dbus_path = "/foo/bar/entries/0";
254- entry.display_name = "Display Name";
255- entry.set_hint ("hintkey1", "hintvalue1");
256- ctl.add_entry (entry);
257-
258- loop.run ();
259-
260- return 0;
261- }
262- */
263-
264 } /* namespace */