Files
@ 11522eba8b9b
Branch filter:
Location: tempo-plotter/src/updatecheckdialog.cpp
11522eba8b9b
3.5 KiB
text/x-c++hdr
modify scrollzoomer so that it tries to maintain zoom window when buffer size changes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | /*
Copyright © 2017 Hasan Yavuz Özderya
This file is part of serialplot.
serialplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
serialplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with serialplot. If not, see <http://www.gnu.org/licenses/>.
*/
#include "setting_defines.h"
#include "updatecheckdialog.h"
#include "ui_updatecheckdialog.h"
UpdateCheckDialog::UpdateCheckDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::UpdateCheckDialog)
{
ui->setupUi(this);
// by default start from yesterday, so that we check at first run
lastCheck = QDate::currentDate().addDays(-1);
connect(&updateChecker, &UpdateChecker::checkFailed,
[this](QString errorMessage)
{
lastCheck = QDate::currentDate();
ui->label->setText(QString("Update check failed.\n") + errorMessage);
});
connect(&updateChecker, &UpdateChecker::checkFinished,
[this](bool found, QString newVersion, QString downloadUrl)
{
QString text;
if (!found)
{
text = "There is no update yet.";
}
else
{
show();
#ifdef UPDATE_TYPE_PKGMAN
text = QString("There is a new version: %1. "
"Use your package manager to update"
" or click to <a href=\"%2\">download</a>.")\
.arg(newVersion).arg(downloadUrl);
#else
text = QString("Found update to version %1. Click to <a href=\"%2\">download</a>.")\
.arg(newVersion).arg(downloadUrl);
#endif
}
lastCheck = QDate::currentDate();
ui->label->setText(text);
});
}
UpdateCheckDialog::~UpdateCheckDialog()
{
delete ui;
}
void UpdateCheckDialog::showEvent(QShowEvent *event)
{
updateChecker.checkUpdate();
ui->label->setText("Checking update...");
}
void UpdateCheckDialog::closeEvent(QShowEvent *event)
{
if (updateChecker.isChecking()) updateChecker.cancelCheck();
}
void UpdateCheckDialog::saveSettings(QSettings* settings)
{
settings->beginGroup(SettingGroup_UpdateCheck);
settings->setValue(SG_UpdateCheck_Periodic, ui->cbPeriodic->isChecked());
settings->setValue(SG_UpdateCheck_LastCheck, lastCheck.toString(Qt::ISODate));
settings->endGroup();
}
void UpdateCheckDialog::loadSettings(QSettings* settings)
{
settings->beginGroup(SettingGroup_UpdateCheck);
ui->cbPeriodic->setChecked(settings->value(SG_UpdateCheck_Periodic,
ui->cbPeriodic->isChecked()).toBool());
auto lastCheckS = settings->value(SG_UpdateCheck_LastCheck, lastCheck.toString(Qt::ISODate)).toString();
lastCheck = QDate::fromString(lastCheckS, Qt::ISODate);
settings->endGroup();
// start the periodic update if required
if (ui->cbPeriodic->isChecked() && lastCheck < QDate::currentDate())
{
updateChecker.checkUpdate();
}
}
|