[tasque/viewmodel: 52/78] Implemented TaskGroupModel as ViewModel
- From: Antonius Riha <antoniusri src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tasque/viewmodel: 52/78] Implemented TaskGroupModel as ViewModel
- Date: Wed, 29 Aug 2012 18:39:02 +0000 (UTC)
commit 625a9ca5b8a51cf570a2e0653a2c72e73c3752e6
Author: Antonius Riha <antoniusriha gmail com>
Date: Mon Aug 6 23:01:10 2012 +0200
Implemented TaskGroupModel as ViewModel
* Moved TaskGroupModel and CompletedTaskGroupModel to Legacy
namespace
* Reimplemented them as ViewModel
* Renamed enum TaskGroup to TaskGroupName
* Created two ValueConverters: CompletionDateRangeConverter and
TaskGroupNameConverter, which convert the enum values to strings
* Applied converters in TaskGroupModel and CompletedTaskGroupModel.
src/libtasqueui/CompletedTaskGroupModel.cs | 79 -------------
src/libtasqueui/Legacy/CompletedTaskGroupModel.cs | 103 ++++++++++++++++
.../Legacy/CompletionDateRangeConverter.cs | 62 ++++++++++
src/libtasqueui/Legacy/TaskGroupConverter.cs | 10 +-
src/libtasqueui/Legacy/TaskGroupModel.cs | 47 ++++++++
src/libtasqueui/Legacy/TaskGroupName.cs | 37 ++++++
src/libtasqueui/Legacy/TaskGroupNameConverter.cs | 62 ++++++++++
src/libtasqueui/TaskGroupModel.cs | 124 --------------------
src/libtasqueui/libtasqueui.csproj | 8 +-
9 files changed, 321 insertions(+), 211 deletions(-)
---
diff --git a/src/libtasqueui/Legacy/CompletedTaskGroupModel.cs b/src/libtasqueui/Legacy/CompletedTaskGroupModel.cs
new file mode 100644
index 0000000..88b8cb3
--- /dev/null
+++ b/src/libtasqueui/Legacy/CompletedTaskGroupModel.cs
@@ -0,0 +1,103 @@
+//
+// CompletedTaskGroupModel.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 System;
+using System.Collections.ObjectModel;
+using System.Globalization;
+using CollectionTransforms;
+
+namespace Tasque.UIModel.Legacy
+{
+ public class CompletedTaskGroupModel : TaskGroupModel, IValueConverter<CompletionDateRange, string>
+ {
+ public CompletedTaskGroupModel (ReadOnlyObservableCollection<Task> tasks,
+ Preferences preferences) : base (TaskGroupName.Completed, tasks)
+ {
+ if (preferences == null)
+ throw new ArgumentNullException ("preferences");
+ this.preferences = preferences;
+ completionDateRange = GetComplDateRangeFromPrefs ();
+ preferences.SettingChanged += HandleSettingChanged;
+
+ complDateRangeConverter = new CompletionDateRangeConverter ();
+ }
+
+ public CompletionDateRange CompletionDateRange {
+ get { return completionDateRange; }
+ set {
+ if (value != completionDateRange) {
+ completionDateRange = value;
+ preferences.Set (Preferences.CompletedTasksRange, value.ToString ());
+ OnPropertyChanged ("CompletionDateRange");
+ }
+ }
+ }
+
+ public string Convert (CompletionDateRange value, object parameter, CultureInfo culture)
+ {
+ return complDateRangeConverter.Convert (value, parameter, culture);
+ }
+
+ public CompletionDateRange ConvertBack (string value, object parameter, CultureInfo culture)
+ {
+ return complDateRangeConverter.ConvertBack (value, parameter, culture);
+ }
+
+ protected override void Dispose (bool disposing)
+ {
+ if (disposing)
+ preferences.SettingChanged -= HandleSettingChanged;
+ base.Dispose (disposing);
+ }
+
+ object IValueConverter.Convert (object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return ((IValueConverter)complDateRangeConverter).Convert (value, targetType, parameter, culture);
+ }
+
+ object IValueConverter.ConvertBack (object value, Type targetType,
+ object parameter, CultureInfo culture)
+ {
+ return ((IValueConverter)complDateRangeConverter).ConvertBack (
+ value, targetType, parameter, culture);
+ }
+
+ CompletionDateRange GetComplDateRangeFromPrefs ()
+ {
+ var val = preferences.Get (Preferences.CompletedTasksRange);
+ return (CompletionDateRange)Enum.Parse (typeof (CompletionDateRange), val);
+ }
+
+ void HandleSettingChanged (Preferences preferences, string settingKey)
+ {
+ if (settingKey == Preferences.CompletedTasksRange)
+ CompletionDateRange = GetComplDateRangeFromPrefs ();
+ }
+
+ CompletionDateRange completionDateRange;
+ CompletionDateRangeConverter complDateRangeConverter;
+ Preferences preferences;
+ }
+}
diff --git a/src/libtasqueui/Legacy/CompletionDateRangeConverter.cs b/src/libtasqueui/Legacy/CompletionDateRangeConverter.cs
new file mode 100644
index 0000000..c493811
--- /dev/null
+++ b/src/libtasqueui/Legacy/CompletionDateRangeConverter.cs
@@ -0,0 +1,62 @@
+//
+// CompletionDateRangeConverter.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 System;
+using System.Globalization;
+using Mono.Unix;
+
+namespace Tasque.UIModel.Legacy
+{
+ public class CompletionDateRangeConverter : ValueConverter<CompletionDateRange, string>
+ {
+ public override string Convert (CompletionDateRange value, object parameter, CultureInfo culture)
+ {
+ var complDateText = "";
+ switch (value) {
+ case CompletionDateRange.All:
+ complDateText = Catalog.GetString ("All");
+ break;
+ case CompletionDateRange.Last7Days:
+ complDateText = Catalog.GetString ("Last 7 days");
+ break;
+ case CompletionDateRange.LastMonth:
+ complDateText = Catalog.GetString ("Last month");
+ break;
+ case CompletionDateRange.LastYear:
+ complDateText = Catalog.GetString ("Last year");
+ break;
+ case CompletionDateRange.Yesterday:
+ complDateText = Catalog.GetString ("Yesterday");
+ break;
+ }
+ return complDateText;
+ }
+
+ public override CompletionDateRange ConvertBack (string value, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException ();
+ }
+ }
+}
diff --git a/src/libtasqueui/Legacy/TaskGroupConverter.cs b/src/libtasqueui/Legacy/TaskGroupConverter.cs
index 1ca7a33..e658696 100644
--- a/src/libtasqueui/Legacy/TaskGroupConverter.cs
+++ b/src/libtasqueui/Legacy/TaskGroupConverter.cs
@@ -35,19 +35,19 @@ namespace Tasque.UIModel.Legacy
{
var task = (Task)value;
if (task.IsComplete)
- return TaskGroup.Completed;
+ return TaskGroupName.Completed;
var today = DateTime.Today;
var tomorrow = DateTime.Today.AddDays (1);
var dueDate = task.DueDate.Date;
if (dueDate < today)
- return TaskGroup.Overdue;
+ return TaskGroupName.Overdue;
else if (dueDate == today)
- return TaskGroup.Today;
+ return TaskGroupName.Today;
else if (dueDate == tomorrow)
- return TaskGroup.Tomorrow;
+ return TaskGroupName.Tomorrow;
else
- return TaskGroup.Future;
+ return TaskGroupName.Future;
}
public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
diff --git a/src/libtasqueui/Legacy/TaskGroupModel.cs b/src/libtasqueui/Legacy/TaskGroupModel.cs
new file mode 100644
index 0000000..719d9bb
--- /dev/null
+++ b/src/libtasqueui/Legacy/TaskGroupModel.cs
@@ -0,0 +1,47 @@
+//
+// TaskGroupModel.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 System;
+using System.Collections.ObjectModel;
+
+namespace Tasque.UIModel.Legacy
+{
+ public class TaskGroupModel : ViewModelBase
+ {
+ public TaskGroupModel (TaskGroupName groupName, ReadOnlyObservableCollection<Task> tasks)
+ {
+ if (tasks == null)
+ throw new ArgumentNullException ("tasks");
+ Tasks = tasks;
+
+ var taskGroupNameConverter = new TaskGroupNameConverter ();
+ Title = taskGroupNameConverter.Convert (groupName, null, null);
+ }
+
+ public ReadOnlyObservableCollection<Task> Tasks { get; private set; }
+
+ public string Title { get; private set; }
+ }
+}
diff --git a/src/libtasqueui/Legacy/TaskGroupName.cs b/src/libtasqueui/Legacy/TaskGroupName.cs
new file mode 100644
index 0000000..194ad58
--- /dev/null
+++ b/src/libtasqueui/Legacy/TaskGroupName.cs
@@ -0,0 +1,37 @@
+//
+// TaskGroup.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.
+
+namespace Tasque.UIModel.Legacy
+{
+ public enum TaskGroupName
+ {
+ Overdue,
+ Today,
+ Tomorrow,
+ Future,
+ Completed
+ }
+}
diff --git a/src/libtasqueui/Legacy/TaskGroupNameConverter.cs b/src/libtasqueui/Legacy/TaskGroupNameConverter.cs
new file mode 100644
index 0000000..79b129e
--- /dev/null
+++ b/src/libtasqueui/Legacy/TaskGroupNameConverter.cs
@@ -0,0 +1,62 @@
+//
+// TaskGroupNameConverter.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 System;
+using System.Globalization;
+using Mono.Unix;
+
+namespace Tasque.UIModel.Legacy
+{
+ public class TaskGroupNameConverter : ValueConverter<TaskGroupName, string>
+ {
+ public override string Convert (TaskGroupName value, object parameter, CultureInfo culture)
+ {
+ var taskGroupNameText = "";
+ switch (value) {
+ case TaskGroupName.Completed:
+ Catalog.GetString ("Completed");
+ break;
+ case TaskGroupName.Future:
+ Catalog.GetString ("Future");
+ break;
+ case TaskGroupName.Overdue:
+ Catalog.GetString ("Overdue");
+ break;
+ case TaskGroupName.Today:
+ Catalog.GetString ("Today");
+ break;
+ case TaskGroupName.Tomorrow:
+ Catalog.GetString ("Tomorrow");
+ break;
+ }
+ return taskGroupNameText;
+ }
+
+ public override TaskGroupName ConvertBack (string value, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException ();
+ }
+ }
+}
diff --git a/src/libtasqueui/libtasqueui.csproj b/src/libtasqueui/libtasqueui.csproj
index 0d1b925..9d3159d 100644
--- a/src/libtasqueui/libtasqueui.csproj
+++ b/src/libtasqueui/libtasqueui.csproj
@@ -104,18 +104,20 @@
<Compile Include="Legacy\Commands\ComponentCommands.cs" />
<Compile Include="Legacy\Commands\TaskCommands.cs" />
<Compile Include="Legacy\NativeApplication.cs" />
- <Compile Include="TaskGroupModel.cs" />
<Compile Include="TaskGroupModelFactory.cs" />
- <Compile Include="CompletedTaskGroupModel.cs" />
<Compile Include="Point.cs" />
<Compile Include="Legacy\Preferences.cs" />
<Compile Include="..\Options.cs">
<Link>Options.cs</Link>
</Compile>
<Compile Include="Legacy\TaskGroupConverter.cs" />
- <Compile Include="Legacy\TaskGroup.cs" />
+ <Compile Include="Legacy\TaskGroupModel.cs" />
+ <Compile Include="Legacy\CompletedTaskGroupModel.cs" />
+ <Compile Include="Legacy\TaskGroupName.cs" />
<Compile Include="IValueConverter.cs" />
<Compile Include="ValueConverter.cs" />
+ <Compile Include="Legacy\CompletionDateRangeConverter.cs" />
+ <Compile Include="Legacy\TaskGroupNameConverter.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]