diff MainWindow.cpp @ 8:21ce6187d32e

Minor changes done by automatic style checker
author Ideenmodellierer
date Mon, 12 Jan 2026 13:51:17 +0000
parents 115cfa4a3239
children e47e0f59101d
line wrap: on
line diff
--- a/MainWindow.cpp	Mon Jan 12 13:49:16 2026 +0000
+++ b/MainWindow.cpp	Mon Jan 12 13:51:17 2026 +0000
@@ -39,11 +39,10 @@
 #include "Utils/LogAppender.h"
 #include "Utils/ProgressEvent.h"
 
+#include "SettingsDialog.h"
+#include "editlogdialog.h"
 #include "ui_MainWindow.h"
-#include "SettingsDialog.h"
-#include "editLogDialog.h"
 
-#include <QString>
 #include <QDateTime>
 #include <QFileDialog>
 #include <QInputDialog>
@@ -53,59 +52,53 @@
 #include <QPlainTextEdit>
 #include <QProgressBar>
 #include <QSettings>
+#include <QString>
 #include <QTextCursor>
-#include "OSTCFrogOperations.h"
+#include "OSTC2Operations.h"
 #include "OSTC2cOperations.h"
-#include "OSTC2Operations.h"
-#include "OSTCSportOperations.h"
 #include "OSTC3Operations.h"
 #include "OSTC3pOperations.h"
 #include "OSTC4Operations.h"
+#include "OSTCFrogOperations.h"
+#include "OSTCSportOperations.h"
 #include "OSTC_CR_Operations.h"
 
-extern QSettings* settings;
+extern QSettings *settings;
 
 //////////////////////////////////////////////////////////////////////////////
 
-class EXPORT LogWindow
-    : public LogAppender
+class EXPORT LogWindow : public LogAppender
 {
-    MainWindow* _window;
+    MainWindow *_window;
 
     //---- The <<printing>> function -----------------------------------------
-    void operator()(const Log &log) override {
+    void operator()(const Log &log) override
+    {
         QString message = log.message;
 
-        message.replace("< ", "&lt; ")
-               .replace(" >", " &gt;");
-        if( ! message.isEmpty() )
+        message.replace("< ", "&lt; ").replace(" >", " &gt;");
+        if (!message.isEmpty())
             _window->statusMessage(message);
     }
 
     //---- Reimplementing mandatory methds -----------------------------------
-    const char *type() const override {
-        return "File";
-    }
-    Log::Level defaultMinLevel() const override {
-        return Log::LEVEL_INFO;
-    }
-    const char* defaultFormat() const override {
-        return "%m";
-    }
+    const char *type() const override { return "File"; }
+    Log::Level defaultMinLevel() const override { return Log::LEVEL_INFO; }
+    const char *defaultFormat() const override { return "%m"; }
 
 public:
-    LogWindow(MainWindow* window)
-      : LogAppender(0, NULL),
-        _window(window)
+    LogWindow(MainWindow *window)
+        : LogAppender(0, NULL)
+        , _window(window)
     {}
 };
 
 //////////////////////////////////////////////////////////////////////////////
 
 MainWindow::MainWindow()
-  : QMainWindow(NULL),
-    _ui(new Ui::MainWindow),
-    _op(0)
+    : QMainWindow(NULL)
+    , _ui(new Ui::MainWindow)
+    , _op(0)
 {
     // Connect the Log system to this window:
     new LogWindow(this);
@@ -119,15 +112,15 @@
 
     // Auto-select last model:
     QString model = settings->value("Interface/computerType").toString();
-        _ui->computerType->setCurrentIndex(0);
+    _ui->computerType->setCurrentIndex(0);
 
-    if( model == "ostc2c" )
+    if (model == "ostc2c")
         _ui->computerType->setCurrentIndex(0);
-    else if( model == "hwOS (Bluetooth)" )
+    else if (model == "hwOS (Bluetooth)")
         _ui->computerType->setCurrentIndex(1);
-    else if( model == "hwOS (USB)" )
+    else if (model == "hwOS (USB)")
         _ui->computerType->setCurrentIndex(2);
-    else if( model == "ostc4" )
+    else if (model == "ostc4")
         _ui->computerType->setCurrentIndex(3);
 
     changeTypeSlot();
@@ -135,21 +128,18 @@
 #ifdef Q_OS_MAC
     {
         QMenuBar *menuBar = new QMenuBar(this);
-        QMenu* help = menuBar->addMenu(tr("&Help"));
-            help->addAction(tr("Preferences..."), this, SLOT(settingsSlot()));
+        QMenu *help = menuBar->addMenu(tr("&Help"));
+        help->addAction(tr("Preferences..."), this, SLOT(settingsSlot()));
     }
 #endif
 
     setWindowTitle(QString("OSTC Companion v%1.%2 %3")
                        .arg(MAJOR_VERSION)
-                       .arg(MINOR_VERSION)  // kein sprintf nötig, arg konvertiert automatisch
-                       .arg(BETA_VERSION
-                                ? QString(" beta %1").arg(PATCH_VERSION)
-                                : QString::number(PATCH_VERSION))
-                   );
+                       .arg(MINOR_VERSION) // kein sprintf nötig, arg konvertiert automatisch
+                       .arg(BETA_VERSION ? QString(" beta %1").arg(PATCH_VERSION)
+                                         : QString::number(PATCH_VERSION)));
 }
 
