/dev/tomkiewicz/new-smileys: 6a0bbe6adc4a: PidginSmileyTheme: so...

Tomasz Wasilczyk twasilczyk at pidgin.im
Mon Mar 31 14:08:49 EDT 2014


Changeset: 6a0bbe6adc4a5f38ceccfffef9de1f6ef5961c28
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-03-31 20:08 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/6a0bbe6adc4a

Description:

PidginSmileyTheme: some fixes

diffstat:

 libpurple/glibcompat.h   |  30 +++++++++++++++++++++
 libpurple/util.c         |  66 ++++++++++++++++++++++++++++++++++++++++++++++++
 pidgin/gtksmiley-theme.c |  31 ++++++++++++++++------
 3 files changed, 118 insertions(+), 9 deletions(-)

diffs (209 lines):

diff --git a/libpurple/glibcompat.h b/libpurple/glibcompat.h
--- a/libpurple/glibcompat.h
+++ b/libpurple/glibcompat.h
@@ -48,6 +48,34 @@
 #endif /* __clang__ */
 
 
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+
+#include <errno.h>
+#include <fcntl.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+static inline gboolean g_close(gint fd, GError **error)
+{
+	int res;
+	int errsv;
+
+	res = close(fd);
+
+	if (G_LIKELY(res == 0))
+		return TRUE;
+	if (G_UNLIKELY(errno == EINTR))
+		return TRUE;
+
+	errsv = errno;
+	g_set_error_literal(error, G_FILE_ERROR,
+		g_file_error_from_errno(errsv), g_strerror(errsv));
+	errno = errsv;
+
+	return FALSE;
+}
+
 #if !GLIB_CHECK_VERSION(2, 32, 0)
 
 #include <glib-object.h>
@@ -129,4 +157,6 @@ static inline void g_object_class_instal
 
 #endif /* < 2.32.0 */
 
+#endif /* < 2.36.0 */
+
 #endif /* _GLIBCOMPAT_H_ */
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -4976,3 +4976,69 @@ gchar *purple_http_digest_calculate_resp
 
 	return g_strdup(hash2);
 }
+
+#if 0
+
+/* Temporarily removed - re-add this when you need ini file support. */
+
+#define PURPLE_KEY_FILE_DEFAULT_MAX_SIZE 102400
+#define PURPLE_KEY_FILE_HARD_LIMIT 10485760
+
+gboolean
+purple_key_file_load_from_ini(GKeyFile *key_file, const gchar *file,
+	gsize max_size)
+{
+	const gchar *header = "[default]\n\n";
+	int header_len = strlen(header);
+	int fd;
+	struct stat st;
+	gsize file_size, buff_size;
+	gchar *buff;
+	GError *error = NULL;
+
+	g_return_val_if_fail(key_file != NULL, FALSE);
+	g_return_val_if_fail(file != NULL, FALSE);
+	g_return_val_if_fail(max_size < PURPLE_KEY_FILE_HARD_LIMIT, FALSE);
+
+	if (max_size == 0)
+		max_size = PURPLE_KEY_FILE_DEFAULT_MAX_SIZE;
+
+	fd = g_open(file, O_RDONLY, S_IREAD);
+	if (fd == -1) {
+		purple_debug_error("util", "Failed to read ini file %s", file);
+		return FALSE;
+	}
+
+	if (fstat(fd, &st) != 0) {
+		purple_debug_error("util", "Failed to fstat ini file %s", file);
+		return FALSE;
+	}
+
+	file_size = (st.st_size > max_size) ? max_size : st.st_size;
+
+	buff_size = file_size + header_len;
+	buff = g_new(gchar, buff_size);
+	memcpy(buff, header, header_len);
+	if (read(fd, buff + header_len, file_size) != (gssize)file_size) {
+		purple_debug_error("util",
+			"Failed to read whole ini file %s", file);
+		g_close(fd, NULL);
+		free(buff);
+		return FALSE;
+	}
+	g_close(fd, NULL);
+
+	g_key_file_load_from_data(key_file, buff, buff_size,
+		G_KEY_FILE_NONE, &error);
+
+	free(buff);
+
+	if (error) {
+		purple_debug_error("util", "Failed parsing ini file %s: %s",
+			file, error->message);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+#endif
diff --git a/pidgin/gtksmiley-theme.c b/pidgin/gtksmiley-theme.c
--- a/pidgin/gtksmiley-theme.c
+++ b/pidgin/gtksmiley-theme.c
@@ -21,12 +21,16 @@
 
 #include "gtksmiley-theme.h"
 
+#include "debug.h"
+
 #include <glib/gstdio.h>
 
 #define PIDGIN_SMILEY_THEME_GET_PRIVATE(obj) \
 	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PIDGIN_TYPE_SMILEY_THEME, \
 	PidginSmileyThemePrivate))
 
