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

« back to all changes in this revision

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