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

« back to all changes in this revision

Viewing changes to src/MainWindow.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane, Mirco Bauer, Iain Lane
  • Date: 2009-02-07 20:23:32 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090207202332-oc93rfjo1st0571s
Tags: 0.5.0.3-2
[ Mirco Bauer]
* Upload to unstable.
* debian/control:
  + Lowered GNOME# build-deps to 2.0 ABI as that transition didn't happen
    yet in unstable.

[ Iain Lane ]
* debian/patches/svn-r4545_locales-import.dpatch: Patch backported from SVN
  trunk revision 4545 - initialize the translation catalog earlier (LP: #293305)
  (Closes: #514457). Thanks to Florian Heinle for finding the patch and to
  Chris Coulson for preparing the update.
* debian/control: Build-depend on libmono-dev (>= 1.2.4) to match configure
  checks.
* debian/rules: Pass CSC=/usr/bin/csc to configure for gio-sharp to fix FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
using Gtk;
3
3
using GtkSharp;
4
4
using Glade;
 
5
using Mono.Addins;
5
6
using Mono.Unix;
6
7
using System;
7
8
using System.Text;
8
9
 
9
10
using System.Collections;
 
11
using System.Collections.Generic;
10
12
using System.Runtime.InteropServices;
11
13
using System.Text.RegularExpressions;
12
14
using System.Web;
15
17
using Banshee.Kernel;
16
18
 
17
19
using FSpot;
 
20
using FSpot.Extensions;
18
21
using FSpot.Query;
19
22
using FSpot.Widgets;
20
23
using FSpot.Utils;
28
31
 
29
32
        Db db;
30
33
 
 
34
        Sidebar sidebar;
 
35
 
31
36
        TagSelectionWidget tag_selection_widget;
32
37
        [Glade.Widget] Gtk.Window main_window;
33
38
 
41
46
        [Glade.Widget] ScrolledWindow icon_view_scrolled;
42
47
        [Glade.Widget] Box photo_box;
43
48
        [Glade.Widget] Notebook view_notebook;
44
 
        [Glade.Widget] ScrolledWindow tag_selection_scrolled;
 
49
        
 
50
        ScrolledWindow tag_selection_scrolled;
45
51
 
46
52
        [Glade.Widget] Label status_label;
47
53
 
53
59
        
54
60
        [Glade.Widget] MenuItem tools;
55
61
        [Glade.Widget] MenuItem export;
 
62
        [Glade.Widget] MenuItem pagesetup_menu_item;
56
63
        [Glade.Widget] MenuItem print;
57
64
        [Glade.Widget] MenuItem send_mail;
58
65
 
62
69
        [Glade.Widget] MenuItem rotate_left;
63
70
        [Glade.Widget] MenuItem rotate_right;
64
71
 
65
 
        [Glade.Widget] MenuItem adjust_color;
66
72
        [Glade.Widget] MenuItem sharpen;
67
73
        [Glade.Widget] MenuItem adjust_time;
68
74
 
75
81
        [Glade.Widget] MenuItem remove_tag;
76
82
 
77
83
        // View
78
 
        [Glade.Widget] MenuItem exif_data;
79
 
        
80
84
        [Glade.Widget] CheckMenuItem display_toolbar;
81
85
        [Glade.Widget] CheckMenuItem display_sidebar;
82
86
        [Glade.Widget] CheckMenuItem display_timeline;
87
91
 
88
92
        [Glade.Widget] MenuItem zoom_in;
89
93
        [Glade.Widget] MenuItem zoom_out;
 
94
        [Glade.Widget] CheckMenuItem loupe_menu_item;
90
95
 
91
96
        [Glade.Widget] RadioMenuItem tag_icon_hidden;
92
97
        [Glade.Widget] RadioMenuItem tag_icon_small;
107
112
 
108
113
        [Glade.Widget] CheckMenuItem find_untagged;
109
114
        
110
 
        [Glade.Widget] MenuItem last_roll;
111
 
        [Glade.Widget] MenuItem select_rolls;
112
115
        [Glade.Widget] MenuItem clear_roll_filter;      
113
116
        
114
117
        // Tags
125
128
 
126
129
        [Glade.Widget] Gtk.HBox tagbar;
127
130
        [Glade.Widget] Gtk.VBox tag_entry_container;
 
131
        [Glade.Widget] Gtk.VBox sidebar_vbox;
128
132
        TagEntry tag_entry;
129
133
 
130
134
        Gtk.Toolbar toolbar;
137
141
        Gtk.ToggleToolButton edit_button;
138
142
 
139
143
        InfoBox info_box;
140
 
        FSpot.InfoDisplay info_display;
141
144
        QueryView icon_view;
142
145
        PhotoView photo_view;
143
146
        FSpot.FullScreenView fsview;
148
151
        
149
152
        ToolButton rl_button;
150
153
        ToolButton rr_button;
 
154
 
 
155
        Label count_label;
 
156
 
 
157
        Gtk.ToolButton display_next_button;
 
158
        Gtk.ToolButton display_previous_button;
151
159
        
152
160
        ModeType view_mode;
153
161
        bool write_metadata = false;
158
166
                set { Tag.TagIconSize = (Tag.IconSize) value; }
159
167
        }
160
168
 
 
169
        public PhotoView PhotoView {
 
170
                get { return photo_view; }
 
171
        }
 
172
 
161
173
        // Drag and Drop
162
174
        public enum TargetType {
163
175
                UriList,
227
239
        get { return find_by_tag; }
228
240
    }
229
241
 
 
242
        public InfoBox InfoBox {
 
243
                get { return info_box; }
 
244
        }
 
245
 
230
246
        //
231
247
        // Constructor
232
248
        //
237
253
                if (Toplevel == null)
238
254
                        Toplevel = this;
239
255
 
240
 
                Glade.XML gui = new Glade.XML (null, "f-spot.glade", "main_window", null);
 
256
                Glade.XML gui = new Glade.XML (null, "f-spot.glade", "main_window", "f-spot");
241
257
                gui.Autoconnect (this);
242
258
 
243
259
                LoadPreference (Preferences.MAIN_WINDOW_WIDTH);
247
263
 
248
264
                LoadPreference (Preferences.SIDEBAR_POSITION);
249
265
                LoadPreference (Preferences.METADATA_EMBED_IN_IMAGE);
250
 
                
 
266
 
 
267
                LoadPreference (Preferences.COLOR_MANAGEMENT_ENABLED);
 
268
                LoadPreference (Preferences.COLOR_MANAGEMENT_USE_X_PROFILE);
 
269
                FSpot.ColorManagement.LoadSettings();
 
270
        
 
271
#if GTK_2_10
 
272
                pagesetup_menu_item.Activated += HandlePageSetupActivated;
 
273
#else
 
274
                pagesetup_menu_item.Visible = false;
 
275
#endif
251
276
                toolbar = new Gtk.Toolbar ();
252
277
                toolbar_vbox.PackStart (toolbar);
253
278
 
295
320
                ss_button.Clicked += HandleViewSlideShow;
296
321
                ss_button.SetTooltip (ToolTips, Catalog.GetString ("View photos in a slideshow"), null);
297
322
                toolbar.Insert (ss_button, -1);
 
323
 
 
324
                SeparatorToolItem white_space = new SeparatorToolItem ();
 
325
                white_space.Draw = false;
 
326
                white_space.Expand = true;
 
327
                toolbar.Insert (white_space, -1);
 
328
 
 
329
                ToolItem label_item = new ToolItem ();
 
330
                count_label = new Label (String.Empty);
 
331
                label_item.Child = count_label;
 
332
                toolbar.Insert (label_item, -1);
 
333
 
 
334
                display_previous_button = new ToolButton (Stock.GoBack);
 
335
                toolbar.Insert (display_previous_button, -1);
 
336
                display_previous_button.SetTooltip (ToolTips, Catalog.GetString ("Previous photo"), String.Empty);
 
337
                display_previous_button.Clicked += new EventHandler (HandleDisplayPreviousButtonClicked);
 
338
 
 
339
                display_next_button = new ToolButton (Stock.GoForward);
 
340
                toolbar.Insert (display_next_button, -1);
 
341
                display_next_button.SetTooltip (ToolTips, Catalog.GetString ("Next photo"), String.Empty);
 
342
                display_next_button.Clicked += new EventHandler (HandleDisplayNextButtonClicked);
 
343
 
 
344
                sidebar = new Sidebar ();
 
345
                ViewModeChanged += sidebar.HandleMainWindowViewModeChanged;
 
346
                sidebar_vbox.Add (sidebar);
 
347
 
 
348
                tag_selection_scrolled = new ScrolledWindow ();
 
349
                tag_selection_scrolled.ShadowType = ShadowType.In;
298
350
                
299
351
                tag_selection_widget = new TagSelectionWidget (db.Tags);
300
352
                tag_selection_scrolled.Add (tag_selection_widget);
 
353
 
 
354
                sidebar.AppendPage (tag_selection_scrolled, Catalog.GetString ("Tags"), "tag");
 
355
 
 
356
                AddinManager.AddExtensionNodeHandler ("/FSpot/Sidebar", OnSidebarExtensionChanged);
 
357
 
 
358
                sidebar.Context = ViewContext.Library;
 
359
                
 
360
                sidebar.CloseRequested += HideSidebar;
 
361
                sidebar.Show ();
 
362
 
 
363
                info_box = new InfoBox ();
 
364
                ViewModeChanged += info_box.HandleMainWindowViewModeChanged;
 
365
                info_box.VersionIdChanged += delegate (InfoBox box, uint version_id) { UpdateForVersionIdChange (version_id);};
 
366
                sidebar_vbox.PackEnd (info_box, false, false, 0);
 
367
 
 
368
                info_box.Context = ViewContext.Library;
301
369
                
302
370
                tag_selection_widget.Selection.Changed += HandleTagSelectionChanged;
303
371
                tag_selection_widget.DragDataGet += HandleTagSelectionDragDataGet;
317
385
                tag_selection_widget.RowActivated += HandleTagSelectionRowActivated;
318
386
                
319
387
                LoadPreference (Preferences.TAG_ICON_SIZE);
320
 
 
321
 
                info_box = new InfoBox ();
322
 
                info_box.VersionIdChanged += HandleInfoBoxVersionIdChange;
323
 
                left_vbox.PackStart (info_box, false, true, 0);
324
388
                
325
389
                try {
326
390
                        query = new FSpot.PhotoQuery (db.Photos);
344
408
#endif
345
409
 
346
410
                group_selector = new FSpot.GroupSelector ();
347
 
                group_selector.Adaptor = new FSpot.TimeAdaptor (query, (bool)Preferences.Get (Preferences.GROUP_ADAPTOR_ORDER_ASC));
 
411
                group_selector.Adaptor = new FSpot.TimeAdaptor (query, Preferences.Get<bool> (Preferences.GROUP_ADAPTOR_ORDER_ASC));
348
412
 
349
413
                group_selector.ShowAll ();
350
414
                
406
470
                photo_view = new PhotoView (query);
407
471
                photo_box.Add (photo_view);
408
472
 
409
 
                photo_view.ButtonPressEvent += HandlePhotoViewButtonPressEvent;
 
473
                photo_view.DoubleClicked += HandleDoubleClicked;
410
474
                photo_view.KeyPressEvent += HandlePhotoViewKeyPressEvent;
411
475
                photo_view.UpdateStarted += HandlePhotoViewUpdateStarted;
412
476
                photo_view.UpdateFinished += HandlePhotoViewUpdateFinished;
439
503
                this.selection = new MainSelection (this);
440
504
                this.selection.Changed += HandleSelectionChanged;
441
505
                this.selection.ItemsChanged += HandleSelectionItemsChanged;
 
506
                this.selection.Changed += sidebar.HandleSelectionChanged;
 
507
                this.selection.ItemsChanged += sidebar.HandleSelectionItemsChanged;
442
508
 
443
509
                Mono.Addins.AddinManager.ExtensionChanged += PopulateExtendableMenus;
444
510
                PopulateExtendableMenus (null, null);
475
541
                Banshee.Kernel.Scheduler.Resume ();
476
542
        }
477
543
 
 
544
        private void HandleDisplayNextButtonClicked (object sender, EventArgs args)
 
545
        {
 
546
                PhotoView.View.Item.MoveNext ();
 
547
        }
 
548
 
 
549
        private void HandleDisplayPreviousButtonClicked (object sender, EventArgs args)
 
550
        {
 
551
                PhotoView.View.Item.MovePrevious ();
 
552
        }
 
553
 
 
554
        private void OnSidebarExtensionChanged (object s, ExtensionNodeEventArgs args) {
 
555
                // FIXME: No sidebar page removal yet!
 
556
                if (args.Change == ExtensionChange.Add)
 
557
                        sidebar.AppendPage ((args.ExtensionNode as SidebarPageNode).GetSidebarPage ());
 
558
        }
 
559
 
478
560
        private Photo CurrentPhoto {
479
561
                get {
480
562
                        int active = ActiveIndex ();
481
563
                        if (active >= 0)
482
 
                                return query.Photos [active];
 
564
                                return query [active] as Photo;
483
565
                        else
484
566
                                return null;
485
567
                }
500
582
                PhotoView
501
583
        };
502
584
 
 
585
        public event EventHandler ViewModeChanged;
 
586
 
503
587
        public void SetViewMode (ModeType value)
504
588
        {
505
589
                if (view_mode == value)
515
599
                        display_filmstrip.Sensitive = false;
516
600
                        group_selector.Visible = display_timeline.Active;
517
601
 
518
 
                        ColorDialog.Close ();
519
602
                        if (photo_view.View.Loupe != null)
520
 
                                photo_view.View.Loupe.Destroy ();
 
603
                                loupe_menu_item.Active = false;
521
604
                        JumpTo (photo_view.Item.Index);
522
605
                        zoom_scale.Value = icon_view.Zoom;
523
606
                        break;
535
618
                }
536
619
                Selection.MarkChanged ();
537
620
                UpdateToolbar ();
 
621
                if (ViewModeChanged != null) 
 
622
                        ViewModeChanged (this, null);
538
623
        }
