Thu, 11 Apr 2024 22:37:41 -0500
Remove the PurpleImageStore API as it's no longer used
This will eventually be replaced by something like PurpleFileCache but we
haven't had a need for it yet.
Testing Done:
Michelangelo is a party dude!
Reviewed at https://reviews.imfreedom.org/r/3093/
| libpurple/core.c | file | annotate | diff | comparison | revisions | |
| libpurple/image-store.c | file | annotate | diff | comparison | revisions | |
| libpurple/image-store.h | file | annotate | diff | comparison | revisions | |
| libpurple/meson.build | file | annotate | diff | comparison | revisions | |
| po/POTFILES.in | file | annotate | diff | comparison | revisions |
--- a/libpurple/core.c Thu Apr 11 21:39:52 2024 -0500 +++ b/libpurple/core.c Thu Apr 11 22:37:41 2024 -0500 @@ -32,7 +32,6 @@ #include "core.h" #include "debug.h" #include "idle.h" -#include "image-store.h" #include "network.h" #include "notify.h" #include "plugins.h" @@ -151,9 +150,6 @@ */ purple_plugins_init(); - /* The buddy icon code uses the image store, so init it early. */ - _purple_image_store_init(); - /* Accounts use status, buddy icons and connection signals, so * initialize these before accounts */ @@ -252,7 +248,6 @@ purple_statuses_uninit(); purple_accounts_uninit(); purple_proxy_uninit(); - _purple_image_store_uninit(); purple_network_uninit(); purple_ui_stop(core->ui);
--- a/libpurple/image-store.c Thu Apr 11 21:39:52 2024 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,228 +0,0 @@ -/* - * Purple - Internet Messaging Library - * Copyright (C) Pidgin Developers <devel@pidgin.im> - * - * 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 library 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 library 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 library; if not, see <https://www.gnu.org/licenses/>. - */ - -#include "image-store.h" - -#include "util.h" - -#define TEMP_IMAGE_TIMEOUT 5 - -static GHashTable *id_to_image = NULL; -static guint last_id = 0; - -/* keys: timeout handle */ -static GHashTable *temp_images = NULL; - -/* keys: img id */ -static GSList *perm_images = NULL; - -static void -image_reset_id(gpointer _id) -{ - g_return_if_fail(id_to_image != NULL); - - g_hash_table_remove(id_to_image, _id); -} - -static guint -image_set_id(PurpleImage *image) -{ - /* Use the next unused id number. We do it in a loop on the off chance - * that next id wraps back around to 0 and the hash table still contains - * entries from the first time around. - */ - while (TRUE) { - last_id++; - - if (G_UNLIKELY(last_id == 0)) - continue; - - if (purple_image_store_get(last_id) == NULL) - break; - } - - g_object_set_data_full(G_OBJECT(image), "purple-image-store-id", - GINT_TO_POINTER(last_id), image_reset_id); - g_hash_table_insert(id_to_image, GINT_TO_POINTER(last_id), image); - return last_id; -} - -static guint -image_get_id(PurpleImage *image) -{ - return GPOINTER_TO_INT(g_object_get_data(G_OBJECT(image), - "purple-image-store-id")); -} - -guint -purple_image_store_add(PurpleImage *image) -{ - guint id; - - g_return_val_if_fail(PURPLE_IS_IMAGE(image), 0); - - id = image_get_id(image); - if (id > 0) - return id; - - id = image_set_id(image); - - g_object_ref(image); - perm_images = g_slist_prepend(perm_images, image); - - return id; -} - -guint -purple_image_store_add_weak(PurpleImage *image) -{ - guint id; - - g_return_val_if_fail(PURPLE_IS_IMAGE(image), 0); - - id = image_get_id(image); - if (id > 0) - return id; - - return image_set_id(image); -} - -static gboolean -remove_temporary(gpointer _image) -{ - PurpleImage *image = _image; - guint handle; - - handle = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(image), - "purple-image-store-handle")); - - g_hash_table_remove(temp_images, GINT_TO_POINTER(handle)); - - return G_SOURCE_REMOVE; -} - -static void -cancel_temporary(gpointer key, G_GNUC_UNUSED gpointer value, - G_GNUC_UNUSED gpointer data) -{ - g_source_remove(GPOINTER_TO_INT(key)); -} - -guint -purple_image_store_add_temporary(PurpleImage *image) -{ - guint id; - guint handle; - - g_return_val_if_fail(PURPLE_IS_IMAGE(image), 0); - - id = image_get_id(image); - /* XXX: add_temporary doesn't extend previous temporary call, sorry */ - if (id > 0) - return id; - - id = image_set_id(image); - - g_object_ref(image); - handle = g_timeout_add_seconds(TEMP_IMAGE_TIMEOUT, - remove_temporary, image); - g_object_set_data(G_OBJECT(image), "purple-image-store-handle", - GINT_TO_POINTER(handle)); - g_hash_table_insert(temp_images, GINT_TO_POINTER(handle), image); - - return id; -} - -PurpleImage * -purple_image_store_get(guint id) -{ - return g_hash_table_lookup(id_to_image, GINT_TO_POINTER(id)); -} - -PurpleImage * -purple_image_store_get_from_uri(const gchar *uri) -{ - guint64 longid; - guint id; - gchar *endptr; - gchar endchar; - - g_return_val_if_fail(uri != NULL, NULL); - - if (!g_str_has_prefix(uri, PURPLE_IMAGE_STORE_PROTOCOL)) { - return NULL; - } - - uri += sizeof(PURPLE_IMAGE_STORE_PROTOCOL) - 1; - if (uri[0] == '-') - return NULL; - - longid = g_ascii_strtoull(uri, &endptr, 10); - endchar = endptr[0]; - if (endchar != '\0' && endchar != '"' && - endchar != '\'' && endchar != ' ') - { - return NULL; - } - - id = longid; - if (id != longid) - return NULL; - - return purple_image_store_get(id); -} - -gchar * -purple_image_store_get_uri(PurpleImage *image) -{ - const gchar *path; - guint img_id; - - g_return_val_if_fail(PURPLE_IS_IMAGE(image), NULL); - - path = purple_image_get_path(image); - - if (path) - return g_filename_to_uri(path, NULL, NULL); - - img_id = purple_image_store_add_weak(image); - return g_strdup_printf(PURPLE_IMAGE_STORE_PROTOCOL "%u", img_id); -} - -void -_purple_image_store_init(void) -{ - id_to_image = g_hash_table_new(g_direct_hash, g_direct_equal); - temp_images = g_hash_table_new_full(g_direct_hash, g_direct_equal, - NULL, g_object_unref); -} - -void -_purple_image_store_uninit(void) -{ - g_clear_slist(&perm_images, g_object_unref); - - g_hash_table_foreach(temp_images, cancel_temporary, NULL); - g_clear_pointer(&temp_images, g_hash_table_destroy); - - g_clear_pointer(&id_to_image, g_hash_table_destroy); -}
--- a/libpurple/image-store.h Thu Apr 11 21:39:52 2024 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,185 +0,0 @@ -/* - * Purple - Internet Messaging Library - * Copyright (C) Pidgin Developers <devel@pidgin.im> - * - * 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 library 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 library 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 library; if not, see <https://www.gnu.org/licenses/>. - */ - -#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION) -# error "only <purple.h> may be included directly" -#endif - -#ifndef PURPLE_IMAGE_STORE_H -#define PURPLE_IMAGE_STORE_H - -/** - * PurpleImageStore: - * - * Image store references #PurpleImage's by a simple integer value. - * It's a convenient way to embed images in HTML-like strings. - * - * Integer ID's are tracked for being valid - when a image is destroyed, it's - * also removed from the store. If the application runs for a very long time and - * all possible id numbers from integer range are utilized, it will use - * previously released numbers. - */ - -#include "image.h" -#include "purpleversion.h" - -/** - * PURPLE_IMAGE_STORE_PROTOCOL: - * - * A global URI prefix for images stored in this subsystem. - */ -#define PURPLE_IMAGE_STORE_PROTOCOL "purple-image:" - -G_BEGIN_DECLS - -/** - * purple_image_store_add: - * @image: the image. - * - * Permanently adds an image to the store. If the @image is already in the - * store, it will return its current id. - * - * This function increases @image's reference count, so it won't be destroyed - * until image store subsystem is shut down. Don't decrease @image's reference - * count by yourself - if you don't want the store to hold the reference, - * use #purple_image_store_add_weak. - * - * Returns: the unique identifier for the @image. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -guint -purple_image_store_add(PurpleImage *image); - -/** - * purple_image_store_add_weak: - * @image: the image. - * - * Adds an image to the store without increasing reference count. It will be - * removed from the store when @image gets destroyed. - * - * If the @image is already in the store, it will return its current id. - * - * Returns: the unique identifier for the @image. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -guint -purple_image_store_add_weak(PurpleImage *image); - -/** - * purple_image_store_add_temporary: - * @image: the image. - * - * Adds an image to the store to be used in a short period of time. - * If the @image is already in the store, it will just return its current id. - * - * Increases reference count for the @image for a time long enough to display - * the @image by the UI. In current implementation it's five seconds, but may be - * changed in the future, so if you need more sophisticated reference - * management, implement it on your own. - * - * Returns: the unique identifier for the @image. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -guint -purple_image_store_add_temporary(PurpleImage *image); - -/** - * purple_image_store_get: - * @id: the unique identifier of an image. - * - * Finds the image with a certain identifier within a store. - * - * Returns: (transfer none): the image referenced by @id, or %NULL if it - * doesn't exists. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -PurpleImage * -purple_image_store_get(guint id); - -/** - * purple_image_store_get_from_uri: - * @uri: the URI of a potential #PurpleImage. Should not be %NULL. - * - * Checks, if the @uri is pointing to any #PurpleImage by referring - * to #PURPLE_IMAGE_STORE_PROTOCOL and returns the image, if it's valid. - * - * The function doesn't throw any warning, if the @uri is for any - * other protocol. - * - * Returns: (transfer none): the image referenced by @uri, or %NULL if it - * doesn't point to any valid image. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -PurpleImage * -purple_image_store_get_from_uri(const gchar *uri); - -/** - * purple_image_store_get_uri: - * @image: the image. - * - * Generates an URI for the @image, to be retrieved using - * #purple_image_store_get_from_uri. - * - * Returns: (transfer full): the URI for the @image. Should be #g_free'd when - * you done using it. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -gchar * -purple_image_store_get_uri(PurpleImage *image); - -/** - * _purple_image_store_init: (skip) - * - * Initializes the image store subsystem. - * - * Since: 3.0 - */ -G_GNUC_INTERNAL -void -_purple_image_store_init(void); - -/** - * _purple_image_store_uninit: (skip) - * - * Uninitializes the image store subsystem. - * - * Since: 3.0 - */ -G_GNUC_INTERNAL -void -_purple_image_store_uninit(void); - -G_END_DECLS - -#endif /* PURPLE_IMAGE_STORE_H */
--- a/libpurple/meson.build Thu Apr 11 21:39:52 2024 -0500 +++ b/libpurple/meson.build Thu Apr 11 22:37:41 2024 -0500 @@ -17,7 +17,6 @@ 'group.c', 'idle.c', 'image.c', - 'image-store.c', 'media/backend-iface.c', 'media/candidate.c', 'media/codec.c', @@ -144,7 +143,6 @@ 'group.h', 'idle.h', 'image.h', - 'image-store.h', 'media.h', 'media-gst.h', 'mediamanager.h',