2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
4 * 2008 Joni Kokko (t5kojo01@students.oamk.fi)
5 * 2008 Harri Vattulainen (t5vaha01@students.oamk.fi)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "irreco_theme_upload_dlg.h"
23 #include "irreco_button_browser_dlg.h"
24 #include <hildon/hildon-banner.h>
28 * @addtogroup IrrecoThemeUploadDlg
31 * Allow user to set theme settings and upload it.
38 * Source file of @ref IrrecoThemeUploadDlg.
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
47 #define IRRECO_THEME_UPLOAD_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 6)
48 #define IRRECO_THEME_UPLOAD_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 6)
56 LOADER_STATE_BACKGROUNDS
,
60 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
62 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
63 static gboolean
_texts_ok(IrrecoThemeUploadDlg
*self
);
64 static gboolean
_send_theme(IrrecoThemeUploadDlg
*self
);
65 static void _update_preview(IrrecoThemeUploadDlg
*self
);
66 static void _run_button_browser_dlg(GtkWidget
*widget
,
67 GdkEventButton
*event
,
68 IrrecoThemeUploadDlg
*self
);
69 static gboolean
_get_image_data_and_hash(gchar
* img_path
,
75 static void _hide_banner(IrrecoThemeUploadDlg
*self
);
76 static void _set_banner(IrrecoThemeUploadDlg
*self
,
79 static void _loader_start(IrrecoThemeUploadDlg
*self
);
80 static void _loader_stop(IrrecoThemeUploadDlg
*self
);
82 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
83 /* Construction & Destruction */
84 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
87 * @name Construction & Destruction
91 G_DEFINE_TYPE(IrrecoThemeUploadDlg
, irreco_theme_upload_dlg
,
92 IRRECO_TYPE_INTERNAL_DLG
)
94 static void irreco_theme_upload_dlg_constructed(GObject
*object
)
96 IrrecoThemeUploadDlg
*self
;
99 GtkWidget
*vbox_preview
;
100 GtkWidget
*label_name
;
101 GtkWidget
*label_comments
;
102 GtkWidget
*label_preview
;
103 GtkWidget
*scrolled_comments
;
105 GtkWidget
*frame_comments
;
106 GtkWidget
*frame_preview
;
110 G_OBJECT_CLASS(irreco_theme_upload_dlg_parent_class
)->constructed(object
);
111 self
= IRRECO_THEME_UPLOAD_DLG(object
);
113 self
->comments
= NULL
;
115 /* Construct dialog. */
116 gtk_window_set_title(GTK_WINDOW(self
), _("Upload theme"));
117 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
118 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
119 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
120 gtk_dialog_add_buttons(GTK_DIALOG(self
),
121 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
122 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
125 /* Create widgets. */
126 hbox_lr
= gtk_hbox_new(FALSE
, 10);
127 vbox_preview
= gtk_vbox_new(FALSE
, 0);
128 label_name
= gtk_label_new("Theme name:");
129 label_comments
= gtk_label_new("Comments: ");
130 label_preview
= gtk_label_new("Select\npreview image:");
131 self
->entry_name
= gtk_entry_new();
132 gtk_editable_set_editable(GTK_EDITABLE(self
->entry_name
), FALSE
);
133 self
->textview_comments
= gtk_text_view_new();
134 frame_comments
= gtk_frame_new(NULL
);
137 self
->preview_image
= gtk_image_new();
138 gtk_image_set_from_file(GTK_IMAGE(self
->preview_image
), NULL
);
139 frame_preview
= gtk_frame_new(NULL
);
140 self
->preview_event_box
= gtk_event_box_new();
141 gtk_container_add(GTK_CONTAINER(frame_preview
), self
->preview_image
);
142 gtk_container_add(GTK_CONTAINER(self
->preview_event_box
), frame_preview
);
143 gtk_widget_set_size_request(frame_preview
, 200,200);
146 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self
->textview_comments
),
148 gtk_widget_set_size_request(self
->textview_comments
, 400, 150);
149 scrolled_comments
= gtk_scrolled_window_new(NULL
, NULL
);
150 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_comments
),
152 GTK_POLICY_AUTOMATIC
);
153 table
= gtk_table_new(4, 2, FALSE
);
156 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
),
158 gtk_box_pack_start_defaults(GTK_BOX(hbox_lr
), table
);
159 gtk_box_pack_end_defaults(GTK_BOX(hbox_lr
), vbox_preview
);
160 gtk_box_pack_start_defaults(GTK_BOX(vbox_preview
), label_preview
);
161 gtk_box_pack_end_defaults(GTK_BOX(vbox_preview
),
162 self
->preview_event_box
);
163 gtk_container_add(GTK_CONTAINER(scrolled_comments
),
164 self
->textview_comments
);
165 gtk_container_add(GTK_CONTAINER (frame_comments
),
167 gtk_table_attach_defaults(GTK_TABLE(table
),
168 label_name
, 0, 1, 0, 1);
169 gtk_table_attach_defaults(GTK_TABLE(table
),
170 self
->entry_name
, 1, 2, 0, 1);
171 gtk_table_attach_defaults(GTK_TABLE(table
),
172 label_comments
, 0, 1, 1, 2);
173 /*gtk_table_attach_defaults(GTK_TABLE(table),
174 frame_comments, 0, 2, 2, 3);*/
175 gtk_table_attach(GTK_TABLE(table
),
178 GTK_EXPAND
, GTK_EXPAND
,
180 gtk_container_set_border_width (GTK_CONTAINER (self
), 5);
182 /* Connect preview eventbox and start dialog from there */
183 g_signal_connect(G_OBJECT(self
->preview_event_box
),
184 "button-release-event",
185 G_CALLBACK(_run_button_browser_dlg
),
186 IRRECO_THEME_UPLOAD_DLG(self
));
188 gtk_widget_show_all(GTK_WIDGET(self
));
192 static void irreco_theme_upload_dlg_init(IrrecoThemeUploadDlg
*self
)
198 static void irreco_theme_upload_dlg_finalize(GObject
*object
)
200 IrrecoThemeUploadDlg
*self
;
203 self
= IRRECO_THEME_UPLOAD_DLG(object
);
205 G_OBJECT_CLASS(irreco_theme_upload_dlg_parent_class
)->finalize(object
);
209 static void irreco_theme_upload_dlg_class_init(IrrecoThemeUploadDlgClass
*klass
)
211 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
212 /* IrrecoDlgClass* parent_class = IRRECO_DLG_CLASS (klass); */
214 object_class
->finalize
= irreco_theme_upload_dlg_finalize
;
215 object_class
->constructed
= irreco_theme_upload_dlg_constructed
;
218 GtkWidget
*irreco_theme_upload_dlg_new(IrrecoData
*irreco_data
,
219 GtkWindow
*parent_window
)
221 IrrecoThemeUploadDlg
*self
;
224 self
= g_object_new(IRRECO_TYPE_THEME_UPLOAD_DLG
,
225 "irreco-data", irreco_data
,
227 irreco_dlg_set_parent(IRRECO_DLG(self
), parent_window
);
228 IRRECO_RETURN_PTR(self
);
234 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
235 /* Private Functions */
236 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
238 * @name Private Functions
243 * Show hildon progressbar banner.
245 * This function will create a new banner if one has not been created yet,
246 * if banner already exists, it's properties will be changed.
248 * @param text Text to show.
249 * @param fraction Value of progress.
251 static void _set_banner(IrrecoThemeUploadDlg
*self
,
257 if (self
->banner
== NULL
) {
258 self
->banner
= hildon_banner_show_progress(
259 GTK_WIDGET(self
), NULL
, "");
262 hildon_banner_set_text(HILDON_BANNER(self
->banner
), text
);
263 hildon_banner_set_fraction(HILDON_BANNER(self
->banner
), fraction
);
269 * Destroy banner, if it exists.
271 static void _hide_banner(IrrecoThemeUploadDlg
*self
)
276 gtk_widget_destroy(self
->banner
);
284 * Start a loader state machine if one is not running already.
286 static void _loader_start(IrrecoThemeUploadDlg
*self
)
290 if (self
->loader_func_id
== 0) {
291 self
->loader_func_id
= g_idle_add((GSourceFunc
)_send_theme
, self
);
298 * Stop and cleanup loader if a loader is running.
300 static void _loader_stop(IrrecoThemeUploadDlg
*self
)
304 if (self
->loader_func_id
!= 0) {
305 g_source_remove(self
->loader_func_id
);
306 self
->loader_func_id
= 0;
307 self
->loader_state
= 0;
313 * Check textfields, return TRUE if everythings fine
315 static gboolean
_texts_ok(IrrecoThemeUploadDlg
*self
)
317 gboolean rvalue
= TRUE
;
318 GtkTextIter startiter
;
323 if (self
->comments
!= NULL
) g_free(self
->comments
);
325 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(self
->buffer_comments
),
327 gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(self
->buffer_comments
),
329 self
->comments
= gtk_text_buffer_get_text(
330 GTK_TEXT_BUFFER(self
->buffer_comments
),
335 if(strlen(self
->comments
) == 0) {
336 self
->comments
= " ";
337 IRRECO_DEBUG("No comment given, "
338 "using space to prevent DB failing\n");
341 IRRECO_DEBUG("theme comments: %s\n", self
->comments
);
343 IRRECO_RETURN_BOOL(rvalue
);
347 * Upload theme confs and images, return TRUE if everything went fine
349 static gboolean
_send_theme(IrrecoThemeUploadDlg
*self
)
353 switch (self
->loader_state
) {
355 case LOADER_STATE_INIT
:
357 IRRECO_DEBUG("Loader state init\n");
359 self
->uploading_errors
= FALSE
;
360 self
->client
= irreco_webdb_client_new();
362 irreco_webdb_client_get_max_image_size(self
->client
);
363 self
->banner_max
= irreco_string_table_lenght(
364 self
->theme
->buttons
);
365 self
->banner_max
+= irreco_string_table_lenght(
366 self
->theme
->backgrounds
);
367 self
->strtablesize
= irreco_string_table_lenght(
368 self
->theme
->buttons
);
369 self
->strtableindex
= 0;
370 _set_banner(self
, _("Uploading theme..."), 0);
371 self
->loader_state
= LOADER_STATE_THEME
;
373 IRRECO_RETURN_BOOL(TRUE
);
375 case LOADER_STATE_THEME
: {
379 IRRECO_DEBUG("Loader state theme\n");
381 /* Parse folder out from theme path */
382 parsedpath
= g_utf8_strrchr(self
->theme
->path
->str
,
385 parsedpath
= g_utf8_find_next_char(parsedpath
, NULL
);
387 /* Create new theme */
388 self
->themeindex
= irreco_webdb_client_create_theme(
390 /*self->theme_name,*/
391 self
->theme
->name
->str
,
393 self
->theme
->preview_button_name
->str
,
398 /* Abort if theme creation fails */
399 if(self
->themeindex
== 0) {
400 irreco_error_dlg(GTK_WINDOW(self
),
401 "Failed to create theme");
402 self
->uploading_errors
= TRUE
;
404 self
->uploading_started
= FALSE
;
405 IRRECO_RETURN_BOOL(FALSE
);
408 self
->loader_state
= LOADER_STATE_BUTTONS
;
410 IRRECO_RETURN_BOOL(TRUE
);
413 case LOADER_STATE_BUTTONS
: {
415 guchar
*img_up_data
= g_malloc0(self
->buffer_size
);
416 guchar
*img_down_data
= g_malloc0(self
->buffer_size
);
417 gchar
*img_up_sha
; /* SHAs */
419 gchar
*img_up_name
; /* filenames */
420 gchar
*img_down_name
;
421 gint img_up_len
; /* img data lengths */
423 GString
*img_folder
= g_string_new(NULL
); /* folder of button */
425 gchar
*error_msg
= NULL
;
427 IrrecoThemeButton
*button
= NULL
;
430 IRRECO_DEBUG("Loader state buttons\n");
432 irreco_string_table_index(self
->theme
->buttons
,
433 self
->strtableindex
, &key
,
434 (gpointer
*) &button
);
437 IRRECO_DEBUG("No buttons\n");
441 banner
= (gfloat
) self
->strtableindex
/(gfloat
) self
->banner_max
;
443 self
->strtableindex
++;
446 "Uploading buttons...",
449 IRRECO_DEBUG("Current button: %s\n", button
->name
->str
);
451 /* button up sizecheck */
452 if(irreco_file_length(button
->image_up
->str
) >=
457 irreco_error_dlg(GTK_WINDOW(self
),
459 "Button %s image too large\n"
460 "Max allowed size: %d KiB",
462 self
->buffer_size
/1024));
463 self
->uploading_errors
= TRUE
;
468 if(_get_image_data_and_hash(button
->image_up
->str
,
475 /* Parse folder out from theme img */
476 img_up_name
= g_utf8_strrchr(button
->image_up
->str
,
479 img_up_name
= g_utf8_find_next_char(img_up_name
, NULL
);
484 irreco_error_dlg(GTK_WINDOW(self
), error_msg
);
485 self
->uploading_errors
= TRUE
;
489 /* button down sizecheck */
490 if(irreco_file_length(button
->image_down
->str
) >=
492 img_down_data
= NULL
;
494 img_down_name
= NULL
;
495 irreco_error_dlg(GTK_WINDOW(self
),
497 "Button %s image too large\n"
498 "Max allowed size: %d KiB",
500 self
->buffer_size
/1024));
501 self
->uploading_errors
= TRUE
;
506 if(_get_image_data_and_hash(button
->image_down
->str
,
512 /* Parse folder out from theme img */
513 img_down_name
= g_utf8_strrchr(button
->image_down
->str
,
516 img_down_name
= g_utf8_find_next_char(img_down_name
,
519 img_down_data
= NULL
;
521 img_down_name
= NULL
;
522 IRRECO_DEBUG("No optional down button\n");
525 /* Copy whole path+button name */
526 g_string_printf(img_folder
, "%s", button
->image_down
->str
);
527 /* Remove everything past and including rightmost folder char */
528 img_folder
= g_string_erase(img_folder
,
529 strlen(button
->image_down
->str
) -
530 strlen(g_utf8_strrchr(
531 button
->image_down
->str
,
535 /* Remove everything prior rightmost folder character */
536 g_string_printf(img_folder
, "%s", g_utf8_strrchr(img_folder
->str
,
539 /* Remove starting folder character */
540 img_folder
= g_string_erase(img_folder
, 0, 1);
543 button_index
= irreco_webdb_client_add_button_to_theme(
547 button
->text_format_up
->str
,
548 button
->text_format_down
->str
,
549 button
->text_padding
,
550 button
->text_h_align
,
551 button
->text_v_align
,
565 if(button_index
== 0) {
566 irreco_error_dlg(GTK_WINDOW(self
),
568 "Button %s uploading failed",
570 self
->uploading_errors
= TRUE
;
577 g_free(img_down_data
);
578 img_down_data
= NULL
;
579 g_string_free(img_folder
, TRUE
);
582 if(self
->strtablesize
== self
->strtableindex
||
583 self
->strtablesize
== 0) {
584 self
->strtablesize
= irreco_string_table_lenght(
585 self
->theme
->backgrounds
);
586 self
->strtableindex
= 0;
587 self
->loader_state
= LOADER_STATE_BACKGROUNDS
;
588 IRRECO_DEBUG("Next loader state backgrounds\n");
591 IRRECO_RETURN_BOOL(TRUE
);
594 case LOADER_STATE_BACKGROUNDS
: {
595 GString
*img_folder
= g_string_new(NULL
);
596 guchar
*img_data
= g_malloc0(self
->buffer_size
);
603 IrrecoThemeBg
*bg
= NULL
;
606 irreco_string_table_index(self
->theme
->backgrounds
,
607 self
->strtableindex
, &key
,
611 IRRECO_DEBUG("No backgrounds\n");
615 banner
= (gfloat
) (self
->banner_max
-
616 self
->strtablesize
+ self
->strtableindex
) /
617 (gfloat
) self
->banner_max
;
619 self
->strtableindex
++;
621 _set_banner(self
, "Uploading backgrounds...", banner
);
623 IRRECO_DEBUG("Current bg: %s\n", bg
->image_name
->str
);
625 /* backgrounds image sizecheck */
626 if(irreco_file_length(bg
->image_path
->str
) >=
631 irreco_error_dlg(GTK_WINDOW(self
),
633 "Background %s image too large\n"
634 "Max allowed size: %d KiB",
636 self
->buffer_size
/1024));
637 self
->uploading_errors
= TRUE
;
640 if(_get_image_data_and_hash(bg
->image_path
->str
,
647 /* Parse folder out from bg img path */
648 img_name
= g_utf8_strrchr(bg
->image_path
->str
,
651 img_name
= g_utf8_find_next_char(img_name
, NULL
);
656 irreco_error_dlg(GTK_WINDOW(self
), error_msg
);
657 self
->uploading_errors
= TRUE
;
661 /* Copy whole path+bg name */
662 g_string_printf(img_folder
, "%s", bg
->image_path
->str
);
663 /* Remove everything past and including rightmost folder char */
664 img_folder
= g_string_erase(img_folder
,
665 strlen(bg
->image_path
->str
) -
666 strlen(g_utf8_strrchr(
671 /* Remove everything prior rightmost folder character */
672 g_string_printf(img_folder
, "%s", g_utf8_strrchr(img_folder
->str
,
675 /* Remove starting folder character */
676 img_folder
= g_string_erase(img_folder
, 0, 1);
678 if(img_len
>= self
->buffer_size
) {
679 irreco_error_dlg(GTK_WINDOW(self
),
681 "Bg %s image too large",
682 bg
->image_name
->str
));
683 self
->uploading_errors
= TRUE
;
687 bg_index
= irreco_webdb_client_add_bg_to_theme(
699 irreco_error_dlg(GTK_WINDOW(self
),
701 "Bg %s uploading failed",
702 bg
->image_name
->str
));
703 self
->uploading_errors
= TRUE
;
709 g_string_free(img_folder
, TRUE
);
712 if(self
->strtablesize
== self
->strtableindex
||
713 self
->strtablesize
== 0) {
714 self
->loader_state
= LOADER_STATE_END
;
715 IRRECO_DEBUG("Next loader state end\n");
718 IRRECO_RETURN_BOOL(TRUE
);
721 case LOADER_STATE_END
:
724 if(!self
->uploading_errors
) {
725 if(!irreco_webdb_client_set_theme_downloadable(
731 irreco_error_dlg(GTK_WINDOW(self
),
732 "Failed to make theme downloadable.\n"
733 "Theme won't show at database.");
734 self
->uploading_errors
= TRUE
;
736 irreco_info_dlg(GTK_WINDOW(self
),
737 "Theme uploaded successfully");
740 irreco_error_dlg(GTK_WINDOW(self
),
741 "Some error(s) occured during upload.\n"
742 "Please try again.");
744 self
->uploading_started
= FALSE
;
745 IRRECO_RETURN_BOOL(FALSE
);
747 self
->uploading_started
= FALSE
;
748 gtk_dialog_response(GTK_DIALOG(self
), GTK_RESPONSE_CLOSE
);
749 IRRECO_RETURN_BOOL(FALSE
);
752 IRRECO_DEBUG("Oh no, shouldn't ever be here\n");
753 IRRECO_RETURN_BOOL(FALSE
);
757 * Retrieves image data and hash of given file
759 * @param img_path Path to file containing binary data
760 * @param img_data Set to contain read binary data
761 * @param img_sha Set to contain sha1 of data
762 * @param img_data_len Set to contain length of data
763 * @param buffer_size Max length of data to read
764 * @param error_msg Set to contain error message, if error occurs
765 * @return True upon success, false otherwise
767 static gboolean
_get_image_data_and_hash(gchar
*img_path
,
774 gboolean rvalue
= TRUE
;
778 if(irreco_file_exists(img_path
)) {
779 if(irreco_read_binary_file(img_path
,
783 *img_sha
= sha_compute_checksum_for_data(
788 IRRECO_DEBUG("File read failed\n");
789 *error_msg
= "File read failed\n";
793 IRRECO_DEBUG("No such file\n");
794 *error_msg
= "No such file\n";
798 IRRECO_RETURN_BOOL(rvalue
)
803 * Update shown preview image
805 static void _update_preview(IrrecoThemeUploadDlg
*self
)
809 /* if theme contains preview image, use it, else get first button */
810 if(self
->preview_name
) {
811 IRRECO_DEBUG("Preview set in dlg, using it\n");
812 } else if(strlen(self
->theme
->preview_button_name
->str
) != 0) {
814 IRRECO_DEBUG("Preview set to theme, using it\n");
815 strtblkey
= g_strdup_printf("%s/%s", self
->theme
->name
->str
,
816 self
->theme
->preview_button_name
->str
);
817 /*IRRECO_DEBUG("key: %s\n", strtblkey);*/
818 if(irreco_string_table_get(self
->theme
->buttons
,
820 (gpointer
*) &self
->preview_button
)) {
821 self
->preview_name
= self
->preview_button
->image_up
->str
;
823 IRRECO_DEBUG("Theme preview set wrong\n");
827 IRRECO_DEBUG("No preview set, using first button of theme\n");
828 irreco_string_table_index(self
->theme
->buttons
,
830 (gpointer
*) &self
->preview_button
);
831 if(self
->preview_button
) {
832 self
->preview_name
= self
->preview_button
->image_up
->str
;
836 gtk_image_set_from_file(GTK_IMAGE(self
->preview_image
),
839 gtk_widget_show_all(GTK_WIDGET(self
));
847 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
848 /* Public Functions */
849 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
852 * Show dialog, and ask user for input.
853 * @param irreco_data Irreco data
854 * @param irreco_theme IrrecoTheme to be uploaded
856 gboolean
irreco_theme_upload_dlg_run(GtkWindow
*parent_window
,
857 IrrecoData
*irreco_data
,
858 IrrecoTheme
* irreco_theme
)
860 IrrecoThemeUploadDlg
*self
;
862 gboolean loop
= TRUE
;
863 gboolean rvalue
= FALSE
;
867 if(irreco_theme
== NULL
) { IRRECO_RETURN_BOOL(FALSE
); }
869 self
= (IrrecoThemeUploadDlg
*)irreco_theme_upload_dlg_new(irreco_data
,
872 self
->parent_window
= GTK_WINDOW(self
);
873 self
->irreco_data
= irreco_data
;
874 self
->theme
= irreco_theme
;
875 self
->preview_name
= NULL
;
876 self
->uploading_started
= FALSE
;
877 self
->loader_func_id
= 0;
879 /* set things to dialog, cause theme & data wasn't set @ _constructed */
880 gtk_entry_set_text(GTK_ENTRY(self
->entry_name
), self
->theme
->name
->str
);
881 self
->buffer_comments
= gtk_text_view_get_buffer(
882 GTK_TEXT_VIEW(self
->textview_comments
));
883 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self
->buffer_comments
),
884 self
->theme
->comment
->str
,
886 _update_preview(self
);
889 response
= gtk_dialog_run(GTK_DIALOG(self
));
891 case GTK_RESPONSE_OK
:
892 IRRECO_DEBUG("GTK_RESPONSE_OK\n");
894 if(self
->uploading_started
) {
895 IRRECO_DEBUG("Already uploading theme\n");
899 /* Check themename length and get texts */
900 if(!_texts_ok(self
)) {
901 IRRECO_DEBUG("Input failure\n");
905 /* Show login/reg dialog */
906 if(!irreco_show_login_dlg(irreco_data
,
910 IRRECO_DEBUG("Failed login\n");
914 /* set new info to theme */
915 irreco_theme_set_author(self
->theme
, self
->user
);
916 irreco_theme_set_comment(self
->theme
, self
->comments
);
917 if(!self
->preview_button
) {
918 irreco_error_dlg(GTK_WINDOW(self
),
919 "Please select preview image first");
922 irreco_theme_set_preview_button(self
->theme
,
923 self
->preview_button
->name
->str
);
924 self
->uploading_started
= TRUE
;
925 self
->loader_state
= LOADER_STATE_INIT
;
926 IRRECO_DEBUG("Start loader\n");
931 case GTK_RESPONSE_CANCEL
:
932 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
934 if(self
->uploading_started
) {
935 irreco_info_dlg(GTK_WINDOW(self
),
936 "Theme uploading aborted");
941 case GTK_RESPONSE_CLOSE
:
942 IRRECO_DEBUG("GTK_RESPONSE_CLOSE\n");
949 IRRECO_DEBUG("Something went horribly wrong\n");
955 gtk_widget_destroy(GTK_WIDGET(self
));
957 IRRECO_RETURN_BOOL(rvalue
);
964 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
965 /* Events and Callbacks */
966 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
969 * @name Events and Callbacks
974 * Run button browser where one button can be selected
975 * Stores selected buttons name and buttonstructure
977 static void _run_button_browser_dlg(GtkWidget
*widget
,
978 GdkEventButton
*event
,
979 IrrecoThemeUploadDlg
*self
)
981 IrrecoThemeButton
*preview_theme_button
= NULL
;
985 preview_theme_button
= irreco_button_browser_dlg_run(
986 GTK_WINDOW(IRRECO_THEME_UPLOAD_DLG(self
)->parent_window
),
990 if(preview_theme_button
) {
991 IRRECO_DEBUG("Set preview button to theme and self->\n");
992 self
->preview_name
= preview_theme_button
->image_up
->str
;
993 self
->preview_button
= preview_theme_button
;
994 _update_preview(self
);