[tasque] [tasque] Add support for Ubuntu/Unity's appindicator



commit 40e6b22c2bd50ba26d9b432e7d81c5cd264c64a6
Author: Antonius Riha <antoniusriha gmail com>
Date:   Wed Aug 22 19:51:52 2012 +0200

    [tasque] Add support for Ubuntu/Unity's appindicator
    
    Tasque decides at runtime based on the environment variable
    DESKTOP_SESSION which tray to use.
    
    AppIndicator requires appindicator0.1-sharp. It is therefore only compiled
    if that dependency is met. Checks have been added to configure.ac.
    Also appindicator build is enabled by default and must be
    explicitly switched off via --enable-appindicator=no. The Gtk.StatusIcon
    tray is always compiled.

 configure.ac            |   23 +++++++++++++++++++++
 src/AppIndicatorTray.cs |   50 +++++++++++++++++++++++++++++++++++++++++++++++
 src/GtkTray.cs          |   28 ++++++++++++++++++++++++-
 src/Makefile.am         |   13 ++++++++++-
 tasque.csproj           |    5 ++++
 5 files changed, 115 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f2dcc04..ae2dc05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,6 +52,27 @@ PKG_CHECK_MODULES(NOTIFY_SHARP, notify-sharp, enable_notify_sharp="yes", enable_
 AM_CONDITIONAL(ENABLE_NOTIFY_SHARP, test "x$enable_notify_sharp" != "xno")
 AC_SUBST(NOTIFY_SHARP_LIBS)
 
+#
+# AppIndicator
+# AppIndicator is enabled by default because it is an absolute requirement for the systray to
+# work on Ubuntu/Unity. If AppIndicator is not available on a given system it must be switched off.
+#
+appindicator=yes
+AC_ARG_ENABLE(appindicator,
+	AC_HELP_STRING([--enable-appindicator],
+		[Enables the use of Ubuntu/Unity's Application Indicator as systray icon [default=yes]]),
+		appindicator=$enableval, )
+if test "x$appindicator" != "xno" ; then
+	PKG_CHECK_MODULES([APPINDICATOR_SHARP], [appindicator-sharp-0.1], appindicator="yes", appindicator="no")
+	if test "$appindicator" == "no" ; then
+		AC_MSG_ERROR([Please install appindicator-sharp, if you want systray support on Ubuntu/Unity. \
+If appindicator-sharp is not available on your system, you probably won't need it. To disable \
+appindicator pass --enable-appindicator=no to configure."])
+	fi
+fi
+AM_CONDITIONAL(ENABLE_APPINDICATOR, test "x$appindicator" != "xno")
+
+
 AC_ARG_ENABLE(debug,
 	AC_HELP_STRING([--enable-debug],
 		[Use 'Debug' Configuration [default=yes]]),
@@ -236,6 +257,7 @@ fi
 # Define ENABLE_BACKEND_RTM here so it only gets defined once
 AM_CONDITIONAL(ENABLE_BACKEND_RTM, test "x$final_backend_rtm" != "xno")
 
+
 ### Begin GAC tool ###
 
 AC_PATH_PROG(GACUTIL, gacutil, no)
@@ -282,5 +304,6 @@ Configuration:
 	RTM Backend:       ${final_backend_rtm}
 	SQLite Backend:    ${final_backend_sqlite}
 	Hiveminder Backend: ${final_backend_hiveminder}
+	AppIndicator:      ${appindicator}
 "
 
diff --git a/src/AppIndicatorTray.cs b/src/AppIndicatorTray.cs
new file mode 100644
index 0000000..9bc217b
--- /dev/null
+++ b/src/AppIndicatorTray.cs
@@ -0,0 +1,50 @@
+// 
+// AppIndicatorTray.cs
+//  
+// Author:
+//       Antonius Riha <antoniusriha gmail com>
+// 
+// Copyright (c) 2012 Antonius Riha
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using Gtk;
+using AppIndicator;
+
+namespace Tasque
+{
+	public class AppIndicatorTray : GtkTray
+	{
+		public AppIndicatorTray ()
+		{
+			appIndicator = new ApplicationIndicator ("TasqueTray", IconName, Category.ApplicationStatus);
+			appIndicator.Status = Status.Active;
+
+			var menu = Menu;
+			var toggleTaskWindowMenuItem = new MenuItem ();
+			ToggleTaskWindowAction.ConnectProxy (toggleTaskWindowMenuItem);
+			menu.Insert (toggleTaskWindowMenuItem, 0);
+			menu.Insert (new SeparatorMenuItem (), 1);
+			menu.ShowAll ();
+			
+			appIndicator.Menu = menu;
+		}
+
+		ApplicationIndicator appIndicator;
+	}
+}
diff --git a/src/GtkTray.cs b/src/GtkTray.cs
index 9d7a596..bc32f89 100644
--- a/src/GtkTray.cs
+++ b/src/GtkTray.cs
@@ -35,7 +35,26 @@ namespace Tasque
 	{
 		public static GtkTray CreateTray ()
 		{
-			return new StatusIconTray ();
+			var desktopSession = Environment.GetEnvironmentVariable ("DESKTOP_SESSION");
+			GtkTray tray;
+			switch (desktopSession) {
+			case "ubuntu":
+				tray = new AppIndicatorTray ();
+				break;
+			case "ubuntu-2d":
+				tray = new AppIndicatorTray ();
+				break;
+			case "gnome-classic":
+				tray = new AppIndicatorTray ();
+				break;
+			case "gnome-fallback":
+				tray = new AppIndicatorTray ();
+				break;
+			default:
+				tray = new StatusIconTray ();
+				break;
+			}
+			return tray;
 		}
 
 		protected GtkTray ()
@@ -56,7 +75,9 @@ namespace Tasque
 		
 		public void RefreshTrayIconTooltip ()
 		{
+			var oldTooltip = Tooltip;
 			var sb = new StringBuilder ();
+			
 			var overdueTasks = Application.Instance.OverdueTasks;
 			if (overdueTasks != null) {
 				int count = overdueTasks.IterNChildren ();
@@ -91,9 +112,12 @@ namespace Tasque
 			}
 
 			Tooltip = sb.ToString ().TrimEnd ('\n');
+			
+			if (Tooltip != oldTooltip)
+				OnTooltipChanged ();
 		}
 
-		protected string IconName { get { return "tasque-24"; } }
+		protected string IconName { get { return "tasque"; } }
 		
 		protected Menu Menu {
 			get {
diff --git a/src/Makefile.am b/src/Makefile.am
index 7e47f0d..b79c4de 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,6 +58,12 @@ else
 HIVEMINDER_CSFILES =
 endif
 
+if ENABLE_APPINDICATOR
+APPINDICATOR_CSFILES = $(srcdir)/AppIndicatorTray.cs
+else
+APPINDICATOR_CSFILES =
+endif
+
 CSFILES = \
 	$(srcdir)/AbstractTask.cs \
 	$(srcdir)/AllCategory.cs \
@@ -96,7 +102,9 @@ CSFILES = \
 	\
 	$(EDS_CSFILES) \
 	\
-	$(HIVEMINDER_CSFILES)
+	$(HIVEMINDER_CSFILES) \
+	\
+	$(APPINDICATOR_CSFILES)
 
 TASQUEDLL_CSFILES = \
 	$(srcdir)/libtasque/DateFormatterFactory.cs \
@@ -162,7 +170,8 @@ ASSEMBLIES =  \
 	$(NDESK_DBUS_GLIB_10_LIBS) \
 	$(ICE_DESKTOP_LIBS) \
 	$(SQLITE_LIBS) \
-	$(EVOLUTION_SHARP_LIBS)
+	$(EVOLUTION_SHARP_LIBS) \
+	$(APPINDICATOR_SHARP_LIBS)
 
 $(TARGET): $(CSFILES) Defines.cs
 	$(CSC) -unsafe -out:$@ $(CSFLAGS) $(NOTIFY_SHARP_CSFLAGS) $^ $(ASSEMBLIES) $(RESOURCES)
diff --git a/tasque.csproj b/tasque.csproj
index 098f7c0..3ebe719 100644
--- a/tasque.csproj
+++ b/tasque.csproj
@@ -58,6 +58,10 @@
     <Reference Include="Mono.Data.Sqlite">
       <HintPath>winbin\Mono.Data.Sqlite.dll</HintPath>
     </Reference>
+    <Reference Include="appindicator-sharp, Version=0.2.0.0, Culture=neutral, PublicKeyToken=bcae265d1c7ab4c2">
+      <Private>False</Private>
+      <Package>appindicator-sharp-0.1</Package>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <None Include="data\images\clock-16-0.svg" />
@@ -68,6 +72,7 @@
     <Compile Include="src\Defines.cs" />
     <Compile Include="src\GtkTray.cs" />
     <Compile Include="src\StatusIconTray.cs" />
+    <Compile Include="src\AppIndicatorTray.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="data\images\clock-16-0.png" />



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