11 #include "mmyth_recordui.h"
14 * GMyth library includes
16 #include <gmyth/gmyth_scheduler.h>
17 #include <gmyth/gmyth_util.h>
20 START_DATE_COLUMN = 0,
30 mmyth_recordui_reload_all(MMythRecordUI * recordui)
34 res = mmyth_recordui_reload_schedule(recordui);
36 res = res & mmyth_recordui_reload_record(recordui);
41 ("[%s] Error while reloading schedule and recording content",
48 mmyth_recordui_reload_schedule(MMythRecordUI * recordui)
51 ScheduleInfo *schedule_info;
54 gchar *start_date_time = NULL;
55 gchar *end_date_time = NULL;
56 GString *str_aux = g_string_new("");
59 gtk_tree_store_clear(recordui->sch_tree_store);
62 gmyth_scheduler_get_schedule_list(recordui->scheduler,
66 ("[%s] Retrieved NULL list of scheduled data from database",
71 for (; schedule_list; schedule_list = schedule_list->next) {
72 schedule_info = (ScheduleInfo *) schedule_list->data;
74 gtk_tree_store_insert(recordui->sch_tree_store, &iter, NULL,
78 gmyth_util_time_to_string_from_time_val(schedule_info->
81 gmyth_util_time_to_string_from_time_val(schedule_info->
84 g_string_printf(str_aux, "%d", schedule_info->channel_id);
86 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
89 RECORD_ID_COLUMN, schedule_info->record_id, -1); // the
104 g_debug("[%s] %d lines added to schedule list UI", __FUNCTION__,
108 * free allocated memory
110 if (!start_date_time)
111 g_free(start_date_time);
113 g_free(end_date_time);
114 g_string_free(str_aux, FALSE);
120 mmyth_recordui_reload_record(MMythRecordUI * recordui)
123 RecordedInfo *recorded_info;
124 GList *record_list = NULL;
126 gchar *start_date_time = NULL;
127 gchar *end_date_time = NULL;
128 GString *str_aux = g_string_new("");
131 gtk_tree_store_clear(recordui->rec_tree_store);
134 gmyth_scheduler_get_recorded_list(recordui->scheduler,
138 ("[%s] Retrieved NULL list of recorded data from database",
143 for (; record_list; record_list = record_list->next) {
144 recorded_info = (RecordedInfo *) record_list->data;
146 gtk_tree_store_insert(recordui->rec_tree_store, &iter, NULL,
150 gmyth_util_time_to_string_from_time_val(recorded_info->
153 gmyth_util_time_to_string_from_time_val(recorded_info->
156 g_string_printf(str_aux, "%d", recorded_info->channel_id);
158 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
161 RECORD_ID_COLUMN, recorded_info->record_id,
162 BASENAME_COLUMN, recorded_info->basename->str,
164 // the last line is a hidden item to be used in searching tasks
167 g_debug("[%s] %d lines added to record list UI", __FUNCTION__,
171 * free allocated memory
173 if (NULL != start_date_time)
174 g_free(start_date_time);
175 if (NULL != end_date_time)
176 g_free(end_date_time);
177 g_string_free(str_aux, FALSE);
184 mmyth_recordui_new(GMythBackendInfo * backend_info)
186 MMythRecordUI *recordui = g_new0(MMythRecordUI, 1);
188 g_return_val_if_fail(backend_info != NULL, NULL);
190 recordui->backend_info = backend_info;
192 recordui->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
193 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
194 (recordui->scrolled_window),
195 GTK_POLICY_AUTOMATIC,
196 GTK_POLICY_AUTOMATIC);
198 recordui->viewport = gtk_viewport_new(NULL, NULL);
199 gtk_container_add(GTK_CONTAINER(recordui->scrolled_window),
202 recordui->notebook = gtk_notebook_new();
203 gtk_container_set_border_width(GTK_CONTAINER(recordui->notebook), 1);
204 gtk_notebook_set_scrollable(GTK_NOTEBOOK(recordui->notebook), TRUE);
205 gtk_notebook_popup_enable(GTK_NOTEBOOK(recordui->notebook));
206 gtk_container_add(GTK_CONTAINER(recordui->viewport),
208 gtk_notebook_popup_disable(GTK_NOTEBOOK(recordui->notebook));
213 recordui->sch_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
214 gtk_container_add(GTK_CONTAINER(recordui->notebook),
215 recordui->sch_scrolled_window);
216 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
217 (recordui->sch_scrolled_window),
218 GTK_POLICY_AUTOMATIC,
219 GTK_POLICY_AUTOMATIC);
220 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW
221 (recordui->sch_scrolled_window),
225 * The basename column in the sched_tree_store is not being used
227 recordui->sch_tree_store =
228 gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
229 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT,
232 recordui->sch_treeview =
233 gtk_tree_view_new_with_model(GTK_TREE_MODEL
234 (recordui->sch_tree_store));
235 gtk_container_add(GTK_CONTAINER(recordui->sch_scrolled_window),
236 recordui->sch_treeview);
237 recordui->sch_renderer = gtk_cell_renderer_text_new();
238 // g_object_set(G_OBJECT(renderer1), "foreground", "green",
239 // "background", "black", NULL);
240 recordui->sch_column1 =
241 gtk_tree_view_column_new_with_attributes("Start time",
242 recordui->sch_renderer,
243 "text", START_DATE_COLUMN,
245 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
246 recordui->sch_column1);
247 recordui->sch_column2 =
248 gtk_tree_view_column_new_with_attributes("Title",
249 recordui->sch_renderer,
250 "text", TITLE_COLUMN,
252 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
253 recordui->sch_column2);
254 recordui->sch_column3 =
255 gtk_tree_view_column_new_with_attributes("Channel",
256 recordui->sch_renderer,
257 "text", CHAN_ID_COLUMN,
259 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
260 recordui->sch_column3);
261 gtk_tree_view_column_set_resizable(recordui->sch_column1, TRUE);
262 gtk_tree_view_column_set_resizable(recordui->sch_column2, TRUE);
263 gtk_tree_view_column_set_resizable(recordui->sch_column3, TRUE);
264 gtk_tree_view_column_set_reorderable(recordui->sch_column1, TRUE);
265 gtk_tree_view_column_set_reorderable(recordui->sch_column2, TRUE);
266 gtk_tree_view_column_set_reorderable(recordui->sch_column3, TRUE);
267 // recordui->sch_column4 =
268 // gtk_tree_view_column_new_with_attributes("",
269 // recordui->sch_renderer, "text", END_TIME_COLUMN, NULL);
270 // gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
271 // recordui->sch_column4);
273 recordui->sch_label = gtk_label_new(("Schedule"));
274 gtk_notebook_set_tab_label(GTK_NOTEBOOK(recordui->notebook),
275 gtk_notebook_get_nth_page(GTK_NOTEBOOK
278 recordui->sch_label);
281 // g_object_set(G_OBJECT(renderer2), "foreground", "blue", NULL);
282 recordui->rec_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
283 gtk_container_add(GTK_CONTAINER(recordui->notebook),
284 recordui->rec_scrolled_window);
285 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
286 (recordui->rec_scrolled_window),
287 GTK_POLICY_AUTOMATIC,
288 GTK_POLICY_AUTOMATIC);
289 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW
290 (recordui->rec_scrolled_window),
293 recordui->rec_tree_store =
294 gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
295 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT,
297 recordui->rec_treeview =
298 gtk_tree_view_new_with_model(GTK_TREE_MODEL
299 (recordui->rec_tree_store));
300 gtk_container_add(GTK_CONTAINER(recordui->rec_scrolled_window),
301 recordui->rec_treeview);
302 recordui->rec_renderer = gtk_cell_renderer_text_new();
303 // g_object_set(G_OBJECT(renderer1), "foreground", "green",
304 // "background", "black", NULL);
306 recordui->rec_column1 =
307 gtk_tree_view_column_new_with_attributes("Start time",
308 recordui->rec_renderer,
309 "text", START_DATE_COLUMN,
311 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
312 recordui->rec_column1);
313 recordui->rec_column2 =
314 gtk_tree_view_column_new_with_attributes("Title",
315 recordui->rec_renderer,
316 "text", TITLE_COLUMN,
318 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
319 recordui->rec_column2);
320 recordui->rec_column3 =
321 gtk_tree_view_column_new_with_attributes("Channel",
322 recordui->rec_renderer,
323 "text", CHAN_ID_COLUMN,
325 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
326 recordui->rec_column3);
327 gtk_tree_view_column_set_resizable(recordui->rec_column1, TRUE);
328 gtk_tree_view_column_set_resizable(recordui->rec_column2, TRUE);
329 gtk_tree_view_column_set_resizable(recordui->rec_column3, TRUE);
330 gtk_tree_view_column_set_reorderable(recordui->rec_column1, TRUE);
331 gtk_tree_view_column_set_reorderable(recordui->rec_column2, TRUE);
332 gtk_tree_view_column_set_reorderable(recordui->rec_column3, TRUE);
333 // recordui->rec_column4 =
334 // gtk_tree_view_column_new_with_attributes("",
335 // recordui->rec_renderer, "text", END_TIME_COLUMN, NULL);
336 // gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
337 // recordui->rec_column4);
339 recordui->rec_label = gtk_label_new(("Recorded"));
340 gtk_notebook_set_tab_label(GTK_NOTEBOOK(recordui->notebook),
341 gtk_notebook_get_nth_page(GTK_NOTEBOOK
344 recordui->rec_label);
346 // Gets the mmyth scheduler manager
347 recordui->scheduler = gmyth_scheduler_new(backend_info);
350 * init connection to the backend
352 gmyth_scheduler_connect(recordui->scheduler,
353 recordui->scheduler->backend_info);
359 mmyth_recordui_free(MMythRecordUI * recordui)
361 // FIXME: Release memory here!
363 * close connection to the backend
365 gmyth_scheduler_disconnect(recordui->scheduler);
369 mmyth_recordui_delete_selected(GtkButton * button,
370 MMythRecordUI * recordui)
372 GtkTreeSelection *selection;
373 GtkTreeModel *list_store;
379 gtk_notebook_get_current_page(GTK_NOTEBOOK(recordui->notebook));
381 if (curr_page == 0) {
383 gtk_tree_view_get_selection(GTK_TREE_VIEW
384 (recordui->sch_treeview));
385 if (selection != NULL) {
386 gtk_tree_selection_get_selected(selection, &list_store, &iter);
387 gtk_tree_model_get(list_store, &iter, RECORD_ID_COLUMN, &index,
389 gmyth_scheduler_delete_schedule(recordui->scheduler, index);
390 mmyth_recordui_reload_schedule(recordui);
394 } else if (curr_page == 1) {
396 gtk_tree_view_get_selection(GTK_TREE_VIEW
397 (recordui->rec_treeview));
398 if (selection != NULL) {
399 gtk_tree_selection_get_selected(selection, &list_store, &iter);
400 gtk_tree_model_get(list_store, &iter, RECORD_ID_COLUMN, &index,
402 gmyth_scheduler_delete_recorded(recordui->scheduler, index);
403 mmyth_recordui_reload_record(recordui);
408 g_warning("[%s] None element was removed from the list", __FUNCTION__);
412 * FIXME: change this function name, it is returning the basename_column
413 * that represents the nuv filename of the recorded content
416 mmyth_recordui_get_selected_recorded(MMythRecordUI * recordui)
418 GtkTreeSelection *selection = NULL;
419 GtkTreeModel *list_store = NULL;
424 * returning nuv filename, basename_column
427 gtk_tree_view_get_selection(GTK_TREE_VIEW(recordui->rec_treeview));
428 if (gtk_tree_selection_get_selected(selection, &list_store, &iter)) {
429 gtk_tree_model_get(list_store, &iter, BASENAME_COLUMN, &path, -1);
431 // FIXME: MOVE THIS TO OTHER PLACE