Explorar o código

frontend: Use signal to update log viewer

Instead of calling the log viewer directly, use a signal instead.
cg2121 hai 8 meses
pai
achega
4b403d2a3e
Modificáronse 4 ficheiros con 13 adicións e 12 borrados
  1. 5 2
      frontend/OBSApp.cpp
  2. 2 0
      frontend/OBSApp.hpp
  3. 2 4
      frontend/dialogs/OBSLogViewer.cpp
  4. 4 6
      frontend/obs-main.cpp

+ 5 - 2
frontend/OBSApp.cpp

@@ -74,8 +74,6 @@ extern bool opt_disable_missing_files_check;
 extern string opt_starting_collection;
 extern string opt_starting_profile;
 
-extern QPointer<OBSLogViewer> obsLogViewer;
-
 #ifndef _WIN32
 int OBSApp::sigintFd[2];
 #endif
@@ -1757,3 +1755,8 @@ void OBSApp::applicationShutdown() noexcept
 		libobs_initialized = false;
 	}
 }
+
+void OBSApp::addLogLine(int logLevel, const QString &message)
+{
+	emit logLineAdded(logLevel, message);
+}

+ 2 - 0
frontend/OBSApp.hpp

@@ -119,6 +119,7 @@ private slots:
 #endif
 
 private slots:
+	void addLogLine(int logLevel, const QString &message);
 	void themeFileChanged(const QString &);
 	void applicationShutdown() noexcept;
 
@@ -212,6 +213,7 @@ public slots:
 	void ProcessSigInt();
 
 signals:
+	void logLineAdded(int logLevel, const QString &message);
 	void StyleChanged();
 
 	void logUploadFinished(OBS::LogFileType, const QString &fileUrl);

+ 2 - 4
frontend/dialogs/OBSLogViewer.cpp

@@ -29,6 +29,8 @@ OBSLogViewer::OBSLogViewer(QWidget *parent) : QDialog(parent), ui(new Ui::OBSLog
 	}
 
 	InitLog();
+
+	connect(App(), &OBSApp::logLineAdded, this, &OBSLogViewer::AddLine);
 }
 
 OBSLogViewer::~OBSLogViewer()
@@ -41,8 +43,6 @@ void OBSLogViewer::on_showStartup_clicked(bool checked)
 	config_set_bool(App()->GetUserConfig(), "LogViewer", "ShowLogStartup", checked);
 }
 
-extern QPointer<OBSLogViewer> obsLogViewer;
-
 void OBSLogViewer::InitLog()
 {
 	char logDir[512];
@@ -74,8 +74,6 @@ void OBSLogViewer::InitLog()
 	}
 	QScrollBar *scroll = ui->textArea->verticalScrollBar();
 	scroll->setValue(scroll->maximum());
-
-	obsLogViewer = this;
 }
 
 void OBSLogViewer::AddLine(int type, const QString &str)

+ 4 - 6
frontend/obs-main.cpp

@@ -16,7 +16,6 @@
 ******************************************************************************/
 
 #include <OBSApp.hpp>
-#include <dialogs/OBSLogViewer.hpp>
 #ifdef __APPLE__
 #include <dialogs/OBSPermissions.hpp>
 #endif
@@ -33,7 +32,9 @@
 #include <util/windows/win-version.h>
 #endif
 
+#include <QFontDatabase>
 #include <QProcess>
+#include <QPushButton>
 #include <curl/curl.h>
 
 #include <fstream>
@@ -80,8 +81,6 @@ bool restart = false;
 bool restart_safe = false;
 static QStringList arguments;
 
-QPointer<OBSLogViewer> obsLogViewer;
-
 string CurrentTimeString()
 {
 	using namespace std::chrono;
@@ -115,9 +114,8 @@ static void LogString(fstream &logFile, const char *timeString, char *str, int l
 	logFile << msg << endl;
 	logfile_mutex.unlock();
 
-	if (!!obsLogViewer)
-		QMetaObject::invokeMethod(obsLogViewer.data(), "AddLine", Qt::QueuedConnection, Q_ARG(int, log_level),
-					  Q_ARG(QString, QString(msg.c_str())));
+	QMetaObject::invokeMethod(App(), "addLogLine", Qt::QueuedConnection, Q_ARG(int, log_level),
+				  Q_ARG(QString, QString(msg.c_str())));
 }
 
 static inline void LogStringChunk(fstream &logFile, char *str, int log_level)