Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize code #26

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/browser/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,29 @@ MainWindow::MainWindow()
mAttributes = new QTableWidget;
mAttributes->setSelectionBehavior(QAbstractItemView::SelectRows);

QVBoxLayout *rootLayout = new QVBoxLayout;
QWidget *widget = new QWidget;
auto *rootLayout = new QVBoxLayout;
auto *widget = new QWidget;
widget->setLayout(rootLayout);
setCentralWidget(widget);

QCheckBox *any = new QCheckBox(tr("Any"));
auto *any = new QCheckBox(tr("Any"));

QHBoxLayout *typeLayout = new QHBoxLayout;
auto *typeLayout = new QHBoxLayout;
typeLayout->addWidget(mServiceType, 1);
typeLayout->addWidget(any);
typeLayout->addWidget(mStartStop);
rootLayout->addLayout(typeLayout);

QSplitter *vSplitter = new QSplitter;
auto *vSplitter = new QSplitter;
vSplitter->setOrientation(Qt::Vertical);
vSplitter->addWidget(mAddresses);
vSplitter->addWidget(mAttributes);

QSplitter *hSplitter = new QSplitter;
auto *hSplitter = new QSplitter;
hSplitter->addWidget(mServices);
hSplitter->addWidget(vSplitter);

QHBoxLayout *servicesLayout = new QHBoxLayout;
auto *servicesLayout = new QHBoxLayout;
servicesLayout->addWidget(hSplitter);
rootLayout->addLayout(servicesLayout);

Expand Down
4 changes: 2 additions & 2 deletions examples/browser/servicemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ServiceModel : public QAbstractListModel

ServiceModel(QMdnsEngine::Server *server, const QByteArray &type);

virtual int rowCount(const QModelIndex &parent) const;
virtual QVariant data(const QModelIndex &index, int role) const;
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;

private Q_SLOTS:

Expand Down
14 changes: 7 additions & 7 deletions examples/provider/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

MainWindow::MainWindow()
: mHostname(&mServer),
mProvider(0),
mProvider(nullptr),
mServiceName(new QLineEdit(tr("Test Service"))),
mServiceType(new QLineEdit(tr("_test._tcp.local."))),
mServicePort(new QLineEdit("1234")),
Expand All @@ -55,17 +55,17 @@ MainWindow::MainWindow()
mLog->setReadOnly(true);

// Create the root layout
QVBoxLayout *rootLayout = new QVBoxLayout;
QWidget *widget = new QWidget;
auto *rootLayout = new QVBoxLayout;
auto *widget = new QWidget;
widget->setLayout(rootLayout);
setCentralWidget(widget);

// Create the horizontal layout for the grid and buttons
QHBoxLayout *upperLayout = new QHBoxLayout;
auto *upperLayout = new QHBoxLayout;
rootLayout->addLayout(upperLayout);

// Create the grid layout for the line edits
QGridLayout *gridLayout = new QGridLayout;
auto *gridLayout = new QGridLayout;
gridLayout->addWidget(new QLabel(tr("Service name:")), 0, 0);
gridLayout->addWidget(mServiceName, 0, 1);
gridLayout->addWidget(new QLabel(tr("Service type:")), 1, 0);
Expand All @@ -75,7 +75,7 @@ MainWindow::MainWindow()
upperLayout->addLayout(gridLayout);

