44static void file_released_callback(
void *w_,
void* user_data);
45static void combo_response(
void *w_,
void* user_data);
46static void set_selected_file(
FileDialog *file_dialog,
int reload);
48static void draw_window(
void *w_,
void* user_data) {
52 int width = metrics.
width;
53 int height = metrics.
height;
56 cairo_rectangle(w->
crb,0,0,width,height);
61 cairo_set_font_size (w->
crb, 12.0);
62 cairo_move_to (w->
crb, 20, 35);
63 cairo_show_text(w->
crb, _(
"Base Directory"));
64 cairo_move_to (w->
crb, 20, 85);
65 cairo_show_text(w->
crb, _(
"Places"));
66 cairo_move_to (w->
crb, 130, 85);
67 cairo_show_text(w->
crb, _(
"Entries"));
69 cairo_show_text(w->
crb, _(
"Load: "));
71 cairo_show_text(w->
crb, _(
"Show hidden files"));
74static void button_quit_callback(
void *w_,
void* user_data) {
79 file_dialog->parent->func.dialog_callback(file_dialog->parent,NULL);
80 file_dialog->send_clear_func =
false;
85static inline int set_files(
FileDialog *file_dialog) {
111static void file_released_b_callback(
void *w_,
void *button,
void* user_data) {
114 set_selected_file(file_dialog, 1);
121static void dummy(
void *w_,
void* user_data) {
125static void reload_from_dir(
FileDialog *file_dialog) {
127 assert(file_dialog->
fp->
path != NULL);
132 int set_f = set_files(file_dialog);
133 set_dirs(file_dialog);
146static void set_selected_file(
FileDialog *file_dialog,
int reload) {
162 if (reload) reload_from_dir(file_dialog);
171static void file_released_callback(
void *w_,
void* user_data) {
174 set_selected_file(file_dialog, 1);
181static void forward_key_press(
void *w_,
void *key_,
void *user_data) {
187static void reload_file_entrys(
FileDialog *file_dialog) {
190 int set_f = set_files(file_dialog);
200static void combo_response(
void *w_,
void* user_data) {
207 free(file_dialog->
fp->
path);
208 file_dialog->
fp->
path = NULL;
210 assert(file_dialog->
fp->
path != NULL);
211 reload_from_dir(file_dialog);
214static void save_and_exit(
void *w_) {
223 _(
"Please enter a file name"),NULL);
228static void question_response(
void *w_,
void* user_data) {
229 if(user_data !=NULL) {
230 int response = *(
int*)user_data;
237static void button_ok_callback(
void *w_,
void* user_data) {
241 set_selected_file(file_dialog, 0);
244 _(
"File already exists, would you overwrite it?"),NULL);
252static void save_on_enter(
void *w_) {
255 set_selected_file(file_dialog, 0);
258 _(
"File already exists, would you overwrite it?"),NULL);
266static void reload_all(
FileDialog *file_dialog) {
272 free(file_dialog->
fp->
path);
273 file_dialog->
fp->
path = NULL;
275 assert(file_dialog->
fp->
path != NULL);
279 int set_f = set_files(file_dialog);
280 set_dirs(file_dialog);
291static void open_dir_callback(
void *w_,
void* user_data) {
295 reload_all(file_dialog);
299static void button_hidden_callback(
void *w_,
void* user_data) {
304 reload_all(file_dialog);
308static void set_filter_callback(
void *w_,
void* user_data) {
320 assert(file_dialog->
fp->
filter != NULL);
322 reload_file_entrys(file_dialog);
326static void draw_entry(
void *w_,
void* user_data) {
331 int width = metrics.
width-2;
332 int height = metrics.
height-2;
336 cairo_rectangle(w->
cr,0,0,width,height);
337 cairo_fill_preserve (w->
cr);
339 cairo_set_line_width(w->
cr, 2.0);
342 cairo_set_font_size (w->
cr, 9.0);
344 cairo_move_to (w->
cr, 2, 9);
345 cairo_show_text(w->
cr,
" ");
348static void entry_add_text(
void *w_,
void *label_) {
351 char *label = (
char*)label_;
356 cairo_text_extents_t extents;
358 cairo_set_font_size (w->
cr, 11.0);
367 cairo_set_font_size (w->
cr, 12.0);
370 cairo_move_to (w->
cr, 2, 12.0+extents.height);
375static void entry_clip(
Widget_t *w) {
377 cairo_text_extents_t extents;
379 cairo_set_font_size (w->
cr, 11.0);
399 cairo_set_font_size (w->
cr, 12.0);
402 cairo_move_to (w->
cr, 2, 12.0+extents.height);
407static void entry_get_text(
void *w_,
void *key_,
void *user_data) {
420 save_on_enter(file_dialog->
w_okay);
424 entry_add_text(w, buf);
429static void fd_mem_free(
void *w_,
void* user_data) {
435 free(file_dialog->
fp);
440static int starts_with(
const char *restrict
string,
const char *restrict prefix) {
443 if(*prefix++ != *
string++)
450static int strremove(
char *
string,
const char *restrict find){
451 if(strstr(
string, find) == NULL)
return 0;
452 char *temporaryString = malloc(strlen(strstr(
string, find) + strlen(find)) + 1);
453 strcpy(temporaryString, strstr(
string, find) + strlen(find));
454 char* rep = strstr(
string, find);
457 strcat(
string, temporaryString);
458 free(temporaryString);
462static void parse_xdg_dirs(
FileDialog *file_dialog) {
465 file_dialog->
home_dir = getenv(
"HOME");
466 if (file_dialog->
home_dir == NULL) {
467 file_dialog->
home_dir = getpwuid(getuid())->pw_dir;
469 if (file_dialog->
home_dir == NULL)
return;
470 sprintf(xdg_dir,
"%s/.config/user-dirs.dirs", file_dialog->
home_dir);
482 fp = fopen(xdg_dir,
"r");
484 while ((read = getline(&line, &len, fp)) != -1) {
485 if(starts_with(line,
"XDG_")) {
486 char* xdg = strstr(line,
"$HOME/");
487 if (!strremove(xdg,
"$HOME/"))
continue;
488 char* rep = strstr(xdg,
"\"");
510static void xdg_dir_select_callback(
void *w_,
void *button,
void* user_data) {
515 free(file_dialog->
fp->
path);
516 file_dialog->
fp->
path = NULL;
518 assert(file_dialog->
fp->
path != NULL);
520 free(file_dialog->
fp->
path);
521 file_dialog->
fp->
path = NULL;
523 assert(file_dialog->
fp->
path != NULL);
525 free(file_dialog->
fp->
path);
526 file_dialog->
fp->
path = NULL;
528 assert(file_dialog->
fp->
path != NULL);
530 reload_from_dir(file_dialog);
533static void add_xdg_dirs(
FileDialog *file_dialog) {
552 parse_xdg_dirs(file_dialog);
554 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
556 }
else if (stat(file_dialog->
home_dir, &sb) == 0 && S_ISDIR(sb.st_mode)) {
562 DWORD attr = GetFileAttributes(path);
563 if (attr&FILE_ATTRIBUTE_DIRECTORY) {
576 XSizeHints* win_size_hints;
577 win_size_hints = XAllocSizeHints();
578 win_size_hints->flags = PMinSize|PBaseSize|PMaxSize|PWinGravity;
579 win_size_hints->min_width = 660;
580 win_size_hints->min_height = 420;
581 win_size_hints->base_width = 660;
582 win_size_hints->base_height = 420;
583 win_size_hints->max_width = 660;
584 win_size_hints->max_height = 840;
585 win_size_hints->win_gravity = CenterGravity;
586 XSetWMNormalHints(file_dialog->
w->
app->
dpy, file_dialog->
w->
widget, win_size_hints);
587 XFree(win_size_hints);
617 int set_f = set_files(file_dialog);
618 set_dirs(file_dialog);
628 add_xdg_dirs(file_dialog);
638 Cursor c = XCreateFontCursor(file_dialog->
w->
app->
dpy, XC_xterm);
640 XFreeCursor(file_dialog->
w->
app->
dpy, c);
668 if(filter !=NULL && strlen(filter))
673 if(filter !=NULL && strlen(filter))
685 return file_dialog->
w;
694static void fdialog_response(
void *w_,
void* user_data) {
697 if(user_data !=NULL) {
698 char *tmp = strdup(*(
const char**)user_data);
699 free(filebutton->last_path);
700 filebutton->last_path = NULL;
701 filebutton->last_path = strdup(dirname(tmp));
702 filebutton->path = filebutton->last_path;
706 filebutton->is_active =
false;
710static void fbutton_callback(
void *w_,
void* user_data) {
715 filebutton->is_active =
true;
717 if(filebutton->is_active)
722static void fbutton_mem_free(
void *w_,
void* user_data) {
725 free(filebutton->last_path);
726 filebutton->last_path = NULL;
732 const char *path,
const char *filter) {
734 filebutton->
path = path;
735 filebutton->
filter = filter;
737 filebutton->
w = NULL;
ComboBox_t - struct to hold information for the combobox.
unsigned int xdg_dir_counter
unsigned int file_counter
evfunc button_release_callback
evfunc key_press_callback
xevfunc value_changed_callback
xevfunc mem_free_callback
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
int asprintf(char *strp[], const char *fmt,...)
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
void use_fg_color_scheme(Widget_t *w, Color_state st)
use_fg_color_scheme - use forground Colors to paint on Widget_t
void set_pattern(Widget_t *w, Colors *from, Colors *to, Color_mod mod)
set_pattern - set pattern for the selected Colors
void use_base_color_scheme(Widget_t *w, Color_state st)
use_base_color_scheme - use base Colors to paint on Widget_t
void combobox_set_active_entry(Widget_t *w, int active)
combobox_set_active_entry - set the active combobox entry
void combobox_delete_entrys(Widget_t *combobox)
combobox_delete_entrys - free the list hold the combobox entrys
void combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Widget_t * add_combobox(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_combobox - add a combobox
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
void listview_remove_list(Widget_t *listview)
listview_remove_list - remove the list from a listview Widget_t
Widget_t * add_listview(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_label - add a listview to a Widget_t
void listview_set_check_dir(Widget_t *listview, int set)
listview_set_check_dir - set optional check if list item is a directory
void listview_set_active_entry(Widget_t *w, int active)
listview_set_active_entry - set the active listview entry
void listview_unset_active_entry(Widget_t *w)
listview_unset_active_entry - unset the active listview entry
void listview_set_list(Widget_t *listview, char **list, int list_size)
listview_set_list - set a list to a listview Widget_t
Widget_t * open_message_dialog(Widget_t *w, int style, const char *title, const char *message, const char *choices)
open_message_dialog - open a non blocking dialog window, lines in message chould be separated by the ...
void widget_get_png(Widget_t *w, const unsigned char *name)
widget_get_png - read png into Widget_t xlib surface
void widget_set_icon_from_png(Widget_t *w, const unsigned char *name)
widget_set_icon_from_png - set icon image from png binary to Widget_t those icon will be used in the ...
Widget_t * save_file_dialog(Widget_t *w, const char *path, const char *filter)
save_file_dialog - open a non blocking dialog window, to select a file. The path to open the file-sel...
Widget_t * add_save_file_button(Widget_t *parent, int x, int y, int width, int height, const char *path, const char *filter)
add_save_file_button - add a pre-defined button which will pop-up a file dialog when pressed....