libxputty 0.1
Loading...
Searching...
No Matches
Data Structures | Functions
xfilepicker.h File Reference

Go to the source code of this file.

Data Structures

struct  FilePicker
 

Functions

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
 
void fp_init (FilePicker *filepicker, const char *path)
 fp_init - set default values used by the filepicker
 

Function Documentation

◆ fp_free()

void fp_free ( FilePicker filepicker)

fp_free - release all memory used by the filepicker

Parameters
*filepicker- pointer to the struct to be released

Definition at line 275 of file xfilepicker.c.

275 {
276 fp_clear_filebuffer(filepicker);
277 fp_clear_dirbuffer(filepicker);
278 free(filepicker->selected_file);
279 free(filepicker->path);
280 free(filepicker->filter);
281}
char * filter
Definition xfilepicker.h:64
char * selected_file
Definition xfilepicker.h:66
char * path
Definition xfilepicker.h:65

References FilePicker::filter, FilePicker::path, and FilePicker::selected_file.

◆ fp_get_files()

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

Parameters
*filepicker- pointer to the struct holding the list pointers
*path- the path to read from
get_dirs- 0 = only read files 1 = refill the directory buffer as well
get_files- 0 = only read directorys 1 = refill the file buffer as well
Returns
int - return the position of the given path in the directory list

Definition at line 226 of file xfilepicker.c.

226 {
227 int ret = 0;
228 fp_clear_filebuffer(filepicker);
229
230 DIR *dirp;
231 struct dirent *dp;
232 if((dirp = opendir(path)) == NULL) {
233 path =(char*)PATH_SEPARATOR;
234 dirp = opendir(PATH_SEPARATOR);
235 assert(dirp);
236 }
237
238 if(get_dirs) {
239 fp_clear_dirbuffer(filepicker);
240 ret = fp_prefill_dirbuffer(filepicker, path);
241 }
242
243 while ((dp = readdir(dirp)) != NULL) {
244
245 if((get_files && (is_file(dirp, dp) || (fp_check_dir(path, dp) == 2)) && strlen(dp->d_name)!=0
246 && strcmp(dp->d_name,"..")!=0 && fp_show_hidden_files(filepicker, dp->d_name)
247 && fp_show_filter_files(filepicker, dp->d_name) && !fp_check_link(path, dp)) ) {
248
249 filepicker->file_names = (char **)realloc(filepicker->file_names,
250 (filepicker->file_counter + 1) * sizeof(char *));
251 assert(filepicker->file_names != NULL);
252 asprintf(&filepicker->file_names[filepicker->file_counter++],"%s",dp->d_name);
253 assert(&filepicker->file_names[filepicker->file_counter-1] != NULL);
254
255 } else if(get_dirs && (is_directory(dirp, dp) || fp_is_link(dp) || (fp_check_dir(path, dp) == 1))
256 && strlen(dp->d_name)!=0 && strcmp(dp->d_name,"..")!=0 && fp_show_hidden_files(filepicker, dp->d_name)) {
257
258 if (fp_is_link(dp)) {
259 if (!fp_check_link(path, dp)) continue;
260 }
261 filepicker->file_names = (char **)realloc(filepicker->file_names,
262 (filepicker->file_counter + 1) * sizeof(char *));
263 assert(filepicker->file_names != NULL);
264 asprintf(&filepicker->file_names[filepicker->file_counter++], (strcmp(path, PATH_SEPARATOR) != 0) ?
265 "%s" PATH_SEPARATOR "%s" : "%s%s" , path,dp->d_name);
266 //asprintf(&filepicker->file_names[filepicker->file_counter++],"%s%s" , path,dp->d_name);
267 assert(&filepicker->dir_names[filepicker->file_counter-1] != NULL);
268 }
269 }
270 closedir(dirp);
271 fp_sort_buffers(filepicker, get_dirs);
272 return ret;
273}
unsigned int file_counter
Definition xfilepicker.h:69
char ** dir_names
Definition xfilepicker.h:68
char ** file_names
Definition xfilepicker.h:67
int asprintf(char *strp[], const char *fmt,...)
Definition xasprintf.c:36
int fp_check_link(char *path, struct dirent *dp)
bool is_file(DIR *dirp, struct dirent *dp)
int fp_check_dir(char *path, struct dirent *dp)
int fp_is_link(struct dirent *dp)
bool is_directory(DIR *dirp, struct dirent *dp)

References asprintf(), FilePicker::dir_names, FilePicker::file_counter, FilePicker::file_names, fp_check_dir(), fp_check_link(), fp_is_link(), is_directory(), and is_file().

Referenced by open_directory_dialog(), open_file_dialog(), and save_file_dialog().

◆ fp_init()

void fp_init ( FilePicker filepicker,
const char *  path 
)

fp_init - set default values used by the filepicker

Parameters
*filepicker- pointer to the struct to alocate
*path- the path to read from

Definition at line 283 of file xfilepicker.c.

283 {
284 filepicker->file_counter=0;
285 filepicker->dir_counter=0;
286 filepicker->use_filter = 0;
287 filepicker->show_hidden = false;
288 filepicker->file_names = NULL;
289 filepicker->dir_names = NULL;
290 filepicker->selected_file = NULL;
291 filepicker->path = NULL;
292 filepicker->filter = NULL;
293#ifdef _WIN32 //file/drive functions
294 asprintf(&filepicker->path, "%s", "C:\\");
295#else
296 asprintf(&filepicker->path, "%s", path);
297#endif
298 assert(filepicker->path != NULL);
299}
bool show_hidden
Definition xfilepicker.h:72
unsigned int dir_counter
Definition xfilepicker.h:70

References asprintf(), FilePicker::dir_counter, FilePicker::dir_names, FilePicker::file_counter, FilePicker::file_names, FilePicker::filter, FilePicker::path, FilePicker::selected_file, FilePicker::show_hidden, and FilePicker::use_filter.

Referenced by open_directory_dialog(), open_file_dialog(), and save_file_dialog().