Warning, /plasma/print-manager/src/plasmoid/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2012-2013 Daniel Nicoletti <dantti12@gmail.com> 0003 SPDX-FileCopyrightText: 2014 Jan Grulich <jgrulich@redhat.com> 0004 SPDX-FileCopyrightText: 2021 Nate Graham <nate@kde.org> 0005 SPDX-FileCopyrightText: 2023 Mike Noe <noeerover@gmail.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 import QtQuick 0011 import QtQuick.Layouts // fullRepresentation sizing 0012 import org.kde.plasma.plasmoid 0013 import org.kde.plasma.core as PlasmaCore 0014 import org.kde.kirigami as Kirigami 0015 import org.kde.config // KAuthorized 0016 import org.kde.kcmutils // KCMLauncher 0017 import org.kde.plasma.printmanager as PrintManager 0018 0019 PlasmoidItem { 0020 0021 property bool cfg_allJobs 0022 property bool cfg_completedJobs 0023 property bool cfg_activeJobs 0024 0025 readonly property bool inPanel: (Plasmoid.location === PlasmaCore.Types.TopEdge 0026 || Plasmoid.location === PlasmaCore.Types.RightEdge 0027 || Plasmoid.location === PlasmaCore.Types.BottomEdge 0028 || Plasmoid.location === PlasmaCore.Types.LeftEdge) 0029 0030 property alias serverUnavailable: printersModel.serverUnavailable 0031 property string printersModelError: "" 0032 0033 property int jobsFilter: Plasmoid.configuration.allJobs 0034 ? PrintManager.JobModel.WhichAll 0035 : Plasmoid.configuration.completedJobs 0036 ? PrintManager.JobModel.WhichCompleted 0037 : PrintManager.JobModel.WhichActive 0038 0039 onJobsFilterChanged: jobsModel.setWhichJobs(jobsFilter) 0040 0041 PrintManager.PrinterModel { 0042 id: printersModel 0043 onError: (lastError, errorTitle, errorMsg) => { 0044 printersModelError = errorTitle; 0045 } 0046 } 0047 0048 PrintManager.JobSortFilterModel { 0049 id: jobsFilterModel 0050 0051 sourceModel: PrintManager.JobModel { 0052 id: jobsModel 0053 Component.onCompleted: setWhichJobs(jobsFilter) 0054 } 0055 } 0056 0057 PrintManager.JobSortFilterModel { 0058 id: activeJobsFilterModel 0059 0060 sourceModel: PrintManager.JobModel { 0061 Component.onCompleted: setWhichJobs(PrintManager.JobModel.WhichActive) 0062 } 0063 } 0064 0065 toolTipMainText: i18n("Printers") 0066 toolTipSubText: { 0067 if (serverUnavailable && printersModelError) { 0068 return printersModelError; 0069 } else if (activeJobsFilterModel.activeCount > 1) { 0070 return i18np("There is one print job in the queue", 0071 "There are %1 print jobs in the queue", 0072 activeJobsFilterModel.activeCount); 0073 // If there is only one job, show more information about it 0074 } else if (activeJobsFilterModel.activeCount === 1) { 0075 const idx = activeJobsFilterModel.index(0, 0); 0076 const jobName = activeJobsFilterModel.data(idx, PrintManager.JobModel.RoleJobName); 0077 const printerName = activeJobsFilterModel.data(idx, PrintManager.JobModel.RoleJobPrinter); 0078 if (jobName) { 0079 return i18nc("Printing document name with printer name", "Printing %1 with %2", jobName, printerName); 0080 } else { 0081 return printerName === "" ? "" : i18nc("Printing with printer name", "Printing with %1", printerName); 0082 } 0083 } else if (printersModel.count > 0) { 0084 return i18n("Print queue is empty"); 0085 } else { 0086 return i18n("No printers have been configured or discovered"); 0087 } 0088 } 0089 0090 Plasmoid.icon: inPanel ? "printer-symbolic" : "printer" 0091 0092 fullRepresentation: FullRepresentation { 0093 focus: true 0094 // as a desktop widget, we need to start with a reasonable size 0095 Layout.preferredWidth: inPanel ? -1 : Kirigami.Units.gridUnit * 24 0096 Layout.preferredHeight: inPanel ? -1 : Kirigami.Units.gridUnit * 24 0097 } 0098 0099 switchWidth: Kirigami.Units.gridUnit * 10 0100 switchHeight: Kirigami.Units.gridUnit * 10 0101 0102 Plasmoid.status: { 0103 if (activeJobsFilterModel.activeCount > 0) { 0104 return PlasmaCore.Types.ActiveStatus; 0105 } else if (printersModel.count > 0 || serverUnavailable) { 0106 return PlasmaCore.Types.PassiveStatus; 0107 } else { 0108 return PlasmaCore.Types.HiddenStatus; 0109 } 0110 } 0111 0112 Plasmoid.contextualActions: [ 0113 PlasmaCore.Action { 0114 text: i18n("Show All Jobs") 0115 icon.name: "view-list-details" 0116 checkable: true 0117 checked: Plasmoid.configuration.allJobs 0118 onTriggered: { 0119 Plasmoid.configuration.allJobs = true; 0120 Plasmoid.configuration.completedJobs = false; 0121 Plasmoid.configuration.activeJobs = false; 0122 } 0123 }, 0124 PlasmaCore.Action { 0125 text: i18n("Show Only Completed Jobs") 0126 icon.name: "task-complete" 0127 checkable: true 0128 checked: Plasmoid.configuration.completedJobs 0129 onTriggered: { 0130 Plasmoid.configuration.allJobs = false; 0131 Plasmoid.configuration.completedJobs = true; 0132 Plasmoid.configuration.activeJobs = false; 0133 } 0134 }, 0135 PlasmaCore.Action { 0136 text: i18n("Show Only Active Jobs") 0137 icon.name: "task-recurring" 0138 checkable: true 0139 checked: Plasmoid.configuration.activeJobs 0140 onTriggered: { 0141 Plasmoid.configuration.allJobs = false; 0142 Plasmoid.configuration.completedJobs = false; 0143 Plasmoid.configuration.activeJobs = true; 0144 } 0145 }, 0146 PlasmaCore.Action { 0147 isSeparator: true 0148 } 0149 ] 0150 0151 // Overwrite default configure menu item 0152 PlasmaCore.Action { 0153 id: configAction 0154 text: i18n("&Configure Printers…") 0155 icon.name: "configure" 0156 shortcut: "alt+d,s" 0157 enabled: KAuthorized.authorizeControlModule("kcm_printer_manager") 0158 onTriggered: KCMLauncher.openSystemSettings("kcm_printer_manager") 0159 } 0160 0161 Component.onCompleted: Plasmoid.setInternalAction("configure", configAction) 0162 }