2 * @file lastlog.c Lastlog plugin for purple-text.
4 * Copyright (C) 2006 Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #define PLUGIN_STATIC_NAME "GntLastlog"
32 #include <gnttextview.h>
33 #include <gntwindow.h>
36 #include <gntplugin.h>
38 static PurpleCmdId cmd
;
41 window_kpress_cb(GntWidget
*wid
, const char *key
, GntTextView
*view
)
45 if (strcmp(key
, GNT_KEY_DOWN
) == 0)
46 gnt_text_view_scroll(view
, 1);
47 else if (strcmp(key
, GNT_KEY_UP
) == 0)
48 gnt_text_view_scroll(view
, -1);
49 else if (strcmp(key
, GNT_KEY_PGDOWN
) == 0)
50 gnt_text_view_scroll(view
, wid
->priv
.height
- 2);
51 else if (strcmp(key
, GNT_KEY_PGUP
) == 0)
52 gnt_text_view_scroll(view
, -(wid
->priv
.height
- 2));
61 lastlog_cb(PurpleConversation
*conv
, const char *cmd
, char **args
, char **error
, gpointer null
)
63 FinchConv
*ggconv
= conv
->ui_data
;
64 char **strings
= g_strsplit(GNT_TEXT_VIEW(ggconv
->tv
)->string
->str
, "\n", 0);
68 win
= gnt_window_new();
69 gnt_box_set_title(GNT_BOX(win
), _("Lastlog"));
71 tv
= gnt_text_view_new();
72 gnt_box_add_widget(GNT_BOX(win
), tv
);
76 for (i
= 0; strings
[i
]; i
++) {
77 if (strstr(strings
[i
], args
[0]) != NULL
) {
78 char **finds
= g_strsplit(strings
[i
], args
[0], 0);
79 for (j
= 0; finds
[j
]; j
++) {
81 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv
), args
[0], GNT_TEXT_FLAG_BOLD
);
82 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv
), finds
[j
], GNT_TEXT_FLAG_NORMAL
);
85 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv
), "\n", GNT_TEXT_FLAG_NORMAL
);
89 g_signal_connect(G_OBJECT(win
), "key_pressed", G_CALLBACK(window_kpress_cb
), tv
);
91 return PURPLE_CMD_STATUS_OK
;
95 plugin_load(PurplePlugin
*plugin
)
97 cmd
= purple_cmd_register("lastlog", "s", PURPLE_CMD_P_DEFAULT
,
98 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
99 /* Translator Note: The "backlog" is the conversation buffer/history. */
100 lastlog_cb
, _("lastlog: Searches for a substring in the backlog."), NULL
);
105 plugin_unload(PurplePlugin
*plugin
)
107 purple_cmd_unregister(cmd
);
111 static PurplePluginInfo info
=
114 PURPLE_MAJOR_VERSION
,
115 PURPLE_MINOR_VERSION
,
116 PURPLE_PLUGIN_STANDARD
,
120 PURPLE_PRIORITY_DEFAULT
,
124 N_("Lastlog plugin."),
125 N_("Lastlog plugin."),
126 "Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
144 init_plugin(PurplePlugin
*plugin
)
148 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME
, init_plugin
, info
)