Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
dpiapi.c
Go to the documentation of this file.
1/*
2 * File: dpiapi.c
3 *
4 * Copyright (C) 2004-2007 Jorge Arellano Cid <jcid@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 */
11
16#include "msg.h"
17#include "bw.h"
18#include "capi.h"
19#include "dpiapi.h" /* for prototypes */
20#include "dialog.hh"
21#include "../dpip/dpip.h"
22
23
24//----------------------------------------------------------------------------
25// Dialog interface
26//
27
28/* This variable can be eliminated as a parameter with a cleaner API. */
29static char *dialog_server = NULL;
30
31
35static void Dpiapi_dialog_answer_cb(BrowserWindow *bw, int answer)
36{
37 char *cmd, numstr[16];
38
39 /* make dpip tag with the answer */
40 snprintf(numstr, 16, "%d", answer);
41 cmd = a_Dpip_build_cmd("cmd=%s to_cmd=%s msg=%s",
42 "answer", "dialog", numstr);
43
44 /* Send answer */
45 a_Capi_dpi_send_cmd(NULL, bw, cmd, dialog_server, 0);
46 dFree(cmd);
47}
48
52void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag)
53{
54 char *title, *msg, *alt1, *alt2, *alt3, *alt4, *alt5;
55 size_t dpip_tag_len;
56 int ret;
57
58 _MSG("a_Dpiapi_dialog:\n");
59 _MSG(" dpip_tag: %s\n", dpip_tag);
60
61 /* set the module scoped variable */
62 dialog_server = server;
63
64 /* other options can be parsed the same way */
65 dpip_tag_len = strlen(dpip_tag);
66 title = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "title");
67 msg = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "msg");
68 alt1 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt1");
69 alt2 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt2");
70 alt3 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt3");
71 alt4 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt4");
72 alt5 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt5");
73
74 ret = a_Dialog_choice(title, msg, alt1, alt2, alt3, alt4, alt5, NULL);
75 /* As choice is modal, call the callback function directly. */
77
78 dFree(alt1); dFree(alt2); dFree(alt3); dFree(alt4); dFree(alt5);
79 dFree(title); dFree(msg);
80}
81
#define _MSG(...)
Definition bookmarks.c:45
int a_Capi_dpi_send_cmd(DilloUrl *url, void *bw, char *cmd, char *server, int flags)
Send a dpi cmd.
Definition capi.c:613
int a_Dialog_choice(const char *title, const char *msg,...)
Make a question-dialog with a question and alternatives.
Definition dialog.cc:342
void dFree(void *mem)
Definition dlib.c:68
static void Dpiapi_dialog_answer_cb(BrowserWindow *bw, int answer)
Generic callback function for dpip dialogs.
Definition dpiapi.c:35
static char * dialog_server
Definition dpiapi.c:29
void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag)
Process a dpip "dialog" command from any dpi.
Definition dpiapi.c:52
char * a_Dpip_build_cmd(const char *format,...)
Printf like function for building dpip commands.
Definition dpip.c:83
char * a_Dpip_get_attr_l(const char *tag, size_t tagsize, const char *attrname)
Task: given a tag, its size and an attribute name, return the attribute value (stuffing of ' is remov...
Definition dpip.c:134
Contains the specific data for a single window.
Definition bw.h:27