libgnumeric.c 7.48 KB
Newer Older
1
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 3 4 5 6 7 8 9
/*
 * Gnumeric, the GNOME spreadsheet.
 *
 * Main file, startup code.
 *
 * Author:
 *   Miguel de Icaza (miguel@gnu.org)
 */
10
#include <gnumeric-config.h>
Arturo Espinosa's avatar
Arturo Espinosa committed
11
#include "gnumeric.h"
Jody Goldberg's avatar
Jody Goldberg committed
12
#include "main.h"
13 14

#include "stf.h"
15
#include "plugin.h"
16
#include "format.h"
17
#include "formats.h"
18
#include "command-context.h"
19
#include "workbook.h"
20
#include "workbook-control-gui.h"
21
#include "workbook-view.h"
22
#include "sheet-object.h"
Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
23
#include "number-match.h"
24
#include "main.h"
25
#include "expr-name.h"
26
#include "func.h"
27
#include "application.h"
28
#include "print-info.h"
29
#include "global-gnome-font.h"
Morten Welinder's avatar
Morten Welinder committed
30
#include "auto-format.h"
Jody Goldberg's avatar
Jody Goldberg committed
31
#include "style.h"
32
#include "style-color.h"
Jody Goldberg's avatar
Jody Goldberg committed
33
#include "str.h"
Jody Goldberg's avatar
Jody Goldberg committed
34
#include "eval.h"
35 36
#include "sheet-autofill.h"
#include "xml-io.h"
Arturo Espinosa's avatar
Arturo Espinosa committed
37

38 39 40 41 42 43 44 45 46 47 48
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <glib.h>
#include <locale.h>
#ifdef ENABLE_BONOBO
#include "bonobo-io.h"
/* DO NOT include embeddable-grid.h.  It causes odd depends in the non-bonobo
 * case */
extern gboolean EmbeddableGridFactory_init (void);
#endif
Jody Goldberg's avatar
Jody Goldberg committed
49
#include <gal/widgets/e-cursors.h>
50
#include <glade/glade.h>
Mark Probst's avatar
Mark Probst committed
51

Jody Goldberg's avatar
fix.  
Jody Goldberg committed
52 53
#include <libgnome/gnome-config.h>

Jacob Berkman's avatar
Jacob Berkman committed
54 55 56 57
#ifdef USE_WM_ICONS
#include <libgnomeui/gnome-window-icon.h>
#endif

58 59 60 61
#ifdef ENABLE_BONOBO
#include <bonobo.h>
#endif

62 63
/* The debugging level */
int gnumeric_debugging = 0;
64
int style_debugging = 0;
Michael Meeks's avatar
Michael Meeks committed
65
int dependency_debugging = 0;
66
int immediate_exit_flag = 0;
67
int print_debugging = 0;
68
gboolean initial_workbook_open_complete = FALSE;
69
extern gboolean libole2_debug;
70

Elliot Lee's avatar
Elliot Lee committed
71
static char *dump_file_name = NULL;
72
static const char **startup_files = NULL;
73 74 75
static int gnumeric_show_version = FALSE;
char *gnumeric_lib_dir = GNUMERIC_LIBDIR;
char *gnumeric_data_dir = GNUMERIC_DATADIR;
76
char *x_geometry;
77

78
poptContext ctx;
Miguel de Icaza's avatar
Miguel de Icaza committed
79

80 81
const struct poptOption
gnumeric_popt_options[] = {
82 83 84 85 86 87 88
	{ "version", 'v', POPT_ARG_NONE, &gnumeric_show_version, 0,
	  N_("Display Gnumeric's version"), NULL  },
	{ "lib-dir", 'L', POPT_ARG_STRING, &gnumeric_lib_dir, 0,
	  N_("Set the root library directory"), NULL  },
	{ "data-dir", 'D', POPT_ARG_STRING, &gnumeric_data_dir, 0,
	  N_("Adjust the root data directory"), NULL  },

89
	{ "dump-func-defs", '\0', POPT_ARG_STRING, &dump_file_name, 0,
90
	  N_("Dumps the function definitions"),   N_("FILE") },
Michael Meeks's avatar
Michael Meeks committed
91

92 93
	{ "debug", '\0', POPT_ARG_INT, &gnumeric_debugging, 0,
	  N_("Enables some debugging functions"), N_("LEVEL") },
Michael Meeks's avatar
Michael Meeks committed
94 95 96

	{ "debug_deps", '\0', POPT_ARG_INT, &dependency_debugging, 0,
	  N_("Enables some dependency related debugging functions"), N_("LEVEL") },
97
	{ "debug_print", '\0', POPT_ARG_INT, &print_debugging, 0,
Karl Eichwalder's avatar
Karl Eichwalder committed
98
	  N_("Enables some print debugging behavior"), N_("LEVEL") },
Michael Meeks's avatar
Michael Meeks committed
99

100 101
	{ "debug_ole", '\0', POPT_ARG_NONE,
	    &libole2_debug, 0,
Karl Eichwalder's avatar
Typo.  
Karl Eichwalder committed
102
	  N_("Enables extra consistency checking while reading ole files"),
103
	  NULL  },
Michael Meeks's avatar
Michael Meeks committed
104

105
	{ "geometry", 'g', POPT_ARG_STRING, &x_geometry, 0,
106 107 108 109 110
	  N_("Specify the size and location of the initial window"), N_("WIDTHxHEIGHT+XOFF+YOFF")  
	},

	{ "quit", '\0', POPT_ARG_NONE, &immediate_exit_flag, 0,
	  N_("Exit immediately after loading the selected books (useful for testing)."), NULL },
111

112
	{ NULL, '\0', 0, NULL, 0 }
113 114
};

115 116 117 118 119
static void
handle_paint_events (void)
{
	/* FIXME: we need to mask input events correctly here */
	/* Show something coherent */
120 121
	while (gtk_events_pending () && !initial_workbook_open_complete)
		gtk_main_iteration_do (FALSE);
122 123
}

Morten Welinder's avatar
Morten Welinder committed
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

static void
warn_about_ancient_gnumerics (const char *binary, WorkbookControl *wbc)
{
	struct stat buf;
	time_t now = time (NULL);
	int days = 180;

	if (binary &&
	    stat (binary, &buf) != -1 &&
	    buf.st_mtime != -1 &&
	    now - buf.st_mtime > days * 24 * 60 * 60) {
		handle_paint_events ();

		gnumeric_error_system (COMMAND_CONTEXT (wbc),
				       _("Thank you for using Gnumeric!\n"
					 "\n"
					 "The version of Gnumeric you are using is quite old\n"
					 "by now.  It is likely that many bugs have been fixed\n"
					 "and that new features have been added in the meantime.\n"
					 "\n"
					 "Please consider upgrading before reporting any bugs.\n"
					 "Consult http://www.gnumeric.org/ for details.\n"
					 "\n"
					 "-- The Gnumeric Team."));
	}
}



154 155 156 157 158 159 160 161 162 163 164 165 166
#if 0
static void
gnumeric_check_for_components (void)
{
	OAF_ServerInfoList *result;

	result = oaf_query ("repo_ids.has('IDL::1.0')", NULL, NULL);

	g_return_if_fail (result != NULL);

	CORBA_free (info_list);
}
#endif
Miguel de Icaza's avatar
Miguel de Icaza committed
167

168 169 170 171
/*
 * FIXME: We hardcode the GUI command context. Change once we are able
 * to tell whether we are in GUI or not.
 */
