<commit_before>/*
 * Copyright 2011 Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at 	
 * http://www.apache.org/licenses/LICENSE-2.0
 */

import QtQuick 1.1
import com.nokia.meego 1.2
import org.nemomobile.email 0.1

Page {
    id: folderListContainer

    Component.onCompleted: {
        mailFolderListModel.setAccountKey (currentMailAccountId);
        window.currentFolderId = mailFolderListModel.inboxFolderId();
        //window.folderListViewTitle = currentAccountDisplayName + " " + mailFolderListModel.inboxFolderName();
        folderServerCount = mailFolderListModel.folderServerCount(window.currentFolderId);
        gettingMoreMessages = false;
    }

    property int dateSortKey: 1
    property int senderSortKey: 1
    property int subjectSortKey: 1
    property string chooseFolder: qsTr("Choose folder:")
    property string attachments: qsTr("Attachments")
    property bool gettingMoreMessages: false
    property bool inSelectMode: false
    property int numOfSelectedMessages: 0
    property int folderServerCount: 0

    Connections {
        target: emailAgent
        onSyncCompleted: {
            gettingMoreMessages = false;
        }
        onError: {
            gettingMoreMessages = false;
        }
        onRetrievalCompleted: {
            gettingMoreMessages = false;
        }
    }

    ListModel {
        id: toModel
    }

    ListModel {
        id: ccModel
    }

    ListModel {
        id: attachmentsModel
    }

    function isDraftFolder()
    {
        return false;
//        return folderListView.pageTitle.indexOf( qsTr("Drafts") ) != -1 ;
    }

    PageHeader {
        id: pageHeader
        color: "#0066ff"
        text: currentAccountDisplayName + " " + mailFolderListModel.inboxFolderName()

        BusyIndicator {
            visible: window.refreshInProgress
            running: window.refreshInProgress
            anchors.right: parent.right
            anchors.rightMargin: UiConstants.DefaultMargin
            anchors.verticalCenter: parent.verticalCenter
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                pageStack.openDialog(Qt.resolvedUrl("FolderSelectionDialog.qml"))
            }
        }
    }

    ListView {
        id: messageListView
        anchors.top: pageHeader.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        clip: true

        Item {
            id: emptyMailboxView
            opacity: messageListView.count > 0 ? 0 : 1
            Text {
                id: noMessageText
                text: qsTr ("There are no messages in this folder.")
                anchors.centerIn: emptyMailboxView
                elide: Text.ElideRight
            }
        }

        model: messageListModel

        footer: Item {
            id: getMoreMessageRect
            height: 90
            width: parent.width
            visible: messageListView.count < folderServerCount

            Button {
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
                height: 45
                width: 300
                text: {
                     if(gettingMoreMessages)
                         return  qsTr("Getting more messages")
                     else
                         return  qsTr("Get more messages")
                }
                onClicked: {
                    gettingMoreMessages = true;
                    emailAgent.getMoreMessages(window.currentFolderId);
                }
            }
        }

        delegate: MouseArea {
            id: dinstance
            height: UiConstants.ListItemHeightSmall
            width: parent.width

            Text {
                id: senderText
                anchors.top: parent.top
                anchors.left: parent.left
                anchors.leftMargin: UiConstants.DefaultMargin
                width: (parent.width * 2) / 3
                height: UiConstants.ListItemHeightSmall / 2
                text: senderDisplayName != "" ? senderDisplayName : senderEmailAddress
                font.bold: readStatus ? false : true
                anchors.bottomMargin: 4
                elide: Text.ElideRight
            }
            Text {
                anchors.top: parent.top
                anchors.right: parent.right
                anchors.rightMargin: UiConstants.DefaultMargin
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 4
                text: Qt.formatDate(qDateTime);
            }
            Text {
                id: subjectText
                text: subject
                anchors.top: senderText.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.leftMargin: UiConstants.DefaultMargin
                anchors.rightMargin: UiConstants.DefaultMargin
                height: theme.listBackgroundPixelHeightTwo / 2
                elide: Text.ElideRight
            }

            // TODO: attachments icon, logic:
            // opacity: numberOfAttachments ? 1 : 0

            onClicked: {
                if (inSelectMode)
                {
                    if (selected)
                    {
                        messageListModel.deSelectMessage(index);
                        --folderListContainer.numOfSelectedMessages;
                    }
                    else
                    {
                        messageListModel.selectMessage(index);
                        ++folderListContainer.numOfSelectedMessages;
                    }
                }
                else
                {
                    window.mailId = messageId;
                    window.mailSubject = subject;
                    window.mailSender = sender;
                    window.mailTimeStamp = timeStamp;
                    window.mailBody = body;
                    window.mailQuotedBody = quotedBody;
                    window.mailHtmlBody = htmlBody;
                    window.mailAttachments = listOfAttachments;
                    window.numberOfMailAttachments = numberOfAttachments;
                    window.mailRecipients = recipients;
                    toListModel.init();
                    window.mailCc = cc;
                    ccListModel.init();
                    window.mailBcc = bcc;
                    bccListModel.init();
                    window.currentMessageIndex = index;
                    mailAttachmentModel.init();
                    emailAgent.markMessageAsRead (messageId);
                    window.mailReadFlag = true;

                    if ( isDraftFolder() )
                    {   window.editableDraft= true
        window.addPage(composer);
                    }
                    else
                        pageStack.push(Qt.resolvedUrl("ReadingView.qml"))

                }
            }
            onPressAndHold: {
                if (inSelectMode)
                    return;
                window.mailId = messageId;
                window.mailReadFlag = readStatus;
                window.currentMessageIndex = index;
                pageStack.openDialog(Qt.resolvedUrl("MessageContextMenu.qml"))
            }
        }

        ScrollDecorator {
            flickableItem: parent
        }
    }

    tools: ToolBarLayout {
        ToolIcon { iconId: "toolbar-back"; onClicked: { pageStack.pop(); }  }
        ToolIcon { iconId: "toolbar-add"; onClicked: {
            mailAttachmentModel.clear();
            window.composeInTextMode = true;
            pageStack.push(Qt.resolvedUrl("ComposerView.qml"))
        } }
        ToolIcon { iconId: "icon-m-toolbar-refresh"; onClicked: {
            // TODO: a spinner in the PageHeader would be neat
            if (window.refreshInProgress == true) {
                emailAgent.cancelSync();
                window.refreshInProgress = false;
            } else {
                emailAgent.synchronize(window.currentMailAccountId);
                window.refreshInProgress = true;
            }
        } }
        ToolIcon { iconId: "toolbar-view-menu" ; onClicked: colorMenu.open(); }
    }
}
<commit_msg>seemingly, this doesn't always have a parent set.<commit_after>/*
 * Copyright 2011 Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at 	
 * http://www.apache.org/licenses/LICENSE-2.0
 */

import QtQuick 1.1
import com.nokia.meego 1.2
import org.nemomobile.email 0.1

Page {
    id: folderListContainer

    Component.onCompleted: {
        mailFolderListModel.setAccountKey (currentMailAccountId);
        window.currentFolderId = mailFolderListModel.inboxFolderId();
        //window.folderListViewTitle = currentAccountDisplayName + " " + mailFolderListModel.inboxFolderName();
        folderServerCount = mailFolderListModel.folderServerCount(window.currentFolderId);
        gettingMoreMessages = false;
    }

    property int dateSortKey: 1
    property int senderSortKey: 1
    property int subjectSortKey: 1
    property string chooseFolder: qsTr("Choose folder:")
    property string attachments: qsTr("Attachments")
    property bool gettingMoreMessages: false
    property bool inSelectMode: false
    property int numOfSelectedMessages: 0
    property int folderServerCount: 0

    Connections {
        target: emailAgent
        onSyncCompleted: {
            gettingMoreMessages = false;
        }
        onError: {
            gettingMoreMessages = false;
        }
        onRetrievalCompleted: {
            gettingMoreMessages = false;
        }
    }

    ListModel {
        id: toModel
    }

    ListModel {
        id: ccModel
    }

    ListModel {
        id: attachmentsModel
    }

    function isDraftFolder()
    {
        return false;
//        return folderListView.pageTitle.indexOf( qsTr("Drafts") ) != -1 ;
    }

    PageHeader {
        id: pageHeader
        color: "#0066ff"
        text: currentAccountDisplayName + " " + mailFolderListModel.inboxFolderName()

        BusyIndicator {
            visible: window.refreshInProgress
            running: window.refreshInProgress
            anchors.right: parent.right
            anchors.rightMargin: UiConstants.DefaultMargin
            anchors.verticalCenter: parent.verticalCenter
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                pageStack.openDialog(Qt.resolvedUrl("FolderSelectionDialog.qml"))
            }
        }
    }

    ListView {
        id: messageListView
        anchors.top: pageHeader.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        clip: true

        Item {
            id: emptyMailboxView
            opacity: messageListView.count > 0 ? 0 : 1
            Text {
                id: noMessageText
                text: qsTr ("There are no messages in this folder.")
                anchors.centerIn: emptyMailboxView
                elide: Text.ElideRight
            }
        }

        model: messageListModel

        footer: Item {
            id: getMoreMessageRect
            height: 90
            width: messageListView.width
            visible: messageListView.count < folderServerCount

            Button {
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
                height: 45
                width: 300
                text: {
                     if(gettingMoreMessages)
                         return  qsTr("Getting more messages")
                     else
                         return  qsTr("Get more messages")
                }
                onClicked: {
                    gettingMoreMessages = true;
                    emailAgent.getMoreMessages(window.currentFolderId);
                }
            }
        }

        delegate: MouseArea {
            id: dinstance
            height: UiConstants.ListItemHeightSmall
            width: parent.width

            Text {
                id: senderText
                anchors.top: parent.top
                anchors.left: parent.left
                anchors.leftMargin: UiConstants.DefaultMargin
                width: (parent.width * 2) / 3
                height: UiConstants.ListItemHeightSmall / 2
                text: senderDisplayName != "" ? senderDisplayName : senderEmailAddress
                font.bold: readStatus ? false : true
                anchors.bottomMargin: 4
                elide: Text.ElideRight
            }
            Text {
                anchors.top: parent.top
                anchors.right: parent.right
                anchors.rightMargin: UiConstants.DefaultMargin
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 4
                text: Qt.formatDate(qDateTime);
            }
            Text {
                id: subjectText
                text: subject
                anchors.top: senderText.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.leftMargin: UiConstants.DefaultMargin
                anchors.rightMargin: UiConstants.DefaultMargin
                height: theme.listBackgroundPixelHeightTwo / 2
                elide: Text.ElideRight
            }

            // TODO: attachments icon, logic:
            // opacity: numberOfAttachments ? 1 : 0

            onClicked: {
                if (inSelectMode)
                {
                    if (selected)
                    {
                        messageListModel.deSelectMessage(index);
                        --folderListContainer.numOfSelectedMessages;
                    }
                    else
                    {
                        messageListModel.selectMessage(index);
                        ++folderListContainer.numOfSelectedMessages;
                    }
                }
                else
                {
                    window.mailId = messageId;
                    window.mailSubject = subject;
                    window.mailSender = sender;
                    window.mailTimeStamp = timeStamp;
                    window.mailBody = body;
                    window.mailQuotedBody = quotedBody;
                    window.mailHtmlBody = htmlBody;
                    window.mailAttachments = listOfAttachments;
                    window.numberOfMailAttachments = numberOfAttachments;
                    window.mailRecipients = recipients;
                    toListModel.init();
                    window.mailCc = cc;
                    ccListModel.init();
                    window.mailBcc = bcc;
                    bccListModel.init();
                    window.currentMessageIndex = index;
                    mailAttachmentModel.init();
                    emailAgent.markMessageAsRead (messageId);
                    window.mailReadFlag = true;

                    if ( isDraftFolder() )
                    {   window.editableDraft= true
        window.addPage(composer);
                    }
                    else
                        pageStack.push(Qt.resolvedUrl("ReadingView.qml"))

                }
            }
            onPressAndHold: {
                if (inSelectMode)
                    return;
                window.mailId = messageId;
                window.mailReadFlag = readStatus;
                window.currentMessageIndex = index;
                pageStack.openDialog(Qt.resolvedUrl("MessageContextMenu.qml"))
            }
        }

        ScrollDecorator {
            flickableItem: parent
        }
    }

    tools: ToolBarLayout {
        ToolIcon { iconId: "toolbar-back"; onClicked: { pageStack.pop(); }  }
        ToolIcon { iconId: "toolbar-add"; onClicked: {
            mailAttachmentModel.clear();
            window.composeInTextMode = true;
            pageStack.push(Qt.resolvedUrl("ComposerView.qml"))
        } }
        ToolIcon { iconId: "icon-m-toolbar-refresh"; onClicked: {
            // TODO: a spinner in the PageHeader would be neat
            if (window.refreshInProgress == true) {
                emailAgent.cancelSync();
                window.refreshInProgress = false;
            } else {
                emailAgent.synchronize(window.currentMailAccountId);
                window.refreshInProgress = true;
            }
        } }
        ToolIcon { iconId: "toolbar-view-menu" ; onClicked: colorMenu.open(); }
    }
}

{'fraction_non_alphanumeric': 0.07130476361245593, 'fraction_numerical': 0.00502062040523579, 'mean_word_length': 1.402987218153095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1410885', 'n_tokens_mistral': 4257, 'n_tokens_neox': 3946, 'n_words': 815}