summaryrefslogtreecommitdiff
path: root/src/browser-data-manager.cpp
blob: 9cd620c3c1b34a0ddad4f988d557aede311504b0 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.tizenopensource.org/license
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 
#include "browser-add-to-bookmark-view.h"
#if defined(FEATURE_MOST_VISITED_SITES)
#include "add-to-most-visited-sites-view.h"
#endif
#include "browser-geolocation-db.h"
#include "browser-bookmark-db.h"
#include "browser-bookmark-view.h"
#include "browser-config.h"
#include "browser-data-manager.h"
#include "browser-history-db.h"
#include "browser-history-layout.h"
#include "browser-multi-window-view.h"
#include "browser-new-folder-view.h"
#include "browser-select-folder-view.h"
#if defined(FEATURE_MOST_VISITED_SITES)
#include "most-visited-sites.h"
#endif
#include "browser-view.h"

Browser_Data_Manager::Browser_Data_Manager(void)
:
	m_browser_view(NULL)
	,m_bookmark_view(NULL)
	,m_add_to_bookmark_view(NULL)
	,m_edit_bookmark_view(NULL)
#if defined(FEATURE_MOST_VISITED_SITES)
	,m_add_to_most_visited_sites_view(NULL)
#endif
	,m_new_folder_view(NULL)
	,m_select_folder_view(NULL)
	,m_history_layout(NULL)
	,m_multi_window_view(NULL)
	,m_bookmark_db(NULL)
	,m_history_db(NULL)
	,m_geolocation_db(NULL)
	,m_stack_status(0)
{
	BROWSER_LOGD("[%s]", __func__);
}

Browser_Data_Manager::~Browser_Data_Manager(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_bookmark_view) {
		delete m_bookmark_view;
		m_bookmark_view = NULL;
	}
	if (m_add_to_bookmark_view) {
		delete m_add_to_bookmark_view;
		m_add_to_bookmark_view = NULL;
	}
	if (m_edit_bookmark_view) {
		delete m_edit_bookmark_view;
		m_edit_bookmark_view = NULL;
	}
#if defined(FEATURE_MOST_VISITED_SITES)
	if (m_add_to_most_visited_sites_view) {
		delete m_add_to_most_visited_sites_view;
		m_add_to_most_visited_sites_view = NULL;
	}
#endif
	if (m_new_folder_view) {
		delete m_new_folder_view;
		m_new_folder_view = NULL;
	}
	if (m_select_folder_view) {
		delete m_select_folder_view;
		m_select_folder_view = NULL;
	}
	if (m_history_layout) {
		delete m_history_layout;
		m_history_layout = NULL;
	}
	if (m_bookmark_db) {
		delete m_bookmark_db;
		m_bookmark_db = NULL;
	}
	if (m_history_db) {
		delete m_history_db;
		m_history_db = NULL;
	}
	if (m_multi_window_view) {
		delete m_multi_window_view;
		m_multi_window_view = NULL;
	}
}


Eina_Bool Browser_Data_Manager::is_in_view_stack(view_stack_status view)
{
	BROWSER_LOGD("m_stack_status = %d, view = %d, m_stack_status & view = %d",
		m_stack_status, view, m_stack_status & view);

	if (m_stack_status & view)
		return EINA_TRUE;
	else
		return EINA_FALSE;
}

void Browser_Data_Manager::set_browser_view(Browser_View *browser_view)
{
	BROWSER_LOGD("[%s]", __func__);
	m_browser_view = browser_view;
	m_stack_status = m_stack_status | BR_BROWSER_VIEW;
}

Browser_Bookmark_View *Browser_Data_Manager::create_bookmark_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_bookmark_view)
		destroy_bookmark_view();

	m_bookmark_view = new(nothrow) Browser_Bookmark_View;
	if (!m_bookmark_view)
		BROWSER_LOGE("new Browser_Bookmark_View failed");
	else
		m_stack_status = m_stack_status | BR_BOOKMARK_VIEW;

	return m_bookmark_view;
}

void Browser_Data_Manager::destroy_bookmark_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_bookmark_view) {
		delete m_bookmark_view;
		m_bookmark_view = NULL;
		m_stack_status = m_stack_status - BR_BOOKMARK_VIEW;
	}
}

Browser_Bookmark_DB *Browser_Data_Manager::create_bookmark_db(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_bookmark_db)
		destroy_bookmark_db();

	m_bookmark_db = new(nothrow) Browser_Bookmark_DB;
	if (!m_bookmark_db)
		BROWSER_LOGE("new Browser_Bookmark_DB failed");

	return m_bookmark_db;
}

void Browser_Data_Manager::destroy_bookmark_db(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_bookmark_db) {
		delete m_bookmark_db;
		m_bookmark_db = NULL;
	}
}

Browser_Add_To_Bookmark_View *Browser_Data_Manager::create_add_to_bookmark_view(string title,
								string url, int current_folder_id)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_add_to_bookmark_view)
		destroy_add_to_bookmark_view();

	m_add_to_bookmark_view = new(nothrow) Browser_Add_To_Bookmark_View(title, url,
								EINA_FALSE, current_folder_id);
	if (!m_add_to_bookmark_view)
		BROWSER_LOGE("new Browser_Add_To_Bookmark_View failed");
	else
		m_stack_status = m_stack_status | BR_ADD_TO_BOOKMARK_VIEW;

	return m_add_to_bookmark_view;
}

void Browser_Data_Manager::destroy_add_to_bookmark_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_add_to_bookmark_view) {
		delete m_add_to_bookmark_view;
		m_add_to_bookmark_view = NULL;
		m_stack_status = m_stack_status - BR_ADD_TO_BOOKMARK_VIEW;
	}
}

