# HG changeset patch
# User rosfran
# Date 1165436568 0
# Node ID c3c073032757c459a52b3401201cf85559c6750b
# Parent  6b697111497bab912cc7d817a445ac04e49be2f7
[svn r209] Removed gmyth_settings, put gmyth_backend* functions.

diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_epg_grid_widget.c
--- a/maemo-ui/src/mmyth_epg_grid_widget.c	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_epg_grid_widget.c	Wed Dec 06 20:22:48 2006 +0000
@@ -37,6 +37,8 @@
     GList * channel_list;
     
     GMythEPG *mmyth_epg;
+
+    GMythBackendInfo *backend_info;
     
     gint DISPLAY_CHANS;
 };
@@ -103,10 +105,13 @@
     private->current_end_time = time(&cur_time) + 10800;   
     
     private->DISPLAY_CHANS = MAX_DISPLAY_CHANS;
-    
+
+    private->backend_info = gmyth_backend_info_new_full ( "192.168.1.109", "mythtv",
+    	"mythtv", "mythconverg", 6543 );
+
     // TODO: Close the epg and unref it in dispose call
     private->mmyth_epg = gmyth_epg_new ();
-    if (!gmyth_epg_connect (private->mmyth_epg)) {
+    if (!gmyth_epg_connect (private->mmyth_epg, private->backend_info)) {
     	g_warning ("[%s] Could not connect mysql handler to db", __FUNCTION__);
     	g_object_unref (private->mmyth_epg);
     	private->mmyth_epg = NULL;
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_epg_grid_widget.h
--- a/maemo-ui/src/mmyth_epg_grid_widget.h	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_epg_grid_widget.h	Wed Dec 06 20:22:48 2006 +0000
@@ -6,8 +6,8 @@
 #include <gtk/gtkvbox.h>
 #include <gtk/gtkeventbox.h>
 
-#include "gmyth_common.h"
-
+#include <gmyth/gmyth_common.h>
+#include <gmyth/gmyth_backendinfo.h>
 #define MAX_DISPLAY_CHANS 4
 
 G_BEGIN_DECLS
@@ -45,6 +45,7 @@
 
     /* Selected Schedule Item*/
     GList *selected_grid_item;  
+
 };
 
 
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_main.c
--- a/maemo-ui/src/mmyth_main.c	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_main.c	Wed Dec 06 20:22:48 2006 +0000
@@ -8,11 +8,11 @@
 #include "hildon-widgets/hildon-window.h"
 #endif
 
-#include "gmyth_recorder.h"
-#include "gmyth_settings.h"
-#include "gmyth_context.h"
-#include "gmyth_tvchain.h"
-#include "gmyth_remote_util.h"
+#include <gmyth/gmyth_recorder.h>
+#include <gmyth/gmyth_settings.h>
+#include <gmyth/gmyth_context.h>
+#include <gmyth/gmyth_tvchain.h>
+#include <gmyth/gmyth_remote_util.h>
 
 #include "mmyth_ui.h"
 #include "mmyth_tvplayer.h"
@@ -63,8 +63,7 @@
 #endif
 
     /* Init libmmyth context */
-    gmyth_context_initialize ();
-	
+	/* TODO */
 #ifndef MAEMO_PLATFORM
     /* create the main window */
     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_recordui.c
--- a/maemo-ui/src/mmyth_recordui.c	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_recordui.c	Wed Dec 06 20:22:48 2006 +0000
@@ -262,7 +262,7 @@
   	recordui->scheduler = gmyth_scheduler_new ();
     
     /* init connection to the backend */
-    gmyth_scheduler_connect (recordui->scheduler);
+    gmyth_scheduler_connect (recordui->scheduler, recordui->scheduler->backend_info);
     
 	return recordui;
 }
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_schedulerui.c
--- a/maemo-ui/src/mmyth_schedulerui.c	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_schedulerui.c	Wed Dec 06 20:22:48 2006 +0000
@@ -191,7 +191,7 @@
     /* FIXME: Architecture change to reuse the scheduler created in the recordui! */
     scheduler = gmyth_scheduler_new ();
 
-    gmyth_scheduler_connect(scheduler);
+    gmyth_scheduler_connect(scheduler, scheduler->backend_info);
 
     /* FIXME: set record_id = -1 to add a new schedule */
     schedule_info->record_id = -1;
