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

« back to all changes in this revision

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

Update formatting to match style (as close as possible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "LauncherEntryRemote.h"
21
21
 
22
 
NUX_IMPLEMENT_OBJECT_TYPE (LauncherEntryRemote);
 
22
NUX_IMPLEMENT_OBJECT_TYPE(LauncherEntryRemote);
23
23
 
24
24
/**
25
25
 * Create a new LauncherEntryRemote parsed from the raw DBus wire format
30
30
 * You don't normally need to use this constructor yourself. The
31
31
 * LauncherEntryRemoteModel will do that for you when needed.
32
32
 */
33
 
LauncherEntryRemote::LauncherEntryRemote(const gchar *dbus_name, GVariant *val)
 
33
LauncherEntryRemote::LauncherEntryRemote(const gchar* dbus_name, GVariant* val)
34
34
{
35
 
  gchar        *app_uri;
36
 
  GVariantIter *prop_iter;
37
 
 
38
 
  g_return_if_fail (dbus_name != NULL);
39
 
  g_return_if_fail (val != NULL);
40
 
 
41
 
  _dbus_name = g_strdup (dbus_name);
 
35
  gchar*        app_uri;
 
36
  GVariantIter* prop_iter;
 
37
 
 
38
  g_return_if_fail(dbus_name != NULL);
 
39
  g_return_if_fail(val != NULL);
 
40
 
 
41
  _dbus_name = g_strdup(dbus_name);
42
42
 
43
43
  _emblem = NULL;
44
 
  _count = G_GINT64_CONSTANT (0);
 
44
  _count = G_GINT64_CONSTANT(0);
45
45
  _progress = 0.0;
46
46
  _quicklist = NULL;
47
 
  
 
47
 
48
48
  _emblem_visible = FALSE;
49
49
  _count_visible = FALSE;
50
50
  _progress_visible = FALSE;
51
51
 
52
52
  _urgent = FALSE;
53
53
 
54
 
  g_variant_ref_sink (val);
55
 
  g_variant_get (val, "(sa{sv})", &app_uri, &prop_iter);
 
54
  g_variant_ref_sink(val);
 
55
  g_variant_get(val, "(sa{sv})", &app_uri, &prop_iter);
56
56
 
57
57
  _app_uri = app_uri; // steal ref
58
58
 
59
 
  Update (prop_iter);
 
59
  Update(prop_iter);
60
60
 
61
 
  g_variant_iter_free (prop_iter);
62
 
  g_variant_unref (val);
 
61
  g_variant_iter_free(prop_iter);
 
62
  g_variant_unref(val);
63
63
}
64
64
 
65
65
LauncherEntryRemote::~LauncherEntryRemote()
66
66
{
67
67
  if (_dbus_name)
68
 
    {
69
 
      g_free (_dbus_name);
70
 
      _dbus_name = NULL;
71
 
    }
 
68
  {
 
69
    g_free(_dbus_name);
 
70
    _dbus_name = NULL;
 
71
  }
72
72
 
73
73
  if (_app_uri)
74
 
    {
75
 
      g_free (_app_uri);
76
 
      _app_uri = NULL;
77
 
    }
78
 
  
 
74
  {
 
75
    g_free(_app_uri);
 
76
    _app_uri = NULL;
 
77
  }
 
78
 
79
79
  if (_emblem)
80
 
    {
81
 
      g_free (_emblem);
82
 
      _emblem = NULL;
83
 
    }
 
80
  {
 
81
    g_free(_emblem);
 
82
    _emblem = NULL;
 
83
  }
84
84
 
85
85
  if (_quicklist)
86
 
    {
87
 
      g_object_unref (_quicklist);
88
 
      _quicklist = NULL;
89
 
    }
 
86
  {
 
87
    g_object_unref(_quicklist);
 
88
    _quicklist = NULL;
 
89
  }
90
90
}
91
91
 
92
92
/**
175
175
void
176
176
LauncherEntryRemote::SetDBusName(const gchar* dbus_name)
177
177
{
178
 
  gchar *old_name;
 
178
  gchar* old_name;
179
179
 
180
 
  if (g_strcmp0 (_dbus_name, dbus_name) == 0)
 
180
  if (g_strcmp0(_dbus_name, dbus_name) == 0)
181
181
    return;
182
182
 
183
183
  old_name = _dbus_name;
184
 
  _dbus_name = g_strdup (dbus_name);
 
184
  _dbus_name = g_strdup(dbus_name);
185
185
 
186
186
  /* Remove the quicklist since we can't know if it it'll be valid on the
187
187
   * new name, and we certainly don't want the quicklist to operate on a
188
188
   * different name than the rest of the launcher API */
189
 
  SetQuicklist (NULL);
 
189
  SetQuicklist(NULL);
190
190
 
191
 
  dbus_name_changed.emit (this, old_name);
192
 
  g_free (old_name);
 
191
  dbus_name_changed.emit(this, old_name);
 
192
  g_free(old_name);
193
193
}
194
194
 
