/****************************************************************************
**
** Copyright (C) 2024 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the FOO module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/


/******************** Desktop **************************************/
var qt6Init = "qt.qt6"
var qt6Version = "673"
var qt6DisplayVersion = "6.7"

var desktop6 = qt6Init + "." + qt6Version;
var mobileiOS = desktop6 + ".ios"
var mobileAndroid = desktop6 + ".android"
var desktop6Clang = desktop6 + ".clang_64"
var desktop6MinGW = desktop6 + ".win64_mingw"
var desktop6GCC = "";
if (systemInfo.currentCpuArchitecture == "arm64")
    desktop6GCC = desktop6 + ".linux_gcc_arm64";
else
    desktop6GCC = desktop6 + ".linux_gcc_64";

//dependencies for Qt6 examples
var qt6AddonDependencyQuick3D = desktop6 + ".qtquick3d";
var qt6AddonDependencyShaderTools = desktop6 + ".qtshadertools";
var qt6AddonDependencyMultimedia = desktop6 + ".addons.qtmultimedia";
var qt6AddonDependencyCharts = desktop6 + ".addons.qtcharts";

/******************** Qt for Android Automotive ********************/
var androidAutomotive = "android_automotive" + "." + "672"
var qtAAQtModuleDependencyBase = qt6Init + "." + "672";
var qtAAQtAndroidDependency =  qtAAQtModuleDependencyBase + ".android"
var qtAADisplayVersion = "6.7"
var qtAAQuickTimeLine = qtAAQtModuleDependencyBase + ".qtquicktimeline"
var qtAAMultimedia = qtAAQtModuleDependencyBase + ".addons.qtmultimedia"
var qtAARemoteObjects = qtAAQtModuleDependencyBase + ".addons.qtremoteobjects"
var qtAAInterfaceFramework = qtAAQtModuleDependencyBase + ".addons.qtinterfaceframework"

/******************** B2Qt ****************************************/
var qt6EmbeddedInit = "embedded.b2qt"
var qt6EmbeddedVersion = "673"
var qt6EmbeddedDisplayVersion = "6.7"

//name field is just a placeholder, the actual text is read from package DisplayName
var b2qtTargetsInPreferredOrderJSON = '{ "items" : [' +
     '{ "id":"awsec2arm64" , "name":"AWS EC2 ARM64" },' +
    '{ "id":"intelskylake64" , "name":"Intel NUC" },' +
    '{ "id":"jetsonagxorindevkit" , "name":"NVIDIA Jetson AGX Orin Developer Kit" },' +
    '{ "id":"jetsonagxxavierdevkit" , "name":"NVIDIA Jetson AGX Xavier Developer Kit" },' +
    '{ "id":"imx8mmlpddr4evk" , "name":"NXP i.MX 8M Mini LPDDR4 EVK" },'  +
    '{ "id":"imx8mnlpddr4evk" , "name":"NXP i.MX 8M Nano LPDDR4 EVK" },'  +
    '{ "id":"imx8mplpddr4evk" , "name":"NXP i.MX 8M Plus LPDDR4 EVK" },'  +
    '{ "id":"imx8mqevk" , "name":"NXP i.MX 8MQuad EVK" },' +
    '{ "id":"imx8qmmek" , "name":"NXP i.MX 8QuadMax MEK" },' +
    '{ "id":"imx8qxpmek" , "name":"NXP i.MX 8QuadXPlus MEK" },' +
    '{ "id":"imx9311x11lpddr4xevk" , "name":"NXP i.MX 93 11x11 LPDDR4X EVK" },' +
    '{ "id":"qcomarmv8a" , "name":"Qualcomm Robotics RB5 Development Kit" },' +
    '{ "id":"raspberrypi464" , "name":"Raspberry Pi 4 64-bit" },' +
    '{ "id":"stm32mp15disco" , "name":"STM32MP15 Discovery" },' +
    '{ "id":"stm32mp15eval" , "name":"STM32MP15 Evaluation" },' +
    '{ "id":"am62xxevm" , "name":"TI SK-AM62" },' +
    '{ "id":"j784s4evm" , "name":"TI SK-AM69" },' +
    '{ "id":"apalisimx6" , "name":"Toradex Apalis iMX6" },' +
    '{ "id":"apalisimx8" , "name":"Toradex Apalis iMX8" },' +
    '{ "id":"colibriimx6ull" , "name":"Toradex Colibri iMX6 ULL" }' +
    ']}';

var b2Qt6 = qt6EmbeddedInit + "." + qt6EmbeddedVersion;

/******************** MCU *****************************************/
var mcuInit = "mcu"
var mcuVersion = "0281"
var qtMCUDisplayVersion = "2.8.1"

//name field is just a placeholder, the actual text is read from package DisplayName
var mcuTargetsInPreferredOrderJSON = '{ "items" : [' +
    '{ "id":"common_files" , "name":"Desktop target and host tools only" },' +
    '{ "id":"tviic2d4mlite" , "name":"Infineon TRAVEO T2G Cluster 4M Lite eval kit" },' +
    '{ "id":"tviic2d4m_tviic2d6m_tviic2d6mddr" , "name":"Infineon TRAVEO T2G Cluster 4M, 6M, and 6M-DDR eval kits" },' +
    '{ "id":"mimxrt1050_evk" , "name":"NXP i.MX RT1050 EVK" },' +
    '{ "id":"mimxrt1060_evkb" , "name":"NXP i.MX RT1060 EVKB" },' +
    '{ "id":"mimxrt1064_evk" , "name":"NXP i.MX RT1064 EVK" },' +
    '{ "id":"mimxrt1170_evkb" , "name":"NXP i.MX RT1170 EVKB" },' +
    '{ "id":"ek_ra6m3g" , "name":"Renesas EK-RA6M3G" },' +
    '{ "id":"ek_ra8d1" , "name":"Renesas EK-RA8D1" },' +
    '{ "id":"rh850_d1m1a" , "name":"Renesas RH850 D1M1A" },' +
    '{ "id":"rh850_d1m1a_autosar" , "name":"Renesas RH850 D1M1A AUTOSAR" },' +
    '{ "id":"stm32f469i_discovery" , "name":"STM32F469I Discovery" },' +
    '{ "id":"stm32f769i_discovery" , "name":"STM32F769I Discovery" },' +
    '{ "id":"stm32h750b_discovery" , "name":"STM32H750B Discovery" } ]}';

var mcu = mcuInit + "." + mcuVersion

/******************** Design Studio *****************************************/
var toolsDesignStudio = "qt.tools.qtdesignstudio"

/******************** GENERAL ***********************************************/
var qt6MingwDescription = QT_TR_NOOP("MinGW toolchain and Qt libraries for MinGW")
var qt6ClangDescription = QT_TR_NOOP("Qt libraries for clang")
var qt6GCCDescription = QT_TR_NOOP("Qt libraries for GCC")
var designStudioDescription = QT_TR_NOOP("Latest version of Qt Design Studio")
var qt6MobileDescription = QT_TR_NOOP("Qt libraries for Android and iOS - platform restrictions apply")
var androidAutomotiveDescription = QT_TR_NOOP("Everything that is required to develop apps for Android Automotive OS.")
var productTypeDev = QT_TR_NOOP("Development tools")
var productTypeDesign = QT_TR_NOOP("Design tools")
var customInstall = QT_TR_NOOP("Custom Installation")
var customInstallDescription = QT_TR_NOOP("User selectable packages. Host platform and developer license restrictions apply.")

var desktopDevelopment = QT_TR_NOOP("Qt %1 for desktop development")
var androidAutomotiveDevelopment = QT_TR_NOOP("Qt %1 for Android Automotive")
var designTools = QT_TR_NOOP("Qt Design Studio")
var embeddedDevelopment = QT_TR_NOOP("Qt %1 for embedded development")
var mcuDevelopment = QT_TR_NOOP("MCU development")
var mobileDevelopment = QT_TR_NOOP("Qt %1 for mobile development")

