forked from GNOME/rhythmbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrb-task-progress-simple.c
214 lines (190 loc) · 6.11 KB
/
rb-task-progress-simple.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2013 Jonathan Matthew <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The Rhythmbox authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Rhythmbox. This permission is above and beyond the permissions granted
* by the GPL license by which Rhythmbox is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <config.h>
#include <lib/rb-task-progress-simple.h>
enum {
CANCEL_TASK,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = {0};
struct _RBTaskProgressSimplePrivate
{
char *label;
char *detail;
double progress;
RBTaskOutcome outcome;
gboolean notify;
gboolean cancellable;
};
static void rb_task_progress_simple_class_init (RBTaskProgressSimpleClass *klass);
static void rb_task_progress_simple_init (RBTaskProgressSimple *task);
static void rb_task_progress_simple_task_progress_init (RBTaskProgressInterface *iface);
/**
* SECTION:rb-task-progress-simple
* @short_description: implementation of RBTaskProgress interface
*
* This implementation of #RBTaskProgress can be used to represent
* tasks that aren't bound to the lifecycle of an object that can
* implement the interface directly.
*/
G_DEFINE_TYPE_EXTENDED (RBTaskProgressSimple,
rb_task_progress_simple,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (RB_TYPE_TASK_PROGRESS, rb_task_progress_simple_task_progress_init));
enum {
PROP_0,
PROP_TASK_LABEL,
PROP_TASK_DETAIL,
PROP_TASK_PROGRESS,
PROP_TASK_OUTCOME,
PROP_TASK_NOTIFY,
PROP_TASK_CANCELLABLE
};
static void
task_progress_cancel (RBTaskProgress *task)
{
g_signal_emit (RB_TASK_PROGRESS_SIMPLE (task), signals[CANCEL_TASK], 0);
}
static void
impl_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
RBTaskProgressSimple *task = RB_TASK_PROGRESS_SIMPLE (object);
switch (prop_id) {
case PROP_TASK_LABEL:
g_free (task->priv->label);
task->priv->label = g_value_dup_string (value);
break;
case PROP_TASK_DETAIL:
g_free (task->priv->detail);
task->priv->detail = g_value_dup_string (value);
break;
case PROP_TASK_PROGRESS:
task->priv->progress = g_value_get_double (value);
break;
case PROP_TASK_OUTCOME:
task->priv->outcome = g_value_get_enum (value);
break;
case PROP_TASK_NOTIFY:
task->priv->notify = g_value_get_boolean (value);
break;
case PROP_TASK_CANCELLABLE:
task->priv->cancellable = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
impl_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
RBTaskProgressSimple *task = RB_TASK_PROGRESS_SIMPLE (object);
switch (prop_id) {
case PROP_TASK_LABEL:
g_value_set_string (value, task->priv->label);
break;
case PROP_TASK_DETAIL:
g_value_set_string (value, task->priv->detail);
break;
case PROP_TASK_PROGRESS:
g_value_set_double (value, task->priv->progress);
break;
case PROP_TASK_OUTCOME:
g_value_set_enum (value, task->priv->outcome);
break;
case PROP_TASK_NOTIFY:
g_value_set_boolean (value, task->priv->notify);
break;
case PROP_TASK_CANCELLABLE:
g_value_set_boolean (value, task->priv->cancellable);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
impl_finalize (GObject *object)
{
RBTaskProgressSimple *task = RB_TASK_PROGRESS_SIMPLE (object);
g_free (task->priv->label);
g_free (task->priv->detail);
G_OBJECT_CLASS (rb_task_progress_simple_parent_class)->finalize (object);
}
static void
rb_task_progress_simple_init (RBTaskProgressSimple *task)
{
task->priv = G_TYPE_INSTANCE_GET_PRIVATE (task, RB_TYPE_TASK_PROGRESS_SIMPLE, RBTaskProgressSimplePrivate);
}
static void
rb_task_progress_simple_task_progress_init (RBTaskProgressInterface *interface)
{
interface->cancel = task_progress_cancel;
}
static void
rb_task_progress_simple_class_init (RBTaskProgressSimpleClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (RBTaskProgressSimplePrivate));
gobject_class->finalize = impl_finalize;
gobject_class->set_property = impl_set_property;
gobject_class->get_property = impl_get_property;
g_object_class_override_property (gobject_class, PROP_TASK_LABEL, "task-label");
g_object_class_override_property (gobject_class, PROP_TASK_DETAIL, "task-detail");
g_object_class_override_property (gobject_class, PROP_TASK_PROGRESS, "task-progress");
g_object_class_override_property (gobject_class, PROP_TASK_OUTCOME, "task-outcome");
g_object_class_override_property (gobject_class, PROP_TASK_NOTIFY, "task-notify");
g_object_class_override_property (gobject_class, PROP_TASK_CANCELLABLE, "task-cancellable");
signals[CANCEL_TASK] =
g_signal_new ("cancel-task",
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE,
0);
}
/**
* rb_task_progress_simple_new:
*
* Creates a new simple task progress object.
*
* Return value: (transfer full): the task object
*/
RBTaskProgress *
rb_task_progress_simple_new (void)
{
return RB_TASK_PROGRESS (g_object_new (RB_TYPE_TASK_PROGRESS_SIMPLE, NULL));
}