[chronojump/michrolab] user change database: better config and gui done



commit 72a1e258c4e201dcd7c1137a1386983f068dbfb4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jun 8 22:11:56 2022 +0200

    user change database: better config and gui done

 glade/app1.glade           | 141 ++++++++++++++++++++++++++++++++++++++++++---
 src/config.cs              |   3 +
 src/gui/app1/chronojump.cs |   2 +
 src/gui/app1/menu.cs       |   5 ++
 src/gui/app1/menu_tiny.cs  |   2 +
 src/gui/networks.cs        |  62 ++++++++++++++++----
 6 files changed, 196 insertions(+), 19 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 1b648a089..cc7086361 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -46,6 +46,32 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
                                     <property name="spacing">20</property>
+                                    <child>
+                                      <widget class="GtkButton" id="button_menu_database">
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">True</property>
+                                        <property name="tooltip" translatable="yes">Database</property>
+                                        <signal name="clicked" handler="on_button_database_change_clicked" 
swapped="no"/>
+                                        <child>
+                                          <widget class="GtkEventBox" id="eventbox_button_menu_database">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <child>
+                                              <widget class="GtkLabel" id="label275">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="label">DB</property>
+                                              </widget>
+                                            </child>
+                                          </widget>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
                                     <child>
                                       <widget class="GtkVBox" id="vbox_menu_session1">
                                         <property name="visible">True</property>
@@ -239,7 +265,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">0</property>
+                                        <property name="position">1</property>
                                       </packing>
                                     </child>
                                     <child>
@@ -266,7 +292,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">1</property>
+                                        <property name="position">2</property>
                                       </packing>
                                     </child>
                                     <child>
@@ -293,7 +319,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">2</property>
+                                        <property name="position">3</property>
                                       </packing>
                                     </child>
                                     <child>
@@ -321,7 +347,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">3</property>
+                                        <property name="position">4</property>
                                       </packing>
                                     </child>
                                     <child>
@@ -349,7 +375,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">4</property>
+                                        <property name="position">5</property>
                                       </packing>
                                     </child>
                                     <child>
@@ -362,7 +388,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">5</property>
+                                        <property name="position">6</property>
                                       </packing>
                                     </child>
                                   </widget>
@@ -448,6 +474,85 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
                                     <property name="spacing">10</property>
+                                    <child>
+                                      <widget class="GtkFrame" id="frame_database">
+                                        <property name="can_focus">False</property>
+                                        <property name="label_xalign">0</property>
+                                        <property name="label_yalign">1</property>
+                                        <property name="shadow_type">out</property>
+                                        <child>
+                                          <widget class="GtkAlignment" id="alignment1">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="top_padding">2</property>
+                                            <property name="bottom_padding">2</property>
+                                            <property name="left_padding">2</property>
+                                            <property name="right_padding">2</property>
+                                            <child>
+                                              <widget class="GtkVBox" id="vbox77">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="spacing">4</property>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label_current_database">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="xalign">0</property>
+                                                    <property name="ellipsize">end</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkHBox" id="hbox224">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <child>
+                                                      <widget class="GtkButton" id="button_database_change">
+                                                        <property name="label" 
translatable="yes">Change</property>
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">True</property>
+                                                        <property name="receives_default">True</property>
+                                                        <signal name="clicked" 
handler="on_button_database_change_clicked" swapped="no"/>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">0</property>
+                                                      </packing>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                            </child>
+                                          </widget>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkLabel" id="label_database_at_frame_database">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label" translatable="yes">Database</property>
+                                            <property name="use_markup">True</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="type">label_item</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
                                     <child>
                                       <widget class="GtkFrame" id="frame_session">
                                         <property name="visible">True</property>
@@ -786,7 +891,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">0</property>
+                                        <property name="position">1</property>
                                       </packing>
                                     </child>
                                     <child>
@@ -2377,7 +2482,7 @@
                                       <packing>
                                         <property name="expand">True</property>
                                         <property name="fill">True</property>
-                                        <property name="position">1</property>
+                                        <property name="position">2</property>
                                       </packing>
                                     </child>
                                     <child>
@@ -2508,7 +2613,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">2</property>
+                                        <property name="position">3</property>
                                       </packing>
                                     </child>
                                   </widget>
@@ -25873,6 +25978,12 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -41943,6 +42054,12 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -49971,6 +50088,12 @@ Since Chronojump 2.1.3, backups contain the complete data.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                             </widget>
diff --git a/src/config.cs b/src/config.cs
index 76a29deb1..a95d5b3d5 100644
--- a/src/config.cs
+++ b/src/config.cs
@@ -61,6 +61,7 @@ public class Config
        public bool LowHeight; //devices with less than 500 px vertical, like Odroid Go Super
        public bool LowCPU; //workaround to not show realtime graph on force sensor capture (until its 
optimized)
        public bool GuiTest;
+       public bool CanOpenExternalDataDir;
        public string DataDir = ""; //on chronojump-networks admin to replace GetLocalDataDir (), think if 
