From 70487ccce4dbcf04f9dfb02ba50f7e88e428f14a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 21:02:17 -0500 Subject: move planner instantiation to main.c so that we can prepare to pass in a mock planner for testing --- src/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index c75b2d7..710db66 100644 --- a/src/main.c +++ b/src/main.c @@ -25,6 +25,7 @@ #include #include +#include "planner-eds.h" #include "service.h" /*** @@ -41,23 +42,28 @@ on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop) int main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) { - GMainLoop * loop; + IndicatorDatetimePlanner * planner; IndicatorDatetimeService * service; + GMainLoop * loop; /* boilerplate i18n */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); + /* get the planner */ + planner = indicator_datetime_planner_eds_new (); + /* run */ - service = indicator_datetime_service_new (); + service = indicator_datetime_service_new (planner); loop = g_main_loop_new (NULL, FALSE); g_signal_connect (service, INDICATOR_DATETIME_SERVICE_SIGNAL_NAME_LOST, G_CALLBACK(on_name_lost), loop); g_main_loop_run (loop); /* cleanup */ - g_clear_object (&service); g_main_loop_unref (loop); + g_object_unref (service); + g_object_unref (planner); return 0; } -- cgit v1.2.3 From b6b0c140f922385d947fa12dfff179a5491a1722 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 21:31:13 -0500 Subject: add a preliminary mock planner for testing alarms/appointments isolated apart from the EDS backend --- src/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 710db66..073c876 100644 --- a/src/main.c +++ b/src/main.c @@ -26,6 +26,7 @@ #include #include "planner-eds.h" +#include "planner-mock.h" #include "service.h" /*** @@ -52,7 +53,15 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) textdomain (GETTEXT_PACKAGE); /* get the planner */ - planner = indicator_datetime_planner_eds_new (); + if (g_getenv ("INDICATOR_DATETIME_USE_FAKE_PLANNER") != NULL) + { + g_message ("Using fake appointment book for testing"); + planner = indicator_datetime_planner_mock_new (); + } + else + { + planner = indicator_datetime_planner_eds_new (); + } /* run */ service = indicator_datetime_service_new (planner); -- cgit v1.2.3 From a52e3b86ee0dbce56221d1327c6c62a6d8e163e3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 21:33:15 -0500 Subject: preliminary implementation of snap decision --- src/main.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 073c876..34e9b98 100644 --- a/src/main.c +++ b/src/main.c @@ -24,6 +24,7 @@ #include #include +#include #include "planner-eds.h" #include "planner-mock.h" @@ -52,6 +53,11 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); + /* init libnotify */ + if (!notify_init ("indicator-datetime-service")) + g_critical ("libnotify initialization failed"); + + /* get the planner */ if (g_getenv ("INDICATOR_DATETIME_USE_FAKE_PLANNER") != NULL) { -- cgit v1.2.3 From dae4fdd39e5381083345e87759dbaffddabe14e4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 22:55:26 -0500 Subject: more wiring in of mock objects --- src/main.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 34e9b98..45ee180 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,7 @@ #include #include /* exit() */ +#include #include #include @@ -30,6 +31,8 @@ #include "planner-mock.h" #include "service.h" +#define TEST_MODE + /*** **** ***/ @@ -41,6 +44,18 @@ on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop) g_main_loop_quit ((GMainLoop*)loop); } +#ifdef TEST_MODE +static void +log_handler (const gchar * log_domain, + GLogLevelFlags log_level, + const gchar * message, + gpointer fp) +{ + fprintf (fp, "%s %d %s\n", log_domain, (int)log_level, message); + fflush (fp); +} +#endif + int main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) { @@ -57,17 +72,15 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) if (!notify_init ("indicator-datetime-service")) g_critical ("libnotify initialization failed"); - - /* get the planner */ - if (g_getenv ("INDICATOR_DATETIME_USE_FAKE_PLANNER") != NULL) - { - g_message ("Using fake appointment book for testing"); - planner = indicator_datetime_planner_mock_new (); - } - else - { - planner = indicator_datetime_planner_eds_new (); - } + /* set up the planner */ +#ifdef TEST_MODE + g_warning ("Using fake appointment book for testing! Probably shouldn't merge this to trunk."); + FILE * fp = fopen ("/tmp/indicator-datetime-log.txt", "w+"); + g_log_set_handler ("Indicator-Datetime", G_LOG_LEVEL_MASK, log_handler, fp); + planner = indicator_datetime_planner_mock_new (); +#else + planner = indicator_datetime_planner_eds_new (); +#endif /* run */ service = indicator_datetime_service_new (planner); @@ -80,5 +93,8 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) g_main_loop_unref (loop); g_object_unref (service); g_object_unref (planner); +#ifdef TEST_MODE + fclose (fp); +#endif return 0; } -- cgit v1.2.3 From 8dadf00b78312867f33a2f6dcd39118a1beb150c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 16 Oct 2013 14:52:54 -0500 Subject: for testing purposes, fire off a snap decision as soon as the datetime indicator is started. this way one can test on phablet by running as user phablet --- src/main.c | 57 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 17 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 45ee180..c7ad34a 100644 --- a/src/main.c +++ b/src/main.c @@ -31,30 +31,55 @@ #include "planner-mock.h" #include "service.h" -#define TEST_MODE - /*** **** ***/ static void -on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop) +on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop G_GNUC_UNUSED) { g_message ("exiting: service couldn't acquire or lost ownership of busname"); g_main_loop_quit ((GMainLoop*)loop); } -#ifdef TEST_MODE static void -log_handler (const gchar * log_domain, - GLogLevelFlags log_level, - const gchar * message, - gpointer fp) +action_ok (NotifyNotification *notification G_GNUC_UNUSED, + char *action, + gpointer gurl) { - fprintf (fp, "%s %d %s\n", log_domain, (int)log_level, message); - fflush (fp); + const char * url = gurl; + g_message ("'%s' clicked for snap decision; url is '%s'", action, url); +} + +static void +show_snap_decision (void) +{ + const gchar * title = "Title"; + const gchar * body = "Body"; + const gchar * icon_name = "alarm-clock"; + NotifyNotification * nn; + GError * error; + + g_debug ("creating a snap decision with title '%s', body '%s', icon '%s'", + title, body, icon_name); + + nn = notify_notification_new (title, body, icon_name); + notify_notification_set_hint (nn, "x-canonical-snap-decisions", + g_variant_new_boolean(TRUE)); + notify_notification_set_hint (nn, "x-canonical-private-button-tint", + g_variant_new_boolean(TRUE)); + notify_notification_add_action (nn, "action_accept", _("OK"), + action_ok, g_strdup("hello world"), g_free); + + g_message ("showing notification %p", nn); + error = NULL; + notify_notification_show (nn, &error); + if (error != NULL) + { + g_warning ("Unable to show alarm '%s' popup: %s", body, error->message); + g_error_free (error); + } } -#endif int main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) @@ -74,14 +99,15 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) /* set up the planner */ #ifdef TEST_MODE - g_warning ("Using fake appointment book for testing! Probably shouldn't merge this to trunk."); - FILE * fp = fopen ("/tmp/indicator-datetime-log.txt", "w+"); - g_log_set_handler ("Indicator-Datetime", G_LOG_LEVEL_MASK, log_handler, fp); + g_warning ("Using fake appointment book for testing! " + "Probably shouldn't merge this to trunk."); planner = indicator_datetime_planner_mock_new (); #else planner = indicator_datetime_planner_eds_new (); #endif + show_snap_decision (); + /* run */ service = indicator_datetime_service_new (planner); loop = g_main_loop_new (NULL, FALSE); @@ -93,8 +119,5 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) g_main_loop_unref (loop); g_object_unref (service); g_object_unref (planner); -#ifdef TEST_MODE - fclose (fp); -#endif return 0; } -- cgit v1.2.3 From a96e714329ea80e676af5dc5db69ba5b62a25b6e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 16 Oct 2013 16:48:01 -0500 Subject: add a test mode for alarms. --- src/main.c | 78 ++++++++++++++++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 48 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index c7ad34a..3be51eb 100644 --- a/src/main.c +++ b/src/main.c @@ -35,55 +35,28 @@ **** ***/ +/* When enabled, new alarms will show up every minute to test snap decisions */ +static gboolean test_alarms = FALSE; + +static GOptionEntry entries[] = { + { "test-alarms", '\0', 0, G_OPTION_ARG_NONE, &test_alarms, "Test Alarms", NULL }, + { NULL } +}; + static void on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop G_GNUC_UNUSED) { g_message ("exiting: service couldn't acquire or lost ownership of busname"); - g_main_loop_quit ((GMainLoop*)loop); -} -static void -action_ok (NotifyNotification *notification G_GNUC_UNUSED, - char *action, - gpointer gurl) -{ - const char * url = gurl; - g_message ("'%s' clicked for snap decision; url is '%s'", action, url); -} - -static void -show_snap_decision (void) -{ - const gchar * title = "Title"; - const gchar * body = "Body"; - const gchar * icon_name = "alarm-clock"; - NotifyNotification * nn; - GError * error; - - g_debug ("creating a snap decision with title '%s', body '%s', icon '%s'", - title, body, icon_name); - - nn = notify_notification_new (title, body, icon_name); - notify_notification_set_hint (nn, "x-canonical-snap-decisions", - g_variant_new_boolean(TRUE)); - notify_notification_set_hint (nn, "x-canonical-private-button-tint", - g_variant_new_boolean(TRUE)); - notify_notification_add_action (nn, "action_accept", _("OK"), - action_ok, g_strdup("hello world"), g_free); - - g_message ("showing notification %p", nn); - error = NULL; - notify_notification_show (nn, &error); - if (error != NULL) - { - g_warning ("Unable to show alarm '%s' popup: %s", body, error->message); - g_error_free (error); - } + if (!test_alarms) + g_main_loop_quit ((GMainLoop*)loop); } int main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) { + GOptionContext * context; + GError * error; IndicatorDatetimePlanner * planner; IndicatorDatetimeService * service; GMainLoop * loop; @@ -97,16 +70,25 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) if (!notify_init ("indicator-datetime-service")) g_critical ("libnotify initialization failed"); + /* parse command-line options */ + context = g_option_context_new (NULL); + g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + g_print("option parsing failed: %s\n", error->message); + return EXIT_FAILURE; + } + /* set up the planner */ -#ifdef TEST_MODE - g_warning ("Using fake appointment book for testing! " - "Probably shouldn't merge this to trunk."); - planner = indicator_datetime_planner_mock_new (); -#else - planner = indicator_datetime_planner_eds_new (); -#endif - - show_snap_decision (); + if (test_alarms) + { + g_message ("Using fake appointment book for testing alarms."); + planner = indicator_datetime_planner_mock_new (); + } + else + { + planner = indicator_datetime_planner_eds_new (); + } /* run */ service = indicator_datetime_service_new (planner); -- cgit v1.2.3