build,core,plugins: Port to GDBus and GVariant
[profile/ivi/rygel.git] / src / plugins / external / rygel-external-album-art-factory.vala
1 /*
2  * Copyright (C) 2009 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
3  * Copyright (C) 2009 Nokia Corporation.
4  *
5  * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
6  *                               <zeeshan.ali@nokia.com>
7  *
8  * This file is part of Rygel.
9  *
10  * Rygel is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * Rygel is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  */
24
25 using FreeDesktop;
26
27 /**
28  * Factory for thumbnail from external plugins.
29  */
30 public class Rygel.External.AlbumArtFactory {
31     public async Thumbnail create (string service_name,
32                                    string object_path,
33                                    string host_ip) throws IOError {
34         Properties props = Bus.get_proxy_sync (BusType.SESSION,
35                                                service_name,
36                                                object_path);
37
38         var item_props = yield props.get_all (MediaItemProxy.IFACE);
39
40         return this.create_from_props (item_props, host_ip);
41     }
42
43     private Thumbnail create_from_props (HashTable<string,Variant> props,
44                                          string                    host_ip) {
45         var thumbnail = new AlbumArt ();
46
47         var value = props.lookup ("MIMEType");
48         thumbnail.mime_type = (string) value;
49
50         value = props.lookup ("URLs");
51         var uris = (string[]) value;
52         if (uris != null && uris[0] != null) {
53             thumbnail.uri = uris[0].replace ("@ADDRESS@", host_ip);
54         }
55
56         value = props.lookup ("Size");
57         if (value != null) {
58             thumbnail.size = (int64) value;
59         }
60
61         return thumbnail;
62     }
63 }