3 * Copyright (C) 2004 Jan Kratochvil <project-udpgate@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <glib/gmessages.h>
26 #include <glib/gutils.h>
30 #include <libgnome/gnome-program.h>
31 #include <libgnomeui/gnome-ui-init.h>
37 static int optarg_text;
39 static const struct poptOption popt_table[]={
41 #define UDPGATE_POPT(shortname,longname,argInfoP,argP,valP,descripP,argDescripP) \
43 longName: (longname), \
44 shortName: (shortname), \
45 argInfo: (argInfoP)|(!(valP) ? 0 : POPT_ARG_VAL), \
48 descrip: (descripP), \
49 argDescrip: (argDescripP), \
52 UDPGATE_POPT(0 ,"text" ,POPT_ARG_NONE ,&optarg_text ,0,
53 N_("Disable Gnome UI; --text must be first argument"),NULL),
54 UDPGATE_POPT('v',"verbose" ,POPT_ARG_NONE ,&optarg_verbose,0,N_("Display additional debug information"),NULL),
60 static const struct poptOption popt_table_autohelp[]={
61 { NULL,'\0',POPT_ARG_INCLUDE_TABLE,(struct poptOption *)&popt_table,0,PACKAGE },
67 static jmp_buf gnome_init_atexit_jmpbuf;
68 static gboolean gnome_init_atexit_disable;
70 static void gnome_init_atexit_handler(void)
72 if (gnome_init_atexit_disable)
75 longjmp(gnome_init_atexit_jmpbuf,1);
76 g_assert_not_reached();
80 static gboolean gnome_init_g_log_handler_hit;
81 static void gnome_init_g_log_handler(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
83 gnome_init_g_log_handler_hit=TRUE;
84 g_log_default_handler(log_domain,log_level,message,user_data);
87 int main(int argc,char **argv)
91 gboolean is_interactive;
95 g_log_set_always_fatal(~(0
102 /* Initialize the i18n stuff */
103 setlocale(LC_ALL,"");
104 bindtextdomain(PACKAGE,LOCALEDIR);
107 if (argv[1] && !strcmp(argv[1],"--text"))
110 no_gnome=(optarg_text || !getenv("DISPLAY") || !*getenv("DISPLAY"));
113 context=poptGetContext(
115 argc,(/*en-const*/const char **)argv, /* argc,argv */
116 popt_table_autohelp, /* options */
117 POPT_CONTEXT_POSIXMEHARDER); /* flags; && !POPT_CONTEXT_KEEP_FIRST */
119 g_assert_not_reached(); /* argument recognization args_error */
122 errint=poptReadDefaultConfig(context,
125 g_assert_not_reached(); /* argument recognization args_error */
128 errint=poptGetNextOpt(context);
130 g_assert_not_reached(); /* some non-callbacked argument reached */
133 if (poptPeekArg(context)) {
134 g_error(_("No arguments expected"));
139 GnomeProgram *gnome_program;
142 gnome_init_atexit_disable=FALSE;
143 g_atexit(gnome_init_atexit_handler);
144 gnome_init_g_log_handler_hit=FALSE;
145 handler_id=g_log_set_handler(
146 "Gtk", /* log_domain */
147 G_LOG_LEVEL_WARNING, /* log_levels */
148 gnome_init_g_log_handler, /* log_func */
149 NULL); /* user_data */
150 if (!setjmp(gnome_init_atexit_jmpbuf))
151 gnome_program=gnome_program_init(PACKAGE,VERSION,LIBGNOMEUI_MODULE,argc,argv,
152 GNOME_PARAM_POPT_TABLE,popt_table,
153 GNOME_PARAM_POPT_FLAGS,(int)POPT_CONTEXT_POSIXMEHARDER,
157 /* No message: (captive-install-acquire:3693): Gtk-WARNING **: cannot open display:
158 * was reported, probably only '--help' message was shown.
160 if (!gnome_init_g_log_handler_hit)
163 gnome_init_atexit_disable=TRUE;
164 g_log_remove_handler(
165 "Gtk", /* log_domain */
166 handler_id); /* handler_id */
170 /* && ! optarg_scan_path_list
171 && ! optarg_scan_disks_quick
172 && ! optarg_scan_disks
173 && ! optarg_microsoft_com */ );
175 /* Initialize UI here to catch all GLog errors below. */
177 && (no_gnome || !ui_gnome_init())
178 /* && !ui_line_init()*/)
179 g_error(_("No UI interface could be initialized"));
184 ui_gnome_interactive();