1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /*
4 * Copyright (C) 2008 Jader Henrique da Silva
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: Jader Henrique da Silva <vovozito@gmail.com>
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <glib/gi18n-lib.h>
29
30 #include <string.h>
31 #include "nst-common.h"
32 #include "caja-sendto-plugin.h"
33
34 enum {
35 COL_PIXBUF,
36 COL_LABEL,
37 NUM_COLS,
38 };
39
40 #define COMBOBOX_OPTION_NEW_DVD 0
41 #define COMBOBOX_OPTION_EXISTING_DVD 1
42
43 static GFile *burn = NULL;
44
45 static
init(NstPlugin * plugin)46 gboolean init (NstPlugin *plugin)
47 {
48 GtkIconTheme *it;
49 char *cmd;
50
51 g_print ("Init caja burn plugin\n");
52
53 it = gtk_icon_theme_get_default ();
54 gtk_icon_theme_append_search_path (it, DATADIR "/brasero/icons");
55
56 cmd = g_find_program_in_path ("brasero");
57 if (cmd == NULL)
58 return FALSE;
59 g_free (cmd);
60
61 burn = g_file_new_for_uri ("burn:/");
62
63 return TRUE;
64 }
65
66 static
get_contacts_widget(NstPlugin * plugin)67 GtkWidget* get_contacts_widget (NstPlugin *plugin)
68 {
69 GtkWidget *widget;
70 GtkCellRenderer *renderer;
71 GtkListStore *store;
72 GtkTreeModel *model;
73 GFileEnumerator *fenum;
74 GFileInfo *file_info = NULL;
75 int selection = COMBOBOX_OPTION_NEW_DVD;
76
77 fenum = g_file_enumerate_children (burn,
78 G_FILE_ATTRIBUTE_STANDARD_NAME,
79 G_FILE_QUERY_INFO_NONE,
80 NULL,
81 NULL);
82
83 if (fenum != NULL) {
84 file_info = g_file_enumerator_next_file (fenum, NULL, NULL);
85 g_object_unref (fenum);
86 }
87
88 store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING);
89
90 gtk_list_store_insert_with_values (store, NULL,
91 INT_MAX,
92 COL_PIXBUF, "media-optical-blank",
93 COL_LABEL, _("New CD/DVD"),
94 -1);
95
96 if (file_info != NULL) {
97 gtk_list_store_insert_with_values (store, NULL,
98 INT_MAX,
99 COL_PIXBUF, "media-optical-data-new",
100 COL_LABEL, _("Existing CD/DVD"),
101 -1);
102 g_object_unref (file_info);
103 selection = COMBOBOX_OPTION_EXISTING_DVD;
104 }
105
106 model = GTK_TREE_MODEL (store);
107 widget = gtk_combo_box_new_with_model (model);
108 renderer = gtk_cell_renderer_pixbuf_new ();
109 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget),
110 renderer,
111 FALSE);
112 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget),
113 renderer,
114 "icon-name", COL_PIXBUF,
115 NULL);
116 renderer = gtk_cell_renderer_text_new ();
117 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget),
118 renderer,
119 TRUE);
120 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget),
121 renderer,
122 "text", COL_LABEL,
123 NULL);
124
125 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), selection);
126
127 return widget;
128 }
129
130 static
send_files(NstPlugin * plugin,GtkWidget * burntype_widget,GList * file_list)131 gboolean send_files (NstPlugin *plugin,
132 GtkWidget *burntype_widget,
133 GList *file_list)
134 {
135 GFileEnumerator *fenum;
136 GFileInfo *file_info;
137 GFile *child;
138
139 if (gtk_combo_box_get_active (GTK_COMBO_BOX (burntype_widget)) == COMBOBOX_OPTION_NEW_DVD) {
140 fenum = g_file_enumerate_children (burn,
141 G_FILE_ATTRIBUTE_STANDARD_NAME,
142 G_FILE_QUERY_INFO_NONE,
143 NULL,
144 NULL);
145
146 if (fenum != NULL) {
147 while ((file_info = g_file_enumerator_next_file (fenum, NULL, NULL)) != NULL) {
148 child = g_file_get_child (burn,
149 g_file_info_get_name(file_info));
150
151 g_object_unref (file_info);
152 g_file_delete (child, NULL, NULL);
153 g_object_unref (child);
154 }
155 g_object_unref (fenum);
156 }
157 }
158
159 copy_files_to (file_list, burn);
160
161 gtk_show_uri_on_window (NULL, "burn:///", GDK_CURRENT_TIME, NULL);
162
163 return TRUE;
164 }
165
166 static
destroy(NstPlugin * plugin)167 gboolean destroy (NstPlugin *plugin)
168 {
169 g_object_unref (burn);
170 burn = NULL;
171 return TRUE;
172 }
173
174 static
175 NstPluginInfo plugin_info = {
176 "brasero",
177 "caja-burn",
178 N_("CD/DVD Creator"),
179 NULL,
180 CAJA_CAPS_SEND_DIRECTORIES,
181 init,
182 get_contacts_widget,
183 NULL,
184 send_files,
185 destroy
186 };
187
188 NST_INIT_PLUGIN (plugin_info)
189