[chronojump] EnocoderConfiguration import working



commit a6fac425b5159b3aac004c54bad8d387c0fc4f7c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Dec 31 03:18:46 2016 +0100

    EnocoderConfiguration import working

 src/encoder.cs                  |   39 +++++++++++++++++++++++++++++++++++++++
 src/gui/encoderConfiguration.cs |   39 +++++++++++++++++++++++++++++++++++++--
 src/utilGtk.cs                  |   32 +++++++++++++++++++++++++++++++-
 3 files changed, 107 insertions(+), 3 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index 71e0637..70d11a0 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -1071,6 +1071,45 @@ public class EncoderConfigurationSQLObject
                this.description = description;
        }
 
+       //imports from file
+       public EncoderConfigurationSQLObject(string contents)
+       {
+               string line;
+               using (StringReader reader = new StringReader (contents)) {
+                       do {
+                               line = reader.ReadLine ();
+
+                               if (line == null)
+                                       break;
+                               if (line == "" || line[0] == '#')
+                                       continue;
+
+                               string [] parts = line.Split(new char[] {'='});
+                               if(parts.Length != 2)
+                                       continue;
+
+                               uniqueID = -1;
+                               if(parts[0] == "customName" && parts[1] != "")
+                                       customName = parts[1];
+                               else if(parts[0] == "EncoderConfiguration")
+                               {
+                                       string [] ecFull = parts[1].Split(new char[] {':'});
+                                       if(Enum.IsDefined(typeof(Constants.EncoderConfigurationNames), 
ecFull[0]))
+                                       {
+                                               //create object
+                                               encoderConfiguration = new EncoderConfiguration(
+                                                               (Constants.EncoderConfigurationNames)
+                                                               
Enum.Parse(typeof(Constants.EncoderConfigurationNames), ecFull[0]) );
+                                               //assign the rest of params
+                                               encoderConfiguration.ReadParamsFromSQL(ecFull);
+                                       }
+                               }
+                               else if(parts[0] == "description" && parts[1] != "")
+                                       description = parts[1];
+                       } while(true);
+               }
+       }
+
        public string ToSQLInsert()
        {
                 string idStr = uniqueID.ToString();
diff --git a/src/gui/encoderConfiguration.cs b/src/gui/encoderConfiguration.cs
index 29b8aa3..7a018a5 100644
--- a/src/gui/encoderConfiguration.cs
+++ b/src/gui/encoderConfiguration.cs
@@ -558,14 +558,15 @@ public class EncoderConfigurationWindow
         * <--------------- side content area / load-save ---->
         */
 
+       TreeStore store;
        private void createAndFillTreeView(List<EncoderConfigurationSQLObject> list)
        {
                createTreeView();
-               TreeStore store = getStore();
+               store = getStore();
                treeview_select.Model = store;
 
                foreach (EncoderConfigurationSQLObject econfSO in list)
-                       store.AppendValues (new string[]{econfSO.customName, econfSO.description});
+                       store.AppendValues (new string[]{ econfSO.customName, econfSO.description });
 
                Pixbuf pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "stock_delete.png");
                image_delete.Pixbuf = pixbuf;
@@ -621,6 +622,40 @@ public class EncoderConfigurationWindow
 
        void on_button_import_clicked (object o, EventArgs args)
        {
+               Gtk.FileChooserDialog fc=
+                       new Gtk.FileChooserDialog(Catalog.GetString("Select file to import"),
+                                       encoder_configuration,
+                                       FileChooserAction.Open,
+                                       Catalog.GetString("Cancel"),ResponseType.Cancel,
+                                       Catalog.GetString("Accept"),ResponseType.Accept
+                                       );
+
+               fc.Filter = new FileFilter();
+               fc.Filter.AddPattern("*.txt");
+
+               if (fc.Run() == (int)ResponseType.Accept)
+               {
+                       try {
+                               string contents = Util.ReadFile(fc.Filename, false);
+                               if (contents != null && contents != "")
+                               {
+                                       EncoderConfigurationSQLObject econfSO = new 
EncoderConfigurationSQLObject(contents);
+                                       if(econfSO.customName != null && econfSO.customName != "") //TODO: 
check if name exists
+                                       {
+                                               //TODO: add depending on inertial. If doesn't match show 
error message
+                                               SqliteEncoder.InsertEncoderConfiguration(false, econfSO);
+                                               store.AppendValues (new string[]{ econfSO.customName, 
econfSO.description });
+                                               UtilGtk.TreeviewSelectRowWithName(treeview_select, store, 0, 
econfSO.customName, true);
+                                       }
+                               }
+                       }
+                       catch {
+                               LogB.Warning("Catched! Configuration cannot be imported");
+                               new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("Error 
importing data."));
+                       }
+               }
+               //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
+               fc.Destroy();
        }
 
        void on_button_save_clicked (object o, EventArgs args)
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 894c600..c61a4e6 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -247,7 +247,8 @@ public class UtilGtk
        }
 
        //finds the row number (starting at 0) of a cell (usually an uniqueID in col 0)
-       private static int getRowNumOfThisID(Gtk.TreeStore store, int colNum, int searchedID) {
+       private static int getRowNumOfThisID(Gtk.TreeStore store, int colNum, int searchedID)
+       {
                TreeIter iter;
                int count = 0;
                bool iterOk = store.GetIterFirst(out iter);
@@ -262,6 +263,23 @@ public class UtilGtk
                return -1;
        }
 
+       //finds the row number (starting at 0) of a cell
+       private static int getRowNumOfThisName(Gtk.TreeStore store, int colNum, string searchedName)
+       {
+               TreeIter iter;
+               int count = 0;
+               bool iterOk = store.GetIterFirst(out iter);
+               while(iterOk) {
+                       string thisName = (string) store.GetValue (iter, colNum);
+                       if(thisName == searchedName)
+                               return count;
+
+                       count ++;
+                       iterOk = store.IterNext(ref iter);
+               }
+               return -1;
+       }
+
        //selects a row that has an uniqueID (usually at col 0)
        public static bool TreeviewSelectRowWithID(Gtk.TreeView tv, Gtk.TreeStore store, int colNum, int id, 
bool scrollToRow)
        {
@@ -269,6 +287,18 @@ public class UtilGtk
                        return false;
 
                int rowNum = getRowNumOfThisID(store, colNum, id);
+               return TreeviewSelectRow(tv, store, rowNum, scrollToRow);
+       }
+       public static bool TreeviewSelectRowWithName(Gtk.TreeView tv, Gtk.TreeStore store, int colNum, string 
name, bool scrollToRow)
+       {
+               if(name == null || name == "")
+                       return false;
+
+               int rowNum = getRowNumOfThisName(store, colNum, name);
+               return TreeviewSelectRow(tv, store, rowNum, scrollToRow);
+       }
+       private static bool TreeviewSelectRow(Gtk.TreeView tv, Gtk.TreeStore store, int rowNum, bool 
scrollToRow)
+       {
                if(rowNum == -1)
                        return false;
 


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