1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 13:05:20 +02: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), tr.translate("Add link in $1", menu.selSection().c_str(), NULL),
std::bind(&GMenu2X::addLink, &gmenu2x))); std::bind(&GMenu2X::addLink, &gmenu2x)));
if (app && !app->getManual().empty()) { if (app) {
options.push_back(std::make_shared<MenuOption>( if (!app->getManual().empty()) {
tr.translate("Show manual of $1", app->getTitle().c_str(), NULL), options.push_back(std::make_shared<MenuOption>(
std::bind(&GMenu2X::showManual, &gmenu2x))); tr.translate("Show manual of $1",
} app->getTitle().c_str(), NULL),
std::bind(&GMenu2X::showManual, &gmenu2x)));
if (app && app->isEditable()) { }
/* FIXME(percuei): This permits to mask the "Edit link" entry /* FIXME(percuei): This permits to mask the "Edit link" entry
* on the contextual menu in case CPUFREQ support is * 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 * This is not a good idea as it'll break things if
* a new config option is added to the contextual menu. * a new config option is added to the contextual menu.
*/ */
if (!app->isOpk() if (app->isEditable() && (
!app->isOpk()
#if defined(ENABLE_CPUFREQ) #if defined(ENABLE_CPUFREQ)
|| true || true
#endif #endif
|| !app->getSelectorDir().empty() || !app->getSelectorDir().empty()
) { )) {
options.push_back(std::make_shared<MenuOption>( options.push_back(std::make_shared<MenuOption>(
tr.translate("Edit $1", app->getTitle().c_str(), NULL), tr.translate("Edit $1", app->getTitle().c_str(), NULL),
std::bind(&GMenu2X::editLink, &gmenu2x))); std::bind(&GMenu2X::editLink, &gmenu2x)));
} }
if (!app->isOpk()) {
if (app->isDeletable()) {
options.push_back(std::make_shared<MenuOption>( options.push_back(std::make_shared<MenuOption>(
tr.translate("Delete $1", app->getTitle().c_str(), NULL), tr.translate("Delete $1", app->getTitle().c_str(), NULL),
std::bind(&GMenu2X::deleteLink, &gmenu2x))); std::bind(&GMenu2X::deleteLink, &gmenu2x)));

View File

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

View File

@ -40,7 +40,7 @@ private:
std::string sclock; std::string sclock;
int iclock; int iclock;
std::string exec, params, workdir, manual, selectordir, selectorfilter; std::string exec, params, workdir, manual, selectordir, selectorfilter;
bool selectorbrowser, editable; bool selectorbrowser, deletable, editable;
std::string file; std::string file;
@ -61,10 +61,10 @@ public:
bool isOpk() { return isOPK; } bool isOpk() { return isOPK; }
const std::string &getOpkFile() { return opkFile; } 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); struct OPK *opk = NULL, const char *metadata = NULL);
#else #else
LinkApp(GMenu2X *gmenu2x, const char* linkfile); LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable);
bool isOpk() { return false; } bool isOpk() { return false; }
#endif #endif
@ -93,6 +93,7 @@ public:
void showManual(); void showManual();
void selector(int startSelection=0, const std::string &selectorDir=""); void selector(int startSelection=0, const std::string &selectorDir="");
bool targetExists(); bool targetExists();
bool isDeletable() { return deletable; }
bool isEditable() { return editable; } bool isEditable() { return editable; }
const std::string &getFile() { return file; } 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); 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"]); link->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]);
links[isection].push_back( link ); links[isection].push_back( link );
} }
@ -698,7 +698,10 @@ void Menu::openPackage(std::string path, bool order)
if (!has_metadata) if (!has_metadata)
break; 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"]); link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]);
addSection(link->getCategory()); addSection(link->getCategory());
@ -844,8 +847,11 @@ void Menu::readLinks() {
+ sections[correct], linkfiles); + sections[correct], linkfiles);
sort(linkfiles.begin(), linkfiles.end(),case_less()); sort(linkfiles.begin(), linkfiles.end(),case_less());
for (uint x=0; x<linkfiles.size(); x++) { for (auto const& linkfile : linkfiles) {
LinkApp *link = new LinkApp(gmenu2x, linkfiles[x].c_str()); // 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"]); link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]);
if (link->targetExists()) if (link->targetExists())
links[i].push_back(link); links[i].push_back(link);