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