NetSurf
hotlist.c
Go to the documentation of this file.
1/*
2 * Copyright 2013 Ole Loots <ole@monochrom.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf 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; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <ctype.h>
20#include <string.h>
21#include <stdbool.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <time.h>
25
26#include "utils/log.h"
27#include "utils/messages.h"
28#include "utils/nsoption.h"
29#include "utils/nsurl.h"
30#include "netsurf/inttypes.h"
31#include "netsurf/keypress.h"
32#include "content/content.h"
33#include "desktop/hotlist.h"
34
35#include "atari/gui.h"
36#include "atari/misc.h"
37#include "atari/treeview.h"
38#include "atari/hotlist.h"
39#include "atari/findfile.h"
40#include "atari/gemtk/gemtk.h"
41#include "atari/res/netsurf.rsh"
42
43extern GRECT desk_area;
44
46
48
49/* Setup Atari Treeview Callbacks: */
50static nserror atari_hotlist_init_phase2(struct core_window *cw,
51 struct core_window_callback_table * default_callbacks);
52static void atari_hotlist_finish(struct core_window *cw);
53static void atari_hotlist_keypress(struct core_window *cw,
54 uint32_t ucs4);
55static void atari_hotlist_mouse_action(struct core_window *cw,
57 int x, int y);
58static void atari_hotlist_draw(struct core_window *cw, int x,
59 int y, struct rect *clip,
60 const struct redraw_context *ctx);
61static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]);
62
65 .finish = atari_hotlist_finish,
66 .draw = atari_hotlist_draw,
67 .keypress = atari_hotlist_keypress,
68 .mouse_action = atari_hotlist_mouse_action,
69 .gemtk_user_func = handle_event
70};
71
72static nserror atari_hotlist_init_phase2(struct core_window *cw,
73 struct core_window_callback_table *cb_t)
74{
75 NSLOG(netsurf, INFO, "cw:%p", cw);
76 return hotlist_manager_init(cb_t, cw);
77}
78
79static void atari_hotlist_finish(struct core_window *cw)
80{
81 NSLOG(netsurf, INFO, "cw:%p", cw);
83}
84
85static void atari_hotlist_draw(struct core_window *cw, int x,
86 int y, struct rect *clip,
87 const struct redraw_context *ctx)
88{
89 hotlist_redraw(x, y, clip, ctx);
90}
91
92static void atari_hotlist_keypress(struct core_window *cw, uint32_t ucs4)
93{
94 //GUIWIN *gemtk_win;
95 //GRECT area;
96 NSLOG(netsurf, INFO, "ucs4: %"PRIu32, ucs4);
97 hotlist_keypress(ucs4);
98 //gemtk_win = atari_treeview_get_gemtk_window(cw);
99 //atari_treeview_get_grect(cw, TREEVIEW_AREA_CONTENT, &area);
100 //gemtk_wm_exec_redraw(gemtk_win, &area);
101}
102
103static void atari_hotlist_mouse_action(struct core_window *cw,
105 int x, int y)
106{
107 NSLOG(netsurf, INFO, "x: %d, y: %d\n", x, y);
108
109 hotlist_mouse_action(mouse, x, y);
110}
111
112
113
114static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
115{
116 char *cur_url = NULL;
117 char *cur_title = NULL;
118 short retval = 0;
119 struct atari_treeview_window *tv = NULL;
120 struct core_window *cw;
121 struct gui_window * gw;
122 OBJECT *toolbar;
123 GRECT tb_area;
124 GUIWIN * gemtk_win;
125
126 NSLOG(netsurf, INFO, "gw:%p", win);
127
128 tv = (struct atari_treeview_window*) gemtk_wm_get_user_data(win);
129 cw = (struct core_window *)tv;
130
131 if (ev_out->emo_events & MU_MESAG) {
132 switch (msg[0]) {
133
134 case WM_TOOLBAR:
135 NSLOG(netsurf, INFO, "WM_TOOLBAR");
136
137 toolbar = gemtk_obj_get_tree(TOOLBAR_HOTLIST);
138
139 assert(toolbar);
140 assert(tv);
141
142 switch (msg[4]) {
143 case TOOLBAR_HOTLIST_CREATE_FOLDER:
144 hotlist_add_folder(NULL, 0, 0);
145 break;
146
147 case TOOLBAR_HOTLIST_ADD:
149 if(gw && gw->browser){
150 cur_url = gui_window_get_url(gw);
151 cur_title = gui_window_get_title(gw);
152 // TODO: read language string.
153 cur_title = (cur_title ? cur_title : (char*)"New bookmark");
154 } else {
155 cur_url = (char*)"http://www";
156 }
157 atari_hotlist_add_page(cur_url, cur_title);
158 break;
159
160 case TOOLBAR_HOTLIST_DELETE:
162 break;
163
164 case TOOLBAR_HOTLIST_EDIT:
166 break;
167 }
168
169 gemtk_win = atari_treeview_get_gemtk_window(cw);
170 assert(gemtk_win);
171 toolbar[msg[4]].ob_state &= ~OS_SELECTED;
173 evnt_timer(150);
174 gemtk_wm_exec_redraw(gemtk_win, &tb_area);
175 retval = 1;
176 break;
177
178 case WM_CLOSED:
180 retval = 1;
181 break;
182
183 default: break;
184 }
185 }
186
187 return(retval);
188}
189
190
191
193{
194 if (hl.init == false) {
195 if( strcmp(nsoption_charp(hotlist_file), "") == 0 ){
196 atari_find_resource( (char*)&hl.path, "hotlist", "hotlist" );
197 } else {
198 strncpy( (char*)&hl.path, nsoption_charp(hotlist_file), PATH_MAX-1 );
199 }
200
201 NSLOG(netsurf, INFO, "Hotlist: %s", (char *)&hl.path);
203
204 if( hl.window == NULL ){
205 int flags = ATARI_TREEVIEW_WIDGETS;
206 short handle = -1;
207 OBJECT * tree = gemtk_obj_get_tree(TOOLBAR_HOTLIST);
208 assert( tree );
209
210 handle = wind_create(flags, 0, 0, desk_area.g_w, desk_area.g_h);
211 hl.window = gemtk_wm_add(handle, GEMTK_WM_FLAG_DEFAULTS, NULL);
212 if( hl.window == NULL ) {
213 gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT,
214 "Failed to allocate Hotlist");
215 return;
216 }
217 wind_set_str(handle, WF_NAME, (char*)messages_get("Hotlist"));
218 gemtk_wm_set_toolbar(hl.window, tree, 0, 0);
219 gemtk_wm_unlink(hl.window);
220 tree_hotlist_path = (const char*)&hl.path;
221
223 NULL, flags);
224
225 if (hl.tv == NULL) {
226 /* handle it properly, clean up previous allocs */
227 NSLOG(netsurf, INFO,
228 "Failed to allocate treeview");
229 return;
230 }
231
232 } else {
233
234 }
235 }
236 hl.init = true;
237}
238
240{
241 assert(hl.init);
242 if (hl.init == false) {
243 return;
244 }
245
246 if (atari_treeview_is_open(hl.tv) == false) {
247
248 GRECT pos;
249 pos.g_x = desk_area.g_w - desk_area.g_w / 4;
250 pos.g_y = desk_area.g_y;
251 pos.g_w = desk_area.g_w / 4;
252 pos.g_h = desk_area.g_h;
253
255 } else {
256 wind_set(gemtk_wm_get_handle(hl.window), WF_TOP, 1, 0, 0, 0);
257 }
258}
259
261{
263}
264
266{
267
268 if( hl.init == false) {
269 return;
270 }
271 if( hl.window != NULL ) {
274 wind_delete(gemtk_wm_get_handle(hl.window));
275 gemtk_wm_remove(hl.window);
276 hl.window = NULL;
278 hl.init = false;
279 }
280 NSLOG(netsurf, INFO, "done");
281}
282
284{
286}
287
288struct node;
289
290void atari_hotlist_add_page( const char * url, const char * title )
291{
292 nsurl *nsurl;
293
294 if(hl.tv == NULL)
295 return;
296
298
299 if (nsurl_create(url, &nsurl) != NSERROR_OK)
300 return;
301
302 if (hotlist_has_url(nsurl)) {
303 NSLOG(netsurf, INFO, "URL already added as Bookmark");
305 return;
306 }
307
308 /* doesn't look nice:
309 if( hl.tv->click.x >= 0 && hl.tv->click.y >= 0 ){
310 hotlist_add_entry( nsurl, title, true, hl.tv->click.y );
311 } else {
312
313 }*/
314 //hotlist_add_url(nsurl);
315 hotlist_add_entry(nsurl, title, 0, 0);
317}
char * atari_find_resource(char *buf, const char *filename, const char *def)
Definition: findfile.c:80
struct gui_window * gui_get_input_window(void)
Definition: gui.c:771
char * gui_window_get_url(struct gui_window *gw)
Definition: gui.c:581
char * gui_window_get_title(struct gui_window *gw)
Definition: gui.c:589
#define PATH_MAX
Definition: gui.h:31
Content handling interface.
bool hotlist_keypress(uint32_t key)
Key press handling.
Definition: hotlist.c:1698
nserror hotlist_add_entry(nsurl *url, const char *title, bool at_y, int y)
Add an entry to the hotlist for given Title/URL.
Definition: hotlist.c:1624
void hotlist_mouse_action(browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: hotlist.c:1691
nserror hotlist_fini(void)
Finalise the hotlist.
Definition: hotlist.c:1388
void hotlist_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the hotlist.
Definition: hotlist.c:1683
nserror hotlist_manager_init(struct core_window_callback_table *cw_t, void *core_window_handle)
Initialise the hotlist manager.
Definition: hotlist.c:1354
nserror hotlist_add_folder(const char *title, bool at_y, int y)
Add a folder to the hotlist.
Definition: hotlist.c:1661
nserror hotlist_init(const char *load_path, const char *save_path)
Initialise the hotlist.
Definition: hotlist.c:1290
void hotlist_edit_selection(void)
Edit the first selected node.
Definition: hotlist.c:1734
bool hotlist_has_url(nsurl *url)
Check whether given URL is present in hotlist.
Definition: hotlist.c:1494
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
static void atari_hotlist_finish(struct core_window *cw)
Definition: hotlist.c:79
static nserror atari_hotlist_init_phase2(struct core_window *cw, struct core_window_callback_table *default_callbacks)
Definition: hotlist.c:72
const char * tree_hotlist_path
Definition: hotlist.c:45
GRECT desk_area
Definition: gui.c:78
struct atari_hotlist hl
Definition: hotlist.c:47
void atari_hotlist_close(void)
Definition: hotlist.c:260
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
Definition: hotlist.c:114
static struct atari_treeview_callbacks atari_hotlist_treeview_callbacks
Definition: hotlist.c:63
void atari_hotlist_open(void)
Definition: hotlist.c:239
static void atari_hotlist_mouse_action(struct core_window *cw, browser_mouse_state mouse, int x, int y)
Definition: hotlist.c:103
void atari_hotlist_add_page(const char *url, const char *title)
Definition: hotlist.c:290
static void atari_hotlist_keypress(struct core_window *cw, uint32_t ucs4)
Definition: hotlist.c:92
void atari_hotlist_destroy(void)
Definition: hotlist.c:265
void atari_hotlist_init(void)
Definition: hotlist.c:192
void atari_hotlist_redraw(void)
Definition: hotlist.c:283
static void atari_hotlist_draw(struct core_window *cw, int x, int y, struct rect *clip, const struct redraw_context *ctx)
Definition: hotlist.c:85
void atari_treeview_delete(struct core_window *cw)
Free the Treeview, but not the gemtk window used for the treeview.
Definition: treeview.c:739
void atari_treeview_get_grect(struct core_window *cw, enum treeview_area_e mode, GRECT *dest)
Get an specific area inside the window.
Definition: treeview.c:601
bool atari_treeview_is_open(struct core_window *cw)
Returns the window "open" state.
Definition: treeview.c:779
void atari_treeview_redraw(struct core_window *cw)
Process all pending redraw requests for a single treeview.
Definition: treeview.c:626
void atari_treeview_close(struct core_window *cw)
Closes (hides) the treeview window.
Definition: treeview.c:803
GUIWIN * atari_treeview_get_gemtk_window(struct core_window *cw)
Get the window manager window handle.
Definition: treeview.c:618
struct core_window * atari_treeview_create(GUIWIN *win, struct atari_treeview_callbacks *callbacks, void *user_data, uint32_t flags)
Initalize an window to be an treeview window.
Definition: treeview.c:546
void atari_treeview_open(struct core_window *cw, GRECT *pos)
Open the treeview window.
Definition: treeview.c:753
@ TREEVIEW_AREA_TOOLBAR
Definition: treeview.h:38
#define ATARI_TREEVIEW_WIDGETS
Default AES Window widgets for a treeview window, can be passed to atari_treeview_create as the flags...
Definition: treeview.h:32
browser_mouse_state
Mouse state.
Definition: mouse.h:43
Netsurf additional integer type formatting macros.
Interface to key press operations.
@ NS_KEY_DELETE_LEFT
Definition: keypress.h:35
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
NetSurf URL handling (interface).
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
Interface to utility string handling.
GUIWIN * window
Definition: hotlist.h:34
bool init
Definition: hotlist.h:37
struct core_window * tv
Definition: hotlist.h:36
char path[PATH_MAX]
Definition: hotlist.h:38
atari_treeview_init2_callback init_phase2
Definition: treeview.h:60
Callbacks to achieve various core window functionality.
Definition: core_window.h:51
first entry in window list
Definition: gui.c:296
struct fbtk_widget_s * toolbar
Definition: gui.h:46
struct s_browser * browser
Definition: gui.h:149
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
Interface to time operations.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:297
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357