[Xfce4-commits] <xfce4-panel:master> Cleanup atk set function handling a bit.

Nick Schermer noreply at xfce.org
Sat Feb 12 17:32:01 CET 2011


Updating branch refs/heads/master
         to e632fe399491128e85b3b68d83e8e56ed28ad60e (commit)
       from e020399f0484e03dabca0a0409bc3a1d26a8ba69 (commit)

commit e632fe399491128e85b3b68d83e8e56ed28ad60e
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Feb 9 18:52:11 2011 +0100

    Cleanup atk set function handling a bit.

 common/panel-utils.c                  |   34 +++++++++++++++++++++++++++++++++
 common/panel-utils.h                  |    4 +++
 plugins/actions/actions.c             |   16 ++++----------
 plugins/directorymenu/directorymenu.c |    8 +------
 plugins/launcher/launcher.c           |   22 ++++----------------
 plugins/showdesktop/Makefile.am       |    4 ++-
 plugins/showdesktop/showdesktop.c     |   10 +-------
 7 files changed, 54 insertions(+), 44 deletions(-)

diff --git a/common/panel-utils.c b/common/panel-utils.c
index 817615c..dbb99d9 100644
--- a/common/panel-utils.c
+++ b/common/panel-utils.c
@@ -225,3 +225,37 @@ panel_utils_grab_available (void)
 
   return grab_succeed;
 }
