You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

106 lines
4.3 KiB

#include "channelsettingsdialog.h"
#include "../db/db_manager.h"
#include "../transport/gui_bridge.h"
#include "../../lib/mem.h"
extern "C" {
#include "chat/chat_core.h"
}
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
ChannelSettingsDialog::ChannelSettingsDialog(const QString& channelId, DbManager* db, QWidget* parent)
: QDialog(parent)
, m_channelId(channelId)
, m_db(db)
{
setWindowTitle(QStringLiteral("Channel Settings"));
setMinimumWidth(340);
setModal(true);
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(20, 16, 20, 16);
layout->setSpacing(12);
auto* titleLabel = new QLabel(QStringLiteral("Settings for channel"), this);
titleLabel->setStyleSheet("font-weight: bold; font-size: 14px;");
layout->addWidget(titleLabel);
auto* chIdLabel = new QLabel(channelId, this);
chIdLabel->setStyleSheet("color: gray; font-size: 11px;");
chIdLabel->setWordWrap(true);
layout->addWidget(chIdLabel);
layout->addSpacing(8);
m_autoPlayVoice = new QCheckBox(QStringLiteral("Auto-play voice messages on receive"), this);
m_autoPlayVoice->setToolTip(QStringLiteral("Voice messages will play automatically when received. Multiple messages queue up and play sequentially without interrupting current playback."));
layout->addWidget(m_autoPlayVoice);
m_soundOnMessage = new QCheckBox(QStringLiteral("Play sound on incoming message"), this);
m_soundOnMessage->setToolTip(QStringLiteral("Play a notification sound when a message arrives in this channel."));
layout->addWidget(m_soundOnMessage);
m_pttMode = new QCheckBox(QStringLiteral("Push-To-Talk (PTT) mode"), this);
m_pttMode->setToolTip(QStringLiteral("Record voice messages with push-to-talk. (Coming soon)"));
m_pttMode->setEnabled(false);
layout->addWidget(m_pttMode);
layout->addStretch();
auto* btnLayout = new QHBoxLayout();
btnLayout->setSpacing(8);
btnLayout->addStretch();
auto* cancelBtn = new QPushButton(QStringLiteral("Cancel"), this);
cancelBtn->setFixedWidth(90);
cancelBtn->setStyleSheet(
"QPushButton { border: 1px solid palette(mid); border-radius: 4px;"
" padding: 6px 16px; font-size: 13px; background: palette(button); }"
"QPushButton:hover { background: palette(light); }");
connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
btnLayout->addWidget(cancelBtn);
auto* saveBtn = new QPushButton(QStringLiteral("Save"), this);
saveBtn->setFixedWidth(90);
saveBtn->setDefault(true);
saveBtn->setStyleSheet(
"QPushButton { border: none; border-radius: 4px;"
" padding: 6px 16px; font-size: 13px; font-weight: bold;"
" background: #3390EC; color: white; }"
"QPushButton:hover { background: #2B7ED4; }");
connect(saveBtn, &QPushButton::clicked, this, &ChannelSettingsDialog::onSave);
btnLayout->addWidget(saveBtn);
layout->addLayout(btnLayout);
if (m_db && m_db->isOpen()) {
QString autoPlayKey = QStringLiteral("ch_%1_auto_play_voice").arg(channelId);
m_autoPlayVoice->setChecked(m_db->getUiStateInt(autoPlayKey, 0) != 0);
QString soundKey = QStringLiteral("ch_%1_sound_on_message").arg(channelId);
m_soundOnMessage->setChecked(m_db->getUiStateInt(soundKey, 1) != 0);
QString pttKey = QStringLiteral("ch_%1_ptt_mode").arg(channelId);
m_pttMode->setChecked(m_db->getUiStateInt(pttKey, 0) != 0);
}
}
void ChannelSettingsDialog::onSave() {
auto saveKey = [&](const char* suffix, int val) {
QString key = QStringLiteral("ch_%1_%2").arg(m_channelId, QString::fromUtf8(suffix));
QByteArray keyBA = key.toUtf8();
QByteArray valBA = QByteArray::number(val);
size_t klen = (size_t)keyBA.size(), vlen = (size_t)valBA.size();
size_t total = klen + 1 + vlen + 1;
if (total <= 256) {
void* arg = u_malloc(total);
memcpy(arg, keyBA.constData(), klen + 1);
memcpy((char*)arg + klen + 1, valBA.constData(), vlen + 1);
gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg);
}
};
saveKey("auto_play_voice", m_autoPlayVoice->isChecked() ? 1 : 0);
saveKey("sound_on_message", m_soundOnMessage->isChecked() ? 1 : 0);
saveKey("ptt_mode", m_pttMode->isChecked() ? 1 : 0);
accept();
}