[chronojump] DB:1.97 load last session, load last mode



commit e99d67c268fa73fc6867ee870e610589959e5985
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Aug 4 12:41:57 2020 +0200

    DB:1.97 load last session, load last mode

 glade/app1.glade            |  57 +++++++-------------
 glade/preferences_win.glade | 124 +++++++++++++++++++++++++++++++-------------
 src/gui/app1/chronojump.cs  |  16 ++++++
 src/gui/preferences.cs      |  22 ++++++++
 src/preferences.cs          |   6 +++
 src/sqlite/main.cs          |  14 ++++-
 src/sqlite/preferences.cs   |  29 ++++++++++-
 7 files changed, 192 insertions(+), 76 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 5ebca9d6..88bcb5c0 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -24515,6 +24515,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -27380,18 +27383,6 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">6</property>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_capturing">
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
@@ -27428,6 +27419,18 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_no_capturing">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -35417,6 +35420,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -36383,26 +36389,6 @@ then click this button.</property>
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
                                                             <child>
-                                                            <widget class="GtkHBox" id="hbox48">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            <property name="spacing">12</property>
-                                                            <child>
-                                                            <widget class="GtkCheckButton" 
id="check_session_autoload_at_start">
-                                                            <property name="label" translatable="yes">Load 
last session at start</property>
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">True</property>
-                                                            <property 
name="receives_default">False</property>
-                                                            <property name="active">True</property>
-                                                            <property name="draw_indicator">True</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkButton" 
id="button_menu_session_import">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
@@ -36450,13 +36436,6 @@ then click this button.</property>
                                                             </child>
                                                             </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="position">0</property>
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index 83fb4241..6c693233 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -619,77 +619,131 @@
                     <property name="can_focus">False</property>
                     <property name="spacing">20</property>
                     <child>
-                      <widget class="GtkHBox" id="hbox49">
+                      <widget class="GtkHBox" id="hbox72">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="spacing">8</property>
-                        <child>
-                          <widget class="GtkLabel" id="label127">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="label" translatable="yes">Background color</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
+                        <property name="spacing">30</property>
                         <child>
-                          <widget class="GtkFrame" id="frame16">
+                          <widget class="GtkHBox" id="hbox73">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="label_xalign">0</property>
-                            <property name="shadow_type">in</property>
+                            <property name="spacing">8</property>
                             <child>
-                              <widget class="GtkDrawingArea" id="drawingarea_background_color">
-                                <property name="width_request">40</property>
-                                <property name="height_request">40</property>
+                              <widget class="GtkLabel" id="label127">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Background color</property>
                               </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
                             </child>
                             <child>
-                              <placeholder/>
+                              <widget class="GtkFrame" id="frame16">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label_xalign">0</property>
+                                <property name="shadow_type">in</property>
+                                <child>
+                                  <widget class="GtkDrawingArea" id="drawingarea_background_color">
+                                    <property name="width_request">40</property>
+                                    <property name="height_request">40</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                  </widget>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                  <packing>
+                                    <property name="type">label_item</property>
+                                  </packing>
+                                </child>
+                              </widget>
                               <packing>
-                                <property name="type">label_item</property>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <widget class="GtkButton" id="button_color_choose">
+                                <property name="label" translatable="yes">Choose</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <signal name="clicked" handler="on_button_color_choose_clicked" 
swapped="no"/>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">2</property>
                               </packing>
                             </child>
                           </widget>
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">1</property>
+                            <property name="position">0</property>
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkButton" id="button_color_choose">
-                            <property name="label" translatable="yes">Choose</property>
+                          <widget class="GtkCheckButton" id="check_logo_animated">
+                            <property name="label" translatable="yes">Show animated logo</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <signal name="clicked" handler="on_button_color_choose_clicked" swapped="no"/>
+                            <property name="receives_default">False</property>
+                            <property name="draw_indicator">True</property>
                           </widget>
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">2</property>
+                            <property name="position">1</property>
                           </packing>
                         </child>
                       </widget>
                       <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkCheckButton" id="check_logo_animated">
-                        <property name="label" translatable="yes">Show animated logo</property>
+                      <widget class="GtkHBox" id="hbox49">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="draw_indicator">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">30</property>
+                        <child>
+                          <widget class="GtkCheckButton" id="check_session_autoload_at_start">
+                            <property name="label" translatable="yes">Load last session at start</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="active">True</property>
+                            <property name="draw_indicator">True</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkCheckButton" id="check_mode_autoload_at_start">
+                            <property name="label" translatable="yes">Load last mode at start</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="active">True</property>
+                            <property name="draw_indicator">True</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
                       </widget>
                       <packing>
                         <property name="expand">False</property>
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index e6b6456a..0d405f48 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -744,6 +744,16 @@ public partial class ChronoJumpWindow
                if(! showSendLog && notebook_sup.CurrentPage == Convert.ToInt32(notebook_sup_pages.START))
                        new ChronojumpLogo (drawingarea_chronojump_logo, viewport_chronojump_logo, 
preferences.logoAnimatedShow);
 
+               //TODO: only if not networks
+               if(preferences.loadLastSessionAtStart && preferences.lastSessionID > 0)
+               {
+                       currentSession = SqliteSession.Select (preferences.lastSessionID.ToString());
+                       on_load_session_accepted();
+               }
+               //TODO: only if not networks
+               if(preferences.loadLastModeAtStart && preferences.lastMode != 
Constants.Menuitem_modes.UNDEFINED)
+                       changeMode(preferences.lastMode);
+
                LogB.Information("Chronojump window started");
        }
 
@@ -2514,6 +2524,8 @@ public partial class ChronoJumpWindow
                //feedback (more in 1st session created)
                string feedbackLoadUsers = Catalog.GetString ("Session created, now add or load persons.");
                new DialogMessage(Constants.MessageTypes.INFO, feedbackLoadUsers);
+
+               SqlitePreferences.Update(SqlitePreferences.LastSessionID, currentSession.UniqueID.ToString(), 
false);
        }
        
        private void on_edit_session_activate (object o, EventArgs args) 
@@ -2615,6 +2627,8 @@ public partial class ChronoJumpWindow
                        reportWin.FillTreeView();
 
                chronojumpWindowTestsNext();
+
+               SqlitePreferences.Update(SqlitePreferences.LastSessionID, currentSession.UniqueID.ToString(), 
false);
        }
        
        private void closeSession()
@@ -3292,6 +3306,8 @@ public partial class ChronoJumpWindow
 
                last_menuitem_mode_defined = true;
 
+               SqlitePreferences.Update(SqlitePreferences.LastMode, m.ToString(), false);
+
                chronopicRegisterUpdate(false);
 
                chronojumpWindowTestsNext();
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index c9e08086..b915cd31 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -72,6 +72,9 @@ public class PreferencesWindow
        [Widget] Gtk.Label label_recommended_undecorated;
        [Widget] Gtk.DrawingArea drawingarea_background_color;
        [Widget] Gtk.CheckButton check_logo_animated;
+       [Widget] Gtk.CheckButton check_session_autoload_at_start;
+       [Widget] Gtk.CheckButton check_mode_autoload_at_start;
+
 
        //jumps tab     
        [Widget] Gtk.CheckButton checkbutton_power;
@@ -382,6 +385,16 @@ public class PreferencesWindow
                else
                        PreferencesWindowBox.check_logo_animated.Active = false;
 
+               if(preferences.loadLastSessionAtStart)
+                       PreferencesWindowBox.check_session_autoload_at_start.Active = true;
+               else
+                       PreferencesWindowBox.check_session_autoload_at_start.Active = false;
+
+               if(preferences.loadLastModeAtStart)
+                       PreferencesWindowBox.check_mode_autoload_at_start.Active = true;
+               else
+                       PreferencesWindowBox.check_mode_autoload_at_start.Active = false;
+
                //multimedia tab
                if(preferences.volumeOn)  
                        PreferencesWindowBox.checkbutton_volume.Active = true; 
@@ -1643,6 +1656,15 @@ public class PreferencesWindow
                                SqlitePreferences.LogoAnimatedShow, preferences.logoAnimatedShow,
                                PreferencesWindowBox.check_logo_animated.Active);
 
