Date: | 2014-08-17 17:57:54 (9 years 7 months ago) |
---|---|
Author: | Maarten ter Huurne |
Commit: | 79ef1768312e1d7c14d74adeb54f70573782f108 |
Message: | 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. |
Files: |
src/contextmenu.cpp (2 diffs) src/linkapp.cpp (1 diff) src/linkapp.h (3 diffs) src/menu.cpp (3 diffs) |
Change Details
src/contextmenu.cpp | ||
---|---|---|
35 | 35 | tr.translate("Add link in $1", menu.selSection().c_str(), NULL), |
36 | 36 | std::bind(&GMenu2X::addLink, &gmenu2x))); |
37 | 37 | |
38 | if (app && !app->getManual().empty()) { | |
39 | options.push_back(std::make_shared<MenuOption>( | |
40 | tr.translate("Show manual of $1", app->getTitle().c_str(), NULL), | |
41 | std::bind(&GMenu2X::showManual, &gmenu2x))); | |
42 | } | |
43 | ||
44 | if (app && app->isEditable()) { | |
38 | if (app) { | |
39 | if (!app->getManual().empty()) { | |
40 | options.push_back(std::make_shared<MenuOption>( | |
41 | tr.translate("Show manual of $1", | |
42 | app->getTitle().c_str(), NULL), | |
43 | std::bind(&GMenu2X::showManual, &gmenu2x))); | |
44 | } | |
45 | 45 | |
46 | 46 | /* FIXME(percuei): This permits to mask the "Edit link" entry |
47 | 47 | * on the contextual menu in case CPUFREQ support is |
... | ... | |
49 | 49 | * This is not a good idea as it'll break things if |
50 | 50 | * a new config option is added to the contextual menu. |
51 | 51 | */ |
52 | if (!app->isOpk() | |
52 | if (app->isEditable() && ( | |
53 | !app->isOpk() | |
53 | 54 | #if defined(ENABLE_CPUFREQ) |
54 | 55 | || true |
55 | 56 | #endif |
56 | 57 | || !app->getSelectorDir().empty() |
57 | ) { | |
58 | )) { | |
58 | 59 | options.push_back(std::make_shared<MenuOption>( |
59 | 60 | tr.translate("Edit $1", app->getTitle().c_str(), NULL), |
60 | 61 | std::bind(&GMenu2X::editLink, &gmenu2x))); |
61 | 62 | } |
62 | if (!app->isOpk()) { | |
63 | ||
64 | if (app->isDeletable()) { | |
63 | 65 | options.push_back(std::make_shared<MenuOption>( |
64 | 66 | tr.translate("Delete $1", app->getTitle().c_str(), NULL), |
65 | 67 | std::bind(&GMenu2X::deleteLink, &gmenu2x))); |
src/linkapp.cpp | ||
---|---|---|
81 | 81 | |
82 | 82 | |
83 | 83 | #ifdef HAVE_LIBOPK |
84 | LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, | |
84 | LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, bool deletable, | |
85 | 85 | struct OPK *opk, const char *metadata_) |
86 | 86 | #else |
87 | LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile) | |
87 | LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, bool deletable) | |
88 | 88 | #endif |
89 | 89 | : Link(gmenu2x_, bind(&LinkApp::start, this)) |
90 | , deletable(deletable) | |
90 | 91 | { |
91 | 92 | manual = ""; |
92 | 93 | file = linkfile; |
src/linkapp.h | ||
---|---|---|
40 | 40 | std::string sclock; |
41 | 41 | int iclock; |
42 | 42 | std::string exec, params, workdir, manual, selectordir, selectorfilter; |
43 | bool selectorbrowser, editable; | |
43 | bool selectorbrowser, deletable, editable; | |
44 | 44 | |
45 | 45 | std::string file; |
46 | 46 | |
... | ... | |
61 | 61 | bool isOpk() { return isOPK; } |
62 | 62 | const std::string &getOpkFile() { return opkFile; } |
63 | 63 | |
64 | LinkApp(GMenu2X *gmenu2x, const char* linkfile, | |
64 | LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable, | |
65 | 65 | struct OPK *opk = NULL, const char *metadata = NULL); |
66 | 66 | #else |
67 | LinkApp(GMenu2X *gmenu2x, const char* linkfile); | |
67 | LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable); | |
68 | 68 | bool isOpk() { return false; } |
69 | 69 | #endif |
70 | 70 | |
... | ... | |
93 | 93 | void showManual(); |
94 | 94 | void selector(int startSelection=0, const std::string &selectorDir=""); |
95 | 95 | bool targetExists(); |
96 | bool isDeletable() { return deletable; } | |
96 | 97 | bool isEditable() { return editable; } |
97 | 98 | |
98 | 99 | const std::string &getFile() { return file; } |
src/menu.cpp | ||
---|---|---|
495 | 495 | |
496 | 496 | INFO("Section: '%s(%i)'\n", sections[isection].c_str(), isection); |
497 | 497 | |
498 | LinkApp* link = new LinkApp(gmenu2x, linkpath.c_str()); | |
498 | LinkApp* link = new LinkApp(gmenu2x, linkpath.c_str(), true); | |
499 | 499 | link->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]); |
500 | 500 | links[isection].push_back( link ); |
501 | 501 | } |
... | ... | |
698 | 698 | if (!has_metadata) |
699 | 699 | break; |
700 | 700 | |
701 | link = new LinkApp(gmenu2x, path.c_str(), opk, name); | |
701 | // Note: OPK links can only be deleted by removing the OPK itself, | |
702 | // but that is not something we want to do in the menu, | |
703 | // so consider this link undeletable. | |
704 | link = new LinkApp(gmenu2x, path.c_str(), false, opk, name); | |
702 | 705 | link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); |
703 | 706 | |
704 | 707 | addSection(link->getCategory()); |
... | ... | |
844 | 847 | + sections[correct], linkfiles); |
845 | 848 | |
846 | 849 | sort(linkfiles.begin(), linkfiles.end(),case_less()); |
847 | for (uint x=0; x<linkfiles.size(); x++) { | |
848 | LinkApp *link = new LinkApp(gmenu2x, linkfiles[x].c_str()); | |
850 | for (auto const& linkfile : linkfiles) { | |
851 | // Check whether the link file could be deleted. | |
852 | bool deletable = access(parentDir(linkfile).c_str(), W_OK) == 0; | |
853 | ||
854 | LinkApp *link = new LinkApp(gmenu2x, linkfile.c_str(), deletable); | |
849 | 855 | link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); |
850 | 856 | if (link->targetExists()) |
851 | 857 | links[i].push_back(link); |
Branches:
install_locations
master
opkrun
packages