summaryrefslogtreecommitdiff
path: root/nautilus-installer/src/installer.c
blob: eac512a0e399e679c1219ffc228f2386f939b173 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gnome.h>
#include "installer.h"
#include <eazel-install-public.h>
#include <libtrilobite/helixcode-utils.h>

#define HOSTNAME "vorlon.eazel.com"
#define PORT_NUMBER 80
#define PROTOCOL PROTOCOL_HTTP
#define TMP_DIR "/tmp/eazel-install"
#define RPMRC "/usr/lib/rpm/rpmrc"
#define REMOTE_RPM_DIR "/RPMS"
#define PACKAGE_LIST "package-list.xml"

static char *package_list[LAST] = {
	"/package-list.xml",
	"/nautilus-only-list.xml",
	"/services-only-list.xml",
	"/package-list.xml",
	"/package-uninstall-list.xml",
};

static void 
eazel_install_progress (EazelInstall *service, 
			const char *name,
			int amount, 
			int total,
			GtkWidget *widget) 
{
	GtkProgressBar *progressbar;
	GtkLabel *action_label;
	GtkLabel *package_label;
	float pct;
 
	pct = ( (total > 0) ? ((float) ((((float) amount) / total) * 100)): 100.0);
	/* fprintf (stdout, "Install Progress - %s - %d %d %% %f\n", name?name:"(null)", amount, total, pct); */

	action_label = gtk_object_get_data (GTK_OBJECT (widget), "action_label");
	package_label = gtk_object_get_data (GTK_OBJECT (widget), "package_label");
	progressbar = gtk_object_get_data (GTK_OBJECT (widget), "progressbar");

	gtk_label_set_text (action_label, "Install :");
	gtk_label_set_text (package_label, name + strlen (TMP_DIR) + 1);
	gtk_progress_bar_update (progressbar, pct/100);

	fflush (stdout);
	if (amount == total) {
		fprintf (stdout, "\n");
	}
	
	gtk_main_iteration ();
}


static void 
eazel_download_progress (EazelInstall *service, 
			 const char *name,
			 int amount, 
			 int total,
			 GtkWidget *widget) 
{
	GtkProgressBar *progressbar;
	GtkLabel *action_label;
	GtkLabel *package_label;
	float pct;
 
	pct = ( (total > 0) ? ((float) ((((float) amount) / total) * 100)): 100.0);
	/* fprintf (stdout, "DOWNLOAD Progress - %s - %d %d %% %f\n", name?name:"(null)", amount, total, pct); */

	action_label = gtk_object_get_data (GTK_OBJECT (widget), "action_label");
	package_label = gtk_object_get_data (GTK_OBJECT (widget), "package_label");
	progressbar = gtk_object_get_data (GTK_OBJECT (widget), "progressbar");

	gtk_label_set_text (action_label, "Download :");
	gtk_label_set_text (package_label, name + strlen (TMP_DIR) + 1);
	gtk_progress_bar_update (progressbar, pct/100);

	fflush (stdout);
	if (amount == total) {
		fprintf (stdout, "\n");
	}
	
	gtk_main_iteration ();
}

static void
append_string_to_window_list (GtkWidget *widget,
		const char *listname,
		const char *name)
{
	GSList *list;

	list = (GSList*)gtk_object_get_data (GTK_OBJECT (widget), listname);
	list = g_slist_append (list, g_strdup (name));
	gtk_object_set_data (GTK_OBJECT (widget), listname, list);
}

static void
download_failed (EazelInstall *service,
		 const char *name,
		 GtkWidget *window)
{
	append_string_to_window_list (window, "download_failed_list", name);
}

static void
install_failed_foreach (PackageData *dep,
			GtkWidget *window)
{	
	char *string;
	string = g_strdup_printf (" requires %s %s", dep->name,
				  dep->version ? dep->version : "");
	append_string_to_window_list (window, "install_failed_list", string);
	g_free (string);
}

static void
requeue (PackageData *dep,
	 const PackageData *pd)
{
	g_message ("%s-%s failed, requeue and add %s for %s, version >= %s",
		   pd->name, 
		   pd->version,
		   dep->name,
		   dep->archtype,
		   dep->version);
}

