1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/gtk/translate/before_translate_infobar_gtk.h"
#include "app/l10n_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"
#include "grit/generated_resources.h"
BeforeTranslateInfoBar::BeforeTranslateInfoBar(
TranslateInfoBarDelegate* delegate)
: TranslateInfoBarBase(delegate) {
}
BeforeTranslateInfoBar::~BeforeTranslateInfoBar() {
}
void BeforeTranslateInfoBar::Init() {
TranslateInfoBarBase::Init();
GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing);
gtk_util::CenterWidgetInHBox(hbox_, hbox, false, 0);
size_t offset = 0;
string16 text =
l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE,
string16(), &offset);
gtk_box_pack_start(GTK_BOX(hbox),
CreateLabel(UTF16ToUTF8(text.substr(0, offset))),
FALSE, FALSE, 0);
GtkWidget* combobox =
CreateLanguageCombobox(GetDelegate()->original_language_index(),
GetDelegate()->target_language_index());
g_signal_connect(combobox, "changed",
G_CALLBACK(&OnLanguageModifiedThunk), this);
gtk_box_pack_start(GTK_BOX(hbox), combobox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox),
CreateLabel(UTF16ToUTF8(text.substr(offset))),
FALSE, FALSE, 0);
GtkWidget* button = gtk_button_new_with_label(
l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_ACCEPT).c_str());
g_signal_connect(button, "clicked",G_CALLBACK(&OnAcceptPressedThunk), this);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
button = gtk_button_new_with_label(
l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_DENY).c_str());
g_signal_connect(button, "clicked",G_CALLBACK(&OnDenyPressedThunk), this);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
TranslateInfoBarDelegate* delegate = GetDelegate();
if (delegate->ShouldShowNeverTranslateButton()) {
std::string label =
l10n_util::GetStringFUTF8(IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE,
delegate->GetLanguageDisplayableNameAt(
delegate->original_language_index()));
button = gtk_button_new_with_label(label.c_str());
g_signal_connect(button, "clicked",
G_CALLBACK(&OnNeverTranslatePressedThunk), this);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
}
if (delegate->ShouldShowAlwaysTranslateButton()) {
std::string label =
l10n_util::GetStringFUTF8(IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE,
delegate->GetLanguageDisplayableNameAt(
delegate->original_language_index()));
button = gtk_button_new_with_label(label.c_str());
g_signal_connect(button, "clicked",
G_CALLBACK(&OnAlwaysTranslatePressedThunk), this);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
}
}
void BeforeTranslateInfoBar::OnLanguageModified(GtkWidget* sender) {
int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
if (index == GetDelegate()->original_language_index())
return;
GetDelegate()->SetOriginalLanguage(index);
}
void BeforeTranslateInfoBar::OnAcceptPressed(GtkWidget* sender) {
GetDelegate()->Translate();
}
void BeforeTranslateInfoBar::OnDenyPressed(GtkWidget* sender) {
GetDelegate()->TranslationDeclined();
RemoveInfoBar();
}
void BeforeTranslateInfoBar::OnNeverTranslatePressed(GtkWidget* sender) {
GetDelegate()->NeverTranslatePageLanguage();
}
void BeforeTranslateInfoBar::OnAlwaysTranslatePressed(GtkWidget* sender) {
GetDelegate()->AlwaysTranslatePageLanguage();
}
|