blob: 5d4afe2d11d782c801f136d220b58370825029b5 (
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
|
#include <stdbool.h>
#include <stdlib.h>
#include "engine.h"
#include "quartz.h"
static quartz_tab_t tabs[MAX_TABS];
static int tab_count = 0;
static int current_tab = -1;
/* TODO: actually implement webkit */
int engine_get_current_index(void)
{
/* fetch private */
return current_tab;
}
int engine_get_tab_count(void)
{
/* fetch private */
return tab_count;
}
bool engine_init(void)
{
LOG_PASS("engine: init");
return true;
}
void engine_load_url(int id, const char* url)
{
if (id < 0 || id >= tab_count)
return;
free(tabs[id].url);
tabs[id].url = SDL_strdup(url);
tabs[id].loading = true;
LOG_INFO("engine: url=%s loaded to tab=%d", url, id);
}
void engine_shutdown(void)
{
LOG_INFO("engine: shutting down");
for (int i = 0; i < tab_count; i++) {
free(tabs[i].url);
free(tabs[i].title);
}
}
void engine_tab_close(int id)
{
if (id < 0 || id >= tab_count)
return;
LOG_INFO("engine: closed tab %d", id);
free(tabs[id].url);
free(tabs[id].title);
/* collapse */
for (int i = id; i < tab_count-1; i++)
tabs[i] = tabs[i+1];
tab_count--;
if (current_tab >= tab_count)
current_tab = tab_count - 1;
}
quartz_tab_t* engine_tab_current(void)
{
for (int i = 0; i < tab_count; i++)
if (i == current_tab)
return &tabs[i];
return NULL;
}
int engine_tab_new(const char* url)
{
if (tab_count >= MAX_TABS) {
LOG_WARN("engine: maximum number of tabs reached");
return -1;
}
quartz_tab_t* t = &tabs[tab_count];
t->url = SDL_strdup(url ? url : "about_blank");
t->title = SDL_strdup("new tab"); /* TODO: customise */
t->loading = true;
current_tab = tab_count;
tab_count++;
LOG_INFO("engine: created new tab: id=%d url=%s", current_tab, url);
return current_tab;
}
void engine_tab_switch(int id)
{
if (id < 0 || id >= tab_count)
return;
current_tab = id;
LOG_INFO("engine: switched to tab %d", id);
}
void engine_update(void)
{
/* nothing here */
}
|