Route MainWindow radio invitations through owned commands and test them
This commit is contained in:
1 parent
0f36248d1e
commit
bc78e0889a
3 files changed
+242
-17
No files matched your search
@@ -811,20 +811,13 @@ void MainWindow::showMemberFiles(const QString& channel, quint64 owner) {
|
||||
m_fileBrowser->setChannel(channel, owner); m_fileBrowser->show(); m_fileBrowser->raise(); m_fileBrowser->activateWindow();
|
||||
}
|
||||
|
||||
/* Все команды рации идут в поток ядра; GUI не читает живые таблицы BGP. */
|
||||
static void postRadioCall(quint64 id, int action, quint64 group = 0, quint64 peer = 0) {
|
||||
auto* inst = gui_bridge_get_inst();
|
||||
if (!inst) { DEBUG_ERROR(DEBUG_CATEGORY_RADIO, "desktop radio call without running core"); return; }
|
||||
auto* req = static_cast<radio_call_request*>(u_calloc(1, sizeof(radio_call_request)));
|
||||
if (!req) { DEBUG_ERROR(DEBUG_CATEGORY_RADIO, "desktop radio call request allocation failed"); return; }
|
||||
req->inst = inst; req->id = id; req->group = group; req->peer = peer; req->action = action;
|
||||
gui_bridge_post_uasync_fn(radio_call_trampoline, req);
|
||||
}
|
||||
|
||||
/* GUI передаёт мосту значения; ядро и время жизни запроса выбирает мост. */
|
||||
void MainWindow::onRadioCallRequested(const QString& channel, quint64 peer) {
|
||||
if (m_radioCallWindow) { m_radioCallWindow->show(); m_radioCallWindow->raise(); return; }
|
||||
quint64 id = QRandomGenerator::global()->generate64();
|
||||
postRadioCall(id ? id : 1, RADIO_CALL_START, channel.toULongLong(), peer);
|
||||
if (gui_bridge_radio_call(GUI_RADIO_CALL_START, id ? id : 1, channel.toULongLong(), peer) < 0)
|
||||
DEBUG_WARN(DEBUG_CATEGORY_RADIO, "desktop radio call start was not queued channel=%s peer=%llu",
|
||||
qPrintable(channel), (unsigned long long)peer);
|
||||
}
|
||||
|
||||
/* Один диалог на незавершённое приглашение; принятая рация живёт своим обычным циклом. */
|
||||
@@ -878,7 +871,7 @@ void MainWindow::onRadioCallEvent(const uint8_t* data, int len) {
|
||||
m_radioCallWindow = nullptr;
|
||||
}
|
||||
if (m_radioCallId == id) return;
|
||||
if (m_radioCallId || !m_activeCalls.isEmpty()) { postRadioCall(id, RADIO_CALL_REJECT_BUSY); return; }
|
||||
if (m_radioCallId || !m_activeCalls.isEmpty()) { gui_bridge_radio_call(GUI_RADIO_CALL_REJECT_BUSY, id, 0, 0); return; }
|
||||
QString name = m_db->getDisplayName(peer);
|
||||
if (name.isEmpty()) name = QStringLiteral("0x%1").arg(peer, 16, 16, QChar('0'));
|
||||
QString channelName = channel;
|
||||
@@ -894,11 +887,11 @@ void MainWindow::onRadioCallEvent(const uint8_t* data, int len) {
|
||||
connect(box, &QMessageBox::buttonClicked, this, [this, id, channel, accept](QAbstractButton* button) {
|
||||
if (m_radioCallId != id) return;
|
||||
m_radioCallAnswered = true;
|
||||
if (button != accept) { postRadioCall(id, RADIO_CALL_DECLINE); return; }
|
||||
if (button != accept) { gui_bridge_radio_call(GUI_RADIO_CALL_DECLINE, id, 0, 0); return; }
|
||||
SoundManager::instance()->stopLoop();
|
||||
m_channelList->selectChannel(channel);
|
||||
bool ready = m_currentChannelId == channel && m_messageList->enableRadio();
|
||||
postRadioCall(id, ready ? RADIO_CALL_ACCEPT : RADIO_CALL_FAIL);
|
||||
gui_bridge_radio_call(ready ? GUI_RADIO_CALL_ACCEPT : GUI_RADIO_CALL_FAIL, id, 0, 0);
|
||||
});
|
||||
} else if (state == RADIO_CALL_WAIT_DECISION) {
|
||||
box->setInformativeText(QCoreApplication::translate("ChatGui", "Subscriber is on a phone call"));
|
||||
@@ -906,10 +899,10 @@ void MainWindow::onRadioCallEvent(const uint8_t* data, int len) {
|
||||
box->addButton(QCoreApplication::translate("ChatGui", "End call"), QMessageBox::RejectRole);
|
||||
connect(box, &QMessageBox::buttonClicked, this, [this, id, proceed](QAbstractButton* button) {
|
||||
if (m_radioCallId != id || button != proceed) return;
|
||||
if (gui_bridge_radio_call(GUI_RADIO_CALL_CONTINUE, id, 0, 0) < 0) return;
|
||||
m_radioCallAnswered = true;
|
||||
m_radioCallId = 0;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_RADIO, "desktop caller overrides phone busy id=%016llx", (unsigned long long)id);
|
||||
postRadioCall(id, RADIO_CALL_CONTINUE);
|
||||
});
|
||||
} else {
|
||||
box->addButton(QMessageBox::Cancel);
|
||||
@@ -919,7 +912,7 @@ void MainWindow::onRadioCallEvent(const uint8_t* data, int len) {
|
||||
if (m_radioCallId == id && !m_radioCallAnswered) {
|
||||
m_radioCallAnswered = true;
|
||||
SoundManager::instance()->stopLoop();
|
||||
postRadioCall(id, incoming ? RADIO_CALL_DECLINE : RADIO_CALL_CANCEL);
|
||||
gui_bridge_radio_call(incoming ? GUI_RADIO_CALL_DECLINE : GUI_RADIO_CALL_CANCEL, id, 0, 0);
|
||||
}
|
||||
});
|
||||
box->show(); box->raise(); box->activateWindow();
|
||||
@@ -927,7 +920,7 @@ void MainWindow::onRadioCallEvent(const uint8_t* data, int len) {
|
||||
if (incoming) {
|
||||
if (m_trayIcon && (!isVisible() || isMinimized()))
|
||||
m_trayIcon->showMessage(QCoreApplication::translate("ChatGui", "Radio call"), box->text());
|
||||
postRadioCall(id, RADIO_CALL_READY);
|
||||
gui_bridge_radio_call(GUI_RADIO_CALL_READY, id, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user