From b94b99b4fde61c55d61241ad9a0b469f7ea2c5da Mon Sep 17 00:00:00 2001 From: Harri Vattulainen Date: Thu, 9 Oct 2008 10:49:54 +0300 Subject: [PATCH] Button upload feature added. Still needs bg upload. --- irreco/src/core/irreco_theme_upload_dlg.c | 122 ++++++++++++++++++------------ 1 file changed, 72 insertions(+), 50 deletions(-) diff --git a/irreco/src/core/irreco_theme_upload_dlg.c b/irreco/src/core/irreco_theme_upload_dlg.c index 10854401..56176711 100644 --- a/irreco/src/core/irreco_theme_upload_dlg.c +++ b/irreco/src/core/irreco_theme_upload_dlg.c @@ -65,7 +65,8 @@ static void _run_button_browser_dlg(GtkWidget *widget, IrrecoThemeUploadDlg *self); static gboolean _get_image_data_and_hash(gchar* img_path, guchar **img_data, - gchar **img_sha); + gchar **img_sha, + gint *img_data_len); /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ @@ -306,12 +307,6 @@ static gboolean _send_theme(IrrecoThemeUploadDlg *self) IRRECO_DEBUG("parsed theme path:%s\n", parsedpath); client = irreco_webdb_client_new(); - - /* TODO a lot to do when reg dialog works */ -#if 0 - self->user = "vbnvbn"; - self->password = "78501edfca2e9f3c35494836747a7307f3f835c3"; -#endif IRRECO_DEBUG("\nthemename: %s\ncomm: %s\nprevname: %s\nthemepath: %s\nusr: %s\npassu: %s\n", self->theme_name, self->comments, self->theme->preview_button_name->str, parsedpath, self->user, self->password); @@ -327,7 +322,6 @@ static gboolean _send_theme(IrrecoThemeUploadDlg *self) IRRECO_RETURN_BOOL(TRUE); } -#if 1 IRRECO_STRING_TABLE_FOREACH_DATA(self->theme->buttons, IrrecoThemeButton *, button) @@ -339,16 +333,18 @@ static gboolean _send_theme(IrrecoThemeUploadDlg *self) gchar *img_down_sha; gchar *img_up_name; /* filenames */ gchar *img_down_name; - /*gchar *button_path;*/ /* button folder */ - /* gint button_index; */ - /* TODO func that parses folder of button from image_up_name */ + gint img_up_len; /* img data lengths */ + gint img_down_len; + GString *img_folder = g_string_new(NULL); /* folder of button */ + gint button_index; IRRECO_DEBUG("Current button: %s\n", button->name->str); /* button up */ if(_get_image_data_and_hash(button->image_up->str, &img_up_data, - &img_up_sha)) { + &img_up_sha, + &img_up_len)) { IRRECO_DEBUG("Up sha: %s\n", img_up_sha); /* Parse folder out from theme img */ @@ -363,11 +359,12 @@ static gboolean _send_theme(IrrecoThemeUploadDlg *self) img_up_name = NULL; /* multifailtilanne, goto the end */ } - + /* button down */ if(_get_image_data_and_hash(button->image_down->str, &img_down_data, - &img_down_sha)) { + &img_down_sha, + &img_down_len)) { IRRECO_DEBUG("Down sha: %s\n", img_down_sha); /* Parse folder out from theme img */ @@ -381,18 +378,28 @@ static gboolean _send_theme(IrrecoThemeUploadDlg *self) img_down_sha = NULL; img_down_name = NULL; } - /* - IRRECO_DEBUG("loppu %d\n", strlen(g_utf8_strrchr(button->image_up->str, - -1, - G_DIR_SEPARATOR))); - IRRECO_DEBUG("alku %d\n", strlen(button->image_up->str)); - IRRECO_DEBUG("alusta %s\n", g_strdup(button->image_up->str, - (strlen(button->image_up->str)- strlen(g_utf8_strrchr(button->image_up->str, + + img_folder = g_string_new(NULL); + /* Copy whole path+button name */ + g_string_printf(img_folder, "%s", button->image_down->str); + /* Remove everything past and including rightmost folder character */ + img_folder = g_string_erase(img_folder, + strlen(button->image_down->str) - + strlen(g_utf8_strrchr( + button->image_down->str, -1, - G_DIR_SEPARATOR))))); - IRRECO_DEBUG("\n");*/ + G_DIR_SEPARATOR)), + -1); + /* Remove everything prior rightmost folder character */ + g_string_printf(img_folder, "%s", g_utf8_strrchr(img_folder->str, + -1, + G_DIR_SEPARATOR)); + /* Remove starting folder character */ + img_folder = g_string_erase(img_folder, 0, 1); + IRRECO_DEBUG("button folder: %s\n", img_folder->str); - /*button_index = irreco_webdb_client_add_button_to_theme( + /* Upload button */ + button_index = irreco_webdb_client_add_button_to_theme( client, button->name->str, button->allow_text, @@ -402,57 +409,72 @@ static gboolean _send_theme(IrrecoThemeUploadDlg *self) img_up_sha, img_up_name, img_up_data, + img_up_len, img_down_sha, img_down_name, img_down_data, - - ...*/ + img_down_len, + img_folder->str, + themeindex, + self->user, + self->password); + + IRRECO_DEBUG("butt index: %d", button_index); + /*gint irreco_webdb_client_add_button_to_theme(IrrecoWebdbClient *self, - const gchar *name, - gboolean allow_text, - const gchar *text_format_up, - const gchar *text_format_down, - gint text_padding, - const gchar *image_up_hash, - const gchar *image_up_name, - const gchar *image_up, - const gchar *image_down_hash, - const gchar *image_down_name, - const gchar *image_down, - const gchar *folder, - gint theme_id, - const gchar *user, - const gchar *password);*/ + const gchar *name, + gboolean allow_text, + const gchar *text_format_up, + const gchar *text_format_down, + gint text_padding, + const gchar *image_up_hash, + const gchar *image_up_name, + const guchar *image_up, + gint image_up_len, + const gchar *image_down_hash, + const gchar *image_down_name, + const guchar *image_down, + gint image_down_len, + const gchar *folder, + gint theme_id, + const gchar *user, + const gchar *password)*/ + + /* TODO if err msg -> messuboxeittain urputusta */ + g_free(img_up_data); img_up_data = NULL; g_free(img_down_data); img_down_data = NULL; + g_string_free(img_folder, TRUE); + img_folder = NULL; IRRECO_STRING_TABLE_FOREACH_END -#endif + IRRECO_RETURN_BOOL(TRUE); } -static gboolean _get_image_data_and_hash(gchar* img_path, +static gboolean _get_image_data_and_hash(gchar *img_path, guchar **img_data, - gchar **img_sha) + gchar **img_sha, + gint *img_data_len) { - /* Max image size */ - gsize buffer_size = MAX_IMG_SIZE; /* 1 Mt */ - gint img_data_len; + gsize buffer_size = MAX_IMG_SIZE; /* Max image size 1 Mt */ + /*gint img_data_len;*/ gboolean rvalue = TRUE; - + IRRECO_ENTER + if(irreco_file_exists(img_path)) { if(irreco_read_binary_file(img_path, *img_data, buffer_size, - &img_data_len)) { + img_data_len)) { /*IRRECO_DEBUG("img_data_len: %d\n", img_data_len);*/ *img_sha = sha_compute_checksum_for_data( G_CHECKSUM_SHA1, *img_data, - img_data_len); + *img_data_len); /*IRRECO_DEBUG("sha1: %s\n", *img_sha);*/ } else { IRRECO_DEBUG("File read failed\n"); -- 2.11.4.GIT