195
195
void
196
196
LauncherEntryRemote::SetEmblem(const gchar* emblem)
197
197
{
198
 
  if (g_strcmp0 (_emblem, emblem) == 0)
 
198
  if (g_strcmp0(_emblem, emblem) == 0)
199
199
    return;
200
200
 
201
201
  if (_emblem)
202
 
    g_free (_emblem);
 
202
    g_free(_emblem);
203
203
 
204
 
  _emblem = g_strdup (emblem);
205
 
  emblem_changed.emit (this);
 
204
  _emblem = g_strdup(emblem);
 
205
  emblem_changed.emit(this);
206
206
}
207
207
 
208
208
void
212
212
    return;
213
213
 
214
214
  _count = count;
215
 
  count_changed.emit (this);
 
215
  count_changed.emit(this);
216
216
}
217
217
 
218
218
void
222
222
    return;
223
223
 
224
224
  _progress = progress;
225
 
  progress_changed.emit (this);
 
225
  progress_changed.emit(this);
226
226
}
227
227
 
228
228
/**
232
232
 * To unset the quicklist pass in a NULL path or empty string.
233
233
 */
234
234
void
235
 
LauncherEntryRemote::SetQuicklistPath(const gchar *dbus_path)
 
235
LauncherEntryRemote::SetQuicklistPath(const gchar* dbus_path)
236
236
{
237
237
  /* Replace "" with NULL to simplify the logic below */
238
 
  if (g_strcmp0 ("", dbus_path) == 0)
239
 
    {
240
 
      dbus_path = NULL;
241
 
    }
 
238
  if (g_strcmp0("", dbus_path) == 0)
 
239
  {
 
240
    dbus_path = NULL;
 
241
  }
242
242
 
243
243
  /* Check if existing quicklist have exact same path
244
244
   * and ignore the change in that case */
245
245
  if (_quicklist)
 
246
  {
 
247
    gchar* ql_path;
 
248
    g_object_get(_quicklist, DBUSMENU_CLIENT_PROP_DBUS_OBJECT, &ql_path, NULL);
 
249
    if (g_strcmp0(dbus_path, ql_path) == 0)
246
250
    {
247
 
      gchar *ql_path;
248
 
      g_object_get (_quicklist, DBUSMENU_CLIENT_PROP_DBUS_OBJECT, &ql_path, NULL);
249
 
      if (g_strcmp0 (dbus_path, ql_path) == 0)
250
 
        {
251
 
          g_free (ql_path);
252
 
          return;
253
 
        }
 
251
      g_free(ql_path);
 
252
      return;
 
253
    }
254
254
 
255
 
      /* Prepare for a new quicklist */
256
 
      g_free (ql_path);
257
 
      g_object_unref (_quicklist);
258
 
    }
 
255
    /* Prepare for a new quicklist */
 
256
    g_free(ql_path);
 
257
    g_object_unref(_quicklist);
 
258
  }
