/* ====================================================================
 * 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 <stdio.h>
#include "ftd_gui_main.h"
#include "ftd_gui_worksheet.h"
#include "ftd_gui_config.h"
#include "ftd_gui_center.h"
#include "ftd_gui_search.h"
#include "ftd_gui_center.h"
#include "ftd_gui_categories.h"
#include "ftd_gui_mail.h"
#include "ftd_gui_toolbar.h"
#include "ftd_gui_post.h"
#include "ftd_gui_errhandler.h"
#include "ftd_gui_sidebar.h"
#include "ftd_gui_group_view.h"
#include "ftd_gui_xslt.h"
#include "ftd_gui_parse.h"
#include "ftd_gui_notification.h"
#include "ftd_gui_status_filter.h"

static void
watcher_foreach_func(const FtdEvent *event, const char *zoekterm, gpointer data)
{
    FtdString *msg = (FtdString *) data;

    if (!event->gevonden_voor_watcher) {
        return;
    }

    if (ftd_string_length(msg) == 0) {
        ftd_string_append_printf(msg, "Er zijn nieuwe postings gevonden die aan\nzoekterm '%s' voldoen:\n\n%s - %s", zoekterm, ftd_string_value(event->title), ftd_string_value(event->poster));
    } else {
        ftd_string_append_printf(msg, "\n%s - %s", ftd_string_value(event->title), ftd_string_value(event->poster));
    }
}

gboolean
ftd_gui_callback_afsluiten(GtkWidget *caller, gpointer data)
{
    g_assert(gui);

#ifndef DARWIN
    if (gui->trayIconActivated) {
        ftd_gui_tray_destroy();
    }
#endif

    g_free(gui->menu);
    g_free(gui->toolbar);
    g_free(gui->worksheet->sidebar->search);
    g_free(gui->worksheet->sidebar);
    g_free(gui->worksheet->center->eventlist);
    g_free(gui->worksheet->center);
    g_free(gui->worksheet);

    gtk_main_quit();

    return FALSE;
}

void
ftd_gui_callback_updaten_file(int num, int cur)
{
    char msg[256];

    if (num == 0 && cur == 0) {
        snprintf(msg, sizeof(msg), "Bezig met ophalen van lijst met beschikbare updates...");
    } else {
        snprintf(msg, sizeof(msg), "Bezig met downloaden van updatebestand %i van %i...", cur, num);
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gui->progressbar), (gdouble) cur / num);
        gtk_widget_show(gui->progressbar);
    }

    gtk_statusbar_push(GTK_STATUSBAR(gui->statusbar), 0, msg);

    while (g_main_context_iteration(NULL, FALSE));
}

void
ftd_gui_callback_updaten_parse(int num, int cur, gpointer data)
{
    char msg[256];
    snprintf(msg, sizeof(msg), "Bezig met verwerken van FTD postings (%i/%i)", cur, num);
    gtk_statusbar_push(GTK_STATUSBAR(gui->statusbar), 0, msg);
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gui->progressbar), (gdouble) cur / num);

    while (g_main_context_iteration(NULL, FALSE));
}

void
ftd_gui_callback_updaten_status(gpointer data)
{
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gui->progressbar), 0);

    ftd_gui_status_push();
}

gboolean
ftd_gui_callback_updaten(GtkWidget *caller, gpointer data)
{
    g_assert(gui);

    if (data == NULL) {
        FtdList *tasks = NULL;
        FtdStatusTask *task;

        task = (FtdStatusTask *) g_malloc0(sizeof(FtdStatusTask));
        task->tekst = ftd_string_new("Ophalen nieuwe FTD gegevens");
        tasks = ftd_list_append(tasks, task);

        task = (FtdStatusTask *) g_malloc0(sizeof(FtdStatusTask));
        task->tekst = ftd_string_new("Samenvoegen ontvangen gegevens");
        tasks = ftd_list_append(tasks, task);

        task = (FtdStatusTask *) g_malloc0(sizeof(FtdStatusTask));
        task->tekst = ftd_string_new("Samenstellen van lijst");
        tasks = ftd_list_append(tasks, task);

        task = (FtdStatusTask *) g_malloc0(sizeof(FtdStatusTask));
        task->tekst = ftd_string_new("Laden van lijst");
        tasks = ftd_list_append(tasks, task);

        ftd_gui_status_new(tasks, gui->window);
    }

    g_idle_add(ftd_gui_callback_do_updaten, FALSE);

    return FALSE;
}

static void
ftd_gui_callback_set_nieuw_filter(void)
{
    FTDEventlist *eventlist;
    FtdFilter *nieuwFilter;

    nieuwFilter = ftd_filter_new_filter();
    nieuwFilter->prevCheck = ftd_config_get()->prevCheck;
    if (ftd_config_get()->groupFilter) {
        nieuwFilter->groupFilterList = ftd_splitted_list_duplicate(ftd_config_get()->groupFilterList);
    }

    nieuwFilter->categoriseerd = TRUE;
    nieuwFilter->statusList = ftd_gui_status_filter_get_filter();

    eventlist = ftd_eventlist_get();
    ftd_eventlist_apply_filter(eventlist, nieuwFilter);
    g_object_unref(eventlist);

    ftd_filter_free_filter(nieuwFilter);
}

#ifndef NO_EXTERNAL_BROWSER
static void
ftd_gui_callback_updaten_create_html(void)
{
    FtdString *uitvoer;

    uitvoer = ftd_events_sort_filtered(ftd_gui_parse);
    ftd_gui_xslt_process (uitvoer, XSLT_TYPE_LIST, HTML_LIST_FILE);

    ftd_string_free (uitvoer);
}
#endif

gboolean
ftd_gui_callback_do_updaten(gpointer data)
{
    FtdErrorCode retval;
    char *title;
    char *errmsg = NULL;

    g_assert(gui);

    gtk_statusbar_push(GTK_STATUSBAR(gui->statusbar), 0, "Bezig met updaten...");

    // Schakel het watchlist icoon uit indien dit nog staat te knipperen
    ftd_watchlist_set_state(2);
    ftd_watcher_set_state(2);

    ftd_gui_toolbar_adjust_watchlist(NULL);

    retval = ftd_events_fetch(ftd_gui_callback_updaten_file, ftd_gui_callback_updaten_parse, ftd_gui_callback_updaten_status, &errmsg, NULL);
    ftd_gui_status_push();

    ftd_gui_categories_fill();

    if (retval != ERROR_NONE) {
        if (retval == ERROR_PLUGIN_UNSUPPORTED || retval == ERROR_PLUGIN_LOCATION ||
            retval == ERROR_PLUGIN_LOAD || retval == ERROR_PLUGIN_EXECUTE ||
            retval == ERROR_MSG || retval == ERROR_UNAUTH || retval == ERROR_PARSE ||
            retval == ERROR_TRANSFER_TIMEOUT || retval == ERROR_READ || retval == ERROR_SEND) {

            ftd_gui_status_push();
            ftd_gui_status_push();
        }

        if (retval == ERROR_DNS || retval == ERROR_NODATA || retval == ERROR_CONNECT || retval == ERROR_UPDATE_LIMIT || retval == ERROR_UPDATE || retval == ERROR_DNS_PROXY) {
            ftd_gui_status_push();
        }

        ftd_gui_status_disable_keep_above();
        if (ftd_gui_status_get_window()) {
            ftd_gui_errhandler(ftd_gui_status_get_window(), FTD_ONDERDEEL_UPDATEN, retval, errmsg);
        } else {
            ftd_gui_errhandler(gui->window, FTD_ONDERDEEL_UPDATEN, retval, errmsg);
        }

        if (retval == ERROR_UPDATE) {
            ftd_gui_status_push();
            ftd_gui_status_push();
            gtk_statusbar_push(GTK_STATUSBAR(gui->statusbar), 0, "Updaten mislukt: nieuwere versie van OpenFTD vereist");
            return FALSE;
        }

        if (retval == ERROR_MSG || retval == ERROR_UNAUTH || retval == ERROR_PARSE || retval == ERROR_UPDATE_LIMIT ||
            retval == ERROR_PLUGIN_UNSUPPORTED || retval == ERROR_PLUGIN_LOCATION ||
            retval == ERROR_PLUGIN_LOAD || retval == ERROR_PLUGIN_EXECUTE ||
            retval == ERROR_TRANSFER_TIMEOUT || retval == ERROR_READ || retval == ERROR_SEND) {

            ftd_gui_status_push();
        }

        if (retval == ERROR_NEW || retval == ERROR_DNS || retval == ERROR_NODATA || retval == ERROR_CONNECT || retval == ERROR_UPDATE_LIMIT || retval == ERROR_DNS_PROXY) {
            // Stel een lijst samen met de nieuwe FTD postings
            ftd_gui_callback_set_nieuw_filter();
#ifndef NO_EXTERNAL_BROWSER
            ftd_gui_callback_updaten_create_html();
#endif
            ftd_gui_center_eventlist_show(NULL);
            ftd_gui_status_push();
        }

        if (retval == ERROR_NEW) {
            title = g_strdup_printf("OpenFTD -- Er zijn %s mensen online -- %i geregistreerde leden", ftd_string_value(ftd_config_get()->numUsersOnline), ftd_config_get()->ledenCount);
            gtk_window_set_title (GTK_WINDOW (gui->window), title);
            ftd_gui_status_push();
            g_free(title);
            gtk_statusbar_push(GTK_STATUSBAR(gui->statusbar), 0, "Klaar met updaten; Geen nieuwe FTD postings ontdekt");
        } else {
            gtk_statusbar_push(GTK_STATUSBAR(gui->statusbar), 0, "Updaten mislukt");
        }

        return FALSE;
    } else {
        gtk_statusbar_push(GTK_STATUSBAR(gui->statusbar), 0, "Klaar met updaten");
    }

    title = g_strdup_printf("OpenFTD -- Er zijn %s mensen online -- %i geregistreerde leden", ftd_string_value(ftd_config_get()->numUsersOnline), ftd_config_get()->ledenCount);
    gtk_window_set_title (GTK_WINDOW (gui->window), title);
    g_free(title);

    ftd_gui_callback_set_nieuw_filter();
#ifndef NO_EXTERNAL_BROWSER
    ftd_gui_callback_updaten_create_html();
#endif
    ftd_gui_center_eventlist_show(NULL);

    // Laat indien nodig het watchlist en watcher icoon in de toolbar knipperen
    if (ftd_watchlist_get_state() == 0 || ftd_watchlist_get_state() == 1) {
        g_timeout_add(500, ftd_gui_toolbar_adjust_watchlist, NULL);
    }
    if (ftd_watcher_get_state() == 0 || ftd_watcher_get_state() == 1) {
#ifdef HAVE_LIBNOTIFY
        if (ftd_config_get()->toonWatcherNotifications) {
            /* Toon notification popups voor alle nieuwe FTD postings die ontdekt
            * zijn door de FTD4Linux Watcher */
            FtdList *list;
            FtdString *msg = ftd_string_new("");

            list = ftd_config_get()->watcher;
            while (list) {
                FtdString *zoekterm = ftd_list_value(list);

                ftd_watcher_foreach(ftd_string_value(zoekterm), watcher_foreach_func, msg);

                list = ftd_list_next(list);
            }

            if (ftd_string_length(msg) > 0) {
                ftd_gui_notification_show("OpenFTD Watcher", ftd_string_value(msg), "", 0 /*event->postId*/);
            }

            ftd_string_free(msg);
        } else {
            g_timeout_add(500, ftd_gui_toolbar_adjust_watcher, NULL);
        }
