| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Butter bar is shown on top of the file list and is used to show the copy |
| 7 * progress and other messages. |
| 8 * @constructor |
| 9 * @param {HTMLElement} dialogDom FileManager top-level div. |
| 10 * @param {FileCopyManagerWrapper} copyManager The copy manager. |
| 11 */ |
| 12 function FileManagerButterBar(dialogDom, copyManager) { |
| 13 ButterBar.call(this, dialogDom); |
| 14 this.copyManager_ = copyManager; |
| 15 |
| 16 this.copyManager_.addEventListener('copy-progress', |
| 17 this.onCopyProgress_.bind(this)); |
| 18 } |
| 19 |
| 20 FileManagerButterBar.prototype = { |
| 21 __proto__: ButterBar.prototype, |
| 22 |
| 23 /** |
| 24 * @private |
| 25 * @return {string?} The type of operation. |
| 26 */ |
| 27 transferType_: function() { |
| 28 var progress = this.progress_; |
| 29 if (!progress || |
| 30 progress.pendingMoves === 0 && progress.pendingCopies === 0) |
| 31 return 'TRANSFER'; |
| 32 |
| 33 if (progress.pendingMoves > 0) { |
| 34 if (progress.pendingCopies > 0) |
| 35 return 'TRANSFER'; |
| 36 return 'MOVE'; |
| 37 } |
| 38 |
| 39 return 'COPY'; |
| 40 }, |
| 41 |
| 42 /** |
| 43 * Set up butter bar for showing copy progress. |
| 44 * @private |
| 45 */ |
| 46 showProgress_: function() { |
| 47 this.progress_ = this.copyManager_.getStatus(); |
| 48 var options = {progress: this.progress_.percentage, actions: {}, |
| 49 timeout: 0}; |
| 50 |
| 51 var type = this.transferType_(); |
| 52 var progressString = (this.progress_.pendingItems === 1) ? |
| 53 strf(type + '_FILE_NAME', this.progress_.filename) : |
| 54 strf(type + '_ITEMS_REMAINING', this.progress_.pendingItems); |
| 55 |
| 56 if (this.isVisible_()) { |
| 57 this.update_(progressString, options); |
| 58 } else { |
| 59 options.actions[str('CANCEL_LABEL')] = |
| 60 this.copyManager_.requestCancel.bind(this.copyManager_); |
| 61 this.show(progressString, options); |
| 62 } |
| 63 }, |
| 64 |
| 65 /** |
| 66 * 'copy-progress' event handler. Show progress or an appropriate message. |
| 67 * @private |
| 68 * @param {cr.Event} event A 'copy-progress' event from FileCopyManager. |
| 69 */ |
| 70 onCopyProgress_: function(event) { |
| 71 if (event.reason != 'PROGRESS') |
| 72 this.clearShowTimeout_(); |
| 73 |
| 74 switch (event.reason) { |
| 75 case 'BEGIN': |
| 76 this.showTimeout_ = setTimeout(function() { |
| 77 this.showTimeout_ = null; |
| 78 this.showProgress_(); |
| 79 }.bind(this), 500); |
| 80 break; |
| 81 |
| 82 case 'PROGRESS': |
| 83 this.showProgress_(); |
| 84 break; |
| 85 |
| 86 case 'SUCCESS': |
| 87 this.hide_(); |
| 88 break; |
| 89 |
| 90 case 'CANCELLED': |
| 91 this.show(str(this.transferType_() + '_CANCELLED'), {timeout: 1000}); |
| 92 break; |
| 93 |
| 94 case 'ERROR': |
| 95 if (event.error.reason === 'TARGET_EXISTS') { |
| 96 var name = event.error.data.name; |
| 97 if (event.error.data.isDirectory) |
| 98 name += '/'; |
| 99 this.showError_(strf(this.transferType_() + |
| 100 '_TARGET_EXISTS_ERROR', name)); |
| 101 } else if (event.error.reason === 'FILESYSTEM_ERROR') { |
| 102 if (event.error.data.toGDrive && |
| 103 event.error.data.code === FileError.QUOTA_EXCEEDED_ERR) { |
| 104 // The alert will be shown in FileManager.onCopyProgress_. |
| 105 this.hide_(); |
| 106 } else { |
| 107 this.showError_(strf(this.transferType_() + '_FILESYSTEM_ERROR', |
| 108 util.getFileErrorString(event.error.data.code))); |
| 109 } |
| 110 } else { |
| 111 this.showError_(strf(this.transferType_() + '_UNEXPECTED_ERROR', |
| 112 event.error)); |
| 113 } |
| 114 break; |
| 115 |
| 116 default: |
| 117 console.log('Unknown "copy-progress" event reason: ' + event.reason); |
| 118 } |
| 119 } |
| 120 }; |
| OLD | NEW |