changeset 22820:5e6b42e77fb7

Cleanup and avoid unnecessary alloc/free.
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 02 May 2008 23:16:11 +0000
parents 42dfa1139b5c
children 900c7b5660d5 05cb3f04c01e
files libpurple/notify.c
diffstat 1 files changed, 88 insertions(+), 137 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/notify.c	Fri May 02 22:51:14 2008 +0000
+++ b/libpurple/notify.c	Fri May 02 23:16:11 2008 +0000
@@ -66,35 +66,27 @@
 	ops = purple_notify_get_ui_ops();
 
 	if (ops != NULL && ops->notify_message != NULL) {
-		PurpleNotifyInfo *info;
+		void *ui_handle = ops->notify_message(type, title, primary,
+											  secondary);
+		if (ui_handle != NULL) {
 
-		info            = g_new0(PurpleNotifyInfo, 1);
-		info->type      = PURPLE_NOTIFY_MESSAGE;
-		info->handle    = handle;
-		info->ui_handle = ops->notify_message(type, title, primary,
-											  secondary);
-		info->cb = cb;
-		info->cb_user_data = user_data;
+			PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
+			info->type = PURPLE_NOTIFY_MESSAGE;
+			info->handle = handle;
+			info->ui_handle = ui_handle;
+			info->cb = cb;
+			info->cb_user_data = user_data;
 
-		if (info->ui_handle != NULL) {
 			handles = g_list_append(handles, info);
 
 			return info->ui_handle;
-
-		} else {
-			if (info->cb != NULL)
-				info->cb(info->cb_user_data);
-
-			g_free(info);
-
-			return NULL;
 		}
 
-	} else {
-		if (cb != NULL)
-			cb(user_data);
 	}
 
+	if (cb != NULL)
+		cb(user_data);
+
 	return NULL;
 }
 
@@ -108,36 +100,30 @@
 	ops = purple_notify_get_ui_ops();
 
 	if (ops != NULL && ops->notify_email != NULL) {
-		PurpleNotifyInfo *info;
-
-		info            = g_new0(PurpleNotifyInfo, 1);
-		info->type      = PURPLE_NOTIFY_EMAIL;
-		info->handle    = handle;
+		void *ui_handle;
 
 		purple_signal_emit(purple_notify_get_handle(), "displaying-email-notification",
-							subject, from, to, url);
+						   subject, from, to, url);
+
+		ui_handle = ops->notify_email(handle, subject, from, to, url);
+
+		if (ui_handle != NULL) {
 
-		info->ui_handle = ops->notify_email(handle, subject, from, to, url);
-		info->cb = cb;
-		info->cb_user_data = user_data;
+			PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
+			info->type = PURPLE_NOTIFY_EMAIL;
+			info->handle = handle;
+			info->ui_handle = ui_handle;
+			info->cb = cb;
+			info->cb_user_data = user_data;
 
-		if (info->ui_handle != NULL) {
 			handles = g_list_append(handles, info);
 
 			return info->ui_handle;
-
-		} else {
-			if (info->cb != NULL)
-				info->cb(info->cb_user_data);
-
-			g_free(info);
+		}
+	}
 
-			return NULL;
-		}
-	} else {
-		if (cb != NULL)
-			cb(user_data);
-	}
+	if (cb != NULL)
+		cb(user_data);
 
 	return NULL;
 }
