35#include <glib/gstdio.h>
51#define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache"
54#define st_atim st_atimespec
55#define st_ctim st_ctimespec
56#define st_mtim st_mtimespec
118 .directories_first = TRUE,
133#include <sys/types.h>
136 G_GNUC_UNUSED gpointer data) {
144 return g_strcmp0(fa->
name, fb->
name);
148 G_GNUC_UNUSED gpointer data) {
167static gint
compare(gconstpointer a, gconstpointer b, gpointer data) {
168 GCompareDataFunc comparator = NULL;
182 return comparator(a, b, data);
188 return statbuf->st_mtim.tv_sec;
190 return statbuf->st_atim.tv_sec;
192 return statbuf->st_ctim.tv_sec;
208 if (g_lstat(file->
path, &statbuf) == 0) {
211 g_warning(
"Failed to stat file: %s, %s", file->
path, strerror(errno));
233 DIR *dir = opendir(cdir);
235 struct dirent *rd = NULL;
236 while ((rd = readdir(dir)) != NULL) {
237 if (g_strcmp0(rd->d_name,
"..") == 0) {
250 if (rd->d_name[0] ==
'.') {
254 switch (rd->d_type) {
267 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
272 g_build_filename(cdir, rd->d_name, NULL);
289 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
294 g_build_filename(cdir, rd->d_name, NULL);
312 if (S_ISDIR(statbuf.st_mode)) {
314 }
else if (S_ISREG(statbuf.st_mode)) {
322 g_warning(
"Failed to stat file: %s, %s",
341 gboolean found_error = FALSE;
347 if (g_strcmp0(p->
value.
s,
"name") == 0) {
349 }
else if (g_strcmp0(p->
value.
s,
"mtime") == 0) {
352 }
else if (g_strcmp0(p->
value.
s,
"atime") == 0) {
355 }
else if (g_strcmp0(p->
value.
s,
"ctime") == 0) {
361 msg = g_strdup_printf(
"\"%s\" is not a valid filebrowser sorting method",
386 gboolean config_has_valid_dir = p != NULL && p->
type ==
P_STRING &&
387 g_file_test(p->
value.
s, G_FILE_TEST_IS_DIR);
389 if (config_has_valid_dir) {
392 char *current_dir = NULL;
396 if (g_file_get_contents(cache_file, ¤t_dir, NULL, NULL)) {
397 if (g_file_test(current_dir, G_FILE_TEST_IS_DIR)) {
398 pd->
current_dir = g_file_new_for_path(current_dir);
409 pd->
current_dir = g_file_new_for_path(g_get_home_dir());
436 unsigned int selected_line) {
441 gboolean special_command =
451 }
else if ((mretv &
MENU_OK)) {
452 if (selected_line < pd->array_length) {
465 char *d_esc = g_shell_quote(pd->
array[selected_line].
path);
466 char *cmd = g_strdup_printf(
"xdg-open %s", d_esc);
475 g_file_set_contents(path, pd->
array[selected_line].
path, -1, NULL);
477 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
487 if (special_command) {
499 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
501 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
502 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
532 G_GNUC_UNUSED
int *state,
533 G_GNUC_UNUSED GList **attr_list,
543 return g_strdup(
" ..");
546 return g_strconcat(
"@", pd->
array[selected_line].
name, NULL);
548 return g_strdup(pd->
array[selected_line].
name);
561 unsigned int index) {
569static cairo_surface_t *
_get_icon(
const Mode *sw,
unsigned int selected_line,
570 unsigned int height) {
573 g_return_val_if_fail(pd->
array != NULL, NULL);
591 char *dirname = g_file_get_parse_name(pd->
current_dir);
593 g_markup_printf_escaped(
"<b>Current directory:</b> %s", dirname);
604 char *d = g_strescape(pd->
array[index].
path, NULL);
619 unsigned int selected_line,
char **path) {
629 }
else if ((mretv &
MENU_OK)) {
630 if (selected_line < pd->array_length) {
641 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
648 *path = g_strescape(pd->
array[selected_line].
path, NULL);
655 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
657 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
658 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
679 .name =
"filebrowser",
680 .cfg_name_key =
"display-filebrowser",
690 ._preprocess_input = NULL,
691 .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)
struct @0 file_browser_config
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)
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)
gboolean helper_execute_command(const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context)
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)
int rofi_view_error_dialog(const char *msg, int markup)
unsigned int array_length_real
unsigned int array_length
Property * rofi_theme_find_property(ThemeWidget *widget, PropertyType type, const char *property, gboolean exact)
ThemeWidget * rofi_config_find_widget(const char *name, const char *state, gboolean exact)