[gnac/devel] Fixed trac ticket #41 (notification on conversion completed)



commit 501c4d99c3032535c6b7668f63628cf79f8adfa0
Author: Benoît Dupasquier <bdupasqu src gnome org>
Date:   Thu Sep 9 21:30:40 2010 +0100

    Fixed trac ticket #41 (notification on conversion completed)

 configure.ac     |   11 +++++++++++
 data/ui/gnac.xml |    1 +
 src/Makefile.am  |   10 ++++++----
 src/gnac-main.c  |   30 ++++++++++++++++++++++++++----
 src/gnac-main.h  |    5 +++++
 src/gnac-ui.c    |   50 +++++++++++++++++++++++++++++++++++++++++++++-----
 src/gnac-ui.h    |    3 +++
 7 files changed, 97 insertions(+), 13 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 86d1310..9e75fb9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,6 +89,17 @@ PKG_CHECK_MODULES(UI, [
 AC_SUBST(UI_CFLAGS)
 AC_SUBST(UI_LIBS)
 
+dnl libnotify
+PKG_CHECK_MODULES(NOTIFY,
+  [libnotify],
+  AC_DEFINE(HAVE_LIBNOTIFY, 1,
+      [Define to 1 if you have the <libnotify/notify.h> header file.]),
+  AC_MSG_WARN(['libnotify' was not found. Notifications will not be displayed.])
+)
+AC_SUBST(NOTIFY_CFLAGS)
+AC_SUBST(NOTIFY_LIBS)
+
+dnl libunique
 PKG_CHECK_MODULES(UNIQUE,
   [unique-1.0],
   AC_DEFINE(HAVE_LIBUNIQUE, 1,
diff --git a/data/ui/gnac.xml b/data/ui/gnac.xml
index 802f89e..e5338e1 100644
--- a/data/ui/gnac.xml
+++ b/data/ui/gnac.xml
@@ -191,6 +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_set_focus_cb" name="set-focus"/>
     <child>
       <object class="GtkVBox" id="internal_vbox">
         <property name="visible">True</property>
diff --git a/src/Makefile.am b/src/Makefile.am
index 92c5c14..febc7fc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -68,20 +68,22 @@ gnac_CPPFLAGS = \
 	$(AM_CPPFLAGS)
 
 gnac_CFLAGS = \
+	$(AM_CFLAGS) \
 	$(GLIB_CFLAGS) \
+	$(GSTREAMER_CFLAGS) \
+	$(NOTIFY_CFLAGS) \
 	$(UI_CFLAGS) \
 	$(UNIQUE_CFLAGS) \
-	$(GSTREAMER_CFLAGS) \
 	$(WARN_CFLAGS) \
-	$(AM_CFLAGS) \
 	-Wl,--export-dynamic
 		
 gnac_LDADD = \
 	$(top_builddir)/libgnac/libgnac.la \
 	$(GLIB_LIBS) \
+	$(GSTREAMER_LIBS) \
+	$(NOTIFY_LIBS) \
 	$(UI_LIBS) \
-	$(UNIQUE_LIBS) \
-	$(GSTREAMER_LIBS)
+	$(UNIQUE_LIBS)
 
 gnac_LDFLAGS = \
 	-Wl,--export-dynamic \
diff --git a/src/gnac-main.c b/src/gnac-main.c
index 5af6bdd..ba72b85 100644
--- a/src/gnac-main.c
+++ b/src/gnac-main.c
@@ -88,7 +88,6 @@ static const gchar *states[] = {
 static void
 gnac_change_state(GnacState new_state)
 {
-
   libgnac_debug("State changed to %s", states[new_state]);
 
   prev_state = state;
@@ -125,7 +124,12 @@ gnac_change_state(GnacState new_state)
     case GNAC_AUDIO_READY_STATE: 
       remember_overwrite = FALSE;
       gnac_bars_on_row_inserted();
-      if (gnac_gconf_get_boolean(GNAC_GCONF_TRAY_ICON)) gnac_ui_hide_trayicon();
+      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();
@@ -414,6 +418,18 @@ gnac_confirm_exit(void)
 }
 
 
+void
+gnac_on_ui_set_focus_cb(GtkWindow *window,
+                        GtkWidget *widget,
+                        gpointer   data)
+{
+  /* the trayicon is only displayed during a conversion */
+  if (state == GNAC_AUDIO_READY_STATE) {
+    gnac_ui_hide_trayicon();
+  }
+}
+
+
 gboolean
 gnac_on_ui_destroy_cb(GtkWidget *widget, 
                       gpointer   data)
@@ -697,12 +713,18 @@ gnac_on_converter_files_cleared_cb(LibgnacConverter *converter)
 static void
 gnac_on_converter_completion_cb(LibgnacConverter *converter)
 {
+  const gchar *msg;
+
   gnac_change_state(GNAC_AUDIO_READY_STATE);
+
   if (conversion_errors) {
-    gnac_ui_push_status(_("Conversion completed with errors"));
+    msg = _("Conversion completed with errors");
   } else {
-    gnac_ui_push_status(_("Conversion completed"));
+    msg = _("Conversion completed");
   }
+
+  gnac_ui_notify(msg);
+  gnac_ui_push_status(msg);
 }
 
 
diff --git a/src/gnac-main.h b/src/gnac-main.h
index 02f5e96..216aaa8 100644
--- a/src/gnac-main.h
+++ b/src/gnac-main.h
@@ -79,6 +79,11 @@ void
 gnac_on_ui_help_cb(GtkAction *action,
                    gpointer   data);
 
+void
+gnac_on_ui_set_focus_cb(GtkWindow *window,
+                        GtkWidget *widget,
+                        gpointer   data);
+
 gboolean
 gnac_on_ui_destroy_cb(GtkWidget *widget, 
                       gpointer   data);
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index 7e3a8d8..a428b05 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -31,6 +31,10 @@
 #include <glib/gi18n.h>
 #include <glib/gprintf.h>
 
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notify.h>
+#endif /* HAVE_LIBNOTIFY */
+
 #ifdef HAVE_LIBUNIQUE
 #include <unique/unique.h>
 #endif /* HAVE_LIBUNIQUE */
@@ -724,6 +728,29 @@ gnac_ui_append_status(const gchar *message)
 }
 
 
+void
+gnac_ui_notify(const gchar *msg)
+{
+#ifdef HAVE_LIBNOTIFY
+
+  NotifyNotification *notification;
+
+  notification = notify_notification_new(PACKAGE_NAME, msg, PACKAGE, NULL);
+  notify_notification_attach_to_status_icon(notification, trayicon);
+
+  notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT);
+  notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL);
+
+  notify_notification_show(notification, NULL);
+
+#else /* HAVE_LIBNOTIFY */
+
+  libgnac_info(msg);
+
+#endif /* !HAVE_LIBNOTIFY */
+}
+
+
 void 
 gnac_ui_show_popup_menu(GtkWidget      *treeview, 
                         GdkEventButton *event, 
@@ -793,16 +820,17 @@ gnac_ui_message_received_cb(UniqueApp         *app,
       filenames = unique_message_data_get_uris(message);
       gnac_options_process_filenames(filenames);
       g_strfreev(filenames);
+      gnac_ui_notify(_("Adding files..."));
       break;
     }
 
     case UNIQUE_CMD_DEBUG:
-      g_print(_("Debug mode activated\n"));
+      gnac_ui_notify(_("Debug mode activated"));
       gnac_options_enable_debug();
       break;
 
     case UNIQUE_CMD_VERBOSE:
-      g_print(_("Verbose mode activated\n"));
+      gnac_ui_notify(_("Verbose mode activated"));
       gnac_options_enable_verbose();
       break;
 
@@ -816,6 +844,15 @@ gnac_ui_message_received_cb(UniqueApp         *app,
 #endif /* HAVE_LIBUNIQUE */
 
 
+static void
+gnac_ui_init_notify(void)
+{
+#ifdef HAVE_LIBNOTIFY
+  notify_init(PACKAGE_NAME);
+#endif /* HAVE_LIBNOTIFY */
+}
+
+
 #ifdef HAVE_LIBUNIQUE
 static void
 gnac_ui_init_unique(void)
@@ -885,6 +922,7 @@ gnac_ui_init_unique(void)
 void
 gnac_ui_init(void)
 {
+  gnac_ui_init_notify();
 #ifdef HAVE_LIBUNIQUE
   gnac_ui_init_unique();
 #endif /* HAVE_LIBUNIQUE */
@@ -1076,15 +1114,17 @@ gnac_ui_on_trayicon(GtkStatusIcon *trayicon,
   main_window = gnac_ui_get_widget("main_window");
   g_object_get(main_window, "visible", &window_displayed, NULL);
 
-  if (window_displayed) 
-  {
+  if (window_displayed) {
     gtk_window_get_position(GTK_WINDOW(main_window), &root_x, &root_y);
     gtk_widget_hide_all(main_window);
-
   } else {
     gtk_widget_show_all(main_window);
     gtk_window_move(GTK_WINDOW(main_window), root_x, root_y);
   }
+
+  if (state == GNAC_AUDIO_READY_STATE) {
+    gnac_ui_hide_trayicon();
+  }
 }
 
 
diff --git a/src/gnac-ui.h b/src/gnac-ui.h
index e0bdbf7..035ed9d 100644
--- a/src/gnac-ui.h
+++ b/src/gnac-ui.h
@@ -60,6 +60,9 @@ void
 gnac_ui_append_status(const gchar *message);
 
 void
+gnac_ui_notify(const gchar *msg);
+
+void
 gnac_ui_activate_profiles(gboolean activate);
 
 void



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