renamed getInstance() -> instance() for singletons

This commit is contained in:
fourtf 2019-10-07 22:42:34 +02:00
parent aeab038bc8
commit 6f710823ed
37 changed files with 77 additions and 77 deletions

View file

@ -82,7 +82,7 @@ void Application::initialize(Settings &settings, Paths &paths)
if (getSettings()->enableExperimentalIrc)
{
Irc::getInstance().load();
Irc::instance().load();
}
for (auto &singleton : this->singletons_)
@ -130,7 +130,7 @@ int Application::run(QApplication &qtApp)
this->windows->getMainWindow().show();
getSettings()->betaUpdates.connect(
[] { Updates::getInstance().checkForUpdates(); }, false);
[] { Updates::instance().checkForUpdates(); }, false);
return qtApp.exec();
}

View file

@ -194,7 +194,7 @@ void runGui(QApplication &a, Paths &paths, Settings &settings)
});
chatterino::NetworkManager::init();
chatterino::Updates::getInstance().checkForUpdates();
chatterino::Updates::instance().checkForUpdates();
#ifdef C_USE_BREAKPAD
QBreakpadInstance.setDumpPath(getPaths()->settingsFolderPath + "/Crashes");

View file

@ -178,7 +178,7 @@ void Channel::addOrReplaceTimeout(MessagePtr message)
}
// XXX: Might need the following line
// WindowManager::getInstance().repaintVisibleChatWidgets(this);
// WindowManager::instance().repaintVisibleChatWidgets(this);
}
void Channel::disableAllMessages()

View file

