~unity-team/unity-lens-sample/trunk

« back to all changes in this revision

Viewing changes to src/daemon.vala

  • Committer: Mikkel Kamstrup Erlandsen
  • Date: 2010-10-23 19:28:23 UTC
  • Revision ID: mikkel.kamstrup@gmail.com-20101023192823-gw12ovvxnd3cjp6y
Require only Valac 0.9 since maverick doesn't ship 0.10

Make code more readable and add some comments

Do some s/files/sample/ in src/Makefile.am

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * BEGIN LICENSE
3
 
 * This file is in the public domain
4
 
 * END LICENSE
 
2
 * Copyright (C) 2010 Canonical Ltd
 
3
 *
 
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.
 
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 General Public License for more details.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 
17
 *
5
18
 */
 
19
using DBus;
6
20
using Dee;
7
21
using Gee;
 
22
using Unity.Place;
8
23
using Config;
9
24
 
10
25
namespace Unity.SamplePlace {
17
32
 
18
33
  /**
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
22
37
   * .place file.
23
38
   *
24
39
   */
25
 
  public class Daemon : GLib.Object, Unity.Activation
 
40
  public class Daemon : GLib.Object, Unity.Place.Activation
26
41
  {
27
 
    private Unity.PlaceController control;
28
 
    private Unity.PlaceEntryInfo place_entry;
 
42
    private Unity.Place.Controller control;
 
43
    private Unity.Place.EntryInfo place_entry;
29
44
 
30
45
    construct
31
46
    {
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
34
49
       * schemas.vala */
35
 
      var sections_model = new Dee.SharedModel(BUS_NAME + ".SectionsModel");
36
 
      sections_model.set_schema ("s", "s");
37
 
 
38
 
      var groups_model = new Dee.SharedModel(BUS_NAME + ".GroupsModel");
39
 
      groups_model.set_schema ("s", "s", "s");
40
 
 
41
 
      var global_groups_model = new Dee.SharedModel(BUS_NAME + ".GlobalGroupsModel");
42
 
      global_groups_model.set_schema ("s", "s", "s");
43
 
 
44
 
      var results_model = new Dee.SharedModel(BUS_NAME + ".ResultsModel");
45
 
      results_model.set_schema ("s", "s", "u", "s", "s", "s");
46
 
 
47
 
      var global_results_model = new Dee.SharedModel(BUS_NAME + ".GlobalResultsModel");
48
 
      global_results_model.set_schema ("s", "s", "u", "s", "s", "s");
49
 
      
 
50
      var sections_model = new Dee.SharedModel(BUS_NAME + ".SectionsModel",
 
51
                                               2, typeof (string), typeof (string));
 
52
 
 
53
      var groups_model = new Dee.SharedModel(
 
54
                                 BUS_NAME + ".GroupsModel",
 
55
                                 3, typeof (string), typeof (string),
 
56
                                 typeof (string));
 
57
 
 
58
      var global_groups_model = new Dee.SharedModel(
 
59
                                 BUS_NAME + ".GlobalGroupsModel",
 
60
                                 3, typeof (string), typeof (string),
 
61
                                 typeof (string));
 
62
 
 
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));
 
68
 
 
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));
 
74
 
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.
54
79
       * Object path of the EntryInfo must match the one defined in the
55
80
       * the place entry in the place .place file
56
81
       */
57
 
      place_entry = new PlaceEntryInfo ("/com/canonical/unity/sampleplace/stuff");
 
82
      place_entry = new EntryInfo ("/com/canonical/unity/sampleplace/stuff");
58
83
      place_entry.sections_model = sections_model;
59
84
      place_entry.entry_renderer_info.groups_model = groups_model;
60
85
      place_entry.entry_renderer_info.results_model = results_model;
66
91
 
67
92
      /* Unity preloads the icon defined in the .place file even before the
68
93
       * place daemon is running - when we come up it will ratify the icon */
69
 
      place_entry.icon = @"$(Config.PREFIX)/share/unity/sample-place-icon.png";
 
94
      place_entry.icon = @"$(Config.PREFIX)/share/unity/files.png";
70
95
 
71
96
      /* Listen for section changes and start updating our results model
72
97
       * accordingly */
83
108
        (obj, pspec) => {
84
109
          debug (@"Activated: $(place_entry.active)");
85
110
        }
86
 
      );          
 
111
      );
 
112
      
 
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 ();            
87
119
 
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);
95
127
      
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  */
102
134
      /* Export the controller on the bus. Unity can see us past this point */
103
135
      try {
104
136
        control.export ();
105
 
      } catch (IOError error) {
 
137
      } catch (DBus.Error error) {
106
138
        critical ("Failed to export DBus service for '%s': %s",
107
139
                  control.dbus_path, error.message);
108
140
      }
119
151
        }
120
152
 
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);
125
160
    }
126
161
 
127
162
    private void populate_groups ()
135
170
        }
136
171
 
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);
140
179
    }
141
180
    
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)
176
215
    {
177
 
      debug ("Rebuilding results model");
178
 
      results_model.clear ();
179
 
      
180
 
      var icon = ContentType.get_icon ("inode/directory");
181
 
      results_model.append ("file:///home",
182
 
                            icon.to_string (), /* Must be a serialized GIcon */
183
 
                            Group.GROUP_ONE,
184
 
                            "inode/directory",
185
 
                            "/home folder",
186
 
                            "Shared user home dir");
187
 
      
188
 
      icon = ContentType.get_icon ("image/png");
189
 
      results_model.append ("file:///usr/share/icons/hicolor/48x48/apps/evolution-mail.png",
190
 
                            icon.to_string (),
191
 
                            Group.GROUP_TWO,
192
 
                            "image/png",
193
 
                            "Evolution icon",
194
 
                            "This is a png with the Evolution icon");
 
216
    
195
217
    }
196
218
 
197
219
    /**
200
222
     * defined in the .place file.
201
223
     *
202
224
     * This method should return a member of the enumeration
203
 
     * Unity.PlaceActivationStatus:
 
225
     * Unity.Place.ActivationStatus:
204
226
     *
205
227
     * - ActivationStatus.ACTIVATED_HIDE_DASH
206
228
     * - ActivationStatus.ACTIVATED_SHOW_DASH
209
231
     */
210
232
    public async uint32 activate (string uri)
211
233
    {
212
 
      debug ("Requested activation of: %s", uri);
213
234
      return ActivationStatus.NOT_ACTIVATED;
214
235
    }
215
236