From 12eaecb7cac54a170a8cbb8570fcf8b4e145c04b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 8 May 2018 11:22:32 +0200 Subject: Install icons as qrc file as use them from there. The plan is that this will help on windows with symlinks not working. --- applications/kube/main.cpp | 18 +++---- icons/CMakeLists.txt | 7 +-- icons/breeze/CMakeLists.txt | 53 ++++++++++++++++++++ icons/breeze/qrcAlias.cpp | 119 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+), 16 deletions(-) create mode 100644 icons/breeze/CMakeLists.txt create mode 100644 icons/breeze/qrcAlias.cpp diff --git a/applications/kube/main.cpp b/applications/kube/main.cpp index aafbeef8..efe31ea2 100644 --- a/applications/kube/main.cpp +++ b/applications/kube/main.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include "framework/src/keyring.h" @@ -168,17 +169,14 @@ int main(int argc, char *argv[]) app.setApplicationVersion(kube_VERSION_STRING); app.setFont(QFont{"Noto Sans", app.font().pointSize(), QFont::Normal}); - //On Mac OS we want to include Contents/Resources/icons in the bundle, and that path is in AppDataLocations. - QStringList iconSearchPaths; - for (const auto &p : QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)) { - auto iconPath = p + "/icons/"; - //I'm getting broken paths reported from standardLocations - if (iconPath.contains("kube.appContents")) { - iconPath.replace("kube.appContents", "kube.app/Contents"); - } - iconSearchPaths << iconPath; + const QString kubeIcons = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kube-icons.rcc")); + if (!QResource::registerResource(kubeIcons, "/icons/kube")) { + qWarning() << "Failed to register icon resource!" << kubeIcons; + Q_ASSERT(false); + } else { + QIcon::setThemeSearchPaths(QStringList() << QStringLiteral(":/icons")); + QIcon::setThemeName(QStringLiteral("kube")); } - QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() + iconSearchPaths); QCommandLineParser parser; parser.setApplicationDescription("A communication and collaboration client."); diff --git a/icons/CMakeLists.txt b/icons/CMakeLists.txt index a5c39b86..5fa36fbf 100644 --- a/icons/CMakeLists.txt +++ b/icons/CMakeLists.txt @@ -7,9 +7,4 @@ ecm_install_icons(ICONS sc-apps-kube_symbol.svg DESTINATION share/icons) ecm_install_icons(ICONS sc-apps-kube_logo.svg DESTINATION share/icons) #See the copybreeze script to adjust icons and to copy them over -install(DIRECTORY - breeze/icons/places - breeze/icons/actions - breeze/icons/mimetypes - DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/kube) -install(FILES breeze/icons/index.theme DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/kube) +add_subdirectory(breeze) diff --git a/icons/breeze/CMakeLists.txt b/icons/breeze/CMakeLists.txt new file mode 100644 index 00000000..4fac9316 --- /dev/null +++ b/icons/breeze/CMakeLists.txt @@ -0,0 +1,53 @@ +include(KDEInstallDirs) + +set(BINARY_ICONS_RESOURCE TRUE) +if(BINARY_ICONS_RESOURCE) + find_package(Qt5 NO_MODULE REQUIRED Core) + add_executable(qrcAlias qrcAlias.cpp) + target_link_libraries(qrcAlias PUBLIC Qt5::Core) + + function(generate_binary_resource target outfile) + set(RESOURCES_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}/res) + set(RESOURCE_FILE ${RESOURCES_WORKING_DIR}/kube-${target}.qrc) + set(BINARY_RESOURCE_FILE ${CMAKE_CURRENT_BINARY_DIR}/kube-${target}.rcc) + + get_target_property(QT_RCC_EXECUTABLE Qt5::rcc LOCATION) + + file(REMOVE_RECURSE ${RESOURCES_WORKING_DIR}) + file(MAKE_DIRECTORY ${RESOURCES_WORKING_DIR}) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${target}/ DESTINATION ${RESOURCES_WORKING_DIR}) + file(REMOVE + ${RESOURCE_FILE} + ${RESOURCE_FILE}.depends + ${RESOURCES_WORKING_DIR}/.gitignore + ${RESOURCES_WORKING_DIR}/CMakeLists.txt + ) + + add_custom_command(OUTPUT ${RESOURCE_FILE} + COMMAND ${QT_RCC_EXECUTABLE} --project -o ${CMAKE_CURRENT_BINARY_DIR}/tmp.qrc + COMMAND $ -i ${CMAKE_CURRENT_BINARY_DIR}/tmp.qrc -o ${RESOURCE_FILE} + WORKING_DIRECTORY ${RESOURCES_WORKING_DIR} + ) + add_custom_command(OUTPUT ${BINARY_RESOURCE_FILE} + COMMAND ${QT_RCC_EXECUTABLE} --binary + -o ${BINARY_RESOURCE_FILE} + ${RESOURCE_FILE} + DEPENDS ${RESOURCE_FILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + add_custom_target(kube-${target}-rcc ALL DEPENDS ${BINARY_RESOURCE_FILE}) + + set(${outfile} ${BINARY_RESOURCE_FILE} PARENT_SCOPE) + endfunction() + + generate_binary_resource(icons binary_resource) + install(FILES ${binary_resource} DESTINATION ${KDE_INSTALL_DATADIR}/kube) +else() + install(DIRECTORY + icons/places + icons/actions + icons/mimetypes + DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/kube) + install(FILES icons/index.theme DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/kube) +endif() diff --git a/icons/breeze/qrcAlias.cpp b/icons/breeze/qrcAlias.cpp new file mode 100644 index 00000000..409ba61f --- /dev/null +++ b/icons/breeze/qrcAlias.cpp @@ -0,0 +1,119 @@ +/* This file is part of the KDE libraries + * Copyright (C) 2016 Kåre Särs + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include + +QString link(const QString &path, const QString &fileName) +{ + QFile in(path + QLatin1Char('/') + fileName); + if (!in.open(QIODevice::ReadOnly)) { + qDebug() << "failed to read" << path << fileName << in.fileName(); + return QString(); + } + + QString firstLine = in.readLine(); + if (firstLine.isEmpty()) { + qDebug() << in.fileName() << "line could not be read..."; + return QString(); + } + QRegularExpression fNameReg(QStringLiteral("(.*\\.(?:svg|png|gif|ico))")); + QRegularExpressionMatch match = fNameReg.match(firstLine); + if (!match.hasMatch()) { + return QString(); + } + + QFileInfo linkInfo(path + QLatin1Char('/') + match.captured(1)); + QString aliasLink = link(linkInfo.path(), linkInfo.fileName()); + if (!aliasLink.isEmpty()) { + //qDebug() << fileName << "=" << match.captured(1) << "=" << aliasLink; + return aliasLink; + } + + return path + QLatin1Char('/') + match.captured(1); +} + +int parseFile(const QString &infile, const QString &outfile) +{ + QFile in(infile); + QFile out(outfile); + QRegularExpression imageReg(QStringLiteral("(.*\\.(?:svg|png|gif|ico))")); + + if (!in.open(QIODevice::ReadOnly)) { + qDebug() << "Failed to open" << infile; + return -1; + } + if (!out.open(QIODevice::WriteOnly)) { + qDebug() << "Failed to create" << outfile; + return -2; + } + + while (in.bytesAvailable()) { + QString line = QString::fromLocal8Bit(in.readLine()); + QRegularExpressionMatch match = imageReg.match(line); + if (!match.hasMatch()) { + //qDebug() << "No Match: " << line; + out.write(qPrintable(line)); + continue; + } + + QFileInfo info(match.captured(1)); + + QString aliasLink = link(info.path(), info.fileName()); + if (aliasLink.isEmpty()) { + //qDebug() << "No alias: " << line; + out.write(qPrintable(line)); + continue; + } + + QString newLine = QStringLiteral("%2\n").arg(match.captured(1), aliasLink); + //qDebug() << newLine; + out.write(qPrintable(newLine)); + } + return 0; +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QCommandLineParser parser; + + QCommandLineOption inOption(QStringList() << QLatin1String("i") << QLatin1String("infile"), QStringLiteral("Input qrc file"), QStringLiteral("infile")); + QCommandLineOption outOption(QStringList() << QLatin1String("o") << QLatin1String("outfile"), QStringLiteral("Output qrc file"), QStringLiteral("outfile")); + parser.setApplicationDescription( + QLatin1String("On Windows git handles symbolic links by converting them " + "to text files containing the links to the actual file. This application " + "takes a .qrc file as input and outputs a .qrc file with the symbolic " + "links converted to qrc-aliases.")); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addOption(inOption); + parser.addOption(outOption); + parser.process(app); + + const QString inName = parser.value(inOption); + const QString outName = parser.value(outOption); + + return parseFile(inName, outName); +} -- cgit v1.2.3