/* ====================================================================
 * 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_post.h"
#include "ftd_gui_center.h"
#include "ftd_gui_errhandler.h"
#include "ftd_gui_compat_macros.h"

gboolean     ftd_gui_post_destroy(GtkWidget *caller, gpointer data);
void         ftd_gui_post_switch_category(GtkWidget *caller, gpointer data);
void         ftd_gui_post_test_afbeelding(GtkWidget *caller, gpointer data);
void         ftd_gui_post_verder1(GtkWidget *caller, gpointer data);
void         ftd_gui_post_bestanden_changed(GtkWidget *caller, gpointer data);
void         ftd_gui_post_par_changed(GtkWidget *caller, gpointer data);
void         ftd_gui_post_verder2(GtkWidget *caller, gpointer data);
void         ftd_gui_post_verder3(GtkWidget *caller, gpointer data);
void         ftd_gui_post_open_playlist(GtkWidget *caller, gpointer data);
void         ftd_gui_post_clear_playlist(GtkWidget *caller, gpointer data);
void         ftd_gui_post_verder4(GtkWidget *caller, gpointer data);
void         ftd_gui_post_switch_page(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data);
void         ftd_gui_post_versturen(GtkWidget *caller, gpointer data);
gboolean     ftd_gui_post_versturen_impl(gpointer data);
gboolean     ftd_gui_post_check_tab1();
gboolean     ftd_gui_post_check_tab2();
gboolean     ftd_gui_post_check_tab3();
void         ftd_gui_post_titel_changed(GtkWidget *caller, gpointer data);
void         ftd_gui_post_aantal_par_blokken_changed(GtkWidget *caller, gpointer data);
void         ftd_gui_post_blocksize_changed(GtkWidget *caller, gpointer data);
void         ftd_gui_post_parse_m3u_data(FtdString *data);
gint         ftd_gui_post_tree_sortable_compare_string(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data);
void         ftd_gui_post_send_callback(FtdSendState status);
void         ftd_gui_post_import(GtkWidget *caller, gpointer data);
void         ftd_gui_post_export(GtkWidget *caller, gpointer data);
FtdEvent    *ftd_gui_post_generate_event(void);

void
ftd_gui_post_new(void)
{
    FtdGuiPost *post = (FtdGuiPost *) g_malloc0(sizeof(FtdGuiPost));
    GtkWidget *hboxCat;
    GtkWidget *hbox1;
    GtkWidget *image1;
    GtkWidget *label6;
    GtkWidget *frame1;
    GtkWidget *label7;
    GtkWidget *frame2;
    GtkWidget *label8;
    GtkWidget *frame5;
    GtkWidget *hbox5;
    GtkWidget *label12;
    GtkWidget *hbox2;
    GtkWidget *frame3;
    GtkWidget *label9;
    GtkWidget *frame4;
    GtkWidget *label10;
    GtkWidget *hbuttonbox1;
    GtkWidget *alignment1;
    GtkWidget *hbox4;
    GtkWidget *image2;
    GtkWidget *label11;
    GtkWidget *label1;
    GtkWidget *frame6;
    GtkWidget *table1;
    GtkWidget *label16;
    GtkObject *spinbutton1_adj;
    GtkObject *spinbutton2_adj;
    GtkWidget *image3;
    GtkWidget *image4;
    GtkWidget *image5;
    GtkWidget *label15;
    GtkWidget *hbox7;
    GtkWidget *image6;
    GtkWidget *label21;
    GtkWidget *hbox8;
    GSList *radiogroupPar = NULL;
    GtkWidget *vbox5;
    GtkWidget *frame7;
    GtkWidget *hbox10;
    GtkObject *spinbutton3_adj;
    GtkObject *spinbutton4_adj;
    GtkWidget *label23;
    GtkWidget *hbuttonbox2;
    GtkWidget *alignment2;
    GtkWidget *hbox9;
    GtkWidget *image7;
    GtkWidget *label22;
    GtkWidget *label2;
    GtkWidget *frame8;
    GtkWidget *hbox11;
    GtkWidget *label26;
    GtkWidget *scrolledwindow2;
    GtkWidget *hbuttonbox3;
    GtkWidget *alignment3;
    GtkWidget *hbox12;
    GtkWidget *image8;
    GtkWidget *label27;
    GtkWidget *label3;
    GtkWidget *frame9;
    GtkWidget *hbox13;
    GSList *radiogroupPostType = NULL;
    GtkWidget *label28;
    GtkWidget *frame10;
    GtkWidget *scrolledwindow3;
    GtkWidget *label29;
    GtkWidget *frame11;
    GtkWidget *scrolledwindow4;
    GtkWidget *label30;
    GtkWidget *hbuttonbox4;
    GtkWidget *alignment4;
    GtkWidget *hbox14;
    GtkWidget *image9;
    GtkWidget *label31;
    GtkWidget *label4;
    GtkWidget *frame12;
    GtkWidget *scrolledwindow5;
    GtkWidget *label32;
    GtkWidget *frame13;
    GtkWidget *scrolledwindow6;
    GtkWidget *label33;
    GtkWidget *hbox15;
    GtkWidget *label34;
    GtkWidget *hbuttonbox5;
    GtkWidget *alignment5;
    GtkWidget *hbox16;
    GtkWidget *image10;
    GtkWidget *label35;
    GtkWidget *label5;
    GtkRequisition req;
    GtkWidget *image;

    FtdList *list;

    g_assert(gui);
    g_assert(gui->post == NULL);

    gui->post = post;

    post->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (post->window), "Toevoegen van een post");
    gtk_window_set_position (GTK_WINDOW (post->window), GTK_WIN_POS_CENTER_ALWAYS);
    gtk_window_set_modal (GTK_WINDOW (post->window), TRUE);
    gtk_window_set_default_size (GTK_WINDOW (post->window), -1, 580);

    post->tabs = gtk_notebook_new ();
    gtk_widget_show (post->tabs);
    gtk_container_add (GTK_CONTAINER (post->window), post->tabs);
    gtk_container_set_border_width (GTK_CONTAINER (post->tabs), 6);
    g_signal_connect( G_OBJECT( post->tabs ), "switch-page", G_CALLBACK( ftd_gui_post_switch_page ), NULL );

    post->tab1 = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (post->tab1);
    gtk_container_add (GTK_CONTAINER (post->tabs), post->tab1);
    gtk_container_set_border_width (GTK_CONTAINER (post->tab1), 5);

    hbox1 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (post->tab1), hbox1, FALSE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox1), 5);

    image1 = gtk_image_new_from_stock ("gtk-info", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image1);
    gtk_box_pack_start (GTK_BOX (hbox1), image1, FALSE, FALSE, 2);
    gtk_misc_set_padding (GTK_MISC (image1), 6, 0);

    label6 = gtk_label_new ("Je staat op het punt om een post aan te melden op FTD. Vergeet niet dat het aanmelden van posts\nop FTD gebonden is aan regels. Overtreden van deze regels kan leiden tot maatregelen ter bescherming\nvan de FTD community. Kijk op http://www.ftd.nu/postregels om de meest actuele postregels te bekijken!");
    gtk_widget_show (label6);
    gtk_box_pack_start (GTK_BOX (hbox1), label6, TRUE, TRUE, 0);

    frame1 = gtk_frame_new (NULL);
    gtk_widget_show (frame1);
    gtk_box_pack_start (GTK_BOX (post->tab1), frame1, FALSE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame1), 6);
    gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_OUT);

    post->entryTitel = gtk_entry_new ();
    gtk_widget_show (post->entryTitel);
    gtk_container_add (GTK_CONTAINER (frame1), post->entryTitel);
    g_signal_connect( G_OBJECT( post->entryTitel ), "changed", G_CALLBACK( ftd_gui_post_titel_changed ), NULL );

    label7 = gtk_label_new ("Titel");
    gtk_widget_show (label7);
    gtk_frame_set_label_widget (GTK_FRAME (frame1), label7);
    gtk_label_set_use_markup (GTK_LABEL (label7), TRUE);

    frame2 = gtk_frame_new (NULL);
    gtk_widget_show (frame2);
    gtk_box_pack_start (GTK_BOX (post->tab1), frame2, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame2), 6);
    gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_OUT);

    post->entryURL = gtk_entry_new ();
    gtk_widget_show (post->entryURL);
    gtk_container_add (GTK_CONTAINER (frame2), post->entryURL);
    gtk_entry_set_text( GTK_ENTRY( post->entryURL ), "http://" );

    label8 = gtk_label_new ("URL");
    gtk_widget_show (label8);
    gtk_frame_set_label_widget (GTK_FRAME (frame2), label8);
    gtk_label_set_use_markup (GTK_LABEL (label8), TRUE);

    frame5 = gtk_frame_new (NULL);
    gtk_widget_show (frame5);
    gtk_box_pack_start (GTK_BOX (post->tab1), frame5, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame5), 6);
    gtk_frame_set_shadow_type (GTK_FRAME (frame5), GTK_SHADOW_OUT);

    hbox5 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox5);
    gtk_container_add (GTK_CONTAINER (frame5), hbox5);

    post->entryPlaatje = gtk_entry_new ();
    gtk_widget_show (post->entryPlaatje);
    gtk_box_pack_start (GTK_BOX (hbox5), post->entryPlaatje, TRUE, TRUE, 6);
    gtk_entry_set_text( GTK_ENTRY( post->entryPlaatje ), "http://" );

    post->buttonTestAfbeelding = gtk_button_new_with_mnemonic ("Testen");
    gtk_widget_show (post->buttonTestAfbeelding);
    gtk_box_pack_start (GTK_BOX (hbox5), post->buttonTestAfbeelding, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (post->buttonTestAfbeelding), 6);
    g_signal_connect_after( G_OBJECT( post->buttonTestAfbeelding ), "clicked", G_CALLBACK(ftd_gui_post_test_afbeelding), NULL );

    label12 = gtk_label_new ("Plaatje op het web (.gif / .jpg / .bmp)");
    gtk_widget_show (label12);
    gtk_frame_set_label_widget (GTK_FRAME (frame5), label12);
    gtk_label_set_use_markup (GTK_LABEL (label12), TRUE);

    hbox2 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox2);
    gtk_box_pack_start (GTK_BOX (post->tab1), hbox2, FALSE, TRUE, 0);

    frame3 = gtk_frame_new (NULL);
    gtk_widget_show (frame3);
    gtk_box_pack_start (GTK_BOX (hbox2), frame3, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame3), 6);
    gtk_frame_set_shadow_type (GTK_FRAME (frame3), GTK_SHADOW_OUT);

    hboxCat = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hboxCat);
    gtk_container_add (GTK_CONTAINER (frame3), hboxCat);
    gtk_container_set_border_width (GTK_CONTAINER (hboxCat), 6);

    post->comboboxCat = gtk_combo_box_new_text ();
    gtk_widget_show (post->comboboxCat);
    gtk_box_pack_start (GTK_BOX (hboxCat), post->comboboxCat, TRUE, TRUE, 6);
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxCat), "Beeld");
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxCat), "Geluid");
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxCat), "Spelletjes");
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxCat), "Applicaties");

    g_signal_connect(G_OBJECT(post->comboboxCat), "changed", G_CALLBACK(ftd_gui_post_switch_category), NULL);

// begin subcategorie
    post->labelSubcategorieTag = gtk_label_new ("");
    gtk_widget_show (post->labelSubcategorieTag);
    gtk_box_pack_start (GTK_BOX (hboxCat), post->labelSubcategorieTag, FALSE, FALSE, 6);
    gtk_label_set_use_markup (GTK_LABEL (post->labelSubcategorieTag), TRUE);

    post->comboboxSCat = gtk_combo_box_new_text ();
    gtk_widget_show (post->comboboxSCat);
    gtk_box_pack_start (GTK_BOX (hboxCat), post->comboboxSCat, TRUE, TRUE, 6);

    label9 = gtk_label_new ("(sub) Categorie");
    gtk_widget_show (label9);
    gtk_frame_set_label_widget (GTK_FRAME (frame3), label9);
    gtk_label_set_use_markup (GTK_LABEL (label9), TRUE);
// eind subcategorie

    frame4 = gtk_frame_new (NULL);
    gtk_widget_show (frame4);
    gtk_box_pack_start (GTK_BOX (hbox2), frame4, FALSE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame4), 6);
    gtk_frame_set_shadow_type (GTK_FRAME (frame4), GTK_SHADOW_OUT);

    post->entryTag = gtk_entry_new ();
    gtk_widget_show (post->entryTag);
    gtk_container_add (GTK_CONTAINER (frame4), post->entryTag);

    label10 = gtk_label_new ("Tag");
    gtk_widget_show (label10);
    gtk_frame_set_label_widget (GTK_FRAME (frame4), label10);
    gtk_label_set_use_markup (GTK_LABEL (label10), TRUE);

    post->hboxTags = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (post->hboxTags);
    gtk_box_pack_start (GTK_BOX (post->tab1), post->hboxTags, TRUE, TRUE, 0);

    // Activeer de optie 'Beeld' als standaardcategorie
    gtk_combo_box_set_active(GTK_COMBO_BOX(post->comboboxCat), 0);

    hbuttonbox1 = gtk_hbutton_box_new ();
    gtk_widget_show (hbuttonbox1);
    gtk_box_pack_start (GTK_BOX (post->tab1), hbuttonbox1, FALSE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox1), 6);
    gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_SPREAD);

    image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image);

    post->buttonImport = gtk_button_new_with_label("Gegevens importeren uit extern bestand");
#if GTK_CHECK_VERSION(2,6,0)
    gtk_button_set_image(GTK_BUTTON(post->buttonImport), image);
#endif
    gtk_widget_show(post->buttonImport);
    gtk_container_add(GTK_CONTAINER(hbuttonbox1), post->buttonImport);
    g_signal_connect(G_OBJECT(post->buttonImport), "clicked", G_CALLBACK(ftd_gui_post_import), NULL);

    post->buttonVerder1 = gtk_button_new ();
    gtk_widget_show (post->buttonVerder1);
    gtk_container_add (GTK_CONTAINER (hbuttonbox1), post->buttonVerder1);
    GTK_WIDGET_SET_FLAGS (post->buttonVerder1, GTK_CAN_DEFAULT);
    g_signal_connect_after( G_OBJECT(post->buttonVerder1), "clicked", G_CALLBACK( ftd_gui_post_verder1 ), NULL );

    alignment1 = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_widget_show (alignment1);
    gtk_container_add (GTK_CONTAINER (post->buttonVerder1), alignment1);

    hbox4 = gtk_hbox_new (FALSE, 2);
    gtk_widget_show (hbox4);
    gtk_container_add (GTK_CONTAINER (alignment1), hbox4);

    image2 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image2);
    gtk_box_pack_start (GTK_BOX (hbox4), image2, FALSE, FALSE, 0);

    label11 = gtk_label_new_with_mnemonic ("Verder");
    gtk_widget_show (label11);
    gtk_box_pack_start (GTK_BOX (hbox4), label11, FALSE, FALSE, 0);

    label1 = gtk_label_new ("Basisinfo");
    gtk_widget_show (label1);
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (post->tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (post->tabs), 0), label1);

    post->tab2 = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (post->tab2);
    gtk_container_add (GTK_CONTAINER (post->tabs), post->tab2);
    gtk_container_set_border_width (GTK_CONTAINER (post->tab2), 6);

    frame6 = gtk_frame_new (NULL);
    gtk_widget_show (frame6);
    gtk_box_pack_start (GTK_BOX (post->tab2), frame6, FALSE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame6), 6);
    gtk_frame_set_shadow_type (GTK_FRAME (frame6), GTK_SHADOW_OUT);

    table1 = gtk_table_new (4, 6, FALSE);
    gtk_widget_show (table1);
    gtk_container_add (GTK_CONTAINER (frame6), table1);
    gtk_container_set_border_width (GTK_CONTAINER (table1), 6);

    post->entryBestandsnaam = gtk_entry_new ();
    gtk_widget_show (post->entryBestandsnaam);
    gtk_table_attach (GTK_TABLE (table1), post->entryBestandsnaam, 1, 6, 1, 2,
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions) (0), 6, 3);
    g_signal_connect_after( G_OBJECT( post->entryBestandsnaam ), "changed", G_CALLBACK( ftd_gui_post_bestanden_changed ), NULL );

    post->comboboxBestandstype = gtk_combo_box_new_text ();
    gtk_widget_show (post->comboboxBestandstype);
    gtk_table_attach (GTK_TABLE (table1), post->comboboxBestandstype, 1, 6, 0, 1,
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions) (GTK_FILL), 6, 3);
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxBestandstype), "RAR (.rar / .r00 / .r01 / ...)");
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxBestandstype), "RAR (.001 / .002 / .003 / ...)");
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxBestandstype), "RAR (.part01.rar / .part02.rar / ...)");
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxBestandstype), "ACE (.ace / .c00 / .c01 / ...)");
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxBestandstype), "ZIP (.**01**.zip / .**02**.zip / ...)");
    gtk_combo_box_append_text (GTK_COMBO_BOX (post->comboboxBestandstype), "MP3 (.m3u playlist)");

    post->labelBestandsnaam = gtk_label_new ("Bestandsnaam :");
    gtk_widget_show (post->labelBestandsnaam);
    gtk_table_attach (GTK_TABLE (table1), post->labelBestandsnaam, 0, 1, 1, 2,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (0), 0, 3);
    gtk_misc_set_alignment (GTK_MISC (post->labelBestandsnaam), 0, 0.5);

    label16 = gtk_label_new ("Extensie :");
    gtk_widget_show (label16);
    gtk_table_attach (GTK_TABLE (table1), label16, 0, 1, 0, 1,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (0), 0, 3);
    gtk_misc_set_alignment (GTK_MISC (label16), 0, 0.5);

    post->labelAantalBestanden = gtk_label_new ("Aantal :");
    gtk_widget_show (post->labelAantalBestanden);
    gtk_table_attach (GTK_TABLE (table1), post->labelAantalBestanden, 0, 1, 2, 3,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (0), 0, 0);
    gtk_misc_set_alignment (GTK_MISC (post->labelAantalBestanden), 0, 0.5);

    spinbutton1_adj = gtk_adjustment_new (1, 1, 250, 1, 10, 10);
    post->spinbuttonAantalBestanden = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton1_adj), 1, 0);
    gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( post->spinbuttonAantalBestanden ), TRUE );
    gtk_widget_show (post->spinbuttonAantalBestanden);
    gtk_table_attach (GTK_TABLE (table1), post->spinbuttonAantalBestanden, 1, 2, 2, 3,
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions) (0), 6, 3);
    g_signal_connect( G_OBJECT( post->spinbuttonAantalBestanden ), "value-changed", G_CALLBACK( ftd_gui_post_bestanden_changed ), NULL );

    post->labelStartBestanden = gtk_label_new ("Start :");
    gtk_widget_show (post->labelStartBestanden);
    gtk_table_attach (GTK_TABLE (table1), post->labelStartBestanden, 3, 4, 2, 3,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (0), 0, 0);
    gtk_misc_set_alignment (GTK_MISC (post->labelStartBestanden), 0, 0.5);

    spinbutton2_adj = gtk_adjustment_new (1, 1, 100, 1, 10, 10);
    post->spinbuttonStartBestanden = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton2_adj), 1, 0);
    gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( post->spinbuttonStartBestanden ), TRUE );
    gtk_widget_show (post->spinbuttonStartBestanden);
    gtk_table_attach (GTK_TABLE (table1), post->spinbuttonStartBestanden, 4, 5, 2, 3,
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions) (0), 0, 0);
    g_signal_connect( G_OBJECT( post->spinbuttonStartBestanden ), "value-changed", G_CALLBACK( ftd_gui_post_bestanden_changed ), NULL );

    image3 = gtk_image_new();
    gtk_widget_show (image3);
    gtk_table_attach (GTK_TABLE (table1), image3, 2, 3, 2, 3,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (GTK_FILL), 0, 0);

    image4 = gtk_image_new();
    gtk_widget_show (image4);
    gtk_table_attach (GTK_TABLE (table1), image4, 5, 6, 2, 3,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (GTK_FILL), 0, 0);

    post->labelBestandsinfoPreview = gtk_label_new ("");
    gtk_widget_show (post->labelBestandsinfoPreview);
    gtk_table_attach (GTK_TABLE (table1), post->labelBestandsinfoPreview, 0, 6, 3, 4,
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions) (0), 0, 0);
    gtk_label_set_use_markup (GTK_LABEL (post->labelBestandsinfoPreview), TRUE);
    gtk_misc_set_alignment (GTK_MISC (post->labelBestandsinfoPreview), 0, 0.5);

    image5 = gtk_image_new();
    gtk_widget_show (image5);
    gtk_table_attach (GTK_TABLE (table1), image5, 1, 6, 3, 4,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (GTK_FILL), 0, 0);

    label15 = gtk_label_new ("Bestandsinformatie");
    gtk_widget_show (label15);
    gtk_frame_set_label_widget (GTK_FRAME (frame6), label15);
    gtk_label_set_use_markup (GTK_LABEL (label15), TRUE);

    hbox7 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox7);
    gtk_box_pack_start (GTK_BOX (post->tab2), hbox7, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox7), 6);

    image6 = gtk_image_new_from_stock ("gtk-info", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image6);
    gtk_box_pack_start (GTK_BOX (hbox7), image6, TRUE, TRUE, 0);

    label21 = gtk_label_new ("Hieronder kan je aangeven of en hoeveel PAR bestanden je meestuurt. Tegenwoordig mag je er\nvanuit gaan dat het meeposten van PAR bestanden een standaard is geworden op usenet. Met\nbehulp van PAR bestanden kunnen mensen zelf missende of corrupte delen van de post herstellen.\nWil je meer informatie over hoe PAR bestanden aan te maken? Kijk op http://www.ftd.nu/parinfo");
    gtk_widget_show (label21);
    gtk_box_pack_start (GTK_BOX (hbox7), label21, FALSE, FALSE, 6);

    hbox8 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox8);
    gtk_box_pack_start (GTK_BOX (post->tab2), hbox8, FALSE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox8), 6);

    post->radioGeenPar = gtk_radio_button_new_with_mnemonic (NULL, "Geen pars");
    gtk_widget_show (post->radioGeenPar);
    gtk_box_pack_start (GTK_BOX (hbox8), post->radioGeenPar, TRUE, TRUE, 0);
    gtk_radio_button_set_group (GTK_RADIO_BUTTON (post->radioGeenPar), radiogroupPar);
    radiogroupPar = gtk_radio_button_get_group (GTK_RADIO_BUTTON (post->radioGeenPar));
    g_signal_connect_after( G_OBJECT( post->radioGeenPar ), "clicked", G_CALLBACK( ftd_gui_post_par_changed ), NULL );

    post->radioPar2 = gtk_radio_button_new_with_mnemonic (NULL, "PAR2");
    gtk_widget_show (post->radioPar2);
    gtk_box_pack_start (GTK_BOX (hbox8), post->radioPar2, TRUE, TRUE, 0);
    gtk_radio_button_set_group (GTK_RADIO_BUTTON (post->radioPar2), radiogroupPar);
    radiogroupPar = gtk_radio_button_get_group (GTK_RADIO_BUTTON (post->radioPar2));
    g_signal_connect( G_OBJECT( post->radioPar2 ), "clicked", G_CALLBACK( ftd_gui_post_par_changed ), NULL );

    vbox5 = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (vbox5);
    gtk_box_pack_start (GTK_BOX (post->tab2), vbox5, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (vbox5), 6);

    post->checkbuttonPARBlocksBijGereed = gtk_check_button_new_with_mnemonic ("Ik post PAR2 blocks, maar geef deze bij gereedmelding op");
    gtk_widget_show (post->checkbuttonPARBlocksBijGereed);
    gtk_box_pack_start (GTK_BOX (vbox5), post->checkbuttonPARBlocksBijGereed, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (post->checkbuttonPARBlocksBijGereed), 6);
    g_signal_connect_after( G_OBJECT( post->checkbuttonPARBlocksBijGereed ), "clicked", G_CALLBACK( ftd_gui_post_par_changed ), NULL );

    frame7 = gtk_frame_new (NULL);
    gtk_widget_show (frame7);
    gtk_box_pack_start (GTK_BOX (vbox5), frame7, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame7), 6);
    gtk_frame_set_shadow_type (GTK_FRAME (frame7), GTK_SHADOW_OUT);

    hbox10 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox10);
    gtk_container_add (GTK_CONTAINER (frame7), hbox10);
    gtk_container_set_border_width (GTK_CONTAINER (hbox10), 6);

    post->labelAantalParBlocks = gtk_label_new ("Aantal blocks :");
    gtk_widget_show (post->labelAantalParBlocks);
    gtk_box_pack_start (GTK_BOX (hbox10), post->labelAantalParBlocks, TRUE, TRUE, 0);

    spinbutton3_adj = gtk_adjustment_new (0, 0, 9999, 1, 10, 10);
    post->spinbuttonAantalParBlocks = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton3_adj), 1, 0);
    gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( post->spinbuttonAantalParBlocks ), TRUE );
    gtk_widget_show (post->spinbuttonAantalParBlocks);
    gtk_box_pack_start (GTK_BOX (hbox10), post->spinbuttonAantalParBlocks, TRUE, TRUE, 0);
    g_signal_connect( G_OBJECT( post->spinbuttonAantalParBlocks ), "value-changed", G_CALLBACK( ftd_gui_post_aantal_par_blokken_changed ), NULL );

    post->labelBlocksize = gtk_label_new ("Blocksize :");
    gtk_widget_show (post->labelBlocksize);
    gtk_box_pack_start (GTK_BOX (hbox10), post->labelBlocksize, TRUE, TRUE, 0);

    spinbutton4_adj = gtk_adjustment_new (0, 0, 104857600, 1, 10, 10);
    post->spinbuttonBlocksize = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton4_adj), 1, 0);
    gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( post->spinbuttonBlocksize ), TRUE );
    gtk_widget_show (post->spinbuttonBlocksize);
    gtk_box_pack_start (GTK_BOX (hbox10), post->spinbuttonBlocksize, TRUE, TRUE, 0);
    g_signal_connect( G_OBJECT( post->spinbuttonBlocksize ), "value-changed", G_CALLBACK( ftd_gui_post_blocksize_changed ), NULL );

    gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( gui->post->radioPar2 ), TRUE );

    label23 = gtk_label_new ("PAR-informatie");
    gtk_widget_show (label23);
    gtk_frame_set_label_widget (GTK_FRAME (frame7), label23);
    gtk_label_set_use_markup (GTK_LABEL (label23), TRUE);

    hbuttonbox2 = gtk_hbutton_box_new ();
    gtk_widget_show (hbuttonbox2);
    gtk_box_pack_start (GTK_BOX (post->tab2), hbuttonbox2, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox2), 6);

    post->buttonVerder2 = gtk_button_new ();
    gtk_widget_show (post->buttonVerder2);
    gtk_container_add (GTK_CONTAINER (hbuttonbox2), post->buttonVerder2);
    GTK_WIDGET_SET_FLAGS (post->buttonVerder2, GTK_CAN_DEFAULT);
    g_signal_connect_after( G_OBJECT(post->buttonVerder2), "clicked", G_CALLBACK( ftd_gui_post_verder2 ), NULL );

    alignment2 = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_widget_show (alignment2);
    gtk_container_add (GTK_CONTAINER (post->buttonVerder2), alignment2);

    hbox9 = gtk_hbox_new (FALSE, 2);
    gtk_widget_show (hbox9);
    gtk_container_add (GTK_CONTAINER (alignment2), hbox9);

    image7 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image7);
    gtk_box_pack_start (GTK_BOX (hbox9), image7, FALSE, FALSE, 0);

    label22 = gtk_label_new_with_mnemonic ("Verder");
    gtk_widget_show (label22);
    gtk_box_pack_start (GTK_BOX (hbox9), label22, FALSE, FALSE, 0);

    label2 = gtk_label_new ("Bestandsinformatie");
    gtk_widget_show (label2);
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (post->tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (post->tabs), 1), label2);

    post->tab3 = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (post->tab3);
    gtk_container_add (GTK_CONTAINER (post->tabs), post->tab3);
    gtk_container_set_border_width (GTK_CONTAINER (post->tab3), 6);

    frame8 = gtk_frame_new (NULL);
    gtk_widget_show (frame8);
    gtk_box_pack_start (GTK_BOX (post->tab3), frame8, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame8), 6);
    gtk_frame_set_shadow_type (GTK_FRAME (frame8), GTK_SHADOW_OUT);

    hbox11 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox11);
    gtk_container_add (GTK_CONTAINER (frame8), hbox11);
    gtk_container_set_border_width (GTK_CONTAINER (hbox11), 6);

    post->entryM3UPlaylist = gtk_entry_new ();
    gtk_widget_show (post->entryM3UPlaylist);
    gtk_box_pack_start (GTK_BOX (hbox11), post->entryM3UPlaylist, TRUE, TRUE, 6);
    gtk_editable_set_editable (GTK_EDITABLE (post->entryM3UPlaylist), FALSE);
    gtk_widget_set_sensitive( GTK_WIDGET( post->entryM3UPlaylist ), FALSE );

    post->buttonOpenM3UPlayList = gtk_button_new_from_stock ("gtk-open");
    gtk_widget_show (post->buttonOpenM3UPlayList);
    gtk_box_pack_start (GTK_BOX (hbox11), post->buttonOpenM3UPlayList, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (post->buttonOpenM3UPlayList), 6);
    g_signal_connect_after( G_OBJECT( post->buttonOpenM3UPlayList ), "clicked", G_CALLBACK(ftd_gui_post_open_playlist), NULL );

    post->buttonClearM3UPlayList = gtk_button_new_from_stock ("gtk-clear");
    gtk_widget_show (post->buttonClearM3UPlayList);
    gtk_box_pack_start (GTK_BOX (hbox11), post->buttonClearM3UPlayList, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (post->buttonClearM3UPlayList), 6);
    g_signal_connect_after( G_OBJECT( post->buttonClearM3UPlayList ), "clicked", G_CALLBACK(ftd_gui_post_clear_playlist), NULL );

    label26 = gtk_label_new (".m3u bestand");
    gtk_widget_show (label26);
    gtk_frame_set_label_widget (GTK_FRAME (frame8), label26);
    gtk_label_set_use_markup (GTK_LABEL (label26), TRUE);

    scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_show (scrolledwindow2);
    gtk_box_pack_start (GTK_BOX (post->tab3), scrolledwindow2, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow2), 6);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_SHADOW_IN);

    post->liststoreM3UPlaylist = gtk_list_store_new( 1, G_TYPE_STRING );
    post->treeviewM3UPlaylist = gtk_tree_view_new_with_model (GTK_TREE_MODEL(post->liststoreM3UPlaylist));
    gtk_tree_view_append_column( GTK_TREE_VIEW( post->treeviewM3UPlaylist ), gtk_tree_view_column_new_with_attributes( "[mp3-bestanden]", gtk_cell_renderer_text_new( ), "text", 0, NULL ) );
    gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( post->treeviewM3UPlaylist ), FALSE );
    gtk_widget_show (post->treeviewM3UPlaylist);
    gtk_container_add (GTK_CONTAINER (scrolledwindow2), post->treeviewM3UPlaylist);
    gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (post->treeviewM3UPlaylist), TRUE);

    hbuttonbox3 = gtk_hbutton_box_new ();
    gtk_widget_show (hbuttonbox3);
    gtk_box_pack_start (GTK_BOX (post->tab3), hbuttonbox3, FALSE, TRUE, 0);

    post->buttonVerder3 = gtk_button_new ();
    gtk_widget_show (post->buttonVerder3);
    gtk_container_add (GTK_CONTAINER (hbuttonbox3), post->buttonVerder3);
    gtk_container_set_border_width (GTK_CONTAINER (post->buttonVerder3), 6);
    GTK_WIDGET_SET_FLAGS (post->buttonVerder3, GTK_CAN_DEFAULT);
    g_signal_connect_after( G_OBJECT( post->buttonVerder3 ), "clicked", G_CALLBACK( ftd_gui_post_verder3 ), NULL );

    alignment3 = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_widget_show (alignment3);
    gtk_container_add (GTK_CONTAINER (post->buttonVerder3), alignment3);

    hbox12 = gtk_hbox_new (FALSE, 2);
    gtk_widget_show (hbox12);
    gtk_container_add (GTK_CONTAINER (alignment3), hbox12);

    image8 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image8);
    gtk_box_pack_start (GTK_BOX (hbox12), image8, FALSE, FALSE, 0);

    label27 = gtk_label_new_with_mnemonic ("Verder");
    gtk_widget_show (label27);
    gtk_box_pack_start (GTK_BOX (hbox12), label27, FALSE, FALSE, 0);

    label3 = gtk_label_new ("MP3 Info");
    gtk_widget_show (label3);
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (post->tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (post->tabs), 2), label3);

    post->tab4 = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (post->tab4);
    gtk_container_add (GTK_CONTAINER (post->tabs), post->tab4);
    gtk_container_set_border_width (GTK_CONTAINER (post->tab4), 6);

    frame9 = gtk_frame_new (NULL);
    gtk_widget_show (frame9);
    gtk_box_pack_start (GTK_BOX (post->tab4), frame9, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame9), 6);

    hbox13 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox13);
    gtk_container_add (GTK_CONTAINER (frame9), hbox13);
    gtk_container_set_border_width (GTK_CONTAINER (hbox13), 6);

    post->radioPostSpot = gtk_radio_button_new_with_mnemonic (NULL, "Spot");
    gtk_widget_show (post->radioPostSpot);
    gtk_box_pack_start (GTK_BOX (hbox13), post->radioPostSpot, TRUE, TRUE, 0);
    gtk_radio_button_set_group (GTK_RADIO_BUTTON (post->radioPostSpot), radiogroupPostType);
    radiogroupPostType = gtk_radio_button_get_group (GTK_RADIO_BUTTON (post->radioPostSpot));

    post->radioPostAankondiging = gtk_radio_button_new_with_mnemonic (NULL, "Aankondiging");
    gtk_widget_show (post->radioPostAankondiging);
    gtk_box_pack_start (GTK_BOX (hbox13), post->radioPostAankondiging, TRUE, TRUE, 0);
    gtk_radio_button_set_group (GTK_RADIO_BUTTON (post->radioPostAankondiging), radiogroupPostType);
    radiogroupPostType = gtk_radio_button_get_group (GTK_RADIO_BUTTON (post->radioPostAankondiging));

    post->radioPostBezigUploaden = gtk_radio_button_new_with_mnemonic (NULL, "Bezig met uploaden");
    gtk_widget_show (post->radioPostBezigUploaden);
    gtk_box_pack_start (GTK_BOX (hbox13), post->radioPostBezigUploaden, TRUE, TRUE, 0);
    gtk_radio_button_set_group (GTK_RADIO_BUTTON (post->radioPostBezigUploaden), radiogroupPostType);
    radiogroupPostType = gtk_radio_button_get_group (GTK_RADIO_BUTTON (post->radioPostBezigUploaden));

    gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( post->radioPostAankondiging ), TRUE );

    label28 = gtk_label_new ("Poststatus");
    gtk_widget_show (label28);
    gtk_frame_set_label_widget (GTK_FRAME (frame9), label28);
    gtk_label_set_use_markup (GTK_LABEL (label28), TRUE);

    frame10 = gtk_frame_new (NULL);
    gtk_widget_show (frame10);
    gtk_box_pack_start (GTK_BOX (post->tab4), frame10, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame10), 6);

    scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_show (scrolledwindow3);
    gtk_container_add (GTK_CONTAINER (frame10), scrolledwindow3);
    gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow3), 6);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_SHADOW_ETCHED_IN);

    post->textviewAankondiging = gtk_text_view_new ();
    gtk_widget_show (post->textviewAankondiging);
    gtk_container_add (GTK_CONTAINER (scrolledwindow3), post->textviewAankondiging);

    label29 = gtk_label_new ("Aankondiging");
    gtk_widget_show (label29);
    gtk_frame_set_label_widget (GTK_FRAME (frame10), label29);
    gtk_label_set_use_markup (GTK_LABEL (label29), TRUE);

    frame11 = gtk_frame_new (NULL);
    gtk_widget_show (frame11);
    gtk_box_pack_start (GTK_BOX (post->tab4), frame11, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame11), 6);

    scrolledwindow4 = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_show (scrolledwindow4);
    gtk_container_add (GTK_CONTAINER (frame11), scrolledwindow4);
    gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow4), 6);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow4), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow4), GTK_SHADOW_ETCHED_IN);

    post->textviewOmschrijving = gtk_text_view_new ();
    gtk_widget_show (post->textviewOmschrijving);
    gtk_container_add (GTK_CONTAINER (scrolledwindow4), post->textviewOmschrijving);

    label30 = gtk_label_new ("Omschrijving");
    gtk_widget_show (label30);
    gtk_frame_set_label_widget (GTK_FRAME (frame11), label30);
    gtk_label_set_use_markup (GTK_LABEL (label30), TRUE);

    hbuttonbox4 = gtk_hbutton_box_new ();
    gtk_widget_show (hbuttonbox4);
    gtk_box_pack_start (GTK_BOX (post->tab4), hbuttonbox4, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox4), 6);

    post->buttonVerder4 = gtk_button_new ();
    gtk_widget_show (post->buttonVerder4);
    gtk_container_add (GTK_CONTAINER (hbuttonbox4), post->buttonVerder4);
    GTK_WIDGET_SET_FLAGS (post->buttonVerder4, GTK_CAN_DEFAULT);
    g_signal_connect_after( G_OBJECT( post->buttonVerder4 ), "clicked", G_CALLBACK( ftd_gui_post_verder4 ), NULL );

    alignment4 = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_widget_show (alignment4);
    gtk_container_add (GTK_CONTAINER (post->buttonVerder4), alignment4);

    hbox14 = gtk_hbox_new (FALSE, 2);
    gtk_widget_show (hbox14);
    gtk_container_add (GTK_CONTAINER (alignment4), hbox14);

    image9 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image9);
    gtk_box_pack_start (GTK_BOX (hbox14), image9, FALSE, FALSE, 0);

    label31 = gtk_label_new_with_mnemonic ("Verder");
    gtk_widget_show (label31);
    gtk_box_pack_start (GTK_BOX (hbox14), label31, FALSE, FALSE, 0);

    label4 = gtk_label_new ("Postinfo");
    gtk_widget_show (label4);
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (post->tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (post->tabs), 3), label4);

    post->tab5 = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (post->tab5);
    gtk_container_add (GTK_CONTAINER (post->tabs), post->tab5);
    gtk_container_set_border_width (GTK_CONTAINER (post->tab5), 6);

    frame12 = gtk_frame_new (NULL);
    gtk_widget_show (frame12);
    gtk_box_pack_start (GTK_BOX (post->tab5), frame12, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame12), 6);

    scrolledwindow5 = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_show (scrolledwindow5);
    gtk_container_add (GTK_CONTAINER (frame12), scrolledwindow5);
    gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow5), 6);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow5), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow5), GTK_SHADOW_ETCHED_IN);

    post->textviewRepostbeleid = gtk_text_view_new ();
    gtk_widget_show (post->textviewRepostbeleid);
    gtk_container_add (GTK_CONTAINER (scrolledwindow5), post->textviewRepostbeleid);

    label32 = gtk_label_new ("Repostbeleid");
    gtk_widget_show (label32);
    gtk_frame_set_label_widget (GTK_FRAME (frame12), label32);
    gtk_label_set_use_markup (GTK_LABEL (label32), TRUE);

    frame13 = gtk_frame_new (NULL);
    gtk_widget_show (frame13);
    gtk_box_pack_start (GTK_BOX (post->tab5), frame13, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (frame13), 6);

    scrolledwindow6 = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_show (scrolledwindow6);
    gtk_container_add (GTK_CONTAINER (frame13), scrolledwindow6);
    gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow6), 6);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow6), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow6), GTK_SHADOW_ETCHED_IN);

    post->liststoreNieuwsgroepen = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
    post->treeviewNieuwsgroepen = gtk_tree_view_new_with_model (GTK_TREE_MODEL(post->liststoreNieuwsgroepen));
    gtk_tree_view_append_column( GTK_TREE_VIEW( post->treeviewNieuwsgroepen ), gtk_tree_view_column_new_with_attributes( "[Nieuwsgroepen]", gtk_cell_renderer_text_new( ), "text", 0, NULL ) );
    gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( post->treeviewNieuwsgroepen ), FALSE );
    gtk_tree_selection_set_mode( gtk_tree_view_get_selection( GTK_TREE_VIEW( post->treeviewNieuwsgroepen ) ), GTK_SELECTION_MULTIPLE );
    gtk_widget_show (post->treeviewNieuwsgroepen);
    gtk_container_add (GTK_CONTAINER (scrolledwindow6), post->treeviewNieuwsgroepen);
    gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (post->treeviewNieuwsgroepen), TRUE);
    gtk_tree_sortable_set_sort_column_id( GTK_TREE_SORTABLE( post->liststoreNieuwsgroepen ), 0, GTK_SORT_ASCENDING );
    gtk_tree_sortable_set_sort_func( GTK_TREE_SORTABLE( post->liststoreNieuwsgroepen ), 0, (GtkTreeIterCompareFunc) ftd_gui_post_tree_sortable_compare_string, NULL, NULL );

    list = (FtdList *) ftd_groups_get( );
    while( list ) {
        GtkTreeIter iter;
        FtdGroup * group = ftd_list_value( list );
        gtk_list_store_append( post->liststoreNieuwsgroepen, &iter );
        gtk_list_store_set( post->liststoreNieuwsgroepen, &iter, 0, ftd_string_value( group->groupName ), 1, group->groupId, -1 );
        list = ftd_list_next( list );
    }

    label33 = gtk_label_new ("Nieuwsgroepen (maximaal 3)");
    gtk_widget_show (label33);
    gtk_frame_set_label_widget (GTK_FRAME (frame13), label33);
    gtk_label_set_use_markup (GTK_LABEL (label33), TRUE);

    hbox15 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox15);
    gtk_box_pack_start (GTK_BOX (post->tab5), hbox15, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox15), 6);

    label34 = gtk_label_new ("Verzendstatus :");
    gtk_widget_show (label34);
    gtk_box_pack_start (GTK_BOX (hbox15), label34, TRUE, TRUE, 0);

    post->progressbarVerzenden = gtk_progress_bar_new ();
    gtk_widget_show (post->progressbarVerzenden);
    gtk_box_pack_start (GTK_BOX (hbox15), post->progressbarVerzenden, TRUE, TRUE, 0);
    gtk_progress_bar_set_text (GTK_PROGRESS_BAR (post->progressbarVerzenden), "Wacht totdat op knop 'Versturen' is gedrukt");

    hbuttonbox5 = gtk_hbutton_box_new ();
    gtk_widget_show (hbuttonbox5);
    gtk_box_pack_start (GTK_BOX (post->tab5), hbuttonbox5, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox5), 6);

    image = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image);

    post->buttonExport = gtk_button_new_with_label("Gegevens exporteren naar extern bestand");
#if GTK_CHECK_VERSION(2,6,0)
    gtk_button_set_image(GTK_BUTTON(post->buttonExport), image);
#endif
    gtk_widget_show(post->buttonExport);
    gtk_container_add(GTK_CONTAINER(hbuttonbox5), post->buttonExport);
    g_signal_connect(G_OBJECT(post->buttonExport), "clicked", G_CALLBACK(ftd_gui_post_export), NULL);

    post->buttonVersturen = gtk_button_new ();
    gtk_widget_show (post->buttonVersturen);
    gtk_container_add (GTK_CONTAINER (hbuttonbox5), post->buttonVersturen);
    GTK_WIDGET_SET_FLAGS (post->buttonVersturen, GTK_CAN_DEFAULT);
    g_signal_connect_after( G_OBJECT( post->buttonVersturen ), "clicked", G_CALLBACK( ftd_gui_post_versturen ), NULL );

    alignment5 = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_widget_show (alignment5);
    gtk_container_add (GTK_CONTAINER (post->buttonVersturen), alignment5);

    hbox16 = gtk_hbox_new (FALSE, 2);
    gtk_widget_show (hbox16);
    gtk_container_add (GTK_CONTAINER (alignment5), hbox16);

    image10 = gtk_image_new_from_stock ("gtk-yes", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image10);
    gtk_box_pack_start (GTK_BOX (hbox16), image10, FALSE, FALSE, 0);

    label35 = gtk_label_new_with_mnemonic ("Versturen");
    gtk_widget_show (label35);
    gtk_box_pack_start (GTK_BOX (hbox16), label35, FALSE, FALSE, 0);

    label5 = gtk_label_new ("Nieuwsgroepen");
    gtk_widget_show (label5);
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (post->tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (post->tabs), 4), label5);

    gtk_widget_show(post->window);

    // Voorkom dat het venster te groot wordt als de filename heel lang is
    gtk_widget_size_request(post->labelBestandsinfoPreview, &req);
    gtk_widget_set_size_request(post->labelBestandsinfoPreview, req.width, -1);

    // Delayed to here, to prevent errors resulting from uninitialised elements
    g_signal_connect_after( G_OBJECT( post->comboboxBestandstype ), "changed", G_CALLBACK( ftd_gui_post_bestanden_changed ), NULL );
    gtk_combo_box_set_active( GTK_COMBO_BOX( post->comboboxBestandstype ), 0 );

    g_signal_connect(G_OBJECT(post->window), "destroy", G_CALLBACK(ftd_gui_post_destroy), NULL);
}

gboolean
ftd_gui_post_destroy(GtkWidget *caller, gpointer data)
{
    FtdList * list;
    g_assert(gui);
    g_assert(gui->post);

    list = gui->post->mp3files;
    if( list ) {
        while( list ) {
            FtdString * file = ftd_list_value( list );
            ftd_string_free( file );
            list = ftd_list_next( list );
        }
        ftd_list_free( gui->post->mp3files );
    }

    g_free(gui->post);
    gui->post = NULL;

    return FALSE;
}


void
ftd_gui_post_switch_category(GtkWidget *caller, gpointer data)
{
    char *tmp;
    FtdList *tags_in_cat, *list;
    const FtdTag *tag;

    g_assert(gui);
    g_assert(gui->post);

    if (gtk_combo_box_get_active(GTK_COMBO_BOX(gui->post->comboboxCat)) < 0) {
        return;
    }

    // Ranzige omweg om een GtkComboBox te legen....
    // FIXME: Dit moet netter kunnen.. Gnome bugzilla #324899
    gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxSCat), 0);
    while ((tmp = gtk_combo_box_get_active_text(GTK_COMBO_BOX(gui->post->comboboxSCat)))) {
        g_free(tmp);
        gtk_combo_box_remove_text(GTK_COMBO_BOX(gui->post->comboboxSCat), 0);
        gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxSCat), 0);
    }

    // Verwijder alle oude tag componenten
    gtk_container_foreach(GTK_CONTAINER(gui->post->hboxTags), (GtkCallback) gtk_widget_destroy, NULL);

    ftd_list_free( gui->post->listCheckbuttonTags );
    gui->post->listCheckbuttonTags = NULL;

    // Achterhaal alle tags die bij de opgegeven categorie horen
    tags_in_cat = ftd_tag_get_tags_in_cat(gtk_combo_box_get_active(GTK_COMBO_BOX(gui->post->comboboxCat)));
    list = tags_in_cat;

    // Het eerste element uit de lijst is altijd de SCat parent
    tag = ftd_list_value(list);
    tmp = g_strdup_printf("<b>%s :</b>", ftd_string_value(tag->name));
    gtk_label_set_markup(GTK_LABEL(gui->post->labelSubcategorieTag), tmp);
    g_free(tmp);

    // Ga nu verder in de lijst totdat we een volgende parent tegenkomen
    list = ftd_list_next(list);
    tag = ftd_list_value(list);

    while (tag->parent != NULL) {
        gtk_combo_box_append_text(GTK_COMBO_BOX(gui->post->comboboxSCat), ftd_string_value(tag->name));
        list = ftd_list_next(list);
        tag = ftd_list_value(list);
    }

    gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxSCat), 0);

    // Doorloop nu de overige tags
    while (list) {
        // tag->parent is op dit punt NULL
        GtkWidget *vbox;
        GtkWidget *label;
        GtkWidget *scrolledwindow;
        GtkWidget *vbox2;

        vbox = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox);
        gtk_box_pack_start (GTK_BOX (gui->post->hboxTags), vbox, TRUE, TRUE, 0);
        gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);

        tag = ftd_list_value(list);
        tmp = g_strdup_printf("<b>%s :</b>", ftd_string_value(tag->name));
        label = gtk_label_new (tmp);
        gtk_widget_show (label);
        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
        gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
        g_free(tmp);

        scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
        gtk_widget_show (scrolledwindow);
        gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);

        vbox2 = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox2);
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwindow), vbox2);

        list = ftd_list_next(list);
        tag = ftd_list_value(list);

        while (tag->parent != NULL) {
            GtkWidget *checkbutton;

            checkbutton = gtk_check_button_new_with_mnemonic (ftd_string_value(tag->name));
            gtk_widget_show (checkbutton);
            gtk_box_pack_start (GTK_BOX (vbox2), checkbutton, FALSE, FALSE, 0);
            g_object_set_data( G_OBJECT( checkbutton ), "ftd_tag_code", tag->code );
            gui->post->listCheckbuttonTags = ftd_list_prepend( gui->post->listCheckbuttonTags, checkbutton );

            list = ftd_list_next(list);
            if (list == NULL) {
                break;
            }

            tag = ftd_list_value(list);
        }

        if (list == NULL) {
            break;
        }
    }

    ftd_list_free(tags_in_cat);
}

void
ftd_gui_post_test_afbeelding(GtkWidget *caller, gpointer data)
{
    gchar * url;
    url = g_strdup( gtk_entry_get_text( GTK_ENTRY(gui->post->entryURL) ) );
    if( url ) {
        ftd_gui_center_launch_browser( (char*) url );
        g_free( url );
    }
}

void
ftd_gui_post_verder1(GtkWidget *caller, gpointer data)
{
    if( ftd_gui_post_check_tab1() ) {
        gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 1 );
    }
}

gboolean
ftd_gui_post_check_tab1()
{
    const char *titel;
    GdkColor rood = { 0, 65535, 0, 0 };
    GdkColor zwart = { 0, 0, 0, 0 };
    titel = gtk_entry_get_text( GTK_ENTRY( gui->post->entryTitel ) );
    if( titel && strlen( titel ) ) {
        if( g_object_get_data( G_OBJECT( gui->post->entryTitel ), "colorchanged" ) ) {
            gtk_widget_modify_base( gui->post->entryTitel, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_text( gui->post->entryTitel, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->entryTitel ), "colorchanged", (gpointer) 0 );
        }
        return TRUE;
    }
    else {
        if( !g_object_get_data( G_OBJECT( gui->post->entryTitel ), "colorchanged" ) ) {
            gtk_widget_modify_base( gui->post->entryTitel, GTK_STATE_NORMAL, &rood );
            gtk_widget_modify_text( gui->post->entryTitel, GTK_STATE_NORMAL, &zwart );
            g_object_set_data( G_OBJECT( gui->post->entryTitel ), "colorchanged", (gpointer) 1 );
        }
    }
    return FALSE;
}

void
ftd_gui_post_bestanden_changed(GtkWidget *caller, gpointer data)
{
    const char *bestandsnaam;
    int schema;
    int start;
    int aantal;
    int eind;
    char * buf;
    char c1;
    char c2;
    int len;

    bestandsnaam = gtk_entry_get_text( GTK_ENTRY( gui->post->entryBestandsnaam ) );
    schema = gtk_combo_box_get_active( GTK_COMBO_BOX( gui->post->comboboxBestandstype ) );

    if( ( bestandsnaam && strlen( bestandsnaam ) ) || schema == 5 ) {
        if( g_object_get_data( G_OBJECT( gui->post->entryBestandsnaam ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->entryBestandsnaam, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->entryBestandsnaam, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->entryBestandsnaam ), "colorchanged", (gpointer) 0 );
        }
    }

    if( schema < 0 || schema == 5 ) {
        if( schema == 5 ) {
            gtk_label_set_text( GTK_LABEL( gui->post->labelBestandsinfoPreview ), "<b>Gebruik een .m3u playlist om bestanden toe te voegen</b>" );
            gtk_label_set_use_markup( GTK_LABEL( gui->post->labelBestandsinfoPreview ), TRUE );
            gtk_widget_set_sensitive( gtk_notebook_get_tab_label( GTK_NOTEBOOK( gui->post->tabs ), gtk_notebook_get_nth_page( GTK_NOTEBOOK( gui->post->tabs ), 2 ) ), TRUE );
        }
        else {
            gtk_label_set_text( GTK_LABEL( gui->post->comboboxBestandstype ), "<b>Selecteer een bestandstype.</b>" );
            gtk_label_set_use_markup( GTK_LABEL( gui->post->labelBestandsinfoPreview ), TRUE );
            gtk_widget_set_sensitive( gtk_notebook_get_tab_label( GTK_NOTEBOOK( gui->post->tabs ), gtk_notebook_get_nth_page( GTK_NOTEBOOK( gui->post->tabs ), 2 ) ), FALSE );
        }
        gtk_widget_set_sensitive( gui->post->labelBestandsnaam, FALSE );
        gtk_widget_set_sensitive( gui->post->entryBestandsnaam, FALSE );
        gtk_entry_set_editable( GTK_ENTRY( gui->post->entryBestandsnaam ), FALSE );
        gtk_widget_set_sensitive( gui->post->labelAantalBestanden, FALSE );
        gtk_widget_set_sensitive( gui->post->spinbuttonAantalBestanden, FALSE );
        gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonAantalBestanden ), FALSE );
        gtk_widget_set_sensitive( gui->post->labelStartBestanden, FALSE );
        gtk_widget_set_sensitive( gui->post->spinbuttonStartBestanden, FALSE );
        gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonStartBestanden ), FALSE );
        return;
    }
    gtk_widget_set_sensitive( gtk_notebook_get_tab_label( GTK_NOTEBOOK( gui->post->tabs ), gtk_notebook_get_nth_page( GTK_NOTEBOOK( gui->post->tabs ), 2 ) ), FALSE );
    start = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonStartBestanden ) );
    aantal = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonAantalBestanden ) );

    gtk_widget_set_sensitive( gui->post->labelBestandsnaam, TRUE );
    gtk_widget_set_sensitive( gui->post->entryBestandsnaam, TRUE );
    gtk_entry_set_editable( GTK_ENTRY( gui->post->entryBestandsnaam ), TRUE );
    gtk_widget_set_sensitive( gui->post->labelAantalBestanden, TRUE );
    gtk_widget_set_sensitive( gui->post->spinbuttonAantalBestanden, TRUE );
    gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonAantalBestanden ), TRUE );
    gtk_widget_set_sensitive( gui->post->labelStartBestanden, TRUE );
    gtk_widget_set_sensitive( gui->post->spinbuttonStartBestanden, TRUE );
    gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonStartBestanden ), TRUE );

    switch( schema ) {
        case 0 :
            start -= 2;
            c1 = 'r' + ( ( start - ( start % 100 ) ) / 100 );
            eind = start + aantal - 1;
            c2 = 'r' + ( ( eind - ( eind % 100 ) ) / 100 );
            len = strlen( bestandsnaam ) * 2 + 21;
            buf = (char *) g_malloc( len );
            if( start <= -1 ) {
                if( eind <= -1 ) {
                    snprintf( buf, len, "<b>%s.rar\n%s.rar</b>", bestandsnaam, bestandsnaam );
                }
                else {
                    snprintf( buf, len, "<b>%s.rar\n%s.%c%02d</b>", bestandsnaam, bestandsnaam, (int)c2, eind%100 );
                }
            }
            else {
                snprintf( buf, len, "<b>%s.%c%02d\n%s.%c%02d</b>", bestandsnaam, (int)c1, start%100, bestandsnaam, (int)c2, eind%100 );
            }
            break;
        case 1 :
            eind = aantal + start - 1;
            len = strlen( bestandsnaam ) * 2 + 21;
            buf = (char *) g_malloc( len );
            snprintf( buf, len, "<b>%s.%03d\n%s.%03d</b>", bestandsnaam, start, bestandsnaam, eind );
            break;
        case 2 :
            eind = aantal + start - 1;
            if( eind < 100 ) {
                len = strlen( bestandsnaam ) * 2 + 35;
                buf = (char *) g_malloc( len );
                snprintf( buf, len, "<b>%s.part%02d.rar\n%s.part%02d.rar</b>", bestandsnaam, start, bestandsnaam, eind );
            }
            else {
                len = strlen( bestandsnaam ) * 2 + 37;
                buf = (char *) g_malloc( len );
                snprintf( buf, len, "<b>%s.part%03d.rar\n%s.part%03d.rar</b>", bestandsnaam, start, bestandsnaam, eind );
            }
            break;
        case 3 :
            start -= 2;
            eind = start + aantal - 1;
            len = strlen( bestandsnaam ) * 2 + 21;
            buf = (char *) g_malloc( len );
            if( start <= -1 ) {
                if( eind < 100 ) {
                    if( eind <= -1 ) {
                        snprintf( buf, len, "<b>%s.ace\n%s.ace</b>", bestandsnaam, bestandsnaam );
                    }
                    else {
                        snprintf( buf, len, "<b>%s.ace\n%s.c%02d</b>", bestandsnaam, bestandsnaam, eind );
                    }
                }
                else {
                    snprintf( buf, len, "<b>%s.ace\n%s.%03d</b>", bestandsnaam, bestandsnaam, eind );
                }
            }
            else {
                if( start < 100 ) {
                    if( eind < 100 ) {
                        snprintf( buf, len, "<b>%s.c%02d\n%s.c%02d</b>", bestandsnaam, start, bestandsnaam, eind );
                    }
                    else {
                        snprintf( buf, len, "<b>%s.c%02d\n%s.%03d</b>", bestandsnaam, start, bestandsnaam, eind );
                    }
                }
                else {
                    if( eind < 100 ) {
                        snprintf( buf, len, "<b>%s.%03d\n%s.c%02d</b>", bestandsnaam, start, bestandsnaam, eind );
                    }
                    else {
                        snprintf( buf, len, "<b>%s.%03d\n%s.%03d</b>", bestandsnaam, start, bestandsnaam, eind );
                    }
                }
            }
            break;
        case 4 :
            eind = aantal + start - 1;
            if( eind < 100 ) {
                len = strlen( bestandsnaam ) * 2 + 25;
                buf = (char *) g_malloc( len );
                snprintf( buf, len, "<b>%02d%s.zip\n%02d%s.zip</b>", start, bestandsnaam, eind, bestandsnaam );
            }
            else {
                if( start < 100 ) {
                    len = strlen( bestandsnaam ) * 2 + 26;
                    buf = (char *) g_malloc( len );
                    snprintf( buf, len, "<b>%02d%s.zip\n%03d%s.zip</b>", start, bestandsnaam, eind, bestandsnaam );
                }
                else {
                    len = strlen( bestandsnaam ) * 2 + 27;
                    buf = (char *) g_malloc( len );
                    snprintf( buf, len, "<b>%03d%s.zip\n%03d%s.zip</b>", start, bestandsnaam, eind, bestandsnaam );
                }
            }
            break;
        default :
            buf = (char *) g_malloc( 28 );
            snprintf( buf, 28, "<b>Ongeldig schema gekozen.</b>" );
    }
    gtk_label_set_text( GTK_LABEL( gui->post->labelBestandsinfoPreview ), buf );
    gtk_label_set_use_markup( GTK_LABEL( gui->post->labelBestandsinfoPreview ), TRUE );
    g_free( buf );
}

void
ftd_gui_post_par_changed(GtkWidget *caller, gpointer data)
{
    if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioGeenPar ) ) ) {
        gtk_widget_set_sensitive( gui->post->checkbuttonPARBlocksBijGereed, FALSE );

        gtk_widget_set_sensitive( gui->post->spinbuttonAantalParBlocks, FALSE );
        gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonAantalParBlocks ), FALSE );
        gtk_widget_set_sensitive( gui->post->labelAantalParBlocks, FALSE );

        gtk_widget_set_sensitive( gui->post->spinbuttonBlocksize, FALSE );
        gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonBlocksize ), FALSE );
        gtk_widget_set_sensitive( gui->post->labelBlocksize, FALSE );

        if( g_object_get_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged", (gpointer) 0 );
        }
        if( g_object_get_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged", (gpointer) 0 );
        }
    }
    if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioPar2 ) ) ) {
        gtk_widget_set_sensitive( gui->post->checkbuttonPARBlocksBijGereed, TRUE );

        gtk_label_set_text( GTK_LABEL( gui->post->labelAantalParBlocks ), "Aantal blocks" );
        if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->checkbuttonPARBlocksBijGereed ) ) ) {
            gtk_widget_set_sensitive( gui->post->spinbuttonAantalParBlocks, FALSE );
            gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonAantalParBlocks ), FALSE );
            gtk_widget_set_sensitive( gui->post->labelAantalParBlocks, FALSE );

            gtk_widget_set_sensitive( gui->post->spinbuttonBlocksize, FALSE );
            gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonBlocksize ), FALSE );
            gtk_widget_set_sensitive( gui->post->labelBlocksize, FALSE );

            if( g_object_get_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged" ) ) {
                gtk_widget_modify_text( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
                gtk_widget_modify_base( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
                g_object_set_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged", (gpointer) 0 );
            }
            if( g_object_get_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged" ) ) {
                gtk_widget_modify_text( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
                gtk_widget_modify_base( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
                g_object_set_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged", (gpointer) 0 );
            }
        }
        else {
            gtk_widget_set_sensitive( gui->post->spinbuttonAantalParBlocks, TRUE );
            gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonAantalParBlocks ), TRUE );
            gtk_widget_set_sensitive( gui->post->labelAantalParBlocks, TRUE );

            gtk_widget_set_sensitive( gui->post->spinbuttonBlocksize, TRUE );
            gtk_entry_set_editable( GTK_ENTRY( gui->post->spinbuttonBlocksize ), TRUE );
            gtk_widget_set_sensitive( gui->post->labelBlocksize, TRUE );
        }
    }
}

void
ftd_gui_post_verder2(GtkWidget *caller, gpointer data)
{
    if( ftd_gui_post_check_tab2() ) {
        if( gtk_combo_box_get_active( GTK_COMBO_BOX( gui->post->comboboxBestandstype ) ) == 5 ) {
            gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 2 );
        }
        else {
            gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 3 );
        }
    }
}

gboolean
ftd_gui_post_check_tab2()
{
    const char *bestandsnaam;
    int blocks;
    int size;
    GdkColor rood = { 0, 65535, 0, 0 };
    GdkColor zwart = { 0, 0, 0, 0 };
    gboolean ok = TRUE;
    bestandsnaam = gtk_entry_get_text( GTK_ENTRY( gui->post->entryBestandsnaam ) );
    if( !( ( bestandsnaam && strlen( bestandsnaam ) ) || gtk_combo_box_get_active( GTK_COMBO_BOX( gui->post->comboboxBestandstype ) ) == 5 ) ) {
        ok = FALSE;
        if( !g_object_get_data( G_OBJECT( gui->post->entryBestandsnaam ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->entryBestandsnaam, GTK_STATE_NORMAL, &zwart );
            gtk_widget_modify_base( gui->post->entryBestandsnaam, GTK_STATE_NORMAL, &rood );
            g_object_set_data( G_OBJECT( gui->post->entryBestandsnaam ), "colorchanged", (gpointer) 1 );
        }
    }
    else {
        if( g_object_get_data( G_OBJECT( gui->post->entryBestandsnaam ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->entryBestandsnaam, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->entryBestandsnaam, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->entryBestandsnaam ), "colorchanged", (gpointer) 0 );
        }
    }
    if( !( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioGeenPar ) ) || gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->checkbuttonPARBlocksBijGereed ) ) ) ) {
        blocks = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonAantalParBlocks ) );
        if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioPar2 ) ) ) {
            if( blocks < 1 ) {
                ok = FALSE;
                if( !g_object_get_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged" ) ) {
                    gtk_widget_modify_text( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, &zwart );
                    gtk_widget_modify_base( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, &rood );
                    g_object_set_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged", (gpointer) 1 );
                }
            }
            else {
                if( g_object_get_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged" ) ) {
                    gtk_widget_modify_text( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
                    gtk_widget_modify_base( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
                    g_object_set_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged", (gpointer) 0 );
                }
            }
            size = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonBlocksize ) );
            if( size < 1 ) {
                ok = FALSE;
                if( !g_object_get_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged" ) ) {
                    gtk_widget_modify_text( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, &zwart );
                    gtk_widget_modify_base( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, &rood );
                    g_object_set_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged", (gpointer) 1 );
                }
            }
            else {
                if( g_object_get_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged" ) ) {
                    gtk_widget_modify_text( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
                    gtk_widget_modify_base( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
                    g_object_set_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged", (gpointer) 0 );
                }
            }
        }
    }
    else {
        if( g_object_get_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged", (gpointer) 0 );
        }
        if( g_object_get_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged", (gpointer) 0 );
        }
    }
    return ok;
}

void
ftd_gui_post_open_playlist(GtkWidget *caller, gpointer data)
{
    GtkWidget *dialog;
    GtkFileFilter *filter;

    dialog = gtk_file_chooser_dialog_new ("Open .m3u-playlist", GTK_WINDOW( gui->post->window ), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
    gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( dialog ), FALSE );
    filter = gtk_file_filter_new( );
    gtk_file_filter_add_pattern( filter, "*.m3u" );
    gtk_file_chooser_set_filter( GTK_FILE_CHOOSER( dialog ), filter );

    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
    {
        char *filename;
        FILE *fp;
        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));

        FOPEN(fp, filename, "r");
        if (fp == NULL) {
            ftd_gui_dialog_show( NULL, "Kan het bestand niet openen.", gui->post->window, TRUE );
        }
        else {
            FtdString *data;

            /* Lees ALLE data uit de file en bewaar deze in een buffer */
            data = ftd_string_new("");
            while (!feof(fp)) {
                char buf[1024];
                if (fgets(buf, sizeof(buf), fp)) {
                    data = ftd_string_append(data, buf);
                }
            }
            fclose (fp);

            ftd_gui_post_parse_m3u_data( data );
            ftd_string_free( data );
        }

        g_free (filename);
    }
    gtk_widget_destroy (dialog);
}

