Skip to content

Commit

Permalink
Clean up on clang-tidy/clazy analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal committed Apr 4, 2019
1 parent 7508887 commit 1c5696e
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lib/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ bool Avatar::Private::checkUrl(const QUrl& url) const
}

QString Avatar::Private::localFile() const {
static const auto cachePath = cacheLocation("avatars");
static const auto cachePath = cacheLocation(QStringLiteral("avatars"));
return cachePath % _url.authority() % '_' % _url.fileName() % ".png";
}

Expand Down
25 changes: 15 additions & 10 deletions lib/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,8 @@ void Connection::doInDirectChat(User* u,
CreateRoomJob* Connection::createDirectChat(const QString& userId,
const QString& topic, const QString& name)
{
return createRoom(UnpublishRoom, "", name, topic, {userId},
"trusted_private_chat", {}, true);
return createRoom(UnpublishRoom, {}, name, topic, {userId},
QStringLiteral("trusted_private_chat"), {}, true);
}

ForgetRoomJob* Connection::forgetRoom(const QString& id)
Expand Down Expand Up @@ -964,7 +964,8 @@ QHash<QString, QVector<Room*>> Connection::tagsToRooms() const
QHash<QString, QVector<Room*>> result;
for (auto* r: qAsConst(d->roomMap))
{
for (const auto& tagName: r->tagNames())
const auto& tagNames = r->tagNames();
for (const auto& tagName: tagNames)
result[tagName].push_back(r);
}
for (auto it = result.begin(); it != result.end(); ++it)
Expand All @@ -979,9 +980,12 @@ QStringList Connection::tagNames() const
{
QStringList tags ({FavouriteTag});
for (auto* r: qAsConst(d->roomMap))
for (const auto& tag: r->tagNames())
{
const auto& tagNames = r->tagNames();
for (const auto& tag: tagNames)
if (tag != LowPriorityTag && !tags.contains(tag))
tags.push_back(tag);
}
tags.push_back(LowPriorityTag);
return tags;
}
Expand Down Expand Up @@ -1264,18 +1268,19 @@ void Connection::saveState() const
{
QJsonObject rooms;
QJsonObject inviteRooms;
for (const auto* i : roomMap()) // Pass on rooms in Leave state
const auto& rs = roomMap(); // Pass on rooms in Leave state
for (const auto* i : rs)
(i->joinState() == JoinState::Invite ? inviteRooms : rooms)
.insert(i->id(), QJsonValue::Null);

QJsonObject roomObj;
if (!rooms.isEmpty())
roomObj.insert("join", rooms);
roomObj.insert(QStringLiteral("join"), rooms);
if (!inviteRooms.isEmpty())
roomObj.insert("invite", inviteRooms);
roomObj.insert(QStringLiteral("invite"), inviteRooms);

rootObj.insert("next_batch", d->data->lastEvent());
rootObj.insert("rooms", roomObj);
rootObj.insert(QStringLiteral("next_batch"), d->data->lastEvent());
rootObj.insert(QStringLiteral("rooms"), roomObj);
}
{
QJsonArray accountDataEvents {
Expand All @@ -1285,7 +1290,7 @@ void Connection::saveState() const
accountDataEvents.append(
basicEventJson(e.first, e.second->contentJson()));

rootObj.insert("account_data",
rootObj.insert(QStringLiteral("account_data"),
QJsonObject {{ QStringLiteral("events"), accountDataEvents }});
}

Expand Down
6 changes: 3 additions & 3 deletions lib/connectiondata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace QMatrixClient;

struct ConnectionData::Private
{
explicit Private(const QUrl& url) : baseUrl(url) { }
explicit Private(QUrl url) : baseUrl(std::move(url)) { }

QUrl baseUrl;
QByteArray accessToken;
Expand All @@ -37,7 +37,7 @@ struct ConnectionData::Private
};

ConnectionData::ConnectionData(QUrl baseUrl)
: d(std::make_unique<Private>(baseUrl))
: d(std::make_unique<Private>(std::move(baseUrl)))
{ }

ConnectionData::~ConnectionData() = default;
Expand Down Expand Up @@ -98,7 +98,7 @@ QString ConnectionData::lastEvent() const

void ConnectionData::setLastEvent(QString identifier)
{
d->lastEvent = identifier;
d->lastEvent = std::move(identifier);
}

QByteArray ConnectionData::generateTxnId() const
Expand Down
3 changes: 2 additions & 1 deletion lib/events/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ event_type_t EventTypeRegistry::initializeTypeId(event_mtype_t matrixTypeId)

QString EventTypeRegistry::getMatrixType(event_type_t typeId)
{
return typeId < get().eventTypes.size() ? get().eventTypes[typeId] : "";
return typeId < get().eventTypes.size()
? get().eventTypes[typeId] : QString();
}

Event::Event(Type type, const QJsonObject& json)
Expand Down
2 changes: 1 addition & 1 deletion lib/events/stateevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace QMatrixClient;
RoomEvent::factory_t::addMethod(
[] (const QJsonObject& json, const QString& matrixType) -> StateEventPtr
{
if (!json.contains("state_key"))
if (!json.contains("state_key"_ls))
return nullptr;

if (auto e = StateEventBase::factory_t::make(json, matrixType))
Expand Down
2 changes: 1 addition & 1 deletion lib/jobs/basejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ BaseJob::Status BaseJob::doCheckReply(QNetworkReply* reply) const
BaseJob::Status BaseJob::parseReply(QNetworkReply* reply)
{
d->rawResponse = reply->readAll();
QJsonParseError error;
QJsonParseError error { 0, QJsonParseError::MissingObject };
const auto& json = QJsonDocument::fromJson(d->rawResponse, &error);
if( error.error == QJsonParseError::NoError )
return parseJson(json);
Expand Down
5 changes: 3 additions & 2 deletions lib/jobs/downloadfilejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class DownloadFileJob::Private

QUrl DownloadFileJob::makeRequestUrl(QUrl baseUrl, const QUrl& mxcUri)
{
return makeRequestUrl(baseUrl, mxcUri.authority(), mxcUri.path().mid(1));
return makeRequestUrl(
std::move(baseUrl), mxcUri.authority(), mxcUri.path().mid(1));
}

DownloadFileJob::DownloadFileJob(const QString& serverName,
Expand All @@ -31,7 +32,7 @@ DownloadFileJob::DownloadFileJob(const QString& serverName,
: GetContentJob(serverName, mediaId)
, d(localFilename.isEmpty() ? new Private : new Private(localFilename))
{
setObjectName("DownloadFileJob");
setObjectName(QStringLiteral("DownloadFileJob"));
}

QString DownloadFileJob::targetFileName() const
Expand Down
2 changes: 1 addition & 1 deletion lib/jobs/mediathumbnailjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ BaseJob::Status MediaThumbnailJob::parseReply(QNetworkReply* reply)
if( _thumbnail.loadFromData(data()->readAll()) )
return Success;

return { IncorrectResponseError, "Could not read image data" };
return { IncorrectResponseError, QStringLiteral("Could not read image data") };
}
3 changes: 2 additions & 1 deletion lib/networkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class NetworkAccessManager::Private
QList<QSslError> ignoredSslErrors;
};

NetworkAccessManager::NetworkAccessManager(QObject* parent) : d(std::make_unique<Private>())
NetworkAccessManager::NetworkAccessManager(QObject* parent)
: QNetworkAccessManager(parent), d(std::make_unique<Private>())
{ }

QList<QSslError> NetworkAccessManager::ignoredSslErrors() const
Expand Down
2 changes: 1 addition & 1 deletion lib/networksettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ void NetworkSettings::setupApplicationProxy() const
}

QMC_DEFINE_SETTING(NetworkSettings, QNetworkProxy::ProxyType, proxyType, "proxy_type", QNetworkProxy::DefaultProxy, setProxyType)
QMC_DEFINE_SETTING(NetworkSettings, QString, proxyHostName, "proxy_hostname", "", setProxyHostName)
QMC_DEFINE_SETTING(NetworkSettings, QString, proxyHostName, "proxy_hostname", {}, setProxyHostName)
QMC_DEFINE_SETTING(NetworkSettings, quint16, proxyPort, "proxy_port", -1, setProxyPort)
32 changes: 16 additions & 16 deletions lib/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Room::Private

//void inviteUser(User* u); // We might get it at some point in time.
void insertMemberIntoMap(User* u);
void renameMember(User* u, QString oldName);
void renameMember(User* u, const QString& oldName);
void removeMemberFromMap(const QString& username, User* u);

// This updates the room displayname field (which is the way a room
Expand All @@ -185,7 +185,7 @@ class Room::Private
void getPreviousContent(int limit = 10);

template <typename EventT>
const EventT* getCurrentState(QString stateKey = {}) const
const EventT* getCurrentState(const QString& stateKey = {}) const
{
static const EventT empty;
const auto* evt =
Expand Down Expand Up @@ -236,8 +236,8 @@ class Room::Private
* @param placement - position and direction of insertion: Older for
* historical messages, Newer for new ones
*/
Timeline::difference_type moveEventsToTimeline(RoomEventsRange events,
EventsPlacement placement);
Timeline::size_type moveEventsToTimeline(RoomEventsRange events,
EventsPlacement placement);

/**
* Remove events from the passed container that are already in the timeline
Expand Down Expand Up @@ -341,7 +341,7 @@ const QString& Room::id() const
QString Room::version() const
{
const auto v = d->getCurrentState<RoomCreateEvent>()->version();
return v.isEmpty() ? "1" : v;
return v.isEmpty() ? QStringLiteral("1") : v;
}

bool Room::isUnstable() const
Expand Down Expand Up @@ -546,8 +546,8 @@ Room::Changes Room::Private::promoteReadMarker(User* u, rev_iter_t newMarker,
{
const auto oldUnreadCount = unreadMessages;
QElapsedTimer et; et.start();
unreadMessages = count_if(eagerMarker, timeline.cend(),
std::bind(&Room::Private::isEventNotable, this, _1));
unreadMessages = int(count_if(eagerMarker, timeline.cend(),
std::bind(&Room::Private::isEventNotable, this, _1)));
if (et.nsecsElapsed() > profilerMinNsecs() / 10)
qCDebug(PROFILER) << "Recounting unread messages took" << et;

Expand Down Expand Up @@ -611,7 +611,7 @@ bool Room::canSwitchVersions() const

// TODO, #276: m.room.power_levels
const auto* plEvt =
d->currentState.value({"m.room.power_levels", ""});
d->currentState.value({QStringLiteral("m.room.power_levels"), {}});
if (!plEvt)
return true;

Expand All @@ -621,7 +621,7 @@ bool Room::canSwitchVersions() const
.value(localUser()->id()).toInt(
plJson.value("users_default"_ls).toInt());
const auto tombstonePowerLevel =
plJson.value("events").toObject()
plJson.value("events"_ls).toObject()
.value("m.room.tombstone"_ls).toInt(
plJson.value("state_default"_ls).toInt());
return currentUserLevel >= tombstonePowerLevel;
Expand Down Expand Up @@ -947,7 +947,7 @@ void Room::Private::setTags(TagsMap newTags)
}
tags = move(newTags);
qCDebug(MAIN) << "Room" << q->objectName() << "is tagged with"
<< q->tagNames().join(", ");
<< q->tagNames().join(QStringLiteral(", "));
emit q->tagsChanged();
}

Expand Down Expand Up @@ -1196,7 +1196,7 @@ void Room::Private::insertMemberIntoMap(User *u)
emit q->memberRenamed(namesakes.front());
}

void Room::Private::renameMember(User* u, QString oldName)
void Room::Private::renameMember(User* u, const QString& oldName)
{
if (u->name(q) == oldName)
{
Expand Down Expand Up @@ -1234,7 +1234,7 @@ inline auto makeErrorStr(const Event& e, QByteArray msg)
return msg.append("; event dump follows:\n").append(e.originalJson());
}

Room::Timeline::difference_type Room::Private::moveEventsToTimeline(
Room::Timeline::size_type Room::Private::moveEventsToTimeline(
RoomEventsRange events, EventsPlacement placement)
{
Q_ASSERT(!events.empty());
Expand Down Expand Up @@ -1407,7 +1407,7 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent)
return;
}
it->setDeparted();
emit q->pendingEventChanged(it - unsyncedEvents.begin());
emit q->pendingEventChanged(int(it - unsyncedEvents.begin()));
});
Room::connect(call, &BaseJob::failure, q,
std::bind(&Room::Private::onEventSendingFailure, this, txnId, call));
Expand All @@ -1423,7 +1423,7 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent)
}

it->setReachedServer(call->eventId());
emit q->pendingEventChanged(it - unsyncedEvents.begin());
emit q->pendingEventChanged(int(it - unsyncedEvents.begin()));
});
} else
onEventSendingFailure(txnId);
Expand All @@ -1442,7 +1442,7 @@ void Room::Private::onEventSendingFailure(const QString& txnId, BaseJob* call)
it->setSendingFailed(call
? call->statusCaption() % ": " % call->errorString()
: tr("The call could not be started"));
emit q->pendingEventChanged(it - unsyncedEvents.begin());
emit q->pendingEventChanged(int(it - unsyncedEvents.begin()));
}

QString Room::retryMessage(const QString& txnId)
Expand Down Expand Up @@ -2045,7 +2045,7 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events)
roomChanges |= q->processStateEvent(*eptr);

auto timelineSize = timeline.size();
auto totalInserted = 0;
size_t totalInserted = 0;
for (auto it = events.begin(); it != events.end();)
{
auto nextPendingPair = findFirstOf(it, events.end(),
Expand Down
21 changes: 12 additions & 9 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,21 @@ void SettingsGroup::remove(const QString& key)
Settings::remove(fullKey);
}

QMC_DEFINE_SETTING(AccountSettings, QString, deviceId, "device_id", "", setDeviceId)
QMC_DEFINE_SETTING(AccountSettings, QString, deviceName, "device_name", "", setDeviceName)
QMC_DEFINE_SETTING(AccountSettings, QString, deviceId, "device_id", {}, setDeviceId)
QMC_DEFINE_SETTING(AccountSettings, QString, deviceName, "device_name", {}, setDeviceName)
QMC_DEFINE_SETTING(AccountSettings, bool, keepLoggedIn, "keep_logged_in", false, setKeepLoggedIn)

static const auto HomeserverKey = QStringLiteral("homeserver");
static const auto AccessTokenKey = QStringLiteral("access_token");

QUrl AccountSettings::homeserver() const
{
return QUrl::fromUserInput(value("homeserver").toString());
return QUrl::fromUserInput(value(HomeserverKey).toString());
}

void AccountSettings::setHomeserver(const QUrl& url)
{
setValue("homeserver", url.toString());
setValue(HomeserverKey, url.toString());
}

QString AccountSettings::userId() const
Expand All @@ -105,19 +108,19 @@ QString AccountSettings::userId() const

QString AccountSettings::accessToken() const
{
return value("access_token").toString();
return value(AccessTokenKey).toString();
}

void AccountSettings::setAccessToken(const QString& accessToken)
{
qCWarning(MAIN) << "Saving access_token to QSettings is insecure."
" Developers, please save access_token separately.";
setValue("access_token", accessToken);
setValue(AccessTokenKey, accessToken);
}

void AccountSettings::clearAccessToken()
{
legacySettings.remove("access_token");
legacySettings.remove("device_id"); // Force the server to re-issue it
remove("access_token");
legacySettings.remove(AccessTokenKey);
legacySettings.remove(QStringLiteral("device_id")); // Force the server to re-issue it
remove(AccessTokenKey);
}
2 changes: 1 addition & 1 deletion lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type classname::propname() const \
\
void classname::setter(type newValue) \
{ \
setValue(QStringLiteral(qsettingname), newValue); \
setValue(QStringLiteral(qsettingname), std::move(newValue)); \
} \

class AccountSettings: public SettingsGroup
Expand Down
8 changes: 4 additions & 4 deletions lib/syncdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void JsonObjectConverter<RoomSummary>::fillFrom(const QJsonObject& jo,
{
fromJson(jo["m.joined_member_count"_ls], rs.joinedMemberCount);
fromJson(jo["m.invited_member_count"_ls], rs.invitedMemberCount);
fromJson(jo["m.heroes"], rs.heroes);
fromJson(jo["m.heroes"_ls], rs.heroes);
}

template <typename EventsArrayT, typename StrT>
Expand All @@ -85,7 +85,7 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
const QJsonObject& room_)
: roomId(roomId_)
, joinState(joinState_)
, summary(fromJson<RoomSummary>(room_["summary"]))
, summary(fromJson<RoomSummary>(room_["summary"_ls]))
, state(load<StateEvents>(room_, joinState == JoinState::Invite
? "invite_state"_ls : "state"_ls))
{
Expand Down Expand Up @@ -121,8 +121,8 @@ SyncData::SyncData(const QString& cacheFileName)
QFileInfo cacheFileInfo { cacheFileName };
auto json = loadJson(cacheFileName);
auto requiredVersion = std::get<0>(cacheVersion());
auto actualVersion = json.value("cache_version").toObject()
.value("major").toInt();
auto actualVersion = json.value("cache_version"_ls).toObject()
.value("major"_ls).toInt();
if (actualVersion == requiredVersion)
parseJson(json, cacheFileInfo.absolutePath() + '/');
else
Expand Down
Loading

0 comments on commit 1c5696e

Please sign in to comment.