1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/**
* @file lastlog.c Lastlog plugin for purple-text.
*
* 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
*/
#define PLUGIN_STATIC_NAME GntLastlog
#include "internal.h"
#include <plugin.h>
#include <version.h>
#include <cmds.h>
#include <gnt.h>
#include <gnttextview.h>
#include <gntwindow.h>
#include <gntconv.h>
#include <gntplugin.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 = conv->ui_data;
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 gboolean
plugin_load(PurplePlugin *plugin)
{
cmd = purple_cmd_register("lastlog", "s", PURPLE_CMD_P_DEFAULT,
PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL,
/* Translator Note: The "backlog" is the conversation buffer/history. */
lastlog_cb, _("lastlog: Searches for a substring in the backlog."), NULL);
return TRUE;
}
static gboolean
plugin_unload(PurplePlugin *plugin)
{
purple_cmd_unregister(cmd);
return TRUE;
}
static PurplePluginInfo info =
{
PURPLE_PLUGIN_MAGIC,
PURPLE_MAJOR_VERSION,
PURPLE_MINOR_VERSION,
PURPLE_PLUGIN_STANDARD,
FINCH_PLUGIN_TYPE,
0,
NULL,
PURPLE_PRIORITY_DEFAULT,
"gntlastlog",
N_("GntLastlog"),
DISPLAY_VERSION,
N_("Lastlog plugin."),
N_("Lastlog plugin."),
"Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
PURPLE_WEBSITE,
plugin_load,
plugin_unload,
NULL,
NULL,
NULL,
NULL,
NULL,
/* padding */
NULL,
NULL,
NULL,
NULL
};
static void
init_plugin(PurplePlugin *plugin)
{
}
PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)
|