Skip to content

Commit 07f233f

Browse files
committed
Indicate symlink in the icon
1 parent f5a8327 commit 07f233f

File tree

8 files changed

+29
-10
lines changed

8 files changed

+29
-10
lines changed

fileLister.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const bool CFileLister::list(const std::string &p_path)
3434
// Read dir
3535
std::string l_file("");
3636
std::string l_fileFull("");
37-
struct stat l_stat;
37+
struct stat st;
3838
struct dirent *l_dirent = readdir(l_dir);
3939
while (l_dirent != NULL)
4040
{
@@ -44,19 +44,29 @@ const bool CFileLister::list(const std::string &p_path)
4444
{
4545
// Stat the file
4646
l_fileFull = p_path + "/" + l_file;
47-
if (stat(l_fileFull.c_str(), &l_stat) == -1)
47+
if (lstat(l_fileFull.c_str(), &st) == -1)
4848
{
49-
std::cerr << "CFileLister::list: Error stat " << l_fileFull << std::endl;
49+
std::cerr << "CFileLister::list: Error lstat " << l_fileFull << std::endl;
5050
}
5151
else
5252
{
53+
const bool is_symlink = S_ISLNK(st.st_mode);
54+
auto tfile = T_FILE(l_file, is_symlink);
55+
if (tfile.is_symlink) {
56+
// Follow the link.
57+
if (stat(l_fileFull.c_str(), &st) == -1) {
58+
st.st_size = 0; // Invalid symlink.
59+
}
60+
}
61+
tfile.m_size = st.st_size;
62+
5363
// Check type
54-
if (S_ISDIR(l_stat.st_mode))
64+
if (S_ISDIR(st.st_mode))
5565
// It's a directory
56-
m_listDirs.push_back(T_FILE(l_file, l_stat.st_size));
66+
m_listDirs.push_back(std::move(tfile));
5767
else
5868
// It's a file
59-
m_listFiles.push_back(T_FILE(l_file, l_stat.st_size));
69+
m_listFiles.push_back(std::move(tfile));
6070
}
6171
}
6272
// Next
@@ -68,7 +78,7 @@ const bool CFileLister::list(const std::string &p_path)
6878
sort(m_listFiles.begin(), m_listFiles.end(), compareNoCase);
6979
sort(m_listDirs.begin(), m_listDirs.end(), compareNoCase);
7080
// Add "..", always at the first place
71-
m_listDirs.insert(m_listDirs.begin(), T_FILE("..", 0));
81+
m_listDirs.insert(m_listDirs.begin(), T_FILE("..", /*is_symlink=*/false, 0));
7282
return true;
7383
}
7484

fileLister.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
struct T_FILE
1010
{
1111
T_FILE(void) : m_size(0) {}
12-
T_FILE(const std::string &p_name, const unsigned long int &p_size)
13-
: m_name(p_name),
12+
T_FILE(std::string p_name, bool is_symlink, unsigned long int p_size = 0)
13+
: m_name(std::move(p_name)),
14+
is_symlink(is_symlink),
1415
m_ext(File_utils::getLowercaseFileExtension(p_name)),
1516
m_size(p_size) {}
1617
T_FILE(const T_FILE &p_source) = default;
1718
T_FILE &operator=(const T_FILE &p_source) = default;
1819
std::string m_name;
1920
std::string m_ext;
21+
bool is_symlink;
2022
unsigned long int m_size;
2123
};
2224

