~ubuntu-branches/ubuntu/saucy/f-spot/saucy

« back to all changes in this revision

Viewing changes to src/SendEmail.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-24 10:35:57 UTC
  • mfrom: (2.4.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20100524103557-1j0i8f66caybci2n
Tags: 0.7.0-1
* New upstream release 0.7.0
 + First release of the unstable 0.7 development series. Massive changes.
 + Reparenting and detaching support (Anton Keks) (Closes: #559745)
 + A new Mallard-based documentation (Harold Schreckengost)
 + No longer embeds flickrnet, uses distribution copy (Iain Lane)
 + Adoption of a large amount of Hyena functionality (Paul Lange, Peter
   Goetz)
 + No longer embeds gnome-keyring-sharp
 + Completely rewritten import, much faster and less memory hungry (Ruben
   Vermeersch) (Closes: #559080, #492658, #341790, #357811, #426017) (LP:
   #412091)
 + No longer use gphoto2-sharp, now uses gvfs which is less crash-pron
   (Ruben Vermeersch)
 + Fix Facebook support (Ruben Vermeersch)
 + Modernized unit tests
 + Revamped build (Mike Gemünde)
 + Much improved duplicate detection (much faster too) (Ruben Vermeersch)
 + Mouse selection in Iconview (Vincent Pomey)
 + Image panning support using middle mouse button (Wojciech Dzierżanowski)
 + Timeline slider now restricted to the size of the window (Iain Churcher)
 + Over 100 bugs closed (http://bit.ly/cyVjnD)
   - No more warnings about schema defaults (Closes: #584215) (LP: #586132)
* debian/control: Clean up build deps to match configure checks
* debian/rules: Don't run dh_makeshilbs as we don't ship any shared
  libraries. There are some private ones though, which get picked up and
  result in a useless postinst/postrm call to ldconfig. Thanks, lintian.
* debian/patches/debian_fix-distclean.patch,
  debian/patches/debian_fix_f-spot.exe.config.patch,
  debian/patches/debian_link-system-flickrnet.patch,
  debian/patches/debian_link-system-gnome-keyring.patch,
  debian/patches/debian_disable-unit-tests,
  debian/patches/git_transition_duration.patch,
  debian/patches/ubuntu_fix_folder_export_hang.patch:
  Clean up obsolete patches which are no longer necessary 
* debian/patches/*: Temporarily disable patches which originated from Ubuntu
  and no longer apply cleanly. We will get these back in a future upstream
  development release.
* debian/patches/*: Refresh to apply cleanly 
* debian/rules: Add new include dir to autoreconf call to pick up f-spot
  macros 

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Author(s)
5
5
 *      Bengt Thuree  <bengt@thuree.com>
6
6
 *      Stephane Delcroix  <stephane@delcroix.org>
 
7
 *      Paul Lange <palango@gmx.de>
7
8
 *
8
9
 * This is free software. See COPYING for details.
9
10
 */
14
15
 
15
16
using FSpot.Widgets;
16
17
using FSpot.Filters;
17
 
using FSpot.Utils;
18
18
using FSpot.UI.Dialog;
19
19
 
 
20
using Hyena;
20
21
using Mono.Unix;
21
22
 
22
 
namespace FSpot {
23
 
        public class SendEmail : GladeDialog {
 
23
namespace FSpot
 
24
{
 
25
        public class SendEmail : BuilderDialog
 
26
        {
24
27
                Window parent_window;
25
 
                PhotoQuery query;
26
 
 
27
 
                [Glade.Widget] private ScrolledWindow   tray_scrolled;
28
 
                [Glade.Widget] private Button           ok_button;
29
 
                [Glade.Widget] private Label            NumberOfPictures, TotalOriginalSize, ApproxNewSize;     
30
 
                [Glade.Widget] private RadioButton      tiny_size, small_size, medium_size, 
31
 
                                                        large_size, x_large_size, original_size;
32
 
                [Glade.Widget] private CheckButton      rotate_check;
33
 
 
34
 
                bool clean;
 
28
 
 
29
#pragma warning disable 0649
 
30
                [GtkBeans.Builder.Object] private ScrolledWindow   tray_scrolled;
 
31
                [GtkBeans.Builder.Object] private Label                 NumberOfPictures, TotalOriginalSize, ApproxNewSize;
 
32
                [GtkBeans.Builder.Object] private RadioButton   tiny_size, small_size, medium_size,
 
33
                                                                                                                large_size, x_large_size, original_size;
 
34
                [GtkBeans.Builder.Object] private CheckButton   rotate_check;
 
35
#pragma warning restore 0649
 
36
 
35
37
                long Orig_Photo_Size    = 0;
36
38
                double scale_percentage = 0.3;
37
39
                
43
45
                
44
46
                static int NoOfSizes    = sizes.Length;
45
47
                double[] avg_scale      = new double [NoOfSizes];
46
 
                System.Collections.ArrayList tmp_paths; // temporary resized image file name
47
48
                string tmp_mail_dir;    // To temporary keep the resized images
48
49
                bool force_original = false;
49
50
 
50
 
                ThreadProgressDialog progress_dialog;
51
 
                System.Threading.Thread command_thread;
52
51
                IBrowsableCollection selection;
53
52
 
54
 
                public SendEmail (IBrowsableCollection selection, Window parent_window) : base ("mail_dialog")
 
53
                public SendEmail (IBrowsableCollection selection, Window parent_window) : base ("mail_dialog.ui", "mail_dialog")
55
54
                {
56
55
                        this.selection = selection;
57
56
                        this.parent_window = parent_window;
58
57
 
59
 
                        for (int i = 0; i < selection.Count; i++) {
60
 
                                Photo p = selection[i] as Photo;
61
 
                                if (FileFactory.NewForUri (p.DefaultVersionUri).QueryInfo ("standard::content-type", FileQueryInfoFlags.None, null).ContentType != "image/jpeg")
 
58
                        foreach (var p in selection.Items) {
 
59
                                if (FileFactory.NewForUri (p.DefaultVersion.Uri).QueryInfo ("standard::content-type", FileQueryInfoFlags.None, null).ContentType != "image/jpeg")
62
60
                                        force_original = true;
63
61
                        }
64
62
 
69
67
                                medium_size.Sensitive = false;
70
68
                                large_size.Sensitive = false;
71
69
                                x_large_size.Sensitive = false;
72
 
                        } else  
 
70
                        } else
73
71
                                switch (Preferences.Get<int> (Preferences.EXPORT_EMAIL_SIZE)) {
74
72
                                        case 0 :  original_size.Active = true; break;
75
73
                                        case 1 :  tiny_size.Active = true; break;
85
83
                        
86
84
                        tray_scrolled.Add (new TrayView (selection));
87
85
 
88
 
                        Dialog.Modal = false;
 
86
                        Modal = false;
89
87
 
90
88
                        // Calculate total original filesize 
91
 
                        for (int i = 0; i < selection.Count; i++) {
92
 
                                Photo photo = selection[i] as Photo;
 
89
                        foreach (var photo in selection.Items) {
93
90
                                try {
94
 
                                        Orig_Photo_Size += FileFactory.NewForUri (photo.DefaultVersionUri).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size;
 
91
                                        Orig_Photo_Size += FileFactory.NewForUri (photo.DefaultVersion.Uri).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size;
95
92
                                } catch {
96
93
                                }
97
94
                        }
101
98
 
102
99
 
103
100
                        // Calculate approximate size shrinking, use first photo, and shrink to medium size as base.
104
 
                        Photo scalephoto = selection [0] as Photo;
 
101
                        var scalephoto = selection [0];
105
102
                        if (scalephoto != null && !force_original) {
106
103
                                
107
104
                                // Get first photos file size
108
 
                                long orig_size = FileFactory.NewForUri (scalephoto.DefaultVersionUri).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size;
 
105
                                long orig_size = FileFactory.NewForUri (scalephoto.DefaultVersion.Uri).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size;
109
106
                                
110
107
                                FilterSet filters = new FilterSet ();
111
108
                                filters.Add (new ResizeFilter ((uint)(sizes [3])));
112
109
                                long new_size;
113
 
                                using (FilterRequest request = new FilterRequest (scalephoto.DefaultVersionUri)) {
 
110
                                using (FilterRequest request = new FilterRequest (scalephoto.DefaultVersion.Uri)) {
114
111
                                        filters.Convert (request);
115
112
                                        new_size = FileFactory.NewForUri (request.Current).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size;
116
113
                                }
123
120
                                        // What is the relation between the estimated medium scale factor, and reality?
124
121
                                        double scale_scale = scale_percentage / avg_scale_ref[3];
125
122
                                        
126
 
                                        //System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}", 
 
123
                                        //System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}",
127
124
                                        //      scale_percentage, avg_scale_ref[3], scale_scale  );
128
125
 
129
126
                                        // Re-Calculate the proper relation per size
130
127
                                        for (int k = 0; k < avg_scale_ref.Length; k++) {
131
128
                                                avg_scale[k] = avg_scale_ref[k] * scale_scale;
132
 
                                        //      System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})", 
 
129
                                        //      System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})",
133
130
                                        //              k, avg_scale[k], avg_scale_ref[k]  );
134
131
                                        }
135
132
                                }
141
138
                        
142
139
                        UpdateEstimatedSize();
143
140
 
144
 
                        Dialog.ShowAll ();
 
141
                        ShowAll ();
145
142
 
146
143
                        //LoadHistory ();
147
144
 
148
 
                        Dialog.Response += HandleResponse;
 
145
                        Response += HandleResponse;
149
146
                }
150
147
 
151
148
                private int GetScaleSize()
152
149
                {
153
150
                        // not only convert dialog size to pixel size, but also set preferences se we use same size next time
154
151
                        int size_number = 0; // default to original size
155
 
                        if (tiny_size.Active) 
 
152
                        if (tiny_size.Active)
156
153
                                size_number = 1;
157
 
                        if (small_size.Active) 
 
154
                        if (small_size.Active)
158
155
                                size_number = 2;
159
 
                        if (medium_size.Active) 
 
156
                        if (medium_size.Active)
160
157
                                size_number = 3;
161
 
                        if (large_size.Active) 
 
158
                        if (large_size.Active)
162
159
                                size_number = 4;
163
 
                        if (x_large_size.Active) 
 
160
                        if (x_large_size.Active)
164
161
                                size_number = 5;
165
162
                        
166
 
                        if (!force_original) 
167
 
                                Preferences.Set (Preferences.EXPORT_EMAIL_SIZE, size_number);                   
168
 
                        return sizes [ size_number ];           
 
163
                        if (!force_original)
 
164
                                Preferences.Set (Preferences.EXPORT_EMAIL_SIZE, size_number);
 
165
                        return sizes [ size_number ];
169
166
                }
170
167
                
171
168
                private int GetScaleIndex ()
210
207
                        bool rotate = true;
211
208
 
212
209
                        // Lets remove the mail "create mail" dialog
213
 
                        Dialog.Destroy();                       
 
210
                        Destroy();
214
211
 
215
212
                        if (args.ResponseId != Gtk.ResponseType.Ok) {
216
213
                                return;
218
215
                        ProgressDialog progress_dialog = null;
219
216
                
220
217
                        progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing email"),
221
 
                                                              ProgressDialog.CancelButtonType.Stop,
222
 
                                                              selection.Count,
223
 
                                                              parent_window);
 
218
                                                                                                ProgressDialog.CancelButtonType.Stop,
 
219
                                                                                                selection.Count,
 
220
                                                                                                parent_window);
224
221
                        
225
222
                        size = GetScaleSize(); // Which size should we scale to. 0 --> Original
226
223
                        
236
233
                        case "kmail %s":
237
234
                                attach_arg.Append(" --attach ");
238
235
                                break;
239
 
                        default:  //evolution falls into default, since it supports mailto uri correctly
 
236
                        default://evolution falls into default, since it supports mailto uri correctly
240
237
                                attach_arg.Append("&attach=");
241
238
                                break;
242
239
                        }
243
240
 
244
241
                        rotate = rotate_check.Active;  // Should we automatically rotate original photos.
245
242
                        Preferences.Set (Preferences.EXPORT_EMAIL_ROTATE, rotate);
246
 
 
247
 
                        // Initiate storage for temporary files to be deleted later
248
 
                        tmp_paths = new System.Collections.ArrayList();
249
243
                        
250
244
                        // Create a tmp directory.
251
245
                        tmp_mail_dir = System.IO.Path.GetTempFileName ();       // Create a tmp file    
260
254
                                filters.Add (new ResizeFilter ((uint) size));
261
255
                        else if (rotate)
262
256
                                filters.Add (new OrientationFilter ());
263
 
                        filters.Add (new UniqueNameFilter (tmp_mail_dir));
 
257
                        filters.Add (new UniqueNameFilter (new SafeUri (tmp_mail_dir)));
264
258
 
265
259
 
266
260
                        for (int i = 0; i < selection.Count; i++) {
267
 
                                Photo photo = selection [i] as Photo;
 
261
                                var photo = selection [i];
268
262
                                if ( (photo != null) && (!UserCancelled) ) {
269
263
 
270
264
                                        if (progress_dialog != null)
272
266
                                                        (Catalog.GetString ("Exporting picture \"{0}\""), photo.Name));
273
267
                                                        
274
268
                                        if (UserCancelled)
275
 
                                                break;
276
 
                                                
 
269
                                                break;
 
270
 
277
271
                                        try {
278
272
                                                // Prepare a tmp_mail file name
279
 
                                                FilterRequest request = new FilterRequest (photo.DefaultVersionUri);
 
273
                                                FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri);
280
274
 
281
275
                                                filters.Convert (request);
282
276
                                                request.Preserve(request.Current);
283
277
 
284
278
                                                mail_attach.Append(((i == 0 && attach_arg.ToString () == ",") ? "" : attach_arg.ToString()) + request.Current.ToString ());
285
 
                                                
286
 
                                                // Mark the path for deletion
287
 
                                                tmp_paths.Add (request.Current.LocalPath);
288
279
                                        } catch (Exception e) {
289
 
                                                Console.WriteLine("Error preparing {0}: {1}", selection[i].Name, e.Message);
 
280
                                                Hyena.Log.ErrorFormat ("Error preparing {0}: {1}", selection[i].Name, e.Message);
290
281
                                                HigMessageDialog md = new HigMessageDialog (parent_window, 
291
282
                                                                                            DialogFlags.DestroyWithParent,
292
283
                                                                                            MessageType.Error,
303
294
                        if (progress_dialog != null) 
304
295
                                progress_dialog.Destroy (); // No need to keep this window
305
296
 
306
 
 
307
297
                        if (!UserCancelled) {
308
298
                                // Send the mail :)
309
299
                                string mail_subject = Catalog.GetString("My Photos");
325
315
                                        System.Diagnostics.Process.Start("kmail", "  --composer --subject \"" + mail_subject + "\"" + mail_attach);
326
316
                                        break;
327
317
                                case "evolution %s": //evo doesn't urldecode the subject
328
 
                                        GtkBeans.Global.ShowUri (Dialog.Screen, "mailto:?subject=" + mail_subject + mail_attach);
 
318
                                        GtkBeans.Global.ShowUri (Screen, "mailto:?subject=" + mail_subject + mail_attach);
329
319
                                        break;
330
320
                                default: 
331
 
                                        GtkBeans.Global.ShowUri (Dialog.Screen, "mailto:?subject=" + System.Web.HttpUtility.UrlEncode(mail_subject) + mail_attach);
 
321
                                        GtkBeans.Global.ShowUri (Screen, "mailto:?subject=" + System.Web.HttpUtility.UrlEncode(mail_subject) + mail_attach);
332
322
                                        break;
333
323
                                }
334
324
                        }