Skip to content

Commit

Permalink
[FreetuxTV] Download TV channel file.
Browse files Browse the repository at this point in the history
  • Loading branch information
eric.beuque committed Nov 18, 2012
1 parent 9cf1989 commit 0b1dcc8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
6 changes: 2 additions & 4 deletions data/ui/tvchannelsdatabase.glade
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="checkbutton2">
<object class="GtkCheckButton" id="checkbutton_download">
<property name="label" translatable="yes">Update database from file:</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
Expand All @@ -125,9 +124,8 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<object class="GtkEntry" id="entry_url">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="text" translatable="yes">http://freetuxtv.googlecode.com/svn/trunk/data/tv_channels.xml</property>
Expand Down
2 changes: 1 addition & 1 deletion src/freetuxtv-fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/freetuxtv-fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 15 additions & 5 deletions src/freetuxtv-tv-channels-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
60 changes: 51 additions & 9 deletions src/freetuxtv-window-tv-channels-database.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 0b1dcc8

Please sign in to comment.