~om26er/ubuntu/oneiric/unity/sru-778256

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/PlacesHomeView.cpp

  • Committer: Didier Roche
  • Date: 2011-07-21 16:17:59 UTC
  • mfrom: (55.813.3 upstream)
  • Revision ID: didier.roche@canonical.com-20110721161759-osmh94x428t2bf2b
* New upstream release.
* debian/control:
  - build-dep on libnotify-dev
  - bump libnux-1.0-dev dep for ABI break

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "PlacesSettings.h"
43
43
#include "PlacesSimpleTile.h"
44
44
#include "PlacesStyle.h"
45
 
#include <UnityCore/UnityCore.h>
 
45
#include <UnityCore/Variant.h>
46
46
 
47
47
#include <string>
48
48
#include <vector>
56
56
 
57
57
enum
58
58
{
59
 
  TYPE_PLACE=0,
 
59
  TYPE_PLACE = 0,
60
60
  TYPE_EXEC
61
61
};
62
62
 
63
63
class Shortcut : public PlacesSimpleTile
64
64
{
65
65
public:
66
 
  Shortcut (const char *icon, const char *name, int size)
67
 
  : PlacesSimpleTile (icon, name, size),
68
 
    _id (0),
69
 
    _place_id (NULL),
70
 
    _place_section (0),
71
 
    _exec (NULL)
 
66
  Shortcut(const char* icon, const char* name, int size)
 
67
    : PlacesSimpleTile(icon, name, size),
 
68
      _id(0),
 
69
      _place_id(NULL),
 
70
      _place_section(0),
 
71
      _exec(NULL)
72
72
  {
73
 
    SetDndEnabled (false, false);
 
73
    SetDndEnabled(false, false);
74
74
  }
75
75
 
76
 
  ~Shortcut ()
 
76
  ~Shortcut()
77
77
  {
78
 
    g_free (_place_id);
79
 
    g_free (_exec);
 
78
    g_free(_place_id);
 
79
    g_free(_exec);
80
80
  }
81
81
 
82
82
  int      _id;
83
 
  gchar   *_place_id;
 
83
  gchar*   _place_id;
84
84
  guint32  _place_section;
85
 
  char    *_exec;
 
85
  char*    _exec;
86
86
};
87
87
 
88
 
PlacesHomeView::PlacesHomeView ()
89
 
: _ubus_handle (0)
 
88
PlacesHomeView::PlacesHomeView()
 
89
  : _ubus_handle(0)
