Applied project style to multiple files

This commit is contained in:
fourtf 2018-07-06 18:10:21 +02:00
parent 3993708164
commit 535c0616a3
26 changed files with 149 additions and 157 deletions

View file

@ -17,10 +17,10 @@
namespace chatterino { namespace chatterino {
Channel::Channel(const QString &_name, Type _type) Channel::Channel(const QString &_name, Type type)
: name(_name) : name(_name)
, completionModel(this->name) , completionModel(this->name)
, type_(_type) , type_(type)
{ {
QObject::connect(&this->clearCompletionModelTimer_, &QTimer::timeout, [this]() { QObject::connect(&this->clearCompletionModelTimer_, &QTimer::timeout, [this]() {
this->completionModel.clearExpiredStrings(); // this->completionModel.clearExpiredStrings(); //

View file

@ -29,7 +29,7 @@ public:
Misc Misc
}; };
explicit Channel(const QString &_name, Type type_); explicit Channel(const QString &name, Type type);
virtual ~Channel(); virtual ~Channel();
pajlada::Signals::Signal<const QString &, const QString &, bool &> sendMessageSignal; pajlada::Signals::Signal<const QString &, const QString &, bool &> sendMessageSignal;

View file

@ -11,14 +11,14 @@ template <typename Type>
class ChatterinoSetting : public pajlada::Settings::Setting<Type> class ChatterinoSetting : public pajlada::Settings::Setting<Type>
{ {
public: public:
ChatterinoSetting(const std::string &_path) ChatterinoSetting(const std::string &path)
: pajlada::Settings::Setting<Type>(_path) : pajlada::Settings::Setting<Type>(path)
{ {
_registerSetting(this->data); _registerSetting(this->data);
} }
ChatterinoSetting(const std::string &_path, const Type &_defaultValue) ChatterinoSetting(const std::string &path, const Type &defaultValue)
: pajlada::Settings::Setting<Type>(_path, _defaultValue) : pajlada::Settings::Setting<Type>(path, defaultValue)
{ {
_registerSetting(this->data); _registerSetting(this->data);
} }

View file

@ -73,8 +73,8 @@ bool CompletionModel::TaggedString::operator<(const TaggedString &that) const
// -- CompletionModel // -- CompletionModel
CompletionModel::CompletionModel(const QString &_channelName) CompletionModel::CompletionModel(const QString &channelName)
: channelName_(_channelName) : channelName_(channelName)
{ {
} }

View file

@ -45,7 +45,7 @@ class CompletionModel : public QAbstractListModel
}; };
public: public:
CompletionModel(const QString &_channelName); CompletionModel(const QString &channelName);
virtual int columnCount(const QModelIndex &) const override; virtual int columnCount(const QModelIndex &) const override;
virtual QVariant data(const QModelIndex &index, int) const override; virtual QVariant data(const QModelIndex &index, int) const override;

View file

@ -5,8 +5,8 @@
namespace chatterino { namespace chatterino {
EmoteData::EmoteData(Image *_image) EmoteData::EmoteData(Image *image)
: image1x(_image) : image1x(image)
{ {
} }

View file

@ -8,7 +8,7 @@ namespace chatterino {
struct EmoteData { struct EmoteData {
EmoteData() = default; EmoteData() = default;
EmoteData(Image *_image); EmoteData(Image *image);
// Emotes must have a 1x image to be valid // Emotes must have a 1x image to be valid
bool isValid() const; bool isValid() const;

View file

@ -24,9 +24,9 @@ void NetworkRequest::setRequestType(RequestType newRequestType)
this->data.requestType = newRequestType; this->data.requestType = newRequestType;
} }
void NetworkRequest::setCaller(const QObject *_caller) void NetworkRequest::setCaller(const QObject *caller)
{ {
this->data.caller = _caller; this->data.caller = caller;
} }
void NetworkRequest::setOnReplyCreated(std::function<void(QNetworkReply *)> f) void NetworkRequest::setOnReplyCreated(std::function<void(QNetworkReply *)> f)

View file

@ -135,7 +135,7 @@ public:
} }
void setUseQuickLoadCache(bool value); void setUseQuickLoadCache(bool value);
void setCaller(const QObject *_caller); void setCaller(const QObject *caller);
void setOnReplyCreated(std::function<void(QNetworkReply *)> f); void setOnReplyCreated(std::function<void(QNetworkReply *)> f);
void setRawHeader(const char *headerName, const char *value); void setRawHeader(const char *headerName, const char *value);
void setRawHeader(const char *headerName, const QByteArray &value); void setRawHeader(const char *headerName, const QByteArray &value);

View file

@ -12,23 +12,23 @@ public:
{ {
} }
Property(const T &_value) Property(const T &value)
: value(_value) : value_(value)
{ {
} }
T &operator=(const T &f) T &operator=(const T &f)
{ {
return value = f; return value_ = f;
} }
operator T const &() const operator T const &() const
{ {
return value; return value_;
} }
protected: protected:
T value; T value_;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -10,9 +10,7 @@ template <>
struct Serialize<QString> { struct Serialize<QString> {
static rapidjson::Value get(const QString &value, rapidjson::Document::AllocatorType &a) static rapidjson::Value get(const QString &value, rapidjson::Document::AllocatorType &a)
{ {
rapidjson::Value ret(value.toUtf8(), a); return rapidjson::Value(value.toUtf8(), a);
return ret;
} }
}; };
@ -27,10 +25,7 @@ struct Deserialize<QString> {
} }
try { try {
const char *str = value.GetString(); return QString::fromUtf8(value.GetString(), value.GetStringLength());
auto strLen = value.GetStringLength();
return QString::fromUtf8(str, strLen);
} catch (const std::exception &) { } catch (const std::exception &) {
// int x = 5; // int x = 5;
} catch (...) { } catch (...) {

View file

@ -23,10 +23,10 @@ class ReadOnlySignalVector : boost::noncopyable
public: public:
ReadOnlySignalVector() ReadOnlySignalVector()
{ {
QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, QObject::connect(&this->itemsChangedTimer_, &QTimer::timeout,
[this] { this->delayedItemsChanged.invoke(); }); [this] { this->delayedItemsChanged.invoke(); });
this->itemsChangedTimer.setInterval(100); this->itemsChangedTimer_.setInterval(100);
this->itemsChangedTimer.setSingleShot(true); this->itemsChangedTimer_.setSingleShot(true);
} }
virtual ~ReadOnlySignalVector() = default; virtual ~ReadOnlySignalVector() = default;
@ -38,23 +38,23 @@ public:
{ {
assertInGuiThread(); assertInGuiThread();
return this->vector; return this->vector_;
} }
void invokeDelayedItemsChanged() void invokeDelayedItemsChanged()
{ {
assertInGuiThread(); assertInGuiThread();
if (!this->itemsChangedTimer.isActive()) { if (!this->itemsChangedTimer_.isActive()) {
itemsChangedTimer.start(); this->itemsChangedTimer_.start();
} }
} }
virtual bool isSorted() const = 0; virtual bool isSorted() const = 0;
protected: protected:
std::vector<TVectorItem> vector; std::vector<TVectorItem> vector_;
QTimer itemsChangedTimer; QTimer itemsChangedTimer_;
}; };
template <typename TVectorItem> template <typename TVectorItem>
@ -68,10 +68,10 @@ public:
void removeItem(int index, void *caller = nullptr) void removeItem(int index, void *caller = nullptr)
{ {
assertInGuiThread(); assertInGuiThread();
assert(index >= 0 && index < this->vector.size()); assert(index >= 0 && index < this->vector_.size());
TVectorItem item = this->vector[index]; TVectorItem item = this->vector_[index];
this->vector.erase(this->vector.begin() + index); this->vector_.erase(this->vector_.begin() + index);
SignalVectorItemArgs<TVectorItem> args{item, index, caller}; SignalVectorItemArgs<TVectorItem> args{item, index, caller};
this->itemRemoved.invoke(args); this->itemRemoved.invoke(args);
@ -92,12 +92,12 @@ public:
{ {
assertInGuiThread(); assertInGuiThread();
if (index == -1) { if (index == -1) {
index = this->vector.size(); index = this->vector_.size();
} else { } else {
assert(index >= 0 && index <= this->vector.size()); assert(index >= 0 && index <= this->vector_.size());
} }
this->vector.insert(this->vector.begin() + index, item); this->vector_.insert(this->vector_.begin() + index, item);
SignalVectorItemArgs<TVectorItem> args{item, index, caller}; SignalVectorItemArgs<TVectorItem> args{item, index, caller};
this->itemInserted.invoke(args); this->itemInserted.invoke(args);
@ -119,9 +119,9 @@ public:
{ {
assertInGuiThread(); assertInGuiThread();
auto it = std::lower_bound(this->vector.begin(), this->vector.end(), item, Compare{}); auto it = std::lower_bound(this->vector_.begin(), this->vector_.end(), item, Compare{});
int index = it - this->vector.begin(); int index = it - this->vector_.begin();
this->vector.insert(it, item); this->vector_.insert(it, item);
SignalVectorItemArgs<TVectorItem> args{item, index, caller}; SignalVectorItemArgs<TVectorItem> args{item, index, caller};
this->itemInserted.invoke(args); this->itemInserted.invoke(args);

View file

@ -16,16 +16,16 @@ class SignalVectorModel : public QAbstractTableModel, pajlada::Signals::SignalHo
public: public:
SignalVectorModel(int columnCount, QObject *parent = nullptr) SignalVectorModel(int columnCount, QObject *parent = nullptr)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
, _columnCount(columnCount) , columnCount_(columnCount)
{ {
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
this->_headerData.emplace_back(); this->headerData_.emplace_back();
} }
} }
void init(BaseSignalVector<TVectorItem> *vec) void init(BaseSignalVector<TVectorItem> *vec)
{ {
this->vector = vec; this->vector_ = vec;
auto insert = [this](const SignalVectorItemArgs<TVectorItem> &args) { auto insert = [this](const SignalVectorItemArgs<TVectorItem> &args) {
if (args.caller == this) { if (args.caller == this) {
@ -33,7 +33,7 @@ public:
} }
// get row index // get row index
int index = this->getModelIndexFromVectorIndex(args.index); int index = this->getModelIndexFromVectorIndex(args.index);
assert(index >= 0 && index <= this->rows.size()); assert(index >= 0 && index <= this->rows_.size());
// get row items // get row items
std::vector<QStandardItem *> row = this->createRow(); std::vector<QStandardItem *> row = this->createRow();
@ -43,7 +43,7 @@ public:
index = this->beforeInsert(args.item, row, index); index = this->beforeInsert(args.item, row, index);
this->beginInsertRows(QModelIndex(), index, index); this->beginInsertRows(QModelIndex(), index, index);
this->rows.insert(this->rows.begin() + index, Row(row, args.item)); this->rows_.insert(this->rows_.begin() + index, Row(row, args.item));
this->endInsertRows(); this->endInsertRows();
}; };
@ -62,13 +62,13 @@ public:
} }
int row = this->getModelIndexFromVectorIndex(args.index); int row = this->getModelIndexFromVectorIndex(args.index);
assert(row >= 0 && row <= this->rows.size()); assert(row >= 0 && row <= this->rows_.size());
// remove row // remove row
std::vector<QStandardItem *> items = std::move(this->rows[row].items); std::vector<QStandardItem *> items = std::move(this->rows_[row].items);
this->beginRemoveRows(QModelIndex(), row, row); this->beginRemoveRows(QModelIndex(), row, row);
this->rows.erase(this->rows.begin() + row); this->rows_.erase(this->rows_.begin() + row);
this->endRemoveRows(); this->endRemoveRows();
this->afterRemoved(args.item, items, row); this->afterRemoved(args.item, items, row);
@ -83,7 +83,7 @@ public:
virtual ~SignalVectorModel() virtual ~SignalVectorModel()
{ {
for (Row &row : this->rows) { for (Row &row : this->rows_) {
for (QStandardItem *item : row.items) { for (QStandardItem *item : row.items) {
delete item; delete item;
} }
@ -92,28 +92,28 @@ public:
int rowCount(const QModelIndex &parent) const override int rowCount(const QModelIndex &parent) const override
{ {
return this->rows.size(); return this->rows_.size();
} }
int columnCount(const QModelIndex &parent) const override int columnCount(const QModelIndex &parent) const override
{ {
return this->_columnCount; return this->columnCount_;
} }
QVariant data(const QModelIndex &index, int role) const override QVariant data(const QModelIndex &index, int role) const override
{ {
int row = index.row(), column = index.column(); int row = index.row(), column = index.column();
assert(row >= 0 && row < this->rows.size() && column >= 0 && column < this->_columnCount); assert(row >= 0 && row < this->rows_.size() && column >= 0 && column < this->columnCount_);
return rows[row].items[column]->data(role); return rows_[row].items[column]->data(role);
} }
bool setData(const QModelIndex &index, const QVariant &value, int role) override bool setData(const QModelIndex &index, const QVariant &value, int role) override
{ {
int row = index.row(), column = index.column(); int row = index.row(), column = index.column();
assert(row >= 0 && row < this->rows.size() && column >= 0 && column < this->_columnCount); assert(row >= 0 && row < this->rows_.size() && column >= 0 && column < this->columnCount_);
Row &rowItem = this->rows[row]; Row &rowItem = this->rows_[row];
rowItem.items[column]->setData(value, role); rowItem.items[column]->setData(value, role);
@ -121,12 +121,12 @@ public:
this->customRowSetData(rowItem.items, column, value, role); this->customRowSetData(rowItem.items, column, value, role);
} else { } else {
int vecRow = this->getVectorIndexFromModelIndex(row); int vecRow = this->getVectorIndexFromModelIndex(row);
this->vector->removeItem(vecRow, this); this->vector_->removeItem(vecRow, this);
assert(this->rows[row].original); assert(this->rows_[row].original);
TVectorItem item = TVectorItem item =
this->getItemFromRow(this->rows[row].items, this->rows[row].original.get()); this->getItemFromRow(this->rows_[row].items, this->rows_[row].original.get());
this->vector->insertItem(item, vecRow, this); this->vector_->insertItem(item, vecRow, this);
} }
return true; return true;
@ -138,8 +138,8 @@ public:
return QVariant(); return QVariant();
} }
auto it = this->_headerData[section].find(role); auto it = this->headerData_[section].find(role);
if (it == this->_headerData[section].end()) { if (it == this->headerData_[section].end()) {
return QVariant(); return QVariant();
} else { } else {
return it.value(); return it.value();
@ -153,7 +153,7 @@ public:
return false; return false;
} }
this->_headerData[section][role] = value; this->headerData_[section][role] = value;
emit this->headerDataChanged(Qt::Horizontal, section, section); emit this->headerDataChanged(Qt::Horizontal, section, section);
return true; return true;
@ -162,22 +162,22 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const override Qt::ItemFlags flags(const QModelIndex &index) const override
{ {
int row = index.row(), column = index.column(); int row = index.row(), column = index.column();
assert(row >= 0 && row < this->rows.size() && column >= 0 && column < this->_columnCount); assert(row >= 0 && row < this->rows_.size() && column >= 0 && column < this->columnCount_);
return this->rows[index.row()].items[index.column()]->flags(); return this->rows_[index.row()].items[index.column()]->flags();
} }
QStandardItem *getItem(int row, int column) QStandardItem *getItem(int row, int column)
{ {
assert(row >= 0 && row < this->rows.size() && column >= 0 && column < this->_columnCount); assert(row >= 0 && row < this->rows_.size() && column >= 0 && column < this->columnCount_);
return rows[row].items[column]; return rows_[row].items[column];
} }
void deleteRow(int row) void deleteRow(int row)
{ {
int signalVectorRow = this->getVectorIndexFromModelIndex(row); int signalVectorRow = this->getVectorIndexFromModelIndex(row);
this->vector->removeItem(signalVectorRow); this->vector_->removeItem(signalVectorRow);
} }
bool removeRows(int row, int count, const QModelIndex &parent) override bool removeRows(int row, int count, const QModelIndex &parent) override
@ -186,10 +186,10 @@ public:
return false; return false;
} }
assert(row >= 0 && row < this->rows.size()); assert(row >= 0 && row < this->rows_.size());
int signalVectorRow = this->getVectorIndexFromModelIndex(row); int signalVectorRow = this->getVectorIndexFromModelIndex(row);
this->vector->removeItem(signalVectorRow); this->vector_->removeItem(signalVectorRow);
return true; return true;
} }
@ -223,27 +223,27 @@ protected:
void insertCustomRow(std::vector<QStandardItem *> row, int index) void insertCustomRow(std::vector<QStandardItem *> row, int index)
{ {
assert(index >= 0 && index <= this->rows.size()); assert(index >= 0 && index <= this->rows_.size());
this->beginInsertRows(QModelIndex(), index, index); this->beginInsertRows(QModelIndex(), index, index);
this->rows.insert(this->rows.begin() + index, Row(std::move(row), true)); this->rows_.insert(this->rows_.begin() + index, Row(std::move(row), true));
this->endInsertRows(); this->endInsertRows();
} }
void removeCustomRow(int index) void removeCustomRow(int index)
{ {
assert(index >= 0 && index <= this->rows.size()); assert(index >= 0 && index <= this->rows_.size());
assert(this->rows[index].isCustomRow); assert(this->rows_[index].isCustomRow);
this->beginRemoveRows(QModelIndex(), index, index); this->beginRemoveRows(QModelIndex(), index, index);
this->rows.erase(this->rows.begin() + index); this->rows_.erase(this->rows_.begin() + index);
this->endRemoveRows(); this->endRemoveRows();
} }
std::vector<QStandardItem *> createRow() std::vector<QStandardItem *> createRow()
{ {
std::vector<QStandardItem *> row; 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()); row.push_back(new QStandardItem());
} }
return row; return row;
@ -268,20 +268,20 @@ protected:
{ {
} }
}; };
std::vector<Row> rows;
private: private:
std::vector<QMap<int, QVariant>> _headerData; std::vector<QMap<int, QVariant>> headerData_;
BaseSignalVector<TVectorItem> *vector; BaseSignalVector<TVectorItem> *vector_;
std::vector<Row> rows_;
int _columnCount; int columnCount_;
// returns the related index of the SignalVector // returns the related index of the SignalVector
int getVectorIndexFromModelIndex(int index) int getVectorIndexFromModelIndex(int index)
{ {
int i = 0; int i = 0;
for (auto &row : this->rows) { for (auto &row : this->rows_) {
if (row.isCustomRow) { if (row.isCustomRow) {
index--; index--;
continue; continue;
@ -301,7 +301,7 @@ private:
{ {
int i = 0; int i = 0;
for (auto &row : this->rows) { for (auto &row : this->rows_) {
if (row.isCustomRow) { if (row.isCustomRow) {
index++; index++;
} }

View file

@ -13,7 +13,7 @@ class SimpleSignalVector
public: public:
SimpleSignalVector &operator=(std::vector<TValue> &other) SimpleSignalVector &operator=(std::vector<TValue> &other)
{ {
this->data = other; this->data_ = other;
this->updated.invoke(); this->updated.invoke();
@ -22,13 +22,13 @@ public:
operator std::vector<TValue> &() operator std::vector<TValue> &()
{ {
return this->data; return this->data_;
} }
pajlada::Signals::NoArgSignal updated; pajlada::Signals::NoArgSignal updated;
private: private:
std::vector<TValue> data; std::vector<TValue> data_;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -4,13 +4,13 @@
namespace chatterino { namespace chatterino {
Account::Account(ProviderId _providerId) Account::Account(ProviderId providerId)
: providerId(_providerId) : providerId_(providerId)
{ {
static QString twitch("Twitch"); static QString twitch("Twitch");
this->category = [&]() { this->category_ = [&]() {
switch (_providerId) { switch (providerId) {
case ProviderId::Twitch: case ProviderId::Twitch:
return twitch; return twitch;
} }
@ -20,12 +20,12 @@ Account::Account(ProviderId _providerId)
const QString &Account::getCategory() const const QString &Account::getCategory() const
{ {
return this->category; return this->category_;
} }
ProviderId Account::getProviderId() const ProviderId Account::getProviderId() const
{ {
return this->providerId; return this->providerId_;
} }
bool Account::operator<(const Account &other) const bool Account::operator<(const Account &other) const
@ -33,7 +33,7 @@ bool Account::operator<(const Account &other) const
QString a = this->toString(); QString a = this->toString();
QString b = other.toString(); QString b = other.toString();
return std::tie(this->category, a) < std::tie(other.category, b); return std::tie(this->category_, a) < std::tie(other.category_, b);
} }
} // namespace chatterino } // namespace chatterino

View file

@ -19,8 +19,8 @@ public:
bool operator<(const Account &other) const; bool operator<(const Account &other) const;
private: private:
ProviderId providerId; ProviderId providerId_;
QString category; QString category_;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -7,7 +7,7 @@ namespace chatterino {
AccountController::AccountController() AccountController::AccountController()
{ {
this->twitch.accounts.itemInserted.connect([this](const auto &args) { this->twitch.accounts.itemInserted.connect([this](const auto &args) {
this->accounts.insertItem(std::dynamic_pointer_cast<Account>(args.item)); this->accounts_.insertItem(std::dynamic_pointer_cast<Account>(args.item));
}); });
this->twitch.accounts.itemRemoved.connect([this](const auto &args) { this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
@ -16,11 +16,11 @@ AccountController::AccountController()
auto it = std::find(accs.begin(), accs.end(), args.item); auto it = std::find(accs.begin(), accs.end(), args.item);
assert(it != accs.end()); assert(it != accs.end());
this->accounts.removeItem(it - accs.begin()); this->accounts_.removeItem(it - accs.begin());
} }
}); });
this->accounts.itemRemoved.connect([this](const auto &args) { this->accounts_.itemRemoved.connect([this](const auto &args) {
switch (args.item->getProviderId()) { switch (args.item->getProviderId()) {
case ProviderId::Twitch: { case ProviderId::Twitch: {
auto &accs = this->twitch.accounts.getVector(); auto &accs = this->twitch.accounts.getVector();
@ -42,7 +42,7 @@ AccountModel *AccountController::createModel(QObject *parent)
{ {
AccountModel *model = new AccountModel(parent); AccountModel *model = new AccountModel(parent);
model->init(&this->accounts); model->init(&this->accounts_);
return model; return model;
} }

View file

@ -23,7 +23,7 @@ public:
TwitchAccountManager twitch; TwitchAccountManager twitch;
private: private:
SortedSignalVector<std::shared_ptr<Account>, SharedPtrElementLess<Account>> accounts; SortedSignalVector<std::shared_ptr<Account>, SharedPtrElementLess<Account>> accounts_;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -27,7 +27,7 @@ void AccountModel::getRowFromItem(const std::shared_ptr<Account> &item,
int AccountModel::beforeInsert(const std::shared_ptr<Account> &item, int AccountModel::beforeInsert(const std::shared_ptr<Account> &item,
std::vector<QStandardItem *> &row, int proposedIndex) std::vector<QStandardItem *> &row, int proposedIndex)
{ {
if (this->categoryCount[item->getCategory()]++ == 0) { if (this->categoryCount_[item->getCategory()]++ == 0) {
auto row = this->createRow(); auto row = this->createRow();
setStringItem(row[0], item->getCategory(), false, false); setStringItem(row[0], item->getCategory(), false, false);
@ -44,11 +44,11 @@ int AccountModel::beforeInsert(const std::shared_ptr<Account> &item,
void AccountModel::afterRemoved(const std::shared_ptr<Account> &item, void AccountModel::afterRemoved(const std::shared_ptr<Account> &item,
std::vector<QStandardItem *> &row, int index) std::vector<QStandardItem *> &row, int index)
{ {
auto it = this->categoryCount.find(item->getCategory()); auto it = this->categoryCount_.find(item->getCategory());
assert(it != this->categoryCount.end()); assert(it != this->categoryCount_.end());
if (it->second <= 1) { if (it->second <= 1) {
this->categoryCount.erase(it); this->categoryCount_.erase(it);
this->removeCustomRow(index - 1); this->removeCustomRow(index - 1);
} else { } else {
it->second--; it->second--;

View file

@ -33,7 +33,7 @@ protected:
friend class AccountController; friend class AccountController;
private: private:
std::unordered_map<QString, int> categoryCount; std::unordered_map<QString, int> categoryCount_;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -28,11 +28,11 @@ namespace chatterino {
CommandController::CommandController() CommandController::CommandController()
{ {
auto addFirstMatchToMap = [this](auto args) { auto addFirstMatchToMap = [this](auto args) {
this->commandsMap.remove(args.item.name); this->commandsMap_.remove(args.item.name);
for (const Command &cmd : this->items.getVector()) { for (const Command &cmd : this->items.getVector()) {
if (cmd.name == args.item.name) { if (cmd.name == args.item.name) {
this->commandsMap[cmd.name] = cmd; this->commandsMap_[cmd.name] = cmd;
break; break;
} }
} }
@ -45,9 +45,9 @@ CommandController::CommandController()
void CommandController::load() void CommandController::load()
{ {
auto app = getApp(); auto app = getApp();
this->filePath = app->paths->settingsDirectory + "/commands.txt"; this->filePath_ = app->paths->settingsDirectory + "/commands.txt";
QFile textFile(this->filePath); QFile textFile(this->filePath_);
if (!textFile.open(QIODevice::ReadOnly)) { if (!textFile.open(QIODevice::ReadOnly)) {
// No commands file created yet // No commands file created yet
return; return;
@ -68,9 +68,9 @@ void CommandController::load()
void CommandController::save() void CommandController::save()
{ {
QFile textFile(this->filePath); QFile textFile(this->filePath_);
if (!textFile.open(QIODevice::WriteOnly)) { if (!textFile.open(QIODevice::WriteOnly)) {
Log("[CommandController::saveCommands] Unable to open {} for writing", this->filePath); Log("[CommandController::saveCommands] Unable to open {} for writing", this->filePath_);
return; return;
} }
@ -95,7 +95,7 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
Command command; Command command;
{ {
std::lock_guard<std::mutex> lock(this->mutex); std::lock_guard<std::mutex> lock(this->mutex_);
if (words.length() == 0) { if (words.length() == 0) {
return text; return text;
@ -202,8 +202,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
} }
// check if custom command exists // check if custom command exists
auto it = this->commandsMap.find(commandName); auto it = this->commandsMap_.find(commandName);
if (it == this->commandsMap.end()) { if (it == this->commandsMap_.end()) {
return text; return text;
} }

View file

@ -28,10 +28,10 @@ public:
UnsortedSignalVector<Command> items; UnsortedSignalVector<Command> items;
private: private:
QMap<QString, Command> commandsMap; QMap<QString, Command> commandsMap_;
std::mutex mutex; std::mutex mutex_;
QString filePath; QString filePath_;
QString execCustomCommand(const QStringList &words, const Command &command); QString execCustomCommand(const QStringList &words, const Command &command);
}; };

View file

@ -13,10 +13,6 @@ namespace chatterino {
class HighlightBlacklistUser class HighlightBlacklistUser
{ {
QString pattern_;
bool isRegex_;
QRegularExpression regex_;
public: public:
bool operator==(const HighlightBlacklistUser &other) const bool operator==(const HighlightBlacklistUser &other) const
{ {
@ -58,6 +54,11 @@ public:
return subject.toLower() == this->pattern_.toLower(); return subject.toLower() == this->pattern_.toLower();
} }
private:
QString pattern_;
bool isRegex_;
QRegularExpression regex_;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -14,15 +14,15 @@ HighlightController::HighlightController()
void HighlightController::initialize() void HighlightController::initialize()
{ {
assert(!this->initialized); assert(!this->initialized_);
this->initialized = true; this->initialized_ = true;
for (const HighlightPhrase &phrase : this->highlightsSetting.getValue()) { for (const HighlightPhrase &phrase : this->highlightsSetting_.getValue()) {
this->phrases.appendItem(phrase); this->phrases.appendItem(phrase);
} }
this->phrases.delayedItemsChanged.connect([this] { // this->phrases.delayedItemsChanged.connect([this] { //
this->highlightsSetting.setValue(this->phrases.getVector()); this->highlightsSetting_.setValue(this->phrases.getVector());
}); });
} }

View file

@ -33,11 +33,11 @@ public:
void addHighlight(const MessagePtr &msg); void addHighlight(const MessagePtr &msg);
private: private:
bool initialized = false; bool initialized_ = false;
ChatterinoSetting<std::vector<HighlightPhrase>> highlightsSetting = { ChatterinoSetting<std::vector<HighlightPhrase>> highlightsSetting_ = {
"/highlighting/highlights"}; "/highlighting/highlights"};
ChatterinoSetting<std::vector<HighlightPhrase>> blacklistSetting = {"/highlighting/blacklist"}; ChatterinoSetting<std::vector<HighlightPhrase>> blacklistSetting_ = {"/highlighting/blacklist"};
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -11,25 +11,19 @@ namespace chatterino {
class HighlightPhrase class HighlightPhrase
{ {
QString pattern;
bool alert;
bool sound;
bool _isRegex;
QRegularExpression regex;
public: public:
bool operator==(const HighlightPhrase &other) const bool operator==(const HighlightPhrase &other) const
{ {
return std::tie(this->pattern, this->sound, this->alert, this->_isRegex) == return std::tie(this->pattern_, this->sound_, this->alert_, this->isRegex_) ==
std::tie(other.pattern, other.sound, other.alert, other._isRegex); std::tie(other.pattern_, other.sound_, other.alert_, other.isRegex_);
} }
HighlightPhrase(const QString &_pattern, bool _alert, bool _sound, bool isRegex) HighlightPhrase(const QString &pattern, bool alert, bool sound, bool isRegex)
: pattern(_pattern) : pattern_(pattern)
, alert(_alert) , alert_(alert)
, sound(_sound) , sound_(sound)
, _isRegex(isRegex) , isRegex_(isRegex)
, regex(_isRegex ? _pattern : "\\b" + QRegularExpression::escape(_pattern) + "\\b", , regex_(isRegex_ ? pattern : "\\b" + QRegularExpression::escape(pattern) + "\\b",
QRegularExpression::CaseInsensitiveOption | QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption) QRegularExpression::UseUnicodePropertiesOption)
{ {
@ -37,35 +31,37 @@ public:
const QString &getPattern() const const QString &getPattern() const
{ {
return this->pattern; return this->pattern_;
} }
bool getAlert() const bool getAlert() const
{ {
return this->alert; return this->alert_;
} }
bool getSound() const bool getSound() const
{ {
return this->sound; return this->sound_;
} }
bool isRegex() const bool isRegex() const
{ {
return this->_isRegex; return this->isRegex_;
} }
bool isValid() const bool isValid() const
{ {
return !this->pattern.isEmpty() && this->regex.isValid(); return !this->pattern_.isEmpty() && this->regex_.isValid();
} }
bool isMatch(const QString &subject) const bool isMatch(const QString &subject) const
{ {
return this->isValid() && this->regex.match(subject).hasMatch(); return this->isValid() && this->regex_.match(subject).hasMatch();
} }
// const QRegularExpression &getRegex() const private:
// { QString pattern_;
// return this->regex; bool alert_;
// } bool sound_;
bool isRegex_;
QRegularExpression regex_;
}; };
} // namespace chatterino } // namespace chatterino