File: PageComponent.qml

package info (click to toggle)
lomiri-system-settings 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,484 kB
  • sloc: cpp: 15,892; python: 5,994; xml: 362; javascript: 80; makefile: 46; sh: 5
file content (206 lines) | stat: -rw-r--r-- 6,672 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * This file is part of system-settings
 *
 * Copyright (C) 2017 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by Jonas G. Drange <jonas.drange@canonical.com>
 */

import QtQuick 2.12
import SystemSettings 1.0
import Lomiri.Components 1.3
import Lomiri.Components.Extras.Printers 0.1

ItemPage {
    id: root
    objectName: "printingPage"

    header: PageHeader {
        id: printerHeader
        title: i18n.tr("Printing")
        flickable: printerList
        trailingActionBar {
            actions: [
                Action {
                    iconName: "add"
                    text: i18n.tr("Add printer")
                    onTriggered: pageStack.addPageToNextColumn(root, Qt.resolvedUrl("AddPrinter.qml"), {
                        plugin: plugin
                    })
                },
                Action {
                    iconName: "document-print"
                    text: i18n.tr("Manager Printer Jobs")
                    onTriggered: Qt.openUrlExternally("printing:///queue")
                }
            ]
        }
    }

    onPushedOntoStack: {
        var page;
        var opts = {
            plugin: plugin,
            pluginManager: pluginManager,
            pluginOptions: pluginOptions,
        };
        if (pluginOptions && pluginOptions['subpage']) {
            switch (pluginOptions['subpage']) {
            case 'add-printer':
                page = Qt.resolvedUrl("AddPrinter.qml");
                break;
            case 'view-printer':
                var printerName = pluginOptions['name'];
                if (printerName) {
                    Printers.loadPrinter(printerName);
                    for (var i = 0; i < allPrintersList.count; i++) {
                        if (printerName == Printers.allPrinters.get(i).name) {
                            allPrintersList.currentIndex = i;
                            allPrintersList.currentItem.clicked();
                            break;
                        }
                    }
                }
                break;
            }
        }
        if (page) {
            pageStack.addPageToNextColumn(root, page, opts);
        }
    }

    Flickable {
        id: printerList
        anchors.fill: parent
        contentHeight: contentItem.childrenRect.height
        clip: true

        Column {
            anchors {
                left: parent.left
                right: parent.right
            }

            ListView {
                id: allPrintersList
                anchors { left: parent.left; right: parent.right }
                contentHeight: contentItem.childrenRect.height
                boundsBehavior: Flickable.StopAtBounds
                height: contentHeight
                model: Printers.localPrinters

                section.property: "default"
                section.delegate: SettingsItemTitle {
                    text: section === "true" ? i18n.tr("Default printer")
                                             : i18n.tr("Configured printers")
                }

                delegate: printerDelegate
            }

            SettingsItemTitle {
                anchors { left: parent.left; right: parent.right }
                text: i18n.tr("Discovered printers")
                visible: discoveredPrintersRepeater.count
            }

            Repeater {
                id: discoveredPrintersRepeater
                anchors { left: parent.left; right: parent.right }
                model: Printers.remotePrinters
                delegate: printerDelegate
            }
        }
    }

    Component {
        id: printerDelegate

        ListItem {
            height: modelLayout.height + (divider.visible ? divider.height : 0)
            leadingActions: ListItemActions {
                actions: [
                    Action {
                        text: i18n.tr("Delete")
                        iconName: "delete"
                        onTriggered: {
                            if (!Printers.removePrinter(model.name)) {
                                console.error('failed to remove printer', Printers.lastMessage);
                            }
                        }
                    }
                ]
            }

            trailingActions: ListItemActions {
               actions: Action {
                   text: i18n.tr("Set as Default")
                   iconName: model.default ? "starred" : "non-starred"
                   enabled: !model.default && !isRemote
                   onTriggered: Printers.defaultPrinterName = model.name
               }
            }

            ListItemLayout {
                id: modelLayout
                title.text: displayName
                anchors { left: parent.left; right: parent.right }

                Icon {
                    id: icon
                    width: height
                    height: units.gu(2.5)
                    name: printerEnabled ? "printer-symbolic" : "media-playback-pause"
                    SlotsLayout.position: SlotsLayout.First
                }

                ProgressionSlot {}
            }
            onClicked: {
                Printers.loadPrinter(model.name);
                pageStack.addPageToNextColumn(root, Qt.resolvedUrl("Printer.qml"), {
                    printer: model, pluginOptions: pluginOptions,
                    plugin: plugin
                });
            }
        }
    }

    Item {
        visible: allPrintersList.count == 0
        z: 1

        anchors.fill: parent

        Label {
            id: noPrintersLabel
            anchors.centerIn: parent
            text: i18n.tr("There are no printers configured yet.")
            color: theme.palette.normal.baseText
        }

        Icon {
            anchors {
                horizontalCenter: parent.horizontalCenter
                top: noPrintersLabel.bottom
                topMargin: units.gu(2)
            }
            name: "printer-symbolic"
            height: units.gu(6)
            width: height
            color: theme.palette.normal.base
        }
    }
}