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