/* command-personas.c generated by valac 0.12.0, the Vala compiler
 * generated from command-personas.vala, do not modify */

/*
 * Copyright (C) 2010 Collabora Ltd.
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Philip Withnall <philip.withnall@collabora.co.uk>
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <folks/folks.h>
#include <gee.h>
#include <stdio.h>
#include <readline/readline.h>


#define FOLKS_INSPECT_TYPE_COMMAND (folks_inspect_command_get_type ())
#define FOLKS_INSPECT_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_INSPECT_TYPE_COMMAND, FolksInspectCommand))
#define FOLKS_INSPECT_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_INSPECT_TYPE_COMMAND, FolksInspectCommandClass))
#define FOLKS_INSPECT_IS_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_INSPECT_TYPE_COMMAND))
#define FOLKS_INSPECT_IS_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_INSPECT_TYPE_COMMAND))
#define FOLKS_INSPECT_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_INSPECT_TYPE_COMMAND, FolksInspectCommandClass))

typedef struct _FolksInspectCommand FolksInspectCommand;
typedef struct _FolksInspectCommandClass FolksInspectCommandClass;
typedef struct _FolksInspectCommandPrivate FolksInspectCommandPrivate;

#define FOLKS_INSPECT_TYPE_CLIENT (folks_inspect_client_get_type ())
#define FOLKS_INSPECT_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_INSPECT_TYPE_CLIENT, FolksInspectClient))
#define FOLKS_INSPECT_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_INSPECT_TYPE_CLIENT, FolksInspectClientClass))
#define FOLKS_INSPECT_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_INSPECT_TYPE_CLIENT))
#define FOLKS_INSPECT_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_INSPECT_TYPE_CLIENT))
#define FOLKS_INSPECT_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_INSPECT_TYPE_CLIENT, FolksInspectClientClass))

typedef struct _FolksInspectClient FolksInspectClient;
typedef struct _FolksInspectClientClass FolksInspectClientClass;

#define FOLKS_INSPECT_COMMANDS_TYPE_PERSONAS (folks_inspect_commands_personas_get_type ())
#define FOLKS_INSPECT_COMMANDS_PERSONAS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_INSPECT_COMMANDS_TYPE_PERSONAS, FolksInspectCommandsPersonas))
#define FOLKS_INSPECT_COMMANDS_PERSONAS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_INSPECT_COMMANDS_TYPE_PERSONAS, FolksInspectCommandsPersonasClass))
#define FOLKS_INSPECT_COMMANDS_IS_PERSONAS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_INSPECT_COMMANDS_TYPE_PERSONAS))
#define FOLKS_INSPECT_COMMANDS_IS_PERSONAS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_INSPECT_COMMANDS_TYPE_PERSONAS))
#define FOLKS_INSPECT_COMMANDS_PERSONAS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_INSPECT_COMMANDS_TYPE_PERSONAS, FolksInspectCommandsPersonasClass))

typedef struct _FolksInspectCommandsPersonas FolksInspectCommandsPersonas;
typedef struct _FolksInspectCommandsPersonasClass FolksInspectCommandsPersonasClass;
typedef struct _FolksInspectCommandsPersonasPrivate FolksInspectCommandsPersonasPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _FolksInspectCommand {
	GTypeInstance parent_instance;
	volatile int ref_count;
	FolksInspectCommandPrivate * priv;
	FolksInspectClient* client;
};

struct _FolksInspectCommandClass {
	GTypeClass parent_class;
	void (*finalize) (FolksInspectCommand *self);
	void (*run) (FolksInspectCommand* self, const gchar* command_string);
	gchar** (*complete_subcommand) (FolksInspectCommand* self, const gchar* subcommand, int* result_length1);
	const gchar* (*get_name) (FolksInspectCommand* self);
	const gchar* (*get_description) (FolksInspectCommand* self);
	const gchar* (*get_help) (FolksInspectCommand* self);
};

struct _FolksInspectCommandsPersonas {
	FolksInspectCommand parent_instance;
	FolksInspectCommandsPersonasPrivate * priv;
};

struct _FolksInspectCommandsPersonasClass {
	FolksInspectCommandClass parent_class;
};


static gpointer folks_inspect_commands_personas_parent_class = NULL;

gpointer folks_inspect_command_ref (gpointer instance);
void folks_inspect_command_unref (gpointer instance);
GParamSpec* folks_inspect_param_spec_command (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void folks_inspect_value_set_command (GValue* value, gpointer v_object);
void folks_inspect_value_take_command (GValue* value, gpointer v_object);
gpointer folks_inspect_value_get_command (const GValue* value);
GType folks_inspect_command_get_type (void) G_GNUC_CONST;
GType folks_inspect_client_get_type (void) G_GNUC_CONST;
GType folks_inspect_commands_personas_get_type (void) G_GNUC_CONST;
enum  {
	FOLKS_INSPECT_COMMANDS_PERSONAS_DUMMY_PROPERTY
};
FolksInspectCommandsPersonas* folks_inspect_commands_personas_new (FolksInspectClient* client);
FolksInspectCommandsPersonas* folks_inspect_commands_personas_construct (GType object_type, FolksInspectClient* client);
FolksInspectCommand* folks_inspect_command_construct (GType object_type, FolksInspectClient* client);
static void folks_inspect_commands_personas_real_run (FolksInspectCommand* base, const gchar* command_string);
FolksIndividualAggregator* folks_inspect_client_get_aggregator (FolksInspectClient* self);
void folks_inspect_utils_print_persona (FolksPersona* persona);
void folks_inspect_utils_print_line (const gchar* format, ...);
static gchar** folks_inspect_commands_personas_real_complete_subcommand (FolksInspectCommand* base, const gchar* subcommand, int* result_length1);
gchar* folks_inspect_utils_persona_uid_completion_cb (const gchar* word, gint state);
static gchar* _folks_inspect_utils_persona_uid_completion_cb_rl_compentry_func_t (const gchar* str, gint a);
static gchar** _vala_array_dup5 (gchar** self, int length);
static gint _vala_array_length (gpointer array);


FolksInspectCommandsPersonas* folks_inspect_commands_personas_construct (GType object_type, FolksInspectClient* client) {
	FolksInspectCommandsPersonas* self = NULL;
	g_return_val_if_fail (client != NULL, NULL);
	self = (FolksInspectCommandsPersonas*) folks_inspect_command_construct (object_type, client);
	return self;
}


FolksInspectCommandsPersonas* folks_inspect_commands_personas_new (FolksInspectClient* client) {
	return folks_inspect_commands_personas_construct (FOLKS_INSPECT_COMMANDS_TYPE_PERSONAS, client);
}


static void folks_inspect_commands_personas_real_run (FolksInspectCommand* base, const gchar* command_string) {
	FolksInspectCommandsPersonas * self;
	self = (FolksInspectCommandsPersonas*) base;
	{
		FolksIndividualAggregator* _tmp0_ = NULL;
		GeeMap* _tmp1_ = NULL;
		GeeCollection* _tmp2_ = NULL;
		GeeCollection* _tmp3_;
		GeeIterator* _tmp4_ = NULL;
		GeeIterator* _tmp5_;
		GeeIterator* _individual_it;
		_tmp0_ = folks_inspect_client_get_aggregator (((FolksInspectCommand*) self)->client);
		_tmp1_ = folks_individual_aggregator_get_individuals (_tmp0_);
		_tmp2_ = gee_map_get_values (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_individual_it = _tmp5_;
		while (TRUE) {
			gboolean _tmp6_;
			gpointer _tmp7_ = NULL;
			FolksIndividual* individual;
			_tmp6_ = gee_iterator_next (_individual_it);
			if (!_tmp6_) {
				break;
			}
			_tmp7_ = gee_iterator_get (_individual_it);
			individual = (FolksIndividual*) _tmp7_;
			{
				GeeSet* _tmp8_ = NULL;
				GeeIterator* _tmp9_ = NULL;
				GeeIterator* _persona_it;
				_tmp8_ = folks_individual_get_personas (individual);
				_tmp9_ = gee_iterable_iterator ((GeeIterable*) _tmp8_);
				_persona_it = _tmp9_;
				while (TRUE) {
					gboolean _tmp10_;
					gpointer _tmp11_ = NULL;
					FolksPersona* persona;
					gboolean _tmp12_ = FALSE;
					_tmp10_ = gee_iterator_next (_persona_it);
					if (!_tmp10_) {
						break;
					}
					_tmp11_ = gee_iterator_get (_persona_it);
					persona = (FolksPersona*) _tmp11_;
					if (command_string != NULL) {
						const gchar* _tmp13_ = NULL;
						_tmp13_ = folks_persona_get_uid (persona);
						_tmp12_ = g_strcmp0 (_tmp13_, command_string) != 0;
					} else {
						_tmp12_ = FALSE;
					}
					if (_tmp12_) {
						_g_object_unref0 (persona);
						continue;
					}
					folks_inspect_utils_print_persona (persona);
					if (command_string == NULL) {
						folks_inspect_utils_print_line ("");
					}
					_g_object_unref0 (persona);
				}
				_g_object_unref0 (_persona_it);
			}
			_g_object_unref0 (individual);
		}
		_g_object_unref0 (_individual_it);
	}
}


static gchar* _folks_inspect_utils_persona_uid_completion_cb_rl_compentry_func_t (const gchar* str, gint a) {
	gchar* result;
	result = folks_inspect_utils_persona_uid_completion_cb (str, a);
	return result;
}


static gchar** _vala_array_dup5 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		result[i] = g_strdup (self[i]);
	}
	return result;
}


static gchar** folks_inspect_commands_personas_real_complete_subcommand (FolksInspectCommand* base, const gchar* subcommand, int* result_length1) {
	FolksInspectCommandsPersonas * self;
	gchar** result = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_ = NULL;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gchar** _tmp4_;
	self = (FolksInspectCommandsPersonas*) base;
	g_return_val_if_fail (subcommand != NULL, NULL);
	_tmp1_ = _tmp0_ = rl_completion_matches (subcommand, _folks_inspect_utils_persona_uid_completion_cb_rl_compentry_func_t);
	_tmp2_ = (_tmp3_ = _tmp1_, (_tmp3_ == NULL) ? ((gpointer) _tmp3_) : _vala_array_dup5 (_tmp3_, _vala_array_length (_tmp0_)));
	_tmp4_ = _tmp2_;
	*result_length1 = _vala_array_length (_tmp0_);
	result = _tmp4_;
	return result;
}


static const gchar* folks_inspect_commands_personas_real_get_name (FolksInspectCommand* base) {
	const gchar* result;
	FolksInspectCommandsPersonas* self;
	self = (FolksInspectCommandsPersonas*) base;
	result = "personas";
	return result;
}


static const gchar* folks_inspect_commands_personas_real_get_description (FolksInspectCommand* base) {
	const gchar* result;
	FolksInspectCommandsPersonas* self;
	self = (FolksInspectCommandsPersonas*) base;
	result = "Inspect the personas currently present in the aggregator";
	return result;
}


static const gchar* folks_inspect_commands_personas_real_get_help (FolksInspectCommand* base) {
	const gchar* result;
	FolksInspectCommandsPersonas* self;
	self = (FolksInspectCommandsPersonas*) base;
	result = "personas                  List all known personas.\n" "personas [persona UID]    Display the details of the " "specified persona.";
	return result;
}


static void folks_inspect_commands_personas_class_init (FolksInspectCommandsPersonasClass * klass) {
	folks_inspect_commands_personas_parent_class = g_type_class_peek_parent (klass);
	FOLKS_INSPECT_COMMAND_CLASS (klass)->run = folks_inspect_commands_personas_real_run;
	FOLKS_INSPECT_COMMAND_CLASS (klass)->complete_subcommand = folks_inspect_commands_personas_real_complete_subcommand;
	FOLKS_INSPECT_COMMAND_CLASS (klass)->get_name = folks_inspect_commands_personas_real_get_name;
	FOLKS_INSPECT_COMMAND_CLASS (klass)->get_description = folks_inspect_commands_personas_real_get_description;
	FOLKS_INSPECT_COMMAND_CLASS (klass)->get_help = folks_inspect_commands_personas_real_get_help;
}


static void folks_inspect_commands_personas_instance_init (FolksInspectCommandsPersonas * self) {
}


GType folks_inspect_commands_personas_get_type (void) {
	static volatile gsize folks_inspect_commands_personas_type_id__volatile = 0;
	if (g_once_init_enter (&folks_inspect_commands_personas_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FolksInspectCommandsPersonasClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folks_inspect_commands_personas_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolksInspectCommandsPersonas), 0, (GInstanceInitFunc) folks_inspect_commands_personas_instance_init, NULL };
		GType folks_inspect_commands_personas_type_id;
		folks_inspect_commands_personas_type_id = g_type_register_static (FOLKS_INSPECT_TYPE_COMMAND, "FolksInspectCommandsPersonas", &g_define_type_info, 0);
		g_once_init_leave (&folks_inspect_commands_personas_type_id__volatile, folks_inspect_commands_personas_type_id);
	}
	return folks_inspect_commands_personas_type_id__volatile;
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