+               preferences.loadLastSessionAtStart = Preferences.PreferencesChange(
+                               SqlitePreferences.LoadLastSessionAtStart, preferences.loadLastSessionAtStart,
+                               PreferencesWindowBox.check_session_autoload_at_start.Active);
+
+               preferences.loadLastModeAtStart = Preferences.PreferencesChange(
+                               SqlitePreferences.LoadLastModeAtStart, preferences.loadLastModeAtStart,
+                               PreferencesWindowBox.check_mode_autoload_at_start.Active);
+
+
                if( preferences.digitsNumber != Convert.ToInt32(UtilGtk.ComboGetActive(combo_decimals)) ) {
                        SqlitePreferences.Update("digitsNumber", UtilGtk.ComboGetActive(combo_decimals), 
true);
                        preferences.digitsNumber = Convert.ToInt32(UtilGtk.ComboGetActive(combo_decimals));
diff --git a/src/preferences.cs b/src/preferences.cs
index f1a1b8a9..7e36c0ba 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -230,6 +230,12 @@ public class Preferences
 
        public bool debugMode;
 
+       //session
+       public bool loadLastSessionAtStart;
+       public int lastSessionID;
+       public bool loadLastModeAtStart;
+       public Constants.Menuitem_modes lastMode;
+
        /*
         * these are unused on SqlitePreferences.SelectAll
         */
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index ffa14014..958001af 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -129,7 +129,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "1.96";
+       static string lastChronojumpDatabaseVersion = "1.97";
 
        public Sqlite()
        {
@@ -2737,6 +2737,17 @@ class Sqlite
 
                                currentVersion = updateVersion("1.96");
                        }
+                       if(currentVersion == "1.96")
+                       {
+                               LogB.SQL("Inserted into preferences: loadLastSessionAtStart, lastSessionID, 
loadLastModeAtStart, lastMode");
+
+                               SqlitePreferences.Insert (SqlitePreferences.LoadLastSessionAtStart, "True");
+                               SqlitePreferences.Insert (SqlitePreferences.LastSessionID, "-1");
+                               SqlitePreferences.Insert (SqlitePreferences.LoadLastModeAtStart, "True");
+                               SqlitePreferences.Insert (SqlitePreferences.LastMode, 
Constants.Menuitem_modes.UNDEFINED.ToString());
+
+                               currentVersion = updateVersion("1.97");
+                       }
 
                        /*
                        if(currentVersion == "1.79")
@@ -2952,6 +2963,7 @@ class Sqlite
 //just testing: 1.79 - 1.80 Converted DB to 1.80 Created table ForceSensorElasticBandGlue and moved 
stiffnessString records there
 
 
+               //1.96 - 1.97 Converted DB to 1.97 Inserted into preferences: loadLastSessionAtStart, 
lastSessionID, loadLastModAtStart, lastMode
                //1.95 - 1.96 Converted DB to 1.96 Inserted into preferences: jumpsFVProfileOnlyBestInWeight, 
jumpsFVProfileShowFullGraph, jumpsEvolutionOnlyBestInSession
                //1.94 - 1.95 Converted DB to 1.95 Inserted into preferences: importerPythonVersion
                //1.93 - 1.94 Converted DB to 1.94 Inserted into preferences: 
RunEncoderAnalyzeAccel/Force/Power
diff --git a/src/sqlite/preferences.cs b/src/sqlite/preferences.cs
index 82625c0a..c1204559 100644
--- a/src/sqlite/preferences.cs
+++ b/src/sqlite/preferences.cs
@@ -96,6 +96,12 @@ class SqlitePreferences : Sqlite
        //advanced
        public const string ImporterPythonVersion = "importerPythonVersion";
 
+       //session
+       public const string LoadLastSessionAtStart = "loadLastSessionAtStart";
+       public const string LastSessionID = "lastSessionID";
+       public const string LoadLastModeAtStart = "loadLastModeAtStart";
+       public const string LastMode = "lastMode";
+
        protected internal static new void createTable()
        {
                dbcmd.CommandText = 
@@ -292,7 +298,12 @@ class SqlitePreferences : Sqlite
                                Insert ("muteLogs", "False", dbcmdTr);
                                Insert (ImporterPythonVersion, 
Preferences.pythonVersionEnum.Python.ToString(), dbcmdTr);
 
-                               
+                               //session
+                               Insert (LoadLastSessionAtStart, "True", dbcmdTr);
+                               Insert (LastSessionID, "-1", dbcmdTr);
+                               Insert (LoadLastModeAtStart, "True", dbcmdTr);
+                               Insert (LastMode, Constants.Menuitem_modes.UNDEFINED.ToString(), dbcmdTr);
+
                                //removed on 1.37
                                //Insert ("encoderConfiguration", new 
EncoderConfiguration().ToStringOutput(EncoderConfiguration.Outputs.SQL), dbcmdTr);
 
@@ -672,6 +683,22 @@ class SqlitePreferences : Sqlite
                                        Enum.Parse(typeof(Preferences.pythonVersionEnum), 
reader[1].ToString());
                        else if(reader[0].ToString() == "databaseVersion")
                                preferences.databaseVersion = reader[1].ToString();
+
+                       //session
+                       else if(reader[0].ToString() == LoadLastSessionAtStart)
+                               preferences.loadLastSessionAtStart = reader[1].ToString() == "True";
+                       else if(reader[0].ToString() == LastSessionID)
+                       {
+                               if(Util.IsNumber(reader[1].ToString(), false))
+                                       preferences.lastSessionID = Convert.ToInt32(reader[1].ToString());
+                               else
+                                       preferences.lastSessionID = -1;
+                       }
+                       else if(reader[0].ToString() == LoadLastModeAtStart)
+                               preferences.loadLastModeAtStart = reader[1].ToString() == "True";
+                       else if(reader[0].ToString() == LastMode)
+                               preferences.lastMode = (Constants.Menuitem_modes)
+                                       Enum.Parse(typeof(Constants.Menuitem_modes), reader[1].ToString());
                }
 
                reader.Close();


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