+++ /dev/null
-/*
- * 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);
-}