summaryrefslogtreecommitdiff
path: root/components/services/install/server/main.c
blob: f458252e4746bc5cb9a57fc98ee931feb207c3fa (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
/* -*- 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: Eskil Heyn Olsen <eskil@eazel.com>
 *
 */

#undef STOP_IN_DEBUG

#include <config.h>
#include <gnome.h>
#include <liboaf/liboaf.h>
#include <bonobo.h>
#include <signal.h>

#include <libtrilobite/libtrilobite-service.h>
#include <libtrilobite/libtrilobite.h>

#ifdef STOP_IN_DEBUG
/* Also add 
	$(top_builddir)/libnautilus-extensions/nautilus-debug.o				 	\
to the ldadd line in Makefile.am
*/
#include <eel/eel-debug.h>
#endif

#include <trilobite-eazel-install.h>
#include <eazel-install-public.h>

#include <libgnomevfs/gnome-vfs.h>

#define OAF_ID_FACTORY "OAFIID:trilobite_eazel_install_service_factory:b423ff3f-1941-4b0d-bd45-6542f64abbfc"
#define OAF_ID "OAFIID:trilobite_eazel_install_service:8ff6e815-1992-437c-9771-d932db3b4a17"

/*
  These are some generally needed objects to get CORBA connectivity
*/
CORBA_ORB                 orb;
CORBA_Environment         ev;

static BonoboGenericFactory *factory;
static int trilobites_active = 0;

static void trilobite_service_factory_destroy (GtkObject *object);
static void sig_segv_handler (int);

static void 
sig_segv_handler (int roedgroed_med_floede)
{
	g_error ("Crash: Install server hit a sigsegv");
}

static void
trilobite_service_factory_destroy (GtkObject *object) 
{
	trilobites_active--;

	trilobite_debug ("destroy, eazel_install trilobites active = %d", trilobites_active);
	if (trilobites_active != 0) {
		return;
	}

	trilobite_debug ("Destroying factory object");

	bonobo_object_unref (BONOBO_OBJECT (factory)); 
	trilobite_main_quit ();
}

static BonoboObject*
eazel_install_service_factory (BonoboGenericFactory *this_factory, 
			       const gchar *oaf_id,
			       gpointer data) 
{
	TrilobiteService *trilobite;
	TrilobitePasswordQuery *trilobite_password;

	EazelInstall *service;
	if (strcmp (oaf_id, OAF_ID)) {
		g_warning ("Unhandled OAF id %s", oaf_id);
		return NULL;
	}

	trilobite = TRILOBITE_SERVICE (gtk_object_new (TRILOBITE_TYPE_SERVICE,
						       "name", "Install",
						       "version", "0.1",
						       "vendor_name", "Eazel, inc.",
						       "vendor_url", "http://www.eazel.com",
						       "url", "http://www.eazel.com/",
						       "icon", "file:///gnome/share/pixmaps/gnome-default-dlg.png",
						       NULL));

	trilobite_password = TRILOBITE_PASSWORDQUERY (gtk_object_new (TRILOBITE_TYPE_PASSWORDQUERY, 
								      "prompt", "root", 
								      NULL));

	service = eazel_install_new_with_config ();

	g_assert (trilobite != NULL);
	g_assert (service != NULL);

	trilobites_active++;

	trilobite_service_add_interface (trilobite, BONOBO_OBJECT (service));
	trilobite_passwordquery_add_interface (trilobite_password, BONOBO_OBJECT (service));
	
	gtk_signal_connect (GTK_OBJECT (trilobite),
			    "destroy",
			    trilobite_service_factory_destroy, NULL);

	return BONOBO_OBJECT (trilobite);
}

int main(int argc, char *argv[]) {

#ifdef ENABLE_NLS /* sadly we need this ifdef because otherwise the following get empty statement warnings */
	bindtextdomain (PACKAGE, GNOMELOCALEDIR);
	textdomain (PACKAGE);
#endif

	/* Disable session manager connection */
	gnome_client_disable_master_connection ();

	signal (SIGSEGV, &sig_segv_handler);

	if (!trilobite_init ("trilobite-eazel-install-service", "0.1", "~/.nautilus/trilobite-install.log",
			     NULL, argc, argv)) {
		g_error ("Could not initialise trilobite. :(");
		exit (1);
	}
	trilobite_set_debug_mode (TRUE);

	gnome_vfs_init ();

	factory = bonobo_generic_factory_new_multi (OAF_ID_FACTORY, 
						    eazel_install_service_factory,
						    NULL);
	
	if (factory == NULL) {
		g_error ("Could not register factory");
	}

#ifdef STOP_IN_DEBUG
	eel_make_warnings_and_criticals_stop_in_debugger ("GLib", NULL);
#endif

	do {
		bonobo_activate ();
		trilobite_main ();
	} while (trilobites_active > 0);

	g_message ("EazelInstall service terminating");

	CORBA_exception_free (&ev);

	return 0;
};