summaryrefslogtreecommitdiffstats
path: root/application/pages/LogPage.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-08-06 15:39:29 +0200
committerPetr Mrázek <peterix@gmail.com>2016-08-07 11:48:15 +0200
commitbc6d1b5304f715ad0d8be27efd6630f820572da4 (patch)
tree6f42bdd351664b6f828247b4860ee3ad723b0971 /application/pages/LogPage.cpp
parentc44d41ee9b132d4f757658bd62d4b115b7887fe3 (diff)
downloadMultiMC-bc6d1b5304f715ad0d8be27efd6630f820572da4.tar
MultiMC-bc6d1b5304f715ad0d8be27efd6630f820572da4.tar.gz
MultiMC-bc6d1b5304f715ad0d8be27efd6630f820572da4.tar.lz
MultiMC-bc6d1b5304f715ad0d8be27efd6630f820572da4.tar.xz
MultiMC-bc6d1b5304f715ad0d8be27efd6630f820572da4.zip
GH-338, GH-513, GH-700 Unify edit instance with console window
* The resulting instance window can be closed at any point. * Main window is kept open and running instances are marked with a badge. * Multiple instances can now run from the same MultiMC - it's even more **multi** now. * MultiMC can be entirely closed, keeping Minecraft(s) running.
Diffstat (limited to 'application/pages/LogPage.cpp')
-rw-r--r--application/pages/LogPage.cpp75
1 files changed, 53 insertions, 22 deletions
diff --git a/application/pages/LogPage.cpp b/application/pages/LogPage.cpp
index af96148b..de4ed4f3 100644
--- a/application/pages/LogPage.cpp
+++ b/application/pages/LogPage.cpp
@@ -12,40 +12,57 @@
#include "GuiUtil.h"
#include <ColorCache.h>
-LogPage::LogPage(std::shared_ptr<LaunchTask> proc, QWidget *parent)
- : QWidget(parent), ui(new Ui::LogPage), m_process(proc)
+LogPage::LogPage(InstancePtr instance, QWidget *parent)
+ : QWidget(parent), ui(new Ui::LogPage), m_instance(instance)
{
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
- connect(m_process.get(), SIGNAL(log(QString, MessageLevel::Enum)), this,
- SLOT(write(QString, MessageLevel::Enum)));
// create the format and set its font
- defaultFormat = new QTextCharFormat(ui->text->currentCharFormat());
- QString fontFamily = MMC->settings()->get("ConsoleFont").toString();
- bool conversionOk = false;
- int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk);
- if(!conversionOk)
{
- fontSize = 11;
+ defaultFormat = new QTextCharFormat(ui->text->currentCharFormat());
+ QString fontFamily = MMC->settings()->get("ConsoleFont").toString();
+ bool conversionOk = false;
+ int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk);
+ if(!conversionOk)
+ {
+ fontSize = 11;
+ }
+ defaultFormat->setFont(QFont(fontFamily, fontSize));
}
- defaultFormat->setFont(QFont(fontFamily, fontSize));
// ensure we don't eat all the RAM
- auto lineSetting = MMC->settings()->getSetting("ConsoleMaxLines");
- int maxLines = lineSetting->get().toInt(&conversionOk);
- if(!conversionOk)
{
- maxLines = lineSetting->defValue().toInt();
- qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines;
+ auto lineSetting = MMC->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;
+ }
+ ui->text->setMaximumBlockCount(maxLines);
+
+ m_stopOnOverflow = MMC->settings()->get("ConsoleOverflowStop").toBool();
}
- ui->text->setMaximumBlockCount(maxLines);
- auto origForeground = ui->text->palette().color(ui->text->foregroundRole());
- auto origBackground = ui->text->palette().color(ui->text->backgroundRole());
- m_colors.reset(new LogColorCache(origForeground, origBackground));
+ // set up instance and launch process recognition
+ {
+ auto launchTask = m_instance->getLaunchTask();
+ if(launchTask)
+ {
+ on_InstanceLaunchTask_changed(launchTask);
+ }
+ connect(m_instance.get(), &BaseInstance::launchTaskChanged,
+ this, &LogPage::on_InstanceLaunchTask_changed);
+ }
- m_stopOnOverflow = MMC->settings()->get("ConsoleOverflowStop").toBool();
+ // set up text colors and adapt them to the current theme foreground and background
+ {
+ auto origForeground = ui->text->palette().color(ui->text->foregroundRole());
+ auto origBackground = ui->text->palette().color(ui->text->backgroundRole());
+ m_colors.reset(new LogColorCache(origForeground, origBackground));
+ }
auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this);
connect(findShortcut, SIGNAL(activated()), SLOT(findActivated()));
@@ -62,6 +79,20 @@ LogPage::~LogPage()
delete defaultFormat;
}
+void LogPage::on_InstanceLaunchTask_changed(std::shared_ptr<LaunchTask> proc)
+{
+ if(m_process)
+ {
+ disconnect(m_process.get(), &LaunchTask::log, this, &LogPage::write);
+ }
+ m_process = proc;
+ if(m_process)
+ {
+ ui->text->clear();
+ connect(m_process.get(), &LaunchTask::log, this, &LogPage::write);
+ }
+}
+
bool LogPage::apply()
{
return true;
@@ -69,7 +100,7 @@ bool LogPage::apply()
bool LogPage::shouldDisplay() const
{
- return m_process->instance()->isRunning();
+ return m_instance->isRunning() || ui->text->blockCount() > 1;
}
void LogPage::on_btnPaste_clicked()