~cyphermox/indicator-datetime/revert277

« back to all changes in this revision

Viewing changes to src/service.c

  • Committer: Tarmac
  • Author(s): Charles Kerr
  • Date: 2013-10-15 20:20:18 UTC
  • mfrom: (270.1.2 lp-1227106)
  • Revision ID: tarmac-20131015202018-ujcnfa27j69vzulr
Changes the phone profile's "Clock" menuitem in two ways:

 1. instead of using a stock icon, try to use the clock app's icon.

 2. when clicked, launch the clock app. Fixes: https://bugs.launchpad.net/bugs/1227106.

Approved by Ted Gould, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include <glib/gi18n.h>
26
26
#include <gio/gio.h>
 
27
#include <json-glib/json-glib.h>
27
28
#include <url-dispatcher.h>
28
29
 
29
30
#include "dbus-shared.h"
98
99
  /* cached GTimeZone for use by indicator_datetime_service_get_localtime() */
99
100
  GTimeZone * internal_timezone;
100
101
 
 
102
  /* the clock app's icon filename */
 
103
  gchar * clock_app_icon_filename;
 
104
 
 
105
  /* Whether or not we've tried to load the clock app's icon.
 
106
     This way we don't keep trying to reload it on the desktop */
 
107
  gboolean clock_app_icon_initialized;
 
108
 
101
109
  guint own_id;
102
110
  guint actions_export_id;
103
111
  GDBusConnection * conn;
783
791
  g_date_time_unref (now);
784
792
}
785
793
 
 
794
 
 
795
/* try to extract the clock app's filename from click. (/$pkgdir/$icon) */
 
796
static gchar *
 
797
get_clock_app_icon_filename (void)
 
798
{
 
799
  gchar * icon_filename = NULL;
 
800
  gchar * pkgdir;
 
801
 
 
802
  pkgdir = NULL;
 
803
  g_spawn_command_line_sync ("click pkgdir com.ubuntu.clock", &pkgdir, NULL, NULL, NULL);
 
804
  if (pkgdir != NULL)
 
805
    {
 
806
      gchar * manifest = NULL;
 
807
      g_strstrip (pkgdir);
 
808
      g_spawn_command_line_sync ("click info com.ubuntu.clock", &manifest, NULL, NULL, NULL);
 
809
      if (manifest != NULL)
 
810
        {
 
811
          JsonParser * parser = json_parser_new ();
 
812
          if (json_parser_load_from_data (parser, manifest, -1, NULL))
 
813
            {
 
814
              JsonNode * root = json_parser_get_root (parser); /* transfer-none */
 
815
              if ((root != NULL) && (JSON_NODE_TYPE(root) == JSON_NODE_OBJECT))
 
816
                {
 
817
                  JsonObject * o = json_node_get_object (root); /* transfer-none */
 
818
                  const gchar * icon_name = json_object_get_string_member (o, "icon");
 
819
                  if (icon_name != NULL)
 
820
                    icon_filename = g_build_filename (pkgdir, icon_name, NULL);
 
821
                }
 
822
            }
 
823
          g_object_unref (parser);
 
824
          g_free (manifest);
 
825
        }
 
826
      g_free (pkgdir);
 
827
    }
 
828
 
 
829
  return icon_filename;
 
830
}
 
831
 
786
832
static GMenuModel *
787
833
create_phone_appointments_section (IndicatorDatetimeService * self)
788
834
{
 
835
  priv_t * p = self->priv;
789
836
  GMenu * menu = g_menu_new ();
790
837
  GMenuItem * menu_item;
791
838
 
792
 
  menu_item = g_menu_item_new (_("Clock"), NULL);
793
 
  g_menu_item_set_attribute (menu_item, G_MENU_ATTRIBUTE_ICON, "s", "clock");
 
839
  if (G_UNLIKELY (!p->clock_app_icon_initialized))
 
840
    {
 
841
      p->clock_app_icon_initialized = TRUE;
 
842
      p->clock_app_icon_filename = get_clock_app_icon_filename ();
 
843
    }
 
844
 
 
845
  menu_item = g_menu_item_new (_("Clock"), "indicator.activate-phone-clock-app");
 
846
  if (p->clock_app_icon_filename != NULL)
 
847
    g_menu_item_set_attribute (menu_item, G_MENU_ATTRIBUTE_ICON, "s", p->clock_app_icon_filename);
794
848
  g_menu_append_item (menu, menu_item);
795
849
  g_object_unref (menu_item);
796
850
 
1312
1366
}
1313
1367
 
1314
1368
static void
 
1369
on_phone_clock_activated (GSimpleAction * a      G_GNUC_UNUSED,
 
1370
                          GVariant      * param  G_GNUC_UNUSED,
 
1371
                          gpointer        gself  G_GNUC_UNUSED)
 
1372
{
 
1373
  const char * url = "appid://com.ubuntu.clock/clock/current-user-version";
 
1374
  url_dispatch_send (url, NULL, NULL);
 
1375
}
 
1376
 
 
1377
static void
1315
1378
on_activate_planner (GSimpleAction * a         G_GNUC_UNUSED,
1316
1379
                     GVariant      * param,
1317
1380
                     gpointer        gself)
1364
1427
  GActionEntry entries[] = {
1365
1428
    { "activate-desktop-settings", on_desktop_settings_activated },
1366
1429
    { "activate-phone-settings", on_phone_settings_activated },
 
1430
    { "activate-phone-clock-app", on_phone_clock_activated },
1367
1431
    { "activate-planner", on_activate_planner, "x", NULL },
1368
1432
    { "set-location", on_set_location, "s" }
1369
1433
  };
1834
1898
  IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE(o);
1835
1899
  priv_t * p = self->priv;
1836
1900
 
 
1901
  g_free (p->clock_app_icon_filename);
1837
1902
  g_clear_pointer (&p->skew_time, g_date_time_unref);
1838
1903
  g_clear_pointer (&p->calendar_date, g_date_time_unref);
1839
1904