diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-05-08 11:22:32 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-05-08 18:36:29 +0200 |
commit | 12eaecb7cac54a170a8cbb8570fcf8b4e145c04b (patch) | |
tree | 2954910a02be3e50c823ddade1b2077126fb9890 | |
parent | 81c05eee49fbb2ddc58025ac4b8834bdc59e41e7 (diff) | |
download | kube-12eaecb7cac54a170a8cbb8570fcf8b4e145c04b.tar.gz kube-12eaecb7cac54a170a8cbb8570fcf8b4e145c04b.zip |
Install icons as qrc file as use them from there.
The plan is that this will help on windows with symlinks not working.
-rw-r--r-- | applications/kube/main.cpp | 18 | ||||
-rw-r--r-- | icons/CMakeLists.txt | 7 | ||||
-rw-r--r-- | icons/breeze/CMakeLists.txt | 53 | ||||
-rw-r--r-- | icons/breeze/qrcAlias.cpp | 119 |
4 files changed, 181 insertions, 16 deletions
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 @@ | |||
48 | #include <QQmlContext> | 48 | #include <QQmlContext> |
49 | #include <QIcon> | 49 | #include <QIcon> |
50 | #include <QStandardPaths> | 50 | #include <QStandardPaths> |
51 | #include <QResource> | ||
51 | #include <sink/store.h> | 52 | #include <sink/store.h> |
52 | 53 | ||
53 | #include "framework/src/keyring.h" | 54 | #include "framework/src/keyring.h" |
@@ -168,17 +169,14 @@ int main(int argc, char *argv[]) | |||
168 | app.setApplicationVersion(kube_VERSION_STRING); | 169 | app.setApplicationVersion(kube_VERSION_STRING); |
169 | app.setFont(QFont{"Noto Sans", app.font().pointSize(), QFont::Normal}); | 170 | app.setFont(QFont{"Noto Sans", app.font().pointSize(), QFont::Normal}); |
170 | 171 | ||
171 | //On Mac OS we want to include Contents/Resources/icons in the bundle, and that path is in AppDataLocations. | 172 | const QString kubeIcons = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kube-icons.rcc")); |
172 | QStringList iconSearchPaths; | 173 | if (!QResource::registerResource(kubeIcons, "/icons/kube")) { |
173 | for (const auto &p : QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)) { | 174 | qWarning() << "Failed to register icon resource!" << kubeIcons; |
174 | auto iconPath = p + "/icons/"; | 175 | Q_ASSERT(false); |
175 | //I'm getting broken paths reported from standardLocations | 176 | } else { |
176 | if (iconPath.contains("kube.appContents")) { | 177 | QIcon::setThemeSearchPaths(QStringList() << QStringLiteral(":/icons")); |
177 | iconPath.replace("kube.appContents", "kube.app/Contents"); | 178 | QIcon::setThemeName(QStringLiteral("kube")); |
178 | } | ||
179 | iconSearchPaths << iconPath; | ||
180 | } | 179 | } |
181 | QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() + iconSearchPaths); | ||
182 | 180 | ||
183 | QCommandLineParser parser; | 181 | QCommandLineParser parser; |
184 | parser.setApplicationDescription("A communication and collaboration client."); | 182 | 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) | |||
7 | ecm_install_icons(ICONS sc-apps-kube_logo.svg DESTINATION share/icons) | 7 | ecm_install_icons(ICONS sc-apps-kube_logo.svg DESTINATION share/icons) |
8 | 8 | ||
9 | #See the copybreeze script to adjust icons and to copy them over | 9 | #See the copybreeze script to adjust icons and to copy them over |
10 | install(DIRECTORY | 10 | add_subdirectory(breeze) |
11 | breeze/icons/places | ||
12 | breeze/icons/actions | ||
13 | breeze/icons/mimetypes | ||
14 | DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/kube) | ||
15 | install(FILES breeze/icons/index.theme DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/kube) | ||
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 @@ | |||
1 | include(KDEInstallDirs) | ||
2 | |||
3 | set(BINARY_ICONS_RESOURCE TRUE) | ||
4 | if(BINARY_ICONS_RESOURCE) | ||
5 | find_package(Qt5 NO_MODULE REQUIRED Core) | ||
6 | add_executable(qrcAlias qrcAlias.cpp) | ||
7 | target_link_libraries(qrcAlias PUBLIC Qt5::Core) | ||
8 | |||
9 | function(generate_binary_resource target outfile) | ||
10 | set(RESOURCES_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}/res) | ||
11 | set(RESOURCE_FILE ${RESOURCES_WORKING_DIR}/kube-${target}.qrc) | ||
12 | set(BINARY_RESOURCE_FILE ${CMAKE_CURRENT_BINARY_DIR}/kube-${target}.rcc) | ||
13 | |||
14 | get_target_property(QT_RCC_EXECUTABLE Qt5::rcc LOCATION) | ||
15 | |||
16 | file(REMOVE_RECURSE ${RESOURCES_WORKING_DIR}) | ||
17 | file(MAKE_DIRECTORY ${RESOURCES_WORKING_DIR}) | ||
18 | file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${target}/ DESTINATION ${RESOURCES_WORKING_DIR}) | ||
19 | file(REMOVE | ||
20 | ${RESOURCE_FILE} | ||
21 | ${RESOURCE_FILE}.depends | ||
22 | ${RESOURCES_WORKING_DIR}/.gitignore | ||
23 | ${RESOURCES_WORKING_DIR}/CMakeLists.txt | ||
24 | ) | ||
25 | |||
26 | add_custom_command(OUTPUT ${RESOURCE_FILE} | ||
27 | COMMAND ${QT_RCC_EXECUTABLE} --project -o ${CMAKE_CURRENT_BINARY_DIR}/tmp.qrc | ||
28 | COMMAND $<TARGET_FILE:qrcAlias> -i ${CMAKE_CURRENT_BINARY_DIR}/tmp.qrc -o ${RESOURCE_FILE} | ||
29 | WORKING_DIRECTORY ${RESOURCES_WORKING_DIR} | ||
30 | ) | ||
31 | add_custom_command(OUTPUT ${BINARY_RESOURCE_FILE} | ||
32 | COMMAND ${QT_RCC_EXECUTABLE} --binary | ||
33 | -o ${BINARY_RESOURCE_FILE} | ||
34 | ${RESOURCE_FILE} | ||
35 | DEPENDS ${RESOURCE_FILE} | ||
36 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
37 | ) | ||
38 | |||
39 | add_custom_target(kube-${target}-rcc ALL DEPENDS ${BINARY_RESOURCE_FILE}) | ||
40 | |||
41 | set(${outfile} ${BINARY_RESOURCE_FILE} PARENT_SCOPE) | ||
42 | endfunction() | ||
43 | |||
44 | generate_binary_resource(icons binary_resource) | ||
45 | install(FILES ${binary_resource} DESTINATION ${KDE_INSTALL_DATADIR}/kube) | ||
46 | else() | ||
47 | install(DIRECTORY | ||
48 | icons/places | ||
49 | icons/actions | ||
50 | icons/mimetypes | ||
51 | DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/kube) | ||
52 | install(FILES icons/index.theme DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/kube) | ||
53 | 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 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | * Copyright (C) 2016 Kåre Särs <kare.sars@iki.fi> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Library General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Library General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Library General Public License | ||
15 | * along with this library; see the file COPYING.LIB. If not, write to | ||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | ||
19 | #include <QCoreApplication> | ||
20 | #include <QFile> | ||
21 | #include <QFileInfo> | ||
22 | #include <QString> | ||
23 | #include <QRegularExpression> | ||
24 | #include <QDebug> | ||
25 | #include <QCommandLineParser> | ||
26 | |||
27 | QString link(const QString &path, const QString &fileName) | ||
28 | { | ||
29 | QFile in(path + QLatin1Char('/') + fileName); | ||
30 | if (!in.open(QIODevice::ReadOnly)) { | ||
31 | qDebug() << "failed to read" << path << fileName << in.fileName(); | ||
32 | return QString(); | ||
33 | } | ||
34 | |||
35 | QString firstLine = in.readLine(); | ||
36 | if (firstLine.isEmpty()) { | ||
37 | qDebug() << in.fileName() << "line could not be read..."; | ||
38 | return QString(); | ||
39 | } | ||
40 | QRegularExpression fNameReg(QStringLiteral("(.*\\.(?:svg|png|gif|ico))")); | ||
41 | QRegularExpressionMatch match = fNameReg.match(firstLine); | ||
42 | if (!match.hasMatch()) { | ||
43 | return QString(); | ||
44 | } | ||
45 | |||
46 | QFileInfo linkInfo(path + QLatin1Char('/') + match.captured(1)); | ||
47 | QString aliasLink = link(linkInfo.path(), linkInfo.fileName()); | ||
48 | if (!aliasLink.isEmpty()) { | ||
49 | //qDebug() << fileName << "=" << match.captured(1) << "=" << aliasLink; | ||
50 | return aliasLink; | ||
51 | } | ||
52 | |||
53 | return path + QLatin1Char('/') + match.captured(1); | ||
54 | } | ||
55 | |||
56 | int parseFile(const QString &infile, const QString &outfile) | ||
57 | { | ||
58 | QFile in(infile); | ||
59 | QFile out(outfile); | ||
60 | QRegularExpression imageReg(QStringLiteral("<file>(.*\\.(?:svg|png|gif|ico))</file>")); | ||
61 | |||
62 | if (!in.open(QIODevice::ReadOnly)) { | ||
63 | qDebug() << "Failed to open" << infile; | ||
64 | return -1; | ||
65 | } | ||
66 | if (!out.open(QIODevice::WriteOnly)) { | ||
67 | qDebug() << "Failed to create" << outfile; | ||
68 | return -2; | ||
69 | } | ||
70 | |||
71 | while (in.bytesAvailable()) { | ||
72 | QString line = QString::fromLocal8Bit(in.readLine()); | ||
73 | QRegularExpressionMatch match = imageReg.match(line); | ||
74 | if (!match.hasMatch()) { | ||
75 | //qDebug() << "No Match: " << line; | ||
76 | out.write(qPrintable(line)); | ||
77 | continue; | ||
78 | } | ||
79 | |||
80 | QFileInfo info(match.captured(1)); | ||
81 | |||
82 | QString aliasLink = link(info.path(), info.fileName()); | ||
83 | if (aliasLink.isEmpty()) { | ||
84 | //qDebug() << "No alias: " << line; | ||
85 | out.write(qPrintable(line)); | ||
86 | continue; | ||
87 | } | ||
88 | |||
89 | QString newLine = QStringLiteral("<file alias=\"%1\">%2</file>\n").arg(match.captured(1), aliasLink); | ||
90 | //qDebug() << newLine; | ||
91 | out.write(qPrintable(newLine)); | ||
92 | } | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | int main(int argc, char *argv[]) | ||
97 | { | ||
98 | QCoreApplication app(argc, argv); | ||
99 | |||
100 | QCommandLineParser parser; | ||
101 | |||
102 | QCommandLineOption inOption(QStringList() << QLatin1String("i") << QLatin1String("infile"), QStringLiteral("Input qrc file"), QStringLiteral("infile")); | ||
103 | QCommandLineOption outOption(QStringList() << QLatin1String("o") << QLatin1String("outfile"), QStringLiteral("Output qrc file"), QStringLiteral("outfile")); | ||
104 | parser.setApplicationDescription( | ||
105 | QLatin1String("On Windows git handles symbolic links by converting them " | ||
106 | "to text files containing the links to the actual file. This application " | ||
107 | "takes a .qrc file as input and outputs a .qrc file with the symbolic " | ||
108 | "links converted to qrc-aliases.")); | ||
109 | parser.addHelpOption(); | ||
110 | parser.addVersionOption(); | ||
111 | parser.addOption(inOption); | ||
112 | parser.addOption(outOption); | ||
113 | parser.process(app); | ||
114 | |||
115 | const QString inName = parser.value(inOption); | ||
116 | const QString outName = parser.value(outOption); | ||
117 | |||
118 | return parseFile(inName, outName); | ||
119 | } | ||