Commits

Alessio Caiazza committed 96d3af6

start new patch on default

  • Participants
  • Parent commits 1c178cd
  • Branches appindicator-0.1.9

Comments (0)

Files changed (5)

.hgpatchinfo/appindicator-0.1.9.dep

+1c178cdae6cbcf02bba942f1cdc8e4684f063c33

.hgpatchinfo/appindicator-0.1.9.desc

+This feature collapse tooltips and tray icon into an App Indicator.
 AM_CONDITIONAL(ENABLE_NOTIFY_SHARP, test "x$enable_notify_sharp" != "xno")
 AC_SUBST(NOTIFY_SHARP_LIBS)
 
+#
+# AppIndicator
+#
+APPINDICATOR_REQUIRED=0.0.7
+
+AC_ARG_ENABLE(appindicator,
+                        AS_HELP_STRING([--enable-appindicator[=@<:@no/auto/yes@:>@]],[Build support for application indicators ]),
+                        [enable_appindicator=$enableval],
+                        [enable_appindicator="auto"])
+
+if test x$enable_appindicator = xauto ; then
+        PKG_CHECK_EXISTS([appindicator-sharp-0.1 >= $APPINDICATOR_REQUIRED],
+                         enable_appindicator="yes",
+                         enable_appindicator="no")
+fi
+
+if test x$enable_appindicator = xyes ; then
+        PKG_CHECK_EXISTS([appindicator-sharp-0.1 >= $APPINDICATOR_REQUIRED],,
+                         AC_MSG_ERROR([appindicator-sharp-0.1 is not installed]))
+        PKG_CHECK_MODULES(APPINDICATOR_SHARP,
+                        appindicator-sharp-0.1 >= $APPINDICATOR_REQUIRED)
+        AC_SUBST(APPINDICATOR_SHARP_CFLAGS)
+        AC_SUBST(APPINDICATOR_SHARP_LIBS)
+        AC_DEFINE(ENABLE_APPINDICATOR_SHARP, 1, [Enable AppIndicator])
+fi
+AM_CONDITIONAL(ENABLE_APPINDICATOR_SHARP, test x"$enable_appindicator" = xyes)
+
+
 AC_ARG_ENABLE(debug,
 	AC_HELP_STRING([--enable-debug],
 		[Use 'Debug' Configuration [default=yes]]),
 	Debug build:       ${enable_debug}
 	Release build:     ${enable_release}
 	Notification:      ${enable_notify_sharp}
+	AppIndicator:      ${enable_appindicator}
 	Dummy Backend:     ${final_backend_dummy}
 	Evolution Backend: ${final_backend_eds}
 	ICECore Backend:   ${final_backend_icecore}

src/Application.cs

 #if ENABLE_NOTIFY_SHARP
 using Notifications;
 #endif
+#if ENABLE_APPINDICATOR_SHARP
+using AppIndicator;
+#endif
 using Tasque.Backends;
 
 namespace Tasque
 		private TaskGroupModel overdue_tasks, today_tasks, tomorrow_tasks;
 		private PreferencesDialog preferencesDialog;
 		private bool quietStart = false;
+#if ENABLE_APPINDICATOR_SHARP
+		private ApplicationIndicator indicator;
+		private MenuItem[] backendDependantEntry;
+		private MenuItem indicatorStatusLine;
+#endif
 		
 		private DateTime currentDay = DateTime.Today;
 		
 			// Discover all available backends
 			LoadAvailableBackends ();
 
+#if ENABLE_APPINDICATOR_SHARP
+			SetupAppIndicator();
+#endif
+
 			GLib.Idle.Add(InitializeIdle);
 			GLib.Timeout.Add (60000, CheckForDaySwitch);
 		}
 				
 			// Initialize the new backend
 			this.backend = value;
+#if ENABLE_APPINDICATOR_SHARP
+			//disable some appindicator entries and re-enable them when 
+			// the new backend will be initialized
+			UpdateAppIndicator();
+			if(this.backend != null)
+				this.backend.BackendInitialized += UpdateAppIndicator;
+#endif
 			if (this.backend == null) {
 				RefreshTrayIconTooltip ();
 				return;
 					Application.Backend = availableBackends [backendTypeString];
 				}
 			}
-			
+
+#if !ENABLE_APPINDICATOR_SHARP
 			SetupTrayIcon ();
