~ubuntu-branches/debian/sid/f-spot/sid

« back to all changes in this revision

Viewing changes to src/PhotoVersionCommands.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
* 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:
3
3
using System;
4
4
using Mono.Unix;
5
5
using FSpot;
6
 
using FSpot.Utils;
 
6
using Hyena;
7
7
using FSpot.UI.Dialog;
8
8
 
9
9
public class PhotoVersionCommands
10
10
{
11
 
        private class VersionNameRequest : GladeDialog {
 
11
        private class VersionNameRequest : BuilderDialog {
12
12
                private Photo photo;
13
13
 
14
 
                [Glade.Widget] private Button ok_button;
15
 
                [Glade.Widget] private Entry version_name_entry;
16
 
                [Glade.Widget] private Label prompt_label;
17
 
                [Glade.Widget] private Label already_in_use_label;
 
14
                [GtkBeans.Builder.Object] private Button ok_button;
 
15
                [GtkBeans.Builder.Object] private Entry version_name_entry;
 
16
                [GtkBeans.Builder.Object] private Label prompt_label;
 
17
                [GtkBeans.Builder.Object] private Label already_in_use_label;
18
18
 
19
19
                public enum RequestType {
20
20
                        Create,
48
48
                        Update ();
49
49
                }
50
50
 
51
 
                public VersionNameRequest (RequestType request_type, Photo photo, Gtk.Window parent_window) : base ("version_name_dialog")
 
51
                public VersionNameRequest (RequestType request_type, Photo photo, Gtk.Window parent_window) : base ("version_name_dialog.ui", "version_name_dialog")
52
52
                {
53
53
                        this.request_type = request_type;
54
54
                        this.photo = photo;
55
55
 
56
56
                        switch (request_type) {
57
57
                        case RequestType.Create:
58
 
                                this.Dialog.Title = Catalog.GetString ("Create New Version");
 
58
                                this.Title = Catalog.GetString ("Create New Version");
59
59
                                prompt_label.Text = Catalog.GetString ("Name:");
60
60
                                break;
61
61
 
62
62
                        case RequestType.Rename:
63
 
                                this.Dialog.Title = Catalog.GetString ("Rename Version");
 
63
                                this.Title = Catalog.GetString ("Rename Version");
64
64
                                prompt_label.Text = Catalog.GetString ("New name:");
65
65
                                version_name_entry.Text = photo.GetVersion (photo.DefaultVersionId).Name;
66
66
                                version_name_entry.SelectRegion (0, -1);
69
69
 
70
70
                        version_name_entry.ActivatesDefault = true;
71
71
 
72
 
                        this.Dialog.TransientFor = parent_window;
73
 
                        this.Dialog.DefaultResponse = ResponseType.Ok;
 
72
                        this.TransientFor = parent_window;
 
73
                        this.DefaultResponse = ResponseType.Ok;
74
74
 
75
75
                        Update ();
76
76
                }
77
77
 
78
78
                public ResponseType Run (out string name)
79
79
                {
80
 
                        ResponseType response = (ResponseType) this.Dialog.Run ();
 
80
                        ResponseType response = (ResponseType) this.Run ();
81
81
 
82
82
                        name = version_name_entry.Text;
83
83
                        if (request_type == RequestType.Rename && name == photo.GetVersion (photo.DefaultVersionId).Name)
84
84
                                response = ResponseType.Cancel;
85
85
 
86
 
                        this.Dialog.Destroy ();
 
86
                        this.Destroy ();
87
87
 
88
88
                        return response;
89
89
                }
106
106
                        try {
107
107
                                photo.DefaultVersionId = photo.CreateVersion (name, photo.DefaultVersionId, true);
108
108
                                store.Commit (photo);
 
109
                                return true;
109
110
                        } catch (Exception e) {
110
 
                                        string msg = Catalog.GetString ("Could not create a new version");
111
 
                                        string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to create version \"{1}\""),
112
 
                                                                     e.Message, name);
113
 
                                        
114
 
                                        HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, 
115
 
                                                                                    Gtk.MessageType.Error, ButtonsType.Ok, 
116
 
                                                                                    msg,
117
 
                                                                                    desc);
118
 
                                        md.Run ();
119
 
                                        md.Destroy ();
120
 
                                        return false;
 
111
                                HandleException ("Could not create a new version", e, parent_window);
 
112
                                return false;
121
113
                        }
122
 
 
123
 
                        return true;
124
114
                }
125
115
        }
126
116
 
