summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/import_dialog_gtk.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-26 23:50:32 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-26 23:50:32 +0000
commit5225e060ae6a708d9bec85c895cb6531083ceb6a (patch)
tree2d60c9ce990019941d10aa88aa23d16645ba52bb /chrome/browser/gtk/import_dialog_gtk.cc
parentaa10ce4e8fce2660f8fe9e3b6360e32ba6623375 (diff)
downloadchromium_src-5225e060ae6a708d9bec85c895cb6531083ceb6a.zip
chromium_src-5225e060ae6a708d9bec85c895cb6531083ceb6a.tar.gz
chromium_src-5225e060ae6a708d9bec85c895cb6531083ceb6a.tar.bz2
gtk: Disable the "Import" button on Import Bookmarks dialog if there is no checkbox checked.
BUG=30401 TEST=open Import Bookmarks dialog, uncheck all checkboxes, see if the "Import" button is disabled. Patch from Thiago Farina <thiago.farina@gmail.com> Review URL: http://codereview.chromium.org/1604025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45641 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/import_dialog_gtk.cc')
-rw-r--r--chrome/browser/gtk/import_dialog_gtk.cc55
1 files changed, 44 insertions, 11 deletions
diff --git a/chrome/browser/gtk/import_dialog_gtk.cc b/chrome/browser/gtk/import_dialog_gtk.cc
index c4c3804..7017c6c 100644
--- a/chrome/browser/gtk/import_dialog_gtk.cc
+++ b/chrome/browser/gtk/import_dialog_gtk.cc
@@ -15,6 +15,15 @@
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
+namespace {
+
+// Returns true if the checkbox is checked.
+gboolean IsChecked(GtkWidget* widget) {
+ return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+}
+
+} // namespace
+
// static
void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile,
int initial_state) {
@@ -93,24 +102,32 @@ ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile,
gtk_box_pack_start(GTK_BOX(vbox), bookmarks_, FALSE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bookmarks_),
(initial_state_ & importer::FAVORITES) != 0);
+ g_signal_connect(bookmarks_, "toggled",
+ G_CALLBACK(OnDialogWidgetClickedThunk), this);
search_engines_ = gtk_check_button_new_with_label(
l10n_util::GetStringUTF8(IDS_IMPORT_SEARCH_ENGINES_CHKBOX).c_str());
gtk_box_pack_start(GTK_BOX(vbox), search_engines_, FALSE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(search_engines_),
(initial_state_ & importer::SEARCH_ENGINES) != 0);
+ g_signal_connect(search_engines_, "toggled",
+ G_CALLBACK(OnDialogWidgetClickedThunk), this);
passwords_ = gtk_check_button_new_with_label(
l10n_util::GetStringUTF8(IDS_IMPORT_PASSWORDS_CHKBOX).c_str());
gtk_box_pack_start(GTK_BOX(vbox), passwords_, FALSE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(passwords_),
(initial_state_ & importer::PASSWORDS) != 0);
+ g_signal_connect(passwords_, "toggled",
+ G_CALLBACK(OnDialogWidgetClickedThunk), this);
history_ = gtk_check_button_new_with_label(
l10n_util::GetStringUTF8(IDS_IMPORT_HISTORY_CHKBOX).c_str());
gtk_box_pack_start(GTK_BOX(vbox), history_, FALSE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(history_),
(initial_state_ & importer::HISTORY) !=0);
+ g_signal_connect(history_, "toggled",
+ G_CALLBACK(OnDialogWidgetClickedThunk), this);
gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0);
@@ -136,7 +153,10 @@ ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile,
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), 0);
g_signal_connect(dialog_, "response",
- G_CALLBACK(HandleOnResponseDialog), this);
+ G_CALLBACK(OnDialogResponseThunk), this);
+
+ UpdateDialogButtons();
+
gtk_widget_show_all(dialog_);
}
@@ -146,16 +166,7 @@ ImportDialogGtk::~ImportDialogGtk() {
void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) {
gtk_widget_hide_all(dialog_);
if (response == GTK_RESPONSE_ACCEPT) {
- uint16 items = importer::NONE;
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bookmarks_)))
- items |= importer::FAVORITES;
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_engines_)))
- items |= importer::SEARCH_ENGINES;
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(passwords_)))
- items |= importer::PASSWORDS;
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(history_)))
- items |= importer::HISTORY;
-
+ uint16 items = GetCheckedItems();
if (items == 0) {
ImportComplete();
} else {
@@ -169,3 +180,25 @@ void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) {
ImportCanceled();
}
}
+
+void ImportDialogGtk::OnDialogWidgetClicked(GtkWidget* widget) {
+ UpdateDialogButtons();
+}
+
+void ImportDialogGtk::UpdateDialogButtons() {
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT,
+ GetCheckedItems() != 0);
+}
+
+uint16 ImportDialogGtk::GetCheckedItems() {
+ uint16 items = importer::NONE;
+ if (IsChecked(bookmarks_))
+ items |= importer::FAVORITES;
+ if (IsChecked(search_engines_))
+ items |= importer::SEARCH_ENGINES;
+ if (IsChecked(passwords_))
+ items |= importer::PASSWORDS;
+ if (IsChecked(history_))
+ items |= importer::HISTORY;
+ return items;
+}