#else
        g_timeout_add(500, ftd_gui_toolbar_adjust_watcher, NULL);
#endif
    }

    return FALSE;
}

gboolean
ftd_gui_callback_config(GtkWidget *caller, gpointer data)
{
    g_assert(gui);

///#ifdef NO_EXTERNAL_BROWSER
#if 0
    gui->config = ftd_gui_config_new(gui->window, TRUE, FALSE);
#else
    gui->config = ftd_gui_config_new(gui->window, TRUE, TRUE);
#endif

    ftd_gui_config_user_proxyAuth_controle(gui->config, TRUE);

    /* We moeten een speciale signal handler aanmaken zodat we een
       seintje krijgen indien het config venster afgesloten wordt.
       Dit is nodig om gemaakte wijzigingen toe te kunnen passen */
    g_signal_connect(G_OBJECT(gui->config->window), "destroy",
                     G_CALLBACK(ftd_gui_callback_config_destroy), NULL);

    return FALSE;
}

gboolean
ftd_gui_callback_config_destroy(GtkWidget *caller, gpointer data)
{
#ifndef DARWIN
    if (ftd_config_get()->trayIcon && !gui->trayIconActivated) {
        ftd_gui_tray_create(NULL);
    }

    if (!ftd_config_get()->trayIcon && gui->trayIconActivated) {
        ftd_gui_tray_destroy();
    }
#endif

    if (ftd_config_get()->toonGUIGroupFilter && !gui->worksheet->sidebar->group_view) {
        FtdGuiSidebar *bar = gui->worksheet->sidebar;
        ftd_gui_group_view_new();
        gtk_box_pack_start(GTK_BOX(bar->widget), bar->group_view->widget, TRUE, TRUE, 0);
    }

    if (!ftd_config_get()->toonGUIGroupFilter && gui->worksheet->sidebar->group_view) {
        ftd_gui_group_view_free();
        gtk_paned_set_position (GTK_PANED (gui->worksheet->widget), 170);
    }

    ftd_gui_categories_fill( );

    return FALSE;
}

