added brace wrapping after if and for
This commit is contained in:
@@ -21,7 +21,8 @@ public:
|
||||
QMutexLocker lock(&this->mutex_);
|
||||
|
||||
auto a = this->data_.find(name);
|
||||
if (a == this->data_.end()) {
|
||||
if (a == this->data_.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,7 +36,8 @@ public:
|
||||
QMutexLocker lock(&this->mutex_);
|
||||
|
||||
auto a = this->data_.find(name);
|
||||
if (a == this->data_.end()) {
|
||||
if (a == this->data_.end())
|
||||
{
|
||||
TValue value = addLambda();
|
||||
this->data_.insert(name, value);
|
||||
return value;
|
||||
@@ -72,7 +74,8 @@ public:
|
||||
|
||||
QMapIterator<TKey, TValue> it(this->data_);
|
||||
|
||||
while (it.hasNext()) {
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
func(it.key(), it.value());
|
||||
}
|
||||
@@ -84,7 +87,8 @@ public:
|
||||
|
||||
QMutableMapIterator<TKey, TValue> it(this->data_);
|
||||
|
||||
while (it.hasNext()) {
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
func(it.key(), it.value());
|
||||
}
|
||||
|
||||
+12
-5
@@ -18,9 +18,12 @@ public:
|
||||
auto counts = counts_.access();
|
||||
|
||||
auto it = counts->find(name);
|
||||
if (it == counts->end()) {
|
||||
if (it == counts->end())
|
||||
{
|
||||
counts->insert(name, 1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reinterpret_cast<int64_t &>(it.value())++;
|
||||
}
|
||||
}
|
||||
@@ -30,9 +33,12 @@ public:
|
||||
auto counts = counts_.access();
|
||||
|
||||
auto it = counts->find(name);
|
||||
if (it == counts->end()) {
|
||||
if (it == counts->end())
|
||||
{
|
||||
counts->insert(name, -1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reinterpret_cast<int64_t &>(it.value())--;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +48,8 @@ public:
|
||||
auto counts = counts_.access();
|
||||
|
||||
QString text;
|
||||
for (auto it = counts->begin(); it != counts->end(); it++) {
|
||||
for (auto it = counts->begin(); it != counts->end(); it++)
|
||||
{
|
||||
text += it.key() + ": " + QString::number(it.value()) + "\n";
|
||||
}
|
||||
return text;
|
||||
|
||||
+14
-7
@@ -19,23 +19,30 @@ QString formatTime(int totalSeconds)
|
||||
int timeoutHours = timeoutMinutes / 60;
|
||||
int hours = timeoutHours % 24;
|
||||
int days = timeoutHours / 24;
|
||||
if (days > 0) {
|
||||
if (days > 0)
|
||||
{
|
||||
appendDuration(days, 'd', res);
|
||||
}
|
||||
if (hours > 0) {
|
||||
if (!res.isEmpty()) {
|
||||
if (hours > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(hours, 'h', res);
|
||||
}
|
||||
if (minutes > 0) {
|
||||
if (!res.isEmpty()) {
|
||||
if (minutes > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(minutes, 'm', res);
|
||||
}
|
||||
if (seconds > 0) {
|
||||
if (!res.isEmpty()) {
|
||||
if (seconds > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(seconds, 's', res);
|
||||
|
||||
@@ -19,7 +19,8 @@ static QString CreateUUID()
|
||||
|
||||
static QString createLink(const QString &url, bool file = false)
|
||||
{
|
||||
if (file) {
|
||||
if (file)
|
||||
{
|
||||
return QString("<a href=\"file:///" + url +
|
||||
"\"><span style=\"color: white;\">" + url +
|
||||
"</span></a>");
|
||||
@@ -29,9 +30,11 @@ static QString createLink(const QString &url, bool file = false)
|
||||
url + "</span></a>");
|
||||
}
|
||||
|
||||
static QString createNamedLink(const QString &url, const QString &name, bool file = false)
|
||||
static QString createNamedLink(const QString &url, const QString &name,
|
||||
bool file = false)
|
||||
{
|
||||
if (file) {
|
||||
if (file)
|
||||
{
|
||||
return QString("<a href=\"file:///" + url +
|
||||
"\"><span style=\"color: white;\">" + name +
|
||||
"</span></a>");
|
||||
@@ -43,7 +46,8 @@ static QString createNamedLink(const QString &url, const QString &name, bool fil
|
||||
|
||||
static QString shortenString(const QString &str, unsigned maxWidth = 50)
|
||||
{
|
||||
if (str.size() <= maxWidth) {
|
||||
if (str.size() <= maxWidth)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ namespace {
|
||||
|
||||
// transform into regex and replacement string
|
||||
std::vector<std::pair<QRegularExpression, QString>> replacers;
|
||||
for (const auto &switch_ : switches) {
|
||||
for (const auto &switch_ : switches)
|
||||
{
|
||||
replacers.emplace_back(
|
||||
QRegularExpression("(" + switch_.first + "\\.exe\"?).*",
|
||||
QRegularExpression::CaseInsensitiveOption),
|
||||
@@ -29,8 +30,10 @@ namespace {
|
||||
}
|
||||
|
||||
// try to find matching regex and apply it
|
||||
for (const auto &replacement : replacers) {
|
||||
if (replacement.first.match(command).hasMatch()) {
|
||||
for (const auto &replacement : replacers)
|
||||
{
|
||||
if (replacement.first.match(command).hasMatch())
|
||||
{
|
||||
command.replace(replacement.first, replacement.second);
|
||||
return command;
|
||||
}
|
||||
@@ -57,13 +60,15 @@ namespace {
|
||||
QSettings::NativeFormat)
|
||||
.value("Default")
|
||||
.toString();
|
||||
if (command.isNull()) return QString();
|
||||
if (command.isNull())
|
||||
return QString();
|
||||
|
||||
log(command);
|
||||
|
||||
// inject switch to enable private browsing
|
||||
command = injectPrivateSwitch(command);
|
||||
if (command.isNull()) return QString();
|
||||
if (command.isNull())
|
||||
return QString();
|
||||
|
||||
// link
|
||||
command += " " + link;
|
||||
|
||||
@@ -20,13 +20,18 @@ void initUpdateButton(Button &button,
|
||||
dialog->raise();
|
||||
|
||||
dialog->buttonClicked.connect([&button](auto buttonType) {
|
||||
switch (buttonType) {
|
||||
case UpdateDialog::Dismiss: {
|
||||
switch (buttonType)
|
||||
{
|
||||
case UpdateDialog::Dismiss:
|
||||
{
|
||||
button.hide();
|
||||
} break;
|
||||
case UpdateDialog::Install: {
|
||||
}
|
||||
break;
|
||||
case UpdateDialog::Install:
|
||||
{
|
||||
Updates::getInstance().installUpdates();
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+30
-15
@@ -11,34 +11,49 @@ inline QString parseTagString(const QString &input)
|
||||
|
||||
auto length = output.length();
|
||||
|
||||
for (int i = 0; i < length - 1; i++) {
|
||||
if (output[i] == '\\') {
|
||||
for (int i = 0; i < length - 1; i++)
|
||||
{
|
||||
if (output[i] == '\\')
|
||||
{
|
||||
QChar c = output[i + 1];
|
||||
|
||||
switch (c.cell()) {
|
||||
case 'n': {
|
||||
switch (c.cell())
|
||||
{
|
||||
case 'n':
|
||||
{
|
||||
output.replace(i, 2, '\n');
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r': {
|
||||
case 'r':
|
||||
{
|
||||
output.replace(i, 2, '\r');
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's': {
|
||||
case 's':
|
||||
{
|
||||
output.replace(i, 2, ' ');
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\\': {
|
||||
case '\\':
|
||||
{
|
||||
output.replace(i, 2, '\\');
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ':': {
|
||||
case ':':
|
||||
{
|
||||
output.replace(i, 2, ';');
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
default:
|
||||
{
|
||||
output.remove(i, 1);
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
@@ -153,7 +153,8 @@ private:
|
||||
int>::type = 0>
|
||||
QLayout *getOrCreateLayout()
|
||||
{
|
||||
if (!this->item_->layout()) {
|
||||
if (!this->item_->layout())
|
||||
{
|
||||
this->item_->setLayout(new QHBoxLayout());
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,10 @@ T *makeLayout(std::initializer_list<LayoutItem> items)
|
||||
{
|
||||
auto t = new T;
|
||||
|
||||
for (auto &item : items) {
|
||||
switch (item.which()) {
|
||||
for (auto &item : items)
|
||||
{
|
||||
switch (item.which())
|
||||
{
|
||||
case 0:
|
||||
t->addItem(new QWidgetItem(boost::get<QWidget *>(item)));
|
||||
break;
|
||||
|
||||
@@ -19,19 +19,25 @@ namespace Settings {
|
||||
struct Deserialize<QString> {
|
||||
static QString get(const rapidjson::Value &value, bool *error = nullptr)
|
||||
{
|
||||
if (!value.IsString()) {
|
||||
if (!value.IsString())
|
||||
{
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION(
|
||||
"Deserialized rapidjson::Value is not a string");
|
||||
return QString{};
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
return QString::fromUtf8(value.GetString(),
|
||||
value.GetStringLength());
|
||||
} catch (const std::exception &) {
|
||||
}
|
||||
catch (const std::exception &)
|
||||
{
|
||||
// int x = 5;
|
||||
} catch (...) {
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// int y = 5;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,15 +72,18 @@ namespace rj {
|
||||
template <typename Type>
|
||||
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
|
||||
{
|
||||
if (!obj.IsObject()) {
|
||||
if (!obj.IsObject())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!obj.HasMember(key)) {
|
||||
if (!obj.HasMember(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj.IsNull()) {
|
||||
if (obj.IsNull())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+58
-24
@@ -38,9 +38,12 @@ namespace {
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
if (getSettings()->streamlinkUseCustomPath) {
|
||||
if (getSettings()->streamlinkUseCustomPath)
|
||||
{
|
||||
return getSettings()->streamlinkPath + "/" + getBinaryName();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return getBinaryName();
|
||||
}
|
||||
}
|
||||
@@ -49,7 +52,8 @@ namespace {
|
||||
{
|
||||
QFileInfo fileinfo(path);
|
||||
|
||||
if (!fileinfo.exists()) {
|
||||
if (!fileinfo.exists())
|
||||
{
|
||||
return false;
|
||||
// throw Exception(fS("Streamlink path ({}) is invalid, file does
|
||||
// not exist", path));
|
||||
@@ -63,13 +67,16 @@ namespace {
|
||||
static QErrorMessage *msg = new QErrorMessage;
|
||||
|
||||
auto app = getApp();
|
||||
if (getSettings()->streamlinkUseCustomPath) {
|
||||
if (getSettings()->streamlinkUseCustomPath)
|
||||
{
|
||||
msg->showMessage(
|
||||
"Unable to find Streamlink executable\nMake sure your custom "
|
||||
"path "
|
||||
"is pointing "
|
||||
"to the DIRECTORY where the streamlink executable is located");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
msg->showMessage(
|
||||
"Unable to find Streamlink executable.\nIf you have Streamlink "
|
||||
"installed, you might need to enable the custom path option");
|
||||
@@ -82,9 +89,12 @@ namespace {
|
||||
p->setProgram(getStreamlinkProgram());
|
||||
|
||||
QObject::connect(p, &QProcess::errorOccurred, [=](auto err) {
|
||||
if (err == QProcess::FailedToStart) {
|
||||
if (err == QProcess::FailedToStart)
|
||||
{
|
||||
showStreamlinkNotFoundError();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
log("Error occured {}", err);
|
||||
}
|
||||
|
||||
@@ -110,20 +120,24 @@ void getStreamQualities(const QString &channelURL,
|
||||
QObject::connect(
|
||||
p, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
|
||||
[=](int res) {
|
||||
if (res != 0) {
|
||||
if (res != 0)
|
||||
{
|
||||
log("Got error code {}", res);
|
||||
// return;
|
||||
}
|
||||
QString lastLine = QString(p->readAllStandardOutput());
|
||||
lastLine = lastLine.trimmed().split('\n').last().trimmed();
|
||||
if (lastLine.startsWith("Available streams: ")) {
|
||||
if (lastLine.startsWith("Available streams: "))
|
||||
{
|
||||
QStringList options;
|
||||
QStringList split =
|
||||
lastLine.right(lastLine.length() - 19).split(", ");
|
||||
|
||||
for (int i = split.length() - 1; i >= 0; i--) {
|
||||
for (int i = split.length() - 1; i >= 0; i--)
|
||||
{
|
||||
QString option = split.at(i);
|
||||
if (option == "best)") {
|
||||
if (option == "best)")
|
||||
{
|
||||
// As it turns out, sometimes, one quality option can
|
||||
// be the best and worst quality at the same time.
|
||||
// Since we start loop from the end, we can check
|
||||
@@ -131,11 +145,17 @@ void getStreamQualities(const QString &channelURL,
|
||||
option = split.at(--i);
|
||||
// "900p60 (worst"
|
||||
options << option.left(option.length() - 7);
|
||||
} else if (option.endsWith(" (worst)")) {
|
||||
}
|
||||
else if (option.endsWith(" (worst)"))
|
||||
{
|
||||
options << option.left(option.length() - 8);
|
||||
} else if (option.endsWith(" (best)")) {
|
||||
}
|
||||
else if (option.endsWith(" (best)"))
|
||||
{
|
||||
options << option.left(option.length() - 7);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
options << option;
|
||||
}
|
||||
}
|
||||
@@ -157,7 +177,8 @@ void openStreamlink(const QString &channelURL, const QString &quality,
|
||||
QStringList arguments;
|
||||
|
||||
QString additionalOptions = getSettings()->streamlinkOpts.getValue();
|
||||
if (!additionalOptions.isEmpty()) {
|
||||
if (!additionalOptions.isEmpty())
|
||||
{
|
||||
arguments << getSettings()->streamlinkOpts;
|
||||
}
|
||||
|
||||
@@ -165,14 +186,16 @@ void openStreamlink(const QString &channelURL, const QString &quality,
|
||||
|
||||
arguments << channelURL;
|
||||
|
||||
if (!quality.isEmpty()) {
|
||||
if (!quality.isEmpty())
|
||||
{
|
||||
arguments << quality;
|
||||
}
|
||||
|
||||
bool res = QProcess::startDetached(getStreamlinkProgram() + " " +
|
||||
QString(arguments.join(' ')));
|
||||
|
||||
if (!res) {
|
||||
if (!res)
|
||||
{
|
||||
showStreamlinkNotFoundError();
|
||||
}
|
||||
}
|
||||
@@ -186,7 +209,8 @@ void openStreamlinkForChannel(const QString &channel)
|
||||
QString preferredQuality = getSettings()->preferredQuality;
|
||||
preferredQuality = preferredQuality.toLower();
|
||||
|
||||
if (preferredQuality == "choose") {
|
||||
if (preferredQuality == "choose")
|
||||
{
|
||||
getStreamQualities(channelURL, [=](QStringList qualityOptions) {
|
||||
QualityPopup::showDialog(channel, qualityOptions);
|
||||
});
|
||||
@@ -201,21 +225,31 @@ void openStreamlinkForChannel(const QString &channel)
|
||||
// Streamlink qualities to exclude
|
||||
QString exclude;
|
||||
|
||||
if (preferredQuality == "high") {
|
||||
if (preferredQuality == "high")
|
||||
{
|
||||
exclude = ">720p30";
|
||||
quality = "high,best";
|
||||
} else if (preferredQuality == "medium") {
|
||||
}
|
||||
else if (preferredQuality == "medium")
|
||||
{
|
||||
exclude = ">540p30";
|
||||
quality = "medium,best";
|
||||
} else if (preferredQuality == "low") {
|
||||
}
|
||||
else if (preferredQuality == "low")
|
||||
{
|
||||
exclude = ">360p30";
|
||||
quality = "low,best";
|
||||
} else if (preferredQuality == "audio only") {
|
||||
}
|
||||
else if (preferredQuality == "audio only")
|
||||
{
|
||||
quality = "audio,audio_only";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
quality = "best";
|
||||
}
|
||||
if (!exclude.isEmpty()) {
|
||||
if (!exclude.isEmpty())
|
||||
{
|
||||
args << "--stream-sorting-excludes" << exclude;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,11 @@ typedef HRESULT(CALLBACK *GetDpiForMonitor_)(HMONITOR, MONITOR_DPI_TYPE, UINT *,
|
||||
boost::optional<UINT> getWindowDpi(HWND hwnd)
|
||||
{
|
||||
static HINSTANCE shcore = LoadLibrary(L"Shcore.dll");
|
||||
if (shcore != nullptr) {
|
||||
if (shcore != nullptr)
|
||||
{
|
||||
if (auto getDpiForMonitor =
|
||||
GetDpiForMonitor_(GetProcAddress(shcore, "GetDpiForMonitor"))) {
|
||||
GetDpiForMonitor_(GetProcAddress(shcore, "GetDpiForMonitor")))
|
||||
{
|
||||
HMONITOR monitor =
|
||||
MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
@@ -39,8 +41,11 @@ typedef HRESULT(CALLBACK *OleFlushClipboard_)();
|
||||
void flushClipboard()
|
||||
{
|
||||
static HINSTANCE ole32 = LoadLibrary(L"Ole32.dll");
|
||||
if (ole32 != nullptr) {
|
||||
if (auto oleFlushClipboard = OleFlushClipboard_(GetProcAddress(ole32, "OleFlushClipboard"))) {
|
||||
if (ole32 != nullptr)
|
||||
{
|
||||
if (auto oleFlushClipboard =
|
||||
OleFlushClipboard_(GetProcAddress(ole32, "OleFlushClipboard")))
|
||||
{
|
||||
oleFlushClipboard();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ namespace chatterino {
|
||||
boost::optional<UINT> getWindowDpi(HWND hwnd);
|
||||
void flushClipboard();
|
||||
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
#endif
|
||||
|
||||
+11
-10
@@ -5,17 +5,18 @@
|
||||
namespace chatterino {
|
||||
namespace util {
|
||||
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
typename Container::iterator find_if(Container &container, UnaryPredicate pred)
|
||||
{
|
||||
return std::find_if(container.begin(), container.end(), pred);
|
||||
}
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
typename Container::iterator find_if(Container &container,
|
||||
UnaryPredicate pred)
|
||||
{
|
||||
return std::find_if(container.begin(), container.end(), pred);
|
||||
}
|
||||
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
bool any_of(Container &container, UnaryPredicate pred)
|
||||
{
|
||||
return std::any_of(container.begin(), container.end(), pred);
|
||||
}
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
bool any_of(Container &container, UnaryPredicate pred)
|
||||
{
|
||||
return std::any_of(container.begin(), container.end(), pred);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user