[gnac/devel] Added helper functions
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Added helper functions
- Date: Sat, 26 Nov 2011 11:33:54 +0000 (UTC)
commit 948b9c1f74a3b364c1a94f8d933fc8a5c99f8cdb
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Fri Nov 25 23:32:37 2011 +0000
Added helper functions
src/gnac-bars.c | 35 +++++-----------
src/gnac-prefs.c | 12 +----
src/gnac-properties.c | 4 +-
src/gnac-ui-utils.c | 69 ++++++++++++++++++++++++++++++-
src/gnac-ui-utils.h | 28 ++++++++++++
src/gnac-ui.c | 64 +++++++++++++++++-----------
src/gnac-ui.h | 18 ++++++++-
src/profiles/gnac-profiles-manager.c | 7 +--
src/profiles/gnac-profiles-properties.c | 3 +-
src/profiles/gnac-profiles-utils.c | 7 +---
10 files changed, 172 insertions(+), 75 deletions(-)
---
diff --git a/src/gnac-bars.c b/src/gnac-bars.c
index 78b1362..b857fba 100644
--- a/src/gnac-bars.c
+++ b/src/gnac-bars.c
@@ -179,76 +179,63 @@ gnac_bars_on_plugin_installed(void)
void
gnac_bars_activate_add(gboolean activate)
{
- GtkAction *action = gnac_ui_get_action("add_item");
- gtk_action_set_sensitive(action, activate);
+ gnac_ui_set_action_sensitive("add_item", activate);
}
void
gnac_bars_activate_clear(gboolean activate)
{
- GtkAction *action = gnac_ui_get_action("clear_item");
- gtk_action_set_sensitive(action, activate);
+ gnac_ui_set_action_sensitive("clear_item", activate);
}
void
gnac_bars_activate_convert(gboolean activate)
{
- GtkAction *action = gnac_ui_get_action("convert_item");
- gtk_action_set_sensitive(action, activate);
-
- GtkWidget *widget = gnac_ui_get_widget("convert_button");
- gtk_widget_set_sensitive(widget, activate);
+ gnac_ui_set_action_sensitive("convert_item", activate);
+ gnac_ui_set_widget_sensitive("convert_button", activate);
}
void
gnac_bars_activate_file_list(gboolean activate)
{
- GtkWidget *file_list = gnac_ui_get_widget("file_list");
- gtk_widget_set_sensitive(file_list, activate);
+ gnac_ui_set_widget_sensitive("file_list", activate);
}
void
gnac_bars_activate_pause(gboolean activate)
{
- GtkAction *action = gnac_ui_get_action("pause_item");
- gtk_action_set_visible(action, activate);
-
- GtkWidget *widget = gnac_ui_get_widget("pause_button");
- gtk_widget_set_sensitive(widget, activate);
+ gnac_ui_set_action_visible("pause_item", activate);
+ gnac_ui_set_widget_sensitive("pause_button", activate);
}
void
gnac_bars_activate_preferences(gboolean activate)
{
- GtkAction *action = gnac_ui_get_action("prefs_item");
- gtk_action_set_sensitive(action, activate);
+ gnac_ui_set_action_sensitive("prefs_item", activate);
}
void
gnac_bars_activate_properties(gboolean activate)
{
- GtkAction *action = gnac_ui_get_action("properties_item");
- gtk_action_set_sensitive(action, activate);
+ gnac_ui_set_action_sensitive("properties_item", activate);
}
void
gnac_bars_activate_quit(gboolean activate)
{
- GtkAction *action = gnac_ui_get_action("quit_item");
- gtk_action_set_sensitive(action, activate);
+ gnac_ui_set_action_sensitive("quit_item", activate);
}
void
gnac_bars_activate_remove(gboolean activate)
{
- GtkAction *action = gnac_ui_get_action("remove_item");
- gtk_action_set_sensitive(action, activate);
+ gnac_ui_set_action_sensitive("remove_item", activate);
}
diff --git a/src/gnac-prefs.c b/src/gnac-prefs.c
index 06eb10c..1b20f87 100644
--- a/src/gnac-prefs.c
+++ b/src/gnac-prefs.c
@@ -108,17 +108,10 @@ gnac_prefs_free_tooltip_patterns(void)
}
-static GObject *
-gnac_prefs_get_object(const gchar *object_name)
-{
- return gtk_builder_get_object(gnac_prefs_builder, object_name);
-}
-
-
static GtkWidget *
gnac_prefs_get_widget(const gchar *widget_name)
{
- return GTK_WIDGET(gnac_prefs_get_object(widget_name));
+ return gnac_ui_utils_get_widget(gnac_prefs_builder, widget_name);
}
@@ -143,8 +136,7 @@ static void
gnac_prefs_set_widget_sensitive(const gchar *widget_name,
gboolean sensitive)
{
- GtkWidget *widget = gnac_prefs_get_widget(widget_name);
- gtk_widget_set_sensitive(widget, sensitive);
+ gnac_ui_utils_set_widget_sensitive(gnac_prefs_builder, widget_name, sensitive);
}
diff --git a/src/gnac-properties.c b/src/gnac-properties.c
index 954ea91..25f4f4c 100644
--- a/src/gnac-properties.c
+++ b/src/gnac-properties.c
@@ -140,14 +140,14 @@ gnac_properties_reset_spin_if_empty(const gchar *name);
static GObject *
gnac_properties_get_object(const gchar *object_name)
{
- return gtk_builder_get_object(gnac_properties_builder, object_name);
+ return gnac_ui_utils_get_object(gnac_properties_builder, object_name);
}
static GtkWidget *
gnac_properties_get_widget(const gchar *widget_name)
{
- return GTK_WIDGET(gnac_properties_get_object(widget_name));
+ return gnac_ui_utils_get_widget(gnac_properties_builder, widget_name);
}
diff --git a/src/gnac-ui-utils.c b/src/gnac-ui-utils.c
index a2c7e4e..97674bc 100644
--- a/src/gnac-ui-utils.c
+++ b/src/gnac-ui-utils.c
@@ -31,6 +31,7 @@
#include <glib/gi18n.h>
#include "gnac-ui-utils.h"
+#include "libgnac-debug.h"
#define GNAC_UTILS_ICON_BORDER_WIDTH 1
@@ -184,9 +185,75 @@ gnac_ui_utils_create_gtk_builder(const gchar *filename)
}
+GObject *
+gnac_ui_utils_get_object(GtkBuilder *builder,
+ const gchar *object_name)
+{
+ GObject *object = gtk_builder_get_object(builder, object_name);
+ if (!object) {
+ libgnac_debug("Object %s not found\n", object_name);
+ }
+
+ return object;
+}
+
+
GtkWidget *
gnac_ui_utils_get_widget(GtkBuilder *builder,
const gchar *widget_name)
{
- return GTK_WIDGET(gtk_builder_get_object(builder, widget_name));
+ GObject *object = gnac_ui_utils_get_object(builder, widget_name);
+ if (!object) return NULL;
+
+ return GTK_WIDGET(object);
+}
+
+GtkAction *
+gnac_ui_utils_get_action(GtkBuilder *builder,
+ const gchar *action_name)
+{
+ GObject *object = gnac_ui_utils_get_object(builder, action_name);
+ if (!object) return NULL;
+
+ return GTK_ACTION(object);
+}
+
+
+void
+gnac_ui_utils_set_action_sensitive(GtkBuilder *builder,
+ const gchar *action_name,
+ gboolean activate)
+{
+ GtkAction *action = gnac_ui_utils_get_action(builder, action_name);
+ if (action) gtk_action_set_sensitive(action, activate);
+}
+
+
+void
+gnac_ui_utils_set_action_visible(GtkBuilder *builder,
+ const gchar *action_name,
+ gboolean visible)
+{
+ GtkAction *action = gnac_ui_utils_get_action(builder, action_name);
+ if (action) gtk_action_set_visible(action, visible);
+}
+
+
+void
+gnac_ui_utils_set_widget_sensitive(GtkBuilder *builder,
+ const gchar *widget_name,
+ gboolean activate)
+{
+ GtkWidget *widget = gnac_ui_utils_get_widget(builder, widget_name);
+ if (widget) gtk_widget_set_sensitive(widget, activate);
+}
+
+
+void
+gnac_ui_utils_set_widget_visible(GtkBuilder *builder,
+ const gchar *widget_name,
+ gboolean visible)
+{
+ GtkAction *widget = gnac_ui_utils_get_action(builder, widget_name);
+ if (widget) gtk_action_set_visible(widget, visible);
}
diff --git a/src/gnac-ui-utils.h b/src/gnac-ui-utils.h
index 90ba85c..e2dd0bf 100644
--- a/src/gnac-ui-utils.h
+++ b/src/gnac-ui-utils.h
@@ -70,10 +70,38 @@ gnac_ui_utils_event_is_return_key(GdkEventKey *event);
GtkBuilder *
gnac_ui_utils_create_gtk_builder(const gchar *filename);
+GObject *
+gnac_ui_utils_get_object(GtkBuilder *builder,
+ const gchar *object_name);
+
GtkWidget *
gnac_ui_utils_get_widget(GtkBuilder *builder,
const gchar *widget_name);
+GtkAction *
+gnac_ui_utils_get_action(GtkBuilder *builder,
+ const gchar *action_name);
+
+void
+gnac_ui_utils_set_action_sensitive(GtkBuilder *builder,
+ const gchar *action_name,
+ gboolean activate);
+
+void
+gnac_ui_utils_set_action_visible(GtkBuilder *builder,
+ const gchar *action_name,
+ gboolean visible);
+
+void
+gnac_ui_utils_set_widget_sensitive(GtkBuilder *builder,
+ const gchar *widget_name,
+ gboolean activate);
+
+void
+gnac_ui_utils_set_widget_visible(GtkBuilder *builder,
+ const gchar *widget_name,
+ gboolean visible);
+
G_END_DECLS
#endif /* GNAC_UI_UTILS_H */
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index 200fe95..900d78b 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -420,14 +420,11 @@ gnac_ui_show_toolbar(void)
{
gboolean visible;
GtkToggleAction *view_toolbar;
- GtkWidget *toolbar;
- /* update toolbar's status */
view_toolbar = GTK_TOGGLE_ACTION(gnac_ui_get_action("view_toolbar_item"));
visible = g_settings_get_boolean(settings_ui, GNAC_KEY_TOOLBAR_VISIBLE);
gtk_toggle_action_set_active(view_toolbar, visible);
- toolbar = gnac_ui_get_widget("main_toolbar");
- gtk_widget_set_visible(toolbar, visible);
+ gnac_ui_set_widget_visible("main_toolbar", visible);
}
@@ -788,24 +785,49 @@ gnac_about_url_hook(GtkAboutDialog *dialog,
}
-static GObject *
-gnac_ui_get_object(const gchar *object_name)
-{
- return gtk_builder_get_object(gnac_main_builder, object_name);
-}
-
-
GtkWidget *
gnac_ui_get_widget(const gchar *widget_name)
{
- return GTK_WIDGET(gnac_ui_get_object(widget_name));
+ return gnac_ui_utils_get_widget(gnac_main_builder, widget_name);
}
GtkAction *
gnac_ui_get_action(const gchar *action_name)
{
- return GTK_ACTION(gnac_ui_get_object(action_name));
+ return gnac_ui_utils_get_action(gnac_main_builder, action_name);
+}
+
+
+void
+gnac_ui_set_action_sensitive(const gchar *action_name,
+ gboolean activate)
+{
+ gnac_ui_utils_set_action_sensitive(gnac_main_builder, action_name, activate);
+}
+
+
+void
+gnac_ui_set_action_visible(const gchar *action_name,
+ gboolean visible)
+{
+ gnac_ui_utils_set_action_visible(gnac_main_builder, action_name, visible);
+}
+
+
+void
+gnac_ui_set_widget_sensitive(const gchar *widget_name,
+ gboolean activate)
+{
+ gnac_ui_utils_set_widget_sensitive(gnac_main_builder, widget_name, activate);
+}
+
+
+void
+gnac_ui_set_widget_visible(const gchar *widget_name,
+ gboolean visible)
+{
+ gnac_ui_utils_set_widget_sensitive(gnac_main_builder, widget_name, visible);
}
@@ -1388,13 +1410,9 @@ gnac_ui_trayicon_tooltip_update(const gchar *tooltip)
void
gnac_ui_trayicon_menu_activate(gboolean activate)
{
- GtkAction *action;
- action = gnac_ui_get_action("tray_pause_item");
- gtk_action_set_sensitive(action, activate);
- action = gnac_ui_get_action("tray_stop_item");
- gtk_action_set_sensitive(action, activate);
- action = gnac_ui_get_action("tray_quit_item");
- gtk_action_set_sensitive(action, activate);
+ gnac_ui_set_action_sensitive("tray_pause_item", activate);
+ gnac_ui_set_action_sensitive("tray_stop_item", activate);
+ gnac_ui_set_action_sensitive("tray_quit_item", activate);
}
@@ -1424,15 +1442,11 @@ gnac_ui_trayicon_menu_pause(gpointer data,
gnac_on_ui_pause_cb(NULL, NULL);
}
-/* Error dialogs */
gint
gnac_ui_show_error_trash(const gchar *filename)
{
- gint response;
-
GtkWidget *main_window = gnac_ui_get_widget("main_window");
-
GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
_("Failed to move the file to the Trash. Delete it permanently?"));
@@ -1440,7 +1454,7 @@ gnac_ui_show_error_trash(const gchar *filename)
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
_("Cannot move file %s to the Trash"), filename);
- response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gint response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
return response;
diff --git a/src/gnac-ui.h b/src/gnac-ui.h
index 9f3c74f..c4027ef 100644
--- a/src/gnac-ui.h
+++ b/src/gnac-ui.h
@@ -117,7 +117,23 @@ GtkWidget *
gnac_ui_get_widget(const gchar *widget_name);
GtkAction *
-gnac_ui_get_action(const gchar *widget_name);
+gnac_ui_get_action(const gchar *action_name);
+
+void
+gnac_ui_set_action_sensitive(const gchar *action_name,
+ gboolean activate);
+
+void
+gnac_ui_set_action_visible(const gchar *action_name,
+ gboolean visible);
+
+void
+gnac_ui_set_widget_sensitive(const gchar *widget_name,
+ gboolean activate);
+
+void
+gnac_ui_set_widget_visible(const gchar *widget_name,
+ gboolean visible);
void
gnac_ui_on_audio_empty_state(void);
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index c3ac215..2cb44b8 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -143,14 +143,14 @@ gnac_profiles_mgr_on_treeselection_changed(void);
static GObject *
gnac_profiles_mgr_get_object(const gchar *object_name)
{
- return gtk_builder_get_object(profiles_mgr_builder, object_name);
+ return gnac_ui_utils_get_object(profiles_mgr_builder, object_name);
}
static GtkWidget *
gnac_profiles_mgr_get_widget(const gchar *widget_name)
{
- return GTK_WIDGET(gnac_profiles_mgr_get_object(widget_name));
+ return gnac_ui_utils_get_widget(profiles_mgr_builder, widget_name);
}
@@ -158,8 +158,7 @@ static void
gnac_profiles_mgr_set_widget_sensitive(const gchar *widget_name,
gboolean sensitive)
{
- GtkWidget *widget = gnac_profiles_mgr_get_widget(widget_name);
- gtk_widget_set_sensitive(widget, sensitive);
+ gnac_ui_utils_set_widget_sensitive(profiles_mgr_builder, widget_name, sensitive);
}
diff --git a/src/profiles/gnac-profiles-properties.c b/src/profiles/gnac-profiles-properties.c
index df062ec..30e16dc 100644
--- a/src/profiles/gnac-profiles-properties.c
+++ b/src/profiles/gnac-profiles-properties.c
@@ -121,8 +121,7 @@ gnac_profiles_properties_reinit(void);
static GtkWidget *
gnac_profiles_properties_get_widget(const gchar *widget_name)
{
- return GTK_WIDGET(gtk_builder_get_object(profiles_properties_builder,
- widget_name));
+ return gnac_ui_utils_get_widget(profiles_properties_builder, widget_name);
}
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index f666723..42cfd68 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -1092,12 +1092,7 @@ GtkWidget *
gnac_profiles_utils_get_widget(BasicFormatInfo *bfi,
const gchar *widget_name)
{
- GObject *object = gtk_builder_get_object(bfi->builder, widget_name);
- if (!object) {
- libgnac_debug("Widget %s not found\n", widget_name);
- return NULL;
- }
- return GTK_WIDGET(object);
+ return gnac_ui_utils_get_widget(bfi->builder, widget_name);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]