[ease/plugins] Added the Flickr fetcher.
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease/plugins] Added the Flickr fetcher.
- Date: Sun, 22 Aug 2010 21:48:02 +0000 (UTC)
commit dc739f876bd3c16f5476e82a42d6f0593ca95dba
Author: Nate Stedman <natesm gmail com>
Date: Sun Aug 22 10:18:23 2010 -0400
Added the Flickr fetcher.
ease/Makefile.am | 1 +
ease/ease-import-dialog.vala | 11 +-
ease/ease-import-flickr-service.vala | 247 +++++----------------------------
3 files changed, 47 insertions(+), 212 deletions(-)
---
diff --git a/ease/Makefile.am b/ease/Makefile.am
index ea332cb..5f6bbf5 100644
--- a/ease/Makefile.am
+++ b/ease/Makefile.am
@@ -9,6 +9,7 @@ ease_SOURCES = \
ease-editor-window.vala \
ease-handle.vala \
ease-import-dialog.vala \
+ ease-import-flickr-media.vala \
ease-import-flickr-service.vala \
ease-import-oca-media.vala \
ease-import-oca-service.vala \
diff --git a/ease/ease-import-dialog.vala b/ease/ease-import-dialog.vala
index f13cc72..d8cbbdd 100644
--- a/ease/ease-import-dialog.vala
+++ b/ease/ease-import-dialog.vala
@@ -29,13 +29,18 @@ internal class Ease.ImportDialog : Gtk.Window
view.show_all();
Plugin.ImportService service = new OCAService();
- var item = new Source.Item.from_stock_icon(
+ var oca = new Source.Item.from_stock_icon(
"OpenClipArt", "gtk-go-down", new ImportWidget(service));
- group.add_item(item);
+ group.add_item(oca);
+
+ service = new FlickrService();
+ var flickr = new Source.Item.from_stock_icon(
+ "Flickr", "gtk-go-down", new ImportWidget(service));
+ group.add_item(flickr);
add(view);
view.show_all();
- item.select();
+ oca.select();
}
internal void run()
diff --git a/ease/ease-import-flickr-service.vala b/ease/ease-import-flickr-service.vala
index 8b9a117..1f13aab 100644
--- a/ease/ease-import-flickr-service.vala
+++ b/ease/ease-import-flickr-service.vala
@@ -2,7 +2,6 @@ using Rest;
using Json;
using Gtk;
-
/*
TODO :
- escaping the description tags (or show the markup maybe?)
@@ -16,60 +15,25 @@ using Gtk;
- show a tiny spinner when loading
*/
-public class FlickrFetcher {
+public class Ease.FlickrService : Plugin.ImportService {
/* Flickr stuff */
private const string api_key = "17c40bceda03e0d6f947b001e7c62058";
private const string secret = "a7c16179a409418b";
- private Rest.FlickrProxy proxy;
- // TODO : FlickrProxyCall is broken?
- private Rest.ProxyCall call;
-
/* Json parser */
- private Json.Parser parser;
-
- /* UI elements */
- private Gtk.Dialog dialog;
- private Gtk.Entry search_entry;
- private Gtk.Button search_button;
- private Gtk.IconView iconview;
- private Gtk.Builder builder;
- private Gtk.VBox vbox;
- private Gtk.Label infos;
-
- private Gtk.ListStore store;
-
- private Gdk.Pixbuf? gdk_pixbug_new_from_uri (string uri) {
-
- var file = File.new_for_uri (uri);
- FileInputStream filestream = null;
- try {
- filestream = file.read (null);
- } catch (Error e) {
- error ("Couldn't read distant file : %s", e.message);
- }
- assert (filestream != null);
- Gdk.Pixbuf pix;
- try {
- pix = new Gdk.Pixbuf.from_stream_at_scale (filestream,
- 150,
- 150,
- true,
- null);
- } catch (Error e) {
- error ("Couldn't create pixbuf from file: %s", e.message);
- pix = null;
- }
- return pix;
+ private Json.Parser parser = new Json.Parser();
+
+ public override Rest.Proxy create_proxy()
+ {
+ return new Rest.FlickrProxy(api_key, secret);
}
-
-
- private string get_flickr_photos_from_tags (string tags) {
-
- call = proxy.new_call ();
+
+ public override Rest.ProxyCall create_call(Rest.Proxy proxy, string search)
+ {
+ var call = proxy.new_call ();
call.set_function ("flickr.photos.search");
- call.add_params ("tags", tags,
+ call.add_params ("tags", search,
"tag_mode", "all",
"per_page", "10",
"format", "json",
@@ -81,37 +45,10 @@ public class FlickrFetcher {
/* Extras info to fetch. */
"extras", "description,licence",
null);
- // TODO : asyncing
- try {
- call.run (null);
- } catch (Error e) {
- print ("Couldn't make call: %s\n", e.message);
- var err = new Gtk.InfoBar.with_buttons ("gtk-quit", 0,
- "gtk-refresh", 1, null);
- var label = new Gtk.Label ("Unable to retrieve pictures." +
- "Make sure you're connected to the Internet.");
- ((Gtk.Box)err.get_content_area()).add (label);
- err.set_message_type (Gtk.MessageType.WARNING);
- err.response.connect ( (dialog, response) =>
- {
- if (response != 0) {
-
- } else {
- this.dialog.destroy ();
- return;
- }
- });
-
- err.show_all ();
- vbox.pack_start (err, false, false, 10);
- vbox.reorder_child (err, 1);
- }
-
- string answer = call.get_payload ();
- return answer;
+ return call;
}
- private void parse_flickr_photos (string jsondata) {
+ public override void parse_data(string jsondata) {
if (jsondata == null) {
return;
@@ -123,21 +60,20 @@ public class FlickrFetcher {
error ("Couldn't parse JSON data: %s", e.message);
}
- print ("==START PAYLOAD==\n%s\n==END PAYLOAD==", jsondata);
+ //print ("==START PAYLOAD==\n%s\n==END PAYLOAD==", jsondata);
Json.Object obj = parser.get_root().get_object ();
var stat = obj.get_string_member ("stat");
if (stat != "ok") {
- print ("The request failed : \nError code: %G\nMessage: %s",
- obj.get_int_member ("code"),
- obj.get_string_member ("message"));
+ warning("The request failed : \nError code: %G\nMessage: %s",
+ obj.get_int_member ("code"),
+ obj.get_string_member ("message"));
return;
}
var photos = obj.get_object_member ("photos");
var photo_array = photos.get_array_member ("photo");
- store.clear ();
// TODO : optimization
photo_array.foreach_element ( (array, index, element) =>
{
@@ -150,134 +86,27 @@ public class FlickrFetcher {
public void iconview_add_thumbnail_from_json (Json.Array array,
uint index,
Json.Node element)
- {
- Gtk.TreeIter iter;
- Json.Object photo = element.get_object ();
- int64 farm_int = photo.get_int_member ("farm");
-
- string farm = @"$farm_int";
- string secret = photo.get_string_member ("secret");
- string server = photo.get_string_member ("server");
- string id = photo.get_string_member ("id");
- string http = "http://farm";
- string flickr = ".static.flickr.com/";
-
- string uri = http + farm + flickr + server + "/" + id + "_" + secret + "_t.jpg";
- // TODO : unittest to track Flickr API changes.
-
- var pixbuf = gdk_pixbug_new_from_uri (uri);
-
- string title = photo.get_string_member ("title");
- string description = photo.get_object_member ("description").get_string_member ("_content");
- string author = photo.get_string_member ("owner");
- // We did specified license in the extras, but it doesn't appear in the payload
- // string licence = photo.get_string_member ("license");
-
- /* Adding to the IconView */
- store.append (out iter);
- store.set (iter,
- 0, id,
- 1, title,
- 2, pixbuf,
- 3, description,
- 4, author,
-// 5, licence,
- -1);
- }
-
-
- [CCode (instance_pos = -1)]
- public void on_item_activated (Gtk.IconView view, Gtk.TreePath path) {
-
- debug ("We have a signal.");
-
- }
-
- [CCode (instance_pos = -1)]
- public void on_search_button (Button? b) {
-
- string entry = this.search_entry.get_text ();
- // convert spaces to comas
- string tags = entry.delimit (" ", ',');
- search_entry.set_text (tags);
-
- string answer = get_flickr_photos_from_tags (tags);
- parse_flickr_photos (answer);
- }
-
- [CCode (instance_pos = -1)]
- public void on_selection_changed (Gtk.IconView view) {
-
- string description;
- string title;
- string author;
- string license;
-
- List<Gtk.TreePath> selected = view.get_selected_items ();
- if (selected.first () == null) {
- debug ("No data!");
- return;
- }
- Gtk.TreeIter iter;
- store.get_iter (out iter, selected.data);
- store.get (iter,
- 1, out title,
- 3, out description,
- 4, out author,
- 5, out license, -1);
-
- string informations = ("<b>Title : </b>%s\n" + title + "\n" +
- "<b>Description : </b>" + description + "\n" +
- "<b>Author : </b>" + author);
- /* FIXME : We have to write the markup cause some authors put some useful
- links in their description (official webpage and such), and I don't
- think there's any security issue with that. Still, we have a problem when
- Pango fails at parsing markup, like the "rel" attribute. We should either
- handle that error and show without markup then, or find a way to parse the
- rel attribute, which is do-able only if we parse ourselves. And I'm way too
- lazy to do it. */
- infos.set_markup (informations);
- }
-
- [CCode (instance_pos = -1)]
- public void on_dialog_response (Gtk.Dialog dialog, int response) {
-
- stdout.printf ("In!\n");
- }
-
- public FlickrFetcher() {
-
- proxy = new Rest.FlickrProxy (api_key, secret);
- parser = new Json.Parser ();
- builder = new Gtk.Builder ();
-
- try {
- builder.add_from_file ("flickr.ui");
- } catch (Error e) {
- stdout.printf ("Error parsing UI : %s\n", e.message);
- builder = null;
- }
-
- assert (builder != null);
-
- dialog = builder.get_object ("dialog1") as Gtk.Dialog;
- iconview = builder.get_object ("iconview1") as Gtk.IconView;
- search_button = builder.get_object ("searchbutton") as Gtk.Button;
- search_entry = builder.get_object ("searchentry") as Gtk.Entry;
- store = builder.get_object ("liststore1") as Gtk.ListStore;
- vbox = builder.get_object ("vbox1") as Gtk.VBox;
- infos = builder.get_object ("infos_label") as Gtk.Label;
-
- iconview.set_pixbuf_column (2);
- iconview.set_text_column (1);
-
- search_button.grab_default ();
- search_entry.set_activates_default (true);
- builder.connect_signals (this);
- }
-
- public void run () {
- dialog.run ();
+ {
+ Json.Object photo = element.get_object ();
+ int64 farm_int = photo.get_int_member ("farm");
+
+ string farm = @"$farm_int";
+ string secret = photo.get_string_member ("secret");
+ string server = photo.get_string_member ("server");
+ string id = photo.get_string_member ("id");
+ string http = "http://farm";
+ string flickr = ".static.flickr.com/";
+
+ var image = new FlickrMedia();
+ image.file_link = http + farm + flickr + server + "/" + id + "_" + secret + "_t.jpg";
+ image.thumb_link = image.file_link;
+ // TODO : unittest to track Flickr API changes.
+ // TODO : license
+ image.title = photo.get_string_member ("title");
+ image.description = photo.get_object_member ("description").get_string_member ("_content");
+ image.author = photo.get_string_member ("owner");
+
+ add_media(image);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]