36 #include <sys/types.h>
50 #define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache"
109 .directories_first = TRUE,
123 #include <sys/types.h>
126 G_GNUC_UNUSED gpointer data) {
134 return g_strcmp0(fa->
name, fb->
name);
138 G_GNUC_UNUSED gpointer data) {
157 static gint
compare(gconstpointer a, gconstpointer b, gpointer data) {
158 GCompareDataFunc comparator = NULL;
172 return comparator(a, b, data);
175 static time_t
get_time(
const struct stat *statbuf) {
178 return statbuf->st_mtim.tv_sec;
180 return statbuf->st_atim.tv_sec;
182 return statbuf->st_ctim.tv_sec;
189 gchar *path = g_filename_from_utf8(file->
path, -1, NULL, NULL, NULL);
193 if (stat(path, &statbuf) == 0) {
196 g_warning(
"Failed to stat file: %s, %s", path, strerror(errno));
210 DIR *dir = opendir(cdir);
212 struct dirent *rd = NULL;
213 while ((rd = readdir(dir)) != NULL) {
214 if (g_strcmp0(rd->d_name,
"..") == 0) {
227 if (rd->d_name[0] ==
'.') {
231 switch (rd->d_type) {
245 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
247 g_build_filename(cdir, rd->d_name, NULL);
264 g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
266 g_build_filename(cdir, rd->d_name, NULL);
277 -1, NULL, NULL, NULL);
280 if (stat(file, &statbuf) == 0) {
281 if (S_ISDIR(statbuf.st_mode)) {
283 }
else if (S_ISREG(statbuf.st_mode)) {
291 g_warning(
"Failed to stat file: %s, %s", file, strerror(errno));
308 gboolean found_error = FALSE;
314 if (g_strcmp0(p->
value.
s,
"name") == 0) {
316 }
else if (g_strcmp0(p->
value.
s,
"mtime") == 0) {
319 }
else if (g_strcmp0(p->
value.
s,
"atime") == 0) {
322 }
else if (g_strcmp0(p->
value.
s,
"ctime") == 0) {
328 msg = g_strdup_printf(
"\"%s\" is not a valid filebrowser sorting method",
353 gboolean config_has_valid_dir = p != NULL && p->
type ==
P_STRING &&
354 g_file_test(p->
value.
s, G_FILE_TEST_IS_DIR);
356 if (config_has_valid_dir) {
359 char *current_dir = NULL;
363 if (g_file_get_contents(cache_file, ¤t_dir, NULL, NULL)) {
364 if (g_file_test(current_dir, G_FILE_TEST_IS_DIR)) {
365 pd->
current_dir = g_file_new_for_path(current_dir);
376 pd->
current_dir = g_file_new_for_path(g_get_home_dir());
403 unsigned int selected_line) {
415 }
else if ((mretv &
MENU_OK)) {
416 if (selected_line < pd->array_length) {
428 g_file_set_contents(path, pd->
array[selected_line].
path, -1, NULL);
430 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
437 char *d = g_filename_from_utf8(pd->
array[selected_line].
path, -1, NULL,
439 char *d_esc = g_shell_quote(d);
440 char *cmd = g_strdup_printf(
"xdg-open %s", d_esc);
453 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
455 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
456 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
485 G_GNUC_UNUSED
int *state,
486 G_GNUC_UNUSED GList **attr_list,
496 return g_strdup(
" ..");
499 return g_strconcat(
"@", pd->
array[selected_line].
name, NULL);
501 return g_strdup(pd->
array[selected_line].
name);
514 unsigned int index) {
522 static cairo_surface_t *
_get_icon(
const Mode *sw,
unsigned int selected_line,
526 g_return_val_if_fail(pd->
array != NULL, NULL);
543 char *dirname = g_file_get_parse_name(pd->
current_dir);
545 g_markup_printf_escaped(
"<b>Current directory:</b> %s", dirname);
556 char *d = g_strescape(pd->
array[index].
path, NULL);
571 unsigned int selected_line,
char **path) {
581 }
else if ((mretv &
MENU_OK)) {
582 if (selected_line < pd->array_length) {
593 GFile *
new = g_file_new_for_path(pd->
array[selected_line].
path);
600 *path = g_strescape(pd->
array[selected_line].
path, NULL);
607 char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
609 if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
610 if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
631 .name =
"filebrowser",
632 .cfg_name_key =
"display-filebrowser",
642 ._preprocess_input = NULL,
643 .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 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 time_t get_time(const struct stat *statbuf)
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 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)
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
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)