~ubuntu-branches/ubuntu/saucy/nautilus/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/0001-trash-bar-Take-a-weak-ref-to-the-view-for-signal-dis.patch/src/nautilus-trash-bar.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2013-06-20 09:38:18 UTC
  • Revision ID: package-import@ubuntu.com-20130620093818-1vl5h5w5dr54gkgv
Tags: 1:3.6.3-0ubuntu20
Remove previous patch; it wasn't the optimal approach. Add
debian/patches/disconnect-extra-location-widgets.patch to remove
references to NautilusTrashBar, causing it to be disposed at the right
time instead. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
3
 
 * Copyright (C) 2006 Paolo Borelli <pborelli@katamail.com>
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 *
19
 
 * Authors: Paolo Borelli <pborelli@katamail.com>
20
 
 *
21
 
 */
22
 
 
23
 
#include "config.h"
24
 
 
25
 
#include <glib/gi18n.h>
26
 
#include <gtk/gtk.h>
27
 
 
28
 
#include "nautilus-trash-bar.h"
29
 
 
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>
35
 
 
36
 
#define NAUTILUS_TRASH_BAR_GET_PRIVATE(o)\
37
 
        (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_TRASH_BAR, NautilusTrashBarPrivate))
38
 
 
39
 
enum {
40
 
        PROP_VIEW = 1,
41
 
        NUM_PROPERTIES
42
 
};
43
 
 
44
 
enum {
45
 
        TRASH_BAR_RESPONSE_EMPTY = 1,
46
 
        TRASH_BAR_RESPONSE_RESTORE
47
 
};
48
 
 
49
 
struct NautilusTrashBarPrivate
50
 
{
51
 
        NautilusView *view;
52
 
        gulong selection_handler_id;
53
 
};
54
 
 
55
 
G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_INFO_BAR);
56
 
 
57
 
static void
58
 
selection_changed_cb (NautilusView *view,
59
 
                      NautilusTrashBar *bar)
60
 
{
61
 
        int count;
62
 
 
63
 
        count = nautilus_view_get_selection_count (view);
64
 
 
65
 
        gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
66
 
                                             TRASH_BAR_RESPONSE_RESTORE,
67
 
                                             (count > 0));
68
 
}
69
 
 
70
 
static void
71
 
connect_view_and_update_button (NautilusTrashBar *bar)
72
 
{
73
 
        bar->priv->selection_handler_id =
74
 
                g_signal_connect (bar->priv->view, "selection-changed",
75
 
                                  G_CALLBACK (selection_changed_cb), bar);
76
 
 
77
 
        selection_changed_cb (bar->priv->view, bar);
78
 
}
79
 
 
80
 
static void
81
 
nautilus_trash_bar_set_property (GObject      *object,
82
 
                                 guint         prop_id,
83
 
                                 const GValue *value,
84
 
                                 GParamSpec   *pspec)
85
 
{
86
 
        NautilusTrashBar *bar;
87
 
 
88
 
        bar = NAUTILUS_TRASH_BAR (object);
89
 
 
90
 
        switch (prop_id) {
91
 
        case PROP_VIEW:
92
 
                bar->priv->view = g_value_get_object (value);
93
 
                connect_view_and_update_button (bar);
94
 
                break;
95
 
        default:
96
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
97
 
                break;
98
 
        }
99
 
}
100
 
 
101
 
static void
102
 
nautilus_trash_bar_dispose (GObject *obj)
103
 
{
104
 
        NautilusTrashBar *bar;
105
 
 
106
 
        bar = NAUTILUS_TRASH_BAR (obj);
107
 
 
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;
111
 
        }
112
 
 
113
 
        G_OBJECT_CLASS (nautilus_trash_bar_parent_class)->dispose (obj);
114
 
}
115
 
 
116
 
static void
117
 
nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor *trash_monitor,
118
 
                                        gboolean              state,
119
 
                                        gpointer              data)
120
 
{
121
 
        NautilusTrashBar *bar;
122
 
 
123
 
        bar = NAUTILUS_TRASH_BAR (data);
124
 
 
125
 
        gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
126
 
                                             TRASH_BAR_RESPONSE_EMPTY,
127
 
                                             !nautilus_trash_monitor_is_empty ());