Import has to be disabled
 
        /*
@@ -148,6 +149,8 @@ public class Config
                                                LowCPU = true;
                                        else if(parts[0] == "GuiTest" && Util.StringToBool(parts[1]))
                                                GuiTest = true;
+                                       else if(parts[0] == "CanOpenExternalDataDir" && 
Util.StringToBool(parts[1]))
+                                               CanOpenExternalDataDir = true;
                                        else if(parts[0] == "DataDir" && parts[1] != "")
                                        {
                                                DataDir = parts[1]; //works even with spaces on name
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index d39ff9d98..07767d13f 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -915,6 +915,8 @@ public partial class ChronoJumpWindow
                } else {
                        if(! Config.UseSystemColor)
                        {
+                               UtilGtk.ContrastLabelsLabel (Config.ColorBackgroundIsDark, 
label_database_at_frame_database);
+                               UtilGtk.ContrastLabelsLabel (Config.ColorBackgroundIsDark, 
label_current_database);
                                UtilGtk.ContrastLabelsLabel (Config.ColorBackgroundIsDark, 
label_session_at_frame_session);
                                UtilGtk.ContrastLabelsLabel (Config.ColorBackgroundIsDark, 
label_current_session);
                                UtilGtk.ContrastLabelsLabel (Config.ColorBackgroundIsDark, 
label_persons_at_frame_persons);
diff --git a/src/gui/app1/menu.cs b/src/gui/app1/menu.cs
index 1fee3b411..96e6beb52 100644
--- a/src/gui/app1/menu.cs
+++ b/src/gui/app1/menu.cs
@@ -54,9 +54,14 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.EventBox eventbox_edit_current_person_h;
        [Widget] Gtk.EventBox eventbox_show_all_person_events_h;
        [Widget] Gtk.EventBox eventbox_delete_current_person_h;
+       [Widget] Gtk.Label label_current_database;
        [Widget] Gtk.Label label_current_session;
        [Widget] Gtk.Label label_current_person;
 
+       [Widget] Gtk.Frame frame_database;
+       [Widget] Gtk.Label label_database_at_frame_database;
+       [Widget] Gtk.Button button_menu_database;
+
        [Widget] Gtk.CheckButton check_menu_session;
        [Widget] Gtk.CheckButton check_manage_persons;
        [Widget] Gtk.Button button_menu_help;
diff --git a/src/gui/app1/menu_tiny.cs b/src/gui/app1/menu_tiny.cs
index a49efd41d..377c9a510 100644
--- a/src/gui/app1/menu_tiny.cs
+++ b/src/gui/app1/menu_tiny.cs
@@ -32,6 +32,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Arrow arrow_menu_show_session_down1;
        [Widget] Gtk.VBox vbox_menu_tiny;
        [Widget] Gtk.VBox vbox_menu_tiny_menu; //really the menu (without the logos at the bottom)
+       [Widget] Gtk.EventBox eventbox_button_menu_database;
        [Widget] Gtk.EventBox eventbox_check_menu_session1;
        [Widget] Gtk.EventBox eventbox_button_menu_session_more1;
        [Widget] Gtk.EventBox eventbox_button_menu_session_new1;
@@ -141,6 +142,7 @@ public partial class ChronoJumpWindow
 
                UtilGtk.ViewportColor(viewport_image_logo_icon, UtilGtk.BLUE_CHRONOJUMP);
 
+               UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_database, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_check_menu_session1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_preferences1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_help1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 68dc83c64..01f7c47a9 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -284,18 +284,13 @@ public partial class ChronoJumpWindow
                        SqliteJson.UploadExhibitionTestsPending();
                }
 
-               if (configChronojump.DataDir != "")
+               if (configChronojump.CanOpenExternalDataDir)
                {
-                       Sqlite.DisConnect ();
+                       frame_database.Visible = true;
+                       button_menu_database.Visible = true;
 
-                       //called from Util.GetLocalDataDir
-                       Config.DataDirStatic = configChronojump.DataDir;
-                       Sqlite.SetHome ();
-
-                       Sqlite.Connect ();
-
-                       //this updated if needed:
-                       Sqlite.ConvertToLastChronojumpDBVersion ();
+                       if (configChronojump.DataDir != "")
+                               databaseChange ();
                }
 
                configDo();
@@ -365,6 +360,53 @@ public partial class ChronoJumpWindow
                rfidProcessCancel = true;
        }
 
+       private void databaseChange ()
+       {
+               Sqlite.DisConnect ();
+
+               //called from Util.GetLocalDataDir
+               Config.DataDirStatic = configChronojump.DataDir;
+               Sqlite.SetHome ();
+
+               Sqlite.Connect ();
+
+               //this updated if needed:
+               Sqlite.ConvertToLastChronojumpDBVersion ();
+
+               label_current_database.Text = "<b>" + Util.GetLastPartOfPath (configChronojump.DataDir) + 
"</b>";
+               label_current_database.UseMarkup = true;
+               label_current_database.TooltipText = configChronojump.DataDir;
+       }
+
+       Gtk.FileChooserDialog database_fc;
+       private void on_button_database_change_clicked (object o, EventArgs args)
+       {
+               database_fc = new Gtk.FileChooserDialog("Use database:",
+                               app1,
+                               FileChooserAction.SelectFolder,
+                               Catalog.GetString("Cancel"),ResponseType.Cancel,
+                               Catalog.GetString("Select"),ResponseType.Accept
+                               );
+               //database_fc.SetCurrentFolder(whatever);
+
+               if (database_fc.Run() == (int)ResponseType.Accept)
+               {
+                       // 1) update to config file (to be opened again on next boot)
+
+                       // 2) reassing configChronojump.DataDir
+                       configChronojump.DataDir = database_fc.Filename;
+
+                       // 2) open database
+                       //TODO: think where to put a try/catch, eg if there is no database file, or search 
database/chronojump.db before
+                       databaseChange ();
+               }
+
+               database_fc.Hide ();
+
+               //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
+               database_fc.Destroy();
+       }
+
        private void on_button_networks_encoder_guest_clicked (object sender, EventArgs e)
        {
                // 1) do not allow to click again the button


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