Initialize Tizen 2.3
[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.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 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_REFRESH_SEARCHING_PRINTERS "Press to refresh searching for printers"
87 #define IDS_SCRREAD_CANCEL_CONNECT_WIFI "Cancel connect to Wi-Fi network"
88 #define IDS_SCRREAD_SMPOS_SK3_CANCEL "Press to cancel printing"
89 #define IDS_SCRREAD_MORE_OPTIONS "More options"
90 #define IDS_SCRREAD_CANCEL_PRINTING "Double tap to cancel printing"
91 #define IDS_SCRREAD_MENU_INFO "More options"
92 #define IDS_SCRREAD_MENU_CONTEXT "Double click to access options menu"
93 #define IDS_SCRREAD_PRINTERS_LIST_IS_BELOW "Printers list is below"
94 #define IDS_SCRREAD_PRINT_CONTEXT "Double tap to send document to the printer"
95 #define IDS_SCRREAD_PREVIEW_IMAGE_TYPE "Preview of the document to be printed"
96 #define IDS_SCRREAD_PREVIEW_IMAGE_CONTEXT "Print button is below"
97 #define IDS_SCRREAD_EXPANDABLE_LIST_TYPE "Expandable list"
98 #define IDS_SCRREAD_EXPANDABLE_LIST_CONTEXT "Double tap to open list"
99 #define IDS_SCRREAD_SETTINS_ITEM_CONTEXT "Double tap to edit"
100 #define IDS_SCRREAD_PRINTER_ITEM_CONTEXT "Double tap to change selected printer"
101
102 #define SERVICE_LAUNCH_TYPE "LAUNCH_TYPE"
103 #define SERVICE_JOB_ID "JOB_ID"
104 #define SERVICE_FILES "FILES"
105 #define SERVICE_PAGE_COUNT "PAGE_COUNT"
106 #define LAUNCH_FROM_DUMMY_NOTI "launch_from_dummy_noti"
107 #define LAUNCH_FROM_PROGRESS_NOTI "launch_from_progress_noti"
108 #define SERVICE_PRINT_FILES_COUNT "service_print_files_count"
109 #define SERVICE_PRINT_FILES_CURRENT_INDEX "service_print_files_current_index"
110 #define SERVICE_PRINT_FILES_TYPE "service_print_files_type"
111 #define SERVICE_PRINT_FILES_FOLDER_NAME "service_print_files_folder_name"
112 #define SERVICE_PRINT_FILES_FILES_NAME "service_print_files_files_name"
113 #define IDS_PRINT_SETTINGS_DUPLEX "Duplex"
114 #define IDS_PRINT_SETTINGS_DUPLEX_OFF "One side"
115 #define IDS_PRINT_SETTINGS_DUPLEX_ON "Double side"
116
117 #define ICON_PRINTER "/usr/apps/org.tizen.mobileprint/res/images/pt_default_printer.png"
118
119 #define UG_MAX_FILED_LEN        64
120 #define COPIES_MAX      99
121
122 #undef MIN
123 #define MIN(a,b)  ((((a)-(b))&0x80000000) >> 31)? (a) : (b)
124 #define PRINTER_LIST_POPUP_W            400
125 #define PRINTER_LIST_POPUP_H            114
126 #define PRINTER_LIST_POPUP_LN_W         400
127 #define PRINTER_LIST_POPUP_LN_H         114
128
129 #ifndef API
130 #define API __attribute__ ((visibility("default")))
131 #endif
132 #define _EDJ(obj) (Evas_Object *)elm_layout_edje_get(obj)
133
134 //#ifndef _
135 //#  define _(str) gettext(str)
136 //#endif
137
138 #ifndef N_
139 #  define gettext_noop(str) (str)
140 #  define N_(str) gettext_noop(str)
141 #endif
142
143 #ifndef S_
144 #  define S_(str) dgettext("sys_string", str)
145 #endif
146
147 #ifndef P_
148 #  define P_(str) dgettext(PACKAGE, str)
149 #endif
150
151 #ifndef U_
152 #  define U_(str) dgettext(UGNAME, str)
153 #endif
154
155 typedef enum {
156         PTS_SIZE_FIT_TO_PAPER,
157         PTS_SIZE_5X7,
158         PTS_SIZE_4X6,
159         PTS_SIZE_3_5X5,
160         PTS_SIZE_WALLET,
161         PTS_SIZE_CUSTOM,
162         PTS_SIZE_MAX,
163 } pts_image_size_e;
164
165 typedef enum {
166         PTS_SEARCH_INITIAL,             // Before launching preview, this printer search is triggered.
167         PTS_SEARCH_IN_PREVIEW,  // When USB Printer detected, this printer search is triggered
168         PTS_SEARCH_IN_SETTING,  // When ether USB Printer detected or printer search button is presed, this printer search is triggered
169 } pts_printer_search_state_e;
170
171 typedef struct {
172         char **selected_files;                                          /** selected print files*/
173         int from;                                                                       /** from print position, the first file equals 0 */
174         int to;                                                                         /** to print position*/
175         int total_pages;
176 } pts_range_t;
177
178 typedef struct {
179         char    *directory;
180         char    **request_files;
181         pts_range_t range;
182         int     num_of_files;
183         int     current_index;
184         char    *type;
185
186         char *input_file;
187 } pts_printing_data_t;
188
189 typedef struct {
190         int                             job_id;
191         int                             noti_id;
192         notification_h  noti_handle;
193         int                             progress;
194         int                             page_printed;
195         pts_printing_data_t     pt_files;
196         char                    *input_file;
197         int                             n_up;
198         int                             copies;
199 } pts_job_spooling_t;
200
201 typedef void (*pts_printer_selection_done_cb)(void *userdata);
202
203 typedef struct {
204         pt_print_option_e option; /* pts_print_option_type */
205         int sub_item;                           /* Individual item. It stores any type of options:
206                                                                         pt_paper_size_t, pt_range_t,
207                                                                         pt_grayscale_t, pt_quality_t,
208                                                                         pt_paper_t*/
209         int radio_index;
210
211         Elm_Object_Item *item;
212         Evas_Object *radio_btn;
213         Evas_Object *radio_group;
214 } Item_data;
215
216 typedef struct
217 {
218         Evas_Object             *root_win;
219         Evas_Object             *main_layout;
220         Evas_Object             *navi;
221         Evas_Object             *printer_layout;
222         Evas_Object             *printer_label;
223         Evas_Object             *more_btn;
224         Evas_Object             *print_btn;
225
226         /*
227          * image layout
228          */
229         Evas_Object             *img_layout;
230
231         /*
232          * sweep image
233          */
234         Evas_Object             *smsc;
235         int                     landscape_toggle;
236
237         /*
238          * main navi item
239          */
240         Elm_Object_Item *navi_it;
241 } pts_main_info_t;
242
243 typedef struct
244 {
245         Evas_Object             *ctxpopup;
246
247         /* Setting option: Header-item */
248         Elm_Object_Item *printer_item;
249         Elm_Object_Item *header_separator_item;
250         Elm_Object_Item *item_paper_size;
251         Elm_Object_Item *item_paper_copies;
252         Elm_Object_Item *item_paper_quality;
253         Elm_Object_Item *item_paper_type;
254         Elm_Object_Item *item_page_range;
255         Elm_Object_Item *item_grayscale;
256         Elm_Object_Item *item_duplex;
257         Elm_Object_Item *footer_separator_item;
258
259         /* Settings: subitems */
260         Elm_Object_Item **paper_size;
261         Elm_Object_Item *quality[PT_QUALITY_ANY];
262         Elm_Object_Item *paper_type[PT_PAPER_ANY];
263         Elm_Object_Item *color[PT_GRAYSCALE_ANY];
264         Elm_Object_Item *duplex[PT_DUPLEX_ANY];
265
266         /* Setting option: Radio Group Leader */
267         Evas_Object *radio_group_paper_size;
268         Evas_Object *radio_group_paper_quality;
269         Evas_Object *radio_group_paper_type;
270         Evas_Object *radio_group_page_range;
271         Evas_Object *radio_group_grayscale;
272         Evas_Object *radio_group_duplex;
273 } pts_setting_info_t;
274
275 typedef struct
276 {
277         Evas_Object             *printer_list_popup;
278         Evas_Object             *printer_list_popup_box;
279         Evas_Coord              printer_list_popup_portrait_height;
280         Evas_Coord              printer_list_popup_landscape_height;
281         Evas_Object             *no_found_popup;
282         pt_printer_mgr_t        *select_printer;
283         pt_printer_mgr_t        *active_printer;
284
285         /*from pts_ug_list_data*/
286
287         Eina_List                       *printer_list;
288
289 } pts_list_info_t;
290
291 typedef struct
292 {
293         Evas_Object             *popup;
294         Evas_Object             *progressbar;
295         Evas_Object             *progress_layout;
296         Evas_Object             *progress_label;
297 } pts_progress_info_t;
298
299 typedef struct
300 {
301         /* Print Search Type*/
302         pts_printer_search_state_e print_search_mode;
303         pts_printer_selection_done_cb selection_done_cb;
304         Evas_Object *print_search_popup_parent;
305         void *printer_search_user_data;
306         char *ip_address;
307         /* whether in process(searching, printing) */
308         int                     is_process;
309
310         /*from pts_ug_list_data*/
311         Ecore_Timer *search_err_timer;
312         Evas_Object             *popup;
313
314 } pts_searching_info_t;
315
316 typedef struct
317 {
318         Evas_Object             *wifi_type_popup;
319 } pts_selector_info_t;
320
321 typedef struct
322 {
323         Evas_Object             *size_popup;
324         Evas_Object             *size_popup_box;
325         Evas_Coord              size_popup_portrait_height;
326         Evas_Coord              size_popup_landscape_height;
327         Evas_Object             *custom_popup;
328         Evas_Object             *custom_popup_box;
329         Evas_Coord              custom_popup_portrait_height;
330         Evas_Coord              custom_popup_landscape_height;
331         pts_image_size_e        image_size;
332
333         double          custom_width;
334         double          custom_height;
335         double          custom_w_ratio;
336         int                     custom_unit; // 1:cm 2:inch
337 } pts_size_popup_info_t;
338
339 typedef struct
340 {
341         Evas_Object             *scaling_popup;
342 } pts_scaling_popup_info_t;
343
344 typedef struct
345 {
346         int                             dummy_noti_id;
347         Eina_List                       *job_spooling_list; /*TODO : provide pt_get_job_count, pt_get_job_id ... as API in print-service*/
348
349 } pts_noti_info_t;
350
351 typedef struct appdata {
352         Evas_Object *win;
353         Ecore_Event_Handler *screen_reader_message_handler;
354
355         /* add more variables here */
356         int prev_app_win_rotate;
357
358         pts_main_info_t main_info;                                      /*Global variables about preview view*/
359         pts_setting_info_t setting_info;                                        /*Global variables about setting view*/
360         pts_list_info_t list_info;                                              /*Global variables about printer list popup*/
361         pts_progress_info_t progress_info;                              /*Global variables about progress popup*/
362         pts_searching_info_t search_info;
363         pts_selector_info_t select_info;                                        /*Global variables about wifi/p2p selet popup*/
364         pts_size_popup_info_t size_popup_info;                  /*Global variables about size popup*/
365         pts_scaling_popup_info_t scaling_popup_info;    /*Global variables about scaling popup*/
366         pts_noti_info_t noti_info;                                              /*Global variables about noti*/
367         pts_printing_data_t printing_data;
368
369 } pts_appdata_t;
370
371 /**
372  *      This function let the app create the label
373  *      @return  void
374  *      @param[in] parent the pointer to the parent of the label
375  *      @param[in] desc the pointer to label text
376  */
377 Evas_Object *pts_create_label_btn(Evas_Object *parent, const char *label);
378
379 /**
380  *      This function let the app create the base layout
381  *      @return  void
382  *      @param[in] parent the pointer to the parent of the base layout
383  *      @param[in] desc the pointer to group of the base layout
384  */
385 Evas_Object *pts_create_base_layout(Evas_Object *parent, const char *group);
386
387 /**
388  *      This function let the app create the base layout
389  *      @return  void
390  *      @param[in] parent the pointer to the parent of the base layout
391  *      @param[in] desc the pointer to group of the base layout
392  */
393 Evas_Object *pts_create_base_layout_with_conform(Evas_Object *parent, const char *group);
394
395 /**
396  *      This function let the app create the popup element
397  *      @return  void
398  *      @param[in] parent the pointer to the parent of the popup element
399  *      @param[in] desc the pointer to description of the popup element
400  *      @param[in] timeout the timeout value
401  */
402 Evas_Object *pts_create_popup(Evas_Object *parent, const char *desc, double timeout);
403 Evas_Object *pts_create_size_popup(Evas_Object *parent, pts_appdata_t *ad);
404 Evas_Object *pts_create_scaling_popup(Evas_Object *parent, pts_appdata_t *ad);
405 Evas_Object *pts_create_wifi_popup(Evas_Object *parent, pts_appdata_t *ad);
406 void clear_preview_image(pts_appdata_t *ad);
407 //void pts_set_ugd(pts_core_data_t *ugd);
408 //pts_core_data_t *pts_get_ugd(void);
409
410 int _pts_get_rotate_angle(enum appcore_rm rotate_mode);
411 void pts_search_printer(pts_appdata_t *ad);
412 Evas_Object *pts_create_print_search_popup(Evas_Object *parent);
413 Evas_Object *pts_utils_create_layout(Evas_Object *navi_frame);
414 void load_main_view(void *userdata);
415
416 inline char *_pts_printing_data_get_directory(pts_printing_data_t *data);
417 inline char **_pts_printing_data_get_request_files(pts_printing_data_t *data);
418 inline int _pts_printing_data_get_files_count(pts_printing_data_t *data);
419 inline int _pts_printing_data_get_index(pts_printing_data_t *data);
420 inline char *_pts_printing_data_get_type(pts_printing_data_t *data);
421 Eina_Bool _pts_printing_data_set_directory(const char *directory, pts_printing_data_t *data);
422 Eina_Bool _pts_printing_data_set_request_files(const char **request_files, const int files_count, pts_printing_data_t *data);
423 Eina_Bool _pts_printing_data_set_files_count(const char *num_of_files, pts_printing_data_t *data);
424 Eina_Bool _pts_printing_data_set_index(const char *current_index, pts_printing_data_t *data);
425 Eina_Bool _pts_printing_data_set_type(const char *type, pts_printing_data_t *data);
426
427 char *pts_parse_protocol(char *addr);
428 int pts_unstandardization(char *name);
429
430 #endif /* PTS_COMMON_H_ */
431