From 9580cecd24614a9ce200c73bc4b528480c6e1026 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Tue, 6 Apr 2021 14:14:10 -0500 Subject: [PATCH] Feature: Show target application Icon, Name, and Description in the integration dialog --- src/ui/CMakeLists.txt | 2 +- src/ui/integration_dialog.cpp | 72 ++++++++++---- src/ui/integration_dialog.h | 4 +- src/ui/integration_dialog.ui | 170 +++++++++++++++++++++++++++------- 4 files changed, 191 insertions(+), 57 deletions(-) diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 5f11513f..82286379 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -1,7 +1,7 @@ if(NOT BUILD_LITE) # main AppImageLauncher application add_executable(AppImageLauncher main.cpp resources.qrc first-run.cpp first-run.h first-run.ui integration_dialog.cpp integration_dialog.h integration_dialog.ui) - target_link_libraries(AppImageLauncher shared PkgConfig::glib libappimage shared) + target_link_libraries(AppImageLauncher shared PkgConfig::glib libappimage shared XdgUtils::DesktopEntry) # set binary runtime rpath to make sure the libappimage.so built and installed by this project is going to be used # by the installed binaries (be it the .deb, the AppImage, or whatever) diff --git a/src/ui/integration_dialog.cpp b/src/ui/integration_dialog.cpp index 5df75944..8366fc61 100644 --- a/src/ui/integration_dialog.cpp +++ b/src/ui/integration_dialog.cpp @@ -5,6 +5,10 @@ // library includes #include +#include +#include + + // local headers #include "integration_dialog.h" #include "ui_integration_dialog.h" @@ -16,25 +20,12 @@ IntegrationDialog::IntegrationDialog(QString pathToAppImage, QString integratedA integratedAppImagesDestinationPath(std::move(integratedAppImagesDestinationPath)) { ui->setupUi(this); - setIcon(); - setMessage(); + loadAppImageInfo(); - QObject::connect(ui->pushButtonIntegrateAndRun, &QPushButton::released, this, - &IntegrationDialog::onPushButtonIntegrateAndRunReleased); - QObject::connect(ui->pushButtonRunOnce, &QPushButton::released, this, - &IntegrationDialog::onPushButtonRunOnceReleased); -} - -void IntegrationDialog::setMessage() { - QString message = ui->message->text(); - message = message.arg(pathToAppImage, integratedAppImagesDestinationPath); - ui->message->setText(message); -} - -void IntegrationDialog::setIcon() { - QIcon icon = QIcon(":/AppImageLauncher.svg"); - QPixmap pixmap = icon.pixmap(QSize(64, 64)); - ui->icon->setPixmap(pixmap); + QObject::connect(ui->pushButtonIntegrateAndRun, &QPushButton::released, + this, &IntegrationDialog::onPushButtonIntegrateAndRunReleased); + QObject::connect(ui->pushButtonRunOnce, &QPushButton::released, + this, &IntegrationDialog::onPushButtonRunOnceReleased); } IntegrationDialog::~IntegrationDialog() { @@ -54,3 +45,48 @@ void IntegrationDialog::onPushButtonRunOnceReleased() { IntegrationDialog::ResultingAction IntegrationDialog::getResultAction() const { return resultAction; } + +void IntegrationDialog::loadAppImageInfo() { + try { + appimage::core::AppImage appImage(pathToAppImage.toStdString()); + appimage::utils::ResourcesExtractor extractor(appImage); + + auto desktopEntryPath = extractor.getDesktopEntryPath(); + auto desktopEntryData = extractor.extractText(desktopEntryPath); + + XdgUtils::DesktopEntry::DesktopEntry desktopEntry(desktopEntryData); + auto appName = QString::fromStdString(desktopEntry.get("Desktop Entry/Name", "")); + auto appDescription = QString::fromStdString(desktopEntry.get("Desktop Entry/Comment", "")); + + ui->labelName->setText(appName); + ui->labelDescription->setText(appDescription); + + // to keep the text aligned in the center with the icon + if (appDescription.isEmpty()) { + ui->labelDescription->setVisible(false); + ui->labelName->setAlignment(Qt::AlignVCenter); + } + + // Read icon data from ".DirIcon" + std::vector iconData = extractor.extract(".DirIcon"); + + // Load into a pixmap + QPixmap pixmap; + pixmap.loadFromData(reinterpret_cast(iconData.data()), iconData.size()); + + // Fallback to the AppImageLauncher icon in case of error + if (pixmap.isNull()) + pixmap = QPixmap(":/AppImageLauncher.svg"); + + // scale icon to 64x64 + pixmap = pixmap.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation); + ui->icon->setPixmap(pixmap); + + // Replace Integrated AppImages Destination Path in the message label + QString message = ui->message->text(); + message = message.arg(integratedAppImagesDestinationPath); + ui->message->setText(message); + } catch (appimage::core::AppImageError& error) { + // TODO: Properly handle errors + } +} diff --git a/src/ui/integration_dialog.h b/src/ui/integration_dialog.h index 6ccc6788..7a317ae4 100644 --- a/src/ui/integration_dialog.h +++ b/src/ui/integration_dialog.h @@ -36,9 +36,7 @@ Q_OBJECT QString pathToAppImage; QString integratedAppImagesDestinationPath; - void setIcon(); - - void setMessage(); + void loadAppImageInfo(); }; #endif //APPIMAGELAUNCHER_INTEGRATION_DIALOG_H diff --git a/src/ui/integration_dialog.ui b/src/ui/integration_dialog.ui index d3407a93..933aa066 100644 --- a/src/ui/integration_dialog.ui +++ b/src/ui/integration_dialog.ui @@ -9,7 +9,7 @@ 0 0 - 460 + 380 300 @@ -23,69 +23,169 @@ Desktop Integration - false + true true - + - 0 + 1 0 + + + 1 + 0 + + + + 0 + - Icon + + + + false - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - 12 + 6 + + + 0 - - - - - - 0 - 0 - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + + + + 3 + 0 + + + + + 0 + 0 + + + + + 8 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 16 + + + + TextLabel + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + true + + + + + + + + 0 + 0 + + + + + 10 + false + + + + TextLabel + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + + + + + Qt::Horizontal + + + + + + + + 0 + 2 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">%1 has not been integrated into your system.</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> <br />Integrating it will move the AppImage into a predefined location, and include it in your application launcher.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Integrating this AppImage will cause it to be moved into '<a href="file://%2"><span style=" text-decoration: underline; color:#2980b9;">%2</span></a>', and to be included in your application launcher.</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">To remove or update the AppImage, please use the context menu of the application icon in your task bar or launcher. </p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The directory where the integrated AppImages are stored in is currently set to: %2</p></body></html> - - - true - - - 0 - - - - - - +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">To remove or update the AppImage, please use the context menu of the application icon in your task bar or launcher. </p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 6 + + + true + + + + 0 +