changed .clang-format

This commit is contained in:
fourtf 2018-08-15 22:46:20 +02:00
parent 44c16f1b3a
commit af7b742a23
46 changed files with 1636 additions and 1611 deletions

View file

@ -25,6 +25,9 @@ DerivePointerBinding: false
FixNamespaceComments: true
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: true
IndentPPDirectives: AfterHash
NamespaceIndentation: Inner
PointerBindsToType: false
SpacesBeforeTrailingComments: 2
Standard: Auto

View file

@ -99,15 +99,15 @@ void Application::save()
void Application::initNm()
{
#ifdef Q_OS_WIN
#ifdef QT_DEBUG
#ifdef C_DEBUG_NM
# ifdef QT_DEBUG
# ifdef C_DEBUG_NM
this->nativeMessaging->registerHost();
this->nativeMessaging->openGuiMessageQueue();
#endif
#else
# endif
# else
this->nativeMessaging->registerHost();
this->nativeMessaging->openGuiMessageQueue();
#endif
# endif
#endif
}

View file

@ -9,24 +9,24 @@
#include <memory>
#ifdef Q_OS_WIN
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
# include <fcntl.h>
# include <io.h>
# include <stdio.h>
#endif
namespace chatterino {
namespace {
void initFileMode()
{
void initFileMode()
{
#ifdef Q_OS_WIN
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
#endif
}
}
void runLoop(NativeMessagingClient &client)
{
void runLoop(NativeMessagingClient &client)
{
while (true) {
char size_c[4];
std::cin.read(size_c, 4);
@ -52,10 +52,10 @@ void runLoop(NativeMessagingClient &client)
std::cin.read(buffer.get(), size);
*(buffer.get() + size) = '\0';
client.sendMessage(
QByteArray::fromRawData(buffer.get(), static_cast<int32_t>(size)));
client.sendMessage(QByteArray::fromRawData(
buffer.get(), static_cast<int32_t>(size)));
}
}
}
} // namespace
bool shouldRunBrowserExtensionHost(const QStringList &args)

View file

@ -1,168 +1,168 @@
#ifdef __cplusplus
#include <fmt/format.h>
#include <irccommand.h>
#include <ircconnection.h>
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
#include <rapidjson/error/error.h>
#include <IrcMessage>
#include <QAbstractListModel>
#include <QAbstractNativeEventFilter>
#include <QAction>
#include <QApplication>
#include <QBrush>
#include <QBuffer>
#include <QButtonGroup>
#include <QByteArray>
#include <QCheckBox>
#include <QClipboard>
#include <QColor>
#include <QComboBox>
#include <QCompleter>
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QDesktopServices>
#include <QDialog>
#include <QDialogButtonBox>
#include <QDir>
#include <QDockWidget>
#include <QDrag>
#include <QDragEnterEvent>
#include <QElapsedTimer>
#include <QEventLoop>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QFlags>
#include <QFont>
#include <QFontDatabase>
#include <QFontDialog>
#include <QFontMetrics>
#include <QFormLayout>
#include <QGraphicsBlurEffect>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QIcon>
#include <QImageReader>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QKeyEvent>
#include <QLabel>
#include <QLayout>
#include <QLibrary>
#include <QLineEdit>
#include <QList>
#include <QListView>
#include <QListWidget>
#include <QMap>
#include <QMediaPlayer>
#include <QMenu>
#include <QMessageBox>
#include <QMimeData>
#include <QMouseEvent>
#include <QMutex>
#include <QMutexLocker>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QObject>
#include <QPaintEvent>
#include <QPainter>
#include <QPainterPath>
#include <QPalette>
#include <QPixmap>
#include <QPoint>
#include <QProcess>
#include <QPropertyAnimation>
#include <QPushButton>
#include <QRadialGradient>
#include <QRect>
#include <QRegularExpression>
#include <QRunnable>
#include <QScroller>
#include <QShortcut>
#include <QSizePolicy>
#include <QSlider>
#include <QStackedLayout>
#include <QStandardPaths>
#include <QString>
#include <QStyle>
#include <QStyleOption>
#include <QTabWidget>
#include <QTextEdit>
#include <QThread>
#include <QThreadPool>
#include <QTime>
#include <QTimer>
#include <QUrl>
#include <QUuid>
#include <QVBoxLayout>
#include <QVariant>
#include <QVector>
#include <QWheelEvent>
#include <QWidget>
#include <QtCore/QVariant>
#include <QtGlobal>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QDialog>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QVBoxLayout>
#include <algorithm>
#include <boost/current_function.hpp>
#include <boost/foreach.hpp>
#include <boost/noncopyable.hpp>
#include <boost/optional.hpp>
#include <cassert>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <cstdint>
#include <ctime>
#include <functional>
#include <future>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/settings/setting.hpp>
#include <pajlada/settings/settinglistener.hpp>
#include <pajlada/signals/connection.hpp>
#include <pajlada/signals/signal.hpp>
#include <random>
#include <set>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
# include <fmt/format.h>
# include <irccommand.h>
# include <ircconnection.h>
# include <rapidjson/document.h>
# include <rapidjson/error/en.h>
# include <rapidjson/error/error.h>
# include <IrcMessage>
# include <QAbstractListModel>
# include <QAbstractNativeEventFilter>
# include <QAction>
# include <QApplication>
# include <QBrush>
# include <QBuffer>
# include <QButtonGroup>
# include <QByteArray>
# include <QCheckBox>
# include <QClipboard>
# include <QColor>
# include <QComboBox>
# include <QCompleter>
# include <QCoreApplication>
# include <QDateTime>
# include <QDebug>
# include <QDesktopServices>
# include <QDialog>
# include <QDialogButtonBox>
# include <QDir>
# include <QDockWidget>
# include <QDrag>
# include <QDragEnterEvent>
# include <QElapsedTimer>
# include <QEventLoop>
# include <QFile>
# include <QFileDialog>
# include <QFileInfo>
# include <QFlags>
# include <QFont>
# include <QFontDatabase>
# include <QFontDialog>
# include <QFontMetrics>
# include <QFormLayout>
# include <QGraphicsBlurEffect>
# include <QGroupBox>
# include <QHBoxLayout>
# include <QHeaderView>
# include <QIcon>
# include <QImageReader>
# include <QJsonArray>
# include <QJsonDocument>
# include <QJsonObject>
# include <QJsonValue>
# include <QKeyEvent>
# include <QLabel>
# include <QLayout>
# include <QLibrary>
# include <QLineEdit>
# include <QList>
# include <QListView>
# include <QListWidget>
# include <QMap>
# include <QMediaPlayer>
# include <QMenu>
# include <QMessageBox>
# include <QMimeData>
# include <QMouseEvent>
# include <QMutex>
# include <QMutexLocker>
# include <QNetworkAccessManager>
# include <QNetworkReply>
# include <QNetworkRequest>
# include <QObject>
# include <QPaintEvent>
# include <QPainter>
# include <QPainterPath>
# include <QPalette>
# include <QPixmap>
# include <QPoint>
# include <QProcess>
# include <QPropertyAnimation>
# include <QPushButton>
# include <QRadialGradient>
# include <QRect>
# include <QRegularExpression>
# include <QRunnable>
# include <QScroller>
# include <QShortcut>
# include <QSizePolicy>
# include <QSlider>
# include <QStackedLayout>
# include <QStandardPaths>
# include <QString>
# include <QStyle>
# include <QStyleOption>
# include <QTabWidget>
# include <QTextEdit>
# include <QThread>
# include <QThreadPool>
# include <QTime>
# include <QTimer>
# include <QUrl>
# include <QUuid>
# include <QVBoxLayout>
# include <QVariant>
# include <QVector>
# include <QWheelEvent>
# include <QWidget>
# include <QtCore/QVariant>
# include <QtGlobal>
# include <QtWidgets/QAction>
# include <QtWidgets/QApplication>
# include <QtWidgets/QButtonGroup>
# include <QtWidgets/QDialog>
# include <QtWidgets/QDialogButtonBox>
# include <QtWidgets/QFormLayout>
# include <QtWidgets/QHBoxLayout>
# include <QtWidgets/QHeaderView>
# include <QtWidgets/QLabel>
# include <QtWidgets/QLineEdit>
# include <QtWidgets/QPushButton>
# include <QtWidgets/QTabWidget>
# include <QtWidgets/QVBoxLayout>
# include <algorithm>
# include <boost/current_function.hpp>
# include <boost/foreach.hpp>
# include <boost/noncopyable.hpp>
# include <boost/optional.hpp>
# include <cassert>
# include <chrono>
# include <cinttypes>
# include <climits>
# include <cmath>
# include <cstdint>
# include <ctime>
# include <functional>
# include <future>
# include <list>
# include <map>
# include <memory>
# include <mutex>
# include <pajlada/settings/serialize.hpp>
# include <pajlada/settings/setting.hpp>
# include <pajlada/settings/settinglistener.hpp>
# include <pajlada/signals/connection.hpp>
# include <pajlada/signals/signal.hpp>
# include <random>
# include <set>
# include <string>
# include <thread>
# include <tuple>
# include <type_traits>
# include <unordered_map>
# include <unordered_set>
# include <vector>
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
# ifndef UNUSED
# define UNUSED(x) (void)(x)
# endif
#ifndef ATTR_UNUSED
#ifdef Q_OS_WIN
#define ATTR_UNUSED
#else
#define ATTR_UNUSED __attribute__((unused))
#endif
#endif
# ifndef ATTR_UNUSED
# ifdef Q_OS_WIN
# define ATTR_UNUSED
# else
# define ATTR_UNUSED __attribute__((unused))
# endif
# endif
#endif

View file

@ -12,7 +12,7 @@
#include "widgets/dialogs/LastRunCrashDialog.hpp"
#ifdef C_USE_BREAKPAD
#include <QBreakpadHandler.h>
# include <QBreakpadHandler.h>
#endif
// void initQt();
@ -23,8 +23,8 @@
namespace chatterino {
namespace {
void installCustomPalette()
{
void installCustomPalette()
{
// borrowed from
// https://stackoverflow.com/questions/15035767/is-the-qt-5-dark-fusion-theme-available-for-windows
auto dark = qApp->palette();
@ -38,7 +38,8 @@ void installCustomPalette()
dark.setColor(QPalette::AlternateBase, QColor("#444"));
dark.setColor(QPalette::ToolTipBase, Qt::white);
dark.setColor(QPalette::ToolTipText, Qt::white);
dark.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
dark.setColor(QPalette::Disabled, QPalette::Text,
QColor(127, 127, 127));
dark.setColor(QPalette::Dark, QColor(35, 35, 35));
dark.setColor(QPalette::Shadow, QColor(20, 20, 20));
dark.setColor(QPalette::Button, QColor(70, 70, 70));
@ -48,16 +49,17 @@ void installCustomPalette()
dark.setColor(QPalette::BrightText, Qt::red);
dark.setColor(QPalette::Link, QColor(42, 130, 218));
dark.setColor(QPalette::Highlight, QColor(42, 130, 218));
dark.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
dark.setColor(QPalette::Disabled, QPalette::Highlight,
QColor(80, 80, 80));
dark.setColor(QPalette::HighlightedText, Qt::white);
dark.setColor(QPalette::Disabled, QPalette::HighlightedText,
QColor(127, 127, 127));
qApp->setPalette(dark);
}
}
void initQt()
{
void initQt()
{
// set up the QApplication flags
QApplication::setAttribute(Qt::AA_Use96Dpi, true);
#ifdef Q_OS_WIN32
@ -67,10 +69,10 @@ void initQt()
QApplication::setStyle(QStyleFactory::create("Fusion"));
installCustomPalette();
}
}
void showLastCrashDialog()
{
void showLastCrashDialog()
{
#ifndef C_DISABLE_CRASH_DIALOG
LastRunCrashDialog dialog;
@ -82,21 +84,21 @@ void showLastCrashDialog()
}
}
#endif
}
}
void createRunningFile(const QString &path)
{
void createRunningFile(const QString &path)
{
QFile runningFile(path);
runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
runningFile.flush();
runningFile.close();
}
}
void removeRunningFile(const QString &path)
{
void removeRunningFile(const QString &path)
{
QFile::remove(path);
}
}
} // namespace
void runGui(QApplication &a, Paths &paths, Settings &settings)

View file

@ -5,9 +5,9 @@
#define CHATTERINO_VERSION "2.0.4"
#if defined(Q_OS_WIN)
#define CHATTERINO_OS "win"
# define CHATTERINO_OS "win"
#elif defined(Q_OS_MACOS)
#define CHATTERINO_OS "macos"
# define CHATTERINO_OS "macos"
#elif defined(Q_OS_LINUX)
#define CHATTERINO_OS "linux"
# define CHATTERINO_OS "linux"
#endif

View file

@ -68,9 +68,10 @@ private:
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::HighlightBlacklistUser> {
static rapidjson::Value get(const chatterino::HighlightBlacklistUser &value,
template <>
struct Serialize<chatterino::HighlightBlacklistUser> {
static rapidjson::Value get(
const chatterino::HighlightBlacklistUser &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);
@ -80,11 +81,12 @@ struct Serialize<chatterino::HighlightBlacklistUser> {
return ret;
}
};
};
template <>
struct Deserialize<chatterino::HighlightBlacklistUser> {
static chatterino::HighlightBlacklistUser get(const rapidjson::Value &value)
template <>
struct Deserialize<chatterino::HighlightBlacklistUser> {
static chatterino::HighlightBlacklistUser get(
const rapidjson::Value &value)
{
QString pattern;
bool isRegex = false;
@ -98,7 +100,7 @@ struct Deserialize<chatterino::HighlightBlacklistUser> {
return chatterino::HighlightBlacklistUser(pattern, isRegex);
}
};
};
} // namespace Settings
} // namespace pajlada

View file

@ -72,8 +72,8 @@ private:
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::HighlightPhrase> {
template <>
struct Serialize<chatterino::HighlightPhrase> {
static rapidjson::Value get(const chatterino::HighlightPhrase &value,
rapidjson::Document::AllocatorType &a)
{
@ -86,14 +86,15 @@ struct Serialize<chatterino::HighlightPhrase> {
return ret;
}
};
};
template <>
struct Deserialize<chatterino::HighlightPhrase> {
template <>
struct Deserialize<chatterino::HighlightPhrase> {
static chatterino::HighlightPhrase get(const rapidjson::Value &value)
{
if (!value.IsObject()) {
return chatterino::HighlightPhrase(QString(), true, false, false);
return chatterino::HighlightPhrase(QString(), true, false,
false);
}
QString _pattern;
@ -106,9 +107,10 @@ struct Deserialize<chatterino::HighlightPhrase> {
chatterino::rj::getSafe(value, "sound", _sound);
chatterino::rj::getSafe(value, "regex", _isRegex);
return chatterino::HighlightPhrase(_pattern, _alert, _sound, _isRegex);
return chatterino::HighlightPhrase(_pattern, _alert, _sound,
_isRegex);
}
};
};
} // namespace Settings
} // namespace pajlada

View file

@ -59,8 +59,8 @@ private:
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::IgnorePhrase> {
template <>
struct Serialize<chatterino::IgnorePhrase> {
static rapidjson::Value get(const chatterino::IgnorePhrase &value,
rapidjson::Document::AllocatorType &a)
{
@ -71,10 +71,10 @@ struct Serialize<chatterino::IgnorePhrase> {
return ret;
}
};
};
template <>
struct Deserialize<chatterino::IgnorePhrase> {
template <>
struct Deserialize<chatterino::IgnorePhrase> {
static chatterino::IgnorePhrase get(const rapidjson::Value &value)
{
if (!value.IsObject()) {
@ -89,7 +89,7 @@ struct Deserialize<chatterino::IgnorePhrase> {
return chatterino::IgnorePhrase(_pattern, _isRegex);
}
};
};
} // namespace Settings
} // namespace pajlada

View file

@ -36,8 +36,8 @@ private:
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::ModerationAction> {
template <>
struct Serialize<chatterino::ModerationAction> {
static rapidjson::Value get(const chatterino::ModerationAction &value,
rapidjson::Document::AllocatorType &a)
{
@ -47,10 +47,10 @@ struct Serialize<chatterino::ModerationAction> {
return ret;
}
};
};
template <>
struct Deserialize<chatterino::ModerationAction> {
template <>
struct Deserialize<chatterino::ModerationAction> {
static chatterino::ModerationAction get(const rapidjson::Value &value)
{
if (!value.IsObject()) {
@ -63,7 +63,7 @@ struct Deserialize<chatterino::ModerationAction> {
return chatterino::ModerationAction(pattern);
}
};
};
} // namespace Settings
} // namespace pajlada

View file

@ -22,28 +22,29 @@
namespace chatterino {
namespace {
// Frames
Frames::Frames()
{
// Frames
Frames::Frames()
{
DebugCount::increase("images");
}
}
Frames::Frames(const QVector<Frame<QPixmap>> &frames)
Frames::Frames(const QVector<Frame<QPixmap>> &frames)
: items_(frames)
{
{
assertInGuiThread();
DebugCount::increase("images");
if (this->animated()) {
DebugCount::increase("animated images");
this->gifTimerConnection_ = getApp()->emotes->gifTimer.signal.connect(
this->gifTimerConnection_ =
getApp()->emotes->gifTimer.signal.connect(
[this] { this->advance(); });
}
}
}
Frames::~Frames()
{
Frames::~Frames()
{
assertInGuiThread();
DebugCount::decrease("images");
@ -52,10 +53,10 @@ Frames::~Frames()
}
this->gifTimerConnection_.disconnect();
}
}
void Frames::advance()
{
void Frames::advance()
{
this->durationOffset_ += GIF_FRAME_LENGTH;
while (true) {
@ -72,28 +73,28 @@ void Frames::advance()
break;
}
}
}
}
bool Frames::animated() const
{
bool Frames::animated() const
{
return this->items_.size() > 1;
}
}
boost::optional<QPixmap> Frames::current() const
{
boost::optional<QPixmap> Frames::current() const
{
if (this->items_.size() == 0) return boost::none;
return this->items_[this->index_].image;
}
}
boost::optional<QPixmap> Frames::first() const
{
boost::optional<QPixmap> Frames::first() const
{
if (this->items_.size() == 0) return boost::none;
return this->items_.front().image;
}
}
// functions
QVector<Frame<QImage>> readFrames(QImageReader &reader, const Url &url)
{
// functions
QVector<Frame<QImage>> readFrames(QImageReader &reader, const Url &url)
{
QVector<Frame<QImage>> frames;
if (reader.imageCount() == 0) {
@ -118,14 +119,14 @@ QVector<Frame<QImage>> readFrames(QImageReader &reader, const Url &url)
}
return frames;
}
}
// parsed
template <typename Assign>
void assignDelayed(
// parsed
template <typename Assign>
void assignDelayed(
std::queue<std::pair<Assign, QVector<Frame<QPixmap>>>> &queued,
std::mutex &mutex, std::atomic_bool &loadedEventQueued)
{
{
std::lock_guard<std::mutex> lock(mutex);
int i = 0;
@ -134,30 +135,34 @@ void assignDelayed(
queued.pop();
if (++i > 50) {
QTimer::singleShot(
3, [&] { assignDelayed(queued, mutex, loadedEventQueued); });
QTimer::singleShot(3, [&] {
assignDelayed(queued, mutex, loadedEventQueued);
});
return;
}
}
getApp()->windows->forceLayoutChannelViews();
loadedEventQueued = false;
}
}
template <typename Assign>
auto makeConvertCallback(const QVector<Frame<QImage>> &parsed, Assign assign)
{
template <typename Assign>
auto makeConvertCallback(const QVector<Frame<QImage>> &parsed,
Assign assign)
{
return [parsed, assign] {
// convert to pixmap
auto frames = QVector<Frame<QPixmap>>();
std::transform(parsed.begin(), parsed.end(), std::back_inserter(frames),
[](auto &frame) {
std::transform(parsed.begin(), parsed.end(),
std::back_inserter(frames), [](auto &frame) {
return Frame<QPixmap>{
QPixmap::fromImage(frame.image), frame.duration};
QPixmap::fromImage(frame.image),
frame.duration};
});
// put into stack
static std::queue<std::pair<Assign, QVector<Frame<QPixmap>>>> queued;
static std::queue<std::pair<Assign, QVector<Frame<QPixmap>>>>
queued;
static std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
@ -168,11 +173,12 @@ auto makeConvertCallback(const QVector<Frame<QImage>> &parsed, Assign assign)
if (!loadedEventQueued) {
loadedEventQueued = true;
QTimer::singleShot(
100, [=] { assignDelayed(queued, mutex, loadedEventQueued); });
QTimer::singleShot(100, [=] {
assignDelayed(queued, mutex, loadedEventQueued);
});
}
};
}
}
} // namespace
// IMAGE2

View file

@ -17,14 +17,14 @@
namespace chatterino {
namespace {
template <typename Image>
struct Frame {
template <typename Image>
struct Frame {
Image image;
int duration;
};
class Frames : boost::noncopyable
{
public:
};
class Frames : boost::noncopyable
{
public:
Frames();
Frames(const QVector<Frame<QPixmap>> &frames);
~Frames();
@ -34,12 +34,12 @@ public:
boost::optional<QPixmap> current() const;
boost::optional<QPixmap> first() const;
private:
private:
QVector<Frame<QPixmap>> items_;
int index_{0};
int durationOffset_{0};
pajlada::Signals::Connection gifTimerConnection_;
};
};
} // namespace
class Image;

View file

@ -2,5 +2,4 @@
namespace chatterino {
} // namespace chatterino

View file

@ -13,24 +13,26 @@
namespace chatterino {
namespace {
Url getEmoteLink(QString urlTemplate, const EmoteId &id,
Url getEmoteLink(QString urlTemplate, const EmoteId &id,
const QString &emoteScale)
{
{
urlTemplate.detach();
return {urlTemplate.replace("{{id}}", id.string)
.replace("{{image}}", emoteScale)};
}
std::pair<Outcome, EmoteMap> parseGlobalEmotes(const QJsonObject &jsonRoot,
const EmoteMap &currentEmotes)
{
}
std::pair<Outcome, EmoteMap> parseGlobalEmotes(
const QJsonObject &jsonRoot, const EmoteMap &currentEmotes)
{
auto emotes = EmoteMap();
auto jsonEmotes = jsonRoot.value("emotes").toArray();
auto urlTemplate = qS("https:") + jsonRoot.value("urlTemplate").toString();
auto urlTemplate =
qS("https:") + jsonRoot.value("urlTemplate").toString();
for (auto jsonEmote : jsonEmotes) {
auto id = EmoteId{jsonEmote.toObject().value("id").toString()};
auto name = EmoteName{jsonEmote.toObject().value("code").toString()};
auto name =
EmoteName{jsonEmote.toObject().value("code").toString()};
auto emote = Emote(
{name,
@ -41,20 +43,21 @@ std::pair<Outcome, EmoteMap> parseGlobalEmotes(const QJsonObject &jsonRoot,
Tooltip{name.string + "<br />Global Bttv Emote"},
Url{"https://manage.betterttv.net/emotes/" + id.string}});
emotes[name] = cachedOrMakeEmotePtr(std::move(emote), currentEmotes);
emotes[name] =
cachedOrMakeEmotePtr(std::move(emote), currentEmotes);
}
return {Success, std::move(emotes)};
}
EmotePtr cachedOrMake(Emote &&emote, const EmoteId &id)
{
}
EmotePtr cachedOrMake(Emote &&emote, const EmoteId &id)
{
static std::unordered_map<EmoteId, std::weak_ptr<const Emote>> cache;
static std::mutex mutex;
return cachedOrMakeEmotePtr(std::move(emote), cache, mutex, id);
}
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
{
}
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
{
auto emotes = EmoteMap();
auto jsonEmotes = jsonRoot.value("emotes").toArray();
auto urlTemplate = "https:" + jsonRoot.value("urlTemplate").toString();
@ -79,7 +82,7 @@ std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
}
return {Success, std::move(emotes)};
}
}
} // namespace
//

View file

@ -13,13 +13,11 @@
#include <memory>
namespace chatterino {
namespace {
void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
const rapidjson::Value &unparsedEmoji,
QString shortCode = QString())
{
{
static uint unicodeBytes[4];
struct {
@ -40,7 +38,8 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
}
}
rj::getSafe(unparsedEmoji, "non_qualified", emojiData->nonQualifiedCode);
rj::getSafe(unparsedEmoji, "non_qualified",
emojiData->nonQualifiedCode);
rj::getSafe(unparsedEmoji, "unified", emojiData->unifiedCode);
rj::getSafe(unparsedEmoji, "has_img_apple", capabilities.apple);
@ -71,7 +70,8 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
QStringList unicodeCharacters;
if (!emojiData->nonQualifiedCode.isEmpty()) {
unicodeCharacters = emojiData->nonQualifiedCode.toLower().split('-');
unicodeCharacters =
emojiData->nonQualifiedCode.toLower().split('-');
} else {
unicodeCharacters = emojiData->unifiedCode.toLower().split('-');
}
@ -87,8 +87,7 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
}
emojiData->value = QString::fromUcs4(unicodeBytes, numUnicodeBytes);
}
}
} // namespace
void Emojis::load()

View file

@ -10,8 +10,8 @@
namespace chatterino {
namespace {
Url getEmoteLink(const QJsonObject &urls, const QString &emoteScale)
{
Url getEmoteLink(const QJsonObject &urls, const QString &emoteScale)
{
auto emote = urls.value(emoteScale);
if (emote.isUndefined()) {
return {""};
@ -20,10 +20,10 @@ Url getEmoteLink(const QJsonObject &urls, const QString &emoteScale)
assert(emote.isString());
return {"https:" + emote.toString()};
}
void fillInEmoteData(const QJsonObject &urls, const EmoteName &name,
}
void fillInEmoteData(const QJsonObject &urls, const EmoteName &name,
const QString &tooltip, Emote &emoteData)
{
{
auto url1x = getEmoteLink(urls, "1");
auto url2x = getEmoteLink(urls, "2");
auto url3x = getEmoteLink(urls, "4");
@ -34,17 +34,17 @@ void fillInEmoteData(const QJsonObject &urls, const EmoteName &name,
ImageSet{Image::fromUrl(url1x, 1), Image::fromUrl(url2x, 0.5),
Image::fromUrl(url3x, 0.25)};
emoteData.tooltip = {tooltip};
}
EmotePtr cachedOrMake(Emote &&emote, const EmoteId &id)
{
}
EmotePtr cachedOrMake(Emote &&emote, const EmoteId &id)
{
static std::unordered_map<EmoteId, std::weak_ptr<const Emote>> cache;
static std::mutex mutex;
return cachedOrMakeEmotePtr(std::move(emote), cache, mutex, id);
}
std::pair<Outcome, EmoteMap> parseGlobalEmotes(const QJsonObject &jsonRoot,
const EmoteMap &currentEmotes)
{
}
std::pair<Outcome, EmoteMap> parseGlobalEmotes(
const QJsonObject &jsonRoot, const EmoteMap &currentEmotes)
{
auto jsonSets = jsonRoot.value("sets").toObject();
auto emotes = EmoteMap();
@ -59,8 +59,8 @@ std::pair<Outcome, EmoteMap> parseGlobalEmotes(const QJsonObject &jsonRoot,
auto urls = jsonEmote.value("urls").toObject();
auto emote = Emote();
fillInEmoteData(urls, name, name.string + "<br/>Global FFZ Emote",
emote);
fillInEmoteData(urls, name,
name.string + "<br/>Global FFZ Emote", emote);
emote.homePage =
Url{QString("https://www.frankerfacez.com/emoticon/%1-%2")
.arg(id.string)
@ -72,9 +72,9 @@ std::pair<Outcome, EmoteMap> parseGlobalEmotes(const QJsonObject &jsonRoot,
}
return {Success, std::move(emotes)};
}
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
{
}
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
{
auto jsonSets = jsonRoot.value("sets").toObject();
auto emotes = EmoteMap();
@ -85,13 +85,14 @@ std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
auto jsonEmote = _jsonEmote.toObject();
// margins
auto id = EmoteId{QString::number(jsonEmote.value("id").toInt())};
auto id =
EmoteId{QString::number(jsonEmote.value("id").toInt())};
auto name = EmoteName{jsonEmote.value("name").toString()};
auto urls = jsonEmote.value("urls").toObject();
Emote emote;
fillInEmoteData(urls, name, name.string + "<br/>Channel FFZ Emote",
emote);
fillInEmoteData(urls, name,
name.string + "<br/>Channel FFZ Emote", emote);
emote.homePage =
Url{QString("https://www.frankerfacez.com/emoticon/%1-%2")
.arg(id.string)
@ -102,7 +103,7 @@ std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
}
return {Success, std::move(emotes)};
}
}
} // namespace
FfzEmotes::FfzEmotes()

View file

@ -24,31 +24,31 @@ static std::map<QString, std::string> sentMessages;
namespace detail {
PubSubClient::PubSubClient(WebsocketClient &websocketClient,
PubSubClient::PubSubClient(WebsocketClient &websocketClient,
WebsocketHandle handle)
: websocketClient_(websocketClient)
, handle_(handle)
{
}
{
}
void PubSubClient::start()
{
void PubSubClient::start()
{
assert(!this->started_);
this->started_ = true;
this->ping();
}
}
void PubSubClient::stop()
{
void PubSubClient::stop()
{
assert(this->started_);
this->started_ = false;
}
}
bool PubSubClient::listen(rapidjson::Document &message)
{
bool PubSubClient::listen(rapidjson::Document &message)
{
int numRequestedListens = message["data"]["topics"].Size();
if (this->numListens_ + numRequestedListens > MAX_PUBSUB_LISTENS) {
@ -73,13 +73,14 @@ bool PubSubClient::listen(rapidjson::Document &message)
this->send(payload.c_str());
return true;
}
}
void PubSubClient::unlistenPrefix(const std::string &prefix)
{
void PubSubClient::unlistenPrefix(const std::string &prefix)
{
std::vector<std::string> topics;
for (auto it = this->listeners_.begin(); it != this->listeners_.end();) {
for (auto it = this->listeners_.begin();
it != this->listeners_.end();) {
const auto &listener = *it;
if (listener.topic.find(prefix) == 0) {
topics.push_back(listener.topic);
@ -103,19 +104,19 @@ void PubSubClient::unlistenPrefix(const std::string &prefix)
sentMessages[uuid] = payload;
this->send(payload.c_str());
}
}
void PubSubClient::handlePong()
{
void PubSubClient::handlePong()
{
assert(this->awaitingPong_);
log("Got pong!");
this->awaitingPong_ = false;
}
}
bool PubSubClient::isListeningToTopic(const std::string &payload)
{
bool PubSubClient::isListeningToTopic(const std::string &payload)
{
for (const auto &listener : this->listeners_) {
if (listener.topic == payload) {
return true;
@ -123,10 +124,10 @@ bool PubSubClient::isListeningToTopic(const std::string &payload)
}
return false;
}
}
void PubSubClient::ping()
{
void PubSubClient::ping()
{
assert(this->started_);
if (!this->send(pingPayload)) {
@ -137,44 +138,45 @@ void PubSubClient::ping()
auto self = this->shared_from_this();
runAfter(this->websocketClient_.get_io_service(), std::chrono::seconds(15),
[self](auto timer) {
runAfter(this->websocketClient_.get_io_service(),
std::chrono::seconds(15), [self](auto timer) {
if (!self->started_) {
return;
}
if (self->awaitingPong_) {
log("No pong respnose, disconnect!");
// TODO(pajlada): Label this connection as "disconnect me"
// TODO(pajlada): Label this connection as "disconnect
// me"
}
});
runAfter(this->websocketClient_.get_io_service(), std::chrono::minutes(5),
[self](auto timer) {
runAfter(this->websocketClient_.get_io_service(),
std::chrono::minutes(5), [self](auto timer) {
if (!self->started_) {
return;
}
self->ping(); //
});
}
}
bool PubSubClient::send(const char *payload)
{
bool PubSubClient::send(const char *payload)
{
WebsocketErrorCode ec;
this->websocketClient_.send(this->handle_, payload,
websocketpp::frame::opcode::text, ec);
if (ec) {
log("Error sending message {}: {}", payload, ec.message());
// TODO(pajlada): Check which error code happened and maybe gracefully
// handle it
// TODO(pajlada): Check which error code happened and maybe
// gracefully handle it
return false;
}
return true;
}
}
} // namespace detail

View file

@ -32,17 +32,18 @@ using WebsocketErrorCode = websocketpp::lib::error_code;
namespace detail {
struct Listener {
struct Listener {
std::string topic;
bool authed;
bool persistent;
bool confirmed = false;
};
};
class PubSubClient : public std::enable_shared_from_this<PubSubClient>
{
public:
PubSubClient(WebsocketClient &_websocketClient, WebsocketHandle _handle);
class PubSubClient : public std::enable_shared_from_this<PubSubClient>
{
public:
PubSubClient(WebsocketClient &_websocketClient,
WebsocketHandle _handle);
void start();
void stop();
@ -54,7 +55,7 @@ public:
bool isListeningToTopic(const std::string &topic);
private:
private:
void ping();
bool send(const char *payload);
@ -66,7 +67,7 @@ private:
std::atomic<bool> awaitingPong_{false};
std::atomic<bool> started_{false};
};
};
} // namespace detail

View file

@ -1,11 +1,10 @@
#pragma once
#include "debug/Log.hpp"
#include "util/RapidjsonHelpers.hpp"
#include "debug/Log.hpp"
#include <boost/asio.hpp>
#include <boost/asio/steady_timer.hpp>
#include <memory>
#include "debug/Log.hpp"
#include "util/RapidjsonHelpers.hpp"
namespace chatterino {

View file

@ -15,8 +15,8 @@ namespace chatterino {
namespace {
EmoteName cleanUpCode(const EmoteName &dirtyEmoteCode)
{
EmoteName cleanUpCode(const EmoteName &dirtyEmoteCode)
{
auto cleanCode = dirtyEmoteCode.string;
cleanCode.detach();
@ -39,7 +39,7 @@ EmoteName cleanUpCode(const EmoteName &dirtyEmoteCode)
cleanCode.replace("&gt;", ">");
return {cleanCode};
}
}
} // namespace
@ -417,7 +417,7 @@ void TwitchAccount::loadEmotes()
}
AccessGuard<const TwitchAccount::TwitchAccountEmoteData>
TwitchAccount::accessEmotes() const
TwitchAccount::accessEmotes() const
{
return this->emotes_.accessConst();
}

View file

@ -25,8 +25,9 @@
namespace chatterino {
namespace {
auto parseRecentMessages(const QJsonObject &jsonRoot, TwitchChannel &channel)
{
auto parseRecentMessages(const QJsonObject &jsonRoot,
TwitchChannel &channel)
{
QJsonArray jsonMessages = jsonRoot.value("messages").toArray();
std::vector<MessagePtr> messages;
@ -34,8 +35,8 @@ auto parseRecentMessages(const QJsonObject &jsonRoot, TwitchChannel &channel)
for (const auto jsonMessage : jsonMessages) {
auto content = jsonMessage.toString().toUtf8();
// passing nullptr as the channel makes the message invalid but we don't
// check for that anyways
// passing nullptr as the channel makes the message invalid but we
// don't check for that anyways
auto message = Communi::IrcMessage::fromData(content, nullptr);
auto privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(message);
assert(privMsg);
@ -48,9 +49,9 @@ auto parseRecentMessages(const QJsonObject &jsonRoot, TwitchChannel &channel)
}
return messages;
}
std::pair<Outcome, UsernameSet> parseChatters(const QJsonObject &jsonRoot)
{
}
std::pair<Outcome, UsernameSet> parseChatters(const QJsonObject &jsonRoot)
{
static QStringList categories = {"moderators", "staff", "admins",
"global_mods", "viewers"};
@ -66,7 +67,7 @@ std::pair<Outcome, UsernameSet> parseChatters(const QJsonObject &jsonRoot)
}
return {Success, std::move(usernames)};
}
}
} // namespace
TwitchChannel::TwitchChannel(const QString &name,
@ -309,7 +310,7 @@ bool TwitchChannel::isLive() const
}
AccessGuard<const TwitchChannel::StreamStatus>
TwitchChannel::accessStreamStatus() const
TwitchChannel::accessStreamStatus() const
{
return this->streamStatus_.accessConst();
}

View file

@ -8,10 +8,10 @@ namespace chatterino {
namespace {
template <typename Type>
inline bool ReadValue(const rapidjson::Value &object, const char *key,
template <typename Type>
inline bool ReadValue(const rapidjson::Value &object, const char *key,
Type &out)
{
{
if (!object.HasMember(key)) {
return false;
}
@ -25,12 +25,12 @@ inline bool ReadValue(const rapidjson::Value &object, const char *key,
out = value.Get<Type>();
return true;
}
}
template <>
inline bool ReadValue<QString>(const rapidjson::Value &object, const char *key,
QString &out)
{
template <>
inline bool ReadValue<QString>(const rapidjson::Value &object,
const char *key, QString &out)
{
if (!object.HasMember(key)) {
return false;
}
@ -44,13 +44,13 @@ inline bool ReadValue<QString>(const rapidjson::Value &object, const char *key,
out = value.GetString();
return true;
}
}
template <>
inline bool ReadValue<std::vector<QString>>(const rapidjson::Value &object,
template <>
inline bool ReadValue<std::vector<QString>>(const rapidjson::Value &object,
const char *key,
std::vector<QString> &out)
{
{
if (!object.HasMember(key)) {
return false;
}
@ -70,12 +70,12 @@ inline bool ReadValue<std::vector<QString>>(const rapidjson::Value &object,
}
return true;
}
}
// Parse a single cheermote set (or "action") from the twitch api
inline bool ParseSingleCheermoteSet(JSONCheermoteSet &set,
// Parse a single cheermote set (or "action") from the twitch api
inline bool ParseSingleCheermoteSet(JSONCheermoteSet &set,
const rapidjson::Value &action)
{
{
if (!action.IsObject()) {
return false;
}
@ -236,7 +236,7 @@ inline bool ParseSingleCheermoteSet(JSONCheermoteSet &set,
}
return true;
}
}
} // namespace
// Look through the results of

View file

@ -34,8 +34,8 @@ struct TwitchUser {
namespace pajlada {
namespace Settings {
template <>
struct Deserialize<chatterino::TwitchUser> {
template <>
struct Deserialize<chatterino::TwitchUser> {
static chatterino::TwitchUser get(const rapidjson::Value &value,
bool *error = nullptr)
{
@ -70,7 +70,7 @@ struct Deserialize<chatterino::TwitchUser> {
return user;
}
};
};
} // namespace Settings
} // namespace pajlada

View file

@ -9,16 +9,16 @@
#include <QtGlobal>
#ifdef Q_OS_WIN32
#define DEFAULT_FONT_FAMILY "Segoe UI"
#define DEFAULT_FONT_SIZE 10
# define DEFAULT_FONT_FAMILY "Segoe UI"
# define DEFAULT_FONT_SIZE 10
#else
#ifdef Q_OS_MACOS
#define DEFAULT_FONT_FAMILY "Helvetica Neue"
#define DEFAULT_FONT_SIZE 12
#else
#define DEFAULT_FONT_FAMILY "Arial"
#define DEFAULT_FONT_SIZE 11
#endif
# ifdef Q_OS_MACOS
# define DEFAULT_FONT_FAMILY "Helvetica Neue"
# define DEFAULT_FONT_SIZE 12
# else
# define DEFAULT_FONT_FAMILY "Arial"
# define DEFAULT_FONT_SIZE 11
# endif
#endif
namespace chatterino {
@ -104,8 +104,7 @@ Fonts::FontData Fonts::createFontData(FontStyle type, float scale)
{FontStyle::ChatMediumSmall, {0.8f, false, QFont::Normal}},
{FontStyle::ChatMedium, {1, false, QFont::Normal}},
{FontStyle::ChatMediumBold,
{1, false,
QFont::Weight(getSettings()->boldScale.getValue())}},
{1, false, QFont::Weight(getSettings()->boldScale.getValue())}},
{FontStyle::ChatMediumItalic, {1, true, QFont::Normal}},
{FontStyle::ChatLarge, {1.2f, false, QFont::Normal}},
{FontStyle::ChatVeryLarge, {1.4f, false, QFont::Normal}},

View file

@ -17,11 +17,11 @@
namespace ipc = boost::interprocess;
#ifdef Q_OS_WIN
#include <QProcess>
# include <QProcess>
#include <Windows.h>
#include "singletons/WindowManager.hpp"
#include "widgets/AttachedWindow.hpp"
# include <Windows.h>
# include "singletons/WindowManager.hpp"
# include "widgets/AttachedWindow.hpp"
#endif
#include <iostream>

View file

@ -10,8 +10,8 @@ namespace chatterino {
namespace detail {
double getMultiplierByTheme(const QString &themeName)
{
double getMultiplierByTheme(const QString &themeName)
{
if (themeName == "Light") {
return 0.8;
} else if (themeName == "White") {
@ -23,7 +23,7 @@ double getMultiplierByTheme(const QString &themeName)
}
return -0.8;
}
}
} // namespace detail

View file

@ -2,11 +2,11 @@
namespace chatterino {
namespace {
void appendDuration(int count, QChar &&order, QString &outString)
{
void appendDuration(int count, QChar &&order, QString &outString)
{
outString.append(QString::number(count));
outString.append(order);
}
}
} // namespace
QString formatTime(int totalSeconds)

View file

@ -4,7 +4,7 @@
namespace pajlada {
namespace Signals {
class SignalHolder;
class SignalHolder;
}
} // namespace pajlada

View file

@ -6,17 +6,17 @@
namespace pajlada {
namespace Settings {
template <>
struct Serialize<QString> {
template <>
struct Serialize<QString> {
static rapidjson::Value get(const QString &value,
rapidjson::Document::AllocatorType &a)
{
return rapidjson::Value(value.toUtf8(), a);
}
};
};
template <>
struct Deserialize<QString> {
template <>
struct Deserialize<QString> {
static QString get(const rapidjson::Value &value, bool *error = nullptr)
{
if (!value.IsString()) {
@ -37,7 +37,7 @@ struct Deserialize<QString> {
return QString{};
}
};
};
} // namespace Settings
} // namespace pajlada

View file

@ -5,26 +5,28 @@
namespace chatterino {
namespace rj {
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &&value,
void addMember(rapidjson::Value &obj, const char *key,
rapidjson::Value &&value,
rapidjson::Document::AllocatorType &a)
{
{
obj.AddMember(rapidjson::Value(key, a).Move(), value, a);
}
}
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &value,
void addMember(rapidjson::Value &obj, const char *key,
rapidjson::Value &value,
rapidjson::Document::AllocatorType &a)
{
{
obj.AddMember(rapidjson::Value(key, a).Move(), value.Move(), a);
}
}
std::string stringify(const rapidjson::Value &value)
{
std::string stringify(const rapidjson::Value &value)
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value.Accept(writer);
return std::string(buffer.GetString());
}
}
} // namespace rj
} // namespace chatterino

View file

@ -11,63 +11,67 @@
namespace chatterino {
namespace rj {
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &&value,
void addMember(rapidjson::Value &obj, const char *key,
rapidjson::Value &&value,
rapidjson::Document::AllocatorType &a);
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &value,
void addMember(rapidjson::Value &obj, const char *key,
rapidjson::Value &value,
rapidjson::Document::AllocatorType &a);
template <typename Type>
void set(rapidjson::Value &obj, const char *key, const Type &value,
template <typename Type>
void set(rapidjson::Value &obj, const char *key, const Type &value,
rapidjson::Document::AllocatorType &a)
{
{
assert(obj.IsObject());
addMember(obj, key, pajlada::Settings::Serialize<Type>::get(value, a), a);
}
addMember(obj, key, pajlada::Settings::Serialize<Type>::get(value, a),
a);
}
template <>
inline void set(rapidjson::Value &obj, const char *key,
template <>
inline void set(rapidjson::Value &obj, const char *key,
const rapidjson::Value &value,
rapidjson::Document::AllocatorType &a)
{
{
assert(obj.IsObject());
addMember(obj, key, const_cast<rapidjson::Value &>(value), a);
}
}
template <typename Type>
void set(rapidjson::Document &obj, const char *key, const Type &value)
{
template <typename Type>
void set(rapidjson::Document &obj, const char *key, const Type &value)
{
assert(obj.IsObject());
auto &a = obj.GetAllocator();
addMember(obj, key, pajlada::Settings::Serialize<Type>::get(value, a), a);
}
addMember(obj, key, pajlada::Settings::Serialize<Type>::get(value, a),
a);
}
template <>
inline void set(rapidjson::Document &obj, const char *key,
template <>
inline void set(rapidjson::Document &obj, const char *key,
const rapidjson::Value &value)
{
{
assert(obj.IsObject());
auto &a = obj.GetAllocator();
addMember(obj, key, const_cast<rapidjson::Value &>(value), a);
}
}
template <typename Type>
void add(rapidjson::Value &arr, const Type &value,
template <typename Type>
void add(rapidjson::Value &arr, const Type &value,
rapidjson::Document::AllocatorType &a)
{
{
assert(arr.IsArray());
arr.PushBack(pajlada::Settings::Serialize<Type>::get(value, a), a);
}
}
template <typename Type>
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
{
template <typename Type>
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
{
if (!obj.IsObject()) {
return false;
}
@ -84,18 +88,18 @@ bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
out = pajlada::Settings::Deserialize<Type>::get(obj[key], &error);
return !error;
}
}
template <typename Type>
bool getSafe(const rapidjson::Value &value, Type &out)
{
template <typename Type>
bool getSafe(const rapidjson::Value &value, Type &out)
{
bool error = false;
out = pajlada::Settings::Deserialize<Type>::get(value, &error);
return !error;
}
}
std::string stringify(const rapidjson::Value &value);
std::string stringify(const rapidjson::Value &value);
} // namespace rj
} // namespace chatterino

View file

@ -2,9 +2,9 @@
#include "Application.hpp"
#include "Helpers.hpp"
#include "debug/Log.hpp"
#include "singletons/Settings.hpp"
#include "widgets/dialogs/QualityPopup.hpp"
#include "debug/Log.hpp"
#include <QErrorMessage>
#include <QFileInfo>
@ -16,26 +16,26 @@ namespace chatterino {
namespace {
const char *getBinaryName()
{
const char *getBinaryName()
{
#ifdef _WIN32
return "streamlink.exe";
#else
return "streamlink";
#endif
}
}
const char *getDefaultBinaryPath()
{
const char *getDefaultBinaryPath()
{
#ifdef _WIN32
return "C:\\Program Files (x86)\\Streamlink\\bin\\streamlink.exe";
#else
return "/usr/bin/streamlink";
#endif
}
}
QString getStreamlinkProgram()
{
QString getStreamlinkProgram()
{
auto app = getApp();
if (getSettings()->streamlinkUseCustomPath) {
@ -43,29 +43,30 @@ QString getStreamlinkProgram()
} else {
return getBinaryName();
}
}
}
bool checkStreamlinkPath(const QString &path)
{
bool checkStreamlinkPath(const QString &path)
{
QFileInfo fileinfo(path);
if (!fileinfo.exists()) {
return false;
// throw Exception(fS("Streamlink path ({}) is invalid, file does not
// exist", path));
// throw Exception(fS("Streamlink path ({}) is invalid, file does
// not exist", path));
}
return fileinfo.isExecutable();
}
}
void showStreamlinkNotFoundError()
{
void showStreamlinkNotFoundError()
{
static QErrorMessage *msg = new QErrorMessage;
auto app = getApp();
if (getSettings()->streamlinkUseCustomPath) {
msg->showMessage(
"Unable to find Streamlink executable\nMake sure your custom path "
"Unable to find Streamlink executable\nMake sure your custom "
"path "
"is pointing "
"to the DIRECTORY where the streamlink executable is located");
} else {
@ -73,10 +74,10 @@ void showStreamlinkNotFoundError()
"Unable to find Streamlink executable.\nIf you have Streamlink "
"installed, you might need to enable the custom path option");
}
}
}
QProcess *createStreamlinkProcess()
{
QProcess *createStreamlinkProcess()
{
auto p = new QProcess;
p->setProgram(getStreamlinkProgram());
@ -90,14 +91,14 @@ QProcess *createStreamlinkProcess()
p->deleteLater();
});
QObject::connect(p,
static_cast<void (QProcess::*)(int)>(&QProcess::finished),
QObject::connect(
p, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
[=](int res) {
p->deleteLater(); //
});
return p;
}
}
} // namespace

View file

@ -2,8 +2,8 @@
#ifdef USEWINSDK
#include <Windows.h>
#include <boost/optional.hpp>
# include <Windows.h>
# include <boost/optional.hpp>
namespace chatterino {

View file

@ -8,12 +8,12 @@
#include <QVBoxLayout>
#ifdef USEWINSDK
#include "util/WindowsHelper.hpp"
# include "util/WindowsHelper.hpp"
#include "Windows.h"
# include "Windows.h"
// don't even think about reordering these
#include "Psapi.h"
#pragma comment(lib, "Dwmapi.lib")
# include "Psapi.h"
# pragma comment(lib, "Dwmapi.lib")
#endif
namespace chatterino {

View file

@ -20,20 +20,20 @@
#include <functional>
#ifdef USEWINSDK
#include <ObjIdl.h>
#include <VersionHelpers.h>
#include <Windows.h>
#include <dwmapi.h>
#include <gdiplus.h>
#include <windowsx.h>
# include <ObjIdl.h>
# include <VersionHelpers.h>
# include <Windows.h>
# include <dwmapi.h>
# include <gdiplus.h>
# include <windowsx.h>
//#include <ShellScalingApi.h>
#pragma comment(lib, "Dwmapi.lib")
# pragma comment(lib, "Dwmapi.lib")
#include <QHBoxLayout>
#include <QVBoxLayout>
# include <QHBoxLayout>
# include <QVBoxLayout>
#define WM_DPICHANGED 0x02E0
# define WM_DPICHANGED 0x02E0
#endif
#include "widgets/helper/TitlebarButton.hpp"
@ -460,11 +460,11 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message,
long *result)
{
#ifdef USEWINSDK
#if (QT_VERSION == QT_VERSION_CHECK(5, 11, 1))
# if (QT_VERSION == QT_VERSION_CHECK(5, 11, 1))
MSG *msg = *reinterpret_cast<MSG **>(message);
#else
# else
MSG *msg = reinterpret_cast<MSG *>(message);
#endif
# endif
bool returnValue = false;

View file

@ -433,8 +433,7 @@ void SplitNotebook::addCustomButtons()
// settings
auto settingsBtn = this->addCustomButton();
settingsBtn->setVisible(
!getSettings()->hidePreferencesButton.getValue());
settingsBtn->setVisible(!getSettings()->hidePreferencesButton.getValue());
getSettings()->hidePreferencesButton.connect(
[settingsBtn](bool hide, auto) { settingsBtn->setVisible(!hide); },

View file

@ -7,7 +7,7 @@
#include "widgets/splits/Split.hpp"
#ifdef USEWEBENGINE
#include <QtWebEngineWidgets>
# include <QtWebEngineWidgets>
#endif
namespace chatterino {

View file

@ -10,7 +10,7 @@
#include <QVBoxLayout>
#ifdef USEWINSDK
#include <Windows.h>
# include <Windows.h>
#endif
namespace chatterino {

View file

@ -16,30 +16,32 @@
namespace chatterino {
namespace {
auto makeTitleMessage(const QString &title)
{
auto makeTitleMessage(const QString &title)
{
MessageBuilder builder;
builder.emplace<TextElement>(title, MessageElementFlag::Text);
builder->flags.set(MessageFlag::Centered);
return builder.release();
}
auto makeEmoteMessage(const EmoteMap &map)
{
}
auto makeEmoteMessage(const EmoteMap &map)
{
MessageBuilder builder;
builder->flags.set(MessageFlag::Centered);
builder->flags.set(MessageFlag::DisableCompactEmotes);
for (const auto &emote : map) {
builder
.emplace<EmoteElement>(emote.second, MessageElementFlag::AlwaysShow)
.emplace<EmoteElement>(emote.second,
MessageElementFlag::AlwaysShow)
->setLink(Link(Link::InsertText, emote.first.string));
}
return builder.release();
}
void addEmoteSets(std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> sets,
}
void addEmoteSets(
std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> sets,
Channel &globalChannel, Channel &subChannel)
{
{
for (const auto &set : sets) {
auto &channel = set->key == "0" ? globalChannel : subChannel;
@ -64,7 +66,7 @@ void addEmoteSets(std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> sets,
channel.addMessage(builder.release());
}
}
}
} // namespace
EmotePopup::EmotePopup()

View file

@ -7,7 +7,7 @@
#include "providers/twitch/PartialTwitchUser.hpp"
#ifdef USEWINSDK
#include <Windows.h>
# include <Windows.h>
#endif
#include <QClipboard>
@ -21,11 +21,11 @@ namespace chatterino {
namespace {
void LogInWithCredentials(const std::string &userID,
void LogInWithCredentials(const std::string &userID,
const std::string &username,
const std::string &clientID,
const std::string &oauthToken)
{
{
QStringList errors;
if (userID.empty()) {
@ -68,7 +68,7 @@ void LogInWithCredentials(const std::string &userID,
// messageBox.exec();
getApp()->accounts->twitch.currentUsername = username;
}
}
} // namespace

View file

@ -39,9 +39,9 @@
namespace chatterino {
namespace {
void addEmoteContextMenuItems(const Emote &emote,
void addEmoteContextMenuItems(const Emote &emote,
MessageElementFlags creatorFlags, QMenu &menu)
{
{
auto openAction = menu.addAction("Open");
auto openMenu = new QMenu;
openAction->setMenu(openMenu);
@ -63,8 +63,8 @@ void addEmoteContextMenuItems(const Emote &emote,
QString(scale) + "x link", [url = image->url()] {
QApplication::clipboard()->setText(url.string);
});
openMenu->addAction(QString(scale) + "x link",
[url = image->url()] {
openMenu->addAction(
QString(scale) + "x link", [url = image->url()] {
QDesktopServices::openUrl(QUrl(url.string));
});
}
@ -83,8 +83,8 @@ void addEmoteContextMenuItems(const Emote &emote,
"Copy " + name + " emote link", [url = emote.homePage] {
QApplication::clipboard()->setText(url.string); //
});
openMenu->addAction("Open " + name + " emote link",
[url = emote.homePage] {
openMenu->addAction(
"Open " + name + " emote link", [url = emote.homePage] {
QDesktopServices::openUrl(QUrl(url.string)); //
});
};
@ -94,7 +94,7 @@ void addEmoteContextMenuItems(const Emote &emote,
} else if (creatorFlags.has(MessageElementFlag::FfzEmote)) {
addPageLink("FFZ");
}
}
}
} // namespace
ChannelView::ChannelView(BaseWidget *parent)

View file

@ -9,15 +9,13 @@
"Choose", "Source", "High", "Medium", "Low", "Audio only"
namespace chatterino {
namespace {
QString CreateLink(const QString &url, const QString &name)
{
return QString("<a href=\"" + url + "\"><span style=\"color: white;\">" +
name + "</span></a>");
}
QString createLink(const QString &url, const QString &name)
{
return QString("<a href=\"" + url +
"\"><span style=\"color: white;\">" + name +
"</span></a>");
}
} // namespace
ExternalToolsPage::ExternalToolsPage()
@ -41,8 +39,8 @@ ExternalToolsPage::ExternalToolsPage()
description->setStyleSheet("color: #bbb");
auto links = new QLabel(
CreateLink("https://streamlink.github.io/", "Website") + " " +
CreateLink(
createLink("https://streamlink.github.io/", "Website") + " " +
createLink(
"https://github.com/streamlink/streamlink/releases/latest",
"Download"));
links->setTextFormat(Qt::RichText);

View file

@ -69,8 +69,7 @@ void addPhrasesTab(LayoutCreator<QVBoxLayout> layout)
void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users,
QStringListModel &userModel)
{
users.append(
page.createCheckBox("Enable twitch ignored users",
users.append(page.createCheckBox("Enable twitch ignored users",
getSettings()->enableTwitchIgnoredUsers));
auto anyways = users.emplace<QHBoxLayout>().withoutMargin();

View file

@ -31,9 +31,9 @@
// clang-format on
#ifdef USEWINSDK
#define WINDOW_TOPMOST "Window always on top"
# define WINDOW_TOPMOST "Window always on top"
#else
#define WINDOW_TOPMOST "Window always on top (requires restart)"
# define WINDOW_TOPMOST "Window always on top (requires restart)"
#endif
#define INPUT_EMPTY "Show input box when empty"
#define LAST_MSG "Mark the last message you read"

View file

@ -25,7 +25,7 @@
namespace chatterino {
inline QString CreateLink(const QString &url, bool file = false)
inline QString createLink(const QString &url, bool file = false)
{
if (file) {
return QString("<a href=\"file:///" + url +

View file

@ -26,13 +26,13 @@
#include <cmath>
#ifdef USEWEBENGINE
#include "widgets/StreamView.hpp"
# include "widgets/StreamView.hpp"
#endif
namespace chatterino {
namespace {
auto formatRoomMode(TwitchChannel &channel) -> QString
{
auto formatRoomMode(TwitchChannel &channel) -> QString
{
QString text;
{
@ -40,7 +40,8 @@ auto formatRoomMode(TwitchChannel &channel) -> QString
if (modes->r9k) text += "r9k, ";
if (modes->slowMode)
text += QString("slow(%1), ").arg(QString::number(modes->slowMode));
text +=
QString("slow(%1), ").arg(QString::number(modes->slowMode));
if (modes->emoteOnly) text += "emote, ";
if (modes->submode) text += "sub, ";
}
@ -60,9 +61,9 @@ auto formatRoomMode(TwitchChannel &channel) -> QString
if (text.isEmpty() && channel.hasModRights()) return "none";
return text;
}
auto formatTooltip(const TwitchChannel::StreamStatus &s)
{
}
auto formatTooltip(const TwitchChannel::StreamStatus &s)
{
return QStringList{"<style>.center { text-align: center; }</style>",
"<p class=\"center\">",
s.title,
@ -77,9 +78,9 @@ auto formatTooltip(const TwitchChannel::StreamStatus &s)
" viewers",
"</p>"}
.join("");
}
auto formatTitle(const TwitchChannel::StreamStatus &s, Settings &settings)
{
}
auto formatTitle(const TwitchChannel::StreamStatus &s, Settings &settings)
{
auto title = QString();
// live
@ -98,14 +99,14 @@ auto formatTitle(const TwitchChannel::StreamStatus &s, Settings &settings)
if (settings.showUptime) title += " - " + s.uptime;
return title;
}
auto distance(QPoint a, QPoint b)
{
}
auto distance(QPoint a, QPoint b)
{
auto x = std::abs(a.x() - b.x());
auto y = std::abs(a.y() - b.y());
return std::sqrt(x * x + y * y);
}
}
} // namespace
SplitHeader::SplitHeader(Split *_split)