From 4d96dcc5e3c163b6217fc54a763641d263d35df0 Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 5 Jan 2017 20:49:33 +0100 Subject: [PATCH] asd --- appsettings.h | 9 ++- channel.cpp | 8 +-- channel.h | 7 +- chatterino.pro | 6 +- emotes.cpp | 68 +++++++++++--------- emotes.h | 8 +++ link.cpp | 9 +++ link.h | 29 ++++++++- message.cpp | 155 ++++++++++++++++++--------------------------- message.h | 14 ++-- twitchemotevalue.h | 2 +- word.cpp | 12 ++-- word.h | 32 ++++++++-- 13 files changed, 210 insertions(+), 149 deletions(-) diff --git a/appsettings.h b/appsettings.h index 3aa10fa6e..56147762c 100644 --- a/appsettings.h +++ b/appsettings.h @@ -1,11 +1,18 @@ #ifndef APPSETTINGS_H #define APPSETTINGS_H +#include "word.h" class AppSettings { public: + Word::Type wordTypeMask() { + return m_wordTypeMask; + } + +private: AppSettings(); + Word::Type m_wordTypeMask = Word::Default; }; -#endif // APPSETTINGS_H \ No newline at end of file +#endif // APPSETTINGS_H diff --git a/channel.cpp b/channel.cpp index 0673ff4c6..3fa4194b8 100644 --- a/channel.cpp +++ b/channel.cpp @@ -7,12 +7,12 @@ const Channel Channel::mentions = Channel(QString("/mentions")); QMap Channel::channels = QMap(); Channel::Channel(QString channel) + : m_name((channel.length() > 0 && channel[0] == '#') ? channel.mid(1) : channel) { messageMutex = new QMutex(); - name = (channel.length() > 0 && channel[0] == '#') ? channel.mid(1) : channel; - subLink = "https://www.twitch.tv/" + name + "/subscribe?ref=in_chat_subscriber_link"; - channelLink = "https://twitch.tv/" + name; - popoutPlayerLink = "https://player.twitch.tv/?channel=" + name; + subLink = "https://www.twitch.tv/" + m_name + "/subscribe?ref=in_chat_subscriber_link"; + channelLink = "https://twitch.tv/" + m_name; + popoutPlayerLink = "https://player.twitch.tv/?channel=" + m_name; } //Channel::~Channel() diff --git a/channel.h b/channel.h index 99443825b..2f487748a 100644 --- a/channel.h +++ b/channel.h @@ -18,7 +18,6 @@ public: static Channel* getChannel(const QString &channel); static void removeChannel(const QString &channel); -public: QString getSubLink(); QString getChannelLink(); QString getPopoutPlayerLink(); @@ -28,6 +27,10 @@ public: QString getStreamStatus(); QString getStreamGame(); + const QString& name() { + return m_name; + } + void addMessage(Message* message); // ~Channel(); @@ -42,7 +45,7 @@ private: int referenceCount = 1; - QString name; + QString m_name; int roomID; diff --git a/chatterino.pro b/chatterino.pro index ebc70e3ad..91ff48ded 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -54,7 +54,8 @@ SOURCES += main.cpp\ message.cpp \ word.cpp \ link.cpp \ - fonts.cpp + fonts.cpp \ + appsettings.cpp HEADERS += mainwindow.h \ chatwidget.h \ @@ -85,7 +86,8 @@ HEADERS += mainwindow.h \ word.h \ link.h \ fonts.h \ - common.h + common.h \ + appsettings.h PRECOMPILED_HEADER = common.h diff --git a/emotes.cpp b/emotes.cpp index 24e59b166..d36d4088e 100644 --- a/emotes.cpp +++ b/emotes.cpp @@ -9,6 +9,13 @@ ConcurrentMap* Emotes::m_fFzChannelEmoteFromCaches ConcurrentMap* Emotes::m_twitchEmoteFromCache = new ConcurrentMap(); ConcurrentMap* Emotes::m_miscImageFromCache = new ConcurrentMap(); +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() { @@ -16,35 +23,34 @@ Emotes::Emotes() LazyLoadedImage* Emotes::getCheerImage(long long amount, bool animated) { -#pragma message WARN("Implement Emotes::getCheerImage") -// object image; - -// if (cheer >= 100000) -// { -// image = GuiEngine.Current.GetImage(ImageType.Cheer100000); -// } -// else if (cheer >= 10000) -// { -// image = GuiEngine.Current.GetImage(ImageType.Cheer10000); -// } -// else if (cheer >= 5000) -// { -// image = GuiEngine.Current.GetImage(ImageType.Cheer5000); -// } -// else if (cheer >= 1000) -// { -// image = GuiEngine.Current.GetImage(ImageType.Cheer1000); -// } -// else if (cheer >= 100) -// { -// image = GuiEngine.Current.GetImage(ImageType.Cheer100); -// } -// else -// { -// image = GuiEngine.Current.GetImage(ImageType.Cheer1); -// } - -// words.Add(new Word { Type = SpanType.Image, Value = image, Tooltip = "Twitch Cheer " + cheer }); - - return new LazyLoadedImage(""); +#warning "xD" + return getCheerBadge(amount); +} + +LazyLoadedImage* Emotes::getCheerBadge(long long amount) +{ + if (amount >= 100000) + { + return m_cheerBadge100000; + } + else if (amount >= 10000) + { + return m_cheerBadge10000; + } + else if (amount >= 5000) + {\ + return m_cheerBadge5000; + } + else if (amount >= 1000) + { + return m_cheerBadge1000; + } + else if (amount >= 100) + { + return m_cheerBadge100; + } + else + { + return m_cheerBadge1; + } } diff --git a/emotes.h b/emotes.h index a43cdd526..488d066dc 100644 --- a/emotes.h +++ b/emotes.h @@ -22,6 +22,7 @@ public: static void loadGlobalEmotes(); static LazyLoadedImage* getCheerImage(long long int amount, bool animated); + static LazyLoadedImage* getCheerBadge(long long int amount); private: Emotes(); @@ -34,6 +35,13 @@ private: static ConcurrentMap* m_fFzChannelEmoteFromCaches; static ConcurrentMap* m_twitchEmoteFromCache; static ConcurrentMap* 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 diff --git a/link.cpp b/link.cpp index 0d9028fc8..5182da08b 100644 --- a/link.cpp +++ b/link.cpp @@ -1,6 +1,15 @@ #include "link.h" Link::Link() + : m_type(None) + , m_value(QString()) +{ + +} + +Link::Link(Type type, const QString& value) + : m_type(type) + , m_value(value) { } diff --git a/link.h b/link.h index f606d420a..3dc3eb649 100644 --- a/link.h +++ b/link.h @@ -1,11 +1,38 @@ #ifndef LINK_H #define LINK_H +#include class Link { public: + enum Type { + None, + Url, + CloseCurrentSplit, + UserInfo, + InsertText, + ShowMessage, + }; + 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 \ No newline at end of file +#endif // LINK_H diff --git a/message.cpp b/message.cpp index 933f90961..eea6cef2e 100644 --- a/message.cpp +++ b/message.cpp @@ -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(); auto words = new QList(); + auto iterator = ircMessage.tags().find("id"); + + if (iterator != ircMessage.tags().end()) + { + m_id = iterator.value().toString(); + } + // timestamps - auto iterator = ircMessage.tags().find("tmi-sent-ts"); + iterator = ircMessage.tags().find("tmi-sent-ts"); std::time_t time = std::time(NULL); 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)); QString timestampWithSeconds = QString(timeStampBuffer); - QString copytext(""); - QString tooltip(""); + words->append(Word(timestamp, Word::TimestampNoSeconds, ColorScheme::getInstance().SystemMessageColor, QString(), QString())); + words->append(Word(timestampWithSeconds, Word::TimestampWithSeconds, ColorScheme::getInstance().SystemMessageColor, QString(), QString())); -// words->append(*new Word(timestamp, Word::TimestampNoSeconds, copytext, tooltip)); -// words->append(*new Word(timestampWithSeconds, Word::TimestampWithSeconds, copytext, tooltip)); + // color + 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 m_userName = ircMessage.account(); @@ -65,24 +86,20 @@ Message::Message(const IrcPrivateMessage& ircMessage, const Channel& Channel) iterator = ircMessage.tags().find("display-name"); if (iterator == ircMessage.tags().end()) { - displayName = m_userName; + displayName = ircMessage.account(); } else { 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 #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 QString bits = ""; @@ -103,86 +120,40 @@ Message::Message(const IrcPrivateMessage& ircMessage, const Channel& Channel) { 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") { - QString a(""); - QString b("Twitch Staff"); - words->append(*new Word(badgeStaff, Word::BadgeStaff, a, b)); + words->append(Word(badgeStaff, Word::BadgeStaff, QString(), QString("Twitch Staff"))); + } + 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)); - } } + + } diff --git a/message.h b/message.h index b13e06645..edb01c9c9 100644 --- a/message.h +++ b/message.h @@ -21,13 +21,14 @@ public: // }; 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() { return m_highlightTab; } - QString timeoutUser() { + const QString& timeoutUser() { return m_timeoutUser; } @@ -35,11 +36,11 @@ public: return m_timeoutCount; } - QString userName() { + const QString& userName() { return m_userName; } - QString displayName() { + const QString& displayName() { return m_displayName; } @@ -51,6 +52,10 @@ public: return m_disabled; } + const QString& id() { + return m_id; + } + private: static LazyLoadedImage* badgeStaff; static LazyLoadedImage* badgeAdmin; @@ -68,6 +73,7 @@ private: QString m_userName = ""; QString m_displayName = ""; + QString m_id = ""; QList m_words; }; diff --git a/twitchemotevalue.h b/twitchemotevalue.h index 9c0027183..3607ceb3a 100644 --- a/twitchemotevalue.h +++ b/twitchemotevalue.h @@ -14,7 +14,7 @@ public: return m_id; } - QString channelName() { + const QString& channelName() { return m_channelName; } diff --git a/word.cpp b/word.cpp index 61ba2f1f1..58df10657 100644 --- a/word.cpp +++ b/word.cpp @@ -1,27 +1,27 @@ #include "word.h" // 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_text() , m_isImage(true) , m_type(type) , m_copyText(copytext) , m_tooltip(tooltip) + , m_color() + , m_link(link) { } // 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_text(text) , m_isImage(true) , m_type(type) , m_copyText(copytext) , m_tooltip(tooltip) -{ -} - -Word::~Word() + , m_color(color) + , m_link(link) { } diff --git a/word.h b/word.h index 3be719df0..5f23174d5 100644 --- a/word.h +++ b/word.h @@ -3,6 +3,7 @@ #include "lazyloadedimage.h" #include "fonts.h" +#include "link.h" #include #include @@ -38,13 +39,24 @@ public: BadgeBroadcaster = 0x80000, BadgePremium = 0x100000, 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(const QString& m_text, Type type, const QString& copytext, const QString& tooltip = ""); - - ~Word(); + 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 QColor& color, const QString& copytext, const QString& tooltip, const Link& link = Link()); LazyLoadedImage& getImage() { return *m_image; @@ -98,9 +110,18 @@ public: return m_tooltip; } + const QColor& color() { + return m_color; + } + + const Link& link() { + return m_link; + } + private: LazyLoadedImage* m_image; QString m_text; + QColor m_color; bool m_isImage; Type m_type; @@ -112,6 +133,7 @@ private: int m_height; bool m_hasTrailingSpace; Fonts::Type m_font = Fonts::Medium; + Link m_link; }; #endif // WORD_H