libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xfile-dialog.c File Reference
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
#include "xfile-dialog.h"
Include dependency graph for xfile-dialog.c:

Go to the source code of this file.

Functions

Widget_topen_file_dialog (Widget_t *w, const char *path, const char *filter)
 open_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. More...
 
Widget_tadd_file_button (Widget_t *parent, int x, int y, int width, int height, const char *path, const char *filter)
 add_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. More...
 

Function Documentation

◆ add_file_button()

Widget_t* add_file_button ( Widget_t parent,
int  x,
int  y,
int  width,
int  height,
const char *  path,
const char *  filter 
)

add_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 377 of file xfile-dialog.c.

378  {
379  FileButton *filebutton = (FileButton*)malloc(sizeof(FileButton));
380  filebutton->path = path;
381  filebutton->filter = filter;
382  filebutton->last_path = NULL;
383  filebutton->w = NULL;
384  filebutton->is_active = false;
385  Widget_t *fbutton = add_image_toggle_button(parent, "", x, y, width, height);
386  fbutton->parent_struct = filebutton;
387  fbutton->flags |= HAS_MEM;
388  widget_get_png(fbutton, LDVAR(directory_open_png));
389  fbutton->scale.gravity = CENTER;
390  fbutton->func.mem_free_callback = fbutton_mem_free;
391  fbutton->func.value_changed_callback = fbutton_callback;
392  fbutton->func.dialog_callback = fdialog_response;
393  return fbutton;
394 }

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

◆ open_file_dialog()

Widget_t* open_file_dialog ( Widget_t w,
const char *  path,
const char *  filter 
)

open_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 257 of file xfile-dialog.c.

257  {
258  FileDialog *file_dialog = (FileDialog*)malloc(sizeof(FileDialog));
259 
260  file_dialog->fp = (FilePicker*)malloc(sizeof(FilePicker));
261  fp_init(file_dialog->fp, (path) ? path : "/");
262  file_dialog->parent = w;
263  file_dialog->send_clear_func = true;
264  file_dialog->icon = NULL;
265 
266  file_dialog->w = create_window(w->app, DefaultRootWindow(w->app->dpy), 0, 0, 660, 420);
267  file_dialog->w->flags |= HAS_MEM;
268  file_dialog->w->parent_struct = file_dialog;
269  widget_set_title(file_dialog->w, "File Selector");
270  file_dialog->w->func.expose_callback = draw_window;
271  file_dialog->w->func.mem_free_callback = fd_mem_free;
272  widget_set_icon_from_png(file_dialog->w,file_dialog->icon,LDVAR(directory_png));
273 
274  file_dialog->ct = add_combobox(file_dialog->w, "", 20, 40, 550, 30);
275  file_dialog->ct->parent_struct = file_dialog;
276  file_dialog->ct->func.value_changed_callback = combo_response;
277 
278  file_dialog->sel_dir = add_button(file_dialog->w, "Open", 580, 40, 60, 30);
279  file_dialog->sel_dir->parent_struct = file_dialog;
280  file_dialog->sel_dir->scale.gravity = CENTER;
281  add_tooltip(file_dialog->sel_dir,"Open sub-directory's");
282  file_dialog->sel_dir->func.value_changed_callback = open_dir_callback;
283 
284  file_dialog->ft = add_listview(file_dialog->w, "", 20, 90, 620, 225);
285  file_dialog->ft->parent_struct = file_dialog;
286  file_dialog->ft->func.value_changed_callback = file_released_callback;
287 
288  int ds = fp_get_files(file_dialog->fp,file_dialog->fp->path, 1);
289  int set_f = set_files(file_dialog);
290  set_dirs(file_dialog);
291  combobox_set_active_entry(file_dialog->ct, ds);
292  listview_set_active_entry(file_dialog->ft, set_f);
293 
294  file_dialog->w_quit = add_button(file_dialog->w, "Quit", 580, 350, 60, 60);
295  file_dialog->w_quit->parent_struct = file_dialog;
296  file_dialog->w_quit->scale.gravity = CENTER;
297  add_tooltip(file_dialog->w_quit,"Exit file selector");
298  file_dialog->w_quit->func.value_changed_callback = button_quit_callback;
299 
300  file_dialog->w_okay = add_button(file_dialog->w, "Load", 510, 350, 60, 60);
301  file_dialog->w_okay->parent_struct = file_dialog;
302  file_dialog->w_okay->scale.gravity = CENTER;
303  add_tooltip(file_dialog->w_okay,"Load selected file");
304  file_dialog->w_okay->func.value_changed_callback = button_ok_callback;
305 
306  file_dialog->set_filter = add_combobox(file_dialog->w, "", 360, 355, 120, 30);
307  file_dialog->set_filter->parent_struct = file_dialog;
308  combobox_add_entry(file_dialog->set_filter,"all");
309  combobox_add_entry(file_dialog->set_filter,"application");
310  combobox_add_entry(file_dialog->set_filter,"audio");
311  combobox_add_entry(file_dialog->set_filter,"font");
312  combobox_add_entry(file_dialog->set_filter,"image");
313  combobox_add_entry(file_dialog->set_filter,"text");
314  combobox_add_entry(file_dialog->set_filter,"video");
315  combobox_add_entry(file_dialog->set_filter,"x-content");
316  if(filter !=NULL && strlen(filter))
317  combobox_add_entry(file_dialog->set_filter,filter);
318  combobox_set_active_entry(file_dialog->set_filter, 0);
319  file_dialog->set_filter->func.value_changed_callback = set_filter_callback;
320  if(filter !=NULL && strlen(filter))
321  combobox_set_active_entry(file_dialog->set_filter, 8);
322  add_tooltip(file_dialog->set_filter->childlist->childs[0], "File filter type");
323 
324  file_dialog->w_hidden = add_check_button(file_dialog->w, "", 20, 365, 20, 20);
325  file_dialog->w_hidden->parent_struct = file_dialog;
326  file_dialog->w_hidden->scale.gravity = CENTER;
327  add_tooltip(file_dialog->w_hidden,"Show hidden files and folders");
328  file_dialog->w_hidden->func.value_changed_callback = button_hidden_callback;
329 
330  widget_show_all(file_dialog->w);
331  return file_dialog->w;
332 }

References Widget_t::app, create_window(), Xputty::dpy, Func_t::expose_callback, Widget_t::flags, FileDialog::fp, fp_init(), Widget_t::func, HAS_MEM, FileDialog::icon, FileDialog::parent, Widget_t::parent_struct, FileDialog::send_clear_func, FileDialog::w, and widget_set_title().

FileDialog::w_quit
Widget_t * w_quit
Definition: xfile-dialog.h:40
FileButton::last_path
char * last_path
Definition: xfile-dialog.h:53
fp_get_files
int fp_get_files(FilePicker *filepicker, char *path, int get_dirs)
fp_get_files - fill file_names and dir_names with the results from readdir path
Definition: xfilepicker.c:131
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
widget_set_title
void widget_set_title(Widget_t *w, const char *title)
widget_set_title - set window title for a Widget_t
Definition: xwidget.c:387
FileDialog::ct
Widget_t * ct
Definition: xfile-dialog.h:38
FilePicker::path
char * path
Definition: xfilepicker.h:67
FileButton
Definition: xfile-dialog.h:51
Widget_t::parent_struct
void * parent_struct
Definition: xwidget.h:306
FileDialog::w_hidden
Widget_t * w_hidden
Definition: xfile-dialog.h:42
Childlist_t::childs
Widget_t ** childs
Definition: xchildlist.h:51
combobox_add_entry
Widget_t * combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Definition: xcombobox.c:56
FileDialog::sel_dir
Widget_t * sel_dir
Definition: xfile-dialog.h:43
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
CENTER
@ CENTER
Definition: xwidget.h:165
listview_set_active_entry
void listview_set_active_entry(Widget_t *w, int active)
listview_set_active_entry - set the active listview entry
Definition: xlistview.c:27
FileDialog
Definition: xfile-dialog.h:35
Widget_t::flags
long long flags
Definition: xwidget.h:324
FileDialog::fp
FilePicker * fp
Definition: xfile-dialog.h:47
add_image_toggle_button
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:73
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
FileButton::w
Widget_t * w
Definition: xfile-dialog.h:52
fp_init
void fp_init(FilePicker *filepicker, const char *path)
fp_init - set default values used by the filepicker
Definition: xfilepicker.c:184
FilePicker
Definition: xfilepicker.h:61
FileDialog::icon
Pixmap * icon
Definition: xfile-dialog.h:46
FileButton::filter
const char * filter
Definition: xfile-dialog.h:55
FileDialog::w_okay
Widget_t * w_okay
Definition: xfile-dialog.h:41
HAS_MEM
@ HAS_MEM
Definition: xwidget.h:251
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
FileButton::is_active
bool is_active
Definition: xfile-dialog.h:56
widget_get_png
void widget_get_png(Widget_t *w, const unsigned char *name)
widget_get_png - read png into Widget_t xlib surface
Definition: xpngloader.c:41
combobox_set_active_entry
void combobox_set_active_entry(Widget_t *w, int active)
combobox_set_active_entry - set the active combobox entry
Definition: xcombobox.c:25
FileDialog::w
Widget_t * w
Definition: xfile-dialog.h:37
FileButton::path
const char * path
Definition: xfile-dialog.h:54
FileDialog::ft
Widget_t * ft
Definition: xfile-dialog.h:39
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
FileDialog::set_filter
Widget_t * set_filter
Definition: xfile-dialog.h:44
FileDialog::send_clear_func
bool send_clear_func
Definition: xfile-dialog.h:48
LDVAR
#define LDVAR(NAME)
Definition: xpngloader.h:71
Func_t::mem_free_callback
xevfunc mem_free_callback
Definition: xwidget.h:87
Widget_t::childlist
Childlist_t * childlist
Definition: xwidget.h:336
add_check_button
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:105
create_window
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:145
FileDialog::parent
Widget_t * parent
Definition: xfile-dialog.h:36
Widget_t::func
Func_t func
Definition: xwidget.h:310
widget_set_icon_from_png
void widget_set_icon_from_png(Widget_t *w, Pixmap *icon_, 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:124
add_listview
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:64
add_combobox
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:32
Func_t::value_changed_callback
xevfunc value_changed_callback
Definition: xwidget.h:85
add_tooltip
void add_tooltip(Widget_t *w, const char *label)
add_tooltip - add a tooltip to Widget_t
Definition: xtooltip.c:41
add_button
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
widget_show_all
void widget_show_all(Widget_t *w)
widget_show_all - map/show Widget_t with all childs
Definition: xwidget.c:405
Func_t::dialog_callback
xevfunc dialog_callback
Definition: xwidget.h:91