mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 23:05:10 +00:00
[ADD/WIP] On-the-fly forms
Still WIP-tier, also I need to make a way to index a multi-option list like a regular array with the forms thing, the current one-at-a-time idea is not great...
This commit is contained in:
parent
91d373addb
commit
0cb19a15d8
4 changed files with 146 additions and 6 deletions
|
|
@ -13,6 +13,7 @@ struct XMPPCommand {
|
|||
|
||||
/* TODO: On-the-fly generation of options */
|
||||
Array *options;
|
||||
XMPPOptionWriter otf;
|
||||
};
|
||||
|
||||
XMPPCommand *
|
||||
|
|
@ -35,8 +36,20 @@ XMPPBasicCmd(char *node, char *name, XMPPCmdCallback callback_funct)
|
|||
/* No options -> no form required */
|
||||
cmd->options = NULL;
|
||||
|
||||
cmd->otf = NULL;
|
||||
|
||||
return cmd;
|
||||
}
|
||||
void
|
||||
XMPPCmdOptionsCreator(XMPPCommand *cmd, XMPPOptionWriter writer)
|
||||
{
|
||||
if (!cmd)
|
||||
{
|
||||
return;
|
||||
}
|
||||
cmd->otf = writer;
|
||||
}
|
||||
|
||||
void
|
||||
XMPPSetFormTitle(XMPPCommand *cmd, char *title)
|
||||
{
|
||||
|
|
@ -95,12 +108,28 @@ XMPPAddOption(XMPPCommand *cmd, XMPPOption *opt)
|
|||
}
|
||||
|
||||
XMLElement *
|
||||
XMPPFormifyCommand(XMPPCommand *cmd)
|
||||
XMPPFormifyCommand(XMPPCommandManager *m, XMPPCommand *cmd, char *from)
|
||||
{
|
||||
XMLElement *x, *field;
|
||||
size_t i;
|
||||
|
||||
if (!cmd || !cmd->options)
|
||||
if (!cmd || !m)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (cmd->otf)
|
||||
{
|
||||
for (i = 0; i < ArraySize(cmd->options); i++)
|
||||
{
|
||||
XMPPOption *opt = ArrayGet(cmd->options, i);
|
||||
XMPPFreeOption(opt);
|
||||
}
|
||||
ArrayFree(cmd->options);
|
||||
cmd->options = NULL;
|
||||
|
||||
cmd->otf(m, cmd, from);
|
||||
}
|
||||
if (!cmd->options)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -152,7 +181,7 @@ XMPPGetCommandDesc(XMPPCommand *cmd)
|
|||
bool
|
||||
XMPPCommandRequiresForm(XMPPCommand *cmd)
|
||||
{
|
||||
return cmd ? !!cmd->options : false;
|
||||
return cmd ? (cmd->otf || !!cmd->options) : false;
|
||||
}
|
||||
void
|
||||
XMPPExecuteCommand(XMPPCommandManager *m, XMPPCommand *cmd, char *from, XMLElement *to, XMLElement *form)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue