Commit 4df75e88 authored by Kåre Särs's avatar Kåre Särs
Browse files

Fix clazy warnings

parent c6af0a37
......@@ -30,6 +30,7 @@
// Qt includes
#include <QMutex>
#include <QMutexLocker>
#include <QList>
#include <QDebug>
......@@ -37,7 +38,7 @@ namespace KSaneIface
{
static KSaneAuth *s_instance = nullptr;
static QMutex s_mutex;
Q_GLOBAL_STATIC(QMutex, s_mutex)
struct KSaneAuth::Private {
struct AuthStruct {
......@@ -51,13 +52,11 @@ struct KSaneAuth::Private {
KSaneAuth *KSaneAuth::getInstance()
{
s_mutex.lock();
QMutexLocker locker(s_mutex);
if (s_instance == nullptr) {
s_instance = new KSaneAuth();
}
s_mutex.unlock();
return s_instance;
}
......@@ -65,6 +64,7 @@ KSaneAuth::KSaneAuth() : d(new Private) {}
KSaneAuth::~KSaneAuth()
{
QMutexLocker locker(s_mutex);
d->authList.clear();
delete d;
}
......
......@@ -110,9 +110,7 @@ KSaneDeviceDialog::~KSaneDeviceDialog()
void KSaneDeviceDialog::reloadDevicesList()
{
setAvailable(false);
while (!m_btnGroupDevices->buttons().isEmpty()) {
delete m_btnGroupDevices->buttons().takeFirst();
}
qDeleteAll(m_btnGroupDevices->buttons());
m_gbDevices->setTitle(i18n("Looking for devices. Please wait."));
m_gbDevices->layout()->itemAt(0)->widget()->hide(); // explanation
m_btnReloadDevices->setEnabled(false);
......@@ -147,9 +145,7 @@ QString KSaneDeviceDialog::getSelectedName() const
void KSaneDeviceDialog::updateDevicesList()
{
while (!m_btnGroupDevices->buttons().isEmpty()) {
delete m_btnGroupDevices->buttons().takeFirst();
}
qDeleteAll(m_btnGroupDevices->buttons());
const QList<KSaneWidget::DeviceInfo> list = m_findDevThread->devicesList();
if (list.isEmpty()) {
......
......@@ -39,20 +39,20 @@ extern "C"
}
#include <QMutex>
#include <QMutexLocker>
namespace KSaneIface
{
static FindSaneDevicesThread *s_instancesane = nullptr;
static QMutex s_mutexsane;
Q_GLOBAL_STATIC(QMutex, s_mutexsane)
FindSaneDevicesThread *FindSaneDevicesThread::getInstance()
{
s_mutexsane.lock();
QMutexLocker locker(s_mutexsane);
if (s_instancesane == nullptr) {
s_instancesane = new FindSaneDevicesThread();
}
s_mutexsane.unlock();
return s_instancesane;
}
......@@ -63,9 +63,8 @@ FindSaneDevicesThread::FindSaneDevicesThread() : QThread(nullptr)
FindSaneDevicesThread::~FindSaneDevicesThread()
{
s_mutexsane.lock();
QMutexLocker locker(s_mutexsane);
wait();
s_mutexsane.unlock();
}
void FindSaneDevicesThread::run()
......
......@@ -63,9 +63,9 @@
namespace KSaneIface
{
static int s_objectCount = 0;
static QMutex s_objectMutex;
Q_GLOBAL_STATIC(QMutex, s_objectMutex)
static const QString InvetColorsOption = QStringLiteral("KSane::InvertColors");
static const QLatin1String InvetColorsOption("KSane::InvertColors");
KSaneWidget::KSaneWidget(QWidget *parent)
: QWidget(parent), d(new KSaneWidgetPrivate(this))
......@@ -73,7 +73,7 @@ KSaneWidget::KSaneWidget(QWidget *parent)
SANE_Int version;
SANE_Status status;
s_objectMutex.lock();
s_objectMutex->lock();
s_objectCount++;
if (s_objectCount == 1) {
......@@ -89,7 +89,7 @@ KSaneWidget::KSaneWidget(QWidget *parent)
// << SANE_VERSION_BUILD(version);
}
}
s_objectMutex.unlock();
s_objectMutex->unlock();
// read the device list to get a list of vendor and model info
d->m_findDevThread->start();
......@@ -248,11 +248,11 @@ KSaneWidget::KSaneWidget(QWidget *parent)
KSaneWidget::~KSaneWidget()
{
while (!closeDevice()) {
usleep(1000);
usleep(100);
}
// wait for any thread to exit
s_objectMutex.lock();
s_objectMutex->lock();
s_objectCount--;
if (s_objectCount <= 0) {
// only delete the find-devices and authorization singletons and call sane_exit
......@@ -261,7 +261,7 @@ KSaneWidget::~KSaneWidget()
delete d->m_auth;
sane_exit();
}
s_objectMutex.unlock();
s_objectMutex->unlock();
delete d;
}
......@@ -662,7 +662,7 @@ void KSaneWidget::scanFinal()
d->startFinalScan();
} else {
// if the button frame is disabled, there is no open device to scan from
emit scanDone(KSaneWidget::ErrorGeneral, QStringLiteral(""));
emit scanDone(KSaneWidget::ErrorGeneral, QString());
}
}
......@@ -672,7 +672,7 @@ void KSaneWidget::startPreviewScan()
d->startPreviewScan();
} else {
// if the button frame is disabled, there is no open device to scan from
emit scanDone(KSaneWidget::ErrorGeneral, QStringLiteral(""));
emit scanDone(KSaneWidget::ErrorGeneral, QString());
}
}
......
......@@ -184,7 +184,7 @@ void KSaneWidgetPrivate::devListUpdated()
void KSaneWidgetPrivate::signalDevListUpdate()
{
emit(q->availableDevices(m_findDevThread->devicesList()));
emit q->availableDevices(m_findDevThread->devicesList());
}
KSaneWidget::ImageFormat KSaneWidgetPrivate::getImgFormat(SANE_Parameters &params)
......@@ -729,10 +729,7 @@ void KSaneWidgetPrivate::optReload()
void KSaneWidgetPrivate::valReload()
{
int i;
QString tmp;
for (i = 0; i < m_optList.size(); ++i) {
for (int i = 0; i < m_optList.size(); ++i) {
m_optList.at(i)->readValue();
}
......@@ -1054,7 +1051,7 @@ void KSaneWidgetPrivate::previewScanDone()
sane_close(m_saneHandle);
m_saneHandle = nullptr;
clearDeviceOptions();
emit(q->scanDone(KSaneWidget::NoError, QStringLiteral("")));
emit q->scanDone(KSaneWidget::NoError, QString());
return;
}
......@@ -1089,7 +1086,7 @@ void KSaneWidgetPrivate::previewScanDone()
m_scanOngoing = false;
m_updProgressTmr.stop();
emit(q->scanDone(KSaneWidget::NoError, QStringLiteral("")));
emit q->scanDone(KSaneWidget::NoError, QString());
return;
}
......@@ -1154,11 +1151,11 @@ void KSaneWidgetPrivate::oneFinalScanDone()
int bytesPerLine = qMax(getBytesPerLines(params), 1); // ensure no div by 0
lines = m_scanData.size() / bytesPerLine;
}
emit(q->imageReady(m_scanData,
emit q->imageReady(m_scanData,
params.pixels_per_line,
lines,
getBytesPerLines(params),
(int)getImgFormat(params)));
(int)getImgFormat(params));
// now check if we should have automatic ADF batch scanning
if (m_optSource) {
......@@ -1235,7 +1232,7 @@ void KSaneWidgetPrivate::oneFinalScanDone()
}
}
}
emit(q->scanDone(KSaneWidget::NoError, QStringLiteral("")));
emit q->scanDone(KSaneWidget::NoError, QString());
} else {
switch (m_scanThread->saneStatus()) {
case SANE_STATUS_GOOD:
......@@ -1243,7 +1240,7 @@ void KSaneWidgetPrivate::oneFinalScanDone()
case SANE_STATUS_EOF:
break;
case SANE_STATUS_NO_DOCS:
emit(q->scanDone(KSaneWidget::Information, i18n(sane_strstatus(m_scanThread->saneStatus()))));
emit q->scanDone(KSaneWidget::Information, i18n(sane_strstatus(m_scanThread->saneStatus())));
alertUser(KSaneWidget::Information, i18n(sane_strstatus(m_scanThread->saneStatus())));
break;
case SANE_STATUS_UNSUPPORTED:
......@@ -1254,7 +1251,7 @@ void KSaneWidgetPrivate::oneFinalScanDone()
case SANE_STATUS_COVER_OPEN:
case SANE_STATUS_DEVICE_BUSY:
case SANE_STATUS_ACCESS_DENIED:
emit(q->scanDone(KSaneWidget::ErrorGeneral, i18n(sane_strstatus(m_scanThread->saneStatus()))));
emit q->scanDone(KSaneWidget::ErrorGeneral, i18n(sane_strstatus(m_scanThread->saneStatus())));
alertUser(KSaneWidget::ErrorGeneral, i18n(sane_strstatus(m_scanThread->saneStatus())));
break;
}
......@@ -1275,7 +1272,7 @@ void KSaneWidgetPrivate::setBusy(bool busy)
m_activityFrame->hide();
m_btnFrame->hide();
m_optionPollTmr.stop();
emit(q->scanProgress(0));
emit q->scanProgress(0);
} else {
m_warmingUp->hide();
m_activityFrame->hide();
......@@ -1283,7 +1280,7 @@ void KSaneWidgetPrivate::setBusy(bool busy)
if (m_pollList.size() > 0) {
m_optionPollTmr.start();
}
emit(q->scanProgress(100));
emit q->scanProgress(100);
}
m_optsTabWidget->setDisabled(busy);
......@@ -1355,7 +1352,7 @@ void KSaneWidgetPrivate::updateProgress()
}
m_progressBar->setValue(progress);
emit(q->scanProgress(progress));
emit q->scanProgress(progress);
}
void KSaneWidgetPrivate::alertUser(int type, const QString &strStatus)
......@@ -1370,7 +1367,7 @@ void KSaneWidgetPrivate::alertUser(int type, const QString &strStatus)
break;
}
} else {
emit(q->userMessage(type, strStatus));
emit q->userMessage(type, strStatus);
}
}
......@@ -1444,7 +1441,7 @@ void KSaneWidgetPrivate::setPossibleScanSizes()
m_scanareaPapersize->addItem(i18n("Custom"), customSize);
// Add portrait page sizes
for (int sizeCode: m_sizeCodes) {
for (int sizeCode: qAsConst(m_sizeCodes)) {
QSizeF size = QPageSize::size((QPageSize::PageSizeId)sizeCode, QPageSize::Millimeter);
if (mmToDispUnit(size.width()) > widthInDispUnit) {
continue;
......@@ -1456,7 +1453,7 @@ void KSaneWidgetPrivate::setPossibleScanSizes()
}
// Add landscape page sizes
for (int sizeCode: m_sizeCodes) {
for (int sizeCode: qAsConst(m_sizeCodes)) {
QSizeF size = QPageSize::size((QPageSize::PageSizeId)sizeCode, QPageSize::Millimeter);
size.transpose();
if (mmToDispUnit(size.width()) > widthInDispUnit) {
......
......@@ -50,7 +50,7 @@ void KSaneOptButton::createWidget(QWidget *parent)
if (!m_optDesc) {
qDebug() << "This is a bug";
m_widget = new KSaneOptionWidget(parent, QStringLiteral(""));
m_widget = new KSaneOptionWidget(parent, QString());
return;
}
......
......@@ -52,7 +52,7 @@ void KSaneOptCheckBox::createWidget(QWidget *parent)
if (!m_optDesc) {
qDebug() << "This is a bug";
m_widget = new KSaneOptionWidget(parent, QStringLiteral(""));
m_widget = new KSaneOptionWidget(parent, QString());
return;
}
......
......@@ -51,7 +51,7 @@ void KSaneOptCombo::createWidget(QWidget *parent)
return;
}
m_widget = m_combo = new LabeledCombo(parent, QStringLiteral(""), QStringList());
m_widget = m_combo = new LabeledCombo(parent, QString(), QStringList());
readOption();
m_widget->setToolTip(sane_i18n(m_optDesc->desc));
connect(m_combo, QOverload<int>::of(&LabeledCombo::activated), this, &KSaneOptCombo::comboboxChangedIndex);
......
......@@ -52,7 +52,7 @@ void KSaneOptEntry::createWidget(QWidget *parent)
if (!m_optDesc) {
qDebug() << "This is a bug";
m_widget = new KSaneOptionWidget(parent, QStringLiteral(""));
m_widget = new KSaneOptionWidget(parent, QString());
return;
}
......@@ -66,7 +66,7 @@ void KSaneOptEntry::createWidget(QWidget *parent)
void KSaneOptEntry::entryChanged(const QString &text)
{
QString tmp;
tmp += text.left(m_optDesc->size);
tmp += text.leftRef(m_optDesc->size);
if (tmp != text) {
m_entry->setText(tmp);
writeData(tmp.toLatin1().data());
......
......@@ -51,7 +51,7 @@ void KSaneOptFSlider::createWidget(QWidget *parent)
return;
}
m_widget = m_slider = new LabeledFSlider(parent, QStringLiteral(""), FIXED_MIN, FIXED_MAX, MIN_FIXED_STEP);
m_widget = m_slider = new LabeledFSlider(parent, QString(), FIXED_MIN, FIXED_MAX, MIN_FIXED_STEP);
readOption();
m_widget->setToolTip(sane_i18n(m_optDesc->desc));
connect(m_slider, &LabeledFSlider::valueChanged, this, &KSaneOptFSlider::sliderChanged);
......
......@@ -52,7 +52,7 @@ void KSaneOptGamma::createWidget(QWidget *parent)
if (!m_optDesc) {
qDebug() << "This is a bug";
m_widget = new KSaneOptionWidget(parent, QStringLiteral(""));
m_widget = new KSaneOptionWidget(parent, QString());
return;
}
......
......@@ -57,7 +57,7 @@ KSaneOption::~KSaneOption()
void KSaneOption::createWidget(QWidget *parent)
{
if (!m_widget) {
m_widget = new KSaneOptionWidget(parent, QStringLiteral(""));
m_widget = new KSaneOptionWidget(parent, QString());
}
if (m_optDesc) {
......@@ -121,7 +121,7 @@ bool KSaneOption::needsPolling() const
QString KSaneOption::name() const
{
if (m_optDesc == nullptr) {
return QStringLiteral("");
return QString();
}
return QString::fromUtf8(m_optDesc->name);
}
......@@ -379,7 +379,7 @@ KLocalizedString KSaneOption::unitString()
QString KSaneOption::unitDoubleString()
{
switch (m_optDesc->unit) {
case SANE_UNIT_NONE: return QStringLiteral("");
case SANE_UNIT_NONE: return QString();
case SANE_UNIT_PIXEL: return i18nc("Double numbers. SpinBox parameter unit", " Pixels");
case SANE_UNIT_BIT: return i18nc("Double numbers. SpinBox parameter unit", " Bits");
case SANE_UNIT_MM: return i18nc("Double numbers. SpinBox parameter unit (Millimeter)", " mm");
......@@ -387,7 +387,7 @@ QString KSaneOption::unitDoubleString()
case SANE_UNIT_PERCENT: return i18nc("Double numbers. SpinBox parameter unit (Percentage)", " %");
case SANE_UNIT_MICROSECOND: return i18nc("Double numbers. SpinBox parameter unit (Microseconds)", " µs");
}
return QStringLiteral("");
return QString();
}
} // NameSpace KSaneIface
......@@ -51,7 +51,7 @@ void KSaneOptSlider::createWidget(QWidget *parent)
return;
}
m_widget = m_slider = new LabeledSlider(parent, QStringLiteral(""), KSW_INT_MIN, KSW_INT_MAX, 1);
m_widget = m_slider = new LabeledSlider(parent, QString(), KSW_INT_MIN, KSW_INT_MAX, 1);
readOption();
m_widget->setToolTip(sane_i18n(m_optDesc->desc));
connect(m_slider, &LabeledSlider::valueChanged, this, &KSaneOptSlider::sliderChanged);
......
......@@ -64,6 +64,11 @@ public:
/** This function forwards the request to the QComboBox equivalent */
int currentIndex() const;
/**
* This function is used to read the current string of the combobox
*/
QString currentText() const;
public Q_SLOTS:
/**
......@@ -82,11 +87,6 @@ public Q_SLOTS:
*/
void setCurrentText(const QString &);
/**
* This function is used to read the current string of the combobox
*/
QString currentText() const;
/**
* set the current item of the combobox.
*/
......
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