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

Side by Side Diff: remoting/host/it2me/it2me_confirmation_dialog_linux.cc

Issue 2343443002: Adding a confirmation dialog for It2Me on Linux (Closed)
Patch Set: Addressing CR Feedback Created 4 years, 3 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
« no previous file with comments | « remoting/host/it2me/BUILD.gn ('k') | remoting/host/it2me/it2me_confirmation_dialog_win.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <gtk/gtk.h>
6
7 #include <memory>
8 #include <string>
9
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/callback_helpers.h"
13 #include "base/i18n/message_formatter.h"
14 #include "base/location.h"
15 #include "base/logging.h"
16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h"
20 #include "base/timer/timer.h"
21 #include "remoting/base/string_resources.h"
5 #include "remoting/host/it2me/it2me_confirmation_dialog.h" 22 #include "remoting/host/it2me/it2me_confirmation_dialog.h"
23 #include "ui/base/glib/glib_signal.h"
24 #include "ui/base/l10n/l10n_util.h"
6 25
7 namespace remoting { 26 namespace remoting {
8 27
28 namespace {
29
30 // Time to wait before closing the dialog and cancelling the connection.
31 constexpr base::TimeDelta kDialogTimeout = base::TimeDelta::FromMinutes(1);
32
33 class It2MeConfirmationDialogLinux : public It2MeConfirmationDialog {
34 public:
35 It2MeConfirmationDialogLinux();
36 ~It2MeConfirmationDialogLinux() override;
37
38 // It2MeConfirmationDialog implementation.
39 void Show(const std::string& remote_user_email,
40 const ResultCallback& callback) override;
41
42 private:
43 // Creates a dialog window and makes it visible.
44 void CreateWindow(const std::string& remote_user_email);
45
46 // Destroys the dialog window (if created) and stop |dialog_timer_|.
47 void Hide();
48
49 // Handles user input from the dialog.
50 CHROMEG_CALLBACK_1(It2MeConfirmationDialogLinux, void, OnResponse, GtkDialog*,
51 int);
52
53 GtkWidget* confirmation_window_ = nullptr;
54
55 ResultCallback result_callback_;
56
57 base::OneShotTimer dialog_timer_;
58
59 DISALLOW_COPY_AND_ASSIGN(It2MeConfirmationDialogLinux);
60 };
61
62 It2MeConfirmationDialogLinux::It2MeConfirmationDialogLinux() {}
63
64 It2MeConfirmationDialogLinux::~It2MeConfirmationDialogLinux() {
65 Hide();
66 }
67
68 void It2MeConfirmationDialogLinux::Show(const std::string& remote_user_email,
69 const ResultCallback& callback) {
70 DCHECK(!remote_user_email.empty());
71 DCHECK(callback);
72 DCHECK(!result_callback_);
73
74 result_callback_ = callback;
75
76 CreateWindow(remote_user_email);
77
78 dialog_timer_.Start(FROM_HERE, kDialogTimeout,
79 base::Bind(&It2MeConfirmationDialogLinux::OnResponse,
80 base::Unretained(this),
81 /*dialog=*/nullptr, GTK_RESPONSE_NONE));
82 }
83
84 void It2MeConfirmationDialogLinux::Hide() {
85 dialog_timer_.Stop();
86
87 if (confirmation_window_) {
88 gtk_widget_destroy(confirmation_window_);
89 confirmation_window_ = nullptr;
90 }
91 }
92
93 void It2MeConfirmationDialogLinux::CreateWindow(
94 const std::string& remote_user_email) {
95 DCHECK(!confirmation_window_);
96
97 confirmation_window_ = gtk_dialog_new_with_buttons(
98 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str(),
99 /*parent=*/nullptr,
100 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL),
101 l10n_util::GetStringUTF8(IDS_SHARE_CONFIRM_DIALOG_DECLINE).c_str(),
102 GTK_RESPONSE_CANCEL,
103 l10n_util::GetStringUTF8(IDS_SHARE_CONFIRM_DIALOG_CONFIRM).c_str(),
104 GTK_RESPONSE_OK,
105 /*next_button=*/nullptr);
106
107 gtk_dialog_set_default_response(GTK_DIALOG(confirmation_window_),
108 GTK_RESPONSE_CANCEL);
109
110 gtk_window_set_resizable(GTK_WINDOW(confirmation_window_), false);
111
112 gtk_window_set_keep_above(GTK_WINDOW(confirmation_window_), true);
113
114 g_signal_connect(confirmation_window_, "response",
115 G_CALLBACK(OnResponseThunk), this);
116
117 GtkWidget* content_area =
118 gtk_dialog_get_content_area(GTK_DIALOG(confirmation_window_));
119
120 base::string16 dialog_text =
121 base::i18n::MessageFormatter::FormatWithNumberedArgs(
122 l10n_util::GetStringUTF16(
123 IDS_SHARE_CONFIRM_DIALOG_MESSAGE_WITH_USERNAME),
124 remote_user_email);
125 GtkWidget* text_label = gtk_label_new(base::UTF16ToUTF8(dialog_text).c_str());
126 gtk_label_set_line_wrap(GTK_LABEL(text_label), true);
127 gtk_misc_set_padding(GTK_MISC(text_label), 12, 12);
128
129 gtk_container_add(GTK_CONTAINER(content_area), text_label);
130 gtk_widget_show_all(content_area);
131
132 gtk_window_set_urgency_hint(GTK_WINDOW(confirmation_window_), true);
133 gtk_window_present(GTK_WINDOW(confirmation_window_));
134 }
135
136 void It2MeConfirmationDialogLinux::OnResponse(GtkDialog* dialog,
137 int response_id) {
138 DCHECK(result_callback_);
139
140 Hide();
141 base::ResetAndReturn(&result_callback_).Run(
142 (response_id == GTK_RESPONSE_OK) ? Result::OK : Result::CANCEL);
143 }
144
145 } // namespace
146
9 std::unique_ptr<It2MeConfirmationDialog> 147 std::unique_ptr<It2MeConfirmationDialog>
10 It2MeConfirmationDialogFactory::Create() { 148 It2MeConfirmationDialogFactory::Create() {
11 return nullptr; 149 return base::MakeUnique<It2MeConfirmationDialogLinux>();
12 } 150 }
13 151
14 } // namespace remoting 152 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/BUILD.gn ('k') | remoting/host/it2me/it2me_confirmation_dialog_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698