[chronojump] Import with thread verbose



commit 73e525d1bf339096d9abc41fe5f6199132217533
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Oct 16 18:04:08 2019 +0200

    Import with thread verbose

 glade/session_load.glade      | 46 ++++++++++++++++++++++++++++++++++++++
 src/chronojumpImporter.cs     | 12 ++++++++--
 src/gui/chronojumpImporter.cs |  8 +++----
 src/gui/session.cs            | 51 +++++++++++++++++++++++++++++++++----------
 4 files changed, 100 insertions(+), 17 deletions(-)
---
diff --git a/glade/session_load.glade b/glade/session_load.glade
index c07bcc88..b74c9b5f 100644
--- a/glade/session_load.glade
+++ b/glade/session_load.glade
@@ -327,6 +327,52 @@
                 <property name="position">1</property>
               </packing>
             </child>
+            <child>
+              <widget class="GtkButton" id="button_import">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">False</property>
+                <signal name="clicked" handler="on_button_import_clicked" swapped="no"/>
+                <child>
+                  <widget class="GtkHBox" id="hbox3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">4</property>
+                    <child>
+                      <widget class="GtkImage" id="image_import">
+                        <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="GtkLabel" id="label3">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Import</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">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
           </widget>
           <packing>
             <property name="expand">False</property>
diff --git a/src/chronojumpImporter.cs b/src/chronojumpImporter.cs
index 28dd0a9c..f9fda892 100644
--- a/src/chronojumpImporter.cs
+++ b/src/chronojumpImporter.cs
@@ -33,6 +33,8 @@ using Mono.Unix;
 
 class ChronojumpImporter
 {
+       public static string MessageToPulsebar;
+
        // Database that it's importing from
        private string sourceFile;
 
@@ -78,6 +80,7 @@ class ChronojumpImporter
                this.sourceSession = sourceSession;
                this.destinationSession = destinationSession;
                this.debugToFile = debugToFile;
+               MessageToPulsebar = "";
        }
 
        // Shows a dialogue to the user and lets him cancel the operation. The dialog information depends on
@@ -137,6 +140,7 @@ class ChronojumpImporter
        {
                //1) create temp dir for forceSensor and runEncoder and copy files there, original files will 
not be used
                //   no need to be done for encoder files because there we will not to change filename
+               MessageToPulsebar = "Copying temporary files";
 
 LogB.Information("import A ");
                string tempImportDir = Util.GetDatabaseTempImportDir();
@@ -161,12 +165,12 @@ LogB.Information("import E ");
 LogB.Information("import F ");
 
                string sourceDir = Path.GetDirectoryName(sourceFile);
-               if(Directory.Exists(Path.Combine(sourceDir, "..", forceSensorName)))
+               if(Directory.Exists(Path.Combine(sourceDir, "..", forceSensorName, sourceSession.ToString())))
                        foreach (FileInfo file in new DirectoryInfo(Path.Combine(sourceDir, "..", 
forceSensorName, sourceSession.ToString())).GetFiles())
                                file.CopyTo(Path.Combine(tempImportDir, forceSensorName, 
sourceSession.ToString(), file.Name));
 
 LogB.Information("import G ");
-               if(Directory.Exists(Path.Combine(sourceDir, "..", raceAnalyzerName)))
+               if(Directory.Exists(Path.Combine(sourceDir, "..", raceAnalyzerName, 
sourceSession.ToString())))
                        foreach (FileInfo file in new DirectoryInfo(Path.Combine(sourceDir, "..", 
raceAnalyzerName, sourceSession.ToString())).GetFiles())
                                file.CopyTo(Path.Combine(tempImportDir, raceAnalyzerName, 
sourceSession.ToString(), file.Name));
 
@@ -174,6 +178,7 @@ LogB.Information("import H ");
 
                //2) prepare SQL files
 
+               MessageToPulsebar = "Preparing database";
                string temporarySourceFile = Path.GetTempFileName ();
                File.Copy (sourceFile, temporarySourceFile, true);
 
@@ -192,16 +197,19 @@ LogB.Information("import A ");
 
                //3 check version of database to be imported
 
+               MessageToPulsebar = "Checking version";
                if (destinationDatabaseVersionNum < sourceDatabaseVersionNum) {
                        return new Result (false, Catalog.GetString ("Trying to import a newer database 
version than this Chronojump\n" +
                                "Please, update the running Chronojump."));
                } else if (destinationDatabaseVersionNum > sourceDatabaseVersionNum) {
                        LogB.Debug ("chronojump-importer version before update: ", 
sourceDatabaseVersion.output);
+                       MessageToPulsebar = "Updating database";
                        updateDatabase (temporarySourceFile);
                        string versionAfterUpdate = getDatabaseVersionFromFile (temporarySourceFile).output;
                        LogB.Debug ("chronojump-importer version after update: ", versionAfterUpdate);
                }
 
+               MessageToPulsebar = "Starting import";
                List<string> parameters = new List<string> ();
                parameters.Add ("--source");
                parameters.Add (temporarySourceFile);
diff --git a/src/gui/chronojumpImporter.cs b/src/gui/chronojumpImporter.cs
index bd72db7b..5550ae14 100644
--- a/src/gui/chronojumpImporter.cs
+++ b/src/gui/chronojumpImporter.cs
@@ -37,7 +37,7 @@ public partial class ChronoJumpWindow
                        sessionLoadWin.DisableImportToCurrentSession ();
                }
 
-               sessionLoadWin.Button_accept.Clicked += new EventHandler(on_load_session_accepted_to_import);
+               sessionLoadWin.Button_import.Clicked += new EventHandler(on_load_session_accepted_to_import);
        }
 
        //from import session
@@ -101,10 +101,10 @@ public partial class ChronoJumpWindow
                        LogB.ThreadEnded();
                        return false;
                }
-       
-               sessionLoadWin.Pulse(); //TODO: sessionLoadWin is hidden, show genericWin or do not hide that 
win on import and show messages like confirm and this pulsebar there
 
-               Thread.Sleep (30);
+               sessionLoadWin.Pulse(ChronojumpImporter.MessageToPulsebar);
+
+               Thread.Sleep (100);
                //LogB.Debug(threadImport.ThreadState.ToString());
                return true;
        }
diff --git a/src/gui/session.cs b/src/gui/session.cs
index d7992d38..4b444169 100644
--- a/src/gui/session.cs
+++ b/src/gui/session.cs
@@ -28,8 +28,8 @@ using System.Collections; //ArrayList
 using Mono.Unix;
 
 
-public class SessionAddEditWindow {
-       
+public class SessionAddEditWindow
+{
        [Widget] Gtk.Window session_add_edit;
        [Widget] Gtk.Entry entry_name;
        [Widget] Gtk.Entry entry_place;
@@ -670,8 +670,8 @@ public class SessionAddEditWindow {
 }
 
 
-public class SessionLoadWindow {
-
+public class SessionLoadWindow
+{
        public enum WindowType
        {
                LOAD_SESSION,
@@ -684,6 +684,8 @@ public class SessionLoadWindow {
        private string import_file_path;
        [Widget] Gtk.TreeView treeview_session_load;
        [Widget] Gtk.Button button_accept;
+       [Widget] Gtk.Button button_import;
+       [Widget] Gtk.Image image_import;
        [Widget] Gtk.Entry entry_search_filter;
        [Widget] Gtk.Image image_open_database;
        [Widget] Gtk.CheckButton checkbutton_show_data_jump_run;
@@ -700,7 +702,8 @@ public class SessionLoadWindow {
        private Session currentSession;
        private WindowType type;
 
-       SessionLoadWindow (Gtk.Window parent, WindowType type) {
+       SessionLoadWindow (Gtk.Window parent, WindowType type)
+       {
                this.type = type;
                Glade.XML gladeXML;
                gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "session_load.glade", 
"session_load", null);
@@ -713,8 +716,12 @@ public class SessionLoadWindow {
                checkbutton_show_data_jump_run.Visible = (type == WindowType.LOAD_SESSION);
 
                if (type == WindowType.LOAD_SESSION) {
+                       button_accept.Visible = true;
+                       button_import.Visible = false;
                        session_load.Title = Catalog.GetString ("Load session");
                } else {
+                       button_accept.Visible = false;
+                       button_import.Visible = true;
                        session_load.Title = Catalog.GetString ("Import session");
                }
 
@@ -722,6 +729,7 @@ public class SessionLoadWindow {
                UtilGtk.IconWindow(session_load);
 
                image_open_database.Pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "folder_open.png");
+               image_import.Pixbuf = new Pixbuf (null, Util.GetImagePath(false) + Constants.FileNameImport);
 
                createTreeView(treeview_session_load, false, false);
                store = getStore(false, false);
@@ -732,6 +740,7 @@ public class SessionLoadWindow {
                store.ChangeSortColumn();
 
                button_accept.Sensitive = false;
+               button_import.Sensitive = false;
                entry_search_filter.CanFocus = true;
                entry_search_filter.IsFocus = true;
 
@@ -1066,8 +1075,11 @@ public class SessionLoadWindow {
                if (((TreeSelection)o).GetSelected(out model, out iter)) {
                        selected = (string)model.GetValue (iter, 0);
                        button_accept.Sensitive = true;
-               } else
+                       button_import.Sensitive = true;
+               } else {
                        button_accept.Sensitive = false;
+                       button_import.Sensitive = false;
+               }
        }
 
        public int CurrentSessionId() {
@@ -1104,8 +1116,12 @@ public class SessionLoadWindow {
                        //put selection in selected
                        selected = (string) model.GetValue (iter, 0);
 
-                       //activate on_button_accept_clicked()
-                       button_accept.Activate();
+                       if (type == WindowType.LOAD_SESSION) {
+                               //activate on_button_accept_clicked()
+                               button_accept.Activate();
+                       } else {
+                               button_import.Activate();
+                       }
                }
        }
        
@@ -1118,9 +1134,17 @@ public class SessionLoadWindow {
                }
        }
 
-       public void Pulse()
+       void on_button_import_clicked (object o, EventArgs args)
+       {
+               if(selected != "-1") {
+                       currentSession = SqliteSession.Select (selected);
+               }
+       }
+
+       public void Pulse(string str)
        {
                progressbarImport.Pulse();
+               progressbarImport.Text = str;
        }
 
        void on_button_cancel_clicked (object o, EventArgs args)
@@ -1140,6 +1164,11 @@ public class SessionLoadWindow {
                set { button_accept = value; }
                get { return button_accept; }
        }
+       public Button Button_import
+       {
+               //set { button_accept = value; }
+               get { return button_import; }
+       }
        
        public Session CurrentSession 
        {
@@ -1148,8 +1177,8 @@ public class SessionLoadWindow {
 
 }
 
-public class SessionSelectStatsWindow {
-       
+public class SessionSelectStatsWindow
+{
        [Widget] Gtk.Window stats_select_sessions;
        
        private TreeStore store1;


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