reformat code

This commit is contained in:
Rasmus Karlsson 2017-07-31 00:57:42 +02:00
parent 0088374694
commit 626002c8ff
11 changed files with 149 additions and 127 deletions

View file

@ -24,7 +24,8 @@ class Message
{ {
public: public:
// explicit Message(const QString &text); // explicit Message(const QString &text);
explicit Message(const QString &text, const std::vector<messages::Word> &words, const bool &highlight); explicit Message(const QString &text, const std::vector<messages::Word> &words,
const bool &highlight);
bool getCanHighlightTab() const; bool getCanHighlightTab() const;
const QString &getTimeoutUser() const; const QString &getTimeoutUser() const;

View file

@ -16,7 +16,7 @@ MessageBuilder::MessageBuilder()
SharedMessage MessageBuilder::build() SharedMessage MessageBuilder::build()
{ {
return SharedMessage(new Message(this->originalMessage, _words,highlight)); return SharedMessage(new Message(this->originalMessage, _words, highlight));
} }
void MessageBuilder::appendWord(const Word &word) void MessageBuilder::appendWord(const Word &word)
@ -31,7 +31,8 @@ void MessageBuilder::appendTimestamp()
appendTimestamp(t); appendTimestamp(t);
} }
void MessageBuilder::setHighlight(const bool &value){ void MessageBuilder::setHighlight(const bool &value)
{
highlight = value; highlight = value;
} }
@ -58,9 +59,12 @@ void MessageBuilder::appendTimestamp(time_t time)
QString MessageBuilder::matchLink(const QString &string) QString MessageBuilder::matchLink(const QString &string)
{ {
QString match = regex.match(string,0,QRegularExpression::PartialPreferCompleteMatch,QRegularExpression::NoMatchOption).captured(); QString match = regex
if(!match.contains(QRegularExpression("\\bhttps?:\/\/"))){ .match(string, 0, QRegularExpression::PartialPreferCompleteMatch,
match.insert(0,"https://"); QRegularExpression::NoMatchOption)
.captured();
if (!match.contains(QRegularExpression("\\bhttps?:\/\/"))) {
match.insert(0, "https://");
} }
return match; return match;
} }

View file

@ -2,9 +2,10 @@
#include "messages/message.hpp" #include "messages/message.hpp"
#include <ctime>
#include <QRegularExpression> #include <QRegularExpression>
#include <ctime>
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {

View file

@ -43,7 +43,8 @@ public:
return _value; return _value;
} }
T &getnonConst() { T &getnonConst()
{
return _value; return _value;
} }
@ -69,12 +70,12 @@ public:
} }
} }
void insertMap(QString id, bool sound, bool task){ void insertMap(QString id, bool sound, bool task)
QPair<bool,bool> pair(sound,task); {
_value.insert(id,pair); QPair<bool, bool> pair(sound, task);
_value.insert(id, pair);
} }
boost::signals2::signal<void(const T &newValue)> valueChanged; boost::signals2::signal<void(const T &newValue)> valueChanged;
private: private:

View file

