Mercurial > pidgin.yaz
annotate finch/plugins/lastlog.c @ 19675:a48681403103
Unregister the iq callback listener when the transfer is freed. Fixes #1804. It doesn't seem correct to me that nothing is sent to the recipient when the sender cancels the ft request, but that is a different issue.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 07 Sep 2007 01:52:47 +0000 |
parents | 30829e806dae |
children | 44b4e8bd759b |
rev | line source |
---|---|
15818 | 1 /** |
15823 | 2 * @file lastlog.c Lastlog plugin for purple-text. |
15818 | 3 * |
4 * Copyright (C) 2006 Sadrul Habib Chowdhury <sadrul@users.sourceforge.net> | |
5 * | |
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. | |
10 * | |
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. | |
15 * | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 | |
21 | |
22 #define PLUGIN_STATIC_NAME "GntLastlog" | |
23 | |
24 #include "internal.h" | |
25 | |
26 #include <plugin.h> | |
27 #include <version.h> | |
28 | |
29 #include <cmds.h> | |
30 | |
31 #include <gnt.h> | |
32 #include <gnttextview.h> | |
33 #include <gntwindow.h> | |
34 | |
35 #include <gntconv.h> | |
36 #include <gntplugin.h> | |
37 | |
15823 | 38 static PurpleCmdId cmd; |
15818 | 39 |
40 static gboolean | |
41 window_kpress_cb(GntWidget *wid, const char *key, GntTextView *view) | |
42 { | |
43 if (key[0] == 27) | |
44 { | |
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)); | |
53 else | |
54 return FALSE; | |
55 return TRUE; | |
56 } | |
57 return FALSE; | |
58 } | |
59 | |
15823 | 60 static PurpleCmdRet |
61 lastlog_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer null) | |
15818 | 62 { |
63 FinchConv *ggconv = conv->ui_data; | |
64 char **strings = g_strsplit(GNT_TEXT_VIEW(ggconv->tv)->string->str, "\n", 0); | |
65 GntWidget *win, *tv; | |
66 int i, j; | |
67 | |
68 win = gnt_window_new(); | |
69 gnt_box_set_title(GNT_BOX(win), _("Lastlog")); | |
70 | |
71 tv = gnt_text_view_new(); | |
72 gnt_box_add_widget(GNT_BOX(win), tv); | |
73 | |
74 gnt_widget_show(win); | |
75 | |
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++) { | |
80 if (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); | |
83 } | |
84 g_strfreev(finds); | |
85 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), "\n", GNT_TEXT_FLAG_NORMAL); | |
86 } | |
87 } | |
88 | |
89 g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(window_kpress_cb), tv); | |
90 g_strfreev(strings); | |
15823 | 91 return PURPLE_CMD_STATUS_OK; |
15818 | 92 } |
93 | |
94 static gboolean | |
15823 | 95 plugin_load(PurplePlugin *plugin) |
15818 | 96 { |
15823 | 97 cmd = purple_cmd_register("lastlog", "s", PURPLE_CMD_P_DEFAULT, |
98 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 99 lastlog_cb, _("lastlog: Searches for a substring in the backlog."), NULL); |
100 return TRUE; | |
101 } | |
102 | |
103 static gboolean | |
15823 | 104 plugin_unload(PurplePlugin *plugin) |
15818 | 105 { |
15823 | 106 purple_cmd_unregister(cmd); |
15818 | 107 return TRUE; |
108 } | |
109 | |
15823 | 110 static PurplePluginInfo info = |
15818 | 111 { |
15823 | 112 PURPLE_PLUGIN_MAGIC, |
113 PURPLE_MAJOR_VERSION, | |
114 PURPLE_MINOR_VERSION, | |
115 PURPLE_PLUGIN_STANDARD, | |
116 FINCH_PLUGIN_TYPE, | |
15818 | 117 0, |
118 NULL, | |
15823 | 119 PURPLE_PRIORITY_DEFAULT, |
15818 | 120 "gntlastlog", |
121 N_("GntLastlog"), | |
122 VERSION, | |
123 N_("Lastlog plugin."), | |
124 N_("Lastlog plugin."), | |
125 "Sadrul H Chowdhury <sadrul@users.sourceforge.net>", | |
15864
4c707efebc0c
Use PURPLE_WEBSITE instead of listing the website directly (which was wrong because of the sed).
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
126 PURPLE_WEBSITE, |
15818 | 127 plugin_load, |
128 plugin_unload, | |
129 NULL, | |
130 NULL, | |
131 NULL, | |
132 NULL, | |
16677
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15864
diff
changeset
|
133 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15864
diff
changeset
|
134 |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15864
diff
changeset
|
135 /* padding */ |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15864
diff
changeset
|
136 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15864
diff
changeset
|
137 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15864
diff
changeset
|
138 NULL, |
15818 | 139 NULL |
140 }; | |
141 | |
142 static void | |
15823 | 143 init_plugin(PurplePlugin *plugin) |
15818 | 144 { |
145 } | |
146 | |
15823 | 147 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |
15818 | 148 |