1 /*
2 * Copyright (c) 2016 Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * Author: Debarshi Ray <debarshir@gnome.org>
19 *
20 */
21
22 #include <cairo-gobject.h>
23
24 #include "gd-main-box-item.h"
25
G_DEFINE_INTERFACE(GdMainBoxItem,gd_main_box_item,G_TYPE_OBJECT)26 G_DEFINE_INTERFACE (GdMainBoxItem, gd_main_box_item, G_TYPE_OBJECT)
27
28 static void
29 gd_main_box_item_default_init (GdMainBoxItemInterface *iface)
30 {
31 GParamSpec *pspec;
32
33 /**
34 * GdMainBoxItem:id:
35 *
36 * A unique ID to identify the #GdMainBoxItem object.
37 */
38 pspec = g_param_spec_string ("id",
39 "ID",
40 "A unique ID to identify the item",
41 NULL,
42 G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
43 g_object_interface_install_property (iface, pspec);
44
45 /**
46 * GdMainBoxItem:uri:
47 *
48 * A URI corresponding to the #GdMainBoxItem object.
49 */
50 pspec = g_param_spec_string ("uri",
51 "URI",
52 "A URI corresponding to the item",
53 NULL,
54 G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
55 g_object_interface_install_property (iface, pspec);
56
57 /**
58 * GdMainBoxItem:primary-text:
59 *
60 * Some text to describe the #GdMainBoxItem object.
61 */
62 pspec = g_param_spec_string ("primary-text",
63 "Primary Text",
64 "Some text to describe the item",
65 NULL,
66 G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
67 g_object_interface_install_property (iface, pspec);
68
69 /**
70 * GdMainBoxItem:secondary-text:
71 *
72 * Some additional text to describe the #GdMainBoxItem object.
73 */
74 pspec = g_param_spec_string ("secondary-text",
75 "Secondary Text",
76 "Some additional text to describe the item",
77 NULL,
78 G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
79 g_object_interface_install_property (iface, pspec);
80
81 /**
82 * GdMainBoxItem:icon:
83 *
84 * An icon to visually identify the #GdMainBoxItem object.
85 */
86 pspec = g_param_spec_boxed ("icon",
87 "Icon",
88 "An icon to visually identify the item",
89 CAIRO_GOBJECT_TYPE_SURFACE,
90 G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
91 g_object_interface_install_property (iface, pspec);
92
93 /**
94 * GdMainBoxItem:mtime:
95 *
96 * The time when the #GdMainBoxItem object was last modified.
97 */
98 pspec = g_param_spec_int64 ("mtime",
99 "Modification time",
100 "The time when the item was last modified",
101 -1,
102 G_MAXINT64,
103 -1,
104 G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
105 g_object_interface_install_property (iface, pspec);
106
107 /**
108 * GdMainBoxItem:pulse:
109 *
110 * Whether to show a progress indicator.
111 */
112 pspec = g_param_spec_boolean ("pulse",
113 "Pulse",
114 "Whether to show a progress indicator",
115 FALSE,
116 G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
117 g_object_interface_install_property (iface, pspec);
118 }
119
120 /**
121 * gd_main_box_item_get_id:
122 * @self:
123 *
124 * Returns: (transfer none): The ID
125 */
126 const gchar *
gd_main_box_item_get_id(GdMainBoxItem * self)127 gd_main_box_item_get_id (GdMainBoxItem *self)
128 {
129 GdMainBoxItemInterface *iface;
130
131 g_return_val_if_fail (GD_IS_MAIN_BOX_ITEM (self), NULL);
132
133 iface = GD_MAIN_BOX_ITEM_GET_IFACE (self);
134
135 return (* iface->get_id) (self);
136 }
137
138 /**
139 * gd_main_box_item_get_uri:
140 * @self:
141 *
142 * Returns: (transfer none): The URI
143 */
144 const gchar *
gd_main_box_item_get_uri(GdMainBoxItem * self)145 gd_main_box_item_get_uri (GdMainBoxItem *self)
146 {
147 GdMainBoxItemInterface *iface;
148
149 g_return_val_if_fail (GD_IS_MAIN_BOX_ITEM (self), NULL);
150
151 iface = GD_MAIN_BOX_ITEM_GET_IFACE (self);
152
153 return (* iface->get_uri) (self);
154 }
155
156 /**
157 * gd_main_box_item_get_primary_text:
158 * @self:
159 *
160 * Returns: (transfer none): The primary text
161 */
162 const gchar *
gd_main_box_item_get_primary_text(GdMainBoxItem * self)163 gd_main_box_item_get_primary_text (GdMainBoxItem *self)
164 {
165 GdMainBoxItemInterface *iface;
166
167 g_return_val_if_fail (GD_IS_MAIN_BOX_ITEM (self), NULL);
168
169 iface = GD_MAIN_BOX_ITEM_GET_IFACE (self);
170
171 return (* iface->get_primary_text) (self);
172 }
173
174 /**
175 * gd_main_box_item_get_secondary_text:
176 * @self:
177 *
178 * Returns: (transfer none): The secondary text
179 */
180 const gchar *
gd_main_box_item_get_secondary_text(GdMainBoxItem * self)181 gd_main_box_item_get_secondary_text (GdMainBoxItem *self)
182 {
183 GdMainBoxItemInterface *iface;
184
185 g_return_val_if_fail (GD_IS_MAIN_BOX_ITEM (self), NULL);
186
187 iface = GD_MAIN_BOX_ITEM_GET_IFACE (self);
188
189 return (* iface->get_secondary_text) (self);
190 }
191
192 /**
193 * gd_main_box_item_get_icon:
194 * @self:
195 *
196 * Returns: (transfer none): The icon
197 */
198 cairo_surface_t *
gd_main_box_item_get_icon(GdMainBoxItem * self)199 gd_main_box_item_get_icon (GdMainBoxItem *self)
200 {
201 GdMainBoxItemInterface *iface;
202
203 g_return_val_if_fail (GD_IS_MAIN_BOX_ITEM (self), NULL);
204
205 iface = GD_MAIN_BOX_ITEM_GET_IFACE (self);
206
207 return (* iface->get_icon) (self);
208 }
209
210 /**
211 * gd_main_box_item_get_mtime:
212 * @self:
213 *
214 * Returns: (transfer none): The modification time
215 */
216 gint64
gd_main_box_item_get_mtime(GdMainBoxItem * self)217 gd_main_box_item_get_mtime (GdMainBoxItem *self)
218 {
219 gint64 mtime;
220
221 g_return_val_if_fail (GD_IS_MAIN_BOX_ITEM (self), -1);
222
223 g_object_get (self, "mtime", &mtime, NULL);
224 return mtime;
225 }
226
227 /**
228 * gd_main_box_item_get_pulse:
229 * @self:
230 *
231 * Returns: (transfer none): Whether to show a progress indicator
232 */
233 gboolean
gd_main_box_item_get_pulse(GdMainBoxItem * self)234 gd_main_box_item_get_pulse (GdMainBoxItem *self)
235 {
236 gboolean pulse;
237
238 g_return_val_if_fail (GD_IS_MAIN_BOX_ITEM (self), FALSE);
239
240 g_object_get (self, "pulse", &pulse, NULL);
241 return pulse;
242 }
243