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

« back to all changes in this revision

Viewing changes to app/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include <io.h> /* get_osfhandle */
42
42
#endif
43
43
 
44
 
#if HAVE_DBUS_GLIB
45
 
#include <dbus/dbus-glib.h>
46
 
#endif
47
 
 
48
44
#ifndef GIMP_CONSOLE_COMPILATION
49
45
#include <gdk/gdk.h>
50
46
#endif
59
55
 
60
56
#include "core/gimp.h"
61
57
 
62
 
#include "file/file-utils.h"
63
 
 
64
 
#include "widgets/gimpdbusservice.h"
65
 
 
66
58
#include "about.h"
67
59
#include "app.h"
68
60
#include "errors.h"
69
61
#include "sanity.h"
 
62
#include "unique.h"
70
63
#include "units.h"
 
64
#include "version.h"
71
65
 
72
66
#ifdef G_OS_WIN32
73
67
#include <windows.h>
74
68
#include <conio.h>
75
69
#endif
76
70
 
 
71
#include "gimp-log.h"
77
72
#include "gimp-intl.h"
78
73
 
79
74
 
111
106
#define gimp_open_console_window() /* as nothing */
112
107
#endif
113
108
 
114
 
static gboolean  gimp_dbus_open               (const gchar **filenames,
115
 
                                               gboolean      as_new,
116
 
                                               gboolean      be_verbose);
117
 
 
118
 
 
119
109
static const gchar        *system_gimprc     = NULL;
120
110
static const gchar        *user_gimprc       = NULL;
121
111
static const gchar        *session_name      = NULL;
278
268
  { NULL }
279
269
};
280
270
 
281
 
 
282
271
int
283
272
main (int    argc,
284
273
      char **argv)
289
278
  gchar          *basename;
290
279
  gint            i;
291
280
 
 
281
#if defined (__GNUC__) && defined (_WIN64)
 
282
  /* mingw-w64, at least the unstable build from late July 2008,
 
283
   * starts subsystem:windows programs in main(), but passes them
 
284
   * bogus argc and argv. __argc and __argv are OK, though, so just
 
285
   * use them.
 
286
   */
 
287
  argc = __argc;
 
288
  argv = __argv;
 
289
#endif
 
290
 
292
291
  g_thread_init (NULL);
293
292
 
294
293
#ifdef GIMP_UNSTABLE
299
298
 
300
299
  gimp_env_init (FALSE);
301
300
 
 
301
  gimp_log_init ();
 
302
 
302
303
  gimp_init_i18n ();
303
304
 
304
305
  g_set_application_name (GIMP_NAME);
307
308
  g_set_prgname (basename);
308
309
  g_free (basename);
309
310
 
 
311
  /* Check argv[] for "--verbose" first */
 
312
  for (i = 1; i < argc; i++)
 
313
    {
 
314
      const gchar *arg = argv[i];
 
315
 
 
316
      if (arg[0] != '-')
 
317
        continue;
 
318
 
 
319
      if ((strcmp (arg, "--verbose") == 0) || (strcmp (arg, "-v") == 0))
 
320
        {
 
321
          be_verbose = TRUE;
 
322
        }
 
323
    }
 
324
 
310
325
  /* Check argv[] for "--no-interface" before trying to initialize gtk+. */
311
326
  for (i = 1; i < argc; i++)
312
327
    {
321
336
        }
322
337
      else if ((strcmp (arg, "--version") == 0) || (strcmp (arg, "-v") == 0))
323
338
        {
324
 
          gimp_open_console_window ();
325
339
          gimp_show_version_and_exit ();
326
340
        }
327
341
#if defined (G_OS_WIN32) && !defined (GIMP_CONSOLE_COMPILATION)
370
384
  if (no_interface)
371
385
    new_instance = TRUE;
372
386
 
373
 
  if (! new_instance)
 
387
#ifndef GIMP_CONSOLE_COMPILATION
 
388
  if (! new_instance && gimp_unique_open (filenames, as_new))
374
389
    {
375
 
      if (gimp_dbus_open (filenames, as_new, be_verbose))
376
 
        return EXIT_SUCCESS;
 
390
      if (be_verbose)
 
391
        g_print ("%s\n",
 
392
                 _("Another GIMP instance is already running."));
 
393
 
 
394
      gdk_notify_startup_complete ();
 
395
 
 
396
      return EXIT_SUCCESS;
377
397
    }
 
398
#endif
378
399
 
379
400
  abort_message = sanity_check ();
380
401
  if (abort_message)
410
431
 
411
432
#ifdef G_OS_WIN32
412
433
 
413
 
/* In case we build this as a windowed application. Well, we do. */
 
434
/* Provide WinMain in case we build GIMP as a subsystem:windows
 
435
 * application. Well, we do. When built with mingw, though, user code
 
436
 * execution still starts in main() in that case. So WinMain() gets
 
437
 * used on MSVC builds only.
 
438
 */
414
439
 
415
440
#ifdef __GNUC__
416
441
#  ifndef _stdcall
551
576
}
552
577
 
553
578
static void
554
 
gimp_show_version (void)
555
 
