File indexing completed on 2022-09-27 16:37:09

0001 /*
0002     SPDX-FileCopyrightText: 2010 Daniel Nicoletti <dantti12@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "ChooseSocket.h"
0008 #include "ui_ChooseSocket.h"
0009 
0010 #include <KCupsRequest.h>
0011 #include <KLocalizedString>
0012 
0013 #include <QPainter>
0014 #include <QUrl>
0015 
0016 ChooseSocket::ChooseSocket(QWidget *parent) :
0017     GenericPage(parent),
0018     ui(new Ui::ChooseSocket)
0019 {
0020     ui->setupUi(this);
0021 
0022     // setup default options
0023     setWindowTitle(i18nc("@title:window", "Select a Printer to Add"));
0024 }
0025 
0026 ChooseSocket::~ChooseSocket()
0027 {
0028     delete ui;
0029 }
0030 
0031 void ChooseSocket::setValues(const QVariantHash &args)
0032 {
0033     if (m_args == args) {
0034         return;
0035     }
0036 
0037     m_args = args;
0038     ui->addressLE->clear();
0039     ui->portISB->setValue(9100);
0040     const QString deviceUri = args[KCUPS_DEVICE_URI].toString();
0041     QUrl url(deviceUri);
0042     if (url.scheme() == QLatin1String("socket")) {
0043         ui->addressLE->setText(url.host());
0044         ui->portISB->setValue(url.port(9100));
0045     }
0046     ui->addressLE->setFocus();
0047 
0048     m_isValid = true;
0049 }
0050 
0051 QVariantHash ChooseSocket::values() const
0052 {
0053     QVariantHash ret = m_args;
0054     QUrl url = QUrl(QLatin1String("socket://") + ui->addressLE->text());
0055     url.setPort(ui->portISB->value());
0056     ret[KCUPS_DEVICE_URI] = url.toDisplayString();
0057     return ret;
0058 }
0059 
0060 bool ChooseSocket::isValid() const
0061 {
0062     return m_isValid;
0063 }
0064 
0065 bool ChooseSocket::canProceed() const
0066 {
0067     return !ui->addressLE->text().isEmpty();
0068 }
0069 
0070 void ChooseSocket::on_addressLE_textChanged(const QString &text)
0071 {
0072     Q_UNUSED(text)
0073     Q_EMIT allowProceed(canProceed());
0074 }
0075 
0076 #include "moc_ChooseSocket.cpp"