Skip to content

Commit

Permalink
Add icons for emv-viewer
Browse files Browse the repository at this point in the history
* Adapt prepare_icons.sh script to generate icons for emv-viewer
* Add window icon using .qrc resource file and setWindowIcon() function
  for Linux and Windows
* Add MacOS bundle icon using MACOSX_BUNDLE_ICON_FILE property and add
  it as a bundle resource
* Add Windows application executable icon using .rc resource file
* Add NSIS installer icons using CPACK_PACKAGE_ICON, CPACK_NSIS_MUI_ICON
  and CPACK_NSIS_MUI_UNIICON variables
* Add icon file, desktop entry file and appstream file for Linux
  desktop environments

NOTE: This is mostly based on the OpenEMV dukpt project.
  • Loading branch information
leonlynch committed Sep 11, 2024
1 parent dd5e687 commit 9745fe0
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ if(WIN32 AND TARGET emv-viewer)
set(CPACK_COMPONENTS_ALL emv_runtime emv_viewer_runtime emv_development)
# Use emv-viewer license file
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/viewer/LICENSE.gpl")
# Set installer branding icon
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/viewer/icons\\openemv_emv_utils.bmp") # CMake's own installer uses a backslash for the last slash due to a bug in NSIS
# Set installer and uninstaller application icons
set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/viewer/icons\\openemv_emv_utils.ico") # CMake's own installer uses a backslash for the last slash due to a bug in NSIS
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/viewer/icons\\openemv_emv_utils.ico") # CMake's own installer uses a backslash for the last slash due to a bug in NSIS
# Set display name used by Control Panel
set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_VENDOR} ${CMAKE_PROJECT_NAME} ${CPACK_PACKAGE_VERSION}")
# Set name used by installer application
Expand Down
45 changes: 45 additions & 0 deletions scripts/prepare_icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Let script show exact commands
set -x

# NOTE: this script depends on Imagemagick. Given that Imagemagick may
# delegate processing of SVGs to various different backends that may have
# different behaviour regarding the alpha channel, it's best to use a PNG icon
# with the correct alpha channel as the input icon.
#
# NOTE: this script also depends on png2icns (see
# https://sourceforge.net/projects/icns/)

function help {
printf "Usage: %s [icons-dir] [input-icon]\n" "$(basename "$0")"
exit 1
}

if [ $# -ne 2 ]; then
help
fi

icons_dir="$1"
input_icon="$2"

if [ ! -f "${input_icon}" ]; then
printf "${input_icon} does not exist!\n"
exit 1
fi

# Trim and center the input icon before creating the various resized outputs
# NOTE: 57px offset ensures that the card image is in the center
magick "${input_icon}" -trim -resize 1024x1024 -background none -gravity center -extent 1024x1024+0-57 "${icons_dir}/openemv_emv_utils_1024x1024.png"

# Output various icon sizes for use in the menu, app window, taskbar and installer
magick "${icons_dir}/openemv_emv_utils_1024x1024.png" -resize 512x512 -background none -gravity center -extent 512x512 "${icons_dir}/openemv_emv_utils_512x512.png"
magick "${icons_dir}/openemv_emv_utils_1024x1024.png" -resize 256x256 -background none -gravity center -extent 256x256 "${icons_dir}/openemv_emv_utils_256x256.png"
magick convert "${icons_dir}/openemv_emv_utils_256x256.png" "${icons_dir}/openemv_emv_utils.ico"

# Output icon for MacOS
png2icns "${icons_dir}/openemv_emv_utils.icns" "${icons_dir}/openemv_emv_utils_1024x1024.png"

# Trim and relocate the input icon for Windows NSIS installer (150x57 geometry)
magick "${input_icon}" -trim -resize 150x53 -background white -gravity center -extent 150x53 - | magick - -resize 150x57 -background white -gravity south -extent 150x57 "${icons_dir}/openemv_emv_utils_150x57.png"
magick convert "${icons_dir}/openemv_emv_utils_150x57.png" "BMP3:${icons_dir}/openemv_emv_utils.bmp"
37 changes: 37 additions & 0 deletions viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ if(QT_VERSION VERSION_LESS 5.15)
# Qt-5.12 provides these versioned commands
qt5_wrap_ui(UI_SRCS emv-viewer-mainwindow.ui)
qt5_wrap_cpp(MOC_SRCS ${EMV_VIEWER_MOC_HEADERS})
qt5_add_resources(QRC_SRCS icons.qrc)
add_library(Qt::Widgets ALIAS Qt5::Widgets)
else()
# Qt-5.15 and Qt-6 provide these version-less commands
qt_wrap_ui(UI_SRCS emv-viewer-mainwindow.ui)
qt_wrap_cpp(MOC_SRCS ${EMV_VIEWER_MOC_HEADERS})
qt_add_resources(QRC_SRCS icons.qrc)
endif()

add_executable(emv-viewer
Expand Down Expand Up @@ -129,9 +131,14 @@ if(APPLE AND BUILD_MACOSX_BUNDLE)
MACOSX_BUNDLE_SHORT_VERSION_STRING ${CMAKE_PROJECT_VERSION}
MACOSX_BUNDLE_COPYRIGHT "Copyright 2021-2024 Leon Lynch"
MACOSX_BUNDLE_GUI_IDENTIFIER org.openemv.${CMAKE_PROJECT_NAME}
MACOSX_BUNDLE_ICON_FILE "openemv_emv_utils.icns"
RESOURCE icons/openemv_emv_utils.icns
OUTPUT_NAME "EMV Viewer"
)

# Add application icon for MacOS
target_sources(emv-viewer PRIVATE icons/openemv_emv_utils.icns)

# Install emv-viewer symlink into bundle for MacOS
install(CODE
"execute_process(COMMAND \"${CMAKE_COMMAND}\" -E make_directory \"$<TARGET_BUNDLE_CONTENT_DIR:emv-viewer>/bin/\")"
Expand Down Expand Up @@ -185,6 +192,9 @@ if(WIN32)
WIN32_EXECUTABLE TRUE
)

# Add application icon for Windows
target_sources(emv-viewer PRIVATE icon.rc)

# Deploy Qt for Windows
include(DeployQt)
windeployqt(emv-viewer emv_viewer_runtime)
Expand All @@ -204,6 +214,33 @@ install(FILES
COMPONENT emv_viewer_runtime
)

if(NOT APPLE AND NOT WIN32)
# Install icon file to UI runtime component for Linux
set(EMV_UTILS_INSTALL_ICONSDIR ${CMAKE_INSTALL_DATADIR}/icons/hicolor/512x512/apps CACHE STRING "Installation location for emv-viewer icon files")
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/icons/openemv_emv_utils_512x512.png
DESTINATION ${EMV_UTILS_INSTALL_ICONSDIR}
COMPONENT emv_viewer_runtime
RENAME emv-viewer.png
)