+#define PIDGIN_SMILEY_THEME_MAX_INDEX_SIZE 102400
+
 typedef struct
 {
 	gchar *path;
@@ -67,9 +71,9 @@ pidgin_smiley_theme_load(const gchar *th
 
 	priv->path = g_strdup(theme_path);
 
-	/* TODO: parse index_path */
+	g_free(index_path);
 
-	g_free(index_path);
+	purple_debug_fatal("tomo", "loading not implemented");
 }
 
 static void
@@ -101,7 +105,13 @@ pidgin_smiley_theme_probe(void)
 			continue;
 
 		while ((theme_dir_name = g_dir_read_name(dir))) {
-			gchar *theme_path = g_build_filename(
+			gchar *theme_path;
+
+			/* Ignore Pidgin 2.x.y "none" theme. */
+			if (g_strcmp0(theme_dir_name, "none") == 0)
+				continue;
+
+			theme_path = g_build_filename(
 				probe_dirs[i], theme_dir_name, NULL);
 
 			if (g_file_test(theme_path, G_FILE_TEST_IS_DIR))
@@ -138,6 +148,9 @@ pidgin_smiley_theme_init(void)
 
 	if (!g_file_test(user_smileys_dir, G_FILE_TEST_IS_DIR))
 		g_mkdir(user_smileys_dir, S_IRUSR | S_IWUSR | S_IXUSR);
+
+	//TODO: remove it
+	pidgin_smiley_theme_probe();
 }
 
 void
@@ -169,7 +182,7 @@ pidgin_smiley_theme_finalize(GObject *ob
 }
 
 static void
-pidgin_smiley_theme_class_init(PurpleSmileyListClass *klass)
+pidgin_smiley_theme_class_init(PidginSmileyThemeClass *klass)
 {
 	GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
 	PurpleSmileyThemeClass *pst_class = PURPLE_SMILEY_THEME_CLASS(klass);
@@ -184,19 +197,19 @@ pidgin_smiley_theme_class_init(PurpleSmi
 }
 
 GType
-purple_smiley_theme_get_type(void)
+pidgin_smiley_theme_get_type(void)
 {
 	static GType type = 0;
 
 	if (G_UNLIKELY(type == 0)) {
 		static const GTypeInfo info = {
-			.class_size = sizeof(PurpleSmileyThemeClass),
+			.class_size = sizeof(PidginSmileyThemeClass),
 			.class_init = (GClassInitFunc)pidgin_smiley_theme_class_init,
-			.instance_size = sizeof(PurpleSmileyTheme),
+			.instance_size = sizeof(PidginSmileyTheme),
 		};
 
-		type = g_type_register_static(G_TYPE_OBJECT,
-			"PurpleSmileyTheme", &info, G_TYPE_FLAG_ABSTRACT);
+		type = g_type_register_static(PURPLE_TYPE_SMILEY_THEME,
+			"PidginSmileyTheme", &info, 0);
 	}
 
 	return type;



More information about the Commits mailing list