/pidgin/main: 44327a195f54: cross-win32: finch: keep your files ...

Tomasz Wasilczyk twasilczyk at pidgin.im
Wed Apr 23 06:36:08 EDT 2014


Changeset: 44327a195f542ae24bc1e3110fd9ab837a1bd5d1
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-23 12:35 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/44327a195f54

Description:

cross-win32: finch: keep your files in config dir

diffstat:

 finch/gntui.c              |  13 ++++++++++---
 finch/libgnt/gnt.h         |  11 +++++++++++
 finch/libgnt/gntinternal.h |   2 +-
 finch/libgnt/gntmain.c     |  23 ++++++++++++++++++++++-
 finch/libgnt/gntwm.c       |   4 ++--
 5 files changed, 46 insertions(+), 7 deletions(-)

diffs (127 lines):

diff --git a/finch/gntui.c b/finch/gntui.c
--- a/finch/gntui.c
+++ b/finch/gntui.c
@@ -47,8 +47,12 @@
 void finch_ui_init()
 {
 #ifdef STANDALONE
+#ifdef _WIN32 /* TODO: don't change it when using FHS under win32 */
+	gnt_set_config_dir(purple_user_dir());
+#endif /* _WIN32 */
+
 	gnt_init();
-#endif
+#endif /* STANDALONE */
 
 	purple_prefs_add_none("/purple/gnt");
 
@@ -147,6 +151,9 @@ void finch_ui_uninit()
 #endif
 
 	gnt_quit();
-#endif
+
+#ifdef _WIN32
+	gnt_set_config_dir(NULL);
+#endif /* _WIN32 */
+#endif /* STANDALONE */
 }
-
diff --git a/finch/libgnt/gnt.h b/finch/libgnt/gnt.h
--- a/finch/libgnt/gnt.h
+++ b/finch/libgnt/gnt.h
@@ -57,6 +57,17 @@
 void gnt_init(void);
 
 /**
+ * gnt_set_config_dir:
+ * @config_dir: the path to a configuration directory, may be %NULL.
+ *
+ * Change directory to store gnt configuration files (default is ~).
+ *
+ * You have to call this before #gnt_init. You might want to call this
+ * with %NULL, to free the resources, but not before a call to #gnt_quit.
+ */
+void gnt_set_config_dir(const gchar *config_dir);
+
+/**
  * gnt_main:
  *
  * Start running the mainloop for gnt.
diff --git a/finch/libgnt/gntinternal.h b/finch/libgnt/gntinternal.h
--- a/finch/libgnt/gntinternal.h
+++ b/finch/libgnt/gntinternal.h
@@ -44,4 +44,4 @@
 
 extern int gnt_need_conversation_to_locale;
 extern const char *C_(const char *x);
-
+const gchar *gnt_get_config_dir(void);
diff --git a/finch/libgnt/gntmain.c b/finch/libgnt/gntmain.c
--- a/finch/libgnt/gntmain.c
+++ b/finch/libgnt/gntmain.c
@@ -93,6 +93,8 @@ static GntClipboard *clipboard;
 
 int gnt_need_conversation_to_locale;
 
+static gchar *custom_config_dir = NULL;
+
 #define HOLDING_ESCAPE  (escape_stuff.timer != 0)
 
 static struct {
@@ -107,6 +109,25 @@ escape_timeout(gpointer data)
 	return FALSE;
 }
 
+void
+gnt_set_config_dir(const gchar *config_dir)
+{
+	if (channel) {
+		gnt_warning("gnt_set_config_dir failed: %s",
+			"gnt already initialized");
+	}
+	free(custom_config_dir);
+	custom_config_dir = g_strdup(config_dir);
+}
+
+const gchar *
+gnt_get_config_dir(void)
+{
+	if (custom_config_dir)
+		return custom_config_dir;
+	return g_get_home_dir();
+}
+
 #ifndef _WIN32
 /**
  * detect_mouse_action:
@@ -613,7 +634,7 @@ void gnt_init()
 	gnt_init_keys();
 	gnt_init_styles();
 
-	filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL);
+	filename = g_build_filename(gnt_get_config_dir(), ".gntrc", NULL);
 	gnt_style_read_configure_file(filename);
 	g_free(filename);
 
diff --git a/finch/libgnt/gntwm.c b/finch/libgnt/gntwm.c
--- a/finch/libgnt/gntwm.c
+++ b/finch/libgnt/gntwm.c
@@ -331,7 +331,7 @@ static void
 read_window_positions(GntWM *wm)
 {
 	GKeyFile *gfile = g_key_file_new();
-	char *filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL);
+	char *filename = g_build_filename(gnt_get_config_dir(), ".gntpositions", NULL);
 	GError *error = NULL;
 	char **keys;
 	gsize nk;
@@ -2120,7 +2120,7 @@ write_already(gpointer data)
 	FILE *file;
 	char *filename;
 
-	filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL);
+	filename = g_build_filename(gnt_get_config_dir(), ".gntpositions", NULL);
 
 	file = fopen(filename, "wb");
 	if (file == NULL) {



More information about the Commits mailing list