panel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CPanel::CPanel(const std::string &p_path, const Sint16 p_x):
2222
m_iconImg(CResourceManager::instance().getSurface(CResourceManager::T_SURFACE_FILE_IMAGE)),
2323
m_iconIpk(CResourceManager::instance().getSurface(CResourceManager::T_SURFACE_FILE_INSTALLABLE_PACKAGE)),
2424
m_iconOpk(CResourceManager::instance().getSurface(CResourceManager::T_SURFACE_FILE_PACKAGE)),
25+
m_iconIsSymlink(CResourceManager::instance().getSurface(CResourceManager::T_SURFACE_FILE_IS_SYMLINK)),
2526
m_iconUp(CResourceManager::instance().getSurface(CResourceManager::T_SURFACE_UP)),
2627
m_cursor1(CResourceManager::instance().getSurface(CResourceManager::T_SURFACE_CURSOR1)),
2728
m_cursor2(CResourceManager::instance().getSurface(CResourceManager::T_SURFACE_CURSOR2)),
@@ -109,6 +110,8 @@ void CPanel::render(const bool p_active) const
109110
l_color = &Globals::g_colorTextNormal;
110111
}
111112
SDL_utils::applySurface(m_x, l_y, l_surfaceTmp, Globals::g_screen);
113+
if (m_fileLister[l_i].is_symlink)
114+
SDL_utils::applySurface(m_x, l_y, m_iconIsSymlink, Globals::g_screen);
112115
// Text
113116
SDL_Color l_bg;
114117
if (l_i == m_highlightedLine) {

panel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class CPanel
9696
SDL_Surface *m_iconImg;
9797
SDL_Surface *m_iconIpk;
9898
SDL_Surface *m_iconOpk;
99+
SDL_Surface *m_iconIsSymlink;
99100
SDL_Surface *m_iconUp;
100101
SDL_Surface *m_cursor1;
101102
SDL_Surface *m_cursor2;

res/build-icons.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rsvg-convert -h 28 "${ICONS_DIR}/mimes/32/image-x-generic.svg" > file-image.png
1010
rsvg-convert -h 28 "${ICONS_DIR}/mimes/32/text-x-generic.svg" > file-text.png
1111
rsvg-convert -h 28 "${ICONS_DIR}/apps/32/synaptic.svg" > file-ipk.png
1212
rsvg-convert -h 28 "${ICONS_DIR}/mimes/32/package-x-generic.svg" > file-opk.png
13+
rsvg-convert -h 28 "${ICONS_DIR}/emblems/22/emblem-symbolic-link.svg" > file-is-symlink.png
1314
rsvg-convert -h 28 "${ICONS_DIR}/actions/24/go-up.svg" > up.png
1415
rsvg-convert -h 32 "${ICONS_DIR}/apps/32/system-file-manager.svg" > ../opkg/commander.png
1516
optipng -o9 *.png

res/file-is-symlink.png

966 Bytes
Loading

resourceManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ CResourceManager::CResourceManager() : m_fonts(LoadFonts()) {
6363
m_surfaces[T_SURFACE_FILE_IMAGE] = LoadIcon(RES_DIR "file-image.png");
6464
m_surfaces[T_SURFACE_FILE_INSTALLABLE_PACKAGE] = LoadIcon(RES_DIR "file-ipk.png");
6565
m_surfaces[T_SURFACE_FILE_PACKAGE] = LoadIcon(RES_DIR "file-opk.png");
66+
m_surfaces[T_SURFACE_FILE_IS_SYMLINK] = LoadIcon(RES_DIR "file-is-symlink.png");
6667
m_surfaces[T_SURFACE_UP] = LoadIcon(RES_DIR "up.png");
6768
m_surfaces[T_SURFACE_CURSOR1] = SDL_utils::createImage(screen.w / 2 * screen.ppu_x, LINE_HEIGHT * screen.ppu_y, SDL_MapRGB(Globals::g_screen->format, COLOR_CURSOR_1));
6869
m_surfaces[T_SURFACE_CURSOR2] = SDL_utils::createImage(screen.w / 2 * screen.ppu_x, LINE_HEIGHT * screen.ppu_y, SDL_MapRGB(Globals::g_screen->format, COLOR_CURSOR_2));

resourceManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <SDL_ttf.h>
88
#include "sdl_ttf_multifont.h"
99

10-
#define NB_SURFACES 8
10+
#define NB_SURFACES 9
1111

1212
class CResourceManager
1313
{
@@ -20,6 +20,7 @@ class CResourceManager
2020
T_SURFACE_FILE_IMAGE,
2121
T_SURFACE_FILE_INSTALLABLE_PACKAGE,
2222
T_SURFACE_FILE_PACKAGE,
23+
T_SURFACE_FILE_IS_SYMLINK,
2324
T_SURFACE_UP,
2425
T_SURFACE_CURSOR1,
2526
T_SURFACE_CURSOR2

0 commit comments

Comments
 (0)