author | Myhailo Danylenko <isbear@ukrpost.net> |
Sun, 11 Apr 2010 21:56:02 +0300 | |
changeset 16 | 42179abafd69 |
parent 15 | 522a4193ef2f |
child 19 | c7e7218be611 |
permissions | -rw-r--r-- |
0 | 1 |
|
1
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
2 |
/* |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
3 |
* marking.c -- Actions on multiple buddies |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
4 |
* |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
5 |
* Copyrigth (C) 2009 Myhailo Danylenko <isbear@ukrpost.net> |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
6 |
* |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
7 |
* This program is free software; you can redistribute it and/or modify |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
9 |
* the Free Software Foundation; either version 2 of the License, or (at |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
10 |
* your option) any later version. |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
11 |
* |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, but |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
15 |
* General Public License for more details. |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
16 |
* |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
18 |
* along with this program; if not, write to the Free Software |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
20 |
* USA |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
21 |
*/ |
0 | 22 |
|
23 |
#include <glib.h> |
|
24 |
#include <string.h> |
|
25 |
||
2
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
26 |
#include <mcabber/hbuf.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
27 |
#include <mcabber/screen.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
28 |
#include <mcabber/commands.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
29 |
#include <mcabber/compl.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
30 |
#include <mcabber/utils.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
31 |
#include <mcabber/logprint.h> |
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
32 |
#include <mcabber/modules.h> |
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
33 |
|
11
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
34 |
#include "config.h" |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
35 |
|
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
36 |
static void marking_init (void); |
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
37 |
static void marking_uninit (void); |
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
38 |
|
11
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
39 |
#define DESCRIPTION ( "Actions on multiple marked buddies\nProvides commands /mark and /marked" ) |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
40 |
|
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
41 |
static module_info_t info_marking_experimental = { |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
42 |
.branch = "experimental", |
16
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
43 |
.api = 27, |
11
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
44 |
.version = PROJECT_VERSION, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
45 |
.description = DESCRIPTION, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
46 |
.requires = NULL, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
47 |
.init = marking_init, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
48 |
.uninit = marking_uninit, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
49 |
.next = NULL, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
50 |
}; |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
51 |
|
16
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
52 |
static module_info_t info_marking_dev = { |
11
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
53 |
.branch = "dev", |
14 | 54 |
.api = 13, |
11
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
55 |
.version = PROJECT_VERSION, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
56 |
.description = DESCRIPTION, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
57 |
.requires = NULL, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
58 |
.init = marking_init, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
59 |
.uninit = marking_uninit, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
60 |
.next = &info_marking_experimental, |
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
61 |
}; |
0 | 62 |
|
16
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
63 |
module_info_t info_marking = { |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
64 |
.branch = "0.10.0", |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
65 |
.api = 1, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
66 |
.version = PROJECT_VERSION, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
67 |
.description = DESCRIPTION, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
68 |
.requires = NULL, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
69 |
.init = marking_init, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
70 |
.uninit = marking_uninit, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
71 |
.next = &info_marking_dev, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
72 |
}; |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
73 |
|
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
74 |
#ifdef HAVE_CMD_ID |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
75 |
static gpointer mark_cmid = NULL; |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
76 |
static gpointer marked_cmid = NULL; |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
77 |
#endif |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
78 |
|
0 | 79 |
static GSList *marked_jids = NULL; |
80 |
||
81 |
// mark set jid |
|
82 |
// mark clear jid |
|
83 |
// mark toggle jid |
|
84 |
static void do_mark (char *arg) |
|
85 |
{ |
|
86 |
char **args = split_arg (arg, 2, 1); |
|
87 |
char *cmd = NULL; |
|
88 |
char *jid = NULL; |
|
89 |
gboolean jfree = FALSE; |
|
90 |
int marked = -1; |
|
91 |
||
92 |
if (args[0]) { |
|
93 |
cmd = args[0]; |
|
94 |
||
95 |
if (args[1]) |
|
96 |
jid = jidtodisp (args[1]); |
|
97 |
} else |
|
98 |
cmd = "set"; |
|
99 |
||
100 |
if (!strcmp (cmd, "set")) { |
|
101 |
||
102 |
if (!g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0)) { |
|
103 |
marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID)); |
|
104 |
marked = 1; |
|
105 |
} else |
|
106 |
jfree = TRUE; |
|
107 |
||
108 |
} else if (!strcmp (cmd, "clear")) { |
|
109 |
||
110 |
GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0); |
|
111 |
||
112 |
if (mel) { |
|
113 |
g_free (mel->data); |
|
114 |
marked_jids = g_slist_delete_link (marked_jids, mel); |
|
115 |
marked = 0; |
|
116 |
} |
|
117 |
||
118 |
jfree = TRUE; |
|
119 |
||
120 |
} else if (!strcmp (cmd, "toggle")) { |
|
121 |
||
122 |
GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0); |
|
123 |
||
124 |
if (mel) { |
|
125 |
g_free (mel->data); |
|
126 |
marked_jids = g_slist_delete_link (marked_jids, mel); |
|
127 |
marked = 0; |
|
128 |
jfree = TRUE; |
|
129 |
} else { |
|
130 |
marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID)); |
|
131 |
marked = 1; |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
if (marked == 1) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
136 |
scr_write_incoming_message (jid ? jid : CURRENT_JID, "Marked", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
0 | 137 |
else if (marked == 0) |
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
138 |
scr_write_incoming_message (jid ? jid : CURRENT_JID, "Mark cleared", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
0 | 139 |
|
140 |
if (jfree && jid) |
|
141 |
g_free (jid); |
|
142 |
||
143 |
free_arg_lst (args); |
|
144 |
} |
|
145 |
||
1
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
146 |
// marked clear |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
147 |
// marked do cmd |
0 | 148 |
void do_marked (char *arg) |
149 |
{ |
|
150 |
char **args = split_arg (arg, 2, 1); |
|
151 |
char *cmd = args[0]; |
|
152 |
||
153 |
if (!cmd) |
|
154 |
cmd = "list"; |
|
155 |
||
156 |
if (!strcmp (cmd, "list")) { |
|
157 |
||
158 |
GSList *mel; |
|
159 |
||
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
160 |
scr_log_print (LPRINT_NORMAL, "Marked jids:"); |
0 | 161 |
for (mel = marked_jids; mel; mel = mel->next) { |
162 |
char *jid = (char *) mel->data; |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
163 |
scr_log_print (LPRINT_NORMAL, " * %s", jid); |
0 | 164 |
} |
165 |
||
166 |
} else if (!strcmp (cmd, "clear")) { |
|
167 |
||
168 |
GSList *mel; |
|
169 |
||
170 |
for (mel = marked_jids; mel; mel = mel->next) |
|
171 |
g_free (mel->data); |
|
172 |
||
173 |
g_slist_free (marked_jids); |
|
174 |
marked_jids = NULL; |
|
175 |
||
176 |
} else if (!strcmp (cmd, "do")) { |
|
177 |
char *format = args[1]; |
|
178 |
||
179 |
if (!format) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
180 |
scr_log_print (LPRINT_NORMAL, "You must specify action to do with marked jids"); |
0 | 181 |
else { |
182 |
char *pos = format; |
|
183 |
gboolean found = FALSE; |
|
184 |
gboolean error = FALSE; |
|
185 |
||
186 |
for (pos = strchr (pos, '%'); pos; pos = strchr (pos, '%')) { |
|
187 |
if (*(pos + 1) == 's') |
|
188 |
found = TRUE; |
|
189 |
else if (*(pos + 1) == '%') |
|
190 |
++pos; |
|
191 |
else { |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
192 |
scr_log_print (LPRINT_NORMAL, "Action string must not contain any other %%-sequesnces!"); |
0 | 193 |
error = TRUE; |
194 |
break; |
|
195 |
} |
|
196 |
||
197 |
++pos; |
|
198 |
} |
|
199 |
||
200 |
if (!found) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
201 |
scr_log_print (LPRINT_NORMAL, "Action string must contain one %%s!"); |
0 | 202 |
else if (!error) { |
203 |
GSList *mel; |
|
204 |
||
205 |
for (mel = marked_jids; mel; mel = mel->next) { |
|
206 |
char *jid = (char *) mel->data; |
|
207 |
char *command = g_strdup_printf (format, jid); |
|
208 |
process_command (command, TRUE); |
|
209 |
g_free (command); |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
free_arg_lst (args); |
|
216 |
} |
|
217 |
||
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
218 |
static void marking_init (void) |
0 | 219 |
{ |
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
220 |
#ifndef HAVE_CMD_ID |
0 | 221 |
cmd_add ("mark", "", 0, COMPL_JID, do_mark, NULL); |
222 |
cmd_add ("marked", "", 0, COMPL_CMD, do_marked, NULL); |
|
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
223 |
#else |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
224 |
mark_cmid = cmd_add ("mark", "", 0, COMPL_JID, do_mark, NULL); |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
225 |
marked_cmid = cmd_add ("marked", "", 0, COMPL_CMD, do_marked, NULL); |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
226 |
#endif |
0 | 227 |
} |
228 |
||
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
229 |
static void marking_uninit (void) |
0 | 230 |
{ |
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
231 |
#ifndef HAVE_CMD_ID |
0 | 232 |
cmd_del ("mark"); |
233 |
cmd_del ("marked"); |
|
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
234 |
#else |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
235 |
if (mark_cmid) |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
236 |
cmd_del (mark_cmid); |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
237 |
if (marked_cmid) |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
238 |
cmd_del (marked_cmid); |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
239 |
#endif |
0 | 240 |
|
241 |
{ |
|
242 |
GSList *mel; |
|
243 |
||
244 |
for (mel = marked_jids; mel; mel = mel->next) |
|
245 |
g_free (mel->data); |
|
246 |
||
247 |
g_slist_free (marked_jids); |
|
248 |
marked_jids = NULL; |
|
249 |
} |
|
250 |
} |
|
251 |
||
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
252 |
/* vim: se ts=4 sw=4: */ |