36#include <glib/gstdio.h>
53#define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache"
55#define DEFAULT_OPEN "xdg-open"
58#define st_atim st_atimespec
59#define st_ctim st_ctimespec
60#define st_mtim st_mtimespec
128 .directories_first = TRUE,
129 .show_hidden = FALSE,
145#include <sys/types.h>
148 G_GNUC_UNUSED gpointer data) {
160 G_GNUC_UNUSED gpointer data) {
179static gint
compare(gconstpointer a, gconstpointer b, gpointer data) {
180 GCompareDataFunc comparator = NULL;
194 return comparator(a, b, data);
200 return statbuf->st_mtim.tv_sec;
202 return statbuf->st_atim.tv_sec;
204 return statbuf->st_ctim.tv_sec;
220 if (g_lstat(file->
path, &statbuf) == 0) {
223 g_warning(
"Failed to stat file: %s, %s", file->
path, strerror(errno));
249 DIR *dir = opendir(cdir);
251 struct dirent *rd = NULL;
252 while ((rd = readdir(dir)) != NULL) {
253 if (g_strcmp0(rd->d_name,
"..") == 0) {
268 if (g_strcmp0(rd->d_name,
".") == 0) {
275 switch (rd->d_type) {
288 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
293 g_build_filename(cdir, rd->d_name, NULL);
313 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
318 g_build_filename(cdir, rd->d_name, NULL);
342 if (S_ISDIR(statbuf.st_mode)) {
344 }
else if (S_ISREG(statbuf.st_mode)) {
352 g_warning(
"Failed to stat file: %s, %s",
373 gboolean found_error = FALSE;
379 if (g_strcmp0(p->
value.
s,
"name") == 0) {
381 }
else if (g_strcmp0(p->
value.
s,
"mtime") == 0) {
384 }
else if (g_strcmp0(p->
value.
s,
"atime") == 0) {
387 }
else if (g_strcmp0(p->
value.
s,
"ctime") == 0) {
393 msg = g_strdup_printf(
"\"%s\" is not a valid filebrowser sorting method",
430 gboolean config_has_valid_dir = p != NULL && p->
type ==
P_STRING &&
431 g_file_test(p->
value.
s, G_FILE_TEST_IS_DIR);
433 if (config_has_valid_dir) {
436 char *current_dir = NULL;
440 if (g_file_get_contents(cache_file, ¤t_dir, NULL, NULL)) {
441 if (g_file_test(current_dir, G_FILE_TEST_IS_DIR)) {
442 pd->
current_dir = g_file_new_for_path(current_dir);
453 pd->
current_dir = g_file_new_for_path(g_get_home_dir());
480 unsigned int selected_line) {
494 gboolean special_command =
498 }
else if ((mretv &
MENU_OK)) {
499 if (selected_line < pd->array_length) {
512 char *d_esc = g_shell_quote(pd->
array[selected_line].
path);
513 char *cmd = g_strdup_printf(
"%s %s", pd->
command, d_esc);
522 g_file_set_contents(path, pd->
array[selected_line].
path, -1, NULL);
524 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
534 if (special_command) {
546 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
548 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
549 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
583 G_GNUC_UNUSED
int *state,
584 G_GNUC_UNUSED GList **attr_list,
594 return g_strdup(
" ..");
597 return g_strconcat(
"@", pd->
array[selected_line].
name, NULL);
599 return g_strdup(pd->
array[selected_line].
name);
612 unsigned int index) {
620static cairo_surface_t *
_get_icon(
const Mode *sw,
unsigned int selected_line,
621 unsigned int height) {
625 g_return_val_if_fail(pd->
array != NULL, NULL);
630 gchar* _path = g_strconcat(
"thumbnail://", dr->
path, NULL);
645 char *dirname = g_file_get_parse_name(pd->
current_dir);
647 g_markup_printf_escaped(
"<b>Current directory:</b> %s", dirname);
658 char *d = g_strescape(pd->
array[index].
path, NULL);
673 unsigned int selected_line,
char **path) {
678 if (selected_line < pd->array_length) {
689 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
696 *path = g_strescape(pd->
array[selected_line].
path, NULL);
703 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
705 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
706 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
729 .name =
"filebrowser",
730 .cfg_name_key =
"display-filebrowser",
740 ._preprocess_input = NULL,
743 .private_data = NULL,
guint display_scale(void)
static int file_browser_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
static char * _get_message(const Mode *sw)
static void free_list(FileBrowserModePrivateData *pd)
static char * _get_completion(const Mode *sw, unsigned int index)
static unsigned int file_browser_mode_get_num_entries(const Mode *sw)
static void set_collate_key(FBFile *file)
static cairo_surface_t * _get_icon(const Mode *sw, unsigned int selected_line, unsigned int height)
static void file_browser_mode_init_current_dir(Mode *sw)
static void fb_resize_array(FileBrowserModePrivateData *pd)
static void set_time(FBFile *file)
#define FILEBROWSER_CACHE_FILE
static gint compare_time(gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data)
static void file_browser_mode_destroy(Mode *sw)
static gint compare_name(gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data)
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 get_file_browser(Mode *sw)
static int file_browser_mode_init(Mode *sw)
static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, unsigned int selected_line)
static void file_browser_mode_init_config(Mode *sw)
const char * icon_name[NUM_FILE_TYPES]
struct @303157304314304337251010176020112243365265147046 file_browser_config
static time_t get_time(const GStatBuf *statbuf)
static gint compare(gconstpointer a, gconstpointer b, gpointer data)
Mode * create_new_file_browser(void)
ModeMode file_browser_mode_completer(Mode *sw, int mretv, char **input, unsigned int selected_line, char **path)
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)
char * rofi_expand_path(const char *input)
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)
int rofi_view_error_dialog(const char *msg, int markup)
struct rofi_int_matcher_t rofi_int_matcher
unsigned int array_length_real
unsigned int array_length
enum FBSortingTime sorting_time
enum FBSortingMethod sorting_method
gboolean directories_first
_mode_completer_result _completer_result