[gnac/devel] Better separation between gnac-main and gnac-ui



commit d7b127cd7cbe90031718122dbe3b642b59bd0661
Author: Benoît Dupasquier <bdupasqu src gnome org>
Date:   Mon Oct 18 17:30:09 2010 +0100

    Better separation between gnac-main and gnac-ui

 data/ui/gnac.xml |    2 +-
 src/gnac-main.c  |  105 +++------------------------------------------------
 src/gnac-main.h  |    5 --
 src/gnac-ui.c    |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/gnac-ui.h    |   20 ++++++++++
 5 files changed, 136 insertions(+), 106 deletions(-)
---
diff --git a/data/ui/gnac.xml b/data/ui/gnac.xml
index e98c4c0..415231e 100644
--- a/data/ui/gnac.xml
+++ b/data/ui/gnac.xml
@@ -191,7 +191,7 @@
     <property name="default_height">500</property>
     <property name="icon_name">gnac</property>
     <signal handler="gnac_on_ui_destroy_cb" name="delete-event"/>
-    <signal handler="gnac_on_ui_focus_in_event_cb" name="focus-in-event"/>
+    <signal handler="gnac_ui_on_focus_in_event_cb" name="focus-in-event"/>
     <child>
       <object class="GtkVBox" id="internal_vbox">
         <property name="visible">True</property>
diff --git a/src/gnac-main.c b/src/gnac-main.c
index 402e3d1..18d9f78 100644
--- a/src/gnac-main.c
+++ b/src/gnac-main.c
@@ -58,7 +58,6 @@ static LibgnacConverter *converter;
 
 static gboolean   conversion_errors = FALSE;
 static guint64    prev_time_left = -1;
-static guint      timeout_id;
 //volatile?
 static gboolean   continue_files_action;
 static gboolean   quit_app = FALSE;
@@ -98,47 +97,18 @@ gnac_change_state(GnacState new_state)
 
   switch (state) {
     case GNAC_AUDIO_EMPTY_STATE:
-      gnac_bars_on_row_deleted();
-      if (gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON)) gnac_ui_hide_trayicon();
-      gnac_ui_show_progress(FALSE);
-      gnac_ui_show_pause(FALSE);
-      gnac_bars_on_convert_stop();
-      if (timeout_id != 0) {
-        g_source_remove(timeout_id);
-        timeout_id = 0;
-      }
-      gnac_ui_set_progress_fraction(0.0f);
-      gnac_ui_set_progress_text("");
+      gnac_ui_on_audio_empty_state();
       prev_time_left = -1;
       gnac_utils_moving_avg_reset();
     break;
 
     case GNAC_AUDIO_FILE_ACTION_STATE:
-      timeout_id = g_timeout_add(100, 
-        (GSourceFunc)gnac_ui_pulse_progress, NULL);
-      gnac_bars_on_add_files();
-      gnac_ui_show_progress(TRUE);
+      gnac_ui_on_audio_file_action_state();
     break;
 
     case GNAC_AUDIO_READY_STATE: 
       remember_overwrite = FALSE;
-      gnac_bars_on_row_inserted();
-      if (gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON) &&
-          gtk_window_has_toplevel_focus(
-              GTK_WINDOW(gnac_ui_get_widget("main_window"))))
-      {
-        gnac_ui_hide_trayicon();
-      }
-      gnac_ui_show_progress(FALSE);
-      gnac_ui_show_pause(FALSE);
-      gnac_bars_on_convert_stop();
-      if (timeout_id != 0) {
-        g_source_remove(timeout_id);
-        timeout_id = 0;
-      }
-      gnac_utils_moving_avg_reset();
-      gnac_ui_set_progress_fraction(0.0f);
-      gnac_ui_set_progress_text("");
+      gnac_ui_on_audio_ready_state();
       prev_time_left = -1;
       gnac_utils_moving_avg_reset();
     break;
@@ -148,12 +118,7 @@ gnac_change_state(GnacState new_state)
     break;
   
     case GNAC_AUDIO_CONVERT_STATE:
-      if (gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON)) gnac_ui_show_trayicon();
-      gnac_file_list_hide_visual_bar();
-      gnac_ui_show_progress(TRUE);
-      gnac_ui_show_pause(TRUE);
-      gnac_bars_on_convert();
-      gnac_bars_on_convert_resume();
+      gnac_ui_on_audio_convert_state();
     break;
 
     case GNAC_AUDIO_PAUSED_STATE:
@@ -388,53 +353,6 @@ gnac_add_file(GFile *file)
 }
 
 
