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-lib.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
39 G_DEFINE_TYPE (NautilusTrashBar
, nautilus_trash_bar
, GTK_TYPE_HBOX
)
42 nautilus_trash_bar_set_property (GObject
*object
,
47 NautilusTrashBar
*bar
;
49 bar
= NAUTILUS_TRASH_BAR (object
);
53 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
59 nautilus_trash_bar_get_property (GObject
*object
,
64 NautilusTrashBar
*bar
;
66 bar
= NAUTILUS_TRASH_BAR (object
);
70 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
76 nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor
*trash_monitor
,
80 NautilusTrashBar
*bar
;
82 bar
= NAUTILUS_TRASH_BAR (data
);
84 gtk_widget_set_sensitive (bar
->priv
->button
,
85 !nautilus_trash_monitor_is_empty ());
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
));
102 empty_trash_callback (GtkWidget
*button
, gpointer data
)
106 window
= gtk_widget_get_toplevel (button
);
108 nautilus_file_operations_empty_trash (window
);
112 nautilus_trash_bar_init (NautilusTrashBar
*bar
)
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
,
136 G_CALLBACK (empty_trash_callback
),
139 g_signal_connect_object (nautilus_trash_monitor_get (),
140 "trash_state_changed",
141 G_CALLBACK (nautilus_trash_bar_trash_state_changed
),
147 nautilus_trash_bar_new (void)
151 bar
= g_object_new (NAUTILUS_TYPE_TRASH_BAR
, NULL
);
153 return GTK_WIDGET (bar
);