[gnac/devel] Added gnac-ui-utils.[ch]



commit 4ea93e2e43217bb0fb61c7d2268699cf8061fdb0
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Fri Nov 18 11:49:06 2011 +0000

    Added gnac-ui-utils.[ch]

 po/POTFILES.in                               |    1 +
 src/Makefile.am                              |    2 +
 src/gnac-file-list.c                         |    5 +-
 src/gnac-prefs.c                             |   14 +-
 src/gnac-properties.c                        |    7 +-
 src/gnac-ui-utils.c                          |  192 ++++++++++++++++++++++++++
 src/gnac-ui-utils.h                          |   79 +++++++++++
 src/gnac-ui.c                                |    9 +-
 src/gnac-utils.c                             |  178 +-----------------------
 src/gnac-utils.h                             |   46 +------
 src/profiles/formats/gnac-profiles-unknown.c |    3 +-
 src/profiles/gnac-profiles-default.c         |    4 +-
 src/profiles/gnac-profiles-manager.c         |    7 +-
 src/profiles/gnac-profiles-properties.c      |    7 +-
 src/profiles/gnac-profiles-utils.c           |    5 +-
 15 files changed, 313 insertions(+), 246 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b71da13..c581eab 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -46,6 +46,7 @@ src/gnac-prefs.c
 src/gnac-properties.c
 src/gnac-stock-items.c
 src/gnac-ui.c
+src/gnac-ui-utils.c
 src/gnac-utils.c
 src/profiles/formats/gnac-profiles-unknown.c
 src/profiles/gnac-profiles.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 2214cfd..2db3761 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,6 +21,8 @@ gnac_SOURCES = \
 	gnac-stock-items.c \
 	gnac-ui.h \
 	gnac-ui.c \
+	gnac-ui-utils.h \
+	gnac-ui-utils.c \
 	gnac-utils.h \
 	gnac-utils.c \
 	profiles/gnac-profiles.h \
diff --git a/src/gnac-file-list.c b/src/gnac-file-list.c
index d84fc3f..1c6cbf9 100644
--- a/src/gnac-file-list.c
+++ b/src/gnac-file-list.c
@@ -30,6 +30,7 @@
 #include "gnac-main.h"
 #include "gnac-properties.h"
 #include "gnac-ui.h"
+#include "gnac-ui-utils.h"
 #include "gnac-utils.h"
 
 #include "libgnac-debug.h"
@@ -518,12 +519,12 @@ gnac_file_list_on_button_pressed(GtkWidget      *treeview,
   row_exists = gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview),
       (gint) event->x, (gint) event->y, &path, NULL, NULL, NULL);
 
-  if (gnac_utils_event_is_double_left_click(event) && !row_exists)
+  if (gnac_ui_utils_event_is_double_left_click(event) && !row_exists)
   {
     gnac_ui_on_add_cb(NULL, NULL);
     ret = TRUE;
   }
