pidgin/pidgin

741992355ead
GSoC History API including sqlite history adapter

The History API has been created to drive all message handling in purple3. It will be used to update existing messages for edits, reactions, pinning, read/deliver receipts, etc. The API uses an adapter pattern, to abstract out backends, but provides a SQLite3 backend by default.

It also provides search capabilities using a custom query language that can easily be expanded over time. It will be use by both the end user to search messages and the frontends to implement features like a pinned messages button. A command line utility is also provided for searching outside of the program itself.

## Remaining Items

**These all will most likely be done by the Pidgin core team after GSoC when we figure out exactly how to solve them.**

Need to store database in purple config directory
* Gary has spent some time looking at this and it looks like the purple-history cli will need to become a purple-ui to make this work write as in the future other adapters will be plugins.

Other things to consider:
- For simplicity, the SqliteHistoryAdapter is parsing the query itself, but for consistency having `PurpleHistoryAdapter` parse the query and pass tokens to the subclass might be something we want to do.

Testing Done:
## Unit Tests
History Manager
History Adapter

## Integration Tests
purplehistorycore created for integration tests.
PurpleSqliteHistoryAdapter functionality tested:
- Creates proper db schema
- Writes logs
- Reads logs
- Queries using query language
- Deletes using query language

Bugs closed: PIDGIN-17526, PIDGIN-17532, PIDGIN-17533, PIDGIN-17534

Reviewed at https://reviews.imfreedom.org/r/877/
/**
* Copyright (C) 2006 Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
*
* 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 <gnt.h>
#include <finch.h>
static PurpleCmdId cmd;
static gboolean
window_kpress_cb(GntWidget *wid, const char *key, GntTextView *view)
{
if (key[0] == 27)
{
if (purple_strequal(key, GNT_KEY_DOWN)) {
gnt_text_view_scroll(view, 1);
} else if (purple_strequal(key, GNT_KEY_UP)) {
gnt_text_view_scroll(view, -1);
} else if (purple_strequal(key, GNT_KEY_PGDOWN)) {
int height = 0;
gnt_widget_get_size(wid, NULL, &height);
gnt_text_view_scroll(view, height - 2);
} else if (purple_strequal(key, GNT_KEY_PGUP)) {
int height = 0;
gnt_widget_get_size(wid, NULL, &height);
gnt_text_view_scroll(view, -(height - 2));
} else {
return FALSE;
}
return TRUE;
}
return FALSE;
}
static PurpleCmdRet
lastlog_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer null)
{
FinchConv *ggconv = FINCH_CONV(conv);
char **strings = g_strsplit(gnt_text_view_get_text(GNT_TEXT_VIEW(ggconv->tv)),
"\n", 0);
GntWidget *win, *tv;
int i, j;
win = gnt_window_new();
gnt_box_set_title(GNT_BOX(win), _("Lastlog"));
tv = gnt_text_view_new();
gnt_box_add_widget(GNT_BOX(win), tv);
gnt_widget_show(win);
for (i = 0; strings[i]; i++) {
if (strstr(strings[i], args[0]) != NULL) {
char **finds = g_strsplit(strings[i], args[0], 0);
for (j = 0; finds[j]; j++) {
if (j)
gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), args[0], GNT_TEXT_FLAG_BOLD);
gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), finds[j], GNT_TEXT_FLAG_NORMAL);
}
g_strfreev(finds);
gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), "\n", GNT_TEXT_FLAG_NORMAL);
}
}
g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(window_kpress_cb), tv);
g_strfreev(strings);
return PURPLE_CMD_RET_OK;
}
static GPluginPluginInfo *
gnt_last_log_query(GError **error) {
const gchar * const authors[] = {
"Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
NULL
};
return finch_plugin_info_new(
"id", "gntlastlog",
"name", N_("GntLastlog"),
"version", DISPLAY_VERSION,
"category", N_("Utility"),
"summary", N_("Lastlog plugin."),
"description", N_("Lastlog plugin."),
"authors", authors,
"website", PURPLE_WEBSITE,
"abi-version", PURPLE_ABI_VERSION,
NULL
);
}
static gboolean
gnt_last_log_load(GPluginPlugin *plugin, GError **error) {
cmd = purple_cmd_register("lastlog", "s", PURPLE_CMD_P_DEFAULT,
PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL,
/* Translators: The "backlog" here refers to the the conversation buffer/history. */
lastlog_cb, _("lastlog: Searches for a substring in the backlog."), NULL);
return TRUE;
}
static gboolean
gnt_last_log_unload(GPluginPlugin *plugin, gboolean shutdown, GError **error) {
purple_cmd_unregister(cmd);
return TRUE;
}
GPLUGIN_NATIVE_PLUGIN_DECLARE(gnt_last_log)