{
556
 
  gimp_open_console_window ();
557
 
  g_print (_("%s version %s"), GIMP_NAME, GIMP_VERSION);
558
 
  g_print ("\n");
559
 
}
560
 
 
561
 
static void
562
579
gimp_show_version_and_exit (void)
563
580
{
564
 
  gimp_show_version ();
 
581
  gimp_open_console_window ();
 
582
  gimp_version_show (be_verbose);
565
583
 
566
584
  app_exit (EXIT_SUCCESS);
567
585
}
569
587
static void
570
588
gimp_show_license_and_exit (void)
571
589
{
572
 
  gimp_show_version ();
 
590
  gimp_open_console_window ();
 
591
  gimp_version_show (be_verbose);
573
592
 
574
593
  g_print ("\n");
575
594
  g_print (GIMP_LICENSE);
597
616
   *
598
617
   * An alternative to tuning this parameter would be to use
599
618
   * malloc_trim(), for example after releasing a large tile-manager.
600
 
   *
601
 
   * Another possibility is to switch to using GSlice as soon as this
602
 
   * API is available in a stable GLib release.
603
619
   */
604
620
  mallopt (M_MMAP_THRESHOLD, TILE_WIDTH * TILE_HEIGHT);
605
621
#endif
688
704
}
689
705
 
690
706
#endif /* ! G_OS_WIN32 */
691
 
 
692
 
 
693
 
static gboolean
694
 
gimp_dbus_open (const gchar **filenames,
695
 
                gboolean      as_new,
696
 
                gboolean      be_verbose)
697
 
{
698
 
#ifndef GIMP_CONSOLE_COMPILATION
699
 
#if HAVE_DBUS_GLIB
700
 
  DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
701
 
 
702
 
  if (connection)
703
 
    {
704
 
      DBusGProxy *proxy;
705
 
      gboolean    success;
706
 
      GError     *error = NULL;
707
 
 
708
 
      proxy = dbus_g_proxy_new_for_name (connection,
709
 
                                         GIMP_DBUS_SERVICE_NAME,
710
 
                                         GIMP_DBUS_SERVICE_PATH,
711
 
                                         GIMP_DBUS_SERVICE_INTERFACE);
712
 
 
713
 
      if (filenames)
714
 
        {
715
 
          const gchar *method = as_new ? "OpenAsNew" : "Open";
716
 
          gchar       *cwd    = NULL;
717
 
          gint         i;
718
 
 
719
 
          for (i = 0, success = TRUE; filenames[i] && success; i++)
720
 
            {
721
 
              const gchar *filename = filenames[i];
722
 
              gchar       *uri      = NULL;
723
 
 
724
 
              if (file_utils_filename_is_uri (filename, &error))
725
 
                {
726
 
                  uri = g_strdup (filename);
727
 
                }
728
 
              else if (! error)
729
 
                {
730
 
                  if (! g_path_is_absolute (filename))
731
 
                    {
732
 
                      gchar *absolute;
733
 
 
734
 
                      if (! cwd)
735
 
                        cwd = g_get_current_dir ();
736
 
 
737
 
                      absolute = g_build_filename (cwd, filename, NULL);
738
 
 
739
 
                      uri = g_filename_to_uri (absolute, NULL, &error);
740
 
 
741
 
                      g_free (absolute);
742
 
                    }
743
 
                  else
744
 
                    {
745
 
                      uri = g_filename_to_uri (filename, NULL, &error);
746
 
                    }
747
 
                }
748
 
 
749
 
              if (uri)
750
 
                {
751
 
                  gboolean retval; /* ignored */
752
 
 
753
 
                  success = dbus_g_proxy_call (proxy, method, &error,
754
 
                                               G_TYPE_STRING, uri,
755
 
                                               G_TYPE_INVALID,
756
 
                                               G_TYPE_BOOLEAN, &retval,
757
 
                                               G_TYPE_INVALID);
758
 
                  g_free (uri);
759
 
                }
760
 
              else
761
 
                {
762
 
                  g_printerr ("conversion to uri failed: %s\n", error->message);
763
 
                  g_clear_error (&error);
764
 
                }
765
 
            }
766
 
 
767
 
          g_free (cwd);
768
 
        }
769
 
      else
770
 
        {
771
 
          success = dbus_g_proxy_call (proxy, "Activate", &error,
772
 
                                       G_TYPE_INVALID, G_TYPE_INVALID);
773
 
        }
774
 
 
775
 
      g_object_unref (proxy);
776
 
      dbus_g_connection_unref (connection);
777
 
 
778
 
      if (success)
779
 
        {
780
 
          if (be_verbose)
781
 
            g_print ("%s\n",
782
 
                     _("Another GIMP instance is already running."));
783
 
 
784
 
          gdk_notify_startup_complete ();
785
 
 
786
 
          return TRUE;
787
 
        }
788
 
      else if (! (error->domain == DBUS_GERROR &&
789
 
                  error->code == DBUS_GERROR_SERVICE_UNKNOWN))
790
 
        {
791
 
          g_print ("%s\n", error->message);
792
 
        }
793
 
 
794
 
      g_clear_error (&error);
795
 
    }
796
 
#endif
797
 
#endif
798
 
 
799
 
  return FALSE;
800
 
}