@@ -235,7 +235,7 @@
 	gtk_box_pack_start (GTK_BOX (hbox), combobox, FALSE, FALSE, 0);
 			
 	GMythEPG *mmyth_epg = gmyth_epg_new ();
-	if (!gmyth_epg_connect (mmyth_epg)) {
+	if (!gmyth_epg_connect (mmyth_epg, mmyth_epg->sqlquery->backend_info)) {
 		// FIXME: Without this list the scheduler UI should not be shown!
 		g_warning ("[%s] Error when getting list of channels", __FUNCTION__);
 	}
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_tvplayer.c
--- a/maemo-ui/src/mmyth_tvplayer.c	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_tvplayer.c	Wed Dec 06 20:22:48 2006 +0000
@@ -30,8 +30,9 @@
  
 #include <gdk/gdkx.h>
 
-#include "gmyth_context.h"
-#include "gmyth_remote_util.h"
+#include <gmyth/gmyth_remote_util.h>
+
+#define MYTHTV_VERSION_DEFAULT	30
 
 typedef struct _GstPlayerWindowStateChange
 {
@@ -73,10 +74,10 @@
 {
 	GObjectClass *gobject_class;
 
-    gobject_class = (GObjectClass *) klass;
-	
-    gobject_class->dispose  = mmyth_tvplayer_dispose;
-    gobject_class->finalize = mmyth_tvplayer_finalize;	
+	gobject_class = (GObjectClass *) klass;
+
+	gobject_class->dispose  = mmyth_tvplayer_dispose;
+	gobject_class->finalize = mmyth_tvplayer_finalize;	
 }
 
 static void
@@ -214,15 +215,16 @@
  * successfully, FALSE otherwise.
  */
 gboolean
-mmyth_tvplayer_initialize (MMythTVPlayer *tvplayer)
+mmyth_tvplayer_initialize (MMythTVPlayer *tvplayer, GMythBackendInfo *backend_info)
 {
-	
-    if (!mmyth_tvplayer_create_pipeline (tvplayer)) {
-    	g_warning ("[%s] Error while creating pipeline. TV Player not initialized", __FUNCTION__);
+	tvplayer->backend_info = backend_info;
+
+	if (!mmyth_tvplayer_create_pipeline (tvplayer)) {
+		g_warning ("[%s] Error while creating pipeline. TV Player not initialized", __FUNCTION__);
 		return FALSE;
 	} else {
 		g_debug ("[%s] GStreamer pipeline created", __FUNCTION__);	
-    }
+	}
 
 	return TRUE;
 }
@@ -317,7 +319,7 @@
     g_object_ref (tvplayer->audioqueue1);
     g_object_ref (tvplayer->audioqueue2);
   	
-    g_object_set (G_OBJECT (videosink), "sync", TRUE, NULL);
+    //g_object_set (G_OBJECT (videosink), "sync", TRUE, NULL);
     g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
 
     gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (tvplayer->gst_pipeline)),
@@ -353,14 +355,12 @@
 gboolean
 mmyth_tvplayer_record_setup (MMythTVPlayer *tvplayer, gchar *filename)
 {
-	GMythSettings *msettings = gmyth_context_get_settings();
-	
 	// FIXME: we should receive the uri instead of filename
-	GString *hostname = gmyth_settings_get_backend_hostname (msettings);
-	int port = gmyth_settings_get_backend_port(msettings);
+	gchar *hostname = gmyth_backend_info_get_hostname (tvplayer->backend_info);
+	gint port = gmyth_backend_info_get_port(tvplayer->backend_info);
 	
 	GString *fullpath = g_string_new ("myth://");
-	g_string_append_printf (fullpath, "%s:%d/%s", hostname->str, port, filename);
+	g_string_append_printf (fullpath, "%s:%d/%s", hostname, port, filename);
 	
 	tvplayer->is_livetv = FALSE;
 
@@ -381,90 +381,24 @@
 gboolean
 mmyth_tvplayer_livetv_setup (MMythTVPlayer *tvplayer)
 {
-	GMythSettings *msettings = gmyth_context_get_settings ();
 	gboolean res = TRUE;
+	gchar *hostname;
 
-	res = gmyth_context_check_connection();
-	if (!res) {
-		g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);	
-		res = FALSE;
+	tvplayer->livetv = gmyth_livetv_new ();
+
+	if ( !gmyth_livetv_setup( tvplayer->livetv, tvplayer->backend_info ) )
 		goto error;
-	}
-
-	tvplayer->backend_hostname = gmyth_settings_get_backend_hostname(msettings);
-	tvplayer->backend_port = gmyth_settings_get_backend_port (msettings);
-
-	tvplayer->local_hostname  = g_string_new("");    
-	gmyth_context_get_local_hostname (tvplayer->local_hostname);
-
-	if ( tvplayer->local_hostname == NULL ) {
-		res = FALSE;
-		goto error;
-	}
-
-	// Gets the remote encoder num
-	tvplayer->recorder = remote_request_next_free_recorder (-1);
-
-	if ( tvplayer->recorder == NULL ) {
-		g_warning ("[%s] None remote encoder available", __FUNCTION__);
-		res = FALSE;
-		goto error;
-	}
-
-	// Creates livetv chain handler
-	tvplayer->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
-	gmyth_tvchain_initialize ( tvplayer->tvchain, tvplayer->local_hostname );
-
-	if ( tvplayer->tvchain == NULL || tvplayer->tvchain->tvchain_id == NULL ) {
-		res = FALSE;
-		goto error;
-	}
-
-	// Init remote encoder. Opens its control socket.
-	res = gmyth_recorder_setup(tvplayer->recorder);
-	if ( !res ) {
-		g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
-		res = FALSE;
-		goto error;
-	}
-	// Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
-	res = gmyth_recorder_spawntv ( tvplayer->recorder,
-			gmyth_tvchain_get_id(tvplayer->tvchain) );
-	if (!res) {
-		g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
-		res = FALSE;
-		goto error;
-	}
-
-	// Reload all TV chain from Mysql database.
-	gmyth_tvchain_reload_all (tvplayer->tvchain);
-
-	if ( tvplayer->tvchain == NULL ) {
-		res = FALSE;
-		goto error;
-	}
-
-	// Get program info from database using chanid and starttime
-	tvplayer->proginfo = gmyth_tvchain_get_program_at (tvplayer->tvchain, -1);
-	if ( tvplayer->proginfo == NULL ) {
-		g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ );
-		res = FALSE;
-		goto error;
-	} else {
-		g_debug ("[%s] MythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ );
-	}
-
+	
 	return res;
 
 error:
-	if ( tvplayer->backend_hostname != NULL ) {
-		g_string_free( tvplayer->backend_hostname, TRUE );
-		res = FALSE;
+	res = FALSE;
+	if ( tvplayer->livetv != NULL ) {
+		g_object_unref( tvplayer->livetv );
 	}
 
 	if ( tvplayer->local_hostname != NULL ) {
 		g_string_free( tvplayer->local_hostname, TRUE );
-		res = FALSE;
 	}
 
 	if ( tvplayer->recorder != NULL ) {
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_tvplayer.h
--- a/maemo-ui/src/mmyth_tvplayer.h	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_tvplayer.h	Wed Dec 06 20:22:48 2006 +0000
@@ -36,9 +36,10 @@
 #include <gst/gst.h>
 #include <gst/interfaces/xoverlay.h>
 
-#include "gmyth_recorder.h"
-#include "gmyth_tvchain.h"
-#include "gmyth_common.h"
+#include <gmyth/gmyth_recorder.h>
+#include <gmyth/gmyth_tvchain.h>
+#include <gmyth/gmyth_common.h>
+#include <gmyth/gmyth_livetv.h>
 
 G_BEGIN_DECLS
 
@@ -88,6 +89,9 @@
 	GMythRecorder *recorder;
 	GMythTVChain *tvchain;
 	GMythProgramInfo *proginfo;
+	GMythLiveTV *livetv;
+
+	GMythBackendInfo *backend_info;
 	
 	gboolean is_livetv;
 };
@@ -96,7 +100,7 @@
 GType          mmyth_tvplayer_get_type (void);
 
 MMythTVPlayer* mmyth_tvplayer_new ();
-gboolean       mmyth_tvplayer_initialize (MMythTVPlayer *tvplayer);
+gboolean       mmyth_tvplayer_initialize (MMythTVPlayer *tvplayer, GMythBackendInfo *backend_info);
 
 void           mmyth_tvplayer_start_playing   (MMythTVPlayer *tvplayer);
 void           mmyth_tvplayer_stop_playing    (MMythTVPlayer *tvplayer);
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_ui.c
--- a/maemo-ui/src/mmyth_ui.c	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_ui.c	Wed Dec 06 20:22:48 2006 +0000
@@ -19,7 +19,6 @@
 #include "mmyth_tvplayer.h"
 
 /* GMyth library includes */
-#include "gmyth_context.h"
 
 #ifndef MAEMO_PLATFORM
 static gint button_press_handler (GtkWidget *widget, GdkEvent *event);
@@ -57,6 +56,8 @@
 
     mmyth_ui = g_new0 (MMythUi, 1);
 
+    mmyth_ui->backend_info = gmyth_backend_info_new_full( "192.168.1.109", "mythtv", "mythtv", "mythconverg", 6543 );
+
     mmyth_ui->main_window = main_window;    
     mmyth_ui->videow = NULL;
     mmyth_ui->mmyth_recordui = NULL;
@@ -215,7 +216,7 @@
     if (mmyth_uisettings_run (GTK_WINDOW (mmyth_ui->main_window))) {
     	// If user changes the settings, we restart the context
     	g_debug ("[%s] Restarting mmyth_context to new settings", __FUNCTION__);
-    	gmyth_context_initialize();
+    	//gmyth_context_initialize();
     }
 }
 
@@ -313,7 +314,7 @@
 	/* choose here if this is a LiveTV session */
 	mmyth_ui->tvplayer->is_livetv = TRUE;
 
-	res = mmyth_tvplayer_initialize (mmyth_ui->tvplayer);
+	res = mmyth_tvplayer_initialize (mmyth_ui->tvplayer, mmyth_ui->backend_info);
 
 	if (!res) {
 		g_warning ("[%s] Could not initialize tvplayer", __FUNCTION__);
@@ -596,7 +597,7 @@
 	// Creates the tv player that will retrieve the mythtv content, decode and show it
 	mmyth_ui->tvplayer = mmyth_tvplayer_new ();
 	g_debug ("[%s] New TV Player created: %d\n", __FUNCTION__, (int) (mmyth_ui->tvplayer));
-	res = mmyth_tvplayer_initialize (mmyth_ui->tvplayer);
+	res = mmyth_tvplayer_initialize (mmyth_ui->tvplayer, mmyth_ui->backend_info);
 	if (!res) {
 		g_warning ("[%s] Could not initialize tvplayer", __FUNCTION__);
 
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_ui.h
--- a/maemo-ui/src/mmyth_ui.h	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_ui.h	Wed Dec 06 20:22:48 2006 +0000
@@ -16,6 +16,9 @@
 #include "mmyth_schedulerui.h"
 #include "mmyth_tvplayer.h"
 
+/* GMyth specific includes */
+#include <gmyth/gmyth_backendinfo.h>
+
 typedef struct _MMythUi
 {
 
@@ -34,6 +37,8 @@
     MMythUiCommon *epg_grid_uicommon;
     MMythUiCommon *record_uicommon;
     MMythUiCommon *schedule_uicommon;
+
+    GMythBackendInfo *backend_info;
     
     GtkWidget *videow;
     int idle_id;
diff -r 6b697111497b -r c3c073032757 maemo-ui/src/mmyth_uisettings.c
--- a/maemo-ui/src/mmyth_uisettings.c	Wed Dec 06 17:59:09 2006 +0000
+++ b/maemo-ui/src/mmyth_uisettings.c	Wed Dec 06 20:22:48 2006 +0000
@@ -9,7 +9,7 @@
 
 #include "mmyth_uisettings.h"
 
-#include "gmyth_context.h"
+#include <gmyth/gmyth_backendinfo.h>
 
 static GtkWidget *settings_dialog;
 static GtkWidget *entry_hostname;
@@ -19,12 +19,13 @@
 static GtkWidget *entry_port;
 
 static void settings_dialog_update_data (void);
-static GtkWidget* add_entry_to_table (GtkWidget *table, GString *init_str,
+static GtkWidget* add_entry_to_table (GtkWidget *table, const gchar *init_str,
 	guint pos_left, guint pos_right, guint pos_top, guint pos_bottom);
 static GtkWidget* add_label_to_table (GtkWidget *table, const gchar *str, 
 	guint pos_left, guint pos_right,  guint pos_top, guint pos_bottom);
 	
-	
+static GMythBackendInfo *backend_info = NULL;
+
 gboolean
 mmyth_uisettings_run (GtkWindow *main_window)
 {
@@ -33,7 +34,8 @@
 	GtkWidget *label_hostname, *label_dbname;
 	GtkWidget *label_username, *label_passwd, *label_port;
 
-	GMythSettings *msettings = gmyth_context_get_settings();
+	backend_info = gmyth_backend_info_new_full( "192.168.1.109", "mythtv", 
+			"mythtv", "mythconverg", 6543 );
 	
 	settings_dialog = gtk_dialog_new_with_buttons ("Settings",
                                          main_window,
@@ -72,24 +74,20 @@
 	label_port = add_label_to_table (settings_table, "Server port:", 0, 1, 4, 5);
 	
 	entry_hostname = add_entry_to_table (settings_table,
-		gmyth_settings_get_backend_hostname (msettings),
+		gmyth_backend_info_get_hostname (backend_info),
 		1, 2, 0, 1);
 	entry_dbname = add_entry_to_table (settings_table,
-		gmyth_settings_get_dbname (msettings),
+		gmyth_backend_info_get_db_name (backend_info),
 		1, 2, 1, 2 );
 	entry_username = add_entry_to_table (settings_table,
-		gmyth_settings_get_username (msettings),
+		gmyth_backend_info_get_username (backend_info),
 		1, 2, 2, 3 );
 	entry_passwd = add_entry_to_table (settings_table,
-		gmyth_settings_get_password (msettings),
+		gmyth_backend_info_get_password (backend_info),
 		1, 2, 3, 4 );
 		
-	GString *str_port = g_string_new ("");
-	g_string_printf (str_port, "%d", 
-		gmyth_settings_get_backend_port (msettings));
-	entry_port = add_entry_to_table (settings_table, str_port,
+	entry_port = add_entry_to_table (settings_table, g_strdup_printf( "%d", gmyth_backend_info_get_port (backend_info) ),
 		1, 2, 4, 5 );
-	g_string_free (str_port, TRUE);
 		
 	if (gtk_dialog_run (GTK_DIALOG (settings_dialog)) == GTK_RESPONSE_ACCEPT) {
 		settings_dialog_update_data ();
@@ -120,7 +118,7 @@
 }
 
 static GtkWidget*
-add_entry_to_table (GtkWidget *table, GString *init_str, guint pos_left, guint pos_right,
+add_entry_to_table (GtkWidget *table, const gchar *init_str, guint pos_left, guint pos_right,
 		guint pos_top, guint pos_bottom)
 {
 	GtkWidget *tmp_entry = gtk_entry_new ();
@@ -130,7 +128,7 @@
                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions) (0), 0, 0);
     if (init_str)
-		gtk_entry_set_text (GTK_ENTRY (tmp_entry), (init_str->str));
+		gtk_entry_set_text (GTK_ENTRY (tmp_entry), init_str);
 		
 	//gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
 	
@@ -141,29 +139,24 @@
 settings_dialog_update_data (void) 
 {
 	GString *tmp_entry_text;
-	GMythSettings *msettings = gmyth_context_get_settings();
+	//GMythSettings *backend_info = gmyth_context_get_settings();
 	
-	if (!msettings) {
+	if (!backend_info) {
 		g_warning ("[%s] Could not get GMythSettings instance from context\n", __FUNCTION__);
 		return;
 	}
 		
-	tmp_entry_text = g_string_new("");
-	g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_hostname)));
-	gmyth_settings_set_backend_hostname(msettings, tmp_entry_text);
+	gmyth_backend_info_set_hostname(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_hostname) ));
 	
-	g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_dbname)));
-	gmyth_settings_set_dbname(msettings, tmp_entry_text);
+	gmyth_backend_info_set_db_name(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_dbname)));
 	
-	g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_username)));
-	gmyth_settings_set_username(msettings, tmp_entry_text);
+	gmyth_backend_info_set_username(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_username)));
+
+	gmyth_backend_info_set_password(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_passwd)));
 	
-	g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_passwd)));
-	gmyth_settings_set_password(msettings, tmp_entry_text);	
+	gmyth_backend_info_set_port(backend_info, (gint)g_ascii_strtoull( gtk_entry_get_text( GTK_ENTRY(entry_port) ), 
+				NULL, 10) );
 	
-	g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_port)));
-	gmyth_settings_set_backend_port(msettings, atoi(tmp_entry_text->str));
-	
-	gmyth_settings_save (msettings);
+	//gmyth_backend_info_save (backend_info);
 	
 }