/* ====================================================================
 * 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_center.h"
#include "ftd_gui_center_eventlist.h"
#include "ftd_gui_errhandler.h"
#include "ftd_gui_pixbuf.h"

static gboolean search_equal_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data);
static void fixed_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data);
static void ftd_gui_center_eventlist_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
static void open_posting(int posting);
static gboolean load_finished(gpointer niks);

void
ftd_gui_center_eventlist_new(void)
{
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;
    GtkWidget *label;
    FtdGuiCenterEventList *eventlist = (FtdGuiCenterEventList *) g_malloc0(sizeof(FtdGuiCenterEventList));
    int num;

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

    gui->worksheet->center->eventlist = eventlist;

    eventlist->widget = gtk_scrolled_window_new (NULL, NULL);

    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (eventlist->widget),
                                    GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

    eventlist->store = gtk_list_store_new(13,  G_TYPE_INT,         /* eventid */
                                               G_TYPE_STRING,      /* stamp */
                                               GDK_TYPE_PIXBUF,    /* status */
                                               GDK_TYPE_PIXBUF,    /* cat */
                                               G_TYPE_INT,         /* scat */
                                               G_TYPE_STRING,      /* title */
                                               G_TYPE_STRING,      /* poster */
                                               G_TYPE_POINTER,     /* event -- niet meer gebruiken!! */
                                               G_TYPE_INT,         /* rating */
                                               GDK_TYPE_PIXBUF,    /* link afbeelding */
                                               G_TYPE_BOOLEAN,     /* watchlist */
                                               G_TYPE_STRING,      /* rating text */
                                               G_TYPE_STRING);     /* link url */

    eventlist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(eventlist->store));
    gtk_tree_view_set_hover_selection(GTK_TREE_VIEW(eventlist->treeview), TRUE);
    gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(eventlist->treeview), TRUE);
    gtk_tree_view_set_enable_search(GTK_TREE_VIEW(eventlist->treeview), TRUE);

    renderer = gtk_cell_renderer_pixbuf_new ();
    column = gtk_tree_view_column_new_with_attributes ("S",
                                                    renderer,
                                                    "pixbuf", 2,
                                                    NULL);
    gtk_tree_view_column_set_min_width (column, 25);
    gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
    gtk_tree_view_column_set_resizable (column, FALSE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (eventlist->treeview), column);

    renderer = gtk_cell_renderer_text_new ();
    g_object_set(G_OBJECT(renderer), "scale-set", TRUE, "scale", 0.9, NULL);
    column = gtk_tree_view_column_new_with_attributes ("Datum",
                                                    renderer,
                                                    "text", 1,
                                                    NULL);
    gtk_tree_view_column_set_min_width (column, 100);
    gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
    gtk_tree_view_column_set_resizable (column, FALSE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (eventlist->treeview), column);

    renderer = gtk_cell_renderer_pixbuf_new ();
    column = gtk_tree_view_column_new_with_attributes ("Cat",
                                                    renderer,
                                                    "pixbuf", 3,
                                                    NULL);
    gtk_tree_view_column_set_min_width (column, 40);
    gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
    gtk_tree_view_column_set_resizable (column, FALSE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (eventlist->treeview), column);

    renderer = gtk_cell_renderer_progress_new ();
    column = gtk_tree_view_column_new_with_attributes ("Rating",
                                                    renderer,
                                                    "text", 11,
                                                    "value", 8,
                                                    NULL);
    gtk_tree_view_column_set_min_width (column, 50);
    gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
    gtk_tree_view_column_set_resizable (column, FALSE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (eventlist->treeview), column);

    renderer = gtk_cell_renderer_text_new ();
    g_object_set(G_OBJECT(renderer), "scale-set", TRUE, "scale", 0.9, "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
    column = gtk_tree_view_column_new_with_attributes ("Title",
                                                    renderer,
                                                    "text", 5,
                                                    NULL);
    gtk_tree_view_column_set_min_width (column, 100);
    gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
    gtk_tree_view_column_set_expand(column, TRUE);
    num = gtk_tree_view_append_column (GTK_TREE_VIEW (eventlist->treeview), column);
    gtk_tree_view_set_search_column(GTK_TREE_VIEW(eventlist->treeview), num);

    renderer = gtk_cell_renderer_pixbuf_new ();
    column = gtk_tree_view_column_new_with_attributes ("Link",
                                                    renderer,
                                                    "pixbuf", 9,
                                                    NULL);
    gtk_tree_view_column_set_min_width (column, 40);
    gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
    gtk_tree_view_column_set_resizable (column, FALSE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (eventlist->treeview), column);

    renderer = gtk_cell_renderer_text_new ();
    g_object_set(G_OBJECT(renderer), "scale-set", TRUE, "scale", 0.9, NULL);
    column = gtk_tree_view_column_new_with_attributes ("Poster",
                                                    renderer,
                                                    "text", 6,
                                                    NULL);
    gtk_tree_view_column_set_min_width (column, 100);
    gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
    gtk_tree_view_column_set_resizable (column, TRUE);
    gtk_tree_view_column_set_expand(column, FALSE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (eventlist->treeview), column);

    renderer = gtk_cell_renderer_toggle_new ();
    g_signal_connect (renderer, "toggled", G_CALLBACK (fixed_toggled), eventlist->store);
    column = gtk_tree_view_column_new_with_attributes ("WL",
                                                    renderer,
                                                    "active", 10,
                                                    NULL);
    gtk_tree_view_column_set_min_width (column, 25);
    gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
    gtk_tree_view_column_set_resizable (column, FALSE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (eventlist->treeview), column);
    gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(eventlist->treeview), TRUE);

    gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(eventlist->treeview), search_equal_func, NULL, NULL);

    gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(eventlist->widget), eventlist->treeview);

    gtk_widget_show(eventlist->treeview);
    gtk_widget_show(eventlist->widget);

    gtk_container_add (GTK_CONTAINER (gui->worksheet->center->widget), gui->worksheet->center->eventlist->widget);

    label = gtk_label_new ("FTD Postings");
    gtk_widget_show (label);
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (gui->worksheet->center->widget),
                                gtk_notebook_get_nth_page (
                                    GTK_NOTEBOOK (gui->worksheet->center->widget), -1), label);
    gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);

    g_signal_connect(G_OBJECT(eventlist->treeview), "row-activated", G_CALLBACK(ftd_gui_center_eventlist_row_activated), NULL);

    gtk_notebook_set_current_page (GTK_NOTEBOOK (gui->worksheet->center->widget), -1);
}

