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/chrome_to_mobile_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/chrome_to_mobile_bubble_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 147 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
148 browser_(browser), | 148 browser_(browser), |
149 service_(ChromeToMobileServiceFactory::GetForProfile(browser->profile())), | 149 service_(ChromeToMobileServiceFactory::GetForProfile(browser->profile())), |
150 theme_service_(GtkThemeService::GetFrom(browser->profile())), | 150 theme_service_(GtkThemeService::GetFrom(browser->profile())), |
151 anchor_image_(anchor_image), | 151 anchor_image_(anchor_image), |
152 send_copy_(NULL), | 152 send_copy_(NULL), |
153 cancel_(NULL), | 153 cancel_(NULL), |
154 send_(NULL), | 154 send_(NULL), |
155 error_(NULL), | 155 error_(NULL), |
156 bubble_(NULL) { | 156 bubble_(NULL) { |
| 157 DCHECK(service_->HasMobiles()); |
157 service_->LogMetric(ChromeToMobileService::BUBBLE_SHOWN); | 158 service_->LogMetric(ChromeToMobileService::BUBBLE_SHOWN); |
158 | 159 |
159 // Generate the MHTML snapshot now to report its size in the bubble. | 160 // Generate the MHTML snapshot now to report its size in the bubble. |
160 service_->GenerateSnapshot(browser_, weak_ptr_factory_.GetWeakPtr()); | 161 service_->GenerateSnapshot(browser_, weak_ptr_factory_.GetWeakPtr()); |
161 | 162 |
162 // Request a mobile device list update. | 163 // Request a mobile device list update. |
163 service_->RequestMobileListUpdate(); | 164 service_->RequestMobileListUpdate(); |
164 | 165 |
165 // Get the list of mobile devices. | 166 const ListValue* mobiles = service_->GetMobiles(); |
166 const ListValue& mobiles = service_->mobiles(); | |
167 DCHECK(!mobiles.empty()); | |
168 | 167 |
169 GtkWidget* content = gtk_vbox_new(FALSE, 5); | 168 GtkWidget* content = gtk_vbox_new(FALSE, 5); |
170 gtk_container_set_border_width(GTK_CONTAINER(content), kContentBorder); | 169 gtk_container_set_border_width(GTK_CONTAINER(content), kContentBorder); |
171 | 170 |
172 // Create and pack the title label; init the selected mobile device. | 171 // Create and pack the title label; init the selected mobile device. |
173 GtkWidget* title = NULL; | 172 GtkWidget* title = NULL; |
174 if (mobiles.GetSize() == 1) { | 173 if (mobiles->GetSize() == 1) { |
175 string16 name; | 174 string16 name; |
176 DictionaryValue* mobile = NULL; | 175 DictionaryValue* mobile = NULL; |
177 if (mobiles.GetDictionary(0, &mobile) && mobile->GetString("name", &name)) { | 176 if (mobiles->GetDictionary(0, &mobile) && |
| 177 mobile->GetString("name", &name)) { |
178 title = gtk_label_new(l10n_util::GetStringFUTF8( | 178 title = gtk_label_new(l10n_util::GetStringFUTF8( |
179 IDS_CHROME_TO_MOBILE_BUBBLE_SINGLE_TITLE, name).c_str()); | 179 IDS_CHROME_TO_MOBILE_BUBBLE_SINGLE_TITLE, name).c_str()); |
180 } else { | 180 } else { |
181 NOTREACHED(); | 181 NOTREACHED(); |
182 } | 182 } |
183 } else { | 183 } else { |
184 title = gtk_label_new(l10n_util::GetStringUTF8( | 184 title = gtk_label_new(l10n_util::GetStringUTF8( |
185 IDS_CHROME_TO_MOBILE_BUBBLE_MULTI_TITLE).c_str()); | 185 IDS_CHROME_TO_MOBILE_BUBBLE_MULTI_TITLE).c_str()); |
186 } | 186 } |
187 gtk_misc_set_alignment(GTK_MISC(title), 0, 1); | 187 gtk_misc_set_alignment(GTK_MISC(title), 0, 1); |
188 gtk_box_pack_start(GTK_BOX(content), title, FALSE, FALSE, 0); | 188 gtk_box_pack_start(GTK_BOX(content), title, FALSE, FALSE, 0); |
189 labels_.push_back(title); | 189 labels_.push_back(title); |
190 | 190 |
191 // Create and pack the device radio group; init the selected mobile device. | 191 // Create and pack the device radio group; init the selected mobile device. |
192 if (mobiles.GetSize() > 1) { | 192 if (mobiles->GetSize() > 1) { |
193 std::string name; | 193 std::string name; |
194 DictionaryValue* mobile = NULL; | 194 DictionaryValue* mobile = NULL; |
195 GtkWidget* radio = NULL; | 195 GtkWidget* radio = NULL; |
196 GtkWidget* row = NULL; | 196 GtkWidget* row = NULL; |
197 for (size_t index = 0; index < mobiles.GetSize(); ++index) { | 197 for (size_t index = 0; index < mobiles->GetSize(); ++index) { |
198 if (mobiles.GetDictionary(index, &mobile) && | 198 if (mobiles->GetDictionary(index, &mobile) && |
199 mobile->GetStringASCII("name", &name)) { | 199 mobile->GetStringASCII("name", &name)) { |
200 radio = gtk_radio_button_new_with_label_from_widget( | 200 radio = gtk_radio_button_new_with_label_from_widget( |
201 GTK_RADIO_BUTTON(radio), name.c_str()); | 201 GTK_RADIO_BUTTON(radio), name.c_str()); |
202 radio_buttons_.push_back(radio); | 202 radio_buttons_.push_back(radio); |
203 } else { | 203 } else { |
204 NOTREACHED(); | 204 NOTREACHED(); |
205 } | 205 } |
206 | 206 |
207 // Pack each radio item into a horizontal box padding. | 207 // Pack each radio item into a horizontal box padding. |
208 row = gtk_hbox_new(FALSE, 0); | 208 row = gtk_hbox_new(FALSE, 0); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 service_->LearnMore(browser_); | 300 service_->LearnMore(browser_); |
301 bubble_->Close(); | 301 bubble_->Close(); |
302 } | 302 } |
303 | 303 |
304 void ChromeToMobileBubbleGtk::OnCancelClicked(GtkWidget* widget) { | 304 void ChromeToMobileBubbleGtk::OnCancelClicked(GtkWidget* widget) { |
305 bubble_->Close(); | 305 bubble_->Close(); |
306 } | 306 } |
307 | 307 |
308 void ChromeToMobileBubbleGtk::OnSendClicked(GtkWidget* widget) { | 308 void ChromeToMobileBubbleGtk::OnSendClicked(GtkWidget* widget) { |
309 // TODO(msw): Handle updates to the mobile list while the bubble is open. | 309 // TODO(msw): Handle updates to the mobile list while the bubble is open. |
310 const ListValue& mobiles = service_->mobiles(); | 310 const ListValue* mobiles = service_->GetMobiles(); |
311 size_t selected_index = 0; | 311 size_t selected_index = 0; |
312 if (mobiles.GetSize() > 1) { | 312 if (mobiles->GetSize() > 1) { |
313 DCHECK_EQ(mobiles.GetSize(), radio_buttons_.size()); | 313 DCHECK_EQ(mobiles->GetSize(), radio_buttons_.size()); |
314 GtkToggleButton* button = NULL; | 314 GtkToggleButton* button = NULL; |
315 for (; selected_index < radio_buttons_.size(); ++selected_index) { | 315 for (; selected_index < radio_buttons_.size(); ++selected_index) { |
316 button = GTK_TOGGLE_BUTTON(radio_buttons_[selected_index]); | 316 button = GTK_TOGGLE_BUTTON(radio_buttons_[selected_index]); |
317 if (gtk_toggle_button_get_active(button)) | 317 if (gtk_toggle_button_get_active(button)) |
318 break; | 318 break; |
319 } | 319 } |
320 } else { | 320 } else { |
321 DCHECK(radio_buttons_.empty()); | 321 DCHECK(radio_buttons_.empty()); |
322 } | 322 } |
323 | 323 |
324 DictionaryValue* mobile = NULL; | 324 DictionaryValue* mobile = NULL; |
325 if (mobiles.GetDictionary(selected_index, &mobile)) { | 325 if (mobiles->GetDictionary(selected_index, &mobile)) { |
326 bool snapshot = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(send_copy_)); | 326 bool snapshot = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(send_copy_)); |
327 service_->SendToMobile(*mobile, snapshot ? snapshot_path_ : FilePath(), | 327 service_->SendToMobile(*mobile, snapshot ? snapshot_path_ : FilePath(), |
328 browser_, weak_ptr_factory_.GetWeakPtr()); | 328 browser_, weak_ptr_factory_.GetWeakPtr()); |
329 } else { | 329 } else { |
330 NOTREACHED(); | 330 NOTREACHED(); |
331 } | 331 } |
332 | 332 |
333 // Update the view's contents to show the "Sending..." progress animation. | 333 // Update the view's contents to show the "Sending..." progress animation. |
334 gtk_widget_set_sensitive(cancel_, FALSE); | 334 gtk_widget_set_sensitive(cancel_, FALSE); |
335 gtk_widget_set_sensitive(send_, FALSE); | 335 gtk_widget_set_sensitive(send_, FALSE); |
336 gtk_button_set_alignment(GTK_BUTTON(send_), 0, 0.5); | 336 gtk_button_set_alignment(GTK_BUTTON(send_), 0, 0.5); |
337 progress_animation_.reset(new ui::ThrobAnimation(this)); | 337 progress_animation_.reset(new ui::ThrobAnimation(this)); |
338 progress_animation_->SetDuration(kProgressThrobDurationMS); | 338 progress_animation_->SetDuration(kProgressThrobDurationMS); |
339 progress_animation_->StartThrobbing(-1); | 339 progress_animation_->StartThrobbing(-1); |
340 } | 340 } |
OLD | NEW |