コード例 #1
0
			public void StretchRealFile ()
			{
				string path = "/home/lewing/Desktop/img_0081.jpg";
				FilterRequest req = new FilterRequest (path);
				FilterSet set = new FilterSet ();
				set.Add (new AutoStretch ());
				set.Add (new UniqueNameFilter (Path.GetDirectoryName (path)));
				set.Convert (req);
				req.Preserve (req.Current);
			}
コード例 #2
0
            public void StretchRealFile()
            {
                string        path = "/home/lewing/Desktop/img_0081.jpg";
                FilterRequest req  = new FilterRequest(path);
                FilterSet     set  = new FilterSet();

                set.Add(new AutoStretch());
                set.Add(new UniqueNameFilter(Path.GetDirectoryName(path)));
                set.Convert(req);
                req.Preserve(req.Current);
            }
コード例 #3
0
ファイル: PhotoRequestHandler.cs プロジェクト: mono/f-spot
		protected virtual void SendImage (Photo photo, Stream stream) 
		{
			string path = photo.DefaultVersion.Uri.LocalPath;
			FileInfo file_info = new FileInfo(path);
			if (!file_info.Exists) {
				SendError (stream, "404 The file is not on the disk");
				return;
			}

			FilterSet filters = new FilterSet ();
			filters.Add (new JpegFilter ());
			filters.Add (new ResizeFilter (1600));

			using (FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri)) {
				filters.Convert (request);
				file_info = new FileInfo (request.Current.LocalPath);
				SendFile (file_info, photo, stream);
			}

			if (stats != null)
				stats.PhotoViews++;
		}
コード例 #4
0
ファイル: FolderGallery.cs プロジェクト: GNOME/f-spot
        public void ProcessImage(int image_num, FilterSet filter_set)
        {
            IPhoto photo = Collection [image_num];
            string path;
            ScaleRequest req;

            req = requests [0];

            MakeDir (SubdirPath (req.Name));
            path = SubdirPath (req.Name, ImageName (image_num));

            using (FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri)) {
                filter_set.Convert (request);
                if (request.Current.LocalPath == path)
                    request.Preserve (request.Current);
                else
                    System.IO.File.Copy (request.Current.LocalPath, path, true);

                if (photo != null && photo is Photo && App.Instance.Database != null)
                    App.Instance.Database.Exports.Create ((photo as Photo).Id, (photo as Photo).DefaultVersionId,
                                      ExportStore.FolderExportType,
                                      // FIXME this is wrong, the final path is the one
                                      // after the Xfer.
                                      new SafeUri (path).ToString ());

                for (int i = 1; i < requests.Length; i++) {

                    req = requests [i];
                    if (scale && req.AvoidScale (Size))
                        continue;

                    FilterSet req_set = new FilterSet ();
                    req_set.Add (new ResizeFilter ((uint)Math.Max (req.Width, req.Height)));

                    bool sharpen;
                    try {
                        sharpen = Preferences.Get<bool> (FolderExport.SHARPEN_KEY);
                    } catch (NullReferenceException) {
                        sharpen = true;
                        Preferences.Set (FolderExport.SHARPEN_KEY, true);
                    }

                    if (sharpen) {
                        if (req.Name == "lq")
                            req_set.Add (new SharpFilter (0.1, 2, 4));
                        if (req.Name == "thumbs")
                            req_set.Add (new SharpFilter (0.1, 2, 5));
                    }
                    using (FilterRequest tmp_req = new FilterRequest (photo.DefaultVersion.Uri)) {
                        req_set.Convert (tmp_req);
                        MakeDir (SubdirPath (req.Name));
                        path = SubdirPath (req.Name, ImageName (image_num));
                        System.IO.File.Copy (tmp_req.Current.LocalPath, path, true);
                    }
                }
            }
        }
コード例 #5
0
        void zip()
        {
            System.Uri dest = new System.Uri (uri_chooser.Uri);
            Crc32 crc = new Crc32 ();
            string filedest = dest.LocalPath + "/" + filename.Text;
            Log.DebugFormat ("Creating zip file {0}", filedest);
            ZipOutputStream s = new ZipOutputStream (File.Create(filedest));
            if (scale_check.Active)
                Log.DebugFormat ("Scaling to {0}", scale_size.ValueAsInt);

            ProgressDialog progress_dialog = new ProgressDialog (Catalog.GetString ("Exporting files"),
                                  ProgressDialog.CancelButtonType.Stop,
                                  photos.Length, zipdiag);

            //Pack up
            for (int i = 0; i < photos.Length; i ++) {
                if (progress_dialog.Update (String.Format (Catalog.GetString ("Preparing photo \"{0}\""), photos[i].Name))) {
                    progress_dialog.Destroy ();
                    return;
                }
                string f = null;
                // FIXME: embed in a try/catch
                if (scale_check.Active) {
                    FilterSet filters = new FilterSet ();
                    filters.Add (new JpegFilter ());
                    filters.Add (new ResizeFilter ((uint) scale_size.ValueAsInt));
                    FilterRequest freq = new FilterRequest (photos [i].DefaultVersion.Uri);
                    filters.Convert (freq);
                    f = freq.Current.LocalPath;
                } else {
                    f = photos [i].DefaultVersion.Uri.LocalPath;
                }
                FileStream fs = File.OpenRead (f);

                byte [] buffer = new byte [fs.Length];
                fs.Read (buffer, 0, buffer.Length);
                ZipEntry entry = new ZipEntry (System.IO.Path.GetFileName (photos [i].DefaultVersion.Uri.LocalPath));

                entry.DateTime = DateTime.Now;

                entry.Size = fs.Length;
                fs.Close ();

                crc.Reset ();
                crc.Update (buffer);

                entry.Crc = crc.Value;

                s.PutNextEntry (entry);

                s.Write (buffer, 0, buffer.Length);
            }
            s.Finish ();
            s.Close ();
            if (progress_dialog != null)
                progress_dialog.Destroy ();
        }