+
+
+
+void
+panel_utils_set_atk_info (GtkWidget   *widget,
+                          const gchar *name,
+                          const gchar *description)
+{
+  static gboolean  initialized = FALSE;
+  static gboolean  atk_enabled = TRUE;
+  AtkObject       *object;
+
+  panel_return_if_fail (GTK_IS_WIDGET (widget));
+
+  if (atk_enabled)
+    {
+      object = gtk_widget_get_accessible (widget);
+
+      if (!initialized)
+        {
+          initialized = TRUE;
+          atk_enabled = GTK_IS_ACCESSIBLE (object);
+
+          if (!atk_enabled)
+            return;
+        }
+
+      if (name != NULL)
+        atk_object_set_name (object, name);
+
+      if (description != NULL)
+        atk_object_set_description (object, description);
+    }
+}
diff --git a/common/panel-utils.h b/common/panel-utils.h
index 56e598f..70cbd3d 100644
--- a/common/panel-utils.h
+++ b/common/panel-utils.h
@@ -38,4 +38,8 @@ void        panel_utils_show_help      (GtkWindow        *parent,
 
 gboolean    panel_utils_grab_available (void);
 
+void        panel_utils_set_atk_info   (GtkWidget        *widget,
+                                        const gchar      *name,
+                                        const gchar      *description);
+
 #endif /* !__PANEL_BUILDER_H__ */
diff --git a/plugins/actions/actions.c b/plugins/actions/actions.c
index f905851..4657fd7 100644
--- a/plugins/actions/actions.c
+++ b/plugins/actions/actions.c
@@ -164,7 +164,6 @@ actions_plugin_init (ActionsPlugin *plugin)
 {
   GtkWidget   *widget;
   ActionEntry *entry = &action_entries[ACTION_LOG_OUT_DIALOG];
-  AtkObject   *atkobj;
 
   plugin->first_action = ACTION_LOG_OUT_DIALOG;
   plugin->second_action = ACTION_DISABLED;
@@ -181,9 +180,7 @@ actions_plugin_init (ActionsPlugin *plugin)
   xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (plugin), widget);
   gtk_widget_show (widget);
 
-  atkobj = gtk_widget_get_accessible (widget);
-  if (atkobj != NULL)
-    atk_object_set_name (atkobj, _(entry->title));
+  panel_utils_set_atk_info (widget, _(entry->title), NULL);
 
   plugin->first_image = xfce_panel_image_new_from_source (entry->icon_name);
   gtk_container_add (GTK_CONTAINER (widget), plugin->first_image);
@@ -237,7 +234,6 @@ actions_plugin_set_property (GObject      *object,
 {
   ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (object);
   ActionType     action;
-  AtkObject     *atkobj;
 
   switch (prop_id)
     {
@@ -250,9 +246,8 @@ actions_plugin_set_property (GObject      *object,
           XFCE_PANEL_IMAGE (plugin->first_image),
           action_entries[action].icon_name);
 
-      atkobj = gtk_widget_get_accessible (plugin->first_button);
-      if (atkobj != NULL)
-        atk_object_set_name (atkobj, _(action_entries[action].title));
+      panel_utils_set_atk_info (plugin->first_button,
+          _(action_entries[action].title), NULL);
       break;
 
     case PROP_SECOND_ACTION:
@@ -273,9 +268,8 @@ actions_plugin_set_property (GObject      *object,
               XFCE_PANEL_IMAGE (plugin->second_image),
               action_entries[action].icon_name);
 
-          atkobj = gtk_widget_get_accessible (plugin->second_button);
-          if (atkobj != NULL)
-            atk_object_set_name (atkobj, _(action_entries[action].title));
+          panel_utils_set_atk_info (plugin->second_button,
+              _(action_entries[action].title), NULL);
         }
 
       /* update plugin size */
diff --git a/plugins/directorymenu/directorymenu.c b/plugins/directorymenu/directorymenu.c
index 229a340..effa5f0 100644
--- a/plugins/directorymenu/directorymenu.c
+++ b/plugins/directorymenu/directorymenu.c
@@ -226,7 +226,6 @@ directory_menu_plugin_set_property (GObject      *object,
   guint                 i;
   GFile                *base_directory;
   const gchar          *path;
-  AtkObject            *atkobj;
 
   switch (prop_id)
     {
@@ -244,12 +243,7 @@ directory_menu_plugin_set_property (GObject      *object,
       display_name = g_file_get_parse_name (plugin->base_directory);
       gtk_widget_set_tooltip_text (plugin->button, display_name);
 
-      atkobj = gtk_widget_get_accessible (plugin->button);
-      if (atkobj != NULL)
-        {
-          atk_object_set_name (atkobj, _("Directory Menu"));
-          atk_object_set_description (atkobj, display_name);
-        }
+      panel_utils_set_atk_info (plugin->button, _("Directory Menu"), display_name);
 
       g_free (display_name);
       break;
diff --git a/plugins/launcher/launcher.c b/plugins/launcher/launcher.c
index 272b5a7..226d63a 100644
--- a/plugins/launcher/launcher.c
+++ b/plugins/launcher/launcher.c
@@ -34,6 +34,7 @@
 #include <libxfce4panel/libxfce4panel.h>
 #include <common/panel-private.h>
 #include <common/panel-xfconf.h>
+#include <common/panel-utils.h>
 
 #include "launcher.h"
 #include "launcher-dialog.h"
@@ -341,7 +342,6 @@ static void
 launcher_plugin_init (LauncherPlugin *plugin)
 {
   GtkIconTheme *icon_theme;
-  AtkObject    *atkobj;
 
   plugin->disable_tooltips = FALSE;
   plugin->move_first = FALSE;
@@ -402,9 +402,7 @@ launcher_plugin_init (LauncherPlugin *plugin)
   g_signal_connect (G_OBJECT (plugin->arrow), "drag-leave",
       G_CALLBACK (launcher_plugin_arrow_drag_leave), plugin);
 
-  atkobj = gtk_widget_get_accessible (plugin->arrow);
-  if (atkobj != NULL)
-    atk_object_set_name (atkobj, _("Open launcher menu"));
+  panel_utils_set_atk_info (plugin->arrow, _("Open launcher menu"), NULL);
 
   /* accept all sorts of drag data, but filter in drag-drop, so we can
    * send other sorts of drops to parent widgets */
@@ -1678,8 +1676,6 @@ launcher_plugin_button_update (LauncherPlugin *plugin)
 {
   GarconMenuItem *item = NULL;
   const gchar    *icon_name;
-  AtkObject      *atkobj;
-  const gchar    *text;
 
   panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
 
@@ -1708,17 +1704,9 @@ launcher_plugin_button_update (LauncherPlugin *plugin)
       xfce_panel_image_set_from_source (XFCE_PANEL_IMAGE (plugin->child),
           exo_str_is_empty (icon_name) ? GTK_STOCK_MISSING_IMAGE : icon_name);
 
-      atkobj = gtk_widget_get_accessible (plugin->button);
-      if (atkobj != NULL)
-        {
-          text = garcon_menu_item_get_name (item);
-          if (text != NULL)
-            atk_object_set_name (atkobj, text);
-
-          text = garcon_menu_item_get_comment (item);
-          if (text != NULL)
-            atk_object_set_description (atkobj, text);
-        }
+      panel_utils_set_atk_info (plugin->button,
+          garcon_menu_item_get_name (item),
+          garcon_menu_item_get_comment (item));
     }
   else
     {
diff --git a/plugins/showdesktop/Makefile.am b/plugins/showdesktop/Makefile.am
index c166d47..37c6f74 100644
--- a/plugins/showdesktop/Makefile.am
+++ b/plugins/showdesktop/Makefile.am
@@ -29,12 +29,14 @@ libshowdesktop_la_LDFLAGS = \
 
 libshowdesktop_la_LIBADD = \
 	$(top_builddir)/libxfce4panel/libxfce4panel-$(LIBXFCE4PANEL_VERSION_API).la \
+	$(top_builddir)/common/libpanel-common.la \
 	$(GTK_LIBS) \
 	$(LIBXFCE4UTIL_LIBS) \
 	$(LIBWNCK_LIBS)
 
 libshowdesktop_la_DEPENDENCIES = \
-	$(top_builddir)/libxfce4panel/libxfce4panel-$(LIBXFCE4PANEL_VERSION_API).la
+	$(top_builddir)/libxfce4panel/libxfce4panel-$(LIBXFCE4PANEL_VERSION_API).la \
+	$(top_builddir)/common/libpanel-common.la
 
 #
 # .desktop file
diff --git a/plugins/showdesktop/showdesktop.c b/plugins/showdesktop/showdesktop.c
index 2d663af..704691e 100644
--- a/plugins/showdesktop/showdesktop.c
+++ b/plugins/showdesktop/showdesktop.c
@@ -23,6 +23,7 @@
 
 #include <libxfce4util/libxfce4util.h>
 #include <common/panel-private.h>
+#include <common/panel-utils.h>
 
 #include "showdesktop.h"
 
@@ -178,7 +179,6 @@ show_desktop_plugin_toggled (GtkToggleButton   *button,
                              ShowDesktopPlugin *plugin)
 {
   gboolean     active;
-  AtkObject   *atkobj;
   const gchar *text;
 
   panel_return_if_fail (XFCE_IS_SHOW_DESKTOP_PLUGIN (plugin));
@@ -196,13 +196,7 @@ show_desktop_plugin_toggled (GtkToggleButton   *button,
     text = _("Minimize all open windows and show the desktop");
 
   gtk_widget_set_tooltip_text (GTK_WIDGET (button), text);
-
-  atkobj = gtk_widget_get_accessible (GTK_WIDGET (button));
-  if (atkobj != NULL)
-    {
-      atk_object_set_name (atkobj, _("Show Desktop"));
-      atk_object_set_description (atkobj, text);
-    }
+  panel_utils_set_atk_info (GTK_WIDGET (button), _("Show Desktop"), text);
 }
 
 



More information about the Xfce4-commits mailing list