summaryrefslogtreecommitdiff
path: root/riscos/theme_install.c
blob: 75991f47f35254f02102b7ac2ed16931753ab85c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * This file is part of NetSurf, http://netsurf.sourceforge.net/
 * Licensed under the GNU General Public License,
 *                http://www.opensource.org/licenses/gpl-license
 * Copyright 2005 James Bursa <bursa@users.sourceforge.net>
 */

/** \file
 * Theme auto-installing.
 */

#include <assert.h>
#include <stdbool.h>
#include "netsurf/content/content.h"
#include "netsurf/desktop/browser.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/riscos/wimp.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/utils.h"


static bool theme_install_active = false;
wimp_w dialog_theme_install;


void theme_install_callback(content_msg msg, struct content *c,
		void *p1, void *p2, union content_msg_data data);


/**
 * Handle a CONTENT_THEME that has started loading.
 */

void theme_install_start(struct content *c)
{
	assert(c);
	assert(c->type == CONTENT_THEME);

	if (theme_install_active) {
		warn_user("ThemeInstActive", 0);
		/* raise & centre dialog */
		return;
	}

	if (!content_add_user(c, theme_install_callback, 0, 0)) {
		warn_user("NoMemory", 0);
		return;
	}

	theme_install_active = true;

	ro_gui_set_icon_string(dialog_theme_install, ICON_THEME_INSTALL_MESSAGE,
			messages_get("ThemeInstDown"));
	ro_gui_set_icon_shaded_state(dialog_theme_install,
			ICON_THEME_INSTALL_INSTALL, true);
	ro_gui_dialog_open(dialog_theme_install);
}


/**
 * Callback for fetchcache() for theme install fetches.
 */

void theme_install_callback(content_msg msg, struct content *c,
		void *p1, void *p2, union content_msg_data data)
{
	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 */
			ro_gui_set_icon_string(dialog_theme_install,
					ICON_THEME_INSTALL_MESSAGE,
					"Would you like to install the theme "
					"\"x\" by y?");
			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);
			warn_user(data.error, 0);
			theme_install_active = false;
			break;

		case CONTENT_MSG_STATUS:
			break;

		case CONTENT_MSG_LOADING:
		case CONTENT_MSG_REDIRECT:
		case CONTENT_MSG_REFORMAT:
		case CONTENT_MSG_REDRAW:
		case CONTENT_MSG_NEWPTR:
		case CONTENT_MSG_AUTH:
		default:
			assert(0);
			break;
	}
}


/**
 * Create theme install window.
 */

void ro_gui_theme_install_init(void)
{
	dialog_theme_install = ro_gui_dialog_create("theme_inst");
}