コード例 #6
0
ファイル: MetaPixel.cs プロジェクト: Yetangitu/f-spot
        void create_mosaics()
        {
            //Prepare the query
            Db db = App.Instance.Database;
            FSpot.PhotoQuery mini_query = new FSpot.PhotoQuery (db.Photos);
            Photo [] photos;

            if (tags_radio.Active) {
                //Build tag array
                List<Tag> taglist = new List<Tag> ();
                foreach (string tag_name in miniatures_tags.GetTypedTagNames ()) {
                    Tag t = db.Tags.GetTagByName (tag_name);
                    if (t != null)
                        taglist.Add(t);
                }
                mini_query.Terms = FSpot.OrTerm.FromTags (taglist.ToArray ());
                photos = mini_query.Photos;
            } else {
                photos = App.Instance.Organizer.Query.Photos;
            }

            if (photos.Length == 0) {
                //There is no photo for the selected tags! :(
                InfoDialog (Catalog.GetString ("No photos for the selection"),
                        Catalog.GetString ("The tags selected provided no pictures. Please select different tags"),
                        Gtk.MessageType.Error);
                return;
            }

            //Create minis
            ProgressDialog progress_dialog = null;
            progress_dialog = new ProgressDialog (Catalog.GetString ("Creating miniatures"),
                                  ProgressDialog.CancelButtonType.Stop,
                                  photos.Length, metapixel_dialog);

            minidir_tmp = System.IO.Path.GetTempFileName ();
            System.IO.File.Delete (minidir_tmp);
            System.IO.Directory.CreateDirectory (minidir_tmp);
            minidir_tmp += "/";

            //Call MetaPixel to create the minis
            foreach (Photo p in photos) {
                if (progress_dialog.Update (String.Format (Catalog.GetString ("Preparing photo \"{0}\""), p.Name))) {
                    progress_dialog.Destroy ();
                    DeleteTmp ();
                    return;
                }
                //FIXME should switch to retry/skip
                if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) {
                    Log.WarningFormat (String.Format ("Couldn't access photo {0} while creating miniatures", p.DefaultVersion.Uri.LocalPath));
                    continue;
                }
                //FIXME Check if the picture's format is supproted (jpg, gif)

                FilterSet filters = new FilterSet ();
                filters.Add (new JpegFilter ());
                FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri);
                filters.Convert (freq);

                //We use photo id for minis, instead of photo names, to avoid duplicates
                string minifile = minidir_tmp + p.Id.ToString() + System.IO.Path.GetExtension (p.DefaultVersion.Uri.ToString ());
                string prepare_command = String.Format ("--prepare -w {0} -h {1} {2} {3} {4}tables.mxt",
                                    icon_x_size.Text, //Minis width
                                    icon_y_size.Text, //Minis height
                                    GLib.Shell.Quote (freq.Current.LocalPath), //Source image
                                    GLib.Shell.Quote (minifile),  //Dest image
                                    minidir_tmp);  //Table file
                Log.Debug ("Executing: metapixel " + prepare_command);

                System.Diagnostics.Process mp_prep = System.Diagnostics.Process.Start ("metapixel", prepare_command);
                mp_prep.WaitForExit ();
                if (!System.IO.File.Exists (minifile)) {
                    Log.DebugFormat ("No mini? No party! {0}", minifile);
                    continue;
                }

            } //Finished preparing!
            if (progress_dialog != null)
                progress_dialog.Destroy ();

            progress_dialog = null;
            progress_dialog = new ProgressDialog (Catalog.GetString ("Creating photomosaics"),
                                  ProgressDialog.CancelButtonType.Stop,
                                  App.Instance.Organizer.SelectedPhotos ().Length, metapixel_dialog);

            //Now create the mosaics!
            uint error_count = 0;
            foreach (Photo p in App.Instance.Organizer.SelectedPhotos ()) {
                if (progress_dialog.Update (String.Format (Catalog.GetString ("Processing \"{0}\""), p.Name))) {
                    progress_dialog.Destroy ();
                    DeleteTmp ();
                    return;
                }
                //FIXME should switch to retry/skip
                if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) {
                    Log.WarningFormat (String.Format ("Couldn't access photo {0} while creating mosaics", p.DefaultVersion.Uri.LocalPath));
                    error_count ++;
                    continue;
                }

                //FIXME Check if the picture's format is supproted (jpg, gif)

                FilterSet filters = new FilterSet ();
                filters.Add (new JpegFilter ());
                FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri);
                filters.Convert (freq);

                string name = GetVersionName (p);
                System.Uri mosaic = GetUriForVersionName (p, name);

                string mosaic_command = String.Format ("--metapixel -l {0} {1} {2}",
                                    minidir_tmp,
                                    GLib.Shell.Quote (freq.Current.LocalPath),
                                    GLib.Shell.Quote (mosaic.LocalPath));
                Log.Debug ("Executing: metapixel " + mosaic_command);
                System.Diagnostics.Process mp_exe = System.Diagnostics.Process.Start ("metapixel", mosaic_command);
                mp_exe.WaitForExit ();
                if (!GLib.FileFactory.NewForUri (mosaic).Exists) {
                    Log.Warning ("Error in processing image " + p.Name);
                    error_count ++;
                    continue;
                }

                p.DefaultVersionId = p.AddVersion (mosaic, name, true);
                p.Changes.DataChanged = true;
                Core.Database.Photos.Commit (p);

            } //Finished creating mosaics
            if (progress_dialog != null)
                progress_dialog.Destroy ();

            string final_message = "Your mosaics have been generated as new versions of the pictures you selected";
            if (error_count > 0)
                final_message += String.Format (".\n{0} images out of {1} had errors",
                            error_count, App.Instance.Organizer.SelectedPhotos ().Length);
            InfoDialog (Catalog.GetString ("PhotoMosaics generated!"),
                    Catalog.GetString (final_message),
                    (error_count == 0 ? Gtk.MessageType.Info : Gtk.MessageType.Warning));
            DeleteTmp ();
        }
コード例 #7
0
ファイル: SendEmail.cs プロジェクト: GNOME/f-spot
		public SendEmail (IBrowsableCollection selection, Window parent_window) : base ("mail_dialog.ui", "mail_dialog")
		{
			this.selection = selection;
			this.parent_window = parent_window;

			foreach (var p in selection.Items) {
				if (FileFactory.NewForUri (p.DefaultVersion.Uri).QueryInfo ("standard::content-type", FileQueryInfoFlags.None, null).ContentType != "image/jpeg")
					force_original = true;
			}

			if (force_original) {
				original_size.Active = true;
				tiny_size.Sensitive = false;
				small_size.Sensitive = false;
				medium_size.Sensitive = false;
				large_size.Sensitive = false;
				x_large_size.Sensitive = false;
			} else
				switch (Preferences.Get<int> (Preferences.EXPORT_EMAIL_SIZE)) {
					case 0 :  original_size.Active = true; break;
					case 1 :  tiny_size.Active = true; break;
					case 2 :  small_size.Active = true; break;
					case 3 :  medium_size.Active = true; break;
					case 4 :  large_size.Active = true; break;
					case 5 :  x_large_size.Active = true; break;
					default: break;
				}


			tray_scrolled.Add (new TrayView (selection));

			Modal = false;

			// Calculate total original filesize
			foreach (var photo in selection.Items) {
				try {
					Orig_Photo_Size += FileFactory.NewForUri (photo.DefaultVersion.Uri).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size;
				} catch {
				}
			}

			for (int k = 0; k < avg_scale_ref.Length; k++)
				avg_scale[k] = avg_scale_ref[k];


			// Calculate approximate size shrinking, use first photo, and shrink to medium size as base.
			var scalephoto = selection [0];
			if (scalephoto != null && !force_original) {

				// Get first photos file size
				long orig_size = FileFactory.NewForUri (scalephoto.DefaultVersion.Uri).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size;

				FilterSet filters = new FilterSet ();
				filters.Add (new ResizeFilter ((uint)(sizes [3])));
				long new_size;
				using (FilterRequest request = new FilterRequest (scalephoto.DefaultVersion.Uri)) {
					filters.Convert (request);
					new_size = FileFactory.NewForUri (request.Current).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size;
				}

				if (orig_size > 0) {

					// Get the factor (scale) between original and resized medium size.
					scale_percentage = 1 - ( (float) (orig_size - new_size) / orig_size);

					// What is the relation between the estimated medium scale factor, and reality?
					double scale_scale = scale_percentage / avg_scale_ref[3];

					//System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}",
					//	scale_percentage, avg_scale_ref[3], scale_scale  );

					// Re-Calculate the proper relation per size
					for (int k = 0; k < avg_scale_ref.Length; k++) {
						avg_scale[k] = avg_scale_ref[k] * scale_scale;
					//	System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})",
					//		k, avg_scale[k], avg_scale_ref[k]  );
					}
				}

			}

			NumberOfPictures.Text 	= selection.Count.ToString();
			TotalOriginalSize.Text 	= GLib.Format.SizeForDisplay (Orig_Photo_Size);

			UpdateEstimatedSize();

			ShowAll ();

			//LoadHistory ();

			Response += HandleResponse;
		}