void
ftd_gui_post_parse_m3u_data(FtdString *data)
{
    char buf[2048];
    FtdString *line = NULL;
    char *pdata;
    int finger;
    int isExtendedM3U = -1;

    if( !ftd_string_length( data ) ) {
        return;
    }

    pdata = ftd_string_value( data );
    finger = 0;
    do {
        // Zijn we aan het einde van een regel? (of de string)
        if( *pdata == '\n' || *pdata == '\r' || *pdata == 0 ) {
            char * p1, * p2;
            FtdString * filename = NULL;
            GtkTreeIter iter;
            buf[finger] = 0;
            if( line ) {
                line = ftd_string_append( line, buf );
            }
            else {
                line = ftd_string_new( buf );
            }
            finger = 0;


            // Eerst een paar checks voor extended m3u
            if( isExtendedM3U == -1 ) {
                p1 = ftd_string_value( line );
                if( strstr( p1, "#EXTM3U" ) == p1 ) {
                    isExtendedM3U = 1;
                    ftd_string_free( line );
                    line = NULL;
                    continue;
                }
                else {
                    isExtendedM3U = 0;
                }
            }
            if( isExtendedM3U ) {
                p1 = ftd_string_value( line );
                // Info tags overslaan: we gebruiken ze niet
                if( strstr( p1, "#EXTINF" ) == p1 ) {
                    ftd_string_free( line );
                    line = NULL;
                    continue;
                }
            }
            // Vind de filename
            p1 = ftd_string_value( line );
            p2 = p1 + ftd_string_length( line ) - 1;
#ifdef WIN32
            while( p2 > p1 && *(p2 - 1) != '\\' )
#else
            while( p2 > p1 && *(p2 - 1) != '/' )
#endif
            {
                p2--;
            }
            filename = ftd_string_new( p2 );
            ftd_string_free( line );
            line = NULL;
            if( !( filename && ftd_string_length( filename ) ) ) {
                ftd_string_free( filename );
                continue;
            }
            // Toevoegen aan de lijsten
            gtk_list_store_append( gui->post->liststoreM3UPlaylist, &iter );
            gtk_list_store_set( gui->post->liststoreM3UPlaylist, &iter, 0, ftd_string_value( filename ), -1 );

            gui->post->mp3files = ftd_list_append( gui->post->mp3files, filename );

            continue;
        }

        // Sla karakter op in de buffer
        buf[finger++] = *pdata;
        // Voorkom buffer-overflow
        if( finger == 2047 ) {
            buf[finger] = 0;
            if( line ) {
                line = ftd_string_append( line, buf );
            }
            else {
                line = ftd_string_new( buf );
            }
            finger = 0;
        }
    } while( *(pdata++) );

    if( gui->post->mp3files ) {
        if( g_object_get_data( G_OBJECT( gui->post->treeviewM3UPlaylist ), "color-changed" ) ) {
            g_object_set_data( G_OBJECT( gui->post->treeviewM3UPlaylist ), "color-changed", (gpointer) 0 );
            gtk_widget_modify_text( gui->post->treeviewM3UPlaylist, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->treeviewM3UPlaylist, GTK_STATE_NORMAL, NULL );
        }
    }

    // Shouldn't be needed
    if( line ) {
        ftd_string_free( line );
    }
}

