[ease] Images can be inserted from Flickr/OCA.



commit 1ba9b41e51a9cdcc803fd87e27c0f04de9d8193a
Author: Nate Stedman <natesm gmail com>
Date:   Sun Aug 22 21:45:04 2010 -0400

    Images can be inserted from Flickr/OCA.

 data/ui/import-widget.ui                  |    2 +
 ease-core/ease-plugin-import-service.vala |   15 +++++--
 ease/ease-editor-window.vala              |   62 ++++++++++++++++------------
 ease/ease-import-dialog.vala              |   19 +++++++++
 ease/ease-import-widget.vala              |   32 ++++++++++++++-
 5 files changed, 97 insertions(+), 33 deletions(-)
---
diff --git a/data/ui/import-widget.ui b/data/ui/import-widget.ui
index ff665d1..07cb6cc 100644
--- a/data/ui/import-widget.ui
+++ b/data/ui/import-widget.ui
@@ -62,6 +62,7 @@
                   <object class="GtkIconView" id="icon-view">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
+                    <property name="selection_mode">multiple</property>
                   </object>
                 </child>
               </object>
@@ -146,6 +147,7 @@
                   <object class="GtkButton" id="insert">
                     <property name="label" translatable="yes">_Insert</property>
                     <property name="visible">True</property>
+                    <property name="sensitive">False</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
                     <property name="image">image1</property>
diff --git a/ease-core/ease-plugin-import-service.vala b/ease-core/ease-plugin-import-service.vala
index 5eb0733..c8d82b0 100644
--- a/ease-core/ease-plugin-import-service.vala
+++ b/ease-core/ease-plugin-import-service.vala
@@ -127,7 +127,8 @@ public abstract class Ease.Plugin.ImportService : GLib.Object
 		if (list_size > 0)
 		{
 			// create model
-			model = new Gtk.ListStore(2, typeof(Gdk.Pixbuf), typeof(string));
+			model = new Gtk.ListStore(3, typeof(Gdk.Pixbuf), typeof(string),
+			                             typeof(ImportMedia));
 			
 			// set icons
 			var icons = loading_started();
@@ -179,7 +180,8 @@ public abstract class Ease.Plugin.ImportService : GLib.Object
 		{
 			model.append(out tree_itr);
 			model.set(tree_itr, Column.PIXBUF, pixbuf,
-				                Column.TEXT, image.title);
+				                Column.TEXT, image.title,
+				                Column.IMPORT_MEDIA, image);
 		}
 		
 		// set the widget.progress bar
@@ -231,7 +233,7 @@ public abstract class Ease.Plugin.ImportService : GLib.Object
 	/**
 	 * Enumerator for columns in the "model" ListStore.
 	 */
-	private enum Column
+	public enum Column
 	{
 		/**
 		 * The column storing Gdk.Pixbufs, downloaded from the internet.
@@ -243,7 +245,12 @@ public abstract class Ease.Plugin.ImportService : GLib.Object
 		/**
 		 * The column for the label displayed in the Gtk.IconView.
 		 */
-		TEXT = 1
+		TEXT = 1,
+		
+		/**
+		 * Stores the ImportMedia associated with the image.
+		 */
+		IMPORT_MEDIA = 2
 	}
 }
 
diff --git a/ease/ease-editor-window.vala b/ease/ease-editor-window.vala
index c5db0b5..63357c5 100644
--- a/ease/ease-editor-window.vala
+++ b/ease/ease-editor-window.vala
@@ -436,33 +436,38 @@ internal class Ease.EditorWindow : Gtk.Window
 
 		if (filename != null)
 		{
-			try
-			{
-				var img = new Clutter.Texture.from_file(filename);
-				var e = new ImageElement();
-				
-				// set the size and position of the element
-				int width = 0, height = 0;
-				img.get_base_size(out width, out height);
-				
-				e.width = width;
-				e.height = height;
-				e.x = slide.width / 2 - width / 2;
-				e.y = slide.height / 2 - height / 2;
-				
-				e.element_type = Slide.IMAGE_TYPE;
-				e.identifier = Theme.CUSTOM_MEDIA;
-				e.filename = document.add_media_file(filename);
-				e.source_filename = filename;
-				
-				// add the element
-				slide.append(e);
-				embed.select_element(e);
-			}
-			catch (Error e)
-			{
-				error_dialog(_("Error Inserting Image"), e.message);
-			}
+			insert_image_actual(filename);
+		}
+	}
+	
+	internal void insert_image_actual(string filename)
+	{	
+		try
+		{
+			var img = new Clutter.Texture.from_file(filename);
+			var e = new ImageElement();
+			
+			// set the size and position of the element
+			int width = 0, height = 0;
+			img.get_base_size(out width, out height);
+			
+			e.width = width;
+			e.height = height;
+			e.x = slide.width / 2 - width / 2;
+			e.y = slide.height / 2 - height / 2;
+			
+			e.element_type = Slide.IMAGE_TYPE;
+			e.identifier = Theme.CUSTOM_MEDIA;
+			e.filename = document.add_media_file(filename);
+			e.source_filename = filename;
+			
+			// add the element
+			slide.append(e);
+			embed.select_element(e);
+		}
+		catch (Error e)
+		{
+			error_dialog(_("Error Inserting Image"), e.message);
 		}
 	}
 	
