Skip to content

Commit

Permalink
Support reverse-dns filenames for data files
Browse files Browse the repository at this point in the history
Flatpak isolates application files from the host, but some files must be
exported to the host to serve their purpose (ex. desktop entries, icons
mime types, etc...). Filenames must however be prefixed by the app id, in
reverse-dns notation (org.keepassxc.KeePassXC).

If KEEPASSXC_DIST_TYPE=Flatpak is set CMake can now install files with
exportable filenames, without affecting other distribution types.
  • Loading branch information
AsavarTzeth authored and louib committed Mar 30, 2022
1 parent 622f46d commit 7d87f3e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
47 changes: 38 additions & 9 deletions share/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,44 @@ install(FILES ${wordlists_files} DESTINATION ${DATA_INSTALL_DIR}/wordlists)
file(COPY "wordlists" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

if(UNIX AND NOT APPLE AND NOT HAIKU)
install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
FILES_MATCHING PATTERN "keepassx*.png" PATTERN "keepassx*.svg"
PATTERN "status" EXCLUDE PATTERN "actions" EXCLUDE PATTERN "categories" EXCLUDE)
install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
FILES_MATCHING PATTERN "application-x-keepassxc.png" PATTERN "application-x-keepassxc.svg"
PATTERN "status" EXCLUDE PATTERN "actions" EXCLUDE PATTERN "categories" EXCLUDE)
install(FILES linux/org.keepassxc.KeePassXC.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES linux/org.keepassxc.KeePassXC.appdata.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
install(FILES linux/keepassxc.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)
# Flatpak requires all host accessible files to use filenames based upon the app id
if(KEEPASSXC_DIST_FLATPAK)
set(APP_ICON "${ID}")
set(MIME_ICON "${ID}-application-x-keepassxc")
configure_file(linux/keepassxc.xml.in linux/${ID}.xml @ONLY)
install(FILES linux/${ID}.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)

file(GLOB_RECURSE ICON_FILES LIST_DIRECTORIES false
"icons/application/*/keepassxc*.png"
"icons/application/*/*keepassxc*.svg")
foreach(icon_match ${ICON_FILES})
get_filename_component(icon_name ${icon_match} NAME)
get_filename_component(icon_dir ${icon_match} DIRECTORY)
# Prefix all icons with application id: "org.keepassxc.KeePassXC"
string(REGEX REPLACE "^keepassxc(.*)?(\\.png|\\.svg)$" "${ID}\\1\\2" icon_name ${icon_name})
string(REGEX REPLACE "^(application-x-keepassxc\\.svg)$" "${ID}-\\1" icon_name ${icon_name})
#string(REGEX REPLACE "^(${ID})-(.*)$" "\\1.\\2" icon_name ${icon_name})
# Find icon sub dir ex. "scalable/mimetypes/"
file(RELATIVE_PATH icon_subdir ${CMAKE_CURRENT_SOURCE_DIR}/icons/application ${icon_dir})
install(FILES ${icon_match} DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${icon_subdir}
RENAME ${icon_name})
endforeach()
else()
set(APP_ICON "keepassxc")
set(MIME_ICON "application-x-keepassxc")
configure_file(linux/keepassxc.xml.in keepassxc.xml @ONLY)
install(FILES linux/keepassxc.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)

install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
FILES_MATCHING PATTERN "keepassx*.png" PATTERN "keepassx*.svg"
PATTERN "status" EXCLUDE PATTERN "actions" EXCLUDE PATTERN "categories" EXCLUDE)
install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
FILES_MATCHING PATTERN "application-x-keepassxc.svg" PATTERN "status"
EXCLUDE PATTERN "actions" EXCLUDE PATTERN "categories" EXCLUDE)
endif(KEEPASSXC_DIST_FLATPAK)
configure_file(linux/${ID}.desktop.in linux/${ID}.desktop @ONLY)
install(FILES linux/${ID}.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES linux/${ID}.appdata.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
endif(UNIX AND NOT APPLE AND NOT HAIKU)

if(APPLE)
Expand Down
3 changes: 3 additions & 0 deletions share/linux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
keepassxc.xml
org.keepassxc.KeePassXC.xml
org.keepassxc.KeePassXC.desktop
2 changes: 1 addition & 1 deletion share/linux/keepassxc.xml → share/linux/keepassxc.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<mime-type type="application/x-keepass2">
<comment>KeePass 2 Database</comment>
<glob pattern="*.kdbx"/>
<icon name="application-x-keepassxc"/>
<icon name="@MIME_ICON@"/>
</mime-type>
</mime-info>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Comment[et]=Kogukonna arendatav port Windowsi programmist KeePass Password Safe
Comment[ru]=Разработанный сообществом порт Windows-приложения KeePass Password Safe
Exec=keepassxc %f
TryExec=keepassxc
Icon=keepassxc
Icon=@APP_ICON@
StartupWMClass=keepassxc
StartupNotify=true
Terminal=false
Expand Down
15 changes: 12 additions & 3 deletions src/gui/Icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ Icons::Icons()
{
}

QString Icons::applicationIconName()
{
#ifdef KEEPASSXC_DIST_FLATPAK
return QString("org.keepassxc.KeePassXC");
#else
return QString("keepassxc");
#endif
}

QIcon Icons::applicationIcon()
{
return icon("keepassxc", false);
return icon(applicationIconName(), false);
}

QString Icons::trayIconAppearance() const
Expand All @@ -81,7 +90,7 @@ QIcon Icons::trayIcon(QString style)

auto iconApperance = trayIconAppearance();
if (!iconApperance.startsWith("monochrome")) {
return icon(QString("keepassxc%1").arg(style), false);
return icon(QString("%1%2").arg(applicationIconName(), style), false);
}

QIcon i;
Expand All @@ -92,7 +101,7 @@ QIcon Icons::trayIcon(QString style)
i = icon(QString("keepassxc-monochrome-dark%1").arg(style), false);
}
#else
i = icon(QString("keepassxc-%1%2").arg(iconApperance, style), false);
i = icon(QString("%1-%2%3").arg(applicationIconName(), iconApperance, style), false);
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
// Set as mask to allow the operating system to recolour the tray icon. This may look weird
Expand Down
1 change: 1 addition & 0 deletions src/gui/Icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
class Icons
{
public:
QString applicationIconName();
QIcon applicationIcon();
QIcon trayIcon(QString style = "unlocked");
QIcon trayIconLocked();
Expand Down

0 comments on commit 7d87f3e

Please sign in to comment.