From bce9f4816e70ec98a415b152a5a9631cf5c4a307 Mon Sep 17 00:00:00 2001 From: Ali Abdallah <ali.slackware@gmail.com> Date: Thu, 2 Apr 2009 13:36:32 +0000 Subject: [PATCH] Added exit option in the context menu+some optimization to function calls in libxfpm common (Old svn revision: 7098) --- ChangeLog | 3 ++ TODO | 2 - libxfpm/xfpm-common.c | 45 ++++++++-------- libxfpm/xfpm-common.h | 13 +++-- libxfpm/xfpm-string.h | 8 ++- po/xfce4-power-manager.pot | 102 +++++++++++++++++++++---------------- src/xfpm-dbus-monitor.c | 20 ++++++-- src/xfpm-dbus-monitor.h | 2 +- src/xfpm-tray-icon.c | 24 +++++++++ 9 files changed, 139 insertions(+), 80 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04392b34..5c423cea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ +2009-04-02 15:36 Ali aliov@xfce.org + * : Added exit option in the context menu+some optimization to function calls in libxfpm common + 2009-04-02 14:14 Ali aliov@xfce.org * : Added on battery DBus signal+Fix brightness settings on battery power diff --git a/TODO b/TODO index a547dd28..60a6a3fc 100644 --- a/TODO +++ b/TODO @@ -9,8 +9,6 @@ * : Support Suspend Hybrid! ( DeviceKit power will not support this ). -* : Probably an exit option in the context menu? - * : Use the session logout when we do shutdown, probably use the shutdown session interface anyway. * : Translations need to be updated. diff --git a/libxfpm/xfpm-common.c b/libxfpm/xfpm-common.c index b2f26fc4..947343ac 100644 --- a/libxfpm/xfpm-common.c +++ b/libxfpm/xfpm-common.c @@ -19,7 +19,6 @@ */ #include <glib.h> -#include <glib/gi18n.h> #include <libxfce4util/libxfce4util.h> @@ -27,18 +26,18 @@ #include "xfpm-string.h" static void -xfpm_link_browser(GtkAboutDialog *about,const gchar *link,gpointer data) +xfpm_link_browser (GtkAboutDialog *about, const gchar *link, gpointer data) { - gchar *cmd = g_strdup_printf("%s %s","xfbrowser4",link); + gchar *cmd = g_strdup_printf ("%s %s","xfbrowser4", link); g_spawn_command_line_async (cmd, NULL); - g_free(cmd); + g_free (cmd); } static void -xfpm_link_mailto(GtkAboutDialog *about,const gchar *link,gpointer data) +xfpm_link_mailto (GtkAboutDialog *about, const gchar *link, gpointer data) { - gchar *cmd = g_strdup_printf("%s %s","xdg-email",link); + gchar *cmd = g_strdup_printf( "%s %s", "xdg-email", link); g_spawn_command_line_async (cmd, NULL); @@ -47,20 +46,20 @@ xfpm_link_mailto(GtkAboutDialog *about,const gchar *link,gpointer data) GdkPixbuf * -xfpm_load_icon(const char *icon_name,gint size) +xfpm_load_icon (const char *icon_name, gint size) { GdkPixbuf *icon; GError *error = NULL; - icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default (), - icon_name, - size, - GTK_ICON_LOOKUP_FORCE_SVG, - &error); + icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + icon_name, + size, + GTK_ICON_LOOKUP_FORCE_SVG, + &error); if ( error ) { - g_warning("Error occured while loading icon %s: %s\n", icon_name, error->message); - g_error_free(error); + g_warning ("Error occured while loading icon %s: %s\n", icon_name, error->message); + g_error_free (error); } return icon; } @@ -68,7 +67,7 @@ xfpm_load_icon(const char *icon_name,gint size) /* * Map of int to strings shutdown values */ -const gchar *xfpm_int_to_shutdown_string (gint val) +const gchar *xfpm_int_to_shutdown_string (gint val) { if ( val == 0 ) return "Nothing"; @@ -82,7 +81,7 @@ const gchar *xfpm_int_to_shutdown_string (gint val) return "Invalid"; } -gint xfpm_shutdown_string_to_int (const gchar *string) +gint xfpm_shutdown_string_to_int (const gchar *string) { if ( xfpm_strequal("Nothing", string) ) return 0; @@ -94,12 +93,10 @@ gint xfpm_shutdown_string_to_int (const gchar *string) return 3; return -1; /* error here */ - - } void -xfpm_lock_screen(void) +xfpm_lock_screen (void) { gboolean ret = g_spawn_command_line_async ("xflock4", NULL); @@ -126,17 +123,23 @@ xfpm_lock_screen(void) } void -xfpm_preferences(void) +xfpm_preferences (void) { g_spawn_command_line_async ("xfce4-power-manager-settings", NULL); } void -xfpm_help(void) +xfpm_help (void) { g_spawn_command_line_async ("xfhelp4 xfce4-power-manager.html", NULL); } +void +xfpm_quit (void) +{ + g_spawn_command_line_async ("xfce4-power-manager -q", NULL); +} + void xfpm_about (GtkWidget *widget, gpointer data) { diff --git a/libxfpm/xfpm-common.h b/libxfpm/xfpm-common.h index ab06dec4..2525c047 100644 --- a/libxfpm/xfpm-common.h +++ b/libxfpm/xfpm-common.h @@ -25,19 +25,26 @@ #include <config.h> #endif +#include <glib.h> #include <gtk/gtk.h> G_BEGIN_DECLS GdkPixbuf* xfpm_load_icon (const gchar *icon_name, - gint size); + gint size) G_GNUC_MALLOC; -const gchar *xfpm_int_to_shutdown_string (gint val); -gint xfpm_shutdown_string_to_int (const gchar *string); +const gchar *xfpm_int_to_shutdown_string (gint val) G_GNUC_PURE; + +gint xfpm_shutdown_string_to_int (const gchar *string) G_GNUC_PURE; void xfpm_lock_screen (void); + void xfpm_preferences (void); + void xfpm_help (void); + +void xfpm_quit (void); + void xfpm_about (GtkWidget *widget, gpointer data); diff --git a/libxfpm/xfpm-string.h b/libxfpm/xfpm-string.h index aa1b20fd..2a7bd201 100644 --- a/libxfpm/xfpm-string.h +++ b/libxfpm/xfpm-string.h @@ -24,14 +24,12 @@ #include <glib.h> #include <string.h> -gint xfpm_strcmp (const gchar *str1, - const gchar *str2); - gboolean xfpm_strequal (const gchar *str1, const gchar *str2); -const gchar *xfpm_bool_to_string (gboolean value); -gboolean xfpm_string_to_bool (const gchar *string); +const gchar *xfpm_bool_to_string (gboolean value) G_GNUC_PURE; + +gboolean xfpm_string_to_bool (const gchar *string) G_GNUC_PURE; #endif /* XFPM_STRING_H */ diff --git a/po/xfce4-power-manager.pot b/po/xfce4-power-manager.pot index 897b1a0d..eede4afa 100644 --- a/po/xfce4-power-manager.pot +++ b/po/xfce4-power-manager.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-03-30 14:57+0200\n" +"POT-Creation-Date: 2009-04-02 15:35+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -108,7 +108,7 @@ msgstr "" #: ../settings/xfpm-settings.glade.h:22 ../settings/xfpm-settings.c:539 #: ../settings/xfpm-settings.c:653 ../settings/xfpm-settings.c:769 #: ../settings/xfpm-settings.c:817 ../src/xfpm-tray-icon.c:194 -#: ../src/xfpm-tray-icon.c:239 +#: ../src/xfpm-tray-icon.c:253 msgid "Suspend" msgstr "" @@ -138,7 +138,7 @@ msgstr "" #: ../settings/xfpm-settings.glade.h:29 ../settings/xfpm-settings-main.c:113 #: ../src/xfpm-main.c:125 ../src/xfpm-main.c:187 ../src/xfpm-main.c:217 -#: ../src/xfpm-tray-icon.c:290 ../src/xfce4-power-manager.desktop.in.h:2 +#: ../src/xfpm-tray-icon.c:304 ../src/xfce4-power-manager.desktop.in.h:2 msgid "Xfce Power Manager" msgstr "" @@ -174,7 +174,7 @@ msgstr "" #: ../settings/xfpm-settings.c:457 ../settings/xfpm-settings.c:545 #: ../settings/xfpm-settings.c:659 ../settings/xfpm-settings.c:775 #: ../settings/xfpm-settings.c:823 ../src/xfpm-tray-icon.c:167 -#: ../src/xfpm-tray-icon.c:224 +#: ../src/xfpm-tray-icon.c:238 msgid "Hibernate" msgstr "" @@ -257,8 +257,8 @@ msgstr "" msgid "Your battery is discharging" msgstr "" -#: ../src/xfpm-battery.c:112 ../src/xfpm-battery.c:369 -#: ../src/xfpm-battery.c:381 +#: ../src/xfpm-battery.c:112 ../src/xfpm-battery.c:372 +#: ../src/xfpm-battery.c:384 msgid "System is running on battery power" msgstr "" @@ -272,7 +272,7 @@ msgstr "" #: ../src/xfpm-battery.c:213 ../src/xfpm-supply.c:277 ../src/xfpm-supply.c:300 #: ../src/xfpm-tray-icon.c:115 ../src/xfpm-tray-icon.c:139 -#: ../src/xfpm-manager.c:215 +#: ../src/xfpm-manager.c:195 msgid "Xfce power manager" msgstr "" @@ -324,43 +324,43 @@ msgstr "" msgid "is almost empty" msgstr "" -#: ../src/xfpm-battery.c:300 +#: ../src/xfpm-battery.c:303 msgid "is not present" msgstr "" -#: ../src/xfpm-battery.c:331 +#: ../src/xfpm-battery.c:334 msgid "Battery not present" msgstr "" -#: ../src/xfpm-battery.c:353 +#: ../src/xfpm-battery.c:356 msgid "Estimated time left" msgstr "" -#: ../src/xfpm-battery.c:357 +#: ../src/xfpm-battery.c:360 msgid "Estimated time to be fully charged" msgstr "" -#: ../src/xfpm-battery.c:360 +#: ../src/xfpm-battery.c:363 msgid "hours" msgstr "" -#: ../src/xfpm-battery.c:360 +#: ../src/xfpm-battery.c:363 msgid "hour" msgstr "" -#: ../src/xfpm-battery.c:361 +#: ../src/xfpm-battery.c:364 msgid "minutes" msgstr "" -#: ../src/xfpm-battery.c:361 +#: ../src/xfpm-battery.c:364 msgid "minute" msgstr "" -#: ../src/xfpm-battery.c:365 ../src/xfpm-battery.c:377 +#: ../src/xfpm-battery.c:368 ../src/xfpm-battery.c:380 msgid "Battery" msgstr "" -#: ../src/xfpm-battery.c:368 ../src/xfpm-battery.c:380 +#: ../src/xfpm-battery.c:371 ../src/xfpm-battery.c:383 msgid "System is running on AC power" msgstr "" @@ -494,26 +494,39 @@ msgid "" "to suspend the system?" msgstr "" -#: ../src/xfpm-engine.c:511 ../src/xfpm-engine.c:540 +#: ../src/xfpm-tray-icon.c:211 +msgid "Exit Xfce power manager" +msgstr "" + +#: ../src/xfpm-tray-icon.c:213 +msgid "Quit" +msgstr "" + +#: ../src/xfpm-engine.c:529 ../src/xfpm-engine.c:558 #, c-format msgid "Permission denied" msgstr "" -#: ../src/xfpm-engine.c:518 +#: ../src/xfpm-engine.c:536 #, c-format msgid "Hibernate not supported" msgstr "" -#: ../src/xfpm-engine.c:547 +#: ../src/xfpm-engine.c:565 #, c-format msgid "Suspend not supported" msgstr "" -#: ../src/xfpm-manager.c:215 +#: ../src/xfpm-manager.c:195 msgid "HAL daemon is not running" msgstr "" -#: ../src/xfpm-inhibit.c:247 +#: ../src/xfpm-inhibit.c:333 +#, c-format +msgid "Invalid arguments" +msgstr "" + +#: ../src/xfpm-inhibit.c:359 #, c-format msgid "Invalid cookie" msgstr "" @@ -584,69 +597,68 @@ msgstr "" msgid "mAh" msgstr "" -#: ../libxfpm/xfpm-common.c:168 +#: ../libxfpm/xfpm-common.c:171 msgid "translator-credits" msgstr "" -#: ../panel-plugins/brightness/brightness-plugin.c:462 -#: ../panel-plugins/brightness/brightness-plugin.c:519 +#: ../panel-plugins/brightness/brightness-plugin.c:460 +#: ../panel-plugins/brightness/brightness-plugin.c:517 msgid "Control your LCD brightness level" msgstr "" -#: ../panel-plugins/brightness/brightness-plugin.c:466 -#: ../panel-plugins/brightness/brightness-plugin.c:523 +#: ../panel-plugins/brightness/brightness-plugin.c:464 +#: ../panel-plugins/brightness/brightness-plugin.c:521 msgid "No device found" msgstr "" -#: ../panel-plugins/brightness/brightness-plugin.c:537 +#: ../panel-plugins/brightness/brightness-plugin.c:535 #: ../panel-plugins/brightness/xfce4-brightness-plugin.desktop.in.in.h:1 msgid "Brightness plugin" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:205 -#: ../panel-plugins/inhibit/inhibit-plugin.c:429 -#: ../panel-plugins/inhibit/inhibit-plugin.c:437 +#: ../panel-plugins/inhibit/inhibit-plugin.c:221 +#: ../panel-plugins/inhibit/inhibit-plugin.c:445 msgid "No power manager instance running" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:208 +#: ../panel-plugins/inhibit/inhibit-plugin.c:224 msgid "Automatic sleep inhibited" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:214 +#: ../panel-plugins/inhibit/inhibit-plugin.c:230 msgid "Another application is disabling the automatic sleep" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:216 +#: ../panel-plugins/inhibit/inhibit-plugin.c:232 msgid "Automatic sleep enabled" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:288 +#: ../panel-plugins/inhibit/inhibit-plugin.c:304 msgid "Power manager automatic sleep is disabled" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:289 +#: ../panel-plugins/inhibit/inhibit-plugin.c:305 msgid "Power manager automatic sleep is enabled" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:292 -#: ../panel-plugins/inhibit/inhibit-plugin.c:328 -#: ../panel-plugins/inhibit/inhibit-plugin.c:515 -#: ../panel-plugins/inhibit/inhibit-plugin.c:617 +#: ../panel-plugins/inhibit/inhibit-plugin.c:308 +#: ../panel-plugins/inhibit/inhibit-plugin.c:344 +#: ../panel-plugins/inhibit/inhibit-plugin.c:523 +#: ../panel-plugins/inhibit/inhibit-plugin.c:625 #: ../panel-plugins/inhibit/xfce4-inhibit-plugin.desktop.in.in.h:1 msgid "Inhibit plugin" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:302 -#: ../panel-plugins/inhibit/inhibit-plugin.c:338 -#: ../panel-plugins/inhibit/inhibit-plugin.c:525 +#: ../panel-plugins/inhibit/inhibit-plugin.c:318 +#: ../panel-plugins/inhibit/inhibit-plugin.c:354 +#: ../panel-plugins/inhibit/inhibit-plugin.c:533 msgid "Don't show again" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:329 +#: ../panel-plugins/inhibit/inhibit-plugin.c:345 msgid "Power manager disconnected" msgstr "" -#: ../panel-plugins/inhibit/inhibit-plugin.c:516 +#: ../panel-plugins/inhibit/inhibit-plugin.c:524 msgid "Power manager is connected" msgstr "" diff --git a/src/xfpm-dbus-monitor.c b/src/xfpm-dbus-monitor.c index 5a575ba7..f49f2db7 100644 --- a/src/xfpm-dbus-monitor.c +++ b/src/xfpm-dbus-monitor.c @@ -175,12 +175,26 @@ xfpm_dbus_monitor_new (void) return XFPM_DBUS_MONITOR (xfpm_dbus_monitor_object); } -void xfpm_dbus_monitor_add_match (XfpmDBusMonitor *monitor, const gchar *unique_name) +gboolean xfpm_dbus_monitor_add_match (XfpmDBusMonitor *monitor, const gchar *unique_name) { - g_return_if_fail (XFPM_IS_DBUS_MONITOR (monitor) ); - g_return_if_fail (unique_name != NULL); + int i = 0; + gchar *name; + + g_return_val_if_fail (XFPM_IS_DBUS_MONITOR (monitor), FALSE); + g_return_val_if_fail (unique_name != NULL, FALSE); + + for ( i = 0; i<monitor->priv->array->len; i++) + { + name = g_ptr_array_index (monitor->priv->array, i); + if ( g_strcmp0 (name, unique_name) == 0 ) + { + return FALSE; + } + } g_ptr_array_add (monitor->priv->array, g_strdup (unique_name)); + + return TRUE; } gboolean xfpm_dbus_monitor_remove_match (XfpmDBusMonitor *monitor, const gchar *unique_name) diff --git a/src/xfpm-dbus-monitor.h b/src/xfpm-dbus-monitor.h index 378370a3..b2c1a84e 100644 --- a/src/xfpm-dbus-monitor.h +++ b/src/xfpm-dbus-monitor.h @@ -49,7 +49,7 @@ typedef struct GType xfpm_dbus_monitor_get_type (void) G_GNUC_CONST; XfpmDBusMonitor *xfpm_dbus_monitor_new (void); -void xfpm_dbus_monitor_add_match (XfpmDBusMonitor *monitor, +gboolean xfpm_dbus_monitor_add_match (XfpmDBusMonitor *monitor, const gchar *unique_name); gboolean xfpm_dbus_monitor_remove_match (XfpmDBusMonitor *monitor, diff --git a/src/xfpm-tray-icon.c b/src/xfpm-tray-icon.c index cc30bada..5656139b 100644 --- a/src/xfpm-tray-icon.c +++ b/src/xfpm-tray-icon.c @@ -203,6 +203,20 @@ xfpm_tray_icon_suspend_cb (GtkWidget *w, XfpmTrayIcon *tray) } } +static void +xfpm_tray_icon_exit_activated_cb (GtkWidget *w, gpointer data) +{ + gboolean ret; + + ret = xfce_confirm (_("Exit Xfce power manager"), + GTK_STOCK_YES, + _("Quit")); + if ( ret ) + { + xfpm_quit (); + } +} + static void xfpm_tray_icon_popup_menu_cb (GtkStatusIcon *icon, guint button, guint activate_time, XfpmTrayIcon *tray) @@ -298,6 +312,16 @@ xfpm_tray_icon_popup_menu_cb (GtkStatusIcon *icon, guint button, gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi); + mi = gtk_separator_menu_item_new (); + gtk_widget_show (mi); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); + + mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT, NULL); + gtk_widget_set_sensitive (mi, TRUE); + gtk_widget_show (mi); + g_signal_connect (mi, "activate", G_CALLBACK (xfpm_tray_icon_exit_activated_cb), NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); + // Popup the menu gtk_menu_popup(GTK_MENU(menu), NULL, NULL, gtk_status_icon_position_menu, -- GitLab