[chronojump] Doing chronojump_config



commit bfd2c9e90a22874bc7da13078694e85fd18575f9
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jun 8 19:55:56 2015 +0200

    Doing chronojump_config

 chronojump_config.txt |   31 +++++++++++--
 src/constants.cs      |    2 +
 src/gui/chronojump.cs |    6 +--
 src/gui/encoder.cs    |    2 +-
 src/gui/networks.cs   |  116 ++++++++++++++++++++++++++++++++++++------------
 src/gui/person.cs     |   14 +++---
 src/util.cs           |   10 +---
 src/utilAll.cs        |    5 ++
 8 files changed, 134 insertions(+), 52 deletions(-)
---
diff --git a/chronojump_config.txt b/chronojump_config.txt
index 38e0a9f..44691f5 100644
--- a/chronojump_config.txt
+++ b/chronojump_config.txt
@@ -1,16 +1,39 @@
+# 1 ------- HELP -------
+
 #Comments start with sharp sign
 #Options are key/values with an = separating them
 #DO NOT write comments in the same line than key/value pairs
+#DO NOT WRITE SPACES BEFORE OR AFTER THE '=' SIGN
 #Whitelines are allowed
 #This file is in .local/share/Chronojump (on Linux)
 
-Maximized=True
+#Recommendations for Raspberry 2
+#Maximized=TRUE
+#CustomButtons=TRUE
+#UseVideo=FALSE
+#AutodetectPort=ACTIVE
+#RunScriptOnExit=
+
+#Recommendations for PIPO tablet (Windows)
+#Maximized=TRUE
+#CustomButtons=TRUE
+#UseVideo=TRUE
+#AutodetectPort=DISCARDFIRST
+#RunScriptOnExit=
+
+# 2 ------- OPTIONS -------
+
+Maximized=TRUE
 
 #Bigger / different buttons at some parts
-CustomButtons=True
+CustomButtons=TRUE
+
+#To disable video on Raspberry change to FALSE
+UseVideo=TRUE
 
-#PIPO table has COM1 and COM5, this is for trying COM5, because at COM1 it doesn't work
-Port=COM5
+#options are ACTIVE, DISCARDFIRST and INACTIVE
+#PIPO windows tablet has COM1 and usually COM5. At COM1 it doesn't work, use DISCARDFIRST to use the other
+AutodetectPort=DISCARDFIRST
 
 #To sync data
 RunScriptOnExit=
diff --git a/src/constants.cs b/src/constants.cs
index a79c2ab..06863f3 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -437,6 +437,8 @@ public class Constants
        public static string FileNameLog = "log_chronojump.txt";
        public static string FileNameLogOld = "log_chronojump_old.txt";
        
+       public static string FileNameConfig = "chronojump_config.txt";
+       
        //30 colors defined
        //see als UtilGtk that's not used by the server
        public static string [] Colors = {
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 169aa04..bf05009 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2616,8 +2616,7 @@ public partial class ChronoJumpWindow
        private void on_person_add_single_activate (object o, EventArgs args) {
                personAddModifyWin = PersonAddModifyWindow.Show(app1, 
                                currentSession, new Person(-1), 
-                               preferences.digitsNumber, checkbutton_video,
-                               (linuxType == linuxTypeEnum.RASPBERRY || linuxType == linuxTypeEnum.NETWORKS)
+                               preferences.digitsNumber, checkbutton_video, useVideo
                                );
                //-1 means we are adding a new person
                //if we were modifying it will be it's uniqueID
@@ -2701,8 +2700,7 @@ public partial class ChronoJumpWindow
                LogB.Information("modify person");
 
                personAddModifyWin = PersonAddModifyWindow.Show(app1, currentSession, currentPerson, 
-                               preferences.digitsNumber, checkbutton_video,
-                               (linuxType == linuxTypeEnum.RASPBERRY || linuxType == linuxTypeEnum.NETWORKS)
+                               preferences.digitsNumber, checkbutton_video, useVideo
                                ); 
                personAddModifyWin.FakeButtonAccept.Clicked += new 
EventHandler(on_edit_current_person_accepted);
        }
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index f39c904..6aae1e6 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -348,7 +348,7 @@ public partial class ChronoJumpWindow
                //done here because in Glade we cannot use the TextBuffer.Changed
                textview_encoder_signal_comment.Buffer.Changed += new 
EventHandler(on_textview_encoder_signal_comment_key_press_event);
 
-               raspberryOrNetworksInit();
+               configInit();
        
                array1RM = new ArrayList();
        }
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index e178d72..43d963c 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -39,38 +39,34 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Box hbox_encoder_capture_extra_mass_no_raspberry;
        [Widget] Gtk.Box hbox_encoder_capture_extra_mass_raspberry;
 
