1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-16 04:45:17 +03:00

Refactoring

This commit is contained in:
bsongis 2014-05-27 15:17:15 +02:00
parent 5620a76679
commit fdde364307
11 changed files with 53 additions and 26 deletions

View file

@ -188,7 +188,7 @@ void AppPreferencesDialog::initSettings()
FirmwareInterface * current_firmware = GetCurrentFirmware();
foreach(FirmwareInterface * firmware, firmwares) {
ui->downloadVerCB->addItem(firmware->name, firmware->id);
ui->downloadVerCB->addItem(firmware->getName(), firmware->getId());
if (current_firmware == firmware) {
ui->downloadVerCB->setCurrentIndex(ui->downloadVerCB->count() - 1);
}
@ -366,7 +366,7 @@ void AppPreferencesDialog::baseFirmwareChanged()
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
voice=NULL;
foreach(FirmwareInterface * firmware, firmwares) {
if (firmware->id == selected_firmware) {
if (firmware->getId() == selected_firmware) {
showVoice(firmware->voice);
populateFirmwareOptions(firmware);
break;
@ -380,8 +380,8 @@ FirmwareVariant AppPreferencesDialog::getFirmwareVariant()
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
bool voice=false;
foreach(FirmwareInterface * firmware, firmwares) {
if (firmware->id == selected_firmware) {
QString id = firmware->id;
QString id = firmware->getId();
if (id == selected_firmware) {
foreach(QCheckBox *cb, optionsCheckBoxes) {
if (cb->isChecked()) {
if (cb->text()=="voice" && cb->isChecked())
@ -414,7 +414,7 @@ void AppPreferencesDialog::firmwareOptionChanged(bool state)
if (cb && state) {
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
foreach(firmware, firmwares) {
if (firmware->id == selected_firmware) {
if (firmware->getId() == selected_firmware) {
foreach(QList<Option> opts, firmware->opts) {
foreach(Option opt, opts) {
if (cb->text() == opt.name) {

View file

@ -328,7 +328,7 @@ void avrOutputDialog::errorWizard()
}
else {
FirmwareInterface *firmware = GetCurrentFirmware();
QMessageBox::warning(this, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease select an appropriate firmware type to program it.").arg(DeviceStr)+FwStr+tr("\nYou are currently using:\n %1").arg(firmware->name));
QMessageBox::warning(this, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease select an appropriate firmware type to program it.").arg(DeviceStr)+FwStr+tr("\nYou are currently using:\n %1").arg(firmware->getName()));
}
}
}

View file

@ -1285,13 +1285,34 @@ bool LoadEepromXml(RadioData &radioData, QDomDocument &doc)
return false;
}
QString getBoardName(BoardEnum board)
{
switch (board) {
case BOARD_STOCK:
return "9X";
case BOARD_M128:
return "9X128";
case BOARD_GRUVIN9X:
return "Gruvin9x";
case BOARD_MEGA2560:
return "MEGA2560";
case BOARD_TARANIS:
return "Taranis";
case BOARD_TARANIS_PLUS:
return "Taranis Plus";
case BOARD_SKY9X:
return "Sky9x";
case BOARD_9XRPRO:
return "9XR-PRO";
}
}
FirmwareVariant GetFirmwareVariant(QString id)
{
FirmwareVariant result;
foreach(FirmwareInterface * firmware, firmwares) {
if (id.contains(firmware->id+"-") || (!id.contains("-") && id.contains(firmware->id))) {
if (id.contains(firmware->getId()+"-") || (!id.contains("-") && id.contains(firmware->getId()))) {
result.id = id;
result.firmware = firmware;
result.variant = firmware->getVariant(id);

View file

@ -52,6 +52,8 @@ enum BoardEnum {
BOARD_TARANIS_PLUS
};
QString getBoardName(BoardEnum board);
#define IS_9X(board) (board==BOARD_STOCK || board==BOARD_M128)
#define IS_STOCK(board) (board==BOARD_STOCK)
#define IS_2560(board) (board==BOARD_GRUVIN9X || board==BOARD_MEGA2560)
@ -1162,8 +1164,6 @@ class EEPROMInterface
virtual ~EEPROMInterface() {}
virtual const char * getName() = 0;
inline BoardEnum getBoard() { return board; }
virtual bool load(RadioData &radioData, const uint8_t *eeprom, int size) = 0;
@ -1351,6 +1351,16 @@ class FirmwareInterface {
return board;
}
inline QString getName()
{
return name;
}
inline QString getId()
{
return id;
}
inline EEPROMInterface * getEepromInterface()
{
return eepromInterface;
@ -1367,10 +1377,10 @@ class FirmwareInterface {
QList<const char *> languages;
QList<const char *> ttslanguages;
QList< QList<Option> > opts;
QString id;
QString name;
protected:
QString id;
QString name;
BoardEnum board;
EEPROMInterface * eepromInterface;

View file

@ -31,8 +31,6 @@ class OpenTxEepromInterface : public EEPROMInterface
virtual ~OpenTxEepromInterface();
virtual const char * getName();
virtual const int getEEpromSize();
virtual const int getMaxModels();
@ -53,6 +51,8 @@ class OpenTxEepromInterface : public EEPROMInterface
protected:
const char * getName();
bool checkVersion(unsigned int version);
bool checkVariant(unsigned int version, unsigned int variant);

View file

@ -8,7 +8,7 @@ class GoogleAnalytics: public QObject
GoogleAnalytics();
~GoogleAnalytics();
void sendPageView(QString page);
void sendEvent(QString category, QString action, QString label);
void sendEvent(QString category, QString action, QString label="");
protected slots:
void slot_receive(QNetworkReply * reply);

View file

@ -164,7 +164,7 @@ MainWindow::MainWindow():
QTimer::singleShot(0, this, SLOT(autoClose()));
}
ga.sendPageView("Companion");
ga.sendEvent(getBoardName(GetCurrentFirmware()->getBoard()), "Start Companion");
}
void MainWindow::displayWarnings()
@ -523,7 +523,7 @@ void MainWindow::startFirmwareDownload(QString url, QString filename)
downloadDialog * dd = new downloadDialog(this, url, filename);
connect(dd, SIGNAL(accepted()), this, SLOT(firmwareDownloadAccepted()));
dd->exec();
ga.sendEvent("Firmwares", "Download", url);
ga.sendEvent(getBoardName(GetCurrentFirmware()->getBoard()), "Download", url);
}
}
@ -1468,7 +1468,7 @@ void MainWindow::updateMenus()
updateIconSizeActions();
updateIconThemeActions();
setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( g.profile[g.id()].name() ));
setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->getName()).arg( g.profile[g.id()].name() ));
}
MdiChild *MainWindow::createMdiChild()

View file

@ -134,8 +134,8 @@ bool MdiChild::hasSelection()
void MdiChild::updateTitle()
{
QString title = userFriendlyCurrentFile() + "[*]"+" ("+GetEepromInterface()->getName()+QString(")");
if (!IS_SKY9X(GetEepromInterface()->getBoard()))
QString title = userFriendlyCurrentFile() + "[*]" + " (" + GetCurrentFirmware()->getName() + QString(")");
if (!IS_SKY9X(GetCurrentFirmware()->getBoard()))
title += QString(" - %1 ").arg(EEPromAvail) + tr("free bytes");
setWindowTitle(title);
}

View file

@ -115,7 +115,7 @@ void PrintDialog::printSetup()
str.append(QString("<tr><td colspan=%1 ><table border=0 width=\"100%\"><tr><td><h1>").arg((firmware->getCapability(FlightModes) && !gvars) ? 2 : 1));
str.append(g_model->name);
str.append("&nbsp;(");
str.append(firmware->getEepromInterface()->getName());
str.append(firmware->getName());
str.append(")</h1></td><td align=right valign=top NOWRAP><font size=-1>"+tr("printed on: %1").arg(QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate))+"</font></td></tr></table></td></tr><tr><td><table border=0 cellspacing=0 cellpadding=3>");
str.append("<tr><td><h2>"+tr("General Model Settings")+"</h2></td></tr>");
str.append("<tr><td>");

View file

@ -16,7 +16,6 @@ SimulatorDialog::SimulatorDialog(QWidget * parent, unsigned int flags):
dialP_4(NULL),
timer(NULL),
lightOn(false),
txInterface(NULL),
simulator(NULL),
lastPhase(-1),
beepVal(0),
@ -340,9 +339,7 @@ void SimulatorDialog::initUi(T * ui)
}
#endif
txInterface = GetEepromInterface();
windowName = tr("Simulating Radio (%1)").arg(txInterface->getName());
windowName = tr("Simulating Radio (%1)").arg(GetCurrentFirmware()->getName());
setWindowTitle(windowName);
simulator = GetCurrentFirmware()->getSimulator();
@ -493,7 +490,7 @@ void SimulatorDialog::onTimerEvent()
{
static unsigned int lcd_counter = 0;
if (!simulator->timer10ms()) {
QMessageBox::critical(this, "Companion", tr("Firmware %1 error: %2").arg(txInterface->getName()).arg(simulator->getError()));
QMessageBox::critical(this, "Companion", tr("Firmware %1 error: %2").arg(GetCurrentFirmware()->getName()).arg(simulator->getError()));
timer->stop();
return;
}

View file

@ -75,7 +75,6 @@ class SimulatorDialog : public QDialog
int jsmap[8];
#endif
EEPROMInterface *txInterface;
SimulatorInterface *simulator;
unsigned int lastPhase;