OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * The minimum about of time to display the butter bar for, in ms. | 6 * The minimum about of time to display the butter bar for, in ms. |
7 * Justification is 1000ms for minimum display time plus 300ms for transition | 7 * Justification is 1000ms for minimum display time plus 300ms for transition |
8 * duration. | 8 * duration. |
9 */ | 9 */ |
10 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; | 10 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 * @private | 179 * @private |
180 */ | 180 */ |
181 ButterBar.prototype.clearHideTimeout_ = function() { | 181 ButterBar.prototype.clearHideTimeout_ = function() { |
182 if (this.hideTimeout_) { | 182 if (this.hideTimeout_) { |
183 clearTimeout(this.hideTimeout_); | 183 clearTimeout(this.hideTimeout_); |
184 this.hideTimeout_ = null; | 184 this.hideTimeout_ = null; |
185 } | 185 } |
186 }; | 186 }; |
187 | 187 |
188 /** | 188 /** |
| 189 * @private |
| 190 * @return {string?} The type of operation. |
| 191 */ |
| 192 ButterBar.prototype.transferType_ = function() { |
| 193 var progress = this.progress_; |
| 194 if (!progress || |
| 195 progress.pendingMoves === 0 && progress.pendingCopies === 0) |
| 196 return 'TRANSFER'; |
| 197 |
| 198 if (progress.pendingMoves > 0) { |
| 199 if (progress.pendingCopies > 0) |
| 200 return 'TRANSFER'; |
| 201 return 'MOVE'; |
| 202 } |
| 203 |
| 204 return 'COPY'; |
| 205 }; |
| 206 |
| 207 /** |
189 * Set up butter bar for showing copy progress. | 208 * Set up butter bar for showing copy progress. |
190 * @private | 209 * @private |
191 */ | 210 */ |
192 ButterBar.prototype.showProgress_ = function() { | 211 ButterBar.prototype.showProgress_ = function() { |
193 var progress = this.copyManager_.getProgress(); | 212 this.progress_ = this.copyManager_.getStatus(); |
194 var options = {progress: progress.percentage, actions: {}, timeout: 0}; | 213 var options = {progress: this.progress_.percentage, actions: {}, timeout: 0}; |
195 options.actions[str('CANCEL_LABEL')] = | 214 |
196 this.copyManager_.requestCancel.bind(this.copyManager_); | 215 var type = this.transferType_(); |
197 this.show(strf('PASTE_ITEMS_REMAINING', progress.pendingItems), options); | 216 var progressString = (this.progress_.pendingItems === 1) ? |
| 217 strf(type + '_FILE_NAME', this.progress_.filename) : |
| 218 strf(type + '_ITEMS_REMAINING', this.progress_.pendingItems); |
| 219 |
| 220 if (this.isVisible_()) { |
| 221 this.update_(progressString, options); |
| 222 } else { |
| 223 options.actions[str('CANCEL_LABEL')] = |
| 224 this.copyManager_.requestCancel.bind(this.copyManager_); |
| 225 this.show(progressString, options); |
| 226 } |
198 }; | 227 }; |
199 | 228 |
200 /** | 229 /** |
201 * 'copy-progress' event handler. Show progress or an appropriate message. | 230 * 'copy-progress' event handler. Show progress or an appropriate message. |
202 * @private | 231 * @private |
203 * @param {cr.Event} event A 'copy-progress' event from FileCopyManager. | 232 * @param {cr.Event} event A 'copy-progress' event from FileCopyManager. |
204 */ | 233 */ |
205 ButterBar.prototype.onCopyProgress_ = function(event) { | 234 ButterBar.prototype.onCopyProgress_ = function(event) { |
206 var progress = this.copyManager_.getProgress(); | |
207 | |
208 if (event.reason != 'PROGRESS') | 235 if (event.reason != 'PROGRESS') |
209 this.clearShowTimeout_(); | 236 this.clearShowTimeout_(); |
210 | 237 |
211 switch (event.reason) { | 238 switch (event.reason) { |
212 case 'BEGIN': | 239 case 'BEGIN': |
213 this.showTimeout_ = setTimeout(function() { | 240 this.showTimeout_ = setTimeout(function() { |
214 this.showTimeout_ = null; | 241 this.showTimeout_ = null; |
215 this.showProgress_(); | 242 this.showProgress_(); |
216 }.bind(this), 500); | 243 }.bind(this), 500); |
217 break; | 244 break; |
218 | 245 |
219 case 'PROGRESS': | 246 case 'PROGRESS': |
220 if (this.isVisible_()) { | 247 this.showProgress_(); |
221 var options = {'progress': progress.percentage, timeout: 0}; | |
222 this.update_(strf('PASTE_ITEMS_REMAINING', progress.pendingItems), | |
223 options); | |
224 } | |
225 break; | 248 break; |
226 | 249 |
227 case 'SUCCESS': | 250 case 'SUCCESS': |
228 this.hide_(); | 251 this.hide_(); |
229 break; | 252 break; |
230 | 253 |
231 case 'CANCELLED': | 254 case 'CANCELLED': |
232 this.show(str('PASTE_CANCELLED'), {timeout: 1000}); | 255 this.show(str(this.transferType_() + '_CANCELLED'), {timeout: 1000}); |
233 break; | 256 break; |
234 | 257 |
235 case 'ERROR': | 258 case 'ERROR': |
236 if (event.error.reason === 'TARGET_EXISTS') { | 259 if (event.error.reason === 'TARGET_EXISTS') { |
237 var name = event.error.data.name; | 260 var name = event.error.data.name; |
238 if (event.error.data.isDirectory) | 261 if (event.error.data.isDirectory) |
239 name += '/'; | 262 name += '/'; |
240 this.showError_(strf('PASTE_TARGET_EXISTS_ERROR', name)); | 263 this.showError_(strf(this.transferType_() + |
| 264 '_TARGET_EXISTS_ERROR', name)); |
241 } else if (event.error.reason === 'FILESYSTEM_ERROR') { | 265 } else if (event.error.reason === 'FILESYSTEM_ERROR') { |
242 if (event.error.data.toGDrive && | 266 if (event.error.data.toGDrive && |
243 event.error.data.code === FileError.QUOTA_EXCEEDED_ERR) { | 267 event.error.data.code === FileError.QUOTA_EXCEEDED_ERR) { |
244 // The alert will be shown in FileManager.onCopyProgress_. | 268 // The alert will be shown in FileManager.onCopyProgress_. |
245 this.hide_(); | 269 this.hide_(); |
246 } else { | 270 } else { |
247 this.showError_(strf('PASTE_FILESYSTEM_ERROR', | 271 this.showError_(strf(this.transferType_() + '_FILESYSTEM_ERROR', |
248 getFileErrorString(event.error.data.code))); | 272 getFileErrorString(event.error.data.code))); |
249 } | 273 } |
250 } else { | 274 } else { |
251 this.showError_(strf('PASTE_UNEXPECTED_ERROR', event.error)); | 275 this.showError_(strf(this.transferType_() + '_UNEXPECTED_ERROR', |
| 276 event.error)); |
252 } | 277 } |
253 break; | 278 break; |
254 | 279 |
255 default: | 280 default: |
256 console.log('Unknown "copy-progress" event reason: ' + event.reason); | 281 console.log('Unknown "copy-progress" event reason: ' + event.reason); |
257 } | 282 } |
258 }; | 283 }; |
OLD | NEW |