]> granicus.if.org Git - handbrake/commitdiff
LinGui: Add status tray icon support for Ubuntu 11.04
authorjstebbins <jstebbins.hb@gmail.com>
Mon, 20 Jun 2011 15:58:36 +0000 (15:58 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Mon, 20 Jun 2011 15:58:36 +0000 (15:58 +0000)
Ubuntu disables GtkStatusIcon support in Unity and instead uses a new
API called AppIndicator.  So this adds support for appindicator when
it is detected by configure.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4067 b64f7644-9d1e-0410-96f1-a4d463321fa5

gtk/configure.ac
gtk/src/callbacks.c
gtk/src/ghb.ui
gtk/src/main.c
gtk/src/settings.h
pkg/linux/debian/control.natty

index e811fe2b708618343f74ae699e1a17efff3c5902..d2db300c4b1cdf93f872b4641c597db9dcb1ff37 100644 (file)
@@ -128,6 +128,12 @@ fi
 
 AM_CONDITIONAL([MINGW], [test "x$mingw_flag" = "xyes"])
 
+PKG_CHECK_MODULES(libappindicator, appindicator-0.1, have_appind=yes, have_appind=no)
+if test "x$have_appind" = "xyes" ; then
+    GHB_PACKAGES="$GHB_PACKAGES appindicator-0.1"
+    CXXFLAGS="$CXXFLAGS -D_USE_APP_IND"
+    CFLAGS="$CFLAGS -D_USE_APP_IND"
+fi
 PKG_CHECK_MODULES(GHB, [$GHB_PACKAGES])
 
 AC_PATH_PROG(BUILD_PKG_CONFIG, pkg-config, no)
index 7c1bde5ad90942828db083df23a8638bce8abf04..4dc685802dc3a1a57381600afbfa2f98254b6e86 100644 (file)
 #include <dbt.h>
 #endif
 
+#if defined(_USE_APP_IND)
+#include <libappindicator/app-indicator.h>
+#endif
+
 #include "hb.h"
 #include "callbacks.h"
 #include "queuehandler.h"
@@ -2744,6 +2748,13 @@ ghb_backend_events(signal_user_data_t *ud)
 
                si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));
                gtk_status_icon_set_tooltip(si, status_str);
+#endif
+#if defined(_USE_APP_IND)
+               char * ai_status_str= g_strdup_printf(
+                       "%.2f%%",
+                       100.0 * status.queue.progress);
+               app_indicator_set_label( ud->ai, ai_status_str, "99.99%");
+               g_free(ai_status_str);
 #endif
                gtk_label_set_text (work_status, status_str);
                gtk_progress_bar_set_fraction (progress, status.queue.progress);
@@ -2782,6 +2793,13 @@ ghb_backend_events(signal_user_data_t *ud)
 
                si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));
                gtk_status_icon_set_tooltip(si, status_str);
+#endif
+#if defined(_USE_APP_IND)
+               char * ai_status_str= g_strdup_printf(
+                       "%.2f%%",
+                       100.0 * status.queue.progress);
+               app_indicator_set_label( ud->ai, ai_status_str, "99.99%");
+               g_free(ai_status_str);
 #endif
                gtk_label_set_text (work_status, status_str);
                gtk_progress_bar_set_fraction (progress, status.queue.progress);
@@ -2866,6 +2884,9 @@ ghb_backend_events(signal_user_data_t *ud)
 
                si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));
                gtk_status_icon_set_tooltip(si, "HandBrake");
+#endif
+#if defined(_USE_APP_IND)
+               app_indicator_set_label( ud->ai, "", "99.99%");
 #endif
        }
        else if (status.queue.state & GHB_STATE_MUXING)
@@ -3613,6 +3634,16 @@ show_status_cb(GtkWidget *widget, signal_user_data_t *ud)
        si = GTK_STATUS_ICON(GHB_OBJECT (ud->builder, "hb_status"));
        gtk_status_icon_set_visible(si,
                        ghb_settings_get_boolean(ud->settings, "show_status"));
+#if defined(_USE_APP_IND)
+       if (ghb_settings_get_boolean(ud->settings, "show_status"))
+       {
+               app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_ACTIVE );
+       }
+       else
+       {
+               app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_PASSIVE );
+       }
+#endif
 }
 
 G_MODULE_EXPORT void
@@ -4850,6 +4881,27 @@ status_activate_cb(GtkStatusIcon *si, signal_user_data_t *ud)
        }
 }
 
+G_MODULE_EXPORT void
+show_hide_toggle_cb(GtkWidget *xwidget, signal_user_data_t *ud)
+{
+       GtkWindow *window;
+       GdkWindowState state;
+
+       window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window"));
+       state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(window)));
+       if ((state & GDK_WINDOW_STATE_ICONIFIED) ||
+               (ud->hb_visibility != GDK_VISIBILITY_UNOBSCURED))
+       {
+               gtk_window_present(window);
+               gtk_window_set_skip_taskbar_hint(window, FALSE);
+       }
+       else
+       {
+               gtk_window_set_skip_taskbar_hint(window, TRUE);
+               gtk_window_iconify(window);
+       }
+}
+
 #if !defined(_WIN32)
 G_MODULE_EXPORT void
 notify_closed_cb(NotifyNotification *notification, signal_user_data_t *ud)
index 939ae155ea2d101246065f1ff1c0e97eff03bea2..a532d0a3c1b3a93be87832398f0f761d29060247 100644 (file)
             <signal handler="guide_activate_cb" name="activate"/>
           </object>
         </child>
+        <child>
+          <object class="GtkAction" id="show_hide">
+            <property name="name">show_hide</property>
+            <property name="label" translatable="yes">_Minimize/Maximize</property>
+            <signal handler="show_hide_toggle_cb" name="activate"/>
+          </object>
+        </child>
       </object>
     </child>
     <ui>
           <menuitem action="guide"/>
         </menu>
       </menubar>
+      <popup name="tray_menu">
+          <menuitem action="show_hide"/>
+          <menuitem action="queue_pause_menu"/>
+          <menuitem action="quit1"/>
+          <menuitem action="about"/>
+      </popup>
     </ui>
   </object>
   <object class="GtkListStore" id="device_list">
index 2534dc449dffc5e68fc1dc848770e784d0dee25f..6ff84ae890360a93ecbee966f790800ba4c1160c 100644 (file)
 #define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)
 #endif
 
+#if defined(_USE_APP_IND)
+#include <libappindicator/app-indicator.h>
+#endif
+
 #include <glib/gstdio.h>
 #include <gio/gio.h>
 #include "hb.h"
@@ -944,6 +948,22 @@ main (int argc, char *argv[])
 #else
        gtk_status_icon_set_tooltip(si, "HandBrake");
 #endif
+#if defined(_USE_APP_IND)
+       GtkUIManager * uim = GHB_OBJECT(ud->builder, "uimanager1");
+
+       GtkMenu *ai_menu = gtk_ui_manager_get_widget (uim, "/ui/tray_menu");
+       ud->ai = app_indicator_new("HandBrake", "hb-icon", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
+       app_indicator_set_menu( ud->ai, ai_menu );
+       app_indicator_set_label( ud->ai, "", "99.99%");
+       if (ghb_settings_get_boolean(ud->settings, "show_status"))
+       {
+               app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_ACTIVE );
+       }
+       else
+       {
+               app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_PASSIVE );
+       }
+#endif
 
        // Ugly hack to keep subtitle table from bouncing around as I change
        // which set of controls are visible
index 2f964037511ffe2dbadb915dfdf440c052a38f7c..d9d92beb1d3391b936b5684c62ae918b8fb931f8 100644 (file)
@@ -17,6 +17,9 @@
 #define _SETTINGS_H_
 
 #include <gtk/gtk.h>
+#if defined(_USE_APP_IND)
+#include <libappindicator/app-indicator.h>
+#endif
 
 #define GHB_WIDGET(b,n)        GTK_WIDGET(gtk_builder_get_object ((b), (n)))
 //#define GHB_WIDGET(b,n)      GTK_WIDGET(debug_get_object((b), (n)))
@@ -64,6 +67,9 @@ typedef struct
        gchar *appcast;
        gint appcast_len;
        GdkVisibilityState hb_visibility;
+#if defined(_USE_APP_IND)
+       AppIndicator *ai;
+#endif
 } signal_user_data_t;
 
 enum
index bda98e1061af0fc45599250812dcc22a6a9b6087..43df45eee29d5605c1df33cb539ca1c6cb2b96c2 100644 (file)
@@ -2,7 +2,7 @@ Source: handbrake
 Section: graphics
 Priority: optional
 Maintainer: John Stebbins <jstebbins.hb@gmail.com>
-Build-Depends: debhelper (>= 6), autotools-dev, libtool, libgudev-1.0-dev, intltool, autoconf, yasm (>= 0.7.0), libbz2-dev, zlib1g-dev, libwebkitgtk-dev, libnotify-dev, libgstreamer0.10-dev, libgstreamer-plugins-base0.10-dev, wget, subversion, python (>= 2.6)
+Build-Depends: debhelper (>= 6), autotools-dev, libtool, libgudev-1.0-dev, intltool, autoconf, yasm (>= 0.7.0), libbz2-dev, zlib1g-dev, libwebkitgtk-dev, libnotify-dev, libgstreamer0.10-dev, libgstreamer-plugins-base0.10-dev, wget, subversion, python (>= 2.6), libappindicator-dev
 Standards-Version: 3.8.4
 Homepage: http://www.handbrake.fr/