コード例 #8
0
ファイル: SendEmail.cs プロジェクト: GNOME/f-spot
		private void HandleResponse (object sender, Gtk.ResponseArgs args)
		{
			int size = 0;
			bool UserCancelled = false;

			// Lets remove the mail "create mail" dialog
			Destroy();

			if (args.ResponseId != Gtk.ResponseType.Ok) {
				return;
			}
			ProgressDialog progress_dialog = null;

			progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing email"),
												ProgressDialog.CancelButtonType.Stop,
												selection.Count,
												parent_window);

			size = GetScaleSize(); // Which size should we scale to. 0 --> Original

			// evaluate mailto command and define attachment args for cli
			System.Text.StringBuilder attach_arg = new System.Text.StringBuilder ();
			switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) {
			case "thunderbird %s":
			case "mozilla-thunderbird %s":
			case "seamonkey -mail -compose %s":
			case "icedove %s":
				attach_arg.Append(",");
				break;
			case "kmail %s":
				attach_arg.Append(" --attach ");
				break;
			default://evolution falls into default, since it supports mailto uri correctly
				attach_arg.Append("&attach=");
				break;
			}

			// Create a tmp directory.
			tmp_mail_dir = System.IO.Path.GetTempFileName ();	// Create a tmp file
			System.IO.File.Delete (tmp_mail_dir);			// Delete above tmp file
			System.IO.Directory.CreateDirectory (tmp_mail_dir);	// Create a directory with above tmp name

			System.Text.StringBuilder mail_attach = new System.Text.StringBuilder ();

			FilterSet filters = new FilterSet ();

			if (size != 0)
				filters.Add (new ResizeFilter ((uint) size));
			filters.Add (new UniqueNameFilter (new SafeUri (tmp_mail_dir)));


			for (int i = 0; i < selection.Count; i++) {
				var photo = selection [i];
				if ( (photo != null) && (!UserCancelled) ) {

					if (progress_dialog != null)
						UserCancelled = progress_dialog.Update (String.Format
							(Catalog.GetString ("Exporting picture \"{0}\""), photo.Name));

					if (UserCancelled)
						break;

					try {
						// Prepare a tmp_mail file name
						FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri);

						filters.Convert (request);
						request.Preserve(request.Current);

						mail_attach.Append(((i == 0 && attach_arg.ToString () == ",") ? "" : attach_arg.ToString()) + request.Current.ToString ());
					} catch (Exception e) {
						Hyena.Log.ErrorFormat ("Error preparing {0}: {1}", selection[i].Name, e.Message);
						HigMessageDialog md = new HigMessageDialog (parent_window,
											    DialogFlags.DestroyWithParent,
											    MessageType.Error,
											    ButtonsType.Close,
											    Catalog.GetString("Error processing image"),
											    String.Format(Catalog.GetString("An error occured while processing \"{0}\": {1}"), selection[i].Name, e.Message));
						md.Run();
						md.Destroy();
						UserCancelled = true;
					}
				}
			} // foreach

			if (progress_dialog != null)
				progress_dialog.Destroy (); // No need to keep this window

		    if (UserCancelled)
                return;

		    // Send the mail :)
		    string mail_subject = Catalog.GetString("My Photos");
		    switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) {
		            // openSuSE
		        case "thunderbird %s":
		            System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
		            break;
		        case "icedove %s":
		            System.Diagnostics.Process.Start("icedove", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
		            break;
		        case "mozilla-thunderbird %s":
		            System.Diagnostics.Process.Start("mozilla-thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
		            break;
		        case "seamonkey -mail -compose %s":
		            System.Diagnostics.Process.Start("seamonkey", " -mail -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
		            break;
		        case "kmail %s":
		            System.Diagnostics.Process.Start("kmail", "  --composer --subject \"" + mail_subject + "\"" + mail_attach);
		            break;
		        case "evolution %s": //evo doesn't urldecode the subject
		            GtkBeans.Global.ShowUri (Screen, "mailto:?subject=" + mail_subject + mail_attach);
		            break;
		        default:
		            GtkBeans.Global.ShowUri (Screen, "mailto:?subject=" + System.Web.HttpUtility.UrlEncode(mail_subject) + mail_attach);
		            break;
		    }
		}
コード例 #9
0
		public SendEmail (IBrowsableCollection selection) : base ("mail_dialog")
		{
			this.selection = selection;

			for (int i = 0; i < selection.Count; i++) {
				Photo p = selection[i] as Photo;
				if (Gnome.Vfs.MimeType.GetMimeTypeForUri (p.DefaultVersionUri.ToString ()) != "image/jpeg")
					force_original = true;
			}

			if (force_original) {
				original_size.Active = true;
				tiny_size.Sensitive = false;
				small_size.Sensitive = false;
				medium_size.Sensitive = false;
				large_size.Sensitive = false;
				x_large_size.Sensitive = false;
			} else  
				switch (Preferences.Get<int> (Preferences.EXPORT_EMAIL_SIZE)) {
					case 0 :  original_size.Active = true; break;
					case 1 :  tiny_size.Active = true; break;
					case 2 :  small_size.Active = true; break;
					case 3 :  medium_size.Active = true; break;
					case 4 :  large_size.Active = true; break;
					case 5 :  x_large_size.Active = true; break;
					default: break;
				}

			rotate_check.Active = Preferences.Get<bool> (Preferences.EXPORT_EMAIL_ROTATE);
			rotate_check.Sensitive = original_size.Active && tiny_size.Sensitive;
			
			tray_scrolled.Add (new TrayView (selection));

			Dialog.Modal = false;

			// Calculate total original filesize 
			for (int i = 0; i < selection.Count; i++) {
				Photo photo = selection[i] as Photo;
				try {
					Orig_Photo_Size += (new Gnome.Vfs.FileInfo (photo.DefaultVersionUri.ToString ())).Size;
				} catch {
				}
			}

			for (int k = 0; k < avg_scale_ref.Length; k++)
				avg_scale[k] = avg_scale_ref[k];


			// Calculate approximate size shrinking, use first photo, and shrink to medium size as base.
			Photo scalephoto = selection [0] as Photo;
			if (scalephoto != null && !force_original) {
				
				// Get first photos file size
				long orig_size = (new Gnome.Vfs.FileInfo (scalephoto.DefaultVersionUri.ToString ())).Size;
				
				FilterSet filters = new FilterSet ();
				filters.Add (new ResizeFilter ((uint)(sizes [3])));
				long new_size;
				using (FilterRequest request = new FilterRequest (scalephoto.DefaultVersionUri)) {
					filters.Convert (request);
					new_size = (new Gnome.Vfs.FileInfo (request.Current.ToString ())).Size;
				}
				
				if (orig_size > 0) {
				
					// Get the factor (scale) between original and resized medium size.
					scale_percentage = 1 - ( (float) (orig_size - new_size) / orig_size);
					
					// What is the relation between the estimated medium scale factor, and reality?
					double scale_scale = scale_percentage / avg_scale_ref[3];
					
					//System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}", 
					//	scale_percentage, avg_scale_ref[3], scale_scale  );

					// Re-Calculate the proper relation per size
					for (int k = 0; k < avg_scale_ref.Length; k++) {
						avg_scale[k] = avg_scale_ref[k] * scale_scale;
					//	System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})", 
					//		k, avg_scale[k], avg_scale_ref[k]  );
					}
				}

			}

			NumberOfPictures.Text 	= selection.Count.ToString();
			TotalOriginalSize.Text 	= SizeUtil.ToHumanReadable (Orig_Photo_Size);
			
			UpdateEstimatedSize();

			Dialog.ShowAll ();

			//LoadHistory ();

			Dialog.Response += HandleResponse;
		}
コード例 #10
0
        void Upload()
        {
            IPhoto [] items = dialog.Items;
            string [] captions = dialog.Captions;
            dialog.StoreCaption ();

            long sent_bytes = 0;

            FilterSet filters = new FilterSet ();
            filters.Add (new JpegFilter ());
            filters.Add (new ResizeFilter ((uint) size));

            for (int i = 0; i < items.Length; i++) {
                try {
                    IPhoto item = items [i];

                    FileInfo file_info;
                    Log.DebugFormat ("uploading {0}", i);

                    progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), item.Name, i + 1, items.Length);
                    progress_dialog.ProgressText = string.Empty;
                    progress_dialog.Fraction = i / (double) items.Length;

                    FilterRequest request = new FilterRequest (item.DefaultVersion.Uri);
                    filters.Convert (request);

                    file_info = new FileInfo (request.Current.LocalPath);

                    album.Upload (captions [i] ?? "", request.Current.LocalPath);

                    sent_bytes += file_info.Length;
                }
                catch (Exception e) {
                    progress_dialog.Message = String.Format (Catalog.GetString ("Error Uploading To Facebook: {0}"), e.Message);
                    progress_dialog.ProgressText = Catalog.GetString ("Error");
                    Log.DebugException (e);

                    if (progress_dialog.PerformRetrySkip ())
                        i--;
                }
            }

            progress_dialog.Message = Catalog.GetString ("Done Sending Photos");
            progress_dialog.Fraction = 1.0;
            progress_dialog.ProgressText = Catalog.GetString ("Upload Complete");
            progress_dialog.ButtonLabel = Gtk.Stock.Ok;

            var li = new LinkButton ("http://www.facebook.com/group.php?gid=158960179844&ref=mf", Catalog.GetString ("Visit F-Spot group on Facebook"));
            progress_dialog.VBoxPackEnd (li);
            li.ShowAll ();
        }
