cpw.nader.asynclogging-3: c60a71e8: Made commonlog properly notify when its ...

morshed.nader at gmail.com morshed.nader at gmail.com
Tue May 17 14:36:15 EDT 2011


----------------------------------------------------------------------
Revision: c60a71e810a47a8559c2743432ff0e3b5ea69283
Parent:   1e3a691b4d6e637f1247911ce0d075bc40f36c4e
Author:   morshed.nader at gmail.com
Date:     05/17/11 04:09:19
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/c60a71e810a47a8559c2743432ff0e3b5ea69283

Changelog: 

Made commonlog properly notify when its properties are modified
Added an extra comment for where PURPLE_IS_ACCOUNT should be checked in the future
Made PurpleCommonLog's internal writers/removers/etc use proper getters/setters to (hopefully) avoid errors
Added missing newline endings to calls to purple_debug_warning

Changes against parent 1e3a691b4d6e637f1247911ce0d075bc40f36c4e

  patched  finch/gntlog.c
  patched  libpurple/commonlog.c
  patched  libpurple/htmllog.c
  patched  libpurple/oldlog.c
  patched  pidgin/gtklog.c

-------------- next part --------------
============================================================
--- pidgin/gtklog.c	74516f85f54a0902eaf2570ffdb741aea62b5668
+++ pidgin/gtklog.c	b9cc71351ef292726865cb26e5850de219f125b3
@@ -1203,7 +1203,7 @@ pidgin_log_show(PurpleLogChatType chat_t
 	gchar *title;
 
 	if (chat_type != PURPLE_LOG_IM) {
-		g_return_if_fail(account != NULL);
+		g_return_if_fail(account != NULL); /* XXX: PURPLE_IS_ACCOUNT */
 		g_return_if_fail(buddyname != NULL);
 	}
 
============================================================
--- finch/gntlog.c	0302692f77a653361873b78887ba5bc915374421
+++ finch/gntlog.c	b3071e409cbd239f431f6ef8015d31c7e0dc3e90
@@ -741,7 +741,7 @@ finch_log_show(PurpleLogChatType chat_ty
 	gchar *title;
 
 	if (chat_type != PURPLE_LOG_IM) {
-		g_return_if_fail(account != NULL);
+		g_return_if_fail(account != NULL); /* XXX: PURPLE_IS_ACCOUNT */
 		g_return_if_fail(username != NULL);
 	}
 
============================================================
--- libpurple/htmllog.c	254384830e78b4b5ad9fa6e8b2575b656962fdb4
+++ libpurple/htmllog.c	0bec1877331371236495937cb9249dc54346a385
@@ -434,7 +434,7 @@ write_footer(PurpleCommonLog *common_log
 	g_object_unref(file_stream);
 
 	if (!success)
-		purple_debug_warning("htmllog", "Error writing file footer: %s",
+		purple_debug_warning("htmllog", "Error writing file footer: %s\n",
 			error->message);
 
 	g_clear_error(&error);
============================================================
--- libpurple/oldlog.c	ebdb68017f452903f287e9e801ed665479c0f799
+++ libpurple/oldlog.c	81c5ce3da6157d4ac806dff2ea825b999e1c8cef
@@ -204,7 +204,7 @@ purple_old_log_list(PurpleLog *log, Purp
 			return list;
 		}
 
-		/* purple_debug_warning is not thread-safe (At the moment)
+		/* XXX: purple_debug_warning is not thread-safe (At the moment)
 		purple_debug_warning("log", "Index \"%s\" exists, but is older "
 			"than the log.\n", pathstr);*/
 		g_object_unref(file_idx);
@@ -223,7 +223,7 @@ purple_old_log_list(PurpleLog *log, Purp
 	index_tmp = g_strdup_printf("%s.XXXXXX", pathstr);
 
 	if ((index_fd = g_mkstemp(index_tmp)) == -1) {
-		/* purple_debug_error is not thread-safe (At the moment)
+		/* XXX: purple_debug_error is not thread-safe (At the moment)
 		purple_debug_error("log", "Failed to open index temp file: %s\n",
 			g_strerror(errno));*/
 
@@ -358,13 +358,13 @@ purple_old_log_list(PurpleLog *log, Purp
 		fclose(index);
 
 		if (g_rename(index_tmp, pathstr)) {
-			/* purple_debug_warning is not thread-safe (At the moment)
+			/* XXX: purple_debug_warning is not thread-safe (At the moment)
 			purple_debug_warning("log", "Failed to rename index temp file "
 				"\"%s\" to \"%s\": %s\n",
 				index_tmp, pathstr, g_strerror(errno));*/
 			g_unlink(index_tmp);
 		} else {
-			/* purple_debug_info is not thread-safe (At the moment)
+			/* XXX: purple_debug_info is not thread-safe (At the moment)
 			purple_debug_info("log", "Built index: %s\n", pathstr);*/
 			; 
 		}
============================================================
--- libpurple/commonlog.c	3abdc7ce806a3422c3d52fe91778848f12f51068
+++ libpurple/commonlog.c	80b9dac726ddb36916bba3a36a5871c2f39f9b72
@@ -109,12 +109,12 @@ purple_common_log_class_init(PurpleCommo
 			G_PARAM_READWRITE);
 
 	g_object_class_install_property(gobject_class,
-		PROP_COMMON_LOG_OFFSET,
-		properties[PROP_COMMON_LOG_OFFSET]);
+		PROP_COMMON_LOG_FILE,
+		properties[PROP_COMMON_LOG_FILE]);
 
 	g_object_class_install_property(gobject_class,
-		PROP_COMMON_LOG_FILE,
-		properties[PROP_COMMON_LOG_FILE]);
+		PROP_COMMON_LOG_OFFSET,
+		properties[PROP_COMMON_LOG_OFFSET]);
 
 	g_object_class_install_property(gobject_class,
 		PROP_COMMON_LOG_LENGTH,
@@ -202,6 +202,13 @@ purple_common_log_set_file(PurpleCommonL
 		g_object_ref(file);
 
 	priv->file = file;
+
+#if GLIB_CHECK_VERSION(2, 26, 0)
+	g_object_notify_by_pspec(G_OBJECT(common_log),
+		properties[PROP_COMMON_LOG_FILE]);
+#else
+	g_object_notify(G_OBJECT(common_log), "file");
+#endif
 }
 
 void
@@ -211,6 +218,13 @@ purple_common_log_set_offset(PurpleCommo
 	g_return_if_fail(offset >= -1);
 
 	PURPLE_COMMON_LOG_GET_PRIVATE(log)->offset = offset;
+
+#if GLIB_CHECK_VERSION(2, 26, 0)
+	g_object_notify_by_pspec(G_OBJECT(common_log),
+		properties[PROP_COMMON_LOG_OFFSET]);
+#else
+	g_object_notify(G_OBJECT(common_log), "offset");
+#endif
 }
 
 void
@@ -220,6 +234,13 @@ purple_common_log_set_length(PurpleCommo
 	g_return_if_fail(length >= -1);
 
 	PURPLE_COMMON_LOG_GET_PRIVATE(log)->length = length;
+
+#if GLIB_CHECK_VERSION(2, 26, 0)
+	g_object_notify_by_pspec(G_OBJECT(common_log),
+		properties[PROP_COMMON_LOG_LENGTH]);
+#else
+	g_object_notify(G_OBJECT(common_log), "length");
+#endif
 }
 
 GFile *
@@ -260,10 +281,10 @@ purple_log_common_remove(PurpleLog *log,
 purple_log_common_remove(PurpleLog *log, GCancellable *cancellable,
 	GError **error)
 {
-	PurpleCommonLogPrivate *priv = PURPLE_COMMON_LOG_GET_PRIVATE(log);
+	GFile *file = purple_common_log_get_file(COMMON_LOG(log));
 	gboolean result;
 
-	if (priv->file == NULL) {
+	if (file == NULL) {
 		g_set_error_literal(error,
 			G_IO_ERROR,
 			G_IO_ERROR_FAILED,
@@ -272,9 +293,8 @@ purple_log_common_remove(PurpleLog *log,
 		return FALSE;
 	}
 
-	result = g_file_delete(priv->file, cancellable, error);
-	g_object_unref(priv->file);
-	priv->file = NULL;
+	result = g_file_delete(file, cancellable, error);
+	purple_log_common_set_file(COMMON_LOG(log), NULL);
 
 	return result;
 }
@@ -283,13 +303,16 @@ purple_log_common_writer(PurpleLog *log,
 purple_log_common_writer(PurpleLog *log, const gchar *ext,
 	GCancellable *cancellable, GError **error)
 {
-	PurpleCommonLogPrivate *priv;
+	PurpleCommonLog *common_log;
+	GFile *file;
 
 	g_return_val_if_fail(PURPLE_IS_COMMON_LOG(log), FALSE);
 
-	priv = PURPLE_COMMON_LOG_GET_PRIVATE(log);
+	common_log = PURPLE_COMMON_LOG(log);
+	file = purple_common_log_get_file(common_log);
 
-	if (priv->file == NULL) {
+	if (file == NULL) {
+		GFile *file;
 		GFileOutputStream *stream;
 		struct tm *tm;
 		const gchar *tz, *date;
@@ -330,27 +353,29 @@ purple_log_common_writer(PurpleLog *log,
 		g_free(dir);
 		g_free(filename);
 
-		priv->file = g_file_new_for_path(path);
+		file = g_file_new_for_path(path);
 		g_free(path);
 
 		/* Make sure the file is writeable */
-		stream = g_file_append_to(priv->file, G_FILE_CREATE_PRIVATE,
-			cancellable, error);
+		stream = g_file_append_to(file, G_FILE_CREATE_PRIVATE, cancellable,
+			error);
 
-		if (stream == NULL) {
-			// PurpleConversation *conv = purple_log_get_conversation(log);
+		if (stream != NULL) {
+			g_object_unref(stream);
+			purple_log_common_set_file(common_log, file);
+			g_object_unref(file);
+		else {
+			/* XXX: Can uncomment this when the rest of libpurple is thread-safe
+			PurpleConversation *conv = purple_log_get_conversation(log);
 
-			// if (conv != NULL)
-				// purple_conversation_write(conv, NULL,
-					// _("Logging of this conversation failed."),
-					// PURPLE_MESSAGE_ERROR, time(NULL));
+			if (conv != NULL)
+				purple_conversation_write(conv, NULL,
+					_("Logging of this conversation failed."),
+					PURPLE_MESSAGE_ERROR, time(NULL));*/
 
-			g_object_unref(priv->file);
-			priv->file = NULL;
-
+			g_object_unref(file);
 			return FALSE;
-		} else
-			g_object_unref(stream);
+		}
 	}
 
 	return TRUE;
@@ -756,14 +781,20 @@ purple_log_common_size(PurpleLog *log, G
 purple_log_common_size(PurpleLog *log, GCancellable *cancellable,
 	GError **error)
 {
-	PurpleCommonLogPrivate *priv = PURPLE_COMMON_LOG_GET_PRIVATE(log);
+	PurpleCommonLog *common_log = PURPLE_COMMON_LOG(log);
+	GFile *file;
 	GFileInfo *info;
+	gssize length;
 	guint64 file_size;
 
-	if (priv->length >= 0)
-		return priv->length;
+	length = purple_common_log_get_length(common_log);
 
-	if (priv->file == NULL) {
+	if (length >= 0)
+		return length;
+
+	file = purple_common_log_get_file(common_log);
+
+	if (file == NULL) {
 		g_set_error_literal(error,
 			G_IO_ERROR,
 			G_IO_ERROR_FAILED,
@@ -772,7 +803,7 @@ purple_log_common_size(PurpleLog *log, G
 		return -1;
 	}
 
-	info = g_file_query_info(priv->file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+	info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
 		G_FILE_QUERY_INFO_NONE, cancellable, error);
 
 	if (info == NULL)
@@ -791,8 +822,10 @@ purple_common_log_finalize(GObject *obje
 {
 	PurpleCommonLogPrivate *priv = PURPLE_COMMON_LOG_GET_PRIVATE(object);
 
-	if (priv->file != NULL)
+	if (priv->file != NULL) {
 		g_object_unref(priv->file);
+		priv->file = NULL;
+	}
 
 	G_OBJECT_CLASS(purple_common_log_parent_class)->finalize(object);
 }


More information about the Commits mailing list