[tasque/viewmodel: 56/78] WiP
- From: Antonius Riha <antoniusri src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tasque/viewmodel: 56/78] WiP
- Date: Wed, 29 Aug 2012 18:39:22 +0000 (UTC)
commit 36fc6c166074546993b1d3afdb24901417a98b3f
Author: Antonius Riha <antoniusriha gmail com>
Date: Tue Aug 7 13:43:40 2012 +0200
WiP
src/Tasque.Gtk/Application.cs | 84 ----------------
src/Tasque.Gtk/GtkTrayBase.cs | 38 ++++++++
src/libtasqueui/Legacy/MainWindowModel.cs | 106 ++++++++++++---------
src/libtasqueui/Legacy/MainWindowTopPanelModel.cs | 4 +-
src/libtasqueui/Legacy/NativeApplication.cs | 90 ++++++++++++++++-
src/libtasqueui/Legacy/TrayModel.cs | 25 +++--
6 files changed, 200 insertions(+), 147 deletions(-)
---
diff --git a/src/Tasque.Gtk/Application.cs b/src/Tasque.Gtk/Application.cs
index bfe049d..0568293 100644
--- a/src/Tasque.Gtk/Application.cs
+++ b/src/Tasque.Gtk/Application.cs
@@ -102,49 +102,6 @@ namespace Tasque
get { return Application.Instance.preferences; }
}
- private void SetBackend (Backend value)
- {
- bool changingBackend = false;
- if (this.backend != null) {
- UnhookFromTooltipTaskGroupModels ();
- changingBackend = true;
- // Cleanup the old backend
- try {
- Debug.WriteLine ("Cleaning up backend: {0}",
- this.backend.Name);
- this.backend.Cleanup ();
- } catch (Exception e) {
- Trace.TraceWarning ("Exception cleaning up '{0}': {1}",
- this.backend.Name,
- e);
- }
- }
-
- // Initialize the new backend
- this.backend = value;
- if (this.backend == null) {
- RefreshTrayIconTooltip ();
- return;
- }
-
- Trace.TraceInformation ("Using backend: {0} ({1})",
- this.backend.Name,
- this.backend.GetType ().ToString ());
- this.backend.Initialize();
-
- if (!changingBackend) {
- TaskWindow.Reinitialize (!this.quietStart);
- } else {
- TaskWindow.Reinitialize (true);
- }
-
- RebuildTooltipTaskGroupModels ();
- RefreshTrayIconTooltip ();
-
- Debug.WriteLine("Configuration status: {0}",
- this.backend.Configured.ToString());
- }
-
private bool InitializeIdle()
{
if (customBackend != null) {
@@ -270,47 +227,6 @@ namespace Tasque
model.CollectionChanged += OnTooltipModelChanged;
}
}
-
- private void RefreshTrayIconTooltip ()
- {
- if (trayIcon == null) {
- return;
- }
-
- StringBuilder sb = new StringBuilder ();
- if (overdue_tasks != null) {
- int count = overdue_tasks.Count;
-
- if (count > 0) {
- sb.Append (String.Format (Catalog.GetPluralString ("{0} task is Overdue\n", "{0} tasks are Overdue\n", count), count));
- }
- }
-
- if (today_tasks != null) {
- int count = today_tasks.Count;
-
- if (count > 0) {
- sb.Append (String.Format (Catalog.GetPluralString ("{0} task for Today\n", "{0} tasks for Today\n", count), count));
- }
- }
-
- if (tomorrow_tasks != null) {
- int count = tomorrow_tasks.Count;
-
- if (count > 0) {
- sb.Append (String.Format (Catalog.GetPluralString ("{0} task for Tomorrow\n", "{0} tasks for Tomorrow\n", count), count));
- }
- }
-
- 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;
- }
-
- trayIcon.Tooltip = sb.ToString ().TrimEnd ('\n');
- }
-
private void OnPreferences (object sender, EventArgs args)
{
diff --git a/src/Tasque.Gtk/GtkTrayBase.cs b/src/Tasque.Gtk/GtkTrayBase.cs
index 54ec74c..4f337ad 100644
--- a/src/Tasque.Gtk/GtkTrayBase.cs
+++ b/src/Tasque.Gtk/GtkTrayBase.cs
@@ -27,6 +27,7 @@ using System;
using Mono.Unix;
using Gtk;
using Tasque.UIModel.Legacy;
+using System.Text;
namespace Tasque
{
@@ -86,6 +87,43 @@ namespace Tasque
uiManager.InsertActionGroup (trayActionGroup, 0);
}
+
+ void RefreshTrayIconTooltip ()
+ {
+ var sb = new StringBuilder ();
+ if (overdue_tasks != null) {
+ int count = overdue_tasks.Count;
+
+ if (count > 0) {
+ sb.Append (String.Format (Catalog.GetPluralString ("{0} task is Overdue\n", "{0} tasks are Overdue\n", count), count));
+ }
+ }
+
+ if (today_tasks != null) {
+ int count = today_tasks.Count;
+
+ if (count > 0) {
+ sb.Append (String.Format (Catalog.GetPluralString ("{0} task for Today\n", "{0} tasks for Today\n", count), count));
+ }
+ }
+
+ if (tomorrow_tasks != null) {
+ int count = tomorrow_tasks.Count;
+
+ if (count > 0) {
+ sb.Append (String.Format (Catalog.GetPluralString ("{0} task for Tomorrow\n", "{0} tasks for Tomorrow\n", count), count));
+ }
+ }
+
+ 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;
+ }
+
+ trayIcon.Tooltip = sb.ToString ().TrimEnd ('\n');
+ }
+
UIManager uiManager;
const string MenuXml = @"
<ui>
diff --git a/src/libtasqueui/Legacy/MainWindowModel.cs b/src/libtasqueui/Legacy/MainWindowModel.cs
index 55491ab..5b8afbe 100644
--- a/src/libtasqueui/Legacy/MainWindowModel.cs
+++ b/src/libtasqueui/Legacy/MainWindowModel.cs
@@ -24,8 +24,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
-using CollectionTransforms;
using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using CollectionTransforms;
+using CrossCommand;
namespace Tasque.UIModel.Legacy
{
@@ -40,7 +42,6 @@ namespace Tasque.UIModel.Legacy
Preferences = preferences;
showCompletedTasks = preferences.GetBool (Preferences.ShowCompletedTasksKey);
- completionDateRange = GetCompletionDateRange ();
preferences.SettingChanged += HandleSettingChanged;
Tasks = new ListCollectionView<Task> (Backend.Tasks);
@@ -52,7 +53,22 @@ namespace Tasque.UIModel.Legacy
topPanel = new MainWindowTopPanelModel (this);
}
-
+
+ public ReadOnlyObservableCollection<TaskGroupModel> Groups {
+ get {
+ if (groups == null) {
+ privateGroups = new ObservableCollection<TaskGroupModel> ();
+ foreach (CollectionViewGroup<Task> group in Tasks.Groups)
+ privateGroups.Add (CreateGroupModel (group));
+
+ groups = new ReadOnlyObservableCollection<TaskGroupModel> (privateGroups);
+ ((INotifyCollectionChanged)Tasks.Groups).CollectionChanged += HandleGroupsChanged;
+ }
+
+ return groups;
+ }
+ }
+
void HandleSettingChanged (Preferences preferences, string settingKey)
{
switch (settingKey) {
@@ -61,19 +77,17 @@ namespace Tasque.UIModel.Legacy
Tasks.Refresh ();
OnPropertyChanged ("ShowCompletedTasks");
break;
- case Preferences.CompletedTasksRange:
- completionDateRange = GetCompletionDateRange ();
- Tasks.Refresh ();
- OnPropertyChanged ("CompletionDateRange");
- break;
}
}
- public CompletionDateRange CompletionDateRange {
- get { return completionDateRange; }
+ bool isVisible;
+ public bool IsVisible {
+ get { return isVisible; }
set {
- if (value != completionDateRange)
- Preferences.Set (Preferences.CompletedTasksRange, value.ToString ());
+ if (value != isVisible) {
+ isVisible = value;
+ OnPropertyChanged ("IsVisible");
+ }
}
}
@@ -98,30 +112,10 @@ namespace Tasque.UIModel.Legacy
}
public bool ShowCompletedTasks { get { return showCompletedTasks; } }
-
- public ReadOnlyObservableCollection<Task> OverdueTasks {
- get { throw new NotImplementedException (); }
- }
-
- public ReadOnlyObservableCollection<Task> TodayTasks {
- get { throw new NotImplementedException (); }
- }
-
- public ReadOnlyObservableCollection<Task> TomorrowTasks {
- get { throw new NotImplementedException (); }
- }
-
- public ReadOnlyObservableCollection<Task> FutureTasks {
- get { throw new NotImplementedException (); }
- }
-
- public ReadOnlyObservableCollection<Task> CompletedTasks {
- get { throw new NotImplementedException (); }
- }
- public UICommand Hide { get { return hide ?? (hide = new UICommand ()); } }
+ public RelayCommand Hide { get { return hide ?? (hide = new RelayCommand ()); } }
- public UICommand Show { get { return show ?? (show = new UICommand ()); } }
+ public RelayCommand Show { get { return show ?? (show = new RelayCommand ()); } }
public Point Position { get; set; }
@@ -153,8 +147,9 @@ namespace Tasque.UIModel.Legacy
if (!showCompletedTasks)
return false;
- // account for completion date range setting
- var complDateRange = CompletionDateRange;
+ // account for completion date range setting.
+ //NOTE: the following code fails if showCompletedTasks is true. This is not good class design
+ var complDateRange = completedTaskGroupModel.CompletionDateRange;
switch (complDateRange) {
case CompletionDateRange.All:
return true;
@@ -171,10 +166,30 @@ namespace Tasque.UIModel.Legacy
}
}
- void GetCompletionDateRange ()
+ TaskGroupModel CreateGroupModel (CollectionViewGroup<Task> group)
{
- return (CompletionDateRange)Enum.Parse (typeof (CompletionDateRange),
- Preferences.Get (Preferences.CompletedTasksRange));
+ TaskGroupModel groupModel;
+ var groupName = (TaskGroupName)group.Name;
+ if (groupName == TaskGroupName.Completed)
+ groupModel = new CompletedTaskGroupModel (group.Items, Preferences);
+ else
+ groupModel = new TaskGroupModel (groupName, group.Items);
+ return groupModel;
+ }
+
+ void HandleGroupsChanged (object sender, NotifyCollectionChangedEventArgs e)
+ {
+ switch (e.Action) {
+ case NotifyCollectionChangedAction.Add:
+ var newGroup = (CollectionViewGroup<Task>)e.NewItems [0];
+ var newIndex = e.NewStartingIndex < 0 ? privateGroups.Count : e.NewStartingIndex;
+ privateGroups.Insert (newIndex, CreateGroupModel (newGroup));
+ break;
+ case NotifyCollectionChangedAction.Remove:
+ var oldIndex = e.OldStartingIndex < 0 ? privateGroups.Count - 1 : e.OldStartingIndex;
+ privateGroups.RemoveAt (oldIndex);
+ break;
+ }
}
void UpdateCompletionDateRangeCompareDates ()
@@ -186,10 +201,7 @@ namespace Tasque.UIModel.Legacy
yesterday = today.AddDays (-1);
}
- DateTime aYearAgo;
- DateTime aMonthAgo;
- DateTime aWeekAgo;
- DateTime yesterday;
+ DateTime aYearAgo, aMonthAgo, aWeekAgo, yesterday;
string status;
@@ -202,10 +214,12 @@ namespace Tasque.UIModel.Legacy
Task selectedTask;
- UICommand hide;
- UICommand show;
+ RelayCommand hide, show;
bool showCompletedTasks;
- CompletionDateRange completionDateRange;
+ CompletedTaskGroupModel completedTaskGroupModel;
+
+ ObservableCollection<TaskGroupModel> privateGroups;
+ ReadOnlyObservableCollection<TaskGroupModel> groups;
}
}
diff --git a/src/libtasqueui/Legacy/MainWindowTopPanelModel.cs b/src/libtasqueui/Legacy/MainWindowTopPanelModel.cs
index 4705112..2fce6fb 100644
--- a/src/libtasqueui/Legacy/MainWindowTopPanelModel.cs
+++ b/src/libtasqueui/Legacy/MainWindowTopPanelModel.cs
@@ -34,7 +34,7 @@ namespace Tasque.UIModel.Legacy
{
tasks = mainWindowModel.Tasks;
- Categories = new ReadOnlySortedNotifyCollection<Category> (mainWindowModel.Backend.Categories);
+ Categories = new ReadOnlyObservableSet<Category> (mainWindowModel.Backend.Categories);
preferences = mainWindowModel.Preferences;
selectedCategory = GetSelectedCategory ();
@@ -54,7 +54,7 @@ namespace Tasque.UIModel.Legacy
}
}
- public ReadOnlySortedNotifyCollection<Category> Categories { get; private set; }
+ public ReadOnlyObservableSet<Category> Categories { get; private set; }
public Category SelectedCategory {
get { return selectedCategory; }
diff --git a/src/libtasqueui/Legacy/NativeApplication.cs b/src/libtasqueui/Legacy/NativeApplication.cs
index 8afc2fa..186db4e 100644
--- a/src/libtasqueui/Legacy/NativeApplication.cs
+++ b/src/libtasqueui/Legacy/NativeApplication.cs
@@ -35,8 +35,8 @@ namespace Tasque.UIModel.Legacy
{
public abstract class NativeApplication : IDisposable
{
- protected NativeApplication ()
- : this (Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), "tasque")) {}
+ protected NativeApplication () : this (Path.Combine (Environment.GetFolderPath (
+ Environment.SpecialFolder.ApplicationData), "tasque")) {}
protected NativeApplication (string confDir)
{
@@ -48,7 +48,7 @@ namespace Tasque.UIModel.Legacy
Directory.CreateDirectory (confDir);
}
- public Backend CurrentBackend { get; }
+ public Backend CurrentBackend { get; private set; }
public ReadOnlyCollection<Backend> AvailableBackends { get; }
@@ -92,8 +92,40 @@ namespace Tasque.UIModel.Legacy
protected virtual void OnInitialize () {}
- public virtual void InitializeIdle () {}
+ public virtual void InitializeIdle ()
+ {
+ if (customBackend != null)
+ CurrentBackend = customBackend;
+ else {
+ // Check to see if the user has a preference of which backend
+ // to use. If so, use it, otherwise, pop open the preferences
+ // dialog so they can choose one.
+ string backendTypeString = preferences.Get (Preferences.CurrentBackend);
+ Debug.WriteLine ("CurrentBackend specified in Preferences: {0}", backendTypeString);
+ if (backendTypeString != null && availableBackends.ContainsKey (backendTypeString))
+ CurrentBackend = availableBackends [backendTypeString];
+ }
+
+ SetupTray (new TrayModel ());
+
+ if (CurrentBackend == null) {
+ // Pop open the preferences dialog so the user can choose a
+ // backend service to use.
+ Application.ShowPreferences ();
+ } else if (!quietStart) {
+ TaskWindow.ShowWindow ();
+ }
+ if (backend == null || !backend.Configured){
+ GLib.Timeout.Add(1000, new GLib.TimeoutHandler(RetryBackend));
+ }
+ nativeApp.InitializeIdle ();
+
+ return false;
+ }
+
+ protected abstract void SetupTray (TrayModel trayModel);
+
protected virtual void OnExit (int exitCode) {}
public virtual void OpenUrlInBrowser (string url)
@@ -179,14 +211,15 @@ namespace Tasque.UIModel.Legacy
try {
types = asm.GetTypes ();
} catch (Exception e) {
- Trace.TraceWarning ("Exception reading types from assembly '{0}': {1}", asm.ToString (), e.Message);
+ Trace.TraceWarning ("Exception reading types from assembly '{0}': {1}",
+ asm.ToString (), e.Message);
return backends;
}
foreach (var type in types) {
if (!type.IsClass)
continue; // Skip non-class types
- if (type.GetInterface ("Tasque.Backends.IBackend") == null)
+ if (type.GetType ("Tasque.Backend") == null)
continue;
Debug.WriteLine ("Found Available Backend: {0}", type.ToString ());
@@ -234,6 +267,49 @@ namespace Tasque.UIModel.Legacy
}
}
+ void SetBackend (Backend value)
+ {
+ bool changingBackend = false;
+ if (this.backend != null) {
+ UnhookFromTooltipTaskGroupModels ();
+ changingBackend = true;
+ // Cleanup the old backend
+ try {
+ Debug.WriteLine ("Cleaning up backend: {0}",
+ this.backend.Name);
+ this.backend.Cleanup ();
+ } catch (Exception e) {
+ Trace.TraceWarning ("Exception cleaning up '{0}': {1}",
+ this.backend.Name,
+ e);
+ }
+ }
+
+ // Initialize the new backend
+ this.backend = value;
+ if (this.backend == null) {
+ RefreshTrayIconTooltip ();
+ return;
+ }
+
+ Trace.TraceInformation ("Using backend: {0} ({1})",
+ this.backend.Name,
+ this.backend.GetType ().ToString ());
+ this.backend.Initialize();
+
+ if (!changingBackend) {
+ TaskWindow.Reinitialize (!this.quietStart);
+ } else {
+ TaskWindow.Reinitialize (true);
+ }
+
+ RebuildTooltipTaskGroupModels ();
+ RefreshTrayIconTooltip ();
+
+ Debug.WriteLine("Configuration status: {0}",
+ this.backend.Configured.ToString());
+ }
+
void SetCustomBackend ()
{
// See if a specific backend is specified
@@ -257,5 +333,7 @@ namespace Tasque.UIModel.Legacy
bool quietStart;
Dictionary<string, Backend> availableBackends;
+
+ TrayModel tray;
}
}
diff --git a/src/libtasqueui/Legacy/TrayModel.cs b/src/libtasqueui/Legacy/TrayModel.cs
index d5234e9..2dd3aa6 100644
--- a/src/libtasqueui/Legacy/TrayModel.cs
+++ b/src/libtasqueui/Legacy/TrayModel.cs
@@ -24,29 +24,36 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
+using CrossCommand;
namespace Tasque.UIModel.Legacy
{
public class TrayModel : ViewModelBase
{
- public TrayModel ()
+ public TrayModel (NativeApplication application)
{
+ if (application == null)
+ throw new ArgumentNullException ("application");
+
+
}
- public string IconName { get; private set; }
+ public string IconName { get { return "tasque"; } }
- public bool IsTaskWindowVisible { get; private set; }
+ public bool IsTaskWindowVisible { get { return application.MainWindowModel.IsVisible; } }
- public UICommand NewTask { get { throw new NotImplementedException (); } }
+ public ICommand NewTask { get { throw new NotImplementedException (); } }
- public UICommand Quit { get { throw new NotImplementedException (); } }
+ public ICommand Quit { get { throw new NotImplementedException (); } }
- public UICommand Refresh { get { throw new NotImplementedException (); } }
+ public ICommand Refresh { get { throw new NotImplementedException (); } }
- public UICommand ShowAbout { get { throw new NotImplementedException (); } }
+ public ICommand ShowAbout { get { throw new NotImplementedException (); } }
- public UICommand ShowPreferences { get { throw new NotImplementedException (); } }
+ public ICommand ShowPreferences { get { throw new NotImplementedException (); } }
- public UICommand ToggleTaskWindow { get { throw new NotImplementedException (); } }
+ public ICommand ToggleTaskWindow { get { throw new NotImplementedException (); } }
+
+ NativeApplication application;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]