~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/app_procs.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
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.
8
 
 *
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.
13
 
 *
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.
17
 
 */
18
 
 
19
 
#include "config.h"
20
 
 
21
 
#include <stdio.h>
22
 
#include <string.h>
23
 
#include <stdlib.h>
24
 
 
25
 
#ifdef HAVE_SYS_PARAM_H
26
 
#include <sys/param.h>
27
 
#endif
28
 
 
29
 
#ifdef HAVE_UNISTD_H
30
 
#include <unistd.h>
31
 
#endif
32
 
 
33
 
#include <glib-object.h>
34
 
 
35
 
#include "libgimpbase/gimpbase.h"
36
 
 
37
 
#include "core/core-types.h"
38
 
 
39
 
#include "config/gimprc.h"
40
 
 
41
 
#include "base/base.h"
42
 
 
43
 
#include "core/gimp.h"
44
 
 
45
 
#include "file/file-open.h"
46
 
#include "file/file-utils.h"
47
 
 
48
 
#ifndef GIMP_CONSOLE_COMPILATION
49
 
#include "dialogs/user-install-dialog.h"
50
 
 
51
 
#include "gui/gui.h"
52
 
#endif
53
 
 
54
 
#include "app_procs.h"
55
 
#include "batch.h"
56
 
#include "errors.h"
57
 
#include "units.h"
58
 
 
59
 
#include "gimp-intl.h"
60
 
 
61
 
#ifdef G_OS_WIN32
62
 
#include <windows.h>
63
 
#endif
64
 
 
65
 
 
66
 
/*  local prototypes  */
67
 
 
68
 
static void       app_init_update_none    (const gchar *text1,
69
 
                                           const gchar *text2,
70
 
                                           gdouble      percentage);
71
 
static gboolean   app_exit_after_callback (Gimp        *gimp,
72
 
                                           gboolean     kill_it,
73
 
                                           GMainLoop   *loop);
74
 
 
75
 
 
76
 
/*  public functions  */
77
 
 
78
 
gboolean
79
 
app_libs_init (gboolean   *no_interface,
80
 
               gint       *argc,
81
 
               gchar    ***argv)
82
 
{
83
 
#ifdef GIMP_CONSOLE_COMPILATION
84
 
  *no_interface = TRUE;
85
 
#endif
86
 
 
87
 
  if (*no_interface)
88
 
    {
89
 
      gchar *basename;
90
 
 
91
 
      basename = g_path_get_basename ((*argv)[0]);
92
 
      g_set_prgname (basename);
93
 
      g_free (basename);
94
 
 
95
 
      g_type_init ();
96
 
 
97
 
      return TRUE;
98
 
    }
99
 
#ifndef GIMP_CONSOLE_COMPILATION
100
 
  else
101
 
    {
102
 
      return gui_libs_init (argc, argv);
103
 
    }
104
 
#endif
105
 
 
106
 
  return FALSE;
107
 
}
108
 
 
109
 
void
110
 
app_abort (gboolean     no_interface,
111
 
           const gchar *abort_message)
112
 
{
113
 
#ifndef GIMP_CONSOLE_COMPILATION
114
 
  if (no_interface)
115
 
#endif
116
 
    {
117
 
      g_print ("%s\n\n", abort_message);
118
 
    }
119
 
#ifndef GIMP_CONSOLE_COMPILATION
120
 
  else
121
 
    {
122
 
      gui_abort (abort_message);
123
 
    }
124
 
#endif
125
 
 
126
 
  app_exit (EXIT_FAILURE);
127
 
}
128
 
 
129
 
void
130
 
app_exit (gint status)
131
 
{
132
 
#ifdef G_OS_WIN32
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
136
 
   * window.
137
 
   */
138
 
  HANDLE console;
139
 
  DWORD  mode;
140
 
 
141
 
  console = GetStdHandle (STD_OUTPUT_HANDLE);
142
 
  if (GetConsoleMode (console, &mode) != 0)
143
 
    {
144
 
      g_print (_("(This console window will close in ten seconds)\n"));
145
 
      Sleep(10000);
146
 
    }
147
 
#endif
148
 
 
149
 
  exit (status);
150
 
}
151
 
 
152
 
void
153
 