@@ -556,6 +561,9 @@ internal class Ease.EditorWindow : Gtk.Window
 	internal void on_insert_web_media(Gtk.Widget sender)
 	{
 		var dialog = new ImportDialog();
+		
+		dialog.add_image.connect(insert_image_actual);
+		
 		dialog.run();
 	}
 	
diff --git a/ease/ease-import-dialog.vala b/ease/ease-import-dialog.vala
index 9410fa6..5d8683d 100644
--- a/ease/ease-import-dialog.vala
+++ b/ease/ease-import-dialog.vala
@@ -17,6 +17,8 @@
 
 internal class Ease.ImportDialog : Gtk.Window
 {
+	public signal void add_image(string filename);
+	
 	internal ImportDialog()
 	{
 		title = _("Import Media");
@@ -51,6 +53,23 @@ internal class Ease.ImportDialog : Gtk.Window
 		var item = new Source.SpinnerItem.from_stock_icon(title, stock_id,
 		                                                  widget);
 		
+		widget.add_media.connect((media) => {
+			var temp = Temp.request();
+			
+			var file = File.new_for_uri(media.file_link);
+			var copy = File.new_for_path(Path.build_filename(temp, "media"));
+			try
+			{
+				file.copy(copy, FileCopyFlags.OVERWRITE, null, null);
+				add_image(copy.get_path());
+			}
+			catch (Error e)
+			{
+				critical("Couldn't read file: %s", e.message);
+				return;
+			}
+		});
+		
 		service.started.connect(() => item.start());
 		service.no_results.connect(() => item.stop());
 		service.loading_complete.connect(() => item.stop());
diff --git a/ease/ease-import-widget.vala b/ease/ease-import-widget.vala
index 933c872..9ea3785 100644
--- a/ease/ease-import-widget.vala
+++ b/ease/ease-import-widget.vala
@@ -1,4 +1,4 @@
-public class Ease.ImportWidget : Gtk.Alignment
+internal class Ease.ImportWidget : Gtk.Alignment
 {
 	private const string UI_FILE_PATH = "import-widget.ui";
 	private const double DARK_FACTOR = 1.1;
@@ -24,6 +24,11 @@ public class Ease.ImportWidget : Gtk.Alignment
 	internal Gtk.Button button;
 	
 	/**
+	 * Insert button.
+	 */
+	internal Gtk.Button insert;
+	
+	/**
 	 * Progress bar, displaying the percentage of images downloaded so far.
 	 */
 	internal Gtk.ProgressBar progress;
@@ -49,11 +54,16 @@ public class Ease.ImportWidget : Gtk.Alignment
 	private Plugin.ImportService service;
 	
 	/**
+	 * Triggers a media add.
+	 */
+	internal signal void add_media(Plugin.ImportMedia media);
+	
+	/**
 	 * Size of the spinner
 	 */
 	private const int SPINNER_SIZE = 40;
 
-	public ImportWidget(Plugin.ImportService serv)
+	internal ImportWidget(Plugin.ImportService serv)
 	{
 		service = serv;
 		set_padding(0, 0, 0, 0);
@@ -86,6 +96,21 @@ public class Ease.ImportWidget : Gtk.Alignment
 		button.clicked.connect(() => service.run(search.text));
 		button.expose_event.connect(set_bg);
 		
+		// insert button
+		insert = builder.get_object("insert") as Gtk.Button;
+		insert.clicked.connect(() => {
+			var model = icons.model;
+			Gtk.TreeIter iter = Gtk.TreeIter();
+			Plugin.ImportMedia media = null;
+			icons.selected_foreach((view, path) => {
+				model.get_iter(out iter, path);
+				model.get(iter, Plugin.ImportService.Column.IMPORT_MEDIA,
+				          out media);
+				add_media(media);
+			});
+		});
+		insert.expose_event.connect(set_bg);
+		
 		// progress
 		progress = builder.get_object("progress-bar") as Gtk.ProgressBar;
 		
@@ -99,6 +124,9 @@ public class Ease.ImportWidget : Gtk.Alignment
 		// icon view
 		icons = builder.get_object("icon-view") as Gtk.IconView;
 		icons_container = builder.get_object("icon-window") as Gtk.Widget;
+		icons.selection_changed.connect(() => {
+			insert.sensitive = icons.get_selected_items().length() > 0;
+		});
 		
 		// no results
 		no_results = builder.get_object("no-results") as Gtk.Widget;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]