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>
26 * @addtogroup IrrecoRemoteDownloadDlg
29 * @todo PURPOCE OF CLASS.
36 * Source file of @ref IrrecoRemoteDownloadDlg.
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
42 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 /** Button responce codes. */
46 IRRECO_REMOTE_REFRESH
,
47 IRRECO_REMOTE_DOWNLOAD
50 /** GtkTreeStore colums. */
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 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
82 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
84 static gboolean
irreco_remote_download_dlg_map_event(
85 IrrecoRemoteDownloadDlg
*self
,
88 static void irreco_remote_download_dlg_destroy_event(
89 IrrecoRemoteDownloadDlg
*self
,
91 static void irreco_remote_download_dlg_row_activated_event(
92 GtkTreeView
*tree_view
,
94 GtkTreeViewColumn
*column
,
95 IrrecoRemoteDownloadDlg
*self
);
96 static void irreco_remote_download_dlg_row_expanded_event(
97 GtkTreeView
*tree_view
,
100 IrrecoRemoteDownloadDlg
*self
);
101 static void irreco_remote_download_dlg_row_collapsed_event(
102 GtkTreeView
*tree_view
,
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
118 G_DEFINE_TYPE(IrrecoRemoteDownloadDlg
, irreco_remote_download_dlg
, IRRECO_TYPE_DLG
)
120 static void irreco_remote_download_dlg_dispose(GObject
*object
)
123 irreco_remote_download_dlg_parent_class
)->dispose(object
);
126 static void irreco_remote_download_dlg_finalize(GObject
*object
)
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
)
145 PangoFontDescription
*title_font
;
146 PangoFontDescription
*initial_font
;
147 PangoFontDescription
*menu_font
;
150 GtkWidget
*scrollbar
;
151 GtkTreeViewColumn
*column
;
152 GtkCellRenderer
*renderer
;
153 GtkTreeSelection
*select
;
154 GtkWidget
*tree_view_frame
;
155 GtkWidget
*tree_view_hbox
;
158 GtkWidget
*help_hbox
= NULL
;
159 GtkWidget
*details_alignment
;
160 GtkWidget
*details_frame
;
161 GtkWidget
*details_table
;
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
,
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
),
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
),
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
),
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
),
300 gtk_text_view_set_editable(GTK_TEXT_VIEW(self
->details_comment
),
302 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self
->details_comment
),
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);
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
),
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(
332 gtk_container_add(GTK_CONTAINER(details_alignment
), details_table
);
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
),
345 gtk_box_pack_start(GTK_BOX(help_hbox
), GTK_WIDGET(self
->help_text
),
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
));
382 IrrecoRemoteDownloadDlg
* irreco_remote_download_dlg_new(IrrecoData
*irreco_data
,
385 IrrecoRemoteDownloadDlg
*self
;
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
);
399 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
400 /* Private Functions */
401 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
404 * @name Private Functions
412 static void irreco_remote_download_dlg_clean_details(
413 IrrecoRemoteDownloadDlg
*self
)
415 GtkTextBuffer
*buffer
;
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
);
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
,
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
,
461 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
462 iter
, FLAG_COL
, &i
, -1);
464 i
= i
| ROW_CHILDREN_LOADED
;
466 i
= i
& ~ROW_CHILDREN_LOADED
;
468 gtk_tree_store_set(self
->tree_store
, iter
, FLAG_COL
, i
, -1);
476 static gint
irreco_remote_download_dlg_row_get_type(
477 IrrecoRemoteDownloadDlg
*self
,
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
,
514 if (self
->banner
== NULL
) {
515 self
->banner
= hildon_banner_show_progress(GTK_WIDGET(self
),
519 hildon_banner_set_text(HILDON_BANNER(self
->banner
), text
);
520 hildon_banner_set_fraction(HILDON_BANNER(self
->banner
), fraction
);
525 * Destroy banner, if it exists.
527 static void irreco_remote_download_dlg_hide_banner(
528 IrrecoRemoteDownloadDlg
*self
)
532 gtk_widget_destroy(self
->banner
);
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
)
548 if (self
->loader_func_id
== 0) {
550 self
->loader_parent_iter
= gtk_tree_iter_copy(
555 self
->loader_func_id
= g_idle_add(function
, self
);
557 IRRECO_ERROR("Loader function pointer not given.\n");
565 * Stop and cleanup loader if a loader is running.
567 static void irreco_remote_download_dlg_loader_stop(
568 IrrecoRemoteDownloadDlg
*self
)
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
;
583 static gboolean
irreco_remote_download_dlg_loader_categ(
584 IrrecoRemoteDownloadDlg
*self
)
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
: {
598 GtkTreeIter iter_loading
;
599 IrrecoStringTable
*categories
;
600 IrrecoWebdbCache
*webdb_cache
= NULL
;
602 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
,
604 if(irreco_webdb_cache_get_remote_categories(webdb_cache
,
606 IRRECO_STRING_TABLE_FOREACH_KEY(categories
, key
)
608 /* Append categogy. */
609 gtk_tree_store_append(self
->tree_store
,
611 gtk_tree_store_set(self
->tree_store
,
612 &iter
, TEXT_COL
, key
,
613 FLAG_COL
, ROW_TYPE_CATEGORY
,
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
,
621 TEXT_COL
, _("Loading ..."),
622 FLAG_COL
, ROW_TYPE_LOADING
,
624 IRRECO_STRING_TABLE_FOREACH_END
626 irreco_error_dlg(GTK_WINDOW(self
),
627 irreco_webdb_cache_get_error(
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
)
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
: {
659 GtkTreeIter iter_loading
;
660 IrrecoStringTable
*manufacturers
;
661 IrrecoWebdbCache
*webdb_cache
= NULL
;
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
,
671 if(irreco_webdb_cache_get_remote_manufacturers(webdb_cache
,
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
,
682 FLAG_COL
, ROW_TYPE_MANUFACTURER
,
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
,
690 TEXT_COL
, _("Loading ..."),
691 FLAG_COL
, ROW_TYPE_LOADING
,
694 IRRECO_STRING_TABLE_FOREACH_END
696 irreco_error_dlg(GTK_WINDOW(self
),
697 irreco_webdb_cache_get_error(
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
,
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
)
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
: {
741 GtkTreeIter iter_loading
;
742 GtkTreeIter category_iter
;
743 IrrecoStringTable
*models
= NULL
;
744 IrrecoWebdbCache
*webdb_cache
= NULL
;
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
),
756 self
->loader_parent_iter
);
758 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
760 TEXT_COL
, &category
, -1);
762 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
,
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
,
776 FLAG_COL
, ROW_TYPE_MODEL
,
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
,
784 TEXT_COL
, _("Loading ..."),
785 FLAG_COL
, ROW_TYPE_LOADING
,
788 IRRECO_STRING_TABLE_FOREACH_END
790 irreco_error_dlg(GTK_WINDOW(self
),
791 irreco_webdb_cache_get_error(
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
,
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
)
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
;
841 GtkTreeIter iter_loading
;
847 IrrecoStringTable
*creators
;
849 /*Get manufacturer_iter and category_iter */
851 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
853 self
->loader_parent_iter
);
855 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
859 /*Get category, manufacturer and model*/
861 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
863 TEXT_COL
, &category
, -1);
865 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
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
,
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
,
888 FLAG_COL
, ROW_TYPE_CREATOR
,
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
,
896 TEXT_COL
, _("Loading ..."),
897 FLAG_COL
, ROW_TYPE_LOADING
,
900 IRRECO_STRING_TABLE_FOREACH_END
902 irreco_error_dlg(GTK_WINDOW(self
),
903 irreco_webdb_cache_get_error(
907 g_free (manufacturer
);
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
,
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
)
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
;
964 IrrecoWebdbRemote
*remote
;
965 GList
*remotes
= NULL
;
970 gint remote_count
= 0;
973 /*Get manufacturer_iter and category_iter */
975 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
977 self
->loader_parent_iter
);
979 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
983 gtk_tree_model_iter_parent(GTK_TREE_MODEL(self
->tree_store
),
987 /*Get category, manufacturer and model*/
989 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
991 TEXT_COL
, &category
, -1);
993 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
995 TEXT_COL
, &manufacturer
, -1);
997 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
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
,
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(
1017 remote_id
= GPOINTER_TO_INT(g_list_nth_data(remotes
,
1020 if(!irreco_webdb_cache_get_remote_by_id(webdb_cache
, remote_id
,
1022 irreco_error_dlg(GTK_WINDOW(self
),
1023 irreco_webdb_cache_get_error(
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(
1037 configs
= g_list_first(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(
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(
1059 themes
= g_list_first(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(
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
);
1093 g_free (manufacturer
);
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 ..."),
1107 if (self
->loader_pos
+ 1 >= remote_count
) {
1108 self
->loader_state
= LOADER_STATE_END
;
1109 IRRECO_RETURN_BOOL(TRUE
);
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
,
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
;
1139 gboolean success
= TRUE
;
1140 gboolean new_instance
= FALSE
;
1141 GList
*configurations
;
1142 IrrecoWebdbConf
*config
;
1143 GString
*instance_number
= g_string_new("");
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) {
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(
1162 if(config
== NULL
) {
1163 g_string_printf(error_msg
, "Configuration is NULL");
1168 if (!irreco_webdb_cache_get_file(webdb_cache
,
1169 config
->file_hash
->str
,
1170 config
->file_name
->str
,
1172 g_string_printf(error_msg
, "%s",
1173 irreco_webdb_cache_get_error(
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.");
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
)) {
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
);
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
);
1208 /* Check if many instances */
1209 IRRECO_BACKEND_MANAGER_FOREACH_INSTANCE(manager
,
1211 irreco_backend_instance_get_description(
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
,
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
;
1235 IRRECO_STRING_TABLE_FOREACH_END
1238 g_string_printf(error_msg
,
1239 "\"%s\" backend is not installed...",
1240 config
->backend
->str
);
1244 irreco_backend_instance_configure(inst
, GTK_WINDOW(self
));
1245 irreco_backend_instance_save_to_conf(inst
);
1246 irreco_config_save_backends(manager
);
1249 file_container
= irreco_backend_file_container_new();
1250 irreco_backend_file_container_set(file_container
,
1252 config
->category
->str
,
1253 config
->manufacturer
->str
,
1255 config
->file_name
->str
,
1258 if (irreco_backend_instance_check_conf(inst
, file_container
)) {
1259 g_string_printf(error_msg
,
1260 "\"%s\" backend already contains\n"
1262 "Do you want to overwrite?",
1263 inst
->lib
->name
, config
->model
->str
);
1264 success
= irreco_yes_no_dlg(GTK_WINDOW(self
),
1266 g_string_erase(error_msg
, 0, -1);
1268 if(success
== FALSE
) {
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
);
1278 g_string_printf(error_msg
, "Backend error");
1281 irreco_backend_manager_destroy_instance(manager
,
1286 configurations
= configurations
->next
;
1287 irreco_backend_file_container_free(file_container
);
1288 file_container
= NULL
;
1291 g_string_free(file_data
, FALSE
);
1296 if(error_msg
->len
> 0) {
1297 irreco_error_dlg(GTK_WINDOW(self
), error_msg
->str
);
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
);
1315 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1316 /* Public Functions */
1317 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1320 * @name Public Functions
1324 gboolean
irreco_show_remote_download_dlg(IrrecoData
*irreco_data
,
1327 IrrecoRemoteDownloadDlg
*self
;
1328 gboolean loop
= TRUE
;
1329 IrrecoWebdbCache
*webdb_cache
;
1330 gboolean downloaded
= FALSE
;
1333 self
= irreco_remote_download_dlg_new(irreco_data
, parent
);
1336 gint response
= gtk_dialog_run(GTK_DIALOG(self
));
1337 if (self
->loader_func_id
!= 0) {
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
,
1359 irreco_remote_download_dlg_loader_categ
), NULL
);
1362 case IRRECO_REMOTE_DOWNLOAD
: {
1363 IrrecoWebdbCache
*webdb_cache
;
1364 IrrecoWebdbRemote
*remote
= self
->remote
;
1365 IrrecoThemeManager
*manager
=
1366 self
->irreco_data
->theme_manager
;
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
;
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");
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
)) {
1401 /* Download configurations */
1402 if (!irreco_remote_download_dlg_load_configs(self
)) {
1406 /* Download themes */
1407 themes
= g_list_first(remote
->themes
);
1408 if (themes
== NULL
) {
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(
1419 GPOINTER_TO_INT(themes
->data
),
1421 irreco_error_dlg(GTK_WINDOW(self
),
1422 irreco_webdb_cache_get_error(
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(
1433 GPOINTER_TO_INT(themes
->data
),
1434 GTK_WINDOW(self
))) {
1438 themes
= themes
->next
;
1440 irreco_theme_manager_update_theme_manager(manager
);
1442 /* Download layout */
1444 /*Create filename */
1446 g_string_printf(layout_filename
,
1448 irreco_get_config_dir("irreco"),
1450 if (!irreco_file_exists(layout_filename
->str
)) {
1451 IRRECO_DEBUG("%s\n",
1452 layout_filename
->str
);
1458 /* Get layout_data */
1459 if (!irreco_webdb_cache_get_remote_data(webdb_cache
,
1462 irreco_error_dlg(GTK_WINDOW(self
),
1463 irreco_webdb_cache_get_error(
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
)) {
1476 gboolean run
= TRUE
;
1478 GKeyFile
*keyfile
= g_key_file_new();
1482 /* Create new name */
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
,
1490 IRRECO_DEBUG("NEW NAME: %s\n",
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
);
1506 /* Set new name for remote */
1507 g_key_file_set_string(keyfile
, "layout",
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
);
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!");
1535 dir_data
.directory
= irreco_get_config_dir("irreco");
1536 dir_data
.filesuffix
= ".conf";
1537 g_string_printf(layout_filename
, "layout%d.conf",
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
),
1555 g_string_printf(bg_image
, "%s",
1556 irreco_button_layout_get_bg_image(
1559 if (bg_image
->len
< 10) {
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
);
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
,
1586 irreco_config_save_layouts(irreco_data
);
1590 irreco_window_manager_set_layout(
1591 self
->irreco_data
->window_manager
,
1594 irreco_info_dlg(GTK_WINDOW(self
),
1595 "Remote downloaded successfully!");
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
);
1612 case GTK_RESPONSE_DELETE_EVENT
:
1613 IRRECO_DEBUG("GTK_RESPONSE_DELETE_EVENT\n");
1620 gtk_widget_destroy(GTK_WIDGET(self
));
1621 IRRECO_RETURN_BOOL(downloaded
);
1628 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1629 /* Events and Callbacks */
1630 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1633 * @name Events and Callbacks
1637 static gboolean
irreco_remote_download_dlg_map_event(
1638 IrrecoRemoteDownloadDlg
*self
,
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
,
1653 irreco_remote_download_dlg_loader_stop(self
);
1657 static void irreco_remote_download_dlg_row_activated_event(
1658 GtkTreeView
*tree_view
,
1660 GtkTreeViewColumn
*column
,
1661 IrrecoRemoteDownloadDlg
*self
)
1665 if (gtk_tree_view_row_expanded(tree_view
, path
)) {
1666 gtk_tree_view_expand_row(tree_view
, path
, FALSE
);
1668 gtk_tree_view_collapse_row(tree_view
, path
);
1673 static void irreco_remote_download_dlg_row_expanded_event(
1674 GtkTreeView
*tree_view
,
1677 IrrecoRemoteDownloadDlg
*self
)
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
,
1692 irreco_remote_download_dlg_loader_manuf
), iter
);
1695 case ROW_TYPE_MANUFACTURER
:
1696 irreco_remote_download_dlg_loader_start(self
,
1698 irreco_remote_download_dlg_loader_model
), iter
);
1701 case ROW_TYPE_MODEL
:
1702 irreco_remote_download_dlg_loader_start(self
,
1704 irreco_remote_download_dlg_loader_creators
),
1708 case ROW_TYPE_CREATOR
:
1709 irreco_remote_download_dlg_loader_start(self
,
1711 irreco_remote_download_dlg_loader_remotes
),
1720 static void irreco_remote_download_dlg_row_collapsed_event(
1721 GtkTreeView
*tree_view
,
1724 IrrecoRemoteDownloadDlg
*self
)
1728 irreco_remote_download_dlg_clean_details(self
);
1733 static void irreco_remote_download_dlg_row_selected_event(GtkTreeSelection
*sel
,
1734 IrrecoRemoteDownloadDlg
*self
)
1737 GtkTreeModel
*model
;
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("");
1754 GList
*backends
= NULL
;
1755 GList
*dummy_list
= NULL
;
1756 GList
*themes
= NULL
;
1757 GtkTextBuffer
*buffer
;
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
,
1770 irreco_error_dlg(GTK_WINDOW(self
),
1771 irreco_webdb_cache_get_error(
1778 gtk_label_set_text(GTK_LABEL(self
->details_model
),
1779 remote
->model
->str
);
1782 gtk_label_set_text(GTK_LABEL(self
->details_creator
),
1783 remote
->creator
->str
);
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
);
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
),
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(
1810 configs
= g_list_first(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
),
1817 irreco_error_dlg(GTK_WINDOW(self
),
1818 irreco_webdb_cache_get_error(
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
, "-");
1835 /* deletion of duplicates */
1837 const char *backend
= backends
->data
;
1838 GList
*next
= backends
->next
;
1840 if (g_str_equal(backend
,
1843 g_list_remove(backends
,
1845 dummy_list
= backends
;
1850 backends
= backends
->next
;
1854 /* Create Backends string */
1855 backends
= g_list_first(dummy_list
);
1857 const char *backend
= backends
->data
;
1858 g_string_append_printf(backend_names
,
1860 backends
= backends
->next
;
1862 if (!backends
->next
) {
1863 g_string_append_printf(
1867 g_string_append_printf(
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(
1886 themes
= g_list_first(themes
);
1887 if (themes
== NULL
||
1888 GPOINTER_TO_INT(themes
->data
) == 0) {
1889 g_string_append(theme_names
, "-");
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
),
1897 irreco_error_dlg(GTK_WINDOW(self
),
1898 irreco_webdb_cache_get_error(
1902 themes
= themes
->next
;
1903 if (theme
!= NULL
) {
1904 g_string_append_printf(theme_names
,
1905 "%s", theme
->name
->str
);
1908 if (!themes
->next
) {
1909 g_string_append_printf(
1913 g_string_append_printf(
1919 gtk_label_set_text(GTK_LABEL(self
->details_themes
),
1922 self
->remote
= remote
;
1923 gtk_widget_hide(GTK_WIDGET(self
->help_text
));
1924 gtk_widget_show(GTK_WIDGET(self
->details
));
1926 g_string_free(theme_names
, TRUE
);
1927 g_string_free(backend_names
, TRUE
);
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
));