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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Paolo Borelli <pborelli@katamail.com>
*
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include "nautilus-trash-bar.h"
#include <libnautilus-private/nautilus-file-operations.h>
#include <libnautilus-private/nautilus-trash-monitor.h>
#define NAUTILUS_TRASH_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_TRASH_BAR, NautilusTrashBarPrivate))
struct NautilusTrashBarPrivate
{
GtkWidget *button;
};
G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_HBOX)
static void
nautilus_trash_bar_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
NautilusTrashBar *bar;
bar = NAUTILUS_TRASH_BAR (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nautilus_trash_bar_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NautilusTrashBar *bar;
bar = NAUTILUS_TRASH_BAR (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor *trash_monitor,
gboolean state,
gpointer data)
{
NautilusTrashBar *bar;
bar = NAUTILUS_TRASH_BAR (data);
gtk_widget_set_sensitive (bar->priv->button,
!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->get_property = nautilus_trash_bar_get_property;
object_class->set_property = nautilus_trash_bar_set_property;
g_type_class_add_private (klass, sizeof (NautilusTrashBarPrivate));
}
static void
empty_trash_callback (GtkWidget *button, gpointer data)
{
GtkWidget *window;
window = gtk_widget_get_toplevel (button);
nautilus_file_operations_empty_trash (window);
}
static void
nautilus_trash_bar_init (NautilusTrashBar *bar)
{
GtkWidget *label;
GtkWidget *hbox;
bar->priv = NAUTILUS_TRASH_BAR_GET_PRIVATE (bar);
hbox = GTK_WIDGET (bar);
label = gtk_label_new (_("Trash"));
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (bar), label, FALSE, FALSE, 0);
bar->priv->button = gtk_button_new_with_mnemonic (_("Empty _Trash"));
gtk_widget_show (bar->priv->button);
gtk_box_pack_end (GTK_BOX (hbox), bar->priv->button, FALSE, FALSE, 0);
gtk_widget_set_sensitive (bar->priv->button,
!nautilus_trash_monitor_is_empty ());
gtk_widget_set_tooltip_text (bar->priv->button,
_("Delete all items in the Trash"));
g_signal_connect (bar->priv->button,
"clicked",
G_CALLBACK (empty_trash_callback),
bar);
g_signal_connect_object (nautilus_trash_monitor_get (),
"trash_state_changed",
G_CALLBACK (nautilus_trash_bar_trash_state_changed),
bar,
0);
}
GtkWidget *
nautilus_trash_bar_new (void)
{
GObject *bar;
bar = g_object_new (NAUTILUS_TYPE_TRASH_BAR, NULL);
return GTK_WIDGET (bar);
}
|