128
 
}
129
 
 
130
 
static void
131
 
nautilus_trash_bar_class_init (NautilusTrashBarClass *klass)
132
 
{
133
 
        GObjectClass *object_class;
134
 
 
135
 
        object_class = G_OBJECT_CLASS (klass);
136
 
 
137
 
        object_class->set_property = nautilus_trash_bar_set_property;
138
 
        object_class->dispose = nautilus_trash_bar_dispose;
139
 
 
140
 
        g_object_class_install_property (object_class,
141
 
                                         PROP_VIEW,
142
 
                                         g_param_spec_object ("view",
143
 
                                                              "view",
144
 
                                                              "the NautilusView",
145
 
                                                              NAUTILUS_TYPE_VIEW,
146
 
                                                              G_PARAM_WRITABLE |
147
 
                                                              G_PARAM_CONSTRUCT_ONLY |
148
 
                                                              G_PARAM_STATIC_STRINGS));
149
 
 
150
 
        g_type_class_add_private (klass, sizeof (NautilusTrashBarPrivate));
151
 
}
152
 
 
153
 
static void
154
 
trash_bar_response_cb (GtkInfoBar *infobar,
155
 
                       gint response_id,
156
 
                       gpointer user_data)
157
 
{
158
 
        NautilusTrashBar *bar;
159
 
        GtkWidget *window;
160
 
        GList *files;
161
 
 
162
 
        bar = NAUTILUS_TRASH_BAR (infobar);
163
 
        window = gtk_widget_get_toplevel (GTK_WIDGET (bar));
164
 
 
165
 
        switch (response_id) {
166
 
        case TRASH_BAR_RESPONSE_EMPTY:
167
 
                nautilus_file_operations_empty_trash (window);
168
 
                break;
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);
173
 
                break;
174
 
        default:
175
 
                break;
176
 
        }
177
 
}
178
 
 
179
 
static void
180
 
nautilus_trash_bar_init (NautilusTrashBar *bar)
181
 
{
182
 
        GtkWidget *content_area, *action_area, *w;
183
 
        GtkWidget *label;
184
 
        PangoAttrList *attrs;
185
 
 
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));
189
 
 
190
 
        gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area),
191
 
                                        GTK_ORIENTATION_HORIZONTAL);
192
 
 
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);
198
 
 
199
 
        gtk_widget_show (label);
200
 
        gtk_container_add (GTK_CONTAINER (content_area), label);
201
 
 
202
 
        w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
203
 
                                     _("Restore"),
204
 
                                     TRASH_BAR_RESPONSE_RESTORE);
205
 
        gtk_widget_set_tooltip_text (w,
206
 
                                     _("Restore selected items to their original position"));
207
 
 
208
 
        w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
209
 
        /* Translators: "Empty" is an action (for the trash) , not a state */
210
 
                                     _("Empty"),
211
 
                                     TRASH_BAR_RESPONSE_EMPTY);
212
 
        gtk_widget_set_tooltip_text (w,
213
 
                                     _("Delete all items in the Trash"));
214
 
 
215
 
        g_signal_connect_object (nautilus_trash_monitor_get (),
216
 
                                 "trash_state_changed",
217
 
                                 G_CALLBACK (nautilus_trash_bar_trash_state_changed),
218
 
                                 bar,
219
 
                                 0);
220
 
        nautilus_trash_bar_trash_state_changed (nautilus_trash_monitor_get (),
221
 
                                                FALSE, bar);
222
 
 
223
 
        g_signal_connect (bar, "response",
224
 
                          G_CALLBACK (trash_bar_response_cb), bar);
225
 
}
226
 
 
227
 
GtkWidget *
228
 
nautilus_trash_bar_new (NautilusView *view)
229
 
{
230
 
        return g_object_new (NAUTILUS_TYPE_TRASH_BAR,
231
 
                             "view", view,
232
 
                             "message-type", GTK_MESSAGE_QUESTION,
233
 
                             NULL);
234
 
}