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 "irreco_webdb_client.h"
24 #include <hildon/hildon-banner.h>
27 * @addtogroup IrrecoRemoteDownloadDlg
30 * @todo PURPOCE OF CLASS.
37 * Source file of @ref IrrecoRemoteDownloadDlg.
41 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
45 /** Button responce codes. */
47 IRRECO_REMOTE_REFRESH
,
48 IRRECO_REMOTE_DOWNLOAD
,
52 /** GtkTreeStore colums. */
73 ROW_CHILDREN_LOADED
= 1 << 1,
74 ROW_TYPE_CATEGORY
= 1 << 2,
75 ROW_TYPE_MANUFACTURER
= 1 << 3,
76 ROW_TYPE_MODEL
= 1 << 4,
77 ROW_TYPE_CREATOR
= 1 << 5,
78 ROW_TYPE_REMOTE
= 1 << 6,
79 ROW_TYPE_LOADING
= 1 << 7
82 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
84 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
86 static gboolean
irreco_remote_download_dlg_map_event(
87 IrrecoRemoteDownloadDlg
*self
,
90 static void irreco_remote_download_dlg_destroy_event(
91 IrrecoRemoteDownloadDlg
*self
,
93 static void irreco_remote_download_dlg_row_activated_event(
94 GtkTreeView
*tree_view
,
96 GtkTreeViewColumn
*column
,
97 IrrecoRemoteDownloadDlg
*self
);
98 static void irreco_remote_download_dlg_row_expanded_event(
99 GtkTreeView
*tree_view
,
102 IrrecoRemoteDownloadDlg
*self
);
103 static void irreco_remote_download_dlg_row_collapsed_event(
104 GtkTreeView
*tree_view
,
107 IrrecoRemoteDownloadDlg
*self
);
108 static void irreco_remote_download_dlg_row_selected_event(GtkTreeSelection
*sel
,
109 IrrecoRemoteDownloadDlg
*self
);
111 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
112 /* Construction & Destruction */
113 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
116 * @name Construction & Destruction
120 G_DEFINE_TYPE(IrrecoRemoteDownloadDlg
, irreco_remote_download_dlg
, IRRECO_TYPE_DLG
)
122 static void irreco_remote_download_dlg_dispose(GObject
*object
)
125 irreco_remote_download_dlg_parent_class
)->dispose(object
);
128 static void irreco_remote_download_dlg_finalize(GObject
*object
)
131 irreco_remote_download_dlg_parent_class
)->finalize(object
);
134 static void irreco_remote_download_dlg_class_init(
135 IrrecoRemoteDownloadDlgClass
*klass
)
137 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
140 object_class
->dispose
= irreco_remote_download_dlg_dispose
;
141 object_class
->finalize
= irreco_remote_download_dlg_finalize
;
144 static void irreco_remote_download_dlg_init(IrrecoRemoteDownloadDlg
*self
)
147 PangoFontDescription
*title_font
;
148 PangoFontDescription
*initial_font
;
149 PangoFontDescription
*menu_font
;
152 GtkWidget
*scrollbar
;
153 GtkTreeViewColumn
*column
;
154 GtkCellRenderer
*renderer
;
155 GtkTreeSelection
*select
;
156 GtkWidget
*tree_view_frame
;
157 GtkWidget
*tree_view_hbox
;
160 GtkWidget
*help_hbox
= NULL
;
161 GtkWidget
*details_alignment
;
162 GtkWidget
*details_frame
;
163 GtkWidget
*details_table
;
170 initial_font
= pango_font_description_from_string("Sans 11");
171 menu_font
= pango_font_description_from_string("Sans 13");
172 title_font
= pango_font_description_from_string("Sans Bold 12");
174 /* Build the dialog */
175 gtk_window_set_title(GTK_WINDOW(self
), _("Download Remote"));
176 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
177 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
178 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
179 gtk_dialog_add_buttons(GTK_DIALOG(self
),
180 GTK_STOCK_REFRESH
, IRRECO_REMOTE_REFRESH
,
181 _("Download"), IRRECO_REMOTE_DOWNLOAD
,
182 _("Done"), IRRECO_REMOTE_DONE
,
186 hbox
= g_object_new(GTK_TYPE_HBOX
, NULL
);
187 gtk_box_set_spacing(GTK_BOX(hbox
), 8);
188 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self
)->vbox
),
189 irreco_gtk_align(GTK_WIDGET(hbox
),
190 0, 0, 1, 1, 8, 8, 8, 8));
192 /* Create tree_view_hbox */
193 tree_view_hbox
= g_object_new(GTK_TYPE_HBOX
, NULL
);
195 /* Create Treeview */
196 self
->tree_store
= gtk_tree_store_new(
197 N_COLUMNS
, G_TYPE_STRING
, G_TYPE_INT
, G_TYPE_POINTER
);
198 self
->tree_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(
199 GTK_TREE_MODEL(self
->tree_store
)));
201 renderer
= gtk_cell_renderer_text_new();
202 g_object_set(renderer
, "font-desc", menu_font
, NULL
);
204 column
= gtk_tree_view_column_new_with_attributes(
205 NULL
, renderer
, "text", TEXT_COL
, NULL
);
206 gtk_tree_view_append_column(self
->tree_view
, column
);
208 gtk_box_pack_start(GTK_BOX(tree_view_hbox
), GTK_WIDGET(self
->tree_view
),
211 /* Create scrollbar for Treeview */
212 scrollbar
= gtk_vscrollbar_new(gtk_tree_view_get_vadjustment(
213 GTK_TREE_VIEW(self
->tree_view
)));
214 gtk_box_pack_start(GTK_BOX(tree_view_hbox
), GTK_WIDGET(scrollbar
),
217 /* Create Frame for Treeview */
218 tree_view_frame
= gtk_frame_new("");
219 gtk_frame_set_label_widget(GTK_FRAME(tree_view_frame
),
220 irreco_gtk_label_bold("Remotes", 0, 0, 0, 0, 0, 0));
222 gtk_container_add(GTK_CONTAINER(tree_view_frame
),
223 GTK_WIDGET(tree_view_hbox
));
225 gtk_box_pack_start(GTK_BOX(hbox
), GTK_WIDGET(tree_view_frame
),
228 /* Create details_table */
229 details_table
= gtk_table_new(7, 4, FALSE
);
230 gtk_table_set_row_spacings(GTK_TABLE(details_table
), 4);
232 label
= gtk_label_new("Model: ");
233 gtk_widget_modify_font(label
, title_font
);
234 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0);
235 gtk_table_attach(GTK_TABLE(details_table
), label
,
236 0, 1, 0, 1, GTK_FILL
| GTK_SHRINK
, GTK_FILL
, 0, 0);
238 label
= gtk_label_new("Creator: ");
239 gtk_widget_modify_font(label
, title_font
);
240 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0);
241 gtk_table_attach(GTK_TABLE(details_table
), label
,
242 0, 1, 1, 2, GTK_FILL
| GTK_SHRINK
, GTK_FILL
, 0, 0);
244 label
= gtk_label_new("Backends: ");
245 gtk_widget_modify_font(label
, title_font
);
246 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0);
247 gtk_table_attach(GTK_TABLE(details_table
), label
,
248 0, 1, 2, 3, GTK_FILL
| GTK_SHRINK
, GTK_FILL
, 0, 0);
250 label
= gtk_label_new("Themes: ");
251 gtk_widget_modify_font(label
, title_font
);
252 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0);
253 gtk_table_attach(GTK_TABLE(details_table
), label
,
254 0, 1, 3, 4, GTK_FILL
| GTK_SHRINK
, GTK_FILL
, 0, 0);
256 label
= gtk_label_new("Downloaded: ");
257 gtk_widget_modify_font(label
, title_font
);
258 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0);
259 gtk_table_attach(GTK_TABLE(details_table
), label
,
260 0, 1, 4, 5, GTK_FILL
| GTK_SHRINK
, GTK_FILL
, 0, 0);
262 label
= gtk_label_new("Comment: ");
263 gtk_widget_modify_font(label
, title_font
);
264 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0);
265 gtk_table_attach(GTK_TABLE(details_table
), label
,
266 0, 1, 5, 6, GTK_FILL
| GTK_SHRINK
, GTK_FILL
, 0, 0);
268 self
->details_model
= gtk_label_new("");
269 gtk_widget_modify_font(self
->details_model
, initial_font
);
270 gtk_misc_set_alignment(GTK_MISC(self
->details_model
), 0, 0);
271 gtk_table_attach(GTK_TABLE(details_table
), self
->details_model
,
272 1, 2, 0, 1, GTK_FILL
, GTK_FILL
, 0, 0);
274 self
->details_creator
= gtk_label_new("");
275 gtk_widget_modify_font(self
->details_creator
, initial_font
);
276 gtk_misc_set_alignment(GTK_MISC(self
->details_creator
), 0, 0);
277 gtk_table_attach(GTK_TABLE(details_table
), self
->details_creator
,
278 1, 2, 1, 2, GTK_FILL
, GTK_FILL
, 0, 0);
280 self
->details_backends
= gtk_label_new("");
281 gtk_widget_modify_font(self
->details_backends
, initial_font
);
282 gtk_misc_set_alignment(GTK_MISC(self
->details_backends
), 0, 0);
283 gtk_table_attach(GTK_TABLE(details_table
), self
->details_backends
,
284 1, 2, 2, 3, GTK_FILL
, GTK_FILL
, 0, 0);
286 self
->details_themes
= gtk_label_new("");
287 gtk_widget_modify_font(self
->details_themes
, initial_font
);
288 gtk_misc_set_alignment(GTK_MISC(self
->details_themes
), 0, 0);
289 gtk_table_attach(GTK_TABLE(details_table
), self
->details_themes
,
290 1, 2, 3, 4, GTK_FILL
, GTK_FILL
, 0, 0);
292 self
->details_downloaded
= gtk_label_new("");
293 gtk_widget_modify_font(self
->details_downloaded
, initial_font
);
294 gtk_misc_set_alignment(GTK_MISC(self
->details_downloaded
), 0, 0);
295 gtk_table_attach(GTK_TABLE(details_table
), self
->details_downloaded
,
296 1, 2, 4, 5, GTK_FILL
, GTK_FILL
, 0, 0);
298 self
->details_comment
= gtk_text_view_new();
299 gtk_widget_modify_font(self
->details_comment
, initial_font
);
300 gtk_misc_set_alignment(GTK_MISC(self
->details_comment
), 0, 0);
301 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(self
->details_comment
),
303 gtk_text_view_set_editable(GTK_TEXT_VIEW(self
->details_comment
),
305 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self
->details_comment
),
307 gtk_table_attach(GTK_TABLE(details_table
), self
->details_comment
,
308 0, 4, 6, 7, GTK_FILL
, GTK_FILL
, 0, 0);
309 gtk_widget_set_size_request(GTK_WIDGET(self
->details_comment
), 311, -1);
312 self
->details
= gtk_scrolled_window_new(NULL
, NULL
);
313 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self
->details
),
314 GTK_POLICY_AUTOMATIC
,
315 GTK_POLICY_AUTOMATIC
);
317 gtk_widget_set_size_request(GTK_WIDGET(self
->details
), 355, -1);
319 /* Create frame for Details */
320 details_frame
= gtk_frame_new("");
321 gtk_frame_set_label_widget(GTK_FRAME(details_frame
),
322 irreco_gtk_label_bold("Details", 0, 0, 0, 0, 0, 0));
324 gtk_box_pack_start(GTK_BOX(hbox
), GTK_WIDGET(details_frame
),
327 /* Create alignment */
328 details_alignment
= gtk_alignment_new(0, 0, 0, 0);
329 gtk_alignment_set_padding(GTK_ALIGNMENT(details_alignment
), 0, 8, 8, 8);
331 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
335 gtk_container_add(GTK_CONTAINER(details_alignment
), details_table
);
338 self
->help_text
= gtk_label_new("Select Remote");
339 gtk_label_set_justify(GTK_LABEL(self
->help_text
), GTK_JUSTIFY_CENTER
);
340 gtk_label_set_line_wrap(GTK_LABEL(self
->help_text
), TRUE
);
341 self
->help_text
= irreco_gtk_align(self
->help_text
,
342 0.5, 0.5, 1, 1, 8, 8, 8, 8);
344 help_hbox
= gtk_hbox_new(0, 0);
346 gtk_box_pack_start(GTK_BOX(help_hbox
), GTK_WIDGET(self
->details
),
348 gtk_box_pack_start(GTK_BOX(help_hbox
), GTK_WIDGET(self
->help_text
),
351 gtk_container_add(GTK_CONTAINER(details_frame
), GTK_WIDGET(help_hbox
));
353 /* Setup the selection handler for TREE */
354 select
= gtk_tree_view_get_selection(self
->tree_view
);
355 gtk_tree_selection_set_mode(select
, GTK_SELECTION_SINGLE
);
357 /* Signal handlers. */
359 g_signal_connect(G_OBJECT(self
), "map-event", G_CALLBACK(
360 irreco_remote_download_dlg_map_event
), NULL
);
361 g_signal_connect(G_OBJECT(self
), "destroy", G_CALLBACK(
362 irreco_remote_download_dlg_destroy_event
), NULL
);
363 g_signal_connect(G_OBJECT(self
->tree_view
), "row-activated", G_CALLBACK(
364 irreco_remote_download_dlg_row_activated_event
), self
);
365 g_signal_connect(G_OBJECT(self
->tree_view
), "row-expanded", G_CALLBACK(
366 irreco_remote_download_dlg_row_expanded_event
), self
);
367 g_signal_connect(G_OBJECT(self
->tree_view
), "row-collapsed", G_CALLBACK(
368 irreco_remote_download_dlg_row_collapsed_event
), self
);
369 g_signal_connect(G_OBJECT(select
), "changed", G_CALLBACK(
370 irreco_remote_download_dlg_row_selected_event
), self
);
372 gtk_tree_view_set_enable_tree_lines(self
->tree_view
, TRUE
);
373 g_object_set (G_OBJECT (self
->tree_view
), "show-expanders", TRUE
, NULL
);
374 g_object_set (G_OBJECT (self
->tree_view
), "level-indentation", 0, NULL
);
375 gtk_tree_view_set_rubber_banding(self
->tree_view
, FALSE
);
377 gtk_widget_set_size_request(GTK_WIDGET(self
), 696, 396);
379 gtk_widget_show_all(GTK_WIDGET(self
));
380 gtk_widget_hide(GTK_WIDGET(self
->details
));
385 IrrecoRemoteDownloadDlg
* irreco_remote_download_dlg_new(IrrecoData
*irreco_data
,
388 IrrecoRemoteDownloadDlg
*self
;
391 self
= g_object_new(IRRECO_TYPE_REMOTE_DOWNLOAD_DLG
, NULL
);
392 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
393 self
->irreco_data
= irreco_data
;
394 IRRECO_RETURN_PTR(self
);
402 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
403 /* Private Functions */
404 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
407 * @name Private Functions
415 static void irreco_remote_download_dlg_clean_details(
416 IrrecoRemoteDownloadDlg
*self
)
418 GtkTextBuffer
*buffer
;
422 gtk_label_set_text(GTK_LABEL(self
->details_model
), "");
423 gtk_label_set_text(GTK_LABEL(self
->details_creator
), "");
424 gtk_label_set_text(GTK_LABEL(self
->details_backends
), "");
425 gtk_label_set_text(GTK_LABEL(self
->details_themes
), "");
426 gtk_label_set_text(GTK_LABEL(self
->details_downloaded
), "");
427 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(self
->details_comment
));
428 gtk_text_buffer_set_text(buffer
, " ", 1);
429 gtk_text_view_set_buffer(GTK_TEXT_VIEW(self
->details_comment
), buffer
);
435 * Have the childern of this item been loaded.
437 * @return TRUE if children have been loade, FALSE otherwise.
439 static gboolean
irreco_remote_download_dlg_row_is_loaded(
440 IrrecoRemoteDownloadDlg
*self
,
446 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
447 iter
, FLAG_COL
, &i
, -1);
448 if (i
& ROW_CHILDREN_LOADED
) IRRECO_RETURN_BOOL(TRUE
);
449 IRRECO_RETURN_BOOL(FALSE
);
453 * Enable / Disable ROW_CHILDREN_LOADED flag from a row.
455 * @param value If set, ROW_CHILDREN_LOADED will be enabled.
457 static void irreco_remote_download_dlg_row_set_loaded(IrrecoRemoteDownloadDlg
*self
,
464 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
465 iter
, FLAG_COL
, &i
, -1);
467 i
= i
| ROW_CHILDREN_LOADED
;
469 i
= i
& ~ROW_CHILDREN_LOADED
;
471 gtk_tree_store_set(self
->tree_store
, iter
, FLAG_COL
, i
, -1);
479 static gint
irreco_remote_download_dlg_row_get_type(
480 IrrecoRemoteDownloadDlg
*self
,
486 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
487 iter
, FLAG_COL
, &i
, -1);
488 if (i
& ROW_TYPE_CATEGORY
)
489 IRRECO_RETURN_ENUM(ROW_TYPE_CATEGORY
);
490 if (i
& ROW_TYPE_MANUFACTURER
)
491 IRRECO_RETURN_ENUM(ROW_TYPE_MANUFACTURER
);
492 if (i
& ROW_TYPE_MODEL
)
493 IRRECO_RETURN_ENUM(ROW_TYPE_MODEL
);
494 if (i
& ROW_TYPE_CREATOR
)
495 IRRECO_RETURN_ENUM(ROW_TYPE_CREATOR
);
496 if (i
& ROW_TYPE_REMOTE
)
497 IRRECO_RETURN_ENUM(ROW_TYPE_REMOTE
);
498 if (i
& ROW_TYPE_LOADING
)
499 IRRECO_RETURN_ENUM(ROW_TYPE_LOADING
);
500 IRRECO_RETURN_INT(0);
504 * Show hildon progressbar banner.
506 * This function will create a new banner if one has not been created yet,
507 * if banner already exists, it's properties will be changed.
509 * @param text Text to show.
510 * @param fraction Value of progress.
512 static void irreco_remote_download_dlg_set_banner(IrrecoRemoteDownloadDlg
*self
,
517 if (self
->banner
== NULL
) {
518 self
->banner
= hildon_banner_show_progress(GTK_WIDGET(self
),
522 hildon_banner_set_text(HILDON_BANNER(self
->banner
), text
);
523 hildon_banner_set_fraction(HILDON_BANNER(self
->banner
), fraction
);
528 * Destroy banner, if it exists.
530 static void irreco_remote_download_dlg_hide_banner(
531 IrrecoRemoteDownloadDlg
*self
)
535 gtk_widget_destroy(self
->banner
);
542 * Start a loader state machine if one is not running already.
544 static void irreco_remote_download_dlg_loader_start(
545 IrrecoRemoteDownloadDlg
*self
,
546 GSourceFunc function
,
547 GtkTreeIter
*parent_iter
)
551 if (self
->loader_func_id
== 0) {
553 self
->loader_parent_iter
= gtk_tree_iter_copy(
558 self
->loader_func_id
= g_idle_add(function
, self
);
560 IRRECO_ERROR("Loader function pointer not given.\n");
568 * Stop and cleanup loader if a loader is running.
570 static void irreco_remote_download_dlg_loader_stop(
571 IrrecoRemoteDownloadDlg
*self
)
574 if (self
->loader_func_id
!= 0) {
575 g_source_remove(self
->loader_func_id
);
576 self
->loader_func_id
= 0;
577 self
->loader_state
= 0;
578 if (self
->loader_parent_iter
) {
579 gtk_tree_iter_free(self
->loader_parent_iter
);
581 self
->loader_parent_iter
= NULL
;
586 static gboolean
irreco_remote_download_dlg_loader_categ(
587 IrrecoRemoteDownloadDlg
*self
)
591 switch (self
->loader_state
) {
592 case LOADER_STATE_INIT
:
593 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
595 self
->loader_state
= LOADER_STATE_LOOP
;
596 irreco_remote_download_dlg_clean_details(self
);
597 IRRECO_RETURN_BOOL(TRUE
);
599 case LOADER_STATE_LOOP
: {
601 GtkTreeIter iter_loading
;
602 IrrecoStringTable
*categories
;
603 IrrecoWebdbCache
*webdb_cache
= NULL
;
605 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
,
607 if(irreco_webdb_cache_get_remote_categories(webdb_cache
,
609 IRRECO_STRING_TABLE_FOREACH_KEY(categories
, key
)
611 /* Append categogy. */
612 gtk_tree_store_append(self
->tree_store
,
614 gtk_tree_store_set(self
->tree_store
,
615 &iter
, TEXT_COL
, key
,
616 FLAG_COL
, ROW_TYPE_CATEGORY
,
619 /* Add loading item into category. */
620 gtk_tree_store_append(self
->tree_store
,
621 &iter_loading
, &iter
);
622 gtk_tree_store_set(self
->tree_store
,
624 TEXT_COL
, _("Loading ..."),
625 FLAG_COL
, ROW_TYPE_LOADING
,
627 IRRECO_STRING_TABLE_FOREACH_END
629 irreco_error_dlg(GTK_WINDOW(self
),
630 irreco_webdb_cache_get_error(
634 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
636 self
->loader_state
= LOADER_STATE_END
;
637 IRRECO_RETURN_BOOL(TRUE
);
640 case LOADER_STATE_END
:
641 irreco_remote_download_dlg_hide_banner(self
);
642 irreco_remote_download_dlg_loader_stop(self
);
645 IRRECO_RETURN_BOOL(FALSE
);
648 static gboolean
irreco_remote_download_dlg_loader_manuf(
649 IrrecoRemoteDownloadDlg
*self
)
653 switch (self
->loader_state
) {
654 case LOADER_STATE_INIT
:
655 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
657 self
->loader_state
= LOADER_STATE_LOOP
;
658 IRRECO_RETURN_BOOL(TRUE
);
660 case LOADER_STATE_LOOP
: {
662 GtkTreeIter iter_loading
;
663 IrrecoStringTable
*manufacturers
;
664 IrrecoWebdbCache
*webdb_cache
= NULL
;
667 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
668 self
->loader_parent_iter
,
669 TEXT_COL
, &category
, -1);
671 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
,
674 if(irreco_webdb_cache_get_remote_manufacturers(webdb_cache
,
677 IRRECO_STRING_TABLE_FOREACH_KEY(manufacturers
, key
)
679 /* Add manufacturer item into category. */
680 gtk_tree_store_append(self
->tree_store
,
681 &iter
, self
->loader_parent_iter
);
682 gtk_tree_store_set(self
->tree_store
,
685 FLAG_COL
, ROW_TYPE_MANUFACTURER
,
688 /* Add loading item into manufacturer. */
689 gtk_tree_store_append(self
->tree_store
,
690 &iter_loading
, &iter
);
691 gtk_tree_store_set(self
->tree_store
,
693 TEXT_COL
, _("Loading ..."),
694 FLAG_COL
, ROW_TYPE_LOADING
,
697 IRRECO_STRING_TABLE_FOREACH_END
699 irreco_error_dlg(GTK_WINDOW(self
),
700 irreco_webdb_cache_get_error(
706 /* Delete loading item from category. */
707 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self
->tree_store
),
708 &iter
,self
->loader_parent_iter
,0);
709 if(irreco_remote_download_dlg_row_get_type(self
,
710 &iter
) == ROW_TYPE_LOADING
) {
711 gtk_tree_store_remove(self
->tree_store
,&iter
);
713 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
715 self
->loader_state
= LOADER_STATE_END
;
716 IRRECO_RETURN_BOOL(TRUE
);
719 case LOADER_STATE_END
:
720 irreco_remote_download_dlg_row_set_loaded(
721 self
, self
->loader_parent_iter
,
723 irreco_remote_download_dlg_hide_banner(self
);
724 irreco_remote_download_dlg_loader_stop(self
);
727 IRRECO_RETURN_BOOL(FALSE
);
730 static gboolean
irreco_remote_download_dlg_loader_model(
731 IrrecoRemoteDownloadDlg
*self
)
735 switch (self
->loader_state
) {
736 case LOADER_STATE_INIT
:
737 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
739 self
->loader_state
= LOADER_STATE_LOOP
;
740 IRRECO_RETURN_BOOL(TRUE
);
742 case LOADER_STATE_LOOP
: {
744 GtkTreeIter iter_loading
;
745 GtkTreeIter category_iter
;
746 IrrecoStringTable
*models
= NULL
;
747 IrrecoWebdbCache
*webdb_cache
= NULL
;
751 /*Get category and manufacturer*/
753 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
754 self
->loader_parent_iter
,
755 TEXT_COL
, &manufacturer
, -1);
757 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
759 self
->loader_parent_iter
);
761 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
763 TEXT_COL
, &category
, -1);
765 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
,
768 if(irreco_webdb_cache_get_remote_models(webdb_cache
, category
,
769 manufacturer
, &models
)){
771 IRRECO_STRING_TABLE_FOREACH_KEY(models
, key
)
773 /* Add model item into manufacturer. */
774 gtk_tree_store_append(self
->tree_store
,
775 &iter
, self
->loader_parent_iter
);
776 gtk_tree_store_set(self
->tree_store
,
779 FLAG_COL
, ROW_TYPE_MODEL
,
782 /* Add loading item into model. */
783 gtk_tree_store_append(self
->tree_store
,
784 &iter_loading
, &iter
);
785 gtk_tree_store_set(self
->tree_store
,
787 TEXT_COL
, _("Loading ..."),
788 FLAG_COL
, ROW_TYPE_LOADING
,
791 IRRECO_STRING_TABLE_FOREACH_END
793 irreco_error_dlg(GTK_WINDOW(self
),
794 irreco_webdb_cache_get_error(
798 g_free (manufacturer
);
800 /* Delete loading item from manufacturer. */
801 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self
->tree_store
),
802 &iter
, self
->loader_parent_iter
,
804 if(irreco_remote_download_dlg_row_get_type(self
,
805 &iter
) == ROW_TYPE_LOADING
) {
806 gtk_tree_store_remove(self
->tree_store
, &iter
);
809 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
811 self
->loader_state
= LOADER_STATE_END
;
813 IRRECO_RETURN_BOOL(TRUE
);
815 case LOADER_STATE_END
:
816 irreco_remote_download_dlg_row_set_loaded(
817 self
, self
->loader_parent_iter
,
819 irreco_remote_download_dlg_hide_banner(self
);
820 irreco_remote_download_dlg_loader_stop(self
);
823 IRRECO_RETURN_BOOL(FALSE
);
826 static gboolean
irreco_remote_download_dlg_loader_creators(
827 IrrecoRemoteDownloadDlg
*self
)
831 switch (self
->loader_state
) {
832 case LOADER_STATE_INIT
:
833 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
835 self
->loader_state
= LOADER_STATE_LOOP
;
836 IRRECO_RETURN_BOOL(TRUE
);
838 case LOADER_STATE_LOOP
: {
839 IrrecoWebdbCache
*webdb_cache
= NULL
;
841 GtkTreeIter category_iter
;
842 GtkTreeIter manufacturer_iter
;
844 GtkTreeIter iter_loading
;
850 IrrecoStringTable
*creators
;
852 /*Get manufacturer_iter and category_iter */
854 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
856 self
->loader_parent_iter
);
858 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
862 /*Get category, manufacturer and model*/
864 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
866 TEXT_COL
, &category
, -1);
868 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
870 TEXT_COL
, &manufacturer
, -1);
872 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
873 self
->loader_parent_iter
,
874 TEXT_COL
, &model
, -1);
877 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
,
880 if(irreco_webdb_cache_get_remote_creators(webdb_cache
,
881 category
, manufacturer
, model
, &creators
)){
883 IRRECO_STRING_TABLE_FOREACH_KEY(creators
, key
)
885 /* Add model item into manufacturer. */
886 gtk_tree_store_append(self
->tree_store
,
887 &iter
, self
->loader_parent_iter
);
888 gtk_tree_store_set(self
->tree_store
,
891 FLAG_COL
, ROW_TYPE_CREATOR
,
894 /* Add loading item into model. */
895 gtk_tree_store_append(self
->tree_store
,
896 &iter_loading
, &iter
);
897 gtk_tree_store_set(self
->tree_store
,
899 TEXT_COL
, _("Loading ..."),
900 FLAG_COL
, ROW_TYPE_LOADING
,
903 IRRECO_STRING_TABLE_FOREACH_END
905 irreco_error_dlg(GTK_WINDOW(self
),
906 irreco_webdb_cache_get_error(
910 g_free (manufacturer
);
913 /* Delete loading item from manufacturer. */
914 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self
->tree_store
),
915 &iter
, self
->loader_parent_iter
,
917 if(irreco_remote_download_dlg_row_get_type(self
,
918 &iter
) == ROW_TYPE_LOADING
) {
919 gtk_tree_store_remove(self
->tree_store
, &iter
);
922 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
924 self
->loader_state
= LOADER_STATE_END
;
926 IRRECO_RETURN_BOOL(TRUE
);
928 case LOADER_STATE_END
:
929 irreco_remote_download_dlg_row_set_loaded(
930 self
, self
->loader_parent_iter
,
932 irreco_remote_download_dlg_hide_banner(self
);
933 irreco_remote_download_dlg_loader_stop(self
);
936 IRRECO_RETURN_BOOL(FALSE
);
939 static gboolean
irreco_remote_download_dlg_loader_remotes(
940 IrrecoRemoteDownloadDlg
*self
)
944 switch (self
->loader_state
) {
945 case LOADER_STATE_INIT
:
946 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
948 self
->loader_state
= LOADER_STATE_LOOP
;
949 self
->loader_pos
= 0;
950 IRRECO_RETURN_BOOL(TRUE
);
952 case LOADER_STATE_LOOP
: {
953 IrrecoWebdbCache
*webdb_cache
= NULL
;
955 GtkTreeIter category_iter
;
956 GtkTreeIter manufacturer_iter
;
957 GtkTreeIter model_iter
;
967 IrrecoWebdbRemote
*remote
;
968 GList
*remotes
= NULL
;
973 gint remote_count
= 0;
976 /*Get manufacturer_iter and category_iter */
978 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
980 self
->loader_parent_iter
);
982 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
986 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
990 /*Get category, manufacturer and model*/
992 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
994 TEXT_COL
, &category
, -1);
996 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
998 TEXT_COL
, &manufacturer
, -1);
1000 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
1002 TEXT_COL
, &model
, -1);
1004 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
1005 self
->loader_parent_iter
,
1006 TEXT_COL
, &creator
, -1);
1009 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
,
1012 if(!irreco_webdb_cache_get_remotes(webdb_cache
,
1013 category
, manufacturer
, model
, creator
, &remotes
)) {
1014 irreco_error_dlg(GTK_WINDOW(self
),
1015 irreco_webdb_cache_get_error(
1020 remote_id
= GPOINTER_TO_INT(g_list_nth_data(remotes
,
1023 if(!irreco_webdb_cache_get_remote_by_id(webdb_cache
, remote_id
,
1025 irreco_error_dlg(GTK_WINDOW(self
),
1026 irreco_webdb_cache_get_error(
1031 /* Get information of configurations */
1032 if (!irreco_webdb_cache_get_configurations_of_remote(
1033 webdb_cache
, remote_id
, &configs
)) {
1034 irreco_error_dlg(GTK_WINDOW(self
),
1035 irreco_webdb_cache_get_error(
1040 configs
= g_list_first(configs
);
1042 IrrecoWebdbConf
*config
;
1043 if (GPOINTER_TO_INT(configs
->data
) != 0 &&
1044 !irreco_webdb_cache_get_configuration(webdb_cache
,
1045 GPOINTER_TO_INT(configs
->data
), &config
)) {
1046 irreco_error_dlg(GTK_WINDOW(self
),
1047 irreco_webdb_cache_get_error(
1050 configs
= configs
->next
;
1053 /* Get information of themes*/
1054 if (!irreco_webdb_cache_get_themes_of_remote(
1055 webdb_cache
, remote_id
, &themes
)) {
1056 irreco_error_dlg(GTK_WINDOW(self
),
1057 irreco_webdb_cache_get_error(
1062 themes
= g_list_first(themes
);
1064 IrrecoWebdbTheme
*theme
;
1065 if (GPOINTER_TO_INT(themes
->data
) != 0 &&
1066 !irreco_webdb_cache_get_theme_by_id(webdb_cache
,
1067 GPOINTER_TO_INT(themes
->data
), &theme
)) {
1068 irreco_error_dlg(GTK_WINDOW(self
),
1069 irreco_webdb_cache_get_error(
1072 themes
= themes
->next
;
1075 /* Add config item into model. */
1076 gtk_tree_store_append(self
->tree_store
, &iter
,
1077 self
->loader_parent_iter
);
1079 gtk_tree_store_set(self
->tree_store
, &iter
,
1080 TEXT_COL
, remote
->uploaded
->str
,
1081 FLAG_COL
, ROW_TYPE_REMOTE
,
1082 DATA_COL
, GINT_TO_POINTER(remote_id
), -1);
1084 /* Delete loading item from model. */
1085 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self
->tree_store
),
1086 &iter
, self
->loader_parent_iter
,
1089 if (irreco_remote_download_dlg_row_get_type(self
,
1090 &iter
) == ROW_TYPE_LOADING
) {
1091 gtk_tree_store_remove(self
->tree_store
, &iter
);
1096 g_free (manufacturer
);
1102 if (remotes
!= NULL
) {
1103 remote_count
= g_list_length(remotes
);
1106 banner
= ((float) self
->loader_pos
+ 1) / (float) remote_count
;
1107 irreco_remote_download_dlg_set_banner(self
, _("Loading ..."),
1110 if (self
->loader_pos
+ 1 >= remote_count
) {
1111 self
->loader_state
= LOADER_STATE_END
;
1112 IRRECO_RETURN_BOOL(TRUE
);
1115 IRRECO_RETURN_BOOL(TRUE
);
1119 IRRECO_RETURN_BOOL(TRUE
);
1121 case LOADER_STATE_END
:
1122 irreco_remote_download_dlg_row_set_loaded(
1123 self
, self
->loader_parent_iter
,
1125 irreco_remote_download_dlg_hide_banner(self
);
1126 irreco_remote_download_dlg_loader_stop(self
);
1129 IRRECO_RETURN_BOOL(FALSE
);
1132 static gboolean
irreco_remote_download_dlg_load_configs(
1133 IrrecoRemoteDownloadDlg
*self
)
1135 IrrecoWebdbCache
*webdb_cache
= NULL
;
1136 IrrecoBackendInstance
*inst
= NULL
;
1137 GString
*error_msg
= g_string_new("");
1138 IrrecoBackendManager
*manager
;
1139 IrrecoBackendFileContainer
*file_container
= NULL
;
1140 GString
*file_data
= NULL
;
1142 gboolean success
= TRUE
;
1143 gboolean new_instance
= FALSE
;
1145 GList
*configurations
;
1146 IrrecoWebdbConf
*config
;
1149 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
, FALSE
);
1151 configurations
= g_list_first(self
->remote
->configurations
);
1152 if (configurations
== NULL
||
1153 GPOINTER_TO_INT(configurations
->data
) == 0) {
1156 while(configurations
) {
1158 if (!irreco_webdb_cache_get_configuration(webdb_cache
,
1159 GPOINTER_TO_INT(configurations
->data
), &config
)) {
1160 g_string_printf(error_msg
, "%s",
1161 irreco_webdb_cache_get_error(
1165 if(config
== NULL
) {
1166 g_string_printf(error_msg
, "Configuration is NULL");
1171 if (!irreco_webdb_cache_get_file(webdb_cache
,
1172 config
->file_hash
->str
,
1173 config
->file_name
->str
,
1175 g_string_printf(error_msg
, "%s",
1176 irreco_webdb_cache_get_error(
1181 sha1
= sha_compute_checksum_for_string(G_CHECKSUM_SHA1
,
1182 file_data
->str
, -1);
1184 if (g_utf8_collate(config
->file_hash
->str
, sha1
) != 0) {
1185 g_string_printf(error_msg
, "sha1 checksum failed.");
1190 /* Search backend */
1191 manager
= self
->irreco_data
->irreco_backend_manager
;
1192 IRRECO_BACKEND_MANAGER_FOREACH_LIB(manager
, lib
)
1193 if (!g_str_equal(lib
->name
, config
->backend
->str
)) {
1196 if (!(lib
->api
->flags
&
1197 IRRECO_BACKEND_EDITABLE_DEVICES
)) {
1198 g_string_printf(error_msg
,
1199 "\"%s\" backend is not editable...",
1200 config
->backend
->str
);
1203 else if (!(lib
->api
->flags
&
1204 IRRECO_BACKEND_CONFIGURATION_EXPORT
)) {
1205 g_string_printf(error_msg
,
1206 "\"%s\" backend doesn't support "
1207 "exporting its configuration...",
1208 config
->backend
->str
);
1211 /* Check if many instances */
1213 IRRECO_BACKEND_MANAGER_FOREACH_INSTANCE(manager
,
1215 irreco_backend_instance_get_description(
1217 if (g_str_equal(instance
->lib
->name
,
1218 config
->backend
->str
)) {
1221 /* if there is only one instance,
1226 IRRECO_STRING_TABLE_FOREACH_END
1227 IRRECO_DEBUG("INSTACES: %d\n", instances
);
1229 /* Create new instance if it comes to the crunch */
1230 if (instances
== 0 || lib
->api
->flags
&
1231 IRRECO_BACKEND_NEW_INST_ON_CONF_IMPORT
) {
1232 inst
= irreco_backend_manager_create_instance(
1233 manager
, lib
, NULL
, NULL
);
1234 new_instance
= TRUE
;
1238 /* Select instace */
1239 if (instances
> 1) {
1240 if (!irreco_show_select_instance_dlg(
1241 self
->irreco_data
, GTK_WINDOW(self
),
1242 config
->backend
->str
, &inst
)) {
1243 g_string_printf(error_msg
,
1244 "Operation aborted by user...");
1248 goto instance_ready
;
1249 IRRECO_STRING_TABLE_FOREACH_END
1252 g_string_printf(error_msg
,
1253 "\"%s\" backend is not installed...",
1254 config
->backend
->str
);
1258 irreco_backend_instance_configure(inst
, GTK_WINDOW(self
));
1259 irreco_backend_instance_save_to_conf(inst
);
1260 irreco_config_save_backends(manager
);
1263 file_container
= irreco_backend_file_container_new();
1264 irreco_backend_file_container_set(file_container
,
1266 config
->category
->str
,
1267 config
->manufacturer
->str
,
1269 config
->file_name
->str
,
1272 if (irreco_backend_instance_check_conf(inst
, file_container
)) {
1273 g_string_printf(error_msg
,
1274 "\"%s\" backend already contains\n"
1276 "Do you want to overwrite?",
1277 inst
->lib
->name
, config
->model
->str
);
1278 success
= irreco_yes_no_dlg(GTK_WINDOW(self
),
1280 g_string_erase(error_msg
, 0, -1);
1282 if(success
== FALSE
) {
1287 /* Send file_data for backend */
1288 if(irreco_backend_instance_import_conf(inst
, file_container
)) {
1289 irreco_backend_manager_get_devcmd_lists(
1290 self
->irreco_data
->irreco_backend_manager
);
1292 g_string_printf(error_msg
, "Backend error");
1295 irreco_backend_manager_destroy_instance(manager
,
1300 configurations
= configurations
->next
;
1301 irreco_backend_file_container_free(file_container
);
1302 file_container
= NULL
;
1305 g_string_free(file_data
, FALSE
);
1310 if(error_msg
->len
> 0) {
1311 irreco_error_dlg(GTK_WINDOW(self
), error_msg
->str
);
1314 g_string_free(error_msg
, FALSE
);
1315 if (sha1
!= NULL
) g_free(sha1
);
1316 if (file_container
!= NULL
) {
1317 irreco_backend_file_container_free(file_container
);
1319 if (file_data
!= NULL
) g_string_free(file_data
, FALSE
);
1321 IRRECO_RETURN_BOOL(success
);
1328 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1329 /* Public Functions */
1330 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1333 * @name Public Functions
1337 void irreco_show_remote_download_dlg(IrrecoData
*irreco_data
, GtkWindow
*parent
)
1339 IrrecoRemoteDownloadDlg
*self
;
1340 gboolean loop
= TRUE
;
1341 IrrecoWebdbCache
*webdb_cache
;
1344 self
= irreco_remote_download_dlg_new(irreco_data
, parent
);
1347 gint response
= gtk_dialog_run(GTK_DIALOG(self
));
1348 if (self
->loader_func_id
!= 0) {
1352 case IRRECO_REMOTE_REFRESH
:
1353 IRRECO_DEBUG("IRRECO_REMOTE_REFRESH\n");
1354 gtk_tree_store_clear(self
->tree_store
);
1355 webdb_cache
= irreco_data_get_webdb_cache(
1356 self
->irreco_data
, FALSE
);
1358 if (webdb_cache
->remote_id_hash
!= NULL
) {
1359 g_hash_table_remove_all(
1360 webdb_cache
->remote_id_hash
);
1362 if (webdb_cache
->remote_categories
!= NULL
) {
1363 irreco_string_table_free(
1364 webdb_cache
->remote_categories
);
1365 webdb_cache
->remote_categories
= NULL
;
1368 irreco_remote_download_dlg_loader_start(self
,
1370 irreco_remote_download_dlg_loader_categ
), NULL
);
1373 case IRRECO_REMOTE_DOWNLOAD
: {
1374 IrrecoWebdbCache
*webdb_cache
;
1375 IrrecoWebdbRemote
*remote
= self
->remote
;
1376 IrrecoThemeManager
*manager
=
1377 self
->irreco_data
->theme_manager
;
1379 gint layout_index
= 1;
1380 GString
*layout_filename
= g_string_new("");
1381 GString
*layout_data
= NULL
;
1382 const gchar
*layout_name
;
1383 IrrecoButtonLayout
*layout
;
1384 GString
*bg_image
= g_string_new("");
1386 IRRECO_DEBUG("IRRECO_REMOTE_DOWNLOAD\n");
1387 webdb_cache
= irreco_data_get_webdb_cache(
1388 self
->irreco_data
, FALSE
);
1390 if (self
->remote
== NULL
) {
1391 irreco_error_dlg(GTK_WINDOW(self
),
1392 "Select Remote first");
1396 /* Download configurations */
1397 if (!irreco_remote_download_dlg_load_configs(self
)) {
1401 /* Download themes */
1402 themes
= g_list_first(remote
->themes
);
1403 if (themes
== NULL
) {
1407 IrrecoWebdbTheme
*new_theme
;
1408 IrrecoTheme
*old_theme
= NULL
;
1409 if (GPOINTER_TO_INT(themes
->data
) == 0) {
1412 if (!irreco_webdb_cache_get_theme_by_id(
1414 GPOINTER_TO_INT(themes
->data
),
1416 irreco_error_dlg(GTK_WINDOW(self
),
1417 irreco_webdb_cache_get_error(
1421 if (!irreco_string_table_get(manager
->themes
,
1422 new_theme
->name
->str
, (gpointer
*)
1423 &old_theme
) || !g_str_equal(
1424 old_theme
->version
->str
,
1425 new_theme
->uploaded
->str
)) {
1426 if (!irreco_theme_download_dlg_run(
1428 GPOINTER_TO_INT(themes
->data
),
1429 GTK_WINDOW(self
))) {
1433 themes
= themes
->next
;
1435 irreco_theme_manager_update_theme_manager(manager
);
1437 /* Download layout */
1439 /*Create filename */
1441 g_string_printf(layout_filename
,
1443 irreco_get_config_dir("irreco"),
1445 if (!irreco_file_exists(layout_filename
->str
)) {
1446 IRRECO_DEBUG("%s\n",
1447 layout_filename
->str
);
1453 /* Get layout_data */
1454 if (!irreco_webdb_cache_get_file(webdb_cache
,
1455 remote
->file_hash
->str
,
1456 remote
->file_name
->str
,
1458 irreco_error_dlg(GTK_WINDOW(self
),
1459 irreco_webdb_cache_get_error(
1464 /* Check if there is same remotename already */
1465 if (irreco_string_table_exists(
1466 irreco_data
->irreco_layout_array
,
1467 remote
->name
->str
)) {
1469 gboolean run
= TRUE
;
1471 GKeyFile
*keyfile
= g_key_file_new();
1475 /* Create new name */
1477 new_name
= g_strdup_printf("%s_%d",
1478 remote
->name
->str
, i
++);
1479 if (!irreco_string_table_exists(
1480 irreco_data
->irreco_layout_array
,
1483 IRRECO_DEBUG("NEW NAME: %s\n",
1490 /* Create key file */
1491 if (!g_key_file_load_from_data(keyfile
,
1492 layout_data
->str
, layout_data
->len
,
1493 G_KEY_FILE_KEEP_TRANSLATIONS
, &error
)) {
1494 IRRECO_DEBUG("%s\n", error
->message
);
1495 g_error_free(error
);
1499 /* Set new name for remote */
1500 g_key_file_set_string(keyfile
, "layout",
1504 irreco_write_keyfile(keyfile
,
1505 layout_filename
->str
);
1507 /* Set new name for every button */
1508 cmd
= g_string_new("");
1509 g_string_printf(cmd
,
1510 "cat %s | sed s/^layout=%s$/layout=%s/ > %s",
1511 layout_filename
->str
,
1512 remote
->name
->str
, new_name
,
1513 layout_filename
->str
);
1515 g_string_free(cmd
, FALSE
);
1517 } else if (!irreco_write_file(layout_filename
->str
,
1518 layout_data
->str
, layout_data
->len
)) {
1519 irreco_error_dlg(GTK_WINDOW(self
),
1520 "Save file error!");
1523 irreco_config_read_layouts_from_files(irreco_data
);
1524 irreco_string_table_index(
1525 irreco_data
->irreco_layout_array
,
1526 layout_index
- 1 , &layout_name
,
1527 (gpointer
*) &layout
);
1529 g_string_printf(bg_image
, "%s",
1530 irreco_button_layout_get_bg_image(
1533 /* Find bg_image from mmc1 */
1534 bg_image
= g_string_erase(bg_image
, 10, 1);
1535 bg_image
= g_string_insert_c(bg_image
, 10, '1');
1537 /* Use mmc2 if bg_image does not exists */
1538 if (!irreco_file_exists(bg_image
->str
)) {
1539 bg_image
= g_string_erase(bg_image
, 10, 1);
1540 bg_image
= g_string_insert_c(bg_image
, 10, '2');
1543 /* Set bg-image to layout */
1544 irreco_button_layout_set_bg_image(layout
,
1546 irreco_config_save_layouts(irreco_data
);
1548 irreco_window_manager_set_layout(
1549 self
->irreco_data
->window_manager
,
1552 irreco_info_dlg(GTK_WINDOW(self
),
1553 "Remote downloaded successfully!");
1557 irreco_webdb_remote_print(self
->remote
);
1558 g_string_free(layout_filename
, FALSE
);
1559 g_string_free(bg_image
, FALSE
);
1560 if (layout_data
!= NULL
) {
1561 g_string_free(layout_data
, FALSE
);
1565 case IRRECO_REMOTE_DONE
:
1566 IRRECO_DEBUG("IRRECO_REMOTE_DONE\n");
1573 gtk_widget_destroy(GTK_WIDGET(self
));
1581 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1582 /* Events and Callbacks */
1583 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1586 * @name Events and Callbacks
1590 static gboolean
irreco_remote_download_dlg_map_event(
1591 IrrecoRemoteDownloadDlg
*self
,
1596 irreco_remote_download_dlg_loader_start(self
,
1597 G_SOURCEFUNC(irreco_remote_download_dlg_loader_categ
), NULL
);
1598 IRRECO_RETURN_BOOL(FALSE
);
1601 static void irreco_remote_download_dlg_destroy_event(
1602 IrrecoRemoteDownloadDlg
*self
,
1606 irreco_remote_download_dlg_loader_stop(self
);
1610 static void irreco_remote_download_dlg_row_activated_event(
1611 GtkTreeView
*tree_view
,
1613 GtkTreeViewColumn
*column
,
1614 IrrecoRemoteDownloadDlg
*self
)
1618 if (gtk_tree_view_row_expanded(tree_view
, path
)) {
1619 gtk_tree_view_expand_row(tree_view
, path
, FALSE
);
1621 gtk_tree_view_collapse_row(tree_view
, path
);
1626 static void irreco_remote_download_dlg_row_expanded_event(
1627 GtkTreeView
*tree_view
,
1630 IrrecoRemoteDownloadDlg
*self
)
1634 irreco_remote_download_dlg_clean_details(self
);
1636 if (self
->loader_func_id
!= 0) {
1637 gtk_tree_view_collapse_row(tree_view
, path
);
1640 if (!irreco_remote_download_dlg_row_is_loaded(self
, iter
)) {
1641 switch (irreco_remote_download_dlg_row_get_type(self
, iter
)) {
1642 case ROW_TYPE_CATEGORY
:
1643 irreco_remote_download_dlg_loader_start(self
,
1645 irreco_remote_download_dlg_loader_manuf
), iter
);
1648 case ROW_TYPE_MANUFACTURER
:
1649 irreco_remote_download_dlg_loader_start(self
,
1651 irreco_remote_download_dlg_loader_model
), iter
);
1654 case ROW_TYPE_MODEL
:
1655 irreco_remote_download_dlg_loader_start(self
,
1657 irreco_remote_download_dlg_loader_creators
),
1661 case ROW_TYPE_CREATOR
:
1662 irreco_remote_download_dlg_loader_start(self
,
1664 irreco_remote_download_dlg_loader_remotes
),
1673 static void irreco_remote_download_dlg_row_collapsed_event(
1674 GtkTreeView
*tree_view
,
1677 IrrecoRemoteDownloadDlg
*self
)
1681 irreco_remote_download_dlg_clean_details(self
);
1686 static void irreco_remote_download_dlg_row_selected_event(GtkTreeSelection
*sel
,
1687 IrrecoRemoteDownloadDlg
*self
)
1690 GtkTreeModel
*model
;
1694 if (gtk_tree_selection_get_selected (sel
, &model
, &iter
))
1696 switch (irreco_remote_download_dlg_row_get_type(self
, &iter
)) {
1698 case ROW_TYPE_REMOTE
:
1699 IRRECO_DEBUG("ROW_TYPE_REMOTE\n");
1701 IrrecoWebdbCache
*webdb_cache
;
1702 IrrecoWebdbRemote
*remote
;
1703 GString
*download_count
;
1704 GString
*theme_names
= g_string_new("");
1705 GString
*backend_names
= g_string_new("");
1707 GList
*backends
= NULL
;
1708 GList
*dummy_list
= NULL
;
1709 GList
*themes
= NULL
;
1710 GtkTextBuffer
*buffer
;
1714 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
1715 &iter
, DATA_COL
,(gpointer
) &id
, -1);
1717 /* Get remote by id */
1718 webdb_cache
= irreco_data_get_webdb_cache(
1719 self
->irreco_data
, FALSE
);
1720 if (!irreco_webdb_cache_get_remote_by_id(webdb_cache
,
1723 irreco_error_dlg(GTK_WINDOW(self
),
1724 irreco_webdb_cache_get_error(
1731 gtk_label_set_text(GTK_LABEL(self
->details_model
),
1732 remote
->model
->str
);
1735 gtk_label_set_text(GTK_LABEL(self
->details_creator
),
1736 remote
->creator
->str
);
1739 download_count
= g_string_new("");
1740 g_string_printf(download_count
, "%d times",
1741 remote
->download_count
);
1742 gtk_label_set_text(GTK_LABEL(self
->details_downloaded
),
1743 download_count
->str
);
1744 g_string_free(download_count
, FALSE
);
1747 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(
1748 self
->details_comment
));
1749 gtk_text_buffer_set_text(buffer
, remote
->comment
->str
,
1750 remote
->comment
->len
);
1751 gtk_text_view_set_buffer(GTK_TEXT_VIEW(
1752 self
->details_comment
),
1755 /* Get configurations and get backends */
1756 if (!irreco_webdb_cache_get_configurations_of_remote(
1757 webdb_cache
, id
, &configs
)) {
1758 irreco_error_dlg(GTK_WINDOW(self
),
1759 irreco_webdb_cache_get_error(
1763 configs
= g_list_first(configs
);
1765 IrrecoWebdbConf
*config
= NULL
;
1766 if (GPOINTER_TO_INT(configs
->data
) != 0 &&
1767 !irreco_webdb_cache_get_configuration(
1768 webdb_cache
, GPOINTER_TO_INT(configs
->data
),
1770 irreco_error_dlg(GTK_WINDOW(self
),
1771 irreco_webdb_cache_get_error(
1776 if (config
!= NULL
) {
1777 backends
= g_list_append(backends
,
1778 config
->backend
->str
);
1780 configs
= configs
->next
;
1783 backends
= g_list_first(backends
);
1784 dummy_list
= backends
;
1785 if (backends
== NULL
) {
1786 g_string_append_printf(backend_names
, "-");
1788 /* deletion of duplicates */
1790 const char *backend
= backends
->data
;
1791 GList
*next
= backends
->next
;
1793 if (g_str_equal(backend
,
1796 g_list_remove(backends
,
1798 dummy_list
= backends
;
1803 backends
= backends
->next
;
1807 /* Create Backends string */
1808 backends
= g_list_first(dummy_list
);
1810 const char *backend
= backends
->data
;
1811 g_string_append_printf(backend_names
,
1813 backends
= backends
->next
;
1815 if (!backends
->next
) {
1816 g_string_append_printf(
1820 g_string_append_printf(
1828 gtk_label_set_text(GTK_LABEL(self
->details_backends
),
1829 backend_names
->str
);
1831 /* Create themes string */
1832 if (!irreco_webdb_cache_get_themes_of_remote(
1833 webdb_cache
, id
, &themes
)) {
1834 irreco_error_dlg(GTK_WINDOW(self
),
1835 irreco_webdb_cache_get_error(
1839 themes
= g_list_first(themes
);
1840 if (themes
== NULL
||
1841 GPOINTER_TO_INT(themes
->data
) == 0) {
1842 g_string_append(theme_names
, "-");
1845 IrrecoWebdbTheme
*theme
= NULL
;
1846 if (GPOINTER_TO_INT(themes
->data
) != 0 &&
1847 !irreco_webdb_cache_get_theme_by_id(
1848 webdb_cache
, GPOINTER_TO_INT(themes
->data
),
1850 irreco_error_dlg(GTK_WINDOW(self
),
1851 irreco_webdb_cache_get_error(
1855 themes
= themes
->next
;
1856 if (theme
!= NULL
) {
1857 g_string_append_printf(theme_names
,
1858 "%s", theme
->name
->str
);
1861 if (!themes
->next
) {
1862 g_string_append_printf(
1866 g_string_append_printf(
1872 gtk_label_set_text(GTK_LABEL(self
->details_themes
),
1875 self
->remote
= remote
;
1876 gtk_widget_hide(GTK_WIDGET(self
->help_text
));
1877 gtk_widget_show(GTK_WIDGET(self
->details
));
1879 g_string_free(theme_names
, TRUE
);
1880 g_string_free(backend_names
, TRUE
);
1885 irreco_remote_download_dlg_clean_details(self
);
1886 gtk_widget_show(GTK_WIDGET(self
->help_text
));
1887 gtk_widget_hide(GTK_WIDGET(self
->details
));