changed to 80 max column

This commit is contained in:
fourtf
2018-08-06 21:17:03 +02:00
parent defa7e41fa
commit f71ff08e68
203 changed files with 3792 additions and 2405 deletions
+18 -10
View File
@@ -22,9 +22,10 @@ Channel::Channel(const QString &name, Type type)
, name_(name)
, type_(type)
{
QObject::connect(&this->clearCompletionModelTimer_, &QTimer::timeout, [this]() {
this->completionModel.clearExpiredStrings(); //
});
QObject::connect(&this->clearCompletionModelTimer_, &QTimer::timeout,
[this]() {
this->completionModel.clearExpiredStrings(); //
});
this->clearCompletionModelTimer_.start(60 * 1000);
}
@@ -65,7 +66,8 @@ void Channel::addMessage(MessagePtr message)
const QString &username = message->loginName;
if (!username.isEmpty()) {
// TODO: Add recent chatters display name. This should maybe be a setting
// TODO: Add recent chatters display name. This should maybe be a
// setting
this->addRecentChatter(message);
}
@@ -101,17 +103,21 @@ void Channel::addOrReplaceTimeout(MessagePtr message)
break;
}
if (s->flags.HasFlag(Message::Untimeout) && s->timeoutUser == message->timeoutUser) {
if (s->flags.HasFlag(Message::Untimeout) &&
s->timeoutUser == message->timeoutUser) {
break;
}
if (s->flags.HasFlag(Message::Timeout) && s->timeoutUser == message->timeoutUser) {
if (message->flags.HasFlag(Message::PubSub) && !s->flags.HasFlag(Message::PubSub)) {
if (s->flags.HasFlag(Message::Timeout) &&
s->timeoutUser == message->timeoutUser) {
if (message->flags.HasFlag(Message::PubSub) &&
!s->flags.HasFlag(Message::PubSub)) {
this->replaceMessage(s, message);
addMessage = false;
break;
}
if (!message->flags.HasFlag(Message::PubSub) && s->flags.HasFlag(Message::PubSub)) {
if (!message->flags.HasFlag(Message::PubSub) &&
s->flags.HasFlag(Message::PubSub)) {
addMessage = false;
break;
}
@@ -119,7 +125,8 @@ void Channel::addOrReplaceTimeout(MessagePtr message)
int count = s->count + 1;
MessagePtr replacement(Message::createSystemMessage(
message->searchText + QString(" (") + QString::number(count) + " times)"));
message->searchText + QString(" (") + QString::number(count) +
" times)"));
replacement->timeoutUser = message->timeoutUser;
replacement->count = count;
@@ -164,7 +171,8 @@ void Channel::disableAllMessages()
void Channel::addMessagesAtStart(std::vector<MessagePtr> &_messages)
{
std::vector<MessagePtr> addedMessages = this->messages_.pushFront(_messages);
std::vector<MessagePtr> addedMessages =
this->messages_.pushFront(_messages);
if (addedMessages.size() != 0) {
this->messagesAddedAtStart.invoke(addedMessages);
+4 -2
View File
@@ -32,7 +32,8 @@ public:
explicit Channel(const QString &name, Type type);
virtual ~Channel();
pajlada::Signals::Signal<const QString &, const QString &, bool &> sendMessageSignal;
pajlada::Signals::Signal<const QString &, const QString &, bool &>
sendMessageSignal;
pajlada::Signals::Signal<MessagePtr &> messageRemovedFromStart;
pajlada::Signals::Signal<MessagePtr &> messageAppended;
@@ -96,7 +97,8 @@ class IndirectChannel
};
public:
IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::Type::Direct)
IndirectChannel(ChannelPtr channel,
Channel::Type type = Channel::Type::Direct)
: data_(new Data(channel, type))
{
}
+4 -2
View File
@@ -25,8 +25,10 @@ inline QString qS(const std::string &string)
return QString::fromStdString(string);
}
const Qt::KeyboardModifiers showSplitOverlayModifiers = Qt::ControlModifier | Qt::AltModifier;
const Qt::KeyboardModifiers showAddSplitRegions = Qt::ControlModifier | Qt::AltModifier;
const Qt::KeyboardModifiers showSplitOverlayModifiers =
Qt::ControlModifier | Qt::AltModifier;
const Qt::KeyboardModifiers showAddSplitRegions =
Qt::ControlModifier | Qt::AltModifier;
const Qt::KeyboardModifiers showResizeHandlesModifiers = Qt::ControlModifier;
static const char *ANONYMOUS_USERNAME_LABEL ATTR_UNUSED = " - anonymous - ";
+21 -11
View File
@@ -111,26 +111,32 @@ void CompletionModel::refresh()
// User-specific: Twitch Emotes
if (auto account = app->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
this->addString(emote.string, TaggedString::Type::TwitchGlobalEmote);
// XXX: No way to discern between a twitch global emote and sub
// emote right now
this->addString(emote.string,
TaggedString::Type::TwitchGlobalEmote);
}
}
// // Global: BTTV Global Emotes
// std::vector<QString> &bttvGlobalEmoteCodes = app->emotes->bttv.globalEmoteNames_;
// for (const auto &m : bttvGlobalEmoteCodes) {
// std::vector<QString> &bttvGlobalEmoteCodes =
// app->emotes->bttv.globalEmoteNames_; for (const auto &m :
// bttvGlobalEmoteCodes) {
// this->addString(m, TaggedString::Type::BTTVGlobalEmote);
// }
// // Global: FFZ Global Emotes
// std::vector<QString> &ffzGlobalEmoteCodes = app->emotes->ffz.globalEmoteCodes;
// for (const auto &m : ffzGlobalEmoteCodes) {
// std::vector<QString> &ffzGlobalEmoteCodes =
// app->emotes->ffz.globalEmoteCodes; for (const auto &m :
// ffzGlobalEmoteCodes) {
// this->addString(m, TaggedString::Type::FFZGlobalEmote);
// }
// Channel emotes
if (auto channel = dynamic_cast<TwitchChannel *>(
getApp()->twitch2->getChannelOrEmptyByID(this->channelName_).get())) {
getApp()
->twitch2->getChannelOrEmptyByID(this->channelName_)
.get())) {
auto bttv = channel->accessBttvEmotes();
// auto it = bttv->begin();
// for (const auto &emote : *bttv) {
@@ -143,7 +149,8 @@ void CompletionModel::refresh()
// Channel-specific: FFZ Channel Emotes
for (const auto &emote : *channel->accessFfzEmotes()) {
this->addString(emote.second->name.string, TaggedString::Type::FFZChannelEmote);
this->addString(emote.second->name.string,
TaggedString::Type::FFZChannelEmote);
}
}
@@ -164,7 +171,8 @@ void CompletionModel::refresh()
// Channel-specific: Usernames
// fourtf: only works with twitch chat
// auto c = ChannelManager::getInstance().getTwitchChannel(this->channelName);
// auto c =
// ChannelManager::getInstance().getTwitchChannel(this->channelName);
// auto usernames = c->getUsernamesForCompletions();
// for (const auto &name : usernames) {
// assert(!name.displayName.isEmpty());
@@ -191,9 +199,11 @@ void CompletionModel::addUser(const QString &username)
auto add = [this](const QString &str) {
auto ts = this->createUser(str + " ");
// Always add a space at the end of completions
std::pair<std::set<TaggedString>::iterator, bool> p = this->emotes_.insert(ts);
std::pair<std::set<TaggedString>::iterator, bool> p =
this->emotes_.insert(ts);
if (!p.second) {
// No inseration was made, figure out if we need to replace the username.
// No inseration was made, figure out if we need to replace the
// username.
if (p.first->str > ts.str) {
// Replace lowercase version of name with mixed-case version
+2 -1
View File
@@ -65,7 +65,8 @@ public:
this->data.insert(name, value);
}
void each(std::function<void(const TKey &name, const TValue &value)> func) const
void each(
std::function<void(const TKey &name, const TValue &value)> func) const
{
QMutexLocker lock(&this->mutex);
+2 -2
View File
@@ -14,8 +14,8 @@ namespace chatterino {
// bool isValid() const;
// Image *getImage(float scale) const;
// // Link to the emote page i.e. https://www.frankerfacez.com/emoticon/144722-pajaCringe
// QString pageLink;
// // Link to the emote page i.e.
// https://www.frankerfacez.com/emoticon/144722-pajaCringe QString pageLink;
// Image *image1x = nullptr;
// Image *image2x = nullptr;
+6 -3
View File
@@ -45,9 +45,11 @@ LinkParser::LinkParser(const QString &unparsedString)
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))"
"|"
// host name
"(?:(?:[_a-z\\x{00a1}-\\x{ffff}0-9]-*)*[a-z\\x{00a1}-\\x{ffff}0-9]+)"
"(?:(?:[_a-z\\x{00a1}-\\x{ffff}0-9]-*)*[a-z\\x{00a1}-\\x{ffff}0-9]+"
")"
// domain name
"(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}0-9]-*)*[a-z\\x{00a1}-\\x{ffff}0-9]+)*"
"(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}0-9]-*)*[a-z\\x{00a1}-\\x{ffff}0-"
"9]+)*"
// TLD identifier
//"(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}]{2,}))"
"(?:[\\.](?:" +
@@ -61,7 +63,8 @@ LinkParser::LinkParser(const QString &unparsedString)
"(?:[/?#]\\S*)?"
"$";
return QRegularExpression(hyperlinkRegExp, QRegularExpression::CaseInsensitiveOption);
return QRegularExpression(hyperlinkRegExp,
QRegularExpression::CaseInsensitiveOption);
}();
this->match_ = linkRegex.match(unparsedString);
+2 -1
View File
@@ -30,7 +30,8 @@ QString NetworkData::getHash()
bytes.append(header);
}
QByteArray hashBytes(QCryptographicHash::hash(bytes, QCryptographicHash::Sha256));
QByteArray hashBytes(
QCryptographicHash::hash(bytes, QCryptographicHash::Sha256));
this->hash_ = hashBytes.toHex();
}
+25 -14
View File
@@ -11,7 +11,8 @@
namespace chatterino {
NetworkRequest::NetworkRequest(const std::string &url, NetworkRequestType requestType)
NetworkRequest::NetworkRequest(const std::string &url,
NetworkRequestType requestType)
: data(new NetworkData)
, timer(new NetworkTimer)
{
@@ -62,7 +63,8 @@ void NetworkRequest::setRawHeader(const char *headerName, const char *value)
this->data->request_.setRawHeader(headerName, value);
}
void NetworkRequest::setRawHeader(const char *headerName, const QByteArray &value)
void NetworkRequest::setRawHeader(const char *headerName,
const QByteArray &value)
{
this->data->request_.setRawHeader(headerName, value);
}
@@ -77,7 +79,8 @@ void NetworkRequest::setTimeout(int ms)
this->timer->timeoutMS_ = ms;
}
void NetworkRequest::makeAuthorizedV5(const QString &clientID, const QString &oauthToken)
void NetworkRequest::makeAuthorizedV5(const QString &clientID,
const QString &oauthToken)
{
this->setRawHeader("Client-ID", clientID);
this->setRawHeader("Accept", "application/vnd.twitchtv.v5+json");
@@ -114,12 +117,14 @@ void NetworkRequest::execute()
} break;
case NetworkRequestType::Put: {
// Put requests cannot be cached, therefore the request is called immediately
// Put requests cannot be cached, therefore the request is called
// immediately
this->doRequest();
} break;
case NetworkRequestType::Delete: {
// Delete requests cannot be cached, therefore the request is called immediately
// Delete requests cannot be cached, therefore the request is called
// immediately
this->doRequest();
} break;
@@ -152,7 +157,8 @@ Outcome NetworkRequest::tryLoadCachedFile()
cachedFile.close();
// XXX: If success is false, we should invalidate the cache file somehow/somewhere
// XXX: If success is false, we should invalidate the cache file
// somehow/somewhere
return outcome;
}
@@ -166,14 +172,16 @@ void NetworkRequest::doRequest()
this->timer->start();
auto onUrlRequested = [data = this->data, timer = this->timer, worker]() mutable {
auto onUrlRequested = [data = this->data, timer = this->timer,
worker]() mutable {
auto reply = [&]() -> QNetworkReply * {
switch (data->requestType_) {
case NetworkRequestType::Get:
return NetworkManager::NaM.get(data->request_);
case NetworkRequestType::Put:
return NetworkManager::NaM.put(data->request_, data->payload_);
return NetworkManager::NaM.put(data->request_,
data->payload_);
case NetworkRequestType::Delete:
return NetworkManager::NaM.deleteResource(data->request_);
@@ -221,12 +229,14 @@ void NetworkRequest::doRequest()
};
if (data->caller_ != nullptr) {
QObject::connect(worker, &NetworkWorker::doneUrl, data->caller_, handleReply);
QObject::connect(reply, &QNetworkReply::finished, worker, [worker]() mutable {
emit worker->doneUrl();
QObject::connect(worker, &NetworkWorker::doneUrl, data->caller_,
handleReply);
QObject::connect(reply, &QNetworkReply::finished, worker,
[worker]() mutable {
emit worker->doneUrl();
delete worker;
});
delete worker;
});
} else {
QObject::connect(reply, &QNetworkReply::finished, worker,
[handleReply, worker]() mutable {
@@ -237,7 +247,8 @@ void NetworkRequest::doRequest()
}
};
QObject::connect(&requester, &NetworkRequester::requestUrl, worker, onUrlRequested);
QObject::connect(&requester, &NetworkRequester::requestUrl, worker,
onUrlRequested);
emit requester.requestUrl();
}
+15 -9
View File
@@ -12,15 +12,18 @@ namespace chatterino {
class NetworkRequest
{
// Stores all data about the request that needs to be passed around to each part of the request
// Stores all data about the request that needs to be passed around to each
// part of the request
std::shared_ptr<NetworkData> data;
// Timer that tracks the timeout
// By default, there's no explicit timeout for the request
// to enable the timer, the "setTimeout" function needs to be called before execute is called
// to enable the timer, the "setTimeout" function needs to be called before
// execute is called
std::shared_ptr<NetworkTimer> timer;
// The NetworkRequest destructor will assert if executed_ hasn't been set to true before dying
// The NetworkRequest destructor will assert if executed_ hasn't been set to
// true before dying
bool executed_ = false;
public:
@@ -31,9 +34,11 @@ public:
NetworkRequest(NetworkRequest &&other) = default;
NetworkRequest &operator=(NetworkRequest &&other) = default;
explicit NetworkRequest(const std::string &url,
NetworkRequestType requestType = NetworkRequestType::Get);
explicit NetworkRequest(QUrl url, NetworkRequestType requestType = NetworkRequestType::Get);
explicit NetworkRequest(
const std::string &url,
NetworkRequestType requestType = NetworkRequestType::Get);
explicit NetworkRequest(
QUrl url, NetworkRequestType requestType = NetworkRequestType::Get);
~NetworkRequest();
@@ -50,14 +55,15 @@ public:
void setRawHeader(const char *headerName, const QByteArray &value);
void setRawHeader(const char *headerName, const QString &value);
void setTimeout(int ms);
void makeAuthorizedV5(const QString &clientID, const QString &oauthToken = QString());
void makeAuthorizedV5(const QString &clientID,
const QString &oauthToken = QString());
void execute();
private:
// Returns true if the file was successfully loaded from cache
// Returns false if the cache file either didn't exist, or it contained "invalid" data
// "invalid" is specified by the onSuccess callback
// Returns false if the cache file either didn't exist, or it contained
// "invalid" data "invalid" is specified by the onSuccess callback
Outcome tryLoadCachedFile();
void doRequest();
+4 -3
View File
@@ -27,11 +27,12 @@ rapidjson::Document NetworkResult::parseRapidJson() const
{
rapidjson::Document ret(rapidjson::kObjectType);
rapidjson::ParseResult result = ret.Parse(this->data_.data(), this->data_.length());
rapidjson::ParseResult result =
ret.Parse(this->data_.data(), this->data_.length());
if (result.Code() != rapidjson::kParseErrorNone) {
Log("JSON parse error: {} ({})", rapidjson::GetParseError_En(result.Code()),
result.Offset());
Log("JSON parse error: {} ({})",
rapidjson::GetParseError_En(result.Code()), result.Offset());
return ret;
}
+2 -1
View File
@@ -28,7 +28,8 @@ bool NetworkTimer::isStarted() const
return this->started_;
}
void NetworkTimer::onTimeout(NetworkWorker *worker, std::function<void()> cb) const
void NetworkTimer::onTimeout(NetworkWorker *worker,
std::function<void()> cb) const
{
assert(this->timer_ != nullptr);
assert(worker != nullptr);
+2 -1
View File
@@ -59,7 +59,8 @@ public:
return !this->hasElement();
}
template <typename X = T, typename = std::enable_if_t<!std::is_const<X>::value>>
template <typename X = T,
typename = std::enable_if_t<!std::is_const<X>::value>>
operator NullablePtr<const T>() const
{
return NullablePtr<const T>(this->element_);
+6 -3
View File
@@ -8,7 +8,8 @@ namespace Settings {
template <>
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)
{
return rapidjson::Value(value.toUtf8(), a);
}
@@ -20,12 +21,14 @@ struct Deserialize<QString> {
{
if (!value.IsString()) {
PAJLADA_REPORT_ERROR(error)
PAJLADA_THROW_EXCEPTION("Deserialized rapidjson::Value is not a string");
PAJLADA_THROW_EXCEPTION(
"Deserialized rapidjson::Value is not a string");
return QString{};
}
try {
return QString::fromUtf8(value.GetString(), value.GetStringLength());
return QString::fromUtf8(value.GetString(),
value.GetStringLength());
} catch (const std::exception &) {
// int x = 5;
} catch (...) {
+6 -3
View File
@@ -88,7 +88,8 @@ template <typename TVectorItem>
class UnsortedSignalVector : public BaseSignalVector<TVectorItem>
{
public:
virtual int insertItem(const TVectorItem &item, int index = -1, void *caller = nullptr) override
virtual int insertItem(const TVectorItem &item, int index = -1,
void *caller = nullptr) override
{
assertInGuiThread();
if (index == -1) {
@@ -115,11 +116,13 @@ template <typename TVectorItem, typename Compare>
class SortedSignalVector : public BaseSignalVector<TVectorItem>
{
public:
virtual int insertItem(const TVectorItem &item, int = -1, void *caller = nullptr) override
virtual int insertItem(const TVectorItem &item, int = -1,
void *caller = nullptr) override
{
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();
this->vector_.insert(it, item);
+32 -18
View File
@@ -11,7 +11,8 @@
namespace chatterino {
template <typename TVectorItem>
class SignalVectorModel : public QAbstractTableModel, pajlada::Signals::SignalHolder
class SignalVectorModel : public QAbstractTableModel,
pajlada::Signals::SignalHolder
{
public:
SignalVectorModel(int columnCount, QObject *parent = nullptr)
@@ -43,7 +44,8 @@ public:
index = this->beforeInsert(args.item, row, 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();
};
@@ -65,7 +67,8 @@ public:
assert(row >= 0 && row <= this->rows_.size());
// 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->rows_.erase(this->rows_.begin() + row);
@@ -103,15 +106,18 @@ public:
QVariant data(const QModelIndex &index, int role) const override
{
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);
}
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();
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];
@@ -124,15 +130,16 @@ public:
this->vector_->removeItem(vecRow, this);
assert(this->rows_[row].original);
TVectorItem item =
this->getItemFromRow(this->rows_[row].items, this->rows_[row].original.get());
TVectorItem item = this->getItemFromRow(
this->rows_[row].items, this->rows_[row].original.get());
this->vector_->insertItem(item, vecRow, this);
}
return true;
}
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
QVariant headerData(int section, Qt::Orientation orientation,
int role) const override
{
if (orientation != Qt::Horizontal) {
return QVariant();
@@ -146,7 +153,8 @@ public:
}
}
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
bool setHeaderData(int section, Qt::Orientation orientation,
const QVariant &value,
int role = Qt::DisplayRole) override
{
if (orientation != Qt::Horizontal) {
@@ -162,14 +170,16 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const override
{
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();
}
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];
}
@@ -204,20 +214,23 @@ protected:
const TVectorItem &original) = 0;
// turns a row in the model into a vector item
virtual void getRowFromItem(const TVectorItem &item, std::vector<QStandardItem *> &row) = 0;
virtual void getRowFromItem(const TVectorItem &item,
std::vector<QStandardItem *> &row) = 0;
virtual int beforeInsert(const TVectorItem &item, std::vector<QStandardItem *> &row,
virtual int beforeInsert(const TVectorItem &item,
std::vector<QStandardItem *> &row,
int proposedIndex)
{
return proposedIndex;
}
virtual void afterRemoved(const TVectorItem &item, std::vector<QStandardItem *> &row, int index)
virtual void afterRemoved(const TVectorItem &item,
std::vector<QStandardItem *> &row, int index)
{
}
virtual void customRowSetData(const std::vector<QStandardItem *> &row, int column,
const QVariant &value, int role)
virtual void customRowSetData(const std::vector<QStandardItem *> &row,
int column, const QVariant &value, int role)
{
}
@@ -226,7 +239,8 @@ protected:
assert(index >= 0 && index <= this->rows_.size());
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();
}