aboutsummaryrefslogtreecommitdiff
path: root/src/metadata-menu-item.c
diff options
context:
space:
mode:
authorSebastien Bacher <seb128@ubuntu.com>2010-09-08 12:24:23 +0200
committerSebastien Bacher <seb128@ubuntu.com>2010-09-08 12:24:23 +0200
commitb347212eb1cb41fb9739a9873b0ff8eb8abb4b77 (patch)
tree3c9cb3c86b5668c2c03155c60a041f6cc85d28ba /src/metadata-menu-item.c
parent80e5ad4f83a8b1218133761de11d433a7854041e (diff)
downloadayatana-indicator-sound-b347212eb1cb41fb9739a9873b0ff8eb8abb4b77.tar.gz
ayatana-indicator-sound-b347212eb1cb41fb9739a9873b0ff8eb8abb4b77.tar.bz2
ayatana-indicator-sound-b347212eb1cb41fb9739a9873b0ff8eb8abb4b77.zip
Import upstream version 0.4.2
Diffstat (limited to 'src/metadata-menu-item.c')
-rw-r--r--src/metadata-menu-item.c367
1 files changed, 364 insertions, 3 deletions
diff --git a/src/metadata-menu-item.c b/src/metadata-menu-item.c
index 311057e..07f18e5 100644
--- a/src/metadata-menu-item.c
+++ b/src/metadata-menu-item.c
@@ -1,4 +1,4 @@
-/* metadata-menu-item.c generated by valac 0.9.7, the Vala compiler
+/* metadata-menu-item.c generated by valac 0.9.8, the Vala compiler
* generated from metadata-menu-item.vala, do not modify */
/*
@@ -26,10 +26,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libdbusmenu-glib/menuitem-proxy.h>
#include <libdbusmenu-glib/menuitem.h>
#include <libdbusmenu-glib/server.h>
-#include <common-defs.h>
-#include <gee.h>
#include <stdlib.h>
#include <string.h>
+#include <common-defs.h>
+#include <gee.h>
+#include <gio/gio.h>
+#include <gdk-pixbuf/gdk-pixdata.h>
+#include <glib/gstdio.h>
#define TYPE_PLAYER_ITEM (player_item_get_type ())
@@ -53,7 +56,19 @@ typedef struct _PlayerItemPrivate PlayerItemPrivate;
typedef struct _MetadataMenuitem MetadataMenuitem;
typedef struct _MetadataMenuitemClass MetadataMenuitemClass;
typedef struct _MetadataMenuitemPrivate MetadataMenuitemPrivate;
+
+#define TYPE_FETCH_FILE (fetch_file_get_type ())
+#define FETCH_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FETCH_FILE, FetchFile))
+#define FETCH_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FETCH_FILE, FetchFileClass))
+#define IS_FETCH_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FETCH_FILE))
+#define IS_FETCH_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FETCH_FILE))
+#define FETCH_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FETCH_FILE, FetchFileClass))
+
+typedef struct _FetchFile FetchFile;
+typedef struct _FetchFileClass FetchFileClass;
+#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
+#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
struct _PlayerItem {
DbusmenuMenuitem parent_instance;
@@ -73,18 +88,44 @@ struct _MetadataMenuitemClass {
PlayerItemClass parent_class;
};
+struct _MetadataMenuitemPrivate {
+ char* previous_temp_album_art_path;
+};
+
+extern char* metadata_menuitem_album_art_cache_dir;
+char* metadata_menuitem_album_art_cache_dir = NULL;
+static FetchFile* metadata_menuitem_fetcher;
+static FetchFile* metadata_menuitem_fetcher = NULL;
static gpointer metadata_menuitem_parent_class = NULL;
GType player_item_get_type (void) G_GNUC_CONST;
GType metadata_menuitem_get_type (void) G_GNUC_CONST;
+#define METADATA_MENUITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_METADATA_MENUITEM, MetadataMenuitemPrivate))
enum {
METADATA_MENUITEM_DUMMY_PROPERTY
};
+GType fetch_file_get_type (void) G_GNUC_CONST;
+#define METADATA_MENUITEM_ALBUM_ART_DIR_SUFFIX "indicators/sound/album-art-cache"
MetadataMenuitem* metadata_menuitem_new (void);
MetadataMenuitem* metadata_menuitem_construct (GType object_type);
void player_item_reset (PlayerItem* self, GeeHashSet* attrs);
GeeHashSet* metadata_menuitem_attributes_format (void);
+static void metadata_menuitem_clean_album_art_temp_dir (void);
+static gboolean metadata_menuitem_delete_album_art_contents (GFile* dir);
+static char* metadata_menuitem_create_album_art_temp_dir (void);
+void metadata_menuitem_fetch_art (MetadataMenuitem* self, const char* uri, const char* prop);
+FetchFile* fetch_file_new (const char* uri, const char* prop);
+FetchFile* fetch_file_construct (GType object_type, const char* uri, const char* prop);
+static void _lambda0_ (MetadataMenuitem* self);
+static void metadata_menuitem_on_fetcher_failed (MetadataMenuitem* self);
+static void __lambda0__fetch_file_failed (FetchFile* _sender, gpointer self);
+static void metadata_menuitem_on_fetcher_completed (MetadataMenuitem* self, GByteArray* update, const char* property);
+static void _metadata_menuitem_on_fetcher_completed_fetch_file_completed (FetchFile* _sender, GByteArray* data, const char* property, gpointer self);
+void fetch_file_fetch_data (FetchFile* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
+void fetch_file_fetch_data_finish (FetchFile* self, GAsyncResult* _res_);
+static GObject * metadata_menuitem_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
+static void metadata_menuitem_finalize (GObject* obj);
@@ -103,6 +144,296 @@ MetadataMenuitem* metadata_menuitem_new (void) {
}
+static void metadata_menuitem_clean_album_art_temp_dir (void) {
+ char* path;
+ GFile* album_art_dir;
+ path = g_build_filename (g_get_user_cache_dir (), METADATA_MENUITEM_ALBUM_ART_DIR_SUFFIX, NULL);
+ album_art_dir = g_file_new_for_path (path);
+ if (metadata_menuitem_delete_album_art_contents (album_art_dir) == FALSE) {
+ g_warning ("metadata-menu-item.vala:52: could not remove the temp album art files " \
+"%s", path);
+ }
+ _g_object_unref0 (album_art_dir);
+ _g_free0 (path);
+}
+
+
+static char* metadata_menuitem_create_album_art_temp_dir (void) {
+ char* result = NULL;
+ char* path;
+ path = g_build_filename (g_get_user_cache_dir (), METADATA_MENUITEM_ALBUM_ART_DIR_SUFFIX, NULL);
+ if (g_mkdir (path, 0700) == (-1)) {
+ g_warning ("metadata-menu-item.vala:60: could not create a temp dir for remote alb" \
+"um art, it must have been created already");
+ }
+ result = path;
+ return result;
+}
+
+
+static const char* string_to_string (const char* self) {
+ const char* result = NULL;
+ g_return_val_if_fail (self != NULL, NULL);
+ result = self;
+ return result;
+}
+
+
+static gboolean metadata_menuitem_delete_album_art_contents (GFile* dir) {
+ gboolean result = FALSE;
+ gboolean _result_;
+ GError * _inner_error_ = NULL;
+ g_return_val_if_fail (dir != NULL, FALSE);
+ _result_ = TRUE;
+ {
+ GFileEnumerator* e;
+ e = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &_inner_error_);
+ if (_inner_error_ != NULL) {
+ goto __catch0_g_error;
+ }
+ while (TRUE) {
+ GFileInfo* file;
+ GFile* child;
+ file = g_file_enumerator_next_file (e, NULL, &_inner_error_);
+ if (_inner_error_ != NULL) {
+ _g_object_unref0 (e);
+ goto __catch0_g_error;
+ }
+ g_debug ("metadata-menu-item.vala:76: file name = %s", g_file_info_get_name (file));
+ if (file == NULL) {
+ _g_object_unref0 (file);
+ break;
+ }
+ child = g_file_get_child (dir, g_file_info_get_name (file));
+ {
+ g_file_delete (child, NULL, &_inner_error_);
+ if (_inner_error_ != NULL) {
+ goto __catch1_g_error;
+ }
+ }
+ goto __finally1;
+ __catch1_g_error:
+ {
+ GError * error_;
+ error_ = _inner_error_;
+ _inner_error_ = NULL;
+ {
+ char* _tmp0_;
+ char* _tmp1_;
+ g_warning ("metadata-menu-item.vala:86: %s", _tmp1_ = g_strconcat ("Unable to delete file '", string_to_string (_tmp0_ = g_file_get_basename (child)), ": ", string_to_string (error_->message), NULL));
+ _g_free0 (_tmp1_);
+ _g_free0 (_tmp0_);
+ _result_ = FALSE;
+ _g_error_free0 (error_);
+ }
+ }
+ __finally1:
+ if (_inner_error_ != NULL) {
+ _g_object_unref0 (child);
+ _g_object_unref0 (file);
+ _g_object_unref0 (e);
+ goto __catch0_g_error;
+ }
+ _g_object_unref0 (child);
+ _g_object_unref0 (file);
+ }
+ _g_object_unref0 (e);
+ }
+ goto __finally0;
+ __catch0_g_error:
+ {
+ GError * _error_;
+ _error_ = _inner_error_;
+ _inner_error_ = NULL;
+ {
+ char* _tmp2_;
+ char* _tmp3_;
+ g_warning (_tmp3_ = g_strconcat ("Unable to read files from directory '", string_to_string (_tmp2_ = g_file_get_basename (dir)), "': %s", NULL), _error_->message);
+ _g_free0 (_tmp3_);
+ _g_free0 (_tmp2_);
+ _result_ = FALSE;
+ _g_error_free0 (_error_);
+ }
+ }
+ __finally0:
+ if (_inner_error_ != NULL) {
+ 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);
+ g_clear_error (&_inner_error_);
+ return FALSE;
+ }
+ result = _result_;
+ return result;
+}
+
+
+static char* string_strip (const char* self) {
+ char* result = NULL;
+ char* _result_;
+ g_return_val_if_fail (self != NULL, NULL);
+ _result_ = g_strdup (self);
+ g_strstrip (_result_);
+ result = _result_;
+ return result;
+}
+
+
+static void _lambda0_ (MetadataMenuitem* self) {
+ metadata_menuitem_on_fetcher_failed (self);
+}
+
+
+static void __lambda0__fetch_file_failed (FetchFile* _sender, gpointer self) {
+ _lambda0_ (self);
+}
+
+
+static void _metadata_menuitem_on_fetcher_completed_fetch_file_completed (FetchFile* _sender, GByteArray* data, const char* property, gpointer self) {
+ metadata_menuitem_on_fetcher_completed (self, data, property);
+}
+
+
+void metadata_menuitem_fetch_art (MetadataMenuitem* self, const char* uri, const char* prop) {
+ GFile* art_file;
+ FetchFile* _tmp4_;
+ GError * _inner_error_ = NULL;
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (uri != NULL);
+ g_return_if_fail (prop != NULL);
+ art_file = g_file_new_for_uri (uri);
+ if (g_file_is_native (art_file) == TRUE) {
+ char* path;
+ path = NULL;
+ {
+ char* _tmp0_;
+ char* _tmp1_;
+ char* _tmp2_;
+ char* _tmp3_;
+ _tmp2_ = (_tmp1_ = g_filename_from_uri (_tmp0_ = string_strip (uri), NULL, &_inner_error_), _g_free0 (_tmp0_), _tmp1_);
+ if (_inner_error_ != NULL) {
+ if (_inner_error_->domain == G_CONVERT_ERROR) {
+ goto __catch2_g_convert_error;
+ }
+ _g_free0 (path);
+ _g_object_unref0 (art_file);
+ 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);
+ g_clear_error (&_inner_error_);
+ return;
+ }
+ path = (_tmp3_ = _tmp2_, _g_free0 (path), _tmp3_);
+ dbusmenu_menuitem_property_set ((DbusmenuMenuitem*) self, prop, path);
+ }
+ goto __finally2;
+ __catch2_g_convert_error:
+ {
+ GError * e;
+ e = _inner_error_;
+ _inner_error_ = NULL;
+ {
+ g_warning ("metadata-menu-item.vala:108: Problem converting URI %s to file path", uri);
+ _g_error_free0 (e);
+ }
+ }
+ __finally2:
+ if (_inner_error_ != NULL) {
+ _g_free0 (path);
+ _g_object_unref0 (art_file);
+ 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);
+ g_clear_error (&_inner_error_);
+ return;
+ }
+ _g_free0 (path);
+ _g_object_unref0 (art_file);
+ return;
+ }
+ g_debug ("metadata-menu-item.vala:114: fetch_art -remotely %s", metadata_menuitem_album_art_cache_dir);
+ if (metadata_menuitem_album_art_cache_dir == NULL) {
+ _g_object_unref0 (art_file);
+ return;
+ }
+ metadata_menuitem_fetcher = (_tmp4_ = fetch_file_new (uri, prop), _g_object_unref0 (metadata_menuitem_fetcher), _tmp4_);
+ g_signal_connect_object (metadata_menuitem_fetcher, "failed", (GCallback) __lambda0__fetch_file_failed, self, 0);
+ g_signal_connect_object (metadata_menuitem_fetcher, "completed", (GCallback) _metadata_menuitem_on_fetcher_completed_fetch_file_completed, self, 0);
+ fetch_file_fetch_data (metadata_menuitem_fetcher, NULL, NULL);
+ _g_object_unref0 (art_file);
+}
+
+
+static void metadata_menuitem_on_fetcher_failed (MetadataMenuitem* self) {
+ g_return_if_fail (self != NULL);
+ g_warning ("metadata-menu-item.vala:129: on_fetcher_failed -> could not fetch artw" \
+"ork");
+}
+
+
+static gpointer _g_object_ref0 (gpointer self) {
+ return self ? g_object_ref (self) : NULL;
+}
+
+
+static void metadata_menuitem_on_fetcher_completed (MetadataMenuitem* self, GByteArray* update, const char* property) {
+ GError * _inner_error_ = NULL;
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (update != NULL);
+ g_return_if_fail (property != NULL);
+ {
+ GdkPixbufLoader* loader;
+ GdkPixbuf* icon;
+ char* path;
+ gint r;
+ loader = gdk_pixbuf_loader_new ();
+ gdk_pixbuf_loader_write (loader, update->data, (gsize) update->len, &_inner_error_);
+ if (_inner_error_ != NULL) {
+ _g_object_unref0 (loader);
+ goto __catch3_g_error;
+ }
+ gdk_pixbuf_loader_close (loader, &_inner_error_);
+ if (_inner_error_ != NULL) {
+ _g_object_unref0 (loader);
+ goto __catch3_g_error;
+ }
+ icon = _g_object_ref0 (gdk_pixbuf_loader_get_pixbuf (loader));
+ path = g_strconcat (metadata_menuitem_album_art_cache_dir, "/downloaded-coverart-XXXXXX", NULL);
+ r = g_mkstemp (path);
+ if (r != (-1)) {
+ char* _tmp0_;
+ gdk_pixbuf_save (icon, path, gdk_pixbuf_format_get_name (gdk_pixbuf_loader_get_format (loader)), &_inner_error_, NULL);
+ if (_inner_error_ != NULL) {
+ _g_free0 (path);
+ _g_object_unref0 (icon);
+ _g_object_unref0 (loader);
+ goto __catch3_g_error;
+ }
+ dbusmenu_menuitem_property_set ((DbusmenuMenuitem*) self, property, path);
+ if (self->priv->previous_temp_album_art_path != NULL) {
+ g_remove (self->priv->previous_temp_album_art_path);
+ }
+ self->priv->previous_temp_album_art_path = (_tmp0_ = g_strdup (path), _g_free0 (self->priv->previous_temp_album_art_path), _tmp0_);
+ }
+ _g_free0 (path);
+ _g_object_unref0 (icon);
+ _g_object_unref0 (loader);
+ }
+ goto __finally3;
+ __catch3_g_error:
+ {
+ GError * e;
+ e = _inner_error_;
+ _inner_error_ = NULL;
+ {
+ g_warning ("metadata-menu-item.vala:151: Problem creating file from bytearray fetc" \
+"hed from the interweb - error: %s", e->message);
+ _g_error_free0 (e);
+ }
+ }
+ __finally3:
+ if (_inner_error_ != NULL) {
+ 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);
+ g_clear_error (&_inner_error_);
+ return;
+ }
+}
+
+
GeeHashSet* metadata_menuitem_attributes_format (void) {
GeeHashSet* result = NULL;
GeeHashSet* attrs;
@@ -116,12 +447,42 @@ GeeHashSet* metadata_menuitem_attributes_format (void) {
}
+static GObject * metadata_menuitem_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
+ GObject * obj;
+ GObjectClass * parent_class;
+ MetadataMenuitem * self;
+ parent_class = G_OBJECT_CLASS (metadata_menuitem_parent_class);
+ obj = parent_class->constructor (type, n_construct_properties, construct_properties);
+ self = METADATA_MENUITEM (obj);
+ {
+ char* _tmp0_;
+ char* _tmp1_;
+ metadata_menuitem_clean_album_art_temp_dir ();
+ self->priv->previous_temp_album_art_path = (_tmp0_ = NULL, _g_free0 (self->priv->previous_temp_album_art_path), _tmp0_);
+ metadata_menuitem_album_art_cache_dir = (_tmp1_ = metadata_menuitem_create_album_art_temp_dir (), _g_free0 (metadata_menuitem_album_art_cache_dir), _tmp1_);
+ }
+ return obj;
+}
+
+
static void metadata_menuitem_class_init (MetadataMenuitemClass * klass) {
metadata_menuitem_parent_class = g_type_class_peek_parent (klass);
+ g_type_class_add_private (klass, sizeof (MetadataMenuitemPrivate));
+ G_OBJECT_CLASS (klass)->constructor = metadata_menuitem_constructor;
+ G_OBJECT_CLASS (klass)->finalize = metadata_menuitem_finalize;
}
static void metadata_menuitem_instance_init (MetadataMenuitem * self) {
+ self->priv = METADATA_MENUITEM_GET_PRIVATE (self);
+}
+
+
+static void metadata_menuitem_finalize (GObject* obj) {
+ MetadataMenuitem * self;
+ self = METADATA_MENUITEM (obj);
+ _g_free0 (self->priv->previous_temp_album_art_path);
+ G_OBJECT_CLASS (metadata_menuitem_parent_class)->finalize (obj);
}