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