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