var mainTargetsJSON = '{ "items" : [' +
    '{ "id": "' + desktop6MinGW + '", "name": "' + qsTranslate("installscript", desktopDevelopment).arg(qt6DisplayVersion) + '", "description": "' + qt6MingwDescription + '" },' +
    '{ "id": "' + desktop6Clang + '", "name": "' + qsTranslate("installscript", desktopDevelopment).arg(qt6DisplayVersion) + '", "description": "' + qt6ClangDescription + '" },' +
    '{ "id": "' + desktop6GCC + '", "name": "' + qsTranslate("installscript", desktopDevelopment).arg(qt6DisplayVersion) + '", "description": "' + qt6GCCDescription + '" },' +
    '{ "id": "' + androidAutomotive + '", "name": "' + qsTranslate("installscript", androidAutomotiveDevelopment).arg(qtAADisplayVersion) + '" , "description": "' + androidAutomotiveDescription + '" },' +
    '{ "id": "' + toolsDesignStudio + '", "name": "' + designTools + '" , "description": "' + designStudioDescription + '" },' +
    '{ "id": "' + b2Qt6 + '", "name": "' + qsTranslate("installscript", embeddedDevelopment).arg(qt6EmbeddedDisplayVersion) + '", "description": "" },' +
    '{ "id": "' + mcu + '" , "name": "' + mcuDevelopment  + '", "description": "" },' +
    '{ "id": "' + mobileiOS + '", "name": "' + qsTranslate("installscript", mobileDevelopment).arg(qt6DisplayVersion) + '", "description": "' + qt6MobileDescription + '" },' +
    '{ "id": "' + mobileAndroid + '", "name": "' + qsTranslate("installscript", mobileDevelopment).arg(qt6DisplayVersion) + '", "description": "' + qt6MobileDescription + '" } ]}';

/******************** INTERNAL *************************************/
var mainTargets = JSON.parse(mainTargetsJSON);
var b2qtTargets = JSON.parse(b2qtTargetsInPreferredOrderJSON);
var mcuTargets = JSON.parse(mcuTargetsInPreferredOrderJSON);

function getItemValueForTarget(id, prop){
    for (var i =0; i < mainTargets.items.length; i++){
        if (mainTargets.items[i].id === id) {
            if (mainTargets.items[i].hasOwnProperty(prop) === true)
                return mainTargets.items[i][prop];
            else
                return "";
        }
    }
    return "";
}

var selectionWidget;
var componentsToInstall = [];

var qt6DesktopAndAddonDependencies = [];
var androidAutomotiveComponents = [];
var qt6MobileComponents = [];
var qt6EmbeddedComponent;
var qtMCUComponent;
var qtDesignStudioComponent;
var ifwVersion;

function Component()
{
    //This repository contains feature that is available only from 4.1.1 onwards (QTIFW-2225)
    ifwVersion = installer.value("FrameworkVersion");
    if (!installer.isInstaller() || installer.versionMatches(ifwVersion, "<4.1.1"))
        return;

    if (installer.isCommandLineDefaultInstall()) {
        var installComponent;
        if (installer.value("os") == "win")
            installComponent = Component.prototype.getComponent(desktop6MinGW);
        else if (installer.value("os") == "mac")
            installComponent = Component.prototype.getComponent(desktop6Clang);
        else
            installComponent = Component.prototype.getComponent(desktop6GCC);

        if (installComponent != "")
            installer.componentByName(installComponent).setValue("Default", "true");
    } else {
        if (installer.versionMatches(ifwVersion, "<4.7.0")) {
            if (installer.addWizardPageItem(component, "InstallTypeWidget", QInstaller.TargetDirectory, 0))
                component.loaded.connect(this, Component.prototype.loaded_46x);
        } else {
            if (installer.addWizardPageItem(component, "InstallTypeWidgetFrame", QInstaller.TargetDirectory, 0))
                component.loaded.connect(this, Component.prototype.loaded);
        }
    }
}

Component.prototype.getAvailableTargets = function(qtVersionId, targets)
{
    var availableTargets = [];
    if (!targets)
        return availableTargets;
    var components = installer.components(qtVersionId);
    for (i = 0; i < targets.items.length; i++) {
        for (j = 0; j < components.length; j++) {
            var componentName = components[j].name;
            var componentId = componentName.slice(qtVersionId.length + 1);
            if (componentId == targets.items[i].id) {
                targets.items[i].name = components[j].displayName;
                var availableTargetItem = {};
                availableTargetItem.name = components[j].displayName;
                availableTargetItem.id = componentId;
                availableTargets.push(availableTargetItem);
                break;
            }
        }
    }
    return availableTargets;
}

Component.prototype.deselectAllComponents = function()
{
    for (i = 0; i < componentsToInstall.length; i++) {
        var component = installer.componentByName(componentsToInstall[i]);
        if (component)
            installer.deselectComponent(componentsToInstall[i]);
    }

    // In 4.7.0 we add/remove components by single click, with versions below
    // 4.7.0 we calculate all checkboxes on single click
    if (installer.versionMatches(ifwVersion, "<4.7.0"))
        componentsToInstall = [];
}

