Mercurial > pidgin
annotate plugins/filectl.c @ 11111:f03dce7ea408
[gaim-migrate @ 13163]
Patch #1234440, from sadrul
"Mark blocked users in the buddy-list"
Patch #1234197, from sadrul
"New API fn gaim_privacy_check"
Plus changes by me. (Read as: blame me if it's busted, thank sadrul if it works)
Basically, all this stuff boils down to the following:
We composite a new blocked.png onto the prpl icon in the buddy list if the user is blocked.
MSN was the only prpl that used the old blocked.png. However, it looks bad to overlay both icons, so I removed the use of blocked.png from the MSN prpl. As an MSN user, I think the result is intuitive.
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Sun, 17 Jul 2005 23:36:34 +0000 |
| parents | 50224ac8184d |
| children | bb0d7b719af2 |
| rev | line source |
|---|---|
| 10256 | 1 /** |
| 2 * Send commands to Gaim via ~/.gaim/control | |
| 3 * | |
| 4 * Originally by Eric Warmenhoven <eric@warmenhoven.org> | |
| 5 * Compile fixes/mini hacks Alex Bennee <alex@bennee.com> | |
| 6 * and Brian Tarricone <bjt23@users.sourceforge.net> | |
| 7 */ | |
| 106 | 8 |
| 7658 | 9 /* system includes */ |
| 106 | 10 #include <stdlib.h> |
| 7658 | 11 #include <stdio.h> |
| 106 | 12 #include <unistd.h> |
| 13 #include <sys/types.h> | |
| 14 #include <sys/stat.h> | |
| 15 #include <string.h> | |
| 16 #include <ctype.h> | |
| 17 | |
| 10256 | 18 #include "account.h" |
| 7658 | 19 #include "config.h" |
| 10256 | 20 #include "core.h" |
| 21 #include "conversation.h" | |
| 22 #include "debug.h" | |
| 23 #include "eventloop.h" | |
| 24 #include "internal.h" | |
| 25 #include "util.h" | |
| 9954 | 26 #include "version.h" |
| 7658 | 27 |
| 5255 | 28 #define FILECTL_PLUGIN_ID "core-filectl" |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
29 static int check; |
|
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
30 static time_t mtime; |
| 106 | 31 |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
32 static void init_file(); |
| 7658 | 33 static gboolean check_file(); |
| 106 | 34 |
| 35 /* parse char * as if were word array */ | |
| 36 char *getarg(char *, int, int); | |
| 37 | |
| 38 /* go through file and run any commands */ | |
| 10256 | 39 void |
| 40 run_commands() | |
| 41 { | |
| 106 | 42 struct stat finfo; |
| 43 char filename[256]; | |
| 44 char buffer[1024]; | |
| 45 char *command, *arg1, *arg2; | |
| 46 FILE *file; | |
| 47 | |
| 10256 | 48 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir()); |
| 106 | 49 |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10416
diff
changeset
|
50 file = g_fopen(filename, "r+"); |
| 10256 | 51 while (fgets(buffer, sizeof(buffer), file)) { |
| 52 | |
| 53 /* Read the next command */ | |
| 106 | 54 if (buffer[strlen(buffer) - 1] == '\n') |
| 55 buffer[strlen(buffer) - 1] = 0; | |
| 10256 | 56 gaim_debug_misc("filectl", "read: %s\n", buffer); |
| 106 | 57 command = getarg(buffer, 0, 0); |
| 10256 | 58 |
| 10272 | 59 if (!strncasecmp(command, "login", 6)) { |
| 10256 | 60 GaimAccount *account; |
| 61 | |
| 106 | 62 arg1 = getarg(buffer, 1, 0); |
| 63 arg2 = getarg(buffer, 2, 1); | |
| 10256 | 64 |
| 65 account = gaim_accounts_find(arg1, arg2); | |
| 66 if (account != NULL) /* username found */ | |
| 10744 | 67 gaim_account_connect(account); |
| 10256 | 68 |
| 69 free(arg1); | |
| 70 free(arg2); | |
| 71 | |
| 10272 | 72 } else if (!strncasecmp(command, "logout", 7)) { |
| 10256 | 73 GaimAccount *account; |
| 74 | |
| 75 arg1 = getarg(buffer, 1, 1); | |
| 76 arg2 = getarg(buffer, 2, 1); | |
| 77 | |
| 78 account = gaim_accounts_find(arg1, arg2); | |
| 79 if (account != NULL) | |
| 7658 | 80 { |
| 10738 | 81 gaim_account_disconnect(account); |
| 10256 | 82 } |
| 83 else if (arg1 == NULL) | |
| 84 gaim_connections_disconnect_all(); | |
| 85 | |
| 86 free(arg1); | |
| 87 free(arg2); | |
| 88 | |
| 89 } else if (!strncasecmp(command, "send", 4)) { | |
| 90 GaimConversation *conv; | |
| 91 | |
| 92 arg1 = getarg(buffer, 1, 0); | |
| 93 arg2 = getarg(buffer, 2, 1); | |
| 94 | |
| 95 conv = gaim_find_conversation(GAIM_CONV_ANY, arg1); | |
| 96 if (conv != NULL) | |
| 97 { | |
| 98 /* | |
| 99 gaim_conversation_write(conv, arg2, WFLAG_SEND, NULL, time(NULL), -1); | |
| 100 serv_send_im(conv->gc, arg1, arg2, 0); | |
| 9863 | 101 */ |
| 7658 | 102 } |
| 10256 | 103 |
| 106 | 104 free(arg1); |
| 105 free(arg2); | |
| 10256 | 106 |
| 106 | 107 } else if (!strncasecmp(command, "away", 4)) { |
| 108 arg1 = getarg(buffer, 1, 1); | |
| 10256 | 109 /* serv_set_away_all(arg1); */ |
| 106 | 110 free(arg1); |
| 10256 | 111 |
| 3198 | 112 } else if (!strncasecmp(command, "hide", 4)) { |
| 10256 | 113 gaim_blist_set_visible(FALSE); |
| 114 | |
| 3198 | 115 } else if (!strncasecmp(command, "unhide", 6)) { |
| 10256 | 116 gaim_blist_set_visible(TRUE); |
| 117 | |
| 106 | 118 } else if (!strncasecmp(command, "back", 4)) { |
| 9863 | 119 /* do_im_back(); */ |
| 10256 | 120 |
| 106 | 121 } else if (!strncasecmp(command, "quit", 4)) { |
| 10256 | 122 gaim_core_quit(); |
| 123 | |
| 106 | 124 } |
| 10256 | 125 |
| 106 | 126 free(command); |
| 127 } | |
| 128 | |
| 129 fclose(file); | |
| 130 | |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10416
diff
changeset
|
131 if (g_stat(filename, &finfo) != 0) |
| 106 | 132 return; |
| 133 mtime = finfo.st_mtime; | |
| 134 } | |
| 135 | |
| 10256 | 136 /** |
| 137 * Check to see if the size of the file is > 0. if so, run commands. | |
| 138 */ | |
| 139 void | |
| 140 init_file() | |
| 141 { | |
| 106 | 142 /* most of this was taken from Bash v2.04 by the FSF */ |
| 143 struct stat finfo; | |
| 10256 | 144 char filename[256]; |
| 106 | 145 |
| 10256 | 146 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir()); |
| 106 | 147 |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10416
diff
changeset
|
148 if ((g_stat(filename, &finfo) == 0) && (finfo.st_size > 0)) |
| 106 | 149 run_commands(); |
| 150 } | |
| 151 | |
| 10256 | 152 /** |
| 153 * Check to see if we need to run commands from the file. | |
| 154 */ | |
| 155 gboolean | |
| 156 check_file() | |
| 157 { | |
| 106 | 158 /* most of this was taken from Bash v2.04 by the FSF */ |
| 159 struct stat finfo; | |
| 10256 | 160 char filename[256]; |
| 106 | 161 |
| 10256 | 162 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir()); |
| 106 | 163 |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10416
diff
changeset
|
164 if ((g_stat(filename, &finfo) == 0) && (finfo.st_size > 0)) |
| 7658 | 165 { |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
166 if (mtime != finfo.st_mtime) { |
| 10256 | 167 gaim_debug_info("filectl", "control changed, checking\n"); |
| 106 | 168 run_commands(); |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
169 } |
| 7658 | 170 } |
| 171 | |
| 172 return TRUE; | |
| 106 | 173 } |
| 174 | |
| 10256 | 175 char * |
| 176 getarg(char *line, int which, int remain) | |
| 177 { | |
| 106 | 178 char *arr; |
| 179 char *val; | |
| 180 int count = -1; | |
| 181 int i; | |
| 182 int state = 0; | |
| 183 | |
| 184 for (i = 0; i < strlen(line) && count < which; i++) { | |
| 185 switch (state) { | |
| 186 case 0: /* in whitespace, expecting word */ | |
| 187 if (isalnum(line[i])) { | |
| 188 count++; | |
| 189 state = 1; | |
| 190 } | |
| 191 break; | |
| 192 case 1: /* inside word, waiting for whitespace */ | |
| 193 if (isspace(line[i])) { | |
| 194 state = 0; | |
| 195 } | |
| 196 break; | |
| 197 } | |
| 198 } | |
| 199 | |
| 200 arr = strdup(&line[i - 1]); | |
| 201 if (remain) | |
| 202 return arr; | |
| 203 | |
| 204 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); | |
| 205 arr[i] = 0; | |
| 206 val = strdup(arr); | |
| 207 arr[i] = ' '; | |
| 208 free(arr); | |
| 209 return val; | |
| 210 } | |
| 10256 | 211 |
| 5255 | 212 /* |
| 213 * EXPORTED FUNCTIONS | |
| 214 */ | |
| 215 | |
| 216 static gboolean | |
| 217 plugin_load(GaimPlugin *plugin) | |
| 218 { | |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10744
diff
changeset
|
219 gaim_debug_register_category("filectl"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10744
diff
changeset
|
220 |
| 5255 | 221 init_file(); |
| 10256 | 222 check = gaim_timeout_add(5000, (GSourceFunc)check_file, NULL); |
| 5255 | 223 |
| 224 return TRUE; | |
| 225 } | |
| 226 | |
| 227 static gboolean | |
| 228 plugin_unload(GaimPlugin *plugin) | |
| 229 { | |
| 10256 | 230 gaim_timeout_remove(check); |
| 5255 | 231 |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10744
diff
changeset
|
232 gaim_debug_unregister_category("filectl"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10744
diff
changeset
|
233 |
| 5255 | 234 return TRUE; |
| 235 } | |
| 236 | |
| 237 static GaimPluginInfo info = | |
| 238 { | |
| 9954 | 239 GAIM_PLUGIN_MAGIC, |
| 240 GAIM_MAJOR_VERSION, | |
| 241 GAIM_MINOR_VERSION, | |
| 5255 | 242 GAIM_PLUGIN_STANDARD, /**< type */ |
| 243 NULL, /**< ui_requirement */ | |
| 244 0, /**< flags */ | |
| 245 NULL, /**< dependencies */ | |
| 246 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 247 | |
| 248 FILECTL_PLUGIN_ID, /**< id */ | |
| 249 N_("Gaim File Control"), /**< name */ | |
| 250 VERSION, /**< version */ | |
| 251 /** summary */ | |
| 252 N_("Allows you to control Gaim by entering commands in a file."), | |
| 253 /** description */ | |
| 254 N_("Allows you to control Gaim by entering commands in a file."), | |
| 255 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */ | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6179
diff
changeset
|
256 GAIM_WEBSITE, /**< homepage */ |
| 5255 | 257 |
| 258 plugin_load, /**< load */ | |
| 259 plugin_unload, /**< unload */ | |
| 260 NULL, /**< destroy */ | |
| 261 | |
| 262 NULL, /**< ui_info */ | |
| 263 NULL /**< extra_info */ | |
| 264 }; | |
| 265 | |
| 266 static void | |
|
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
267 init_plugin(GaimPlugin *plugin) |
| 5255 | 268 { |
| 269 } | |
| 270 | |
| 6063 | 271 GAIM_INIT_PLUGIN(filectl, init_plugin, info) |
