libgnumeric.c 7.68 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
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
Jody Goldberg's avatar
Jody Goldberg committed
41 42
#include <time.h>
#include <gtk/gtkmain.h>
43 44 45 46 47 48 49
#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
50
#include <gal/widgets/e-cursors.h>
51
#include <glade/glade.h>
Mark Probst's avatar
Mark Probst committed
52

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

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

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

63 64
/* The debugging level */
int gnumeric_debugging = 0;
65
int style_debugging = 0;
Michael Meeks's avatar
Michael Meeks committed
66
int dependency_debugging = 0;
67
int immediate_exit_flag = 0;
68
int print_debugging = 0;
69
gboolean initial_workbook_open_complete = FALSE;
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 79
const struct poptOption
gnumeric_popt_options[] = {
80 81 82 83 84 85 86
	{ "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  },

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

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

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

98
	{ "geometry", 'g', POPT_ARG_STRING, &x_geometry, 0,
Jody Goldberg's avatar
Jody Goldberg committed
99
	  N_("Specify the size and location of the initial window"), N_("WIDTHxHEIGHT+XOFF+YOFF")
100 101 102 103
	},

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

105
	{ NULL, '\0', 0, NULL, 0 }
106 107
};

108 109 110 111 112
static void
handle_paint_events (void)
{
	/* FIXME: we need to mask input events correctly here */
	/* Show something coherent */
113 114
	while (gtk_events_pending () && !initial_workbook_open_complete)
		gtk_main_iteration_do (FALSE);
115 116
}

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

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."));
	}
}



147 148 149 150 151 152 153 154 155 156 157 158 159
#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
160

161 162 163 164
/*
 * FIXME: We hardcode the GUI command context. Change once we are able
 * to tell whether we are in GUI or not.
 */
165 166
int
main (int argc, char *argv [])
Arturo Espinosa's avatar
Arturo Espinosa committed
167
{
Jody Goldberg's avatar
Jody Goldberg committed
168
	poptContext ctx;
169
	gboolean opened_workbook = FALSE;
170
	WorkbookControl *wbc;
Jody Goldberg's avatar
Jody Goldberg committed
171
	char const *gnumeric_binary = argv[0];
Morten Welinder's avatar
Morten Welinder committed
172

173 174 175
	/* Make stdout line buffered - we only use it for debug info */
	setvbuf (stdout, NULL, _IOLBF, 0);

Jody Goldberg's avatar
Jody Goldberg committed
176
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
177 178
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
179

180 181 182 183 184
	/* Force all of the locale segments to update from the environment.
	 * Unless we do this they will default to C
	 */
	setlocale (LC_ALL, "");

Jody Goldberg's avatar
Jody Goldberg committed
185
	ctx = gnumeric_arg_parse (argc, argv);
186

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

196
	application_init ();
Jody Goldberg's avatar
Jody Goldberg committed
197
	dependent_types_init ();
198
	string_init ();
199
	style_init ();
Morten Welinder's avatar
Morten Welinder committed
200
	gnumeric_color_init ();
201
	format_color_init ();
Jody Goldberg's avatar
Jody Goldberg committed
202
	format_match_init ();
203
	e_cursors_init ();
Morten Welinder's avatar
Morten Welinder committed
204
	auto_format_init ();
Arturo Espinosa's avatar
Arturo Espinosa committed
205
	functions_init ();
206
	expr_name_init ();
207
	print_init ();
208
	autofill_init ();
209
	sheet_object_register ();
210

211 212
	/* The statically linked in file formats */
	xml_init ();
213
	stf_init ();
214 215 216
#ifdef ENABLE_BONOBO
	gnumeric_bonobo_io_init ();
#endif
217

218 219
	global_gnome_font_init ();

220 221 222 223 224 225 226 227
#if 0
	/* 2/Feb/2002 JEG
	 * disable the code below and pray for a solution to 50300
	 * With it enabled treeview (and probably other widgets) get
	 * confused and register duplicate bindings for the shifted and non
	 * shifted versions.  When we disable shift, things go to hell
	 * and happen twice.
	 */
Jody Goldberg's avatar
Jody Goldberg committed
228 229 230 231
	/* 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.
232
	 */
Jody Goldberg's avatar
Jody Goldberg committed
233 234
	gtk_accelerator_set_default_mod_mask (
		gtk_accelerator_get_default_mod_mask() & ~GDK_SHIFT_MASK);
235
#endif
236

Jody Goldberg's avatar
Jody Goldberg committed
237
	glade_gnome_init ();
Morten Welinder's avatar
Morten Welinder committed
238

Michael Meeks's avatar
Michael Meeks committed
239 240
	if (dump_file_name) {
		function_dump_defs (dump_file_name);
241
		exit (0);
242 243
	}

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

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

	/* Load selected files */
Michael Meeks's avatar
Michael Meeks committed
256 257 258 259 260
	if (ctx)
		startup_files = poptGetArgs (ctx);
	else
		startup_files = NULL;

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

273
			handle_paint_events ();
Elliot Lee's avatar
Elliot Lee committed
274
		}
275 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;
}