2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com)
4 * Joni Kokko (t5kojo01@students.oamk.fi),
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "irreco_theme_manager_dlg.h"
22 #include <hildon/hildon-banner.h>
23 #include "irreco_webdb_register_dlg.h"
24 #include "irreco_select_instance_dlg.h"
25 #include "irreco_config.h"
28 * @addtogroup IrrecoThemeManagerDlg
31 * @todo PURPOCE OF CLASS.
38 * Source file of @ref IrrecoThemeManagerDlg.
42 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
45 #define IRRECO_BACKGROUND_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 6)
46 #define IRRECO_BACKGROUND_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 6)
49 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
51 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
53 static void irreco_theme_manager_dlg_hide_banner(IrrecoThemeManagerDlg
*self
);
54 static void irreco_theme_manager_dlg_loader_stop(IrrecoThemeManagerDlg
*self
);
56 static void irreco_theme_manager_dlg_clean_details(IrrecoThemeManagerDlg
*self
);
59 irreco_theme_manager_dlg_loader_deb(IrrecoThemeManagerDlg
*self
);
61 irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg
*self
);
63 irreco_theme_manager_dlg_loader_web(IrrecoThemeManagerDlg
*self
);
65 irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg
*self
);
67 irreco_theme_manager_dlg_theme_db_detail_loader(IrrecoThemeManagerDlg
*self
);
69 irreco_theme_manager_dlg_bg_loader(IrrecoThemeManagerDlg
*self
);
71 irreco_theme_manager_dlg_button_loader(IrrecoThemeManagerDlg
*self
);
75 irreco_theme_manager_dlg_display_theme_detail(IrrecoThemeManagerDlg
*self
,
78 static gboolean
irreco_show_theme_manager_dlg_map_event(IrrecoThemeManagerDlg
79 *self
, GdkEvent
*event
,
81 static void irreco_show_theme_manager_dlg_destroy_event(IrrecoThemeManagerDlg
86 irreco_show_theme_manager_dlg_row_activated_event(GtkTreeView
*tree_view
,
88 GtkTreeViewColumn
*column
,
89 IrrecoThemeManagerDlg
*self
);
92 irreco_show_theme_manager_dlg_row_expanded_event(GtkTreeView
*tree_view
,
95 IrrecoThemeManagerDlg
*self
);
97 irreco_show_theme_manager_dlg_row_collapsed_event(GtkTreeView
*tree_view
,
100 IrrecoThemeManagerDlg
*self
);
104 irreco_show_theme_manager_dlg_row_selected_event(GtkTreeSelection
*sel
,
105 IrrecoThemeManagerDlg
*self
);
107 gboolean
irreco_theme_manager_dlg_preview_dlg(GtkWidget
*widget
,
108 GdkEventButton
*event
,
109 IrrecoThemeManagerDlg
*self
);
112 static void irreco_theme_manager_dlg_upload_theme(GtkButton
*button
,
113 IrrecoThemeManagerDlg
*self
);
115 static void irreco_theme_manager_dlg_delete_theme(GtkButton
*button
,
116 IrrecoThemeManagerDlg
*self
);
118 irreco_theme_manager_dlg_download_theme(GtkButton
*button
,
119 IrrecoThemeManagerDlg
*self
);
122 irreco_theme_manager_dlg_selected_version_dlg(GtkComboBox
*widget
,
123 IrrecoThemeManagerDlg
*self
);
125 void irreco_theme_manager_update_theme_manager(IrrecoThemeManager
*self
);
127 static void irreco_theme_manager_dlg_new_theme(GtkButton
*button
,
128 IrrecoThemeManagerDlg
*self
);
130 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
132 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
134 /** Button responce codes. */
136 IRRECO_DEVICE_REFRESH
139 /** GtkTreeStore colums. */
148 /** Version colums. */
155 /** Loader states. */
167 ROW_CHILDREN_LOADED
= 1 << 1,
168 ROW_TYPE_CATEGORY
= 1 << 2,
169 ROW_TYPE_DEB
= 1 << 3,
170 ROW_TYPE_USER
= 1 << 4,
171 ROW_TYPE_WEB
= 1 << 5,
172 ROW_TYPE_DB
= 1 << 6,
173 ROW_TYPE_LOADING
= 1 << 7
176 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
177 /* Construction & Destruction */
178 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
181 * @name Construction & Destruction
185 G_DEFINE_TYPE(IrrecoThemeManagerDlg
, irreco_theme_manager_dlg
, IRRECO_TYPE_DLG
)
187 static void irreco_theme_manager_dlg_finalize(GObject
*object
)
189 if (G_OBJECT_CLASS(irreco_theme_manager_dlg_parent_class
)->finalize
)
190 G_OBJECT_CLASS(irreco_theme_manager_dlg_parent_class
)->finalize(
195 irreco_theme_manager_dlg_class_init(IrrecoThemeManagerDlgClass
*klass
)
197 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
198 object_class
->finalize
= irreco_theme_manager_dlg_finalize
;
201 static void irreco_theme_manager_dlg_init(IrrecoThemeManagerDlg
*self
)
203 GtkTreeViewColumn
*column
;
204 GtkCellRenderer
*renderer
;
205 GtkTreeSelection
*select
;
206 GtkWidget
*label_name
;
207 GtkWidget
*label_description
;
208 /*GtkWidget *label_rate;*/
209 GtkWidget
*theme_info_frame
;
210 GtkWidget
*tree_view_frame
;
211 GtkWidget
*tree_view_hbox
;
212 GtkWidget
*preview_frame
;
213 PangoFontDescription
*initial_font
;
214 GtkWidget
*select_vbox
;
215 GtkWidget
*versions_hbox
;
216 GtkWidget
*comment_alignment
;
217 GtkWidget
*info_scrollbar
;
218 GtkWidget
*scrollbar
;
219 GtkWidget
*theme_info
;
221 GtkWidget
*info_vbox
;
222 GtkWidget
*done_button
;
223 GtkWidget
*theme_table
;
224 GtkWidget
*preview_event_box
;
228 self
->theme_folder
= NULL
;
230 /* Construct dialog. */
231 gtk_window_set_title(GTK_WINDOW(self
),
232 _("Theme Manager "));
233 /*gtk_window_set_decorated (GTK_WINDOW(self), FALSE);*/
234 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
235 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
236 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
240 self
->refresh_button
= gtk_dialog_add_button (GTK_DIALOG(self
),
242 IRRECO_DEVICE_REFRESH
);
243 self
->new_button
= gtk_dialog_add_button (GTK_DIALOG(self
),
244 _("New"), GTK_RESPONSE_NONE
);
246 self
->upload_button
= gtk_dialog_add_button (GTK_DIALOG(self
),
247 _("Upload"), GTK_RESPONSE_NONE
);
250 self
->download_button
= gtk_dialog_add_button (GTK_DIALOG(self
),
253 self
->clear_button
= gtk_dialog_add_button (GTK_DIALOG(self
),
256 done_button
= gtk_dialog_add_button (GTK_DIALOG(self
),
258 GTK_RESPONSE_CANCEL
);
260 /* Create theme table */
262 table
= gtk_table_new(7,7,TRUE
);
263 gtk_table_set_col_spacings(GTK_TABLE (table
), 8);
264 gtk_table_set_row_spacings(GTK_TABLE (table
), 8);
265 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self
)->vbox
),
266 irreco_gtk_align(GTK_WIDGET(table
),
267 0, 0, 1, 1, 8, 8, 8, 8));
268 /* Create tree_view_hbox */
269 tree_view_hbox
= gtk_hbox_new(FALSE
, 2);
271 /* Create Treeview */
272 self
->tree_store
= gtk_tree_store_new(
273 N_COLUMNS
, G_TYPE_STRING
, G_TYPE_INT
, G_TYPE_POINTER
);
274 self
->tree_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(
275 GTK_TREE_MODEL(self
->tree_store
)));
277 renderer
= gtk_cell_renderer_text_new();
278 column
= gtk_tree_view_column_new_with_attributes(
279 NULL
, renderer
, "text", TEXT_COL
, NULL
);
280 gtk_tree_view_append_column(self
->tree_view
, column
);
282 gtk_box_pack_start(GTK_BOX(tree_view_hbox
), GTK_WIDGET(self
->tree_view
),
285 /* Create scrollbar for Treeview */
287 scrollbar
= gtk_scrolled_window_new(NULL
, NULL
);
288 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar
),
289 GTK_POLICY_AUTOMATIC
,
290 GTK_POLICY_AUTOMATIC
);
292 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
293 scrollbar
), tree_view_hbox
);
295 /* Create Frame for Treeview */
296 tree_view_frame
= gtk_frame_new("");
297 gtk_frame_set_label_widget(GTK_FRAME(tree_view_frame
),
298 irreco_gtk_label_bold("Themes", 0, 0, 0, 0, 0, 0));
300 gtk_container_add(GTK_CONTAINER(tree_view_frame
),
301 GTK_WIDGET(scrollbar
));
303 /* Create theme_info */
305 theme_info
= gtk_table_new(7, 4, TRUE
);
306 gtk_table_set_col_spacings(GTK_TABLE(theme_info
), 8);
307 gtk_table_set_row_spacings(GTK_TABLE(theme_info
), 8);
309 /* Scrolled window for info */
310 info_scrollbar
= gtk_scrolled_window_new(NULL
, NULL
);
311 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
314 GTK_POLICY_AUTOMATIC
);
317 self
->version_store
= gtk_tree_store_new(
318 2, G_TYPE_STRING
, G_TYPE_STRING
);
320 self
->combobox
= gtk_combo_box_new_text();
321 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(self
->combobox
), 1);
322 gtk_combo_box_set_model(GTK_COMBO_BOX(self
->combobox
),
323 GTK_TREE_MODEL(self
->version_store
));
325 theme_table
= gtk_table_new(5, 7, TRUE
);
326 gtk_table_set_col_spacings(GTK_TABLE(theme_table
), 1);
327 gtk_table_set_row_spacings(GTK_TABLE(theme_table
), 1);
329 info_vbox
= gtk_vbox_new(FALSE
, 1);
332 preview_event_box
= gtk_event_box_new();
333 self
->select_label
= gtk_label_new(" Select \ncategory");
335 /* Create frame for theme_info */
336 select_vbox
= gtk_vbox_new(FALSE
, 2);
337 versions_hbox
= gtk_hbox_new(FALSE
, 2);
338 theme_info_frame
= gtk_frame_new("");
339 gtk_frame_set_label_widget(GTK_FRAME(theme_info_frame
),
340 irreco_gtk_label_bold("Info", 0, 0, 0, 0, 0, 0));
341 self
->theme_info_alignment
= gtk_alignment_new(0, 0, 0, 0);
342 gtk_alignment_set_padding(GTK_ALIGNMENT(self
->theme_info_alignment
),
346 preview_frame
= gtk_frame_new(NULL
);
347 gtk_frame_set_shadow_type(GTK_FRAME(preview_frame
), GTK_SHADOW_OUT
);
349 self
->theme_image
= gtk_image_new();
350 gtk_image_set_from_file(GTK_IMAGE(self
->theme_image
), NULL
);
354 /*label_rate = gtk_label_new(" Rating");*/
355 label_name
= gtk_label_new("Name: ");
356 self
->label_creator
= gtk_label_new("Author: ");
357 self
->label_download
= gtk_label_new("Downloads: ");
358 label_description
= gtk_label_new("Comment: ");
359 self
->label_combobox
= gtk_label_new("Version:");
361 self
->theme_name
= gtk_label_new("");
362 self
->theme_creator
= gtk_label_new("");
363 self
->theme_downloaded
= gtk_label_new("");
364 self
->theme_comment
= gtk_label_new("");
365 self
->theme_version
= gtk_label_new("");
367 comment_alignment
= gtk_alignment_new(0, 0, 0, 0);
368 gtk_widget_set_size_request(self
->theme_comment
,
370 gtk_alignment_set_padding(GTK_ALIGNMENT(comment_alignment
),
372 gtk_label_set_line_wrap(GTK_LABEL(self
->theme_comment
), TRUE
);
373 gtk_label_set_line_wrap_mode(GTK_LABEL(self
->theme_comment
),
376 /*gtk_misc_set_alignment(GTK_MISC(label_rate), 0, 0.5);*/
377 gtk_misc_set_alignment(GTK_MISC(label_name
), 0, 0.5);
378 gtk_misc_set_alignment(GTK_MISC(self
->label_creator
), 0, 0.5);
379 gtk_misc_set_alignment(GTK_MISC(self
->label_download
), 0, 0.5);
380 gtk_misc_set_alignment(GTK_MISC(label_description
), 0, 0.5);
381 gtk_misc_set_alignment(GTK_MISC(self
->label_combobox
), 0, 0.5);
382 gtk_misc_set_alignment(GTK_MISC(self
->theme_name
), 0, 0.5);
383 gtk_misc_set_alignment(GTK_MISC(self
->theme_creator
), 0, 0.5);
384 gtk_misc_set_alignment(GTK_MISC(self
->theme_downloaded
), 0, 0.5);
385 gtk_misc_set_alignment(GTK_MISC(self
->theme_comment
), 0, 0.5);
386 gtk_misc_set_alignment(GTK_MISC(self
->theme_version
), 0, 0.5);
389 /*Attach WidGets to tables*/
391 gtk_table_attach(GTK_TABLE(theme_info
), info_scrollbar
,
392 0, 4, 4, 7, GTK_FILL
, GTK_FILL
, 0, 0);
394 gtk_table_attach_defaults(GTK_TABLE(table
),
395 tree_view_frame
, 0, 3, 0, 7);
396 gtk_table_attach_defaults(GTK_TABLE(theme_info
),
397 preview_event_box
, 3, 4, 0, 3);
398 /* gtk_table_attach_defaults(GTK_TABLE(self->theme_info),
399 label_rate, 3, 4, 3, 4);*/
400 gtk_table_attach_defaults(GTK_TABLE(theme_info
),
401 theme_table
, 0, 3, 0, 4);
402 gtk_table_attach_defaults(GTK_TABLE(theme_table
),
403 label_name
, 0, 3, 0, 1);
404 gtk_table_attach_defaults(GTK_TABLE(theme_table
),
405 self
->label_creator
, 0, 3, 1, 2);
406 gtk_table_attach_defaults(GTK_TABLE(theme_table
),
407 self
->label_download
, 0, 3, 2, 3);
408 gtk_table_attach_defaults(GTK_TABLE(theme_table
),
409 label_description
, 0, 3, 4, 5);
410 gtk_table_attach_defaults(GTK_TABLE(theme_table
),
411 self
->label_combobox
, 0, 3, 3, 4);
412 gtk_table_attach_defaults(GTK_TABLE(theme_table
),
413 versions_hbox
, 3, 7, 3, 4);
414 gtk_table_attach_defaults(GTK_TABLE(table
),
415 theme_info_frame
, 3, 7, 0, 7);
416 gtk_table_attach(GTK_TABLE(theme_table
), self
->theme_name
,
417 3, 7, 0, 1, GTK_FILL
, GTK_FILL
, 0, 0);
418 gtk_table_attach(GTK_TABLE(theme_table
), self
->theme_creator
,
419 3, 7, 1, 2, GTK_FILL
, GTK_FILL
, 0, 0);
420 gtk_table_attach(GTK_TABLE(theme_table
), self
->theme_downloaded
,
421 3, 7, 2, 3, GTK_FILL
, GTK_FILL
, 0, 0);
425 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
426 info_scrollbar
), info_vbox
);
427 gtk_container_add(GTK_CONTAINER(preview_frame
),
429 gtk_container_add(GTK_CONTAINER(preview_event_box
),
431 gtk_container_add(GTK_CONTAINER(info_vbox
), comment_alignment
);
432 gtk_container_add(GTK_CONTAINER(comment_alignment
),
433 self
->theme_comment
);
434 gtk_container_add(GTK_CONTAINER(theme_info_frame
),
435 GTK_WIDGET(select_vbox
));
436 gtk_container_add(GTK_CONTAINER(select_vbox
),
437 GTK_WIDGET(self
->theme_info_alignment
));
438 gtk_container_add(GTK_CONTAINER(select_vbox
),
439 GTK_WIDGET(self
->select_label
));
440 gtk_container_add(GTK_CONTAINER(self
->theme_info_alignment
),
441 GTK_WIDGET(theme_info
));
442 gtk_container_add(GTK_CONTAINER(versions_hbox
),
443 GTK_WIDGET(self
->theme_version
));
444 gtk_container_add(GTK_CONTAINER(versions_hbox
),
445 GTK_WIDGET(self
->combobox
));
447 /*Set font size and style*/
449 initial_font
= pango_font_description_from_string ("Sans Bold 16");
450 gtk_widget_modify_font (self
->select_label
, initial_font
);
452 initial_font
= pango_font_description_from_string ("Sans Bold 12");
453 /*gtk_widget_modify_font (label_rate, initial_font);*/
454 gtk_widget_modify_font (label_name
, initial_font
);
455 gtk_widget_modify_font (self
->label_creator
, initial_font
);
456 gtk_widget_modify_font (self
->label_download
, initial_font
);
457 gtk_widget_modify_font (label_description
, initial_font
);
458 gtk_widget_modify_font (self
->label_combobox
, initial_font
);
460 initial_font
= pango_font_description_from_string ("Sans 11");
461 gtk_widget_modify_font (self
->theme_name
, initial_font
);
462 gtk_widget_modify_font (self
->theme_creator
, initial_font
);
463 gtk_widget_modify_font (self
->theme_downloaded
, initial_font
);
464 gtk_widget_modify_font (self
->theme_comment
, initial_font
);
465 gtk_widget_modify_font (self
->theme_version
, initial_font
);
466 gtk_widget_modify_font (self
->combobox
, initial_font
);
468 /* Setup the selection handler for TREE */
469 select
= gtk_tree_view_get_selection(self
->tree_view
);
470 gtk_tree_selection_set_mode(select
, GTK_SELECTION_SINGLE
);
472 /* Signal handlers. */
473 g_signal_connect(G_OBJECT(self
), "map-event",
474 G_CALLBACK(irreco_show_theme_manager_dlg_map_event
), NULL
);
475 g_signal_connect(G_OBJECT(self
), "destroy",
476 G_CALLBACK(irreco_show_theme_manager_dlg_destroy_event
), NULL
);
477 g_signal_connect(G_OBJECT(self
->tree_view
), "row-activated",
478 G_CALLBACK(irreco_show_theme_manager_dlg_row_activated_event
),
480 g_signal_connect(G_OBJECT(self
->tree_view
), "row-expanded",
481 G_CALLBACK(irreco_show_theme_manager_dlg_row_expanded_event
),
483 g_signal_connect(G_OBJECT(self
->tree_view
), "row-collapsed",
484 G_CALLBACK(irreco_show_theme_manager_dlg_row_collapsed_event
),
486 g_signal_connect(G_OBJECT (select
), "changed",
487 G_CALLBACK (irreco_show_theme_manager_dlg_row_selected_event
),
489 g_signal_connect(G_OBJECT (self
->combobox
), "changed",
490 G_CALLBACK (irreco_theme_manager_dlg_selected_version_dlg
),
492 g_signal_connect(G_OBJECT(preview_event_box
),
493 "button-release-event",
494 G_CALLBACK(irreco_theme_manager_dlg_preview_dlg
),
496 g_signal_connect(G_OBJECT(self
->upload_button
),
498 G_CALLBACK(irreco_theme_manager_dlg_upload_theme
),
500 g_signal_connect(G_OBJECT(self
->clear_button
),
502 G_CALLBACK(irreco_theme_manager_dlg_delete_theme
),
504 g_signal_connect(G_OBJECT(self
->download_button
),
506 G_CALLBACK(irreco_theme_manager_dlg_download_theme
),
508 g_signal_connect(G_OBJECT(self
->new_button
),
510 G_CALLBACK(irreco_theme_manager_dlg_new_theme
),
514 gtk_tree_view_set_enable_tree_lines(self
->tree_view
, TRUE
);
515 g_object_set (G_OBJECT (self
->tree_view
), "show-expanders", TRUE
, NULL
);
516 g_object_set (G_OBJECT (self
->tree_view
), "level-indentation", 0, NULL
);
517 gtk_tree_view_set_rubber_banding(self
->tree_view
, FALSE
);
519 gtk_widget_set_size_request(GTK_WIDGET(self
), 696, 396);
520 gtk_widget_show_all(GTK_WIDGET(self
));
525 GtkWidget
*irreco_theme_manager_dlg_new(IrrecoData
*irreco_data
,
528 IrrecoThemeManagerDlg
*self
;
532 self
= g_object_new(IRRECO_TYPE_THEME_MANAGER_DLG
, NULL
);
533 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
534 irreco_theme_manager_dlg_set_irreco_data(self
, irreco_data
);
536 IRRECO_RETURN_PTR(self
);
540 * Show whole preview image
544 gboolean
irreco_theme_manager_dlg_preview_dlg(GtkWidget
*widget
,
545 GdkEventButton
*event
,
546 IrrecoThemeManagerDlg
*self
)
548 if(self
->preview_add
!=NULL
|| self
->webdb_theme
->preview_button
!=NULL
){
550 GtkWidget
*image
, *event_box
;
551 GtkWidget
*preview_dialog
;
555 preview_dialog
= irreco_dlg_new ();
556 gtk_window_set_title(GTK_WINDOW(preview_dialog
), _("Preview"));
557 gtk_window_set_modal(GTK_WINDOW(preview_dialog
), TRUE
);
558 gtk_window_set_destroy_with_parent(GTK_WINDOW(preview_dialog
), TRUE
);
559 gtk_dialog_set_has_separator(GTK_DIALOG(preview_dialog
), FALSE
);
561 gtk_widget_set_size_request(preview_dialog
, 185, -1);
563 event_box
= gtk_event_box_new();
564 image
= gtk_image_new();
565 if(self
->preview_add
!= NULL
){
566 gtk_image_set_from_file(GTK_IMAGE(image
), self
->preview_add
);
569 gtk_image_set_from_pixbuf(GTK_IMAGE(image
),
570 GDK_PIXBUF(self
->webdb_theme
->preview_button
));
573 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(preview_dialog
)->vbox
),
575 gtk_container_add(GTK_CONTAINER(event_box
), image
);
577 g_signal_connect_swapped(G_OBJECT(event_box
),
578 "button-release-event",
579 G_CALLBACK(gtk_widget_destroy
),
582 gtk_widget_show_all(GTK_WIDGET(preview_dialog
));
584 IRRECO_RETURN_BOOL(TRUE
);
593 irreco_theme_manager_dlg_selected_version_dlg(GtkComboBox
*widget
,
594 IrrecoThemeManagerDlg
*self
)
601 if(!gtk_combo_box_get_active_iter(widget
, &iter
)) {
604 gtk_tree_model_get(GTK_TREE_MODEL(self
->version_store
), &iter
,
607 if (self
->webdb_theme
== NULL
|| self
->webdb_theme
->id
!= atoi(id
)) {
608 IRRECO_DEBUG("SELECTED ID: %d\n", atoi(id
));
609 self
->selected_theme_id
= atoi(id
);
610 self
->loader_func_id
= g_idle_add(G_SOURCEFUNC(
611 irreco_theme_manager_dlg_theme_db_detail_loader
),
622 static void irreco_theme_manager_dlg_delete_theme(GtkButton
*button
,
623 IrrecoThemeManagerDlg
*self
)
626 const gchar
*name
= gtk_label_get_label(GTK_LABEL(self
->theme_name
));
627 GString
*message
= g_string_new(NULL
);
630 g_string_append_printf(
631 message
, _("Are you sure you want to\n "
632 "delete %s theme?"),name
);
634 if (irreco_yes_no_dlg(GTK_WINDOW(self
), message
->str
)){
636 irreco_theme_manager_remove_theme(
637 self
->irreco_data
->theme_manager
, name
);
638 gtk_button_clicked(GTK_BUTTON(self
->refresh_button
));
641 g_string_free(message
, TRUE
);
646 * Download theme from DB
649 static void irreco_theme_manager_dlg_download_theme(GtkButton
*button
,
650 IrrecoThemeManagerDlg
*self
)
652 GtkWidget
*radio1
, *radio2
, *radio3
;
655 IrrecoWebdbCache
*webdb_cache
= NULL
;
656 gboolean theme_is_loaded
= FALSE
;
657 gint delete_mode
= 0;
658 IrrecoTheme
*same_theme
= NULL
;
659 gchar
*same_theme_folder
= NULL
;
660 IrrecoThemeManager
*theme_manager
= self
->irreco_data
->theme_manager
;
661 GString
*message
= g_string_new(NULL
);
662 GString
*path
= g_string_new(NULL
);
666 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
, FALSE
);
667 self
->download_dialog
= irreco_dlg_new();
669 gtk_window_set_title(GTK_WINDOW(self
->download_dialog
),
670 _("Download theme"));
671 gtk_window_set_modal(GTK_WINDOW(self
->download_dialog
), TRUE
);
672 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
->download_dialog
),
674 gtk_dialog_set_has_separator(GTK_DIALOG(self
->download_dialog
), FALSE
);
675 gtk_dialog_add_buttons(GTK_DIALOG(self
->download_dialog
),
676 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
677 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
680 label
= gtk_label_new("Select download location");
682 radio1
= gtk_radio_button_new_with_label (NULL
, "MMC1");
683 radio2
= gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(
685 radio3
= gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(
688 gtk_box_pack_start_defaults(GTK_BOX(
689 GTK_DIALOG(self
->download_dialog
)->vbox
),
692 if(irreco_is_dir("/media/mmc1")) {
693 gtk_box_pack_start_defaults(GTK_BOX(
694 GTK_DIALOG(self
->download_dialog
)->vbox
),
698 if(irreco_is_dir("/media/mmc2")) {
699 gtk_box_pack_start_defaults(GTK_BOX(
700 GTK_DIALOG(self
->download_dialog
)->vbox
),
704 gtk_box_pack_start_defaults(GTK_BOX(
705 GTK_DIALOG(self
->download_dialog
)->vbox
),
710 gtk_widget_show_all(GTK_WIDGET(self
->download_dialog
));
715 GTK_DIALOG(self
->download_dialog
)) == GTK_RESPONSE_CANCEL
){
719 if (self
->loader_func_id
!= 0) {
723 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio1
))) {
724 self
->theme_folder
= "/media/mmc1/irreco/";
725 } else if (gtk_toggle_button_get_active(
726 GTK_TOGGLE_BUTTON(radio2
))) {
727 self
->theme_folder
= "/media/mmc2/irreco/";
729 self
->theme_folder
= IRRECO_THEME_DIR
;
732 if(!irreco_is_dir(self
->theme_folder
)) {
733 g_mkdir(self
->theme_folder
, 0777);
737 g_string_printf(path
, "%s%s/", self
->theme_folder
,
738 self
->webdb_theme
->folder
->str
);
740 IRRECO_STRING_TABLE_FOREACH_DATA(theme_manager
->themes
,
741 IrrecoTheme
*, theme
)
743 if (g_str_equal(self
->webdb_theme
->name
->str
,
745 if (g_str_equal(theme
->source
->str
, "deb")) {
746 g_string_printf(message
,
747 _("The \"%s\" theme already exists.\n"
748 "Can't overwrite \"Built In themes\"\n"
749 "Please remove it first from the\n"
750 "Application Manager"),
753 irreco_error_dlg(GTK_WINDOW(
754 self
->download_dialog
),
761 /*Check theme folder path*/
762 else if (g_str_equal(path
->str
,
763 g_strconcat(theme
->path
->str
, "/", NULL
))){
764 if (g_str_equal(theme
->source
->str
, "deb")) {
765 g_string_printf(message
,
766 _("This theme replaces \"%s\" theme.\n"
767 "Can't overwrite \"Built In themes\"\n"
768 "Please remove it first from the\n"
769 "Application Manager"),
772 irreco_error_dlg(GTK_WINDOW(
773 self
->download_dialog
),
778 same_theme_folder
= g_strdup(theme
->name
->str
);
780 IRRECO_STRING_TABLE_FOREACH_END
782 if (delete_mode
== 1) {
783 g_string_printf(message
,
784 _("The \"%s\" theme already exists.\n"
785 "Do you want to replace this theme?"),
786 same_theme
->name
->str
);
787 } else if (delete_mode
== 2) {
788 g_string_printf(message
,
789 _("This theme replaces \"%s\" theme.\n"
790 "Do you want to continue?"),
792 } else if (delete_mode
== 3) {
793 g_string_printf(message
,
794 _("This theme replaces themes\n"
795 "\"%s\" and \"%s\"\n"
796 "Do you want to continue?"),
797 same_theme
->name
->str
,
801 /* Check whether a theme folder already exists */
802 if (delete_mode
!= 0) {
804 if (!irreco_yes_no_dlg(
805 GTK_WINDOW(self
->download_dialog
), message
->str
)) {
808 /* Remove theme folder and then make it again*/
809 if (delete_mode
== 1 || delete_mode
== 3) {
810 gchar
*rm_cmd
= g_strconcat("rm -r ",
811 same_theme
->path
->str
, NULL
);
815 if (delete_mode
== 2 || delete_mode
== 3) {
816 irreco_theme_manager_remove_theme(
817 self
->irreco_data
->theme_manager
,
819 g_free(same_theme_folder
);
825 g_mkdir(path
->str
, 0777);
828 if (delete_mode
== 0 || delete_mode
== 2) {
829 theme
= irreco_theme_new(self
->webdb_theme
->name
->str
,
831 self
->webdb_theme
->creator
->str
,
832 self
->webdb_theme
->comment
->str
,
833 self
->webdb_theme
->preview_button_name
->str
,
834 self
->webdb_theme
->uploaded
->str
);
836 irreco_theme_update_keyfile(theme
);
837 irreco_theme_free(theme
);
839 irreco_theme_set(same_theme
,
840 self
->webdb_theme
->name
->str
,
842 self
->webdb_theme
->creator
->str
,
843 self
->webdb_theme
->comment
->str
,
844 self
->webdb_theme
->preview_button_name
->str
,
845 self
->webdb_theme
->uploaded
->str
);
848 /* Get buttons and backgrounds */
849 self
->loader_func_id
= g_idle_add(G_SOURCEFUNC(
850 irreco_theme_manager_dlg_button_loader
), self
);
851 theme_is_loaded
= TRUE
;
855 g_string_free(message
, TRUE
);
856 g_string_free(path
, TRUE
);
857 irreco_theme_manager_dlg_hide_banner(self
);
858 irreco_theme_manager_dlg_loader_stop(self
);
859 if(self
->download_dialog
!= NULL
) {
860 gtk_widget_destroy(GTK_WIDGET(self
->download_dialog
));
861 self
->download_dialog
= NULL
;
862 if(theme_is_loaded
== TRUE
) {
863 gtk_button_clicked(GTK_BUTTON(self
->refresh_button
));
874 static void irreco_theme_manager_dlg_upload_theme(GtkButton
*button
,
875 IrrecoThemeManagerDlg
*self
)
879 if (irreco_theme_upload_dlg_run(GTK_WINDOW(self
),
880 self
->irreco_data
, self
->theme
) == TRUE
) {
881 gtk_button_clicked(GTK_BUTTON(self
->refresh_button
));
886 static void irreco_theme_manager_dlg_new_theme(GtkButton
*button
,
887 IrrecoThemeManagerDlg
*self
){
890 irreco_theme_creator_dlg_run(GTK_WINDOW(self
),
891 self
->irreco_data
, self
->theme
);
899 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
900 /* Private Functions */
901 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
904 * @name Private Functions
909 static void _smaller_text(gpointer cell, gpointer user_data)
911 g_object_set(cell, "scale", (gdouble)0.75,
912 "scale-set", TRUE, NULL);
913 IRRECO_PRINTF("_smaller_text\n");
917 static void scale_combobox(IrrecoThemeManagerDlg *self)
921 cells = gtk_tree_view_column_get_cell_renderers(GTK_TREE_VIEW_COLUMN(self->combobox));
922 cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(self->version_store));
923 g_list_foreach(cells, _smaller_text, NULL);
932 static void irreco_theme_manager_dlg_clean_details(IrrecoThemeManagerDlg
*self
)
937 gtk_widget_show_all(GTK_WIDGET(self
));
939 GTK_LABEL(self
->theme_name
), "-");
941 GTK_LABEL(self
->theme_creator
), "-");
943 GTK_LABEL(self
->theme_comment
), "-");
945 GTK_LABEL(self
->theme_downloaded
), "-");
946 gtk_image_clear(GTK_IMAGE(self
->theme_image
));
947 self
->preview_add
=NULL
;
949 gtk_widget_hide(self
->upload_button
);
950 gtk_widget_hide(self
->download_button
);
951 gtk_widget_hide(self
->clear_button
);
952 gtk_widget_hide(self
->theme_info_alignment
);
953 gtk_widget_show(self
->select_label
);
960 * Have the childern of this item been loaded.
962 * @return TRUE if children have been loade, FALSE otherwise.
966 irreco_theme_manager_dlg_row_is_loaded(IrrecoThemeManagerDlg
*self
,
973 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
974 iter
, FLAG_COL
, &i
, -1);
975 if (i
& ROW_CHILDREN_LOADED
) IRRECO_RETURN_BOOL(TRUE
);
977 IRRECO_RETURN_BOOL(FALSE
);
984 static gint
irreco_theme_manager_dlg_row_get_type(IrrecoThemeManagerDlg
*self
,
991 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
992 iter
, FLAG_COL
, &i
, -1);
993 if (i
& ROW_TYPE_CATEGORY
)
994 IRRECO_RETURN_ENUM(ROW_TYPE_CATEGORY
);
995 if (i
& ROW_TYPE_DEB
)
996 IRRECO_RETURN_ENUM(ROW_TYPE_DEB
);
997 if (i
& ROW_TYPE_USER
)
998 IRRECO_RETURN_ENUM(ROW_TYPE_USER
);
999 if (i
& ROW_TYPE_WEB
)
1000 IRRECO_RETURN_ENUM(ROW_TYPE_WEB
);
1001 if (i
& ROW_TYPE_DB
)
1002 IRRECO_RETURN_ENUM(ROW_TYPE_DB
);
1003 if (i
& ROW_TYPE_LOADING
)
1004 IRRECO_RETURN_ENUM(ROW_TYPE_LOADING
);
1005 IRRECO_RETURN_INT(0);
1009 * Show hildon progressbar banner.
1011 * This function will create a new banner if one has not been created yet,
1012 * if banner already exists, it's properties will be changed.
1014 * @param text Text to show.
1015 * @param fraction Value of progress.
1018 static void irreco_theme_manager_dlg_set_banner(IrrecoThemeManagerDlg
*self
,
1024 if (self
->banner
== NULL
) {
1025 self
->banner
= hildon_banner_show_progress(
1026 GTK_WIDGET(self
), NULL
, "");
1029 hildon_banner_set_text(HILDON_BANNER(self
->banner
), text
);
1030 hildon_banner_set_fraction(HILDON_BANNER(self
->banner
), fraction
);
1036 * Destroy banner, if it exists.
1039 static void irreco_theme_manager_dlg_hide_banner(IrrecoThemeManagerDlg
*self
)
1044 gtk_widget_destroy(self
->banner
);
1045 self
->banner
= NULL
;
1052 * Start a loader state machine if one is not running already.
1056 gboolean
irreco_theme_manager_dlg_loader_start(IrrecoThemeManagerDlg
*self
,
1057 GSourceFunc function
,
1058 GtkTreeIter
*parent_iter
)
1062 if (self
->loader_func_id
== 0) {
1064 self
->loader_parent_iter
= gtk_tree_iter_copy(
1068 self
->loader_func_id
= g_idle_add(function
, self
);
1070 IRRECO_ERROR("Loader function pointer not given.\n");
1073 IRRECO_RETURN_BOOL(TRUE
);
1078 * Stop and cleanup loader if a loader is running.
1081 static void irreco_theme_manager_dlg_loader_stop(IrrecoThemeManagerDlg
*self
)
1085 if (self
->loader_func_id
!= 0) {
1086 g_source_remove(self
->loader_func_id
);
1087 self
->loader_func_id
= 0;
1088 self
->loader_state
= 0;
1089 if (self
->loader_parent_iter
) {
1090 gtk_tree_iter_free(self
->loader_parent_iter
);
1092 self
->loader_parent_iter
= NULL
;
1098 irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg
*self
)
1102 switch (self
->loader_state
) {
1103 case LOADER_STATE_INIT
: {
1105 irreco_theme_manager_dlg_set_banner(self
, _("Loading ..."),
1107 self
->loader_state
= LOADER_STATE_LOOP
;
1108 irreco_theme_manager_dlg_clean_details(self
);
1109 if (!irreco_theme_manager_does_user_exist(
1110 self
->irreco_data
->theme_manager
)) {
1111 self
->loader_state
= LOADER_STATE_END
;
1112 self
->loader_iter
= NULL
;
1116 gtk_tree_store_append(self
->tree_store
,
1118 gtk_tree_store_set(self
->tree_store
,
1120 TEXT_COL
, _("My Themes"),
1121 FLAG_COL
, ROW_TYPE_CATEGORY
,
1122 DATA_COL
, NULL
, -1);
1124 self
->loader_iter
= gtk_tree_iter_copy(&iter
);
1127 IRRECO_RETURN_BOOL(TRUE
);
1131 case LOADER_STATE_LOOP
: {
1133 IrrecoData
*irreco_data
= NULL
;
1134 IrrecoThemeManager
*theme_manager
= NULL
;
1136 IrrecoStringTable
*categories
= NULL
;
1139 irreco_data
= self
->irreco_data
;
1140 theme_manager
= irreco_data
->theme_manager
;
1141 categories
= irreco_theme_manager_get_themes(theme_manager
);
1143 IRRECO_STRING_TABLE_FOREACH_DATA(categories
,
1144 IrrecoTheme
*, theme
)
1146 if (g_utf8_collate(theme
->source
->str
, "user") == 0){
1148 /* Add loading item into category. */
1149 gtk_tree_store_append(self
->tree_store
,
1152 gtk_tree_store_set(self
->tree_store
,
1158 DATA_COL
, NULL
, -1);
1160 IRRECO_STRING_TABLE_FOREACH_END
1162 irreco_theme_manager_dlg_set_banner(self
, _("Loading ..."),
1164 self
->loader_state
= LOADER_STATE_END
;
1165 IRRECO_RETURN_BOOL(TRUE
);
1168 case LOADER_STATE_END
:
1169 if (self
->loader_iter
!= NULL
) {
1170 gtk_tree_iter_free(self
->loader_iter
);
1172 irreco_theme_manager_dlg_hide_banner(self
);
1173 irreco_theme_manager_dlg_loader_stop(self
);
1175 irreco_theme_manager_dlg_loader_start(self
,
1176 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_deb
),NULL
);
1179 IRRECO_RETURN_BOOL(FALSE
);
1185 * This loader will request a list of categories from the theme and
1186 * update the TreeView accordingly. Every category row created by this loader
1187 * will have row type ROW_TYPE_DEB.
1191 static gboolean
irreco_theme_manager_dlg_loader_deb(IrrecoThemeManagerDlg
*self
)
1195 switch (self
->loader_state
) {
1196 case LOADER_STATE_INIT
: {
1198 irreco_theme_manager_dlg_set_banner(self
, _("Loading ..."),
1200 self
->loader_state
= LOADER_STATE_LOOP
;
1201 irreco_theme_manager_dlg_clean_details(self
);
1203 if (!irreco_theme_manager_does_deb_exist(
1204 self
->irreco_data
->theme_manager
)) {
1205 self
->loader_state
= LOADER_STATE_END
;
1206 self
->loader_iter
= NULL
;
1209 gtk_tree_store_append(self
->tree_store
,
1211 gtk_tree_store_set(self
->tree_store
,
1213 TEXT_COL
, _("Built In"),
1214 FLAG_COL
, ROW_TYPE_CATEGORY
,
1215 DATA_COL
, NULL
, -1);
1217 self
->loader_iter
= gtk_tree_iter_copy(&iter
);
1219 IRRECO_RETURN_BOOL(TRUE
);
1223 case LOADER_STATE_LOOP
: {
1225 IrrecoData
*irreco_data
= NULL
;
1226 IrrecoThemeManager
*theme_manager
= NULL
;
1228 IrrecoStringTable
*categories
= NULL
;
1230 irreco_data
= self
->irreco_data
;
1231 theme_manager
= irreco_data
->theme_manager
;
1232 categories
= irreco_theme_manager_get_themes(theme_manager
);
1234 IRRECO_STRING_TABLE_FOREACH_DATA(categories
,
1235 IrrecoTheme
*, theme
)
1236 if (g_utf8_collate(theme
->source
->str
, "deb") == 0){
1238 /* Add loading item into category. */
1239 gtk_tree_store_append(self
->tree_store
,
1240 &iter
, self
->loader_iter
);
1241 gtk_tree_store_set(self
->tree_store
,
1245 FLAG_COL
, ROW_TYPE_DEB
,
1246 DATA_COL
, NULL
, -1);
1248 IRRECO_STRING_TABLE_FOREACH_END
1250 irreco_theme_manager_dlg_set_banner(self
, _("Loading ..."),
1252 self
->loader_state
= LOADER_STATE_END
;
1253 IRRECO_RETURN_BOOL(TRUE
);
1256 case LOADER_STATE_END
: {
1257 GtkTreeIter iter
, iter_loading
;
1258 if (self
->loader_iter
!= NULL
) {
1259 gtk_tree_iter_free(self
->loader_iter
);
1261 irreco_theme_manager_dlg_hide_banner(self
);
1262 irreco_theme_manager_dlg_loader_stop(self
);
1264 /* Create database row */
1265 gtk_tree_store_append(self
->tree_store
, &iter
, NULL
);
1266 gtk_tree_store_set(self
->tree_store
, &iter
,
1267 TEXT_COL
, _("Database"),
1268 FLAG_COL
, ROW_TYPE_CATEGORY
,
1269 DATA_COL
, NULL
, -1);
1271 /* Add loading item into manufacturer. */
1272 gtk_tree_store_append(self
->tree_store
, &iter_loading
, &iter
);
1273 gtk_tree_store_set(self
->tree_store
, &iter_loading
,
1274 TEXT_COL
, _("Loading ..."),
1275 FLAG_COL
, ROW_TYPE_LOADING
,
1276 DATA_COL
, NULL
, -1);
1278 irreco_theme_manager_dlg_loader_start(self
,
1279 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_web
), NULL
);
1283 IRRECO_RETURN_BOOL(FALSE
);
1286 static gboolean
irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg
*self
)
1290 switch (self
->loader_state
) {
1291 case LOADER_STATE_INIT
:{
1293 irreco_theme_manager_dlg_set_banner(self
, _("Loading themes"),
1295 self
->loader_state
= LOADER_STATE_LOOP
;
1296 self
->theme_loader_index
= 0;
1297 irreco_theme_manager_dlg_clean_details(self
);
1299 /* Check if loading item exist */
1300 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self
->tree_store
),
1301 &iter
, self
->loader_iter
, 0);
1303 if(irreco_theme_manager_dlg_row_get_type(self
,
1304 &iter
) != ROW_TYPE_LOADING
) {
1305 self
->loader_state
= LOADER_STATE_END
;
1308 IRRECO_RETURN_BOOL(TRUE
);
1312 case LOADER_STATE_LOOP
: {
1314 GtkTreeIter iter_loading
;
1315 IrrecoStringTable
*themes
= NULL
;
1316 IrrecoWebdbTheme
*theme_by_id
;
1317 IrrecoWebdbCache
*webdb_cache
= NULL
;
1321 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
,
1324 irreco_webdb_cache_get_themes(webdb_cache
, &themes
);
1326 if (irreco_string_table_index(themes
,
1327 (guint
)self
->theme_loader_index
, &id
, NULL
)) {
1329 irreco_webdb_cache_get_theme_by_id(webdb_cache
,
1333 gtk_tree_store_append(self
->tree_store
,
1334 &iter
, self
->loader_iter
);
1335 gtk_tree_store_set(self
->tree_store
,
1338 theme_by_id
->name
->str
,
1339 FLAG_COL
, ROW_TYPE_DB
,
1342 irreco_error_dlg(GTK_WINDOW(self
),
1343 irreco_webdb_cache_get_error(
1347 banner
= ++self
->theme_loader_index
;
1348 banner
/= (gfloat
) irreco_string_table_lenght (themes
);
1350 irreco_theme_manager_dlg_set_banner(self
, _("Loading themes"),
1352 if (banner
>= 1.0) {
1353 self
->loader_state
= LOADER_STATE_END
;
1356 /* Delete loading item */
1357 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self
->tree_store
),
1358 &iter_loading
, self
->loader_iter
,
1360 if(irreco_theme_manager_dlg_row_get_type(self
,
1361 &iter_loading
) == ROW_TYPE_LOADING
) {
1362 gtk_tree_store_remove(self
->tree_store
, &iter_loading
);
1365 IRRECO_RETURN_BOOL(TRUE
);
1368 case LOADER_STATE_END
:
1369 if (self
->loader_iter
!= NULL
) {
1370 gtk_tree_iter_free(self
->loader_iter
);
1372 irreco_theme_manager_dlg_hide_banner(self
);
1373 irreco_theme_manager_dlg_loader_stop(self
);
1376 IRRECO_RETURN_BOOL(FALSE
);
1380 static gboolean
irreco_theme_manager_dlg_loader_web(IrrecoThemeManagerDlg
*self
)
1384 switch (self
->loader_state
) {
1385 case LOADER_STATE_INIT
: {
1387 irreco_theme_manager_dlg_set_banner(self
, _("Loading ..."),
1389 self
->loader_state
= LOADER_STATE_LOOP
;
1390 irreco_theme_manager_dlg_clean_details(self
);
1391 if (!irreco_theme_manager_does_web_exist(
1392 self
->irreco_data
->theme_manager
)) {
1393 self
->loader_state
= LOADER_STATE_END
;
1394 self
->loader_iter
= NULL
;
1397 gtk_tree_store_append(self
->tree_store
,
1399 gtk_tree_store_set(self
->tree_store
,
1401 TEXT_COL
, _("Downloaded"),
1402 FLAG_COL
, ROW_TYPE_CATEGORY
,
1403 DATA_COL
, NULL
, -1);
1405 self
->loader_iter
= gtk_tree_iter_copy(&iter
);
1407 IRRECO_RETURN_BOOL(TRUE
);
1409 case LOADER_STATE_LOOP
: {
1411 IrrecoData
*irreco_data
= NULL
;
1412 IrrecoThemeManager
*theme_manager
= NULL
;
1414 IrrecoStringTable
*categories
= NULL
;
1416 irreco_data
= self
->irreco_data
;
1417 theme_manager
= irreco_data
->theme_manager
;
1418 categories
= irreco_theme_manager_get_themes(theme_manager
);
1420 IRRECO_STRING_TABLE_FOREACH_DATA(categories
,
1421 IrrecoTheme
*, theme
)
1423 if (g_utf8_collate(theme
->source
->str
, "web") == 0){
1425 /* Add loading item into category. */
1426 gtk_tree_store_append(self
->tree_store
,
1429 gtk_tree_store_set(self
->tree_store
,
1435 DATA_COL
, NULL
, -1);
1437 IRRECO_STRING_TABLE_FOREACH_END
1439 irreco_theme_manager_dlg_set_banner(self
, _("Loading ..."),
1441 self
->loader_state
= LOADER_STATE_END
;
1442 IRRECO_RETURN_BOOL(TRUE
);
1445 case LOADER_STATE_END
:
1446 if (self
->loader_iter
!= NULL
) {
1447 gtk_tree_iter_free(self
->loader_iter
);
1449 irreco_theme_manager_dlg_hide_banner(self
);
1450 irreco_theme_manager_dlg_loader_stop(self
);
1453 IRRECO_RETURN_BOOL(FALSE
);
1457 * Show theme details
1463 irreco_theme_manager_dlg_display_theme_detail(IrrecoThemeManagerDlg
*self
,
1466 IrrecoThemeManager
*theme_manager
= self
->irreco_data
->theme_manager
;
1467 IrrecoThemeButton
*button
;
1468 const gchar
*theme_name
;
1472 gtk_image_clear(GTK_IMAGE(self
->theme_image
));
1474 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
1475 iter
, TEXT_COL
, &theme_name
, -1);
1476 irreco_string_table_get(theme_manager
->themes
, theme_name
,
1477 (gpointer
*) &self
->theme
);
1479 gtk_label_set_text(GTK_LABEL(self
->theme_name
),
1480 self
->theme
->name
->str
);
1481 gtk_label_set_text(GTK_LABEL(self
->theme_creator
),
1482 self
->theme
->author
->str
);
1483 gtk_label_set_text(GTK_LABEL(self
->theme_comment
),
1484 self
->theme
->comment
->str
);
1485 gtk_label_set_text(GTK_LABEL(self
->theme_version
),
1486 self
->theme
->version
->str
);
1488 if (self
->theme
->preview_button_name
->len
> 0) {
1489 button
=irreco_theme_get_button(self
->theme
,
1490 self
->theme
->preview_button_name
->str
);
1493 irreco_string_table_index(self
->theme
->buttons
,
1494 0, &key
, (gpointer
*) &button
);
1496 IRRECO_DEBUG("Preview-button: %s\n", button
->image_up
->str
);
1498 gtk_image_set_from_file(GTK_IMAGE(self
->theme_image
),
1499 button
->image_up
->str
);
1501 self
->preview_add
= button
->image_up
->str
;
1503 IRRECO_RETURN_BOOL(TRUE
);
1507 irreco_theme_manager_dlg_theme_db_detail_loader(IrrecoThemeManagerDlg
*self
)
1511 switch (self
->loader_state
) {
1512 case LOADER_STATE_INIT
:{
1513 irreco_theme_manager_dlg_set_banner(self
,
1514 _("Loading ..."), 0.5);
1515 self
->loader_state
= LOADER_STATE_LOOP
;
1516 IRRECO_RETURN_BOOL(TRUE
);
1519 case LOADER_STATE_LOOP
: {
1520 gchar
*download_count
;
1522 IrrecoWebdbCache
*webdb_cache
= irreco_data_get_webdb_cache(
1526 gtk_image_clear(GTK_IMAGE(self
->theme_image
));
1529 /* gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1530 iter, DATA_COL, &theme_id, -1);*/
1532 /* Get WebdbTheme with preview-button */
1533 irreco_webdb_cache_get_preview_button(webdb_cache
,
1534 self
->selected_theme_id
,
1535 &self
->webdb_theme
);
1537 gtk_label_set_text(GTK_LABEL(self
->theme_name
),
1538 self
->webdb_theme
->name
->str
);
1539 gtk_label_set_text(GTK_LABEL(self
->theme_creator
),
1540 self
->webdb_theme
->creator
->str
);
1541 gtk_label_set_text(GTK_LABEL(self
->theme_comment
),
1542 self
->webdb_theme
->comment
->str
);
1544 /* Clear combobox */
1545 gtk_tree_store_clear(self
->version_store
);
1547 IRRECO_STRING_TABLE_FOREACH(self
->webdb_theme
->versions
,
1552 gtk_tree_store_append(self
->version_store
,
1556 gtk_tree_store_set(self
->version_store
, &iter
,
1560 if (g_utf8_collate (date
,
1561 self
->webdb_theme
->uploaded
->str
) == 0) {
1562 gtk_combo_box_set_active(GTK_COMBO_BOX(
1567 IRRECO_STRING_TABLE_FOREACH_END
1569 /*scale_combobox(self);*/
1571 download_count
= g_strdup_printf("%d",
1572 self
->webdb_theme
->download_count
);
1574 gtk_label_set_text(GTK_LABEL(self
->theme_downloaded
),
1576 g_free(download_count
);
1578 if (self
->webdb_theme
->preview_button
!= NULL
) {
1579 gtk_image_set_from_pixbuf(GTK_IMAGE(self
->theme_image
),
1580 self
->webdb_theme
->preview_button
);
1581 self
->preview_add
= NULL
;
1583 IRRECO_DEBUG("preview_button is NULL\n");
1585 self
->preview_add
= NULL
;
1587 self
->loader_state
= LOADER_STATE_END
;
1588 IRRECO_RETURN_BOOL(TRUE
);
1591 case LOADER_STATE_END
:
1592 irreco_theme_manager_dlg_hide_banner(self
);
1593 irreco_theme_manager_dlg_loader_stop(self
);
1595 IRRECO_RETURN_BOOL(FALSE
);
1598 static gboolean
irreco_theme_manager_dlg_bg_loader(IrrecoThemeManagerDlg
*self
)
1602 switch (self
->loader_state
) {
1603 case LOADER_STATE_INIT
:{
1604 GString
*path
= g_string_new("");
1605 irreco_theme_manager_dlg_set_banner(self
,
1606 _("Loading backgrounds..."),
1608 self
->loader_state
= LOADER_STATE_LOOP
;
1609 self
->theme_loader_index
= 0;
1611 g_string_printf(path
, "%s%s/bg/", self
->theme_folder
,
1612 self
->webdb_theme
->folder
->str
);
1614 IRRECO_DEBUG("mkdir %s\n", path
->str
);
1615 g_mkdir(path
->str
, 0777);
1616 g_string_free(path
, TRUE
);
1618 IRRECO_RETURN_BOOL(TRUE
);
1621 case LOADER_STATE_LOOP
: {
1622 IrrecoStringTable
*bg_list
= NULL
;
1623 GString
*path
= g_string_new("");
1626 IrrecoWebdbCache
*webdb_cache
= irreco_data_get_webdb_cache(
1629 /* Get backrounds */
1630 irreco_webdb_cache_get_backgrounds(webdb_cache
,
1631 self
->webdb_theme
->id
,
1634 g_string_printf(path
, "%s%s/bg/", self
->theme_folder
,
1635 self
->webdb_theme
->folder
->str
);
1637 if (irreco_string_table_index(bg_list
,
1638 (guint
)self
->theme_loader_index
, &id
, NULL
)) {
1639 irreco_webdb_cache_get_bg_by_id(webdb_cache
, atoi(id
),
1643 banner
= ++self
->theme_loader_index
;
1644 banner
/= (gfloat
) irreco_string_table_lenght (bg_list
);
1646 irreco_theme_manager_dlg_set_banner(self
,
1647 _("Loading backgrounds..."),
1649 if (banner
>= 1.0) {
1650 self
->loader_state
= LOADER_STATE_END
;
1652 g_string_free(path
, TRUE
);
1653 IRRECO_RETURN_BOOL(TRUE
);
1655 case LOADER_STATE_END
:
1656 irreco_theme_manager_dlg_hide_banner(self
);
1657 irreco_theme_manager_dlg_loader_stop(self
);
1658 gtk_dialog_response(GTK_DIALOG(self
->download_dialog
),
1659 GTK_RESPONSE_CANCEL
);
1661 IRRECO_RETURN_BOOL(FALSE
);
1665 irreco_theme_manager_dlg_button_loader(IrrecoThemeManagerDlg
*self
)
1669 switch (self
->loader_state
) {
1670 case LOADER_STATE_INIT
:{
1671 GString
*path
= g_string_new("");
1672 irreco_theme_manager_dlg_set_banner(self
,
1673 _("Loading buttons.."),
1675 self
->loader_state
= LOADER_STATE_LOOP
;
1676 self
->theme_loader_index
= 0;
1678 g_string_printf(path
, "%s%s/buttons/", self
->theme_folder
,
1679 self
->webdb_theme
->folder
->str
);
1681 IRRECO_DEBUG("mkdir %s\n", path
->str
);
1682 g_mkdir(path
->str
, 0777);
1683 g_string_free(path
, TRUE
);
1685 IRRECO_RETURN_BOOL(TRUE
);
1688 case LOADER_STATE_LOOP
: {
1689 IrrecoStringTable
*button_list
= NULL
;
1690 GString
*path
= g_string_new("");
1693 IrrecoWebdbCache
*webdb_cache
= irreco_data_get_webdb_cache(
1697 irreco_webdb_cache_get_buttons(webdb_cache
,
1698 self
->webdb_theme
->id
,
1701 g_string_printf(path
, "%s%s/buttons/", self
->theme_folder
,
1702 self
->webdb_theme
->folder
->str
);
1704 if (irreco_string_table_index(button_list
,
1705 (guint
)self
->theme_loader_index
, &id
, NULL
)) {
1706 irreco_webdb_cache_get_button_by_id(webdb_cache
,
1711 banner
= ++self
->theme_loader_index
;
1712 banner
/= (gfloat
) irreco_string_table_lenght (button_list
);
1714 irreco_theme_manager_dlg_set_banner(self
,
1715 _("Loading buttons.."),
1717 if (banner
>= 1.0) {
1718 self
->loader_state
= LOADER_STATE_END
;
1720 g_string_free(path
, TRUE
);
1721 IRRECO_RETURN_BOOL(TRUE
);
1723 case LOADER_STATE_END
:
1724 irreco_theme_manager_dlg_hide_banner(self
);
1725 irreco_theme_manager_dlg_loader_stop(self
);
1727 /* Get backgrounds */
1728 self
->loader_func_id
= g_idle_add(G_SOURCEFUNC(
1729 irreco_theme_manager_dlg_bg_loader
), self
);
1731 IRRECO_RETURN_BOOL(FALSE
);
1738 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1740 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1743 * @name Public Functions
1747 void irreco_theme_manager_dlg_set_irreco_data(IrrecoThemeManagerDlg
*self
,
1748 IrrecoData
*irreco_data
)
1752 self
->irreco_data
= irreco_data
;
1757 void irreco_show_theme_manager_dlg(IrrecoData
*irreco_data
, GtkWindow
*parent
)
1759 IrrecoThemeManagerDlg
*self
;
1761 gboolean loop
= TRUE
;
1762 IrrecoWebdbCache
*webdb_cache
= NULL
;
1766 self
= IRRECO_THEME_MANAGER_DLG(irreco_theme_manager_dlg_new(
1767 irreco_data
, parent
));
1769 webdb_cache
= irreco_data_get_webdb_cache(self
->irreco_data
, FALSE
);
1772 response
= gtk_dialog_run(GTK_DIALOG(self
));
1774 case IRRECO_DEVICE_REFRESH
:
1775 if (self
->loader_func_id
!= 0) {
1778 IRRECO_DEBUG("IRRECO_DEVICE_REFRESH\n");
1779 gtk_tree_store_clear(self
->tree_store
);
1780 irreco_theme_manager_update_theme_manager
1781 (self
->irreco_data
->theme_manager
);
1783 if (webdb_cache
->theme_id_hash
!= NULL
) {
1784 g_hash_table_remove_all(
1785 webdb_cache
->theme_id_hash
);
1786 self
->webdb_theme
= NULL
;
1789 IRRECO_STRING_TABLE_FOREACH_DATA(
1790 irreco_data
->theme_manager
->themes
,
1791 IrrecoTheme
*, theme
)
1792 irreco_theme_check(theme
);
1793 IRRECO_STRING_TABLE_FOREACH_END
1795 irreco_theme_manager_dlg_loader_start(self
,
1797 irreco_theme_manager_dlg_loader_user
),
1799 gtk_label_set_text(GTK_LABEL(self
->select_label
),
1800 " Select \ncategory");
1803 case GTK_RESPONSE_CANCEL
:
1804 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
1810 gtk_widget_destroy(GTK_WIDGET(self
));
1819 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1820 /* Events and Callbacks */
1821 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1824 * @name Events and Callbacks
1829 irreco_show_theme_manager_dlg_map_event(IrrecoThemeManagerDlg
*self
,
1836 irreco_theme_manager_dlg_loader_start(
1837 self
, G_SOURCEFUNC(irreco_theme_manager_dlg_loader_user
),
1840 IRRECO_RETURN_BOOL(FALSE
);
1844 irreco_show_theme_manager_dlg_destroy_event(IrrecoThemeManagerDlg
*self
,
1848 irreco_theme_manager_dlg_loader_stop(self
);
1853 irreco_show_theme_manager_dlg_row_activated_event(GtkTreeView
*tree_view
,
1855 GtkTreeViewColumn
*column
,
1856 IrrecoThemeManagerDlg
*self
)
1860 if (gtk_tree_view_row_expanded(tree_view
, path
)) {
1861 gtk_tree_view_expand_row(tree_view
, path
, FALSE
);
1863 gtk_tree_view_collapse_row(tree_view
, path
);
1869 irreco_show_theme_manager_dlg_row_expanded_event(GtkTreeView
*tree_view
,
1872 IrrecoThemeManagerDlg
*self
)
1874 gchar
*row_name
= NULL
;
1877 irreco_theme_manager_dlg_clean_details(self
);
1878 gtk_label_set_text(GTK_LABEL(self
->select_label
), "Select \ntheme");
1880 if (self
->loader_func_id
!= 0) {
1881 gtk_tree_view_collapse_row(tree_view
, path
);
1884 if (!irreco_theme_manager_dlg_row_is_loaded(self
, iter
)){
1885 switch (irreco_theme_manager_dlg_row_get_type(self
, iter
)){
1886 case ROW_TYPE_CATEGORY
:
1887 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
1888 iter
, TEXT_COL
, &row_name
, -1);
1890 if(g_utf8_collate(row_name
, "Database") != 0) {
1894 self
->loader_iter
= gtk_tree_iter_copy(iter
);
1895 irreco_theme_manager_dlg_loader_start(self
,
1896 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_db
), NULL
);
1901 if (row_name
!= NULL
) g_free(row_name
);
1906 irreco_show_theme_manager_dlg_row_collapsed_event(GtkTreeView
*tree_view
,
1909 IrrecoThemeManagerDlg
*self
)
1914 gtk_label_set_text(GTK_LABEL(self
->select_label
), " Select\ncategory");
1916 irreco_theme_manager_dlg_clean_details(self
);
1922 irreco_show_theme_manager_dlg_row_selected_event(GtkTreeSelection
*sel
,
1923 IrrecoThemeManagerDlg
*self
)
1926 GtkTreeModel
*model
;
1931 if (gtk_tree_selection_get_selected (sel
, &model
, &iter
))
1933 switch (irreco_theme_manager_dlg_row_get_type(self
, &iter
)) {
1936 IRRECO_DEBUG("ROW_TYPE_DEB\n");
1938 gtk_widget_hide(self
->select_label
);
1939 gtk_widget_show(self
->theme_info_alignment
);
1940 gtk_widget_hide(self
->label_download
);
1941 gtk_widget_hide(self
->theme_downloaded
);
1942 gtk_widget_hide(self
->label_combobox
);
1943 gtk_widget_hide(self
->combobox
);
1944 gtk_widget_hide(self
->theme_version
);
1945 gtk_widget_hide(self
->theme_creator
);
1946 gtk_widget_hide(self
->label_creator
);
1948 gtk_widget_hide(self
->upload_button
);
1949 gtk_widget_hide(self
->download_button
);
1950 gtk_widget_hide(self
->clear_button
);
1951 gtk_widget_hide(self
->new_button
);
1954 irreco_theme_manager_dlg_display_theme_detail(self
,
1959 IRRECO_DEBUG("ROW_TYPE_USER\n");
1961 gtk_widget_hide(self
->select_label
);
1962 gtk_widget_show(self
->theme_info_alignment
);
1963 gtk_widget_hide(self
->label_download
);
1964 gtk_widget_hide(self
->theme_downloaded
);
1965 gtk_widget_show(self
->theme_creator
);
1966 gtk_widget_show(self
->label_creator
);
1968 gtk_widget_show(self
->label_combobox
);
1969 gtk_widget_hide(self
->combobox
);
1970 gtk_widget_show(self
->theme_version
);
1972 gtk_widget_show(self
->upload_button
);
1973 gtk_widget_show(self
->clear_button
);
1974 gtk_widget_hide(self
->download_button
);
1975 gtk_widget_show(self
->new_button
);
1977 irreco_theme_manager_dlg_display_theme_detail(self
,
1982 IRRECO_DEBUG("ROW_TYPE_WEB\n");
1984 gtk_widget_show(self
->clear_button
);
1985 gtk_widget_hide(self
->upload_button
);
1986 gtk_widget_hide(self
->download_button
);
1987 gtk_widget_hide(self
->new_button
);
1990 gtk_widget_hide(self
->select_label
);
1991 gtk_widget_show(self
->theme_creator
);
1992 gtk_widget_show(self
->label_creator
);
1993 gtk_widget_hide(self
->label_download
);
1994 gtk_widget_hide(self
->theme_downloaded
);
1996 gtk_widget_hide(self
->combobox
);
1997 gtk_widget_show(self
->label_combobox
);
1998 gtk_widget_show(self
->theme_version
);
2000 gtk_widget_show(self
->theme_info_alignment
);
2002 irreco_theme_manager_dlg_display_theme_detail(self
,
2007 IRRECO_DEBUG("ROW_TYPE_DB\n");
2009 gtk_tree_model_get(GTK_TREE_MODEL(self
->tree_store
),
2010 &iter
, DATA_COL
, &id
, -1);
2012 gtk_widget_hide(self
->clear_button
);
2013 gtk_widget_hide(self
->upload_button
);
2014 gtk_widget_show(self
->download_button
);
2015 gtk_widget_hide(self
->new_button
);
2018 gtk_widget_show(self
->combobox
);
2019 gtk_widget_show(self
->label_combobox
);
2020 gtk_widget_hide(self
->theme_version
);
2022 gtk_widget_hide(self
->select_label
);
2023 gtk_widget_show(self
->theme_creator
);
2024 gtk_widget_show(self
->label_creator
);
2025 gtk_widget_show(self
->label_download
);
2026 gtk_widget_show(self
->theme_downloaded
);
2028 gtk_widget_show(self
->theme_info_alignment
);
2030 IRRECO_DEBUG("SELECTED ID: %d\n", atoi(id
));
2032 self
->selected_theme_id
= atoi(id
);
2033 self
->loader_func_id
= g_idle_add(G_SOURCEFUNC(
2034 irreco_theme_manager_dlg_theme_db_detail_loader
),
2039 irreco_theme_manager_dlg_clean_details(self
);