pidgin/pidgin

Parents 8737840a09b7
Children 503cfa50c8c3
Extract pidgin_presence_get_icon_name from PidginPresenceIcon so others can use it.

Extract `pidgin_presence_get_icon_name` from PidginPresenceIcon so others can use it.

Testing Done:
Compiled, `pidgin-pot`, `pidgin-doc`, and joined an XMPP MUC as well as Bonjour IM.

Reviewed at https://reviews.imfreedom.org/r/278/
--- a/doc/reference/pidgin/pidgin-docs.xml Thu Dec 17 23:48:47 2020 -0600
+++ b/doc/reference/pidgin/pidgin-docs.xml Thu Dec 17 23:50:15 2020 -0600
@@ -77,6 +77,7 @@
<xi:include href="xml/pidginplugininfo.xml" />
<xi:include href="xml/pidginpluginsdialog.xml" />
<xi:include href="xml/pidginpluginsmenu.xml" />
+ <xi:include href="xml/pidginpresence.xml" />
<xi:include href="xml/pidginpresenceicon.xml" />
<xi:include href="xml/pidginstock.xml" />
<xi:include href="xml/pidginstyle.xml" />
--- a/pidgin/meson.build Thu Dec 17 23:48:47 2020 -0600
+++ b/pidgin/meson.build Thu Dec 17 23:50:15 2020 -0600
@@ -57,6 +57,7 @@
'pidginplugininfo.c',
'pidginpluginsdialog.c',
'pidginpluginsmenu.c',
+ 'pidginpresence.c',
'pidginpresenceicon.c',
'pidginprotocolchooser.c',
'pidginprotocolstore.c',
@@ -128,6 +129,7 @@
'pidginplugininfo.h',
'pidginpluginsdialog.h',
'pidginpluginsmenu.h',
+ 'pidginpresence.h',
'pidginpresenceicon.h',
'pidginprotocolchooser.h',
'pidginprotocolstore.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginpresence.c Thu Dec 17 23:50:15 2020 -0600
@@ -0,0 +1,75 @@
+/*
+ * Pidgin - Internet Messenger
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * Pidgin 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, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "pidgin/pidginpresence.h"
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+const gchar *
+pidgin_presence_get_icon_name(PurplePresence *presence, const gchar *fallback) {
+ PurpleStatus *status = NULL;
+ PurpleStatusType *type = NULL;
+
+ if(!PURPLE_IS_PRESENCE(presence)) {
+ return fallback;
+ }
+
+ status = purple_presence_get_active_status(presence);
+ if(!PURPLE_IS_STATUS(status)) {
+ return fallback;
+ }
+
+ type = purple_status_get_status_type(status);
+ if(type == NULL) {
+ return fallback;
+ }
+
+ switch(purple_status_type_get_primitive(type)) {
+ case PURPLE_STATUS_OFFLINE:
+ return "pidgin-user-offline";
+ break;
+ case PURPLE_STATUS_AVAILABLE:
+ return "pidgin-user-available";
+ break;
+ case PURPLE_STATUS_UNAVAILABLE:
+ return "pidgin-user-unavailable";
+ break;
+ case PURPLE_STATUS_AWAY:
+ return "pidgin-user-away";
+ break;
+ case PURPLE_STATUS_INVISIBLE:
+ return "pidgin-user-invisible";
+ break;
+ case PURPLE_STATUS_EXTENDED_AWAY:
+ return "pidgin-user-extended-away";
+ break;
+ case PURPLE_STATUS_MOBILE:
+ case PURPLE_STATUS_TUNE:
+ case PURPLE_STATUS_MOOD:
+ case PURPLE_STATUS_UNSET:
+ default:
+ break;
+ }
+
+ return fallback;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginpresence.h Thu Dec 17 23:50:15 2020 -0600
@@ -0,0 +1,59 @@
+/*
+ * Pidgin - Internet Messenger
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * Pidgin 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, see <https://www.gnu.org/licenses/>.
+ */
+
+#if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION)
+# error "only <pidgin.h> may be included directly"
+#endif
+
+#ifndef PIDGIN_PRESENCE_H
+#define PIDGIN_PRESENCE_H
+
+/**
+ * SECTION:pidginpresence
+ * @section_id: pidgin-presence
+ * @short_description: Presence Utilities
+ * @title: Presence Utility Functions
+ *
+ * Displaying #PurplePresence's can be tricky. These functions make it easier.
+ */
+
+#include <gtk/gtk.h>
+
+#include <purple.h>
+
+G_BEGIN_DECLS
+
+/**
+ * pidgin_presence_get_icon_name:
+ * @presence: The #PurplePresence instance.
+ * @fallback: The icon name to fall back to.
+ *
+ * Gets the icon name that should be used to represent @presence falling back
+ * to @fallback if @presence is invalid.
+ *
+ * Returns: The icon name to represent @presence.
+ */
+const gchar *pidgin_presence_get_icon_name(PurplePresence *presence, const gchar *fallback);
+
+G_END_DECLS
+
+#endif /* PIDGIN_PRESENCE_H */
--- a/pidgin/pidginpresenceicon.c Thu Dec 17 23:48:47 2020 -0600
+++ b/pidgin/pidginpresenceicon.c Thu Dec 17 23:50:15 2020 -0600
@@ -22,6 +22,8 @@
#include "pidgin/pidginpresenceicon.h"
+#include "pidgin/pidginpresence.h"
+
struct _PidginPresenceIcon {
GtkImage parent;
@@ -46,49 +48,9 @@
*****************************************************************************/
static void
pidgin_presence_icon_update(PidginPresenceIcon *icon) {
- const gchar *icon_name = icon->fallback;
-
- /* Sorry for the pyramid of doom, couldn't come up with a better way to do
- * this...
- */
- if(PURPLE_IS_PRESENCE(icon->presence)) {
- PurpleStatus *status = NULL;
-
- status = purple_presence_get_active_status(icon->presence);
- if(PURPLE_IS_STATUS(status)) {
- PurpleStatusType *type = purple_status_get_status_type(status);
+ const gchar *icon_name = NULL;
- if(type != NULL) {
- switch(purple_status_type_get_primitive(type)) {
- case PURPLE_STATUS_OFFLINE:
- icon_name = "pidgin-user-offline";
- break;
- case PURPLE_STATUS_AVAILABLE:
- icon_name = "pidgin-user-available";
- break;
- case PURPLE_STATUS_UNAVAILABLE:
- icon_name = "pidgin-user-unavailable";
- break;
- case PURPLE_STATUS_AWAY:
- icon_name = "pidgin-user-away";
- break;
- case PURPLE_STATUS_INVISIBLE:
- icon_name = "pidgin-user-invisible";
- break;
- case PURPLE_STATUS_EXTENDED_AWAY:
- icon_name = "pidgin-user-extended-away";
- break;
- case PURPLE_STATUS_MOBILE:
- case PURPLE_STATUS_TUNE:
- case PURPLE_STATUS_MOOD:
- case PURPLE_STATUS_UNSET:
- default:
- /* Use the fallback which was set above. */
- break;
- }
- }
- }
- }
+ icon_name = pidgin_presence_get_icon_name(icon->presence, icon->fallback);
gtk_image_set_from_icon_name(GTK_IMAGE(icon), icon_name, icon->icon_size);
}
--- a/po/POTFILES.in Thu Dec 17 23:48:47 2020 -0600
+++ b/po/POTFILES.in Thu Dec 17 23:50:15 2020 -0600
@@ -351,6 +351,7 @@
pidgin/pidginlog.c
pidgin/pidginmenutray.c
pidgin/pidginmessage.c
+pidgin/pidginpresence.c
pidgin/pidginpresenceicon.c
pidgin/pidginstock.c
pidgin/pidginstyle.c