merge with master
[apps/home/mobileprint.git] / mobileprint / include / pts_common.h
1 /*
2 *  Mobileprint
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.0 (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 PTS_COMMON_H_
21 #define PTS_COMMON_H_
22
23 #include <appcore-common.h>
24 #include <Ecore.h>
25 #include <Ecore_X.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <Elementary.h>
29 #include <notification.h>
30 #include <pt_api.h>
31 #include "pts_debug.h"
32
33 #include <smsc_smart.h>
34
35 #define PTS_2   "Can not register the printer"
36 #define PTS_17  "Error option"
37 #define PTS_18  "Tap to add printer"
38 #define PTS_19  "Unable to cancel. The current page is already being printed."
39
40 #define IDS_PRT_1       "Failed to connect Wi-Fi Direct Printer"
41 #define IDS_PRT_2       "USB Printer Connected"
42 #define IDS_PRT_5       "Unable to cancel. The current page is already being printed."
43 #define IDS_PRT_6       "The printer is not connected"
44 #define IDS_PRT_7       "Disconnect USB cable, then reconnect it"
45 #define IDS_PRT_8       "You are not connected to a Wi-Fi network"
46 #define IDS_PRT_9       "The printer is not ready"
47 #define IDS_PRT_10      "Print info error"
48 #define IDS_PRT_11      "Printer is use"
49 #define IDS_PRT_12      "Printing failed"
50 #define IDS_PRT_13      "Unsupported file"
51 #define IDS_PRT_14      "File related error"
52 #define IDS_PRT_15      "The output tray is almost full"
53 #define IDS_PRT_16      "The output tray is full"
54 #define IDS_PRT_17      "Printer supply low"
55 #define IDS_PRT_18      "Printer supply empty"
56 #define IDS_PRT_19      "Device failure"
57 #define IDS_PRT_20      "No ink"
58 #define IDS_PRT_21      "No ink cartridge"
59 #define IDS_PRT_22      "The printer catridge is running low"
60 #define IDS_PRT_23      "Ink cover open"
61 #define IDS_PRT_24      "Ink related error"
62 #define IDS_PRT_25      "The paper tray is empty"
63 #define IDS_PRT_26      "The paper tray is running low"
64 #define IDS_PRT_27      "Paper jam"
65 #define IDS_PRT_28      "The paper size or type is incorrect"
66 #define IDS_PRT_29      "Paper loading error occurred"
67 #define IDS_PRT_30      "Paper related error occurred"
68 #define IDS_PRT_31      "Printer cover open"
69 #define IDS_PRT_32      "Printer hardware error occurred"
70 #define IDS_PRT_33      "Paper level error"
71 #define IDS_PRT_34      "No print head"
72 #define IDS_PRT_35      "Printer related error occurred"
73 #define IDS_PRT_41      "Failed to launch mobileprint"
74
75 #define IDS_BR_OPT_5X7  "5\"x7\"(13x18cm)"
76 #define IDS_BR_OPT_4X6  "4\"x6\"(10x15cm)"
77 #define IDS_BR_OPT_3_5X5        "3.5\"x5\"(9x13cm)"
78 #define IDS_BR_OPT_WALLET       "Wallet(6.4x8.4cm)"
79
80
81 #define IDS_PRT_GET_ATTRS_FOR_PRINTERS "Getting printer attributes..."
82 #define IDS_ASEML_POP_GET_ATTRS_FAILED "Failed to get printer attributes"
83
84 #define IDS_SCRREAD_CANCEL_SEARCHING_PRINTERS "Double tap to cancel searching for printers"
85 #define IDS_SCRREAD_CONFIRM_SELECTED_PRINTER "Press to confirm selected printer"
86 #define IDS_SCRREAD_CANCEL_CONNECT_WIFI "Cancel connect to Wi-Fi network"
87 #define IDS_SCRREAD_SMPOS_SK3_CANCEL "Press to cancel printing"
88 #define IDS_SCRREAD_MORE_OPTIONS "More options"
89 #define IDS_SCRREAD_CANCEL_PRINTING "Double tap to cancel printing"
90 #define IDS_SCRREAD_MENU_INFO "More options"
91 #define IDS_SCRREAD_MENU_CONTEXT "Double click to access options menu"
92 #define IDS_SCRREAD_PRINTERS_LIST_IS_BELOW "Printers list is below"
93 #define IDS_SCRREAD_PRINT_CONTEXT "Double tap to send document to the printer"
94 #define IDS_SCRREAD_PREVIEW_IMAGE_TYPE "Preview of the document to be printed"
95 #define IDS_SCRREAD_PREVIEW_IMAGE_CONTEXT "Print button is below"
96 #define IDS_SCRREAD_EXPANDABLE_LIST_TYPE "Expandable list"
97 #define IDS_SCRREAD_EXPANDABLE_LIST_CONTEXT "Double tap to open list"
98 #define IDS_SCRREAD_SETTINS_ITEM_CONTEXT "Double tap to edit"
99 #define IDS_SCRREAD_PRINTER_ITEM_CONTEXT "Double tap to change selected printer"
100
101 #define SERVICE_LAUNCH_TYPE "LAUNCH_TYPE"
102 #define SERVICE_JOB_ID "JOB_ID"
103 #define SERVICE_FILES "FILES"
104 #define SERVICE_PAGE_COUNT "PAGE_COUNT"
105 #define LAUNCH_FROM_DUMMY_NOTI "launch_from_dummy_noti"
106 #define LAUNCH_FROM_PROGRESS_NOTI "launch_from_progress_noti"
107 #define SERVICE_PRINT_FILES_COUNT "service_print_files_count"
108 #define SERVICE_PRINT_FILES_CURRENT_INDEX "service_print_files_current_index"
109 #define SERVICE_PRINT_FILES_TYPE "service_print_files_type"
110 #define SERVICE_PRINT_FILES_FOLDER_NAME "service_print_files_folder_name"
111 #define SERVICE_PRINT_FILES_FILES_NAME "service_print_files_files_name"
112
113 #define ICON_PRINTER "/usr/apps/org.tizen.mobileprint/res/images/pt_default_printer.png"
114
115 #define UG_MAX_FILED_LEN        64
116 #define COPIES_MAX      99
117
118 #undef MIN
119 #define MIN(a,b)  ((((a)-(b))&0x80000000) >> 31)? (a) : (b)
120 #define PRINTER_LIST_POPUP_W            656
121 #define PRINTER_LIST_POPUP_H            880
122 #define PRINTER_LIST_POPUP_LN_W         720
123 #define PRINTER_LIST_POPUP_LN_H         480
124
125 #ifndef API
126 #define API __attribute__ ((visibility("default")))
127 #endif
128 #define _EDJ(obj) (Evas_Object *)elm_layout_edje_get(obj)
129
130 //#ifndef _
131 //#  define _(str) gettext(str)
132 //#endif
133
134 #ifndef N_
135 #  define gettext_noop(str) (str)
136 #  define N_(str) gettext_noop(str)
137 #endif
138
139 #ifndef S_
140 #  define S_(str) dgettext("sys_string", str)
141 #endif
142
143 #ifndef P_
144 #  define P_(str) dgettext(PACKAGE, str)
145 #endif
146
147 #ifndef U_
148 #  define U_(str) dgettext(UGNAME, str)
149 #endif
150
151 typedef enum {
152         PTS_SIZE_FIT_TO_PAPER,
153         PTS_SIZE_5X7,
154         PTS_SIZE_4X6,
155         PTS_SIZE_3_5X5,
156         PTS_SIZE_WALLET,
157         PTS_SIZE_CUSTOM,
158         PTS_SIZE_MAX,
159 } pts_image_size_e;
160
161 typedef enum {
162         PTS_SEARCH_INITIAL,             // Before launching preview, this printer search is triggered.
163         PTS_SEARCH_IN_PREVIEW,  // When USB Printer detected, this printer search is triggered
164         PTS_SEARCH_IN_SETTING,  // When ether USB Printer detected or printer search button is presed, this printer search is triggered
165 } pts_printer_search_state_e;
166
167 typedef struct {
168         char **selected_files;                                          /** selected print files*/
169         int from;                                                                       /** from print position, the first file equals 0 */
170         int to;                                                                         /** to print position*/
171         int total_pages;
172 } pts_range_t;
173
174 typedef struct {
175         char    *directory;
176         char    **request_files;
177         pts_range_t range;
178         int             num_of_files;
179         int             current_index;
180         char    *type;
181 } pts_printing_data_t;
182
183 typedef struct {
184         int                             job_id;
185         int                             noti_id;
186         notification_h  noti_handle;
187         int                             progress;
188         int                             page_printed;
189         pts_printing_data_t     pt_files;
190         char                    *input_file;
191         int                             n_up;
192         int                             copies;
193 } pts_job_spooling_t;
194
195 typedef void (*pts_printer_selection_done_cb)(void *userdata);
196
197 typedef struct {
198         Evas_Object             *root_win;
199         Evas_Object             *main_layout;
200         Evas_Object             *navi;
201         Evas_Object             *printer_layout;
202         Evas_Object             *printer_label;
203         Evas_Object             *more_btn;
204         Evas_Object             *print_btn;
205         Evas_Object             *ctxpopup;
206
207         /*
208          * popup
209          */
210         Evas_Object             *popup;
211         Evas_Object             *wifi_type_popup;
212         Evas_Object             *printer_list_popup;
213         Evas_Object             *printer_list_popup_box;
214         Evas_Coord              printer_list_popup_portrait_height;
215         Evas_Coord              printer_list_popup_landscape_height;
216         Evas_Object             *no_found_popup;
217         Evas_Object             *scaling_popup;
218         Evas_Object             *size_popup;
219         Evas_Object             *size_popup_box;
220         Evas_Coord              size_popup_portrait_height;
221         Evas_Coord              size_popup_landscape_height;
222         Evas_Object             *custom_popup;
223         Evas_Object             *custom_popup_box;
224         Evas_Coord              custom_popup_portrait_height;
225         Evas_Coord              custom_popup_landscape_height;
226
227         Evas_Object             *progressbar;
228         Evas_Object             *progress_layout;
229         Evas_Object             *progress_label;
230
231         /*
232          * image layout
233          */
234         Evas_Object             *img_layout;
235         /*
236          * main navi item
237          */
238         Elm_Object_Item *navi_it;
239
240         /* Print Search Type*/
241         pts_printer_search_state_e print_search_mode;
242         pts_printer_selection_done_cb selection_done_cb;
243         Evas_Object *print_search_popup_parent;
244         void *printer_search_user_data;
245
246         /* Setting option: Header-item */
247         Elm_Object_Item *printer_item;
248         Elm_Object_Item *header_separator_item;
249         Elm_Object_Item *item_paper_size;
250         Elm_Object_Item *item_paper_copies;
251         Elm_Object_Item *item_paper_quality;
252         Elm_Object_Item *item_paper_type;
253         Elm_Object_Item *item_page_range;
254         Elm_Object_Item *item_grayscale;
255         Elm_Object_Item *footer_separator_item;
256
257         /* Settings: subitems */
258         Elm_Object_Item **paper_size;
259         Elm_Object_Item *quality[PT_QUALITY_ANY];
260         Elm_Object_Item *paper_type[PT_PAPER_ANY];
261         Elm_Object_Item *color[PT_GRAYSCALE_ANY];
262
263         /* Setting option: Radio Group Leader */
264         Evas_Object *radio_group_paper_size;
265         Evas_Object *radio_group_paper_quality;
266         Evas_Object *radio_group_paper_type;
267         Evas_Object *radio_group_page_range;
268         Evas_Object *radio_group_grayscale;
269
270         char *input_file; /* initial input file */
271         pts_printing_data_t     pt_files;
272         /*
273          * wifi, usb, all connection
274          */
275         //int                           connect_type;
276         /*
277          * sweep image
278          */
279         Evas_Coord              cur_x;
280         pt_printer_mgr_t        *active_printer;
281         pt_printer_mgr_t        *select_printer;
282
283         int                                     dummy_noti_id;
284         Eina_List                       *job_spooling_list;
285
286         Evas_Object *smsc;
287
288         int                     landscape_toggle;
289
290         /* whether in process(searching, printing) */
291         int                     is_process;
292
293         pts_image_size_e        image_size;
294
295         double          custom_width;
296         double          custom_height;
297         double          custom_w_ratio;
298         int                     custom_unit; // 1:cm 2:inch
299 } pts_core_data_t;
300
301 typedef struct {
302         Evas_Object                     *popup;
303         Eina_List                       *printer_list;
304
305         pts_core_data_t *ugd;
306
307         Ecore_Timer *search_err_timer;
308 } pts_ug_list_data;
309
310 typedef struct {
311         pts_core_data_t *ugd;
312
313         pt_print_option_e option; /* pts_print_option_type */
314         int sub_item;                           /* Individual item. It stores any type of options:
315                                                                         pt_paper_size_t, pt_range_t,
316                                                                         pt_grayscale_t, pt_quality_t,
317                                                                         pt_paper_t*/
318         int radio_index;
319
320         Elm_Object_Item *item;
321         Evas_Object *radio_btn;
322         Evas_Object *radio_group;
323 } Item_data;
324
325 /**
326  *      This function let the app create the label
327  *      @return  void
328  *      @param[in] parent the pointer to the parent of the label
329  *      @param[in] desc the pointer to label text
330  */
331 Evas_Object *pts_create_label_btn(Evas_Object *parent, const char *label);
332
333 /**
334  *      This function let the app create the base layout
335  *      @return  void
336  *      @param[in] parent the pointer to the parent of the base layout
337  *      @param[in] desc the pointer to group of the base layout
338  */
339 Evas_Object *pts_create_base_layout(Evas_Object *parent, const char *group);
340
341 /**
342  *      This function let the app create the base layout
343  *      @return  void
344  *      @param[in] parent the pointer to the parent of the base layout
345  *      @param[in] desc the pointer to group of the base layout
346  */
347 Evas_Object *pts_create_base_layout_with_conform(Evas_Object *parent, const char *group);
348
349 /**
350  *      This function let the app create the popup element
351  *      @return  void
352  *      @param[in] parent the pointer to the parent of the popup element
353  *      @param[in] desc the pointer to description of the popup element
354  *      @param[in] timeout the timeout value
355  */
356 Evas_Object *pts_create_popup(Evas_Object *parent, const char *desc, double timeout);
357 Evas_Object *pts_create_size_popup(Evas_Object *parent, pts_core_data_t *ugd);
358 Evas_Object *pts_create_scaling_popup(Evas_Object *parent, pts_core_data_t *ugd);
359 Evas_Object *pts_create_wifi_popup(Evas_Object *parent, pts_core_data_t *ugd);
360 void clear_preview_image(pts_core_data_t *ugd);
361 void pts_set_ugd(pts_core_data_t *ugd);
362 pts_core_data_t *pts_get_ugd(void);
363
364
365 int _pts_get_rotate_angle(enum appcore_rm rotate_mode);
366 void pts_search_printer(pts_core_data_t *ugd, Evas_Object *parent, pts_printer_search_state_e search_mode, pts_printer_selection_done_cb cb, void *userdata);
367 void pts_create_print_search_popup(Evas_Object *parent, pts_core_data_t *ugd);
368 Evas_Object *pts_utils_create_layout(Evas_Object *navi_frame);
369 void load_main_view(void *userdata);
370
371 inline char *_pts_printing_data_get_directory(pts_printing_data_t *data);
372 inline char **_pts_printing_data_get_request_files(pts_printing_data_t *data);
373 inline int _pts_printing_data_get_files_count(pts_printing_data_t *data);
374 inline int _pts_printing_data_get_index(pts_printing_data_t *data);
375 inline char *_pts_printing_data_get_type(pts_printing_data_t *data);
376 Eina_Bool _pts_printing_data_set_directory(const char *directory, pts_printing_data_t *data);
377 Eina_Bool _pts_printing_data_set_request_files(const char **request_files, const int files_count, pts_printing_data_t *data);
378 Eina_Bool _pts_printing_data_set_files_count(const char *num_of_files, pts_printing_data_t *data);
379 Eina_Bool _pts_printing_data_set_index(const char *current_index, pts_printing_data_t *data);
380 Eina_Bool _pts_printing_data_set_type(const char *type, pts_printing_data_t *data);
381
382 char *pts_parse_protocol(char *addr);
383 int pts_unstandardization(char *name);
384
385 #endif /* PTS_COMMON_H_ */
386