From 04737aac1fc1969bc35c0c87a4eafaee97770467 Mon Sep 17 00:00:00 2001 From: antony-jr Date: Wed, 10 Mar 2021 17:47:40 +0530 Subject: [PATCH] Qt Plugin: use Application name instead of AppImage filename if given. --- docs/ClassQAppImageUpdate.md | 10 ++++ docs/PluginInterface.md | 10 ++++ include/qappimageupdateinterface.hpp | 1 + include/qappimageupdateinterfaceimpl.hpp | 1 + scripts/docker_build.sh | 73 ++++++++++++++++++++++++ src/qappimageupdate_p.cc | 16 ++++-- src/qappimageupdateinterfaceimpl.cc | 4 ++ 7 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 scripts/docker_build.sh diff --git a/docs/ClassQAppImageUpdate.md b/docs/ClassQAppImageUpdate.md index 5b35fcc..93a1531 100644 --- a/docs/ClassQAppImageUpdate.md +++ b/docs/ClassQAppImageUpdate.md @@ -39,6 +39,7 @@ All methods in this class is [reentrant](https://doc.qt.io/qt-5/threads-reentran | **void** | [setIcon(QByteArray)](#void-seticonqbytearray-icon) | | **void** | [start(short)](#void-startshort-action) | | **void** | [cancel()](#void-cancel) | +| **void** | [setApplicationName(const QString&)](#void-setapplicationname-qstring) | | **void** | [setAppImage(const QString&)](#void-setappimageconst-qstring) | | **void** | [setAppImage(QFile \*)](#void-setappimageqfile-) | | **void** | [setShowLog(bool)](#void-setshowlogbool) | @@ -199,6 +200,15 @@ Cancels the update. Emits **canceled(short action)** signal when cancel was successfull. +### void setApplicationName(const QString&) +

[SLOT]

+ +Set a application name to use when display GUI dialogs if required. + +> NOTE: This is optional. By default the GUI dialogs uses the AppImage filename. + + + ### void setAppImage(const QString&)

[SLOT]

diff --git a/docs/PluginInterface.md b/docs/PluginInterface.md index 79f2c84..ad95847 100644 --- a/docs/PluginInterface.md +++ b/docs/PluginInterface.md @@ -29,6 +29,7 @@ I'm not sure about other Qt bindings, So help is much welcomed. | [setIcon(QByteArray)](#seticonqbytearray-icon) | Set Icon for GUI Update. | | [start(short)](#startshort-action) | Starts the given action. | | [cancel()](#cancel) | Cancels current update process. | +| [setApplicationName(QString)](#setapplicationnameqstring) | Sets the Application Name in GUI dialogs. | | [setAppImagePath(QString)](#setappimagepathqstring) | Assume the given string as path to AppImage to update. | | [setAppImageFile(QFile\*)](#setappimagefileqfile) | Assume the given QFile as the AppImage to update. | | [setShowLog(bool)](#setshowlogbool) | If the given boolean is true then prints log. | @@ -170,6 +171,15 @@ One has to use **getConstant(QString)** method to get a constant. Cancels the current action. Emits **canceled(short)** signal when cancel for a action was successfull. + +### setApplicationName(QString) +

[SLOT]

+ +Sets the given string as the Application Name which will be used in GUI dialogs. + +> NOTE: This is optional and by default the updater uses the AppImage filename. + + ### setAppImagePath(QString)

[SLOT]

diff --git a/include/qappimageupdateinterface.hpp b/include/qappimageupdateinterface.hpp index 9ba7d8a..d7b6530 100644 --- a/include/qappimageupdateinterface.hpp +++ b/include/qappimageupdateinterface.hpp @@ -9,6 +9,7 @@ class QAppImageUpdateInterface { public Q_SLOTS: + virtual void setApplicationName(const QString&) = 0; virtual void setGuiFlag(int) = 0; virtual void setIcon(QByteArray) = 0; virtual void setAppImagePath(const QString&) = 0; diff --git a/include/qappimageupdateinterfaceimpl.hpp b/include/qappimageupdateinterfaceimpl.hpp index c22cae8..59344ae 100644 --- a/include/qappimageupdateinterfaceimpl.hpp +++ b/include/qappimageupdateinterfaceimpl.hpp @@ -21,6 +21,7 @@ class QAppImageUpdateInterfaceImpl : public QObject, QAppImageUpdateInterface { QAppImageUpdateInterfaceImpl(QObject *parent = nullptr); ~QAppImageUpdateInterfaceImpl(); public Q_SLOTS: + void setApplicationName(const QString&); void setIcon(QByteArray); void setGuiFlag(int); void setAppImagePath(const QString&); diff --git a/scripts/docker_build.sh b/scripts/docker_build.sh new file mode 100644 index 0000000..a08efe7 --- /dev/null +++ b/scripts/docker_build.sh @@ -0,0 +1,73 @@ +# Run it like so, +# docker run -v $PWD:/docker-share -it ubuntu:xenial bash scripts/docker_build.sh +# To get libQAppImageUpdate.so Qt Plugin. + +# Install dependencies +apt update +apt upgrade -y +apt install software-properties-common build-essential libarchive13 libarchive-dev wget expat -y +add-apt-repository ppa:beineri/opt-qt563-xenial -y +apt-get update -qq +apt install libgl1-mesa-dev xvfb qt56base -y + +cd /docker-share/ +rm -rf build +mkdir build +cd build + +# Build OpenSSL Static version +wget "https://www.openssl.org/source/openssl-1.1.1j.tar.gz" +tar -xf openssl-1.1.1j.tar.gz +cd openssl-1.1.1j +./config no-shared --prefix=/usr/ --openssldir=/usr/ +make -j$(nproc) +make install -j$(nproc) +cd .. + +# Install CURL +wget "https://curl.se/download/curl-7.75.0.tar.gz" +tar -xf curl-7.75.0.tar.gz +cd curl-7.75.0 +,/configure +make -j$(nproc) +make install -j$(nproc) +cd .. + +# Install CMake 3.19.6 +wget "https://github.com/Kitware/CMake/releases/download/v3.19.6/cmake-3.19.6.tar.gz" +tar -xf cmake-3.19.6.tar.gz +cd cmake-3.19.6 +./bootstrap +make -j$(nproc) +make install -j$(nproc) +cd .. + +# Install Boost libraries +wget "https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz" +tar -xf boost_1_75_0.tar.gz +cd boost_1_75_0 +./bootstrap.sh +cp b2 /usr/bin/ +echo "using gcc ;" > ~/user-config.jam +export BOOST_ROOT=$PWD +export BOOST_BUILD_PATH=$PWD/tools/build +BOOST_ROOT=$PWD BOOST_BUILD_PATH=$PWD/tools/build b2 cxxflags="-std=c++14" variant=release link=static install -j$(nproc) --with-system --with-chrono --with-random > /dev/null +cd .. + +# Install Torrent Rasterbar +wget "https://github.com/arvidn/libtorrent/releases/download/libtorrent-1.2.8/libtorrent-rasterbar-1.2.8.tar.gz" +tar -xvf libtorrent-rasterbar-1.2.8.tar.gz +cd libtorrent-rasterbar-1.2.8 +cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON . +make -j$(nproc) +make install -j$(nproc) +cd .. + +# Now Build QAppImageUpdate Qt Plugin. +source /opt/qt56/bin/qt56-env.sh +cmake -DDECENTRALIZED_UPDATE_ENABLED=ON -DBUILD_AS_PLUGIN=ON .. +make -j$(nproc) + +cp libQAppImageUpdate.* .. +cd .. +rm -rf build diff --git a/src/qappimageupdate_p.cc b/src/qappimageupdate_p.cc index 165c476..1c65ddf 100644 --- a/src/qappimageupdate_p.cc +++ b/src/qappimageupdate_p.cc @@ -871,7 +871,9 @@ void QAppImageUpdatePrivate::handleGUIUpdateCheck(QJsonObject info) { bool showNoUpdateDialog = n_GuiFlag & GuiFlag::NotifyWhenNoUpdateIsAvailable; bool noConfirmTorrentUsage = n_GuiFlag & GuiFlag::NoConfirmTorrentUsage; m_UpdaterDialog->setWindowTitle(QString::fromUtf8("Updating ") + - QFileInfo(localAppImagePath).baseName()); + (m_ApplicationName.isEmpty() ? + QFileInfo(localAppImagePath).baseName() : + m_ApplicationName)); bool isUpdateAvailable = (localAppImageSHA1Hash != remoteTargetFileSHA1Hash); @@ -886,7 +888,8 @@ void QAppImageUpdatePrivate::handleGUIUpdateCheck(QJsonObject info) { box.setText( QString::fromUtf8( "It seems that the author of ") + - QFileInfo(localAppImagePath).baseName() + + (m_ApplicationName.isEmpty() ? QFileInfo(localAppImagePath).baseName() : + m_ApplicationName) + QString::fromUtf8(" supports decentralized update via Bittorrent.") + QString::fromUtf8( " Do you agree to use Bittorrent for decentralized update? This is completely optional.") + @@ -923,8 +926,9 @@ void QAppImageUpdatePrivate::handleGUIUpdateCheck(QJsonObject info) { QMessageBox box(m_UpdaterDialog.data()); box.setWindowTitle(QString::fromUtf8("No Updates Available!")); box.setText( - QString::fromUtf8("You are currently using the lastest version of ") + - QFileInfo(localAppImagePath).fileName() + + QString::fromUtf8("You are currently using the lastest version of ") +\ + (m_ApplicationName.isEmpty() ? QFileInfo(localAppImagePath).fileName() + : m_ApplicationName ) + QString::fromUtf8(".")); box.exec(); } @@ -1135,7 +1139,7 @@ void QAppImageUpdatePrivate::handleGUIUpdateError(short ecode) { box.setWindowTitle(QString::fromUtf8("Update Failed")); box.setIcon(QMessageBox::Critical); box.setText(QString::fromUtf8("Update failed for '") + - QFileInfo(m_CurrentAppImagePath).fileName() + + (m_ApplicationName.isEmpty() ? QFileInfo(m_CurrentAppImagePath).fileName() : m_ApplicationName) + QString::fromUtf8("': ") + errorString); box.exec(); } @@ -1223,7 +1227,7 @@ void QAppImageUpdatePrivate::handleGUIUpdateFinished(QJsonObject info, QString o QString::fromUtf8("New version is saved at: ") + result["NewVersionPath"].toString()); box.setText(QString::fromUtf8("Update completed successfully for ") + - currentAppImageName + + (m_ApplicationName.isEmpty() ? currentAppImageName : m_ApplicationName) + QString::fromUtf8(", do you want to launch the new version? View details for more information.")); box.addButton(QMessageBox::Yes); box.addButton(QMessageBox::No); diff --git a/src/qappimageupdateinterfaceimpl.cc b/src/qappimageupdateinterfaceimpl.cc index 716e207..7554642 100644 --- a/src/qappimageupdateinterfaceimpl.cc +++ b/src/qappimageupdateinterfaceimpl.cc @@ -32,6 +32,10 @@ QAppImageUpdateInterfaceImpl::QAppImageUpdateInterfaceImpl(QObject *parent) QAppImageUpdateInterfaceImpl::~QAppImageUpdateInterfaceImpl() { } +void QAppImageUpdateInterfaceImpl::setApplicationName(const QString &a) { + m_Private->setApplicationName(a); +} + void QAppImageUpdateInterfaceImpl::setIcon(QByteArray icon) { m_Private->setIcon(icon); }