app_run (const gchar         *full_prog_name,
154
 
         gint                 gimp_argc,
155
 
         gchar              **gimp_argv,
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,
162
 
         gboolean             no_data,
163
 
         gboolean             no_fonts,
164
 
         gboolean             no_splash,
165
 
         gboolean             be_verbose,
166
 
         gboolean             use_shm,
167
 
         gboolean             use_cpu_accel,
168
 
         gboolean             console_messages,
169
 
         GimpStackTraceMode   stack_trace_mode,
170
 
         GimpPDBCompatMode    pdb_compat_mode)
171
 
{
172
 
  GimpInitStatusFunc  update_status_func = NULL;
173
 
  Gimp               *gimp;
174
 
  GMainLoop          *loop;
175
 
  gboolean            swap_is_ok;
176
 
  gint                i;
177
 
 
178
 
  const gchar *log_domains[] =
179
 
  {
180
 
    "Gimp",
181
 
    "Gimp-Actions",
182
 
    "Gimp-Base",
183
 
    "Gimp-Composite",
184
 
    "Gimp-Config",
185
 
    "Gimp-Core",
186
 
    "Gimp-Dialogs",
187
 
    "Gimp-Display",
188
 
    "Gimp-File",
189
 
    "Gimp-GUI",
190
 
    "Gimp-Menus",
191
 
    "Gimp-PDB",
192
 
    "Gimp-Paint",
193
 
    "Gimp-Paint-Funcs",
194
 
    "Gimp-Plug-In",
195
 
    "Gimp-Text",
196
 
    "Gimp-Tools",
197
 
    "Gimp-Vectors",
198
 
    "Gimp-Widgets",
199
 
    "Gimp-XCF"
200
 
  };
201
 
 
202
 
  /*  Create an instance of the "Gimp" object which is the root of the
203
 
   *  core object system
204
 
   */
205
 
  gimp = gimp_new (full_prog_name,
206
 
                   session_name,
207
 
                   be_verbose,
208
 
                   no_data,
209
 
                   no_fonts,
210
 
                   no_interface,
211
 
                   use_shm,
212
 
                   console_messages,
213
 
                   stack_trace_mode,
214
 
                   pdb_compat_mode);
215
 
 
216
 
  for (i = 0; i < G_N_ELEMENTS (log_domains); i++)
217
 
    g_log_set_handler (log_domains[i],
218
 
                       G_LOG_LEVEL_MESSAGE,
219
 
                       gimp_message_log_func, &gimp);
220
 
 
221
 
  g_log_set_handler (NULL,
222
 
                     G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
223
 
                     gimp_error_log_func, &gimp);
224
 
 
225
 
  units_init (gimp);
226
 
 
227
 
  /*  Check if the user's gimp_directory exists
228
 
   */
229
 
  if (! g_file_test (gimp_directory (), G_FILE_TEST_IS_DIR))
230
 
    {
231
 
      /*  not properly installed  */
232
 
 
233
 
#ifndef GIMP_CONSOLE_COMPILATION
234
 
      if (no_interface)
235
 
#endif
236
 
        {
237
 
          const gchar *msg;
238
 
 
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.");
242
 
 
243
 
          g_printerr ("%s\n\n", msg);
244
 
        }
245
 
#ifndef GIMP_CONSOLE_COMPILATION
246
 
      else
247
 
        {
248
 
          user_install_dialog_run (alternate_system_gimprc,
249
 
                                   alternate_gimprc,
250
 
                                   be_verbose);
251
 
        }
252
 
#endif
253
 
    }
254
 
 
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.
260
 
   */
261
 
  if (!no_interface && !be_verbose && !console_messages)
262
 
    FreeConsole ();
263
 
#endif
264
 
 
265
 
  gimp_load_config (gimp, alternate_system_gimprc, alternate_gimprc);
266
 
 
267
 
  /*  initialize lowlevel stuff  */
268
 
  swap_is_ok = base_init (GIMP_BASE_CONFIG (gimp->config),
269
 
                          be_verbose, use_cpu_accel);
270
 
 
271
 
#ifndef GIMP_CONSOLE_COMPILATION
272
 
  if (! no_interface)
273
 
    update_status_func = gui_init (gimp, no_splash);
274
 
#endif
275
 
 
276
 
  if (! update_status_func)
277
 
    update_status_func = app_init_update_none;
278
 
 
279
 
  /*  Create all members of the global Gimp instance which need an already
280
 
   *  parsed gimprc, e.g. the data factories
281
 
   */
282
 
  gimp_initialize (gimp, update_status_func);
283
 
 
284
 
  /*  Load all data files
285
 
   */
286
 
  gimp_restore (gimp, update_status_func);
287
 
 
288
 
  /* display a warning when no test swap file could be generated */
289
 
  if (! swap_is_ok)
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);
295
 
 
296
 
  /*  enable autosave late so we don't autosave when the
297
 
   *  monitor resolution is set in gui_init()
298
 
   */
