/* ====================================================================
 * FTD4Linux Software License, Version 1.0
 *
 * Copyright (c) 2000-2004 The FTD4Linux Development Team.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        FTD4Linux Development Team (http://www.ftd4linux.2y.net/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "FTD" and "FTD4Linux" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact alguno@ftd4linux.2y.net.
 *
 * 5. Products derived from this software may not be called "FTD4Linux",
 *    nor may "FTD4Linux" appear in their name, without prior written
 *    permission of the FTD4Linux Development Team.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE FTD4LINUX DEVELOPMENT TEAM OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include "ftd_gui_main.h"
#include "ftd_gui_status_filter.h"

static FtdList *active_status_filter = NULL;

void
ftd_gui_status_filter_new(void)
{
    FtdGuiStatusFilter *status_filter = g_malloc0(sizeof(FtdGuiStatusFilter));
    GtkWidget *vbox2;
    GtkWidget *hbox1;
    GtkWidget *toggleAnn;
    GtkWidget *image7;
    GtkWidget *toggleUpl;
    GtkWidget *image8;
    GtkWidget *toggleReady;
    GtkWidget *image9;
    GtkWidget *toggleUnsupp;
    GtkWidget *image10;
    GtkWidget *toggleSpot;
    GtkWidget *image11;
    GtkWidget *toggleDeleted;
    GtkWidget *image12;
    GtkWidget *button6;
    GtkWidget *label1;
    char *volledigeFilename;
    FtdList *list;

    gui->worksheet->sidebar->status_filter = status_filter;

    status_filter->widget = gtk_frame_new (NULL);
    gtk_widget_show (status_filter->widget);
    gtk_container_set_border_width (GTK_CONTAINER (status_filter->widget), 4);

    vbox2 = gtk_vbox_new (FALSE, 4);
    gtk_widget_show (vbox2);
    gtk_container_add (GTK_CONTAINER (status_filter->widget), vbox2);
    gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);

    hbox1 = gtk_hbox_new (TRUE, 0);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);

    toggleAnn = gtk_toggle_button_new ();
    gtk_widget_show (toggleAnn);
    gtk_box_pack_start (GTK_BOX (hbox1), toggleAnn, FALSE, FALSE, 0);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggleAnn), TRUE);

    volledigeFilename = ftd_file_parse_data_dir("/images/brown.gif");
    image7 = gtk_image_new_from_file(volledigeFilename);
    g_free(volledigeFilename);
    gtk_widget_show (image7);
    gtk_container_add (GTK_CONTAINER (toggleAnn), image7);

    toggleUpl = gtk_toggle_button_new ();
    gtk_widget_show (toggleUpl);
    gtk_box_pack_start (GTK_BOX (hbox1), toggleUpl, FALSE, FALSE, 0);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggleUpl), TRUE);

    volledigeFilename = ftd_file_parse_data_dir("/images/green.gif");
    image8 = gtk_image_new_from_file(volledigeFilename);
    g_free(volledigeFilename);
    gtk_widget_show (image8);
    gtk_container_add (GTK_CONTAINER (toggleUpl), image8);

    toggleReady = gtk_toggle_button_new ();
    gtk_widget_show (toggleReady);
    gtk_box_pack_start (GTK_BOX (hbox1), toggleReady, FALSE, FALSE, 0);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggleReady), TRUE);

    volledigeFilename = ftd_file_parse_data_dir("/images/gray.gif");
    image9 = gtk_image_new_from_file(volledigeFilename);
    g_free(volledigeFilename);
    gtk_widget_show (image9);
    gtk_container_add (GTK_CONTAINER (toggleReady), image9);

    toggleUnsupp = gtk_toggle_button_new ();
    gtk_widget_show (toggleUnsupp);
    gtk_box_pack_start (GTK_BOX (hbox1), toggleUnsupp, FALSE, FALSE, 0);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggleUnsupp), TRUE);

    volledigeFilename = ftd_file_parse_data_dir("/images/red.gif");
    image10 = gtk_image_new_from_file(volledigeFilename);
    g_free(volledigeFilename);
    gtk_widget_show (image10);
    gtk_container_add (GTK_CONTAINER (toggleUnsupp), image10);

    toggleSpot = gtk_toggle_button_new ();
    gtk_widget_show (toggleSpot);
    gtk_box_pack_start (GTK_BOX (hbox1), toggleSpot, FALSE, FALSE, 0);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggleSpot), TRUE);

    volledigeFilename = ftd_file_parse_data_dir("/images/spot.gif");
    image11 = gtk_image_new_from_file(volledigeFilename);
    g_free(volledigeFilename);
    gtk_widget_show (image11);
    gtk_container_add (GTK_CONTAINER (toggleSpot), image11);

    toggleDeleted = gtk_toggle_button_new ();
    gtk_widget_show (toggleDeleted);
    gtk_box_pack_start (GTK_BOX (hbox1), toggleDeleted, FALSE, FALSE, 0);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggleDeleted), TRUE);

    volledigeFilename = ftd_file_parse_data_dir("/images/kill.gif");
    image12 = gtk_image_new_from_file(volledigeFilename);
    g_free(volledigeFilename);
    gtk_widget_show (image12);
    gtk_container_add (GTK_CONTAINER (toggleDeleted), image12);

    button6 = gtk_button_new_with_mnemonic ("Pas wijzigingen toe");
    gtk_widget_set_sensitive(button6, FALSE);
    gtk_widget_show (button6);
    gtk_box_pack_start (GTK_BOX (vbox2), button6, FALSE, TRUE, 0);

    label1 = gtk_label_new ("Statusfilters");
    gtk_widget_show (label1);
    gtk_frame_set_label_widget (GTK_FRAME (status_filter->widget), label1);
    gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);

    active_status_filter = ftd_config_get()->statusList;
}

static void
ftd_gui_status_filter_on_toggle(GtkWidget *caller, gpointer data)
{
    FtdList *list;
    int status = GPOINTER_TO_INT(data);

    list = active_status_filter;
    while (list) {
        int elem_status = GPOINTER_TO_INT(ftd_list_value(list));

        if (status == elem_status) {
            // DOE IETS!!!
        }

        list = ftd_list_next(list);
    }

    // Element bestaat nog niet in de lijst, toevoegen
    active_status_filter = ftd_list_append(active_status_filter, GINT_TO_POINTER(status));
}

FtdList *
ftd_gui_status_filter_get_filter(void)
{
    if (active_status_filter) {
        return ftd_list_copy(active_status_filter);
    } else {
        return NULL;
    }
}
