Commit 3d2613a9 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Modernize code

parent 2bb6c04c
Pipeline #60779 passed with stage
in 4 minutes and 50 seconds
......@@ -19,7 +19,7 @@ class LdapControlPrivate;
namespace KLDAP
{
class LdapControl;
typedef QVector<LdapControl> LdapControls;
using LdapControls = QVector<LdapControl>;
/**
@brief
......
......@@ -20,8 +20,8 @@ class LdapObjectPrivate;
namespace KLDAP
{
typedef QList<QByteArray> LdapAttrValue;
typedef QMap<QString, LdapAttrValue> LdapAttrMap;
using LdapAttrValue = QList<QByteArray>;
using LdapAttrMap = QMap<QString, LdapAttrValue>;
/**
* @brief
......@@ -98,6 +98,6 @@ private:
QSharedDataPointer<LdapObjectPrivate> d;
};
typedef QVector<LdapObject> LdapObjects;
using LdapObjects = QVector<LdapObject>;
}
......@@ -235,7 +235,7 @@ int LdapOperation::LdapOperationPrivate::bind(const QByteArray &creds, SASL_Call
if (server.auth() == LdapServer::SASL) {
#if !defined(HAVE_WINLDAP_H)
auto *saslconn = (sasl_conn_t *)mConnection->saslHandle();
auto saslconn = (sasl_conn_t *)mConnection->saslHandle();
sasl_interact_t *client_interact = nullptr;
const char *out = nullptr;
uint outlen;
......@@ -557,7 +557,7 @@ static void addModOp(LDAPMod ***pmods, int mod_type, const QString &attr, const
static void addControlOp(LDAPControl ***pctrls, const QString &oid, const QByteArray &value, bool critical)
{
LDAPControl **ctrls;
auto *ctrl = (LDAPControl *)malloc(sizeof(LDAPControl));
auto ctrl = (LDAPControl *)malloc(sizeof(LDAPControl));
ctrls = *pctrls;
......
......@@ -29,9 +29,9 @@ namespace KLDAP
class KLDAP_EXPORT LdapOperation
{
public:
typedef enum { Mod_None, Mod_Add, Mod_Replace, Mod_Del } ModType;
using ModType = enum { Mod_None, Mod_Add, Mod_Replace, Mod_Del };
typedef enum {
using ResultType = enum {
RES_BIND = 0x61,
RES_SEARCH_ENTRY = 0x64,
RES_SEARCH_REFERENCE = 0x73,
......@@ -43,15 +43,15 @@ public:
RES_COMPARE = 0x6f,
RES_EXTENDED = 0x78,
RES_EXTENDED_PARTIAL = 0x79
} ResultType;
};
typedef struct {
using ModOp = struct {
ModType type;
QString attr;
QList<QByteArray> values;
} ModOp;
};
typedef QVector<ModOp> ModOps;
using ModOps = QVector<ModOp>;
enum SASL_Fields { SASL_Authname = 0x1, SASL_Authzid = 0x2, SASL_Realm = 0x4, SASL_Password = 0x8 };
......@@ -63,7 +63,7 @@ public:
QString password;
};
typedef int(SASL_Callback_Proc)(SASL_Credentials &cred, void *data);
using SASL_Callback_Proc = int(SASL_Credentials &, void *);
struct SASL_Data {
SASL_Callback_Proc *proc;
......
......@@ -58,34 +58,34 @@ public:
* Describes the encryption settings that can be used
* for the LDAP connection.
*/
typedef enum {
using Security = enum {
None, ///< Do not use any encryption.
TLS, ///< Use TLS encryption.
SSL ///< Use SSL encryption.
} Security;
};
/**
* Describes the authentication method that can be used
* for the LDAP connection.
*/
typedef enum {
using Auth = enum {
Anonymous, ///< Do no authentication.
Simple, ///< Authenticate via login and password.
SASL ///< Azthenticate with the SASL framework.
} Auth;
};
/**
* Describes the certificate request and check behaviour
* for TLS/SSL connections.
*/
typedef enum {
using TLSRequireCertificate = enum {
TLSReqCertDefault, ///< Use system defaults
TLSReqCertNever, ///< Do not require any certificates.
TLSReqCertDemand, ///< Use LDAP_OPT_X_TLS_DEMAND.
TLSReqCertAllow, ///< Use LDAP_OPT_X_TLS_ALLOW.
TLSReqCertTry, ///< Use LDAP_OPT_X_TLS_TRY.
TLSReqCertHard, ///< Use LDAP_OPT_X_TLS_HARD.
} TLSRequireCertificate;
};
/**
* Clears all server settings.
......
......@@ -33,19 +33,19 @@ public:
* A class holding the extension name and state whether
* the extension is critical.
*/
typedef struct {
using Extension = struct {
QString value;
bool critical;
} Extension;
};
/**
* Describes the scope of the LDAP url.
*/
typedef enum {
using Scope = enum {
Base, ///< Only the same level as the url.
One, ///< The level of the url and the one below.
Sub ///< All levels below the url's level.
} Scope;
};
/**
* Constructs an empty LDAP url.
......
......@@ -28,11 +28,11 @@ namespace KLDAP
class KLDAP_EXPORT Ldif
{
public:
typedef enum { None, NewEntry, EndEntry, Item, Control, Err, MoreData } ParseValue;
using ParseValue = enum { None, NewEntry, EndEntry, Item, Control, Err, MoreData };
typedef enum { Entry_None, Entry_Add, Entry_Del, Entry_Mod, Entry_Modrdn } EntryType;
using EntryType = enum { Entry_None, Entry_Add, Entry_Del, Entry_Mod, Entry_Modrdn };
typedef enum { Mod_None, Mod_Add, Mod_Replace, Mod_Del } ModType;
using ModType = enum { Mod_None, Mod_Add, Mod_Replace, Mod_Del };
Ldif();
......
......@@ -63,7 +63,7 @@ AddHostDialog::AddHostDialog(KLDAP::LdapServer *server, QWidget *parent)
{
setWindowTitle(i18nc("@title:window", "Add Host"));
auto mainLayout = new QVBoxLayout(this);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
d->mOkButton = buttonBox->button(QDialogButtonBox::Ok);
d->mOkButton->setDefault(true);
d->mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
......@@ -73,7 +73,7 @@ AddHostDialog::AddHostDialog(KLDAP::LdapServer *server, QWidget *parent)
d->mServer = server;
QWidget *page = new QWidget(this);
auto page = new QWidget(this);
mainLayout->addWidget(page);
mainLayout->addWidget(buttonBox);
auto layout = new QHBoxLayout(page);
......
......@@ -23,7 +23,7 @@ class LdapClient;
* @since 4.14
*/
struct LdapResultObject {
typedef QVector<LdapResultObject> List;
using List = QVector<LdapResultObject>;
const LdapClient *client = nullptr;
KLDAP::LdapObject object;
};
......@@ -37,7 +37,7 @@ struct LdapResult {
/**
* A list of LdapResult objects.
*/
typedef QVector<LdapResult> List;
using List = QVector<LdapResult>;
LdapDN dn;
QString name; ///< The full name of the contact.
......
......@@ -61,7 +61,7 @@ void LdapConfigureWidget::slotSelectionChanged(QListWidgetItem *item)
void LdapConfigureWidget::slotItemClicked(QListWidgetItem *item)
{
auto *ldapItem = dynamic_cast<LdapWidgetItem *>(item);
auto ldapItem = dynamic_cast<LdapWidgetItem *>(item);
if (!ldapItem) {
return;
}
......@@ -87,7 +87,7 @@ void LdapConfigureWidget::slotAddHost()
void LdapConfigureWidget::slotEditHost()
{
auto *item = dynamic_cast<LdapWidgetItem *>(mHostListView->currentItem());
auto item = dynamic_cast<LdapWidgetItem *>(mHostListView->currentItem());
if (!item) {
return;
}
......@@ -109,7 +109,7 @@ void LdapConfigureWidget::slotRemoveHost()
if (!item) {
return;
}
auto *ldapItem = dynamic_cast<LdapWidgetItem *>(item);
auto ldapItem = dynamic_cast<LdapWidgetItem *>(item);
if (KMessageBox::No
== KMessageBox::questionYesNo(this, i18n("Do you want to remove setting for host \"%1\"?", ldapItem->server().host()), i18n("Remove Host"))) {
return;
......@@ -227,7 +227,7 @@ void LdapConfigureWidget::save()
int selected = 0;
int unselected = 0;
for (int i = 0; i < mHostListView->count(); ++i) {
auto *item = dynamic_cast<LdapWidgetItem *>(mHostListView->item(i));
auto item = dynamic_cast<LdapWidgetItem *>(mHostListView->item(i));
if (!item) {
continue;
}
......@@ -265,17 +265,17 @@ void LdapConfigureWidget::initGUI()
layout->setObjectName(QStringLiteral("layout"));
layout->setContentsMargins(0, 0, 0, 0);
QGroupBox *groupBox = new QGroupBox(i18n("LDAP Servers"));
auto groupBox = new QGroupBox(i18n("LDAP Servers"));
layout->addWidget(groupBox);
auto mainLayout = new QVBoxLayout;
mainLayout->setObjectName(QStringLiteral("mainlayout"));
groupBox->setLayout(mainLayout);
// Contents of the QVGroupBox: label and hbox
QLabel *label = new QLabel(i18n("Check all servers that should be used:"));
auto label = new QLabel(i18n("Check all servers that should be used:"));
mainLayout->addWidget(label);
QWidget *hBox = new QWidget(this);
auto hBox = new QWidget(this);
mainLayout->addWidget(hBox);
auto hBoxHBoxLayout = new QHBoxLayout(hBox);
......@@ -286,7 +286,7 @@ void LdapConfigureWidget::initGUI()
hBoxHBoxLayout->addWidget(mHostListView);
mHostListView->setSortingEnabled(false);
QWidget *upDownBox = new QWidget(hBox);
auto upDownBox = new QWidget(hBox);
auto upDownBoxVBoxLayout = new QVBoxLayout(upDownBox);
upDownBoxVBoxLayout->setContentsMargins(0, 0, 0, 0);
hBoxHBoxLayout->addWidget(upDownBox);
......@@ -301,7 +301,7 @@ void LdapConfigureWidget::initGUI()
mDownButton->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
mDownButton->setEnabled(false); // b/c no item is selected yet
QWidget *spacer = new QWidget(upDownBox);
auto spacer = new QWidget(upDownBox);
upDownBoxVBoxLayout->addWidget(spacer);
upDownBoxVBoxLayout->setStretchFactor(spacer, 100);
......
......@@ -224,7 +224,7 @@ void LdapConfigWidget::Private::initWidget()
mainLayout->addWidget(mDn, row, 1, 1, 1);
// without host query doesn't make sense
if (mHost) {
QPushButton *dnquery = new QPushButton(i18n("Query Server"), mParent);
auto dnquery = new QPushButton(i18n("Query Server"), mParent);
dnquery->setEnabled(false);
connect(dnquery, &QPushButton::clicked, mParent, [this]() {
queryDNClicked();
......@@ -248,7 +248,7 @@ void LdapConfigWidget::Private::initWidget()
}
if (mFeatures & W_SECBOX) {
QGroupBox *btgroup = new QGroupBox(i18n("Security"), mParent);
auto btgroup = new QGroupBox(i18n("Security"), mParent);
auto hbox = new QHBoxLayout;
btgroup->setLayout(hbox);
mSecNo = new QRadioButton(i18nc("@option:radio set no security", "No"), btgroup);
......@@ -277,7 +277,7 @@ void LdapConfigWidget::Private::initWidget()
}
if (mFeatures & W_AUTHBOX) {
QGroupBox *authbox = new QGroupBox(i18n("Authentication"), mParent);
auto authbox = new QGroupBox(i18n("Authentication"), mParent);
auto vbox = new QVBoxLayout;
authbox->setLayout(vbox);
auto hbox = new QHBoxLayout;
......
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