Commit 06cdd75e authored by Daniel Nicoletti's avatar Daniel Nicoletti
Browse files

Fixed regression due to the lack of browsing queues that system-config-printer had

BUG: 310200
parent ed3466f0
......@@ -43,6 +43,7 @@ kde4_add_executable(add-printer
target_link_libraries(add-printer
${KDE4_KDEUI_LIBS}
${QT_QTNETWORK_LIBRARY}
${KDE4_KIO_LIBS}
kcupslib
)
......
......@@ -34,12 +34,14 @@ ChooseUri::ChooseUri(QWidget *parent) :
{
ui->setupUi(this);
ui->searchTB->setIcon(KIcon("system-search"));
ui->searchTB->setIcon(KIcon("edit-find"));
// setup default options
setWindowTitle(i18nc("@title:window", "Select a Printer to Add"));
connect(ui->addressLE, SIGNAL(textChanged(QString)), this, SLOT(checkSelected()));
connect(ui->addressLE, SIGNAL(returnPressed()), this, SLOT(findPrinters()));
connect(ui->searchTB, SIGNAL(clicked()), this, SLOT(findPrinters()));
}
ChooseUri::~ChooseUri()
......@@ -50,27 +52,26 @@ ChooseUri::~ChooseUri()
void ChooseUri::setValues(const QVariantHash &args)
{
m_args = args;
bool visible = false;
KUrl url = args[KCUPS_DEVICE_URI].toString();
if (url.url() != QLatin1String("other") && url.isValid()) {
if (url.url() == QLatin1String("other")) {
ui->addressLE->clear();
visible = true;
} else if (url.protocol().isEmpty() && url.authority().isEmpty()) {
ui->addressLE->setText(url.url() % QLatin1String("://"));
} else {
ui->addressLE->clear();
ui->addressLE->setText(url.url());
}
ui->searchTB->setVisible(visible);
ui->addressLE->setFocus();
}
QVariantHash ChooseUri::values() const
{
QVariantHash ret = m_args;
// URI might be scsi, network on anything that doesn't match before
KUrl url(ui->addressLE->text());
if (url.protocol().isEmpty() && ret[KCUPS_DEVICE_URI].toString() != QLatin1String("other")) {
kDebug() << url;
url.setProtocol(ret[KCUPS_DEVICE_URI].toString());
kDebug() << url;
}
ret[KCUPS_DEVICE_URI] = url.url();
ret[KCUPS_DEVICE_URI] = parsedURL(ui->addressLE->text()).url();
return ret;
}
......@@ -78,7 +79,7 @@ bool ChooseUri::isValid() const
{
QVariantHash args = values();
KUrl url(args[KCUPS_DEVICE_URI].toString());
kDebug() << url << url.isValid() << url.isEmpty() << url.protocol().isEmpty() << url.hasHost();
//kDebug() << url << url.isValid() << url.isEmpty() << url.protocol().isEmpty() << url.hasHost();
return url.isValid() && !url.isEmpty() && !url.protocol().isEmpty() && url.hasHost();
}
......@@ -98,10 +99,102 @@ void ChooseUri::checkSelected()
void ChooseUri::on_addressLE_textChanged(const QString &text)
{
KUrl url(text);
if (url.isValid() && url.protocol().isEmpty()) {
KUrl url = parsedURL(text);
if (url.isValid() &&
(url.protocol().isEmpty() ||
url.protocol() == QLatin1String("http") ||
url.protocol() == QLatin1String("https") ||
url.protocol() == QLatin1String("ipp"))) {
// TODO maybe cups library can connect to more protocols
ui->searchTB->setEnabled(true);
} else {
ui->searchTB->setEnabled(false);
}
}
void ChooseUri::findPrinters()
{
KUrl url = parsedURL(ui->addressLE->text());
KCupsConnection *conn = new KCupsConnection(url, this);
KCupsRequest *request = new KCupsRequest(conn);
connect(request, SIGNAL(device(QString,QString,QString,QString,QString,QString)),
this, SLOT(gotDevice(QString,QString,QString,QString,QString,QString)));
connect(request, SIGNAL(finished()), this, SLOT(getPrintersFinished()));
QStringList attr;
attr << KCUPS_PRINTER_NAME;
attr << KCUPS_PRINTER_STATE;
attr << KCUPS_PRINTER_IS_SHARED;
attr << KCUPS_PRINTER_IS_ACCEPTING_JOBS;
attr << KCUPS_PRINTER_TYPE;
attr << KCUPS_PRINTER_LOCATION;
attr << KCUPS_PRINTER_INFO;
attr << KCUPS_PRINTER_MAKE_AND_MODEL;
request->setProperty("URI", url);
request->getPrinters(attr);
}
void ChooseUri::gotDevice(const QString &device_class, const QString &device_id, const QString &device_info, const QString &device_make_and_model, const QString &device_uri, const QString &device_location)
{
kDebug() << device_class;
// "MFG:Samsung;CMD:GDI;MDL:SCX-4200 Series;CLS:PRINTER;MODE:PCL;STATUS:IDLE;"
kDebug() << device_id;
// "Samsung SCX-4200 Series"
kDebug() << device_info;
// "Samsung SCX-4200 Series"
kDebug() << device_make_and_model;
// "usb://Samsung/SCX-4200%20Series"
kDebug() << device_uri;
// ""
kDebug() << device_location;
}
void ChooseUri::getPrintersFinished()
{
KCupsRequest *request = qobject_cast<KCupsRequest*>(sender());
KUrl url = request->property("URI").value<KUrl>();
QStringList uris;
foreach (const KCupsPrinter &printer, request->printers()) {
KUrl printerURI;
printerURI.setProtocol(QLatin1String("ipp"));
printerURI.setAuthority(url.authority());
printerURI.addPath(QLatin1String("printers/") % printer.name());
uris << printerURI.url();
}
emit insertDevice("network",
url.authority(),
url.authority(),
QString(),
url.url(),
QString(),
uris);
request->deleteLater();
request->connection()->deleteLater();
}
void ChooseUri::gotPPDFinished()
{
kDebug();
KCupsRequest *request = qobject_cast<KCupsRequest*>(sender());
kDebug() << request->printerPPD();
}
KUrl ChooseUri::parsedURL(const QString &text) const
{
KUrl url(text);
if (url.host().isEmpty() && !text.contains(QLatin1String("://"))) {
url = KUrl();
// URI might be scsi, network on anything that didn't match before
if (m_args[KCUPS_DEVICE_URI].toString() != QLatin1String("other")) {
url.setProtocol(m_args[KCUPS_DEVICE_URI].toString());
}
url.setAuthority(text);
}
return url;
}
......@@ -23,6 +23,8 @@
#include "GenericPage.h"
#include <KUrl>
namespace Ui {
class ChooseUri;
}
......@@ -41,11 +43,31 @@ public:
public slots:
void load();
signals:
void insertDevice(const QString &device_class,
const QString &device_id,
const QString &device_info,
const QString &device_make_and_model,
const QString &device_uri,
const QString &device_location,
const QStringList &grouped_uris);
private slots:
void checkSelected();
void on_addressLE_textChanged(const QString &text);
void findPrinters();
void gotDevice(const QString &device_class,
const QString &device_id,
const QString &device_info,
const QString &device_make_and_model,
const QString &device_uri,
const QString &device_location);
void getPrintersFinished();
void gotPPDFinished();
private:
KUrl parsedURL(const QString &text) const;
Ui::ChooseUri *ui;
};
......
......@@ -35,7 +35,7 @@
DevicesModel::DevicesModel(QObject *parent)
: QStandardItemModel(parent),
m_request(0),
m_rx("[a-z]+://?")
m_rx("[a-z]+://.*")
{
qDBusRegisterMetaType<MapSS>();
qDBusRegisterMetaType<MapSMapSS>();
......@@ -47,6 +47,14 @@ DevicesModel::DevicesModel(QObject *parent)
m_blacklistedURIs << QLatin1String("scsi");
m_blacklistedURIs << QLatin1String("http");
m_blacklistedURIs << QLatin1String("delete");
// Adds the other device which is meant for manual URI input
insertDevice("other",
QString(),
i18nc("@item", "Manual URI"),
QString(),
"other",
QString());
}
void DevicesModel::update()
......@@ -56,22 +64,16 @@ void DevicesModel::update()
}
// clear the model to don't duplicate items
clear();
if (rowCount()) {
removeRows(1, rowCount() - 1);
}
m_request = new KCupsRequest;
connect(m_request, SIGNAL(device(QString,QString,QString,QString,QString,QString)),
this, SLOT(gotDevice(QString,QString,QString,QString,QString,QString)));
connect(m_request, SIGNAL(finished()), this, SLOT(finished()));
// Get devices with 5 seconds of timeout
m_request->getDevices(5);
// Adds the other device which is meant for manual URI input
insertDevice("network",
QString(),
i18nc("@item", "Manual URI"),
QString(),
"other",
QString());
m_request->getDevices(10);
}
......@@ -178,11 +180,13 @@ void DevicesModel::insertDevice(const QString &device_class,
// just "http"
kind = OtherNetworked;
}
} else if (device_class == QLatin1String("other") &&
device_uri == QLatin1String("other")) {
kind = Other;
} else {
// If device class is not network assume local
kind = Local;
}
kDebug() << device_class << kind << device_uri;
QString location;
if (device_location.isEmpty() && kind == Local) {
......@@ -249,16 +253,19 @@ void DevicesModel::insertDevice(const QString &device_class,
switch (kind) {
case Networked:
catItem = findCreateCategory(i18nc("@item", "Discovered Network Printers"));
catItem->appendRow(stdItem);
break;
case OtherNetworked:
catItem = findCreateCategory(i18nc("@item", "Other Network Printers"));
catItem->appendRow(stdItem);
break;
default:
case Local:
catItem = findCreateCategory(i18nc("@item", "Local Printers"));
catItem->appendRow(stdItem);
break;
default:
appendRow(stdItem);
}
// Append the devie item to the row
catItem->appendRow(stdItem);
}
void DevicesModel::getGroupedDevicesSuccess(const QDBusMessage &message)
......
......@@ -45,7 +45,8 @@ public:
typedef enum {
Local,
Networked,
OtherNetworked
OtherNetworked,
Other
} Kind;
DevicesModel(QObject *parent = 0);
......@@ -57,6 +58,13 @@ signals:
public slots:
void update();
void insertDevice(const QString &device_class,
const QString &device_id,
const QString &device_info,
const QString &device_make_and_model,
const QString &device_uri,
const QString &device_location,
const QStringList &grouped_uris = QStringList());
private slots:
void gotDevice(const QString &device_class,
......@@ -66,13 +74,6 @@ private slots:
const QString &device_uri,
const QString &device_location);
void finished();
void insertDevice(const QString &device_class,
const QString &device_id,
const QString &device_info,
const QString &device_make_and_model,
const QString &device_uri,
const QString &device_location,
const QStringList &grouped_uris = QStringList());
void getGroupedDevicesSuccess(const QDBusMessage &message);
void getGroupedDevicesFailed(const QDBusError &error, const QDBusMessage &message);
void groupedDevicesFallback();
......
......@@ -25,13 +25,16 @@
#include <KCupsRequest.h>
#include <KTemporaryFile>
#include <QStringBuilder>
#include <KDebug>
PageChoosePPD::PageChoosePPD(const QVariantHash &args, QWidget *parent) :
GenericPage(parent),
ui(new Ui::PageChoosePPD),
m_isValid(false)
m_isValid(false),
m_ppdJob(0)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
......@@ -73,6 +76,29 @@ void PageChoosePPD::setValues(const QVariantHash &args)
QString makeAndModel = args[KCUPS_DEVICE_MAKE_AND_MODEL].toString();
QString deviceURI = args[KCUPS_DEVICE_URI].toString();
// If
KUrl url(deviceURI % QLatin1String(".ppd"));
if (url.protocol() == QLatin1String("ipp")) {
KTemporaryFile *tempFile = new KTemporaryFile;
tempFile->setPrefix("print-manager");
tempFile->setSuffix(".ppd");
tempFile->open();
if (m_ppdJob) {
m_ppdJob->deleteLater();
}
url.setProtocol(QLatin1String("http"));
if (url.port() < 0) {
url.setPort(631);
}
kDebug() << deviceURI << url;
m_ppdJob = KIO::file_copy(url,
tempFile->fileName(),
-1,
KIO::Overwrite | KIO::HideProgressInfo);
connect(m_ppdJob, SIGNAL(result(KJob*)),
this, SLOT(resultJob(KJob*)));
}
// Get the make from the device id
foreach (const QString &pair, deviceId.split(QLatin1Char(';'))) {
if (pair.startsWith(QLatin1String("MFG:"))) {
......@@ -123,7 +149,9 @@ QVariantHash PageChoosePPD::values() const
QVariantHash ret = m_args;
if (canProceed()) {
// TODO get the PPD file name
if (m_selectMM->isFileSelected()) {
if (m_ppdJob) {
ret[FILENAME] = m_ppdJob->destUrl().toLocalFile();
} else if (m_selectMM->isFileSelected()) {
ret[FILENAME] = m_selectMM->selectedPPDFileName();
} else {
ret[PPD_NAME] = m_selectMM->selectedPPDName();
......@@ -154,5 +182,12 @@ void PageChoosePPD::checkSelected()
void PageChoosePPD::selectDefault()
{
}
void PageChoosePPD::resultJob(KJob *job)
{
KIO::FileCopyJob *fJob = qobject_cast<KIO::FileCopyJob*>(job);
if (!fJob->error()) {
emit proceed();
}
}
......@@ -21,12 +21,13 @@
#ifndef PAGE_CHOOSE_PPD_H
#define PAGE_CHOOSE_PPD_H
#include <SelectMakeModel.h>
#include "GenericPage.h"
#include <SelectMakeModel.h>
#include <QStackedLayout>
#include <KIO/Job>
namespace Ui {
class PageChoosePPD;
}
......@@ -46,10 +47,12 @@ public:
private slots:
void checkSelected();
void selectDefault();
void resultJob(KJob *job);
private:
Ui::PageChoosePPD *ui;
bool m_isValid;
KIO::FileCopyJob *m_ppdJob;
SelectMakeModel *m_selectMM;
QStackedLayout *m_layout;
};
......
......@@ -64,6 +64,8 @@ PageDestinations::PageDestinations(const QVariantHash &args, QWidget *parent) :
ui->stackedWidget->addWidget(m_chooseUri);
connect(m_chooseUri, SIGNAL(allowProceed(bool)), SIGNAL(allowProceed(bool)));
connect(m_chooseUri, SIGNAL(insertDevice(QString,QString,QString,QString,QString,QString,QStringList)),
SLOT(insertDevice(QString,QString,QString,QString,QString,QString,QStringList)));
m_chooseLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->stackedWidget->addWidget(m_chooseLabel);
......@@ -178,6 +180,7 @@ void PageDestinations::deviceUriChanged()
// "beh" is excluded from the list
QString deviceUri = args[KCUPS_DEVICE_URI].toString();
kDebug() << deviceUri;
if (deviceUri.startsWith(QLatin1String("parallel"))) {
m_chooseLabel->setText(i18n("A printer connected to the parallel port."));
setCurrentPage(m_chooseLabel, args);
......@@ -249,6 +252,17 @@ void PageDestinations::deviceUriChanged()
emit allowProceed(canProceed());
}
void PageDestinations::insertDevice(const QString &device_class, const QString &device_id, const QString &device_info, const QString &device_make_and_model, const QString &device_uri, const QString &device_location, const QStringList &grouped_uris)
{
m_model->insertDevice(device_class,
device_id,
device_info,
device_make_and_model,
device_uri,
device_location,
grouped_uris);
}
QVariantHash PageDestinations::selectedItemValues() const
{
QVariantHash ret = m_args;
......
......@@ -53,6 +53,13 @@ public:
private slots:
void deviceChanged();
void deviceUriChanged();
void insertDevice(const QString &device_class,
const QString &device_id,
const QString &device_info,
const QString &device_make_and_model,
const QString &device_uri,
const QString &device_location,
const QStringList &grouped_uris);
private:
QString uriText(const QString &uri) const;
......
......@@ -293,7 +293,13 @@ void KCupsConnection::run()
// Check if we need an special connection
if (!m_serverUrl.isEmpty() && m_serverUrl.isValid()) {
// Connect to a special server
m_connection = httpConnectEncrypt(m_serverUrl.host().toUtf8(), m_serverUrl.port(), HTTP_ENCRYPT_IF_REQUESTED);
int port = m_serverUrl.port();
if (port < 0) {
// TODO find out if there's a better way of hardcoding
// the CUPS port
port = 631;
}
m_connection = httpConnectEncrypt(m_serverUrl.host().toUtf8(), port, HTTP_ENCRYPT_IF_REQUESTED);
}
// This is dead cool, cups will call the thread_password_cb()
......
......@@ -100,21 +100,40 @@ static void choose_device_cb(const char *device_class, /* I - Class */
}
void KCupsRequest::getDevices(int timeout)
{
getDevices(timeout, QStringList(), QStringList());
}
void KCupsRequest::getDevices(int timeout, QStringList includeSchemes, QStringList excludeSchemes)
{
if (m_connection->readyToStart()) {
do {
const char *include;
if (includeSchemes.isEmpty()) {
include = CUPS_INCLUDE_ALL;
} else {
include = includeSchemes.join(QLatin1String(",")).toUtf8();
}
const char *exclude;
if (excludeSchemes.isEmpty()) {
exclude = CUPS_EXCLUDE_NONE;
} else {
exclude = excludeSchemes.join(QLatin1String(",")).toUtf8();
}
// Scan for devices for "timeout" seconds
cupsGetDevices(m_connection->cupsConnection(),
timeout,
CUPS_INCLUDE_ALL,
CUPS_EXCLUDE_NONE,
include,
exclude,
(cups_device_cb_t) choose_device_cb,
this);
} while (m_connection->retry("/admin/"));
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished(true);
} else {
invokeMethod("getDevices", timeout);
invokeMethod("getDevices", timeout, includeSchemes, excludeSchemes);
}
}
......@@ -642,6 +661,11 @@ QString KCupsRequest::errorMsg() const
return m_errorMsg;
}
KCupsConnection *KCupsRequest::connection() const
{
return m_connection;
}
void KCupsRequest::setError(ipp_status_t error, const QString &errorMsg)
{
m_error = error;
......
......@@ -61,6 +61,8 @@ public:
QString serverError() const;
QString errorMsg() const;
KCupsConnection* connection() const;
/**
* Non empty when getPrinters is called and finish is emitted
*/
......@@ -97,7 +99,13 @@ public:
* Get all devices that could be added as a printer
* This method emits device()
*/
Q_INVOKABLE void getDevices(int timeout);
Q_INVOKABLE void getDevices(int timeout = CUPS_TIMEOUT_DEFAULT);
/**
* Get all devices that could be added as a printer
* This method emits device()
*/
Q_INVOKABLE void getDevices(int timeout, QStringList includeSchemes, QStringList excludeSchemes);
/**
* Get all available printers
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment