2013-12-07 09:22:56 -08:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
2014-01-11 15:34:15 -08:00
|
|
|
Copyright (C) 2014 by Zachary Lund <admin@computerquip.com>
|
2013-12-07 09:22:56 -08:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
2014-01-24 11:52:22 -08:00
|
|
|
|
2014-07-21 07:26:57 -07:00
|
|
|
#include <obs-config.h>
|
2014-07-11 11:32:27 -07:00
|
|
|
#include "obs-app.hpp"
|
|
|
|
|
2016-10-03 23:50:13 -07:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QScreen>
|
|
|
|
|
2013-12-27 18:43:28 -08:00
|
|
|
#include <unistd.h>
|
2013-12-07 09:22:56 -08:00
|
|
|
#include <sstream>
|
2014-07-11 11:32:27 -07:00
|
|
|
#include <locale.h>
|
2013-12-27 18:43:28 -08:00
|
|
|
|
2013-12-07 09:22:56 -08:00
|
|
|
#include "platform.hpp"
|
2013-12-29 03:40:53 -08:00
|
|
|
using namespace std;
|
2013-12-07 09:22:56 -08:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
static inline bool check_path(const char *data, const char *path,
|
|
|
|
string &output)
|
2013-12-27 18:43:28 -08:00
|
|
|
{
|
|
|
|
ostringstream str;
|
2014-01-03 14:22:49 -08:00
|
|
|
str << path << data;
|
2013-12-27 18:43:28 -08:00
|
|
|
output = str.str();
|
2014-01-24 11:52:22 -08:00
|
|
|
|
2013-12-27 18:43:28 -08:00
|
|
|
printf("Attempted path: %s\n", output.c_str());
|
2014-01-24 11:52:22 -08:00
|
|
|
|
2013-12-27 18:43:28 -08:00
|
|
|
return (access(output.c_str(), R_OK) == 0);
|
|
|
|
}
|
|
|
|
|
2014-01-24 18:44:34 -08:00
|
|
|
#define INSTALL_DATA_PATH OBS_INSTALL_PREFIX OBS_DATA_PATH "/obs-studio/"
|
2014-01-24 11:52:22 -08:00
|
|
|
|
2013-12-07 09:22:56 -08:00
|
|
|
bool GetDataFilePath(const char *data, string &output)
|
|
|
|
{
|
2013-12-27 18:43:28 -08:00
|
|
|
char *data_path = getenv("OBS_DATA_PATH");
|
|
|
|
if (data_path != NULL) {
|
|
|
|
if (check_path(data, data_path, output))
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-24 11:52:22 -08:00
|
|
|
|
2014-01-20 07:58:58 -08:00
|
|
|
if (check_path(data, OBS_DATA_PATH "/obs-studio/", output))
|
2013-12-27 18:43:28 -08:00
|
|
|
return true;
|
2014-01-24 11:52:22 -08:00
|
|
|
if (check_path(data, INSTALL_DATA_PATH, output))
|
2013-12-27 18:43:28 -08:00
|
|
|
return true;
|
2014-01-24 11:52:22 -08:00
|
|
|
|
2013-12-11 20:50:10 -08:00
|
|
|
return false;
|
2013-12-07 09:22:56 -08:00
|
|
|
}
|
2013-12-15 23:06:13 -08:00
|
|
|
|
2014-01-08 16:17:30 -08:00
|
|
|
bool InitApplicationBundle()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-20 23:08:47 -07:00
|
|
|
|
|
|
|
string GetDefaultVideoSavePath()
|
|
|
|
{
|
|
|
|
return string(getenv("HOME"));
|
|
|
|
}
|
2014-07-11 11:32:27 -07:00
|
|
|
|
|
|
|
vector<string> GetPreferredLocales()
|
|
|
|
{
|
|
|
|
setlocale(LC_ALL, "");
|
2020-06-05 18:00:52 -07:00
|
|
|
vector<string> matched;
|
2014-07-11 11:32:27 -07:00
|
|
|
string messages = setlocale(LC_MESSAGES, NULL);
|
|
|
|
if (!messages.size() || messages == "C" || messages == "POSIX")
|
|
|
|
return {};
|
|
|
|
|
|
|
|
if (messages.size() > 2)
|
|
|
|
messages[2] = '-';
|
|
|
|
|
|
|
|
for (auto &locale_pair : GetLocaleNames()) {
|
|
|
|
auto &locale = locale_pair.first;
|
|
|
|
if (locale == messages.substr(0, locale.size()))
|
|
|
|
return {locale};
|
|
|
|
|
|
|
|
if (locale.substr(0, 2) == messages.substr(0, 2))
|
2020-06-05 18:00:52 -07:00
|
|
|
matched.push_back(locale);
|
2014-07-11 11:32:27 -07:00
|
|
|
}
|
|
|
|
|
2020-06-05 18:00:52 -07:00
|
|
|
return matched;
|
2014-07-11 11:32:27 -07:00
|
|
|
}
|
2016-01-22 07:33:29 -08:00
|
|
|
|
2016-08-21 16:11:32 -07:00
|
|
|
bool IsAlwaysOnTop(QWidget *window)
|
2016-01-22 07:33:29 -08:00
|
|
|
{
|
|
|
|
return (window->windowFlags() & Qt::WindowStaysOnTopHint) != 0;
|
|
|
|
}
|
|
|
|
|
2016-08-21 16:11:32 -07:00
|
|
|
void SetAlwaysOnTop(QWidget *window, bool enable)
|
2016-01-22 07:33:29 -08:00
|
|
|
{
|
|
|
|
Qt::WindowFlags flags = window->windowFlags();
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
flags |= Qt::WindowStaysOnTopHint;
|
|
|
|
else
|
|
|
|
flags &= ~Qt::WindowStaysOnTopHint;
|
|
|
|
|
|
|
|
window->setWindowFlags(flags);
|
|
|
|
window->show();
|
|
|
|
}
|