thorsson_cups 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/ext/cups.c +57 -1
  2. metadata +3 -3
data/ext/cups.c CHANGED
@@ -142,7 +142,61 @@ static VALUE cups_print(VALUE self)
142
142
  cupsAddOption(iter_str, value_str, num_options++, &options);
143
143
  }
144
144
 
145
- job_id = cupsPrintFile(target, fname, "rCUPS", num_options, options); // Do it. "rCups" should be the filename/path
145
+ job_id = cupsPrintFile(target, fname, "cloudomat", num_options, options); // Do it. "rCups" should be the filename/path
146
+
147
+ cupsFreeOptions(num_options, options);
148
+
149
+ rb_iv_set(self, "@job_id", INT2NUM(job_id));
150
+
151
+ return Qtrue;
152
+ }
153
+
154
+ /*
155
+ * call-seq:
156
+ * print_job.web_print -> Fixnum
157
+ *
158
+ * Submit a print job from URL to the selected printer or class. Returns true on success.
159
+ */
160
+ static VALUE cups_web_print(VALUE self)
161
+ {
162
+ int job_id;
163
+ VALUE file = rb_iv_get(self, "@filename");
164
+ VALUE printer = rb_iv_get(self, "@printer");
165
+ VALUE url_path = rb_iv_get(self, "@url_path");
166
+
167
+ char *fname = RSTRING_PTR(file); // Filename
168
+ char *target = RSTRING_PTR(printer); // Target printer string
169
+ char *url = RSTRING_PTR(url_path); // URL path for web file
170
+
171
+ VALUE job_options = rb_iv_get(self, "@job_options");
172
+
173
+ // Create an array of the keys from the job_options hash
174
+ VALUE job_options_keys = rb_ary_new();
175
+ rb_hash_foreach(job_options, cups_keys_i, job_options_keys);
176
+
177
+ VALUE iter;
178
+ int num_options = 0;
179
+ cups_option_t *options = NULL;
180
+
181
+ // foreach option in the job options array
182
+ while (! NIL_P(iter = rb_ary_pop(job_options_keys))) {
183
+
184
+ VALUE value = rb_hash_aref(job_options, iter);
185
+
186
+ // assert the key and value are strings
187
+ if (NIL_P(rb_check_string_type(iter)) || NIL_P(rb_check_string_type(value))) {
188
+ cupsFreeOptions(num_options, options);
189
+ rb_raise(rb_eTypeError, "job options is not string => string hash");
190
+ return Qfalse;
191
+ }
192
+
193
+ // convert to char pointers and add to cups optoins
194
+ char * iter_str = rb_string_value_ptr(&iter);
195
+ char * value_str = rb_string_value_ptr(&value);
196
+ cupsAddOption(iter_str, value_str, num_options++, &options);
197
+ }
198
+
199
+ job_id = cupsPrintFile(url, target, fname, "cloudomat", num_options, options); // Do it. "rCups" should be the filename/path
146
200
 
147
201
  cupsFreeOptions(num_options, options);
148
202
 
@@ -471,12 +525,14 @@ void Init_cups() {
471
525
  // Cups::PrintJob Attributes
472
526
  rb_define_attr(printJobs, "printer", 1, 0);
473
527
  rb_define_attr(printJobs, "filename", 1, 0);
528
+ rb_define_attr(printJobs, "url_path", 1, 0)
474
529
  rb_define_attr(printJobs, "job_id", 1, 0);
475
530
  rb_define_attr(printJobs, "job_options", 1, 0);
476
531
 
477
532
  // Cups::PrintJob Methods
478
533
  rb_define_method(printJobs, "initialize", job_init, -1);
479
534
  rb_define_method(printJobs, "print", cups_print, 0);
535
+ rb_define_method(printJobs, "web_print", cups_web_print, 0);
480
536
  rb_define_method(printJobs, "cancel", cups_cancel, 0);
481
537
  rb_define_method(printJobs, "state", cups_get_job_state, 0);
482
538
  rb_define_method(printJobs, "completed?", cups_job_completed, 0);
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 12
9
- version: 0.0.12
8
+ - 13
9
+ version: 0.0.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ivan Turkovic
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-08 00:00:00 +01:00
18
+ date: 2010-12-09 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21