[chronojump] When importing a session: shows the session name in the information dialog.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] When importing a session: shows the session name in the information dialog.
- Date: Tue, 25 Oct 2016 21:48:49 +0000 (UTC)
commit 6937e1f3e9c966cd4040b00bdb8b854bac69bcf2
Author: Carles Pina i Estany <carles pina cat>
Date: Tue Oct 25 23:48:08 2016 +0200
When importing a session: shows the session name in the information dialog.
src/chronojump-importer/chronojump_importer.py | 3 +-
src/chronojumpImporter.cs | 55 +++++++++++++++++++----
src/gui/chronojump.cs | 2 +-
3 files changed, 48 insertions(+), 12 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index 28d9abe..398d950 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -662,7 +662,8 @@ def json_information(database_path):
data = {'uniqueID': session.get('uniqueID'),
'date': session.get('date'),
'place': session.get('place'),
- 'comments': session.get('comments')
+ 'comments': session.get('comments'),
+ 'name': session.get('name')
}
information['sessions'].append(data)
diff --git a/src/chronojumpImporter.cs b/src/chronojumpImporter.cs
index e7260e9..8bd4683 100644
--- a/src/chronojumpImporter.cs
+++ b/src/chronojumpImporter.cs
@@ -75,17 +75,18 @@ class ChronojumpImporter
// 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()
+ public Gtk.ResponseType showImportConfirmation()
{
string message;
+ string sessionName = getSessionName (sourceFile, sourceSession);
string sessionInformation = String.Format (Catalog.GetString ("Session name: {0}\n" +
- "from file: {1}"), sourceSession, sourceFile);
+ "from file: {1}"), sessionName, sourceFile);
if (importsToNew()) {
message = Catalog.GetString ("A new session will be created with the data from:" +
"\n" +
sessionInformation + "\n\n" +
- Catalog.GetString ("(if you would like to import into an existing session
then Cancel, Load the session that you would like to import into and import it)"));
+ Catalog.GetString ("(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)"));
} else {
message = String.Format (Catalog.GetString ("The current session will be modified.
The data from:") + "\n" +
sessionInformation + "\n" +
@@ -195,8 +196,12 @@ class ChronojumpImporter
Sqlite.Connect ();
}
- private Result getDatabaseVersionFromFile(string filePath)
+ private static Result getImporterInformation(string filePath)
{
+ // If Result.success == true Result.output contains a valid JSON string.
+ // It's a string and not a JsonValue for convenience with other methods (at the moment).
+ // If result.success == false then result.error will contain the error that might help
+ // the user to fix the problem or Chronojump support/developers to fix the problem.
List<string> parameters = new List<string> ();
parameters.Add ("--source");
@@ -206,23 +211,53 @@ class ChronojumpImporter
Result result = executeChronojumpImporter (parameters);
if (result.success) {
- JsonValue json = "";
try {
- json = JsonValue.Parse (result.output);
+ JsonValue.Parse (result.output);
} catch (Exception e) {
return new Result(false, "",
String.Format(Catalog.GetString("getDatabaseVersionFromFile: invalid JSON content:\n{0}\nException. {1}"),
result.output, e.Message));
}
- string databaseVersion = json ["databaseVersion"];
-
- return new Result (true, databaseVersion);
+ return new Result (true, result.output);
} else {
return new Result(false, "",
String.Format(Catalog.GetString("getDatabaseVersionFromFile: no success fetching the database version
of:\n{0}\nError: {1}"), filePath, result.error));
}
}
- private Result executeChronojumpImporter(List<string> parameters)
+ private static string getSessionName(string filePath, int sessionId)
+ {
+ Result information = getImporterInformation (filePath);
+ if (information.success == false) {
+ // This shouldn't happen, other getImporterInformation is used in different ways.
+ LogB.Information ("chronojumpImporter::getSessionName failed. Output:" +
information.output + "Error:" + information.error);
+ return "UNKNOWN";
+ } else {
+ JsonValue json = JsonValue.Parse (information.output);
+
+ foreach(JsonValue session in json["sessions"])
+ {
+ if (session ["uniqueID"] == sessionId) {
+ return session ["name"];
+ }
+ }
+ LogB.Information ("Trying to import a session that we can't find the name. Output:" +
information.output);
+ return "UNKNOWN";
+ }
+ }
+
+ private Result getDatabaseVersionFromFile(string filePath)
+ {
+ Result information = getImporterInformation (filePath);
+
+ if (information.success) {
+ JsonValue json = JsonValue.Parse (information.output);
+ return new Result (true, json ["databaseVersion"]);
+ } else {
+ return information;
+ }
+ }
+
+ private static Result executeChronojumpImporter(List<string> parameters)
{
string importer_executable;
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 1bfa2b1..d91c2ae 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2312,7 +2312,7 @@ public partial class ChronoJumpWindow
ChronojumpImporter chronojumpImporter = new ChronojumpImporter (app1, source_filename,
destination_filename, sourceSession, destinationSessionId);
- Gtk.ResponseType response = chronojumpImporter.showDialogueToUser ();
+ Gtk.ResponseType response = chronojumpImporter.showImportConfirmation ();
if (response != Gtk.ResponseType.Ok) {
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]