1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2006 Paolo Borelli <pborelli@katamail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
* Authors: Paolo Borelli <pborelli@katamail.com>
25
#include <glib/gi18n.h>
28
#include "nautilus-trash-bar.h"
30
#include "nautilus-view.h"
31
#include <libnautilus-private/nautilus-file-operations.h>
32
#include <libnautilus-private/nautilus-file-utilities.h>
33
#include <libnautilus-private/nautilus-file.h>
34
#include <libnautilus-private/nautilus-trash-monitor.h>
36
#define NAUTILUS_TRASH_BAR_GET_PRIVATE(o)\
37
(G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_TRASH_BAR, NautilusTrashBarPrivate))
45
TRASH_BAR_RESPONSE_EMPTY = 1,
46
TRASH_BAR_RESPONSE_RESTORE
49
struct NautilusTrashBarPrivate
52
gulong selection_handler_id;
55
G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_INFO_BAR);
58
selection_changed_cb (NautilusView *view,
59
NautilusTrashBar *bar)
63
count = nautilus_view_get_selection_count (view);
65
gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
66
TRASH_BAR_RESPONSE_RESTORE,
71
connect_view_and_update_button (NautilusTrashBar *bar)
73
bar->priv->selection_handler_id =
74
g_signal_connect (bar->priv->view, "selection-changed",
75
G_CALLBACK (selection_changed_cb), bar);
77
selection_changed_cb (bar->priv->view, bar);
81
nautilus_trash_bar_set_property (GObject *object,
86
NautilusTrashBar *bar;
88
bar = NAUTILUS_TRASH_BAR (object);
92
bar->priv->view = g_value_get_object (value);
93
connect_view_and_update_button (bar);
96
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
102
nautilus_trash_bar_dispose (GObject *obj)
104
NautilusTrashBar *bar;
106
bar = NAUTILUS_TRASH_BAR (obj);
108
if (bar->priv->selection_handler_id) {
109
g_signal_handler_disconnect (bar->priv->view, bar->priv->selection_handler_id);
110
bar->priv->selection_handler_id = 0;
113
G_OBJECT_CLASS (nautilus_trash_bar_parent_class)->dispose (obj);
117
nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor *trash_monitor,
121
NautilusTrashBar *bar;
123
bar = NAUTILUS_TRASH_BAR (data);
125
gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
126
TRASH_BAR_RESPONSE_EMPTY,
127
!nautilus_trash_monitor_is_empty ());
131
nautilus_trash_bar_class_init (NautilusTrashBarClass *klass)
133
GObjectClass *object_class;
135
object_class = G_OBJECT_CLASS (klass);
137
object_class->set_property = nautilus_trash_bar_set_property;
138
object_class->dispose = nautilus_trash_bar_dispose;
140
g_object_class_install_property (object_class,
142
g_param_spec_object ("view",
147
G_PARAM_CONSTRUCT_ONLY |
148
G_PARAM_STATIC_STRINGS));
150
g_type_class_add_private (klass, sizeof (NautilusTrashBarPrivate));
154
trash_bar_response_cb (GtkInfoBar *infobar,
158
NautilusTrashBar *bar;
162
bar = NAUTILUS_TRASH_BAR (infobar);
163
window = gtk_widget_get_toplevel (GTK_WIDGET (bar));
165
switch (response_id) {
166
case TRASH_BAR_RESPONSE_EMPTY:
167
nautilus_file_operations_empty_trash (window);
169
case TRASH_BAR_RESPONSE_RESTORE:
170
files = nautilus_view_get_selection (bar->priv->view);
171
nautilus_restore_files_from_trash (files, GTK_WINDOW (window));
172
nautilus_file_list_free (files);
180
nautilus_trash_bar_init (NautilusTrashBar *bar)
182
GtkWidget *content_area, *action_area, *w;
184
PangoAttrList *attrs;
186
bar->priv = NAUTILUS_TRASH_BAR_GET_PRIVATE (bar);
187
content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
188
action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
190
gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area),
191
GTK_ORIENTATION_HORIZONTAL);
193
attrs = pango_attr_list_new ();
194
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
195
label = gtk_label_new (_("Trash"));
196
gtk_label_set_attributes (GTK_LABEL (label), attrs);
197
pango_attr_list_unref (attrs);
199
gtk_widget_show (label);
200
gtk_container_add (GTK_CONTAINER (content_area), label);
202
w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
204
TRASH_BAR_RESPONSE_RESTORE);
205
gtk_widget_set_tooltip_text (w,
206
_("Restore selected items to their original position"));
208
w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
209
/* Translators: "Empty" is an action (for the trash) , not a state */
211
TRASH_BAR_RESPONSE_EMPTY);
212
gtk_widget_set_tooltip_text (w,
213
_("Delete all items in the Trash"));
215
g_signal_connect_object (nautilus_trash_monitor_get (),
216
"trash_state_changed",
217
G_CALLBACK (nautilus_trash_bar_trash_state_changed),
220
nautilus_trash_bar_trash_state_changed (nautilus_trash_monitor_get (),
223
g_signal_connect (bar, "response",
224
G_CALLBACK (trash_bar_response_cb), bar);
228
nautilus_trash_bar_new (NautilusView *view)
230
return g_object_new (NAUTILUS_TYPE_TRASH_BAR,
232
"message-type", GTK_MESSAGE_QUESTION,