author | Myhailo Danylenko <isbear@ukrpost.net> |
Fri, 15 Jan 2010 11:44:12 +0200 | |
changeset 5 | 80a5ee0efeff |
parent 2 | 30b66610f86a |
child 10 | b84d72957c06 |
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 <gmodule.h> |
|
25 |
#include <string.h> |
|
26 |
||
2
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
27 |
#include <mcabber/hbuf.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
28 |
#include <mcabber/screen.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
29 |
#include <mcabber/commands.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
30 |
#include <mcabber/compl.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
31 |
#include <mcabber/utils.h> |
30b66610f86a
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
32 |
#include <mcabber/logprint.h> |
0 | 33 |
|
34 |
static GSList *marked_jids = NULL; |
|
35 |
||
36 |
// mark set jid |
|
37 |
// mark clear jid |
|
38 |
// mark toggle jid |
|
39 |
static void do_mark (char *arg) |
|
40 |
{ |
|
41 |
char **args = split_arg (arg, 2, 1); |
|
42 |
char *cmd = NULL; |
|
43 |
char *jid = NULL; |
|
44 |
gboolean jfree = FALSE; |
|
45 |
int marked = -1; |
|
46 |
||
47 |
if (args[0]) { |
|
48 |
cmd = args[0]; |
|
49 |
||
50 |
if (args[1]) |
|
51 |
jid = jidtodisp (args[1]); |
|
52 |
} else |
|
53 |
cmd = "set"; |
|
54 |
||
55 |
if (!strcmp (cmd, "set")) { |
|
56 |
||
57 |
if (!g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0)) { |
|
58 |
marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID)); |
|
59 |
marked = 1; |
|
60 |
} else |
|
61 |
jfree = TRUE; |
|
62 |
||
63 |
} else if (!strcmp (cmd, "clear")) { |
|
64 |
||
65 |
GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0); |
|
66 |
||
67 |
if (mel) { |
|
68 |
g_free (mel->data); |
|
69 |
marked_jids = g_slist_delete_link (marked_jids, mel); |
|
70 |
marked = 0; |
|
71 |
} |
|
72 |
||
73 |
jfree = TRUE; |
|
74 |
||
75 |
} else if (!strcmp (cmd, "toggle")) { |
|
76 |
||
77 |
GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0); |
|
78 |
||
79 |
if (mel) { |
|
80 |
g_free (mel->data); |
|
81 |
marked_jids = g_slist_delete_link (marked_jids, mel); |
|
82 |
marked = 0; |
|
83 |
jfree = TRUE; |
|
84 |
} else { |
|
85 |
marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID)); |
|
86 |
marked = 1; |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
if (marked == 1) |
|
91 |
scr_WriteIncomingMessage (jid ? jid : CURRENT_JID, "Marked", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
|
92 |
else if (marked == 0) |
|
93 |
scr_WriteIncomingMessage (jid ? jid : CURRENT_JID, "Mark cleared", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
|
94 |
||
95 |
if (jfree && jid) |
|
96 |
g_free (jid); |
|
97 |
||
98 |
free_arg_lst (args); |
|
99 |
} |
|
100 |
||
1
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
101 |
// marked clear |
c8473c43ce72
Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
102 |
// marked do cmd |
0 | 103 |
void do_marked (char *arg) |
104 |
{ |
|
105 |
char **args = split_arg (arg, 2, 1); |
|
106 |
char *cmd = args[0]; |
|
107 |
||
108 |
if (!cmd) |
|
109 |
cmd = "list"; |
|
110 |
||
111 |
if (!strcmp (cmd, "list")) { |
|
112 |
||
113 |
GSList *mel; |
|
114 |
||
115 |
scr_LogPrint (LPRINT_NORMAL, "Marked jids:"); |
|
116 |
for (mel = marked_jids; mel; mel = mel->next) { |
|
117 |
char *jid = (char *) mel->data; |
|
118 |
scr_LogPrint (LPRINT_NORMAL, " * %s", jid); |
|
119 |
} |
|
120 |
||
121 |
} else if (!strcmp (cmd, "clear")) { |
|
122 |
||
123 |
GSList *mel; |
|
124 |
||
125 |
for (mel = marked_jids; mel; mel = mel->next) |
|
126 |
g_free (mel->data); |
|
127 |
||
128 |
g_slist_free (marked_jids); |
|
129 |
marked_jids = NULL; |
|
130 |
||
131 |
} else if (!strcmp (cmd, "do")) { |
|
132 |
char *format = args[1]; |
|
133 |
||
134 |
if (!format) |
|
135 |
scr_LogPrint (LPRINT_NORMAL, "You must specify action to do with marked jids"); |
|
136 |
else { |
|
137 |
char *pos = format; |
|
138 |
gboolean found = FALSE; |
|
139 |
gboolean error = FALSE; |
|
140 |
||
141 |
for (pos = strchr (pos, '%'); pos; pos = strchr (pos, '%')) { |
|
142 |
if (*(pos + 1) == 's') |
|
143 |
found = TRUE; |
|
144 |
else if (*(pos + 1) == '%') |
|
145 |
++pos; |
|
146 |
else { |
|
147 |
scr_LogPrint (LPRINT_NORMAL, "Action string must not contain any other %%-sequesnces!"); |
|
148 |
error = TRUE; |
|
149 |
break; |
|
150 |
} |
|
151 |
||
152 |
++pos; |
|
153 |
} |
|
154 |
||
155 |
if (!found) |
|
156 |
scr_LogPrint (LPRINT_NORMAL, "Action string must contain one %%s!"); |
|
157 |
else if (!error) { |
|
158 |
GSList *mel; |
|
159 |
||
160 |
for (mel = marked_jids; mel; mel = mel->next) { |
|
161 |
char *jid = (char *) mel->data; |
|
162 |
char *command = g_strdup_printf (format, jid); |
|
163 |
process_command (command, TRUE); |
|
164 |
g_free (command); |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
free_arg_lst (args); |
|
171 |
} |
|
172 |
||
173 |
gchar *g_module_check_init (GModule *module) |
|
174 |
{ |
|
175 |
cmd_add ("mark", "", 0, COMPL_JID, do_mark, NULL); |
|
176 |
cmd_add ("marked", "", 0, COMPL_CMD, do_marked, NULL); |
|
177 |
||
178 |
return NULL; |
|
179 |
} |
|
180 |
||
181 |
void g_module_unload (GModule *module) |
|
182 |
{ |
|
183 |
cmd_del ("mark"); |
|
184 |
cmd_del ("marked"); |
|
185 |
||
186 |
{ |
|
187 |
GSList *mel; |
|
188 |
||
189 |
for (mel = marked_jids; mel; mel = mel->next) |
|
190 |
g_free (mel->data); |
|
191 |
||
192 |
g_slist_free (marked_jids); |
|
193 |
marked_jids = NULL; |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
/* The End */ |