Warning, file /utilities/print-manager/add-printer/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2010 Daniel Nicoletti <dantti12@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "AddPrinter.h"
0008 
0009 #include <config.h>
0010 
0011 #include <QCommandLineParser>
0012 #include <QCommandLineOption>
0013 
0014 #include <QLoggingCategory>
0015 
0016 #include <KLocalizedString>
0017 #include <KAboutData>
0018 
0019 Q_LOGGING_CATEGORY(PM_ADD_PRINTER, "pm.add.printer")
0020 
0021 int main(int argc, char **argv)
0022 {
0023     QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0024     AddPrinter app(argc, argv);
0025     app.setOrganizationDomain(QLatin1String("org.kde"));
0026 
0027     KAboutData about(QLatin1String("kde-add-printer"),
0028                      i18n("Add Printer"),
0029                      QLatin1String(PM_VERSION),
0030                      i18n("Tool for adding new printers"),
0031                      KAboutLicense::GPL,
0032                      i18n("(C) 2010-2018 Daniel Nicoletti"));
0033 
0034     about.addAuthor(QLatin1String("Daniel Nicoletti"), QString(), QLatin1String("dantti12@gmail.com"));
0035     about.addAuthor(QStringLiteral("Lukáš Tinkl"), i18n("Port to Qt 5 / Plasma 5"), QStringLiteral("ltinkl@redhat.com"));
0036     KAboutData::setApplicationData(about);
0037 
0038     QCommandLineParser parser;
0039     about.setupCommandLine(&parser);
0040 
0041     QCommandLineOption parentWindowOpt({QLatin1String("w"), QLatin1String("parent-window")}, i18n("Parent Window ID"), QLatin1String("wid"));
0042     parser.addOption(parentWindowOpt);
0043 
0044     QCommandLineOption addPrinterOpt(QLatin1String("add-printer"), i18n("Add a new printer"));
0045     parser.addOption(addPrinterOpt);
0046 
0047     QCommandLineOption addClassOpt(QLatin1String("add-class"), i18n("Add a new printer class"));
0048     parser.addOption(addClassOpt);
0049 
0050     QCommandLineOption changePpdOpt(QLatin1String("change-ppd"), i18n("Changes the PPD of a given printer"), QLatin1String("printer-name"));
0051     parser.addOption(changePpdOpt);
0052 
0053     QCommandLineOption newPrinterDevOpt(QLatin1String("new-printer-from-device"), i18n("Changes the PPD of a given printer/deviceid"),
0054                                         QLatin1String("printername/deviceid"));
0055     parser.addOption(newPrinterDevOpt);
0056 
0057     parser.process(app);
0058     about.processCommandLine(&parser);
0059 
0060     qulonglong wid = 0;
0061     if (parser.isSet(parentWindowOpt)) {
0062         wid = parser.value(parentWindowOpt).toULongLong();
0063     }
0064 
0065     if (parser.isSet(addPrinterOpt)) {
0066         app.addPrinter(wid);
0067     } else if (parser.isSet(addClassOpt)) {
0068         app.addClass(wid);
0069     } else if (parser.isSet(changePpdOpt)) {
0070         app.changePPD(wid, parser.value(changePpdOpt));
0071     } else if (parser.isSet(newPrinterDevOpt)) {
0072         const QString value = parser.value(newPrinterDevOpt);
0073         const QStringList values = value.split(QLatin1String("/"));
0074         if (values.size() == 2) {
0075             app.newPrinterFromDevice(wid, values.first(), values.last());
0076         } else {
0077             qWarning() << "The expected input should be printer/deviceid";
0078             exit(EXIT_FAILURE);
0079         }
0080     } else {
0081         parser.showHelp(EXIT_FAILURE);
0082     }
0083 
0084     return app.exec();
0085 }