1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[FileBrowser] Prepend '@' before filename if link.

This commit is contained in:
Dave Davenport 2020-10-16 21:09:36 +02:00
parent 9a21040d0e
commit 10678e55d8

View file

@ -64,6 +64,7 @@ typedef struct {
char *path; char *path;
enum FBFileType type; enum FBFileType type;
uint32_t icon_fetch_uid; uint32_t icon_fetch_uid;
gboolean link;
} FBFile; } FBFile;
typedef struct typedef struct
@ -118,6 +119,7 @@ static void get_file_browser ( Mode *sw )
pd->array[pd->array_length].path = NULL; pd->array[pd->array_length].path = NULL;
pd->array[pd->array_length].type = UP; pd->array[pd->array_length].type = UP;
pd->array[pd->array_length].icon_fetch_uid = 0; pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].link = FALSE;
pd->array_length++; pd->array_length++;
continue; continue;
@ -142,6 +144,7 @@ static void get_file_browser ( Mode *sw )
pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL ); pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
pd->array[pd->array_length].type = (rd->d_type == DT_DIR)? DIRECTORY: RFILE; pd->array[pd->array_length].type = (rd->d_type == DT_DIR)? DIRECTORY: RFILE;
pd->array[pd->array_length].icon_fetch_uid = 0; pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].link = FALSE;
pd->array_length++; pd->array_length++;
break; break;
case DT_LNK: case DT_LNK:
@ -150,28 +153,29 @@ static void get_file_browser ( Mode *sw )
pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL); pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL);
pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL ); pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
pd->array[pd->array_length].icon_fetch_uid = 0; pd->array[pd->array_length].icon_fetch_uid = 0;
// Default to file. pd->array[pd->array_length].link = TRUE;
pd->array[pd->array_length].type = RFILE; // Default to file.
{ pd->array[pd->array_length].type = RFILE;
// If we have link, use a stat to fine out what it is, if we fail, we mark it as file. {
// TODO have a 'broken link' mode? // If we have link, use a stat to fine out what it is, if we fail, we mark it as file.
// Convert full path to right encoding. // TODO have a 'broken link' mode?
char *file = g_filename_from_utf8(pd->array[pd->array_length].path,-1, NULL, NULL, NULL ); // Convert full path to right encoding.
if ( file ) { char *file = g_filename_from_utf8(pd->array[pd->array_length].path,-1, NULL, NULL, NULL );
struct stat statbuf; if ( file ) {
if ( stat(file, &statbuf ) == 0 ) { struct stat statbuf;
if ( S_ISDIR(statbuf.st_mode ) ) { if ( stat(file, &statbuf ) == 0 ) {
pd->array[pd->array_length].type = DIRECTORY; if ( S_ISDIR(statbuf.st_mode ) ) {
} else if ( S_ISREG ( statbuf.st_mode ) ) { pd->array[pd->array_length].type = DIRECTORY;
pd->array[pd->array_length].type = RFILE; } else if ( S_ISREG ( statbuf.st_mode ) ) {
} pd->array[pd->array_length].type = RFILE;
} else { }
g_warning("Failed to stat file: %s, %s" , file, strerror(errno)); } else {
} g_warning("Failed to stat file: %s, %s" , file, strerror(errno));
}
g_free ( file ); g_free ( file );
} }
} }
pd->array_length++; pd->array_length++;
break; break;
} }
@ -285,12 +289,14 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
// Only return the string if requested, otherwise only set state. // Only return the string if requested, otherwise only set state.
if ( !get_entry ) return NULL; if ( !get_entry ) return NULL;
if ( pd->array[selected_line].type == DIRECTORY ){ if ( pd->array[selected_line].type == UP ){
return g_strdup ( pd->array[selected_line].name);
} else if ( pd->array[selected_line].type == UP ){
return g_strdup( " .."); return g_strdup( " ..");
} else { } else {
return g_strdup ( pd->array[selected_line].name); if ( pd->array[selected_line].link ) {
return g_strconcat ( "@", pd->array[selected_line].name, NULL);
} else {
return g_strdup ( pd->array[selected_line].name);
}
} }
return g_strdup("n/a"); return g_strdup("n/a");
} }