~ubuntu-branches/ubuntu/raring/nautilus-sendto-universe/raring

« back to all changes in this revision

Viewing changes to src/plugins/gaim/gaim.c

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-07-30 23:31:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730233120-ut3baoo6lde6q9gk
Tags: 1.1.6-0ubuntu1
* New upstream release. (LP: #377192)
* debian/control
  - Remove libglade2-dev build dependency.
  - Bump version of libgtk2.0-dev build dependency to 2.12.
  - Remove empathy related build dependencies.
  - Update description to remove empathy references.
* debian/nautilus-sendto-universe.install
  - Remove empathy plugin.
* debian/patches/10_fix_empathy_2.26.patch
  - Remove. Not needed anymore.
* debian/README.Debian.
  - Update to remove empathy references.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
 
3
 
/* 
4
 
 * Copyright (C) 2004 Roberto Majadas
5
 
 * 
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.
10
 
 *
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.
15
 
 *
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.
20
 
 *
21
 
 * Author:  Roberto Majadas <roberto.majadas@openshine.com>
22
 
 */
23
 
 
24
 
#include "config.h"
25
 
#include <string.h>
26
 
#include <glib/gi18n-lib.h>
27
 
#include "nautilus-sendto-plugin.h"
28
 
 
29
 
static GList *contact_list;
30
 
static gchar *blist_online;
31
 
 
32
 
static 
33
 
gboolean init (NstPlugin *plugin)
34
 
{
35
 
        g_print ("Init gaim plugin\n");
36
 
        contact_list = NULL;
37
 
 
38
 
        blist_online = g_build_path ("/", g_get_home_dir(),
39
 
                                     ".gnome2/nautilus-sendto/buddies_online",
40
 
                                     NULL);
41
 
        if (!g_file_test (blist_online, G_FILE_TEST_EXISTS)) {
42
 
                g_free (blist_online);
43
 
                blist_online = NULL;
44
 
                return FALSE;
45
 
        }
46
 
        return TRUE;
47
 
}
48
 
 
49
 
static void
50
 
add_gaim_contacts_to_model (GtkListStore *store, GtkTreeIter *iter)
51
 
{
52
 
        GdkPixbuf *msn, *jabber, *yahoo, *aim;
53
 
        GtkIconTheme *it;
54
 
        GList *list = NULL;
55
 
        GList *l;
56
 
        gchar *contact_info;
57
 
        GIOChannel *io; 
58
 
 
59
 
        io = g_io_channel_new_file (blist_online, "r", NULL);
60
 
 
61
 
        if (io != NULL){
62
 
                GString *str;
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, 
68
 
                                                                  NULL, NULL))
69
 
                {
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 ("");
74
 
                }
75
 
                g_string_free(str,TRUE);
76
 
                g_io_channel_shutdown (io, TRUE, NULL);         
77
 
                if (list != NULL)
78
 
                        list = g_list_reverse(list);
79
 
                else
80
 
                        return;
81
 
                
82
 
        }else
83
 
                return;
84
 
        
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);
94
 
                
95
 
        l = list;
96
 
        while (l->next != NULL){
97
 
                gchar *prt, *username, *cname, *alias;
98
 
                GString *alias_e;
99
 
                
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;
104
 
                
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, "...");
109
 
                }
110
 
                
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);
118
 
                }else
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);
124
 
                  }else
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);
130
 
                    }else
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);
136
 
                      }else{
137
 
                              g_free (contact_info);
138
 
                      }
139
 
                g_string_free(alias_e, TRUE);
140
 
        }
141
 
        
142
 
        g_list_foreach (list, (GFunc)g_free, NULL);
143
 
        g_list_free (list);
144
 
}
145
 
 
146
 
static
147
 
GtkWidget* get_contacts_widget (NstPlugin *plugin)
148
 
{
149
 
        GtkWidget *cb;
150
 
        GtkCellRenderer *renderer;
151
 
        GtkListStore *store;
152
 
        GtkTreeModel *model;
153
 
        GtkTreeIter *iter;
154
 
 
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);
158
 
        g_free (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),
163
 
                                    renderer,
164
 
                                    FALSE);
165
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cb), 
166
 
                                        renderer,
167
 
                                        "pixbuf", 0,
168
 
                                        NULL);          
169
 
        renderer = gtk_cell_renderer_text_new ();
170
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cb),
171
 
                                    renderer,
172
 
                                    TRUE);
173
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cb), 
174
 
                                        renderer,
175
 
                                        "text", 1,
176
 
                                        NULL);
177
 
        gtk_combo_box_set_active (GTK_COMBO_BOX (cb), 0);
178
 
        return cb;
179
 
}
180
 
 
181
 
static
182
 
gboolean send_files (NstPlugin *plugin, GtkWidget *contact_widget,
183
 
                         GList *file_list)
184
 
{
185
 
        GString *gaimto;        
186
 
        GList *l;
187
 
        gchar *spool_file, *spool_file_send, *contact_info;
188
 
        FILE *fd;
189
 
        gint t, option;
190
 
 
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);
194
 
        
195
 
        for (l = file_list ; l; l=l->next){
196
 
                char *path;
197
 
 
198
 
                path = g_filename_from_uri (l->data, NULL, NULL);
199
 
                g_string_append_printf (gaimto,"%s\n", path);
200
 
                g_free (path);
201
 
        }
202
 
        g_string_append_printf (gaimto,"\n");
203
 
        t = time (NULL);
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);
210
 
        fclose (fd);
211
 
        rename (spool_file, spool_file_send);
212
 
        g_free (spool_file);
213
 
        g_free (spool_file_send);
214
 
        return TRUE;
215
 
}
216
 
 
217
 
static 
218
 
gboolean destroy (NstPlugin *plugin){
219
 
        g_free (blist_online);
220
 
        g_list_foreach (contact_list, (GFunc)g_free, NULL);
221
 
        return TRUE;
222
 
}
223
 
 
224
 
static 
225
 
NstPluginInfo plugin_info = {
226
 
        "im",
227
 
        "gaim",
228
 
        N_("Instant Message (Gaim)"),
229
 
        FALSE,
230
 
        FALSE,
231
 
        init,
232
 
        get_contacts_widget,
233
 
        NULL,
234
 
        send_files,
235
 
        destroy
236
 
}; 
237
 
 
238
 
NST_INIT_PLUGIN (plugin_info)
239
 
 
240