void
ftd_gui_post_clear_playlist(GtkWidget *caller, gpointer data)
{
    FtdList *list;

    gtk_list_store_clear( gui->post->liststoreM3UPlaylist );

    if( gui->post->mp3files ) {
        list = gui->post->mp3files;
        while( list ) {
            FtdString * file = ftd_list_value( list );
            ftd_string_free( file );
            list = ftd_list_next( list );
        }
        ftd_list_free( gui->post->mp3files );
        gui->post->mp3files = NULL;
    }
}

gboolean
ftd_gui_post_check_tab3()
{
    GdkColor rood = { 0, 65535, 0, 0 };
    GdkColor zwart = { 0, 0, 0, 0 };

    if( gtk_combo_box_get_active( GTK_COMBO_BOX( gui->post->comboboxBestandstype ) ) != 5 || gui->post->mp3files ) {
        if( g_object_get_data( G_OBJECT( gui->post->treeviewM3UPlaylist ), "color-changed" ) ) {
            g_object_set_data( G_OBJECT( gui->post->treeviewM3UPlaylist ), "color-changed", (gpointer) 0 );
            gtk_widget_modify_text( gui->post->treeviewM3UPlaylist, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->treeviewM3UPlaylist, GTK_STATE_NORMAL, NULL );
        }
        return TRUE;
    }
    else {
        if( !g_object_get_data( G_OBJECT( gui->post->treeviewM3UPlaylist ), "color-changed" ) ) {
            g_object_set_data( G_OBJECT( gui->post->treeviewM3UPlaylist ), "color-changed", (gpointer) 1 );
            gtk_widget_modify_text( gui->post->treeviewM3UPlaylist, GTK_STATE_NORMAL, &zwart );
            gtk_widget_modify_base( gui->post->treeviewM3UPlaylist, GTK_STATE_NORMAL, &rood );
        }
        return FALSE;
    }
}