-
 //////////////////////////////////////////////////////////////////////////////
 
 MainWindow::~MainWindow()
@@ -160,23 +150,19 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-bool MainWindow::event(QEvent* e)
+bool MainWindow::event(QEvent *e)
 {
-    if( ProgressEvent* p = dynamic_cast<ProgressEvent*>(e) )
-    {
-        QProgressBar* w = _ui->progressBar;
+    if (ProgressEvent *p = dynamic_cast<ProgressEvent *>(e)) {
+        QProgressBar *w = _ui->progressBar;
 
-        if( p->current > p->maximum && p->maximum > 0)
-        {
-            w->setMaximum(p->maximum);  // Remove throttling mode, if any.
+        if (p->current > p->maximum && p->maximum > 0) {
+            w->setMaximum(p->maximum); // Remove throttling mode, if any.
             w->reset();
-        }
-        else
-        {
-            if( ! w->isEnabled() )
+        } else {
+            if (!w->isEnabled())
                 w->setEnabled(true);
-            if( w->maximum() != p->maximum )
-                w->setMaximum(p->maximum);  // Start throttling if max==0
+            if (w->maximum() != p->maximum)
+                w->setMaximum(p->maximum); // Start throttling if max==0
             w->setValue(p->current);
         }
         return true;
@@ -194,17 +180,21 @@
     //---- Setup a new driver ------------------------------------------------
     delete _op;
     _op = 0;
-    switch( _ui->computerType->currentIndex() ) {
-    case 0: name = "ostc2c";
-            _op = new OSTC2cOperations;
+    switch (_ui->computerType->currentIndex()) {
+    case 0:
+        name = "ostc2c";
+        _op = new OSTC2cOperations;
         break;
-    case 1:  name = "hwOS (USB)";
-             _op = new OSTC3Operations;
+    case 1:
+        name = "hwOS (USB)";
+        _op = new OSTC3Operations;
         break;
-    case 2: name = "hwOS (Bluetooth)";
-             _op = new OSTC3pOperations;
+    case 2:
+        name = "hwOS (Bluetooth)";
+        _op = new OSTC3pOperations;
         break;
-    case 3: name = "ostc4";
+    case 3:
+        name = "ostc4";
         _op = new OSTC4Operations;
         break;
 
@@ -218,11 +208,14 @@
     settings->sync();
 
     // backword compatibility >= translate name if necessary
-    if ( name =="hwOS (Bluetooth)") name = "ostc3p";
-    if( name =="hwOS (USB)") name = "ostc3";
-    if( name =="ostc 4/5") name = "ostc4";
+    if (name == "hwOS (Bluetooth)")
+        name = "ostc3p";
+    if (name == "hwOS (USB)")
+        name = "ostc3";
+    if (name == "ostc 4/5")
+        name = "ostc4";
 
-    _ui->computerImage->setPixmap( QPixmap(":/Images/" + name + "_160x120.png"));
+    _ui->computerImage->setPixmap(QPixmap(":/Images/" + name + "_160x120.png"));
 
     updateStatus();
 }
@@ -231,7 +224,7 @@
 
 void MainWindow::settingsSlot()
 {
-    Settings* s = new Settings(this, _op);
+    Settings *s = new Settings(this, _op);
     s->exec();
     delete s;
 }
@@ -240,29 +233,26 @@
 
 void MainWindow::connectSlot()
 {
-    Q_ASSERT( _op );
+    Q_ASSERT(_op);
 
     try {
         LOG_INFO("Connecting...");
 
         //---- Already connected ? ----------------------------------------------
-        if( ! _op->description().isEmpty() )
+        if (!_op->description().isEmpty())
             _op->disconnect();
 
         //---- (Re)connect ------------------------------------------------------
-        if( _op->connect() ) {
-
-            if( Settings::autoSetDateTime )
+        if (_op->connect()) {
+            if (Settings::autoSetDateTime)
                 dateSlot();
 
-            LOG_INFO("Connected: " + _op->description() );
+            LOG_INFO("Connected: " + _op->description());
         }
         updateStatus();
-    }
-    catch(const std::exception& e) {
-        LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2")
-                    .arg(tr("Error"))
-                    .arg(e.what()) );
+    } catch (const std::exception &e) {
+        LOG_INFO(
+            QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
     }
 }
 
@@ -270,18 +260,16 @@
 
 void MainWindow::closeSlot()
 {
-    Q_ASSERT( _op );
+    Q_ASSERT(_op);
 
     try {
         LOG_INFO("Disconnecting...");
-        if( _op->disconnect() )
+        if (_op->disconnect())
             LOG_INFO("Disconnected.");
         updateStatus();
-    }
-    catch(const std::exception& e) {
-        LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2")
-                    .arg(tr("Error"))
-                    .arg(e.what()) );
+    } catch (const std::exception &e) {
+        LOG_INFO(
+            QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
     }
 }
 
@@ -290,49 +278,46 @@
 void MainWindow::updateStatus()
 {
     bool ok = _op;
-    _ui->connectButton->setEnabled( ok );
+    _ui->connectButton->setEnabled(ok);
 
     // ON when supported but NOT connected, OFF once connected.
-    _ui->upgradeButton->setEnabled( ok
-                                   && (_op->supported() & HardwareOperations::CompanionFeatures(HardwareOperations::FIRMWARE))
-                                && !_op->serial().isOpen());
+    _ui->upgradeButton->setEnabled(
+        ok
+        && (_op->supported() & HardwareOperations::CompanionFeatures(HardwareOperations::FIRMWARE))
+        && !_op->serial().isOpen());
 
     // Only allow buttons when connected:
     ok &= _op->serial().isOpen();
-    _ui->dateButton  ->setEnabled(ok && _op->supported().testFlag(HardwareOperations::DATE));
-    _ui->nameButton  ->setEnabled(ok && _op->supported().testFlag(HardwareOperations::NAME));
-    _ui->iconButton  ->setEnabled(ok);// && _op->supported().testFlag(HardwareOperations::ICON));
+    _ui->dateButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::DATE));
+    _ui->nameButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::NAME));
+    _ui->iconButton->setEnabled(ok); // && _op->supported().testFlag(HardwareOperations::ICON));
     _ui->signalButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::SIGNAL_CHECK));
-    _ui->closeButton  ->setEnabled( ok );
+    _ui->closeButton->setEnabled(ok);
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
 void MainWindow::dateSlot()
 {
-    Q_ASSERT( _op );
+    Q_ASSERT(_op);
 
     try {
         QDateTime date = QDateTime::currentDateTime();
 
         LOG_INFO(tr("Settings date & time..."));
-        _op->setDate( date );
-        LOG_INFO( QString("Date set to %1")
-                 .arg(date.toString("yyyy/MM/dd hh:mm:ss")) );
-    }
-    catch(const std::exception& e) {
-        LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2")
-                    .arg(tr("Error"))
-                    .arg(e.what()) );
+        _op->setDate(date);
+        LOG_INFO(QString("Date set to %1").arg(date.toString("yyyy/MM/dd hh:mm:ss")));
+    } catch (const std::exception &e) {
+        LOG_INFO(
+            QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
     }
 }
 
-
 //////////////////////////////////////////////////////////////////////////////
 
 void MainWindow::nameSlot()
 {
-    Q_ASSERT( _op );
+    Q_ASSERT(_op);
     try {
         LOG_INFO(tr("Settings name..."));
 
@@ -341,15 +326,14 @@
         QString oldText;
         QSize size = _op->nameSize();
 
-        for(int l=0; l<size.height(); ++l) {
-            QString line = oldName.left( size.width() ).leftJustified(size.width());
-            if( line.contains("\n") ) {
+        for (int l = 0; l < size.height(); ++l) {
+            QString line = oldName.left(size.width()).leftJustified(size.width());
+            if (line.contains("\n")) {
                 line = line.section("\n", 0, 0);
                 oldName = oldName.mid(line.length());
-            }
-            else {
+            } else {
                 oldName = oldName.mid(line.length());
-                if( oldName[0] == '\n' )
+                if (oldName[0] == '\n')
                     oldName = oldName.mid(1);
             }
             oldText += line + "|\n";
@@ -357,21 +341,19 @@
 
         //---- Ask user ------------------------------------------------------
 
-        QInputDialog* d = new QInputDialog(this);
+        QInputDialog *d = new QInputDialog(this);
         d->setWindowTitle("Set Computer Name...");
         d->setInputMode(QInputDialog::TextInput);
         d->setOptions(QInputDialog::UsePlainTextEditForTextInput);
         d->setTextValue(oldText);
 
-        QPlainTextEdit* edit = d->findChild<QPlainTextEdit*>();
+        QPlainTextEdit *edit = d->findChild<QPlainTextEdit *>();
         assert(edit);
-        edit->setStyleSheet(
-            "background-color: black;"
-            "color: green;"
-            "font: 14pt 'Courier New';"
-        );
+        edit->setStyleSheet("background-color: black;"
+                            "color: green;"
+                            "font: 14pt 'Courier New';");
 
-        if( d->exec() != QDialog::Accepted )
+        if (d->exec() != QDialog::Accepted)
             return;
 
         QString newText = d->textValue();
@@ -380,23 +362,21 @@
         //---- Reformat to single padded string ------------------------------
         QStringList lines = newText.split("\n");
         QString name;
-        for(int l=0; l<size.height(); ++l) {
-            if( l < lines.count() )
+        for (int l = 0; l < size.height(); ++l) {
+            if (l < lines.count())
                 name += lines[l].leftJustified(size.width(), ' ', true);
             else
                 name += QString(size.width(), ' ');
         }
 
         //---- Send result ---------------------------------------------------
-        _op->setName( name );
+        _op->setName(name);
         _op->getIdentity();
-        LOG_INFO( QString("Name set to '%1'")
-            .arg(_op->description().section(',', 2)).replace("\n", "|") );
-    }
-    catch(const std::exception& e) {
-        LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2")
-                    .arg(tr("Error"))
-                    .arg(e.what()) );
+        LOG_INFO(
+            QString("Name set to '%1'").arg(_op->description().section(',', 2)).replace("\n", "|"));
+    } catch (const std::exception &e) {
+        LOG_INFO(
+            QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
     }
 }
 
@@ -404,7 +384,7 @@
 
 void MainWindow::iconSlot()
 {
-    Q_ASSERT( _op );
+    Q_ASSERT(_op);
     try {
         LOG_INFO(tr("Settings icons..."));
 
@@ -414,13 +394,11 @@
                                                         "Images (*.bmp);;"
                                                         "BMP Image (*.bmp);;"
                                                         "Anything (*.*)");
-        if( ! fileName.isEmpty() )
+        if (!fileName.isEmpty())
             _op->setIcons(fileName);
-    }
-    catch(const std::exception& e) {
-        LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2")
-                    .arg(tr("Error"))
-                    .arg(e.what()) );
+    } catch (const std::exception &e) {
+        LOG_INFO(
+            QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
     }
 }
 
@@ -428,7 +406,7 @@
 
 void MainWindow::upgradeSlot()
 {
-    Q_ASSERT( _op );
+    Q_ASSERT(_op);
 
     try {
         LOG_INFO(tr("Upgrading firmware..."));
@@ -437,27 +415,25 @@
                                                        "Hex File...",
                                                        Settings::currentPath,
                                                        _op->firmwareTemplate());
-        if( hexFile.isEmpty() )
+        if (hexFile.isEmpty())
             return;
 
         Settings::currentPath = QFileInfo(hexFile).absoluteDir().path();
         Settings::save();
 
-        if( _op )
+        if (_op)
             _op->upgradeFW(hexFile);
-    }
-    catch(const std::exception& e) {
-        LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2")
-                    .arg(tr("Error"))
-                    .arg(e.what()) );
+    } catch (const std::exception &e) {
+        LOG_INFO(
+            QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
     }
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
-void MainWindow::statusMessage(const QString& msg)
+void MainWindow::statusMessage(const QString &msg)
 {
-    {   // Move cursor to end of document.
+    { // Move cursor to end of document.
         QTextCursor c = _ui->console->textCursor();
         c.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
         _ui->console->setTextCursor(c);
@@ -476,23 +452,20 @@
 //////////////////////////////////////////////////////////////////////////////
 void MainWindow::on_signalButton_clicked()
 {
-    Q_ASSERT( _op );
+    Q_ASSERT(_op);
 
     try {
-            LOG_INFO(tr("Request Bluetooth signal strength..."));
-            _op->getSignal();
-    }
-    catch(const std::exception& e) {
-        LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2")
-                    .arg(tr("Error"))
-                    .arg(e.what()) );
+        LOG_INFO(tr("Request Bluetooth signal strength..."));
+        _op->getSignal();
+    } catch (const std::exception &e) {
+        LOG_INFO(
+            QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
     }
 }
 
-
 void MainWindow::on_editLog_clicked()
 {
-    EditLogDialog* eL = new EditLogDialog(this, _op);
+    EditLogDialog *eL = new EditLogDialog(this, _op);
     eL->exec();
     delete eL;
 }