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); | 59 std::string buttonLabel = ui_strings->disconnectButtonText + " (" + |
Sergey Ulanov
2011/08/13 01:11:36
Whole string must be localizible, and not some par
Jamie
2011/08/13 01:34:03
Unfortunately on Windows we need to remove the sho
Sergey Ulanov
2011/08/13 01:37:26
Then I think the right solution in this case is to
Jamie
2011/08/13 02:20:15
Done.
| |
49 disconnect_button += kDisconnectKeysLinux; | 60 ui_strings->disconnectButtonShortcut + ")"; |
61 | |
50 disconnect_window_ = gtk_dialog_new_with_buttons( | 62 disconnect_window_ = gtk_dialog_new_with_buttons( |
51 kTitle, | 63 ui_strings->productName.c_str(), |
52 NULL, | 64 NULL, |
53 GTK_DIALOG_NO_SEPARATOR, | 65 GTK_DIALOG_NO_SEPARATOR, |
54 disconnect_button.c_str(), GTK_RESPONSE_OK, | 66 buttonLabel.c_str(), GTK_RESPONSE_OK, |
55 NULL); | 67 NULL); |
56 | 68 |
57 GtkWindow* window = GTK_WINDOW(disconnect_window_); | 69 GtkWindow* window = GTK_WINDOW(disconnect_window_); |
58 gtk_window_set_resizable(window, FALSE); | 70 gtk_window_set_resizable(window, FALSE); |
59 // Try to keep the window always visible. | 71 // Try to keep the window always visible. |
60 gtk_window_stick(window); | 72 gtk_window_stick(window); |
61 gtk_window_set_keep_above(window, TRUE); | 73 gtk_window_set_keep_above(window, TRUE); |
62 // Utility windows have no minimize button or taskbar presence. | 74 // Utility windows have no minimize button or taskbar presence. |
63 gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_UTILITY); | 75 gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_UTILITY); |
64 gtk_window_set_deletable(window, FALSE); | 76 gtk_window_set_deletable(window, FALSE); |
65 | 77 |
66 g_signal_connect(disconnect_window_, "response", | 78 g_signal_connect(disconnect_window_, "response", |
67 G_CALLBACK(OnResponseThunk), this); | 79 G_CALLBACK(OnResponseThunk), this); |
68 | 80 |
69 GtkWidget* content_area = | 81 GtkWidget* content_area = |
70 gtk_dialog_get_content_area(GTK_DIALOG(disconnect_window_)); | 82 gtk_dialog_get_content_area(GTK_DIALOG(disconnect_window_)); |
71 | 83 |
72 GtkWidget* username_row = gtk_hbox_new(FALSE, 0); | 84 GtkWidget* message_row = gtk_hbox_new(FALSE, 0); |
73 // TODO(lambroslambrou): Replace the magic number with an appropriate | 85 // TODO(lambroslambrou): Replace the magic number with an appropriate |
74 // constant from a header file (such as chrome/browser/ui/gtk/gtk_util.h | 86 // constant from a header file (such as chrome/browser/ui/gtk/gtk_util.h |
75 // but check_deps disallows its #inclusion here). | 87 // but check_deps disallows its #inclusion here). |
76 gtk_container_set_border_width(GTK_CONTAINER(username_row), 12); | 88 gtk_container_set_border_width(GTK_CONTAINER(message_row), 12); |
77 gtk_container_add(GTK_CONTAINER(content_area), username_row); | 89 gtk_container_add(GTK_CONTAINER(content_area), message_row); |
78 | 90 |
79 GtkWidget* share_label = gtk_label_new(kSharingWith); | 91 message_ = gtk_label_new(NULL); |
80 gtk_container_add(GTK_CONTAINER(username_row), share_label); | 92 gtk_widget_set_size_request(message_, kMessageWidth, -1); |
81 | 93 gtk_label_set_line_wrap(GTK_LABEL(message_), true); |
82 user_label_ = gtk_label_new(NULL); | 94 gtk_container_add(GTK_CONTAINER(message_row), message_); |
83 gtk_container_add(GTK_CONTAINER(username_row), user_label_); | |
84 | 95 |
85 gtk_widget_show_all(content_area); | 96 gtk_widget_show_all(content_area); |
86 } | 97 } |
87 | 98 |
88 void DisconnectWindowLinux::Show(ChromotingHost* host, | 99 void DisconnectWindowLinux::Show(ChromotingHost* host, |
89 const std::string& username) { | 100 const std::string& /* unused */) { |
90 host_ = host; | 101 host_ = host; |
91 CreateWindow(); | 102 CreateWindow(host->ui_strings()); |
92 gtk_label_set_text(GTK_LABEL(user_label_), username.c_str()); | 103 gtk_label_set_text(GTK_LABEL(message_), |
104 host->ui_strings()->disconnectMessage.c_str()); | |
93 gtk_window_present(GTK_WINDOW(disconnect_window_)); | 105 gtk_window_present(GTK_WINDOW(disconnect_window_)); |
94 } | 106 } |
95 | 107 |
96 void DisconnectWindowLinux::Hide() { | 108 void DisconnectWindowLinux::Hide() { |
97 if (disconnect_window_) { | 109 if (disconnect_window_) { |
98 gtk_widget_destroy(disconnect_window_); | 110 gtk_widget_destroy(disconnect_window_); |
99 disconnect_window_ = NULL; | 111 disconnect_window_ = NULL; |
100 } | 112 } |
101 } | 113 } |
102 | 114 |
103 void DisconnectWindowLinux::OnResponse(GtkWidget* dialog, int response_id) { | 115 void DisconnectWindowLinux::OnResponse(GtkWidget* dialog, int response_id) { |
104 // |response_id| is ignored, because there is only one button, and pressing | 116 // |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 | 117 // it should have the same effect as closing the window (if the window Close |
106 // button were visible). | 118 // button were visible). |
107 CHECK(host_); | 119 CHECK(host_); |
108 | 120 |
109 host_->Shutdown(NULL); | 121 host_->Shutdown(NULL); |
110 Hide(); | 122 Hide(); |
111 } | 123 } |
112 | 124 |
113 DisconnectWindow* DisconnectWindow::Create() { | 125 DisconnectWindow* DisconnectWindow::Create() { |
114 return new DisconnectWindowLinux; | 126 return new DisconnectWindowLinux; |
115 } | 127 } |
116 | 128 |
117 } // namespace remoting | 129 } // namespace remoting |
OLD | NEW |