1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4
* Copyright (C) 2004 Roberto Majadas
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of the
9
* License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more av.
16
* You should have received a copy of the GNU General Public
17
* License along with this program; if not, write to the
18
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301 USA.
21
* Author: Roberto Majadas <roberto.majadas@openshine.com>
26
#include <glib/gi18n-lib.h>
27
#include "nautilus-sendto-plugin.h"
29
static GList *contact_list;
30
static gchar *blist_online;
33
gboolean init (NstPlugin *plugin)
35
g_print ("Init gaim plugin\n");
38
blist_online = g_build_path ("/", g_get_home_dir(),
39
".gnome2/nautilus-sendto/buddies_online",
41
if (!g_file_test (blist_online, G_FILE_TEST_EXISTS)) {
42
g_free (blist_online);
50
add_gaim_contacts_to_model (GtkListStore *store, GtkTreeIter *iter)
52
GdkPixbuf *msn, *jabber, *yahoo, *aim;
59
io = g_io_channel_new_file (blist_online, "r", NULL);
63
str = g_string_new ("");
64
g_io_channel_read_line_string (io, str, NULL, NULL);
65
g_string_free (str, TRUE);
66
str = g_string_new ("");
67
while (G_IO_STATUS_EOF != g_io_channel_read_line_string (io, str,
70
str = g_string_truncate (str, str->len - 1);
71
list = g_list_prepend (list, str->str);
72
g_string_free (str, FALSE);
73
str = g_string_new ("");
75
g_string_free(str,TRUE);
76
g_io_channel_shutdown (io, TRUE, NULL);
78
list = g_list_reverse(list);
85
it = gtk_icon_theme_get_default ();
86
msn = gtk_icon_theme_load_icon (it, "im-msn", 16,
87
GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
88
jabber = gtk_icon_theme_load_icon (it, "im-jabber", 16,
89
GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
90
yahoo = gtk_icon_theme_load_icon (it, "im-yahoo", 16,
91
GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
92
aim = gtk_icon_theme_load_icon (it, "im-aim", 16,
93
GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
96
while (l->next != NULL){
97
gchar *prt, *username, *cname, *alias;
100
username = (gchar *) l->data; l = l->next;
101
cname = (gchar *) l->data; l = l->next;
102
alias = (gchar *) l->data; l = l->next;
103
prt = (gchar *) l->data; l = l->next;
105
alias_e = g_string_new (alias);
106
if (alias_e->len > 30){
107
alias_e = g_string_truncate (alias_e, 30);
108
alias_e = g_string_append (alias_e, "...");
111
contact_info = g_strdup_printf ("%s\n%s\n%s\n",
112
username, cname, prt);
113
if (strcmp(prt ,"prpl-msn")==0){
114
gtk_list_store_append (store, iter);
115
gtk_list_store_set (store, iter, 0,
116
msn, 1, alias_e->str, -1);
117
contact_list = g_list_append (contact_list, contact_info);
119
if (strcmp(prt,"prpl-jabber")==0){
120
gtk_list_store_append (store, iter);
121
gtk_list_store_set (store, iter, 0,
122
jabber, 1, alias_e->str, -1);
123
contact_list = g_list_append (contact_list, contact_info);
125
if (strcmp(prt,"prpl-oscar")==0){
126
gtk_list_store_append (store, iter);
127
gtk_list_store_set (store, iter, 0,
128
aim, 1, alias_e->str, -1);
129
contact_list = g_list_append (contact_list, contact_info);
131
if (strcmp(prt,"prpl-yahoo")==0){
132
gtk_list_store_append (store, iter);
133
gtk_list_store_set (store, iter, 0,
134
yahoo, 1, alias_e->str, -1);
135
contact_list = g_list_append (contact_list, contact_info);
137
g_free (contact_info);
139
g_string_free(alias_e, TRUE);
142
g_list_foreach (list, (GFunc)g_free, NULL);
147
GtkWidget* get_contacts_widget (NstPlugin *plugin)
150
GtkCellRenderer *renderer;
155
iter = g_malloc (sizeof(GtkTreeIter));
156
store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
157
add_gaim_contacts_to_model (store, iter);
159
model = GTK_TREE_MODEL (store);
160
cb = gtk_combo_box_new_with_model (model);
161
renderer = gtk_cell_renderer_pixbuf_new ();
162
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cb),
165
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cb),
169
renderer = gtk_cell_renderer_text_new ();
170
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cb),
173
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cb),
177
gtk_combo_box_set_active (GTK_COMBO_BOX (cb), 0);
182
gboolean send_files (NstPlugin *plugin, GtkWidget *contact_widget,
187
gchar *spool_file, *spool_file_send, *contact_info;
191
option = gtk_combo_box_get_active (GTK_COMBO_BOX(contact_widget));
192
contact_info = (gchar *) g_list_nth_data (contact_list, option);
193
gaimto = g_string_new (contact_info);
195
for (l = file_list ; l; l=l->next){
198
path = g_filename_from_uri (l->data, NULL, NULL);
199
g_string_append_printf (gaimto,"%s\n", path);
202
g_string_append_printf (gaimto,"\n");
204
spool_file = g_strdup_printf ("%s/.gnome2/nautilus-sendto/spool/tmp/%i.send",
205
g_get_home_dir(), t);
206
spool_file_send = g_strdup_printf ("%s/.gnome2/nautilus-sendto/spool/%i.send",
207
g_get_home_dir(), t);
208
fd = fopen (spool_file,"w");
209
fwrite (gaimto->str, 1, gaimto->len, fd);
211
rename (spool_file, spool_file_send);
213
g_free (spool_file_send);
218
gboolean destroy (NstPlugin *plugin){
219
g_free (blist_online);
220
g_list_foreach (contact_list, (GFunc)g_free, NULL);
225
NstPluginInfo plugin_info = {
228
N_("Instant Message (Gaim)"),
238
NST_INIT_PLUGIN (plugin_info)