static gboolean
search_equal_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data)
{
    char *title = NULL;
    char *title_upcase;
    char *key_upcase;
    gboolean retval;

    gtk_tree_model_get (model, iter, 5, &title, -1);

    title_upcase = g_utf8_strup(title, -1);
    key_upcase = g_utf8_strup(key, -1);

    if (strstr(title_upcase, key_upcase)) {
        retval = FALSE; // Match gevonden
    } else {
        retval = TRUE;
    }

    g_free(title);
    g_free(title_upcase);
    g_free(key_upcase);

    return retval;
}

static void
fixed_toggled (GtkCellRendererToggle *cell,
               gchar                 *path_str,
               gpointer               data)
{
    GtkTreeModel *model = (GtkTreeModel *)data;
    GtkTreeIter  iter;
    GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
    gboolean fixed;
    int postId;
    int i;

    /* get toggled iter */
    gtk_tree_model_get_iter (model, &iter, path);
    gtk_tree_model_get (model, &iter, 0, &postId, 10, &fixed, -1);

    /* do something with the value */
    fixed ^= 1;

    /* set new value */
    gtk_list_store_set (GTK_LIST_STORE (model), &iter, 10, fixed, -1);

    // Verander ook de postinfo indien deze open stond
#if 1
    if (gui->worksheet->center->eventinfo) {
        int teller;
        char *path_tmp = NULL;
        FtdString *path_tmp2 = NULL;
        FtdString *path_tmp3 = NULL;
        FtdString *path_tmp4 = NULL;
        char *path = NULL;
        char buf[2048];

        // Pas het watchlist icoontje in een eventueel geopende postinfo aan
        path_tmp = ftd_file_parse_data_dir(NULL);
        path_tmp2 = ftd_string_new(path_tmp);
        path_tmp3 = ftd_string_replace(path_tmp2, " ", "%20");
        path_tmp4 = ftd_string_replace(path_tmp3, "\\", "/");
        path = ftd_string_value(path_tmp4);
        if (fixed == 1) {
            snprintf(buf, sizeof(buf), "file://%s/images/b4-3.bmp", path);
        } else {
            snprintf(buf, sizeof(buf), "file://%s/images/b4-1.bmp", path);
        }
        ftd_string_free(path_tmp4);
        ftd_string_free(path_tmp3);
        ftd_string_free(path_tmp2);
        g_free(path_tmp);

        for (teller = 0; teller < MAX_EVENT_INFO; teller++) {
            if (gui->worksheet->center->eventinfo[teller] && gui->worksheet->center->eventinfo[teller]->post_id == postId) {
                ftd_gui_browser_set_element_attribute( gui->worksheet->center->eventinfo[teller]->browser_data, "dlbut", "src", buf );
                break;
            }
        }
    }
#endif

    if (fixed) {
        ftd_watchlist_add(postId);
    } else {
        ftd_watchlist_remove(postId);
    }

    /* clean up */
    gtk_tree_path_free (path);
}

