refactor: Remove most raw accesses into Application (#5104)

This commit is contained in:
pajlada
2024-01-19 17:59:55 +01:00
committed by GitHub
parent 326a402710
commit 4380ef8c5f
82 changed files with 552 additions and 452 deletions
+9 -7
View File
@@ -26,7 +26,8 @@ EditHotkeyDialog::EditHotkeyDialog(const std::shared_ptr<Hotkey> hotkey,
this->ui_->easyArgsPicker->setVisible(false);
this->ui_->easyArgsLabel->setVisible(false);
// dynamically add category names to the category picker
for (const auto &[_, hotkeyCategory] : getApp()->hotkeys->categories())
for (const auto &[_, hotkeyCategory] :
getIApp()->getHotkeys()->categories())
{
this->ui_->categoryPicker->addItem(hotkeyCategory.displayName,
hotkeyCategory.name);
@@ -153,7 +154,7 @@ void EditHotkeyDialog::afterEdit()
auto arguments =
parseHotkeyArguments(this->ui_->argumentsEdit->toPlainText());
auto category = getApp()->hotkeys->hotkeyCategoryFromName(
auto category = getIApp()->getHotkeys()->hotkeyCategoryFromName(
this->ui_->categoryPicker->currentData().toString());
if (!category)
{
@@ -165,7 +166,7 @@ void EditHotkeyDialog::afterEdit()
// check if another hotkey with this name exists, accounts for editing a hotkey
bool isEditing = bool(this->data_);
if (getApp()->hotkeys->getHotkeyByName(nameText))
if (getIApp()->getHotkeys()->getHotkeyByName(nameText))
{
// A hotkey with this name already exists
if (isEditing && this->data()->name() == nameText)
@@ -242,7 +243,8 @@ void EditHotkeyDialog::afterEdit()
{
if (keyComboWasEdited || nameWasEdited)
{
if (getApp()->hotkeys->isDuplicate(hotkey, this->data()->name()))
if (getIApp()->getHotkeys()->isDuplicate(hotkey,
this->data()->name()))
{
this->showEditError(
"Keybinding needs to be unique in the category.");
@@ -252,7 +254,7 @@ void EditHotkeyDialog::afterEdit()
}
else
{
if (getApp()->hotkeys->isDuplicate(hotkey, QString()))
if (getIApp()->getHotkeys()->isDuplicate(hotkey, QString()))
{
this->showEditError(
"Keybinding needs to be unique in the category.");
@@ -266,7 +268,7 @@ void EditHotkeyDialog::afterEdit()
void EditHotkeyDialog::updatePossibleActions()
{
const auto &hotkeys = getApp()->hotkeys;
const auto &hotkeys = getIApp()->getHotkeys();
auto category = hotkeys->hotkeyCategoryFromName(
this->ui_->categoryPicker->currentData().toString());
if (!category)
@@ -318,7 +320,7 @@ void EditHotkeyDialog::updateArgumentsInput()
this->ui_->argumentsEdit->setEnabled(true);
return;
}
const auto &hotkeys = getApp()->hotkeys;
const auto &hotkeys = getIApp()->getHotkeys();
auto category = hotkeys->hotkeyCategoryFromName(
this->ui_->categoryPicker->currentData().toString());
if (!category)
+15 -9
View File
@@ -206,7 +206,7 @@ EmotePopup::EmotePopup(QWidget *parent)
, notebook_(new Notebook(this))
{
// this->setStayInScreenRect(true);
this->moveTo(getApp()->windows->emotePopupPos(),
this->moveTo(getIApp()->getWindows()->emotePopupPos(),
widgets::BoundsChecking::DesiredPosition);
auto *layout = new QVBoxLayout();
@@ -273,7 +273,7 @@ EmotePopup::EmotePopup(QWidget *parent)
loadEmojis(*this->viewEmojis_,
getApp()->getEmotes()->getEmojis()->getEmojis());
this->addShortcuts();
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated,
[this]() {
this->clearShortcuts();
this->addShortcuts();
@@ -371,7 +371,7 @@ void EmotePopup::addShortcuts()
}},
};
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory(
HotkeyCategory::PopupWindow, actions, this);
}
@@ -394,9 +394,12 @@ void EmotePopup::loadChannel(ChannelPtr channel)
auto channelChannel = std::make_shared<Channel>("", Channel::Type::None);
// twitch
addTwitchEmoteSets(
getApp()->accounts->twitch.getCurrent()->accessEmotes()->emoteSets,
*globalChannel, *subChannel, this->channel_->getName());
addTwitchEmoteSets(getIApp()
->getAccounts()
->twitch.getCurrent()
->accessEmotes()
->emoteSets,
*globalChannel, *subChannel, this->channel_->getName());
// global
if (Settings::instance().enableBTTVGlobalEmotes)
@@ -467,8 +470,11 @@ bool EmotePopup::eventFilter(QObject *object, QEvent *event)
void EmotePopup::filterTwitchEmotes(std::shared_ptr<Channel> searchChannel,
const QString &searchText)
{
auto twitchEmoteSets =
getApp()->accounts->twitch.getCurrent()->accessEmotes()->emoteSets;
auto twitchEmoteSets = getIApp()
->getAccounts()
->twitch.getCurrent()
->accessEmotes()
->emoteSets;
std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> twitchGlobalEmotes{};
for (const auto &set : twitchEmoteSets)
@@ -589,7 +595,7 @@ void EmotePopup::filterEmotes(const QString &searchText)
void EmotePopup::closeEvent(QCloseEvent *event)
{
getApp()->windows->setEmotePopupPos(this->pos());
getIApp()->getWindows()->setEmotePopupPos(this->pos());
BaseWindow::closeEvent(event);
}
+2 -2
View File
@@ -66,8 +66,8 @@ namespace {
pajlada::Settings::Setting<QString>::set(basePath + "/oauthToken",
oauthToken);
getApp()->accounts->twitch.reloadUsers();
getApp()->accounts->twitch.currentUsername = username;
getIApp()->getAccounts()->twitch.reloadUsers();
getIApp()->getAccounts()->twitch.currentUsername = username;
return true;
}
+1 -1
View File
@@ -14,7 +14,7 @@ QualityPopup::QualityPopup(const QString &channelURL, QStringList options)
BaseWindow::DisableLayoutSave,
BaseWindow::BoundsCheckOnShow,
},
static_cast<QWidget *>(&(getApp()->windows->getMainWindow())))
static_cast<QWidget *>(&(getIApp()->getWindows()->getMainWindow())))
, channelURL_(channelURL)
{
this->ui_.selector = new QComboBox(this);
+8 -6
View File
@@ -77,7 +77,7 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, Split *split)
{"search", nullptr},
};
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory(
HotkeyCategory::PopupWindow, actions, this);
// initialize UI
@@ -98,7 +98,7 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, Split *split)
new SplitInput(this, this->split_, this->ui_.threadView, false);
this->bSignals_.emplace_back(
getApp()->accounts->twitch.currentUserChanged.connect([this] {
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
this->updateInputUI();
}));
@@ -284,7 +284,7 @@ void ReplyThreadPopup::updateInputUI()
this->ui_.replyInput->setVisible(channel->isWritable());
auto user = getApp()->accounts->twitch.getCurrent();
auto user = getIApp()->getAccounts()->twitch.getCurrent();
QString placeholderText;
if (user->isAnon())
@@ -293,9 +293,11 @@ void ReplyThreadPopup::updateInputUI()
}
else
{
placeholderText =
QStringLiteral("Reply as %1...")
.arg(getApp()->accounts->twitch.getCurrent()->getUserName());
placeholderText = QStringLiteral("Reply as %1...")
.arg(getIApp()
->getAccounts()
->twitch.getCurrent()
->getUserName());
}
this->ui_.replyInput->setPlaceholderText(placeholderText);
+1 -1
View File
@@ -615,7 +615,7 @@ void SelectChannelDialog::addShortcuts()
actions.emplace("openTab", nullptr);
}
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory(
HotkeyCategory::PopupWindow, actions, this);
}
+4 -4
View File
@@ -54,7 +54,7 @@ SettingsDialog::SettingsDialog(QWidget *parent)
this->overrideBackgroundColor_ = QColor("#111111");
this->addShortcuts();
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated,
[this]() {
this->clearShortcuts();
this->addShortcuts();
@@ -78,13 +78,13 @@ void SettingsDialog::addShortcuts()
{"openTab", nullptr},
};
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory(
HotkeyCategory::PopupWindow, actions, this);
}
void SettingsDialog::setSearchPlaceholderText()
{
QString searchHotkey;
auto searchSeq = getApp()->hotkeys->getDisplaySequence(
auto searchSeq = getIApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::PopupWindow, "search");
if (!searchSeq.isEmpty())
{
@@ -432,7 +432,7 @@ void SettingsDialog::onOkClicked()
{
if (!getApp()->getArgs().dontSaveSettings)
{
getApp()->commands->save();
getIApp()->getCommands()->save();
pajlada::Settings::SettingManager::gSave();
}
this->close();
+22 -19
View File
@@ -56,7 +56,7 @@ namespace {
{
button.assign(copyButton);
}
button->setPixmap(getApp()->themes->buttons.copy);
button->setPixmap(getIApp()->getThemes()->buttons.copy);
button->setScaleIndependantSize(18, 18);
button->setDim(Button::Dim::Lots);
button->setToolTip(tooltip);
@@ -226,7 +226,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
.arg(calculateTimeoutDuration(button));
}
msg = getApp()->commands->execCommand(
msg = getIApp()->getCommands()->execCommand(
msg, this->underlyingChannel_, false);
this->underlyingChannel_->sendMessage(msg);
@@ -245,7 +245,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
{"search", nullptr},
};
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory(
HotkeyCategory::PopupWindow, actions, this);
auto layers = LayoutCreator<QWidget>(this->getLayoutContainer())
@@ -299,7 +299,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
"Open channel in a new popup window", this,
[loginName] {
auto *app = getApp();
auto &window = app->windows->createWindow(
auto &window = app->getWindows()->createWindow(
WindowType::Popup, true);
auto *split = window.getNotebook()
.getOrAddSelectedPage()
@@ -314,7 +314,8 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
getApp()->twitch->getOrAddChannel(
loginName);
auto &nb = getApp()
->windows->getMainWindow()
->getWindows()
->getMainWindow()
.getNotebook();
SplitContainer *container = nb.addPage(true);
Split *split = new Split(container);
@@ -414,25 +415,25 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
QObject::connect(mod.getElement(), &Button::leftClicked, [this] {
QString value = "/mod " + this->userName_;
value = getApp()->commands->execCommand(
value = getIApp()->getCommands()->execCommand(
value, this->underlyingChannel_, false);
this->underlyingChannel_->sendMessage(value);
});
QObject::connect(unmod.getElement(), &Button::leftClicked, [this] {
QString value = "/unmod " + this->userName_;
value = getApp()->commands->execCommand(
value = getIApp()->getCommands()->execCommand(
value, this->underlyingChannel_, false);
this->underlyingChannel_->sendMessage(value);
});
QObject::connect(vip.getElement(), &Button::leftClicked, [this] {
QString value = "/vip " + this->userName_;
value = getApp()->commands->execCommand(
value = getIApp()->getCommands()->execCommand(
value, this->underlyingChannel_, false);
this->underlyingChannel_->sendMessage(value);
});
QObject::connect(unvip.getElement(), &Button::leftClicked, [this] {
QString value = "/unvip " + this->userName_;
value = getApp()->commands->execCommand(
value = getIApp()->getCommands()->execCommand(
value, this->underlyingChannel_, false);
this->underlyingChannel_->sendMessage(value);
});
@@ -450,9 +451,11 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
if (twitchChannel)
{
bool isMyself =
QString::compare(
getApp()->accounts->twitch.getCurrent()->getUserName(),
this->userName_, Qt::CaseInsensitive) == 0;
QString::compare(getIApp()
->getAccounts()
->twitch.getCurrent()
->getUserName(),
this->userName_, Qt::CaseInsensitive) == 0;
visibilityModButtons =
twitchChannel->isBroadcaster() && !isMyself;
@@ -497,7 +500,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
if (this->underlyingChannel_)
{
QString value = "/ban " + this->userName_;
value = getApp()->commands->execCommand(
value = getIApp()->getCommands()->execCommand(
value, this->underlyingChannel_, false);
this->underlyingChannel_->sendMessage(value);
@@ -508,7 +511,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
if (this->underlyingChannel_)
{
QString value = "/unban " + this->userName_;
value = getApp()->commands->execCommand(
value = getIApp()->getCommands()->execCommand(
value, this->underlyingChannel_, false);
this->underlyingChannel_->sendMessage(value);
@@ -521,7 +524,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
QString value = "/timeout " + this->userName_ + " " +
QString::number(arg);
value = getApp()->commands->execCommand(
value = getIApp()->getCommands()->execCommand(
value, this->underlyingChannel_, false);
this->underlyingChannel_->sendMessage(value);
@@ -594,7 +597,7 @@ void UserInfoPopup::installEvents()
QObject::connect(
this->ui_.block, &QCheckBox::stateChanged,
[this](int newState) mutable {
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
const auto reenableBlockCheckbox = [this] {
this->ui_.block->setEnabled(true);
@@ -611,7 +614,7 @@ void UserInfoPopup::installEvents()
case Qt::CheckState::Unchecked: {
this->ui_.block->setEnabled(false);
getApp()->accounts->twitch.getCurrent()->unblockUser(
getIApp()->getAccounts()->twitch.getCurrent()->unblockUser(
this->userId_, this,
[this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage(
@@ -638,7 +641,7 @@ void UserInfoPopup::installEvents()
case Qt::CheckState::Checked: {
this->ui_.block->setEnabled(false);
getApp()->accounts->twitch.getCurrent()->blockUser(
getIApp()->getAccounts()->twitch.getCurrent()->blockUser(
this->userId_, this,
[this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage(
@@ -795,7 +798,7 @@ void UserInfoPopup::updateLatestMessages()
void UserInfoPopup::updateUserData()
{
std::weak_ptr<bool> hack = this->lifetimeHack_;
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
const auto onUserFetchFailed = [this, hack] {
if (!hack.lock())
@@ -21,9 +21,8 @@ NewPopupItem::NewPopupItem(const QString &channelName)
void NewPopupItem::action()
{
auto *app = getApp();
auto channel = app->twitch->getOrAddChannel(this->channelName_);
app->windows->openInPopup(channel);
auto channel = getApp()->twitch->getOrAddChannel(this->channelName_);
getIApp()->getWindows()->openInPopup(channel);
}
void NewPopupItem::paint(QPainter *painter, const QRect &rect) const
@@ -32,9 +31,10 @@ void NewPopupItem::paint(QPainter *painter, const QRect &rect) const
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(getApp()->themes->splits.header.text);
painter->setPen(getIApp()->getThemes()->splits.header.text);
painter->setBrush(Qt::SolidPattern);
painter->setFont(getApp()->fonts->getFont(FontStyle::UiMediumBold, 1.0));
painter->setFont(
getIApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0));
QRect iconRect(rect.topLeft(), ICON_SIZE);
this->icon_.paint(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter);
+3 -2
View File
@@ -37,9 +37,10 @@ void NewTabItem::paint(QPainter *painter, const QRect &rect) const
painter->setRenderHint(QPainter::Antialiasing, true);
// TODO(leon): Right pen/brush/font settings?
painter->setPen(getApp()->themes->splits.header.text);
painter->setPen(getIApp()->getThemes()->splits.header.text);
painter->setBrush(Qt::SolidPattern);
painter->setFont(getApp()->fonts->getFont(FontStyle::UiMediumBold, 1.0));
painter->setFont(
getIApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0));
QRect iconRect(rect.topLeft(), ICON_SIZE);
this->icon_.paint(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter);
@@ -21,11 +21,11 @@ void SwitchSplitItem::action()
{
if (this->split_)
{
getApp()->windows->select(this->split_);
getIApp()->getWindows()->select(this->split_);
}
else if (this->container_)
{
getApp()->windows->select(this->container_);
getIApp()->getWindows()->select(this->container_);
}
}
@@ -36,9 +36,10 @@ void SwitchSplitItem::paint(QPainter *painter, const QRect &rect) const
painter->setRenderHint(QPainter::Antialiasing, true);
// TODO(leon): Right pen/brush/font settings?
painter->setPen(getApp()->themes->splits.header.text);
painter->setPen(getIApp()->getThemes()->splits.header.text);
painter->setBrush(Qt::SolidPattern);
painter->setFont(getApp()->fonts->getFont(FontStyle::UiMediumBold, 1.0));
painter->setFont(
getIApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0));
QRect iconRect(rect.topLeft(), ICON_SIZE);
this->icon_.paint(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter);
@@ -58,7 +59,8 @@ void SwitchSplitItem::paint(QPainter *painter, const QRect &rect) const
QRect(leftTextRect.topRight(),
QSize(0.7 * availableTextWidth, iconRect.height()));
painter->setFont(getApp()->fonts->getFont(FontStyle::UiMedium, 1.0));
painter->setFont(
getIApp()->getFonts()->getFont(FontStyle::UiMedium, 1.0));
painter->drawText(rightTextRect, Qt::AlignRight | Qt::AlignVCenter,
this->container_->getTab()->getTitle());
}