refactor: Remove most raw accesses into Application (#5104)
This commit is contained in:
@@ -241,7 +241,7 @@ Split::Split(QWidget *parent)
|
||||
|
||||
// update placeholder text on Twitch account change and channel change
|
||||
this->bSignals_.emplace_back(
|
||||
getApp()->accounts->twitch.currentUserChanged.connect([this] {
|
||||
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
|
||||
this->updateInputPlaceholder();
|
||||
}));
|
||||
this->signalHolder_.managedConnect(channelChanged, [this] {
|
||||
@@ -427,7 +427,8 @@ Split::Split(QWidget *parent)
|
||||
}
|
||||
}
|
||||
QPointer<ResizingTextEdit> edit = this->input_->ui_.textEdit;
|
||||
getApp()->imageUploader->upload(source, this->getChannel(), edit);
|
||||
getIApp()->getImageUploader()->upload(source, this->getChannel(),
|
||||
edit);
|
||||
});
|
||||
|
||||
getSettings()->imageUploaderEnabled.connect(
|
||||
@@ -436,7 +437,7 @@ Split::Split(QWidget *parent)
|
||||
},
|
||||
this->signalHolder_);
|
||||
this->addShortcuts();
|
||||
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
|
||||
this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated,
|
||||
[this]() {
|
||||
this->clearShortcuts();
|
||||
this->addShortcuts();
|
||||
@@ -689,7 +690,7 @@ void Split::addShortcuts()
|
||||
<< "runCommand hotkey called without arguments!";
|
||||
return "runCommand hotkey called without arguments!";
|
||||
}
|
||||
QString command = getApp()->commands->execCommand(
|
||||
QString command = getIApp()->getCommands()->execCommand(
|
||||
arguments.at(0).replace('\n', ' '), this->getChannel(), false);
|
||||
this->getChannel()->sendMessage(command);
|
||||
return "";
|
||||
@@ -724,24 +725,24 @@ void Split::addShortcuts()
|
||||
|
||||
if (mode == 0)
|
||||
{
|
||||
getApp()->notifications->removeChannelNotification(
|
||||
getIApp()->getNotifications()->removeChannelNotification(
|
||||
this->getChannel()->getName(), Platform::Twitch);
|
||||
}
|
||||
else if (mode == 1)
|
||||
{
|
||||
getApp()->notifications->addChannelNotification(
|
||||
getIApp()->getNotifications()->addChannelNotification(
|
||||
this->getChannel()->getName(), Platform::Twitch);
|
||||
}
|
||||
else
|
||||
{
|
||||
getApp()->notifications->updateChannelNotification(
|
||||
getIApp()->getNotifications()->updateChannelNotification(
|
||||
this->getChannel()->getName(), Platform::Twitch);
|
||||
}
|
||||
return "";
|
||||
}},
|
||||
};
|
||||
|
||||
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
||||
this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory(
|
||||
HotkeyCategory::Split, actions, this);
|
||||
}
|
||||
|
||||
@@ -770,7 +771,7 @@ void Split::updateInputPlaceholder()
|
||||
return;
|
||||
}
|
||||
|
||||
auto user = getApp()->accounts->twitch.getCurrent();
|
||||
auto user = getIApp()->getAccounts()->twitch.getCurrent();
|
||||
QString placeholderText;
|
||||
|
||||
if (user->isAnon())
|
||||
@@ -779,9 +780,11 @@ void Split::updateInputPlaceholder()
|
||||
}
|
||||
else
|
||||
{
|
||||
placeholderText =
|
||||
QString("Send message as %1...")
|
||||
.arg(getApp()->accounts->twitch.getCurrent()->getUserName());
|
||||
placeholderText = QString("Send message as %1...")
|
||||
.arg(getIApp()
|
||||
->getAccounts()
|
||||
->twitch.getCurrent()
|
||||
->getUserName());
|
||||
}
|
||||
|
||||
this->input_->ui_.textEdit->setPlaceholderText(placeholderText);
|
||||
@@ -789,7 +792,7 @@ void Split::updateInputPlaceholder()
|
||||
|
||||
void Split::joinChannelInNewTab(ChannelPtr channel)
|
||||
{
|
||||
auto &nb = getApp()->windows->getMainWindow().getNotebook();
|
||||
auto &nb = getIApp()->getWindows()->getMainWindow().getNotebook();
|
||||
SplitContainer *container = nb.addPage(true);
|
||||
|
||||
Split *split = new Split(container);
|
||||
@@ -889,7 +892,7 @@ void Split::setChannel(IndirectChannel newChannel)
|
||||
this->actionRequested.invoke(Action::RefreshTab);
|
||||
|
||||
// Queue up save because: Split channel changed
|
||||
getApp()->windows->queueSave();
|
||||
getIApp()->getWindows()->queueSave();
|
||||
}
|
||||
|
||||
void Split::setModerationMode(bool value)
|
||||
@@ -983,7 +986,7 @@ void Split::keyReleaseEvent(QKeyEvent *event)
|
||||
void Split::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
// Queue up save because: Split resized
|
||||
getApp()->windows->queueSave();
|
||||
getIApp()->getWindows()->queueSave();
|
||||
|
||||
BaseWidget::resizeEvent(event);
|
||||
|
||||
@@ -1073,7 +1076,7 @@ void Split::explainSplitting()
|
||||
void Split::popup()
|
||||
{
|
||||
auto *app = getApp();
|
||||
Window &window = app->windows->createWindow(WindowType::Popup);
|
||||
Window &window = app->getWindows()->createWindow(WindowType::Popup);
|
||||
|
||||
Split *split = new Split(static_cast<SplitContainer *>(
|
||||
window.getNotebook().getOrAddSelectedPage()));
|
||||
@@ -1104,7 +1107,8 @@ void Split::openInBrowser()
|
||||
|
||||
void Split::openWhispersInBrowser()
|
||||
{
|
||||
auto userName = getApp()->accounts->twitch.getCurrent()->getUserName();
|
||||
auto userName =
|
||||
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
|
||||
QDesktopServices::openUrl("https://twitch.tv/popout/moderator/" + userName +
|
||||
"/whispers");
|
||||
}
|
||||
@@ -1191,7 +1195,8 @@ void Split::showChatterList()
|
||||
auto formatListItemText = [](QString text) {
|
||||
auto *item = new QListWidgetItem();
|
||||
item->setText(text);
|
||||
item->setFont(getApp()->fonts->getFont(FontStyle::ChatMedium, 1.0));
|
||||
item->setFont(
|
||||
getIApp()->getFonts()->getFont(FontStyle::ChatMedium, 1.0));
|
||||
return item;
|
||||
};
|
||||
|
||||
@@ -1241,7 +1246,7 @@ void Split::showChatterList()
|
||||
auto loadChatters = [=](auto modList, auto vipList, bool isBroadcaster) {
|
||||
getHelix()->getChatters(
|
||||
twitchChannel->roomId(),
|
||||
getApp()->accounts->twitch.getCurrent()->getUserId(), 50000,
|
||||
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 50000,
|
||||
[=](auto chatters) {
|
||||
auto broadcaster = channel->getName().toLower();
|
||||
QStringList chatterList;
|
||||
@@ -1406,8 +1411,8 @@ void Split::showChatterList()
|
||||
}},
|
||||
};
|
||||
|
||||
getApp()->hotkeys->shortcutsForCategory(HotkeyCategory::PopupWindow,
|
||||
actions, chatterDock);
|
||||
getIApp()->getHotkeys()->shortcutsForCategory(HotkeyCategory::PopupWindow,
|
||||
actions, chatterDock);
|
||||
|
||||
dockVbox->addWidget(searchBar);
|
||||
dockVbox->addWidget(loadingLabel);
|
||||
@@ -1470,7 +1475,7 @@ void Split::showSearch(bool singleChannel)
|
||||
}
|
||||
|
||||
// Pass every ChannelView for every Split across the app to the search popup
|
||||
auto ¬ebook = getApp()->windows->getMainWindow().getNotebook();
|
||||
auto ¬ebook = getIApp()->getWindows()->getMainWindow().getNotebook();
|
||||
for (int i = 0; i < notebook.getPageCount(); ++i)
|
||||
{
|
||||
auto *container = dynamic_cast<SplitContainer *>(notebook.getPageAt(i));
|
||||
@@ -1489,7 +1494,7 @@ void Split::showSearch(bool singleChannel)
|
||||
void Split::reloadChannelAndSubscriberEmotes()
|
||||
{
|
||||
auto channel = this->getChannel();
|
||||
getApp()->accounts->twitch.getCurrent()->loadEmotes(channel);
|
||||
getIApp()->getAccounts()->twitch.getCurrent()->loadEmotes(channel);
|
||||
|
||||
if (auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
|
||||
{
|
||||
|
||||
@@ -131,7 +131,7 @@ Split *SplitContainer::appendNewSplit(bool openChannelNameDialog)
|
||||
void SplitContainer::insertSplit(Split *split, InsertOptions &&options)
|
||||
{
|
||||
// Queue up save because: Split added
|
||||
getApp()->windows->queueSave();
|
||||
getIApp()->getWindows()->queueSave();
|
||||
|
||||
assertInGuiThread();
|
||||
|
||||
@@ -345,7 +345,7 @@ SplitContainer::Position SplitContainer::releaseSplit(Split *split)
|
||||
SplitContainer::Position SplitContainer::deleteSplit(Split *split)
|
||||
{
|
||||
// Queue up save because: Split removed
|
||||
getApp()->windows->queueSave();
|
||||
getIApp()->getWindows()->queueSave();
|
||||
|
||||
assertInGuiThread();
|
||||
assert(split != nullptr);
|
||||
@@ -614,8 +614,8 @@ void SplitContainer::paintEvent(QPaintEvent * /*event*/)
|
||||
|
||||
painter.setPen(this->theme->splits.header.text);
|
||||
|
||||
const auto font =
|
||||
getApp()->fonts->getFont(FontStyle::ChatMedium, this->scale());
|
||||
const auto font = getIApp()->getFonts()->getFont(FontStyle::ChatMedium,
|
||||
this->scale());
|
||||
painter.setFont(font);
|
||||
|
||||
QString text = "Click to add a split";
|
||||
@@ -634,7 +634,7 @@ void SplitContainer::paintEvent(QPaintEvent * /*event*/)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getApp()->themes->isLightTheme())
|
||||
if (getIApp()->getThemes()->isLightTheme())
|
||||
{
|
||||
painter.fillRect(rect(), QColor("#999"));
|
||||
}
|
||||
@@ -646,8 +646,8 @@ void SplitContainer::paintEvent(QPaintEvent * /*event*/)
|
||||
|
||||
for (DropRect &dropRect : this->dropRects_)
|
||||
{
|
||||
QColor border = getApp()->themes->splits.dropTargetRectBorder;
|
||||
QColor background = getApp()->themes->splits.dropTargetRect;
|
||||
QColor border = getIApp()->getThemes()->splits.dropTargetRectBorder;
|
||||
QColor background = getIApp()->getThemes()->splits.dropTargetRect;
|
||||
|
||||
if (!dropRect.rect.contains(this->mouseOverPoint_))
|
||||
{
|
||||
@@ -774,7 +774,7 @@ void SplitContainer::applyFromDescriptor(const NodeDescriptor &rootNode)
|
||||
|
||||
void SplitContainer::popup()
|
||||
{
|
||||
Window &window = getApp()->windows->createWindow(WindowType::Popup);
|
||||
Window &window = getIApp()->getWindows()->createWindow(WindowType::Popup);
|
||||
auto *popupContainer = window.getNotebook().getOrAddSelectedPage();
|
||||
|
||||
QJsonObject encodedTab;
|
||||
@@ -1436,15 +1436,15 @@ void SplitContainer::DropOverlay::paintEvent(QPaintEvent * /*event*/)
|
||||
{
|
||||
if (!foundMover && rect.rect.contains(this->mouseOverPoint_))
|
||||
{
|
||||
painter.setBrush(getApp()->themes->splits.dropPreview);
|
||||
painter.setPen(getApp()->themes->splits.dropPreviewBorder);
|
||||
painter.setBrush(getIApp()->getThemes()->splits.dropPreview);
|
||||
painter.setPen(getIApp()->getThemes()->splits.dropPreviewBorder);
|
||||
foundMover = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.setBrush(QColor(0, 0, 0, 0));
|
||||
painter.setPen(QColor(0, 0, 0, 0));
|
||||
// painter.setPen(getApp()->themes->splits.dropPreviewBorder);
|
||||
// painter.setPen(getIApp()->getThemes()->splits.dropPreviewBorder);
|
||||
}
|
||||
|
||||
painter.drawRect(rect.rect);
|
||||
@@ -1526,10 +1526,10 @@ SplitContainer::ResizeHandle::ResizeHandle(SplitContainer *_parent)
|
||||
void SplitContainer::ResizeHandle::paintEvent(QPaintEvent * /*event*/)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setPen(QPen(getApp()->themes->splits.resizeHandle, 2));
|
||||
painter.setPen(QPen(getIApp()->getThemes()->splits.resizeHandle, 2));
|
||||
|
||||
painter.fillRect(this->rect(),
|
||||
getApp()->themes->splits.resizeHandleBackground);
|
||||
getIApp()->getThemes()->splits.resizeHandleBackground);
|
||||
|
||||
if (this->vertical_)
|
||||
{
|
||||
|
||||
@@ -246,7 +246,7 @@ SplitHeader::SplitHeader(Split *split)
|
||||
});
|
||||
|
||||
this->bSignals_.emplace_back(
|
||||
getApp()->accounts->twitch.currentUserChanged.connect([this] {
|
||||
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
|
||||
this->updateModerationModeIcon();
|
||||
}));
|
||||
|
||||
@@ -295,7 +295,7 @@ void SplitHeader::initializeLayout()
|
||||
case Qt::LeftButton:
|
||||
if (getSettings()->moderationActions.empty())
|
||||
{
|
||||
getApp()->windows->showSettingsDialog(
|
||||
getIApp()->getWindows()->showSettingsDialog(
|
||||
this, SettingsDialogPreference::
|
||||
ModerationActions);
|
||||
this->split_->setModerationMode(true);
|
||||
@@ -313,7 +313,7 @@ void SplitHeader::initializeLayout()
|
||||
|
||||
case Qt::RightButton:
|
||||
case Qt::MiddleButton:
|
||||
getApp()->windows->showSettingsDialog(
|
||||
getIApp()->getWindows()->showSettingsDialog(
|
||||
this,
|
||||
SettingsDialogPreference::ModerationActions);
|
||||
break;
|
||||
@@ -363,7 +363,7 @@ void SplitHeader::initializeLayout()
|
||||
std::unique_ptr<QMenu> SplitHeader::createMainMenu()
|
||||
{
|
||||
// top level menu
|
||||
const auto &h = getApp()->hotkeys;
|
||||
const auto &h = getIApp()->getHotkeys();
|
||||
auto menu = std::make_unique<QMenu>();
|
||||
menu->addAction(
|
||||
"Change channel", this->split_, &Split::changeChannel,
|
||||
@@ -533,11 +533,11 @@ std::unique_ptr<QMenu> SplitHeader::createMainMenu()
|
||||
action->setShortcut(notifySeq);
|
||||
|
||||
QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action, this]() {
|
||||
action->setChecked(getApp()->notifications->isChannelNotified(
|
||||
action->setChecked(getIApp()->getNotifications()->isChannelNotified(
|
||||
this->split_->getChannel()->getName(), Platform::Twitch));
|
||||
});
|
||||
QObject::connect(action, &QAction::triggered, this, [this]() {
|
||||
getApp()->notifications->updateChannelNotification(
|
||||
getIApp()->getNotifications()->updateChannelNotification(
|
||||
this->split_->getChannel()->getName(), Platform::Twitch);
|
||||
});
|
||||
|
||||
@@ -1034,7 +1034,7 @@ void SplitHeader::reloadSubscriberEmotes()
|
||||
this->lastReloadedSubEmotes_ = now;
|
||||
|
||||
auto channel = this->split_->getChannel();
|
||||
getApp()->accounts->twitch.getCurrent()->loadEmotes(channel);
|
||||
getIApp()->getAccounts()->twitch.getCurrent()->loadEmotes(channel);
|
||||
}
|
||||
|
||||
void SplitHeader::reconnect()
|
||||
|
||||
@@ -69,7 +69,7 @@ SplitInput::SplitInput(QWidget *parent, Split *_chatWidget,
|
||||
this->hideCompletionPopup();
|
||||
});
|
||||
this->scaleChangedEvent(this->scale());
|
||||
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
|
||||
this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated,
|
||||
[this]() {
|
||||
this->clearShortcuts();
|
||||
this->addShortcuts();
|
||||
@@ -96,7 +96,7 @@ void SplitInput::initLayout()
|
||||
auto replyLabel = replyHbox.emplace<QLabel>().assign(&this->ui_.replyLabel);
|
||||
replyLabel->setAlignment(Qt::AlignLeft);
|
||||
replyLabel->setFont(
|
||||
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
|
||||
app->getFonts()->getFont(FontStyle::ChatMedium, this->scale()));
|
||||
|
||||
replyHbox->addStretch(1);
|
||||
|
||||
@@ -157,18 +157,18 @@ void SplitInput::initLayout()
|
||||
|
||||
// set edit font
|
||||
this->ui_.textEdit->setFont(
|
||||
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
|
||||
app->getFonts()->getFont(FontStyle::ChatMedium, this->scale()));
|
||||
QObject::connect(this->ui_.textEdit, &QTextEdit::cursorPositionChanged,
|
||||
this, &SplitInput::onCursorPositionChanged);
|
||||
QObject::connect(this->ui_.textEdit, &QTextEdit::textChanged, this,
|
||||
&SplitInput::onTextChanged);
|
||||
|
||||
this->managedConnections_.managedConnect(
|
||||
app->fonts->fontChanged, [=, this]() {
|
||||
app->getFonts()->fontChanged, [=, this]() {
|
||||
this->ui_.textEdit->setFont(
|
||||
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
|
||||
this->ui_.replyLabel->setFont(
|
||||
app->fonts->getFont(FontStyle::ChatMediumBold, this->scale()));
|
||||
app->getFonts()->getFont(FontStyle::ChatMedium, this->scale()));
|
||||
this->ui_.replyLabel->setFont(app->getFonts()->getFont(
|
||||
FontStyle::ChatMediumBold, this->scale()));
|
||||
});
|
||||
|
||||
// open emote popup
|
||||
@@ -213,11 +213,11 @@ void SplitInput::scaleChangedEvent(float scale)
|
||||
this->setMaximumHeight(this->scaledMaxHeight());
|
||||
}
|
||||
this->ui_.textEdit->setFont(
|
||||
app->fonts->getFont(FontStyle::ChatMedium, scale));
|
||||
app->getFonts()->getFont(FontStyle::ChatMedium, scale));
|
||||
this->ui_.textEditLength->setFont(
|
||||
app->fonts->getFont(FontStyle::ChatMedium, scale));
|
||||
app->getFonts()->getFont(FontStyle::ChatMedium, scale));
|
||||
this->ui_.replyLabel->setFont(
|
||||
app->fonts->getFont(FontStyle::ChatMediumBold, scale));
|
||||
app->getFonts()->getFont(FontStyle::ChatMediumBold, scale));
|
||||
}
|
||||
|
||||
void SplitInput::themeChangedEvent()
|
||||
@@ -332,7 +332,7 @@ QString SplitInput::handleSendMessage(const std::vector<QString> &arguments)
|
||||
|
||||
message = message.replace('\n', ' ');
|
||||
QString sendMessage =
|
||||
getApp()->commands->execCommand(message, c, false);
|
||||
getIApp()->getCommands()->execCommand(message, c, false);
|
||||
|
||||
c->sendMessage(sendMessage);
|
||||
|
||||
@@ -363,7 +363,8 @@ QString SplitInput::handleSendMessage(const std::vector<QString> &arguments)
|
||||
}
|
||||
|
||||
message = message.replace('\n', ' ');
|
||||
QString sendMessage = getApp()->commands->execCommand(message, c, false);
|
||||
QString sendMessage =
|
||||
getIApp()->getCommands()->execCommand(message, c, false);
|
||||
|
||||
// Reply within TwitchChannel
|
||||
tc->sendReply(sendMessage, this->replyThread_->id);
|
||||
@@ -640,7 +641,7 @@ void SplitInput::addShortcuts()
|
||||
}},
|
||||
};
|
||||
|
||||
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
||||
this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory(
|
||||
HotkeyCategory::SplitInput, actions, this->parentWidget());
|
||||
}
|
||||
|
||||
@@ -947,8 +948,8 @@ void SplitInput::editTextChanged()
|
||||
this->textChanged.invoke(text);
|
||||
|
||||
text = text.trimmed();
|
||||
text =
|
||||
app->commands->execCommand(text, this->split_->getChannel(), true);
|
||||
text = app->getCommands()->execCommand(text, this->split_->getChannel(),
|
||||
true);
|
||||
}
|
||||
|
||||
if (text.length() > 0 &&
|
||||
|
||||
@@ -268,8 +268,8 @@ void SplitOverlay::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
rect.setRight(rect.right() - 1);
|
||||
rect.setBottom(rect.bottom() - 1);
|
||||
painter.setPen(getApp()->themes->splits.dropPreviewBorder);
|
||||
painter.setBrush(getApp()->themes->splits.dropPreview);
|
||||
painter.setPen(getIApp()->getThemes()->splits.dropPreviewBorder);
|
||||
painter.setBrush(getIApp()->getThemes()->splits.dropPreview);
|
||||
painter.drawRect(rect);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user