Skip to content
Snippets Groups Projects
Select Git revision
  • 69e46c62d2e42c52452f2856434dbf7bd0a8159d
  • master default protected
  • release/beta-qt-202301101210
  • stable
  • release/beta-qt-202211182015
  • release/beta-qt-202211181752
  • release/beta-qt-202211171508
  • release/beta-qt-202211081754
  • release/beta-qt-202211071518
  • release/beta-qt-202210270957
  • release/beta-qt-202210071648
  • release/beta-qt-202209291549
  • release/beta-qt-202209011129
  • release/beta-qt-202208261640
  • release/beta-qt-202208241511
  • release/beta-qt-202208231849
  • release/beta-qt-202208091525
  • release/beta-qt-202207191241
  • release/beta-qt-202207181708
  • release/beta-qt-202207131914
  • release/beta-qt-202207131513
  • android/release_358
  • android/release_357
  • android/release_356
  • android/release_355
  • android/release_354
  • 20221220.0956.79e1207
  • android/release_353
  • android/release_352
  • android/release_350
  • android/release_349
  • android/release_348
  • android/release_347
  • 20221031.1308.130cc26
  • android/release_346
  • android/release_345
  • android/release_344
  • android/release_343
  • android/release_342
  • android/release_341
  • android/release_340
41 results

build-package-gentoo.sh

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    gen_resources_qrc.py 3.86 KiB
    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    # Copyright (C) 2021-2024 Savoir-faire Linux Inc.
    #
    # This program is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation; either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program 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 General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software
    # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
    # USA.
    
    """
    Generate qrc file for generic resource files (images, text documents, etc.)
    recursively within the resource directory. A QML file is also generated that
    contains a property for each resource file, which can be accessed from QML via
    a QML singleton.
    """
    
    import os
    import re
    
    # These paths should be relative to the working directory of the
    # script as set in the project CMakeLists, which should in turn be
    # where the resources.qrc will be located (currently 'src/app').
    resdir = os.path.join('..', '..', 'resources')
    qmlfile = os.path.join('net/jami/Constants', 'JamiResources.qml')
    resfile = os.path.join('resources.qrc')
    
    print("Generating resource.qrc file ...")
    
    
    def format_qml_prop(prop):
        """
        Replace characters that aren't valid within QML property names.
        - replace all spaces, periods, and hyphens with underscores
        - change all characters to lowercase
        """
        return "".join([{".": "_", "-": "_", " ": "_"}
                        .get(c, c) for c in prop]
                       ).lower()
    
    
    def path_contains_dir(filepath, dir_str):
        """ Return True if the given filepath contains the given directory. """
        # Split the filepath into its components
        path_components = os.path.normpath(filepath).split(os.sep)
        # Return True if the given directory is in the path
        return dir_str in path_components
    
    
    def gen_resources_qrc(with_webengine):
        """ Generate the resources.qrc file. """
        with open(resfile, 'w', encoding='utf-8') as qrc, \
                open(qmlfile, 'w', encoding='utf-8') as qml:
            qrc.write('<RCC>\n')
            qml.write('pragma Singleton\nimport QtQuick\nQtObject {\n')
            for root, _, files in os.walk(resdir):
                # Skip the webengine directory if we can't use webengine
                if not with_webengine and path_contains_dir(root, 'webengine'):
                    continue
                prefix = root.rsplit(os.sep, 1)[-1]
                # add a prefix to the resource file
                qrc.write(f'\t<qresource prefix="/{prefix}">\n')
                for filename in files:
                    # use posix separators in the resource path
                    filepath = os.path.join(
                        root, filename).replace(os.sep, '/')
                    qrc.write(
                        f'\t\t<file alias="{filename}">{filepath}</file>\n')
                    # only record images/icons as properties
                    if re.match("icons|images", prefix):
                        resource = f'qrc:/{prefix}/{filename}'
                        qml.write(
                            "    readonly property string"
                            f' {format_qml_prop(filename)}:'
                            f' "{resource}"\n'
                        )
                qrc.write('\t</qresource>\n')
            qml.write('}')
            qrc.write('</RCC>')
    
    
    if __name__ == '__main__':
        # We can't use webengine if we're building for macOS app store
        import argparse
        parser = argparse.ArgumentParser()
        parser.add_argument('--with-webengine', action='store_true',
                            default=False, help='Include webengine resources')
        args = parser.parse_args()
        gen_resources_qrc(args.with_webengine)