~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/sanity.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

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 <glib.h>
 
22
#include <fontconfig/fontconfig.h>
 
23
#include <pango/pangoft2.h>
 
24
 
 
25
#include "libgimpbase/gimpenv.h"
 
26
 
 
27
#include "core/gimp-utils.h"
 
28
 
 
29
#include "sanity.h"
 
30
 
 
31
#include "gimp-intl.h"
 
32
 
 
33
 
 
34
static gchar * sanity_check_glib              (void);
 
35
static gchar * sanity_check_fontconfig        (void);
 
36
static gchar * sanity_check_freetype          (void);
 
37
static gchar * sanity_check_filename_encoding (void);
 
38
 
 
39
 
 
40
/*  public functions  */
 
41
 
 
42
const gchar *
 
43
sanity_check (void)
 
44
{
 
45
  gchar *abort_message = sanity_check_glib ();
 
46
 
 
47
  if (! abort_message)
 
48
    abort_message = sanity_check_fontconfig ();
 
49
 
 
50
  if (! abort_message)
 
51
    abort_message = sanity_check_freetype ();
 
52
 
 
53
  if (! abort_message)
 
54
    abort_message = sanity_check_filename_encoding ();
 
55
 
 
56
  return abort_message;
 
57
}
 
58
 
 
59
 
 
60
/*  private functions  */
 
61
 
 
62
static gchar *
 
63
sanity_check_glib (void)
 
64
{
 
65
  const gchar *mismatch;
 
66
 
 
67
#define GLIB_REQUIRED_MAJOR 2
 
68
#define GLIB_REQUIRED_MINOR 4
 
69
#define GLIB_REQUIRED_MICRO 5
 
70
 
 
71
  mismatch = gimp_check_glib_version (GLIB_REQUIRED_MAJOR,
 
72
                                      GLIB_REQUIRED_MINOR,
 
73
                                      GLIB_REQUIRED_MICRO);
 
74
 
 
75
  if (mismatch)
 
76
    {
 
77
      return g_strdup_printf
 
78
        ("%s\n\n"
 
79
         "The GIMP requires GLib+ version %d.%d.%d or later.\n"
 
80
         "Installed GLib+ version is %d.%d.%d.\n\n"
 
81
         "Somehow you or your software packager managed\n"
 
82
         "to install The GIMP with an older GLib+ version.\n\n"
 
83
         "Please upgrade to GLib+ version %d.%d.%d or later.",
 
84
         mismatch,
 
85
         GLIB_REQUIRED_MAJOR, GLIB_REQUIRED_MINOR, GLIB_REQUIRED_MICRO,
 
86
         glib_major_version, glib_minor_version, glib_micro_version,
 
87
         GLIB_REQUIRED_MAJOR, GLIB_REQUIRED_MINOR, GLIB_REQUIRED_MICRO);
 
88
    }
 
89
 
 
90
#undef GLIB_REQUIRED_MAJOR
 
91
#undef GLIB_REQUIRED_MINOR
 
92
#undef GLIB_REQUIRED_MICRO
 
93
 
 
94
  return NULL;
 
95
}
 
96
 
 
97
static gchar *
 
98
sanity_check_fontconfig (void)
 
99
{
 
100
  gint   fc_version       = FcGetVersion ();
 
101
  gint   fc_major_version = fc_version / 100 / 100;
 
102
  gint   fc_minor_version = fc_version / 100 % 100;
 
103
  gint   fc_micro_version = fc_version % 100;
 
104
 
 
105
#define FC_REQUIRED_MAJOR 2
 
106
#define FC_REQUIRED_MINOR 2
 
107
#define FC_REQUIRED_MICRO 0
 
108
 
 
109
  if (fc_version < ((FC_REQUIRED_MAJOR * 10000) +
 
110
                    (FC_REQUIRED_MINOR *   100) +
 
111
                    (FC_REQUIRED_MICRO *     1)))
 
112
    {
 
113
      return g_strdup_printf
 
114
        ("The Fontconfig version being used is too old!\n\n"
 
115
         "The GIMP requires Fontconfig version %d.%d.%d or later.\n"
 
116
         "The Fontconfig version loaded by The GIMP is %d.%d.%d.\n\n"
 
117
         "This may be caused by another instance of libfontconfig.so.1\n"
 
118
         "being installed in the system, probably in /usr/X11R6/lib.\n"
 
119
         "Please correct the situation or report it to someone who can.",
 
120
         FC_REQUIRED_MAJOR, FC_REQUIRED_MINOR, FC_REQUIRED_MICRO,
 
121
         fc_major_version, fc_minor_version, fc_micro_version);
 
122
    }
 
123
 
 
124
#undef FC_REQUIRED_MAJOR
 
125
#undef FC_REQUIRED_MINOR
 
126
#undef FC_REQUIRED_MICRO
 
127
 
 
128
  return NULL;
 
129
}
 
