Centrafuse Logo Flux Logo


Setup.cpp

See the Setup/Settings section for a detailed description of this example.

#include "Setup.h"

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Xml;
using namespace System::Web;
using namespace centrafuse::Plugins;

namespace HelloWorld
{

    // The setup constructor will be called each time this plugin's setup is opened from the CF Setting Page
    // This setup is opened as a dialog from the CF_pluginShowSetup() call into the main plugin application form.
        Setup::Setup()
    {
                PluginPath = "plugins\\HelloWorld\\";
                PluginPathLanguages = String::Concat(PluginPath, "Languages\\");
                ConfigurationFile = "config.xml";
                ConfigSection = "/APPCONFIG/";
                LanguageSection = "/APPLANG/SETUP/";
                LanguageControlSection = "/APPLANG/HELLOWORLD/";

        totalpages = 1;

        // If user has advanced settings turned on, then the CF_showAdvancedSettings flag will be set to true
        // Some plugins may require more pages for advanced settings, this must be determined by plugin developer.
        if (CF_showAdvancedSettings)
            totalpages = 1;

        // Current page when settings are opened is always 1
        currentpage = 1;

        // Builds the controls.
        buildControls();

                String^ configfilepath = String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile);

        // Loads the plugin configuration from the specified path.
        this->CF_loadConfig(configfilepath);

        // Loads the plugin language file from the specified path. This is loaded using the language 
        // specified in the configuration file.
                this->CF_loadLang(String::Concat(PluginPathLanguages, this->pluginConfig->readPluginField("/APPCONFIG/APPLANG"), ".xml"));

