File indexing completed on 2025-01-05 05:09:30
0001 /* 0002 SPDX-FileCopyrightText: 2010-2018 Daniel Nicoletti <dantti12@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KCupsPrinter.h" 0008 0009 KCupsPrinter::KCupsPrinter() 0010 : m_isClass(false) 0011 { 0012 } 0013 0014 KCupsPrinter::KCupsPrinter(const QString &printer, bool isClass) 0015 : m_printer(printer) 0016 , m_isClass(isClass) 0017 { 0018 } 0019 0020 KCupsPrinter::KCupsPrinter(const QVariantMap &arguments) 0021 : m_printer(arguments[QLatin1String(KCUPS_PRINTER_NAME)].toString()) 0022 , m_isClass(arguments[QLatin1String(KCUPS_PRINTER_TYPE)].toInt() & CUPS_PRINTER_CLASS) 0023 , m_arguments(arguments) 0024 { 0025 } 0026 0027 QString KCupsPrinter::name() const 0028 { 0029 return m_printer; 0030 } 0031 0032 bool KCupsPrinter::isClass() const 0033 { 0034 return m_isClass; 0035 } 0036 0037 bool KCupsPrinter::isDefault() const 0038 { 0039 return m_arguments[QLatin1String(KCUPS_PRINTER_TYPE)].toUInt() & CUPS_PRINTER_DEFAULT; 0040 } 0041 0042 bool KCupsPrinter::isShared() const 0043 { 0044 return m_arguments[QLatin1String(KCUPS_PRINTER_IS_SHARED)].toBool(); 0045 } 0046 0047 bool KCupsPrinter::isAcceptingJobs() const 0048 { 0049 return m_arguments[QLatin1String(KCUPS_PRINTER_IS_ACCEPTING_JOBS)].toBool(); 0050 } 0051 0052 cups_ptype_e KCupsPrinter::type() const 0053 { 0054 return static_cast<cups_ptype_e>(m_arguments[QLatin1String(KCUPS_PRINTER_TYPE)].toUInt()); 0055 } 0056 0057 QString KCupsPrinter::location() const 0058 { 0059 return m_arguments[QLatin1String(KCUPS_PRINTER_LOCATION)].toString(); 0060 } 0061 0062 QString KCupsPrinter::info() const 0063 { 0064 const QString printerInfo = m_arguments[QLatin1String(KCUPS_PRINTER_INFO)].toString(); 0065 if (printerInfo.isEmpty()) { 0066 return name(); 0067 } 0068 return printerInfo; 0069 } 0070 0071 QString KCupsPrinter::makeAndModel() const 0072 { 0073 return m_arguments[QLatin1String(KCUPS_PRINTER_MAKE_AND_MODEL)].toString(); 0074 } 0075 0076 QStringList KCupsPrinter::commands() const 0077 { 0078 return m_arguments[QLatin1String(KCUPS_PRINTER_COMMANDS)].toStringList(); 0079 } 0080 0081 QStringList KCupsPrinter::memberNames() const 0082 { 0083 return m_arguments[QLatin1String(KCUPS_MEMBER_NAMES)].toStringList(); 0084 } 0085 0086 QString KCupsPrinter::deviceUri() const 0087 { 0088 return m_arguments[QLatin1String(KCUPS_DEVICE_URI)].toString(); 0089 } 0090 0091 QStringList KCupsPrinter::errorPolicy() const 0092 { 0093 return m_arguments[QLatin1String(KCUPS_PRINTER_ERROR_POLICY)].toStringList(); 0094 } 0095 0096 QStringList KCupsPrinter::errorPolicySupported() const 0097 { 0098 return m_arguments[QLatin1String(KCUPS_PRINTER_ERROR_POLICY_SUPPORTED)].toStringList(); 0099 } 0100 0101 QStringList KCupsPrinter::opPolicy() const 0102 { 0103 return m_arguments[QLatin1String(KCUPS_PRINTER_OP_POLICY)].toStringList(); 0104 } 0105 0106 QStringList KCupsPrinter::opPolicySupported() const 0107 { 0108 return m_arguments[QLatin1String(KCUPS_PRINTER_OP_POLICY_SUPPORTED)].toStringList(); 0109 } 0110 0111 QStringList KCupsPrinter::jobSheetsDefault() const 0112 { 0113 return m_arguments[QLatin1String(KCUPS_JOB_SHEETS_DEFAULT)].toStringList(); 0114 } 0115 0116 QStringList KCupsPrinter::jobSheetsSupported() const 0117 { 0118 return m_arguments[QLatin1String(KCUPS_JOB_SHEETS_SUPPORTED)].toStringList(); 0119 } 0120 0121 QStringList KCupsPrinter::requestingUserNameAllowed() const 0122 { 0123 return m_arguments[QLatin1String(KCUPS_REQUESTING_USER_NAME_ALLOWED)].toStringList(); 0124 } 0125 0126 QStringList KCupsPrinter::requestingUserNameDenied() const 0127 { 0128 return m_arguments[QLatin1String(KCUPS_REQUESTING_USER_NAME_DENIED)].toStringList(); 0129 } 0130 0131 QStringList KCupsPrinter::authInfoRequired() const 0132 { 0133 return m_arguments[QLatin1String(KCUPS_AUTH_INFO_REQUIRED)].toStringList(); 0134 } 0135 0136 QString KCupsPrinter::uriSupported() const 0137 { 0138 return m_arguments[QLatin1String(KCUPS_PRINTER_URI_SUPPORTED)].toString(); 0139 } 0140 0141 KCupsPrinter::Status KCupsPrinter::state() const 0142 { 0143 return static_cast<Status>(m_arguments[QLatin1String(KCUPS_PRINTER_STATE)].toUInt()); 0144 } 0145 0146 QString KCupsPrinter::stateMsg() const 0147 { 0148 return m_arguments[QLatin1String(KCUPS_PRINTER_STATE_MESSAGE)].toString(); 0149 } 0150 0151 int KCupsPrinter::markerChangeTime() const 0152 { 0153 return m_arguments[QLatin1String(KCUPS_MARKER_CHANGE_TIME)].toInt(); 0154 } 0155 0156 QVariant KCupsPrinter::argument(const QString &name) const 0157 { 0158 return m_arguments.value(name); 0159 } 0160 0161 QIcon KCupsPrinter::icon() const 0162 { 0163 return icon(type()); 0164 } 0165 0166 QIcon KCupsPrinter::icon(cups_ptype_e type) 0167 { 0168 return QIcon::fromTheme(iconName(type)); 0169 } 0170 0171 QString KCupsPrinter::iconName() const 0172 { 0173 return iconName(type()); 0174 } 0175 0176 QString KCupsPrinter::iconName(cups_ptype_e type) 0177 { 0178 // TODO get the ppd or something to get the real printer icon 0179 if (!(type & CUPS_PRINTER_COLOR)) { 0180 // If the printer is not color it is probably a laser one 0181 return QStringLiteral("printer-laser"); 0182 } else if (type & CUPS_PRINTER_SCANNER) { 0183 return QStringLiteral("scanner"); 0184 } else { 0185 return QStringLiteral("printer"); 0186 } 0187 }