Skip to content

Commit 9580cec

Browse files
committed
Feature: Show target application Icon, Name, and Description in the integration dialog
1 parent 52d7ace commit 9580cec

File tree

4 files changed

+191
-57
lines changed

4 files changed

+191
-57
lines changed

src/ui/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
if(NOT BUILD_LITE)
22
# main AppImageLauncher application
33
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)
4-
target_link_libraries(AppImageLauncher shared PkgConfig::glib libappimage shared)
4+
target_link_libraries(AppImageLauncher shared PkgConfig::glib libappimage shared XdgUtils::DesktopEntry)
55

66
# set binary runtime rpath to make sure the libappimage.so built and installed by this project is going to be used
77
# by the installed binaries (be it the .deb, the AppImage, or whatever)

src/ui/integration_dialog.cpp

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// library includes
66
#include <QStyle>
77

8+
#include <XdgUtils/DesktopEntry/DesktopEntry.h>
9+
#include <appimage/utils/ResourcesExtractor.h>
10+
11+
812
// local headers
913
#include "integration_dialog.h"
1014
#include "ui_integration_dialog.h"
@@ -16,25 +20,12 @@ IntegrationDialog::IntegrationDialog(QString pathToAppImage, QString integratedA
1620
integratedAppImagesDestinationPath(std::move(integratedAppImagesDestinationPath)) {
1721
ui->setupUi(this);
1822

19-
setIcon();
20-
setMessage();
23+
loadAppImageInfo();
2124

22-
QObject::connect(ui->pushButtonIntegrateAndRun, &QPushButton::released, this,
23-
&IntegrationDialog::onPushButtonIntegrateAndRunReleased);
24-
QObject::connect(ui->pushButtonRunOnce, &QPushButton::released, this,
25-
&IntegrationDialog::onPushButtonRunOnceReleased);
26-
}
27-
28-
void IntegrationDialog::setMessage() {
29-
QString message = ui->message->text();
30-
message = message.arg(pathToAppImage, integratedAppImagesDestinationPath);
31-
ui->message->setText(message);
32-
}
33-
34-
void IntegrationDialog::setIcon() {
35-
QIcon icon = QIcon(":/AppImageLauncher.svg");
36-
QPixmap pixmap = icon.pixmap(QSize(64, 64));
37-
ui->icon->setPixmap(pixmap);
25+
QObject::connect(ui->pushButtonIntegrateAndRun, &QPushButton::released,
26+
this, &IntegrationDialog::onPushButtonIntegrateAndRunReleased);
27+
QObject::connect(ui->pushButtonRunOnce, &QPushButton::released,
28+
this, &IntegrationDialog::onPushButtonRunOnceReleased);
3829
}
3930

4031
IntegrationDialog::~IntegrationDialog() {
@@ -54,3 +45,48 @@ void IntegrationDialog::onPushButtonRunOnceReleased() {
5445
IntegrationDialog::ResultingAction IntegrationDialog::getResultAction() const {
5546
return resultAction;
5647
}
48+
49+
void IntegrationDialog::loadAppImageInfo() {
50+
try {
51+
appimage::core::AppImage appImage(pathToAppImage.toStdString());
52+
appimage::utils::ResourcesExtractor extractor(appImage);
53+
54+
auto desktopEntryPath = extractor.getDesktopEntryPath();
55+
auto desktopEntryData = extractor.extractText(desktopEntryPath);
56+
57+
XdgUtils::DesktopEntry::DesktopEntry desktopEntry(desktopEntryData);
58+
auto appName = QString::fromStdString(desktopEntry.get("Desktop Entry/Name", ""));
59+
auto appDescription = QString::fromStdString(desktopEntry.get("Desktop Entry/Comment", ""));
60+
61+
ui->labelName->setText(appName);
62+
ui->labelDescription->setText(appDescription);
63+
64+
// to keep the text aligned in the center with the icon
65+
if (appDescription.isEmpty()) {
66+
ui->labelDescription->setVisible(false);
67+
ui->labelName->setAlignment(Qt::AlignVCenter);
68+
}
69+
70+
// Read icon data from ".DirIcon"
71+
std::vector<char> iconData = extractor.extract(".DirIcon");
72+
73+
// Load into a pixmap
74+
QPixmap pixmap;
75+
pixmap.loadFromData(reinterpret_cast<const uchar*>(iconData.data()), iconData.size());
76+
77+
// Fallback to the AppImageLauncher icon in case of error
78+
if (pixmap.isNull())
79+
pixmap = QPixmap(":/AppImageLauncher.svg");
80+
81+
// scale icon to 64x64
82+
pixmap = pixmap.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation);
83+
ui->icon->setPixmap(pixmap);
84+
85+
// Replace Integrated AppImages Destination Path in the message label
86+
QString message = ui->message->text();
87+
message = message.arg(integratedAppImagesDestinationPath);
88+
ui->message->setText(message);
89+
} catch (appimage::core::AppImageError& error) {
90+
// TODO: Properly handle errors
91+
}
92+
}

src/ui/integration_dialog.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ Q_OBJECT
3636
QString pathToAppImage;
3737
QString integratedAppImagesDestinationPath;
3838

39-
void setIcon();
40-
41-
void setMessage();
39+
void loadAppImageInfo();
4240
};
4341

4442
#endif //APPIMAGELAUNCHER_INTEGRATION_DIALOG_H

src/ui/integration_dialog.ui

Lines changed: 135 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<rect>
1010
<x>0</x>
1111
<y>0</y>
12-
<width>460</width>
12+
<width>380</width>
1313
<height>300</height>
1414
</rect>
1515
</property>
@@ -23,69 +23,169 @@
2323
<string>Desktop Integration</string>
2424
</property>
2525
<property name="sizeGripEnabled">
26-
<bool>false</bool>
26+
<bool>true</bool>
2727
</property>
2828
<property name="modal">
2929
<bool>true</bool>
3030
</property>
31-
<layout class="QVBoxLayout" name="verticalLayout">
31+
<layout class="QVBoxLayout" name="verticalLayout_3">
3232
<item>
3333
<layout class="QHBoxLayout" name="horizontalLayout_2">
3434
<item>
3535
<widget class="QLabel" name="icon">
3636
<property name="sizePolicy">
3737
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
38-
<horstretch>0</horstretch>
38+
<horstretch>1</horstretch>
3939
<verstretch>0</verstretch>
4040
</sizepolicy>
4141
</property>
42+
<property name="sizeIncrement">
43+
<size>
44+
<width>1</width>
45+
<height>0</height>
46+
</size>
47+
</property>
48+
<property name="lineWidth">
49+
<number>0</number>
50+
</property>
4251
<property name="text">
43-
<string>Icon</string>
52+
<string/>
53+
</property>
54+
<property name="scaledContents">
55+
<bool>false</bool>
4456
</property>
4557
<property name="alignment">
46-
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
58+
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
4759
</property>
4860
<property name="margin">
49-
<number>12</number>
61+
<number>6</number>
62+
</property>
63+
<property name="indent">
64+
<number>0</number>
5065
</property>
5166
</widget>
5267
</item>
5368
<item>
54-
<layout class="QVBoxLayout" name="verticalLayout_2">
55-
<item>
56-
<widget class="QLabel" name="message">
57-
<property name="sizePolicy">
58-
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
59-
<horstretch>0</horstretch>
60-
<verstretch>0</verstretch>
61-
</sizepolicy>
62-
</property>
63-
<property name="text">
64-
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
69+
<widget class="QWidget" name="widget" native="true">
70+
<property name="sizePolicy">
71+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
72+
<horstretch>3</horstretch>
73+
<verstretch>0</verstretch>
74+
</sizepolicy>
75+
</property>
76+
<property name="sizeIncrement">
77+
<size>
78+
<width>0</width>
79+
<height>0</height>
80+
</size>
81+
</property>
82+
<layout class="QVBoxLayout" name="verticalLayout_2">
83+
<property name="spacing">
84+
<number>8</number>
85+
</property>
86+
<property name="leftMargin">
87+
<number>0</number>
88+
</property>
89+
<property name="bottomMargin">
90+
<number>0</number>
91+
</property>
92+
<item>
93+
<widget class="QLabel" name="labelName">
94+
<property name="sizePolicy">
95+
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
96+
<horstretch>0</horstretch>
97+
<verstretch>0</verstretch>
98+
</sizepolicy>
99+
</property>
100+
<property name="font">
101+
<font>
102+
<pointsize>16</pointsize>
103+
</font>
104+
</property>
105+
<property name="text">
106+
<string notr="true">TextLabel</string>
107+
</property>
108+
<property name="alignment">
109+
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
110+
</property>
111+
<property name="wordWrap">
112+
<bool>true</bool>
113+
</property>
114+
</widget>
115+
</item>
116+
<item>
117+
<widget class="QLabel" name="labelDescription">
118+
<property name="sizePolicy">
119+
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
120+
<horstretch>0</horstretch>
121+
<verstretch>0</verstretch>
122+
</sizepolicy>
123+
</property>
124+
<property name="font">
125+
<font>
126+
<pointsize>10</pointsize>
127+
<italic>false</italic>
128+
</font>
129+
</property>
130+
<property name="text">
131+
<string>TextLabel</string>
132+
</property>
133+
<property name="alignment">
134+
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
135+
</property>
136+
<property name="wordWrap">
137+
<bool>true</bool>
138+
</property>
139+
</widget>
140+
</item>
141+
</layout>
142+
</widget>
143+
</item>
144+
</layout>
145+
</item>
146+
<item>
147+
<widget class="Line" name="line">
148+
<property name="orientation">
149+
<enum>Qt::Horizontal</enum>
150+
</property>
151+
</widget>
152+
</item>
153+
<item>
154+
<widget class="QLabel" name="message">
155+
<property name="sizePolicy">
156+
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
157+
<horstretch>0</horstretch>
158+
<verstretch>2</verstretch>
159+
</sizepolicy>
160+
</property>
161+
<property name="text">
162+
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
65163
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
66164
p, li { white-space: pre-wrap; }
67165
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
68-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%1 has not been integrated into your system.&lt;/p&gt;
69-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt; &lt;br /&gt;Integrating it will move the AppImage into a predefined location, and include it in your application launcher.&lt;/p&gt;
166+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Integrating this AppImage will cause it to be moved into '&lt;a href=&quot;file://%2&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;%2&lt;/span&gt;&lt;/a&gt;', and to be included in your application launcher.&lt;/p&gt;
70167
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
71-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;To remove or update the AppImage, please use the context menu of the application icon in your task bar or launcher. &lt;/p&gt;
72-
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
73-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;The directory where the integrated AppImages are stored in is currently set to: %2&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
74-
</property>
75-
<property name="wordWrap">
76-
<bool>true</bool>
77-
</property>
78-
<property name="margin">
79-
<number>0</number>
80-
</property>
81-
</widget>
82-
</item>
83-
</layout>
84-
</item>
85-
</layout>
168+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;To remove or update the AppImage, please use the context menu of the application icon in your task bar or launcher. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
169+
</property>
170+
<property name="alignment">
171+
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
172+
</property>
173+
<property name="wordWrap">
174+
<bool>true</bool>
175+
</property>
176+
<property name="margin">
177+
<number>6</number>
178+
</property>
179+
<property name="openExternalLinks">
180+
<bool>true</bool>
181+
</property>
182+
</widget>
86183
</item>
87184
<item>
88185
<layout class="QHBoxLayout" name="horizontalLayout">
186+
<property name="bottomMargin">
187+
<number>0</number>
188+
</property>
89189
<item>
90190
<spacer name="horizontalSpacer">
91191
<property name="orientation">

0 commit comments

Comments
 (0)