| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * Base class that Ribbon uses to display photos. | 6 * Base class that Ribbon uses to display photos. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 function RibbonClient() {} | 9 function RibbonClient() {} |
| 10 | 10 |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 fileWriter.truncate(0); | 879 fileWriter.truncate(0); |
| 880 } | 880 } |
| 881 }, | 881 }, |
| 882 onError); | 882 onError); |
| 883 }, onError); | 883 }, onError); |
| 884 }; | 884 }; |
| 885 | 885 |
| 886 // TODO: Localize? | 886 // TODO: Localize? |
| 887 Ribbon.Item.COPY_SIGNATURE = 'Copy of '; | 887 Ribbon.Item.COPY_SIGNATURE = 'Copy of '; |
| 888 | 888 |
| 889 Ribbon.Item.REGEXP_COPY_N = |
| 890 new RegExp('^' + Ribbon.Item.COPY_SIGNATURE + '(.+) \\((\\d+)\\)$'); |
| 891 |
| 892 Ribbon.Item.REGEXP_COPY_0 = |
| 893 new RegExp('^' + Ribbon.Item.COPY_SIGNATURE + '(.+)$'); |
| 894 |
| 889 Ribbon.Item.prototype.createCopyName_ = function () { | 895 Ribbon.Item.prototype.createCopyName_ = function () { |
| 890 // When saving a modified image we never overwrite the original file (the one | 896 // When saving a modified image we never overwrite the original file (the one |
| 891 // that existed prior to opening the Gallery. Instead we save to a file named | 897 // that existed prior to opening the Gallery. Instead we save to a file named |
| 892 // <original-name>_Edited_<date-stamp>.<original extension>. | 898 // <original-name>_Edited_<date-stamp>.<original extension>. |
| 893 | 899 |
| 894 var name = this.url_.substr(this.url_.lastIndexOf('/') + 1); | 900 var name = this.url_.substr(this.url_.lastIndexOf('/') + 1); |
| 895 | 901 |
| 896 // If the item represents a file created during the current Gallery session | 902 // If the item represents a file created during the current Gallery session |
| 897 // we reuse it for subsequent saves instead of creating multiple copies. | 903 // we reuse it for subsequent saves instead of creating multiple copies. |
| 898 if (!this.original_) | 904 if (!this.original_) |
| 899 return name; | 905 return name; |
| 900 | 906 |
| 901 var ext = ''; | 907 var ext = ''; |
| 902 var index = name.lastIndexOf('.'); | 908 var index = name.lastIndexOf('.'); |
| 903 if (index != -1) { | 909 if (index != -1) { |
| 904 ext = name.substr(index); | 910 ext = name.substr(index); |
| 905 name = name.substr(0, index); | 911 name = name.substr(0, index); |
| 906 } | 912 } |
| 907 | 913 |
| 908 if (name.indexOf(Ribbon.Item.COPY_SIGNATURE) == 0) { | 914 // If the file name contains the copy signature add/advance the sequential |
| 909 // TODO(dgozman): add a number to form 'Copy (X) of File.jpg'. | 915 // number. |
| 910 name = name.substr(Ribbon.Item.COPY_SIGNATURE.length); | 916 // TODO(kaznacheev): Check if the name is already taken. |
| 917 var match = Ribbon.Item.REGEXP_COPY_N.exec(name); |
| 918 if (match && match[1] && match[2]) { |
| 919 var copyNumber = parseInt(match[2], 10) + 1; |
| 920 name = match[1] + ' (' + copyNumber + ')'; |
| 921 } else { |
| 922 match = Ribbon.Item.REGEXP_COPY_0.exec(name); |
| 923 if (match && match[1]) { |
| 924 name = match[1] + ' (1)'; |
| 925 } |
| 911 } | 926 } |
| 912 | 927 |
| 913 var mimeType = this.metadata_.mimeType.toLowerCase(); | 928 var mimeType = this.metadata_.mimeType.toLowerCase(); |
| 914 if (mimeType != 'image/jpeg') { | 929 if (mimeType != 'image/jpeg') { |
| 915 // Chrome can natively encode only two formats: JPEG and PNG. | 930 // Chrome can natively encode only two formats: JPEG and PNG. |
| 916 // All non-JPEG images are saved in PNG, hence forcing the file extension. | 931 // All non-JPEG images are saved in PNG, hence forcing the file extension. |
| 917 if (mimeType == 'image/png') { | 932 ext = '.png'; |
| 918 ext = '.png'; | |
| 919 } else { | |
| 920 // All non-JPEG images get 'image/png' mimeType (see | |
| 921 // ImageEncoder.MetadataEncoder constructor). | |
| 922 // This code can be reached only if someone has added a metadata parser | |
| 923 // for a format other than JPEG or PNG. The message below is to remind | |
| 924 // that one must also come up with the way to encode the image data. | |
| 925 console.error('Image encoding for ' + mimeType + ' is not supported'); | |
| 926 } | |
| 927 } | 933 } |
| 928 | 934 |
| 929 return Ribbon.Item.COPY_SIGNATURE + name + ext; | 935 return Ribbon.Item.COPY_SIGNATURE + name + ext; |
| 930 }; | 936 }; |
| 931 | 937 |
| 932 Ribbon.Item.prototype.setCopyName = function(opt_name) { | 938 Ribbon.Item.prototype.setCopyName = function(opt_name) { |
| 933 if (opt_name) { | 939 if (opt_name) { |
| 934 this.copyName_ = opt_name; | 940 this.copyName_ = opt_name; |
| 935 } else { | 941 } else { |
| 936 this.copyName_ = this.createCopyName_(); | 942 this.copyName_ = this.createCopyName_(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 ShareMode.prototype.setUp = function() { | 1102 ShareMode.prototype.setUp = function() { |
| 1097 ImageEditor.Mode.prototype.setUp.apply(this, arguments); | 1103 ImageEditor.Mode.prototype.setUp.apply(this, arguments); |
| 1098 ImageUtil.setAttribute(this.menu_, 'hidden', false); | 1104 ImageUtil.setAttribute(this.menu_, 'hidden', false); |
| 1099 ImageUtil.setAttribute(this.button_, 'pressed', false); | 1105 ImageUtil.setAttribute(this.button_, 'pressed', false); |
| 1100 }; | 1106 }; |
| 1101 | 1107 |
| 1102 ShareMode.prototype.cleanUpUI = function() { | 1108 ShareMode.prototype.cleanUpUI = function() { |
| 1103 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); | 1109 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); |
| 1104 ImageUtil.setAttribute(this.menu_, 'hidden', true); | 1110 ImageUtil.setAttribute(this.menu_, 'hidden', true); |
| 1105 }; | 1111 }; |
| OLD | NEW |