| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Called from the main frame when unloading. | 8 * Called from the main frame when unloading. |
| 9 * @param {boolean=} opt_exiting True if the app is exiting. | 9 * @param {boolean=} opt_exiting True if the app is exiting. |
| 10 */ | 10 */ |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 * Saves new image. | 66 * Saves new image. |
| 67 * | 67 * |
| 68 * @param {Gallery.Item} item Original gallery item. | 68 * @param {Gallery.Item} item Original gallery item. |
| 69 * @param {Canvas} canvas Canvas containing new image. | 69 * @param {Canvas} canvas Canvas containing new image. |
| 70 * @param {boolean} overwrite Whether to overwrite the image to the item or not. | 70 * @param {boolean} overwrite Whether to overwrite the image to the item or not. |
| 71 * @return {Promise} Promise to be fulfilled with when the operation completes. | 71 * @return {Promise} Promise to be fulfilled with when the operation completes. |
| 72 */ | 72 */ |
| 73 GalleryDataModel.prototype.saveItem = function(item, canvas, overwrite) { | 73 GalleryDataModel.prototype.saveItem = function(item, canvas, overwrite) { |
| 74 var oldEntry = item.getEntry(); | 74 var oldEntry = item.getEntry(); |
| 75 var oldMetadata = item.getMetadata(); | 75 var oldMetadata = item.getMetadata(); |
| 76 var oldLocationInfo = item.getLocationInfo(); |
| 76 var metadataEncoder = ImageEncoder.encodeMetadata( | 77 var metadataEncoder = ImageEncoder.encodeMetadata( |
| 77 item.getMetadata(), canvas, 1 /* quality */); | 78 item.getMetadata(), canvas, 1 /* quality */); |
| 78 var newMetadata = ContentProvider.ConvertContentMetadata( | 79 var newMetadata = ContentProvider.ConvertContentMetadata( |
| 79 metadataEncoder.getMetadata(), | 80 metadataEncoder.getMetadata(), |
| 80 MetadataCache.cloneMetadata(item.getMetadata())); | 81 MetadataCache.cloneMetadata(item.getMetadata())); |
| 81 if (newMetadata.filesystem) | 82 if (newMetadata.filesystem) |
| 82 newMetadata.filesystem.modificationTime = new Date(); | 83 newMetadata.filesystem.modificationTime = new Date(); |
| 83 if (newMetadata.drive) | 84 if (newMetadata.external) |
| 84 newMetadata.drive.present = true; | 85 newMetadata.external.present = true; |
| 85 | 86 |
| 86 return new Promise(function(fulfill, reject) { | 87 return new Promise(function(fulfill, reject) { |
| 87 item.saveToFile( | 88 item.saveToFile( |
| 88 this.fallbackSaveDirectory, | 89 this.fallbackSaveDirectory, |
| 89 overwrite, | 90 overwrite, |
| 90 canvas, | 91 canvas, |
| 91 metadataEncoder, | 92 metadataEncoder, |
| 92 function(success) { | 93 function(success) { |
| 93 if (!success) { | 94 if (!success) { |
| 94 reject('Failed to save the image.'); | 95 reject('Failed to save the image.'); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 110 // Need an update of metdataCache. | 111 // Need an update of metdataCache. |
| 111 this.metadataCache_.set( | 112 this.metadataCache_.set( |
| 112 item.getEntry(), | 113 item.getEntry(), |
| 113 Gallery.METADATA_TYPE, | 114 Gallery.METADATA_TYPE, |
| 114 newMetadata); | 115 newMetadata); |
| 115 } else { | 116 } else { |
| 116 // New entry is added and the item now tracks it. | 117 // New entry is added and the item now tracks it. |
| 117 // Add another item for the old entry. | 118 // Add another item for the old entry. |
| 118 var anotherItem = new Gallery.Item( | 119 var anotherItem = new Gallery.Item( |
| 119 oldEntry, | 120 oldEntry, |
| 121 oldLocationInfo, |
| 120 oldMetadata, | 122 oldMetadata, |
| 121 this.metadataCache_, | 123 this.metadataCache_, |
| 122 item.isOriginal(), | 124 item.isOriginal(), |
| 123 item.isReadOnly()); | 125 item.isReadOnly()); |
| 124 // The item must be added behind the existing item so that it does | 126 // The item must be added behind the existing item so that it does |
| 125 // not change the index of the existing item. | 127 // not change the index of the existing item. |
| 126 // TODO(hirono): Update the item index of the selection model | 128 // TODO(hirono): Update the item index of the selection model |
| 127 // correctly. | 129 // correctly. |
| 128 this.splice(this.indexOf(item) + 1, 0, anotherItem); | 130 this.splice(this.indexOf(item) + 1, 0, anotherItem); |
| 129 } | 131 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 * @const | 249 * @const |
| 248 * @type {number} | 250 * @type {number} |
| 249 */ | 251 */ |
| 250 Gallery.MOSAIC_BACKGROUND_INIT_DELAY = 1000; | 252 Gallery.MOSAIC_BACKGROUND_INIT_DELAY = 1000; |
| 251 | 253 |
| 252 /** | 254 /** |
| 253 * Types of metadata Gallery uses (to query the metadata cache). | 255 * Types of metadata Gallery uses (to query the metadata cache). |
| 254 * @const | 256 * @const |
| 255 * @type {string} | 257 * @type {string} |
| 256 */ | 258 */ |
| 257 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|drive'; | 259 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|external'; |
| 258 | 260 |
| 259 /** | 261 /** |
| 260 * Initializes listeners. | 262 * Initializes listeners. |
| 261 * @private | 263 * @private |
| 262 */ | 264 */ |
| 263 Gallery.prototype.initListeners_ = function() { | 265 Gallery.prototype.initListeners_ = function() { |
| 264 this.keyDownBound_ = this.onKeyDown_.bind(this); | 266 this.keyDownBound_ = this.onKeyDown_.bind(this); |
| 265 this.document_.body.addEventListener('keydown', this.keyDownBound_); | 267 this.document_.body.addEventListener('keydown', this.keyDownBound_); |
| 266 | 268 |
| 267 this.inactivityWatcher_ = new MouseInactivityWatcher( | 269 this.inactivityWatcher_ = new MouseInactivityWatcher( |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 // Obtains metadata for chunk. | 484 // Obtains metadata for chunk. |
| 483 var entries = chunk.map(function(chunkItem) { | 485 var entries = chunk.map(function(chunkItem) { |
| 484 return chunkItem.entry; | 486 return chunkItem.entry; |
| 485 }); | 487 }); |
| 486 self.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill); | 488 self.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill); |
| 487 }).then(function(metadataList) { | 489 }).then(function(metadataList) { |
| 488 if (chunk.length !== metadataList.length) | 490 if (chunk.length !== metadataList.length) |
| 489 return Promise.reject('Failed to load metadata.'); | 491 return Promise.reject('Failed to load metadata.'); |
| 490 | 492 |
| 491 // Add items to the model. | 493 // Add items to the model. |
| 492 var items = chunk.map(function(chunkItem, index) { | 494 var items = []; |
| 493 var volumeInfo = self.volumeManager_.getVolumeInfo(chunkItem.entry); | 495 chunk.forEach(function(chunkItem, index) { |
| 496 var locationInfo = self.volumeManager_.getLocationInfo(chunkItem.entry); |
| 497 if (!locationInfo) // Skip the item, since gone. |
| 498 return; |
| 494 var clonedMetadata = MetadataCache.cloneMetadata(metadataList[index]); | 499 var clonedMetadata = MetadataCache.cloneMetadata(metadataList[index]); |
| 495 return new Gallery.Item( | 500 items.push(new Gallery.Item( |
| 496 chunkItem.entry, | 501 chunkItem.entry, |
| 502 locationInfo, |
| 497 clonedMetadata, | 503 clonedMetadata, |
| 498 self.metadataCache_, | 504 self.metadataCache_, |
| 499 /* original */ true, | 505 /* original */ true, |
| 500 /* readonly */ !!(volumeInfo && volumeInfo.isReadOnly)); | 506 /* readonly */ !!(locationInfo && locationInfo.isReadOnly))); |
| 501 }); | 507 }); |
| 502 self.dataModel_.push.apply(self.dataModel_, items); | 508 self.dataModel_.push.apply(self.dataModel_, items); |
| 503 | 509 |
| 504 // Apply the selection. | 510 // Apply the selection. |
| 505 var selectionUpdated = false; | 511 var selectionUpdated = false; |
| 506 for (var i = 0; i < chunk.length; i++) { | 512 for (var i = 0; i < chunk.length; i++) { |
| 507 if (!chunk[i].selected) | 513 if (!chunk[i].selected) |
| 508 continue; | 514 continue; |
| 509 var index = self.dataModel_.indexOf(items[i]); | 515 var index = self.dataModel_.indexOf(items[i]); |
| 510 if (index < 0) | 516 if (index < 0) |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 // Update cache. | 852 // Update cache. |
| 847 selectedItem.touch(); | 853 selectedItem.touch(); |
| 848 this.dataModel_.evictCache(); | 854 this.dataModel_.evictCache(); |
| 849 | 855 |
| 850 // Update the title and the display name. | 856 // Update the title and the display name. |
| 851 if (numSelectedItems === 1) { | 857 if (numSelectedItems === 1) { |
| 852 document.title = this.selectedEntry_.name; | 858 document.title = this.selectedEntry_.name; |
| 853 this.filenameEdit_.disabled = selectedItem.isReadOnly(); | 859 this.filenameEdit_.disabled = selectedItem.isReadOnly(); |
| 854 this.filenameEdit_.value = | 860 this.filenameEdit_.value = |
| 855 ImageUtil.getDisplayNameFromName(this.selectedEntry_.name); | 861 ImageUtil.getDisplayNameFromName(this.selectedEntry_.name); |
| 856 this.shareButton_.hidden = !selectedItem.isOnDrive(); | 862 this.shareButton_.hidden = !selectedItem.getLocationInfo().isDriveBased; |
| 857 } else { | 863 } else { |
| 858 if (this.context_.curDirEntry) { | 864 if (this.context_.curDirEntry) { |
| 859 // If the Gallery was opened on search results the search query will not | 865 // If the Gallery was opened on search results the search query will not |
| 860 // be recorded in the app state and the relaunch will just open the | 866 // be recorded in the app state and the relaunch will just open the |
| 861 // gallery in the curDirEntry directory. | 867 // gallery in the curDirEntry directory. |
| 862 document.title = this.context_.curDirEntry.name; | 868 document.title = this.context_.curDirEntry.name; |
| 863 } else { | 869 } else { |
| 864 document.title = ''; | 870 document.title = ''; |
| 865 } | 871 } |
| 866 this.filenameEdit_.disabled = true; | 872 this.filenameEdit_.disabled = true; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 window.loadTimeData.data = backgroundComponents.stringData; | 1022 window.loadTimeData.data = backgroundComponents.stringData; |
| 1017 gallery = new Gallery(backgroundComponents.volumeManager); | 1023 gallery = new Gallery(backgroundComponents.volumeManager); |
| 1018 }; | 1024 }; |
| 1019 | 1025 |
| 1020 /** | 1026 /** |
| 1021 * Loads entries. | 1027 * Loads entries. |
| 1022 */ | 1028 */ |
| 1023 window.loadEntries = function(entries, selectedEntries) { | 1029 window.loadEntries = function(entries, selectedEntries) { |
| 1024 gallery.load(entries, selectedEntries); | 1030 gallery.load(entries, selectedEntries); |
| 1025 }; | 1031 }; |
| OLD | NEW |