Browser_Add_To_Bookmark_View *Browser_Data_Manager::create_edit_bookmark_view(string title,
								string url, int current_folder_id)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_edit_bookmark_view)
		destroy_edit_bookmark_view();

	m_edit_bookmark_view = new(nothrow) Browser_Add_To_Bookmark_View(title, url,
								EINA_TRUE, current_folder_id);
	if (!m_edit_bookmark_view)
		BROWSER_LOGE("new Browser_Add_To_Bookmark_View failed");
	else
		m_stack_status = m_stack_status | BR_EDIT_BOOKMARK_VIEW;

	return m_edit_bookmark_view;
}

void Browser_Data_Manager::destroy_edit_bookmark_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_edit_bookmark_view) {
		delete m_edit_bookmark_view;
		m_edit_bookmark_view = NULL;
		m_stack_status = m_stack_status - BR_EDIT_BOOKMARK_VIEW;
	}
}

#if defined(FEATURE_MOST_VISITED_SITES)
Add_To_Most_Visited_Sites_View *Browser_Data_Manager::create_add_to_most_visited_sites_view(Most_Visited_Sites *most_visited_sites)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_add_to_most_visited_sites_view)
		destroy_add_to_most_visited_sites_view();

	m_add_to_most_visited_sites_view = new(nothrow) Add_To_Most_Visited_Sites_View(most_visited_sites);
	if (!m_add_to_most_visited_sites_view)
		BROWSER_LOGE("new Add_To_Most_Visited_Sites_View failed");
	else
		m_stack_status = m_stack_status | ADD_TO_MOST_VISITED_SITES_VIEW;

	return m_add_to_most_visited_sites_view;
}
#endif

#if defined(FEATURE_MOST_VISITED_SITES)
void Browser_Data_Manager::destroy_add_to_most_visited_sites_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_add_to_most_visited_sites_view) {
		delete m_add_to_most_visited_sites_view;
		m_add_to_most_visited_sites_view = NULL;
		m_stack_status = m_stack_status - ADD_TO_MOST_VISITED_SITES_VIEW;
	}
}
#endif

Browser_New_Folder_View *Browser_Data_Manager::create_new_folder_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_new_folder_view)
		destroy_new_folder_view();

	m_new_folder_view = new(nothrow) Browser_New_Folder_View;
	if (!m_new_folder_view)
		BROWSER_LOGE("new Browser_New_Folder_View failed");
	else
		m_stack_status = m_stack_status | BR_NEW_FOLDER_VIEW;

	return m_new_folder_view;
}

void Browser_Data_Manager::destroy_new_folder_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_new_folder_view) {
		delete m_new_folder_view;
		m_new_folder_view = NULL;
		m_stack_status = m_stack_status - BR_NEW_FOLDER_VIEW;
	}
}

/* 'current_folder_id' is used to mark the current folder radio button in select folder view. */
Browser_Select_Folder_View *Browser_Data_Manager::create_select_folder_view(int current_folder_id)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_select_folder_view)
		destroy_select_folder_view();

	m_select_folder_view = new(nothrow) Browser_Select_Folder_View(current_folder_id);
	if (!m_select_folder_view)
		BROWSER_LOGE("new Browser_Select_Folder_View failed");
	else
		m_stack_status = m_stack_status | BR_SELECT_FOLDER_VIEW;

	return m_select_folder_view;
}

void Browser_Data_Manager::destroy_select_folder_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_select_folder_view) {
		delete m_select_folder_view;
		m_select_folder_view = NULL;
		m_stack_status = m_stack_status - BR_SELECT_FOLDER_VIEW;
	}
}

Browser_Multi_Window_View* Browser_Data_Manager::create_multi_window_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_multi_window_view)
		destroy_multi_window_view();

	m_multi_window_view = new(nothrow) Browser_Multi_Window_View;
	if (!m_multi_window_view) {
		BROWSER_LOGE("new Browser_Multi_Window_View failed");
		return NULL;
	} else
		m_stack_status = m_stack_status | BR_MULTI_WINDOW_VIEW;

	return m_multi_window_view;
}

void Browser_Data_Manager::destroy_multi_window_view(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_multi_window_view) {
		delete m_multi_window_view;
		m_multi_window_view = NULL;
		m_stack_status = m_stack_status - BR_MULTI_WINDOW_VIEW;
	}
}

Browser_History_Layout *Browser_Data_Manager::create_history_layout(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_history_layout)
		destroy_history_layout();

	m_history_layout = new(nothrow) Browser_History_Layout;
	if (!m_history_layout)
		BROWSER_LOGE("new Browser_History_Layout failed");

	return m_history_layout;
}

void Browser_Data_Manager::destroy_history_layout(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_history_layout) {
		delete m_history_layout;
		m_history_layout = NULL;
	}
}

Browser_History_DB *Browser_Data_Manager::create_history_db(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_history_db)
		destroy_history_db();

	m_history_db = new(nothrow) Browser_History_DB;
	if (!m_history_db)
		BROWSER_LOGE("new Browser_History_DB failed");

	return m_history_db;
}

void Browser_Data_Manager::destroy_history_db(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_history_db) {
		delete m_history_db;
		m_history_db = NULL;
	}
}

Browser_Geolocation_DB *Browser_Data_Manager::create_geolocation_db(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_geolocation_db)
		destroy_geolocation_db();

	m_geolocation_db = new(nothrow) Browser_Geolocation_DB;
	if (!m_geolocation_db)
		BROWSER_LOGE("new Browser_Geolocation_DB failed");

	return m_geolocation_db;
}

void Browser_Data_Manager::destroy_geolocation_db(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_geolocation_db) {
		delete m_geolocation_db;
		m_geolocation_db = NULL;
	}
}