[Planner Dev] Add "Assigned to" column to the tasks display



Just wanted to thank the developers of planner for an excellent and very 
useful program.

I wrote up this patch to add a column to the task view with the resources a 
task is assigned to.  This seemed quite useful to have and allows for knowing 
which tasks have no one assigned to at the moment.  This is my first planner 
patch so please tell me what things I need to clean up to get this into cvs.

Thanks,
Chris



? assigned_to_column_in_tasks.patch
Index: src/planner-gantt-model.h
===================================================================
RCS file: /cvs/gnome/planner/src/planner-gantt-model.h,v
retrieving revision 1.5
diff -u -r1.5 planner-gantt-model.h
--- src/planner-gantt-model.h	29 Jun 2004 09:06:44 -0000	1.5
+++ src/planner-gantt-model.h	19 Jul 2004 23:35:45 -0000
@@ -59,6 +59,7 @@
 	COL_EDITABLE,
 	COL_TASK,
 	COL_COST,
+	COL_ASSIGNED_TO,
 	NUM_COLS
 };
 
Index: src/planner-task-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v
retrieving revision 1.37
diff -u -r1.37 planner-task-tree.c
--- src/planner-task-tree.c	5 Jul 2004 09:13:48 -0000	1.37
+++ src/planner-task-tree.c	19 Jul 2004 23:35:51 -0000
@@ -47,6 +47,7 @@
 #include "planner-gantt-model.h"
 #include "planner-task-popup.h"
 #include "planner-task-cmd.h"
+#include "planner-gantt-row.h"
 
 #define WARN_TASK_DIALOGS 10
 #define MAX_TASK_DIALOGS 25
@@ -128,6 +129,11 @@
 							GtkTreeModel         *tree_model,
 							GtkTreeIter          *iter,
 							gpointer              data);
+static void        task_tree_assigned_to_data_func     (GtkTreeViewColumn    *tree_column,
+							GtkCellRenderer      *cell,
+							GtkTreeModel         *tree_model,
+							GtkTreeIter          *iter,
+							gpointer              data);
 static void        task_tree_work_data_func            (GtkTreeViewColumn    *tree_column,
 							GtkCellRenderer      *cell,
 							GtkTreeModel         *tree_model,
@@ -1523,6 +1529,66 @@
 }
 
 static void
+task_tree_assigned_to_data_func (GtkTreeViewColumn *tree_column,
+			  GtkCellRenderer   *cell,
+			  GtkTreeModel      *tree_model,
+			  GtkTreeIter       *iter,
+			  gpointer           data)
+{
+	gchar  *assigned_to;
+	GList  *resources;
+	MrpAssignment  *assignment;
+	MrpResource    *resource;
+	GList          *l;
+	MrpTask        *task;
+	const gchar    *name;
+
+	gtk_tree_model_get (tree_model, iter, 
+			    COL_TASK, &task,
+			    -1);
+
+	assigned_to = 0;
+	resources = mrp_task_get_assigned_resources(task);
+
+        for (l = resources; l; l = l->next) {
+                resource = l->data;
+
+                assignment = mrp_task_get_assignment (task, resource);
+
+                /* Try short name first. */
+                name = mrp_resource_get_short_name (resource);
+
+                if (!name || name[0] == 0) {
+                        name = mrp_resource_get_name (resource);
+                }
+
+                if (!name || name[0] == 0) {
+                                name = _("Unnamed");
+                }
+
+		/* separate names with commas */
+		if(assigned_to)
+		{
+			char *newstr;
+			newstr = g_strdup_printf("%s, %s", assigned_to, name);
+			g_free(assigned_to);
+			assigned_to = newstr;
+		}
+		else /* g_strconcat() can't take a NULL string so we do special stuff when assigned_to is null */
+		{
+			assigned_to = g_strdup(name);
+		}
+        }
+        g_list_free (resources);
+
+	g_object_set (cell,
+		      "text", assigned_to,
+		      NULL);
+
+	g_free(assigned_to);
+}
+
+static void
 task_tree_work_data_func (GtkTreeViewColumn *tree_column,
 			  GtkCellRenderer   *cell,
 			  GtkTreeModel      *tree_model,
@@ -2401,6 +2467,25 @@
 		gtk_tree_view_append_column (tree, col);
 		break;
 
+	case COL_ASSIGNED_TO:
+		cell = gtk_cell_renderer_text_new ();
+		col = gtk_tree_view_column_new_with_attributes (title,
+								cell,
+								NULL);
+		gtk_tree_view_column_set_resizable (col, TRUE);
+		gtk_tree_view_column_set_cell_data_func (col,
+							 cell,
+							 task_tree_assigned_to_data_func,
+							 tree,
+							 NULL);
+		g_object_set_data (G_OBJECT (col),
+				   "data-func", task_tree_assigned_to_data_func);
+		g_object_set_data (G_OBJECT (col),
+				   "user-data", tree);
+
+		gtk_tree_view_append_column (tree, col);
+		break;
+
 	default:
 		g_assert_not_reached ();
 	}
Index: src/planner-task-view.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-view.c,v
retrieving revision 1.11
diff -u -r1.11 planner-task-view.c
--- src/planner-task-view.c	17 Jun 2004 16:30:38 -0000	1.11
+++ src/planner-task-view.c	19 Jul 2004 23:35:53 -0000
@@ -277,6 +277,7 @@
 						    COL_WORK,   _("Work"),
 						    COL_SLACK,  _("Slack"),
 						    COL_COST,   _("Cost"),
+						    COL_ASSIGNED_TO, _("Assigned to"),
 						    -1);
 
 		g_object_unref (model);


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