コード例 #11
0
		private void Upload ()
		{
			album.UploadProgress += HandleUploadProgress;
			sent_bytes = 0;
			approx_size = 0;

			System.Console.WriteLine ("Starting Upload to Picasa");

			FilterSet filters = new FilterSet ();
			filters.Add (new JpegFilter ());

			if (scale)
				filters.Add (new ResizeFilter ((uint)size));

			if (rotate)
				filters.Add (new OrientationFilter ());

			Array.Sort (items, new DateComparer ());

			while (photo_index < items.Length) {
				try {
					IBrowsableItem item = items[photo_index];

					FileInfo file_info;
					Console.WriteLine ("uploading {0}", photo_index);

					progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"),
										 item.Name, photo_index+1, items.Length);
					photo_index++;

					PicasaPicture picture;
					using (FilterRequest request = new FilterRequest (item.DefaultVersionUri)) {
						filters.Convert (request);
						file_info = new FileInfo (request.Current.LocalPath);

						if (approx_size == 0) //first image
							approx_size = file_info.Length * items.Length;
						else
							approx_size = sent_bytes * items.Length / (photo_index - 1);

						picture = album.UploadPicture (request.Current.LocalPath, Path.ChangeExtension (item.Name, "jpg"), item.Description);
						sent_bytes += file_info.Length;
					}
					if (Core.Database != null && item is Photo)
						Core.Database.Exports.Create ((item as Photo).Id,
									      (item as Photo).DefaultVersionId,
									      ExportStore.PicasaExportType,
									      picture.Link);

					//tagging
					if (item.Tags != null && export_tag)
						foreach (Tag tag in item.Tags)
							picture.AddTag (tag.Name);
				} catch (System.Threading.ThreadAbortException te) {
					Log.Exception (te);
					System.Threading.Thread.ResetAbort ();
				} catch (System.Exception e) {
					progress_dialog.Message = String.Format (Catalog.GetString ("Error Uploading To Gallery: {0}"),
										 e.Message);
					progress_dialog.ProgressText = Catalog.GetString ("Error");
					System.Console.WriteLine (e);

					if (progress_dialog.PerformRetrySkip ())
						photo_index--;
				}
			}

			progress_dialog.Message = Catalog.GetString ("Done Sending Photos");
			progress_dialog.Fraction = 1.0;
			progress_dialog.ProgressText = Catalog.GetString ("Upload Complete");
			progress_dialog.ButtonLabel = Gtk.Stock.Ok;

			if (browser) {
				GnomeUtil.UrlShow (album.Link);
			}
		}
コード例 #12
0
ファイル: FacebookExport.cs プロジェクト: iainlane/f-spot
        void Upload()
        {
            Album album = null;

            IBrowsableItem [] items = dialog.Items;
            string [] captions = dialog.Captions;
            dialog.StoreCaption ();

            if (dialog.CreateAlbum) {
                string name = dialog.AlbumName;
                if (String.IsNullOrEmpty (name)) {
                    HigMessageDialog mbox = new HigMessageDialog (dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal,
                            Gtk.MessageType.Error, Gtk.ButtonsType.Ok, Catalog.GetString ("Album must have a name"),
                            Catalog.GetString ("Please name your album or choose an existing album."));
                    mbox.Run ();
                    mbox.Destroy ();
                    return;
                }

                string description = dialog.AlbumDescription;
                string location = dialog.AlbumLocation;

                try {
                    album = dialog.Account.Facebook.CreateAlbum (name, description, location);
                }
                catch (FacebookException fe) {
                    HigMessageDialog mbox = new HigMessageDialog (dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal,
                            Gtk.MessageType.Error, Gtk.ButtonsType.Ok, Catalog.GetString ("Creating a new album failed"),
                            String.Format (Catalog.GetString ("An error occurred creating a new album.\n\n{0}"), fe.Message));
                    mbox.Run ();
                    mbox.Destroy ();
                    return;
                }
            } else {
                album = dialog.ActiveAlbum;
            }

            long sent_bytes = 0;

            FilterSet filters = new FilterSet ();
            filters.Add (new JpegFilter ());
            filters.Add (new ResizeFilter ((uint) size));

            for (int i = 0; i < items.Length; i++) {
                try {
                    IBrowsableItem item = items [i];

                    FileInfo file_info;
                    Console.WriteLine ("uploading {0}", i);

                    progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), item.Name, i + 1, items.Length);
                    progress_dialog.ProgressText = string.Empty;
                    progress_dialog.Fraction = i / (double) items.Length;

                    FilterRequest request = new FilterRequest (item.DefaultVersionUri);
                    filters.Convert (request);

                    file_info = new FileInfo (request.Current.LocalPath);

                    album.Upload (captions [i] ?? "", request.Current.LocalPath);

                    sent_bytes += file_info.Length;
                }
                catch (Exception e) {
                    progress_dialog.Message = String.Format (Catalog.GetString ("Error Uploading To Facebook: {0}"), e.Message);
                    progress_dialog.ProgressText = Catalog.GetString ("Error");
                    Console.WriteLine (e);

                    if (progress_dialog.PerformRetrySkip ())
                        i--;
                }
            }

            progress_dialog.Message = Catalog.GetString ("Done Sending Photos");
            progress_dialog.Fraction = 1.0;
            progress_dialog.ProgressText = Catalog.GetString ("Upload Complete");
            progress_dialog.ButtonLabel = Gtk.Stock.Ok;

            var li = new LinkButton ("http://www.facebook.com/group.php?gid=158960179844&ref=mf", Catalog.GetString ("Visit F-Spot group on Facebook"));
            progress_dialog.VBoxPackEnd (li);
            li.ShowAll ();
        }
コード例 #13
0
		private void HandleResponse (object sender, Gtk.ResponseArgs args)
		{
			long new_size = 0;
//			long orig_size = 0;
			long actual_total_size = 0;
			int size = 0;
			System.IO.FileInfo file_info;
			bool UserCancelled = false;
			bool rotate = true;

			// Lets remove the mail "create mail" dialog
			Dialog.Destroy();			

			if (args.ResponseId != Gtk.ResponseType.Ok) {
				return;
			}
			ProgressDialog progress_dialog = null;
			actual_total_size = 0;
		
			progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing email"),
							      ProgressDialog.CancelButtonType.Stop,
							      selection.Items.Length, 
							      parent_window);
			
			size = GetScaleSize(); // Which size should we scale to. 0 --> Original
			
			// evaluate mailto command and define attachment args for cli
			System.Text.StringBuilder attach_arg = new System.Text.StringBuilder ();
			switch (Preferences.Get (Preferences.GNOME_MAILTO_COMMAND) as string) {
				case "thunderbird %s":
				case "mozilla-thunderbird %s":
				case "seamonkey -mail -compose %s":
				case "icedove %s":
					attach_arg.Append(",");
				break;
				case "kmail %s":
					attach_arg.Append(" --attach ");
				break;
				default:  //evolution falls into default, since it supports mailto uri correctly
					attach_arg.Append("&attach=");
				break;
			}

			rotate = rotate_check.Active;  // Should we automatically rotate original photos.
			Preferences.Set (Preferences.EXPORT_EMAIL_ROTATE, rotate);

			// Initiate storage for temporary files to be deleted later
			tmp_paths = new System.Collections.ArrayList();
			
			// Create a tmp directory.
			tmp_mail_dir = System.IO.Path.GetTempFileName ();	// Create a tmp file	
			System.IO.File.Delete (tmp_mail_dir);			// Delete above tmp file
			System.IO.Directory.CreateDirectory (tmp_mail_dir);	// Create a directory with above tmp name
			
			System.Text.StringBuilder mail_attach = new System.Text.StringBuilder ();

			FilterSet filters = new FilterSet ();

			if (size != 0)
				filters.Add (new ResizeFilter ((uint) size));
			else if (rotate)
				filters.Add (new OrientationFilter ());
			filters.Add (new UniqueNameFilter (tmp_mail_dir));


			foreach (Photo photo in selection.Items) {
			
				if ( (photo != null) && (!UserCancelled) ) {

					if (progress_dialog != null)
						UserCancelled = progress_dialog.Update (String.Format 
							(Catalog.GetString ("Exporting picture \"{0}\""), photo.Name));
							
					if (UserCancelled)
					 	break;
					 	
					file_info = new System.IO.FileInfo (photo.GetVersionPath(photo.DefaultVersionId));
//					orig_size = file_info.Length;

					// Prepare a tmp_mail file name
					FilterRequest request = new FilterRequest (photo.DefaultVersionUri);

					filters.Convert (request);
					request.Preserve(request.Current);

 					mail_attach.Append(attach_arg.ToString() + System.Web.HttpUtility.UrlEncode (request.Current.ToString()));
					
					// Mark the path for deletion
					tmp_paths.Add (request.Current.LocalPath);

					// Update the running total of the actual file sizes.
					file_info = new System.IO.FileInfo (request.Current.LocalPath);
					new_size = file_info.Length;
					actual_total_size += new_size;

					// Update dialog to indicate Actual size!
					// This is currently disabled, since the dialog box is not visible at this stage.
					// string approxresult = SizeUtil.ToHumanReadable (actual_total_size);
					// ActualMailSize.Text = approxresult;	


					//System.Console.WriteLine ("Orig file size {0}, New file size {1}, % {4}, Scaled to size {2}, new name {3}", 
					//orig_size, new_size, size, tmp_path, 1 - ((orig_size-new_size)/orig_size));
				}
			} // foreach
			
			if (progress_dialog != null) 
				progress_dialog.Destroy (); // No need to keep this window

			if (UserCancelled)
				DeleteTempFile();
			else {		
				// Send the mail :)
				switch (Preferences.Get (Preferences.GNOME_MAILTO_COMMAND) as string) {
					// openSuSE
					case "thunderbird %s":
						System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=my photos,attachment='" + mail_attach + "'\"");
					break;
					case "icedove %s":
						System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=my photos,attachment='" + mail_attach + "'\"");
					break;
					case "mozilla-thunderbird %s":
						System.Diagnostics.Process.Start("mozilla-thunderbird", " -compose \"subject=my photos,attachment='" + mail_attach + "'\"");
					break;
					case "seamonkey -mail -compose %s":
						System.Diagnostics.Process.Start("seamonkey", " -mail -compose \"subject=my photos,attachment='" + mail_attach + "'\"");
					break;
					case "kmail %s":
						System.Diagnostics.Process.Start("kmail", "  --composer --subject \"my photos\"" + mail_attach);
					break;
					default: 
						GnomeUtil.UrlShow (parent_window,"mailto:?subject=my%20photos" + mail_attach);
					break;
				}
				                
				// Check if we have any temporary files to be deleted
				if (tmp_paths.Count > 0) {
					// Fetch timeout value from preferences. In seconds. Needs to be multiplied with 1000 to get msec
					uint delete_timeout;
					delete_timeout = (uint) ( (int) Preferences.Get (Preferences.EXPORT_EMAIL_DELETE_TIMEOUT_SEC) );
					delete_timeout = delete_timeout * 1000; // to get milliseconds.

					// Start a timer and when it occurs, delete the temp files.
					GLib.Timeout.Add (delete_timeout, new GLib.TimeoutHandler (DeleteTempFile));
				}
			}
		}
