diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index cebea59e..ad639b54 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -8,7 +8,7 @@ #include "lc_viewwidget.h" #include "lc_colorlist.h" #include "lc_qutils.h" -#include "lc_qupdatedialog.h" +#include "lc_updatedialog.h" #include "lc_aboutdialog.h" #include "lc_setsdatabasedialog.h" #include "lc_qhtmldialog.h" @@ -1299,7 +1299,7 @@ void lcMainWindow::Print(QPrinter* Printer) void lcMainWindow::ShowUpdatesDialog() { - lcQUpdateDialog Dialog(this, false); + lcUpdateDialog Dialog(this, false); Dialog.exec(); } diff --git a/common/lc_updatedialog.cpp b/common/lc_updatedialog.cpp new file mode 100644 index 00000000..5f86e36e --- /dev/null +++ b/common/lc_updatedialog.cpp @@ -0,0 +1,147 @@ +#include "lc_global.h" +#include "lc_updatedialog.h" +#include "ui_lc_qupdatedialog.h" +#include "lc_application.h" +#include "lc_library.h" +#include "lc_profile.h" +#include "lc_http.h" + +void lcDoInitialUpdateCheck() +{ + int UpdateFrequency = lcGetProfileInt(LC_PROFILE_CHECK_UPDATES); + + if (UpdateFrequency == 0) + return; + + QSettings Settings; + QDateTime CheckTime = Settings.value("Updates/LastCheck", QDateTime()).toDateTime(); + + if (!CheckTime.isNull()) + { + QDateTime NextCheckTime = CheckTime.addDays(UpdateFrequency == 1 ? 1 : 7); + + if (NextCheckTime > QDateTime::currentDateTimeUtc()) + return; + } + + new lcUpdateDialog(nullptr, true); +} + +lcUpdateDialog::lcUpdateDialog(QWidget* Parent, bool InitialUpdate) + : QDialog(Parent), ui(new Ui::lcUpdateDialog), mInitialUpdate(InitialUpdate) +{ + ui->setupUi(this); + + connect(this, SIGNAL(finished(int)), this, SLOT(finished(int))); + + ui->status->setText(tr("Connecting to update server...")); + + mHttpManager = new lcHttpManager(this); + connect(mHttpManager, &lcHttpManager::DownloadFinished, this, &lcUpdateDialog::DownloadFinished); + + mHttpManager->DownloadFile(QLatin1String("https://www.leocad.org/updates.txt")); +} + +lcUpdateDialog::~lcUpdateDialog() +{ + delete ui; +} + +void lcUpdateDialog::accept() +{ + QSettings Settings; + Settings.setValue("Updates/IgnoreVersion", mVersionData); + + QDialog::accept(); +} + +void lcUpdateDialog::finished(int result) +{ + Q_UNUSED(result); + + if (mInitialUpdate) + deleteLater(); +} + +void lcUpdateDialog::DownloadFinished(lcHttpReply* Reply) +{ + bool UpdateAvailable = false; + + if (Reply->error() == QNetworkReply::NoError) + { + int MajorVersion, MinorVersion, PatchVersion; + int Parts; + + mVersionData = Reply->readAll(); + const char* Update = mVersionData; + + QSettings Settings; + QByteArray IgnoreUpdate = Settings.value("Updates/IgnoreVersion", QByteArray()).toByteArray(); + + if (mInitialUpdate && IgnoreUpdate == mVersionData) + { + UpdateAvailable = false; + } + else if (sscanf(Update, "%d.%d.%d %d", &MajorVersion, &MinorVersion, &PatchVersion, &Parts) == 4) + { + QString Status; + + if (MajorVersion > LC_VERSION_MAJOR) + UpdateAvailable = true; + else if (MajorVersion == LC_VERSION_MAJOR) + { + if (MinorVersion > LC_VERSION_MINOR) + UpdateAvailable = true; + else if (MinorVersion == LC_VERSION_MINOR) + { + if (PatchVersion > LC_VERSION_PATCH) + UpdateAvailable = true; + } + } + + if (UpdateAvailable) + Status = QString(tr("

