summaryrefslogtreecommitdiff
path: root/components/services/startup/nautilus-view/nautilus-service-startup-view.c
blob: 4b8a29a1a731665b97b6eaeb33a34f0511533910 (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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* 
 * Copyright (C) 2000 Eazel, Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authors: Ramiro Estrugo <ramiro@eazel.com>
 *          Andy Hertzfeld <andy@eazel.com>
 *          J Shane Culpepper <pepper@eazel.com>
 */

/* nautilus-service-startup-view.c - The bootstrap controller for
 * eazel services.
 */
   
#include <config.h>

#include "nautilus-service-startup-view.h"
#include "shared-service-widgets.h"
#include "shared-service-utilities.h"

#include <ghttp.h>
#include <unistd.h>
#include <gnome-xml/tree.h>
#include <gtk/gtkpixmap.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libnautilus-extensions/nautilus-background.h>
#include <libnautilus-extensions/nautilus-gdk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-font-factory.h>
#include <libnautilus-extensions/nautilus-image.h>
#include <stdio.h>


struct _NautilusServiceStartupViewDetails {
	char		*uri;
	NautilusView	*nautilus_view;
	GtkWidget	*form;
	GtkWidget	*form_title;
	GtkWidget	*progress_bar;
	GtkWidget	*feedback_text;
};

#define STARTUP_VIEW_DEFAULT_BACKGROUND_COLOR  "rgb:0000/6666/6666"
#define SERVICE_DOMAIN_NAME		       "testmachine.eazel.com"



static void       nautilus_service_startup_view_initialize_class (NautilusServiceStartupViewClass *klass);
static void       nautilus_service_startup_view_initialize       (NautilusServiceStartupView      *view);
static void       nautilus_service_startup_view_destroy          (GtkObject                       *object);
static void       service_load_location_callback                 (NautilusView                    *view,
								  const char                      *location,
								  NautilusServiceStartupView      *services);
static void       generate_form_logo                             (NautilusServiceStartupView      *view);

NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusServiceStartupView, nautilus_service_startup_view, GTK_TYPE_EVENT_BOX)

/* create the startup view */
static void
generate_startup_form (NautilusServiceStartupView	*view) 
{
	GtkWidget		*temp_widget;
	GtkWidget		*temp_box;
	GtkWidget		*align;
	int			counter;
	char			*font_color;
	GdkFont			*font;

	/* allocate the parent box to hold everything */
	view->details->form = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (view), view->details->form);
	gtk_widget_show (view->details->form);

	/* setup the title */
	generate_form_logo (view);

	/* create a fill space box */
	temp_box = gtk_hbox_new (TRUE, 30);
	gtk_box_pack_start (GTK_BOX (view->details->form), temp_box, 0, 0, 12);
	gtk_widget_show (temp_box);

	/* Add the watch icon */
	temp_box = gtk_hbox_new (TRUE, 0);
	gtk_box_pack_start (GTK_BOX (view->details->form), temp_box, 0, 0, 40);
	gtk_widget_show (temp_box);

	temp_widget = create_image_widget ("service-watch.png",
					   STARTUP_VIEW_DEFAULT_BACKGROUND_COLOR,
					   NAUTILUS_IMAGE_PLACEMENT_CENTER);
	g_assert (temp_widget != NULL);

	gtk_box_pack_start (GTK_BOX (temp_box), temp_widget, 0, 0, 8);
	gtk_widget_show (temp_widget);

	/* Add a label for error status messages */
	view->details->feedback_text = gtk_label_new ("");
	font = nautilus_font_factory_get_font_from_preferences (12);
	font_color = g_strdup ("rgb:FFFF/FFFF/FFFF");
	set_widget_foreground_color (view->details->feedback_text, font_color);
	g_free (font_color);
	nautilus_gtk_widget_set_font (view->details->feedback_text, font);
	gdk_font_unref (font);
	gtk_box_pack_end (GTK_BOX (view->details->form), view->details->feedback_text, 0, 0, 15);

	/* Create a center alignment object */
	align = gtk_alignment_new (0.5, 0.5, 0, 0);
	gtk_box_pack_end (GTK_BOX (view->details->form), align, FALSE, FALSE, 5);
	gtk_widget_show (align);

	/* Add the progress meter */
	view->details->progress_bar = gtk_progress_bar_new ();
	gtk_container_add (GTK_CONTAINER (align), view->details->progress_bar);
	gtk_widget_show (view->details->progress_bar);

	/* bogus progress loop */
	for (counter = 1; counter <= 20000; counter++) {
		float value;

		value = (float) counter / 20000;

		if (counter == 1) {
			show_feedback (view->details->feedback_text, "Initializing eazel-proxy ...");
		}
		if (counter == 5000) {
			show_feedback (view->details->feedback_text, "Contacting www.eazel.com ...");
		}
		if (counter == 10000) {
			show_feedback (view->details->feedback_text, "Authenticating user anonymous ...");
		}
		if (counter == 15000) {
			show_feedback (view->details->feedback_text, "Retreiving services list ...");
		}
		if (counter == 20000) {
			go_to_uri (view->details->nautilus_view, "eazel-login:");
		}
		else {
			gtk_progress_bar_update (GTK_PROGRESS_BAR (view->details->progress_bar), value);
			while (gtk_events_pending ()) {
				gtk_main_iteration ();
			}
		}
	}

}

