summaryrefslogtreecommitdiff
path: root/riscos/theme_install.c
diff options
context:
space:
mode:
authorRichard Wilson <rjw@netsurf-browser.org>2005-01-23 16:09:05 +0000
committerRichard Wilson <rjw@netsurf-browser.org>2005-01-23 16:09:05 +0000
commit422df9008913857667ff20bf3ec295c1839cbc45 (patch)
treee3a122c9b871a9487372ca0d958e3c520f89f777 /riscos/theme_install.c
parent54f903d1b457a280f2cf0a677667428dd3dee239 (diff)
downloadnetsurf-422df9008913857667ff20bf3ec295c1839cbc45.tar.gz
netsurf-422df9008913857667ff20bf3ec295c1839cbc45.tar.bz2
[project @ 2005-01-23 16:09:05 by rjw]
Further work on theme installing svn path=/import/netsurf/; revision=1463
Diffstat (limited to 'riscos/theme_install.c')
-rw-r--r--riscos/theme_install.c140
1 files changed, 128 insertions, 12 deletions
diff --git a/riscos/theme_install.c b/riscos/theme_install.c
index 75991f47f..b1b733b2f 100644
--- a/riscos/theme_install.c
+++ b/riscos/theme_install.c
@@ -11,18 +11,24 @@
#include <assert.h>
#include <stdbool.h>
+#include "oslib/osfile.h"
#include "netsurf/content/content.h"
#include "netsurf/desktop/browser.h"
#include "netsurf/riscos/gui.h"
+#include "netsurf/riscos/options.h"
+#include "netsurf/riscos/theme.h"
#include "netsurf/riscos/wimp.h"
#include "netsurf/utils/messages.h"
+#include "netsurf/utils/url.h"
#include "netsurf/utils/utils.h"
-static bool theme_install_active = false;
+static bool theme_install_active;
+static struct content *theme_install_content = NULL;
+static struct theme_descriptor theme_install_descriptor;
wimp_w dialog_theme_install;
-
+static void theme_install_close(void);
void theme_install_callback(content_msg msg, struct content *c,
void *p1, void *p2, union content_msg_data data);
@@ -64,25 +70,49 @@ void theme_install_start(struct content *c)
void theme_install_callback(content_msg msg, struct content *c,
void *p1, void *p2, union content_msg_data data)
{
+ char txt_buffer[256];
+ bool error = false;
+ int author_indent = 0;
+
switch (msg) {
case CONTENT_MSG_READY:
break;
case CONTENT_MSG_DONE:
- /** \todo: parse the theme data, extract name & author,
- * and ask the user if they want to install */
+ theme_install_content = c;
+ if ((c->source_size < sizeof(struct theme_file_header)) ||
+ (!ro_gui_theme_read_file_header(&theme_install_descriptor,
+ (struct theme_file_header *)c->source_data)))
+ error = true;
+ else if (c->source_size - sizeof(struct theme_file_header) !=
+ theme_install_descriptor.compressed_size)
+ error = true;
+
+ if (error) {
+ warn_user("ThemeInvalid", 0);
+ theme_install_close();
+ break;
+ }
+
+ /* remove ' ' from the start of the data */
+ if (theme_install_descriptor.author[0] == '')
+ author_indent++;
+ while (theme_install_descriptor.author[author_indent] == ' ')
+ author_indent++;
+ snprintf(txt_buffer, 256, messages_get("ThemeInstall"),
+ theme_install_descriptor.name,
+ &theme_install_descriptor.author[author_indent]);
+ txt_buffer[255] = '\0';
ro_gui_set_icon_string(dialog_theme_install,
ICON_THEME_INSTALL_MESSAGE,
- "Would you like to install the theme "
- "\"x\" by y?");
+ txt_buffer);
ro_gui_set_icon_shaded_state(dialog_theme_install,
ICON_THEME_INSTALL_INSTALL, false);
break;
case CONTENT_MSG_ERROR:
- ro_gui_dialog_close(dialog_theme_install);
+ theme_install_close();
warn_user(data.error, 0);
- theme_install_active = false;
break;
case CONTENT_MSG_STATUS:
@@ -102,10 +132,96 @@ void theme_install_callback(content_msg msg, struct content *c,
/**
- * Create theme install window.
+ * Handle clicks in the theme install window
*/
+void ro_gui_theme_install_click(wimp_pointer *pointer) {
+ os_error *error;
+ fileswitch_object_type obj_type;
+ char theme_save[256];
+ char theme_leaf[256];
+ char *theme_file;
+ int theme_number = 1;
+ bool theme_found;
+ struct theme_descriptor *theme_install;
+
+ switch (pointer->i) {
+ case ICON_THEME_INSTALL_INSTALL:
+ if (theme_install_content) {
+ if (url_nice(theme_install_descriptor.name, &theme_file) != URL_FUNC_OK) {
+ warn_user("ThemeInstallErr", 0);
+ theme_install_close();
+ return;
+ }
+ theme_found = false;
+ while (!theme_found) {
+ if (theme_number == 1)
+ snprintf(theme_leaf, 256,
+ "WWW.NetSurf.Themes.%s",
+ theme_file);
+ else
+ snprintf(theme_leaf, 256,
+ "WWW.NetSurf.Themes.%s%i",
+ theme_file, theme_number);
+ theme_leaf[255] = '\0';
+ theme_number++;
+ snprintf(theme_save, 256,
+ "<Choices$Write>.%s",
+ theme_leaf);
+ theme_save[255] = '\0';
+ error = xosfile_read_stamped(theme_save,
+ &obj_type, 0, 0, 0, 0, 0);
+ if (error) {
+ warn_user("ThemeInstallErr", 0);
+ theme_install_close();
+ free(theme_file);
+ return;
+ }
+ theme_found = (obj_type == osfile_NOT_FOUND);
+ }
+ free(theme_file);
+ error = xosfile_save_stamped(theme_save, 0xffd,
+ theme_install_content->source_data,
+ theme_install_content->source_data +
+ theme_install_content->source_size);
+ if (error) {
+ warn_user("ThemeInstallErr", 0);
+ theme_install_close();
+ return;
+ }
+ /* apply theme only on Select clicks */
+ if (pointer->buttons == wimp_CLICK_SELECT) {
+ ro_gui_theme_get_available();
+ snprintf(theme_save, 256, "Choices:%s", theme_leaf);
+ theme_save[255] = '\0';
+ theme_install = ro_gui_theme_find(theme_save);
+ if ((!theme_install) ||
+ (!ro_gui_theme_apply(theme_install))) {
+ warn_user("ThemeApplyErr", 0);
+ } else {
+ theme_file = strdup(theme_save);
+ if (!theme_file) {
+ warn_user("NoMemory", 0);
+ } else {
+ free(option_theme);
+ option_theme = theme_file;
+ }
+ }
+ }
+ theme_install_close();
+ }
+ break;
+ case ICON_THEME_INSTALL_CANCEL:
+ if (pointer->buttons == wimp_CLICK_ADJUST)
+ break;
+ theme_install_close();
+ break;
+ }
+}
-void ro_gui_theme_install_init(void)
-{
- dialog_theme_install = ro_gui_dialog_create("theme_inst");
+static void theme_install_close(void) {
+ theme_install_active = false;
+ if (theme_install_content)
+ content_close(theme_install_content);
+ theme_install_content = NULL;
+ ro_gui_dialog_close(dialog_theme_install);
}