Files
mcde/programs/dtchat/ui_main.h
T
lotherk 2f3511ebf2 dtchat: run the configured accounts as adapters in the UI
accounts_run.c loads accounts.json (id, protocol, label, adapter, settings, enabled) and secrets.json (per account id) and starts one DcAdapter per enabled account, pumping the DcLoop from an Xt timeout. Its events go into the model and the panel: state into the status line, conversation (direct/channel/group) and roster entries into the model (roster sets presence), messages into the transcript via dtchat_ui_message_added, presence/typing/errors into the status/dialog, request events into the existing request dialog with the answer routed to that adapter. The UI send hook resolves the selected account (dtchat_ui_current_account) or the account that owns the conversation and calls dc_adapter_send_text; dtchat_accounts_join/_typing expose join and XEP-0085 for menus and tests. Normal GUI runs (not --demo/--local/--perf/--smoke) start with an empty model and the configured accounts; the demo peers are gone in that mode. dtchat-irc is installed next to dtchat and listed in the PLIST; dtchat-xmpp and the demo adapter remain build artifacts. Verified with the fake adapter under Xvfb (accounts fake: starting/online/sent alice/message alice), including the real UI send path (DTCHAT_TEST_UI_SEND), screenshot build/mcde-shots/dtchat-accounts.png; --smoke-test still passes.
2026-11-17 10:22:27 +00:00

80 lines
2.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"
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);
/* 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);
/* ... 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);
/* 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 */