90
90
{
91
 
  PlacesStyle *style = PlacesStyle::GetDefault ();
92
 
 
93
 
  SetName (_("Shortcuts"));
94
 
  SetIcon (PKGDATADIR"/shortcuts_group_icon.png");
95
 
  
96
 
  _layout = new nux::GridHLayout (NUX_TRACKER_LOCATION);
97
 
  SetChildLayout (_layout);
98
 
 
99
 
  _layout->ForceChildrenSize (true);
100
 
  _layout->SetChildrenSize (style->GetHomeTileWidth (), style->GetHomeTileHeight ());
101
 
  _layout->EnablePartialVisibility (false);
102
 
  _layout->SetHeightMatchContent (true);
103
 
  _layout->SetVerticalExternalMargin (32);
104
 
  _layout->SetHorizontalExternalMargin (32);
105
 
  _layout->SetVerticalInternalMargin (32);
106
 
  _layout->SetHorizontalInternalMargin (32);
107
 
  _layout->SetMinMaxSize ((style->GetHomeTileWidth () * 4) + (32 * 5),
108
 
                          (style->GetHomeTileHeight () * 2) + (32 *3));
109
 
 
110
 
  _client = gconf_client_get_default ();
111
 
  gconf_client_add_dir (_client,
112
 
                        BROWSER_DIR,
113
 
                        GCONF_CLIENT_PRELOAD_NONE,
114
 
                        NULL);
115
 
  gconf_client_add_dir (_client,
116
 
                        MAIL_DIR,
117
 
                        GCONF_CLIENT_PRELOAD_NONE,
118
 
                        NULL);
119
 
  gconf_client_add_dir (_client,
120
 
                        MEDIA_DIR,
121
 
                        GCONF_CLIENT_PRELOAD_NONE,
122
 
                        NULL);
 
91
  PlacesStyle* style = PlacesStyle::GetDefault();
 
92
 
 
93
  SetName(_("Shortcuts"));
 
94
  SetIcon(PKGDATADIR"/shortcuts_group_icon.png");
 
95
 
 
96
  _layout = new nux::GridHLayout(NUX_TRACKER_LOCATION);
 
97
  _layout->SetReconfigureParentLayoutOnGeometryChange(true);
 
98
  SetChildLayout(_layout);
 
99
 
 
100
  _layout->ForceChildrenSize(true);
 
101
  _layout->SetChildrenSize(style->GetHomeTileWidth(), style->GetHomeTileHeight());
 
102
  _layout->EnablePartialVisibility(false);
 
103
  _layout->SetHeightMatchContent(true);
 
104
  _layout->SetVerticalExternalMargin(32);
 
105
  _layout->SetHorizontalExternalMargin(32);
 
106
  _layout->SetVerticalInternalMargin(32);
 
107
  _layout->SetHorizontalInternalMargin(32);
 
108
  _layout->SetMinMaxSize((style->GetHomeTileWidth() * 4) + (32 * 5),
 
109
                         (style->GetHomeTileHeight() * 2) + (32 * 3));
 
110
 
 
111
  _client = gconf_client_get_default();
 
112
  gconf_client_add_dir(_client,
 
113
                       BROWSER_DIR,
 
114
                       GCONF_CLIENT_PRELOAD_NONE,
 
115
                       NULL);
 
116
  gconf_client_add_dir(_client,
 
117
                       MAIL_DIR,
 
118
                       GCONF_CLIENT_PRELOAD_NONE,
 
119
                       NULL);
 
120
  gconf_client_add_dir(_client,
 
121
                       MEDIA_DIR,
 
122
                       GCONF_CLIENT_PRELOAD_NONE,
 
123
                       NULL);
123
124
  _browser_gconf_notify = gconf_client_notify_add(_client,
124
 
                                                  BROWSER_DIR"/exec", 
 
125
                                                  BROWSER_DIR"/exec",
125
126
                                                  (GConfClientNotifyFunc)OnKeyChanged,
126
127
                                                  this,
127
128
                                                  NULL, NULL);
135
136
                                                (GConfClientNotifyFunc)OnKeyChanged,
136
137
                                                this,
137
138
                                                NULL, NULL);
138
 
                          
 
139
 
139
140
  _last_activate_time.tv_sec = 0;
140
141
  _last_activate_time.tv_nsec = 0;
141
142
 
142
 
  _ubus_handle = ubus_server_register_interest (ubus_server_get_default (),
143
 
                                                UBUS_DASH_EXTERNAL_ACTIVATION,
144
 
                                                (UBusCallback) &PlacesHomeView::DashVisible,
145
 
                                                this);
 
143
  _ubus_handle = ubus_server_register_interest(ubus_server_get_default(),
 
144
                                               UBUS_DASH_EXTERNAL_ACTIVATION,
 
145
                                               (UBusCallback) &PlacesHomeView::DashVisible,
 
146
                                               this);
146
147
 
147
148
  //In case the GConf key is invalid (e.g. when an app was uninstalled), we
148
149
  //rely on a fallback "whitelist" mechanism instead of showing nothing at all
150
151
  _browser_alternatives.push_back("chromium-browser");
151
152
  _browser_alternatives.push_back("epiphany-browser");
152
153
  _browser_alternatives.push_back("midori");
153
 
  
 
154
 
154
155
  _photo_alternatives.push_back("shotwell");
155
156
  _photo_alternatives.push_back("f-spot");
156
157
  _photo_alternatives.push_back("gthumb");
157
158
  _photo_alternatives.push_back("gwenview");
158
159
  _photo_alternatives.push_back("eog");
159
 
  
 
160
 
160
161
  _email_alternatives.push_back("evolution");
161
162
  _email_alternatives.push_back("thunderbird");
162
163
  _email_alternatives.push_back("claws-mail");
163
164
  _email_alternatives.push_back("kmail");
164
 
  
165
 
  _music_alternatives.push_back("banshee");
 
165
 
 
166
  _music_alternatives.push_back("banshee-1");
166
167
  _music_alternatives.push_back("rhythmbox");
