Add some improvements to the Update Hamlib feature (display Hamlib version, etc.).

This commit is contained in:
Uwe Risse 2023-10-29 12:48:26 +01:00
parent 84069fe9e9
commit 3fcb8d3deb
3 changed files with 100 additions and 29 deletions

View File

@ -173,7 +173,6 @@
#include <QJsonDocument>
#include <QJsonArray>
#include "pimpl_impl.hpp"
#include "Logger.hpp"
#include "qt_helpers.hpp"
@ -331,9 +330,9 @@ public:
connect (button_box, &QDialogButtonBox::accepted, this, &FrequencyDialog::accept);
connect (button_box, &QDialogButtonBox::rejected, this, &FrequencyDialog::reject);
connect(start_date_time_edit_, &QDateTimeEdit::dateTimeChanged, this, &FrequencyDialog::checkSaneDates);
connect(end_date_time_edit_, &QDateTimeEdit::dateTimeChanged, this, &FrequencyDialog::checkSaneDates);
connect(enable_dates_checkbox_, &QCheckBox::stateChanged, this, &FrequencyDialog::toggleValidity);
connect (start_date_time_edit_, &QDateTimeEdit::dateTimeChanged, this, &FrequencyDialog::checkSaneDates);
connect (end_date_time_edit_, &QDateTimeEdit::dateTimeChanged, this, &FrequencyDialog::checkSaneDates);
connect (enable_dates_checkbox_, &QCheckBox::stateChanged, this, &FrequencyDialog::toggleValidity);
toggleValidity();
}
@ -585,6 +584,7 @@ private:
Q_SLOT void on_revert_update_button_clicked (bool);
void error_during_hamlib_download (QString const& reason);
void after_hamlib_downloaded();
void display_file_information();
Q_SLOT void on_cbx2ToneSpacing_clicked(bool);
Q_SLOT void on_cbx4ToneSpacing_clicked(bool);
@ -689,6 +689,7 @@ private:
QString FD_exchange_;
QString RTTY_exchange_;
QString Contest_Name_;
QString hamlib_backed_up_;
qint32 id_interval_;
qint32 ntrials_;
@ -1575,6 +1576,7 @@ void Configuration::impl::read_settings ()
ui_->Field_Day_Exchange->setText(FD_exchange_);
ui_->RTTY_Exchange->setText(RTTY_exchange_);
ui_->Contest_Name->setText(Contest_Name_);
hamlib_backed_up_ = settings_->value ("HamlibBackedUp",QString {}).toString ();
if (next_font_.fromString (settings_->value ("Font", QGuiApplication::font ().toString ()).toString ())
&& next_font_ != font_)
@ -1751,6 +1753,11 @@ void Configuration::impl::read_settings ()
pwrBandTuneMemory_ = settings_->value("pwrBandTuneMemory",false).toBool ();
highlight_DXcall_ = settings_->value("highlight_DXcall",false).toBool ();
highlight_DXgrid_ = settings_->value("highlight_DXgrid",false).toBool ();
#ifdef WIN32
QTimer::singleShot (2500, [=] {display_file_information ();});
#else
ui_->hamlib_groupBox->setVisible(false);
#endif
}
void Configuration::impl::find_audio_devices ()
@ -2492,6 +2499,10 @@ void Configuration::impl::on_decoded_text_font_push_button_clicked ()
void Configuration::impl::on_hamlib_download_button_clicked (bool /*clicked*/)
{
#ifdef WIN32
extern char* hamlib_version2;
SettingsGroup g {settings_, "Configuration"};
settings_->setValue ("HamlibBackedUp", hamlib_version2);
settings_->sync ();
QDir dataPath = QCoreApplication::applicationDirPath();
QFile f1 {dataPath.absolutePath() + "/" + "libhamlib-4_old.dll"};
QFile f2 {dataPath.absolutePath() + "/" + "libhamlib-4_new.dll"};
@ -2501,14 +2512,14 @@ void Configuration::impl::on_hamlib_download_button_clicked (bool /*clicked*/)
ui_->revert_update_button->setEnabled (false);
if (ui_->rbHamlib32->isChecked()) {
cty_download.configure(network_manager_,
"https://n0nb.users.sourceforge.net/dll32/libhamlib-4.dll",
dataPath.absoluteFilePath("libhamlib-4_new.dll"),
"Downloading latest libhamlib-4.dll");
"https://n0nb.users.sourceforge.net/dll32/libhamlib-4.dll",
dataPath.absoluteFilePath("libhamlib-4_new.dll"),
"Downloading latest libhamlib-4.dll");
} else {
cty_download.configure(network_manager_,
"https://n0nb.users.sourceforge.net/dll64/libhamlib-4.dll",
dataPath.absoluteFilePath("libhamlib-4_new.dll"),
"Downloading latest libhamlib-4.dll");
"https://n0nb.users.sourceforge.net/dll64/libhamlib-4.dll",
dataPath.absoluteFilePath("libhamlib-4_new.dll"),
"Downloading latest libhamlib-4.dll");
}
connect (&cty_download, &FileDownload::complete, this, &Configuration::impl::after_hamlib_downloaded, Qt::UniqueConnection);
connect (&cty_download, &FileDownload::error, this, &Configuration::impl::error_during_hamlib_download, Qt::UniqueConnection);
@ -2550,7 +2561,7 @@ void Configuration::impl::on_revert_update_button_clicked (bool /*clicked*/)
ui_->hamlib_download_button->setEnabled (false);
QFile::rename(dataPath.absolutePath() + "/" + "libhamlib-4.dll", dataPath.absolutePath() + "/" + "libhamlib-4_new.dll");
QTimer::singleShot (1000, [=] {
QFile::rename(dataPath.absolutePath() + "/" + "libhamlib-4_old.dll", dataPath.absolutePath() + "/" + "libhamlib-4.dll");
QFile::copy(dataPath.absolutePath() + "/" + "libhamlib-4_old.dll", dataPath.absolutePath() + "/" + "libhamlib-4.dll");
});
QTimer::singleShot (2000, [=] {
MessageBox::information_message (this, tr ("Hamlib successfully reverted \n\nReverted Hamlib will be used after restart"));
@ -2565,6 +2576,26 @@ void Configuration::impl::on_revert_update_button_clicked (bool /*clicked*/)
#endif
}
void Configuration::impl::display_file_information ()
{
#ifdef WIN32
QDir dataPath = QCoreApplication::applicationDirPath();
extern char* hamlib_version2;
ui_->in_use->setText(hamlib_version2);
QFileInfo fi2(dataPath.absolutePath() + "/" + "libhamlib-4_old.dll");
QString birthTime2 = fi2.birthTime().toString("yyyy-MM-dd hh:mm");
QFile f {dataPath.absolutePath() + "/" + "libhamlib-4_old.dll"};
if (f.exists()) {
if (hamlib_backed_up_=="") {
ui_->backed_up->setText(QString{"no hamlib data available, file saved %1"}.arg(birthTime2));
} else {
ui_->backed_up->setText(hamlib_backed_up_);
}
} else {
ui_->backed_up->setText("");
}
#endif
}
void Configuration::impl::on_PTT_port_combo_box_activated (int /* index */)
{

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>684</width>
<height>662</height>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
@ -1371,7 +1371,7 @@ radio interface behave as expected.</string>
<item row="12" column="0">
<widget class="QGroupBox" name="hamlib_groupBox">
<property name="title">
<string>Update Hamlib (Windows only)</string>
<string>Update Hamlib</string>
</property>
<layout class="QGridLayout" name="gridLayout_18">
<item row="0" column="0">
@ -1391,6 +1391,16 @@ radio interface behave as expected.</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="revert_update_button">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Revert the last Hamlib update. &lt;/p&gt;&lt;p&gt;Note: This function is only available on Windows.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Revert Update</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="hamlib_download_button">
<property name="toolTip">
@ -1401,15 +1411,37 @@ radio interface behave as expected.</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="revert_update_button">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Revert the last Hamlib update. &lt;/p&gt;&lt;p&gt;Note: This function is only available on Windows.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Revert Update</string>
</property>
</widget>
<item row="1" column="0" colspan="4">
<layout class="QGridLayout" name="hamlib_version_gridLayout" columnstretch="0,1">
<item row="0" column="0">
<widget class="QLabel" name="in_use_text">
<property name="text">
<string>In use:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="backed_up_text">
<property name="text">
<string>Backed up:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="in_use">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="backed_up">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
@ -3466,13 +3498,13 @@ Right click for insert and delete options.</string>
</connection>
</connections>
<buttongroups>
<buttongroup name="TX_audio_source_button_group"/>
<buttongroup name="CAT_stop_bits_button_group"/>
<buttongroup name="TX_mode_button_group"/>
<buttongroup name="split_mode_button_group"/>
<buttongroup name="CAT_data_bits_button_group"/>
<buttongroup name="CAT_handshake_button_group"/>
<buttongroup name="split_mode_button_group"/>
<buttongroup name="TX_audio_source_button_group"/>
<buttongroup name="TX_mode_button_group"/>
<buttongroup name="special_op_activity_button_group"/>
<buttongroup name="CAT_data_bits_button_group"/>
<buttongroup name="CAT_stop_bits_button_group"/>
<buttongroup name="PTT_method_button_group"/>
</buttongroups>
</ui>

View File

@ -1088,7 +1088,15 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
// backup libhamlib-4.dll file, so it is still available after the next program update
QDir dataPath = QCoreApplication::applicationDirPath();
QFile f {dataPath.absolutePath() + "/" + "libhamlib-4_old.dll"};
if (!f.exists()) QFile::copy(dataPath.absolutePath() + "/" + "libhamlib-4.dll", dataPath.absolutePath() + "/" + "libhamlib-4_old.dll");
if (!f.exists()) {
QFile::copy(dataPath.absolutePath() + "/" + "libhamlib-4.dll", dataPath.absolutePath() + "/" + "libhamlib-4_old.dll");
QTimer::singleShot (5000, [=] { //wait until hamlib has been started
extern char* hamlib_version2;
m_settings->beginGroup("Configuration");
m_settings->setValue ("HamlibBackedUp", hamlib_version2);
m_settings->endGroup();
});
}
#endif
// this must be the last statement of constructor