539
624
        
540
625
        void UpdateToolbar ()
552
637
                        if (edit_button.Active != state)
553
638
                                edit_button.Active = state;
554
639
                }
 
640
 
 
641
                if (view_mode == ModeType.PhotoView) {
 
642
                        display_previous_button.Visible = true;
 
643
                        display_next_button.Visible = true;
 
644
                        count_label.Visible = true;
 
645
 
 
646
                        bool valid = photo_view.View.Item.IsValid;
 
647
                        bool prev = valid && photo_view.View.Item.Index > 0;
 
648
                        bool next = valid && photo_view.View.Item.Index < query.Count - 1;
 
649
 
 
650
                        if (valid) {
 
651
                                Gnome.Vfs.Uri vfs = new Gnome.Vfs.Uri (photo_view.View.Item.Current.DefaultVersionUri.ToString ());
 
652
                                valid = vfs.Scheme == "file";
 
653
                        }
 
654
 
 
655
                        display_previous_button.Sensitive = prev;
 
656
                        display_next_button.Sensitive = next;
 
657
 
 
658
                        if (Query == null)
 
659
                                count_label.Text = String.Empty;
 
660
                        else
 
661
                                // Note for translators: This indicates the current photo is photo {0} of {1} out of photos
 
662
                                count_label.Text = String.Format (Catalog.GetString ("{0} of {1}"), Query.Count == 0 ? 0 : photo_view.View.Item.Index + 1, Query.Count == 0 ? 0 : Query.Count);
 
663
                } else {
 
664
                        display_previous_button.Visible = false;
 
665
                        display_next_button.Visible = false;
 
666
                        count_label.Visible = false;
 
667
                }
 
668
 
555
669
        }
556
670
 
557
671
        private void HandleExportActivated (object o, EventArgs e)
565
679
                        Photo p = item as Photo;
566
680
                        if (p == null)
567
681
                                continue;
568
 
#if ENABLE_BEAGLE
569
 
                        BeagleNotifier.SendUpdate (p);
