예제 #1
0
        public SendEmail(IBrowsableCollection selection) : base("mail_dialog")
        {
            this.selection = selection;

            // Set default values in dialog. Fetch from Preferences.
            switch ((int)Preferences.Get(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    = (bool)Preferences.Get(Preferences.EXPORT_EMAIL_ROTATE);
            rotate_check.Sensitive = original_size.Active;

            tray_scrolled.Add(new TrayView(selection));

            Dialog.Modal = false;

            string path;

            System.IO.FileInfo file_info;

            // Calculate total original filesize
            foreach (Photo photo in selection.Items)
            {
                if (photo != null)
                {
                    path = photo.GetVersionPath(photo.DefaultVersionId);
                    if (System.IO.File.Exists(path))
                    {
                        file_info        = new System.IO.FileInfo(path);
                        Orig_Photo_Size += file_info.Length;
                    }     // if file exists
                }         // if photo != null
            }             // foreach

            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.Items [0] as Photo;

            if (scalephoto != null)
            {
                // Get first photos file size
                file_info = new System.IO.FileInfo(scalephoto.GetVersionPath(scalephoto.DefaultVersionId));
                long orig_size = file_info.Length;

                // Get filesize of first photo after resizing it to medium size
                path      = PixbufUtils.Resize(scalephoto.GetVersionPath(scalephoto.DefaultVersionId), sizes[3], true);
                file_info = new System.IO.FileInfo(path);
                long new_size = file_info.Length;

                // Delete the just created temporary resized photo
                System.IO.File.Delete(path);

                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;
        }