[chronojump] Import with thread WIP
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Import with thread WIP
- Date: Wed, 16 Oct 2019 12:28:17 +0000 (UTC)
commit aff27b338510a796bc162a81af5469315df1823b
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Oct 16 14:18:34 2019 +0200
Import with thread WIP
glade/app1.glade | 32 ++++----
glade/session_load.glade | 11 +++
po/POTFILES.in | 1 +
src/Makefile.am | 1 +
src/gui/chronojump.cs | 104 --------------------------
src/gui/chronojumpImporter.cs | 165 ++++++++++++++++++++++++++++++++++++++++++
src/gui/session.cs | 8 +-
src/sqlite/forceSensor.cs | 4 +-
src/sqlite/runEncoder.cs | 6 +-
9 files changed, 209 insertions(+), 123 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 4a8e58f6..25906f1d 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -109,7 +109,7 @@
<property name="can_focus">False</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
- <signal name="activate" handler="on_button_encoder_import_chronojump_session"
swapped="no"/>
+ <signal name="activate" handler="on_button_import_chronojump_session" swapped="no"/>
<child internal-child="image">
<widget class="GtkImage" id="image_import_database">
<property name="visible">True</property>
@@ -21986,6 +21986,9 @@ Concentric</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -23934,6 +23937,18 @@ 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>
@@ -23970,18 +23985,6 @@ 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>
@@ -30937,6 +30940,9 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/glade/session_load.glade b/glade/session_load.glade
index c7452202..c07bcc88 100644
--- a/glade/session_load.glade
+++ b/glade/session_load.glade
@@ -142,6 +142,17 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <widget class="GtkProgressBar" id="progressbarImport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</widget>
</child>
</widget>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 99984c64..4c18023f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -57,6 +57,7 @@ src/execute/run.cs
src/exportSession.cs
src/forceSensor.cs
src/gui/chronojump.cs
+src/gui/chronojumpImporter.cs
src/gui/chronopic.cs
src/gui/chronopicRegister.cs
src/gui/convertWeight.cs
diff --git a/src/Makefile.am b/src/Makefile.am
index 5e1aed18..ba4ca40a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,7 @@ LINK = $(REF_DEP_CHRONOJUMP)
SOURCES = \
gui/chronojump.cs\
gui/chronojumpIcons.cs\
+ gui/chronojumpImporter.cs\
gui/chronojumpPersons.cs\
gui/chronopic.cs\
gui/chronopicRegister.cs\
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 0669313a..1b96a494 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2421,110 +2421,6 @@ public partial class ChronoJumpWindow
}
}
- private void on_button_encoder_import_chronojump_session(object o, EventArgs args)
- {
- sessionLoadWin = SessionLoadWindow.Show (app1, SessionLoadWindow.WindowType.IMPORT_SESSION);
-
- if (currentSession == null) {
- sessionLoadWin.DisableImportToCurrentSession ();
- }
-
- sessionLoadWin.Button_accept.Clicked += new EventHandler(on_load_session_accepted_to_import);
- }
-
- //from import session
- private void on_load_session_accepted_to_import(object o, EventArgs args)
- {
- int sourceSession = sessionLoadWin.CurrentSessionId();
- string databasePath = sessionLoadWin.ImportDatabasePath();
- LogB.Information (databasePath);
-
- Session destinationSession = currentSession;
-
- if (sessionLoadWin.ImportToNewSession ()) {
- destinationSession = null;
- }
-
- ImportSessionFromDatabase (databasePath, sourceSession, destinationSession);
- }
-
- private void ImportSessionFromDatabase(string databasePath, int sourceSession, Session
destinationSession)
- {
- string source_filename = databasePath;
- string destination_filename = Sqlite.DatabaseFilePath;
-
- int destinationSessionId;
- if (destinationSession == null)
- {
- destinationSessionId = 0;
- }
- else
- {
- destinationSessionId = destinationSession.UniqueID;
- }
-
- ChronojumpImporter chronojumpImporter = new ChronojumpImporter (app1, source_filename,
destination_filename, sourceSession, destinationSessionId, preferences.debugMode);
-
- Gtk.ResponseType response = chronojumpImporter.showImportConfirmation ();
-
- if (response != Gtk.ResponseType.Ok) {
- return;
- }
-
- ChronojumpImporter.Result result = chronojumpImporter.import ();
-
- if (result.success)
- {
- //update GUI if events have been added
- //1) simple jump
- createComboSelectJumps(false);
- UtilGtk.ComboUpdate(combo_result_jumps,
- SqliteJumpType.SelectJumpTypes(false, Constants.AllJumpsNameStr(),
"", true), ""); //without filter, only select name
- combo_select_jumps.Active = 0;
- combo_result_jumps.Active = 0;
-
- //2) reactive jump
- createComboSelectJumpsRj(false);
- UtilGtk.ComboUpdate(combo_result_jumps_rj,
- SqliteJumpType.SelectJumpRjTypes(Constants.AllJumpsNameStr(), true),
""); //without filter, only select name
- combo_select_jumps_rj.Active = 0;
- combo_result_jumps_rj.Active = 0;
-
- //3) simple run
- createComboSelectRuns(false);
- UtilGtk.ComboUpdate(combo_result_runs,
- SqliteRunType.SelectRunTypes(Constants.AllRunsNameStr(), true), "");
//without filter, only select name
- combo_select_runs.Active = 0;
- combo_result_runs.Active = 0;
-
- //4) intervallic run
- createComboSelectRunsInterval(false);
- UtilGtk.ComboUpdate(combo_result_runs_interval,
-
SqliteRunIntervalType.SelectRunIntervalTypes(Constants.AllRunsNameStr(), true), ""); //without filter, only
select name
- combo_select_runs_interval.Active = 0;
- combo_result_runs_interval.Active = 0;
-
- // TODO: we need this on encoder or is already done at reloadSession???
- //createEncoderCombos();
-
- // forceSensor
- fillForceSensorExerciseCombo("");
-
- // runEncoder
- fillRunEncoderExerciseCombo("");
-
- //update stats combos
- updateComboStats ();
-
- reloadSession ();
-
- chronojumpImporter.showImportCorrectlyFinished ();
- } else {
- LogB.Debug ("Chronojump Importer error: ", result.error);
- new DialogMessage (Catalog.GetString("Chronojump importer"),
Constants.MessageTypes.WARNING, result.error, true);
- }
- }
-
private void on_open_activate (object o, EventArgs args)
{
LogB.Information("open session");
diff --git a/src/gui/chronojumpImporter.cs b/src/gui/chronojumpImporter.cs
new file mode 100644
index 00000000..bd72db7b
--- /dev/null
+++ b/src/gui/chronojumpImporter.cs
@@ -0,0 +1,165 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ChronoJump is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Copyright (C) 2019 Xavier de Blas <xaviblas gmail com>
+ */
+
+using Gtk;
+using System;
+using System.Threading;
+using Mono.Unix;
+
+public partial class ChronoJumpWindow
+{
+ static ChronojumpImporter.Result importerResult;
+ static Thread threadImport;
+ static ChronojumpImporter chronojumpImporter;
+
+ private void on_button_import_chronojump_session(object o, EventArgs args)
+ {
+ sessionLoadWin = SessionLoadWindow.Show (app1, SessionLoadWindow.WindowType.IMPORT_SESSION);
+
+ if (currentSession == null) {
+ sessionLoadWin.DisableImportToCurrentSession ();
+ }
+
+ sessionLoadWin.Button_accept.Clicked += new EventHandler(on_load_session_accepted_to_import);
+ }
+
+ //from import session
+ private void on_load_session_accepted_to_import(object o, EventArgs args)
+ {
+ int sourceSession = sessionLoadWin.CurrentSessionId();
+ string databasePath = sessionLoadWin.ImportDatabasePath();
+ LogB.Information (databasePath);
+
+ Session destinationSession = currentSession;
+
+ if (sessionLoadWin.ImportToNewSession ()) {
+ destinationSession = null;
+ }
+
+ importSessionFromDatabasePrepare (databasePath, sourceSession, destinationSession);
+ }
+
+ private void importSessionFromDatabasePrepare (string databasePath, int sourceSession, Session
destinationSession)
+ {
+ string source_filename = databasePath;
+ string destination_filename = Sqlite.DatabaseFilePath;
+
+ int destinationSessionId;
+ if (destinationSession == null)
+ destinationSessionId = 0;
+ else
+ destinationSessionId = destinationSession.UniqueID;
+
+ chronojumpImporter = new ChronojumpImporter (app1, source_filename, destination_filename,
sourceSession, destinationSessionId, preferences.debugMode);
+
+ Gtk.ResponseType response = chronojumpImporter.showImportConfirmation ();
+
+ if (response != Gtk.ResponseType.Ok) {
+ return;
+ }
+
+ LogB.Information("import before thread");
+ LogB.PrintAllThreads = true; //TODO: remove this
+
+ //with threads DOES NOT WORK
+ threadImport = new Thread(new ThreadStart(importSessionFromDatabaseDo));
+ GLib.Idle.Add (new GLib.IdleHandler (PulseGTKImport));
+
+ LogB.ThreadStart();
+ threadImport.Start();
+ }
+
+ //no GTK here!
+ private void importSessionFromDatabaseDo()
+ {
+ importerResult = chronojumpImporter.import ();
+ }
+
+ private bool PulseGTKImport ()
+ {
+ if ( ! threadImport.IsAlive ) {
+ LogB.ThreadEnding();
+ importSessionFromDatabaseEnd();
+
+ 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);
+ //LogB.Debug(threadImport.ThreadState.ToString());
+ return true;
+ }
+
+ private void importSessionFromDatabaseEnd()
+ {
+ if (importerResult.success)
+ {
+ //update GUI if events have been added
+ //1) simple jump
+ createComboSelectJumps(false);
+ UtilGtk.ComboUpdate(combo_result_jumps,
+ SqliteJumpType.SelectJumpTypes(false, Constants.AllJumpsNameStr(),
"", true), ""); //without filter, only select name
+ combo_select_jumps.Active = 0;
+ combo_result_jumps.Active = 0;
+
+ //2) reactive jump
+ createComboSelectJumpsRj(false);
+ UtilGtk.ComboUpdate(combo_result_jumps_rj,
+ SqliteJumpType.SelectJumpRjTypes(Constants.AllJumpsNameStr(), true),
""); //without filter, only select name
+ combo_select_jumps_rj.Active = 0;
+ combo_result_jumps_rj.Active = 0;
+
+ //3) simple run
+ createComboSelectRuns(false);
+ UtilGtk.ComboUpdate(combo_result_runs,
+ SqliteRunType.SelectRunTypes(Constants.AllRunsNameStr(), true), "");
//without filter, only select name
+ combo_select_runs.Active = 0;
+ combo_result_runs.Active = 0;
+
+ //4) intervallic run
+ createComboSelectRunsInterval(false);
+ UtilGtk.ComboUpdate(combo_result_runs_interval,
+
SqliteRunIntervalType.SelectRunIntervalTypes(Constants.AllRunsNameStr(), true), ""); //without filter, only
select name
+ combo_select_runs_interval.Active = 0;
+ combo_result_runs_interval.Active = 0;
+
+ // TODO: we need this on encoder or is already done at reloadSession???
+ //createEncoderCombos();
+
+ // forceSensor
+ fillForceSensorExerciseCombo("");
+
+ // runEncoder
+ fillRunEncoderExerciseCombo("");
+
+ //update stats combos
+ updateComboStats ();
+
+ reloadSession ();
+
+ chronojumpImporter.showImportCorrectlyFinished ();
+ } else {
+ LogB.Debug ("Chronojump Importer error: ", importerResult.error);
+ new DialogMessage (Catalog.GetString("Chronojump importer"),
Constants.MessageTypes.WARNING, importerResult.error, true);
+ }
+ }
+}
diff --git a/src/gui/session.cs b/src/gui/session.cs
index ccd7ecc9..d7992d38 100644
--- a/src/gui/session.cs
+++ b/src/gui/session.cs
@@ -690,6 +690,7 @@ public class SessionLoadWindow {
[Widget] Gtk.CheckButton checkbutton_show_data_other_tests;
[Widget] Gtk.Label file_path_import;
[Widget] Gtk.VBox session_import_box;
+ [Widget] Gtk.ProgressBar progressbarImport;
[Widget] Gtk.RadioButton radio_import_new_session;
[Widget] Gtk.RadioButton radio_import_current_session;
@@ -1116,7 +1117,12 @@ public class SessionLoadWindow {
SessionLoadWindowBox = null;
}
}
-
+
+ public void Pulse()
+ {
+ progressbarImport.Pulse();
+ }
+
void on_button_cancel_clicked (object o, EventArgs args)
{
SessionLoadWindowBox.session_load.Hide();
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index 55598b39..ce7aa563 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -263,7 +263,7 @@ class SqliteForceSensor : Sqlite
protected internal static void import_from_1_68_to_1_69() //database is opened
{
- LogB.PrintAllThreads = true; //TODO: remove this
+ //LogB.PrintAllThreads = true; //TODO: remove this
LogB.Information("at import_from_1_68_to_1_69()");
string forceSensorDir = Util.GetForceSensorDir();
@@ -400,7 +400,7 @@ class SqliteForceSensor : Sqlite
}
}
- LogB.PrintAllThreads = false; //TODO: remove this
+ //LogB.PrintAllThreads = false; //TODO: remove this
}
}
diff --git a/src/sqlite/runEncoder.cs b/src/sqlite/runEncoder.cs
index a9eb46cd..328ed4e0 100644
--- a/src/sqlite/runEncoder.cs
+++ b/src/sqlite/runEncoder.cs
@@ -259,7 +259,7 @@ class SqliteRunEncoder : Sqlite
protected internal static void import_from_1_70_to_1_71() //database is opened
{
- LogB.PrintAllThreads = true; //TODO: remove this
+ //LogB.PrintAllThreads = true; //TODO: remove this
LogB.Information("at import_from_1_70_to_1_71()");
string raceAnalyzerDir = Util.GetRunEncoderDir();
@@ -269,7 +269,7 @@ class SqliteRunEncoder : Sqlite
if(! Directory.Exists(raceAnalyzerDir))
{
LogB.Information("nothing to import");
- LogB.PrintAllThreads = false; //TODO: remove this
+ //LogB.PrintAllThreads = false; //TODO: remove this
return;
}
@@ -330,7 +330,7 @@ class SqliteRunEncoder : Sqlite
SqliteRunEncoderExercise.Insert(true, 0, "Sprint", "");
LogB.Information("end of import_from_1_70_to_1_71()");
- LogB.PrintAllThreads = false; //TODO: remove this
+ //LogB.PrintAllThreads = false; //TODO: remove this
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]