1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-10 18:24:11 +01:00

OP-99 Import/Export: Prepare for version compatibility.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1598 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
erhard 2010-09-12 15:51:14 +00:00 committed by erhard
parent ba34bb8c24
commit ddf6ee46ee
5 changed files with 298 additions and 6 deletions

View File

@ -61,7 +61,8 @@ SOURCES += mainwindow.cpp \
uavgadgetinstancemanager.cpp \
uavgadgetoptionspagedecorator.cpp \
uavgadgetdecorator.cpp \
workspacesettings.cpp
workspacesettings.cpp \
uavconfiginfo.cpp
HEADERS += mainwindow.h \
tabpositionindicator.h \
fancyactionbar.h \
@ -119,7 +120,8 @@ HEADERS += mainwindow.h \
uavgadgetinstancemanager.h \
uavgadgetoptionspagedecorator.h \
uavgadgetdecorator.h \
workspacesettings.h
workspacesettings.h \
uavconfiginfo.h
FORMS += dialogs/settingsdialog.ui \
dialogs/shortcutsettings.ui \
generalsettings.ui \

View File

@ -0,0 +1,186 @@
/**
******************************************************************************
*
* @file uavconfiginfo.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup CorePlugin Core Plugin
* @{
* @brief The Core GCS plugin
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "uavconfiginfo.h"
#include <QMessageBox>
#define VERSION_DEFAULT "0.0.0"
#define TEXT_MINOR_LOSS_OF_CONFIGURATION tr( \
" Some of the configured features might not be supported \
by your version of the plugin. You might want to upgrade the plugin.")
#define TEXT_MISSING_CONFIGURATION tr( \
" Some configuration is missing in the imported config and will be replaced \
by default settings. It's probably an old config.")
#define TEXT_MAJOR_LOSS_OF_CONFIGURATION tr( \
" Major features can't be imported \
by your version of the plugin. You should upgrade the plugin to import these settings.")
#define TEXT_NOT_COMPATIBLE tr( \
" The imported settings are not compatible with this plugin and won't be imported!")
using namespace Core;
UAVConfigInfo::UAVConfigInfo(QSettings *qs, QObject *parent) :
QObject(parent),
m_version(VERSION_DEFAULT)
{
qs->beginGroup("configInfo");
m_version = UAVConfigVersion( qs->value("version", VERSION_DEFAULT ).toString());
qs->endGroup();
}
UAVConfigInfo::UAVConfigInfo(UAVConfigVersion version, QString nameOfConfigurable, QObject *parent) :
QObject(parent),
m_version(version),
m_nameOfConfigurable(nameOfConfigurable)
{
}
void UAVConfigInfo::save(QSettings *qs)
{
qs->beginGroup("configInfo");
qs->setValue("version", m_version.toString());
qs->endGroup();
}
bool UAVConfigInfo::askToAbort(int compat, QString message)
{
QMessageBox msgBox;
msgBox.setInformativeText(tr("Do you want to continue the import?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
int result;
switch(compat){
case FullyCompatible:
return false;
case MinorLossOfConfiguration:
msgBox.setText(tr("INFO: ") + message + TEXT_MINOR_LOSS_OF_CONFIGURATION);
msgBox.setDefaultButton(QMessageBox::Ok);
result = msgBox.exec();
break;
case MissingConfiguration:
msgBox.setText(tr("WARNING: ") + message + TEXT_MISSING_CONFIGURATION);
msgBox.setDefaultButton(QMessageBox::Ok);
result = msgBox.exec();
break;
case MajorLossOfConfiguration:
msgBox.setText(tr("ERROR: ") + message + TEXT_MAJOR_LOSS_OF_CONFIGURATION);
msgBox.setDefaultButton(QMessageBox::Cancel);
result = msgBox.exec();
break;
case NotCompatible:
msgBox.setText("ERROR: " + message + TEXT_NOT_COMPATIBLE);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return true;
default:
msgBox.setText("INTERNAL ERROR: " + message + tr("Unknown compatibility level: " + compat));
}
if ( result == QMessageBox::Ok )
return false;
else
return true;
}
void UAVConfigInfo::notifyAbort(QString message)
{
QMessageBox msgBox;
msgBox.setText(message);
msgBox.exec();
}
int UAVConfigInfo::checkCompatibilityWith(UAVConfigVersion programVersion)
{
if ( m_version.majorNr != programVersion.majorNr )
return NotCompatible;
if ( m_version.minorNr < programVersion.minorNr )
return MissingConfiguration;
if ( m_version.minorNr > programVersion.minorNr )
return MajorLossOfConfiguration;
if ( m_version.patchNr > programVersion.patchNr )
return MinorLossOfConfiguration;
return FullyCompatible;
}
bool UAVConfigInfo::standardVersionHandlingIsNotOK(UAVConfigVersion programVersion)
{
return askToAbort(
checkCompatibilityWith(programVersion),
"("+m_nameOfConfigurable+")");
}
UAVConfigVersion::UAVConfigVersion(int majorNum, int minorNum, int patchNum)
:majorNr(majorNum)
,minorNr(minorNum)
,patchNr(patchNum)
{
}
UAVConfigVersion::UAVConfigVersion(QString versionString)
{
int begin;
int end = 0;
begin = end;
end = versionString.indexOf(".", begin);
majorNr = versionString.mid(begin, end-begin).toInt();
begin = end+1;
end = versionString.indexOf(".", begin);
minorNr = versionString.mid(begin, end-begin).toInt();
begin = end+1;
patchNr = versionString.mid(begin).toInt();
}
QString UAVConfigVersion::toString() const
{
return QString("%1.%2.%3").arg(majorNr).arg(minorNr).arg(patchNr);
}
bool UAVConfigVersion::operator==(const UAVConfigVersion &other)
{
return toString() == other.toString();
}
/**
* @}
* @}
*/

