Added irreco_theme_manager_dlg_set_layout_button() functio.
[irreco.git] / irreco / src / core / irreco_theme_manager_dlg.c
blob01fb1d920de10bb9813195185b734a9705867a03
1 /*
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"
27 /**
28 * @addtogroup IrrecoThemeManagerDlg
29 * @ingroup Irreco
31 * @todo PURPOCE OF CLASS.
33 * @{
36 /**
37 * @file
38 * Source file of @ref IrrecoThemeManagerDlg.
42 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 /* Datatypes */
44 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
45 #define IRRECO_BACKGROUND_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 6)
46 #define IRRECO_BACKGROUND_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 6)
49 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
50 /* Prototypes */
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);
58 static gboolean
59 irreco_theme_manager_dlg_loader_deb(IrrecoThemeManagerDlg *self);
60 static gboolean
61 irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg *self);
62 static gboolean
63 irreco_theme_manager_dlg_loader_web(IrrecoThemeManagerDlg *self);
64 static gboolean
65 irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg *self);
66 static gboolean
67 irreco_theme_manager_dlg_theme_db_detail_loader(IrrecoThemeManagerDlg *self);
68 static gboolean
69 irreco_theme_manager_dlg_bg_loader(IrrecoThemeManagerDlg *self);
70 static gboolean
71 irreco_theme_manager_dlg_button_loader(IrrecoThemeManagerDlg *self);
74 static gboolean
75 irreco_theme_manager_dlg_display_theme_detail(IrrecoThemeManagerDlg *self,
76 GtkTreeIter * iter);
78 static gboolean irreco_show_theme_manager_dlg_map_event(IrrecoThemeManagerDlg
79 *self, GdkEvent *event,
80 gpointer user_data);
81 static void irreco_show_theme_manager_dlg_destroy_event(IrrecoThemeManagerDlg
82 *self,
83 gpointer user_data);
85 static void
86 irreco_show_theme_manager_dlg_row_activated_event(GtkTreeView *tree_view,
87 GtkTreePath *path,
88 GtkTreeViewColumn *column,
89 IrrecoThemeManagerDlg*self);
91 static void
92 irreco_show_theme_manager_dlg_row_expanded_event(GtkTreeView *tree_view,
93 GtkTreeIter *iter,
94 GtkTreePath *path,
95 IrrecoThemeManagerDlg *self);
96 static void
97 irreco_show_theme_manager_dlg_row_collapsed_event(GtkTreeView *tree_view,
98 GtkTreeIter *iter,
99 GtkTreePath *path,
100 IrrecoThemeManagerDlg *self);
103 static void
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);
117 static void
118 irreco_theme_manager_dlg_download_theme(GtkButton *button,
119 IrrecoThemeManagerDlg *self);
121 static void
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 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
131 /* Datatypes */
132 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
134 /** Button responce codes. */
135 enum {
136 IRRECO_DEVICE_REFRESH
139 /** GtkTreeStore colums. */
140 enum
142 TEXT_COL,
143 FLAG_COL,
144 DATA_COL,
145 N_COLUMNS
148 /** Version colums. */
149 enum
151 DATE_COL,
152 ID_COL
155 /** Loader states. */
156 enum
158 LOADER_STATE_INIT,
159 LOADER_STATE_LOOP,
160 LOADER_STATE_END,
161 LOADER_STATE_CLEANUP
164 /** Row flags. */
165 enum
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
182 * @{
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(
191 object);
194 static void
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;
220 GtkWidget *table;
221 GtkWidget *info_vbox;
222 GtkWidget *done_button;
223 GtkWidget *theme_table;
224 GtkWidget *preview_event_box;
226 IRRECO_ENTER
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);
238 /*Buttons*/
240 self->refresh_button= gtk_dialog_add_button (GTK_DIALOG(self),
241 _("Refresh"),
242 IRRECO_DEVICE_REFRESH);
244 self->new_button= gtk_dialog_add_button (GTK_DIALOG(self),
245 _("New"), GTK_RESPONSE_NONE);
246 self->edit_button= gtk_dialog_add_button (GTK_DIALOG(self),
247 _("Edit"), GTK_RESPONSE_NONE);
249 self->upload_button= gtk_dialog_add_button (GTK_DIALOG(self),
250 _("Upload"), GTK_RESPONSE_NONE);
253 self->download_button= gtk_dialog_add_button (GTK_DIALOG(self),
254 _("Download"),
255 GTK_RESPONSE_NONE);
256 self->clear_button= gtk_dialog_add_button (GTK_DIALOG(self),
257 _("Delete"),
258 GTK_RESPONSE_NONE);
259 done_button= gtk_dialog_add_button (GTK_DIALOG(self),
260 _("Done"),
261 GTK_RESPONSE_CANCEL);
263 /* Create theme table */
265 table = gtk_table_new(7,7,TRUE);
266 gtk_table_set_col_spacings(GTK_TABLE (table), 8);
267 gtk_table_set_row_spacings(GTK_TABLE (table), 8);
268 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self)->vbox),
269 irreco_gtk_align(GTK_WIDGET(table),
270 0, 0, 1, 1, 8, 8, 8, 8));
271 /* Create tree_view_hbox */
272 tree_view_hbox = gtk_hbox_new(FALSE, 2);
274 /* Create Treeview */
275 self->tree_store = gtk_tree_store_new(
276 N_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_POINTER);
277 self->tree_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(
278 GTK_TREE_MODEL(self->tree_store)));
280 renderer = gtk_cell_renderer_text_new();
281 column = gtk_tree_view_column_new_with_attributes(
282 NULL, renderer, "text", TEXT_COL, NULL);
283 gtk_tree_view_append_column(self->tree_view, column);
285 gtk_box_pack_start(GTK_BOX(tree_view_hbox), GTK_WIDGET(self->tree_view),
286 TRUE, TRUE, 0);
288 /* Create scrollbar for Treeview */
290 scrollbar = gtk_scrolled_window_new(NULL, NULL);
291 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar),
292 GTK_POLICY_AUTOMATIC,
293 GTK_POLICY_AUTOMATIC);
295 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
296 scrollbar), tree_view_hbox);
298 /* Create Frame for Treeview */
299 tree_view_frame = gtk_frame_new("");
300 gtk_frame_set_label_widget(GTK_FRAME(tree_view_frame),
301 irreco_gtk_label_bold("Themes", 0, 0, 0, 0, 0, 0));
303 gtk_container_add(GTK_CONTAINER(tree_view_frame),
304 GTK_WIDGET(scrollbar));
306 /* Create theme_info */
308 theme_info = gtk_table_new(7, 4, TRUE);
309 gtk_table_set_col_spacings(GTK_TABLE(theme_info), 8);
310 gtk_table_set_row_spacings(GTK_TABLE(theme_info), 8);
312 /* Scrolled window for info */
313 info_scrollbar = gtk_scrolled_window_new(NULL, NULL);
314 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
315 info_scrollbar),
316 GTK_POLICY_NEVER,
317 GTK_POLICY_AUTOMATIC);
319 /* Create combobox*/
320 self->version_store = gtk_tree_store_new(
321 2, G_TYPE_STRING, G_TYPE_STRING);
323 self->combobox = gtk_combo_box_new_text();
324 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(self->combobox), 1);
325 gtk_combo_box_set_model(GTK_COMBO_BOX(self->combobox),
326 GTK_TREE_MODEL(self->version_store));
328 theme_table = gtk_table_new(5, 7, TRUE);
329 gtk_table_set_col_spacings(GTK_TABLE(theme_table), 1);
330 gtk_table_set_row_spacings(GTK_TABLE(theme_table), 1);
332 info_vbox = gtk_vbox_new(FALSE, 1);
334 /*create eventbox*/
335 preview_event_box = gtk_event_box_new();
336 self->select_label = gtk_label_new(" Select \ncategory");
338 /* Create frame for theme_info */
339 select_vbox = gtk_vbox_new(FALSE, 2);
340 versions_hbox = gtk_hbox_new(FALSE, 2);
341 theme_info_frame = gtk_frame_new("");
342 gtk_frame_set_label_widget(GTK_FRAME(theme_info_frame),
343 irreco_gtk_label_bold("Info", 0, 0, 0, 0, 0, 0));
344 self->theme_info_alignment = gtk_alignment_new(0, 0, 0, 0);
345 gtk_alignment_set_padding(GTK_ALIGNMENT(self->theme_info_alignment),
346 0, 4, 8, 8);
349 preview_frame = gtk_frame_new(NULL);
350 gtk_frame_set_shadow_type(GTK_FRAME(preview_frame), GTK_SHADOW_OUT);
352 self->theme_image = gtk_image_new();
353 gtk_image_set_from_file(GTK_IMAGE(self->theme_image), NULL);
355 /*Dialog label*/
357 /*label_rate = gtk_label_new(" Rating");*/
358 label_name = gtk_label_new("Name: ");
359 self->label_creator = gtk_label_new("Author: ");
360 self->label_download= gtk_label_new("Downloads: ");
361 label_description = gtk_label_new("Comment: ");
362 self->label_combobox = gtk_label_new("Version:");
364 self->theme_name = gtk_label_new("");
365 self->theme_creator = gtk_label_new("");
366 self->theme_downloaded = gtk_label_new("");
367 self->theme_comment = gtk_label_new("");
368 self->theme_version = gtk_label_new("");
370 comment_alignment = gtk_alignment_new(0, 0, 0, 0);
371 gtk_widget_set_size_request(self->theme_comment,
372 330, -1);
373 gtk_alignment_set_padding(GTK_ALIGNMENT(comment_alignment),
374 0, 0, 20, 0);
375 gtk_label_set_line_wrap(GTK_LABEL(self->theme_comment), TRUE);
376 gtk_label_set_line_wrap_mode(GTK_LABEL(self->theme_comment),
377 PANGO_WRAP_WORD);
379 /*gtk_misc_set_alignment(GTK_MISC(label_rate), 0, 0.5);*/
380 gtk_misc_set_alignment(GTK_MISC(label_name), 0, 0.5);
381 gtk_misc_set_alignment(GTK_MISC(self->label_creator), 0, 0.5);
382 gtk_misc_set_alignment(GTK_MISC(self->label_download), 0, 0.5);
383 gtk_misc_set_alignment(GTK_MISC(label_description), 0, 0.5);
384 gtk_misc_set_alignment(GTK_MISC(self->label_combobox), 0, 0.5);
385 gtk_misc_set_alignment(GTK_MISC(self->theme_name), 0, 0.5);
386 gtk_misc_set_alignment(GTK_MISC(self->theme_creator), 0, 0.5);
387 gtk_misc_set_alignment(GTK_MISC(self->theme_downloaded), 0, 0.5);
388 gtk_misc_set_alignment(GTK_MISC(self->theme_comment), 0, 0.5);
389 gtk_misc_set_alignment(GTK_MISC(self->theme_version), 0, 0.5);
392 /*Attach WidGets to tables*/
394 gtk_table_attach(GTK_TABLE(theme_info), info_scrollbar,
395 0, 4, 4, 7, GTK_FILL, GTK_FILL, 0, 0);
397 gtk_table_attach_defaults(GTK_TABLE(table),
398 tree_view_frame, 0, 3, 0, 7);
399 gtk_table_attach_defaults(GTK_TABLE(theme_info),
400 preview_event_box, 3, 4, 0, 3);
401 /* gtk_table_attach_defaults(GTK_TABLE(self->theme_info),
402 label_rate, 3, 4, 3, 4);*/
403 gtk_table_attach_defaults(GTK_TABLE(theme_info),
404 theme_table, 0, 3, 0, 4);
405 gtk_table_attach_defaults(GTK_TABLE(theme_table),
406 label_name, 0, 3, 0, 1);
407 gtk_table_attach_defaults(GTK_TABLE(theme_table),
408 self->label_creator, 0, 3, 1, 2);
409 gtk_table_attach_defaults(GTK_TABLE(theme_table),
410 self->label_download, 0, 3, 2, 3);
411 gtk_table_attach_defaults(GTK_TABLE(theme_table),
412 label_description, 0, 3, 4, 5);
413 gtk_table_attach_defaults(GTK_TABLE(theme_table),
414 self->label_combobox, 0, 3, 3, 4);
415 gtk_table_attach_defaults(GTK_TABLE(theme_table),
416 versions_hbox, 3, 7, 3, 4);
417 gtk_table_attach_defaults(GTK_TABLE(table),
418 theme_info_frame, 3, 7, 0, 7);
419 gtk_table_attach(GTK_TABLE(theme_table), self->theme_name,
420 3, 7, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
421 gtk_table_attach(GTK_TABLE(theme_table), self->theme_creator,
422 3, 7, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
423 gtk_table_attach(GTK_TABLE(theme_table), self->theme_downloaded,
424 3, 7, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
426 /*Add WidGets*/
428 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
429 info_scrollbar), info_vbox);
430 gtk_container_add(GTK_CONTAINER(preview_frame),
431 self->theme_image);
432 gtk_container_add(GTK_CONTAINER(preview_event_box),
433 preview_frame);
434 gtk_container_add(GTK_CONTAINER(info_vbox), comment_alignment);
435 gtk_container_add(GTK_CONTAINER(comment_alignment),
436 self->theme_comment);
437 gtk_container_add(GTK_CONTAINER(theme_info_frame),
438 GTK_WIDGET(select_vbox));
439 gtk_container_add(GTK_CONTAINER(select_vbox),
440 GTK_WIDGET(self->theme_info_alignment));
441 gtk_container_add(GTK_CONTAINER(select_vbox),
442 GTK_WIDGET(self->select_label));
443 gtk_container_add(GTK_CONTAINER(self->theme_info_alignment),
444 GTK_WIDGET(theme_info));
445 gtk_container_add(GTK_CONTAINER(versions_hbox),
446 GTK_WIDGET(self->theme_version));
447 gtk_container_add(GTK_CONTAINER(versions_hbox),
448 GTK_WIDGET(self->combobox));
450 /*Set font size and style*/
451 /* Font size*/
452 initial_font = pango_font_description_from_string ("Sans Bold 16");
453 gtk_widget_modify_font (self->select_label, initial_font);
455 initial_font = pango_font_description_from_string ("Sans Bold 12");
456 /*gtk_widget_modify_font (label_rate, initial_font);*/
457 gtk_widget_modify_font (label_name, initial_font);
458 gtk_widget_modify_font (self->label_creator, initial_font);
459 gtk_widget_modify_font (self->label_download, initial_font);
460 gtk_widget_modify_font (label_description, initial_font);
461 gtk_widget_modify_font (self->label_combobox, initial_font);
462 /* Font size*/
463 initial_font = pango_font_description_from_string ("Sans 11");
464 gtk_widget_modify_font (self->theme_name, initial_font);
465 gtk_widget_modify_font (self->theme_creator, initial_font);
466 gtk_widget_modify_font (self->theme_downloaded, initial_font);
467 gtk_widget_modify_font (self->theme_comment, initial_font);
468 gtk_widget_modify_font (self->theme_version, initial_font);
469 gtk_widget_modify_font (self->combobox, initial_font);
471 /* Setup the selection handler for TREE */
472 select = gtk_tree_view_get_selection(self->tree_view);
473 gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
475 /* Signal handlers. */
476 g_signal_connect(G_OBJECT(self), "map-event",
477 G_CALLBACK(irreco_show_theme_manager_dlg_map_event), NULL);
478 g_signal_connect(G_OBJECT(self), "destroy",
479 G_CALLBACK(irreco_show_theme_manager_dlg_destroy_event), NULL);
480 g_signal_connect(G_OBJECT(self->tree_view), "row-activated",
481 G_CALLBACK(irreco_show_theme_manager_dlg_row_activated_event),
482 self);
483 g_signal_connect(G_OBJECT(self->tree_view), "row-expanded",
484 G_CALLBACK(irreco_show_theme_manager_dlg_row_expanded_event),
485 self);
486 g_signal_connect(G_OBJECT(self->tree_view), "row-collapsed",
487 G_CALLBACK(irreco_show_theme_manager_dlg_row_collapsed_event),
488 self);
489 g_signal_connect(G_OBJECT (select), "changed",
490 G_CALLBACK (irreco_show_theme_manager_dlg_row_selected_event),
491 self);
492 g_signal_connect(G_OBJECT (self->combobox), "changed",
493 G_CALLBACK (irreco_theme_manager_dlg_selected_version_dlg),
494 self);
495 g_signal_connect(G_OBJECT(preview_event_box),
496 "button-release-event",
497 G_CALLBACK(irreco_theme_manager_dlg_preview_dlg),
498 self);
499 g_signal_connect(G_OBJECT(self->upload_button),
500 "clicked",
501 G_CALLBACK(irreco_theme_manager_dlg_upload_theme),
502 self);
503 g_signal_connect(G_OBJECT(self->clear_button),
504 "clicked",
505 G_CALLBACK(irreco_theme_manager_dlg_delete_theme),
506 self);
507 g_signal_connect(G_OBJECT(self->download_button),
508 "clicked",
509 G_CALLBACK(irreco_theme_manager_dlg_download_theme),
510 self);
511 g_signal_connect(G_OBJECT(self->edit_button),
512 "clicked",
513 G_CALLBACK(irreco_theme_manager_dlg_new_theme),
514 self);
515 g_signal_connect(G_OBJECT(self->new_button),
516 "clicked",
517 G_CALLBACK(irreco_theme_manager_dlg_new_theme),
518 self);
520 gtk_tree_view_set_enable_tree_lines(self->tree_view, TRUE);
521 g_object_set (G_OBJECT (self->tree_view), "show-expanders", TRUE, NULL);
522 g_object_set (G_OBJECT (self->tree_view), "level-indentation", 0, NULL);
523 gtk_tree_view_set_rubber_banding(self->tree_view, FALSE);
525 gtk_widget_set_size_request(GTK_WIDGET(self), 696, 396);
526 gtk_widget_show_all(GTK_WIDGET(self));
528 IRRECO_RETURN
531 GtkWidget *irreco_theme_manager_dlg_new(IrrecoData *irreco_data,
532 GtkWindow *parent)
534 IrrecoThemeManagerDlg *self;
536 IRRECO_ENTER
538 self = g_object_new(IRRECO_TYPE_THEME_MANAGER_DLG, NULL);
539 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
540 irreco_theme_manager_dlg_set_irreco_data(self, irreco_data);
542 IRRECO_RETURN_PTR(self);
546 * Show whole preview image
550 gboolean irreco_theme_manager_dlg_preview_dlg(GtkWidget *widget,
551 GdkEventButton *event,
552 IrrecoThemeManagerDlg *self)
554 GtkWidget *image, *event_box;
555 GtkWidget *preview_dialog;
557 IRRECO_ENTER
559 if(self->preview_add != NULL ||
560 self->webdb_theme->preview_button != NULL) {
562 preview_dialog = irreco_dlg_new ();
563 gtk_window_set_title(GTK_WINDOW(preview_dialog), _("Preview"));
564 gtk_window_set_modal(GTK_WINDOW(preview_dialog), TRUE);
565 gtk_window_set_destroy_with_parent(GTK_WINDOW(preview_dialog), TRUE);
566 gtk_dialog_set_has_separator(GTK_DIALOG(preview_dialog), FALSE);
568 gtk_widget_set_size_request(preview_dialog, 185, -1);
570 event_box = gtk_event_box_new();
571 image = gtk_image_new();
572 if(self->preview_add != NULL){
573 gtk_image_set_from_file(GTK_IMAGE(image), self->preview_add);
575 }else{
576 gtk_image_set_from_pixbuf(GTK_IMAGE(image),
577 GDK_PIXBUF(self->webdb_theme->preview_button));
580 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(preview_dialog)->vbox),
581 event_box);
582 gtk_container_add(GTK_CONTAINER(event_box), image);
584 g_signal_connect_swapped(G_OBJECT(event_box),
585 "button-release-event",
586 G_CALLBACK(gtk_widget_destroy),
587 preview_dialog);
589 gtk_widget_show_all(GTK_WIDGET(preview_dialog));
591 IRRECO_RETURN_BOOL(TRUE);
595 * Combobox versions
599 static void
600 irreco_theme_manager_dlg_selected_version_dlg(GtkComboBox *widget,
601 IrrecoThemeManagerDlg *self)
603 GtkTreeIter iter;
604 gchar *id;
606 IRRECO_ENTER
608 if(!gtk_combo_box_get_active_iter(widget, &iter)) {
609 IRRECO_RETURN
611 gtk_tree_model_get(GTK_TREE_MODEL(self->version_store), &iter,
612 ID_COL, &id, -1);
614 if (self->webdb_theme == NULL || self->webdb_theme->id != atoi(id)) {
615 IRRECO_DEBUG("SELECTED ID: %d\n", atoi(id));
616 self->selected_theme_id = atoi(id);
617 self->loader_func_id = g_idle_add(G_SOURCEFUNC(
618 irreco_theme_manager_dlg_theme_db_detail_loader),
619 self);
622 IRRECO_RETURN
626 * Delete user theme
629 static void irreco_theme_manager_dlg_delete_theme(GtkButton *button,
630 IrrecoThemeManagerDlg *self)
633 const gchar *name = gtk_label_get_label(GTK_LABEL(self->theme_name));
634 GString *message = g_string_new(NULL);
635 IRRECO_ENTER
637 g_string_append_printf(
638 message, _("Are you sure you want to\n "
639 "delete %s theme?"),name);
641 if (irreco_yes_no_dlg(GTK_WINDOW(self), message->str)){
643 irreco_theme_manager_remove_theme(
644 self->irreco_data->theme_manager, name);
645 gtk_button_clicked(GTK_BUTTON(self->refresh_button));
648 g_string_free(message, TRUE);
649 IRRECO_RETURN
653 * Download theme from DB
656 static void irreco_theme_manager_dlg_download_theme(GtkButton *button,
657 IrrecoThemeManagerDlg *self)
659 GtkWidget *radio1, *radio2, *radio3;
660 GtkWidget *label;
661 IrrecoTheme *theme;
662 IrrecoWebdbCache *webdb_cache = NULL;
663 gboolean theme_is_loaded = FALSE;
664 gint delete_mode = 0;
665 IrrecoTheme *same_theme = NULL;
666 gchar *same_theme_folder = NULL;
667 IrrecoThemeManager *theme_manager = self->irreco_data->theme_manager;
668 GString *message = g_string_new(NULL);
669 GString *path = g_string_new(NULL);
671 IRRECO_ENTER
673 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data, FALSE);
674 self->download_dialog = irreco_dlg_new();
676 gtk_widget_set_size_request(self->download_dialog, 340, 160);
678 gtk_window_set_title(GTK_WINDOW(self->download_dialog),
679 _("Download theme"));
680 gtk_window_set_modal(GTK_WINDOW(self->download_dialog), TRUE);
681 gtk_window_set_destroy_with_parent(GTK_WINDOW(self->download_dialog),
682 TRUE);
683 gtk_dialog_set_has_separator(GTK_DIALOG(self->download_dialog), FALSE);
684 gtk_dialog_add_buttons(GTK_DIALOG(self->download_dialog),
685 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
686 GTK_STOCK_OK, GTK_RESPONSE_OK,
687 NULL);
689 label = gtk_label_new("Select save location");
691 radio1 = gtk_radio_button_new_with_label (NULL, "MMC1");
692 radio2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(
693 radio1), "MMC2");
694 radio3 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(
695 radio2), "DEVICE");
697 gtk_box_pack_start_defaults(GTK_BOX(
698 GTK_DIALOG(self->download_dialog)->vbox),
699 label);
701 if(irreco_is_dir("/media/mmc1")) {
702 gtk_box_pack_start_defaults(GTK_BOX(
703 GTK_DIALOG(self->download_dialog)->vbox),
704 radio1);
707 if(irreco_is_dir("/media/mmc2")) {
708 gtk_box_pack_start_defaults(GTK_BOX(
709 GTK_DIALOG(self->download_dialog)->vbox),
710 radio2);
712 #if 0
713 gtk_box_pack_start_defaults(GTK_BOX(
714 GTK_DIALOG(self->download_dialog)->vbox),
715 radio3);
717 #endif
719 gtk_widget_show_all(GTK_WIDGET(self->download_dialog));
721 while (1) {
722 delete_mode = 0;
724 if (gtk_dialog_run(
725 GTK_DIALOG(self->download_dialog)) == GTK_RESPONSE_CANCEL){
726 break;
729 if (self->loader_func_id != 0) {
730 continue;
733 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio1))) {
734 self->theme_folder = "/media/mmc1/irreco/";
735 } else if (gtk_toggle_button_get_active(
736 GTK_TOGGLE_BUTTON(radio2))) {
737 self->theme_folder = "/media/mmc2/irreco/";
738 } else {
739 self->theme_folder = IRRECO_THEME_DIR;
742 if(!irreco_is_dir(self->theme_folder)) {
743 g_mkdir(self->theme_folder, 0777);
746 /* Create theme */
747 g_string_printf(path, "%s%s/", self->theme_folder,
748 self->webdb_theme->folder->str);
750 IRRECO_STRING_TABLE_FOREACH_DATA(theme_manager->themes,
751 IrrecoTheme *, theme)
752 /*Check theme name*/
753 if (g_str_equal(self->webdb_theme->name->str,
754 theme->name->str)) {
755 if (g_str_equal(theme->source->str, "deb")) {
756 g_string_printf(message,
757 _("The \"%s\" theme already exists.\n"
758 "Can't overwrite \"Built In themes\"\n"
759 "Please remove it first from the\n"
760 "Application Manager"),
761 theme->name->str);
763 irreco_error_dlg(GTK_WINDOW(
764 self->download_dialog),
765 message->str);
766 goto end;
768 delete_mode += 1;
769 same_theme = theme;
771 /*Check theme folder path*/
772 else if (g_str_equal(path->str,
773 g_strconcat(theme->path->str, "/", NULL))){
774 if (g_str_equal(theme->source->str, "deb")) {
775 g_string_printf(message,
776 _("This theme replaces \"%s\" theme.\n"
777 "Can't overwrite \"Built In themes\"\n"
778 "Please remove it first from the\n"
779 "Application Manager"),
780 theme->name->str);
782 irreco_error_dlg(GTK_WINDOW(
783 self->download_dialog),
784 message->str);
785 goto end;
787 delete_mode += 2;
788 same_theme_folder = g_strdup(theme->name->str);
790 IRRECO_STRING_TABLE_FOREACH_END
792 if (delete_mode == 1) {
793 g_string_printf(message,
794 _("The \"%s\" theme already exists.\n"
795 "Do you want to replace this theme?"),
796 same_theme->name->str);
797 } else if (delete_mode == 2) {
798 g_string_printf(message,
799 _("This theme replaces \"%s\" theme.\n"
800 "Do you want to continue?"),
801 same_theme_folder);
802 } else if (delete_mode == 3) {
803 g_string_printf(message,
804 _("This theme replaces themes\n"
805 "\"%s\" and \"%s\"\n"
806 "Do you want to continue?"),
807 same_theme->name->str,
808 same_theme_folder);
811 /* Check whether a theme folder already exists */
812 if (delete_mode != 0) {
813 /* Create dialog*/
814 if (!irreco_yes_no_dlg(
815 GTK_WINDOW(self->download_dialog), message->str)) {
816 continue;
817 } else {
818 /* Remove theme folder and then make it again*/
819 if (delete_mode == 1 || delete_mode == 3) {
820 gchar *rm_cmd = g_strconcat("rm -r ",
821 same_theme->path->str, NULL);
822 system(rm_cmd);
823 g_free(rm_cmd);
825 if (delete_mode == 2 || delete_mode == 3) {
826 irreco_theme_manager_remove_theme(
827 self->irreco_data->theme_manager,
828 same_theme_folder);
829 g_free(same_theme_folder);
834 /*Create folder */
835 g_mkdir(path->str, 0777);
837 /*Create new theme*/
838 if (delete_mode == 0 || delete_mode == 2) {
839 theme = irreco_theme_new();
840 irreco_theme_set(theme,
841 self->webdb_theme->name->str,
842 path->str, "web",
843 self->webdb_theme->creator->str,
844 self->webdb_theme->comment->str,
845 self->webdb_theme->preview_button_name->str,
846 self->webdb_theme->uploaded->str);
848 irreco_theme_update_keyfile(theme);
849 irreco_theme_free(theme);
850 } else {
851 irreco_theme_set(same_theme,
852 self->webdb_theme->name->str,
853 path->str, "web",
854 self->webdb_theme->creator->str,
855 self->webdb_theme->comment->str,
856 self->webdb_theme->preview_button_name->str,
857 self->webdb_theme->uploaded->str);
860 /* Get buttons and backgrounds */
861 self->loader_func_id = g_idle_add(G_SOURCEFUNC(
862 irreco_theme_manager_dlg_button_loader), self);
863 theme_is_loaded = TRUE;
866 end:
867 g_string_free(message, TRUE);
868 g_string_free(path, TRUE);
869 irreco_theme_manager_dlg_hide_banner(self);
870 irreco_theme_manager_dlg_loader_stop(self);
871 if(self->download_dialog != NULL) {
872 gtk_widget_destroy(GTK_WIDGET(self->download_dialog));
873 self->download_dialog = NULL;
874 if(theme_is_loaded == TRUE) {
875 gtk_button_clicked(GTK_BUTTON(self->refresh_button));
878 IRRECO_RETURN
882 * Upload user theme
886 static void irreco_theme_manager_dlg_upload_theme(GtkButton *button,
887 IrrecoThemeManagerDlg *self)
889 IRRECO_ENTER
891 if (irreco_theme_upload_dlg_run(GTK_WINDOW(self),
892 self->irreco_data, self->theme) == TRUE) {
893 gtk_button_clicked(GTK_BUTTON(self->refresh_button));
895 IRRECO_RETURN
899 void irreco_theme_manager_dlg_set_layout_button(IrrecoThemeManagerDlg *self)
901 IrrecoStringTable *table;
902 gchar *un_mmc1 = NULL;
903 gchar *un_mmc2 = NULL;
904 gchar *pressed_mmc1 = NULL;
905 gchar *pressed_mmc2 = NULL;
906 gchar *button_dir = NULL;
907 GString *bg_mmc = NULL;
909 IRRECO_ENTER
910 bg_mmc = g_string_new(NULL);
911 table = self->irreco_data->irreco_layout_array;
913 IRRECO_STRING_TABLE_FOREACH_DATA(self->theme->buttons,
914 IrrecoThemeButton *, temp_button)
916 button_dir = g_strrstr(temp_button->image_up->str, "/irreco");
917 un_mmc1 = g_strconcat("/media/mmc1", button_dir, NULL);
918 un_mmc2 = g_strconcat("/media/mmc2", button_dir, NULL);
920 button_dir = g_strrstr(temp_button->image_down->str, "/irreco");
921 pressed_mmc1 = g_strconcat("/media/mmc1", button_dir, NULL);
922 pressed_mmc2 = g_strconcat("/media/mmc2", button_dir, NULL);
924 if (!irreco_is_file(temp_button->image_up->str)) {
926 IRRECO_STRING_TABLE_FOREACH(table, key,
927 IrrecoButtonLayout *,
928 layout)
930 IRRECO_PTR_ARRAY_FORWARDS(layout->button_array,
931 IrrecoButton *, button)
933 if (button->style != NULL &&
934 g_str_equal(button->style->style_name->str,
935 temp_button->style_name->str)) {
937 if (irreco_is_file(un_mmc1)) {
938 g_string_printf(
939 button->style->image_up,
940 "%s", un_mmc1);
941 g_string_printf(
942 button->style->image_down,
943 "%s", pressed_mmc1);
944 } else if (irreco_is_file(un_mmc2)) {
945 g_string_printf(
946 button->style->image_up,
947 "%s", un_mmc2);
948 g_string_printf(
949 button->style->image_down,
950 "%s", pressed_mmc2);
951 } else {
952 button->type = IRRECO_BTYPE_GTK_BUTTON;
953 irreco_button_set_style(button, NULL);
954 irreco_button_create_widget(button);
958 IRRECO_PTR_ARRAY_FORWARDS_END
960 g_string_printf(bg_mmc, "%s" ,
961 irreco_button_layout_get_bg_image(layout));
963 g_string_erase(bg_mmc, 10, 1);
964 g_string_insert_c(bg_mmc, 10, 1);
965 if (irreco_is_file(bg_mmc->str)) {
967 irreco_button_layout_set_bg_image(layout,
968 bg_mmc->str);
969 } else {
970 g_string_erase(bg_mmc, 10, 1);
971 g_string_insert_c(bg_mmc, 10, 2);
972 irreco_button_layout_set_bg_image(layout,
973 bg_mmc->str);
977 IRRECO_STRING_TABLE_FOREACH_END
979 IRRECO_STRING_TABLE_FOREACH_END
981 g_string_free(bg_mmc, TRUE);
982 if (un_mmc1 != NULL) g_free(un_mmc1);
983 if (un_mmc2 != NULL) g_free(un_mmc2);
984 if (pressed_mmc1 != NULL) g_free(pressed_mmc1);
985 if (pressed_mmc2 != NULL) g_free(pressed_mmc2);
986 IRRECO_RETURN
990 *Create new theme or edit theme
992 static void irreco_theme_manager_dlg_new_theme(GtkButton *button,
993 IrrecoThemeManagerDlg *self)
996 IRRECO_ENTER
997 /* Check which button */
998 /* Create new theme */
999 if (g_str_equal("New", gtk_button_get_label(button))) {
1000 IrrecoTheme *new_theme = NULL;
1001 new_theme = irreco_theme_new();
1003 if (irreco_theme_creator_dlg_run(GTK_WINDOW(self),
1004 self->irreco_data, new_theme)) {
1005 gtk_button_clicked(GTK_BUTTON(self->refresh_button));
1007 /* Edit theme */
1008 } else {
1009 IrrecoTheme *new_theme = NULL;
1010 gchar *rm_dir;
1011 gchar *temp_dir;
1012 /* Create temp theme folder */
1013 temp_dir = g_strconcat("cp -r ", self->theme->path->str, " ",
1014 "/media/mmc2/irreco/irreco_temp", NULL);
1015 rm_dir = g_strconcat("rm -r ",
1016 "/media/mmc2/irreco/irreco_temp", NULL);
1017 /* Delete temp dir */
1018 if (irreco_is_dir("/media/mmc2/irreco/irreco_temp")) {
1019 system(rm_dir);
1021 system(temp_dir);
1023 new_theme = irreco_theme_new_from_dir(
1024 "/media/mmc2/irreco/irreco_temp");
1026 irreco_theme_set(new_theme, self->theme->name->str,
1027 self->theme->path->str,
1028 self->theme->source->str,
1029 self->theme->author->str,
1030 self->theme->comment->str,
1031 self->theme->preview_button_name->str,
1032 self->theme->version->str);
1034 IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme);
1035 IRRECO_DEBUG("New_Pointer: %p \n", (void*) new_theme);
1036 irreco_theme_print(new_theme);
1038 if (irreco_theme_creator_dlg_run(GTK_WINDOW(self),
1039 self->irreco_data, new_theme)) {
1041 irreco_theme_manager_dlg_set_layout_button(self);
1043 self->theme = irreco_theme_copy(new_theme);
1044 gtk_button_clicked(GTK_BUTTON(self->refresh_button));
1046 /* remove temp theme */
1047 system(rm_dir);
1049 g_free(rm_dir);
1050 g_free(temp_dir);
1051 irreco_theme_free(new_theme);
1054 IRRECO_RETURN
1057 /** @} */
1059 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1060 /* Private Functions */
1061 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1064 * @name Private Functions
1065 * @{
1069 * Clean detail list
1072 static void irreco_theme_manager_dlg_clean_details(IrrecoThemeManagerDlg *self)
1074 IRRECO_ENTER
1076 gtk_widget_show_all(GTK_WIDGET(self));
1077 gtk_label_set_text(
1078 GTK_LABEL(self->theme_name), "-");
1079 gtk_label_set_text(
1080 GTK_LABEL(self->theme_creator), "-");
1081 gtk_label_set_text(
1082 GTK_LABEL(self->theme_comment), "-");
1083 gtk_label_set_text(
1084 GTK_LABEL(self->theme_downloaded), "-");
1085 gtk_image_clear(GTK_IMAGE(self->theme_image));
1086 self->preview_add=NULL;
1088 gtk_widget_hide(self->upload_button);
1089 gtk_widget_hide(self->download_button);
1090 gtk_widget_hide(self->clear_button);
1091 gtk_widget_hide(self->edit_button);
1092 gtk_widget_hide(self->theme_info_alignment);
1093 gtk_widget_show(self->select_label);
1095 IRRECO_RETURN
1099 * Have the childern of this item been loaded.
1101 * @return TRUE if children have been loade, FALSE otherwise.
1104 static gboolean
1105 irreco_theme_manager_dlg_row_is_loaded(IrrecoThemeManagerDlg *self,
1106 GtkTreeIter *iter)
1108 gint i;
1109 IRRECO_ENTER
1111 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1112 iter, FLAG_COL, &i, -1);
1113 if (i & ROW_CHILDREN_LOADED) IRRECO_RETURN_BOOL(TRUE);
1115 IRRECO_RETURN_BOOL(FALSE);
1119 * Get type of row.
1122 static gint irreco_theme_manager_dlg_row_get_type(IrrecoThemeManagerDlg *self,
1123 GtkTreeIter *iter)
1125 gint i;
1127 IRRECO_ENTER
1129 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1130 iter, FLAG_COL, &i, -1);
1131 if (i & ROW_TYPE_CATEGORY)
1132 IRRECO_RETURN_ENUM(ROW_TYPE_CATEGORY);
1133 if (i & ROW_TYPE_DEB)
1134 IRRECO_RETURN_ENUM(ROW_TYPE_DEB);
1135 if (i & ROW_TYPE_USER)
1136 IRRECO_RETURN_ENUM(ROW_TYPE_USER);
1137 if (i & ROW_TYPE_WEB)
1138 IRRECO_RETURN_ENUM(ROW_TYPE_WEB);
1139 if (i & ROW_TYPE_DB)
1140 IRRECO_RETURN_ENUM(ROW_TYPE_DB);
1141 if (i & ROW_TYPE_LOADING)
1142 IRRECO_RETURN_ENUM(ROW_TYPE_LOADING);
1143 IRRECO_RETURN_INT(0);
1147 * Show hildon progressbar banner.
1149 * This function will create a new banner if one has not been created yet,
1150 * if banner already exists, it's properties will be changed.
1152 * @param text Text to show.
1153 * @param fraction Value of progress.
1156 static void irreco_theme_manager_dlg_set_banner(IrrecoThemeManagerDlg *self,
1157 const gchar *text,
1158 gdouble fraction)
1160 IRRECO_ENTER
1162 if (self->banner == NULL) {
1163 self->banner = hildon_banner_show_progress(
1164 GTK_WIDGET(self), NULL, "");
1167 hildon_banner_set_text(HILDON_BANNER(self->banner), text);
1168 hildon_banner_set_fraction(HILDON_BANNER(self->banner), fraction);
1170 IRRECO_RETURN
1174 * Destroy banner, if it exists.
1177 static void irreco_theme_manager_dlg_hide_banner(IrrecoThemeManagerDlg *self)
1179 IRRECO_ENTER
1181 if (self->banner) {
1182 gtk_widget_destroy(self->banner);
1183 self->banner = NULL;
1186 IRRECO_RETURN
1190 * Start a loader state machine if one is not running already.
1193 static
1194 gboolean irreco_theme_manager_dlg_loader_start(IrrecoThemeManagerDlg *self,
1195 GSourceFunc function,
1196 GtkTreeIter *parent_iter)
1198 IRRECO_ENTER
1200 if (self->loader_func_id == 0) {
1201 if (parent_iter) {
1202 self->loader_parent_iter = gtk_tree_iter_copy(
1203 parent_iter);
1205 if (function) {
1206 self->loader_func_id = g_idle_add(function, self);
1207 } else {
1208 IRRECO_ERROR("Loader function pointer not given.\n");
1211 IRRECO_RETURN_BOOL(TRUE);
1216 * Stop and cleanup loader if a loader is running.
1219 static void irreco_theme_manager_dlg_loader_stop(IrrecoThemeManagerDlg *self)
1221 IRRECO_ENTER
1223 if (self->loader_func_id != 0) {
1224 g_source_remove(self->loader_func_id);
1225 self->loader_func_id = 0;
1226 self->loader_state = 0;
1227 if (self->loader_parent_iter) {
1228 gtk_tree_iter_free(self->loader_parent_iter);
1230 self->loader_parent_iter = NULL;
1232 IRRECO_RETURN
1235 static gboolean
1236 irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg *self)
1238 IRRECO_ENTER
1240 switch (self->loader_state) {
1241 case LOADER_STATE_INIT: {
1242 GtkTreeIter iter;
1243 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
1244 0.5);
1245 self->loader_state = LOADER_STATE_LOOP;
1246 irreco_theme_manager_dlg_clean_details(self);
1247 if (!irreco_theme_manager_does_user_exist(
1248 self->irreco_data->theme_manager)) {
1249 self->loader_state = LOADER_STATE_END;
1250 self->loader_iter = NULL;
1251 } else {
1254 gtk_tree_store_append(self->tree_store,
1255 &iter, NULL);
1256 gtk_tree_store_set(self->tree_store,
1257 &iter,
1258 TEXT_COL, _("My Themes"),
1259 FLAG_COL, ROW_TYPE_CATEGORY,
1260 DATA_COL, NULL, -1);
1262 self->loader_iter = gtk_tree_iter_copy(&iter);
1265 IRRECO_RETURN_BOOL(TRUE);
1269 case LOADER_STATE_LOOP: {
1271 IrrecoData *irreco_data = NULL;
1272 IrrecoThemeManager *theme_manager = NULL;
1273 GtkTreeIter iter;
1274 IrrecoStringTable *categories = NULL;
1277 irreco_data = self->irreco_data;
1278 theme_manager = irreco_data->theme_manager;
1279 categories = irreco_theme_manager_get_themes(theme_manager);
1281 IRRECO_STRING_TABLE_FOREACH_DATA(categories,
1282 IrrecoTheme *, theme)
1284 if (g_utf8_collate(theme->source->str, "user") == 0){
1286 /* Add loading item into category. */
1287 gtk_tree_store_append(self->tree_store,
1288 &iter,
1289 self->loader_iter);
1290 gtk_tree_store_set(self->tree_store,
1291 &iter,
1292 TEXT_COL,
1293 theme->name->str,
1294 FLAG_COL,
1295 ROW_TYPE_USER,
1296 DATA_COL, NULL, -1);
1298 IRRECO_STRING_TABLE_FOREACH_END
1300 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
1301 1.0);
1302 self->loader_state = LOADER_STATE_END;
1303 IRRECO_RETURN_BOOL(TRUE);
1306 case LOADER_STATE_END:
1307 if (self->loader_iter != NULL) {
1308 gtk_tree_iter_free(self->loader_iter);
1310 irreco_theme_manager_dlg_hide_banner(self);
1311 irreco_theme_manager_dlg_loader_stop(self);
1313 irreco_theme_manager_dlg_loader_start(self,
1314 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_deb),NULL);
1317 IRRECO_RETURN_BOOL(FALSE);
1321 * Category loader.
1323 * This loader will request a list of categories from the theme and
1324 * update the TreeView accordingly. Every category row created by this loader
1325 * will have row type ROW_TYPE_DEB.
1329 static gboolean irreco_theme_manager_dlg_loader_deb(IrrecoThemeManagerDlg *self)
1331 IRRECO_ENTER
1333 switch (self->loader_state) {
1334 case LOADER_STATE_INIT: {
1335 GtkTreeIter iter;
1336 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
1337 0.5);
1338 self->loader_state = LOADER_STATE_LOOP;
1339 irreco_theme_manager_dlg_clean_details(self);
1341 if (!irreco_theme_manager_does_deb_exist(
1342 self->irreco_data->theme_manager)) {
1343 self->loader_state = LOADER_STATE_END;
1344 self->loader_iter = NULL;
1345 } else {
1347 gtk_tree_store_append(self->tree_store,
1348 &iter, NULL);
1349 gtk_tree_store_set(self->tree_store,
1350 &iter,
1351 TEXT_COL, _("Built In"),
1352 FLAG_COL, ROW_TYPE_CATEGORY,
1353 DATA_COL, NULL, -1);
1355 self->loader_iter = gtk_tree_iter_copy(&iter);
1357 IRRECO_RETURN_BOOL(TRUE);
1361 case LOADER_STATE_LOOP: {
1363 IrrecoData *irreco_data = NULL;
1364 IrrecoThemeManager *theme_manager = NULL;
1365 GtkTreeIter iter;
1366 IrrecoStringTable *categories = NULL;
1368 irreco_data = self->irreco_data;
1369 theme_manager = irreco_data->theme_manager;
1370 categories = irreco_theme_manager_get_themes(theme_manager);
1372 IRRECO_STRING_TABLE_FOREACH_DATA(categories,
1373 IrrecoTheme *, theme)
1374 if (g_utf8_collate(theme->source->str, "deb") == 0){
1376 /* Add loading item into category. */
1377 gtk_tree_store_append(self->tree_store,
1378 &iter, self->loader_iter);
1379 gtk_tree_store_set(self->tree_store,
1380 &iter,
1381 TEXT_COL,
1382 theme->name->str,
1383 FLAG_COL, ROW_TYPE_DEB,
1384 DATA_COL, NULL, -1);
1386 IRRECO_STRING_TABLE_FOREACH_END
1388 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
1389 1.0);
1390 self->loader_state = LOADER_STATE_END;
1391 IRRECO_RETURN_BOOL(TRUE);
1394 case LOADER_STATE_END: {
1395 GtkTreeIter iter, iter_loading;
1396 if (self->loader_iter != NULL) {
1397 gtk_tree_iter_free(self->loader_iter);
1399 irreco_theme_manager_dlg_hide_banner(self);
1400 irreco_theme_manager_dlg_loader_stop(self);
1402 /* Create database row */
1403 gtk_tree_store_append(self->tree_store, &iter, NULL);
1404 gtk_tree_store_set(self->tree_store, &iter,
1405 TEXT_COL, _("Database"),
1406 FLAG_COL, ROW_TYPE_CATEGORY,
1407 DATA_COL, NULL, -1);
1409 /* Add loading item into manufacturer. */
1410 gtk_tree_store_append(self->tree_store, &iter_loading, &iter);
1411 gtk_tree_store_set(self->tree_store, &iter_loading,
1412 TEXT_COL, _("Loading ..."),
1413 FLAG_COL, ROW_TYPE_LOADING,
1414 DATA_COL, NULL, -1);
1416 irreco_theme_manager_dlg_loader_start(self,
1417 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_web), NULL);
1421 IRRECO_RETURN_BOOL(FALSE);
1424 static gboolean irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg *self)
1426 IRRECO_ENTER
1428 switch (self->loader_state) {
1429 case LOADER_STATE_INIT:{
1430 GtkTreeIter iter;
1431 irreco_theme_manager_dlg_set_banner(self, _("Loading themes"),
1432 0.0);
1433 self->loader_state = LOADER_STATE_LOOP;
1434 self->theme_loader_index = 0;
1435 irreco_theme_manager_dlg_clean_details(self);
1437 /* Check if loading item exist */
1438 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self->tree_store),
1439 &iter, self->loader_iter, 0);
1441 if(irreco_theme_manager_dlg_row_get_type(self,
1442 &iter) != ROW_TYPE_LOADING) {
1443 self->loader_state = LOADER_STATE_END;
1446 IRRECO_RETURN_BOOL(TRUE);
1450 case LOADER_STATE_LOOP: {
1451 GtkTreeIter iter;
1452 GtkTreeIter iter_loading;
1453 IrrecoStringTable *themes = NULL;
1454 IrrecoWebdbTheme *theme_by_id;
1455 IrrecoWebdbCache *webdb_cache = NULL;
1456 const gchar *id;
1457 gfloat banner;
1459 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data,
1460 FALSE);
1461 /* Get themes */
1462 if (!irreco_webdb_cache_get_themes(webdb_cache, &themes)) {
1463 irreco_error_dlg(GTK_WINDOW(self),
1464 irreco_webdb_cache_get_error(
1465 webdb_cache));
1466 self->loader_state = LOADER_STATE_END;
1467 IRRECO_RETURN_BOOL(TRUE);
1470 if (!irreco_string_table_index(themes,
1471 (guint)self->theme_loader_index, &id, NULL)) {
1472 irreco_error_dlg(GTK_WINDOW(self), "Can't find theme");
1473 self->loader_state = LOADER_STATE_END;
1474 IRRECO_RETURN_BOOL(TRUE);
1477 if (!irreco_webdb_cache_get_theme_by_id(webdb_cache,
1478 atoi(id),
1479 &theme_by_id)) {
1480 irreco_error_dlg(GTK_WINDOW(self),
1481 irreco_webdb_cache_get_error(
1482 webdb_cache));
1483 self->loader_state = LOADER_STATE_END;
1484 IRRECO_RETURN_BOOL(TRUE);
1487 gtk_tree_store_append(self->tree_store, &iter,
1488 self->loader_iter);
1490 gtk_tree_store_set(self->tree_store, &iter,
1491 TEXT_COL, theme_by_id->name->str,
1492 FLAG_COL, ROW_TYPE_DB,
1493 DATA_COL, id, -1);
1495 banner = ++self->theme_loader_index;
1496 banner /= (gfloat) irreco_string_table_lenght (themes);
1498 irreco_theme_manager_dlg_set_banner(self, _("Loading themes"),
1499 banner);
1500 if (banner >= 1.0) {
1501 self->loader_state = LOADER_STATE_END;
1504 /* Delete loading item */
1505 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self->tree_store),
1506 &iter_loading, self->loader_iter,
1508 if(irreco_theme_manager_dlg_row_get_type(self,
1509 &iter_loading) == ROW_TYPE_LOADING) {
1510 gtk_tree_store_remove(self->tree_store, &iter_loading);
1513 IRRECO_RETURN_BOOL(TRUE);
1516 case LOADER_STATE_END:
1517 if (self->loader_iter != NULL) {
1518 gtk_tree_iter_free(self->loader_iter);
1520 irreco_theme_manager_dlg_hide_banner(self);
1521 irreco_theme_manager_dlg_loader_stop(self);
1524 IRRECO_RETURN_BOOL(FALSE);
1528 static gboolean irreco_theme_manager_dlg_loader_web(IrrecoThemeManagerDlg *self)
1530 IRRECO_ENTER
1532 switch (self->loader_state) {
1533 case LOADER_STATE_INIT: {
1534 GtkTreeIter iter;
1535 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
1536 0.5);
1537 self->loader_state = LOADER_STATE_LOOP;
1538 irreco_theme_manager_dlg_clean_details(self);
1539 if (!irreco_theme_manager_does_web_exist(
1540 self->irreco_data->theme_manager)) {
1541 self->loader_state = LOADER_STATE_END;
1542 self->loader_iter = NULL;
1543 } else {
1545 gtk_tree_store_append(self->tree_store,
1546 &iter, NULL);
1547 gtk_tree_store_set(self->tree_store,
1548 &iter,
1549 TEXT_COL, _("Downloaded"),
1550 FLAG_COL, ROW_TYPE_CATEGORY,
1551 DATA_COL, NULL, -1);
1553 self->loader_iter = gtk_tree_iter_copy(&iter);
1555 IRRECO_RETURN_BOOL(TRUE);
1557 case LOADER_STATE_LOOP: {
1559 IrrecoData *irreco_data = NULL;
1560 IrrecoThemeManager *theme_manager = NULL;
1561 GtkTreeIter iter;
1562 IrrecoStringTable *categories = NULL;
1564 irreco_data = self->irreco_data;
1565 theme_manager = irreco_data->theme_manager;
1566 categories = irreco_theme_manager_get_themes(theme_manager);
1568 IRRECO_STRING_TABLE_FOREACH_DATA(categories,
1569 IrrecoTheme *, theme)
1571 if (g_utf8_collate(theme->source->str, "web") == 0){
1573 /* Add loading item into category. */
1574 gtk_tree_store_append(self->tree_store,
1575 &iter,
1576 self->loader_iter);
1577 gtk_tree_store_set(self->tree_store,
1578 &iter,
1579 TEXT_COL,
1580 theme->name->str,
1581 FLAG_COL,
1582 ROW_TYPE_WEB,
1583 DATA_COL, NULL, -1);
1585 IRRECO_STRING_TABLE_FOREACH_END
1587 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
1588 1.0);
1589 self->loader_state = LOADER_STATE_END;
1590 IRRECO_RETURN_BOOL(TRUE);
1593 case LOADER_STATE_END:
1594 if (self->loader_iter != NULL) {
1595 gtk_tree_iter_free(self->loader_iter);
1597 irreco_theme_manager_dlg_hide_banner(self);
1598 irreco_theme_manager_dlg_loader_stop(self);
1601 IRRECO_RETURN_BOOL(FALSE);
1605 * Show theme details
1607 * @todo
1610 static gboolean
1611 irreco_theme_manager_dlg_display_theme_detail(IrrecoThemeManagerDlg *self,
1612 GtkTreeIter * iter)
1614 IrrecoThemeManager *theme_manager = self->irreco_data->theme_manager;
1615 IrrecoThemeButton *button = NULL;
1616 const gchar *theme_name;
1618 IRRECO_ENTER
1620 gtk_image_clear(GTK_IMAGE(self->theme_image));
1622 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1623 iter, TEXT_COL, &theme_name, -1);
1624 irreco_string_table_get(theme_manager->themes, theme_name,
1625 (gpointer *) &self->theme);
1627 gtk_label_set_text(GTK_LABEL(self->theme_name),
1628 self->theme->name->str);
1629 gtk_label_set_text(GTK_LABEL(self->theme_creator),
1630 self->theme->author->str);
1631 gtk_label_set_text(GTK_LABEL(self->theme_comment),
1632 self->theme->comment->str);
1633 gtk_label_set_text(GTK_LABEL(self->theme_version),
1634 self->theme->version->str);
1636 if (self->theme->preview_button_name->len > 0) {
1637 button =irreco_theme_get_button(self->theme,
1638 self->theme->preview_button_name->str);
1639 } else {
1640 const gchar *key;
1641 irreco_string_table_index(self->theme->buttons,
1642 0, &key, (gpointer *) &button);
1645 if (button != NULL) {
1646 IRRECO_DEBUG("Preview-button: %s\n", button->image_up->str);
1648 gtk_image_set_from_file(GTK_IMAGE(self->theme_image),
1649 button->image_up->str);
1651 self->preview_add = button->image_up->str;
1652 } else {
1653 self->preview_add = NULL;
1655 self->webdb_theme = NULL;
1657 IRRECO_RETURN_BOOL(TRUE);
1660 static gboolean
1661 irreco_theme_manager_dlg_theme_db_detail_loader(IrrecoThemeManagerDlg *self)
1663 IRRECO_ENTER
1665 switch (self->loader_state) {
1666 case LOADER_STATE_INIT:{
1667 irreco_theme_manager_dlg_set_banner(self,
1668 _("Loading ..."), 0.5);
1669 self->loader_state = LOADER_STATE_LOOP;
1670 IRRECO_RETURN_BOOL(TRUE);
1673 case LOADER_STATE_LOOP: {
1674 gchar *download_count;
1675 gint index = 0;
1676 IrrecoWebdbCache *webdb_cache = irreco_data_get_webdb_cache(
1677 self->irreco_data,
1678 FALSE);
1680 /* Get WebdbTheme with preview-button */
1681 if (!irreco_webdb_cache_get_preview_button(webdb_cache,
1682 self->selected_theme_id,
1683 &self->webdb_theme)) {
1684 irreco_error_dlg(GTK_WINDOW(self),
1685 irreco_webdb_cache_get_error(
1686 webdb_cache));
1688 self->loader_state = LOADER_STATE_END;
1689 IRRECO_RETURN_BOOL(TRUE);
1692 gtk_image_clear(GTK_IMAGE(self->theme_image));
1694 gtk_label_set_text(GTK_LABEL(self->theme_name),
1695 self->webdb_theme->name->str);
1696 gtk_label_set_text(GTK_LABEL(self->theme_creator),
1697 self->webdb_theme->creator->str);
1698 gtk_label_set_text(GTK_LABEL(self->theme_comment),
1699 self->webdb_theme->comment->str);
1701 /* Clear combobox */
1702 gtk_tree_store_clear(self->version_store);
1704 IRRECO_STRING_TABLE_FOREACH(self->webdb_theme->versions,
1705 key, gchar *, date)
1706 GtkTreeIter iter;
1708 /* Append row */
1709 gtk_tree_store_append(self->version_store,
1710 &iter, NULL);
1712 /* Fill row */
1713 gtk_tree_store_set(self->version_store, &iter,
1714 DATE_COL, date,
1715 ID_COL, key, -1);
1717 if (g_utf8_collate (date,
1718 self->webdb_theme->uploaded->str) == 0) {
1719 gtk_combo_box_set_active(GTK_COMBO_BOX(
1720 self->combobox),
1721 index);
1723 index++;
1724 IRRECO_STRING_TABLE_FOREACH_END
1726 /*scale_combobox(self);*/
1728 download_count = g_strdup_printf("%d",
1729 self->webdb_theme->download_count);
1731 gtk_label_set_text(GTK_LABEL(self->theme_downloaded),
1732 download_count);
1733 g_free(download_count);
1735 if (self->webdb_theme->preview_button != NULL) {
1736 gtk_image_set_from_pixbuf(GTK_IMAGE(self->theme_image),
1737 self->webdb_theme->preview_button);
1738 } else {
1739 IRRECO_DEBUG("preview_button is NULL\n");
1741 self->preview_add = NULL;
1743 self->loader_state = LOADER_STATE_END;
1744 IRRECO_RETURN_BOOL(TRUE);
1747 case LOADER_STATE_END:
1748 irreco_theme_manager_dlg_hide_banner(self);
1749 irreco_theme_manager_dlg_loader_stop(self);
1751 IRRECO_RETURN_BOOL(FALSE);
1754 static gboolean irreco_theme_manager_dlg_bg_loader(IrrecoThemeManagerDlg *self)
1756 IRRECO_ENTER
1758 switch (self->loader_state) {
1759 case LOADER_STATE_INIT:{
1760 GString *path = g_string_new("");
1761 irreco_theme_manager_dlg_set_banner(self,
1762 _("Loading backgrounds..."),
1763 0.0);
1764 self->loader_state = LOADER_STATE_LOOP;
1765 self->theme_loader_index = 0;
1767 g_string_printf(path, "%s%s/bg/", self->theme_folder,
1768 self->webdb_theme->folder->str);
1770 IRRECO_DEBUG("mkdir %s\n", path->str);
1771 g_mkdir(path->str, 0777);
1772 g_string_free(path, TRUE);
1774 IRRECO_RETURN_BOOL(TRUE);
1777 case LOADER_STATE_LOOP: {
1778 IrrecoStringTable *bg_list = NULL;
1779 GString *path = g_string_new("");
1780 gfloat banner;
1781 const gchar *id;
1782 IrrecoWebdbCache *webdb_cache = irreco_data_get_webdb_cache(
1783 self->irreco_data,
1784 FALSE);
1785 /* Get backrounds */
1786 irreco_webdb_cache_get_backgrounds(webdb_cache,
1787 self->webdb_theme->id,
1788 &bg_list);
1790 g_string_printf(path, "%s%s/bg/", self->theme_folder,
1791 self->webdb_theme->folder->str);
1793 if (irreco_string_table_index(bg_list,
1794 (guint)self->theme_loader_index, &id, NULL) &&
1795 !g_str_equal(id, "0")) {
1796 irreco_webdb_cache_get_bg_by_id(webdb_cache, atoi(id),
1797 path->str);
1798 } else {
1799 self->loader_state = LOADER_STATE_END;
1800 goto end;
1803 banner = ++self->theme_loader_index;
1804 banner /= (gfloat) irreco_string_table_lenght (bg_list);
1806 irreco_theme_manager_dlg_set_banner(self,
1807 _("Loading backgrounds..."),
1808 banner);
1809 if (banner >= 1.0) {
1810 self->loader_state = LOADER_STATE_END;
1812 end:
1813 g_string_free(path, TRUE);
1814 IRRECO_RETURN_BOOL(TRUE);
1816 case LOADER_STATE_END:
1817 irreco_theme_manager_dlg_hide_banner(self);
1818 irreco_theme_manager_dlg_loader_stop(self);
1819 gtk_dialog_response(GTK_DIALOG(self->download_dialog),
1820 GTK_RESPONSE_CANCEL);
1822 IRRECO_RETURN_BOOL(FALSE);
1825 static gboolean
1826 irreco_theme_manager_dlg_button_loader(IrrecoThemeManagerDlg *self)
1828 IRRECO_ENTER
1830 switch (self->loader_state) {
1831 case LOADER_STATE_INIT:{
1832 GString *path = g_string_new("");
1833 irreco_theme_manager_dlg_set_banner(self,
1834 _("Loading buttons.."),
1835 0.0);
1836 self->loader_state = LOADER_STATE_LOOP;
1837 self->theme_loader_index = 0;
1839 g_string_printf(path, "%s%s/buttons/", self->theme_folder,
1840 self->webdb_theme->folder->str);
1842 IRRECO_DEBUG("mkdir %s\n", path->str);
1843 g_mkdir(path->str, 0777);
1844 g_string_free(path, TRUE);
1846 IRRECO_RETURN_BOOL(TRUE);
1849 case LOADER_STATE_LOOP: {
1850 IrrecoStringTable *button_list = NULL;
1851 GString *path = g_string_new("");
1852 gfloat banner;
1853 const gchar *id;
1854 IrrecoWebdbCache *webdb_cache = irreco_data_get_webdb_cache(
1855 self->irreco_data,
1856 FALSE);
1857 /* Get buttons */
1858 irreco_webdb_cache_get_buttons(webdb_cache,
1859 self->webdb_theme->id,
1860 &button_list);
1861 if (button_list == NULL) {
1862 self->loader_state = LOADER_STATE_END;
1863 goto end;
1866 g_string_printf(path, "%s%s/buttons/", self->theme_folder,
1867 self->webdb_theme->folder->str);
1869 if (irreco_string_table_index(button_list,
1870 (guint)self->theme_loader_index, &id, NULL) &&
1871 !g_str_equal(id, "0")) {
1872 irreco_webdb_cache_get_button_by_id(webdb_cache,
1873 atoi(id),
1874 path->str);
1875 } else {
1876 self->loader_state = LOADER_STATE_END;
1877 goto end;
1880 banner = ++self->theme_loader_index;
1881 banner /= (gfloat) irreco_string_table_lenght (button_list);
1883 irreco_theme_manager_dlg_set_banner(self,
1884 _("Loading buttons.."),
1885 banner);
1886 if (banner >= 1.0) {
1887 self->loader_state = LOADER_STATE_END;
1890 end:
1891 g_string_free(path, TRUE);
1892 IRRECO_RETURN_BOOL(TRUE);
1894 case LOADER_STATE_END:
1895 irreco_theme_manager_dlg_hide_banner(self);
1896 irreco_theme_manager_dlg_loader_stop(self);
1898 /* Get backgrounds */
1899 self->loader_func_id = g_idle_add(G_SOURCEFUNC(
1900 irreco_theme_manager_dlg_bg_loader), self);
1902 IRRECO_RETURN_BOOL(FALSE);
1905 /** @} */
1909 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1910 /* Functions */
1911 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1914 * @name Public Functions
1915 * @{
1918 void irreco_theme_manager_dlg_set_irreco_data(IrrecoThemeManagerDlg *self,
1919 IrrecoData *irreco_data)
1921 IRRECO_ENTER
1923 self->irreco_data = irreco_data;
1925 IRRECO_RETURN
1928 void irreco_show_theme_manager_dlg(IrrecoData *irreco_data, GtkWindow *parent)
1930 IrrecoThemeManagerDlg *self;
1931 gint response;
1932 gboolean loop = TRUE;
1933 IrrecoWebdbCache *webdb_cache = NULL;
1935 IRRECO_ENTER
1937 self = IRRECO_THEME_MANAGER_DLG(irreco_theme_manager_dlg_new(
1938 irreco_data, parent));
1940 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data, FALSE);
1942 do {
1943 response = gtk_dialog_run(GTK_DIALOG(self));
1944 switch (response) {
1945 case IRRECO_DEVICE_REFRESH:
1946 if (self->loader_func_id != 0) {
1947 break;
1949 IRRECO_DEBUG("IRRECO_DEVICE_REFRESH\n");
1950 gtk_tree_store_clear(self->tree_store);
1951 irreco_theme_manager_update_theme_manager
1952 (self->irreco_data->theme_manager);
1954 if (webdb_cache->theme_id_hash != NULL) {
1955 g_hash_table_remove_all(
1956 webdb_cache->theme_id_hash);
1957 self->webdb_theme = NULL;
1960 IRRECO_STRING_TABLE_FOREACH_DATA(
1961 irreco_data->theme_manager->themes,
1962 IrrecoTheme *, theme)
1963 irreco_theme_check(theme);
1964 IRRECO_STRING_TABLE_FOREACH_END
1966 irreco_theme_manager_dlg_loader_start(self,
1967 G_SOURCEFUNC(
1968 irreco_theme_manager_dlg_loader_user),
1969 NULL);
1970 gtk_label_set_text(GTK_LABEL(self->select_label),
1971 " Select \ncategory");
1972 break;
1974 case GTK_RESPONSE_CANCEL:
1975 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
1976 loop = FALSE;
1977 break;
1979 } while (loop);
1981 gtk_widget_destroy(GTK_WIDGET(self));
1983 IRRECO_RETURN
1986 /** @} */
1990 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1991 /* Events and Callbacks */
1992 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1995 * @name Events and Callbacks
1996 * @{
1999 static gboolean
2000 irreco_show_theme_manager_dlg_map_event(IrrecoThemeManagerDlg *self,
2001 GdkEvent *event,
2002 gpointer user_data)
2005 IRRECO_ENTER
2007 irreco_theme_manager_dlg_loader_start(
2008 self, G_SOURCEFUNC(irreco_theme_manager_dlg_loader_user),
2009 NULL);
2011 IRRECO_RETURN_BOOL(FALSE);
2014 static void
2015 irreco_show_theme_manager_dlg_destroy_event(IrrecoThemeManagerDlg *self,
2016 gpointer user_data)
2018 IRRECO_ENTER
2019 irreco_theme_manager_dlg_loader_stop(self);
2020 IRRECO_RETURN
2023 static void
2024 irreco_show_theme_manager_dlg_row_activated_event(GtkTreeView *tree_view,
2025 GtkTreePath *path,
2026 GtkTreeViewColumn *column,
2027 IrrecoThemeManagerDlg *self)
2029 IRRECO_ENTER
2031 if (gtk_tree_view_row_expanded(tree_view, path)) {
2032 gtk_tree_view_expand_row(tree_view, path, FALSE);
2033 } else {
2034 gtk_tree_view_collapse_row(tree_view, path);
2036 IRRECO_RETURN
2039 static void
2040 irreco_show_theme_manager_dlg_row_expanded_event(GtkTreeView *tree_view,
2041 GtkTreeIter *iter,
2042 GtkTreePath *path,
2043 IrrecoThemeManagerDlg *self)
2045 gchar *row_name = NULL;
2046 IRRECO_ENTER
2048 irreco_theme_manager_dlg_clean_details(self);
2049 gtk_label_set_text(GTK_LABEL(self->select_label), "Select \ntheme");
2052 if (self->loader_func_id != 0) {
2053 gtk_tree_view_collapse_row(tree_view, path);
2056 if (!irreco_theme_manager_dlg_row_is_loaded(self, iter)){
2057 switch (irreco_theme_manager_dlg_row_get_type(self, iter)){
2058 case ROW_TYPE_CATEGORY:
2059 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
2060 iter, TEXT_COL, &row_name, -1);
2062 if(g_utf8_collate(row_name, "Database") != 0) {
2063 goto end;
2066 self->loader_iter = gtk_tree_iter_copy(iter);
2067 irreco_theme_manager_dlg_loader_start(self,
2068 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_db), NULL);
2069 break;
2072 end:
2073 if (row_name != NULL) g_free(row_name);
2074 IRRECO_RETURN
2077 static void
2078 irreco_show_theme_manager_dlg_row_collapsed_event(GtkTreeView *tree_view,
2079 GtkTreeIter *iter,
2080 GtkTreePath *path,
2081 IrrecoThemeManagerDlg *self)
2084 IRRECO_ENTER
2086 gtk_label_set_text(GTK_LABEL(self->select_label), " Select\ncategory");
2088 irreco_theme_manager_dlg_clean_details(self);
2090 IRRECO_RETURN
2093 static void
2094 irreco_show_theme_manager_dlg_row_selected_event(GtkTreeSelection *sel,
2095 IrrecoThemeManagerDlg *self)
2097 GtkTreeIter iter;
2098 GtkTreeModel *model;
2099 const char *id;
2101 IRRECO_ENTER
2103 if (gtk_tree_selection_get_selected (sel, &model, &iter))
2105 switch (irreco_theme_manager_dlg_row_get_type(self, &iter)) {
2107 case ROW_TYPE_DEB:
2108 IRRECO_DEBUG("ROW_TYPE_DEB\n");
2110 gtk_widget_hide(self->select_label);
2111 gtk_widget_show(self->theme_info_alignment);
2112 gtk_widget_hide(self->label_download);
2113 gtk_widget_hide(self->theme_downloaded);
2114 gtk_widget_hide(self->label_combobox);
2115 gtk_widget_hide(self->combobox);
2116 gtk_widget_hide(self->theme_version);
2117 gtk_widget_hide(self->theme_creator);
2118 gtk_widget_hide(self->label_creator);
2120 gtk_widget_hide(self->upload_button);
2121 gtk_widget_hide(self->download_button);
2122 gtk_widget_hide(self->clear_button);
2123 gtk_widget_show(self->new_button);
2124 gtk_widget_hide(self->edit_button);
2127 irreco_theme_manager_dlg_display_theme_detail(self,
2128 &iter);
2130 break;
2131 case ROW_TYPE_USER:
2132 IRRECO_DEBUG("ROW_TYPE_USER\n");
2134 gtk_widget_hide(self->select_label);
2135 gtk_widget_show(self->theme_info_alignment);
2136 gtk_widget_hide(self->label_download);
2137 gtk_widget_hide(self->theme_downloaded);
2138 gtk_widget_show(self->theme_creator);
2139 gtk_widget_show(self->label_creator);
2141 gtk_widget_show(self->label_combobox);
2142 gtk_widget_hide(self->combobox);
2143 gtk_widget_show(self->theme_version);
2145 gtk_widget_show(self->upload_button);
2146 gtk_widget_show(self->clear_button);
2147 gtk_widget_hide(self->download_button);
2148 gtk_widget_show(self->edit_button);
2149 gtk_widget_hide(self->new_button);
2151 irreco_theme_manager_dlg_display_theme_detail(self,
2152 &iter);
2154 break;
2155 case ROW_TYPE_WEB:
2156 IRRECO_DEBUG("ROW_TYPE_WEB\n");
2158 gtk_widget_show(self->clear_button);
2159 gtk_widget_hide(self->upload_button);
2160 gtk_widget_hide(self->download_button);
2161 gtk_widget_show(self->new_button);
2162 gtk_widget_hide(self->edit_button);
2165 gtk_widget_hide(self->select_label);
2166 gtk_widget_show(self->theme_creator);
2167 gtk_widget_show(self->label_creator);
2168 gtk_widget_hide(self->label_download);
2169 gtk_widget_hide(self->theme_downloaded);
2171 gtk_widget_hide(self->combobox);
2172 gtk_widget_show(self->label_combobox);
2173 gtk_widget_show(self->theme_version);
2175 gtk_widget_show(self->theme_info_alignment);
2177 irreco_theme_manager_dlg_display_theme_detail(self,
2178 &iter);
2180 break;
2181 case ROW_TYPE_DB:
2182 IRRECO_DEBUG("ROW_TYPE_DB\n");
2184 if (self->loader_func_id != 0) {
2185 break;
2188 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
2189 &iter, DATA_COL, &id, -1);
2191 gtk_widget_hide(self->clear_button);
2192 gtk_widget_hide(self->upload_button);
2193 gtk_widget_show(self->download_button);
2194 gtk_widget_show(self->new_button);
2195 gtk_widget_hide(self->edit_button);
2198 gtk_widget_show(self->combobox);
2199 gtk_widget_show(self->label_combobox);
2200 gtk_widget_hide(self->theme_version);
2202 gtk_widget_hide(self->select_label);
2203 gtk_widget_show(self->theme_creator);
2204 gtk_widget_show(self->label_creator);
2205 gtk_widget_show(self->label_download);
2206 gtk_widget_show(self->theme_downloaded);
2208 gtk_widget_show(self->theme_info_alignment);
2210 IRRECO_DEBUG("SELECTED ID: %d\n", atoi(id));
2212 self->selected_theme_id = atoi(id);
2213 self->loader_func_id = g_idle_add(G_SOURCEFUNC(
2214 irreco_theme_manager_dlg_theme_db_detail_loader),
2215 self);
2217 break;
2218 default:
2219 irreco_theme_manager_dlg_clean_details(self);
2220 break;
2224 IRRECO_RETURN
2226 /** @} */
2227 /** @} */