@@ -162,39 +148,32 @@
 	ops = purple_notify_get_ui_ops();
 
 	if (ops != NULL && ops->notify_emails != NULL) {
-		PurpleNotifyInfo *info;
-
-		info            = g_new0(PurpleNotifyInfo, 1);
-		info->type      = PURPLE_NOTIFY_EMAILS;
-		info->handle    = handle;
+		void *ui_handle;
 
 		purple_signal_emit(purple_notify_get_handle(), "displaying-emails-notification",
 							subjects, froms, tos, urls, count);
 
-		info->ui_handle = ops->notify_emails(handle, count, detailed, subjects,
+		ui_handle = ops->notify_emails(handle, count, detailed, subjects,
 											 froms, tos, urls);
-		info->cb = cb;
-		info->cb_user_data = user_data;
 
-		if (info->ui_handle != NULL) {
+		if (ui_handle != NULL) {
+			PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
+			info->type = PURPLE_NOTIFY_EMAILS;
+			info->handle = handle;
+			info->ui_handle = ui_handle;
+			info->cb = cb;
+			info->cb_user_data = user_data;
+
 			handles = g_list_append(handles, info);
 
 			return info->ui_handle;
-
-		} else {
-			if (info->cb != NULL)
-				info->cb(info->cb_user_data);
-
-			g_free(info);
-
-			return NULL;
 		}
 
-	} else {
-		if (cb != NULL)
-			cb(user_data);
 	}
 
+	if (cb != NULL)
+		cb(user_data);
+
 	return NULL;
 }
 
@@ -210,34 +189,25 @@
 	ops = purple_notify_get_ui_ops();
 
 	if (ops != NULL && ops->notify_formatted != NULL) {
-		PurpleNotifyInfo *info;
+		void *ui_handle = ops->notify_formatted(title, primary, secondary, text);
+
+		if (ui_handle != NULL) {
 
-		info            = g_new0(PurpleNotifyInfo, 1);
-		info->type      = PURPLE_NOTIFY_FORMATTED;
-		info->handle    = handle;
-		info->ui_handle = ops->notify_formatted(title, primary, secondary, text);
-		info->cb = cb;
-		info->cb_user_data = user_data;
+			PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
+			info->type = PURPLE_NOTIFY_FORMATTED;
+			info->handle = handle;
+			info->ui_handle = ui_handle;
+			info->cb = cb;
+			info->cb_user_data = user_data;
 
-		if (info->ui_handle != NULL) {
 			handles = g_list_append(handles, info);
 
 			return info->ui_handle;
-
-		} else {
-			if (info->cb != NULL)
-				info->cb(info->cb_user_data);
-
-			g_free(info);
-
-			return NULL;
 		}
-
-	} else {
-		if (cb != NULL)
-			cb(user_data);
 	}
 
+	if (cb != NULL)
+		cb(user_data);
 	return NULL;
 }
 
@@ -252,34 +222,25 @@
 	ops = purple_notify_get_ui_ops();
 
 	if (ops != NULL && ops->notify_searchresults != NULL) {
-		PurpleNotifyInfo *info;
+		void *ui_handle = ops->notify_searchresults(gc, title, primary,
+													secondary, results, user_data);
+		if (ui_handle != NULL) {
 
-		info            = g_new0(PurpleNotifyInfo, 1);
-		info->type      = PURPLE_NOTIFY_SEARCHRESULTS;
-		info->handle    = gc;
-		info->ui_handle = ops->notify_searchresults(gc, title, primary,
-													secondary, results, user_data);
-		info->cb = cb;
-		info->cb_user_data = user_data;
+			PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
+			info->type      = PURPLE_NOTIFY_SEARCHRESULTS;
+			info->handle    = gc;
+			info->ui_handle = ui_handle;
+			info->cb = cb;
+			info->cb_user_data = user_data;
 
-		if (info->ui_handle != NULL) {
 			handles = g_list_append(handles, info);
 
 			return info->ui_handle;
-
-		} else {
-			if (info->cb != NULL)
-				info->cb(info->cb_user_data);
-
-			g_free(info);
+		}
+	}
 
-			return NULL;
-		}
-
-	} else {
-		if (cb != NULL)
-			cb(user_data);
-	}
+	if (cb != NULL)
+		cb(user_data);
 
 	return NULL;
 }
@@ -449,37 +410,30 @@
 	ops = purple_notify_get_ui_ops();
 
 	if (ops != NULL && ops->notify_userinfo != NULL) {
-		PurpleNotifyInfo *info;
-
-		info            = g_new0(PurpleNotifyInfo, 1);
-		info->type      = PURPLE_NOTIFY_USERINFO;
-		info->handle    = gc;
+		void *ui_handle;
 
 		purple_signal_emit(purple_notify_get_handle(), "displaying-userinfo",
 						 purple_connection_get_account(gc), who, user_info);
 
-		info->ui_handle = ops->notify_userinfo(gc, who, user_info);
-		info->cb = cb;
-		info->cb_user_data = user_data;
+		ui_handle = ops->notify_userinfo(gc, who, user_info);
+
+		if (ui_handle != NULL) {
 
-		if (info->ui_handle != NULL) {
+			PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
+			info->type = PURPLE_NOTIFY_USERINFO;
+			info->handle = gc;
+			info->ui_handle = ui_handle;
+			info->cb = cb;
+			info->cb_user_data = user_data;
+
 			handles = g_list_append(handles, info);
 
 			return info->ui_handle;
-
-		} else {
-			if (info->cb != NULL)
-				info->cb(info->cb_user_data);
-
-			g_free(info);
+		}
+	}
 
-			return NULL;
-		}
-
-	} else {
-		if (cb != NULL)
-			cb(user_data);
-	}
+	if (cb != NULL)
+		cb(user_data);
 
 	return NULL;
 }
@@ -705,22 +659,19 @@
 	ops = purple_notify_get_ui_ops();
 
 	if (ops != NULL && ops->notify_uri != NULL) {
-		PurpleNotifyInfo *info;
+
+		void *ui_handle = ops->notify_uri(uri);
+
+		if (ui_handle != NULL) {
 
-		info            = g_new0(PurpleNotifyInfo, 1);
-		info->type      = PURPLE_NOTIFY_URI;
-		info->handle    = handle;
-		info->ui_handle = ops->notify_uri(uri);
+			PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
+			info->type = PURPLE_NOTIFY_URI;
+			info->handle = handle;
+			info->ui_handle = ui_handle;
 
-		if (info->ui_handle != NULL) {
 			handles = g_list_append(handles, info);
 
 			return info->ui_handle;
-
-		} else {
-			g_free(info);
-
-			return NULL;
 		}
 	}