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 @@
'pidginprotocolchooser.c',
@@ -128,6 +129,7 @@
'pidginprotocolchooser.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 + * 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" +/****************************************************************************** + *****************************************************************************/ +pidgin_presence_get_icon_name(PurplePresence *presence, const gchar *fallback) { + PurpleStatus *status = NULL; + PurpleStatusType *type = NULL; + if(!PURPLE_IS_PRESENCE(presence)) { + status = purple_presence_get_active_status(presence); + if(!PURPLE_IS_STATUS(status)) { + type = purple_status_get_status_type(status); + switch(purple_status_type_get_primitive(type)) { + case PURPLE_STATUS_OFFLINE: + return "pidgin-user-offline"; + case PURPLE_STATUS_AVAILABLE: + return "pidgin-user-available"; + case PURPLE_STATUS_UNAVAILABLE: + return "pidgin-user-unavailable"; + case PURPLE_STATUS_AWAY: + return "pidgin-user-away"; + case PURPLE_STATUS_INVISIBLE: + return "pidgin-user-invisible"; + case PURPLE_STATUS_EXTENDED_AWAY: + return "pidgin-user-extended-away"; + case PURPLE_STATUS_MOBILE: + case PURPLE_STATUS_TUNE: + case PURPLE_STATUS_MOOD: + case PURPLE_STATUS_UNSET: --- /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 + * 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" +#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. + * 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); +#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 {
@@ -46,49 +48,9 @@
*****************************************************************************/
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
- 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;
- switch(purple_status_type_get_primitive(type)) {
- case PURPLE_STATUS_OFFLINE:
- icon_name = "pidgin-user-offline";
- case PURPLE_STATUS_AVAILABLE:
- icon_name = "pidgin-user-available";
- case PURPLE_STATUS_UNAVAILABLE:
- icon_name = "pidgin-user-unavailable";
- case PURPLE_STATUS_AWAY:
- icon_name = "pidgin-user-away";
- case PURPLE_STATUS_INVISIBLE:
- icon_name = "pidgin-user-invisible";
- case PURPLE_STATUS_EXTENDED_AWAY:
- icon_name = "pidgin-user-extended-away";
- case PURPLE_STATUS_MOBILE:
- case PURPLE_STATUS_TUNE:
- case PURPLE_STATUS_MOOD:
- case PURPLE_STATUS_UNSET:
- /* Use the fallback which was set above. */
+ 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/pidginpresenceicon.c