]> git.llucax.com Git - software/sadba.git/blobdiff - src/lib-display-blanking-status-menu-widget.c
Add (empty) upgrade description to package info
[software/sadba.git] / src / lib-display-blanking-status-menu-widget.c
index a3fbb2c1b46b72e9f258f85c2f52026894569393..fc02eb2123aae7fd08010a31c1f11ca6c107f4b1 100644 (file)
@@ -76,6 +76,9 @@ GType display_blanking_status_plugin_get_type (void);
 #define MODE_GCONF_ROOT "/system/osso/dsm/display"
 #define MODE_GCONF_KEY  MODE_GCONF_ROOT "/inhibit_blank_mode"
 
 #define MODE_GCONF_ROOT "/system/osso/dsm/display"
 #define MODE_GCONF_KEY  MODE_GCONF_ROOT "/inhibit_blank_mode"
 
+#define HOURS_GCONF_KEY   "/apps/Maemo/sadba/timed_inhibit_hours"
+#define MINUTES_GCONF_KEY "/apps/Maemo/sadba/timed_inhibit_minutes"
+
 #define INHIBIT_MSG_INTERVAL 30 // in seconds
 
 #define GETTEXT_DOM "status-area-displayblanking-applet"
 #define INHIBIT_MSG_INTERVAL 30 // in seconds
 
 #define GETTEXT_DOM "status-area-displayblanking-applet"
@@ -102,9 +105,11 @@ static const char *mode_icon_name[BLANKING_MODES] =
 };
 #define INHIBIT_ICON_NAME       "display-blanking-inhibit-icon"
 #define TIMED_INHIBIT_ICON_NAME "display-blanking-inhibit-icon.timed"
 };
 #define INHIBIT_ICON_NAME       "display-blanking-inhibit-icon"
 #define TIMED_INHIBIT_ICON_NAME "display-blanking-inhibit-icon.timed"
+#define INHIBIT_STATUS_ICON_NAME "display-blanking-status"
 
 struct _DisplayBlankingStatusPluginPrivate
 {
 
 struct _DisplayBlankingStatusPluginPrivate
 {
+    DisplayBlankingStatusPlugin* plugin;
     GConfClient *gconf_client;
     DBusConnection* dbus_conn;
     DBusMessage* dbus_msg;
     GConfClient *gconf_client;
     DBusConnection* dbus_conn;
     DBusMessage* dbus_msg;
@@ -155,6 +160,14 @@ disable_timer (gint *timer_id)
     *timer_id = 0;
 }
 
     *timer_id = 0;
 }
 
+static void
+disable_inhibition (DisplayBlankingStatusPluginPrivate *priv)
+{
+    disable_timer (&(priv->inhibit_timer_id));
+    hd_status_plugin_item_set_status_area_icon (
+            HD_STATUS_PLUGIN_ITEM (priv->plugin), NULL);
+}
+
 static gboolean
 on_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
 {
 static gboolean
 on_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
 {
@@ -168,7 +181,7 @@ on_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
 static gboolean
 on_timed_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
 {
 static gboolean
 on_timed_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
 {
-    disable_timer (&(priv->inhibit_timer_id));
+    disable_inhibition (priv);
     disable_timer (&(priv->timed_inhibit_timer_id));
 
     priv->inhibit_in_signal = TRUE;
     disable_timer (&(priv->timed_inhibit_timer_id));
 
     priv->inhibit_in_signal = TRUE;
@@ -185,12 +198,18 @@ on_timed_inhibit_timeout (DisplayBlankingStatusPluginPrivate *priv)
 }
 
 static void
 }
 
 static void
-enable_inhibit_timer (DisplayBlankingStatusPluginPrivate *priv)
+enable_inhibition (DisplayBlankingStatusPluginPrivate *priv)
 {
     g_assert (priv->inhibit_timer_id == 0);
     priv->inhibit_timer_id = g_timeout_add_seconds (INHIBIT_MSG_INTERVAL,
             (GSourceFunc) on_inhibit_timeout, priv);
     g_assert (priv->inhibit_timer_id > 0);
 {
     g_assert (priv->inhibit_timer_id == 0);
     priv->inhibit_timer_id = g_timeout_add_seconds (INHIBIT_MSG_INTERVAL,
             (GSourceFunc) on_inhibit_timeout, priv);
     g_assert (priv->inhibit_timer_id > 0);
+
+    GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
+    GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (icon_theme,
+            INHIBIT_STATUS_ICON_NAME, 18, GTK_ICON_LOOKUP_NO_SVG, NULL);
+    hd_status_plugin_item_set_status_area_icon (
+            HD_STATUS_PLUGIN_ITEM (priv->plugin), pixbuf);
 }
 
 static void
 }
 
 static void
@@ -221,29 +240,33 @@ on_inhibit_button_clicked (GtkWidget *button,
     else if (self_pressed && !other_pressed) {
         g_assert (priv->timed_inhibit_timer_id == 0);
 
     else if (self_pressed && !other_pressed) {
         g_assert (priv->timed_inhibit_timer_id == 0);
 
-        enable_inhibit_timer (priv);
+        enable_inhibition (priv);
     }
     else if (!self_pressed) {
         g_assert (!other_pressed);
         g_assert (priv->timed_inhibit_timer_id == 0);
 
     }
     else if (!self_pressed) {
         g_assert (!other_pressed);
         g_assert (priv->timed_inhibit_timer_id == 0);
 
-        disable_timer (&(priv->inhibit_timer_id));
+        disable_inhibition (priv);
     }
     else
         g_assert (FALSE);
 }
 
 static GtkWidget *
     }
     else
         g_assert (FALSE);
 }
 
 static GtkWidget *
-timed_inhibit_picker_new (const gchar* title, gsize selected, guint max,
+timed_inhibit_picker_new (const gchar* title, gsize current, guint max,
         guint step)
 {
     g_assert (max < 100);
     static gchar buffer[3]; // 2 for the number + 1 for \0
 
     GtkWidget *selector = hildon_touch_selector_entry_new_text ();
         guint step)
 {
     g_assert (max < 100);
     static gchar buffer[3]; // 2 for the number + 1 for \0
 
     GtkWidget *selector = hildon_touch_selector_entry_new_text ();
-    for (int i = 0; i <= max; i += step)
+    gint selected = -1;
+    for (int i = 0; i*step <= max; i++) {
+        if (i*step == current)
+            selected = i;
         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
-                g_ascii_formatd (buffer, 3, "%.0f", i));
+                g_ascii_formatd (buffer, 3, "%.0f", i*step));
+    }
     hildon_gtk_entry_set_input_mode (GTK_ENTRY (
                 hildon_touch_selector_entry_get_entry (
                     HILDON_TOUCH_SELECTOR_ENTRY (selector))),
     hildon_gtk_entry_set_input_mode (GTK_ENTRY (
                 hildon_touch_selector_entry_get_entry (
                     HILDON_TOUCH_SELECTOR_ENTRY (selector))),
@@ -254,7 +277,10 @@ timed_inhibit_picker_new (const gchar* title, gsize selected, guint max,
     hildon_button_set_title (HILDON_BUTTON (picker), title);
     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker),
             HILDON_TOUCH_SELECTOR (selector));
     hildon_button_set_title (HILDON_BUTTON (picker), title);
     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker),
             HILDON_TOUCH_SELECTOR (selector));
-    hildon_picker_button_set_active (HILDON_PICKER_BUTTON (picker), selected);
+    hildon_picker_button_set_active (HILDON_PICKER_BUTTON (picker),
+            selected);
+    hildon_button_set_value (HILDON_BUTTON (picker),
+                g_ascii_formatd (buffer, 3, "%.0f", current));
 
     g_object_set_data (G_OBJECT (picker), "max", GUINT_TO_POINTER (max));
 
 
     g_object_set_data (G_OBJECT (picker), "max", GUINT_TO_POINTER (max));
 
@@ -280,9 +306,13 @@ timed_inhibit_get_input (DisplayBlankingStatusPluginPrivate *priv)
             GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
 
     GtkWidget *h_picker = timed_inhibit_picker_new (
             GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
 
     GtkWidget *h_picker = timed_inhibit_picker_new (
-            dgettext (GETTEXT_DOM, "Hours"), 1, 24, 1);
+            dgettext (GETTEXT_DOM, "Hours"),
+            gconf_client_get_int (priv->gconf_client, HOURS_GCONF_KEY, NULL),
+            24, 1);
     GtkWidget *m_picker = timed_inhibit_picker_new (
     GtkWidget *m_picker = timed_inhibit_picker_new (
-            dgettext (GETTEXT_DOM, "Minutes"), 0, 60, 10);
+            dgettext (GETTEXT_DOM, "Minutes"),
+            gconf_client_get_int (priv->gconf_client, MINUTES_GCONF_KEY, NULL),
+            60, 10);
 
     GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
     g_assert (hbox != NULL);
 
     GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
     g_assert (hbox != NULL);
@@ -299,9 +329,18 @@ timed_inhibit_get_input (DisplayBlankingStatusPluginPrivate *priv)
     gint result = gtk_dialog_run (GTK_DIALOG (priv->timed_inhibit_dialog));
 
     guint timeout = 0;
     gint result = gtk_dialog_run (GTK_DIALOG (priv->timed_inhibit_dialog));
 
     guint timeout = 0;
-    if (result == GTK_RESPONSE_ACCEPT)
-        timeout = timed_inhibit_picker_get_value (h_picker) * 3600 +
-            timed_inhibit_picker_get_value (m_picker) * 60;
+    if (result == GTK_RESPONSE_ACCEPT) {
+        gint hours = timed_inhibit_picker_get_value (h_picker);
+        gint mins = timed_inhibit_picker_get_value (m_picker);
+
+        GError *e = NULL;
+        gconf_client_set_int (priv->gconf_client, HOURS_GCONF_KEY, hours, &e);
+        g_assert (e == NULL);
+        gconf_client_set_int (priv->gconf_client, MINUTES_GCONF_KEY, mins, &e);
+        g_assert (e == NULL);
+
+        timeout = hours*3600 + mins*60;
+    }
 
     gtk_widget_destroy (priv->timed_inhibit_dialog);
     priv->timed_inhibit_dialog = NULL;
 
     gtk_widget_destroy (priv->timed_inhibit_dialog);
     priv->timed_inhibit_dialog = NULL;
@@ -339,7 +378,7 @@ on_timed_inhibit_button_clicked (GtkWidget *button,
                 priv->inhibit_in_signal = FALSE;
             }
             else
                 priv->inhibit_in_signal = FALSE;
             }
             else
-                enable_inhibit_timer (priv);
+                enable_inhibition (priv);
 
             priv->timed_inhibit_timer_id = g_timeout_add_seconds (timeout,
                     (GSourceFunc) on_timed_inhibit_timeout, priv);
 
             priv->timed_inhibit_timer_id = g_timeout_add_seconds (timeout,
                     (GSourceFunc) on_timed_inhibit_timeout, priv);
@@ -355,7 +394,7 @@ on_timed_inhibit_button_clicked (GtkWidget *button,
     else { // !self_pressed
         g_assert (!other_pressed);
 
     else { // !self_pressed
         g_assert (!other_pressed);
 
-        disable_timer (&(priv->inhibit_timer_id));
+        disable_inhibition (priv);
         disable_timer (&(priv->timed_inhibit_timer_id));
     }
 }
         disable_timer (&(priv->timed_inhibit_timer_id));
     }
 }
@@ -555,6 +594,7 @@ display_blanking_status_plugin_init (DisplayBlankingStatusPlugin *plugin)
 
     priv = DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE (plugin);
     plugin->priv = priv;
 
     priv = DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE (plugin);
     plugin->priv = priv;
+    priv->plugin = plugin;
 
     init_gconf (priv);
     init_dbus (priv);
 
     init_gconf (priv);
     init_dbus (priv);