@@ -2428,73 +2428,78 @@ void MainWindow::reloadSettings()
24282428
24292429void MainWindow::checkNewVersion (const bool automatic)
24302430{
2431- RemoteNetwork::get ().fetch (QUrl (" https://download.sqlitebrowser.org/currentrelease" ), RemoteNetwork::RequestTypeCustom,
2431+ RemoteNetwork::get ().fetch (QUrl (" https://download.sqlitebrowser.org/currentrelease" ), RemoteNetwork::RequestTypeCustom,
24322432 QString (), [this , automatic](const QByteArray& reply) {
2433- QList<QByteArray> info = reply.split (' \n ' );
2434- if (info.size () >= 2 )
2435- {
2436- const QString versionString = info.at (0 ).trimmed ();
2437- const QString url = info.at (1 ).trimmed ();
2433+ QList<QByteArray> info = reply.split (' \n ' );
2434+ if (info.size () >= 2 )
2435+ {
2436+ QString version = info.at (0 ).trimmed ();
2437+ QString url = info.at (1 ).trimmed ();
2438+ compareVersionAndShowDialog (version, url, automatic);
24382439
2439- // versionString contains a major.minor.patch version string
2440- QStringList versiontokens = versionString.split (" ." );
2441- if (versiontokens.size () < 3 )
2442- return ;
2440+ }
2441+ }, false , true );
2442+ }
2443+
2444+ void MainWindow::compareVersionAndShowDialog (const QString& versionstring, const QString& url, const bool automatic)
2445+ {
2446+ // versionString contains a major.minor.patch version string
2447+ QStringList versiontokens = versionstring.split (" ." );
2448+ if (versiontokens.size () < 3 )
2449+ return ;
24432450
2444- int major = versiontokens[0 ].toInt ();
2445- int minor = versiontokens[1 ].toInt ();
2446- int patch = versiontokens[2 ].toInt ();
2451+ int major = versiontokens[0 ].toInt ();
2452+ int minor = versiontokens[1 ].toInt ();
2453+ int patch = versiontokens[2 ].toInt ();
24472454
2448- bool newversion = false ;
2449- if (major > MAJOR_VERSION)
2455+ bool newversion = false ;
2456+ if (major > MAJOR_VERSION)
2457+ newversion = true ;
2458+ else if (major == MAJOR_VERSION)
2459+ {
2460+ if (minor > MINOR_VERSION)
2461+ newversion = true ;
2462+ else if (minor == MINOR_VERSION)
2463+ {
2464+ if (patch > PATCH_VERSION)
24502465 newversion = true ;
2451- else if (major == MAJOR_VERSION)
2452- {
2453- if (minor > MINOR_VERSION)
2454- newversion = true ;
2455- else if (minor == MINOR_VERSION)
2456- {
2457- if (patch > PATCH_VERSION)
2458- newversion = true ;
2459- }
2460- }
2466+ }
2467+ }
24612468
2462- if (newversion)
2463- {
2464- int ignmajor = (automatic) ? Settings::getValue (" checkversion" , " ignmajor" ).toInt () : 0 ;
2465- int ignminor = (automatic) ? Settings::getValue (" checkversion" , " ignminor" ).toInt () : 0 ;
2466- int ignpatch = (automatic) ? Settings::getValue (" checkversion" , " ignpatch" ).toInt () : 0 ;
2469+ if (newversion)
2470+ {
2471+ int ignmajor = (automatic) ? Settings::getValue (" checkversion" , " ignmajor" ).toInt () : 0 ;
2472+ int ignminor = (automatic) ? Settings::getValue (" checkversion" , " ignminor" ).toInt () : 0 ;
2473+ int ignpatch = (automatic) ? Settings::getValue (" checkversion" , " ignpatch" ).toInt () : 0 ;
24672474
2468- // check if the user doesn't care about the current update
2469- if (!(ignmajor == major && ignminor == minor && ignpatch == patch))
2470- {
2471- QMessageBox msgBox;
2472- // WARN: Please note that if the user attempts to manually check for updates, the value of this variable may be nullptr.
2473- QPushButton *idontcarebutton = (automatic) ? msgBox.addButton (tr (" Don't show again" ), QMessageBox::ActionRole) : nullptr ;
2474- msgBox.addButton (QMessageBox::Ok);
2475- msgBox.setTextFormat (Qt::RichText);
2476- msgBox.setWindowTitle (tr (" New version available." ));
2477- msgBox.setText (tr (" A new DB Browser for SQLite version is available (%1.%2.%3).<br/><br/>"
2478- " Please download at <a href='%4'>%4</a>." ).arg (major).arg (minor).arg (patch).
2479- arg (url));
2480- msgBox.exec ();
2481-
2482- if (msgBox.clickedButton () == idontcarebutton)
2483- {
2484- // save that the user don't want to get bothered about this update
2485- Settings::setValue (" checkversion" , " ignmajor" , major);
2486- Settings::setValue (" checkversion" , " ignminor" , minor);
2487- Settings::setValue (" checkversion" , " ignpatch" , patch);
2488- }
2489- }
2490- }
2491- else
2475+ // check if the user doesn't care about the current update
2476+ if (!(ignmajor == major && ignminor == minor && ignpatch == patch))
2477+ {
2478+ QMessageBox msgBox;
2479+ // WARN: Please note that if the user attempts to manually check for updates, the value of this variable may be nullptr.
2480+ QPushButton *idontcarebutton = (automatic) ? msgBox.addButton (tr (" Don't show again" ), QMessageBox::ActionRole) : nullptr ;
2481+ msgBox.addButton (QMessageBox::Ok);
2482+ msgBox.setTextFormat (Qt::RichText);
2483+ msgBox.setWindowTitle (tr (" New version available." ));
2484+ msgBox.setText (tr (" A new DB Browser for SQLite version is available (%1.%2.%3).<br/><br/>"
2485+ " Please download at <a href='%4'>%4</a>." ).arg (major).arg (minor).arg (patch).
2486+ arg (url));
2487+ msgBox.exec ();
2488+
2489+ if (msgBox.clickedButton () == idontcarebutton)
24922490 {
2493- if (!automatic)
2494- QMessageBox::information (this , QApplication::applicationName (), tr (" You are using the latest version." ));
2491+ // save that the user don't want to get bothered about this update
2492+ Settings::setValue (" checkversion" , " ignmajor" , major);
2493+ Settings::setValue (" checkversion" , " ignminor" , minor);
2494+ Settings::setValue (" checkversion" , " ignpatch" , patch);
24952495 }
24962496 }
2497- }, false , true );
2497+ }
2498+ else
2499+ {
2500+ if (!automatic)
2501+ QMessageBox::information (this , QApplication::applicationName (), tr (" You are using the latest version." ));
2502+ }
24982503}
24992504
25002505void MainWindow::openLinkWiki () const
0 commit comments