Ejemplo n.º 1
0
static gchar *
mpp_property_to_string (MrpObject   *object,
			MrpProperty *property)
{
	const gchar *name;
	gchar       *str;
	gchar        buffer[G_ASCII_DTOSTR_BUF_SIZE];
	gint         i;
	gfloat       f;
	mrptime      date;
	GArray      *array;

	name = mrp_property_get_name (property);

	switch (mrp_property_get_property_type (property)) {
	case MRP_PROPERTY_TYPE_STRING:
		mrp_object_get (object, name, &str, NULL);
		return str;
	case MRP_PROPERTY_TYPE_STRING_LIST:
		mrp_object_get (object, name, &array, NULL);
		if (!array) {
			return NULL;
		}

		/* FIXME */
		str = g_strdup ("text-list-foo");

		return str;
	case MRP_PROPERTY_TYPE_INT:
		mrp_object_get (object, name, &i, NULL);
		return g_strdup_printf ("%d", i);
	case MRP_PROPERTY_TYPE_FLOAT:
		mrp_object_get (object, name, &f, NULL);
		g_ascii_dtostr (buffer, sizeof (buffer), (double) f);
		return g_strdup (buffer);
	case MRP_PROPERTY_TYPE_DURATION:
		mrp_object_get (object, name, &i, NULL);
		return g_strdup_printf ("%d", i);
	case MRP_PROPERTY_TYPE_DATE:
		mrp_object_get (object, name, &date, NULL);
		str = mrp_time_to_string (date);
		return str;
	case MRP_PROPERTY_TYPE_COST:
		/* FIXME: implement cost */
		return NULL;
	default:
		g_warning ("Not implemented support for type %d",
			   mrp_property_get_property_type (property));
		break;
	}

	return NULL;
}
Ejemplo n.º 2
0
static MrpResource *
eds_find_resource (PlannerPlugin *plugin,
		   const gchar   *uid,
		   GList         *resources_orig)
{
	GList *l;
	MrpResource *resource = NULL;

	for (l = resources_orig; l; l = l->next) {
		gchar *current_uid;

		mrp_object_get (l->data, "eds-uid", &current_uid, NULL);
		if (!current_uid) {
			continue;
		}
		if (!strcmp (uid, current_uid)) {
			resource = l->data;
			break;
		}
	}
	return resource;
}
Ejemplo n.º 3
0
/* If the resource is already imported, update it */
static void
eds_import_resource (gchar         *name,
		     gchar         *email,
		     gchar         *uid,
		     PlannerPlugin *plugin,
		     GList         *resources_orig)
{
	MrpResource *resource;
	gchar       *note = _("Imported from Evolution Data Server");
	gchar       *note_update = _("Updated from Evolution Data Server");


	resource = eds_find_resource (plugin, uid, resources_orig);
	if (!resource) {
		resource = mrp_resource_new ();
		planner_resource_cmd_insert (plugin->main_window, resource);
		mrp_object_set (resource,
				"type", MRP_RESOURCE_TYPE_WORK,
				"units", 1,
				"note", g_strdup_printf ("%s:\n%s", note, uid),
				"eds-uid", g_strdup (uid),
				NULL);
	} else {
		gchar *note_now;
		mrp_object_get (resource, "note", &note_now, NULL);
		mrp_object_set (resource, "note",
				g_strdup_printf ("%s\n%s", note_now, note_update), NULL);
		g_free (note_now);
	}

	if (name) {
		mrp_object_set (resource, "name", name, NULL);
	}
	if (email) {
		mrp_object_set (resource, "email", email, NULL);
	}
}
Ejemplo n.º 4
0
static gboolean
phase_cmd_remove_do (PlannerCmd *cmd_base)
{
	PhaseCmdRemove *cmd;
	GList          *list, *l;
	gchar          *assigned_phase;
	gboolean        found;

	cmd = (PhaseCmdRemove*) cmd_base;

	mrp_object_get (cmd->project, "phase", &assigned_phase, NULL);
	if (assigned_phase == cmd->phase) {
		cmd->is_assigned = TRUE;
	}

	g_object_get (cmd->project, "phases", &list, NULL);

	found = FALSE;
	for (l = list; l; l = l->next) {
		if (!strcmp (cmd->phase, l->data)) {
			g_free (l->data);
			cmd->position = g_list_position (list, l);
			list = g_list_remove_link (list, l);
			found = TRUE;
			break;
		}
	}

	if (found) {
		g_object_set (cmd->project, "phases", list, NULL);
	}

	mrp_string_list_free (list);

	return !found;
}
Ejemplo n.º 5
0
static void
mpp_write_string_list (xmlNodePtr   node,
		       MrpProperty *property,
		       MrpObject   *object)
{
	xmlNodePtr   child;
	GArray      *array;
	GValue      *value;
	gint         i;

	mrp_object_get (object, mrp_property_get_name (property), &array, NULL);
	if (!array) {
		return;
	}

	for (i = 0; i < array->len; i++) {
		value = g_array_index (array, GValue *, i);

		child = xmlNewChild (node, NULL, "list-item", NULL);
		xmlSetProp (child, "value", g_value_get_string (value));
	}

	g_array_free (array, TRUE);
}
Ejemplo n.º 6
0
static void
mpp_write_resource (MrpParser   *parser,
		    xmlNodePtr   parent,
		    MrpResource *resource)
{
	xmlNodePtr   node;
	gchar       *name, *short_name, *email;
	gchar       *note;
	gint         type, units;
	gfloat       std_rate; /*, ovt_rate;*/
	NodeEntry   *group_entry;
	NodeEntry   *resource_entry;
	MrpGroup    *group;
	MrpCalendar *calendar;
	gint         id;

	g_return_if_fail (MRP_IS_RESOURCE (resource));

	node = xmlNewChild (parent,
                            NULL,
			    "resource",
			    NULL);

	mrp_object_get (MRP_OBJECT (resource),
			"name", &name,
			"short_name", &short_name,
			"email", &email,
			"type", &type,
			"units", &units,
			"group", &group,
			"cost", &std_rate,
			"note", &note,
			/*"cost-overtime", &ovt_rate,*/
			NULL);

	group_entry = g_hash_table_lookup (parser->group_hash, group);

	/* FIXME: should group really be able to be NULL? Should always
	 * be default group? */
	if (group_entry != NULL) {
		mpp_xml_set_int (node, "group", group_entry->id);
	}

	resource_entry = g_hash_table_lookup (parser->resource_hash, resource);
	mpp_xml_set_int (node, "id", resource_entry->id);

	xmlSetProp (node, "name", name);
	xmlSetProp (node, "short-name", short_name);

	mpp_xml_set_int (node, "type", type);

	mpp_xml_set_int (node, "units", units);
	xmlSetProp (node, "email", email);

	xmlSetProp (node, "note", note);

	mpp_xml_set_float (node, "std-rate", std_rate);
	/*mpp_xml_set_float (node, "ovt-rate", ovt_rate);*/

	calendar = mrp_resource_get_calendar (resource);
	if (calendar) {
		id = GPOINTER_TO_INT (g_hash_table_lookup (parser->calendar_hash,
							   calendar));

		if (id) {
			mpp_xml_set_int (node, "calendar", id);
		}
	}

	mpp_write_custom_properties (parser, node, MRP_OBJECT (resource));

	g_free (name);
	g_free (short_name);
	g_free (email);
	g_free (note);
}