author | Myhailo Danylenko <isbear@ukrpost.net> |
Tue, 03 May 2011 16:35:05 +0300 | |
changeset 19 | c7e7218be611 |
parent 16 | 42179abafd69 |
child 21 | 66ece9145926 |
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> |
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
33 |
#include <mcabber/api.h> |
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
34 |
|
11
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
35 |
#include "config.h" |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
36 |
|
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
37 |
void marking_init (void); |
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
38 |
void marking_uninit (void); |
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
39 |
|
11
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
40 |
#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
|
41 |
|
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
42 |
static module_info_t info_marking_dev = { |
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
43 |
.branch = "dev", |
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
44 |
.api = 20, |
11
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
45 |
.version = PROJECT_VERSION, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
46 |
.description = DESCRIPTION, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
47 |
.requires = NULL, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
48 |
.init = marking_init, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
49 |
.uninit = marking_uninit, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
50 |
.next = NULL, |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
51 |
}; |
f7c76b2c9900
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
52 |
|
16
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
53 |
module_info_t info_marking = { |
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
54 |
.branch = "0.10.1", |
16
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
55 |
.api = 1, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
56 |
.version = PROJECT_VERSION, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
57 |
.description = DESCRIPTION, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
58 |
.requires = NULL, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
59 |
.init = marking_init, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
60 |
.uninit = marking_uninit, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
61 |
.next = &info_marking_dev, |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
62 |
}; |
42179abafd69
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
63 |
|
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
64 |
#ifdef MCABBER_API_HAVE_CMD_ID |
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
65 |
static gpointer mark_cmid = NULL; |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
66 |
static gpointer marked_cmid = NULL; |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
67 |
#endif |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
68 |
|
0 | 69 |
static GSList *marked_jids = NULL; |
70 |
||
71 |
// mark set jid |
|
72 |
// mark clear jid |
|
73 |
// mark toggle jid |
|
74 |
static void do_mark (char *arg) |
|
75 |
{ |
|
76 |
char **args = split_arg (arg, 2, 1); |
|
77 |
char *cmd = NULL; |
|
78 |
char *jid = NULL; |
|
79 |
gboolean jfree = FALSE; |
|
80 |
int marked = -1; |
|
81 |
||
82 |
if (args[0]) { |
|
83 |
cmd = args[0]; |
|
84 |
||
85 |
if (args[1]) |
|
86 |
jid = jidtodisp (args[1]); |
|
87 |
} else |
|
88 |
cmd = "set"; |
|
89 |
||
90 |
if (!strcmp (cmd, "set")) { |
|
91 |
||
92 |
if (!g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0)) { |
|
93 |
marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID)); |
|
94 |
marked = 1; |
|
95 |
} else |
|
96 |
jfree = TRUE; |
|
97 |
||
98 |
} else if (!strcmp (cmd, "clear")) { |
|
99 |
||
100 |
GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0); |
|
101 |
||
102 |
if (mel) { |
|
103 |
g_free (mel->data); |
|
104 |
marked_jids = g_slist_delete_link (marked_jids, mel); |
|
105 |
marked = 0; |
|
106 |
} |
|
107 |
||
108 |
jfree = TRUE; |
|
109 |
||
110 |
} else if (!strcmp (cmd, "toggle")) { |
|
111 |
||
112 |
GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0); |
|
113 |
||
114 |
if (mel) { |
|
115 |
g_free (mel->data); |
|
116 |
marked_jids = g_slist_delete_link (marked_jids, mel); |
|
117 |
marked = 0; |
|
118 |
jfree = TRUE; |
|
119 |
} else { |
|
120 |
marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID)); |
|
121 |
marked = 1; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
if (marked == 1) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
126 |
scr_write_incoming_message (jid ? jid : CURRENT_JID, "Marked", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
0 | 127 |
else if (marked == 0) |
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
128 |
scr_write_incoming_message (jid ? jid : CURRENT_JID, "Mark cleared", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
0 | 129 |
|
130 |
if (jfree && jid) |
|
131 |
g_free (jid); |
|
132 |
||
133 |
free_arg_lst (args); |
|
134 |
} |
|
135 |
||
1
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
136 |
// marked clear |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
137 |
// marked do cmd |
0 | 138 |
void do_marked (char *arg) |
139 |
{ |
|
140 |
char **args = split_arg (arg, 2, 1); |
|
141 |
char *cmd = args[0]; |
|
142 |
||
143 |
if (!cmd) |
|
144 |
cmd = "list"; |
|
145 |
||
146 |
if (!strcmp (cmd, "list")) { |
|
147 |
||
148 |
GSList *mel; |
|
149 |
||
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
150 |
scr_log_print (LPRINT_NORMAL, "Marked jids:"); |
0 | 151 |
for (mel = marked_jids; mel; mel = mel->next) { |
152 |
char *jid = (char *) mel->data; |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
153 |
scr_log_print (LPRINT_NORMAL, " * %s", jid); |
0 | 154 |
} |
155 |
||
156 |
} else if (!strcmp (cmd, "clear")) { |
|
157 |
||
158 |
GSList *mel; |
|
159 |
||
160 |
for (mel = marked_jids; mel; mel = mel->next) |
|
161 |
g_free (mel->data); |
|
162 |
||
163 |
g_slist_free (marked_jids); |
|
164 |
marked_jids = NULL; |
|
165 |
||
166 |
} else if (!strcmp (cmd, "do")) { |
|
167 |
char *format = args[1]; |
|
168 |
||
169 |
if (!format) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
170 |
scr_log_print (LPRINT_NORMAL, "You must specify action to do with marked jids"); |
0 | 171 |
else { |
172 |
char *pos = format; |
|
173 |
gboolean found = FALSE; |
|
174 |
gboolean error = FALSE; |
|
175 |
||
176 |
for (pos = strchr (pos, '%'); pos; pos = strchr (pos, '%')) { |
|
177 |
if (*(pos + 1) == 's') |
|
178 |
found = TRUE; |
|
179 |
else if (*(pos + 1) == '%') |
|
180 |
++pos; |
|
181 |
else { |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
182 |
scr_log_print (LPRINT_NORMAL, "Action string must not contain any other %%-sequesnces!"); |
0 | 183 |
error = TRUE; |
184 |
break; |
|
185 |
} |
|
186 |
||
187 |
++pos; |
|
188 |
} |
|
189 |
||
190 |
if (!found) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
191 |
scr_log_print (LPRINT_NORMAL, "Action string must contain one %%s!"); |
0 | 192 |
else if (!error) { |
193 |
GSList *mel; |
|
194 |
||
195 |
for (mel = marked_jids; mel; mel = mel->next) { |
|
196 |
char *jid = (char *) mel->data; |
|
197 |
char *command = g_strdup_printf (format, jid); |
|
198 |
process_command (command, TRUE); |
|
199 |
g_free (command); |
|
200 |
} |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
free_arg_lst (args); |
|
206 |
} |
|
207 |
||
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
208 |
void marking_init (void) |
0 | 209 |
{ |
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
210 |
#ifndef MCABBER_API_HAVE_CMD_ID |
0 | 211 |
cmd_add ("mark", "", 0, COMPL_JID, do_mark, NULL); |
212 |
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
|
213 |
#else |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
214 |
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
|
215 |
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
|
216 |
#endif |
0 | 217 |
} |
218 |
||
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
219 |
void marking_uninit (void) |
0 | 220 |
{ |
19
c7e7218be611
Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
221 |
#ifndef MCABBER_API_HAVE_CMD_ID |
0 | 222 |
cmd_del ("mark"); |
223 |
cmd_del ("marked"); |
|
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
224 |
#else |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
225 |
if (mark_cmid) |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
226 |
cmd_del (mark_cmid); |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
227 |
if (marked_cmid) |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
228 |
cmd_del (marked_cmid); |
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
229 |
#endif |
0 | 230 |
|
231 |
{ |
|
232 |
GSList *mel; |
|
233 |
||
234 |
for (mel = marked_jids; mel; mel = mel->next) |
|
235 |
g_free (mel->data); |
|
236 |
||
237 |
g_slist_free (marked_jids); |
|
238 |
marked_jids = NULL; |
|
239 |
} |
|
240 |
} |
|
241 |
||
15
522a4193ef2f
Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents:
14
diff
changeset
|
242 |
/* vim: se ts=4 sw=4: */ |