コード例 #14
0
        public void ProcessImage(int image_num, Filters.FilterSet filter_set)
        {
            IBrowsableItem photo      = collection [image_num];
            string         photo_path = photo.DefaultVersionUri.LocalPath;
            string         path;
            ScaleRequest   req;

            req = requests [0];

            MakeDir(SubdirPath(req.Name));
            path = SubdirPath(req.Name, ImageName(image_num));

            using (Filters.FilterRequest request = new Filters.FilterRequest(photo.DefaultVersionUri)) {
                filter_set.Convert(request);
                if (request.Current.LocalPath == path)
                {
                    request.Preserve(request.Current);
                }
                else
                {
                    File.Copy(request.Current.LocalPath, path, true);
                }

                if (photo != null && photo is Photo && Core.Database != null)
                {
                    Core.Database.Exports.Create((photo as Photo).Id, (photo as Photo).DefaultVersionId,
                                                 ExportStore.FolderExportType,
                                                 // FIXME this is wrong, the final path is the one
                                                 // after the Xfer.
                                                 UriList.PathToFileUriEscaped(path).ToString());
                }

                using (Exif.ExifData data = new Exif.ExifData(photo_path)) {
                    for (int i = 1; i < requests.Length; i++)
                    {
                        req = requests [i];
                        if (scale && req.AvoidScale(size))
                        {
                            continue;
                        }

                        Filters.FilterSet req_set = new Filters.FilterSet();
                        req_set.Add(new Filters.ResizeFilter((uint)Math.Max(req.Width, req.Height)));
                        if ((bool)Preferences.Get(Preferences.EXPORT_FOLDER_SHARPEN))
                        {
                            if (req.Name == "lq")
                            {
                                req_set.Add(new Filters.SharpFilter(0.1, 2, 4));
                            }
                            if (req.Name == "thumbs")
                            {
                                req_set.Add(new Filters.SharpFilter(0.1, 2, 5));
                            }
                        }
                        using (Filters.FilterRequest tmp_req = new Filters.FilterRequest(photo.DefaultVersionUri)) {
                            req_set.Convert(tmp_req);
                            MakeDir(SubdirPath(req.Name));
                            path = SubdirPath(req.Name, ImageName(image_num));
                            System.IO.File.Copy(tmp_req.Current.LocalPath, path, true);
                        }
                    }
                }
            }
        }
コード例 #15
0
		public void ProcessImage (int image_num, Filters.FilterSet filter_set)
		{
			IBrowsableItem photo = collection [image_num];
			string photo_path = photo.DefaultVersionUri.LocalPath;
			string path;
			ScaleRequest req;

			req = requests [0];
			
			MakeDir (SubdirPath (req.Name));
			path = SubdirPath (req.Name, ImageName (image_num));
			
			using (Filters.FilterRequest request = new Filters.FilterRequest (photo.DefaultVersionUri)) {
				filter_set.Convert (request);
				if (request.Current.LocalPath == path)
					request.Preserve(request.Current);
				else
					File.Copy (request.Current.LocalPath, path, true); 

				if (photo != null && photo is Photo && Core.Database != null) {
					Core.Database.Exports.Create ((photo as Photo).Id, (photo as Photo).DefaultVersionId,
								      ExportStore.FolderExportType,
								      // FIXME this is wrong, the final path is the one
								      // after the Xfer.
								      UriList.PathToFileUriEscaped (path).ToString ());
				}

				using (Exif.ExifData data = new Exif.ExifData (photo_path)) {
					for (int i = 1; i < requests.Length; i++) {
						
						req = requests [i];
						if (scale && req.AvoidScale (size))
							continue;
				
						Filters.FilterSet req_set = new Filters.FilterSet ();
						req_set.Add (new Filters.ResizeFilter ((uint)Math.Max (req.Width, req.Height)));
						if ((bool)Preferences.Get (Preferences.EXPORT_FOLDER_SHARPEN)) {
							if (req.Name == "lq")
								req_set.Add (new Filters.SharpFilter (0.1, 2, 4));
							if (req.Name == "thumbs")
								req_set.Add (new Filters.SharpFilter (0.1, 2, 5));
						}
						using (Filters.FilterRequest tmp_req = new Filters.FilterRequest (photo.DefaultVersionUri)) {
							req_set.Convert (tmp_req);
							MakeDir (SubdirPath (req.Name));
							path = SubdirPath (req.Name, ImageName (image_num));
							System.IO.File.Copy (tmp_req.Current.LocalPath, path, true);
						}
						
					}
				}
			}
		}
コード例 #16
0
ファイル: GalleryExport.cs プロジェクト: Yetangitu/f-spot
        private void Upload()
        {
            account.Gallery.Progress = new ProgressItem ();
            account.Gallery.Progress.Changed += HandleProgressChanged;

            Log.Debug ("Starting upload");

            FilterSet filters = new FilterSet ();
            if (account.Version == GalleryVersion.Version1)
                filters.Add (new WhiteListFilter (new string []{".jpg", ".jpeg", ".png", ".gif"}));
            if (scale)
                filters.Add (new ResizeFilter ((uint)size));

            while (photo_index < items.Length) {
                IPhoto item = items [photo_index];

                Log.DebugFormat ("uploading {0}", photo_index);

                progress_dialog.Message = System.String.Format (Catalog.GetString ("Uploading picture \"{0}\""), item.Name);
                progress_dialog.Fraction = photo_index / (double)items.Length;
                photo_index++;

                progress_dialog.ProgressText = System.String.Format (Catalog.GetString ("{0} of {1}"), photo_index, items.Length);

                FilterRequest req = new FilterRequest (item.DefaultVersion.Uri);

                filters.Convert (req);
                try {
                    int id = album.Add (item, req.Current.LocalPath);

                    if (item != null && item is Photo && App.Instance.Database != null && id != 0)
                            App.Instance.Database.Exports.Create ((item as Photo).Id, (item as Photo).DefaultVersionId,
                                              ExportStore.Gallery2ExportType,
                                              String.Format("{0}:{1}",album.Gallery.Uri.ToString (), id.ToString ()));
                } catch (System.Exception e) {
                    progress_dialog.Message = String.Format (Catalog.GetString ("Error uploading picture \"{0}\" to Gallery: {1}"), item.Name, e.Message);
                    progress_dialog.ProgressText = Catalog.GetString ("Error");
                    Log.Exception (e);

                    if (progress_dialog.PerformRetrySkip ())
                            photo_index--;
                }
            }

            progress_dialog.Message = Catalog.GetString ("Done Sending Photos");
            progress_dialog.Fraction = 1.0;
            progress_dialog.ProgressText = Catalog.GetString ("Upload Complete");
            progress_dialog.ButtonLabel = Gtk.Stock.Ok;

            if (browser)
                GtkBeans.Global.ShowUri (export_dialog.Screen, album.GetUrl());
        }
コード例 #17
0
		private void HandleResponse (object sender, Gtk.ResponseArgs args)
		{
			int size = 0;
			bool UserCancelled = false;
			bool rotate = true;

			// Lets remove the mail "create mail" dialog
			Dialog.Destroy();			

			if (args.ResponseId != Gtk.ResponseType.Ok) {
				return;
			}
			ProgressDialog progress_dialog = null;
		
			progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing email"),
							      ProgressDialog.CancelButtonType.Stop,
							      selection.Count,
							      parent_window);
			
			size = GetScaleSize(); // Which size should we scale to. 0 --> Original
			
			// evaluate mailto command and define attachment args for cli
			System.Text.StringBuilder attach_arg = new System.Text.StringBuilder ();
			switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) {
				case "thunderbird %s":
				case "mozilla-thunderbird %s":
				case "seamonkey -mail -compose %s":
				case "icedove %s":
					attach_arg.Append(",");
				break;
				case "kmail %s":
					attach_arg.Append(" --attach ");
				break;
				default:  //evolution falls into default, since it supports mailto uri correctly
					attach_arg.Append("&attach=");
				break;
			}

			rotate = rotate_check.Active;  // Should we automatically rotate original photos.
			Preferences.Set (Preferences.EXPORT_EMAIL_ROTATE, rotate);

			// Initiate storage for temporary files to be deleted later
			tmp_paths = new System.Collections.ArrayList();
			
			// Create a tmp directory.
			tmp_mail_dir = System.IO.Path.GetTempFileName ();	// Create a tmp file	
			System.IO.File.Delete (tmp_mail_dir);			// Delete above tmp file
			System.IO.Directory.CreateDirectory (tmp_mail_dir);	// Create a directory with above tmp name
			
			System.Text.StringBuilder mail_attach = new System.Text.StringBuilder ();

			FilterSet filters = new FilterSet ();

			if (size != 0)
				filters.Add (new ResizeFilter ((uint) size));
			else if (rotate)
				filters.Add (new OrientationFilter ());
			filters.Add (new UniqueNameFilter (tmp_mail_dir));


			for (int i = 0; i < selection.Count; i++) {
				Photo photo = selection [i] as Photo;
				if ( (photo != null) && (!UserCancelled) ) {

					if (progress_dialog != null)
						UserCancelled = progress_dialog.Update (String.Format 
							(Catalog.GetString ("Exporting picture \"{0}\""), photo.Name));
							
					if (UserCancelled)
					 	break;
					 	
					try {
						// Prepare a tmp_mail file name
						FilterRequest request = new FilterRequest (photo.DefaultVersionUri);

						filters.Convert (request);
						request.Preserve(request.Current);

						mail_attach.Append(attach_arg.ToString() + request.Current.ToString ());
						
						// Mark the path for deletion
						tmp_paths.Add (request.Current.LocalPath);
					} catch (Exception e) {
						Console.WriteLine("Error preparing {0}: {1}", selection[photo_index].Name, e.Message);
						HigMessageDialog md = new HigMessageDialog (parent_window, 
											    DialogFlags.DestroyWithParent,
											    MessageType.Error,
											    ButtonsType.Close,
											    Catalog.GetString("Error processing image"), 
											    String.Format(Catalog.GetString("An error occured while processing \"{0}\": {1}"), selection[photo_index].Name, e.Message));
						md.Run();
						md.Destroy();
						UserCancelled = true;
					}
				}
			} // foreach
			
			if (progress_dialog != null) 
				progress_dialog.Destroy (); // No need to keep this window

			if (UserCancelled)
				DeleteTempFile();
			else {		
				// Send the mail :)
				string mail_subject = Catalog.GetString("my photos");
				switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) {
					// openSuSE
					case "thunderbird %s":
						System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
					break;
					case "icedove %s":
						System.Diagnostics.Process.Start("icedove", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
					break;
					case "mozilla-thunderbird %s":
						System.Diagnostics.Process.Start("mozilla-thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
					break;
					case "seamonkey -mail -compose %s":
						System.Diagnostics.Process.Start("seamonkey", " -mail -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
					break;
					case "kmail %s":
						System.Diagnostics.Process.Start("kmail", "  --composer --subject \"" + mail_subject + "\"" + mail_attach);
					break;
					default: 
						GnomeUtil.UrlShow ("mailto:?subject=" + System.Web.HttpUtility.UrlEncode(mail_subject) + mail_attach);
					break;
				}
				                
				// Check if we have any temporary files to be deleted
				if (tmp_paths.Count > 0) {
					// Fetch timeout value from preferences. In seconds. Needs to be multiplied with 1000 to get msec
					uint delete_timeout;
					delete_timeout = (uint) (Preferences.Get<int> (Preferences.EXPORT_EMAIL_DELETE_TIMEOUT_SEC));
					delete_timeout = delete_timeout * 1000; // to get milliseconds.

					// Start a timer and when it occurs, delete the temp files.
					GLib.Timeout.Add (delete_timeout, new GLib.TimeoutHandler (DeleteTempFile));
				}
			}
		}
コード例 #18
0
ファイル: PictureTile.cs プロジェクト: Yetangitu/f-spot
        void CreatePhotoWall()
        {
            dir_tmp = System.IO.Path.GetTempFileName ();
            System.IO.File.Delete (dir_tmp);
            System.IO.Directory.CreateDirectory (dir_tmp);
            dir_tmp += "/";

            //Prepare the pictures
            ProgressDialog progress_dialog = null;
            progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing selected pictures"),
                                  ProgressDialog.CancelButtonType.Stop,
                                  App.Instance.Organizer.SelectedPhotos ().Length, picturetile_dialog);

            FilterSet filters = new FilterSet ();
            filters.Add (new JpegFilter ());
            uint counter = 0;
            List<Tag> all_tags = new List<Tag> ();
            foreach (Photo p in App.Instance.Organizer.SelectedPhotos ()) {
                if (progress_dialog.Update (String.Format (Catalog.GetString ("Processing \"{0}\""), p.Name))) {
                    progress_dialog.Destroy ();
                    DeleteTmp ();
                    return;
                }

                //Store photo tags, to attach them later on import
                foreach (Tag tag in p.Tags) {
                    if (! all_tags.Contains (tag))
                        all_tags.Add (tag);
                }

                //FIXME should switch to retry/skip
                if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) {
                    Log.WarningFormat ("Couldn't access photo {0} while creating mosaics", p.DefaultVersion.Uri.LocalPath);
                    continue;
                }

                using (FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri)) {
                    filters.Convert (freq);
                    File.Copy (freq.Current.LocalPath, String.Format ("{0}{1}.jpg", dir_tmp, counter ++));
                }
            }
            if (progress_dialog != null)
                progress_dialog.Destroy ();

            photo_tags = all_tags.ToArray ();

            string uniform = "";
            if (uniform_images.Active)
                uniform = "--uniform";
            string output_format = "jpeg";
            if (tiff_radio.Active)
                output_format = "tiff";
            string scale = String.Format (CultureInfo.InvariantCulture, "{0,4}", (double) image_scale.Value / (double) 100);

            destfile_tmp = String.Format ("{0}.{1}", System.IO.Path.GetTempFileName (), output_format);

            //Execute picturetile
            string picturetile_command = String.Format ("--size {0}x{1} " +
                                    "--directory {2} " +
                                    "--scale {3} " +
                                    "--margin {4} " +
                                    "--border {5} " +
                                    "--background {6} " +
                                    "--pages {7} " +
                                    "{8} " +
                                    "{9}",
                                x_max_size.Text,
                                y_max_size.Text,
                                dir_tmp,
                                scale,
                                space_between_images.Text,
                                outside_border.Text,
                                colors [background_color.Active],
                                pages.Text,
                                uniform,
                                destfile_tmp);
            Log.Debug ("Executing: picturetile.pl " + picturetile_command);
            System.Diagnostics.Process pt_exe = System.Diagnostics.Process.Start ("picturetile.pl", picturetile_command);
            pt_exe.WaitForExit ();

            // Handle multiple files generation (pages).
            // If the user wants 2 pages (images), and the output filename is out.jpg, picturetile will create
            // /tmp/out1.jpg and /tmp/out2.jpg.
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo (System.IO.Path.GetDirectoryName (destfile_tmp));
            string filemask = System.IO.Path.GetFileNameWithoutExtension (destfile_tmp) + "*" + System.IO.Path.GetExtension (destfile_tmp);
            FileInfo [] fi = di.GetFiles (filemask);

            // Move generated files to f-spot photodir
            string [] photo_import_list = new string [fi.Length];
            counter = 0;
            foreach (FileInfo f in fi) {
                string orig = System.IO.Path.Combine (f.DirectoryName, f.Name);
                photo_import_list [counter ++] = MoveFile (orig);
            }

            //Add the pic(s) to F-Spot!
            Db db = App.Instance.Database;
            ImportCommand command = new ImportCommand (null);
            if (command.ImportFromPaths (db.Photos, photo_import_list, photo_tags) > 0) {
                InfoDialog (Catalog.GetString ("PhotoWall generated!"),
                        Catalog.GetString ("Your photo wall have been generated and imported in F-Spot. Select the last roll to see it"),
                        Gtk.MessageType.Info);
            } else {
                InfoDialog (Catalog.GetString ("Error importing photowall"),
                        Catalog.GetString ("An error occurred while importing the newly generated photowall to F-Spot"),
                        Gtk.MessageType.Error);
            }
            DeleteTmp ();
        }
