Dillo v3.1.1-91-g6d5b3ee3
Loading...
Searching...
No Matches
bookmark.c
Go to the documentation of this file.
1/*
2 * File: bookmark.c
3 *
4 * Copyright 2002-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
12#include <stdlib.h>
13
14#include "msg.h"
15#include "history.h"
16#include "capi.h"
17#include "bookmark.h" /* for prototypes */
18#include "../dpip/dpip.h"
19
20
21
27void a_Bookmarks_chat_add(BrowserWindow *Bw, char *Cmd, char *answer)
28{
29 static char *cmd1 = NULL, *cmd2 = NULL, *cmd3 = NULL, *cmd4 = NULL;
30 static BrowserWindow *bw = NULL;
31
32 if (!cmd1) {
33 cmd1 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Hi server");
34 cmd2 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat",
35 "I want to set a bookmark");
36 cmd3 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Sure it is!");
37 }
38
39 _MSG("a_Bookmarks_chat_add\n answer=%s\n", answer ? answer : "(null)");
40
41 if (Bw)
42 bw = Bw;
43 if (!cmd4 && Cmd)
44 cmd4 = dStrdup(Cmd);
45
46 if (!answer) {
47 a_Capi_dpi_send_cmd(NULL, bw, cmd1, "bookmarks", 1);
48
49 } else {
50 /* we have an answer */
51 if (answer) {
52 if (*answer == 'H') {
53 /* "Hi browser" */
54 a_Capi_dpi_send_cmd(NULL, bw, cmd2, "bookmarks", 0);
55 } else if (*answer == 'I') {
56 /* "Is it worth?" */
57 a_Capi_dpi_send_cmd(NULL, bw, cmd3, "bookmarks", 0);
58 } else if (*answer == 'O') {
59 /* "OK, send it!" */
60 a_Capi_dpi_send_cmd(NULL, bw, cmd4, "bookmarks", 0);
61 dFree(cmd4);
62 cmd4 = NULL;
63 }
64 }
65 }
66}
67
72{
73 const char *title;
74 char *cmd;
75
76 dReturn_if_fail(url != NULL);
77
78 /* if the page has no title, we'll use the url string */
79 title = a_History_get_title_by_url(url, 1);
80
81 cmd = a_Dpip_build_cmd("cmd=%s url=%s title=%s",
82 "add_bookmark", URL_STR(url), title);
83 a_Bookmarks_chat_add(bw, cmd, NULL);
84 dFree(cmd);
85}
86
void a_Bookmarks_add(BrowserWindow *bw, const DilloUrl *url)
Add the new bookmark through the bookmarks server.
Definition bookmark.c:71
void a_Bookmarks_chat_add(BrowserWindow *Bw, char *Cmd, char *answer)
Have a short chat with the bookmarks server, and finally ask it to add a new bookmark.
Definition bookmark.c:27
#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:611
void dFree(void *mem)
Definition dlib.c:68
char * dStrdup(const char *s)
Definition dlib.c:77
#define dReturn_if_fail(expr)
Definition dlib.h:72
char * a_Dpip_build_cmd(const char *format,...)
Printf like function for building dpip commands.
Definition dpip.c:83
const char * a_History_get_title_by_url(const DilloUrl *url, int force)
Return the title field (by url) ('force' returns URL_STR when there's no title)
Definition history.c:110
Contains the specific data for a single window.
Definition bw.h:27
Definition url.h:88
#define URL_STR(u)
Definition url.h:76