Add "destroy non-primary image versions" functionality
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 29 Jul 2007 19:08:48 +0000 (21:08 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 29 Jul 2007 19:08:48 +0000 (21:08 +0200)
src/gkofoto/glade/gkofoto.glade
src/packages/kofoto/gkofoto/objectcollection.py
src/packages/kofoto/gkofoto/objectcollectionview.py
src/packages/kofoto/gkofoto/tableview.py

index 4b43ca2..4febfb5 100644 (file)
                      <accelerator key="s" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1061">
+                       <widget class="GtkImage" id="image1240">
                          <property name="visible">True</property>
                          <property name="stock">gtk-save</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_revert_activate" last_modification_time="Sat, 17 May 2003 15:02:14 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1062">
+                       <widget class="GtkImage" id="image1241">
                          <property name="visible">True</property>
                          <property name="stock">gtk-revert-to-saved</property>
                          <property name="icon_size">1</property>
                      <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1063">
+                       <widget class="GtkImage" id="image1242">
                          <property name="visible">True</property>
                          <property name="stock">gtk-quit</property>
                          <property name="icon_size">1</property>
                      <accelerator key="x" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1064">
+                       <widget class="GtkImage" id="image1243">
                          <property name="visible">True</property>
                          <property name="stock">gtk-cut</property>
                          <property name="icon_size">1</property>
                      <accelerator key="c" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1065">
+                       <widget class="GtkImage" id="image1244">
                          <property name="visible">True</property>
                          <property name="stock">gtk-copy</property>
                          <property name="icon_size">1</property>
                      <accelerator key="v" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1066">
+                       <widget class="GtkImage" id="image1245">
                          <property name="visible">True</property>
                          <property name="stock">gtk-paste</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_menubarDelete_activate" last_modification_time="Sun, 11 Jul 2004 19:26:27 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1067">
+                       <widget class="GtkImage" id="image1246">
                          <property name="visible">True</property>
                          <property name="stock">gtk-delete</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_destroy_activate" last_modification_time="Sun, 11 Jul 2004 19:26:27 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1068">
+                       <widget class="GtkImage" id="image1247">
                          <property name="visible">True</property>
                          <property name="stock">gtk-delete</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_clear_activate" last_modification_time="Sun, 11 Jul 2004 20:06:16 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1069">
+                       <widget class="GtkImage" id="image1248">
                          <property name="visible">True</property>
                          <property name="stock">gtk-clear</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_menubarProperties_activate" last_modification_time="Wed, 14 Jul 2004 10:12:21 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1070">
+                       <widget class="GtkImage" id="image1249">
                          <property name="visible">True</property>
                          <property name="stock">gtk-properties</property>
                          <property name="icon_size">1</property>
                      <accelerator key="F6" modifiers="0" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1071">
+                       <widget class="GtkImage" id="image1250">
                          <property name="visible">True</property>
                          <property name="stock">gtk-go-forward</property>
                          <property name="icon_size">1</property>
                      <accelerator key="F6" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1072">
+                       <widget class="GtkImage" id="image1251">
                          <property name="visible">True</property>
                          <property name="stock">gtk-go-back</property>
                          <property name="icon_size">1</property>
                              <accelerator key="0" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                              <child internal-child="image">
-                               <widget class="GtkImage" id="image1073">
+                               <widget class="GtkImage" id="image1252">
                                  <property name="visible">True</property>
                                  <property name="stock">gtk-zoom-100</property>
                                  <property name="icon_size">1</property>
                              <accelerator key="equal" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                              <child internal-child="image">
-                               <widget class="GtkImage" id="image1074">
+                               <widget class="GtkImage" id="image1253">
                                  <property name="visible">True</property>
                                  <property name="stock">gtk-zoom-fit</property>
                                  <property name="icon_size">1</property>
                              <accelerator key="plus" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                              <child internal-child="image">
-                               <widget class="GtkImage" id="image1075">
+                               <widget class="GtkImage" id="image1254">
                                  <property name="visible">True</property>
                                  <property name="stock">gtk-zoom-in</property>
                                  <property name="icon_size">1</property>
                              <accelerator key="minus" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                              <child internal-child="image">
-                               <widget class="GtkImage" id="image1076">
+                               <widget class="GtkImage" id="image1255">
                                  <property name="visible">True</property>
                                  <property name="stock">gtk-zoom-out</property>
                                  <property name="icon_size">1</property>
                      <signal name="activate" handler="on_open_image_activate" last_modification_time="Sun, 11 Jul 2004 19:52:02 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1077">
+                       <widget class="GtkImage" id="image1256">
                          <property name="visible">True</property>
                          <property name="stock">gtk-open</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_menubarDuplicateAndOpenImage_activate" last_modification_time="Thu, 14 Jul 2005 10:29:29 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1078">
+                       <widget class="GtkImage" id="image1257">
                          <property name="visible">True</property>
                          <property name="stock">gtk-open</property>
                          <property name="icon_size">1</property>
                      <accelerator key="R" modifiers="GDK_CONTROL_MASK | GDK_SHIFT_MASK" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1079">
+                       <widget class="GtkImage" id="image1258">
                          <property name="visible">True</property>
                          <property name="stock">gtk-add</property>
                          <property name="icon_size">1</property>
                      <accelerator key="R" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1080">
+                       <widget class="GtkImage" id="image1259">
                          <property name="visible">True</property>
                          <property name="stock">gtk-add</property>
                          <property name="icon_size">1</property>
                  </child>
 
                  <child>
+                   <widget class="GtkImageMenuItem" id="menubarDestroyNonPrimaryImageVersions">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">Destroy non-primary image versions...</property>
+                     <property name="use_underline">True</property>
+                     <signal name="activate" handler="on_menubarDestroyNonPrimaryImageVersions_activate" last_modification_time="Sun, 29 Jul 2007 18:29:28 GMT"/>
+
+                     <child internal-child="image">
+                       <widget class="GtkImage" id="image1260">
+                         <property name="visible">True</property>
+                         <property name="stock">gtk-delete</property>
+                         <property name="icon_size">1</property>
+                         <property name="xalign">0.5</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                     </child>
+                   </widget>
+                 </child>
+
+                 <child>
                    <widget class="GtkSeparatorMenuItem" id="separator7">
                      <property name="visible">True</property>
                    </widget>
                      <signal name="activate" handler="on_open_image_version(s)_in_external_program1_activate" last_modification_time="Wed, 13 Jul 2005 10:11:26 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1081">
+                       <widget class="GtkImage" id="image1261">
                          <property name="visible">True</property>
                          <property name="stock">gtk-open</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_menubarDuplicateAndOpenImageVersion_activate" last_modification_time="Thu, 14 Jul 2005 12:03:08 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1082">
+                       <widget class="GtkImage" id="image1262">
                          <property name="visible">True</property>
                          <property name="stock">gtk-open</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_rotate_left1_activate" last_modification_time="Wed, 13 Jul 2005 10:11:26 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1083">
+                       <widget class="GtkImage" id="image1263">
                          <property name="visible">True</property>
                          <property name="stock">gtk-add</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_rotate_right1_activate" last_modification_time="Wed, 13 Jul 2005 10:11:26 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1084">
+                       <widget class="GtkImage" id="image1264">
                          <property name="visible">True</property>
                          <property name="stock">gtk-add</property>
                          <property name="icon_size">1</property>
                  </child>
 
                  <child>
-                   <widget class="GtkMenuItem" id="menubarDestroyImageVersion">
+                   <widget class="GtkImageMenuItem" id="menubarDestroyImageVersion">
                      <property name="visible">True</property>
                      <property name="label" translatable="yes">_Destroy...</property>
                      <property name="use_underline">True</property>
                      <signal name="activate" handler="on_destroy1_activate" last_modification_time="Wed, 13 Jul 2005 10:11:26 GMT"/>
+
+                     <child internal-child="image">
+                       <widget class="GtkImage" id="image1265">
+                         <property name="visible">True</property>
+                         <property name="stock">gtk-delete</property>
+                         <property name="icon_size">1</property>
+                         <property name="xalign">0.5</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                     </child>
                    </widget>
                  </child>
 
                      <signal name="activate" handler="on_about_activate" last_modification_time="Sun, 11 Jul 2004 20:05:01 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image1085">
+                       <widget class="GtkImage" id="image1266">
                          <property name="visible">True</property>
                          <property name="stock">gtk-add</property>
                          <property name="icon_size">1</property>
@@ -4834,4 +4867,126 @@ description of the new, single image:</property>
   </child>
 </widget>
 
+<widget class="GtkDialog" id="destroyNonPrimaryImageVersionsDialog">
+  <property name="visible">True</property>
+  <property name="title" translatable="yes">Destroy image version(s)</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">True</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
+  <property name="has_separator">True</property>
+
+  <child internal-child="vbox">
+    <widget class="GtkVBox" id="vbox24">
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">0</property>
+
+      <child internal-child="action_area">
+       <widget class="GtkHButtonBox" id="hbuttonbox7">
+         <property name="visible">True</property>
+         <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+         <child>
+           <widget class="GtkButton" id="button8">
+             <property name="visible">True</property>
+             <property name="can_default">True</property>
+             <property name="can_focus">True</property>
+             <property name="label">gtk-cancel</property>
+             <property name="use_stock">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+             <property name="response_id">-6</property>
+           </widget>
+         </child>
+
+         <child>
+           <widget class="GtkButton" id="button9">
+             <property name="visible">True</property>
+             <property name="can_default">True</property>
+             <property name="can_focus">True</property>
+             <property name="label">gtk-ok</property>
+             <property name="use_stock">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+             <property name="response_id">-5</property>
+           </widget>
+         </child>
+       </widget>
+       <packing>
+         <property name="padding">0</property>
+         <property name="expand">False</property>
+         <property name="fill">True</property>
+         <property name="pack_type">GTK_PACK_END</property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="GtkVBox" id="vbox25">
+         <property name="visible">True</property>
+         <property name="homogeneous">False</property>
+         <property name="spacing">0</property>
+
+         <child>
+           <widget class="GtkLabel" id="label304">
+             <property name="visible">True</property>
+             <property name="label" translatable="yes">Throw away all knowledge about non-primary versions of the selected image(s)?</property>
+             <property name="use_underline">False</property>
+             <property name="use_markup">False</property>
+             <property name="justify">GTK_JUSTIFY_CENTER</property>
+             <property name="wrap">True</property>
+             <property name="selectable">False</property>
+             <property name="xalign">0.5</property>
+             <property name="yalign">0.5</property>
+             <property name="xpad">0</property>
+             <property name="ypad">0</property>
+             <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+             <property name="width_chars">-1</property>
+             <property name="single_line_mode">False</property>
+             <property name="angle">0</property>
+           </widget>
+           <packing>
+             <property name="padding">10</property>
+             <property name="expand">False</property>
+             <property name="fill">False</property>
+           </packing>
+         </child>
+
+         <child>
+           <widget class="GtkCheckButton" id="deleteImageFilesCheckbutton">
+             <property name="visible">True</property>
+             <property name="can_focus">True</property>
+             <property name="label" translatable="yes">Also delete image file(s) on disk.</property>
+             <property name="use_underline">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+             <property name="active">False</property>
+             <property name="inconsistent">False</property>
+             <property name="draw_indicator">True</property>
+           </widget>
+           <packing>
+             <property name="padding">6</property>
+             <property name="expand">False</property>
+             <property name="fill">False</property>
+           </packing>
+         </child>
+       </widget>
+       <packing>
+         <property name="padding">0</property>
+         <property name="expand">True</property>
+         <property name="fill">True</property>
+       </packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
 </glade-interface>
index c1d26e1..ee84bea 100644 (file)
@@ -119,6 +119,9 @@ class ObjectCollection(object):
     def getMergeImagesLabel(self):
         return "Merge images..."
 
+    def getDestroyNonPrimaryImageVersionsLabel(self):
+        return "Destroy non-primary image versions..."
+
     def getObjectMetadataMap(self):
         return self.__objectMetadataMap
 
@@ -517,6 +520,33 @@ class ObjectCollection(object):
         dialog = ImageVersionsDialog(self)
         dialog.runMergeImages(selectedObjects)
 
+    def destroyNonPrimaryImageVersions(self, *unused):
+        selectedImages = [
+            x
+            for x in self.__objectSelection.getSelectedObjects()
+            if not x.isAlbum()]
+        assert len(selectedImages) > 0
+        dialogId = "destroyNonPrimaryImageVersionsDialog"
+        widgets = gtk.glade.XML(env.gladeFile, dialogId)
+        dialog = widgets.get_widget(dialogId)
+        result = dialog.run()
+        if result == gtk.RESPONSE_OK:
+            checkbutton = widgets.get_widget("deleteImageFilesCheckbutton")
+            deleteFiles = checkbutton.get_active()
+            for image in selectedImages:
+                for iv in image.getImageVersions():
+                    if not iv.isPrimary():
+                        if deleteFiles:
+                            try:
+                                os.remove(iv.getLocation())
+                                # TODO: Delete from image cache too?
+                            except OSError:
+                                pass
+                        env.shelf.deleteImageVersion(iv.getId())
+            self.reloadSingleObjectView()
+            self.reloadSelectedRows()
+        dialog.destroy()
+
     def rotateImage(self, unused, angle):
         for (rowNr, obj) in self.__objectSelection.getMap().items():
             if not obj.isAlbum():
index 229254d..f721fd4 100644 (file)
@@ -65,6 +65,10 @@ class ObjectCollectionView:
             env.widgets["menubarMergeImages"],
             "activate",
             self._objectCollection.mergeImages)
