summaryrefslogtreecommitdiff
path: root/pidgin/libpidgin.c
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2021-10-18 02:01:37 -0500
committerGary Kramlich <grim@reaperworld.com>2021-10-18 02:01:37 -0500
commit25855c9d62f63c81be44849a5f282184d8bd56c1 (patch)
treef3c83dc898dc8fd37b4b61e2fcbc60457a37ea18 /pidgin/libpidgin.c
parent55fd0754377b9ef459e35da750eed571fdb2a081 (diff)
downloadpidgin-25855c9d62f63c81be44849a5f282184d8bd56c1.tar.gz
Make user interfaces setup the default history adapter.
This helps avoid some issues with the unit tests as well as gives us more flexibility in the future. Testing Done: Ran the unit tests without issue. Ran Pidgin 3 with no existing config directory and verified that `history.db` was created properly. Reviewed at https://reviews.imfreedom.org/r/1033/
Diffstat (limited to 'pidgin/libpidgin.c')
-rw-r--r--pidgin/libpidgin.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/pidgin/libpidgin.c b/pidgin/libpidgin.c
index 5c775ef915..99114b17a1 100644
--- a/pidgin/libpidgin.c
+++ b/pidgin/libpidgin.c
@@ -190,11 +190,46 @@ debug_init(void)
purple_debug_set_ui(PURPLE_DEBUG_UI(ui));
}
+static gboolean
+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
+ * the 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);
+ g_free(filename);
+
+ id = purple_history_adapter_get_id(adapter);
+ if(!purple_history_manager_register(manager, adapter, error)) {
+ g_clear_object(&adapter);
+
+ return FALSE;
+ }
+
+ /* The manager adds a ref to the adapter on registration, so we can remove
+ * our reference.
+ */
+ g_clear_object(&adapter);
+
+ return purple_history_manager_set_active(manager, id, error);
+}
+
static void
pidgin_ui_init(void)
{
PurpleProtocolManager *protocol_manager = NULL;
GtkIconTheme *theme = NULL;
+ GError *error = NULL;
gchar *path;
theme = gtk_icon_theme_get_default();
@@ -216,6 +251,12 @@ pidgin_ui_init(void)
purple_protocol_manager_foreach(protocol_manager,
purple_ui_protocol_foreach_theme_cb, NULL);
+ if(!pidgin_history_init(&error)) {
+ g_critical("failed to initialize the history api: %s",
+ error != NULL ? error->message : "unknown");
+ g_clear_error(&error);
+ }
+
pidgin_stock_init();
/* Set the UI operation structures. */