[chronojump] EncoderConfiguration export. Done!
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] EncoderConfiguration export. Done!
- Date: Wed, 11 Jan 2017 13:51:01 +0000 (UTC)
commit fceae5e2a04aaf27d2e0f682bea7072b07129715
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Jan 11 14:50:22 2017 +0100
EncoderConfiguration export. Done!
glade/encoder_configuration.glade | 79 +++++++++++++++++++++++++++++++++---
src/encoder.cs | 25 ++++++++++++
src/gui/encoderConfiguration.cs | 78 ++++++++++++++++++++++++++++++++++++
src/util.cs | 3 +
4 files changed, 178 insertions(+), 7 deletions(-)
---
diff --git a/glade/encoder_configuration.glade b/glade/encoder_configuration.glade
index c0184b7..1c3aa90 100644
--- a/glade/encoder_configuration.glade
+++ b/glade/encoder_configuration.glade
@@ -1160,32 +1160,97 @@ Eg. value = 2, means person does twice force at half speed.</property>
<property name="label_yalign">0.69999998807907104</property>
<property name="shadow_type">out</property>
<child>
- <widget class="GtkHButtonBox" id="hbuttonbox3">
+ <widget class="GtkHBox" id="hbox15">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="border_width">8</property>
+ <property name="border_width">6</property>
<child>
<widget class="GtkButton" id="button_import">
- <property name="label" translatable="yes">Import</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <property name="tooltip" translatable="yes">Import</property>
<signal name="clicked" handler="on_button_import_clicked" swapped="no"/>
+ <child>
+ <widget class="GtkImage" id="image_import">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-new</property>
+ </widget>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
- <property name="fill">True</property>
+ <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <widget class="GtkButton" id="button_export">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip" translatable="yes">Export</property>
+ <signal name="clicked" handler="on_button_export_clicked" swapped="no"/>
+ <child>
+ <widget class="GtkImage" id="image_export">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-convert</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
</child>
<child>
- <widget class="GtkLabel" id="label27">
+ <widget class="GtkHBox" id="hbox9">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label" translatable="yes">Import</property>
- <property name="use_markup">True</property>
+ <property name="spacing">6</property>
+ <child>
+ <widget class="GtkLabel" id="label27">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Import</property>
+ <property name="use_markup">True</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="label34">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">/</property>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label37">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Export</property>
+ <property name="use_markup">True</property>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="type">label_item</property>
diff --git a/src/encoder.cs b/src/encoder.cs
index 26b4487..a10e754 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -1146,6 +1146,31 @@ public class EncoderConfigurationSQLObject
", \"" + description + "\"" +
", \"\", \"\", \"\""; //future1, future2, future3
}
+
+ public string ToFile()
+ {
+ return
+ "#Case sensitive!\n" +
+ "#Comments start with sharp sign\n" +
+ "#Options are key/values with an = separating them\n" +
+ "#DO NOT write comments in the same line than key/value pairs\n" +
+ "#\n" +
+ "#DO NOT WRITE SPACES JUST BEFORE OR AFTER THE '=' SIGN\n" +
+ "#This work:\n" +
+ "#name=My encoder config\n" +
+ "#This doesn't work:\n" +
+ "#name= My encoder config\n" +
+ "#\n" +
+ "#Whitelines are allowed\n" +
+ "\nname=" + name + "\n" +
+ "description=" + description + "\n" +
+ "\n#encoderGI must be GRAVITATORY or INERTIAL\n" +
+ "encoderGI=" + encoderGI.ToString() + "\n" +
+ "\n#EncoderConfiguration if exists, this will be used and cannot be changed\n" +
+"#name:d:D:anglePush:angleWeight:inertiaMachine:gearedDown:inertiaTotal:extraWeightN:extraWeightGrams:extraWeightLenght:list_d\n"
+
+"#list_d is list of anchorages in centimeters. each value separated by '_' . Decimal separator is '.'\n" +
+ "EncoderConfiguration=" +
encoderConfiguration.ToStringOutput(EncoderConfiguration.Outputs.SQL);
+ }
}
public class EncoderConfiguration
diff --git a/src/gui/encoderConfiguration.cs b/src/gui/encoderConfiguration.cs
index 8134d68..a033493 100644
--- a/src/gui/encoderConfiguration.cs
+++ b/src/gui/encoderConfiguration.cs
@@ -19,6 +19,7 @@
*/
using System;
+using System.IO;
using System.Collections;
using System.Collections.Generic; //List<T>
using Gtk;
@@ -673,6 +674,83 @@ public class EncoderConfigurationWindow
fc.Destroy();
}
+ string exportFileName;
+ void on_button_export_clicked (object o, EventArgs args)
+ {
+ Gtk.FileChooserDialog fc=
+ new Gtk.FileChooserDialog(Catalog.GetString("Export to file"),
+ encoder_configuration,
+ FileChooserAction.Save,
+ Catalog.GetString("Cancel"),ResponseType.Cancel,
+ Catalog.GetString("Accept"),ResponseType.Accept
+ );
+
+ if (fc.Run() == (int)ResponseType.Accept)
+ {
+ exportFileName = fc.Filename;
+ exportFileName = Util.AddTxtIfNeeded(exportFileName);
+
+ try {
+ if (File.Exists(exportFileName)) {
+ LogB.Information(string.Format(
+ "File {0} exists with attributes {1}, created
at {2}",
+ exportFileName,
+ File.GetAttributes(exportFileName),
+ File.GetCreationTime(exportFileName)));
+ LogB.Information("Overwrite...");
+ ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString(
+ "Are you sure you want to overwrite file: "),
"",
+ exportFileName);
+
+ confirmWin.Button_accept.Clicked +=
+ new EventHandler(on_overwrite_file_export_accepted);
+ } else {
+ on_file_export_accepted();
+
+ string myString = string.Format(Catalog.GetString("Saved to {0}"),
+ exportFileName);
+ new DialogMessage(Constants.MessageTypes.INFO, myString);
+ }
+ }
+ catch {
+ string myString = string.Format(
+ Catalog.GetString("Cannot save file {0} "), exportFileName);
+ new DialogMessage(Constants.MessageTypes.WARNING, myString);
+ }
+ }
+ else {
+ LogB.Information("cancelled");
+ new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Cancelled."));
+ fc.Hide ();
+ return ;
+ }
+
+ //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
+ fc.Destroy();
+
+ return;
+ }
+ private void on_overwrite_file_export_accepted(object o, EventArgs args)
+ {
+ on_file_export_accepted();
+
+ string myString = string.Format(Catalog.GetString("Saved to {0}"), exportFileName);
+ new DialogMessage(Constants.MessageTypes.INFO, myString);
+ }
+ private void on_file_export_accepted()
+ {
+ TextWriter writer = File.CreateText(exportFileName);
+
+ EncoderConfiguration econfOnGUI = GetAcceptedValues();
+ EncoderConfigurationSQLObject econfSO = new EncoderConfigurationSQLObject(-1,
+ encoderGI, true, entry_save_name.Text.ToString(),
+ econfOnGUI, entry_save_description.Text.ToString());
+ writer.Write(econfSO.ToFile());
+
+ writer.Close();
+ ((IDisposable)writer).Dispose();
+ }
+
//TODO: button_apply sensitive only when name != "" && != of the others
void on_button_apply_clicked (object o, EventArgs args)
{
diff --git a/src/util.cs b/src/util.cs
index c926679..fe9ec35 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1521,6 +1521,9 @@ public class Util
public static string AddPngIfNeeded(string myFile) {
return addExtensionIfNeeded(myFile, ".png");
}
+ public static string AddTxtIfNeeded(string myFile) {
+ return addExtensionIfNeeded(myFile, ".txt");
+ }
private static string addExtensionIfNeeded(string myFile, string extension)
{
int posOfDot = myFile.LastIndexOf('.');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]