-static gboolean
-gnac_confirm_exit(void)
-{
-  gboolean   has_trayicon;
-  gint       response;
-  GtkWidget *dialog;
-
-  has_trayicon = gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON);
-
-  /* disable stop/resume and quit from trayicon's menu */
-  if (has_trayicon) gnac_ui_trayicon_menu_activate(FALSE);
-
-  dialog = gtk_message_dialog_new(
-      GTK_WINDOW(gnac_ui_get_widget("main_window")),
-      GTK_DIALOG_MODAL,
-      GTK_MESSAGE_WARNING,
-      GTK_BUTTONS_YES_NO,
-      "%s\n%s",
-      _("A conversion is currently running..."),
-      _("Are you sure you want to quit?"));
-
-  gtk_window_set_title(GTK_WINDOW(dialog), PACKAGE_NAME);
-
-  response = gtk_dialog_run(GTK_DIALOG(dialog));
-
-  gtk_widget_destroy(dialog);
-
-  /* enable stop/resume and quit from trayicon's menu */
-  if (has_trayicon) gnac_ui_trayicon_menu_activate(TRUE);
-
-  return (response == GTK_RESPONSE_YES);
-}
-
-
-gboolean
-gnac_on_ui_focus_in_event_cb(GtkWidget     *widget,
-                             GdkEventFocus *event,
-                             gpointer       data)
-{
-  /* the trayicon is only displayed during a conversion */
-  if (state == GNAC_AUDIO_READY_STATE) {
-    gnac_ui_hide_trayicon();
-  }
-  return FALSE;
-}
-
-
 G_GNUC_NORETURN void
 gnac_exit(gint status)
 {
@@ -458,7 +376,7 @@ gnac_on_ui_destroy_cb(GtkWidget *widget,
     case GNAC_AUDIO_CONVERT_STATE:
     case GNAC_AUDIO_PAUSED_STATE: {
       GError *error = NULL;
-      if (!gnac_confirm_exit()) return TRUE;
+      if (!gnac_ui_confirm_exit()) return TRUE;
       libgnac_converter_stop(converter, &error);
       if (error) {
         libgnac_debug("Error: %s", error->message);
@@ -647,20 +565,9 @@ gnac_on_converter_file_started_cb(LibgnacConverter *converter,
                                   const gchar      *input,
                                   const gchar      *output)
 {
-  GError *err = NULL;
-
   gnac_file_list_remove_visual_error(input);
-
   gnac_file_list_select_uri_and_follow(input);
-
-  if (err) {
-    g_clear_error(&err);
-    return;
-  }
-
-  if (gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON)) {
-    gnac_ui_trayicon_tooltip_update(input);
-  }
+  gnac_ui_trayicon_tooltip_update(input);
 }
 
 
diff --git a/src/gnac-main.h b/src/gnac-main.h
index 98d19c2..35b5b29 100644
--- a/src/gnac-main.h
+++ b/src/gnac-main.h
@@ -79,11 +79,6 @@ void
 gnac_on_ui_help_cb(GtkAction *action,
                    gpointer   data);
 
-gboolean
-gnac_on_ui_focus_in_event_cb(GtkWidget     *widget,
-                             GdkEventFocus *event,
-                             gpointer       data);
-
 G_GNUC_NORETURN void
 gnac_exit(gint status);
 
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index baef1c2..457b019 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -62,6 +62,7 @@ static GtkWidget      *gnac_file_chooser;
 static gchar          *status_msg = NULL;
 static gchar          *tooltip_path = NULL;
 static gchar          *progress_msg = NULL;
+static guint           timeout_id;
 
 static gint root_x;
 static gint root_y;
@@ -798,6 +799,78 @@ gnac_ui_get_action(const gchar *widget_name)
 }
 
 
+void
+gnac_ui_on_audio_empty_state(void)
+{
+  gnac_bars_on_row_deleted();
+  gnac_ui_hide_trayicon();
+  gnac_ui_show_progress(FALSE);
+  gnac_ui_show_pause(FALSE);
+  gnac_bars_on_convert_stop();
+  if (timeout_id != 0) {
+    g_source_remove(timeout_id);
+    timeout_id = 0;
+  }
+  gnac_ui_set_progress_fraction(0.0f);
+  gnac_ui_set_progress_text("");
+}
+
+
+void
+gnac_ui_on_audio_file_action_state(void)
+{
+  timeout_id = g_timeout_add(100, (GSourceFunc)gnac_ui_pulse_progress, NULL);
+  gnac_bars_on_add_files();
+  gnac_ui_show_progress(TRUE);
+}
+
+
+void
+gnac_ui_on_audio_ready_state(void)
+{
+  gnac_bars_on_row_inserted();
+  if (gtk_window_has_toplevel_focus(
+      GTK_WINDOW(gnac_ui_get_widget("main_window"))))
+  {
+    gnac_ui_hide_trayicon();
+  }
+  gnac_ui_show_progress(FALSE);
+  gnac_ui_show_pause(FALSE);
+  gnac_bars_on_convert_stop();
+  if (timeout_id != 0) {
+    g_source_remove(timeout_id);
+    timeout_id = 0;
+  }
+  gnac_ui_set_progress_fraction(0.0f);
+  gnac_ui_set_progress_text("");
+}
+
+
+void
+gnac_ui_on_audio_convert_state(void)
+{
+  gnac_ui_show_trayicon();
+  gnac_file_list_hide_visual_bar();
+  gnac_ui_show_progress(TRUE);
+  gnac_ui_show_pause(TRUE);
+  gnac_bars_on_convert();
+  gnac_bars_on_convert_resume();
+}
+
+
+gboolean
+gnac_ui_on_focus_in_event_cb(GtkWidget     *widget,
+                             GdkEventFocus *event,
+                             gpointer       data)
+{
+  /* the trayicon is only displayed during a conversion */
+  if (state == GNAC_AUDIO_READY_STATE) {
+    gnac_ui_hide_trayicon();
+  }
+  return FALSE;
+}
+
+
 #ifdef HAVE_LIBUNIQUE
 static UniqueResponse
 gnac_ui_message_received_cb(UniqueApp         *app,
@@ -987,6 +1060,37 @@ gnac_ui_destroy(void)
 }
 
 
+gboolean
+gnac_ui_confirm_exit(void)
+{
+  gint       response;
+  GtkWidget *dialog;
+
+  /* disable stop/resume and quit from trayicon's menu */
+  gnac_ui_trayicon_menu_activate(FALSE);
+
+  dialog = gtk_message_dialog_new(
+      GTK_WINDOW(gnac_ui_get_widget("main_window")),
+      GTK_DIALOG_MODAL,
+      GTK_MESSAGE_WARNING,
+      GTK_BUTTONS_YES_NO,
+      "%s\n%s",
+      _("A conversion is currently running..."),
+      _("Are you sure you want to quit?"));
+
+  gtk_window_set_title(GTK_WINDOW(dialog), PACKAGE_NAME);
+
+  response = gtk_dialog_run(GTK_DIALOG(dialog));
+
+  gtk_widget_destroy(dialog);
+
+  /* enable stop/resume and quit from trayicon's menu */
+  gnac_ui_trayicon_menu_activate(TRUE);
+
+  return (response == GTK_RESPONSE_YES);
+}
+
+
 /* Tray icon */
 
 gboolean
@@ -1061,6 +1165,8 @@ gnac_ui_show_trayicon(void)
 {
   GtkWidget *main_window;
 
+  if (!gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON)) return;
+
   main_window = gnac_ui_get_widget("main_window");
 
   if (!trayicon) 
@@ -1087,7 +1193,7 @@ gnac_ui_hide_trayicon(void)
   GtkWidget *main_window;
   gboolean window_displayed;
 
-  if (!trayicon) return;
+  if (!gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON) || !trayicon) return;
 
   main_window = gnac_ui_get_widget("main_window");
   g_object_get(main_window, "visible", &window_displayed, NULL);
@@ -1162,6 +1268,8 @@ gnac_ui_trayicon_tooltip_update(const gchar *tooltip)
 {
   GdkDisplay *display;
   
+  if (!gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON) || !trayicon) return;
+
   if (tooltip_path) {
     g_free(tooltip_path);
     tooltip_path = NULL;
diff --git a/src/gnac-ui.h b/src/gnac-ui.h
index 035ed9d..3218ecf 100644
--- a/src/gnac-ui.h
+++ b/src/gnac-ui.h
@@ -109,9 +109,29 @@ gnac_ui_get_widget(const gchar *widget_name);
 GtkAction *
 gnac_ui_get_action(const gchar *widget_name);
 
+void
+gnac_ui_on_audio_empty_state(void);
+
+void
+gnac_ui_on_audio_file_action_state(void);
+
+void
+gnac_ui_on_audio_ready_state(void);
+
+void
+gnac_ui_on_audio_convert_state(void);
+
+gboolean
+gnac_ui_on_focus_in_event_cb(GtkWidget     *widget,
+                             GdkEventFocus *event,
+                             gpointer       data);
+
 void 
 gnac_ui_destroy(void);
 
+gboolean
+gnac_ui_confirm_exit(void);
+
 void
 gnac_ui_show(void);
 



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