1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/maemo-ui-old/src/mmyth_recordui.c Mon Oct 08 19:35:09 2007 +0100
1.3 @@ -0,0 +1,433 @@
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 +/*
1.17 + * GMyth library includes
1.18 + */
1.19 +#include <gmyth/gmyth_scheduler.h>
1.20 +#include <gmyth/gmyth_util.h>
1.21 +
1.22 +enum {
1.23 + START_DATE_COLUMN = 0,
1.24 + TITLE_COLUMN,
1.25 + CHAN_ID_COLUMN,
1.26 + END_TIME_COLUMN,
1.27 + RECORD_ID_COLUMN,
1.28 + BASENAME_COLUMN,
1.29 + N_COLUMNS
1.30 +};
1.31 +
1.32 +gboolean
1.33 +mmyth_recordui_reload_all(MMythRecordUI * recordui)
1.34 +{
1.35 + gboolean res = FALSE;
1.36 +
1.37 + res = mmyth_recordui_reload_schedule(recordui);
1.38 +
1.39 + res = res & mmyth_recordui_reload_record(recordui);
1.40 +
1.41 +
1.42 + if (!res)
1.43 + g_warning
1.44 + ("[%s] Error while reloading schedule and recording content",
1.45 + __FUNCTION__);
1.46 +
1.47 + return res;
1.48 +}
1.49 +
1.50 +gboolean
1.51 +mmyth_recordui_reload_schedule(MMythRecordUI * recordui)
1.52 +{
1.53 + gint new_row = 0;
1.54 + ScheduleInfo *schedule_info;
1.55 + GList *schedule_list;
1.56 + GtkTreeIter iter;
1.57 + gchar *start_date_time = NULL;
1.58 + gchar *end_date_time = NULL;
1.59 + GString *str_aux = g_string_new("");
1.60 + gint res;
1.61 +
1.62 + gtk_tree_store_clear(recordui->sch_tree_store);
1.63 +
1.64 + res =
1.65 + gmyth_scheduler_get_schedule_list(recordui->scheduler,
1.66 + &(schedule_list));
1.67 + if (res < 0) {
1.68 + g_warning
1.69 + ("[%s] Retrieved NULL list of scheduled data from database",
1.70 + __FUNCTION__);
1.71 + return FALSE;
1.72 + }
1.73 +
1.74 + for (; schedule_list; schedule_list = schedule_list->next) {
1.75 + schedule_info = (ScheduleInfo *) schedule_list->data;
1.76 +
1.77 + gtk_tree_store_insert(recordui->sch_tree_store, &iter, NULL,
1.78 + new_row++);
1.79 +
1.80 + start_date_time =
1.81 + gmyth_util_time_to_string_from_time_val(schedule_info->
1.82 + start_time);
1.83 + end_date_time =
1.84 + gmyth_util_time_to_string_from_time_val(schedule_info->
1.85 + end_time);
1.86 +
1.87 + g_string_printf(str_aux, "%d", schedule_info->channel_id);
1.88 +
1.89 + gtk_tree_store_set(recordui->sch_tree_store, &iter, START_DATE_COLUMN, start_date_time, TITLE_COLUMN, schedule_info->title->str, CHAN_ID_COLUMN, str_aux->str, END_TIME_COLUMN, end_date_time, // It
1.90 + // doesn't
1.91 + // appear
1.92 + RECORD_ID_COLUMN, schedule_info->record_id, -1); // the
1.93 + // last
1.94 + // line
1.95 + // is
1.96 + // a
1.97 + // hidden
1.98 + // item
1.99 + // to
1.100 + // be
1.101 + // used
1.102 + // in
1.103 + // searching
1.104 + // tasks
1.105 + }
1.106 +
1.107 + g_debug("[%s] %d lines added to schedule list UI", __FUNCTION__,
1.108 + new_row);
1.109 +
1.110 + /*
1.111 + * free allocated memory
1.112 + */
1.113 + if (!start_date_time)
1.114 + g_free(start_date_time);
1.115 + if (!end_date_time)
1.116 + g_free(end_date_time);
1.117 + g_string_free(str_aux, FALSE);
1.118 +
1.119 + return TRUE;
1.120 +}
1.121 +
1.122 +gboolean
1.123 +mmyth_recordui_reload_record(MMythRecordUI * recordui)
1.124 +{
1.125 + gint new_row = 0;
1.126 + RecordedInfo *recorded_info;
1.127 + GList *record_list = NULL;
1.128 + GtkTreeIter iter;
1.129 + gchar *start_date_time = NULL;
1.130 + gchar *end_date_time = NULL;
1.131 + GString *str_aux = g_string_new("");
1.132 + gint res;
1.133 +
1.134 + gtk_tree_store_clear(recordui->rec_tree_store);
1.135 +
1.136 + res =
1.137 + gmyth_scheduler_get_recorded_list(recordui->scheduler,
1.138 + &record_list);
1.139 + if (res < 0) {
1.140 + g_warning
1.141 + ("[%s] Retrieved NULL list of recorded data from database",
1.142 + __FUNCTION__);
1.143 + return FALSE;
1.144 + }
1.145 +
1.146 + for (; record_list; record_list = record_list->next) {
1.147 + recorded_info = (RecordedInfo *) record_list->data;
1.148 +
1.149 + gtk_tree_store_insert(recordui->rec_tree_store, &iter, NULL,
1.150 + new_row++);
1.151 +
1.152 + start_date_time =
1.153 + gmyth_util_time_to_string_from_time_val(recorded_info->
1.154 + start_time);
1.155 + end_date_time =
1.156 + gmyth_util_time_to_string_from_time_val(recorded_info->
1.157 + end_time);
1.158 +
1.159 + g_string_printf(str_aux, "%d", recorded_info->channel_id);
1.160 +
1.161 + gtk_tree_store_set(recordui->rec_tree_store, &iter, START_DATE_COLUMN, start_date_time, TITLE_COLUMN, recorded_info->title->str, CHAN_ID_COLUMN, str_aux->str, END_TIME_COLUMN, end_date_time, // It
1.162 + // doesn't
1.163 + // appear
1.164 + RECORD_ID_COLUMN, recorded_info->record_id,
1.165 + BASENAME_COLUMN, recorded_info->basename->str,
1.166 + -1);
1.167 + // the last line is a hidden item to be used in searching tasks
1.168 + }
1.169 +
1.170 + g_debug("[%s] %d lines added to record list UI", __FUNCTION__,
1.171 + new_row);
1.172 +
1.173 + /*
1.174 + * free allocated memory
1.175 + */
1.176 + if (NULL != start_date_time)
1.177 + g_free(start_date_time);
1.178 + if (NULL != end_date_time)
1.179 + g_free(end_date_time);
1.180 + g_string_free(str_aux, FALSE);
1.181 +
1.182 + return TRUE;
1.183 +}
1.184 +
1.185 +
1.186 +MMythRecordUI *
1.187 +mmyth_recordui_new(GMythBackendInfo * backend_info)
1.188 +{
1.189 + MMythRecordUI *recordui = g_new0(MMythRecordUI, 1);
1.190 +
1.191 + g_return_val_if_fail(backend_info != NULL, NULL);
1.192 +
1.193 + recordui->backend_info = backend_info;
1.194 +
1.195 + recordui->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
1.196 + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
1.197 + (recordui->scrolled_window),
1.198 + GTK_POLICY_AUTOMATIC,
1.199 + GTK_POLICY_AUTOMATIC);
1.200 +
1.201 + recordui->viewport = gtk_viewport_new(NULL, NULL);
1.202 + gtk_container_add(GTK_CONTAINER(recordui->scrolled_window),
1.203 + recordui->viewport);
1.204 +
1.205 + recordui->notebook = gtk_notebook_new();
1.206 + gtk_container_set_border_width(GTK_CONTAINER(recordui->notebook), 1);
1.207 + gtk_notebook_set_scrollable(GTK_NOTEBOOK(recordui->notebook), TRUE);
1.208 + gtk_notebook_popup_enable(GTK_NOTEBOOK(recordui->notebook));
1.209 + gtk_container_add(GTK_CONTAINER(recordui->viewport),
1.210 + recordui->notebook);
1.211 + gtk_notebook_popup_disable(GTK_NOTEBOOK(recordui->notebook));
1.212 +
1.213 + /*
1.214 + * Schedule tab
1.215 + */
1.216 + recordui->sch_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
1.217 + gtk_container_add(GTK_CONTAINER(recordui->notebook),
1.218 + recordui->sch_scrolled_window);
1.219 + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
1.220 + (recordui->sch_scrolled_window),
1.221 + GTK_POLICY_AUTOMATIC,
1.222 + GTK_POLICY_AUTOMATIC);
1.223 + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW
1.224 + (recordui->sch_scrolled_window),
1.225 + GTK_SHADOW_IN);
1.226 +
1.227 + /*
1.228 + * The basename column in the sched_tree_store is not being used
1.229 + */
1.230 + recordui->sch_tree_store =
1.231 + gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
1.232 + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT,
1.233 + G_TYPE_STRING);
1.234 +
1.235 + recordui->sch_treeview =
1.236 + gtk_tree_view_new_with_model(GTK_TREE_MODEL
1.237 + (recordui->sch_tree_store));
1.238 + gtk_container_add(GTK_CONTAINER(recordui->sch_scrolled_window),
1.239 + recordui->sch_treeview);
1.240 + recordui->sch_renderer = gtk_cell_renderer_text_new();
1.241 + // g_object_set(G_OBJECT(renderer1), "foreground", "green",
1.242 + // "background", "black", NULL);
1.243 + recordui->sch_column1 =
1.244 + gtk_tree_view_column_new_with_attributes("Start time",
1.245 + recordui->sch_renderer,
1.246 + "text", START_DATE_COLUMN,
1.247 + NULL);
1.248 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
1.249 + recordui->sch_column1);
1.250 + recordui->sch_column2 =
1.251 + gtk_tree_view_column_new_with_attributes("Title",
1.252 + recordui->sch_renderer,
1.253 + "text", TITLE_COLUMN,
1.254 + NULL);
1.255 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
1.256 + recordui->sch_column2);
1.257 + recordui->sch_column3 =
1.258 + gtk_tree_view_column_new_with_attributes("Channel",
1.259 + recordui->sch_renderer,
1.260 + "text", CHAN_ID_COLUMN,
1.261 + NULL);
1.262 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
1.263 + recordui->sch_column3);
1.264 + gtk_tree_view_column_set_resizable(recordui->sch_column1, TRUE);
1.265 + gtk_tree_view_column_set_resizable(recordui->sch_column2, TRUE);
1.266 + gtk_tree_view_column_set_resizable(recordui->sch_column3, TRUE);
1.267 + gtk_tree_view_column_set_reorderable(recordui->sch_column1, TRUE);
1.268 + gtk_tree_view_column_set_reorderable(recordui->sch_column2, TRUE);
1.269 + gtk_tree_view_column_set_reorderable(recordui->sch_column3, TRUE);
1.270 + // recordui->sch_column4 =
1.271 + // gtk_tree_view_column_new_with_attributes("",
1.272 + // recordui->sch_renderer, "text", END_TIME_COLUMN, NULL);
1.273 + // gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
1.274 + // recordui->sch_column4);
1.275 +
1.276 + recordui->sch_label = gtk_label_new(("Schedule"));
1.277 + gtk_notebook_set_tab_label(GTK_NOTEBOOK(recordui->notebook),
1.278 + gtk_notebook_get_nth_page(GTK_NOTEBOOK
1.279 + (recordui->
1.280 + notebook), 0),
1.281 + recordui->sch_label);
1.282 +
1.283 + // Record items tab
1.284 + // g_object_set(G_OBJECT(renderer2), "foreground", "blue", NULL);
1.285 + recordui->rec_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
1.286 + gtk_container_add(GTK_CONTAINER(recordui->notebook),
1.287 + recordui->rec_scrolled_window);
1.288 + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
1.289 + (recordui->rec_scrolled_window),
1.290 + GTK_POLICY_AUTOMATIC,
1.291 + GTK_POLICY_AUTOMATIC);
1.292 + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW
1.293 + (recordui->rec_scrolled_window),
1.294 + GTK_SHADOW_IN);
1.295 +
1.296 + recordui->rec_tree_store =
1.297 + gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
1.298 + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT,
1.299 + G_TYPE_STRING);
1.300 + recordui->rec_treeview =
1.301 + gtk_tree_view_new_with_model(GTK_TREE_MODEL
1.302 + (recordui->rec_tree_store));
1.303 + gtk_container_add(GTK_CONTAINER(recordui->rec_scrolled_window),
1.304 + recordui->rec_treeview);
1.305 + recordui->rec_renderer = gtk_cell_renderer_text_new();
1.306 + // g_object_set(G_OBJECT(renderer1), "foreground", "green",
1.307 + // "background", "black", NULL);
1.308 +
1.309 + recordui->rec_column1 =
1.310 + gtk_tree_view_column_new_with_attributes("Start time",
1.311 + recordui->rec_renderer,
1.312 + "text", START_DATE_COLUMN,
1.313 + NULL);
1.314 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
1.315 + recordui->rec_column1);
1.316 + recordui->rec_column2 =
1.317 + gtk_tree_view_column_new_with_attributes("Title",
1.318 + recordui->rec_renderer,
1.319 + "text", TITLE_COLUMN,
1.320 + NULL);
1.321 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
1.322 + recordui->rec_column2);
1.323 + recordui->rec_column3 =
1.324 + gtk_tree_view_column_new_with_attributes("Channel",
1.325 + recordui->rec_renderer,
1.326 + "text", CHAN_ID_COLUMN,
1.327 + NULL);
1.328 + gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
1.329 + recordui->rec_column3);
1.330 + gtk_tree_view_column_set_resizable(recordui->rec_column1, TRUE);
1.331 + gtk_tree_view_column_set_resizable(recordui->rec_column2, TRUE);
1.332 + gtk_tree_view_column_set_resizable(recordui->rec_column3, TRUE);
1.333 + gtk_tree_view_column_set_reorderable(recordui->rec_column1, TRUE);
1.334 + gtk_tree_view_column_set_reorderable(recordui->rec_column2, TRUE);
1.335 + gtk_tree_view_column_set_reorderable(recordui->rec_column3, TRUE);
1.336 + // recordui->rec_column4 =
1.337 + // gtk_tree_view_column_new_with_attributes("",
1.338 + // recordui->rec_renderer, "text", END_TIME_COLUMN, NULL);
1.339 + // gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
1.340 + // recordui->rec_column4);
1.341 +
1.342 + recordui->rec_label = gtk_label_new(("Recorded"));
1.343 + gtk_notebook_set_tab_label(GTK_NOTEBOOK(recordui->notebook),
1.344 + gtk_notebook_get_nth_page(GTK_NOTEBOOK
1.345 + (recordui->
1.346 + notebook), 1),
1.347 + recordui->rec_label);
1.348 +
1.349 + // Gets the mmyth scheduler manager
1.350 + recordui->scheduler = gmyth_scheduler_new(backend_info);
1.351 +
1.352 + /*
1.353 + * init connection to the backend
1.354 + */
1.355 + gmyth_scheduler_connect(recordui->scheduler,
1.356 + recordui->scheduler->backend_info);
1.357 +
1.358 + return recordui;
1.359 +}
1.360 +
1.361 +void
1.362 +mmyth_recordui_free(MMythRecordUI * recordui)
1.363 +{
1.364 + // FIXME: Release memory here!
1.365 + /*
1.366 + * close connection to the backend
1.367 + */
1.368 + gmyth_scheduler_disconnect(recordui->scheduler);
1.369 +}
1.370 +
1.371 +void
1.372 +mmyth_recordui_delete_selected(GtkButton * button,
1.373 + MMythRecordUI * recordui)
1.374 +{
1.375 + GtkTreeSelection *selection;
1.376 + GtkTreeModel *list_store;
1.377 + GtkTreeIter iter;
1.378 + int index;
1.379 + int curr_page = 0;
1.380 +
1.381 + curr_page =
1.382 + gtk_notebook_get_current_page(GTK_NOTEBOOK(recordui->notebook));
1.383 +
1.384 + if (curr_page == 0) {
1.385 + selection =
1.386 + gtk_tree_view_get_selection(GTK_TREE_VIEW
1.387 + (recordui->sch_treeview));
1.388 + if (selection != NULL) {
1.389 + gtk_tree_selection_get_selected(selection, &list_store, &iter);
1.390 + gtk_tree_model_get(list_store, &iter, RECORD_ID_COLUMN, &index,
1.391 + -1);
1.392 + gmyth_scheduler_delete_schedule(recordui->scheduler, index);
1.393 + mmyth_recordui_reload_schedule(recordui);
1.394 + return;
1.395 + }
1.396 +
1.397 + } else if (curr_page == 1) {
1.398 + selection =
1.399 + gtk_tree_view_get_selection(GTK_TREE_VIEW
1.400 + (recordui->rec_treeview));
1.401 + if (selection != NULL) {
1.402 + gtk_tree_selection_get_selected(selection, &list_store, &iter);
1.403 + gtk_tree_model_get(list_store, &iter, RECORD_ID_COLUMN, &index,
1.404 + -1);
1.405 + gmyth_scheduler_delete_recorded(recordui->scheduler, index);
1.406 + mmyth_recordui_reload_record(recordui);
1.407 + return;
1.408 + }
1.409 + }
1.410 +
1.411 + g_warning("[%s] None element was removed from the list", __FUNCTION__);
1.412 +}
1.413 +
1.414 +/*
1.415 + * FIXME: change this function name, it is returning the basename_column
1.416 + * that represents the nuv filename of the recorded content
1.417 + */
1.418 +gchar *
1.419 +mmyth_recordui_get_selected_recorded(MMythRecordUI * recordui)
1.420 +{
1.421 + GtkTreeSelection *selection = NULL;
1.422 + GtkTreeModel *list_store = NULL;
1.423 + GtkTreeIter iter;
1.424 + gchar *path = NULL;
1.425 +
1.426 + /*
1.427 + * returning nuv filename, basename_column
1.428 + */
1.429 + selection =
1.430 + gtk_tree_view_get_selection(GTK_TREE_VIEW(recordui->rec_treeview));
1.431 + if (gtk_tree_selection_get_selected(selection, &list_store, &iter)) {
1.432 + gtk_tree_model_get(list_store, &iter, BASENAME_COLUMN, &path, -1);
1.433 + }
1.434 + // FIXME: MOVE THIS TO OTHER PLACE
1.435 + return path;
1.436 +}