mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-22 09:54:54 -05:00
The "core" macro conditions and actions have been extracted out to the "base" plugin. The library now mostly contains functionality which is required across all plugins and (e.g. definitions for macro segments). The goal is to reduce the complexity and cross-dependencies and group the source files in a better way. This should relsove the "library limit of 65535 objects exceeded" build issue occuring in some Windows build environments.
90 lines
2.5 KiB
C++
90 lines
2.5 KiB
C++
#include "macro-export-import-dialog.hpp"
|
|
#include "obs-module-helper.hpp"
|
|
|
|
#include <obs.hpp>
|
|
#include <QLayout>
|
|
#include <QLabel>
|
|
#include <QDialogButtonBox>
|
|
|
|
namespace advss {
|
|
|
|
MacroExportImportDialog::MacroExportImportDialog(Type type)
|
|
: QDialog(nullptr), _importExportString(new QPlainTextEdit(this))
|
|
{
|
|
_importExportString->setReadOnly(type == Type::EXPORT_MACRO);
|
|
auto label = new QLabel(obs_module_text(
|
|
type == Type::EXPORT_MACRO
|
|
? "AdvSceneSwitcher.macroTab.export.info"
|
|
: "AdvSceneSwitcher.macroTab.import.info"));
|
|
label->setWordWrap(true);
|
|
|
|
QDialogButtonBox *buttons = nullptr;
|
|
if (type == Type::EXPORT_MACRO) {
|
|
buttons = new QDialogButtonBox(QDialogButtonBox::Ok);
|
|
} else {
|
|
buttons = new QDialogButtonBox(QDialogButtonBox::Ok |
|
|
QDialogButtonBox::Cancel);
|
|
}
|
|
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
buttons->setCenterButtons(true);
|
|
|
|
auto layout = new QVBoxLayout;
|
|
layout->addWidget(label);
|
|
layout->addWidget(_importExportString);
|
|
layout->addWidget(buttons);
|
|
setLayout(layout);
|
|
|
|
setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle"));
|
|
}
|
|
|
|
QString compressMacroString(const QString &input)
|
|
{
|
|
QByteArray inputData = input.toUtf8();
|
|
auto compressedData = qCompress(inputData);
|
|
QByteArray encodedData = compressedData.toBase64();
|
|
return QString::fromUtf8(encodedData);
|
|
}
|
|
|
|
QString decompressMacroString(const QString &input)
|
|
{
|
|
QByteArray encodedData = input.toUtf8();
|
|
QByteArray compressedData = QByteArray::fromBase64(encodedData);
|
|
auto outputData = qUncompress(compressedData);
|
|
return QString::fromUtf8(outputData);
|
|
}
|
|
|
|
void MacroExportImportDialog::ExportMacros(const QString &json)
|
|
{
|
|
MacroExportImportDialog dialog(
|
|
MacroExportImportDialog::Type::EXPORT_MACRO);
|
|
dialog._importExportString->setPlainText(compressMacroString(json));
|
|
dialog.adjustSize();
|
|
dialog.updateGeometry();
|
|
dialog.exec();
|
|
}
|
|
|
|
static bool isValidData(const QString &json)
|
|
{
|
|
OBSDataAutoRelease data =
|
|
obs_data_create_from_json(json.toStdString().c_str());
|
|
return !!data;
|
|
}
|
|
|
|
bool MacroExportImportDialog::ImportMacros(QString &json)
|
|
{
|
|
MacroExportImportDialog dialog(
|
|
MacroExportImportDialog::Type::IMPORT_MACRO);
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
json = decompressMacroString(
|
|
dialog._importExportString->toPlainText());
|
|
if (!isValidData(json)) { // Fallback to support raw json format
|
|
json = dialog._importExportString->toPlainText();
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} // namespace advss
|