mrp-object.c 16.8 KB
Newer Older
Richard Hult's avatar
Richard Hult committed
1 2
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
Richard Hult's avatar
Richard Hult committed
3
 * Copyright (C) 2003-2005 Imendio AB
Richard Hult's avatar
Richard Hult committed
4 5 6
 * Copyright (C) 2001-2003 CodeFactory AB
 * Copyright (C) 2001-2003 Richard Hult <richard@imendio.com>
 * Copyright (C) 2001-2002 Mikael Hallendal <micke@imendio.com>
7
 * Copyright (C) 2004      Alvaro del Castillo <acs@barrapunto.com>
Richard Hult's avatar
Richard Hult committed
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This library 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 library 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 library; if not, write to the
Josué Abarca's avatar
Josué Abarca committed
21 22
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
Richard Hult's avatar
Richard Hult committed
23 24
 */

25 26
/**
 * SECTION:mrp-object
Ahmed Baïzid's avatar
Ahmed Baïzid committed
27
 * @Short_Description: libplanner base class.
28
 * @Title: MrpObject
Ahmed Baïzid's avatar
Ahmed Baïzid committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 * @include: libplanner/mrp-object.h
 *
 * #MrpObject extends #GObject.
 * Most of @libplanner entities are #MrpObject instances.
 * Others are #GBoxed like #MrpInterval or #GEnum like #MrpTaskType.
 * #MrpApplication is a #GObject.
 *
 * #MrpObject has no constructor.
 *
 * #MrpObject instances belong to a project.
 *
 * #MrpObject has properties.
 *
 * #MrpApplication can associate pointers to ids.
 * #MrpObject uses the mechanism to register with
 * #MrpApplication, gaining an id.
 * mrp_application_id_get_data() retrieves an #MrpObject given its id.
 *
 * #MrpObject signals removal and modification.
48 49
 */

Richard Hult's avatar
Richard Hult committed
50 51 52 53 54 55
#include <config.h>
#include <gobject/gvaluecollector.h>
#include <string.h>

#include "mrp-marshal.h"
#include "mrp-project.h"
56
#include "mrp-application.h"
Richard Hult's avatar
Richard Hult committed
57 58 59 60 61
#include "mrp-private.h"
#include "mrp-object.h"

struct _MrpObjectPriv {
	MrpProject *project;
62
	guint       id;
Richard Hult's avatar
Richard Hult committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	GHashTable *property_hash;
};

/* Signals */
enum {
	REMOVED,
	PROP_CHANGED,
	LAST_SIGNAL
};

/* Properties */
enum {
	PROP_0,
	PROP_PROJECT
};


static GObjectClass *parent_class;
static guint         signals[LAST_SIGNAL];


static void object_class_init          (MrpObjectClass      *klass);
static void object_init                (MrpObject           *object);
static void object_finalize            (GObject             *g_object);
static void object_set_g_property      (GObject             *g_object,
					guint                prop_id,
					const GValue        *value,
					GParamSpec          *pspec);
static void object_get_g_property      (GObject             *g_object,
					guint                prop_id,
					GValue              *value,
					GParamSpec          *pspec);
static void object_property_removed_cb (MrpProject          *project,
					MrpProperty         *property,
					MrpObject           *object);


GType
mrp_object_get_type (void)
{
	static GType object_type = 0;

	if (!object_type) {
		static const GTypeInfo object_info = {
			sizeof (MrpObjectClass),
			NULL,		/* base_init */
			NULL,		/* base_finalize */
			(GClassInitFunc) object_class_init,
			NULL,		/* class_finalize */
			NULL,		/* class_data */
			sizeof (MrpObject),
			0,              /* n_preallocs */
			(GInstanceInitFunc) object_init,
		};

118 119
		object_type = g_type_register_static (G_TYPE_OBJECT,
                                                      "MrpObject",
Richard Hult's avatar
Richard Hult committed
120 121 122 123 124 125 126 127 128 129
                                                      &object_info, 0);
	}

	return object_type;
}

static void
object_class_init (MrpObjectClass *klass)
{
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
130

Richard Hult's avatar
Richard Hult committed
131
        parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
132

Richard Hult's avatar
Richard Hult committed
133 134 135 136 137 138 139
        object_class->finalize     = object_finalize;
        object_class->set_property = object_set_g_property;
        object_class->get_property = object_get_g_property;

	klass->removed             = NULL;

	/* Signals */
140

141 142 143 144 145 146
	/**
	 * MrpObject::removed:
	 * @object: the object which received the signal.
	 *
	 * emitted when @object is removed.
	 */
Richard Hult's avatar
Richard Hult committed
147 148 149 150 151 152 153
	signals[REMOVED] =
		g_signal_new ("removed",
			      G_TYPE_FROM_CLASS (klass),
			      G_SIGNAL_RUN_LAST,
			      G_STRUCT_OFFSET (MrpObjectClass, removed),
			      NULL, NULL,
			      mrp_marshal_VOID__VOID,
154
			      G_TYPE_NONE,
Richard Hult's avatar
Richard Hult committed
155 156
			      0);

157 158 159 160 161 162 163 164
	/**
	 * MrpObject::prop-changed:
	 * @object: a libplanner object.
	 * @property: the property that changed.
	 * @new_value: the new value.
	 *
	 * emitted when @property changes.
	 */
Richard Hult's avatar
Richard Hult committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
	signals[PROP_CHANGED] =
		g_signal_new ("prop_changed",
			      G_TYPE_FROM_CLASS (klass),
			      G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
			      G_STRUCT_OFFSET (MrpObjectClass, prop_changed),
			      NULL, NULL,
			      mrp_marshal_VOID__POINTER_POINTER,
			      G_TYPE_NONE,
			      2, G_TYPE_POINTER, G_TYPE_VALUE);

	/* Properties */
	g_object_class_install_property (
		object_class,
		PROP_PROJECT,
		g_param_spec_object ("project",
				     "Project",
				     "The project this object belongs to",
				     MRP_TYPE_PROJECT,
				     G_PARAM_READWRITE));
}

static void
object_init (MrpObject *object)
{
        MrpObjectPriv *priv;
190

Richard Hult's avatar
Richard Hult committed
191 192
        priv = g_new0 (MrpObjectPriv, 1);
        object->priv = priv;
193

194
	priv->id = mrp_application_get_unique_id ();
195
	imrp_application_id_set_data (object, priv->id);
196

197
        priv->property_hash = g_hash_table_new (NULL, NULL);
Richard Hult's avatar
Richard Hult committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
}

static void
object_finalize (GObject *g_object)
{
        if (G_OBJECT_CLASS (parent_class)->finalize) {
                (* G_OBJECT_CLASS (parent_class)->finalize) (g_object);
        }
}

/**
 * mrp_object_set_property:
 * @object: an #MrpObject
 * @property: the property to set
 * @value: the value to set
213
 *
Richard Hult's avatar
Richard Hult committed
214 215 216 217 218 219 220 221 222 223 224 225 226
 * Sets a custom property. This is mostly for language bindings. C programmers
 * should use mrp_object_set instead.
 **/
void
mrp_object_set_property (MrpObject *object, MrpProperty *property, GValue *value)
{
	MrpObjectPriv *priv;
	GValue        *value_cpy;
	GParamSpec    *pspec;
	GValue        *tmp_value;

	priv  = object->priv;
	pspec = G_PARAM_SPEC (property);
227

Richard Hult's avatar
Richard Hult committed
228 229 230 231 232
	value_cpy = g_new0 (GValue, 1);

	g_value_init (value_cpy, G_PARAM_SPEC_VALUE_TYPE (pspec));

	g_value_copy (value, value_cpy);
233

Richard Hult's avatar
Richard Hult committed
234 235 236 237 238 239 240 241 242
	tmp_value = g_hash_table_lookup (priv->property_hash,
					 property);

	if (tmp_value) {
		g_hash_table_steal (priv->property_hash, property);
		g_value_unset (tmp_value);
	} else {
		mrp_property_ref (property);
	}
243 244

	g_hash_table_insert (priv->property_hash,
Richard Hult's avatar
Richard Hult committed
245 246
			     property, value_cpy);

247
	g_signal_emit (object, signals[PROP_CHANGED],
248
		       g_quark_from_string (G_PARAM_SPEC (property)->name),
Richard Hult's avatar
Richard Hult committed
249 250 251 252 253 254 255 256
		       property, value);

	mrp_object_changed (object);
}

/**
 * mrp_object_get_property:
 * @object: an #MrpObject
257 258
 * @property: the property to get
 * @value: the value to get
259
 *
Richard Hult's avatar
Richard Hult committed
260 261 262 263 264 265 266 267
 * Gets a custom property. This is mostly for language bindings. C programmers
 * should use mrp_object_get instead.
 **/
void
mrp_object_get_property (MrpObject *object, MrpProperty *property, GValue *value)
{
	MrpObjectPriv *priv;
	GValue        *tmp_value;
268

Richard Hult's avatar
Richard Hult committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	priv = object->priv;

	tmp_value = g_hash_table_lookup (priv->property_hash,
					 property);

	if (!tmp_value) {
		g_param_value_set_default (G_PARAM_SPEC (property),
					   value);
		return;
	}

	g_value_copy (tmp_value, value);
}

static void
object_set_g_property (GObject        *g_object,
		       guint           prop_id,
		       const GValue   *value,
		       GParamSpec     *pspec)
{
	MrpObject     *object;
	MrpObjectPriv *priv;
291

Richard Hult's avatar
Richard Hult committed
292
	g_return_if_fail (MRP_IS_OBJECT (g_object));
293

Richard Hult's avatar
Richard Hult committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
	object = MRP_OBJECT (g_object);
	priv   = object->priv;

	switch (prop_id) {
	case PROP_PROJECT:
		if (priv->project) {
			g_signal_handlers_disconnect_by_func (priv->project,
							      G_CALLBACK (object_property_removed_cb),
							      object);
			g_object_unref (priv->project);
		}

		priv->project = g_value_get_object (value);
		if (priv->project) {
			g_object_ref (priv->project);
309
			g_signal_connect_object (priv->project,
Richard Hult's avatar
Richard Hult committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
						 "property_removed",
						 G_CALLBACK (object_property_removed_cb),
						 object,
						 G_CONNECT_AFTER);
		}
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
object_get_g_property (GObject      *g_object,
		       guint         prop_id,
		       GValue       *value,
		       GParamSpec   *pspec)
{
	MrpObject     *object;
	MrpObjectPriv *priv;

	g_return_if_fail (MRP_IS_OBJECT (g_object));
332

Richard Hult's avatar
Richard Hult committed
333 334
	object = MRP_OBJECT (g_object);
	priv   = object->priv;
335

Richard Hult's avatar
Richard Hult committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
	switch (prop_id) {
	case PROP_PROJECT:
		g_value_set_object (value, priv->project);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
object_property_removed_cb (MrpProject  *project,
			    MrpProperty *property,
			    MrpObject   *object)
{
	MrpObjectPriv *priv;
	GValue        *value;

	g_return_if_fail (MRP_IS_PROJECT (project));
	g_return_if_fail (property != NULL);
	g_return_if_fail (MRP_IS_OBJECT (object));

	priv = object->priv;

	value = g_hash_table_lookup (priv->property_hash, property);

	if (value) {
		g_hash_table_steal (priv->property_hash, property);
		g_value_unset (value);
		g_free (value);
		mrp_property_unref (property);
	}
}

/**
 * mrp_object_removed:
 * @object: an #MrpObject
 *
 * Emits the signal %removed. This means that any references to the object
 * should be dropped, since the object is removed from the project.
 **/
void
mrp_object_removed (MrpObject *object)
{
	g_return_if_fail (MRP_IS_OBJECT (object));
381

Richard Hult's avatar
Richard Hult committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395
	g_signal_emit (object, signals[REMOVED], 0);
}

/**
 * mrp_object_changed:
 * @object: an #MrpObject
 *
 * Emits the signal needs-saving on the project that this object belongs to,
 * indicating that the project has unsaved changes.
 **/
void
mrp_object_changed (MrpObject *object)
{
	MrpObjectPriv *priv;
396

Richard Hult's avatar
Richard Hult committed
397
	g_return_if_fail (MRP_IS_OBJECT (object));
398

Richard Hult's avatar
Richard Hult committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
	priv = object->priv;

	if (priv->project) {
		imrp_project_set_needs_saving (priv->project, TRUE);
	}
}

/**
 * mrp_object_set:
 * @object: an #MrpObject
 * @first_property_name: the name of the first property to set
 * @...: first value to set, followed by additional name/value pairs to set, NULL terminated
 *
 * #MrpObject can have custom properties, which are added runtime, for example
 * by a user or plugin. mrp_object_set() allows you to set these the value of
 * those properties. It also handles the regular #GObject properties, so you can
 * use it to set both custom properties and regular properties at the same time.
 **/
void
mrp_object_set (gpointer     pobject,
		const gchar *first_property_name,
		...)
421
{
Richard Hult's avatar
Richard Hult committed
422 423
	MrpObject *object = MRP_OBJECT (pobject);
	va_list    var_args;
424
	gboolean   blocked = FALSE;
425

Richard Hult's avatar
Richard Hult committed
426
	g_return_if_fail (MRP_IS_OBJECT (object));
427 428 429 430 431

	if (object->priv->project) {
		blocked = mrp_project_get_block_scheduling (object->priv->project);
		mrp_project_set_block_scheduling (object->priv->project, TRUE);
	}
432

Richard Hult's avatar
Richard Hult committed
433 434 435
	va_start (var_args, first_property_name);
	mrp_object_set_valist (object, first_property_name, var_args);
	va_end (var_args);
436 437 438 439

	if (object->priv->project) {
		mrp_project_set_block_scheduling (object->priv->project, blocked);
	}
Richard Hult's avatar
Richard Hult committed
440 441 442 443 444 445 446
}

/**
 * mrp_object_get:
 * @object: an #MrpProject
 * @first_property_name: the name of the first property to get
 * @...: first value to get, followed by additional name/value pairs to get, NULL terminated
447
 *
Richard Hult's avatar
Richard Hult committed
448 449 450 451 452 453 454 455 456 457
 * Retrieves the values of a variable number of custom properties or regular
 * properties from an object. See mrp_object_set().
 **/
void
mrp_object_get (gpointer     pobject,
		const gchar *first_property_name,
		...)
{
	MrpObject *object = MRP_OBJECT (pobject);
	va_list    var_args;
458

Richard Hult's avatar
Richard Hult committed
459
	g_return_if_fail (MRP_IS_OBJECT (object));
460

Richard Hult's avatar
Richard Hult committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
	va_start (var_args, first_property_name);
	mrp_object_get_valist (object, first_property_name, var_args);
	va_end (var_args);
}

/**
 * mrp_object_set_valist:
 * @object: an #MrpObject
 * @first_property_name: the name of the first property to set
 * @var_args: va_list of arguments
 *
 * va_list version of mrp_object_set().
 **/
void
mrp_object_set_valist (MrpObject   *object,
		       const gchar *first_property_name,
		       va_list      var_args)
{
	MrpObjectPriv *priv;
	const gchar   *name;
481

Richard Hult's avatar
Richard Hult committed
482 483 484
	g_return_if_fail (MRP_IS_OBJECT (object));

	priv = object->priv;
485

Richard Hult's avatar
Richard Hult committed
486
	g_object_ref (object);
487

Richard Hult's avatar
Richard Hult committed
488 489 490 491 492 493
	name = first_property_name;

	while (name) {
		GValue       value = { 0, };
		GParamSpec  *pspec;
		gchar       *error = NULL;
494

Richard Hult's avatar
Richard Hult committed
495 496 497 498 499
		pspec = g_object_class_find_property (
			G_OBJECT_GET_CLASS (object), name);

		if (pspec) {
			/* Normal g_object property */
500
			g_value_init (&value,
Richard Hult's avatar
Richard Hult committed
501
				      G_PARAM_SPEC_VALUE_TYPE (pspec));
502

Richard Hult's avatar
Richard Hult committed
503 504 505 506 507 508 509
			G_VALUE_COLLECT (&value, var_args, 0, &error);
			g_object_set_property (G_OBJECT (object),
					       name,
					       &value);
		} else {
			/* Our custom properties */
			pspec = G_PARAM_SPEC (
510
				mrp_project_get_property (priv->project,
Richard Hult's avatar
Richard Hult committed
511 512
							  name,
							  G_OBJECT_TYPE (object)));
513

Richard Hult's avatar
Richard Hult committed
514 515 516 517 518 519 520
			if (!pspec) {
				g_warning ("%s: object class `%s' has no property named `%s'",
					   G_STRLOC,
					   G_OBJECT_TYPE_NAME (object),
					   name);
				break;
			}
521

Richard Hult's avatar
Richard Hult committed
522 523 524 525 526 527 528
			if (!(pspec->flags & G_PARAM_WRITABLE)) {
				g_warning ("%s: property `%s' of object class `%s' is not writable",
					   G_STRLOC,
					   pspec->name,
					   G_OBJECT_TYPE_NAME (object));
				break;
			}
529

Richard Hult's avatar
Richard Hult committed
530
			g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
531

Richard Hult's avatar
Richard Hult committed
532 533 534 535 536 537
			G_VALUE_COLLECT (&value, var_args, 0, &error);
		}

		if (error) {
			g_warning ("%s: %s", G_STRLOC, error);
			g_free (error);
538

Richard Hult's avatar
Richard Hult committed
539 540 541 542 543 544 545
			/* we purposely leak the value here, it might not be
			 * in a sane state if an error condition occoured
			 */
			break;
		}

		mrp_object_set_property (object, MRP_PROPERTY (pspec), &value);
546

Richard Hult's avatar
Richard Hult committed
547 548
		/* set the property value */
		g_value_unset (&value);
549

Richard Hult's avatar
Richard Hult committed
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
		name = va_arg (var_args, gchar*);
	}

	g_object_unref (object);
}

/**
 * mrp_object_get_valist:
 * @object: an #MrpObject
 * @first_property_name: the name of the first property to get
 * @var_args: va_list of arguments
 *
 * va_list version of mrp_object_get().
 **/
void
mrp_object_get_valist (MrpObject   *object,
		       const gchar *first_property_name,
		       va_list      var_args)
{
	MrpObjectPriv *priv;
	const gchar   *name;
571

Richard Hult's avatar
Richard Hult committed
572
	g_return_if_fail (MRP_IS_OBJECT (object));
573

Richard Hult's avatar
Richard Hult committed
574
	priv = object->priv;
575

Richard Hult's avatar
Richard Hult committed
576
	g_object_ref (object);
577

Richard Hult's avatar
Richard Hult committed
578
	name = first_property_name;
579

Richard Hult's avatar
Richard Hult committed
580 581 582 583 584 585 586 587
	while (name) {
		GValue      value = { 0, };
		GParamSpec *pspec;
		gchar      *error;

		pspec = g_object_class_find_property (
			G_OBJECT_GET_CLASS (object),
			name);
588

Richard Hult's avatar
Richard Hult committed
589 590 591 592 593 594 595 596 597 598
		if (pspec) {
			g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));

			g_object_get_property (G_OBJECT (object),
					       name,
					       &value);
		} else {
			pspec = mrp_project_get_property (priv->project,
							  name,
							  G_OBJECT_TYPE (object));
599

Richard Hult's avatar
Richard Hult committed
600 601 602 603 604 605 606 607 608 609 610
			if (!pspec) {
				break;
			}

			if (!(pspec->flags & G_PARAM_READABLE))	{
				g_warning ("%s: property `%s' of object class `%s' is not readable",
					   G_STRLOC,
					   pspec->name,
					   G_OBJECT_TYPE_NAME (object));
				break;
			}
611

Richard Hult's avatar
Richard Hult committed
612
			g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
613

Richard Hult's avatar
Richard Hult committed
614
			mrp_object_get_property (object,
615
						 MRP_PROPERTY (pspec),
Richard Hult's avatar
Richard Hult committed
616 617
						 &value);
		}
618

Richard Hult's avatar
Richard Hult committed
619 620 621 622 623 624 625 626
		G_VALUE_LCOPY (&value, var_args, 0, &error);

		if (error) {
			g_warning ("%s: %s", G_STRLOC, error);
			g_free (error);
			g_value_unset (&value);
			break;
		}
627

Richard Hult's avatar
Richard Hult committed
628
		g_value_unset (&value);
629

Richard Hult's avatar
Richard Hult committed
630 631
		name = va_arg (var_args, gchar *);
	}
632

Richard Hult's avatar
Richard Hult committed
633 634 635 636 637 638
	g_object_unref (object);
}

/**
 * mrp_object_get_properties:
 * @object: an #MrpObject
639
 *
Richard Hult's avatar
Richard Hult committed
640
 * Retrieves the list of custom properties for the type of @object.
641
 *
Richard Hult's avatar
Richard Hult committed
642 643 644 645 646 647 648 649 650 651
 * Return value: A list of #MrpProperty, must not be changed or freed.
 **/
GList *
mrp_object_get_properties (MrpObject *object)
{
	MrpObjectPriv *priv;

	g_return_val_if_fail (MRP_IS_OBJECT (object), NULL);

	priv = object->priv;
652 653

	return mrp_project_get_properties_from_type (priv->project,
Richard Hult's avatar
Richard Hult committed
654 655
						     G_OBJECT_TYPE (object));
}
656

657 658 659
/**
 * mrp_object_get_id:
 * @object: an #MrpObject
660
 *
661
 * Retrieves the unique object id in the application
662
 *
663 664
 * Return value: 0 if fails, object id if everything is ok.
 **/
665 666 667 668
guint
mrp_object_get_id (MrpObject *object)
{
	MrpObjectPriv *priv;
669

670
	g_return_val_if_fail (MRP_IS_OBJECT (object), 0);
671

672 673 674 675 676
	priv = object->priv;

	return priv->id;
}

677 678 679 680

/**
 * mrp_object_set_id:
 * @object: an #MrpObject
681
 * @id: an id
682
 *
683
 * Change the unique object id in the application.
684 685
 * This function must be called only from Undo/Redo operations.
 *
686 687
 * Return value: FALSE if fails, TRUE is everything is ok.
 **/
688 689 690 691 692 693 694 695
gboolean
mrp_object_set_id (MrpObject *object,
		   guint      id)
{
	MrpObjectPriv *priv;

	g_return_val_if_fail (MRP_IS_OBJECT (object), FALSE);

696
	priv = object->priv;
697 698

	if (imrp_application_id_set_data (object, id)) {
699 700 701 702 703
		priv->id = id;
		return TRUE;
	} else {
		return FALSE;
	}
704
}
705

706 707 708 709 710 711 712
/**
 * mrp_object_get_project:
 * @object: a libplanner object
 * @Returns: The project @object belongs to
 *
 * to which project does @object belongs to?
 */
713 714 715 716 717 718 719 720 721 722 723
gpointer
mrp_object_get_project (MrpObject *object)
{
	MrpObjectPriv *priv;

	g_return_val_if_fail (MRP_IS_OBJECT (object), FALSE);

	priv = object->priv;

	return priv->project;
}