167
168
  _music_alternatives.push_back("totem");
168
169
  _music_alternatives.push_back("vlc");
169
170
 
170
 
  expanded.connect (sigc::mem_fun (this, &PlacesHomeView::Refresh));
 
171
  expanded.connect(sigc::mem_fun(this, &PlacesHomeView::Refresh));
171
172
 
172
 
  SetExpanded (PlacesSettings::GetDefault ()->GetHomeExpanded ());
173
 
  if (GetExpanded ())
174
 
    Refresh ();
 
173
  SetExpanded(PlacesSettings::GetDefault()->GetHomeExpanded());
 
174
  if (GetExpanded())
 
175
    Refresh();
175
176
}
176
177
 
177
 
PlacesHomeView::~PlacesHomeView ()
 
178
PlacesHomeView::~PlacesHomeView()
178
179
{
179
 
  g_object_unref (_client);
 
180
  g_object_unref(_client);
180
181
 
181
182
  if (_ubus_handle != 0)
182
 
    ubus_server_unregister_interest (ubus_server_get_default (), _ubus_handle);
183
 
    
 
183
    ubus_server_unregister_interest(ubus_server_get_default(), _ubus_handle);
 
184
 
184
185
  if (_browser_gconf_notify)
185
 
    gconf_client_notify_remove (_client, _browser_gconf_notify);
 
186
    gconf_client_notify_remove(_client, _browser_gconf_notify);
186
187
  if (_mail_gconf_notify)
187
 
    gconf_client_notify_remove (_client, _mail_gconf_notify);
 
188
    gconf_client_notify_remove(_client, _mail_gconf_notify);
188
189
  if (_media_gconf_notify)
189
 
    gconf_client_notify_remove (_client, _media_gconf_notify);
190
 
  gconf_client_remove_dir (_client, BROWSER_DIR, NULL);
191
 
  gconf_client_remove_dir (_client, MAIL_DIR, NULL);
192
 
  gconf_client_remove_dir (_client, MEDIA_DIR, NULL);
 
190
    gconf_client_notify_remove(_client, _media_gconf_notify);
 
191
  gconf_client_remove_dir(_client, BROWSER_DIR, NULL);
 
192
  gconf_client_remove_dir(_client, MAIL_DIR, NULL);
 
193
  gconf_client_remove_dir(_client, MEDIA_DIR, NULL);
193
194
}
194
195
 
195
196
void
196
 
PlacesHomeView::DashVisible (GVariant *data, void *val)
 
197
PlacesHomeView::DashVisible(GVariant* data, void* val)
197
198
{
198
 
  PlacesHomeView *self = (PlacesHomeView*)val;
199
 
  
 
199
  PlacesHomeView* self = (PlacesHomeView*)val;
 
200
 
200
201
  struct timespec event_time, delta;
201
202
  clock_gettime(CLOCK_MONOTONIC, &event_time);
202
 
  delta = self->time_diff (self->_last_activate_time, event_time);
 
203
  delta = self->time_diff(self->_last_activate_time, event_time);
203
204
 
204
205
  self->_last_activate_time.tv_sec = event_time.tv_sec;
205
206
  self->_last_activate_time.tv_nsec = event_time.tv_nsec;
207
208
  // FIXME: this should be handled by ubus (not sending the request twice
208
209
  // for some selected ones). Too intrusive for now.
209
210
  if (!((delta.tv_sec == 0) && (delta.tv_nsec < DELTA_DOUBLE_REQUEST)))
210
 
    self->Refresh ();
211
 
 
212
 
}
213
 
 
214
 
void
215
 
PlacesHomeView::OnKeyChanged (GConfClient    *client,
216
 
                              guint           cnxn_id,
217
 
                              GConfEntry     *entry,
218
 
                              PlacesHomeView *self)
219
 
{
220
 
  self->Refresh ();
221
 
}
222
 
 
223
 
void
224
 
PlacesHomeView::Refresh ()
225
 
{
226
 
  PlacesStyle *style = PlacesStyle::GetDefault ();
227
 
  Shortcut   *shortcut = NULL;
228
 
  gchar      *markup = NULL;
229
 
  const char *temp = "<big>%s</big>";
230
 
  int         icon_size = style->GetHomeTileIconSize ();
231
 
 
232
 
  _layout->Clear ();
233
 
 
234
 
  PlacesSettings::GetDefault ()->SetHomeExpanded (GetExpanded ());
235
 
 
236
 
  if (!GetExpanded ())
 
211
    self->Refresh();
 
212
 
 
213
}
 
