summaryrefslogtreecommitdiff
path: root/src/yelp-main.c
blob: 095d21ca2a19132470e5258c11e2e36f16dd5f3b (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2001 Mikael Hallendal <micke@codefactory.se>
 *
 * 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: Mikael Hallendal <micke@codefactory.se>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtkmain.h>
#include <gtk/gtkwidget.h>
#include <bonobo/bonobo-context.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-generic-factory.h>
#include <bonobo/bonobo-main.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-program.h>
#include <libgnomeui/gnome-ui-init.h>
#include <libgnomevfs/gnome-vfs.h>
#include "yelp-window.h"
#include "GNOME_Yelp.h"
#include "yelp-base.h"

#define YELP_FACTORY_OAFIID "OAFIID:GNOME_Yelp_Factory"

static BonoboObject * yelp_base_factory       (BonoboGenericFactory *factory,
					      const gchar           *iid,
					      gpointer               closure);
static CORBA_Object   yelp_main_activate_base (void);
static gboolean       yelp_main_idle_start    (gpointer              data);

static BonoboObject *
yelp_base_factory (BonoboGenericFactory *factory,
		   const gchar          *iid,
		   gpointer              closure)
{
	static YelpBase *yelp_base = NULL;

	if (!yelp_base) {
		yelp_base = yelp_base_new ();
	} else { 
		bonobo_object_ref (BONOBO_OBJECT (yelp_base));
	}

	return BONOBO_OBJECT (yelp_base);
}

static CORBA_Object
yelp_main_activate_base ()
{
	CORBA_Environment ev;
	CORBA_Object      yelp_base;
	
	CORBA_exception_init (&ev);
	
	yelp_base = bonobo_activation_activate_from_id ("OAFIID:GNOME_Yelp",
							0, NULL, &ev);
	
	if (BONOBO_EX (&ev) || yelp_base == CORBA_OBJECT_NIL) {
		g_warning (_("Could not activate Yelp: '%s'"),
			   bonobo_exception_get_text (&ev));
		exit (1);
	}

	CORBA_exception_free (&ev);
	
	return yelp_base;
}

static void
yelp_main_open_new_window (CORBA_Object yelp_base)
{
	CORBA_Environment ev;
	
	CORBA_exception_init (&ev);
	
	GNOME_Yelp_newWindow (yelp_base, &ev);
	
	if (BONOBO_EX (&ev)) {
		g_warning (_("Could not open new window."));
		exit (1);
	}

	CORBA_exception_free (&ev);
}
	
static void
yelp_main_start () 
{
	CORBA_Object yelp_base;
	
	yelp_base = yelp_main_activate_base ();

	if (!yelp_base) {
		g_error ("Couldn't activate YelpBase");
	}
	
	yelp_main_open_new_window (yelp_base);
	
	bonobo_object_release_unref (yelp_base, NULL);
}

static gboolean
yelp_main_idle_start (gpointer null_data)
{
	CORBA_Object yelp_base;
	
	yelp_base = yelp_main_activate_base ();

	if (!yelp_base) {
		g_error ("Couldn't activate YelpBase");
	}

	yelp_main_open_new_window (yelp_base);
	
	return FALSE;
}

int
main (int argc, char **argv) 
{
	GnomeProgram      *program;
	CORBA_Object       factory;
	
#ifdef ENABLE_NLS
	bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);  
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);
#endif 
	g_thread_init (NULL);
	
	program = gnome_program_init (PACKAGE, VERSION,
				      LIBGNOMEUI_MODULE,
				      argc, argv, 
				      GNOME_PROGRAM_STANDARD_PROPERTIES,
				      NULL);

	gnome_vfs_init ();

	factory = bonobo_activation_activate_from_id (YELP_FACTORY_OAFIID,
						      Bonobo_ACTIVATION_FLAG_EXISTING_ONLY, 
						      NULL, NULL);
	
	if (!factory) {
		BonoboGenericFactory   *factory;
		/* Not started, start now */

		g_print ("Creating factory\n");

		factory = bonobo_generic_factory_new (YELP_FACTORY_OAFIID,
						      yelp_base_factory,
						      NULL);

		bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (factory));
		g_idle_add (yelp_main_idle_start, NULL);
		bonobo_main ();
	} else {
		yelp_main_start ();
	}

        return 0;
}