| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/disconnect_window.h" | 5 #include "remoting/host/disconnect_window.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" |
| 11 #include "remoting/host/chromoting_host.h" | 13 #include "remoting/host/chromoting_host.h" |
| 12 #include "remoting/host/ui_strings.h" | 14 #include "remoting/host/ui_strings.h" |
| 13 #include "ui/base/gtk/gtk_signal.h" | 15 #include "ui/base/gtk/gtk_signal.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 // The width in pixels at which the message will wrap. Given that the message | 18 // The width in pixels at which the message will wrap. Given that the message |
| 17 // contains an un-splittable email address, it's unlikely that a fixed width | 19 // contains an un-splittable email address, it's unlikely that a fixed width |
| 18 // is going to look aesthetically pleasing in all languages. | 20 // is going to look aesthetically pleasing in all languages. |
| 19 // TODO(jamiewalch): Replace this with a layout that only uses a single line, | 21 // TODO(jamiewalch): Replace this with a layout that only uses a single line, |
| 20 // and which is docked at the top or bottom of the host screen, as in our | 22 // and which is docked at the top or bottom of the host screen, as in our |
| 21 // UI mocks. | 23 // UI mocks. |
| 22 const int kMessageWidth = 300; | 24 const int kMessageWidth = 300; |
| 23 } | 25 } |
| 24 | 26 |
| 25 namespace remoting { | 27 namespace remoting { |
| 26 | 28 |
| 27 class DisconnectWindowLinux : public DisconnectWindow { | 29 class DisconnectWindowLinux : public DisconnectWindow { |
| 28 public: | 30 public: |
| 29 DisconnectWindowLinux(); | 31 DisconnectWindowLinux(); |
| 30 virtual ~DisconnectWindowLinux(); | 32 virtual ~DisconnectWindowLinux(); |
| 31 | 33 |
| 32 virtual void Show(ChromotingHost* host, | 34 virtual void Show(ChromotingHost* host, |
| 33 const std::string& username) OVERRIDE; | 35 const std::string& username) OVERRIDE; |
| 34 virtual void Hide() OVERRIDE; | 36 virtual void Hide() OVERRIDE; |
| 35 | 37 |
| 36 private: | 38 private: |
| 37 CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, void, OnResponse, int); | 39 CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, void, OnResponse, int); |
| 38 | 40 |
| 39 void CreateWindow(UiStrings* ui_strings); | 41 void CreateWindow(const UiStrings& ui_strings); |
| 40 | 42 |
| 41 ChromotingHost* host_; | 43 ChromotingHost* host_; |
| 42 GtkWidget* disconnect_window_; | 44 GtkWidget* disconnect_window_; |
| 43 GtkWidget* message_; | 45 GtkWidget* message_; |
| 44 | 46 |
| 45 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowLinux); | 47 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowLinux); |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 DisconnectWindowLinux::DisconnectWindowLinux() | 50 DisconnectWindowLinux::DisconnectWindowLinux() |
| 49 : host_(NULL), | 51 : host_(NULL), |
| 50 disconnect_window_(NULL) { | 52 disconnect_window_(NULL) { |
| 51 } | 53 } |
| 52 | 54 |
| 53 DisconnectWindowLinux::~DisconnectWindowLinux() { | 55 DisconnectWindowLinux::~DisconnectWindowLinux() { |
| 54 } | 56 } |
| 55 | 57 |
| 56 void DisconnectWindowLinux::CreateWindow(UiStrings* ui_strings) { | 58 void DisconnectWindowLinux::CreateWindow(const UiStrings& ui_strings) { |
| 57 if (disconnect_window_) return; | 59 if (disconnect_window_) return; |
| 58 | 60 |
| 59 disconnect_window_ = gtk_dialog_new_with_buttons( | 61 disconnect_window_ = gtk_dialog_new_with_buttons( |
| 60 ui_strings->product_name.c_str(), | 62 UTF16ToUTF8(ui_strings.product_name).c_str(), |
| 61 NULL, | 63 NULL, |
| 62 GTK_DIALOG_NO_SEPARATOR, | 64 GTK_DIALOG_NO_SEPARATOR, |
| 63 ui_strings->disconnect_button_text_plus_shortcut.c_str(), GTK_RESPONSE_OK, | 65 UTF16ToUTF8(ui_strings.disconnect_button_text_plus_shortcut).c_str(), |
| 66 GTK_RESPONSE_OK, |
| 64 NULL); | 67 NULL); |
| 65 | 68 |
| 66 GtkWindow* window = GTK_WINDOW(disconnect_window_); | 69 GtkWindow* window = GTK_WINDOW(disconnect_window_); |
| 67 gtk_window_set_resizable(window, FALSE); | 70 gtk_window_set_resizable(window, FALSE); |
| 68 // Try to keep the window always visible. | 71 // Try to keep the window always visible. |
| 69 gtk_window_stick(window); | 72 gtk_window_stick(window); |
| 70 gtk_window_set_keep_above(window, TRUE); | 73 gtk_window_set_keep_above(window, TRUE); |
| 71 // Utility windows have no minimize button or taskbar presence. | 74 // Utility windows have no minimize button or taskbar presence. |
| 72 gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_UTILITY); | 75 gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_UTILITY); |
| 73 gtk_window_set_deletable(window, FALSE); | 76 gtk_window_set_deletable(window, FALSE); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 87 | 90 |
| 88 message_ = gtk_label_new(NULL); | 91 message_ = gtk_label_new(NULL); |
| 89 gtk_widget_set_size_request(message_, kMessageWidth, -1); | 92 gtk_widget_set_size_request(message_, kMessageWidth, -1); |
| 90 gtk_label_set_line_wrap(GTK_LABEL(message_), true); | 93 gtk_label_set_line_wrap(GTK_LABEL(message_), true); |
| 91 gtk_container_add(GTK_CONTAINER(message_row), message_); | 94 gtk_container_add(GTK_CONTAINER(message_row), message_); |
| 92 | 95 |
| 93 gtk_widget_show_all(content_area); | 96 gtk_widget_show_all(content_area); |
| 94 } | 97 } |
| 95 | 98 |
| 96 void DisconnectWindowLinux::Show(ChromotingHost* host, | 99 void DisconnectWindowLinux::Show(ChromotingHost* host, |
| 97 const std::string& /* unused */) { | 100 const std::string& username) { |
| 98 host_ = host; | 101 host_ = host; |
| 99 CreateWindow(host->ui_strings()); | 102 CreateWindow(host->ui_strings()); |
| 100 gtk_label_set_text(GTK_LABEL(message_), | 103 |
| 101 host->ui_strings()->disconnect_message.c_str()); | 104 string16 text = ReplaceStringPlaceholders( |
| 105 host->ui_strings().disconnect_message, UTF8ToUTF16(username), NULL); |
| 106 gtk_label_set_text(GTK_LABEL(message_), UTF16ToUTF8(text).c_str()); |
| 102 gtk_window_present(GTK_WINDOW(disconnect_window_)); | 107 gtk_window_present(GTK_WINDOW(disconnect_window_)); |
| 103 } | 108 } |
| 104 | 109 |
| 105 void DisconnectWindowLinux::Hide() { | 110 void DisconnectWindowLinux::Hide() { |
| 106 if (disconnect_window_) { | 111 if (disconnect_window_) { |
| 107 gtk_widget_destroy(disconnect_window_); | 112 gtk_widget_destroy(disconnect_window_); |
| 108 disconnect_window_ = NULL; | 113 disconnect_window_ = NULL; |
| 109 } | 114 } |
| 110 } | 115 } |
| 111 | 116 |
| 112 void DisconnectWindowLinux::OnResponse(GtkWidget* dialog, int response_id) { | 117 void DisconnectWindowLinux::OnResponse(GtkWidget* dialog, int response_id) { |
| 113 // |response_id| is ignored, because there is only one button, and pressing | 118 // |response_id| is ignored, because there is only one button, and pressing |
| 114 // it should have the same effect as closing the window (if the window Close | 119 // it should have the same effect as closing the window (if the window Close |
| 115 // button were visible). | 120 // button were visible). |
| 116 CHECK(host_); | 121 CHECK(host_); |
| 117 | 122 |
| 118 host_->Shutdown(NULL); | 123 host_->Shutdown(NULL); |
| 119 Hide(); | 124 Hide(); |
| 120 } | 125 } |
| 121 | 126 |
| 122 DisconnectWindow* DisconnectWindow::Create() { | 127 DisconnectWindow* DisconnectWindow::Create() { |
| 123 return new DisconnectWindowLinux; | 128 return new DisconnectWindowLinux; |
| 124 } | 129 } |
| 125 | 130 |
| 126 } // namespace remoting | 131 } // namespace remoting |
| OLD | NEW |