36#include <glib/gstdio.h>
52#define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache"
54#define DEFAULT_OPEN "xdg-open"
57#define st_atim st_atimespec
58#define st_ctim st_ctimespec
59#define st_mtim st_mtimespec
124 .directories_first = TRUE,
125 .show_hidden = FALSE,
140#include <sys/types.h>
143 G_GNUC_UNUSED gpointer data) {
151 return g_strcmp0(fa->
name, fb->
name);
155 G_GNUC_UNUSED gpointer data) {
174static gint
compare(gconstpointer a, gconstpointer b, gpointer data) {
175 GCompareDataFunc comparator = NULL;
189 return comparator(a, b, data);
195 return statbuf->st_mtim.tv_sec;
197 return statbuf->st_atim.tv_sec;
199 return statbuf->st_ctim.tv_sec;
215 if (g_lstat(file->
path, &statbuf) == 0) {
218 g_warning(
"Failed to stat file: %s, %s", file->
path, strerror(errno));
240 DIR *dir = opendir(cdir);
242 struct dirent *rd = NULL;
243 while ((rd = readdir(dir)) != NULL) {
244 if (g_strcmp0(rd->d_name,
"..") == 0) {
257 if (g_strcmp0(rd->d_name,
".") == 0) {
264 switch (rd->d_type) {
277 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
282 g_build_filename(cdir, rd->d_name, NULL);
299 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
304 g_build_filename(cdir, rd->d_name, NULL);
322 if (S_ISDIR(statbuf.st_mode)) {
324 }
else if (S_ISREG(statbuf.st_mode)) {
332 g_warning(
"Failed to stat file: %s, %s",
353 gboolean found_error = FALSE;
359 if (g_strcmp0(p->
value.
s,
"name") == 0) {
361 }
else if (g_strcmp0(p->
value.
s,
"mtime") == 0) {
364 }
else if (g_strcmp0(p->
value.
s,
"atime") == 0) {
367 }
else if (g_strcmp0(p->
value.
s,
"ctime") == 0) {
373 msg = g_strdup_printf(
"\"%s\" is not a valid filebrowser sorting method",
410 gboolean config_has_valid_dir = p != NULL && p->
type ==
P_STRING &&
411 g_file_test(p->
value.
s, G_FILE_TEST_IS_DIR);
413 if (config_has_valid_dir) {
416 char *current_dir = NULL;
420 if (g_file_get_contents(cache_file, ¤t_dir, NULL, NULL)) {
421 if (g_file_test(current_dir, G_FILE_TEST_IS_DIR)) {
422 pd->
current_dir = g_file_new_for_path(current_dir);
433 pd->
current_dir = g_file_new_for_path(g_get_home_dir());
460 unsigned int selected_line) {
474 gboolean special_command =
478 }
else if ((mretv &
MENU_OK)) {
479 if (selected_line < pd->array_length) {
492 char *d_esc = g_shell_quote(pd->
array[selected_line].
path);
493 char *cmd = g_strdup_printf(
"%s %s", pd->
command, d_esc);
502 g_file_set_contents(path, pd->
array[selected_line].
path, -1, NULL);
504 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
514 if (special_command) {
526 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
528 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
529 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
563 G_GNUC_UNUSED
int *state,
564 G_GNUC_UNUSED GList **attr_list,
574 return g_strdup(
" ..");
577 return g_strconcat(
"@", pd->
array[selected_line].
name, NULL);
579 return g_strdup(pd->
array[selected_line].
name);
592 unsigned int index) {
600static cairo_surface_t *
_get_icon(
const Mode *sw,
unsigned int selected_line,
601 unsigned int height) {
604 g_return_val_if_fail(pd->
array != NULL, NULL);
609 gchar* _path = g_strconcat(
"thumbnail://", dr->
path, NULL);
623 char *dirname = g_file_get_parse_name(pd->
current_dir);
625 g_markup_printf_escaped(
"<b>Current directory:</b> %s", dirname);
636 char *d = g_strescape(pd->
array[index].
path, NULL);
651 unsigned int selected_line,
char **path) {
656 if (selected_line < pd->array_length) {
667 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
674 *path = g_strescape(pd->
array[selected_line].
path, NULL);
681 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
683 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
684 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
707 .name =
"filebrowser",
708 .cfg_name_key =
"display-filebrowser",
718 ._preprocess_input = NULL,
721 .private_data = NULL,
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 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)
enum FBSortingMethod sorting_method
enum FBSortingTime sorting_time
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)
struct @122133055311334107350014243023035034374212064377 file_browser_config
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]
gboolean directories_first
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