コード例 #19
0
ファイル: SmugMugExport.cs プロジェクト: Yetangitu/f-spot
        private void Upload()
        {
            sent_bytes = 0;
            approx_size = 0;

            System.Uri album_uri = null;

            Log.Debug ("Starting Upload to Smugmug, album " + album.Title + " - " + album.AlbumID);

            FilterSet filters = new FilterSet ();
            filters.Add (new JpegFilter ());

            if (scale)
                filters.Add (new ResizeFilter ((uint)size));

            while (photo_index < items.Length) {
                try {
                    IPhoto item = items[photo_index];

                    FileInfo file_info;
                    Log.Debug ("uploading " + photo_index);

                    progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"),
                                         item.Name, photo_index+1, items.Length);
                    progress_dialog.ProgressText = string.Empty;
                    progress_dialog.Fraction = ((photo_index) / (double) items.Length);
                    photo_index++;

                    FilterRequest request = new FilterRequest (item.DefaultVersion.Uri);

                    filters.Convert (request);

                    file_info = new FileInfo (request.Current.LocalPath);

                    if (approx_size == 0) //first image
                        approx_size = file_info.Length * items.Length;
                    else
                        approx_size = sent_bytes * items.Length / (photo_index - 1);

                    int image_id = account.SmugMug.Upload (request.Current.LocalPath, album.AlbumID);
                    if (App.Instance.Database != null && item is Photo && image_id >= 0)
                        App.Instance.Database.Exports.Create ((item as Photo).Id,
                                          (item as Photo).DefaultVersionId,
                                          ExportStore.SmugMugExportType,
                                          account.SmugMug.GetAlbumUrl (image_id).ToString ());

                    sent_bytes += file_info.Length;

                    if (album_uri == null)
                        album_uri = account.SmugMug.GetAlbumUrl (image_id);
                } catch (System.Exception e) {
                    progress_dialog.Message = String.Format (Mono.Unix.Catalog.GetString ("Error Uploading To Gallery: {0}"),
                                         e.Message);
                    progress_dialog.ProgressText = Mono.Unix.Catalog.GetString ("Error");
                    Log.DebugException (e);

                    if (progress_dialog.PerformRetrySkip ()) {
                        photo_index--;
                        if (photo_index == 0)
                            approx_size = 0;
                    }
                }
            }

            progress_dialog.Message = Catalog.GetString ("Done Sending Photos");
            progress_dialog.Fraction = 1.0;
            progress_dialog.ProgressText = Mono.Unix.Catalog.GetString ("Upload Complete");
            progress_dialog.ButtonLabel = Gtk.Stock.Ok;

            if (browser && album_uri != null) {
                GtkBeans.Global.ShowUri (Dialog.Screen, album_uri.ToString ());
            }
        }
コード例 #20
0
		private void Upload ()
		{
			Album album = null;

			if (create_album_radiobutton.Active) {
				string name = album_name_entry.Text;
				if (name.Length == 0) {
					HigMessageDialog mbox = new HigMessageDialog (Dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, Catalog.GetString ("Album must have a name"), Catalog.GetString ("Please name your album or choose an existing album."));
					mbox.Run ();
					mbox.Destroy ();
					return;
				}

				string description = album_description_entry.Text;
				string location = album_location_entry.Text;

				try {
					album = account.Facebook.CreateAlbum (name, description, location);
				}
				catch (FacebookException fe) {
					HigMessageDialog mbox = new HigMessageDialog (Dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, Catalog.GetString ("Creating a new album failed"), String.Format (Catalog.GetString ("An error occurred creating a new album.\n\n{0}"), fe.Message));
					mbox.Run ();
					mbox.Destroy ();
					return;
				}
			}
			else {
				AlbumStore store = (AlbumStore) existing_album_combobox.Model;
				album = store.Albums [existing_album_combobox.Active];
			}

			long sent_bytes = 0;

			FilterSet filters = new FilterSet ();
			filters.Add (new JpegFilter ());
			filters.Add (new ResizeFilter ((uint) size));

			for (int i = 0; i < items.Length; i++) {
				try {
					IBrowsableItem item = items [i];

					FileInfo file_info;
					Console.WriteLine ("uploading {0}", i);

					progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), item.Name, i + 1, items.Length);
					progress_dialog.ProgressText = string.Empty;
					progress_dialog.Fraction = i / (double) items.Length;

					FilterRequest request = new FilterRequest (item.DefaultVersionUri);
					filters.Convert (request);

					file_info = new FileInfo (request.Current.LocalPath);

					Mono.Facebook.Photo photo = album.Upload (captions [i] ?? "", request.Current.LocalPath);

					sent_bytes += file_info.Length;
				}
				catch (Exception e) {
					progress_dialog.Message = String.Format (Catalog.GetString ("Error Uploading To Facebook: {0}"), e.Message);
					progress_dialog.ProgressText = Catalog.GetString ("Error");
					Console.WriteLine (e);

					if (progress_dialog.PerformRetrySkip ())
						i--;
				}
			}

			progress_dialog.Message = Catalog.GetString ("Done Sending Photos");
			progress_dialog.Fraction = 1.0;
			progress_dialog.ProgressText = Catalog.GetString ("Upload Complete");
			progress_dialog.ButtonLabel = Gtk.Stock.Ok;

			Dialog.Destroy ();
		}