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);
51static void atari_hotlist_finish(struct core_window *cw);
52static void atari_hotlist_keypress(struct core_window *cw,
53 uint32_t ucs4);
54static void atari_hotlist_mouse_action(struct core_window *cw,
56 int x, int y);
57static void atari_hotlist_draw(struct core_window *cw, int x,
58 int y, struct rect *clip,
59 const struct redraw_context *ctx);
60static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]);
61
64 .finish = atari_hotlist_finish,
65 .draw = atari_hotlist_draw,
66 .keypress = atari_hotlist_keypress,
67 .mouse_action = atari_hotlist_mouse_action,
68 .gemtk_user_func = handle_event
69};
70
71static nserror atari_hotlist_init_phase2(struct core_window *cw)
72{
73 NSLOG(netsurf, INFO, "cw:%p", cw);
74 return hotlist_manager_init(cw);
75}
76
77static void atari_hotlist_finish(struct core_window *cw)
78{
79 NSLOG(netsurf, INFO, "cw:%p", cw);
81}
82
83static void atari_hotlist_draw(struct core_window *cw, int x,
84 int y, struct rect *clip,
85 const struct redraw_context *ctx)
86{
87 hotlist_redraw(x, y, clip, ctx);
88}
89
90static void atari_hotlist_keypress(struct core_window *cw, uint32_t ucs4)
91{
92 //GUIWIN *gemtk_win;
93 //GRECT area;
94 NSLOG(netsurf, INFO, "ucs4: %"PRIu32, ucs4);
95 hotlist_keypress(ucs4);
96 //gemtk_win = atari_treeview_get_gemtk_window(cw);
97 //atari_treeview_get_grect(cw, TREEVIEW_AREA_CONTENT, &area);
98 //gemtk_wm_exec_redraw(gemtk_win, &area);
99}
100
101static void atari_hotlist_mouse_action(struct core_window *cw,
103 int x, int y)
104{
105 NSLOG(netsurf, INFO, "x: %d, y: %d\n", x, y);
106
107 hotlist_mouse_action(mouse, x, y);
108}
109
110
111
112static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
113{
114 char *cur_url = NULL;
115 char *cur_title = NULL;
116 short retval = 0;
117 struct atari_treeview_window *tv = NULL;
118 struct core_window *cw;
119 struct gui_window * gw;
120 OBJECT *toolbar;
121 GRECT tb_area;
122 GUIWIN * gemtk_win;
123
124 NSLOG(netsurf, INFO, "gw:%p", win);
125
126 tv = (struct atari_treeview_window*) gemtk_wm_get_user_data(win);
127 cw = (struct core_window *)tv;
128
129 if (ev_out->emo_events & MU_MESAG) {
130 switch (msg[0]) {
131
132 case WM_TOOLBAR:
133 NSLOG(netsurf, INFO, "WM_TOOLBAR");
134
135 toolbar = gemtk_obj_get_tree(TOOLBAR_HOTLIST);
136
137 assert(toolbar);
138 assert(tv);
139
140 switch (msg[4]) {
141 case TOOLBAR_HOTLIST_CREATE_FOLDER:
142 hotlist_add_folder(NULL, 0, 0);
143 break;
144
145 case TOOLBAR_HOTLIST_ADD:
147 if(gw && gw->browser){
148 cur_url = gui_window_get_url(gw);
149 cur_title = gui_window_get_title(gw);
150 // TODO: read language string.
151 cur_title = (cur_title ? cur_title : (char*)"New bookmark");
152 } else {
153 cur_url = (char*)"http://www";
154 }
155 atari_hotlist_add_page(cur_url, cur_title);
156 break;
157
158 case TOOLBAR_HOTLIST_DELETE:
160 break;
161
162 case TOOLBAR_HOTLIST_EDIT:
164 break;
165 }
166
167 gemtk_win = atari_treeview_get_gemtk_window(cw);
168 assert(gemtk_win);
169 toolbar[msg[4]].ob_state &= ~OS_SELECTED;
171 evnt_timer(150);
172 gemtk_wm_exec_redraw(gemtk_win, &tb_area);
173 retval = 1;
174 break;
175
176 case WM_CLOSED:
178 retval = 1;
179 break;
180
181 default: break;
182 }
183 }
184
185 return(retval);
186}
187
188
189
191{
192 if (hl.init == false) {
193 if( strcmp(nsoption_charp(hotlist_file), "") == 0 ){
194 atari_find_resource( (char*)&hl.path, "hotlist", "hotlist" );
195 } else {
196 strncpy( (char*)&hl.path, nsoption_charp(hotlist_file), PATH_MAX-1 );
197 }
198
199 NSLOG(netsurf, INFO, "Hotlist: %s", (char *)&hl.path);
201
202 if( hl.window == NULL ){
203 int flags = ATARI_TREEVIEW_WIDGETS;
204 short handle = -1;
205 OBJECT * tree = gemtk_obj_get_tree(TOOLBAR_HOTLIST);
206 assert( tree );
207
208 handle = wind_create(flags, 0, 0, desk_area.g_w, desk_area.g_h);
209 hl.window = gemtk_wm_add(handle, GEMTK_WM_FLAG_DEFAULTS, NULL);
210 if( hl.window == NULL ) {
211 gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT,
212 "Failed to allocate Hotlist");
213 return;
214 }
215 wind_set_str(handle, WF_NAME, (char*)messages_get("Hotlist"));
216 gemtk_wm_set_toolbar(hl.window, tree, 0, 0);
217 gemtk_wm_unlink(hl.window);
218 tree_hotlist_path = (const char*)&hl.path;
219
221 NULL, flags);
222
223 if (hl.tv == NULL) {
224 /* handle it properly, clean up previous allocs */
225 NSLOG(netsurf, INFO,
226 "Failed to allocate treeview");
227 return;
228 }
229
230 } else {
231
232 }
233 }
234 hl.init = true;
235}
236
238{
239 assert(hl.init);
240 if (hl.init == false) {
241 return;
242 }
243
244 if (atari_treeview_is_open(hl.tv) == false) {
245
246 GRECT pos;
247 pos.g_x = desk_area.g_w - desk_area.g_w / 4;
248 pos.g_y = desk_area.g_y;
249 pos.g_w = desk_area.g_w / 4;
250 pos.g_h = desk_area.g_h;
251
253 } else {
254 wind_set(gemtk_wm_get_handle(hl.window), WF_TOP, 1, 0, 0, 0);
255 }
256}
257
259{
261}
262
264{
265
266 if( hl.init == false) {
267 return;
268 }
269 if( hl.window != NULL ) {
272 wind_delete(gemtk_wm_get_handle(hl.window));
273 gemtk_wm_remove(hl.window);
274 hl.window = NULL;
276 hl.init = false;
277 }
278 NSLOG(netsurf, INFO, "done");
279}
280
282{
284}
285
286struct node;
287
288void atari_hotlist_add_page( const char * url, const char * title )
289{
290 nsurl *nsurl;
291
292 if(hl.tv == NULL)
293 return;
294
296
297 if (nsurl_create(url, &nsurl) != NSERROR_OK)
298 return;
299
300 if (hotlist_has_url(nsurl)) {
301 NSLOG(netsurf, INFO, "URL already added as Bookmark");
303 return;
304 }
305
306 /* doesn't look nice:
307 if( hl.tv->click.x >= 0 && hl.tv->click.y >= 0 ){
308 hotlist_add_entry( nsurl, title, true, hl.tv->click.y );
309 } else {
310
311 }*/
312 //hotlist_add_url(nsurl);
313 hotlist_add_entry(nsurl, title, 0, 0);
315}
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:772
char * gui_window_get_url(struct gui_window *gw)
Definition: gui.c:582
char * gui_window_get_title(struct gui_window *gw)
Definition: gui.c:590
#define PATH_MAX
Definition: gui.h:31
Content handling interface.
bool hotlist_keypress(uint32_t key)
Key press handling.
Definition: hotlist.c:1697
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:1623
void hotlist_mouse_action(browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: hotlist.c:1690
nserror hotlist_fini(void)
Finalise the hotlist.
Definition: hotlist.c:1387
nserror hotlist_manager_init(void *core_window_handle)
Initialise the hotlist manager.
Definition: hotlist.c:1354
void hotlist_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the hotlist.
Definition: hotlist.c:1682
nserror hotlist_add_folder(const char *title, bool at_y, int y)
Add a folder to the hotlist.
Definition: hotlist.c:1660
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:1733
bool hotlist_has_url(nsurl *url)
Check whether given URL is present in hotlist.
Definition: hotlist.c:1493
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:77
const char * tree_hotlist_path
Definition: hotlist.c:45
static nserror atari_hotlist_init_phase2(struct core_window *cw)
Definition: hotlist.c:71
GRECT desk_area
Definition: gui.c:79
struct atari_hotlist hl
Definition: hotlist.c:47
void atari_hotlist_close(void)
Definition: hotlist.c:258
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
Definition: hotlist.c:112
static struct atari_treeview_callbacks atari_hotlist_treeview_callbacks
Definition: hotlist.c:62
void atari_hotlist_open(void)
Definition: hotlist.c:237
static void atari_hotlist_mouse_action(struct core_window *cw, browser_mouse_state mouse, int x, int y)
Definition: hotlist.c:101
void atari_hotlist_add_page(const char *url, const char *title)
Definition: hotlist.c:288
static void atari_hotlist_keypress(struct core_window *cw, uint32_t ucs4)
Definition: hotlist.c:90
void atari_hotlist_destroy(void)
Definition: hotlist.c:263
void atari_hotlist_init(void)
Definition: hotlist.c:190
void atari_hotlist_redraw(void)
Definition: hotlist.c:281
static void atari_hotlist_draw(struct core_window *cw, int x, int y, struct rect *clip, const struct redraw_context *ctx)
Definition: hotlist.c:83
void atari_treeview_delete(struct core_window *cw)
Free the Treeview, but not the gemtk window used for the treeview.
Definition: treeview.c:740
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:602
bool atari_treeview_is_open(struct core_window *cw)
Returns the window "open" state.
Definition: treeview.c:780
void atari_treeview_redraw(struct core_window *cw)
Process all pending redraw requests for a single treeview.
Definition: treeview.c:627
void atari_treeview_close(struct core_window *cw)
Closes (hides) the treeview window.
Definition: treeview.c:804
GUIWIN * atari_treeview_get_gemtk_window(struct core_window *cw)
Get the window manager window handle.
Definition: treeview.c:619
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:547
void atari_treeview_open(struct core_window *cw, GRECT *pos)
Open the treeview window.
Definition: treeview.c:754
@ 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: 1 is primary mouse button.
Definition: mouse.h:52
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
first entry in window list
Definition: gui.c:298
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:331
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357