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 "remoting/host/chromoting_host.h" | 11 #include "remoting/host/chromoting_host.h" |
| 12 #include "remoting/host/ui_strings.h" |
12 #include "ui/base/gtk/gtk_signal.h" | 13 #include "ui/base/gtk/gtk_signal.h" |
13 | 14 |
| 15 namespace { |
| 16 // 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 |
| 18 // is going to look aesthetically pleasing in all languages. |
| 19 // 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 |
| 21 // UI mocks. |
| 22 const int kMessageWidth = 300; |
| 23 } |
| 24 |
14 namespace remoting { | 25 namespace remoting { |
15 | 26 |
16 class DisconnectWindowLinux : public DisconnectWindow { | 27 class DisconnectWindowLinux : public DisconnectWindow { |
17 public: | 28 public: |
18 DisconnectWindowLinux(); | 29 DisconnectWindowLinux(); |
19 virtual ~DisconnectWindowLinux(); | 30 virtual ~DisconnectWindowLinux(); |
20 | 31 |
21 virtual void Show(ChromotingHost* host, | 32 virtual void Show(ChromotingHost* host, |
22 const std::string& username) OVERRIDE; | 33 const std::string& username) OVERRIDE; |
23 virtual void Hide() OVERRIDE; | 34 virtual void Hide() OVERRIDE; |
24 | 35 |
25 private: | 36 private: |
26 CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, void, OnResponse, int); | 37 CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, void, OnResponse, int); |
27 | 38 |
28 void CreateWindow(); | 39 void CreateWindow(UiStrings* ui_strings); |
29 | 40 |
30 ChromotingHost* host_; | 41 ChromotingHost* host_; |
31 GtkWidget* disconnect_window_; | 42 GtkWidget* disconnect_window_; |
32 GtkWidget* user_label_; | 43 GtkWidget* message_; |
33 | 44 |
34 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowLinux); | 45 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowLinux); |
35 }; | 46 }; |
36 | 47 |
37 DisconnectWindowLinux::DisconnectWindowLinux() | 48 DisconnectWindowLinux::DisconnectWindowLinux() |
38 : host_(NULL), | 49 : host_(NULL), |
39 disconnect_window_(NULL) { | 50 disconnect_window_(NULL) { |
40 } | 51 } |
41 | 52 |
42 DisconnectWindowLinux::~DisconnectWindowLinux() { | 53 DisconnectWindowLinux::~DisconnectWindowLinux() { |
43 } | 54 } |
44 | 55 |
45 void DisconnectWindowLinux::CreateWindow() { | 56 void DisconnectWindowLinux::CreateWindow(UiStrings* ui_strings) { |
46 if (disconnect_window_) return; | 57 if (disconnect_window_) return; |
47 | 58 |
48 std::string disconnect_button(kDisconnectButton); | |
49 disconnect_button += kDisconnectKeysLinux; | |
50 disconnect_window_ = gtk_dialog_new_with_buttons( | 59 disconnect_window_ = gtk_dialog_new_with_buttons( |
51 kTitle, | 60 ui_strings->product_name.c_str(), |
52 NULL, | 61 NULL, |
53 GTK_DIALOG_NO_SEPARATOR, | 62 GTK_DIALOG_NO_SEPARATOR, |
54 disconnect_button.c_str(), GTK_RESPONSE_OK, | 63 ui_strings->disconnect_button_text_plus_shortcut.c_str(), GTK_RESPONSE_OK, |
55 NULL); | 64 NULL); |
56 | 65 |
57 GtkWindow* window = GTK_WINDOW(disconnect_window_); | 66 GtkWindow* window = GTK_WINDOW(disconnect_window_); |
58 gtk_window_set_resizable(window, FALSE); | 67 gtk_window_set_resizable(window, FALSE); |
59 // Try to keep the window always visible. | 68 // Try to keep the window always visible. |
60 gtk_window_stick(window); | 69 gtk_window_stick(window); |
61 gtk_window_set_keep_above(window, TRUE); | 70 gtk_window_set_keep_above(window, TRUE); |
62 // Utility windows have no minimize button or taskbar presence. | 71 // Utility windows have no minimize button or taskbar presence. |
63 gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_UTILITY); | 72 gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_UTILITY); |
64 gtk_window_set_deletable(window, FALSE); | 73 gtk_window_set_deletable(window, FALSE); |
65 | 74 |
66 g_signal_connect(disconnect_window_, "response", | 75 g_signal_connect(disconnect_window_, "response", |
67 G_CALLBACK(OnResponseThunk), this); | 76 G_CALLBACK(OnResponseThunk), this); |
68 | 77 |
69 GtkWidget* content_area = | 78 GtkWidget* content_area = |
70 gtk_dialog_get_content_area(GTK_DIALOG(disconnect_window_)); | 79 gtk_dialog_get_content_area(GTK_DIALOG(disconnect_window_)); |
71 | 80 |
72 GtkWidget* username_row = gtk_hbox_new(FALSE, 0); | 81 GtkWidget* message_row = gtk_hbox_new(FALSE, 0); |
73 // TODO(lambroslambrou): Replace the magic number with an appropriate | 82 // TODO(lambroslambrou): Replace the magic number with an appropriate |
74 // constant from a header file (such as chrome/browser/ui/gtk/gtk_util.h | 83 // constant from a header file (such as chrome/browser/ui/gtk/gtk_util.h |
75 // but check_deps disallows its #inclusion here). | 84 // but check_deps disallows its #inclusion here). |
76 gtk_container_set_border_width(GTK_CONTAINER(username_row), 12); | 85 gtk_container_set_border_width(GTK_CONTAINER(message_row), 12); |
77 gtk_container_add(GTK_CONTAINER(content_area), username_row); | 86 gtk_container_add(GTK_CONTAINER(content_area), message_row); |
78 | 87 |
79 GtkWidget* share_label = gtk_label_new(kSharingWith); | 88 message_ = gtk_label_new(NULL); |
80 gtk_container_add(GTK_CONTAINER(username_row), share_label); | 89 gtk_widget_set_size_request(message_, kMessageWidth, -1); |
81 | 90 gtk_label_set_line_wrap(GTK_LABEL(message_), true); |
82 user_label_ = gtk_label_new(NULL); | 91 gtk_container_add(GTK_CONTAINER(message_row), message_); |
83 gtk_container_add(GTK_CONTAINER(username_row), user_label_); | |
84 | 92 |
85 gtk_widget_show_all(content_area); | 93 gtk_widget_show_all(content_area); |
86 } | 94 } |
87 | 95 |
88 void DisconnectWindowLinux::Show(ChromotingHost* host, | 96 void DisconnectWindowLinux::Show(ChromotingHost* host, |
89 const std::string& username) { | 97 const std::string& /* unused */) { |
90 host_ = host; | 98 host_ = host; |
91 CreateWindow(); | 99 CreateWindow(host->ui_strings()); |
92 gtk_label_set_text(GTK_LABEL(user_label_), username.c_str()); | 100 gtk_label_set_text(GTK_LABEL(message_), |
| 101 host->ui_strings()->disconnect_message.c_str()); |
93 gtk_window_present(GTK_WINDOW(disconnect_window_)); | 102 gtk_window_present(GTK_WINDOW(disconnect_window_)); |
94 } | 103 } |
95 | 104 |
96 void DisconnectWindowLinux::Hide() { | 105 void DisconnectWindowLinux::Hide() { |
97 if (disconnect_window_) { | 106 if (disconnect_window_) { |
98 gtk_widget_destroy(disconnect_window_); | 107 gtk_widget_destroy(disconnect_window_); |
99 disconnect_window_ = NULL; | 108 disconnect_window_ = NULL; |
100 } | 109 } |
101 } | 110 } |
102 | 111 |
103 void DisconnectWindowLinux::OnResponse(GtkWidget* dialog, int response_id) { | 112 void DisconnectWindowLinux::OnResponse(GtkWidget* dialog, int response_id) { |
104 // |response_id| is ignored, because there is only one button, and pressing | 113 // |response_id| is ignored, because there is only one button, and pressing |
105 // it should have the same effect as closing the window (if the window Close | 114 // it should have the same effect as closing the window (if the window Close |
106 // button were visible). | 115 // button were visible). |
107 CHECK(host_); | 116 CHECK(host_); |
108 | 117 |
109 host_->Shutdown(NULL); | 118 host_->Shutdown(NULL); |
110 Hide(); | 119 Hide(); |
111 } | 120 } |
112 | 121 |
113 DisconnectWindow* DisconnectWindow::Create() { | 122 DisconnectWindow* DisconnectWindow::Create() { |
114 return new DisconnectWindowLinux; | 123 return new DisconnectWindowLinux; |
115 } | 124 } |
116 | 125 |
117 } // namespace remoting | 126 } // namespace remoting |
OLD | NEW |