本文整理汇总了Golang中github.com/google/cups-connector/cdd.NewLocalizedString函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLocalizedString函数的具体用法?Golang NewLocalizedString怎么用?Golang NewLocalizedString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLocalizedString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: convertPagesPerSheet
func convertPagesPerSheet(printerTags map[string][]string) *cdd.VendorCapability {
numberUpSupported, exists := printerTags[attrNumberUpSupported]
if !exists {
return nil
}
c := cdd.VendorCapability{
ID: attrNumberUp,
Type: cdd.VendorCapabilitySelect,
SelectCap: &cdd.SelectCapability{},
DisplayNameLocalized: cdd.NewLocalizedString("Pages per sheet"),
}
def, exists := printerTags[attrNumberUpDefault]
if !exists {
def = []string{"1"}
}
for _, number := range numberUpSupported {
option := cdd.SelectCapabilityOption{
Value: number,
IsDefault: reflect.DeepEqual(number, def[0]),
DisplayNameLocalized: cdd.NewLocalizedString(number),
}
c.SelectCap.Option = append(c.SelectCap.Option, option)
}
return &c
}
开发者ID:kleopatra999,项目名称:cups-connector,代码行数:29,代码来源:translate-attrs.go
示例2: TestGetVendorState
func TestGetVendorState(t *testing.T) {
vs := getVendorState(nil)
if nil != vs {
t.Logf("expected nil")
t.Fail()
}
pt := map[string][]string{}
vs = getVendorState(pt)
if nil != vs {
t.Logf("expected nil")
t.Fail()
}
pt = map[string][]string{
attrPrinterStateReasons: []string{"broken-arrow", "peanut-butter-jam-warning"},
}
expected := &cdd.VendorState{
Item: []cdd.VendorStateItem{
cdd.VendorStateItem{
DescriptionLocalized: cdd.NewLocalizedString("broken-arrow"),
State: cdd.VendorStateError,
},
cdd.VendorStateItem{
DescriptionLocalized: cdd.NewLocalizedString("peanut-butter-jam-warning"),
State: cdd.VendorStateWarning,
},
},
}
vs = getVendorState(pt)
if !reflect.DeepEqual(expected, vs) {
t.Logf("expected\n %+v\ngot\n %+v", expected, vs)
t.Fail()
}
}
开发者ID:t-yuki,项目名称:cups-connector,代码行数:35,代码来源:translate-attrs_test.go
示例3: TestTrInputSlot
func TestTrInputSlot(t *testing.T) {
ppd := `*PPD-Adobe: "4.3"
*OpenUI *OutputBin/Destination: PickOne
*OrderDependency: 210 AnySetup *OutputBin
*DefaultOutputBin: FinProof
*OutputBin Standard/Internal Tray 1: ""
*OutputBin Bin1/Internal Tray 2: ""
*OutputBin External/External Tray: ""
*CloseUI: *OutputBin`
expected := &cdd.PrinterDescriptionSection{
VendorCapability: &[]cdd.VendorCapability{
cdd.VendorCapability{
ID: "OutputBin",
Type: cdd.VendorCapabilitySelect,
DisplayNameLocalized: cdd.NewLocalizedString("Destination"),
SelectCap: &cdd.SelectCapability{
Option: []cdd.SelectCapabilityOption{
cdd.SelectCapabilityOption{"Standard", "", true, cdd.NewLocalizedString("Internal Tray 1")},
cdd.SelectCapabilityOption{"Bin1", "", false, cdd.NewLocalizedString("Internal Tray 2")},
cdd.SelectCapabilityOption{"External", "", false, cdd.NewLocalizedString("External Tray")},
},
},
},
},
}
translationTest(t, ppd, expected)
}
开发者ID:tryandbuy,项目名称:cups-connector,代码行数:27,代码来源:translate-ppd_test.go
示例4: TestConvertColorAttrs
func TestConvertColorAttrs(t *testing.T) {
c := convertColorAttrs(nil)
if c != nil {
t.Logf("expected nil")
t.Fail()
}
pt := map[string][]string{}
c = convertColorAttrs(pt)
if c != nil {
t.Logf("expected nil")
t.Fail()
}
pt = map[string][]string{
"print-color-mode-default": []string{"auto"},
"print-color-mode-supported": []string{"color", "monochrome", "auto", "zebra"},
}
expected := &cdd.Color{
Option: []cdd.ColorOption{
cdd.ColorOption{"print-color-mode:color", cdd.ColorTypeStandardColor, "", false, cdd.NewLocalizedString("Color")},
cdd.ColorOption{"print-color-mode:monochrome", cdd.ColorTypeStandardMonochrome, "", false, cdd.NewLocalizedString("Monochrome")},
cdd.ColorOption{"print-color-mode:auto", cdd.ColorTypeAuto, "", true, cdd.NewLocalizedString("Auto")},
cdd.ColorOption{"print-color-mode:zebra", cdd.ColorTypeCustomColor, "", false, cdd.NewLocalizedString("zebra")},
},
}
c = convertColorAttrs(pt)
if !reflect.DeepEqual(expected, c) {
t.Logf("expected %+v, got %+v", expected, c)
t.Fail()
}
}
开发者ID:t-yuki,项目名称:cups-connector,代码行数:32,代码来源:translate-attrs_test.go
示例5: TestTrPrintQuality
func TestTrPrintQuality(t *testing.T) {
ppd := `*PPD-Adobe: "4.3"
*OpenUI *HPPrintQuality/Print Quality: PickOne
*DefaultHPPrintQuality: FastRes1200
*HPPrintQuality FastRes1200/FastRes 1200: ""
*HPPrintQuality 600dpi/600 dpi: ""
*HPPrintQuality ProRes1200/ProRes 1200: ""
*CloseUI: *HPPrintQuality`
expected := &cdd.PrinterDescriptionSection{
VendorCapability: &[]cdd.VendorCapability{
cdd.VendorCapability{
ID: "HPPrintQuality",
Type: cdd.VendorCapabilitySelect,
DisplayNameLocalized: cdd.NewLocalizedString("Print Quality"),
SelectCap: &cdd.SelectCapability{
Option: []cdd.SelectCapabilityOption{
cdd.SelectCapabilityOption{"FastRes1200", "", true, cdd.NewLocalizedString("FastRes 1200")},
cdd.SelectCapabilityOption{"600dpi", "", false, cdd.NewLocalizedString("600 dpi")},
cdd.SelectCapabilityOption{"ProRes1200", "", false, cdd.NewLocalizedString("ProRes 1200")},
},
},
},
},
}
translationTest(t, ppd, expected)
}
开发者ID:tryandbuy,项目名称:cups-connector,代码行数:26,代码来源:translate-ppd_test.go
示例6: TestTrColor
func TestTrColor(t *testing.T) {
ppd := `*PPD-Adobe: "4.3"
*OpenUI *ColorModel/Color Mode: PickOne
*DefaultColorModel: Gray
*ColorModel CMYK/Color: "(cmyk) RCsetdevicecolor"
*ColorModel Gray/Black and White: "(gray) RCsetdevicecolor"
*CloseUI: *ColorModel`
expected := &cdd.PrinterDescriptionSection{
Color: &cdd.Color{
Option: []cdd.ColorOption{
cdd.ColorOption{"ColorModel:CMYK", cdd.ColorTypeStandardColor, "", false, cdd.NewLocalizedString("Color")},
cdd.ColorOption{"ColorModel:Gray", cdd.ColorTypeStandardMonochrome, "", true, cdd.NewLocalizedString("Black and White")},
},
},
}
translationTest(t, ppd, expected)
ppd = `*PPD-Adobe: "4.3"
*OpenUI *CMAndResolution/Print Color as Gray: PickOne
*OrderDependency: 20 AnySetup *CMAndResolution
*DefaultCMAndResolution: CMYKImageRET3600
*CMAndResolution CMYKImageRET3600/Off: "
<</ProcessColorModel /DeviceCMYK /HWResolution [600 600] /PreRenderingEnhance false >> setpagedevice"
*End
*CMAndResolution Gray600x600dpi/On: "
<</ProcessColorModel /DeviceGray /HWResolution [600 600] >> setpagedevice"
*End
*CloseUI: *CMAndResolution
`
expected = &cdd.PrinterDescriptionSection{
Color: &cdd.Color{
Option: []cdd.ColorOption{
cdd.ColorOption{"CMAndResolution:CMYKImageRET3600", cdd.ColorTypeStandardColor, "", true, cdd.NewLocalizedString("Color")},
cdd.ColorOption{"CMAndResolution:Gray600x600dpi", cdd.ColorTypeStandardMonochrome, "", false, cdd.NewLocalizedString("Gray")},
},
},
}
translationTest(t, ppd, expected)
ppd = `*PPD-Adobe: "4.3"
*OpenUI *CMAndResolution/Print Color as Gray: PickOne
*OrderDependency: 20 AnySetup *CMAndResolution
*DefaultCMAndResolution: CMYKImageRET2400
*CMAndResolution CMYKImageRET2400/Off - ImageRET 2400: "<< /ProcessColorModel /DeviceCMYK /HWResolution [600 600] >> setpagedevice"
*CMAndResolution Gray1200x1200dpi/On - ProRes 1200: "<</ProcessColorModel /DeviceGray /HWResolution [1200 1200] /PreRenderingEnhance false>> setpagedevice"
*CMAndResolution Gray600x600dpi/On - 600 dpi: "<</ProcessColorModel /DeviceGray /HWResolution [600 600] /PreRenderingEnhance false>> setpagedevice"
*CloseUI: *CMAndResolution
`
expected = &cdd.PrinterDescriptionSection{
Color: &cdd.Color{
Option: []cdd.ColorOption{
cdd.ColorOption{"CMAndResolution:CMYKImageRET2400", cdd.ColorTypeStandardColor, "", true, cdd.NewLocalizedString("Color, ImageRET 2400")},
cdd.ColorOption{"CMAndResolution:Gray1200x1200dpi", cdd.ColorTypeCustomMonochrome, "", false, cdd.NewLocalizedString("Gray, ProRes 1200")},
cdd.ColorOption{"CMAndResolution:Gray600x600dpi", cdd.ColorTypeCustomMonochrome, "", false, cdd.NewLocalizedString("Gray, 600 dpi")},
},
},
}
translationTest(t, ppd, expected)
}
开发者ID:jacobmarble,项目名称:cc-deb-pkg,代码行数:59,代码来源:translate-ppd_test.go
示例7: TestConvertPagesPerSheet
func TestConvertPagesPerSheet(t *testing.T) {
vc := convertPagesPerSheet(nil)
if vc != nil {
t.Logf("expected nil")
t.Fail()
}
pt := map[string][]string{}
vc = convertPagesPerSheet(pt)
if vc != nil {
t.Logf("expected nil")
t.Fail()
}
pt = map[string][]string{
"number-up-default": []string{"4"},
"number-up-supported": []string{"1", "2", "4"},
}
expected := &cdd.VendorCapability{
ID: "number-up",
Type: cdd.VendorCapabilitySelect,
SelectCap: &cdd.SelectCapability{
Option: []cdd.SelectCapabilityOption{
cdd.SelectCapabilityOption{
Value: "1",
IsDefault: false,
DisplayNameLocalized: cdd.NewLocalizedString("1"),
},
cdd.SelectCapabilityOption{
Value: "2",
IsDefault: false,
DisplayNameLocalized: cdd.NewLocalizedString("2"),
},
cdd.SelectCapabilityOption{
Value: "4",
IsDefault: true,
DisplayNameLocalized: cdd.NewLocalizedString("4"),
},
},
},
DisplayNameLocalized: cdd.NewLocalizedString("Pages per sheet"),
}
vc = convertPagesPerSheet(pt)
if !reflect.DeepEqual(expected, vc) {
e, _ := json.Marshal(expected)
f, _ := json.Marshal(vc)
t.Logf("expected\n %s\ngot\n %s", e, f)
t.Fail()
}
}
开发者ID:t-yuki,项目名称:cups-connector,代码行数:50,代码来源:translate-attrs_test.go
示例8: convertColorAttrs
func convertColorAttrs(printerTags map[string][]string) *cdd.Color {
colorSupported, exists := printerTags[attrPrintColorModeSupported]
if !exists {
return nil
}
colorDefault, exists := printerTags[attrPrintColorModeDefault]
if !exists || len(colorDefault) != 1 {
colorDefault = colorSupported[:1]
}
var c cdd.Color
for _, color := range colorSupported {
var co cdd.ColorOption
var exists bool
if co, exists = colorByKeyword[color]; !exists {
co = cdd.ColorOption{
VendorID: fmt.Sprintf("%s%s%s", attrPrintColorMode, internalKeySeparator, color),
Type: cdd.ColorTypeCustomColor,
CustomDisplayNameLocalized: cdd.NewLocalizedString(color),
}
}
if color == colorDefault[0] {
co.IsDefault = true
}
c.Option = append(c.Option, co)
}
return &c
}
开发者ID:TechEdge01,项目名称:cups-connector,代码行数:30,代码来源:translate-attrs.go
示例9: TestTrColor
func TestTrColor(t *testing.T) {
ppd := `*PPD-Adobe: "4.3"
*OpenUI *ColorModel/Color Mode: PickOne
*DefaultColorModel: Gray
*ColorModel CMYK/Color: "(cmyk) RCsetdevicecolor"
*ColorModel Gray/Black and White: "(gray) RCsetdevicecolor"
*CloseUI: *ColorModel`
expected := &cdd.PrinterDescriptionSection{
Color: &cdd.Color{
Option: []cdd.ColorOption{
cdd.ColorOption{"ColorModelCMYK", cdd.ColorTypeStandardColor, "", false, cdd.NewLocalizedString("Color")},
cdd.ColorOption{"ColorModelGray", cdd.ColorTypeStandardMonochrome, "", true, cdd.NewLocalizedString("Black and White")},
},
},
}
translationTest(t, ppd, expected)
}
开发者ID:kleopatra999,项目名称:cups-connector,代码行数:17,代码来源:translate-ppd_test.go
示例10: TestTrDPI
func TestTrDPI(t *testing.T) {
ppd := `*PPD-Adobe: "4.3"
*OpenUI *Resolution/Resolution: PickOne
*DefaultResolution: 600dpi
*Resolution 600dpi/600 dpi: ""
*Resolution 1200x600dpi/1200x600 dpi: ""
*Resolution 1200x1200dpi/1200 dpi: ""
*CloseUI: *Resolution`
expected := &cdd.PrinterDescriptionSection{
DPI: &cdd.DPI{
Option: []cdd.DPIOption{
cdd.DPIOption{600, 600, true, "", "600dpi", cdd.NewLocalizedString("600 dpi")},
cdd.DPIOption{1200, 600, false, "", "1200x600dpi", cdd.NewLocalizedString("1200x600 dpi")},
cdd.DPIOption{1200, 1200, false, "", "1200x1200dpi", cdd.NewLocalizedString("1200 dpi")},
},
},
}
translationTest(t, ppd, expected)
}
开发者ID:tryandbuy,项目名称:cups-connector,代码行数:19,代码来源:translate-ppd_test.go
示例11: GetCovers
func (vs *VariableSet) GetCovers() (*[]cdd.Cover, *cdd.CoverState, bool) {
descriptions := vs.GetSubtree(PrinterCoverDescription).Variables()
statuses := vs.GetSubtree(PrinterCoverStatus).Variables()
if len(descriptions) < 1 ||
len(descriptions) != len(statuses) {
return nil, nil, false
}
covers := make([]cdd.Cover, 0, len(descriptions))
coverState := cdd.CoverState{make([]cdd.CoverStateItem, 0, len(statuses))}
for i := 0; i < len(descriptions); i++ {
index := cdd.NewSchizophrenicInt64(descriptions[i].Name[len(descriptions[i].Name)-1])
description := descriptions[i].Value
state := PrinterCoverStatusToGCP[statuses[i].Value]
cover := cdd.Cover{
VendorID: index.String(),
Index: index,
}
switch strings.ToLower(description) {
case "cover":
cover.Type = cdd.CoverTypeCover
case "door":
cover.Type = cdd.CoverTypeDoor
default:
cover.Type = cdd.CoverTypeCustom
cover.CustomDisplayNameLocalized = cdd.NewLocalizedString(description)
}
covers = append(covers, cover)
coverStateItem := cdd.CoverStateItem{
VendorID: index.String(),
State: state,
}
if state == cdd.CoverStateFailure {
coverStateItem.VendorMessage = PrinterCoverStatusTC[statuses[i].Value]
}
coverState.Item = append(coverState.Item, coverStateItem)
}
return &covers, &coverState, true
}
开发者ID:t-yuki,项目名称:cups-connector,代码行数:44,代码来源:printmib.go
示例12: TestRicohLockedPrint
func TestRicohLockedPrint(t *testing.T) {
ppd := `*PPD-Adobe: "4.3"
*OpenUI *JobType/JobType: PickOne
*FoomaticRIPOption JobType: enum CmdLine B
*OrderDependency: 255 AnySetup *JobType
*DefaultJobType: Normal
*JobType Normal/Normal: "%% FoomaticRIPOptionSetting: JobType=Normal"
*JobType SamplePrint/Sample Print: "%% FoomaticRIPOptionSetting: JobType=SamplePrint"
*JobType LockedPrint/Locked Print: ""
*JobType DocServer/Document Server: ""
*CloseUI: *JobType
*OpenUI *LockedPrintPassword/Locked Print Password (4-8 digits): PickOne
*FoomaticRIPOption LockedPrintPassword: password CmdLine C
*FoomaticRIPOptionMaxLength LockedPrintPassword:8
*FoomaticRIPOptionAllowedChars LockedPrintPassword: "0-9"
*OrderDependency: 255 AnySetup *LockedPrintPassword
*DefaultLockedPrintPassword: None
*LockedPrintPassword None/None: ""
*LockedPrintPassword 4001/4001: "%% FoomaticRIPOptionSetting: LockedPrintPassword=4001"
*LockedPrintPassword 4002/4002: "%% FoomaticRIPOptionSetting: LockedPrintPassword=4002"
*LockedPrintPassword 4003/4003: "%% FoomaticRIPOptionSetting: LockedPrintPassword=4003"
*CloseUI: *LockedPrintPassword
*CustomLockedPrintPassword True/Custom Password: ""
*ParamCustomLockedPrintPassword Password: 1 passcode 4 8
`
expected := &cdd.PrinterDescriptionSection{
VendorCapability: &[]cdd.VendorCapability{
cdd.VendorCapability{
ID: "JobType:LockedPrint/LockedPrintPassword",
Type: cdd.VendorCapabilityTypedValue,
DisplayNameLocalized: cdd.NewLocalizedString("Password (4 numbers)"),
TypedValueCap: &cdd.TypedValueCapability{
ValueType: cdd.TypedValueCapabilityTypeString,
},
},
},
}
translationTest(t, ppd, expected)
}
开发者ID:tryandbuy,项目名称:cups-connector,代码行数:41,代码来源:translate-ppd_test.go
示例13: convertColorAttrs
func convertColorAttrs(printerTags map[string][]string) *cdd.Color {
colorSupported, exists := printerTags[attrPrintColorModeSupported]
if !exists {
return nil
}
colorDefault, exists := printerTags[attrPrintColorModeDefault]
if !exists || len(colorDefault) != 1 {
colorDefault = colorSupported[:1]
}
var c cdd.Color
for _, color := range colorSupported {
var co cdd.ColorOption
var exists bool
if co, exists = colorByKeyword[color]; !exists {
co = cdd.ColorOption{
VendorID: color,
Type: cdd.ColorTypeCustomColor,
CustomDisplayNameLocalized: cdd.NewLocalizedString(color),
}
}
if color == colorDefault[0] {
co.IsDefault = true
}
c.Option = append(c.Option, co)
}
for i := range c.Option {
// Color can be specified by either attribute or PPD.
// Therefore, prepend "ColorModel" to these ColorOptions.
c.Option[i].VendorID = attrPrintColorMode + c.Option[i].VendorID
}
return &c
}
开发者ID:kleopatra999,项目名称:cups-connector,代码行数:36,代码来源:translate-attrs.go
示例14: getVendorState
func getVendorState(printerTags map[string][]string) *cdd.VendorState {
reasons, exists := printerTags[attrPrinterStateReasons]
if !exists || len(reasons) < 1 {
return nil
}
sort.Strings(reasons)
vendorState := &cdd.VendorState{Item: make([]cdd.VendorStateItem, len(reasons))}
for i, reason := range reasons {
vs := cdd.VendorStateItem{DescriptionLocalized: cdd.NewLocalizedString(reason)}
if strings.HasSuffix(reason, "-error") {
vs.State = cdd.VendorStateError
} else if strings.HasSuffix(reason, "-warning") {
vs.State = cdd.VendorStateWarning
} else if strings.HasSuffix(reason, "-report") {
vs.State = cdd.VendorStateInfo
} else {
vs.State = cdd.VendorStateError
}
vendorState.Item[i] = vs
}
return vendorState
}
开发者ID:kleopatra999,项目名称:cups-connector,代码行数:24,代码来源:translate-attrs.go
示例15: convertPrinterState
func convertPrinterState(wsStatus uint32) *cdd.PrinterStateSection {
state := cdd.PrinterStateSection{
State: cdd.CloudDeviceStateIdle,
VendorState: &cdd.VendorState{},
}
if wsStatus&(PRINTER_STATUS_PRINTING|PRINTER_STATUS_PROCESSING) != 0 {
state.State = cdd.CloudDeviceStateProcessing
}
if wsStatus&PRINTER_STATUS_PAUSED != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateWarning,
DescriptionLocalized: cdd.NewLocalizedString("printer paused"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_ERROR != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateError,
DescriptionLocalized: cdd.NewLocalizedString("printer error"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_PENDING_DELETION != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateError,
DescriptionLocalized: cdd.NewLocalizedString("printer is being deleted"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_PAPER_JAM != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateError,
DescriptionLocalized: cdd.NewLocalizedString("paper jam"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_PAPER_OUT != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateError,
DescriptionLocalized: cdd.NewLocalizedString("paper out"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_MANUAL_FEED != 0 {
vs := cdd.VendorStateItem{
State: cdd.VendorStateInfo,
DescriptionLocalized: cdd.NewLocalizedString("manual feed mode"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_PAPER_PROBLEM != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateError,
DescriptionLocalized: cdd.NewLocalizedString("paper problem"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_OFFLINE != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateError,
DescriptionLocalized: cdd.NewLocalizedString("printer is offline"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_IO_ACTIVE != 0 {
vs := cdd.VendorStateItem{
State: cdd.VendorStateInfo,
DescriptionLocalized: cdd.NewLocalizedString("active I/O state"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_BUSY != 0 {
vs := cdd.VendorStateItem{
State: cdd.VendorStateInfo,
DescriptionLocalized: cdd.NewLocalizedString("busy"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_OUTPUT_BIN_FULL != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateError,
DescriptionLocalized: cdd.NewLocalizedString("output bin is full"),
}
state.VendorState.Item = append(state.VendorState.Item, vs)
}
if wsStatus&PRINTER_STATUS_NOT_AVAILABLE != 0 {
state.State = cdd.CloudDeviceStateStopped
vs := cdd.VendorStateItem{
State: cdd.VendorStateError,
DescriptionLocalized: cdd.NewLocalizedString("printer not available"),
//.........这里部分代码省略.........
开发者ID:tryandbuy,项目名称:cups-connector,代码行数:101,代码来源:winspool.go
示例16: GetOutputBins
func (vs *VariableSet) GetOutputBins() (*[]cdd.OutputBinUnit, *cdd.OutputBinState, bool) {
capacitiesMax := vs.GetSubtree(PrinterOutputMaxCapacity).Variables()
capacitiesRemaining := vs.GetSubtree(PrinterOutputRemainingCapacity).Variables()
statuses := vs.GetSubtree(PrinterOutputStatus).Variables()
names := vs.GetSubtree(PrinterOutputName).Variables()
if len(names) < 1 ||
len(names) != len(capacitiesMax) ||
len(names) != len(capacitiesRemaining) ||
len(names) != len(statuses) {
return nil, nil, false
}
outputBinUnits := make([]cdd.OutputBinUnit, 0, len(names))
outputBinState := cdd.OutputBinState{make([]cdd.OutputBinStateItem, 0, len(names))}
for i := 0; i < len(names); i++ {
index := cdd.NewSchizophrenicInt64(statuses[i].Name[len(statuses[i].Name)-1])
status, err := strconv.ParseUint(statuses[i].Value, 10, 8)
if err != nil {
return nil, nil, false
}
state := cdd.OutputBinStateOK
stateMessage := []string{}
if (status & PrinterSubUnitUnavailable) != 0 {
stateMessage = append(stateMessage, "unavailable")
switch status & 7 {
case PrinterSubUnitUnavailableAndOnRequest:
stateMessage = append(stateMessage, "on request")
case PrinterSubUnitUnavailableBecauseBroken:
state = cdd.OutputBinStateFailure
stateMessage = append(stateMessage, "broken")
case PrinterSubUnitUnknown:
state = cdd.OutputBinStateFailure
stateMessage = append(stateMessage, "reason unknown")
}
}
if (status & PrinterSubUnitNonCritical) != 0 {
stateMessage = append(stateMessage, "non-critical")
}
if (status & PrinterSubUnitCritical) != 0 {
state = cdd.OutputBinStateFailure
stateMessage = append(stateMessage, "critical")
}
if (status & PrinterSubUnitOffline) != 0 {
state = cdd.OutputBinStateOff
stateMessage = append(stateMessage, "offline")
}
outputState := cdd.OutputBinStateItem{
VendorID: index.String(),
State: state,
VendorMessage: strings.Join(stateMessage, ","),
}
capacityMax, err := strconv.ParseInt(capacitiesMax[i].Value, 10, 32)
if err != nil {
return nil, nil, false
}
capacityRemaining, err := strconv.ParseInt(capacitiesRemaining[i].Value, 10, 32)
if err != nil {
return nil, nil, false
}
if capacityMax >= 0 && capacityRemaining >= 0 {
if capacityRemaining == 0 && state == cdd.OutputBinStateOK {
outputState.State = cdd.OutputBinStateFull
}
levelPercent := 100 - int32(100*capacityRemaining/capacityMax)
outputState.LevelPercent = &levelPercent
}
outputBinState.Item = append(outputBinState.Item, outputState)
outputBinUnits = append(outputBinUnits, cdd.OutputBinUnit{
VendorID: index.String(),
Type: cdd.OutputBinUnitCustom,
Index: index,
CustomDisplayNameLocalized: cdd.NewLocalizedString(names[i].Value),
})
}
return &outputBinUnits, &outputBinState, true
}
开发者ID:t-yuki,项目名称:cups-connector,代码行数:82,代码来源:printmib.go
示例17: GetInputTrays
func (vs *VariableSet) GetInputTrays() (*[]cdd.InputTrayUnit, *cdd.InputTrayState, bool) {
levelsMax := vs.GetSubtree(PrinterInputMaxCapacity).Variables()
levelsCurrent := vs.GetSubtree(PrinterInputCurrentLevel).Variables()
statuses := vs.GetSubtree(PrinterInputStatus).Variables()
names := vs.GetSubtree(PrinterInputName).Variables()
if len(levelsMax) < 1 ||
len(levelsMax) != len(levelsCurrent) ||
len(levelsMax) != len(statuses) ||
len(levelsMax) != len(names) {
return nil, nil, false
}
inputTrayUnits := make([]cdd.InputTrayUnit, 0, len(statuses))
inputTrayState := cdd.InputTrayState{make([]cdd.InputTrayStateItem, 0, len(statuses))}
for i := 0; i < len(statuses); i++ {
index := cdd.NewSchizophrenicInt64(statuses[i].Name[len(statuses[i].Name)-1])
status, err := strconv.ParseUint(statuses[i].Value, 10, 8)
if err != nil {
return nil, nil, false
}
state := cdd.InputTrayStateOK
stateMessage := []string{}
if (status & PrinterSubUnitUnavailable) != 0 {
stateMessage = append(stateMessage, "unavailable")
switch status & 7 {
case PrinterSubUnitUnavailableAndOnRequest:
stateMessage = append(stateMessage, "on request")
case PrinterSubUnitUnavailableBecauseBroken:
state = cdd.InputTrayStateFailure
stateMessage = append(stateMessage, "broken")
case PrinterSubUnitUnknown:
state = cdd.InputTrayStateFailure
stateMessage = append(stateMessage, "reason unknown")
}
}
if (status & PrinterSubUnitNonCritical) != 0 {
stateMessage = append(stateMessage, "non-critical")
}
if (status & PrinterSubUnitCritical) != 0 {
state = cdd.InputTrayStateFailure
stateMessage = append(stateMessage, "critical")
}
if (status & PrinterSubUnitOffline) != 0 {
state = cdd.InputTrayStateOff
stateMessage = append(stateMessage, "offline")
}
inputState := cdd.InputTrayStateItem{
VendorID: index.String(),
State: state,
VendorMessage: strings.Join(stateMessage, ", "),
}
levelMax, err := strconv.ParseInt(levelsMax[i].Value, 10, 32)
if err != nil {
return nil, nil, false
}
levelCurrent, err := strconv.ParseInt(levelsCurrent[i].Value, 10, 32)
if err != nil {
return nil, nil, false
}
if levelMax >= 0 && levelCurrent >= 0 {
if levelCurrent == 0 && state == cdd.InputTrayStateOK {
inputState.State = cdd.InputTrayStateEmpty
}
var levelPercent int32
if levelMax > 0 {
levelPercent = int32(100 * levelCurrent / levelMax)
}
inputState.LevelPercent = &levelPercent
}
if inputState.State == cdd.InputTrayStateOK ||
inputState.State == cdd.InputTrayStateEmpty {
// No message necessary when state says everything.
inputState.VendorMessage = ""
}
inputTrayState.Item = append(inputTrayState.Item, inputState)
inputTrayUnits = append(inputTrayUnits, cdd.InputTrayUnit{
VendorID: index.String(),
Type: cdd.InputTrayUnitCustom,
Index: index,
CustomDisplayNameLocalized: cdd.NewLocalizedString(names[i].Value),
})
}
return &inputTrayUnits, &inputTrayState, true
}
开发者ID:t-yuki,项目名称:cups-connector,代码行数:91,代码来源:printmib.go
示例18: TestConvertMarkers
func TestConvertMarkers(t *testing.T) {
log.SetLevel(log.ERROR)
m, ms := convertMarkers(nil)
if m != nil {
t.Logf("expected nil")
t.Fail()
}
if ms != nil {
t.Logf("expected nil")
t.Fail()
}
pt := map[string][]string{}
m, ms = convertMarkers(pt)
if m != nil {
t.Logf("expected nil")
t.Fail()
}
if ms != nil {
t.Logf("expected nil")
t.Fail()
}
pt = map[string][]string{
attrMarkerNames: []string{"black", "black", "black"},
attrMarkerTypes: []string{"toner", "toner", "ink"},
attrMarkerLevels: []string{"10", "11", "12"},
}
m, ms = convertMarkers(pt)
if m != nil {
t.Logf("expected nil")
t.Fail()
}
if ms != nil {
t.Logf("expected nil")
t.Fail()
}
pt = map[string][]string{
attrMarkerNames: []string{"black", "color"},
attrMarkerTypes: []string{"toner", "toner", "ink"},
attrMarkerLevels: []string{"10", "11", "12"},
}
m, ms = convertMarkers(pt)
if m != nil {
t.Logf("expected nil")
t.Fail()
}
if ms != nil {
t.Logf("expected nil")
t.Fail()
}
pt = map[string][]string{
attrMarkerNames: []string{"black", "color", "rainbow"},
attrMarkerTypes: []string{"toner", "toner"},
attrMarkerLevels: []string{"10", "11", "12"},
}
m, ms = convertMarkers(pt)
if m != nil {
t.Logf("expected nil")
t.Fail()
}
if ms != nil {
t.Logf("expected nil")
t.Fail()
}
pt = map[string][]string{
attrMarkerNames: []string{"black", " Reorder Part #12345", "color", "rainbow", "zebra", "pony"},
attrMarkerTypes: []string{"toner", "toner", "ink", "staples", "water", " Reorder H2O"},
attrMarkerLevels: []string{"10", "11", "12", "208", "13"},
}
mExpected := &[]cdd.Marker{
cdd.Marker{
VendorID: "black, Reorder Part #12345",
Type: cdd.MarkerToner,
Color: &cdd.MarkerColor{Type: cdd.MarkerColorBlack},
},
cdd.Marker{
VendorID: "color",
Type: cdd.MarkerToner,
Color: &cdd.MarkerColor{Type: cdd.MarkerColorColor},
},
cdd.Marker{
VendorID: "rainbow",
Type: cdd.MarkerInk,
Color: &cdd.MarkerColor{
Type: cdd.MarkerColorCustom,
CustomDisplayNameLocalized: cdd.NewLocalizedString("rainbow"),
},
},
cdd.Marker{
VendorID: "zebra",
Type: cdd.MarkerStaples,
},
}
ten, eleven, twelve, eighty := int32(10), int32(11), int32(12), int32(80)
msExpected := &cdd.MarkerState{
//.........这里部分代码省略.........
开发者ID:t-yuki,项目名称:cups-connector,代码行数:101,代码来源:translate-attrs_test.go
示例19: GetMarkers
func (vs *VariableSet) GetMarkers() (*[]cdd.Marker, *cdd.MarkerState, *cdd.VendorState, bool) {
classes := vs.GetSubtree(PrinterMarkerSuppliesClass).Variables()
types := vs.GetSubtree(PrinterMarkerSuppliesType).Variables()
descriptions := vs.GetSubtree(PrinterMarkerSuppliesDescription).Variables()
units := vs.GetSubtree(PrinterMarkerSuppliesSupplyUnit).Variables()
levelsMax := vs.GetSubtree(PrinterMarkerSuppliesMaxCapacity).Variables()
levelsCurrent := vs.GetSubtree(PrinterMarkerSuppliesLevel).Variables()
colors := vs.GetSubtree(PrinterMarkerColorantValue).Variables()
if len(classes) < 1 ||
len(classes) != len(types) ||
len(classes) != len(descriptions) ||
len(classes) != len(units) ||
len(classes) != len(levelsMax) ||
len(classes) != len(levelsCurrent) ||
len(classes) != len(colors) {
return nil, nil, nil, false
}
markers := []cdd.Marker{}
markerState := cdd.MarkerState{}
vendorState := cdd.VendorState{}
for i := 0; i < len(classes); i++ {
index := int64(classes[i].Name[len(classes[i].Name)-1])
levelMax, err := strconv.ParseInt(levelsMax[i].Value, 10, 32)
if err != nil {
return nil, nil, nil, false
}
levelCurrent, err := strconv.ParseInt(levelsCurrent[i].Value, 10, 32)
if err != nil {
return nil, nil, nil, false
}
var levelPercent int32
if levelMax > 0 {
levelPercent = int32(100 * levelCurrent / levelMax)
}
if markerType, exists := PrinterMarkerSuppliesTypeToGCP[types[i].Value]; exists && markerType != "" {
// GCP calls this a Marker.
state := cdd.MarkerStateOK
markerStateItem := cdd.MarkerStateItem{
VendorID: strconv.FormatInt(index, 10),
State: state,
}
if levelMax >= 0 && levelCurrent >= 0 {
if levelPercent <= 10 {
markerStateItem.State = cdd.MarkerStateExhausted
}
markerStateItem.LevelPercent = &levelPercent
if unit, exists := PrinterMarkerSuppliesSupplyUnitTC[units[i].Value]; exists && unit == "sheets" {
levelPages := int32(levelCurrent)
markerStateItem.LevelPages = &levelPages
}
}
rawColor := strings.Replace(strings.Replace(strings.ToLower(colors[i].Value), " ", "", -1), "-", "", -1)
colorType := cdd.MarkerColorCustom
for k, v := range snmpMarkerColorToGCP {
if strings.HasPrefix(rawColor, k) {
colorType = v
break
}
}
markerColor := cdd.MarkerColor{Type: colorType}
if colorType == cdd.MarkerColorCustom {
name := colors[i].Value
name = strings.TrimSuffix(name, " Cartridge")
name = strings.TrimSuffix(name, " cartridge")
name = strings.TrimSuffix(name, " Ribbon")
name = strings.TrimSuffix(name, " ribbon")
name = strings.TrimSuffix(name, " Toner")
name = strings.TrimSuffix(name, " toner")
name = strings.TrimSuffix(name, " Ink")
name = strings.TrimSuffix(name, " ink")
name = strings.Replace(name, "-", " ", -1)
markerColor.CustomDisplayNameLocalized = cdd.NewLocalizedString(name)
}
marker := cdd.Marker{
VendorID: strconv.FormatInt(index, 10),
Type: markerType,
Color: &markerColor,
}
markerState.Item = append(markerState.Item, markerStateItem)
markers = append(markers, marker)
} else {
var state cdd.VendorStateType
if levelPercent <= 1 {
state = cdd.VendorStateError
} else if levelPercent <= 10 {
state = cdd.VendorStateWarning
} else {
state = cdd.VendorStateInfo
}
//.........这里部分代码省略.........
开发者ID:t-yuki,项目名称:cups-connector,代码行数:101,代码来源:printmib.go
示例20:
"os"
"sync"
"unsafe"
"github.com/google/cups-connector/cdd"
)
var numberUpCapability = cdd.VendorCapability{
ID: "number-up",
Type: cdd.VendorCapabilitySelect,
SelectCap: &cdd.SelectCapability{
Option: []cdd.SelectCapabilityOption{
cdd.SelectCapabilityOption{
Value: "1",
IsDefault: true,
DisplayNameLocalized: cdd.NewLocalizedString("1"),
},
cdd.SelectCapabilityOption{
Value: "2",
IsDefault: false,
DisplayNameLocalized: cdd.NewLocalizedString("2"),
},
cdd.SelectCapabilityOption{
Value: "4",
IsDefault: false,
DisplayNameLocalized: cdd.NewLocalizedString("4"),
},
cdd.SelectCapabilityOption{
Value: "6",
IsDefault: false,
DisplayNameLocalized: cdd.NewLocalizedString("6"),
开发者ID:nooyoo11,项目名称:cups-connector,代码行数:31,代码来源:ppdcache.go
注:本文中的github.com/google/cups-connector/cdd.NewLocalizedString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论