This commit is contained in:
fourtf 2017-01-05 20:49:33 +01:00
parent a8006cf68c
commit 4d96dcc5e3
13 changed files with 210 additions and 149 deletions

View file

@ -1,11 +1,18 @@
#ifndef APPSETTINGS_H #ifndef APPSETTINGS_H
#define APPSETTINGS_H #define APPSETTINGS_H
#include "word.h"
class AppSettings class AppSettings
{ {
public: public:
Word::Type wordTypeMask() {
return m_wordTypeMask;
}
private:
AppSettings(); AppSettings();
Word::Type m_wordTypeMask = Word::Default;
}; };
#endif // APPSETTINGS_H #endif // APPSETTINGS_H

View file

@ -7,12 +7,12 @@ const Channel Channel::mentions = Channel(QString("/mentions"));
QMap<QString, Channel*> Channel::channels = QMap<QString, Channel*>(); QMap<QString, Channel*> Channel::channels = QMap<QString, Channel*>();
Channel::Channel(QString channel) Channel::Channel(QString channel)
: m_name((channel.length() > 0 && channel[0] == '#') ? channel.mid(1) : channel)
{ {
messageMutex = new QMutex(); messageMutex = new QMutex();
name = (channel.length() > 0 && channel[0] == '#') ? channel.mid(1) : channel; subLink = "https://www.twitch.tv/" + m_name + "/subscribe?ref=in_chat_subscriber_link";
subLink = "https://www.twitch.tv/" + name + "/subscribe?ref=in_chat_subscriber_link"; channelLink = "https://twitch.tv/" + m_name;
channelLink = "https://twitch.tv/" + name; popoutPlayerLink = "https://player.twitch.tv/?channel=" + m_name;
popoutPlayerLink = "https://player.twitch.tv/?channel=" + name;
} }
//Channel::~Channel() //Channel::~Channel()

View file

@ -18,7 +18,6 @@ public:
static Channel* getChannel(const QString &channel); static Channel* getChannel(const QString &channel);
static void removeChannel(const QString &channel); static void removeChannel(const QString &channel);
public:
QString getSubLink(); QString getSubLink();
QString getChannelLink(); QString getChannelLink();
QString getPopoutPlayerLink(); QString getPopoutPlayerLink();
@ -28,6 +27,10 @@ public:
QString getStreamStatus(); QString getStreamStatus();
QString getStreamGame(); QString getStreamGame();
const QString& name() {
return m_name;
}
void addMessage(Message* message); void addMessage(Message* message);
// ~Channel(); // ~Channel();
@ -42,7 +45,7 @@ private:
int referenceCount = 1; int referenceCount = 1;
QString name; QString m_name;
int roomID; int roomID;

View file

@ -54,7 +54,8 @@ SOURCES += main.cpp\
message.cpp \ message.cpp \
word.cpp \ word.cpp \
link.cpp \ link.cpp \
fonts.cpp fonts.cpp \
appsettings.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
chatwidget.h \ chatwidget.h \
@ -85,7 +86,8 @@ HEADERS += mainwindow.h \
word.h \ word.h \
link.h \ link.h \
fonts.h \ fonts.h \
common.h common.h \
appsettings.h
PRECOMPILED_HEADER = common.h PRECOMPILED_HEADER = common.h

View file

