annotate plugins/filectl.c @ 11016:6417b2f5de4e

[gaim-migrate @ 12885] Wherever possible, allow users to act on objects and data directly, rather than through dialogs or explicit commands. For example, it is more intuitive to drag a circle object around in a diagram rather than selecting a "Move" command from a menu while the circle is selected. Simlarly, in an email application, allow the user to attach files by dragging them from the file manager and dropping them onto the message composition window if they wish. -- GNOME HIG This allows direct manipulation of buddy aliases and group names, by moving the features from dialogs to GtkTreeView's inline editing. I think this is a great change, but it seems like the type of thing that might stir up controversy. If so, take it to the mailing list for discussion. If not, I'll go ahead and perfect this sometime later. -s. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Tue, 21 Jun 2005 04:40:34 +0000
parents 1b927566fcc4
children 50224ac8184d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
1 /**
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
2 * Send commands to Gaim via ~/.gaim/control
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
3 *
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
4 * Originally by Eric Warmenhoven <eric@warmenhoven.org>
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
5 * Compile fixes/mini hacks Alex Bennee <alex@bennee.com>
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
6 * and Brian Tarricone <bjt23@users.sourceforge.net>
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
7 */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
9 /* system includes */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #include <stdlib.h>
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
11 #include <stdio.h>
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 #include <unistd.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 #include <sys/types.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 #include <sys/stat.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 #include <string.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 #include <ctype.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
18 #include "account.h"
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
19 #include "config.h"
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
20 #include "core.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
21 #include "conversation.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
22 #include "debug.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
23 #include "eventloop.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
24 #include "internal.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
25 #include "util.h"
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9863
diff changeset
26 #include "version.h"
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
27
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
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
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
32 static void init_file();
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
33 static gboolean check_file();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 /* parse char * as if were word array */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 char *getarg(char *, int, int);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 /* go through file and run any commands */
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
39 void
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
40 run_commands()
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
41 {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 char filename[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 char buffer[1024];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 char *command, *arg1, *arg2;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 FILE *file;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
48 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir());
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10416
diff changeset
50 file = g_fopen(filename, "r+");
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
51 while (fgets(buffer, sizeof(buffer), file)) {
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
52
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
53 /* Read the next command */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 if (buffer[strlen(buffer) - 1] == '\n')
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 buffer[strlen(buffer) - 1] = 0;
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
56 gaim_debug_misc("filectl", "read: %s\n", buffer);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 command = getarg(buffer, 0, 0);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
58
10272
bf1ebc8f3bf3 [gaim-migrate @ 11421]
Mark Doliner <mark@kingant.net>
parents: 10256
diff changeset
59 if (!strncasecmp(command, "login", 6)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
60 GaimAccount *account;
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
61
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 arg1 = getarg(buffer, 1, 0);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 arg2 = getarg(buffer, 2, 1);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
64
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
65 account = gaim_accounts_find(arg1, arg2);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
66 if (account != NULL) /* username found */
10744
1b927566fcc4 [gaim-migrate @ 12346]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
67 gaim_account_connect(account);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
68
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
69 free(arg1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
70 free(arg2);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
71
10272
bf1ebc8f3bf3 [gaim-migrate @ 11421]
Mark Doliner <mark@kingant.net>
parents: 10256
diff changeset
72 } else if (!strncasecmp(command, "logout", 7)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
73 GaimAccount *account;
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
74
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
75 arg1 = getarg(buffer, 1, 1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
76 arg2 = getarg(buffer, 2, 1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
77
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
78 account = gaim_accounts_find(arg1, arg2);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
79 if (account != NULL)
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
80 {
10738
55af3fa46329 [gaim-migrate @ 12340]
Mark Doliner <mark@kingant.net>
parents: 10589
diff changeset
81 gaim_account_disconnect(account);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
82 }
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
83 else if (arg1 == NULL)
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
84 gaim_connections_disconnect_all();
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
85
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
86 free(arg1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
87 free(arg2);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
88
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
89 } else if (!strncasecmp(command, "send", 4)) {
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
90 GaimConversation *conv;
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
91
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
92 arg1 = getarg(buffer, 1, 0);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
93 arg2 = getarg(buffer, 2, 1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
94
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
95 conv = gaim_find_conversation(GAIM_CONV_ANY, arg1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
96 if (conv != NULL)
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
97 {
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
98 /*
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
99 gaim_conversation_write(conv, arg2, WFLAG_SEND, NULL, time(NULL), -1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
100 serv_send_im(conv->gc, arg1, arg2, 0);
9863
0e3a84f18467 [gaim-migrate @ 10742]
Mark Doliner <mark@kingant.net>
parents: 8749
diff changeset
101 */
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
102 }
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
103
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 free(arg1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 free(arg2);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
106
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 } else if (!strncasecmp(command, "away", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 arg1 = getarg(buffer, 1, 1);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
109 /* serv_set_away_all(arg1); */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 free(arg1);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
111
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
112 } else if (!strncasecmp(command, "hide", 4)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
113 gaim_blist_set_visible(FALSE);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
114
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
115 } else if (!strncasecmp(command, "unhide", 6)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
116 gaim_blist_set_visible(TRUE);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
117
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 } else if (!strncasecmp(command, "back", 4)) {
9863
0e3a84f18467 [gaim-migrate @ 10742]
Mark Doliner <mark@kingant.net>
parents: 8749
diff changeset
119 /* do_im_back(); */
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
120
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 } else if (!strncasecmp(command, "quit", 4)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
122 gaim_core_quit();
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
123
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 }
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
125
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 free(command);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 fclose(file);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10416
diff changeset
131 if (g_stat(filename, &finfo) != 0)
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 return;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 mtime = finfo.st_mtime;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
136 /**
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
137 * Check to see if the size of the file is > 0. if so, run commands.
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
138 */
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
139 void
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
140 init_file()
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
141 {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 struct stat finfo;
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
144 char filename[256];
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
146 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir());
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 run_commands();
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
152 /**
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
153 * Check to see if we need to run commands from the file.
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
154 */
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
155 gboolean
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
156 check_file()
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
157 {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 struct stat finfo;
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
160 char filename[256];
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
162 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir());
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
165 {
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
166 if (mtime != finfo.st_mtime) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
167 gaim_debug_info("filectl", "control changed, checking\n");
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 run_commands();
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
169 }
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
170 }
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
171
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
172 return TRUE;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
175 char *
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
176 getarg(char *line, int which, int remain)
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
177 {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 char *arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 char *val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 int count = -1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 int i;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 int state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 for (i = 0; i < strlen(line) && count < which; i++) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 switch (state) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 case 0: /* in whitespace, expecting word */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 if (isalnum(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 count++;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 state = 1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 case 1: /* inside word, waiting for whitespace */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 if (isspace(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200 arr = strdup(&line[i - 1]);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 if (remain)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202 return arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 arr[i] = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 val = strdup(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 arr[i] = ' ';
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 free(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 return val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 }
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
211
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
212 /*
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
213 * EXPORTED FUNCTIONS
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
214 */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
215
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
216 static gboolean
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
217 plugin_load(GaimPlugin *plugin)
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
218 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
219 init_file();
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
220 check = gaim_timeout_add(5000, (GSourceFunc)check_file, NULL);
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
221
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
222 return TRUE;
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
223 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
224
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
225 static gboolean
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
226 plugin_unload(GaimPlugin *plugin)
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
227 {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
228 gaim_timeout_remove(check);
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
229
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
230 return TRUE;
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
231 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
232
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
233 static GaimPluginInfo info =
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
234 {
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9863
diff changeset
235 GAIM_PLUGIN_MAGIC,
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9863
diff changeset
236 GAIM_MAJOR_VERSION,
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9863
diff changeset
237 GAIM_MINOR_VERSION,
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
238 GAIM_PLUGIN_STANDARD, /**< type */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
239 NULL, /**< ui_requirement */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
240 0, /**< flags */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
241 NULL, /**< dependencies */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
242 GAIM_PRIORITY_DEFAULT, /**< priority */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
243
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
244 FILECTL_PLUGIN_ID, /**< id */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
245 N_("Gaim File Control"), /**< name */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
246 VERSION, /**< version */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
247 /** summary */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
248 N_("Allows you to control Gaim by entering commands in a file."),
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
249 /** description */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
250 N_("Allows you to control Gaim by entering commands in a file."),
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
251 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */
6371
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6179
diff changeset
252 GAIM_WEBSITE, /**< homepage */
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
253
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
254 plugin_load, /**< load */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
255 plugin_unload, /**< unload */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
256 NULL, /**< destroy */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
257
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
258 NULL, /**< ui_info */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
259 NULL /**< extra_info */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
260 };
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
261
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
262 static void
5920
7d385de2f9cd [gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents: 5676
diff changeset
263 init_plugin(GaimPlugin *plugin)
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
264 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
265 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
266
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 6036
diff changeset
267 GAIM_INIT_PLUGIN(filectl, init_plugin, info)