+        self._connect(
+            env.widgets["menubarDestroyNonPrimaryImageVersions"],
+            "activate",
+            self._objectCollection.destroyNonPrimaryImageVersions)
 
     def _updateMenubarSortMenu(self):
         sortMenuGroup = self.__createSortMenuGroup(self._objectCollection)
@@ -268,6 +272,7 @@ class ObjectCollectionView:
                 env.widgets["menubarOpenImage"].set_sensitive(True)
                 env.widgets["menubarRotateLeft"].set_sensitive(True)
                 env.widgets["menubarRotateRight"].set_sensitive(True)
+                env.widgets["menubarDestroyNonPrimaryImageVersions"].set_sensitive(True)
                 if imagesSelected == 1:
                     env.widgets["menubarDuplicateAndOpenImage"].set_sensitive(True)
                     self.__singleImageMenuGroup.enable()
@@ -293,6 +298,7 @@ class ObjectCollectionView:
                 env.widgets["menubarRegisterImageVersions"].set_sensitive(False)
                 env.widgets["menubarRotateLeft"].set_sensitive(False)
                 env.widgets["menubarRotateRight"].set_sensitive(False)
+                env.widgets["menubarDestroyNonPrimaryImageVersions"].set_sensitive(False)
         else:
             self.__clipboardMenuGroup.disable()
             env.widgets["menubarCut"].set_sensitive(False)
