| 1 |
namespace Xmpp.Xep.JingleContentThumbnails { |
| 2 |
public const string NS_URI = "urn:xmpp:thumbs:1"; |
| 3 |
|
| 4 |
public Gee.List<Thumbnail> get_thumbnails(StanzaNode node) { |
| 5 |
var thumbnails = new Gee.ArrayList<Thumbnail>(); |
| 6 |
foreach (StanzaNode thumbnail_node in node.get_subnodes("thumbnail", Xep.JingleContentThumbnails.NS_URI)) { |
| 7 |
var thumbnail = Thumbnail.from_stanza_node(thumbnail_node); |
| 8 |
if (thumbnail != null) { |
| 9 |
thumbnails.add(thumbnail); |
| 10 |
} |
| 11 |
} |
| 12 |
return thumbnails; |
| 13 |
} |
| 14 |
|
| 15 |
public class Thumbnail { |
| 16 |
public string uri; |
| 17 |
public string? media_type; |
| 18 |
public int width; |
| 19 |
public int height; |
| 20 |
|
| 21 |
public StanzaNode to_stanza_node() { |
| 22 |
StanzaNode node = new StanzaNode.build("thumbnail", NS_URI).add_self_xmlns() |
| 23 |
.put_attribute("uri", this.uri); |
| 24 |
if (this.media_type != null) { |
| 25 |
node.put_attribute("media-type", this.media_type); |
| 26 |
} |
| 27 |
if (this.width != -1) { |
| 28 |
node.put_attribute("width", this.width.to_string()); |
| 29 |
} |
| 30 |
if (this.height != -1) { |
| 31 |
node.put_attribute("height", this.height.to_string()); |
| 32 |
} |
| 33 |
return node; |
| 34 |
} |
| 35 |
|
| 36 |
public static Thumbnail? from_stanza_node(StanzaNode node) { |
| 37 |
Thumbnail thumbnail = new Thumbnail(); |
| 38 |
thumbnail.uri = node.get_attribute("uri"); |
| 39 |
if (thumbnail.uri == null) { |
| 40 |
return null; |
| 41 |
} |
| 42 |
thumbnail.media_type = node.get_attribute("media-type"); |
| 43 |
thumbnail.width = node.get_attribute_int("width"); |
| 44 |
thumbnail.height = node.get_attribute_int("height"); |
| 45 |
return thumbnail; |
| 46 |
} |
| 47 |
} |
| 48 |
} |