@ -9,6 +9,13 @@ ConcurrentMap<QString, LazyLoadedImage* >* Emotes::m_fFzChannelEmoteFromCaches
ConcurrentMap<int, LazyLoadedImage* >* Emotes::m_twitchEmoteFromCache = new ConcurrentMap<int, LazyLoadedImage* >(); ConcurrentMap<int, LazyLoadedImage* >* Emotes::m_twitchEmoteFromCache = new ConcurrentMap<int, LazyLoadedImage* >();
ConcurrentMap<int, LazyLoadedImage* >* Emotes::m_miscImageFromCache = new ConcurrentMap<int, LazyLoadedImage* >(); ConcurrentMap<int, LazyLoadedImage* >* Emotes::m_miscImageFromCache = new ConcurrentMap<int, LazyLoadedImage* >();
LazyLoadedImage* Emotes::m_cheerBadge100000 = new LazyLoadedImage(new QImage(":/cheer100000"));
LazyLoadedImage* Emotes::m_cheerBadge10000 = new LazyLoadedImage(new QImage(":/cheer10000"));
LazyLoadedImage* Emotes::m_cheerBadge5000 = new LazyLoadedImage(new QImage(":/cheer5000"));
LazyLoadedImage* Emotes::m_cheerBadge1000 = new LazyLoadedImage(new QImage(":/cheer1000"));
LazyLoadedImage* Emotes::m_cheerBadge100 = new LazyLoadedImage(new QImage(":/cheer100"));
LazyLoadedImage* Emotes::m_cheerBadge1 = new LazyLoadedImage(new QImage(":/cheer1"));
Emotes::Emotes() Emotes::Emotes()
{ {
@ -16,35 +23,34 @@ Emotes::Emotes()
LazyLoadedImage* Emotes::getCheerImage(long long amount, bool animated) LazyLoadedImage* Emotes::getCheerImage(long long amount, bool animated)
{ {
#pragma message WARN("Implement Emotes::getCheerImage") #warning "xD"
// object image; return getCheerBadge(amount);
}
// if (cheer >= 100000)
// { LazyLoadedImage* Emotes::getCheerBadge(long long amount)
// image = GuiEngine.Current.GetImage(ImageType.Cheer100000); {
// } if (amount >= 100000)
// else if (cheer >= 10000) {
// { return m_cheerBadge100000;
// image = GuiEngine.Current.GetImage(ImageType.Cheer10000); }
// } else if (amount >= 10000)
// else if (cheer >= 5000) {
// { return m_cheerBadge10000;
// image = GuiEngine.Current.GetImage(ImageType.Cheer5000); }
// } else if (amount >= 5000)
// else if (cheer >= 1000) {\
// { return m_cheerBadge5000;
// image = GuiEngine.Current.GetImage(ImageType.Cheer1000); }
// } else if (amount >= 1000)
// else if (cheer >= 100) {
// { return m_cheerBadge1000;
// image = GuiEngine.Current.GetImage(ImageType.Cheer100); }
// } else if (amount >= 100)
// else {
// { return m_cheerBadge100;
// image = GuiEngine.Current.GetImage(ImageType.Cheer1); }
// } else
{
// words.Add(new Word { Type = SpanType.Image, Value = image, Tooltip = "Twitch Cheer " + cheer }); return m_cheerBadge1;
}
return new LazyLoadedImage("");
} }

View file

@ -22,6 +22,7 @@ public:
static void loadGlobalEmotes(); static void loadGlobalEmotes();
static LazyLoadedImage* getCheerImage(long long int amount, bool animated); static LazyLoadedImage* getCheerImage(long long int amount, bool animated);
static LazyLoadedImage* getCheerBadge(long long int amount);
private: private:
Emotes(); Emotes();
@ -34,6 +35,13 @@ private:
static ConcurrentMap<QString, LazyLoadedImage* >* m_fFzChannelEmoteFromCaches; static ConcurrentMap<QString, LazyLoadedImage* >* m_fFzChannelEmoteFromCaches;
static ConcurrentMap<int, LazyLoadedImage* >* m_twitchEmoteFromCache; static ConcurrentMap<int, LazyLoadedImage* >* m_twitchEmoteFromCache;
static ConcurrentMap<int, LazyLoadedImage* >* m_miscImageFromCache; static ConcurrentMap<int, LazyLoadedImage* >* m_miscImageFromCache;
static LazyLoadedImage* m_cheerBadge100000;
static LazyLoadedImage* m_cheerBadge10000 ;
static LazyLoadedImage* m_cheerBadge5000 ;
static LazyLoadedImage* m_cheerBadge1000 ;
static LazyLoadedImage* m_cheerBadge100 ;
static LazyLoadedImage* m_cheerBadge1 ;
}; };
#endif // EMOTES_H #endif // EMOTES_H

View file

@ -1,6 +1,15 @@
#include "link.h" #include "link.h"
Link::Link() Link::Link()
: m_type(None)
, m_value(QString())
{
}
Link::Link(Type type, const QString& value)
: m_type(type)
, m_value(value)
{ {
} }

29
link.h
View file

@ -1,11 +1,38 @@
#ifndef LINK_H #ifndef LINK_H
#define LINK_H #define LINK_H
#include <QString>
class Link class Link
{ {
public: public:
enum Type {
None,
Url,
CloseCurrentSplit,
UserInfo,
InsertText,
ShowMessage,
};
Link(); Link();
Link(Type type, const QString& value);
bool isValid() {
return m_type == None;
}
Type type() {
return m_type;
}
const QString& value() {
return m_value;
}
private:
Type m_type;
QString m_value;
}; };
#endif // LINK_H #endif // LINK_H

View file

@ -18,14 +18,22 @@ Message::Message(const QString &text)
} }
Message::Message(const IrcPrivateMessage& ircMessage, const Channel& Channel) Message::Message(const IrcPrivateMessage& ircMessage, const Channel& channel, bool enablePingSound,
bool isReceivedWhisper, bool isSentWhisper, bool includeChannel )
{ {
m_parseTime = std::chrono::system_clock::now(); m_parseTime = std::chrono::system_clock::now();
auto words = new QList<Word>(); auto words = new QList<Word>();
auto iterator = ircMessage.tags().find("id");
if (iterator != ircMessage.tags().end())
{
m_id = iterator.value().toString();
}
// timestamps // timestamps
auto iterator = ircMessage.tags().find("tmi-sent-ts"); iterator = ircMessage.tags().find("tmi-sent-ts");
std::time_t time = std::time(NULL); std::time_t time = std::time(NULL);
if (iterator != ircMessage.tags().end()) if (iterator != ircMessage.tags().end())
@ -41,11 +49,24 @@ Message::Message(const IrcPrivateMessage& ircMessage, const Channel& Channel)
strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&time)); strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&time));
QString timestampWithSeconds = QString(timeStampBuffer); QString timestampWithSeconds = QString(timeStampBuffer);
QString copytext(""); words->append(Word(timestamp, Word::TimestampNoSeconds, ColorScheme::getInstance().SystemMessageColor, QString(), QString()));
QString tooltip(""); words->append(Word(timestampWithSeconds, Word::TimestampWithSeconds, ColorScheme::getInstance().SystemMessageColor, QString(), QString()));
// words->append(*new Word(timestamp, Word::TimestampNoSeconds, copytext, tooltip)); // color
// words->append(*new Word(timestampWithSeconds, Word::TimestampWithSeconds, copytext, tooltip)); QColor usernameColor = ColorScheme::getInstance().SystemMessageColor;
iterator = ircMessage.tags().find("color");
if (iterator != ircMessage.tags().end())
{
usernameColor = QColor(iterator.value().toString());
}
// channel name
if (includeChannel)
{
QString channelName("#" + channel.name());
words->append(Word(channelName, Word::Misc, QString(channelName), QString(), Link(Link::ShowMessage, channel.name() + "\n" + m_id)));
}
// username // username
m_userName = ircMessage.account(); m_userName = ircMessage.account();
@ -65,24 +86,20 @@ Message::Message(const IrcPrivateMessage& ircMessage, const Channel& Channel)
iterator = ircMessage.tags().find("display-name"); iterator = ircMessage.tags().find("display-name");
if (iterator == ircMessage.tags().end()) { if (iterator == ircMessage.tags().end()) {
displayName = m_userName; displayName = ircMessage.account();
} }
else { else {
displayName = iterator.value().toString(); displayName = iterator.value().toString();
} }
bool hasLocalizedName = QString::compare(displayName, ircMessage.account()) == 0;
QString userDisplayString = displayName + (hasLocalizedName ? (" (" + ircMessage.account() + ")") : QString());
words->append(Word(userDisplayString, Word::Username, usernameColor, userDisplayString, QString()));
// highlights // highlights
#pragma message WARN("xD") #pragma message WARN("xD")
// color
QColor usernameColor = ColorScheme::getInstance().SystemMessageColor;
iterator = ircMessage.tags().find("color");
if (iterator != ircMessage.tags().end())
{
usernameColor = QColor(iterator.value().toString());
}
// bits // bits
QString bits = ""; QString bits = "";
@ -103,86 +120,40 @@ Message::Message(const IrcPrivateMessage& ircMessage, const Channel& Channel)
{ {
if (badge.startsWith("bits/")) if (badge.startsWith("bits/"))
{ {
long long int cheer = strtoll(badge.mid(5).toStdString().c_str(), NULL, 10);
words->append(Word(Emotes::getCheerBadge(cheer), Word::BadgeCheer, QString(), QString("Twitch Cheer" + QString::number(cheer))));
} }
else if (badge == "staff/1") else if (badge == "staff/1")
{ {
QString a(""); words->append(Word(badgeStaff, Word::BadgeStaff, QString(), QString("Twitch Staff")));
QString b("Twitch Staff"); }
words->append(*new Word(badgeStaff, Word::BadgeStaff, a, b)); else if (badge == "admin/1")
{
words->append(Word(badgeAdmin, Word::BadgeAdmin, QString(), QString("Twitch Admin")));
}
else if (badge == "global_mod/1")
{
words->append(Word(badgeGlobalmod, Word::BadgeGlobalMod, QString(), QString("Global Moderator")));
}
else if (badge == "moderator/1")
{
#warning "xD"
words->append(Word(badgeTurbo, Word::BadgeModerator, QString(), QString("Channel Moderator"))); // custom badge
}
else if (badge == "turbo/1")
{
words->append(Word(badgeStaff, Word::BadgeTurbo, QString(), QString("Turbo Subscriber")));
}
else if (badge == "broadcaster/1")
{
words->append(Word(badgeBroadcaster, Word::BadgeBroadcaster, QString(), QString("Channel Broadcaster")));
}
else if (badge == "premium/1")
{
words->append(Word(badgePremium, Word::BadgePremium, QString(), QString("Twitch Prime")));
} }
// else if (badge == "admin/1")
// {
// words->append(*new Word(badgeAdmin, Word::BadgeAdmin, "", "Twitch Admin"));
// }
// else if (badge == "global_mod/1")
// {
// words->append(*new Word(badgeGlobalmod, Word::BadgeGlobalMod, "", "Global Moderator"));
// }
// else if (badge == "moderator/1")
// {
//#warning "xD"
// words->append(*new Word(badgeTurbo, Word::BadgeModerator, "", "Channel Moderator")); // custom badge
// }
// else if (badge == "turbo/1")
// {
// words->append(*new Word(badgeStaff, Word::BadgeTurbo, "", "Turbo Subscriber"));
// }
// else if (badge == "broadcaster/1")
// {
// words->append(*new Word(badgeBroadcaster, Word::BadgeBroadcaster, "", "Channel Broadcaster"));
// }
// else if (badge == "premium/1")
// {
// words->append(*new Word(badgeTwitchPrime, Word::BadgePremium, "", "Twitch Prime"));
// }
// case "staff/1":
// Badges |= MessageBadges.Staff;
// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeStaff), Tooltip = });
// break;
// case "admin/1":
// Badges |= MessageBadges.Admin;
// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeAdmin), Tooltip = "Twitch Admin" });
// break;
// case "global_mod/1":
// Badges |= MessageBadges.GlobalMod;
// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeGlobalmod), Tooltip = "Global Moderator" });
// break;
// case "moderator/1":
// Badges |= MessageBadges.Mod;
// if (channel.ModeratorBadge == null)
// {
// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeModerator), Tooltip = "Channel Moderator" });
// }
// else
// {
// words.Add(new Word { Type = SpanType.LazyLoadedImage, Value = channel.ModeratorBadge, Tooltip = channel.ModeratorBadge.Tooltip });
// }
// break;
// case "turbo/1":
// Badges |= MessageBadges.Turbo;
// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeTurbo), Tooltip = "Turbo Subscriber" });
// break;
// case "broadcaster/1":
// Badges |= MessageBadges.Broadcaster;
// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeBroadcaster), Tooltip = "Channel Broadcaster" });
// break;
// case "premium/1":
// Badges |= MessageBadges.Broadcaster;
// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeTwitchPrime), Tooltip = "Twitch Prime" });
// break;
// long long int cheer = strtoll(badge.mid(5).toStdString().c_str(), NULL, 10);
// auto image = Emotes::getCheerImage(cheer, false);
// auto imageAnimated = Emotes::getCheerImage(cheer, true);
// words->append(*new Word(image, Word::Bits));
// words->append(*new Word(imageAnimated, Word::BitsAnimated));
} }
} }
} }

