[chronojump] Session export (SQL) can be cancelled



commit 661248966b6a1ac2f95a81ecef2eed4d850e7ba5
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Apr 27 16:49:51 2021 +0200

    Session export (SQL) can be cancelled

 glade/app1.glade               | 73 +++++++++++++++++++++++++++---------------
 src/gui/app1/session/export.cs | 42 ++++++++++++++++++------
 src/gui/app1/session/main.cs   | 10 +++---
 3 files changed, 87 insertions(+), 38 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 8ab7b0ff..f48e65a8 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -25318,6 +25318,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -31485,18 +31488,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>
@@ -31533,6 +31524,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>
@@ -40567,6 +40570,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -45970,23 +45976,19 @@ then click this button.</property>
                                                         <property name="can_focus">False</property>
                                                         <property name="layout_style">center</property>
                                                         <child>
-                                                          <widget class="GtkVBox" id="vbox231">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            <child>
-                                                            <widget class="GtkButton" 
id="app1s_button_export_cancel_close">
+                                                          <widget class="GtkButton" 
id="app1s_button_export_cancel">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property name="can_default">True</property>
                                                             <property 
name="receives_default">False</property>
-                                                            <signal name="clicked" 
handler="on_app1s_button_export_cancel_or_close_clicked" swapped="no"/>
+                                                            <signal name="clicked" 
handler="on_app1s_button_export_cancel_clicked" swapped="no"/>
                                                             <accelerator key="Escape" signal="clicked"/>
                                                             <child>
-                                                            <widget class="GtkEventBox" 
id="app1s_eventbox_button_export_cancel_close">
+                                                            <widget class="GtkEventBox" 
id="app1s_eventbox_button_export_cancel">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="app1s_label_export_cancel_close">
+                                                            <widget class="GtkLabel" 
id="app1s_label_export_cancel">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="label" 
translatable="yes">Cancel</property>
@@ -45994,18 +45996,39 @@ then click this button.</property>
                                                             </child>
                                                             </widget>
                                                             </child>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">True</property>
+                                                          </widget>
+                                                          <packing>
+                                                            <property name="expand">False</property>
                                                             <property name="fill">False</property>
                                                             <property name="position">0</property>
-                                                            </packing>
+                                                          </packing>
+                                                        </child>
+                                                        <child>
+                                                          <widget class="GtkButton" 
id="app1s_button_export_close">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="can_default">True</property>
+                                                            <property 
name="receives_default">False</property>
+                                                            <signal name="clicked" 
handler="on_app1s_button_export_close_clicked" swapped="no"/>
+                                                            <accelerator key="Escape" signal="clicked"/>
+                                                            <child>
+                                                            <widget class="GtkEventBox" 
id="app1s_eventbox_button_export_close">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <child>
+                                                            <widget class="GtkLabel" 
id="app1s_label_export_close">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" 
translatable="yes">Close</property>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
                                                             </child>
                                                           </widget>
                                                           <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">False</property>
-                                                            <property name="position">0</property>
+                                                            <property name="position">1</property>
                                                           </packing>
                                                         </child>
                                                       </widget>
diff --git a/src/gui/app1/session/export.cs b/src/gui/app1/session/export.cs
index 5fb876be..88fa8917 100644
--- a/src/gui/app1/session/export.cs
+++ b/src/gui/app1/session/export.cs
@@ -30,6 +30,7 @@ using Mono.Unix;
 public partial class ChronoJumpWindow
 {
        private Thread app1s_threadExport;
+       private static bool cancelExport;
 
        private void on_button_session_export_pre_clicked (object o, EventArgs args)
        {
@@ -44,8 +45,8 @@ public partial class ChronoJumpWindow
                app1s_exportText = "";
                app1s_button_export_select.Sensitive = true;
                app1s_button_export_start.Sensitive = false;
-               app1s_button_export_cancel_close.Sensitive = true;
-               app1s_label_export_cancel_close.Text = Catalog.GetString("Cancel");
+               app1s_button_export_cancel.Visible = false;
+               app1s_button_export_close.Visible = true;
        
                app1s_notebook.CurrentPage = app1s_PAGE_EXPORT;
        }
@@ -91,8 +92,11 @@ public partial class ChronoJumpWindow
                                                "", app1s_fileCopy);
                                confirmWin.Button_accept.Clicked += new 
