chore: remove Singleton & replace getIApp with getApp (#5514)

This commit is contained in:
pajlada
2024-07-21 15:09:59 +02:00
committed by GitHub
parent 21186df058
commit 5deec1f02f
145 changed files with 802 additions and 856 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ AccountsPage::AccountsPage()
// return;
// }
// getIApp()->getAccounts()->Twitch.removeUser(selectedUser);
// getApp()->getAccounts()->Twitch.removeUser(selectedUser);
// });
}
+3 -3
View File
@@ -87,7 +87,7 @@ CommandPage::CommandPage()
auto *view = layout
.emplace<EditableModelView>(
getIApp()->getCommands()->createModel(nullptr))
getApp()->getCommands()->createModel(nullptr))
.getElement();
view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"});
@@ -95,7 +95,7 @@ CommandPage::CommandPage()
1, QHeaderView::Stretch);
// We can safely ignore this signal connection since we own the view
std::ignore = view->addButtonPressed.connect([] {
getIApp()->getCommands()->items.append(
getApp()->getCommands()->items.append(
Command{"/command", "I made a new command HeyGuys"});
});
@@ -114,7 +114,7 @@ CommandPage::CommandPage()
{
if (int index = line.indexOf(' '); index != -1)
{
getIApp()->getCommands()->items.insert(
getApp()->getCommands()->items.insert(
Command(line.mid(0, index), line.mid(index + 1)));
}
}
+16 -16
View File
@@ -122,7 +122,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
layout.addTitle("Interface");
{
auto *themes = getIApp()->getThemes();
auto *themes = getApp()->getThemes();
auto available = themes->availableThemes();
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
available.emplace_back("System", "System");
@@ -273,7 +273,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
layout.addCheckbox("Show message reply button", s.showReplyButton, false,
"Show a reply button next to every chat message");
auto removeTabSeq = getIApp()->getHotkeys()->getDisplaySequence(
auto removeTabSeq = getApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::Window, "removeTab");
QString removeTabShortcut = "an assigned hotkey (Window -> remove tab)";
if (!removeTabSeq.isEmpty())
@@ -294,7 +294,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
#endif
if (!BaseWindow::supportsCustomWindowFrame())
{
auto settingsSeq = getIApp()->getHotkeys()->getDisplaySequence(
auto settingsSeq = getApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::Window, "openSettings");
QString shortcut = " (no key bound to open them otherwise)";
// TODO: maybe prevent the user from locking themselves out of the settings?
@@ -570,7 +570,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
// as an official description from 7TV devs is best
s.showUnlistedSevenTVEmotes.connect(
[]() {
getIApp()->getTwitch()->forEachChannelAndSpecialChannels(
getApp()->getTwitch()->forEachChannelAndSpecialChannels(
[](const auto &c) {
if (c->isTwitchChannel())
{
@@ -824,9 +824,9 @@ void GeneralPage::initLayout(GeneralPageView &layout)
layout.addButton("Open AppData directory", [] {
#ifdef Q_OS_DARWIN
QDesktopServices::openUrl("file://" +
getIApp()->getPaths().rootAppDataDirectory);
getApp()->getPaths().rootAppDataDirectory);
#else
QDesktopServices::openUrl(getIApp()->getPaths().rootAppDataDirectory);
QDesktopServices::openUrl(getApp()->getPaths().rootAppDataDirectory);
#endif
});
@@ -838,7 +838,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
auto *cachePathLabel = layout.addDescription("placeholder :D");
getSettings()->cachePath.connect([cachePathLabel](const auto &,
auto) mutable {
QString newPath = getIApp()->getPaths().cacheDirectory();
QString newPath = getApp()->getPaths().cacheDirectory();
QString pathShortened = "Cache saved at <a href=\"file:///" + newPath +
"\"><span style=\"color: white;\">" +
@@ -866,9 +866,9 @@ void GeneralPage::initLayout(GeneralPageView &layout)
if (reply == QMessageBox::Yes)
{
auto cacheDir = QDir(getIApp()->getPaths().cacheDirectory());
auto cacheDir = QDir(getApp()->getPaths().cacheDirectory());
cacheDir.removeRecursively();
cacheDir.mkdir(getIApp()->getPaths().cacheDirectory());
cacheDir.mkdir(getApp()->getPaths().cacheDirectory());
}
}));
box->addStretch(1);
@@ -890,7 +890,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
"Show the stream title");
layout.addSubtitle("R9K");
auto toggleLocalr9kSeq = getIApp()->getHotkeys()->getDisplaySequence(
auto toggleLocalr9kSeq = getApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::Window, "toggleLocalR9K");
QString toggleLocalr9kShortcut =
"an assigned hotkey (Window -> Toggle local R9K)";
@@ -913,7 +913,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
s.shownSimilarTriggerHighlights);
s.hideSimilar.connect(
[]() {
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
},
false);
layout.addDropdown<float>(
@@ -981,15 +981,15 @@ void GeneralPage::initLayout(GeneralPageView &layout)
layout.addCustomCheckbox(
"Restart on crash (requires restart)",
[] {
return getIApp()->getCrashHandler()->shouldRecover();
return getApp()->getCrashHandler()->shouldRecover();
},
[](bool on) {
return getIApp()->getCrashHandler()->saveShouldRecover(on);
return getApp()->getCrashHandler()->saveShouldRecover(on);
},
"When possible, restart Chatterino if the program crashes");
#if defined(Q_OS_LINUX) && !defined(NO_QTKEYCHAIN)
if (!getIApp()->getPaths().isPortable())
if (!getApp()->getPaths().isPortable())
{
layout.addCheckbox(
"Use libsecret/KWallet/Gnome keychain to secure passwords",
@@ -1196,7 +1196,7 @@ void GeneralPage::initExtra()
{
getSettings()->cachePath.connect(
[cachePath = this->cachePath_](const auto &, auto) mutable {
QString newPath = getIApp()->getPaths().cacheDirectory();
QString newPath = getApp()->getPaths().cacheDirectory();
QString pathShortened = "Current location: <a href=\"file:///" +
newPath + "\">" +
@@ -1216,7 +1216,7 @@ QString GeneralPage::getFont(const DropdownArgs &args) const
auto ok = bool();
auto previousFont =
getIApp()->getFonts()->getFont(FontStyle::ChatMedium, 1.);
getApp()->getFonts()->getFont(FontStyle::ChatMedium, 1.);
auto font = QFontDialog::getFont(&ok, previousFont, this->window());
if (ok)
@@ -197,7 +197,7 @@ ComboBox *GeneralPageView::addDropdown(
QObject::connect(combo, &QComboBox::currentTextChanged,
[&setting](const QString &newValue) {
setting = newValue;
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
});
return combo;
@@ -204,7 +204,7 @@ public:
.index = combo->currentIndex(),
.combobox = combo,
});
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
};
if (listenToActivated)
@@ -268,7 +268,7 @@ public:
setValue = std::move(setValue)](const int newIndex) {
setting = setValue(DropdownArgs{combo->itemText(newIndex),
combo->currentIndex(), combo});
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
});
return combo;
@@ -312,7 +312,7 @@ public:
// Instead, it's up to the getters to make sure that the setting is legic - see the enum_cast above
// You could also use the settings `getEnum` function
setting = newText;
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
});
return combo;
@@ -22,7 +22,7 @@ using namespace chatterino;
void tableCellClicked(const QModelIndex &clicked, EditableModelView *view,
HotkeyModel *model)
{
auto hotkey = getIApp()->getHotkeys()->getHotkeyByName(
auto hotkey = getApp()->getHotkeys()->getHotkeyByName(
clicked.siblingAtColumn(0).data(Qt::EditRole).toString());
if (!hotkey)
{
@@ -34,8 +34,8 @@ void tableCellClicked(const QModelIndex &clicked, EditableModelView *view,
if (wasAccepted)
{
auto newHotkey = dialog.data();
getIApp()->getHotkeys()->replaceHotkey(hotkey->name(), newHotkey);
getIApp()->getHotkeys()->save();
getApp()->getHotkeys()->replaceHotkey(hotkey->name(), newHotkey);
getApp()->getHotkeys()->save();
}
}
@@ -48,7 +48,7 @@ KeyboardSettingsPage::KeyboardSettingsPage()
LayoutCreator<KeyboardSettingsPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>();
auto *model = getIApp()->getHotkeys()->createModel(nullptr);
auto *model = getApp()->getHotkeys()->createModel(nullptr);
EditableModelView *view =
layout.emplace<EditableModelView>(model).getElement();
@@ -68,8 +68,8 @@ KeyboardSettingsPage::KeyboardSettingsPage()
if (wasAccepted)
{
auto newHotkey = dialog.data();
getIApp()->getHotkeys()->hotkeys_.append(newHotkey);
getIApp()->getHotkeys()->save();
getApp()->getHotkeys()->hotkeys_.append(newHotkey);
getApp()->getHotkeys()->save();
}
});
@@ -87,7 +87,7 @@ KeyboardSettingsPage::KeyboardSettingsPage()
if (reply == QMessageBox::Yes)
{
getIApp()->getHotkeys()->resetToDefaults();
getApp()->getHotkeys()->resetToDefaults();
}
});
view->addCustomButton(resetEverything);
+13 -13
View File
@@ -58,7 +58,7 @@ QString formatSize(qint64 size)
QString fetchLogDirectorySize()
{
QString logsDirectoryPath = getSettings()->logPath.getValue().isEmpty()
? getIApp()->getPaths().messageLogDirectory
? getApp()->getPaths().messageLogDirectory
: getSettings()->logPath;
auto logsSize = dirSize(logsDirectoryPath);
@@ -83,20 +83,20 @@ ModerationPage::ModerationPage()
auto logsPathLabel = logs.emplace<QLabel>();
// Logs (copied from LoggingMananger)
getSettings()->logPath.connect([logsPathLabel](const QString &logPath,
auto) mutable {
QString pathOriginal =
logPath.isEmpty() ? getIApp()->getPaths().messageLogDirectory
: logPath;
getSettings()->logPath.connect(
[logsPathLabel](const QString &logPath, auto) mutable {
QString pathOriginal =
logPath.isEmpty() ? getApp()->getPaths().messageLogDirectory
: logPath;
QString pathShortened =
"Logs are saved at <a href=\"file:///" + pathOriginal +
"\"><span style=\"color: white;\">" +
shortenString(pathOriginal, 50) + "</span></a>";
QString pathShortened =
"Logs are saved at <a href=\"file:///" + pathOriginal +
"\"><span style=\"color: white;\">" +
shortenString(pathOriginal, 50) + "</span></a>";
logsPathLabel->setText(pathShortened);
logsPathLabel->setToolTip(pathOriginal);
});
logsPathLabel->setText(pathShortened);
logsPathLabel->setToolTip(pathOriginal);
});
logsPathLabel->setTextFormat(Qt::RichText);
logsPathLabel->setTextInteractionFlags(Qt::TextBrowserInteraction |
@@ -97,7 +97,7 @@ NotificationPage::NotificationPage()
EditableModelView *view =
twitchChannels
.emplace<EditableModelView>(
getIApp()->getNotifications()->createModel(
getApp()->getNotifications()->createModel(
nullptr, Platform::Twitch))
.getElement();
view->setTitles({"Twitch channels"});
+4 -4
View File
@@ -55,7 +55,7 @@ PluginsPage::PluginsPage()
auto *description =
new QLabel("You can load plugins by putting them into " +
formatRichNamedLink(
"file:///" + getIApp()->getPaths().pluginsDirectory,
"file:///" + getApp()->getPaths().pluginsDirectory,
"the Plugins directory") +
". Each one is a new directory.");
description->setOpenExternalLinks(true);
@@ -95,7 +95,7 @@ void PluginsPage::rebuildContent()
this->scrollAreaWidget_.append(this->dataFrame_);
auto layout = frame.setLayoutType<QVBoxLayout>();
layout->setParent(this->dataFrame_);
for (const auto &[id, plugin] : getIApp()->getPlugins()->plugins())
for (const auto &[id, plugin] : getApp()->getPlugins()->plugins())
{
auto groupHeaderText =
QString("%1 (%2, from %3)")
@@ -214,7 +214,7 @@ void PluginsPage::rebuildContent()
val.push_back(name);
}
getSettings()->enabledPlugins.setValue(val);
getIApp()->getPlugins()->reload(name);
getApp()->getPlugins()->reload(name);
this->rebuildContent();
});
pluginEntry->addRow(toggleButton);
@@ -223,7 +223,7 @@ void PluginsPage::rebuildContent()
auto *reloadButton = new QPushButton("Reload", this->dataFrame_);
QObject::connect(reloadButton, &QPushButton::pressed,
[name = id, this]() {
getIApp()->getPlugins()->reload(name);
getApp()->getPlugins()->reload(name);
this->rebuildContent();
});
pluginEntry->addRow(reloadButton);
+1 -1
View File
@@ -103,7 +103,7 @@ QCheckBox *SettingsPage::createCheckBox(
QObject::connect(checkbox, &QCheckBox::toggled, this,
[&setting](bool state) {
setting = state;
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
});
return checkbox;