130
120
        public class Delete {
131
121
                public bool Execute (PhotoStore store, Photo photo, Gtk.Window parent_window)
132
122
                {
133
 
                        // FIXME HIG-ify.
134
 
                        Dialog dialog = new Dialog ();
135
 
                        dialog.BorderWidth = 6;
136
 
                        dialog.TransientFor = parent_window;
137
 
                        dialog.HasSeparator = false;
138
 
                        dialog.Title = Catalog.GetString ("Really Delete?");
139
 
                        dialog.AddButton (Catalog.GetString ("Cancel"), (int) ResponseType.Cancel);
140
 
                        dialog.AddButton (Catalog.GetString ("Delete"), (int) ResponseType.Ok);
141
 
                        dialog.DefaultResponse = ResponseType.Ok;
142
 
 
143
 
                        string version_name = photo.GetVersion (photo.DefaultVersionId).Name;
144
 
                        Label label = new Label (String.Format (Catalog.GetString ("Really delete version \"{0}\"?"), version_name));
145
 
                        label.Show ();
146
 
                        dialog.VBox.PackStart (label, false, true, 6);;
147
 
 
148
 
                        if (dialog.Run () == (int) ResponseType.Ok) {
149
 
                                try {
 
123
                        string ok_caption = Catalog.GetString ("Delete");
 
124
                        string msg = String.Format (Catalog.GetString ("Really delete version \"{0}\"?"), photo.DefaultVersion.Name);
 
125
                        string desc = Catalog.GetString ("This removes the version and deletes the corresponding file from disk.");
 
126
                        try {
 
127
                                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, 
 
128
                                                                           MessageType.Warning, msg, desc, ok_caption)) {
150
129
                                        photo.DeleteVersion (photo.DefaultVersionId);
151
130
                                        store.Commit (photo);
152
 
                                } catch (Exception e) {
153
 
                                        Log.DebugException (e);
154
 
                                        string msg = Catalog.GetString ("Could not delete a version");
155
 
                                        string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to delete version \"{1}\""),
156
 
                                                                     e.Message, photo.Name);
157
 
                                        
158
 
                                        HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, 
159
 
                                                                                    Gtk.MessageType.Error, ButtonsType.Ok, 
160
 
                                                                                    msg,
161
 
                                                                                    desc);
162
 
                                        md.Run ();
163
 
                                        md.Destroy ();
164
 
                                        dialog.Destroy (); // Delete confirmation window.
165
 
                                        return false;
 
131
                                        return true;
166
132
                                }
167
 
 
168
 
                                dialog.Destroy ();
169
 
                                return true;
 
133
                        } catch (Exception e) {
 
134
                                HandleException ("Could not delete a version", e, parent_window);
170
135
                        }
171
 
 
172
 
                        dialog.Destroy ();
173
136
                        return false;
174
137
                }
175
138
        }
176
139
 
177
 
 
178
140
        // Renaming a version.
179
141
 
180
142
        public class Rename {
192
154
                        try {
193
155
                                photo.RenameVersion (photo.DefaultVersionId, new_name);
194
156
                                store.Commit (photo);
 
157
                                return true;
195
158
                        } catch (Exception e) {
196
 
                                        string msg = Catalog.GetString ("Could not rename a version");
197
 
                                        string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to rename version to \"{1}\""),
198
 
                                                                     e.Message, new_name);
199
 
                                        
200
 
                                        HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, 
201
 
                                                                                    Gtk.MessageType.Error, ButtonsType.Ok, 
202
 
                                                                                    msg,
203
 
                                                                                    desc);
204
 
                                        md.Run ();
205
 
                                        md.Destroy ();
206
 
                                        return false;
 
159
                                HandleException ("Could not rename a version", e, parent_window);
 
160
                                return false;
207
161
                        }
 
162
                }
 
163
        }
208
164
 
209
 
                        return true;
 
165
        // Detaching a version (making it a separate photo).
 
166
        
 
167
        public class Detach {
 
168
                public bool Execute (PhotoStore store, Photo photo, Gtk.Window parent_window)
 
169
                {
 
170
                        string ok_caption = Catalog.GetString ("De_tach");
 
171
                        string msg = String.Format (Catalog.GetString ("Really detach version \"{0}\" from \"{1}\"?"), photo.DefaultVersion.Name, photo.Name.Replace("_", "__"));
 
172
                        string desc = Catalog.GetString ("This makes the version appear as a separate photo in the library. To undo, drag the new photo back to its parent.");
 
173
                        try {
 
174
                                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, 
 
175
                                                                           MessageType.Warning, msg, desc, ok_caption)) {
 
176
                                        Photo new_photo = store.CreateFrom (photo, photo.RollId);
 
177
                                        new_photo.CopyAttributesFrom (photo);
 
178
                                        photo.DeleteVersion (photo.DefaultVersionId, false, true);
 
179
                                        store.Commit (new Photo[] {new_photo, photo});
 
180
                                        return true;
 
181
                                }
 
182
                        } catch (Exception e) {
 
183
                                HandleException ("Could not detach a version", e, parent_window);
 
184
                        }
 