Component.prototype.componentSelected = function(id, isSelected)
{
    Component.prototype.deselectAllComponents();
    if (id == "custom") {
        componentsToInstall = [];
        var designStudioComponent = installer.componentByName(toolsDesignStudio);
        if (designStudioComponent && designStudioComponent.value("Default") == "true")
            installer.selectComponent(toolsDesignStudio);
        installer.clearComponentsToInstallCalculated();
        installer.calculateComponentsToInstall();
    } else if (id == "desktop") {
        if (isSelected) {
            componentsToInstall = componentsToInstall.concat(qt6DesktopAndAddonDependencies);
        } else {
            componentsToInstall = componentsToInstall.filter(function (x) {
                return qt6DesktopAndAddonDependencies.indexOf(x) < 0;
            });
        }
    } else if (id == "androidAutomotive") {
        if (isSelected) {
            componentsToInstall = componentsToInstall.concat(androidAutomotiveComponents);
        } else {
            componentsToInstall = componentsToInstall.filter(function (x) {
                return androidAutomotiveComponents.indexOf(x) < 0;
            });
        }
    } else if (id == "mobile") {
        if (isSelected) {
            componentsToInstall = componentsToInstall.concat(qt6MobileComponents);
        } else {
            componentsToInstall = componentsToInstall.filter(function (x) {
                return qt6MobileComponents.indexOf(x) < 0;
            });
        }
    } else {
        if (isSelected) {
            componentsToInstall.push(id);
        } else {
            var index = componentsToInstall.indexOf(id);
            if (index != -1)
                componentsToInstall.splice(index, 1);
        }
    }
    if (componentsToInstall.length == 0) {
        installer.setDefaultPageVisible(QInstaller.ComponentSelection, true);
    } else {
        installer.setDefaultPageVisible(QInstaller.ComponentSelection, false);
    }

    for (j = 0; j < componentsToInstall.length; j++) {
        var component = installer.componentByName(componentsToInstall[j]);
        if (component)
            installer.selectComponent(componentsToInstall[j]);
        else
            console.log("Component not found " + componentsToInstall[j]);
    }

    if ((componentsToInstall.length == 1) && (componentsToInstall[0] == toolsDesignStudio))
        installer.setValue("DesignStudioInstallOnly", true);
    else
        installer.setValue("DesignStudioInstallOnly", false);

    installer.clearComponentsToInstallCalculated();
    installer.calculateComponentsToInstall()
}

Component.prototype.getComponent = function(qtVersionId, targets)
{
    var selectedComponent = "";
    if (targets == undefined) {
        if (installer.componentByName(qtVersionId) != null)
            selectedComponent = qtVersionId;
    } else {
        var components = installer.components(qtVersionId);
loop1:
        for (i = 0; i < targets.items.length; i++) {
loop2:
            for (j = 0; j < components.length; j++) {
                var componentName = components[j].name;
                var componentId = componentName.slice(qtVersionId.length + 1);
                if (componentId == targets.items[i].id) {
                    selectedComponent = componentName;
                    break loop1;
                }
            }
        }
    }
    return selectedComponent;
}

Component.prototype.initFrameItem = function(objectName, productTypeStr, qtVersionId, targets)
{
    var selectedComponent = Component.prototype.getComponent(qtVersionId, targets);
    if (selectedComponent != "") {
        var titleText = qsTranslate("installscript", getItemValueForTarget(qtVersionId, "name"));
        var description = qsTranslate("installscript", getItemValueForTarget(qtVersionId, "description"));
        var availableTargets = Component.prototype.getAvailableTargets(qtVersionId, targets);
        selectionWidget.addItem(objectName, qtVersionId, productTypeStr, titleText, description, availableTargets);
    }
}

Component.prototype.initMobileItemsAndFrame = function(objectName, productTypeStr, id, dependencies)
{
    var selectedComponents = [];
    var components = [];
    for (i = 0; i < dependencies.length; i++)
        components = components.concat(installer.components(dependencies[i] + "$"));

    for (j = 0; j < components.length; j++) {
        var componentName = components[j].name;
        selectedComponents.push(componentName);
    }

    if (selectedComponents.length > 0) {
        var titleText = qsTranslate("installscript", getItemValueForTarget(dependencies[0], "name"));
        var description = qsTranslate("installscript", getItemValueForTarget(dependencies[0], "description"));
        selectionWidget.addItem(objectName, id, productTypeStr, titleText, description);
    }
    return selectedComponents;
}