EventHandler(app1s_export_on_overwrite_file_accepted);
                        } else {
+                               //note this is the same than: app1s_export_on_overwrite_file_accepted
                                app1s_pulsebarExportActivity.Visible = true;
                                app1s_uc = new UtilCopy(currentSession.UniqueID, false);
+
+                               cancelExport = false;
                                app1s_threadExport = new Thread(new ThreadStart(app1s_export));
                                GLib.Idle.Add (new GLib.IdleHandler (app1s_ExportPulseGTK));
 
@@ -134,9 +138,14 @@ public partial class ChronoJumpWindow
        private void app1s_ExportPulseEnd()
        {
                app1s_pulsebarExportActivity.Fraction = 1;
-               app1s_label_export_progress.Text =
-                       string.Format(Catalog.GetString("Exported in {0} ms"),
-                                       app1s_exportElapsedMs);
+
+               if(cancelExport)
+                       app1s_label_export_progress.Text =
+                               Catalog.GetString("Cancelled.");
+               else
+                       app1s_label_export_progress.Text =
+                               string.Format(Catalog.GetString("Exported in {0} ms"),
+                                               app1s_exportElapsedMs);
 
                app1s_export_doing_sensitive_start_end(false);
        }
@@ -152,10 +161,11 @@ public partial class ChronoJumpWindow
                app1s_button_export_start.Sensitive = false;
 
                if(start) {
-                       app1s_button_export_cancel_close.Sensitive = false; //or make cancel sensitive while 
process?
+                       app1s_button_export_cancel.Visible = true;
+                       app1s_button_export_close.Visible = false;
                } else {
-                       app1s_button_export_cancel_close.Sensitive = true;
-                       app1s_label_export_cancel_close.Text = Catalog.GetString("Close");
+                       app1s_button_export_cancel.Visible = false;
+                       app1s_button_export_close.Visible = true;
                }
        }
 
@@ -164,8 +174,11 @@ public partial class ChronoJumpWindow
                try {
                        Directory.Delete(app1s_fileCopy, true);
 
+                       //note this is the same than: on_app1s_button_export_start_clicked
                        app1s_pulsebarExportActivity.Visible = true;
                        app1s_uc = new UtilCopy(currentSession.UniqueID, false);
+
+                       cancelExport = false;
                        app1s_threadExport = new Thread(new ThreadStart(app1s_export));
                        GLib.Idle.Add (new GLib.IdleHandler (app1s_ExportPulseGTK));
 
@@ -219,6 +232,10 @@ public partial class ChronoJumpWindow
                int count = 1;
                foreach (string session in mySessions)
                {
+                       //cancelExport breaks here instead doing it on pulse to avoid leaving some Sqlite 
DataReader opened
+                       if(cancelExport)
+                               break;
+
                        app1s_exportText = string.Format("Adjusting new database {0}/{1}", count, 
mySessions.Length);
                        LogB.Information(string.Format("session: {0}", session));
                        string [] myStringFull = session.Split(new char[] {':'});
@@ -237,8 +254,15 @@ public partial class ChronoJumpWindow
                LogB.Information("ended app1s_export()");
        }
 
-       private void on_app1s_button_export_cancel_or_close_clicked (object o, EventArgs args)
+       private void on_app1s_button_export_cancel_clicked (object o, EventArgs args)
+       {
+               LogB.Information("cancelling export session");
+               cancelExport = true;
+       }
+
+       private void on_app1s_button_export_close_clicked (object o, EventArgs args)
        {
+               LogB.Information("closing export session");
                app1s_notebook.CurrentPage = app1s_PAGE_MODES;
        }
 }
diff --git a/src/gui/app1/session/main.cs b/src/gui/app1/session/main.cs
index 56d03e9d..f3b7e526 100644
--- a/src/gui/app1/session/main.cs
+++ b/src/gui/app1/session/main.cs
@@ -162,9 +162,10 @@ public partial class ChronoJumpWindow
        //notebook tab 8 (export)
        [Widget] Gtk.Button app1s_button_export_select;
        [Widget] Gtk.Button app1s_button_export_start;
-       [Widget] Gtk.Button app1s_button_export_cancel_close;
-       [Widget] Gtk.EventBox app1s_eventbox_button_export_cancel_close;
-       [Widget] Gtk.Label app1s_label_export_cancel_close;
+       [Widget] Gtk.Button app1s_button_export_cancel;
+       [Widget] Gtk.Button app1s_button_export_close;
+       [Widget] Gtk.EventBox app1s_eventbox_button_export_cancel;
+       [Widget] Gtk.EventBox app1s_eventbox_button_export_close;
        [Widget] Gtk.Image app1s_image_button_export_select;
        [Widget] Gtk.Label app1s_label_export_destination;
        [Widget] Gtk.Label app1s_label_export_progress;
@@ -214,7 +215,8 @@ public partial class ChronoJumpWindow
                UtilGtk.EventBoxColorBackgroundActive (app1s_eventbox_button_import_again, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (app1s_eventbox_button_delete_close, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (app1s_eventbox_button_backup_cancel_close, 
UtilGtk.YELLOW, UtilGtk.YELLOW_LIGHT);
-               UtilGtk.EventBoxColorBackgroundActive (app1s_eventbox_button_export_cancel_close, 
UtilGtk.YELLOW, UtilGtk.YELLOW_LIGHT);
+               UtilGtk.EventBoxColorBackgroundActive (app1s_eventbox_button_export_cancel, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
+               UtilGtk.EventBoxColorBackgroundActive (app1s_eventbox_button_export_close, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
        }
 
        private void app1s_label_session_set_name()


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