rewtguy/pidgin

Collapsed revision
draft history-api tip
2021-10-08, Gary Kramlich
00e6f98b4243
Collapsed revision
* Bootstrap the PurpleHistoryAdapter class
* HistoryApi - added name property and added write, query, remove methods
* Fix minor issues in purplehistoryadapter.
* Add unit tests for purple_history_adapter. Initial scaffolding for purple_history_manager.
* Add history manager. Start of adding unit tests for history manager. Slight modification of formatting of test_histroy_adapter. Add classes to POTFILES.in.
* Updates to history manager and unit tests
* Add test_purple_history_manager.c
* Fixed history manager and unit tests. Should be in a better state now.
* Fixed missing curly brace in history manager.
* Made changes to purplehistorymanager.h documentation.
* Add a dependency on sqlite3. 3.27.0 is kind of an arbitrary version we can adjust if necessary.
* Update _purple_conversation_write_common to use the history api.
* Initial implementation of purplesqlitehistoryadapter
* Add in activate and deactivate for purplesqlitehistoryadapter
* Embed our sqlite history schema into libpurple and run it during startup
* Implement shutdown in purplehistorymanager, implement write in purplesqlitehistoryadapter, modify schema for history adapter.
* Finish purplesqlitehistoryadapter write functionality. Changed api to include PurpleConversation.
* History API - flushed out sqlite query builder, query, and remove.
* Create a stub purple-history command line tool
* Add a simple cli for the history api and fix a few bugs
* Fixed signatures for query and remove
* Fixed memory leaks in sqlite history adapter
* Add remove function in purplehistorycore and update unit test for history adapter
* Fixed purple history core not printing results from query
* Addressed PR comments
* Add additional docs, fixed error messages, finished implementing query in purple history.
* Addressed PR comments. Fixed style, some objects weren't being dereferenced but now are, fixed issues in documentation.
* Fixed docs, grouped sqlite3 dependency check with libpurple, enabled g_option set help for history core.
* Fixed style issues. Fixed unfreed references. Add in checks against empty strings for sqlite adapter. Fixed documentation.
* Address PR comments. Fixed incorrect parameters in activate signal. Fix some styling problems. Removed unnecessary frees. Fixed compiler warnings.
* Address additional PR comments for history adapter.
* Address review findings
* Fix up the unit tests
/*
* finch
*
* Finch 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include <glib/gi18n-lib.h>
#include <purple.h>
#include "gntaccount.h"
#include "gntconn.h"
#include "libfinch.h"
#define INITIAL_RECON_DELAY_MIN 8
#define INITIAL_RECON_DELAY_MAX 60
#define MAX_RECON_DELAY 600
typedef struct {
int delay;
guint timeout;
} FinchAutoRecon;
/*
* Contains accounts that are auto-reconnecting.
* The key is a pointer to the PurpleAccount and the
* value is a pointer to a FinchAutoRecon.
*/
static GHashTable *hash = NULL;
static void
free_auto_recon(gpointer data)
{
FinchAutoRecon *info = data;
if (info->timeout != 0)
g_source_remove(info->timeout);
g_free(info);
}
static gboolean
do_signon(gpointer data)
{
PurpleAccount *account = data;
FinchAutoRecon *info;
PurpleStatus *status;
purple_debug_info("autorecon", "do_signon called\n");
g_return_val_if_fail(account != NULL, FALSE);
info = g_hash_table_lookup(hash, account);
if (info)
info->timeout = 0;
status = purple_account_get_active_status(account);
if (purple_status_is_online(status))
{
purple_debug_info("autorecon", "calling purple_account_connect\n");
purple_account_connect(account);
purple_debug_info("autorecon", "done calling purple_account_connect\n");
}
return FALSE;
}
static void
ce_modify_account_cb(PurpleAccount *account)
{
finch_account_dialog_show(account);
}
static void
ce_enable_account_cb(PurpleAccount *account)
{
purple_account_set_enabled(account, FINCH_UI, TRUE);
}
static void
finch_connection_report_disconnect(PurpleConnection *gc, PurpleConnectionError reason,
const char *text)
{
FinchAutoRecon *info;
PurpleAccount *account = purple_connection_get_account(gc);
if (!purple_connection_error_is_fatal(reason)) {
info = g_hash_table_lookup(hash, account);
if (info == NULL) {
info = g_new0(FinchAutoRecon, 1);
g_hash_table_insert(hash, account, info);
info->delay = g_random_int_range(INITIAL_RECON_DELAY_MIN, INITIAL_RECON_DELAY_MAX);
} else {
info->delay = MIN(2 * info->delay, MAX_RECON_DELAY);
if (info->timeout != 0)
g_source_remove(info->timeout);
}
info->timeout = g_timeout_add_seconds(info->delay, do_signon, account);
} else {
char *act, *primary, *secondary;
act = g_strdup_printf(_("%s (%s)"), purple_account_get_username(account),
purple_account_get_protocol_name(account));
primary = g_strdup_printf(_("%s disconnected."), act);
secondary = g_strdup_printf(_("%s\n\n"
"Finch will not attempt to reconnect the account until you "
"correct the error and re-enable the account."), text);
purple_request_action(account, NULL, primary, secondary, 2,
purple_request_cpar_from_account(account), account, 3,
_("OK"), NULL,
_("Modify Account"), PURPLE_CALLBACK(ce_modify_account_cb),
_("Re-enable Account"), PURPLE_CALLBACK(ce_enable_account_cb));
g_free(act);
g_free(primary);
g_free(secondary);
purple_account_set_enabled(account, FINCH_UI, FALSE);
}
}
static void
account_removed_cb(PurpleAccount *account, gpointer user_data)
{
g_hash_table_remove(hash, account);
}
static void *
finch_connection_get_handle(void)
{
static int handle;
return &handle;
}
static PurpleConnectionUiOps ops =
{
NULL, /* connect_progress */
NULL, /* connected */
NULL, /* disconnected */
NULL, /* notice */
NULL, /* network_connected */
NULL, /* network_disconnected */
finch_connection_report_disconnect,
NULL,
NULL,
NULL,
NULL
};
PurpleConnectionUiOps *finch_connections_get_ui_ops()
{
return &ops;
}
void finch_connections_init()
{
hash = g_hash_table_new_full(
g_direct_hash, g_direct_equal,
NULL, free_auto_recon);
purple_signal_connect(purple_accounts_get_handle(), "account-removed",
finch_connection_get_handle(),
PURPLE_CALLBACK(account_removed_cb), NULL);
}
void finch_connections_uninit()
{
purple_signals_disconnect_by_handle(finch_connection_get_handle());
g_hash_table_destroy(hash);
}