[chronojump] PersonWin can delete photos, and shows no-photo icon if needed.



commit 4941265e8632cfb939054d3e473179cf092a6dc9
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Nov 26 17:38:50 2021 +0100

    PersonWin can delete photos, and shows no-photo icon if needed.

 glade/person_win.glade      | 48 ++++++++++++++++++++++++++++++++++++++++++++-
 src/gui/person/addModify.cs | 38 +++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 1 deletion(-)
---
diff --git a/glade/person_win.glade b/glade/person_win.glade
index 8e74ad006..8a3aacbce 100644
--- a/glade/person_win.glade
+++ b/glade/person_win.glade
@@ -515,10 +515,56 @@
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="pack_type">end</property>
                                                 <property name="position">1</property>
                                               </packing>
                                             </child>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox4">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="spacing">6</property>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label1">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="xalign">0</property>
+                                                    <property name="label" translatable="yes">Delete 
photo</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkButton" id="button_delete_photo_file">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">True</property>
+                                                    <signal name="clicked" 
handler="on_button_delete_photo_file_clicked" swapped="no"/>
+                                                    <child>
+                                                      <widget class="GtkImage" id="image_photo_delete">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="stock">gtk-missing-image</property>
+                                                      </widget>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="pack_type">end</property>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">True</property>
+                                                <property name="pack_type">end</property>
+                                                <property name="position">2</property>
+                                              </packing>
+                                            </child>
                                           </widget>
                                           <packing>
                                             <property name="expand">False</property>
diff --git a/src/gui/person/addModify.cs b/src/gui/person/addModify.cs
index 7448b4e8a..fbb5773ae 100644
--- a/src/gui/person/addModify.cs
+++ b/src/gui/person/addModify.cs
@@ -50,6 +50,9 @@ public class PersonAddModifyWindow
        [Widget] Gtk.Image image_photo_preview;
        [Widget] Gtk.Image image_photo_do;
 
+       [Widget] Gtk.Button button_delete_photo_file;
+       [Widget] Gtk.Image image_photo_delete;
+
        [Widget] Gtk.Button button_add_photo_file;
        [Widget] Gtk.Button button_take_photo_do;
        [Widget] Gtk.HBox hbox_camera;
@@ -192,6 +195,9 @@ public class PersonAddModifyWindow
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_person_outline.png");
                image_load_person.Pixbuf = pixbuf;
 
+               pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "stock_delete.png");
+               image_photo_delete.Pixbuf = pixbuf;
+
                image_photo_from_file.Pixbuf = new Pixbuf (null, Util.GetImagePath(false) + 
"image_attachment.png");
                image_photo_preview.Pixbuf = new Pixbuf (null, Util.GetImagePath(false) + 
"image_photo_preview.png");
                image_photo_do.Pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_photo_do.png");
@@ -212,7 +218,15 @@ public class PersonAddModifyWindow
                                pixbuf = new Pixbuf (tempFileName);
                                image_photo_mini.Pixbuf = pixbuf;
                        }
+
+                       button_delete_photo_file.Sensitive = true;
                }
+               else {
+                       pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_no_photo.png");
+                       image_photo_mini.Pixbuf = pixbuf;
+                       button_delete_photo_file.Sensitive = false;
+               }
+
                //show zoom button only if big image exists
                string photoBigFile = Util.UserPhotoURL(false, currentPerson.UniqueID);
                if(photoBigFile != "")
@@ -319,6 +333,19 @@ public class PersonAddModifyWindow
                        Util.FileDelete(file);
        }
 
+       //user wants to delete his photo
+       private void deletePhoto (int uniqueID)
+       {
+               LogB.Information("deletePhoto: " + uniqueID.ToString());
+               string file = Util.UserPhotoURL(false, uniqueID); //default
+               if(file != "")
+                       Util.FileDelete(file);
+
+               file  = Util.UserPhotoURL(true, uniqueID); //small
+               if(file != "")
+                       Util.FileDelete(file);
+       }
+
        void on_button_add_photo_file_clicked (object o, EventArgs args)
        {
                Gtk.FileChooserDialog fc=
@@ -431,6 +458,17 @@ public class PersonAddModifyWindow
                button_delete_photo_file.Sensitive = true;
        }
 
+       private void on_button_delete_photo_file_clicked (object o, EventArgs args)
+       {
+               deletePhoto (currentPerson.UniqueID);
+
+               button_delete_photo_file.Sensitive = false;
+
+               Pixbuf pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_no_photo.png");
+               image_photo_mini.Pixbuf = pixbuf;
+               button_zoom.Sensitive = false;
+       }
+
        void on_entries_required_changed (object o, EventArgs args)
        {
                entry1.Text = Util.MakeValidSQL(entry1.Text);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]