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.
33 lines
1.2 KiB
C
33 lines
1.2 KiB
C
/*
|
|
* ui_accounts.h -- the generic account editor of dtchat
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*/
|
|
#ifndef _Dtchat_ui_accounts_h
|
|
#define _Dtchat_ui_accounts_h
|
|
|
|
#include <X11/Intrinsic.h>
|
|
|
|
#include "dc_internal.h"
|
|
|
|
typedef struct DtAccountsDialog DtAccountsDialog;
|
|
typedef void (*DtAccountsClosedFn)(void *arg);
|
|
/* write the accounts and secrets (the runtime owns the files) */
|
|
typedef int (*DtAccountsSaveFn)(void *arg, const DcJson *accounts,
|
|
const DcJson *secrets);
|
|
|
|
/*
|
|
* Build the account list and the settings form from SCHEMA (the adapter's
|
|
* "settings" array). The dialog copies the schema; the caller may free it
|
|
* after the call. CLOSED is called when the dialog is closed, before the
|
|
* widgets are destroyed. MODEL is borrowed.
|
|
*/
|
|
DtAccountsDialog *dtchat_accounts_dialog_create(Widget parent, DcModel *model,
|
|
const DcJson *schema, const DcJson *accounts, const DcJson *secrets,
|
|
DtAccountsSaveFn save, void *save_arg, DtAccountsClosedFn closed,
|
|
void *arg);
|
|
void dtchat_accounts_dialog_destroy(DtAccountsDialog *dialog);
|
|
Widget dtchat_accounts_dialog_shell(const DtAccountsDialog *dialog);
|
|
|
|
#endif /* _Dtchat_ui_accounts_h */
|