summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Michael <cpmichael1@comcast.net>2011-10-27 17:35:10 +0000
committerChristopher Michael <cpmichael1@comcast.net>2011-10-27 17:35:10 +0000
commitc77c08ac9b347e42cc021ffeeb2a7cafdd031656 (patch)
treedc9037ad7e18e89aead2afd57bb8895a0364a700
parent2cc8d415191a30bf726b02ece280effd1fa3e297 (diff)
Emprint: Fix for Cliff ;) so that you can get numbered screenshots via
the Screenshot module, or Emprint cli. Basically, you just use '%N' in the filename (screenshot%N.png, etc, etc). SVN revision: 64438
-rw-r--r--src/bin/main.c193
1 files changed, 104 insertions, 89 deletions
diff --git a/src/bin/main.c b/src/bin/main.c
index a6cf62b..f0f8d1e 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -47,6 +47,7 @@ static void _em_band_hide(void);
47static void _em_band_resize(int w, int h); 47static void _em_band_resize(int w, int h);
48static void _em_grab_region_end(void); 48static void _em_grab_region_end(void);
49static void _em_do_app(void); 49static void _em_do_app(void);
50static int _em_get_filecount(const char *filename);
50 51
51/* Global Variables */ 52/* Global Variables */
52static Options *opts = NULL; 53static Options *opts = NULL;
@@ -236,7 +237,7 @@ _em_print_help(void)
236 ); 237 );
237 238
238 _em_free_options(); 239 _em_free_options();
239 exit(EXIT_FAILURE); 240 exit(EXIT_SUCCESS);
240} 241}
241 242
242static void 243static void
@@ -262,13 +263,9 @@ _em_free_options(void)
262static void 263static void
263_em_get_filename(void) 264_em_get_filename(void)
264{ 265{
265 Eina_List *fl = NULL;
266 char *dir = NULL, *ext = NULL, *file = NULL;
267 const char *f;
268 char buf[256]; 266 char buf[256];
269 struct tm *loctime; 267 struct tm *loctime;
270 time_t t; 268 time_t t;
271 int c = 0;
272 269
273 /* get the current time in local format */ 270 /* get the current time in local format */
274 t = time(NULL); 271 t = time(NULL);
@@ -282,78 +279,55 @@ _em_get_filename(void)
282 if (ecore_file_is_dir(opts->filename)) 279 if (ecore_file_is_dir(opts->filename))
283 { 280 {
284 strftime(buf, sizeof(buf), "%Y-%m-%d-%H%M%S.png", loctime); 281 strftime(buf, sizeof(buf), "%Y-%m-%d-%H%M%S.png", loctime);
285 /* set the new filename */
286 snprintf(buf, sizeof(buf), "%s/%s", opts->filename, strdup(buf)); 282 snprintf(buf, sizeof(buf), "%s/%s", opts->filename, strdup(buf));
287 eina_stringshare_replace(&opts->filename, buf);
288 return;
289 } 283 }
290 else 284 else
291 { 285 {
286 char *filename = NULL;
287 const char *file = NULL, *dir = NULL;
288 char *ext = NULL, *p = NULL;
289
290 filename = strdup(opts->filename);
291
292 dir = ecore_file_dir_get(filename);
293 file = ecore_file_file_get(filename);
294
295 if ((dir) && (file))
296 {
297 if (!strcmp(dir, file)) dir = getenv("PWD");
298 }
299 else if (!dir)
300 dir = getenv("PWD");
301
302 /* strip the extension for searches */
303 ext = strrchr(file, '.');
304 if (!ext) ext = strdup(".png");
305
306 /* strip any %N out of filename */
307 p = strrchr(file, '%');
308 if (p) *p = 0;
309
292 /* filename was given, check for '%' signs to 310 /* filename was given, check for '%' signs to
293 * format based on strftime */ 311 * format based on strftime or file count */
294 if (strstr(opts->filename, "%")) 312 if ((strstr(opts->filename, "%")) &&
313 (!strstr(opts->filename, "%N")))
295 strftime(buf, sizeof(buf), opts->filename, loctime); 314 strftime(buf, sizeof(buf), opts->filename, loctime);
296 else 315 else if (strstr(opts->filename, "%N"))
297 { 316 {
298 /* no '%' signs, check for files existing in the directory */ 317 int c = 0;
299 if (ecore_file_exists(opts->filename)) 318
300 { 319 c = _em_get_filecount(filename);
301 /* get the directory */ 320
302 dir = ecore_file_dir_get(opts->filename); 321 if (c > 0)
303 322 snprintf(buf, sizeof(buf), "%s/%s%i%s", dir, file, c, ext);
304 /* get the filename */ 323 else
305 f = ecore_file_file_get(opts->filename); 324 snprintf(buf, sizeof(buf), "%s/%s%s", dir, file, ext);
306 325 }
307 /* if these two match, then no dir was passed in, 326 else
308 * use current dir */ 327 snprintf(buf, sizeof(buf), "%s/%s%s", dir, file, ext);
309 if (!strcmp(dir, f)) dir = getenv("PWD");
310
311 /* strip the extension for searches */
312 ext = ecore_file_strip_ext(opts->filename);
313
314 /* list files in this directory & count them */
315 fl = ecore_file_ls(dir);
316 EINA_LIST_FREE(fl, file)
317 {
318 /* skip "thumb" files in the count */
319 if (strstr(file, "thumb")) continue;
320 if (strstr(file, ext)) c++;
321 free(file);
322 }
323
324 /* strip the extension from filename */
325 file = ecore_file_strip_ext(opts->filename);
326
327 /* get the actual extension */
328 ext = strrchr(opts->filename, '.');
329 if (!ext) ext = strdup(".png");
330
331 if (c > 0)
332 {
333 c++;
334 /* assemble new filename */
335 snprintf(buf, sizeof(buf), "%s%i%s", file, c, ext);
336 }
337 else
338 {
339 /* assemble new filename */
340 snprintf(buf, sizeof(buf), "%s%s", file, ext);
341 }
342 }
343 else
344 {
345 /* strip the extension from filename */
346 file = ecore_file_strip_ext(opts->filename);
347
348 ext = strrchr(opts->filename, '.');
349 if (!ext) ext = strdup(".png");
350
351 /* assemble new filename */
352 snprintf(buf, sizeof(buf), "%s%s", file, ext);
353 }
354 }
355 } 328 }
356 } 329 }
330
357 /* set the new filename */ 331 /* set the new filename */
358 eina_stringshare_replace(&opts->filename, buf); 332 eina_stringshare_replace(&opts->filename, buf);
359} 333}
@@ -535,29 +509,27 @@ _em_do_thumb(const char *filename)
535 evas_damage_rectangle_add(sub_evas, 0, 0, tw, th); 509 evas_damage_rectangle_add(sub_evas, 0, 0, tw, th);
536 evas_render(sub_evas); 510 evas_render(sub_evas);
537 511
512 /* check for user-supplied thumbnail filename */
513 if (!opts->thumb.filename)
538 { 514 {
539 /* check for user-supplied thumbnail filename */ 515 /* no thumbname filename supplied, create one */
540 if (!opts->thumb.filename) 516 ext = ecore_file_strip_ext(opts->filename);
541 { 517 snprintf(buf, sizeof(buf), "%s-thumb", ext);
542 /* no thumbname filename supplied, create one */ 518
543 ext = ecore_file_strip_ext(opts->filename); 519 /* check for extension */
544 snprintf(buf, sizeof(buf), "%s-thumb", ext); 520 ext = strrchr(opts->filename, '.');
545 521 if (ext)
546 /* check for extension */ 522 snprintf(buf, sizeof(buf), "%s%s", strdup(buf), ext);
547 ext = strrchr(opts->filename, '.'); 523 else
548 if (ext) 524 snprintf(buf, sizeof(buf), "%s.png", strdup(buf));
549 snprintf(buf, sizeof(buf), "%s%s", strdup(buf), ext); 525 opts->thumb.filename = eina_stringshare_add(buf);
550 else
551 snprintf(buf, sizeof(buf), "%s.png", strdup(buf));
552 opts->thumb.filename = eina_stringshare_add(buf);
553 }
554
555 /* actually save the thumbnail */
556 snprintf(buf, sizeof(buf), "quality=%d compress=9", opts->quality);
557 if (!(evas_object_image_save(tmp, opts->thumb.filename, NULL, buf)))
558 printf("Error saving thumbnail: %s\n", opts->thumb.filename);
559 } 526 }
560 527
528 /* actually save the thumbnail */
529 snprintf(buf, sizeof(buf), "quality=%d compress=9", opts->quality);
530 if (!(evas_object_image_save(tmp, opts->thumb.filename, NULL, buf)))
531 printf("Error saving thumbnail: %s\n", opts->thumb.filename);
532
561 if (tmp) evas_object_del(tmp); 533 if (tmp) evas_object_del(tmp);
562 if (img) evas_object_del(img); 534 if (img) evas_object_del(img);
563 if (sub_ee) ecore_evas_free(sub_ee); 535 if (sub_ee) ecore_evas_free(sub_ee);
@@ -908,3 +880,46 @@ _em_do_app(void)
908 exe = ecore_exe_run(buf, NULL); 880 exe = ecore_exe_run(buf, NULL);
909 if (exe) ecore_exe_free(exe); 881 if (exe) ecore_exe_free(exe);
910} 882}
883
884static int
885_em_get_filecount(const char *filename)
886{
887 Eina_List *fl = NULL;
888 char *dir = NULL, *ext = NULL;
889 char *p = NULL, *f = NULL;
890 const char *file = NULL;
891 int c = 0;
892
893 /* grab dir and file */
894 dir = ecore_file_dir_get(filename);
895 file = ecore_file_file_get(filename);
896 if ((dir) && (file))
897 {
898 if (!strcmp(dir, file)) dir = getenv("PWD");
899 }
900 else if (!dir)
901 dir = getenv("PWD");
902
903 /* strip the extension for searches */
904 ext = strrchr(file, '.');
905 if (!ext) ext = strdup(".png");
906
907 /* strip any %N out of filename */
908 p = strrchr(file, '%');
909 if (p) *p = 0;
910
911 fl = ecore_file_ls(dir);
912 EINA_LIST_FREE(fl, f)
913 {
914 if (!strstr(f, ext)) continue;
915 if (strncmp(f, file, strlen(file)) >= 0)
916 {
917 if (strstr(f, "thumb")) continue;
918 if (strstr(f, ext)) c++;
919 }
920
921 free(f);
922 }
923
924 return c;
925}