570
 
#endif
571
682
                        if (write_metadata)
572
683
                                FSpot.Jobs.SyncMetadataJob.Create (db.Jobs, p);
573
684
                }
574
685
                
575
 
                if (args is TimeChangedEventArgs)
 
686
                if (args is PhotoEventArgs && (args as PhotoEventArgs).Changes.TimeChanged)
576
687
                        query.RequestReload ();
577
688
        }
578
689
 
579
690
        private void HandleTagsChanged (object sender, DbItemEventArgs args)
580
691
        {
581
692
                icon_view.QueueDraw ();
582
 
                UpdateTagEntryFromSelection ();
583
 
                
 
693
                UpdateTagEntryFromSelection (); 
584
694
        }
585
695
 
586
696
        void HandleViewNotebookSwitchPage (object sender, SwitchPageArgs args)
668
778
                                Changed (this);
669
779
                }
670
780
 
671
 
                public void MarkChanged (int index)
 
781
                public void MarkChanged (int index, IBrowsableItemChanges changes)
672
782
                {
673
783
                        throw new System.NotImplementedException ("I didn't think you'd find me");
674
784
                }
712
822
 
713
823
                        foreach (int item in args.Items) {
714
824
                                if (win.photo_view.Item.Index == item ) {
715
 
                                        ItemsChanged (this, new BrowsableEventArgs (0));
 
825
                                        ItemsChanged (this, new BrowsableEventArgs (item, args.Changes));
716
826
                                        break;
717
827
                                }
718
828
                        }
744
854
 
745
855
        private void HandleSelectionChanged (IBrowsableCollection collection)
746
856
        {
747
 
                info_box.Photo = CurrentPhoto;
748
 
                if (info_display != null)
749
 
                        info_display.Photo = CurrentPhoto;
750
 
 
751
857
                UpdateMenus ();
752
858
                UpdateTagEntryFromSelection ();
753
 
                UpdateStatusLabel();    
 
859
                UpdateStatusLabel ();
 
860
                UpdateToolbar ();
 
861
 
 
862
                info_box.Photos = SelectedPhotos ();
754
863
        }
755
864
 
756
865
        private void HandleSelectionItemsChanged (IBrowsableCollection collection, BrowsableEventArgs args)
757
866
        {
758
867
                UpdateMenus ();
759
868
                UpdateTagEntryFromSelection ();
760
 
                info_box.Update ();
 
869
 
 
870
                info_box.Photos = SelectedPhotos ();
761
871
        }
762
872
 
763
873
 
771
881
        
772
882
                int i = 0;
773
883
                foreach (int num in selected_ids)
774
 
                        photo_list [i ++] = query.Photos [num];
 
884
                        photo_list [i ++] = query [num] as Photo;
775
885
                
776
886
                return photo_list;
777
887
        }
781
891
                return SelectedPhotos (SelectedIds ());
782
892
        }
783
893
 
 
894
        [Obsolete ("MARKED FOR REMOVAL")]
784
895
        public Photo [] ActivePhotos () 
