apply FSL(Flora Software License)
[profile/ivi/org.tizen.browser.git] / src / browser-history / browser-history-layout.cpp
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *    http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include "browser-add-to-bookmark-view.h"
18 #include "browser-view.h"
19 #include "browser-history-layout.h"
20
21 Date::Date() : day(0), month(0), year(0) {}
22
23 Date::Date(Date &date)
24 {
25         this->day = date.day;
26         this->month = date.month;
27         this->year = date.year;
28 }
29
30 void Date::operator=(Date &date)
31 {
32         this->day = date.day;
33         this->month = date.month;
34         this->year = date.year;
35 }
36
37 bool Date::operator==(Date &date)
38 {
39         return (this->day == date.day && this->month == date.month && this->year == date.year);
40 }
41
42 bool Date::operator!=(Date &date)
43 {
44         return (this->day != date.day || this->month != date.month || this->year != date.year);
45 }
46
47 Browser_History_Layout::Browser_History_Layout(void)
48 :       m_history_genlist(NULL)
49         ,m_edit_mode_select_all_layout(NULL)
50         ,m_edit_mode_select_all_check_button(NULL)
51         ,m_content_box(NULL)
52         ,m_no_history_label(NULL)
53         ,m_processing_popup_timer(NULL)
54         ,m_processed_it(NULL)
55         ,m_processed_count(0)
56         ,m_total_item_count(0)
57         ,m_processing_popup(NULL)
58         ,m_processing_popup_layout(NULL)
59         ,m_processing_progress_bar(NULL)
60         ,m_select_all_check_value(EINA_FALSE)
61         ,m_searchbar_layout(NULL)
62         ,m_searched_history_genlist(NULL)
63         ,m_no_content_search_result(NULL)
64         ,m_searchbar(NULL)
65         ,m_delete_confirm_popup(NULL)
66 {
67         BROWSER_LOGD("[%s]", __func__);
68 }
69
70 Browser_History_Layout::~Browser_History_Layout(void)
71 {
72         BROWSER_LOGD("[%s]", __func__);
73         hide_notify_popup();
74
75         for(int i = 0 ; i < m_history_list.size() ; i++ ) {
76                 if (m_history_list[i])
77                         delete m_history_list[i];
78         }
79         m_history_list.clear();
80
81         for(int i = 0 ; i < m_history_date_label_list.size() ; i++ ) {
82                 if (m_history_date_label_list[i])
83                         free(m_history_date_label_list[i]);
84         }
85         m_history_date_label_list.clear();
86
87         for(int i = 0 ; i < m_searched_history_date_label_list.size() ; i++ ) {
88                 if (m_searched_history_date_label_list[i])
89                         free(m_searched_history_date_label_list[i]);
90         }
91         m_searched_history_date_label_list.clear();
92
93         for(int i = 0 ; i < m_searched_history_item_list.size() ; i++ ) {
94                 if (m_searched_history_item_list[i])
95                         delete m_searched_history_item_list[i];
96         }
97         m_searched_history_item_list.clear();
98
99         if (m_delete_confirm_popup)
100                 evas_object_del(m_delete_confirm_popup);
101 }
102
103 Eina_Bool Browser_History_Layout::init(void)
104 {
105         BROWSER_LOGD("[%s]", __func__);
106         return _create_main_layout();
107 }
108
109 Eina_Bool Browser_History_Layout::_show_searched_history(const char *search_text)
110 {
111         BROWSER_LOGD("search_text = [%s]", search_text);
112
113         for(int i = 0 ; i < m_searched_history_item_list.size() ; i++ ) {
114                 if (m_searched_history_item_list[i])
115                         delete m_searched_history_item_list[i];
116         }
117         m_searched_history_item_list.clear();
118
119         for(int i = 0 ; i < m_searched_history_date_label_list.size() ; i++ ) {
120                 if (m_searched_history_date_label_list[i])
121                         free(m_searched_history_date_label_list[i]);
122         }
123         m_searched_history_date_label_list.clear();
124
125         if (!search_text || !strlen(search_text)) {
126                 if (m_searched_history_genlist || m_no_content_search_result) {
127                         elm_box_unpack_all(m_content_box);
128                         elm_box_pack_start(m_content_box, m_history_genlist);
129                         evas_object_show(m_history_genlist);
130
131                         if (m_searched_history_genlist) {
132                                 evas_object_del(m_searched_history_genlist);
133                                 m_searched_history_genlist = NULL;
134                         }
135
136                         if (m_no_content_search_result) {
137                                 evas_object_del(m_no_content_search_result);
138                                 m_no_content_search_result = NULL;
139                         }
140
141                         if (m_history_list.size() == 0) {
142                                 if (m_no_history_label) {
143                                         elm_box_unpack_all(m_content_box);
144                                         elm_box_pack_start(m_content_box, m_no_history_label);
145                                 }
146                         }
147
148                         return EINA_TRUE;
149                 }
150         }
151
152         Elm_Object_Item *it = elm_genlist_first_item_get(m_history_genlist);
153         while (it) {
154                 Browser_History_DB::history_item *item = NULL;
155                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
156                 if (item && elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
157                         if (item->url.find(search_text) != string::npos || item->title.find(search_text) != string::npos) {
158                                 Browser_History_DB::history_item *searched_item = NULL;
159                                 searched_item = new(nothrow) Browser_History_DB::history_item;
160                                 searched_item->id = item->id;
161                                 searched_item->url = item->url;
162                                 searched_item->title = item->title;
163                                 searched_item->date = item->date;
164                                 searched_item->is_delete = item->is_delete;
165                                 searched_item->user_data = item->user_data;
166                                 m_searched_history_item_list.push_back(searched_item);
167                         }
168                 }
169                 it = elm_genlist_item_next_get(it);
170         }
171
172         if (m_searched_history_item_list.size()) {
173                 if (m_no_content_search_result) {
174                         evas_object_del(m_no_content_search_result);
175                         m_no_content_search_result = NULL;
176                 }
177
178                 if (!m_searched_history_genlist) {
179                         m_searched_history_genlist = _create_history_genlist();
180                         if (!m_searched_history_genlist) {
181                                 BROWSER_LOGE("_create_history_genlist failed");
182                                 return EINA_FALSE;
183                         }
184                 }
185
186                 elm_genlist_clear(m_searched_history_genlist);
187
188                 Date date;
189                 Date last_date;
190                 for(int i = 0 ; i < m_searched_history_item_list.size() ; i++) {
191                         sscanf(m_searched_history_item_list[i]->date.c_str(), "%d-%d-%d", &date.year, &date.month, &date.day);
192                         m_searched_history_item_list[i]->user_data = (void *)this;
193                         if (last_date != date) {
194                                 last_date = date;
195                                 char *labe_item = strdup(m_searched_history_item_list[i]->date.c_str());
196                                 if (!labe_item) {
197                                         BROWSER_LOGE("strdup failed");
198                                         return EINA_FALSE;
199                                 }
200                                 m_searched_history_date_label_list.push_back(labe_item);
201                                 it = elm_genlist_item_append(m_searched_history_genlist, &m_history_group_title_class,
202                                                                 labe_item, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL);
203
204                                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
205                         }
206                         elm_genlist_item_append(m_searched_history_genlist, &m_history_genlist_item_class,
207                                                 m_searched_history_item_list[i], it, ELM_GENLIST_ITEM_NONE,
208                                                 __history_item_clicked_cb, this);
209                 }
210
211                 elm_box_unpack_all(m_content_box);
212                 evas_object_hide(m_history_genlist);
213                 elm_box_pack_start(m_content_box, m_searched_history_genlist);
214                 evas_object_show(m_searched_history_genlist);
215         } else {
216                 BROWSER_LOGD("show no content");
217                 if (m_no_content_search_result)
218                         evas_object_del(m_no_content_search_result);
219                 m_no_content_search_result = elm_layout_add(m_content_box);
220                 if (!m_no_content_search_result) {
221                         BROWSER_LOGE("elm_layout_add failed");
222                         return EINA_FALSE;
223                 }
224                 elm_layout_theme_set(m_no_content_search_result, "layout", "nocontents", "search");
225                 elm_object_part_text_set(m_no_content_search_result, "elm.text", BR_STRING_NO_SEARCH_RESULT);
226                 evas_object_size_hint_weight_set(m_no_content_search_result, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
227                 evas_object_size_hint_align_set(m_no_content_search_result, EVAS_HINT_FILL, EVAS_HINT_FILL);
228
229                 if (m_searched_history_genlist) {
230                         evas_object_del(m_searched_history_genlist);
231                         m_searched_history_genlist = NULL;
232                 }
233
234                 elm_box_unpack_all(m_content_box);
235                 evas_object_hide(m_history_genlist);
236                 elm_box_pack_start(m_content_box, m_no_content_search_result);
237                 evas_object_show(m_no_content_search_result);
238         }
239
240         return EINA_TRUE;
241 }
242
243 void Browser_History_Layout::__search_delay_changed_cb(void *data, Evas_Object *obj, void *event_info)
244 {
245         const char *search_text = elm_entry_entry_get(obj);
246         BROWSER_LOGD("search_text=[%s]", search_text);
247
248         if (!data || !search_text)
249                 return;
250
251         char *utf8_text = elm_entry_markup_to_utf8(search_text);
252         if (!utf8_text)
253                 return;
254
255         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
256         if (!history_layout->_show_searched_history(utf8_text))
257                 BROWSER_LOGE("_show_searched_history failed");
258
259         free(utf8_text);
260 }
261
262 void Browser_History_Layout::_enable_searchbar_layout(Eina_Bool enable)
263 {
264         if (enable) {
265                 elm_layout_theme_set(m_searchbar_layout, "layout", "application", "searchbar_base");
266
267                 if (!m_searchbar) {
268                         m_searchbar = br_elm_searchbar_add(m_searchbar_layout);
269                         if (!m_searchbar)
270                                 BROWSER_LOGD("br_elm_searchbar_add failed");
271                 }
272
273                 elm_object_part_content_set(m_searchbar_layout, "searchbar", m_searchbar);
274                 evas_object_show(m_searchbar);
275
276                 elm_object_signal_emit(m_searchbar_layout, "elm,state,show,searchbar", "elm");
277
278                 Evas_Object *searchbar_entry = br_elm_searchbar_entry_get(m_searchbar);
279                 elm_entry_input_panel_layout_set(searchbar_entry, ELM_INPUT_PANEL_LAYOUT_URL);
280
281                 evas_object_smart_callback_add(searchbar_entry, "changed", __search_delay_changed_cb, this);
282         } else {
283                 for(int i = 0 ; i < m_searched_history_item_list.size() ; i++ ) {
284                         if (m_searched_history_item_list[i])
285                                 delete m_searched_history_item_list[i];
286                 }
287                 m_searched_history_item_list.clear();
288
289                 for(int i = 0 ; i < m_searched_history_date_label_list.size() ; i++ ) {
290                         if (m_searched_history_date_label_list[i])
291                                 free(m_searched_history_date_label_list[i]);
292                 }
293                 m_searched_history_date_label_list.clear();
294
295                 if (m_searched_history_genlist || m_no_content_search_result) {
296                         elm_box_unpack_all(m_content_box);
297                         elm_box_pack_start(m_content_box, m_history_genlist);
298                         evas_object_show(m_history_genlist);
299
300                         if (m_searched_history_genlist) {
301                                 evas_object_del(m_searched_history_genlist);
302                                 m_searched_history_genlist = NULL;
303                         }
304
305                         if (m_no_content_search_result) {
306                                 evas_object_del(m_no_content_search_result);
307                                 m_no_content_search_result = NULL;
308                         }
309                 }
310
311                 if (m_searchbar) {
312                         elm_object_part_content_unset(m_searchbar_layout, "searchbar");
313                         evas_object_hide(m_searchbar);
314                 }
315
316                 Evas_Object *searchbar_entry = br_elm_searchbar_entry_get(m_searchbar);
317                 evas_object_smart_callback_del(searchbar_entry, "changed", __search_delay_changed_cb);
318
319                 elm_layout_theme_set(m_searchbar_layout, "layout", "application", "noindicator");
320         }
321 }
322
323 void Browser_History_Layout::_set_edit_mode(Eina_Bool edit_mode)
324 {
325         BROWSER_LOGD("[%s]", __func__);
326         Browser_Bookmark_View *bookmark_view = m_data_manager->get_bookmark_view();
327
328         hide_notify_popup();
329
330         _enable_searchbar_layout(!edit_mode);
331
332         if (edit_mode) {
333                 elm_object_style_set(m_bg, "edit_mode");
334
335                 m_edit_mode_select_all_layout = elm_layout_add(m_content_box);
336                 if (!m_edit_mode_select_all_layout) {
337                         BROWSER_LOGE("elm_layout_add failed");
338                         return;
339                 }
340                 elm_layout_theme_set(m_edit_mode_select_all_layout, "genlist", "item", "select_all/default");
341                 evas_object_size_hint_weight_set(m_edit_mode_select_all_layout, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
342                 evas_object_size_hint_align_set(m_edit_mode_select_all_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
343                 evas_object_event_callback_add(m_edit_mode_select_all_layout, EVAS_CALLBACK_MOUSE_DOWN,
344                                                                 __edit_mode_select_all_clicked_cb, this);
345
346                 m_edit_mode_select_all_check_button = elm_check_add(m_edit_mode_select_all_layout);
347                 if (!m_edit_mode_select_all_check_button) {
348                         BROWSER_LOGE("elm_layout_add failed");
349                         return;
350                 }
351                 evas_object_smart_callback_add(m_edit_mode_select_all_check_button, "changed",
352                                                 __edit_mode_select_all_check_changed_cb, this);
353                 evas_object_propagate_events_set(m_edit_mode_select_all_check_button, EINA_FALSE);
354
355                 elm_object_part_content_set(m_edit_mode_select_all_layout, "elm.icon", m_edit_mode_select_all_check_button);
356                 elm_object_text_set(m_edit_mode_select_all_layout, BR_STRING_SELECT_ALL);
357
358                 elm_box_pack_start(m_content_box, m_edit_mode_select_all_layout);
359                 evas_object_show(m_edit_mode_select_all_layout);
360
361                 elm_genlist_decorate_mode_set(m_history_genlist, EINA_TRUE);
362                 elm_genlist_select_mode_set(m_history_genlist, ELM_OBJECT_SELECT_MODE_ALWAYS);
363
364                 bookmark_view->_set_navigationbar_title(BR_STRING_SELECT_HISTORIES);
365
366                 if (!bookmark_view->_set_controlbar_type(Browser_Bookmark_View::HISTORY_VIEW_EDIT_MODE))
367                         BROWSER_LOGE("_set_controlbar_type HISTORY_VIEW_EDIT_MODE failed");
368         } else {
369                 if (m_edit_mode_select_all_layout) {
370                         elm_box_unpack(m_content_box, m_edit_mode_select_all_layout);
371                         evas_object_del(m_edit_mode_select_all_layout);
372                         m_edit_mode_select_all_layout = NULL;
373                 }
374                 if (m_edit_mode_select_all_check_button) {
375                         evas_object_del(m_edit_mode_select_all_check_button);
376                         m_edit_mode_select_all_check_button = NULL;
377                 }
378                 if (m_no_history_label) {
379                         evas_object_del(m_no_history_label);
380                         m_no_history_label = NULL;
381                 }
382
383                 Browser_Bookmark_View *bookmark_view = m_data_manager->get_bookmark_view();
384                 if (!bookmark_view->_set_controlbar_type(Browser_Bookmark_View::HISTORY_VIEW_DEFAULT))
385                         BROWSER_LOGE("_set_controlbar_type failed");
386
387                 Elm_Object_Item *it = NULL;
388                 Browser_History_DB::history_item *item = NULL;
389                 it = elm_genlist_first_item_get(m_history_genlist);
390                 while(it) {
391                         item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
392                         item->is_delete = EINA_FALSE;
393                         it = elm_genlist_item_next_get(it);
394                 }
395
396                 elm_object_style_set(m_bg, "default");
397                 elm_genlist_decorate_mode_set(m_history_genlist, EINA_FALSE);
398                 elm_genlist_select_mode_set(m_history_genlist, ELM_OBJECT_SELECT_MODE_DEFAULT);
399
400                 bookmark_view->_set_navigationbar_title(BR_STRING_HISTORY);
401
402                 if (m_history_list.size() == 0) {
403                         elm_box_unpack_all(m_content_box);
404                         elm_genlist_clear(m_history_genlist);
405                         evas_object_hide(m_history_genlist);
406
407                         if (m_edit_mode_select_all_layout) {
408                                 evas_object_del(m_edit_mode_select_all_layout);
409                                 m_edit_mode_select_all_layout = NULL;
410                         }
411                         if (m_edit_mode_select_all_check_button) {
412                                 evas_object_del(m_edit_mode_select_all_check_button);
413                                 m_edit_mode_select_all_check_button = NULL;
414                         }
415
416                         m_no_history_label = elm_label_add(m_searchbar_layout);
417                         if (!m_no_history_label) {
418                                 BROWSER_LOGE("elm_label_add failed");
419                                 return;
420                         }
421
422                         std::string text = std::string("<color='#646464'>") + std::string(BR_STRING_NO_HISTORY);
423                         elm_object_text_set(m_no_history_label, text.c_str());
424                         evas_object_show(m_no_history_label);
425                         elm_box_pack_start(m_content_box, m_no_history_label);
426
427                         elm_object_item_disabled_set(bookmark_view->m_bookmark_edit_controlbar_item, EINA_TRUE);
428                 }
429         }
430 }
431
432 void Browser_History_Layout::_show_selection_info(void)
433 {
434         BROWSER_LOGD("[%s]", __func__);
435         Elm_Object_Item *it = elm_genlist_first_item_get(m_history_genlist);
436         int selected_count = 0;
437         int total_count = 0;
438         while(it) {
439                 Browser_History_DB::history_item *item = NULL;
440                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
441                 if (item && elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
442                         if (item->is_delete)
443                                 selected_count++;
444                         total_count++;
445                 }
446                 it = elm_genlist_item_next_get(it);
447         }
448
449         if (selected_count == 0) {
450                 elm_object_item_disabled_set(m_data_manager->get_bookmark_view()->m_bookmark_delete_controlbar_item, EINA_TRUE);
451                 hide_notify_popup();
452                 return;
453         } else
454                 elm_object_item_disabled_set(m_data_manager->get_bookmark_view()->m_bookmark_delete_controlbar_item, EINA_FALSE);
455
456         if (selected_count == 1) {
457                 show_notify_popup(BR_STRING_ONE_ITEM_SELECTED, 0, EINA_TRUE);
458         } else if (selected_count > 1) {
459                 char *small_popup_text = NULL;
460                 int string_len = strlen(BR_STRING_ITEMS_SELECTED) + 4;
461
462                 small_popup_text = (char *)malloc(string_len * sizeof(char));
463                 memset(small_popup_text, 0x00, string_len);
464
465                 snprintf(small_popup_text, string_len, BR_STRING_ITEMS_SELECTED, selected_count);
466                 show_notify_popup(small_popup_text, 0, EINA_TRUE);
467
468                 if (small_popup_text)
469                         free(small_popup_text);
470                 small_popup_text = 0x00;
471         }
472 }
473
474 void Browser_History_Layout::_show_delete_processing_popup(void)
475 {
476         BROWSER_LOGD("[%s]", __func__);
477         if (m_processing_popup)
478                 evas_object_del(m_processing_popup);
479
480         m_processing_popup = elm_popup_add(m_searchbar_layout);
481         if (!m_processing_popup) {
482                 BROWSER_LOGE("elm_popup_add failed");
483                 return;
484         }
485
486         if (m_processing_popup_layout)
487                 evas_object_del(m_processing_popup_layout);
488         m_processing_popup_layout = elm_layout_add(m_processing_popup);
489         if (!m_processing_popup_layout) {
490                 BROWSER_LOGE("elm_layout_add failed");
491                 return;
492         }
493         if (!elm_layout_file_set(m_processing_popup_layout, BROWSER_EDJE_DIR"/browser-bookmark-view.edj",
494                                                         "browser/popup_center_progressview")) {
495                 BROWSER_LOGE("elm_layout_file_set failed");
496                 return;
497         }
498         evas_object_size_hint_weight_set(m_processing_popup_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
499
500         m_processing_progress_bar = elm_progressbar_add(m_processing_popup);
501         elm_object_style_set(m_processing_progress_bar, "list_progress");
502         elm_progressbar_horizontal_set(m_processing_progress_bar, EINA_TRUE);
503         evas_object_size_hint_align_set(m_processing_progress_bar, EVAS_HINT_FILL, EVAS_HINT_FILL);
504         evas_object_size_hint_weight_set(m_processing_progress_bar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
505         elm_progressbar_value_set(m_processing_progress_bar, 0.0);
506
507         if (m_processing_popup_timer)
508                 ecore_timer_del(m_processing_popup_timer);
509
510         m_processed_count = 0;
511         m_processed_it = elm_genlist_last_item_get(m_history_genlist);
512
513         Elm_Object_Item *it = elm_genlist_first_item_get(m_history_genlist);
514         m_total_item_count = 0;
515         while (it) {
516                 Browser_History_DB::history_item *item = NULL;
517                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
518                 if (item && elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
519                         if(item->is_delete)
520                                 m_total_item_count++;
521                 }
522                 it = elm_genlist_item_next_get(it);
523         }
524
525         m_processing_popup_timer = ecore_timer_add(0.3, __delete_processing_popup_timer_cb, this);
526         evas_object_show(m_processing_progress_bar);
527
528         elm_object_part_content_set(m_processing_popup_layout, "elm.swallow.content", m_processing_progress_bar);
529         edje_object_part_text_set(elm_layout_edje_get(m_processing_popup_layout), "elm.title", BR_STRING_PROCESSING);
530         edje_object_part_text_set(elm_layout_edje_get(m_processing_popup_layout), "elm.text.left", "");
531         edje_object_part_text_set(elm_layout_edje_get(m_processing_popup_layout), "elm.text.right", "");
532
533         elm_object_content_set(m_processing_popup, m_processing_popup_layout);
534
535         Evas_Object *cancel_button = elm_button_add(m_processing_popup);
536         if (!cancel_button) {
537                 BROWSER_LOGE("elm_button_add failed");
538                 return;
539         }
540         elm_object_text_set(cancel_button, BR_STRING_CANCEL);
541         elm_object_part_content_set(m_processing_popup, "button1", cancel_button);
542         evas_object_smart_callback_add(cancel_button, "clicked", __delete_processing_popup_response_cb, this);
543
544         evas_object_show(m_processing_popup);
545 }
546
547 void Browser_History_Layout::__delete_processing_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
548 {
549         BROWSER_LOGD("[%s]", __func__);
550         if (!data)
551                 return;
552
553         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
554
555         evas_object_del(history_layout->m_processing_popup);
556
557         history_layout->m_processing_progress_bar = NULL;
558         history_layout->m_processed_it = NULL;
559
560         if (history_layout->m_processing_popup_timer) {
561                 ecore_timer_del(history_layout->m_processing_popup_timer);
562                 history_layout->m_processing_popup_timer = NULL;
563         }
564
565         history_layout->show_notify_popup(BR_STRING_DELETED, 3, EINA_TRUE);
566
567         if (history_layout->m_history_list.size() == 0) {
568                 elm_box_unpack_all(history_layout->m_content_box);
569                 elm_genlist_clear(history_layout->m_history_genlist);
570                 evas_object_hide(history_layout->m_history_genlist);
571
572                 if (history_layout->m_edit_mode_select_all_layout) {
573                         evas_object_del(history_layout->m_edit_mode_select_all_layout);
574                         history_layout->m_edit_mode_select_all_layout = NULL;
575                 }
576                 if (history_layout->m_edit_mode_select_all_check_button) {
577                         evas_object_del(history_layout->m_edit_mode_select_all_check_button);
578                         history_layout->m_edit_mode_select_all_check_button = NULL;
579                 }
580
581                 history_layout->m_no_history_label = elm_label_add(history_layout->m_searchbar_layout);
582                 if (!history_layout->m_no_history_label) {
583                         BROWSER_LOGE("elm_label_add failed");
584                         return;
585                 }
586
587                 std::string text = std::string("<color='#646464'>") + std::string(BR_STRING_NO_HISTORY);
588                 elm_object_text_set(history_layout->m_no_history_label, text.c_str());
589                 evas_object_show(history_layout->m_no_history_label);
590                 elm_box_pack_start(history_layout->m_content_box, history_layout->m_no_history_label);
591
592                 Browser_Bookmark_View *bookmark_view = m_data_manager->get_bookmark_view();
593                 if (!bookmark_view->_set_controlbar_type(Browser_Bookmark_View::HISTORY_VIEW_DEFAULT))
594                         BROWSER_LOGE("_set_controlbar_type failed");
595
596                 elm_object_item_disabled_set(bookmark_view->m_bookmark_edit_controlbar_item, EINA_TRUE);
597         }
598 }
599
600 Eina_Bool Browser_History_Layout::__delete_processing_popup_timer_cb(void *data)
601 {
602         BROWSER_LOGD("[%s]", __func__);
603         if (!data)
604                 return ECORE_CALLBACK_CANCEL;
605
606         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
607         Evas_Object* progress_bar = history_layout->m_processing_progress_bar;
608
609         Eina_Bool check_value = history_layout->m_select_all_check_value;
610
611         double value = elm_progressbar_value_get(progress_bar);
612         if (value >= 1.0) {
613                 __delete_processing_popup_response_cb(history_layout, NULL, NULL);
614
615                 history_layout->m_processing_popup_timer = NULL;
616                 history_layout->show_notify_popup(BR_STRING_DELETED, 3, EINA_TRUE);
617
618                 return ECORE_CALLBACK_CANCEL;
619         }
620
621         while (history_layout->m_processed_it) {
622                 Browser_History_DB::history_item *item = NULL;
623                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(history_layout->m_processed_it);
624                 if (item) {
625                         if(item->is_delete
626                             && elm_genlist_item_select_mode_get(history_layout->m_processed_it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
627                                 Eina_Bool ret = m_data_manager->get_history_db()->delete_history(item->id);
628                                 for(int index = 0 ; index < history_layout->m_history_list.size() ; index++) {
629                                         if (history_layout->m_history_list[index]->id == item->id) {
630                                                 delete history_layout->m_history_list[index];
631                                                 history_layout->m_history_list.erase(history_layout->m_history_list.begin() + index);
632                                         }
633                                 }
634
635                                 history_layout->m_processed_count++;
636                                 Elm_Object_Item *it = history_layout->m_processed_it;
637                                 history_layout->m_processed_it = elm_genlist_item_prev_get(history_layout->m_processed_it);
638                                 elm_object_item_del(it);
639                                 elm_genlist_realized_items_update(history_layout->m_history_genlist);
640                         } else
641                                 history_layout->m_processed_it = elm_genlist_item_prev_get(history_layout->m_processed_it);
642                 } else
643                         history_layout->m_processed_it = elm_genlist_item_prev_get(history_layout->m_processed_it);
644
645                 if (history_layout->m_processed_count % 20 == 0)
646                         break;
647         }
648
649         elm_progressbar_value_set(history_layout->m_processing_progress_bar,
650                                 (float)((float)history_layout->m_processed_count / (float)history_layout->m_total_item_count));
651
652         char progress_text[20] = {0, };
653         snprintf(progress_text, sizeof(progress_text) - 1, "%d / %d",
654                         history_layout->m_processed_count, history_layout->m_total_item_count);
655
656         edje_object_part_text_set(elm_layout_edje_get(history_layout->m_processing_popup_layout),
657                                 "elm.text.right", progress_text);
658
659         return ECORE_CALLBACK_RENEW;
660 }
661
662 void Browser_History_Layout::_show_select_processing_popup(void)
663 {
664         BROWSER_LOGD("[%s]", __func__);
665         if (m_processing_popup)
666                 evas_object_del(m_processing_popup);
667
668         m_processing_popup = elm_popup_add(m_searchbar_layout);
669         if (!m_processing_popup) {
670                 BROWSER_LOGE("elm_popup_add failed");
671                 return;
672         }
673
674         if (m_processing_popup_layout)
675                 evas_object_del(m_processing_popup_layout);
676         m_processing_popup_layout = elm_layout_add(m_processing_popup);
677         if (!m_processing_popup_layout) {
678                 BROWSER_LOGE("elm_layout_add failed");
679                 return;
680         }
681         if (!elm_layout_file_set(m_processing_popup_layout, BROWSER_EDJE_DIR"/browser-bookmark-view.edj",
682                                                         "browser/popup_center_progressview")) {
683                 BROWSER_LOGE("elm_layout_file_set failed");
684                 return;
685         }
686         evas_object_size_hint_weight_set(m_processing_popup_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
687
688         m_processing_progress_bar = elm_progressbar_add(m_processing_popup);
689         elm_object_style_set(m_processing_progress_bar, "list_progress");
690         elm_progressbar_horizontal_set(m_processing_progress_bar, EINA_TRUE);
691         evas_object_size_hint_align_set(m_processing_progress_bar, EVAS_HINT_FILL, EVAS_HINT_FILL);
692         evas_object_size_hint_weight_set(m_processing_progress_bar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
693         elm_progressbar_value_set(m_processing_progress_bar, 0.0);
694
695         if (m_processing_popup_timer)
696                 ecore_timer_del(m_processing_popup_timer);
697
698         m_processed_count = 0;
699         m_processed_it = elm_genlist_first_item_get(m_history_genlist);
700
701         m_processing_popup_timer = ecore_timer_add(0.1, __select_processing_popup_timer_cb, this);
702         evas_object_show(m_processing_progress_bar);
703
704         elm_object_part_content_set(m_processing_popup_layout, "elm.swallow.content", m_processing_progress_bar);
705         edje_object_part_text_set(elm_layout_edje_get(m_processing_popup_layout), "elm.title", BR_STRING_PROCESSING);
706         edje_object_part_text_set(elm_layout_edje_get(m_processing_popup_layout), "elm.text.left", "");
707         edje_object_part_text_set(elm_layout_edje_get(m_processing_popup_layout), "elm.text.right", "");
708
709         elm_object_content_set(m_processing_popup, m_processing_popup_layout);
710
711         Evas_Object *cancel_button = elm_button_add(m_processing_popup);
712         if (!cancel_button) {
713                 BROWSER_LOGE("elm_button_add failed");
714                 return;
715         }
716         elm_object_text_set(cancel_button, BR_STRING_CANCEL);
717         elm_object_part_content_set(m_processing_popup, "button1", cancel_button);
718         evas_object_smart_callback_add(cancel_button, "clicked", __select_processing_popup_response_cb, this);
719
720         evas_object_show(m_processing_popup);
721
722         Eina_Bool check_value = elm_check_state_get(m_edit_mode_select_all_check_button);
723         m_select_all_check_value = check_value;
724
725         if (check_value)
726                 elm_check_state_set(m_edit_mode_select_all_check_button, !check_value);
727 }
728
729 void Browser_History_Layout::__select_processing_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
730 {
731         BROWSER_LOGD("[%s]", __func__);
732         if (!data)
733                 return;
734
735         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
736
737         evas_object_del(history_layout->m_processing_popup);
738
739         history_layout->m_processing_progress_bar = NULL;
740         history_layout->m_processed_it = NULL;
741
742         if (history_layout->m_processing_popup_timer) {
743                 ecore_timer_del(history_layout->m_processing_popup_timer);
744                 history_layout->m_processing_popup_timer = NULL;
745         }
746
747         Elm_Object_Item *it = elm_genlist_first_item_get(history_layout->m_history_genlist);
748         int check_count = 0;
749         while (it) {
750                 Browser_History_DB::history_item *item = NULL;
751                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
752                 if (item) {
753                         if(item->is_delete && elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)
754                                 check_count++;
755                 }
756                 it = elm_genlist_item_next_get(it);
757         }
758
759         history_layout->_delete_date_only_label_genlist_item();
760
761         if (check_count)
762                 elm_object_item_disabled_set(m_data_manager->get_bookmark_view()->m_bookmark_delete_controlbar_item, EINA_FALSE);
763         else
764                 elm_object_item_disabled_set(m_data_manager->get_bookmark_view()->m_bookmark_delete_controlbar_item, EINA_TRUE);
765 }
766
767 Eina_Bool Browser_History_Layout::__select_processing_popup_timer_cb(void *data)
768 {
769         if (!data)
770                 return ECORE_CALLBACK_CANCEL;
771
772         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
773         Evas_Object* progress_bar = history_layout->m_processing_progress_bar;
774
775         Eina_Bool check_value = history_layout->m_select_all_check_value;
776
777         double value = elm_progressbar_value_get(progress_bar);
778         if (value >= 1.0) {
779                 __select_processing_popup_response_cb(history_layout, NULL, NULL);
780
781                 history_layout->m_processing_popup_timer = NULL;
782                 elm_check_state_set(history_layout->m_edit_mode_select_all_check_button, !check_value);
783                 history_layout->_show_selection_info();
784
785                 return ECORE_CALLBACK_CANCEL;
786         }
787
788         while (history_layout->m_processed_it) {
789                 Browser_History_DB::history_item *item = NULL;
790                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(history_layout->m_processed_it);
791                 if (item && (elm_genlist_item_select_mode_get(history_layout->m_processed_it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)) {
792                         item->is_delete = !check_value;
793                         elm_genlist_item_update(history_layout->m_processed_it);
794                         history_layout->m_processed_count++;
795                 }
796                 history_layout->m_processed_it = elm_genlist_item_next_get(history_layout->m_processed_it);
797
798                 if (history_layout->m_processed_count % 30 == 0)
799                         break;
800         }
801
802         elm_progressbar_value_set(history_layout->m_processing_progress_bar,
803                                 (float)((float)history_layout->m_processed_count / (float)(history_layout->m_history_list.size())));
804
805         char progress_text[20] = {0, };
806         snprintf(progress_text, sizeof(progress_text) - 1, "%d / %d",
807                         history_layout->m_processed_count, history_layout->m_history_list.size());
808
809         edje_object_part_text_set(elm_layout_edje_get(history_layout->m_processing_popup_layout),
810                                 "elm.text.right", progress_text);
811
812         return ECORE_CALLBACK_RENEW;
813 }
814
815 void Browser_History_Layout::__edit_mode_select_all_check_changed_cb(void *data,
816                                                         Evas_Object *obj, void *event_info)
817 {
818         BROWSER_LOGD("[%s]", __func__);
819         if (!data)
820                 return;
821
822         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
823         Eina_Bool value = elm_check_state_get(obj);
824
825         if (history_layout->m_history_list.size() >= BROWSER_BOOKMARK_PROCESS_BLOCK_COUNT) {
826                 elm_check_state_set(obj, !value);
827                 history_layout->_show_select_processing_popup();
828         } else {
829                 Elm_Object_Item *it = elm_genlist_first_item_get(history_layout->m_history_genlist);
830                 while (it) {
831                         Browser_History_DB::history_item *item = NULL;
832                         item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
833                         if (item) {
834                                 if (elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
835                                         item->is_delete = value;
836                                         elm_genlist_item_update(it);
837                                 }
838                         }
839                         it = elm_genlist_item_next_get(it);
840                 }
841
842                 history_layout->_show_selection_info();
843         }
844 }
845
846 void Browser_History_Layout::__edit_mode_select_all_clicked_cb(void *data, Evas *evas,
847                                                                 Evas_Object *obj, void *event_info)
848 {       
849         if (!data)
850                 return;
851
852         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
853
854         if (history_layout->m_history_list.size() >= BROWSER_BOOKMARK_PROCESS_BLOCK_COUNT) {
855                 history_layout->_show_select_processing_popup();
856         } else {
857                 Eina_Bool value = elm_check_state_get(history_layout->m_edit_mode_select_all_check_button);
858                 elm_check_state_set(history_layout->m_edit_mode_select_all_check_button, !value);
859
860                 Elm_Object_Item *it = elm_genlist_first_item_get(history_layout->m_history_genlist);
861                 while (it) {
862                         Browser_History_DB::history_item *item = NULL;
863                         item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
864                         if (item) {
865                                 /* Ignore the date label. */
866                                 if (elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
867                                         item->is_delete = !value;
868                                         elm_genlist_item_update(it);
869                                 }
870                         }
871                         it = elm_genlist_item_next_get(it);
872                 }
873
874                 history_layout->_show_selection_info();
875         }
876 }
877
878 void Browser_History_Layout::__history_item_clicked_cb(void *data, Evas_Object *obj, void *eventInfo)
879 {
880         BROWSER_LOGD("[%s]", __func__);
881         if (!data)
882                 return;
883
884         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
885
886         Elm_Object_Item *seleted_item = elm_genlist_selected_item_get(obj);
887         Elm_Object_Item *index_item = elm_genlist_first_item_get(obj);
888         int index = 0;
889
890         if (!elm_genlist_decorate_mode_get(obj)) {
891                 /* calculate the index of the selected item */
892                 while (index_item != seleted_item) {
893                         /* Do not count date label item */
894                         if (elm_genlist_item_select_mode_get(index_item) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)
895                                 index++;
896
897                         index_item = elm_genlist_item_next_get(index_item);
898                 }
899
900                 const char *selected_url = NULL;
901                 if (history_layout->m_searched_history_genlist == obj)
902                         selected_url = history_layout->m_searched_history_item_list[index]->url.c_str();
903                 else
904                         selected_url = history_layout->m_history_list[index]->url.c_str();
905
906                 m_data_manager->get_bookmark_view()->history_item_clicked(selected_url);
907         } else {
908                 Browser_History_DB::history_item *item = NULL;
909                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(seleted_item);
910                 if (item && elm_genlist_item_select_mode_get(seleted_item) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
911                         item->is_delete = !(item->is_delete);
912                         elm_genlist_item_update(seleted_item);
913                 }
914                 elm_genlist_item_selected_set(seleted_item, EINA_FALSE);
915
916                 int selected_count = 0;
917                 int total_count = 0;
918                 Elm_Object_Item *it = elm_genlist_first_item_get(history_layout->m_history_genlist);
919                 while(it) {
920                         item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
921                         if (elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
922                                 if (item->is_delete)
923                                         selected_count++;
924                                 total_count++;
925                         }
926                         it = elm_genlist_item_next_get(it);                     
927                 }
928
929                 if (selected_count == total_count)
930                         elm_check_state_set(history_layout->m_edit_mode_select_all_check_button, EINA_TRUE);
931                 else
932                         elm_check_state_set(history_layout->m_edit_mode_select_all_check_button, EINA_FALSE);
933
934                 history_layout->_show_selection_info();
935         }
936 }
937
938 void Browser_History_Layout::_delete_selected_history(void)
939 {
940         BROWSER_LOGD("[%s]", __func__);
941
942         Elm_Object_Item *it = elm_genlist_first_item_get(m_history_genlist);
943         int delete_item_count = 0;
944         Browser_History_DB::history_item *item = NULL;
945         while (it) {
946                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
947                 if ((elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) && item->is_delete) {
948                         delete_item_count++;
949                 }
950                 it = elm_genlist_item_next_get(it);
951         }
952
953         if (delete_item_count >= BROWSER_BOOKMARK_PROCESS_BLOCK_COUNT) {
954                 _show_delete_processing_popup();
955         } else {
956                 Eina_List *delete_item_list = NULL;
957                 it = elm_genlist_first_item_get(m_history_genlist);
958                 int remain_count = 0;
959                 Browser_History_DB::history_item *item = NULL;
960
961                 while (it) {
962                         item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
963                         if (elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
964                                 if (item->is_delete)
965                                         delete_item_list = eina_list_append(delete_item_list, it);
966                                 else
967                                         remain_count++;
968                         }
969                         it = elm_genlist_item_next_get(it);
970                 }
971
972                 int count = eina_list_count(delete_item_list);
973                 for (int i = 0; i < count; i++) {
974                         it = (Elm_Object_Item *)eina_list_data_get(delete_item_list);
975                         item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
976                         /* Delete history item */
977                         Eina_Bool ret = m_data_manager->get_history_db()->delete_history(item->id);
978                         if (!ret)
979                                 BROWSER_LOGD("history [%s] delete failed", item->title.c_str());
980
981                         delete_item_list = eina_list_next(delete_item_list);
982
983                         for(int index = 0 ; index < m_history_list.size() ; index++) {
984                                 if (m_history_list[index]->id == item->id) {
985                                         delete m_history_list[index];
986                                         m_history_list.erase(m_history_list.begin() + index);
987                                 }
988                         }
989
990                         elm_object_item_del(it);
991                 }
992                 eina_list_free(delete_item_list);
993
994                 elm_check_state_set(m_edit_mode_select_all_check_button, EINA_FALSE);
995
996                 _delete_date_only_label_genlist_item();
997
998                 if (remain_count == 0) {
999                         elm_box_unpack_all(m_content_box);
1000                         elm_genlist_clear(m_history_genlist);
1001                         evas_object_hide(m_history_genlist);
1002
1003                         if (m_edit_mode_select_all_layout) {
1004                                 evas_object_del(m_edit_mode_select_all_layout);
1005                                 m_edit_mode_select_all_layout = NULL;
1006                         }
1007                         if (m_edit_mode_select_all_check_button) {
1008                                 evas_object_del(m_edit_mode_select_all_check_button);
1009                                 m_edit_mode_select_all_check_button = NULL;
1010                         }
1011
1012                         m_no_history_label = elm_label_add(m_searchbar_layout);
1013                         if (!m_no_history_label) {
1014                                 BROWSER_LOGE("elm_label_add failed");
1015                                 return;
1016                         }
1017
1018                         std::string text = std::string("<color='#646464'>") + std::string(BR_STRING_NO_HISTORY);
1019                         elm_object_text_set(m_no_history_label, text.c_str());
1020                         evas_object_show(m_no_history_label);
1021                         elm_box_pack_start(m_content_box, m_no_history_label);
1022
1023                         Browser_Bookmark_View *bookmark_view = m_data_manager->get_bookmark_view();
1024                         if (!bookmark_view->_set_controlbar_type(Browser_Bookmark_View::HISTORY_VIEW_DEFAULT))
1025                                 BROWSER_LOGE("_set_controlbar_type failed");
1026
1027                         elm_object_item_disabled_set(bookmark_view->m_bookmark_edit_controlbar_item, EINA_TRUE);
1028                 }
1029
1030                 show_notify_popup(BR_STRING_DELETED, 3, EINA_TRUE);
1031         }
1032 }
1033
1034 void Browser_History_Layout::_reload_history_genlist(void)
1035 {
1036         Elm_Object_Item *it = NULL;
1037         while (it = elm_genlist_first_item_get(m_history_genlist))
1038                 elm_object_item_del(it);
1039
1040         for(int i = 0 ; i < m_history_list.size() ; i++ ) {
1041                 if (m_history_list[i])
1042                         delete m_history_list[i];
1043         }
1044         elm_box_unpack_all(m_content_box);
1045         m_history_list.clear(); 
1046
1047         for(int i = 0 ; i < m_history_date_label_list.size() ; i++ ) {
1048                 if (m_history_date_label_list[i])
1049                         free(m_history_date_label_list[i]);
1050         }
1051         m_history_date_label_list.clear();
1052
1053         Eina_Bool ret = m_data_manager->get_history_db()->get_history_list(m_history_list);
1054         if (!ret)
1055                 BROWSER_LOGE("get_history_list failed");
1056
1057         unsigned int history_count = m_history_list.size();
1058         BROWSER_LOGD("history_count=%d", history_count);
1059
1060         Date date;
1061         for(int i = 0 ; i < history_count; i++) {
1062                 sscanf(m_history_list[i]->date.c_str(), "%d-%d-%d", &date.year, &date.month, &date.day);
1063                 m_history_list[i]->user_data = (void *)this;
1064                 if (m_last_date != date) {
1065                         m_last_date = date;
1066                         char *labe_item = strdup(m_history_list[i]->date.c_str());
1067                         if (!labe_item) {
1068                                 BROWSER_LOGE("strdup failed");
1069                                 return;
1070                         }
1071                         m_history_date_label_list.push_back(labe_item);
1072                         it = elm_genlist_item_append(m_history_genlist, &m_history_group_title_class,
1073                                                         labe_item, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL);
1074
1075                         elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1076                 }
1077                 elm_genlist_item_append(m_history_genlist, &m_history_genlist_item_class, m_history_list[i], it,
1078                                         ELM_GENLIST_ITEM_NONE, __history_item_clicked_cb, this);
1079         }
1080
1081         if (m_no_history_label) {
1082                 evas_object_del(m_no_history_label);
1083                 m_no_history_label = NULL;
1084         }
1085
1086         if (m_edit_mode_select_all_check_button) {
1087                 evas_object_del(m_edit_mode_select_all_check_button);
1088                 m_edit_mode_select_all_check_button = NULL;
1089         }
1090
1091         if (m_edit_mode_select_all_layout) {
1092                 evas_object_del(m_edit_mode_select_all_layout);
1093                 m_edit_mode_select_all_layout = NULL;
1094         }
1095
1096         if (m_history_list.size() == 0) {
1097                 evas_object_hide(m_history_genlist);
1098
1099                 m_no_history_label = elm_label_add(m_searchbar_layout);
1100                 if (!m_no_history_label) {
1101                         BROWSER_LOGE("elm_label_add failed");
1102                         return;
1103                 }
1104
1105                 std::string text = std::string("<color='#646464'>") + std::string(BR_STRING_NO_HISTORY);
1106                 elm_object_text_set(m_no_history_label, text.c_str());
1107                 evas_object_show(m_no_history_label);
1108                 elm_box_pack_start(m_content_box, m_no_history_label);
1109
1110                 Browser_Bookmark_View *bookmark_view = m_data_manager->get_bookmark_view();
1111                 if (!bookmark_view->_set_controlbar_type(Browser_Bookmark_View::HISTORY_VIEW_DEFAULT))
1112                         BROWSER_LOGE("_set_controlbar_type failed");
1113                 elm_object_item_disabled_set(bookmark_view->m_bookmark_edit_controlbar_item, EINA_TRUE);
1114         } else {
1115                 elm_box_pack_start(m_content_box, m_history_genlist);
1116                 evas_object_show(m_history_genlist);
1117
1118                 Browser_Bookmark_View *bookmark_view = m_data_manager->get_bookmark_view();
1119                 elm_object_item_disabled_set(bookmark_view->m_bookmark_edit_controlbar_item, EINA_FALSE);
1120         }
1121 }
1122
1123 Eina_Bool Browser_History_Layout::_create_main_layout(void)
1124 {
1125         BROWSER_LOGD("[%s]", __func__);
1126         elm_object_style_set(m_bg, "default");  
1127
1128         m_searchbar_layout = elm_layout_add(m_navi_bar);
1129         if (!m_searchbar_layout) {
1130                 BROWSER_LOGE("elm_layout_add failed");
1131                 return EINA_FALSE;
1132         }
1133
1134         _enable_searchbar_layout(EINA_TRUE);
1135
1136         evas_object_show(m_searchbar_layout);
1137
1138         m_content_box = elm_box_add(m_searchbar_layout);
1139         if (!m_content_box) {
1140                 BROWSER_LOGE("elm_box_add failed");
1141                 return EINA_FALSE;
1142         }
1143
1144         m_history_genlist = _create_history_genlist();
1145         if (!m_history_genlist) {
1146                 BROWSER_LOGE("_create_history_genlist failed");
1147                 return EINA_FALSE;
1148         }
1149
1150         m_history_genlist_item_class.item_style = "2text.1icon.4";
1151         m_history_genlist_item_class.decorate_all_item_style = "edit_default";
1152         m_history_genlist_item_class.func.text_get = __genlist_label_get_cb;
1153         m_history_genlist_item_class.func.content_get = __genlist_icon_get_cb;
1154         m_history_genlist_item_class.func.state_get = NULL;
1155         m_history_genlist_item_class.func.del = NULL;
1156
1157         m_history_group_title_class.item_style = "grouptitle";
1158         m_history_group_title_class.func.text_get = __genlist_date_label_get_cb;
1159         m_history_group_title_class.func.content_get = NULL;
1160         m_history_group_title_class.func.state_get = NULL;
1161         m_history_group_title_class.func.del = NULL;
1162
1163         _reload_history_genlist();
1164
1165         evas_object_show(m_content_box);
1166         elm_object_part_content_set(m_searchbar_layout, "elm.swallow.content", m_content_box);
1167
1168         return EINA_TRUE;
1169 }
1170
1171 Evas_Object *Browser_History_Layout::_show_delete_confirm_popup(void)
1172 {
1173         BROWSER_LOGD("[%s]", __func__);
1174
1175         m_delete_confirm_popup = elm_popup_add(m_navi_bar);
1176         if (!m_delete_confirm_popup) {
1177                 BROWSER_LOGE("elm_popup_add failed");
1178                 return NULL;
1179         }
1180
1181         evas_object_size_hint_weight_set(m_delete_confirm_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1182         elm_object_text_set(m_delete_confirm_popup, BR_STRING_DELETE_Q);
1183
1184         Evas_Object *ok_button = elm_button_add(m_delete_confirm_popup);
1185         elm_object_text_set(ok_button, BR_STRING_YES);
1186         elm_object_part_content_set(m_delete_confirm_popup, "button1", ok_button);
1187
1188         Evas_Object *cancel_button = elm_button_add(m_delete_confirm_popup);
1189         elm_object_text_set(cancel_button, BR_STRING_NO);
1190         elm_object_part_content_set(m_delete_confirm_popup, "button2", cancel_button);
1191         evas_object_smart_callback_add(cancel_button, "clicked", __cancel_confirm_response_by_slide_button_cb,
1192                                                                                 m_delete_confirm_popup);
1193
1194         evas_object_show(m_delete_confirm_popup);
1195
1196         return ok_button;
1197 }
1198 char *Browser_History_Layout::__genlist_label_get_cb(void *data, Evas_Object *obj, const char *part)
1199 {
1200         if (!data)
1201                 return NULL;
1202
1203         Browser_History_DB::history_item *item = (Browser_History_DB::history_item *)data;
1204         if (!item)
1205                 return NULL;
1206
1207         char *mark_up = NULL;
1208
1209         if (!strncmp(part, "elm.text.1", strlen("elm.text.1"))
1210                 || !strncmp(part, "elm.base.text", strlen("elm.base.text")))
1211         {
1212                 mark_up = elm_entry_utf8_to_markup(item->title.c_str());
1213                 return mark_up;
1214         } else if (!strncmp(part, "elm.text.2", strlen("elm.text.2"))) {
1215                 mark_up = elm_entry_utf8_to_markup(item->url.c_str());
1216                 return mark_up;
1217         }
1218
1219         return NULL;
1220 }
1221
1222 char *Browser_History_Layout::__genlist_date_label_get_cb(void *data, Evas_Object *obj, const char *part)
1223 {
1224         if (!data)
1225                 return NULL;
1226
1227         char *date_label = (char *)data;
1228
1229         if (!strncmp(part, "elm.text", strlen("elm.text"))) {
1230                 Date date;
1231                 char buffer[BROWSER_MAX_DATE_LEN] = {0, };
1232
1233                 sscanf(date_label, "%d-%d-%d",
1234                         &date.year, &date.month, &date.day);
1235 //              BROWSER_LOGD("%d %d %d\n", date.day, date.month, date.year);
1236                 time_t raw_time;
1237                 struct tm *time_info;
1238                 time(&raw_time);
1239                 time_info = localtime(&raw_time);
1240                 int day_gap = -1;
1241 //              BROWSER_LOGD("\ncurrent time : %d %d %d\n", time_info->tm_mday, (time_info->tm_mon+1), (time_info->tm_year+1900));
1242                 if (time_info->tm_year == date.year -1900 && time_info->tm_mon == date.month - 1)
1243                         day_gap = time_info->tm_mday - date.day;
1244                 else {
1245                         time_info->tm_year = date.year - 1900;
1246                         time_info->tm_mon = date.month - 1;
1247                 }
1248                 time_info->tm_mday = date.day;
1249                 mktime(time_info);
1250
1251                 if (day_gap == 0)
1252                         strftime (buffer, BROWSER_MAX_DATE_LEN, "Today (%a, %b %d %Y)", time_info);
1253                 else if (day_gap == 1)
1254                         strftime (buffer, 40, "Yesterday (%a, %b %d %Y)", time_info);
1255                 else
1256                         strftime (buffer, 40, "%a, %b %d %Y", time_info);
1257                 return strdup(buffer);
1258         }
1259         return NULL;
1260 }
1261
1262 void Browser_History_Layout::__delete_confirm_response_by_edit_mode_cb(void *data, Evas_Object *obj,
1263                                                                 void *event_info)
1264 {
1265         BROWSER_LOGD("event_info = %d", (int)event_info);
1266
1267         if (!data)
1268                 return;
1269
1270         Browser_History_Layout *history_layout = (Browser_History_Layout *)data;
1271
1272         if (history_layout->m_delete_confirm_popup) {
1273                 evas_object_del(history_layout->m_delete_confirm_popup);
1274                 history_layout->m_delete_confirm_popup = NULL;
1275         }
1276
1277         history_layout->_delete_selected_history();
1278
1279         history_layout->_set_edit_mode(EINA_FALSE);
1280 }
1281 void Browser_History_Layout::__cancel_confirm_response_by_slide_button_cb(void *data, Evas_Object *obj,
1282                                                                 void *event_info)
1283 {
1284         BROWSER_LOGD("event_info = %d", (int)event_info);
1285
1286         if (!data)
1287                 return;
1288
1289         Evas_Object *popup = (Evas_Object *)data;
1290         evas_object_del(popup);
1291 }
1292
1293 void Browser_History_Layout::_delete_date_only_label_genlist_item(void)
1294 {
1295         BROWSER_LOGD("[%s]", __func__);
1296
1297         Elm_Object_Item *it = elm_genlist_first_item_get(m_history_genlist);
1298         /* Remove date only label item */
1299         while (it) {
1300                 if (elm_genlist_item_select_mode_get(it) == ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
1301                         Elm_Object_Item *tmp_it = elm_genlist_item_next_get(it);
1302                         if (!tmp_it || elm_genlist_item_select_mode_get(tmp_it) == ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
1303                                 tmp_it = it;
1304                                 it = elm_genlist_item_next_get(it);
1305                                 elm_object_item_del(tmp_it);
1306                                 continue;
1307                         }
1308                 }
1309                 it = elm_genlist_item_next_get(it);
1310         }
1311 }
1312
1313 Evas_Object *Browser_History_Layout::__genlist_icon_get_cb(void *data, Evas_Object *obj, const char *part)
1314 {
1315         if (!data || !part)
1316                 return NULL;
1317
1318         Browser_History_DB::history_item *item = (Browser_History_DB::history_item *)data;
1319         Browser_History_Layout *history_layout = (Browser_History_Layout *)item->user_data;
1320         if (!history_layout)
1321                 return NULL;
1322
1323         if (!strncmp(part, "elm.icon", strlen("elm.icon"))) {
1324                 Evas_Object *favicon = NULL;
1325                 favicon = m_data_manager->get_browser_view()->get_favicon(item->url.c_str());
1326                 if (favicon)
1327                         return favicon;
1328                 else {
1329                         Evas_Object *default_favicon = elm_icon_add(obj);
1330                         if (!default_favicon) {
1331                                 BROWSER_LOGE("elm_icon_add is failed");
1332                                 return NULL;
1333                         }
1334                         elm_icon_file_set(default_favicon, BROWSER_IMAGE_DIR"/faviconDefault.png", NULL);
1335                         evas_object_size_hint_aspect_set(default_favicon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1336                         return default_favicon;
1337                 }
1338         } else if (!strncmp(part, "elm.edit.icon.1", strlen("elm.edit.icon.1"))) {
1339                 if (elm_genlist_decorate_mode_get(obj)) {
1340                         Evas_Object *check_button = elm_check_add(obj);
1341                         if (!check_button) {
1342                                 BROWSER_LOGE("elm_check_add is failed");
1343                                 return NULL;
1344                         }
1345                         elm_check_state_pointer_set(check_button, &(item->is_delete));
1346                         elm_check_state_set(check_button, item->is_delete);
1347                         evas_object_smart_callback_add(check_button, "changed", __edit_mode_item_check_changed_cb, item);
1348                         return check_button;
1349                 }
1350         }
1351
1352         return NULL;
1353 }
1354
1355 void Browser_History_Layout::__edit_mode_item_check_changed_cb(void *data, Evas_Object *obj, void *event_info)
1356 {
1357         BROWSER_LOGD("[%s]", __func__);
1358         if (!data)
1359                 return;
1360         Browser_History_DB::history_item *item = (Browser_History_DB::history_item *)data;
1361         Browser_History_Layout *history_layout = (Browser_History_Layout *)(item->user_data);
1362         int selected_count = 0;
1363         int total_count = 0;
1364         Elm_Object_Item *it = elm_genlist_first_item_get(history_layout->m_history_genlist);
1365         while(it) {
1366                 Browser_History_DB::history_item *item = NULL;
1367                 item = (Browser_History_DB::history_item *)elm_object_item_data_get(it);
1368
1369                 /* Ignore the date label. */
1370                 if (elm_genlist_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
1371                         total_count++;
1372                         if (item->is_delete)
1373                                 selected_count++;
1374                 }
1375                 it = elm_genlist_item_next_get(it);
1376         }
1377
1378         if (total_count == selected_count)
1379                 elm_check_state_set(history_layout->m_edit_mode_select_all_check_button, EINA_TRUE);
1380         else
1381                 elm_check_state_set(history_layout->m_edit_mode_select_all_check_button, EINA_FALSE);
1382
1383         history_layout->_show_selection_info();
1384 }
1385
1386 Evas_Object *Browser_History_Layout::_create_history_genlist(void)
1387 {
1388         BROWSER_LOGD("[%s]", __func__);
1389         Evas_Object *genlist = elm_genlist_add(m_searchbar_layout);
1390         if (genlist) {
1391                 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1392                 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1393         }
1394
1395         return genlist;
1396 }
1397