Add multi-user support
[apps/core/preloaded/print-service.git] / include / pt_api.h
1 /*
2 *       Printservice
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://floralicense.org/license/
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 #ifndef __PRINT_SERVICE_API_H__
21 #define __PRINT_SERVICE_API_H__
22
23 #ifndef API
24 #define API __attribute__ ((visibility("default")))
25 #endif
26
27 #include <glib.h>
28 #include <eina_list.h>
29 #define PT_MAX_LENGTH           512
30
31 typedef enum _pt_err_e {
32         PT_ERR_NONE = 0,                                                        /** success */
33         PT_ERR_FAIL,                                                            /** operate fail */
34         PT_ERR_INVALID_PARAM,                                           /** invalid parameter */
35         PT_ERR_NO_MEMORY,                                                       /** no memory */
36         PT_ERR_NOT_NETWORK_ACCESS,                                      /** network is not available*/
37         PT_ERR_NOT_USB_ACCESS,                                          /** USB is not available */
38         PT_ERR_NO_DEFAULT_PRINTER,                                      /** no default printer */
39         PT_ERR_SET_OPTION_FAIL,                                         /** option is not fit for the printer */
40         PT_ERR_INVALID_USER_CB,                                         /** not USB access */
41         PT_ERR_UNSUPPORTED,                                             /** unsupported */
42         PT_ERR_UNKNOWN,                                                         /** unknown error */
43 } pt_err_e;
44
45 typedef enum _pt_connection_type_e {
46         PT_CONNECTION_USB =0x01,                                                /** usb mode*/
47         PT_CONNECTION_WIFI =0x02,                                               /** wifi mode */
48         PT_CONNECTION_WIFI_DIRECT=0x04,                         /** wifi direct mode */
49 } pt_connection_type_e;
50
51 typedef enum _pt_duplex_e {
52         PT_DUPLEX_OFF = 0,
53         PT_DUPLEX_NO_TUMBLE,
54         PT_DUPLEX_TUMBLE,
55         PT_DUPLEX_ANY,
56         PT_DUPLEX_MAX
57 } pt_duplex_e;
58
59 typedef enum _pt_collate_e {
60         PT_COLLATE_OFF = 0,
61         PT_COLLATE_ON,
62 } pt_collate_e;
63
64 typedef enum _pt_paper_size_e {
65         PT_PAPER_A4 = 0,                                        /** A4:                 210.0 mm x 297.0 mm */
66         PT_PAPER_L,                                             /** L :                 89.0 mm x 127.0 mm */
67         PT_PAPER_2L,                                            /** 2L:                 127.0 mm x 178.0 mm */
68         PT_PAPER_HAGAKI_POSTCARD,                   /** Hagaki Postcard:    100.0 mm x 148.0 mm */
69         PT_PAPER_BUISNESSCARD,                          /** Buisness card:      54.0 mm x 85.6 mm */
70         PT_PAPER_4X6,                                           /** 4" x 6":            101.6 mm x 152.4 mm */
71         PT_PAPER_8X10,                                          /** 8" x 10":           203.2 mm x 254.0 mm */
72         PT_PAPER_LETTER,                                        /** Letter:             216.0 mm x 279.4 mm */
73         PT_PAPER_11X17,                                         /** 11" x 17":          279.4 mm x 431.8 mm */
74         PT_PAPER_SIZE_MAX,
75 } pt_paper_size_e;
76
77 typedef enum _pt_scaling_e {
78         PT_SCALING_FIT_TO_PAGE = 0,                 /** Fit to page */
79 //    PT_SCALING_ORIGINAL_SIZE,                   /** Original image size 100% */
80         PT_SCALING_2_PAGES,                         /** 2 pages in 1 sheet */
81         PT_SCALING_4_PAGES                          /** 4 pages in 1 sheet */
82 //    PT_SCALING_8_PAGES,                         /** 8 pages in 1 sheet */
83 } pt_scaling_e;
84
85 typedef enum _pt_image_size_option_e {
86         PT_SIZE_FIT_TO_PAPER = 0,
87         PT_SIZE_5X7,
88         PT_SIZE_4X6,
89         PT_SIZE_3_5X5,
90         PT_SIZE_WALLET,
91         PT_SIZE_CUSTOM,
92         PT_SIZE_MAX,
93 } pt_image_size_option_e;
94
95 typedef enum _pt_orientation_e {
96         //PT_ORIENTATION_AUTO = 0,                                              /** Auto rotation */
97         PT_ORIENTATION_PORTRAIT,                                                /** Portrait mode */
98         PT_ORIENTATION_LANDSCAPE,                                               /** Landscape mode */
99 } pt_orientation_e;
100
101 typedef enum _pt_paper_e {
102         PT_PAPER_NORMAL = 0,                            /** Normal paper */
103         PT_PAPER_GLOSSY,                                                        /** Glossy paper */
104         PT_PAPER_PHOTO,                                                         /** Photographic paper */
105         PT_PAPER_ANY,                               /** Any kind of paper - doesn't matter */
106         PT_PAPER_MAX
107 } pt_papertype_e;
108
109 typedef enum _pt_quality_e {
110         PT_QUALITY_DRAFT = 0,                           /** Draft print */
111         PT_QUALITY_STANDARD,                                            /** Standard */
112         PT_QUALITY_HIGH,                                                        /** High quality print */
113         PT_QUALITY_ANY,                             /** Any quality - doesn't matter */
114         PT_QUALITY_MAX
115 } pt_quality_e;
116
117 typedef enum _pt_range_e {
118         PT_RANGE_ALL = 0,                                       /** Print all pages */
119         PT_RANGE_CURRENT,                                                       /** Print current page */
120         PT_RANGE_MAX,
121 } pt_range_e;
122
123 typedef enum _pt_grayscale_e {
124         PT_GRAYSCALE_GRAYSCALE = 0,                                     /** Grayscale print */
125         PT_GRAYSCALE_COLOUR,                        /** Coloured print */
126 //    PT_GRAYSCALE_BLACKNWHITE,                                 /** Black & White print */
127         PT_GRAYSCALE_ANY,                           /** Color Or Grayscale - doesn't matter */
128         PT_GRAYSCALE_MAX
129 } pt_grayscale_e;
130
131 typedef enum _pt_printer_state_e {
132         PT_PRINTER_IDLE = 0,                                            /** printer is in idle mode */
133         PT_PRINTER_BUSY,                                                        /** printer is busy for printing */
134         PT_PRINTER_STOPPED,                                                     /** printer has stopped printing */
135         PT_PRINTER_OFFLINE,                                                     /** printer offline */
136 } pt_printer_state_e;
137
138 typedef enum _pt_job_state_e {
139         PT_JOB_ERROR = -1,                                                      /** invalid job status */
140         PT_JOB_PENDING = 3,                                                     /** waiting to be printed */
141         PT_JOB_HELD,                                                            /** held for printing */
142         PT_JOB_PROCESSING,                                                      /** currently printing */
143         PT_JOB_STOPPED,                                                         /** stopped */
144         PT_JOB_CANCELED,                                                        /** canceled */
145         PT_JOB_ABORTED,                                                         /** aborted due to error */
146         PT_JOB_COMPLETED                                                        /** completed successfully */
147 } pt_job_state_e;
148
149 typedef struct {
150         Eina_List *printerlist;                                         /** printer list*/
151         void  *userdata;                                                        /** user data*/
152 } pt_response_data_t;
153
154 typedef enum _pt_event_e {
155         PT_EVENT_JOB_ERROR,
156         PT_EVENT_JOB_PENDING,
157         PT_EVENT_JOB_STARTED,
158         PT_EVENT_JOB_HELD,
159         PT_EVENT_JOB_PROCESSING,
160         PT_EVENT_JOB_PROGRESS,
161         PT_EVENT_JOB_STOPPED,
162         PT_EVENT_JOB_CANCELED,
163         PT_EVENT_JOB_ABORTED,
164         PT_EVENT_JOB_COMPLETED,
165         PT_EVENT_ALL_THREAD_COMPLETED,
166         PT_EVENT_PRINTER_OFFLINE,
167         PT_EVENT_PRINTER_ONLINE,
168         PT_EVENT_USB_PRINTER_OFFLINE,
169         PT_EVENT_USB_PRINTER_ONLINE,
170 } pt_event_e;
171
172 typedef enum _pt_vendor_e {
173         PT_VENDOR_EPSON,
174         PT_VENDOR_GENERIC,
175         PT_VENDOR_HP,
176         PT_VENDOR_SAMSUNG,
177         PT_VENDOR_MAX,
178 } pt_vendor_e;
179
180 typedef enum _pt_print_option_e {
181         PT_OPTION_ID_PRINTER = 0,
182         PT_OPTION_ID_PAPERSIZE,
183         PT_OPTION_ID_COPIES,
184         PT_OPTION_ID_RANGE,
185         PT_OPTION_ID_QUALITY,
186         PT_OPTION_ID_PAPER,
187         PT_OPTION_ID_GRAYSCALE,
188         PT_OPTION_ID_DUPLEX,
189         PT_OPTION_ID_MAX,
190 } pt_print_option_e;
191
192 typedef struct {
193         int job_id;
194         int progress;
195         int page_printed;
196 } pt_progress_info_t;
197
198 typedef void (*get_printers_cb)(pt_response_data_t *resp);    /** callback function*/
199 typedef void (*pt_event_cb)(pt_event_e event, void *user_data, pt_progress_info_t *progress_info);    /** event callback function*/
200
201 #define NOTI_CONVERT_PDF_COMPLETE "mobileprint_convert_pdf_complete"
202 #define NOTI_CONVERT_PDF_ERROR "mobileprint_convert_pdf_error"
203 #define NOTI_USB_PRINTER_CHECK_ONLINE "mobileprint_usb_printer_online"
204 #define NOTI_USB_PRINTER_CHECK_OFFLINE "mobileprint_usb_printer_offline"
205
206 typedef struct {
207         char keyword[PT_MAX_LENGTH];
208         char value[PT_QUALITY_ANY][PT_MAX_LENGTH];
209 } pt_quality_value_t;
210
211 typedef struct {
212         char keyword[PT_MAX_LENGTH];
213         char value[PT_PAPER_ANY][PT_MAX_LENGTH];
214 } pt_paper_value_t;
215
216 typedef struct {
217         char keyword[PT_MAX_LENGTH];
218         char value[PT_GRAYSCALE_ANY][PT_MAX_LENGTH];
219 } pt_color_value_t;
220
221 typedef struct {
222         char name[PT_MAX_LENGTH];                                       /** the description of the printer */
223         char address[PT_MAX_LENGTH];                            /** ip address */
224         char mdl[PT_MAX_LENGTH];                                /* mdl name */
225         char mfg[PT_MAX_LENGTH];                                /* mfg name */
226         char ppd[PT_MAX_LENGTH];                    /** ppd file name (with full path) */
227         gboolean is_ppd_exist;
228         int     authrequired;                                                   /** reserved, the type of authentication required for printing:
229                                                                                                   *  0- none,
230                                                                                                   *  1- username,password,
231                                                                                                   *  2- domain,username,password,
232                                                                                                   *  4- negotiate
233                                                                                                   */
234         int     support_color;                                                                  /** reserved
235                                                                                                   *  0- the printer unsupports color mode,
236                                                                                                   *  1- the printer supports color mode.
237                                                                                                   */
238         int  support_duplex;                                                            /** reserved
239                                                                                                   *  0- the printer unsupports duplex mode,
240                                                                                                   *  1- the printer supports duplex mode.
241                                                                                                   */
242         pt_printer_state_e  status;                             /** printer status */
243         int actived;                                                            /** actived printer */
244
245         int      copies;                                                                /** print copy number */
246         int            size;                                            /** paper size */
247         pt_orientation_e landscape;                                     /** orientation */
248         pt_scaling_e scaling;                                           /** scaling mode */
249         pt_image_size_option_e imagesize;                                       /** image size */
250         pt_range_e range;                                                       /** printing range */
251 //      pt_grayscale_t grayscale;                                       /** colour mode */
252 //      pt_quality_t quality;                                           /** quality */
253 //      pt_paper_t paper;                                                       /** paper type */
254 } pt_printer_mgr_t;
255
256 typedef struct {
257         char name[PT_MAX_LENGTH];
258         double x;
259         double y;
260 } pt_pagesize_t;
261
262 typedef struct {
263         pt_image_size_option_e imagesize;
264         double          resolution_width;
265         double          resolution_height;
266         double          ratio;
267         int                     unit; // 1:cm 2:inch
268 } pt_imagesize_t;
269
270 /**
271  *      This API let the app initialize the environment(eg.ip address) by type
272  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
273  *      @param[in] type connection type enumerated in pt_connection_type
274  *      @param[in] type event callback function
275  */
276 API int pt_init(pt_event_cb evt_cb, void *user_data);
277
278 /**
279  *      This API let the app finalize the environment
280  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
281  */
282 API int pt_deinit(void);
283
284 /**
285  *      This API let the app get the printer list
286  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
287  *      @param[in] callback the pointer to the function which will be excuted after search
288  *      @param[in] userdata the pointer to the user data
289  *      @code
290         static void test_cb(pt_response_data_t *resp)
291         {
292                 if (resp == NULL)
293                         return;
294
295                 if (NULL == resp->printerlist)
296                         return;
297
298                 Eina_List* cursor = NULL;
299                 pt_printer_mgr_t* printer = NULL;
300
301                 EINA_LIST_FOREACH(resp->printerlist,cursor,printer)
302                 {
303                                 ...
304                 }
305
306                 ....
307         }
308
309         void main_test()
310         {
311                 ...
312                 pt_get_printers(test_cb, userdata);
313                 ...
314         }
315  *      @endcode
316  */
317 API int pt_get_printers(get_printers_cb callback, void *userdata);
318
319 /**
320  *      This API let the app cancel getting the printer list
321  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
322  */
323 API int pt_cancel_get_printers();
324
325 /**
326  *      This API let the app get the current default printer
327  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
328  *      @param[out] printer the pointer to the printer object
329  *      @code
330         void main_test()
331         {
332                 ...
333                 pt_printer_mgr_t *pt;
334                 int ret = pt_get_default_printer(&pt);
335                 if(ret != PT_ERR_NONE)
336                         return;
337                 ...
338         }
339  *      @endcode
340  */
341 API int pt_get_default_printer(pt_printer_mgr_t **printer);
342
343 /**
344  *      This API let the app set a printer as the default printer
345  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
346  *      @param[in] printer the pointer to the printer object
347  */
348 API int pt_set_default_printer(pt_printer_mgr_t *printer);
349
350 /**
351  *      This API let the app get the current active printer
352  *      allocates memory for printer info structure! Please free after use!
353  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
354  *      @param[out] printer the pointer to the printer object
355  */
356 int pt_get_active_printer(pt_printer_mgr_t **printer);
357
358 /**
359  *      This API let the app select a specify printer as active printer
360  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
361  *      @param[in] printer the pointer to the printer object
362  */
363 API int pt_set_active_printer(pt_printer_mgr_t *printer);
364
365 /**
366  *      This API let the app set page ranges option for active printer, if not find active printer, will use default printer
367  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
368  *      @param[in] ranges page range string
369  */
370 API int pt_set_print_option_page_range(const char *ranges);
371
372 /**
373  *      This API let the app set copies option for active printer, if not find active printer, will use default printer
374  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
375  *      @param[in] copies the copy number
376  */
377 API int pt_set_print_option_copies(int copies);
378
379 /**
380  *      This API let the app set paper option for active printer, if not find active printer, will use default printer
381  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
382  *      @param[in] papersize the paper size
383  */
384 API int pt_set_print_option_papersize(void);
385
386 /**
387  *      This API let the app set orientation option for active printer, if not find active printer, will use default printer
388  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
389  *      @param[in] orientation the orientation value(0:portrait, 1:landscape)
390  */
391 API int pt_set_print_option_orientation(pt_orientation_e orientation);
392
393 /**
394  *      This API let the app set image fit for the page size, if not find active printer, will use default printer
395  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
396  */
397 API int pt_set_print_option_imagesize(pt_imagesize_t *crop_image_info, const char *filepath, int res_x, int res_y);
398
399 /**
400  *      This API let the app set image fit for the page size, if not find active printer, will use default printer
401  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
402  */
403 API int pt_set_print_option_scaleimage(pt_scaling_e scaling);
404
405 /**
406  *      This API let the app set the color mode (if supported by printer)
407  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
408  */
409 API int pt_set_print_option_color(void);
410
411 /**
412  *      This API let the app set the print quality (if supported by printer)
413  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
414  */
415 API int pt_set_print_option_quality(void);
416
417 /**
418  *      This API let the app set the paper type (if supported by printer)
419  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
420  */
421 API int pt_set_print_option_paper_type(void);
422
423 /**
424  *      This API let the app start the print job on the active printer, if not find active printer, will use default printer
425  *      now only support image and txt file,
426  *      will support pdf,office,eml,html in the future
427  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
428  *      @param[in] files is the print files path address
429  *      @param[in] num is the print files number
430  *      @param[out] jobid the job id
431  */
432 API int pt_start_print(const char **files, int num);
433
434 /**
435  *      This API let the app cancel the print job by jobid
436  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
437  *      @param[in] jobid the job id
438  */
439 API int pt_cancel_print(int jobid);
440
441 /**
442  *      This API let the app get the connect status
443  *      @return   If success, return PT_ERR_CONNECTION_USB_ACCESS or PT_ERR_CONNECTION_WIFI_ACCESS,
444  *      else return the other error code as defined in pt_err_t
445  */
446 API int pt_get_connection_status(int *connection_type);
447
448 /**
449  *      This API let the app get the job status
450  *      @return   return job status
451  *      @param[in] job id
452  */
453 API pt_job_state_e pt_get_current_job_status(int jobid);
454
455 /**
456  *      This API check the printer status
457  *      @return   If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
458  */
459 API pt_printer_state_e pt_check_printer_status(pt_printer_mgr_t *printer);
460
461 /**
462  *      This API returns the human-readable paper size. "papersize_num" is it's position in the PPD file.
463  *      @return   The pointer to the string or NULL if problem
464  */
465 API char *pt_get_print_option_papersize(int papersize_num);
466
467 /**
468  *      This API returns the printer instruction for setting paper size. "papersize_num" is it's position in the PPD file.
469  *      @return   The pointer to the string or NULL if problem
470  */
471 API char *pt_get_print_option_papersize_cmd(int papersize_num);
472
473 /**
474  *      This API returns the number of paper sizes in the PPD.
475  */
476 API int pt_get_print_option_papersize_num(void);
477
478 /**
479  *      This API returns the position of the default paper size in the PPD.
480  */
481 //API int pt_get_print_option_default_papersize(void);
482
483 /**
484  *      This API selects(marks) the choice number ch of the option op.
485  */
486
487 API int pt_set_choice(int op, int ch);
488
489 /**
490  *      This API returns the number of the selected choice of the option op.
491  */
492 API int pt_get_selected(int op);
493
494 /**
495  *      This API checks if the choice ch of the option op can be selected (is enabled).
496  */
497 API int pt_is_enabled(int op, int ch);
498
499 /**
500  *      This API returns the selected page size in points.
501  */
502 API int pt_get_selected_paper_size_pts(pt_pagesize_t *s);
503
504 #endif /* __PRINT_SERVICE_API_H__ */