Cppcheck - HTML report - digiKam-nl-search-more-criteria-rev-e2466e0973

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/libs/dplugins/webservices/wslogindialog.cpp

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2015-11-12
     * Description : a common login dialog for Web Service tools
     *
     * SPDX-FileCopyrightText: 2007-2008 by Vardhman Jain <vardhman at gmail dot com>
     * SPDX-FileCopyrightText: 2011      by Roman Tsisyk <roman at tsisyk dot com>
     * SPDX-FileCopyrightText: 2015      by Shourya Singh Gupta <shouryasgupta at gmail dot com>
     * SPDX-FileCopyrightText: 2007-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "wslogindialog.h"

    // Qt includes

    #include <QGridLayout>
    #include <QHBoxLayout>
    #include <QVBoxLayout>
    #include <QFrame>
    #include <QLabel>
    #include <QPushButton>
    #include <QLineEdit>
    #include <QMessageBox>

    // KDE includes

    #include <klocalizedstring.h>

    // Local includes

    #include "digikam_debug.h"

    namespace Digikam
    {

    class Q_DECL_HIDDEN WSLoginDialog::Private
    {
    public:

        Private() = default;

        QLabel*    headerLabel  = nullptr;
        QLineEdit* loginEdit    = nullptr;
        QLineEdit* passwordEdit = nullptr;
    };

    WSLoginDialog::WSLoginDialog(QWidget* const parent,
                                 const QString& prompt,
                                 const QString& login,
                                 const QString& password)
        : QDialog(parent),
          d      (new Private)
    {
        setSizeGripEnabled(false);

        QVBoxLayout* const vbox = new QVBoxLayout(this);
        d->headerLabel          = new QLabel(this);
        d->headerLabel->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
        d->headerLabel->setTextFormat(Qt::RichText);
        d->headerLabel->setText(prompt);

        QFrame* const hline = new QFrame(this);
        hline->setObjectName(QLatin1String("hline"));
        hline->setFrameShape( QFrame::HLine );
        hline->setFrameShadow( QFrame::Sunken );
        hline->setFrameShape( QFrame::HLine );

        QGridLayout* const centerLayout = new QGridLayout();

        d->loginEdit    = new QLineEdit(this);
        d->passwordEdit = new QLineEdit(this);
        d->passwordEdit->setEchoMode(QLineEdit::Password);

        QLabel* const loginLabel    = new QLabel(this);
        loginLabel->setText(i18n( "Login:" ));

        QLabel* const passwordLabel = new QLabel(this);
        passwordLabel->setText(i18n("Password:"));

        centerLayout->addWidget(d->loginEdit,    0, 1);
        centerLayout->addWidget(d->passwordEdit, 1, 1);
        centerLayout->addWidget(loginLabel,     0, 0);
        centerLayout->addWidget(passwordLabel,  1, 0);

        QHBoxLayout* const btnLayout = new QHBoxLayout();
        QPushButton* const okBtn     = new QPushButton(this);
        okBtn->setAutoDefault(true);
        okBtn->setDefault(true);
        okBtn->setText(i18n("&Login"));

        QPushButton* const cancelBtn = new QPushButton(this);
        cancelBtn->setText(i18n("&Skip"));

        btnLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
        btnLayout->addWidget(okBtn);
        btnLayout->addWidget(cancelBtn);
        btnLayout->setContentsMargins(QMargins());
        btnLayout->setSpacing(5);

        vbox->setContentsMargins(5, 5, 5, 5);
        vbox->setSpacing(5);
        vbox->setObjectName(QLatin1String("vbox"));
        vbox->addWidget(d->headerLabel);
        vbox->addWidget(hline);
        vbox->addLayout(centerLayout);
        vbox->addLayout(btnLayout);

        resize(QSize(300, 150).expandedTo(minimumSizeHint()));

        setLogin(login);
        setPassword(password);

        connect(okBtn, SIGNAL(clicked()),
                this, SLOT(slotAccept()));

        connect(cancelBtn, SIGNAL(clicked()),
                this, SLOT(reject()));
    }

    WSLoginDialog::~WSLoginDialog()
    {
        delete d;
    }

    QString WSLoginDialog::login() const
    {
        return d->loginEdit->text();
    }

    QString WSLoginDialog::password() const
    {
        return d->passwordEdit->text();
    }

    void WSLoginDialog::setLogin(const QString& login)<--- Shadow argument
    {
        d->loginEdit->setText(login);
    }

    void WSLoginDialog::setPassword(const QString& password)<--- Shadow argument
    {
        d->passwordEdit->setText(password);
    }

    void WSLoginDialog::slotAccept()
    {
        if (!d->passwordEdit->text().isEmpty())
        {
            accept();
        }
        else
        {
            QMessageBox::critical(this, i18nc("@title:window", "Error"),
                                  i18n("Password cannot be empty."));
        }
    }

    } // namespace Digikam

    #include "moc_wslogindialog.cpp"