From fe6148723172d93d97fa941184ecc9a256201379 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 May 2010 22:07:22 -0500 Subject: Building the basic service structure --- src/datetime-service.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 63590c7..da4cd87 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -1,7 +1,40 @@ +#include +#include + +#include + +#include "dbus-shared.h" + +static IndicatorService * service = NULL; +static GMainLoop * mainloop = NULL; + +static void +service_shutdown (IndicatorService * service, gpointer user_data) +{ + g_warning("Shutting down service!"); + g_main_loop_quit(mainloop); + return; +} + int main (int argc, char ** argv) { + g_type_init(); + + service = indicator_service_new_version(SERVICE_NAME, SERVICE_VERSION); + g_signal_connect(service, INDICATOR_SERVICE_SIGNAL_SHUTDOWN, G_CALLBACK(service_shutdown), NULL); + + /* Setting up i18n and gettext. Apparently, we need + all of these. */ + setlocale (LC_ALL, ""); + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + textdomain (GETTEXT_PACKAGE); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_object_unref(G_OBJECT(service)); return 0; } -- cgit v1.2.3 From e66edab185ed5f916dc15628956d89f87ab10b44 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 May 2010 12:41:30 -0500 Subject: Now we have a menu, whoo ha! --- src/datetime-service.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index da4cd87..d2e2b3e 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -4,10 +4,22 @@ #include +#include +#include + #include "dbus-shared.h" static IndicatorService * service = NULL; static GMainLoop * mainloop = NULL; +static DbusmenuServer * server = NULL; +static DbusmenuMenuitem * root = NULL; + +static void +build_menus (DbusmenuMenuitem * root) +{ + + return; +} static void service_shutdown (IndicatorService * service, gpointer user_data) @@ -22,6 +34,7 @@ main (int argc, char ** argv) { g_type_init(); + /* Acknowledging the service init and setting up the interface */ service = indicator_service_new_version(SERVICE_NAME, SERVICE_VERSION); g_signal_connect(service, INDICATOR_SERVICE_SIGNAL_SHUTDOWN, G_CALLBACK(service_shutdown), NULL); @@ -31,10 +44,18 @@ main (int argc, char ** argv) bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); + /* Building the base menu */ + server = dbusmenu_server_new(MENU_OBJ); + root = dbusmenu_menuitem_new(); + dbusmenu_server_set_root(server, root); + build_menus(root); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); g_object_unref(G_OBJECT(service)); + g_object_unref(G_OBJECT(server)); + g_object_unref(G_OBJECT(root)); return 0; } -- cgit v1.2.3 From 33799d8b1d8417218688a7d2599c24bc14e04e4c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 May 2010 12:42:48 -0500 Subject: Comments --- src/datetime-service.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index d2e2b3e..ee29a7a 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -14,6 +14,9 @@ static GMainLoop * mainloop = NULL; static DbusmenuServer * server = NULL; static DbusmenuMenuitem * root = NULL; +/* Does the work to build the default menu, really calls out + to other functions but this is the core to clean up the + main function. */ static void build_menus (DbusmenuMenuitem * root) { @@ -21,6 +24,8 @@ build_menus (DbusmenuMenuitem * root) return; } +/* Repsonds to the service object saying it's time to shutdown. + It stops the mainloop. */ static void service_shutdown (IndicatorService * service, gpointer user_data) { @@ -29,6 +34,7 @@ service_shutdown (IndicatorService * service, gpointer user_data) return; } +/* Function to build everything up. Entry point from asm. */ int main (int argc, char ** argv) { -- cgit v1.2.3 From cfef5b08bd7812d6f97854f157ab0227a9cdfd03 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Jul 2010 16:24:17 -0500 Subject: Make date and time menu items. --- src/datetime-service.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index ee29a7a..99a24f5 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -14,12 +14,32 @@ static GMainLoop * mainloop = NULL; static DbusmenuServer * server = NULL; static DbusmenuMenuitem * root = NULL; +/* Items */ +static DbusmenuMenuitem * date = NULL; +static DbusmenuMenuitem * calendar = NULL; + /* Does the work to build the default menu, really calls out to other functions but this is the core to clean up the main function. */ static void build_menus (DbusmenuMenuitem * root) { + if (date == NULL) { + date = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (date, DBUSMENU_MENUITEM_PROP_LABEL, _("No date yet...")); + dbusmenu_menuitem_property_set_bool(date, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + dbusmenu_menuitem_child_append(root, date); + //update_label(self); + } + + if (calendar == NULL) { + calendar = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (calendar, DBUSMENU_MENUITEM_PROP_LABEL, _("Open Calendar")); + /* insensitive until we check for available apps */ + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + dbusmenu_menuitem_child_append(root, calendar); + // queue checking for apps + } return; } -- cgit v1.2.3 From 4a8b1c170bde2526aea845e628894e1cceaa92d5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Jul 2010 16:36:46 -0500 Subject: Making the separator and the settings item. --- src/datetime-service.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 99a24f5..9154db5 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -5,6 +5,7 @@ #include #include +#include #include #include "dbus-shared.h" @@ -41,6 +42,17 @@ build_menus (DbusmenuMenuitem * root) // queue checking for apps } + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append(root, separator); + + DbusmenuMenuitem * settings = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (settings, DBUSMENU_MENUITEM_PROP_LABEL, _("Set Time and Date...")); + /* insensitive until we check for available apps */ + dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + //g_signal_connect(G_OBJECT(settings), DBUSMENU_MENUITEM_SIGNAL_ACTIVATE, G_CALLBACK(activate_cb), "time-admin"); + dbusmenu_menuitem_child_append(root, settings); + return; } -- cgit v1.2.3 From 515a3e5f9068e5eb06765c47ba90e2857a22c264 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Jul 2010 16:44:55 -0500 Subject: Activating the settings --- src/datetime-service.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 9154db5..ad64417 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -15,10 +15,22 @@ static GMainLoop * mainloop = NULL; static DbusmenuServer * server = NULL; static DbusmenuMenuitem * root = NULL; -/* Items */ +/* Global Items */ static DbusmenuMenuitem * date = NULL; static DbusmenuMenuitem * calendar = NULL; +/* Run a particular program based on an activation */ +static void +activate_cb (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) +{ + GError * error = NULL; + + if (!g_spawn_command_line_async(command, &error)) { + g_warning("Unable to start %s: %s", (char *)command, error->message); + g_error_free(error); + } +} + /* Does the work to build the default menu, really calls out to other functions but this is the core to clean up the main function. */ @@ -50,7 +62,7 @@ build_menus (DbusmenuMenuitem * root) dbusmenu_menuitem_property_set (settings, DBUSMENU_MENUITEM_PROP_LABEL, _("Set Time and Date...")); /* insensitive until we check for available apps */ dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); - //g_signal_connect(G_OBJECT(settings), DBUSMENU_MENUITEM_SIGNAL_ACTIVATE, G_CALLBACK(activate_cb), "time-admin"); + g_signal_connect(G_OBJECT(settings), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "time-admin"); dbusmenu_menuitem_child_append(root, settings); return; -- cgit v1.2.3 From 03e448f0dfaf9c3a268b1b089563b7fd65252b09 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 14:57:25 -0500 Subject: Adding in a check for the calendar application. --- src/datetime-service.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index ad64417..6cbaf93 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -31,6 +31,25 @@ activate_cb (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) } } +/* Looks for the calendar application and enables the item if + we have one */ +static gboolean +check_for_calendar (gpointer user_data) +{ + g_return_val_if_fail (calendar != NULL, FALSE); + + gchar *evo = g_find_program_in_path("evolution"); + if (evo != NULL) { + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + g_free(evo); + } else { + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } + + return FALSE; +} + /* Does the work to build the default menu, really calls out to other functions but this is the core to clean up the main function. */ @@ -50,8 +69,11 @@ build_menus (DbusmenuMenuitem * root) dbusmenu_menuitem_property_set (calendar, DBUSMENU_MENUITEM_PROP_LABEL, _("Open Calendar")); /* insensitive until we check for available apps */ dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + g_signal_connect (G_OBJECT(calendar), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_cb), "evolution -c calendar"); dbusmenu_menuitem_child_append(root, calendar); - // queue checking for apps + + g_idle_add(check_for_calendar, NULL); } DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); -- cgit v1.2.3 From 4edb23e4a529f287cec6bbc18153b2e65df11f32 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 14:59:59 -0500 Subject: Adding some good debugging messages. --- src/datetime-service.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 6cbaf93..06b64c1 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -25,6 +25,7 @@ activate_cb (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) { GError * error = NULL; + g_debug("Issuing command '%s'", command); if (!g_spawn_command_line_async(command, &error)) { g_warning("Unable to start %s: %s", (char *)command, error->message); g_error_free(error); @@ -40,10 +41,12 @@ check_for_calendar (gpointer user_data) gchar *evo = g_find_program_in_path("evolution"); if (evo != NULL) { + g_debug("Found the calendar application: %s", evo); dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); g_free(evo); } else { + g_debug("Unable to find calendar app."); dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } @@ -56,6 +59,7 @@ check_for_calendar (gpointer user_data) static void build_menus (DbusmenuMenuitem * root) { + g_debug("Building Menus."); if (date == NULL) { date = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (date, DBUSMENU_MENUITEM_PROP_LABEL, _("No date yet...")); -- cgit v1.2.3 From 4117028fe68956d4c8b1db460a908a5779410421 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 15:09:39 -0500 Subject: Setting up the update of the label for the date. --- src/datetime-service.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 06b64c1..37e5af4 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -19,6 +19,34 @@ static DbusmenuMenuitem * root = NULL; static DbusmenuMenuitem * date = NULL; static DbusmenuMenuitem * calendar = NULL; +/* Updates the label in the date menuitem */ +static gboolean +update_datetime (gpointer user_data) +{ + g_debug("Updating Date/Time"); + + gchar longstr[128]; + time_t t; + struct tm *ltime; + + t = time(NULL); + ltime = localtime(&t); + if (ltime == NULL) { + g_warning("Error getting local time"); + dbusmenu_menuitem_property_set(date, DBUSMENU_MENUITEM_PROP_LABEL, _("Error getting time")); + return FALSE; + } + + /* Note: may require some localization tweaks */ + strftime(longstr, 128, "%A, %e %B %Y", ltime); + + gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL); + dbusmenu_menuitem_property_set(date, DBUSMENU_MENUITEM_PROP_LABEL, utf8); + g_free(utf8); + + return FALSE; +} + /* Run a particular program based on an activation */ static void activate_cb (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) @@ -65,7 +93,9 @@ build_menus (DbusmenuMenuitem * root) dbusmenu_menuitem_property_set (date, DBUSMENU_MENUITEM_PROP_LABEL, _("No date yet...")); dbusmenu_menuitem_property_set_bool(date, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); dbusmenu_menuitem_child_append(root, date); - //update_label(self); + + g_idle_add(update_datetime, NULL); + /* TODO: Set up updating daily */ } if (calendar == NULL) { -- cgit v1.2.3 From 16a8df4b6d59fe642984ccae311f424017c8c0bc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 15:28:16 -0500 Subject: Setting up checking for time-admin as well. --- src/datetime-service.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 37e5af4..a701453 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -18,6 +18,7 @@ static DbusmenuMenuitem * root = NULL; /* Global Items */ static DbusmenuMenuitem * date = NULL; static DbusmenuMenuitem * calendar = NULL; +static DbusmenuMenuitem * settings = NULL; /* Updates the label in the date menuitem */ static gboolean @@ -81,6 +82,26 @@ check_for_calendar (gpointer user_data) return FALSE; } +/* Looks for the time and date admin application and enables the + item we have one */ +static gboolean +check_for_timeadmin (gpointer user_data) +{ + g_return_val_if_fail (settings != NULL, FALSE); + + gchar * timeadmin = g_find_program_in_path("time-admin"); + if (timeadmin != NULL) { + g_debug("Found the time-admin application: %s", timeadmin); + dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + g_free(timeadmin); + } else { + g_debug("Unable to find time-admin app."); + dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + } + + return FALSE; +} + /* Does the work to build the default menu, really calls out to other functions but this is the core to clean up the main function. */ @@ -114,12 +135,13 @@ build_menus (DbusmenuMenuitem * root) dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); - DbusmenuMenuitem * settings = dbusmenu_menuitem_new(); + settings = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (settings, DBUSMENU_MENUITEM_PROP_LABEL, _("Set Time and Date...")); /* insensitive until we check for available apps */ dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); g_signal_connect(G_OBJECT(settings), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "time-admin"); dbusmenu_menuitem_child_append(root, settings); + g_idle_add(check_for_timeadmin, NULL); return; } -- cgit v1.2.3 From df30f437fd80697d97544fafa43999a05debefb0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 15:34:19 -0500 Subject: Legal stuffs --- src/datetime-service.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index a701453..56d024e 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -1,3 +1,23 @@ +/* +An indicator to show date and time information. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ #include #include -- cgit v1.2.3