| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/gtk/options/cookies_view.h" | 5 #include "chrome/browser/gtk/options/cookies_view.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/gfx/gtk_util.h" | 11 #include "base/gfx/gtk_util.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/time_format.h" | 14 #include "base/time_format.h" |
| 15 #include "chrome/browser/cookies_table_model.h" | 15 #include "chrome/browser/cookies_table_model.h" |
| 16 #include "chrome/common/gtk_util.h" | 16 #include "chrome/common/gtk_util.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 // Initial size for dialog. | 21 // Initial size for dialog. |
| 23 const int kDialogDefaultWidth = 550; | 22 const int kDialogDefaultWidth = 550; |
| 24 const int kDialogDefaultHeight = 550; | 23 const int kDialogDefaultHeight = 550; |
| 25 const int kSiteColumnInitialSize = 300; | 24 const int kSiteColumnInitialSize = 300; |
| 26 | 25 |
| 27 // Delay after entering filter text before filtering occurs. | 26 // Delay after entering filter text before filtering occurs. |
| 28 const int kSearchFilterDelayMs = 500; | 27 const int kSearchFilterDelayMs = 100; |
| 29 | 28 |
| 30 // Response ids for our custom buttons. | 29 // Response ids for our custom buttons. |
| 31 enum { | 30 enum { |
| 32 RESPONSE_REMOVE = 1, | 31 RESPONSE_REMOVE = 1, |
| 33 RESPONSE_REMOVE_ALL | 32 RESPONSE_REMOVE_ALL |
| 34 }; | 33 }; |
| 35 | 34 |
| 36 // The currently open cookie manager, if any. | 35 // The currently open cookie manager, if any. |
| 37 CookiesView* instance_ = NULL; | 36 CookiesView* instance_ = NULL; |
| 38 | 37 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 void CookiesView::Init() { | 78 void CookiesView::Init() { |
| 80 dialog_ = gtk_dialog_new_with_buttons( | 79 dialog_ = gtk_dialog_new_with_buttons( |
| 81 l10n_util::GetStringUTF8(IDS_COOKIES_WINDOW_TITLE).c_str(), | 80 l10n_util::GetStringUTF8(IDS_COOKIES_WINDOW_TITLE).c_str(), |
| 82 NULL, | 81 NULL, |
| 83 GTK_DIALOG_NO_SEPARATOR, | 82 GTK_DIALOG_NO_SEPARATOR, |
| 84 GTK_STOCK_CLOSE, | 83 GTK_STOCK_CLOSE, |
| 85 GTK_RESPONSE_CLOSE, | 84 GTK_RESPONSE_CLOSE, |
| 86 NULL); | 85 NULL); |
| 87 gtk_util::SetWindowIcon(GTK_WINDOW(dialog_)); | 86 gtk_util::SetWindowIcon(GTK_WINDOW(dialog_)); |
| 88 | 87 |
| 89 remove_button_ = gtk_dialog_add_button( | 88 remove_button_ = gtk_util::AddButtonToDialog( |
| 90 GTK_DIALOG(dialog_), | 89 dialog_, |
| 91 gtk_util::ConvertAcceleratorsFromWindowsStyle( | 90 gtk_util::ConvertAcceleratorsFromWindowsStyle( |
| 92 l10n_util::GetStringUTF8(IDS_COOKIES_REMOVE_LABEL)).c_str(), | 91 l10n_util::GetStringUTF8(IDS_COOKIES_REMOVE_LABEL)).c_str(), |
| 92 GTK_STOCK_REMOVE, |
| 93 RESPONSE_REMOVE); | 93 RESPONSE_REMOVE); |
| 94 gtk_button_box_set_child_secondary( | 94 gtk_button_box_set_child_secondary( |
| 95 GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), | 95 GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), |
| 96 remove_button_, | 96 remove_button_, |
| 97 TRUE); | 97 TRUE); |
| 98 | 98 |
| 99 remove_all_button_ = gtk_dialog_add_button( | 99 remove_all_button_ = gtk_util::AddButtonToDialog( |
| 100 GTK_DIALOG(dialog_), | 100 dialog_, |
| 101 gtk_util::ConvertAcceleratorsFromWindowsStyle( | 101 gtk_util::ConvertAcceleratorsFromWindowsStyle( |
| 102 l10n_util::GetStringUTF8(IDS_COOKIES_REMOVE_ALL_LABEL)).c_str(), | 102 l10n_util::GetStringUTF8(IDS_COOKIES_REMOVE_ALL_LABEL)).c_str(), |
| 103 GTK_STOCK_CLEAR, |
| 103 RESPONSE_REMOVE_ALL); | 104 RESPONSE_REMOVE_ALL); |
| 104 gtk_button_box_set_child_secondary( | 105 gtk_button_box_set_child_secondary( |
| 105 GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), | 106 GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), |
| 106 remove_all_button_, | 107 remove_all_button_, |
| 107 TRUE); | 108 TRUE); |
| 108 | 109 |
| 109 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_CLOSE); | 110 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_CLOSE); |
| 110 gtk_window_set_default_size(GTK_WINDOW(dialog_), kDialogDefaultWidth, | 111 gtk_window_set_default_size(GTK_WINDOW(dialog_), kDialogDefaultWidth, |
| 111 kDialogDefaultHeight); | 112 kDialogDefaultHeight); |
| 112 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), | 113 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 151 |
| 151 GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); | 152 GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); |
| 152 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), | 153 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), |
| 153 GTK_POLICY_AUTOMATIC, | 154 GTK_POLICY_AUTOMATIC, |
| 154 GTK_POLICY_AUTOMATIC); | 155 GTK_POLICY_AUTOMATIC); |
| 155 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), | 156 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), |
| 156 GTK_SHADOW_ETCHED_IN); | 157 GTK_SHADOW_ETCHED_IN); |
| 157 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0); | 158 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0); |
| 158 | 159 |
| 159 list_store_ = gtk_list_store_new(COL_COUNT, | 160 list_store_ = gtk_list_store_new(COL_COUNT, |
| 160 GDK_TYPE_PIXBUF, | |
| 161 G_TYPE_STRING, | 161 G_TYPE_STRING, |
| 162 G_TYPE_STRING); | 162 G_TYPE_STRING); |
| 163 list_sort_ = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(list_store_)); | 163 list_sort_ = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(list_store_)); |
| 164 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_sort_), | 164 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_sort_), |
| 165 COL_SITE, CompareSite, this, NULL); | 165 COL_SITE, CompareSite, this, NULL); |
| 166 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_sort_), | 166 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_sort_), |
| 167 COL_COOKIE_NAME, CompareCookieName, this, | 167 COL_COOKIE_NAME, CompareCookieName, this, |
| 168 NULL); | 168 NULL); |
| 169 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list_sort_), | 169 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list_sort_), |
| 170 COL_SITE, GTK_SORT_ASCENDING); | 170 COL_SITE, GTK_SORT_ASCENDING); |
| 171 tree_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_sort_)); | 171 tree_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_sort_)); |
| 172 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_), TRUE); | 172 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_), TRUE); |
| 173 gtk_container_add(GTK_CONTAINER(scroll_window), tree_); | 173 gtk_container_add(GTK_CONTAINER(scroll_window), tree_); |
| 174 | 174 |
| 175 GtkTreeViewColumn* site_column = gtk_tree_view_column_new(); | 175 GtkTreeViewColumn* site_column = gtk_tree_view_column_new(); |
| 176 GtkCellRenderer* pixbuf_renderer = gtk_cell_renderer_pixbuf_new(); | |
| 177 gtk_tree_view_column_pack_start(site_column, pixbuf_renderer, FALSE); | |
| 178 gtk_tree_view_column_add_attribute(site_column, pixbuf_renderer, "pixbuf", | |
| 179 COL_ICON); | |
| 180 GtkCellRenderer* site_renderer = gtk_cell_renderer_text_new(); | 176 GtkCellRenderer* site_renderer = gtk_cell_renderer_text_new(); |
| 181 gtk_tree_view_column_pack_start(site_column, site_renderer, TRUE); | 177 gtk_tree_view_column_pack_start(site_column, site_renderer, TRUE); |
| 182 gtk_tree_view_column_add_attribute(site_column, site_renderer, "text", | 178 gtk_tree_view_column_add_attribute(site_column, site_renderer, "text", |
| 183 COL_SITE); | 179 COL_SITE); |
| 184 gtk_tree_view_column_set_title( | 180 gtk_tree_view_column_set_title( |
| 185 site_column, l10n_util::GetStringUTF8( | 181 site_column, l10n_util::GetStringUTF8( |
| 186 IDS_COOKIES_DOMAIN_COLUMN_HEADER).c_str()); | 182 IDS_COOKIES_DOMAIN_COLUMN_HEADER).c_str()); |
| 187 gtk_tree_view_column_set_sort_column_id(site_column, COL_SITE); | 183 gtk_tree_view_column_set_sort_column_id(site_column, COL_SITE); |
| 188 gtk_tree_view_column_set_sizing(site_column, GTK_TREE_VIEW_COLUMN_FIXED); | 184 gtk_tree_view_column_set_sizing(site_column, GTK_TREE_VIEW_COLUMN_FIXED); |
| 189 gtk_tree_view_column_set_resizable(site_column, TRUE); | 185 gtk_tree_view_column_set_resizable(site_column, TRUE); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 selected != selected_rows.rend(); ++selected) { | 359 selected != selected_rows.rend(); ++selected) { |
| 364 cookies_table_model_->RemoveCookies(*selected, 1); | 360 cookies_table_model_->RemoveCookies(*selected, 1); |
| 365 } | 361 } |
| 366 } | 362 } |
| 367 | 363 |
| 368 void CookiesView::OnAnyModelUpdate() { | 364 void CookiesView::OnAnyModelUpdate() { |
| 369 EnableControls(); | 365 EnableControls(); |
| 370 } | 366 } |
| 371 | 367 |
| 372 void CookiesView::SetColumnValues(int row, GtkTreeIter* iter) { | 368 void CookiesView::SetColumnValues(int row, GtkTreeIter* iter) { |
| 373 SkBitmap bitmap = cookies_table_model_->GetIcon(row); | |
| 374 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); | |
| 375 std::wstring site = cookies_table_model_->GetText( | 369 std::wstring site = cookies_table_model_->GetText( |
| 376 row, IDS_COOKIES_DOMAIN_COLUMN_HEADER); | 370 row, IDS_COOKIES_DOMAIN_COLUMN_HEADER); |
| 377 std::wstring name = cookies_table_model_->GetText( | 371 std::wstring name = cookies_table_model_->GetText( |
| 378 row, IDS_COOKIES_NAME_COLUMN_HEADER); | 372 row, IDS_COOKIES_NAME_COLUMN_HEADER); |
| 379 gtk_list_store_set(list_store_, iter, | 373 gtk_list_store_set(list_store_, iter, |
| 380 COL_ICON, pixbuf, | |
| 381 COL_SITE, WideToUTF8(site).c_str(), | 374 COL_SITE, WideToUTF8(site).c_str(), |
| 382 COL_COOKIE_NAME, WideToUTF8(name).c_str(), | 375 COL_COOKIE_NAME, WideToUTF8(name).c_str(), |
| 383 -1); | 376 -1); |
| 384 g_object_unref(pixbuf); | |
| 385 } | 377 } |
| 386 | 378 |
| 387 // Compare the value of the given column at the given rows. | 379 // Compare the value of the given column at the given rows. |
| 388 gint CookiesView::CompareRows(GtkTreeModel* model, GtkTreeIter* a, | 380 gint CookiesView::CompareRows(GtkTreeModel* model, GtkTreeIter* a, |
| 389 GtkTreeIter* b, int column_id) { | 381 GtkTreeIter* b, int column_id) { |
| 390 int row1 = gtk_tree::GetRowNumForIter(model, a); | 382 int row1 = gtk_tree::GetRowNumForIter(model, a); |
| 391 int row2 = gtk_tree::GetRowNumForIter(model, b); | 383 int row2 = gtk_tree::GetRowNumForIter(model, b); |
| 392 return cookies_table_model_->CompareValues(row1, row2, column_id); | 384 return cookies_table_model_->CompareValues(row1, row2, column_id); |
| 393 } | 385 } |
| 394 | 386 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 window->EnableControls(); | 444 window->EnableControls(); |
| 453 } | 445 } |
| 454 | 446 |
| 455 // static | 447 // static |
| 456 void CookiesView::OnFilterClearButtonClicked(GtkButton* button, | 448 void CookiesView::OnFilterClearButtonClicked(GtkButton* button, |
| 457 CookiesView* window) { | 449 CookiesView* window) { |
| 458 gtk_entry_set_text(GTK_ENTRY(window->filter_entry_), ""); | 450 gtk_entry_set_text(GTK_ENTRY(window->filter_entry_), ""); |
| 459 window->filter_update_factory_.RevokeAll(); | 451 window->filter_update_factory_.RevokeAll(); |
| 460 window->UpdateFilterResults(); | 452 window->UpdateFilterResults(); |
| 461 } | 453 } |
| OLD | NEW |