diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-23 23:46:50 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-23 23:46:50 +0000 |
commit | 0cac676933f11f6f8a32c9e8aa1d082da211957e (patch) | |
tree | 0249277e4fd864f9fa4ee112b8872543909f5a5f /chrome/browser/gtk/options | |
parent | a20cf38e9b2cd094bc4ae20da50588cdd2b79933 (diff) | |
download | chromium_src-0cac676933f11f6f8a32c9e8aa1d082da211957e.zip chromium_src-0cac676933f11f6f8a32c9e8aa1d082da211957e.tar.gz chromium_src-0cac676933f11f6f8a32c9e8aa1d082da211957e.tar.bz2 |
linux: Show an icon to the right indicating if the host is valid or not.
BUG=34181
TEST=open the exceptions editor, type some text in the host textfield, see the indication.
Review URL: http://codereview.chromium.org/650122
Patch from thiago.farina@gmail.com.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39802 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/options')
-rw-r--r-- | chrome/browser/gtk/options/content_exception_editor.cc | 52 | ||||
-rw-r--r-- | chrome/browser/gtk/options/content_exception_editor.h | 5 |
2 files changed, 39 insertions, 18 deletions
diff --git a/chrome/browser/gtk/options/content_exception_editor.cc b/chrome/browser/gtk/options/content_exception_editor.cc index 809a31b..882110a 100644 --- a/chrome/browser/gtk/options/content_exception_editor.cc +++ b/chrome/browser/gtk/options/content_exception_editor.cc @@ -5,25 +5,27 @@ #include "chrome/browser/gtk/options/content_exception_editor.h" #include "app/l10n_util.h" +#include "app/resource_bundle.h" #include "base/message_loop.h" #include "chrome/browser/content_exceptions_table_model.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/common/gtk_util.h" #include "googleurl/src/url_canon.h" #include "googleurl/src/url_parse.h" +#include "grit/app_resources.h" #include "grit/generated_resources.h" #include "net/base/net_util.h" namespace { // The settings shown in the combobox if show_ask_ is false; -static const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_BLOCK }; +const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW, + CONTENT_SETTING_BLOCK }; // The settings shown in the combobox if show_ask_ is true; -static const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_ASK, - CONTENT_SETTING_BLOCK }; +const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW, + CONTENT_SETTING_ASK, + CONTENT_SETTING_BLOCK }; // Returns true if the host name is valid. bool ValidHost(const std::string& host) { @@ -34,6 +36,13 @@ bool ValidHost(const std::string& host) { return !net::CanonicalizeHost(host, &host_info).empty(); } +GtkWidget* CreateEntryImageHBox(GtkWidget* entry, GtkWidget* image) { + GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); + gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); + return hbox; +} + } // namespace ContentExceptionEditor::ContentExceptionEditor( @@ -68,6 +77,8 @@ ContentExceptionEditor::ContentExceptionEditor( g_signal_connect(entry_, "changed", G_CALLBACK(OnEntryChanged), this); gtk_entry_set_activates_default(GTK_ENTRY(entry_), TRUE); + host_image_ = gtk_image_new_from_pixbuf(NULL); + action_combo_ = gtk_combo_box_new_text(); for (int i = 0; i < GetItemCount(); ++i) { gtk_combo_box_append_text(GTK_COMBO_BOX(action_combo_), @@ -79,7 +90,7 @@ ContentExceptionEditor::ContentExceptionEditor( GtkWidget* table = gtk_util::CreateLabeledControlsGroup( NULL, l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_HOST_TITLE).c_str(), - entry_, + CreateEntryImageHBox(entry_, host_image_), l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_ACTION_TITLE).c_str(), action_combo_, NULL); @@ -124,23 +135,28 @@ int ContentExceptionEditor::IndexForSetting(ContentSetting setting) { return 0; } +bool ContentExceptionEditor::IsHostValid(const std::string& host) const { + bool is_valid_host = ValidHost(host) && + (model_->IndexOfExceptionByHost(host) == -1); + + return is_new() ? is_valid_host : (!host.empty() && + ((host_ == host) || is_valid_host)); +} + +void ContentExceptionEditor::UpdateImage(GtkWidget* image, bool is_valid) { + return gtk_image_set_from_pixbuf(GTK_IMAGE(image), + ResourceBundle::GetSharedInstance().GetPixbufNamed( + is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); +} + // static void ContentExceptionEditor::OnEntryChanged(GtkEditable* entry, ContentExceptionEditor* window) { - bool can_accept = false; std::string new_host = gtk_entry_get_text(GTK_ENTRY(window->entry_)); - if (window->is_new()) { - can_accept = ValidHost(new_host) && - (window->model_->IndexOfExceptionByHost(new_host) == -1); - } else { - can_accept = !new_host.empty() && - (window->host_ == new_host || - (ValidHost(new_host) && - window->model_->IndexOfExceptionByHost(new_host) == -1)); - } - + bool is_valid = window->IsHostValid(new_host); gtk_dialog_set_response_sensitive(GTK_DIALOG(window->dialog_), - GTK_RESPONSE_OK, can_accept); + GTK_RESPONSE_OK, is_valid); + window->UpdateImage(window->host_image_, is_valid); } // static diff --git a/chrome/browser/gtk/options/content_exception_editor.h b/chrome/browser/gtk/options/content_exception_editor.h index c71e693..a40b4d2 100644 --- a/chrome/browser/gtk/options/content_exception_editor.h +++ b/chrome/browser/gtk/options/content_exception_editor.h @@ -51,6 +51,10 @@ class ContentExceptionEditor { ContentSetting SettingForIndex(int index); int IndexForSetting(ContentSetting setting); + bool IsHostValid(const std::string& host) const; + + void UpdateImage(GtkWidget* image, bool is_valid); + // GTK callbacks static void OnEntryChanged(GtkEditable* entry, ContentExceptionEditor* window); @@ -72,6 +76,7 @@ class ContentExceptionEditor { // UI widgets. GtkWidget* dialog_; GtkWidget* entry_; + GtkWidget* host_image_; GtkWidget* action_combo_; DISALLOW_COPY_AND_ASSIGN(ContentExceptionEditor); |