--- a/finch/finchui.c Thu Oct 26 22:22:34 2023 -0500
+++ b/finch/finchui.c Thu Oct 26 22:24:08 2023 -0500
@@ -51,40 +51,6 @@
G_DEFINE_TYPE(FinchUi, finch_ui, PURPLE_TYPE_UI)
/******************************************************************************
- *****************************************************************************/
-finch_history_init(GError **error) {
- PurpleHistoryManager *manager = NULL;
- PurpleHistoryAdapter *adapter = NULL;
- gchar *filename = NULL;
- const gchar *id = NULL;
- manager = purple_history_manager_get_default();
- /* Attempt to create the config directory. */
- g_mkdir_with_parents(purple_config_dir(), 0700);
- filename = g_build_filename(purple_config_dir(), "history.db", NULL);
- adapter = purple_sqlite_history_adapter_new(filename);
- id = purple_history_adapter_get_id(adapter);
- if(!purple_history_manager_register(manager, adapter, error)) {
- g_clear_object(&adapter);
- /* The manager adds a ref to the adapter on registration, so we can remove
- g_clear_object(&adapter);
- return purple_history_manager_set_active(manager, id, error);
-/******************************************************************************
* PurpleUi Implementation
*****************************************************************************/
@@ -93,7 +59,7 @@
-finch_ui_start(G_GNUC_UNUSED PurpleUi *ui, GError **error) {
+finch_ui_start(G_GNUC_UNUSED PurpleUi *ui, G_GNUC_UNUSED GError **error) { @@ -104,18 +70,6 @@
- if(!finch_history_init(error)) {
- const char *error_message = "unknown";
- if(error != NULL && *error != NULL) {
- error_message = (*error)->message;
- g_critical("failed to initialize the history api: %s", error_message);
purple_prefs_add_none("/purple/gnt");
@@ -217,6 +171,20 @@
+static PurpleHistoryAdapter * +finch_ui_get_history_adapter(G_GNUC_UNUSED PurpleUi *ui) { + PurpleHistoryAdapter *adapter = NULL; + g_mkdir_with_parents(purple_config_dir(), 0700); + filename = g_build_filename(purple_config_dir(), "history.db", NULL); + adapter = purple_sqlite_history_adapter_new(filename); /******************************************************************************
*****************************************************************************/
@@ -232,6 +200,7 @@
ui_class->start = finch_ui_start;
ui_class->stop = finch_ui_stop;
ui_class->get_settings_backend = finch_ui_get_settings_backend;
+ ui_class->get_history_adapter = finch_ui_get_history_adapter; /******************************************************************************
--- a/libpurple/core.c Thu Oct 26 22:22:34 2023 -0500
+++ b/libpurple/core.c Thu Oct 26 22:24:08 2023 -0500
@@ -93,8 +93,9 @@
-purple_core_init(PurpleUi *ui, G_GNUC_UNUSED GError **error) {
+purple_core_init(PurpleUi *ui, GError **error) { + PurpleCore *core = NULL; + PurpleHistoryAdapter *adapter = NULL; const char *force_error_message = NULL;
g_return_val_if_fail(PURPLE_IS_UI(ui), FALSE);
@@ -168,7 +169,13 @@
purple_conversation_manager_startup();
purple_whiteboard_manager_startup();
- purple_history_manager_startup();
+ /* Setup the history adapter. */ + adapter = purple_ui_get_history_adapter(ui); + if(!purple_history_manager_startup(adapter, error)) { --- a/libpurple/purplehistorymanager.c Thu Oct 26 22:22:34 2023 -0500
+++ b/libpurple/purplehistorymanager.c Thu Oct 26 22:24:08 2023 -0500
@@ -138,38 +138,6 @@
/******************************************************************************
- *****************************************************************************/
-purple_history_manager_startup(void) {
- if(default_manager == NULL) {
- default_manager = g_object_new(PURPLE_TYPE_HISTORY_MANAGER, NULL);
-purple_history_manager_shutdown(void) {
- if(default_manager == NULL) {
- if(PURPLE_IS_HISTORY_ADAPTER(default_manager->active_adapter)) {
- PurpleHistoryAdapter *adapter = NULL;
- adapter = g_object_ref(default_manager->active_adapter);
- purple_history_manager_set_active(default_manager, NULL, NULL);
- purple_history_manager_unregister(default_manager,
- g_clear_object(&adapter);
- g_clear_object(&default_manager);
-/******************************************************************************
*****************************************************************************/
@@ -397,3 +365,57 @@
func(PURPLE_HISTORY_ADAPTER(value), data);
+purple_history_manager_startup(PurpleHistoryAdapter *adapter, GError **error) { + if(default_manager == NULL) { + default_manager = g_object_new(PURPLE_TYPE_HISTORY_MANAGER, NULL); + g_object_add_weak_pointer(G_OBJECT(default_manager), + (gpointer)&default_manager); + if(!PURPLE_IS_HISTORY_ADAPTER(adapter)) { + adapter = purple_sqlite_history_adapter_new(":memory:"); + if(!purple_history_manager_register(default_manager, adapter, error)) { + g_clear_object(&adapter); + id = purple_history_adapter_get_id(adapter); + if(!purple_history_manager_set_active(default_manager, id, error)) { + g_clear_object(&adapter); + g_clear_object(&adapter); +purple_history_manager_shutdown(void) { + if(default_manager == NULL) { + if(PURPLE_IS_HISTORY_ADAPTER(default_manager->active_adapter)) { + PurpleHistoryAdapter *adapter = NULL; + adapter = g_object_ref(default_manager->active_adapter); + purple_history_manager_set_active(default_manager, NULL, NULL); + purple_history_manager_unregister(default_manager, + g_clear_object(&adapter); + g_clear_object(&default_manager); --- a/libpurple/purplehistorymanager.h Thu Oct 26 22:22:34 2023 -0500
+++ b/libpurple/purplehistorymanager.h Thu Oct 26 22:24:08 2023 -0500
@@ -72,13 +72,19 @@
* purple_history_manager_startup:
+ * @adapter: (transfer full) (nullable): The history adapter to use by default. + * @error: A return address for a #GError. - * Starts up the history manager by creating the default instance.
+ * Starts up the history manager by creating the default instance and setting + * @adapter as active if @adapter is non %NULL. + * Returns: %TRUE if startup was successful, otherwise %FALSE with @error -void purple_history_manager_startup(void);
+gboolean purple_history_manager_startup(PurpleHistoryAdapter *adapter, GError **error); * purple_history_manager_shutdown:
--- a/libpurple/purpleui.c Thu Oct 26 22:22:34 2023 -0500
+++ b/libpurple/purpleui.c Thu Oct 26 22:24:08 2023 -0500
@@ -425,3 +425,17 @@
+purple_ui_get_history_adapter(PurpleUi *ui) { + PurpleUiClass *klass = NULL; + g_return_val_if_fail(PURPLE_IS_UI(ui), NULL); + klass = PURPLE_UI_GET_CLASS(ui); + if(klass != NULL && klass->get_history_adapter != NULL) { + return klass->get_history_adapter(ui); --- a/libpurple/purpleui.h Thu Oct 26 22:22:34 2023 -0500
+++ b/libpurple/purpleui.h Thu Oct 26 22:24:08 2023 -0500
@@ -26,6 +26,7 @@
+#include "purplehistoryadapter.h" #include "purpleversion.h"
@@ -71,6 +72,7 @@
void (*stop)(PurpleUi *ui);
gpointer (*get_settings_backend)(PurpleUi *ui);
+ PurpleHistoryAdapter *(*get_history_adapter)(PurpleUi *ui); @@ -215,6 +217,22 @@
gpointer purple_ui_get_settings_backend(PurpleUi *ui);
+ * purple_ui_get_history_adapter: + * Gets the history adapter that the user interface wants to use. + * > Note: This should typically only be called by libpurple. If this returns + * %NULL, then libpurple will use an in-memory history adapter instead. + * Returns: (transfer full) (nullable): The [class@HistoryAdapter] to use or +PurpleHistoryAdapter *purple_ui_get_history_adapter(PurpleUi *ui); --- a/libpurple/tests/test_ui.c Thu Oct 26 22:22:34 2023 -0500
+++ b/libpurple/tests/test_ui.c Thu Oct 26 22:24:08 2023 -0500
@@ -107,31 +107,6 @@
-test_ui_init_history(GError **error) {
- PurpleHistoryManager *manager = NULL;
- PurpleHistoryAdapter *adapter = NULL;
- const gchar *id = NULL;
- manager = purple_history_manager_get_default();
- adapter = purple_sqlite_history_adapter_new(":memory:");
- id = purple_history_adapter_get_id(adapter);
- if(!purple_history_manager_register(manager, adapter, error)) {
- g_clear_object(&adapter);
- /* The manager adds a ref to the adapter on registration, so we can remove
- g_clear_object(&adapter);
- return purple_history_manager_set_active(manager, id, error);
test_ui_purple_init(void) {
@@ -158,12 +133,6 @@
/* Make sure our configuration directory exists. */
g_mkdir_with_parents(purple_config_dir(), 0755);
- if(!test_ui_init_history(&error)) {
- g_critical("failed to initialize the history api: %s",
- error ? error->message : "unknown");
/* Load the preferences. */
--- a/pidgin/pidginui.c Thu Oct 26 22:22:34 2023 -0500
+++ b/pidgin/pidginui.c Thu Oct 26 22:24:08 2023 -0500
@@ -53,40 +53,6 @@
/******************************************************************************
*****************************************************************************/
-pidgin_history_init(GError **error) {
- PurpleHistoryManager *manager = NULL;
- PurpleHistoryAdapter *adapter = NULL;
- gchar *filename = NULL;
- const gchar *id = NULL;
- manager = purple_history_manager_get_default();
- /* Attempt to create the config_dir. We don't care about the result as the
- * logging adapter will fail with a better error than us failing to create
- g_mkdir_with_parents(purple_config_dir(), 0700);
- filename = g_build_filename(purple_config_dir(), "history.db", NULL);
- adapter = purple_sqlite_history_adapter_new(filename);
- id = purple_history_adapter_get_id(adapter);
- if(!purple_history_manager_register(manager, adapter, error)) {
- g_clear_object(&adapter);
- /* The manager adds a ref to the adapter on registration, so we can remove
- g_clear_object(&adapter);
- return purple_history_manager_set_active(manager, id, error);
pidgin_ui_add_protocol_theme_paths(PurpleProtocol *protocol) {
GdkDisplay *display = NULL;
@@ -134,7 +100,7 @@
-pidgin_ui_start(G_GNUC_UNUSED PurpleUi *ui, GError **error) {
+pidgin_ui_start(G_GNUC_UNUSED PurpleUi *ui, G_GNUC_UNUSED GError **error) { PurpleProtocolManager *protocol_manager = NULL;
GdkDisplay *display = NULL;
GtkIconTheme *theme = NULL;
@@ -162,18 +128,6 @@
purple_protocol_manager_foreach(protocol_manager,
pidgin_ui_protocol_foreach_theme_cb, NULL);
- if(!pidgin_history_init(error)) {
- const char *error_message = "unknown";
- if(error != NULL && *error != NULL) {
- error_message = (*error)->message;
- g_critical("failed to initialize the history api: %s", error_message);
/* Set the UI operation structures. */
purple_xfers_set_ui_ops(pidgin_xfers_get_ui_ops());
purple_blist_set_ui(PIDGIN_TYPE_BUDDY_LIST);
@@ -223,6 +177,20 @@
+static PurpleHistoryAdapter * +pidgin_ui_get_history_adapter(G_GNUC_UNUSED PurpleUi *ui) { + PurpleHistoryAdapter *adapter = NULL; + g_mkdir_with_parents(purple_config_dir(), 0700); + filename = g_build_filename(purple_config_dir(), "history.db", NULL); + adapter = purple_sqlite_history_adapter_new(filename); /******************************************************************************
*****************************************************************************/
@@ -238,6 +206,7 @@
ui_class->start = pidgin_ui_start;
ui_class->stop = pidgin_ui_stop;
ui_class->get_settings_backend = pidgin_ui_get_settings_backend;
+ ui_class->get_history_adapter = pidgin_ui_get_history_adapter; /******************************************************************************
--- a/purple-history/purplehistorycore.c Thu Oct 26 22:22:34 2023 -0500
+++ b/purple-history/purplehistorycore.c Thu Oct 26 22:24:08 2023 -0500
@@ -103,7 +103,7 @@
- purple_history_manager_startup();
+ purple_history_manager_startup(NULL, NULL); for(gint i = 1; i < argc; i++) {
if(argv[i] == NULL || *argv[i] == '\0') {