@@ -313,6 +319,7 @@ class ObjectCollectionView:
             env.widgets["menubarDuplicateAndOpenImage"].set_sensitive(False)
             env.widgets["menubarRotateLeft"].set_sensitive(False)
             env.widgets["menubarRotateRight"].set_sensitive(False)
+            env.widgets["menubarDestroyNonPrimaryImageVersions"].set_sensitive(False)
             self.__singleImageMenuGroup.disable()
             env.widgets["menubarImageVersions"].set_sensitive(False)
             env.widgets["menubarRegisterImageVersions"].set_sensitive(False)
@@ -423,6 +430,10 @@ class ObjectCollectionView:
             oc.getRotateImageRightLabel(),
             os.path.join(env.iconDir, "rotateright.png"),
             oc.rotateImage, 90)
+        menuGroup.addStockImageMenuItem(
+            oc.getDestroyNonPrimaryImageVersionsLabel(),
+            gtk.STOCK_DELETE,
+            oc.destroyNonPrimaryImageVersions)
         menuGroup.addSeparator()
         return menuGroup
 
index c186aa6..c288ea7 100644 (file)
@@ -178,6 +178,7 @@ class TableView(ObjectCollectionView):
                 ("menubarDuplicateAndOpenImage", oc.duplicateAndOpenImage),
                 ("menubarRotateLeft", oc.rotateImageLeft),
                 ("menubarRotateRight", oc.rotateImageRight),
+                ("menubarDestroyNonPrimaryImageVersions", oc.destroyNonPrimaryImageVersions),
                 ("menubarImageVersions", oc.imageVersions),
                 ("menubarRegisterImageVersions", oc.registerImageVersions),
                 ("menubarMergeImages", oc.mergeImages),
@@ -215,6 +216,7 @@ class TableView(ObjectCollectionView):
                 "menubarDuplicateAndOpenImage",
                 "menubarRotateLeft",
                 "menubarRotateRight",
+                "menubarDestroyNonPrimaryImageVersions",
                 "menubarImageVersions",
                 "menubarRegisterImageVersions",
                 "menubarMergeImages",