whitespaces fixed
[irreco.git] / irreco / src / core / irreco_theme_manager_dlg.c
blobb9fdccc2ecc286603d79d95f781c3eff02a59c02
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"
26 #include "irreco_theme_download_dlg.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);
55 static void irreco_theme_manager_dlg_loader_stop(IrrecoThemeManagerDlg *self);
57 static void irreco_theme_manager_dlg_clean_details(IrrecoThemeManagerDlg *self);
59 static gboolean
60 irreco_theme_manager_dlg_loader_deb(IrrecoThemeManagerDlg *self);
62 static gboolean
63 irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg *self);
65 static gboolean
66 irreco_theme_manager_dlg_loader_web(IrrecoThemeManagerDlg *self);
68 static gboolean
69 irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg *self);
71 static gboolean
72 irreco_theme_manager_dlg_theme_db_detail_loader(IrrecoThemeManagerDlg *self);
74 static gboolean
75 irreco_theme_manager_dlg_display_theme_detail(IrrecoThemeManagerDlg *self,
76 GtkTreeIter * iter);
78 static gboolean irreco_theme_manager_dlg_map_event(IrrecoThemeManagerDlg
79 *self, GdkEvent *event,
80 gpointer user_data);
82 static void irreco_theme_manager_dlg_destroy_event(IrrecoThemeManagerDlg
83 *self,
84 gpointer user_data);
86 static void irreco_theme_manager_dlg_row_activated_event(GtkTreeView *tree_view,
87 GtkTreePath *path,
88 GtkTreeViewColumn *column,
89 IrrecoThemeManagerDlg*self);
91 static void irreco_theme_manager_dlg_row_expanded_event(GtkTreeView *tree_view,
92 GtkTreeIter *iter,
93 GtkTreePath *path,
94 IrrecoThemeManagerDlg *self);
96 static void irreco_theme_manager_dlg_row_collapsed_event(GtkTreeView *tree_view,
97 GtkTreeIter *iter,
98 GtkTreePath *path,
99 IrrecoThemeManagerDlg *self);
102 static void irreco_theme_manager_dlg_row_selected_event(GtkTreeSelection *sel,
103 IrrecoThemeManagerDlg *self);
105 gboolean irreco_theme_manager_dlg_preview_dlg(GtkWidget *widget,
106 GdkEventButton *event,
107 IrrecoThemeManagerDlg *self);
109 static void irreco_theme_manager_dlg_delete_theme(GtkButton *button,
110 IrrecoThemeManagerDlg *self);
112 static void irreco_theme_manager_dlg_selected_version(GtkComboBox *widget,
113 IrrecoThemeManagerDlg *self);
115 void irreco_theme_manager_update_theme_manager(IrrecoThemeManager *self);
117 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
118 /* Datatypes */
119 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
121 /** Button responce codes. */
122 enum {
123 IRRECO_DEVICE_REFRESH,
124 IRRECO_DOWNLOAD_THEME,
125 IRRECO_UPLOAD_THEME
128 /** GtkTreeStore colums. */
129 enum
131 TEXT_COL,
132 FLAG_COL,
133 DATA_COL,
134 N_COLUMNS
137 /** Version colums. */
138 enum
140 DATE_COL,
141 ID_COL
144 /** Loader states. */
145 enum
147 LOADER_STATE_INIT,
148 LOADER_STATE_LOOP,
149 LOADER_STATE_END,
150 LOADER_STATE_CLEANUP
153 /** Row flags. */
154 enum
156 ROW_CHILDREN_LOADED = 1 << 1,
157 ROW_TYPE_CATEGORY = 1 << 2,
158 ROW_TYPE_DEB = 1 << 3,
159 ROW_TYPE_USER = 1 << 4,
160 ROW_TYPE_WEB = 1 << 5,
161 ROW_TYPE_DB = 1 << 6,
162 ROW_TYPE_LOADING = 1 << 7
165 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
166 /* Construction & Destruction */
167 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
170 * @name Construction & Destruction
171 * @{
174 G_DEFINE_TYPE(IrrecoThemeManagerDlg, irreco_theme_manager_dlg, IRRECO_TYPE_DLG)
176 static void irreco_theme_manager_dlg_finalize(GObject *object)
178 if (G_OBJECT_CLASS(irreco_theme_manager_dlg_parent_class)->finalize)
179 G_OBJECT_CLASS(irreco_theme_manager_dlg_parent_class)->finalize(
180 object);
183 static void
184 irreco_theme_manager_dlg_class_init(IrrecoThemeManagerDlgClass *klass)
186 GObjectClass *object_class = G_OBJECT_CLASS(klass);
187 object_class->finalize = irreco_theme_manager_dlg_finalize;
190 static void irreco_theme_manager_dlg_init(IrrecoThemeManagerDlg *self)
192 GtkTreeViewColumn *column;
193 GtkCellRenderer *renderer;
194 GtkTreeSelection *select;
195 GtkWidget *label_name;
196 GtkWidget *label_description;
197 /*GtkWidget *label_rate;*/
198 GtkWidget *theme_info_frame;
199 GtkWidget *tree_view_frame;
200 GtkWidget *tree_view_hbox;
201 GtkWidget *preview_frame;
202 PangoFontDescription *initial_font;
203 GtkWidget *select_vbox;
204 GtkWidget *versions_hbox;
205 GtkWidget *comment_alignment;
206 GtkWidget *info_scrollbar;
207 GtkWidget *scrollbar;
208 GtkWidget *theme_info;
209 GtkWidget *table;
210 GtkWidget *info_vbox;
211 GtkWidget *done_button;
212 GtkWidget *theme_table;
213 GtkWidget *preview_event_box;
215 IRRECO_ENTER
217 self->theme_folder = NULL;
219 /* Construct dialog. */
220 gtk_window_set_title(GTK_WINDOW(self),
221 _("Theme Manager "));
222 /*gtk_window_set_decorated (GTK_WINDOW(self), FALSE);*/
223 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
224 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
225 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
227 /*Buttons*/
229 self->refresh_button= gtk_dialog_add_button (GTK_DIALOG(self),
230 _("Refresh"),
231 IRRECO_DEVICE_REFRESH);
233 self->upload_button= gtk_dialog_add_button (GTK_DIALOG(self),
234 _("Upload"), IRRECO_UPLOAD_THEME);
237 self->download_button= gtk_dialog_add_button (GTK_DIALOG(self),
238 _("Download"), IRRECO_DOWNLOAD_THEME);
240 self->clear_button= gtk_dialog_add_button (GTK_DIALOG(self),
241 _("Delete"),
242 GTK_RESPONSE_NONE);
243 done_button= gtk_dialog_add_button (GTK_DIALOG(self),
244 _("Done"),
245 GTK_RESPONSE_CANCEL);
247 /* Create theme table */
249 table = gtk_table_new(7,7,TRUE);
250 gtk_table_set_col_spacings(GTK_TABLE (table), 8);
251 gtk_table_set_row_spacings(GTK_TABLE (table), 8);
252 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self)->vbox),
253 irreco_gtk_align(GTK_WIDGET(table),
254 0, 0, 1, 1, 8, 8, 8, 8));
255 /* Create tree_view_hbox */
256 tree_view_hbox = gtk_hbox_new(FALSE, 2);
258 /* Create Treeview */
259 self->tree_store = gtk_tree_store_new(
260 N_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_POINTER);
261 self->tree_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(
262 GTK_TREE_MODEL(self->tree_store)));
264 renderer = gtk_cell_renderer_text_new();
265 column = gtk_tree_view_column_new_with_attributes(
266 NULL, renderer, "text", TEXT_COL, NULL);
267 gtk_tree_view_append_column(self->tree_view, column);
269 gtk_box_pack_start(GTK_BOX(tree_view_hbox), GTK_WIDGET(self->tree_view),
270 TRUE, TRUE, 0);
272 /* Create scrollbar for Treeview */
274 scrollbar = gtk_scrolled_window_new(NULL, NULL);
275 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar),
276 GTK_POLICY_AUTOMATIC,
277 GTK_POLICY_AUTOMATIC);
279 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
280 scrollbar), tree_view_hbox);
282 /* Create Frame for Treeview */
283 tree_view_frame = gtk_frame_new("");
284 gtk_frame_set_label_widget(GTK_FRAME(tree_view_frame),
285 irreco_gtk_label_bold("Themes", 0, 0, 0, 0, 0, 0));
287 gtk_container_add(GTK_CONTAINER(tree_view_frame),
288 GTK_WIDGET(scrollbar));
290 /* Create theme_info */
292 theme_info = gtk_table_new(7, 4, TRUE);
293 gtk_table_set_col_spacings(GTK_TABLE(theme_info), 8);
294 gtk_table_set_row_spacings(GTK_TABLE(theme_info), 8);
296 /* Scrolled window for info */
297 info_scrollbar = gtk_scrolled_window_new(NULL, NULL);
298 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
299 info_scrollbar),
300 GTK_POLICY_NEVER,
301 GTK_POLICY_AUTOMATIC);
303 /* Create combobox*/
304 self->version_store = gtk_tree_store_new(
305 2, G_TYPE_STRING, G_TYPE_STRING);
307 self->combobox = gtk_combo_box_new_text();
308 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(self->combobox), 1);
309 gtk_combo_box_set_model(GTK_COMBO_BOX(self->combobox),
310 GTK_TREE_MODEL(self->version_store));
312 theme_table = gtk_table_new(5, 7, TRUE);
313 gtk_table_set_col_spacings(GTK_TABLE(theme_table), 1);
314 gtk_table_set_row_spacings(GTK_TABLE(theme_table), 1);
316 info_vbox = gtk_vbox_new(FALSE, 1);
318 /*create eventbox*/
319 preview_event_box = gtk_event_box_new();
320 self->select_label = gtk_label_new(" Select \ncategory");
322 /* Create frame for theme_info */
323 select_vbox = gtk_vbox_new(FALSE, 2);
324 versions_hbox = gtk_hbox_new(FALSE, 2);
325 theme_info_frame = gtk_frame_new("");
326 gtk_frame_set_label_widget(GTK_FRAME(theme_info_frame),
327 irreco_gtk_label_bold("Info", 0, 0, 0, 0, 0, 0));
328 self->theme_info_alignment = gtk_alignment_new(0, 0, 0, 0);
329 gtk_alignment_set_padding(GTK_ALIGNMENT(self->theme_info_alignment),
330 0, 4, 8, 8);
333 preview_frame = gtk_frame_new(NULL);
334 gtk_frame_set_shadow_type(GTK_FRAME(preview_frame), GTK_SHADOW_OUT);
336 self->theme_image = gtk_image_new();
337 gtk_image_set_from_file(GTK_IMAGE(self->theme_image), NULL);
339 /*Dialog label*/
341 /*label_rate = gtk_label_new(" Rating");*/
342 label_name = gtk_label_new("Name: ");
343 self->label_creator = gtk_label_new("Author: ");
344 self->label_download= gtk_label_new("Downloads: ");
345 label_description = gtk_label_new("Comment: ");
346 self->label_combobox = gtk_label_new("Version:");
348 self->theme_name = gtk_label_new("");
349 self->theme_creator = gtk_label_new("");
350 self->theme_downloaded = gtk_label_new("");
351 self->theme_comment = gtk_label_new("");
352 self->theme_version = gtk_label_new("");
354 comment_alignment = gtk_alignment_new(0, 0, 0, 0);
355 gtk_widget_set_size_request(self->theme_comment,
356 330, -1);
357 gtk_alignment_set_padding(GTK_ALIGNMENT(comment_alignment),
358 0, 0, 20, 0);
359 gtk_label_set_line_wrap(GTK_LABEL(self->theme_comment), TRUE);
360 gtk_label_set_line_wrap_mode(GTK_LABEL(self->theme_comment),
361 PANGO_WRAP_WORD);
363 /*gtk_misc_set_alignment(GTK_MISC(label_rate), 0, 0.5);*/
364 gtk_misc_set_alignment(GTK_MISC(label_name), 0, 0.5);
365 gtk_misc_set_alignment(GTK_MISC(self->label_creator), 0, 0.5);
366 gtk_misc_set_alignment(GTK_MISC(self->label_download), 0, 0.5);
367 gtk_misc_set_alignment(GTK_MISC(label_description), 0, 0.5);
368 gtk_misc_set_alignment(GTK_MISC(self->label_combobox), 0, 0.5);
369 gtk_misc_set_alignment(GTK_MISC(self->theme_name), 0, 0.5);
370 gtk_misc_set_alignment(GTK_MISC(self->theme_creator), 0, 0.5);
371 gtk_misc_set_alignment(GTK_MISC(self->theme_downloaded), 0, 0.5);
372 gtk_misc_set_alignment(GTK_MISC(self->theme_comment), 0, 0.5);
373 gtk_misc_set_alignment(GTK_MISC(self->theme_version), 0, 0.5);
376 /*Attach WidGets to tables*/
378 gtk_table_attach(GTK_TABLE(theme_info), info_scrollbar,
379 0, 4, 4, 7, GTK_FILL, GTK_FILL, 0, 0);
381 gtk_table_attach_defaults(GTK_TABLE(table),
382 tree_view_frame, 0, 3, 0, 7);
383 gtk_table_attach_defaults(GTK_TABLE(theme_info),
384 preview_event_box, 3, 4, 0, 3);
385 /* gtk_table_attach_defaults(GTK_TABLE(self->theme_info),
386 label_rate, 3, 4, 3, 4);*/
387 gtk_table_attach_defaults(GTK_TABLE(theme_info),
388 theme_table, 0, 3, 0, 4);
389 gtk_table_attach_defaults(GTK_TABLE(theme_table),
390 label_name, 0, 3, 0, 1);
391 gtk_table_attach_defaults(GTK_TABLE(theme_table),
392 self->label_creator, 0, 3, 1, 2);
393 gtk_table_attach_defaults(GTK_TABLE(theme_table),
394 self->label_download, 0, 3, 2, 3);
395 gtk_table_attach_defaults(GTK_TABLE(theme_table),
396 label_description, 0, 3, 4, 5);
397 gtk_table_attach_defaults(GTK_TABLE(theme_table),
398 self->label_combobox, 0, 3, 3, 4);
399 gtk_table_attach_defaults(GTK_TABLE(theme_table),
400 versions_hbox, 3, 7, 3, 4);
401 gtk_table_attach_defaults(GTK_TABLE(table),
402 theme_info_frame, 3, 7, 0, 7);
403 gtk_table_attach(GTK_TABLE(theme_table), self->theme_name,
404 3, 7, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
405 gtk_table_attach(GTK_TABLE(theme_table), self->theme_creator,
406 3, 7, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
407 gtk_table_attach(GTK_TABLE(theme_table), self->theme_downloaded,
408 3, 7, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
410 /*Add WidGets*/
412 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
413 info_scrollbar), info_vbox);
414 gtk_container_add(GTK_CONTAINER(preview_frame),
415 self->theme_image);
416 gtk_container_add(GTK_CONTAINER(preview_event_box),
417 preview_frame);
418 gtk_container_add(GTK_CONTAINER(info_vbox), comment_alignment);
419 gtk_container_add(GTK_CONTAINER(comment_alignment),
420 self->theme_comment);
421 gtk_container_add(GTK_CONTAINER(theme_info_frame),
422 GTK_WIDGET(select_vbox));
423 gtk_container_add(GTK_CONTAINER(select_vbox),
424 GTK_WIDGET(self->theme_info_alignment));
425 gtk_container_add(GTK_CONTAINER(select_vbox),
426 GTK_WIDGET(self->select_label));
427 gtk_container_add(GTK_CONTAINER(self->theme_info_alignment),
428 GTK_WIDGET(theme_info));
429 gtk_container_add(GTK_CONTAINER(versions_hbox),
430 GTK_WIDGET(self->theme_version));
431 gtk_container_add(GTK_CONTAINER(versions_hbox),
432 GTK_WIDGET(self->combobox));
434 /*Set font size and style*/
435 /* Font size*/
436 initial_font = pango_font_description_from_string ("Sans Bold 16");
437 gtk_widget_modify_font (self->select_label, initial_font);
439 initial_font = pango_font_description_from_string ("Sans Bold 12");
440 /*gtk_widget_modify_font (label_rate, initial_font);*/
441 gtk_widget_modify_font (label_name, initial_font);
442 gtk_widget_modify_font (self->label_creator, initial_font);
443 gtk_widget_modify_font (self->label_download, initial_font);
444 gtk_widget_modify_font (label_description, initial_font);
445 gtk_widget_modify_font (self->label_combobox, initial_font);
446 /* Font size*/
447 initial_font = pango_font_description_from_string ("Sans 11");
448 gtk_widget_modify_font (self->theme_name, initial_font);
449 gtk_widget_modify_font (self->theme_creator, initial_font);
450 gtk_widget_modify_font (self->theme_downloaded, initial_font);
451 gtk_widget_modify_font (self->theme_comment, initial_font);
452 gtk_widget_modify_font (self->theme_version, initial_font);
453 gtk_widget_modify_font (self->combobox, initial_font);
455 /* Setup the selection handler for TREE */
456 select = gtk_tree_view_get_selection(self->tree_view);
457 gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
459 /* Signal handlers. */
460 g_signal_connect(G_OBJECT(self), "map-event",
461 G_CALLBACK(irreco_theme_manager_dlg_map_event), NULL);
462 g_signal_connect(G_OBJECT(self), "destroy",
463 G_CALLBACK(irreco_theme_manager_dlg_destroy_event), NULL);
464 g_signal_connect(G_OBJECT(self->tree_view), "row-activated",
465 G_CALLBACK(irreco_theme_manager_dlg_row_activated_event),
466 self);
467 g_signal_connect(G_OBJECT(self->tree_view), "row-expanded",
468 G_CALLBACK(irreco_theme_manager_dlg_row_expanded_event),
469 self);
470 g_signal_connect(G_OBJECT(self->tree_view), "row-collapsed",
471 G_CALLBACK(irreco_theme_manager_dlg_row_collapsed_event),
472 self);
473 g_signal_connect(G_OBJECT (select), "changed",
474 G_CALLBACK (irreco_theme_manager_dlg_row_selected_event),
475 self);
476 g_signal_connect(G_OBJECT (self->combobox), "changed",
477 G_CALLBACK (irreco_theme_manager_dlg_selected_version),
478 self);
479 g_signal_connect(G_OBJECT(preview_event_box),
480 "button-release-event",
481 G_CALLBACK(irreco_theme_manager_dlg_preview_dlg),
482 self);
483 g_signal_connect(G_OBJECT(self->clear_button),
484 "clicked",
485 G_CALLBACK(irreco_theme_manager_dlg_delete_theme),
486 self);
488 gtk_tree_view_set_enable_tree_lines(self->tree_view, TRUE);
489 g_object_set (G_OBJECT (self->tree_view), "show-expanders", TRUE, NULL);
490 g_object_set (G_OBJECT (self->tree_view), "level-indentation", 0, NULL);
491 gtk_tree_view_set_rubber_banding(self->tree_view, FALSE);
493 gtk_widget_set_size_request(GTK_WIDGET(self), 696, 396);
494 gtk_widget_show_all(GTK_WIDGET(self));
496 IRRECO_RETURN
499 GtkWidget *irreco_theme_manager_dlg_new(IrrecoData *irreco_data,
500 GtkWindow *parent)
502 IrrecoThemeManagerDlg *self;
504 IRRECO_ENTER
506 self = g_object_new(IRRECO_TYPE_THEME_MANAGER_DLG, NULL);
507 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
508 irreco_theme_manager_dlg_set_irreco_data(self, irreco_data);
510 IRRECO_RETURN_PTR(self);
514 * Show whole preview image
518 gboolean irreco_theme_manager_dlg_preview_dlg(GtkWidget *widget,
519 GdkEventButton *event,
520 IrrecoThemeManagerDlg *self)
522 GtkWidget *image, *event_box;
523 GtkWidget *preview_dialog;
525 IRRECO_ENTER
527 if(self->preview_add != NULL ||
528 self->webdb_theme->preview_button != NULL) {
530 preview_dialog = irreco_dlg_new();
531 gtk_window_set_title(GTK_WINDOW(preview_dialog), _("Preview"));
532 gtk_window_set_modal(GTK_WINDOW(preview_dialog), TRUE);
533 gtk_window_set_destroy_with_parent(GTK_WINDOW(preview_dialog), TRUE);
534 gtk_dialog_set_has_separator(GTK_DIALOG(preview_dialog), FALSE);
536 gtk_widget_set_size_request(preview_dialog, 185, -1);
538 event_box = gtk_event_box_new();
539 image = gtk_image_new();
540 if(self->preview_add != NULL){
541 gtk_image_set_from_file(GTK_IMAGE(image), self->preview_add);
543 }else{
544 gtk_image_set_from_pixbuf(GTK_IMAGE(image),
545 GDK_PIXBUF(self->webdb_theme->preview_button));
548 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(preview_dialog)->vbox),
549 event_box);
550 gtk_container_add(GTK_CONTAINER(event_box), image);
552 g_signal_connect_swapped(G_OBJECT(event_box),
553 "button-release-event",
554 G_CALLBACK(gtk_widget_destroy),
555 preview_dialog);
557 gtk_widget_show_all(GTK_WIDGET(preview_dialog));
559 IRRECO_RETURN_BOOL(TRUE);
563 * Combobox versions
567 static void
568 irreco_theme_manager_dlg_selected_version(GtkComboBox *widget,
569 IrrecoThemeManagerDlg *self)
571 GtkTreeIter iter;
572 gchar *id;
574 IRRECO_ENTER
576 if(!gtk_combo_box_get_active_iter(widget, &iter)) {
577 IRRECO_RETURN
579 gtk_tree_model_get(GTK_TREE_MODEL(self->version_store), &iter,
580 ID_COL, &id, -1);
582 if (self->webdb_theme == NULL || self->webdb_theme->id != atoi(id)) {
583 IRRECO_DEBUG("SELECTED ID: %d\n", atoi(id));
584 self->selected_theme_id = atoi(id);
585 self->loader_func_id = g_idle_add(G_SOURCEFUNC(
586 irreco_theme_manager_dlg_theme_db_detail_loader),
587 self);
590 IRRECO_RETURN
594 * Delete user theme
597 static void irreco_theme_manager_dlg_delete_theme(GtkButton *button,
598 IrrecoThemeManagerDlg *self)
601 const gchar *name = gtk_label_get_label(GTK_LABEL(self->theme_name));
602 GString *message = g_string_new(NULL);
603 IRRECO_ENTER
605 g_string_append_printf(
606 message, _("Are you sure you want to\n "
607 "delete %s theme?"),name);
609 if (irreco_yes_no_dlg(GTK_WINDOW(self), message->str)){
611 irreco_theme_manager_remove_theme(
612 self->irreco_data->theme_manager, name);
613 gtk_button_clicked(GTK_BUTTON(self->refresh_button));
616 g_string_free(message, TRUE);
617 IRRECO_RETURN
621 /** @} */
623 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
624 /* Private Functions */
625 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
628 * @name Private Functions
629 * @{
633 * Clean detail list
636 static void irreco_theme_manager_dlg_clean_details(IrrecoThemeManagerDlg *self)
639 IRRECO_ENTER
641 gtk_widget_show_all(GTK_WIDGET(self));
642 gtk_label_set_text(
643 GTK_LABEL(self->theme_name), "-");
644 gtk_label_set_text(
645 GTK_LABEL(self->theme_creator), "-");
646 gtk_label_set_text(
647 GTK_LABEL(self->theme_comment), "-");
648 gtk_label_set_text(
649 GTK_LABEL(self->theme_downloaded), "-");
650 gtk_image_clear(GTK_IMAGE(self->theme_image));
651 self->preview_add=NULL;
653 gtk_widget_hide(self->upload_button);
654 gtk_widget_hide(self->download_button);
655 gtk_widget_hide(self->clear_button);
656 gtk_widget_hide(self->theme_info_alignment);
657 gtk_widget_show(self->select_label);
660 IRRECO_RETURN
664 * Have the childern of this item been loaded.
666 * @return TRUE if children have been loade, FALSE otherwise.
669 static gboolean
670 irreco_theme_manager_dlg_row_is_loaded(IrrecoThemeManagerDlg *self,
671 GtkTreeIter *iter)
673 gint i;
675 IRRECO_ENTER
677 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
678 iter, FLAG_COL, &i, -1);
679 if (i & ROW_CHILDREN_LOADED) IRRECO_RETURN_BOOL(TRUE);
681 IRRECO_RETURN_BOOL(FALSE);
685 * Get type of row.
688 static gint irreco_theme_manager_dlg_row_get_type(IrrecoThemeManagerDlg *self,
689 GtkTreeIter *iter)
691 gint i;
693 IRRECO_ENTER
695 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
696 iter, FLAG_COL, &i, -1);
697 if (i & ROW_TYPE_CATEGORY)
698 IRRECO_RETURN_ENUM(ROW_TYPE_CATEGORY);
699 if (i & ROW_TYPE_DEB)
700 IRRECO_RETURN_ENUM(ROW_TYPE_DEB);
701 if (i & ROW_TYPE_USER)
702 IRRECO_RETURN_ENUM(ROW_TYPE_USER);
703 if (i & ROW_TYPE_WEB)
704 IRRECO_RETURN_ENUM(ROW_TYPE_WEB);
705 if (i & ROW_TYPE_DB)
706 IRRECO_RETURN_ENUM(ROW_TYPE_DB);
707 if (i & ROW_TYPE_LOADING)
708 IRRECO_RETURN_ENUM(ROW_TYPE_LOADING);
709 IRRECO_RETURN_INT(0);
713 * Show hildon progressbar banner.
715 * This function will create a new banner if one has not been created yet,
716 * if banner already exists, it's properties will be changed.
718 * @param text Text to show.
719 * @param fraction Value of progress.
722 static void irreco_theme_manager_dlg_set_banner(IrrecoThemeManagerDlg *self,
723 const gchar *text,
724 gdouble fraction)
726 IRRECO_ENTER
728 if (self->banner == NULL) {
729 self->banner = hildon_banner_show_progress(
730 GTK_WIDGET(self), NULL, "");
733 hildon_banner_set_text(HILDON_BANNER(self->banner), text);
734 hildon_banner_set_fraction(HILDON_BANNER(self->banner), fraction);
736 IRRECO_RETURN
740 * Destroy banner, if it exists.
743 static void irreco_theme_manager_dlg_hide_banner(IrrecoThemeManagerDlg *self)
745 IRRECO_ENTER
747 if (self->banner) {
748 gtk_widget_destroy(self->banner);
749 self->banner = NULL;
752 IRRECO_RETURN
756 * Start a loader state machine if one is not running already.
759 static
760 gboolean irreco_theme_manager_dlg_loader_start(IrrecoThemeManagerDlg *self,
761 GSourceFunc function,
762 GtkTreeIter *parent_iter)
764 IRRECO_ENTER
766 if (self->loader_func_id == 0) {
767 if (parent_iter) {
768 self->loader_parent_iter = gtk_tree_iter_copy(
769 parent_iter);
771 if (function) {
772 self->loader_func_id = g_idle_add(function, self);
773 } else {
774 IRRECO_ERROR("Loader function pointer not given.\n");
777 IRRECO_RETURN_BOOL(TRUE);
782 * Stop and cleanup loader if a loader is running.
785 static void irreco_theme_manager_dlg_loader_stop(IrrecoThemeManagerDlg *self)
787 IRRECO_ENTER
789 if (self->loader_func_id != 0) {
790 g_source_remove(self->loader_func_id);
791 self->loader_func_id = 0;
792 self->loader_state = 0;
793 if (self->loader_parent_iter) {
794 gtk_tree_iter_free(self->loader_parent_iter);
796 self->loader_parent_iter = NULL;
798 IRRECO_RETURN
801 static gboolean
802 irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg *self)
804 IRRECO_ENTER
806 switch (self->loader_state) {
807 case LOADER_STATE_INIT: {
808 GtkTreeIter iter;
809 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
810 0.5);
811 self->loader_state = LOADER_STATE_LOOP;
812 irreco_theme_manager_dlg_clean_details(self);
813 if (!irreco_theme_manager_does_user_exist(
814 self->irreco_data->theme_manager)) {
815 self->loader_state = LOADER_STATE_END;
816 self->loader_iter = NULL;
817 } else {
820 gtk_tree_store_append(self->tree_store,
821 &iter, NULL);
822 gtk_tree_store_set(self->tree_store,
823 &iter,
824 TEXT_COL, _("My Themes"),
825 FLAG_COL, ROW_TYPE_CATEGORY,
826 DATA_COL, NULL, -1);
828 self->loader_iter = gtk_tree_iter_copy(&iter);
831 IRRECO_RETURN_BOOL(TRUE);
835 case LOADER_STATE_LOOP: {
837 IrrecoData *irreco_data = NULL;
838 IrrecoThemeManager *theme_manager = NULL;
839 GtkTreeIter iter;
840 IrrecoStringTable *categories = NULL;
843 irreco_data = self->irreco_data;
844 theme_manager = irreco_data->theme_manager;
845 categories = irreco_theme_manager_get_themes(theme_manager);
847 IRRECO_STRING_TABLE_FOREACH_DATA(categories,
848 IrrecoTheme *, theme)
850 if (g_utf8_collate(theme->source->str, "user") == 0){
852 /* Add loading item into category. */
853 gtk_tree_store_append(self->tree_store,
854 &iter,
855 self->loader_iter);
856 gtk_tree_store_set(self->tree_store,
857 &iter,
858 TEXT_COL,
859 theme->name->str,
860 FLAG_COL,
861 ROW_TYPE_USER,
862 DATA_COL, NULL, -1);
864 IRRECO_STRING_TABLE_FOREACH_END
866 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
867 1.0);
868 self->loader_state = LOADER_STATE_END;
869 IRRECO_RETURN_BOOL(TRUE);
872 case LOADER_STATE_END:
873 if (self->loader_iter != NULL) {
874 gtk_tree_iter_free(self->loader_iter);
876 irreco_theme_manager_dlg_hide_banner(self);
877 irreco_theme_manager_dlg_loader_stop(self);
879 irreco_theme_manager_dlg_loader_start(self,
880 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_deb),NULL);
883 IRRECO_RETURN_BOOL(FALSE);
887 * Category loader.
889 * This loader will request a list of categories from the theme and
890 * update the TreeView accordingly. Every category row created by this loader
891 * will have row type ROW_TYPE_DEB.
895 static gboolean irreco_theme_manager_dlg_loader_deb(IrrecoThemeManagerDlg *self)
897 IRRECO_ENTER
899 switch (self->loader_state) {
900 case LOADER_STATE_INIT: {
901 GtkTreeIter iter;
902 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
903 0.5);
904 self->loader_state = LOADER_STATE_LOOP;
905 irreco_theme_manager_dlg_clean_details(self);
907 if (!irreco_theme_manager_does_deb_exist(
908 self->irreco_data->theme_manager)) {
909 self->loader_state = LOADER_STATE_END;
910 self->loader_iter = NULL;
911 } else {
913 gtk_tree_store_append(self->tree_store,
914 &iter, NULL);
915 gtk_tree_store_set(self->tree_store,
916 &iter,
917 TEXT_COL, _("Built In"),
918 FLAG_COL, ROW_TYPE_CATEGORY,
919 DATA_COL, NULL, -1);
921 self->loader_iter = gtk_tree_iter_copy(&iter);
923 IRRECO_RETURN_BOOL(TRUE);
927 case LOADER_STATE_LOOP: {
929 IrrecoData *irreco_data = NULL;
930 IrrecoThemeManager *theme_manager = NULL;
931 GtkTreeIter iter;
932 IrrecoStringTable *categories = NULL;
934 irreco_data = self->irreco_data;
935 theme_manager = irreco_data->theme_manager;
936 categories = irreco_theme_manager_get_themes(theme_manager);
938 IRRECO_STRING_TABLE_FOREACH_DATA(categories,
939 IrrecoTheme *, theme)
940 if (g_utf8_collate(theme->source->str, "deb") == 0){
942 /* Add loading item into category. */
943 gtk_tree_store_append(self->tree_store,
944 &iter, self->loader_iter);
945 gtk_tree_store_set(self->tree_store,
946 &iter,
947 TEXT_COL,
948 theme->name->str,
949 FLAG_COL, ROW_TYPE_DEB,
950 DATA_COL, NULL, -1);
952 IRRECO_STRING_TABLE_FOREACH_END
954 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
955 1.0);
956 self->loader_state = LOADER_STATE_END;
957 IRRECO_RETURN_BOOL(TRUE);
960 case LOADER_STATE_END: {
961 GtkTreeIter iter, iter_loading;
962 if (self->loader_iter != NULL) {
963 gtk_tree_iter_free(self->loader_iter);
965 irreco_theme_manager_dlg_hide_banner(self);
966 irreco_theme_manager_dlg_loader_stop(self);
968 /* Create database row */
969 gtk_tree_store_append(self->tree_store, &iter, NULL);
970 gtk_tree_store_set(self->tree_store, &iter,
971 TEXT_COL, _("Database"),
972 FLAG_COL, ROW_TYPE_CATEGORY,
973 DATA_COL, NULL, -1);
975 /* Add loading item into manufacturer. */
976 gtk_tree_store_append(self->tree_store, &iter_loading, &iter);
977 gtk_tree_store_set(self->tree_store, &iter_loading,
978 TEXT_COL, _("Loading ..."),
979 FLAG_COL, ROW_TYPE_LOADING,
980 DATA_COL, NULL, -1);
982 irreco_theme_manager_dlg_loader_start(self,
983 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_web), NULL);
987 IRRECO_RETURN_BOOL(FALSE);
990 static gboolean irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg *self)
992 IRRECO_ENTER
994 switch (self->loader_state) {
995 case LOADER_STATE_INIT:{
996 GtkTreeIter iter;
997 irreco_theme_manager_dlg_set_banner(self, _("Loading themes"),
998 0.0);
999 self->loader_state = LOADER_STATE_LOOP;
1000 self->theme_loader_index = 0;
1001 irreco_theme_manager_dlg_clean_details(self);
1003 /* Check if loading item exist */
1004 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self->tree_store),
1005 &iter, self->loader_iter, 0);
1007 if(irreco_theme_manager_dlg_row_get_type(self,
1008 &iter) != ROW_TYPE_LOADING) {
1009 self->loader_state = LOADER_STATE_END;
1012 IRRECO_RETURN_BOOL(TRUE);
1016 case LOADER_STATE_LOOP: {
1017 GtkTreeIter iter;
1018 GtkTreeIter iter_loading;
1019 IrrecoStringTable *themes = NULL;
1020 IrrecoWebdbTheme *theme_by_id;
1021 IrrecoWebdbCache *webdb_cache = NULL;
1022 const gchar *id;
1023 gfloat banner;
1025 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data,
1026 FALSE);
1027 /* Get themes */
1028 if (!irreco_webdb_cache_get_themes(webdb_cache, &themes)) {
1029 irreco_error_dlg(GTK_WINDOW(self),
1030 irreco_webdb_cache_get_error(
1031 webdb_cache));
1032 self->loader_state = LOADER_STATE_END;
1033 IRRECO_RETURN_BOOL(TRUE);
1036 if (!irreco_string_table_index(themes,
1037 (guint)self->theme_loader_index, &id, NULL)) {
1038 irreco_error_dlg(GTK_WINDOW(self), "Can't find theme");
1039 self->loader_state = LOADER_STATE_END;
1040 IRRECO_RETURN_BOOL(TRUE);
1043 if (!irreco_webdb_cache_get_theme_by_id(webdb_cache,
1044 atoi(id),
1045 &theme_by_id)) {
1046 irreco_error_dlg(GTK_WINDOW(self),
1047 irreco_webdb_cache_get_error(
1048 webdb_cache));
1049 self->loader_state = LOADER_STATE_END;
1050 IRRECO_RETURN_BOOL(TRUE);
1053 gtk_tree_store_append(self->tree_store, &iter,
1054 self->loader_iter);
1056 gtk_tree_store_set(self->tree_store, &iter,
1057 TEXT_COL, theme_by_id->name->str,
1058 FLAG_COL, ROW_TYPE_DB,
1059 DATA_COL, id, -1);
1061 banner = ++self->theme_loader_index;
1062 banner /= (gfloat) irreco_string_table_lenght (themes);
1064 irreco_theme_manager_dlg_set_banner(self, _("Loading themes"),
1065 banner);
1066 if (banner >= 1.0) {
1067 self->loader_state = LOADER_STATE_END;
1070 /* Delete loading item */
1071 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(self->tree_store),
1072 &iter_loading, self->loader_iter,
1074 if(irreco_theme_manager_dlg_row_get_type(self,
1075 &iter_loading) == ROW_TYPE_LOADING) {
1076 gtk_tree_store_remove(self->tree_store, &iter_loading);
1079 IRRECO_RETURN_BOOL(TRUE);
1082 case LOADER_STATE_END:
1083 if (self->loader_iter != NULL) {
1084 gtk_tree_iter_free(self->loader_iter);
1086 irreco_theme_manager_dlg_hide_banner(self);
1087 irreco_theme_manager_dlg_loader_stop(self);
1090 IRRECO_RETURN_BOOL(FALSE);
1094 static gboolean irreco_theme_manager_dlg_loader_web(IrrecoThemeManagerDlg *self)
1096 IRRECO_ENTER
1098 switch (self->loader_state) {
1099 case LOADER_STATE_INIT: {
1100 GtkTreeIter iter;
1101 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
1102 0.5);
1103 self->loader_state = LOADER_STATE_LOOP;
1104 irreco_theme_manager_dlg_clean_details(self);
1105 if (!irreco_theme_manager_does_web_exist(
1106 self->irreco_data->theme_manager)) {
1107 self->loader_state = LOADER_STATE_END;
1108 self->loader_iter = NULL;
1109 } else {
1111 gtk_tree_store_append(self->tree_store,
1112 &iter, NULL);
1113 gtk_tree_store_set(self->tree_store,
1114 &iter,
1115 TEXT_COL, _("Downloaded"),
1116 FLAG_COL, ROW_TYPE_CATEGORY,
1117 DATA_COL, NULL, -1);
1119 self->loader_iter = gtk_tree_iter_copy(&iter);
1121 IRRECO_RETURN_BOOL(TRUE);
1123 case LOADER_STATE_LOOP: {
1125 IrrecoData *irreco_data = NULL;
1126 IrrecoThemeManager *theme_manager = NULL;
1127 GtkTreeIter iter;
1128 IrrecoStringTable *categories = NULL;
1130 irreco_data = self->irreco_data;
1131 theme_manager = irreco_data->theme_manager;
1132 categories = irreco_theme_manager_get_themes(theme_manager);
1134 IRRECO_STRING_TABLE_FOREACH_DATA(categories,
1135 IrrecoTheme *, theme)
1137 if (g_utf8_collate(theme->source->str, "web") == 0){
1139 /* Add loading item into category. */
1140 gtk_tree_store_append(self->tree_store,
1141 &iter,
1142 self->loader_iter);
1143 gtk_tree_store_set(self->tree_store,
1144 &iter,
1145 TEXT_COL,
1146 theme->name->str,
1147 FLAG_COL,
1148 ROW_TYPE_WEB,
1149 DATA_COL, NULL, -1);
1151 IRRECO_STRING_TABLE_FOREACH_END
1153 irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
1154 1.0);
1155 self->loader_state = LOADER_STATE_END;
1156 IRRECO_RETURN_BOOL(TRUE);
1159 case LOADER_STATE_END:
1160 if (self->loader_iter != NULL) {
1161 gtk_tree_iter_free(self->loader_iter);
1163 irreco_theme_manager_dlg_hide_banner(self);
1164 irreco_theme_manager_dlg_loader_stop(self);
1167 IRRECO_RETURN_BOOL(FALSE);
1171 * Show theme details
1173 * @todo
1176 static gboolean
1177 irreco_theme_manager_dlg_display_theme_detail(IrrecoThemeManagerDlg *self,
1178 GtkTreeIter * iter)
1180 IrrecoThemeManager *theme_manager = self->irreco_data->theme_manager;
1181 IrrecoThemeButton *button = NULL;
1182 const gchar *theme_name;
1184 IRRECO_ENTER
1186 gtk_image_clear(GTK_IMAGE(self->theme_image));
1188 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1189 iter, TEXT_COL, &theme_name, -1);
1190 irreco_string_table_get(theme_manager->themes, theme_name,
1191 (gpointer *) &self->theme);
1193 gtk_label_set_text(GTK_LABEL(self->theme_name),
1194 self->theme->name->str);
1195 gtk_label_set_text(GTK_LABEL(self->theme_creator),
1196 self->theme->author->str);
1197 gtk_label_set_text(GTK_LABEL(self->theme_comment),
1198 self->theme->comment->str);
1199 gtk_label_set_text(GTK_LABEL(self->theme_version),
1200 self->theme->version->str);
1202 if (self->theme->preview_button_name->len > 0) {
1203 button =irreco_theme_get_button(self->theme,
1204 self->theme->preview_button_name->str);
1205 } else {
1206 const gchar *key;
1207 irreco_string_table_index(self->theme->buttons,
1208 0, &key, (gpointer *) &button);
1211 if (button != NULL) {
1212 IRRECO_DEBUG("Preview-button: %s\n", button->image_up->str);
1214 gtk_image_set_from_file(GTK_IMAGE(self->theme_image),
1215 button->image_up->str);
1217 self->preview_add = button->image_up->str;
1218 } else {
1219 self->preview_add = NULL;
1221 self->webdb_theme = NULL;
1223 IRRECO_RETURN_BOOL(TRUE);
1226 static gboolean
1227 irreco_theme_manager_dlg_theme_db_detail_loader(IrrecoThemeManagerDlg *self)
1229 IRRECO_ENTER
1231 switch (self->loader_state) {
1232 case LOADER_STATE_INIT:{
1233 irreco_theme_manager_dlg_set_banner(self,
1234 _("Loading ..."), 0.5);
1235 self->loader_state = LOADER_STATE_LOOP;
1236 IRRECO_RETURN_BOOL(TRUE);
1239 case LOADER_STATE_LOOP: {
1240 gchar *download_count;
1241 gint index = 0;
1242 IrrecoWebdbCache *webdb_cache = irreco_data_get_webdb_cache(
1243 self->irreco_data,
1244 FALSE);
1246 /* Get WebdbTheme with preview-button */
1247 if (!irreco_webdb_cache_get_preview_button(webdb_cache,
1248 self->selected_theme_id,
1249 &self->webdb_theme)) {
1250 irreco_error_dlg(GTK_WINDOW(self),
1251 irreco_webdb_cache_get_error(
1252 webdb_cache));
1254 self->loader_state = LOADER_STATE_END;
1255 IRRECO_RETURN_BOOL(TRUE);
1258 gtk_image_clear(GTK_IMAGE(self->theme_image));
1260 gtk_label_set_text(GTK_LABEL(self->theme_name),
1261 self->webdb_theme->name->str);
1262 gtk_label_set_text(GTK_LABEL(self->theme_creator),
1263 self->webdb_theme->creator->str);
1264 gtk_label_set_text(GTK_LABEL(self->theme_comment),
1265 self->webdb_theme->comment->str);
1267 /* Clear combobox */
1268 gtk_tree_store_clear(self->version_store);
1270 IRRECO_STRING_TABLE_FOREACH(self->webdb_theme->versions,
1271 key, gchar *, date)
1272 GtkTreeIter iter;
1274 /* Append row */
1275 gtk_tree_store_append(self->version_store,
1276 &iter, NULL);
1278 /* Fill row */
1279 gtk_tree_store_set(self->version_store, &iter,
1280 DATE_COL, date,
1281 ID_COL, key, -1);
1283 if (g_utf8_collate (date,
1284 self->webdb_theme->uploaded->str) == 0) {
1285 gtk_combo_box_set_active(GTK_COMBO_BOX(
1286 self->combobox),
1287 index);
1289 index++;
1290 IRRECO_STRING_TABLE_FOREACH_END
1292 /*scale_combobox(self);*/
1294 download_count = g_strdup_printf("%d",
1295 self->webdb_theme->download_count);
1297 gtk_label_set_text(GTK_LABEL(self->theme_downloaded),
1298 download_count);
1299 g_free(download_count);
1301 if (self->webdb_theme->preview_button != NULL) {
1302 gtk_image_set_from_pixbuf(GTK_IMAGE(self->theme_image),
1303 self->webdb_theme->preview_button);
1304 } else {
1305 IRRECO_DEBUG("preview_button is NULL\n");
1307 self->preview_add = NULL;
1309 self->loader_state = LOADER_STATE_END;
1310 IRRECO_RETURN_BOOL(TRUE);
1313 case LOADER_STATE_END:
1314 irreco_theme_manager_dlg_hide_banner(self);
1315 irreco_theme_manager_dlg_loader_stop(self);
1317 IRRECO_RETURN_BOOL(FALSE);
1321 /** @} */
1325 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1326 /* Functions */
1327 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1330 * @name Public Functions
1331 * @{
1334 void irreco_theme_manager_dlg_set_irreco_data(IrrecoThemeManagerDlg *self,
1335 IrrecoData *irreco_data)
1337 IRRECO_ENTER
1339 self->irreco_data = irreco_data;
1341 IRRECO_RETURN
1344 void irreco_show_theme_manager_dlg(IrrecoData *irreco_data, GtkWindow *parent)
1346 IrrecoThemeManagerDlg *self;
1347 gint response;
1348 gboolean loop = TRUE;
1349 gboolean refresh = FALSE;
1350 IrrecoWebdbCache *webdb_cache = NULL;
1352 IRRECO_ENTER
1354 self = IRRECO_THEME_MANAGER_DLG(irreco_theme_manager_dlg_new(
1355 irreco_data, parent));
1357 webdb_cache = irreco_data_get_webdb_cache(self->irreco_data, FALSE);
1359 do {
1360 if (refresh) {
1361 response = IRRECO_DEVICE_REFRESH;
1362 refresh = FALSE;
1364 else {
1365 response = gtk_dialog_run(GTK_DIALOG(self));
1368 switch (response) {
1369 case IRRECO_DOWNLOAD_THEME:
1370 if (irreco_theme_download_dlg_run(
1371 self->irreco_data,
1372 self->selected_theme_id,
1373 GTK_WINDOW(self))) {
1374 refresh = TRUE;
1376 break;
1378 case IRRECO_UPLOAD_THEME:
1379 if (irreco_theme_upload_dlg_run(GTK_WINDOW(self),
1380 self->irreco_data,
1381 self->theme)) {
1382 refresh = TRUE;
1384 break;
1386 case IRRECO_DEVICE_REFRESH:
1387 if (self->loader_func_id != 0) {
1388 break;
1390 IRRECO_DEBUG("IRRECO_DEVICE_REFRESH\n");
1391 gtk_tree_store_clear(self->tree_store);
1392 irreco_theme_manager_update_theme_manager
1393 (self->irreco_data->theme_manager);
1395 if (webdb_cache->theme_id_hash != NULL) {
1396 g_hash_table_remove_all(
1397 webdb_cache->theme_id_hash);
1398 self->webdb_theme = NULL;
1401 IRRECO_STRING_TABLE_FOREACH_DATA(
1402 irreco_data->theme_manager->themes,
1403 IrrecoTheme *, theme)
1404 irreco_theme_check(theme);
1405 IRRECO_STRING_TABLE_FOREACH_END
1407 irreco_theme_manager_dlg_loader_start(self,
1408 G_SOURCEFUNC(
1409 irreco_theme_manager_dlg_loader_user),
1410 NULL);
1411 gtk_label_set_text(GTK_LABEL(self->select_label),
1412 " Select \ncategory");
1413 break;
1415 case GTK_RESPONSE_CANCEL:
1416 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
1417 loop = FALSE;
1418 break;
1420 } while (loop);
1422 gtk_widget_destroy(GTK_WIDGET(self));
1424 IRRECO_RETURN
1427 /** @} */
1431 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1432 /* Events and Callbacks */
1433 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1436 * @name Events and Callbacks
1437 * @{
1440 static gboolean
1441 irreco_theme_manager_dlg_map_event(IrrecoThemeManagerDlg *self,
1442 GdkEvent *event,
1443 gpointer user_data)
1446 IRRECO_ENTER
1448 irreco_theme_manager_dlg_loader_start(
1449 self, G_SOURCEFUNC(irreco_theme_manager_dlg_loader_user),
1450 NULL);
1452 IRRECO_RETURN_BOOL(FALSE);
1455 static void
1456 irreco_theme_manager_dlg_destroy_event(IrrecoThemeManagerDlg *self,
1457 gpointer user_data)
1459 IRRECO_ENTER
1460 irreco_theme_manager_dlg_loader_stop(self);
1461 IRRECO_RETURN
1464 static void
1465 irreco_theme_manager_dlg_row_activated_event(GtkTreeView *tree_view,
1466 GtkTreePath *path,
1467 GtkTreeViewColumn *column,
1468 IrrecoThemeManagerDlg *self)
1470 IRRECO_ENTER
1472 if (gtk_tree_view_row_expanded(tree_view, path)) {
1473 gtk_tree_view_expand_row(tree_view, path, FALSE);
1474 } else {
1475 gtk_tree_view_collapse_row(tree_view, path);
1477 IRRECO_RETURN
1480 static void
1481 irreco_theme_manager_dlg_row_expanded_event(GtkTreeView *tree_view,
1482 GtkTreeIter *iter,
1483 GtkTreePath *path,
1484 IrrecoThemeManagerDlg *self)
1486 gchar *row_name = NULL;
1487 IRRECO_ENTER
1489 irreco_theme_manager_dlg_clean_details(self);
1490 gtk_label_set_text(GTK_LABEL(self->select_label), "Select \ntheme");
1492 if (self->loader_func_id != 0) {
1493 gtk_tree_view_collapse_row(tree_view, path);
1496 if (!irreco_theme_manager_dlg_row_is_loaded(self, iter)){
1497 switch (irreco_theme_manager_dlg_row_get_type(self, iter)){
1498 case ROW_TYPE_CATEGORY:
1499 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1500 iter, TEXT_COL, &row_name, -1);
1502 if(g_utf8_collate(row_name, "Database") != 0) {
1503 goto end;
1506 self->loader_iter = gtk_tree_iter_copy(iter);
1507 irreco_theme_manager_dlg_loader_start(self,
1508 G_SOURCEFUNC(irreco_theme_manager_dlg_loader_db), NULL);
1509 break;
1512 end:
1513 if (row_name != NULL) g_free(row_name);
1514 IRRECO_RETURN
1517 static void
1518 irreco_theme_manager_dlg_row_collapsed_event(GtkTreeView *tree_view,
1519 GtkTreeIter *iter,
1520 GtkTreePath *path,
1521 IrrecoThemeManagerDlg *self)
1524 IRRECO_ENTER
1526 gtk_label_set_text(GTK_LABEL(self->select_label), " Select\ncategory");
1528 irreco_theme_manager_dlg_clean_details(self);
1530 IRRECO_RETURN
1533 static void
1534 irreco_theme_manager_dlg_row_selected_event(GtkTreeSelection *sel,
1535 IrrecoThemeManagerDlg *self)
1537 GtkTreeIter iter;
1538 GtkTreeModel *model;
1539 const char *id;
1541 IRRECO_ENTER
1543 if (gtk_tree_selection_get_selected (sel, &model, &iter))
1545 switch (irreco_theme_manager_dlg_row_get_type(self, &iter)) {
1547 case ROW_TYPE_DEB:
1548 IRRECO_DEBUG("ROW_TYPE_DEB\n");
1550 gtk_widget_hide(self->select_label);
1551 gtk_widget_show(self->theme_info_alignment);
1552 gtk_widget_hide(self->label_download);
1553 gtk_widget_hide(self->theme_downloaded);
1554 gtk_widget_hide(self->label_combobox);
1555 gtk_widget_hide(self->combobox);
1556 gtk_widget_hide(self->theme_version);
1557 gtk_widget_hide(self->theme_creator);
1558 gtk_widget_hide(self->label_creator);
1560 gtk_widget_hide(self->upload_button);
1561 gtk_widget_hide(self->download_button);
1562 gtk_widget_hide(self->clear_button);
1564 irreco_theme_manager_dlg_display_theme_detail(self,
1565 &iter);
1567 break;
1568 case ROW_TYPE_USER:
1569 IRRECO_DEBUG("ROW_TYPE_USER\n");
1571 gtk_widget_hide(self->select_label);
1572 gtk_widget_show(self->theme_info_alignment);
1573 gtk_widget_hide(self->label_download);
1574 gtk_widget_hide(self->theme_downloaded);
1575 gtk_widget_show(self->theme_creator);
1576 gtk_widget_show(self->label_creator);
1578 gtk_widget_show(self->label_combobox);
1579 gtk_widget_hide(self->combobox);
1580 gtk_widget_show(self->theme_version);
1582 gtk_widget_show(self->upload_button);
1583 gtk_widget_show(self->clear_button);
1584 gtk_widget_hide(self->download_button);
1586 irreco_theme_manager_dlg_display_theme_detail(self,
1587 &iter);
1589 break;
1590 case ROW_TYPE_WEB:
1591 IRRECO_DEBUG("ROW_TYPE_WEB\n");
1593 gtk_widget_show(self->clear_button);
1594 gtk_widget_hide(self->upload_button);
1595 gtk_widget_hide(self->download_button);
1597 gtk_widget_hide(self->select_label);
1598 gtk_widget_show(self->theme_creator);
1599 gtk_widget_show(self->label_creator);
1600 gtk_widget_hide(self->label_download);
1601 gtk_widget_hide(self->theme_downloaded);
1603 gtk_widget_hide(self->combobox);
1604 gtk_widget_show(self->label_combobox);
1605 gtk_widget_show(self->theme_version);
1607 gtk_widget_show(self->theme_info_alignment);
1609 irreco_theme_manager_dlg_display_theme_detail(self,
1610 &iter);
1612 break;
1613 case ROW_TYPE_DB:
1614 IRRECO_DEBUG("ROW_TYPE_DB\n");
1616 if (self->loader_func_id != 0) {
1617 break;
1620 gtk_tree_model_get(GTK_TREE_MODEL(self->tree_store),
1621 &iter, DATA_COL, &id, -1);
1623 gtk_widget_hide(self->clear_button);
1624 gtk_widget_hide(self->upload_button);
1625 gtk_widget_show(self->download_button);
1627 gtk_widget_show(self->combobox);
1628 gtk_widget_show(self->label_combobox);
1629 gtk_widget_hide(self->theme_version);
1631 gtk_widget_hide(self->select_label);
1632 gtk_widget_show(self->theme_creator);
1633 gtk_widget_show(self->label_creator);
1634 gtk_widget_show(self->label_download);
1635 gtk_widget_show(self->theme_downloaded);
1637 gtk_widget_show(self->theme_info_alignment);
1639 IRRECO_DEBUG("SELECTED ID: %d\n", atoi(id));
1641 self->selected_theme_id = atoi(id);
1642 self->loader_func_id = g_idle_add(G_SOURCEFUNC(
1643 irreco_theme_manager_dlg_theme_db_detail_loader),
1644 self);
1646 break;
1647 default:
1648 irreco_theme_manager_dlg_clean_details(self);
1649 break;
1653 IRRECO_RETURN
1655 /** @} */
1656 /** @} */