Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
6.1KB

  1. /* libSOFD - Simple Open File Dialog [for X11 without toolkit]
  2. *
  3. * Copyright (C) 2014 Robin Gareus <robin@gareus.org>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #ifndef LIBSOFD_H
  24. #define LIBSOFD_H 1
  25. #ifdef HAVE_X11
  26. #include <X11/Xlib.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. ///////////////////////////////////////////////////////////////////////////////
  31. /* public API */
  32. /** open a file select dialog
  33. * @param dpy X Display connection
  34. * @param parent (optional) if not NULL, become transient for given window
  35. * @param x if >0 set explict initial width of the window
  36. * @param y if >0 set explict initial height of the window
  37. * @return 0 on success
  38. */
  39. int x_fib_show (Display *dpy, Window parent, int x, int y, double scalefactor);
  40. /** force close the dialog.
  41. * This is normally not needed, the dialog closes itself
  42. * when a file is selected or the user cancels selection.
  43. * @param dpy X Display connection
  44. */
  45. void x_fib_close (Display *dpy);
  46. /** non-blocking X11 event handler.
  47. * It is safe to run this function even if the dialog is
  48. * closed or was not initialized.
  49. *
  50. * @param dpy X Display connection
  51. * @param event the XEvent to process
  52. * @return status
  53. * 0: the event was not for this window, or file-dialog still
  54. * active, or the dialog window is not displayed.
  55. * >0: file was selected, dialog closed
  56. * <0: file selection was cancelled.
  57. */
  58. int x_fib_handle_events (Display *dpy, XEvent *event);
  59. /** last status of the dialog
  60. * @return >0: file was selected, <0: canceled or inactive. 0: active
  61. */
  62. int x_fib_status ();
  63. /** query the selected filename
  64. * @return NULL if none set, or allocated string to be free()ed by the called
  65. */
  66. char *x_fib_filename ();
  67. /** customize/configure the dialog before calling \ref x_fib_show
  68. * changes only have any effect if the dialog is not visible.
  69. * @param k key to change
  70. * 0: set current dir to display (must end with slash)
  71. * 1: set title of dialog window
  72. * 2: specify a custom X11 font to use
  73. * 3: specify a custom 'places' file to include
  74. * (following gtk-bookmark convention)
  75. * @param v value
  76. * @return 0 on success.
  77. */
  78. int x_fib_configure (int k, const char *v);
  79. /** customize/configure the dialog before calling \ref x_fib_show
  80. * changes only have any effect if the dialog is not visible.
  81. *
  82. * @param k button to change:
  83. * 1: show hidden files
  84. * 2: show places
  85. * 3: show filter/list all (automatically hidden if there is no
  86. * filter function)
  87. * @param v <0 to hide the button >=0 show button,
  88. * 0: set button-state to not-checked
  89. * 1: set button-state to checked
  90. * >1: retain current state
  91. * @return 0 on success.
  92. */
  93. int x_fib_cfg_buttons (int k, int v);
  94. /** set custom callback to filter file-names.
  95. * NULL will disable the filter and hide the 'show all' button.
  96. * changes only have any effect if the dialog is not visible.
  97. *
  98. * @param cb callback function to check file
  99. * the callback function is called with the file name (basename only)
  100. * and is expected to return 1 if the file passes the filter
  101. * and 0 if the file should not be listed by default.
  102. * @return 0 on success.
  103. */
  104. int x_fib_cfg_filter_callback (int (*cb)(const char*));
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif /* END X11 specific functions */
  109. #ifdef __cplusplus
  110. extern "C" {
  111. #endif
  112. /* 'recently used' API. x-platform
  113. * NOTE: all functions use a static cache and are not reentrant.
  114. * It is expected that none of these functions are called in
  115. * parallel from different threads.
  116. */
  117. /** release static resources of 'recently used files'
  118. */
  119. void x_fib_free_recent ();
  120. /** add an entry to the recently used list
  121. *
  122. * The dialog does not add files automatically on open,
  123. * if the application succeeds to open a selected file,
  124. * this function should be called.
  125. *
  126. * @param path complete path to file
  127. * @param atime time of last use, 0: NOW
  128. * @return -1 on error, number of current entries otherwise
  129. */
  130. int x_fib_add_recent (const char *path, time_t atime);
  131. /** get a platform specific path to a good location for
  132. * saving the recently used file list.
  133. * (follows XDG_DATA_HOME on Unix, and CSIDL_LOCAL_APPDATA spec)
  134. *
  135. * @param application-name to use to include in file
  136. * @return pointer to static path or NULL
  137. */
  138. const char *x_fib_recent_file(const char *appname);
  139. /** save the current list of recently used files to the given filename
  140. * (the format is one file per line, filename URL encoded and space separated
  141. * with last-used timestamp)
  142. *
  143. * This function tries to creates the containing directory if it does
  144. * not exist.
  145. *
  146. * @param fn file to save the list to
  147. * @return 0: on success
  148. */
  149. int x_fib_save_recent (const char *fn);
  150. /** load a recently used file list.
  151. *
  152. * @param fn file to load the list from
  153. * @return 0: on success
  154. */
  155. int x_fib_load_recent (const char *fn);
  156. /** get number of entries in the current list
  157. * @return number of entries in the recently used list
  158. */
  159. unsigned int x_fib_recent_count ();
  160. /** get recently used entry at given position
  161. *
  162. * @param i entry to query
  163. * @return pointer to static string
  164. */
  165. const char *x_fib_recent_at (unsigned int i);
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif // header guard