Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: chrome/browser/gtk/options/simple_content_exceptions_window.cc

Issue 2835031: Rename GeolocationExceptionsView, make it more reusable. (Closed)
Patch Set: comments Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/geolocation_content_exceptions_window.h" 5 #include "chrome/browser/gtk/options/simple_content_exceptions_window.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
11 #include "chrome/browser/gtk/gtk_util.h" 10 #include "chrome/browser/gtk/gtk_util.h"
12 #include "gfx/gtk_util.h" 11 #include "gfx/gtk_util.h"
13 #include "grit/generated_resources.h" 12 #include "grit/generated_resources.h"
14 #include "grit/locale_settings.h" 13 #include "grit/locale_settings.h"
15 14
16 namespace { 15 namespace {
17 16
18 // Singleton for exception window. 17 // Singleton for exception window.
19 GeolocationContentExceptionsWindow* instance = NULL; 18 SimpleContentExceptionsWindow* instance = NULL;
20 19
21 } // namespace 20 } // namespace
22 21
23 // static 22 // static
24 void GeolocationContentExceptionsWindow::ShowExceptionsWindow( 23 void SimpleContentExceptionsWindow::ShowExceptionsWindow(
25 GtkWindow* parent, GeolocationContentSettingsMap* map) { 24 GtkWindow* parent, RemoveRowsTableModel* model) {
26 DCHECK(map); 25 DCHECK(model);
26 scoped_ptr<RemoveRowsTableModel> owned_model(model);
27 27
28 if (!instance) { 28 if (!instance) {
29 instance = new GeolocationContentExceptionsWindow(parent, map); 29 instance = new SimpleContentExceptionsWindow(parent, owned_model.release());
30 } else { 30 } else {
31 gtk_util::PresentWindow(instance->dialog_, 0); 31 gtk_util::PresentWindow(instance->dialog_, 0);
32 } 32 }
33 } 33 }
34 34
35 GeolocationContentExceptionsWindow::GeolocationContentExceptionsWindow( 35 SimpleContentExceptionsWindow::SimpleContentExceptionsWindow(
36 GtkWindow* parent, 36 GtkWindow* parent,
37 GeolocationContentSettingsMap* map) { 37 RemoveRowsTableModel* model) {
38 // Build the model adapters that translate views and TableModels into 38 // Build the model adapters that translate views and TableModels into
39 // something GTK can use. 39 // something GTK can use.
40 list_store_ = gtk_list_store_new(COL_COUNT, G_TYPE_STRING, G_TYPE_STRING); 40 list_store_ = gtk_list_store_new(COL_COUNT, G_TYPE_STRING, G_TYPE_STRING);
41 treeview_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store_)); 41 treeview_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store_));
42 g_object_unref(list_store_); 42 g_object_unref(list_store_);
43 43
44 // Set up the properties of the treeview 44 // Set up the properties of the treeview
45 GtkTreeViewColumn* hostname_column = gtk_tree_view_column_new_with_attributes( 45 GtkTreeViewColumn* hostname_column = gtk_tree_view_column_new_with_attributes(
46 l10n_util::GetStringUTF8(IDS_EXCEPTIONS_HOSTNAME_HEADER).c_str(), 46 l10n_util::GetStringUTF8(IDS_EXCEPTIONS_HOSTNAME_HEADER).c_str(),
47 gtk_cell_renderer_text_new(), 47 gtk_cell_renderer_text_new(),
48 "text", COL_HOSTNAME, 48 "text", COL_HOSTNAME,
49 NULL); 49 NULL);
50 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_), hostname_column); 50 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_), hostname_column);
51 51
52 GtkTreeViewColumn* action_column = gtk_tree_view_column_new_with_attributes( 52 GtkTreeViewColumn* action_column = gtk_tree_view_column_new_with_attributes(
53 l10n_util::GetStringUTF8(IDS_EXCEPTIONS_ACTION_HEADER).c_str(), 53 l10n_util::GetStringUTF8(IDS_EXCEPTIONS_ACTION_HEADER).c_str(),
54 gtk_cell_renderer_text_new(), 54 gtk_cell_renderer_text_new(),
55 "text", COL_ACTION, 55 "text", COL_ACTION,
56 NULL); 56 NULL);
57 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_), action_column); 57 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_), action_column);
58 58
59 treeview_selection_ = gtk_tree_view_get_selection( 59 treeview_selection_ = gtk_tree_view_get_selection(
60 GTK_TREE_VIEW(treeview_)); 60 GTK_TREE_VIEW(treeview_));
61 gtk_tree_selection_set_mode(treeview_selection_, GTK_SELECTION_MULTIPLE); 61 gtk_tree_selection_set_mode(treeview_selection_, GTK_SELECTION_MULTIPLE);
62 g_signal_connect(treeview_selection_, "changed", 62 g_signal_connect(treeview_selection_, "changed",
63 G_CALLBACK(OnTreeSelectionChangedThunk), this); 63 G_CALLBACK(OnTreeSelectionChangedThunk), this);
64 64
65 // Bind |list_store_| to our C++ model. 65 // Bind |list_store_| to our C++ model.
66 model_.reset(new GeolocationExceptionsTableModel(map)); 66 model_.reset(model);
67 model_adapter_.reset(new gtk_tree::TableAdapter(this, list_store_, 67 model_adapter_.reset(new gtk_tree::TableAdapter(this, list_store_,
68 model_.get())); 68 model_.get()));
69 // Force a reload of everything to copy data into |list_store_|. 69 // Force a reload of everything to copy data into |list_store_|.
70 model_adapter_->OnModelChanged(); 70 model_adapter_->OnModelChanged();
71 71
72 dialog_ = gtk_dialog_new_with_buttons( 72 dialog_ = gtk_dialog_new_with_buttons(
73 l10n_util::GetStringUTF8(IDS_GEOLOCATION_EXCEPTION_TITLE).c_str(), 73 l10n_util::GetStringUTF8(IDS_GEOLOCATION_EXCEPTION_TITLE).c_str(),
74 parent, 74 parent,
75 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), 75 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
76 GTK_STOCK_CLOSE, 76 GTK_STOCK_CLOSE,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 gtk_util::ShowDialogWithLocalizedSize(dialog_, 118 gtk_util::ShowDialogWithLocalizedSize(dialog_,
119 IDS_GEOLOCATION_EXCEPTION_DIALOG_WIDTH_CHARS, 119 IDS_GEOLOCATION_EXCEPTION_DIALOG_WIDTH_CHARS,
120 IDS_GEOLOCATION_EXCEPTION_DIALOG_HEIGHT_LINES, 120 IDS_GEOLOCATION_EXCEPTION_DIALOG_HEIGHT_LINES,
121 true); 121 true);
122 122
123 g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); 123 g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL);
124 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); 124 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this);
125 } 125 }
126 126
127 void GeolocationContentExceptionsWindow::SetColumnValues(int row, 127 void SimpleContentExceptionsWindow::SetColumnValues(int row,
128 GtkTreeIter* iter) { 128 GtkTreeIter* iter) {
129 std::wstring hostname = model_->GetText(row, IDS_EXCEPTIONS_HOSTNAME_HEADER); 129 std::wstring hostname = model_->GetText(row, IDS_EXCEPTIONS_HOSTNAME_HEADER);
130 gtk_list_store_set(list_store_, iter, COL_HOSTNAME, 130 gtk_list_store_set(list_store_, iter, COL_HOSTNAME,
131 WideToUTF8(hostname).c_str(), -1); 131 WideToUTF8(hostname).c_str(), -1);
132 132
133 std::wstring action = model_->GetText(row, IDS_EXCEPTIONS_ACTION_HEADER); 133 std::wstring action = model_->GetText(row, IDS_EXCEPTIONS_ACTION_HEADER);
134 gtk_list_store_set(list_store_, iter, COL_ACTION, 134 gtk_list_store_set(list_store_, iter, COL_ACTION,
135 WideToUTF8(action).c_str(), -1); 135 WideToUTF8(action).c_str(), -1);
136 } 136 }
137 137
138 void GeolocationContentExceptionsWindow::UpdateButtonState() { 138 void SimpleContentExceptionsWindow::UpdateButtonState() {
139 int row_count = gtk_tree_model_iter_n_children( 139 int row_count = gtk_tree_model_iter_n_children(
140 GTK_TREE_MODEL(list_store_), NULL); 140 GTK_TREE_MODEL(list_store_), NULL);
141 141
142 GeolocationExceptionsTableModel::Rows rows; 142 RemoveRowsTableModel::Rows rows;
143 GetSelectedRows(&rows); 143 GetSelectedRows(&rows);
144 gtk_widget_set_sensitive(remove_button_, model_->CanRemoveRows(rows)); 144 gtk_widget_set_sensitive(remove_button_, model_->CanRemoveRows(rows));
145 gtk_widget_set_sensitive(remove_all_button_, row_count > 0); 145 gtk_widget_set_sensitive(remove_all_button_, row_count > 0);
146 } 146 }
147 147
148 void GeolocationContentExceptionsWindow::GetSelectedRows( 148 void SimpleContentExceptionsWindow::GetSelectedRows(
149 GeolocationExceptionsTableModel::Rows* rows) { 149 RemoveRowsTableModel::Rows* rows) {
150 std::set<int> indices; 150 std::set<int> indices;
151 gtk_tree::GetSelectedIndices(treeview_selection_, &indices); 151 gtk_tree::GetSelectedIndices(treeview_selection_, &indices);
152 for (std::set<int>::iterator i = indices.begin(); i != indices.end(); ++i) 152 for (std::set<int>::iterator i = indices.begin(); i != indices.end(); ++i)
153 rows->insert(*i); 153 rows->insert(*i);
154 } 154 }
155 155
156 void GeolocationContentExceptionsWindow::Remove(GtkWidget* widget) { 156 void SimpleContentExceptionsWindow::Remove(GtkWidget* widget) {
157 GeolocationExceptionsTableModel::Rows rows; 157 RemoveRowsTableModel::Rows rows;
158 GetSelectedRows(&rows); 158 GetSelectedRows(&rows);
159 model_->RemoveRows(rows); 159 model_->RemoveRows(rows);
160 UpdateButtonState(); 160 UpdateButtonState();
161 } 161 }
162 162
163 void GeolocationContentExceptionsWindow::RemoveAll(GtkWidget* widget) { 163 void SimpleContentExceptionsWindow::RemoveAll(GtkWidget* widget) {
164 model_->RemoveAll(); 164 model_->RemoveAll();
165 UpdateButtonState(); 165 UpdateButtonState();
166 } 166 }
167 167
168 void GeolocationContentExceptionsWindow::OnWindowDestroy(GtkWidget* widget) { 168 void SimpleContentExceptionsWindow::OnWindowDestroy(GtkWidget* widget) {
169 instance = NULL; 169 instance = NULL;
170 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 170 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
171 } 171 }
172 172
173 void GeolocationContentExceptionsWindow::OnTreeSelectionChanged( 173 void SimpleContentExceptionsWindow::OnTreeSelectionChanged(
174 GtkWidget* selection) { 174 GtkWidget* selection) {
175 UpdateButtonState(); 175 UpdateButtonState();
176 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698