1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/maemo-ui/src/mmyth_recordui.c Wed Nov 15 18:07:23 2006 +0000
1.3 @@ -0,0 +1,332 @@
1.4 +#include<gtk/gtk.h>
1.5 +#include<glib.h>
1.6 +#include <sys/types.h>
1.7 +#include <sys/stat.h>
1.8 +#include <unistd.h>
1.9 +#include <string.h>
1.10 +#include <stdio.h>
1.11 +#include <stdlib.h>
1.12 +
1.13 +#include "mmyth_ui.h"
1.14 +#include "mmyth_recordui.h"
1.15 +
1.16 +/* GMyth library includes */
1.17 +#include "gmyth_scheduler.h"
1.18 +#include "gmyth_util.h"
1.19 +
1.20 +enum {
1.21 + START_DATE_COLUMN = 0,
1.22 + TITLE_COLUMN,
1.23 + CHAN_ID_COLUMN,
1.24 + END_TIME_COLUMN,
1.25 + RECORD_ID_COLUMN,
1.26 + BASENAME_COLUMN,
1.27 + N_COLUMNS
1.28 +};
1.29 +
1.30 +gboolean
1.31 +mmyth_recordui_reload_all (MMythRecordUI *recordui)
1.32 +{
1.33 + gboolean res = FALSE;
1.34 +
1.35 + res = mmyth_recordui_reload_schedule (recordui);
1.36 +
1.37 + res = res & mmyth_recordui_reload_record (recordui);
1.38 +
1.39 +
1.40 + if (!res)
1.41 + g_warning ("[%s] Error while reloading schedule and recording content", __FUNCTION__);
1.42 +
1.43 + return res;
1.44 +}
1.45 +
1.46 +gboolean
1.47 +mmyth_recordui_reload_schedule (MMythRecordUI *recordui)
1.48 +{
1.49 + gint new_row = 0;
1.50 + ScheduleInfo *schedule_info;
1.51 + GList *schedule_list;
1.52 + GtkTreeIter iter;
1.53 + GString *start_date_time = NULL;
1.54 + GString *end_date_time = NULL;
1.55 + GString *str_aux = g_string_new("");
1.56 + gint res;
1.57 +
1.58 + gtk_tree_store_clear(recordui->sch_tree_store);
1.59 +
1.60 + res = gmyth_scheduler_get_schedule_list(recordui->scheduler, &(schedule_list));
1.61 + if (res < 0) {
1.62 + g_warning ("[%s] Retrieved NULL list of scheduled data from database",
1.63 + __FUNCTION__);
1.64 + return FALSE;
1.65 + }
1.66 +
1.67 + for ( ; schedule_list; schedule_list = schedule_list->next) {
1.68 + schedule_info = (ScheduleInfo*) schedule_list->data;
1.69 +
1.70 + gtk_tree_store_insert(recordui->sch_tree_store, &iter, NULL, new_row++);
1.71 +
1.72 + start_date_time = gmyth_util_time_to_string(schedule_info->start_time);
1.73 + end_date_time = gmyth_util_time_to_string(schedule_info->end_time);
1.74 +
1.75 + g_string_printf(str_aux, "%d", schedule_info->channel_id);
1.76 +
1.77 + gtk_tree_store_set(recordui->sch_tree_store, &iter,
1.78 + START_DATE_COLUMN, start_date_time->str,
1.79 + TITLE_COLUMN, schedule_info->title->str,
1.80 + CHAN_ID_COLUMN, str_aux->str,
1.81 + END_TIME_COLUMN, end_date_time->str, //It doesn't appear
1.82 + RECORD_ID_COLUMN, schedule_info->record_id,
1.83 + -1); //the last line is a hidden item to be used in searching tasks
1.84 + }
1.85 +
1.86 + g_debug ("[%s] %d lines added to schedule list UI", __FUNCTION__, new_row);
1.87 +
1.88 + /* free allocated memory */
1.89 + if(!start_date_time)
1.90 + g_string_free(start_date_time, FALSE);
1.91 + if(!end_date_time)
1.92 + g_string_free(end_date_time, FALSE);
1.93 + g_string_free(str_aux, FALSE);
1.94 +
1.95 + return TRUE;
1.96 +}
1.97 +
1.98 +gboolean
1.99 +mmyth_recordui_reload_record (MMythRecordUI *recordui)
1.100 +{
1.101 + gint new_row = 0;
1.102 + RecordedInfo *recorded_info;
1.103 + GList *record_list = NULL;
1.104 + GtkTreeIter iter;
1.105 + GString *start_date_time = NULL;
1.106 + GString *end_date_time = NULL;
1.107 + GString *str_aux = g_string_new("");
1.108 + gint res;
1.109 +
1.110 + gtk_tree_store_clear(recordui->rec_tree_store);
1.111 +
1.112 + res = gmyth_scheduler_get_recorded_list(recordui->scheduler, &record_list);
1.113 + if (res < 0) {
1.114 + g_warning ("[%s] Retrieved NULL list of recorded data from database", __FUNCTION__);
1.115 + return FALSE;
1.116 + }
1.117 +
1.118 + for (; record_list; record_list = record_list->next) {
1.119 + recorded_info = (RecordedInfo*) record_list->data;
1.120 +
1.121 + gtk_tree_store_insert(recordui->rec_tree_store, &iter, NULL, new_row++);
1.122 +
1.123 + start_date_time = gmyth_util_time_to_string(recorded_info->start_time);
1.124 + end_date_time = gmyth_util_time_to_string(recorded_info->end_time);
1.125 +
1.126 + g_string_printf(str_aux, "%d", recorded_info->channel_id);
1.127 +
1.128 + gtk_tree_store_set(recordui->rec_tree_store, &iter,
1.129 + START_DATE_COLUMN, start_date_time->str,
1.130 + TITLE_COLUMN, recorded_info->title->str,
1.131 + CHAN_ID_COLUMN, str_aux->str,
1.132 + END_TIME_COLUMN, end_date_time->str, //It doesn't appear
1.133 + RECORD_ID_COLUMN, recorded_info->record_id,
1.134 + BASENAME_COLUMN, recorded_info->basename->str, -1);
1.135 + //the last line is a hidden item to be used in searching tasks
1.136 + }
1.137 +
1.138 + g_debug ("[%s] %d lines added to record list UI", __FUNCTION__, new_row);
1.139 +
1.140 + return TRUE;
1.141 +}
1.142 +
1.143 +
1.144 +MMythRecordUI*
1.145 +mmyth_recordui_new(void)
1.146 +{
1.147 + MMythRecordUI *recordui = g_new0 (MMythRecordUI, 1);
1.148 +
1.149 + recordui->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1.150 + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (recordui->scrolled_window),
1.151 + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1.152 +
1.153 + recordui->viewport = gtk_viewport_new (NULL, NULL);
1.154 + gtk_container_add (GTK_CONTAINER (recordui->scrolled_window), recordui->viewport);
1.155 +
1.156 + recordui->notebook = gtk_notebook_new ();
1.157 + gtk_container_set_border_width (GTK_CONTAINER (recordui->notebook), 1);
1.158 + gtk_notebook_set_scrollable (GTK_NOTEBOOK (recordui->notebook), TRUE);
1.159 + gtk_notebook_popup_enable (GTK_NOTEBOOK (recordui->notebook));
1.160 + gtk_container_add (GTK_CONTAINER (recordui->viewport), recordui->notebook);
1.161 + gtk_notebook_popup_disable(GTK_NOTEBOOK (recordui->notebook));
1.162 +
1.163 + /* Schedule tab */
1.164 + recordui->sch_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1.165 + gtk_container_add (GTK_CONTAINER (recordui->notebook), recordui->sch_scrolled_window);
1.166 + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (recordui->sch_scrolled_window),
1.167 + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1.168 + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (recordui->sch_scrolled_window),
1.169 + GTK_SHADOW_IN);
1.170 +
1.171 + /* The basename column in the sched_tree_store is not being used*/
1.172 + recordui->sch_tree_store =
1.173 + gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
1.174 + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING );
1.175 +
1.176 + recordui->sch_treeview =
1.177 + gtk_tree_view_new_with_model(GTK_TREE_MODEL(recordui->sch_tree_store));
1.178 + gtk_container_add (GTK_CONTAINER (recordui->sch_scrolled_window),
1.179 + recordui->sch_treeview);
1.180 + recordui->sch_renderer = gtk_cell_renderer_text_new();
1.181 + //g_object_set(G_OBJECT(renderer1), "foreground", "green", "background", "black", NULL);
1.182 + recordui->sch_column1 =
1.183 + gtk_tree_view_column_new_with_attributes("Start time", recordui->sch_renderer,
1.184 + "text", START_DATE_COLUMN, NULL);
1.185 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
1.186 + recordui->sch_column1);
1.187 + recordui->sch_column2 =
1.188 + gtk_tree_view_column_new_with_attributes("Title", recordui->sch_renderer,
1.189 + "text", TITLE_COLUMN, NULL);
1.190 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
1.191 + recordui->sch_column2);
1.192 + recordui->sch_column3 =
1.193 + gtk_tree_view_column_new_with_attributes("Channel", recordui->sch_renderer,
1.194 + "text", CHAN_ID_COLUMN, NULL);
1.195 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
1.196 + recordui->sch_column3);
1.197 + gtk_tree_view_column_set_resizable(recordui->sch_column1, TRUE);
1.198 + gtk_tree_view_column_set_resizable(recordui->sch_column2, TRUE);
1.199 + gtk_tree_view_column_set_resizable(recordui->sch_column3, TRUE);
1.200 + gtk_tree_view_column_set_reorderable(recordui->sch_column1, TRUE);
1.201 + gtk_tree_view_column_set_reorderable(recordui->sch_column2, TRUE);
1.202 + gtk_tree_view_column_set_reorderable(recordui->sch_column3, TRUE);
1.203 +// recordui->sch_column4 =
1.204 +// gtk_tree_view_column_new_with_attributes("", recordui->sch_renderer, "text", END_TIME_COLUMN, NULL);
1.205 +// gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
1.206 +// recordui->sch_column4);
1.207 +
1.208 + recordui->sch_label = gtk_label_new (("Schedule"));
1.209 + gtk_notebook_set_tab_label (GTK_NOTEBOOK (recordui->notebook),
1.210 + gtk_notebook_get_nth_page (
1.211 + GTK_NOTEBOOK (recordui->notebook), 0),
1.212 + recordui->sch_label);
1.213 +
1.214 + // Record items tab
1.215 + // g_object_set(G_OBJECT(renderer2), "foreground", "blue", NULL);
1.216 + recordui->rec_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1.217 + gtk_container_add (GTK_CONTAINER (recordui->notebook),
1.218 + recordui->rec_scrolled_window);
1.219 + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (recordui->rec_scrolled_window),
1.220 + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1.221 + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (recordui->rec_scrolled_window),
1.222 + GTK_SHADOW_IN);
1.223 +
1.224 + recordui->rec_tree_store =
1.225 + gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
1.226 + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1.227 + recordui->rec_treeview =
1.228 + gtk_tree_view_new_with_model(GTK_TREE_MODEL(recordui->rec_tree_store));
1.229 + gtk_container_add (GTK_CONTAINER (recordui->rec_scrolled_window),
1.230 + recordui->rec_treeview);
1.231 + recordui->rec_renderer = gtk_cell_renderer_text_new();
1.232 + //g_object_set(G_OBJECT(renderer1), "foreground", "green", "background", "black", NULL);
1.233 +
1.234 + recordui->rec_column1 =
1.235 + gtk_tree_view_column_new_with_attributes("Start time", recordui->rec_renderer,
1.236 + "text", START_DATE_COLUMN, NULL);
1.237 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
1.238 + recordui->rec_column1);
1.239 + recordui->rec_column2 =
1.240 + gtk_tree_view_column_new_with_attributes("Title", recordui->rec_renderer,
1.241 + "text", TITLE_COLUMN, NULL);
1.242 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
1.243 + recordui->rec_column2);
1.244 + recordui->rec_column3 =
1.245 + gtk_tree_view_column_new_with_attributes("Channel", recordui->rec_renderer,
1.246 + "text", CHAN_ID_COLUMN, NULL);
1.247 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
1.248 + recordui->rec_column3);
1.249 + gtk_tree_view_column_set_resizable(recordui->rec_column1, TRUE);
1.250 + gtk_tree_view_column_set_resizable(recordui->rec_column2, TRUE);
1.251 + gtk_tree_view_column_set_resizable(recordui->rec_column3, TRUE);
1.252 + gtk_tree_view_column_set_reorderable(recordui->rec_column1, TRUE);
1.253 + gtk_tree_view_column_set_reorderable(recordui->rec_column2, TRUE);
1.254 + gtk_tree_view_column_set_reorderable(recordui->rec_column3, TRUE);
1.255 +// recordui->rec_column4 = gtk_tree_view_column_new_with_attributes("", recordui->rec_renderer, "text", END_TIME_COLUMN, NULL);
1.256 +// gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview), recordui->rec_column4);
1.257 +
1.258 + recordui->rec_label = gtk_label_new (("Recorded"));
1.259 + gtk_notebook_set_tab_label (GTK_NOTEBOOK (recordui->notebook),
1.260 + gtk_notebook_get_nth_page (
1.261 + GTK_NOTEBOOK (recordui->notebook), 1),
1.262 + recordui->rec_label);
1.263 +
1.264 + // Gets the mmyth scheduler manager
1.265 + recordui->scheduler = gmyth_scheduler_new ();
1.266 +
1.267 + /* init connection to the backend */
1.268 + gmyth_scheduler_connect (recordui->scheduler);
1.269 +
1.270 + return recordui;
1.271 +}
1.272 +
1.273 +void
1.274 +mmyth_recordui_free (MMythRecordUI *recordui)
1.275 +{
1.276 + // FIXME: Release memory here!
1.277 + /* close connection to the backend */
1.278 + gmyth_scheduler_disconnect (recordui->scheduler);
1.279 +}
1.280 +
1.281 +void
1.282 +mmyth_recordui_delete_selected (GtkButton *button, MMythRecordUI *recordui)
1.283 +{
1.284 + GtkTreeSelection *selection;
1.285 + GtkTreeModel *list_store;
1.286 + GtkTreeIter iter;
1.287 + int index;
1.288 + int curr_page = 0;
1.289 +
1.290 + curr_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(recordui->notebook));
1.291 +
1.292 + if ( curr_page == 0) {
1.293 + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(recordui->sch_treeview));
1.294 + if (selection != NULL) {
1.295 + gtk_tree_selection_get_selected(selection, &list_store, &iter);
1.296 + gtk_tree_model_get(list_store, &iter, RECORD_ID_COLUMN, &index, -1);
1.297 + gmyth_scheduler_delete_schedule(recordui->scheduler, index);
1.298 + mmyth_recordui_reload_schedule (recordui);
1.299 + return;
1.300 + }
1.301 +
1.302 + } else if (curr_page == 1) {
1.303 + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(recordui->rec_treeview));
1.304 + if (selection != NULL) {
1.305 + gtk_tree_selection_get_selected(selection, &list_store, &iter);
1.306 + gtk_tree_model_get(list_store, &iter, RECORD_ID_COLUMN, &index, -1);
1.307 + gmyth_scheduler_delete_recorded(recordui->scheduler, index);
1.308 + mmyth_recordui_reload_record (recordui);
1.309 + return;
1.310 + }
1.311 + }
1.312 +
1.313 + g_warning ("[%s] None element was removed from the list", __FUNCTION__);
1.314 +}
1.315 +
1.316 +/* FIXME: change this function name, it is returning the
1.317 + * basename_column that represents the nuv filename of
1.318 + * the recorded content */
1.319 +gchar*
1.320 +mmyth_recordui_get_selected_recorded (MMythRecordUI *recordui)
1.321 +{
1.322 + GtkTreeSelection *selection = NULL;
1.323 + GtkTreeModel *list_store = NULL;
1.324 + GtkTreeIter iter;
1.325 + gchar *path = NULL;
1.326 +
1.327 + /* returning nuv filename, basename_column */
1.328 + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(recordui->rec_treeview));
1.329 + if (gtk_tree_selection_get_selected (selection, &list_store, &iter)) {
1.330 + gtk_tree_model_get(list_store, &iter, BASENAME_COLUMN, &path, -1);
1.331 + }
1.332 +
1.333 + // FIXME: MOVE THIS TO OTHER PLACE
1.334 + return path;
1.335 +}