File: screem-main.c

package info (click to toggle)
screem 0.12.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,728 kB
  • ctags: 8,333
  • sloc: ansic: 98,234; sh: 8,278; xml: 2,278; makefile: 1,054
file content (198 lines) | stat: -rw-r--r-- 5,542 bytes parent folder | download
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*  Screem:  screem-main.c
 *
 *  initialisation code, shouldn't do much as most of the init stuff
 *  belongs in screem-application.c
 *
 *  Copyright (C) 2001 David A Knight
 *
 *  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
 *
 *  For contact information with the author of this source code please see
 *  the AUTHORS file.  If there is no AUTHORS file present then check the
 *  about box under the help menu for a contact address
 */

#include <config.h>
#include <gmodule.h>

#include <glib/gi18n.h>
#include <libgnomeui/gnome-ui-init.h>
#include <libgnomeui/gnome-window-icon.h>

#include <gtk/gtk.h>

#include <unistd.h>
#include <errno.h>

#include <glade/glade-init.h>
#include <glade/glade.h>

#include <gconf/gconf.h>

#include <libgnomevfs/gnome-vfs.h>

#include "screem-application.h"
#include "screem-session.h"

#include "fileops.h"
#include "support.h"

ScreemApplication *app;

static gchar *session_filename = SESSION_LAST;

/* passed parameters stuff */
static const struct poptOption options[] = {
	{ "load-session", 'l', POPT_ARG_STRING, &session_filename, 0,
	  N_("Load the given session file"),
	  N_("FILE") },
	{ NULL, '\0', 0, NULL, 0, NULL, NULL }
};

typedef enum {
	MISSING_GLADE,
	MISSING_SCHEMAS,
	MISSING_CONFIG_DIR
} MissingType;

static gboolean screem_main_start_app( const gchar **start_files );
static const gchar** parse_args( poptContext ctx, int argc, char *argv[] );

static void screem_main_missing( MissingType type );

int main( int argc, char *argv[] )
{
	GnomeProgram *program;
	poptContext ctx;
	const gchar** start_files;
	const gchar *icon;
	
	gchar *path;
	gchar *dotdir;
	GConfClient *client;
	
#ifdef ENABLE_NLS
	/* initialise i18n stuff */
        bindtextdomain( GETTEXT_PACKAGE, GNOMELOCALEDIR );
	bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
        textdomain( GETTEXT_PACKAGE );
#endif	
	program = gnome_program_init( PACKAGE, VERSION, 
			LIBGNOMEUI_MODULE,
			argc, argv,
			GNOME_PROGRAM_STANDARD_PROPERTIES,
			GNOME_PARAM_POPT_TABLE, options,
			GNOME_PARAM_APP_DATADIR, DATADIR,
			LIBGNOMEUI_PARAM_DEFAULT_ICON,
			DATADIR"/pixmaps/screem.png",
			GNOME_PARAM_HUMAN_READABLE_NAME,
			_( "Site CReation and Editing EnvironMent" ),
			NULL );

	gdk_threads_init();

	icon = DATADIR"/pixmaps/screem.png";
        gtk_window_set_default_icon_from_file( icon, NULL );

	/* parse arguments */
	g_object_get( G_OBJECT( program ), 
			GNOME_PARAM_POPT_CONTEXT, &ctx, NULL );
	start_files = parse_args( ctx, argc, argv );

        gnome_vfs_init();
	screem_init_vfs_callbacks();

	glade_require( "gnome" );

	/* check schemas are installed, we can access ~/.screem,
	 * and we have a glade file */
	client = gconf_client_get_default();
	dotdir = screem_get_dot_dir();
	path = screem_get_glade_path();
	
	if( ! gconf_client_get_bool( client,
				"/apps/screem/installed",
				NULL ) ) {
		screem_main_missing( MISSING_SCHEMAS );
	} else if( ! uri_accessible( dotdir, GNOME_VFS_PERM_USER_ALL ) ) {
		screem_main_missing( MISSING_CONFIG_DIR );
	} else if( ! uri_exists( path, NULL ) ) {
		screem_main_missing( MISSING_GLADE );
	} else {
		app = screem_application_new();
		
		g_idle_add( (GSourceFunc)screem_main_start_app, 
				start_files );

		gdk_threads_enter();
		gtk_main();
		gdk_threads_leave();

		screem_application_close( app );
		g_object_unref( app );
	}

	g_free( path );
	g_free( dotdir );
	g_object_unref( client );

	gnome_vfs_shutdown();
	
	g_object_unref( program );
	
	return 0;
}

static gboolean screem_main_start_app( const gchar **start_files )
{
	screem_application_startup( app, session_filename, start_files );

	return FALSE;
}

static const gchar **parse_args( poptContext ctx, int argc, char *argv[] )
{
	const gchar** start_files;

        /* passed arguements */
        start_files = poptGetArgs( ctx );

	return start_files;
}

static void screem_main_missing( MissingType type )
{
	const gchar *primary;
	const gchar *secondary;

	primary =_( "Screem was unable to locate one of its files." ); 
	switch( type ) {
		case MISSING_GLADE:
			secondary = _( "The user interface file appears to be missing, this means that screem doesn't appear to have been installed correctly and can not continue." );
			break;
		case MISSING_SCHEMAS:
			secondary = _( "The default configuration could not be found, this means that screem doesn't appear to have been installed correctly and can not continue.  If you have just installed screem then try restarting gconfd." );
			break;
		case MISSING_CONFIG_DIR:
			secondary = _( "~/.screem could not be accessed, check that you, the owner, have read/write/execute permissions. If that directory doesn't exist then you need to make sure you have permissions to create .screem in your home directory." );
			break;
		default:
			secondary = "";
			break;
	}
	
	screem_hig_alert( GTK_STOCK_DIALOG_ERROR,
			primary, secondary, NULL );
}