gboolean
ftd_gui_callback_nieuw(GtkWidget *caller, gpointer data)
{
    g_assert(gui);

    if (data == NULL) {
        FtdList *tasks = NULL;
        FtdStatusTask *task;

        task = (FtdStatusTask *) g_malloc0(sizeof(FtdStatusTask));
        task->tekst = ftd_string_new("Samenstellen van lijst");
        tasks = ftd_list_append(tasks, task);

        task = (FtdStatusTask *) g_malloc0(sizeof(FtdStatusTask));
        task->tekst = ftd_string_new("Laden van lijst");
        tasks = ftd_list_append(tasks, task);

        ftd_gui_status_new(tasks, gui->window);
    }

    g_idle_add(ftd_gui_callback_do_nieuw, FALSE);

    return FALSE;
}

gboolean
ftd_gui_callback_do_nieuw(gpointer data)
{
    FtdFilter *nieuwFilter;
    char *title;
    FTDEventlist *eventlist;
#ifndef NO_EXTERNAL_BROWSER
    FtdString *uitvoer;
#endif

    g_assert (gui);

    /* stel het filter goed in */
    nieuwFilter = ftd_filter_new_filter();
    if (ftd_config_get()->toonCategoriseerdeLijstBijKnopNieuw) {
        nieuwFilter->categoriseerd = TRUE;
    } else {
        nieuwFilter->categoriseerd = FALSE;
    }
    nieuwFilter->prevCheck = ftd_config_get()->prevCheck;
    if (ftd_config_get()->groupFilter) {
        nieuwFilter->groupFilterList = ftd_splitted_list_duplicate(ftd_config_get()->groupFilterList);
    }
    nieuwFilter->statusList = ftd_gui_status_filter_get_filter();

    eventlist = ftd_eventlist_get();
    ftd_eventlist_apply_filter(eventlist, nieuwFilter);
    g_object_unref(eventlist);

#ifndef NO_EXTERNAL_BROWSER
    uitvoer = ftd_events_sort_filtered(ftd_gui_parse);

    if (ftd_config_get()->toonCategoriseerdeLijstBijKnopNieuw) {
        ftd_gui_xslt_process (uitvoer, XSLT_TYPE_LIST, HTML_LIST_FILE);
    } else {
        ftd_gui_xslt_process (uitvoer, XSLT_TYPE_LIST_TOTAL, HTML_LIST_FILE);
    }

    ftd_string_free (uitvoer);
#endif

    ftd_gui_status_push();

    ftd_gui_categories_fill();

    title = g_strdup_printf("OpenFTD -- Er zijn %s mensen online -- %i geregistreerde leden", ftd_string_value(ftd_config_get()->numUsersOnline), ftd_config_get()->ledenCount);
    gtk_window_set_title (GTK_WINDOW (gui->window), title);
    g_free(title);

    ftd_gui_center_eventlist_show(NULL);

    return FALSE;
}

