File indexing completed on 2025-01-19 05:06:21
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 "AddPrinter.h" 0008 0009 #include "AddPrinterAssistant.h" 0010 0011 #include <KCupsRequest.h> 0012 #include <KWindowSystem> 0013 #include <KX11Extras> 0014 0015 #include <QLoggingCategory> 0016 #include <QPointer> 0017 0018 Q_DECLARE_LOGGING_CATEGORY(PM_ADD_PRINTER) 0019 0020 AddPrinter::AddPrinter(int &argc, char **argv) 0021 : QApplication(argc, argv) 0022 { 0023 setQuitOnLastWindowClosed(true); 0024 } 0025 0026 AddPrinter::~AddPrinter() 0027 { 0028 } 0029 0030 void AddPrinter::addPrinter(qulonglong wid) 0031 { 0032 auto wizard = new AddPrinterAssistant(); 0033 wizard->initAddPrinter(); 0034 show(wizard, wid); 0035 } 0036 0037 void AddPrinter::addClass(qulonglong wid) 0038 { 0039 auto wizard = new AddPrinterAssistant(); 0040 wizard->initAddClass(); 0041 show(wizard, wid); 0042 } 0043 0044 void AddPrinter::changePPD(qulonglong wid, const QString &name) 0045 { 0046 // Fist we need to get the printer attributes 0047 QPointer<KCupsRequest> request = new KCupsRequest; 0048 const QStringList attr({KCUPS_PRINTER_TYPE, // needed to know if it's a remote printer 0049 KCUPS_PRINTER_MAKE_AND_MODEL, 0050 KCUPS_DEVICE_URI}); 0051 request->getPrinterAttributes(name, false, attr); 0052 request->waitTillFinished(); 0053 if (request) { 0054 if (!request->hasError() && request->printers().size() == 1) { 0055 const KCupsPrinter printer = request->printers().first(); 0056 if (printer.type() & CUPS_PRINTER_REMOTE) { 0057 qCWarning(PM_ADD_PRINTER) << "Ignoring request, can not change PPD of remote printer" << name; 0058 } else { 0059 auto wizard = new AddPrinterAssistant(); 0060 wizard->initChangePPD(name, printer.deviceUri(), printer.makeAndModel()); 0061 show(wizard, wid); 0062 } 0063 } else { 0064 qWarning() << "Ignoring request, printer not found" << name << request->errorMsg(); 0065 } 0066 request->deleteLater(); 0067 } 0068 } 0069 0070 void AddPrinter::newPrinterFromDevice(qulonglong wid, const QString &name, const QString &device_id) 0071 { 0072 // Example of data 0073 // "direct" 0074 // "MFG:Samsung;CMD:GDI;MDL:SCX-4200 Series;CLS:PRINTER;MODE:PCL;STATUS:IDLE;" 0075 // "Samsung SCX-4200 Series" 0076 // "Samsung SCX-4200 Series" 0077 // "usb://Samsung/SCX-4200%20Series" 0078 // "" 0079 0080 // printer = "Samsung SCX-3400 Series"; 0081 // deviceId = "MFG:Samsung;CMD:SPL,FWV,PIC,BDN,EXT;MDL:SCX-3400 Series;CLS:PRINTER;MODE:SCN,SPL3,R000105;STATUS:BUSY;"; 0082 0083 // printer = "Samsung SCX-4200 Series"; 0084 // deviceId = "MFG:Samsung;CMD:GDI;MDL:SCX-4200 Series;CLS:PRINTER;MODE:PCL;STATUS:IDLE;"; 0085 0086 // printer = "HP PSC 1400 series"; 0087 // deviceId = "MFG:HP;MDL:PSC 1400 series;DES:;CMD:LDL,MLC,PML,DYN;"; 0088 0089 auto wizard = new AddPrinterAssistant(); 0090 wizard->initAddPrinter(name, device_id); 0091 show(wizard, wid); 0092 } 0093 0094 void AddPrinter::show(QWidget *widget, qulonglong wid) const 0095 { 0096 widget->show(); 0097 if (KWindowSystem::isPlatformX11()) { 0098 KX11Extras::forceActiveWindow(widget->winId()); 0099 } 0100 widget->setAttribute(Qt::WA_NativeWindow, true); 0101 KWindowSystem::setMainWindow(widget->windowHandle(), wid); 0102 } 0103 0104 #include "moc_AddPrinter.cpp"