/*
This source file is part of Scol
For the latest info, see http://www.scolring.org

Copyright (c) 2010 Stephane Bisaro, aka Iri <iri@irizone.net>

This program 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 of the License, or (at your option) any later
version.

This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt

For others informations, please contact us from http://www.scolring.org/
*/



#include "../include/scol_gtk_style.h"


#ifndef SCOL_GTK_2
int scol_gtkStyleCssLoad (mmachine m, int flag)
{
    int mchannel, mfilename;
    gchar *filename;
    gboolean b;
    GtkCssProvider *ccsp;
    GError *err = NULL;

    g_message ("scol_gtkStyleCssLoad : entering");

    mfilename = MMpull (m);
    mchannel = MMget (m, 0);
    if (mchannel == NIL)
    {
        g_warning ("scol_gtkStyleCssLoad error : channel is nil");
        MMpull (m);
        MMpush (m, NIL);
        return 0;
    }
    if (mfilename == NIL)
    {
        g_warning ("scol_gtkStyleCssLoad error : filename is nil");
        MMpull (m);
        MMpush (m, NIL);
        return 0;
    }
    filename = MMstartstr (m, MTOP (mfilename));

    ccsp = gtk_css_provider_new ();
    if (flag)
        b = gtk_css_provider_load_from_data (ccsp, filename, -1, &err);
    else
        b = gtk_css_provider_load_from_path (ccsp, filename, &err);
    if ((b == FALSE) || (err != NULL))
    {
        g_warning ("scol_gtkStyleCssLoad error : file could not be loaded");
        g_error_free (err);
        g_object_unref (ccsp);
        MMpull (m);
        MMpush (m, NIL);
        return 0;
    }
/* not finished ... */
}
int SCOL_gtkStyleCssLoadP (mmachine m)
{
    return scol_gtkStyleCssLoad (m, 0);
}

int SCOL_gtkStyleCssLoadS (mmachine m)
{
    return scol_gtkStyleCssLoad (m, 1);
}
#else
int SCOL_gtkStyleCssLoadP (mmachine m)
{
    MMpull (m);
    MMpull (m);
    MMpush (m, NIL);
    return 0;
}

int SCOL_gtkStyleCssLoadS (mmachine m)
{
    MMpull (m);
    MMpull (m);
    MMpush (m, NIL);
    return 0;
}
#endif


/* API définitions : */

char* gtk_style_name[GTK_STYLE_PKG_NB]=
{
    "_gtkStyleCssLoadP",
    "_gtkStyleCssLoadS"
};

int (*gtk_style_fun[GTK_STYLE_PKG_NB])(mmachine m)=
{
    SCOL_gtkStyleCssLoadP,
    SCOL_gtkStyleCssLoadS
};

int gtk_style_narg[GTK_STYLE_PKG_NB]=
{
    2,
    2
};

char* gtk_style_type[GTK_STYLE_PKG_NB]=
{
    "fun [Chn P] ObjGtkStyle",
    "fun [Chn S] ObjGtkStyle"
};

int SCOLloadGTKstyle (mmachine m)
{
    int k;

    MMechostr (0, "SCOLloadGTKstyle : entering\n");

    k = PKhardpak (m, "GTK2DstyleEngine", GTK_STYLE_PKG_NB, gtk_style_name, gtk_style_fun, gtk_style_narg, gtk_style_type);
    return k;
}

