-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdest.go
88 lines (71 loc) · 1.7 KB
/
dest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package cups
/*
#cgo LDFLAGS: -lcups
#include "cups/cups.h"
*/
import "C"
const printerStateIdle = "3"
const printerStatePrinting = "4"
const printerStateStopped = "5"
// Dest is a struct for each printer
type Dest struct {
Name string
IsDefault bool
options map[string]string
// internal keys for status
}
// PrintFile prints a file
// TODO: Complete implementation
// func (d *Dest) PrintFile(filename, mimeType string) int {
// // check mime type
// // check file
// return 0
// }
// Status returns the status of the dest
func (d *Dest) Status() string {
var returnMessage string
// Return status of dest
value, ok := d.options["printer-state"]
if ok != true {
returnMessage = "printer state key does not exist"
}
switch value {
case printerStateIdle:
returnMessage = "idle"
break
case printerStatePrinting:
returnMessage = "printing"
break
case printerStateStopped:
returnMessage = "stopped"
break
default:
returnMessage = "error"
break
}
return returnMessage
}
// GetOption returns the options
// TODO: Complete implementation
// func (d *Dest) GetOption(keyName string) string {
// // Return option
// return ""
// }
// GetOptions returns a map of the dest options
func (d *Dest) GetOptions() map[string]string {
// Return option
return d.options
}
// TestPrint prints a test page
func (d *Dest) TestPrint() int {
var numOptions C.int
var options *C.cups_option_t
var jobID C.int
// resolve path/to/test/file
// TODO: find the location of this file on linux/bsd/osx
osxTest := "/usr/share/cups/data/testprint"
// Print a single file
jobID = C.cupsPrintFile(C.CString(d.Name), C.CString(osxTest),
C.CString("Test Print"), numOptions, options)
return int(jobID)
}