summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/InstancePageProvider.h10
-rw-r--r--application/pages/OtherLogsPage.cpp128
-rw-r--r--application/pages/OtherLogsPage.h10
-rw-r--r--application/pages/OtherLogsPage.ui52
4 files changed, 161 insertions, 39 deletions
diff --git a/application/InstancePageProvider.h b/application/InstancePageProvider.h
index cff0b6d2..79bdb71b 100644
--- a/application/InstancePageProvider.h
+++ b/application/InstancePageProvider.h
@@ -41,12 +41,10 @@ public:
values.append(new NotesPage(onesix.get()));
values.append(new ScreenshotsPage(PathCombine(onesix->minecraftRoot(), "screenshots")));
values.append(new InstanceSettingsPage(onesix.get()));
- values.append(new OtherLogsPage(onesix->minecraftRoot()));
}
std::shared_ptr<LegacyInstance> legacy = std::dynamic_pointer_cast<LegacyInstance>(inst);
if(legacy)
{
- QList<BasePage *> values;
// FIXME: actually implement the legacy instance upgrade, then enable this.
//values.append(new LegacyUpgradePage(this));
values.append(new LegacyJarModPage(legacy.get()));
@@ -58,8 +56,12 @@ public:
values.append(new NotesPage(legacy.get()));
values.append(new ScreenshotsPage(PathCombine(legacy->minecraftRoot(), "screenshots")));
values.append(new InstanceSettingsPage(legacy.get()));
- values.append(new OtherLogsPage(legacy->minecraftRoot()));
- return values;
+ values.append(new OtherLogsPage(legacy->minecraftRoot(), inst->getLogFileMatcher()));
+ }
+ auto logMatcher = inst->getLogFileMatcher();
+ if(logMatcher)
+ {
+ values.append(new OtherLogsPage(onesix->minecraftRoot(), logMatcher));
}
return values;
}
diff --git a/application/pages/OtherLogsPage.cpp b/application/pages/OtherLogsPage.cpp
index 2f9a800c..d59f0451 100644
--- a/application/pages/OtherLogsPage.cpp
+++ b/application/pages/OtherLogsPage.cpp
@@ -20,20 +20,20 @@
#include "GuiUtil.h"
#include "RecursiveFileSystemWatcher.h"
+#include <GZip.h>
#include <pathutils.h>
-OtherLogsPage::OtherLogsPage(QString path, QWidget *parent)
- : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path),
+OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent)
+ : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter),
m_watcher(new RecursiveFileSystemWatcher(this))
{
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
- m_watcher->setFileExpression("(.*\\.log(\\.[0-9]*)?$)|(crash-.*\\.txt)");
+ m_watcher->setMatcher(fileFilter);
m_watcher->setRootDir(QDir::current().absoluteFilePath(m_path));
- connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, this,
- &OtherLogsPage::populateSelectLogBox);
+ connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, this, &OtherLogsPage::populateSelectLogBox);
populateSelectLogBox();
}
@@ -55,15 +55,23 @@ void OtherLogsPage::populateSelectLogBox()
{
ui->selectLogBox->clear();
ui->selectLogBox->addItems(m_watcher->files());
- if (m_currentFile.isNull())
+ if (m_currentFile.isEmpty())
{
+ setControlsEnabled(false);
ui->selectLogBox->setCurrentIndex(-1);
}
else
{
const int index = ui->selectLogBox->findText(m_currentFile);
if (index != -1)
+ {
ui->selectLogBox->setCurrentIndex(index);
+ setControlsEnabled(true);
+ }
+ else
+ {
+ setControlsEnabled(false);
+ }
}
}
@@ -91,6 +99,11 @@ void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index)
void OtherLogsPage::on_btnReload_clicked()
{
+ if(m_currentFile.isEmpty())
+ {
+ setControlsEnabled(false);
+ return;
+ }
QFile file(PathCombine(m_path, m_currentFile));
if (!file.open(QFile::ReadOnly))
{
@@ -102,16 +115,39 @@ void OtherLogsPage::on_btnReload_clicked()
}
else
{
- if (file.size() < 10000000ll)
- {
- ui->text->setPlainText(QString::fromUtf8(file.readAll()));
- }
- else
+ auto showTooBig = [&]()
{
ui->text->setPlainText(
tr("The file (%1) is too big. You may want to open it in a viewer optimized "
"for large files.").arg(file.fileName()));
+ };
+ if(file.size() >= 10000000ll)
+ {
+ showTooBig();
+ return;
}
+ QString content;
+ if(file.fileName().endsWith(".gz"))
+ {
+ QByteArray temp;
+ if(!GZip::inflate(file.readAll(), temp))
+ {
+ ui->text->setPlainText(
+ tr("The file (%1) is not readable.").arg(file.fileName()));
+ return;
+ }
+ content = QString::fromUtf8(temp);
+ }
+ else
+ {
+ content = QString::fromUtf8(file.readAll());
+ }
+ if (content.size() >= 50000000ll)
+ {
+ showTooBig();
+ return;
+ }
+ ui->text->setPlainText(content);
}
}
@@ -119,12 +155,19 @@ void OtherLogsPage::on_btnPaste_clicked()
{
GuiUtil::uploadPaste(ui->text->toPlainText(), this);
}
+
void OtherLogsPage::on_btnCopy_clicked()
{
GuiUtil::setClipboardText(ui->text->toPlainText());
}
+
void OtherLogsPage::on_btnDelete_clicked()
{
+ if(m_currentFile.isEmpty())
+ {
+ setControlsEnabled(false);
+ return;
+ }
if (QMessageBox::question(this, tr("Delete"),
tr("Do you really want to delete %1?").arg(m_currentFile),
QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
@@ -139,6 +182,68 @@ void OtherLogsPage::on_btnDelete_clicked()
}
}
+
+
+void OtherLogsPage::on_btnClean_clicked()
+{
+ auto toDelete = m_watcher->files();
+ if(toDelete.isEmpty())
+ {
+ return;
+ }
+ QMessageBox *messageBox = new QMessageBox(this);
+ messageBox->setWindowTitle(tr("Clean up"));
+ if(toDelete.size() > 5)
+ {
+ messageBox->setText(tr("Do you really want to delete all log files?"));
+ messageBox->setDetailedText(toDelete.join('\n'));
+ }
+ else
+ {
+ messageBox->setText(tr("Do you really want to these files?\n%1").arg(toDelete.join('\n')));
+ }
+ messageBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ messageBox->setDefaultButton(QMessageBox::Ok);
+ messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ messageBox->setIcon(QMessageBox::Question);
+ messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction);
+
+ if (messageBox->exec() != QMessageBox::Ok)
+ {
+ return;
+ }
+ QStringList failed;
+ for(auto item: toDelete)
+ {
+ QFile file(PathCombine(m_path, item));
+ if (!file.remove())
+ {
+ failed.push_back(item);
+ }
+ }
+ if(!failed.empty())
+ {
+ QMessageBox *messageBox = new QMessageBox(this);
+ messageBox->setWindowTitle(tr("Error"));
+ if(failed.size() > 5)
+ {
+ messageBox->setText(tr("Couldn't delete some files!"));
+ messageBox->setDetailedText(failed.join('\n'));
+ }
+ else
+ {
+ messageBox->setText(tr("Couldn't delete some files:\n%1").arg(failed.join('\n')));
+ }
+ messageBox->setStandardButtons(QMessageBox::Ok);
+ messageBox->setDefaultButton(QMessageBox::Ok);
+ messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ messageBox->setIcon(QMessageBox::Critical);
+ messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ messageBox->exec();
+ }
+}
+
+
void OtherLogsPage::setControlsEnabled(const bool enabled)
{
ui->btnReload->setEnabled(enabled);
@@ -146,4 +251,5 @@ void OtherLogsPage::setControlsEnabled(const bool enabled)
ui->btnCopy->setEnabled(enabled);
ui->btnPaste->setEnabled(enabled);
ui->text->setEnabled(enabled);
+ ui->btnClean->setEnabled(enabled);
}
diff --git a/application/pages/OtherLogsPage.h b/application/pages/OtherLogsPage.h
index d6e4ec9f..9a5a6ed4 100644
--- a/application/pages/OtherLogsPage.h
+++ b/application/pages/OtherLogsPage.h
@@ -19,6 +19,7 @@
#include "BasePage.h"
#include <MultiMC.h>
+#include <pathmatcher/IPathMatcher.h>
namespace Ui
{
@@ -32,7 +33,7 @@ class OtherLogsPage : public QWidget, public BasePage
Q_OBJECT
public:
- explicit OtherLogsPage(QString path, QWidget *parent = 0);
+ explicit OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent = 0);
~OtherLogsPage();
QString id() const override
@@ -61,12 +62,15 @@ private slots:
void on_btnPaste_clicked();
void on_btnCopy_clicked();
void on_btnDelete_clicked();
+ void on_btnClean_clicked();
+
+private:
+ void setControlsEnabled(const bool enabled);
private:
Ui::OtherLogsPage *ui;
QString m_path;
RecursiveFileSystemWatcher *m_watcher;
QString m_currentFile;
-
- void setControlsEnabled(const bool enabled);
+ IPathMatcher::Ptr m_fileFilter;
};
diff --git a/application/pages/OtherLogsPage.ui b/application/pages/OtherLogsPage.ui
index 08200684..755de6df 100644
--- a/application/pages/OtherLogsPage.ui
+++ b/application/pages/OtherLogsPage.ui
@@ -37,35 +37,28 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QComboBox" name="selectLogBox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="3" column="1">
+ <widget class="QPushButton" name="btnCopy">
+ <property name="toolTip">
+ <string>Copy the whole log into the clipboard</string>
</property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="btnReload">
<property name="text">
- <string>Reload</string>
+ <string>&amp;Copy</string>
</property>
</widget>
</item>
- <item>
- <widget class="QPushButton" name="btnCopy">
+ <item row="3" column="3">
+ <widget class="QPushButton" name="btnDelete">
<property name="toolTip">
- <string>Copy the whole log into the clipboard</string>
+ <string>Clear the log</string>
</property>
<property name="text">
- <string>&amp;Copy</string>
+ <string>Delete</string>
</property>
</widget>
</item>
- <item>
+ <item row="3" column="2">
<widget class="QPushButton" name="btnPaste">
<property name="toolTip">
<string>Upload the log to paste.ee - it will stay online for a month</string>
@@ -75,13 +68,30 @@
</property>
</widget>
</item>
- <item>
- <widget class="QPushButton" name="btnDelete">
+ <item row="3" column="0">
+ <widget class="QPushButton" name="btnReload">
+ <property name="text">
+ <string>Reload</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" colspan="5">
+ <widget class="QComboBox" name="selectLogBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="4">
+ <widget class="QPushButton" name="btnClean">
<property name="toolTip">
<string>Clear the log</string>
</property>
<property name="text">
- <string>Delete</string>
+ <string>Clean</string>
</property>
</widget>
</item>