dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavconfiginfo.cpp
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
106 #include "uavconfiginfo.h"
107 #include "icore.h"
108 #include <QMainWindow>
109 #include <QMessageBox>
110 
111 #define VERSION_DEFAULT "0.0.0"
112 
113 #define TEXT_MINOR_LOSS_OF_CONFIGURATION \
114  tr(" Some of the configured features might not be supported \
115 by your version of the plugin. You might want to upgrade the plugin.")
116 
117 #define TEXT_MISSING_CONFIGURATION \
118  tr(" Some configuration is missing in the imported config and will be replaced \
119 by default settings.")
120 
121 #define TEXT_MAJOR_LOSS_OF_CONFIGURATION \
122  tr(" Major features can't be imported \
123 by your version of the plugin. You should upgrade the plugin to import these settings.")
124 
125 #define TEXT_NOT_COMPATIBLE \
126  tr(" The imported settings are not compatible with this plugin and won't be imported!")
127 
128 using namespace Core;
129 
131  : QObject(parent)
132  , m_version(VERSION_DEFAULT)
133  , m_locked(false)
134  , m_nameOfConfigurable("")
135 {
136 }
137 
138 UAVConfigInfo::UAVConfigInfo(QSettings *qs, QObject *parent)
139  : QObject(parent)
140  , m_version(VERSION_DEFAULT)
141 {
142  read(qs);
143 }
144 
145 UAVConfigInfo::UAVConfigInfo(UAVConfigVersion version, QString nameOfConfigurable, QObject *parent)
146  : QObject(parent)
147  , m_version(version)
148  , m_locked(false)
149  , m_nameOfConfigurable(nameOfConfigurable)
150 {
151 }
152 
154  : QObject(parent)
155 {
156  m_locked = config->locked();
157  m_nameOfConfigurable = config->classId() + "-" + config->name();
158 }
159 
160 void UAVConfigInfo::save(QSettings *qs)
161 {
162  qs->beginGroup("configInfo");
163  qs->setValue("version", m_version.toString());
164  qs->setValue("locked", m_locked);
165  qs->endGroup();
166 }
167 
168 void UAVConfigInfo::read(QSettings *qs)
169 {
170  qs->beginGroup("configInfo");
171  m_version = UAVConfigVersion(qs->value("version", VERSION_DEFAULT).toString());
172  m_locked = qs->value("locked", false).toBool();
173  qs->endGroup();
174 }
175 
176 bool UAVConfigInfo::askToAbort(int compat, QString message)
177 {
178  QMessageBox msgBox(dynamic_cast<QWidget *>(Core::ICore::instance()->mainWindow()));
179  msgBox.setInformativeText(tr("Do you want to continue the import?"));
180  msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
181 
182  int result = 0;
183 
184  switch (compat) {
185 
186  case FullyCompatible:
187  return false;
188 
190  msgBox.setText(tr("INFO: ") + message + TEXT_MINOR_LOSS_OF_CONFIGURATION);
191  msgBox.setDefaultButton(QMessageBox::Ok);
192  result = msgBox.exec();
193  break;
194 
196  msgBox.setText(tr("WARNING: ") + message + TEXT_MISSING_CONFIGURATION);
197  msgBox.setDefaultButton(QMessageBox::Ok);
198  result = msgBox.exec();
199  break;
200 
202  msgBox.setText(tr("ERROR: ") + message + TEXT_MAJOR_LOSS_OF_CONFIGURATION);
203  msgBox.setDefaultButton(QMessageBox::Cancel);
204  result = msgBox.exec();
205  break;
206 
207  case NotCompatible:
208  msgBox.setText("ERROR: " + message + TEXT_NOT_COMPATIBLE);
209  msgBox.setInformativeText(tr(""));
210  msgBox.setStandardButtons(QMessageBox::Ok);
211  msgBox.exec();
212  return true;
213 
214  default:
215  msgBox.setText("INTERNAL ERROR: " + message + tr("Unknown compatibility level: ")
216  + QString::number(compat));
217  }
218  if (result == QMessageBox::Ok)
219  return false;
220  else
221  return true;
222 }
223 
224 void UAVConfigInfo::notify(QString message)
225 {
226  QMessageBox msgBox(dynamic_cast<QWidget *>(Core::ICore::instance()->mainWindow()));
227  msgBox.setText(message);
228  msgBox.exec();
229 }
230 
232 {
233  if (m_version.majorNr != programVersion.majorNr)
234  return NotCompatible;
235  if (m_version.minorNr < programVersion.minorNr)
236  return MissingConfiguration;
237  if (m_version.minorNr > programVersion.minorNr)
239  if (m_version.patchNr > programVersion.patchNr)
241 
242  return FullyCompatible;
243 }
244 
246 {
247  return !askToAbort(checkCompatibilityWith(programVersion), "(" + m_nameOfConfigurable + ")");
248 }
249 
250 UAVConfigVersion::UAVConfigVersion(int majorNum, int minorNum, int patchNum)
251  : majorNr(majorNum)
252  , minorNr(minorNum)
253  , patchNr(patchNum)
254 {
255 }
256 
258 {
259  int begin;
260  int end = 0;
261 
262  begin = end;
263  end = versionString.indexOf(".", begin);
264  majorNr = versionString.mid(begin, end - begin).toInt();
265 
266  begin = end + 1;
267  end = versionString.indexOf(".", begin);
268  minorNr = versionString.mid(begin, end - begin).toInt();
269 
270  begin = end + 1;
271  patchNr = versionString.mid(begin).toInt();
272 }
273 
275 {
276  return QString("%1.%2.%3").arg(majorNr).arg(minorNr).arg(patchNr);
277 }
278 
280 {
281  return toString() == other.toString();
282 }
283 
int checkCompatibilityWith(UAVConfigVersion programVersion)
UAVConfigInfo(QObject *parent=nullptr)
bool askToAbort(int compat, QString message)
QString toString() const
void save(QSettings *qs)
end(INSTANTIATIONCODE) fid
static ICore * instance()
Definition: coreimpl.cpp:46
bool operator==(const UAVConfigVersion &other)
bool standardVersionHandlingOK(UAVConfigVersion programVersion)
Default version handling.
void notify(QString message)
void read(QSettings *qs)
UAVConfigVersion(QString versionString="0.0.0")