~nicovdw/unity/fix-for-733743

« back to all changes in this revision

Viewing changes to src/PlaceRemote.cpp

[merge] various fixes work

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#define MIME_PATTERN     "MimetypePattern"
33
33
 
34
34
#define PLACE_IFACE "com.canonical.Unity.Place"
 
35
#define ACTIVE_IFACE "com.canonical.Unity.Activation"
35
36
 
36
37
static void on_service_proxy_ready (GObject      *source,
37
38
                                    GAsyncResult *result,
60
61
  GKeyFile *key_file;
61
62
  GError   *error = NULL;
62
63
 
63
 
  g_debug ("Loading Place: %s", path);
64
64
  _path = g_strdup (path);
65
65
 
66
66
  // A .place file is a keyfile, so we create on representing the .place file to
216
216
                            NULL,
217
217
                            on_service_proxy_ready,
218
218
                            this);
 
219
 
 
220
  if (_uri_regex || _mime_regex)
 
221
    g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
 
222
                              G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
 
223
                              NULL,
 
224
                              _dbus_name,
 
225
                              _dbus_path,
 
226
                              ACTIVE_IFACE,
 
227
                              NULL,
 
228
                              (GAsyncReadyCallback)PlaceRemote::OnActivationProxyReady,
 
229
                              this);
219
230
}
220
231
 
221
232
std::vector<PlaceEntry *>&
244
255
 
245
256
    if (g_str_has_prefix (group, ENTRY_PREFIX))
246
257
    {
247
 
      PlaceEntryRemote *entry = new PlaceEntryRemote (_dbus_name);
 
258
      PlaceEntryRemote *entry = new PlaceEntryRemote (this, _dbus_name);
248
259
      entry->InitFromKeyFile (key_file, group);
249
260
      
250
261
      if (entry->IsValid ())
369
380
 
370
381
    if (!existing)
371
382
    {
372
 
      existing = new PlaceEntryRemote (_dbus_name);
 
383
      existing = new PlaceEntryRemote (this, _dbus_name);
373
384
 
374
385
      _entries.push_back (existing);
375
386
      entry_added.emit (existing);
456
467
                 &global_results_model,
457
468
                 &global_hints);
458
469
 
459
 
  entry = new PlaceEntryRemote (_dbus_name);
 
470
  entry = new PlaceEntryRemote (this, _dbus_name);
460
471
  entry->Update (dbus_path,
461
472
                 name,
462
473
                 icon,
512
523
  }
513
524
}
514
525
 
 
526
void
 
527
PlaceRemote::OnActivationResultReceived (GObject      *source,
 
528
                                         GAsyncResult *result,
 
529
                                         PlaceRemote  *self)
 
530
{
 
531
  GVariant    *args;
 
532
  GError      *error = NULL;
 
533
  guint        ret = 0;
 
534
 
 
535
  args = g_dbus_proxy_call_finish ((GDBusProxy *)source, result, &error);
 
536
  if (error)
 
537
  {
 
538
    g_warning ("Unable to call Activate() on: %s",
 
539
               error->message);
 
540
    g_error_free (error);
 
541
    return;
 
542
  }
 
543
 
 
544
  self->result_activated.emit (self->_active_uri.c_str (), (ActivationResult)ret);
 
545
 
 
546
  g_variant_unref (args);
 
547
}
 
548
 
 
549
void
 
550
PlaceRemote::ActivateResult (const char *uri, const char *mimetype)
 
551
{
 
552
  if (G_IS_DBUS_PROXY (_activation_proxy)
 
553
      && ((_uri_regex && g_regex_match (_uri_regex, uri, (GRegexMatchFlags)0, NULL))
 
554
          || (_mime_regex && g_regex_match (_mime_regex, mimetype, (GRegexMatchFlags)0, NULL))))
 
555
  {
 
556
    _active_uri = uri;
 
557
    g_dbus_proxy_call (_activation_proxy,
 
558
                       "Activate",
 
559
                       g_variant_new ("(s)", uri),
 
560
                       G_DBUS_CALL_FLAGS_NONE,
 
561
                       -1, 
 
562
                       NULL,
 
563
                       (GAsyncReadyCallback)OnActivationResultReceived,
 
564
                       this);
 
565
  }
 
566
  else
 
567
  {
 
568
    result_activated.emit (uri, FALLBACK);
 
569
  }
 
570
}
 
571
 
 
572
void
 
573
PlaceRemote::OnActivationProxyReady (GObject      *source,
 
574
                                     GAsyncResult *result,
 
575
                                     PlaceRemote  *self)
 
576
{
 
577
  GError *error = NULL;
 
578
  gchar  *name_owner = NULL;
 
579
 
 
580
  self->_activation_proxy = g_dbus_proxy_new_for_bus_finish (result, &error);
 
581
  name_owner = g_dbus_proxy_get_name_owner (self->_activation_proxy);
 
582
 
 
583
  if (error || !name_owner)
 
584
  {
 
585
    g_warning ("Unable to connect to PlaceRemote Activation %s: %s",
 
586
               self->_dbus_name,
 
587
               error ? error->message : "No name owner");
 
588
    if (error)
 
589
      g_error_free (error);
 
590
  }
 
591
 
 
592
  g_free (name_owner);
 
593
}
 
594
 
 
595
 
515
596
/*
516
597
 * C callbacks
517
598
 */