void
ftd_gui_post_verder3(GtkWidget *caller, gpointer data)
{
    if( ftd_gui_post_check_tab3( ) ) {
        gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 3 );
    }
}

void
ftd_gui_post_verder4(GtkWidget *caller, gpointer data)
{
    gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 4 );
}

void
ftd_gui_post_versturen(GtkWidget *caller, gpointer data)
{
   g_idle_add( (GSourceFunc) ftd_gui_post_versturen_impl, NULL );
}

gboolean
ftd_gui_post_versturen_impl(gpointer data)
{
    int n;
    FtdEvent * event = NULL;
    GList * list;
    FtdList * ftdlist;
    GtkTextIter text_iter_start, text_iter_end;
    GtkTextBuffer * textbuffer;
    FtdErrorCode err;
    // Check of er minimaal 1 en maximaal 3 groepen zijn geselecteerd
    n = gtk_tree_selection_count_selected_rows( gtk_tree_view_get_selection( GTK_TREE_VIEW( gui->post->treeviewNieuwsgroepen ) ) );
    if( n < 1 ) {
        ftd_gui_dialog_show( NULL, "Je moet minimaal 1 nieuwsgroep selecteren.", gui->post->window, FALSE );
        return FALSE;
    }
    else if( n > 3 ) {
        ftd_gui_dialog_show( NULL, "Je mag niet meer dan 3 nieuwsgroepen selecteren.", gui->post->window, FALSE );
        return FALSE;
    }

    // Alles voor de zekerheid nog even checken
    if( !ftd_gui_post_check_tab1() ) {
        gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 0 );
        return FALSE;
    }
    if( !ftd_gui_post_check_tab2() ) {
        gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 1 );
        return FALSE;
    }
    if( gtk_combo_box_get_active( GTK_COMBO_BOX( gui->post->comboboxBestandstype ) ) == 5 ) {
        if( !ftd_gui_post_check_tab3() ) {
            gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 2 );
            return FALSE;
        }
    }

    event = ftd_gui_post_generate_event();

    err = ftd_post_send( event, ftd_gui_post_send_callback );
    if( err ) {
        ftd_gui_errhandler( gui->post->window, FTD_ONDERDEEL_POST, err, NULL );
    }

    ftd_event_free( event );
    gtk_widget_destroy( gui->post->window );

    return FALSE;
}

