2014-06-30 05:32:57 +05:30
|
|
|
#include "LogPage.h"
|
|
|
|
#include "ui_LogPage.h"
|
2014-07-12 21:28:23 +05:30
|
|
|
|
2014-11-10 00:18:35 +05:30
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2014-07-12 21:28:23 +05:30
|
|
|
#include <QIcon>
|
2014-06-30 05:32:57 +05:30
|
|
|
#include <QScrollBar>
|
2014-11-09 05:29:22 +05:30
|
|
|
#include <QShortcut>
|
2014-06-30 05:32:57 +05:30
|
|
|
|
2015-07-10 04:41:06 +05:30
|
|
|
#include "launch/LaunchTask.h"
|
2015-06-11 05:19:13 +05:30
|
|
|
#include <settings/Setting.h>
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "GuiUtil.h"
|
2015-08-20 05:19:03 +05:30
|
|
|
#include <ColorCache.h>
|
2014-07-12 21:28:23 +05:30
|
|
|
|
2015-07-10 04:41:06 +05:30
|
|
|
LogPage::LogPage(std::shared_ptr<LaunchTask> proc, QWidget *parent)
|
2014-06-30 05:32:57 +05:30
|
|
|
: QWidget(parent), ui(new Ui::LogPage), m_process(proc)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-07-21 03:40:13 +05:30
|
|
|
ui->tabWidget->tabBar()->hide();
|
2015-07-04 23:32:43 +05:30
|
|
|
connect(m_process.get(), SIGNAL(log(QString, MessageLevel::Enum)), this,
|
2014-11-09 05:29:22 +05:30
|
|
|
SLOT(write(QString, MessageLevel::Enum)));
|
|
|
|
|
2014-11-09 19:23:08 +05:30
|
|
|
// create the format and set its font
|
|
|
|
defaultFormat = new QTextCharFormat(ui->text->currentCharFormat());
|
2014-11-10 00:18:35 +05:30
|
|
|
QString fontFamily = MMC->settings()->get("ConsoleFont").toString();
|
2014-11-11 05:20:17 +05:30
|
|
|
bool conversionOk = false;
|
|
|
|
int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk);
|
|
|
|
if(!conversionOk)
|
|
|
|
{
|
|
|
|
fontSize = 11;
|
|
|
|
}
|
|
|
|
defaultFormat->setFont(QFont(fontFamily, fontSize));
|
2014-11-09 19:23:08 +05:30
|
|
|
|
2015-06-11 05:19:13 +05:30
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
ui->text->setMaximumBlockCount(maxLines);
|
|
|
|
|
2015-08-20 05:19:03 +05:30
|
|
|
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));
|
|
|
|
|
2015-06-11 05:19:13 +05:30
|
|
|
m_stopOnOverflow = MMC->settings()->get("ConsoleOverflowStop").toBool();
|
|
|
|
|
2014-11-09 05:29:22 +05:30
|
|
|
auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this);
|
|
|
|
connect(findShortcut, SIGNAL(activated()), SLOT(findActivated()));
|
|
|
|
auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this);
|
|
|
|
connect(findNextShortcut, SIGNAL(activated()), SLOT(findNextActivated()));
|
|
|
|
connect(ui->searchBar, SIGNAL(returnPressed()), SLOT(on_findButton_clicked()));
|
|
|
|
auto findPreviousShortcut = new QShortcut(QKeySequence(QKeySequence::FindPrevious), this);
|
|
|
|
connect(findPreviousShortcut, SIGNAL(activated()), SLOT(findPreviousActivated()));
|
2014-06-30 05:32:57 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
LogPage::~LogPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
2014-11-09 19:23:08 +05:30
|
|
|
delete defaultFormat;
|
2014-06-30 05:32:57 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool LogPage::apply()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-12 21:28:23 +05:30
|
|
|
bool LogPage::shouldDisplay() const
|
2014-06-30 05:32:57 +05:30
|
|
|
{
|
|
|
|
return m_process->instance()->isRunning();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::on_btnPaste_clicked()
|
|
|
|
{
|
2014-07-12 21:28:23 +05:30
|
|
|
GuiUtil::uploadPaste(ui->text->toPlainText(), this);
|
2014-06-30 05:32:57 +05:30
|
|
|
}
|
|
|
|
|
2014-07-11 05:20:36 +05:30
|
|
|
void LogPage::on_btnCopy_clicked()
|
|
|
|
{
|
2014-07-12 21:28:23 +05:30
|
|
|
GuiUtil::setClipboardText(ui->text->toPlainText());
|
2014-07-11 05:20:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::on_btnClear_clicked()
|
|
|
|
{
|
|
|
|
ui->text->clear();
|
|
|
|
}
|
|
|
|
|
2015-04-29 04:58:58 +05:30
|
|
|
void LogPage::on_btnBottom_clicked()
|
|
|
|
{
|
|
|
|
ui->text->verticalScrollBar()->setSliderPosition(ui->text->verticalScrollBar()->maximum());
|
|
|
|
}
|
|
|
|
|
2014-11-09 05:29:22 +05:30
|
|
|
void LogPage::on_trackLogCheckbox_clicked(bool checked)
|
|
|
|
{
|
|
|
|
m_write_active = checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::on_findButton_clicked()
|
|
|
|
{
|
|
|
|
auto modifiers = QApplication::keyboardModifiers();
|
|
|
|
if (modifiers & Qt::ShiftModifier)
|
|
|
|
{
|
|
|
|
findPreviousActivated();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
findNextActivated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::findActivated()
|
|
|
|
{
|
|
|
|
// focus the search bar if it doesn't have focus
|
|
|
|
if (!ui->searchBar->hasFocus())
|
|
|
|
{
|
|
|
|
auto searchForCursor = ui->text->textCursor();
|
|
|
|
auto searchForString = searchForCursor.selectedText();
|
|
|
|
if (searchForString.size())
|
|
|
|
{
|
|
|
|
ui->searchBar->setText(searchForString);
|
|
|
|
}
|
|
|
|
ui->searchBar->setFocus();
|
|
|
|
ui->searchBar->selectAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::findNextActivated()
|
|
|
|
{
|
|
|
|
auto toSearch = ui->searchBar->text();
|
|
|
|
if (toSearch.size())
|
|
|
|
{
|
|
|
|
ui->text->find(toSearch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::findPreviousActivated()
|
|
|
|
{
|
|
|
|
auto toSearch = ui->searchBar->text();
|
|
|
|
if (toSearch.size())
|
|
|
|
{
|
|
|
|
ui->text->find(toSearch, QTextDocument::FindBackward);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 05:19:13 +05:30
|
|
|
void LogPage::setParentContainer(BasePageContainer * container)
|
|
|
|
{
|
|
|
|
m_parentContainer = container;
|
|
|
|
}
|
|
|
|
|
2014-06-30 05:32:57 +05:30
|
|
|
void LogPage::write(QString data, MessageLevel::Enum mode)
|
|
|
|
{
|
2014-11-09 05:29:22 +05:30
|
|
|
if (!m_write_active)
|
|
|
|
{
|
2015-05-12 01:51:37 +05:30
|
|
|
if (mode != MessageLevel::MultiMC)
|
2014-11-09 05:29:22 +05:30
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-06-11 05:19:13 +05:30
|
|
|
if(m_stopOnOverflow && m_write_active)
|
|
|
|
{
|
2015-05-12 01:51:37 +05:30
|
|
|
if(mode != MessageLevel::MultiMC)
|
2015-06-11 05:19:13 +05:30
|
|
|
{
|
|
|
|
if(ui->text->blockCount() >= ui->text->maximumBlockCount())
|
|
|
|
{
|
|
|
|
m_write_active = false;
|
|
|
|
data = tr("MultiMC 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 loggging to files and"
|
|
|
|
" likely wasting harddrive space at an alarming rate!")
|
|
|
|
.arg(ui->text->maximumBlockCount());
|
|
|
|
mode = MessageLevel::Fatal;
|
|
|
|
ui->trackLogCheckbox->setCheckState(Qt::Unchecked);
|
|
|
|
if(!isVisible())
|
|
|
|
{
|
|
|
|
m_parentContainer->selectPage(id());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-09 05:29:22 +05:30
|
|
|
|
|
|
|
// save the cursor so it can be restored.
|
|
|
|
auto savedCursor = ui->text->cursor();
|
|
|
|
|
2014-06-30 05:32:57 +05:30
|
|
|
QScrollBar *bar = ui->text->verticalScrollBar();
|
|
|
|
int max_bar = bar->maximum();
|
|
|
|
int val_bar = bar->value();
|
2014-11-09 05:29:22 +05:30
|
|
|
if (isVisible())
|
2014-06-30 05:32:57 +05:30
|
|
|
{
|
|
|
|
if (m_scroll_active)
|
|
|
|
{
|
|
|
|
m_scroll_active = (max_bar - val_bar) <= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_scroll_active = val_bar == max_bar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data.endsWith('\n'))
|
|
|
|
data = data.left(data.length() - 1);
|
|
|
|
QStringList paragraphs = data.split('\n');
|
|
|
|
QStringList filtered;
|
|
|
|
for (QString ¶graph : paragraphs)
|
|
|
|
{
|
2014-11-09 05:29:22 +05:30
|
|
|
//TODO: implement filtering here.
|
2014-11-09 19:23:08 +05:30
|
|
|
filtered.append(paragraph);
|
2014-06-30 05:32:57 +05:30
|
|
|
}
|
|
|
|
QListIterator<QString> iter(filtered);
|
2014-11-09 19:23:08 +05:30
|
|
|
QTextCharFormat format(*defaultFormat);
|
|
|
|
|
2015-08-20 05:19:03 +05:30
|
|
|
format.setForeground(m_colors->getFront(mode));
|
|
|
|
format.setBackground(m_colors->getBack(mode));
|
2014-11-09 19:23:08 +05:30
|
|
|
|
|
|
|
while (iter.hasNext())
|
|
|
|
{
|
|
|
|
// append a paragraph/line
|
|
|
|
auto workCursor = ui->text->textCursor();
|
|
|
|
workCursor.movePosition(QTextCursor::End);
|
|
|
|
workCursor.insertText(iter.next(), format);
|
|
|
|
workCursor.insertBlock();
|
|
|
|
}
|
|
|
|
|
2014-11-09 05:29:22 +05:30
|
|
|
if (isVisible())
|
2014-06-30 05:32:57 +05:30
|
|
|
{
|
|
|
|
if (m_scroll_active)
|
|
|
|
{
|
|
|
|
bar->setValue(bar->maximum());
|
|
|
|
}
|
|
|
|
m_last_scroll_value = bar->value();
|
|
|
|
}
|
2014-11-09 05:29:22 +05:30
|
|
|
ui->text->setCursor(savedCursor);
|
2014-06-30 05:32:57 +05:30
|
|
|
}
|