<commit_before>import Qt 4.7
import MeeGo.Labs.Components 0.1 as Labs
import MeeGo.Components 0.1
import MeeGo.Media 0.1
import QtMultimediaKit 1.1
import MeeGo.App.Video.VideoPlugin 1.0
import MeeGo.Sharing 0.1
import MeeGo.Sharing.UI 0.1
import "functions.js" as Code

AppPage {
    id: landingPage
    anchors.fill: parent
    pageTitle: labelAppName
    property bool infocus: true
    property string videoSearch: ""
    property int videoListState: 0

    onActivated : {
        infocus = true;
        currentState.page = 0;
        window.disableToolBarSearch = false;
        fullScreen = false;
        window.lockOrientationIn = "noLock";
    }
    onDeactivated : { infocus = false; }

    Labs.ApplicationsModel {
        id: appsModel
        directories: [ "/usr/share/meego-ux-appgrid/applications", "/usr/share/applications", "~/.local/share/applications" ]
    }

    ModalDialog {
        id: deleteItemDialog
        title: labelDelete
        acceptButtonText: labelConfirmDelete
        cancelButtonText: labelCancel
        property variant payload
        onPayloadChanged:{
            contentItem.title = payload.mtitle;
        }
        onAccepted: {
            masterVideoModel.destroyItemByID(payload.mitemid);
        }
        content: Item {
            id: contentItem
            anchors.fill: parent
            property alias title : titleText.text
            clip: true
            Text{
                id: titleText
                text : qsTr("Video name")
                anchors.top: parent.top
                width:  parent.width
                horizontalAlignment: Text.AlignHCenter
            }
            Text {
                //: Confirmation message for deleting videos. "This" and "it" refer to list items, which represent videos on-screen.
                text: qsTr("If you delete this, it will be removed from your device")
                anchors.top:titleText.bottom
                width:  parent.width
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: theme_fontPixelSizeMedium
            }
        }
    }

    ModalDialog {
        id: deleteMultipleItemsDialog
        property int deletecount: 0
        //: text asking the user if the videos(s) is to deleted, warning them that it's permanent
        title: (deletecount < 2)?qsTr("Permanently delete this video?"):qsTr("Permanently delete these %1 videos?").arg(deletecount)
        acceptButtonText: labelConfirmDelete
        cancelButtonText:labelCancel
        onAccepted: {
            masterVideoModel.destroyItemsByID(masterVideoModel.getSelectedIDs());
            masterVideoModel.clearSelected();
            shareObj.clearItems();
            multiSelectMode = false;
        }
        content: Item {
            anchors.fill: parent
            clip: true
            Text {
                //: Confirmation message for deleting videos. "These" and "they" refer to list items, which represent videos on-screen.
                text: qsTr("If you delete these, they will be removed from your device")
                anchors.verticalCenter:parent.verticalCenter
                width:  parent.width
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: theme_fontPixelSizeMedium
            }
        }
    }

    Connections {
        target: window
        onSearch: {
            videoSearch = needle;
            landingView.opacity = 0;
            masterVideoModel.search = videoSearch;
            if(masterVideoModel.filter != VideoListModel.FilterSearch)
                masterVideoModel.filter = VideoListModel.FilterSearch
            window.actionMenuSelectedIndex = 0
            videoListState = (videoListState + 1)%2;
        }
    }

    function playvideo(payload)
    {
        targetState.set(1, "play", payload.muri, 0, -1);
        window.addPage(detailViewContent);
    }

    Connections {
        target: window
        onSetState: {
            if(infocus)
            {
                if(targetState.filter >= 0)
                    masterVideoModel.filter = targetState.filter;

                if((targetState.page == 1)&&(targetState.command != "")&&(targetState.uri != "")) // Goto DetailPage
                {
                    window.addPage(detailViewContent);
                }
            }
        }
    }

    ContextMenu {
        id: contextMenu
        property alias payload: contextActionMenu.payload
        property alias model: contextActionMenu.model
        property int mouseX
        property int mouseY
        content: ActionMenu {
            id: contextActionMenu
            property variant payload: undefined
            onTriggered: {
                shareObj.clearItems();
                if (model[index] == labelPlay)
                {
                    // Play
                    landingPage.playvideo(payload);
                    contextMenu.hide();
                }
                else if ((model[index] == labelFavorite)||(model[index] == labelUnFavorite))
                {
                    // Favorite/unfavorite
                    Code.changeItemFavorite(payload);
                    contextMenu.hide();
                }
                else if (model[index] == labelDelete)
                {
                    // Delete
                    deleteItemDialog.payload = payload;
                    deleteItemDialog.show();
                    contextMenu.hide();
                }
                else if (model[index] == labelMultiSelect)
                {
                    // multi select mode on
                    multiSelectMode = true;
                    contextMenu.hide();
                }
                else if (model[index] == labelcShare)
                {
                    // Share
                    shareObj.clearItems();
                    shareObj.addItem(payload.muri) // URI
                    shareObj.showContextTypes(contextMenu.mouseX, contextMenu.mouseY)
                }
            }
        }
    }
    Connections {
        target: masterVideoModel
        onTotalChanged: {
            topicAll = qsTr("All (%1 videos)").arg(masterVideoModel.total);
            window.actionMenuModel = [topicAll, topicAdded, topicViewed, topicUnwatched, topicFavorites];
            window.actionMenuSelectedIndex = 0
        }
    }
    actionMenuModel: [topicAll, topicAdded, topicViewed, topicUnwatched, topicFavorites]
    actionMenuPayload: ["all", "added", "viewed", "unwatched", "favorites"]
    actionMenuHighlightSelection: true
    actionMenuSelectedIndex: 0
    onActionMenuTriggered: {
        selectView(selectedItem);
    }

    function selectView(selectedItem) {
        if (selectedItem == "all") {
            actionMenuSelectedIndex = 1
            landingView.opacity = 0;
            if(masterVideoModel.filter != VideoListModel.FilterAll)
            {
                masterVideoModel.filter = VideoListModel.FilterAll
                masterVideoModel.sort = VideoListModel.SortByTitle;
            }
        }else if(selectedItem == "added") {
            actionMenuSelectedIndex = 2
            landingView.opacity = 0;
            if(masterVideoModel.filter != VideoListModel.FilterAdded)
            {
                masterVideoModel.filter = VideoListModel.FilterAdded<commit_msg>Add plural forms to remaining qsTr() calls<commit_after>import Qt 4.7
import MeeGo.Labs.Components 0.1 as Labs
import MeeGo.Components 0.1
import MeeGo.Media 0.1
import QtMultimediaKit 1.1
import MeeGo.App.Video.VideoPlugin 1.0
import MeeGo.Sharing 0.1
import MeeGo.Sharing.UI 0.1
import "functions.js" as Code

AppPage {
    id: landingPage
    anchors.fill: parent
    pageTitle: labelAppName
    property bool infocus: true
    property string videoSearch: ""
    property int videoListState: 0

    onActivated : {
        infocus = true;
        currentState.page = 0;
        window.disableToolBarSearch = false;
        fullScreen = false;
        window.lockOrientationIn = "noLock";
    }
    onDeactivated : { infocus = false; }

    Labs.ApplicationsModel {
        id: appsModel
        directories: [ "/usr/share/meego-ux-appgrid/applications", "/usr/share/applications", "~/.local/share/applications" ]
    }

    ModalDialog {
        id: deleteItemDialog
        title: labelDelete
        acceptButtonText: labelConfirmDelete
        cancelButtonText: labelCancel
        property variant payload
        onPayloadChanged:{
            contentItem.title = payload.mtitle;
        }
        onAccepted: {
            masterVideoModel.destroyItemByID(payload.mitemid);
        }
        content: Item {
            id: contentItem
            anchors.fill: parent
            property alias title : titleText.text
            clip: true
            Text{
                id: titleText
                text : qsTr("Video name")
                anchors.top: parent.top
                width:  parent.width
                horizontalAlignment: Text.AlignHCenter
            }
            Text {
                //: Confirmation message for deleting videos. "This" and "it" refer to list items, which represent videos on-screen.
                text: qsTr("If you delete this, it will be removed from your device")
                anchors.top:titleText.bottom
                width:  parent.width
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: theme_fontPixelSizeMedium
            }
        }
    }

    ModalDialog {
        id: deleteMultipleItemsDialog
        property int deletecount: 0
        //: text asking the user if the videos(s) is to deleted, warning them that it's permanent
        title: qsTr("Permanently delete these %n video(s)?", "", deletecount)
        acceptButtonText: labelConfirmDelete
        cancelButtonText:labelCancel
        onAccepted: {
            masterVideoModel.destroyItemsByID(masterVideoModel.getSelectedIDs());
            masterVideoModel.clearSelected();
            shareObj.clearItems();
            multiSelectMode = false;
        }
        content: Item {
            anchors.fill: parent
            clip: true
            Text {
                //: Confirmation message for deleting videos. "These" and "they" refer to list items, which represent videos on-screen.
                text: qsTr("If you delete these, they will be removed from your device")
                anchors.verticalCenter:parent.verticalCenter
                width:  parent.width
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: theme_fontPixelSizeMedium
            }
        }
    }

    Connections {
        target: window
        onSearch: {
            videoSearch = needle;
            landingView.opacity = 0;
            masterVideoModel.search = videoSearch;
            if(masterVideoModel.filter != VideoListModel.FilterSearch)
                masterVideoModel.filter = VideoListModel.FilterSearch
            window.actionMenuSelectedIndex = 0
            videoListState = (videoListState + 1)%2;
        }
    }

    function playvideo(payload)
    {
        targetState.set(1, "play", payload.muri, 0, -1);
        window.addPage(detailViewContent);
    }

    Connections {
        target: window
        onSetState: {
            if(infocus)
            {
                if(targetState.filter >= 0)
                    masterVideoModel.filter = targetState.filter;

                if((targetState.page == 1)&&(targetState.command != "")&&(targetState.uri != "")) // Goto DetailPage
                {
                    window.addPage(detailViewContent);
                }
            }
        }
    }

    ContextMenu {
        id: contextMenu
        property alias payload: contextActionMenu.payload
        property alias model: contextActionMenu.model
        property int mouseX
        property int mouseY
        content: ActionMenu {
            id: contextActionMenu
            property variant payload: undefined
            onTriggered: {
                shareObj.clearItems();
                if (model[index] == labelPlay)
                {
                    // Play
                    landingPage.playvideo(payload);
                    contextMenu.hide();
                }
                else if ((model[index] == labelFavorite)||(model[index] == labelUnFavorite))
                {
                    // Favorite/unfavorite
                    Code.changeItemFavorite(payload);
                    contextMenu.hide();
                }
                else if (model[index] == labelDelete)
                {
                    // Delete
                    deleteItemDialog.payload = payload;
                    deleteItemDialog.show();
                    contextMenu.hide();
                }
                else if (model[index] == labelMultiSelect)
                {
                    // multi select mode on
                    multiSelectMode = true;
                    contextMenu.hide();
                }
                else if (model[index] == labelcShare)
                {
                    // Share
                    shareObj.clearItems();
                    shareObj.addItem(payload.muri) // URI
                    shareObj.showContextTypes(contextMenu.mouseX, contextMenu.mouseY)
                }
            }
        }
    }
    Connections {
        target: masterVideoModel
        onTotalChanged: {
            topicAll = qsTr("All (%n video(s))", "", masterVideoModel.total);
            window.actionMenuModel = [topicAll, topicAdded, topicViewed, topicUnwatched, topicFavorites];
            window.actionMenuSelectedIndex = 0
        }
    }
    actionMenuModel: [topicAll, topicAdded, topicViewed, topicUnwatched, topicFavorites]
    actionMenuPayload: ["all", "added", "viewed", "unwatched", "favorites"]
    actionMenuHighlightSelection: true
    actionMenuSelectedIndex: 0
    onActionMenuTriggered: {
        selectView(selectedItem);
    }

    function selectView(selectedItem) {
        if (selectedItem == "all") {
            actionMenuSelectedIndex = 1
            landingView.opacity = 0;
            if(masterVideoModel.filter != VideoListModel.FilterAll)
            {
                masterVideoModel.filter = VideoListModel.FilterAll
                masterVideoModel.sort = VideoListModel.SortByTitle;
            }
        }else if(selectedItem == "added") {
            actionMenuSelectedIndex = 2
            landingView.opacity = 0;
            if(masterVideoModel.filter != VideoListModel.FilterAdded)
            {
                masterVideoModel.filter = VideoListModel.FilterAdded
{'fraction_non_alphanumeric': 0.08067824422261725, 'fraction_numerical': 0.0048543689320388345, 'mean_word_length': 1.6469417300036193, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '56936', 'n_tokens_mistral': 3785, 'n_tokens_neox': 3583, 'n_words': 807}