// Create the layout for the buttons
QVBoxLayout *buttonLayout = new QVBoxLayout;
auto *buttonLayout = new QVBoxLayout;
buttonLayout->addWidget(mButton);
buttonLayout->addWidget(mShowQueries);
buttonLayout->addWidget(new QWidget, 1);
Expand All @@ -94,7 +94,7 @@ void MainWindow::onClicked()
if (mProvider) {
mLog->append(tr("Destroying provider"));
delete mProvider;
mProvider = 0;
mProvider = nullptr;
} else {
mLog->append(tr("Creating provider"));
QMdnsEngine::Service service;
Expand Down
2 changes: 1 addition & 1 deletion src/include/qmdnsengine/abstractserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class QMDNSENGINE_EXPORT AbstractServer : public QObject
/**
* @brief Abstract constructor
*/
explicit AbstractServer(QObject *parent = 0);
explicit AbstractServer(QObject *parent = nullptr);

/**
* @brief Send a message to its provided destination
Expand Down
2 changes: 1 addition & 1 deletion src/include/qmdnsengine/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class QMDNSENGINE_EXPORT Browser : public QObject
* @param cache DNS cache to use or null to create one
* @param parent QObject
*/
Browser(AbstractServer *server, const QByteArray &type, Cache *cache = 0, QObject *parent = 0);
Browser(AbstractServer *server, const QByteArray &type, Cache *cache = nullptr, QObject *parent = nullptr);

Q_SIGNALS:

Expand Down
2 changes: 1 addition & 1 deletion src/include/qmdnsengine/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class QMDNSENGINE_EXPORT Cache : public QObject
/**
* @brief Create an empty cache.
*/
explicit Cache(QObject *parent = 0);
explicit Cache(QObject *parent = nullptr);

/**
* @brief Add a record to the cache
Expand Down
4 changes: 2 additions & 2 deletions src/include/qmdnsengine/dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ QMDNSENGINE_EXPORT bool fromPacket(const QByteArray &packet, Message &message);
/**
* @brief Create a raw DNS packet from a Message
* @param message Message to create the packet from
* @param packet storage for raw DNS packet
* @return packet storage for raw DNS packet
*/
QMDNSENGINE_EXPORT void toPacket(const Message &message, QByteArray &packet);
QMDNSENGINE_EXPORT QByteArray toPacket(const Message &message);

/**
* @brief Retrieve the string representation of a DNS type
Expand Down
2 changes: 1 addition & 1 deletion src/include/qmdnsengine/hostname.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class QMDNSENGINE_EXPORT Hostname : public QObject
/**
* @brief Create a new hostname
*/
Hostname(AbstractServer *server, QObject *parent = 0);
explicit Hostname(AbstractServer *server, QObject *parent = nullptr);

/**
* @brief Determine if a hostname has been registered
Expand Down
2 changes: 1 addition & 1 deletion src/include/qmdnsengine/prober.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class QMDNSENGINE_EXPORT Prober : public QObject
/**
* @brief Create a new prober
*/
Prober(AbstractServer *server, const Record &record, QObject *parent = 0);
Prober(AbstractServer *server, const Record &record, QObject *parent = nullptr);

Q_SIGNALS:

Expand Down
2 changes: 1 addition & 1 deletion src/include/qmdnsengine/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class QMDNSENGINE_EXPORT Provider : public QObject
/**
* @brief Create a new service provider
*/
Provider(AbstractServer *server, Hostname *hostname, QObject *parent = 0);
Provider(AbstractServer *server, Hostname *hostname, QObject *parent = nullptr);

/**
* @brief Update the service with the provided information
Expand Down
2 changes: 1 addition & 1 deletion src/include/qmdnsengine/resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class QMDNSENGINE_EXPORT Resolver : public QObject
/**
* @brief Create a new resolver
*/
Resolver(AbstractServer *server, const QByteArray &name, Cache *cache = 0, QObject *parent = 0);
Resolver(AbstractServer *server, const QByteArray &name, Cache *cache = nullptr, QObject *parent = nullptr);

Q_SIGNALS:

Expand Down
6 changes: 3 additions & 3 deletions src/include/qmdnsengine/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ class QMDNSENGINE_EXPORT Server : public AbstractServer
/**
* @brief Create a new server
*/
explicit Server(QObject *parent = 0);
explicit Server(QObject *parent = nullptr);

/**
* @brief Implementation of AbstractServer::sendMessage()
*/
virtual void sendMessage(const Message &message);
void sendMessage(const Message &message) override;

/**
* @brief Implementation of AbstractServer::sendMessageToAll()
*/
virtual void sendMessageToAll(const Message &message);
void sendMessageToAll(const Message &message) override;

private:

Expand Down
4 changes: 1 addition & 3 deletions src/src/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ BitmapPrivate::~BitmapPrivate()

void BitmapPrivate::free()
{
if (data) {
delete[] data;
}
delete[] data;
}

void BitmapPrivate::fromData(quint8 newLength, const quint8 *newData)
Expand Down
6 changes: 4 additions & 2 deletions src/src/browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
#include <qmdnsengine/query.h>
#include <qmdnsengine/record.h>

#include <utility>

#include "browser_p.h"

using namespace QMdnsEngine;

BrowserPrivate::BrowserPrivate(Browser *browser, AbstractServer *server, const QByteArray &type, Cache *existingCache)
BrowserPrivate::BrowserPrivate(Browser *browser, AbstractServer *server, QByteArray type, Cache *existingCache)
: QObject(browser),
q(browser),
server(server),
type(type),
type(std::move(type)),
cache(existingCache ? existingCache : new Cache(this))
{
connect(server, &AbstractServer::messageReceived, this, &BrowserPrivate::onMessageReceived);
Expand Down
2 changes: 1 addition & 1 deletion src/src/browser_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BrowserPrivate : public QObject

public:

explicit BrowserPrivate(Browser *browser, AbstractServer *server, const QByteArray &type, Cache *existingCache);
explicit BrowserPrivate(Browser *browser, AbstractServer *server, QByteArray type, Cache *existingCache);

bool updateService(const QByteArray &fqName);

Expand Down
2 changes: 1 addition & 1 deletion src/src/cache_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CachePrivate : public QObject
QList<QDateTime> triggers;
};

CachePrivate(Cache *cache);
explicit CachePrivate(Cache *cache);

QTimer timer;
QList<Entry> entries;
Expand Down
4 changes: 3 additions & 1 deletion src/src/dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,9 @@ bool fromPacket(const QByteArray &packet, Message &message)
return true;
}

