<commit_before>/*
 * Editors/SoftFocus.cs
 *
 * Copyright 2007 Novell Inc.
 *
 * Author
 *   <NAME> <<EMAIL>>
 *
 * See COPYING for license information.
 *
 */
using Gtk;
using System;
using Cairo;

namespace FSpot.Editors {
	public class SoftFocus : EffectEditor {
		Widgets.SoftFocus soft; 
		Scale scale;
		bool double_buffer;

		public SoftFocus (PhotoImageView view) : base (view)
		{
		}


		protected override void SetView (PhotoImageView value)
		{
			base.SetView (value);
			
			if (value == null)
				return;

			soft = new Widgets.SoftFocus (info);
			effect = (IEffect) soft;
		}

		protected override Widget CreateControls ()
		{
			VBox box = new VBox ();
			box.Spacing = 12;
			box.BorderWidth = 12;
			scale = new HScale (0, 1, .01);
			scale.Value = 0.5;
			scale.ValueChanged += HandleValueChanged;
			scale.WidthRequest = 250;
			box.PackStart (scale);
			HBox actions = new HBox ();
			actions.Spacing = 12;
			Button cancel = new Button ("Cancel");
			cancel.Clicked += HandleCancel;
			actions.PackStart (cancel);
			Button apply = new Button ("Apply");
			apply.Clicked += HandleApply;
			actions.PackStart (apply);
			box.PackStart (actions);

			return box;	
		}

		private void HandleCancel (object sender, EventArgs args)
		{
			Close ();
		}

		private void HandleApply (object sender, EventArgs args)
		{
			BrowsablePointer item = view.Item;
			EditTarget target = new EditTarget (item);
			try { 
				ImageFile img = ImageFile.Create (item.Current.DefaultVersionUri);

				Cairo.Format format = view.CompletePixbuf ().HasAlpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24;

				MemorySurface dest = new MemorySurface (format,
									info.Bounds.Width,
									info.Bounds.Height);

				Context ctx = new Context (dest);
				effect.OnExpose (ctx, info.Bounds);
				((IDisposable)ctx).Dispose ();

				string tmp = ImageFile.TempPath (item.Current.DefaultVersionUri.LocalPath);
				using (Gdk.Pixbuf output = Widgets.CairoUtils.CreatePixbuf (dest)) {
					using (System.IO.Stream stream = System.IO.File.OpenWrite (tmp)) {
						img.Save (output, stream);
						
					}
				}

				// FIXME Not this again. I need to imlplement a real version of the transfer
				// function that shows progress in the main window and allows for all the<commit_msg>Dispose the surface.<commit_after>/*
 * Editors/SoftFocus.cs
 *
 * Copyright 2007 Novell Inc.
 *
 * Author
 *   <NAME> <<EMAIL>>
 *
 * See COPYING for license information.
 *
 */
using Gtk;
using System;
using Cairo;

namespace FSpot.Editors {
	public class SoftFocus : EffectEditor {
		Widgets.SoftFocus soft; 
		Scale scale;
		bool double_buffer;

		public SoftFocus (PhotoImageView view) : base (view)
		{
		}


		protected override void SetView (PhotoImageView value)
		{
			base.SetView (value);
			
			if (value == null)
				return;

			soft = new Widgets.SoftFocus (info);
			effect = (IEffect) soft;
		}

		protected override Widget CreateControls ()
		{
			VBox box = new VBox ();
			box.Spacing = 12;
			box.BorderWidth = 12;
			scale = new HScale (0, 1, .01);
			scale.Value = 0.5;
			scale.ValueChanged += HandleValueChanged;
			scale.WidthRequest = 250;
			box.PackStart (scale);
			HBox actions = new HBox ();
			actions.Spacing = 12;
			Button cancel = new Button ("Cancel");
			cancel.Clicked += HandleCancel;
			actions.PackStart (cancel);
			Button apply = new Button ("Apply");
			apply.Clicked += HandleApply;
			actions.PackStart (apply);
			box.PackStart (actions);

			return box;	
		}

		private void HandleCancel (object sender, EventArgs args)
		{
			Close ();
		}

		private void HandleApply (object sender, EventArgs args)
		{
			BrowsablePointer item = view.Item;
			EditTarget target = new EditTarget (item);
			try { 
				ImageFile img = ImageFile.Create (item.Current.DefaultVersionUri);

				Cairo.Format format = view.CompletePixbuf ().HasAlpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24;

				MemorySurface dest = new MemorySurface (format,
									info.Bounds.Width,
									info.Bounds.Height);

				Context ctx = new Context (dest);
				effect.OnExpose (ctx, info.Bounds);
				((IDisposable)ctx).Dispose ();
				dest.Destroy ();

				string tmp = ImageFile.TempPath (item.Current.DefaultVersionUri.LocalPath);
				using (Gdk.Pixbuf output = Widgets.CairoUtils.CreatePixbuf (dest)) {
					using (System.IO.Stream stream = System.IO.File.OpenWrite (tmp)) {
						img.Save (output, stream);
						
					}
				}

				// FIXME Not this again. I need to imlplement a real version of the transfer
				// function that shows progress in the main window and allows for all the
{'fraction_non_alphanumeric': 0.11011774967291757, 'fraction_numerical': 0.01003052769297863, 'mean_word_length': 3.0485436893203883, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2099137', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1403, 'n_words': 412}