214
 
 
215
void
 
216
PlacesHomeView::OnKeyChanged(GConfClient*    client,
 
217
                             guint           cnxn_id,
 
218
                             GConfEntry*     entry,
 
219
                             PlacesHomeView* self)
 
220
{
 
221
  self->Refresh();
 
222
}
 
223
 
 
224
void
 
225
PlacesHomeView::Refresh()
 
226
{
 
227
  PlacesStyle* style = PlacesStyle::GetDefault();
 
228
  Shortcut*   shortcut = NULL;
 
229
  gchar*      markup = NULL;
 
230
  const char* temp = "<big>%s</big>";
 
231
  int         icon_size = style->GetHomeTileIconSize();
 
232
 
 
233
  _layout->Clear();
 
234
 
 
235
  PlacesSettings::GetDefault()->SetHomeExpanded(GetExpanded());
 
236
 
 
237
  if (!GetExpanded())
237
238
    return;
238
239
 
239
240
  // Media Apps
240
 
  markup = g_strdup_printf (temp, _("Media Apps"));
241
 
  shortcut = new Shortcut (PKGDATADIR"/find_media_apps.png",
242
 
                           markup,
243
 
                           icon_size);
 
241
  markup = g_strdup_printf(temp, _("Media Apps"));
 
242
  shortcut = new Shortcut(PKGDATADIR"/find_media_apps.png",
 
243
                          markup,
 
244
                          icon_size);
244
245
  shortcut->_id = TYPE_PLACE;
245
 
  shortcut->_place_id = g_strdup ("/com/canonical/unity/applicationsplace/applications");
 
246
  shortcut->_place_id = g_strdup("/com/canonical/unity/applicationsplace/applications");
246
247
  shortcut->_place_section = 9;
247
 
  _layout->AddView (shortcut, 1, nux::eLeft, nux::eFull);
248
 
  shortcut->sigClick.connect (sigc::mem_fun (this, &PlacesHomeView::OnShortcutClicked));
249
 
  g_free (markup);
 
248
  _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull);
 
249
  shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked));
 
250
  g_free(markup);
250
251
 
251
252
  // Internet Apps
252
 
  markup = g_strdup_printf (temp, _("Internet Apps"));
253
 
  shortcut = new Shortcut (PKGDATADIR"/find_internet_apps.png",
254
 
                           markup,
255
 
                           icon_size);
 
253
  markup = g_strdup_printf(temp, _("Internet Apps"));
 
254
  shortcut = new Shortcut(PKGDATADIR"/find_internet_apps.png",
 
255
                          markup,
 
256
                          icon_size);
256
257
  shortcut->_id = TYPE_PLACE;
257
 
  shortcut->_place_id = g_strdup ("/com/canonical/unity/applicationsplace/applications");
 
258
  shortcut->_place_id = g_strdup("/com/canonical/unity/applicationsplace/applications");
258
259
  shortcut->_place_section = 8;
259
 
  _layout->AddView (shortcut, 1, nux::eLeft, nux::eFull);
260
 
  shortcut->sigClick.connect (sigc::mem_fun (this, &PlacesHomeView::OnShortcutClicked));
261
 
  g_free (markup);
 
260
  _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull);
 
261
  shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked));
 
262
  g_free(markup);
262
263
 
263
264
  // More Apps
264
 
  markup = g_strdup_printf (temp, _("More Apps"));
265
 
  shortcut = new Shortcut (PKGDATADIR"/find_more_apps.png",
266
 
                           markup,
267
 
                           icon_size);
 
265
  markup = g_strdup_printf(temp, _("More Apps"));
 
266
  shortcut = new Shortcut(PKGDATADIR"/find_more_apps.png",
 
267
                          markup,
 
268
                          icon_size);
268
269
  shortcut->_id = TYPE_PLACE;
269
 
  shortcut->_place_id = g_strdup ("/com/canonical/unity/applicationsplace/applications");
 
