libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xsavefile-dialoge.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 "xmessage-dialog.h"
Include dependency graph for xsavefile-dialoge.c:

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. More...
 
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. More...
 

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 534 of file xsavefile-dialoge.c.

535  {
536  FileButton *filebutton = (FileButton*)malloc(sizeof(FileButton));
537  filebutton->path = path;
538  filebutton->filter = filter;
539  filebutton->last_path = NULL;
540  filebutton->w = NULL;
541  filebutton->is_active = false;
542  Widget_t *fbutton = add_image_toggle_button(parent, "", x, y, width, height);
543  fbutton->parent_struct = filebutton;
544  fbutton->flags |= HAS_MEM;
545  widget_get_png(fbutton, LDVAR(directory_open_png));
546  fbutton->scale.gravity = CENTER;
547  fbutton->func.mem_free_callback = fbutton_mem_free;
548  fbutton->func.value_changed_callback = fbutton_callback;
549  fbutton->func.dialog_callback = fdialog_response;
550  return fbutton;
551 }

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().

◆ 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 401 of file xsavefile-dialoge.c.

401  {
402  FileDialog *file_dialog = (FileDialog*)malloc(sizeof(FileDialog));
403 
404  file_dialog->fp = (FilePicker*)malloc(sizeof(FilePicker));
405  fp_init(file_dialog->fp, (path) ? path : "/");
406  file_dialog->parent = w;
407  file_dialog->send_clear_func = true;
408  file_dialog->icon = NULL;
409 
410  file_dialog->w = create_window(w->app, DefaultRootWindow(w->app->dpy), 0, 0, 660, 420);
411  file_dialog->w->flags |= HAS_MEM;
412  file_dialog->w->parent_struct = file_dialog;
413  widget_set_title(file_dialog->w, "File Save");
414  file_dialog->w->func.expose_callback = draw_window;
415  file_dialog->w->func.key_press_callback = forward_key_press;
416  file_dialog->w->func.mem_free_callback = fd_mem_free;
417  widget_set_icon_from_png(file_dialog->w,file_dialog->icon,LDVAR(directory_png));
418 
419  file_dialog->ct = add_combobox(file_dialog->w, "", 20, 40, 550, 30);
420  file_dialog->ct->parent_struct = file_dialog;
421  file_dialog->ct->func.value_changed_callback = combo_response;
422  file_dialog->ct->func.key_press_callback = forward_key_press;
423 
424  file_dialog->sel_dir = add_button(file_dialog->w, "Open", 580, 40, 60, 30);
425  file_dialog->sel_dir->parent_struct = file_dialog;
426  file_dialog->sel_dir->scale.gravity = CENTER;
427  add_tooltip(file_dialog->sel_dir,"Open sub-directory's");
428  file_dialog->sel_dir->func.value_changed_callback = open_dir_callback;
429  file_dialog->sel_dir->func.key_press_callback = forward_key_press;
430 
431  file_dialog->ft = add_listview(file_dialog->w, "", 20, 90, 620, 225);
432  file_dialog->ft->parent_struct = file_dialog;
433  file_dialog->ft->func.key_press_callback = forward_key_press;
434 
435  int ds = fp_get_files(file_dialog->fp,file_dialog->fp->path, 1);
436  int set_f = set_files(file_dialog);
437  set_dirs(file_dialog);
438  combobox_set_active_entry(file_dialog->ct, ds);
439  listview_set_active_entry(file_dialog->ft, set_f);
440  file_dialog->ft->func.value_changed_callback = file_released_callback;
441 
442  file_dialog->text_entry = create_widget(file_dialog->w->app, file_dialog->w, 80, 320, 200, 30);
443  memset(file_dialog->text_entry->input_label, 0, 32 * (sizeof file_dialog->text_entry->input_label[0]) );
444  file_dialog->text_entry->func.expose_callback = entry_add_text;
445  file_dialog->text_entry->func.key_press_callback = entry_get_text;
446  file_dialog->text_entry->flags &= ~USE_TRANSPARENCY;
447  file_dialog->text_entry->scale.gravity = CENTER;
448 
449  file_dialog->w_quit = add_button(file_dialog->w, "Quit", 580, 350, 60, 60);
450  file_dialog->w_quit->parent_struct = file_dialog;
451  file_dialog->w_quit->scale.gravity = CENTER;
452  add_tooltip(file_dialog->w_quit,"Exit File Saver");
453  file_dialog->w_quit->func.value_changed_callback = button_quit_callback;
454  file_dialog->w_quit->func.key_press_callback = forward_key_press;
455 
456  file_dialog->w_okay = add_button(file_dialog->w, "Save", 510, 350, 60, 60);
457  file_dialog->w_okay->parent_struct = file_dialog;
458  file_dialog->w_okay->scale.gravity = CENTER;
459  add_tooltip(file_dialog->w_okay,"Save as selected file");
460  file_dialog->w_okay->func.value_changed_callback = button_ok_callback;
461  file_dialog->w_okay->func.key_press_callback = forward_key_press;
462 
463  file_dialog->set_filter = add_combobox(file_dialog->w, "", 360, 355, 120, 30);
464  file_dialog->set_filter->parent_struct = file_dialog;
465  combobox_add_entry(file_dialog->set_filter,"all");
466  combobox_add_entry(file_dialog->set_filter,"application");
467  combobox_add_entry(file_dialog->set_filter,"audio");
468  combobox_add_entry(file_dialog->set_filter,"font");
469  combobox_add_entry(file_dialog->set_filter,"image");
470  combobox_add_entry(file_dialog->set_filter,"text");
471  combobox_add_entry(file_dialog->set_filter,"video");
472  combobox_add_entry(file_dialog->set_filter,"x-content");
473  if(filter !=NULL && strlen(filter))
474  combobox_add_entry(file_dialog->set_filter,filter);
475  combobox_set_active_entry(file_dialog->set_filter, 0);
476  file_dialog->set_filter->func.value_changed_callback = set_filter_callback;
477  if(filter !=NULL && strlen(filter))
478  combobox_set_active_entry(file_dialog->set_filter, 8);
479  add_tooltip(file_dialog->set_filter->childlist->childs[0], "File filter type");
480 
481  file_dialog->w_hidden = add_check_button(file_dialog->w, "", 20, 365, 20, 20);
482  file_dialog->w_hidden->parent_struct = file_dialog;
483  file_dialog->w_hidden->scale.gravity = CENTER;
484  add_tooltip(file_dialog->w_hidden,"Show hidden files and folders");
485  file_dialog->w_hidden->func.value_changed_callback = button_hidden_callback;
486 
487  widget_show_all(file_dialog->w);
488  return file_dialog->w;
489 }

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
create_widget
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:268
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
Func_t::key_press_callback
evfunc key_press_callback
Definition: xwidget.h:96
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
USE_TRANSPARENCY
@ USE_TRANSPARENCY
Definition: xwidget.h:243
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::text_entry
Widget_t * text_entry
Definition: xfile-dialog.h:45
Widget_t::input_label
char input_label[32]
Definition: xwidget.h:328
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