libxputty 0.1
Loading...
Searching...
No Matches
xfilepicker.h
Go to the documentation of this file.
1/*
2 * 0BSD
3 *
4 * BSD Zero Clause License
5 *
6 * Copyright (c) 2019 Hermann Meyer
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted.
10
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 *
19 */
20
21
22/* define _GNU_SOURCE to remove dependency of xasprintf.h */
23
24/*
25#ifndef _GNU_SOURCE
26#define _GNU_SOURCE 1
27#endif
28*/
29
30#include <dirent.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <stdarg.h>
34#include <stdbool.h>
35#include <string.h>
36#include <unistd.h>
37#include <assert.h>
38
39#include <libgen.h>
40
41#pragma once
42
43#ifndef XFILEPICKER_H_
44#define XFILEPICKER_H_
45
46/* comment out xdgmine.h will disable the file filter, you may implement your own.*/
47#ifdef __linux__
48#include "xdgmime.h"
49#endif
50/* comment out xasprintf and define _GNU_SOURCE on top of this file will remove this dependency.*/
51#include "xasprintf.h"
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57#if defined(WIN32) || defined(_WIN32)
58#define PATH_SEPARATOR "\\"
59#else
60#define PATH_SEPARATOR "/"
61#endif
62
63typedef struct {
64 char *filter;
65 char *path;
67 char **file_names;
68 char **dir_names;
69 unsigned int file_counter;
70 unsigned int dir_counter;
73 char pad[3];
75
76
87int fp_get_files(FilePicker *filepicker, char *path, int get_dirs, int get_files);
88
94void fp_free(FilePicker *filepicker);
95
102void fp_init(FilePicker *filepicker, const char *path);
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif //XFILEPICKER_H_
unsigned int file_counter
Definition xfilepicker.h:69
char * filter
Definition xfilepicker.h:64
bool show_hidden
Definition xfilepicker.h:72
char * selected_file
Definition xfilepicker.h:66
char * path
Definition xfilepicker.h:65
unsigned int dir_counter
Definition xfilepicker.h:70
char ** dir_names
Definition xfilepicker.h:68
char ** file_names
Definition xfilepicker.h:67
Multiplatform implementation of asprintf() from: https://stackoverflow.com/questions/40159892/using-a...
void fp_init(FilePicker *filepicker, const char *path)
fp_init - set default values used by the filepicker
int fp_get_files(FilePicker *filepicker, char *path, int get_dirs, int get_files)
fp_get_files - fill file_names and dir_names with the results from readdir path
void fp_free(FilePicker *filepicker)
fp_free - release all memory used by the filepicker