/soc/2013/ankitkv/gobjectification: f45f0745da61: Started GObjec...

Ankit Vani a at nevitus.org
Fri Jul 19 13:53:48 EDT 2013


Changeset: f45f0745da614b71aa5c493506dd46d79fa935e4
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-19 23:23 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/f45f0745da61

Description:

Started GObjectification of PurplePresence.
* Added presence.[ch]
* Moved things over from status.[ch]

diffstat:

 libpurple/Makefile.am |    9 +-
 libpurple/presence.c  |  585 ++++++++++++++++++++++++++++++++++++++++++++++++++
 libpurple/presence.h  |  346 +++++++++++++++++++++++++++++
 libpurple/status.c    |  569 ------------------------------------------------
 libpurple/status.h    |  302 +------------------------
 5 files changed, 947 insertions(+), 864 deletions(-)

diffs (truncated from 1933 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -79,6 +79,7 @@ purple_coresources = \
 	pluginpref.c \
 	pounce.c \
 	prefs.c \
+	presence.c \
 	proxy.c \
 	prpl.c \
 	request.c \
@@ -149,6 +150,7 @@ purple_coreheaders = \
 	pluginpref.h \
 	pounce.h \
 	prefs.h \
+	presence.h \
 	proxy.h \
 	prpl.h \
 	request.h \
@@ -187,7 +189,8 @@ purple_enumheaders = \
 	cipher.h \
 	connection.h \
 	conversation.h \
-	conversationtypes.h
+	conversationtypes.h \
+	status.h
 
 marshallers.h: marshallers.list
 	$(AM_V_GEN)$(GLIB_GENMARSHAL) --prefix=purple_smarshal $(srcdir)/marshallers.list --header > marshallers.h
@@ -227,8 +230,8 @@ dbus_headers  = dbus-bindings.h dbus-pur
 dbus_exported = dbus-useful.h dbus-define-api.h account.h accounts.h blistnodes.h \
                 blistnodetypes.h buddylist.h buddyicon.h connection.h conversation.h \
                 conversationtypes.h conversations.h core.h ft.h log.h notify.h \
-                prefs.h roomlist.h savedstatuses.h smiley.h status.h server.h util.h \
-                xmlnode.h prpl.h
+                prefs.h presence.h roomlist.h savedstatuses.h smiley.h status.h \
+                server.h util.h xmlnode.h prpl.h
 
 purple_build_coreheaders = $(addprefix $(srcdir)/, $(purple_coreheaders)) \
 		$(addprefix $(srcdir)/media/, $(purple_mediaheaders)) \
diff --git a/libpurple/presence.c b/libpurple/presence.c
new file mode 100644
--- /dev/null
+++ b/libpurple/presence.c
@@ -0,0 +1,585 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#include "presence.h"
+
+#define PURPLE_PRESENCE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_PRESENCE, PurplePresencePrivate))
+
+/** @copydoc _PurplePresencePrivate */
+typedef struct _PurplePresencePrivate  PurplePresencePrivate;
+
+/** Private data for a presence */
+struct _PurplePresencePrivate
+{
+	PurplePresenceContext context;
+
+	gboolean idle;
+	time_t idle_time;
+	time_t login_time;
+
+	GList *statuses;
+	GHashTable *status_table;
+
+	PurpleStatus *active_status;
+
+	union
+	{
+		PurpleAccount *account;
+
+		struct
+		{
+			PurpleConversation *conv;
+			char *user;
+
+		} chat;
+
+		struct
+		{
+			PurpleAccount *account;
+			char *name;
+			PurpleBuddy *buddy;
+
+		} buddy;
+
+	} u;
+};
+
+/**************************************************************************
+* PurplePresence API
+**************************************************************************/
+PurplePresence *
+purple_presence_new(PurplePresenceContext context)
+{
+	PurplePresence *presence;
+
+	g_return_val_if_fail(context != PURPLE_PRESENCE_CONTEXT_UNSET, NULL);
+
+	presence = g_new0(PurplePresence, 1);
+	PURPLE_DBUS_REGISTER_POINTER(presence, PurplePresence);
+
+	presence->context = context;
+
+	presence->status_table =
+		g_hash_table_new_full(g_str_hash, g_str_equal,
+							  g_free, NULL);
+
+	return presence;
+}
+
+PurplePresence *
+purple_presence_new_for_account(PurpleAccount *account)
+{
+	PurplePresence *presence = NULL;
+	g_return_val_if_fail(account != NULL, NULL);
+
+	presence = purple_presence_new(PURPLE_PRESENCE_CONTEXT_ACCOUNT);
+	presence->u.account = account;
+	presence->statuses = purple_prpl_get_statuses(account, presence);
+
+	return presence;
+}
+
+PurplePresence *
+purple_presence_new_for_conv(PurpleConversation *conv)
+{
+	PurplePresence *presence;
+
+	g_return_val_if_fail(conv != NULL, NULL);
+
+	presence = purple_presence_new(PURPLE_PRESENCE_CONTEXT_CONV);
+	presence->u.chat.conv = conv;
+	/* presence->statuses = purple_prpl_get_statuses(purple_conversation_get_account(conv), presence); ? */
+
+	return presence;
+}
+
+PurplePresence *
+purple_presence_new_for_buddy(PurpleBuddy *buddy)
+{
+	PurplePresence *presence;
+	PurpleAccount *account;
+
+	g_return_val_if_fail(buddy != NULL, NULL);
+	account = purple_buddy_get_account(buddy);
+
+	presence = purple_presence_new(PURPLE_PRESENCE_CONTEXT_BUDDY);
+
+	presence->u.buddy.name    = g_strdup(purple_buddy_get_name(buddy));
+	presence->u.buddy.account = account;
+	presence->statuses = purple_prpl_get_statuses(account, presence);
+
+	presence->u.buddy.buddy = buddy;
+
+	return presence;
+}
+
+void
+purple_presence_destroy(PurplePresence *presence)
+{
+	g_return_if_fail(presence != NULL);
+
+	if (purple_presence_get_context(presence) == PURPLE_PRESENCE_CONTEXT_BUDDY)
+	{
+		g_free(presence->u.buddy.name);
+	}
+	else if (purple_presence_get_context(presence) == PURPLE_PRESENCE_CONTEXT_CONV)
+	{
+		g_free(presence->u.chat.user);
+	}
+
+	g_list_foreach(presence->statuses, (GFunc)purple_status_destroy, NULL);
+	g_list_free(presence->statuses);
+
+	g_hash_table_destroy(presence->status_table);
+
+	PURPLE_DBUS_UNREGISTER_POINTER(presence);
+	g_free(presence);
+}
+
+void
+purple_presence_set_status_active(PurplePresence *presence, const char *status_id,
+		gboolean active)
+{
+	PurpleStatus *status;
+
+	g_return_if_fail(presence  != NULL);
+	g_return_if_fail(status_id != NULL);
+
+	status = purple_presence_get_status(presence, status_id);
+
+	g_return_if_fail(status != NULL);
+	/* TODO: Should we do the following? */
+	/* g_return_if_fail(active == status->active); */
+
+	if (purple_status_is_exclusive(status))
+	{
+		if (!active)
+		{
+			purple_debug_warning("status",
+					"Attempted to set a non-independent status "
+					"(%s) inactive. Only independent statuses "
+					"can be specifically marked inactive.",
+					status_id);
+			return;
+		}
+	}
+
+	purple_status_set_active(status, active);
+}
+
+void
+purple_presence_switch_status(PurplePresence *presence, const char *status_id)
+{
+	purple_presence_set_status_active(presence, status_id, TRUE);
+}
+
+static void
+update_buddy_idle(PurpleBuddy *buddy, PurplePresence *presence,
+		time_t current_time, gboolean old_idle, gboolean idle)
+{
+	PurpleBListUiOps *ops = purple_blist_get_ui_ops();
+	PurpleAccount *account = purple_buddy_get_account(buddy);
+
+	if (!old_idle && idle)
+	{
+		if (purple_prefs_get_bool("/purple/logging/log_system"))
+		{
+			PurpleLog *log = purple_account_get_log(account, FALSE);
+
+			if (log != NULL)
+			{
+				char *tmp, *tmp2;
+				tmp = g_strdup_printf(_("%s became idle"),
+				purple_buddy_get_alias(buddy));
+				tmp2 = g_markup_escape_text(tmp, -1);
+				g_free(tmp);
+
+				purple_log_write(log, PURPLE_MESSAGE_SYSTEM,
+				purple_buddy_get_alias(buddy), current_time, tmp2);
+				g_free(tmp2);
+			}
+		}
+	}
+	else if (old_idle && !idle)
+	{
+		if (purple_prefs_get_bool("/purple/logging/log_system"))
+		{
+			PurpleLog *log = purple_account_get_log(account, FALSE);
+
+			if (log != NULL)
+			{
+				char *tmp, *tmp2;
+				tmp = g_strdup_printf(_("%s became unidle"),
+				purple_buddy_get_alias(buddy));
+				tmp2 = g_markup_escape_text(tmp, -1);
+				g_free(tmp);
+
+				purple_log_write(log, PURPLE_MESSAGE_SYSTEM,
+				purple_buddy_get_alias(buddy), current_time, tmp2);
+				g_free(tmp2);
+			}
+		}
+	}
+
+	if (old_idle != idle)
+		purple_signal_emit(purple_blist_get_handle(), "buddy-idle-changed", buddy,
+		                 old_idle, idle);
+
+	purple_contact_invalidate_priority_buddy(purple_buddy_get_contact(buddy));
+
+	/* Should this be done here? It'd perhaps make more sense to
+	 * connect to buddy-[un]idle signals and update from there
+	 */
+
+	if (ops != NULL && ops->update != NULL)
+		ops->update(purple_blist_get_buddy_list(), (PurpleBListNode *)buddy);
+}
+



More information about the Commits mailing list