[chronojump] networks: implemented gui, rfid, on sending email of an image to admin



commit d27fb631eef0d38570eb7bdd01981ef988f080fe
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jan 21 21:03:22 2019 +0100

    networks: implemented gui, rfid, on sending email of an image to admin

 glade/app1.glade    |  96 +++++++++++++++++++++++++-----------------
 src/config.cs       |  10 ++++-
 src/gui/encoder.cs  |  13 ++++++
 src/gui/networks.cs | 117 +++++++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 186 insertions(+), 50 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 1a03f69f..24017dea 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1817,6 +1817,9 @@
                                                             <placeholder/>
                                                             </child>
                                                             <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkLabel" 
id="label_start_selector_jumps">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -19119,42 +19122,6 @@ Concentric</property>
                                                             <placeholder/>
                                                             </child>
                                                             <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkLabel" 
id="label_force_sensor_ai_rfd_a">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -19469,6 +19436,9 @@ Concentric</property>
                                                             <placeholder/>
                                                             </child>
                                                             <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkCheckButton" 
id="checkbutton_force_sensor_ai_b">
                                                             <property name="width_request">30</property>
                                                             <property name="visible">True</property>
@@ -19581,6 +19551,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -27876,6 +27849,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -27967,6 +27943,50 @@ then click this button.</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkButton" 
id="button_encoder_analyze_image_compujump_send_email">
+                                                            <property name="sensitive">False</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <signal name="clicked" 
handler="on_button_encoder_analyze_image_compujump_send_email_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox54">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">4</property>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_encoder_analyze_image_compujump_send_email_image">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_encoder_analyze_image_compujump_send_email_send">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkButton" 
id="button_encoder_analyze_1RM_save">
                                                             <property name="can_focus">True</property>
                                                             <property name="receives_default">True</property>
@@ -28008,7 +28028,7 @@ then click this button.</property>
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">True</property>
-                                                            <property name="position">1</property>
+                                                            <property name="position">2</property>
                                                             </packing>
                                                             </child>
                                                             <child>
@@ -28053,7 +28073,7 @@ then click this button.</property>
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">True</property>
-                                                            <property name="position">2</property>
+                                                            <property name="position">3</property>
                                                             </packing>
                                                             </child>
                                                             </widget>
diff --git a/src/config.cs b/src/config.cs
index faa6467c..094140c0 100644
--- a/src/config.cs
+++ b/src/config.cs
@@ -41,6 +41,7 @@ public class Config
        public string CompujumpServerURL = "";
        public int CompujumpStationID = -1;
        public int CompujumpAdminID = -1; //undefined
+       public string CompujumpAdminEmail = ""; //undefined
        public Constants.Menuitem_modes CompujumpStationMode = Constants.Menuitem_modes.UNDEFINED;
        public string RunScriptOnExit;
        public bool PlaySoundsFromFile;
@@ -91,6 +92,8 @@ public class Config
                                                CompujumpStationID = Convert.ToInt32(parts[1]);
                                        else if(parts[0] == "CompujumpAdminID" && parts[1] != "" && 
Util.IsNumber(parts[1], false))
                                                CompujumpAdminID = Convert.ToInt32(parts[1]);
+                                       else if(parts[0] == "CompujumpAdminEmail" && parts[1] != "")
+                                               CompujumpAdminEmail = parts[1];
                                        else if(parts[0] == "CompujumpStationMode" && 
Enum.IsDefined(typeof(Constants.Menuitem_modes), parts[1]))
                                                CompujumpStationMode = (Constants.Menuitem_modes)
                                                        Enum.Parse(typeof(Constants.Menuitem_modes), 
parts[1]);
@@ -107,12 +110,17 @@ public class Config
        //p is currentPerson
        public bool CompujumpUserIsAdmin(Person p)
        {
-               LogB.Information("CompujumpUserIsAdmin ?");
+               LogB.Information("CompujumpUserIsAdmin ? (person)");
                LogB.Information(string.Format("{0}, {1}", p.UniqueID, CompujumpAdminID));
                LogB.Information(string.Format("{0}, {1}, {2}", p != null, Compujump, p.UniqueID == 
CompujumpAdminID));
 
                return (p != null && Compujump && p.UniqueID == CompujumpAdminID);
        }
+       public bool CompujumpUserIsAdmin(int pID)
+       {
+               LogB.Information("CompujumpUserIsAdmin ? (int)");
+               return (Compujump && pID == CompujumpAdminID);
+       }
 
        /*
        public void Read()
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index a4a8eb68..8e819a45 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -4200,6 +4200,15 @@ public partial class ChronoJumpWindow
                }
        }
 
+       void on_button_encoder_analyze_image_compujump_send_email_clicked (object o, EventArgs args)
+       {
+               if(configChronojump.CompujumpUserIsAdmin(currentPerson))
+                       compujumpSendEmail(Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE);
+               else
+                       if(rfidWaitingAdmin != null)
+                               rfidWaitingAdmin.Start();
+       }
+
        void on_button_encoder_analyze_table_save_clicked (object o, EventArgs args)
        {
                /* file is in:
@@ -4752,6 +4761,7 @@ public partial class ChronoJumpWindow
                image_encoder_analyze.Sensitive = false;
                treeview_encoder_analyze_curves.Sensitive = false;
                button_encoder_analyze_image_save.Sensitive = false;
+               button_encoder_analyze_image_compujump_send_email.Sensitive = false;
                button_encoder_analyze_AB_save.Sensitive = false;
                button_encoder_analyze_table_save.Sensitive = false;
                button_encoder_analyze_1RM_save.Visible = false;
@@ -5914,6 +5924,7 @@ public partial class ChronoJumpWindow
                        encoderButtonsSensitive(encoderSensEnum.PROCESSINGR);
                        treeview_encoder_analyze_curves.Sensitive = false;
                        button_encoder_analyze_image_save.Sensitive = false;
+                       button_encoder_analyze_image_compujump_send_email.Sensitive = false;
                        button_encoder_analyze_AB_save.Sensitive = false;
                        button_encoder_analyze_table_save.Sensitive = false;
                        button_encoder_analyze_1RM_save.Visible = false;
@@ -7006,6 +7017,7 @@ public partial class ChronoJumpWindow
                        image_encoder_analyze.Sensitive = false;
                        treeview_encoder_analyze_curves.Sensitive = false;
                        button_encoder_analyze_image_save.Sensitive = false;
+                       button_encoder_analyze_image_compujump_send_email.Sensitive = false;
                        button_encoder_analyze_AB_save.Sensitive = false;
                        button_encoder_analyze_table_save.Sensitive = false;
                        button_encoder_analyze_1RM_save.Visible = false;
@@ -7104,6 +7116,7 @@ public partial class ChronoJumpWindow
                        treeview_encoder_analyze_curves.Sensitive = true;
                        
                        button_encoder_analyze_image_save.Sensitive = true;
+                       button_encoder_analyze_image_compujump_send_email.Sensitive = true;
                        button_encoder_analyze_AB_save.Sensitive = true;
                        button_encoder_analyze_table_save.Sensitive = true;
                        
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 77e1c096..75f559b1 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -75,6 +75,7 @@ public partial class ChronoJumpWindow
 
        //encoder ...
        [Widget] Gtk.Button button_encoder_monthly_change_current_session;
+       [Widget] Gtk.Button button_encoder_analyze_image_compujump_send_email;
 
        //runsInterval
        [Widget] Gtk.HBox hbox_runs_interval_compujump;
@@ -106,6 +107,8 @@ public partial class ChronoJumpWindow
        //private static CompujumpAutologout compujumpAutologout;
        private CompujumpAutologout compujumpAutologout;
 
+       private static RFIDWaitingAdmin rfidWaitingAdmin;
+
        DialogPersonPopup dialogPersonPopup;
                
        Config configChronojump;
@@ -190,20 +193,25 @@ public partial class ChronoJumpWindow
                                LogB.ThreadStart();
                                threadRFID.Start();
                        }
+
+                       if(configChronojump.CompujumpAdminEmail != "")
+                               button_encoder_analyze_image_compujump_send_email.Visible = true;
                }
 
                configDo();
        }
        private void RFIDStart()
        {
-               LogB.Information("RFID Start");
-               rfid.Start();
                startedRFIDWait = DateTime.MinValue;
+               rfidWaitingAdmin = new RFIDWaitingAdmin();
                LogB.Information("networksRI: " + networksRunIntervalCanChangePersonSQLReady.ToString());
-               //rfid.ChangedEvent += new EventHandler(this.rfidChanged);
+
+               LogB.Information("RFID Start");
+               rfid.Start();
        }
        private void rfidChanged(object sender, EventArgs e)
        {
+               LogB.Information("at rfidChanged");
                /*
                 * TODO: only if we are not in the middle of capture, or in cont mode without repetitions
                 */
