/* -*- Mode: C; c-basic-offset: 4 -*-
 * pygobject - Python bindings for GObject
 * Copyright (C) 2008  Johan Dahlin
 *               2009  Gian Mario Tagliaretti
 *
 *   gfileinfo.override: module overrides for GFileInfo
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 * USA
 */

%%
headers

#ifndef G_TYPE_FILE_ATTRIBUTE_MATCHER
#define G_TYPE_FILE_ATTRIBUTE_MATCHER (_g_file_attribute_matcher_get_type ())

static GType _g_file_attribute_matcher_get_type (void)
{
  static GType our_type = 0;
  
  if (our_type == 0)
    our_type = g_boxed_type_register_static ("GFileAttributeMatcher",
                                (GBoxedCopyFunc)g_file_attribute_matcher_ref,
                                (GBoxedFreeFunc)g_file_attribute_matcher_unref);

  return our_type;
}
#endif

%%
override g_file_info_list_attributes kwargs
static PyObject *
_wrap_g_file_info_list_attributes(PyGObject *self, 
                                  PyObject  *args, 
				  PyObject  *kwargs)
{
    char *kwlist[] = { "name_space", NULL};
    gchar *name_space = NULL;
    gchar **names;
    gchar **n;
    PyObject *ret;
    
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				     "|z:gio.FileInfo.list_attributes",
				     kwlist, &name_space))
	return NULL;

    names = g_file_info_list_attributes(G_FILE_INFO(self->obj),
					name_space);

    ret = PyList_New(0);
    n = names;
    while (n && *n) {
        PyObject *item = PyString_FromString(n[0]);
        PyList_Append(ret, item);
        Py_DECREF(item);

        n++;
    }
    
    g_strfreev(names);
    return ret;
}
%%
override g_file_info_get_modification_time noargs
static PyObject *
_wrap_g_file_info_get_modification_time(PyGObject *self, PyObject *unused)
{
    GTimeVal timeval;

    g_file_info_get_modification_time(G_FILE_INFO(self->obj), &timeval);
    return pyglib_float_from_timeval(timeval);
}
%%
override g_file_info_set_modification_time kwargs
static PyObject *
_wrap_g_file_info_set_modification_time(PyGObject *self, 
                                        PyObject  *args, 
                                        PyObject  *kwargs)
{
    char *kwlist[] = { "mtime", NULL};
    double py_mtime = 0.0;
    GTimeVal ttime, *mtime;
    
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "d:gio.FileInfo.set_modification_time",
                                     kwlist, &py_mtime))
        return NULL;

    if (py_mtime > 0.0) {
	ttime.tv_sec = (glong) py_mtime;
	ttime.tv_usec = (glong)((py_mtime - ttime.tv_sec) * G_USEC_PER_SEC);
        mtime = &ttime;
    } else if (py_mtime == 0.0) {
	mtime = NULL;
    } else {
        PyErr_SetString(PyExc_ValueError, "mtime must be >= 0.0");
        return NULL;
    }
    
    g_file_info_set_modification_time(G_FILE_INFO(self->obj), mtime);
    
    Py_INCREF(Py_None);
    return Py_None;
}

/* GFileInfo.get_attribute_data: No ArgType for GFileAttributeType* */
/* GFileInfo.set_attribute: No ArgType for gpointer */
