60
57
static guint take_spool_files_handler;
61
58
static gboolean taking_files;
62
static GString *buddies_str;
59
static GString *buddies_str = NULL;
62
get_buddies_path (void)
64
return g_build_filename (g_get_home_dir(), PLUGIN_HOME, B_ONLINE, NULL);
65
68
get_online_buddies (PurpleBlistNode *node, GString *str){
71
for (aux = node ; aux != NULL ;aux = aux->next){
72
if (PURPLE_BLIST_NODE_IS_BUDDY(aux)){
74
buddy = (PurpleBuddy*)aux;
75
if (PURPLE_BUDDY_IS_ONLINE(buddy)){
78
if (buddy->alias == NULL){
79
if (buddy->server_alias == NULL){
80
alias = g_strdup (buddy->name);
82
alias = g_strdup (buddy->server_alias);
85
alias = g_strdup (buddy->alias);
88
g_string_append_printf (str,"%s\n%s\n%s\n%s\n",
89
buddy->account->username,
92
buddy->account->protocol_id);
97
get_online_buddies (aux->child, str);
104
save_online_buddies (PurpleBuddy *buddy, gpointer data){
105
PurpleBuddyList *blist;
110
fd_name = g_build_path ("/", g_get_home_dir(), PLUGIN_HOME,
113
blist = purple_get_blist();
114
str = g_string_new ("---\n");
115
get_online_buddies (blist->root, str);
116
str = g_string_append (str, "---\n");
118
if (!g_string_equal (buddies_str, str)){
120
if (g_file_set_contents (fd_name, str->str, str->len, &err) == FALSE) {
121
purple_debug_info ("nautilus", "couldn't save '%s': %s\n", fd_name, err->message);
123
g_string_free (buddies_str, TRUE);
125
purple_debug_info ("nautilus", "saved blist online\n");
126
g_string_free (buddies_str, TRUE);
130
g_string_free (str, TRUE);
131
purple_debug_info ("nautilus", "don't save blist online. No change\n");
138
init_plugin_stuff (){
142
plugin_home = g_build_path ("/", g_get_home_dir(),
145
if (!g_file_test (plugin_home,G_FILE_TEST_IS_DIR)){
146
mkdir (plugin_home, 0755);
147
purple_debug_info ("nautilus", "creating: %s\n",plugin_home);
149
g_free (plugin_home);
150
spool = g_build_path ("/", g_get_home_dir(), PLUGIN_HOME, "spool", NULL);
151
if (!g_file_test (spool,G_FILE_TEST_IS_DIR)){
153
purple_debug_info ("nautilus", "creating: %s\n", spool);
156
spool_tmp = g_build_path ("/", g_get_home_dir(), PLUGIN_HOME, "spool", "tmp", NULL);
157
if (!g_file_test (spool_tmp,G_FILE_TEST_IS_DIR)){
158
mkdir (spool_tmp, 0755);
159
purple_debug_info ("nautilus", "creating: %s\n", spool_tmp);
75
for (aux = node ; aux != NULL ;aux = aux->next) {
76
if (PURPLE_BLIST_NODE_IS_BUDDY(aux)){
78
buddy = (PurpleBuddy*)aux;
79
if (PURPLE_BUDDY_IS_ONLINE(buddy)){
82
if (buddy->alias == NULL){
83
if (buddy->server_alias == NULL){
84
alias = g_strdup (buddy->name);
86
alias = g_strdup (buddy->server_alias);
89
alias = g_strdup (buddy->alias);
92
g_string_append_printf (str,"%s\n%s\n%s\n%s\n",
93
buddy->account->username,
96
buddy->account->protocol_id);
101
get_online_buddies (aux->child, str);
107
save_online_buddies (PurpleBuddy *buddy, gpointer data)
109
PurpleBuddyList *blist;
113
fd_name = get_buddies_path ();
115
blist = purple_get_blist();
116
str = g_string_new ("---\n");
117
get_online_buddies (blist->root, str);
118
str = g_string_append (str, "---\n");
120
if (!g_string_equal (buddies_str, str)) {
122
if (g_file_set_contents (fd_name, str->str, str->len, &err) == FALSE) {
123
purple_debug_info ("nautilus", "couldn't save '%s': %s\n", fd_name, err->message);
125
g_string_free (str, TRUE);
127
purple_debug_info ("nautilus", "saved blist online\n");
128
g_string_free (buddies_str, TRUE);
132
g_string_free (str, TRUE);
133
purple_debug_info ("nautilus", "don't save blist online. No change\n");
139
init_plugin_stuff (void)
144
spool_tmp = g_build_filename (g_get_home_dir(), PLUGIN_HOME, "spool", "tmp", NULL);
145
if (g_mkdir_with_parents (spool_tmp, 0755) < 0) {
147
g_warning ("Failed to create '%s': %s", spool_tmp, g_strerror (error));
165
159
send_file (GString *username, GString *cname,
166
GString *protocol, GString *file){
168
PurpleAccount *account;
171
account = purple_accounts_find (username->str, protocol->str);
175
serv_send_file (account->gc, cname->str, file->str);
160
GString *protocol, GString *file)
162
PurpleAccount *account;
164
account = purple_accounts_find (username->str, protocol->str);
168
serv_send_file (account->gc, cname->str, file->str);
179
process_file (gchar *file){
184
GString *file_to_send;
186
username = g_string_new ("");
187
cname = g_string_new ("");
188
protocol = g_string_new ("");
189
file_to_send = g_string_new ("");
191
io = g_io_channel_new_file (file,"r",NULL);
195
purple_debug_info ("nautilus","Open spool file : %s\n",file);
196
g_io_channel_read_line_string (io, username, NULL, NULL);
197
username = g_string_truncate (username, username->len - 1);
198
g_io_channel_read_line_string (io, cname, NULL, NULL);
199
cname = g_string_truncate (cname, cname->len - 1);
200
g_io_channel_read_line_string (io, protocol, NULL, NULL);
201
protocol = g_string_truncate (protocol, protocol->len - 1);
203
while (G_IO_STATUS_EOF !=
204
g_io_channel_read_line_string (io,file_to_send,
207
if (file_to_send->len <=1)
209
file_to_send = g_string_truncate (file_to_send,
210
file_to_send->len - 1);
211
send_file (username, cname,
212
protocol, file_to_send);
215
g_string_free (username, TRUE);
216
g_string_free (cname, TRUE);
217
g_string_free (protocol, TRUE);
218
g_string_free (file_to_send, TRUE);
219
g_io_channel_shutdown (io, TRUE, NULL);
172
process_file (const char *file)
178
GString *file_to_send;
180
username = g_string_new ("");
181
cname = g_string_new ("");
182
protocol = g_string_new ("");
183
file_to_send = g_string_new ("");
185
io = g_io_channel_new_file (file,"r",NULL);
189
purple_debug_info ("nautilus","Open spool file : %s\n",file);
190
g_io_channel_read_line_string (io, username, NULL, NULL);
191
username = g_string_truncate (username, username->len - 1);
192
g_io_channel_read_line_string (io, cname, NULL, NULL);
193
cname = g_string_truncate (cname, cname->len - 1);
194
g_io_channel_read_line_string (io, protocol, NULL, NULL);
195
protocol = g_string_truncate (protocol, protocol->len - 1);
197
while (G_IO_STATUS_EOF != g_io_channel_read_line_string (io,file_to_send, NULL, NULL)) {
198
if (file_to_send->len <=1)
200
file_to_send = g_string_truncate (file_to_send,
201
file_to_send->len - 1);
202
send_file (username, cname,
203
protocol, file_to_send);
206
g_string_free (username, TRUE);
207
g_string_free (cname, TRUE);
208
g_string_free (protocol, TRUE);
209
g_string_free (file_to_send, TRUE);
210
g_io_channel_shutdown (io, TRUE, NULL);
229
if (taking_files == FALSE){
231
plugin_spool = g_build_path ("/", g_get_home_dir(),PLUGIN_HOME,"spool", NULL);
232
dir = opendir (plugin_spool);
233
g_free (plugin_spool);
235
purple_debug_info ("nautilus","Can't open the spool dir\n");
237
while (ep = readdir(dir)){
240
if ((strcmp (ep->d_name,".")==0) ||
241
(strcmp (ep->d_name, "..")==0) ||
242
(strcmp (ep->d_name, "tmp")==0))
245
file = g_build_path ("/", g_get_home_dir(),
253
taking_files = FALSE;
215
take_spool_files (gpointer user_data)
219
if (taking_files == FALSE)
225
plugin_spool = g_build_filename (g_get_home_dir(), PLUGIN_HOME, "spool", NULL);
226
dir = g_dir_open (plugin_spool, 0, &err);
227
g_free (plugin_spool);
229
purple_debug_info ("nautilus","Can't open the spool dir: %s\n", err->message);
232
const char *filename;
234
filename = g_dir_read_name (dir);
238
if (g_str_equal (filename, "tmp")) {
239
filename = g_dir_read_name (dir);
243
file = g_build_filename (g_get_home_dir(),
244
PLUGIN_HOME, "spool",
249
filename = g_dir_read_name (dir);
253
taking_files = FALSE;
259
plugin_load(PurplePlugin *plugin)
259
plugin_load (PurplePlugin *plugin)
261
261
void *blist_handle;
263
init_plugin_stuff ();
263
if (init_plugin_stuff () == FALSE)
264
265
buddies_str = g_string_new ("");
266
267
blist_handle = purple_blist_get_handle();
289
fd_name = g_build_path ("/", g_get_home_dir(), PLUGIN_HOME,
291
purple_timeout_remove (take_spool_files_handler);
294
g_string_free (buddies_str, TRUE);
295
purple_debug_info ("nautilus", "Stop nautilus plugin\n");
285
plugin_unload (PurplePlugin *plugin)
290
blist_handle = purple_blist_get_handle();
292
purple_signal_disconnect (blist_handle, "buddy-signed-on",
293
plugin, (PurpleCallback) save_online_buddies);
294
purple_signal_disconnect (blist_handle, "buddy-signed-off",
295
plugin, (PurpleCallback) save_online_buddies);
297
fd_name = get_buddies_path ();
298
purple_timeout_remove (take_spool_files_handler);
301
g_string_free (buddies_str, TRUE);
303
purple_debug_info ("nautilus", "Stop nautilus plugin\n");
301
309
force_load_once (gpointer data)
303
PurplePlugin *plugin = (PurplePlugin *)data;
304
if (!purple_prefs_get_bool ("/plugins/gtk/nautilus/auto_loaded")) {
305
purple_debug_info ("nautilus", "Force loading nautilus plugin\n");
306
purple_plugin_load (plugin);
311
PurplePlugin *plugin = (PurplePlugin *)data;
313
if (!purple_prefs_get_bool ("/plugins/gtk/nautilus/auto_loaded")) {
314
purple_debug_info ("nautilus", "Force loading nautilus plugin\n");
315
purple_plugin_load (plugin);
307
316
purple_plugins_save_loaded (PIDGIN_PREFS_ROOT "/plugins/loaded");
308
purple_prefs_set_bool ("/plugins/gtk/nautilus/auto_loaded", TRUE);
317
purple_prefs_set_bool ("/plugins/gtk/nautilus/auto_loaded", TRUE);
315
init_plugin(PurplePlugin *plugin) {
316
purple_prefs_add_none ("/plugins/gtk/nautilus");
317
purple_prefs_add_bool ("/plugins/gtk/nautilus/auto_loaded", FALSE);
324
init_plugin(PurplePlugin *plugin)
326
purple_prefs_add_none ("/plugins/gtk/nautilus");
327
purple_prefs_add_bool ("/plugins/gtk/nautilus/auto_loaded", FALSE);
318
328
g_idle_add(force_load_once, plugin);
321
331
static PurplePluginInfo info = {
322
PURPLE_PLUGIN_MAGIC, /* api version */
323
PURPLE_MAJOR_VERSION,
324
PURPLE_MINOR_VERSION,
325
PURPLE_PLUGIN_STANDARD, /* type */
326
PIDGIN_PLUGIN_TYPE, /* ui requirement */
327
PURPLE_PRIORITY_DEFAULT, /* flags */
328
NULL, /* dependencies */
329
PURPLE_PRIORITY_DEFAULT, /* priority */
331
"gtk-nautilus", /* id */
332
N_("Nautilus Integration"), /* name */
334
N_("Provides integration with Nautilus"), /* summary */
335
N_("Provides integration with Nautilus"), /* description */
337
"Roberto Majadas <roberto.majadas@openshine.com>", /* author */
338
"www.gnome.org", /* homepage */
340
plugin_load, /* load */
341
plugin_unload, /* unload */
344
NULL, /* extra info */
345
NULL /* actions info */
332
PURPLE_PLUGIN_MAGIC, /* api version */
333
PURPLE_MAJOR_VERSION,
334
PURPLE_MINOR_VERSION,
335
PURPLE_PLUGIN_STANDARD, /* type */
336
PIDGIN_PLUGIN_TYPE, /* ui requirement */
337
PURPLE_PRIORITY_DEFAULT, /* flags */
338
NULL, /* dependencies */
339
PURPLE_PRIORITY_DEFAULT, /* priority */
341
"gtk-nautilus", /* id */
342
N_("Nautilus Integration"), /* name */
344
N_("Provides integration with Nautilus"), /* summary */
345
N_("Provides integration with Nautilus"), /* description */
347
"Roberto Majadas <roberto.majadas@openshine.com>", /* author */
348
"www.gnome.org", /* homepage */
350
plugin_load, /* load */
351
plugin_unload, /* unload */
354
NULL, /* extra info */
355
NULL /* actions info */
348
358
PURPLE_INIT_PLUGIN(nautilus, init_plugin, info)