Module: Cups
- Defined in:
- lib/cups/printer/printer.rb,
lib/cups/print_job/transient.rb,
ext/cups.c
Defined Under Namespace
Class Method Summary collapse
-
.all_jobs(printer) ⇒ Hash
Get all jobs from default CUPS server.
-
.default_printer ⇒ String?
Get default printer or class.
-
.options_for(name) ⇒ Hash?
Get all options from CUPS server with name.
-
.show_destinations ⇒ Array
Show all destinations on the default server.
Class Method Details
.all_jobs(printer) ⇒ Hash
Get all jobs from default CUPS server. Takes a single printer/class string argument. Returned hash keys are CUPS job ids, and the values are hashes of job info with keys:
- :title, :submitted_by, :size, :format, :state
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'ext/cups.c', line 316
static VALUE cups_get_jobs(VALUE self, VALUE printer)
{
VALUE job_list, job_info_hash, jid, jtitle, juser, jsize, jformat, jstate;
int job_id;
int num_jobs;
cups_job_t *jobs;
ipp_jstate_t state;
int i;
char *printer_arg = RSTRING_PTR(printer);
num_jobs = cupsGetJobs(&jobs, printer_arg, 1, -1); // Get jobs
job_list = rb_hash_new();
for (i = 0; i < num_jobs; i ++) { // Construct a hash of individual job info
job_info_hash = rb_hash_new();
jid = INT2NUM(jobs[i].id);
jtitle = rb_str_new2(jobs[i].title);
juser = rb_str_new2(jobs[i].user);
jsize = INT2NUM(jobs[i].size);
jformat = rb_str_new2(jobs[i].format);
jstate = rb_str_new2(ipp_state_to_string(jobs[i].state));
rb_hash_aset(job_info_hash, ID2SYM(rb_intern("title")), jtitle);
rb_hash_aset(job_info_hash, ID2SYM(rb_intern("submitted_by")), juser);
rb_hash_aset(job_info_hash, ID2SYM(rb_intern("size")), jsize);
rb_hash_aset(job_info_hash, ID2SYM(rb_intern("format")), jformat);
rb_hash_aset(job_info_hash, ID2SYM(rb_intern("state")), jstate);
rb_hash_aset(job_list, jid, job_info_hash); // And push it all into job_list hash
}
// Free job array
cupsFreeJobs(num_jobs, jobs);
return job_list;
}
|
.default_printer ⇒ String?
Get default printer or class. Returns a string or false if there is no default
137 138 139 140 141 142 143 144 145 146 |
# File 'ext/cups.c', line 137
static VALUE cups_get_default(VALUE self)
{
const char *default_printer;
default_printer = cupsGetDefault();
if (default_printer != NULL) {
VALUE def_p = rb_str_new2(default_printer);
return def_p;
}
}
|
.options_for(name) ⇒ Hash?
Get all options from CUPS server with name. Returns a hash with key/value pairs based on server options, or nil if no server with name.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'ext/cups.c', line 360
static VALUE cups_get_options(VALUE self, VALUE printer)
{
VALUE options_list;
int i;
char *printer_arg = RSTRING_PTR(printer);
options_list = rb_hash_new();
cups_dest_t *dests;
int num_dests = cupsGetDests(&dests);
cups_dest_t *dest = cupsGetDest(printer_arg, NULL, num_dests, dests);
if (dest == NULL) {
cupsFreeDests(num_dests, dests);
return Qnil;
} else {
for(i =0; i< dest->num_options; i++) {
rb_hash_aset(options_list, rb_str_new2(dest->options[i].name), rb_str_new2(dest->options[i].value));
}
cupsFreeDests(num_dests, dests);
return options_list;
}
}
|
.show_destinations ⇒ Array
Show all destinations on the default server
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/cups.c', line 117
static VALUE cups_show_dests(VALUE self)
{
VALUE dest_list;
int i;
int num_dests = cupsGetDests(&dests); // Size of dest_list array
dest_list = rb_ary_new2(num_dests);
for (i = num_dests, dest = dests; i > 0; i --, dest ++) {
VALUE destination = rb_str_new2(dest->name);
rb_ary_push(dest_list, destination); // Add this testination name to dest_list string
}
return dest_list;
}
|