26#define G_LOG_DOMAIN "Modes.RecursiveBrowser"
39#include <glib/gstdio.h>
56#define DEFAULT_OPEN "xdg-open"
74 uint32_t icon_fetch_uid;
75 uint32_t icon_fetch_size;
84 unsigned int array_length;
85 unsigned int array_length_real;
108#include <sys/types.h>
122 gboolean found_error = FALSE;
133 GError *error = NULL;
134 g_debug(
"compile regex: %s\n", p->
value.
s);
137 msg = g_strdup_printf(
"\"%s\" is not a valid regex for filtering: %s",
138 p->
value.
s, error->message);
144 g_debug(
"compile default regex\n");
145 pd->
filter_regex = g_regex_new(
"^(\\..*)", G_REGEX_OPTIMIZE, 0, NULL);
169 gboolean config_has_valid_dir = p != NULL && p->
type ==
P_STRING &&
170 g_file_test(p->
value.
s, G_FILE_TEST_IS_DIR);
172 if (config_has_valid_dir) {
176 pd->
current_dir = g_file_new_for_path(g_get_home_dir());
181 GQueue *dirs_to_scan = g_queue_new();
182 g_queue_push_tail(dirs_to_scan, g_object_ref(path));
183 GFile *dir_to_scan = NULL;
184 while ((dir_to_scan = g_queue_pop_head(dirs_to_scan)) != NULL) {
185 char *cdir = g_file_get_path(dir_to_scan);
186 DIR *dir = opendir(cdir);
187 g_object_unref(dir_to_scan);
189 struct dirent *rd = NULL;
190 while (pd->
end_thread == FALSE && (rd = readdir(dir)) != NULL) {
191 if (g_strcmp0(rd->d_name,
"..") == 0) {
194 if (g_strcmp0(rd->d_name,
".") == 0) {
201 switch (rd->d_type) {
211 f->
path = g_build_filename(cdir, rd->d_name, NULL);
212 f->
name = g_filename_to_utf8(f->
path, -1, NULL, NULL, NULL);
213 if (f->
name == NULL) {
216 if (f->
name == NULL) {
217 f->
name = g_strdup(
"n/a");
225 if (g_async_queue_length(pd->
async_queue) > 10000) {
231 char *d = g_build_filename(cdir, rd->d_name, NULL);
232 GFile *dirp = g_file_new_for_path(d);
233 g_queue_push_tail(dirs_to_scan, dirp);
241 f->
path = g_build_filename(cdir, rd->d_name, NULL);
242 f->
name = g_filename_to_utf8(f->
path, -1, NULL, NULL, NULL);
243 if (f->
name == NULL) {
246 if (f->
name == NULL) {
247 f->
name = g_strdup(
"n/a");
253 if (rd->d_type == DT_LNK) {
270 if (g_stat(f->
path, &statbuf) == 0) {
271 if (S_ISDIR(statbuf.st_mode)) {
272 char *new_full_path =
273 g_build_filename(cdir, rd->d_name, NULL);
278 GFile *dirp = g_file_new_for_path(new_full_path);
279 g_queue_push_tail(dirs_to_scan, dirp);
280 g_free(new_full_path);
282 }
else if (S_ISREG(statbuf.st_mode)) {
287 g_warning(
"Failed to stat file: %s, %s", f->
path,
296 if (g_async_queue_length(pd->
async_queue) > 10000) {
309 g_queue_free(dirs_to_scan);
313 GTimer *t = g_timer_new();
314 g_debug(
"Start scan.\n");
318 double f = g_timer_elapsed(t, NULL);
319 g_debug(
"End scan: %f\n", f);
324 GIOCondition condition,
325 gpointer user_data) {
329 if ((condition & G_IO_IN) != G_IO_IN) {
330 return G_SOURCE_CONTINUE;
333 if (read(fd, &command, 1) == 1) {
334 if (command ==
'r') {
336 gboolean changed = FALSE;
339 while ((block = g_async_queue_try_pop(pd->
async_queue)) != NULL) {
350 }
else if (command ==
'q') {
356 return G_SOURCE_CONTINUE;
372 g_error(
"Failed to create pipe");
393 G_GNUC_UNUSED
char **input,
394 unsigned int selected_line) {
411 }
else if ((mretv &
MENU_OK)) {
412 if (selected_line < pd->array_length) {
414 char *d_esc = g_shell_quote(pd->
array[selected_line].
path);
415 char *cmd = g_strdup_printf(
"%s %s", pd->
command, d_esc);
453 G_GNUC_UNUSED
int *state,
454 G_GNUC_UNUSED GList **attr_list,
464 return g_strdup(
" ..");
467 return g_strconcat(
"@", pd->
array[selected_line].
name, NULL);
469 return g_strdup(pd->
array[selected_line].
name);
483 unsigned int index) {
491static cairo_surface_t *
_get_icon(
const Mode *sw,
unsigned int selected_line,
492 unsigned int height) {
495 g_return_val_if_fail(pd->
array != NULL, NULL);
500 gchar *_path = g_strconcat(
"thumbnail://", dr->
path, NULL);
515 char *dirname = g_file_get_parse_name(pd->
current_dir);
517 g_markup_printf_escaped(
"<b>Current directory:</b> %s", dirname);
528 char *d = g_strescape(pd->
array[index].
path, NULL);
543 unsigned int selected_line,
549 if (selected_line < pd->array_length) {
551 *path = g_strescape(pd->
array[selected_line].
path, NULL);
566 .display_name = NULL,
568 .name =
"recursivebrowser",
569 .cfg_name_key =
"display-recursivebrowser",
579 ._preprocess_input = NULL,
582 .private_data = NULL,
static char * _get_message(const Mode *sw)
static char * _get_completion(const Mode *sw, unsigned int index)
static cairo_surface_t * _get_icon(const Mode *sw, unsigned int selected_line, unsigned int height)
static char * _get_display_value(const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry)
ModeMode recursive_browser_mode_completer(Mode *sw, int mretv, char **input, unsigned int selected_line, char **path)
Mode recursive_browser_mode
Mode * create_new_recursive_browser(void)
Property * rofi_theme_find_property(ThemeWidget *wid, PropertyType type, const char *property, gboolean exact)
gboolean helper_execute_command(const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context)
ThemeWidget * rofi_config_find_widget(const char *name, const char *state, gboolean exact)
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
char * rofi_force_utf8(const gchar *data, ssize_t length)
gboolean rofi_icon_fetcher_file_is_image(const char *const path)
cairo_surface_t * rofi_icon_fetcher_get(const uint32_t uid)
uint32_t rofi_icon_fetcher_query(const char *name, const int size)
void * mode_get_private_data(const Mode *mode)
void mode_set_private_data(Mode *mode, void *pd)
void rofi_set_return_code(int code)
void rofi_view_set_overlay(RofiViewState *state, const char *text)
void rofi_view_reload(void)
int rofi_view_error_dialog(const char *msg, int markup)
RofiViewState * rofi_view_get_active(void)
static char * _get_message(const Mode *sw)
static void free_list(FileBrowserModePrivateData *pd)
static gboolean recursive_browser_async_read_proc(gint fd, GIOCondition condition, gpointer user_data)
const char * rb_icon_name[NUM_FILE_TYPES]
static char * _get_completion(const Mode *sw, unsigned int index)
static void scan_dir(FileBrowserModePrivateData *pd, GFile *path)
static int recursive_browser_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
static cairo_surface_t * _get_icon(const Mode *sw, unsigned int selected_line, unsigned int height)
static void recursive_browser_mode_init_current_dir(Mode *sw)
static void fb_resize_array(FileBrowserModePrivateData *pd)
static void recursive_browser_mode_init_config(Mode *sw)
static unsigned int recursive_browser_mode_get_num_entries(const Mode *sw)
static char * _get_display_value(const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry)
static void recursive_browser_mode_destroy(Mode *sw)
static gpointer recursive_browser_input_thread(gpointer userdata)
static ModeMode recursive_browser_mode_result(Mode *sw, int mretv, G_GNUC_UNUSED char **input, unsigned int selected_line)
static int recursive_browser_mode_init(Mode *sw)
struct rofi_int_matcher_t rofi_int_matcher
GAsyncQueue * async_queue
unsigned int array_length_real
unsigned int array_length