# Install desktop entry file to UI runtime component for Linux
set(EMV_UTILS_INSTALL_DESKTOPENTRYDIR ${CMAKE_INSTALL_DATADIR}/applications CACHE STRING "Installation location for emv-viewer desktop entry files")
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/emv-viewer.desktop
DESTINATION ${EMV_UTILS_INSTALL_DESKTOPENTRYDIR}
COMPONENT emv_viewer_runtime
)

# Install appstream file to UI runtime component for Linux
set(EMV_UTILS_INSTALL_APPSTREAMDIR ${CMAKE_INSTALL_DATADIR}/metainfo CACHE STRING "Installation location for emv-viewer appstream files")
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/emv-viewer.appdata.xml
DESTINATION ${EMV_UTILS_INSTALL_APPSTREAMDIR}
COMPONENT emv_viewer_runtime
)
endif()

install(
TARGETS
emv-viewer
Expand Down
1 change: 1 addition & 0 deletions viewer/emv-viewer-mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ EmvViewerMainWindow::EmvViewerMainWindow(

// Setup UI widgets
setupUi(this);
setWindowIcon(QIcon(":icons/openemv_emv_utils_512x512.png"));
setWindowTitle(windowTitle().append(QStringLiteral(" (") + qApp->applicationVersion() + QStringLiteral(")")));

// Note that EmvHighlighter assumes that all blocks are processed in order
Expand Down
26 changes: 26 additions & 0 deletions viewer/emv-viewer.appdata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<component type="desktop">
<id>org.openemv.emv-viewer</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0</project_license>
<name>EMV Viewer</name>
<summary>Decoder and viewer for EMV card data</summary>
<description>
<p>
EMV Viewer is a graphical user interface to decode and view EMV card data, including:
</p>
<ul>
<li>Decoding of ISO 3166 country codes</li>
<li>Decoding of ISO 4217 currency codes</li>
<li>Decoding of ISO 8859 strings</li>
<li>Decoding of ISO 18245 Merchant Category Codes (MCC)</li>
</ul>
</description>
<launchable type="desktop-id">emv-viewer.desktop</launchable>
<url type="homepage">https://github.com/openemv/emv-utils</url>
<url type="bugtracker">https://github.com/openemv/emv-utils/issues</url>
<provides>
<id>emv-viewer.desktop</id>
<binary>emv-viewer</binary>
</provides>
</component>
1 change: 1 addition & 0 deletions viewer/emv-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char** argv)
app.setOrganizationDomain("openemv.org");
app.setApplicationName("emv-viewer");
app.setApplicationVersion(EMV_VIEWER_VERSION_STRING);
app.setWindowIcon(QIcon(":icons/openemv_emv_utils_512x512.png"));

QCommandLineParser parser;
parser.addHelpOption();
Expand Down
8 changes: 8 additions & 0 deletions viewer/emv-viewer.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=EMV Viewer
Comment=Decoder and viewer for EMV card data
Exec=emv-viewer
Icon=emv-viewer
Categories=Development;Qt
Terminal=false
1 change: 1 addition & 0 deletions viewer/icon.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "icons/openemv_emv_utils.ico"
7 changes: 7 additions & 0 deletions viewer/icons.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>icons/openemv_emv_utils_512x512.png</file>
<file>icons/openemv_emv_utils_256x256.png</file>
</qresource>
</RCC>
Binary file added viewer/icons/openemv_emv_utils.bmp
Binary file not shown.
Binary file added viewer/icons/openemv_emv_utils.icns
Binary file not shown.
Binary file added viewer/icons/openemv_emv_utils.ico
Binary file not shown.
Binary file added viewer/icons/openemv_emv_utils_1024x1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added viewer/icons/openemv_emv_utils_150x57.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added viewer/icons/openemv_emv_utils_256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added viewer/icons/openemv_emv_utils_512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9745fe0

Please sign in to comment.