<commit_before>// Copyright 2015 <NAME>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import QtQuick 2.3
import QtQuick.Controls 1.2

import "version.js" as Version

ApplicationWindow {
    id: mainWindow
    visible: true
    width: 640
    height: 480
    title: Version.appName

    // Holds the about window to avoid it being removed by garbage collector
    property var aboutWindow

    signal exportImage(var window)

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                id: exportMenuItem
                text: "Export image"
                enabled: false

                onTriggered: exportImage(mainWindow)
            }
            MenuItem {
                text: "Exit"
                onTriggered: Qt.quit();
            }
        }
        Menu {
            title: qsTr("Help")
            MenuItem {
                text: qsTr("About...")
                onTriggered: {
                    var component = Qt.createComponent("qrc:/about.qml");
                    aboutWindow = component.createObject(mainWindow);
                }
            }
        }
    }

    Rectangle {
        id: screenshotArea
        objectName: "screenshotArea"
        anchors.fill: parent
    }

    DropArea {
        anchors.fill: parent

        onDropped: {
            if (tipText.state == "BACKGROUND")
            {
                backgroundImage.source = drop.urls[0];
                tipText.state = "LOGO";
            }
            else if (tipText.state == "LOGO")
            {
                logoImage.source = drop.urls[0];
                tipText.state = "READY"
            }
        }
    }

    Image {
        id: backgroundImage
        objectName: "backgroundImage"
        mipmap: true

        signal sourceChanged()

        onSourceSizeChanged: {

            resizeImageWithAspectRatio(this, 1200, 900)
            setWindowSizeWithOffset(width, height)
            sourceChanged()
        }

        Image {
            id: logoImage
            x: 10
            y: 10
            mipmap: true

            Drag.active: true

            MouseArea {
                id: dragArea
                anchors.fill: parent
                drag.target: parent
            }

            onSourceSizeChanged: {
                resizeLogoImage();
            }
        }
    }

    Rectangle {
        id: tipTextBackground
        anchors.centerIn: tipText
        width: tipText.width + 20
        height: tipText.height + 20
        scale: tipText.scale

        color: "White"
        opacity: 0.8
    }
<commit_msg>Prevent invalid image files from changing app state<commit_after>// Copyright 2015 <NAME>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import QtQuick 2.3
import QtQuick.Controls 1.2

import "version.js" as Version

ApplicationWindow {
    id: mainWindow
    visible: true
    width: 640
    height: 480
    title: Version.appName

    // Holds the about window to avoid it being removed by garbage collector
    property var aboutWindow

    signal exportImage(var window)

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                id: exportMenuItem
                text: "Export image"
                enabled: false

                onTriggered: exportImage(mainWindow)
            }
            MenuItem {
                text: "Exit"
                onTriggered: Qt.quit();
            }
        }
        Menu {
            title: qsTr("Help")
            MenuItem {
                text: qsTr("About...")
                onTriggered: {
                    var component = Qt.createComponent("qrc:/about.qml");
                    aboutWindow = component.createObject(mainWindow);
                }
            }
        }
    }

    Rectangle {
        id: screenshotArea
        objectName: "screenshotArea"
        anchors.fill: parent
    }

    DropArea {
        anchors.fill: parent

        onDropped: {
            if (tipText.state == "BACKGROUND")
            {
                backgroundImage.source = drop.urls[0]; // this causes the state to change
            }
            else if (tipText.state == "LOGO")
            {
                logoImage.source = drop.urls[0]; // this causes the state to change
            }
        }
    }

    Image {
        id: backgroundImage
        objectName: "backgroundImage"
        mipmap: true

        signal sourceChanged()

        onSourceSizeChanged: {

            if (sourceSize.width == 0 || sourceSize.height == 0) {
                // invalid file was loaded by user
                console.log("Invalid file");
                mainWindow.width = 640;
                mainWindow.height = 480;
            } else {
                resizeImageWithAspectRatio(this, 1200, 900);
                setWindowSizeWithOffset(width, height);
                tipText.state = "LOGO";
                sourceChanged();
            }
        }

        Image {
            id: logoImage
            x: 10
            y: 10
            mipmap: true

            Drag.active: true

            MouseArea {
                id: dragArea
                anchors.fill: parent
                drag.target: parent
            }

            onSourceSizeChanged: {
                if (sourceSize.width > 0 && sourceSize.height > 0) {
                    resizeLogoImage();
                    tipText.state = "READY";
                }
            }
        }
    }

    Rectangle {
        id: tipTextBackground
        anchors.centerIn: tipText
        width: tipText.width + 20
        height: tipText.height + 20
        scale: tipText.scale

        color: "White"
        opacity: 0.8
    }

{'fraction_non_alphanumeric': 0.07605315238903025, 'fraction_numerical': 0.01441899915182358, 'mean_word_length': 1.478108581436077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5839457', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1751, 'n_words': 582}