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 5cr.define('print_preview', function() { 6 'use strict'; 7 8 /** Namespace that contains a method to parse local print destinations. */ 9 function LocalDestinationParser() {}; 10 11 /** 12 * Parses a local print destination. 13 * @param {!Object} destinationInfo Information describing a local print 14 * destination. 15 * @return {!print_preview.Destination} Parsed local print destination. 16 */ 17 LocalDestinationParser.parse = function(destinationInfo) { 18 return new print_preview.Destination( 19 destinationInfo.deviceName, 20 print_preview.Destination.Type.LOCAL, 21 print_preview.Destination.Origin.LOCAL, 22 destinationInfo.printerName, 23 false /*isRecent*/, 24 print_preview.Destination.ConnectionStatus.ONLINE); 25 }; 26 27 /** Namespace that contains a method to parse local print capabilities. */ 28 function LocalCapabilitiesParser() {}; 29 30 /** 31 * Parses local print capabilities. 32 * @param {!Object} settingsInfo Object that describes local print 33 * capabilities. 34 * @return {!print_preview.Cdd} Parsed local print capabilities. 35 */ 36 LocalCapabilitiesParser.parse = function(settingsInfo) { 37 var cdd = { 38 version: '1.0', 39 printer: { 40 collate: {default: true} 41 } 42 }; 43 44 if (!settingsInfo['disableColorOption']) { 45 cdd.printer.color = { 46 option: [ 47 { 48 type: 'STANDARD_COLOR', 49 is_default: !!settingsInfo['setColorAsDefault'] 50 }, 51 { 52 type: 'STANDARD_MONOCHROME', 53 is_default: !settingsInfo['setColorAsDefault'] 54 } 55 ] 56 } 57 } 58 59 if (!settingsInfo['disableCopiesOption']) { 60 cdd.printer.copies = {default: 1}; 61 } 62 63 if (settingsInfo['printerDefaultDuplexValue'] != 64 print_preview.NativeLayer.DuplexMode.UNKNOWN_DUPLEX_MODE) { 65 cdd.printer.duplex = { 66 option: [ 67 {type: 'NO_DUPLEX', is_default: !settingsInfo['setDuplexAsDefault']}, 68 {type: 'LONG_EDGE', is_default: !!settingsInfo['setDuplexAsDefault']} 69 ] 70 }; 71 } 72 73 if (!settingsInfo['disableLandscapeOption']) { 74 cdd.printer.page_orientation = { 75 option: [ 76 {type: 'PORTRAIT', is_default: true}, 77 {type: 'LANDSCAPE'} 78 ] 79 }; 80 } 81 82 return cdd; 83 }; 84 85 function PrivetDestinationParser() {} 86 87 /** 88 * Parses a privet destination as a local printer or printers. 89 * @param {!Object} destinationInfo Object that describes a privet printer. 90 * @return {!Array.<print_preview.Destination>} Parsed destination info. 91 */ 92 PrivetDestinationParser.parse = function(destinationInfo) { 93 var returnedPrinters = []; 94 95 if (destinationInfo.hasLocalPrinting) { 96 returnedPrinters.push(new print_preview.Destination( 97 destinationInfo.serviceName, 98 print_preview.Destination.Type.LOCAL, 99 print_preview.Destination.Origin.PRIVET, 100 destinationInfo.name, 101 false /*isRecent*/, 102 print_preview.Destination.ConnectionStatus.ONLINE, 103 { cloudID: destinationInfo.cloudID })); 104 } 105 106 if (destinationInfo.isUnregistered) { 107 returnedPrinters.push(new print_preview.Destination( 108 destinationInfo.serviceName, 109 print_preview.Destination.Type.GOOGLE, 110 print_preview.Destination.Origin.PRIVET, 111 destinationInfo.name, 112 false /*isRecent*/, 113 print_preview.Destination.ConnectionStatus.UNREGISTERED)); 114 } 115 116 return returnedPrinters; 117 }; 118 119 // Export 120 return { 121 LocalCapabilitiesParser: LocalCapabilitiesParser, 122 LocalDestinationParser: LocalDestinationParser, 123 PrivetDestinationParser: PrivetDestinationParser 124 }; 125}); 126