annotate src/bookmark.c @ 2048:5060d415a85a

clickable menu items (even those introducing submenus) MUST have callbacks I clicked on the "Panel size" item itself instead of any of the options in its submenu, and: Segfault!
author corvid <corvid@lavabit.com>
date Thu, 26 May 2011 02:51:18 +0000
parents 94bca98ac942
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: bookmark.c
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 11
diff changeset
4 * Copyright 2002-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 #include <stdlib.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 #include "msg.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15 #include "history.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 #include "capi.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17 #include "bookmark.h" /* for prototypes */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #include "../dpip/dpip.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 * Have a short chat with the bookmarks server,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 * and finally ask it to add a new bookmark.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 * (this is an example of dpi chat)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 void a_Bookmarks_chat_add(BrowserWindow *Bw, char *Cmd, char *answer)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 static char *cmd1 = NULL, *cmd2 = NULL, *cmd3 = NULL, *cmd4 = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 static BrowserWindow *bw = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 if (!cmd1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 cmd1 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Hi server");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 cmd2 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 "I want to set a bookmark");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 cmd3 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Sure it is!");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 _MSG("a_Bookmarks_chat_add\n answer=%s\n", answer ? answer : "(null)");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 if (Bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 bw = Bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43 if (!cmd4 && Cmd)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 cmd4 = dStrdup(Cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 if (!answer) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 a_Capi_dpi_send_cmd(NULL, bw, cmd1, "bookmarks", 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 /* we have an answer */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 if (answer) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 if (*answer == 'H') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 /* "Hi browser" */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 a_Capi_dpi_send_cmd(NULL, bw, cmd2, "bookmarks", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 } else if (*answer == 'I') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 /* "Is it worth?" */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 a_Capi_dpi_send_cmd(NULL, bw, cmd3, "bookmarks", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 } else if (*answer == 'O') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 /* "OK, send it!" */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 a_Capi_dpi_send_cmd(NULL, bw, cmd4, "bookmarks", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 dFree(cmd4);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 cmd4 = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 * Add the new bookmark through the bookmarks server
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 */
11
4a5942beffdf Added some "const" qualifiers.
jcid
parents: 0
diff changeset
71 void a_Bookmarks_add(BrowserWindow *bw, const DilloUrl *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 const char *title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 char *cmd;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 dReturn_if_fail(url != NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 /* if the page has no title, we'll use the url string */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 title = a_History_get_title_by_url(url, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 cmd = a_Dpip_build_cmd("cmd=%s url=%s title=%s",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 "add_bookmark", URL_STR(url), title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 a_Bookmarks_chat_add(bw, cmd, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 dFree(cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86