130
 
 
131
static gchar *
 
132
sanity_check_freetype (void)
 
133
{
 
134
  FT_Library ft_library;
 
135
  FT_Int     ft_major_version;
 
136
  FT_Int     ft_minor_version;
 
137
  FT_Int     ft_micro_version;
 
138
  FT_Int     ft_version;
 
139
 
 
140
#define FT_REQUIRED_MAJOR 2
 
141
#define FT_REQUIRED_MINOR 1
 
142
#define FT_REQUIRED_MICRO 7
 
143
 
 
144
  if (FT_Init_FreeType (&ft_library) != 0)
 
145
    g_error ("FT_Init_FreeType() failed");
 
146
 
 
147
  FT_Library_Version (ft_library,
 
148
                      &ft_major_version,
 
149
                      &ft_minor_version,
 
150
                      &ft_micro_version);
 
151
 
 
152
  if (FT_Done_FreeType (ft_library) != 0)
 
153
    g_error ("FT_Done_FreeType() failed");
 
154
 
 
155
  ft_version = (ft_major_version * 10000 +
 
156
                ft_minor_version *   100 +
 
157
                ft_micro_version *     1);
 
158
 
 
159
  if (ft_version < ((FT_REQUIRED_MAJOR * 10000) +
 
160
                    (FT_REQUIRED_MINOR *   100) +
 
161
                    (FT_REQUIRED_MICRO *     1)))
 
162
    {
 
163
      return g_strdup_printf
 
164
        ("FreeType version too old!\n\n"
 
165
         "The GIMP requires FreeType version %d.%d.%d or later.\n"
 
166
         "Installed FreeType version is %d.%d.%d.\n\n"
 
167
         "Somehow you or your software packager managed\n"
 
168
         "to install The GIMP with an older FreeType version.\n\n"
 
169
         "Please upgrade to FreeType version %d.%d.%d or later.",
 
170
         FT_REQUIRED_MAJOR, FT_REQUIRED_MINOR, FT_REQUIRED_MICRO,
 
171
         ft_major_version, ft_minor_version, ft_micro_version,
 
172
         FT_REQUIRED_MAJOR, FT_REQUIRED_MINOR, FT_REQUIRED_MICRO);
 
173
    }
 
174
 
 
175
#undef FT_REQUIRED_MAJOR
 
176
#undef FT_REQUIRED_MINOR
 
177
#undef FT_REQUIRED_MICRO
 
178
 
 
179
  return NULL;
 
180
}
 
181
 
 
182
static gchar *
 
183
sanity_check_filename_encoding (void)
 
184
{
 
185
  gchar  *result;
 
186
  GError *error = NULL;
 
187
 
 
188
  result = g_filename_to_utf8 ("", -1, NULL, NULL, &error);
 
189
 
 
190
  if (! result)
 
191
    {
 
192
      gchar *msg =
 
193
        g_strdup_printf
 
194
        (_("The configured filename encoding cannot be converted to UTF-8: "
 
195
           "%s\n\n"
 
196
           "Please check the value of the environment variable "
 
197
           "G_FILENAME_ENCODING."),
 
198
         error->message);
 
199
 
 
200
      g_error_free (error);
 
201
 
 
202
      return msg;
 
203
    }
 
204
 
 
205
  g_free (result);
 
206
 
 
207
  result = g_filename_to_utf8 (gimp_directory (), -1, NULL, NULL, &error);
 
208
 
 
209
  if (! result)
 
210
    {
 
211
      gchar *msg =
 
212
        g_strdup_printf
 
213
        (_("The name of the directory holding the GIMP user configuration "
 
214
           "cannot be converted to UTF-8: "
 
215
           "%s\n\n"
 
216
           "Most probably your filesystem stores files in an encoding "
 
217
           "different from UTF-8 and you didn't tell GLib about this. "
 
218
           "Please set the environment variable G_FILENAME_ENCODING."),
 
219
         error->message);
 
220
 
 
221
      g_error_free (error);
 
222
 
 
223
      return msg;
 
224
    }
 
225
 
 
226
  g_free (result);
 
227
 
 
228
  return NULL;
 
229
}