-
+       private bool useVideo = true;
        private enum linuxTypeEnum { NOTLINUX, LINUX, RASPBERRY, NETWORKS }
        private linuxTypeEnum linuxType;
-       
-       //networks is a raspberry connected to the server       
-       private static linuxTypeEnum getLinuxTypes() 
+
+
+       private void configInit() 
        {
-               if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX) 
-               {
-                       if(Util.FileExists(Util.GetChronojumpNetworksFile()))
-                               return(linuxTypeEnum.NETWORKS);
-                       else if(Util.FileExists(Util.GetChronojumpRaspberryFile()))
-                               return(linuxTypeEnum.RASPBERRY);
-                       else
-                               return(linuxTypeEnum.LINUX);
-               }
-               return(linuxTypeEnum.NOTLINUX);
-       }
+               //trying new Config class
+               Config config = new Config();
+               config.Read();
+               LogB.Information("Config:\n" + config.ToString());
 
-       
-       private void raspberryOrNetworksInit() {
-               linuxType = getLinuxTypes();
-       
-               if(linuxType == linuxTypeEnum.RASPBERRY || linuxType == linuxTypeEnum.NETWORKS) 
-               {
+               if(config.Maximized)
+                       app1.Maximize();
+               if(config.CustomButtons) {
                        hbox_encoder_capture_extra_mass_no_raspberry.Visible = false;
                        hbox_encoder_capture_extra_mass_raspberry.Visible = true;
-
+               }
+               if(! config.UseVideo) {
+                       useVideo = false;
                        alignment_video_encoder.Visible = false;
-                       //TODO: put the no connect video here.
                }
 
+               //TODO
+               //AutodetectPort
+               //RunScriptOnExit
+
+               /*
                if(linuxType == linuxTypeEnum.NETWORKS) {
                        //mostrar directament el power
                        select_menuitem_mode_toggled(menuitem_modes.POWER);
@@ -91,12 +87,7 @@ public partial class ChronoJumpWindow
                        hbox_encoder_sup_capture_analyze.Sensitive = true;
                        notebook_encoder_sup.Sensitive = false;
                }
-
-               //si es rapsberry o si es networks cal desactivar camera
-               
-               //maximize now, at the end of tweaks
-               if(linuxType == linuxTypeEnum.RASPBERRY || linuxType == linuxTypeEnum.NETWORKS)
-                       app1.Maximize();
+               */
        }
 
        //rfid
@@ -112,3 +103,70 @@ public partial class ChronoJumpWindow
        }
 
 }
