summaryrefslogtreecommitdiff
path: root/atari/hotlist.c
blob: 68e5c31aa7817ae631b82941718f2f03e2101896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright 2010 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/>.
 */

#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "desktop/browser.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "content/urldb.h"
#include "desktop/options.h"
#include "desktop/hotlist.h"
#include "desktop/tree.h"
#include "desktop/tree_url_node.h"
#include "desktop/gui.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/url.h"
#include "atari/gui.h"
#include "atari/misc.h"
#include "atari/treeview.h"
#include "atari/hotlist.h"
#include "atari/findfile.h"
#include "atari/res/netsurf.rsh"

struct atari_hotlist hl;

static void evnt_hl_toolbar( WINDOW *win, short buff[8]) {
	/* handle toolbar object (index in buff[4] ) */
	switch( buff[4] ) {
	case TOOLBAR_HOTLIST_CREATE_FOLDER:
		hotlist_add_folder(true);
		break;

	case TOOLBAR_HOTLIST_ADD:
		atari_hotlist_add_page("http://www.de", "");
		break;

	case TOOLBAR_HOTLIST_DELETE:
		hotlist_delete_selected();
		break;

	case TOOLBAR_HOTLIST_EDIT:
		hotlist_edit_selected();
		break;
	}
	ObjcChange( OC_TOOLBAR, win, buff[4], ~SELECTED, OC_MSG );
}


static void __CDECL evnt_hl_close( WINDOW *win, short buff[8] )
{
	hotlist_close();
}


static void __CDECL evnt_hl_mbutton( WINDOW *win, short buff[8] )
{
	/* todo: implement popup?
	if(evnt.mbut & 2) {

	}
	*/
}


void hotlist_init(void)
{
	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 );
	}

	LOG(("Hotlist: %s",  (char*)&hl.path ));

	if( hl.window == NULL ){
		int flags = ATARI_TREEVIEW_WIDGETS;
		OBJECT * tree = get_tree(TOOLBAR_HOTLIST);
		assert( tree );
		hl.open = false;
		hl.window = WindCreate( flags, 40, 40, app.w, app.h );
		if( hl.window == NULL ) {
			LOG(("Failed to allocate Hotlist"));
			return;
		}
		/* TODO: load hotlist strings from messages */
		WindSetStr( hl.window, WF_NAME, (char*)"Hotlist" );
		WindSetPtr( hl.window, WF_TOOLBAR, tree, evnt_hl_toolbar );
		EvntAttach( hl.window, WM_CLOSED, evnt_hl_close );
		EvntAttach( hl.window, WM_XBUTTON,evnt_hl_mbutton );
		hl.tv = atari_treeview_create(
			hotlist_get_tree_flags(),
			hl.window
		);
		if (hl.tv == NULL) {
			/* handle it properly, clean up previous allocs */
			LOG(("Failed to allocate treeview"));
			return;
		}

		hotlist_initialise(
			hl.tv->tree,
			(char*)&hl.path,
			"dir.png"
		);

	} else {

	}
	hl.init = true;
}


void hotlist_open(void)
{
	GRECT pos = {app.w - (app.w/3), app.y, app.w/3, app.h/2};

	if( hl.init == false ) {
		return;
	}

	if( hl.open == false ) {
		WindOpen( hl.window, pos.g_x, pos.g_y, pos.g_w, pos.g_h);
		hl.open = true;
		atari_treeview_open( hl.tv );
	} else {
		WindTop( hl.window );
	}
}

void hotlist_close(void)
{
	WindClose(hl.window);
	hl.open = false;
	atari_treeview_close( hl.tv );
}

void hotlist_destroy(void)
{
	if( hl.init == false ) {
		return;
	}
	if( hl.window != NULL ) {
		hotlist_cleanup( (char*)&hl.path );
		if( hl.open )
			hotlist_close();
		WindDelete( hl.window );
		hl.window = NULL;
		atari_treeview_destroy( hl.tv  );
		hl.init = false;
	}
	LOG(("done"));
}

struct node;

void atari_hotlist_add_page( const char * url, const char * title )
{
	struct node * root;
	struct node * selected = NULL;
	struct node * folder = NULL;
	NSTREEVIEW tv = hl.tv;
	if(hl.tv == NULL )
		return;
	if( hl.tv->click.x >= 0 && hl.tv->click.y >= 0 ){
		hotlist_add_page_xy( url, hl.tv->click.x, hl.tv->click.y );
	} else {
		hotlist_add_page( url );
	}
}