[svn r25] String list cleaning function.
11 #include "mmyth_recordui.h"
13 /* GMyth library includes */
14 #include "gmyth_scheduler.h"
15 #include "gmyth_util.h"
18 START_DATE_COLUMN = 0,
28 mmyth_recordui_reload_all (MMythRecordUI *recordui)
32 res = mmyth_recordui_reload_schedule (recordui);
34 res = res & mmyth_recordui_reload_record (recordui);
38 g_warning ("[%s] Error while reloading schedule and recording content", __FUNCTION__);
44 mmyth_recordui_reload_schedule (MMythRecordUI *recordui)
47 ScheduleInfo *schedule_info;
50 GString *start_date_time = NULL;
51 GString *end_date_time = NULL;
52 GString *str_aux = g_string_new("");
55 gtk_tree_store_clear(recordui->sch_tree_store);
57 res = gmyth_scheduler_get_schedule_list(recordui->scheduler, &(schedule_list));
59 g_warning ("[%s] Retrieved NULL list of scheduled data from database",
64 for ( ; schedule_list; schedule_list = schedule_list->next) {
65 schedule_info = (ScheduleInfo*) schedule_list->data;
67 gtk_tree_store_insert(recordui->sch_tree_store, &iter, NULL, new_row++);
69 start_date_time = gmyth_util_time_to_string(schedule_info->start_time);
70 end_date_time = gmyth_util_time_to_string(schedule_info->end_time);
72 g_string_printf(str_aux, "%d", schedule_info->channel_id);
74 gtk_tree_store_set(recordui->sch_tree_store, &iter,
75 START_DATE_COLUMN, start_date_time->str,
76 TITLE_COLUMN, schedule_info->title->str,
77 CHAN_ID_COLUMN, str_aux->str,
78 END_TIME_COLUMN, end_date_time->str, //It doesn't appear
79 RECORD_ID_COLUMN, schedule_info->record_id,
80 -1); //the last line is a hidden item to be used in searching tasks
83 g_debug ("[%s] %d lines added to schedule list UI", __FUNCTION__, new_row);
85 /* free allocated memory */
87 g_string_free(start_date_time, FALSE);
89 g_string_free(end_date_time, FALSE);
90 g_string_free(str_aux, FALSE);
96 mmyth_recordui_reload_record (MMythRecordUI *recordui)
99 RecordedInfo *recorded_info;
100 GList *record_list = NULL;
102 GString *start_date_time = NULL;
103 GString *end_date_time = NULL;
104 GString *str_aux = g_string_new("");
107 gtk_tree_store_clear(recordui->rec_tree_store);
109 res = gmyth_scheduler_get_recorded_list(recordui->scheduler, &record_list);
111 g_warning ("[%s] Retrieved NULL list of recorded data from database", __FUNCTION__);
115 for (; record_list; record_list = record_list->next) {
116 recorded_info = (RecordedInfo*) record_list->data;
118 gtk_tree_store_insert(recordui->rec_tree_store, &iter, NULL, new_row++);
120 start_date_time = gmyth_util_time_to_string(recorded_info->start_time);
121 end_date_time = gmyth_util_time_to_string(recorded_info->end_time);
123 g_string_printf(str_aux, "%d", recorded_info->channel_id);
125 gtk_tree_store_set(recordui->rec_tree_store, &iter,
126 START_DATE_COLUMN, start_date_time->str,
127 TITLE_COLUMN, recorded_info->title->str,
128 CHAN_ID_COLUMN, str_aux->str,
129 END_TIME_COLUMN, end_date_time->str, //It doesn't appear
130 RECORD_ID_COLUMN, recorded_info->record_id,
131 BASENAME_COLUMN, recorded_info->basename->str, -1);
132 //the last line is a hidden item to be used in searching tasks
135 g_debug ("[%s] %d lines added to record list UI", __FUNCTION__, new_row);
142 mmyth_recordui_new(void)
144 MMythRecordUI *recordui = g_new0 (MMythRecordUI, 1);
146 recordui->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
147 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (recordui->scrolled_window),
148 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
150 recordui->viewport = gtk_viewport_new (NULL, NULL);
151 gtk_container_add (GTK_CONTAINER (recordui->scrolled_window), recordui->viewport);
153 recordui->notebook = gtk_notebook_new ();
154 gtk_container_set_border_width (GTK_CONTAINER (recordui->notebook), 1);
155 gtk_notebook_set_scrollable (GTK_NOTEBOOK (recordui->notebook), TRUE);
156 gtk_notebook_popup_enable (GTK_NOTEBOOK (recordui->notebook));
157 gtk_container_add (GTK_CONTAINER (recordui->viewport), recordui->notebook);
158 gtk_notebook_popup_disable(GTK_NOTEBOOK (recordui->notebook));
161 recordui->sch_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
162 gtk_container_add (GTK_CONTAINER (recordui->notebook), recordui->sch_scrolled_window);
163 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (recordui->sch_scrolled_window),
164 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
165 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (recordui->sch_scrolled_window),
168 /* The basename column in the sched_tree_store is not being used*/
169 recordui->sch_tree_store =
170 gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
171 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING );
173 recordui->sch_treeview =
174 gtk_tree_view_new_with_model(GTK_TREE_MODEL(recordui->sch_tree_store));
175 gtk_container_add (GTK_CONTAINER (recordui->sch_scrolled_window),
176 recordui->sch_treeview);
177 recordui->sch_renderer = gtk_cell_renderer_text_new();
178 //g_object_set(G_OBJECT(renderer1), "foreground", "green", "background", "black", NULL);
179 recordui->sch_column1 =
180 gtk_tree_view_column_new_with_attributes("Start time", recordui->sch_renderer,
181 "text", START_DATE_COLUMN, NULL);
182 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
183 recordui->sch_column1);
184 recordui->sch_column2 =
185 gtk_tree_view_column_new_with_attributes("Title", recordui->sch_renderer,
186 "text", TITLE_COLUMN, NULL);
187 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
188 recordui->sch_column2);
189 recordui->sch_column3 =
190 gtk_tree_view_column_new_with_attributes("Channel", recordui->sch_renderer,
191 "text", CHAN_ID_COLUMN, NULL);
192 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
193 recordui->sch_column3);
194 gtk_tree_view_column_set_resizable(recordui->sch_column1, TRUE);
195 gtk_tree_view_column_set_resizable(recordui->sch_column2, TRUE);
196 gtk_tree_view_column_set_resizable(recordui->sch_column3, TRUE);
197 gtk_tree_view_column_set_reorderable(recordui->sch_column1, TRUE);
198 gtk_tree_view_column_set_reorderable(recordui->sch_column2, TRUE);
199 gtk_tree_view_column_set_reorderable(recordui->sch_column3, TRUE);
200 // recordui->sch_column4 =
201 // gtk_tree_view_column_new_with_attributes("", recordui->sch_renderer, "text", END_TIME_COLUMN, NULL);
202 // gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->sch_treeview),
203 // recordui->sch_column4);
205 recordui->sch_label = gtk_label_new (("Schedule"));
206 gtk_notebook_set_tab_label (GTK_NOTEBOOK (recordui->notebook),
207 gtk_notebook_get_nth_page (
208 GTK_NOTEBOOK (recordui->notebook), 0),
209 recordui->sch_label);
212 // g_object_set(G_OBJECT(renderer2), "foreground", "blue", NULL);
213 recordui->rec_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
214 gtk_container_add (GTK_CONTAINER (recordui->notebook),
215 recordui->rec_scrolled_window);
216 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (recordui->rec_scrolled_window),
217 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
218 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (recordui->rec_scrolled_window),
221 recordui->rec_tree_store =
222 gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
223 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
224 recordui->rec_treeview =
225 gtk_tree_view_new_with_model(GTK_TREE_MODEL(recordui->rec_tree_store));
226 gtk_container_add (GTK_CONTAINER (recordui->rec_scrolled_window),
227 recordui->rec_treeview);
228 recordui->rec_renderer = gtk_cell_renderer_text_new();
229 //g_object_set(G_OBJECT(renderer1), "foreground", "green", "background", "black", NULL);
231 recordui->rec_column1 =
232 gtk_tree_view_column_new_with_attributes("Start time", recordui->rec_renderer,
233 "text", START_DATE_COLUMN, NULL);
234 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
235 recordui->rec_column1);
236 recordui->rec_column2 =
237 gtk_tree_view_column_new_with_attributes("Title", recordui->rec_renderer,
238 "text", TITLE_COLUMN, NULL);
239 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
240 recordui->rec_column2);
241 recordui->rec_column3 =
242 gtk_tree_view_column_new_with_attributes("Channel", recordui->rec_renderer,
243 "text", CHAN_ID_COLUMN, NULL);
244 gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview),
245 recordui->rec_column3);
246 gtk_tree_view_column_set_resizable(recordui->rec_column1, TRUE);
247 gtk_tree_view_column_set_resizable(recordui->rec_column2, TRUE);
248 gtk_tree_view_column_set_resizable(recordui->rec_column3, TRUE);
249 gtk_tree_view_column_set_reorderable(recordui->rec_column1, TRUE);
250 gtk_tree_view_column_set_reorderable(recordui->rec_column2, TRUE);
251 gtk_tree_view_column_set_reorderable(recordui->rec_column3, TRUE);
252 // recordui->rec_column4 = gtk_tree_view_column_new_with_attributes("", recordui->rec_renderer, "text", END_TIME_COLUMN, NULL);
253 // gtk_tree_view_append_column(GTK_TREE_VIEW(recordui->rec_treeview), recordui->rec_column4);
255 recordui->rec_label = gtk_label_new (("Recorded"));
256 gtk_notebook_set_tab_label (GTK_NOTEBOOK (recordui->notebook),
257 gtk_notebook_get_nth_page (
258 GTK_NOTEBOOK (recordui->notebook), 1),
259 recordui->rec_label);
261 // Gets the mmyth scheduler manager
262 recordui->scheduler = gmyth_scheduler_new ();
264 /* init connection to the backend */
265 gmyth_scheduler_connect (recordui->scheduler);
271 mmyth_recordui_free (MMythRecordUI *recordui)
273 // FIXME: Release memory here!
274 /* close connection to the backend */
275 gmyth_scheduler_disconnect (recordui->scheduler);
279 mmyth_recordui_delete_selected (GtkButton *button, MMythRecordUI *recordui)
281 GtkTreeSelection *selection;
282 GtkTreeModel *list_store;
287 curr_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(recordui->notebook));
289 if ( curr_page == 0) {
290 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(recordui->sch_treeview));
291 if (selection != NULL) {
292 gtk_tree_selection_get_selected(selection, &list_store, &iter);
293 gtk_tree_model_get(list_store, &iter, RECORD_ID_COLUMN, &index, -1);
294 gmyth_scheduler_delete_schedule(recordui->scheduler, index);
295 mmyth_recordui_reload_schedule (recordui);
299 } else if (curr_page == 1) {
300 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(recordui->rec_treeview));
301 if (selection != NULL) {
302 gtk_tree_selection_get_selected(selection, &list_store, &iter);
303 gtk_tree_model_get(list_store, &iter, RECORD_ID_COLUMN, &index, -1);
304 gmyth_scheduler_delete_recorded(recordui->scheduler, index);
305 mmyth_recordui_reload_record (recordui);
310 g_warning ("[%s] None element was removed from the list", __FUNCTION__);
313 /* FIXME: change this function name, it is returning the
314 * basename_column that represents the nuv filename of
315 * the recorded content */
317 mmyth_recordui_get_selected_recorded (MMythRecordUI *recordui)
319 GtkTreeSelection *selection = NULL;
320 GtkTreeModel *list_store = NULL;
324 /* returning nuv filename, basename_column */
325 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(recordui->rec_treeview));
326 if (gtk_tree_selection_get_selected (selection, &list_store, &iter)) {
327 gtk_tree_model_get(list_store, &iter, BASENAME_COLUMN, &path, -1);
330 // FIXME: MOVE THIS TO OTHER PLACE