Incorporate most clang-format changes

This commit is contained in:
Přemysl Eric Janouch 2021-11-01 04:59:38 +01:00
parent 810a1fee57
commit 6eecee6b91
Signed by: p
GPG Key ID: A0420B94F92B9493
7 changed files with 103 additions and 111 deletions

View File

@ -74,8 +74,8 @@ fastiv_browser_get_request_mode(G_GNUC_UNUSED GtkWidget *widget)
} }
static void static void
fastiv_browser_get_preferred_width(GtkWidget *widget, fastiv_browser_get_preferred_width(
gint *minimum, gint *natural) GtkWidget *widget, gint *minimum, gint *natural)
{ {
G_GNUC_UNUSED FastivBrowser *self = FASTIV_BROWSER(widget); G_GNUC_UNUSED FastivBrowser *self = FASTIV_BROWSER(widget);
// TODO(p): Set it to the width of the widget with one wide item within. // TODO(p): Set it to the width of the widget with one wide item within.
@ -83,8 +83,8 @@ fastiv_browser_get_preferred_width(GtkWidget *widget,
} }
static void static void
fastiv_browser_get_preferred_height_for_width(GtkWidget *widget, fastiv_browser_get_preferred_height_for_width(
G_GNUC_UNUSED gint width, gint *minimum, gint *natural) GtkWidget *widget, G_GNUC_UNUSED gint width, gint *minimum, gint *natural)
{ {
G_GNUC_UNUSED FastivBrowser *self = FASTIV_BROWSER(widget); G_GNUC_UNUSED FastivBrowser *self = FASTIV_BROWSER(widget);
// TODO(p): Re-layout, figure it out. // TODO(p): Re-layout, figure it out.
@ -99,18 +99,18 @@ fastiv_browser_realize(GtkWidget *widget)
GdkWindowAttr attributes = { GdkWindowAttr attributes = {
.window_type = GDK_WINDOW_CHILD, .window_type = GDK_WINDOW_CHILD,
.x = allocation.x, .x = allocation.x,
.y = allocation.y, .y = allocation.y,
.width = allocation.width, .width = allocation.width,
.height = allocation.height, .height = allocation.height,
// Input-only would presumably also work (as in GtkPathBar, e.g.), // Input-only would presumably also work (as in GtkPathBar, e.g.),
// but it merely seems to involve more work. // but it merely seems to involve more work.
.wclass = GDK_INPUT_OUTPUT, .wclass = GDK_INPUT_OUTPUT,
.visual = gtk_widget_get_visual(widget), .visual = gtk_widget_get_visual(widget),
.event_mask = gtk_widget_get_events(widget) .event_mask = gtk_widget_get_events(widget) | GDK_KEY_PRESS_MASK |
| GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK, GDK_BUTTON_PRESS_MASK,
}; };
// We need this window to receive input events at all. // We need this window to receive input events at all.
@ -131,8 +131,8 @@ fastiv_browser_draw(GtkWidget *widget, cairo_t *cr)
GtkAllocation allocation; GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation); gtk_widget_get_allocation(widget, &allocation);
gtk_render_background(gtk_widget_get_style_context(widget), cr, gtk_render_background(gtk_widget_get_style_context(widget), cr, 0, 0,
0, 0, allocation.width, allocation.height); allocation.width, allocation.height);
const double row_height = 256; const double row_height = 256;
@ -152,8 +152,8 @@ fastiv_browser_draw(GtkWidget *widget, cairo_t *cr)
int projected_width = round(scale * width); int projected_width = round(scale * width);
int projected_height = round(scale * height); int projected_height = round(scale * height);
if (occupied_width != 0 if (occupied_width != 0 &&
&& occupied_width + projected_width > allocation.width) { occupied_width + projected_width > allocation.width) {
occupied_width = 0; occupied_width = 0;
y += row_height; y += row_height;
} }
@ -178,17 +178,15 @@ fastiv_browser_class_init(FastivBrowserClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
widget_class->get_request_mode = fastiv_browser_get_request_mode; widget_class->get_request_mode = fastiv_browser_get_request_mode;
widget_class->get_preferred_width = widget_class->get_preferred_width = fastiv_browser_get_preferred_width;
fastiv_browser_get_preferred_width;
widget_class->get_preferred_height_for_width = widget_class->get_preferred_height_for_width =
fastiv_browser_get_preferred_height_for_width; fastiv_browser_get_preferred_height_for_width;
widget_class->realize = fastiv_browser_realize; widget_class->realize = fastiv_browser_realize;
widget_class->draw = fastiv_browser_draw; widget_class->draw = fastiv_browser_draw;
// TODO(p): Connect to this and emit it. // TODO(p): Connect to this and emit it.
browser_signals[ITEM_ACTIVATED] = browser_signals[ITEM_ACTIVATED] = g_signal_new("item-activated",
g_signal_new("item-activated", G_TYPE_FROM_CLASS(klass), G_TYPE_FROM_CLASS(klass), 0, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
0, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
// TODO(p): Later override "screen_changed", recreate Pango layouts there, // TODO(p): Later override "screen_changed", recreate Pango layouts there,
// if we get to have any, or otherwise reflect DPI changes. // if we get to have any, or otherwise reflect DPI changes.
@ -217,15 +215,15 @@ fastiv_browser_load(FastivBrowser *self, const char *path)
const char *filename; const char *filename;
while ((filename = g_dir_read_name(dir))) { while ((filename = g_dir_read_name(dir))) {
if (!strcmp(filename, ".") if (!strcmp(filename, ".") || !strcmp(filename, ".."))
|| !strcmp(filename, ".."))
continue; continue;
gchar *subpath = g_build_filename(path, filename, NULL); gchar *subpath = g_build_filename(path, filename, NULL);
g_array_append_val(self->entries, ((Entry) { g_array_append_val(self->entries,
.thumbnail = fastiv_io_lookup_thumbnail(subpath), ((Entry){
.filename = subpath, .thumbnail = fastiv_io_lookup_thumbnail(subpath),
})); .filename = subpath,
}));
} }
g_dir_close(dir); g_dir_close(dir);

View File

@ -19,7 +19,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#define FASTIV_TYPE_BROWSER (fastiv_browser_get_type()) #define FASTIV_TYPE_BROWSER (fastiv_browser_get_type())
G_DECLARE_FINAL_TYPE(FastivBrowser, fastiv_browser, FASTIV, BROWSER, GtkWidget) G_DECLARE_FINAL_TYPE(FastivBrowser, fastiv_browser, FASTIV, BROWSER, GtkWidget)
void fastiv_browser_load(FastivBrowser *self, const char *path); void fastiv_browser_load(FastivBrowser *self, const char *path);

View File

@ -15,8 +15,8 @@
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
// //
#include <time.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include <time.h>
#include "fastiv-view.h" #include "fastiv-view.h"

View File

@ -17,8 +17,8 @@
#include "config.h" #include "config.h"
#include <glib.h>
#include <cairo.h> #include <cairo.h>
#include <glib.h>
#include <turbojpeg.h> #include <turbojpeg.h>
#ifdef HAVE_LIBRAW #ifdef HAVE_LIBRAW
#include <libraw.h> #include <libraw.h>
@ -53,7 +53,7 @@ const char *fastiv_io_supported_media_types[] = {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#define FASTIV_IO_ERROR fastiv_io_error_quark() #define FASTIV_IO_ERROR fastiv_io_error_quark()
G_DEFINE_QUARK(fastiv-io-error-quark, fastiv_io_error) G_DEFINE_QUARK(fastiv-io-error-quark, fastiv_io_error)
@ -64,8 +64,7 @@ enum FastivIoError {
static void static void
set_error(GError **error, const char *message) set_error(GError **error, const char *message)
{ {
g_set_error_literal(error, g_set_error_literal(error, FASTIV_IO_ERROR, FASTIV_IO_ERROR_OPEN, message);
FASTIV_IO_ERROR, FASTIV_IO_ERROR_OPEN, message);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -74,8 +73,8 @@ set_error(GError **error, const char *message)
// is pure C, and a good reference. I can't use the auxiliary libraries, // is pure C, and a good reference. I can't use the auxiliary libraries,
// since they depend on C++, which is undesirable. // since they depend on C++, which is undesirable.
static cairo_surface_t * static cairo_surface_t *
open_wuffs(wuffs_base__image_decoder *dec, open_wuffs(
wuffs_base__io_buffer src, GError **error) wuffs_base__image_decoder *dec, wuffs_base__io_buffer src, GError **error)
{ {
wuffs_base__image_config cfg; wuffs_base__image_config cfg;
wuffs_base__status status = wuffs_base__status status =
@ -148,7 +147,7 @@ open_wuffs(wuffs_base__image_decoder *dec,
status = wuffs_base__pixel_buffer__set_from_slice(&pb, &cfg.pixcfg, status = wuffs_base__pixel_buffer__set_from_slice(&pb, &cfg.pixcfg,
wuffs_base__make_slice_u8(cairo_image_surface_get_data(surface), wuffs_base__make_slice_u8(cairo_image_surface_get_data(surface),
cairo_image_surface_get_stride(surface) * cairo_image_surface_get_stride(surface) *
cairo_image_surface_get_height(surface))); cairo_image_surface_get_height(surface)));
if (!wuffs_base__status__is_ok(&status)) { if (!wuffs_base__status__is_ok(&status)) {
set_error(error, wuffs_base__status__message(&status)); set_error(error, wuffs_base__status__message(&status));
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
@ -170,8 +169,8 @@ open_wuffs(wuffs_base__image_decoder *dec,
// Starting to modify pixel data directly. Probably an unnecessary call. // Starting to modify pixel data directly. Probably an unnecessary call.
cairo_surface_flush(surface); cairo_surface_flush(surface);
status = wuffs_base__image_decoder__decode_frame(dec, &pb, &src, status = wuffs_base__image_decoder__decode_frame(
WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL); dec, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL);
if (!wuffs_base__status__is_ok(&status)) { if (!wuffs_base__status__is_ok(&status)) {
set_error(error, wuffs_base__status__message(&status)); set_error(error, wuffs_base__status__message(&status));
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
@ -196,8 +195,8 @@ open_wuffs_using(wuffs_base__image_decoder *(*allocate)(),
return NULL; return NULL;
} }
cairo_surface_t *surface = open_wuffs(dec, cairo_surface_t *surface = open_wuffs(
wuffs_base__ptr_u8__reader((uint8_t *) data, len, TRUE), error); dec, wuffs_base__ptr_u8__reader((uint8_t *) data, len, TRUE), error);
free(dec); free(dec);
return surface; return surface;
} }
@ -255,8 +254,8 @@ open_libjpeg_turbo(const gchar *data, gsize len, GError **error)
int stride = cairo_image_surface_get_stride(surface); int stride = cairo_image_surface_get_stride(surface);
if (tjDecompress2(dec, (const unsigned char *) data, len, if (tjDecompress2(dec, (const unsigned char *) data, len,
cairo_image_surface_get_data(surface), width, stride, cairo_image_surface_get_data(surface), width, stride, height,
height, pixel_format, TJFLAG_ACCURATEDCT)) { pixel_format, TJFLAG_ACCURATEDCT)) {
set_error(error, tjGetErrorStr2(dec)); set_error(error, tjGetErrorStr2(dec));
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
tjDestroy(dec); tjDestroy(dec);
@ -267,8 +266,8 @@ open_libjpeg_turbo(const gchar *data, gsize len, GError **error)
if (pixel_format == TJPF_CMYK) { if (pixel_format == TJPF_CMYK) {
// CAIRO_STRIDE_ALIGNMENT is 4 bytes, so there will be no padding with // CAIRO_STRIDE_ALIGNMENT is 4 bytes, so there will be no padding with
// ARGB/BGR/XRGB/BGRX. // ARGB/BGR/XRGB/BGRX.
trivial_cmyk_to_bgra(cairo_image_surface_get_data(surface), trivial_cmyk_to_bgra(
width * height); cairo_image_surface_get_data(surface), width * height);
} }
// Pixel data has been written, need to let Cairo know. // Pixel data has been written, need to let Cairo know.
@ -284,8 +283,8 @@ static cairo_surface_t *
open_libraw(const gchar *data, gsize len, GError **error) open_libraw(const gchar *data, gsize len, GError **error)
{ {
// https://github.com/LibRaw/LibRaw/issues/418 // https://github.com/LibRaw/LibRaw/issues/418
libraw_data_t *iprc = libraw_init(LIBRAW_OPIONS_NO_MEMERR_CALLBACK libraw_data_t *iprc = libraw_init(
| LIBRAW_OPIONS_NO_DATAERR_CALLBACK); LIBRAW_OPIONS_NO_MEMERR_CALLBACK | LIBRAW_OPIONS_NO_DATAERR_CALLBACK);
if (!iprc) { if (!iprc) {
set_error(error, "failed to obtain a LibRaw handle"); set_error(error, "failed to obtain a LibRaw handle");
return NULL; return NULL;
@ -300,7 +299,7 @@ open_libraw(const gchar *data, gsize len, GError **error)
// TODO(p): Check if we need to set anything for autorotation (sizes.flip). // TODO(p): Check if we need to set anything for autorotation (sizes.flip).
iprc->params.use_camera_wb = 1; iprc->params.use_camera_wb = 1;
iprc->params.output_color = 1; // sRGB, TODO(p): Is this used? iprc->params.output_color = 1; // sRGB, TODO(p): Is this used?
iprc->params.output_bps = 8; // This should be the default value. iprc->params.output_bps = 8; // This should be the default value.
int err = 0; int err = 0;
if ((err = libraw_open_buffer(iprc, (void *) data, len))) { if ((err = libraw_open_buffer(iprc, (void *) data, len))) {
@ -368,8 +367,8 @@ open_libraw(const gchar *data, gsize len, GError **error)
unsigned char *p = image->data; unsigned char *p = image->data;
for (ushort y = 0; y < image->height; y++) { for (ushort y = 0; y < image->height; y++) {
for (ushort x = 0; x < image->width; x++) { for (ushort x = 0; x < image->width; x++) {
*pixels++ = 0xff000000 | (uint32_t) p[0] << 16 *pixels++ = 0xff000000 | (uint32_t) p[0] << 16 |
| (uint32_t) p[1] << 8 | (uint32_t) p[2]; (uint32_t) p[1] << 8 | (uint32_t) p[2];
p += 3; p += 3;
} }
} }
@ -407,18 +406,18 @@ fastiv_io_open(const gchar *path, GError **error)
// Note that BMP can redirect into another format, // Note that BMP can redirect into another format,
// which is so far unsupported here. // which is so far unsupported here.
surface = open_wuffs_using( surface = open_wuffs_using(
wuffs_bmp__decoder__alloc_as__wuffs_base__image_decoder, wuffs_bmp__decoder__alloc_as__wuffs_base__image_decoder, data, len,
data, len, error); error);
break; break;
case WUFFS_BASE__FOURCC__GIF: case WUFFS_BASE__FOURCC__GIF:
surface = open_wuffs_using( surface = open_wuffs_using(
wuffs_gif__decoder__alloc_as__wuffs_base__image_decoder, wuffs_gif__decoder__alloc_as__wuffs_base__image_decoder, data, len,
data, len, error); error);
break; break;
case WUFFS_BASE__FOURCC__PNG: case WUFFS_BASE__FOURCC__PNG:
surface = open_wuffs_using( surface = open_wuffs_using(
wuffs_png__decoder__alloc_as__wuffs_base__image_decoder, wuffs_png__decoder__alloc_as__wuffs_base__image_decoder, data, len,
data, len, error); error);
break; break;
case WUFFS_BASE__FOURCC__JPEG: case WUFFS_BASE__FOURCC__JPEG:
surface = open_libjpeg_turbo(data, len, error); surface = open_libjpeg_turbo(data, len, error);
@ -446,8 +445,8 @@ fastiv_io_open(const gchar *path, GError **error)
// scaled, linear encoded, pre-multiplied component values must be used!" // scaled, linear encoded, pre-multiplied component values must be used!"
// //
// We can use the pixman library to scale, PIXMAN_a8r8g8b8_sRGB. // We can use the pixman library to scale, PIXMAN_a8r8g8b8_sRGB.
#include <png.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <png.h>
// TODO(p): Reorganize the sources. // TODO(p): Reorganize the sources.
gchar *get_xdg_home_dir(const char *var, const char *default_); gchar *get_xdg_home_dir(const char *var, const char *default_);
@ -467,8 +466,8 @@ discard_png_warning(png_structp pngp, const char *warning)
} }
static int static int
check_png_thumbnail(png_structp pngp, png_infop infop, const gchar *target, check_png_thumbnail(
time_t mtime) png_structp pngp, png_infop infop, const gchar *target, time_t mtime)
{ {
// May contain Thumb::Image::Width Thumb::Image::Height, // May contain Thumb::Image::Width Thumb::Image::Height,
// but those aren't interesting currently (would be for fast previews). // but those aren't interesting currently (would be for fast previews).
@ -496,8 +495,8 @@ check_png_thumbnail(png_structp pngp, png_infop infop, const gchar *target,
// TODO(p): Support spng as well (it can't premultiply alpha by itself, // TODO(p): Support spng as well (it can't premultiply alpha by itself,
// but at least it won't gamma-adjust it for us). // but at least it won't gamma-adjust it for us).
static cairo_surface_t * static cairo_surface_t *
read_png_thumbnail(const gchar *path, const gchar *uri, time_t mtime, read_png_thumbnail(
GError **error) const gchar *path, const gchar *uri, time_t mtime, GError **error)
{ {
FILE *fp; FILE *fp;
if (!(fp = fopen(path, "rb"))) { if (!(fp = fopen(path, "rb"))) {
@ -506,8 +505,8 @@ read_png_thumbnail(const gchar *path, const gchar *uri, time_t mtime,
} }
cairo_surface_t *volatile surface = NULL; cairo_surface_t *volatile surface = NULL;
png_structp pngp = png_create_read_struct(PNG_LIBPNG_VER_STRING, png_structp pngp = png_create_read_struct(
error, redirect_png_error, discard_png_warning); PNG_LIBPNG_VER_STRING, error, redirect_png_error, discard_png_warning);
png_infop infop = png_create_info_struct(pngp); png_infop infop = png_create_info_struct(pngp);
if (!infop) { if (!infop) {
set_error(error, g_strerror(errno)); set_error(error, g_strerror(errno));
@ -617,8 +616,8 @@ fastiv_io_lookup_thumbnail(const gchar *target)
const gchar *sizes[] = {"large", "x-large", "xx-large", "normal"}; const gchar *sizes[] = {"large", "x-large", "xx-large", "normal"};
GError *error = NULL; GError *error = NULL;
for (gsize i = 0; !result && i < G_N_ELEMENTS(sizes); i++) { for (gsize i = 0; !result && i < G_N_ELEMENTS(sizes); i++) {
gchar *path = g_strdup_printf("%s/thumbnails/%s/%s.png", gchar *path = g_strdup_printf(
cache_dir, sizes[i], sum); "%s/thumbnails/%s/%s.png", cache_dir, sizes[i], sum);
result = read_png_thumbnail(path, uri, st.st_mtim.tv_sec, &error); result = read_png_thumbnail(path, uri, st.st_mtim.tv_sec, &error);
if (error) { if (error) {
g_debug("%s: %s", path, error->message); g_debug("%s: %s", path, error->message);

View File

@ -57,8 +57,8 @@ fastiv_view_finalize(GObject *gobject)
} }
static void static void
fastiv_view_get_preferred_height(GtkWidget *widget, fastiv_view_get_preferred_height(
gint *minimum, gint *natural) GtkWidget *widget, gint *minimum, gint *natural)
{ {
*minimum = 0; *minimum = 0;
*natural = 0; *natural = 0;
@ -68,8 +68,7 @@ fastiv_view_get_preferred_height(GtkWidget *widget,
} }
static void static void
fastiv_view_get_preferred_width(GtkWidget *widget, fastiv_view_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural)
gint *minimum, gint *natural)
{ {
*minimum = 0; *minimum = 0;
*natural = 0; *natural = 0;
@ -86,19 +85,19 @@ fastiv_view_realize(GtkWidget *widget)
GdkWindowAttr attributes = { GdkWindowAttr attributes = {
.window_type = GDK_WINDOW_CHILD, .window_type = GDK_WINDOW_CHILD,
.x = allocation.x, .x = allocation.x,
.y = allocation.y, .y = allocation.y,
.width = allocation.width, .width = allocation.width,
.height = allocation.height, .height = allocation.height,
// Input-only would presumably also work (as in GtkPathBar, e.g.), // Input-only would presumably also work (as in GtkPathBar, e.g.),
// but it merely seems to involve more work. // but it merely seems to involve more work.
.wclass = GDK_INPUT_OUTPUT, .wclass = GDK_INPUT_OUTPUT,
// Assuming here that we can't ask for a higher-precision Visual // Assuming here that we can't ask for a higher-precision Visual
// than what we get automatically. // than what we get automatically.
.visual = gtk_widget_get_visual(widget), .visual = gtk_widget_get_visual(widget),
.event_mask = gtk_widget_get_events(widget) | GDK_SCROLL_MASK, .event_mask = gtk_widget_get_events(widget) | GDK_SCROLL_MASK,
}; };
// We need this window to receive input events at all. // We need this window to receive input events at all.
@ -113,14 +112,14 @@ static gboolean
fastiv_view_draw(GtkWidget *widget, cairo_t *cr) fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
{ {
FastivView *self = FASTIV_VIEW(widget); FastivView *self = FASTIV_VIEW(widget);
if (!self->surface if (!self->surface ||
|| !gtk_cairo_should_draw_window(cr, gtk_widget_get_window(widget))) !gtk_cairo_should_draw_window(cr, gtk_widget_get_window(widget)))
return TRUE; return TRUE;
GtkAllocation allocation; GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation); gtk_widget_get_allocation(widget, &allocation);
gtk_render_background(gtk_widget_get_style_context(widget), cr, gtk_render_background(gtk_widget_get_style_context(widget), cr, 0, 0,
0, 0, allocation.width, allocation.height); allocation.width, allocation.height);
int w = get_display_width(self); int w = get_display_width(self);
int h = get_display_height(self); int h = get_display_height(self);
@ -133,8 +132,8 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
y = round((allocation.height - h) / 2.); y = round((allocation.height - h) / 2.);
cairo_scale(cr, self->scale, self->scale); cairo_scale(cr, self->scale, self->scale);
cairo_set_source_surface(cr, self->surface, cairo_set_source_surface(
x / self->scale, y / self->scale); cr, self->surface, x / self->scale, y / self->scale);
// TODO(p): Prescale it ourselves to an off-screen bitmap, gamma-correctly. // TODO(p): Prescale it ourselves to an off-screen bitmap, gamma-correctly.
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD); cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD);

View File

@ -19,7 +19,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#define FASTIV_TYPE_VIEW (fastiv_view_get_type()) #define FASTIV_TYPE_VIEW (fastiv_view_get_type())
G_DECLARE_FINAL_TYPE(FastivView, fastiv_view, FASTIV, VIEW, GtkWidget) G_DECLARE_FINAL_TYPE(FastivView, fastiv_view, FASTIV, VIEW, GtkWidget)
/// Try to open the given file, synchronously, to be displayed by the widget. /// Try to open the given file, synchronously, to be displayed by the widget.

View File

@ -15,26 +15,25 @@
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
// //
#include <gtk/gtk.h>
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <locale.h> #include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <fnmatch.h> #include <fnmatch.h>
#include "config.h" #include "config.h"
#include "fastiv-browser.h"
#include "fastiv-io.h" #include "fastiv-io.h"
#include "fastiv-view.h" #include "fastiv-view.h"
#include "fastiv-browser.h"
// --- Utilities --------------------------------------------------------------- // --- Utilities ---------------------------------------------------------------
static void static void exit_fatal(const gchar *format, ...) G_GNUC_PRINTF(1, 2);
exit_fatal(const gchar *format, ...) G_GNUC_PRINTF(1, 2);
static void static void
exit_fatal(const gchar *format, ...) exit_fatal(const gchar *format, ...)
@ -53,8 +52,8 @@ exit_fatal(const gchar *format, ...)
/// Add `element` to the `output` set. `relation` is a map of sets of strings /// Add `element` to the `output` set. `relation` is a map of sets of strings
/// defining is-a relations, and is traversed recursively. /// defining is-a relations, and is traversed recursively.
static void static void
add_applying_transitive_closure(const gchar *element, GHashTable *relation, add_applying_transitive_closure(
GHashTable *output) const gchar *element, GHashTable *relation, GHashTable *output)
{ {
// Stop condition. // Stop condition.
if (!g_hash_table_add(output, g_strdup(element))) if (!g_hash_table_add(output, g_strdup(element)))
@ -181,8 +180,8 @@ get_supported_globs(const char **media_types)
// The mime.cache format is inconvenient to parse, // The mime.cache format is inconvenient to parse,
// we'll do it from the text files manually, and once only. // we'll do it from the text files manually, and once only.
GHashTable *subclass_sets = g_hash_table_new_full(g_str_hash, g_str_equal, GHashTable *subclass_sets = g_hash_table_new_full(
g_free, (GDestroyNotify) g_hash_table_destroy); g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy);
for (gsize i = 0; data_dirs[i]; i++) { for (gsize i = 0; data_dirs[i]; i++) {
gchar *path = gchar *path =
g_build_filename(data_dirs[i], "mime", "subclasses", NULL); g_build_filename(data_dirs[i], "mime", "subclasses", NULL);
@ -195,8 +194,8 @@ get_supported_globs(const char **media_types)
GHashTable *supported = GHashTable *supported =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
while (*media_types) { while (*media_types) {
add_applying_transitive_closure(*media_types++, add_applying_transitive_closure(
subclass_sets, supported); *media_types++, subclass_sets, supported);
} }
g_hash_table_destroy(subclass_sets); g_hash_table_destroy(subclass_sets);
@ -261,9 +260,9 @@ is_supported(const gchar *filename)
static void static void
show_error_dialog(GError *error) show_error_dialog(GError *error)
{ {
GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(g.window), GtkWidget *dialog =
GTK_DIALOG_MODAL, gtk_message_dialog_new(GTK_WINDOW(g.window), GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message); GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message);
gtk_dialog_run(GTK_DIALOG(dialog)); gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
g_error_free(error); g_error_free(error);
@ -336,7 +335,6 @@ open(const gchar *path)
} }
} }
g_free(dirname); g_free(dirname);
} }
static void static void
@ -375,9 +373,8 @@ on_previous(void)
if (g.files_index >= 0) { if (g.files_index >= 0) {
int previous = int previous =
(g.files->len - 1 + g.files_index - 1) % (g.files->len - 1); (g.files->len - 1 + g.files_index - 1) % (g.files->len - 1);
char *absolute = char *absolute = g_canonicalize_filename(
g_canonicalize_filename(g_ptr_array_index(g.files, previous), g_ptr_array_index(g.files, previous), g.directory);
g.directory);
open(absolute); open(absolute);
g_free(absolute); g_free(absolute);
} }
@ -388,9 +385,8 @@ on_next(void)
{ {
if (g.files_index >= 0) { if (g.files_index >= 0) {
int next = (g.files_index + 1) % (g.files->len - 1); int next = (g.files_index + 1) % (g.files->len - 1);
char *absolute = char *absolute = g_canonicalize_filename(
g_canonicalize_filename(g_ptr_array_index(g.files, next), g_ptr_array_index(g.files, next), g.directory);
g.directory);
open(absolute); open(absolute);
g_free(absolute); g_free(absolute);
} }
@ -408,13 +404,13 @@ main(int argc, char *argv[])
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &path_args, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &path_args,
NULL, "[FILE | DIRECTORY]"}, NULL, "[FILE | DIRECTORY]"},
{"version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, {"version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
&show_version, "output version information and exit", NULL}, &show_version, "output version information and exit", NULL},
{}, {},
}; };
GError *error = NULL; GError *error = NULL;
if (!gtk_init_with_args(&argc, &argv, " - fast image viewer", if (!gtk_init_with_args(
options, NULL, &error)) &argc, &argv, " - fast image viewer", options, NULL, &error))
exit_fatal("%s", error->message); exit_fatal("%s", error->message);
if (show_version) { if (show_version) {
printf(PROJECT_NAME " " PROJECT_VERSION "\n"); printf(PROJECT_NAME " " PROJECT_VERSION "\n");
@ -494,9 +490,9 @@ main(int argc, char *argv[])
if (!path_arg) { if (!path_arg) {
load_directory(cwd); load_directory(cwd);
} else if (g_stat(path_arg, &st)) { } else if (g_stat(path_arg, &st)) {
show_error_dialog(g_error_new(G_FILE_ERROR, show_error_dialog(
g_file_error_from_errno(errno), g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), "%s: %s",
"%s: %s", path_arg, g_strerror(errno))); path_arg, g_strerror(errno)));
load_directory(cwd); load_directory(cwd);
} else { } else {
gchar *path_arg_absolute = g_canonicalize_filename(path_arg, cwd); gchar *path_arg_absolute = g_canonicalize_filename(path_arg, cwd);