static void 
generate_form_logo (NautilusServiceStartupView	*view) {

	GtkWidget	*logo_container;
	GtkWidget	*logo_widget;

	logo_container = gtk_hbox_new (TRUE, 0);
	gtk_box_pack_start (GTK_BOX (view->details->form), logo_container, 0, 0, 4);	

	logo_widget = create_image_widget ("startup-logo.png",
					   STARTUP_VIEW_DEFAULT_BACKGROUND_COLOR,
					   NAUTILUS_IMAGE_PLACEMENT_CENTER);

	g_assert (logo_widget != NULL);

	gtk_box_pack_start (GTK_BOX(logo_container), logo_widget, 0, 0, 4);
	gtk_widget_show_all (logo_container);
}

static void
nautilus_service_startup_view_initialize_class (NautilusServiceStartupViewClass	*klass) {

	GtkObjectClass	*object_class;
	GtkWidgetClass	*widget_class;
	
	object_class = GTK_OBJECT_CLASS (klass);
	widget_class = GTK_WIDGET_CLASS (klass);
 	parent_class = gtk_type_class (gtk_event_box_get_type ());
	object_class->destroy = nautilus_service_startup_view_destroy;
}

static void
nautilus_service_startup_view_initialize (NautilusServiceStartupView	*view) {

  	NautilusBackground	*background;

	view->details = g_new0 (NautilusServiceStartupViewDetails, 1);
	view->details->nautilus_view = nautilus_view_new (GTK_WIDGET (view));
	gtk_signal_connect (GTK_OBJECT (view->details->nautilus_view), 
			    "load_location",
			    GTK_SIGNAL_FUNC (service_load_location_callback),
			    view);

  	background = nautilus_get_widget_background (GTK_WIDGET (view));
  	nautilus_background_set_color (background, STARTUP_VIEW_DEFAULT_BACKGROUND_COLOR);

	gtk_widget_show_all (GTK_WIDGET (view));
}

static void
nautilus_service_startup_view_destroy (GtkObject	*object) {

	NautilusServiceStartupView	*view;

	view = NAUTILUS_SERVICE_STARTUP_VIEW (object);

	g_free (view->details->uri);
	g_free (view->details);

	NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}

/* Component embedding support */
NautilusView *
nautilus_service_startup_view_get_nautilus_view (NautilusServiceStartupView	*view) {

	return view->details->nautilus_view;

}

/* URI handling */
void
nautilus_service_startup_view_load_uri (NautilusServiceStartupView	*view,
				        const char			*uri) {

	char	*document_name;
	
	/* dispose of the old uri and copy the new one */
	g_free (view->details->uri);
	view->details->uri = g_strdup (uri);

	/* dispose of any old form that was installed */
	if (view->details->form != NULL) {
		gtk_widget_destroy (view->details->form);
		view->details->form = NULL;
	}

	/* extract the document part of the uri */
	document_name = strchr (uri, ':');

	/* load the appropriate form, based on the uri and the registration state */
	if (is_location (document_name, "startup")) {
		generate_startup_form (view);
	}
	else if (is_location (document_name, "login")) {
		go_to_uri (view->details->nautilus_view, "eazel-login:");
	}
	else if (is_location(document_name, "summary")) {
		go_to_uri (view->details->nautilus_view, "eazel-summary:");
	}
	else if (is_location(document_name, "inventory")) {
		go_to_uri (view->details->nautilus_view, "eazel-inventory:");
	}
	else if (is_location(document_name, "install")) {
		go_to_uri (view->details->nautilus_view, "eazel-install:");
	}
	else if (is_location(document_name, "time")) {
		go_to_uri (view->details->nautilus_view, "eazel-time:");
	}
	else if (is_location(document_name, "vault")) {
		go_to_uri (view->details->nautilus_view, "eazel-vault:");
	}
	else if (is_location(document_name, "register")) {
		go_to_uri (view->details->nautilus_view, "http://www.eazel.com");
	}
	else {
		generate_startup_form (view); /* eventually, this should be setup_bad_location_form */
	}
}

static void
service_load_location_callback (NautilusView			*view,
				const char			*location,
				NautilusServiceStartupView	*services) {

	nautilus_view_report_load_underway (services->details->nautilus_view);
	nautilus_service_startup_view_load_uri (services, location);
	nautilus_view_report_load_complete (services->details->nautilus_view);
}