-  else if (gnac_utils_event_is_single_right_click(event))
+  else if (gnac_ui_utils_event_is_single_right_click(event))
   {
     if (row_exists && gnac_file_list_count_selected_rows() <= 1)
     {
diff --git a/src/gnac-prefs.c b/src/gnac-prefs.c
index e62faaa..80e9c00 100644
--- a/src/gnac-prefs.c
+++ b/src/gnac-prefs.c
@@ -34,6 +34,7 @@
 #include "gnac-prefs.h"
 #include "gnac-properties.h"
 #include "gnac-ui.h"
+#include "gnac-ui-utils.h"
 #include "gnac-utils.h"
 #include "libgnac-debug.h"
 #include "libgnac-output.h"
@@ -77,8 +78,7 @@ gnac_prefs_select_custom_pattern(GtkComboBox *combo_box);
 static gchar *
 gnac_prefs_get_tooltip_patterns(void)
 {
-  if (!tooltip_patterns)
-  {
+  if (!tooltip_patterns) {
     /* Translators: patterns refers to rename patterns, e.g., %a -> artist */
     tooltip_patterns = g_strconcat(_("Patterns available:"),
         "\n  <b>\%a:</b> ", _("Artist"),
@@ -179,6 +179,7 @@ gnac_prefs_set_toggle_button_active(const gchar *button_name,
   gtk_toggle_button_set_active(button, is_active);
 }
 
+
 static void 
 gnac_prefs_set_same_mode(void)
 {
@@ -270,7 +271,8 @@ gnac_prefs_window_new(void)
   GtkWidget *check_button;
   GtkWidget *prefs_window;
 
-  gnac_prefs_builder = gnac_utils_create_gtk_builder(PKGDATADIR "/gnac-pref-window.xml");
+  gnac_prefs_builder = gnac_ui_utils_create_gtk_builder(
+      PKGDATADIR "/gnac-pref-window.xml");
 
   prefs_window = gnac_prefs_get_widget("gnac_preference_window");
   /* Set the parent */
@@ -466,7 +468,7 @@ gnac_prefs_button_press_event_cb(GtkWidget      *widget,
   GtkWidget *child;
   GType      widget_type;
 
-  if (!gnac_utils_event_is_left_click(event)) return FALSE;
+  if (!gnac_ui_utils_event_is_left_click(event)) return FALSE;
 
   child = gtk_bin_get_child(GTK_BIN(user_data));
   widget_type = G_OBJECT_TYPE(widget);
@@ -492,7 +494,7 @@ static gboolean
 gnac_prefs_custom_pattern_is_selected(GtkComboBox *combo_box,
                                       gint         selected_index)
 {
-  gint size = gnac_utils_get_combo_size(combo_box);
+  gint size = gnac_ui_utils_get_combo_size(combo_box);
   return (selected_index == size-1);
 }
 
@@ -500,7 +502,7 @@ gnac_prefs_custom_pattern_is_selected(GtkComboBox *combo_box,
 static void
 gnac_prefs_select_custom_pattern(GtkComboBox *combo_box)
 {
-  gint size = gnac_utils_get_combo_size(combo_box);
+  gint size = gnac_ui_utils_get_combo_size(combo_box);
   gtk_combo_box_set_active(combo_box, size-1);
 }
 
diff --git a/src/gnac-properties.c b/src/gnac-properties.c
index 0351f84..8e4e1e5 100644
--- a/src/gnac-properties.c
+++ b/src/gnac-properties.c
@@ -33,6 +33,7 @@
 #include "gnac-main.h"
 #include "gnac-properties.h"
 #include "gnac-ui.h"
+#include "gnac-ui-utils.h"
 #include "gnac-utils.h"
 
 #include "libgnac-debug.h"
@@ -314,8 +315,8 @@ gnac_properties_set_image(GtkWidget    *widget,
                           const GValue *value)
 {
   GdkPixbuf *pixbuf = g_value_get_object(value);
-  pixbuf = gnac_utils_scale_pixbuf(pixbuf, 96, 96);
-  pixbuf = gnac_utils_add_border_to_pixbuf(pixbuf);
+  pixbuf = gnac_ui_utils_scale_pixbuf(pixbuf, 96, 96);
+  pixbuf = gnac_ui_utils_add_border_to_pixbuf(pixbuf);
   gtk_image_set_from_pixbuf(GTK_IMAGE(widget), pixbuf);
 }
 
@@ -482,7 +483,7 @@ gnac_properties_window_new(void)
 {
   GtkWidget *properties_window;
 
-  gnac_properties_builder = gnac_utils_create_gtk_builder(
+  gnac_properties_builder = gnac_ui_utils_create_gtk_builder(
       PKGDATADIR "/gnac-properties-window.xml");
 
   gnac_properties_build_table();
diff --git a/src/gnac-ui-utils.c b/src/gnac-ui-utils.c
new file mode 100644
index 0000000..a2c7e4e
--- /dev/null
+++ b/src/gnac-ui-utils.c
@@ -0,0 +1,192 @@
+/*
+ * This file is part of GNAC - Gnome Audio Converter
+ *
+ * Copyright (C) 2007 - 2011 Gnac
+ *    
+ *    - DUPASQUIER  Benoit    <bdupasqu src gnome org>
+ *    - JOAQUIM     David     <djoaquim src gnome org>
+ *    - ROUX        Alexandre <alexroux src gnome org>
+ *
+ * GNAC is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNAC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNAC; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gdk/gdkkeysyms.h>
+#include <glib/gi18n.h>
+
+#include "gnac-ui-utils.h"
+
+#define GNAC_UTILS_ICON_BORDER_WIDTH 1
+
+
+gint
+gnac_ui_utils_get_combo_size(GtkComboBox *combo)
+{
+  gboolean      has_next;
+  guint         count = 0;
+  GtkTreeIter   iter;
+  GtkTreeModel *model;
+
+  model = gtk_combo_box_get_model(combo);
+  has_next = gtk_tree_model_get_iter_first(model, &iter);
+
+  while (has_next) {
+    count++;
+    has_next = gtk_tree_model_iter_next(model, &iter);
+  }
+
+  return count;
+}
+
+
+GdkPixbuf *
+gnac_ui_utils_scale_pixbuf(GdkPixbuf *pixbuf,
+                           gint       new_width,
+                           gint       new_height)
+{
+  g_return_val_if_fail(GDK_IS_PIXBUF(pixbuf), NULL);
+
+  gint n_height, n_width;
+
+  gint width = gdk_pixbuf_get_width(pixbuf);
+  gint height = gdk_pixbuf_get_height(pixbuf);
+
+  if (width > height) {
+    n_width = new_width;
+    n_height = n_width * height / width;
+  } else {
+    n_height = new_height;
+    n_width = n_height * width / height;
+  }
+
+  return gdk_pixbuf_scale_simple(pixbuf, n_width, n_height,
+      GDK_INTERP_BILINEAR);
+}
+
+
+GdkPixbuf *
+gnac_ui_utils_add_border_to_pixbuf(GdkPixbuf *pixbuf)
+{
+  g_return_val_if_fail(GDK_IS_PIXBUF(pixbuf), NULL);
+
+  gint width = gdk_pixbuf_get_width(pixbuf);
+  gint height = gdk_pixbuf_get_height(pixbuf);
+  GdkPixbuf *bordered = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(pixbuf),
+      gdk_pixbuf_get_has_alpha(pixbuf), gdk_pixbuf_get_bits_per_sample(pixbuf),
+      width + (GNAC_UTILS_ICON_BORDER_WIDTH*2),
+      height +(GNAC_UTILS_ICON_BORDER_WIDTH*2));
+  gdk_pixbuf_fill(bordered, 0xff);
+  gdk_pixbuf_copy_area(pixbuf, 0, 0, width, height, bordered, 
+      GNAC_UTILS_ICON_BORDER_WIDTH, GNAC_UTILS_ICON_BORDER_WIDTH);
+
+  return bordered;
+}
+
+
+static gboolean
+gnac_ui_utils_event_is_double_click(GdkEventButton *event)
+{
+  return event->type == GDK_2BUTTON_PRESS;
+}
+
+
+static gboolean
+gnac_ui_utils_event_is_single_click(GdkEventButton *event)
+{
+  return event->type == GDK_BUTTON_PRESS;
+}
+
+
+gboolean
+gnac_ui_utils_event_is_left_click(GdkEventButton *event)
+{
+  return event->button == 1;
+}
+
+
+gboolean
+gnac_ui_utils_event_is_right_click(GdkEventButton *event)
+{
+  return event->button == 3;
+}
+
+
+gboolean
+gnac_ui_utils_event_is_double_left_click(GdkEventButton *event)
+{
+  return gnac_ui_utils_event_is_double_click(event) &&
+         gnac_ui_utils_event_is_left_click(event);
+}
+
+
+gboolean
+gnac_ui_utils_event_is_single_right_click(GdkEventButton *event)
+{
+  return gnac_ui_utils_event_is_single_click(event) &&
+         gnac_ui_utils_event_is_right_click(event);
+}
+
+
+gboolean
+gnac_ui_utils_event_is_delete_key(GdkEventKey *event)
+{
+  return event->keyval == GDK_KEY_Delete;
+}
+
+
+gboolean
+gnac_ui_utils_event_is_escape_key(GdkEventKey *event)
+{
+  return event->keyval == GDK_KEY_Escape;
+}
+
+
+gboolean
+gnac_ui_utils_event_is_return_key(GdkEventKey *event)
+{
+  return event->keyval == GDK_KEY_Return;
+}
+
+
+GtkBuilder *
+gnac_ui_utils_create_gtk_builder(const gchar *filename)
+{
+  GError *error = NULL;
+
+  GtkBuilder *builder = gtk_builder_new();
+  gtk_builder_add_from_file(builder, filename, &error);
+  if (error) {
+    g_printerr("%s: %s\n", _("Unable to read file"), error->message);
+    g_clear_error(&error);
+  }
+
+  g_assert(!error && builder);
+
+  gtk_builder_connect_signals(builder, NULL);
+
+  return builder;
+}
+
+
+GtkWidget *
+gnac_ui_utils_get_widget(GtkBuilder  *builder,
+                         const gchar *widget_name)
+{
+  return GTK_WIDGET(gtk_builder_get_object(builder, widget_name));
+}
diff --git a/src/gnac-ui-utils.h b/src/gnac-ui-utils.h
new file mode 100644
index 0000000..90ba85c
--- /dev/null
+++ b/src/gnac-ui-utils.h
@@ -0,0 +1,79 @@
+/*
+ * This file is part of GNAC - Gnome Audio Converter
+ *
+ * Copyright (C) 2007 - 2011 Gnac
+ *    
+ *    - DUPASQUIER  Benoit    <bdupasqu src gnome org>
+ *    - JOAQUIM     David     <djoaquim src gnome org>
+ *    - ROUX        Alexandre <alexroux src gnome org>
+ *
+ * GNAC is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNAC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNAC; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef GNAC_UI_UTILS_H
+#define GNAC_UI_UTILS_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+gint
+gnac_ui_utils_get_combo_size(GtkComboBox *combo);
+
+/* scale pixbuf to width x height while keeping the aspect ratio */
+GdkPixbuf *
+gnac_ui_utils_scale_pixbuf(GdkPixbuf *pixbuf,
+                           gint       width,
+                           gint       height);
+
+/* add a one pixel black border around pixbuf */
+GdkPixbuf *
+gnac_ui_utils_add_border_to_pixbuf(GdkPixbuf *pixbuf);
+
+gboolean
+gnac_ui_utils_event_is_left_click(GdkEventButton *event);
+
+gboolean
+gnac_ui_utils_event_is_right_click(GdkEventButton *event);
+
+gboolean
+gnac_ui_utils_event_is_double_left_click(GdkEventButton *event);
+
+gboolean
+gnac_ui_utils_event_is_single_right_click(GdkEventButton *event);
+
+gboolean
+gnac_ui_utils_event_is_key_press(GdkEventKey *event);
+
+gboolean
+gnac_ui_utils_event_is_delete_key(GdkEventKey *event);
+
+gboolean
+gnac_ui_utils_event_is_escape_key(GdkEventKey *event);
+
+gboolean
+gnac_ui_utils_event_is_return_key(GdkEventKey *event);
+
+GtkBuilder *
+gnac_ui_utils_create_gtk_builder(const gchar *filename);
+
+GtkWidget *
+gnac_ui_utils_get_widget(GtkBuilder  *builder,
+                         const gchar *widget_name);
+
+G_END_DECLS
+
+#endif /* GNAC_UI_UTILS_H */
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index 45fe319..836de35 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -46,6 +46,7 @@
 #include "gnac-properties.h"
 #include "gnac-stock-items.h"
 #include "gnac-ui.h"
+#include "gnac-ui-utils.h"
 #include "gnac-utils.h"
 #include "libgnac-debug.h"
 #include "profiles/gnac-profiles.h"
@@ -568,7 +569,7 @@ gnac_ui_file_chooser_key_press_event_cb(GtkWidget   *widget,
                                         GdkEventKey *event,
                                         gpointer     user_data)
 {
-  if (gnac_utils_event_is_return_key(event)) {
+  if (gnac_ui_utils_event_is_return_key(event)) {
     gnac_ui_file_chooser_response_cb(GTK_DIALOG(widget),
         GTK_RESPONSE_NONE, NULL);
     return TRUE;
@@ -613,7 +614,7 @@ gnac_ui_new(void)
 
   gnac_stock_items_init();
 
-  gnac_main_builder = gnac_utils_create_gtk_builder(PKGDATADIR "/gnac.xml");
+  gnac_main_builder = gnac_ui_utils_create_gtk_builder(PKGDATADIR "/gnac.xml");
 
   gtk_window_set_default_icon_name(PACKAGE);
 
@@ -1249,8 +1250,8 @@ gnac_ui_query_tooltip_cb(GtkStatusIcon *status_icon,
   if (libgnac_metadata_tag_exists(tags, GST_TAG_IMAGE)) {
     GdkPixbuf *pixbuf;
     pixbuf = g_value_get_object(LIBGNAC_METADATA_TAG_IMAGE(tags));
-    pixbuf = gnac_utils_scale_pixbuf(pixbuf, 80, 80);
-    pixbuf = gnac_utils_add_border_to_pixbuf(pixbuf);
+    pixbuf = gnac_ui_utils_scale_pixbuf(pixbuf, 80, 80);
+    pixbuf = gnac_ui_utils_add_border_to_pixbuf(pixbuf);
     gtk_tooltip_set_icon(tooltip, pixbuf);
   }
 
diff --git a/src/gnac-utils.c b/src/gnac-utils.c
index d2faf49..508db4b 100644
--- a/src/gnac-utils.c
+++ b/src/gnac-utils.c
@@ -27,14 +27,11 @@
 #include "config.h"
 #endif
 
-#include <gdk/gdkkeysyms.h>
 #include <gio/gio.h>
-#include <glib.h>
 #include <glib/gi18n.h>
 
 #include "gnac-utils.h"
 
-#define GNAC_UTILS_ICON_BORDER_WIDTH 1
 
 static guint64 average = 0;
 static guint64 total_samples = 0;
@@ -78,17 +75,14 @@ gnac_utils_format_duration_for_display(guint64 duration)
   minutes = (gint) ((duration / 60) % 60);
   seconds = (gint) (duration % 60);
 
-  if (duration >= 3600) 
-  {
+  if (duration >= 3600) {
     /* Translators: time remaining hours:minutes:seconds. You may change ":" to the separator that your local uses or use "%Id" instead of "%d" if your locale uses localized digits. */
     return g_strdup_printf(_("%d:%02d:%02d"),
         (gint) (duration / 3600), minutes, seconds);
-  } 
-  else
-  {
+  } else {
     /* Translators: time remaining minutes:seconds. You may change ":" to the separator that your local uses or use "%Id" instead of "%d" if your locale uses localized digits. */
     return g_strdup_printf(_("%d:%02d"), minutes, seconds);
-  } 
+  }
 
   return NULL;
 }
@@ -119,78 +113,6 @@ gnac_utils_moving_avg_reset(void)
 }
 
 
-gint
-gnac_utils_get_combo_size(GtkComboBox *combo)
-{
-  gboolean      has_next;
-  guint         count = 0;
-  GtkTreeIter   iter;
-  GtkTreeModel *model;
-
-  model = gtk_combo_box_get_model(combo);
-  has_next = gtk_tree_model_get_iter_first(model, &iter);
-
-  while (has_next) {
-    count++;
-    has_next = gtk_tree_model_iter_next(model, &iter);
-  }
-
-  return count;
-}
-
-
-GdkPixbuf *
-gnac_utils_scale_pixbuf(GdkPixbuf *pixbuf,
-                        gint       new_width,
-                        gint       new_height)
-{
-  gint height, width;
-  gint n_height, n_width;
-
-  g_return_val_if_fail(GDK_IS_PIXBUF(pixbuf), NULL);
-
-  width = gdk_pixbuf_get_width(pixbuf);
-  height = gdk_pixbuf_get_height(pixbuf);
-
-  if (width > height)
-  {
-    n_width = new_width;
-    n_height = n_width * height / width;
-  }
-  else
-  {
-    n_height = new_height;
-    n_width = n_height * width / height;
-  }
-
-  return gdk_pixbuf_scale_simple(pixbuf, n_width, n_height,
-      GDK_INTERP_BILINEAR);
-}
-
-
-GdkPixbuf *
-gnac_utils_add_border_to_pixbuf(GdkPixbuf *pixbuf)
-{
-  GdkPixbuf *bordered;
-  gint width, height;
-
-  g_return_val_if_fail(GDK_IS_PIXBUF(pixbuf), NULL);
-
-  width = gdk_pixbuf_get_width(pixbuf);
-  height = gdk_pixbuf_get_height(pixbuf);
-  bordered = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(pixbuf),
-                            gdk_pixbuf_get_has_alpha(pixbuf),
-                            gdk_pixbuf_get_bits_per_sample(pixbuf),
-                            width + (GNAC_UTILS_ICON_BORDER_WIDTH*2),
-                            height +(GNAC_UTILS_ICON_BORDER_WIDTH*2));
-  gdk_pixbuf_fill(bordered, 0xff);
-  gdk_pixbuf_copy_area(pixbuf, 0, 0, width, height, bordered, 
-            GNAC_UTILS_ICON_BORDER_WIDTH, GNAC_UTILS_ICON_BORDER_WIDTH);
-
-  return bordered;
-}
-
-
 /*
  * The returned value must be freed using g_strfreev()
  */
@@ -236,92 +158,6 @@ gnac_utils_file_format_is_supported(const gchar *mime_type)
 }
 
 
-static gboolean
-gnac_utils_event_is_double_click(GdkEventButton *event)
-{
-  return event->type == GDK_2BUTTON_PRESS;
-}
-
-
-static gboolean
-gnac_utils_event_is_single_click(GdkEventButton *event)
-{
-  return event->type == GDK_BUTTON_PRESS;
-}
-
-
-gboolean
-gnac_utils_event_is_left_click(GdkEventButton *event)
-{
-  return event->button == 1;
-}
-
-
-gboolean
-gnac_utils_event_is_right_click(GdkEventButton *event)
-{
-  return event->button == 3;
-}
-
-
-gboolean
-gnac_utils_event_is_double_left_click(GdkEventButton *event)
-{
-  return gnac_utils_event_is_double_click(event) &&
-         gnac_utils_event_is_left_click(event);
-}
-
-
-gboolean
-gnac_utils_event_is_single_right_click(GdkEventButton *event)
-{
-  return gnac_utils_event_is_single_click(event) &&
-         gnac_utils_event_is_right_click(event);
-}
-
-
-gboolean
-gnac_utils_event_is_delete_key(GdkEventKey *event)
-{
-  return event->keyval == GDK_KEY_Delete;
-}
-
-
-gboolean
-gnac_utils_event_is_escape_key(GdkEventKey *event)
-{
-  return event->keyval == GDK_KEY_Escape;
-}
-
-
-gboolean
-gnac_utils_event_is_return_key(GdkEventKey *event)
-{
-  return event->keyval == GDK_KEY_Return;
-}
-
-
-GtkBuilder *
-gnac_utils_create_gtk_builder(const gchar *filename)
-{
-  GError *error = NULL;
-  GtkBuilder *builder;
-
-  builder = gtk_builder_new();
-  gtk_builder_add_from_file(builder, filename, &error);
-  if (error) {
-    g_printerr("%s: %s\n", _("Unable to read file"), error->message);
-    g_error_free(error);
-  }
-
-  g_assert(!error && builder);
-
-  gtk_builder_connect_signals(builder, NULL);
-
-  return builder;
-}
-
-
 gboolean
 gnac_utils_string_is_null_or_empty(const gchar *string)
 {
@@ -335,11 +171,3 @@ gnac_utils_str_equal(const gchar *str1,
 {
   return g_strcmp0(str1, str2) == 0;
 }
-
-
-GtkWidget *
-gnac_utils_get_widget(GtkBuilder  *builder,
-                      const gchar *widget_name)
-{
-  return GTK_WIDGET(gtk_builder_get_object(builder, widget_name));
-}
diff --git a/src/gnac-utils.h b/src/gnac-utils.h
index e0044ed..bf5f9aa 100644
--- a/src/gnac-utils.h
+++ b/src/gnac-utils.h
@@ -26,7 +26,7 @@
 #ifndef GNAC_UTILS_H
 #define GNAC_UTILS_H
 
-#include <gtk/gtk.h>
+#include <glib.h>
 
 G_BEGIN_DECLS
 
@@ -46,19 +46,6 @@ gnac_utils_moving_avg_add_sample(guint64 sample);
 void
 gnac_utils_moving_avg_reset(void);
 
-gint
-gnac_utils_get_combo_size(GtkComboBox *combo);
-
-/* scale pixbuf to width x height while keeping the aspect ratio */
-GdkPixbuf *
-gnac_utils_scale_pixbuf(GdkPixbuf *pixbuf,
-                        gint       width,
-                        gint       height);
-
-/* add a one pixel black border around pixbuf */
-GdkPixbuf *
-gnac_utils_add_border_to_pixbuf(GdkPixbuf *pixbuf);
-
 /* The returned value must be freed using g_strfreev() */
 gchar **
 gnac_utils_get_filenames_from_cmd_line(gchar **argv);
@@ -67,43 +54,12 @@ gboolean
 gnac_utils_file_format_is_supported(const gchar *mime_type);
 
 gboolean
-gnac_utils_event_is_left_click(GdkEventButton *event);
-
-gboolean
-gnac_utils_event_is_right_click(GdkEventButton *event);
-
-gboolean
-gnac_utils_event_is_double_left_click(GdkEventButton *event);
-
-gboolean
-gnac_utils_event_is_single_right_click(GdkEventButton *event);
-
-gboolean
-gnac_utils_event_is_key_press(GdkEventKey *event);
-
-gboolean
-gnac_utils_event_is_delete_key(GdkEventKey *event);
-
-gboolean
-gnac_utils_event_is_escape_key(GdkEventKey *event);
-
-gboolean
-gnac_utils_event_is_return_key(GdkEventKey *event);
-
-GtkBuilder *
-gnac_utils_create_gtk_builder(const gchar *filename);
-
-gboolean
 gnac_utils_string_is_null_or_empty(const gchar *string);
 
 gboolean
 gnac_utils_str_equal(const gchar *str1,
                      const gchar *str2);
 
-GtkWidget *
-gnac_utils_get_widget(GtkBuilder  *builder,
-                      const gchar *widget_name);
-
 G_END_DECLS
 
 #endif /* GNAC_UTILS_H */
diff --git a/src/profiles/formats/gnac-profiles-unknown.c b/src/profiles/formats/gnac-profiles-unknown.c
index 0e6a1cf..4683e39 100644
--- a/src/profiles/formats/gnac-profiles-unknown.c
+++ b/src/profiles/formats/gnac-profiles-unknown.c
@@ -27,6 +27,7 @@
 #include <glib/gstdio.h>
 
 #include "gnac-main.h"
+#include "gnac-ui-utils.h"
 #include "gnac-utils.h"
 #include "gnac-profiles-unknown.h"
 
@@ -126,7 +127,7 @@ gnac_profiles_unknown_get_funcs(void)
 static const gchar *
 gnac_profiles_unknown_init(UpdateTextBufferFunc call_back)
 {
-  unknown_bfi.builder = gnac_utils_create_gtk_builder(
+  unknown_bfi.builder = gnac_ui_utils_create_gtk_builder(
       unknown_bfi.gtkbuilder_xml_file);
 
   return unknown_bfi.format_id;
diff --git a/src/profiles/gnac-profiles-default.c b/src/profiles/gnac-profiles-default.c
index 4ea6027..57202f4 100755
--- a/src/profiles/gnac-profiles-default.c
+++ b/src/profiles/gnac-profiles-default.c
@@ -27,7 +27,7 @@
 
 #include "gnac-main.h"
 #include "gnac-profiles-default.h"
-#include "gnac-utils.h"
+#include "gnac-ui-utils.h"
 #include "libgnac-debug.h"
 
 
@@ -39,7 +39,7 @@ gnac_profiles_default_init(BasicFormatInfo *bfi)
   GtkWidget *profile_advanced_base_widget;
   GError    *error = NULL;
 
-  bfi->builder = gnac_utils_create_gtk_builder(bfi->gtkbuilder_xml_file);
+  bfi->builder = gnac_ui_utils_create_gtk_builder(bfi->gtkbuilder_xml_file);
 
   widget = gnac_profiles_default_get_properties_alignment(bfi);
 
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index 2e185c9..f037539 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -34,6 +34,7 @@
 #include "gnac-profiles.h"
 #include "gnac-profiles-default.h"
 #include "gnac-profiles-manager.h"
+#include "gnac-ui-utils.h"
 #include "gnac-utils.h"
 #include "libgnac-debug.h"
 
@@ -178,7 +179,7 @@ gnac_profiles_mgr_init(void)
   GtkTreeModel     *model;
   GtkWidget        *widget;
 
-  profiles_mgr_builder = gnac_utils_create_gtk_builder(
+  profiles_mgr_builder = gnac_ui_utils_create_gtk_builder(
       PKGDATADIR "/profiles/gnac-profiles-manager.xml");
 
   view = GTK_TREE_VIEW(gnac_profiles_mgr_get_widget("profile_treeview"));
@@ -1417,7 +1418,7 @@ gnac_profiles_mgr_list_on_key_pressed(GtkWidget   *widget,
                                       GdkEventKey *event,
                                       gpointer     data)
 {
-  if (gnac_utils_event_is_delete_key(event)) {
+  if (gnac_ui_utils_event_is_delete_key(event)) {
     gnac_profiles_mgr_on_remove(NULL, NULL);
     return TRUE;
   }
@@ -1431,7 +1432,7 @@ gnac_profiles_mgr_on_key_pressed(GtkWidget   *widget,
                                  GdkEventKey *event,
                                  gpointer     data)
 {
-  if (gnac_utils_event_is_escape_key(event)) {
+  if (gnac_ui_utils_event_is_escape_key(event)) {
     widget = gnac_profiles_mgr_get_widget("close_button");
     gtk_button_clicked(GTK_BUTTON(widget));
     return TRUE;
diff --git a/src/profiles/gnac-profiles-properties.c b/src/profiles/gnac-profiles-properties.c
index c54070f..d039441 100644
--- a/src/profiles/gnac-profiles-properties.c
+++ b/src/profiles/gnac-profiles-properties.c
@@ -43,6 +43,7 @@
 #include "gnac-main.h"
 #include "gnac-profiles-default.h"
 #include "gnac-profiles-properties.h"
+#include "gnac-ui-utils.h"
 #include "gnac-utils.h"
 
 #include "libgnac-debug.h"
@@ -139,7 +140,7 @@ gnac_profiles_properties_init(void)
   GtkWindow       *window;
   GtkCellRenderer *renderer_format;
   
-  profiles_properties_builder = gnac_utils_create_gtk_builder(
+  profiles_properties_builder = gnac_ui_utils_create_gtk_builder(
       PKGDATADIR "/profiles/gnac-profiles-properties.xml");
   formats = g_hash_table_new(g_str_hash, g_str_equal);
   
@@ -577,7 +578,7 @@ gnac_profiles_properties_on_name_entry_key_pressed(GtkWidget   *widget,
                                                    GdkEventKey *event,
                                                    gpointer     data)
 {
-  if (gnac_utils_event_is_return_key(event)) {
+  if (gnac_ui_utils_event_is_return_key(event)) {
     GtkWidget *widget;
     widget = gnac_profiles_properties_get_widget("save-button");
     gtk_button_clicked(GTK_BUTTON(widget));
@@ -605,7 +606,7 @@ gnac_profiles_properties_on_window_key_pressed(GtkWidget   *widget,
                                                GdkEventKey *event,
                                                gpointer     data)
 {
-  if (gnac_utils_event_is_escape_key(event)) {
+  if (gnac_ui_utils_event_is_escape_key(event)) {
     GtkWidget *widget;
     widget = gnac_profiles_properties_get_widget("cancel-button");
     gtk_button_clicked(GTK_BUTTON(widget));
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index 403e4f5..2409b9c 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -24,6 +24,7 @@
  */
 
 #include "gnac-profiles-utils.h"
+#include "gnac-ui-utils.h"
 #include "gnac-utils.h"
 #include "libgnac-debug.h"
 
@@ -210,7 +211,7 @@ gnac_profiles_utils_register_advanced_channels(GtkBuilder *builder,
 {
   GtkWidget *widget;
 
-  widget = gnac_utils_get_widget(builder, "combo-channels");
+  widget = gnac_ui_utils_get_widget(builder, "combo-channels");
   if (!widget) {
     libgnac_warning("Impossible to find widget %s", "combo-channels");
     return NULL;
@@ -228,7 +229,7 @@ gnac_profiles_utils_register_advanced_sample_rate(GtkBuilder *builder,
 {
   GtkWidget *widget;
 
-  widget = gnac_utils_get_widget(builder, "combo-sample-rate");
+  widget = gnac_ui_utils_get_widget(builder, "combo-sample-rate");
   if (!widget) {
     libgnac_warning("Impossible to find widget %s", "combo-sample-rate");
     return NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]