34 #include <sys/types.h> 49 #define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache" 94 #include <sys/types.h> 97 static gint
compare ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data )
105 return g_strcmp0 ( fa->
name, fb->
name );
116 DIR *dir = opendir ( cdir );
118 struct dirent *rd = NULL;
119 while ( ( rd = readdir ( dir ) ) != NULL ) {
120 if ( g_strcmp0 ( rd->d_name,
".." ) == 0 ) {
131 else if ( rd->d_name[0] ==
'.' ) {
135 switch ( rd->d_type )
171 if ( stat ( file, &statbuf ) == 0 ) {
172 if ( S_ISDIR ( statbuf.st_mode ) ) {
175 else if ( S_ISREG ( statbuf.st_mode ) ) {
180 g_warning (
"Failed to stat file: %s, %s", file, strerror ( errno ) );
206 if ( g_file_get_contents ( path, &file, NULL, NULL ) ) {
207 if ( g_file_test ( file, G_FILE_TEST_IS_DIR ) ) {
208 pd->current_dir = g_file_new_for_path ( file );
214 if ( pd->current_dir == NULL ) {
215 pd->current_dir = g_file_new_for_path ( g_get_home_dir () );
242 else if ( ( mretv &
MENU_OK ) ) {
243 if ( selected_line < pd->array_length ) {
245 GFile *
new = g_file_get_parent ( pd->
current_dir );
256 g_file_set_contents ( path, pd->
array[selected_line].
path, -1, NULL );
258 GFile *
new = g_file_new_for_path ( pd->
array[selected_line].
path );
266 char *d = g_filename_from_utf8 ( pd->
array[selected_line].
path, -1, NULL, NULL, NULL );
267 char *cmd = g_strdup_printf (
"xdg-open '%s'", d );
280 char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
282 if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) {
283 if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ) {
312 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 )
321 return g_strdup (
" .." );
325 return g_strconcat (
"@", pd->
array[selected_line].
name, NULL );
328 return g_strdup ( pd->
array[selected_line].
name );
331 return g_strdup (
"n/a" );
351 static cairo_surface_t *
_get_icon (
const Mode *sw,
unsigned int selected_line,
int height )
354 g_return_val_if_fail ( pd->
array != NULL, NULL );
372 char *dirname = g_file_get_parse_name ( pd->
current_dir );
373 char *str = g_markup_printf_escaped (
"<b>Current directory:</b> %s", dirname );
384 char *d = g_strescape ( pd->
array[index].
path, NULL );
390 Mode *sw = g_malloc0 (
sizeof (
Mode ) );
412 else if ( ( mretv &
MENU_OK ) ) {
413 if ( selected_line < pd->array_length ) {
415 GFile *
new = g_file_get_parent ( pd->
current_dir );
425 GFile *
new = g_file_new_for_path ( pd->
array[selected_line].
path );
433 *path = g_strescape ( pd->
array[selected_line].
path, NULL );
441 char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
443 if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) {
444 if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ) {
467 .name =
"file-browser",
468 .cfg_name_key =
"display-file_browser",
478 ._preprocess_input = NULL,
479 .private_data = NULL,
static void get_file_browser(Mode *sw)
static cairo_surface_t * _get_icon(const Mode *sw, unsigned int selected_line, int height)
static char * _get_completion(const Mode *sw, unsigned int index)
static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, unsigned int selected_line)
#define FILEBROWSER_CACHE_FILE
unsigned int array_length
gboolean helper_execute_command(const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context)
const char * icon_name[NUM_FILE_TYPES]
static int file_browser_mode_init(Mode *sw)
static void free_list(FileBrowserModePrivateData *pd)
cairo_surface_t * rofi_icon_fetcher_get(const uint32_t uid)
ModeMode file_browser_mode_completer(Mode *sw, int mretv, char **input, unsigned int selected_line, char **path)
void * mode_get_private_data(const Mode *mode)
Mode * create_new_file_browser(void)
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
uint32_t rofi_icon_fetcher_query(const char *name, const int size)
static char * _get_message(const Mode *sw)
char * rofi_expand_path(const char *input)
gboolean rofi_icon_fetcher_file_is_image(const char *const path)
void mode_set_private_data(Mode *mode, void *pd)
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 unsigned int file_browser_mode_get_num_entries(const Mode *sw)
static void file_browser_mode_destroy(Mode *sw)
static int file_browser_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
static gint compare(gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data)