@ -143,7 +143,7 @@ namespace {
}
} // namespace
Credentials &Credentials::getInstance()
Credentials &Credentials::instance()
{
static Credentials creds;
return creds;

View file

@ -8,7 +8,7 @@ namespace chatterino {
class Credentials
{
public:
static Credentials &getInstance();
static Credentials &instance();
void get(const QString &provider, const QString &name, QObject *receiver,
std::function<void(const QString &)> &&onLoaded);

View file

@ -27,7 +27,7 @@ Modes::Modes()
}
}
const Modes &Modes::getInstance()
const Modes &Modes::instance()
{
static Modes instance;
return instance;

View file

@ -7,7 +7,7 @@ class Modes
public:
Modes();
static const Modes &getInstance();
static const Modes &instance();
bool isNightly{};
bool isPortable{};

View file

@ -26,7 +26,7 @@ Version::Version()
// "Full" version string, as displayed in window title
this->fullVersion_ = "Chatterino ";
if (Modes::getInstance().isNightly)
if (Modes::instance().isNightly)
{
this->fullVersion_ += "Nightly ";
}
@ -34,7 +34,7 @@ Version::Version()
this->fullVersion_ += this->version_;
}
const Version &Version::getInstance()
const Version &Version::instance()
{
static Version instance;
return instance;

View file

@ -20,7 +20,7 @@ namespace chatterino {
class Version
{
public:
static const Version &getInstance();
static const Version &instance();
const QString &version() const;
const QString &commitHash() const;

View file

@ -32,7 +32,7 @@ int main(int argc, char **argv)
}
else if (getArgs().printVersion)
{
qInfo().noquote() << Version::getInstance().fullVersion();
qInfo().noquote() << Version::instance().fullVersion();
}
else
{
@ -45,7 +45,7 @@ int main(int argc, char **argv)
catch (std::runtime_error &error)
{
QMessageBox box;
if (Modes::getInstance().isPortable)
if (Modes::instance().isPortable)
{
box.setText(
error.what() +

View file

@ -73,13 +73,13 @@ inline QString getCredentialName(const IrcServerData &data)
void IrcServerData::getPassword(
QObject *receiver, std::function<void(const QString &)> &&onLoaded) const
{
Credentials::getInstance().get("irc", getCredentialName(*this), receiver,
Credentials::instance().get("irc", getCredentialName(*this), receiver,
std::move(onLoaded));
}
void IrcServerData::setPassword(const QString &password)
{
Credentials::getInstance().set("irc", getCredentialName(*this), password);
Credentials::instance().set("irc", getCredentialName(*this), password);
}
Irc::Irc()
@ -133,7 +133,7 @@ Irc::Irc()
if (args.caller != Irc::noEraseCredentialCaller)
{
Credentials::getInstance().erase("irc",
Credentials::instance().erase("irc",
getCredentialName(args.item));
}
});
@ -164,7 +164,7 @@ ChannelPtr Irc::getOrAddChannel(int id, QString name)
}
}
Irc &Irc::getInstance()
Irc &Irc::instance()
{
static Irc irc;
return irc;

View file

@ -36,7 +36,7 @@ class Irc
public:
Irc();
static Irc &getInstance();
static Irc &instance();
static inline void *const noEraseCredentialCaller =
reinterpret_cast<void *>(1);

View file

@ -40,7 +40,7 @@ static QMap<QString, QString> parseBadges(QString badgesString)
return badges;
}
IrcMessageHandler &IrcMessageHandler::getInstance()
IrcMessageHandler &IrcMessageHandler::instance()
{
static IrcMessageHandler instance;
return instance;

View file

@ -13,7 +13,7 @@ class IrcMessageHandler
IrcMessageHandler() = default;
public:
static IrcMessageHandler &getInstance();
static IrcMessageHandler &instance();
// parseMessage parses a single IRC message into 0+ Chatterino messages
std::vector<MessagePtr> parseMessage(Channel *channel,

View file

@ -566,7 +566,7 @@ void TwitchChannel::loadRecentMessages()
auto messages = parseRecentMessages(result.parseJson(), shared);
auto &handler = IrcMessageHandler::getInstance();
auto &handler = IrcMessageHandler::instance();
std::vector<MessagePtr> allBuiltMessages;

View file

@ -125,7 +125,7 @@ std::shared_ptr<Channel> TwitchIrcServer::createChannel(
void TwitchIrcServer::privateMessageReceived(
Communi::IrcPrivateMessage *message)
{
IrcMessageHandler::getInstance().handlePrivMessage(message, *this);
IrcMessageHandler::instance().handlePrivMessage(message, *this);
}
void TwitchIrcServer::readConnectionMessageReceived(
@ -141,7 +141,7 @@ void TwitchIrcServer::readConnectionMessageReceived(
const QString &command = message->command();
auto &handler = IrcMessageHandler::getInstance();
auto &handler = IrcMessageHandler::instance();
// Below commands enabled through the twitch.tv/membership CAP REQ
if (command == "MODE")
@ -194,7 +194,7 @@ void TwitchIrcServer::writeConnectionMessageReceived(
{
const QString &command = message->command();
auto &handler = IrcMessageHandler::getInstance();
auto &handler = IrcMessageHandler::instance();
// Below commands enabled through the twitch.tv/commands CAP REQ
if (command == "USERSTATE")
{

View file

@ -652,7 +652,7 @@ void TwitchMessageBuilder::appendUsername()
{
// TODO(pajlada): Re-implement
// userDisplayString +=
// IrcManager::getInstance().getUser().getUserName();
// IrcManager::instance().getUser().getUserName();
}
else if (this->args.isReceivedWhisper)
{

View file

@ -35,7 +35,7 @@ bool Paths::createFolder(const QString &folderPath)
bool Paths::isPortable()
{
return Modes::getInstance().isPortable;
return Modes::instance().isPortable;
}
QString Paths::cacheDirectory()

View file

@ -9,12 +9,12 @@
namespace chatterino {
Settings *Settings::instance = nullptr;
Settings *Settings::instance_ = nullptr;
Settings::Settings(const QString &settingsDirectory)
: ABSettings(settingsDirectory)
{
instance = this;
instance_ = this;
#ifdef USEWINSDK
this->autorun = isRegisteredForStartup();
@ -23,14 +23,14 @@ Settings::Settings(const QString &settingsDirectory)
#endif
}
Settings &Settings::getInstance()
Settings &Settings::instance()
{
return *instance;
return *instance_;
}
Settings *getSettings()
{
return &Settings::getInstance();
return &Settings::instance();
}
} // namespace chatterino

View file

@ -13,12 +13,12 @@ namespace chatterino {
class Settings : public ABSettings
{
static Settings *instance;
static Settings *instance_;
public:
Settings(const QString &settingsDirectory);
static Settings &getInstance();
static Settings &instance();
/// Appearance
BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};

View file

@ -5,7 +5,7 @@
#include "widgets/TooltipWidget.hpp"
namespace chatterino {
TooltipPreviewImage &TooltipPreviewImage::getInstance()
TooltipPreviewImage &TooltipPreviewImage::instance()
{
static TooltipPreviewImage *instance = new TooltipPreviewImage();
return *instance;
@ -14,7 +14,7 @@ TooltipPreviewImage &TooltipPreviewImage::getInstance()
TooltipPreviewImage::TooltipPreviewImage()
{
connections_.push_back(getApp()->windows->gifRepaintRequested.connect([&] {
auto tooltipWidget = TooltipWidget::getInstance();
auto tooltipWidget = TooltipWidget::instance();
if (this->image_ && !tooltipWidget->isHidden())
{
auto pixmap = this->image_->pixmapOrLoad();

View file

@ -6,7 +6,7 @@ namespace chatterino {
class TooltipPreviewImage
{
public:
static TooltipPreviewImage &getInstance();
static TooltipPreviewImage &instance();
void setImage(ImagePtr image);
TooltipPreviewImage(const TooltipPreviewImage &) = delete;

View file

@ -62,7 +62,7 @@ Updates::Updates()
qDebug() << "init UpdateManager";
}
Updates &Updates::getInstance()
Updates &Updates::instance()
{
// fourtf: don't add this class to the application class
static Updates instance;
@ -234,7 +234,7 @@ void Updates::checkForUpdates()
{
// Disable updates if on nightly and windows.
#ifdef Q_OS_WIN
if (Modes::getInstance().isNightly)
if (Modes::instance().isNightly)
{
return;
}

View file

@ -22,7 +22,7 @@ public:
};
// fourtf: don't add this class to the application class
static Updates &getInstance();
static Updates &instance();
void checkForUpdates();
const QString &getCurrentVersion() const;

View file

@ -649,7 +649,7 @@ IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj)
}
else if (type == "irc")
{
return Irc::getInstance().getOrAddChannel(
return Irc::instance().getOrAddChannel(
obj.value("server").toInt(-1), obj.value("channel").toString());
}

View file

@ -27,7 +27,7 @@ void initUpdateButton(Button &button,
}
break;
case UpdateDialog::Install: {
Updates::getInstance().installUpdates();
Updates::instance().installUpdates();
}
break;
}
@ -39,18 +39,18 @@ void initUpdateButton(Button &button,
// update image when state changes
auto updateChange = [&button](auto) {
button.setVisible(Updates::getInstance().shouldShowUpdateButton());
button.setVisible(Updates::instance().shouldShowUpdateButton());
auto imageUrl = Updates::getInstance().isError()
auto imageUrl = Updates::instance().isError()
? ":/buttons/updateError.png"
: ":/buttons/update.png";
button.setPixmap(QPixmap(imageUrl));
};
updateChange(Updates::getInstance().getStatus());
updateChange(Updates::instance().getStatus());
signalHolder.managedConnect(
Updates::getInstance().statusUpdated,
Updates::instance().statusUpdated,
[updateChange](auto status) { updateChange(status); });
}

View file

@ -464,7 +464,7 @@ void BaseWindow::changeEvent(QEvent *)
{
if (this->isVisible())
{
TooltipWidget::getInstance()->hide();
TooltipWidget::instance()->hide();
}
#ifdef USEWINSDK
@ -494,7 +494,7 @@ void BaseWindow::changeEvent(QEvent *)
void BaseWindow::leaveEvent(QEvent *)
{
TooltipWidget::getInstance()->hide();
TooltipWidget::instance()->hide();
}
void BaseWindow::moveTo(QWidget *parent, QPoint point, bool offset)

View file

@ -14,7 +14,7 @@
namespace chatterino {
TooltipWidget *TooltipWidget::getInstance()
TooltipWidget *TooltipWidget::instance()
{
static TooltipWidget *tooltipWidget = new TooltipWidget();
return tooltipWidget;

View file

@ -13,7 +13,7 @@ class TooltipWidget : public BaseWindow
Q_OBJECT
public:
static TooltipWidget *getInstance();
static TooltipWidget *instance();
TooltipWidget(BaseWidget *parent = nullptr);
~TooltipWidget() override;

View file

@ -367,7 +367,7 @@ void Window::onAccountSelected()
auto user = getApp()->accounts->twitch.getCurrent();
// update title
this->setWindowTitle(Version::getInstance().fullVersion());
this->setWindowTitle(Version::instance().fullVersion());
// update user
if (user->isAnon())

View file

@ -31,7 +31,7 @@ LastRunCrashDialog::LastRunCrashDialog()
// QDialogButtonBox::NoRole); installUpdateButton->setEnabled(false);
// QObject::connect(installUpdateButton, &QPushButton::clicked, [this,
// update]() mutable {
// auto &updateManager = UpdateManager::getInstance();
// auto &updateManager = UpdateManager::instance();
// updateManager.installUpdates();
// this->setEnabled(false);
@ -45,7 +45,7 @@ LastRunCrashDialog::LastRunCrashDialog()
// Updates
// auto updateUpdateLabel = [update]() mutable {
// auto &updateManager = UpdateManager::getInstance();
// auto &updateManager = UpdateManager::instance();
// switch (updateManager.getStatus()) {
// case UpdateManager::None: {

View file

@ -134,7 +134,7 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
{
auto view = this->ui_.irc.servers = new EditableModelView(
Irc::getInstance().newConnectionModel(this));
Irc::instance().newConnectionModel(this));
view->setTitles({"host", "port", "ssl", "user", "nick", "real",
"password", "login command"});
@ -147,12 +147,12 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
view->addButtonPressed.connect([] {
auto unique = IrcServerData{};
unique.id = Irc::getInstance().uniqueId();
unique.id = Irc::instance().uniqueId();
auto editor = new IrcConnectionEditor(unique);
if (editor->exec() == QDialog::Accepted)
{
Irc::getInstance().connections.appendItem(editor->data());
Irc::instance().connections.appendItem(editor->data());
}
});
@ -160,22 +160,22 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
view->getTableView(), &QTableView::doubleClicked,
[](const QModelIndex &index) {
auto editor = new IrcConnectionEditor(
Irc::getInstance()
Irc::instance()
.connections.getVector()[size_t(index.row())]);
if (editor->exec() == QDialog::Accepted)
{
auto data = editor->data();
auto &&conns =
Irc::getInstance().connections.getVector();
Irc::instance().connections.getVector();
int i = 0;
for (auto &&conn : conns)
{
if (conn.id == data.id)
{
Irc::getInstance().connections.removeItem(
Irc::instance().connections.removeItem(
i, Irc::noEraseCredentialCaller);
Irc::getInstance().connections.insertItem(data,
Irc::instance().connections.insertItem(data,
i);
}
i++;
@ -289,7 +289,7 @@ void SelectChannelDialog::setSelectedChannel(IndirectChannel _channel)
if (auto server = ircChannel->server())
{
int i = 0;
for (auto &&conn : Irc::getInstance().connections)
for (auto &&conn : Irc::instance().connections)
{
if (conn.id == server->id())
{
@ -350,11 +350,11 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const
->currentIndex()
.row();
auto &&vector = Irc::getInstance().connections.getVector();
auto &&vector = Irc::instance().connections.getVector();
if (row >= 0 && row < int(vector.size()))
{
return Irc::getInstance().getOrAddChannel(
return Irc::instance().getOrAddChannel(
vector[size_t(row)].id, this->ui_.irc.channel->text());
}
else

View file

@ -26,7 +26,7 @@ UpdateDialog::UpdateDialog()
auto dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
QObject::connect(install, &QPushButton::clicked, this, [this] {
Updates::getInstance().installUpdates();
Updates::instance().installUpdates();
this->close();
});
QObject::connect(dismiss, &QPushButton::clicked, this, [this] {
@ -34,9 +34,9 @@ UpdateDialog::UpdateDialog()
this->close();
});
this->updateStatusChanged(Updates::getInstance().getStatus());
this->updateStatusChanged(Updates::instance().getStatus());
this->connections_.managedConnect(
Updates::getInstance().statusUpdated,
Updates::instance().statusUpdated,
[this](auto status) { this->updateStatusChanged(status); });
this->setScaleIndependantHeight(150);
@ -50,17 +50,17 @@ void UpdateDialog::updateStatusChanged(Updates::Status status)
{
case Updates::UpdateAvailable: {
this->ui_.label->setText(
(Updates::getInstance().isDowngrade()
(Updates::instance().isDowngrade()
? QString(
"The version online (%1) seems to be lower than the "
"current (%2).\nEither a version was reverted or "
"you are running a newer build.\n\nDo you want to "
"download and install it?")
.arg(Updates::getInstance().getOnlineVersion(),
Updates::getInstance().getCurrentVersion())
.arg(Updates::instance().getOnlineVersion(),
Updates::instance().getCurrentVersion())
: QString("An update (%1) is available.\n\nDo you want to "
"download and install it?")
.arg(Updates::getInstance().getOnlineVersion())));
.arg(Updates::instance().getOnlineVersion())));
this->updateGeometry();
}
break;

View file

@ -1049,7 +1049,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
this->pause(PauseReason::Mouse);
}
auto tooltipWidget = TooltipWidget::getInstance();
auto tooltipWidget = TooltipWidget::instance();
std::shared_ptr<MessageLayout> layout;
QPoint relativePos;
int messageIndex;
@ -1242,7 +1242,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
}
else
{
auto &tooltipPreviewImage = TooltipPreviewImage::getInstance();
auto &tooltipPreviewImage = TooltipPreviewImage::instance();
auto emoteElement = dynamic_cast<const EmoteElement *>(
&hoverLayoutElement->getCreator());
auto badgeElement = dynamic_cast<const BadgeElement *>(

View file

@ -75,7 +75,7 @@ AboutPage::AboutPage()
auto versionInfo = layout.emplace<QGroupBox>("Version");
{
auto version = Version::getInstance();
auto version = Version::instance();
QString text = QString("%1 (commit %2%3)")
.arg(version.fullVersion())
.arg("<a "
@ -83,7 +83,7 @@ AboutPage::AboutPage()
"chatterino2/commit/" +
version.commitHash() + "\">" +
version.commitHash() + "</a>")
.arg(Modes::getInstance().isNightly
.arg(Modes::instance().isNightly
? ", " + version.dateOfBuild()
: "");

View file

@ -412,7 +412,7 @@ void Split::leaveEvent(QEvent *event)
this->overlay_->hide();
TooltipWidget::getInstance()->hide();
TooltipWidget::instance()->hide();
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}

View file

@ -670,9 +670,9 @@ void SplitHeader::enterEvent(QEvent *event)
{
if (!this->tooltipText_.isEmpty())
{
TooltipPreviewImage::getInstance().setImage(nullptr);
TooltipPreviewImage::instance().setImage(nullptr);
auto tooltip = TooltipWidget::getInstance();
auto tooltip = TooltipWidget::instance();
tooltip->moveTo(this, this->mapToGlobal(this->rect().bottomLeft()),
false);
tooltip->setText(this->tooltipText_);
@ -687,7 +687,7 @@ void SplitHeader::enterEvent(QEvent *event)
void SplitHeader::leaveEvent(QEvent *event)
{
TooltipWidget::getInstance()->hide();
TooltipWidget::instance()->hide();
BaseWidget::leaveEvent(event);
}