summaryrefslogtreecommitdiff
path: root/src/nautilus-window-service-ui.c
blob: 868ed0a02c1bd4bab59d5d916b02466d6a9881dd (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
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-

   nautilus-service-ui.c: integrate the built-in service ui
 
   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.
  
   Author: Andy Hertzfeld <andy@eazel.com>
*/

#include <config.h>
#include "nautilus-window-service-ui.h"

#include <bonobo/bonobo-ui-util.h>
#include "nautilus-window-private.h"
#include <gtk/gtksignal.h>
#ifdef EAZEL_SERVICES
#include <libtrilobite/libammonite.h>
#include <bonobo/bonobo-main.h>

static void
goto_services_summary (BonoboUIComponent *component, 
		       gpointer callback_data, 
		       const char *verb)
{
	nautilus_window_go_to (NAUTILUS_WINDOW (callback_data),
			       "eazel:");
}

static void
goto_online_storage (BonoboUIComponent *component, 
		     gpointer callback_data, 
		     const char *verb)
{
	char			*url;
	char			*user_name;

	if ( ammonite_init (bonobo_poa())) {
		user_name = ammonite_get_default_user_username ();
	} else {
		user_name = NULL;
	}

	if (user_name == NULL) {
		url = g_strdup ("eazel:");
		/* FIXME bugzilla.eazel.com 5036: user feedback needs to be displayed in this case */
		/* Something better than just going to the summary page */

	} else {
		url = g_strdup_printf ("eazel-services:///~%s", user_name);
		g_free (user_name);
		user_name = NULL;
	}
	nautilus_window_go_to (NAUTILUS_WINDOW (callback_data), url);
	g_free (url);
	url = NULL;
}

static void
goto_software_catalog (BonoboUIComponent *component, 
		       gpointer callback_data, 
		       const char *verb)
{
	char			*url;
	gboolean		logged_in;
	char 			*user_name;

	if (ammonite_init (bonobo_poa())) {
		user_name = ammonite_get_default_user_username ();

		logged_in = (NULL != user_name);
		g_free (user_name);
	} else {
		logged_in = FALSE;
	}


	if (!logged_in) {
		url = g_strdup ("eazel-services://anonymous/catalog");
	} else {
		url = g_strdup ("eazel-services:///catalog");
	}

	nautilus_window_go_to (NAUTILUS_WINDOW (callback_data), url);
	g_free (url);
	url = NULL;

}

static void
detach_service_ui (GtkObject *object,
		   gpointer callback_data)
{
	BonoboUIComponent *service_ui;

	service_ui = BONOBO_UI_COMPONENT (callback_data);
	bonobo_ui_component_unset_container (service_ui);
	bonobo_object_unref (BONOBO_OBJECT (service_ui));
}

void
nautilus_window_install_service_ui (NautilusWindow *window)
{
	BonoboUIComponent *service_ui;
	
	BonoboUIVerb verbs [] = {
		BONOBO_UI_VERB ("Eazel Services", goto_services_summary),
		BONOBO_UI_VERB ("Online Storage", goto_online_storage),
		BONOBO_UI_VERB ("Software Catalog", goto_software_catalog),
		BONOBO_UI_VERB_END
	};

	/* Load UI from the XML file. */
	service_ui = bonobo_ui_component_new ("Eazel Services");
	bonobo_ui_component_add_verb_list_with_data (service_ui, verbs, window);
	bonobo_ui_component_set_container
		(service_ui,
		 nautilus_window_get_ui_container (window));
	bonobo_ui_component_freeze (service_ui, NULL);
	bonobo_ui_util_set_ui (service_ui,
			       DATADIR,
			       "nautilus-service-ui.xml",
			       "nautilus");
	bonobo_ui_component_thaw (service_ui, NULL);

	/* Get rid of the UI when the window goes away. */
	gtk_signal_connect (GTK_OBJECT (window),
			    "destroy",
			    detach_service_ui,
			    service_ui);
}

#endif