~ubuntu-branches/ubuntu/trusty/rhythmbox/trusty

« back to all changes in this revision

Viewing changes to widgets/rb-task-list-display.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2013-10-24 11:01:12 UTC
  • mfrom: (1.1.69) (2.1.31 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131024110112-v3ou37rae2m6xpml
Tags: 3.0.1-1ubuntu1
* Merge with Debian unstable (LP: #1220972), remaining changes:
  + Add Breaks and Replaces on versions of transmageddon which shipped the
    .prs files we are now shipping in -data.
  + Split magnatune, visualizer and cdrecorder plugins out and Recommend
    these from rhythmbox instead of all of the plugins.
  + Suggest gst-plugins-ugly instead of Recommending.
  + Add Ubuntu encoding presets and use them by default.
  + debian/patches/02_use_escaped_podcast_uri.patch
    - Handle podcasts that have sound files with the same basename
  + debian/patches/03_magnatune_partner.patch:
    - Change magnatune partner ID to 'ubuntu'.
  + debian/patches/05_hide_on_quit.patch
    - Hide (not quit) if RB is playing when closed.
  + debian/patches/07_quicklists.patch
    - Add quicklists.
* Re-enable visualization plugin; it works again.
* Remove 09_keywords.patch as the upstream .desktop file contains (almost)
  all of these.
* Disable grilo plugin as grilo is in Universe. 
* Use dh_python3 and pass --no-ext-rename to leave plugin filenames alone. 
* Have -plugin-magnatune depend on gir1.2-secret-1
* Re-enabled replaygain plugin (LP: #1180721)

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) 2013 Jonathan Matthew <jonathan@d14n.org>
 
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
 *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 
11
 *  GStreamer plugins to be used and distributed together with GStreamer
 
12
 *  and Rhythmbox. This permission is above and beyond the permissions granted
 
13
 *  by the GPL license by which Rhythmbox is covered. If you modify this code
 
14
 *  you may extend this exception to your version of the code, but you are not
 
15
 *  obligated to do so. If you do not wish to do so, delete this exception
 
16
 *  statement from your version.
 
17
 *
 
18
 *  This program is distributed in the hope that it will be useful,
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 *  GNU General Public License for more details.
 
22
 *
 
23
 *  You should have received a copy of the GNU General Public License
 
24
 *  along with this program; if not, write to the Free Software
 
25
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
26
 *
 
27
 */
 
28
 
 
29
#include <config.h>
 
30
 
 
31
#include <widgets/rb-task-list-display.h>
 
32
#include <lib/rb-task-progress.h>
 
33
#include <lib/rb-list-model.h>
 
34
#include <lib/rb-util.h>
 
35
 
 
36
#define TASK_REMOVE_DELAY       15
 
37
 
 
38
static void rb_task_list_display_class_init (RBTaskListDisplayClass *klass);
 
39
static void rb_task_list_display_init (RBTaskListDisplay *list);
 
40
 
 
41
struct _RBTaskListDisplayPrivate
 
42
{
 
43
        RBListModel *model;
 
44
        GArray *widgets;
 
45
};
 
46
 
 
47
G_DEFINE_TYPE (RBTaskListDisplay, rb_task_list_display, GTK_TYPE_GRID);
 
48
 
 
49
enum {
 
50
        PROP_0,
 
51
        PROP_MODEL
 
52
};
 
53
 
 
54
static void
 
55
stop_clicked_cb (GtkButton *button, RBTaskProgress *task)
 
56
{
 
57
        rb_task_progress_cancel (task);
 
58
}
 
59
 
 
60
static gboolean
 
61
transform_outcome (GBinding *binding, const GValue *source, GValue *target, gpointer data)
 
62
{
 
63
        RBTaskOutcome outcome;
 
64
        gboolean sensitive;
 
65
 
 
66
        outcome = g_value_get_enum (source);
 
67
        switch (outcome) {
 
68
        case RB_TASK_OUTCOME_NONE:
 
69
                sensitive = TRUE;
 
70
                break;
 
71
        case RB_TASK_OUTCOME_COMPLETE:
 
72
        case RB_TASK_OUTCOME_CANCELLED:
 
73
                sensitive = FALSE;
 
74
                break;
 
75
        default:
 
76
                g_assert_not_reached ();
 
77
        }
 
78
 
 
79
        g_value_set_boolean (target, sensitive);
 
80
        return TRUE;
 
81
}
 
82
 
 
83
static void
 
84
task_list_changed_cb (RBListModel *model, int position, int removed, int added, RBTaskListDisplay *list)
 
85
{
 
86
        int i;
 
87
 
 
88
        for (i = 0; i < removed; i++) {
 
89
                GtkWidget *w;
 
90
 
 
91
                w = g_array_index (list->priv->widgets, GtkWidget *, position);
 
92
                gtk_container_remove (GTK_CONTAINER (list), w);
 
93
                g_array_remove_index (list->priv->widgets, position);
 
94
        }
 
95
 
 
96
        for (i = 0; i < added; i++) {
 
97
                GtkWidget *tw, *w;
 
98
                RBTaskProgress *task;
 
99
                gboolean cancellable;
 
100
 
 
101
                task = RB_TASK_PROGRESS (rb_list_model_get (model, position + i));
 
102
                tw = gtk_grid_new ();
 
103
                g_object_set (tw,
 
104
                              "column-spacing", 12,
 
105
                              "margin", 6,
 
106
                              NULL);
 
107
 
 
108
                w = gtk_label_new (NULL);
 
109
                g_object_bind_property (task, "task-label", w, "label", G_BINDING_SYNC_CREATE);
 
110
                g_object_set (w, "hexpand", TRUE, "halign", GTK_ALIGN_START, NULL);
 
111
                gtk_grid_attach (GTK_GRID (tw), w, 0, 0, 1, 1);
 
112
 
 
113
                w = gtk_label_new (NULL);
 
114
                gtk_style_context_add_class (gtk_widget_get_style_context (w), GTK_STYLE_CLASS_DIM_LABEL);
 
115
                g_object_bind_property (task, "task-detail", w, "label", G_BINDING_SYNC_CREATE);
 
116
                g_object_set (w, "hexpand", TRUE, "halign", GTK_ALIGN_START, NULL);
 
117
                gtk_grid_attach (GTK_GRID (tw), w, 1, 0, 1, 1);
 
118
 
 
119
                w = gtk_progress_bar_new ();
 
120
                g_object_bind_property (task, "task-progress", w, "fraction", G_BINDING_SYNC_CREATE);
 
121
                g_object_set (w, "hexpand", TRUE, NULL);
 
122
                gtk_grid_attach (GTK_GRID (tw), w, 2, 0, 1, 1);
 
123
 
 
124
                /* pause/resume button? */
 
125
 
 
126
                g_object_get (task, "task-cancellable", &cancellable, NULL);
 
127
                w = gtk_button_new ();
 
128
                gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_icon_name ("process-stop-symbolic", GTK_ICON_SIZE_MENU));
 
129
                if (cancellable) {
 
130
                        g_object_bind_property_full (task, "task-outcome",
 
131
                                                     w, "sensitive",
 
132
                                                     G_BINDING_SYNC_CREATE,
 
133
                                                     transform_outcome,
 
134
                                                     NULL,
 
135
                                                     NULL,
 
136
                                                     NULL);
 
137
                } else {
 
138
                        g_object_set (w, "sensitive", FALSE, NULL);
 
139
                }
 
140
                g_signal_connect_object (w, "clicked", G_CALLBACK (stop_clicked_cb), task, 0);
 
141
                gtk_grid_attach (GTK_GRID (tw), w, 3, 0, 1, 1);
 
142
 
 
143
                gtk_grid_insert_column (GTK_GRID (list), position + i);
 
144
                gtk_grid_attach (GTK_GRID (list), tw, 0, position + i, 1, 1);
 
145
                gtk_widget_show_all (tw);
 
146
                g_array_insert_val (list->priv->widgets, position + i, tw);
 
147
        }
 
148
}
 
149
 
 
150
static void
 
151
impl_constructed (GObject *object)
 
152
{
 
153
        RBTaskListDisplay *list;
 
154
 
 
155
        RB_CHAIN_GOBJECT_METHOD (rb_task_list_display_parent_class, constructed, object);
 
156
 
 
157
        list = RB_TASK_LIST_DISPLAY (object);
 
158
        g_signal_connect (list->priv->model, "items-changed", G_CALLBACK (task_list_changed_cb), list);
 
159
        task_list_changed_cb (list->priv->model, 0, 0, rb_list_model_n_items (list->priv->model), list);
 
160
}
 
161
 
 
162
static void
 
163
impl_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 
164
{
 
165
        RBTaskListDisplay *list = RB_TASK_LIST_DISPLAY (object);
 
166
        
 
167
        switch (prop_id) {
 
168
        case PROP_MODEL:
 
169
                g_value_set_object (value, list->priv->model);
 
170
                break;
 
171
        default:
 
172
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
173
                break;
 
174
        }
 
175
}
 
176
 
 
177
static void
 
178
impl_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 
179
{
 
180
        RBTaskListDisplay *list = RB_TASK_LIST_DISPLAY (object);
 
181
        
 
182
        switch (prop_id) {
 
183
        case PROP_MODEL:
 
184
                list->priv->model = g_value_dup_object (value);
 
185
                break;
 
186
        default:
 
187
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
188
                break;
 
189
        }
 
190
}
 
191
 
 
192
static void
 
193
impl_dispose (GObject *object)
 
194
{
 
195
        RBTaskListDisplay *list = RB_TASK_LIST_DISPLAY (object);
 
196
        
 
197
        if (list->priv->model != NULL) {
 
198
                g_signal_handlers_disconnect_by_func (list->priv->model, task_list_changed_cb, list);
 
199
                g_clear_object (&list->priv->model);
 
200
        }
 
201
        if (list->priv->widgets != NULL) {
 
202
                g_array_free (list->priv->widgets, TRUE);
 
203
                list->priv->widgets = NULL;
 
204
        }
 
205
        G_OBJECT_CLASS (rb_task_list_display_parent_class)->dispose (object);
 
206
}
 
207
 
 
208
static void
 
209
rb_task_list_display_init (RBTaskListDisplay *list)
 
210
{
 
211
        list->priv = G_TYPE_INSTANCE_GET_PRIVATE (list, RB_TYPE_TASK_LIST_DISPLAY, RBTaskListDisplayPrivate);
 
212
 
 
213
        list->priv->widgets = g_array_new (FALSE, FALSE, sizeof (GtkWidget *));
 
214
}
 
215
 
 
216
static void
 
217
rb_task_list_display_class_init (RBTaskListDisplayClass *klass)
 
218
{
 
219
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
220
 
 
221
        g_type_class_add_private (klass, sizeof (RBTaskListDisplayPrivate));
 
222
 
 
223
        gobject_class->constructed = impl_constructed;
 
224
        gobject_class->dispose = impl_dispose;
 
225
        gobject_class->set_property = impl_set_property;
 
226
        gobject_class->get_property = impl_get_property;
 
227
 
 
228
        g_object_class_install_property (gobject_class,
 
229
                                         PROP_MODEL,
 
230
                                         g_param_spec_object ("model",
 
231
                                                              "model",
 
232
                                                              "model",
 
233
                                                              RB_TYPE_LIST_MODEL,
 
234
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
235
}
 
236
 
 
237
GtkWidget *
 
238
rb_task_list_display_new (RBListModel *model)
 
239
{
 
240
        return GTK_WIDGET (g_object_new (RB_TYPE_TASK_LIST_DISPLAY,
 
241
                                         "model", model,
 
242
                                         "row-spacing", 12,
 
243
                                         NULL));
 
244
}