dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
setupwizardplugin.cpp
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 #include "setupwizardplugin.h"
29 
30 #include <QDebug>
31 #include <QtPlugin>
32 #include <QStringList>
34 
35 #include <config/configplugin.h>
38 #include <coreplugin/icore.h>
39 #include <QKeySequence>
40 #include <coreplugin/modemanager.h>
43 
44 SetupWizardPlugin::SetupWizardPlugin()
45  : wizardRunning(false)
46 {
47 }
48 
49 SetupWizardPlugin::~SetupWizardPlugin()
50 {
51 }
52 
53 bool SetupWizardPlugin::initialize(const QStringList &args, QString *errMsg)
54 {
55  Q_UNUSED(args);
56  Q_UNUSED(errMsg);
57 
58  // Add Menu entry
61 
62  Core::Command *cmd = am->registerAction(new QAction(this), "SetupWizardPlugin.ShowSetupWizard",
64  cmd->action()->setText(tr("Vehicle Setup Wizard"));
65 
67 
68  ac->menu()->addSeparator();
69  ac->appendGroup("Wizard");
70  ac->addAction(cmd, "Wizard");
71 
72  connect(cmd->action(), &QAction::triggered, this, &SetupWizardPlugin::showSetupWizard);
73  return true;
74 }
75 
76 void SetupWizardPlugin::extensionsInitialized()
77 {
78  auto pm = ExtensionSystem::PluginManager::instance();
79  auto config = pm->getObject<ConfigPlugin>();
80  if (config)
81  connect(config, &ConfigPlugin::launchSetupWizard,
82  std::bind(&SetupWizardPlugin::showSetupWizard, this, true));
83 }
84 
85 void SetupWizardPlugin::shutdown()
86 {
87 }
88 
89 void SetupWizardPlugin::showSetupWizard(bool autoLaunched)
90 {
91  if (wizardRunning)
92  return;
93 
94  if (autoLaunched) {
95  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
96 
97  // check if uploader is working with this board
98  auto uploaders = pm->getObjects<uploader::UploaderGadgetWidget>();
99  for (const auto uploader : uploaders) {
100  if (uploader->active())
101  return;
102  }
103 
104  // check if it's been ignored already
105  UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
106  if (!utilMngr) {
107  qWarning() << "Could not get UAVObjectUtilManager";
108  Q_ASSERT(false);
109  return;
110  }
111  if (ignoredBoards.contains(utilMngr->getBoardCPUSerial())) {
112  qInfo() << "Ignoring board";
113  return;
114  }
115  }
116 
118 
119  wizardRunning = true;
120  SetupWizard *m_wiz = new SetupWizard(autoLaunched);
121  connect(m_wiz, &SetupWizard::boardIgnored, this, &SetupWizardPlugin::ignoreBoard);
122  connect(m_wiz, &QDialog::finished, this, &SetupWizardPlugin::wizardTerminated);
123  m_wiz->setAttribute(Qt::WA_DeleteOnClose, true);
124  m_wiz->setWindowFlags(m_wiz->windowFlags() | Qt::WindowStaysOnTopHint);
125  m_wiz->show();
126 }
127 
128 void SetupWizardPlugin::wizardTerminated()
129 {
130  wizardRunning = false;
131  disconnect(this, SLOT(wizardTerminated()));
132 }
133 
134 void SetupWizardPlugin::ignoreBoard(QByteArray uuid)
135 {
136  ignoredBoards << uuid;
137 }
138 
The SetupWizard class is the main interface to the setup wizard. It provides selects the sequence of ...
Definition: setupwizard.h:47
static ModeManager * instance()
Definition: modemanager.h:62
void launchSetupWizard()
virtual QAction * action() const =0
virtual Command * registerAction(QAction *action, const QString &id, const QList< int > &context)=0
Makes an action known to the system under the specified string id.
const char *const M_TOOLS
Definition: coreconstants.h:83
virtual ActionContainer * actionContainer(const QString &id) const =0
Returns the IActionContainter object that is know to the system under the given string id...
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
virtual ActionManager * actionManager() const =0
Returns the application's action manager.
void addAction(Command *command, int priority, QMenu *menu=nullptr)
void boardIgnored(QByteArray uuid)
virtual QMenu * menu() const =0
const int C_GLOBAL_ID
Definition: coreconstants.h:90
const char *const MODE_WELCOME
Definition: coreconstants.h:68
void activateModeByWorkspaceName(const QString &id)
static ICore * instance()
Definition: coreimpl.cpp:46
virtual void appendGroup(const QString &group)=0
virtual void addAction(Core::Command *action, const QString &group=QString())=0
The action manager is responsible for registration of menus and menu items and keyboard shortcuts...
Definition: actionmanager.h:47
The class Command represents an action like a menu item, tool button, or shortcut. You don't create Command objects directly, instead use {ActionManager::registerAction()} to register an action and retrieve a Command. The Command object represents the user visible action and its properties. If multiple actions are registered with the same ID (but different contexts) the returned Command is the shared one between these actions.
Definition: command.h:43