FtdEvent *
ftd_gui_post_generate_event(void)
{
    int n;
    FtdEvent * event = NULL;
    GList * list;
    FtdList * ftdlist;
    GtkTextIter text_iter_start, text_iter_end;
    GtkTextBuffer * textbuffer;
    FtdErrorCode err;

    event = (FtdEvent *) g_malloc0( sizeof( FtdEvent ) );

    if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioPostSpot ) ) ) {
        event->status = FTDSTATUS_SPOT;
    }
    else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioPostAankondiging ) ) ) {
        event->status = FTDSTATUS_ANNOUNCE;
    }
    else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioPostBezigUploaden ) ) ) {
        event->status = FTDSTATUS_UPLOADING;
    }
    else {
        ftd_gui_dialog_show( NULL, "Er lijkt geen status gekozen te zijn.", gui->post->window, FALSE );
        ftd_event_free( event );
        return FALSE;
    }

    event->fileName = ftd_string_new( gtk_entry_get_text( GTK_ENTRY( gui->post->entryBestandsnaam ) ) );

    event->title = ftd_string_new( gtk_entry_get_text( GTK_ENTRY( gui->post->entryTitel ) ) );

    list = gtk_tree_selection_get_selected_rows( gtk_tree_view_get_selection( GTK_TREE_VIEW( gui->post->treeviewNieuwsgroepen ) ), NULL );
    while( list ) {
        GtkTreeIter iter;
        char buf[512];
        int id;
        GtkTreePath *path = (GtkTreePath*) list->data;
        gtk_tree_model_get_iter( GTK_TREE_MODEL( gui->post->liststoreNieuwsgroepen ), &iter, path );
        gtk_tree_model_get( GTK_TREE_MODEL( gui->post->liststoreNieuwsgroepen ), &iter, 1, &id, -1 );
        snprintf( buf, 512, "%d", id );
        event->groups = ftd_list_append( event->groups, ftd_string_new( g_strdup( buf ) ) );
        gtk_tree_path_free( path );
        list = g_list_next( list );
    }
    g_list_free( list );

    event->link = ftd_string_new( gtk_entry_get_text( GTK_ENTRY( gui->post->entryURL ) ) );
    // Lege en semi-lege ('http://') strings weggooien
    if( event->link && !( ftd_string_length( event->link ) && strcmp( ftd_string_value( event->link ), "http://" ) ) ) {
        ftd_string_free( event->link );
        event->link = NULL;
    }

    event->cat = gtk_combo_box_get_active(GTK_COMBO_BOX(gui->post->comboboxCat));
    if( event->cat < 0 ) {
        ftd_gui_dialog_show( NULL, "Er lijkt geen categorie gekozen te zijn.", gui->post->window, FALSE );
        ftd_event_free( event );
        return FALSE;
    }

    event->sCat = gtk_combo_box_get_active(GTK_COMBO_BOX(gui->post->comboboxSCat));
    if( event->sCat < 0 ) {
        ftd_gui_dialog_show( NULL, "Er lijkt geen sub-categorie gekozen te zijn.", gui->post->window, FALSE );
        ftd_event_free( event );
        return FALSE;
    }

    ftdlist = gui->post->listCheckbuttonTags;
    while( ftdlist ) {
        GtkToggleButton * checkbuttonTag = GTK_TOGGLE_BUTTON( ftd_list_value( ftdlist ) );
        if( gtk_toggle_button_get_active( checkbuttonTag ) ) {
            event->tags = ftd_list_append( event->tags, ftd_string_new( ftd_string_value( (FtdString *) g_object_get_data( G_OBJECT( checkbuttonTag ), "ftd_tag_code" ) ) ) );
        }
        ftdlist = ftd_list_next( ftdlist );
    }

    event->extra_tag = ftd_string_new( gtk_entry_get_text( GTK_ENTRY( gui->post->entryTag ) ) );
    if( event->extra_tag && !ftd_string_length( event->extra_tag ) ) {
        ftd_string_free( event->extra_tag );
        event->extra_tag = NULL;
    }

    textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( gui->post->textviewAankondiging ) );
    gtk_text_buffer_get_start_iter( textbuffer, &text_iter_start );
    gtk_text_buffer_get_end_iter( textbuffer, &text_iter_end );
    event->announcement = ftd_string_new( gtk_text_buffer_get_text( textbuffer, &text_iter_start, &text_iter_end, TRUE ) );
    if( event->announcement && !ftd_string_length( event->announcement ) ) {
        ftd_string_free( event->announcement );
        event->announcement = NULL;
    }

    textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( gui->post->textviewOmschrijving ) );
    gtk_text_buffer_get_start_iter( textbuffer, &text_iter_start );
    gtk_text_buffer_get_end_iter( textbuffer, &text_iter_end );
    event->description = ftd_string_new( gtk_text_buffer_get_text( textbuffer, &text_iter_start, &text_iter_end, TRUE ) );
    if( event->description && !ftd_string_length( event->description ) ) {
        ftd_string_free( event->description );
        event->description = NULL;
    }

    textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( gui->post->textviewRepostbeleid ) );
    gtk_text_buffer_get_start_iter( textbuffer, &text_iter_start );
    gtk_text_buffer_get_end_iter( textbuffer, &text_iter_end );
    event->sig = ftd_string_new( gtk_text_buffer_get_text( textbuffer, &text_iter_start, &text_iter_end, TRUE ) );
    if( event->sig && !ftd_string_length( event->sig ) ) {
        ftd_string_free( event->sig );
        event->sig = NULL;
    }

    switch( gtk_combo_box_get_active( GTK_COMBO_BOX( gui->post->comboboxBestandstype ) ) ) {
        case 0 :
            // RAR .rar .r01 .r02
            event->fileType = 1;
            break;
        case 1 :
            // RAR .001 .002 .003
            event->fileType = 4;
            break;
        case 2 :
            // RAR .part01.rar .part02.rar .part03.rar
            event->fileType = 6;
            break;
        case 3 :
            // ACE
            event->fileType = 2;
            break;
        case 4 :
            // ZIP
            event->fileType = 3;
            break;
        case 5 :
            // M3U
            event->fileType = 5;
            break;
        default :
            ftd_gui_dialog_show( NULL, "Er lijkt geen (geldig) bestandstype gekozen te zijn.", gui->post->window, FALSE );
            ftd_event_free( event );
            return FALSE;
    }

    event->aantalFiles = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonAantalBestanden ) );

    event->fileStart = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonStartBestanden ) );

    event->image = ftd_string_new( gtk_entry_get_text( GTK_ENTRY( gui->post->entryPlaatje ) ) );
    // Lege en semi-lege ('http://') strings niet toestaan
    if( event->image && !( ftd_string_length( event->image ) && strcmp( ftd_string_value( event->image ), "http://" ) ) ) {
        ftd_string_free( event->image );
        event->image = NULL;
    }

    if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioGeenPar ) ) ) {
        event->parType = 0;
    }
    else {
        if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->checkbuttonPARBlocksBijGereed ) ) ) {
            event->aantalParFiles = -1;
        }
        else {
            event->aantalParFiles = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonAantalParBlocks ) );
        }
        if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( gui->post->radioPar2 ) ) ) {
            event->parType = 2;
        }
        else {
            ftd_gui_dialog_show( NULL, "Er lijkt geen PAR-type gekozen te zijn.", gui->post->window, FALSE );
            ftd_event_free( event );
            return FALSE;
        }
    }

    event->parBlockSize = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonBlocksize ) );

    ftdlist = gui->post->mp3files;
    while( ftdlist ) {
        FtdString * file = (FtdString*) ftd_list_value( ftdlist );
        event->mp3Tracks = ftd_list_append( event->mp3Tracks, ftd_string_new( ftd_string_value( file ) ) );
        ftdlist = ftd_list_next( ftdlist );
    }

    return event;
}

