1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-06-28 12:27:37 +03:00

Don't use file system write permissions to determine "deletable"

Instead, consider the installation location non-deletable and the home
directory deletable. This makes the "deletable" property follow the
purpose of the directory rather than its implementation details.
This commit is contained in:
Maarten ter Huurne 2014-08-18 23:17:27 +02:00
parent fe790b1c8d
commit 5805d7889f
2 changed files with 9 additions and 8 deletions

View File

@ -818,21 +818,21 @@ void Menu::readLinks()
int correct = (i>sections.size() ? iSection : i);
string const& section = sections[correct];
readLinksOfSection(GMENU2X_SYSTEM_DIR "/sections/" + section, i);
readLinksOfSection(GMenu2X::getHome() + "/sections/" + section, i);
readLinksOfSection(
links[i], GMENU2X_SYSTEM_DIR "/sections/" + section, false);
readLinksOfSection(
links[i], GMenu2X::getHome() + "/sections/" + section, true);
}
orderLinks();
}
void Menu::readLinksOfSection(std::string const& path, uint i)
void Menu::readLinksOfSection(
vector<Link*>& links, string const& path, bool deletable)
{
DIR *dirp = opendir(path.c_str());
if (!dirp) return;
// Check whether link files in this directory could be deleted.
bool deletable = access(path.c_str(), W_OK) == 0;
while (struct dirent *dptr = readdir(dirp)) {
if (dptr->d_type != DT_REG) continue;
string linkfile = path + '/' + dptr->d_name;
@ -842,7 +842,7 @@ void Menu::readLinksOfSection(std::string const& path, uint i)
link->setSize(
gmenu2x->skinConfInt["linkWidth"],
gmenu2x->skinConfInt["linkHeight"]);
links[i].push_back(link);
links.push_back(link);
} else {
delete link;
}

View File

@ -89,7 +89,8 @@ private:
#endif
// Load all the links on the given section directory.
void readLinksOfSection(std::string const& path, uint i);
void readLinksOfSection(std::vector<Link*>& links,
std::string const& path, bool deletable);
void decSectionIndex();
void incSectionIndex();