172 173
int
main (int argc, char *argv [])
Arturo Espinosa's avatar
Arturo Espinosa committed
174
{
175
	gboolean opened_workbook = FALSE;
176
	WorkbookControl *wbc;
177
	const char *gnumeric_binary = argv[0];
Morten Welinder's avatar
Morten Welinder committed
178

179 180 181
	/* Make stdout line buffered - we only use it for debug info */
	setvbuf (stdout, NULL, _IOLBF, 0);

182 183
	bindtextdomain (PACKAGE, GNOMELOCALEDIR);
	textdomain (PACKAGE);
184

185 186 187 188 189
	/* Force all of the locale segments to update from the environment.
	 * Unless we do this they will default to C
	 */
	setlocale (LC_ALL, "");

190
	gnumeric_arg_parse (argc, argv);
191

192
	if (gnumeric_show_version) {
Jody Goldberg's avatar
Jody Goldberg committed
193
		printf (_("gnumeric version '%s'\ndatadir := '%s'\nlibdir := '%s'\n"),
194
			GNUMERIC_VERSION, GNUMERIC_DATADIR, GNUMERIC_LIBDIR);
195
		return 0;
196
	}
Jacob Berkman's avatar
Jacob Berkman committed
197
#ifdef USE_WM_ICONS
198
	gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/gnome-gnumeric.png");
Jacob Berkman's avatar
Jacob Berkman committed
199
#endif
Jon K Hellan's avatar
Jon K Hellan committed
200

201
	application_init ();
Jody Goldberg's avatar
Jody Goldberg committed
202
	dependent_types_init ();
203
	string_init ();
204
	style_init ();
Morten Welinder's avatar
Morten Welinder committed
205
	gnumeric_color_init ();
206
	format_color_init ();
Jody Goldberg's avatar
Jody Goldberg committed
207
	format_match_init ();
208
	e_cursors_init ();
Morten Welinder's avatar
Morten Welinder committed
209
	auto_format_init ();
Arturo Espinosa's avatar
Arturo Espinosa committed
210
	functions_init ();
211
	expr_name_init ();
212
	print_init ();
213
	autofill_init ();
214
	sheet_object_register ();
215

216 217
	/* The statically linked in file formats */
	xml_init ();
218
	stf_init ();
219 220 221
#ifdef ENABLE_BONOBO
	gnumeric_bonobo_io_init ();
#endif
222

223 224
	global_gnome_font_init ();

Jody Goldberg's avatar
Jody Goldberg committed
225 226 227 228
	/* Ignore Shift for accelerators to avoid problems with different
	 * keyboard layouts that change the shift state of various keys.
	 *
	 * WARNING : This means that Shift-Space is not valid accelerator.
229
	 */
Jody Goldberg's avatar
Jody Goldberg committed
230 231
	gtk_accelerator_set_default_mod_mask (
		gtk_accelerator_get_default_mod_mask() & ~GDK_SHIFT_MASK);
232

233
	/* Glade */
Jody Goldberg's avatar
Jody Goldberg committed
234
	glade_gnome_init ();
Morten Welinder's avatar
Morten Welinder committed
235

Michael Meeks's avatar
Michael Meeks committed
236 237
	if (dump_file_name) {
		function_dump_defs (dump_file_name);
238
		exit (0);
239 240
	}

241
#ifdef ENABLE_BONOBO
242
#if 0
243 244 245
	/* Activate object factories and init connections to POA */
	if (!WorkbookFactory_init ())
		g_warning (_("Could not initialize Workbook factory"));
246
#endif
247 248 249 250 251 252

	if (!EmbeddableGridFactory_init ())
		g_warning (_("Could not initialize EmbeddableGrid factory"));
#endif

	/* Load selected files */
Michael Meeks's avatar
Michael Meeks committed
253 254 255 256 257
	if (ctx)
		startup_files = poptGetArgs (ctx);
	else
		startup_files = NULL;

258 259 260
#ifdef ENABLE_BONOBO
	bonobo_activate ();
#endif
261 262
 	wbc = workbook_control_gui_new (NULL, NULL);
 	plugins_init (COMMAND_CONTEXT (wbc));
263 264
	if (startup_files) {
		int i;
265
		for (i = 0; startup_files [i]  && !initial_workbook_open_complete ; i++) {
266 267
 			if (wb_view_open (wb_control_view (wbc), wbc,
					  startup_files[i], TRUE))
268
  				opened_workbook = TRUE;
269

270
			handle_paint_events ();
Elliot Lee's avatar
Elliot Lee committed
271
		}
272 273
	}

Michael Meeks's avatar
Michael Meeks committed
274 275
	if (ctx)
		poptFreeContext (ctx);
Morten Welinder's avatar
Morten Welinder committed
276

277 278 279
	/* If we were intentionally short circuited exit now */
	if (!initial_workbook_open_complete && !immediate_exit_flag) {
		initial_workbook_open_complete = TRUE;
280
		if (!opened_workbook) {
281
			workbook_sheet_add (wb_control_workbook (wbc),
282
					    NULL, FALSE);
283 284 285
			handle_paint_events ();
		}

Morten Welinder's avatar
Morten Welinder committed
286
		warn_about_ancient_gnumerics (gnumeric_binary, wbc);
287

288
		gtk_main ();
289
	}
Arturo Espinosa's avatar
Arturo Espinosa committed
290

291
	plugins_shutdown ();
292
	print_shutdown ();
Morten Welinder's avatar
Morten Welinder committed
293
	auto_format_shutdown ();
294
	e_cursors_shutdown ();
Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
295
	format_match_finish ();
296
	format_color_shutdown ();
297
	gnumeric_color_shutdown ();
Morten Welinder's avatar
Morten Welinder committed
298
	style_shutdown ();
Jody Goldberg's avatar
Jody Goldberg committed
299
	dependent_types_shutdown ();
Miguel de Icaza's avatar
Miguel de Icaza committed
300

301 302
	global_gnome_font_shutdown ();

Miguel de Icaza's avatar
Miguel de Icaza committed
303
	gnome_config_drop_all ();
304

Mark Probst's avatar
Mark Probst committed
305 306
	return 0;
}