@ -27,12 +27,12 @@ SettingsManager::SettingsManager()
, mentionUsersWithAt(_settingsItems, "mentionUsersWithAt", false) , mentionUsersWithAt(_settingsItems, "mentionUsersWithAt", false)
, allowCommandsAtEnd(_settingsItems, "allowCommandsAtEnd", false) , allowCommandsAtEnd(_settingsItems, "allowCommandsAtEnd", false)
, enableHighlights(_settingsItems, "enableHighlights", true) , enableHighlights(_settingsItems, "enableHighlights", true)
, enableHighlightsSelf(_settingsItems,"enableHighlightsSelf", true) , enableHighlightsSelf(_settingsItems, "enableHighlightsSelf", true)
, enableHighlightSound(_settingsItems, "enableHighlightSound", true) , enableHighlightSound(_settingsItems, "enableHighlightSound", true)
, enableHighlightTaskbar(_settingsItems, "enableHighlightTaskbar", true) , enableHighlightTaskbar(_settingsItems, "enableHighlightTaskbar", true)
, customHighlightSound(_settingsItems, "customHighlightSound", false) , customHighlightSound(_settingsItems, "customHighlightSound", false)
, pathHighlightSound(_settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav") , pathHighlightSound(_settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav")
, highlightProperties(_settingsItems,"highlightProperties",QMap<QString,QPair<bool,bool>>()) , highlightProperties(_settingsItems, "highlightProperties", QMap<QString, QPair<bool, bool>>())
, enableTwitchEmotes(_settingsItems, "enableTwitchEmotes", true) , enableTwitchEmotes(_settingsItems, "enableTwitchEmotes", true)
, enableBttvEmotes(_settingsItems, "enableBttvEmotes", true) , enableBttvEmotes(_settingsItems, "enableBttvEmotes", true)
, enableFfzEmotes(_settingsItems, "enableFfzEmotes", true) , enableFfzEmotes(_settingsItems, "enableFfzEmotes", true)
@ -64,17 +64,17 @@ SettingsManager::SettingsManager()
void SettingsManager::save() void SettingsManager::save()
{ {
for (auto &item : _settingsItems) { for (auto &item : _settingsItems) {
if(item.get().getName() != "highlightProperties"){ if (item.get().getName() != "highlightProperties") {
_settings.setValue(item.get().getName(), item.get().getVariant()); _settings.setValue(item.get().getName(), item.get().getVariant());
} else { } else {
_settings.beginGroup("Highlights"); _settings.beginGroup("Highlights");
QStringList list = highlightProperties.get().keys(); QStringList list = highlightProperties.get().keys();
list.removeAll(""); list.removeAll("");
_settings.remove(""); _settings.remove("");
for (auto string : list){ for (auto string : list) {
_settings.beginGroup(string); _settings.beginGroup(string);
_settings.setValue("highlightSound",highlightProperties.get().value(string).first); _settings.setValue("highlightSound", highlightProperties.get().value(string).first);
_settings.setValue("highlightTask",highlightProperties.get().value(string).second); _settings.setValue("highlightTask", highlightProperties.get().value(string).second);
_settings.endGroup(); _settings.endGroup();
} }
_settings.endGroup(); _settings.endGroup();
@ -85,15 +85,16 @@ void SettingsManager::save()
void SettingsManager::load() void SettingsManager::load()
{ {
for (auto &item : _settingsItems) { for (auto &item : _settingsItems) {
if(item.get().getName() != "highlightProperties"){ if (item.get().getName() != "highlightProperties") {
item.get().setVariant(_settings.value(item.get().getName())); item.get().setVariant(_settings.value(item.get().getName()));
} else { } else {
_settings.beginGroup("Highlights"); _settings.beginGroup("Highlights");
QStringList list = _settings.childGroups(); QStringList list = _settings.childGroups();
qDebug() << list.join(","); qDebug() << list.join(",");
for (auto string : list){ for (auto string : list) {
_settings.beginGroup(string); _settings.beginGroup(string);
highlightProperties.insertMap(string,_settings.value("highlightSound").toBool(),_settings.value("highlightTask").toBool()); highlightProperties.insertMap(string, _settings.value("highlightSound").toBool(),
_settings.value("highlightTask").toBool());
_settings.endGroup(); _settings.endGroup();
} }
_settings.endGroup(); _settings.endGroup();
@ -101,7 +102,6 @@ void SettingsManager::load()
} }
} }
Word::Type SettingsManager::getWordTypeMask() Word::Type SettingsManager::getWordTypeMask()
{ {
return _wordTypeMask; return _wordTypeMask;
@ -159,7 +159,7 @@ SettingsSnapshot SettingsManager::createSnapshot()
SettingsSnapshot snapshot; SettingsSnapshot snapshot;
for (auto &item : this->_settingsItems) { for (auto &item : this->_settingsItems) {
if(item.get().getName() != "highlightProperties"){ if (item.get().getName() != "highlightProperties") {
snapshot.addItem(item, item.get().getVariant()); snapshot.addItem(item, item.get().getVariant());
} else { } else {
snapshot._mapItems = highlightProperties.get(); snapshot._mapItems = highlightProperties.get();

View file

@ -62,7 +62,7 @@ public:
Setting<bool> enableHighlightTaskbar; Setting<bool> enableHighlightTaskbar;
Setting<bool> customHighlightSound; Setting<bool> customHighlightSound;
Setting<QString> pathHighlightSound; Setting<QString> pathHighlightSound;
Setting<QMap<QString,QPair<bool,bool>>> highlightProperties; Setting<QMap<QString, QPair<bool, bool>>> highlightProperties;
Setting<bool> enableTwitchEmotes; Setting<bool> enableTwitchEmotes;
Setting<bool> enableBttvEmotes; Setting<bool> enableBttvEmotes;
Setting<bool> enableFfzEmotes; Setting<bool> enableFfzEmotes;

View file

@ -18,12 +18,12 @@ public:
std::pair<std::reference_wrapper<BaseSetting>, QVariant>(setting.get(), value)); std::pair<std::reference_wrapper<BaseSetting>, QVariant>(setting.get(), value));
} }
void addMapItem(QString string,QPair<bool,bool> pair){ void addMapItem(QString string, QPair<bool, bool> pair)
QMap<QString,QPair<bool,bool>> map; {
_mapItems.insert(string,pair); QMap<QString, QPair<bool, bool>> map;
_mapItems.insert(string, pair);
} }
void apply() void apply()
{ {
for (auto &item : _items) { for (auto &item : _items) {
@ -31,7 +31,7 @@ public:
} }
} }
QMap<QString,QPair<bool,bool>> _mapItems; QMap<QString, QPair<bool, bool>> _mapItems;
private: private:
std::vector<std::pair<std::reference_wrapper<BaseSetting>, QVariant>> _items; std::vector<std::pair<std::reference_wrapper<BaseSetting>, QVariant>> _items;

View file

@ -57,32 +57,34 @@ SharedMessage TwitchMessageBuilder::parse()
this->originalMessage = originalMessage; this->originalMessage = originalMessage;
SettingsManager &settings = SettingsManager::getInstance(); SettingsManager &settings = SettingsManager::getInstance();
static auto player = new QMediaPlayer; static auto player = new QMediaPlayer;
if(settings.customHighlightSound.get()){ if (settings.customHighlightSound.get()) {
player->setMedia(QUrl(settings.pathHighlightSound.get())); player->setMedia(QUrl(settings.pathHighlightSound.get()));
} else { } else {
player->setMedia(QUrl("qrc:/sounds/ping2.wav")); player->setMedia(QUrl("qrc:/sounds/ping2.wav"));
} }
if(settings.enableHighlights.get() && ircMessage->nick().compare(settings.selectedUser.get(), Qt::CaseInsensitive)){ if (settings.enableHighlights.get() &&
if(settings.enableHighlightsSelf.get() && originalMessage.contains(settings.selectedUser.get(), Qt::CaseInsensitive)){ ircMessage->nick().compare(settings.selectedUser.get(), Qt::CaseInsensitive)) {
if (settings.enableHighlightsSelf.get() &&
originalMessage.contains(settings.selectedUser.get(), Qt::CaseInsensitive)) {
this->setHighlight(true); this->setHighlight(true);
if(settings.enableHighlightSound.get()){ if (settings.enableHighlightSound.get()) {
player->play(); player->play();
} }
if(settings.enableHighlightTaskbar.get()){ if (settings.enableHighlightTaskbar.get()) {
QApplication::alert(windowManager.getMainWindow().window(),2500); QApplication::alert(windowManager.getMainWindow().window(), 2500);
} }
} else { } else {
QStringList lines = settings.highlightProperties.get().keys(); QStringList lines = settings.highlightProperties.get().keys();
for(QString string : lines){ for (QString string : lines) {
if(originalMessage.contains(string,Qt::CaseInsensitive)){ if (originalMessage.contains(string, Qt::CaseInsensitive)) {
this->setHighlight(true); this->setHighlight(true);
// Sound // Sound
if(settings.highlightProperties.get().value(string).first){ if (settings.highlightProperties.get().value(string).first) {
player->play(); player->play();
} }
// Taskbar // Taskbar
if(settings.highlightProperties.get().value(string).second){ if (settings.highlightProperties.get().value(string).second) {
QApplication::alert(windowManager.getMainWindow().window(),2500); QApplication::alert(windowManager.getMainWindow().window(), 2500);
} }
} }
} }

View file

@ -227,7 +227,9 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
// update messages that have been changed // update messages that have been changed
if (updateBuffer) { if (updateBuffer) {
QPainter painter(buffer); QPainter painter(buffer);
painter.fillRect(buffer->rect(), (messageRef->getMessage()->getCanHighlightTab()) ? this->colorScheme.ChatBackgroundHighlighted : this->colorScheme.ChatBackground); painter.fillRect(buffer->rect(), (messageRef->getMessage()->getCanHighlightTab())
? this->colorScheme.ChatBackgroundHighlighted
: this->colorScheme.ChatBackground);
for (messages::WordPart const &wordPart : messageRef->getWordParts()) { for (messages::WordPart const &wordPart : messageRef->getWordParts()) {
// image // image
if (wordPart.getWord().isImage()) { if (wordPart.getWord().isImage()) {
@ -380,7 +382,7 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event)
auto &link = hoverWord.getLink(); auto &link = hoverWord.getLink();
switch (link.getType()) { switch (link.getType()) {
case messages::Link::UserInfo:{ case messages::Link::UserInfo: {
auto user = message->getMessage()->getUserName(); auto user = message->getMessage()->getUserName();
this->userPopupWidget.setName(user); this->userPopupWidget.setName(user);
this->userPopupWidget.move(event->screenPos().toPoint()); this->userPopupWidget.move(event->screenPos().toPoint());
@ -390,7 +392,7 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event)
qDebug() << "Clicked " << user << "s message"; qDebug() << "Clicked " << user << "s message";
break; break;
} }
case messages::Link::Url:{ case messages::Link::Url: {
QDesktopServices::openUrl(QUrl(link.getValue())); QDesktopServices::openUrl(QUrl(link.getValue()));
break; break;
} }

View file

@ -9,15 +9,15 @@
#include <QComboBox> #include <QComboBox>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QFileDialog>
#include <QFontDialog> #include <QFontDialog>
#include <QFormLayout> #include <QFormLayout>
#include <QFileDialog>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
#include <QListWidget> #include <QListWidget>
#include <QPalette> #include <QPalette>
#include <QTextEdit>
#include <QResource> #include <QResource>
#include <QTextEdit>
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
@ -108,10 +108,11 @@ void SettingsDialog::addTabs()
listWidget->addItem(user.getUserName()); listWidget->addItem(user.getUserName());
} }
if(listWidget->count()){ if (listWidget->count()) {
int itemIndex = 0; int itemIndex = 0;
for(; itemIndex < listWidget->count(); ++itemIndex){ for (; itemIndex < listWidget->count(); ++itemIndex) {
if(listWidget->item(itemIndex)->text().compare(settings.selectedUser.get(),Qt::CaseInsensitive)){ if (listWidget->item(itemIndex)->text().compare(settings.selectedUser.get(),
Qt::CaseInsensitive)) {
++itemIndex; ++itemIndex;
break; break;
} }
@ -119,8 +120,8 @@ void SettingsDialog::addTabs()
listWidget->setCurrentRow(itemIndex); listWidget->setCurrentRow(itemIndex);
} }
QObject::connect(listWidget,&QListWidget::clicked,this,[&,listWidget]{ QObject::connect(listWidget, &QListWidget::clicked, this, [&, listWidget] {
if(!listWidget->selectedItems().isEmpty()){ if (!listWidget->selectedItems().isEmpty()) {
settings.selectedUser.set(listWidget->currentItem()->text()); settings.selectedUser.set(listWidget->currentItem()->text());
} }
}); });
@ -374,14 +375,17 @@ void SettingsDialog::addTabs()
auto soundForm = new QFormLayout(); auto soundForm = new QFormLayout();
{ {
vbox->addWidget(createCheckbox("Enable Highlighting", settings.enableHighlights)); vbox->addWidget(createCheckbox("Enable Highlighting", settings.enableHighlights));
vbox->addWidget(createCheckbox("Highlight messages containing your name", settings.enableHighlightsSelf)); vbox->addWidget(createCheckbox("Highlight messages containing your name",
vbox->addWidget(createCheckbox("Play sound when your name is mentioned", settings.enableHighlightSound)); settings.enableHighlightsSelf));
vbox->addWidget(createCheckbox("Flash taskbar when your name is mentioned", settings.enableHighlightTaskbar)); vbox->addWidget(createCheckbox("Play sound when your name is mentioned",
settings.enableHighlightSound));
vbox->addWidget(createCheckbox("Flash taskbar when your name is mentioned",
settings.enableHighlightTaskbar));
customSound->addWidget(createCheckbox("Custom sound", settings.customHighlightSound)); customSound->addWidget(createCheckbox("Custom sound", settings.customHighlightSound));
auto selectBtn = new QPushButton("Select"); auto selectBtn = new QPushButton("Select");
QObject::connect(selectBtn,&QPushButton::clicked,this,[&settings,this]{ QObject::connect(selectBtn, &QPushButton::clicked, this, [&settings, this] {
auto fileName = QFileDialog::getOpenFileName(this, auto fileName = QFileDialog::getOpenFileName(this, tr("Open Sound"), "",
tr("Open Sound"), "", tr("Image Files (*.mp3 *.wav)")); tr("Image Files (*.mp3 *.wav)"));
settings.pathHighlightSound.set(fileName); settings.pathHighlightSound.set(fileName);
}); });
customSound->addWidget(selectBtn); customSound->addWidget(selectBtn);
@ -395,7 +399,7 @@ void SettingsDialog::addTabs()
auto editBtn = new QPushButton("Edit"); auto editBtn = new QPushButton("Edit");
auto delBtn = new QPushButton("Remove"); auto delBtn = new QPushButton("Remove");
QObject::connect(addBtn,&QPushButton::clicked,this,[highlights,this,&settings]{ QObject::connect(addBtn, &QPushButton::clicked, this, [highlights, this, &settings] {
auto show = new QWidget(); auto show = new QWidget();
auto box = new QBoxLayout(QBoxLayout::TopToBottom); auto box = new QBoxLayout(QBoxLayout::TopToBottom);
@ -405,10 +409,11 @@ void SettingsDialog::addTabs()
auto sound = new QCheckBox("Play sound"); auto sound = new QCheckBox("Play sound");
auto task = new QCheckBox("Flash taskbar"); auto task = new QCheckBox("Flash taskbar");
QObject::connect(add,&QPushButton::clicked,this,[=,&settings]{ QObject::connect(add, &QPushButton::clicked, this, [=, &settings] {
if(edit->text().length()){ if (edit->text().length()) {
highlights->addItem(edit->text()); highlights->addItem(edit->text());
settings.highlightProperties.insertMap(edit->text(),sound->isChecked(),task->isChecked()); settings.highlightProperties.insertMap(edit->text(), sound->isChecked(),
task->isChecked());
show->close(); show->close();
} }
}); });
@ -419,8 +424,8 @@ void SettingsDialog::addTabs()
show->setLayout(box); show->setLayout(box);
show->show(); show->show();
}); });
QObject::connect(editBtn,&QPushButton::clicked,this,[highlights,this,&settings]{ QObject::connect(editBtn, &QPushButton::clicked, this, [highlights, this, &settings] {
if(!highlights->selectedItems().isEmpty()){ if (!highlights->selectedItems().isEmpty()) {
auto show = new QWidget(); auto show = new QWidget();
auto box = new QBoxLayout(QBoxLayout::TopToBottom); auto box = new QBoxLayout(QBoxLayout::TopToBottom);
@ -431,28 +436,35 @@ void SettingsDialog::addTabs()
auto sound = new QCheckBox("Play sound"); auto sound = new QCheckBox("Play sound");
auto task = new QCheckBox("Flash taskbar"); auto task = new QCheckBox("Flash taskbar");
QObject::connect(add,&QPushButton::clicked,this,[=,&settings]{ QObject::connect(add, &QPushButton::clicked, this, [=, &settings] {
if(edit->text().length()){ if (edit->text().length()) {
settings.highlightProperties.getnonConst().remove(highlights->selectedItems().first()->text()); settings.highlightProperties.getnonConst().remove(
highlights->selectedItems().first()->text());
delete highlights->selectedItems().first(); delete highlights->selectedItems().first();
highlights->addItem(edit->text()); highlights->addItem(edit->text());
settings.highlightProperties.insertMap(edit->text(),sound->isChecked(),task->isChecked()); settings.highlightProperties.insertMap(edit->text(), sound->isChecked(),
task->isChecked());
show->close(); show->close();
} }
}); });
box->addWidget(edit); box->addWidget(edit);
box->addWidget(add); box->addWidget(add);
box->addWidget(sound); box->addWidget(sound);
sound->setChecked(settings.highlightProperties.get().value(highlights->selectedItems().first()->text()).first); sound->setChecked(settings.highlightProperties.get()
.value(highlights->selectedItems().first()->text())
.first);
box->addWidget(task); box->addWidget(task);
task->setChecked(settings.highlightProperties.get().value(highlights->selectedItems().first()->text()).second); task->setChecked(settings.highlightProperties.get()
.value(highlights->selectedItems().first()->text())
.second);
show->setLayout(box); show->setLayout(box);
show->show(); show->show();
} }
}); });
QObject::connect(delBtn,&QPushButton::clicked,this,[highlights,&settings]{ QObject::connect(delBtn, &QPushButton::clicked, this, [highlights, &settings] {
if(!highlights->selectedItems().isEmpty()){ if (!highlights->selectedItems().isEmpty()) {
settings.highlightProperties.getnonConst().remove(highlights->selectedItems().first()->text()); settings.highlightProperties.getnonConst().remove(
highlights->selectedItems().first()->text());
delete highlights->selectedItems().first(); delete highlights->selectedItems().first();
} }
}); });
@ -586,8 +598,7 @@ void SettingsDialog::cancelButtonClicked()
QStringList list = instance.highlightProperties.get().keys(); QStringList list = instance.highlightProperties.get().keys();
list.removeDuplicates(); list.removeDuplicates();
while(globalHighlights->count()>0) while (globalHighlights->count() > 0) {
{
delete globalHighlights->takeItem(0); delete globalHighlights->takeItem(0);
} }
globalHighlights->addItems(list); globalHighlights->addItems(list);

View file

@ -52,7 +52,7 @@ private:
SettingsDialogTab *selectedTab = nullptr; SettingsDialogTab *selectedTab = nullptr;
QListWidget* globalHighlights; QListWidget *globalHighlights;
/// Widget creation helpers /// Widget creation helpers
QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting); QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting);