2008-04-30 Cosimo Cecchi <cosimoc@gnome.org>
[nautilus.git] / src / nautilus-trash-bar.c
blob109714c867fd3f683042b63034294e3a3d7dc028
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
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>
23 #include "config.h"
25 #include <glib/gi18n-lib.h>
26 #include <gtk/gtk.h>
28 #include "nautilus-trash-bar.h"
29 #include <libnautilus-private/nautilus-file-operations.h>
30 #include <libnautilus-private/nautilus-trash-monitor.h>
32 #define NAUTILUS_TRASH_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_TRASH_BAR, NautilusTrashBarPrivate))
34 struct NautilusTrashBarPrivate
36 GtkWidget *button;
39 G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_HBOX)
41 static void
42 nautilus_trash_bar_set_property (GObject *object,
43 guint prop_id,
44 const GValue *value,
45 GParamSpec *pspec)
47 NautilusTrashBar *bar;
49 bar = NAUTILUS_TRASH_BAR (object);
51 switch (prop_id) {
52 default:
53 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
54 break;
58 static void
59 nautilus_trash_bar_get_property (GObject *object,
60 guint prop_id,
61 GValue *value,
62 GParamSpec *pspec)
64 NautilusTrashBar *bar;
66 bar = NAUTILUS_TRASH_BAR (object);
68 switch (prop_id) {
69 default:
70 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
71 break;
75 static void
76 nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor *trash_monitor,
77 gboolean state,
78 gpointer data)
80 NautilusTrashBar *bar;
82 bar = NAUTILUS_TRASH_BAR (data);
84 gtk_widget_set_sensitive (bar->priv->button,
85 !nautilus_trash_monitor_is_empty ());
88 static void
89 nautilus_trash_bar_class_init (NautilusTrashBarClass *klass)
91 GObjectClass *object_class;
93 object_class = G_OBJECT_CLASS (klass);
95 object_class->get_property = nautilus_trash_bar_get_property;
96 object_class->set_property = nautilus_trash_bar_set_property;
98 g_type_class_add_private (klass, sizeof (NautilusTrashBarPrivate));
101 static void
102 empty_trash_callback (GtkWidget *button, gpointer data)
104 GtkWidget *window;
106 window = gtk_widget_get_toplevel (button);
108 nautilus_file_operations_empty_trash (window);
111 static void
112 nautilus_trash_bar_init (NautilusTrashBar *bar)
114 GtkWidget *label;
115 GtkWidget *hbox;
117 bar->priv = NAUTILUS_TRASH_BAR_GET_PRIVATE (bar);
119 hbox = GTK_WIDGET (bar);
121 label = gtk_label_new (_("Trash"));
122 gtk_widget_show (label);
123 gtk_box_pack_start (GTK_BOX (bar), label, FALSE, FALSE, 0);
125 bar->priv->button = gtk_button_new_with_mnemonic (_("Empty _Trash"));
126 gtk_widget_show (bar->priv->button);
127 gtk_box_pack_end (GTK_BOX (hbox), bar->priv->button, FALSE, FALSE, 0);
129 gtk_widget_set_sensitive (bar->priv->button,
130 !nautilus_trash_monitor_is_empty ());
131 gtk_widget_set_tooltip_text (bar->priv->button,
132 _("Delete all items in the Trash"));
134 g_signal_connect (bar->priv->button,
135 "clicked",
136 G_CALLBACK (empty_trash_callback),
137 bar);
139 g_signal_connect_object (nautilus_trash_monitor_get (),
140 "trash_state_changed",
141 G_CALLBACK (nautilus_trash_bar_trash_state_changed),
142 bar,
146 GtkWidget *
147 nautilus_trash_bar_new (void)
149 GObject *bar;
151 bar = g_object_new (NAUTILUS_TYPE_TRASH_BAR, NULL);
153 return GTK_WIDGET (bar);