author | Myhailo Danylenko <isbear@ukrpost.net> |
Sun, 04 Apr 2010 16:44:53 +0300 | |
changeset 14 | 01cdc293e2c2 |
parent 12 | 5ae14bc061b2 |
child 15 | 522a4193ef2f |
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", |
14 | 43 |
.api = 15, |
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 |
|
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
52 |
module_info_t info_marking = { |
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 |
|
63 |
static GSList *marked_jids = NULL; |
|
64 |
||
65 |
// mark set jid |
|
66 |
// mark clear jid |
|
67 |
// mark toggle jid |
|
68 |
static void do_mark (char *arg) |
|
69 |
{ |
|
70 |
char **args = split_arg (arg, 2, 1); |
|
71 |
char *cmd = NULL; |
|
72 |
char *jid = NULL; |
|
73 |
gboolean jfree = FALSE; |
|
74 |
int marked = -1; |
|
75 |
||
76 |
if (args[0]) { |
|
77 |
cmd = args[0]; |
|
78 |
||
79 |
if (args[1]) |
|
80 |
jid = jidtodisp (args[1]); |
|
81 |
} else |
|
82 |
cmd = "set"; |
|
83 |
||
84 |
if (!strcmp (cmd, "set")) { |
|
85 |
||
86 |
if (!g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0)) { |
|
87 |
marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID)); |
|
88 |
marked = 1; |
|
89 |
} else |
|
90 |
jfree = TRUE; |
|
91 |
||
92 |
} else if (!strcmp (cmd, "clear")) { |
|
93 |
||
94 |
GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0); |
|
95 |
||
96 |
if (mel) { |
|
97 |
g_free (mel->data); |
|
98 |
marked_jids = g_slist_delete_link (marked_jids, mel); |
|
99 |
marked = 0; |
|
100 |
} |
|
101 |
||
102 |
jfree = TRUE; |
|
103 |
||
104 |
} else if (!strcmp (cmd, "toggle")) { |
|
105 |
||
106 |
GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0); |
|
107 |
||
108 |
if (mel) { |
|
109 |
g_free (mel->data); |
|
110 |
marked_jids = g_slist_delete_link (marked_jids, mel); |
|
111 |
marked = 0; |
|
112 |
jfree = TRUE; |
|
113 |
} else { |
|
114 |
marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID)); |
|
115 |
marked = 1; |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
if (marked == 1) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
120 |
scr_write_incoming_message (jid ? jid : CURRENT_JID, "Marked", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
0 | 121 |
else if (marked == 0) |
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
122 |
scr_write_incoming_message (jid ? jid : CURRENT_JID, "Mark cleared", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
0 | 123 |
|
124 |
if (jfree && jid) |
|
125 |
g_free (jid); |
|
126 |
||
127 |
free_arg_lst (args); |
|
128 |
} |
|
129 |
||
1
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
130 |
// marked clear |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
131 |
// marked do cmd |
0 | 132 |
void do_marked (char *arg) |
133 |
{ |
|
134 |
char **args = split_arg (arg, 2, 1); |
|
135 |
char *cmd = args[0]; |
|
136 |
||
137 |
if (!cmd) |
|
138 |
cmd = "list"; |
|
139 |
||
140 |
if (!strcmp (cmd, "list")) { |
|
141 |
||
142 |
GSList *mel; |
|
143 |
||
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
144 |
scr_log_print (LPRINT_NORMAL, "Marked jids:"); |
0 | 145 |
for (mel = marked_jids; mel; mel = mel->next) { |
146 |
char *jid = (char *) mel->data; |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
147 |
scr_log_print (LPRINT_NORMAL, " * %s", jid); |
0 | 148 |
} |
149 |
||
150 |
} else if (!strcmp (cmd, "clear")) { |
|
151 |
||
152 |
GSList *mel; |
|
153 |
||
154 |
for (mel = marked_jids; mel; mel = mel->next) |
|
155 |
g_free (mel->data); |
|
156 |
||
157 |
g_slist_free (marked_jids); |
|
158 |
marked_jids = NULL; |
|
159 |
||
160 |
} else if (!strcmp (cmd, "do")) { |
|
161 |
char *format = args[1]; |
|
162 |
||
163 |
if (!format) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
164 |
scr_log_print (LPRINT_NORMAL, "You must specify action to do with marked jids"); |
0 | 165 |
else { |
166 |
char *pos = format; |
|
167 |
gboolean found = FALSE; |
|
168 |
gboolean error = FALSE; |
|
169 |
||
170 |
for (pos = strchr (pos, '%'); pos; pos = strchr (pos, '%')) { |
|
171 |
if (*(pos + 1) == 's') |
|
172 |
found = TRUE; |
|
173 |
else if (*(pos + 1) == '%') |
|
174 |
++pos; |
|
175 |
else { |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
176 |
scr_log_print (LPRINT_NORMAL, "Action string must not contain any other %%-sequesnces!"); |
0 | 177 |
error = TRUE; |
178 |
break; |
|
179 |
} |
|
180 |
||
181 |
++pos; |
|
182 |
} |
|
183 |
||
184 |
if (!found) |
|
12
5ae14bc061b2
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
11
diff
changeset
|
185 |
scr_log_print (LPRINT_NORMAL, "Action string must contain one %%s!"); |
0 | 186 |
else if (!error) { |
187 |
GSList *mel; |
|
188 |
||
189 |
for (mel = marked_jids; mel; mel = mel->next) { |
|
190 |
char *jid = (char *) mel->data; |
|
191 |
char *command = g_strdup_printf (format, jid); |
|
192 |
process_command (command, TRUE); |
|
193 |
g_free (command); |
|
194 |
} |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
free_arg_lst (args); |
|
200 |
} |
|
201 |
||
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
202 |
static void marking_init (void) |
0 | 203 |
{ |
204 |
cmd_add ("mark", "", 0, COMPL_JID, do_mark, NULL); |
|
205 |
cmd_add ("marked", "", 0, COMPL_CMD, do_marked, NULL); |
|
206 |
} |
|
207 |
||
10
b84d72957c06
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
208 |
static void marking_uninit (void) |
0 | 209 |
{ |
210 |
cmd_del ("mark"); |
|
211 |
cmd_del ("marked"); |
|
212 |
||
213 |
{ |
|
214 |
GSList *mel; |
|
215 |
||
216 |
for (mel = marked_jids; mel; mel = mel->next) |
|
217 |
g_free (mel->data); |
|
218 |
||
219 |
g_slist_free (marked_jids); |
|
220 |
marked_jids = NULL; |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
/* The End */ |