[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [breeze-icons] /: Add a program to convert symbolically linked files to qrc aliases
From:       Kåre Särs <kare.sars () iki ! fi>
Date:       2016-06-16 16:01:32
Message-ID: E1bDZjY-0006Tv-KZ () scm ! kde ! org
[Download RAW message or body]

Git commit 1faf4798d27057f34a92f54199f7db77eac5443a by Kåre Särs.
Committed on 16/06/2016 at 16:00.
Pushed by sars into branch 'master'.

Add a program to convert symbolically linked files to qrc aliases

On windows git converts symbolic links to text files with links to
the actual file. This added application modifies the .qrc to use
aliases for the links.

This change also adds an option to not install the icons.

M  +10   -1    CMakeLists.txt
M  +5    -2    icons-dark/CMakeLists.txt
M  +6    -3    icons/CMakeLists.txt
A  +119  -0    qrcAlias.cpp     [License: LGPL (v2+)]

http://commits.kde.org/breeze-icons/1faf4798d27057f34a92f54199f7db77eac5443a

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 08cd1a0..5bea265 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,12 @@ include(GtkUpdateIconCache)
 set(REQUIRED_QT_VERSION 5.4.0)
 
 option(BINARY_ICONS_RESOURCE "Install a Qt binary resource file, containing breeze \
icons" OFF) +option(SKIP_INSTALL_ICONS "Skip installing the icons files" OFF)
+
+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)
@@ -38,7 +44,9 @@ function(generate_binary_resource target outfile)
             ${RESOURCE_FILE}.depends
             ${RESOURCES_WORKING_DIR}/.gitignore
             ${RESOURCES_WORKING_DIR}/CMakeLists.txt
-        COMMAND ${QT_RCC_EXECUTABLE} --project -o ${RESOURCE_FILE}
+        COMMAND ${QT_RCC_EXECUTABLE} --project -o \
${CMAKE_CURRENT_BINARY_DIR}/tmp.qrc +        COMMAND $<TARGET_FILE:qrcAlias> -i \
${CMAKE_CURRENT_BINARY_DIR}/tmp.qrc -o ${RESOURCE_FILE} +
         WORKING_DIRECTORY ${RESOURCES_WORKING_DIR}
         DEPENDS breeze-${target}-mkdir
     )
@@ -54,6 +62,7 @@ function(generate_binary_resource target outfile)
 
     set(${outfile} ${BINARY_RESOURCE_FILE} PARENT_SCOPE)
 endfunction()
+endif()
 
 add_subdirectory(autotests)
 add_subdirectory(icons)
diff --git a/icons-dark/CMakeLists.txt b/icons-dark/CMakeLists.txt
index 5d7e6f8..4dccbfd 100644
--- a/icons-dark/CMakeLists.txt
+++ b/icons-dark/CMakeLists.txt
@@ -7,8 +7,11 @@ endif()
 set( breeze_icon_dark_dirs  actions applets apps categories devices emblems emotes \
mimetypes places status)  
 set(BREEZE_INSTALL_DIR ${KDE_INSTALL_FULL_ICONDIR}/breeze-dark)
-install( DIRECTORY ${breeze_icon_dark_dirs} DESTINATION ${BREEZE_INSTALL_DIR} )
-install( FILES index.theme DESTINATION ${BREEZE_INSTALL_DIR})
+
+if (NOT SKIP_INSTALL_ICONS)
+    install( DIRECTORY ${breeze_icon_dark_dirs} DESTINATION ${BREEZE_INSTALL_DIR} )
+    install( FILES index.theme DESTINATION ${BREEZE_INSTALL_DIR})
+endif()
 
 gtk_update_icon_cache(${BREEZE_INSTALL_DIR})
 
diff --git a/icons/CMakeLists.txt b/icons/CMakeLists.txt
index bd4c048..7fc18e2 100644
--- a/icons/CMakeLists.txt
+++ b/icons/CMakeLists.txt
@@ -7,11 +7,14 @@ endif()
 set( breeze_icon_dirs  actions applets apps categories devices emblems emotes \
mimetypes places status )  
 set(BREEZE_INSTALL_DIR ${KDE_INSTALL_FULL_ICONDIR}/breeze)
-install( DIRECTORY ${breeze_icon_dirs} DESTINATION ${BREEZE_INSTALL_DIR} )
-install( FILES index.theme DESTINATION ${BREEZE_INSTALL_DIR})
+
+if (NOT SKIP_INSTALL_ICONS)
+    install( DIRECTORY ${breeze_icon_dirs} DESTINATION ${BREEZE_INSTALL_DIR} )
+    install( FILES index.theme DESTINATION ${BREEZE_INSTALL_DIR})
+endif()
 
 gtk_update_icon_cache(${BREEZE_INSTALL_DIR})
 
 if(BINARY_ICONS_RESOURCE)
     install( FILES ${binary_resource} DESTINATION ${BREEZE_INSTALL_DIR})
-endif()
\ No newline at end of file
+endif()
diff --git a/qrcAlias.cpp b/qrcAlias.cpp
new file mode 100644
index 0000000..409ba61
--- /dev/null
+++ b/qrcAlias.cpp
@@ -0,0 +1,119 @@
+/*  This file is part of the KDE libraries
+ *    Copyright (C) 2016 Kåre Särs <kare.sars@iki.fi>
+ *
+ *    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 <QCoreApplication>
+#include <QFile>
+#include <QFileInfo>
+#include <QString>
+#include <QRegularExpression>
+#include <QDebug>
+#include <QCommandLineParser>
+
+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("<file>(.*\\.(?:svg|png|gif|ico))</file>")); +
+    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("<file \
alias=\"%1\">%2</file>\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);
+}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic