mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OP-232 gcs configuration: First step to configure all plugins in a standard way
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2632 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
b5426e09d0
commit
311bcdd492
@ -196,3 +196,12 @@ void CoreImpl::saveMainSettings(QSettings* qs)
|
||||
m_mainwindow->saveSettings(qs);
|
||||
}
|
||||
|
||||
void CoreImpl::readSettings(IConfigurablePlugin* plugin, QSettings* qs)
|
||||
{
|
||||
m_mainwindow->readSettings(plugin, qs);
|
||||
}
|
||||
void CoreImpl::saveSettings(IConfigurablePlugin* plugin, QSettings* qs)
|
||||
{
|
||||
m_mainwindow->saveSettings(plugin, qs);
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
SettingsDatabase *settingsDatabase() const;
|
||||
void readMainSettings(QSettings* qs);
|
||||
void saveMainSettings(QSettings* qs);
|
||||
void readSettings(IConfigurablePlugin* plugin, QSettings* qs = 0 );
|
||||
void saveSettings(IConfigurablePlugin* plugin, QSettings* qs = 0 );
|
||||
|
||||
QString resourcePath() const;
|
||||
|
||||
|
@ -125,7 +125,8 @@ HEADERS += mainwindow.h \
|
||||
uavgadgetdecorator.h \
|
||||
workspacesettings.h \
|
||||
uavconfiginfo.h \
|
||||
authorsdialog.h
|
||||
authorsdialog.h \
|
||||
iconfigurableplugin.h
|
||||
FORMS += dialogs/settingsdialog.ui \
|
||||
dialogs/shortcutsettings.ui \
|
||||
generalsettings.ui \
|
||||
|
@ -111,6 +111,7 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
QWidget *w = new QWidget(parent);
|
||||
m_page->setupUi(w);
|
||||
|
||||
/* TODO: Clean this: settings not used, Core::ICore::instance()->settings() shouldn't be used, since not externally configurable */
|
||||
QSettings* settings = Core::ICore::instance()->settings();
|
||||
fillLanguageBox();
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
#ifndef ICONFIGURABLEPLUGIN_H
|
||||
#define ICONFIGURABLEPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <coreplugin/uavconfiginfo.h>
|
||||
|
||||
#include <coreplugin/core_global.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class CORE_EXPORT IConfigurablePlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
public:
|
||||
// IConfigurablePlugin(QObject *parent = 0){}
|
||||
virtual ~IConfigurablePlugin() {}
|
||||
virtual void readConfig( QSettings* qSettings, UAVConfigInfo *configInfo) = 0;
|
||||
virtual void saveConfig(QSettings* qSettings, Core::UAVConfigInfo *configInfo) = 0;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
#endif // ICONFIGURABLEPLUGIN_H
|
@ -54,6 +54,7 @@ class VariableManager;
|
||||
class ThreadManager;
|
||||
class UAVGadgetManager;
|
||||
class UAVGadgetInstanceManager;
|
||||
class IConfigurablePlugin;
|
||||
|
||||
class CORE_EXPORT ICore : public QObject
|
||||
{
|
||||
@ -89,6 +90,8 @@ public:
|
||||
virtual SettingsDatabase *settingsDatabase() const = 0;
|
||||
virtual void readMainSettings(QSettings* qs) = 0;
|
||||
virtual void saveMainSettings(QSettings* qs) = 0;
|
||||
virtual void readSettings(IConfigurablePlugin* plugin, QSettings* qs = 0) = 0;
|
||||
virtual void saveSettings(IConfigurablePlugin* plugin, QSettings* qs = 0) = 0;
|
||||
|
||||
virtual QString resourcePath() const = 0;
|
||||
|
||||
|
@ -62,6 +62,7 @@
|
||||
#include "baseview.h"
|
||||
#include "ioutputpane.h"
|
||||
#include "icorelistener.h"
|
||||
#include "iconfigurableplugin.h"
|
||||
|
||||
#include <coreplugin/settingsdatabase.h>
|
||||
#include <utils/pathchooser.h>
|
||||
@ -998,13 +999,11 @@ static const char *colorKey = "Color";
|
||||
static const char *maxKey = "Maximized";
|
||||
static const char *fullScreenKey = "FullScreen";
|
||||
|
||||
void MainWindow::readSettings()
|
||||
{
|
||||
readSettings(m_settings);
|
||||
}
|
||||
|
||||
void MainWindow::readSettings(QSettings* qs)
|
||||
{
|
||||
if ( !qs ){
|
||||
qs = m_settings;
|
||||
}
|
||||
|
||||
m_actionManager->readSettings(qs);
|
||||
|
||||
@ -1036,13 +1035,13 @@ void MainWindow::readSettings(QSettings* qs)
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::saveSettings()
|
||||
{
|
||||
saveSettings(m_settings);
|
||||
}
|
||||
|
||||
void MainWindow::saveSettings(QSettings* qs)
|
||||
{
|
||||
if ( !qs ){
|
||||
qs = m_settings;
|
||||
}
|
||||
|
||||
m_workspaceSettings->saveSettings(qs);
|
||||
|
||||
qs->beginGroup(QLatin1String(settingsGroup));
|
||||
@ -1069,6 +1068,49 @@ void MainWindow::saveSettings(QSettings* qs)
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::readSettings(IConfigurablePlugin* plugin, QSettings* qs)
|
||||
{
|
||||
if ( !qs ){
|
||||
qs = m_settings;
|
||||
}
|
||||
|
||||
UAVConfigInfo configInfo;
|
||||
QObject* qo = reinterpret_cast<QObject *>(plugin);
|
||||
QString configName = qo->metaObject()->className();
|
||||
|
||||
qs->beginGroup("Plugins");
|
||||
qs->beginGroup(configName);
|
||||
configInfo.read(qs);
|
||||
configInfo.setNameOfConfigurable("Plugin-"+configName);
|
||||
qs->beginGroup("data");
|
||||
plugin->readConfig(qs, &configInfo);
|
||||
|
||||
qs->endGroup();
|
||||
qs->endGroup();
|
||||
qs->endGroup();
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::saveSettings(IConfigurablePlugin* plugin, QSettings* qs)
|
||||
{
|
||||
if ( !qs ){
|
||||
qs = m_settings;
|
||||
}
|
||||
|
||||
UAVConfigInfo configInfo;
|
||||
QString configName = plugin->metaObject()->className();
|
||||
|
||||
qs->beginGroup("Plugins");
|
||||
qs->beginGroup(configName);
|
||||
qs->beginGroup("data");
|
||||
plugin->saveConfig(qs, &configInfo);
|
||||
qs->endGroup();
|
||||
configInfo.save(qs);
|
||||
qs->endGroup();
|
||||
qs->endGroup();
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::addAdditionalContext(int context)
|
||||
{
|
||||
if (context == 0)
|
||||
|
@ -47,6 +47,7 @@ namespace Core {
|
||||
class ActionManager;
|
||||
class BaseMode;
|
||||
class BaseView;
|
||||
class IConfigurablePlugin;
|
||||
class IContext;
|
||||
class IMode;
|
||||
class IWizard;
|
||||
@ -93,8 +94,10 @@ public:
|
||||
void addContextObject(IContext *contex);
|
||||
void removeContextObject(IContext *contex);
|
||||
void resetContext();
|
||||
void readSettings(QSettings* qs);
|
||||
void saveSettings(QSettings* qs);
|
||||
void readSettings(QSettings* qs = 0);
|
||||
void saveSettings(QSettings* qs = 0);
|
||||
void readSettings(IConfigurablePlugin* plugin, QSettings* qs = 0);
|
||||
void saveSettings(IConfigurablePlugin* plugin, QSettings* qs = 0);
|
||||
void openFiles(const QStringList &fileNames);
|
||||
|
||||
Core::ActionManager *actionManager() const;
|
||||
@ -166,8 +169,6 @@ private:
|
||||
void registerDefaultActions();
|
||||
|
||||
void createWorkspaces();
|
||||
void readSettings();
|
||||
void saveSettings();
|
||||
|
||||
CoreImpl *m_coreImpl;
|
||||
UniqueIDManager *m_uniqueIDManager;
|
||||
|
@ -38,16 +38,20 @@
|
||||
#include <iostream>
|
||||
#include "qxttimer.h"
|
||||
|
||||
static const QString VERSION = "1.0.0";
|
||||
|
||||
//#define DEBUG_NOTIFIES
|
||||
|
||||
SoundNotifyPlugin::SoundNotifyPlugin()
|
||||
{
|
||||
phonon.mo = NULL;
|
||||
configured = false;
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
SoundNotifyPlugin::~SoundNotifyPlugin()
|
||||
{
|
||||
Core::ICore::instance()->saveSettings(this);
|
||||
if (phonon.mo != NULL)
|
||||
delete phonon.mo;
|
||||
// Do nothing
|
||||
@ -66,9 +70,77 @@ bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg)
|
||||
|
||||
void SoundNotifyPlugin::extensionsInitialized()
|
||||
{
|
||||
Core::ICore::instance()->readSettings(this);
|
||||
if ( !configured ){
|
||||
readConfig_0_0_0();
|
||||
}
|
||||
|
||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||
connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*)));
|
||||
removedNotifies.clear();
|
||||
connectNotifications();
|
||||
}
|
||||
|
||||
void SoundNotifyPlugin::saveConfig( QSettings* settings, UAVConfigInfo *configInfo){
|
||||
|
||||
configInfo->setVersion(VERSION);
|
||||
|
||||
settings->beginWriteArray("Current");
|
||||
settings->setArrayIndex(0);
|
||||
currentNotification.saveState(settings);
|
||||
settings->endArray();
|
||||
|
||||
settings->beginGroup("listNotifies");
|
||||
settings->remove("");
|
||||
settings->endGroup();
|
||||
|
||||
settings->beginWriteArray("listNotifies");
|
||||
for (int i = 0; i < lstNotifications.size(); i++) {
|
||||
settings->setArrayIndex(i);
|
||||
lstNotifications.at(i)->saveState(settings);
|
||||
}
|
||||
settings->endArray();
|
||||
settings->setValue(QLatin1String("EnableSound"), enableSound);
|
||||
|
||||
}
|
||||
|
||||
void SoundNotifyPlugin::readConfig( QSettings* settings, UAVConfigInfo *configInfo){
|
||||
|
||||
if ( configInfo->version() == UAVConfigVersion() ){
|
||||
// Just for migration to the new format.
|
||||
configured = false;
|
||||
return;
|
||||
}
|
||||
|
||||
settings->beginReadArray("Current");
|
||||
settings->setArrayIndex(0);
|
||||
currentNotification.restoreState(settings);
|
||||
settings->endArray();
|
||||
|
||||
// read list of notifications from settings
|
||||
int size = settings->beginReadArray("listNotifies");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings->setArrayIndex(i);
|
||||
NotifyPluginConfiguration* notification = new NotifyPluginConfiguration;
|
||||
notification->restoreState(settings);
|
||||
lstNotifications.append(notification);
|
||||
}
|
||||
settings->endArray();
|
||||
setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool());
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
||||
void SoundNotifyPlugin::readConfig_0_0_0(){
|
||||
|
||||
settings = Core::ICore::instance()->settings();
|
||||
settings->beginGroup(QLatin1String("NotifyPlugin"));
|
||||
|
||||
settings->beginReadArray("Current");
|
||||
settings->setArrayIndex(0);
|
||||
currentNotification.restoreState(settings);
|
||||
settings->endArray();
|
||||
|
||||
// read list of notifications from settings
|
||||
int size = settings->beginReadArray("listNotifies");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
@ -85,6 +157,8 @@ void SoundNotifyPlugin::extensionsInitialized()
|
||||
connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*)));
|
||||
removedNotifies.clear();
|
||||
connectNotifications();
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
||||
void SoundNotifyPlugin::onTelemetryManagerAdded(QObject* obj)
|
||||
@ -140,6 +214,8 @@ void SoundNotifyPlugin::updateNotificationList(QList<NotifyPluginConfiguration*>
|
||||
lstNotifications.clear();
|
||||
lstNotifications=list;
|
||||
connectNotifications();
|
||||
|
||||
Core::ICore::instance()->saveSettings(this);
|
||||
}
|
||||
|
||||
void SoundNotifyPlugin::connectNotifications()
|
||||
|
@ -28,15 +28,16 @@
|
||||
#define SOUNDNOTIFYPLUGIN_H
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <coreplugin/iconfigurableplugin.h>
|
||||
#include "uavtalk/telemetrymanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
#include "notifypluginconfiguration.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <phonon>
|
||||
|
||||
class NotifyPluginOptionsPage;
|
||||
class NotifyPluginConfiguration;
|
||||
|
||||
typedef struct {
|
||||
Phonon::MediaObject* mo;
|
||||
@ -44,7 +45,7 @@ typedef struct {
|
||||
bool firstPlay;
|
||||
} PhononObject, *pPhononObject;
|
||||
|
||||
class SoundNotifyPlugin : public ExtensionSystem::IPlugin
|
||||
class SoundNotifyPlugin : public Core::IConfigurablePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -53,11 +54,14 @@ public:
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void readConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo);
|
||||
void saveConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo);
|
||||
void shutdown();
|
||||
|
||||
|
||||
QList<NotifyPluginConfiguration*> getListNotifications() { return lstNotifications; }
|
||||
//void setListNotifications(QList<NotifyPluginConfiguration*>& list_notify) { }
|
||||
NotifyPluginConfiguration* getCurrentNotification(){ return ¤tNotification;}
|
||||
|
||||
bool getEnableSound() const { return enableSound; }
|
||||
void setEnableSound(bool value) {enableSound = value; }
|
||||
@ -65,6 +69,7 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
bool configured; // just for migration,delete later
|
||||
bool enableSound;
|
||||
QList< QList<Phonon::MediaSource>* > lstMediaSource;
|
||||
QStringList mediaSource;
|
||||
@ -79,6 +84,7 @@ private:
|
||||
QList<NotifyPluginConfiguration*> pendingNotifications;
|
||||
QList<NotifyPluginConfiguration*> removedNotifies;
|
||||
|
||||
NotifyPluginConfiguration currentNotification;
|
||||
NotifyPluginConfiguration* nowPlayingConfiguration;
|
||||
|
||||
QString m_field;
|
||||
@ -88,6 +94,7 @@ private:
|
||||
|
||||
bool playNotification(NotifyPluginConfiguration* notification);
|
||||
void checkNotificationRule(NotifyPluginConfiguration* notification, UAVObject* object);
|
||||
void readConfig_0_0_0();
|
||||
|
||||
private slots:
|
||||
void onTelemetryManagerAdded(QObject* obj);
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
|
||||
NotifyPluginConfiguration::NotifyPluginConfiguration(QObject *parent) :
|
||||
QObject(parent),
|
||||
isNowPlaying(0),
|
||||
firstStart(1),
|
||||
soundCollectionPath(""),
|
||||
@ -53,6 +54,27 @@ NotifyPluginConfiguration::NotifyPluginConfiguration(QObject *parent) :
|
||||
expireTimer = NULL;
|
||||
}
|
||||
|
||||
void NotifyPluginConfiguration::copyTo(NotifyPluginConfiguration* that) const
|
||||
{
|
||||
|
||||
that->isNowPlaying = isNowPlaying;
|
||||
that->firstStart = firstStart;
|
||||
that->soundCollectionPath = soundCollectionPath;
|
||||
that->currentLanguage = currentLanguage;
|
||||
that->soundCollectionPath = soundCollectionPath;
|
||||
that->dataObject = dataObject;
|
||||
that->objectField = objectField;
|
||||
that->value = value;
|
||||
that->sound1 = sound1;
|
||||
that->sound2 = sound2;
|
||||
that->sound3 = sound3;
|
||||
that->sayOrder = sayOrder;
|
||||
that->spinBoxValue = spinBoxValue;
|
||||
that->repeatString = repeatString;
|
||||
that->repeatTimeout = repeatTimeout;
|
||||
that->expireTimeout = expireTimeout;
|
||||
}
|
||||
|
||||
|
||||
void NotifyPluginConfiguration::saveState(QSettings* settings) const
|
||||
{
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
bool isNowPlaying; //
|
||||
bool firstStart;
|
||||
|
||||
void copyTo(NotifyPluginConfiguration*) const;
|
||||
|
||||
QString getSound1() const { return sound1; }
|
||||
void setSound1(QString text) {sound1 = text; }
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "notifypluginconfiguration.h"
|
||||
#include "ui_notifypluginoptionspage.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "utils/pathutils.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QtAlgorithms>
|
||||
@ -64,7 +65,6 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
delegateItems.clear();
|
||||
privListNotifications.clear();
|
||||
listSoundFiles.clear();
|
||||
|
||||
delegateItems << "Repeat Once"
|
||||
@ -79,9 +79,6 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
|
||||
|
||||
|
||||
settings = Core::ICore::instance()->settings();
|
||||
settings->beginGroup(QLatin1String("NotifyPlugin"));
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
@ -111,23 +108,18 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
|
||||
//emit resetNotification();
|
||||
|
||||
int size = settings->beginReadArray("listNotifies");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings->setArrayIndex(i);
|
||||
NotifyPluginConfiguration* notification = new NotifyPluginConfiguration;
|
||||
notification->restoreState(settings);
|
||||
|
||||
privListNotifications.clear();
|
||||
|
||||
for (int i = 0; i < owner->getListNotifications().size(); ++i) {
|
||||
NotifyPluginConfiguration* notification = new NotifyPluginConfiguration();
|
||||
owner->getListNotifications().at(i)->copyTo(notification);
|
||||
privListNotifications.append(notification);
|
||||
}
|
||||
settings->endArray();
|
||||
|
||||
settings->beginReadArray("Current");
|
||||
settings->setArrayIndex(0);
|
||||
NotifyPluginConfiguration notification;
|
||||
notification.restoreState(settings);
|
||||
updateConfigView(¬ification);
|
||||
settings->endArray();
|
||||
options_page->chkEnableSound->setChecked(settings->value(QLatin1String("EnableSound"),0).toBool());
|
||||
settings->endGroup();
|
||||
updateConfigView(owner->getCurrentNotification());
|
||||
|
||||
options_page->chkEnableSound->setChecked(owner->getEnableSound());
|
||||
|
||||
QStringList headerStrings;
|
||||
headerStrings << "Name" << "Repeats" << "Lifetime,sec";
|
||||
@ -214,29 +206,8 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotifyPluginConfiguration* no
|
||||
////////////////////////////////////////////
|
||||
void NotifyPluginOptionsPage::apply()
|
||||
{
|
||||
NotifyPluginConfiguration notification;
|
||||
|
||||
settings->beginGroup(QLatin1String("NotifyPlugin"));
|
||||
|
||||
getOptionsPageValues(¬ification);
|
||||
|
||||
settings->beginWriteArray("Current");
|
||||
settings->setArrayIndex(0);
|
||||
notification.saveState(settings);
|
||||
settings->endArray();
|
||||
|
||||
settings->beginGroup("listNotifies");
|
||||
settings->remove("");
|
||||
settings->endGroup();
|
||||
|
||||
settings->beginWriteArray("listNotifies");
|
||||
for (int i = 0; i < privListNotifications.size(); i++) {
|
||||
settings->setArrayIndex(i);
|
||||
privListNotifications.at(i)->saveState(settings);
|
||||
}
|
||||
settings->endArray();
|
||||
settings->setValue(QLatin1String("EnableSound"), options_page->chkEnableSound->isChecked());
|
||||
settings->endGroup();
|
||||
getOptionsPageValues(owner->getCurrentNotification());
|
||||
|
||||
owner->setEnableSound(options_page->chkEnableSound->isChecked());
|
||||
//owner->setListNotifications(privListNotifications);
|
||||
@ -352,7 +323,7 @@ void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notifi
|
||||
{
|
||||
//QDir dir = QDir::currentPath();
|
||||
//path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds";
|
||||
path = "../share/sounds";
|
||||
path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds");
|
||||
}
|
||||
options_page->SoundDirectoryPathChooser->setPath(path);
|
||||
|
||||
|
@ -76,7 +76,6 @@ public:
|
||||
private:
|
||||
UAVObjectManager *objManager;
|
||||
SoundNotifyPlugin* owner;
|
||||
QSettings* settings;
|
||||
QStringList listDirCollections;
|
||||
QStringList listSoundFiles;
|
||||
QString currentCollectionPath;
|
||||
|
Loading…
x
Reference in New Issue
Block a user