From 0b1dcc821d1501cd983a4d4f4076c1105c37cee1 Mon Sep 17 00:00:00 2001 From: "eric.beuque" Date: Sun, 18 Nov 2012 19:11:20 +0000 Subject: [PATCH] [FreetuxTV] Download TV channel file. --- data/ui/tvchannelsdatabase.glade | 6 +-- src/freetuxtv-fileutils.c | 2 +- src/freetuxtv-fileutils.h | 2 +- src/freetuxtv-tv-channels-list.c | 20 +++++-- src/freetuxtv-window-tv-channels-database.c | 60 +++++++++++++++++---- 5 files changed, 70 insertions(+), 20 deletions(-) diff --git a/data/ui/tvchannelsdatabase.glade b/data/ui/tvchannelsdatabase.glade index c78dcaa..b2359f5 100644 --- a/data/ui/tvchannelsdatabase.glade +++ b/data/ui/tvchannelsdatabase.glade @@ -107,11 +107,10 @@ True False - + Update database from file: False True - False True False False @@ -125,9 +124,8 @@ - + True - False True http://freetuxtv.googlecode.com/svn/trunk/data/tv_channels.xml diff --git a/src/freetuxtv-fileutils.c b/src/freetuxtv-fileutils.c index 200e9da..0ebb45a 100644 --- a/src/freetuxtv-fileutils.c +++ b/src/freetuxtv-fileutils.c @@ -35,7 +35,7 @@ freetuxtv_curl_error_quark () { } void -freetuxtv_fileutils_get_file (gchar* url, gchar* dst_file, const GProxyStruct* pProxySctruct, int timeout, GError **error) +freetuxtv_fileutils_get_file (const gchar* url, const gchar* dst_file, const GProxyStruct* pProxySctruct, int timeout, GError **error) { g_return_if_fail(url != NULL); g_return_if_fail(dst_file != NULL); diff --git a/src/freetuxtv-fileutils.h b/src/freetuxtv-fileutils.h index 377ae21..3e15a60 100644 --- a/src/freetuxtv-fileutils.h +++ b/src/freetuxtv-fileutils.h @@ -46,7 +46,7 @@ typedef struct _GProxyStruct { } GProxyStruct; void -freetuxtv_fileutils_get_file (gchar* url, gchar* dst_file, const GProxyStruct* pProxySctruct, int timeout, GError **error); +freetuxtv_fileutils_get_file (const gchar* url, const gchar* dst_file, const GProxyStruct* pProxySctruct, int timeout, GError **error); gchar* gproxystruct_to_string(const GProxyStruct* pProxySctruct, gboolean protocol, gboolean server, gboolean auth); diff --git a/src/freetuxtv-tv-channels-list.c b/src/freetuxtv-tv-channels-list.c index 1f2d5fc..8e5bc3e 100644 --- a/src/freetuxtv-tv-channels-list.c +++ b/src/freetuxtv-tv-channels-list.c @@ -93,11 +93,21 @@ tvchannels_list_synchronize (FreetuxTVApp *app, DBSync *dbsync, G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG, &cbxmldata, NULL); gchar *xml_data; - gchar *filename; - filename = g_build_filename(app->paths.datadir, "tv_channels.xml", NULL); - g_file_get_contents (filename, &xml_data, &filelen, NULL); - g_free(filename); - filename = NULL; + gchar *szFileName = NULL; + + szFileName = g_build_filename(g_get_user_cache_dir(), "freetuxtv", "tv_channels.dat", NULL); + if(szFileName){ + if(!g_file_test(szFileName, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)){ + g_free(szFileName); + szFileName = NULL; + } + } + if(!szFileName){ + szFileName = g_build_filename(app->paths.datadir, "tv_channels.xml", NULL); + } + g_file_get_contents (szFileName, &xml_data, &filelen, NULL); + g_free(szFileName); + szFileName = NULL; g_markup_parse_context_parse (context, xml_data, -1, error); } diff --git a/src/freetuxtv-window-tv-channels-database.c b/src/freetuxtv-window-tv-channels-database.c index 984296b..0d18d94 100644 --- a/src/freetuxtv-window-tv-channels-database.c +++ b/src/freetuxtv-window-tv-channels-database.c @@ -25,6 +25,8 @@ freetuxtv is free software: you can redistribute it and/or modify it #include "freetuxtv-tv-channels-list.h" #include "freetuxtv-window-main.h" +#include "freetuxtv-fileutils.h" + #include "gtk-progress-dialog.h" typedef struct _FreetuxTVWindowTVChannelsDatabasePrivate FreetuxTVWindowTVChannelsDatabasePrivate; @@ -107,14 +109,26 @@ on_buttonapply_clicked (GtkButton *button, gpointer user_data) DBSync dbsync; + gchar* szTmp = NULL; + gboolean bSynchronize = FALSE; + gboolean bDownloadFile = FALSE; + + const gchar *szUrl; + gchar *szDstFile = NULL; - // Check if must synchronize GtkWidget* pWidget; - pWidget = (GtkWidget *) gtk_builder_get_object (builder, "checkbutton_synchronize"); GtkWindow* pParent; - + + // Check if must synchronize + pWidget = (GtkWidget *) gtk_builder_get_object (builder, "checkbutton_synchronize"); bSynchronize = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pWidget)); + + // Check if must update file + pWidget = (GtkWidget *) gtk_builder_get_object (builder, "checkbutton_download"); + bDownloadFile = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pWidget)); + pWidget = (GtkWidget *) gtk_builder_get_object (builder, "entry_url"); + szUrl = gtk_entry_get_text(GTK_ENTRY(pWidget)); pParent = gtk_builder_window_get_top_window(GTK_BUILDER_WINDOW(pWindowTVChannelsDatabase)); @@ -128,8 +142,25 @@ on_buttonapply_clicked (GtkButton *button, gpointer user_data) gtk_widget_show(GTK_WIDGET(pProgressDialog)); } + // Do download file + if(bDownloadFile && (error == NULL)){ + szDstFile = g_build_filename(g_get_user_cache_dir(), "freetuxtv", "tv_channels.dat", NULL); + + szTmp = g_strdup_printf(_("Downloading the file '%s'"), szUrl); + g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Downloading the file '%s'\n", szUrl); + + gtk_progress_dialog_set_text(pProgressDialog, szTmp); + if(szTmp){ + g_free(szTmp); + szTmp = NULL; + } + + freetuxtv_fileutils_get_file (szUrl, szDstFile, &(priv->app->prefs.proxy), priv->app->prefs.timeout, &error); + } + // Do synchronize - if(bSynchronize){ + if(bSynchronize && (error == NULL)){ gtk_progress_dialog_set_text(pProgressDialog, _("Synchronizing TV channels from file")); dbsync_open_db (&dbsync, &error); @@ -143,13 +174,24 @@ on_buttonapply_clicked (GtkButton *button, gpointer user_data) dbsync_close_db(&dbsync); - progress += 0.33; - gtk_progress_dialog_set_percent(pProgressDialog, progress); + gtk_progress_dialog_set_percent(pProgressDialog, 0.90); } - progress = 1.0; - gtk_progress_dialog_set_percent(pProgressDialog, 1.0); - gtk_progress_dialog_set_button_close_enabled(pProgressDialog, TRUE); + if(szDstFile){ + g_free(szDstFile); + szDstFile = NULL; + } + + // On error we destroy the progress dialog view + if(pProgressDialog){ + if(error != NULL){ + gtk_widget_destroy (GTK_WIDGET(pProgressDialog)); + pProgressDialog = NULL; + }else{ + gtk_progress_dialog_set_percent(pProgressDialog, 1.0); + gtk_progress_dialog_set_button_close_enabled(pProgressDialog, TRUE); + } + } if(error != NULL){ windowmain_show_gerror (priv->app, error);