1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/*
* Copyright (C) 2006 Paolo Borelli <pborelli@katamail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* Authors: Paolo Borelli <pborelli@katamail.com>
*
*/
#include "config.h"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "nautilus-trash-bar.h"
#include "nautilus-files-view.h"
#include "nautilus-file-operations.h"
#include "nautilus-file-utilities.h"
#include "nautilus-file.h"
#include "nautilus-trash-monitor.h"
enum
{
PROP_VIEW = 1,
NUM_PROPERTIES
};
enum
{
TRASH_BAR_RESPONSE_EMPTY = 1,
TRASH_BAR_RESPONSE_RESTORE
};
struct _NautilusTrashBar
{
GtkInfoBar parent_instance;
NautilusFilesView *view;
gulong selection_handler_id;
};
G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_INFO_BAR)
static void
selection_changed_cb (NautilusFilesView *view,
NautilusTrashBar *bar)
{
g_autolist (NautilusFile) selection = NULL;
int count;
selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
count = g_list_length (selection);
gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
TRASH_BAR_RESPONSE_RESTORE,
(count > 0));
}
static void
connect_view_and_update_button (NautilusTrashBar *bar)
{
bar->selection_handler_id = g_signal_connect (bar->view,
"selection-changed",
G_CALLBACK (selection_changed_cb),
bar);
selection_changed_cb (bar->view, bar);
}
static void
nautilus_trash_bar_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
NautilusTrashBar *bar = NAUTILUS_TRASH_BAR (object);
switch (prop_id)
{
case PROP_VIEW:
{
bar->view = g_value_get_object (value);
connect_view_and_update_button (NAUTILUS_TRASH_BAR (object));
}
break;
default:
{
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
break;
}
}
static void
nautilus_trash_bar_dispose (GObject *obj)
{
NautilusTrashBar *bar = NAUTILUS_TRASH_BAR (obj);
g_clear_signal_handler (&bar->selection_handler_id, bar->view);
G_OBJECT_CLASS (nautilus_trash_bar_parent_class)->dispose (obj);
}
static void
nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor *trash_monitor,
gboolean state,
gpointer data)
{
NautilusTrashBar *bar;
bar = NAUTILUS_TRASH_BAR (data);
gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
TRASH_BAR_RESPONSE_EMPTY,
!nautilus_trash_monitor_is_empty ());
}
static void
nautilus_trash_bar_class_init (NautilusTrashBarClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
object_class->set_property = nautilus_trash_bar_set_property;
object_class->dispose = nautilus_trash_bar_dispose;
g_object_class_install_property (object_class,
PROP_VIEW,
g_param_spec_object ("view",
"view",
"the NautilusFilesView",
NAUTILUS_TYPE_FILES_VIEW,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}
static void
trash_bar_response_cb (GtkInfoBar *infobar,
gint response_id,
gpointer user_data)
{
NautilusTrashBar *bar;
GtkWidget *window;
bar = NAUTILUS_TRASH_BAR (infobar);
window = gtk_widget_get_toplevel (GTK_WIDGET (bar));
switch (response_id)
{
case TRASH_BAR_RESPONSE_EMPTY:
{
nautilus_file_operations_empty_trash (window, TRUE, NULL);
}
break;
case TRASH_BAR_RESPONSE_RESTORE:
{
g_autolist (NautilusFile) selection = NULL;
selection = nautilus_view_get_selection (NAUTILUS_VIEW (bar->view));
nautilus_restore_files_from_trash (selection, GTK_WINDOW (window));
}
break;
default:
{
}
break;
}
}
static void
nautilus_trash_bar_init (NautilusTrashBar *bar)
{
GtkWidget *content_area, *action_area, *w;
GtkWidget *label;
PangoAttrList *attrs;
content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area),
GTK_ORIENTATION_HORIZONTAL);
attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
label = gtk_label_new (_("Trash"));
gtk_label_set_attributes (GTK_LABEL (label), attrs);
pango_attr_list_unref (attrs);
gtk_widget_show (label);
gtk_container_add (GTK_CONTAINER (content_area), label);
w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
_("_Restore"),
TRASH_BAR_RESPONSE_RESTORE);
gtk_widget_set_tooltip_text (w,
_("Restore selected items to their original position"));
w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
/* Translators: "Empty" is an action (for the trash) , not a state */
_("_Empty"),
TRASH_BAR_RESPONSE_EMPTY);
gtk_widget_set_tooltip_text (w,
_("Delete all items in the Trash"));
g_signal_connect_object (nautilus_trash_monitor_get (),
"trash-state-changed",
G_CALLBACK (nautilus_trash_bar_trash_state_changed),
bar,
0);
nautilus_trash_bar_trash_state_changed (nautilus_trash_monitor_get (),
FALSE, bar);
g_signal_connect (bar, "response",
G_CALLBACK (trash_bar_response_cb), bar);
}
GtkWidget *
nautilus_trash_bar_new (NautilusFilesView *view)
{
return g_object_new (NAUTILUS_TYPE_TRASH_BAR,
"view", view,
"message-type", GTK_MESSAGE_QUESTION,
NULL);
}
|