Mostly minor fixes up until version 0.8.10.
[irreco.git] / irreco / src / core / irreco_remote_download_dlg.c
blob1db11b4e921d074641fe0e050330a53af3237b3a
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_remote_download_dlg.h"
21 #include "irreco_select_instance_dlg.h"
22 #include "irreco_theme_download_dlg.h"
23 #include <hildon/hildon-banner.h>
25 /**
26 * @addtogroup IrrecoRemoteDownloadDlg
27 * @ingroup Irreco
29 * @todo PURPOCE OF CLASS.
31 * @{
34 /**
35 * @file
36 * Source file of @ref IrrecoRemoteDownloadDlg.
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 /* Datatypes */
42 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 /** Button responce codes. */
45 enum {
46 IRRECO_REMOTE_REFRESH,
47 IRRECO_REMOTE_DOWNLOAD
50 /** GtkTreeStore colums. */
51 enum
53 TEXT_COL,
54 FLAG_COL,
55 DATA_COL,
56 N_COLUMNS
59 /** Loader states. */
60 enum
62 LOADER_STATE_INIT,
63 LOADER_STATE_LOOP,
64 LOADER_STATE_END,
65 LOADER_STATE_CLEANUP
68 /** Row flags. */
69 enum
71 ROW_CHILDREN_LOADED = 1 << 1,
72 ROW_TYPE_CATEGORY = 1 << 2,
73 ROW_TYPE_MANUFACTURER = 1 << 3,
74 ROW_TYPE_MODEL = 1 << 4,
75 ROW_TYPE_CREATOR = 1 << 5,
76 ROW_TYPE_REMOTE = 1 << 6,
77 ROW_TYPE_LOADING = 1 << 7
80 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
81 /* Prototypes */
82 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
84 static gboolean irreco_remote_download_dlg_map_event(
85 IrrecoRemoteDownloadDlg *self,
86 GdkEvent *event,
87 gpointer user_data);
88 static void irreco_remote_download_dlg_destroy_event(
89 IrrecoRemoteDownloadDlg *self,
90 gpointer user_data);
91 static void irreco_remote_download_dlg_row_activated_event(
92 GtkTreeView *tree_view,
93 GtkTreePath *path,
94 GtkTreeViewColumn *column,
95 IrrecoRemoteDownloadDlg *self);
96 static void irreco_remote_download_dlg_row_expanded_event(
97 GtkTreeView *tree_view,
98 GtkTreeIter *iter,
99 GtkTreePath *path,
100 IrrecoRemoteDownloadDlg *self);
101 static void irreco_remote_download_dlg_row_collapsed_event(
102 GtkTreeView *tree_view,
103 GtkTreeIter *iter,
104 GtkTreePath *path,
105 IrrecoRemoteDownloadDlg *self);
106 static void irreco_remote_download_dlg_row_selected_event(GtkTreeSelection *sel,
107 IrrecoRemoteDownloadDlg *self);
109 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
110 /* Construction & Destruction */
111 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
114 * @name Construction & Destruction
115 * @{
118 G_DEFINE_TYPE(IrrecoRemoteDownloadDlg, irreco_remote_download_dlg, IRRECO_TYPE_DLG)
120 static void irreco_remote_download_dlg_dispose(GObject *object)
122 G_OBJECT_CLASS(
123 irreco_remote_download_dlg_parent_class)->dispose(object);
126 static void irreco_remote_download_dlg_finalize(GObject *object)
128 G_OBJECT_CLASS(
129 irreco_remote_download_dlg_parent_class)->finalize(object);
132 static void irreco_remote_download_dlg_class_init(
133 IrrecoRemoteDownloadDlgClass *klass)
135 GObjectClass *object_class = G_OBJECT_CLASS (klass);
138 object_class->dispose = irreco_remote_download_dlg_dispose;
139 object_class->finalize = irreco_remote_download_dlg_finalize;
142 static void irreco_remote_download_dlg_init(IrrecoRemoteDownloadDlg *self)
144 GtkWidget *hbox;
145 PangoFontDescription *title_font;
146 PangoFontDescription *initial_font;
147 PangoFontDescription *menu_font;
149 /* Remotes */
150 GtkWidget *scrollbar;
151 GtkTreeViewColumn *column;
152 GtkCellRenderer *renderer;
153 GtkTreeSelection *select;
154 GtkWidget *tree_view_frame;
155 GtkWidget *tree_view_hbox;
157 /* Details */
158 GtkWidget *help_hbox = NULL;
159 GtkWidget *details_alignment;
160 GtkWidget *details_frame;
161 GtkWidget *details_table;
162 GtkWidget *label;
163 IRRECO_ENTER
165 self->remote = NULL;
167 /* Create fonts */
168 initial_font = pango_font_description_from_string("Sans 11");
169 menu_font = pango_font_description_from_string("Sans 13");
170 title_font = pango_font_description_from_string("Sans Bold 12");
172 /* Build the dialog */
173 gtk_window_set_title(GTK_WINDOW(self), _("Download Remote"));
174 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
175 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
176 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
177 gtk_dialog_add_buttons(GTK_DIALOG(self),
178 GTK_STOCK_REFRESH, IRRECO_REMOTE_REFRESH,
179 _("Download"), IRRECO_REMOTE_DOWNLOAD,
180 NULL);
182 /* Create hbox */
183 hbox = g_object_new(GTK_TYPE_HBOX, NULL);
184 gtk_box_set_spacing(GTK_BOX(hbox), 8);
185 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self)->vbox),
186 irreco_gtk_align(GTK_WIDGET(hbox),
187 0, 0, 1, 1, 8, 8, 8, 8));
189 /* Create tree_view_hbox */
190 tree_view_hbox = g_object_new(GTK_TYPE_HBOX, NULL);
192 /* Create Treeview */
193 self->tree_store = gtk_tree_store_new(
194 N_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_POINTER);
195 self->tree_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(
196 GTK_TREE_MODEL(self->tree_store)));
198 renderer = gtk_cell_renderer_text_new();
199 g_object_set(renderer, "font-desc", menu_font, NULL);
201 column = gtk_tree_view_column_new_with_attributes(
202 NULL, renderer, "text", TEXT_COL, NULL);
203 gtk_tree_view_append_column(self->tree_view, column);
205 gtk_box_pack_start(GTK_BOX(tree_view_hbox), GTK_WIDGET(self->tree_view),
206 TRUE, TRUE, 0);
208 /* Create scrollbar for Treeview */
209 scrollbar = gtk_vscrollbar_new(gtk_tree_view_get_vadjustment(
210 GTK_TREE_VIEW(self->tree_view)));
211 gtk_box_pack_start(GTK_BOX(tree_view_hbox), GTK_WIDGET(scrollbar),
212 FALSE, TRUE, 0);
214 /* Create Frame for Treeview */
215 tree_view_frame = gtk_frame_new("");
216 gtk_frame_set_label_widget(GTK_FRAME(tree_view_frame),
217 irreco_gtk_label_bold("Remotes", 0, 0, 0, 0, 0, 0));
219 gtk_container_add(GTK_CONTAINER(tree_view_frame),
220 GTK_WIDGET(tree_view_hbox));
222 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(tree_view_frame),
223 TRUE, TRUE, 0);
225 /* Create details_table */
226 details_table = gtk_table_new(7, 4, FALSE);
227 gtk_table_set_row_spacings(GTK_TABLE(details_table), 4);
229 label = gtk_label_new("Model: ");
230 gtk_widget_modify_font(label, title_font);
231 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
232 gtk_table_attach(GTK_TABLE(details_table), label,
233 0, 1, 0, 1, GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
235 label = gtk_label_new("Creator: ");
236 gtk_widget_modify_font(label, title_font);
237 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
238 gtk_table_attach(GTK_TABLE(details_table), label,
239 0, 1, 1, 2, GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
241 label = gtk_label_new("Backends: ");
242 gtk_widget_modify_font(label, title_font);
243 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
244 gtk_table_attach(GTK_TABLE(details_table), label,
245 0, 1, 2, 3, GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
247 label = gtk_label_new("Themes: ");
248 gtk_widget_modify_font(label, title_font);
249 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
250 gtk_table_attach(GTK_TABLE(details_table), label,
251 0, 1, 3, 4, GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
253 label = gtk_label_new("Downloaded: ");
254 gtk_widget_modify_font(label, title_font);
255 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
256 gtk_table_attach(GTK_TABLE(details_table), label,
257 0, 1, 4, 5, GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
259 label = gtk_label_new("Comment: ");
260 gtk_widget_modify_font(label, title_font);
261 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
262 gtk_table_attach(GTK_TABLE(details_table), label,
263 0, 1, 5, 6, GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
265 self->details_model = gtk_label_new("");
266 gtk_widget_modify_font(self->details_model, initial_font);
267 gtk_misc_set_alignment(GTK_MISC(self->details_model), 0, 0);
268 gtk_table_attach(GTK_TABLE(details_table), self->details_model,
269 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
271 self->details_creator = gtk_label_new("");
272 gtk_widget_modify_font(self->details_creator, initial_font);
273 gtk_misc_set_alignment(GTK_MISC(self->details_creator), 0, 0);
274 gtk_table_attach(GTK_TABLE(details_table), self->details_creator,
275 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
277 self->details_backends = gtk_label_new("");
278 gtk_widget_modify_font(self->details_backends, initial_font);
279 gtk_misc_set_alignment(GTK_MISC(self->details_backends), 0, 0);
280 gtk_table_attach(GTK_TABLE(details_table), self->details_backends,
281 1, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
283 self->details_themes = gtk_label_new("");
284 gtk_widget_modify_font(self->details_themes, initial_font);
285 gtk_misc_set_alignment(GTK_MISC(self->details_themes), 0, 0);
286 gtk_table_attach(GTK_TABLE(details_table), self->details_themes,
287 1, 2, 3, 4, GTK_FILL, GTK_FILL, 0, 0);
289 self->details_downloaded = gtk_label_new("");
290 gtk_widget_modify_font(self->details_downloaded, initial_font);
291 gtk_misc_set_alignment(GTK_MISC(self->details_downloaded), 0, 0);
292 gtk_table_attach(GTK_TABLE(details_table), self->details_downloaded,
293 1, 2, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
295 self->details_comment = gtk_text_view_new();
296 gtk_widget_modify_font(self->details_comment, initial_font);
297 gtk_misc_set_alignment(GTK_MISC(self->details_comment), 0, 0);
298 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(self->details_comment),
299 FALSE);
300 gtk_text_view_set_editable(GTK_TEXT_VIEW(self->details_comment),
301 FALSE);
302 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self->details_comment),
303 GTK_WRAP_WORD_CHAR);
304 gtk_table_attach(GTK_TABLE(details_table), self->details_comment,
305 0, 4, 6, 7, GTK_FILL, GTK_FILL, 0, 0);
306 gtk_widget_set_size_request(GTK_WIDGET(self->details_comment), 241, -1);
308 /* Details */
309 self->details = gtk_scrolled_window_new(NULL, NULL);
310 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->details),
311 GTK_POLICY_AUTOMATIC,
312 GTK_POLICY_AUTOMATIC);
314 gtk_widget_set_size_request(GTK_WIDGET(self->details), 285, -1);
316 /* Create frame for Details */
317 details_frame = gtk_frame_new("");
318 gtk_frame_set_label_widget(GTK_FRAME(details_frame),
319 irreco_gtk_label_bold("Details", 0, 0, 0, 0, 0, 0));
321 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(details_frame),
322 FALSE, TRUE, 0);
324 /* Create alignment */
325 details_alignment = gtk_alignment_new(0, 0, 0, 0);
326 gtk_alignment_set_padding(GTK_ALIGNMENT(details_alignment), 0, 8, 8, 8);
328 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
329 self->details),
330 details_alignment);
332 gtk_container_add(GTK_CONTAINER(details_alignment), details_table);
334 /* Help text */
335 self->help_text = gtk_label_new("Select Remote");
336 gtk_label_set_justify(GTK_LABEL(self->help_text), GTK_JUSTIFY_CENTER);
337 gtk_label_set_line_wrap(GTK_LABEL(self->help_text), TRUE);
338 self->help_text = irreco_gtk_align(self->help_text,
339 0.5, 0.5, 1, 1, 8, 8, 8, 8);
341 help_hbox = gtk_hbox_new(0, 0);
343 gtk_box_pack_start(GTK_BOX(help_hbox), GTK_WIDGET(self->details),
344 TRUE, TRUE, 0);
345 gtk_box_pack_start(GTK_BOX(help_hbox), GTK_WIDGET(self->help_text),
346 TRUE, TRUE, 0);
348 gtk_container_add(GTK_CONTAINER(details_frame), GTK_WIDGET(help_hbox));
350 /* Setup the selection handler for TREE */
351 select = gtk_tree_view_get_selection(self->tree_view);
352 gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
354 /* Signal handlers. */
356 g_signal_connect(G_OBJECT(self), "map-event", G_CALLBACK(
357 irreco_remote_download_dlg_map_event), NULL);
358 g_signal_connect(G_OBJECT(self), "destroy", G_CALLBACK(
359 irreco_remote_download_dlg_destroy_event), NULL);
360 g_signal_connect(G_OBJECT(self->tree_view), "row-activated", G_CALLBACK(
361 irreco_remote_download_dlg_row_activated_event), self);
362 g_signal_connect(G_OBJECT(self->tree_view), "row-expanded", G_CALLBACK(
363 irreco_remote_download_dlg_row_expanded_event), self);
364 g_signal_connect(G_OBJECT(self->tree_view), "row-collapsed", G_CALLBACK(
365 irreco_remote_download_dlg_row_collapsed_event), self);
366 g_signal_connect(G_OBJECT(select), "changed", G_CALLBACK(
367 irreco_remote_download_dlg_row_selected_event), self);
369 gtk_tree_view_set_enable_tree_lines(self->tree_view, TRUE);
370 g_object_set (G_OBJECT (self->tree_view), "show-expanders", TRUE, NULL);
371 g_object_set (G_OBJECT (self->tree_view), "level-indentation", 0, NULL);
372 gtk_tree_view_set_rubber_banding(self->tree_view, FALSE);
374 gtk_widget_set_size_request(GTK_WIDGET(self), -1, 300);
376 gtk_widget_show_all(GTK_WIDGET(self));
377 gtk_widget_hide(GTK_WIDGET(self->details));
379 IRRECO_RETURN
382 IrrecoRemoteDownloadDlg* irreco_remote_download_dlg_new(IrrecoData *irreco_data,
383 GtkWindow *parent)
385 IrrecoRemoteDownloadDlg *self;
386 IRRECO_ENTER
388 self = g_object_new(IRRECO_TYPE_REMOTE_DOWNLOAD_DLG, NULL);
389 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
390 self->irreco_data = irreco_data;
391 IRRECO_RETURN_PTR(self);
395 /** @} */
399 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
400 /* Private Functions */
401 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
404 * @name Private Functions
405 * @{
409 * Clean detail list
412 static void irreco_remote_download_dlg_clean_details(
413 IrrecoRemoteDownloadDlg *self)
415 GtkTextBuffer *buffer;
416 IRRECO_ENTER
418 self->remote = NULL;
419 gtk_label_set_text(GTK_LABEL(self->details_model), "");
420 gtk_label_set_text(GTK_LABEL(self->details_creator), "");
421 gtk_label_set_text(GTK_LABEL(self->details_backends), "");
422 gtk_label_set_text(GTK_LABEL(self->details_themes), "");
423 gtk_label_set_text(GTK_LABEL(self->details_downloaded), "");
424 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self->details_comment));
425 gtk_text_buffer_set_text(buffer, " ", 1);
426 gtk_text_view_set_buffer(GTK_TEXT_VIEW(self->details_comment), buffer);
428 IRRECO_RETURN
432 * Have the childern of this item been loaded.
434 * @return TRUE if children have been loade, FALSE otherwise.
436 static gboolean irreco_remote_download_dlg_row_is_loaded(
437 IrrecoRemoteDownloadDlg *self,
438 GtkTreeIter *iter)
440 gint i;
441 IRRECO_ENTER
443 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
444 iter, FLAG_COL, &i, -1);
445 if (i & ROW_CHILDREN_LOADED) IRRECO_RETURN_BOOL(TRUE);
446 IRRECO_RETURN_BOOL(FALSE);
450 * Enable / Disable ROW_CHILDREN_LOADED flag from a row.
452 * @param value If set, ROW_CHILDREN_LOADED will be enabled.
454 static void irreco_remote_download_dlg_row_set_loaded(IrrecoRemoteDownloadDlg *self,
455 GtkTreeIter *iter,
456 gboolean value)
458 gint i;
459 IRRECO_ENTER
461 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
462 iter, FLAG_COL, &i, -1);
463 if (value) {
464 i = i | ROW_CHILDREN_LOADED;
465 } else {
466 i = i & ~ROW_CHILDREN_LOADED;
468 gtk_tree_store_set(self->tree_store, iter, FLAG_COL, i, -1);
470 IRRECO_RETURN
474 * Get type of row.
476 static gint irreco_remote_download_dlg_row_get_type(
477 IrrecoRemoteDownloadDlg *self,
478 GtkTreeIter *iter)
480 gint i;
481 IRRECO_ENTER
483 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
484 iter, FLAG_COL, &i, -1);
485 if (i & ROW_TYPE_CATEGORY)
486 IRRECO_RETURN_ENUM(ROW_TYPE_CATEGORY);
487 if (i & ROW_TYPE_MANUFACTURER)
488 IRRECO_RETURN_ENUM(ROW_TYPE_MANUFACTURER);
489 if (i & ROW_TYPE_MODEL)
490 IRRECO_RETURN_ENUM(ROW_TYPE_MODEL);
491 if (i & ROW_TYPE_CREATOR)
492 IRRECO_RETURN_ENUM(ROW_TYPE_CREATOR);
493 if (i & ROW_TYPE_REMOTE)
494 IRRECO_RETURN_ENUM(ROW_TYPE_REMOTE);
495 if (i & ROW_TYPE_LOADING)
496 IRRECO_RETURN_ENUM(ROW_TYPE_LOADING);
497 IRRECO_RETURN_INT(0);
501 * Show hildon progressbar banner.
503 * This function will create a new banner if one has not been created yet,
504 * if banner already exists, it's properties will be changed.
506 * @param text Text to show.
507 * @param fraction Value of progress.
509 static void irreco_remote_download_dlg_set_banner(IrrecoRemoteDownloadDlg *self,
510 const gchar *text,
511 gdouble fraction)
513 IRRECO_ENTER
514 if (self->banner == NULL) {
515 self->banner = hildon_banner_show_progress(GTK_WIDGET(self),
516 NULL, "");
519 hildon_banner_set_text(HILDON_BANNER(self->banner), text);
520 hildon_banner_set_fraction(HILDON_BANNER(self->banner), fraction);
521 IRRECO_RETURN
525 * Destroy banner, if it exists.
527 static void irreco_remote_download_dlg_hide_banner(
528 IrrecoRemoteDownloadDlg *self)
530 IRRECO_ENTER
531 if (self->banner) {
532 gtk_widget_destroy(self->banner);
533 self->banner = NULL;
535 IRRECO_RETURN
539 * Start a loader state machine if one is not running already.
541 static void irreco_remote_download_dlg_loader_start(
542 IrrecoRemoteDownloadDlg *self,
543 GSourceFunc function,
544 GtkTreeIter *parent_iter)
546 IRRECO_ENTER
548 if (self->loader_func_id == 0) {
549 if (parent_iter) {
550 self->loader_parent_iter = gtk_tree_iter_copy(
551 parent_iter);
554 if (function) {
555 self->loader_func_id = g_idle_add(function, self);
556 } else {
557 IRRECO_ERROR("Loader function pointer not given.\n");
561 IRRECO_RETURN
565 * Stop and cleanup loader if a loader is running.
567 static void irreco_remote_download_dlg_loader_stop(
568 IrrecoRemoteDownloadDlg *self)
570 IRRECO_ENTER
571 if (self->loader_func_id != 0) {
572 g_source_remove(self->loader_func_id);
573 self->loader_func_id = 0;
574 self->loader_state = 0;
575 if (self->loader_parent_iter) {
576 gtk_tree_iter_free(self->loader_parent_iter);
578 self->loader_parent_iter = NULL;
580 IRRECO_RETURN
583 static gboolean irreco_remote_download_dlg_loader_categ(
584 IrrecoRemoteDownloadDlg *self)
586 IRRECO_ENTER
588 switch (self->loader_state) {
589 case LOADER_STATE_INIT:
590 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
592 self->loader_state = LOADER_STATE_LOOP;
593 irreco_remote_download_dlg_clean_details(self);
594 IRRECO_RETURN_BOOL(TRUE);
596 case LOADER_STATE_LOOP: {
597 GtkTreeIter iter;
598 GtkTreeIter iter_loading;
599 IrrecoStringTable *categories;
600 IrrecoWebdbCache *webdb_cache = NULL;
602 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data,
603 FALSE);
604 if(irreco_webdb_cache_get_remote_categories(webdb_cache,
605 &categories)) {
606 IRRECO_STRING_TABLE_FOREACH_KEY(categories, key)
608 /* Append categogy. */
609 gtk_tree_store_append(self->tree_store,
610 &iter, NULL);
611 gtk_tree_store_set(self->tree_store,
612 &iter, TEXT_COL, key,
613 FLAG_COL, ROW_TYPE_CATEGORY,
614 DATA_COL, NULL, -1);
616 /* Add loading item into category. */
617 gtk_tree_store_append(self->tree_store,
618 &iter_loading, &iter);
619 gtk_tree_store_set(self->tree_store,
620 &iter_loading,
621 TEXT_COL, _("Loading ..."),
622 FLAG_COL, ROW_TYPE_LOADING,
623 DATA_COL, NULL, -1);
624 IRRECO_STRING_TABLE_FOREACH_END
625 } else {
626 irreco_error_dlg(GTK_WINDOW(self),
627 irreco_webdb_cache_get_error(
628 webdb_cache));
631 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
633 self->loader_state = LOADER_STATE_END;
634 IRRECO_RETURN_BOOL(TRUE);
637 case LOADER_STATE_END:
638 irreco_remote_download_dlg_hide_banner(self);
639 irreco_remote_download_dlg_loader_stop(self);
642 IRRECO_RETURN_BOOL(FALSE);
645 static gboolean irreco_remote_download_dlg_loader_manuf(
646 IrrecoRemoteDownloadDlg *self)
648 IRRECO_ENTER
650 switch (self->loader_state) {
651 case LOADER_STATE_INIT:
652 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
654 self->loader_state = LOADER_STATE_LOOP;
655 IRRECO_RETURN_BOOL(TRUE);
657 case LOADER_STATE_LOOP: {
658 GtkTreeIter iter;
659 GtkTreeIter iter_loading;
660 IrrecoStringTable *manufacturers;
661 IrrecoWebdbCache *webdb_cache = NULL;
662 gchar *category;
664 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
665 self->loader_parent_iter,
666 TEXT_COL, &category, -1);
668 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data,
669 FALSE);
671 if(irreco_webdb_cache_get_remote_manufacturers(webdb_cache,
672 category,
673 &manufacturers)) {
674 IRRECO_STRING_TABLE_FOREACH_KEY(manufacturers, key)
676 /* Add manufacturer item into category. */
677 gtk_tree_store_append(self->tree_store,
678 &iter, self->loader_parent_iter);
679 gtk_tree_store_set(self->tree_store,
680 &iter,
681 TEXT_COL, key,
682 FLAG_COL, ROW_TYPE_MANUFACTURER,
683 DATA_COL, NULL, -1);
685 /* Add loading item into manufacturer. */
686 gtk_tree_store_append(self->tree_store,
687 &iter_loading, &iter);
688 gtk_tree_store_set(self->tree_store,
689 &iter_loading,
690 TEXT_COL, _("Loading ..."),
691 FLAG_COL, ROW_TYPE_LOADING,
692 DATA_COL, NULL, -1);
694 IRRECO_STRING_TABLE_FOREACH_END
695 } else {
696 irreco_error_dlg(GTK_WINDOW(self),
697 irreco_webdb_cache_get_error(
698 webdb_cache));
701 g_free (category);
703 /* Delete loading item from category. */
704 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self->tree_store),
705 &iter,self->loader_parent_iter,0);
706 if(irreco_remote_download_dlg_row_get_type(self,
707 &iter) == ROW_TYPE_LOADING) {
708 gtk_tree_store_remove(self->tree_store,&iter);
710 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
712 self->loader_state = LOADER_STATE_END;
713 IRRECO_RETURN_BOOL(TRUE);
716 case LOADER_STATE_END:
717 irreco_remote_download_dlg_row_set_loaded(
718 self, self->loader_parent_iter,
719 TRUE);
720 irreco_remote_download_dlg_hide_banner(self);
721 irreco_remote_download_dlg_loader_stop(self);
724 IRRECO_RETURN_BOOL(FALSE);
727 static gboolean irreco_remote_download_dlg_loader_model(
728 IrrecoRemoteDownloadDlg *self)
730 IRRECO_ENTER
732 switch (self->loader_state) {
733 case LOADER_STATE_INIT:
734 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
736 self->loader_state = LOADER_STATE_LOOP;
737 IRRECO_RETURN_BOOL(TRUE);
739 case LOADER_STATE_LOOP: {
740 GtkTreeIter iter;
741 GtkTreeIter iter_loading;
742 GtkTreeIter category_iter;
743 IrrecoStringTable *models = NULL;
744 IrrecoWebdbCache *webdb_cache = NULL;
745 gchar *category;
746 gchar *manufacturer;
748 /*Get category and manufacturer*/
750 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
751 self->loader_parent_iter,
752 TEXT_COL, &manufacturer, -1);
754 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self->tree_store),
755 &category_iter,
756 self->loader_parent_iter);
758 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
759 &category_iter,
760 TEXT_COL, &category, -1);
762 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data,
763 FALSE);
765 if(irreco_webdb_cache_get_remote_models(webdb_cache, category,
766 manufacturer, &models)){
768 IRRECO_STRING_TABLE_FOREACH_KEY(models, key)
770 /* Add model item into manufacturer. */
771 gtk_tree_store_append(self->tree_store,
772 &iter, self->loader_parent_iter);
773 gtk_tree_store_set(self->tree_store,
774 &iter,
775 TEXT_COL, key,
776 FLAG_COL, ROW_TYPE_MODEL,
777 DATA_COL, NULL, -1);
779 /* Add loading item into model. */
780 gtk_tree_store_append(self->tree_store,
781 &iter_loading, &iter);
782 gtk_tree_store_set(self->tree_store,
783 &iter_loading,
784 TEXT_COL, _("Loading ..."),
785 FLAG_COL, ROW_TYPE_LOADING,
786 DATA_COL, NULL, -1);
788 IRRECO_STRING_TABLE_FOREACH_END
789 } else {
790 irreco_error_dlg(GTK_WINDOW(self),
791 irreco_webdb_cache_get_error(
792 webdb_cache));
794 g_free (category);
795 g_free (manufacturer);
797 /* Delete loading item from manufacturer. */
798 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self->tree_store),
799 &iter, self->loader_parent_iter,
801 if(irreco_remote_download_dlg_row_get_type(self,
802 &iter) == ROW_TYPE_LOADING) {
803 gtk_tree_store_remove(self->tree_store, &iter);
806 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
808 self->loader_state = LOADER_STATE_END;
810 IRRECO_RETURN_BOOL(TRUE);
812 case LOADER_STATE_END:
813 irreco_remote_download_dlg_row_set_loaded(
814 self, self->loader_parent_iter,
815 TRUE);
816 irreco_remote_download_dlg_hide_banner(self);
817 irreco_remote_download_dlg_loader_stop(self);
820 IRRECO_RETURN_BOOL(FALSE);
823 static gboolean irreco_remote_download_dlg_loader_creators(
824 IrrecoRemoteDownloadDlg *self)
826 IRRECO_ENTER
828 switch (self->loader_state) {
829 case LOADER_STATE_INIT:
830 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
832 self->loader_state = LOADER_STATE_LOOP;
833 IRRECO_RETURN_BOOL(TRUE);
835 case LOADER_STATE_LOOP: {
836 IrrecoWebdbCache *webdb_cache = NULL;
838 GtkTreeIter category_iter;
839 GtkTreeIter manufacturer_iter;
840 GtkTreeIter iter;
841 GtkTreeIter iter_loading;
843 gchar *category;
844 gchar *manufacturer;
845 gchar *model;
847 IrrecoStringTable *creators;
849 /*Get manufacturer_iter and category_iter */
851 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self->tree_store),
852 &manufacturer_iter,
853 self->loader_parent_iter);
855 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self->tree_store),
856 &category_iter,
857 &manufacturer_iter);
859 /*Get category, manufacturer and model*/
861 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
862 &category_iter,
863 TEXT_COL, &category, -1);
865 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
866 &manufacturer_iter,
867 TEXT_COL, &manufacturer, -1);
869 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
870 self->loader_parent_iter,
871 TEXT_COL, &model, -1);
874 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data,
875 FALSE);
877 if(irreco_webdb_cache_get_remote_creators(webdb_cache,
878 category, manufacturer, model, &creators)){
880 IRRECO_STRING_TABLE_FOREACH_KEY(creators, key)
882 /* Add model item into manufacturer. */
883 gtk_tree_store_append(self->tree_store,
884 &iter, self->loader_parent_iter);
885 gtk_tree_store_set(self->tree_store,
886 &iter,
887 TEXT_COL, key,
888 FLAG_COL, ROW_TYPE_CREATOR,
889 DATA_COL, NULL, -1);
891 /* Add loading item into model. */
892 gtk_tree_store_append(self->tree_store,
893 &iter_loading, &iter);
894 gtk_tree_store_set(self->tree_store,
895 &iter_loading,
896 TEXT_COL, _("Loading ..."),
897 FLAG_COL, ROW_TYPE_LOADING,
898 DATA_COL, NULL, -1);
900 IRRECO_STRING_TABLE_FOREACH_END
901 } else {
902 irreco_error_dlg(GTK_WINDOW(self),
903 irreco_webdb_cache_get_error(
904 webdb_cache));
906 g_free (category);
907 g_free (manufacturer);
908 g_free (model);
910 /* Delete loading item from manufacturer. */
911 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self->tree_store),
912 &iter, self->loader_parent_iter,
914 if(irreco_remote_download_dlg_row_get_type(self,
915 &iter) == ROW_TYPE_LOADING) {
916 gtk_tree_store_remove(self->tree_store, &iter);
919 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
921 self->loader_state = LOADER_STATE_END;
923 IRRECO_RETURN_BOOL(TRUE);
925 case LOADER_STATE_END:
926 irreco_remote_download_dlg_row_set_loaded(
927 self, self->loader_parent_iter,
928 TRUE);
929 irreco_remote_download_dlg_hide_banner(self);
930 irreco_remote_download_dlg_loader_stop(self);
933 IRRECO_RETURN_BOOL(FALSE);
936 static gboolean irreco_remote_download_dlg_loader_remotes(
937 IrrecoRemoteDownloadDlg *self)
939 IRRECO_ENTER
941 switch (self->loader_state) {
942 case LOADER_STATE_INIT:
943 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
945 self->loader_state = LOADER_STATE_LOOP;
946 self->loader_pos = 0;
947 IRRECO_RETURN_BOOL(TRUE);
949 case LOADER_STATE_LOOP: {
950 IrrecoWebdbCache *webdb_cache = NULL;
952 GtkTreeIter category_iter;
953 GtkTreeIter manufacturer_iter;
954 GtkTreeIter model_iter;
955 GtkTreeIter iter;
957 gchar *category;
958 gchar *manufacturer;
959 gchar *model;
960 gchar *creator;
962 /* Remote info */
963 gint remote_id;
964 IrrecoWebdbRemote *remote;
965 GList *remotes = NULL;
966 GList *configs;
967 GList *themes;
969 /* Banner info */
970 gint remote_count = 0;
971 gfloat banner;
973 /*Get manufacturer_iter and category_iter */
975 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self->tree_store),
976 &model_iter,
977 self->loader_parent_iter);
979 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self->tree_store),
980 &manufacturer_iter,
981 &model_iter);
983 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self->tree_store),
984 &category_iter,
985 &manufacturer_iter);
987 /*Get category, manufacturer and model*/
989 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
990 &category_iter,
991 TEXT_COL, &category, -1);
993 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
994 &manufacturer_iter,
995 TEXT_COL, &manufacturer, -1);
997 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
998 &model_iter,
999 TEXT_COL, &model, -1);
1001 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1002 self->loader_parent_iter,
1003 TEXT_COL, &creator, -1);
1006 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data,
1007 FALSE);
1009 if(!irreco_webdb_cache_get_remotes(webdb_cache,
1010 category, manufacturer, model, creator, &remotes)) {
1011 irreco_error_dlg(GTK_WINDOW(self),
1012 irreco_webdb_cache_get_error(
1013 webdb_cache));
1014 goto end;
1017 remote_id = GPOINTER_TO_INT(g_list_nth_data(remotes,
1018 self->loader_pos));
1020 if(!irreco_webdb_cache_get_remote_by_id(webdb_cache, remote_id,
1021 &remote)) {
1022 irreco_error_dlg(GTK_WINDOW(self),
1023 irreco_webdb_cache_get_error(
1024 webdb_cache));
1025 goto end;
1028 /* Get information of configurations */
1029 if (!irreco_webdb_cache_get_configurations_of_remote(
1030 webdb_cache, remote_id, &configs)) {
1031 irreco_error_dlg(GTK_WINDOW(self),
1032 irreco_webdb_cache_get_error(
1033 webdb_cache));
1034 goto end;
1037 configs = g_list_first(configs);
1038 while(configs) {
1039 IrrecoWebdbConf *config;
1040 if (GPOINTER_TO_INT(configs->data) != 0 &&
1041 !irreco_webdb_cache_get_configuration(webdb_cache,
1042 GPOINTER_TO_INT(configs->data), &config)) {
1043 irreco_error_dlg(GTK_WINDOW(self),
1044 irreco_webdb_cache_get_error(
1045 webdb_cache));
1047 configs = configs->next;
1050 /* Get information of themes*/
1051 if (!irreco_webdb_cache_get_themes_of_remote(
1052 webdb_cache, remote_id, &themes)) {
1053 irreco_error_dlg(GTK_WINDOW(self),
1054 irreco_webdb_cache_get_error(
1055 webdb_cache));
1056 goto end;
1059 themes = g_list_first(themes);
1060 while(themes) {
1061 IrrecoWebdbTheme *theme;
1062 if (GPOINTER_TO_INT(themes->data) != 0 &&
1063 !irreco_webdb_cache_get_theme_by_id(webdb_cache,
1064 GPOINTER_TO_INT(themes->data), &theme)) {
1065 irreco_error_dlg(GTK_WINDOW(self),
1066 irreco_webdb_cache_get_error(
1067 webdb_cache));
1069 themes = themes->next;
1072 /* Add config item into model. */
1073 gtk_tree_store_append(self->tree_store, &iter,
1074 self->loader_parent_iter);
1076 gtk_tree_store_set(self->tree_store, &iter,
1077 TEXT_COL, remote->uploaded->str,
1078 FLAG_COL, ROW_TYPE_REMOTE,
1079 DATA_COL, GINT_TO_POINTER(remote_id), -1);
1081 /* Delete loading item from model. */
1082 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self->tree_store),
1083 &iter, self->loader_parent_iter,
1086 if (irreco_remote_download_dlg_row_get_type(self,
1087 &iter) == ROW_TYPE_LOADING) {
1088 gtk_tree_store_remove(self->tree_store, &iter);
1091 end:
1092 g_free (category);
1093 g_free (manufacturer);
1094 g_free (model);
1095 g_free (creator);
1097 /* Banner */
1099 if (remotes != NULL) {
1100 remote_count = g_list_length(remotes);
1103 banner = ((float) self->loader_pos + 1) / (float) remote_count;
1104 irreco_remote_download_dlg_set_banner(self, _("Loading ..."),
1105 banner);
1107 if (self->loader_pos + 1 >= remote_count) {
1108 self->loader_state = LOADER_STATE_END;
1109 IRRECO_RETURN_BOOL(TRUE);
1110 } else {
1111 self->loader_pos++;
1112 IRRECO_RETURN_BOOL(TRUE);
1116 IRRECO_RETURN_BOOL(TRUE);
1118 case LOADER_STATE_END:
1119 irreco_remote_download_dlg_row_set_loaded(
1120 self, self->loader_parent_iter,
1121 TRUE);
1122 irreco_remote_download_dlg_hide_banner(self);
1123 irreco_remote_download_dlg_loader_stop(self);
1126 IRRECO_RETURN_BOOL(FALSE);
1129 static gboolean irreco_remote_download_dlg_load_configs(
1130 IrrecoRemoteDownloadDlg *self)
1132 IrrecoWebdbCache *webdb_cache = NULL;
1133 IrrecoBackendInstance *inst = NULL;
1134 GString *error_msg = g_string_new("");
1135 IrrecoBackendManager *manager;
1136 IrrecoBackendFileContainer *file_container = NULL;
1137 GString *file_data = NULL;
1138 gchar *sha1 = NULL;
1139 gboolean success = TRUE;
1140 gboolean new_instance = FALSE;
1141 GList *configurations;
1142 IrrecoWebdbConf *config;
1143 GString *instance_number = g_string_new("");
1144 IRRECO_ENTER
1146 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data, FALSE);
1148 configurations = g_list_first(self->remote->configurations);
1149 if (configurations == NULL ||
1150 GPOINTER_TO_INT(configurations->data) == 0) {
1151 goto end;
1153 while(configurations) {
1155 if (!irreco_webdb_cache_get_configuration(webdb_cache,
1156 GPOINTER_TO_INT(configurations->data), &config)) {
1157 g_string_printf(error_msg, "%s",
1158 irreco_webdb_cache_get_error(
1159 webdb_cache));
1162 if(config == NULL) {
1163 g_string_printf(error_msg, "Configuration is NULL");
1164 goto end;
1167 /* Get file_data */
1168 if (!irreco_webdb_cache_get_file(webdb_cache,
1169 config->file_hash->str,
1170 config->file_name->str,
1171 &file_data)) {
1172 g_string_printf(error_msg, "%s",
1173 irreco_webdb_cache_get_error(
1174 webdb_cache));
1175 goto end;
1178 sha1 = g_compute_checksum_for_string(G_CHECKSUM_SHA1,
1179 file_data->str, -1);
1181 if (g_utf8_collate(config->file_hash->str, sha1) != 0) {
1182 g_string_printf(error_msg, "sha1 checksum failed.");
1183 goto end;
1187 /* Search backend */
1188 manager = self->irreco_data->irreco_backend_manager;
1189 IRRECO_BACKEND_MANAGER_FOREACH_LIB(manager, lib)
1190 if (!g_str_equal(lib->name, config->backend->str)) {
1191 continue;
1193 if (!(lib->api->flags &
1194 IRRECO_BACKEND_EDITABLE_DEVICES)) {
1195 g_string_printf(error_msg,
1196 "\"%s\" backend is not editable...",
1197 config->backend->str);
1198 goto end;
1200 else if (!(lib->api->flags &
1201 IRRECO_BACKEND_CONFIGURATION_EXPORT)) {
1202 g_string_printf(error_msg,
1203 "\"%s\" backend doesn't support "
1204 "exporting its configuration...",
1205 config->backend->str);
1206 goto end;
1208 /* Check if many instances */
1209 IRRECO_BACKEND_MANAGER_FOREACH_INSTANCE(manager,
1210 instance)
1211 irreco_backend_instance_get_description(
1212 instance);
1213 if (g_str_equal(instance->lib->name,
1214 config->backend->str)) {
1215 g_string_printf(instance_number, "%s",
1216 instance->name->str);
1217 g_string_erase(instance_number, 0,
1218 instance->name->len - 1);
1219 if (g_str_equal(instance_number->str,
1220 "1")) {
1221 inst = instance;
1222 IRRECO_DEBUG("SELECTED %s",
1223 instance->name->str);
1224 goto instance_ready;
1227 IRRECO_BACKEND_MANAGER_FOREACH_END
1229 /* Create new instance if it comes to the crunch */
1230 inst = irreco_backend_manager_create_instance(
1231 manager, lib, NULL, NULL);
1232 new_instance = TRUE;
1233 break;
1235 IRRECO_STRING_TABLE_FOREACH_END
1237 if (inst == NULL) {
1238 g_string_printf(error_msg,
1239 "\"%s\" backend is not installed...",
1240 config->backend->str);
1241 goto end;
1244 irreco_backend_instance_configure(inst, GTK_WINDOW(self));
1245 irreco_backend_instance_save_to_conf(inst);
1246 irreco_config_save_backends(manager);
1248 instance_ready:
1249 file_container = irreco_backend_file_container_new();
1250 irreco_backend_file_container_set(file_container,
1251 inst->lib->name,
1252 config->category->str,
1253 config->manufacturer->str,
1254 config->model->str,
1255 config->file_name->str,
1256 file_data->str);
1258 if (irreco_backend_instance_check_conf(inst, file_container)) {
1259 g_string_printf(error_msg,
1260 "\"%s\" backend already contains\n"
1261 "device \"%s\".\n"
1262 "Do you want to overwrite?",
1263 inst->lib->name, config->model->str);
1264 success = irreco_yes_no_dlg(GTK_WINDOW(self),
1265 error_msg->str);
1266 g_string_erase(error_msg, 0, -1);
1268 if(success == FALSE) {
1269 goto end;
1273 /* Send file_data for backend */
1274 if(irreco_backend_instance_import_conf(inst, file_container)) {
1275 irreco_backend_manager_get_devcmd_lists(
1276 self->irreco_data->irreco_backend_manager);
1277 } else {
1278 g_string_printf(error_msg, "Backend error");
1280 if (new_instance) {
1281 irreco_backend_manager_destroy_instance(manager,
1282 inst);
1284 goto end;
1286 configurations = configurations->next;
1287 irreco_backend_file_container_free(file_container);
1288 file_container = NULL;
1289 g_free(sha1);
1290 sha1 = NULL;
1291 g_string_free(file_data, FALSE);
1292 file_data = NULL;
1295 end:
1296 if(error_msg->len > 0) {
1297 irreco_error_dlg(GTK_WINDOW(self), error_msg->str);
1298 success = FALSE;
1300 g_string_free(error_msg, FALSE);
1301 if (sha1 != NULL) g_free(sha1);
1302 if (file_container != NULL) {
1303 irreco_backend_file_container_free(file_container);
1305 if (file_data != NULL) g_string_free(file_data, FALSE);
1306 g_string_free(instance_number, FALSE);
1308 IRRECO_RETURN_BOOL(success);
1311 /** @} */
1315 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1316 /* Public Functions */
1317 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1320 * @name Public Functions
1321 * @{
1324 gboolean irreco_show_remote_download_dlg(IrrecoData *irreco_data,
1325 GtkWindow *parent)
1327 IrrecoRemoteDownloadDlg *self;
1328 gboolean loop = TRUE;
1329 IrrecoWebdbCache *webdb_cache;
1330 gboolean downloaded = FALSE;
1331 IRRECO_ENTER
1333 self = irreco_remote_download_dlg_new(irreco_data, parent);
1335 do {
1336 gint response = gtk_dialog_run(GTK_DIALOG(self));
1337 if (self->loader_func_id != 0) {
1338 continue;
1340 switch (response) {
1341 case IRRECO_REMOTE_REFRESH:
1342 IRRECO_DEBUG("IRRECO_REMOTE_REFRESH\n");
1343 gtk_tree_store_clear(self->tree_store);
1344 webdb_cache = irreco_data_get_webdb_cache(
1345 self->irreco_data, FALSE);
1347 if (webdb_cache->remote_id_hash != NULL) {
1348 g_hash_table_remove_all(
1349 webdb_cache->remote_id_hash);
1351 if (webdb_cache->remote_categories != NULL) {
1352 irreco_string_table_free(
1353 webdb_cache->remote_categories);
1354 webdb_cache->remote_categories = NULL;
1357 irreco_remote_download_dlg_loader_start(self,
1358 G_SOURCEFUNC(
1359 irreco_remote_download_dlg_loader_categ), NULL);
1361 break;
1362 case IRRECO_REMOTE_DOWNLOAD: {
1363 IrrecoWebdbCache *webdb_cache;
1364 IrrecoWebdbRemote *remote = self->remote;
1365 IrrecoThemeManager *manager =
1366 self->irreco_data->theme_manager;
1367 GList *themes;
1368 gint layout_index = 1;
1369 GString *layout_filename = g_string_new("");
1370 gchar *layout_data = NULL;
1371 gchar *layout_name = NULL;
1372 IrrecoButtonLayout *layout = NULL;
1373 GString *bg_image = g_string_new("");
1374 GString *notification = g_string_new("");
1375 IrrecoDirForeachData dir_data;
1376 GString *tmp;
1377 GString *tmp2;
1379 IRRECO_DEBUG("IRRECO_REMOTE_DOWNLOAD\n");
1380 webdb_cache = irreco_data_get_webdb_cache(
1381 self->irreco_data, FALSE);
1383 if (self->remote == NULL) {
1384 irreco_error_dlg(GTK_WINDOW(self),
1385 "Select Remote first");
1386 break;
1389 g_string_printf(notification,
1390 "When downloading remote, system\n"
1391 "needs to download all the themes\n"
1392 "and devices that are used in remote:\n"
1393 "%s \n\nDo you wish to continue?",
1394 self->remote->model->str);
1396 if (!irreco_yes_no_dlg(GTK_WINDOW(self),
1397 notification->str)) {
1398 goto end;
1401 /* Download configurations */
1402 if (!irreco_remote_download_dlg_load_configs(self)) {
1403 goto end;
1406 /* Download themes */
1407 themes = g_list_first(remote->themes);
1408 if (themes == NULL) {
1409 goto end;
1411 while(themes) {
1412 IrrecoWebdbTheme *new_theme;
1413 IrrecoTheme *old_theme = NULL;
1414 if (GPOINTER_TO_INT(themes->data) == 0) {
1415 goto download_layout;
1417 if (!irreco_webdb_cache_get_theme_by_id(
1418 webdb_cache,
1419 GPOINTER_TO_INT(themes->data),
1420 &new_theme)) {
1421 irreco_error_dlg(GTK_WINDOW(self),
1422 irreco_webdb_cache_get_error(
1423 webdb_cache));
1424 goto end;
1426 if (!irreco_string_table_get(manager->themes,
1427 new_theme->name->str, (gpointer *)
1428 &old_theme) || !g_str_equal(
1429 old_theme->version->str,
1430 new_theme->uploaded->str)) {
1431 if (!irreco_theme_download_dlg_run(
1432 self->irreco_data,
1433 GPOINTER_TO_INT(themes->data),
1434 GTK_WINDOW(self))) {
1435 goto end;
1438 themes = themes->next;
1440 irreco_theme_manager_update_theme_manager(manager);
1442 /* Download layout */
1443 download_layout:
1444 /*Create filename */
1445 while(1) {
1446 g_string_printf(layout_filename,
1447 "%s/layout%d.conf",
1448 irreco_get_config_dir("irreco"),
1449 layout_index);
1450 if (!irreco_file_exists(layout_filename->str)) {
1451 IRRECO_DEBUG("%s\n",
1452 layout_filename->str);
1453 break;
1455 layout_index++;
1458 /* Get layout_data */
1459 if (!irreco_webdb_cache_get_remote_data(webdb_cache,
1460 remote->id,
1461 &layout_data)) {
1462 irreco_error_dlg(GTK_WINDOW(self),
1463 irreco_webdb_cache_get_error(
1464 webdb_cache));
1465 goto end;
1468 /* Copy layout_name */
1469 layout_name = g_strdup(remote->model->str);
1471 /* Check if there is same remotename already */
1472 if (irreco_string_table_exists(
1473 irreco_data->irreco_layout_array,
1474 remote->model->str)) {
1475 gint i = 2;
1476 gboolean run = TRUE;
1477 gchar *new_name;
1478 GKeyFile *keyfile = g_key_file_new();
1479 GError *error;
1480 GString *cmd;
1482 /* Create new name */
1483 while (run) {
1484 new_name = g_strdup_printf("%s_%d",
1485 remote->model->str, i++);
1486 if (!irreco_string_table_exists(
1487 irreco_data->irreco_layout_array,
1488 new_name)) {
1489 run = FALSE;
1490 IRRECO_DEBUG("NEW NAME: %s\n",
1491 new_name);
1492 } else {
1493 g_free(new_name);
1497 /* Create key file */
1498 if (!g_key_file_load_from_data(keyfile,
1499 layout_data, strlen(layout_data),
1500 G_KEY_FILE_KEEP_TRANSLATIONS, &error)) {
1501 IRRECO_DEBUG("%s\n", error->message);
1502 g_error_free(error);
1503 goto end;
1506 /* Set new name for remote */
1507 g_key_file_set_string(keyfile, "layout",
1508 "name", new_name);
1510 /* Save keyfile */
1511 irreco_write_keyfile(keyfile,
1512 layout_filename->str);
1514 /* Set new name for every button */
1515 cmd = g_string_new("");
1516 g_string_printf(cmd,
1517 "cat %s | sed s}'^layout=%s$'}'layout=%s'} > %s",
1518 layout_filename->str,
1519 remote->model->str, new_name,
1520 layout_filename->str);
1521 system(cmd->str);
1522 g_string_free(cmd, FALSE);
1524 /* Change layout_name */
1525 g_free(layout_name);
1526 layout_name = g_strdup(new_name);
1528 } else if (!irreco_write_file(layout_filename->str,
1529 layout_data, strlen(layout_data))) {
1530 irreco_error_dlg(GTK_WINDOW(self),
1531 "Save file error!");
1532 goto end;
1535 dir_data.directory = irreco_get_config_dir("irreco");
1536 dir_data.filesuffix = ".conf";
1537 g_string_printf(layout_filename, "layout%d.conf",
1538 layout_index);
1539 dir_data.filename = layout_filename->str;
1540 dir_data.user_data_1 = self->irreco_data;
1542 /* Get new layout to list */
1543 irreco_config_read_layouts(&dir_data);
1545 irreco_string_table_get(
1546 irreco_data->irreco_layout_array,
1547 layout_name, (gpointer *) &layout);
1549 if (layout == NULL) {
1550 irreco_error_dlg(GTK_WINDOW(self),
1551 "Broken layout!");
1552 goto end;
1555 g_string_printf(bg_image, "%s",
1556 irreco_button_layout_get_bg_image(
1557 layout));
1559 if (bg_image->len < 10) {
1560 goto no_bg;
1563 tmp = g_string_new(bg_image->str);
1564 tmp = g_string_erase(tmp, 6, -1);
1565 tmp2 = g_string_new("/media");
1568 IRRECO_PRINTF("VERTAILU");
1569 IRRECO_PRINTF(tmp->str);
1571 if(g_string_equal(tmp, tmp2))
1573 bg_image = g_string_erase(bg_image, 0, 11);
1574 bg_image = g_string_prepend(bg_image, "/home/user/MyDocs");
1576 IRRECO_PRINTF(bg_image->str);
1579 IRRECO_PAUSE
1580 g_string_free(tmp, TRUE);
1581 g_string_free(tmp2, TRUE);
1583 /* Set bg-image to layout */
1584 irreco_button_layout_set_bg_image(layout,
1585 bg_image->str);
1586 irreco_config_save_layouts(irreco_data);
1588 no_bg:
1590 irreco_window_manager_set_layout(
1591 self->irreco_data->window_manager,
1592 layout);
1594 irreco_info_dlg(GTK_WINDOW(self),
1595 "Remote downloaded successfully!");
1596 loop = FALSE;
1597 downloaded = TRUE;
1599 end:
1600 g_string_free(layout_filename, FALSE);
1601 g_string_free(bg_image, FALSE);
1602 if (layout_data != NULL) {
1603 g_free(layout_data);
1605 if (layout_name != NULL) {
1606 g_free(layout_name);
1608 g_string_free(notification, FALSE);
1609 break;
1612 case GTK_RESPONSE_DELETE_EVENT:
1613 IRRECO_DEBUG("GTK_RESPONSE_DELETE_EVENT\n");
1614 loop = FALSE;
1615 break;
1618 } while (loop);
1620 gtk_widget_destroy(GTK_WIDGET(self));
1621 IRRECO_RETURN_BOOL(downloaded);
1624 /** @} */
1628 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1629 /* Events and Callbacks */
1630 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1633 * @name Events and Callbacks
1634 * @{
1637 static gboolean irreco_remote_download_dlg_map_event(
1638 IrrecoRemoteDownloadDlg *self,
1639 GdkEvent *event,
1640 gpointer user_data)
1642 IRRECO_ENTER
1643 irreco_remote_download_dlg_loader_start(self,
1644 G_SOURCEFUNC(irreco_remote_download_dlg_loader_categ), NULL);
1645 IRRECO_RETURN_BOOL(FALSE);
1648 static void irreco_remote_download_dlg_destroy_event(
1649 IrrecoRemoteDownloadDlg *self,
1650 gpointer user_data)
1652 IRRECO_ENTER
1653 irreco_remote_download_dlg_loader_stop(self);
1654 IRRECO_RETURN
1657 static void irreco_remote_download_dlg_row_activated_event(
1658 GtkTreeView *tree_view,
1659 GtkTreePath *path,
1660 GtkTreeViewColumn *column,
1661 IrrecoRemoteDownloadDlg *self)
1663 IRRECO_ENTER
1665 if (gtk_tree_view_row_expanded(tree_view, path)) {
1666 gtk_tree_view_expand_row(tree_view, path, FALSE);
1667 } else {
1668 gtk_tree_view_collapse_row(tree_view, path);
1670 IRRECO_RETURN
1673 static void irreco_remote_download_dlg_row_expanded_event(
1674 GtkTreeView *tree_view,
1675 GtkTreeIter *iter,
1676 GtkTreePath *path,
1677 IrrecoRemoteDownloadDlg *self)
1679 IRRECO_ENTER
1681 irreco_remote_download_dlg_clean_details(self);
1683 if (self->loader_func_id != 0) {
1684 gtk_tree_view_collapse_row(tree_view, path);
1687 if (!irreco_remote_download_dlg_row_is_loaded(self, iter)) {
1688 switch (irreco_remote_download_dlg_row_get_type(self, iter)) {
1689 case ROW_TYPE_CATEGORY:
1690 irreco_remote_download_dlg_loader_start(self,
1691 G_SOURCEFUNC(
1692 irreco_remote_download_dlg_loader_manuf), iter);
1693 break;
1695 case ROW_TYPE_MANUFACTURER:
1696 irreco_remote_download_dlg_loader_start(self,
1697 G_SOURCEFUNC(
1698 irreco_remote_download_dlg_loader_model), iter);
1699 break;
1701 case ROW_TYPE_MODEL:
1702 irreco_remote_download_dlg_loader_start(self,
1703 G_SOURCEFUNC(
1704 irreco_remote_download_dlg_loader_creators),
1705 iter);
1706 break;
1708 case ROW_TYPE_CREATOR:
1709 irreco_remote_download_dlg_loader_start(self,
1710 G_SOURCEFUNC(
1711 irreco_remote_download_dlg_loader_remotes),
1712 iter);
1713 break;
1717 IRRECO_RETURN
1720 static void irreco_remote_download_dlg_row_collapsed_event(
1721 GtkTreeView *tree_view,
1722 GtkTreeIter *iter,
1723 GtkTreePath *path,
1724 IrrecoRemoteDownloadDlg *self)
1726 IRRECO_ENTER
1728 irreco_remote_download_dlg_clean_details(self);
1730 IRRECO_RETURN
1733 static void irreco_remote_download_dlg_row_selected_event(GtkTreeSelection *sel,
1734 IrrecoRemoteDownloadDlg *self)
1736 GtkTreeIter iter;
1737 GtkTreeModel *model;
1739 IRRECO_ENTER
1741 if (gtk_tree_selection_get_selected (sel, &model, &iter))
1743 switch (irreco_remote_download_dlg_row_get_type(self, &iter)) {
1745 case ROW_TYPE_REMOTE:
1746 IRRECO_DEBUG("ROW_TYPE_REMOTE\n");
1748 IrrecoWebdbCache *webdb_cache;
1749 IrrecoWebdbRemote *remote;
1750 GString *download_count;
1751 GString *theme_names = g_string_new("");
1752 GString *backend_names = g_string_new("");
1753 GList *configs;
1754 GList *backends = NULL;
1755 GList *dummy_list = NULL;
1756 GList *themes = NULL;
1757 GtkTextBuffer *buffer;
1758 gint id;
1760 /* Get remote_id */
1761 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1762 &iter, DATA_COL,(gpointer) &id, -1);
1764 /* Get remote by id */
1765 webdb_cache = irreco_data_get_webdb_cache(
1766 self->irreco_data, FALSE);
1767 if (!irreco_webdb_cache_get_remote_by_id(webdb_cache,
1769 &remote)) {
1770 irreco_error_dlg(GTK_WINDOW(self),
1771 irreco_webdb_cache_get_error(
1772 webdb_cache));
1773 goto end;
1777 /* Model */
1778 gtk_label_set_text(GTK_LABEL(self->details_model),
1779 remote->model->str);
1781 /* Creator */
1782 gtk_label_set_text(GTK_LABEL(self->details_creator),
1783 remote->creator->str);
1785 /* Downloaded */
1786 download_count = g_string_new("");
1787 g_string_printf(download_count, "%d times",
1788 remote->download_count);
1789 gtk_label_set_text(GTK_LABEL(self->details_downloaded),
1790 download_count->str);
1791 g_string_free(download_count, FALSE);
1793 /* Comment */
1794 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
1795 self->details_comment));
1796 gtk_text_buffer_set_text(buffer, remote->comment->str,
1797 remote->comment->len);
1798 gtk_text_view_set_buffer(GTK_TEXT_VIEW(
1799 self->details_comment),
1800 buffer);
1802 /* Get configurations and get backends */
1803 if (!irreco_webdb_cache_get_configurations_of_remote(
1804 webdb_cache, id, &configs)) {
1805 irreco_error_dlg(GTK_WINDOW(self),
1806 irreco_webdb_cache_get_error(
1807 webdb_cache));
1808 goto end;
1810 configs = g_list_first(configs);
1811 while(configs) {
1812 IrrecoWebdbConf *config = NULL;
1813 if (GPOINTER_TO_INT(configs->data) != 0 &&
1814 !irreco_webdb_cache_get_configuration(
1815 webdb_cache, GPOINTER_TO_INT(configs->data),
1816 &config)) {
1817 irreco_error_dlg(GTK_WINDOW(self),
1818 irreco_webdb_cache_get_error(
1819 webdb_cache));
1820 goto end;
1823 if (config != NULL) {
1824 backends = g_list_append(backends,
1825 config->backend->str);
1827 configs = configs->next;
1830 backends = g_list_first(backends);
1831 dummy_list = backends;
1832 if (backends == NULL) {
1833 g_string_append_printf(backend_names, "-");
1834 } else {
1835 /* deletion of duplicates */
1836 while(backends) {
1837 const char *backend = backends->data;
1838 GList *next = backends->next;
1839 while(next) {
1840 if (g_str_equal(backend,
1841 next->data)) {
1842 backends =
1843 g_list_remove(backends,
1844 next->data);
1845 dummy_list = backends;
1846 next = backends;
1848 next = next->next;
1850 backends = backends->next;
1854 /* Create Backends string */
1855 backends = g_list_first(dummy_list);
1856 while(backends) {
1857 const char *backend = backends->data;
1858 g_string_append_printf(backend_names,
1859 "%s", backend);
1860 backends = backends->next;
1861 if (backends) {
1862 if (!backends->next) {
1863 g_string_append_printf(
1864 backend_names,
1865 _(" and\n"));
1866 } else {
1867 g_string_append_printf(
1868 backend_names,
1869 ",\n");
1875 gtk_label_set_text(GTK_LABEL(self->details_backends),
1876 backend_names->str);
1878 /* Create themes string */
1879 if (!irreco_webdb_cache_get_themes_of_remote(
1880 webdb_cache, id, &themes)) {
1881 irreco_error_dlg(GTK_WINDOW(self),
1882 irreco_webdb_cache_get_error(
1883 webdb_cache));
1884 goto end;
1886 themes = g_list_first(themes);
1887 if (themes == NULL ||
1888 GPOINTER_TO_INT(themes->data) == 0) {
1889 g_string_append(theme_names, "-");
1891 while(themes) {
1892 IrrecoWebdbTheme *theme = NULL;
1893 if (GPOINTER_TO_INT(themes->data) != 0 &&
1894 !irreco_webdb_cache_get_theme_by_id(
1895 webdb_cache, GPOINTER_TO_INT(themes->data),
1896 &theme)) {
1897 irreco_error_dlg(GTK_WINDOW(self),
1898 irreco_webdb_cache_get_error(
1899 webdb_cache));
1900 goto end;
1902 themes = themes->next;
1903 if (theme != NULL) {
1904 g_string_append_printf(theme_names,
1905 "%s", theme->name->str);
1907 if (themes) {
1908 if (!themes->next) {
1909 g_string_append_printf(
1910 theme_names,
1911 _(" and\n"));
1912 } else {
1913 g_string_append_printf(
1914 theme_names,
1915 ",\n");
1919 gtk_label_set_text(GTK_LABEL(self->details_themes),
1920 theme_names->str);
1922 self->remote = remote;
1923 gtk_widget_hide(GTK_WIDGET(self->help_text));
1924 gtk_widget_show(GTK_WIDGET(self->details));
1925 end:
1926 g_string_free(theme_names, TRUE);
1927 g_string_free(backend_names, TRUE);
1929 break;
1931 default:
1932 irreco_remote_download_dlg_clean_details(self);
1933 gtk_widget_show(GTK_WIDGET(self->help_text));
1934 gtk_widget_hide(GTK_WIDGET(self->details));
1935 break;
1939 IRRECO_RETURN
1942 /** @} */
1944 /** @} */