diff --git a/src/freetuxtv-channels-list.c b/src/freetuxtv-channels-list.c index c90eca8..c1ba52d 100644 --- a/src/freetuxtv-channels-list.c +++ b/src/freetuxtv-channels-list.c @@ -133,12 +133,22 @@ static void channels_group_get_file (FreetuxTVApp *app, FreetuxTVChannelsGroupInfos *self, gchar **filename, gboolean update, GError** error); -static GtkTreePath* -get_favourites_channels_group_new(FreetuxTVApp *app, FreetuxTVChannelsGroupInfos **pChannelsGroupInfos); - static GList* get_favourites_channels_groups_paths(FreetuxTVApp *app); +static void +on_channels_group_favourites_added ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data); + +static void +channels_list_add_favourites(FreetuxTVApp* app, + FreetuxTVChannelsGroupInfos* pFavouritesChannelsGroupInfos, + GtkTreePath* pFavouritesChannelsGroupInfosPath, + DBSync* dbsync, GError** error); + /* static void channels_list_print(FreetuxTVApp *app); @@ -216,37 +226,48 @@ channels_list_load_channels (FreetuxTVApp *app, DBSync* dbsync, GError** error) } void -channels_list_add_channels_group (FreetuxTVApp *app, FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, - GtkTreePath** ppChannelsGroupTreePath, DBSync* dbsync, - GError** error) +channels_list_db_add_channels_group ( + FreetuxTVApp *app, DBSync* dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBOnChannelsGroupAddedFunc func_group_added, + DBOnChannelsAddedFunc func_channels_added, + gpointer user_data, + GError** error) { + g_return_if_fail(app != NULL); g_return_if_fail(dbsync != NULL); + g_return_if_fail(pChannelsGroupInfos != NULL); g_return_if_fail(error != NULL); + // Add the group in the database if(*error == NULL){ dbsync_add_channels_group (dbsync, pChannelsGroupInfos, error); } - // Add group in the treeview - if(*error == NULL){ - GtkTreeIter iter_channelsgroup; - gtk_tree_store_append (GTK_TREE_STORE(app->channelslist), &iter_channelsgroup, NULL); - gtk_tree_store_set (GTK_TREE_STORE(app->channelslist), &iter_channelsgroup, - CHANNELSGROUP_COLUMN, pChannelsGroupInfos, -1); - - GtkTreePath* path; - path = gtk_tree_model_get_path(app->channelslist, &iter_channelsgroup); + // Send signal that a group is added + if(*error == NULL){ + if(func_group_added){ + func_group_added(app, dbsync, pChannelsGroupInfos, user_data, error); + } + } - channels_list_refresh_channels_group(app, path, dbsync, error); + // Only playslist group have can have channel when added + if(pChannelsGroupInfos->type == FREETUXTV_CHANNELSGROUP_TYPEGROUP_PLAYLIST){ + // Refresh the list of channel for the group + if(*error == NULL){ + channels_list_db_refresh_channels_group(app, dbsync, pChannelsGroupInfos, error); + } - if(ppChannelsGroupTreePath){ - *ppChannelsGroupTreePath = path; - }else{ - gtk_tree_path_free(path); + // Send signal that channels of group are added + if(*error == NULL){ + if(func_channels_added){ + func_channels_added(app, dbsync, pChannelsGroupInfos, user_data, error); + } } } - if(*error == NULL){ + if(*error == NULL){ + // Update the channels list count windowmain_update_statusbar_infos (app); } } @@ -280,6 +301,126 @@ channels_list_update_channels_group (FreetuxTVApp *app, GtkTreePath *path_group, } } +void +channels_list_db_refresh_channels_group ( + FreetuxTVApp *app, DBSync* dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + GError** error) +{ + g_return_if_fail(app != NULL); + g_return_if_fail(dbsync != NULL); + g_return_if_fail(error != NULL); + + gchar *text; + + // Update status bar + text = g_strdup_printf(_("Update \"%s\" channels list"), pChannelsGroupInfos->name); + windowmain_statusbar_push (app, "UpdateMsg", text); + g_free(text); + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, + "Start updating \"%s\" channels list\n", pChannelsGroupInfos->name); + + if(pChannelsGroupInfos->type == FREETUXTV_CHANNELSGROUP_TYPEGROUP_PLAYLIST){ + // Get the file of the playlist + text = g_strdup_printf (_("Getting the file: \"%s\""), pChannelsGroupInfos->uri); + windowmain_statusbar_push (app, "UpdateMsg", text); + g_free(text); + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Getting the file \"%s\"\n", pChannelsGroupInfos->uri); + + gchar *filename = NULL; + channels_group_get_file (app, pChannelsGroupInfos, &filename, TRUE, error); + windowmain_statusbar_pop (app, "UpdateMsg"); + + // Delete channels of the channels group in the database + if(*error == NULL){ + dbsync_start_update_channels_of_channels_group (dbsync, pChannelsGroupInfos, error); + } + + // Parse the M3U file and add channels in the database + if(*error == NULL){ + Parsem3uData pdata; + pdata.channels_group_infos = pChannelsGroupInfos; + pdata.dbsync = dbsync; + pdata.app = app; + pdata.error = error; + int res = 0; + + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Parsing the file \"%s\"\n", filename); + res = libm3uparser_parse(filename, &on_parsem3u_add_channel, &pdata); + if (res != LIBM3UPARSER_OK){ + if (res != LIBM3UPARSER_CALLBACK_RETURN_ERROR){ + *error = g_error_new (FREETUXTV_LIBM3UPARSE_ERROR, + FREETUXTV_LIBM3UPARSE_ERROR_PARSE, + _("Error when adding the channels.\n\nM3UParser has returned error:\n%s."), + libm3uparser_errmsg(res)); + } + } + } + + if(*error == NULL){ + dbsync_end_update_channels_of_channels_group (dbsync, pChannelsGroupInfos, error); + } + + if(filename){ + g_free(filename); + } + } + + if(*error == NULL){ + // Update the last update date of the group + dbsync_update_channels_group_last_update (dbsync, + pChannelsGroupInfos, error); + } + + windowmain_statusbar_pop (app, "UpdateMsg"); +} + +void +channels_list_reload_channels_of_channels_group ( + FreetuxTVApp *app, DBSync* dbsync, + GtkTreePath *path_group, + GError** error) +{ + g_return_if_fail(dbsync != NULL); + g_return_if_fail(error != NULL); + + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos; + pChannelsGroupInfos = channels_list_get_group (app, path_group); + + g_return_if_fail(pChannelsGroupInfos != NULL); + g_return_if_fail(FREETUXTV_IS_CHANNELS_GROUP_INFOS(pChannelsGroupInfos)); + + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Reloading channel for the group \"%s\"\n", pChannelsGroupInfos->name); + + if(*error == NULL){ + // Delete channels of the channels group in the treeview + channels_list_delete_rows (app, path_group, TRUE); + + // Display the channels from the database + CBIterData iter_data; + GtkTreeIter iter_group; + GtkTreeIter iter_channel; + gtk_tree_model_get_iter (GTK_TREE_MODEL(app->channelslist), &iter_group, path_group); + + iter_data.iter = &iter_channel; + iter_data.iter_parent = &iter_group; + + dbsync_select_channels_of_channels_group (dbsync, pChannelsGroupInfos, app, on_dbsync_add_channel, &iter_data, error); + } + + // Expand the group + if(*error == NULL){ + GtkWidget *treeview; + treeview = (GtkWidget *)gtk_builder_get_object (app->gui, + "windowmain_treeviewchannelslist"); + gtk_tree_view_expand_row (GTK_TREE_VIEW(treeview), path_group, FALSE); + } +} + + void channels_list_refresh_channels_group (FreetuxTVApp *app, GtkTreePath *path_group, DBSync* dbsync, GError** error) @@ -571,6 +712,33 @@ channels_list_switch_channel (FreetuxTVApp *app, } +void +channels_list_ui_add_channels_group ( + FreetuxTVApp *app, FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + GtkTreePath** ppChannelsGroupTreePath) +{ + + g_return_if_fail(app != NULL); + g_return_if_fail(pChannelsGroupInfos != NULL); + g_return_if_fail(FREETUXTV_IS_CHANNELS_GROUP_INFOS(pChannelsGroupInfos)); + + // Add group in the treeview + GtkTreeIter iter_channelsgroup; + gtk_tree_store_append (GTK_TREE_STORE(app->channelslist), &iter_channelsgroup, NULL); + gtk_tree_store_set (GTK_TREE_STORE(app->channelslist), &iter_channelsgroup, + CHANNELSGROUP_COLUMN, pChannelsGroupInfos, -1); + + // Get the path of the new group + GtkTreePath* path; + path = gtk_tree_model_get_path(app->channelslist, &iter_channelsgroup); + + if(ppChannelsGroupTreePath){ + *ppChannelsGroupTreePath = path; + }else{ + gtk_tree_path_free(path); + } +} + gboolean channels_list_get_prev_channel (FreetuxTVApp *app, GtkTreePath **path_prev_channel) @@ -1744,89 +1912,44 @@ on_popupmenu_activated_channeladdfavourites (GtkMenuItem *menuitem, gpointer use GError* error = NULL; - GtkWidget* treeview; - GtkTreeModel* model_filter; - GtkTreeSelection *selection; - GList *list; - GList* iterator = NULL; - GtkTreePath *path; - GtkTreePath *real_path; - GtkTreeIter treeiter; - FreetuxTVChannelsGroupInfos* pFavouritesChannelsGroupInfos = NULL; GtkTreePath* pFavouritesChannelsGroupInfosPath = NULL; - - FreetuxTVChannelInfos* pOriginalChannelInfos = NULL; - FreetuxTVChannelInfos* pChannelInfos = NULL; DBSync dbsync; - dbsync_open_db (&dbsync, &error); - - treeview = (GtkWidget *) gtk_builder_get_object (app->gui, - "windowmain_treeviewchannelslist"); - model_filter = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)); - - // Get the selection - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - list = gtk_tree_selection_get_selected_rows (selection, &model_filter); - iterator = g_list_last (list); + GtkWidget* pParent; + pParent = (GtkWidget *) gtk_builder_get_object (app->gui, + "windowmain"); // Get the favourites group where add channels - if(iterator != NULL){ - pFavouritesChannelsGroupInfos = g_object_get_data (G_OBJECT(menuitem), "FavouritesChannelsGroup"); - pFavouritesChannelsGroupInfosPath = g_object_get_data (G_OBJECT(menuitem), "PathFavouritesChannelsGroup"); - - if(pFavouritesChannelsGroupInfos == NULL){ - pFavouritesChannelsGroupInfosPath = get_favourites_channels_group_new(app, &pFavouritesChannelsGroupInfos); - } - } + pFavouritesChannelsGroupInfos = g_object_get_data (G_OBJECT(menuitem), "FavouritesChannelsGroup"); + pFavouritesChannelsGroupInfosPath = g_object_get_data (G_OBJECT(menuitem), "PathFavouritesChannelsGroup"); if(pFavouritesChannelsGroupInfos != NULL){ - - while(iterator != NULL && error == NULL){ - - // Get the real path - path = (GtkTreePath*)iterator->data; - real_path = gtk_tree_model_filter_convert_path_to_child_path(GTK_TREE_MODEL_FILTER(model_filter), path); - - gtk_tree_model_get_iter (app->channelslist, &treeiter, real_path); - gtk_tree_model_get (app->channelslist, &treeiter, CHANNEL_COLUMN, &pOriginalChannelInfos, -1); + dbsync_open_db (&dbsync, &error); + channels_list_add_favourites(app, + pFavouritesChannelsGroupInfos, pFavouritesChannelsGroupInfosPath, + &dbsync, &error); + dbsync_close_db(&dbsync); + }else{ + // No favourites group, ask to add one + FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroups; - if(pOriginalChannelInfos){ - g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, - "Adding '%s' to favourites group '%s'\n", pOriginalChannelInfos->name, pFavouritesChannelsGroupInfos->name); + pWindowAddChannelsGroups = freetuxtv_window_add_channels_group_new (GTK_WINDOW(pParent), app); - // Copy the channel and add it in database - pChannelInfos = freetuxtv_channel_infos_new (pOriginalChannelInfos->name, pOriginalChannelInfos->url); - freetuxtv_channel_infos_set_position (pChannelInfos, pFavouritesChannelsGroupInfos->nb_channels+1); - freetuxtv_channel_infos_set_logo (pChannelInfos, pOriginalChannelInfos->logo_name); - freetuxtv_channel_infos_set_channels_group (pChannelInfos, pFavouritesChannelsGroupInfos); - freetuxtv_channel_infos_set_vlcoptions (pChannelInfos, pOriginalChannelInfos->vlc_options); + int allowedType; + allowedType = FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_ALLOW_FAVOURITES; + freetuxtv_window_add_channels_group_set_allowed_type (pWindowAddChannelsGroups, allowedType); - // Add the channels in the groups - dbsync_add_channel (&dbsync, pChannelInfos, FALSE, &error); + freetuxtv_window_add_channels_group_show (pWindowAddChannelsGroups); - if(error == NULL){ - pFavouritesChannelsGroupInfos->nb_channels++; + g_signal_connect(G_OBJECT(pWindowAddChannelsGroups), "channels-group-added", + G_CALLBACK(on_channels_group_favourites_added), NULL); - // Add the channel in the treeview as the last element - GtkTreeIter iterChannelsGroup; - GtkTreeIter iterChannel; - gtk_tree_model_get_iter (app->channelslist, &iterChannelsGroup, - pFavouritesChannelsGroupInfosPath); - - gtk_tree_store_append (GTK_TREE_STORE(app->channelslist), &iterChannel, &iterChannelsGroup); - gtk_tree_store_set (GTK_TREE_STORE(app->channelslist), &iterChannel, - CHANNEL_COLUMN, pChannelInfos, -1); - } - } - - iterator = g_list_previous(iterator); - } + g_object_unref(pWindowAddChannelsGroups); + pWindowAddChannelsGroups = NULL; } - dbsync_close_db(&dbsync); if(error != NULL){ windowmain_show_gerror (app, error); @@ -2055,42 +2178,6 @@ on_popupmenu_activated_channelproperties (GtkMenuItem *menuitem, gpointer user_d } } -static GtkTreePath* -get_favourites_channels_group_new(FreetuxTVApp *app, FreetuxTVChannelsGroupInfos **ppChannelsGroupInfos) -{ - GtkTreePath* pTreePath = NULL; - - // No favourites group, ask to add one - FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroups; - gint res; - - GtkWidget* pParent; - pParent = NULL; - // TODO : Get the parent - /*pParent = gtk_widget_get_toplevel (GTK_WIDGET(button)); - if (!gtk_widget_is_toplevel (pParent)) { - pParent = NULL; - }*/ - pWindowAddChannelsGroups = freetuxtv_window_add_channels_group_new (GTK_WINDOW(pParent), app); - - int allowedType; - allowedType = FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_ALLOW_FAVOURITES; - freetuxtv_window_add_channels_group_set_allowed_type (pWindowAddChannelsGroups, allowedType); - - res = freetuxtv_window_add_channels_group_run (pWindowAddChannelsGroups); - if(res == GTK_RESPONSE_OK){ - - } - - freetuxtv_window_add_channels_group_get_last_added (pWindowAddChannelsGroups, - ppChannelsGroupInfos, &pTreePath); - - g_object_unref(pWindowAddChannelsGroups); - pWindowAddChannelsGroups = NULL; - - return pTreePath; -} - static GList* get_favourites_channels_groups_paths(FreetuxTVApp *app) { @@ -2331,3 +2418,110 @@ channels_list_print(FreetuxTVApp *app) } } */ + +static void +on_channels_group_favourites_added ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data) +{ + g_return_if_fail(pWindowAddChannelsGroup != NULL); + g_return_if_fail(FREETUXTV_IS_WINDOW_ADD_CHANNELS_GROUP(pWindowAddChannelsGroup)); + g_return_if_fail(pChannelsGroupInfos != NULL); + g_return_if_fail(FREETUXTV_IS_CHANNELS_GROUP_INFOS(pChannelsGroupInfos)); + g_return_if_fail(dbsync != NULL); + g_return_if_fail(error != NULL); + g_return_if_fail(*error == NULL); + + g_print("channels_group_added\n"); + + FreetuxTVApp *app; + app = freetuxtv_window_add_channels_group_get_app (pWindowAddChannelsGroup); + + GtkTreePath* pTreePath = NULL; + + channels_list_ui_add_channels_group (app, pChannelsGroupInfos, &pTreePath); + + channels_list_add_favourites(app, pChannelsGroupInfos, pTreePath, dbsync, error); + + if(pTreePath){ + gtk_tree_path_free (pTreePath); + pTreePath = NULL; + } +} + +static void +channels_list_add_favourites(FreetuxTVApp* app, + FreetuxTVChannelsGroupInfos* pFavouritesChannelsGroupInfos, + GtkTreePath* pFavouritesChannelsGroupInfosPath, + DBSync* dbsync, GError** error) +{ + g_return_if_fail(app != NULL); + g_return_if_fail(dbsync != NULL); + g_return_if_fail(error != NULL); + g_return_if_fail(*error == NULL); + + GtkWidget* treeview; + GtkTreeModel* model_filter; + GtkTreeSelection *selection; + GList *list; + GList* iterator = NULL; + GtkTreePath *path; + GtkTreePath *real_path; + GtkTreeIter treeiter; + + FreetuxTVChannelInfos* pOriginalChannelInfos = NULL; + FreetuxTVChannelInfos* pChannelInfos = NULL; + + treeview = (GtkWidget *) gtk_builder_get_object (app->gui, + "windowmain_treeviewchannelslist"); + model_filter = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)); + + // Get the selection + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + list = gtk_tree_selection_get_selected_rows (selection, &model_filter); + + iterator = g_list_last (list); + + while(iterator != NULL && *error == NULL){ + + // Get the real path + path = (GtkTreePath*)iterator->data; + real_path = gtk_tree_model_filter_convert_path_to_child_path(GTK_TREE_MODEL_FILTER(model_filter), path); + + gtk_tree_model_get_iter (app->channelslist, &treeiter, real_path); + gtk_tree_model_get (app->channelslist, &treeiter, CHANNEL_COLUMN, &pOriginalChannelInfos, -1); + + if(pOriginalChannelInfos){ + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, + "Adding '%s' to favourites group '%s'\n", pOriginalChannelInfos->name, pFavouritesChannelsGroupInfos->name); + + // Copy the channel and add it in database + pChannelInfos = freetuxtv_channel_infos_new (pOriginalChannelInfos->name, pOriginalChannelInfos->url); + freetuxtv_channel_infos_set_position (pChannelInfos, pFavouritesChannelsGroupInfos->nb_channels+1); + freetuxtv_channel_infos_set_logo (pChannelInfos, pOriginalChannelInfos->logo_name); + freetuxtv_channel_infos_set_channels_group (pChannelInfos, pFavouritesChannelsGroupInfos); + freetuxtv_channel_infos_set_vlcoptions (pChannelInfos, pOriginalChannelInfos->vlc_options); + + // Add the channels in the groups + dbsync_add_channel (dbsync, pChannelInfos, FALSE, error); + + if(*error == NULL){ + pFavouritesChannelsGroupInfos->nb_channels++; + + // Add the channel in the treeview as the last element + GtkTreeIter iterChannelsGroup; + GtkTreeIter iterChannel; + gtk_tree_model_get_iter (app->channelslist, &iterChannelsGroup, + pFavouritesChannelsGroupInfosPath); + + gtk_tree_store_append (GTK_TREE_STORE(app->channelslist), &iterChannel, &iterChannelsGroup); + gtk_tree_store_set (GTK_TREE_STORE(app->channelslist), &iterChannel, + CHANNEL_COLUMN, pChannelInfos, -1); + } + } + + iterator = g_list_previous(iterator); + } +} diff --git a/src/freetuxtv-channels-list.h b/src/freetuxtv-channels-list.h index 71e5ebc..9f92d98 100644 --- a/src/freetuxtv-channels-list.h +++ b/src/freetuxtv-channels-list.h @@ -35,6 +35,18 @@ typedef enum GQuark freetuxtv_libm3uparse_error_quark (); +// Callback function +typedef void (*DBOnChannelsGroupAddedFunc) ( + FreetuxTVApp *app, DBSync *dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + gpointer user_data, GError** error); + +typedef void (*DBOnChannelsAddedFunc) ( + FreetuxTVApp *app, DBSync *dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + gpointer user_data, GError** error); + + void channels_list_init (FreetuxTVApp *app); @@ -42,13 +54,32 @@ void channels_list_load_channels (FreetuxTVApp *app, DBSync* dbsync, GError** error); void -channels_list_add_channels_group (FreetuxTVApp *app, FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, - GtkTreePath** ppChannelsGroupTreePath, DBSync* dbsync, GError** error); +channels_list_db_add_channels_group ( + FreetuxTVApp *app, DBSync* dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBOnChannelsGroupAddedFunc funcGroupAdded, + DBOnChannelsAddedFunc funcChannelsAdded, + gpointer user_data, + GError** error + ); void channels_list_update_channels_group (FreetuxTVApp *app, GtkTreePath *path_group, FreetuxTVChannelsGroupInfos* channels_group_infos); +void +channels_list_db_refresh_channels_group ( + FreetuxTVApp *app, DBSync* dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + GError** error + ); + +void +channels_list_reload_channels_of_channels_group ( + FreetuxTVApp *app, DBSync* dbsync, + GtkTreePath *path_group, + GError** error); + void channels_list_refresh_channels_group (FreetuxTVApp *app, GtkTreePath *path_group, DBSync* dbsync, GError** error); @@ -71,6 +102,12 @@ channels_list_switch_channel (FreetuxTVApp *app, GtkTreePath *pPathChannelSrc, GtkTreePath *pPathChannelDest, DBSync* dbsync, GError** error); +void +channels_list_ui_add_channels_group ( + FreetuxTVApp *app, FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + GtkTreePath** ppChannelsGroupTreePath + ); + gboolean channels_list_get_prev_channel (FreetuxTVApp *app, GtkTreePath **path_prev_channel); diff --git a/src/freetuxtv-window-add-channels-group.c b/src/freetuxtv-window-add-channels-group.c index 9f4ffbc..e938e43 100644 --- a/src/freetuxtv-window-add-channels-group.c +++ b/src/freetuxtv-window-add-channels-group.c @@ -35,18 +35,20 @@ struct _FreetuxTVWindowAddChannelsGroupPrivate int allowedType; - FreetuxTVChannelsGroupInfos* pLastAddedChannelsGroupInfos; - GtkTreePath* pLastAddedChannelsGroupPath; - GtkTreeModel* pModel; }; #define FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FREETUXTV_TYPE_WINDOW_ADD_CHANNELS_GROUP, FreetuxTVWindowAddChannelsGroupPrivate)) - - G_DEFINE_TYPE (FreetuxTVWindowAddChannelsGroup, freetuxtv_window_add_channels_group, G_TYPE_OBJECT); +enum { + SIGNAL_CHANNELS_GROUP_ADDED, + SIGNAL_CHANNELS_ADDED, + NB_SIGNALS +}; + +static guint g_signals [NB_SIGNALS] = { 0, 0 }; static gboolean dialog_init (FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, GtkWindow *parent); @@ -66,6 +68,18 @@ on_dialog_close (GtkWidget *widget, GdkEvent *event, gpointer user_data); static void gtk_notebook_set_page_visible(GtkNotebook* notebook, int page_num, gboolean visible); +static void +db_on_group_added ( + FreetuxTVApp *app, DBSync *dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + gpointer user_data, GError** error); + +static void +db_on_channels_added ( + FreetuxTVApp *app, DBSync *dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + gpointer user_data, GError** error); + static void freetuxtv_window_add_channels_group_init (FreetuxTVWindowAddChannelsGroup *object) { @@ -76,9 +90,6 @@ freetuxtv_window_add_channels_group_init (FreetuxTVWindowAddChannelsGroup *objec priv->pBuilder = NULL; priv->allowedType = FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_ALLOW_ALL; - - priv->pLastAddedChannelsGroupInfos = NULL; - priv->pLastAddedChannelsGroupPath = NULL; } static void @@ -98,6 +109,89 @@ freetuxtv_window_add_channels_group_finalize (GObject *object) } } +#ifdef G_ENABLE_DEBUG +#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v) +#define g_marshal_value_peek_char(v) g_value_get_char (v) +#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v) +#define g_marshal_value_peek_int(v) g_value_get_int (v) +#define g_marshal_value_peek_uint(v) g_value_get_uint (v) +#define g_marshal_value_peek_long(v) g_value_get_long (v) +#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v) +#define g_marshal_value_peek_int64(v) g_value_get_int64 (v) +#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v) +#define g_marshal_value_peek_enum(v) g_value_get_enum (v) +#define g_marshal_value_peek_flags(v) g_value_get_flags (v) +#define g_marshal_value_peek_float(v) g_value_get_float (v) +#define g_marshal_value_peek_double(v) g_value_get_double (v) +#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v) +#define g_marshal_value_peek_param(v) g_value_get_param (v) +#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v) +#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v) +#define g_marshal_value_peek_object(v) g_value_get_object (v) +#else /* !G_ENABLE_DEBUG */ +/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API. + * Do not access GValues directly in your code. Instead, use the + * g_value_get_*() functions + */ +#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int +#define g_marshal_value_peek_char(v) (v)->data[0].v_int +#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint +#define g_marshal_value_peek_int(v) (v)->data[0].v_int +#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint +#define g_marshal_value_peek_long(v) (v)->data[0].v_long +#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong +#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64 +#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64 +#define g_marshal_value_peek_enum(v) (v)->data[0].v_long +#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong +#define g_marshal_value_peek_float(v) (v)->data[0].v_float +#define g_marshal_value_peek_double(v) (v)->data[0].v_double +#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer +#endif /* !G_ENABLE_DEBUG */ + +void +g_cclosure_marshal_VOID__OBJECT_POINTER_POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef void (*GMarshalFunc_VOID__OBJECT_POINTER_POINTER) (gpointer data1, + gpointer arg_1, + gpointer arg_2, + gpointer arg_3, + gpointer data2); + register GMarshalFunc_VOID__OBJECT_POINTER_POINTER callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + + g_return_if_fail (n_param_values == 4); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__OBJECT_POINTER_POINTER) (marshal_data ? marshal_data : cc->callback); + + callback (data1, + g_marshal_value_peek_object (param_values + 1), + g_marshal_value_peek_pointer (param_values + 2), + g_marshal_value_peek_pointer (param_values + 3), + data2); +} + + static void freetuxtv_window_add_channels_group_class_init (FreetuxTVWindowAddChannelsGroupClass *klass) { @@ -106,6 +200,34 @@ freetuxtv_window_add_channels_group_class_init (FreetuxTVWindowAddChannelsGroupC g_type_class_add_private (klass, sizeof (FreetuxTVWindowAddChannelsGroupPrivate)); object_class->finalize = freetuxtv_window_add_channels_group_finalize; + + g_signals [SIGNAL_CHANNELS_GROUP_ADDED] = g_signal_new ( + "channels-group-added", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (FreetuxTVWindowAddChannelsGroupClass, channels_group_added), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT_POINTER_POINTER, + G_TYPE_NONE, + 3, + FREETUXTV_TYPE_CHANNELS_GROUP_INFOS, + G_TYPE_POINTER, + G_TYPE_POINTER + ); + + g_signals [SIGNAL_CHANNELS_ADDED] = g_signal_new ( + "channels-added", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (FreetuxTVWindowAddChannelsGroupClass, channels_added), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT_POINTER_POINTER, + G_TYPE_NONE, + 3, + FREETUXTV_TYPE_CHANNELS_GROUP_INFOS, + G_TYPE_POINTER, + G_TYPE_POINTER + ); } FreetuxTVWindowAddChannelsGroup* @@ -154,12 +276,15 @@ freetuxtv_window_add_channels_group_set_allowed_type ( priv->allowedType = allowedType; } -gint -freetuxtv_window_add_channels_group_run ( +void +freetuxtv_window_add_channels_group_show ( FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup) { - g_return_val_if_fail(pWindowAddChannelsGroup != NULL, GTK_RESPONSE_NONE); - g_return_val_if_fail(FREETUXTV_IS_WINDOW_ADD_CHANNELS_GROUP(pWindowAddChannelsGroup), GTK_RESPONSE_NONE); + g_return_if_fail(pWindowAddChannelsGroup != NULL); + g_return_if_fail(FREETUXTV_IS_WINDOW_ADD_CHANNELS_GROUP(pWindowAddChannelsGroup)); + + // TODO : Destroy it + g_object_ref(pWindowAddChannelsGroup); FreetuxTVWindowAddChannelsGroupPrivate* priv; priv = FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_PRIVATE(pWindowAddChannelsGroup); @@ -167,8 +292,6 @@ freetuxtv_window_add_channels_group_run ( GtkBuilder *builder; builder = priv->pBuilder; - gint res; - GtkDialog *dialog; dialog = (GtkDialog*) gtk_builder_get_object (builder, "dialogaddgroup"); @@ -195,38 +318,7 @@ freetuxtv_window_add_channels_group_run ( } // Display the dialog - res = gtk_dialog_run(dialog); - - return res; -} - -gboolean -freetuxtv_window_add_channels_group_get_last_added( - FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup, - FreetuxTVChannelsGroupInfos** ppChannelsGroupInfos, - GtkTreePath** ppTreePath - ) -{ - g_return_val_if_fail(pWindowAddChannelsGroup != NULL, GTK_RESPONSE_NONE); - g_return_val_if_fail(FREETUXTV_IS_WINDOW_ADD_CHANNELS_GROUP(pWindowAddChannelsGroup), GTK_RESPONSE_NONE); - - FreetuxTVWindowAddChannelsGroupPrivate* priv; - priv = FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_PRIVATE(pWindowAddChannelsGroup); - - gboolean res = FALSE; - - res = priv->pLastAddedChannelsGroupInfos != NULL - && priv->pLastAddedChannelsGroupPath != NULL; - - if(ppChannelsGroupInfos){ - *ppChannelsGroupInfos = priv->pLastAddedChannelsGroupInfos; - } - - if(ppTreePath){ - *ppTreePath = priv->pLastAddedChannelsGroupPath; - } - - return res; + gtk_widget_show(GTK_WIDGET(dialog)); } static gboolean @@ -237,16 +329,12 @@ dialog_init (FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, GtkWindow FreetuxTVWindowAddChannelsGroupPrivate* priv; priv = FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_PRIVATE(pWindowAddChannelsGroup); - FreetuxTVWindowAddChannelsGroupClass* klass; - GtkDialog *dialog; GtkWidget *widget; GtkBuilder *builder; builder = priv->pBuilder; - klass = FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_GET_CLASS(pWindowAddChannelsGroup); - dialog = (GtkDialog*) gtk_builder_get_object (builder, "dialogaddgroup"); // Set the parent @@ -393,8 +481,6 @@ on_buttonadd_clicked (GtkButton *button, gpointer user_data) gboolean has_process = FALSE; gchar *tmptext; - - GtkTreePath* pTreePathTmp; DBSync dbsync; dbsync_open_db (&dbsync, &error); @@ -410,7 +496,7 @@ on_buttonadd_clicked (GtkButton *button, gpointer user_data) page = gtk_notebook_get_current_page (GTK_NOTEBOOK(widget)); switch(page){ case 0: - // Add one or many groups in the list + // Add one or many groups from the list of existing group widget = (GtkWidget *)gtk_builder_get_object (builder, "dialogaddgroup_treeviewchannelsgroups"); GtkTreeSelection *selection; @@ -427,7 +513,6 @@ on_buttonadd_clicked (GtkButton *button, gpointer user_data) int nb_added = 0; count = gtk_tree_selection_count_selected_rows(selection); - GList* iterator = NULL; iterator = g_list_first (list); @@ -485,7 +570,12 @@ on_buttonadd_clicked (GtkButton *button, gpointer user_data) gtk_progress_dialog_set_text(pProgressDialog, tmptext); g_free(tmptext); - channels_list_add_channels_group (app, pChannelsGroupInfos, NULL, &dbsync, &error); + // Add the group in the database + if(error == NULL){ + channels_list_db_add_channels_group (app, &dbsync, pChannelsGroupInfos, + db_on_group_added, db_on_channels_added, pWindowAddChannelsGroup, &error); + } + if(error == NULL){ nb_added++; } @@ -523,8 +613,13 @@ on_buttonadd_clicked (GtkButton *button, gpointer user_data) pChannelsGroupInfos->name); gtk_progress_dialog_set_text(pProgressDialog, tmptext); g_free(tmptext); + + // Add the group in the database + if(error == NULL){ + channels_list_db_add_channels_group (app, &dbsync, pChannelsGroupInfos, + db_on_group_added, db_on_channels_added, pWindowAddChannelsGroup, &error); + } - channels_list_add_channels_group (app, pChannelsGroupInfos, NULL, &dbsync, &error); if(error == NULL){ nb_added++; } @@ -600,13 +695,19 @@ on_buttonadd_clicked (GtkButton *button, gpointer user_data) gtk_progress_dialog_set_percent(pProgressDialog, 0.0); g_free(tmptext); - channels_list_add_channels_group (app, pChannelsGroupInfos, NULL, &dbsync, &error); + // Add the group in the database + if(error == NULL){ + channels_list_db_add_channels_group (app, &dbsync, pChannelsGroupInfos, + db_on_group_added, db_on_channels_added, pWindowAddChannelsGroup, &error); + } - tmptext = g_strdup_printf(_("%d channels group(s) have been successfully added."), 1); - gtk_progress_dialog_set_text(pProgressDialog, tmptext); - gtk_progress_dialog_set_percent(pProgressDialog, 1.0); + if(error == NULL){ + tmptext = g_strdup_printf(_("%d channels group(s) have been successfully added."), 1); + gtk_progress_dialog_set_text(pProgressDialog, tmptext); + gtk_progress_dialog_set_percent(pProgressDialog, 1.0); - g_free(tmptext); + g_free(tmptext); + } } break; @@ -637,18 +738,19 @@ on_buttonadd_clicked (GtkButton *button, gpointer user_data) gtk_progress_dialog_set_percent(pProgressDialog, 0.0); g_free(tmptext); - channels_list_add_channels_group (app, pChannelsGroupInfos, &pTreePathTmp, &dbsync, &error); - priv->pLastAddedChannelsGroupInfos = pChannelsGroupInfos; - if(priv->pLastAddedChannelsGroupPath){ - gtk_tree_path_free(priv->pLastAddedChannelsGroupPath); + // Add the group in the database + if(error == NULL){ + channels_list_db_add_channels_group (app, &dbsync, pChannelsGroupInfos, + db_on_group_added, db_on_channels_added, pWindowAddChannelsGroup, &error); } - priv->pLastAddedChannelsGroupPath = pTreePathTmp; - tmptext = g_strdup_printf(_("%d channels group(s) have been successfully added."), 1); - gtk_progress_dialog_set_text(pProgressDialog, tmptext); - gtk_progress_dialog_set_percent(pProgressDialog, 1.0); + if(error == NULL){ + tmptext = g_strdup_printf(_("%d channels group(s) have been successfully added."), 1); + gtk_progress_dialog_set_text(pProgressDialog, tmptext); + gtk_progress_dialog_set_percent(pProgressDialog, 1.0); - g_free(tmptext); + g_free(tmptext); + } } break; } @@ -670,7 +772,6 @@ on_buttonadd_clicked (GtkButton *button, gpointer user_data) } } - static void on_dialog_response (GtkDialog *dialog, gint response_id, gpointer user_data) { @@ -685,3 +786,69 @@ on_dialog_close (GtkWidget *widget, GdkEvent *event, gpointer user_data) return gtk_widget_hide_on_delete(widget); } + +static void +db_on_group_added ( + FreetuxTVApp *app, DBSync *dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + gpointer user_data, GError** error) +{ + g_return_if_fail(app != NULL); + g_return_if_fail(dbsync != NULL); + g_return_if_fail(pChannelsGroupInfos != NULL); + g_return_if_fail(error != NULL); + g_return_if_fail(*error == NULL); + + FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup; + pWindowAddChannelsGroup = (FreetuxTVWindowAddChannelsGroup*)user_data; + + g_return_if_fail(pWindowAddChannelsGroup != NULL); + g_return_if_fail(FREETUXTV_IS_WINDOW_ADD_CHANNELS_GROUP(pWindowAddChannelsGroup)); + + // Send signal that a group is added + if(*error == NULL){ + g_signal_emit ( + G_OBJECT (pWindowAddChannelsGroup), + g_signals [SIGNAL_CHANNELS_GROUP_ADDED], + 0, pChannelsGroupInfos, dbsync, error + ); + } +} +static void +db_on_channels_added ( + FreetuxTVApp *app, DBSync *dbsync, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + gpointer user_data, GError** error) +{ + g_return_if_fail(app != NULL); + g_return_if_fail(dbsync != NULL); + g_return_if_fail(pChannelsGroupInfos != NULL); + g_return_if_fail(error != NULL); + + FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup; + pWindowAddChannelsGroup = (FreetuxTVWindowAddChannelsGroup*)user_data; + + g_return_if_fail(pWindowAddChannelsGroup != NULL); + g_return_if_fail(FREETUXTV_IS_WINDOW_ADD_CHANNELS_GROUP(pWindowAddChannelsGroup)); + + // Send signal that a group is added + if(*error == NULL){ + g_signal_emit ( + G_OBJECT (pWindowAddChannelsGroup), + g_signals [SIGNAL_CHANNELS_ADDED], + 0, pChannelsGroupInfos, dbsync, error + ); + } +} + +FreetuxTVApp* +freetuxtv_window_add_channels_group_get_app(FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup) +{ + g_return_val_if_fail(pWindowAddChannelsGroup != NULL, NULL); + g_return_val_if_fail(FREETUXTV_IS_WINDOW_ADD_CHANNELS_GROUP(pWindowAddChannelsGroup), NULL); + + FreetuxTVWindowAddChannelsGroupPrivate* priv; + priv = FREETUXTV_WINDOW_ADD_CHANNELS_GROUP_PRIVATE(pWindowAddChannelsGroup); + + return priv->app; +} diff --git a/src/freetuxtv-window-add-channels-group.h b/src/freetuxtv-window-add-channels-group.h index 61e3cba..5fe6924 100644 --- a/src/freetuxtv-window-add-channels-group.h +++ b/src/freetuxtv-window-add-channels-group.h @@ -27,6 +27,8 @@ #include "freetuxtv-app.h" #include "gtk-progress-dialog.h" +#include "freetuxtv-db-sync.h" + G_BEGIN_DECLS #define FREETUXTV_TYPE_WINDOW_ADD_CHANNELS_GROUP (freetuxtv_window_add_channels_group_get_type ()) @@ -42,6 +44,18 @@ typedef struct _FreetuxTVWindowAddChannelsGroup FreetuxTVWindowAddChannelsGroup; struct _FreetuxTVWindowAddChannelsGroupClass { GObjectClass parent_class; + + void (*channels_group_added) ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data); + + void (*channels_added) ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data); }; struct _FreetuxTVWindowAddChannelsGroup @@ -70,16 +84,12 @@ freetuxtv_window_add_channels_group_set_allowed_type ( FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup, int allowedType); -gint -freetuxtv_window_add_channels_group_run ( +void +freetuxtv_window_add_channels_group_show ( FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup); - -gboolean -freetuxtv_window_add_channels_group_get_last_added( - FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup, - FreetuxTVChannelsGroupInfos** ppChannelsGroupInfos, - GtkTreePath** ppTreePath - ); + +FreetuxTVApp* +freetuxtv_window_add_channels_group_get_app(FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroup); G_END_DECLS diff --git a/src/freetuxtv-window-main.c b/src/freetuxtv-window-main.c index fe2e71d..c3b598e 100644 --- a/src/freetuxtv-window-main.c +++ b/src/freetuxtv-window-main.c @@ -228,7 +228,14 @@ on_accel_volumeup (GtkAccelGroup *accel_group, GObject *acceleratable, guint key static gboolean on_accel_volumedown (GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer user_data); + GdkModifierType modifier, gpointer user_data); + +static void +on_channels_group_added ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data); void windowmain_init(FreetuxTVApp *app) @@ -1460,6 +1467,49 @@ on_windowmain_menuitempreferences_activate (GtkMenuItem *menuitem, } +static void +on_channels_group_added ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data) +{ + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Received signal for channels group added '%s'\n", pChannelsGroupInfos->name); + + FreetuxTVApp *app; + app = freetuxtv_window_add_channels_group_get_app(pWindowAddChannelsGroup); + + GtkTreePath** ppTreePath = (GtkTreePath**)user_data; + + if(ppTreePath){ + gtk_tree_path_free (*ppTreePath); + *ppTreePath = NULL; + } + + channels_list_ui_add_channels_group (app, pChannelsGroupInfos, ppTreePath); +} + +static void +on_channels_added ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data) +{ + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Received signal for channels added in group '%s'\n", pChannelsGroupInfos->name); + + FreetuxTVApp *app; + app = freetuxtv_window_add_channels_group_get_app(pWindowAddChannelsGroup); + + GtkTreePath** ppTreePath = (GtkTreePath**)user_data; + + if(ppTreePath){ + channels_list_reload_channels_of_channels_group (app, dbsync, *ppTreePath, error); + } +} + static void on_windowmain_menuitemgroupsadd_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -1467,7 +1517,6 @@ on_windowmain_menuitemgroupsadd_activate (GtkMenuItem *menuitem, FreetuxTVApp *app = (FreetuxTVApp *) user_data; FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroups; - gint res; GtkWidget* pParent; pParent = gtk_widget_get_toplevel (GTK_WIDGET(menuitem)); @@ -1475,11 +1524,15 @@ on_windowmain_menuitemgroupsadd_activate (GtkMenuItem *menuitem, pParent = NULL; } pWindowAddChannelsGroups = freetuxtv_window_add_channels_group_new (GTK_WINDOW(pParent), app); - res = freetuxtv_window_add_channels_group_run (pWindowAddChannelsGroups); - if(res == GTK_RESPONSE_OK){ - - } + freetuxtv_window_add_channels_group_show (pWindowAddChannelsGroups); + + GtkTreePath* pCurrentTreePath = NULL; + g_signal_connect(G_OBJECT(pWindowAddChannelsGroups), "channels-group-added", + G_CALLBACK(on_channels_group_added), &pCurrentTreePath); + g_signal_connect(G_OBJECT(pWindowAddChannelsGroups), "channels-added", + G_CALLBACK(on_channels_added), &pCurrentTreePath); + g_object_unref(pWindowAddChannelsGroups); pWindowAddChannelsGroups = NULL; } diff --git a/src/gtk-progress-dialog.c b/src/gtk-progress-dialog.c index 22ee4d1..49233fd 100644 --- a/src/gtk-progress-dialog.c +++ b/src/gtk-progress-dialog.c @@ -33,8 +33,6 @@ struct _GtkProgressDialogPrivate #define GTK_PROGRESS_DIALOG_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PROGRESS_DIALOG, GtkProgressDialogPrivate)) - - G_DEFINE_TYPE (GtkProgressDialog, gtk_progress_dialog, GTK_TYPE_DIALOG); static void @@ -121,7 +119,11 @@ gtk_progress_dialog_new(GtkWindow* parent) g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(gtk_widget_hide_on_delete), NULL); g_signal_connect(G_OBJECT(dialog), "delete-event", - G_CALLBACK(gtk_widget_hide_on_delete), NULL); + G_CALLBACK(gtk_widget_hide_on_delete), NULL); + + while (gtk_events_pending()) { + gtk_main_iteration(); + } return dialog; } @@ -142,6 +144,10 @@ gtk_progress_dialog_set_title(GtkProgressDialog* dialog, gchar *title) text = g_strdup_printf("%s", title); gtk_label_set_markup(GTK_LABEL(priv->title_widget), text); g_free(text); + + while (gtk_events_pending()) { + gtk_main_iteration(); + } } void @@ -154,6 +160,10 @@ gtk_progress_dialog_set_text(GtkProgressDialog* dialog, gchar *text) priv = GTK_PROGRESS_DIALOG_PRIVATE(dialog); gtk_label_set_markup(GTK_LABEL(priv->text_widget), text); + + while (gtk_events_pending()) { + gtk_main_iteration(); + } } void @@ -172,4 +182,8 @@ gtk_progress_dialog_set_percent(GtkProgressDialog* dialog, gdouble percent) text = g_strdup_printf("%0.0f %%", percent * 100); gtk_progress_bar_set_text (GTK_PROGRESS_BAR(priv->progress_widget), text); g_free(text); + + while (gtk_events_pending()) { + gtk_main_iteration(); + } } diff --git a/src/main.c b/src/main.c index fde1b87..a007797 100644 --- a/src/main.c +++ b/src/main.c @@ -486,6 +486,48 @@ splashscreen_statusbar_pop (FreetuxTVApp *app) gtk_statusbar_pop (GTK_STATUSBAR(statusbar), context_id); } +static void +on_channels_group_added ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data) +{ + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Received signal for channels group added '%s'\n", pChannelsGroupInfos->name); + + FreetuxTVApp *app; + app = freetuxtv_window_add_channels_group_get_app(pWindowAddChannelsGroup); + + GtkTreePath** ppTreePath = (GtkTreePath**)user_data; + + if(ppTreePath){ + gtk_tree_path_free (*ppTreePath); + *ppTreePath = NULL; + } + + channels_list_ui_add_channels_group (app, pChannelsGroupInfos, ppTreePath); +} + +static void +on_channels_added ( + FreetuxTVWindowAddChannelsGroup *pWindowAddChannelsGroup, + FreetuxTVChannelsGroupInfos* pChannelsGroupInfos, + DBSync *dbsync, GError** error, + gpointer user_data) +{ + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Received signal for channels added in group '%s'\n", pChannelsGroupInfos->name); + + FreetuxTVApp *app; + app = freetuxtv_window_add_channels_group_get_app(pWindowAddChannelsGroup); + + GtkTreePath** ppTreePath = (GtkTreePath**)user_data; + + if(ppTreePath){ + channels_list_reload_channels_of_channels_group (app, dbsync, *ppTreePath, error); + } +} static gboolean splashscreen_app_init(gpointer data) @@ -661,13 +703,16 @@ splashscreen_app_init(gpointer data) nb_channelsgroup = gtk_tree_model_iter_n_children (app->channelslist, NULL); if(nb_channelsgroup == 0){ FreetuxTVWindowAddChannelsGroup* pWindowAddChannelsGroups; - gint res; pWindowAddChannelsGroups = freetuxtv_window_add_channels_group_new (GTK_WINDOW(pMainWindow), app); - res = freetuxtv_window_add_channels_group_run (pWindowAddChannelsGroups); - if(res == GTK_RESPONSE_OK){ + freetuxtv_window_add_channels_group_show (pWindowAddChannelsGroups); - } + GtkTreePath* pCurrentTreePath = NULL; + + g_signal_connect(G_OBJECT(pWindowAddChannelsGroups), "channels-group-added", + G_CALLBACK(on_channels_group_added), &pCurrentTreePath); + g_signal_connect(G_OBJECT(pWindowAddChannelsGroups), "channels-added", + G_CALLBACK(on_channels_added), &pCurrentTreePath); g_object_unref(pWindowAddChannelsGroups); pWindowAddChannelsGroups = NULL;