View file

@ -21,13 +21,14 @@ public:
// }; // };
Message(const QString& text); Message(const QString& text);
Message(const IrcPrivateMessage& ircMessage, const Channel& Channel); Message(const IrcPrivateMessage& ircMessage, const Channel& Channel, bool enablePingSound = true,
bool isReceivedWhisper = false, bool isSentWhisper = false, bool includeChannel = false);
bool canHighlightTab() { bool canHighlightTab() {
return m_highlightTab; return m_highlightTab;
} }
QString timeoutUser() { const QString& timeoutUser() {
return m_timeoutUser; return m_timeoutUser;
} }
@ -35,11 +36,11 @@ public:
return m_timeoutCount; return m_timeoutCount;
} }
QString userName() { const QString& userName() {
return m_userName; return m_userName;
} }
QString displayName() { const QString& displayName() {
return m_displayName; return m_displayName;
} }
@ -51,6 +52,10 @@ public:
return m_disabled; return m_disabled;
} }
const QString& id() {
return m_id;
}
private: private:
static LazyLoadedImage* badgeStaff; static LazyLoadedImage* badgeStaff;
static LazyLoadedImage* badgeAdmin; static LazyLoadedImage* badgeAdmin;
@ -68,6 +73,7 @@ private:
QString m_userName = ""; QString m_userName = "";
QString m_displayName = ""; QString m_displayName = "";
QString m_id = "";
QList<Word> m_words; QList<Word> m_words;
}; };

View file

@ -14,7 +14,7 @@ public:
return m_id; return m_id;
} }
QString channelName() { const QString& channelName() {
return m_channelName; return m_channelName;
} }

View file

@ -1,27 +1,27 @@
#include "word.h" #include "word.h"
// Image word // Image word
Word::Word(LazyLoadedImage* image, Type type, const QString& copytext, const QString& tooltip) Word::Word(LazyLoadedImage* image, Type type, const QString& copytext, const QString& tooltip, const Link& link)
: m_image(image) : m_image(image)
, m_text() , m_text()
, m_isImage(true) , m_isImage(true)
, m_type(type) , m_type(type)
, m_copyText(copytext) , m_copyText(copytext)
, m_tooltip(tooltip) , m_tooltip(tooltip)
, m_color()
, m_link(link)
{ {
} }
// Text word // Text word
Word::Word(const QString& text, Type type, const QString& copytext, const QString& tooltip) Word::Word(const QString& text, Type type, const QColor& color, const QString& copytext, const QString& tooltip, const Link& link)
: m_image(nullptr) : m_image(nullptr)
, m_text(text) , m_text(text)
, m_isImage(true) , m_isImage(true)
, m_type(type) , m_type(type)
, m_copyText(copytext) , m_copyText(copytext)
, m_tooltip(tooltip) , m_tooltip(tooltip)
{ , m_color(color)
} , m_link(link)
Word::~Word()
{ {
} }

32
word.h
View file

@ -3,6 +3,7 @@
#include "lazyloadedimage.h" #include "lazyloadedimage.h"
#include "fonts.h" #include "fonts.h"
#include "link.h"
#include <QRect> #include <QRect>
#include <QString> #include <QString>
@ -38,13 +39,24 @@ public:
BadgeBroadcaster = 0x80000, BadgeBroadcaster = 0x80000,
BadgePremium = 0x100000, BadgePremium = 0x100000,
BadgeChatterino = 0x200000, BadgeChatterino = 0x200000,
BadgeBits = 0x400000, BadgeCheer = 0x400000,
Badges = BadgeStaff
| BadgeAdmin
| BadgeGlobalMod
| BadgeModerator
| BadgeTurbo
| BadgeBroadcaster
| BadgePremium
| BadgeChatterino
| BadgeCheer,
Username = 0x800000,
Default = TimestampNoSeconds | Badges | Username | Bits | FfzEmoteImage | BttvEmoteImage | BttvGifEmoteImage | TwitchEmoteImage
}; };
explicit Word(LazyLoadedImage* m_image, Type type, const QString& copytext, const QString& tooltip = ""); explicit Word(LazyLoadedImage* m_image, Type type, const QString& copytext, const QString& tooltip, const Link& link = Link());
explicit Word(const QString& m_text, Type type, const QString& copytext, const QString& tooltip = ""); explicit Word(const QString& m_text, Type type, const QColor& color, const QString& copytext, const QString& tooltip, const Link& link = Link());
~Word();
LazyLoadedImage& getImage() { LazyLoadedImage& getImage() {
return *m_image; return *m_image;
@ -98,9 +110,18 @@ public:
return m_tooltip; return m_tooltip;
} }
const QColor& color() {
return m_color;
}
const Link& link() {
return m_link;
}
private: private:
LazyLoadedImage* m_image; LazyLoadedImage* m_image;
QString m_text; QString m_text;
QColor m_color;
bool m_isImage; bool m_isImage;
Type m_type; Type m_type;
@ -112,6 +133,7 @@ private:
int m_height; int m_height;
bool m_hasTrailingSpace; bool m_hasTrailingSpace;
Fonts::Type m_font = Fonts::Medium; Fonts::Type m_font = Fonts::Medium;
Link m_link;
}; };
#endif // WORD_H #endif // WORD_H