259
259
  else if (_quicklist == NULL && dbus_path == NULL)
260
260
    return;
261
261
 
262
262
  if (dbus_path != NULL)
263
 
    _quicklist = dbusmenu_client_new (_dbus_name, dbus_path);
 
263
    _quicklist = dbusmenu_client_new(_dbus_name, dbus_path);
264
264
  else
265
265
    _quicklist = NULL;
266
266
 
267
 
  quicklist_changed.emit (this);
 
267
  quicklist_changed.emit(this);
268
268
}
269
269
 
270
270
/**
274
274
 * To unset the quicklist for this entry pass in NULL as the quicklist to set.
275
275
 */
276
276
void
277
 
LauncherEntryRemote::SetQuicklist(DbusmenuClient *quicklist)
 
277
LauncherEntryRemote::SetQuicklist(DbusmenuClient* quicklist)
278
278
{
279
279
  /* Check if existing quicklist have exact same path as the new one
280
280
   * and ignore the change in that case. We also assert that the quicklist
281
281
   * uses the same name as the connection owning this launcher entry */
282
282
  if (_quicklist)
283
 
    {
284
 
      gchar *ql_path, *new_ql_path, *new_ql_name;
285
 
      g_object_get (_quicklist, DBUSMENU_CLIENT_PROP_DBUS_OBJECT, &ql_path, NULL);
286
 
 
287
 
      if (quicklist == NULL)
288
 
        {
289
 
          new_ql_path = NULL;
290
 
          new_ql_name = NULL;
291
 
        }
292
 
      else
293
 
        {
294
 
          g_object_get (quicklist, DBUSMENU_CLIENT_PROP_DBUS_OBJECT, &new_ql_path, NULL);
295
 
          g_object_get (quicklist, DBUSMENU_CLIENT_PROP_DBUS_NAME, &new_ql_name, NULL);
296
 
        }
297
 
 
298
 
      if (quicklist != NULL && g_strcmp0 (new_ql_name, _dbus_name) != 0)
299
 
        {
300
 
          g_critical ("Mismatch between quicklist- and launcher entry owner:"
301
 
                      "%s and %s respectively", new_ql_name, _dbus_name);
302
 
          g_free (ql_path);
303
 
          g_free (new_ql_path);
304
 
          g_free (new_ql_name);
305
 
          return;
306
 
        }
307
 
 
308
 
      if (g_strcmp0 (new_ql_path, ql_path) == 0)
309
 
        {
310
 
          g_free (ql_path);
311
 
          g_free (new_ql_path);
312
 
          g_free (new_ql_name);
313
 
          return;
314
 
        }
315
 
 
316
 
      /* Prepare for a new quicklist */
317
 
      g_free (ql_path);
318
 
      g_free (new_ql_path);
319
 
      g_free (new_ql_name);
320
 
      g_object_unref (_quicklist);
321
 
    }
 
283
  {
 
284
    gchar* ql_path, *new_ql_path, *new_ql_name;
 
285
    g_object_get(_quicklist, DBUSMENU_CLIENT_PROP_DBUS_OBJECT, &ql_path, NULL);
 
286
 
 
287
    if (quicklist == NULL)
 
288
    {
 
289
      new_ql_path = NULL;
 
290
      new_ql_name = NULL;
 
291
    }
 
292
    else
 
293
    {
 
294
      g_object_get(quicklist, DBUSMENU_CLIENT_PROP_DBUS_OBJECT, &new_ql_path, NULL);
 
295
      g_object_get(quicklist, DBUSMENU_CLIENT_PROP_DBUS_NAME, &new_ql_name, NULL);
 
296
    }
 
297
 
 
298
    if (quicklist != NULL && g_strcmp0(new_ql_name, _dbus_name) != 0)
 
299
    {
 
300
      g_critical("Mismatch between quicklist- and launcher entry owner:"
 
301
                 "%s and %s respectively", new_ql_name, _dbus_name);
 
302
      g_free(ql_path);
 
303
      g_free(new_ql_path);
 
304
      g_free(new_ql_name);
 
305
      return;
 
306
    }
 
307
 
 
308
    if (g_strcmp0(new_ql_path, ql_path) == 0)
 
309
    {
 
310
      g_free(ql_path);
 
311
      g_free(new_ql_path);
 
312
      g_free(new_ql_name);
 
313
      return;
 
314
    }
 
315
 
 
316
    /* Prepare for a new quicklist */
 
317
    g_free(ql_path);
 
318
    g_free(new_ql_path);
 
319
    g_free(new_ql_name);
 
320
    g_object_unref(_quicklist);
 
321
  }
322
322
  else if (_quicklist == NULL && quicklist == NULL)
323
323
    return;
324
324
 
325
325
  if (quicklist == NULL)
326
326
    _quicklist = NULL;
327
327
  else
328
 
    _quicklist = (DbusmenuClient *) g_object_ref (quicklist);
 
328
    _quicklist = (DbusmenuClient*) g_object_ref(quicklist);
329
329
 
330
 
  quicklist_changed.emit (this);
 
330
  quicklist_changed.emit(this);
331
331
}
332
332
 
333
333
void
337
337
    return;
338
338
 
339
339
  _emblem_visible = visible;
340
 
  emblem_visible_changed.emit (this);
 
340
  emblem_visible_changed.emit(this);
341
341
}
342
342
 
343
343
void
344
344
LauncherEntryRemote::SetCountVisible(gboolean visible)
345
345
{
346
346
  if (_count_visible == visible)
347
 
      return;
 
347
    return;
348
348
 
349
349
  _count_visible = visible;
350
 
  count_visible_changed.emit (this);
 
350
  count_visible_changed.emit(this);
351
351
}
352
352
 
353
353
void
354
354
LauncherEntryRemote::SetProgressVisible(gboolean visible)
355
355
{
356
356
  if (_progress_visible == visible)
357
 
      return;
 
357
    return;
358
358
 
359
359
  _progress_visible = visible;
360
 
  progress_visible_changed.emit (this);
 
360
  progress_visible_changed.emit(this);
361
361
}
362
362
 
363
363
void
364
 
LauncherEntryRemote::SetUrgent (gboolean urgent)
 
364
LauncherEntryRemote::SetUrgent(gboolean urgent)
365
365
{
366
366
  if (_urgent == urgent)
367
367
    return;
368
 
  
 
368
 
369
369
  _urgent = urgent;
370
 
  urgent_changed.emit (this);
 
370
  urgent_changed.emit(this);
371
371
}
372
372
 
373
373
/**
374
374
 * Set all properties from 'other' on 'this'.
375
375
 */
376
376
void
377
 
LauncherEntryRemote::Update(LauncherEntryRemote *other)
 
377
LauncherEntryRemote::Update(LauncherEntryRemote* other)
378
378
{
379
379
  /* It's important that we update the DBus name first since it might
380
380
   * unset the quicklist if it changes */
381
 
  SetDBusName (other->DBusName ());
382
 
 
383
 
  SetEmblem (other->Emblem ());
384
 
  SetCount (other->Count ());
385
 
  SetProgress (other->Progress ());
386
 
  SetQuicklist (other->Quicklist());
387
 
  SetUrgent (other->Urgent ());
388
 
 
389
 
  SetEmblemVisible (other->EmblemVisible ());
390
 
  SetCountVisible(other->CountVisible ());
 
381
  SetDBusName(other->DBusName());
 
382
 
 
383
  SetEmblem(other->Emblem());
 
384
  SetCount(other->Count());
 
385
  SetProgress(other->Progress());
 
386
  SetQuicklist(other->Quicklist());
 
387
  SetUrgent(other->Urgent());
 
388
 
 
389
  SetEmblemVisible(other->EmblemVisible());
 
390
  SetCountVisible(other->CountVisible());
391
391
  SetProgressVisible(other->ProgressVisible());
392
392
}
393
393
 
396
396
 * any properties to 'this'.
397
397
 */
398
398
void
399
 
LauncherEntryRemote::Update(GVariantIter *prop_iter)
 
399
LauncherEntryRemote::Update(GVariantIter* prop_iter)
400
400
{
401
 
  gchar       *prop_key;
402
 
  const gchar *prop_value_s;
403
 
  GVariant    *prop_value;
404
 
 
405
 
  g_return_if_fail (prop_iter != NULL);
406
 
 
407
 
  while (g_variant_iter_loop (prop_iter, "{sv}", &prop_key, &prop_value))
408
 
    {
409
 
      if (g_str_equal ("emblem", prop_key))
410
 
        {
411
 
          prop_value_s = g_variant_get_string (prop_value, NULL);
412
 
          SetEmblem (prop_value_s);
413
 
        }
414
 
      else if (g_str_equal ("count", prop_key))
415
 
        SetCount (g_variant_get_int64 (prop_value));
416
 
      else if (g_str_equal ("progress", prop_key))
417
 
        SetProgress (g_variant_get_double (prop_value));
418
 
      else if (g_str_equal ("emblem-visible", prop_key))
419
 
        SetEmblemVisible (g_variant_get_boolean (prop_value));
420
 
      else if (g_str_equal ("count-visible", prop_key))
421
 
        SetCountVisible (g_variant_get_boolean (prop_value));
422
 
      else if (g_str_equal ("progress-visible", prop_key))
423
 
        SetProgressVisible (g_variant_get_boolean (prop_value));
424
 
      else if (g_str_equal ("urgent", prop_key))
425
 
        SetUrgent (g_variant_get_boolean (prop_value));
426
 
      else if (g_str_equal ("quicklist", prop_key))
427
 
        {
428
 
          /* The value is the object path of the dbusmenu */
429
 
          prop_value_s = g_variant_get_string (prop_value,  NULL);
430
 
          SetQuicklistPath (prop_value_s);
431
 
        }
432
 
    }
 
401
  gchar*       prop_key;
 
402
  const gchar* prop_value_s;
 
403
  GVariant*    prop_value;
 
404
 
 
405
  g_return_if_fail(prop_iter != NULL);
 
406
 
 
407
  while (g_variant_iter_loop(prop_iter, "{sv}", &prop_key, &prop_value))
 
408
  {
 
409
    if (g_str_equal("emblem", prop_key))
 
410
    {
 
411
      prop_value_s = g_variant_get_string(prop_value, NULL);
 
412
      SetEmblem(prop_value_s);
 
413
    }
 
414
    else if (g_str_equal("count", prop_key))
 
415
      SetCount(g_variant_get_int64(prop_value));
 
416
    else if (g_str_equal("progress", prop_key))
 
417
      SetProgress(g_variant_get_double(prop_value));
 
418
    else if (g_str_equal("emblem-visible", prop_key))
 
419
      SetEmblemVisible(g_variant_get_boolean(prop_value));
 
420
    else if (g_str_equal("count-visible", prop_key))
 
421
      SetCountVisible(g_variant_get_boolean(prop_value));
 
422
    else if (g_str_equal("progress-visible", prop_key))
 
423
      SetProgressVisible(g_variant_get_boolean(prop_value));
 
424
    else if (g_str_equal("urgent", prop_key))
 
425
      SetUrgent(g_variant_get_boolean(prop_value));
 
426
    else if (g_str_equal("quicklist", prop_key))
 
427
    {
 
428
      /* The value is the object path of the dbusmenu */
 
429
      prop_value_s = g_variant_get_string(prop_value,  NULL);
 
430
      SetQuicklistPath(prop_value_s);
 
431
    }
 
432
  }
433
433
}