added brace wrapping after if and for

This commit is contained in:
fourtf
2018-10-21 13:43:02 +02:00
parent c6e1ec3c71
commit e259b9e39f
138 changed files with 4738 additions and 2237 deletions
+31 -16
View File
@@ -65,17 +65,20 @@ void Channel::addMessage(MessagePtr message,
MessagePtr deleted;
const QString &username = message->loginName;
if (!username.isEmpty()) {
if (!username.isEmpty())
{
// TODO: Add recent chatters display name
this->addRecentChatter(message);
}
// FOURTF: change this when adding more providers
if (this->isTwitchChannel()) {
if (this->isTwitchChannel())
{
app->logging->addMessage(this->name_, message);
}
if (this->messages_.pushBack(message, deleted)) {
if (this->messages_.pushBack(message, deleted))
{
this->messageRemovedFromStart.invoke(deleted);
}
@@ -93,15 +96,18 @@ void Channel::addOrReplaceTimeout(MessagePtr message)
QTime minimumTime = QTime::currentTime().addSecs(-5);
for (int i = snapshotLength - 1; i >= end; --i) {
for (int i = snapshotLength - 1; i >= end; --i)
{
auto &s = snapshot[i];
if (s->parseTime < minimumTime) {
if (s->parseTime < minimumTime)
{
break;
}
if (s->flags.has(MessageFlag::Untimeout) &&
s->timeoutUser == message->timeoutUser) {
s->timeoutUser == message->timeoutUser)
{
break;
}
@@ -139,17 +145,20 @@ void Channel::addOrReplaceTimeout(MessagePtr message)
}
// disable the messages from the user
for (int i = 0; i < snapshotLength; i++) {
for (int i = 0; i < snapshotLength; i++)
{
auto &s = snapshot[i];
if (s->flags.hasNone({MessageFlag::Timeout, MessageFlag::Untimeout}) &&
s->loginName == message->timeoutUser) {
s->loginName == message->timeoutUser)
{
// FOURTF: disabled for now
// PAJLADA: Shitty solution described in Message.hpp
s->flags.set(MessageFlag::Disabled);
}
}
if (addMessage) {
if (addMessage)
{
this->addMessage(message);
}
@@ -161,10 +170,11 @@ void Channel::disableAllMessages()
{
LimitedQueueSnapshot<MessagePtr> snapshot = this->getMessageSnapshot();
int snapshotLength = snapshot.getLength();
for (int i = 0; i < snapshotLength; i++) {
for (int i = 0; i < snapshotLength; i++)
{
auto &message = snapshot[i];
if (message->flags.hasAny(
{MessageFlag::System, MessageFlag::Timeout})) {
if (message->flags.hasAny({MessageFlag::System, MessageFlag::Timeout}))
{
continue;
}
@@ -178,7 +188,8 @@ void Channel::addMessagesAtStart(std::vector<MessagePtr> &_messages)
std::vector<MessagePtr> addedMessages =
this->messages_.pushFront(_messages);
if (addedMessages.size() != 0) {
if (addedMessages.size() != 0)
{
this->messagesAddedAtStart.invoke(addedMessages);
}
}
@@ -187,7 +198,8 @@ void Channel::replaceMessage(MessagePtr message, MessagePtr replacement)
{
int index = this->messages_.replaceItem(message, replacement);
if (index >= 0) {
if (index >= 0)
{
this->messageReplaced.invoke((size_t)index, replacement);
}
}
@@ -276,9 +288,12 @@ pajlada::Signals::NoArgSignal &IndirectChannel::getChannelChanged()
Channel::Type IndirectChannel::getType()
{
if (this->data_->type == Channel::Type::Direct) {
if (this->data_->type == Channel::Type::Direct)
{
return this->get()->getType();
} else {
}
else
{
return this->data_->type;
}
}
+39 -20
View File
@@ -33,14 +33,16 @@ bool CompletionModel::TaggedString::isEmote() const
bool CompletionModel::TaggedString::operator<(const TaggedString &that) const
{
if (this->isEmote() != that.isEmote()) {
if (this->isEmote() != that.isEmote())
{
return this->isEmote();
}
// try comparing insensitively, if they are the same then senstively
// (fixes order of LuL and LUL)
int k = QString::compare(this->string, that.string, Qt::CaseInsensitive);
if (k == 0) return this->string > that.string;
if (k == 0)
return this->string > that.string;
return k < 0;
}
@@ -79,17 +81,21 @@ void CompletionModel::refresh(const QString &prefix)
std::lock_guard<std::mutex> guard(this->itemsMutex_);
this->items_.clear();
if (prefix.length() < 2) return;
if (prefix.length() < 2)
return;
auto addString = [&](const QString &str, TaggedString::Type type) {
if (str.startsWith(prefix, Qt::CaseInsensitive))
this->items_.emplace(str + " ", type);
};
if (auto channel = dynamic_cast<TwitchChannel *>(&this->channel_)) {
if (auto channel = dynamic_cast<TwitchChannel *>(&this->channel_))
{
// account emotes
if (auto account = getApp()->accounts->twitch.getCurrent()) {
for (const auto &emote : account->accessEmotes()->allEmoteNames) {
if (auto account = getApp()->accounts->twitch.getCurrent())
{
for (const auto &emote : account->accessEmotes()->allEmoteNames)
{
// XXX: No way to discern between a twitch global emote and sub
// emote right now
addString(emote.string, TaggedString::Type::TwitchGlobalEmote);
@@ -97,60 +103,73 @@ void CompletionModel::refresh(const QString &prefix)
}
// Usernames
if (prefix.length() >= UsernameSet::PrefixLength) {
if (prefix.length() >= UsernameSet::PrefixLength)
{
auto usernames = channel->accessChatters();
QString usernamePrefix = prefix;
if (usernamePrefix.startsWith("@")) {
if (usernamePrefix.startsWith("@"))
{
usernamePrefix.remove(0, 1);
for (const auto &name :
usernames->subrange(Prefix(usernamePrefix))) {
usernames->subrange(Prefix(usernamePrefix)))
{
addString("@" + name, TaggedString::Type::Username);
}
} else {
}
else
{
for (const auto &name :
usernames->subrange(Prefix(usernamePrefix))) {
usernames->subrange(Prefix(usernamePrefix)))
{
addString(name, TaggedString::Type::Username);
}
}
}
// Bttv Global
for (auto &emote : *channel->globalBttv().emotes()) {
for (auto &emote : *channel->globalBttv().emotes())
{
addString(emote.first.string, TaggedString::Type::BTTVChannelEmote);
}
// Ffz Global
for (auto &emote : *channel->globalFfz().emotes()) {
for (auto &emote : *channel->globalFfz().emotes())
{
addString(emote.first.string, TaggedString::Type::FFZChannelEmote);
}
// Bttv Channel
for (auto &emote : *channel->bttvEmotes()) {
for (auto &emote : *channel->bttvEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Ffz Channel
for (auto &emote : *channel->ffzEmotes()) {
for (auto &emote : *channel->ffzEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Emojis
if (prefix.startsWith(":")) {
if (prefix.startsWith(":"))
{
const auto &emojiShortCodes = getApp()->emotes->emojis.shortCodes;
for (auto &m : emojiShortCodes) {
for (auto &m : emojiShortCodes)
{
addString(":" + m + ":", TaggedString::Type::Emoji);
}
}
// Commands
for (auto &command : getApp()->commands->items.getVector()) {
for (auto &command : getApp()->commands->items.getVector())
{
addString(command.name, TaggedString::Command);
}
for (auto &command :
getApp()->commands->getDefaultTwitchCommandList()) {
for (auto &command : getApp()->commands->getDefaultTwitchCommandList())
{
addString(command, TaggedString::Command);
}
}
+8 -4
View File
@@ -21,7 +21,8 @@ public:
QMutexLocker lock(&this->mutex);
auto a = this->data.find(name);
if (a == this->data.end()) {
if (a == this->data.end())
{
return false;
}
@@ -35,7 +36,8 @@ public:
QMutexLocker lock(&this->mutex);
auto a = this->data.find(name);
if (a == this->data.end()) {
if (a == this->data.end())
{
TValue value = addLambda();
this->data.insert(name, value);
return value;
@@ -72,7 +74,8 @@ public:
QMapIterator<TKey, TValue> it(this->data);
while (it.hasNext()) {
while (it.hasNext())
{
it.next();
func(it.key(), it.value());
}
@@ -84,7 +87,8 @@ public:
QMutableMapIterator<TKey, TValue> it(this->data);
while (it.hasNext()) {
while (it.hasNext())
{
it.next();
func(it.key(), it.value());
}
+12 -6
View File
@@ -48,16 +48,21 @@ void DownloadManager::onDownloadProgress(qint64 bytesRead, qint64 bytesTotal)
void DownloadManager::onFinished(QNetworkReply *reply)
{
switch (reply->error()) {
case QNetworkReply::NoError: {
switch (reply->error())
{
case QNetworkReply::NoError:
{
qDebug("file is downloaded successfully.");
} break;
default: {
}
break;
default:
{
qDebug() << reply->errorString().toLatin1();
};
}
if (file->isOpen()) {
if (file->isOpen())
{
file->close();
file->deleteLater();
}
@@ -71,7 +76,8 @@ void DownloadManager::onReadyRead()
void DownloadManager::onReplyFinished()
{
if (file->isOpen()) {
if (file->isOpen())
{
file->close();
file->deleteLater();
}
+2 -1
View File
@@ -20,7 +20,8 @@ public:
FlagsEnum(std::initializer_list<T> flags)
{
for (auto flag : flags) {
for (auto flag : flags)
{
this->set(flag);
}
}
+8 -4
View File
@@ -20,12 +20,14 @@ NetworkData::~NetworkData()
QString NetworkData::getHash()
{
if (this->hash_.isEmpty()) {
if (this->hash_.isEmpty())
{
QByteArray bytes;
bytes.append(this->request_.url().toString());
for (const auto &header : this->request_.rawHeaderList()) {
for (const auto &header : this->request_.rawHeaderList())
{
bytes.append(header);
}
@@ -40,10 +42,12 @@ QString NetworkData::getHash()
void NetworkData::writeToCache(const QByteArray &bytes)
{
if (this->useQuickLoadCache_) {
if (this->useQuickLoadCache_)
{
QFile cachedFile(getPaths()->cacheDirectory() + "/" + this->getHash());
if (cachedFile.open(QIODevice::WriteOnly)) {
if (cachedFile.open(QIODevice::WriteOnly))
{
cachedFile.write(bytes);
cachedFile.close();
+49 -24
View File
@@ -93,7 +93,8 @@ void NetworkRequest::makeAuthorizedV5(const QString &clientID,
{
this->setRawHeader("Client-ID", clientID);
this->setRawHeader("Accept", "application/vnd.twitchtv.v5+json");
if (!oauthToken.isEmpty()) {
if (!oauthToken.isEmpty())
{
this->setRawHeader("Authorization", "OAuth " + oauthToken);
}
}
@@ -112,34 +113,45 @@ void NetworkRequest::execute()
{
this->executed_ = true;
switch (this->data->requestType_) {
case NetworkRequestType::Get: {
switch (this->data->requestType_)
{
case NetworkRequestType::Get:
{
// Get requests try to load from cache, then perform the request
if (this->data->useQuickLoadCache_) {
if (this->tryLoadCachedFile()) {
if (this->data->useQuickLoadCache_)
{
if (this->tryLoadCachedFile())
{
// Successfully loaded from cache
return;
}
}
this->doRequest();
} break;
}
break;
case NetworkRequestType::Put: {
case NetworkRequestType::Put:
{
// Put requests cannot be cached, therefore the request is called
// immediately
this->doRequest();
} break;
}
break;
case NetworkRequestType::Delete: {
case NetworkRequestType::Delete:
{
// Delete requests cannot be cached, therefore the request is called
// immediately
this->doRequest();
} break;
}
break;
default: {
default:
{
log("[Execute] Unhandled request type");
} break;
}
break;
}
}
@@ -153,12 +165,14 @@ Outcome NetworkRequest::tryLoadCachedFile()
QFile cachedFile(getPaths()->cacheDirectory() + "/" +
this->data->getHash());
if (!cachedFile.exists()) {
if (!cachedFile.exists())
{
// File didn't exist
return Failure;
}
if (!cachedFile.open(QIODevice::ReadOnly)) {
if (!cachedFile.open(QIODevice::ReadOnly))
{
// File could not be opened
return Failure;
}
@@ -190,7 +204,8 @@ void NetworkRequest::doRequest()
auto onUrlRequested = [data = this->data, timer = this->timer,
worker]() mutable {
auto reply = [&]() -> QNetworkReply * {
switch (data->requestType_) {
switch (data->requestType_)
{
case NetworkRequestType::Get:
return NetworkManager::accessManager.get(data->request_);
@@ -207,29 +222,35 @@ void NetworkRequest::doRequest()
}
}();
if (reply == nullptr) {
if (reply == nullptr)
{
log("Unhandled request type");
return;
}
if (timer->isStarted()) {
if (timer->isStarted())
{
timer->onTimeout(worker, [reply, data]() {
log("Aborted!");
reply->abort();
if (data->onError_) {
if (data->onError_)
{
data->onError_(-2);
}
});
}
if (data->onReplyCreated_) {
if (data->onReplyCreated_)
{
data->onReplyCreated_(reply);
}
auto handleReply = [data, timer, reply]() mutable {
// TODO(pajlada): A reply was received, kill the timeout timer
if (reply->error() != QNetworkReply::NetworkError::NoError) {
if (data->onError_) {
if (reply->error() != QNetworkReply::NetworkError::NoError)
{
if (data->onError_)
{
data->onError_(reply->error());
}
return;
@@ -242,7 +263,8 @@ void NetworkRequest::doRequest()
DebugCount::increase("http request success");
// log("starting {}", data->request_.url().toString());
if (data->onSuccess_) {
if (data->onSuccess_)
{
if (data->executeConcurrently)
QtConcurrent::run(
[onSuccess = std::move(data->onSuccess_),
@@ -255,7 +277,8 @@ void NetworkRequest::doRequest()
reply->deleteLater();
};
if (data->caller_ != nullptr) {
if (data->caller_ != nullptr)
{
QObject::connect(worker, &NetworkWorker::doneUrl, data->caller_,
handleReply);
QObject::connect(reply, &QNetworkReply::finished, worker,
@@ -264,7 +287,9 @@ void NetworkRequest::doRequest()
delete worker;
});
} else {
}
else
{
QObject::connect(reply, &QNetworkReply::finished, worker,
[handleReply, worker]() mutable {
handleReply();
+4 -2
View File
@@ -16,7 +16,8 @@ NetworkResult::NetworkResult(const QByteArray &data)
QJsonObject NetworkResult::parseJson() const
{
QJsonDocument jsonDoc(QJsonDocument::fromJson(this->data_));
if (jsonDoc.isNull()) {
if (jsonDoc.isNull())
{
return QJsonObject{};
}
@@ -30,7 +31,8 @@ rapidjson::Document NetworkResult::parseRapidJson() const
rapidjson::ParseResult result =
ret.Parse(this->data_.data(), this->data_.length());
if (result.Code() != rapidjson::kParseErrorNone) {
if (result.Code() != rapidjson::kParseErrorNone)
{
log("JSON parse error: {} ({})",
rapidjson::GetParseError_En(result.Code()), result.Offset());
return ret;
+2 -1
View File
@@ -10,7 +10,8 @@ namespace chatterino {
void NetworkTimer::start()
{
if (this->timeoutMS_ <= 0) {
if (this->timeoutMS_ <= 0)
{
return;
}
+7 -3
View File
@@ -45,7 +45,8 @@ public:
{
assertInGuiThread();
if (!this->itemsChangedTimer_.isActive()) {
if (!this->itemsChangedTimer_.isActive())
{
this->itemsChangedTimer_.start();
}
}
@@ -92,9 +93,12 @@ public:
void *caller = nullptr) override
{
assertInGuiThread();
if (index == -1) {
if (index == -1)
{
index = this->vector_.size();
} else {
}
else
{
assert(index >= 0 && index <= this->vector_.size());
}
+44 -21
View File
@@ -19,7 +19,8 @@ public:
: QAbstractTableModel(parent)
, columnCount_(columnCount)
{
for (int i = 0; i < columnCount; i++) {
for (int i = 0; i < columnCount; i++)
{
this->headerData_.emplace_back();
}
}
@@ -29,7 +30,8 @@ public:
this->vector_ = vec;
auto insert = [this](const SignalVectorItemArgs<TVectorItem> &args) {
if (args.caller == this) {
if (args.caller == this)
{
return;
}
// get row index
@@ -50,7 +52,8 @@ public:
};
int i = 0;
for (const TVectorItem &item : vec->getVector()) {
for (const TVectorItem &item : vec->getVector())
{
SignalVectorItemArgs<TVectorItem> args{item, i++, 0};
insert(args);
@@ -59,7 +62,8 @@ public:
this->managedConnect(vec->itemInserted, insert);
this->managedConnect(vec->itemRemoved, [this](auto args) {
if (args.caller == this) {
if (args.caller == this)
{
return;
}
@@ -76,7 +80,8 @@ public:
this->afterRemoved(args.item, items, row);
for (QStandardItem *item : items) {
for (QStandardItem *item : items)
{
delete item;
}
});
@@ -86,8 +91,10 @@ public:
virtual ~SignalVectorModel()
{
for (Row &row : this->rows_) {
for (QStandardItem *item : row.items) {
for (Row &row : this->rows_)
{
for (QStandardItem *item : row.items)
{
delete item;
}
}
@@ -123,9 +130,12 @@ public:
rowItem.items[column]->setData(value, role);
if (rowItem.isCustomRow) {
if (rowItem.isCustomRow)
{
this->customRowSetData(rowItem.items, column, value, role, row);
} else {
}
else
{
int vecRow = this->getVectorIndexFromModelIndex(row);
this->vector_->removeItem(vecRow, this);
@@ -141,14 +151,18 @@ public:
QVariant headerData(int section, Qt::Orientation orientation,
int role) const override
{
if (orientation != Qt::Horizontal) {
if (orientation != Qt::Horizontal)
{
return QVariant();
}
auto it = this->headerData_[section].find(role);
if (it == this->headerData_[section].end()) {
if (it == this->headerData_[section].end())
{
return QVariant();
} else {
}
else
{
return it.value();
}
}
@@ -157,7 +171,8 @@ public:
const QVariant &value,
int role = Qt::DisplayRole) override
{
if (orientation != Qt::Horizontal) {
if (orientation != Qt::Horizontal)
{
return false;
}
@@ -192,7 +207,8 @@ public:
bool removeRows(int row, int count, const QModelIndex &parent) override
{
if (count != 1) {
if (count != 1)
{
return false;
}
@@ -258,7 +274,8 @@ protected:
std::vector<QStandardItem *> createRow()
{
std::vector<QStandardItem *> row;
for (int i = 0; i < this->columnCount_; i++) {
for (int i = 0; i < this->columnCount_; i++)
{
row.push_back(new QStandardItem());
}
return row;
@@ -296,13 +313,16 @@ private:
{
int i = 0;
for (auto &row : this->rows_) {
if (row.isCustomRow) {
for (auto &row : this->rows_)
{
if (row.isCustomRow)
{
index--;
continue;
}
if (i == index) {
if (i == index)
{
return i;
}
i++;
@@ -316,12 +336,15 @@ private:
{
int i = 0;
for (auto &row : this->rows_) {
if (row.isCustomRow) {
for (auto &row : this->rows_)
{
if (row.isCustomRow)
{
index++;
}
if (i == index) {
if (i == index)
{
return i;
}
i++;
+2 -1
View File
@@ -32,7 +32,8 @@ public:
~AccessGuard()
{
if (this->isValid_) this->mutex_->unlock();
if (this->isValid_)
this->mutex_->unlock();
}
T *operator->() const
+14 -6
View File
@@ -21,11 +21,13 @@ UsernameSet::ConstIterator UsernameSet::end() const
UsernameSet::Range UsernameSet::subrange(const Prefix &prefix) const
{
auto it = this->firstKeyForPrefix.find(prefix);
if (it != this->firstKeyForPrefix.end()) {
if (it != this->firstKeyForPrefix.end())
{
auto start = this->items.find(it->second);
auto end = start;
while (end != this->items.end() && prefix.isStartOf(*end)) {
while (end != this->items.end() && prefix.isStartOf(*end))
{
end++;
}
return {start, end};
@@ -57,7 +59,8 @@ void UsernameSet::insertPrefix(const QString &value)
{
auto &string = this->firstKeyForPrefix[Prefix(value)];
if (string.isNull() || value < string) string = value;
if (string.isNull() || value < string)
string = value;
}
//
@@ -98,12 +101,17 @@ bool Prefix::operator==(const Prefix &other) const
bool Prefix::isStartOf(const QString &string) const
{
if (string.size() == 0) {
if (string.size() == 0)
{
return this->first == QChar('\0') && this->second == QChar('\0');
} else if (string.size() == 1) {
}
else if (string.size() == 1)
{
return this->first == string[0].toLower() &&
this->second == QChar('\0');
} else {
}
else
{
return this->first == string[0].toLower() &&
this->second == string[1].toLower();
}