1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* Copyright (C) 2013 Jonathan Matthew <jonathan@d14n.org>
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
* 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.
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.
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.
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>
36
#define TASK_REMOVE_DELAY 15
38
static void rb_task_list_display_class_init (RBTaskListDisplayClass *klass);
39
static void rb_task_list_display_init (RBTaskListDisplay *list);
41
struct _RBTaskListDisplayPrivate
47
G_DEFINE_TYPE (RBTaskListDisplay, rb_task_list_display, GTK_TYPE_GRID);
55
stop_clicked_cb (GtkButton *button, RBTaskProgress *task)
57
rb_task_progress_cancel (task);
61
transform_outcome (GBinding *binding, const GValue *source, GValue *target, gpointer data)
63
RBTaskOutcome outcome;
66
outcome = g_value_get_enum (source);
68
case RB_TASK_OUTCOME_NONE:
71
case RB_TASK_OUTCOME_COMPLETE:
72
case RB_TASK_OUTCOME_CANCELLED:
76
g_assert_not_reached ();
79
g_value_set_boolean (target, sensitive);
84
task_list_changed_cb (RBListModel *model, int position, int removed, int added, RBTaskListDisplay *list)
88
for (i = 0; i < removed; i++) {
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);
96
for (i = 0; i < added; i++) {
101
task = RB_TASK_PROGRESS (rb_list_model_get (model, position + i));
102
tw = gtk_grid_new ();
104
"column-spacing", 12,
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);
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);
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);
124
/* pause/resume button? */
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));
130
g_object_bind_property_full (task, "task-outcome",
132
G_BINDING_SYNC_CREATE,
138
g_object_set (w, "sensitive", FALSE, NULL);
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);
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);
151
impl_constructed (GObject *object)
153
RBTaskListDisplay *list;
155
RB_CHAIN_GOBJECT_METHOD (rb_task_list_display_parent_class, constructed, object);
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);
163
impl_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
165
RBTaskListDisplay *list = RB_TASK_LIST_DISPLAY (object);
169
g_value_set_object (value, list->priv->model);
172
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
178
impl_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
180
RBTaskListDisplay *list = RB_TASK_LIST_DISPLAY (object);
184
list->priv->model = g_value_dup_object (value);
187
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
193
impl_dispose (GObject *object)
195
RBTaskListDisplay *list = RB_TASK_LIST_DISPLAY (object);
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);
201
if (list->priv->widgets != NULL) {
202
g_array_free (list->priv->widgets, TRUE);
203
list->priv->widgets = NULL;
205
G_OBJECT_CLASS (rb_task_list_display_parent_class)->dispose (object);
209
rb_task_list_display_init (RBTaskListDisplay *list)
211
list->priv = G_TYPE_INSTANCE_GET_PRIVATE (list, RB_TYPE_TASK_LIST_DISPLAY, RBTaskListDisplayPrivate);
213
list->priv->widgets = g_array_new (FALSE, FALSE, sizeof (GtkWidget *));
217
rb_task_list_display_class_init (RBTaskListDisplayClass *klass)
219
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
221
g_type_class_add_private (klass, sizeof (RBTaskListDisplayPrivate));
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;
228
g_object_class_install_property (gobject_class,
230
g_param_spec_object ("model",
234
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
238
rb_task_list_display_new (RBListModel *model)
240
return GTK_WIDGET (g_object_new (RB_TYPE_TASK_LIST_DISPLAY,