Compare commits

...

7 Commits

Author SHA1 Message Date
WarmUpTill
93703c80bc Hide option to verify timestamps when functionality is disabled 2025-06-01 11:57:26 +02:00
WarmUpTill
d7951a7179 Cleanup constness 2025-06-01 11:57:26 +02:00
WarmUpTill
d42a3b584a Rework resource tab hotkey handling
Added hotkey to add new entry
2025-06-01 11:57:26 +02:00
WarmUpTill
becd1bd02a Set default hotkey for new macro to CTRL + N 2025-06-01 11:57:26 +02:00
WarmUpTill
30422aecf3 Fix crash when deleting macro 2025-06-01 11:57:26 +02:00
WarmUpTill
c567e6ef7f Allow import of json files
Automatic backups are stored as json files
2025-06-01 11:57:26 +02:00
WarmUpTill
1ca61f3ed4 Add option to not link date-tz even if the source code exists 2025-05-28 22:11:07 +02:00
26 changed files with 152 additions and 186 deletions

View File

@@ -232,8 +232,6 @@ target_sources(
lib/utils/resizing-text-edit.hpp
lib/utils/resource-table.cpp
lib/utils/resource-table.hpp
lib/utils/resource-table-hotkey-handler.cpp
lib/utils/resource-table-hotkey-handler.hpp
lib/utils/scene-selection.cpp
lib/utils/scene-selection.hpp
lib/utils/scene-switch-helpers.cpp

View File

@@ -40,7 +40,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="Exportieren"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="Importieren"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="Exportiere Erweiterter Automatischer Szenenwechsler Einstellungen zu Datei ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="Exportiere Erweiterter Automatischer Szenenwechsler Einstellungen von Datei ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Text Dateien (*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Text Dateien (*.txt *.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="Importieren der Einstellungen ist fehlgeschlagen"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="Einstellungen wurden erfolgreich importiert"
AdvSceneSwitcher.generalTab.priority.fileContent="Datei Inhalt"

View File

@@ -53,7 +53,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="Export"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="Import"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="Export Advanced Scene Switcher settings to file ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="Import Advanced Scene Switcher settings from file ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Text files (*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Text files (*.txt);;JSON files (*.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="Advanced Scene Switcher failed to import settings"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="Advanced Scene Switcher settings imported successfully"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportSensitiveDataWarning="Warning:\nThe exported data might contain sensitive information!"

View File

@@ -38,7 +38,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="Exportar"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="Importar"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="Exportar los ajustes para Advanced Scene Switcher ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="Importar los ajustes para Advanced Scene Switcher ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Archivos de texto (*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Archivos de texto (*.txt *.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="La importacion la configuracion de escenas fallo"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="Configuración de escenas importada correctamente"
AdvSceneSwitcher.generalTab.priority.fileContent="Contenido del archivo"

View File

@@ -43,7 +43,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="Exporter"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="Importer"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="Exporter les paramètres d'Advanced Scene Switcher vers un fichier ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="Importer les paramètres d'Advanced Scene Switcher depuis un fichier ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Fichiers texte (*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Fichiers texte (*.txt *.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="L'importation des paramètres d'Advanced Scene Switcher a échoué"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="Les paramètres d'Advanced Scene Switcher ont été importés avec succès"
AdvSceneSwitcher.generalTab.priority.fileContent="Contenu du fichier"

View File

@@ -48,7 +48,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="エクスポート"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="インポート"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="高機能シーンスイッチャーの設定をファイルにエクスポート..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="高機能シーンスイッチャーの設定をファイルからインポート..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="テキストファイル(*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="テキストファイル(*.txt *.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="高機能シーンスイッチャーの設定インポートに失敗しました"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="高機能シーンスイッチャーの設定が正常にインポートされました"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportSensitiveDataWarning="警告:\nエクスポートされたデータにはセンシティブ情報が含まれている可能性があります"

View File

@@ -48,7 +48,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="Exportar"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="Importar"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="Exportar configurações do Advanced Scene Switcher para arquivo ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="Importar configurações do Advanced Scene Switcher de arquivo ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Arquivos de texto (*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Arquivos de texto (*.txt *.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="O Advanced Scene Switcher falhou ao importar configurações"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="Configurações do Advanced Scene Switcher importadas com sucesso"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportSensitiveDataWarning="Aviso:\nOs dados exportados podem conter informações sensíveis!"

View File

@@ -36,7 +36,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="Экспорт"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="Импорт"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="Экспортировать настройки расширенного переключателя сцен в файл ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="Импортировать настройки Advanced Scene Switcher из файла ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Текстовые файлы (*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Текстовые файлы (*.txt *.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="Advanced Scene Switcher не удалось импортировать настройки"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="Настройки Advanced Scene Switcher импортированы успешно"
AdvSceneSwitcher.generalTab.priority.fileContent="Содержание файла"

View File

@@ -38,7 +38,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="Dışa Aktar"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="İçe Aktar"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="Gelişmiş Sahne Değiştirici ayarlarını dosyaya aktar ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="Gelişmiş Sahne Değiştirici ayarlarını dosyadan içe aktar ..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Text dosyası (*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="Text dosyası (*.txt *.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="Gelişmiş Sahne Değiştirici ayarları dosyadan içe aktarmakta başarısız oldu"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="Gelişmiş Sahne Değiştirici ayarları başarılı bir şekilde dosyadan içe aktarıldı"
AdvSceneSwitcher.generalTab.priority.fileContent="Dosya İçeriği"

View File

@@ -51,7 +51,7 @@ AdvSceneSwitcher.generalTab.saveOrLoadsettings.export="导出设置"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.import="导入设置"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportWindowTitle="导出高级场景切换器到文件..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.importWindowTitle="导入高级场景切换器到文件..."
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="文本文件 (*.txt)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType="文本文件 (*.txt *.json)"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadFail="高级场景切换器导入设置失败"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess="高级场景切换器导入设置成功"
AdvSceneSwitcher.generalTab.saveOrLoadsettings.exportSensitiveDataWarning="警告:\n导出的数据可能包含敏感信息!"

View File

@@ -35,12 +35,14 @@ MacroActionEdit::MacroActionEdit(QWidget *parent,
_enable(new SwitchButton()),
_entryData(entryData)
{
auto actionStateTimer = new QTimer(this);
QWidget::connect(_actionSelection,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(ActionSelectionChanged(const QString &)));
QWidget::connect(_enable, SIGNAL(checked(bool)), this,
SLOT(ActionEnableChanged(bool)));
QWidget::connect(&_actionStateTimer, SIGNAL(timeout()), this,
QWidget::connect(actionStateTimer, SIGNAL(timeout()), this,
SLOT(UpdateActionState()));
populateActionSelection(_actionSelection);
@@ -63,7 +65,7 @@ MacroActionEdit::MacroActionEdit(QWidget *parent,
_entryData = entryData;
SetupWidgets(true);
_actionStateTimer.start(300);
actionStateTimer->start(300);
_loading = false;
}

View File

@@ -32,7 +32,6 @@ private:
SwitchButton *_enable;
std::shared_ptr<MacroAction> *_entryData;
QTimer _actionStateTimer;
bool _loading = true;
};

View File

@@ -78,36 +78,36 @@ bool MacroSwitchedScene()
return macroSceneSwitched;
}
std::string GetMacroName(Macro *macro)
std::string GetMacroName(const Macro *macro)
{
return macro ? macro->Name() : "";
}
std::chrono::high_resolution_clock::time_point
LastMacroConditionCheckTime(Macro *macro)
LastMacroConditionCheckTime(const Macro *macro)
{
return macro ? macro->LastConditionCheckTime()
: std::chrono::high_resolution_clock::time_point{};
}
bool MacroIsStopped(Macro *macro)
bool MacroIsStopped(const Macro *macro)
{
return macro ? macro->GetStop() : true;
}
bool MacroIsPaused(Macro *macro)
bool MacroIsPaused(const Macro *macro)
{
return macro ? macro->Paused() : true;
}
bool MacroWasPausedSince(
Macro *macro,
const Macro *macro,
const std::chrono::high_resolution_clock::time_point &time)
{
return macro ? macro->WasPausedSince(time) : false;
}
bool MacroWasCheckedSinceLastStart(Macro *macro)
bool MacroWasCheckedSinceLastStart(const Macro *macro)
{
if (!macro) {
return false;
@@ -144,7 +144,7 @@ void ResetMacroRunCount(Macro *macro)
macro->ResetRunCount();
}
bool IsValidMacroSegmentIndex(Macro *m, const int idx, bool isCondition)
bool IsValidMacroSegmentIndex(const Macro *m, const int idx, bool isCondition)
{
if (!m || idx < 0) {
return false;

View File

@@ -41,17 +41,17 @@ EXPORT std::atomic_int &GetShutdownConditionCount();
EXPORT void SetMacroSwitchedScene(bool value);
EXPORT bool MacroSwitchedScene();
EXPORT std::string GetMacroName(Macro *);
EXPORT std::string GetMacroName(const Macro *);
EXPORT std::chrono::high_resolution_clock::time_point
LastMacroConditionCheckTime(Macro *);
LastMacroConditionCheckTime(const Macro *);
EXPORT bool MacroIsStopped(Macro *);
EXPORT bool MacroIsPaused(Macro *);
EXPORT bool MacroIsStopped(const Macro *);
EXPORT bool MacroIsPaused(const Macro *);
EXPORT bool
MacroWasPausedSince(Macro *,
MacroWasPausedSince(const Macro *,
const std::chrono::high_resolution_clock::time_point &);
EXPORT bool MacroWasCheckedSinceLastStart(Macro *);
EXPORT bool MacroWasCheckedSinceLastStart(const Macro *);
EXPORT void AddMacroHelperThread(Macro *, std::thread &&);
@@ -68,6 +68,6 @@ EXPORT void InvalidateMacroTempVarValues();
EXPORT void ResetMacroConditionTimers(Macro *);
EXPORT void ResetMacroRunCount(Macro *);
bool IsValidMacroSegmentIndex(Macro *m, const int idx, bool isCondition);
bool IsValidMacroSegmentIndex(const Macro *m, const int idx, bool isCondition);
} // namespace advss

View File

@@ -42,6 +42,13 @@ MacroSegmentList::MacroSegmentList(QWidget *parent)
[this]() { SetupVisibleMacroSegmentWidgets(); });
}
static void clearWidgetVector(const std::vector<QWidget *> &widgets)
{
for (auto widget : widgets) {
widget->deleteLater();
}
};
MacroSegmentList::~MacroSegmentList()
{
if (_autoScrollThread.joinable()) {
@@ -49,13 +56,6 @@ MacroSegmentList::~MacroSegmentList()
_autoScrollThread.join();
}
const auto clearWidgetVector =
[](const std::vector<QWidget *> &widgets) {
for (auto widget : widgets) {
widget->deleteLater();
}
};
for (const auto &[_, widgets] : _widgetCache) {
clearWidgetVector(widgets);
}
@@ -185,6 +185,16 @@ bool MacroSegmentList::PopulateWidgetsFromCache(const Macro *macro)
return true;
}
void MacroSegmentList::ClearWidgetsFromCacheFor(const Macro *macro)
{
auto it = _widgetCache.find(macro);
if (it == _widgetCache.end()) {
return;
}
clearWidgetVector(it->second);
_widgetCache.erase(it);
}
void MacroSegmentList::Highlight(int idx, QColor color)
{
auto item = _contentLayout->itemAt(idx);

View File

@@ -29,6 +29,7 @@ public:
static void SetCachingEnabled(bool enable);
void CacheCurrentWidgetsFor(const Macro *);
bool PopulateWidgetsFromCache(const Macro *);
void ClearWidgetsFromCacheFor(const Macro *);
void Highlight(int idx, QColor color = QColor(Qt::green));
void SetCollapsed(bool) const;
void SetSelection(int idx) const;

View File

@@ -140,6 +140,42 @@ void AdvSceneSwitcher::on_macroAdd_clicked()
emit MacroAdded(QString::fromStdString(name));
}
static void addGroupSubitems(std::vector<std::shared_ptr<Macro>> &macros,
const std::shared_ptr<Macro> &group)
{
std::vector<std::shared_ptr<Macro>> subitems;
subitems.reserve(group->GroupSize());
// Find all subitems
auto allMacros = GetMacros();
for (auto it = allMacros.begin(); it < allMacros.end(); it++) {
if ((*it)->Name() != group->Name()) {
continue;
}
for (uint32_t i = 1; i <= group->GroupSize(); i++) {
subitems.emplace_back(*std::next(it, i));
}
break;
}
// Remove subitems which were already selected to avoid duplicates
for (const auto &subitem : subitems) {
auto it = std::find(macros.begin(), macros.end(), subitem);
if (it == macros.end()) {
continue;
}
macros.erase(it);
}
// Add group subitems
auto it = std::find(macros.begin(), macros.end(), group);
if (it == macros.end()) {
return;
}
it = std::next(it);
macros.insert(it, subitems.begin(), subitems.end());
}
void AdvSceneSwitcher::RemoveMacro(std::shared_ptr<Macro> &macro)
{
if (!macro) {
@@ -155,6 +191,28 @@ void AdvSceneSwitcher::RemoveMacro(std::shared_ptr<Macro> &macro)
}
}
const auto clearWidgetCache = [this](Macro *macro) {
ui->conditionsList->ClearWidgetsFromCacheFor(macro);
ui->actionsList->ClearWidgetsFromCacheFor(macro);
ui->elseActionsList->ClearWidgetsFromCacheFor(macro);
};
if (macro->IsGroup()) {
std::vector<std::shared_ptr<Macro>> macros = {macro};
addGroupSubitems(macros, macro);
for (auto macro : macros) {
clearWidgetCache(macro.get());
}
} else {
clearWidgetCache(macro.get());
}
// Currently shown macro will always be part of the macros to be
// removed, so, we clear the widgets as they should not be cached
ui->conditionsList->Clear();
ui->actionsList->Clear();
ui->elseActionsList->Clear();
ui->macros->Remove(macro);
emit MacroRemoved(name);
}
@@ -254,41 +312,6 @@ void AdvSceneSwitcher::RenameSelectedMacro()
ui->macroName->setText(QString::fromStdString(name));
}
static void addGroupSubitems(std::vector<std::shared_ptr<Macro>> &macros,
const std::shared_ptr<Macro> &group)
{
std::vector<std::shared_ptr<Macro>> subitems;
subitems.reserve(group->GroupSize());
// Find all subitems
auto allMacros = GetMacros();
for (auto it = allMacros.begin(); it < allMacros.end(); it++) {
if ((*it)->Name() == group->Name()) {
for (uint32_t i = 1; i <= group->GroupSize(); i++) {
subitems.emplace_back(*std::next(it, i));
}
break;
}
}
// Remove subitems which were already selected to avoid duplicates
for (const auto &subitem : subitems) {
auto it = std::find(macros.begin(), macros.end(), subitem);
if (it == macros.end()) {
continue;
}
macros.erase(it);
}
// Add group subitems
auto it = std::find(macros.begin(), macros.end(), group);
if (it == macros.end()) {
return;
}
it = std::next(it);
macros.insert(it, subitems.begin(), subitems.end());
}
void AdvSceneSwitcher::ExportMacros() const
{
auto selectedMacros = GetSelectedMacros();

View File

@@ -724,16 +724,31 @@ std::deque<std::shared_ptr<MacroCondition>> &Macro::Conditions()
return _conditions;
}
const std::deque<std::shared_ptr<MacroCondition>> &Macro::Conditions() const
{
return _conditions;
}
std::deque<std::shared_ptr<MacroAction>> &Macro::Actions()
{
return _actions;
}
const std::deque<std::shared_ptr<MacroAction>> &Macro::Actions() const
{
return _actions;
}
std::deque<std::shared_ptr<MacroAction>> &Macro::ElseActions()
{
return _elseActions;
}
const std::deque<std::shared_ptr<MacroAction>> &Macro::ElseActions() const
{
return _elseActions;
}
static void updateIndicesHelper(std::deque<std::shared_ptr<MacroSegment>> &list)
{
int idx = 0;

View File

@@ -95,8 +95,11 @@ public:
// Macro segments
std::deque<std::shared_ptr<MacroCondition>> &Conditions();
const std::deque<std::shared_ptr<MacroCondition>> &Conditions() const;
std::deque<std::shared_ptr<MacroAction>> &Actions();
const std::deque<std::shared_ptr<MacroAction>> &Actions() const;
std::deque<std::shared_ptr<MacroAction>> &ElseActions();
const std::deque<std::shared_ptr<MacroAction>> &ElseActions() const;
void UpdateActionIndices();
void UpdateElseActionIndices();
void UpdateConditionIndices();

View File

@@ -325,11 +325,27 @@ static void loadHotkey(obs_data_t *obj, obs_hotkey_id id, const char *name)
obs_data_array_release(a);
}
static void setDefaultHotkeyBinding(obs_data_t *data, const char *name,
const char *value)
{
OBSDataAutoRelease hotkeyData = obs_data_create_from_json(value);
OBSDataArrayAutoRelease hotkeyArray = obs_data_array_create();
obs_data_array_push_back(hotkeyArray, hotkeyData);
obs_data_set_default_array(data, name, hotkeyArray);
}
void SwitcherData::LoadHotkeys(obs_data_t *obj)
{
if (!hotkeysRegistered) {
registerHotkeys();
}
setDefaultHotkeyBinding(obj, "newMacroHotkey",
"{"
"\"control\": true,"
"\"key\": \"OBS_KEY_N\""
"}");
loadHotkey(obj, startHotkey, "startHotkey");
loadHotkey(obj, stopHotkey, "stopHotkey");
loadHotkey(obj, toggleHotkey, "toggleHotkey");

View File

@@ -1,70 +0,0 @@
#include "resource-table-hotkey-handler.hpp"
#include <QKeyEvent>
#include <QWidget>
#include <unordered_map>
namespace advss {
void RegisterHotkeyFunction(QWidget *widget, Qt::Key key,
std::function<void()> func)
{
ResourceTabHotkeyHandler::Instance()->RegisterHandler(widget, key,
func);
}
void DeregisterHotkeyFunctions(QWidget *widget)
{
ResourceTabHotkeyHandler::Instance()->Deregister(widget);
}
ResourceTabHotkeyHandler *ResourceTabHotkeyHandler::Instance()
{
static ResourceTabHotkeyHandler handler;
return &handler;
}
void ResourceTabHotkeyHandler::RegisterHandler(QWidget *widget, Qt::Key key,
std::function<void()> func)
{
std::lock_guard<std::mutex> lock(_mutex);
_callbacks.emplace(widget, CallbackData{key, func});
widget->installEventFilter(this);
}
void ResourceTabHotkeyHandler::Deregister(QWidget *widget)
{
std::lock_guard<std::mutex> lock(_mutex);
_callbacks.erase(widget);
}
bool ResourceTabHotkeyHandler::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() != QEvent::KeyPress) {
return QObject::eventFilter(obj, event);
}
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
auto pressedKey = keyEvent->key();
std::lock_guard<std::mutex> lock(_mutex);
auto it = _callbacks.find(obj);
if (it == _callbacks.end()) {
return QObject::eventFilter(obj, event);
}
auto current = it;
while (current != _callbacks.end() && current->first == it->first) {
auto &[_, cbData] = *current;
if (pressedKey != cbData.key) {
++current;
continue;
}
cbData.func();
++current;
continue;
}
return QObject::eventFilter(obj, event);
}
} // namespace advss

View File

@@ -1,37 +0,0 @@
#pragma once
#include "export-symbol-helper.hpp"
#include <map>
#include <mutex>
#include <QEvent>
#include <QObject>
namespace advss {
EXPORT void RegisterHotkeyFunction(QWidget *, Qt::Key,
std::function<void()> func);
EXPORT void DeregisterHotkeyFunctions(QWidget *);
class ResourceTabHotkeyHandler : public QObject {
Q_OBJECT
public:
static ResourceTabHotkeyHandler *Instance();
void RegisterHandler(QWidget *, Qt::Key, std::function<void()> func);
void Deregister(QWidget *);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
struct CallbackData {
Qt::Key key;
std::function<void()> func;
};
ResourceTabHotkeyHandler() : QObject(){};
std::multimap<QObject *, CallbackData> _callbacks;
std::mutex _mutex;
};
} // namespace advss

View File

@@ -1,10 +1,10 @@
#include "resource-table.hpp"
#include "plugin-state-helpers.hpp"
#include "resource-table-hotkey-handler.hpp"
#include "ui-helpers.hpp"
#include <QGridLayout>
#include <QHeaderView>
#include <QShortcut>
namespace advss {
@@ -64,13 +64,16 @@ ResourceTable::ResourceTable(QTabWidget *parent, const QString &help,
QWidget::connect(_table, &QTableWidget::cellDoubleClicked,
[openSettings]() { openSettings(); });
RegisterHotkeyFunction(this, Qt::Key_F2, openSettings);
RegisterHotkeyFunction(this, Qt::Key_Delete, [this]() { Remove(); });
}
auto settingsShortcut = new QShortcut(QKeySequence("F2"), this);
QWidget::connect(settingsShortcut, &QShortcut::activated, this,
openSettings);
auto removeShortcut = new QShortcut(QKeySequence("Del"), this);
QWidget::connect(removeShortcut, &QShortcut::activated, this,
[this]() { Remove(); });
ResourceTable::~ResourceTable()
{
DeregisterHotkeyFunctions(this);
auto newShortcut = new QShortcut(QKeySequence("Ctrl+N"), this);
QWidget::connect(newShortcut, &QShortcut::activated, this,
[this]() { Add(); });
}
void ResourceTable::SetHelpVisible(bool visible) const

View File

@@ -18,7 +18,6 @@ public:
const QString &addToolTip, const QString &removeToolTip,
const QStringList &headers,
const std::function<void()> &openSettings);
virtual ~ResourceTable();
QTableWidget *Table() const { return _table; }
void SetHelpVisible(bool) const;

View File

@@ -31,7 +31,8 @@ if(NOT ZLIB_FOUND)
endif()
set(DATE_LIB_DIR "${ADVSS_SOURCE_DIR}/deps/date")
if(EXISTS "${DATE_LIB_DIR}/CMakeLists.txt")
if(EXISTS "${DATE_LIB_DIR}/CMakeLists.txt"
AND NOT DISABLE_TWITCH_TIMESTAMP_VERIFICATION)
set(BUILD_TZ_LIB ON)
if(OS_WINDOWS)
if(CURL_FOUND AND TARGET CURL::libcurl)

View File

@@ -565,6 +565,9 @@ TwitchTokenSettingsDialog::TwitchTokenSettingsDialog(
}
_validateTimestamps->setChecked(settings._validateEventSubTimestamps);
#ifndef VERIFY_TIMESTAMPS
_validateTimestamps->hide();
#endif
_currentToken = settings;