void
ftd_gui_post_switch_page(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data)
{
    int current;
    current = gtk_notebook_get_current_page( notebook );

    // NB: GTK lijkt een bugje te hebben in de notebook: nadat je op een tab klikt en hij nite verspringt, ontvangt
    // die tab geen events meer (of iig niet de juiste) om een switch-page te genereren voordat een andere tab
    // is aangeklikt. Too bad voor gebruikers die dat willen :D.

    if( current == 0 ) {
        if( !ftd_gui_post_check_tab1() ) {
            g_signal_stop_emission_by_name( (gpointer) notebook, "switch-page" );
            return;
        }
    }
    if( current < 2 && page_num > 1 ) {
        if( !ftd_gui_post_check_tab2() ) {
            g_signal_stop_emission_by_name( (gpointer) notebook, "switch-page" );
            if( current != 1 ) {
                gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 1 );
            }
            return;
        }
    }
    if( page_num == 2 && gtk_combo_box_get_active( GTK_COMBO_BOX( gui->post->comboboxBestandstype ) ) != 5 ) {
        g_signal_stop_emission_by_name( (gpointer) notebook, "switch-page" );
        return;
    }
    if( current < 3 && page_num > 2 ) {
        if( !ftd_gui_post_check_tab3() ) {
            g_signal_stop_emission_by_name( (gpointer) notebook, "switch-page" );
            if( current != 2 ) {
                gtk_notebook_set_current_page( GTK_NOTEBOOK( gui->post->tabs ), 2 );
            }
            return;
        }
    }
}

void
ftd_gui_post_titel_changed(GtkWidget *caller, gpointer data)
{
    const char *titel;

    titel = gtk_entry_get_text( GTK_ENTRY( gui->post->entryTitel ) );
    if( titel && strlen( titel ) ) {
        if( g_object_get_data( G_OBJECT( gui->post->entryTitel ), "colorchanged" ) ) {
            gtk_widget_modify_base( gui->post->entryTitel, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_text( gui->post->entryTitel, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->entryTitel ), "colorchanged", (gpointer) 0 );
        }
    }
}

void
ftd_gui_post_aantal_par_blokken_changed(GtkWidget *caller, gpointer data)
{
    if( gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonAantalParBlocks ) ) ) {
        if( g_object_get_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->spinbuttonAantalParBlocks, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->spinbuttonAantalParBlocks ), "colorchanged", (gpointer) 0 );
        }
    }
}

void
ftd_gui_post_blocksize_changed(GtkWidget *caller, gpointer data)
{
    if( gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gui->post->spinbuttonBlocksize ) ) ) {
        if( g_object_get_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged" ) ) {
            gtk_widget_modify_text( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
            gtk_widget_modify_base( gui->post->spinbuttonBlocksize, GTK_STATE_NORMAL, NULL );
            g_object_set_data( G_OBJECT( gui->post->spinbuttonBlocksize ), "colorchanged", (gpointer) 0 );
        }
    }
}

gint
ftd_gui_post_tree_sortable_compare_string(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
{
    gchar *str_a, *str_b;
    gint retval;

    gtk_tree_model_get( model, a, 0, &str_a, -1 );
    gtk_tree_model_get( model, b, 0, &str_b, -1 );

    retval = strcmp(str_a, str_b);

    g_free(str_a);
    g_free(str_b);

    return retval;
}

void
ftd_gui_post_send_callback(FtdSendState status)
{
    switch( status ) {
        case SEND_STATE_NONE :
            //printf( "Niets te melden bij het zenden.\n" );
            break;
        case SEND_STATE_STARTING :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 1.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Verzamelen van gegevens..." );
            break;
        case SEND_STATE_FASE_1_CONNECT :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 2.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Verzenden van post..." );
            break;
        case SEND_STATE_FASE_1_DONE :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 3.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Post verzonden..." );
            break;
        case SEND_STATE_FASE_1_ACCEPTED :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 4.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Post verzenden is gelukt." );
            break;
        case SEND_STATE_FASE_2_CONNECT :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 5.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Verzenden van omschrijving..." );
            break;
        case SEND_STATE_FASE_2_DONE :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 6.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Omschrijving verzonden..." );
            break;
        case SEND_STATE_FASE_2_ACCEPTED :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 7.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Omschrijving verzenden is gelukt." );
            break;
        case SEND_STATE_FASE_3_CONNECT :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 8.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Verzenden van repost-beleid..." );
            break;
        case SEND_STATE_FASE_3_DONE :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 9.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Repost-beleid verzonden..." );
            break;
        case SEND_STATE_FASE_3_ACCEPTED :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 10.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Repost-beleid verzenden is gelukt." );
            break;
        case SEND_STATE_FASE_4_CONNECT :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 11.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Verzenden van mp3 bestandsnamen..." );
            break;
        case SEND_STATE_FASE_4_DONE :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 12.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "mp3 bestandsnamen verzonden..." );
            break;
        case SEND_STATE_FASE_4_ACCEPTED :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 13.0/14.0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "mp3 bestandsnamen verzenden is gelukt." );
            break;
        case SEND_STATE_DONE :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 1 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "De post is aangemeld." );
            break;
        case SEND_STATE_DONE_MODERATED :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 1 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "De post is aangemeld, maar moet nog door een modje goedgekeurd worden." );
            break;
        case SEND_STATE_ERROR :
            gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), 0 );
            gtk_progress_bar_set_text( GTK_PROGRESS_BAR( gui->post->progressbarVerzenden ), "Er is een fout opgetreden." );
            break;
    }
    // Force any pending updates in the GUI (GTK FAQ 5.16)
    while (g_main_context_iteration(NULL, FALSE));
}

