@@ -265,18 +265,50 @@ void TwitchMessageBuilder::parseUsername()
|
|||||||
this->userName = this->tags.value(QLatin1String("login")).toString();
|
this->userName = this->tags.value(QLatin1String("login")).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString displayName;
|
QString username = this->userName;
|
||||||
|
QString localizedName;
|
||||||
|
|
||||||
iterator = this->tags.find("display-name");
|
iterator = this->tags.find("display-name");
|
||||||
if (iterator == this->tags.end()) {
|
if (iterator != this->tags.end()) {
|
||||||
displayName = this->userName;
|
QString displayName = iterator.value().toString();
|
||||||
} else {
|
|
||||||
displayName = iterator.value().toString();
|
if (QString::compare(displayName, this->userName, Qt::CaseInsensitive) == 0) {
|
||||||
|
username = displayName;
|
||||||
|
} else {
|
||||||
|
localizedName = displayName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasLocalizedName = QString::compare(displayName, ircMessage->account()) == 0;
|
bool hasLocalizedName = !localizedName.isEmpty();
|
||||||
QString userDisplayString =
|
|
||||||
displayName + (hasLocalizedName ? (" (" + ircMessage->account() + ")") : QString());
|
// The full string that will be rendered in the chat widget
|
||||||
|
QString usernameString;
|
||||||
|
|
||||||
|
pajlada::Settings::Setting<int> usernameDisplayMode(
|
||||||
|
"/appearance/messages/usernameDisplayMode", UsernameDisplayMode::UsernameAndLocalizedName);
|
||||||
|
|
||||||
|
switch (usernameDisplayMode.getValue()) {
|
||||||
|
case UsernameDisplayMode::Username: {
|
||||||
|
usernameString = username;
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case UsernameDisplayMode::LocalizedName: {
|
||||||
|
if (hasLocalizedName) {
|
||||||
|
usernameString = localizedName;
|
||||||
|
} else {
|
||||||
|
usernameString = username;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case UsernameDisplayMode::UsernameAndLocalizedName: {
|
||||||
|
if (hasLocalizedName) {
|
||||||
|
usernameString = username + "(" + localizedName + ")";
|
||||||
|
} else {
|
||||||
|
usernameString = username;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
|
||||||
if (this->args.isSentWhisper) {
|
if (this->args.isSentWhisper) {
|
||||||
// TODO(pajlada): Re-implement
|
// TODO(pajlada): Re-implement
|
||||||
@@ -289,10 +321,10 @@ void TwitchMessageBuilder::parseUsername()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ircMessage->isAction()) {
|
if (!ircMessage->isAction()) {
|
||||||
userDisplayString += ": ";
|
usernameString += ": ";
|
||||||
}
|
}
|
||||||
|
|
||||||
this->appendWord(Word(userDisplayString, Word::Username, this->usernameColor, userDisplayString,
|
this->appendWord(Word(usernameString, Word::Username, this->usernameColor, usernameString,
|
||||||
QString(), Link(Link::UserInfo, this->userName)));
|
QString(), Link(Link::UserInfo, this->userName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ namespace twitch {
|
|||||||
class TwitchMessageBuilder : public messages::MessageBuilder
|
class TwitchMessageBuilder : public messages::MessageBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum UsernameDisplayMode : int {
|
||||||
|
Username = 1, // Username
|
||||||
|
LocalizedName = 2, // Localized name
|
||||||
|
UsernameAndLocalizedName = 3, // Username (Localized name)
|
||||||
|
};
|
||||||
|
|
||||||
TwitchMessageBuilder() = delete;
|
TwitchMessageBuilder() = delete;
|
||||||
|
|
||||||
explicit TwitchMessageBuilder(Channel *_channel, Resources &_resources,
|
explicit TwitchMessageBuilder(Channel *_channel, Resources &_resources,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "widgets/settingsdialog.hpp"
|
#include "widgets/settingsdialog.hpp"
|
||||||
#include "accountmanager.hpp"
|
#include "accountmanager.hpp"
|
||||||
|
#include "twitch/twitchmessagebuilder.hpp"
|
||||||
#include "twitch/twitchuser.hpp"
|
#include "twitch/twitchuser.hpp"
|
||||||
#include "widgets/settingsdialogtab.hpp"
|
#include "widgets/settingsdialogtab.hpp"
|
||||||
#include "windowmanager.hpp"
|
#include "windowmanager.hpp"
|
||||||
@@ -20,6 +21,9 @@ namespace widgets {
|
|||||||
|
|
||||||
SettingsDialog::SettingsDialog()
|
SettingsDialog::SettingsDialog()
|
||||||
: snapshot(SettingsManager::getInstance().createSnapshot())
|
: snapshot(SettingsManager::getInstance().createSnapshot())
|
||||||
|
, usernameDisplayMode(
|
||||||
|
"/appearance/messages/usernameDisplayMode",
|
||||||
|
twitch::TwitchMessageBuilder::UsernameDisplayMode::UsernameAndLocalizedName)
|
||||||
{
|
{
|
||||||
QFile file(":/qss/settings.qss");
|
QFile file(":/qss/settings.qss");
|
||||||
file.open(QFile::ReadOnly);
|
file.open(QFile::ReadOnly);
|
||||||
@@ -239,6 +243,19 @@ void SettingsDialog::addTabs()
|
|||||||
settings.allowDouplicateMessages));
|
settings.allowDouplicateMessages));
|
||||||
v->addWidget(createCheckbox("Seperate messages", settings.seperateMessages));
|
v->addWidget(createCheckbox("Seperate messages", settings.seperateMessages));
|
||||||
v->addWidget(createCheckbox("Show message length", settings.showMessageLength));
|
v->addWidget(createCheckbox("Show message length", settings.showMessageLength));
|
||||||
|
v->addLayout(this->createCombobox(
|
||||||
|
"Username display mode", this->usernameDisplayMode,
|
||||||
|
{"Username (Localized name)", "Username", "Localized name"},
|
||||||
|
[](const QString &newValue, pajlada::Settings::Setting<int> &setting) {
|
||||||
|
if (newValue == "Username (Localized name)") {
|
||||||
|
setting =
|
||||||
|
twitch::TwitchMessageBuilder::UsernameDisplayMode::UsernameAndLocalizedName;
|
||||||
|
} else if (newValue == "Username") {
|
||||||
|
setting = twitch::TwitchMessageBuilder::UsernameDisplayMode::Username;
|
||||||
|
} else if (newValue == "Localized name") {
|
||||||
|
setting = twitch::TwitchMessageBuilder::UsernameDisplayMode::LocalizedName;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
group->setLayout(v);
|
group->setLayout(v);
|
||||||
|
|
||||||
@@ -409,6 +426,26 @@ QCheckBox *SettingsDialog::createCheckbox(const QString &title,
|
|||||||
return checkbox;
|
return checkbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHBoxLayout *SettingsDialog::createCombobox(
|
||||||
|
const QString &title, pajlada::Settings::Setting<int> &setting, QStringList items,
|
||||||
|
std::function<void(QString, pajlada::Settings::Setting<int> &)> cb)
|
||||||
|
{
|
||||||
|
auto box = new QHBoxLayout();
|
||||||
|
auto label = new QLabel(title);
|
||||||
|
auto widget = new QComboBox();
|
||||||
|
widget->addItems(items);
|
||||||
|
|
||||||
|
QObject::connect(widget, &QComboBox::currentTextChanged, this,
|
||||||
|
[&setting, cb](const QString &newValue) {
|
||||||
|
cb(newValue, setting); //
|
||||||
|
});
|
||||||
|
|
||||||
|
box->addWidget(label);
|
||||||
|
box->addWidget(widget);
|
||||||
|
|
||||||
|
return box;
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsDialog::okButtonClicked()
|
void SettingsDialog::okButtonClicked()
|
||||||
{
|
{
|
||||||
this->close();
|
this->close();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
@@ -32,6 +33,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
SettingsSnapshot snapshot;
|
SettingsSnapshot snapshot;
|
||||||
|
|
||||||
|
pajlada::Settings::Setting<int> usernameDisplayMode;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
QVBoxLayout tabs;
|
QVBoxLayout tabs;
|
||||||
QVBoxLayout vbox;
|
QVBoxLayout vbox;
|
||||||
@@ -51,6 +54,9 @@ private:
|
|||||||
/// Widget creation helpers
|
/// Widget creation helpers
|
||||||
QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting);
|
QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting);
|
||||||
QCheckBox *createCheckbox(const QString &title, pajlada::Settings::Setting<bool> &setting);
|
QCheckBox *createCheckbox(const QString &title, pajlada::Settings::Setting<bool> &setting);
|
||||||
|
QHBoxLayout *createCombobox(const QString &title, pajlada::Settings::Setting<int> &setting,
|
||||||
|
QStringList items,
|
||||||
|
std::function<void(QString, pajlada::Settings::Setting<int> &)> cb);
|
||||||
|
|
||||||
void okButtonClicked();
|
void okButtonClicked();
|
||||||
void cancelButtonClicked();
|
void cancelButtonClicked();
|
||||||
|
|||||||
Reference in New Issue
Block a user