[Xfce4-commits] r24236 - xfce4-panel/trunk/libxfce4panel

Nick Schermer nick at xfce.org
Mon Jan 1 20:51:30 CET 2007


Author: nick
Date: 2007-01-01 19:51:30 +0000 (Mon, 01 Jan 2007)
New Revision: 24236

Modified:
   xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.c
   xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.h
Log:
* Add gtk dialog that popups up on the right screen.
* Fix memory leaks in libxfce4panel. g_object_get returns new
  data, not a pointer.


Modified: xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.c
===================================================================
--- xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.c	2007-01-01 19:22:10 UTC (rev 24235)
+++ xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.c	2007-01-01 19:51:30 UTC (rev 24236)
@@ -25,7 +25,6 @@
 
 #include <string.h>
 #include <gtk/gtk.h>
-#include <libxfcegui4/dialogs.h>
 
 #include "xfce-panel-convenience.h"
 #include "xfce-panel-plugin-iface.h"
@@ -431,10 +430,10 @@
  * 
  * Returns: the plugin name.
  **/
-G_CONST_RETURN char *
+gchar *
 xfce_panel_plugin_get_name (XfcePanelPlugin *plugin)
 {
-    const char *name = NULL;
+    gchar *name = NULL;
     
     g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), NULL);
 
@@ -452,10 +451,10 @@
  *
  * Returns: the plugin id.
  **/
-G_CONST_RETURN char *
+gchar *
 xfce_panel_plugin_get_id (XfcePanelPlugin *plugin)
 {
-    const char *id = NULL;
+    gchar *id = NULL;
     
     g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), NULL);
 
@@ -473,10 +472,10 @@
  *
  * Returns: the display name of @plugin.
  **/
-G_CONST_RETURN char *
+gchar *
 xfce_panel_plugin_get_display_name (XfcePanelPlugin *plugin)
 {
-    const char *name = NULL;
+    gchar *name = NULL;
     
     g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), NULL);
 
@@ -572,23 +571,34 @@
 void
 xfce_panel_plugin_remove_confirm (XfcePanelPlugin *plugin)
 {
-    int response = GTK_RESPONSE_NONE;
-    char *first;
+    GtkWidget *dialog;
+    gint       response;
+    gchar     *name;
+
+    name = xfce_panel_plugin_get_display_name (plugin);
+
+    dialog = gtk_message_dialog_new (NULL,
+                                     GTK_DIALOG_MODAL,
+                                     GTK_MESSAGE_QUESTION,
+                                     GTK_BUTTONS_YES_NO,
+                                     _("Remove \"%s\"?"), name);
+
+    g_free (name);
     
-    first = g_strdup_printf (_("Remove \"%s\"?"), 
-                             xfce_panel_plugin_get_display_name (plugin));
-    
-    response = xfce_message_dialog (NULL, _("Xfce Panel"), 
-                                    GTK_STOCK_DIALOG_QUESTION, first, 
-                                    _("The item will be removed from "
-                                      "the panel and its configuration "
-                                      "will be lost."),
-                                    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                                    GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT,
-                                    NULL);
-    g_free (first);
-                                    
-    if (response == GTK_RESPONSE_ACCEPT)
+    gtk_window_set_screen (GTK_WINDOW (dialog),
+                           gtk_widget_get_screen (GTK_WIDGET (plugin)));
+
+    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+
+    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                              _("The item will be removed from "
+                                                "the panel and its configuration "
+                                                "will be lost."));
+
+    response = gtk_dialog_run (GTK_DIALOG (dialog));
+    gtk_widget_destroy (dialog);
+
+    if (G_LIKELY (response == GTK_RESPONSE_YES))
         xfce_panel_plugin_remove (plugin);
 }
 
@@ -745,7 +755,9 @@
     int insert_position;
     int configure_position;
     gboolean allow_customization;
+    gchar *name;
     
+    
     g_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
 
     allow_customization = xfce_allow_panel_customization ();
@@ -755,8 +767,9 @@
     menu = gtk_menu_new ();
 
     /* title */
-    mi = gtk_menu_item_new_with_label (
-            xfce_panel_plugin_get_display_name (plugin));
+    name = xfce_panel_plugin_get_display_name (plugin);
+    mi = gtk_menu_item_new_with_label (name);
+    g_free (name);
     gtk_widget_set_sensitive (mi, FALSE);
     gtk_widget_show (mi);
     gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
@@ -1112,13 +1125,19 @@
 xfce_panel_plugin_lookup_rc_file (XfcePanelPlugin *plugin)
 {
     char path[255];
+    gchar *name, *id;
+    
+    name = xfce_panel_plugin_get_name (plugin);
+    id = xfce_panel_plugin_get_id (plugin);
 
     g_snprintf (path, 255, 
                 "xfce4" G_DIR_SEPARATOR_S
                 "panel" G_DIR_SEPARATOR_S 
                 "%s-%s.rc", 
-                xfce_panel_plugin_get_name (plugin), 
-                xfce_panel_plugin_get_id (plugin));
+                name, id);
+                
+    g_free (name);
+    g_free (id);
 
     return xfce_resource_lookup (XFCE_RESOURCE_CONFIG, path);
 }
@@ -1140,13 +1159,19 @@
 xfce_panel_plugin_save_location (XfcePanelPlugin *plugin, gboolean create)
 {
     char path[255];
+    gchar *name, *id;
+    
+    name = xfce_panel_plugin_get_name (plugin);
+    id = xfce_panel_plugin_get_id (plugin);
 
     g_snprintf (path, 255, 
                 "xfce4" G_DIR_SEPARATOR_S
                 "panel" G_DIR_SEPARATOR_S 
                 "%s-%s.rc", 
-                xfce_panel_plugin_get_name (plugin), 
-                xfce_panel_plugin_get_id (plugin));
+                name, id);
+                
+    g_free (name);
+    g_free (id);
 
     return xfce_resource_save_location (XFCE_RESOURCE_CONFIG, path, create);
 }

Modified: xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.h
===================================================================
--- xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.h	2007-01-01 19:22:10 UTC (rev 24235)
+++ xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.h	2007-01-01 19:51:30 UTC (rev 24236)
@@ -72,11 +72,11 @@
 
 /* properties */
 
-G_CONST_RETURN char *xfce_panel_plugin_get_name (XfcePanelPlugin *plugin);
+gchar *xfce_panel_plugin_get_name (XfcePanelPlugin *plugin);
 
-G_CONST_RETURN char *xfce_panel_plugin_get_id (XfcePanelPlugin *plugin);
+gchar *xfce_panel_plugin_get_id (XfcePanelPlugin *plugin);
 
-G_CONST_RETURN char * xfce_panel_plugin_get_display_name (XfcePanelPlugin *plugin);
+gchar * xfce_panel_plugin_get_display_name (XfcePanelPlugin *plugin);
 
 int xfce_panel_plugin_get_size (XfcePanelPlugin *plugin);
 



More information about the Xfce4-commits mailing list