        // Loads the configuration file into the local XmlDocument.
                configxml = gcnew XmlDocument();
                languagexml = gcnew XmlDocument();
        configxml->Load(configfilepath);
        languagexml->Load(String::Concat(PluginPathLanguages, this->pluginConfig->readPluginField("/APPCONFIG/APPLANG"), ".xml"));
    }

    // This function can be called by the plugin application form after construction and after setting the MainForm property
    void Setup::setupSection()
    {
        // Build controls
        this->buildSetup();

        // Populate the setup page
        this->loadSetupPage();

        // Populate button texts
                this->CF_updateButtonText("OK", LanguageReader::getText("APPLANG/BUTTONS/SAVE"));
                this->CF_updateButtonText("CANCEL", LanguageReader::getText("APPLANG/BUTTONS/CANCEL"));
        this->CF_updateText("TITLE", this->pluginLang->readPluginField("/APPLANG/SETUP/TITLE"));
    }
        
        String^ Setup::readConfigValue(String^ xpath)
    {
        if (configxml->SelectSingleNode(xpath) != nullptr)
                        return System::Web::HttpUtility::HtmlDecode(configxml->SelectSingleNode(xpath)->InnerText);
        else
            return "";
    }

    void Setup::updateConfig(String^ xpath, String^ xvalue)
    {
        if (configxml->SelectSingleNode(xpath) != nullptr)
                        configxml->SelectSingleNode(xpath)->InnerText = HttpUtility::HtmlEncode(xvalue);
    }

    void Setup::buildControls()
    {
                this->CFSetup_ok += gcnew EventHandler(this, &Setup::section1_CFSetup_ok);
        this->CFSetup_cancel += gcnew EventHandler(this, &Setup::section1_CFSetup_cancel);
    }

    void Setup::readConfig()
    {
        try
        {
                        int i = SetupButton::One;

            if (CF_showAdvancedSettings)
            {
                /*******************************************************************************************/
                /*****  ADVANCED SETTINGS - PAGE 1  ********************************************************/
                /*******************************************************************************************/
                if (currentpage == 1)
                {

                    // TEXT BUTTONS (1-4)

                    ButtonHandler[i] = gcnew SettingsClickHandler(this, &Setup::SetDisplayName);
                    ButtonText[i] = this->pluginLang->readPluginField("APPLANG/SETUP/DISPLAYNAME");
                    ButtonValue[i++] = this->pluginLang->readPluginField("APPLANG/HELLOWORLD/DISPLAYNAME");

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    // BOOL BUTTONS (5-8)

                    ButtonHandler[i] = gcnew SettingsClickHandler(this, &Setup::SetLogEvents);
                    ButtonText[i] = this->pluginLang->readPluginField("/APPLANG/SETUP/LOGEVENTS");
                    ButtonValue[i++] = readConfigValue("/APPCONFIG/LOGEVENTS");

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";
                }
            }
            else
            {
                /*******************************************************************************************/
                /*****  BASIC SETTINGS - PAGE 1  ***********************************************************/
                /*******************************************************************************************/
                if (currentpage == 1)
                {

                    // TEXT BUTTONS (1-4)

                    ButtonHandler[i] = gcnew SettingsClickHandler(this, &Setup::SetDisplayName);
                    ButtonText[i] = this->pluginLang->readPluginField("APPLANG/SETUP/DISPLAYNAME");
                    ButtonValue[i++] = this->pluginLang->readPluginField("APPLANG/HELLOWORLD/DISPLAYNAME");

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    // BOOL BUTTONS (5-8)

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";

                    ButtonHandler[i] = nullptr;
                    ButtonText[i] = "";
                    ButtonValue[i++] = "";
                }
            }
        }
                catch (Exception^ errmsg) { CFTools::writeError(errmsg->Message, errmsg->StackTrace); }
    }

    void Setup::section1_CFSetup_ok(Object^ sender, EventArgs^ e)
    {
        // Launches system YesNo dialog to verify the user wants to overwrite their current settings.  If yes then the
        // local XML document is saved.
        Object^ tempobject;
        String^ temp, ^temp2;
        try
        {
                        if (this->CF_systemDisplayDialog(CF_Dialogs::YesNo, LanguageReader::getText("APPLANG/SETUP/OVERWRITETEXT"), nullptr, nullptr, temp, temp2, tempobject, nullptr, true, true, true, true, false, false, 1) == Windows::Forms::DialogResult::OK)
            {
                                configxml->Save(String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile));
                languagexml->Save(String::Concat(PluginPathLanguages, configxml->SelectSingleNode("/APPCONFIG/APPLANG")->InnerText, ".xml"));
                                this->DialogResult = Windows::Forms::DialogResult::OK;
            }
        }
                catch (Exception^ errmsg) { CFTools::writeError(errmsg->Message, errmsg->StackTrace); }
    }

    void Setup::section1_CFSetup_cancel(Object^ sender, EventArgs^ e)
    {
                this->DialogResult = Windows::Forms::DialogResult::Cancel;
    }

    void Setup::SetDisplayName(Object^% value)
    {
        try
        {
            Object^ tempobject;
            String^ resultvalue, ^resulttext;
                        if (this->CF_systemDisplayDialog(CF_Dialogs::OSK, this->pluginLang->readPluginField("/APPLANG/SETUP/DISPLAYNAME"), ButtonValue[(int)value], nullptr, resultvalue, resulttext, tempobject, nullptr, true, true, true, true, false, false, 1) == Windows::Forms::DialogResult::OK)
            {
                                languagexml->SelectSingleNode("/APPLANG/HELLOWORLD/DISPLAYNAME")->InnerText = HttpUtility::HtmlEncode(resultvalue);
                ButtonValue[(int)value] = resultvalue;
            }
        }
                catch (Exception^ errmsg) { CFTools::writeError(errmsg->Message, errmsg->StackTrace); }
    }

    void Setup::SetLogEvents(Object^% value)
    {
        updateConfig("/APPCONFIG/LOGEVENTS", value->ToString());
    }
}




Copyright © 2008 Flux Media, Inc. (U.S. Copyright Registration Number: TXu-1-239-794) Flux Logo