void toPacket(const Message &message, QByteArray &packet)
QByteArray toPacket(const Message &message)
{
QByteArray packet;
quint16 offset = 0;
quint16 flags = (message.isResponse() ? 0x8400 : 0) |
(message.isTruncated() ? 0x200 : 0);
Expand All @@ -357,6 +358,7 @@ void toPacket(const Message &message, QByteArray &packet)
for (Record record : records) {
writeRecord(packet, offset, record, nameMap);
}
return packet;
}

QString typeName(quint16 type)
Expand Down
8 changes: 0 additions & 8 deletions src/src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@

using namespace QMdnsEngine;

MessagePrivate::MessagePrivate()
: port(0),
transactionId(0),
isResponse(false),
isTruncated(false)
{
}

Message::Message()
: d(new MessagePrivate)
{
Expand Down
14 changes: 5 additions & 9 deletions src/src/message_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ namespace QMdnsEngine
class Query;
class Record;

class MessagePrivate
struct MessagePrivate
{
public:

MessagePrivate();

QHostAddress address;
quint16 port;
quint16 transactionId;
bool isResponse;
bool isTruncated;
quint16 port = 0;
quint16 transactionId = 0;
bool isResponse = false;
bool isTruncated = false;
QList<Query> queries;
QList<Record> records;
};
Expand Down
4 changes: 1 addition & 3 deletions src/src/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ void ProviderPrivate::confirm()
{
// Confirm that the desired name is unique through probing

if (prober) {
delete prober;
}
delete prober;
prober = new Prober(server, srvProposed, this);
connect(prober, &Prober::nameConfirmed, [this](const QByteArray &name) {

Expand Down
6 changes: 0 additions & 6 deletions src/src/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@

using namespace QMdnsEngine;

QueryPrivate::QueryPrivate()
: type(0),
unicastResponse(false)
{
}

Query::Query()
: d(new QueryPrivate)
{
Expand Down
10 changes: 3 additions & 7 deletions src/src/query_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@
namespace QMdnsEngine
{

class QueryPrivate
struct QueryPrivate
{
public:

QueryPrivate();

QByteArray name;
quint16 type;
bool unicastResponse;
quint16 type = 0;
bool unicastResponse = false;
};

}
Expand Down
10 changes: 0 additions & 10 deletions src/src/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@

using namespace QMdnsEngine;

RecordPrivate::RecordPrivate()
: type(0),
flushCache(false),
ttl(3600),
priority(0),
weight(0),
port(0)
{
}

Record::Record()
: d(new RecordPrivate)
{
Expand Down
18 changes: 7 additions & 11 deletions src/src/record_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,19 @@

namespace QMdnsEngine {

class RecordPrivate
struct RecordPrivate
{
public:

RecordPrivate();

QByteArray name;
quint16 type;
bool flushCache;
quint32 ttl;
quint16 type = 0;
bool flushCache = false;
quint32 ttl = 3600;

QHostAddress address;
QByteArray target;
QByteArray nextDomainName;
quint16 priority;
quint16 weight;
quint16 port;
quint16 priority = 0;
quint16 weight = 0;
quint16 port = 0;
QMap<QByteArray, QByteArray> attributes;
Bitmap bitmap;
};
Expand Down
Loading