Remove some duplicate code
Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
parent
e4a801fdf7
commit
ef3bf75715
7 changed files with 31 additions and 50 deletions
|
@ -696,8 +696,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
|||
m_settings->registerSetting("ConsoleMaxLines", 100000);
|
||||
m_settings->registerSetting("ConsoleOverflowStop", true);
|
||||
|
||||
logModel->setMaxLines(getConsoleMaxLines());
|
||||
logModel->setStopOnOverflow(shouldStopOnConsoleOverflow());
|
||||
logModel->setMaxLines(getConsoleMaxLines(settings()));
|
||||
logModel->setStopOnOverflow(shouldStopOnConsoleOverflow(settings()));
|
||||
logModel->setOverflowMessage(tr("Cannot display this log since the log length surpassed %1 lines.").arg(logModel->getMaxLines()));
|
||||
|
||||
// Folders
|
||||
|
@ -1605,23 +1605,6 @@ void Application::updateIsRunning(bool running)
|
|||
m_updateRunning = running;
|
||||
}
|
||||
|
||||
int Application::getConsoleMaxLines() const
|
||||
{
|
||||
auto lineSetting = settings()->getSetting("ConsoleMaxLines");
|
||||
bool conversionOk = false;
|
||||
int maxLines = lineSetting->get().toInt(&conversionOk);
|
||||
if (!conversionOk) {
|
||||
maxLines = lineSetting->defValue().toInt();
|
||||
qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines;
|
||||
}
|
||||
return maxLines;
|
||||
}
|
||||
|
||||
bool Application::shouldStopOnConsoleOverflow() const
|
||||
{
|
||||
return settings()->get("ConsoleOverflowStop").toBool();
|
||||
}
|
||||
|
||||
void Application::controllerSucceeded()
|
||||
{
|
||||
auto controller = qobject_cast<LaunchController*>(QObject::sender());
|
||||
|
|
|
@ -162,9 +162,6 @@ class Application : public QApplication {
|
|||
QString getModrinthAPIToken();
|
||||
QString getUserAgent();
|
||||
|
||||
int getConsoleMaxLines() const;
|
||||
bool shouldStopOnConsoleOverflow() const;
|
||||
|
||||
/// this is the root of the 'installation'. Used for automatic updates
|
||||
const QString& root() { return m_rootPath; }
|
||||
|
||||
|
|
|
@ -53,6 +53,23 @@
|
|||
#include "Commandline.h"
|
||||
#include "FileSystem.h"
|
||||
|
||||
int getConsoleMaxLines(SettingsObjectPtr settings)
|
||||
{
|
||||
auto lineSetting = settings->getSetting("ConsoleMaxLines");
|
||||
bool conversionOk = false;
|
||||
int maxLines = lineSetting->get().toInt(&conversionOk);
|
||||
if (!conversionOk) {
|
||||
maxLines = lineSetting->defValue().toInt();
|
||||
qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines;
|
||||
}
|
||||
return maxLines;
|
||||
}
|
||||
|
||||
bool shouldStopOnConsoleOverflow(SettingsObjectPtr settings)
|
||||
{
|
||||
return settings->get("ConsoleOverflowStop").toBool();
|
||||
}
|
||||
|
||||
BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString& rootDir) : QObject()
|
||||
{
|
||||
m_settings = settings;
|
||||
|
@ -184,23 +201,6 @@ void BaseInstance::copyManagedPack(BaseInstance& other)
|
|||
}
|
||||
}
|
||||
|
||||
int BaseInstance::getConsoleMaxLines() const
|
||||
{
|
||||
auto lineSetting = m_settings->getSetting("ConsoleMaxLines");
|
||||
bool conversionOk = false;
|
||||
int maxLines = lineSetting->get().toInt(&conversionOk);
|
||||
if (!conversionOk) {
|
||||
maxLines = lineSetting->defValue().toInt();
|
||||
qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines;
|
||||
}
|
||||
return maxLines;
|
||||
}
|
||||
|
||||
bool BaseInstance::shouldStopOnConsoleOverflow() const
|
||||
{
|
||||
return m_settings->get("ConsoleOverflowStop").toBool();
|
||||
}
|
||||
|
||||
QStringList BaseInstance::getLinkedInstances() const
|
||||
{
|
||||
auto setting = m_settings->get("linkedInstances").toString();
|
||||
|
|
|
@ -78,6 +78,10 @@ struct ShortcutData {
|
|||
ShortcutTarget target = ShortcutTarget::Other;
|
||||
};
|
||||
|
||||
/// Console settings
|
||||
int getConsoleMaxLines(SettingsObjectPtr settings);
|
||||
bool shouldStopOnConsoleOverflow(SettingsObjectPtr settings);
|
||||
|
||||
/*!
|
||||
* \brief Base class for instances.
|
||||
* This class implements many functions that are common between instances and
|
||||
|
@ -272,9 +276,6 @@ class BaseInstance : public QObject, public std::enable_shared_from_this<BaseIns
|
|||
|
||||
Status currentStatus() const;
|
||||
|
||||
int getConsoleMaxLines() const;
|
||||
bool shouldStopOnConsoleOverflow() const;
|
||||
|
||||
QStringList getLinkedInstances() const;
|
||||
void setLinkedInstances(const QStringList& list);
|
||||
void addLinkedInstanceId(const QString& id);
|
||||
|
|
|
@ -27,6 +27,6 @@ MessageLevel::Enum getLevel(QtMsgType type);
|
|||
/* Get message level from a line. Line is modified if it was successful. */
|
||||
MessageLevel::Enum fromLine(QString& line);
|
||||
|
||||
/* Get message level from a line from the launcher log. Line is modified if it was successful. */
|
||||
/* Get message level from a line from the launcher log. Line is modified if it was successful. */
|
||||
MessageLevel::Enum fromLauncherLine(QString& line);
|
||||
} // namespace MessageLevel
|
||||
|
|
|
@ -203,8 +203,8 @@ shared_qobject_ptr<LogModel> LaunchTask::getLogModel()
|
|||
{
|
||||
if (!m_logModel) {
|
||||
m_logModel.reset(new LogModel());
|
||||
m_logModel->setMaxLines(m_instance->getConsoleMaxLines());
|
||||
m_logModel->setStopOnOverflow(m_instance->shouldStopOnConsoleOverflow());
|
||||
m_logModel->setMaxLines(getConsoleMaxLines(m_instance->settings()));
|
||||
m_logModel->setStopOnOverflow(shouldStopOnConsoleOverflow(m_instance->settings()));
|
||||
// FIXME: should this really be here?
|
||||
m_logModel->setOverflowMessage(tr("Stopped watching the game log because the log length surpassed %1 lines.\n"
|
||||
"You may have to fix your mods because the game is still logging to files and"
|
||||
|
|
|
@ -66,7 +66,7 @@ OtherLogsPage::OtherLogsPage(QString id, QString displayName, QString helpPage,
|
|||
m_proxy = new LogFormatProxyModel(this);
|
||||
if (m_instance) {
|
||||
m_model.reset(new LogModel(this));
|
||||
ui->trackLogCheckbox->setVisible(false);
|
||||
ui->trackLogCheckbox->hide();
|
||||
} else {
|
||||
m_model = APPLICATION->logModel;
|
||||
}
|
||||
|
@ -85,8 +85,8 @@ OtherLogsPage::OtherLogsPage(QString id, QString displayName, QString helpPage,
|
|||
ui->text->setModel(m_proxy);
|
||||
|
||||
if (m_instance) {
|
||||
m_model->setMaxLines(m_instance->getConsoleMaxLines());
|
||||
m_model->setStopOnOverflow(m_instance->shouldStopOnConsoleOverflow());
|
||||
m_model->setMaxLines(getConsoleMaxLines(m_instance->settings()));
|
||||
m_model->setStopOnOverflow(shouldStopOnConsoleOverflow(m_instance->settings()));
|
||||
m_model->setOverflowMessage(tr("Cannot display this log since the log length surpassed %1 lines.").arg(m_model->getMaxLines()));
|
||||
} else {
|
||||
modelStateToUI();
|
||||
|
@ -310,8 +310,8 @@ void OtherLogsPage::reload()
|
|||
ui->text->setModel(nullptr);
|
||||
if (!m_instance) {
|
||||
m_model.reset(new LogModel(this));
|
||||
m_model->setMaxLines(APPLICATION->getConsoleMaxLines());
|
||||
m_model->setStopOnOverflow(APPLICATION->shouldStopOnConsoleOverflow());
|
||||
m_model->setMaxLines(getConsoleMaxLines(APPLICATION->settings()));
|
||||
m_model->setStopOnOverflow(shouldStopOnConsoleOverflow(APPLICATION->settings()));
|
||||
m_model->setOverflowMessage(tr("Cannot display this log since the log length surpassed %1 lines.").arg(m_model->getMaxLines()));
|
||||
}
|
||||
m_model->clear();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue