~robert-ancell/indicator-datetime/unity-control-center2

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Tarmac
  • Author(s): Charles Kerr
  • Date: 2013-10-17 03:39:12 UTC
  • mfrom: (267.2.22 lp-1233176)
  • Revision ID: tarmac-20131017033912-o7qc0p8w07h2853g
== Changes to planner-eds:

The get-appointments GTask has a new task subtype for pulling an ECalComponent's uris asynchronously.

When get_appointments() is called, create one GTask. We add subtasks to it for each client we know of for calling e_cal_client_generate_instances(). What's new is that for each ECalComponent we find in generate_instances(), we add another new subtask that tries to get the uris for that component.

== Testing changes:

Make "planner" a property in IndicatorDatetimeService so that we can swap in different appointment planners at runtime. This is for unit testing purposes.

Add a mechanism for testing snap decisions without an EDS backend.

== Service changes:

Every time the appointment list changes, walk through it to find the alarm that will occur the soonest. Set a timer to wake up at that time. When the timer is reached, pop up a snap decision for each alarm set to that time. If the user clicks "OK", dispatch the URL associated with that alarm.

Made the appointment menuitems clickable, they now dispatch the appointment's URL. Fixes: https://bugs.launchpad.net/bugs/1233176.

Approved by PS Jenkins bot, Ted Gould.

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 <libnotify/notify.h> 
27
28
 
 
29
#include "planner-eds.h"
 
30
#include "planner-mock.h"
28
31
#include "service.h"
29
32
 
30
33
/***
31
34
****
32
35
***/
33
36
 
 
37
/* When enabled, new alarms will show up every minute to test snap decisions */
 
38
static gboolean test_alarms = FALSE;
 
39
 
 
40
static GOptionEntry entries[] = {
 
41
  { "test-alarms", '\0', 0, G_OPTION_ARG_NONE, &test_alarms, "Test Alarms", NULL },
 
42
  { NULL }
 
43
};
 
44
 
34
45
static void
35
46
on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)
36
47
{
37
48
  g_message ("exiting: service couldn't acquire or lost ownership of busname");
38
 
  g_main_loop_quit ((GMainLoop*)loop);
 
49
 
 
50
  if (!test_alarms)
 
51
    g_main_loop_quit ((GMainLoop*)loop);
39
52
}
40
53
 
41
54
int
42
55
main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
43
56
{
 
57
  GOptionContext * context;
 
58
  GError * error;
 
59
  IndicatorDatetimePlanner * planner;
 
60
  IndicatorDatetimeService * service;
44
61
  GMainLoop * loop;
45
 
  IndicatorDatetimeService * service;
46
62
 
47
63
  /* boilerplate i18n */
48
64
  setlocale (LC_ALL, "");
49
65
  bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
50
66
  textdomain (GETTEXT_PACKAGE);
51
67
 
 
68
  /* init libnotify */
 
69
  if (!notify_init ("indicator-datetime-service"))
 
70
    g_critical ("libnotify initialization failed");
 
71
 
 
72
  /* parse command-line options */
 
73
  context = g_option_context_new (NULL);
 
74
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
 
75
  if (!g_option_context_parse (context, &argc, &argv, &error))
 
76
    {
 
77
      g_print("option parsing failed: %s\n", error->message);
 
78
      return EXIT_FAILURE;
 
79
    }
 
80
 
 
81
  /* set up the planner */
 
82
  if (test_alarms)
 
83
    {
 
84
      g_message ("Using fake appointment book for testing alarms.");
 
85
      planner = indicator_datetime_planner_mock_new ();
 
86
    }
 
87
  else
 
88
    {
 
89
      planner = indicator_datetime_planner_eds_new ();
 
90
    }
 
91
 
52
92
  /* run */
53
 
  service = indicator_datetime_service_new ();
 
93
  service = indicator_datetime_service_new (planner);
54
94
  loop = g_main_loop_new (NULL, FALSE);
55
95
  g_signal_connect (service, INDICATOR_DATETIME_SERVICE_SIGNAL_NAME_LOST,
56
96
                    G_CALLBACK(on_name_lost), loop);
57
97
  g_main_loop_run (loop);
58
98
 
59
99
  /* cleanup */
60
 
  g_clear_object (&service);
61
100
  g_main_loop_unref (loop);
 
101
  g_object_unref (service);
 
102
  g_object_unref (planner);
62
103
  return 0;
63
104
}