summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOlof-Joachim Frahm <Olof.Frahm@web.de>2011-10-02 00:14:00 +0200
committerOlof-Joachim Frahm <Olof.Frahm@web.de>2011-10-02 00:14:00 +0200
commit360f6e32b8e466d9a63b319269b3fc5734cdc58e (patch)
treed4161c4ac9a19e1809b72b55ddd88088fef9bfeb /src
parent0bab331e21a046a1ec775f188feadd300c9a57f8 (diff)
parentf55de5185347da52e7cd282491afdc7114418e50 (diff)
Merge remote-tracking branches 'derf/master' and 'origin/master'
Diffstat (limited to 'src')
-rw-r--r--src/filelist.c10
-rw-r--r--src/index.c206
-rw-r--r--src/index.h33
-rw-r--r--src/options.c31
-rw-r--r--src/options.h4
-rw-r--r--src/slideshow.c27
-rw-r--r--src/thumbnail.c180
7 files changed, 183 insertions, 308 deletions
diff --git a/src/filelist.c b/src/filelist.c
index 215f371..91b6b89 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -321,11 +321,11 @@ int feh_file_info_load(feh_file * file, Imlib_Image im)
if (im)
im1 = im;
- else if (!feh_load_image(&im1, file))
- return(1);
-
- if (!im1)
+ else if (!feh_load_image(&im1, file) || !im1) {
+ if (!opt.quiet)
+ weprintf("couldn't load %s", file->filename);
return(1);
+ }
file->info = feh_file_info_new();
@@ -340,7 +340,7 @@ int feh_file_info_load(feh_file * file, Imlib_Image im)
file->info->size = st.st_size;
- if (need_free && im1)
+ if (need_free)
gib_imlib_free_image_and_decache(im1);
return(0);
}
diff --git a/src/index.c b/src/index.c
index 897a47d..d9e068a 100644
--- a/src/index.c
+++ b/src/index.c
@@ -28,10 +28,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "filelist.h"
#include "winwidget.h"
#include "options.h"
+#include "index.h"
-static char *create_index_dimension_string(int w, int h);
-static char *create_index_size_string(char *file);
-static char *create_index_title_string(int num, int w, int h);
/* TODO Break this up a bit ;) */
/* TODO s/bit/lot */
@@ -51,17 +49,17 @@ void init_index_mode(void)
Imlib_Font title_fn = NULL;
int text_area_w = 0;
int tw = 0, th = 0;
- int fw_name, fw_size, fw_dim, fw, fh;
+ int fw, fh;
int vertical = 0;
int max_column_w = 0;
int thumbnailcount = 0;
gib_list *l = NULL, *last = NULL;
feh_file *file = NULL;
- int lines;
+ int lineno;
unsigned char trans_bg = 0;
int index_image_width, index_image_height;
- int x_offset_name = 0, x_offset_dim = 0, x_offset_size = 0;
char *s;
+ gib_list *line, *lines;
if (opt.montage) {
mode = "montage";
@@ -76,7 +74,6 @@ void init_index_mode(void)
fn = gib_imlib_load_font(DEFAULT_FONT);
if (opt.title_font) {
- int fh, fw;
title_fn = gib_imlib_load_font(opt.title_font);
if (!title_fn)
@@ -92,8 +89,9 @@ void init_index_mode(void)
/* Work out how tall the font is */
gib_imlib_get_text_size(fn, "W", NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT);
+ get_index_string_dim(NULL, fn, &fw, &fh);
/* For now, allow room for the right number of lines with small gaps */
- text_area_h = ((th + 2) * (opt.index_show_name + opt.index_show_size + opt.index_show_dim)) + 5;
+ text_area_h = fh + 5;
/* This includes the text area for index data */
tot_thumb_h = opt.thumb_h + text_area_h;
@@ -151,24 +149,14 @@ void init_index_mode(void)
for (l = filelist; l; l = l->next) {
file = FEH_FILE(l->data);
text_area_w = opt.thumb_w;
- if (opt.index_show_name) {
- gib_imlib_get_text_size(fn, file->name, NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > text_area_w)
- text_area_w = fw;
- }
- if (opt.index_show_dim) {
- gib_imlib_get_text_size(fn,
- create_index_dimension_string
- (1000, 1000), NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > text_area_w)
- text_area_w = fw;
- }
- if (opt.index_show_size) {
- gib_imlib_get_text_size(fn,
- create_index_size_string
- (file->filename), NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
+ if (opt.index_info) {
+ get_index_string_dim(file, fn, &fw, &fh);
if (fw > text_area_w)
text_area_w = fw;
+ if (fh > text_area_h) {
+ text_area_h = fh + 5;
+ tot_thumb_h = opt.thumb_h + text_area_h;
+ }
}
if (text_area_w > opt.thumb_w)
text_area_w += 5;
@@ -198,24 +186,14 @@ void init_index_mode(void)
file = FEH_FILE(l->data);
text_area_w = opt.thumb_w;
/* Calc width of text */
- if (opt.index_show_name) {
- gib_imlib_get_text_size(fn, file->name, NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > text_area_w)
- text_area_w = fw;
- }
- if (opt.index_show_dim) {
- gib_imlib_get_text_size(fn,
- create_index_dimension_string
- (1000, 1000), NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > text_area_w)
- text_area_w = fw;
- }
- if (opt.index_show_size) {
- gib_imlib_get_text_size(fn,
- create_index_size_string
- (file->filename), NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
+ if (opt.index_info) {
+ get_index_string_dim(file, fn, &fw, &fh);
if (fw > text_area_w)
text_area_w = fw;
+ if (fh > text_area_h) {
+ text_area_h = fh + 5;
+ tot_thumb_h = opt.thumb_h + text_area_h;
+ }
}
if (text_area_w > opt.thumb_w)
text_area_w += 5;
@@ -240,24 +218,14 @@ void init_index_mode(void)
for (l = filelist; l; l = l->next) {
file = FEH_FILE(l->data);
text_area_w = opt.thumb_w;
- if (opt.index_show_name) {
- gib_imlib_get_text_size(fn, file->name, NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > text_area_w)
- text_area_w = fw;
- }
- if (opt.index_show_dim) {
- gib_imlib_get_text_size(fn,
- create_index_dimension_string
- (1000, 1000), NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > text_area_w)
- text_area_w = fw;
- }
- if (opt.index_show_size) {
- gib_imlib_get_text_size(fn,
- create_index_size_string
- (file->filename), NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
+ if (opt.index_info) {
+ get_index_string_dim(file, fn, &fw, &fh);
if (fw > text_area_w)
text_area_w = fw;
+ if (fh > text_area_h) {
+ text_area_h = fh + 5;
+ tot_thumb_h = opt.thumb_h + text_area_h;
+ }
}
if (text_area_w > opt.thumb_w)
@@ -356,33 +324,14 @@ void init_index_mode(void)
text_area_w = opt.thumb_w;
/* Now draw on the info text */
- if (opt.index_show_name) {
- gib_imlib_get_text_size(fn, file->name, NULL, &fw_name, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw_name > text_area_w)
- text_area_w = fw_name;
- }
- if (opt.index_show_dim) {
- gib_imlib_get_text_size(fn,
- create_index_dimension_string
- (ww, hh), NULL, &fw_dim, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw_dim > text_area_w)
- text_area_w = fw_dim;
- }
- if (opt.index_show_size) {
- gib_imlib_get_text_size(fn,
- create_index_size_string
- (file->filename), NULL, &fw_size, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw_size > text_area_w)
- text_area_w = fw_size;
+ if (opt.index_info) {
+ get_index_string_dim(file, fn, &fw, &fh);
+ if (fw > text_area_w)
+ text_area_w = fw;
}
if (text_area_w > opt.thumb_w)
text_area_w += 5;
- /* offsets for centering text */
- x_offset_name = (text_area_w - fw_name) / 2;
- x_offset_dim = (text_area_w - fw_dim) / 2;
- x_offset_size = (text_area_w - fw_size) / 2;
-
if (vertical) {
if (text_area_w > max_column_w)
max_column_w = text_area_w;
@@ -418,29 +367,23 @@ void init_index_mode(void)
gib_imlib_free_image_and_decache(im_thumb);
- lines = 0;
- if (opt.index_show_name)
- gib_imlib_text_draw(im_main, fn, NULL,
- x + x_offset_name,
- y + opt.thumb_h +
- (lines++ * (th + 2)) +
- 2, file->name, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
- if (opt.index_show_dim)
- gib_imlib_text_draw(im_main, fn, NULL,
- x + x_offset_dim,
- y + opt.thumb_h +
- (lines++ * (th + 2)) +
- 2,
- create_index_dimension_string
- (ww, hh), IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
- if (opt.index_show_size)
- gib_imlib_text_draw(im_main, fn, NULL,
- x + x_offset_size,
- y + opt.thumb_h +
- (lines++ * (th + 2)) +
- 2,
- create_index_size_string
- (file->filename), IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
+ lineno = 0;
+ if (opt.index_info) {
+ line = lines = feh_wrap_string(create_index_string(file),
+ opt.thumb_w * 3, fn, NULL);
+
+ while (line) {
+ gib_imlib_get_text_size(fn, (char *) line->data,
+ NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
+ gib_imlib_text_draw(im_main, fn, NULL,
+ x + ((text_area_w - fw) >> 1),
+ y + opt.thumb_h + (lineno++ * (th + 2)) + 2,
+ (char *) line->data,
+ IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
+ line = line->next;
+ }
+ gib_list_free_and_data(lines);
+ }
if (vertical)
y += tot_thumb_h;
@@ -502,33 +445,54 @@ void init_index_mode(void)
return;
}
-static char *create_index_size_string(char *file)
+void get_index_string_dim(feh_file *file, Imlib_Font fn, int *fw, int *fh)
{
- static char str[50];
- int size = 0;
- double kbs = 0.0;
- struct stat st;
-
- if (stat(file, &st))
- kbs = 0.0;
- else {
- size = st.st_size;
- kbs = (double) size / 1000;
+ int line_w, line_h;
+ char fake_file = 0;
+ gib_list *line, *lines;
+ int max_w = 0, total_h = 0;
+
+ if (!opt.index_info)
+ return;
+
+ /* called with file = NULL in the setup phase.
+ * We need a fake file, otherwise feh_printf will remove format specifiers,
+ * leading e.g. to a 0x0 report for index_dim = "%n".
+ */
+ if (file == NULL) {
+ fake_file = 1;
+ file = feh_file_new("foo");
+ file->info = feh_file_info_new();
}
- snprintf(str, sizeof(str), "%.2fKb", kbs);
- return(str);
+ line = lines = feh_wrap_string(create_index_string(file), opt.thumb_w * 3, fn, NULL);
+
+ while (line) {
+ gib_imlib_get_text_size(fn, (char *) line->data,
+ NULL, &line_w, &line_h, IMLIB_TEXT_TO_RIGHT);
+
+ if (line_w > max_w)
+ max_w = line_w;
+ total_h += line_h + 2;
+
+ line = line->next;
+ }
+
+ gib_list_free_and_data(lines);
+ if (fake_file)
+ feh_file_free(file);
+
+ *fw = max_w;
+ *fh = total_h;
+ return;
}
-static char *create_index_dimension_string(int w, int h)
+char *create_index_string(feh_file * file)
{
- static char str[50];
-
- snprintf(str, sizeof(str), "%dx%d", w, h);
- return(str);
+ return feh_printf(opt.index_info, file);
}
-static char *create_index_title_string(int num, int w, int h)
+char *create_index_title_string(int num, int w, int h)
{
static char str[50];
diff --git a/src/index.h b/src/index.h
new file mode 100644
index 0000000..288b0ee
--- /dev/null
+++ b/src/index.h
@@ -0,0 +1,33 @@
+/* index.h
+
+Copyright (C) 2011 Daniel Friesel.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies of the Software and its documentation and acknowledgment shall be
+given in the documentation and software packages that this Software was
+used.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+*/
+
+#ifndef INDEX_H
+#define INDEX_H
+
+char *create_index_string(feh_file *file);
+char *create_index_title_string(int num, int w, int h);
+void get_index_string_dim(feh_file *file, Imlib_Font fn, int *w, int *h);
+
+#endif
diff --git a/src/options.c b/src/options.c
index 316f62d..1583eb8 100644
--- a/src/options.c
+++ b/src/options.c
@@ -374,6 +374,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
{"menu-style" , 1, 0, 204},
{"zoom" , 1, 0, 205},
{"no-screen-clip", 0, 0, 206},
+ {"index-info" , 1, 0, 207},
{"caption-path" , 1, 0, 'K'},
{"action1" , 1, 0, 209},
{"action2" , 1, 0, 210},
@@ -386,9 +387,6 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
{"action9" , 1, 0, 217},
{"bg-fill" , 0, 0, 218},
{"bg-max" , 0, 0, 219},
- {"index-name" , 1, 0, 230},
- {"index-size" , 1, 0, 231},
- {"index-dim" , 1, 0, 232},
{"thumb-redraw" , 1, 0, 'J'},
{"info" , 1, 0, 234},
{"force-aliasing", 0, 0, 235},
@@ -411,27 +409,20 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
break;
case 'm':
opt.index = 1;
- opt.index_show_name = 0;
- opt.index_show_size = 0;
- opt.index_show_dim = 0;
break;
case 'c':
opt.collage = 1;
break;
case 'i':
opt.index = 1;
- opt.index_show_name = 1;
- opt.index_show_size = 0;
- opt.index_show_dim = 0;
+ opt.index_info = estrdup("%n");
break;
case '.':
opt.scale_down = 1;
break;
case 'I':
opt.index = 1;
- opt.index_show_name = 1;
- opt.index_show_size = 1;
- opt.index_show_dim = 1;
+ opt.index_info = estrdup("%n\n%S\n%wx%h");
break;
case 'l':
opt.list = 1;
@@ -612,9 +603,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
break;
case 't':
opt.thumbs = 1;
- opt.index_show_name = 1;
- opt.index_show_size = 0;
- opt.index_show_dim = 0;
+ opt.index_info = estrdup("%n");
break;
case 'j':
opt.output_dir = estrdup(optarg);
@@ -650,6 +639,9 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
case 206:
opt.screen_clip = 0;
break;
+ case 207:
+ opt.index_info = estrdup(optarg);
+ break;
case 'K':
opt.caption_path = estrdup(optarg);
break;
@@ -701,15 +693,6 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
case 229:
opt.text_bg = TEXT_BG_TINTED;
break;
- case 230:
- opt.index_show_name = atoi(optarg);
- break;
- case 231:
- opt.index_show_size = atoi(optarg);
- break;
- case 232:
- opt.index_show_dim = atoi(optarg);
- break;
case 'J':
opt.thumb_redraw = atoi(optarg);
break;
diff --git a/src/options.h b/src/options.h
index f1fe3c4..4946927 100644
--- a/src/options.h
+++ b/src/options.h
@@ -32,9 +32,6 @@ struct __fehoptions {
unsigned char montage;
unsigned char collage;
unsigned char index;
- unsigned char index_show_name;
- unsigned char index_show_dim;
- unsigned char index_show_size;
unsigned char thumbs;
unsigned char slideshow;
unsigned char recursive;
@@ -89,6 +86,7 @@ struct __fehoptions {
char *caption_path;
char *start_list_at;
char *info_cmd;
+ char *index_info;
gib_style *menu_style_l;
diff --git a/src/slideshow.c b/src/slideshow.c
index e6ffb56..b9d9494 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -402,41 +402,38 @@ char *feh_printf(char *str, feh_file * file)
strcat(ret, file->name);
break;
case 'w':
- if (file) {
- if (!file->info)
- feh_file_info_load(file, NULL);
+ if (file && (file->info || !feh_file_info_load(file, NULL))) {
snprintf(buf, sizeof(buf), "%d", file->info->width);
strcat(ret, buf);
}
break;
case 'h':
- if (file) {
- if (!file->info)
- feh_file_info_load(file, NULL);
+ if (file && (file->info || !feh_file_info_load(file, NULL))) {
snprintf(buf, sizeof(buf), "%d", file->info->height);
strcat(ret, buf);
}
break;
case 's':
- if (file) {
- if (!file->info)
- feh_file_info_load(file, NULL);
+ if (file && (file->info || !feh_file_info_load(file, NULL))) {
snprintf(buf, sizeof(buf), "%d", file->info->size);
strcat(ret, buf);
}
break;
+ case 'S':
+ if (file && (file->info || !feh_file_info_load(file, NULL))) {
+ snprintf(buf, sizeof(buf),
+ "%.2fkB", ((double)file->info->size / 1000));
+ strcat(ret, buf);
+ }
+ break;
case 'p':
- if (file) {
- if (!file->info)
- feh_file_info_load(file, NULL);
+ if (file && (file->info || !feh_file_info_load(file, NULL))) {
snprintf(buf, sizeof(buf), "%d", file->info->pixels);
strcat(ret, buf);
}
break;
case 't':
- if (file) {
- if (!file->info)
- feh_file_info_load(file, NULL);
+ if (file && (file->info || !feh_file_info_load(file, NULL))) {
strcat(ret, file->info->format);
}
break;
diff --git a/src/thumbnail.c b/src/thumbnail.c
index 033fd85..42e2a82 100644
--- a/src/thumbnail.c
+++ b/src/thumbnail.c
@@ -31,10 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "thumbnail.h"
#include "md5.h"
#include "feh_png.h"
+#include "index.h"
-static char *create_index_dimension_string(int w, int h);
-static char *create_index_size_string(char *file);
-static char *create_index_title_string(int num, int w, int h);
static gib_list *thumbnails = NULL;
static thumbmode_data td;
@@ -65,15 +63,15 @@ void init_thumbnail_mode(void)
unsigned char trans_bg = 0;
int title_area_h = 0;
int tw = 0, th = 0;
- int fw_name, fw_size, fw_dim, fh;
+ int fw, fh;
int thumbnailcount = 0;
feh_file *file = NULL;
gib_list *l, *last = NULL;
- int lines;
+ int lineno;
int index_image_width, index_image_height;
- int x_offset_name = 0, x_offset_dim = 0, x_offset_size = 0;
char *s;
unsigned int thumb_counter = 0;
+ gib_list *line, *lines;
/* initialize thumbnail mode data */
td.im_main = NULL;
@@ -119,9 +117,8 @@ void init_thumbnail_mode(void)
/* Work out how tall the font is */
gib_imlib_get_text_size(td.font_main, "W", NULL, &tw, &th,
IMLIB_TEXT_TO_RIGHT);
- /* For now, allow room for the right number of lines with small gaps */
- td.text_area_h = ((th + 2) * (opt.index_show_name + opt.index_show_size +
- opt.index_show_dim)) + 5;
+ get_index_string_dim(NULL, td.font_main, &fw, &fh);
+ td.text_area_h = fh + 5;
/* This includes the text area for index data */
td.thumb_tot_h = opt.thumb_h + td.text_area_h;
@@ -264,34 +261,18 @@ void init_thumbnail_mode(void)
td.text_area_w = opt.thumb_w;
/* Now draw on the info text */
- if (opt.index_show_name) {
- gib_imlib_get_text_size(td.font_main, file->name, NULL,
- &fw_name, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw_name > td.text_area_w)
- td.text_area_w = fw_name;
- }
- if (opt.index_show_dim) {
- gib_imlib_get_text_size(td.font_main,
- create_index_dimension_string(ww, hh),
- NULL, &fw_dim, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw_dim > td.text_area_w)
- td.text_area_w = fw_dim;
- }
- if (opt.index_show_size) {
- gib_imlib_get_text_size(td.font_main,
- create_index_size_string(file->filename),
- NULL, &fw_size, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw_size > td.text_area_w)
- td.text_area_w = fw_size;
+ if (opt.index_info) {
+ get_index_string_dim(file, td.font_main, &fw, &fh);
+ if (fw > td.text_area_w)
+ td.text_area_w = fw;
+ if (fh > td.text_area_h) {
+ td.text_area_h = fh + 5;
+ td.thumb_tot_h = opt.thumb_h + td.text_area_h;
+ }
}
if (td.text_area_w > opt.thumb_w)
td.text_area_w += 5;
- /* offsets for centering text */
- x_offset_name = (td.text_area_w - fw_name) / 2;
- x_offset_dim = (td.text_area_w - fw_dim) / 2;
- x_offset_size = (td.text_area_w - fw_size) / 2;
-
if (td.vertical) {
if (td.text_area_w > td.max_column_w)
td.max_column_w = td.text_area_w;
@@ -332,28 +313,23 @@ void init_thumbnail_mode(void)
gib_imlib_free_image_and_decache(im_thumb);
- lines = 0;
- if (opt.index_show_name)
- gib_imlib_text_draw(td.im_main,
- td.font_main, NULL,
- x + x_offset_name,
- y + opt.thumb_h + (lines++ * (th + 2)) + 2,
- file->name, IMLIB_TEXT_TO_RIGHT,
- 255, 255, 255, 255);
- if (opt.index_show_dim)
- gib_imlib_text_draw(td.im_main,
- td.font_main, NULL,
- x + x_offset_dim,
- y + opt.thumb_h + (lines++ * (th + 2)) + 2,
- create_index_dimension_string(orig_w, orig_h),
- IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
- if (opt.index_show_size)
- gib_imlib_text_draw(td.im_main,
- td.font_main, NULL,
- x + x_offset_size,
- y + opt.thumb_h + (lines++ * (th + 2)) + 2,
- create_index_size_string(file->filename),
- IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
+ lineno = 0;
+ if (opt.index_info) {
+ line = lines = feh_wrap_string(create_index_string(file),
+ opt.thumb_w * 3, td.font_main, NULL);
+
+ while (line) {
+ gib_imlib_get_text_size(td.font_main, (char *) line -> data,
+ NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
+ gib_imlib_text_draw(td.im_main, td.font_main, NULL,
+ x + ((td.text_area_w - fw) >> 1),
+ y + opt.thumb_h + (lineno++ * (th + 2)) + 2,
+ (char *) line->data,
+ IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
+ line = line->next;
+ }
+ gib_list_free_and_data(lines);
+ }
if (td.vertical)
y += td.thumb_tot_h;
@@ -424,40 +400,6 @@ void init_thumbnail_mode(void)
return;
}
-static char *create_index_size_string(char *file)
-{
- static char str[50];
- int size = 0;
- double kbs = 0.0;
- struct stat st;
-
- if (stat(file, &st))
- kbs = 0.0;
- else {
- size = st.st_size;
- kbs = (double) size / 1000;
- }
-
- snprintf(str, sizeof(str), "%.2fKb", kbs);
- return(str);
-}
-
-static char *create_index_dimension_string(int w, int h)
-{
- static char str[50];
-
- snprintf(str, sizeof(str), "%dx%d", w, h);
- return(str);
-}
-
-static char *create_index_title_string(int num, int w, int h)
-{
- static char str[50];
-
- snprintf(str, sizeof(str), PACKAGE " index - %d thumbnails, %d by %d pixels", num, w, h);
- return(str);
-}
-
feh_thumbnail *feh_thumbnail_new(feh_file * file, int x, int y, int w, int h)
{
feh_thumbnail *thumb;
@@ -606,23 +548,8 @@ void feh_thumbnail_calculate_geometry(void)
for (l = filelist; l; l = l->next) {
file = FEH_FILE(l->data);
td.text_area_w = opt.thumb_w;
- if (opt.index_show_name) {
- gib_imlib_get_text_size(td.font_main, file->name, NULL,
- &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > td.text_area_w)
- td.text_area_w = fw;
- }
- if (opt.index_show_dim) {
- gib_imlib_get_text_size(td.font_main,
- create_index_dimension_string(1000, 1000),
- NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > td.text_area_w)
- td.text_area_w = fw;
- }
- if (opt.index_show_size) {
- gib_imlib_get_text_size(td.font_main,
- create_index_size_string(file->filename),
- NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
+ if (opt.index_info) {
+ get_index_string_dim(file, td.font_main, &fw, &fh);
if (fw > td.text_area_w)
td.text_area_w = fw;
}
@@ -654,23 +581,8 @@ void feh_thumbnail_calculate_geometry(void)
file = FEH_FILE(l->data);
td.text_area_w = opt.thumb_w;
/* Calc width of text */
- if (opt.index_show_name) {
- gib_imlib_get_text_size(td.font_main, file->name, NULL,
- &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > td.text_area_w)
- td.text_area_w = fw;
- }
- if (opt.index_show_dim) {
- gib_imlib_get_text_size(td.font_main,
- create_index_dimension_string(1000, 1000),
- NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > td.text_area_w)
- td.text_area_w = fw;
- }
- if (opt.index_show_size) {
- gib_imlib_get_text_size(td.font_main,
- create_index_size_string(file->filename),
- NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
+ if (opt.index_info) {
+ get_index_string_dim(file, td.font_main, &fw, &fh);
if (fw > td.text_area_w)
td.text_area_w = fw;
}
@@ -697,23 +609,8 @@ void feh_thumbnail_calculate_geometry(void)
for (l = filelist; l; l = l->next) {
file = FEH_FILE(l->data);
td.text_area_w = opt.thumb_w;
- if (opt.index_show_name) {
- gib_imlib_get_text_size(td.font_main, file->name, NULL,
- &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > td.text_area_w)
- td.text_area_w = fw;
- }
- if (opt.index_show_dim) {
- gib_imlib_get_text_size(td.font_main,
- create_index_dimension_string(1000, 1000),
- NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
- if (fw > td.text_area_w)
- td.text_area_w = fw;
- }
- if (opt.index_show_size) {
- gib_imlib_get_text_size(td.font_main,
- create_index_size_string(file->filename),
- NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT);
+ if (opt.index_info) {
+ get_index_string_dim(file, td.font_main, &fw, &fh);
if (fw > td.text_area_w)
td.text_area_w = fw;
}
@@ -1035,11 +932,14 @@ int feh_thumbnail_setup_thumbnail_dir(void)
weprintf("unable to create %s directory", dir_thumbnails);
}
+ free(dir_thumbnails);
+
if (mkdir(dir, 0700) == -1)
weprintf("unable to create %s directory", dir);
else
status = 1;
}
+ free(dir);
}
return status;