Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: remoting/host/continue_window_gtk.cc

Issue 11886051: Turned UiStrings into a singleton so that the continue window does not depend on ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/continue_window.h ('k') | remoting/host/continue_window_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 5 #include "remoting/host/continue_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/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "remoting/host/chromoting_host.h"
13 #include "remoting/host/ui_strings.h" 12 #include "remoting/host/ui_strings.h"
14 #include "ui/base/gtk/gtk_signal.h" 13 #include "ui/base/gtk/gtk_signal.h"
15 14
16 namespace remoting { 15 namespace remoting {
17 16
18 class ContinueWindowGtk : public remoting::ContinueWindow { 17 class ContinueWindowGtk : public remoting::ContinueWindow {
19 public: 18 public:
20 ContinueWindowGtk(); 19 explicit ContinueWindowGtk(const UiStrings* ui_strings);
21 virtual ~ContinueWindowGtk(); 20 virtual ~ContinueWindowGtk();
22 21
23 virtual void Show(remoting::ChromotingHost* host, 22 virtual void Show(const ContinueSessionCallback& callback) OVERRIDE;
24 const ContinueSessionCallback& callback) OVERRIDE;
25 virtual void Hide() OVERRIDE; 23 virtual void Hide() OVERRIDE;
26 24
27 private: 25 private:
28 CHROMEGTK_CALLBACK_1(ContinueWindowGtk, void, OnResponse, int); 26 CHROMEGTK_CALLBACK_1(ContinueWindowGtk, void, OnResponse, int);
29 27
30 void CreateWindow(const UiStrings& ui_strings); 28 void CreateWindow();
31 29
32 ChromotingHost* host_;
33 ContinueSessionCallback callback_; 30 ContinueSessionCallback callback_;
34 GtkWidget* continue_window_; 31 GtkWidget* continue_window_;
35 32
33 // Points to the localized strings.
34 const UiStrings* ui_strings_;
35
36 DISALLOW_COPY_AND_ASSIGN(ContinueWindowGtk); 36 DISALLOW_COPY_AND_ASSIGN(ContinueWindowGtk);
37 }; 37 };
38 38
39 ContinueWindowGtk::ContinueWindowGtk() 39 ContinueWindowGtk::ContinueWindowGtk(const UiStrings* ui_strings)
40 : host_(NULL), 40 : continue_window_(NULL),
41 continue_window_(NULL) { 41 ui_strings_(ui_strings) {
42 } 42 }
43 43
44 ContinueWindowGtk::~ContinueWindowGtk() { 44 ContinueWindowGtk::~ContinueWindowGtk() {
45 } 45 }
46 46
47 void ContinueWindowGtk::CreateWindow(const UiStrings& ui_strings) { 47 void ContinueWindowGtk::CreateWindow() {
48 if (continue_window_) return; 48 if (continue_window_)
49 return;
49 50
50 continue_window_ = gtk_dialog_new_with_buttons( 51 continue_window_ = gtk_dialog_new_with_buttons(
51 UTF16ToUTF8(ui_strings.product_name).c_str(), 52 UTF16ToUTF8(ui_strings_->product_name).c_str(),
52 NULL, 53 NULL,
53 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), 54 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
54 UTF16ToUTF8(ui_strings.stop_sharing_button_text).c_str(), 55 UTF16ToUTF8(ui_strings_->stop_sharing_button_text).c_str(),
55 GTK_RESPONSE_CANCEL, 56 GTK_RESPONSE_CANCEL,
56 UTF16ToUTF8(ui_strings.continue_button_text).c_str(), 57 UTF16ToUTF8(ui_strings_->continue_button_text).c_str(),
57 GTK_RESPONSE_OK, 58 GTK_RESPONSE_OK,
58 NULL); 59 NULL);
59 60
60 gtk_dialog_set_default_response(GTK_DIALOG(continue_window_), 61 gtk_dialog_set_default_response(GTK_DIALOG(continue_window_),
61 GTK_RESPONSE_OK); 62 GTK_RESPONSE_OK);
62 gtk_window_set_resizable(GTK_WINDOW(continue_window_), FALSE); 63 gtk_window_set_resizable(GTK_WINDOW(continue_window_), FALSE);
63 64
64 // Set always-on-top, otherwise this window tends to be obscured by the 65 // Set always-on-top, otherwise this window tends to be obscured by the
65 // DisconnectWindow. 66 // DisconnectWindow.
66 gtk_window_set_keep_above(GTK_WINDOW(continue_window_), TRUE); 67 gtk_window_set_keep_above(GTK_WINDOW(continue_window_), TRUE);
67 68
68 g_signal_connect(continue_window_, "response", 69 g_signal_connect(continue_window_, "response",
69 G_CALLBACK(OnResponseThunk), this); 70 G_CALLBACK(OnResponseThunk), this);
70 71
71 GtkWidget* content_area = 72 GtkWidget* content_area =
72 gtk_dialog_get_content_area(GTK_DIALOG(continue_window_)); 73 gtk_dialog_get_content_area(GTK_DIALOG(continue_window_));
73 74
74 GtkWidget* text_label = 75 GtkWidget* text_label =
75 gtk_label_new(UTF16ToUTF8(ui_strings.continue_prompt).c_str()); 76 gtk_label_new(UTF16ToUTF8(ui_strings_->continue_prompt).c_str());
76 gtk_label_set_line_wrap(GTK_LABEL(text_label), TRUE); 77 gtk_label_set_line_wrap(GTK_LABEL(text_label), TRUE);
77 // TODO(lambroslambrou): Fix magic numbers, as in disconnect_window_gtk.cc. 78 // TODO(lambroslambrou): Fix magic numbers, as in disconnect_window_gtk.cc.
78 gtk_misc_set_padding(GTK_MISC(text_label), 12, 12); 79 gtk_misc_set_padding(GTK_MISC(text_label), 12, 12);
79 gtk_container_add(GTK_CONTAINER(content_area), text_label); 80 gtk_container_add(GTK_CONTAINER(content_area), text_label);
80 81
81 gtk_widget_show_all(content_area); 82 gtk_widget_show_all(content_area);
82 } 83 }
83 84
84 void ContinueWindowGtk::Show(remoting::ChromotingHost* host, 85 void ContinueWindowGtk::Show(const ContinueSessionCallback& callback) {
85 const ContinueSessionCallback& callback) {
86 host_ = host;
87 callback_ = callback; 86 callback_ = callback;
88 CreateWindow(host->ui_strings()); 87 CreateWindow();
89 gtk_window_set_urgency_hint(GTK_WINDOW(continue_window_), TRUE); 88 gtk_window_set_urgency_hint(GTK_WINDOW(continue_window_), TRUE);
90 gtk_window_present(GTK_WINDOW(continue_window_)); 89 gtk_window_present(GTK_WINDOW(continue_window_));
91 } 90 }
92 91
93 void ContinueWindowGtk::Hide() { 92 void ContinueWindowGtk::Hide() {
94 if (continue_window_) { 93 if (continue_window_) {
95 gtk_widget_destroy(continue_window_); 94 gtk_widget_destroy(continue_window_);
96 continue_window_ = NULL; 95 continue_window_ = NULL;
97 } 96 }
98 } 97 }
99 98
100 void ContinueWindowGtk::OnResponse(GtkWidget* dialog, int response_id) { 99 void ContinueWindowGtk::OnResponse(GtkWidget* dialog, int response_id) {
101 callback_.Run(response_id == GTK_RESPONSE_OK); 100 callback_.Run(response_id == GTK_RESPONSE_OK);
102 Hide(); 101 Hide();
103 } 102 }
104 103
105 scoped_ptr<ContinueWindow> ContinueWindow::Create() { 104 scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) {
106 return scoped_ptr<ContinueWindow>(new ContinueWindowGtk()); 105 return scoped_ptr<ContinueWindow>(new ContinueWindowGtk(ui_strings));
107 } 106 }
108 107
109 } // namespace remoting 108 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/continue_window.h ('k') | remoting/host/continue_window_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698