mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-19 10:20:17 -06:00
add a version check feature
this is only enabled on windows as there is no package manager handling the versions and we don't want users to stay on old versions forever
This commit is contained in:
@@ -9,7 +9,7 @@ set(QHEXEDIT_DIR libs/qhexedit)
|
||||
add_subdirectory(${ANTLR_DIR})
|
||||
add_subdirectory(${QHEXEDIT_DIR})
|
||||
|
||||
find_package(Qt4 COMPONENTS QtCore QtGui QtTest REQUIRED)
|
||||
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork QtTest REQUIRED)
|
||||
|
||||
include(${QT_USE_FILE})
|
||||
add_definitions(${QT_DEFINITIONS})
|
||||
@@ -98,6 +98,9 @@ set_source_files_properties(src/AboutDialog.cpp PROPERTIES OBJECT_DEPENDS ${CMAK
|
||||
|
||||
#icon and correct libs/subsystem for windows
|
||||
if(WIN32)
|
||||
#enable version check for windows
|
||||
add_definitions(-DCHECKNEWVERSION)
|
||||
|
||||
IF( MINGW )
|
||||
# resource compilation for MinGW
|
||||
ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sqlbicon.o
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "SqlExecutionArea.h"
|
||||
#include "VacuumDialog.h"
|
||||
#include "DbStructureModel.h"
|
||||
#include "gen_version.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFile>
|
||||
@@ -29,6 +30,11 @@
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QElapsedTimer>
|
||||
#include <sqlite3.h>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QSettings>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QMainWindow(parent),
|
||||
@@ -122,6 +128,15 @@ void MainWindow::init()
|
||||
|
||||
// Load all settings
|
||||
reloadSettings();
|
||||
|
||||
#ifdef CHECKNEWVERSION
|
||||
// Check for a new release version, usually only enabled on windows
|
||||
m_NetworkManager = new QNetworkAccessManager(this);
|
||||
QObject::connect(m_NetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpresponse(QNetworkReply*)));
|
||||
|
||||
QUrl url("https://raw.github.com/rp-/sqlitebrowser/master/currentrelease");
|
||||
m_NetworkManager->get(QNetworkRequest(url));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool MainWindow::fileOpen(const QString& fileName)
|
||||
@@ -1201,3 +1216,66 @@ void MainWindow::reloadSettings()
|
||||
populateStructure();
|
||||
resetBrowser();
|
||||
}
|
||||
|
||||
void MainWindow::httpresponse(QNetworkReply *reply)
|
||||
{
|
||||
//QVariant statuscode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
|
||||
if(reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
// first line of the currentrelease file contains a major.minor.patch version string
|
||||
QString sversion(reply->readLine());
|
||||
|
||||
QStringList versiontokens = sversion.split(".");
|
||||
int major = versiontokens[0].toInt();
|
||||
int minor = versiontokens[1].toInt();
|
||||
int patch = versiontokens[2].toInt();
|
||||
|
||||
bool newversion = false;
|
||||
if(major > MAJOR_VERSION)
|
||||
newversion = true;
|
||||
else if(major == MAJOR_VERSION)
|
||||
{
|
||||
if(minor > MINOR_VERSION)
|
||||
newversion = true;
|
||||
else if(minor == MINOR_VERSION)
|
||||
{
|
||||
if(patch > PATCH_VERSION)
|
||||
newversion = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(newversion)
|
||||
{
|
||||
QSettings settings(QApplication::organizationName(), QApplication::organizationName());
|
||||
bool disablecheck = settings.value("checkversion/disable", false).toBool();
|
||||
int ignmajor = settings.value("checkversion/major", 999).toInt();
|
||||
int ignminor = settings.value("checkversion/minor", 0).toInt();
|
||||
int ignpatch = settings.value("checkversion/patch", 0).toInt();
|
||||
|
||||
// check if the user doesn't care about the current update
|
||||
if(!(ignmajor == major && ignminor == minor && ignpatch == patch && disablecheck))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
QPushButton *idontcarebutton = msgBox.addButton(tr("Don't show again"), QMessageBox::ActionRole);
|
||||
msgBox.addButton(QMessageBox::Ok);
|
||||
msgBox.setTextFormat(Qt::RichText);
|
||||
msgBox.setWindowTitle(tr("New version available."));
|
||||
msgBox.setText(tr("A new sqlitebrowser version is available (%1.%2.%3).<br/><br/>"
|
||||
"Please download at <a href='https://github.com/rp-/sqlitebrowser/releases'>https://github.com/rp-/sqlitebrowser/releases</a>.").arg(major).arg(minor).arg(patch));
|
||||
msgBox.exec();
|
||||
|
||||
if(msgBox.clickedButton() == idontcarebutton)
|
||||
{
|
||||
// save that the user don't want to get bothered about this update
|
||||
settings.beginGroup("checkversion");
|
||||
settings.setValue("major", major);
|
||||
settings.setValue("minor", minor);
|
||||
settings.setValue("patch", minor);
|
||||
settings.setValue("disable", true);
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ class QLabel;
|
||||
class QModelIndex;
|
||||
class SqliteTableModel;
|
||||
class DbStructureModel;
|
||||
class QNetworkReply;
|
||||
class QNetworkAccessManager;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@@ -81,6 +83,8 @@ private:
|
||||
QStandardItemModel completerModelTables;
|
||||
SqlTextEdit::FieldCompleterModelMap completerModelsFields;
|
||||
|
||||
QNetworkAccessManager* m_NetworkManager;
|
||||
|
||||
void init();
|
||||
|
||||
void updateRecentFileActions();
|
||||
@@ -148,6 +152,7 @@ private slots:
|
||||
virtual void saveSqlFile();
|
||||
virtual void loadExtension();
|
||||
virtual void reloadSettings();
|
||||
virtual void httpresponse(QNetworkReply* reply);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
#ifndef __GEN_VERSIONS_H__
|
||||
#define __GEN_VERISONS_H__
|
||||
#define APP_VERSION "master_git"
|
||||
#define MAJOR_VERSION 999
|
||||
#define MINOR_VERSION 0
|
||||
#define PATCH_VERSION 0
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
TEMPLATE = app
|
||||
|
||||
QT += core gui
|
||||
QT += core gui network
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = sqlitebrowser
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
cd $1
|
||||
|
||||
version=`git log -n1 --format="\"%h_git\""`
|
||||
version_macro="#define APP_VERSION $version"
|
||||
inc_guard_head="#ifndef __GEN_VERSIONS_H__\n#define __GEN_VERISONS_H__\n"
|
||||
inc_guard_foot="#endif"
|
||||
version_numbers="#define MAJOR_VERSION 999\n#define MINOR_VERSION 0\n#define PATCH_VERSION 0\n"
|
||||
version_macro="#define APP_VERSION $version\n"
|
||||
|
||||
if [ -f gen_version.h ]; then
|
||||
current_file=`cat gen_version.h`
|
||||
fi
|
||||
|
||||
if [ "$version_macro" != "$current_file" ]; then
|
||||
echo "$version_macro" > gen_version.h
|
||||
echo -e "$inc_guard_head$version_macro$version_numbers$inc_guard_foot" > gen_version.h
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user