<commit_before>/*
 * Copyright (C) 2015-2017 kimmoli <<EMAIL>>
 * All rights reserved.
 *
 * This file is part of Maira
 *
 * You may use this file under the terms of BSD license
 */

import QtQuick 2.0
import Sailfish.Silica 1.0
import "../components"

Page
{
    id: page

    property var attachment

    RemorsePopup { id: remorse }

    SilicaFlickable
    {
        id: flick
        anchors.fill: parent

        VerticalScrollDecorator { flickable: flick }

        PullDownMenu
        {
            MenuItem
            {
                text: "Remove attachment"
                onClicked: remorse.execute("Removing", function()
                {
                    removeattachment(attachment.id)
                    pageStack.pop()
                })
            }
            MenuItem
            {
                text: "Link in new comment"
                onClicked:
                {
                    var newcomment = pageStack.push(Qt.resolvedUrl("Editor.qml"), {text: (stringStartsWith(attachment.mime, "image") ? ("!" + attachment.filename + "|thumbnail!") : ("[^" + attachment.filename + "]"))})
                    newcomment.accepted.connect(function()
                    {
                        if (newcomment.text.length > 0)
                        {
                            managecomment(attachment.issuekey, newcomment.text, 0, function() { fetchissue(currentissue.key) })
                        }
                    })
                }
            }
        }

        contentHeight: column.height + pageHeader.height

        Column
        {
            id: column

            width: page.width
            spacing: Theme.paddingSmall

            PageHeader
            {
                id: pageHeader
                title: attachment.filename
            }

            DetailUserItem
            {
                label: "Author"
                avatar: attachment.avatarurl
                value: attachment.author
            }
            DetailItem
            {
                label: "Created"
                value: Qt.formatDateTime(new Date(attachment.created), "hh:mm dd.MM.yyyy")
            }
            DetailItem
            {
                label: "Size"
                value: bytesToSize(attachment.size)
            }
            DetailItem
            {
                label: "Type"
                value: attachment.mime
            }
            Item
            {
                width: 1
                height: Theme.paddingLarge
            }
            Image
            {
                id: thumbnail
                anchors.horizontalCenter: parent.horizontalCenter
                source: stringStartsWith(attachment.mime, "image") ? attachment.thumbnail : "image://theme/icon-l-document"
            }
            Item
            {
                width: 1
                height: Theme.paddingLarge
            }
            IconButton
            {
                icon.source: "image://theme/icon-m-cloud-download"
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: FileDownloader.downloadFile(attachment.content, attachment.filename)
            }
        }
    }
}

<commit_msg>[attachments] show larger image in attachment view<commit_after>/*
 * Copyright (C) 2015-2017 kimmoli <<EMAIL>>
 * All rights reserved.
 *
 * This file is part of Maira
 *
 * You may use this file under the terms of BSD license
 */

import QtQuick 2.0
import Sailfish.Silica 1.0
import "../components"

Page
{
    id: page

    property var attachment
    property bool isImage : stringStartsWith(attachment.mime, "image")

    Component.onDestruction: bi.stop()

    RemorsePopup { id: remorse }

    SilicaFlickable
    {
        id: flick
        anchors.fill: parent

        VerticalScrollDecorator { flickable: flick }

        PullDownMenu
        {
            MenuItem
            {
                text: "Remove attachment"
                onClicked: remorse.execute("Removing", function()
                {
                    removeattachment(attachment.id)
                    pageStack.pop()
                })
            }
            MenuItem
            {
                text: "Link in new comment"
                onClicked:
                {
                    var newcomment = pageStack.push(Qt.resolvedUrl("Editor.qml"), {text: (stringStartsWith(attachment.mime, "image") ? ("!" + attachment.filename + "|thumbnail!") : ("[^" + attachment.filename + "]"))})
                    newcomment.accepted.connect(function()
                    {
                        if (newcomment.text.length > 0)
                        {
                            managecomment(attachment.issuekey, newcomment.text, 0, function() { fetchissue(currentissue.key) })
                        }
                    })
                }
            }
        }

        contentHeight: column.height + pageHeader.height

        Column
        {
            id: column

            width: page.width
            spacing: Theme.paddingSmall

            PageHeader
            {
                id: pageHeader
                title: attachment.filename
            }

            DetailUserItem
            {
                label: "Author"
                avatar: attachment.avatarurl
                value: attachment.author
            }
            DetailItem
            {
                label: "Created"
                value: Qt.formatDateTime(new Date(attachment.created), "hh:mm dd.MM.yyyy")
            }
            DetailItem
            {
                label: "Size"
                value: bytesToSize(attachment.size)
            }
            DetailItem
            {
                label: "Type"
                value: attachment.mime
            }
            Item
            {
                width: 1
                height: Theme.paddingLarge
            }
            Image
            {
                id: thumbnail
                visible: isImage && previewImage.status == Image.Loading
                anchors.horizontalCenter: parent.horizontalCenter
                source: isImage ? attachment.thumbnail : ""
            }
            Image
            {
                id: previewImage
                anchors.horizontalCenter: parent.horizontalCenter
                sourceSize.width: page.width - 2*Theme.paddingLarge
                fillMode: Image.PreserveAspectFit
                source: isImage ? attachment.content : "image://theme/icon-l-document"
                onStatusChanged:
                {
                    if (status == Image.Loading && isImage)
                        bi.start()
                    else
                        bi.stop()
                }
            }
            Item
            {
                width: 1
                height: Theme.paddingLarge
            }
            IconButton
            {
                visible: previewImage.status == Image.Ready
                icon.source: "image://theme/icon-m-cloud-download"
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: FileDownloader.downloadFile(attachment.content, attachment.filename)
            }
        }
    }
}


{'fraction_non_alphanumeric': 0.082039911308204, 'fraction_numerical': 0.004573170731707317, 'mean_word_length': 1.1170431211498972, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2857944', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1647, 'n_words': 348}