270
  shortcut->_place_id = g_strdup("/com/canonical/unity/applicationsplace/applications");
270
271
  shortcut->_place_section = 0;
271
 
  _layout->AddView (shortcut, 1, nux::eLeft, nux::eFull);
272
 
  shortcut->sigClick.connect (sigc::mem_fun (this, &PlacesHomeView::OnShortcutClicked));
273
 
  g_free (markup);
 
272
  _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull);
 
273
  shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked));
 
274
  g_free(markup);
274
275
 
275
276
  // Find Files
276
 
  markup = g_strdup_printf (temp, _("Find Files"));
277
 
  shortcut = new Shortcut (PKGDATADIR"/find_files.png",
278
 
                           markup,
279
 
                           icon_size);
 
277
  markup = g_strdup_printf(temp, _("Find Files"));
 
278
  shortcut = new Shortcut(PKGDATADIR"/find_files.png",
 
279
                          markup,
 
280
                          icon_size);
280
281
  shortcut->_id = TYPE_PLACE;
281
 
  shortcut->_place_id = g_strdup ("/com/canonical/unity/filesplace/files");
 
282
  shortcut->_place_id = g_strdup("/com/canonical/unity/filesplace/files");
282
283
  shortcut->_place_section = 0;
283
 
  _layout->AddView (shortcut, 1, nux::eLeft, nux::eFull);
284
 
  shortcut->sigClick.connect (sigc::mem_fun (this, &PlacesHomeView::OnShortcutClicked));
285
 
  g_free (markup);
 
284
  _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull);
 
285
  shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked));
 
286
  g_free(markup);
286
287
 
287
288
  // Browser
288
 
  markup = gconf_client_get_string (_client, BROWSER_DIR"/exec", NULL);
289
 
  CreateShortcutFromExec (markup, _("Browse the Web"), _browser_alternatives);
290
 
  g_free (markup);
 
289
  markup = gconf_client_get_string(_client, BROWSER_DIR"/exec", NULL);
 
290
  CreateShortcutFromExec(markup, _("Browse the Web"), _browser_alternatives);
 
291
  g_free(markup);
291
292
 
292
293
  // Photos
293
294
  // FIXME: Need to figure out the default
294
 
  CreateShortcutFromExec ("shotwell", _("View Photos"), _photo_alternatives);
 
295
  CreateShortcutFromExec("shotwell", _("View Photos"), _photo_alternatives);
295
296
 
296
297
  // Email
297
 
  markup = gconf_client_get_string (_client, MAIL_DIR"/command", NULL);
 
298
  markup = gconf_client_get_string(_client, MAIL_DIR"/command", NULL);
298
299
  // get the first word on key (the executable name itself)
299
 
  markup = g_strsplit (markup, " ", 0)[0];
300
 
  CreateShortcutFromExec (markup, _("Check Email"), _email_alternatives);
301
 
  g_free (markup);
 
300
  markup = g_strsplit(markup, " ", 0)[0];
 
301
  CreateShortcutFromExec(markup, _("Check Email"), _email_alternatives);
 
302
  g_free(markup);
302
303
 
303
304
  // Music
304
 
  markup = gconf_client_get_string (_client, MEDIA_DIR"/exec", NULL);
305
 
  CreateShortcutFromExec (markup, _("Listen to Music"), _music_alternatives);
306
 
  g_free (markup);
 
305
  markup = gconf_client_get_string(_client, MEDIA_DIR"/exec", NULL);
 
306
  CreateShortcutFromExec(markup, _("Listen to Music"), _music_alternatives);
 
307
  g_free(markup);
307
308
 
308
 
  QueueDraw ();
309
 
  _layout->QueueDraw ();
310
 
  QueueRelayout ();
 
309
  QueueDraw();
 
310
  _layout->QueueDraw();
 
311
  QueueRelayout();
311
312
}
312
313
 
313
314
void
314
 
PlacesHomeView::CreateShortcutFromExec (const char *exec,
315
 
                                        const char *name,
316
 
                                        std::vector<std::string>& alternatives)
 
315
PlacesHomeView::CreateShortcutFromExec(const char* exec,
 
316
                                       const char* name,
 
317
                                       std::vector<std::string>& alternatives)
317
318
{
318
 
  PlacesStyle     *style = PlacesStyle::GetDefault ();
319
 
  Shortcut        *shortcut = NULL;
320
 
  gchar           *id;
321
 
  gchar           *markup;
322
 
  gchar           *icon;
323
 
  gchar           *real_exec;
324
 
  GDesktopAppInfo *info;
 
319
  PlacesStyle*     style = PlacesStyle::GetDefault();
 
320
  Shortcut*        shortcut = NULL;
 
321
  gchar*           id;
 
322
  gchar*           markup;
 
323
  gchar*           icon;
 
324
  gchar*           real_exec;
 
325
  GDesktopAppInfo* info;
325
326
 
326
 
  markup = g_strdup_printf ("<big>%s</big>", name);
 
327
  markup = g_strdup_printf("<big>%s</big>", name);
327
328
 
328
329
  // We're going to try and create a desktop id from a exec string. Now, this is hairy at the
329
330
  // best of times but the following is the closest best-guess without having to do D-Bus
330
331
  // roundtrips to BAMF.
331
332
  if (exec)
332
333
  {
333
 
    char *basename;
 
334
    char* basename;
334
335
 
335
336
    if (exec[0] == '/')
336
 
      basename = g_path_get_basename (exec);
 
337
      basename = g_path_get_basename(exec);
337
338
    else
338
 
      basename = g_strdup (exec);
339
 
 
340
 
    id = g_strdup_printf ("%s.desktop", basename);
341
 
 
342
 
    g_free (basename);
 
339
      basename = g_strdup(exec);
 
340
 
 
341
    id = g_strdup_printf("%s.desktop", basename);
 
342
 
 
343
    g_free(basename);
343
344
  }
344
345
  else
345
346
  {
346
 
    id = g_strdup_printf ("%s.desktop", alternatives[0].c_str());
 
347
    id = g_strdup_printf("%s.desktop", alternatives[0].c_str());
347
348
  }
348
 
  
349
 
  info = g_desktop_app_info_new (id);
 
349
 
 
350
  info = g_desktop_app_info_new(id);
350
351
  std::vector<std::string>::iterator iter = alternatives.begin();
351
352
  while (iter != alternatives.end())
352
353
  {
353
 
    if (!G_IS_DESKTOP_APP_INFO (info))
 
354
    if (!G_IS_DESKTOP_APP_INFO(info))
354
355
    {
355
 
      id = g_strdup_printf ("%s.desktop", (*iter).c_str());
356
 
      info = g_desktop_app_info_new (id);
357
 
      iter++;    
 
356
      id = g_strdup_printf("%s.desktop", (*iter).c_str());
 
357
      info = g_desktop_app_info_new(id);
 
358
      iter++;
358
359
    }
359
 
  
360
 
    if (G_IS_DESKTOP_APP_INFO (info))
 
360
 
 
361
    if (G_IS_DESKTOP_APP_INFO(info))
361
362
    {
362
 
      icon = g_icon_to_string (g_app_info_get_icon (G_APP_INFO (info)));
363
 
      real_exec = g_strdup (g_app_info_get_executable (G_APP_INFO (info)));
364
 
      
365
 
      shortcut = new Shortcut (icon, markup, style->GetHomeTileIconSize ());
 
363
      icon = g_icon_to_string(g_app_info_get_icon(G_APP_INFO(info)));
 
364
      real_exec = g_strdup(g_app_info_get_executable(G_APP_INFO(info)));
 
365
 
 
366
      shortcut = new Shortcut(icon, markup, style->GetHomeTileIconSize());
366
367
      shortcut->_id = TYPE_EXEC;
367
368
      shortcut->_exec = real_exec;
368
 
      _layout->AddView (shortcut, 1, nux::eLeft, nux::eFull);
369
 
      shortcut->sigClick.connect (sigc::mem_fun (this, &PlacesHomeView::OnShortcutClicked));
370
 
      
371
 
      g_free (icon);
372
 
      
 
369
      _layout->AddView(shortcut, 1, nux::eLeft, nux::eFull);
 
370
      shortcut->sigClick.connect(sigc::mem_fun(this, &PlacesHomeView::OnShortcutClicked));
 
371
 
 
372
      g_free(icon);
 
373
 
373
374
      break;
374
375
    }
375
376
  }
376
 
  
377
 
  g_free (id);
378
 
  g_free (markup);
 
377
 
 
378
  g_free(id);
 
379
  g_free(markup);
379
380
}
380
381
 
