| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/extensions/media_galleries_dialog_gtk.h" | 5 #include "chrome/browser/ui/gtk/extensions/media_galleries_dialog_gtk.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/media_gallery/media_galleries_preferences.h" | 9 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_util.h" | 10 #include "chrome/browser/ui/gtk/gtk_util.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 GtkWidget* subtext = | 45 GtkWidget* subtext = |
| 46 gtk_label_new(UTF16ToUTF8(controller_->GetSubtext()).c_str()); | 46 gtk_label_new(UTF16ToUTF8(controller_->GetSubtext()).c_str()); |
| 47 gtk_label_set_line_wrap(GTK_LABEL(subtext), TRUE); | 47 gtk_label_set_line_wrap(GTK_LABEL(subtext), TRUE); |
| 48 gtk_widget_set_size_request(subtext, 500, -1); | 48 gtk_widget_set_size_request(subtext, 500, -1); |
| 49 gtk_box_pack_start(GTK_BOX(contents_.get()), subtext, FALSE, FALSE, 0); | 49 gtk_box_pack_start(GTK_BOX(contents_.get()), subtext, FALSE, FALSE, 0); |
| 50 | 50 |
| 51 checkbox_container_ = gtk_vbox_new(FALSE, 0); | 51 checkbox_container_ = gtk_vbox_new(FALSE, 0); |
| 52 gtk_box_pack_start(GTK_BOX(contents_.get()), checkbox_container_, | 52 gtk_box_pack_start(GTK_BOX(contents_.get()), checkbox_container_, |
| 53 FALSE, FALSE, 0); | 53 FALSE, FALSE, 0); |
| 54 | 54 |
| 55 // As a safeguard against the user skipping reading over the dialog and just | |
| 56 // confirming, the button will be unavailable for dialogs without any checks | |
| 57 // until the user toggles something. | |
| 58 bool confirm_available = false; | |
| 59 const GalleryPermissions& permissions = controller_->permissions(); | 55 const GalleryPermissions& permissions = controller_->permissions(); |
| 60 for (GalleryPermissions::const_iterator iter = permissions.begin(); | 56 for (GalleryPermissions::const_iterator iter = permissions.begin(); |
| 61 iter != permissions.end(); iter++) { | 57 iter != permissions.end(); iter++) { |
| 62 confirm_available = confirm_available || iter->second.allowed; | |
| 63 UpdateGallery(&iter->second.pref_info, iter->second.allowed); | 58 UpdateGallery(&iter->second.pref_info, iter->second.allowed); |
| 64 } | 59 } |
| 65 | 60 |
| 66 // Holds the "add gallery" and cancel/confirm buttons. | 61 // Holds the "add gallery" and cancel/confirm buttons. |
| 67 GtkWidget* bottom_area = gtk_hbox_new(FALSE, ui::kControlSpacing); | 62 GtkWidget* bottom_area = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 68 gtk_box_pack_start(GTK_BOX(contents_.get()), bottom_area, FALSE, FALSE, 0); | 63 gtk_box_pack_start(GTK_BOX(contents_.get()), bottom_area, FALSE, FALSE, 0); |
| 69 | 64 |
| 70 // Add gallery button. | 65 // Add gallery button. |
| 71 GtkWidget* add_folder = gtk_button_new_with_label( | 66 GtkWidget* add_folder = gtk_button_new_with_label( |
| 72 l10n_util::GetStringUTF8(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY).c_str()); | 67 l10n_util::GetStringUTF8(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY).c_str()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 83 gtk_box_pack_end(GTK_BOX(bottom_area), confirm_, FALSE, FALSE, 0); | 78 gtk_box_pack_end(GTK_BOX(bottom_area), confirm_, FALSE, FALSE, 0); |
| 84 | 79 |
| 85 GtkWidget* cancel = gtk_button_new_with_label(l10n_util::GetStringUTF8( | 80 GtkWidget* cancel = gtk_button_new_with_label(l10n_util::GetStringUTF8( |
| 86 IDS_MEDIA_GALLERIES_DIALOG_CANCEL).c_str()); | 81 IDS_MEDIA_GALLERIES_DIALOG_CANCEL).c_str()); |
| 87 gtk_button_set_image( | 82 gtk_button_set_image( |
| 88 GTK_BUTTON(cancel), | 83 GTK_BUTTON(cancel), |
| 89 gtk_image_new_from_stock(GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); | 84 gtk_image_new_from_stock(GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); |
| 90 g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelThunk), this); | 85 g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelThunk), this); |
| 91 gtk_box_pack_end(GTK_BOX(bottom_area), cancel, FALSE, FALSE, 0); | 86 gtk_box_pack_end(GTK_BOX(bottom_area), cancel, FALSE, FALSE, 0); |
| 92 | 87 |
| 93 gtk_widget_set_sensitive(confirm_, confirm_available); | 88 // As a safeguard against the user skipping reading over the dialog and just |
| 89 // confirming, the button will be unavailable for dialogs without any checks |
| 90 // until the user toggles something. |
| 91 gtk_widget_set_sensitive(confirm_, controller_->HasPermittedGalleries()); |
| 94 } | 92 } |
| 95 | 93 |
| 96 void MediaGalleriesDialogGtk::UpdateGallery( | 94 void MediaGalleriesDialogGtk::UpdateGallery( |
| 97 const MediaGalleryPrefInfo* gallery, | 95 const MediaGalleryPrefInfo* gallery, |
| 98 bool permitted) { | 96 bool permitted) { |
| 99 CheckboxMap::iterator iter = checkbox_map_.find(gallery); | 97 CheckboxMap::iterator iter = checkbox_map_.find(gallery); |
| 100 | 98 |
| 101 GtkWidget* widget = NULL; | 99 GtkWidget* widget = NULL; |
| 102 if (iter != checkbox_map_.end()) { | 100 if (iter != checkbox_map_.end()) { |
| 103 widget = iter->second; | 101 widget = iter->second; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 129 void MediaGalleriesDialogGtk::OnToggled(GtkWidget* widget) { | 127 void MediaGalleriesDialogGtk::OnToggled(GtkWidget* widget) { |
| 130 if (confirm_) | 128 if (confirm_) |
| 131 gtk_widget_set_sensitive(confirm_, TRUE); | 129 gtk_widget_set_sensitive(confirm_, TRUE); |
| 132 | 130 |
| 133 if (ignore_toggles_) | 131 if (ignore_toggles_) |
| 134 return; | 132 return; |
| 135 | 133 |
| 136 for (CheckboxMap::iterator iter = checkbox_map_.begin(); | 134 for (CheckboxMap::iterator iter = checkbox_map_.begin(); |
| 137 iter != checkbox_map_.end(); ++iter) { | 135 iter != checkbox_map_.end(); ++iter) { |
| 138 if (iter->second == widget) { | 136 if (iter->second == widget) { |
| 139 controller_->GalleryToggled( | 137 controller_->DidToggleGallery( |
| 140 iter->first, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); | 138 iter->first, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); |
| 141 return; | 139 return; |
| 142 } | 140 } |
| 143 } | 141 } |
| 144 | 142 |
| 145 NOTREACHED(); | 143 NOTREACHED(); |
| 146 return; | 144 return; |
| 147 } | 145 } |
| 148 | 146 |
| 149 void MediaGalleriesDialogGtk::OnAddFolder(GtkWidget* widget) { | 147 void MediaGalleriesDialogGtk::OnAddFolder(GtkWidget* widget) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 161 | 159 |
| 162 // MediaGalleriesDialogController ---------------------------------------------- | 160 // MediaGalleriesDialogController ---------------------------------------------- |
| 163 | 161 |
| 164 // static | 162 // static |
| 165 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 163 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
| 166 MediaGalleriesDialogController* controller) { | 164 MediaGalleriesDialogController* controller) { |
| 167 return new MediaGalleriesDialogGtk(controller); | 165 return new MediaGalleriesDialogGtk(controller); |
| 168 } | 166 } |
| 169 | 167 |
| 170 } // namespace chrome | 168 } // namespace chrome |
| OLD | NEW |