2012-07-10 00:26:59 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
2012-07-17 01:24:22 +02:00
|
|
|
* @file setupwizardplugin.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
2012-07-10 00:26:59 +02:00
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
2012-07-11 01:00:41 +02:00
|
|
|
* @addtogroup SetupWizardPlugin
|
2012-07-10 00:26:59 +02:00
|
|
|
* @{
|
|
|
|
* @brief A Setup Wizard 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 "setupwizardplugin.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QtPlugin>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <QKeySequence>
|
2012-09-16 23:03:15 +02:00
|
|
|
#include <coreplugin/modemanager.h>
|
2014-09-15 22:46:28 +02:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include "stabilizationsettings.h"
|
2012-07-10 00:26:59 +02:00
|
|
|
|
2012-10-13 17:35:36 +02:00
|
|
|
SetupWizardPlugin::SetupWizardPlugin() : wizardRunning(false)
|
2013-05-19 16:37:30 +02:00
|
|
|
{}
|
2012-07-10 00:26:59 +02:00
|
|
|
|
|
|
|
SetupWizardPlugin::~SetupWizardPlugin()
|
2013-05-19 16:37:30 +02:00
|
|
|
{}
|
2012-07-10 00:26:59 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
bool SetupWizardPlugin::initialize(const QStringList & args, QString *errMsg)
|
2012-07-10 00:26:59 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(args);
|
|
|
|
Q_UNUSED(errMsg);
|
|
|
|
|
|
|
|
// Add Menu entry
|
2013-05-19 16:37:30 +02:00
|
|
|
Core::ActionManager *am = Core::ICore::instance()->actionManager();
|
|
|
|
Core::ActionContainer *ac = am->actionContainer(Core::Constants::M_TOOLS);
|
2012-07-10 00:26:59 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
Core::Command *cmd = am->registerAction(new QAction(this),
|
2012-07-10 00:26:59 +02:00
|
|
|
"SetupWizardPlugin.ShowSetupWizard",
|
|
|
|
QList<int>() <<
|
|
|
|
Core::Constants::C_GLOBAL_ID);
|
2012-09-16 23:03:15 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence("Ctrl+V"));
|
|
|
|
cmd->action()->setText(tr("Vehicle Setup Wizard"));
|
2014-09-15 22:46:28 +02:00
|
|
|
connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(showSetupWizard()));
|
2012-09-16 23:03:15 +02:00
|
|
|
|
|
|
|
Core::ModeManager::instance()->addAction(cmd, 1);
|
2014-09-15 22:46:28 +02:00
|
|
|
ac->menu()->addSeparator();
|
|
|
|
ac->appendGroup("Wizard");
|
|
|
|
ac->addAction(cmd, "Wizard");
|
|
|
|
|
|
|
|
cmd = am->registerAction(new QAction(this),
|
|
|
|
"SetupWizardPlugin.ExportJSon",
|
|
|
|
QList<int>() <<
|
|
|
|
Core::Constants::C_GLOBAL_ID);
|
|
|
|
cmd->action()->setText(tr("Export Stabilization Settings"));
|
|
|
|
connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(exportSettings()));
|
2012-07-10 00:26:59 +02:00
|
|
|
|
2014-09-15 22:46:28 +02:00
|
|
|
Core::ModeManager::instance()->addAction(cmd, 1);
|
2012-07-10 00:26:59 +02:00
|
|
|
ac->menu()->addSeparator();
|
|
|
|
ac->appendGroup("Wizard");
|
|
|
|
ac->addAction(cmd, "Wizard");
|
|
|
|
|
2014-09-15 22:46:28 +02:00
|
|
|
|
2012-07-10 00:26:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupWizardPlugin::extensionsInitialized()
|
2013-05-19 16:37:30 +02:00
|
|
|
{}
|
2012-07-10 00:26:59 +02:00
|
|
|
|
|
|
|
void SetupWizardPlugin::shutdown()
|
2013-05-19 16:37:30 +02:00
|
|
|
{}
|
2012-07-10 00:26:59 +02:00
|
|
|
|
|
|
|
void SetupWizardPlugin::showSetupWizard()
|
|
|
|
{
|
2012-10-13 17:35:36 +02:00
|
|
|
if (!wizardRunning) {
|
|
|
|
wizardRunning = true;
|
|
|
|
SetupWizard *m_wiz = new SetupWizard();
|
|
|
|
connect(m_wiz, SIGNAL(finished(int)), this, SLOT(wizardTerminated()));
|
2013-05-19 16:37:30 +02:00
|
|
|
m_wiz->setAttribute(Qt::WA_DeleteOnClose, true);
|
2012-10-13 19:57:02 +02:00
|
|
|
m_wiz->setWindowFlags(m_wiz->windowFlags() | Qt::WindowStaysOnTopHint);
|
2012-10-13 17:35:36 +02:00
|
|
|
m_wiz->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-15 22:46:28 +02:00
|
|
|
void SetupWizardPlugin::exportSettings()
|
|
|
|
{
|
|
|
|
QFile saveFile(QStringLiteral("/home/fredrik/export.json"));
|
|
|
|
|
|
|
|
if (!saveFile.open(QIODevice::WriteOnly)) {
|
|
|
|
qWarning("Couldn't open save file.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject exportObject;
|
|
|
|
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *uavoManager = pm->getObject<UAVObjectManager>();
|
|
|
|
StabilizationSettings* settings = StabilizationSettings::GetInstance(uavoManager);
|
|
|
|
settings->toJson(exportObject);
|
|
|
|
|
|
|
|
QJsonDocument saveDoc(exportObject);
|
|
|
|
saveFile.write(saveDoc.toJson());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-13 17:35:36 +02:00
|
|
|
void SetupWizardPlugin::wizardTerminated()
|
|
|
|
{
|
|
|
|
wizardRunning = false;
|
2013-05-19 16:37:30 +02:00
|
|
|
disconnect(this, SLOT(wizardTerminated()));
|
2012-07-10 00:26:59 +02:00
|
|
|
}
|