1 /* metadata-menu-item.c generated by valac 0.14.2, the Vala compiler
2 * generated from metadata-menu-item.vala, do not modify */
3
4 /*
5 Copyright 2010 Canonical Ltd.
6
7 Authors:
8 Conor Curran <conor.curran@canonical.com>
9
10 This program is free software: you can redistribute it and/or modify it
11 under the terms of the GNU General Public License version 3, as published
12 by the Free Software Foundation.
13
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranties of
16 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
17 PURPOSE. See the GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License along
20 with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include <glib.h>
24 #include <glib-object.h>
25 #include <libdbusmenu-glib/client.h>
26 #include <libdbusmenu-glib/dbusmenu-glib.h>
27 #include <libdbusmenu-glib/enum-types.h>
28 #include <libdbusmenu-glib/menuitem-proxy.h>
29 #include <libdbusmenu-glib/menuitem.h>
30 #include <libdbusmenu-glib/server.h>
31 #include <libdbusmenu-glib/types.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <common-defs.h>
35 #include <gio/gio.h>
36 #include <gdk-pixbuf/gdk-pixdata.h>
37 #include <glib/gstdio.h>
38 #include <gee.h>
39
40
41 #define TYPE_PLAYER_ITEM (player_item_get_type ())
42 #define PLAYER_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLAYER_ITEM, PlayerItem))
43 #define PLAYER_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLAYER_ITEM, PlayerItemClass))
44 #define IS_PLAYER_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PLAYER_ITEM))
45 #define IS_PLAYER_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PLAYER_ITEM))
46 #define PLAYER_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PLAYER_ITEM, PlayerItemClass))
47
48 typedef struct _PlayerItem PlayerItem;
49 typedef struct _PlayerItemClass PlayerItemClass;
50 typedef struct _PlayerItemPrivate PlayerItemPrivate;
51
52 #define TYPE_METADATA_MENUITEM (metadata_menuitem_get_type ())
53 #define METADATA_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_METADATA_MENUITEM, MetadataMenuitem))
54 #define METADATA_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_METADATA_MENUITEM, MetadataMenuitemClass))
55 #define IS_METADATA_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_METADATA_MENUITEM))
56 #define IS_METADATA_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_METADATA_MENUITEM))
57 #define METADATA_MENUITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_METADATA_MENUITEM, MetadataMenuitemClass))
58
59 typedef struct _MetadataMenuitem MetadataMenuitem;
60 typedef struct _MetadataMenuitemClass MetadataMenuitemClass;
61 typedef struct _MetadataMenuitemPrivate MetadataMenuitemPrivate;
62
63 #define TYPE_FETCH_FILE (fetch_file_get_type ())
64 #define FETCH_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FETCH_FILE, FetchFile))
65 #define FETCH_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FETCH_FILE, FetchFileClass))
66 #define IS_FETCH_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FETCH_FILE))
67 #define IS_FETCH_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FETCH_FILE))
68 #define FETCH_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FETCH_FILE, FetchFileClass))
69
70 typedef struct _FetchFile FetchFile;
71 typedef struct _FetchFileClass FetchFileClass;
72 #define _g_free0(var) (var = (g_free (var), NULL))
73
74 #define TYPE_PLAYER_CONTROLLER (player_controller_get_type ())
75 #define PLAYER_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLAYER_CONTROLLER, PlayerController))
76 #define PLAYER_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLAYER_CONTROLLER, PlayerControllerClass))
77 #define IS_PLAYER_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PLAYER_CONTROLLER))
78 #define IS_PLAYER_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PLAYER_CONTROLLER))
79 #define PLAYER_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PLAYER_CONTROLLER, PlayerControllerClass))
80
81 typedef struct _PlayerController PlayerController;
82 typedef struct _PlayerControllerClass PlayerControllerClass;
83 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
84 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
85 typedef struct _PlayerControllerPrivate PlayerControllerPrivate;
86
87 #define TYPE_MPRIS2_CONTROLLER (mpris2_controller_get_type ())
88 #define MPRIS2_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MPRIS2_CONTROLLER, Mpris2Controller))
89 #define MPRIS2_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MPRIS2_CONTROLLER, Mpris2ControllerClass))
90 #define IS_MPRIS2_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MPRIS2_CONTROLLER))
91 #define IS_MPRIS2_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MPRIS2_CONTROLLER))
92 #define MPRIS2_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MPRIS2_CONTROLLER, Mpris2ControllerClass))
93
94 typedef struct _Mpris2Controller Mpris2Controller;
95 typedef struct _Mpris2ControllerClass Mpris2ControllerClass;
96
97 #define PLAYER_CONTROLLER_TYPE_STATE (player_controller_state_get_type ())
98
99 struct _PlayerItem {
100 DbusmenuMenuitem parent_instance;
101 PlayerItemPrivate * priv;
102 };
103
104 struct _PlayerItemClass {
105 DbusmenuMenuitemClass parent_class;
106 };
107
108 struct _MetadataMenuitem {
109 PlayerItem parent_instance;
110 MetadataMenuitemPrivate * priv;
111 };
112
113 struct _MetadataMenuitemClass {
114 PlayerItemClass parent_class;
115 };
116
117 struct _MetadataMenuitemPrivate {
118 gchar* previous_temp_album_art_path;
119 };
120
121 struct _PlayerController {
122 GObject parent_instance;
123 PlayerControllerPrivate * priv;
124 gint current_state;
125 DbusmenuMenuitem* root_menu;
126 GeeArrayList* custom_items;
127 Mpris2Controller* mpris_bridge;
128 gboolean* use_playlists;
129 };
130
131 struct _PlayerControllerClass {
132 GObjectClass parent_class;
133 };
134
135 typedef enum {
136 PLAYER_CONTROLLER_STATE_OFFLINE,
137 PLAYER_CONTROLLER_STATE_INSTANTIATING,
138 PLAYER_CONTROLLER_STATE_READY,
139 PLAYER_CONTROLLER_STATE_CONNECTED,
140 PLAYER_CONTROLLER_STATE_DISCONNECTED
141 } PlayerControllerstate;
142
143
144 static gpointer metadata_menuitem_parent_class = NULL;
145 extern gchar* metadata_menuitem_album_art_cache_dir;
146 gchar* metadata_menuitem_album_art_cache_dir = NULL;
147 static FetchFile* metadata_menuitem_fetcher;
148 static FetchFile* metadata_menuitem_fetcher = NULL;
149
150 GType player_item_get_type (void) G_GNUC_CONST;
151 GType metadata_menuitem_get_type (void) G_GNUC_CONST;
152 #define METADATA_MENUITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_METADATA_MENUITEM, MetadataMenuitemPrivate))
153 enum {
154 METADATA_MENUITEM_DUMMY_PROPERTY
155 };
156 GType fetch_file_get_type (void) G_GNUC_CONST;
157 #define METADATA_MENUITEM_ALBUM_ART_DIR_SUFFIX "indicator/sound/album-art-cache"
158 GType player_controller_get_type (void) G_GNUC_CONST;
159 MetadataMenuitem* metadata_menuitem_new (PlayerController* parent);
160 MetadataMenuitem* metadata_menuitem_construct (GType object_type, PlayerController* parent);
161 static void metadata_menuitem_clean_album_art_temp_dir (void);
162 static gboolean metadata_menuitem_delete_album_art_contents (GFile* dir);
163 static gchar* metadata_menuitem_create_album_art_temp_dir (void);
164 void metadata_menuitem_fetch_art (MetadataMenuitem* self, const gchar* uri, const gchar* prop);
165 #define PLAYER_ITEM_EMPTY (-1)
166 FetchFile* fetch_file_new (const gchar* uri, const gchar* prop);
167 FetchFile* fetch_file_construct (GType object_type, const gchar* uri, const gchar* prop);
168 static void __lambda0_ (MetadataMenuitem* self);
169 static void metadata_menuitem_on_fetcher_failed (MetadataMenuitem* self);
170 static void ___lambda0__fetch_file_failed (FetchFile* _sender, gpointer self);
171 static void metadata_menuitem_on_fetcher_completed (MetadataMenuitem* self, GByteArray* update, const gchar* property);
172 static void _metadata_menuitem_on_fetcher_completed_fetch_file_completed (FetchFile* _sender, GByteArray* data, const gchar* property, gpointer self);
173 void fetch_file_fetch_data (FetchFile* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
174 void fetch_file_fetch_data_finish (FetchFile* self, GAsyncResult* _res_);
175 static void metadata_menuitem_real_handle_event (DbusmenuMenuitem* base, const gchar* name, GVariant* input_value, guint timestamp);
176 PlayerController* player_item_get_owner (PlayerItem* self);
177 GType mpris2_controller_get_type (void) G_GNUC_CONST;
178 GType player_controller_state_get_type (void) G_GNUC_CONST;
179 void player_controller_instantiate (PlayerController* self);
180 void mpris2_controller_expose (Mpris2Controller* self);
181 void metadata_menuitem_alter_label (MetadataMenuitem* self, const gchar* new_title);
182 void metadata_menuitem_toggle_active_triangle (MetadataMenuitem* self, gboolean update);
183 void metadata_menuitem_should_collapse (MetadataMenuitem* self, gboolean collapse);
184 GeeHashSet* metadata_menuitem_attributes_format (void);
185 GeeHashSet* metadata_menuitem_relevant_attributes_for_ui (void);
186 static GObject * metadata_menuitem_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
187 GAppInfo* player_controller_get_app_info (PlayerController* self);
188 const gchar* player_controller_get_icon_name (PlayerController* self);
189 void player_item_reset (PlayerItem* self, GeeHashSet* attrs);
190 static void metadata_menuitem_finalize (GObject* obj);
191
192
193 MetadataMenuitem* metadata_menuitem_construct (GType object_type, PlayerController* parent) {
194 MetadataMenuitem * self = NULL;
195 PlayerController* _tmp0_;
196 g_return_val_if_fail (parent != NULL, NULL);
197 _tmp0_ = parent;
198 self = (MetadataMenuitem*) g_object_new (object_type, "item-type", DBUSMENU_METADATA_MENUITEM_TYPE, "owner", _tmp0_, NULL);
199 return self;
200 }
201
202
203 MetadataMenuitem* metadata_menuitem_new (PlayerController* parent) {
204 return metadata_menuitem_construct (TYPE_METADATA_MENUITEM, parent);
205 }
206
207
208 static void metadata_menuitem_clean_album_art_temp_dir (void) {
209 const gchar* _tmp0_ = NULL;
210 gchar* _tmp1_ = NULL;
211 gchar* path;
212 const gchar* _tmp2_;
213 GFile* _tmp3_ = NULL;
214 GFile* album_art_dir;
215 GFile* _tmp4_;
216 gboolean _tmp5_ = FALSE;
217 _tmp0_ = g_get_user_cache_dir ();
218 _tmp1_ = g_build_filename (_tmp0_, METADATA_MENUITEM_ALBUM_ART_DIR_SUFFIX, NULL);
219 path = _tmp1_;
220 _tmp2_ = path;
221 _tmp3_ = g_file_new_for_path (_tmp2_);
222 album_art_dir = _tmp3_;
223 _tmp4_ = album_art_dir;
224 _tmp5_ = metadata_menuitem_delete_album_art_contents (_tmp4_);
225 if (_tmp5_ == FALSE) {
226 const gchar* _tmp6_;
227 _tmp6_ = path;
228 g_warning ("metadata-menu-item.vala:58: could not remove the temp album art files " \
229 "%s", _tmp6_);
230 }
231 _g_object_unref0 (album_art_dir);
232 _g_free0 (path);
233 }
234
235
236 static gchar* metadata_menuitem_create_album_art_temp_dir (void) {
237 gchar* result = NULL;
238 const gchar* _tmp0_ = NULL;
239 gchar* _tmp1_ = NULL;
240 gchar* path;
241 const gchar* _tmp2_;
242 gint _tmp3_ = 0;
243 _tmp0_ = g_get_user_cache_dir ();
244 _tmp1_ = g_build_filename (_tmp0_, METADATA_MENUITEM_ALBUM_ART_DIR_SUFFIX, NULL);
245 path = _tmp1_;
246 _tmp2_ = path;
247 _tmp3_ = g_mkdir_with_parents (_tmp2_, 0700);
248 if (_tmp3_ == (-1)) {
249 const gchar* _tmp4_;
250 _tmp4_ = path;
251 g_warning ("metadata-menu-item.vala:66: could not create temp dir %s for remote al" \
252 "bum art, it must have been created already", _tmp4_);
253 }
254 result = path;
255 return result;
256 }
257
258
259 static const gchar* string_to_string (const gchar* self) {
260 const gchar* result = NULL;
261 g_return_val_if_fail (self != NULL, NULL);
262 result = self;
263 return result;
264 }
265
266
267 static gboolean metadata_menuitem_delete_album_art_contents (GFile* dir) {
268 gboolean result = FALSE;
269 gboolean _result_;
270 GError * _inner_error_ = NULL;
271 g_return_val_if_fail (dir != NULL, FALSE);
272 _result_ = TRUE;
273 {
274 GFile* _tmp0_;
275 GFileEnumerator* _tmp1_ = NULL;
276 GFileEnumerator* e;
277 _tmp0_ = dir;
278 _tmp1_ = g_file_enumerate_children (_tmp0_, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &_inner_error_);
279 e = _tmp1_;
280 if (_inner_error_ != NULL) {
281 goto __catch3_g_error;
282 }
283 while (TRUE) {
284 GFileEnumerator* _tmp2_;
285 GFileInfo* _tmp3_ = NULL;
286 GFileInfo* file;
287 GFileInfo* _tmp4_;
288 GFileInfo* _tmp5_;
289 const gchar* _tmp6_ = NULL;
290 GFile* _tmp7_;
291 GFileInfo* _tmp8_;
292 const gchar* _tmp9_ = NULL;
293 GFile* _tmp10_ = NULL;
294 GFile* child;
295 _tmp2_ = e;
296 _tmp3_ = g_file_enumerator_next_file (_tmp2_, NULL, &_inner_error_);
297 file = _tmp3_;
298 if (_inner_error_ != NULL) {
299 _g_object_unref0 (e);
300 goto __catch3_g_error;
301 }
302 _tmp4_ = file;
303 if (_tmp4_ == NULL) {
304 _g_object_unref0 (file);
305 break;
306 }
307 _tmp5_ = file;
308 _tmp6_ = g_file_info_get_name (_tmp5_);
309 g_debug ("metadata-menu-item.vala:85: file name = %s", _tmp6_);
310 _tmp7_ = dir;
311 _tmp8_ = file;
312 _tmp9_ = g_file_info_get_name (_tmp8_);
313 _tmp10_ = g_file_get_child (_tmp7_, _tmp9_);
314 child = _tmp10_;
315 {
316 GFile* _tmp11_;
317 _tmp11_ = child;
318 g_file_delete (_tmp11_, NULL, &_inner_error_);
319 if (_inner_error_ != NULL) {
320 goto __catch4_g_error;
321 }
322 }
323 goto __finally4;
324 __catch4_g_error:
325 {
326 GError* error_ = NULL;
327 GFile* _tmp12_;
328 gchar* _tmp13_ = NULL;
329 gchar* _tmp14_;
330 const gchar* _tmp15_ = NULL;
331 GError* _tmp16_;
332 const gchar* _tmp17_;
333 const gchar* _tmp18_ = NULL;
334 gchar* _tmp19_ = NULL;
335 gchar* _tmp20_;
336 error_ = _inner_error_;
337 _inner_error_ = NULL;
338 _tmp12_ = child;
339 _tmp13_ = g_file_get_basename (_tmp12_);
340 _tmp14_ = _tmp13_;
341 _tmp15_ = string_to_string (_tmp14_);
342 _tmp16_ = error_;
343 _tmp17_ = _tmp16_->message;
344 _tmp18_ = string_to_string (_tmp17_);
345 _tmp19_ = g_strconcat ("Unable to delete file '", _tmp15_, ": ", _tmp18_, NULL);
346 _tmp20_ = _tmp19_;
347 g_warning ("metadata-menu-item.vala:92: %s", _tmp20_);
348 _g_free0 (_tmp20_);
349 _g_free0 (_tmp14_);
350 _result_ = FALSE;
351 _g_error_free0 (error_);
352 }
353 __finally4:
354 if (_inner_error_ != NULL) {
355 _g_object_unref0 (child);
356 _g_object_unref0 (file);
357 _g_object_unref0 (e);
358 goto __catch3_g_error;
359 }
360 _g_object_unref0 (child);
361 _g_object_unref0 (file);
362 }
363 _g_object_unref0 (e);
364 }
365 goto __finally3;
366 __catch3_g_error:
367 {
368 GError* _error_ = NULL;
369 GFile* _tmp21_;
370 gchar* _tmp22_ = NULL;
371 gchar* _tmp23_;
372 const gchar* _tmp24_ = NULL;
373 gchar* _tmp25_ = NULL;
374 gchar* _tmp26_;
375 GError* _tmp27_;
376 const gchar* _tmp28_;
377 _error_ = _inner_error_;
378 _inner_error_ = NULL;
379 _tmp21_ = dir;
380 _tmp22_ = g_file_get_basename (_tmp21_);
381 _tmp23_ = _tmp22_;
382 _tmp24_ = string_to_string (_tmp23_);
383 _tmp25_ = g_strconcat ("Unable to read files from directory '", _tmp24_, "': %s", NULL);
384 _tmp26_ = _tmp25_;
385 _tmp27_ = _error_;
386 _tmp28_ = _tmp27_->message;
387 g_warning (_tmp26_, _tmp28_);
388 _g_free0 (_tmp26_);
389 _g_free0 (_tmp23_);
390 _result_ = FALSE;
391 _g_error_free0 (_error_);
392 }
393 __finally3:
394 if (_inner_error_ != NULL) {
395 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
396 g_clear_error (&_inner_error_);
397 return FALSE;
398 }
399 result = _result_;
400 return result;
401 }
402
403
404 static gchar* string_strip (const gchar* self) {
405 gchar* result = NULL;
406 gchar* _tmp0_ = NULL;
407 gchar* _result_;
408 const gchar* _tmp1_;
409 g_return_val_if_fail (self != NULL, NULL);
410 _tmp0_ = g_strdup (self);
411 _result_ = _tmp0_;
412 _tmp1_ = _result_;
413 g_strstrip (_tmp1_);
414 result = _result_;
415 return result;
416 }
417
418
419 static void __lambda0_ (MetadataMenuitem* self) {
420 metadata_menuitem_on_fetcher_failed (self);
421 }
422
423
424 static void ___lambda0__fetch_file_failed (FetchFile* _sender, gpointer self) {
425 __lambda0_ (self);
426 }
427
428
429 static void _metadata_menuitem_on_fetcher_completed_fetch_file_completed (FetchFile* _sender, GByteArray* data, const gchar* property, gpointer self) {
430 metadata_menuitem_on_fetcher_completed (self, data, property);
431 }
432
433
434 void metadata_menuitem_fetch_art (MetadataMenuitem* self, const gchar* uri, const gchar* prop) {
435 const gchar* _tmp0_;
436 GFile* _tmp1_ = NULL;
437 GFile* art_file;
438 GFile* _tmp2_;
439 gboolean _tmp3_ = FALSE;
440 const gchar* _tmp19_;
441 const gchar* _tmp20_;
442 const gchar* _tmp21_;
443 const gchar* _tmp22_;
444 FetchFile* _tmp23_;
445 FetchFile* _tmp24_;
446 FetchFile* _tmp25_;
447 FetchFile* _tmp26_;
448 GError * _inner_error_ = NULL;
449 g_return_if_fail (self != NULL);
450 g_return_if_fail (uri != NULL);
451 g_return_if_fail (prop != NULL);
452 _tmp0_ = uri;
453 _tmp1_ = g_file_new_for_uri (_tmp0_);
454 art_file = _tmp1_;
455 _tmp2_ = art_file;
456 _tmp3_ = g_file_is_native (_tmp2_);
457 if (_tmp3_ == TRUE) {
458 GFile* _tmp4_;
459 gboolean _tmp5_ = FALSE;
460 gchar* path = NULL;
461 _tmp4_ = art_file;
462 _tmp5_ = g_file_query_exists (_tmp4_, NULL);
463 if (_tmp5_ == FALSE) {
464 const gchar* _tmp6_;
465 _tmp6_ = prop;
466 dbusmenu_menuitem_property_set_int ((DbusmenuMenuitem*) self, _tmp6_, PLAYER_ITEM_EMPTY);
467 _g_object_unref0 (art_file);
468 return;
469 }
470 {
471 const gchar* _tmp7_;
472 gchar* _tmp8_ = NULL;
473 gchar* _tmp9_;
474 gchar* _tmp10_ = NULL;
475 gchar* _tmp11_;
476 gchar* _tmp12_;
477 const gchar* _tmp13_;
478 gchar* _tmp14_ = NULL;
479 gchar* _tmp15_;
480 const gchar* _tmp16_;
481 const gchar* _tmp17_;
482 _tmp7_ = uri;
483 _tmp8_ = string_strip (_tmp7_);
484 _tmp9_ = _tmp8_;
485 _tmp10_ = g_filename_from_uri (_tmp9_, NULL, &_inner_error_);
486 _tmp11_ = _tmp10_;
487 _g_free0 (_tmp9_);
488 _tmp12_ = _tmp11_;
489 if (_inner_error_ != NULL) {
490 if (_inner_error_->domain == G_CONVERT_ERROR) {
491 goto __catch5_g_convert_error;
492 }
493 _g_free0 (path);
494 _g_object_unref0 (art_file);
495 g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
496 g_clear_error (&_inner_error_);
497 return;
498 }
499 _g_free0 (path);
500 path = _tmp12_;
501 _tmp13_ = uri;
502 _tmp14_ = string_strip (_tmp13_);
503 _tmp15_ = _tmp14_;
504 g_debug ("metadata-menu-item.vala:116: Populating the artwork field with %s", _tmp15_);
505 _g_free0 (_tmp15_);
506 _tmp16_ = prop;
507 _tmp17_ = path;
508 dbusmenu_menuitem_property_set ((DbusmenuMenuitem*) self, _tmp16_, _tmp17_);
509 }
510 goto __finally5;
511 __catch5_g_convert_error:
512 {
513 GError* e = NULL;
514 const gchar* _tmp18_;
515 e = _inner_error_;
516 _inner_error_ = NULL;
517 _tmp18_ = uri;
518 g_warning ("metadata-menu-item.vala:120: Problem converting URI %s to file path", _tmp18_);
519 _g_error_free0 (e);
520 }
521 __finally5:
522 if (_inner_error_ != NULL) {
523 _g_free0 (path);
524 _g_object_unref0 (art_file);
525 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
526 g_clear_error (&_inner_error_);
527 return;
528 }
529 _g_free0 (path);
530 _g_object_unref0 (art_file);
531 return;
532 }
533 _tmp19_ = metadata_menuitem_album_art_cache_dir;
534 g_debug ("metadata-menu-item.vala:126: fetch_art -remotely %s", _tmp19_);
535 _tmp20_ = metadata_menuitem_album_art_cache_dir;
536 if (_tmp20_ == NULL) {
537 _g_object_unref0 (art_file);
538 return;
539 }
540 _tmp21_ = uri;
541 _tmp22_ = prop;
542 _tmp23_ = fetch_file_new (_tmp21_, _tmp22_);
543 _g_object_unref0 (metadata_menuitem_fetcher);
544 metadata_menuitem_fetcher = _tmp23_;
545 _tmp24_ = metadata_menuitem_fetcher;
546 g_signal_connect_object (_tmp24_, "failed", (GCallback) ___lambda0__fetch_file_failed, self, 0);
547 _tmp25_ = metadata_menuitem_fetcher;
548 g_signal_connect_object (_tmp25_, "completed", (GCallback) _metadata_menuitem_on_fetcher_completed_fetch_file_completed, self, 0);
549 _tmp26_ = metadata_menuitem_fetcher;
550 fetch_file_fetch_data (_tmp26_, NULL, NULL);
551 _g_object_unref0 (art_file);
552 }
553
554
555 static void metadata_menuitem_on_fetcher_failed (MetadataMenuitem* self) {
556 g_return_if_fail (self != NULL);
557 g_warning ("metadata-menu-item.vala:141: on_fetcher_failed -> could not fetch artw" \
558 "ork");
559 }
560
561
562 static gpointer _g_object_ref0 (gpointer self) {
563 return self ? g_object_ref (self) : NULL;
564 }
565
566
567 static void metadata_menuitem_on_fetcher_completed (MetadataMenuitem* self, GByteArray* update, const gchar* property) {
568 GError * _inner_error_ = NULL;
569 g_return_if_fail (self != NULL);
570 g_return_if_fail (update != NULL);
571 g_return_if_fail (property != NULL);
572 {
573 GdkPixbufLoader* _tmp0_;
574 GdkPixbufLoader* loader;
575 GdkPixbufLoader* _tmp1_;
576 GByteArray* _tmp2_;
577 guint8* _tmp3_;
578 gint _tmp3__length1;
579 GdkPixbufLoader* _tmp4_;
580 GdkPixbufLoader* _tmp5_;
581 GdkPixbuf* _tmp6_ = NULL;
582 GdkPixbuf* _tmp7_;
583 GdkPixbuf* icon;
584 const gchar* _tmp8_;
585 gchar* _tmp9_ = NULL;
586 gchar* path;
587 const gchar* _tmp10_;
588 gint _tmp11_ = 0;
589 gint r;
590 gint _tmp12_;
591 _tmp0_ = gdk_pixbuf_loader_new ();
592 loader = _tmp0_;
593 _tmp1_ = loader;
594 _tmp2_ = update;
595 _tmp3_ = _tmp2_->data;
596 _tmp3__length1 = (gint) _tmp2_->len;
597 gdk_pixbuf_loader_write (_tmp1_, _tmp3_, (gsize) _tmp3__length1, &_inner_error_);
598 if (_inner_error_ != NULL) {
599 _g_object_unref0 (loader);
600 goto __catch6_g_error;
601 }
602 _tmp4_ = loader;
603 gdk_pixbuf_loader_close (_tmp4_, &_inner_error_);
604 if (_inner_error_ != NULL) {
605 _g_object_unref0 (loader);
606 goto __catch6_g_error;
607 }
608 _tmp5_ = loader;
609 _tmp6_ = gdk_pixbuf_loader_get_pixbuf (_tmp5_);
610 _tmp7_ = _g_object_ref0 (_tmp6_);
611 icon = _tmp7_;
612 _tmp8_ = metadata_menuitem_album_art_cache_dir;
613 _tmp9_ = g_strconcat (_tmp8_, "/downloaded-coverart-XXXXXX", NULL);
614 path = _tmp9_;
615 _tmp10_ = path;
616 _tmp11_ = g_mkstemp (_tmp10_);
617 r = _tmp11_;
618 _tmp12_ = r;
619 if (_tmp12_ != (-1)) {
620 GdkPixbuf* _tmp13_;
621 const gchar* _tmp14_;
622 GdkPixbufLoader* _tmp15_;
623 GdkPixbufFormat* _tmp16_ = NULL;
624 const gchar* _tmp17_ = NULL;
625 const gchar* _tmp18_;
626 const gchar* _tmp19_;
627 const gchar* _tmp20_;
628 const gchar* _tmp22_;
629 gchar* _tmp23_;
630 _tmp13_ = icon;
631 _tmp14_ = path;
632 _tmp15_ = loader;
633 _tmp16_ = gdk_pixbuf_loader_get_format (_tmp15_);
634 _tmp17_ = gdk_pixbuf_format_get_name (_tmp16_);
635 gdk_pixbuf_save (_tmp13_, _tmp14_, _tmp17_, &_inner_error_, NULL);
636 if (_inner_error_ != NULL) {
637 _g_free0 (path);
638 _g_object_unref0 (icon);
639 _g_object_unref0 (loader);
640 goto __catch6_g_error;
641 }
642 _tmp18_ = property;
643 _tmp19_ = path;
644 dbusmenu_menuitem_property_set ((DbusmenuMenuitem*) self, _tmp18_, _tmp19_);
645 _tmp20_ = self->priv->previous_temp_album_art_path;
646 if (_tmp20_ != NULL) {
647 const gchar* _tmp21_;
648 _tmp21_ = self->priv->previous_temp_album_art_path;
649 g_remove (_tmp21_);
650 }
651 _tmp22_ = path;
652 _tmp23_ = g_strdup (_tmp22_);
653 _g_free0 (self->priv->previous_temp_album_art_path);
654 self->priv->previous_temp_album_art_path = _tmp23_;
655 }
656 _g_free0 (path);
657 _g_object_unref0 (icon);
658 _g_object_unref0 (loader);
659 }
660 goto __finally6;
661 __catch6_g_error:
662 {
663 GError* e = NULL;
664 GError* _tmp24_;
665 const gchar* _tmp25_;
666 e = _inner_error_;
667 _inner_error_ = NULL;
668 _tmp24_ = e;
669 _tmp25_ = _tmp24_->message;
670 g_warning ("metadata-menu-item.vala:163: Problem creating file from bytearray fetc" \
671 "hed from the interweb - error: %s", _tmp25_);
672 _g_error_free0 (e);
673 }
674 __finally6:
675 if (_inner_error_ != NULL) {
676 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
677 g_clear_error (&_inner_error_);
678 return;
679 }
680 }
681
682
683 static void metadata_menuitem_real_handle_event (DbusmenuMenuitem* base, const gchar* name, GVariant* input_value, guint timestamp) {
684 MetadataMenuitem * self;
685 PlayerController* _tmp0_;
686 PlayerController* _tmp1_;
687 gint _tmp2_;
688 self = (MetadataMenuitem*) base;
689 g_return_if_fail (name != NULL);
690 g_return_if_fail (input_value != NULL);
691 _tmp0_ = player_item_get_owner ((PlayerItem*) self);
692 _tmp1_ = _tmp0_;
693 _tmp2_ = _tmp1_->current_state;
694 if (_tmp2_ == ((gint) PLAYER_CONTROLLER_STATE_OFFLINE)) {
695 PlayerController* _tmp3_;
696 PlayerController* _tmp4_;
697 _tmp3_ = player_item_get_owner ((PlayerItem*) self);
698 _tmp4_ = _tmp3_;
699 player_controller_instantiate (_tmp4_);
700 } else {
701 PlayerController* _tmp5_;
702 PlayerController* _tmp6_;
703 gint _tmp7_;
704 _tmp5_ = player_item_get_owner ((PlayerItem*) self);
705 _tmp6_ = _tmp5_;
706 _tmp7_ = _tmp6_->current_state;
707 if (_tmp7_ == ((gint) PLAYER_CONTROLLER_STATE_CONNECTED)) {
708 PlayerController* _tmp8_;
709 PlayerController* _tmp9_;
710 Mpris2Controller* _tmp10_;
711 _tmp8_ = player_item_get_owner ((PlayerItem*) self);
712 _tmp9_ = _tmp8_;
713 _tmp10_ = _tmp9_->mpris_bridge;
714 mpris2_controller_expose (_tmp10_);
715 }
716 }
717 }
718
719
720 void metadata_menuitem_alter_label (MetadataMenuitem* self, const gchar* new_title) {
721 const gchar* _tmp0_;
722 const gchar* _tmp1_;
723 g_return_if_fail (self != NULL);
724 g_return_if_fail (new_title != NULL);
CID 10719 - DEADCODE
After this line (or expression), the value of "_tmp0_" cannot be 0.
725 _tmp0_ = new_title;
CID 10719 - DEADCODE
On this path, the condition "_tmp0_ == NULL" cannot be true.
726 if (_tmp0_ == NULL) {
CID 10719 - DEADCODE
Execution cannot reach this statement "return;".
727 return;
728 }
729 _tmp1_ = new_title;
730 dbusmenu_menuitem_property_set ((DbusmenuMenuitem*) self, DBUSMENU_METADATA_MENUITEM_PLAYER_NAME, _tmp1_);
731 }
732
733
734 void metadata_menuitem_toggle_active_triangle (MetadataMenuitem* self, gboolean update) {
735 gboolean _tmp0_;
736 g_return_if_fail (self != NULL);
737 g_debug ("metadata-menu-item.vala:189: toggle active triangle");
738 _tmp0_ = update;
739 dbusmenu_menuitem_property_set_bool ((DbusmenuMenuitem*) self, DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING, _tmp0_);
740 }
741
742
743 void metadata_menuitem_should_collapse (MetadataMenuitem* self, gboolean collapse) {
744 gboolean _tmp0_;
745 g_return_if_fail (self != NULL);
746 _tmp0_ = collapse;
747 dbusmenu_menuitem_property_set_bool ((DbusmenuMenuitem*) self, DBUSMENU_METADATA_MENUITEM_HIDE_TRACK_DETAILS, _tmp0_);
748 }
749
750
751 GeeHashSet* metadata_menuitem_attributes_format (void) {
752 GeeHashSet* result = NULL;
753 GeeHashSet* _tmp0_;
754 GeeHashSet* attrs;
755 _tmp0_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL);
756 attrs = _tmp0_;
757 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_TITLE);
758 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_ARTIST);
759 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_ALBUM);
760 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_ARTURL);
761 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_PLAYER_NAME);
762 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_PLAYER_ICON);
763 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING);
764 result = attrs;
765 return result;
766 }
767
768
769 GeeHashSet* metadata_menuitem_relevant_attributes_for_ui (void) {
770 GeeHashSet* result = NULL;
771 GeeHashSet* _tmp0_;
772 GeeHashSet* attrs;
773 _tmp0_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL);
774 attrs = _tmp0_;
775 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_TITLE);
776 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_ARTIST);
777 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_ALBUM);
778 gee_abstract_collection_add ((GeeAbstractCollection*) attrs, DBUSMENU_METADATA_MENUITEM_ARTURL);
779 result = attrs;
780 return result;
781 }
782
783
784 static GObject * metadata_menuitem_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
785 GObject * obj;
786 GObjectClass * parent_class;
787 MetadataMenuitem * self;
788 gchar* _tmp0_ = NULL;
789 PlayerController* _tmp1_;
790 PlayerController* _tmp2_;
791 GAppInfo* _tmp3_;
792 GAppInfo* _tmp4_;
793 const gchar* _tmp5_ = NULL;
794 PlayerController* _tmp6_;
795 PlayerController* _tmp7_;
796 GAppInfo* _tmp8_;
797 GAppInfo* _tmp9_;
798 const gchar* _tmp10_ = NULL;
799 PlayerController* _tmp11_;
800 PlayerController* _tmp12_;
801 const gchar* _tmp13_;
802 const gchar* _tmp14_;
803 GeeHashSet* _tmp15_ = NULL;
804 GeeHashSet* _tmp16_;
805 parent_class = G_OBJECT_CLASS (metadata_menuitem_parent_class);
806 obj = parent_class->constructor (type, n_construct_properties, construct_properties);
807 self = METADATA_MENUITEM (obj);
808 metadata_menuitem_clean_album_art_temp_dir ();
809 _g_free0 (self->priv->previous_temp_album_art_path);
810 self->priv->previous_temp_album_art_path = NULL;
811 _tmp0_ = metadata_menuitem_create_album_art_temp_dir ();
812 _g_free0 (metadata_menuitem_album_art_cache_dir);
813 metadata_menuitem_album_art_cache_dir = _tmp0_;
814 _tmp1_ = player_item_get_owner ((PlayerItem*) self);
815 _tmp2_ = _tmp1_;
816 _tmp3_ = player_controller_get_app_info (_tmp2_);
817 _tmp4_ = _tmp3_;
818 _tmp5_ = g_app_info_get_name (_tmp4_);
819 g_debug ("metadata-menu-item.vala:42: JUST ABOUT TO ATTEMPT PLAYER NAME SETTING " \
820 "%s", _tmp5_);
821 _tmp6_ = player_item_get_owner ((PlayerItem*) self);
822 _tmp7_ = _tmp6_;
823 _tmp8_ = player_controller_get_app_info (_tmp7_);
824 _tmp9_ = _tmp8_;
825 _tmp10_ = g_app_info_get_name (_tmp9_);
826 dbusmenu_menuitem_property_set ((DbusmenuMenuitem*) self, DBUSMENU_METADATA_MENUITEM_PLAYER_NAME, _tmp10_);
827 _tmp11_ = player_item_get_owner ((PlayerItem*) self);
828 _tmp12_ = _tmp11_;
829 _tmp13_ = player_controller_get_icon_name (_tmp12_);
830 _tmp14_ = _tmp13_;
831 dbusmenu_menuitem_property_set ((DbusmenuMenuitem*) self, DBUSMENU_METADATA_MENUITEM_PLAYER_ICON, _tmp14_);
832 dbusmenu_menuitem_property_set_bool ((DbusmenuMenuitem*) self, DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING, FALSE);
833 dbusmenu_menuitem_property_set_bool ((DbusmenuMenuitem*) self, DBUSMENU_METADATA_MENUITEM_HIDE_TRACK_DETAILS, TRUE);
834 _tmp15_ = metadata_menuitem_relevant_attributes_for_ui ();
835 _tmp16_ = _tmp15_;
836 player_item_reset ((PlayerItem*) self, _tmp16_);
837 _g_object_unref0 (_tmp16_);
838 return obj;
839 }
840
841
842 static void metadata_menuitem_class_init (MetadataMenuitemClass * klass) {
843 metadata_menuitem_parent_class = g_type_class_peek_parent (klass);
844 g_type_class_add_private (klass, sizeof (MetadataMenuitemPrivate));
845 DBUSMENU_MENUITEM_CLASS (klass)->handle_event = metadata_menuitem_real_handle_event;
846 G_OBJECT_CLASS (klass)->constructor = metadata_menuitem_constructor;
847 G_OBJECT_CLASS (klass)->finalize = metadata_menuitem_finalize;
848 }
849
850
851 static void metadata_menuitem_instance_init (MetadataMenuitem * self) {
852 self->priv = METADATA_MENUITEM_GET_PRIVATE (self);
853 }
854
855
856 static void metadata_menuitem_finalize (GObject* obj) {
857 MetadataMenuitem * self;
858 self = METADATA_MENUITEM (obj);
859 _g_free0 (self->priv->previous_temp_album_art_path);
860 G_OBJECT_CLASS (metadata_menuitem_parent_class)->finalize (obj);
861 }
862
863
864 GType metadata_menuitem_get_type (void) {
865 static volatile gsize metadata_menuitem_type_id__volatile = 0;
866 if (g_once_init_enter (&metadata_menuitem_type_id__volatile)) {
867 static const GTypeInfo g_define_type_info = { sizeof (MetadataMenuitemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) metadata_menuitem_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MetadataMenuitem), 0, (GInstanceInitFunc) metadata_menuitem_instance_init, NULL };
868 GType metadata_menuitem_type_id;
869 metadata_menuitem_type_id = g_type_register_static (TYPE_PLAYER_ITEM, "MetadataMenuitem", &g_define_type_info, 0);
870 g_once_init_leave (&metadata_menuitem_type_id__volatile, metadata_menuitem_type_id);
871 }
872 return metadata_menuitem_type_id__volatile;
873 }