void on_button_new_clicked(object o, EventArgs args)
    {
        string selectedName = getSelectedName();

        if (selectedName == "")
        {
            return;
        }

        List <EncoderConfigurationSQLObject> list = SqliteEncoderConfiguration.Select(false, encoderGI, selectedName);

        if (list != null && list.Count == 1)
        {
            EncoderConfigurationSQLObject econfSO = list[0];
            econfSO.uniqueID = -1;             //to be entered as null and not repeat the uniqueID

            //add a suffix
            econfSO.name += "_" + Catalog.GetString("copy");
            //add more suffixes until name is unique
            econfSO.name = SqliteEncoderConfiguration.IfNameExistsAddSuffix(econfSO.name, Catalog.GetString("copy"));

            SqliteEncoderConfiguration.MarkAllAsUnactive(false, encoderGI);
            econfSO.active = true;
            SqliteEncoderConfiguration.Insert(false, econfSO);

            store.AppendValues(new string[] { econfSO.name, econfSO.description });
            UtilGtk.TreeviewSelectRowWithName(treeview_select, store, colName, econfSO.name, true);
        }
    }
示例#2
0
    //called on load signal
    //if does not found any encoderConfiguration then return one with -1 as uniqueID
    public static EncoderConfigurationSQLObject SelectByEconf(bool dbconOpened, Constants.EncoderGI encoderGI, EncoderConfiguration econf)
    {
        openIfNeeded(dbconOpened);

        dbcmd.CommandText = "SELECT * FROM " + Constants.EncoderConfigurationTable +
                            " WHERE encoderGI = \"" + encoderGI.ToString() + "\"" +
                            " AND encoderConfiguration LIKE \"" + econf.ToStringOutput(EncoderConfiguration.Outputs.SQLECWINCOMPARE) + "\"";
        LogB.SQL(dbcmd.CommandText.ToString());
        dbcmd.ExecuteNonQuery();

        SqliteDataReader reader;

        reader = dbcmd.ExecuteReader();

        EncoderConfigurationSQLObject econfSO = new EncoderConfigurationSQLObject();

        if (reader.Read())
        {
            econfSO = new EncoderConfigurationSQLObject(
                Convert.ToInt32(reader[0].ToString()),                          //uniqueID
                encoderGI,                                                      //encoderGI
                true,                                                           //active
                reader[3].ToString(),                                           //name
                econf,                                                          //encoderConfiguration
                reader[5].ToString()                                            //description
                );
        }
        reader.Close();
        Sqlite.Close();

        return(econfSO);
    }
    private void onTVSelectionChanged(object o, EventArgs args)
    {
        string selectedName = getSelectedName();

        if (selectedName == "")
        {
            return;
        }

        List <EncoderConfigurationSQLObject> list = SqliteEncoderConfiguration.Select(false, encoderGI, selectedName);

        if (list != null && list.Count == 1)
        {
            EncoderConfigurationSQLObject econfSO = list[0];
            entry_save_name.Text        = econfSO.name;
            entry_save_description.Text = econfSO.description;

            //mark all as unactive
            SqliteEncoderConfiguration.MarkAllAsUnactive(false, encoderGI);
            econfSO.active = true;
            //mark this as active
            SqliteEncoderConfiguration.Update(false, encoderGI, selectedName, econfSO);

            EncoderConfigurationWindowBox.updateGUIFromEncoderConfiguration(econfSO.encoderConfiguration);
        }
    }
    static public EncoderConfigurationWindow View(
        Constants.EncoderGI encoderGI, EncoderConfigurationSQLObject econfSO,
        string anchorage_str, int extraWeightN)
    {
        if (EncoderConfigurationWindowBox == null)
        {
            EncoderConfigurationWindowBox = new EncoderConfigurationWindow();
        }

        EncoderConfigurationWindowBox.encoderGI = encoderGI;
        EncoderConfigurationWindowBox.updateGUIFromEncoderConfiguration(econfSO.encoderConfiguration);
        EncoderConfigurationWindowBox.main_gui_anchorage_str = anchorage_str;
        EncoderConfigurationWindowBox.main_gui_extraWeightN  = extraWeightN;

        EncoderConfigurationWindowBox.createTreeView();
        EncoderConfigurationWindowBox.fillTreeView(
            SqliteEncoderConfiguration.Select(false, encoderGI, ""),                     //all
            econfSO);

        //A) side is hidden at start to ensure scr_treeview_select is scrolled and displays correctly the last row
        EncoderConfigurationWindowBox.notebook_side.Visible = false;

        EncoderConfigurationWindowBox.encoder_configuration.Show();

        //B) side is shown now, after showing the window in order to be displayed correctly (see A)
        EncoderConfigurationWindowBox.notebook_side.Visible = (EncoderConfigurationWindowBox.sideMode != sideModes.HIDDEN);

        return(EncoderConfigurationWindowBox);
    }
    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.encoderGI != encoderGI)
                    {
                        if (encoderGI == Constants.EncoderGI.GRAVITATORY)
                        {
                            new DialogMessage(Constants.MessageTypes.WARNING,
                                              Catalog.GetString("Chronojump is currently in gravitory mode.") + "\n" +
                                              Catalog.GetString("Selected configuration is inertial.") + "\n\n" +
                                              Catalog.GetString("If you still want to import it, change to inertial mode."));
                        }
                        else if (encoderGI == Constants.EncoderGI.INERTIAL)
                        {
                            new DialogMessage(Constants.MessageTypes.WARNING,
                                              Catalog.GetString("Chronojump is currently in inertial mode.") + "\n" +
                                              Catalog.GetString("Selected configuration is gravitatory.") + "\n\n" +
                                              Catalog.GetString("If you still want to import it, change to gravitatory mode."));
                        }
                    }
                    else if (econfSO.name != null && econfSO.name != "")
                    {
                        //add more suffixes until name is unique
                        econfSO.name = SqliteEncoderConfiguration.IfNameExistsAddSuffix(econfSO.name, "_" + Catalog.GetString("copy"));

                        SqliteEncoderConfiguration.MarkAllAsUnactive(false, encoderGI);
                        econfSO.active = true;
                        SqliteEncoderConfiguration.Insert(false, econfSO);

                        store.AppendValues(new string[] { econfSO.name, econfSO.description });
                        UtilGtk.TreeviewSelectRowWithName(treeview_select, store, colName, econfSO.name, 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();
    }
    private void fillTreeView(List <EncoderConfigurationSQLObject> list, EncoderConfigurationSQLObject currentSO)
    {
        foreach (EncoderConfigurationSQLObject econfSO in list)
        {
            store.AppendValues(new string[] { econfSO.name, econfSO.description });
        }

        UtilGtk.TreeviewSelectRowWithName(treeview_select, store, colName, currentSO.name, true);
    }
示例#7
0
    public static void Insert(bool dbconOpened, EncoderConfigurationSQLObject econfSO)
    {
        openIfNeeded(dbconOpened);

        dbcmd.CommandText = "INSERT INTO " + Constants.EncoderConfigurationTable +
                            " (uniqueID, encoderGI, active, name, encoderConfiguration, description, future1, future2, future3)" +
                            " VALUES (" + econfSO.ToSQLInsert() + ")";
        LogB.SQL(dbcmd.CommandText.ToString());
        dbcmd.ExecuteNonQuery();

        closeIfNeeded(dbconOpened);
    }
    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();
    }