static gboolean
eventlist_show_func(gpointer key, gpointer value, gpointer data)
{
    GdkPixbuf *status_image = NULL;
    GdkPixbuf *cat_image = NULL;
    GdkPixbuf *link_image = NULL;
    FtdEvent *event = (FtdEvent *) value;
    GtkTreeIter iter;
    char *tmp;
    char *date;
    char *ratingText;
    int rating, max_rating;
    float factor;
    FtdString *title;

    switch(event->status) {
        case FTDSTATUS_DELETED:
        case FTDSTATUS_DELETED2:
            status_image = ftd_gui_main_get_pixbuf("deleted");
            break;
        case FTDSTATUS_SPOT:
            status_image = ftd_gui_main_get_pixbuf("spot");
            break;
        case FTDSTATUS_READY:
            status_image = ftd_gui_main_get_pixbuf("ready");
            break;
        case FTDSTATUS_ANNOUNCE:
            status_image = ftd_gui_main_get_pixbuf("announce");
            break;
        case FTDSTATUS_UPLOADING:
            status_image = ftd_gui_main_get_pixbuf("uploading");
            break;
        case FTDSTATUS_UNSUPPORTED:
            status_image = ftd_gui_main_get_pixbuf("unsupported");
            break;
        default:
            break;
    }

    if (event->link && ftd_string_length(event->link) > 0) {
        link_image = ftd_gui_main_get_pixbuf("link");
    }

    tmp = g_strdup_printf("ct%i%i", event->cat, event->sCat);
    cat_image = ftd_gui_main_get_pixbuf(tmp);
    g_free(tmp);

    date = ftd_string_date(event->stamp);
    ratingText = g_strdup_printf("%i", event->rating);

    //  500 is maximaal bij een ratingScale van  50
    // 1000 is maximaal bij een ratingScale van 100
    // 2000 is maximaal bij een ratingScale van 200
    max_rating = ftd_config_get()->ratingScale * 10;
    rating = (event->rating > max_rating) ? max_rating : event->rating;
    factor = (float) (100.0 / ftd_config_get()->ratingScale) / 10.0;
    rating = rating * factor;

    title = ftd_string_replace(event->title, "&amp;", "&");

    gtk_list_store_append(gui->worksheet->center->eventlist->store, &iter);
    gtk_list_store_set(gui->worksheet->center->eventlist->store, &iter, 0, event->postId,
                                                                        1, date,
                                                                        2, status_image,
                                                                        3, cat_image,
                                                                        4, event->sCat,
                                                                        5, ftd_string_value(title),
                                                                        6, ftd_string_value(event->poster),
                                                                        8, rating,
                                                                        9, link_image,
                                                                        10, ftd_watchlist_is_in_list(event->postId),
                                                                        11, ratingText,
                                                                        12, ftd_string_value(event->link),
                                                                        -1);

    ftd_string_free(title);
    g_free(ratingText);
    g_free(date);

    return FALSE;
}

