~ubuntu-branches/ubuntu/wily/nautilus-sendto/wily

« back to all changes in this revision

Viewing changes to src/nautilus-nste.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-07-07 11:48:32 UTC
  • mfrom: (2.2.11 sid)
  • Revision ID: package-import@ubuntu.com-20140707114832-05jaedc7yfmq6z5j
Tags: 3.8.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control.in:
  - Don't rename thunderbird in icedove in Ubuntu 
  - set the epoch number for nautilus in Ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Nautilus-sendto 
3
 
 * 
4
 
 *  Copyright (C) 2004 Free Software Foundation, Inc.
5
 
 *
6
 
 *  This library is free software; you can redistribute it and/or
7
 
 *  modify it under the terms of the GNU General Public
8
 
 *  License as published by the Free Software Foundation; either
9
 
 *  version 2 of the License, or (at your option) any later version.
10
 
 *
11
 
 *  This library 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
 
 *  Library General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public
17
 
 *  License along with this library; if not, write to the Free
18
 
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
 
 *
20
 
 *  Author: Roberto Majadas <roberto.majadas@openshine.com> 
21
 
 * 
22
 
 */
23
 
 
24
 
#include <config.h>
25
 
#include <string.h>
26
 
#include <glib/gi18n-lib.h>
27
 
#include <libnautilus-extension/nautilus-extension-types.h>
28
 
#include <libnautilus-extension/nautilus-file-info.h>
29
 
#include <libnautilus-extension/nautilus-menu-provider.h>
30
 
#include "nautilus-nste.h"
31
 
 
32
 
 
33
 
static GObjectClass *parent_class;
34
 
 
35
 
static void
36
 
sendto_callback (NautilusMenuItem *item,
37
 
              gpointer          user_data)
38
 
{
39
 
        GList            *files, *scan;
40
 
        gchar            *uri;
41
 
        GString          *cmd;
42
 
 
43
 
        files = g_object_get_data (G_OBJECT (item), "files");
44
 
 
45
 
        cmd = g_string_new ("nautilus-sendto");
46
 
 
47
 
        for (scan = files; scan; scan = scan->next) {
48
 
                NautilusFileInfo *file = scan->data;
49
 
 
50
 
                uri = nautilus_file_info_get_uri (file);
51
 
                g_string_append_printf (cmd, " \"%s\"", uri);
52
 
                g_free (uri);
53
 
        }
54
 
 
55
 
        g_spawn_command_line_async (cmd->str, NULL);
56
 
 
57
 
        g_string_free (cmd, TRUE);
58
 
}
59
 
 
60
 
static GList *
61
 
nautilus_nste_get_file_items (NautilusMenuProvider *provider,
62
 
                              GtkWidget            *window,
63
 
                              GList                *files)
64
 
{
65
 
        GList    *items = NULL;
66
 
        GList    *scan;
67
 
        gboolean  one_item;
68
 
        NautilusMenuItem *item;
69
 
 
70
 
        if (files == NULL)
71
 
                return NULL;
72
 
 
73
 
        for (scan = files; scan; scan = scan->next) {
74
 
                NautilusFileInfo *file = scan->data;
75
 
                gchar            *scheme;
76
 
                gboolean          local;
77
 
 
78
 
                scheme = nautilus_file_info_get_uri_scheme (file);
79
 
                local = strncmp (scheme, "file", 4) == 0;
80
 
                g_free (scheme);
81
 
 
82
 
                if (!local)
83
 
                        return NULL;
84
 
        }
85
 
 
86
 
        one_item = (files != NULL) && (files->next == NULL);
87
 
        if (one_item && 
88
 
            !nautilus_file_info_is_directory ((NautilusFileInfo *)files->data)) {
89
 
                item = nautilus_menu_item_new ("NautilusNste::sendto",
90
 
                                               _("Send To..."),
91
 
                                               _("Send file by mail, instant message..."),
92
 
                                               "document-send");
93
 
        } else {
94
 
                item = nautilus_menu_item_new ("NautilusNste::sendto",
95
 
                                               _("Send To..."),
96
 
                                               _("Send files by mail, instant message..."),
97
 
                                               "document-send");
98
 
        }
99
 
  g_signal_connect (item, 
100
 
      "activate",
101
 
      G_CALLBACK (sendto_callback),
102
 
      provider);
103
 
  g_object_set_data_full (G_OBJECT (item), 
104
 
      "files",
105
 
      nautilus_file_info_list_copy (files),
106
 
      (GDestroyNotify) nautilus_file_info_list_free);
107
 
 
108
 
  items = g_list_append (items, item);
109
 
 
110
 
        return items;
111
 
}
112
 
 
113
 
 
114
 
static void 
115
 
nautilus_nste_menu_provider_iface_init (NautilusMenuProviderIface *iface)
116
 
{
117
 
        iface->get_file_items = nautilus_nste_get_file_items;
118
 
}
119
 
 
120
 
 
121
 
static void 
122
 
nautilus_nste_instance_init (NautilusNste *nste)
123
 
{
124
 
}
125
 
 
126
 
 
127
 
static void
128
 
nautilus_nste_class_init (NautilusNsteClass *class)
129
 
{
130
 
        parent_class = g_type_class_peek_parent (class);
131
 
}
132
 
 
133
 
 
134
 
static GType nste_type = 0;
135
 
 
136
 
 
137
 
GType
138
 
nautilus_nste_get_type (void) 
139
 
{
140
 
        return nste_type;
141
 
}
142
 
 
143
 
 
144
 
void
145
 
nautilus_nste_register_type (GTypeModule *module)
146
 
{
147
 
        static const GTypeInfo info = {
148
 
                sizeof (NautilusNsteClass),
149
 
                (GBaseInitFunc) NULL,
150
 
                (GBaseFinalizeFunc) NULL,
151
 
                (GClassInitFunc) nautilus_nste_class_init,
152
 
                NULL, 
153
 
                NULL,
154
 
                sizeof (NautilusNste),
155
 
                0,
156
 
                (GInstanceInitFunc) nautilus_nste_instance_init,
157
 
        };
158
 
 
159
 
        static const GInterfaceInfo menu_provider_iface_info = {
160
 
                (GInterfaceInitFunc) nautilus_nste_menu_provider_iface_init,
161
 
                NULL,
162
 
                NULL
163
 
        };
164
 
 
165
 
        nste_type = g_type_module_register_type (module,
166
 
                                                 G_TYPE_OBJECT,
167
 
                                                 "NautilusNste",
168
 
                                                 &info, 0);
169
 
 
170
 
        g_type_module_add_interface (module,
171
 
                                     nste_type,
172
 
                                     NAUTILUS_TYPE_MENU_PROVIDER,
173
 
                                     &menu_provider_iface_info);
174
 
}