main.c 2.94 KB
Newer Older
Fatih Demir's avatar
Fatih Demir committed
1
/*
2
 * (C) 2000-2007 	Fatih Demir <kabalak@kabalak.net>
3
 *			Ross Golder <ross@golder.org>
4 5
 *			Gediminas Paulauskas <menesis@kabalak.net>
 *			Peeter Vois <peeter@kabalak.net>
6
 * 			Ignacio Casal Quinteiro <nacho.resa@gmail.com>
7
 *
Fatih Demir's avatar
Fatih Demir committed
8 9 10 11
 * gtranslator 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.
12
 *
Fatih Demir's avatar
Fatih Demir committed
13 14 15 16 17 18
 * gtranslator 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
19
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Fatih Demir's avatar
Fatih Demir committed
20 21
 *
 */
Fatih Demir's avatar
Fatih Demir committed
22 23

#ifdef HAVE_CONFIG_H
Fatih Demir's avatar
Fatih Demir committed
24
#include <config.h>
25
#endif
Fatih Demir's avatar
Fatih Demir committed
26

27 28
#include "gtr-application.h"
#include "gtr-dirs.h"
Fatih Demir's avatar
Fatih Demir committed
29

30
#include <errno.h>
31
#include <locale.h>
Ross Golder's avatar
Ross Golder committed
32
#include <glib.h>
33
#include <glib/gi18n.h>
34
#include <gio/gio.h>
35

36 37 38 39
#ifdef ENABLE_INTROSPECTION
#include <girepository.h>
#endif

40 41 42 43 44 45 46 47 48 49 50 51 52
#ifdef G_OS_WIN32
#define SAVE_DATADIR DATADIR
#undef DATADIR
#define _WIN32_WINNT 0x0500
#include <windows.h>
#define DATADIR SAVE_DATADIR
#undef SAVE_DATADIR
#endif

#ifdef G_OS_WIN32
static void
setup_path (void)
{
53
  gchar *path;
54 55
  gchar *installdir;
  gchar *bin;
56

57
  installdir = g_win32_get_package_installation_directory_of_module (NULL);
58

59
  bin = g_build_filename (installdir, "bin", NULL);
60
  g_free (installdir);
61

62
  /* Set PATH to include the gedit executable's folder */
63
  path = g_build_path (";", bin, g_getenv ("PATH"), NULL);
64
  g_free (bin);
65 66

  if (!g_setenv ("PATH", path, TRUE))
67
    g_warning ("Could not set PATH for gtranslator");
68 69

  g_free (path);
70 71 72
}
#endif

73
/* The ubiquitous main function... */
74
gint
75
main (gint argc, gchar * argv[])
Fatih Demir's avatar
Fatih Demir committed
76
{
77
  GtrApplication *app;
78
  gint status;
79

80 81
  gtr_dirs_init ();

82
  /* Initialize gettext. */
83 84
  setlocale (LC_ALL, "");

85
  bindtextdomain (GETTEXT_PACKAGE, gtr_dirs_get_gtr_locale_dir ());
86 87 88
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

89
#ifdef G_OS_WIN32
90
  setup_path ();
91 92
#endif

93 94 95 96
#ifdef ENABLE_INTROSPECTION
  GOptionContext *context;
  GError *error = NULL;

97
  context = g_option_context_new (_("— Edit PO files"));
98 99 100
  g_option_context_add_group (context, g_irepository_get_option_group ());
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
101
      g_print(_("%s\nRun “%s --help” to see a full list of available command line options.\n"),
102 103 104 105 106 107 108 109
              error->message, argv[0]);
      g_error_free (error);
      g_option_context_free (context);
      return 1;
    }
  g_option_context_free (context);
#endif

110 111
  app = _gtr_application_new ();

112
  status = g_application_run (G_APPLICATION (app), argc, argv);
113

114
  g_object_unref (app);
115
  gtr_dirs_shutdown ();
116

117 118 119
  /* Make sure settings are saved */
  g_settings_sync ();

120
  return status;
Fatih Demir's avatar
Fatih Demir committed
121
}