Sfoglia il codice sorgente

UI: Add import/export of scene collections & profiles

Closes jp9000/obs-studio#721
cg2121 9 anni fa
parent
commit
9f0c48d9c7

+ 8 - 0
UI/data/locale/en-US.ini

@@ -59,6 +59,8 @@ Minutes="Minutes"
 Seconds="Seconds"
 Deprecated="Deprecated"
 ReplayBuffer="Replay Buffer"
+Import="Import"
+Export="Export"
 
 # quick transitions
 QuickTransitions.SwapScenes="Swap Preview/Output Scenes After Transitioning"
@@ -370,6 +372,12 @@ Basic.MainMenu.View.StatusBar="&Status Bar"
 # basic mode profile/scene collection menus
 Basic.MainMenu.SceneCollection="&Scene Collection"
 Basic.MainMenu.Profile="&Profile"
+Basic.MainMenu.Profile.Import="Import Profile"
+Basic.MainMenu.Profile.Export="Export Profile"
+Basic.MainMenu.SceneCollection.Import="Import Scene Collection"
+Basic.MainMenu.SceneCollection.Export="Export Scene Collection"
+Basic.MainMenu.Profile.Exists="The profile already exists"
+Basic.MainMenu.SceneCollection.Exists="The scene collection already exists"
 
 # basic mode help menu
 Basic.MainMenu.Tools="&Tools"

+ 24 - 0
UI/forms/OBSBasic.ui

@@ -898,6 +898,8 @@
     <addaction name="actionDupProfile"/>
     <addaction name="actionRenameProfile"/>
     <addaction name="actionRemoveProfile"/>
+    <addaction name="actionImportProfile"/>
+    <addaction name="actionExportProfile"/>
     <addaction name="separator"/>
    </widget>
    <widget class="QMenu" name="sceneCollectionMenu">
@@ -908,6 +910,8 @@
     <addaction name="actionDupSceneCollection"/>
     <addaction name="actionRenameSceneCollection"/>
     <addaction name="actionRemoveSceneCollection"/>
+    <addaction name="actionImportSceneCollection"/>
+    <addaction name="actionExportSceneCollection"/>
     <addaction name="separator"/>
    </widget>
    <widget class="QMenu" name="viewMenu">
@@ -1273,6 +1277,16 @@
     <string>Remove</string>
    </property>
   </action>
+  <action name="actionImportSceneCollection">
+   <property name="text">
+    <string>Import</string>
+   </property>
+  </action>
+  <action name="actionExportSceneCollection">
+   <property name="text">
+    <string>Export</string>
+   </property>
+  </action>
   <action name="actionNewProfile">
    <property name="text">
     <string>New</string>
@@ -1293,6 +1307,16 @@
     <string>Remove</string>
    </property>
   </action>
+  <action name="actionImportProfile">
+   <property name="text">
+    <string>Import</string>
+   </property>
+  </action>
+  <action name="actionExportProfile">
+   <property name="text">
+    <string>Export</string>
+   </property>
+  </action>
   <action name="actionShowSettingsFolder">
    <property name="text">
     <string>Basic.MainMenu.File.ShowSettingsFolder</string>

+ 80 - 0
UI/window-basic-main-profiles.cpp

@@ -20,6 +20,7 @@
 #include <util/util.hpp>
 #include <QMessageBox>
 #include <QVariant>
+#include <QFileDialog>
 #include "window-basic-main.hpp"
 #include "window-namedialog.hpp"
 #include "qt-wrappers.hpp"
@@ -448,6 +449,85 @@ void OBSBasic::on_actionRemoveProfile_triggered()
 	}
 }
 
