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.
5 cr.define('print_preview', function() {
8 /** Namespace that contains a method to parse local print destinations. */
9 function LocalDestinationParser() {};
12 * Parses a local print destination.
13 * @param {!Object} destinationInfo Information describing a local print
15 * @return {!print_preview.Destination} Parsed local print destination.
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,
24 print_preview.Destination.ConnectionStatus.ONLINE);
27 /** Namespace that contains a method to parse local print capabilities. */
28 function LocalCapabilitiesParser() {};
31 * Parses local print capabilities.
32 * @param {!Object} settingsInfo Object that describes local print
34 * @return {!print_preview.Cdd} Parsed local print capabilities.
36 LocalCapabilitiesParser.parse = function(settingsInfo) {
40 collate: {default: true}
44 if (!settingsInfo['disableColorOption']) {
48 type: 'STANDARD_COLOR',
49 is_default: !!settingsInfo['setColorAsDefault']
52 type: 'STANDARD_MONOCHROME',
53 is_default: !settingsInfo['setColorAsDefault']
59 if (!settingsInfo['disableCopiesOption']) {
60 cdd.printer.copies = {default: 1};
63 if (settingsInfo['printerDefaultDuplexValue'] !=
64 print_preview.NativeLayer.DuplexMode.UNKNOWN_DUPLEX_MODE) {
65 cdd.printer.duplex = {
67 {type: 'NO_DUPLEX', is_default: !settingsInfo['setDuplexAsDefault']},
68 {type: 'LONG_EDGE', is_default: !!settingsInfo['setDuplexAsDefault']}
73 if (!settingsInfo['disableLandscapeOption']) {
74 cdd.printer.page_orientation = {
76 {type: 'PORTRAIT', is_default: true},
85 function PrivetDestinationParser() {}
88 * Parses a privet destination as one or more local printers.
89 * @param {!Object} destinationInfo Object that describes a privet printer.
90 * @return {!Array.<!print_preview.Destination>} Parsed destination info.
92 PrivetDestinationParser.parse = function(destinationInfo) {
93 var returnedPrinters = [];
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,
102 print_preview.Destination.ConnectionStatus.ONLINE,
103 { cloudID: destinationInfo.cloudID }));
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,
113 print_preview.Destination.ConnectionStatus.UNREGISTERED));
116 return returnedPrinters;
121 LocalCapabilitiesParser: LocalCapabilitiesParser,
122 LocalDestinationParser: LocalDestinationParser,
123 PrivetDestinationParser: PrivetDestinationParser