No issues found
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 cmd = g_string_new ("nautilus-sendto");
45
46 for (scan = files; scan; scan = scan->next) {
47 NautilusFileInfo *file = scan->data;
48
49 uri = nautilus_file_info_get_uri (file);
50 g_string_append_printf (cmd, " \"%s\"", uri);
51 g_free (uri);
52 }
53
54 g_spawn_command_line_async (cmd->str, NULL);
55
56 g_string_free (cmd, TRUE);
57 }
58
59 static GList *
60 nautilus_nste_get_file_items (NautilusMenuProvider *provider,
61 GtkWidget *window,
62 GList *files)
63 {
64 GList *items = NULL;
65 gboolean one_item;
66 NautilusMenuItem *item;
67 NautilusNste *nste;
68
69 nste = NAUTILUS_NSTE (provider);
70 if (!nste->nst_present)
71 return NULL;
72
73 if (files == NULL)
74 return NULL;
75
76 one_item = (files != NULL) && (files->next == NULL);
77 if (one_item &&
78 !nautilus_file_info_is_directory ((NautilusFileInfo *)files->data)) {
79 item = nautilus_menu_item_new ("NautilusNste::sendto",
80 _("Send To..."),
81 _("Send file by mail, instant message..."),
82 "document-send");
83 } else {
84 item = nautilus_menu_item_new ("NautilusNste::sendto",
85 _("Send To..."),
86 _("Send files by mail, instant message..."),
87 "document-send");
88 }
89 g_signal_connect (item,
90 "activate",
91 G_CALLBACK (sendto_callback),
92 provider);
93 g_object_set_data_full (G_OBJECT (item),
94 "files",
95 nautilus_file_info_list_copy (files),
96 (GDestroyNotify) nautilus_file_info_list_free);
97
98 items = g_list_append (items, item);
99
100 return items;
101 }
102
103 static void
104 nautilus_nste_menu_provider_iface_init (NautilusMenuProviderIface *iface)
105 {
106 iface->get_file_items = nautilus_nste_get_file_items;
107 }
108
109 static void
110 nautilus_nste_instance_init (NautilusNste *nste)
111 {
112 char *path;
113
114 path = g_find_program_in_path ("nautilus-sendto");
115 nste->nst_present = (path != NULL);
116 g_free (path);
117 }
118
119 static void
120 nautilus_nste_class_init (NautilusNsteClass *class)
121 {
122 parent_class = g_type_class_peek_parent (class);
123 }
124
125 static GType nste_type = 0;
126
127 GType
128 nautilus_nste_get_type (void)
129 {
130 return nste_type;
131 }
132
133 void
134 nautilus_nste_register_type (GTypeModule *module)
135 {
136 static const GTypeInfo info = {
137 sizeof (NautilusNsteClass),
138 (GBaseInitFunc) NULL,
139 (GBaseFinalizeFunc) NULL,
140 (GClassInitFunc) nautilus_nste_class_init,
141 NULL,
142 NULL,
143 sizeof (NautilusNste),
144 0,
145 (GInstanceInitFunc) nautilus_nste_instance_init,
146 };
147
148 static const GInterfaceInfo menu_provider_iface_info = {
149 (GInterfaceInitFunc) nautilus_nste_menu_provider_iface_init,
150 NULL,
151 NULL
152 };
153
154 nste_type = g_type_module_register_type (module,
155 G_TYPE_OBJECT,
156 "NautilusNste",
157 &info, 0);
158
159 g_type_module_add_interface (module,
160 nste_type,
161 NAUTILUS_TYPE_MENU_PROVIDER,
162 &menu_provider_iface_info);
163 }