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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
// 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.
#import "chrome/browser/cocoa/import_progress_dialog.h"
#include "app/l10n_util_mac.h"
#include "base/logging.h"
#include "base/mac_util.h"
#include "base/message_loop.h"
#import "base/scoped_nsobject.h"
#import "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
namespace {
// Convert ImportItem enum into the name of the ImportProgressDialogController
// property corresponding to the text for that item, this makes the code to
// change the values for said properties much more readable.
NSString* keyForImportItem(importer::ImportItem item) {
switch(item) {
case importer::HISTORY:
return @"historyStatusText";
case importer::FAVORITES:
return @"favoritesStatusText";
case importer::PASSWORDS:
return @"savedPasswordStatusText";
case importer::SEARCH_ENGINES:
return @"searchStatusText";
default:
DCHECK(false);
break;
}
return nil;
}
} // namespace
@implementation ImportProgressDialogController
@synthesize explanatoryText = explanatory_text_;
@synthesize favoritesStatusText = favorites_status_text_;
@synthesize searchStatusText = search_status_text_;
@synthesize savedPasswordStatusText = saved_password_status_text_;
@synthesize historyStatusText = history_status_text_;
@synthesize favoritesImportEnabled = favorites_import_enabled_;
@synthesize searchImportEnabled = search_import_enabled_;
@synthesize passwordImportEnabled = password_import_enabled_;
@synthesize historyImportEnabled = history_import_enabled_;
- (id)initWithImporterHost:(ImporterHost*)host
browserName:(string16)browserName
observer:(ImportObserver*)observer
itemsEnabled:(int16)items; {
NSString* nib_path =
[mac_util::MainAppBundle() pathForResource:@"ImportProgressDialog"
ofType:@"nib"];
self = [super initWithWindowNibPath:nib_path owner:self];
if (self != nil) {
importer_host_ = host;
observer_ = observer;
import_host_observer_bridge_.reset(new ImporterObserverBridge(self));
importer_host_->SetObserver(import_host_observer_bridge_.get());
string16 productName = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
NSString* explanatory_text = l10n_util::GetNSStringF(
IDS_IMPORT_PROGRESS_EXPLANATORY_TEXT_MAC,
productName,
browserName);
[self setExplanatoryText:explanatory_text];
progress_text_ =
[l10n_util::GetNSStringWithFixup(IDS_IMPORT_IMPORTING_PROGRESS_TEXT_MAC)
retain];
done_text_ =
[l10n_util::GetNSStringWithFixup(IDS_IMPORT_IMPORTING_DONE_TEXT_MAC)
retain];
// Enable/disable item titles.
NSColor* disabled = [NSColor disabledControlTextColor];
NSColor* active = [NSColor textColor];
[self setFavoritesImportEnabled:items & importer::FAVORITES ? active :
disabled];
[self setSearchImportEnabled:items & importer::SEARCH_ENGINES ? active :
disabled];
[self setPasswordImportEnabled:items & importer::PASSWORDS ? active :
disabled];
[self setHistoryImportEnabled:items & importer::HISTORY ? active :
disabled];
}
return self;
}
- (void)dealloc {
[explanatory_text_ release];
[favorites_status_text_ release];
[search_status_text_ release];
[saved_password_status_text_ release];
[history_status_text_ release];
[favorites_import_enabled_ release];
[search_import_enabled_ release];
[password_import_enabled_ release];
[history_import_enabled_ release];
[progress_text_ release];
[done_text_ release];
[super dealloc];
}
- (IBAction)showWindow:(id)sender {
NSWindow* win = [self window];
[win center];
[super showWindow:nil];
}
- (void)closeDialog {
if ([[self window] isVisible]) {
[[self window] close];
}
}
- (IBAction)cancel:(id)sender {
[self closeDialog];
if (importing_) {
importer_host_->Cancel();
} else {
[self release];
}
}
- (void)ImportItemStarted:(importer::ImportItem)item {
[self setValue:progress_text_ forKey:keyForImportItem(item)];
}
- (void)ImportItemEnded:(importer::ImportItem)item {
[self setValue:done_text_ forKey:keyForImportItem(item)];
}
- (void)ImportStarted {
importing_ = YES;
}
- (void)ImportEnded {
importing_ = NO;
importer_host_->SetObserver(NULL);
if (observer_)
observer_->ImportComplete();
[self closeDialog];
[self release];
// Break out of modal event loop.
[NSApp stopModal];
}
@end
void StartImportingWithUI(gfx::NativeWindow parent_window,
int16 items,
ImporterHost* coordinator,
const importer::ProfileInfo& source_profile,
Profile* target_profile,
ImportObserver* observer,
bool first_run) {
DCHECK(items != 0);
// Retrieve name of browser we're importing from and do a little dance to
// convert wstring -> string16.
string16 import_browser_name = WideToUTF16Hack(source_profile.description);
// progress_dialog_ is responsible for deleting itself.
ImportProgressDialogController* progress_dialog_ =
[[ImportProgressDialogController alloc]
initWithImporterHost:coordinator
browserName:import_browser_name
observer:observer
itemsEnabled:items];
// Call is async.
coordinator->StartImportSettings(source_profile, target_profile, items,
new ProfileWriter(target_profile),
first_run);
// Display the window while spinning a message loop.
// For details on why we need a modal message loop see http://crbug.com/19169
NSWindow* progress_window = [progress_dialog_ window];
NSModalSession session = [NSApp beginModalSessionForWindow:progress_window];
[progress_dialog_ showWindow:nil];
while (true) {
if ([NSApp runModalSession:session] != NSRunContinuesResponse)
break;
MessageLoop::current()->RunAllPending();
}
[NSApp endModalSession:session];
}
|