185
                        return false;
210
186
                }
211
187
        }
212
188
 
213
189
        // Reparenting a photo as version of another one
 
190
        
214
191
        public class Reparent {
215
192
                public bool Execute (PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
216
193
                {
217
 
                        foreach (Photo photo in photos) {
218
 
                                new_parent.AddTag (photo.Tags);
219
 
                                foreach (uint version_id in photo.VersionIds) {
220
 
                                        try {
221
 
                                                new_parent.DefaultVersionId = new_parent.CreateReparentedVersion (photo.GetVersion (version_id) as PhotoVersion);
222
 
                                                store.Commit (new_parent);
223
 
                                        } catch (Exception e) {
224
 
                                                Log.DebugException (e); 
225
 
                                        }
226
 
                                }
227
 
                                uint [] version_ids = photo.VersionIds;
228
 
                                Array.Reverse (version_ids);
229
 
                                foreach (uint version_id in version_ids) {
230
 
                                        try {
231
 
                                                photo.DeleteVersion (version_id, true, true);
232
 
                                        } catch (Exception e) {
233
 
                                                Log.DebugException (e);
234
 
                                        }
235
 
                                }
236
 
                                MainWindow.Toplevel.Database.Photos.Remove (photo);
237
 
                        }
238
 
                        return true;
 
194
                        string ok_caption = Catalog.GetString ("Re_parent");
 
195
                        string msg = String.Format (Catalog.GetPluralString ("Really reparent \"{0}\" as version of \"{1}\"?", 
 
196
                                                                             "Really reparent {2} photos as versions of \"{1}\"?", photos.Length), 
 
197
                                                    new_parent.Name.Replace ("_", "__"), photos[0].Name.Replace ("_", "__"), photos.Length);
 
198
                        string desc = Catalog.GetString ("This makes the photos appear as a single one in the library. The versions can be detached using the Photo menu.");
 
199
 
 
200
                        try {
 
201
                                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, 
 
202
                                                                           MessageType.Warning, msg, desc, ok_caption)) {
 
203
                                        uint highest_rating = new_parent.Rating;
 
204
                                        string new_description = new_parent.Description;
 
205
                                        foreach (Photo photo in photos) {
 
206
                                                highest_rating = Math.Max(photo.Rating, highest_rating);
 
207
                                                if (string.IsNullOrEmpty(new_description))
 
208
                                                        new_description = photo.Description;
 
209
                                                new_parent.AddTag (photo.Tags);
 
210
                                                
 
211
                                                foreach (uint version_id in photo.VersionIds) {
 
212
                                                        new_parent.DefaultVersionId = new_parent.CreateReparentedVersion (photo.GetVersion (version_id) as PhotoVersion);
 
213
                                                        store.Commit (new_parent);
 
214
                                                }
 
215
                                                uint [] version_ids = photo.VersionIds;
 
216
                                                Array.Reverse (version_ids);
 
217
                                                foreach (uint version_id in version_ids) {
 
218
                                                        photo.DeleteVersion (version_id, true, true);
 
219
                                                }
 
220
                                                store.Remove (photo);
 
221
                                        }
 
222
                                        new_parent.Rating = highest_rating;
 
223
                                        new_parent.Description = new_description;
 
224
                                        store.Commit (new_parent);
 
225
                                        return true;
 
226
                                }
 
227
                        }
 
228
                        catch (Exception e) {
 
229
                                HandleException ("Could not reparent photos", e, parent_window);
 
230
                        }
 
231
                        return false;
239
232
                }
240
233
        }
 
234
        
 
235
        private static void HandleException (string msg, Exception e, Gtk.Window parent_window) {
 
236
                Log.DebugException (e);
 
237
                msg = Catalog.GetString (msg);
 
238
                string desc = String.Format (Catalog.GetString ("Received exception \"{0}\"."), e.Message);
 
239
                HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, 
 
240
                                                            Gtk.MessageType.Error, ButtonsType.Ok, msg, desc);
 
241
                md.Run ();
 
242
                md.Destroy ();
 
243
        }
241
244
}