gboolean
ftd_gui_center_eventlist_show(gpointer data)
{
    FTDEventlist *eventlist;
    int pagenum;

    pagenum = gtk_notebook_page_num(GTK_NOTEBOOK(gui->worksheet->center->widget), gui->worksheet->center->eventlist->widget);
    gtk_notebook_set_current_page(GTK_NOTEBOOK(gui->worksheet->center->widget), pagenum);

    gtk_list_store_clear(gui->worksheet->center->eventlist->store);

    eventlist = ftd_eventlist_get();
    ftd_eventlist_foreach(eventlist, TRUE, TRUE, eventlist_show_func, NULL);
    g_object_unref(eventlist);

    while (gtk_events_pending ())
        gtk_main_iteration ();

    g_idle_add(load_finished, NULL);

    return FALSE;
}

static gboolean
load_finished(gpointer niks)
{
    ftd_gui_center_eventlist_load_finished(NULL, NULL);
    return FALSE;
}

void
ftd_gui_center_eventlist_load_finished (GtkWidget *caller, gpointer data)
{
    g_assert (gui);

    ftd_gui_status_push();

    gtk_statusbar_push(GTK_STATUSBAR(gui->statusbar), 0, "Klaar...");
}

static void
ftd_gui_center_eventlist_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
{
    GtkTreeIter iter;
    int postId = -1;
    char *url;
    char *poster;

    g_assert(gui);

    if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(gui->worksheet->center->eventlist->store), &iter, path)) {
        g_print("ftd_gui_center_eventlist_row_activated(): gtk_tree_model_get_iter() mislukt\n");
        return;
    }

    gtk_tree_model_get(GTK_TREE_MODEL(gui->worksheet->center->eventlist->store), &iter, 0, &postId, 6, &poster, 12, &url, -1);

    // Als de gebruiker op de link heeft gedrukt en er is een link gekoppeld aan het FTD event, start
    // dan direct de externe webbrowser met de juiste url
    if (!strcmp(gtk_tree_view_column_get_title(column), "Link")) {
        if (url && strlen(url) > 0) {
            ftd_gui_center_launch_browser(url);
            g_free(url);
            return;
        }
    }

    if (!strcmp(gtk_tree_view_column_get_title(column), "Poster")) {
        // We moeten de gebruikersinfo tonen
        ftd_gui_profile_show(poster);
        g_free(poster);
        return;
    }

    if (url) {
        g_free(url);
    }

    g_free(poster);

    open_posting(postId);
}

static void
forum_fetch_cb(FtdErrorCode retval, int posting, time_t lastCheck, char *errmsg, gpointer data)
{
    FtdGuiCenterEventInfo *eventinfo = (FtdGuiCenterEventInfo *) data;

    if (retval != ERROR_NONE) {
        ftd_gui_errhandler(gui->window, FTD_ONDERDEEL_EVENTINFO_FORUM, retval, errmsg);
        ftd_gui_center_eventinfo_sluiten(eventinfo->cmdclose, NULL);
        return;
    }

    // Is het tabblad nog wel aanwezig?
    if (eventinfo->can_be_destroyed) {
        // Neen, geef eventinfo vrij en kap er maar gelijk mee
        FTDEventlist *eventlist = ftd_eventlist_get();
        ftd_eventlist_set_posting_is_active(eventlist, eventinfo->post_id, FALSE);
        g_object_unref(eventlist);

        g_free(eventinfo);
        return;
    }

#if 1
    retval = ftd_gui_center_eventinfo_process(posting);
    if (retval != ERROR_NONE) {
        ftd_gui_errhandler(gui->window, FTD_ONDERDEEL_EVENTINFO_FORUM, retval, NULL);
        ftd_gui_center_eventinfo_sluiten(eventinfo->cmdclose, NULL);
        return;
    }
#endif

    // Toon de gegevens op het scherm
    ftd_gui_center_eventinfo_show(eventinfo->widget, NULL);

    eventinfo->still_in_use = FALSE;
}

