diff options
author | jcid <devnull@localhost> | 2007-10-07 00:36:34 +0200 |
---|---|---|
committer | jcid <devnull@localhost> | 2007-10-07 00:36:34 +0200 |
commit | 93715c46a99c96d6c866968312691ec9ab0f6a03 (patch) | |
tree | 573f19ec6aa740844f53a7c0eb7114f04096bf64 /src/bookmark.c |
Initial revision
Diffstat (limited to 'src/bookmark.c')
-rw-r--r-- | src/bookmark.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/bookmark.c b/src/bookmark.c new file mode 100644 index 00000000..af37bfed --- /dev/null +++ b/src/bookmark.c @@ -0,0 +1,89 @@ +/* + * File: bookmark.c + * + * Copyright 2002 Jorge Arellano Cid <jcid@dillo.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + */ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "msg.h" +#include "history.h" +#include "capi.h" +#include "bookmark.h" /* for prototypes */ +#include "../dpip/dpip.h" + + + +/* + * Have a short chat with the bookmarks server, + * and finally ask it to add a new bookmark. + * (this is an example of dpi chat) + */ +void a_Bookmarks_chat_add(BrowserWindow *Bw, char *Cmd, char *answer) +{ + static char *cmd1 = NULL, *cmd2 = NULL, *cmd3 = NULL, *cmd4 = NULL; + static BrowserWindow *bw = NULL; + + if (!cmd1) { + cmd1 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Hi server"); + cmd2 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", + "I want to set a bookmark"); + cmd3 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Sure it is!"); + } + + _MSG("a_Bookmarks_chat_add\n answer=%s\n", answer ? answer : "(null)"); + + if (Bw) + bw = Bw; + if (!cmd4 && Cmd) + cmd4 = dStrdup(Cmd); + + if (!answer) { + a_Capi_dpi_send_cmd(NULL, bw, cmd1, "bookmarks", 1); + + } else { + /* we have an answer */ + if (answer) { + if (*answer == 'H') { + /* "Hi browser" */ + a_Capi_dpi_send_cmd(NULL, bw, cmd2, "bookmarks", 0); + } else if (*answer == 'I') { + /* "Is it worth?" */ + a_Capi_dpi_send_cmd(NULL, bw, cmd3, "bookmarks", 0); + } else if (*answer == 'O') { + /* "OK, send it!" */ + a_Capi_dpi_send_cmd(NULL, bw, cmd4, "bookmarks", 0); + dFree(cmd4); + cmd4 = NULL; + } + } + } +} + +/* + * Add the new bookmark through the bookmarks server + */ +void a_Bookmarks_add(BrowserWindow *bw, DilloUrl *url) +{ + const char *title; + char *cmd; + + dReturn_if_fail(url != NULL); + + /* if the page has no title, we'll use the url string */ + title = a_History_get_title_by_url(url, 1); + + cmd = a_Dpip_build_cmd("cmd=%s url=%s title=%s", + "add_bookmark", URL_STR(url), title); + a_Bookmarks_chat_add(bw, cmd, NULL); + dFree(cmd); +} + |