/* $Id: exo.override 18442 2005-10-27 18:12:00Z benny $ */
/* vim:set ts=2 sw=2 et ai syntax=c cindent: */
/*-
 * Copyright (c) 2005 os-cillation e.K.
 *
 * Written by Benedikt Meurer <benny@xfce.org>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

%%
headers
#include <Python.h>
#include <pygtk/pygtk.h>
#include <exo/exo.h>

/* mark internal symbols with G_GNUC_INTERNAL */
void         exo_add_constants             (PyObject    *module,
                                            const gchar *strip_prefix) G_GNUC_INTERNAL;
void         exo_register_classes          (PyObject    *d) G_GNUC_INTERNAL;
GtkTreePath *pygtk_tree_path_from_pyobject (PyObject    *object) G_GNUC_INTERNAL;
PyObject    *pygtk_tree_path_to_pyobject   (GtkTreePath *path) G_GNUC_INTERNAL;

%%
modulename exo

%%
import gobject.GObject as PyGObject_Type
import gtk.gdk.Window as PyGdkWindow_Type
import gtk.CellRenderer as PyGtkCellRenderer_Type
import gtk.CellRendererText as PyGtkCellRendererText_Type
import gtk.Container as PyGtkContainer_Type
import gtk.Dialog as PyGtkDialog_Type
import gtk.Label as PyGtkLabel_Type
import gtk.IconTheme as PyGtkIconTheme_Type
import gtk.TreeModel as PyGtkTreeModel_Type
import gtk.UIManager as PyGtkUIManager_Type
import gtk.VBox as PyGtkVBox_Type

%%
ignore-glob
  *_get_type

%%
ignore
  exo_icon_bar_new
  exo_icon_view_new
  exo_icon_view_selected_foreach
  exo_toolbars_editor_new
  exo_toolbars_view_new

%%
override exo_icon_view_get_selected_items kwargs
static PyObject*
_wrap_exo_icon_view_get_selected_items (PyGObject *self,
                                        PyObject  *args,
                                        PyObject  *kwargs)
{
  PyObject *result;
  PyObject *item;
  GList    *items;
  GList    *lp;

  items = exo_icon_view_get_selected_items (EXO_ICON_VIEW (self->obj));

  result = PyList_New (0);
  if (G_UNLIKELY (result == NULL))
    return NULL;

  for (lp = items; lp != NULL; lp = lp->next)
    {
      item = pygtk_tree_path_to_pyobject (lp->data);
      PyList_Append (result, item);
      Py_DECREF (item);

      gtk_tree_path_free (lp->data);
    }

  g_list_free (items);

  return result;
}

%%
override exo_toolbars_model_get_actions
static PyObject*
_wrap_exo_toolbars_model_get_actions (PyGObject *self)
{
  PyObject *result;
  PyObject *value;
  gchar   **actions;
  guint     n;

  actions = exo_toolbars_model_get_actions (EXO_TOOLBARS_MODEL (self->obj));
  if (G_LIKELY (actions != NULL))
    {
      result = PyList_New (0);
      if (G_UNLIKELY (result == NULL))
        return NULL;

      for (n = 0; actions[n] != NULL; ++n)
        {
          value = Py_BuildValue ("s", actions[n]);
          PyList_Append (result, value);
          Py_DECREF (value);
        }

      g_strfreev (actions);
    }
  else
    {
      Py_INCREF (Py_None);
      result = Py_None;
    }

  return result;
}

%%
override exo_toolbars_model_set_actions kwargs
static PyObject*
_wrap_exo_toolbars_model_set_actions (PyGObject *self,
                                      PyObject  *args,
                                      PyObject  *kwargs)
{
  static char *kwlist[] = { "args", NULL };
  PyObject    *sequence;
  PyObject    *item;
  gchar      **actions;
  guint        n_actions;
  guint        n;

  if (!PyArg_ParseTupleAndKeywords (args, kwargs,
                                    "O:ExoToolbarsModel.set_actions",
                                    kwlist, &sequence))
    return NULL;

  if (!PySequence_Check (sequence))
    {
      PyErr_SetString (PyExc_TypeError, "first argument must be a sequence");
      return NULL;
    }

  n_actions = PySequence_Length (sequence);
  actions = g_new0 (gchar *, n_actions + 1);

  for (n = 0; n < n_actions; ++n)
    {
      item = PySequence_GetItem (sequence, n);
      Py_DECREF (item);

      if (!PyString_Check (item) && !PyUnicode_Check (item))
        {
          PyErr_SetString (PyExc_TypeError, "sequence item "
                           "not a string or unicode object");
          g_strfreev (actions);
          return NULL;
        }

      actions[n] = g_strdup (PyString_AsString (item));
    }

  exo_toolbars_model_set_actions (EXO_TOOLBARS_MODEL (self->obj),
                                  actions, n_actions);
  g_strfreev (actions);

  Py_INCREF (Py_None);
  return Py_None;
}

%%
override exo_toolbars_model_get_item_type kwargs
static PyObject*
_wrap_exo_toolbars_model_get_item_type (PyGObject *self,
                                        PyObject  *args,
                                        PyObject  *kwargs)
{
  static char *kwlist[] = { "dnd_type", NULL };
  PyObject    *object;
  GdkAtom      type;
  gchar       *result;

  if (!PyArg_ParseTupleAndKeywords (args, kwargs,
                                    "O:ExoToolbarsModel.get_item_type",
                                    kwlist, &object))
    return NULL;

  if (G_UNLIKELY (object == NULL))
    type = NULL;
  else if (PyString_Check (object))
    type = gdk_atom_intern (PyString_AsString (object), FALSE);
  else if (PyGdkAtom_Check (object))
    type = PyGdkAtom_Get (object);
  else
    {
      PyErr_SetString (PyExc_TypeError, "unable to convert argument to GdkAtom");
      return NULL;
    }

  result = exo_toolbars_model_get_item_type (EXO_TOOLBARS_MODEL (self->obj), type);
  if (G_LIKELY (result != NULL))
    {
      object = PyString_FromString (result);
      g_free (result);
    }
  else
    {
      object = Py_None;
      Py_INCREF (Py_None);
    }

  return object;
}

%%
override exo_toolbars_model_item_nth kwargs
static PyObject*
_wrap_exo_toolbars_model_item_nth (PyGObject *self,
                                   PyObject  *args,
                                   PyObject  *kwargs)
{
  static char *kwlist[] = { "toolbar_position", "item_position", NULL };
  const gchar *type;
  const gchar *id;
  gboolean     is_separator;
  gint         toolbar_position;
  gint         item_position;
  

  if (!PyArg_ParseTupleAndKeywords (args, kwargs,
                                    "ii:ExoToolbarsModel.item_nth",
                                    kwlist, &toolbar_position, &item_position))
    return NULL;

  exo_toolbars_model_item_nth (EXO_TOOLBARS_MODEL (self->obj),
                               toolbar_position, item_position,
                               &is_separator, &id, &type);

  return Py_BuildValue ("(iss)", is_separator, id, type);
}

%%
override exo_xsession_client_get_restart_command
static PyObject*
_wrap_exo_xsession_client_get_restart_command (PyGObject *self)
{
  PyObject *result;
  PyObject *value;
  gchar   **argv;
  gint      argc;
  gint      n;

  if (exo_xsession_client_get_restart_command (EXO_XSESSION_CLIENT (self->obj),
                                               &argv, &argc))
    {
      result = PyList_New (0);
      if (G_UNLIKELY (result == NULL))
        return NULL;

      for (n = 0; n < argc; ++n)
        {
          value = Py_BuildValue ("s", argv[n]);
          PyList_Append (result, value);
          Py_DECREF (value);
        }

      g_strfreev (argv);
    }
  else
    {
      Py_INCREF (Py_None);
      result = Py_None;
    }

  return result;
}

%%
override exo_xsession_client_set_restart_command kwargs
static PyObject*
_wrap_exo_xsession_client_set_restart_command (PyGObject *self,
                                               PyObject  *args,
                                               PyObject  *kwargs)
{
  static char *kwlist[] = { "args", NULL };
  PyObject    *sequence;
  PyObject    *item;
  gchar      **argv;
  gint         argc;
  gint         n;

  if (!PyArg_ParseTupleAndKeywords (args, kwargs,
                                    "0:ExoXsessionClient.set_restart_command",
                                    kwlist, &sequence))
    return NULL;

  if (!PySequence_Check (sequence))
    {
      PyErr_SetString (PyExc_TypeError, "first argument must be a sequence");
      return NULL;
    }

  argc = PySequence_Length (sequence);
  argv = g_new0 (gchar *, argc + 1);

  for (n = 0; n < argc; ++n)
    {
      item = PySequence_GetItem (sequence, n);
      Py_DECREF (item);

      if (!PyString_Check (item) && !PyUnicode_Check (item))
        {
          PyErr_SetString (PyExc_TypeError, "sequence item "
                           "not a string or unicode object");
          g_strfreev (argv);
          return NULL;
        }

      argv[n] = g_strdup (PyString_AsString (item));
    }

  exo_xsession_client_set_restart_command (EXO_XSESSION_CLIENT (self->obj),
                                           argv, argc);
  g_strfreev (argv);

  Py_INCREF (Py_None);
  return Py_None;
}
