Include subgroup rename command used by the member context menu
This commit is contained in:
1 parent
80c645c982
commit
f2529fd624
2 files changed
+30
No files matched your search
@@ -25,6 +25,7 @@ extern "C" {
|
||||
class DevgroupDialog;
|
||||
static QPointer<DevgroupDialog> active;
|
||||
static QHash<quint64, QPointer<QPushButton>> leaveRequests;
|
||||
static QHash<quint64, QPointer<QWidget>> renameRequests;
|
||||
static quint64 nextRequest = 0;
|
||||
static QPointer<QWidget> invitationWindow;
|
||||
static quint64 statusRequest = 0, lastAutomaticSnapshot = 0;
|
||||
@@ -92,6 +93,15 @@ static void devgroupResult(const uint8_t* data, int len) {
|
||||
} else {
|
||||
if (len >= 9) {
|
||||
quint64 id = 0; for (int i = 0; i < 8; ++i) id |= quint64(data[i]) << (8*i);
|
||||
if (renameRequests.contains(id)) {
|
||||
const auto parent = renameRequests.take(id);
|
||||
if (!data[8]) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CHAT, "devgroup UI: rename refused");
|
||||
if (parent) QMessageBox::warning(parent, QCoreApplication::translate("ChatGui", "Rename"),
|
||||
QCoreApplication::translate("ChatGui", "Could not rename device group"));
|
||||
} else DEBUG_INFO(DEBUG_CATEGORY_CHAT, "devgroup UI: group renamed");
|
||||
return;
|
||||
}
|
||||
if (leaveRequests.contains(id)) {
|
||||
const auto button = leaveRequests.take(id);
|
||||
if (!data[8]) {
|
||||
@@ -203,3 +213,21 @@ void disconnectMyDevice(QPushButton* button) {
|
||||
}
|
||||
leaveRequests.insert(id, button); button->setEnabled(false);
|
||||
}
|
||||
|
||||
void renameMyDeviceGroup(QWidget* parent, const QString& name) {
|
||||
const auto bytes = name.toUtf8();
|
||||
if (bytes.isEmpty() || bytes.size() > 63 || bytes.contains('\0')) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CHAT, "devgroup UI: rename invalid name bytes=%lld", (long long)bytes.size()); return;
|
||||
}
|
||||
auto* req = static_cast<chat_devgroup_request*>(u_calloc(1, sizeof(chat_devgroup_request)));
|
||||
if (!req) { DEBUG_ERROR(DEBUG_CATEGORY_CHAT, "devgroup UI: rename allocation failed"); return; }
|
||||
req->inst = gui_bridge_get_inst(); req->action = CHAT_DEVGROUP_RENAME; req->request_id = ++nextRequest;
|
||||
memcpy(req->text, bytes.constData(), bytes.size());
|
||||
const quint64 id = req->request_id; gui_bridge_set_devgroup_result_cb(devgroupResult);
|
||||
if (gui_bridge_post_uasync_owned_fn(chat_devgroup_trampoline, req) < 0) {
|
||||
u_free(req); DEBUG_WARN(DEBUG_CATEGORY_CHAT, "devgroup UI: rename enqueue failed");
|
||||
QMessageBox::warning(parent, QCoreApplication::translate("ChatGui", "Rename"), DevgroupDialog::tr("Core unavailable")); return;
|
||||
}
|
||||
renameRequests.insert(id, parent);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CHAT, "devgroup UI: rename submitted name_bytes=%lld", (long long)bytes.size());
|
||||
}
|
||||
@@ -11,4 +11,6 @@ void initDevgroupUi(QWidget* window);
|
||||
void inviteMyDevice(QWidget* parent, const QString& channel, quint64 peer);
|
||||
/* Отключить self; кнопка блокируется до результата, при отказе восстанавливается и показывается ошибка. */
|
||||
void disconnectMyDevice(QPushButton* button);
|
||||
/* Отправить новое имя своей группы в ядро; результат/ошибка привязаны к живому окну parent. */
|
||||
void renameMyDeviceGroup(QWidget* parent, const QString& name);
|
||||
#endif
|
||||
Reference in new issue
Block a user