summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-07-17 08:56:16 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-07-22 07:33:37 -0400
commitbca6283311cf1dea4c96f8ee5bf192bdb1640cb3 (patch)
tree7a6b0445974a974bf4b03d08d4ac9371de0ea663
parentd1b4dec8ad1635738ada3dfbde5907e7f0df3448 (diff)
use log::Levels instead of ints
create log level combobox in code, set selected index based on value instead added log level to context menu in log list
-rw-r--r--src/mainwindow.cpp47
-rw-r--r--src/mainwindow.h12
-rw-r--r--src/mainwindow.ui30
-rw-r--r--src/organizercore.cpp4
-rw-r--r--src/organizercore.h5
-rw-r--r--src/settings.cpp30
-rw-r--r--src/settings.h10
-rw-r--r--src/settingsdialog.ui20
-rw-r--r--src/usvfsconnector.cpp20
-rw-r--r--src/usvfsconnector.h7
10 files changed, 127 insertions, 58 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 4e91ef9f..f65bf4e1 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -357,7 +357,7 @@ MainWindow::MainWindow(QSettings &initSettings
m_CategoryFactory.loadCategories();
- ui->logList->addAction(ui->actionCopy_Log_to_Clipboard);
+ setupLogMenu();
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);
@@ -812,6 +812,36 @@ 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("&Errors"), log::Error);
+ addAction(tr("&Warnings"), log::Warning);
+ addAction(tr("&Info"), log::Info);
+ addAction(tr("&Debug"), log::Debug);
+
+ menu->popup(ui->logList->viewport()->mapToGlobal(pos));
+ });
+}
+
void MainWindow::updatePinnedExecutables()
{
for (auto* a : ui->toolBar->actions()) {
@@ -5287,12 +5317,23 @@ void MainWindow::on_actionSettings_triggered()
m_statusBar->checkSettings(m_OrganizerCore.settings());
updateDownloadView();
- m_OrganizerCore.updateVFSParams(settings.logLevel(), settings.crashDumpsType(), settings.executablesBlacklist());
+ 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()
{
@@ -6811,7 +6852,7 @@ void MainWindow::on_restoreModsButton_clicked()
}
}
-void MainWindow::on_actionCopy_Log_to_Clipboard_triggered()
+void MainWindow::on_actionLogCopy_triggered()
{
ui->logList->copyToClipboard();
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index d7dbfd90..74993667 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -30,6 +30,9 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "modlistsortproxy.h"
#include "savegameinfo.h"
#include "tutorialcontrol.h"
+#include "plugincontainer.h" //class PluginContainer;
+#include "iplugingame.h" //namespace MOBase { class IPluginGame; }
+#include <log.h>
//Note the commented headers here can be replaced with forward references,
//when I get round to cleaning up main.cpp
@@ -38,10 +41,10 @@ class CategoryFactory;
class LockedDialogBase;
class OrganizerCore;
class StatusBar;
-#include "plugincontainer.h" //class PluginContainer;
+
class PluginListSortProxy;
namespace BSA { class Archive; }
-#include "iplugingame.h" //namespace MOBase { class IPluginGame; }
+
namespace MOBase { class IPluginModPage; }
namespace MOBase { class IPluginTool; }
namespace MOBase { class ISaveGame; }
@@ -633,10 +636,13 @@ 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();
@@ -690,7 +696,7 @@ private slots: // ui slots
void on_restoreButton_clicked();
void on_restoreModsButton_clicked();
void on_saveModsButton_clicked();
- void on_actionCopy_Log_to_Clipboard_triggered();
+ 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 c694abd4..fc2bcdd3 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -1428,7 +1428,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="LogList" name="logList">
<property name="contextMenuPolicy">
- <enum>Qt::ActionsContextMenu</enum>
+ <enum>Qt::CustomContextMenu</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
@@ -1645,20 +1645,6 @@ p, li { white-space: pre-wrap; }
<string>Endorse Mod Organizer</string>
</property>
</action>
- <action name="actionCopy_Log_to_Clipboard">
- <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>
<action name="actionChange_Game">
<property name="icon">
<iconset resource="resources.qrc">
@@ -1771,6 +1757,20 @@ 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 d3cd54ee..25fbc7cd 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -726,7 +726,9 @@ void OrganizerCore::prepareVFS()
m_USVFS.updateMapping(fileMapping(m_CurrentProfile->name(), QString()));
}
-void OrganizerCore::updateVFSParams(int logLevel, int crashDumpsType, QString executableBlacklist) {
+void OrganizerCore::updateVFSParams(
+ log::Levels logLevel, int crashDumpsType, QString executableBlacklist)
+{
setGlobalCrashDumpsType(crashDumpsType);
m_USVFS.updateParams(logLevel, crashDumpsType, executableBlacklist);
}
diff --git a/src/organizercore.h b/src/organizercore.h
index 99b1c5f2..ef1a4133 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -21,6 +21,7 @@
#include <delayedfilewriter.h>
#include <boost/signals2.hpp>
#include "executableinfo.h"
+#include <log.h>
class ModListSortProxy;
class PluginListSortProxy;
@@ -191,7 +192,9 @@ public:
void prepareVFS();
- void updateVFSParams(int logLevel, int crashDumpsType, QString executableBlacklist);
+ void updateVFSParams(
+ MOBase::log::Levels logLevel, int crashDumpsType,
+ QString executableBlacklist);
bool cycleDiagnostics();
diff --git a/src/settings.cpp b/src/settings.cpp
index 5cb2524f..e622d632 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -415,9 +415,14 @@ bool Settings::offlineMode() const
return m_Settings.value("Settings/offline_mode", false).toBool();
}
-int Settings::logLevel() const
+log::Levels Settings::logLevel() const
{
- return m_Settings.value("Settings/log_level", static_cast<int>(LogLevel::Info)).toInt();
+ return static_cast<log::Levels>(m_Settings.value("Settings/log_level").toInt());
+}
+
+void Settings::setLogLevel(log::Levels level)
+{
+ m_Settings.setValue("Settings/log_level", static_cast<int>(level));
}
int Settings::crashDumpsType() const
@@ -1000,7 +1005,7 @@ Settings::DiagnosticsTab::DiagnosticsTab(Settings *m_parent, SettingsDialog &m_d
, m_dumpsMaxEdit(m_dialog.findChild<QSpinBox *>("dumpsMaxEdit"))
, m_diagnosticsExplainedLabel(m_dialog.findChild<QLabel *>("diagnosticsExplainedLabel"))
{
- m_logLevelBox->setCurrentIndex(m_parent->logLevel());
+ setLevelsBox();
m_dumpsTypeBox->setCurrentIndex(m_parent->crashDumpsType());
m_dumpsMaxEdit->setValue(m_parent->crashDumpsMax());
QString logsPath = qApp->property("dataPath").toString()
@@ -1016,11 +1021,28 @@ Settings::DiagnosticsTab::DiagnosticsTab(Settings *m_parent, SettingsDialog &m_d
void Settings::DiagnosticsTab::update()
{
- m_Settings.setValue("Settings/log_level", m_logLevelBox->currentIndex());
+ m_Settings.setValue("Settings/log_level", m_logLevelBox->currentData().toInt());
m_Settings.setValue("Settings/crash_dumps_type", m_dumpsTypeBox->currentIndex());
m_Settings.setValue("Settings/crash_dumps_max", m_dumpsMaxEdit->value());
}
+void Settings::DiagnosticsTab::setLevelsBox()
+{
+ m_logLevelBox->clear();
+
+ m_logLevelBox->addItem(tr("Debug"), log::Debug);
+ m_logLevelBox->addItem(tr("Info (recommended)"), log::Info);
+ m_logLevelBox->addItem(tr("Warning"), log::Warning);
+ m_logLevelBox->addItem(tr("Error"), log::Error);
+
+ for (int i=0; i<m_logLevelBox->count(); ++i) {
+ if (m_logLevelBox->itemData(i) == m_parent->logLevel()) {
+ m_logLevelBox->setCurrentIndex(i);
+ break;
+ }
+ }
+}
+
Settings::NexusTab::NexusTab(Settings *parent, SettingsDialog &dialog)
: Settings::SettingsTab(parent, dialog)
, m_offlineBox(dialog.findChild<QCheckBox *>("offlineBox"))
diff --git a/src/settings.h b/src/settings.h
index bccd1e81..c66eb94c 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -21,6 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#define SETTINGS_H
#include "loadmechanism.h"
+#include <log.h>
#include <QList>
#include <QMap>
@@ -232,7 +233,12 @@ public:
/**
* @return the configured log level
*/
- int logLevel() const;
+ MOBase::log::Levels logLevel() const;
+
+ /**
+ * sets the log level setting
+ */
+ void setLogLevel(MOBase::log::Levels level);
/**
* @return the configured crash dumps type
@@ -481,6 +487,8 @@ private:
QComboBox *m_dumpsTypeBox;
QSpinBox *m_dumpsMaxEdit;
QLabel *m_diagnosticsExplainedLabel;
+
+ void setLevelsBox();
};
/** Display/store the configuration in the 'nexus' tab of the settings dialogue */
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui
index fccc8be0..1e94bcde 100644
--- a/src/settingsdialog.ui
+++ b/src/settingsdialog.ui
@@ -1426,26 +1426,6 @@ programs you are intentionally running.</string>
&quot;Debug&quot; produces very useful information for finding problems. There is usually no noteworthy performance impact but the file may become rather large. If this is a problem you may prefer the &quot;Info&quot; level for regular use. On the &quot;Error&quot; level the log file usually remains empty.
</string>
</property>
- <item>
- <property name="text">
- <string>Debug</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Info (recommended)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Warning</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Error</string>
- </property>
- </item>
</widget>
</item>
</layout>
diff --git a/src/usvfsconnector.cpp b/src/usvfsconnector.cpp
index b752667d..197955b8 100644
--- a/src/usvfsconnector.cpp
+++ b/src/usvfsconnector.cpp
@@ -32,7 +32,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <qstandardpaths.h>
static const char SHMID[] = "mod_organizer_instance";
-
+using namespace MOBase;
std::string to_hex(void *bufferIn, size_t bufferSize)
{
@@ -90,15 +90,16 @@ void LogWorker::exit()
m_QuitRequested = true;
}
-LogLevel logLevel(int level)
+LogLevel toUsvfsLogLevel(log::Levels level)
{
- switch (static_cast<LogLevel>(level)) {
- case LogLevel::Info:
+ switch (level) {
+ case log::Info:
return LogLevel::Info;
- case LogLevel::Warning:
+ case log::Warning:
return LogLevel::Warning;
- case LogLevel::Error:
+ case log::Error:
return LogLevel::Error;
+ case log::Debug: // fall-through
default:
return LogLevel::Debug;
}
@@ -121,7 +122,7 @@ CrashDumpsType crashDumpsType(int type)
UsvfsConnector::UsvfsConnector()
{
USVFSParameters params;
- LogLevel level = logLevel(Settings::instance().logLevel());
+ LogLevel level = toUsvfsLogLevel(Settings::instance().logLevel());
CrashDumpsType dumpType = crashDumpsType(Settings::instance().crashDumpsType());
std::string dumpPath = MOShared::ToString(OrganizerCore::crashDumpsPath(), true);
@@ -205,9 +206,10 @@ void UsvfsConnector::updateMapping(const MappingType &mapping)
*/
}
-void UsvfsConnector::updateParams(int logLevel, int crashDumpsType, QString executableBlacklist)
+void UsvfsConnector::updateParams(
+ MOBase::log::Levels logLevel, int crashDumpsType, QString executableBlacklist)
{
- USVFSUpdateParams(::logLevel(logLevel), ::crashDumpsType(crashDumpsType));
+ USVFSUpdateParams(toUsvfsLogLevel(logLevel), ::crashDumpsType(crashDumpsType));
ClearExecutableBlacklist();
for (auto exec : executableBlacklist.split(";")) {
std::wstring buf = exec.toStdWString();
diff --git a/src/usvfsconnector.h b/src/usvfsconnector.h
index 8a88bde5..b0bd320c 100644
--- a/src/usvfsconnector.h
+++ b/src/usvfsconnector.h
@@ -29,6 +29,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QDebug>
#include <QList>
#include <usvfsparameters.h>
+#include <log.h>
#include "executableinfo.h"
@@ -84,7 +85,11 @@ public:
~UsvfsConnector();
void updateMapping(const MappingType &mapping);
- void updateParams(int logLevel, int crashDumpsType, QString executableBlacklist);
+
+ void updateParams(
+ MOBase::log::Levels logLevel, int crashDumpsType,
+ QString executableBlacklist);
+
void updateForcedLibraries(const QList<MOBase::ExecutableForcedLoadSetting> &forcedLibraries);
private: