~dobey/ubuntu-printing-app/add-notifier-daemon

« back to all changes in this revision

Viewing changes to ubuntu-printing-app/components/PrintingHelper.qml

  • Committer: Rodney Dawes
  • Date: 2017-03-17 17:55:52 UTC
  • mfrom: (23.2.3 ubuntu-printing-app)
  • Revision ID: rodney.dawes@canonical.com-20170317175552-267wu0f58hf7mzbz
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19
19
 */
20
20
import QtQuick 2.4
21
 
import Ubuntu_Printing_App 1.0
22
 
import Ubuntu.Settings.Printers 0.1
23
 
 
24
 
QtObject {
25
 
    readonly property var model: Printers.allPrintersWithPdf
26
 
    readonly property bool pdfMode: printer ? printer.isPdf : true
27
 
    readonly property var printer: {
28
 
        if (Printers.allPrintersWithPdf.count > 0
29
 
                && 0 <= printerSelectedIndex
30
 
                && printerSelectedIndex < Printers.allPrintersWithPdf.count) {
31
 
            Printers.allPrintersWithPdf.get(printerSelectedIndex)
32
 
        } else {
33
 
            null
34
 
        }
35
 
    }
36
 
    readonly property PrinterJob printerJob: PrinterJob {
37
 
        printerName: printer ? printer.name : ""
38
 
    }
 
21
import QtQml 2.2
 
22
import UbuntuPrintingApp 1.0
 
23
import Ubuntu.Components.Extras.Printers 0.1
 
24
 
 
25
Item {
 
26
    readonly property bool isEditable: isLoaded && !pdfMode && !printer.isRaw
 
27
    readonly property bool isLoaded: printer && printer.isLoaded
 
28
    readonly property alias model: instantiator.model
 
29
    readonly property bool pdfMode: isLoaded && printer.isPdf
 
30
 
 
31
    // This is the current printer and is preloaded
 
32
    readonly property var printer: instantiator.printer && instantiator.printer.isLoaded ? instantiator.printer : null
 
33
 
 
34
    property var printerJob: Printers.createJob("")
39
35
    property int printerSelectedIndex: -1
 
36
 
 
37
    Instantiator {
 
38
        id: instantiator
 
39
        model: Printers.allPrintersWithPdf
 
40
        delegate: Item {
 
41
            readonly property var printer: model
 
42
        }
 
43
 
 
44
        // Extract the printer from the Instantiator so we can use it
 
45
        // this printer may not be loaded yet
 
46
        readonly property var printer: {
 
47
            if (model.count > 0
 
48
                    && 0 <= printerSelectedIndex
 
49
                    && printerSelectedIndex < model.count) {
 
50
                instantiator.objectAt(printerSelectedIndex).printer
 
51
            } else {
 
52
                null
 
53
            }
 
54
        }
 
55
 
 
56
        // The information about the Printer is lazy loaded, this requests
 
57
        // the loading of a Printer's information
 
58
        function loadPrinter() {
 
59
            if (printer) {
 
60
                Printers.loadPrinter(printer.name)
 
61
            }
 
62
        }
 
63
 
 
64
        onPrinterChanged: loadPrinter()
 
65
 
 
66
        Component.onCompleted: loadPrinter()
 
67
    }
 
68
 
 
69
    Binding {
 
70
        property: "printer"
 
71
        target: printerJob
 
72
        when: printer && isLoaded
 
73
        value: printer ? printer.printer : null
 
74
    }
40
75
}