Files
mcde/programs/dtchat/ui_main.h
T
lotherk f0144bc092 dtchat: make the account editor persistent (T2.4)
The dialog now edits real accounts instead of in-memory demo entries: the schema is Label, Protocol (irc/xmpp/telegram/whatsapp/demo), Adapter path, Settings (JSON) and Secrets (JSON). It loads accounts.json/secrets.json through the runtime (label, protocol, adapter, settings, masked secrets), and Save builds the complete accounts/secrets documents for every account, extracts label/protocol/adapter and parses the two JSON fields, then calls the runtime's writer. The runtime saves via dc_store_save_accounts/_secrets (files 0600), swaps its stored JSON, removes deleted accounts from the model, and restarts all adapters from the new set; the UI data pointers are refreshed. Add/Delete/Save semantics are now file-backed. Verified through the real UI under Xvfb: Add filled (Label 'Fake via UI', adapter /tmp/opencode/fake_adapter, settings {"mode":"echo"}), Save wrote both files (0600) and started the fake adapter online; restarting dtchat shows the account and all fields again (screenshots dtchat-accounts-editor.png, dtchat-accounts-loaded.png). In-tree build and harness follow.
2026-11-17 12:23:15 +00:00

97 lines
3.9 KiB
C

/*
* ui_main.h -- dtchat's main window
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*/
#ifndef _Dtchat_ui_main_h
#define _Dtchat_ui_main_h
#include <X11/Intrinsic.h>
#include "dc_internal.h"
#include "ui_accounts.h"
typedef struct DtChatUi DtChatUi;
/* Send text to CONV. Return 0 when it was accepted. */
typedef int (*DtChatSendFn)(void *arg, const char *conv, const char *text);
/* typing state of the person at the input (XEP-0085 / IRC typing) */
typedef void (*DtChatTypingFn)(void *arg, const char *conv, int on);
/* join a channel or MUC room on an account */
typedef void (*DtChatJoinFn)(void *arg, const char *account, const char *conv);
/* MODEL is borrowed; the caller keeps it alive until dtchat_ui_destroy(). */
DtChatUi *dtchat_ui_create(Widget shell, DcModel *model);
void dtchat_ui_destroy(DtChatUi *ui);
/* The toplevel shell, for dialog parents. */
Widget dtchat_ui_shell(const DtChatUi *ui);
/* The account of the conversation in the window, for the send hook. */
const char *dtchat_ui_current_account(const DtChatUi *ui);
/* True when the shell is realized and its map state is IsViewable. */
int dtchat_ui_is_viewable(DtChatUi *ui);
/* Select ACCOUNT/CONV in the roster and show it in the chat. */
void dtchat_ui_select(DtChatUi *ui, const char *account, const char *conv);
/* The local peers shown in the Nearby section (borrowed). */
void dtchat_ui_set_peers(DtChatUi *ui, DcPeers *peers);
void dtchat_ui_select_peer(DtChatUi *ui, const char *id);
int dtchat_ui_is_peer(const DtChatUi *ui, const char *id);
/* The local manager supplies the file sender (T5.8). */
typedef void (*DtChatFileSendFn)(const char *peer_id, const char *path,
void *arg);
void dtchat_ui_set_file_send(DtChatUi *ui, DtChatFileSendFn fn, void *arg);
/* Sends PATH to the open conversation through the file hook (the dialog
* does the same after its OK). */
int dtchat_ui_send_file(DtChatUi *ui, const char *path);
/* ... and the call starter (T6.5/T7.6). */
typedef void (*DtChatCallFn)(const char *peer_id, void *arg);
void dtchat_ui_set_call_hook(DtChatUi *ui, DtChatCallFn fn, void *arg);
/* T2.3 runtime binding. */
void dtchat_ui_refresh(DtChatUi *ui);
void dtchat_ui_message_added(DtChatUi *ui, const char *account,
const char *conv);
int dtchat_ui_send_text(DtChatUi *ui, const char *text);
size_t dtchat_ui_shown_messages(const DtChatUi *ui);
int dtchat_ui_contains(const DtChatUi *ui, const char *needle);
/* T2.2/T2.3 smoke: a conversation is selected, its title and transcript exist. */
int dtchat_ui_smoke(DtChatUi *ui);
/* Route sends through FN (the demo/adapter path); NULL restores the local echo. */
void dtchat_ui_set_send_hook(DtChatUi *ui, DtChatSendFn fn, void *arg);
void dtchat_ui_set_typing_hook(DtChatUi *ui, DtChatTypingFn fn, void *arg);
void dtchat_ui_set_join_hook(DtChatUi *ui, DtChatJoinFn fn, void *arg);
/* the account files and the writer the editor uses (the accounts runtime) */
void dtchat_ui_set_accounts_data(DtChatUi *ui, const DcJson *accounts,
const DcJson *secrets, DtAccountsSaveFn save, void *arg);
void dtchat_ui_show_accounts(DtChatUi *ui);
/* ask for a channel/room and join it (the dialog), or join CONV directly */
void dtchat_ui_join_dialog(DtChatUi *ui);
int dtchat_ui_join(DtChatUi *ui, const char *conv);
/* T2.8 input helpers (the key handler uses them too). */
void dtchat_ui_clear_input(DtChatUi *ui);
int dtchat_ui_history(DtChatUi *ui, int direction); /* -1 up, +1 down */
int dtchat_ui_complete(DtChatUi *ui);
void dtchat_ui_set_input(DtChatUi *ui, const char *text);
int dtchat_ui_input_equals(const DtChatUi *ui, const char *text);
/* The status line. */
void dtchat_ui_set_status(DtChatUi *ui, const char *text);
/* True when the current conversation is ACCOUNT/CONV. */
int dtchat_ui_is_current(const DtChatUi *ui, const char *account,
const char *conv);
/* Append a system line to the transcript. */
void dtchat_ui_append_system(DtChatUi *ui, const char *text);
#endif /* _Dtchat_ui_main_h */