summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-07-20 05:34:31 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-07-22 07:39:53 -0400
commit3c7712a32dd5079a9543485b6a85d548460faefd (patch)
tree17df829b4e6f4a96f2567381adca29b8cd45e9a0 /src
parent5304d52f9373e0078674af79b656e2e4d010ca90 (diff)
moved setLogLevel() to OrganizerCore
moved context menu to LogList
Diffstat (limited to 'src')
-rw-r--r--src/loglist.cpp61
-rw-r--r--src/loglist.h16
-rw-r--r--src/mainwindow.cpp57
-rw-r--r--src/mainwindow.h4
-rw-r--r--src/mainwindow.ui14
-rw-r--r--src/organizercore.cpp12
-rw-r--r--src/organizercore.h2
7 files changed, 78 insertions, 88 deletions
diff --git a/src/loglist.cpp b/src/loglist.cpp
index c34ac76e..26aea682 100644
--- a/src/loglist.cpp
+++ b/src/loglist.cpp
@@ -18,14 +18,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "loglist.h"
-#include <scopeguard.h>
-#include <report.h>
-#include <log.h>
-#include <QMutexLocker>
-#include <QFile>
-#include <QIcon>
-#include <QDateTime>
-#include <Windows.h>
+#include "organizercore.h"
using namespace MOBase;
@@ -158,7 +151,7 @@ QVariant LogModel::headerData(int, Qt::Orientation, int) const
LogList::LogList(QWidget* parent)
- : QTreeView(parent)
+ : QTreeView(parent), m_core(nullptr)
{
setModel(&LogModel::instance());
@@ -172,6 +165,10 @@ LogList::LogList(QWidget* parent)
scrollToBottom();
connect(
+ this, &QWidget::customContextMenuRequested,
+ [&](auto&& pos){ onContextMenu(pos); });
+
+ connect(
model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(scrollToBottom()));
@@ -180,6 +177,11 @@ LogList::LogList(QWidget* parent)
this, SLOT(scrollToBottom()));
}
+void LogList::setCore(OrganizerCore& core)
+{
+ m_core = &core;
+}
+
void LogList::copyToClipboard()
{
std::string s;
@@ -196,3 +198,44 @@ void LogList::copyToClipboard()
QApplication::clipboard()->setText(QString::fromStdString(s));
}
+
+QMenu* LogList::createMenu(QWidget* parent)
+{
+ auto* menu = new QMenu(parent);
+
+ menu->addAction(tr("Copy& Log"), [&]{ copyToClipboard(); });
+ menu->addSeparator();
+
+ auto* levels = new QMenu(tr("&Level"));
+ menu->addMenu(levels);
+
+ auto* ag = new QActionGroup(menu);
+
+ auto addAction = [&](auto&& text, auto&& level) {
+ auto* a = new QAction(text, ag);
+
+ a->setCheckable(true);
+ a->setChecked(log::getDefault().level() == level);
+
+ connect(a, &QAction::triggered, [this, level]{
+ if (m_core) {
+ m_core->setLogLevel(level);
+ }
+ });
+
+ levels->addAction(a);
+ };
+
+ addAction(tr("&Debug"), log::Debug);
+ addAction(tr("&Info"), log::Info);
+ addAction(tr("&Warnings"), log::Warning);
+ addAction(tr("&Errors"), log::Error);
+
+ return menu;
+}
+
+void LogList::onContextMenu(const QPoint& pos)
+{
+ auto* menu = createMenu(this);
+ menu->popup(viewport()->mapToGlobal(pos));
+}
diff --git a/src/loglist.h b/src/loglist.h
index d1f7a2ad..ae827ca7 100644
--- a/src/loglist.h
+++ b/src/loglist.h
@@ -20,14 +20,11 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#ifndef LOGBUFFER_H
#define LOGBUFFER_H
-#include <QObject>
-#include <QMutex>
-#include <QScopedPointer>
-#include <QStringListModel>
-#include <QTime>
-#include <vector>
+#include <QTreeView>
#include <log.h>
+class OrganizerCore;
+
class LogModel : public QAbstractItemModel
{
Q_OBJECT
@@ -65,7 +62,14 @@ class LogList : public QTreeView
public:
LogList(QWidget* parent=nullptr);
+ void setCore(OrganizerCore& core);
+
void copyToClipboard();
+ QMenu* createMenu(QWidget* parent=nullptr);
+
+private:
+ OrganizerCore* m_core;
+ void onContextMenu(const QPoint& pos);
};
#endif // LOGBUFFER_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 8a8a99ef..761e9843 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -59,7 +59,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "installationmanager.h"
#include "lockeddialog.h"
#include "waitingonclosedialog.h"
-#include "loglist.h"
#include "downloadlistsortproxy.h"
#include "motddialog.h"
#include "filedialogmemory.h"
@@ -358,7 +357,7 @@ MainWindow::MainWindow(QSettings &initSettings
m_CategoryFactory.loadCategories();
- setupLogMenu();
+ ui->logList->setCore(m_OrganizerCore);
int splitterSize = this->size().height(); // actually total window size, but the splitter doesn't seem to return the true value
ui->topLevelSplitter->setSizes(QList<int>() << splitterSize - 100 << 100);
@@ -813,36 +812,6 @@ void MainWindow::setupActionMenu(QAction* a)
tb->setPopupMode(QToolButton::InstantPopup);
}
-void MainWindow::setupLogMenu()
-{
- connect(ui->logList, &QWidget::customContextMenuRequested, [&](auto&& pos){
- auto* menu = new QMenu(ui->logList);
-
- menu->addAction(tr("Copy& Log"), [&]{ ui->logList->copyToClipboard(); });
- menu->addSeparator();
-
- auto* levels = new QMenu(tr("&Level"));
- menu->addMenu(levels);
-
- auto* ag = new QActionGroup(menu);
-
- auto addAction = [&](auto&& text, auto&& level) {
- auto* a = new QAction(text, ag);
- a->setCheckable(true);
- a->setChecked(log::getDefault().level() == level);
- connect(a, &QAction::triggered, [this, level]{ setLogLevel(level); });
- levels->addAction(a);
- };
-
- addAction(tr("&Debug"), log::Debug);
- addAction(tr("&Info"), log::Info);
- addAction(tr("&Warnings"), log::Warning);
- addAction(tr("&Errors"), log::Error);
-
- menu->popup(ui->logList->viewport()->mapToGlobal(pos));
- });
-}
-
void MainWindow::updatePinnedExecutables()
{
for (auto* a : ui->toolBar->actions()) {
@@ -1432,11 +1401,6 @@ bool MainWindow::confirmExit()
void MainWindow::cleanup()
{
- if (ui->logList->model() != nullptr) {
- disconnect(ui->logList->model(), nullptr, nullptr, nullptr);
- ui->logList->setModel(nullptr);
- }
-
QWebEngineProfile::defaultProfile()->clearAllVisitedLinks();
m_IntegratedBrowser.close();
m_SaveMetaTimer.stop();
@@ -5317,24 +5281,12 @@ void MainWindow::on_actionSettings_triggered()
m_statusBar->checkSettings(m_OrganizerCore.settings());
updateDownloadView();
- setLogLevel(settings.logLevel());
+ m_OrganizerCore.setLogLevel(settings.logLevel());
m_OrganizerCore.cycleDiagnostics();
toggleMO2EndorseState();
}
-void MainWindow::setLogLevel(log::Levels level)
-{
- auto& s = m_OrganizerCore.settings();
-
- s.setLogLevel(level);
-
- m_OrganizerCore.updateVFSParams(
- s.logLevel(), s.crashDumpsType(), s.executablesBlacklist());
-
- log::getDefault().setLevel(s.logLevel());
-}
-
void MainWindow::on_actionNexus_triggered()
{
const IPluginGame *game = m_OrganizerCore.managedGame();
@@ -6858,11 +6810,6 @@ void MainWindow::on_restoreModsButton_clicked()
}
}
-void MainWindow::on_actionLogCopy_triggered()
-{
- ui->logList->copyToClipboard();
-}
-
void MainWindow::on_categoriesAndBtn_toggled(bool checked)
{
if (checked) {
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 74993667..aa49205d 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -636,13 +636,10 @@ private slots:
void search_activated();
void searchClear_activated();
- void setupLogMenu();
void resetActionIcons();
void updateModCount();
void updatePluginCount();
- void setLogLevel(MOBase::log::Levels level);
-
private slots: // ui slots
// actions
void on_actionAdd_Profile_triggered();
@@ -696,7 +693,6 @@ private slots: // ui slots
void on_restoreButton_clicked();
void on_restoreModsButton_clicked();
void on_saveModsButton_clicked();
- void on_actionLogCopy_triggered();
void on_categoriesAndBtn_toggled(bool checked);
void on_categoriesOrBtn_toggled(bool checked);
void on_managedArchiveLabel_linkHovered(const QString &link);
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index fc2bcdd3..6c6d0bca 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -1757,20 +1757,6 @@ p, li { white-space: pre-wrap; }
<string>Log</string>
</property>
</action>
- <action name="actionLogCopy">
- <property name="text">
- <string>Copy &amp;Log</string>
- </property>
- <property name="iconText">
- <string>Copy &amp;Log</string>
- </property>
- <property name="toolTip">
- <string>Copy log to clipboard</string>
- </property>
- <property name="statusTip">
- <string>Copy log to clipboard</string>
- </property>
- </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 92372d82..1e164525 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -731,6 +731,18 @@ void OrganizerCore::updateVFSParams(
m_USVFS.updateParams(logLevel, crashDumpsType, executableBlacklist);
}
+void OrganizerCore::setLogLevel(log::Levels level)
+{
+ m_Settings.setLogLevel(level);
+
+ updateVFSParams(
+ m_Settings.logLevel(),
+ m_Settings.crashDumpsType(),
+ m_Settings.executablesBlacklist());
+
+ log::getDefault().setLevel(m_Settings.logLevel());
+}
+
bool OrganizerCore::cycleDiagnostics() {
if (int maxDumps = settings().crashDumpsMax())
removeOldFiles(QString::fromStdWString(crashDumpsPath()), "*.dmp", maxDumps, QDir::Time|QDir::Reversed);
diff --git a/src/organizercore.h b/src/organizercore.h
index c368d101..2aa7e707 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -196,6 +196,8 @@ public:
MOBase::log::Levels logLevel, int crashDumpsType,
QString executableBlacklist);
+ void setLogLevel(MOBase::log::Levels level);
+
bool cycleDiagnostics();
static CrashDumpsType getGlobalCrashDumpsType() { return m_globalCrashDumpsType; }