785
896
        {
786
897
                return query.Photos;
811
922
                RotateCommand command = new RotateCommand (parent);
812
923
                
813
924
                int [] selected_ids = SelectedIds ();
814
 
                if (command.Execute (direction, SelectedPhotos (selected_ids))) {
815
 
                        foreach (int num in selected_ids)
816
 
                                query.MarkChanged (num);
 
925
                if (command.Execute (direction, SelectedPhotos (selected_ids)))
 
926
#if MONO_1_9_0
 
927
                        query.MarkChanged (selected_ids, new PhotoChanges () {DataChanged = true});
 
928
#else
 
929
                {
 
930
                        PhotoChanges changes = new PhotoChanges ();
 
931
                        changes.DataChanged = true;
 
932
                        query.MarkChanged (selected_ids, changes);
817
933
                }
 
934
#endif
818
935
        }
819
936
 
820
937
        //
821
938
        // Tag Selection Drag Handlers
822
939
        //
823
 
 
 
940
        [Obsolete ("Use AddTagExtended (int [], Tag []) instead")]
824
941
        public void AddTagExtended (int num, Tag [] tags)
825
942
        {
826
 
                Photo p = query.Photos [num];
 
943
                AddTagExtended (new int [] {num}, tags);
 
944
        }
827
945
 
828
 
                p.AddTag (tags);
829
 
                query.Commit (num);
 
946
        public void AddTagExtended (int [] nums, Tag [] tags)
 
947
        {
 
948
                foreach (int num in nums)
 
949
                        (query[num] as Photo).AddTag (tags);
 
950
                query.Commit (nums);
830
951
 
831
952
                foreach (Tag t in tags) {
832
953
                        if (t.Icon != null)
833
954
                                continue;
834
 
 
835
955
                        // FIXME this needs a lot more work.
836
956
                        Pixbuf icon = null;
837
957
                        try {
838
 
                                Pixbuf tmp = FSpot.PhotoLoader.LoadAtMaxSize (query.Items [num], 128, 128);
 
958
                                Pixbuf tmp = FSpot.PhotoLoader.LoadAtMaxSize (query [nums[0]], 128, 128);
839
959
                                icon = PixbufUtils.TagIconFromPixbuf (tmp);
840
960
                                tmp.Dispose ();
841
961
                        } catch {
847
967
                }
848
968
        }
849
969
 
 
970
        public void RemoveTags (int [] nums, Tag [] tags)
 
971
        {
 
972
                foreach (int num in nums)
 
973
                        (query[num] as Photo).RemoveTag (tags);
 
974
                query.Commit (nums);
 
975
        }
 
976
 
850
977
        void HandleTagSelectionRowActivated (object sender, RowActivatedArgs args)
851
978
        {
852
979
                ShowQueryWidget ();
963
1090
                switch (args.Info) {
964
1091
                case (uint)TargetType.PhotoList:
965
1092
                        db.BeginTransaction ();
966
 
                        foreach (int num in SelectedIds ()) {
967
 
                                AddTagExtended (num, new Tag[] {tag});
968
 
                        }
 
1093
                        AddTagExtended (SelectedIds (), new Tag[] {tag});
969
1094
                        db.CommitTransaction ();
970
1095
                        query_widget.PhotoTagsChanged (new Tag[] {tag});
971
1096
                        break;
973
1098
                        UriList list = new UriList (args.SelectionData);
974
1099
                        
975
1100
                        db.BeginTransaction ();
976
 
                        foreach (string photo_path in list.ToLocalPaths ()) {
977
 
                                Photo photo = db.Photos.GetByPath (photo_path);
 
1101
                        List<Photo> photos = new List<Photo> ();
 
1102
                        foreach (Uri photo_uri in list) {
 
1103
                                Photo photo = db.Photos.GetByUri (photo_uri);
978
1104
                                
979
1105
                                // FIXME - at this point we should import the photo, and then continue
980
1106
                                if (photo == null)
982
1108
                                
983
1109
                                // FIXME this should really follow the AddTagsExtended path too
984
1110
                                photo.AddTag (new Tag[] {tag});
985
 
                                db.Photos.Commit (photo);
 
1111
                                photos.Add (photo);
986
1112
                        }
 
1113
                        db.Photos.Commit (photos.ToArray ());
987
1114
                        db.CommitTransaction ();
988
1115
                        InvalidateViews ();
989
1116
                        break;
1039
1166
                
1040
1167
                FSpot.TimeAdaptor time_adaptor = group_selector.Adaptor as FSpot.TimeAdaptor;
1041
1168
                if (time_adaptor != null)
1042
 
                        JumpTo (time_adaptor.LookupItem (time));
 
1169
                        JumpTo (query.LookupItem (time));
1043
1170
        }
1044
1171
 
1045
1172
        private void JumpTo (int index)
1078
1205
                if (cell_num == -1 /*|| cell_num == lastTopLeftCell*/)
1079
1206
                        return;
1080
1207
 
1081
 
                FSpot.IBrowsableItem photo = icon_view.Collection.Items [cell_num];
 
1208
                FSpot.IBrowsableItem photo = icon_view.Collection [cell_num];
1082
1209
#if false
1083
1210
                group_selector.Adaptor.GlassSet -= HandleAdaptorGlassSet;
1084
1211
                group_selector.Adaptor.SetGlass (group_selector.Adaptor.IndexFromPhoto (photo));
1130
1257
                                FSpot.PixbufCache.CacheEntry entry = icon_view.Cache.Lookup (thumbnail_path);
1131
1258
 
1132
1259
                                Pixbuf thumbnail = null;
1133
 
                                if (entry != null)
1134
 
                                        thumbnail = entry.ShallowCopyPixbuf ();
 
1260
                                if (entry != null) {
 
1261
                                        if (FSpot.ColorManagement.IsEnabled) {
 
1262
                                                //FIXME
 
1263
                                                thumbnail = entry.ShallowCopyPixbuf ();
 
1264
                                                thumbnail = thumbnail.Copy ();
 
1265
                                                FSpot.ColorManagement.ApplyScreenProfile (thumbnail);
 
1266
                                        }
 
1267
                                        else
 
1268
                                                thumbnail = entry.ShallowCopyPixbuf ();
 
1269
                                }
1135
1270
                                
1136
1271
                                if (thumbnail != null) {
1137
1272
                                        Pixbuf small = PixbufUtils.ScaleToMaxSize (thumbnail, size, size);                              
1189
1324
                args.RetVal = true;
1190
1325
        }
1191
1326
 
1192
 
        void HandleIconViewKeyPressEvent (object sender, Gtk.KeyPressEventArgs args)
1193
 
        {
1194
 
                bool alt = ModifierType.Mod1Mask == (args.Event.State & ModifierType.Mod1Mask);
1195
 
 
1196
 
                switch (args.Event.Key) {
1197
 
                case Gdk.Key.Delete:
1198
 
                        HandleRemoveCommand (sender, (EventArgs) args);
1199
 
                        args.RetVal = true;
1200
 
                        break;
1201
 
                case Gdk.Key.Key_0:
1202
 
                        if (alt) {
1203
 
                                HandleRatingMenuSelected (0);
1204
 
                                args.RetVal = true;
1205
 
                        }
1206
 
                        break;
1207
 
                case Gdk.Key.Key_1:
1208
 
                        if (alt) {
1209
 
                                HandleRatingMenuSelected (1);
1210
 
                                args.RetVal = true;
1211
 
                        }
1212
 
                        break;
1213
 
                case Gdk.Key.Key_2:
1214
 
                        if (alt) {
1215
 
                                HandleRatingMenuSelected (2);
1216
 
                                args.RetVal = true;
1217
 
                        }
1218
 
                        break;
1219
 
                case Gdk.Key.Key_3:
1220
 
                        if (alt) {
1221
 
                                HandleRatingMenuSelected (3);
1222
 
                                args.RetVal = true;
1223
 
                        }
1224
 
                        break;
1225
 
                case Gdk.Key.Key_4:
1226
 
                        if (alt) {
1227
 
                                HandleRatingMenuSelected (4);
1228
 
                                args.RetVal = true;
1229
 
                        }
1230
 
                        break;
1231
 
                case Gdk.Key.Key_5:
1232
 
                        if (alt) {
1233
 
                                HandleRatingMenuSelected (5);
1234
 
                                args.RetVal = true;
1235
 
                        }
1236
 
                        break;
1237
 
                }
1238
 
        }
1239
 
 
1240
1327
        public void ImportUriList (UriList list, bool copy) 
1241
1328
        {
1242
1329
                ImportCommand command = new ImportCommand (main_window);
1332
1419
        // IconView event handlers
1333
1420
        // 
1334
1421
 
1335
 
        void HandleDoubleClicked (FSpot.Widgets.IconView icon_view, int clicked_item)
1336
 
        {
1337
 
                icon_view.FocusCell = clicked_item;
1338
 
                SetViewMode (ModeType.PhotoView);
 
1422
        void HandleDoubleClicked (Widget widget, BrowsableEventArgs args)
 
1423
        {
 
1424
                switch (ViewMode) {
 
1425
                case ModeType.IconView:
 
1426
                        icon_view.FocusCell = args.Items[0];
 
1427
                        SetViewMode (ModeType.PhotoView);
 
1428
                        break;
 
1429
                case ModeType.PhotoView:
 
1430
                        SetViewMode (ModeType.IconView);
 
1431
                        break;
 
1432
                }
 
1433
        }
 
1434
 
 
1435
        public void HandleCommonPhotoCommands (object sender, Gtk.KeyPressEventArgs args) {
 
1436
                bool alt = ModifierType.Mod1Mask == (args.Event.State & ModifierType.Mod1Mask);
 
1437
                bool shift = ModifierType.ShiftMask == (args.Event.State & ModifierType.ShiftMask);
 
1438
 
 
1439
                if (args.RetVal == null)
 
1440
                        args.RetVal = false;
 
1441
                
 
1442
                switch (args.Event.Key) {
 
1443
                case Gdk.Key.Delete:
 
1444
                        if (shift)
 
1445
                                HandleDeleteCommand (sender, args);
 
1446
                        else
 
1447
                                HandleRemoveCommand (sender, args);
 
1448
                        break;
 
1449
                case Gdk.Key.Key_0:
 
1450
                        if (alt)
 
1451
                                HandleRatingMenuSelected (0);
 
1452
                        break;
 
1453
                case Gdk.Key.Key_1:
 
1454
                        if (alt)
 
1455
                                HandleRatingMenuSelected (1);
 
1456
                        break;
 
1457
                case Gdk.Key.Key_2:
 
1458
                        if (alt)
 
1459
                                HandleRatingMenuSelected (2);
 
1460
                        break;
 
1461
                case Gdk.Key.Key_3:
 
1462
                        if (alt)
 
1463
                                HandleRatingMenuSelected (3);
 
1464
                        break;
 
1465
                case Gdk.Key.Key_4:
 
1466
                        if (alt)
 
1467
                                HandleRatingMenuSelected (4);
 
1468
                        break;
 
1469
                case Gdk.Key.Key_5:
 
1470
                        if (alt)
 
1471
                                HandleRatingMenuSelected (5);
 
1472
                        break;
 
1473
                default:
 
1474
                        return; //do not set the RetVal to true
 
1475
                }
 
1476
                args.RetVal = true;
 
1477
        }
 
1478
 
 
1479
        void HandleIconViewKeyPressEvent (object sender, Gtk.KeyPressEventArgs args)
 
1480
        {
 
1481
                HandleCommonPhotoCommands (sender, args);
 
1482
                if ((bool)args.RetVal)
 
1483
                        return;
 
1484
 
 
1485
                switch (args.Event.Key) {
 
1486
                case Gdk.Key.F:
 
1487
                case Gdk.Key.f:
 
1488
                        HandleViewFullscreen (sender, args);
 
1489
                        args.RetVal = true;
 
1490
                        break;
 
1491
                }
 
1492
        }
 
1493
 
 
1494
        //
 
1495
        // FullScreenView event handlers.
 
1496
        //
 
1497
 
 
1498
        void HandleFullScreenViewKeyPressEvent (object sender, Gtk.KeyPressEventArgs args)
 
1499
        {
 
1500
                HandleCommonPhotoCommands (sender, args);
 
1501
                if ((bool)args.RetVal)
 
1502
                        // this will hide any panels again that might have appeared above the fullscreen view
 
1503
                        fsview.Present ();
1339
1504
        }
1340
1505
 
1341
1506
        //
1342
1507
        // PhotoView event handlers.
1343
1508
        //
1344
 
        
 
1509
 
1345
1510
        void HandlePhotoViewKeyPressEvent (object sender, Gtk.KeyPressEventArgs args)
1346
1511
        {
1347
 
                bool alt = ModifierType.Mod1Mask == (args.Event.State & ModifierType.Mod1Mask);
 
1512
                HandleCommonPhotoCommands (sender, args);
 
1513
                if ((bool)args.RetVal)
 
1514
                        return;
 
1515
 
1348
1516
                switch (args.Event.Key) {
1349
1517
                case Gdk.Key.F:
1350
1518
                case Gdk.Key.f:
1355
1523
                        SetViewMode (ModeType.IconView);
1356
1524
                        args.RetVal = true;
1357
1525
                        break;
1358
 
                case Gdk.Key.Delete:
1359
 
                        HandleRemoveCommand (sender, (EventArgs) args);
1360
 
                        args.RetVal = true;
1361
 
                        break;
1362
 
                case Gdk.Key.Key_0:
1363
 
                        if (alt) {
1364
 
                                HandleRatingMenuSelected (0);
1365
 
                                args.RetVal = true;
1366
 
                        }
1367
 
                        break;
1368
 
                case Gdk.Key.Key_1:
1369
 
                        if (alt) {
1370
 
                                HandleRatingMenuSelected (1);
1371
 
                                args.RetVal = true;
1372
 
                        }
1373
 
                        break;
1374
 
                case Gdk.Key.Key_2:
1375
 
                        if (alt) {
1376
 
                                HandleRatingMenuSelected (2);
1377
 
                                args.RetVal = true;
1378
 
                        }
1379
 
                        break;
1380
 
                case Gdk.Key.Key_3:
1381
 
                        if (alt) {
1382
 
                                HandleRatingMenuSelected (3);
1383
 
                                args.RetVal = true;
1384
 
                        }
1385
 
                        break;
1386
 
                case Gdk.Key.Key_4:
1387
 
                        if (alt) {
1388
 
                                HandleRatingMenuSelected (4);
1389
 
                                args.RetVal = true;
1390
 
                        }
1391
 
                        break;
1392
 
                case Gdk.Key.Key_5:
1393
 
                        if (alt) {
1394
 
                                HandleRatingMenuSelected (5);
1395
 
                                args.RetVal = true;
1396
 
                        }
1397
 
                        break;
1398
 
                default:
1399
 
                        break;
1400
1526
                }
1401
 
                return;
1402
 
        }
1403
 
 
1404
 
        void HandlePhotoViewButtonPressEvent (object sender, Gtk.ButtonPressEventArgs args)
1405
 
        {
1406
 
                if (args.Event.Type == EventType.TwoButtonPress && args.Event.Button == 1)
1407
 
                        SetViewMode (ModeType.IconView);
1408
1527
        }
1409
1528
 
1410
1529
        void HandlePhotoViewUpdateStarted (PhotoView sender)
1461
1580
                if (view_mode == ModeType.PhotoView)
1462
1581
                        this.photo_view.UpdateRating(r);
1463
1582
 
1464
 
                uint timer = Log.DebugTimerStart ();
1465
1583
                Photo p;
1466
1584
                db.BeginTransaction ();
1467
 
                foreach (int num in SelectedIds ()) {
1468
 
                        p = query.Photos [num];
 
1585
                int [] selected_photos = SelectedIds ();
 
1586
                foreach (int num in selected_photos) {
 
1587
                        p = query [num] as Photo;
1469
1588
                        p.Rating = (uint) r;
1470
 
                        query.Commit (num);
1471
1589
                }
 
1590
                query.Commit (selected_photos);
1472
1591
                db.CommitTransaction ();
1473
 
                Log.DebugTimerPrint (timer, "HandleRating took {0}");
1474
1592
        }
1475
1593
 
1476
1594
        //
1490
1608
        public void HandleAttachTagMenuSelected (Tag t) 
1491
1609
        {
1492
1610
                db.BeginTransaction ();
1493
 
                foreach (int num in SelectedIds ()) {
1494
 
                        AddTagExtended (num, new Tag [] {t});
1495
 
                }
 
1611
                AddTagExtended (SelectedIds (), new Tag [] {t});
1496
1612
                db.CommitTransaction ();
1497
1613
                query_widget.PhotoTagsChanged (new Tag[] {t});
1498
1614
        }
1511
1627
        public void HandleRemoveTagMenuSelected (Tag t)
1512
1628
        {
1513
1629
                db.BeginTransaction ();
1514
 
                foreach (int num in SelectedIds ()) {
1515
 
                        query.Photos [num].RemoveTag (t);
1516
 
                        query.Commit (num);
1517
 
                }
 
1630
                RemoveTags (SelectedIds (), new Tag [] {t});
1518
1631
                db.CommitTransaction ();
1519
1632
                query_widget.PhotoTagsChanged (new Tag [] {t});
1520
1633
        }
1606
1719
                        cam.ReleaseGPhotoResources ();
1607
1720
                }
1608
1721
        }
 
1722
#if GTK_2_10
 
1723
        void HandlePageSetupActivated (object o, EventArgs e)
 
1724
        {
 
1725
                FSpot.Global.PageSetup = Print.RunPageSetupDialog (this.Window, FSpot.Global.PageSetup, null);
 
1726
        }
 
1727
#endif
1609
1728
        
1610
1729
        void HandlePrintCommand (object sender, EventArgs e)
1611
1730
        {
1621
1740
        public void HandleInfoDisplayDestroy (object sender, EventArgs args)
1622
1741
        {
1623
1742
                info_display_window = null;
1624
 
                info_display = null;
1625
1743
        }
1626
1744
 
1627
1745
        public void HandlePreferences (object sender, EventArgs args)
1634
1752
                Mono.Addins.Gui.AddinManagerWindow.Run (main_window);
1635
1753
        }
1636
1754
        
1637
 
        void HandleViewFullExif (object sender, EventArgs args)
1638
 
        {
1639
 
                if (info_display_window != null) {
1640
 
                        info_display_window.Present ();
1641
 
                        return;
1642
 
                }
1643
 
 
1644
 
                info_display = new FSpot.InfoDisplay ();
1645
 
                info_display_window = new Gtk.Dialog (Catalog.GetString ("Metadata Browser"), 
1646
 
                                                      main_window, 
1647
 
                                                      Gtk.DialogFlags.NoSeparator | Gtk.DialogFlags.DestroyWithParent);
1648
 
                info_display_window.SetDefaultSize (400, 400);
1649
 
                Gtk.ScrolledWindow scroll = new ScrolledWindow ();
1650
 
                info_display_window.VBox.PackStart (scroll);
1651
 
                scroll.Add (info_display);
1652
 
 
1653
 
                info_display.Photo = CurrentPhoto;
1654
 
               
1655
 
                info_display_window.ShowAll ();
1656
 
                info_display_window.Destroyed += HandleInfoDisplayDestroy;
1657
 
        }
1658
 
 
1659
1755
        void HandleViewDirectory (object sender, EventArgs args)
1660
1756
        {
1661
1757
                Gtk.Window win = new Gtk.Window ("Directory View");
1780
1876
                        return;
1781
1877
                
1782
1878
                group_selector.Adaptor.OrderAscending = item.Active;
1783
 
                query.RequestReload ();
 
1879
                query.TimeOrderAsc = item.Active;
1784
1880
 
1785
1881
                // FIXME this is blah...we need UIManager love here
1786
1882
                if (item != reverse_order)
1846
1942
        {
1847
1943
                PhotoVersionCommands.Create cmd = new PhotoVersionCommands.Create ();
1848
1944
 
1849
 
                if (cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null))) {
1850
 
                        query.MarkChanged (ActiveIndex ());
1851
 
                }
 
1945
                cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null));
 
1946
//              if (cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null))) {
 
1947
//                      query.MarkChanged (ActiveIndex (), true, false);
 
1948
//              }
1852
1949
        }
1853
1950
 
1854
1951
        void HandleDeleteVersionCommand (object obj, EventArgs args)
1855
1952
        {
1856
1953
                PhotoVersionCommands.Delete cmd = new PhotoVersionCommands.Delete ();
1857
1954
 
1858
 
                if (cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null))) {
1859
 
                        query.MarkChanged (ActiveIndex ());
1860
 
                }
 
1955
                cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null));
 
1956
//              if (cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null))) {
 
1957
//                      query.MarkChanged (ActiveIndex (), true, true);
 
1958
//              }
1861
1959
        }
1862
1960
 
1863
1961
        void HandlePropertiesCommand (object obje, EventArgs args)
1879
1977
        {
1880
1978
                PhotoVersionCommands.Rename cmd = new PhotoVersionCommands.Rename ();
1881
1979
 
1882
 
                if (cmd.Execute (db.Photos, CurrentPhoto, main_window)) {
1883
 
                        query.MarkChanged (ActiveIndex ());
1884
 
                }
 
1980
                cmd.Execute (db.Photos, CurrentPhoto, main_window);
 
1981
//              if (cmd.Execute (db.Photos, CurrentPhoto, main_window)) {
 
1982
//                      query.MarkChanged (ActiveIndex (), true, false);
 
1983
//              }
1885
1984
        }
1886
1985
        
1887
1986
        public void HandleCreateTagAndAttach (object sender, EventArgs args)
1916
2015
        void AttachTags (Tag [] tags, int [] ids) 
1917
2016
        {
1918
2017
                db.BeginTransaction ();
1919
 
                foreach (int num in ids) {
1920
 
                        AddTagExtended (num, tags);
1921
 
                }
 
2018
                AddTagExtended (ids, tags);
1922
2019
                db.CommitTransaction ();
1923
2020
                query_widget.PhotoTagsChanged (tags);
1924
2021
        }
1928
2025
                Tag [] tags = this.tag_selection_widget.TagHighlight;
1929
2026
 
1930
2027
                db.BeginTransaction ();
1931
 
                foreach (int num in SelectedIds ()) {
1932
 
                        Photo p = query.Photos [num];
1933
 
 
1934
 
                        p.RemoveTag (tags);
1935
 
 
1936
 
                        query.Commit (num);
1937
 
                }
 
2028
                RemoveTags (SelectedIds (), tags);
1938
2029
                db.CommitTransaction ();
1939
2030
                query_widget.PhotoTagsChanged (tags);
1940
2031
        }
2032
2123
                new TimeDialog (db, list);
2033
2124
        }
2034
2125
 
2035
 
        void HandleAdjustColor (object sender, EventArgs args)
2036
 
        {
2037
 
                if (ActiveIndex () >= 0) {
2038
 
                        SetViewMode (ModeType.PhotoView);
2039
 
                        ColorDialog.CreateForView (photo_view.View);
 
2126
        public void HideLoupe ()
 
2127
        {
 
2128
                loupe_menu_item.Active = false;
 
2129
        }
 
2130
 
 
2131
        void HandleLoupe (object sender, EventArgs args)
 
2132
        {
 
2133
                // Don't steal characters from any text entries
 
2134
                if (Window.Focus is Gtk.Entry && Gtk.Global.CurrentEvent is Gdk.EventKey) {
 
2135
                        Window.Focus.ProcessEvent (Gtk.Global.CurrentEvent);
 
2136
                        return;
2040
2137
                }
 
2138
                
 
2139
                photo_view.View.ShowHideLoupe ();
2041
2140
        }
2042
2141
 
2043
2142
        void HandleSharpen (object sender, EventArgs args)
2088
2187
        void HandleDisplayFilmstrip (object sender, EventArgs args)
2089
2188
        {
2090
2189
                photo_view.FilmStripVisibility = display_filmstrip.Active;
 
2190
                if (view_mode == ModeType.PhotoView)
 
2191
                        photo_view.QueueDraw ();
2091
2192
        }
2092
2193
 
2093
2194
        void HandleDisplayInfoSidebar (object sender, EventArgs args)
2136
2237
                if (fsview == null) {
2137
2238
                        fsview = new FSpot.FullScreenView (query, main_window);
2138
2239
                        fsview.Destroyed += HandleFullScreenViewDestroy;
 
2240
                        fsview.KeyPressEvent += HandleFullScreenViewKeyPressEvent;
2139
2241
                        fsview.View.Item.Index = active;
2140
 
                        ColorDialog.SwitchViews (fsview.View);
2141
2242
                } else {
2142
2243
                        // FIXME this needs to be another mode like PhotoView and IconView mode.
2143
2244
                        fsview.View.Item.Index = active;
2150
2251
        {
2151
2252
                JumpTo (fsview.View.Item.Index);
2152
2253
                fsview = null;
2153
 
                
2154
 
                if (ViewMode == ModeType.PhotoView) {
2155
 
                        ColorDialog.SwitchViews (photo_view.View);
2156
 
                }
2157
2254
        }
2158
2255
        
2159
2256
        void HandleZoomScaleValueChanged (object sender, System.EventArgs args)
2182
2279
                
2183
2280
                clear_date_range.Sensitive = (query.Range != null);
2184
2281
                clear_rating_filter.Sensitive = (query.RatingRange != null);
2185
 
                UpdateStatusLabel ();
 
2282
                update_status_label = true;
 
2283
                GLib.Idle.Add (UpdateStatusLabel);
2186
2284
        }
2187
2285
 
2188
 
        private void UpdateStatusLabel ()
 
2286
        bool update_status_label;
 
2287
        private bool UpdateStatusLabel ()
2189
2288
        {
2190
 
                //uint timer = Log.DebugTimerStart ();
 
2289
                update_status_label = false;
2191
2290
                int total_photos = Database.Photos.TotalPhotos;
2192
2291
                if (total_photos != query.Count)
2193
2292
                        status_label.Text = String.Format (Catalog.GetPluralString ("{0} Photo out of {1}", "{0} Photos out of {1}", query.Count), query.Count, total_photos);
2197
2296
                if ((selection != null) && (selection.Count > 0))
2198
2297
                        status_label.Text += String.Format (Catalog.GetPluralString (" ({0} selected)", " ({0} selected)", selection.Count), selection.Count);
2199
2298
                status_label.UseMarkup = true;
2200
 
                //Log.DebugTimerPrint (timer, "UpdateStatusLabel took {0}");
 
2299
                return update_status_label;
2201
2300
        }
2202
2301
        
2203
2302
        void HandleZoomChanged (object sender, System.EventArgs args)
2299
2398
                Widget wsender = sender as Widget;
2300
2399
                Gtk.Window toplevel = null;
2301
2400
 
2302
 
                if (wsender != null)
 
2401
                if (wsender != null && !(wsender is MenuItem))
2303
2402
                        toplevel = (Gtk.Window) wsender.Toplevel;
2304
2403
                else if (fsview != null)
2305
2404
                        toplevel = fsview;
2321
2420
                                                                 photos.Length);
2322
2421
                string ok_caption = Catalog.GetPluralString ("_Delete photo", "_Delete photos", photos.Length);
2323
2422
                
2324
 
 
2325
 
 
2326
2423
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(GetToplevel (sender), 
2327
2424
                                                                           DialogFlags.DestroyWithParent, 
2328
2425
                                                                           MessageType.Warning, 
2329
2426
                                                                           header, msg, ok_caption)) {                              
2330
2427
                        
 
2428
                        uint timer = Log.DebugTimerStart ();
2331
2429
                        foreach (Photo photo in photos) {
2332
2430
                                foreach (uint id in photo.VersionIds) {
2333
 
                                        Console.WriteLine (" path == {0}", photo.VersionUri (id).LocalPath);
2334
2431
                                        try {
2335
2432
                                                photo.DeleteVersion (id, true);
2336
2433
                                        } catch (Exception e) {
2341
2438
                        db.Photos.Remove (photos);
2342
2439
                        
2343
2440
                        UpdateQuery ();
 
2441
                        Log.DebugTimerPrint (timer, "HandleDeleteCommand took {0}");
2344
2442
                }
2345
2443
        }
2346
2444
 
2415
2513
                Db db = MainWindow.Toplevel.Database;
2416
2514
                FSpot.PhotoQuery count_query = new FSpot.PhotoQuery(db.Photos);
2417
2515
                count_query.Terms = FSpot.OrTerm.FromTags(tags);
2418
 
                int associated_photos = count_query.Photos.Length;
 
2516
                int associated_photos = count_query.Count;
2419
2517
 
2420
2518
                string header;
2421
2519
                if (tags.Length == 1)
2462
2560
                }
2463
2561
        }
2464
2562
 
2465
 
        void HandleUpdateThumbnailCommand (object sende, EventArgs args)
 
2563
        void HandleUpdateThumbnailCommand (object sender, EventArgs args)
2466
2564
        {
2467
2565
                ThumbnailCommand command = new ThumbnailCommand (main_window);
2468
2566
 
2469
2567
                int [] selected_ids = SelectedIds ();
2470
 
                if (command.Execute (SelectedPhotos (selected_ids))) {
2471
 
                        foreach (int num in selected_ids)
2472
 
                                query.MarkChanged (num);
 
2568
                if (command.Execute (SelectedPhotos (selected_ids)))
 
2569
#if MONO_1_9_0
 
2570
                        query.MarkChanged (selected_ids, new PhotoChanges {DataChanged = true});
 
2571
#else
 
2572
                {
 
2573
                        PhotoChanges changes = new PhotoChanges ();
 
2574
                        changes.DataChanged = true;
 
2575
                        query.MarkChanged (selected_ids, changes);
2473
2576
                }
 
2577
#endif
2474
2578
        }
2475
2579
 
2476
2580
        public void HandleRotate90Command (object sender, EventArgs args)
2546
2650
        }
2547
2651
 
2548
2652
        void HandleSelectLastRoll (object sender, EventArgs args) {
2549
 
                query.RollSet = new RollSet (db.Rolls.GetRolls (1)[0]);
 
2653
                query.RollSet = new RollSet (db.Rolls.GetRolls (1));
2550
2654
        }
2551
2655
 
2552
2656
        void HandleSelectRolls (object sender, EventArgs args) {
2580
2684
 
2581
2685
        void LoadPreference (String key)
2582
2686
        {
2583
 
                object val = Preferences.Get (key);
2584
 
 
2585
 
                if (val == null)
2586
 
                        return;
2587
 
                
2588
 
                //System.Console.WriteLine("Setting {0} to {1}", key, val);
2589
 
 
2590
2687
                switch (key) {
2591
2688
                case Preferences.MAIN_WINDOW_MAXIMIZED:
2592
 
                        if ((bool) val)
 
2689
                        if (Preferences.Get<bool> (key))
2593
2690
                                main_window.Maximize ();
2594
2691
                        else
2595
2692
                                main_window.Unmaximize ();
2597
2694
 
2598
2695
                case Preferences.MAIN_WINDOW_X:
2599
2696
                case Preferences.MAIN_WINDOW_Y:
2600
 
                        main_window.Move((int) Preferences.Get(Preferences.MAIN_WINDOW_X),
2601
 
                                        (int) Preferences.Get(Preferences.MAIN_WINDOW_Y));
 
2697
                        main_window.Move(Preferences.Get<int> (Preferences.MAIN_WINDOW_X),
 
2698
                                         Preferences.Get<int> (Preferences.MAIN_WINDOW_Y));
2602
2699
                        break;
2603
2700
                
2604
2701
                case Preferences.MAIN_WINDOW_WIDTH:
2605
2702
                case Preferences.MAIN_WINDOW_HEIGHT:
2606
 
                        main_window.Resize((int) Preferences.Get(Preferences.MAIN_WINDOW_WIDTH),
2607
 
                                        (int) Preferences.Get(Preferences.MAIN_WINDOW_HEIGHT));
 
2703
                        main_window.Resize(Preferences.Get<int> (Preferences.MAIN_WINDOW_WIDTH),
 
2704
                                           Preferences.Get<int> (Preferences.MAIN_WINDOW_HEIGHT));
2608
2705
 
2609
2706
                        break;
2610
2707
                
2611
2708
                case Preferences.SHOW_TOOLBAR:
2612
 
                        if (display_toolbar.Active != (bool) val)
2613
 
                                display_toolbar.Active = (bool) val;
 
2709
                        if (display_toolbar.Active != Preferences.Get<bool> (key))
 
2710
                                display_toolbar.Active = Preferences.Get<bool> (key);
2614
2711
                        break;
2615
2712
                
2616
2713
                case Preferences.SHOW_SIDEBAR:
2617
 
                        if (display_sidebar.Active != (bool) val)
2618
 
                                display_sidebar.Active = (bool) val;
 
2714
                        if (display_sidebar.Active != Preferences.Get<bool> (key))
 
2715
                                display_sidebar.Active = Preferences.Get<bool> (key);
2619
2716
                        break;
2620
2717
                
2621
2718
                case Preferences.SHOW_TIMELINE:
2622
 
                        if (display_timeline.Active != (bool) val)
2623
 
                                display_timeline.Active = (bool) val;
 
2719
                        if (display_timeline.Active != Preferences.Get<bool> (key))
 
2720
                                display_timeline.Active = Preferences.Get<bool> (key);
2624
2721
                        break;
2625
2722
                
2626
2723
                case Preferences.SHOW_FILMSTRIP:
2627
 
                        if (display_filmstrip.Active != (bool) val)
2628
 
                                display_filmstrip.Active = (bool) val;
 
2724
                        if (display_filmstrip.Active != Preferences.Get<bool> (key))
 
2725
                                display_filmstrip.Active = Preferences.Get<bool> (key);
2629
2726
                        break;
2630
2727
                
2631
2728
                case Preferences.SHOW_TAGS:
2632
 
                        if (display_tags_menu_item.Active != (bool) val)
2633
 
                                display_tags_menu_item.Active = (bool) val;
 
2729
                        if (display_tags_menu_item.Active != Preferences.Get<bool> (key))
 
2730
                                display_tags_menu_item.Active = Preferences.Get<bool> (key);
2634
2731
                        break;
2635
2732
                
2636
2733
                case Preferences.SHOW_DATES:
2637
 
                        if (display_dates_menu_item.Active != (bool) val)
2638
 
                                display_dates_menu_item.Active = (bool) val;
 
2734
                        if (display_dates_menu_item.Active != Preferences.Get<bool> (key))
 
2735
                                display_dates_menu_item.Active = Preferences.Get<bool> (key);
2639
2736
                                //display_dates_menu_item.Toggle ();
2640
2737
                        break;
2641
2738
                
2642
2739
                case Preferences.SHOW_RATINGS:
2643
 
                        if (display_ratings_menu_item.Active != (bool) val)
2644
 
                                display_ratings_menu_item.Active = (bool) val;
 
2740
                        if (display_ratings_menu_item.Active != Preferences.Get<bool> (key))
 
2741
                                display_ratings_menu_item.Active = Preferences.Get<bool> (key);
2645
2742
                        break;
2646
2743
                
2647
2744
                case Preferences.GROUP_ADAPTOR:
2648
 
                        if ((int) val == 1)
 
2745
                        if (Preferences.Get<int> (key) == 1)
2649
2746
                                directory.Active = true;
2650
2747
                        break;
2651
2748
 
2652
2749
                case Preferences.GROUP_ADAPTOR_ORDER_ASC:
2653
 
                        group_selector.Adaptor.OrderAscending = (bool) val;
2654
 
                        reverse_order.Active = (bool) val;
 
2750
                        group_selector.Adaptor.OrderAscending = Preferences.Get<bool> (key);
 
2751
                        reverse_order.Active = Preferences.Get<bool> (key);
 
2752
                        query.TimeOrderAsc = group_selector.Adaptor.OrderAscending;
2655
2753
                        break;
2656
2754
 
2657
2755
                case Preferences.GLASS_POSITION:
2659
2757
                                // If the database has changed since this pref was saved, this could cause
2660
2758
                                // an exception to be thrown.
2661
2759
                                try {
2662
 
                                        IBrowsableItem photo = group_selector.Adaptor.PhotoFromIndex ((int) val);
 
2760
                                        IBrowsableItem photo = group_selector.Adaptor.PhotoFromIndex (Preferences.Get<int> (key));
2663
2761
                                        
2664
2762
                                        if (photo != null)
2665
2763
                                                JumpTo (query.IndexOf (photo));
2667
2765
                        }
2668
2766
                        break;
2669
2767
                case Preferences.SIDEBAR_POSITION:
2670
 
                        if (main_hpaned.Position != (int) val)
2671
 
                                main_hpaned.Position = (int) val;
 
2768
                        if (main_hpaned.Position !=Preferences.Get<int> (key) )
 
2769
                                main_hpaned.Position = Preferences.Get<int> (key);
2672
2770
                        break;
2673
2771
 
2674
2772
                case Preferences.TAG_ICON_SIZE:
2675
 
                        int s = (int) val;
 
2773
                        int s = Preferences.Get<int> (key);
2676
2774
                        tag_icon_hidden.Active = (s == (int) Tag.IconSize.Hidden);
2677
2775
                        tag_icon_small.Active = (s == (int) Tag.IconSize.Small);
2678
2776
                        tag_icon_medium.Active = (s == (int) Tag.IconSize.Medium);
2681
2779
                        break;
2682
2780
 
2683
2781
                case Preferences.ZOOM:
2684
 
                        icon_view.Zoom = (double) val;
 
2782
                        icon_view.Zoom = Preferences.Get<double> (key);
2685
2783
                        break;
2686
2784
                
2687
2785
                case Preferences.METADATA_EMBED_IN_IMAGE:
2688
 
                        write_metadata = (bool) val;
 
2786
                        write_metadata =Preferences.Get<bool> (key) ;
 
2787
                        break;
 
2788
                case Preferences.COLOR_MANAGEMENT_ENABLED:
 
2789
                        FSpot.ColorManagement.IsEnabled = Preferences.Get<bool> (key);
 
2790
                        break;
 
2791
                case Preferences.COLOR_MANAGEMENT_USE_X_PROFILE:
 
2792
                        FSpot.ColorManagement.UseXProfile = Preferences.Get<bool> (key);
2689
2793
                        break;
2690
2794
                case Preferences.GNOME_MAILTO_ENABLED:
2691
 
                        send_mail.Visible = (bool) val;
 
2795
                        send_mail.Visible = Preferences.Get<bool> (key);
2692
2796
                        break;
2693
2797
                }
2694
2798
        }
2698
2802
        void UpdateForVersionIdChange (uint version_id)
2699
2803
        {
2700
2804
                CurrentPhoto.DefaultVersionId = version_id;
2701
 
                int active = ActiveIndex ();
2702
 
                
2703
 
                query.Commit (active);
2704
 
        }
2705
 
 
2706
 
        void HandleVersionIdChanged (PhotoVersionMenu menu)
2707
 
        {
2708
 
                UpdateForVersionIdChange (menu.VersionId);
2709
 
        }
2710
 
 
2711
 
        void HandleInfoBoxVersionIdChange (InfoBox box, uint version_id)
2712
 
        {
2713
 
                UpdateForVersionIdChange (version_id);
2714
 
        }
2715
 
 
 
2805
                query.Commit (ActiveIndex ());
 
2806
        }
