From 660392b973b07bde480a5069b9556571fcde4667 Mon Sep 17 00:00:00 2001 From: "eric.beuque" Date: Sun, 11 Apr 2010 16:21:19 +0000 Subject: [PATCH] =?UTF-8?q?[FreetuxTV]=20Conversion=20du=20fichier=20de=20?= =?UTF-8?q?la=20liste=20des=20logos=20en=20un=20fichier=20contenant=20une?= =?UTF-8?q?=20liste=20de=20cha=C3=AEne=20et=20correction=20du=20code=20pou?= =?UTF-8?q?r=20supporter=20le=20nouveau=20format=20du=20fichier.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/Makefile.am | 4 +- data/images/groups/Makefile.am | 3 + data/tv_channels.xml | 1125 ++++++++++++++++++++++++++++++ src/Makefile.am | 2 + src/freetuxtv-app.h | 2 +- src/freetuxtv-db-sync.c | 482 +++++++------ src/freetuxtv-db-sync.h | 51 +- src/freetuxtv-logos-list.c | 154 ++-- src/freetuxtv-logos-list.h | 2 +- src/freetuxtv-tv-channel-infos.c | 224 ++++++ src/freetuxtv-tv-channel-infos.h | 78 +++ src/freetuxtv-window-main.c | 17 +- 12 files changed, 1829 insertions(+), 315 deletions(-) create mode 100644 data/images/groups/Makefile.am create mode 100644 data/tv_channels.xml create mode 100644 src/freetuxtv-tv-channel-infos.c create mode 100644 src/freetuxtv-tv-channel-infos.h diff --git a/data/Makefile.am b/data/Makefile.am index ffb424c..e640d9e 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -6,8 +6,8 @@ xml_DATA = $(xml_in_files:.xml.in=.xml) # Other data file to install freetuxtvdata_DATA = \ - sqlite3-create-tables.sql\ - channels_logos.xml + sqlite3-create-tables.sql \ + tv_channels.xml freetuxtvdatadir = \ $(pkgdatadir) diff --git a/data/images/groups/Makefile.am b/data/images/groups/Makefile.am new file mode 100644 index 0000000..b4f449a --- /dev/null +++ b/data/images/groups/Makefile.am @@ -0,0 +1,3 @@ +## File created by the gnome-build tools + + diff --git a/data/tv_channels.xml b/data/tv_channels.xml new file mode 100644 index 0000000..df0bb3b --- /dev/null +++ b/data/tv_channels.xml @@ -0,0 +1,1125 @@ + + + 100pourcentradio.png + + + 1onairconnect.png + + + 2mmaroc.png + + + ab1.png + + + abmoteurs.png + + + abudhabitv.png + + + accrotv.png + + + aci.png + + + action.png + + + adofm.png + + + aljazeera.png + + + + aljazeerachildren.png + + + aljazeerainternational.png + + + almasriya.png + + + alouettefm.png + + + alsatictv.png + + + apsaratv.png + + + aptv.png + + + argentquebec.png + + + armeniapublictv.png + + + armeniatv.png + + + arretsurimages.png + + + artchannel.png + + + arte.png + + + + artplatv.png + + + astrocentertv.png + + + + astv.png + + + aupradio.png + + + babylontv.png + + + bambochtv.png + + + baraem.png + + + bastilletv.png + + + bbcworld.png + + + bbcworldnews.png + + + beurfm.png + + + beurtv.png + + + beijingtv.png + + + bestofshopping.png + + + bfmradio.png + + + bfmtv.png + + + biscottetv.png + + + bloombergtv.png + + + boardriderstv.png + + + bulgariatv.png + + + c9.png + + + calaistv.png + + + canalacademie.png + + + canalalgerie.png + + + + canalinfonews.png + + + canalplus.png + + + canalsavoir.png + + + canaltv.png + + + cap24-paris.png + + + cashtv.png + + + cctv1.png + + + cctv2.png + + + cctv4.png + + + + cctv7.png + + + cctv9.png + + + cctv10.png + + + cctv11.png + + + cctv12.png + + + cctvdivertissement.png + + + cctv_e.png + + + cctvf.png + + + + cheriefm.png + + + + channelonerussia-orti.png + + + + + + + chongqing_tv.png + + + + + + + + + cinefirst.png + + + cinefx.png + + + cinepolar.png + + + clermontpremiere.png + + + clubbingtv.png + + + cmusictv.png + + + cnbc.png + + + + contactfm.png + + + corriland.png + + + couleur3-rsr.png + + + cpac.png + + + demaintv.png + + + + + direct8.png + + + dubaitv.png + + + dwtv-deutschewelle.png + + + + ekodesgarrigues.png + + + equidia.png + + + ertworld.png + + + espacefm.png + + + espacemusique.png + + + etbsat.png + + + euronews.png + + + + + + + + + + + + europe1.png + + + evasionfm.png + + + extra3channel.png + + + fashiontv.png + + + + fazzmusic.png + + + fcradiolessentiel.png + + + fip.png + + + flyfm.png + + + fmen.png + + + foxlife.png + + + france2.png + + + france24.png + + + + + + france3.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + + france4.png + + + france5.png + + + francebleu.png + + + + franceculture.png + + + franceinfo.png + + + franceinter.png + + + francemusique.png + + + franceo.png + + + + + + franceteleachat.png + + + + francevivace.png + + + freenewstv.png + + + frequence3.png + + + frequenceindia.png + + + funradio.png + + + funtv.png + + + gameone.png + + + gameonemusichd.png + + + godtv.png + + + gong.png + + + grandlille_tv.png + + + grossecaisse.png + + + guangdongsoutherntv.png + + + gulli.png + + + guysentv.png + + + hebei_tv.png + + + heilongjiangtv.png + + + hilaltv.png + + + hitwest.png + + + hunansatellitetv.png + + + idf1.png + + + inraci.png + + + inspirationnetwork.png + + + ishtartv.png + + + itelevision.png + + + + + jamzine.png + + + jazzradio-exfrequencejazz.png + + + + jazzradioblack.png + + + jazzradioblues.png + + + jazzradioladies.png + + + jazzradiolounge.png + + + jazzradioreprises.png + + + jet.png + + + jordansatellitechannel.png + + + jpopsukitv.png + + + jukebox.png + + + kanal7int.png + + + kanal24.png + + + kanalavrupa.png + + + kto.png + + + kuwaittv1.png + + + kuwaittv2.png + + + labelletv.png + + + lachainechinoise.png + + + lachainedejiangsu.png + + + lachaineparlementaire.png + + + + + + lalocale.png + + + laradiodelamer.png + + + lcm-marseille.png + + + lcnquebec.png + + + lemouv.png + + + lequipetv.png + + + libertytv.png + + + localesidf.png + + + luxetv.png + + + + m6boutique.png + + + m6musicblack.png + + + m6musicclub.png + + + m6musichits.png + + + m6musicrock.png + + + mangas.png + + + mcm.png + + + mcmpop.png + + + mcmtop.png + + + medi1sat.png + + + + mezzo.png + + + mfm.png + + + mfmflashback.png + + + mfmserenite.png + + + mfmsexy.png + + + miziktropical.png + + + mjcapt.png + + + montecarlodoualiya.png + + + mosaiquefm.png + + + montereybayaquarium.png + + + mplusm.png + + + mtv.png + + + mtv2.png + + + mtvdance.png + + + mtvhits.png + + + nasatv.png + + + + + natgeomusic.png + + + nationalgeographic.png + + + nhk.png + + + nightmagcom.png + + + nolife.png + + + normandietv.png + + + nostalgie.png + + + nrj.png + + + nrj12.png + + + nrjhits.png + + + nrjnouveautes.png + + + + nrjparis.png + + + nt1.png + + + + nti.png + + + + orleanstv.png + + + ouesttv.png + + + ouifm.png + + + + + oxyradio.png + + + ozradio.png + + + parentheseradio.png + + + parispremiere.png + + + phoenixchinesenewsandentertainment.png + + + phoenixinfonews.png + + + pokerchannel.png + + + powerturktv.png + + + publicsenat.png + + + purescreens.png + + + radio8.png + + + radioclapas.png + + + radioclassique.png + + + + radioethic.png + + + radiofg.png + + + radiofgamerica.png + + + radiofgchic.png + + + radiofgclassics.png + + + radiofgdance.png + + + radiofgunderground.png + + + radioicietmaintenant.png + + + radiojunior.png + + + radiolatina.png + + + + radiolibertaire.png + + + radiomelodie.png + + + radioneo.png + + + radionotredame.png + + + radionova.png + + + radiocean.png + + + radiopublicsante.png + + + radioscoop.png + + + radioscoop80s.png + + + radioscoopmusicpod.png + + + radioscoopboxvintage.png + + + radiostar.png + + + radiosun.png + + + railtv.png + + + raiuno.png + + + raidue.png + + + raitre.png + + + rbg.png + + + rdicanada.png + + + recordinternacional.png + + + relaxtv.png + + + rfi.png + + + + + + + rfm.png + + + rireetchansons.png + + + rmc.png + + + + rmn.png + + + rocfm.png + + + rocktv.png + + + rtcgsat.png + + + rtcteleliege.png + + + rtl.png + + + rtl2.png + + + rtl9.png + + + rtpi.png + + + + + rtrplaneta.png + + + rtsfm.png + + + russiatoday.png + + + rve.png + + + sabcnews.png + + + samanyolutv.png + + + seebittv.png + + + shanghaidragontv.png + + + shenzhen_tv.png + + + skynews.png + + + + skynewsinternational.png + + + skyrock.png + + + soleil_la_radio.png + + + souvenirfromearth.png + + + sudradio.png + + + suroyotv.png + + + tele102.png + + + teleblagon.png + + + telegrenoble.png + + + + + telemelody.png + + + telenantes.png + + + telenight.png + + + telenova.png + + + teleplaisance.png + + + telessonne.png + + + telesur.png + + + telif.png + + + tempomix.png + + + teva.png + + + tfou.png + + + tfouwebtv.png + + + tllteleloire.png + + + tlm-lyon.png + + + + tlt-toulouse.png + + + turnerclassicmovies.png + + + tmc.png + + + + tna.png + + + topmusic.png + + + tracetropical.png + + + tracetv.png + + + trt1.png + + + trtcocuk.png + + + trtint.png + + + + tsfjazz.png + + + tv3cat-extvci.png + + + tv5.png + + + + tv7bordeaux.png + + + tv7tunisia.png + + + tv8montblanc.png + + + + tvaquebec.png + + + tvbiznes.png + + + tveint.png + + + + + tvmeurope-exrtm1-rtmmaroc.png + + + tvpi.png + + + tvpolonia-tvp.png + + + + tvromania.png + + + tvt.png + + + tvtours.png + + + tvvi.png + + + vesti.png + + + vh1.png + + + vh1classic.png + + + vibration.png + + + videoclick.png + + + vietnam-vtv4.png + + + virgin17.png + + + virginradio.png + + + voltage.png + + + voxafrica.png + + + worldfashion.png + + + xiamenstartv.png + + + yementv.png + + + zdf_de.png + + + zhejiangstartv.png + + diff --git a/src/Makefile.am b/src/Makefile.am index 4e5fd28..593751f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,6 +36,8 @@ freetuxtv_SOURCES = \ freetuxtv-models.h \ freetuxtv-recordings-list.c \ freetuxtv-recordings-list.h \ + freetuxtv-tv-channel-infos.h \ + freetuxtv-tv-channel-infos.c\ freetuxtv-utils.c \ freetuxtv-utils.h \ freetuxtv-window-main.c \ diff --git a/src/freetuxtv-app.h b/src/freetuxtv-app.h index f97f637..89a27ba 100644 --- a/src/freetuxtv-app.h +++ b/src/freetuxtv-app.h @@ -33,8 +33,8 @@ G_BEGIN_DECLS /* For testing propose use the local (not installed) ui file */ -// #define FREETUXTV_DIR "data" #define FREETUXTV_DIR PACKAGE_DATA_DIR "/" PACKAGE +//#define FREETUXTV_DIR "data" #define FREETUXTV_UI_DIR FREETUXTV_DIR "/ui" #define FREETUXTV_GLADEXML FREETUXTV_UI_DIR "/freetuxtv.ui" diff --git a/src/freetuxtv-db-sync.c b/src/freetuxtv-db-sync.c index dd2c2f2..4e6c90f 100644 --- a/src/freetuxtv-db-sync.c +++ b/src/freetuxtv-db-sync.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8-*- */ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4-*- */ /* * FreetuxTV is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ #include #include "freetuxtv-db-sync.h" +#include "freetuxtv-tv-channel-infos.h" typedef struct { FreetuxTVApp *app; @@ -73,8 +74,12 @@ static int on_exec_channel (void *data, int argc, char **argv, char **colsname); static void -dbsync_link_tvchannel_to_channels (DBSync *dbsync, gchar *label, glong id_tvchannel, - GError** error); +dbsync_add_label_tvchannel (DBSync *dbsync, gchar* label, glong id_tvchannel, + GError** error); + +static void +dbsync_link_tvchannel_to_channels_from_label (DBSync *dbsync, gchar *label, + glong id_tvchannel, GError** error); GQuark freetuxtv_dbsync_error = 0; @@ -97,8 +102,8 @@ dbsync_open_db(DBSync *dbsync, GError** error) int res; user_db = g_strconcat(g_get_user_config_dir(), - "/FreetuxTV/freetuxtv.db", NULL); - + "/FreetuxTV/freetuxtv.db", NULL); + // Open the database if not open g_print("DBSync : Open database\n"); res = sqlite3_open(user_db, &(dbsync->db_link)); @@ -106,12 +111,12 @@ dbsync_open_db(DBSync *dbsync, GError** error) if(error != NULL){ // sqlite3_errmsg return const char*, no need to free it *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_OPEN, - _("Cannot open database.\n\nSQLite has returned error :\n%s."), - sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_OPEN, + _("Cannot open database.\n\nSQLite has returned error :\n%s."), + sqlite3_errmsg(dbsync->db_link)); } } - + g_free(user_db); } @@ -135,8 +140,8 @@ dbsync_db_exists(DBSync *dbsync) gboolean res = FALSE; user_db = g_strconcat(g_get_user_config_dir(), - "/FreetuxTV/freetuxtv.db", NULL); - + "/FreetuxTV/freetuxtv.db", NULL); + if (g_file_test (user_db, G_FILE_TEST_IS_REGULAR)){ res = TRUE; } @@ -154,36 +159,36 @@ dbsync_create_db (DBSync *dbsync, GError** error) gchar *query; gchar *db_err = NULL; int res; - + // Load file containing the database creation queries gchar* filename; gsize filelen; filename = FREETUXTV_DIR "/sqlite3-create-tables.sql"; - + res = g_file_get_contents (filename, &query, &filelen, error); if (res){ res = sqlite3_exec(dbsync->db_link, query, NULL, 0, &db_err); if(res != SQLITE_OK){ g_printerr("Sqlite3 : %s\n", - sqlite3_errmsg(dbsync->db_link)); + sqlite3_errmsg(dbsync->db_link)); g_printerr("FreetuxTV : Cannot create tables\n"); - + *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when creating the database.\n\nSQLite has returned error :\n%s."), - sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when creating the database.\n\nSQLite has returned error :\n%s."), + sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); } } - + g_free(query); } void dbsync_select_channels_groups (DBSync *dbsync, FreetuxTVApp *app, - int (*callback)(FreetuxTVApp *app, FreetuxTVChannelsGroupInfos* channels_group_infos, - DBSync *dbsync, gpointer user_data, GError** error), - gpointer user_data, GError** error) + int (*callback)(FreetuxTVApp *app, FreetuxTVChannelsGroupInfos* channels_group_infos, + DBSync *dbsync, gpointer user_data, GError** error), + gpointer user_data, GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -202,36 +207,37 @@ dbsync_select_channels_groups (DBSync *dbsync, FreetuxTVApp *app, cb_data.user_data = user_data; cb_data.error = error; - query = sqlite3_mprintf("SELECT %s, %s, %s, %s, %s, %s, %s \ - FROM %s \ - ORDER BY %s", - // SELECT - DB_CHANNELSGROUP_ID, DB_CHANNELSGROUP_RANK, DB_CHANNELSGROUP_NAME, - DB_CHANNELSGROUP_TYPE, DB_CHANNELSGROUP_URI, DB_CHANNELSGROUP_BREGEX, DB_CHANNELSGROUP_EREGEX, - // FROM - DB_CHANNELSGROUP, - // ORDER BY - DB_CHANNELSGROUP_RANK); + query = sqlite3_mprintf("\ + SELECT %s, %s, %s, %s, %s, %s, %s \ + FROM %s \ + ORDER BY %s", + // SELECT + DB_CHANNELSGROUP_ID, DB_CHANNELSGROUP_RANK, DB_CHANNELSGROUP_NAME, + DB_CHANNELSGROUP_TYPE, DB_CHANNELSGROUP_URI, DB_CHANNELSGROUP_BREGEX, DB_CHANNELSGROUP_EREGEX, + // FROM + DB_CHANNELSGROUP, + // ORDER BY + DB_CHANNELSGROUP_RANK); res = sqlite3_exec(dbsync->db_link, query, on_exec_channels_group, &cb_data, &db_err); sqlite3_free(query); if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when displaying the channels.\n\nSQLite has returned error :\n%s."), - sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when displaying the channels.\n\nSQLite has returned error :\n%s."), + sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); - + } } void dbsync_select_channels_of_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - FreetuxTVApp *app, - int (*callback)(FreetuxTVApp *app, - FreetuxTVChannelInfos* channel_infos, - DBSync *dbsync, gpointer user_data, GError** error), - gpointer user_data, GError** error) + FreetuxTVChannelsGroupInfos* channels_group_infos, + FreetuxTVApp *app, + int (*callback)(FreetuxTVApp *app, + FreetuxTVChannelInfos* channel_infos, + DBSync *dbsync, gpointer user_data, GError** error), + gpointer user_data, GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -251,38 +257,39 @@ dbsync_select_channels_of_channels_group (DBSync *dbsync, cb_data.error = error; cb_data.cb_data1 = channels_group_infos; - query = sqlite3_mprintf("SELECT %s.%s, %s.%s, %s.%s, %s.%s, %s.%s \ - FROM %s LEFT JOIN %s ON %s.%s=%s.%s \ - WHERE %s.%s=%d \ - ORDER BY %s.%s", - // SELECT - DB_CHANNEL, DB_CHANNEL_ID, DB_CHANNEL, DB_CHANNEL_NAME, - DB_TVCHANNEL, DB_TVCHANNEL_LOGOFILENAME, DB_CHANNEL, DB_CHANNEL_URI, - DB_CHANNEL, DB_CHANNEL_VLCOPTIONS, - // FROM - DB_CHANNEL, DB_TVCHANNEL, - // ON - DB_CHANNEL, DB_CHANNEL_TVCHANNELID, DB_TVCHANNEL, DB_TVCHANNEL_ID, - // WHERE - DB_CHANNEL, DB_CHANNEL_CHANNELGROUPID, channels_group_infos->id, - // ORDER BY - DB_CHANNEL, DB_CHANNEL_RANK); + query = sqlite3_mprintf("\ + SELECT %s.%s, %s.%s, %s.%s, %s.%s, %s.%s \ + FROM %s LEFT JOIN %s ON %s.%s=%s.%s \ + WHERE %s.%s=%d \ + ORDER BY %s.%s", + // SELECT + DB_CHANNEL, DB_CHANNEL_ID, DB_CHANNEL, DB_CHANNEL_NAME, + DB_TVCHANNEL, DB_TVCHANNEL_LOGOFILENAME, DB_CHANNEL, DB_CHANNEL_URI, + DB_CHANNEL, DB_CHANNEL_VLCOPTIONS, + // FROM + DB_CHANNEL, DB_TVCHANNEL, + // ON + DB_CHANNEL, DB_CHANNEL_TVCHANNELID, DB_TVCHANNEL, DB_TVCHANNEL_ID, + // WHERE + DB_CHANNEL, DB_CHANNEL_CHANNELGROUPID, channels_group_infos->id, + // ORDER BY + DB_CHANNEL, DB_CHANNEL_RANK); res = sqlite3_exec(dbsync->db_link, query, on_exec_channel, &cb_data, &db_err); sqlite3_free(query); if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when displaying the channels.\n\nSQLite has returned error :\n%s."), - sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when displaying the channels.\n\nSQLite has returned error :\n%s."), + sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); } } void dbsync_add_channel (DBSync *dbsync, - FreetuxTVChannelInfos* channel_infos, - GError** error) + FreetuxTVChannelInfos* channel_infos, + GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -302,40 +309,47 @@ dbsync_add_channel (DBSync *dbsync, } // Add the channel - query = sqlite3_mprintf("INSERT INTO %s (%s, %s, %s, %s, %s, %s) \ - VALUES ('%q',%d,'%q', %Q, \ - (SELECT %s.%s FROM %s \ - WHERE ('%q' LIKE %s.%s||'%%') OR %s.%s = \ - (SELECT %s.%s FROM %s \ - WHERE ('%q' LIKE %s.%s||'%%') \ - ORDER BY %s.%s DESC \ - ) \ - ORDER BY %s.%s DESC \ - ),'%d');", - // INSERT INTO - DB_CHANNEL, - // ( - DB_CHANNEL_NAME, DB_CHANNEL_RANK, DB_CHANNEL_URI, - DB_CHANNEL_VLCOPTIONS, DB_CHANNEL_TVCHANNELID, DB_CHANNEL_CHANNELGROUPID, - // ) VALUES ( - channel_infos->name, channel_infos->order, channel_infos->url, vlc_options, - // (SELECT - DB_TVCHANNEL, DB_TVCHANNEL_ID, - // FROM - DB_TVCHANNEL, - // WHERE - channel_infos->name, DB_TVCHANNEL, DB_TVCHANNEL_NAME, - // OR - DB_TVCHANNEL, DB_TVCHANNEL_ID, - // (SELECT - DB_LABELTVCHANNEL, DB_LABELTVCHANNEL_TVCHANNELID, DB_LABELTVCHANNEL, - // WHERE - channel_infos->name, DB_LABELTVCHANNEL, DB_LABELTVCHANNEL_LABEL, - // ORDER BY - DB_LABELTVCHANNEL, DB_LABELTVCHANNEL_LABEL, - // ) ORDER BY - DB_TVCHANNEL, DB_TVCHANNEL_NAME, - channel_infos->channels_group->id); + query = sqlite3_mprintf("\ + INSERT INTO %s (%s, %s, %s, %s, %s, %s) \ + VALUES \ + ('%q',%d,'%q', %Q, (\ + SELECT %s.%s FROM %s \ + WHERE ('%q' LIKE %s.%s||'%%') \ + OR %s.%s = ( \ + SELECT %s.%s FROM %s \ + WHERE ('%q' LIKE %s.%s||'%%') \ + ORDER BY %s.%s DESC ) \ + ORDER BY %s.%s DESC ) \ + ,'%d');", + // INSERT INTO + DB_CHANNEL, + // ( + DB_CHANNEL_NAME, DB_CHANNEL_RANK, DB_CHANNEL_URI, + DB_CHANNEL_VLCOPTIONS, DB_CHANNEL_TVCHANNELID, DB_CHANNEL_CHANNELGROUPID, + // ) VALUES ( + channel_infos->name, channel_infos->order, channel_infos->url, vlc_options, + // (SELECT + DB_TVCHANNEL, DB_TVCHANNEL_ID, + // FROM + DB_TVCHANNEL, + // WHERE + channel_infos->name, DB_TVCHANNEL, DB_TVCHANNEL_NAME, + // OR + DB_TVCHANNEL, DB_TVCHANNEL_ID, + // (SELECT + DB_LABELTVCHANNEL, DB_LABELTVCHANNEL_TVCHANNELID, DB_LABELTVCHANNEL, + // WHERE + channel_infos->name, DB_LABELTVCHANNEL, DB_LABELTVCHANNEL_LABEL, + // ORDER BY + DB_LABELTVCHANNEL, DB_LABELTVCHANNEL_LABEL, + // ) + // ORDER BY + DB_TVCHANNEL, DB_TVCHANNEL_NAME, + // ) + channel_infos->channels_group->id + // ) + ); + res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); //g_print("%s\n", query); sqlite3_free(query); @@ -343,23 +357,23 @@ dbsync_add_channel (DBSync *dbsync, if(vlc_options){ g_free(vlc_options); } - + if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when adding the channel \"%s\".\n\nSQLite has returned error :\n%s."), - channel_infos->name, sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when adding the channel \"%s\".\n\nSQLite has returned error :\n%s."), + channel_infos->name, sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); }else{ freetuxtv_channel_infos_set_id (channel_infos, - (int)sqlite3_last_insert_rowid(dbsync->db_link)); + (int)sqlite3_last_insert_rowid(dbsync->db_link)); } } void dbsync_add_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - GError** error) + FreetuxTVChannelsGroupInfos* channels_group_infos, + GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -371,48 +385,49 @@ dbsync_add_channels_group (DBSync *dbsync, gchar *query; gchar *db_err = NULL; int res; - + // Add the group query = sqlite3_mprintf("INSERT INTO %s (%s, %s, %s, %s, %s, %s) \ - VALUES ((SELECT IFNULL(MAX(%s), 0) + 1 FROM %s), '%q', %d, %Q, %Q, %Q);", - // INSERT INTO - DB_CHANNELSGROUP, - // ( - DB_CHANNELSGROUP_RANK, - DB_CHANNELSGROUP_NAME, - DB_CHANNELSGROUP_TYPE, - DB_CHANNELSGROUP_URI, - DB_CHANNELSGROUP_BREGEX, - DB_CHANNELSGROUP_EREGEX, - // ) VALUES ( - DB_CHANNELSGROUP_RANK, DB_CHANNELSGROUP, // rank - channels_group_infos->name, - 0, - channels_group_infos->uri, - channels_group_infos->bregex, - channels_group_infos->eregex - ); - + VALUES ((SELECT IFNULL(MAX(%s), 0) + 1 FROM %s), '%q', %d, %Q, %Q, %Q);", + // INSERT INTO + DB_CHANNELSGROUP, + // ( + DB_CHANNELSGROUP_RANK, + DB_CHANNELSGROUP_NAME, + DB_CHANNELSGROUP_TYPE, + DB_CHANNELSGROUP_URI, + DB_CHANNELSGROUP_BREGEX, + DB_CHANNELSGROUP_EREGEX, + // ) VALUES ( + DB_CHANNELSGROUP_RANK, DB_CHANNELSGROUP, // rank + channels_group_infos->name, + 0, + channels_group_infos->uri, + channels_group_infos->bregex, + channels_group_infos->eregex + // ) + ); + res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); sqlite3_free(query); - + if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Cannot add the group \"%s\" in database.\n\nSQLite has returned error :\n%s."), - channels_group_infos->name, - sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Cannot add the group \"%s\" in database.\n\nSQLite has returned error :\n%s."), + channels_group_infos->name, + sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); }else{ freetuxtv_channels_group_infos_set_id (channels_group_infos, - (int)sqlite3_last_insert_rowid(dbsync->db_link)); + (int)sqlite3_last_insert_rowid(dbsync->db_link)); } } void dbsync_update_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - GError** error) + FreetuxTVChannelsGroupInfos* channels_group_infos, + GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -424,27 +439,27 @@ dbsync_update_channels_group (DBSync *dbsync, gchar *query; gchar *db_err = NULL; int res; - + // Update the group query = sqlite3_mprintf("UPDATE %s SET %s='%q', %s=%Q, %s=%Q, %s=%Q \ - WHERE %s=%d", - // UPDATE - DB_CHANNELSGROUP, - // SET - DB_CHANNELSGROUP_NAME, channels_group_infos->name, - DB_CHANNELSGROUP_URI, channels_group_infos->uri, - DB_CHANNELSGROUP_BREGEX, channels_group_infos->bregex, - DB_CHANNELSGROUP_EREGEX, channels_group_infos->eregex, - // WHERE - DB_CHANNELSGROUP_ID, channels_group_infos->id); + WHERE %s=%d", + // UPDATE + DB_CHANNELSGROUP, + // SET + DB_CHANNELSGROUP_NAME, channels_group_infos->name, + DB_CHANNELSGROUP_URI, channels_group_infos->uri, + DB_CHANNELSGROUP_BREGEX, channels_group_infos->bregex, + DB_CHANNELSGROUP_EREGEX, channels_group_infos->eregex, + // WHERE + DB_CHANNELSGROUP_ID, channels_group_infos->id); res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); sqlite3_free(query); - + if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when updating the group \"%s\".\n\nSQLite has returned error :\n%s."), - channels_group_infos->name, sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when updating the group \"%s\".\n\nSQLite has returned error :\n%s."), + channels_group_infos->name, sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); } } @@ -452,8 +467,8 @@ dbsync_update_channels_group (DBSync *dbsync, void dbsync_delete_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - GError** error) + FreetuxTVChannelsGroupInfos* channels_group_infos, + GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -465,30 +480,30 @@ dbsync_delete_channels_group (DBSync *dbsync, gchar *query; gchar *db_err = NULL; int res; - + // Delete the channels group query = sqlite3_mprintf("DELETE FROM %s WHERE %s=%d", - // DELETE FROM - DB_CHANNELSGROUP, - // WHERE - DB_CHANNELSGROUP_ID, channels_group_infos->id); + // DELETE FROM + DB_CHANNELSGROUP, + // WHERE + DB_CHANNELSGROUP_ID, channels_group_infos->id); res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); sqlite3_free(query); - + if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when deleting the group \"%s\".\n\nSQLite has returned error :\n%s."), - channels_group_infos->name, - sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when deleting the group \"%s\".\n\nSQLite has returned error :\n%s."), + channels_group_infos->name, + sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); } } void dbsync_delete_channels_of_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - GError** error) + FreetuxTVChannelsGroupInfos* channels_group_infos, + GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -503,19 +518,19 @@ dbsync_delete_channels_of_channels_group (DBSync *dbsync, // Delete the channels of the channels group query = sqlite3_mprintf("DELETE FROM %s WHERE %s=%d", - // DELETE FROM - DB_CHANNEL, - // WHERE - DB_CHANNEL_CHANNELGROUPID, channels_group_infos->id); + // DELETE FROM + DB_CHANNEL, + // WHERE + DB_CHANNEL_CHANNELGROUPID, channels_group_infos->id); res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); sqlite3_free(query); - + if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when deleting the channels of the group \"%s\".\n\nSQLite has returned error :\n%s."), - channels_group_infos->name, - sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when deleting the channels of the group \"%s\".\n\nSQLite has returned error :\n%s."), + channels_group_infos->name, + sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); } } @@ -532,58 +547,83 @@ dbsync_delete_tvchannels (DBSync *dbsync, GError** error) gchar *db_err = NULL; int res; - // Delete the channels logos + // Delete all TV channels from the database query = sqlite3_mprintf("DELETE FROM %s", DB_TVCHANNEL); res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); sqlite3_free(query); if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when deleting the tv channels list.\n\nSQLite has returned error :\n%s."), - sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when deleting the tv channels list.\n\nSQLite has returned error :\n%s."), + sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); } } void -dbsync_add_tvchannel (DBSync *dbsync, gchar* label, gchar* filename, - glong *id, GError** error) +dbsync_add_tvchannel (DBSync *dbsync, FreetuxTVTvChannelInfos* tv_channel_infos, + GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); g_return_if_fail(error != NULL); g_return_if_fail(*error == NULL); - g_return_if_fail(id != NULL); + g_return_if_fail(tv_channel_infos != NULL); + g_return_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos)); gchar *query; gchar *db_err = NULL; int res; - - // Add the channel logo - query = sqlite3_mprintf("INSERT INTO %s (%s, %s) VALUES ('%q','%q');", - // INSERT INTO - DB_TVCHANNEL, - // ( - DB_TVCHANNEL_NAME, DB_TVCHANNEL_LOGOFILENAME, - // ) VALUES ( - label, filename); + int id; + + gchar* name; + gchar* logo_filename; + GList* cur_label; + + name = (gchar*)freetuxtv_tv_channel_infos_get_name(tv_channel_infos); + logo_filename = (gchar*)freetuxtv_tv_channel_infos_get_logo_filename(tv_channel_infos); + + // Add the TV channel in the database + query = sqlite3_mprintf("INSERT INTO %s (%s, %s) VALUES ('%q', %Q);", + // INSERT INTO + DB_TVCHANNEL, + // ( + DB_TVCHANNEL_NAME, DB_TVCHANNEL_LOGOFILENAME, + // ) VALUES ( + name, logo_filename + // ) + ); res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); sqlite3_free(query); if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when adding the tv channel '%s'.\n\nSQLite has returned error :\n%s."), - label, sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when adding the tv channel '%s'.\n\nSQLite has returned error :\n%s."), + name, sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); - }else{ - *id = sqlite3_last_insert_rowid(dbsync->db_link); - dbsync_link_tvchannel_to_channels (dbsync, label, *id, error); + } + + if(*error == NULL){ + // Get the insert id of the TV channel + id = sqlite3_last_insert_rowid(dbsync->db_link); + freetuxtv_tv_channel_infos_set_id(tv_channel_infos, id); + // Link channels who has close label + dbsync_link_tvchannel_to_channels_from_label (dbsync, name, id, error); + } + + if(*error == NULL){ + // Add the label of the TV channel + cur_label = freetuxtv_tv_channel_infos_get_labels(tv_channel_infos); + while(cur_label && *error == NULL){ + dbsync_add_label_tvchannel (dbsync, cur_label->data, id, error); + cur_label = cur_label->next; + } } } -void +static void dbsync_add_label_tvchannel (DBSync *dbsync, gchar* label, glong id_tvchannel, - GError** error) + GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -594,24 +634,26 @@ dbsync_add_label_tvchannel (DBSync *dbsync, gchar* label, glong id_tvchannel, gchar *db_err = NULL; int res; - // Add the label of channel logo + // Add an alternative label for the TV channel query = sqlite3_mprintf("INSERT INTO %s (%s, %s) values ('%q', '%ld');", - // INSERT INTO - DB_LABELTVCHANNEL, - // ( - DB_LABELTVCHANNEL_LABEL, DB_LABELTVCHANNEL_TVCHANNELID, - // ) VALUES ( - label, id_tvchannel); + // INSERT INTO + DB_LABELTVCHANNEL, + // ( + DB_LABELTVCHANNEL_LABEL, DB_LABELTVCHANNEL_TVCHANNELID, + // ) VALUES ( + label, id_tvchannel + // ) + ); res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); sqlite3_free(query); if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when adding the label of channel logo '%s'.\n\nSQLite has returned error :\n%s."), - label, sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when adding the label of channel logo '%s'.\n\nSQLite has returned error :\n%s."), + label, sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); }else{ - dbsync_link_tvchannel_to_channels (dbsync, label, id_tvchannel, error); + dbsync_link_tvchannel_to_channels_from_label (dbsync, label, id_tvchannel, error); } } @@ -641,7 +683,7 @@ on_exec_channel (void *data, int argc, char **argv, char **colsname) FreetuxTVChannelInfos* channel_infos; gchar** vlc_options; - + int id = g_ascii_strtoll (argv[0], NULL, 10); channel_infos = freetuxtv_channel_infos_new (argv[1], argv[3]); freetuxtv_channel_infos_set_id (channel_infos, id); @@ -649,7 +691,7 @@ on_exec_channel (void *data, int argc, char **argv, char **colsname) if(argv[2] != NULL){ freetuxtv_channel_infos_set_logo(channel_infos, argv[2]); } - + if(argv[4]){ vlc_options = g_strsplit(argv[4], "\n", 0); freetuxtv_channel_infos_set_vlcoptions(channel_infos, vlc_options); @@ -661,13 +703,13 @@ on_exec_channel (void *data, int argc, char **argv, char **colsname) int res = 0; res = cb_data->callback(cb_data->app, channel_infos, cb_data->dbsync, cb_data->user_data, cb_data->error); - + return res; } static void -dbsync_link_tvchannel_to_channels (DBSync *dbsync, gchar *label, glong id_tvchannel, - GError** error) +dbsync_link_tvchannel_to_channels_from_label (DBSync *dbsync, gchar *label, + glong id_tvchannel, GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(dbsync->db_link != NULL); @@ -678,21 +720,21 @@ dbsync_link_tvchannel_to_channels (DBSync *dbsync, gchar *label, glong id_tvchan gchar *db_err = NULL; int res; - // Link logo to channels + // Link TV channel to channels query = sqlite3_mprintf("UPDATE %s SET %s=%ld WHERE %s LIKE '%q%%';", - // UPDATE - DB_CHANNEL, - // SET - DB_CHANNEL_TVCHANNELID, id_tvchannel, - // WHERE - DB_CHANNEL_NAME, label); + // UPDATE + DB_CHANNEL, + // SET + DB_CHANNEL_TVCHANNELID, id_tvchannel, + // WHERE + DB_CHANNEL_NAME, label); res = sqlite3_exec(dbsync->db_link, query, NULL, NULL, &db_err); sqlite3_free(query); if(res != SQLITE_OK){ *error = g_error_new (FREETUXTV_DBSYNC_ERROR, - FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, - _("Error when linking the channel logo '%s'.\n\nSQLite has returned error :\n%s."), - label, sqlite3_errmsg(dbsync->db_link)); + FREETUXTV_DBSYNC_ERROR_EXEC_QUERY, + _("Error when linking the TV channel '%s' to channel.\n\nSQLite has returned error :\n%s."), + label, sqlite3_errmsg(dbsync->db_link)); sqlite3_free(db_err); } } diff --git a/src/freetuxtv-db-sync.h b/src/freetuxtv-db-sync.h index 8222f0f..907342b 100644 --- a/src/freetuxtv-db-sync.h +++ b/src/freetuxtv-db-sync.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8-*- */ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4-*- */ /* * FreetuxTV is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include "freetuxtv-i18n.h" #include "freetuxtv-channel-infos.h" #include "freetuxtv-channels-group-infos.h" +#include "freetuxtv-tv-channel-infos.h" typedef struct _DBSync DBSync; struct _DBSync @@ -57,54 +58,50 @@ dbsync_create_db (DBSync *dbsync, GError** error); void dbsync_select_channels_groups (DBSync *dbsync, - FreetuxTVApp *app, - int (*callback)(FreetuxTVApp *app, FreetuxTVChannelsGroupInfos* channels_group_infos, - DBSync *dbsync, gpointer user_data, GError** error), - gpointer user_data, GError** error); + FreetuxTVApp *app, + int (*callback)(FreetuxTVApp *app, FreetuxTVChannelsGroupInfos* channels_group_infos, + DBSync *dbsync, gpointer user_data, GError** error), + gpointer user_data, GError** error); void dbsync_select_channels_of_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - FreetuxTVApp *app, - int (*callback)(FreetuxTVApp *app, - FreetuxTVChannelInfos* channel_infos, - DBSync *dbsync, gpointer user_data, GError** error), - gpointer user_data, GError** error); + FreetuxTVChannelsGroupInfos* channels_group_infos, + FreetuxTVApp *app, + int (*callback)(FreetuxTVApp *app, + FreetuxTVChannelInfos* channel_infos, + DBSync *dbsync, gpointer user_data, GError** error), + gpointer user_data, GError** error); void dbsync_add_channel (DBSync *dbsync, - FreetuxTVChannelInfos* channel_infos, - GError** error); + FreetuxTVChannelInfos* channel_infos, + GError** error); void dbsync_add_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - GError** error); + FreetuxTVChannelsGroupInfos* channels_group_infos, + GError** error); void dbsync_update_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - GError** error); + FreetuxTVChannelsGroupInfos* channels_group_infos, + GError** error); void dbsync_delete_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - GError** error); + FreetuxTVChannelsGroupInfos* channels_group_infos, + GError** error); void dbsync_delete_channels_of_channels_group (DBSync *dbsync, - FreetuxTVChannelsGroupInfos* channels_group_infos, - GError** error); + FreetuxTVChannelsGroupInfos* channels_group_infos, + GError** error); void dbsync_delete_tvchannels (DBSync *dbsync, GError** error); void -dbsync_add_tvchannel (DBSync *dbsync, gchar* label, gchar* filename, - glong *id, GError** error); - -void -dbsync_add_label_tvchannel (DBSync *dbsync, gchar* label, glong id_tvchannel, - GError** error); +dbsync_add_tvchannel (DBSync *dbsync, FreetuxTVTvChannelInfos* tv_channel_infos, + GError** error); #endif /* FREETUXTV_DB_SYNC_H */ diff --git a/src/freetuxtv-logos-list.c b/src/freetuxtv-logos-list.c index d13d17b..b60d224 100644 --- a/src/freetuxtv-logos-list.c +++ b/src/freetuxtv-logos-list.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8-*- */ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4-*- */ /* * FreetuxTV is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,73 +23,86 @@ #include "freetuxtv-app.h" #include "freetuxtv-i18n.h" #include "freetuxtv-window-main.h" - +#include "freetuxtv-tv-channel-infos.h" typedef struct _CBXMLData { FreetuxTVApp *app; DBSync *dbsync; - long current_logo; + FreetuxTVTvChannelInfos *tv_channels_infos; } CBXMLData; static void xml_start_cb(GMarkupParseContext *context, - const gchar *element_name, - const gchar **attribute_names, - const gchar **attribute_values, - gpointer data, - GError **error); + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer data, + GError **error); + +static void +xml_end_cb(GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error); + +static void +xml_text_cb(GMarkupParseContext *context, + const gchar *text, + gsize text_len, + gpointer user_data, + GError **error); void logos_list_synchronize (FreetuxTVApp *app, DBSync *dbsync, - GError** error) + GError** error) { g_return_if_fail(dbsync != NULL); g_return_if_fail(error != NULL); - - // Mise à jour de la barre de statut + + // Update the status bar to the the process gchar *text; text = g_strdup_printf(_("Synchronizing the logo list")); windowmain_statusbar_push (app, "UpdateMsg", text); g_free(text); g_print("FreetuxTV : Synchronizing the logo list\n"); - // Efface les anciens logos + // Delete the TV channel in the database dbsync_delete_tvchannels (dbsync, error); if(*error == NULL){ - // Ajout de la liste des logos dans la base de donnée + // Add the list of TV channel in the data base for the XML file CBXMLData cbxmldata; cbxmldata.app = app; cbxmldata.dbsync = dbsync; - cbxmldata.current_logo = -1; - + cbxmldata.tv_channels_infos = NULL; + gsize filelen; - static GMarkupParser parser = { xml_start_cb, NULL, NULL, - NULL, NULL }; + static GMarkupParser parser = { xml_start_cb, xml_end_cb, xml_text_cb, + NULL, NULL }; GMarkupParseContext *context; - + context = g_markup_parse_context_new (&parser, - G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG, - &cbxmldata, NULL); + G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG, + &cbxmldata, NULL); gchar *xml_data; - g_file_get_contents (FREETUXTV_DIR "/channels_logos.xml", - &xml_data, &filelen, NULL); + g_file_get_contents (FREETUXTV_DIR "/tv_channels.xml", + &xml_data, &filelen, NULL); g_markup_parse_context_parse (context, xml_data, -1, error); } - + windowmain_statusbar_pop (app, "UpdateMsg"); } gchar* logos_list_get_channel_logo_filename(FreetuxTVApp *app, - FreetuxTVChannelInfos* channel_infos, - gboolean none_icon) + FreetuxTVChannelInfos* channel_infos, + gboolean none_icon) { gchar *imgfile = NULL; gchar *user_img_channels_dir; user_img_channels_dir = g_strconcat(g_get_user_config_dir(), - "/FreetuxTV/images/channels", NULL); + "/FreetuxTV/images/channels", NULL); if(channel_infos->logo_name == NULL){ if(none_icon){ imgfile = g_strconcat(user_img_channels_dir, "/_none.png", NULL); @@ -105,48 +118,79 @@ logos_list_get_channel_logo_filename(FreetuxTVApp *app, imgfile = g_strconcat(FREETUXTV_DIR "/images/channels/", channel_infos->logo_name, NULL); } } - + g_free(user_img_channels_dir); - + return imgfile; } static void xml_start_cb(GMarkupParseContext *context, - const gchar *element_name, - const gchar **attribute_names, - const gchar **attribute_values, - gpointer data, - GError **error) + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer data, + GError **error) { - CBXMLData* cbxmldata = (CBXMLData*)data; - - gchar *label = NULL; - gchar *filename = NULL; - - if(g_ascii_strcasecmp(element_name, "logo") == 0){ - label = g_strdup(attribute_values[1]); - filename = g_strdup(attribute_values[0]); - dbsync_add_tvchannel (cbxmldata->dbsync, label, filename, - &(cbxmldata->current_logo), error); - g_free(filename); - + + gchar *name = NULL; + + if(g_ascii_strcasecmp(element_name, "tvchannel") == 0){ + name = (gchar*)attribute_values[0]; + cbxmldata->tv_channels_infos = freetuxtv_tv_channel_infos_new(name); } - if(g_ascii_strcasecmp(element_name, "logolabel") == 0){ - label = g_strdup(attribute_values[0]); - dbsync_add_label_tvchannel (cbxmldata->dbsync, label, - cbxmldata->current_logo, error); - } - - if(label != NULL){ + if(name != NULL){ if(cbxmldata->app->debug == TRUE){ g_print("FreetuxTV-debug : Add channel logos '%s' in database\n", - label); + name); + } + } +} + +static void +xml_end_cb(GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error) +{ + CBXMLData* cbxmldata = (CBXMLData*)user_data; + + FreetuxTVTvChannelInfos *tv_channels_infos = NULL; + + if(g_ascii_strcasecmp(element_name, "tvchannel") == 0){ + tv_channels_infos = cbxmldata->tv_channels_infos; + if(tv_channels_infos){ + // We have a channel pending, we add it in database + dbsync_add_tvchannel (cbxmldata->dbsync, tv_channels_infos, error); + + g_object_unref(cbxmldata->tv_channels_infos); + cbxmldata->tv_channels_infos = NULL; } + } +} - g_free(label); - label = NULL; +static void +xml_text_cb(GMarkupParseContext *context, + const gchar *text, + gsize text_len, + gpointer user_data, + GError **error) +{ + CBXMLData* cbxmldata = (CBXMLData*)user_data; + + const gchar *element_name; + element_name = g_markup_parse_context_get_element(context); + + // Add the logo filename + if(g_ascii_strcasecmp(element_name, "logo_filename") == 0){ + freetuxtv_tv_channel_infos_set_logo_filename(cbxmldata->tv_channels_infos, (gchar*) text); + } + + // Add a label for the channel + if(g_ascii_strcasecmp(element_name, "label") == 0){ + freetuxtv_tv_channel_infos_add_label(cbxmldata->tv_channels_infos, (gchar*) text); } + } diff --git a/src/freetuxtv-logos-list.h b/src/freetuxtv-logos-list.h index e9cf2f6..47b803c 100644 --- a/src/freetuxtv-logos-list.h +++ b/src/freetuxtv-logos-list.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8-*- */ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4-*- */ /* * FreetuxTV is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/freetuxtv-tv-channel-infos.c b/src/freetuxtv-tv-channel-infos.c new file mode 100644 index 0000000..cbac6ee --- /dev/null +++ b/src/freetuxtv-tv-channel-infos.c @@ -0,0 +1,224 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * freetuxtv + * Copyright (C) Eric Beuque 2010 + * + * freetuxtv is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * freetuxtv is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "freetuxtv-tv-channel-infos.h" + +typedef struct _FreetuxTVTvChannelInfosPrivate FreetuxTVTvChannelInfosPrivate; +struct _FreetuxTVTvChannelInfosPrivate +{ + gint id; + + gchar* name; + + gchar* logo_filename; + + GList* labels; +}; + +#define FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FREETUXTV_TYPE_TV_CHANNEL_INFOS, FreetuxTVTvChannelInfosPrivate)) + + + +G_DEFINE_TYPE (FreetuxTVTvChannelInfos, freetuxtv_tv_channel_infos, G_TYPE_OBJECT); + +static void +freetuxtv_tv_channel_infos_init (FreetuxTVTvChannelInfos *object) +{ + FreetuxTVTvChannelInfosPrivate* priv; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(object); + + priv->id = -1; + priv->name = NULL; + + priv->labels = NULL; +} + +static void +freetuxtv_tv_channel_infos_finalize (GObject *object) +{ + FreetuxTVTvChannelInfosPrivate* priv; + gchar* text; + GList* list_tmp; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(object); + + if(priv->name){ + g_free(priv->name); + priv->name = NULL; + } + + list_tmp = priv->labels; + while(list_tmp){ + text = (gchar*) list_tmp->data; + g_free(text); + list_tmp->data = NULL; + list_tmp = list_tmp->next; + } + if(priv->labels){ + g_list_free(priv->labels); + priv->labels = NULL; + } + + G_OBJECT_CLASS (freetuxtv_tv_channel_infos_parent_class)->finalize (object); +} + +static void +freetuxtv_tv_channel_infos_class_init (FreetuxTVTvChannelInfosClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); +// GObjectClass* parent_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (FreetuxTVTvChannelInfosPrivate)); + + object_class->finalize = freetuxtv_tv_channel_infos_finalize; +} + +FreetuxTVTvChannelInfos* +freetuxtv_tv_channel_infos_new(gchar* name) +{ + FreetuxTVTvChannelInfos* tv_channel_infos; + FreetuxTVTvChannelInfosPrivate* priv; + + tv_channel_infos = g_object_new (FREETUXTV_TYPE_TV_CHANNEL_INFOS, NULL); + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + priv->name = g_strdup(name); + + return tv_channel_infos; +} + +void +freetuxtv_tv_channel_infos_set_id(FreetuxTVTvChannelInfos* tv_channel_infos, gint id) +{ + g_return_if_fail(tv_channel_infos != NULL); + g_return_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos)); + + FreetuxTVTvChannelInfosPrivate* priv; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + priv->id = id; +} + +gint +freetuxtv_tv_channel_infos_get_id(FreetuxTVTvChannelInfos* tv_channel_infos) +{ + g_return_val_if_fail(tv_channel_infos != NULL, -1); + g_return_val_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos), -1); + + FreetuxTVTvChannelInfosPrivate* priv; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + return priv->id; + +} + +void +freetuxtv_tv_channel_infos_set_name(FreetuxTVTvChannelInfos* tv_channel_infos, gchar* name) +{ + g_return_if_fail(tv_channel_infos != NULL); + g_return_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos)); + + FreetuxTVTvChannelInfosPrivate* priv; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + if(priv->name){ + g_free(priv->name); + priv->name = NULL; + } + + priv->name = g_strdup(name); +} + +const gchar* +freetuxtv_tv_channel_infos_get_name(FreetuxTVTvChannelInfos* tv_channel_infos) +{ + g_return_val_if_fail(tv_channel_infos != NULL, NULL); + g_return_val_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos), NULL); + + FreetuxTVTvChannelInfosPrivate* priv; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + return priv->name; +} + +void +freetuxtv_tv_channel_infos_set_logo_filename(FreetuxTVTvChannelInfos* tv_channel_infos, gchar* logo_filename) +{ + g_return_if_fail(tv_channel_infos != NULL); + g_return_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos)); + + FreetuxTVTvChannelInfosPrivate* priv; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + if(priv->logo_filename){ + g_free(priv->logo_filename); + priv->logo_filename = NULL; + } + + priv->logo_filename = g_strdup(logo_filename); +} + +const gchar* +freetuxtv_tv_channel_infos_get_logo_filename(FreetuxTVTvChannelInfos* tv_channel_infos) +{ + g_return_val_if_fail(tv_channel_infos != NULL, NULL); + g_return_val_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos), NULL); + + FreetuxTVTvChannelInfosPrivate* priv; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + return priv->logo_filename; +} + +void +freetuxtv_tv_channel_infos_add_label(FreetuxTVTvChannelInfos* tv_channel_infos, gchar *label) +{ + g_return_val_if_fail(tv_channel_infos != NULL, NULL); + g_return_val_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos), NULL); + + FreetuxTVTvChannelInfosPrivate* priv; + gchar* text; + + text = g_strdup(label); + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + priv->labels = g_list_append (priv->labels, text); +} + +GList* +freetuxtv_tv_channel_infos_get_labels(FreetuxTVTvChannelInfos* tv_channel_infos) +{ + g_return_val_if_fail(tv_channel_infos != NULL, NULL); + g_return_val_if_fail(FREETUXTV_IS_TV_CHANNEL_INFOS(tv_channel_infos), NULL); + + FreetuxTVTvChannelInfosPrivate* priv; + + priv = FREETUXTV_TV_CHANNEL_INFOS_PRIVATE(tv_channel_infos); + + return priv->labels; +} \ No newline at end of file diff --git a/src/freetuxtv-tv-channel-infos.h b/src/freetuxtv-tv-channel-infos.h new file mode 100644 index 0000000..fa979e8 --- /dev/null +++ b/src/freetuxtv-tv-channel-infos.h @@ -0,0 +1,78 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * freetuxtv + * Copyright (C) Eric Beuque 2010 + * + * freetuxtv is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * freetuxtv is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _FREETUXTV_TV_CHANNEL_INFOS_H_ +#define _FREETUXTV_TV_CHANNEL_INFOS_H_ + +#include + +G_BEGIN_DECLS + +#define FREETUXTV_TYPE_TV_CHANNEL_INFOS (freetuxtv_tv_channel_infos_get_type ()) +#define FREETUXTV_TV_CHANNEL_INFOS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FREETUXTV_TYPE_TV_CHANNEL_INFOS, FreetuxtvTvChannelInfos)) +#define FREETUXTV_TV_CHANNEL_INFOS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FREETUXTV_TYPE_TV_CHANNEL_INFOS, FreetuxtvTvChannelInfosClass)) +#define FREETUXTV_IS_TV_CHANNEL_INFOS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FREETUXTV_TYPE_TV_CHANNEL_INFOS)) +#define FREETUXTV_IS_TV_CHANNEL_INFOS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FREETUXTV_TYPE_TV_CHANNEL_INFOS)) +#define FREETUXTV_TV_CHANNEL_INFOS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FREETUXTV_TYPE_TV_CHANNEL_INFOS, FreetuxtvTvChannelInfosClass)) + +typedef struct _FreetuxTVTvChannelInfosClass FreetuxTVTvChannelInfosClass; +typedef struct _FreetuxTVTvChannelInfos FreetuxTVTvChannelInfos; + +struct _FreetuxTVTvChannelInfosClass +{ + GObjectClass parent_class; +}; + +struct _FreetuxTVTvChannelInfos +{ + GObject parent_instance; +}; + +GType freetuxtv_tv_channel_infos_get_type (void) G_GNUC_CONST; + +FreetuxTVTvChannelInfos* +freetuxtv_tv_channel_infos_new(gchar* name); + +void +freetuxtv_tv_channel_infos_set_id(FreetuxTVTvChannelInfos* tv_channel_infos, gint id); + +gint +freetuxtv_tv_channel_infos_get_id(FreetuxTVTvChannelInfos* tv_channel_infos); + +void +freetuxtv_tv_channel_infos_set_name(FreetuxTVTvChannelInfos* tv_channel_infos, gchar* name); + +const gchar* +freetuxtv_tv_channel_infos_get_name(FreetuxTVTvChannelInfos* tv_channel_infos); + +void +freetuxtv_tv_channel_infos_set_logo_filename(FreetuxTVTvChannelInfos* tv_channel_infos, gchar* logo_filename); + +const gchar* +freetuxtv_tv_channel_infos_get_logo_filename(FreetuxTVTvChannelInfos* tv_channel_infos); + +void +freetuxtv_tv_channel_infos_add_label(FreetuxTVTvChannelInfos* tv_channel_infos, gchar *label); + +GList* +freetuxtv_tv_channel_infos_get_labels(FreetuxTVTvChannelInfos* tv_channel_infos); + +G_END_DECLS + +#endif /* _FREETUXTV_TV_CHANNEL_INFOS_H_ */ diff --git a/src/freetuxtv-window-main.c b/src/freetuxtv-window-main.c index f6b07af..543f412 100644 --- a/src/freetuxtv-window-main.c +++ b/src/freetuxtv-window-main.c @@ -31,7 +31,6 @@ #include "freetuxtv-logos-list.h" #include "freetuxtv-db-sync.h" #include "freetuxtv-models.h" -#include "gtk-libvlc-media-player.h" static gboolean on_windowmain_deleteevent (GtkWidget *widget, GdkEvent *event, gpointer *data); @@ -45,8 +44,8 @@ on_windowmain_menuitemgroupsadd_activate (GtkMenuItem *menuitem, gpointer user_data); static void -on_windowmain_menuitemupdatelogos_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_windowmain_menuitemupdatetvchannels_activate (GtkMenuItem *menuitem, + gpointer user_data); static void on_windowmain_menuitemquit_activate (GtkMenuItem *menuitem, @@ -207,11 +206,11 @@ windowmain_init(FreetuxTVApp *app) "activate", G_CALLBACK(on_windowmain_menuitemgroupsadd_activate), app); - p_menu_item = gtk_menu_item_new_with_mnemonic (_("_Update logos list")); + p_menu_item = gtk_menu_item_new_with_mnemonic (_("_Update TV channels list")); gtk_menu_shell_append (GTK_MENU_SHELL (p_menu), p_menu_item); g_signal_connect(G_OBJECT(p_menu_item), "activate", - G_CALLBACK(on_windowmain_menuitemupdatelogos_activate), + G_CALLBACK(on_windowmain_menuitemupdatetvchannels_activate), app); // End Menu : Channels @@ -974,8 +973,8 @@ on_windowmain_menuitemgroupsadd_activate (GtkMenuItem *menuitem, } static void -on_windowmain_menuitemupdatelogos_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_windowmain_menuitemupdatetvchannels_activate (GtkMenuItem *menuitem, + gpointer user_data) { FreetuxTVApp *app = (FreetuxTVApp *) user_data; @@ -983,7 +982,7 @@ on_windowmain_menuitemupdatelogos_activate (GtkMenuItem *menuitem, DBSync dbsync; dbsync_open_db (&dbsync, &error); - + if(error == NULL){ logos_list_synchronize (app, &dbsync, &error); } @@ -993,7 +992,7 @@ on_windowmain_menuitemupdatelogos_activate (GtkMenuItem *menuitem, } dbsync_close_db(&dbsync); - + if(error != NULL){ windowmain_show_gerror (app, error); g_error_free (error);