Beispiel #1
0
 private void Destroy(object sender, System.EventArgs args)
 {
     progress_dialog.Destroy();
 }
		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));
				}
			}
		}
        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));
                }
            }
        }
Beispiel #4
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));
                }
            }
        }