2716
2807
 
2717
2808
        // Queries.
2718
2809
 
2834
2925
                        rename_version_menu_item.Sensitive = false;
2835
2926
 
2836
2927
                        sharpen.Sensitive = false;
 
2928
                        loupe_menu_item.Sensitive = false;
2837
2929
                } else {
2838
2930
                        version_menu_item.Sensitive = true;
2839
2931
                        create_version_menu_item.Sensitive = true;
2847
2939
                        }
2848
2940
 
2849
2941
                        versions_submenu = new PhotoVersionMenu (CurrentPhoto);
2850
 
                        versions_submenu.VersionIdChanged += new PhotoVersionMenu.VersionIdChangedHandler (HandleVersionIdChanged);
 
2942
                        versions_submenu.VersionIdChanged += delegate (PhotoVersionMenu menu) { UpdateForVersionIdChange (menu.VersionId);};
2851
2943
                        version_menu_item.Submenu = versions_submenu;
2852
2944
 
2853
2945
                        sharpen.Sensitive = (view_mode == ModeType.IconView ? false : true);
 
2946
                        loupe_menu_item.Sensitive = (view_mode == ModeType.IconView ? false : true);
2854
2947
                }
2855
2948
 
2856
2949
                set_as_background.Sensitive = single_active;
2857
 
                adjust_color.Sensitive = single_active;
2858
2950
                adjust_time.Sensitive = active_selection;
2859
2951
 
2860
2952
                attach_tag.Sensitive = active_selection;
2869
2961
                print.Sensitive = active_selection;
2870
2962
                select_none.Sensitive = active_selection;
2871
2963
                copy_location.Sensitive = active_selection;
2872
 
                exif_data.Sensitive = active_selection;
2873
2964
                remove_from_catalog.Sensitive = active_selection;
2874
2965
                
2875
2966
                clear_rating_filter.Sensitive = (query.RatingRange != null);
2876
2967
 
2877
 
                last_roll.Sensitive = (db.Rolls.GetRolls (1).Length > 0);
2878
 
                select_rolls.Sensitive = (db.Rolls.GetRolls (2).Length > 1);
2879
2968
                clear_roll_filter.Sensitive = (query.RollSet != null);
2880
2969
                
2881
2970
                delete_selected_tag.Sensitive = tag_sensitive;
2999
3088
                                        uint version = photo.CreateNamedVersion (mime_application.Name, photo.DefaultVersionId, true);
3000
3089
                                        photo.DefaultVersionId = version;
3001
3090
                                }
3002
 
                                query.MarkChanged (query.IndexOf (photo));
3003
3091
                        } catch (Exception e) {
3004
3092
                                errors.Add (new EditException (photo, e));
3005
3093
                        }
3014
3102
                        md.Destroy ();
3015
3103
                }
3016
3104
 
3017
 
                if (create_new_versions) {
3018
 
                        db.Photos.Commit (selected, new DbItemEventArgs (selected));
3019
 
                }
 
3105
                if (create_new_versions)
 
3106
                        db.Photos.Commit (selected);
3020
3107
 
3021
3108
                mime_application.Launch (uri_list);
3022
3109
        }
3089
3176
                        else
3090
3177
                                default_category = selection [0].Category;
3091
3178
                }
3092
 
 
 
3179
                Tag [] tags = new Tag [new_tags.Length];
 
3180
                int i = 0;
3093
3181
                db.BeginTransaction ();
3094
3182
                foreach (string tagname in new_tags) {
3095
3183
                        Tag t = db.Tags.GetTagByName (tagname);
3097
3185
                                t = db.Tags.CreateCategory (default_category, tagname) as Tag;
3098
3186
                                db.Tags.Commit (t);
3099
3187
                        }
3100
 
 
3101
 
                        Tag [] tags = new Tag [1];
3102
 
                        tags [0] = t;
3103
 
 
3104
 
                        foreach (int num in selected_photos)
3105
 
                                AddTagExtended (num, tags);
 
3188
                        tags [i++] = t;
3106
3189
                }
 
3190
                AddTagExtended (selected_photos, tags);
3107
3191
                db.CommitTransaction ();
3108
3192
        }
3109
3193
 
3113
3197
                if (selected_photos == null || remove_tags == null || remove_tags.Length == 0)
3114
3198
                        return;
3115
3199
 
3116
 
                foreach (Tag t in remove_tags) {
3117
 
                        foreach (int num in selected_photos) {
3118
 
                                query.Photos [num].RemoveTag (t);
3119
 
                                query.Commit (num);
3120
 
                        }
3121
 
                }
 
3200
                db.BeginTransaction ();
 
3201
                RemoveTags (selected_photos, remove_tags);
 
3202
                db.CommitTransaction ();
3122
3203
        }
3123
3204
 
3124
3205
        private void HideTagbar ()
3133
3214
 
3134
3215
                if (view_mode == ModeType.IconView)
3135
3216
                        icon_view.GrabFocus ();
3136
 
                else
 
3217
                else {
 
3218
                        photo_view.QueueDraw ();
3137
3219
                        photo_view.View.GrabFocus ();
 
3220
                }
3138
3221
 
3139
3222
                tag_entry.ClearTagCompletions ();
3140
3223
        }
3177
3260
                query_widget.ShowBar ();
3178
3261
                return;
3179
3262
        }
 
3263
 
 
3264
        public void HideSidebar (object o, EventArgs args) {
 
3265
                display_sidebar.Active = false;
 
3266
        }
3180
3267
        
3181
3268
        public void HandleKeyPressEvent (object sender, Gtk.KeyPressEventArgs args)
3182
3269
        {