1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-09-28 21:09:47 +03:00

Disable delete context menu option for undeletable link files

Before this change, it was possible to delete for example a link that
is stored on a read-only file system and it would disappear after
deletion but reappear as soon as the menu restarts.
This commit is contained in:
Maarten ter Huurne 2014-08-17 17:57:54 +02:00
parent c3df9c4517
commit 79ef176831
4 changed files with 29 additions and 19 deletions

View File

@ -35,13 +35,13 @@ ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu)
tr.translate("Add link in $1", menu.selSection().c_str(), NULL),
std::bind(&GMenu2X::addLink, &gmenu2x)));
if (app && !app->getManual().empty()) {
options.push_back(std::make_shared<MenuOption>(
tr.translate("Show manual of $1", app->getTitle().c_str(), NULL),
std::bind(&GMenu2X::showManual, &gmenu2x)));
}
if (app && app->isEditable()) {
if (app) {
if (!app->getManual().empty()) {
options.push_back(std::make_shared<MenuOption>(
tr.translate("Show manual of $1",
app->getTitle().c_str(), NULL),
std::bind(&GMenu2X::showManual, &gmenu2x)));
}
/* FIXME(percuei): This permits to mask the "Edit link" entry
* on the contextual menu in case CPUFREQ support is
@ -49,17 +49,19 @@ ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu)
* This is not a good idea as it'll break things if
* a new config option is added to the contextual menu.
*/
if (!app->isOpk()
if (app->isEditable() && (
!app->isOpk()
#if defined(ENABLE_CPUFREQ)
|| true
#endif
|| !app->getSelectorDir().empty()
) {
)) {
options.push_back(std::make_shared<MenuOption>(
tr.translate("Edit $1", app->getTitle().c_str(), NULL),
std::bind(&GMenu2X::editLink, &gmenu2x)));
}
if (!app->isOpk()) {
if (app->isDeletable()) {
options.push_back(std::make_shared<MenuOption>(
tr.translate("Delete $1", app->getTitle().c_str(), NULL),
std::bind(&GMenu2X::deleteLink, &gmenu2x)));

View File

@ -81,12 +81,13 @@ private:
#ifdef HAVE_LIBOPK
LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile,
LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, bool deletable,
struct OPK *opk, const char *metadata_)
#else
LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile)
LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, bool deletable)
#endif
: Link(gmenu2x_, bind(&LinkApp::start, this))
, deletable(deletable)
{
manual = "";
file = linkfile;

View File

@ -40,7 +40,7 @@ private:
std::string sclock;
int iclock;
std::string exec, params, workdir, manual, selectordir, selectorfilter;
bool selectorbrowser, editable;
bool selectorbrowser, deletable, editable;
std::string file;
@ -61,10 +61,10 @@ public:
bool isOpk() { return isOPK; }
const std::string &getOpkFile() { return opkFile; }
LinkApp(GMenu2X *gmenu2x, const char* linkfile,
LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable,
struct OPK *opk = NULL, const char *metadata = NULL);
#else
LinkApp(GMenu2X *gmenu2x, const char* linkfile);
LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable);
bool isOpk() { return false; }
#endif
@ -93,6 +93,7 @@ public:
void showManual();
void selector(int startSelection=0, const std::string &selectorDir="");
bool targetExists();
bool isDeletable() { return deletable; }
bool isEditable() { return editable; }
const std::string &getFile() { return file; }

View File

@ -495,7 +495,7 @@ bool Menu::addLink(string path, string file, string section) {
INFO("Section: '%s(%i)'\n", sections[isection].c_str(), isection);
LinkApp* link = new LinkApp(gmenu2x, linkpath.c_str());
LinkApp* link = new LinkApp(gmenu2x, linkpath.c_str(), true);
link->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]);
links[isection].push_back( link );
}
@ -698,7 +698,10 @@ void Menu::openPackage(std::string path, bool order)
if (!has_metadata)
break;
link = new LinkApp(gmenu2x, path.c_str(), opk, name);
// Note: OPK links can only be deleted by removing the OPK itself,
// but that is not something we want to do in the menu,
// so consider this link undeletable.
link = new LinkApp(gmenu2x, path.c_str(), false, opk, name);
link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]);
addSection(link->getCategory());
@ -844,8 +847,11 @@ void Menu::readLinks() {
+ sections[correct], linkfiles);
sort(linkfiles.begin(), linkfiles.end(),case_less());
for (uint x=0; x<linkfiles.size(); x++) {
LinkApp *link = new LinkApp(gmenu2x, linkfiles[x].c_str());
for (auto const& linkfile : linkfiles) {
// Check whether the link file could be deleted.
bool deletable = access(parentDir(linkfile).c_str(), W_OK) == 0;
LinkApp *link = new LinkApp(gmenu2x, linkfile.c_str(), deletable);
link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]);
if (link->targetExists())
links[i].push_back(link);