Skip to content

Commit

Permalink
print info
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsson committed Feb 7, 2011
1 parent d70af9a commit 7571766
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 6 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion .redcar/tags
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1291811820
1291980758
Cups /home/ivan/projects/thorsson_cups/lib/cups/print_job/transient.rb module Cups
Cups /home/ivan/projects/thorsson_cups/lib/cups/printer/printer.rb module Cups
CupsTest /home/ivan/projects/thorsson_cups/test/cups_test.rb class CupsTest
Expand Down
Empty file modified CHANGES
100644 → 100755
Empty file.
Empty file modified Manifest.txt
100644 → 100755
Empty file.
Empty file modified README.rdoc
100644 → 100755
Empty file.
Empty file modified Rakefile
100644 → 100755
Empty file.
50 changes: 46 additions & 4 deletions ext/cups.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ VALUE rubyCups, printJobs;
// Need to abstract this out of cups.c
VALUE ipp_state_to_symbol(int state)
{

VALUE jstate;

switch (state) {
Expand Down Expand Up @@ -117,7 +116,7 @@ static VALUE cups_print(VALUE self)
char *target = RSTRING_PTR(printer); // Target printer string
char *url = RSTRING_PTR(url_path); // Server URL address
int port = 631; // Default CUPS port

VALUE job_options = rb_iv_get(self, "@job_options");

// Create an array of the keys from the job_options hash
Expand Down Expand Up @@ -413,14 +412,17 @@ static VALUE cups_get_jobs(VALUE self, VALUE printer)

/*
* call-seq:
* Cups.cancel_print(cups_id) -> true or false
* Cups.cancel_print(cups_id, printer_name) -> true or false
*
* Cancel the print job. Returns true if successful, false otherwise.
*/
static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
{
VALUE printer, job_id;
rb_scan_args(argc, argv, "12", &job_id, &printer);
rb_scan_args(argc, argv, "20", &job_id, &printer);

VALUE url_path = cupsServer();
char *url = RSTRING_PTR(url_path);

if (NIL_P(job_id)) {
return Qfalse; // If @job_id is nil
Expand All @@ -433,6 +435,44 @@ static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
}
}

/*
* call-seq:
* Cups.device_uri_for(printer_name) -> String
*
* Return uri for requested printer.
*/
static VALUE cups_get_device_uri(VALUE self, VALUE printer)
{
if (!printer_exists(printer))
{
rb_raise(rb_eRuntimeError, "The printer or destination doesn't exist!");
}

VALUE options_list;
http_t *http;
ipp_t *request;
ipp_t *response;
ipp_attribute_t *attr;
char uri[1024];
char *location;

char *name = RSTRING_PTR(printer);

request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s", name);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);

if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
if((attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI)) != NULL)
{
return rb_str_new2(attr->values[0].string.text);
}
ippDelete(response);
}
return Qtrue;
}

/*
* call-seq:
* Cups.options_for(name) -> Hash or nil
Expand Down Expand Up @@ -501,4 +541,6 @@ void Init_cups() {
rb_define_singleton_method(rubyCups, "all_jobs", cups_get_jobs, 1);
rb_define_singleton_method(rubyCups, "cancel_print", cups_cancel_print, -1);
rb_define_singleton_method(rubyCups, "options_for", cups_get_options, 1);
rb_define_singleton_method(rubyCups, "device_uri_for", cups_get_device_uri, 1);
rb_define_singleton_method(rubyCups, "get_connection_for", cups_get_device_uri, 1);
}
Empty file modified ext/extconf.rb
100644 → 100755
Empty file.
Empty file modified ext/ruby_cups.h
100644 → 100755
Empty file.
Empty file modified lib/cups/print_job/transient.rb
100644 → 100755
Empty file.
Empty file modified lib/cups/printer/printer.rb
100644 → 100755
Empty file.
Empty file modified test/cups_test.rb
100644 → 100755
Empty file.
Empty file modified test/sample.txt
100644 → 100755
Empty file.
Empty file modified test/sample_blank.txt
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion thorsson_cups.gemspec
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = %q{thorsson_cups}
s.version = "0.0.18"
s.version = "0.0.31"
s.authors = ["Ivan Turkovic", "Chris Mowforth"]
s.email = ["me@ivanturkovic.com", "chris@mowforth.com"]
s.summary = "A lightweight Ruby library for printing."
Expand Down

0 comments on commit 7571766

Please sign in to comment.