+#endif
 			
 			if (backend == null) {
 				// Pop open the preferences dialog so the user can choose a
 		
 		private void RefreshTrayIconTooltip ()
 		{
+#if !ENABLE_APPINDICATOR_SHARP
 			if (trayIcon == null) {
 				return;
 			}
+			trayIcon.Tooltip = GenerateTooltip();
+#else
+			if(indicatorStatusLine != null)
+				((Label)indicatorStatusLine.Child).Text = GenerateTooltip();
+#endif
+		}
 
+		private string GenerateTooltip()
+		{
 			StringBuilder sb = new StringBuilder ();
 			if (overdue_tasks != null) {
 				int count =  overdue_tasks.IterNChildren ();
 
 			if (sb.Length == 0) {
 				// Translators: This is the status icon's tooltip. When no tasks are overdue, due today, or due tomorrow, it displays this fun message
-				trayIcon.Tooltip = Catalog.GetString ("Tasque Rocks");
-				return;
+				return Catalog.GetString ("Tasque Rocks");
 			}
 
-			trayIcon.Tooltip = sb.ToString ().TrimEnd ('\n');
+			return sb.ToString ().TrimEnd ('\n');
 		}
 
 
 			uiManager.AddUiFromString (menuXml);
 			uiManager.InsertActionGroup (trayActionGroup, 0);
 		}
+
+#if ENABLE_APPINDICATOR_SHARP
+		private void SetupAppIndicator()
+		{
+			// NewTask and Refresh depends on backend status
+			const int BackendDependantItems = 2;
+
+			indicator =
+				new ApplicationIndicator ("tasque", "tasque-24", Category.ApplicationStatus);
+
+			indicator.Status = AppIndicator.Status.Active;
+
+			backendDependantEntry = new MenuItem[BackendDependantItems];
+			int backendDependantIndex = 0;
+
+			indicator.Menu = new Menu();
+
+			var itm = new MenuItem("Tasque");
+			itm.Activated += (o,e) => TaskWindow.ToggleWindowVisible();
+			itm.Show();
+			indicator.Menu.Append(itm);
+
+			//mimic the tooltip with a non sensitive MenuItem
+			indicator.Menu.Append(new SeparatorMenuItem());
+			indicatorStatusLine = new MenuItem("tooltip");
+			indicatorStatusLine.Sensitive = false;
+			indicator.Menu.Append(indicatorStatusLine);
+			indicator.Menu.Append(new SeparatorMenuItem());
+
+			backendDependantEntry[backendDependantIndex++] =
+				AddActionToIndicator(uiManager.GetAction ("/TrayIconMenu/NewTaskAction"));
+			indicator.Menu.Append(new SeparatorMenuItem());
+
+			AddActionToIndicator(uiManager.GetAction ("/TrayIconMenu/PreferencesAction"));
+			AddActionToIndicator(uiManager.GetAction ("/TrayIconMenu/AboutAction"));
+			indicator.Menu.Append(new SeparatorMenuItem());
+
+			backendDependantEntry[backendDependantIndex++] =
+				AddActionToIndicator(uiManager.GetAction ("/TrayIconMenu/RefreshAction"));
+			AddActionToIndicator(uiManager.GetAction ("/TrayIconMenu/QuitAction"));
+
+			UpdateAppIndicator();
+			RefreshTrayIconTooltip();
+
+			indicator.Menu.ShowAll();
+		}
+
+
+		/// <summary>
+		/// Connect AppIndicator menu item with a TrayIcon action.
+		/// The menu item label and action are the same of the action.
+		/// </summary>
+		/// <param name="action">
+		/// The <see cref="Gtk.Action"/> to be added
+		/// </param>
+		/// <returns>
+		/// A <see cref="MenuItem"/> reference to the newly created entry
+		/// </returns>
+		private MenuItem AddActionToIndicator(Gtk.Action action)
+		{
+			var itm = new MenuItem(action.Label);
+			itm.Activated += (o,e) => action.Activate();
+			itm.Show();
+			indicator.Menu.Append(itm);
+
+			return itm;
+		}
+
+		/// <summary>
+		/// Enable/disable AppIndicator menu items based on Backend status
+		/// </summary>
+		private void UpdateAppIndicator()
+		{
+			bool backendItemsSensitive = (backend != null && backend.Initialized);
+			foreach(var menuEntry in backendDependantEntry)
+				menuEntry.Sensitive = backendItemsSensitive;
+		}
+#endif
 	}
 }
 NOTIFY_SHARP_CSFLAGS = -define:ENABLE_NOTIFY_SHARP
 endif
 
+if ENABLE_APPINDICATOR_SHARP
+APPINDICATOR_CSFLAGS = -define:ENABLE_APPINDICATOR_SHARP
+endif
+
 if ENABLE_BACKEND_DUMMY
 DUMMY_CSFILES = \
 	$(srcdir)/Backends/Dummy/*.cs
 	$(GNOME_SHARP_20_LIBS) \
 	$(GTK_DOTNET_20_LIBS) \
 	$(NOTIFY_SHARP_LIBS) \
+	$(APPINDICATOR_SHARP_LIBS) \
 	$(NDESK_DBUS_10_LIBS) \
 	$(NDESK_DBUS_GLIB_10_LIBS) \
 	$(ICE_DESKTOP_LIBS) \
 	$(EVOLUTION_SHARP_LIBS)
 
 $(TARGET): $(CSFILES) Defines.cs
-	$(CSC) -unsafe -out:$@ $(CSFLAGS) $(NOTIFY_SHARP_CSFLAGS) $^ $(ASSEMBLIES) $(RESOURCES)
+	$(CSC) -unsafe -out:$@ $(CSFLAGS) $(NOTIFY_SHARP_CSFLAGS) $(APPINDICATOR_CSFLAGS) $^ $(ASSEMBLIES) $(RESOURCES)
 
 tasquelibdir = $(libdir)/tasque
 tasquelib_DATA = $(TARGET) $(TARGET).config $(TARGET).mdb