gboolean
ftd_gui_callback_mail(GtkWidget *caller, gpointer data)
{
    gtk_widget_show_all(gui->mail->window);
    gtk_widget_grab_focus(gui->mail->window);

    return FALSE;
}

gboolean
ftd_gui_callback_toevoegen(GtkWidget *caller, gpointer data)
{
    g_assert(gui);

    ftd_gui_post_new();

    return FALSE;
}

gboolean
ftd_gui_callback_watchlist(GtkWidget *caller, gpointer data)
{
    g_assert(gui);

    /* Indien het knopje in de toolbar nog zit te knipperen moeten we dit uitzetten */
    ftd_watchlist_set_state(2);

///#ifndef NO_EXTERNAL_BROWSER
#if 1
    ftd_gui_center_watchlist_create();
#endif

    ftd_gui_center_watchlist_new();

    return FALSE;
}

gboolean
ftd_gui_callback_watcher(GtkWidget *caller, gpointer data)
{
    g_assert(gui);

    /* Indien het knopje in de toolbar nog zit te knipperen moeten we dit uitzetten */
    ftd_watcher_set_state(2);

    ftd_gui_center_watcher_new();

    return FALSE;
}

gboolean
ftd_gui_callback_modje(GtkWidget *caller, gpointer data)
{
    int teller;
    int current_page;

    g_assert(gui);
    g_assert(gui->worksheet);
    g_assert(gui->worksheet->center);
    g_assert(gui->worksheet->center->widget);

    current_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(gui->worksheet->center->widget));

    // Zitten we op een event-info pagina ?
    for (teller = 0; teller < MAX_EVENT_INFO; teller++) {
        FtdGuiCenterEventInfo *eventinfo = gui->worksheet->center->eventinfo[teller];
        if (eventinfo) {
            int page = gtk_notebook_page_num(GTK_NOTEBOOK(gui->worksheet->center->widget), eventinfo->widget);
            if (page == current_page) {
                ftd_gui_modje_create (eventinfo->post_id, 0);

                return FALSE;
            }
        }
    }

    ftd_gui_dialog_show(NULL, "De functie 'Modje' werkt alleen bij postinfo-tabbladen", gui->window, FALSE);

    return FALSE;
}