void
install_failed (EazelInstall *service,
		const PackageData *pd,
		RPM_FAIL code,
		GList *deps,
		GtkWidget *window)
{
	append_string_to_window_list (window, "install_failed_list", pd->name);

	switch (code) {
	case RPM_DEP_FAIL:
		g_list_foreach (deps, (GFunc)install_failed_foreach, window);
		g_list_foreach (deps, (GFunc)requeue, (gpointer)pd);
		break;
	case RPM_SRC_NOT_SUPPORTED: 
		append_string_to_window_list (window, "install_failed_list", "source packaages not supported" );
		break;
	default:
		break;
	}

}

static void
gen_report (GtkWidget *widget,
	    const char *listname,
	    char **text,
	    const char *title)
{
	GSList *list;

	list = gtk_object_get_data (GTK_OBJECT (widget), listname);
	if (list != NULL) {
		GSList *ptr;
		if ((*text)==NULL) {
			(*text) = g_strdup (title);
		} else {
			char *tmp;
			tmp = g_strconcat ((*text), title, NULL);
			g_free ((*text));
			(*text) = tmp;
		}
		ptr = list;
		while (ptr) {
			char *tmp;
			tmp = g_strconcat ((*text), (char*)ptr->data, "\n", NULL);
			g_free ((*text));
			(*text) = tmp;
			ptr = ptr->next;
		}
	}
}

static void
dump_failure_info (GtkWidget *window) 
{
	char *text;

	text = NULL;
	gen_report (window, "download_failed_list", &text, "Download failed for\n");
	gen_report (window, "install_failed_list", &text, "Install failed for\n");
	gnome_warning_dialog (text);
}

void installer (GtkWidget *window,
		gint method) 
{
	EazelInstall *service;
	GtkProgressBar *progressbar;
	GtkLabel *package_label;

	if (method==UPGRADE) {
		gnome_warning_dialog ("We don't do UPGRADE yet");
		return;
	}

	service = EAZEL_INSTALL (gtk_object_new (TYPE_EAZEL_INSTALL,
						 "verbose", TRUE,
						 "silent", FALSE,
						 "debug", TRUE,
						 "test", FALSE,
						 "force", TRUE,
						 "depend", FALSE,
						 "update", TRUE, //method==UPGRADE ? TRUE : FALSE,
						 "uninstall", method==UNINSTALL ? TRUE : FALSE,
						 "downgrade", FALSE,
						 "protocol", PROTOCOL,
						 "tmp_dir", TMP_DIR,
						 "rpmrc_file", RPMRC,
						 "hostname", HOSTNAME,
						 "rpm_storage_path", REMOTE_RPM_DIR,
						 "package_list_storage_path", package_list [ method ],
						 "package_list", PACKAGE_LIST, 
						 "port_number", PORT_NUMBER,
						 NULL));

	service = eazel_install_new_with_config ("/var/eazel/services/eazel-services-config.xml");
	g_assert (service != NULL);

	eazel_install_set_hostname (service, HOSTNAME);
	eazel_install_set_rpmrc_file (service, RPMRC);
	eazel_install_set_package_list_storage_path (service, "/package-list.xml");
	eazel_install_set_rpm_storage_path (service, REMOTE_RPM_DIR);
	eazel_install_set_tmp_dir (service, TMP_DIR);
	eazel_install_set_port_number (service, PORT_NUMBER);
	eazel_install_set_protocol (service, PROTOCOL);	

	g_assert (service != NULL);

	gtk_signal_connect (GTK_OBJECT (service), "download_progress", eazel_download_progress, window);
	gtk_signal_connect (GTK_OBJECT (service), "install_progress", eazel_install_progress, window);
	gtk_signal_connect (GTK_OBJECT (service), "download_failed", download_failed, window);
	gtk_signal_connect (GTK_OBJECT (service), "install_failed", install_failed, window);

	switch (method) {
	case FULL_INST:
	case NAUTILUS_ONLY:
	case SERVICES_ONLY:
	case UPGRADE:
		eazel_install_new_packages (service);
		break;
	case UNINSTALL:
		eazel_install_uninstall (service);
		break;
	};
	eazel_install_destroy (GTK_OBJECT (service));

	package_label = gtk_object_get_data (GTK_OBJECT (window), "package_label");
	progressbar = gtk_object_get_data (GTK_OBJECT (window), "progressbar");

	gtk_label_set_text (package_label, "Completed :");
	gtk_progress_bar_update (progressbar, 1);


	dump_failure_info (window);
}