299
 
  gimp_rc_set_autosave (GIMP_RC (gimp->edit_config), TRUE);
300
 
 
301
 
  /*  Parse the rest of the command line arguments as images to load
302
 
   */
303
 
  if (gimp_argc > 0)
304
 
    {
305
 
      gint i;
306
 
 
307
 
      for (i = 0; i < gimp_argc; i++)
308
 
        {
309
 
          if (gimp_argv[i])
310
 
            {
311
 
              GError *error = NULL;
312
 
              gchar  *uri;
313
 
 
314
 
              /*  first try if we got a file uri  */
315
 
              uri = g_filename_from_uri (gimp_argv[i], NULL, NULL);
316
 
 
317
 
              if (uri)
318
 
                {
319
 
                  g_free (uri);
320
 
                  uri = g_strdup (gimp_argv[i]);
321
 
                }
322
 
              else
323
 
                {
324
 
                  uri = file_utils_filename_to_uri (gimp->load_procs,
325
 
                                                    gimp_argv[i], &error);
326
 
                }
327
 
 
328
 
              if (! uri)
329
 
                {
330
 
                  g_printerr ("conversion filename -> uri failed: %s\n",
331
 
                              error->message);
332
 
                  g_clear_error (&error);
333
 
                }
334
 
              else
335
 
                {
336
 
                  GimpImage         *gimage;
337
 
                  GimpPDBStatusType  status;
338
 
 
339
 
                  gimage = file_open_with_display (gimp,
340
 
                                                   gimp_get_user_context (gimp),
341
 
                                                   NULL,
342
 
                                                   uri,
343
 
                                                   &status, &error);
344
 
 
345
 
                  if (! gimage && status != GIMP_PDB_CANCEL)
346
 
                    {
347
 
                      gchar *filename = file_utils_uri_to_utf8_filename (uri);
348
 
 
349
 
                      g_message (_("Opening '%s' failed: %s"),
350
 
                                 filename, error->message);
351
 
                      g_clear_error (&error);
352
 
 
353
 
                      g_free (filename);
354
 
                   }
355
 
 
356
 
                  g_free (uri);
357
 
                }
358
 
            }
359
 
        }
360
 
    }
361
 
 
362
 
#ifndef GIMP_CONSOLE_COMPILATION
363
 
  if (! no_interface)
364
 
    gui_post_init (gimp);
365
 
#endif
366
 
 
367
 
  batch_run (gimp, batch_interpreter, batch_commands);
368
 
 
369
 
  loop = g_main_loop_new (NULL, FALSE);
370
 
 
371
 
  g_signal_connect_after (gimp, "exit",
372
 
                          G_CALLBACK (app_exit_after_callback),
373
 
                          loop);
374
 
 
375
 
  gimp_threads_leave (gimp);
376
 
  g_main_loop_run (loop);
377
 
  gimp_threads_enter (gimp);
378
 
 
379
 
  g_main_loop_unref (loop);
380
 
 
381
 
  g_object_unref (gimp);
382
 
  base_exit ();
383
 
}
384
 
 
385
 
 
386
 
/*  private functions  */
387
 
 
388
 
static void
389
 
app_init_update_none (const gchar *text1,
390
 
                      const gchar *text2,
391
 
                      gdouble      percentage)
392
 
{
393
 
}
394
 
 
395
 
static gboolean
396
 
app_exit_after_callback (Gimp      *gimp,
397
 
                         gboolean   kill_it,
398
 
                         GMainLoop *loop)
399
 
{
400
 
  if (gimp->be_verbose)
401
 
    g_print ("EXIT: app_exit_after_callback\n");
402
 
 
403
 
  /*
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.
407
 
   *
408
 
   *  In unstable releases, we shut down GIMP properly in an attempt
409
 
   *  to catch possible problems in our finalizers.
410
 
   */
411
 
 
412
 
#ifdef GIMP_UNSTABLE
413
 
  g_main_loop_quit (loop);
414
 
#else
415
 
  /*  make sure that the swap file is removed before we quit */
416
 
  base_exit ();
417
 
  exit (EXIT_SUCCESS);
418
 
#endif
419
 
 
420
 
  return FALSE;
421
 
}