void
ftd_gui_post_import(GtkWidget *caller, gpointer data)
{
    GtkWidget *dialog;
    xmlDocPtr    doc;
    xmlNodePtr   cur;
    char *inhoud = NULL;
    GError *err = NULL;
    char *filename;
    FtdString *str;

    dialog = gtk_file_chooser_dialog_new("Geef een bestandsnaam op om van te importeren", GTK_WINDOW(gui->post->window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);

    if (!gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
        gtk_widget_destroy (dialog);
        return;
    }

    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
    if (!g_file_get_contents(filename, &inhoud, NULL, &err)) {
        char *msg = g_strdup_printf("Inlezen van bestand mislukt:\n%s", err->message);
        ftd_gui_dialog_show(NULL, msg, gui->post->window, TRUE);
        g_free(filename);

        gtk_widget_destroy(dialog);

        return;
    }

    g_free(filename);

    doc = xmlParseMemory(inhoud, strlen(inhoud));
    cur = xmlDocGetRootElement(doc);
    if (cur == NULL) {
        ftd_gui_dialog_show(NULL, "Opgegeven bestand bevat geen bruikbare gegevens", gui->post->window, TRUE);
        xmlFreeDoc(doc);

        gtk_widget_destroy(dialog);

        return;
    }

    if (strcasecmp(cur->name, "Event")) {
        ftd_gui_dialog_show(NULL, "Opgegeven bestand bevat geen bruikbare gegevens", gui->post->window, TRUE);
        xmlFreeDoc(doc);

        gtk_widget_destroy(dialog);

        return;
    }

    cur = cur->xmlChildrenNode;
    if (!cur) {
        ftd_gui_dialog_show(NULL, "Opgegeven bestand bevat geen bruikbare gegevens", gui->post->window, TRUE);
        xmlFreeDoc(doc);

        gtk_widget_destroy(dialog);

        return;
    }

    do {
        if (!strcasecmp(cur->name, "Title")) {
            str = ftd_xml_parse_string(doc, cur);
            if (str) {
                gtk_entry_set_text(GTK_ENTRY(gui->post->entryTitel), ftd_string_value(str));
                ftd_string_free(str);
            }
        }

        if (!strcasecmp(cur->name, "Link")) {
            str = ftd_xml_parse_string(doc, cur);
            if (str) {
                gtk_entry_set_text(GTK_ENTRY(gui->post->entryURL), ftd_string_value(str));
                ftd_string_free(str);
            }
        }

        if (!strcasecmp(cur->name, "Img")) {
            str = ftd_xml_parse_string(doc, cur);
            if (str) {
                gtk_entry_set_text(GTK_ENTRY(gui->post->entryPlaatje), ftd_string_value(str));
                ftd_string_free(str);
            }
        }

        if (!strcasecmp(cur->name, "Cat")) {
            gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxCat), ftd_xml_parse_int(doc, cur));
        }

        if (!strcasecmp(cur->name, "SCat")) {
            gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxSCat), ftd_xml_parse_int(doc, cur));
        }

        if (!strcasecmp(cur->name, "Tags")) {
            FtdList *list_internal, *list_tags;
            FtdList *list, *list_buttons = gui->post->listCheckbuttonTags;

            str = ftd_xml_parse_string(doc, cur);
            if (!str) {
                continue;
            }

            list_tags = ftd_splitted_list_split(ftd_string_value(str));
            ftd_string_free(str);

            list = list_buttons;
            while (list) {
                GtkToggleButton * checkbuttonTag = GTK_TOGGLE_BUTTON(ftd_list_value(list));

                str = g_object_get_data(G_OBJECT(checkbuttonTag), "ftd_tag_code");

                list_internal = list_tags;
                while (list_internal) {
                    FtdString *item = ftd_list_value(list_internal);

                    if (!strcmp(ftd_string_value(item), ftd_string_value(str))) {
                        gtk_toggle_button_set_active(checkbuttonTag, TRUE);
                    }

                    list_internal = ftd_list_next(list_internal);
                }

                list = ftd_list_next(list);
            }

            ftd_splitted_list_free(&list_tags);
        }

        if (!strcasecmp(cur->name, "Tag")) {
            str = ftd_xml_parse_string(doc, cur);
            if (str) {
                gtk_entry_set_text(GTK_ENTRY(gui->post->entryTag), ftd_string_value(str));
                ftd_string_free(str);
            }
        }

        if (!strcasecmp(cur->name, "Status")) {
            switch (ftd_xml_parse_int(doc, cur)) {
                case FTDSTATUS_SPOT:
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui->post->radioPostSpot), TRUE);
                    break;

                case FTDSTATUS_ANNOUNCE:
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui->post->radioPostAankondiging), TRUE);
                    break;

                case FTDSTATUS_UPLOADING:
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui->post->radioPostBezigUploaden), TRUE);
                    break;
            }
        }

        if (!strcasecmp(cur->name, "Groups")) {
            GtkTreeIter iter;
            GtkTreeModel *model;
            int id;
            FtdList *list_groups, *list;
            GtkTreeSelection *select = gtk_tree_view_get_selection(GTK_TREE_VIEW(gui->post->treeviewNieuwsgroepen));
            gtk_tree_selection_unselect_all(select);

            model = gtk_tree_view_get_model(GTK_TREE_VIEW(gui->post->treeviewNieuwsgroepen));

            str = ftd_xml_parse_string(doc, cur);
            if (!str) {
                continue;
            }

            list_groups = list = ftd_splitted_list_split(ftd_string_value(str));
            ftd_string_free(str);

            gtk_tree_model_get_iter_first(model, &iter);
            do {
                gtk_tree_model_get(model, &iter, 1, &id, -1);
                list = list_groups;
                while (list) {
                    FtdString *str = ftd_list_value(list);
                    if (atoi(ftd_string_value(str)) == id) {
                        gtk_tree_selection_select_iter(select, &iter);
                    }

                    list = ftd_list_next(list);
                }
            } while (gtk_tree_model_iter_next(model, &iter));

            ftd_splitted_list_free(&list_groups);
        }

        if (!strcasecmp(cur->name, "FType")) {
            switch (ftd_xml_parse_int(doc, cur)) {
                case 1:
                    // RAR .rar .r01 .r02
                    gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxBestandstype), 0);
                    break;

                case 2:
                    // ACE
                    gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxBestandstype), 3);
                    break;

                case 3:
                    // ZIP
                    gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxBestandstype), 4);
                    break;

                case 4:
                    // RAR .001 .002 .003
                    gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxBestandstype), 1);
                    break;

                case 5:
                    // M3U
                    gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxBestandstype), 5);
                    break;

                case 6:
                    // RAR .part01.rar .part02.rar .part03.rar
                    gtk_combo_box_set_active(GTK_COMBO_BOX(gui->post->comboboxBestandstype), 2);
                    break;
            }
        }

        if (!strcasecmp(cur->name, "FName")) {
            str = ftd_xml_parse_string(doc, cur);
            if (str) {
                gtk_entry_set_text(GTK_ENTRY(gui->post->entryBestandsnaam), ftd_string_value(str));
                ftd_string_free(str);
            }
        }

        if (!strcasecmp(cur->name, "FStart")) {
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(gui->post->spinbuttonStartBestanden), ftd_xml_parse_int(doc, cur));
        }

        if (!strcasecmp(cur->name, "FCount")) {
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(gui->post->spinbuttonAantalBestanden), ftd_xml_parse_int(doc, cur));
        }

        if (!strcasecmp(cur->name, "ParType")) {
            switch(ftd_xml_parse_int(doc, cur)) {
                case 0:
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui->post->radioGeenPar), TRUE);
                    break;

                case 2:
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui->post->radioPar2), TRUE);
                    break;
            }
        }

        if (!strcasecmp(cur->name, "ParCount")) {
            if (ftd_xml_parse_int(doc, cur) == -1) {
                gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( gui->post->checkbuttonPARBlocksBijGereed ), TRUE);
            } else {
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(gui->post->spinbuttonAantalParBlocks), ftd_xml_parse_int(doc, cur));
            }
        }

        if (!strcasecmp(cur->name, "ParBlockSize")) {
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(gui->post->spinbuttonBlocksize), ftd_xml_parse_int(doc, cur));
        }

        if (!strcasecmp(cur->name, "Ann")) {
            GtkTextBuffer *textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( gui->post->textviewAankondiging ) );

            str = ftd_xml_parse_string(doc, cur);
            if (str) {
                gtk_text_buffer_set_text(textbuffer, ftd_string_value(str), ftd_string_length(str));
                ftd_string_free(str);
            }
        }

        if (!strcasecmp(cur->name, "Desc")) {
            GtkTextBuffer *textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( gui->post->textviewOmschrijving ) );

            str = ftd_xml_parse_string(doc, cur);
            if (str) {
                gtk_text_buffer_set_text(textbuffer, ftd_string_value(str), ftd_string_length(str));
                ftd_string_free(str);
            }
        }

        if (!strcasecmp(cur->name, "Rep")) {
            GtkTextBuffer *textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( gui->post->textviewRepostbeleid ) );

            str = ftd_xml_parse_string(doc, cur);
            if (str) {
                gtk_text_buffer_set_text(textbuffer, ftd_string_value(str), ftd_string_length(str));
                ftd_string_free(str);
            }
        }
    } while ((cur=cur->next));

    xmlFreeDoc(doc);

    gtk_widget_destroy (dialog);
}

void
ftd_gui_post_export(GtkWidget *caller, gpointer data)
{
    GtkWidget *dialog;
    xmlNodePtr node, cdataNode, tmpNode;
    xmlDocPtr doc;
    char *filename;
    int retval;
    FtdString *str;
    FtdEvent *event;

    dialog = gtk_file_chooser_dialog_new("Geef een bestandsnaam op om naar te exporteren", GTK_WINDOW(gui->post->window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
#if GTK_CHECK_VERSION(2,8,0)
    gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
#endif

    if (!gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
        gtk_widget_destroy (dialog);
        return;
    }

    event = ftd_gui_post_generate_event();

    doc = xmlNewDoc(BAD_CAST "1.0");
    node = xmlNewNode(NULL, BAD_CAST "Event");
    xmlDocSetRootElement(doc, node);

    cdataNode = xmlNewCDataBlock(doc, ftd_string_value(event->title), ftd_string_length(event->title));
    tmpNode = xmlNewNode(NULL, "Title");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    if (event->link) {
        cdataNode = xmlNewCDataBlock(doc, ftd_string_value(event->link), ftd_string_length(event->link));
    } else {
        cdataNode = xmlNewCDataBlock(doc, "", 0);
    }
    tmpNode = xmlNewNode(NULL, "Link");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    if (event->image) {
        cdataNode = xmlNewCDataBlock(doc, ftd_string_value(event->image), ftd_string_length(event->image));
    } else {
        cdataNode = xmlNewCDataBlock(doc, "", 0);
    }
    tmpNode = xmlNewNode(NULL, "Img");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    str = ftd_string_integer(event->cat);
    xmlNewTextChild(node, NULL, "Cat", ftd_string_value(str));
    ftd_string_free(str);

    str = ftd_string_integer(event->sCat);
    xmlNewTextChild(node, NULL, "SCat", ftd_string_value(str));
    ftd_string_free(str);

    str = ftd_splitted_list_concat(event->tags);
    cdataNode = xmlNewCDataBlock(doc, ftd_string_value(str), ftd_string_length(str));
    tmpNode = xmlNewNode(NULL, "Tags");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    if (event->extra_tag) {
        cdataNode = xmlNewCDataBlock(doc, ftd_string_value(event->extra_tag), ftd_string_length(event->extra_tag));
    } else {
        cdataNode = xmlNewCDataBlock(doc, "", 0);
    }
    tmpNode = xmlNewNode(NULL, "Tag");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    str = ftd_string_integer(event->status);
    xmlNewTextChild(node, NULL, "Status", ftd_string_value(str));
    ftd_string_free(str);

    str = ftd_splitted_list_concat(event->groups);
    cdataNode = xmlNewCDataBlock(doc, ftd_string_value(str), ftd_string_length(str));
    tmpNode = xmlNewNode(NULL, "Groups");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    str = ftd_string_integer(event->fileType);
    xmlNewTextChild(node, NULL, "FType", ftd_string_value(str));
    ftd_string_free(str);

    if (event->fileName) {
        cdataNode = xmlNewCDataBlock(doc, ftd_string_value(event->fileName), ftd_string_length(event->fileName));
    } else {
        cdataNode = xmlNewCDataBlock(doc, "", 0);
    }
    tmpNode = xmlNewNode(NULL, "FName");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    str = ftd_string_integer(event->fileStart);
    xmlNewTextChild(node, NULL, "FStart", ftd_string_value(str));
    ftd_string_free(str);

    str = ftd_string_integer(event->aantalFiles);
    xmlNewTextChild(node, NULL, "FCount", ftd_string_value(str));
    ftd_string_free(str);

    str = ftd_string_integer(event->parType);
    xmlNewTextChild(node, NULL, "ParType", ftd_string_value(str));
    ftd_string_free(str);

    str = ftd_string_integer(event->aantalParFiles);
    xmlNewTextChild(node, NULL, "ParCount", ftd_string_value(str));
    ftd_string_free(str);

    str = ftd_string_integer(event->parBlockSize);
    xmlNewTextChild(node, NULL, "ParBlockSize", ftd_string_value(str));
    ftd_string_free(str);

    if (event->announcement) {
        cdataNode = xmlNewCDataBlock(doc, ftd_string_value(event->announcement), ftd_string_length(event->announcement));
    } else {
        cdataNode = xmlNewCDataBlock(doc, "", 0);
    }
    tmpNode = xmlNewNode(NULL, "Ann");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    if (event->description) {
        cdataNode = xmlNewCDataBlock(doc, ftd_string_value(event->description), ftd_string_length(event->description));
    } else {
        cdataNode = xmlNewCDataBlock(doc, "", 0);
    }
    tmpNode = xmlNewNode(NULL, "Desc");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    if (event->sig) {
        cdataNode = xmlNewCDataBlock(doc, ftd_string_value(event->sig), ftd_string_length(event->sig));
    } else {
        cdataNode = xmlNewCDataBlock(doc, "", 0);
    }
    tmpNode = xmlNewNode(NULL, "Rep");
    xmlAddChild(tmpNode, cdataNode);
    xmlAddChild(node, tmpNode);

    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
    xmlSetCompressMode(0);
    retval = xmlSaveFormatFile(filename, doc, 1);
    g_free (filename);

    gtk_widget_destroy (dialog);

    if (retval >= 0) {
        ftd_gui_dialog_show(NULL, "Exporteren van gegevens geslaagd\n", gui->post->window, FALSE);
    } else {
        ftd_gui_dialog_show(NULL, "Exporteren van gegevens mislukt\n", gui->post->window, TRUE);
    }
}