gboolean
ftd_gui_callback_myftd(GtkWidget *caller, gpointer data)
{
    FtdErrorCode retval;
    char *errmsg = NULL;

    g_assert(gui);

    retval = ftd_gui_center_myftd_create(&errmsg);
    if (retval != ERROR_NONE) {
        ftd_gui_errhandler(gui->window, FTD_ONDERDEEL_MYFTD, retval, errmsg);
        return FALSE;
    }

    ftd_gui_center_myftd_new();

    return FALSE;
}

gboolean
ftd_gui_callback_about(GtkWidget *caller, gpointer data)
{
    ftd_gui_about_show();

    return FALSE;
}

gboolean
ftd_gui_callback_refresh(GtkWidget *caller, gpointer data)
{
    int teller;
    int current_page;

    g_assert(gui);
    g_assert(gui->worksheet);
    g_assert(gui->worksheet->center);
    g_assert(gui->worksheet->center->widget);

    current_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(gui->worksheet->center->widget));

    // Zitten we op een event-info pagina ?
    for (teller = 0; teller < MAX_EVENT_INFO; teller++) {
        FtdGuiCenterEventInfo *eventinfo = gui->worksheet->center->eventinfo[teller];
        if (eventinfo) {
            int page = gtk_notebook_page_num(GTK_NOTEBOOK(gui->worksheet->center->widget), eventinfo->widget);
            if (page == current_page) {
                char url[32];
                snprintf(url, sizeof(url), "iets.html#post%i", eventinfo->post_id);
                ftd_gui_center_eventlist_open_uri (NULL, url, (gpointer) 1);

                return FALSE;
            }
        }
    }

    ftd_gui_dialog_show(NULL, "De functie 'Refresh' werkt alleen bij postinfo-tabbladen", gui->window, FALSE);

    return FALSE;
}

gboolean
ftd_gui_callback_dayselector(GtkWidget *caller, gpointer data)
{
    ftd_gui_dayselector_new();

    return FALSE;
}

gboolean
ftd_gui_callback_vrienden(GtkWidget *caller, gpointer data)
{
///#ifdef NO_EXTERNAL_BROWSER
#if 0
    char *url = g_strdup_printf("http://www.ftd.nu/watch/index.php?login[name]=%s&login[pass]=%s", ftd_string_value(ftd_config_get()->username), ftd_string_value(ftd_config_get()->password));
    ftd_gui_center_launch_browser(url);
    g_free(url);
#else
    if (ftd_config_get()->htmlRenderer != NULL && strcmp(ftd_string_value(ftd_config_get()->htmlRenderer), "GtkHTML") == 0) {
        char *url = g_strdup_printf("http://www.ftd.nu/watch/index.php?login[name]=%s&login[pass]=%s", ftd_string_value(ftd_config_get()->username), ftd_string_value(ftd_config_get()->password));
        ftd_gui_center_launch_browser(url);
        g_free(url);
    } else {
        ftd_gui_center_vrienden_new();
    }
#endif

    return FALSE;
}

gboolean
ftd_gui_callback_import(GtkWidget *caller, gpointer data)
{
    ftd_gui_create_import_ftddb_window();

    return FALSE;
}

#ifdef HAVE_DBUS
void
ftd_gui_callback_bring_to_front(OpenFTDDBusObject *obj)
{
    gtk_window_unstick(GTK_WINDOW(gui->window));
    gtk_window_set_skip_taskbar_hint(GTK_WINDOW(gui->window), FALSE);
    gtk_window_present(GTK_WINDOW(gui->window));
    gtk_widget_grab_focus(gui->window);
}

void
ftd_gui_callback_open_posting(OpenFTDDBusObject *obj, int postID)
{
    char url[32];
    snprintf(url, sizeof(url), "iets.html#post%i", postID);
    ftd_gui_center_eventlist_open_uri (NULL, url, NULL);
}
#endif