示例#9
0
    //if by any bug there's no active, then create default
    public static EncoderConfigurationSQLObject SelectActive(Constants.EncoderGI encoderGI)
    {
        Sqlite.Open();

        dbcmd.CommandText = "SELECT * FROM " + Constants.EncoderConfigurationTable +
                            " WHERE encoderGI = \"" + encoderGI.ToString() + "\" AND active = \"True\"";
        LogB.SQL(dbcmd.CommandText.ToString());
        dbcmd.ExecuteNonQuery();

        SqliteDataReader reader;

        reader = dbcmd.ExecuteReader();

        EncoderConfigurationSQLObject econfSO = new EncoderConfigurationSQLObject();

        bool success = false;

        if (reader.Read())
        {
            string []            strFull = reader[4].ToString().Split(new char[] { ':' });
            EncoderConfiguration econf   = new EncoderConfiguration(
                (Constants.EncoderConfigurationNames)
                Enum.Parse(typeof(Constants.EncoderConfigurationNames), strFull[0]));
            econf.ReadParamsFromSQL(strFull);

            econfSO = new EncoderConfigurationSQLObject(
                Convert.ToInt32(reader[0].ToString()),                          //uniqueID
                encoderGI,                                                      //encoderGI
                true,                                                           //active
                reader[3].ToString(),                                           //name
                econf,                                                          //encoderConfiguration
                reader[5].ToString()                                            //description
                );
            success = true;
        }
        reader.Close();

        //if by any bug there's no active, then create default and call himself again to select
        if (!success)
        {
            insertDefault(encoderGI);
            Sqlite.Close();
            return(SelectActive(encoderGI));
        }

        Sqlite.Close();

        return(econfSO);
    }
示例#10
0
    //pass customName = "" to select all
    public static List <EncoderConfigurationSQLObject> Select(bool dbconOpened, Constants.EncoderGI encoderGI, string name)
    {
        openIfNeeded(dbconOpened);

        string nameStr = "";

        if (name != "")
        {
            nameStr = " AND name = \"" + name + "\"";
        }

        dbcmd.CommandText = "SELECT * FROM " + Constants.EncoderConfigurationTable +
                            " WHERE encoderGI = \"" + encoderGI.ToString() + "\"" + nameStr;
        LogB.SQL(dbcmd.CommandText.ToString());
        dbcmd.ExecuteNonQuery();

        List <EncoderConfigurationSQLObject> list = new List <EncoderConfigurationSQLObject>();
        SqliteDataReader reader;

        reader = dbcmd.ExecuteReader();
        while (reader.Read())
        {
            string []            strFull = reader[4].ToString().Split(new char[] { ':' });
            EncoderConfiguration econf   = new EncoderConfiguration(
                (Constants.EncoderConfigurationNames)
                Enum.Parse(typeof(Constants.EncoderConfigurationNames), strFull[0]));
            econf.ReadParamsFromSQL(strFull);

            EncoderConfigurationSQLObject econfSO = new EncoderConfigurationSQLObject(
                Convert.ToInt32(reader[0].ToString()),                          //uniqueID
                encoderGI,                                                      //encoderGI
                reader[2].ToString() == "True",                                 //active
                reader[3].ToString(),                                           //name
                econf,                                                          //encoderConfiguration
                reader[5].ToString()                                            //description
                );

            list.Add(econfSO);
        }

        reader.Close();
        closeIfNeeded(dbconOpened);

        return(list);
    }
    private void apply(bool updateGUI)
    {
        //useful fo update SQL
        string selectedOldName = getSelectedName();

        if (selectedOldName == "")
        {
            return;
        }

        string newName = entry_save_name.Text;

        if (newName != selectedOldName)
        {
            /*
             * if name has changed, then check if newname already exists on database
             * if exists add _copy recursively
             */
            newName = SqliteEncoderConfiguration.IfNameExistsAddSuffix(newName, Catalog.GetString("copy"));
        }
        //update entry_save_name if needed
        if (newName != entry_save_name.Text)
        {
            entry_save_name.Text = newName;
        }

        //update SQL
        EncoderConfiguration          econfOnGUI = GetAcceptedValues();
        EncoderConfigurationSQLObject econfSO    = new EncoderConfigurationSQLObject(-1,
                                                                                     encoderGI, true, newName,
                                                                                     econfOnGUI, entry_save_description.Text.ToString());

        SqliteEncoderConfiguration.Update(false, encoderGI, selectedOldName, econfSO);

        if (updateGUI)
        {
            TreeModel model;
            TreeIter  iter = new TreeIter();
            treeview_select.Selection.GetSelected(out model, out iter);
            store.SetValue(iter, colName, newName);
            store.SetValue(iter, colDescription, entry_save_description.Text);
        }
    }
示例#12
0
    //called on gui/encoderConfiguration.cs when click on save
    //also on load set
    public static void Update(bool dbconOpened, Constants.EncoderGI encoderGI, string oldName, EncoderConfigurationSQLObject econfSO)
    {
        openIfNeeded(dbconOpened);

        dbcmd.CommandText = "UPDATE " + Constants.EncoderConfigurationTable +
                            " SET active = \"" + econfSO.active + "\", name = \"" + econfSO.name + "\", " +
                            " encoderConfiguration = \"" + econfSO.encoderConfiguration.ToStringOutput(EncoderConfiguration.Outputs.SQL) + "\", " +
                            " description = \"" + econfSO.description + "\"" +
                            " WHERE name = \"" + oldName + "\" AND encoderGI = \"" + encoderGI.ToString() + "\"";
        LogB.SQL(dbcmd.CommandText.ToString());
        dbcmd.ExecuteNonQuery();

        closeIfNeeded(dbconOpened);
    }