/* Generated by GOB (v2.0.15)   (do not edit directly) */

/* End world hunger, donate to the World Food Programme, http://www.wfp.org */

#define GOB_VERSION_MAJOR 2
#define GOB_VERSION_MINOR 0
#define GOB_VERSION_PATCHLEVEL 15

#define selfp (self->_priv)

#include <string.h> /* memset() */

#include "mn-auth-combo-box.h"

#include "mn-auth-combo-box-private.h"

#ifdef G_LIKELY
#define ___GOB_LIKELY(expr) G_LIKELY(expr)
#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr)
#else /* ! G_LIKELY */
#define ___GOB_LIKELY(expr) (expr)
#define ___GOB_UNLIKELY(expr) (expr)
#endif /* G_LIKELY */

#line 24 "src/mn-auth-combo-box.gob"

#include <glib/gi18n.h>
#if WITH_SASL
#include <sasl/sasl.h>
#include "mn-sasl.h"
#endif /* WITH_SASL */
#include "mn-util.h"

enum
{
  COLUMN_MECHANISM,
  COLUMN_LABEL,
  N_COLUMNS
};

#line 42 "mn-auth-combo-box.c"
/* self casting macros */
#define SELF(x) MN_AUTH_COMBO_BOX(x)
#define SELF_CONST(x) MN_AUTH_COMBO_BOX_CONST(x)
#define IS_SELF(x) MN_IS_AUTH_COMBO_BOX(x)
#define TYPE_SELF MN_TYPE_AUTH_COMBO_BOX
#define SELF_CLASS(x) MN_AUTH_COMBO_BOX_CLASS(x)

#define SELF_GET_CLASS(x) MN_AUTH_COMBO_BOX_GET_CLASS(x)

/* self typedefs */
typedef MNAuthComboBox Self;
typedef MNAuthComboBoxClass SelfClass;

/* here are local prototypes */
static void ___object_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void ___object_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
#line 0 "src/mn-auth-combo-box.gob"
static void mn_auth_combo_box_class_init (MNAuthComboBoxClass * c);
#line 61 "mn-auth-combo-box.c"
#line 83 "src/mn-auth-combo-box.gob"
static void mn_auth_combo_box_init (MNAuthComboBox * self);
#line 64 "mn-auth-combo-box.c"
#line 120 "src/mn-auth-combo-box.gob"
static int mn_auth_combo_box_sort_cb (GtkTreeModel * model, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data);
#line 67 "mn-auth-combo-box.c"

enum {
	PROP_0,
	PROP_ACTIVE_MECHANISM
};

/* pointer to the class of our parent */
static GtkComboBoxClass *parent_class = NULL;

/* Short form macros */
#define self_get_active_mechanism mn_auth_combo_box_get_active_mechanism
#define self_set_active_mechanism mn_auth_combo_box_set_active_mechanism
#define self_sort_cb mn_auth_combo_box_sort_cb
#define self_append mn_auth_combo_box_append
#define self_new mn_auth_combo_box_new
GType
mn_auth_combo_box_get_type (void)
{
	static GType type = 0;

	if ___GOB_UNLIKELY(type == 0) {
		static const GTypeInfo info = {
			sizeof (MNAuthComboBoxClass),
			(GBaseInitFunc) NULL,
			(GBaseFinalizeFunc) NULL,
			(GClassInitFunc) mn_auth_combo_box_class_init,
			(GClassFinalizeFunc) NULL,
			NULL /* class_data */,
			sizeof (MNAuthComboBox),
			0 /* n_preallocs */,
			(GInstanceInitFunc) mn_auth_combo_box_init,
			NULL
		};

		type = g_type_register_static (GTK_TYPE_COMBO_BOX, "MNAuthComboBox", &info, (GTypeFlags)0);
	}

	return type;
}

/* a macro for creating a new object of our type */
#define GET_NEW ((MNAuthComboBox *)g_object_new(mn_auth_combo_box_get_type(), NULL))

/* a function for creating a new object of our type */
#include <stdarg.h>
static MNAuthComboBox * GET_NEW_VARG (const char *first, ...) G_GNUC_UNUSED;
static MNAuthComboBox *
GET_NEW_VARG (const char *first, ...)
{
	MNAuthComboBox *ret;
	va_list ap;
	va_start (ap, first);
	ret = (MNAuthComboBox *)g_object_new_valist (mn_auth_combo_box_get_type (), first, ap);
	va_end (ap);
	return ret;
}

