1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
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.
25
#ifdef HAVE_SYS_PARAM_H
26
#include <sys/param.h>
33
#include <glib-object.h>
35
#include "libgimpbase/gimpbase.h"
37
#include "core/core-types.h"
39
#include "config/gimprc.h"
41
#include "base/base.h"
43
#include "core/gimp.h"
45
#include "file/file-open.h"
46
#include "file/file-utils.h"
48
#ifndef GIMP_CONSOLE_COMPILATION
49
#include "dialogs/user-install-dialog.h"
54
#include "app_procs.h"
59
#include "gimp-intl.h"
66
/* local prototypes */
68
static void app_init_update_none (const gchar *text1,
71
static gboolean app_exit_after_callback (Gimp *gimp,
76
/* public functions */
79
app_libs_init (gboolean *no_interface,
83
#ifdef GIMP_CONSOLE_COMPILATION
91
basename = g_path_get_basename ((*argv)[0]);
92
g_set_prgname (basename);
99
#ifndef GIMP_CONSOLE_COMPILATION
102
return gui_libs_init (argc, argv);
110
app_abort (gboolean no_interface,
111
const gchar *abort_message)
113
#ifndef GIMP_CONSOLE_COMPILATION
117
g_print ("%s\n\n", abort_message);
119
#ifndef GIMP_CONSOLE_COMPILATION
122
gui_abort (abort_message);
126
app_exit (EXIT_FAILURE);
130
app_exit (gint status)
133
/* Give them time to read the message if it was printed in a
134
* separate console window. I would really love to have
135
* some way of asking for confirmation to close the console
141
console = GetStdHandle (STD_OUTPUT_HANDLE);
142
if (GetConsoleMode (console, &mode) != 0)
144
g_print (_("(This console window will close in ten seconds)\n"));
153
app_run (const gchar *full_prog_name,
156
const gchar *alternate_system_gimprc,
157
const gchar *alternate_gimprc,
158
const gchar *session_name,
159
const gchar *batch_interpreter,
160
const gchar **batch_commands,
161
gboolean no_interface,
167
gboolean use_cpu_accel,
168
gboolean console_messages,
169
GimpStackTraceMode stack_trace_mode,
170
GimpPDBCompatMode pdb_compat_mode)
172
GimpInitStatusFunc update_status_func = NULL;
178
const gchar *log_domains[] =
202
/* Create an instance of the "Gimp" object which is the root of the
205
gimp = gimp_new (full_prog_name,
216
for (i = 0; i < G_N_ELEMENTS (log_domains); i++)
217
g_log_set_handler (log_domains[i],
219
gimp_message_log_func, &gimp);
221
g_log_set_handler (NULL,
222
G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
223
gimp_error_log_func, &gimp);
227
/* Check if the user's gimp_directory exists
229
if (! g_file_test (gimp_directory (), G_FILE_TEST_IS_DIR))
231
/* not properly installed */
233
#ifndef GIMP_CONSOLE_COMPILATION
239
msg = _("GIMP is not properly installed for the current user.\n"
240
"User installation was skipped because the '--no-interface' flag was used.\n"
241
"To perform user installation, run the GIMP without the '--no-interface' flag.");
243
g_printerr ("%s\n\n", msg);
245
#ifndef GIMP_CONSOLE_COMPILATION
248
user_install_dialog_run (alternate_system_gimprc,
255
#if defined G_OS_WIN32 && !defined GIMP_CONSOLE_COMPILATION
256
/* Common windoze apps don't have a console at all. So does Gimp
257
* - if appropiate. This allows to compile as console application
258
* with all it's benefits (like inheriting the console) but hide
259
* it, if the user doesn't want it.
261
if (!no_interface && !be_verbose && !console_messages)
265
gimp_load_config (gimp, alternate_system_gimprc, alternate_gimprc);
267
/* initialize lowlevel stuff */
268
swap_is_ok = base_init (GIMP_BASE_CONFIG (gimp->config),
269
be_verbose, use_cpu_accel);
271
#ifndef GIMP_CONSOLE_COMPILATION
273
update_status_func = gui_init (gimp, no_splash);
276
if (! update_status_func)
277
update_status_func = app_init_update_none;
279
/* Create all members of the global Gimp instance which need an already
280
* parsed gimprc, e.g. the data factories
282
gimp_initialize (gimp, update_status_func);
284
/* Load all data files
286
gimp_restore (gimp, update_status_func);
288
/* display a warning when no test swap file could be generated */
290
g_message (_("Unable to open a test swap file. To avoid data loss "
291
"please check the location and permissions of the swap "
292
"directory defined in your Preferences "
293
"(currently \"%s\")."),
294
GIMP_BASE_CONFIG (gimp->config)->swap_path);
296
/* enable autosave late so we don't autosave when the
297
* monitor resolution is set in gui_init()
299
gimp_rc_set_autosave (GIMP_RC (gimp->edit_config), TRUE);
301
/* Parse the rest of the command line arguments as images to load
307
for (i = 0; i < gimp_argc; i++)
311
GError *error = NULL;
314
/* first try if we got a file uri */
315
uri = g_filename_from_uri (gimp_argv[i], NULL, NULL);
320
uri = g_strdup (gimp_argv[i]);
324
uri = file_utils_filename_to_uri (gimp->load_procs,
325
gimp_argv[i], &error);
330
g_printerr ("conversion filename -> uri failed: %s\n",
332
g_clear_error (&error);
337
GimpPDBStatusType status;
339
gimage = file_open_with_display (gimp,
340
gimp_get_user_context (gimp),
345
if (! gimage && status != GIMP_PDB_CANCEL)
347
gchar *filename = file_utils_uri_to_utf8_filename (uri);
349
g_message (_("Opening '%s' failed: %s"),
350
filename, error->message);
351
g_clear_error (&error);
362
#ifndef GIMP_CONSOLE_COMPILATION
364
gui_post_init (gimp);
367
batch_run (gimp, batch_interpreter, batch_commands);
369
loop = g_main_loop_new (NULL, FALSE);
371
g_signal_connect_after (gimp, "exit",
372
G_CALLBACK (app_exit_after_callback),
375
gimp_threads_leave (gimp);
376
g_main_loop_run (loop);
377
gimp_threads_enter (gimp);
379
g_main_loop_unref (loop);
381
g_object_unref (gimp);
386
/* private functions */
389
app_init_update_none (const gchar *text1,
396
app_exit_after_callback (Gimp *gimp,
400
if (gimp->be_verbose)
401
g_print ("EXIT: app_exit_after_callback\n");
404
* In stable releases, we simply call exit() here. This speeds up
405
* the process of quitting GIMP and also works around the problem
406
* that plug-ins might still be running.
408
* In unstable releases, we shut down GIMP properly in an attempt
409
* to catch possible problems in our finalizers.
413
g_main_loop_quit (loop);
415
/* make sure that the swap file is removed before we quit */