summaryrefslogtreecommitdiff
path: root/garcon/garcon-config.c
blob: 8a3916fbd71b6ce6c5c46874c7112d1dd43ec2f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
 * Copyright (c) 2009-2010 Jannis Pohlmann <jannis@xfce.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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 Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <garcon/garcon-config.h>



/**
 * SECTION: garcon-config
 * @title: Version Information
 * @short_description: Information about the garcon version in use.
 * @include: garcon/garcon.h
 *
 * The garcon library provides version information, which could be used
 * by developers to handle new API.
 **/



/**
 * garcon_major_version:
 *
 * The major version number of the garcon library (e.g. in
 * version 4.8.0 this is 4).
 *
 * This variable is in the library, so represents the
 * garcon library you have linked against. Contrast with the
 * #GARCON_MAJOR_VERSION macro, which represents the major
 * version of the garcon headers you have included.
 **/
const guint garcon_major_version = GARCON_MAJOR_VERSION;

/**
 * garcon_minor_version:
 *
 * The minor version number of the garcon library (e.g. in
 * version 4.8.0 this is 8).
 *
 * This variable is in the library, so represents the
 * garcon library you have linked against. Contrast with the
 * #GARCON_MINOR_VERSION macro, which represents the minor
 * version of the garcon headers you have included.
 **/
const guint garcon_minor_version = GARCON_MINOR_VERSION;

/**
 * garcon_micro_version:
 *
 * The micro version number of the garcon library (e.g. in
 * version 4.8.0 this is 0).
 *
 * This variable is in the library, so represents the
 * garcon library you have linked against. Contrast with the
 * #GARCON_MICRO_VERSION macro, which represents the micro
 * version of the garcon headers you have included.
 **/
const guint garcon_micro_version = GARCON_MICRO_VERSION;




/**
 * garcon_check_version:
 * @required_major : the required major version.
 * @required_minor : the required minor version.
 * @required_micro : the required micro version.
 *
 * Checks that the <systemitem class="library">garcon</systemitem>
 * library in use is compatible with the given version. Generally you
 * would pass in the constants #GARCON_MAJOR_VERSION,
 * #GARCON_MINOR_VERSION and #GARCON_MICRO_VERSION as the three
 * arguments to this function; that produces a check that the library
 * in use is compatible with the version of
 * <systemitem class="library">garcon</systemitem> the application was
 * compiled against.
 *
 * <example>
 * <title>Checking the runtime version of the garcon library</title>
 * <programlisting>
 * const gchar *mismatch;
 * mismatch = garcon_check_version (GARCON_VERSION_MAJOR,
 *                                  GARCON_VERSION_MINOR,
 *                                  GARCON_VERSION_MICRO);
 * if (G_UNLIKELY (mismatch != NULL))
 *   g_error ("Version mismatch: %<!---->s", mismatch);
 * </programlisting>
 * </example>
 *
 * Returns: %NULL if the library is compatible with the given version,
 *          or a string describing the version mismatch. The returned
 *          string is owned by the library and must not be freed or
 *          modified by the caller.
 **/
const gchar*
garcon_check_version (guint required_major,
                      guint required_minor,
                      guint required_micro)
{
  return NULL;
}



/**
 * garcon_config_build_paths:
 * @filename: name of .desktop file
 *
 * Returns: (transfer full):
 */
gchar **
garcon_config_build_paths (const gchar *filename)
{
  const gchar * const *dirs;
  gchar              **paths;
  guint                n;

  g_return_val_if_fail (filename != NULL && *filename != '\0', NULL);

  dirs = g_get_system_config_dirs ();

  paths = g_new0 (gchar *, 1 + g_strv_length ((gchar **)dirs) + 1);
  
  paths[0] = g_build_filename (g_get_user_config_dir (), filename, NULL);
  for (n = 1; dirs[n-1] != NULL; ++n)
    paths[n] = g_build_filename (dirs[n-1], filename, NULL);
  paths[n] = NULL;

  return paths;
}



/**
 * garcon_config_lookup:
 * @filename : relative filename of the config resource.
 *
 * Looks for the filename in the users' config directory and then
 * the system config directories.
 *
 * Returns: the absolute path to the first file in the search path,
 *          that matches @filename or %NULL if no such
 *          file or directory could be found.
 **/
gchar *
garcon_config_lookup (const gchar *filename)
{
  const gchar * const *dirs;
  gchar               *path;
  guint                i;

  g_return_val_if_fail (filename != NULL && *filename != '\0', NULL);

  /* Look for the file in the user's config directory */
  path = g_build_filename (g_get_user_config_dir (), filename, NULL);
  if (g_path_is_absolute (path) && g_file_test (path, G_FILE_TEST_IS_REGULAR))
    return path;

  g_free (path);
  path = NULL;

  /* Look for the file in the system config directories */
  dirs = g_get_system_config_dirs ();
  for (i = 0; path == NULL && dirs[i] != NULL; ++i)
    {
      /* Build the filename, if the file exists return the path */
      path = g_build_filename (dirs[i], filename, NULL);
      if (g_path_is_absolute (path) && g_file_test (path, G_FILE_TEST_IS_REGULAR))
        return path;

      g_free (path);
      path = NULL;
    }

  /* Also try the install prefix of garcon in case XDG_CONFIG_DIRS is not
   * properly set (startxfce4 for exaple should take care of that) */
  path = g_build_filename (SYSCONFIGDIR, filename, NULL);
  if (g_path_is_absolute (path) && g_file_test (path, G_FILE_TEST_IS_REGULAR))
    return path;

  g_free (path);
  path = NULL;

  /* Return the path or NULL if the file could not be found */
  return path;
}