import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.3

Page {
    id: mainList

    PageHeader {
        id: header
        width: parent.width
        title: "Select the webapp to unify"
    }
    SilicaGridView {
        anchors.top: header.bottom
        width: parent.width
        height: parent.height
        cellWidth: width / 4
        cellHeight: cellWidth

        model: ListModel {
            id: appsList
        }

        delegate: GridItem {
            menu: Component {
                ContextMenu {
                    MenuItem {
                        text: attrs.Name
                    }
                }
            }

            Image {
                anchors.centerIn: parent
                source: attrs.Icon
            }

            onClicked: {
                pageStack.push(Qt.resolvedUrl("Icon.qml"), {attrs: attrs});
            }
        }
    }

    Python {
        id: py
        Component.onCompleted: {
            py.addImportPath(Qt.resolvedUrl("../src"));
            py.importModule("main", function(){
                py.call("main.get_web_icons", [], function(apps){
                    for(var i=0; i < apps.length; i++){
                        appsList.append({attrs: apps[i]});
                    }
                })
            })
        }
    }
}