35 #include <glib/gstdio.h>
37 #include <sys/types.h>
51 #define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache"
111 .directories_first = TRUE,
126 #include <sys/types.h>
129 G_GNUC_UNUSED gpointer data) {
137 return g_strcmp0(fa->
name, fb->
name);
141 G_GNUC_UNUSED gpointer data) {
160 static gint
compare(gconstpointer a, gconstpointer b, gpointer data) {
161 GCompareDataFunc comparator = NULL;
175 return comparator(a, b, data);
181 return statbuf->st_mtim.tv_sec;
183 return statbuf->st_atim.tv_sec;
185 return statbuf->st_ctim.tv_sec;
201 if (g_lstat(file->
path, &statbuf) == 0) {
204 g_warning(
"Failed to stat file: %s, %s", file->
path, strerror(errno));
226 DIR *dir = opendir(cdir);
228 struct dirent *rd = NULL;
229 while ((rd = readdir(dir)) != NULL) {
230 if (g_strcmp0(rd->d_name,
"..") == 0) {
242 if (rd->d_name[0] ==
'.') {
246 switch (rd->d_type) {
259 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
264 g_build_filename(cdir, rd->d_name, NULL);
280 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
285 g_build_filename(cdir, rd->d_name, NULL);
302 if (S_ISDIR(statbuf.st_mode)) {
304 }
else if (S_ISREG(statbuf.st_mode)) {
312 g_warning(
"Failed to stat file: %s, %s",
331 gboolean found_error = FALSE;
337 if (g_strcmp0(p->
value.
s,
"name") == 0) {
339 }
else if (g_strcmp0(p->
value.
s,
"mtime") == 0) {
342 }
else if (g_strcmp0(p->
value.
s,
"atime") == 0) {
345 }
else if (g_strcmp0(p->
value.
s,
"ctime") == 0) {
351 msg = g_strdup_printf(
"\"%s\" is not a valid filebrowser sorting method",
376 gboolean config_has_valid_dir = p != NULL && p->
type ==
P_STRING &&
377 g_file_test(p->
value.
s, G_FILE_TEST_IS_DIR);
379 if (config_has_valid_dir) {
382 char *current_dir = NULL;
386 if (g_file_get_contents(cache_file, ¤t_dir, NULL, NULL)) {
387 if (g_file_test(current_dir, G_FILE_TEST_IS_DIR)) {
388 pd->
current_dir = g_file_new_for_path(current_dir);
399 pd->
current_dir = g_file_new_for_path(g_get_home_dir());
426 unsigned int selected_line) {
438 }
else if ((mretv &
MENU_OK)) {
439 if (selected_line < pd->array_length) {
451 g_file_set_contents(path, pd->
array[selected_line].
path, -1, NULL);
453 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
463 char *d_esc = g_shell_quote(pd->
array[selected_line].
path);
464 char *cmd = g_strdup_printf(
"xdg-open %s", d_esc);
476 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
478 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
479 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
508 G_GNUC_UNUSED
int *state,
509 G_GNUC_UNUSED GList **attr_list,
519 return g_strdup(
" ..");
522 return g_strconcat(
"@", pd->
array[selected_line].
name, NULL);
524 return g_strdup(pd->
array[selected_line].
name);
537 unsigned int index) {
545 static cairo_surface_t *
_get_icon(
const Mode *sw,
unsigned int selected_line,
549 g_return_val_if_fail(pd->
array != NULL, NULL);
566 char *dirname = g_file_get_parse_name(pd->
current_dir);
568 g_markup_printf_escaped(
"<b>Current directory:</b> %s", dirname);
579 char *d = g_strescape(pd->
array[index].
path, NULL);
594 unsigned int selected_line,
char **path) {
604 }
else if ((mretv &
MENU_OK)) {
605 if (selected_line < pd->array_length) {
616 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
623 *path = g_strescape(pd->
array[selected_line].
path, NULL);
630 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
632 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
633 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
654 .name =
"filebrowser",
655 .cfg_name_key =
"display-filebrowser",
665 ._preprocess_input = NULL,
666 .private_data = NULL,
static int file_browser_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
static void free_list(FileBrowserModePrivateData *pd)
static cairo_surface_t * _get_icon(const Mode *sw, unsigned int selected_line, int height)
struct @0 file_browser_config
static unsigned int file_browser_mode_get_num_entries(const Mode *sw)
static char * _get_message(const Mode *sw)
static char * _get_completion(const Mode *sw, unsigned int index)
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 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 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)
ModeMode file_browser_mode_completer(Mode *sw, int mretv, char **input, unsigned int selected_line, char **path)
Mode * create_new_file_browser(void)
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_set_private_data(Mode *mode, void *pd)
void * mode_get_private_data(const Mode *mode)
int rofi_view_error_dialog(const char *msg, int markup)
unsigned int array_length_real
unsigned int array_length
ThemeWidget * rofi_config_find_widget(const char *name, const char *state, gboolean exact)
Property * rofi_theme_find_property(ThemeWidget *widget, PropertyType type, const char *property, gboolean exact)