Новый модуль src/radio (radio/radio_audio/radio_headless) — push-to-talk радио поверх topo-групп, доставка аудио в канал, headless-режим и тесты. Интеграция в chatgui (ptt_hotkey_manager, radio_audio_engine, радионастройки, вызовы) и chatgui-android (RadioAudioEngine, RadioOverlayService, UI).
76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
#include "ptt_hotkey_manager.h"
|
|
#include "radio_audio_engine.h"
|
|
#include "../db/db_manager.h"
|
|
#include "qhotkey.h"
|
|
|
|
#include <QKeySequence>
|
|
#include <QDebug>
|
|
|
|
static PttHotkeyManager* g_pttHotkeys = nullptr;
|
|
|
|
PttHotkeyManager* PttHotkeyManager::instance() {
|
|
if (!g_pttHotkeys) g_pttHotkeys = new PttHotkeyManager();
|
|
return g_pttHotkeys;
|
|
}
|
|
|
|
bool PttHotkeyManager::isSupported() {
|
|
return QHotkey::isPlatformSupported();
|
|
}
|
|
|
|
void PttHotkeyManager::init(DbManager* db) {
|
|
m_db = db;
|
|
reload();
|
|
}
|
|
|
|
QStringList PttHotkeyManager::hotkeys() const {
|
|
return m_seqs;
|
|
}
|
|
|
|
void PttHotkeyManager::setHotkeys(const QStringList& seqs) {
|
|
applyHotkeys(seqs);
|
|
}
|
|
|
|
void PttHotkeyManager::reload() {
|
|
QStringList seqs;
|
|
if (m_db && m_db->isOpen()) {
|
|
const QString raw = m_db->getUiState("radio_ptt_hotkeys");
|
|
if (!raw.isEmpty())
|
|
seqs = raw.split('|', Qt::SkipEmptyParts);
|
|
}
|
|
applyHotkeys(seqs);
|
|
}
|
|
|
|
void PttHotkeyManager::clearHotkeys() {
|
|
for (QHotkey* h : m_hotkeys) {
|
|
h->resetShortcut();
|
|
h->deleteLater();
|
|
}
|
|
m_hotkeys.clear();
|
|
}
|
|
|
|
void PttHotkeyManager::applyHotkeys(const QStringList& seqs) {
|
|
clearHotkeys();
|
|
m_seqs.clear();
|
|
|
|
for (const QString& s : seqs) {
|
|
QKeySequence seq(s);
|
|
if (seq.isEmpty()) continue;
|
|
auto* hk = new QHotkey(seq, true, this);
|
|
if (!hk->isRegistered()) {
|
|
qWarning("PttHotkey: failed to register '%s'", qPrintable(s));
|
|
hk->deleteLater();
|
|
continue;
|
|
}
|
|
connect(hk, &QHotkey::activated, this, []() {
|
|
RadioAudioEngine::instance()->talkBegin();
|
|
});
|
|
connect(hk, &QHotkey::released, this, []() {
|
|
RadioAudioEngine::instance()->talkEnd();
|
|
});
|
|
m_hotkeys.append(hk);
|
|
m_seqs.append(seq.toString());
|
|
}
|
|
|
|
qDebug("PttHotkey: applied %d hotkey(s)", (int)m_hotkeys.size());
|
|
}
|