mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Show thumbnails for live streams inside of the split header tooltip (#1702)
This feature is enabled by default and can be disabled in the Settings dialog with the "Show stream thumbnail" setting
This commit is contained in:
parent
f7b063f265
commit
6d5ba0c442
|
@ -162,6 +162,7 @@ public:
|
||||||
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
||||||
BoolSetting linkInfoTooltip = {"/links/linkInfoTooltip", false};
|
BoolSetting linkInfoTooltip = {"/links/linkInfoTooltip", false};
|
||||||
IntSetting thumbnailSize = {"/appearance/thumbnailSize", 0};
|
IntSetting thumbnailSize = {"/appearance/thumbnailSize", 0};
|
||||||
|
IntSetting thumbnailSizeStream = {"/appearance/thumbnailSizeStream", 2};
|
||||||
BoolSetting unshortLinks = {"/links/unshortLinks", false};
|
BoolSetting unshortLinks = {"/links/unshortLinks", false};
|
||||||
BoolSetting lowercaseDomains = {"/links/linkLowercase", true};
|
BoolSetting lowercaseDomains = {"/links/linkLowercase", true};
|
||||||
|
|
||||||
|
|
|
@ -544,6 +544,31 @@ void GeneralPage::initLayout(SettingsLayout &layout)
|
||||||
else if (args.value == "Large")
|
else if (args.value == "Large")
|
||||||
return 300;
|
return 300;
|
||||||
|
|
||||||
|
return fuzzyToInt(args.value, 0);
|
||||||
|
});
|
||||||
|
layout.addDropdown<int>(
|
||||||
|
"Show stream thumbnail", {"Off", "Small", "Medium", "Large"},
|
||||||
|
s.thumbnailSizeStream,
|
||||||
|
[](auto val) {
|
||||||
|
if (val == 0)
|
||||||
|
return QString("Off");
|
||||||
|
else if (val == 1)
|
||||||
|
return QString("Small");
|
||||||
|
else if (val == 2)
|
||||||
|
return QString("Medium");
|
||||||
|
else if (val == 3)
|
||||||
|
return QString("Large");
|
||||||
|
else
|
||||||
|
return QString::number(val);
|
||||||
|
},
|
||||||
|
[](auto args) {
|
||||||
|
if (args.value == "Small")
|
||||||
|
return 1;
|
||||||
|
else if (args.value == "Medium")
|
||||||
|
return 2;
|
||||||
|
else if (args.value == "Large")
|
||||||
|
return 3;
|
||||||
|
|
||||||
return fuzzyToInt(args.value, 0);
|
return fuzzyToInt(args.value, 0);
|
||||||
});
|
});
|
||||||
layout.addCheckbox("Double click to open links and other elements in chat",
|
layout.addCheckbox("Double click to open links and other elements in chat",
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "widgets/splits/Split.hpp"
|
#include "widgets/splits/Split.hpp"
|
||||||
#include "widgets/splits/SplitContainer.hpp"
|
#include "widgets/splits/SplitContainer.hpp"
|
||||||
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
@ -85,12 +84,18 @@ namespace {
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
auto formatTooltip(const TwitchChannel::StreamStatus &s)
|
auto formatTooltip(const TwitchChannel::StreamStatus &s, QString thumbnail)
|
||||||
{
|
{
|
||||||
return QString("<style>.center { text-align: center; }</style> \
|
return QString("<style>.center { text-align: center; }</style> \
|
||||||
<p class=\"center\">%1%2%3%4%5 for %6 with %7 viewers</p>")
|
<p class=\"center\">%1%2%3%4%5%6 for %7 with %8 viewers</p>")
|
||||||
.arg(s.title.toHtmlEscaped())
|
.arg(s.title.toHtmlEscaped())
|
||||||
.arg(s.title.isEmpty() ? QString() : "<br><br>")
|
.arg(s.title.isEmpty() ? QString() : "<br><br>")
|
||||||
|
.arg(getSettings()->thumbnailSizeStream.getValue() > 0
|
||||||
|
? (thumbnail.isEmpty()
|
||||||
|
? "Couldn't fetch thumbnail"
|
||||||
|
: "<img src=\"data:image/jpg;base64, " + thumbnail +
|
||||||
|
"\"/><br>")
|
||||||
|
: QString())
|
||||||
.arg(s.game.toHtmlEscaped())
|
.arg(s.game.toHtmlEscaped())
|
||||||
.arg(s.game.isEmpty() ? QString() : "<br>")
|
.arg(s.game.isEmpty() ? QString() : "<br>")
|
||||||
.arg(s.rerun ? "Vod-casting" : "Live")
|
.arg(s.rerun ? "Vod-casting" : "Live")
|
||||||
|
@ -567,7 +572,38 @@ void SplitHeader::updateChannelText()
|
||||||
if (streamStatus->live)
|
if (streamStatus->live)
|
||||||
{
|
{
|
||||||
this->isLive_ = true;
|
this->isLive_ = true;
|
||||||
this->tooltipText_ = formatTooltip(*streamStatus);
|
QString url = "https://static-cdn.jtvnw.net/"
|
||||||
|
"previews-ttv/live_user_" +
|
||||||
|
channel->getName().toLower();
|
||||||
|
switch (getSettings()->thumbnailSizeStream.getValue())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
url.append("-80x45.jpg");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
url.append("-160x90.jpg");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
url.append("-360x180.jpg");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
url = "";
|
||||||
|
}
|
||||||
|
if (!url.isEmpty() &&
|
||||||
|
(!this->lastThumbnail_.isValid() ||
|
||||||
|
this->lastThumbnail_.elapsed() > 5 * 60 * 1000))
|
||||||
|
{
|
||||||
|
NetworkRequest(url, NetworkRequestType::Get)
|
||||||
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
|
this->thumbnail_ =
|
||||||
|
QString::fromLatin1(result.getData().toBase64());
|
||||||
|
updateChannelText();
|
||||||
|
return Success;
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
|
this->lastThumbnail_.restart();
|
||||||
|
}
|
||||||
|
this->tooltipText_ = formatTooltip(*streamStatus, this->thumbnail_);
|
||||||
title += formatTitle(*streamStatus, *getSettings());
|
title += formatTitle(*streamStatus, *getSettings());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -52,6 +52,8 @@ private:
|
||||||
Split *const split_{};
|
Split *const split_{};
|
||||||
QString tooltipText_{};
|
QString tooltipText_{};
|
||||||
bool isLive_{false};
|
bool isLive_{false};
|
||||||
|
QString thumbnail_;
|
||||||
|
QElapsedTimer lastThumbnail_;
|
||||||
|
|
||||||
// ui
|
// ui
|
||||||
Button *dropdownButton_{};
|
Button *dropdownButton_{};
|
||||||
|
|
Loading…
Reference in a new issue