+
+public class Config
+{
+       public enum AutodetectPortEnum { ACTIVE, DISCARDFIRST, INACTIVE }
+
+       public bool Maximized;
+       public bool CustomButtons;
+       public bool UseVideo;
+       public AutodetectPortEnum AutodetectPort;
+       public string RunScriptOnExit;
+
+       public Config()
+       {
+               Maximized = false;
+               CustomButtons = false;
+               UseVideo = true;
+               AutodetectPort = AutodetectPortEnum.ACTIVE;
+               RunScriptOnExit = "";
+       }
+
+       public void Read()
+       {
+               string contents = Util.ReadFile(UtilAll.GetConfigFileName(), false);
+               if (contents != null && contents != "") 
+               {
+                       string line;
+                       using (StringReader reader = new StringReader (contents)) {
+                               do {
+                                       line = reader.ReadLine ();
+
+                                       if (line == null)
+                                               break;
+                                       if (line == "" || line[0] == '#')
+                                               continue;
+
+                                       string [] parts = line.Split(new char[] {'='});
+                                       if(parts.Length != 2)
+                                               continue;
+
+                                       if(parts[0] == "Maximized" && Util.StringToBool(parts[1]))
+                                               Maximized = true;
+                                       else if(parts[0] == "CustomButtons" && Util.StringToBool(parts[1]))
+                                               CustomButtons = true;
+                                       else if(parts[0] == "UseVideo" && ! Util.StringToBool(parts[1]))
+                                               UseVideo = false;
+                                       else if(parts[0] == "AutodetectPort" && 
Enum.IsDefined(typeof(AutodetectPortEnum), parts[1]))
+                                               AutodetectPort = (AutodetectPortEnum) 
+                                                       Enum.Parse(typeof(AutodetectPortEnum), parts[1]);
+                                       else if(parts[0] == "RunScriptOnExit" && parts[1] != "")
+                                               RunScriptOnExit = parts[1];
+                               } while(true);
+                       }
+               }
+       }
+
+       public override string ToString() {
+               return(
+                               "Maximized = " + Maximized.ToString() + "\n" +
+                               "CustomButtons = " + CustomButtons.ToString() + "\n" +
+                               "UseVideo = " + UseVideo.ToString() + "\n" +
+                               "AutodetectPort = " + AutodetectPort.ToString() + "\n" +
+                               "RunScriptOnExit = " + RunScriptOnExit.ToString() + "\n"
+                     );
+       }
+
+       ~Config() {}
+}
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 044bfd0..9a2615e 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -878,8 +878,8 @@ 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
-       //hidePhotoStuff is true on raspberry to not use camera
-       PersonAddModifyWindow (Gtk.Window parent, Session currentSession, Person currentPerson, bool 
hidePhotoStuff) {
+       //showPhotoStuff is false on raspberry to not use camera
+       PersonAddModifyWindow (Gtk.Window parent, Session currentSession, Person currentPerson, bool 
showPhotoStuff) {
                Glade.XML gladeXML;
                gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "chronojump.glade", "person_win", 
null);
                gladeXML.Autoconnect(this);
@@ -911,9 +911,7 @@ public class PersonAddModifyWindow
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + Constants.FileNameZoomInIcon);
                image_zoom.Pixbuf = pixbuf;
 
-               if(hidePhotoStuff)
-                       vbox_photo.Visible = false;
-               else {
+               if(showPhotoStuff) {
                        string photoFile = Util.GetPhotoFileName(true, currentPerson.UniqueID);
                        if(File.Exists(photoFile)) {
                                try {
@@ -934,6 +932,8 @@ public class PersonAddModifyWindow
                        else
                                button_zoom.Sensitive = false;
                }
+               else
+                       vbox_photo.Visible = false;
                        
                fakeButtonAccept = new Gtk.Button();
 
@@ -1097,10 +1097,10 @@ public class PersonAddModifyWindow
        
        static public PersonAddModifyWindow Show (Gtk.Window parent, 
                        Session mySession, Person currentPerson, int pDN, 
-                       Gtk.CheckButton app1_checkbutton_video, bool hidePhotoStuff)
+                       Gtk.CheckButton app1_checkbutton_video, bool showPhotoStuff)
        {
                if (PersonAddModifyWindowBox == null) {
-                       PersonAddModifyWindowBox = new PersonAddModifyWindow (parent, mySession, 
currentPerson, hidePhotoStuff);
+                       PersonAddModifyWindowBox = new PersonAddModifyWindow (parent, mySession, 
currentPerson, showPhotoStuff);
                }
 
                PersonAddModifyWindowBox.pDN = pDN;
diff --git a/src/util.cs b/src/util.cs
index 93d4613..8e03113 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -804,18 +804,14 @@ public class Util
        }
 
        /********** end of database paths ************/
-       
+
+       /*      
        public static string GetChronojumpNetworksFile() {
                return Path.Combine(
                                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                "Chronojump" + Path.DirectorySeparatorChar + "chronojump_networks.txt");
        }
-       public static string GetChronojumpRaspberryFile() {
-               return Path.Combine(
-                               Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
-                               "Chronojump" + Path.DirectorySeparatorChar + "chronojump_raspberry.txt");
-       }
-       
+       */
        
 
        /********** start of multimedia paths ************/
diff --git a/src/utilAll.cs b/src/utilAll.cs
index 3b2b768..722531b 100644
--- a/src/utilAll.cs
+++ b/src/utilAll.cs
@@ -100,6 +100,11 @@ public class UtilAll
                                "Chronojump");
        }
        
+       public static string GetConfigFileName() {
+               return Path.Combine(GetApplicationDataDir() +  Path.DirectorySeparatorChar + 
Constants.FileNameConfig);
+       }
+       
+       
        public static string DetectPortsLinux(bool formatting) {
                string startStr = "";
                string midStr = "\n";


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