static void
open_posting_fase2(FtdErrorCode retval, int posting, char *errmsg, gpointer data)
{
    FtdGuiCenterEventInfo *eventinfo = (FtdGuiCenterEventInfo *) data;
    FtdEvent *event;
    FTDEventlist *eventlist;

    if (retval != ERROR_NONE) {
        FTDEventlist *eventlist = ftd_eventlist_get();

        ftd_gui_errhandler(gui->window, FTD_ONDERDEEL_EVENTINFO, retval, errmsg);
        ftd_gui_center_eventinfo_sluiten(eventinfo->cmdclose, NULL);

        ftd_eventlist_set_posting_is_active(eventlist, eventinfo->post_id, FALSE);
        g_object_unref(eventlist);

        return;
    }

    // Is het tabblad nog wel aanwezig?
    if (eventinfo->can_be_destroyed) {
        // Neen, geef eventinfo vrij en kap er maar gelijk mee
        g_free(eventinfo);
        return;
    }

    // Stel de titel van het tabblad goed in
    eventlist = ftd_eventlist_get();
    event = ftd_eventlist_lookup_id(eventlist, posting);
    g_object_unref(eventlist);

    if (event && event->title) {
        char bericht[64];
        FtdString *tmp;

        tmp = ftd_string_replace(event->title, "&amp;", "&");
        if (ftd_string_length(tmp) > 20) {
            char title[21];
            strncpy(title, ftd_string_value(tmp), 21); // Dit levert onder Win32 een truncate melding op, maar dat is ook de bedoeling in deze situatie
            title[20] = '\0';
            snprintf(bericht, sizeof(bericht), "%s...", title);
        } else {
            snprintf(bericht, sizeof(bericht), "%s", ftd_string_value(tmp));
        }

        ftd_event_free(event);
        event = NULL;

        gtk_label_set_text(GTK_LABEL(eventinfo->label), bericht);
    }

    // Haal alle bijbehorende forum reacties op
    ftd_events_forum_fetch_async(posting, (time_t) 0, forum_fetch_cb, data);
}

static void
open_posting(int posting)
{
    FtdErrorCode retval;
    char *errmsg;
    FtdGuiCenterEventInfo *eventinfo;

    // Open een tabblad voor de postinfo in te dumpen
    eventinfo = ftd_gui_center_eventinfo_new(posting);

    if (!eventinfo) {
        return;
    }

    eventinfo->still_in_use = TRUE;

    /* Haal de gegevens van het FTD event op. */
    ftd_eventinfo_fetch_async(posting, open_posting_fase2, eventinfo);
}

gboolean
ftd_gui_center_eventlist_open_uri (GtkWidget *embed, const char *uri, gpointer data)
{
    char *begin;

    begin = strstr(uri, "#post");
    if (begin) {
        open_posting(atoi(begin + 5));

        return TRUE;
    }

    return TRUE;
}

static gboolean
watchlist_foreach_func(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
    int postId;
    int requestedPostId = GPOINTER_TO_INT(data);
    gboolean value;

    gtk_tree_model_get(model, iter, 0, &postId, 10, &value, -1);

    if (postId == requestedPostId) {
        value ^= 1;

        gtk_list_store_set(gui->worksheet->center->eventlist->store, iter, 10, value, -1);
    }

    return FALSE;
}

void
ftd_gui_center_eventlist_toggle_watchlist (int postId)
{
    gtk_tree_model_foreach(GTK_TREE_MODEL(gui->worksheet->center->eventlist->store), watchlist_foreach_func, GINT_TO_POINTER(postId));
}
