[chronojump] Photo file can be added to person (jpg or png). Need tests!



commit c519174f8b36ad97b7db4999dffdccb6e02f95d1
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Feb 1 17:13:50 2018 +0100

    Photo file can be added to person (jpg or png). Need tests!

 glade/person_win.glade       |   68 ++++++++++++-----
 src/constants.cs             |    3 +-
 src/gui/dialogPersonPopup.cs |    8 +-
 src/gui/networks.cs          |    9 ++-
 src/gui/person.cs            |  166 ++++++++++++++++++++++++++++++++++-------
 src/gui/personSelect.cs      |    2 +-
 src/sqlite/personSession.cs  |    8 +-
 src/util.cs                  |   43 ++++++++++-
 src/utilMultimedia.cs        |   30 ++++---
 9 files changed, 261 insertions(+), 76 deletions(-)
---
diff --git a/glade/person_win.glade b/glade/person_win.glade
index 2bd8e40..d82fe5f 100644
--- a/glade/person_win.glade
+++ b/glade/person_win.glade
@@ -4,13 +4,13 @@
   <!-- interface-naming-policy toplevel-contextual -->
   <widget class="GtkWindow" id="person_win">
     <property name="width_request">425</property>
-    <property name="height_request">450</property>
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="has_default">True</property>
     <property name="border_width">10</property>
     <property name="title" translatable="yes">New jumper</property>
     <property name="resizable">False</property>
+    <property name="modal">True</property>
     <property name="type_hint">dialog</property>
     <signal name="delete_event" handler="on_person_win_delete_event" swapped="no"/>
     <child>
@@ -337,34 +337,60 @@
                                 <property name="stock">gtk-missing-image</property>
                               </widget>
                               <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
+                                <property name="expand">True</property>
+                                <property name="fill">True</property>
                                 <property name="position">0</property>
                               </packing>
                             </child>
                             <child>
-                              <widget class="GtkHBox" id="hbox6">
+                              <widget class="GtkVBox" id="vbox3">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="spacing">4</property>
+                                <property name="spacing">6</property>
                                 <child>
-                                  <widget class="GtkButton" id="button_zoom">
+                                  <widget class="GtkHBox" id="hbox6">
                                     <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="receives_default">True</property>
-                                    <property name="has_tooltip">True</property>
-                                    <signal name="clicked" handler="on_button_zoom_clicked" swapped="no"/>
-                                    <accelerator key="z" signal="clicked"/>
+                                    <property name="can_focus">False</property>
+                                    <property name="spacing">6</property>
                                     <child>
-                                      <widget class="GtkImage" id="image_zoom">
+                                      <widget class="GtkButton" id="button_zoom">
                                         <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">True</property>
+                                        <property name="has_tooltip">True</property>
+                                        <signal name="clicked" handler="on_button_zoom_clicked" 
swapped="no"/>
+                                        <accelerator key="z" signal="clicked"/>
+                                        <child>
+                                          <widget class="GtkImage" id="image_zoom">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                          </widget>
+                                        </child>
                                       </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_add_photo_file">
+                                        <property name="label" translatable="yes">Add photo</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">True</property>
+                                        <signal name="clicked" handler="on_button_add_photo_file_clicked" 
swapped="no"/>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
+                                      </packing>
                                     </child>
                                   </widget>
                                   <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
                                     <property name="position">0</property>
                                   </packing>
                                 </child>
@@ -543,12 +569,6 @@
                                       <placeholder/>
                                     </child>
                                     <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
                                       <widget class="GtkLabel" id="label218">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
@@ -1944,6 +1964,12 @@
                                     <child>
                                       <placeholder/>
                                     </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
                                   </widget>
                                 </child>
                               </widget>
diff --git a/src/constants.cs b/src/constants.cs
index 48876d9..75609de 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -710,10 +710,11 @@ public class Constants
        }
        
        public enum MultimediaItems {
-               PHOTO, VIDEO
+               PHOTO, PHOTOPNG, VIDEO
        }
        public const string ExtensionVideo = ".avi";
        public const string ExtensionPhoto = ".jpg";
+       public const string ExtensionPhotoPng = ".png"; //used for Cairo resized images
        public const string SmallPhotoDir = "small";
        public static string MultimediaFileNoExists = Catalog.GetString("Sorry, this multimedia file does not 
exists.");
        public static string PhotoTemp = "chronojump-last-photo";
diff --git a/src/gui/dialogPersonPopup.cs b/src/gui/dialogPersonPopup.cs
index 8a9d61c..42257bc 100644
--- a/src/gui/dialogPersonPopup.cs
+++ b/src/gui/dialogPersonPopup.cs
@@ -90,16 +90,18 @@ public class DialogPersonPopup
                        image_server_connected_no.Visible = true;
                }
 
-               string photoFile = Util.GetPhotoFileName(false, personID);
+               //string photoFile = Util.GetPhotoFileName(false, personID);
+               string photoFile = Util.UserPhotoURL(false, personID);
                if(File.Exists(photoFile))
                {
                        try {
                                pixbuf = new Pixbuf (photoFile); //from a file
                                image_person.Pixbuf = pixbuf;
                        } catch {
+                               string extension = Util.GetMultimediaExtension(photoFile);
                                //on windows there are problem using the fileNames that are not on temp
-                               string tempFileName = Path.Combine(Path.GetTempPath(), 
Constants.PhotoSmallTemp +
-                                               Util.GetMultimediaExtension(Constants.MultimediaItems.PHOTO));
+                               string tempFileName = Path.Combine(Path.GetTempPath(),
+                                               Constants.PhotoSmallTemp + extension);
                                File.Copy(photoFile, tempFileName, true);
                                pixbuf = new Pixbuf (tempFileName);
                                image_person.Pixbuf = pixbuf;
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index a15c12f..fe9aaa0 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -516,13 +516,18 @@ public partial class ChronoJumpWindow
 
                                if(json.LastPersonWasInserted)
                                {
-                                       if(json.LastPersonByRFIDImageURL != "")
+                                       string imageFile = json.LastPersonByRFIDImageURL;
+                                       if(imageFile != "")
                                        {
+                                               string image_dest = Util.GetPhotoFileName(false, 
currentPerson.UniqueID);
+                                               if(UtilMultimedia.GetImageType(imageFile) == 
UtilMultimedia.ImageTypes.PNG)
+                                                       image_dest = Util.GetPhotoPngFileName(false, 
currentPerson.UniqueID);
+
                                                bool downloaded = 
json.DownloadImage(json.LastPersonByRFIDImageURL, currentPerson.UniqueID);
                                                if(downloaded)
                                                        File.Copy(
                                                                        Path.Combine(Path.GetTempPath(), 
currentPerson.UniqueID.ToString()),
-                                                                       Util.GetPhotoFileName(false, 
currentPerson.UniqueID),
+                                                                       image_dest,
                                                                        true); //overwrite
                                        }
 
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 5a2b2e9..0583b5f 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -788,7 +788,8 @@ public class PersonAddModifyWindow
        [Widget] Gtk.TextView textview_description;
        [Widget] Gtk.TextView textview_ps_comments;
        
-       [Widget] Gtk.Box vbox_photo;
+       [Widget] Gtk.Button button_add_photo_file;
+       [Widget] Gtk.Button button_take_photo;
        
        [Widget] Gtk.Label label_date;
        //[Widget] Gtk.Button button_change_date;
@@ -859,8 +860,9 @@ public class PersonAddModifyWindow
        //
        //if we are adding a person, currentPerson.UniqueID it's -1
        //if we are modifying a person, currentPerson.UniqueID is obviously it's ID
-       //showPhotoStuff is false on raspberry to not use camera
-       PersonAddModifyWindow (Gtk.Window parent, Session currentSession, Person currentPerson, bool 
showPhotoStuff) {
+       //showCapturePhoto is false on raspberry to not use camera
+       PersonAddModifyWindow (Gtk.Window parent, Session currentSession, Person currentPerson, bool 
showCapturePhoto)
+       {
                Glade.XML gladeXML;
                gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "person_win.glade", "person_win", 
null);
                gladeXML.Autoconnect(this);
@@ -892,30 +894,35 @@ public class PersonAddModifyWindow
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + Constants.FileNameZoomInIcon);
                image_zoom.Pixbuf = pixbuf;
 
-               if(showPhotoStuff) {
-                       string photoFile = Util.GetPhotoFileName(true, currentPerson.UniqueID);
-                       if(File.Exists(photoFile)) {
-                               try {
-                                       pixbuf = new Pixbuf (photoFile); //from a file
-                                       image_photo_mini.Pixbuf = pixbuf;
-                               } catch {
-                                       //on windows there are problem using the fileNames that are not on 
temp
-                                       string tempFileName = Path.Combine(Path.GetTempPath(), 
Constants.PhotoSmallTemp +
-                                                       
Util.GetMultimediaExtension(Constants.MultimediaItems.PHOTO));
-                                       File.Copy(photoFile, tempFileName, true);
-                                       pixbuf = new Pixbuf (tempFileName);
-                                       image_photo_mini.Pixbuf = pixbuf;
-                               }
+               button_take_photo.Visible = showCapturePhoto;
+
+               //delete a -1.png or -1.jpg added before on a new user where "accept" button was not pressed 
and window was closed
+               deleteOldPhotosIfAny(-1);
+
+               string photoFile = Util.UserPhotoURL(true, currentPerson.UniqueID);
+               if(photoFile != "") {
+                       try {
+                               pixbuf = new Pixbuf (photoFile); //from a file
+                               image_photo_mini.Pixbuf = pixbuf;
+                       } catch {
+                               //on windows there are problem using the fileNames that are not on temp
+                               string tempFileName = Path.Combine(Path.GetTempPath(), 
Constants.PhotoSmallTemp +
+                                               Util.GetMultimediaExtension(Constants.MultimediaItems.PHOTO));
+                               File.Copy(photoFile, tempFileName, true);
+                               pixbuf = new Pixbuf (tempFileName);
+                               image_photo_mini.Pixbuf = pixbuf;
                        }
-                       //show zoom button only if big image exists
-                       if(File.Exists(Util.GetPhotoFileName(false, currentPerson.UniqueID)))
-                               button_zoom.Sensitive = true;
-                       else
-                               button_zoom.Sensitive = false;
+               }
+               //show zoom button only if big image exists
+               string photoBigFile = Util.UserPhotoURL(false, currentPerson.UniqueID);
+               if(photoBigFile != "")
+               {
+                       button_zoom.Sensitive = true;
+                       button_add_photo_file.Label = Catalog.GetString("Change photo");
                }
                else
-                       vbox_photo.Visible = false;
-                       
+                       button_zoom.Sensitive = false;
+
                fakeButtonAccept = new Gtk.Button();
 
                entry1.CanFocus = true;
@@ -933,13 +940,89 @@ public class PersonAddModifyWindow
                                Util.GetMultimediaExtension(Constants.MultimediaItems.PHOTO));
                if(! adding) {
                        //on windows there are problem using the fileNames that are not on temp
-                       string fileName = Util.GetPhotoFileName(false, currentPerson.UniqueID);
+                       string fileName = Util.UserPhotoURL(false, currentPerson.UniqueID);
                        File.Copy(fileName, tempFileName, true);
                }
 
                new DialogImageTest(currentPerson.Name, tempFileName, DialogImageTest.ArchiveType.FILE);
        }
 
+       /*
+        * used when:
+        * 1.- adding a photo to delete a possible duplicate, eg user 231 has 231.png and now will add 231.jpg
+        * 2.- start this window to delete a -1.png or -1.jpg added before on a new user where "accept" 
button was not pressed and window was closed
+        */
+       private void deleteOldPhotosIfAny(int uniqueID)
+       {
+               LogB.Information("deleteOldPhotosIfAny: " + 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=
+                       new Gtk.FileChooserDialog(Catalog.GetString("Select file"),
+                                       person_win,
+                                       FileChooserAction.Open,
+                                       Catalog.GetString("Cancel"),ResponseType.Cancel,
+                                       Catalog.GetString("Accept"),ResponseType.Accept
+                                       );
+
+               fc.Filter = new FileFilter();
+               fc.Filter.AddPattern("*.png");
+               fc.Filter.AddPattern("*.PNG");
+               fc.Filter.AddPattern("*.jpg");
+               fc.Filter.AddPattern("*.JPG");
+               fc.Filter.AddPattern("*.jpeg");
+               fc.Filter.AddPattern("*.JPEG");
+
+               if (fc.Run() == (int)ResponseType.Accept)
+               {
+                       bool originalCopySuccess = false;
+                       try {
+                               deleteOldPhotosIfAny(currentPerson.UniqueID);
+                               if(UtilMultimedia.GetImageType(fc.Filename) == UtilMultimedia.ImageTypes.JPEG)
+                               {
+                                       File.Copy(fc.Filename, Util.GetPhotoFileName(false, 
currentPerson.UniqueID), true); //overwrite
+                                       originalCopySuccess = true;
+                               }
+                               else if(UtilMultimedia.GetImageType(fc.Filename) == 
UtilMultimedia.ImageTypes.PNG)
+                               {
+                                       File.Copy(fc.Filename, Util.GetPhotoPngFileName(false, 
currentPerson.UniqueID), true); //overwrite
+                                       originalCopySuccess = true;
+                               }
+                       }
+                       catch {
+                               LogB.Warning("Catched! photo cannot be added");
+                               new DialogMessage(Constants.MessageTypes.WARNING, string.Format(
+                                                       Catalog.GetString("Cannot save file {0} "), 
fc.Filename));
+                       }
+
+                       if(originalCopySuccess)
+                       {
+                               //mini will be always png from now on (after 1.7.1-213)
+                               string filenameMini = Util.GetPhotoPngFileName(true, currentPerson.UniqueID);
+                               bool miniSuccess = UtilMultimedia.LoadAndResizeImage(fc.Filename, 
filenameMini, 150, 150);
+
+                               if(miniSuccess)
+                               {
+                                       Pixbuf pixbuf = new Pixbuf (filenameMini);
+                                       image_photo_mini.Pixbuf = pixbuf;
+                                       button_add_photo_file.Label = Catalog.GetString("Change photo");
+                                       button_zoom.Sensitive = true;
+                               }
+                       }
+               }
+               //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
+               fc.Destroy();
+       }
+
        Gtk.Window capturerWindow;
        CapturerBin capturer;
        void on_button_take_photo_clicked (object o, EventArgs args) 
@@ -980,7 +1063,10 @@ public class PersonAddModifyWindow
                capturer.Run();
        }
 
-       private void on_snapshot_done(Pixbuf pixbuf) {
+       //libCesarplayer method, jpeg
+       private void on_snapshot_done(Pixbuf pixbuf)
+       {
+               deleteOldPhotosIfAny(currentPerson.UniqueID);
                string fileName = Path.Combine(Path.GetTempPath(), Constants.PhotoTemp +
                                Util.GetMultimediaExtension(Constants.MultimediaItems.PHOTO));
                
@@ -993,7 +1079,10 @@ public class PersonAddModifyWindow
                button_zoom.Sensitive = true;
        }
 
-       private void on_snapshot_mini_done(Pixbuf pixbuf) {
+       //libCesarplayer method, jpeg
+       private void on_snapshot_mini_done(Pixbuf pixbuf)
+       {
+               deleteOldPhotosIfAny(currentPerson.UniqueID);
                string tempSmallFileName = Path.Combine(Path.GetTempPath(), Constants.PhotoSmallTemp +
                                Util.GetMultimediaExtension(Constants.MultimediaItems.PHOTO));
                
@@ -1079,10 +1168,10 @@ public class PersonAddModifyWindow
        
        static public PersonAddModifyWindow Show (Gtk.Window parent, 
                        Session mySession, Person currentPerson, int pDN, 
-                       Gtk.CheckButton app1_checkbutton_video, bool showPhotoStuff)
+                       Gtk.CheckButton app1_checkbutton_video, bool showCapturePhoto)
        {
                if (PersonAddModifyWindowBox == null) {
-                       PersonAddModifyWindowBox = new PersonAddModifyWindow (parent, mySession, 
currentPerson, showPhotoStuff);
+                       PersonAddModifyWindowBox = new PersonAddModifyWindow (parent, mySession, 
currentPerson, showCapturePhoto);
                }
 
                PersonAddModifyWindowBox.pDN = pDN;
@@ -1640,6 +1729,25 @@ public class PersonAddModifyWindow
                                        Util.FetchID(UtilGtk.ComboGetActive(combo_levels)),
                                        textview_ps_comments.Buffer.Text, false); //dbconOpened
                        LogB.Information("inserted both");
+
+                       //if we added photo while creating, filename is -1.png or -1.png, change name
+                       string photo = Util.UserPhotoURL(false, -1);
+                       if(photo != "")
+                       {
+                               if(UtilMultimedia.GetImageType(photo) == UtilMultimedia.ImageTypes.JPEG)
+                                       File.Move(photo, Util.GetPhotoFileName(false, 
currentPerson.UniqueID));
+                               else if(UtilMultimedia.GetImageType(photo) == UtilMultimedia.ImageTypes.PNG)
+                                       File.Move(photo, Util.GetPhotoPngFileName(false, 
currentPerson.UniqueID));
+                       }
+                       photo = Util.UserPhotoURL(true, -1);
+                       if(photo != "")
+                       {
+                               if(UtilMultimedia.GetImageType(photo) == UtilMultimedia.ImageTypes.JPEG)
+                                       File.Move(photo, Util.GetPhotoFileName(true, currentPerson.UniqueID));
+                               else if(UtilMultimedia.GetImageType(photo) == UtilMultimedia.ImageTypes.PNG)
+                                       File.Move(photo, Util.GetPhotoPngFileName(true, 
currentPerson.UniqueID));
+                       }
+
                } else {
                        //here we update rows in the database
                        currentPerson = new Person (currentPerson.UniqueID, personName, sex, dateTime,
diff --git a/src/gui/personSelect.cs b/src/gui/personSelect.cs
index 47a337b..85290d1 100644
--- a/src/gui/personSelect.cs
+++ b/src/gui/personSelect.cs
@@ -241,7 +241,7 @@ public class PersonPhotoButton
                Gtk.VBox vbox = new Gtk.VBox();
 
                Gtk.Image image = new Gtk.Image();
-               string photoFile = Util.GetPhotoFileName(true, p.UniqueID);
+               string photoFile = Util.UserPhotoURL(true, p.UniqueID);
                if(photoFile != "" && File.Exists(photoFile)) {
                        try {
                                Pixbuf pixbuf = new Pixbuf (photoFile); //from a file
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index af02220..de5e074 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -363,10 +363,10 @@ class SqlitePersonSession : Sqlite
                        Delete(true, Constants.PersonTable, Convert.ToInt32(personID));
 
                        //delete photos if any
-                       if(File.Exists(Util.GetPhotoFileName(false, Convert.ToInt32(personID))))
-                               File.Delete(Util.GetPhotoFileName(false, Convert.ToInt32(personID)));
-                       if(File.Exists(Util.GetPhotoFileName(true, Convert.ToInt32(personID))))
-                               File.Delete(Util.GetPhotoFileName(true, Convert.ToInt32(personID)));
+                       if(File.Exists(Util.UserPhotoURL(false, Convert.ToInt32(personID))))
+                               File.Delete(Util.UserPhotoURL(false, Convert.ToInt32(personID)));
+                       if(File.Exists(Util.UserPhotoURL(true, Convert.ToInt32(personID))))
+                               File.Delete(Util.UserPhotoURL(true, Convert.ToInt32(personID)));
                }
 
                //3.- Delete tests
diff --git a/src/util.cs b/src/util.cs
index cd13963..7f1a9a2 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -991,12 +991,39 @@ public class Util
        public static string GetVideoFileNameOnlyFolder (int sessionID) {
                return GetVideoSessionDir(sessionID);
        }
+
+       /*
+        * --------------------- GetPhoto stuff
+        */
+       //returns the jpg, png or ""
+       public static string UserPhotoURL (bool small, int uniqueID)
+       {
+               string jpeg = GetPhotoFileName (small, uniqueID);
+               if(File.Exists(jpeg))
+                       return jpeg;
+
+               string png = GetPhotoPngFileName (small, uniqueID);
+               if(File.Exists(png))
+                       return png;
+
+               return "";
+       }
        
+       //jpg
        public static string GetPhotoFileName (bool small, int uniqueID) {
                return GetPhotosDir(small) + Path.DirectorySeparatorChar + uniqueID.ToString() +
                        GetMultimediaExtension(Constants.MultimediaItems.PHOTO);
        }
-       
+       //png
+       public static string GetPhotoPngFileName (bool small, int uniqueID) {
+               return GetPhotosDir(small) + Path.DirectorySeparatorChar + uniqueID.ToString() +
+                       GetMultimediaExtension(Constants.MultimediaItems.PHOTOPNG);
+       }
+
+       /*
+        * --------------------- End of GetPhoto stuff
+        */
+
        public static string GetVideoTempFileName() {
                return Path.Combine(
                                Path.GetTempPath(), Constants.VideoTemp + 
@@ -1012,11 +1039,23 @@ public class Util
                                Path.GetTempPath(), fileName + 
GetMultimediaExtension(Constants.MultimediaItems.PHOTO));
        }
        
+       public static string GetMultimediaExtension (string filename)
+       {
+               if(UtilMultimedia.GetImageType(filename) == UtilMultimedia.ImageTypes.JPEG)
+                       return Constants.ExtensionPhoto;
+               if(UtilMultimedia.GetImageType(filename) == UtilMultimedia.ImageTypes.PNG)
+                       return Constants.ExtensionPhotoPng;
+
+               return "";
+       }
+
        public static string GetMultimediaExtension (Constants.MultimediaItems multimediaItem) {
                if(multimediaItem == Constants.MultimediaItems.VIDEO)
                        return Constants.ExtensionVideo;
-               else //multimediaItem = Constants.MultimediaItems.PHOTO
+               else if(multimediaItem == Constants.MultimediaItems.PHOTO)
                        return Constants.ExtensionPhoto;
+               else //multimediaItem == Constants.MultimediaItems.PHOTOPNG
+                       return Constants.ExtensionPhotoPng;
        }
                        
        public static bool CopyTempVideo(int sessionID, Constants.TestTypes type, int uniqueID) {
diff --git a/src/utilMultimedia.cs b/src/utilMultimedia.cs
index 3905997..2555450 100644
--- a/src/utilMultimedia.cs
+++ b/src/utilMultimedia.cs
@@ -50,8 +50,8 @@ public class UtilMultimedia
         * IMAGES
         */
 
-       private enum ImageTypes { UNKNOWN, PNG, JPEG }
-       private static ImageTypes getImageType(string filename)
+       public enum ImageTypes { UNKNOWN, PNG, JPEG }
+       public static ImageTypes GetImageType(string filename)
        {
                if(filename.ToLower().EndsWith("jpeg") || filename.ToLower().EndsWith("jpg"))
                        return ImageTypes.JPEG;
@@ -61,34 +61,35 @@ public class UtilMultimedia
                return ImageTypes.UNKNOWN;
        }
 
-       public static void ResizeImages()
+       public static void ResizeImageTests()
        {
                string file1 = "/home/xavier/Imatges/tenerife.png";
                string file2 = "/home/xavier/Imatges/2016-06-07-152244.jpg";
                string file3 = "/home/xavier/Imatges/humor-desmotivaciones-ofender-lasers.jpeg";
 
-               resizeImage(file1, "/home/xavier/Imatges/prova1.png", 100, 150);
-               resizeImage(file2, "/home/xavier/Imatges/prova2.png", 200, 200);
-               resizeImage(file3, "/home/xavier/Imatges/prova3.png", 400, 350);
+               LoadAndResizeImage(file1, "/home/xavier/Imatges/prova1.png", 100, 150);
+               LoadAndResizeImage(file2, "/home/xavier/Imatges/prova2.png", 200, 200);
+               LoadAndResizeImage(file3, "/home/xavier/Imatges/prova3.png", 400, 350);
        }
        
-       private static void resizeImage(string filenameOriginal, string filenameDest, int width, int height)
+       public static bool LoadAndResizeImage(string filenameOriginal, string filenameDest, int width, int 
height)
        {
                ImageSurface imgSurface;
-               if(getImageType(filenameOriginal) == ImageTypes.PNG)
+               if(GetImageType(filenameOriginal) == ImageTypes.PNG)
                {
                        imgSurface = LoadPngToCairoImageSurface(filenameOriginal);
                }
-               else if(getImageType(filenameOriginal) == ImageTypes.JPEG)
+               else if(GetImageType(filenameOriginal) == ImageTypes.JPEG)
                {
                        imgSurface = LoadJpegToCairoImageSurface(filenameOriginal);
                }
-               else //(getImageType(filenameOriginal) == ImageTypes.UNKNOWN)
+               else //(GetImageType(filenameOriginal) == ImageTypes.UNKNOWN)
                {
-                       return;
+                       return false;
                }
                
-               ImageSurfaceResize(imgSurface, filenameDest, width, height);
+               bool success = ImageSurfaceResize(imgSurface, filenameDest, width, height);
+               return success;
        }
 
        public static ImageSurface LoadJpegToCairoImageSurface(string jpegFilename)
@@ -123,7 +124,7 @@ public class UtilMultimedia
                return imgSurface;
        }
 
-       public static void ImageSurfaceResize(ImageSurface imgSurface, string filename_dest,
+       public static bool ImageSurfaceResize(ImageSurface imgSurface, string filename_dest,
                        int width, int height)
        {
                Surface surfaceResized = scale_surface(
@@ -134,7 +135,10 @@ public class UtilMultimedia
                        surfaceResized.WriteToPng(filename_dest);
                } catch {
                        LogB.Warning("Catched at ImageFileResize");
+                       return false;
                }
+
+               return true;
        }
 
         // Thanks to: Owen Taylor


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