381
382
void
382
 
PlacesHomeView::OnShortcutClicked (PlacesTile *tile)
 
383
PlacesHomeView::OnShortcutClicked(PlacesTile* tile)
383
384
{
384
 
  Shortcut *shortcut = static_cast<Shortcut *> (tile);
 
385
  Shortcut* shortcut = static_cast<Shortcut*>(tile);
385
386
  int id = shortcut->_id;
386
387
 
387
388
  if (id == TYPE_PLACE)
388
389
  {
389
 
    ubus_server_send_message (ubus_server_get_default (),
390
 
                              UBUS_PLACE_ENTRY_ACTIVATE_REQUEST,
391
 
                              g_variant_new ("(sus)",
392
 
                                             shortcut->_place_id,
393
 
                                             shortcut->_place_section,
394
 
                                             ""));
 
390
    ubus_server_send_message(ubus_server_get_default(),
 
391
                             UBUS_PLACE_ENTRY_ACTIVATE_REQUEST,
 
392
                             g_variant_new("(sus)",
 
393
                                           shortcut->_place_id,
 
394
                                           shortcut->_place_section,
 
395
                                           ""));
395
396
  }
396
397
  else if (id == TYPE_EXEC)
397
398
  {
398
 
    GError *error = NULL;
 
399
    GError* error = NULL;
399
400
 
400
 
    if (!g_spawn_command_line_async (shortcut->_exec, &error))
 
401
    if (!g_spawn_command_line_async(shortcut->_exec, &error))
401
402
    {
402
 
      g_warning ("%s: Unable to launch %s: %s",
403
 
                 G_STRFUNC,
404
 
                 shortcut->_exec,
405
 
                 error->message);
406
 
      g_error_free (error);
 
403
      g_warning("%s: Unable to launch %s: %s",
 
404
                G_STRFUNC,
 
405
                shortcut->_exec,
 
406
                error->message);
 
407
      g_error_free(error);
407
408
    }
408
 
    
409
 
    ubus_server_send_message (ubus_server_get_default (),
410
 
                              UBUS_PLACE_VIEW_CLOSE_REQUEST,
411
 
                              NULL);
 
409
 
 
410
    ubus_server_send_message(ubus_server_get_default(),
 
411
                             UBUS_PLACE_VIEW_CLOSE_REQUEST,
 
412
                             NULL);
412
413
  }
413
414
}
414
415
 
415
 
const gchar* PlacesHomeView::GetName ()
 
416
const gchar* PlacesHomeView::GetName()
416
417
{
417
 
        return "PlacesHomeView";
 
418
  return "PlacesHomeView";
418
419
}
419
420
 
420
 
const gchar *
421
 
PlacesHomeView::GetChildsName ()
 
421
const gchar*
 
422
PlacesHomeView::GetChildsName()
422
423
{
423
424
  return "";
424
425
}
425
426
 
426
 
void PlacesHomeView::AddProperties (GVariantBuilder *builder)
 
427
void PlacesHomeView::AddProperties(GVariantBuilder* builder)
427
428
{
428
429
  unity::variant::BuilderWrapper(builder).add(GetGeometry());
429
430
}
430
431
 
431
432
// TODO: put that in some "util" toolbox
432
 
struct timespec PlacesHomeView::time_diff (struct timespec start, struct timespec end)
 
433
struct timespec PlacesHomeView::time_diff(struct timespec start, struct timespec end)
433
434
{
434
435
  struct timespec temp;
435
 
  if ((end.tv_nsec - start.tv_nsec) < 0) {
436
 
    temp.tv_sec = end.tv_sec - start.tv_sec-1;
 
436
  if ((end.tv_nsec - start.tv_nsec) < 0)
 
437
  {
 
438
    temp.tv_sec = end.tv_sec - start.tv_sec - 1;
437
439
    temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
438
 
  } else {
 
440
  }
 
441
  else
 
442
  {
439
443
    temp.tv_sec = end.tv_sec - start.tv_sec;
440
444
    temp.tv_nsec = end.tv_nsec - start.tv_nsec;
441
445
  }