There's a newer version of LeoCAD available for download (%1.%2.%3).

")).arg(QString::number(MajorVersion), QString::number(MinorVersion), QString::number(PatchVersion)); + else + Status = tr("

You are using the latest LeoCAD version.

"); + + lcPiecesLibrary* Library = lcGetPiecesLibrary(); + + if (Library->mNumOfficialPieces) + { + if (Parts > Library->mNumOfficialPieces) + { + Status += tr("

There are new parts available.

"); + UpdateAvailable = true; + } + else + Status += tr("

There are no new parts available at this time.

"); + } + + if (UpdateAvailable) + { + Status += tr("

Visit https://github.com/leozide/leocad/releases to download.

"); + } + + ui->status->setText(Status); + } + else + ui->status->setText(tr("Error parsing update information.")); + + Settings.setValue("Updates/LastCheck", QDateTime::currentDateTimeUtc()); + } + else + ui->status->setText(tr("Error connecting to the update server.")); + + if (mInitialUpdate) + { + if (UpdateAvailable) + show(); + else + deleteLater(); + } + + if (UpdateAvailable) + ui->buttonBox->setStandardButtons(QDialogButtonBox::Close | QDialogButtonBox::Ignore); + else + ui->buttonBox->setStandardButtons(QDialogButtonBox::Close); +} diff --git a/qt/lc_qupdatedialog.h b/common/lc_updatedialog.h similarity index 51% rename from qt/lc_qupdatedialog.h rename to common/lc_updatedialog.h index a2f4fdd5..3727281b 100644 --- a/qt/lc_qupdatedialog.h +++ b/common/lc_updatedialog.h @@ -1,37 +1,33 @@ #pragma once -#include - class lcHttpReply; class lcHttpManager; namespace Ui { -class lcQUpdateDialog; +class lcUpdateDialog; } void lcDoInitialUpdateCheck(); -class lcQUpdateDialog : public QDialog +class lcUpdateDialog : public QDialog { Q_OBJECT public: - explicit lcQUpdateDialog(QWidget* Parent, bool InitialUpdate); - ~lcQUpdateDialog(); + lcUpdateDialog(QWidget* Parent, bool InitialUpdate); + virtual ~lcUpdateDialog(); - void parseUpdate(const char *update); + void ParseUpdate(const char* Update); public slots: void DownloadFinished(lcHttpReply* Reply); void accept() override; - void reject() override; void finished(int result); private: - Ui::lcQUpdateDialog *ui; + Ui::lcUpdateDialog *ui; lcHttpManager* mHttpManager; - QByteArray versionData; + QByteArray mVersionData; bool mInitialUpdate; }; - diff --git a/qt/lc_qupdatedialog.ui b/common/lc_updatedialog.ui similarity index 82% rename from qt/lc_qupdatedialog.ui rename to common/lc_updatedialog.ui index c9b14f75..057d5d7c 100644 --- a/qt/lc_qupdatedialog.ui +++ b/common/lc_updatedialog.ui @@ -1,7 +1,7 @@ - lcQUpdateDialog - + lcUpdateDialog + 0 @@ -20,7 +20,7 @@ - Qt::RichText + Qt::TextFormat::RichText true @@ -30,10 +30,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QDialogButtonBox::Cancel + QDialogButtonBox::StandardButton::Cancel @@ -44,7 +44,7 @@ buttonBox accepted() - lcQUpdateDialog + lcUpdateDialog accept() @@ -60,7 +60,7 @@ buttonBox rejected() - lcQUpdateDialog + lcUpdateDialog reject() diff --git a/leocad.pro b/leocad.pro index ea191f8c..849ee45a 100644 --- a/leocad.pro +++ b/leocad.pro @@ -227,6 +227,7 @@ SOURCES += \ common/lc_thumbnailmanager.cpp \ common/lc_timelinewidget.cpp \ common/lc_traintrack.cpp \ + common/lc_updatedialog.cpp \ common/lc_view.cpp \ common/lc_viewmanipulator.cpp \ common/lc_viewsphere.cpp \ @@ -238,7 +239,6 @@ SOURCES += \ qt/lc_qhtmldialog.cpp \ qt/lc_qpreferencesdialog.cpp \ qt/lc_qimagedialog.cpp \ - qt/lc_qupdatedialog.cpp \ qt/lc_qutils.cpp \ qt/lc_renderdialog.cpp \ qt/lc_setsdatabasedialog.cpp @@ -306,6 +306,7 @@ HEADERS += \ common/lc_thumbnailmanager.h \ common/lc_timelinewidget.h \ common/lc_traintrack.h \ + common/lc_updatedialog.h \ common/lc_view.h \ common/lc_viewmanipulator.h \ common/lc_viewsphere.h \ @@ -316,20 +317,11 @@ HEADERS += \ qt/lc_qhtmldialog.h \ qt/lc_qpreferencesdialog.h \ qt/lc_qimagedialog.h \ - qt/lc_qupdatedialog.h \ qt/lc_qutils.h \ qt/lc_renderdialog.h \ qt/lc_setsdatabasedialog.h \ common/lc_partpalettedialog.h FORMS += \ - qt/lc_qselectdialog.ui \ - qt/lc_qpropertiesdialog.ui \ - qt/lc_qhtmldialog.ui \ - qt/lc_qpreferencesdialog.ui \ - qt/lc_qimagedialog.ui \ - qt/lc_qupdatedialog.ui \ - qt/lc_renderdialog.ui \ - qt/lc_setsdatabasedialog.ui \ common/lc_aboutdialog.ui \ common/lc_arraydialog.ui \ common/lc_categorydialog.ui \ @@ -338,7 +330,15 @@ FORMS += \ common/lc_minifigdialog.ui \ common/lc_modellistdialog.ui \ common/lc_pagesetupdialog.ui \ - common/lc_partpalettedialog.ui + common/lc_partpalettedialog.ui \ + common/lc_updatedialog.ui \ + qt/lc_qselectdialog.ui \ + qt/lc_qpropertiesdialog.ui \ + qt/lc_qhtmldialog.ui \ + qt/lc_qpreferencesdialog.ui \ + qt/lc_qimagedialog.ui \ + qt/lc_renderdialog.ui \ + qt/lc_setsdatabasedialog.ui OTHER_FILES += RESOURCES += leocad.qrc resources/stylesheet/stylesheet.qrc diff --git a/qt/lc_qupdatedialog.cpp b/qt/lc_qupdatedialog.cpp deleted file mode 100644 index 059dfaa3..00000000 --- a/qt/lc_qupdatedialog.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "lc_global.h" -#include "lc_qupdatedialog.h" -#include "ui_lc_qupdatedialog.h" -#include "lc_application.h" -#include "lc_library.h" -#include "lc_profile.h" -#include "lc_http.h" - -void lcDoInitialUpdateCheck() -{ - int updateFrequency = lcGetProfileInt(LC_PROFILE_CHECK_UPDATES); - - if (updateFrequency == 0) - return; - - QSettings settings; - QDateTime CheckTime = settings.value("Updates/LastCheck", QDateTime()).toDateTime(); - - if (!CheckTime.isNull()) - { - QDateTime NextCheckTime = CheckTime.addDays(updateFrequency == 1 ? 1 : 7); - - if (NextCheckTime > QDateTime::currentDateTimeUtc()) - return; - } - - new lcQUpdateDialog(nullptr, true); -} - -lcQUpdateDialog::lcQUpdateDialog(QWidget* Parent, bool InitialUpdate) - : QDialog(Parent), ui(new Ui::lcQUpdateDialog), mInitialUpdate(InitialUpdate) -{ - ui->setupUi(this); - - connect(this, SIGNAL(finished(int)), this, SLOT(finished(int))); - - ui->status->setText(tr("Connecting to update server...")); - - mHttpManager = new lcHttpManager(this); - connect(mHttpManager, SIGNAL(DownloadFinished(lcHttpReply*)), this, SLOT(DownloadFinished(lcHttpReply*))); - - mHttpManager->DownloadFile(QLatin1String("https://www.leocad.org/updates.txt")); -} - -lcQUpdateDialog::~lcQUpdateDialog() -{ - delete ui; -} - -void lcQUpdateDialog::accept() -{ - QSettings settings; - settings.setValue("Updates/IgnoreVersion", versionData); - - QDialog::accept(); -} - -void lcQUpdateDialog::reject() -{ - QDialog::reject(); -} - -void lcQUpdateDialog::finished(int result) -{ - Q_UNUSED(result); - - if (mInitialUpdate) - deleteLater(); -} - -void lcQUpdateDialog::DownloadFinished(lcHttpReply *reply) -{ - bool updateAvailable = false; - - if (reply->error() == QNetworkReply::NoError) - { - int majorVersion, minorVersion, patchVersion; - int parts; - - versionData = reply->readAll(); - const char *update = versionData; - - QSettings settings; - QByteArray ignoreUpdate = settings.value("Updates/IgnoreVersion", QByteArray()).toByteArray(); - - if (mInitialUpdate && ignoreUpdate == versionData) - { - updateAvailable = false; - } - else if (sscanf(update, "%d.%d.%d %d", &majorVersion, &minorVersion, &patchVersion, &parts) == 4) - { - QString status; - - if (majorVersion > LC_VERSION_MAJOR) - updateAvailable = true; - else if (majorVersion == LC_VERSION_MAJOR) - { - if (minorVersion > LC_VERSION_MINOR) - updateAvailable = true; - else if (minorVersion == LC_VERSION_MINOR) - { - if (patchVersion > LC_VERSION_PATCH) - updateAvailable = true; - } - } - - if (updateAvailable) - status = QString(tr("

