immodules: Move path code out of gtkrc

This commit is contained in:
Benjamin Otte
2016-10-06 19:59:53 +02:00
parent 1aa336b500
commit 361d322bfb
3 changed files with 72 additions and 13 deletions

View File

@@ -33,6 +33,7 @@
#include <gmodule.h>
#include "gtkimmoduleprivate.h"
#include "gtkimcontextsimple.h"
#include "gtkmodulesprivate.h"
#include "gtksettings.h"
#include "gtkprivate.h"
#include "gtkutilsprivate.h"
@@ -63,8 +64,6 @@
#define GDK_DEPRECATED
#define GDK_DEPRECATED_FOR(f)
#include "deprecated/gtkrc.h"
/* We need to call getc() a lot in a loop. This is suboptimal,
* as getc() does thread locking on the FILE it is given.
* To optimize that, lock the file first, then call getc(),
@@ -332,12 +331,71 @@ add_builtin_module (const gchar *module_name,
return module;
}
/*
* gtk_get_im_module_path:
*
* Obtains the path in which to look for IM modules. See the documentation
* of the `GTK_PATH`
* environment variable for more details about looking up modules. This
* function is useful solely for utilities supplied with GTK+ and should
* not be used by applications under normal circumstances.
*
* Returns: (type filename): a newly-allocated string containing the
* path in which to look for IM modules.
*/
gchar *
gtk_get_im_module_path (void)
{
gchar **paths = _gtk_get_module_path ("immodules");
gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
g_strfreev (paths);
return result;
}
/*
* gtk_get_im_module_file:
*
* Obtains the path to the IM modules file. See the documentation
* of the `GTK_IM_MODULE_FILE`
* environment variable for more details.
*
* Returns: (type filename): a newly-allocated string containing the
* name of the file listing the IM modules available for loading
*/
gchar *
gtk_get_im_module_file (void)
{
const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
gchar *result = NULL;
if (var)
result = g_strdup (var);
if (!result)
{
const gchar *var;
gchar *path;
var = g_getenv ("GTK_EXE_PREFIX");
if (var)
path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, "immodules.cache", NULL);
else
path = g_build_filename (_gtk_get_libdir (), "gtk-3.0", GTK_BINARY_VERSION, "immodules.cache", NULL);
return path;
}
return result;
}
static void
gtk_im_module_initialize (void)
{
GString *line_buf = g_string_new (NULL);
GString *tmp_buf = g_string_new (NULL);
gchar *filename = gtk_rc_get_im_module_file();
gchar *filename = gtk_get_im_module_file();
FILE *file;
gboolean have_error = FALSE;

View File

@@ -19,8 +19,8 @@
#define __GTK_IM_MODULE_PRIVATE_H__
#include <gdk/gdk.h>
#include <gtk/gtkimcontext.h>
#include <gtk/gtkimcontextinfo.h>
#include "gtkimcontext.h"
#include "gtkimcontextinfo.h"
G_BEGIN_DECLS
@@ -29,6 +29,12 @@ void _gtk_im_module_list (const GtkIMContextInfo ***
GtkIMContext * _gtk_im_module_create (const gchar *context_id);
const gchar * _gtk_im_module_get_default_context_id (void);
/* Needs to be exported API for gtk-queryimmodules */
GDK_AVAILABLE_IN_ALL
gchar * gtk_get_im_module_path (void);
GDK_AVAILABLE_IN_ALL
gchar * gtk_get_im_module_file (void);
G_END_DECLS
#endif /* __GTK_IM_MODULE_PRIVATE_H__ */

View File

@@ -35,11 +35,10 @@
#endif
#include "gtk/gtkimcontextinfo.h"
#include "gtk/gtkimmoduleprivate.h"
#include "gtk/gtkversion.h"
#include "gtk/gtkutilsprivate.h"
#include "gtk/deprecated/gtkrc.h"
static void
escape_string (GString *contents, const char *str)
{
@@ -164,9 +163,7 @@ int main (int argc, char **argv)
if (argc > 1 && strcmp (argv[1], "--update-cache") == 0)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
cache_file = gtk_rc_get_im_module_file ();
G_GNUC_END_IGNORE_DEPRECATIONS
cache_file = gtk_get_im_module_file ();
first_file = 2;
}
@@ -184,9 +181,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
char **dirs;
GHashTable *dirs_done;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
path = gtk_rc_get_im_module_path ();
G_GNUC_END_IGNORE_DEPRECATIONS
path = gtk_get_im_module_path ();
g_string_append_printf (contents, "# ModulesPath = %s\n#\n", path);