+void OBSBasic::on_actionImportProfile_triggered()
+{
+	char path[512];
+
+	QString home = QDir::homePath();
+
+	int ret = GetConfigPath(path, 512, "obs-studio/basic/profiles/");
+	if (ret <= 0) {
+		blog(LOG_WARNING, "Failed to get profile config path");
+		return;
+	}
+
+	QString dir = QFileDialog::getExistingDirectory(
+			this,
+			QTStr("Basic.MainMenu.Profile.Import"),
+			home,
+			QFileDialog::ShowDirsOnly |
+			QFileDialog::DontResolveSymlinks);
+
+	if (!dir.isEmpty() && !dir.isNull()) {
+		QString inputPath = QString::fromUtf8(path);
+		QFileInfo finfo(dir);
+		QString directory = finfo.fileName();
+		QString profileDir = inputPath + directory;
+		QDir folder(profileDir);
+
+		if (!folder.exists()) {
+			folder.mkpath(profileDir);
+			QFile::copy(dir + "/basic.ini",
+					profileDir + "/basic.ini");
+			QFile::copy(dir + "/service.json",
+					profileDir + "/service.json");
+			RefreshProfiles();
+		} else {
+			QMessageBox::information(this,
+					QTStr("Basic.MainMenu.Profile.Import"),
+					QTStr("Basic.MainMenu.Profile.Exists"));
+		}
+	}
+}
+
+void OBSBasic::on_actionExportProfile_triggered()
+{
+	char path[512];
+
+	QString home = QDir::homePath();
+
+	QString currentProfile =
+		QString::fromUtf8(config_get_string(App()->GlobalConfig(),
+		"Basic", "ProfileDir"));
+
+	int ret = GetConfigPath(path, 512, "obs-studio/basic/profiles/");
+	if (ret <= 0) {
+		blog(LOG_WARNING, "Failed to get profile config path");
+		return;
+	}
+
+	QString dir = QFileDialog::getExistingDirectory(
+			this,
+			QTStr("Basic.MainMenu.Profile.Export"),
+			home,
+			QFileDialog::ShowDirsOnly |
+			QFileDialog::DontResolveSymlinks);
+
+	if (!dir.isEmpty() && !dir.isNull()) {
+		QString outputDir = dir + "/" + currentProfile;
+		QString inputPath = QString::fromUtf8(path);
+		QDir folder(outputDir);
+
+		if (!folder.exists()) {
+			folder.mkpath(outputDir);
+			QFile::copy(inputPath + currentProfile + "/basic.ini",
+					outputDir + "/basic.ini");
+			QFile::copy(inputPath + currentProfile + "/service.json",
+					outputDir + "/service.json");
+		}
+	}
+}
+
 void OBSBasic::ChangeProfile()
 {
 	QAction *action = reinterpret_cast<QAction*>(sender());

+ 63 - 0
UI/window-basic-main-scene-collections.cpp

@@ -19,6 +19,8 @@
 #include <util/util.hpp>
 #include <QMessageBox>
 #include <QVariant>
+#include <QFileDialog>
+#include <QStandardPaths>
 #include "item-widget-helpers.hpp"
 #include "window-basic-main.hpp"
 #include "window-namedialog.hpp"
@@ -347,6 +349,67 @@ void OBSBasic::on_actionRemoveSceneCollection_triggered()
 	}
 }
 
+void OBSBasic::on_actionImportSceneCollection_triggered()
+{
+	char path[512];
+
+	QString home = QDir::homePath();
+
+	int ret = GetConfigPath(path, 512, "obs-studio/basic/scenes/");
+	if (ret <= 0) {
+		blog(LOG_WARNING, "Failed to get scene collection config path");
+		return;
+	}
+
+	QString file = QFileDialog::getOpenFileName(
+			this,
+			QTStr("Basic.MainMenu.SceneCollection.Import"),
+			home,
+			"JSON Files (*.json)");
+
+	QFileInfo finfo(file);
+	QString filename = finfo.fileName();
+	QFileInfo destinfo(path + filename);
+
+	if (!file.isEmpty() && !file.isNull()) {
+		 if (!destinfo.exists()) {
+			QFile::copy(file, path + filename);
+			RefreshSceneCollections();
+		} else {
+			QMessageBox::information(this,
+				QTStr("Basic.MainMenu.SceneCollection.Import"),
+				QTStr("Basic.MainMenu.SceneCollection.Exists"));
+		}
+	}
+}
+
+void OBSBasic::on_actionExportSceneCollection_triggered()
+{
+	char path[512];
+
+	QString home = QDir::homePath();
+
+	QString currentFile = QT_UTF8(config_get_string(App()->GlobalConfig(),
+				"Basic", "SceneCollectionFile"));
+
+	int ret = GetConfigPath(path, 512, "obs-studio/basic/scenes/");
+	if (ret <= 0) {
+		blog(LOG_WARNING, "Failed to get scene collection config path");
+		return;
+	}
+
+	QString exportFile = QFileDialog::getSaveFileName(
+			0,
+			QTStr("Basic.MainMenu.SceneCollection.Export"),
+			home + "/" + currentFile,
+			"JSON Files (*.json)");
+
+	string file = QT_TO_UTF8(exportFile);
+
+	if (!exportFile.isEmpty() && !exportFile.isNull())
+		QFile::copy(path + currentFile + ".json", exportFile);
+}
+
 void OBSBasic::ChangeSceneCollection()
 {
 	QAction *action = reinterpret_cast<QAction*>(sender());

+ 4 - 0
UI/window-basic-main.hpp

@@ -552,11 +552,15 @@ private slots:
 	void on_actionDupSceneCollection_triggered();
 	void on_actionRenameSceneCollection_triggered();
 	void on_actionRemoveSceneCollection_triggered();
+	void on_actionImportSceneCollection_triggered();
+	void on_actionExportSceneCollection_triggered();
 
 	void on_actionNewProfile_triggered();
 	void on_actionDupProfile_triggered();
 	void on_actionRenameProfile_triggered();
 	void on_actionRemoveProfile_triggered();
+	void on_actionImportProfile_triggered();
+	void on_actionExportProfile_triggered();
 
 	void on_actionShowSettingsFolder_triggered();
 	void on_actionShowProfileFolder_triggered();