Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Implement backend work for configurable storage locations for settings, profiles, and scene collections #11055

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UI/adv-audio-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
stackedWidget->addWidget(percent);

VolumeType volType = (VolumeType)config_get_int(
GetGlobalConfig(), "BasicWindow", "AdvAudioVolumeType");
App()->GetUserConfig(), "BasicWindow", "AdvAudioVolumeType");

SetVolumeWidget(volType);

Expand Down
59 changes: 30 additions & 29 deletions UI/api-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ template<typename T> static T GetOBSRef(QListWidgetItem *item)
return item->data(static_cast<int>(QtDataRole::OBSRef)).value<T>();
}

void EnumProfiles(function<bool(const char *, const char *)> &&cb);
void EnumSceneCollections(function<bool(const char *, const char *)> &&cb);

extern volatile bool streaming_active;
extern volatile bool recording_active;
extern volatile bool recording_paused;
Expand Down Expand Up @@ -169,19 +166,17 @@ struct OBSStudioAPI : obs_frontend_callbacks {
void obs_frontend_get_scene_collections(
std::vector<std::string> &strings) override
{
auto addCollection = [&](const char *name, const char *) {
strings.emplace_back(name);
return true;
};

EnumSceneCollections(addCollection);
for (auto &[collectionName, collection] :
main->GetSceneCollectionCache()) {
strings.emplace_back(collectionName);
}
}

char *obs_frontend_get_current_scene_collection(void) override
{
const char *cur_name = config_get_string(
App()->GlobalConfig(), "Basic", "SceneCollection");
return bstrdup(cur_name);
const OBSSceneCollection &currentCollection =
main->GetCurrentSceneCollection();
return bstrdup(currentCollection.name.c_str());
}

void obs_frontend_set_current_scene_collection(
Expand All @@ -207,40 +202,34 @@ struct OBSStudioAPI : obs_frontend_callbacks {
bool obs_frontend_add_scene_collection(const char *name) override
{
bool success = false;
QMetaObject::invokeMethod(main, "AddSceneCollection",
QMetaObject::invokeMethod(main, "NewSceneCollection",
WaitConnection(),
Q_RETURN_ARG(bool, success),
Q_ARG(bool, true),
Q_ARG(QString, QT_UTF8(name)));
return success;
}

void
obs_frontend_get_profiles(std::vector<std::string> &strings) override
{
auto addProfile = [&](const char *name, const char *) {
strings.emplace_back(name);
return true;
};
const OBSProfileCache &profiles = main->GetProfileCache();

EnumProfiles(addProfile);
for (auto &[profileName, profile] : profiles) {
strings.emplace_back(profileName);
}
}

char *obs_frontend_get_current_profile(void) override
{
const char *name = config_get_string(App()->GlobalConfig(),
"Basic", "Profile");
return bstrdup(name);
const OBSProfile &profile = main->GetCurrentProfile();
return bstrdup(profile.name.c_str());
}

char *obs_frontend_get_current_profile_path(void) override
{
char profilePath[512];
int ret = GetProfilePath(profilePath, sizeof(profilePath), "");
if (ret <= 0)
return nullptr;
const OBSProfile &profile = main->GetCurrentProfile();

return bstrdup(profilePath);
return bstrdup(profile.path.u8string().c_str());
}

void obs_frontend_set_current_profile(const char *profile) override
Expand Down Expand Up @@ -510,12 +499,24 @@ struct OBSStudioAPI : obs_frontend_callbacks {

config_t *obs_frontend_get_profile_config(void) override
{
return main->basicConfig;
return main->activeConfiguration;
}

config_t *obs_frontend_get_global_config(void) override
{
return App()->GlobalConfig();
blog(LOG_WARNING,
"DEPRECATION: obs_frontend_get_global_config is deprecated. Read from global or user configuration explicitly instead.");
return App()->GetAppConfig();
}

config_t *obs_frontend_get_app_config(void) override
{
return App()->GetAppConfig();
}

config_t *obs_frontend_get_user_config(void) override
{
return App()->GetUserConfig();
}

void obs_frontend_open_projector(const char *type, int monitor,
Expand Down
2 changes: 1 addition & 1 deletion UI/auth-twitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void TwitchAuth::LoadSecondaryUIPanes()
stats->setVisible(false);
feed->setVisible(false);
} else {
uint32_t lastVersion = config_get_int(App()->GlobalConfig(),
uint32_t lastVersion = config_get_int(App()->GetAppConfig(),
"General", "LastVersion");

if (lastVersion <= MAKE_SEMANTIC_VERSION(23, 0, 2)) {
Expand Down
19 changes: 9 additions & 10 deletions UI/frontend-plugins/frontend-tools/scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ ScriptLogWindow::ScriptLogWindow() : QDialog(nullptr)

resize(600, 400);

config_t *global_config = obs_frontend_get_global_config();
config_t *global_config = obs_frontend_get_user_config();
const char *geom =
config_get_string(global_config, "ScriptLogWindow", "geometry");
if (geom != nullptr) {
Expand All @@ -129,7 +129,7 @@ ScriptLogWindow::ScriptLogWindow() : QDialog(nullptr)

ScriptLogWindow::~ScriptLogWindow()
{
config_t *global_config = obs_frontend_get_global_config();
config_t *global_config = obs_frontend_get_user_config();
config_set_string(global_config, "ScriptLogWindow", "geometry",
saveGeometry().toBase64().constData());
}
Expand Down Expand Up @@ -189,7 +189,7 @@ ScriptsTool::ScriptsTool() : QDialog(nullptr), ui(new Ui_ScriptsTool)
RefreshLists();

#if PYTHON_UI
config_t *config = obs_frontend_get_global_config();
config_t *config = obs_frontend_get_user_config();
const char *path =
config_get_string(config, "Python", "Path" ARCH_NAME);
ui->pythonPath->setText(path);
Expand All @@ -207,16 +207,15 @@ ScriptsTool::ScriptsTool() : QDialog(nullptr), ui(new Ui_ScriptsTool)
QSizePolicy::Expanding);
ui->propertiesLayout->addWidget(propertiesView);

config_t *global_config = obs_frontend_get_global_config();
int row =
config_get_int(global_config, "scripts-tool", "prevScriptRow");
config_t *user_config = obs_frontend_get_user_config();
int row = config_get_int(user_config, "scripts-tool", "prevScriptRow");
ui->scripts->setCurrentRow(row);
}

ScriptsTool::~ScriptsTool()
{
config_t *global_config = obs_frontend_get_global_config();
config_set_int(global_config, "scripts-tool", "prevScriptRow",
config_t *user_config = obs_frontend_get_user_config();
config_set_int(user_config, "scripts-tool", "prevScriptRow",
ui->scripts->currentRow());
}

Expand Down Expand Up @@ -465,7 +464,7 @@ void ScriptsTool::on_pythonPathBrowse_clicked()
QByteArray array = newPath.toUtf8();
const char *path = array.constData();

config_t *config = obs_frontend_get_global_config();
config_t *config = obs_frontend_get_user_config();
config_set_string(config, "Python", "Path" ARCH_NAME, path);

ui->pythonPath->setText(newPath);
Expand Down Expand Up @@ -685,7 +684,7 @@ extern "C" void InitScripts()
obs_module_text("Scripts"));

#if PYTHON_UI
config_t *config = obs_frontend_get_global_config();
config_t *config = obs_frontend_get_user_config();
const char *python_path =
config_get_string(config, "Python", "Path" ARCH_NAME);

Expand Down
14 changes: 7 additions & 7 deletions UI/log-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ OBSLogViewer::OBSLogViewer(QWidget *parent)
ui->setupUi(this);

bool showLogViewerOnStartup = config_get_bool(
App()->GlobalConfig(), "LogViewer", "ShowLogStartup");
App()->GetUserConfig(), "LogViewer", "ShowLogStartup");

ui->showStartup->setChecked(showLogViewerOnStartup);

const char *geom = config_get_string(App()->GlobalConfig(), "LogViewer",
"geometry");
const char *geom = config_get_string(App()->GetUserConfig(),
"LogViewer", "geometry");

if (geom != nullptr) {
QByteArray ba = QByteArray::fromBase64(QByteArray(geom));
Expand All @@ -40,13 +40,13 @@ OBSLogViewer::OBSLogViewer(QWidget *parent)

OBSLogViewer::~OBSLogViewer()
{
config_set_string(App()->GlobalConfig(), "LogViewer", "geometry",
config_set_string(App()->GetUserConfig(), "LogViewer", "geometry",
saveGeometry().toBase64().constData());
}

void OBSLogViewer::on_showStartup_clicked(bool checked)
{
config_set_bool(App()->GlobalConfig(), "LogViewer", "ShowLogStartup",
config_set_bool(App()->GetUserConfig(), "LogViewer", "ShowLogStartup",
checked);
}

Expand All @@ -57,7 +57,7 @@ void OBSLogViewer::InitLog()
char logDir[512];
std::string path;

if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs")) {
if (GetAppConfigPath(logDir, sizeof(logDir), "obs-studio/logs")) {
path += logDir;
path += "/";
path += App()->GetCurrentLog();
Expand Down Expand Up @@ -124,7 +124,7 @@ void OBSLogViewer::AddLine(int type, const QString &str)
void OBSLogViewer::on_openButton_clicked()
{
char logDir[512];
if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
if (GetAppConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
return;

const char *log = App()->GetCurrentLog();
Expand Down
4 changes: 2 additions & 2 deletions UI/media-controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ MediaControls::MediaControls(QWidget *parent)
connect(ui->slider, &AbsoluteSlider::sliderMoved, this,
&MediaControls::AbsoluteSliderMoved);

countDownTimer = config_get_bool(App()->GlobalConfig(), "BasicWindow",
countDownTimer = config_get_bool(App()->GetUserConfig(), "BasicWindow",
"MediaControlsCountdownTimer");

QAction *restartAction = new QAction(this);
Expand Down Expand Up @@ -465,7 +465,7 @@ void MediaControls::on_durationLabel_clicked()
{
countDownTimer = !countDownTimer;

config_set_bool(App()->GlobalConfig(), "BasicWindow",
config_set_bool(App()->GetUserConfig(), "BasicWindow",
"MediaControlsCountdownTimer", countDownTimer);

if (MediaPaused())
Expand Down
44 changes: 25 additions & 19 deletions UI/obs-app-theming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,26 +409,31 @@ static vector<OBSThemeVariable> ParseThemeVariables(const char *themeData)

void OBSApp::FindThemes()
{
string themeDir;

QStringList filters;
filters << "*.obt" // OBS Base Theme
<< "*.ovt" // OBS Variant Theme
<< "*.oha" // OBS High-contrast Adjustment layer
;

GetDataFilePath("themes/", themeDir);
QDirIterator it(QString::fromStdString(themeDir), filters, QDir::Files);
while (it.hasNext()) {
auto theme = ParseThemeMeta(it.next());
if (theme && !themes.contains(theme->id))
themes[theme->id] = std::move(*theme);
{
string themeDir;
GetDataFilePath("themes/", themeDir);
QDirIterator it(QString::fromStdString(themeDir), filters,
QDir::Files);
while (it.hasNext()) {
auto theme = ParseThemeMeta(it.next());
if (theme && !themes.contains(theme->id))
themes[theme->id] = std::move(*theme);
}
}

themeDir.resize(1024);
if (GetConfigPath(themeDir.data(), themeDir.capacity(),
"obs-studio/themes/") > 0) {
QDirIterator it(QT_UTF8(themeDir.c_str()), filters,
PatTheMav marked this conversation as resolved.
Show resolved Hide resolved
{
const std::string themeDir =
App()->userConfigLocation.u8string() +
"/obs-studio/themes";

QDirIterator it(QString::fromStdString(themeDir), filters,
QDir::Files);

while (it.hasNext()) {
Expand Down Expand Up @@ -876,7 +881,8 @@ bool OBSApp::SetTheme(const QString &name)

filesystem::path debugOut;
char configPath[512];
if (GetConfigPath(configPath, sizeof(configPath), filename.c_str())) {
if (GetAppConfigPath(configPath, sizeof(configPath),
filename.c_str())) {
debugOut = absolute(filesystem::u8path(configPath));
filesystem::create_directories(debugOut.parent_path());
}
Expand Down Expand Up @@ -940,35 +946,35 @@ bool OBSApp::InitTheme()
}

char userDir[512];
if (GetConfigPath(userDir, sizeof(userDir), "obs-studio/themes")) {
if (GetAppConfigPath(userDir, sizeof(userDir), "obs-studio/themes")) {
auto configSearchDir = filesystem::u8path(userDir);
QDir::addSearchPath("theme", absolute(configSearchDir));
}

/* Load list of themes and read their metadata */
FindThemes();

if (config_get_bool(globalConfig, "Appearance", "AutoReload")) {
if (config_get_bool(userConfig, "Appearance", "AutoReload")) {
/* Set up Qt file watcher to automatically reload themes */
themeWatcher = new QFileSystemWatcher(this);
connect(themeWatcher.get(), &QFileSystemWatcher::fileChanged,
this, &OBSApp::themeFileChanged);
}

/* Migrate old theme config key */
if (config_has_user_value(globalConfig, "General", "CurrentTheme3") &&
!config_has_user_value(globalConfig, "Appearance", "Theme")) {
const char *old = config_get_string(globalConfig, "General",
if (config_has_user_value(userConfig, "General", "CurrentTheme3") &&
!config_has_user_value(userConfig, "Appearance", "Theme")) {
const char *old = config_get_string(userConfig, "General",
"CurrentTheme3");

if (themeMigrations.count(old)) {
config_set_string(globalConfig, "Appearance", "Theme",
config_set_string(userConfig, "Appearance", "Theme",
themeMigrations[old].c_str());
}
}

QString themeName =
config_get_string(globalConfig, "Appearance", "Theme");
config_get_string(userConfig, "Appearance", "Theme");

if (themeName.isEmpty() || !GetTheme(themeName)) {
if (!themeName.isEmpty()) {
Expand Down
Loading
Loading