PluginTools: Plugin Configuration

AfterShot Pro Plugins
Post Reply
andreas
Posts: 154
Joined: Thu Jan 12, 2012 1:53 pm
operating_system: Linux
System_Drive: X
32bit or 64bit: 64 Bit
motherboard: Asus in Workstation and Dell XPS Notebook
processor: i7-980 and i7-2720QM
ram: 12GB - 8GB
Video Card: ATI FireGL
sound_card: on board
Hard_Drive_Capacity: 4.5TB Rd10
Monitor/Display Make & Model: Samsung Syncmaster 2343sw
Location: DE - Wermelskirchen
Contact:

PluginTools: Plugin Configuration

Post by andreas »

Hi,

the plugin SDK offers the info for a directory for plugin relevant data, resp. configuration files and so on. With

Code: Select all

git clone http://schrell.de/PluginTools.git
You can get code for a configuration interface which can be used by your plugin. You have to create a field for the configuration and create a configuration mapper for interaction with your config. It creates or uses a directory named like your plugin and a config file in there also named like your plugin. Here is my implementation when using it in asPluginManager:

Code: Select all

#pragma once

#include <QString>
#include <QObject>

#include "ConfigFile.h"

#include "PluginHub.h"
#include "PluginDependency.h"
#include "PluginImageSettings.h"
#include "PluginOptionList.h"

#define ASPM_CHECK_FOR_UPDATES "ASPM_CHECK_FOR_UPDATES"
#define ASPM_TOOLBOX_HEIGHT "ASPM_TOOLBOX_HEIGHT"

class ConfigurationMapper : public QObject {
        Q_OBJECT

    public:

        ConfigurationMapper(QString filename);

        bool getBool(const QString key, bool def);
        QString getString(const QString key, QString def);
        int getInt(const QString key, int def);

        void setString(const QString key, const QString val);

        bool checkForUpdates();

        int toolBoxHeight();

private:
        ConfigFile *m_cf;
};
and

Code: Select all

#include "ConfigurationMapper.h"

#include <QDebug>
#include <QString>
#include <QStringList>

#include "PluginHub.h"
#include "PluginDependency.h"
#include "PluginImageSettings.h"
#include "PluginOptionList.h"

#include "ConfigFile.h"

ConfigurationMapper::ConfigurationMapper(QString fileName) {
    m_cf = new ConfigFile(fileName);
    m_cf->autoWrite(true);
}

bool ConfigurationMapper::getBool(const QString key, bool def = false) {
    QString val = m_cf->getValue(key);
    if (val == 0) return def;
    return val == "true";
}

QString ConfigurationMapper::getString(const QString key, QString def = "") {
    QString val = m_cf->getValue(key);
    if (val == 0) return def;
    return val;
}

int ConfigurationMapper::getInt(const QString key, int def = 0) {
    QString val = m_cf->getValue(key);
    if (val == 0) return def;
    return val.toInt();
}

void ConfigurationMapper::setString(const QString key, const QString val) {
    m_cf->setValue(key, val);
}

bool ConfigurationMapper::checkForUpdates() {
    return getBool(ASPM_CHECK_FOR_UPDATES, true);
}

int ConfigurationMapper::toolBoxHeight() {
    return getInt(ASPM_TOOLBOX_HEIGHT, 400);
}
In your plugin code you have to initialize the configuration, after that you can read or set values. When setting values the config file is updated automatically.

Init:

Code: Select all

    QString configDir = m_hub->property("pluginStorageHome").toString() + "/asPluginManager";
    QDir qdir;
    qdir.mkdir(configDir);
    QString configPath = configDir + "/asPluginManager.conf";
    m_config = new ConfigurationMapper(configPath);
    if (m_config == NULL) {
        QMessageBox::information(NULL,"asPluginManager",tr("Configuration file problem with file:") + "<br/>" + configPath);
        return false;
    }
usage in your code:

Code: Select all

if (m_config->checkForUpdates()) {
...
}
...
uiWidget->setMinimumSize(100, min(height, m_config->toolBoxHeight()));
What will change in the near future:
  • A ConfigurationMapperBase will preimplement the getter and setter methods. Your will extend it with your own methods
  • Integrated dir/path management
It is possible to use this method both for configuration based on an ui like asGPS does or with config file changes only with a text editor. Like it is implemented in asPluginManager at the moment.

Andreas
Linux - not Windows
Post Reply