@@ -215,11 +223,21 @@ public partial class ChronoJumpWindow
                        {
                                startedRFIDWait = DateTime.Now;
                                LogB.Information("... but we are on the middle of capture");
-                       } else {
-                               capturedRFID = rfid.Captured;
-                               rfidIsDifferent = true;
-
-                               shouldUpdateRFIDGui = true;
+                       }
+                       else {
+                               if(rfidWaitingAdmin != null && rfidWaitingAdmin.Waiting)
+                               {
+                                       LogB.Information("Checking if an email has to be sent");
+                                       Person pLocal = SqlitePerson.SelectByRFID(rfid.Captured);
+                                       if(configChronojump.CompujumpUserIsAdmin(pLocal.UniqueID))
+                                               
compujumpSendEmail(Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE);
+                                       else
+                                               LogB.Information("RFID should be the RFID of AdminID, not 
this: " + rfid.Captured);
+                               } else {
+                                       capturedRFID = rfid.Captured;
+                                       rfidIsDifferent = true;
+                                       shouldUpdateRFIDGui = true;
+                               }
                        }
                }
        }
@@ -488,19 +506,52 @@ public partial class ChronoJumpWindow
                        label_rfid_encoder_wait.Visible = false;
                }
 
-               if(isCompujumpCapturing ())
+               if(isCompujumpCapturing ()) {
+                       Thread.Sleep (100);
                        return true;
+               }
 
                //---- end of checking if we are on the middle of capture.
 
+               //to send email with analyzed image to the admin
+               if(rfidWaitingAdmin != null)
+               {
+                       if(rfidWaitingAdmin.ShowGuiMessage)
+                       {
+                               new DialogMessage(Constants.MessageTypes.INFO,
+                                               "Sent Email to: " + configChronojump.CompujumpAdminEmail);
+                               rfidWaitingAdmin = new RFIDWaitingAdmin();
+                       }
+
+                       if(rfidWaitingAdmin.Waiting)
+                       {
+                               if(rfidWaitingAdmin.RestSeconds() != -1) {
+                                       label_rfid_encoder_wait.Text =
+                                               string.Format("Please, identify with admin ID wristband 
before {0} seconds", rfidWaitingAdmin.RestSeconds());
+                                       label_rfid_encoder_wait.Visible = true;
+                               } else {
+                                       rfidWaitingAdmin = new RFIDWaitingAdmin();
+                                       label_rfid_encoder_wait.Text = "";
+                                       label_rfid_encoder_wait.Visible = false;
+                               }
+                               Thread.Sleep (100);
+                               return true;
+                       } else
+                               label_rfid_encoder_wait.Text = "";
+               }
+
 
                //don't allow this method to be called again until ended
                //Note RFID detection can send many cards (the same) per second
-               if(updatingRFIDGuiStuff)
+               if(updatingRFIDGuiStuff) {
+                       Thread.Sleep (100);
                        return true;
+               }
 
-               if(! shouldUpdateRFIDGui)
+               if(! shouldUpdateRFIDGui) {
+                       Thread.Sleep (100);
                        return true;
+               }
 
                shouldUpdateRFIDGui = false;
                updatingRFIDGuiStuff = true;
@@ -886,6 +937,15 @@ public partial class ChronoJumpWindow
                return(compujumpAutologout.IsCompujumpCapturing());
        }
 
+       private void compujumpSendEmail(Constants.CheckFileOp op)
+       {
+               if(op == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE)
+               {
+                       LogB.Information("Send Email to: " + configChronojump.CompujumpAdminEmail);
+                       rfidWaitingAdmin.ShowGuiMessage = true;
+               }
+       }
+
        /*
         *
         * This code uses a watcher to see changes on a filename
@@ -1188,3 +1248,38 @@ public class CompujumpAutologout
                        return "Logout in\n" + Math.Round(maxTime, 2) + " min.";
        }
 }
+
+//this class manages the wating of admin wristband in tasks like sending an email with the analyze image
+public class RFIDWaitingAdmin
+{
+       public bool Waiting;
+       public bool ShowGuiMessage;
+
+       private static DateTime startedDT; //time to wait ID of the admin to have access to "higher" methods
+       private const int secondsLimit = 5; //5 seconds to use the admin ID
+
+       //constructor
+       public RFIDWaitingAdmin()
+       {
+               Waiting = false;
+               ShowGuiMessage = false;
+               startedDT = DateTime.MinValue;
+               LogB.Information("RFIDWaitingAdmin constructed!");
+       }
+
+       public void Start()
+       {
+               startedDT = DateTime.Now; //start countdown
+               Waiting = true;
+       }
+
+       //we have to capture before this time in seconds
+       public int RestSeconds()
+       {
+               TimeSpan span = DateTime.Now - startedDT;
+               if (Waiting && span.TotalSeconds < secondsLimit)
+                       return Convert.ToInt32(Math.Round(secondsLimit - span.TotalSeconds, 0));
+               else
+                       return -1;
+       }
+}


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