[tasque-list] [PATCH] Extend dbus interface



Hi,

I wrote a little program that interfaces with Tasque via dbus.  As the dbus
interface currently is not able to view due dates or priority, and is not 
able to set the properties of an existing task, I write this functionality.

Below is a patch, and I have also opened bug 645040.  I tried to follow the 
existing style. The Set functions do not return anything very useful, so if
you would rather they were void or purely returned status info I can change
that.

I hope this proves to be useful and worthy of inclusion upstream.
Yours,

David Newgas

---
 src/RemoteControl.cs |  176 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 176 insertions(+), 0 deletions(-)

diff --git a/src/RemoteControl.cs b/src/RemoteControl.cs
index 3681960..82c8b83 100644
--- a/src/RemoteControl.cs
+++ b/src/RemoteControl.cs
@@ -234,6 +234,29 @@ namespace Tasque
 		}
 		
 		/// <summary>
+		/// Sets the name of a task for a given ID
+		/// </summary>
+		/// <param name="id">
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </param>
+		/// <param>
+		/// A <see cref="System.String"/> the name of the task
+		/// </param>
+		/// <returns>
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </returns>
+		public string SetNameForTaskById (string id, string name)
+		{
+			ITask task = GetTaskById (id);
+			if (task == null)
+			{
+				return string.Empty;
+			}
+			task.Name = name;
+			return id;
+		}
+		
+		/// <summary>
 		/// Gets the category of a task for a given ID
 		/// </summary>
 		/// <param name="id">
@@ -249,6 +272,90 @@ namespace Tasque
 		}
 		
 		/// <summary>
+		/// Sets the category of a task for a given ID
+		/// </summary>
+		/// <param name="id">
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </param>
+		/// <param name="category">
+		/// A <see cref="System.String"/> the category of the task
+		/// </param>
+		/// <returns>
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </returns>
+		public string SetCategoryForTaskById (string id,
+							string categoryName)
+		{
+			ITask task = GetTaskById (id);
+			if (task == null)
+			{
+				return string.Empty;
+			}
+			Gtk.TreeIter iter;
+			Gtk.TreeModel model = Application.Backend.Categories;
+			
+			if (!model.GetIterFirst (out iter))
+				return string.Empty;
+			
+			do {
+				ICategory category = model.GetValue (iter, 0) as ICategory;
+				if (string.Compare(category.Name,categoryName)==0)
+				{
+					task.Category = category;
+					return id;
+				}
+			} while (model.IterNext (ref iter));
+			return string.Empty;
+		}
+		
+		/// <summary>
+		/// Get the due date of a task for a given ID
+		/// </summary>
+		/// <param name="id">
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </param>
+		/// <returns>
+		/// A <see cref="System.Int32"/> containing the POSIX time
+		/// of the due date
+		/// </returns>
+		public int GetDueDateForTaskById (string id)
+		{
+			ITask task = GetTaskById (id);
+			if (task == null)
+				return -1;
+			if (task.DueDate == DateTime.MinValue)
+				return 0;
+			return (int)(task.DueDate - new DateTime(1970,1,1)).TotalSeconds;
+		}
+		
+		/// <summary>
+		/// Set the due date of a task for a given ID
+		/// </summary>
+		/// <param name="id">
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </param>
+		/// <param name="duedate">
+		/// A <see cref="System.Int32"/> containing the POSIX time
+		/// of the due date
+		/// </param>
+		/// <returns>
+		/// A <see cref="System.String"/> for the ID of the task
+		/// <returns>
+		public string SetDueDateForTaskById (string id, int dueDate)
+		{
+			ITask task = GetTaskById (id);
+			if (task == null)
+			{
+				return string.Empty;
+			}
+			if (dueDate == 0)
+				task.DueDate = DateTime.MinValue;
+			else
+				task.DueDate = new DateTime(1970,1,1).AddSeconds(dueDate);
+			return id;
+		}
+		
+		/// <summary>
 		/// Gets the state of a task for a given ID
 		/// </summary>
 		/// <param name="id">
@@ -264,6 +371,59 @@ namespace Tasque
 		}
 
 		/// <summary>
+		/// Gets the priority of a task for a given ID
+		/// </summary>
+		/// <param name="id">
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </param>
+		/// <returns>
+		/// A <see cref="System.Int32"/> the priority of the task
+		/// </returns>
+		public int GetPriorityForTaskById (string id)
+		{
+			ITask task = GetTaskById (id);
+			return task != null ? (int) task.Priority : -1;
+		}
+		
+		/// <summary>
+		/// Sets the priority of a task for a given ID
+		/// </summary>
+		/// <param name="id">
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </param>
+		/// <param name="priority">
+		/// A <see cref="System.Int32"/> the priority of the task
+		/// </param>
+		/// <returns>
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </returns>
+		public string SetPriorityForTaskById (string id, int priority)
+		{
+			ITask task = GetTaskById (id);
+			if (task == null)
+			{
+				return string.Empty;
+			}
+			task.Priority = (TaskPriority) priority;
+			return id;
+		}
+		
+		/// <summary>
+		/// Marks a task active
+		/// </summary>
+		/// <param name="id">
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </param>
+		public void MarkTaskAsActiveById (string id)
+		{
+			ITask task = GetTaskById (id);
+			if (task == null)
+				return;
+				
+			task.Activate ();
+		}
+		
+		/// <summary>
 		/// Marks a task complete
 		/// </summary>
 		/// <param name="id">
@@ -283,6 +443,22 @@ namespace Tasque
 		}
 		
 		/// <summary>
+		/// Deletes a task
+		/// </summary>
+		/// <param name="id">
+		/// A <see cref="System.String"/> for the ID of the task
+		/// </param>
+		public void DeleteTaskById (string id)
+		{
+			ITask task = GetTaskById (id);
+			if (task == null)
+				return;
+				
+			task.Delete ();
+		}
+
+		
+		/// <summary>
 		/// Looks up a task by ID in the backend
 		/// </summary>
 		/// <param name="id">
-- 
1.7.4.1


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