static void 
mn_auth_combo_box_class_init (MNAuthComboBoxClass * c G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::class_init"
	GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) c;

	parent_class = g_type_class_ref (GTK_TYPE_COMBO_BOX);

	g_object_class->get_property = ___object_get_property;
	g_object_class->set_property = ___object_set_property;
    {
	GParamSpec   *param_spec;

	param_spec = g_param_spec_string
		("active_mechanism" /* name */,
		 NULL /* nick */,
		 NULL /* blurb */,
		 NULL /* default_value */,
		 (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (g_object_class,
		PROP_ACTIVE_MECHANISM,
		param_spec);
    }
}
#undef __GOB_FUNCTION__
#line 83 "src/mn-auth-combo-box.gob"
static void 
mn_auth_combo_box_init (MNAuthComboBox * self G_GNUC_UNUSED)
{
#line 154 "mn-auth-combo-box.c"
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::init"
 {
#line 84 "src/mn-auth-combo-box.gob"

    GtkListStore *store;
    GtkCellRenderer *renderer;

    store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
    gtk_combo_box_set_model(GTK_COMBO_BOX(self), GTK_TREE_MODEL(store));
    g_object_unref(store);

    renderer = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(self), renderer, TRUE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(self), renderer,
				   "text", COLUMN_LABEL,
				   NULL);

    self_append(self, NULL, _("Autodetect"));
#if WITH_SASL
    if (mn_sasl_init(NULL))
      {
        const char **mechanisms;

	mechanisms = sasl_global_listmech();
	if (mechanisms)
	  {
	    int i;
	    for (i = 0; mechanisms[i]; i++)
	      self_append(self, mechanisms[i], mechanisms[i]);
	  }
      }
#endif /* WITH_SASL */

    gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), self_sort_cb, NULL, NULL);
    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);

    self_set_active_mechanism(self, NULL);
  
#line 193 "mn-auth-combo-box.c"
 }
}
#undef __GOB_FUNCTION__

static void
___object_set_property (GObject *object,
	guint property_id,
	const GValue *VAL G_GNUC_UNUSED,
	GParamSpec *pspec G_GNUC_UNUSED)
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::set_property"
{
	MNAuthComboBox *self G_GNUC_UNUSED;

	self = MN_AUTH_COMBO_BOX (object);

	switch (property_id) {
	case PROP_ACTIVE_MECHANISM:
		{
#line 44 "src/mn-auth-combo-box.gob"

      const char *mechanism = g_value_get_string(VAL);
      GtkTreeModel *model;
      GtkTreeIter iter;
      gboolean valid;

      model = gtk_combo_box_get_model(GTK_COMBO_BOX(self));

      MN_TREE_MODEL_FOREACH(valid, &iter, model)
	{
	  char *this_mech;
	  gboolean found;

	  gtk_tree_model_get(model, &iter, COLUMN_MECHANISM, &this_mech, -1);
	  found = (! this_mech && ! mechanism)
	    || (this_mech && mechanism && ! strcmp(this_mech, mechanism));
	  g_free(this_mech);

	  if (found)
	    {
	      gtk_combo_box_set_active_iter(GTK_COMBO_BOX(self), &iter);
	      break;
	    }
	}
    
#line 238 "mn-auth-combo-box.c"
		}
		break;
	default:
/* Apparently in g++ this is needed, glib is b0rk */
#ifndef __PRETTY_FUNCTION__
#  undef G_STRLOC
#  define G_STRLOC	__FILE__ ":" G_STRINGIFY (__LINE__)
#endif
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}
#undef __GOB_FUNCTION__

static void
___object_get_property (GObject *object,
	guint property_id,
	GValue *VAL G_GNUC_UNUSED,
	GParamSpec *pspec G_GNUC_UNUSED)
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::get_property"
{
	MNAuthComboBox *self G_GNUC_UNUSED;

	self = MN_AUTH_COMBO_BOX (object);

	switch (property_id) {
	case PROP_ACTIVE_MECHANISM:
		{
#line 70 "src/mn-auth-combo-box.gob"

      char *mechanism = NULL;
      GtkTreeIter iter;

      if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(self), &iter))
	{
	  GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(self));
	  gtk_tree_model_get(model, &iter, COLUMN_MECHANISM, &mechanism, -1);
	}

      g_value_take_string(VAL, mechanism);
    
#line 280 "mn-auth-combo-box.c"
		}
		break;
	default:
/* Apparently in g++ this is needed, glib is b0rk */
#ifndef __PRETTY_FUNCTION__
#  undef G_STRLOC
#  define G_STRLOC	__FILE__ ":" G_STRINGIFY (__LINE__)
#endif
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}
#undef __GOB_FUNCTION__


#line 70 "src/mn-auth-combo-box.gob"
gchar * 
mn_auth_combo_box_get_active_mechanism (MNAuthComboBox * self)
{
#line 300 "mn-auth-combo-box.c"
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::get_active_mechanism"
{
#line 42 "src/mn-auth-combo-box.gob"
		gchar* val; g_object_get (G_OBJECT (self), "active_mechanism", &val, NULL); return val;
}}
#line 306 "mn-auth-combo-box.c"
#undef __GOB_FUNCTION__

#line 44 "src/mn-auth-combo-box.gob"
void 
mn_auth_combo_box_set_active_mechanism (MNAuthComboBox * self, gchar * val)
{
#line 313 "mn-auth-combo-box.c"
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::set_active_mechanism"
{
#line 42 "src/mn-auth-combo-box.gob"
		g_object_set (G_OBJECT (self), "active_mechanism", val, NULL);
}}
#line 319 "mn-auth-combo-box.c"
#undef __GOB_FUNCTION__


#line 120 "src/mn-auth-combo-box.gob"
static int 
mn_auth_combo_box_sort_cb (GtkTreeModel * model, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data)
{
#line 327 "mn-auth-combo-box.c"
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::sort_cb"
{
#line 125 "src/mn-auth-combo-box.gob"
	
    char *mechanism_a;
    char *label_a;
    char *mechanism_b;
    char *label_b;
    int coll;

    gtk_tree_model_get(model, a,
		       COLUMN_MECHANISM, &mechanism_a,
		       COLUMN_LABEL, &label_a,
		       -1);
    gtk_tree_model_get(model, b,
		       COLUMN_MECHANISM, &mechanism_b,
		       COLUMN_LABEL, &label_b,
		       -1);

    /* put "autodetect" (NULL mechanism) on top of the list */
    if (mechanism_a && mechanism_b)
      coll = g_utf8_collate(label_a, label_b);
    else if (mechanism_a || mechanism_b)
      coll = mechanism_a ? 1 : -1;
    else
      coll = 0;

    g_free(mechanism_a);
    g_free(mechanism_b);

    return coll;
  }}
#line 360 "mn-auth-combo-box.c"
#undef __GOB_FUNCTION__

#line 155 "src/mn-auth-combo-box.gob"
void 
mn_auth_combo_box_append (MNAuthComboBox * self, const char * mechanism, const char * label)
{
#line 367 "mn-auth-combo-box.c"
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::append"
#line 155 "src/mn-auth-combo-box.gob"
	g_return_if_fail (self != NULL);
#line 155 "src/mn-auth-combo-box.gob"
	g_return_if_fail (MN_IS_AUTH_COMBO_BOX (self));
#line 155 "src/mn-auth-combo-box.gob"
	g_return_if_fail (label != NULL);
#line 375 "mn-auth-combo-box.c"
{
#line 157 "src/mn-auth-combo-box.gob"
	
    GtkTreeModel *model;
    GtkTreeIter iter;

    model = gtk_combo_box_get_model(GTK_COMBO_BOX(self));

    gtk_list_store_append(GTK_LIST_STORE(model), &iter);
    gtk_list_store_set(GTK_LIST_STORE(model), &iter,
		       COLUMN_MECHANISM, mechanism,
		       COLUMN_LABEL, label,
		       -1);
  }}
#line 390 "mn-auth-combo-box.c"
#undef __GOB_FUNCTION__

#line 170 "src/mn-auth-combo-box.gob"
GtkWidget * 
mn_auth_combo_box_new (void)
{
#line 397 "mn-auth-combo-box.c"
#define __GOB_FUNCTION__ "MN:Auth:Combo:Box::new"
{
#line 172 "src/mn-auth-combo-box.gob"
	
    return GTK_WIDGET(GET_NEW);
  }}
#line 404 "mn-auth-combo-box.c"
#undef __GOB_FUNCTION__
