2014-05-20 20:48:51 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Ole Loots <ole@monochrom.net>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-01-06 00:02:22 +03:00
|
|
|
*/
|
2013-09-17 04:10:35 +04:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2014-10-17 00:23:51 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
2013-09-17 04:10:35 +04:00
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/hlcache.h"
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "desktop/hotlist.h"
|
|
|
|
#include "desktop/tree.h"
|
2013-09-21 07:29:04 +04:00
|
|
|
#include "desktop/core_window.h"
|
2014-10-17 00:23:51 +04:00
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
#include "atari/gui.h"
|
|
|
|
#include "atari/misc.h"
|
|
|
|
#include "atari/treeview.h"
|
|
|
|
#include "atari/hotlist.h"
|
|
|
|
#include "atari/findfile.h"
|
|
|
|
#include "atari/gemtk/gemtk.h"
|
|
|
|
#include "atari/res/netsurf.rsh"
|
|
|
|
|
|
|
|
extern GRECT desk_area;
|
|
|
|
|
|
|
|
struct atari_hotlist hl;
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
/* Setup Atari Treeview Callbacks: */
|
|
|
|
static nserror atari_hotlist_init_phase2(struct core_window *cw,
|
2015-05-28 11:11:32 +03:00
|
|
|
struct core_window_callback_table * default_callbacks);
|
2013-09-21 07:29:04 +04:00
|
|
|
static void atari_hotlist_finish(struct core_window *cw);
|
|
|
|
static void atari_hotlist_keypress(struct core_window *cw,
|
2015-05-28 11:11:32 +03:00
|
|
|
uint32_t ucs4);
|
2013-09-21 07:29:04 +04:00
|
|
|
static void atari_hotlist_mouse_action(struct core_window *cw,
|
2015-05-28 11:11:32 +03:00
|
|
|
browser_mouse_state mouse,
|
|
|
|
int x, int y);
|
2013-09-21 07:29:04 +04:00
|
|
|
static void atari_hotlist_draw(struct core_window *cw, int x,
|
2015-05-28 11:11:32 +03:00
|
|
|
int y, struct rect *clip,
|
|
|
|
const struct redraw_context *ctx);
|
2013-09-21 07:29:04 +04:00
|
|
|
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]);
|
|
|
|
|
|
|
|
static struct atari_treeview_callbacks atari_hotlist_treeview_callbacks = {
|
|
|
|
.init_phase2 = atari_hotlist_init_phase2,
|
|
|
|
.finish = atari_hotlist_finish,
|
|
|
|
.draw = atari_hotlist_draw,
|
|
|
|
.keypress = atari_hotlist_keypress,
|
|
|
|
.mouse_action = atari_hotlist_mouse_action,
|
|
|
|
.gemtk_user_func = handle_event
|
|
|
|
};
|
|
|
|
|
|
|
|
static nserror atari_hotlist_init_phase2(struct core_window *cw,
|
2015-05-28 11:11:32 +03:00
|
|
|
struct core_window_callback_table *cb_t)
|
2013-09-21 07:29:04 +04:00
|
|
|
{
|
2016-01-22 17:38:12 +03:00
|
|
|
LOG("cw:%p", cw);
|
2013-09-21 07:29:04 +04:00
|
|
|
return(hotlist_init(cb_t, cw, hl.path));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void atari_hotlist_finish(struct core_window *cw)
|
|
|
|
{
|
2016-01-22 17:38:12 +03:00
|
|
|
LOG("cw:%p", cw);
|
2013-09-21 07:29:04 +04:00
|
|
|
hotlist_fini(hl.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void atari_hotlist_draw(struct core_window *cw, int x,
|
2015-05-28 11:11:32 +03:00
|
|
|
int y, struct rect *clip,
|
|
|
|
const struct redraw_context *ctx)
|
2013-09-21 07:29:04 +04:00
|
|
|
{
|
|
|
|
hotlist_redraw(x, y, clip, ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void atari_hotlist_keypress(struct core_window *cw, uint32_t ucs4)
|
|
|
|
{
|
2013-09-26 03:24:49 +04:00
|
|
|
GUIWIN *gemtk_win;
|
|
|
|
GRECT area;
|
2016-04-30 13:34:45 +03:00
|
|
|
LOG("ucs4: %"PRIu32 , ucs4);
|
2013-09-21 07:29:04 +04:00
|
|
|
hotlist_keypress(ucs4);
|
2013-09-26 03:24:49 +04:00
|
|
|
gemtk_win = atari_treeview_get_gemtk_window(cw);
|
|
|
|
atari_treeview_get_grect(cw, TREEVIEW_AREA_CONTENT, &area);
|
|
|
|
//gemtk_wm_exec_redraw(gemtk_win, &area);
|
2013-09-21 07:29:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void atari_hotlist_mouse_action(struct core_window *cw,
|
2015-05-28 11:11:32 +03:00
|
|
|
browser_mouse_state mouse,
|
|
|
|
int x, int y)
|
2013-09-21 07:29:04 +04:00
|
|
|
{
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("x: %d, y: %d\n", x, y);
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2014-05-20 20:51:41 +04:00
|
|
|
hotlist_mouse_action(mouse, x, y);
|
2013-09-21 07:29:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
|
|
|
|
{
|
2013-09-21 07:29:04 +04:00
|
|
|
char *cur_url = NULL;
|
|
|
|
char *cur_title = NULL;
|
2013-09-26 03:24:49 +04:00
|
|
|
short retval = 0;
|
|
|
|
struct atari_treeview_window *tv = NULL;
|
|
|
|
struct core_window *cw;
|
|
|
|
struct gui_window * gw;
|
2013-09-22 05:10:12 +04:00
|
|
|
OBJECT *toolbar;
|
2013-09-26 03:24:49 +04:00
|
|
|
GRECT tb_area;
|
|
|
|
GUIWIN * gemtk_win;
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2016-01-22 17:38:12 +03:00
|
|
|
LOG("gw:%p", win);
|
2013-09-17 04:10:35 +04:00
|
|
|
|
2013-09-22 05:10:12 +04:00
|
|
|
tv = (struct atari_treeview_window*) gemtk_wm_get_user_data(win);
|
|
|
|
cw = (struct core_window *)tv;
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
if (ev_out->emo_events & MU_MESAG) {
|
2013-09-17 04:10:35 +04:00
|
|
|
switch (msg[0]) {
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
case WM_TOOLBAR:
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("WM_TOOLBAR");
|
2015-05-28 11:11:32 +03:00
|
|
|
|
|
|
|
toolbar = gemtk_obj_get_tree(TOOLBAR_HOTLIST);
|
|
|
|
|
|
|
|
assert(toolbar);
|
|
|
|
assert(tv);
|
|
|
|
|
|
|
|
switch (msg[4]) {
|
|
|
|
case TOOLBAR_HOTLIST_CREATE_FOLDER:
|
|
|
|
hotlist_add_folder(NULL, 0, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOOLBAR_HOTLIST_ADD:
|
|
|
|
gw = gui_get_input_window();
|
|
|
|
if(gw && gw->browser){
|
|
|
|
cur_url = gui_window_get_url(gw);
|
|
|
|
cur_title = gui_window_get_title(gw);
|
|
|
|
// TODO: read language string.
|
|
|
|
cur_title = (cur_title ? cur_title : (char*)"New bookmark");
|
|
|
|
} else {
|
|
|
|
cur_url = (char*)"http://www";
|
2013-09-17 04:10:35 +04:00
|
|
|
}
|
2015-05-28 11:11:32 +03:00
|
|
|
atari_hotlist_add_page(cur_url, cur_title);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOOLBAR_HOTLIST_DELETE:
|
|
|
|
hotlist_keypress(NS_KEY_DELETE_LEFT);
|
|
|
|
break;
|
2013-09-17 04:10:35 +04:00
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
case TOOLBAR_HOTLIST_EDIT:
|
|
|
|
hotlist_edit_selection();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gemtk_win = atari_treeview_get_gemtk_window(cw);
|
|
|
|
assert(gemtk_win);
|
|
|
|
toolbar[msg[4]].ob_state &= ~OS_SELECTED;
|
|
|
|
atari_treeview_get_grect(cw, TREEVIEW_AREA_TOOLBAR, &tb_area);
|
|
|
|
evnt_timer(150);
|
|
|
|
gemtk_wm_exec_redraw(gemtk_win, &tb_area);
|
|
|
|
retval = 1;
|
2013-09-17 04:10:35 +04:00
|
|
|
break;
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
case WM_CLOSED:
|
|
|
|
atari_hotlist_close();
|
|
|
|
retval = 1;
|
2013-09-17 04:10:35 +04:00
|
|
|
break;
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
default: break;
|
2013-09-17 04:10:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 03:24:49 +04:00
|
|
|
return(retval);
|
2013-09-17 04:10:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void atari_hotlist_init(void)
|
|
|
|
{
|
|
|
|
if (hl.init == false) {
|
|
|
|
if( strcmp(nsoption_charp(hotlist_file), "") == 0 ){
|
|
|
|
atari_find_resource( (char*)&hl.path, "hotlist", "hotlist" );
|
|
|
|
} else {
|
|
|
|
strncpy( (char*)&hl.path, nsoption_charp(hotlist_file), PATH_MAX-1 );
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Hotlist: %s", (char *)&hl.path);
|
2013-09-17 04:10:35 +04:00
|
|
|
|
|
|
|
if( hl.window == NULL ){
|
|
|
|
int flags = ATARI_TREEVIEW_WIDGETS;
|
|
|
|
short handle = -1;
|
|
|
|
OBJECT * tree = gemtk_obj_get_tree(TOOLBAR_HOTLIST);
|
|
|
|
assert( tree );
|
|
|
|
|
|
|
|
handle = wind_create(flags, 0, 0, desk_area.g_w, desk_area.g_h);
|
|
|
|
hl.window = gemtk_wm_add(handle, GEMTK_WM_FLAG_DEFAULTS, NULL);
|
|
|
|
if( hl.window == NULL ) {
|
|
|
|
gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT,
|
2015-05-28 11:11:32 +03:00
|
|
|
"Failed to allocate Hotlist");
|
2013-09-17 04:10:35 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
wind_set_str(handle, WF_NAME, (char*)messages_get("Hotlist"));
|
|
|
|
gemtk_wm_set_toolbar(hl.window, tree, 0, 0);
|
|
|
|
gemtk_wm_unlink(hl.window);
|
|
|
|
tree_hotlist_path = (const char*)&hl.path;
|
2013-09-21 07:29:04 +04:00
|
|
|
|
|
|
|
hl.tv = atari_treeview_create(hl.window, &atari_hotlist_treeview_callbacks,
|
2015-05-28 11:11:32 +03:00
|
|
|
NULL, flags);
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
if (hl.tv == NULL) {
|
|
|
|
/* handle it properly, clean up previous allocs */
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Failed to allocate treeview");
|
2013-09-17 04:10:35 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hl.init = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void atari_hotlist_open(void)
|
|
|
|
{
|
2013-09-21 07:29:04 +04:00
|
|
|
assert(hl.init);
|
|
|
|
if (hl.init == false) {
|
2013-09-17 04:10:35 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
if (atari_treeview_is_open(hl.tv) == false) {
|
2013-09-17 04:10:35 +04:00
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
GRECT pos;
|
|
|
|
pos.g_x = desk_area.g_w - desk_area.g_w / 4;
|
|
|
|
pos.g_y = desk_area.g_y;
|
|
|
|
pos.g_w = desk_area.g_w / 4;
|
|
|
|
pos.g_h = desk_area.g_h;
|
2013-09-17 04:10:35 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
atari_treeview_open(hl.tv, &pos);
|
2013-09-17 04:10:35 +04:00
|
|
|
} else {
|
|
|
|
wind_set(gemtk_wm_get_handle(hl.window), WF_TOP, 1, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void atari_hotlist_close(void)
|
|
|
|
{
|
|
|
|
atari_treeview_close(hl.tv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void atari_hotlist_destroy(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if( hl.init == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( hl.window != NULL ) {
|
2013-09-21 07:29:04 +04:00
|
|
|
if (atari_treeview_is_open(hl.tv))
|
2013-09-17 04:10:35 +04:00
|
|
|
atari_hotlist_close();
|
|
|
|
wind_delete(gemtk_wm_get_handle(hl.window));
|
|
|
|
gemtk_wm_remove(hl.window);
|
|
|
|
hl.window = NULL;
|
2013-09-21 07:29:04 +04:00
|
|
|
atari_treeview_delete(hl.tv);
|
2013-09-17 04:10:35 +04:00
|
|
|
hl.init = false;
|
|
|
|
}
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("done");
|
2013-09-17 04:10:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void atari_hotlist_redraw(void)
|
|
|
|
{
|
|
|
|
atari_treeview_redraw(hl.tv);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct node;
|
|
|
|
|
|
|
|
void atari_hotlist_add_page( const char * url, const char * title )
|
|
|
|
{
|
|
|
|
nsurl *nsurl;
|
2013-09-22 05:10:12 +04:00
|
|
|
|
|
|
|
if(hl.tv == NULL)
|
2013-09-17 04:10:35 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
atari_hotlist_open();
|
|
|
|
|
|
|
|
if (nsurl_create(url, &nsurl) != NSERROR_OK)
|
|
|
|
return;
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
if (hotlist_has_url(nsurl)) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("URL already added as Bookmark");
|
2015-05-28 11:11:32 +03:00
|
|
|
nsurl_unref(nsurl);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-13 03:51:06 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
/* doesn't look nice:
|
2015-05-28 11:11:32 +03:00
|
|
|
if( hl.tv->click.x >= 0 && hl.tv->click.y >= 0 ){
|
|
|
|
hotlist_add_entry( nsurl, title, true, hl.tv->click.y );
|
|
|
|
} else {
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
}*/
|
2013-09-21 07:29:04 +04:00
|
|
|
//hotlist_add_url(nsurl);
|
|
|
|
hotlist_add_entry(nsurl, title, 0, 0);
|
2013-09-17 04:10:35 +04:00
|
|
|
nsurl_unref(nsurl);
|
|
|
|
}
|