| 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 "remoting/host/continue_window.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
| 8 | 6 |
| 9 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 8 #include "base/logging.h" |
| 11 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 12 #include "remoting/host/ui_strings.h" | 10 #include "remoting/host/continue_window.h" |
| 13 #include "ui/base/gtk/gtk_signal.h" | 11 #include "ui/base/gtk/gtk_signal.h" |
| 14 | 12 |
| 15 namespace remoting { | 13 namespace remoting { |
| 16 | 14 |
| 17 class ContinueWindowGtk : public remoting::ContinueWindow { | 15 class ContinueWindowGtk : public ContinueWindow { |
| 18 public: | 16 public: |
| 19 explicit ContinueWindowGtk(const UiStrings* ui_strings); | 17 explicit ContinueWindowGtk(const UiStrings& ui_strings); |
| 20 virtual ~ContinueWindowGtk(); | 18 virtual ~ContinueWindowGtk(); |
| 21 | 19 |
| 22 virtual void Show(const ContinueSessionCallback& callback) OVERRIDE; | 20 protected: |
| 23 virtual void Hide() OVERRIDE; | 21 // ContinueWindow overrides. |
| 22 virtual void ShowUi() OVERRIDE; |
| 23 virtual void HideUi() OVERRIDE; |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 void CreateWindow(); |
| 27 |
| 26 CHROMEGTK_CALLBACK_1(ContinueWindowGtk, void, OnResponse, int); | 28 CHROMEGTK_CALLBACK_1(ContinueWindowGtk, void, OnResponse, int); |
| 27 | 29 |
| 28 void CreateWindow(); | |
| 29 | |
| 30 ContinueSessionCallback callback_; | |
| 31 GtkWidget* continue_window_; | 30 GtkWidget* continue_window_; |
| 32 | 31 |
| 33 // Points to the localized strings. | |
| 34 const UiStrings* ui_strings_; | |
| 35 | |
| 36 DISALLOW_COPY_AND_ASSIGN(ContinueWindowGtk); | 32 DISALLOW_COPY_AND_ASSIGN(ContinueWindowGtk); |
| 37 }; | 33 }; |
| 38 | 34 |
| 39 ContinueWindowGtk::ContinueWindowGtk(const UiStrings* ui_strings) | 35 ContinueWindowGtk::ContinueWindowGtk(const UiStrings& ui_strings) |
| 40 : continue_window_(NULL), | 36 : ContinueWindow(ui_strings), |
| 41 ui_strings_(ui_strings) { | 37 continue_window_(NULL) { |
| 42 } | 38 } |
| 43 | 39 |
| 44 ContinueWindowGtk::~ContinueWindowGtk() { | 40 ContinueWindowGtk::~ContinueWindowGtk() { |
| 41 if (continue_window_) { |
| 42 gtk_widget_destroy(continue_window_); |
| 43 continue_window_ = NULL; |
| 44 } |
| 45 } |
| 46 |
| 47 void ContinueWindowGtk::ShowUi() { |
| 48 DCHECK(CalledOnValidThread()); |
| 49 DCHECK(!continue_window_); |
| 50 |
| 51 CreateWindow(); |
| 52 gtk_window_set_urgency_hint(GTK_WINDOW(continue_window_), TRUE); |
| 53 gtk_window_present(GTK_WINDOW(continue_window_)); |
| 54 } |
| 55 |
| 56 void ContinueWindowGtk::HideUi() { |
| 57 DCHECK(CalledOnValidThread()); |
| 58 |
| 59 if (continue_window_) { |
| 60 gtk_widget_destroy(continue_window_); |
| 61 continue_window_ = NULL; |
| 62 } |
| 45 } | 63 } |
| 46 | 64 |
| 47 void ContinueWindowGtk::CreateWindow() { | 65 void ContinueWindowGtk::CreateWindow() { |
| 48 if (continue_window_) | 66 DCHECK(CalledOnValidThread()); |
| 49 return; | 67 DCHECK(!continue_window_); |
| 50 | 68 |
| 51 continue_window_ = gtk_dialog_new_with_buttons( | 69 continue_window_ = gtk_dialog_new_with_buttons( |
| 52 UTF16ToUTF8(ui_strings_->product_name).c_str(), | 70 UTF16ToUTF8(ui_strings().product_name).c_str(), |
| 53 NULL, | 71 NULL, |
| 54 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | 72 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), |
| 55 UTF16ToUTF8(ui_strings_->stop_sharing_button_text).c_str(), | 73 UTF16ToUTF8(ui_strings().stop_sharing_button_text).c_str(), |
| 56 GTK_RESPONSE_CANCEL, | 74 GTK_RESPONSE_CANCEL, |
| 57 UTF16ToUTF8(ui_strings_->continue_button_text).c_str(), | 75 UTF16ToUTF8(ui_strings().continue_button_text).c_str(), |
| 58 GTK_RESPONSE_OK, | 76 GTK_RESPONSE_OK, |
| 59 NULL); | 77 NULL); |
| 60 | 78 |
| 61 gtk_dialog_set_default_response(GTK_DIALOG(continue_window_), | 79 gtk_dialog_set_default_response(GTK_DIALOG(continue_window_), |
| 62 GTK_RESPONSE_OK); | 80 GTK_RESPONSE_OK); |
| 63 gtk_window_set_resizable(GTK_WINDOW(continue_window_), FALSE); | 81 gtk_window_set_resizable(GTK_WINDOW(continue_window_), FALSE); |
| 64 | 82 |
| 65 // Set always-on-top, otherwise this window tends to be obscured by the | 83 // Set always-on-top, otherwise this window tends to be obscured by the |
| 66 // DisconnectWindow. | 84 // DisconnectWindow. |
| 67 gtk_window_set_keep_above(GTK_WINDOW(continue_window_), TRUE); | 85 gtk_window_set_keep_above(GTK_WINDOW(continue_window_), TRUE); |
| 68 | 86 |
| 69 g_signal_connect(continue_window_, "response", | 87 g_signal_connect(continue_window_, "response", |
| 70 G_CALLBACK(OnResponseThunk), this); | 88 G_CALLBACK(OnResponseThunk), this); |
| 71 | 89 |
| 72 GtkWidget* content_area = | 90 GtkWidget* content_area = |
| 73 gtk_dialog_get_content_area(GTK_DIALOG(continue_window_)); | 91 gtk_dialog_get_content_area(GTK_DIALOG(continue_window_)); |
| 74 | 92 |
| 75 GtkWidget* text_label = | 93 GtkWidget* text_label = |
| 76 gtk_label_new(UTF16ToUTF8(ui_strings_->continue_prompt).c_str()); | 94 gtk_label_new(UTF16ToUTF8(ui_strings().continue_prompt).c_str()); |
| 77 gtk_label_set_line_wrap(GTK_LABEL(text_label), TRUE); | 95 gtk_label_set_line_wrap(GTK_LABEL(text_label), TRUE); |
| 78 // TODO(lambroslambrou): Fix magic numbers, as in disconnect_window_gtk.cc. | 96 // TODO(lambroslambrou): Fix magic numbers, as in disconnect_window_gtk.cc. |
| 79 gtk_misc_set_padding(GTK_MISC(text_label), 12, 12); | 97 gtk_misc_set_padding(GTK_MISC(text_label), 12, 12); |
| 80 gtk_container_add(GTK_CONTAINER(content_area), text_label); | 98 gtk_container_add(GTK_CONTAINER(content_area), text_label); |
| 81 | 99 |
| 82 gtk_widget_show_all(content_area); | 100 gtk_widget_show_all(content_area); |
| 83 } | 101 } |
| 84 | 102 |
| 85 void ContinueWindowGtk::Show(const ContinueSessionCallback& callback) { | 103 void ContinueWindowGtk::OnResponse(GtkWidget* dialog, int response_id) { |
| 86 callback_ = callback; | 104 DCHECK(CalledOnValidThread()); |
| 87 CreateWindow(); | 105 |
| 88 gtk_window_set_urgency_hint(GTK_WINDOW(continue_window_), TRUE); | 106 if (response_id == GTK_RESPONSE_OK) { |
| 89 gtk_window_present(GTK_WINDOW(continue_window_)); | 107 ContinueSession(); |
| 108 } else { |
| 109 DisconnectSession(); |
| 110 } |
| 111 |
| 112 HideUi(); |
| 90 } | 113 } |
| 91 | 114 |
| 92 void ContinueWindowGtk::Hide() { | 115 // static |
| 93 if (continue_window_) { | 116 scoped_ptr<HostWindow> HostWindow::CreateContinueWindow( |
| 94 gtk_widget_destroy(continue_window_); | 117 const UiStrings& ui_strings) { |
| 95 continue_window_ = NULL; | 118 return scoped_ptr<HostWindow>(new ContinueWindowGtk(ui_strings)); |
| 96 } | |
| 97 } | |
| 98 | |
| 99 void ContinueWindowGtk::OnResponse(GtkWidget* dialog, int response_id) { | |
| 100 callback_.Run(response_id == GTK_RESPONSE_OK); | |
| 101 Hide(); | |
| 102 } | |
| 103 | |
| 104 scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { | |
| 105 return scoped_ptr<ContinueWindow>(new ContinueWindowGtk(ui_strings)); | |
| 106 } | 119 } |
| 107 | 120 |
| 108 } // namespace remoting | 121 } // namespace remoting |
| OLD | NEW |