summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2014-09-24 16:12:38 +0100
committerTom Hacohen <tom@stosb.com>2014-09-24 16:12:38 +0100
commit7b8cf03c5f170f905a04ea40bf50b3c863af062f (patch)
tree6c3aa79f0b5dcab96364d64320c0ce1a877744c6
parent8235f7a7205ecd7dfa8ef4ee2d8e37d37f094e9d (diff)
Gather some pdf file info.
-rw-r--r--src/bin/main.c71
1 files changed, 49 insertions, 22 deletions
diff --git a/src/bin/main.c b/src/bin/main.c
index 454e6aa..129ae0e 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -24,6 +24,8 @@ typedef struct _Gifter_Context {
24 Gifter_Win main, preview; 24 Gifter_Win main, preview;
25 Eina_Stringshare *filename; 25 Eina_Stringshare *filename;
26 int page; 26 int page;
27 int num_pages;
28 double ratio;
27} Gifter_Context; 29} Gifter_Context;
28 30
29static Gifter_Context ctx; 31static Gifter_Context ctx;
@@ -93,19 +95,47 @@ _global_key_down_cb(void *data EINA_UNUSED, Eo *eo_obj EINA_UNUSED, const Eo_Eve
93} 95}
94 96
95static void 97static void
98_pdf_info_populate(void)
99{
100 int page = 0;
101 Evas_Image *img = eo_add(EVAS_IMAGE_CLASS, ctx.main.win);
102
103 /* FIXME: Naive search, should improve... Horrible slow hack.
104 * Should be done in the background... */
105 for (page = 0 ; ; page++)
106 {
107 eo_do(img, _pdf_page_set(page));
108 if (evas_object_image_load_error_get(img) != EVAS_LOAD_ERROR_NONE)
109 {
110 break;
111 }
112 }
113
114 ctx.num_pages = page - 1;
115
116 if (page > 0)
117 {
118 int w = 0, h = 0;
119 eo_do(img, _pdf_page_set(0),
120 evas_obj_image_size_get(&w, &h));
121 if (h > 0)
122 {
123 ctx.ratio = ((double) w) / h;
124 }
125 }
126
127 eo_unref(img);
128}
129
130static void
96_create_win(Gifter_Win *win, const char *group_name) 131_create_win(Gifter_Win *win, const char *group_name)
97{ 132{
98 Evas_Coord w = 600, h = 600;
99 Evas_Object *bg, *dummy_key; 133 Evas_Object *bg, *dummy_key;
100 char theme_filename[PATH_MAX]; 134 char theme_filename[PATH_MAX];
101 unsigned int i = 0; 135 unsigned int i = 0;
102 136
103 snprintf(theme_filename, sizeof(theme_filename), "%s/themes/default.edj", elm_app_data_dir_get()); 137 snprintf(theme_filename, sizeof(theme_filename), "%s/themes/default.edj", elm_app_data_dir_get());
104 138
105 w *= elm_config_scale_get();
106 h *= elm_config_scale_get();
107
108
109 win->win = elm_win_add(NULL, group_name, ELM_WIN_BASIC); 139 win->win = elm_win_add(NULL, group_name, ELM_WIN_BASIC);
110 eo_do(win->win, elm_obj_win_autodel_set(EINA_FALSE), 140 eo_do(win->win, elm_obj_win_autodel_set(EINA_FALSE),
111 elm_obj_win_title_set("Gifter")); 141 elm_obj_win_title_set("Gifter"));
@@ -114,7 +144,6 @@ _create_win(Gifter_Win *win, const char *group_name)
114 evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), 144 evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND),
115 evas_obj_visibility_set(EINA_TRUE)); 145 evas_obj_visibility_set(EINA_TRUE));
116 146
117 evas_object_resize(win->win, w, h);
118 elm_win_resize_object_add(win->win, bg); 147 elm_win_resize_object_add(win->win, bg);
119 eo_unref(bg); 148 eo_unref(bg);
120 149
@@ -135,20 +164,6 @@ _create_win(Gifter_Win *win, const char *group_name)
135 eo_unref(win->pdf[i]); 164 eo_unref(win->pdf[i]);
136 } 165 }
137 166
138 {
139 /* Update w/h according to aspect ratio. */
140 int tw = 0, th = 0;
141 eo_do(win->pdf[1], elm_obj_image_object_size_get(&tw, &th));
142
143 if (tw && th)
144 {
145 double ratio = ((double) th) / tw;
146 h = w * ratio;
147 }
148
149 evas_object_resize(win->win, w, h);
150 }
151
152 eo_do(win->layout, elm_obj_container_content_set("slide_prev", win->pdf[0])); 167 eo_do(win->layout, elm_obj_container_content_set("slide_prev", win->pdf[0]));
153 eo_do(win->layout, elm_obj_container_content_set("slide_cur", win->pdf[1])); 168 eo_do(win->layout, elm_obj_container_content_set("slide_cur", win->pdf[1]));
154 eo_do(win->layout, elm_obj_container_content_set("slide_next", win->pdf[2])); 169 eo_do(win->layout, elm_obj_container_content_set("slide_next", win->pdf[2]));
@@ -167,6 +182,7 @@ _create_win(Gifter_Win *win, const char *group_name)
167int 182int
168main(int argc, char *argv[]) 183main(int argc, char *argv[])
169{ 184{
185 Evas_Coord w = 600, h = 600;
170 int c; 186 int c;
171 187
172 opterr = 0; 188 opterr = 0;
@@ -217,7 +233,6 @@ main(int argc, char *argv[])
217 gifter_cfg_init(PACKAGE_NAME); 233 gifter_cfg_init(PACKAGE_NAME);
218 gifter_cfg_load(); 234 gifter_cfg_load();
219 235
220 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
221 elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); 236 elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
222 elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR); 237 elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR);
223 elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); 238 elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
@@ -228,12 +243,24 @@ main(int argc, char *argv[])
228 243
229 244
230 ctx.filename = eina_stringshare_add(argv[optind]); 245 ctx.filename = eina_stringshare_add(argv[optind]);
231
232 DBG("Opening filename: '%s'", ctx.filename); 246 DBG("Opening filename: '%s'", ctx.filename);
233 247
248 w *= elm_config_scale_get();
249 h *= elm_config_scale_get();
250
234 _create_win(&ctx.main, "main_win"); 251 _create_win(&ctx.main, "main_win");
235 _create_win(&ctx.preview, "preview_win"); 252 _create_win(&ctx.preview, "preview_win");
236 253
254 _pdf_info_populate();
255
256 if (ctx.ratio > 0)
257 {
258 h = w / ctx.ratio;
259 }
260
261 evas_object_resize(ctx.main.win, w, h);
262 evas_object_resize(ctx.preview.win, w, h);
263
237 elm_run(); 264 elm_run();
238 265
239 gifter_cfg_shutdown(); 266 gifter_cfg_shutdown();