libxputty 0.1
Loading...
Searching...
No Matches
Functions
xsavefile-dialoge.c File Reference

Go to the source code of this file.

Functions

Widget_tsave_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-selector could be NULL It will open then in $HOME. The filter to use could be NULL, then the file-selector will show all files.
 
Widget_tadd_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. path and filter will e hand over to the file selector.
 

Function Documentation

◆ add_save_file_button()

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. path and filter will e hand over to the file selector.

Returns
Widget_t* - pointer to the Widget_t struct

Definition at line 731 of file xsavefile-dialoge.c.

732 {
733 FileButton *filebutton = (FileButton*)malloc(sizeof(FileButton));
734 filebutton->path = path;
735 filebutton->filter = filter;
736 filebutton->last_path = NULL;
737 filebutton->w = NULL;
738 filebutton->is_active = false;
739 Widget_t *fbutton = add_image_toggle_button(parent, "", x, y, width, height);
740 fbutton->parent_struct = filebutton;
741 fbutton->flags |= HAS_MEM;
742 widget_get_png(fbutton, LDVAR(directory_open_png));
743 fbutton->scale.gravity = CENTER;
744 fbutton->func.mem_free_callback = fbutton_mem_free;
745 fbutton->func.value_changed_callback = fbutton_callback;
746 fbutton->func.dialog_callback = fdialog_response;
747 return fbutton;
748}
const char * path
Widget_t * w
char * last_path
const char * filter
xevfunc value_changed_callback
Definition xwidget.h:90
xevfunc mem_free_callback
Definition xwidget.h:92
xevfunc dialog_callback
Definition xwidget.h:96
Gravity gravity
Definition xwidget.h:347
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Resize_t scale
Definition xwidget.h:525
long long flags
Definition xwidget.h:461
void * parent_struct
Definition xwidget.h:473
Func_t func
Definition xwidget.h:481
Widget_t * add_image_toggle_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_image_toggle_button - add a button to a Widget_t connect to func.value_changed_callback to implem...
Definition xbutton.c:89
void widget_get_png(Widget_t *w, const unsigned char *name)
widget_get_png - read png into Widget_t xlib surface
Definition xpngloader.c:75
@ CENTER
Definition xwidget.h:320
@ HAS_MEM
Definition xwidget.h:406

References add_image_toggle_button(), CENTER, Func_t::dialog_callback, FileButton::filter, Widget_t::flags, Widget_t::func, Resize_t::gravity, HAS_MEM, FileButton::is_active, FileButton::last_path, Func_t::mem_free_callback, Widget_t::parent_struct, FileButton::path, Widget_t::scale, Func_t::value_changed_callback, FileButton::w, and widget_get_png().

◆ save_file_dialog()

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-selector could be NULL It will open then in $HOME. The filter to use could be NULL, then the file-selector will show all files.

Returns
Widget_t* - pointer to the Widget_t struct

Definition at line 544 of file xsavefile-dialoge.c.

544 {
545 FileDialog *file_dialog = (FileDialog*)malloc(sizeof(FileDialog));
546
547 file_dialog->xdg_user_dirs = NULL;
548 file_dialog->xdg_dir_counter = 0;
549 file_dialog->fp = (FilePicker*)malloc(sizeof(FilePicker));
550
551#ifdef __linux__
552 parse_xdg_dirs(file_dialog);
553 struct stat sb;
554 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
555 fp_init(file_dialog->fp, path);
556 } else if (stat(file_dialog->home_dir, &sb) == 0 && S_ISDIR(sb.st_mode)) {
557 fp_init(file_dialog->fp, file_dialog->home_dir);
558 } else {
559 fp_init(file_dialog->fp, "/");
560 }
561#else
562 DWORD attr = GetFileAttributes(path);
563 if (attr&FILE_ATTRIBUTE_DIRECTORY) {
564 fp_init(file_dialog->fp, path);
565 } else {
566 fp_init(file_dialog->fp, "c:\\");
567 }
568
569#endif
570
571 file_dialog->parent = w;
572 file_dialog->send_clear_func = true;
573
574 file_dialog->w = create_window(w->app, os_get_root_window(w->app, IS_WINDOW), 0, 0, 660, 420);
575#ifdef __linux__
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);
588#endif
589 file_dialog->w->flags |= HAS_MEM;
590 file_dialog->w->parent_struct = file_dialog;
591 widget_set_title(file_dialog->w, _("File Save"));
592 file_dialog->w->func.expose_callback = draw_window;
593 file_dialog->w->func.key_press_callback = forward_key_press;
594 file_dialog->w->func.mem_free_callback = fd_mem_free;
595 widget_set_icon_from_png(file_dialog->w,LDVAR(directory_png));
596
597 file_dialog->ct = add_combobox(file_dialog->w, "", 20, 40, 550, 30);
598 file_dialog->ct->parent_struct = file_dialog;
599 file_dialog->ct->scale.gravity = NORTHEAST;
600 file_dialog->ct->func.value_changed_callback = combo_response;
601 file_dialog->ct->func.key_press_callback = forward_key_press;
602
603 file_dialog->sel_dir = add_button(file_dialog->w, _("Open"), 580, 40, 60, 30);
604 file_dialog->sel_dir->parent_struct = file_dialog;
605 file_dialog->sel_dir->scale.gravity = WESTNORTH;
606 add_tooltip(file_dialog->sel_dir,_("Open sub-directory's"));
607 file_dialog->sel_dir->func.value_changed_callback = open_dir_callback;
608 file_dialog->sel_dir->func.key_press_callback = forward_key_press;
609
610 file_dialog->ft = add_listview(file_dialog->w, "", 130, 90, 510, 225);
611 file_dialog->ft->parent_struct = file_dialog;
612 file_dialog->ft->scale.gravity = NORTHWEST;
613 listview_set_check_dir(file_dialog->ft, 1);
614 file_dialog->ft->func.key_press_callback = forward_key_press;
615
616 int ds = fp_get_files(file_dialog->fp,file_dialog->fp->path, 1, 1);
617 int set_f = set_files(file_dialog);
618 set_dirs(file_dialog);
619 combobox_set_active_entry(file_dialog->ct, ds);
620 if (set_f != -1) {
621 listview_set_active_entry(file_dialog->ft, set_f);
622 } else {
623 listview_unset_active_entry(file_dialog->ft);
624 }
625 file_dialog->ft->func.value_changed_callback = file_released_callback;
626
627#ifdef __linux__
628 add_xdg_dirs(file_dialog);
629#endif
630 file_dialog->text_entry = create_widget(file_dialog->w->app, file_dialog->w, 130, 320, 200, 30);
631 memset(file_dialog->text_entry->input_label, 0, 32 * (sizeof file_dialog->text_entry->input_label[0]) );
632 file_dialog->text_entry->func.expose_callback = entry_add_text;
633 file_dialog->text_entry->func.key_press_callback = entry_get_text;
634 file_dialog->text_entry->flags &= ~USE_TRANSPARENCY;
635 file_dialog->text_entry->scale.gravity = EASTWEST;
636 file_dialog->text_entry->parent_struct = file_dialog;
637#ifdef __linux__
638 Cursor c = XCreateFontCursor(file_dialog->w->app->dpy, XC_xterm);
639 XDefineCursor (file_dialog->w->app->dpy, file_dialog->text_entry->widget, c);
640 XFreeCursor(file_dialog->w->app->dpy, c);
641#endif
642
643 file_dialog->w_quit = add_button(file_dialog->w, _("Cancel"), 580, 350, 60, 60);
644 file_dialog->w_quit->parent_struct = file_dialog;
645 file_dialog->w_quit->scale.gravity = SOUTHWEST;
646 add_tooltip(file_dialog->w_quit,_("Exit File Saver"));
647 file_dialog->w_quit->func.value_changed_callback = button_quit_callback;
648 file_dialog->w_quit->func.key_press_callback = forward_key_press;
649
650 file_dialog->w_okay = add_button(file_dialog->w, _("Save"), 490, 350, 80, 60);
651 file_dialog->w_okay->parent_struct = file_dialog;
652 file_dialog->w_okay->scale.gravity = SOUTHWEST;
653 add_tooltip(file_dialog->w_okay,_("Save as selected file"));
654 file_dialog->w_okay->func.value_changed_callback = button_ok_callback;
655 file_dialog->w_okay->func.key_press_callback = forward_key_press;
656
657 file_dialog->set_filter = add_combobox(file_dialog->w, "", 340, 355, 120, 30);
658 file_dialog->set_filter->parent_struct = file_dialog;
659 file_dialog->set_filter->scale.gravity = SOUTHWEST;
660 combobox_add_entry(file_dialog->set_filter,_("all"));
661 combobox_add_entry(file_dialog->set_filter,_("application"));
662 combobox_add_entry(file_dialog->set_filter,_("audio"));
663 combobox_add_entry(file_dialog->set_filter,_("font"));
664 combobox_add_entry(file_dialog->set_filter,_("image"));
665 combobox_add_entry(file_dialog->set_filter,_("text"));
666 combobox_add_entry(file_dialog->set_filter,_("video"));
667 combobox_add_entry(file_dialog->set_filter,_("x-content"));
668 if(filter !=NULL && strlen(filter))
669 combobox_add_entry(file_dialog->set_filter,filter);
670 combobox_set_active_entry(file_dialog->set_filter, 0);
671 file_dialog->set_filter->func.key_press_callback = forward_key_press;
672 file_dialog->set_filter->func.value_changed_callback = set_filter_callback;
673 if(filter !=NULL && strlen(filter))
674 combobox_set_active_entry(file_dialog->set_filter, 8);
675 add_tooltip(file_dialog->set_filter->childlist->childs[0], _("File filter type"));
676
677 file_dialog->w_hidden = add_check_button(file_dialog->w, "", 20, 365, 20, 20);
678 file_dialog->w_hidden->parent_struct = file_dialog;
679 file_dialog->w_hidden->scale.gravity = EASTWEST;
680 add_tooltip(file_dialog->w_hidden,_("Show hidden files and folders"));
681 file_dialog->w_hidden->func.key_press_callback = forward_key_press;
682 file_dialog->w_hidden->func.value_changed_callback = button_hidden_callback;
683
684 widget_show_all(file_dialog->w);
685 return file_dialog->w;
686}
Widget_t ** childs
Definition xchildlist.h:51
const char * home_dir
Widget_t * ft
Widget_t * w_quit
FilePicker * fp
bool send_clear_func
Widget_t * sel_dir
Widget_t * ct
Widget_t * w
unsigned int xdg_dir_counter
Widget_t * w_okay
Widget_t * text_entry
char ** xdg_user_dirs
Widget_t * w_hidden
Widget_t * set_filter
Widget_t * parent
char * path
Definition xfilepicker.h:65
xevfunc expose_callback
Definition xwidget.h:85
evfunc key_press_callback
Definition xwidget.h:104
Window widget
Definition xwidget.h:469
Childlist_t * childlist
Definition xwidget.h:499
char input_label[32]
Definition xwidget.h:459
Xputty * app
Definition xwidget.h:465
Display * dpy
Definition xputty.h:232
Widget_t * add_check_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_check_button - add a button to a Widget_t connect to func.value_changed_callback to implement you...
Definition xbutton.c:121
Widget_t * add_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_button - add a button to a Widget_t connect to func.value_changed_callback to implement your acti...
Definition xbutton.c:26
void combobox_set_active_entry(Widget_t *w, int active)
combobox_set_active_entry - set the active combobox entry
Definition xcombobox.c:27
void combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Definition xcombobox.c:175
Widget_t * add_combobox(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_combobox - add a combobox
Definition xcombobox.c:152
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
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
Definition xlistview.c:72
void listview_set_check_dir(Widget_t *listview, int set)
listview_set_check_dir - set optional check if list item is a directory
Definition xlistview.c:134
void listview_set_active_entry(Widget_t *w, int active)
listview_set_active_entry - set the active listview entry
Definition xlistview.c:28
void listview_unset_active_entry(Widget_t *w)
listview_unset_active_entry - unset the active listview entry
Definition xlistview.c:39
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 ...
Definition xpngloader.c:159
void add_tooltip(Widget_t *w, const char *label)
add_tooltip - add a tooltip to Widget_t
Definition xtooltip.c:41
Window os_get_root_window(Xputty *main, int flag)
os_get_root_window - get a pointer to the root window (desktop)
void widget_set_title(Widget_t *w, const char *title)
widget_set_title - set window title for a Widget_t
Definition xwidget.c:359
Widget_t * create_widget(Xputty *app, Widget_t *win, int x, int y, int width, int height)
*create_widget - create a widget A Widget_t could only be created as child of a other Widget_t To...
Definition xwidget.c:265
Widget_t * create_window(Xputty *app, Window win, int x, int y, int width, int height)
*create_window - create a Window You need to create as least minimun one Window to get started....
Definition xwidget.c:163
@ EASTWEST
Definition xwidget.h:310
@ SOUTHWEST
Definition xwidget.h:304
@ NORTHEAST
Definition xwidget.h:302
@ NORTHWEST
Definition xwidget.h:300
@ WESTNORTH
Definition xwidget.h:316
@ IS_WINDOW
Definition xwidget.h:390
void widget_show_all(Widget_t *w)
widget_show_all - map/show Widget_t with all childs
Definition xwidget.c:386

References add_button(), add_check_button(), add_combobox(), add_listview(), add_tooltip(), Widget_t::app, Widget_t::childlist, Childlist_t::childs, combobox_add_entry(), combobox_set_active_entry(), create_widget(), create_window(), FileDialog::ct, Xputty::dpy, EASTWEST, Func_t::expose_callback, Widget_t::flags, FileDialog::fp, fp_get_files(), fp_init(), FileDialog::ft, Widget_t::func, Resize_t::gravity, HAS_MEM, FileDialog::home_dir, Widget_t::input_label, IS_WINDOW, Func_t::key_press_callback, listview_set_active_entry(), listview_set_check_dir(), listview_unset_active_entry(), Func_t::mem_free_callback, NORTHEAST, NORTHWEST, os_get_root_window(), FileDialog::parent, Widget_t::parent_struct, FilePicker::path, Widget_t::scale, FileDialog::sel_dir, FileDialog::send_clear_func, FileDialog::set_filter, SOUTHWEST, FileDialog::text_entry, Func_t::value_changed_callback, FileDialog::w, FileDialog::w_hidden, FileDialog::w_okay, FileDialog::w_quit, WESTNORTH, Widget_t::widget, widget_set_icon_from_png(), widget_set_title(), widget_show_all(), FileDialog::xdg_dir_counter, and FileDialog::xdg_user_dirs.