View File

@ -0,0 +1,83 @@
/**
******************************************************************************
*
* @file uavconfiginfo.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup CorePlugin Core Plugin
* @{
* @brief The Core GCS plugin
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef UAVCONFIGINFO_H
#define UAVCONFIGINFO_H
#include <QObject>
#include <QString>
#include <QSettings>
namespace Core
{
class UAVConfigVersion{
public:
UAVConfigVersion(QString versionString = "0.0.0");
UAVConfigVersion(int major, int minor, int patch);
int majorNr;
int minorNr;
int patchNr;
QString toString() const;
bool operator==(const UAVConfigVersion &other);
};
class UAVConfigInfo : public QObject
{
Q_OBJECT
public:
UAVConfigInfo(QSettings *qs, QObject *parent = 0);
UAVConfigInfo(UAVConfigVersion version, QString nameOfConfigurable, QObject *parent = 0);
enum Compatibility { FullyCompatible, MinorLossOfConfiguration, MissingConfiguration, MajorLossOfConfiguration, NotCompatible };
void setNameOfConfigurable(const QString nameOfConfigurable){m_nameOfConfigurable = nameOfConfigurable;}
void save(QSettings *qs);
void setVersion(int major, int minor, int patch){m_version = UAVConfigVersion(major, minor, patch);}
void setVersion(const QString version){m_version = UAVConfigVersion(version);}
UAVConfigVersion version(){ return m_version;}
int checkCompatibilityWith(UAVConfigVersion programVersion);
bool askToAbort(int compat, QString message);
void notifyAbort(QString message);
bool standardVersionHandlingIsNotOK(UAVConfigVersion programVersion);
signals:
public slots:
private:
UAVConfigVersion m_version;
QString m_nameOfConfigurable;
};
} // namespace Core
#endif // UAVCONFIGINFO_H

View File

@ -45,7 +45,8 @@
using namespace Core;
UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
QObject(parent)
QObject(parent),
m_versionUAVGadgetConfigurations("1.0.0")
{
m_pm = ExtensionSystem::PluginManager::instance();
QList<IUAVGadgetFactory*> factories = m_pm->getObjects<IUAVGadgetFactory>();
@ -73,6 +74,24 @@ void UAVGadgetInstanceManager::readConfigurations(QSettings *qs)
emit configurationToBeDeleted(m_configurations.takeLast());
}
qs->beginGroup("UAVGadgetConfigurations");
UAVConfigInfo configInfo(qs);
configInfo.setNameOfConfigurable("UAVGadgetConfigurations");
if ( configInfo.version() == UAVConfigVersion() ){
// If version is not set, assume its a old version before readable config.
configInfo.setVersion("1.0.0");
}
if ( configInfo.standardVersionHandlingIsNotOK(m_versionUAVGadgetConfigurations) ){
// We are in trouble now. User wants us to quit the import.
qs->endGroup();
return;
}
readConfigs_1_0_0(qs);
qs->endGroup();
createOptionsPages();
}
void UAVGadgetInstanceManager::readConfigs_1_0_0(QSettings *qs)
{
foreach (QString classId, m_classIds.keys())
{
IUAVGadgetFactory *f = factory(classId);
@ -115,14 +134,14 @@ void UAVGadgetInstanceManager::readConfigurations(QSettings *qs)
}
qs->endGroup();
}
qs->endGroup();
createOptionsPages();
}
void UAVGadgetInstanceManager::writeConfigurations(QSettings *qs)
{
qs->beginGroup("UAVGadgetConfigurations");
qs->remove(""); // Remove existing configurations
UAVConfigInfo configInfo(m_versionUAVGadgetConfigurations, "UAVGadgetConfigurations");
configInfo.save(qs);
foreach (IUAVGadgetConfiguration *config, m_configurations)
{
qs->beginGroup(config->classId());

View File

@ -33,6 +33,7 @@
#include <QtCore/QMap>
#include <QtCore/QStringList>
#include "core_global.h"
#include "uavconfiginfo.h"
namespace ExtensionSystem {
class PluginManager;
@ -96,9 +97,10 @@ private:
QList<IOptionsPage*> m_provisionalOptionsPages;
Core::Internal::SettingsDialog *m_settingsDialog;
ExtensionSystem::PluginManager *m_pm;
UAVConfigVersion m_versionUAVGadgetConfigurations;
int indexForConfig(QList<IUAVGadgetConfiguration*> configurations,
QString classId, QString configName);
void readConfigs_1_0_0(QSettings *qs);
};
} // namespace Core