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

Side by Side Diff: chrome/browser/gtk/first_run_dialog.cc

Issue 149348: Linux: Add First Run UI. (Closed)
Patch Set: merge to tot Created 11 years, 5 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 | « chrome/browser/gtk/first_run_dialog.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 "chrome/browser/gtk/first_run_dialog.h"
6
7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h"
9 #include "base/message_loop.h"
10 #include "chrome/app/breakpad_linux.h"
11 #include "chrome/browser/shell_integration.h"
12 #include "chrome/common/gtk_util.h"
13 #include "chrome/installer/util/google_update_settings.h"
14 #include "grit/generated_resources.h"
15 #include "grit/google_chrome_strings.h"
16
17 // static
18 bool FirstRunDialog::Show(Profile* profile) {
19 int response = -1;
20 new FirstRunDialog(profile, response);
21 return (response == GTK_RESPONSE_ACCEPT);
22 }
23
24 FirstRunDialog::FirstRunDialog(Profile* profile, int& response)
25 : dialog_(NULL), report_crashes_(NULL), make_default_(NULL),
26 import_data_(NULL), import_profile_(NULL), profile_(profile),
27 response_(response), importer_host_(new ImporterHost()) {
28 dialog_ = gtk_dialog_new_with_buttons(
29 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(),
30 NULL, // No parent
31 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
32 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_OK).c_str(),
33 GTK_RESPONSE_ACCEPT,
34 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_CANCEL).c_str(),
35 GTK_RESPONSE_REJECT,
36 NULL);
37 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE);
38 g_signal_connect(G_OBJECT(dialog_), "delete-event",
39 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
40
41 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox;
42 gtk_box_set_spacing(GTK_BOX(content_area), 18);
43
44 GtkWidget* vbox = gtk_vbox_new(FALSE, 12);
45 // Force a size on the vbox so the labels wrap.
46 gtk_widget_set_size_request(vbox, 350, -1);
47
48 #if defined(GOOGLE_CHROME_BUILD)
49 // TODO(port): remove this warning before beta release when we have all the
50 // privacy features working.
51 GtkWidget* privacy_label = gtk_label_new(
52 "This version of Google Chrome for Linux is not appropriate for "
53 "general consumer use. Certain privacy features are unavailable "
54 "at this time as described in our privacy policy at");
55 gtk_misc_set_alignment(GTK_MISC(privacy_label), 0, 0);
56 gtk_label_set_line_wrap(GTK_LABEL(privacy_label), TRUE);
57 gtk_box_pack_start(GTK_BOX(vbox), privacy_label, FALSE, FALSE, 0);
58
59 GtkWidget* url_label = gtk_label_new(NULL);
60 gtk_label_set_markup(GTK_LABEL(url_label),
61 "<tt>http://www.google.com/chrome/intl/en/privacy_linux.html</tt>");
62 // Set selectable to allow copy and paste.
63 gtk_label_set_selectable(GTK_LABEL(url_label), TRUE);
64 gtk_box_pack_start(GTK_BOX(vbox), url_label, FALSE, FALSE, 0);
65
66 report_crashes_ = gtk_check_button_new();
67 GtkWidget* check_label = gtk_label_new(
68 l10n_util::GetStringUTF8(IDS_OPTIONS_ENABLE_LOGGING).c_str());
69 gtk_label_set_line_wrap(GTK_LABEL(check_label), TRUE);
70 gtk_container_add(GTK_CONTAINER(report_crashes_), check_label);
71 gtk_box_pack_start(GTK_BOX(vbox), report_crashes_, FALSE, FALSE, 0);
72 #endif
73
74 make_default_ = gtk_check_button_new_with_label(
75 l10n_util::GetStringUTF8(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER).c_str());
76 gtk_box_pack_start(GTK_BOX(vbox), make_default_, FALSE, FALSE, 0);
77
78 GtkWidget* combo_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing);
79 import_data_ = gtk_check_button_new_with_label(
80 l10n_util::GetStringUTF8(IDS_FR_CUSTOMIZE_IMPORT).c_str());
81 gtk_box_pack_start(GTK_BOX(combo_hbox), import_data_, FALSE, FALSE, 0);
82 import_profile_ = gtk_combo_box_new_text();
83 gtk_box_pack_start(GTK_BOX(combo_hbox), import_profile_, TRUE, TRUE, 0);
84 gtk_box_pack_start(GTK_BOX(vbox), combo_hbox, FALSE, FALSE, 0);
85
86 // Detect any supported browsers that we can import from and fill
87 // up the combo box. If none found, disable import data checkbox.
88 int profiles_count = importer_host_->GetAvailableProfileCount();
89 if (profiles_count > 0) {
90 for (int i = 0; i < profiles_count; i++) {
91 std::wstring profile = importer_host_->GetSourceProfileNameAt(i);
92 gtk_combo_box_append_text(GTK_COMBO_BOX(import_profile_),
93 WideToUTF8(profile).c_str());
94 }
95 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(import_data_), TRUE);
96 gtk_combo_box_set_active(GTK_COMBO_BOX(import_profile_), 0);
97 } else {
98 gtk_combo_box_append_text(GTK_COMBO_BOX(import_profile_),
99 l10n_util::GetStringUTF8(IDS_IMPORT_NO_PROFILE_FOUND).c_str());
100 gtk_combo_box_set_active(GTK_COMBO_BOX(import_profile_), 0);
101 gtk_widget_set_sensitive(import_data_, FALSE);
102 gtk_widget_set_sensitive(import_profile_, FALSE);
103 }
104
105 gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0);
106
107 // TODO(port): it should be sufficient to just run the dialog:
108 // int response = gtk_dialog_run(GTK_DIALOG(dialog));
109 // but that spins a nested message loop and hoses us. :(
110 // http://code.google.com/p/chromium/issues/detail?id=12552
111 // Instead, run a loop and extract the response manually.
112 g_signal_connect(G_OBJECT(dialog_), "response",
113 G_CALLBACK(HandleOnResponseDialog), this);
114 gtk_widget_show_all(dialog_);
115 MessageLoop::current()->Run();
116 }
117
118 void FirstRunDialog::OnDialogResponse(GtkWidget* widget, int response) {
119 gtk_widget_hide_all(dialog_);
120 response_ = response;
121
122 if (response == GTK_RESPONSE_ACCEPT) {
123 // Mark that first run has ran.
124 FirstRun::CreateSentinel();
125
126 // Check if user has opted into reporting.
127 if (report_crashes_ &&
128 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(report_crashes_))) {
129 if (GoogleUpdateSettings::SetCollectStatsConsent(true))
130 InitCrashReporter();
131 } else {
132 GoogleUpdateSettings::SetCollectStatsConsent(false);
133 }
134
135 // If selected set as default browser.
136 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(make_default_)))
137 ShellIntegration::SetAsDefaultBrowser();
138
139 // Import data if selected.
140 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(import_data_))) {
141 const ProfileInfo& source_profile =
142 importer_host_->GetSourceProfileInfoAt(
143 gtk_combo_box_get_active(GTK_COMBO_BOX(import_profile_)));
144 int items = SEARCH_ENGINES + HISTORY + FAVORITES + HOME_PAGE + PASSWORDS;
145 // TODO(port): Call StartImportingWithUI here instead and launch
146 // a new process that does the actual import.
147 importer_host_->StartImportSettings(source_profile, profile_, items,
148 new ProfileWriter(profile_), true);
149 }
150 }
151
152 gtk_widget_destroy(dialog_);
153 MessageLoop::current()->Quit();
154 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/first_run_dialog.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698