Cut unnecessary MilkTask class.
authorTravis Reitter <treitter@gmail.com>
Mon, 30 Nov 2009 02:19:53 +0000 (18:19 -0800)
committerTravis Reitter <treitter@gmail.com>
Fri, 4 Dec 2009 06:01:13 +0000 (22:01 -0800)
src/Makefile.am
src/milk-main-window.c
src/milk-task-model.c
src/milk-task.c [deleted file]
src/milk-task.h [deleted file]

index 0c45bb2..abfce09 100644 (file)
@@ -16,8 +16,6 @@ milk_SOURCES = \
        milk-main.h \
        milk-main-window.c \
        milk-main-window.h \
-       milk-task.c \
-       milk-task.h \
        milk-task-model.c \
        milk-task-model.h
 
index 1d6901b..89104f7 100644 (file)
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <hildon/hildon.h>
+#include <rtm-glib/rtm-glib.h>
 
 #include "milk-main-window.h"
 #include "milk-auth.h"
-#include "milk-task.h"
 #include "milk-task-model.h"
 
 G_DEFINE_TYPE (MilkMainWindow, milk_main_window, HILDON_TYPE_WINDOW)
@@ -227,16 +227,12 @@ contact_column_render_func (GtkCellLayout   *cell_layout,
                             GtkTreeIter     *iter,
                             gpointer         user_data)
 {
-        MilkTask *task;
-        char *title;
+        RtmTask *task;
 
         gtk_tree_model_get (
                         model, iter, MILK_TASK_MODEL_COLUMN_TASK, &task, -1);
+        g_object_set (renderer, "text", rtm_task_get_name (task), NULL);
 
-        g_object_get (task, "title", &title, NULL);
-        g_object_set (renderer, "text", title, NULL);
-
-        g_free (title);
         g_object_unref (task);
 }
 
index 605e4a5..a1d6594 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "milk-task-model.h"
 #include "milk-auth.h"
-#include "milk-task.h"
 
 static void
 milk_task_model_tree_model_init (GtkTreeModelIface *iface);
@@ -84,7 +83,7 @@ milk_task_model_get_column_type (GtkTreeModel *model,
 {
         switch (column) {
                 case MILK_TASK_MODEL_COLUMN_TASK:
-                        return MILK_TYPE_TASK;
+                        return RTM_TYPE_TASK;
 
                 default:
                         g_warning (G_STRLOC ": invalid column: %d", column);
@@ -257,15 +256,14 @@ model_store_find_task (MilkTaskModel *model,
         valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
                         &iter);
         while (valid && !found) {
-                MilkTask *task;
-                char *task_id;
+                RtmTask *task;
 
                 gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
                                         MILK_TASK_MODEL_COLUMN_TASK, &task,
                                         -1);
-                g_object_get (task, "id", &task_id, NULL);
 
-                if (!g_strcmp0 (rtm_task_get_id (task_in), task_id)) {
+                if (!g_strcmp0 (rtm_task_get_id (task_in),
+                                rtm_task_get_id (task))) {
                         *iter_in = iter;
                         found = TRUE;
                 }
@@ -310,7 +308,6 @@ update_model (MilkTaskModel *model)
         for (l = rtm_tasks; l; l = g_list_delete_link (l, l)) {
                 GtkTreeIter iter;
                 RtmTask *rtm_task;
-                MilkTask *task;
                 const char *id;
                 gboolean task_in_store;
 
@@ -329,15 +326,20 @@ update_model (MilkTaskModel *model)
                         }
                 /* Task has been changed */
                 } else if (task_in_store) {
+                        RtmTask *old_task;
                         GtkTreePath *path;
 
+                        /* rtm-glib doesn't re-use task structs when they're
+                         * updated, so we have to replace the changed */
                         gtk_tree_model_get (
                                         GTK_TREE_MODEL (priv->store), &iter,
-                                        MILK_TASK_MODEL_COLUMN_TASK, &task,
+                                        MILK_TASK_MODEL_COLUMN_TASK, &old_task,
                                         -1);
 
-                        milk_task_set_title (task,
-                                        rtm_task_get_name (rtm_task));
+                        gtk_list_store_set (
+                                        priv->store, &iter,
+                                        MILK_TASK_MODEL_COLUMN_TASK, rtm_task,
+                                        -1);
 
                         path = gtk_tree_model_get_path (
                                         GTK_TREE_MODEL (priv->store), &iter);
@@ -346,22 +348,14 @@ update_model (MilkTaskModel *model)
                                         path, &iter);
                         gtk_tree_path_free (path);
 
-                        g_object_unref (task);
+                        g_object_unref (old_task);
 
                 /* Task is new */
                 } else {
-                        /* FIXME: remove the MilkTask class; just use RtmTask
-                         * directly */
-                        task = milk_task_new (id, rtm_task_get_name (rtm_task),
-                                        /* FIXME: switch priority from int to
-                                         * string */
-                                        g_ascii_strtod (rtm_task_get_priority
-                                                        (rtm_task), NULL));
-
                         gtk_list_store_append (priv->store, &iter);
                         gtk_list_store_set (
                                         priv->store, &iter,
-                                        MILK_TASK_MODEL_COLUMN_TASK, task,
+                                        MILK_TASK_MODEL_COLUMN_TASK, rtm_task,
                                         -1);
                 }
         }
@@ -571,7 +565,7 @@ milk_task_model_init (MilkTaskModel *self)
                         g_free, g_object_unref);
 
         priv->store = gtk_list_store_new (
-                        MILK_TASK_MODEL_N_COLUMNS, MILK_TYPE_TASK);
+                        MILK_TASK_MODEL_N_COLUMNS, RTM_TYPE_TASK);
 
         g_signal_connect (priv->store, "row-changed",
                         G_CALLBACK (row_changed_cb), self);
diff --git a/src/milk-task.c b/src/milk-task.c
deleted file mode 100644 (file)
index fffbeb2..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA  02110-1301  USA
- *
- * Authors: Travis Reitter <treitter@gmail.com>
- */
-
-#include <config.h>
-
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-#include <hildon/hildon.h>
-
-#include "milk-task.h"
-
-G_DEFINE_TYPE (MilkTask, milk_task, G_TYPE_OBJECT);
-
-/* less expensive than G_TYPE_INSTANCE_GET_PRIVATE */
-#define MILK_TASK_PRIVATE(o) ((MILK_TASK ((o)))->priv)
-
-struct _MilkTaskPrivate
-{
-        char *id;
-        gint priority;
-        char *title;
-};
-
-enum {
-        PROP_ID = 1,
-        PROP_TITLE,
-        PROP_PRIORITY,
-};
-
-
-static void
-task_set_id (MilkTask   *task,
-             const char *id)
-{
-        MilkTaskPrivate *priv;
-
-        g_return_if_fail (MILK_IS_TASK (task));
-        g_return_if_fail (id && !g_str_equal (id, ""));
-
-        priv = MILK_TASK_PRIVATE (task);
-        g_free (priv->id);
-        priv->id = g_strdup (id);
-}
-
-void
-milk_task_set_title (MilkTask   *task,
-                     const char *title)
-{
-        MilkTaskPrivate *priv;
-
-        g_return_if_fail (MILK_IS_TASK (task));
-
-        priv = MILK_TASK_PRIVATE (task);
-        g_free (priv->title);
-        priv->title = g_strdup (title);
-}
-
-void
-milk_task_set_priority (MilkTask *task,
-                        gint      priority)
-{
-        MilkTaskPrivate *priv;
-
-        g_return_if_fail (MILK_IS_TASK (task));
-        /* FIXME: set constraints on the allowed priority values */
-
-        priv = MILK_TASK_PRIVATE (task);
-        priv->priority = priority;
-}
-
-static void
-milk_task_get_property (GObject    *object,
-                        guint       property_id,
-                        GValue     *value,
-                        GParamSpec *pspec)
-{
-        MilkTaskPrivate *priv = MILK_TASK_PRIVATE (object);
-
-        switch (property_id)
-        {
-                case PROP_ID:
-                        g_value_set_string (value, priv->id);
-                break;
-
-                case PROP_TITLE:
-                        g_value_set_string (value, priv->title);
-                break;
-
-                case PROP_PRIORITY:
-                        g_value_set_int (value, priv->priority);
-                break;
-
-                default:
-                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
-                                        pspec);
-        }
-}
-
-static void
-milk_task_set_property (GObject      *object,
-                        guint         property_id,
-                        const GValue *value,
-                        GParamSpec   *pspec)
-{
-        MilkTaskPrivate *priv;
-        MilkTask *task;
-
-        task = MILK_TASK (object);
-        priv = MILK_TASK_PRIVATE (task);
-
-        switch (property_id)
-        {
-                case PROP_ID:
-                        task_set_id (task, g_value_get_string (value));
-                break;
-
-                case PROP_TITLE:
-                        milk_task_set_title (task, g_value_get_string (value));
-                break;
-
-                case PROP_PRIORITY:
-                        milk_task_set_priority (task, g_value_get_int (value));
-                break;
-
-                default:
-                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
-                                        pspec);
-        }
-}
-
-static void
-milk_task_finalize (GObject *object)
-{
-        MilkTaskPrivate *priv = MILK_TASK_PRIVATE (object);
-
-        g_free (priv->id);
-        g_free (priv->title);
-}
-
-static void
-milk_task_class_init (MilkTaskClass *klass)
-{
-        GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-        g_type_class_add_private (klass, sizeof (MilkTaskPrivate));
-
-        object_class->get_property = milk_task_get_property;
-        object_class->set_property = milk_task_set_property;
-        object_class->finalize = milk_task_finalize;
-
-        g_object_class_install_property
-                (object_class,
-                 PROP_ID,
-                 g_param_spec_string
-                         ("id",
-                          "Task ID",
-                          "A globally-unique identifier for the task.",
-                          "invalid-ID",
-                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
-                          G_PARAM_STATIC_STRINGS));
-
-        g_object_class_install_property
-                (object_class,
-                 PROP_TITLE,
-                 g_param_spec_string
-                         ("title",
-                          "Task title",
-                          "The description of the task to be performed.",
-                          "Untitled Task",
-                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
-        g_object_class_install_property
-                (object_class,
-                 PROP_PRIORITY,
-                 g_param_spec_int
-                         ("priority",
-                          "Task priority",
-                          "The user-valued priority of the task.",
-                          0, G_MAXINT, 0,
-                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-}
-
-static void
-milk_task_init (MilkTask *self)
-{
-        MilkTaskPrivate *priv;
-
-        self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (
-                        self, MILK_TYPE_TASK, MilkTaskPrivate);
-}
-
-MilkTask*
-milk_task_new (const char *id,
-               const char *title,
-               gint priority)
-{
-        return g_object_new (
-                        MILK_TYPE_TASK,
-                        "id", id,
-                        "title", title,
-                        "priority", priority,
-                        NULL);
-}
diff --git a/src/milk-task.h b/src/milk-task.h
deleted file mode 100644 (file)
index 36efa9c..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA  02110-1301  USA
- *
- * Authors: Travis Reitter <treitter@gmail.com>
- */
-
-#ifndef _MILK_TASK_H
-#define _MILK_TASK_H
-
-G_BEGIN_DECLS
-
-#define MILK_TYPE_TASK milk_task_get_type()
-
-#define MILK_TASK(obj) \
-                (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                MILK_TYPE_TASK, MilkTask))
-
-#define MILK_TASK_CLASS(klass) \
-                (G_TYPE_CHECK_CLASS_CAST ((klass), \
-                MILK_TYPE_TASK, MilkTaskClass))
-
-#define MILK_IS_TASK(obj) \
-                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                MILK_TYPE_TASK))
-
-#define MILK_IS_TASK_CLASS(klass) \
-                (G_TYPE_CHECK_CLASS_TYPE ((klass), \
-                MILK_TYPE_TASK))
-
-#define MILK_TASK_GET_CLASS(obj) \
-                (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-                MILK_TYPE_TASK, MilkTaskClass))
-
-typedef struct _MilkTask MilkTask;
-typedef struct _MilkTaskClass MilkTaskClass;
-typedef struct _MilkTaskPrivate MilkTaskPrivate;
-
-struct _MilkTask
-{
-        GObject parent;
-        MilkTaskPrivate *priv;
-};
-
-struct _MilkTaskClass
-{
-        GObjectClass parent_class;
-};
-
-GType milk_task_get_type (void);
-
-
-MilkTask* milk_task_new (const char *id, const char *title, gint priority);
-
-void milk_task_set_title (MilkTask *task, const char *title);
-void milk_task_set_priority (MilkTask *task, gint priority);
-
-#endif /* _MILK_TASK_H */