3
* This file is in the public domain
2
* Copyright (C) 2010 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
* Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
10
25
namespace Unity.SamplePlace {
19
34
* The Daemon class implements all of the logic for the place.
20
* It implements the Unity.PlaceActivation interface in order to
35
* It implements the Unity.Place.Activation interface in order to
21
36
* do custom activation of the URI and Mime patterns defined in the
25
public class Daemon : GLib.Object, Unity.Activation
40
public class Daemon : GLib.Object, Unity.Place.Activation
27
private Unity.PlaceController control;
28
private Unity.PlaceEntryInfo place_entry;
42
private Unity.Place.Controller control;
43
private Unity.Place.EntryInfo place_entry;
32
47
/* Create all the models we need to share with the Unity shell.
33
48
* The model column schemas must align with what we defined in
35
var sections_model = new Dee.SharedModel(BUS_NAME + ".SectionsModel");
36
sections_model.set_schema ("s", "s");
38
var groups_model = new Dee.SharedModel(BUS_NAME + ".GroupsModel");
39
groups_model.set_schema ("s", "s", "s");
41
var global_groups_model = new Dee.SharedModel(BUS_NAME + ".GlobalGroupsModel");
42
global_groups_model.set_schema ("s", "s", "s");
44
var results_model = new Dee.SharedModel(BUS_NAME + ".ResultsModel");
45
results_model.set_schema ("s", "s", "u", "s", "s", "s");
47
var global_results_model = new Dee.SharedModel(BUS_NAME + ".GlobalResultsModel");
48
global_results_model.set_schema ("s", "s", "u", "s", "s", "s");
50
var sections_model = new Dee.SharedModel(BUS_NAME + ".SectionsModel",
51
2, typeof (string), typeof (string));
53
var groups_model = new Dee.SharedModel(
54
BUS_NAME + ".GroupsModel",
55
3, typeof (string), typeof (string),
58
var global_groups_model = new Dee.SharedModel(
59
BUS_NAME + ".GlobalGroupsModel",
60
3, typeof (string), typeof (string),
63
var results_model = new Dee.SharedModel(
64
BUS_NAME + ".ResultsModel",
65
6, typeof (string), typeof (string),
66
typeof (uint), typeof (string),
67
typeof (string), typeof (string));
69
var global_results_model = new Dee.SharedModel(
70
BUS_NAME + ".GlobalResultsModel",
71
6, typeof (string), typeof (string),
72
typeof (uint), typeof (string),
73
typeof (string), typeof (string));
50
75
/* Create an EntryInfo. The properties of the EntryInfo is automatically
51
76
* mapped back and forth over the bus, and removes most DBusisms from
52
77
* the place daemon code.
84
109
debug (@"Activated: $(place_entry.active)");
113
/* Export all our Dee.SharedModels on the bus */
114
sections_model.connect ();
115
groups_model.connect ();
116
global_groups_model.connect ();
117
results_model.connect ();
118
global_results_model.connect ();
88
120
/* The last thing we do is export the controller. Once that is up,
89
121
* clients will expect the Dee.SharedModels to work.
90
122
* The 'place' EntryInfo is exported for Unity to show by adding it to
91
123
* the controller. You can add more than one EntryInfo here if you have
92
124
* more than one place entry to export from the same place daemon */
93
control = new Unity.PlaceController ("/com/canonical/unity/sampleplace");
125
control = new Unity.Place.Controller ("/com/canonical/unity/sampleplace");
94
126
control.add_entry (place_entry);
96
/* Since the Daemon class implements the Unity.PlaceActivation interface
128
/* Since the Daemon class implements the Unity.Place.Activation interface
97
129
* we can override the default activation handler on the controller.
98
130
* We need to do that to properly handle the activation patternts we
99
131
* registered in the .place file */
121
153
/* The row offsets should match those from the Section enum */
122
sections.append (_("All Stuff"), "");
123
sections.append (_("My Stuff"), "");
124
sections.append (_("Your Stuff"), "");
154
sections.append (SectionsColumn.DISPLAY_NAME, _("All Stuff"),
155
SectionsColumn.ICON_HINT, "", -1);
156
sections.append (SectionsColumn.DISPLAY_NAME, _("My Stuff"),
157
SectionsColumn.ICON_HINT, "", -1);
158
sections.append (SectionsColumn.DISPLAY_NAME, _("Your Stuff"),
159
SectionsColumn.ICON_HINT, "", -1);
127
162
private void populate_groups ()
137
172
/* The row offsets should match those from the Group enum */
138
groups.append ("UnityDefaultRenderer", _("Group One"), ICON_PATH + "group-mostused.svg");
139
groups.append ("UnityDefaultRenderer", _("Group Two"), ICON_PATH + "group-recent.svg");
173
groups.append (GroupsColumn.RENDERER, "UnityDefaultRenderer",
174
GroupsColumn.DISPLAY_NAME, _("Group One"),
175
GroupsColumn.ICON_HINT, ICON_PATH + "group-mostused.svg", -1);
176
groups.append (GroupsColumn.RENDERER, "UnityDefaultRenderer",
177
GroupsColumn.DISPLAY_NAME, _("Group Two"),
178
GroupsColumn.ICON_HINT, ICON_PATH + "group-recent.svg", -1);
142
181
private void update_entry_results_model ()
172
211
/* Generic method to update a results model. We do it like this to minimize
173
212
* code dup between updating the global- and the entry results model */
174
213
private void update_results_model (Dee.Model results_model, Dee.Model groups_model,
175
PlaceSearch? search, Section section)
214
Search? search, Section section)
177
debug ("Rebuilding results model");
178
results_model.clear ();
180
var icon = ContentType.get_icon ("inode/directory");
181
results_model.append ("file:///home",
182
icon.to_string (), /* Must be a serialized GIcon */
186
"Shared user home dir");
188
icon = ContentType.get_icon ("image/png");
189
results_model.append ("file:///usr/share/icons/hicolor/48x48/apps/evolution-mail.png",
194
"This is a png with the Evolution icon");