diff --git a/Configuration.cpp b/Configuration.cpp index b955871..ae81d45 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -628,6 +628,7 @@ private: qint32 RxBandwidth_; double degrade_; double txDelay_; + bool check_for_updates_; bool id_after_73_; bool tx_qsy_allowed_; bool spot_to_reporting_networks_; @@ -750,6 +751,7 @@ qint32 Configuration::aggressive() const {return m_->aggressive_;} double Configuration::degrade() const {return m_->degrade_;} double Configuration::txDelay() const {return m_->txDelay_;} qint32 Configuration::RxBandwidth() const {return m_->RxBandwidth_;} +bool Configuration::check_for_updates() const { return m_->check_for_updates_; } bool Configuration::id_after_73 () const {return m_->id_after_73_;} bool Configuration::tx_qsy_allowed () const {return m_->tx_qsy_allowed_;} bool Configuration::spot_to_reporting_networks () const @@ -1400,6 +1402,7 @@ void Configuration::impl::initialize_models () ui_->sound_cq_path_display_label->setText(sound_cq_path_); ui_->sound_dm_path_display_label->setText(sound_dm_path_); ui_->sound_am_path_display_label->setText(sound_am_path_); + ui_->checkForUpdates_checkBox->setChecked (check_for_updates_); ui_->CW_id_after_73_check_box->setChecked (id_after_73_); ui_->tx_qsy_check_box->setChecked (tx_qsy_allowed_); ui_->psk_reporter_check_box->setChecked (spot_to_reporting_networks_); @@ -1677,6 +1680,7 @@ void Configuration::impl::read_settings () monitor_off_at_startup_ = settings_->value ("MonitorOFF", false).toBool (); monitor_last_used_ = settings_->value ("MonitorLastUsed", false).toBool (); spot_to_reporting_networks_ = settings_->value ("PSKReporter", true).toBool (); + check_for_updates_ = settings_->value("CheckForUpdates", true).toBool(); id_after_73_ = settings_->value ("After73", false).toBool (); tx_qsy_allowed_ = settings_->value ("TxQSYAllowed", false).toBool (); use_dynamic_info_ = settings_->value ("AutoGrid", false).toBool (); @@ -1849,6 +1853,7 @@ void Configuration::impl::write_settings () settings_->setValue ("MonitorOFF", monitor_off_at_startup_); settings_->setValue ("MonitorLastUsed", monitor_last_used_); settings_->setValue ("PSKReporter", spot_to_reporting_networks_); + settings_->setValue ("CheckForUpdates", check_for_updates_); settings_->setValue ("After73", id_after_73_); settings_->setValue ("TxQSYAllowed", tx_qsy_allowed_); settings_->setValue ("Macros", macros_.stringList ()); @@ -2381,6 +2386,7 @@ void Configuration::impl::accept () aggressive_ = ui_->sbAggressive->value (); degrade_ = ui_->sbDegrade->value (); RxBandwidth_ = ui_->sbBandwidth->value (); + check_for_updates_ = ui_->checkForUpdates_checkBox->isChecked(); id_after_73_ = ui_->CW_id_after_73_check_box->isChecked (); tx_qsy_allowed_ = ui_->tx_qsy_check_box->isChecked (); transmit_directed_ = ui_->transmit_directed_check_box->isChecked(); diff --git a/Configuration.hpp b/Configuration.hpp index f47ba0b..e971a87 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -118,6 +118,7 @@ public: qint32 RxBandwidth() const; double degrade() const; double txDelay() const; + bool check_for_updates() const; bool id_after_73 () const; bool tx_qsy_allowed () const; bool spot_to_reporting_networks () const; diff --git a/Configuration.ui b/Configuration.ui index aa4fd43..153e7ac 100644 --- a/Configuration.ui +++ b/Configuration.ui @@ -23,7 +23,7 @@ Select tab to change configuration parameters. - 3 + 0 @@ -63,7 +63,7 @@ 0 0 738 - 453 + 448 @@ -278,8 +278,8 @@ 0 0 - 615 - 646 + 726 + 631 @@ -394,6 +394,13 @@ + + + + Check for software updates at startup + + + @@ -918,8 +925,8 @@ text message. 0 0 - 718 - 435 + 285 + 397 @@ -1339,8 +1346,8 @@ a few, particularly some Kenwood rigs, require it). 0 0 - 237 - 467 + 257 + 427 @@ -1767,8 +1774,8 @@ radio interface behave as expected. 0 0 - 760 - 502 + 267 + 302 @@ -2080,8 +2087,8 @@ both here. 0 0 - 746 - 525 + 572 + 498 @@ -2543,8 +2550,8 @@ for assessing propagation and system performance. 0 0 - 760 - 502 + 498 + 321 @@ -3121,8 +3128,8 @@ QListView::item:hover { 0 0 - 738 - 378 + 280 + 201 @@ -3376,8 +3383,8 @@ QListView::item:hover { 0 0 - 233 - 253 + 236 + 258 @@ -3580,8 +3587,8 @@ QListView::item:hover { 0 0 - 277 - 93 + 288 + 96 @@ -4190,11 +4197,11 @@ soundcard changes + + - - diff --git a/mainwindow.cpp b/mainwindow.cpp index 11d7e65..874a84e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -1638,15 +1641,81 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, if (!m_valid) throw std::runtime_error {"Fatal initialization exception"}; } -void MainWindow::checkVersion(){ - auto m = new QNetworkAccessManager(this); - connect(m, &QNetworkAccessManager::finished, this, [this](QNetworkReply * reply){ - if(reply->error()) return; +QPair, int> splitVersion(QString v){ + int hyphenPos = v.lastIndexOf("-"); + if(hyphenPos >= 0){ + v = v.left(hyphenPos); + } - QString content = reply->readAll(); - qDebug() << "version" << content; + QVector intSegs; + foreach(QString seg, v.split(".")){ + bool ok = false; + int i = seg.toInt(&ok); + if(!ok){ + break; + } + intSegs.append(i); + } + + int len = intSegs.count(); + QPair, int> tuple; + if(len > 0){ + tuple.first.first = intSegs.at(0); + } + if(len > 1){ + tuple.first.second = intSegs.at(1); + } + if(len > 2){ + tuple.second = intSegs.at(2); + } + return tuple; +} + +void MainWindow::checkVersion(bool alertOnUpToDate){ + auto m = new QNetworkAccessManager(this); + connect(m, &QNetworkAccessManager::finished, this, [this, alertOnUpToDate](QNetworkReply * reply){ + if(reply->error()){ + qDebug() << "Checking for Updates Error:" << reply->errorString(); + return; + } + + QString content = reply->readAll().trimmed(); + + auto currentVersion = splitVersion(version()); + auto networkVersion = splitVersion(content); + + qDebug() << "Checking Version" << currentVersion << "with" << networkVersion; + + if(currentVersion < networkVersion){ + + SelfDestructMessageBox * m = new SelfDestructMessageBox(60, + "New Updates Available", + QString("A new version (%1) of JS8Call is now available. Please see js8call.com for more details.").arg(content), + QMessageBox::Information, + QMessageBox::Ok, + QMessageBox::Ok, + false, + this); + + m->show(); + + } else if(alertOnUpToDate){ + + SelfDestructMessageBox * m = new SelfDestructMessageBox(60, + "No Updates Available", + QString("Your version (%1) of JS8Call is up-to-date.").arg(version()), + QMessageBox::Information, + QMessageBox::Ok, + QMessageBox::Ok, + false, + this); + + m->show(); + + } }); + qDebug() << "Checking for Updates..."; QUrl url("http://files.js8call.com/version.txt"); QNetworkRequest r(url); m->get(r); @@ -1654,7 +1723,9 @@ void MainWindow::checkVersion(){ void MainWindow::checkStartupWarnings () { - checkVersion(); + if(m_config.check_for_updates()){ + checkVersion(false); + } ensureCallsignSet(false); } @@ -2598,6 +2669,10 @@ void MainWindow::on_menuControl_aboutToShow(){ #endif } +void MainWindow::on_actionCheck_for_Updates_triggered(){ + checkVersion(true); +} + void MainWindow::on_actionEnable_Spotting_toggled(bool checked){ ui->spotButton->setChecked(checked); } diff --git a/mainwindow.h b/mainwindow.h index b24c390..747ad40 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -177,6 +177,7 @@ private slots: void on_tx5_currentTextChanged (QString const&); void on_tx6_editingFinished(); void on_menuControl_aboutToShow(); + void on_actionCheck_for_Updates_triggered(); void on_actionEnable_Spotting_toggled(bool checked); void on_actionEnable_Auto_Reply_toggled(bool checked); void on_menuWindow_aboutToShow(); @@ -413,7 +414,7 @@ private slots: void on_cbCQTx_toggled(bool b); void splash_done (); void on_measure_check_box_stateChanged (int); - void checkVersion(); + void checkVersion(bool alertOnUpToDate); void checkStartupWarnings (); void clearCallsignSelected(); void refreshTextDisplay(); diff --git a/mainwindow.ui b/mainwindow.ui index a573951..2966989 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -4613,7 +4613,7 @@ list. The list can be maintained in Settings (F2). 0 0 994 - 22 + 25 @@ -4688,6 +4688,7 @@ list. The list can be maintained in Settings (F2). + @@ -5677,6 +5678,11 @@ list. The list can be maintained in Settings (F2). Show Message Inbox... + + + Check for Updates + +