There's a newer version of LeoCAD available for download (%1.%2.%3).

")).arg(QString::number(majorVersion), QString::number(minorVersion), QString::number(patchVersion)); - else - status = tr("

You are using the latest LeoCAD version.

"); - - lcPiecesLibrary* library = lcGetPiecesLibrary(); - - if (library->mNumOfficialPieces) - { - if (parts > library->mNumOfficialPieces) - { - status += tr("

There are new parts available.

"); - updateAvailable = true; - } - else - status += tr("

There are no new parts available at this time.

"); - } - - if (updateAvailable) - { - status += tr("

Visit https://github.com/leozide/leocad/releases to download.

"); - } - - ui->status->setText(status); - } - else - ui->status->setText(tr("Error parsing update information.")); - - settings.setValue("Updates/LastCheck", QDateTime::currentDateTimeUtc()); - } - else - ui->status->setText(tr("Error connecting to the update server.")); - - if (mInitialUpdate) - { - if (updateAvailable) - show(); - else - deleteLater(); - } - - if (updateAvailable) - ui->buttonBox->setStandardButtons(QDialogButtonBox::Close | QDialogButtonBox::Ignore); - else - ui->buttonBox->setStandardButtons(QDialogButtonBox::Close); -} diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index bf59102c..cd818eca 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -1,6 +1,6 @@ #include "lc_global.h" #include "lc_application.h" -#include "lc_qupdatedialog.h" +#include "lc_updatedialog.h" #include "lc_profile.h" #include "pieceinf.h" #include diff --git a/resources/leocad_cs.ts b/resources/leocad_cs.ts index 1aef3a31..f6c7aba8 100644 --- a/resources/leocad_cs.ts +++ b/resources/leocad_cs.ts @@ -8073,49 +8073,49 @@ GL_EXT_texture_filter_anisotropic rozšíření: %5 - lcQUpdateDialog + lcUpdateDialog - + LeoCAD Updates Aktualizace LeoCADu - + Connecting to update server... Připojuji se k aktualizačnímu serveru ... - + <p>There's a newer version of LeoCAD available for download (%1.%2.%3).</p> <p>K dispozici je novější verze LeoCADu ke stažení (%1.%2.%3).</p> - + <p>You are using the latest LeoCAD version.</p> <p>Používáte nejnovější verzi LeoCADu.</p> - + <p>There are new parts available.</p> <p>K dispozici jsou nové aktualizace.</p> - + <p>There are no new parts available at this time.</p> <p>Momentálně nejsou k dispozici žádné nové aktualizace.</p> - + <p>Visit <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> to download.</p> <p>Navštivte <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> pro stažení.</p> - + Error parsing update information. Při analýze informací o aktualizaci došlo k chybě. - + Error connecting to the update server. Při připojování k aktualizačnímu serveru došlo k chybě. diff --git a/resources/leocad_de.ts b/resources/leocad_de.ts index 25670640..afe08fb4 100644 --- a/resources/leocad_de.ts +++ b/resources/leocad_de.ts @@ -7963,49 +7963,49 @@ Anisotropic: %5 - lcQUpdateDialog + lcUpdateDialog - + LeoCAD Updates Aktualisierungen für LeoCAD - + Connecting to update server... Verbinde zum Server für Aktualisierungen… - + <p>There's a newer version of LeoCAD available for download (%1.%2.%3).</p> <p>Es ist einen neue Version von LeoCAD zum herunterladen verfügbar (%1.%2.%3).</p> - + <p>You are using the latest LeoCAD version.</p> <p>Sie benutzen die aktuelle Version von LeoCAD.</p> - + <p>There are new parts available.</p> <p>Es sind neue Teile verfügbar.</p> - + <p>There are no new parts available at this time.</p> <p>Im Moment gibt es keine neuen Teile.</p> - + <p>Visit <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> to download.</p> <p>Besuchen sie <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> zum downloaden.</p> - + Error parsing update information. Fehler bei der Analyse der Aktualisierungsinformation. - + Error connecting to the update server. Fehler bein Verbinden mit dem Aktualisierungsserver. diff --git a/resources/leocad_es.ts b/resources/leocad_es.ts index b1bf37fd..4d408e69 100644 --- a/resources/leocad_es.ts +++ b/resources/leocad_es.ts @@ -8106,49 +8106,49 @@ Anisotropic: %5 - lcQUpdateDialog + lcUpdateDialog - + LeoCAD Updates Actualizaciones de LeoCAD - + Connecting to update server... Conectando con el servidor de actualizaciones... - + <p>There's a newer version of LeoCAD available for download (%1.%2.%3).</p> <p>Hay una nueva versión de LeoCAD disponible para descargar (%1.%2.%3).</p> - + <p>You are using the latest LeoCAD version.</p> <p>Estás utilizando la última versión de LeoCAD.</p> - + <p>There are new parts available.</p> <p>No hay nuevas piezas disponibles.</p> - + <p>There are no new parts available at this time.</p> <p>No hay nuevas piezas disponibles en este momento.</p> - + <p>Visit <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> to download.</p> <p>Visita <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> para descargar.</p> - + Error parsing update information. Error parseando la información de la actualización. - + Error connecting to the update server. Error conectando al servidor de actualizaciones. diff --git a/resources/leocad_fr.ts b/resources/leocad_fr.ts index fe5ec3e6..f691f20d 100644 --- a/resources/leocad_fr.ts +++ b/resources/leocad_fr.ts @@ -7837,49 +7837,49 @@ Anisotropic: %5 - lcQUpdateDialog + lcUpdateDialog - + LeoCAD Updates Mises à jour LeoCAD - + Connecting to update server... Connexion au serveur de mise à jour… - + <p>There's a newer version of LeoCAD available for download (%1.%2.%3).</p> <p>Il y a une nouvelle version de LeoCAD disponible au téléchargement (%1.%2.%3).</p> - + <p>You are using the latest LeoCAD version.</p> <p>Vous utilisez la dernière version de LeoCAD.</p> - + <p>There are new parts available.</p> <p>Il y a de nouvelle pièces disponibles.</p> - + <p>There are no new parts available at this time.</p> <p>Il n’y a pas de nouvelle pièces disponibles en ce moment.</p> - + <p>Visit <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> to download.</p> - + Error parsing update information. Erreur à la lecture des informations de mise à jour. - + Error connecting to the update server. Erreur à la connexion au serveur de mise à jour. diff --git a/resources/leocad_pt.ts b/resources/leocad_pt.ts index 657b3e48..5b968687 100644 --- a/resources/leocad_pt.ts +++ b/resources/leocad_pt.ts @@ -7833,49 +7833,49 @@ Anisotropic: %5 - lcQUpdateDialog + lcUpdateDialog - + LeoCAD Updates Actualizações do LeoCAD - + Connecting to update server... A ligar ao servidor de actualizações... - + <p>There's a newer version of LeoCAD available for download (%1.%2.%3).</p> <p>Existe uma nova versão do LeoCAD em descarregamento (%1.%2.%3).</p> - + <p>You are using the latest LeoCAD version.</p> <p>Tem a última versão do LeoCAD.</p> - + <p>There are new parts available.</p> <p>Existem novas peças disponiveis.</p> - + <p>There are no new parts available at this time.</p> <p>Não há novas peças disponiveis.</p> - + <p>Visit <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> to download.</p> - + Error parsing update information. Erro ao ler a informação de actualização. - + Error connecting to the update server. Erro ao ligar ao servidor de actualizações. diff --git a/resources/leocad_ru.ts b/resources/leocad_ru.ts index 62d6cb07..a4b6ad6b 100644 --- a/resources/leocad_ru.ts +++ b/resources/leocad_ru.ts @@ -7975,49 +7975,49 @@ GL_EXT_texture_filter_anisotropic extension: %5 - lcQUpdateDialog + lcUpdateDialog - + LeoCAD Updates Обновления LeoCAD - + Connecting to update server... Соединение с сервером обновления… - + <p>There's a newer version of LeoCAD available for download (%1.%2.%3).</p> <p>Доступна новая версия LeoCAD для загрузки (%1.%2.%3).</p> - + <p>You are using the latest LeoCAD version.</p> <p>Используется последняя версия LeoCAD.</p> - + <p>There are new parts available.</p> <p>Доступны новые детали.</p> - + <p>There are no new parts available at this time.</p> <p>В данный момент новые детали недоступны.</p> - + <p>Visit <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> to download.</p> <p>Посетите <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> для загрузки.</p> - + Error parsing update information. Ошибка обработки информации по обновлению. - + Error connecting to the update server. Ошибка соединения с сервером обновления. diff --git a/resources/leocad_uk.ts b/resources/leocad_uk.ts index 8b55327f..4508c8c7 100644 --- a/resources/leocad_uk.ts +++ b/resources/leocad_uk.ts @@ -7899,49 +7899,49 @@ GL_EXT_texture_filter_anisotropic extension: %5 - lcQUpdateDialog + lcUpdateDialog - + LeoCAD Updates Оновлення LeoCAD - + Connecting to update server... З'єднання з сервером оновлень... - + <p>There's a newer version of LeoCAD available for download (%1.%2.%3).</p> <p>Доступна нова версія LeoCAD для завантаження (%1.%2.%3).</p> - + <p>You are using the latest LeoCAD version.</p> <p>Ви використовуєте найновішу версію LeoCAD.</p> - + <p>There are new parts available.</p> <p>Виявлено нові доступні блоки.</p> - + <p>There are no new parts available at this time.</p> <p>Наразі немає нових доступних блоків.</p> - + <p>Visit <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> to download.</p> <p>Відвідайте <a href="https://github.com/leozide/leocad/releases">https://github.com/leozide/leocad/releases</a> для завантаження.</p> - + Error parsing update information. Помилка розбору інформації оновлення. - + Error connecting to the update server. Помилка з'єднання з сервером оновлень.