[chronojump] When importing a chronojump session: if the user has an opened session it merges the data into the e



commit 29a1ce187989365c0293367ae54fc9688a0feda9
Author: Carles Pina i Estany <carles pina cat>
Date:   Tue Oct 25 23:05:58 2016 +0200

    When importing a chronojump session: if the user has an opened session it merges the data into the 
existing session.
    
    Some UI interface messages needs to be improved.

 src/chronojump-importer/chronojump_importer.py |    2 +-
 src/chronojumpImporter.cs                      |   69 ++++++++++++++++++++++--
 src/gui/chronojump.cs                          |   27 +++++++--
 3 files changed, 87 insertions(+), 11 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index 486a678..28d9abe 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -692,7 +692,7 @@ def process_command_line():
     parser.add_argument("--source_session", type=int, required=False,
                         help="Session from source that will be imported to the session specified by 
--destination-session\n"
                              "or to a new session if no --destination-session is specified")
-    parser.add_argument("--destination-session", type=int, required=False,
+    parser.add_argument("--destination_session", type=int, required=False,
                         help="Imports the [source_session] into the [destination_session]. If not specified 
imports as\n"
                              "new session.")
     parser.add_argument("--json_information", required=False, action='store_true',
diff --git a/src/chronojumpImporter.cs b/src/chronojumpImporter.cs
index 14e1de3..48adaba 100644
--- a/src/chronojumpImporter.cs
+++ b/src/chronojumpImporter.cs
@@ -36,7 +36,13 @@ class ChronojumpImporter
        private string destinationFile;
 
        // Session that will import
-       private string session;
+       private int sourceSession;
+
+       // Session that we will import into. If it's 0 it means into to create
+       // a new session, otherwise it will import it into the session indicated by it
+       private int destinationSession;
+
+       Gtk.Window parentWindow;
 
        // Result struct holds the output, error and success operations. It's used to pass
        // errors from different layers (e.g. executing Python scripts) to the UI layer
@@ -56,11 +62,61 @@ class ChronojumpImporter
 
        // ChronojumpImporter class imports a specific session from sourceFile to destinationFile.
        // The main method is "import()" which does all the work.
-       public ChronojumpImporter(string sourceFile, string destinationFile, string session)
+       public ChronojumpImporter(Gtk.Window parentWindow, string sourceFile, string destinationFile, int 
sourceSession, int destinationSession)
        {
+               this.parentWindow = parentWindow;
                this.sourceFile = sourceFile;
                this.destinationFile = destinationFile;
-               this.session = session;
+               this.sourceSession = sourceSession;
+               this.destinationSession = destinationSession;
+       }
+
+       // Shows a dialogue to the user and lets him cancel the operation. The dialog information depends on
+       // this class configuration: depends if the session is going to be inserted in a new session or an
+       // existing one.
+       // Returns 
+       public Gtk.ResponseType showDialogueToUser()
+       {
+               string message;
+
+               if (importsToNew()) {
+                       message = String.Format (Catalog.GetString ("Are you sure to import the session:\n"+
+                                                                   "{0}\n" +
+                                                                   "from:\n" +
+                                                                   "{1}\n" +
+                                                                   "as a new session?\n" +
+                                                                   "(if you would like to import into an 
existing session then press Cancel, Load the session that you would like to import into and import it)"),
+                                                                                       sourceSession, 
sourceFile);
+               } else {
+                       message = String.Format (Catalog.GetString ("Are you sure to import the session {0} 
from {1} into the active session?\n" +
+                                                                   "(if you would like to import it as a new 
session then press Cancel, exit Chronojump and import before Loading a session)"),
+                                                                                       sourceSession, 
sourceFile);
+               }
+
+               Gtk.MessageDialog confirmationDialog = new Gtk.MessageDialog (parentWindow, 
Gtk.DialogFlags.Modal, Gtk.MessageType.Question, Gtk.ButtonsType.OkCancel, message);
+               confirmationDialog.Title = Catalog.GetString ("Import session?");
+               Gtk.ResponseType response = (Gtk.ResponseType) confirmationDialog.Run ();
+
+               confirmationDialog.Destroy ();
+
+               return response;
+       }
+
+       public void showImportCorrectlyFinished()
+       {
+               string message;
+
+               if (importsToNew()) {
+                       message = Catalog.GetString ("Imported to a new session. You can load it now in 
Session - Load.");
+               } else {
+                       message = Catalog.GetString ("Data merged into the open session.");
+               }
+               new DialogMessage (Constants.MessageTypes.INFO, message);
+       }
+
+       private bool importsToNew()
+       {
+               return destinationSession == 0;
        }
 
        // Tries to import the session and files defined in the constructor and returns Result. See
@@ -107,7 +163,12 @@ class ChronojumpImporter
                parameters.Add ("--destination");
                parameters.Add (destinationFile);
                parameters.Add ("--source_session");
-               parameters.Add (session);
+               parameters.Add (Convert.ToString (sourceSession));
+
+               if (destinationSession != 0) {
+                       parameters.Add ("--destination_session");
+                       parameters.Add (Convert.ToString (destinationSession));
+               }
 
                Result result = executeChronojumpImporter (parameters);
 
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 135af68..1bfa2b1 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2288,20 +2288,35 @@ public partial class ChronoJumpWindow
        //from import session
        private void on_load_session_accepted_to_import(object o, EventArgs args)
        {
-               int sessionNumber = sessionLoadWin.CurrentSessionId();
+               int sourceSession = sessionLoadWin.CurrentSessionId();
                string databasePath = sessionLoadWin.DatabasePath();
                LogB.Information (databasePath);
 
-               ImportSessionFromDatabase (databasePath, sessionNumber);
+               ImportSessionFromDatabase (databasePath, sourceSession, currentSession);
        }
 
-       private void ImportSessionFromDatabase(string databasePath, int sessionNumber)
+       private void ImportSessionFromDatabase(string databasePath, int sourceSession, Session 
destinationSession)
        {
                string source_filename = databasePath;
                string destination_filename = Sqlite.DatabaseFilePath;
-               string session = Convert.ToString (sessionNumber);
 
-               ChronojumpImporter chronojumpImporter = new ChronojumpImporter (source_filename, 
destination_filename, session);
+               int destinationSessionId;
+               if (destinationSession == null)
+               {
+                       destinationSessionId = 0;
+               }
+               else
+               {
+                       destinationSessionId = destinationSession.UniqueID;
+               }
+
+               ChronojumpImporter chronojumpImporter = new ChronojumpImporter (app1, source_filename, 
destination_filename, sourceSession, destinationSessionId);
+
+               Gtk.ResponseType response = chronojumpImporter.showDialogueToUser ();
+
+               if (response != Gtk.ResponseType.Ok) {
+                       return;
+               }
 
                ChronojumpImporter.Result result = chronojumpImporter.import ();
 
@@ -2320,7 +2335,7 @@ public partial class ChronoJumpWindow
                        //update stats combos
                        updateComboStats ();
 
-                       new DialogMessage (Constants.MessageTypes.INFO, Catalog.GetString ("Session 
imported."));
+                       chronojumpImporter.showImportCorrectlyFinished ();
                } else {
                        LogB.Debug ("Chronojump Importer error: ", result.error);
                        new DialogMessage (Constants.MessageTypes.WARNING, result.error);


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