Commit 0c0bce67 authored by Daniel Nicoletti's avatar Daniel Nicoletti

Get rid of slow sender() calls

parent 7d68c1d6
......@@ -134,9 +134,8 @@ void ChooseUri::findPrinters()
request->getPrinters(attr);
}
void ChooseUri::getPrintersFinished()
void ChooseUri::getPrintersFinished(KCupsRequest *request)
{
auto request = qobject_cast<KCupsRequest*>(sender());
QUrl uri = request->property("URI").value<QUrl>();
QUrl url;
url.setScheme(QStringLiteral("ipp"));
......
......@@ -30,6 +30,7 @@
namespace Ui {
class ChooseUri;
}
class KCupsRequest;
class ChooseUri : public GenericPage
{
Q_OBJECT
......@@ -59,7 +60,7 @@ private slots:
void checkSelected();
void on_addressLE_textChanged(const QString &text);
void findPrinters();
void getPrintersFinished();
void getPrintersFinished(KCupsRequest *request);
private:
QUrl parsedURL(const QString &text) const;
......
......@@ -79,11 +79,11 @@ void ClassListWidget::init()
}
}
void ClassListWidget::loadFinished()
void ClassListWidget::loadFinished(KCupsRequest *request)
{
// If we have an old request running discard it's result and get a new one
if (m_request != sender()) {
sender()->deleteLater();
if (m_request != request) {
request->deleteLater();
return;
}
......
......@@ -51,7 +51,7 @@ signals:
private slots:
void init();
void loadFinished();
void loadFinished(KCupsRequest *request);
void modelChanged();
private:
......
......@@ -179,9 +179,8 @@ void JobModel::getJobs()
m_processingJob.clear();
}
void JobModel::getJobFinished()
void JobModel::getJobFinished(KCupsRequest *request)
{
auto request = static_cast<KCupsRequest *>(sender());
if (request) {
if (request->hasError()) {
// clear the model after so that the proper widget can be shown
......
......@@ -106,7 +106,7 @@ public:
private slots:
void getJobs();
void getJobFinished();
void getJobFinished(KCupsRequest *request);
void jobCompleted(const QString &text,
const QString &printerUri,
......
......@@ -665,8 +665,10 @@ void KCupsRequest::setFinished(bool delayed)
{
m_finished = true;
if (delayed) {
QTimer::singleShot(0, this, SIGNAL(finished()));
QTimer::singleShot(0, this, [this] () {
emit finished(this);
});
} else {
emit finished();
emit finished(this);
}
}
......@@ -291,7 +291,7 @@ signals:
const QString &device_uri,
const QString &device_location);
void finished();
void finished(KCupsRequest *);
private:
void invokeMethod(const char *method,
......
......@@ -114,9 +114,8 @@ PrinterModel::PrinterModel(QObject *parent) :
update();
}
void PrinterModel::getDestsFinished()
void PrinterModel::getDestsFinished(KCupsRequest *request)
{
auto request = qobject_cast<KCupsRequest *>(sender());
// When there is no printer IPP_NOT_FOUND is returned
if (request->hasError() && request->error() != IPP_NOT_FOUND) {
// clear the model after so that the proper widget can be shown
......@@ -435,9 +434,8 @@ void PrinterModel::insertUpdatePrinter(const QString &text,
insertUpdatePrinterName(printerName);
}
void PrinterModel::insertUpdatePrinterFinished()
void PrinterModel::insertUpdatePrinterFinished(KCupsRequest *request)
{
auto request = qobject_cast<KCupsRequest *>(sender());
if (!request->hasError()) {
foreach (const KCupsPrinter &printer, request->printers()) {
// If there is a printer and it's not the current one add it
......
......@@ -26,6 +26,7 @@
#include <KCupsPrinter.h>
class KCupsRequest;
class Q_DECL_EXPORT PrinterModel : public QStandardItemModel
{
Q_OBJECT
......@@ -75,7 +76,7 @@ public:
public slots:
void update();
void getDestsFinished();
void getDestsFinished(KCupsRequest *request);
void slotCountChanged();
signals:
......@@ -91,7 +92,7 @@ private slots:
uint printerState,
const QString &printerStateReasons,
bool printerIsAcceptingJobs);
void insertUpdatePrinterFinished();
void insertUpdatePrinterFinished(KCupsRequest *request);
void printerRemovedName(const QString &printerName);
void printerRemoved(const QString &text, const QString &printerUri, const QString &printerName, uint printerState, const QString &printerStateReasons, bool printerIsAcceptingJobs);
void printerStateChanged(const QString &text, const QString &printerUri, const QString &printerName, uint printerState, const QString &printerStateReasons, bool printerIsAcceptingJobs);
......
......@@ -149,24 +149,24 @@ void SelectMakeModel::setMakeModel(const QString &make, const QString &makeAndMo
}
}
void SelectMakeModel::ppdsLoaded()
void SelectMakeModel::ppdsLoaded(KCupsRequest *request)
{
if (m_ppdRequest->hasError()) {
qCWarning(LIBKCUPS) << "Failed to get PPDs" << m_ppdRequest->errorMsg();
ui->messageWidget->setText(i18n("Failed to get a list of drivers: '%1'", m_ppdRequest->errorMsg()));
if (request->hasError()) {
qCWarning(LIBKCUPS) << "Failed to get PPDs" << request->errorMsg();
ui->messageWidget->setText(i18n("Failed to get a list of drivers: '%1'", request->errorMsg()));
ui->messageWidget->animatedShow();
// Force the changed signal to be sent
checkChanged();
m_ppdRequest = 0;
} else {
m_ppds = m_ppdRequest->ppds();
m_ppds = request->ppds();
// Try to show the PPDs
setModelData();
}
sender()->deleteLater();
m_ppdRequest = nullptr;
request->deleteLater();
}
void SelectMakeModel::checkChanged()
......
......@@ -48,7 +48,7 @@ public:
public slots:
void checkChanged();
void ppdsLoaded();
void ppdsLoaded(KCupsRequest *request);
signals:
void changed(bool);
......
......@@ -312,10 +312,8 @@ void PrintKCM::getServerSettings()
}
}
void PrintKCM::getServerSettingsFinished()
void PrintKCM::getServerSettingsFinished(KCupsRequest *request)
{
auto request = qobject_cast<KCupsRequest *>(sender());
// When we don't have any destinations error is set to IPP_NOT_FOUND
// we can safely ignore the error since it DOES bring the server settings
bool error = request->hasError() && request->error() != IPP_NOT_FOUND;
......@@ -351,9 +349,8 @@ void PrintKCM::getServerSettingsFinished()
m_serverRequest = 0;
}
void PrintKCM::updateServerFinished()
void PrintKCM::updateServerFinished(KCupsRequest *request)
{
auto request = qobject_cast<KCupsRequest *>(sender());
if (request->hasError()) {
if (request->error() == IPP_SERVICE_UNAVAILABLE ||
request->error() == IPP_INTERNAL_ERROR ||
......
......@@ -50,8 +50,8 @@ private slots:
void showInfo(const QIcon &icon, const QString &title, const QString &comment, bool showAddPrinter, bool showToolButtons);
void getServerSettings();
void getServerSettingsFinished();
void updateServerFinished();
void getServerSettingsFinished(KCupsRequest *request);
void updateServerFinished(KCupsRequest *request);
void systemPreferencesTriggered();
private:
......
......@@ -258,9 +258,8 @@ void PrinterDescription::on_actionPrintSelfTestPage_triggered(bool checked)
request->printCommand(m_destName, "PrintSelfTestPage", i18n("Print Self-Test Page"));
}
void PrinterDescription::requestFinished()
void PrinterDescription::requestFinished(KCupsRequest *request)
{
auto request = qobject_cast<KCupsRequest*>(sender());
if (request && request->hasError()) {
ui->errorMessage->setText(i18n("Failed to perform request: %1", request->errorMsg()));
ui->errorMessage->animatedShow();
......
......@@ -70,7 +70,7 @@ private slots:
void on_actionCleanPrintHeads_triggered(bool checked);
void on_actionPrintSelfTestPage_triggered(bool checked);
void requestFinished();
void requestFinished(KCupsRequest *request);
private:
Ui::PrinterDescription *ui;
......
......@@ -378,9 +378,8 @@ void PrintQueueUi::updatePrinter(const QString &text, const QString &printerUri,
updatePrinterByName(printerName);
}
void PrintQueueUi::getAttributesFinished()
void PrintQueueUi::getAttributesFinished(KCupsRequest *request)
{
KCupsRequest *request = qobject_cast<KCupsRequest *>(sender());
qDebug() << request->hasError() << request->printers().isEmpty();
if (request->hasError() || request->printers().isEmpty()) {
......
......@@ -29,6 +29,7 @@ namespace Ui {
class PrintQueueUi;
}
class KCupsRequest;
class KCupsPrinter;
class JobSortFilterModel;
class JobModel;
......@@ -66,7 +67,7 @@ private slots:
void updateButtons();
void showContextMenu(const QPoint &point);
void showHeaderContextMenu(const QPoint &point);
void getAttributesFinished();
void getAttributesFinished(KCupsRequest *request);
private:
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
......
Markdown is supported
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