Component.prototype.loaded = function()
{
    selectionWidget = component.userInterface("InstallTypeWidgetFrame").defaultInstall;
    var addonDependencies = [qt6AddonDependencyQuick3D, qt6AddonDependencyMultimedia, qt6AddonDependencyShaderTools, qt6AddonDependencyCharts];
    if (selectionWidget != null) {
        selectionWidget.selectedChanged.connect(Component.prototype.componentSelected);
        // Custom installation
        selectionWidget.addItem("custom", "custom", "", qsTr(customInstall), qsTr(customInstallDescription));
        if (installer.value("os") == "win")
            addonDependencies.unshift(desktop6MinGW);
        else if (installer.value("os") == "mac")
            addonDependencies.unshift(desktop6Clang);
        else
            addonDependencies.unshift(desktop6GCC);
        qt6DesktopAndAddonDependencies = addonDependencies.slice();
        Component.prototype.initMobileItemsAndFrame("desktop", qsTr(productTypeDev), "desktop", qt6DesktopAndAddonDependencies);

        Component.prototype.initFrameItem("b2qt", qsTr(productTypeDev), b2Qt6, b2qtTargets);
        Component.prototype.initFrameItem("mcu", qsTr(productTypeDev), mcu, mcuTargets);
        Component.prototype.initFrameItem("designstudio", qsTr(productTypeDesign), toolsDesignStudio);

        var androidAutomotiveDependencies = [androidAutomotive, qtAAQtAndroidDependency, qtAAQuickTimeLine, qtAARemoteObjects, qtAAInterfaceFramework, qtAAMultimedia]
        androidAutomotiveComponents = Component.prototype.initMobileItemsAndFrame("android", qsTr(productTypeDev), "androidAutomotive", androidAutomotiveDependencies);

        var mobileTargets = [mobileAndroid, mobileiOS]
        qt6MobileComponents = Component.prototype.initMobileItemsAndFrame("mobile", qsTr(productTypeDev), "mobile", mobileTargets);
    } else {
        console.log("Selection widget not found");
    }
}

/********* Rest of the functions are used in IFW version 4.6.x default install *************/
Component.prototype.setAvailableTargets = function(qtVersionId, targets, uiFrame, comboBox)
{
    var availableTarget = []
    var components = installer.components(qtVersionId);
    for (i = 0; i < targets.items.length; i++) {
        for (j = 0; j < components.length; j++) {
            var componentName = components[j].name;
            var componentId = componentName.slice(qtVersionId.length + 1);
            if (componentId == targets.items[i].id) {
                if (availableTarget.indexOf(targets.items[i].name) == -1) {
                    targets.items[i].name = components[j].displayName;
                    availableTarget.push(components[j].displayName);
                    break;
                }
            }
        }
    }
    if (availableTarget.length == 0)
        uiFrame.visible = false;
    else
        gui.setTextItems(comboBox, availableTarget);
}

Component.prototype.getId = function (combobox, targets)
{
    var currentText = combobox.currentText;
    var id = "";
    for (j = 0; j < targets.items.length; j++) {
        if (currentText === targets.items[j].name) {
            id = targets.items[j].id;
            break;
        }
    }
    return id;
}

Component.prototype.b2Qt6TargetChanged = function()
{
    //Select the checkbox, if not already selected, when we change the target
    if (selectionWidget.qt6EmbeddedFrame.qt6EmbeddedCheckBox.checked == false)
        selectionWidget.qt6EmbeddedFrame.qt6EmbeddedCheckBox.checked = true
    var selectedTarget = Component.prototype.getId(selectionWidget.qt6EmbeddedFrame.qt6EmbeddedComboBox, b2qtTargets);
    qt6EmbeddedComponent = b2Qt6 + "." + selectedTarget;
    Component.prototype.selectComponentForInstall();
}

Component.prototype.mcuTargetChanged = function()
{
    //Select the checkbox, if not already selected, when we change the target
    if (selectionWidget.qt6MCUFrame.qt6MCUCheckBox.checked == false)
        selectionWidget.qt6MCUFrame.qt6MCUCheckBox.checked = true
    var selectedTarget = Component.prototype.getId(selectionWidget.qt6MCUFrame.qt6MCUComboBox, mcuTargets);
    qtMCUComponent = mcu + "." + selectedTarget;
    Component.prototype.selectComponentForInstall();
}

Component.prototype.selectComponentForInstall = function(checked)
{
    Component.prototype.deselectAllComponents();
    //Select new components
    if (selectionWidget.qt6MobileFrame.qt6MobileCheckBox.checked == true)
        componentsToInstall = componentsToInstall.concat(qt6MobileComponents);
    if (selectionWidget.qt6DesktopFrame.qt6DesktopCheckBox.checked == true)
        componentsToInstall = componentsToInstall.concat(qt6DesktopAndAddonDependencies);
    if (selectionWidget.androidAutomotiveFrame.androidAutomotiveCheckBox.checked == true)
        componentsToInstall = componentsToInstall.concat(androidAutomotiveComponents);
    if (selectionWidget.qt6EmbeddedFrame.qt6EmbeddedCheckBox.checked == true)
        componentsToInstall.push(qt6EmbeddedComponent);
    if (selectionWidget.qt6MCUFrame.qt6MCUCheckBox.checked == true)
        componentsToInstall.push(qtMCUComponent);
    if (selectionWidget.designStudioFrame.designStudioCheckBox.checked == true)
        componentsToInstall.push(qtDesignStudioComponent);

    if (componentsToInstall.length == 0) {
        selectionWidget.customFrame.customCheckBox.checked = true;
        installer.setDefaultPageVisible(QInstaller.ComponentSelection, true);
    } else {
        selectionWidget.customFrame.customCheckBox.checked = false;
        installer.setDefaultPageVisible(QInstaller.ComponentSelection, false);
    }

    for (j = 0; j < componentsToInstall.length; j++) {
        var component = installer.componentByName(componentsToInstall[j]);
        if (component)
            installer.selectComponent(componentsToInstall[j]);
        else
            console.log("Component not found " + componentsToInstall[j]);
    }

    if ((componentsToInstall.length == 1) && (componentsToInstall[0] == toolsDesignStudio))
        installer.setValue("DesignStudioInstallOnly", true);
    else
        installer.setValue("DesignStudioInstallOnly", false);

    installer.clearComponentsToInstallCalculated();
    installer.calculateComponentsToInstall()
}

Component.prototype.customInstallationSelected = function(checked)
{
    if (selectionWidget.customFrame.customCheckBox.checked == true) {
        selectionWidget.qt6MobileFrame.qt6MobileCheckBox.checked = false;
        selectionWidget.qt6DesktopFrame.qt6DesktopCheckBox.checked = false;
        selectionWidget.androidAutomotiveFrame.androidAutomotiveCheckBox.checked = false;
        selectionWidget.qt6EmbeddedFrame.qt6EmbeddedCheckBox.checked = false;
        selectionWidget.qt6MCUFrame.qt6MCUCheckBox.checked = false;
        selectionWidget.designStudioFrame.designStudioCheckBox.checked = false;
        Component.prototype.deselectAllComponents();
        var designStudioComponent = installer.componentByName(toolsDesignStudio);
        if (designStudioComponent && designStudioComponent.value("Default") == "true")
            installer.selectComponent(toolsDesignStudio);
        installer.clearComponentsToInstallCalculated();
        installer.calculateComponentsToInstall();
        installer.setDefaultPageVisible(QInstaller.ComponentSelection, true);
    }
}

Component.prototype.initCheckBox = function(checkBox, label, buttonFrame, qtVersionId, targets)
{
    var selectedComponent = Component.prototype.getComponent(qtVersionId, targets);
    //If no component found behind the checkBox, hide the checkBox
    if (selectedComponent == "") {
        buttonFrame.visible = false;
    } else {
        checkBox.text = qsTranslate("installscript", getItemValueForTarget(qtVersionId, "name"));
        if (label)
            label.text = qsTranslate("installscript", getItemValueForTarget(qtVersionId, "description"));
        checkBox.clicked.connect(Component.prototype.selectComponentForInstall);
    }
    return selectedComponent;
}

Component.prototype.initMobileCheckBox = function(checkBox, label, buttonFrame, qtVersionIds)
{
    var selectedComponents = [];
    var components = [];
    for (i = 0; i < qtVersionIds.length; i++)
        components = components.concat(installer.components(qtVersionIds[i] + "$"));

    for (j = 0; j < components.length; j++) {
        var componentName = components[j].name;
        selectedComponents.push(componentName);
    }
    //If component not found behind the checkBox, hide the checkBox
    if (selectedComponents.length == 0) {
        buttonFrame.visible = false;
    } else {
        checkBox.text = qsTranslate("installscript", getItemValueForTarget(qtVersionIds[0], "name"));
        if (label)
            label.text = qsTranslate("installscript", getItemValueForTarget(qtVersionIds[0], "description"));
        checkBox.clicked.connect(Component.prototype.selectComponentForInstall);
    }
    return selectedComponents;
}

Component.prototype.loaded_46x = function()
{
    selectionWidget = component.userInterface("InstallTypeWidget").scrollArea.qt_scrollarea_viewport.scrollContents;
    var addonDependencies = [qt6AddonDependencyQuick3D, qt6AddonDependencyMultimedia, qt6AddonDependencyShaderTools, qt6AddonDependencyCharts];
    if (selectionWidget != null) {
        var qt6DesktopCheckbox = selectionWidget.qt6DesktopFrame.qt6DesktopCheckBox;
        var qt6DesktopLabel = selectionWidget.qt6DesktopFrame.qt6DesktopLabel;
        var qt6DesktopComponent = [];
        if (installer.value("os") == "win")
            addonDependencies.unshift(desktop6MinGW);
        else if (installer.value("os") == "mac")
            addonDependencies.unshift(desktop6Clang);
        else
            addonDependencies.unshift(desktop6GCC);
        qt6DesktopAndAddonDependencies = addonDependencies.slice();
        qt6DesktopComponent = Component.prototype.initMobileCheckBox(qt6DesktopCheckbox, qt6DesktopLabel, selectionWidget.qt6DesktopFrame, qt6DesktopAndAddonDependencies);

        qt6EmbeddedComponent = Component.prototype.initCheckBox(selectionWidget.qt6EmbeddedFrame.qt6EmbeddedCheckBox, null, selectionWidget.qt6EmbeddedFrame, b2Qt6, b2qtTargets);
        qtMCUComponent = Component.prototype.initCheckBox(selectionWidget.qt6MCUFrame.qt6MCUCheckBox, null, selectionWidget.qt6MCUFrame, mcu, mcuTargets);
        qtDesignStudioComponent = Component.prototype.initCheckBox(selectionWidget.designStudioFrame.designStudioCheckBox, selectionWidget.designStudioFrame.designStudioLabel, selectionWidget.designStudioFrame, toolsDesignStudio);

        var androidAutomotiveDependencies = [androidAutomotive, qtAAQtAndroidDependency, qtAAQuickTimeLine, qtAARemoteObjects, qtAAInterfaceFramework, qtAAMultimedia]
        androidAutomotiveComponents = Component.prototype.initMobileCheckBox(selectionWidget.androidAutomotiveFrame.androidAutomotiveCheckBox, selectionWidget.androidAutomotiveFrame.androidAutomotiveLabel, selectionWidget.androidAutomotiveFrame, androidAutomotiveDependencies);

        var mobileTargets = [mobileAndroid, mobileiOS]
        qt6MobileComponents = Component.prototype.initMobileCheckBox(selectionWidget.qt6MobileFrame.qt6MobileCheckBox, selectionWidget.qt6MobileFrame.qt6MobileLabel, selectionWidget.qt6MobileFrame, mobileTargets);

        // Comboboxes for MCU and embedded
        var comboBox = selectionWidget.qt6MCUFrame.qt6MCUComboBox;
        Component.prototype.setAvailableTargets(mcu, mcuTargets, selectionWidget.qt6MCUFrame, comboBox);
        comboBox.currentIndexChanged.connect(Component.prototype.mcuTargetChanged);

        comboBox = selectionWidget.qt6EmbeddedFrame.qt6EmbeddedComboBox;
        Component.prototype.setAvailableTargets(b2Qt6, b2qtTargets, selectionWidget.qt6EmbeddedFrame, comboBox);
        comboBox.currentIndexChanged.connect(Component.prototype.b2Qt6TargetChanged);

        // Custom installation
        var customCheckbox = selectionWidget.customFrame.customCheckBox;
        customCheckbox.clicked.connect(Component.prototype.customInstallationSelected);
    }
}
