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

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

Issue 6251001: Move chrome/browser/gtk/ to chrome/browser/ui/gtk/... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/import_progress_dialog_gtk.h"
6
7 #include <string>
8
9 #include "app/l10n_util.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/gtk/gtk_util.h"
12 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h"
14
15 using importer::ALL;
16 using importer::BOOKMARKS_HTML;
17 using importer::FAVORITES;
18 using importer::HISTORY;
19 using importer::HOME_PAGE;
20 using importer::ImportItem;
21 using importer::PASSWORDS;
22 using importer::ProfileInfo;
23 using importer::SEARCH_ENGINES;
24
25 namespace {
26
27 void SetItemImportStatus(GtkWidget* label, int res_id, bool is_done) {
28 std::string status = l10n_util::GetStringUTF8(res_id);
29 // Windows version of this has fancy throbbers to indicate progress. Here
30 // we rely on text until we can have something equivalent on Linux.
31 if (is_done)
32 status = "\xE2\x9C\x94 " + status; // U+2714 HEAVY CHECK MARK
33 else
34 status.append(" ...");
35 gtk_label_set_text(GTK_LABEL(label), status.c_str());
36 }
37
38 } // namespace
39
40 // static
41 void ImportProgressDialogGtk::StartImport(GtkWindow* parent,
42 int16 items,
43 ImporterHost* importer_host,
44 const ProfileInfo& browser_profile,
45 Profile* profile,
46 ImportObserver* observer,
47 bool first_run) {
48 ImportProgressDialogGtk* v = new ImportProgressDialogGtk(
49 WideToUTF16(browser_profile.description), items, importer_host, observer,
50 parent, browser_profile.browser_type == BOOKMARKS_HTML);
51
52 // In headless mode it means that we don't show the progress window, but it
53 // still need it to exist. No user interaction will be required.
54 if (!importer_host->is_headless())
55 v->ShowDialog();
56
57 importer_host->StartImportSettings(browser_profile, profile, items,
58 new ProfileWriter(profile),
59 first_run);
60 }
61
62 ////////////////////////////////////////////////////////////////////////////////
63 // ImporterHost::Observer implementation:
64 void ImportProgressDialogGtk::ImportItemStarted(importer::ImportItem item) {
65 DCHECK(items_ & item);
66 switch (item) {
67 case FAVORITES:
68 SetItemImportStatus(bookmarks_,
69 IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS, false);
70 break;
71 case SEARCH_ENGINES:
72 SetItemImportStatus(search_engines_,
73 IDS_IMPORT_PROGRESS_STATUS_SEARCH, false);
74 break;
75 case PASSWORDS:
76 SetItemImportStatus(passwords_,
77 IDS_IMPORT_PROGRESS_STATUS_PASSWORDS, false);
78 break;
79 case HISTORY:
80 SetItemImportStatus(history_,
81 IDS_IMPORT_PROGRESS_STATUS_HISTORY, false);
82 break;
83 default:
84 break;
85 }
86 }
87
88 void ImportProgressDialogGtk::ImportItemEnded(importer::ImportItem item) {
89 DCHECK(items_ & item);
90 switch (item) {
91 case FAVORITES:
92 SetItemImportStatus(bookmarks_,
93 IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS, true);
94 break;
95 case SEARCH_ENGINES:
96 SetItemImportStatus(search_engines_,
97 IDS_IMPORT_PROGRESS_STATUS_SEARCH, true);
98 break;
99 case PASSWORDS:
100 SetItemImportStatus(passwords_,
101 IDS_IMPORT_PROGRESS_STATUS_PASSWORDS, true);
102 break;
103 case HISTORY:
104 SetItemImportStatus(history_,
105 IDS_IMPORT_PROGRESS_STATUS_HISTORY, true);
106 break;
107 default:
108 break;
109 }
110 }
111
112 void ImportProgressDialogGtk::ImportStarted() {
113 importing_ = true;
114 }
115
116 void ImportProgressDialogGtk::ImportEnded() {
117 importing_ = false;
118 importer_host_->SetObserver(NULL);
119 if (observer_)
120 observer_->ImportComplete();
121 CloseDialog();
122 }
123
124 ImportProgressDialogGtk::ImportProgressDialogGtk(const string16& source_profile,
125 int16 items, ImporterHost* importer_host, ImportObserver* observer,
126 GtkWindow* parent, bool bookmarks_import) :
127 parent_(parent), importing_(true), observer_(observer),
128 items_(items), importer_host_(importer_host) {
129 importer_host_->SetObserver(this);
130
131 // Build the dialog.
132 dialog_ = gtk_dialog_new_with_buttons(
133 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_TITLE).c_str(),
134 parent_,
135 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
136 GTK_STOCK_CANCEL,
137 GTK_RESPONSE_REJECT,
138 NULL);
139 importer_host_->set_parent_window(GTK_WINDOW(dialog_));
140
141 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox;
142 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing);
143
144 GtkWidget* control_group = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
145
146 GtkWidget* import_info = gtk_label_new(
147 l10n_util::GetStringFUTF8(IDS_IMPORT_PROGRESS_INFO,
148 source_profile).c_str());
149 gtk_label_set_line_wrap(GTK_LABEL(import_info), TRUE);
150 gtk_widget_set_size_request(import_info, 350, -1);
151 gtk_box_pack_start(GTK_BOX(control_group), import_info, FALSE, FALSE, 0);
152
153 GtkWidget* item_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
154
155 if (items_ & HISTORY) {
156 history_ = gtk_label_new(
157 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_HISTORY).c_str());
158 gtk_misc_set_alignment(GTK_MISC(history_), 0, 0.5);
159 gtk_box_pack_start(GTK_BOX(item_box), history_, FALSE, FALSE, 0);
160 }
161
162 if (items_ & FAVORITES) {
163 bookmarks_ = gtk_label_new(
164 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS).c_str());
165 gtk_misc_set_alignment(GTK_MISC(bookmarks_), 0, 0.5);
166 gtk_box_pack_start(GTK_BOX(item_box), bookmarks_, FALSE, FALSE, 0);
167 }
168
169 if (items_ & SEARCH_ENGINES) {
170 search_engines_ = gtk_label_new(
171 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_SEARCH).c_str());
172 gtk_misc_set_alignment(GTK_MISC(search_engines_), 0, 0.5);
173 gtk_box_pack_start(GTK_BOX(item_box), search_engines_, FALSE, FALSE, 0);
174 }
175
176 if (items_ & PASSWORDS) {
177 passwords_ = gtk_label_new(
178 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_PASSWORDS).c_str());
179 gtk_misc_set_alignment(GTK_MISC(passwords_), 0, 0.5);
180 gtk_box_pack_start(GTK_BOX(item_box), passwords_, FALSE, FALSE, 0);
181 }
182
183 gtk_box_pack_start(GTK_BOX(control_group), gtk_util::IndentWidget(item_box),
184 FALSE, FALSE, 0);
185 gtk_box_pack_start(GTK_BOX(content_area), control_group, FALSE, FALSE, 0);
186
187 g_signal_connect(dialog_, "response",
188 G_CALLBACK(HandleOnResponseDialog), this);
189 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE);
190 }
191
192 ImportProgressDialogGtk::~ImportProgressDialogGtk() {}
193
194 void ImportProgressDialogGtk::CloseDialog() {
195 gtk_widget_destroy(dialog_);
196 dialog_ = NULL;
197 delete this;
198 }
199
200 void ImportProgressDialogGtk::OnDialogResponse(GtkWidget* widget,
201 int response) {
202 if (!importing_) {
203 CloseDialog();
204 return;
205 }
206
207 // Only response to the dialog is to close it so we hide immediately.
208 gtk_widget_hide_all(dialog_);
209 if (response == GTK_RESPONSE_REJECT)
210 importer_host_->Cancel();
211 }
212
213 void ImportProgressDialogGtk::ShowDialog() {
214 gtk_widget_show_all(dialog_);
215 }
216
217
218 void StartImportingWithUI(GtkWindow* parent,
219 uint16 items,
220 ImporterHost* importer_host,
221 const ProfileInfo& browser_profile,
222 Profile* profile,
223 ImportObserver* observer,
224 bool first_run) {
225 DCHECK_NE(0, items);
226 ImportProgressDialogGtk::StartImport(parent, items, importer_host,
227 browser_profile, profile, observer,
228 first_run);
229 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/import_progress_dialog_gtk.h ('k') | chrome/browser/gtk/info_bubble_accelerators_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698