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
3535            tr.translate("Add link in $1", menu.selSection().c_str(), NULL),
3636            std::bind(&GMenu2X::addLink, &gmenu2x)));
3737
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        }
4545
4646        /* FIXME(percuei): This permits to mask the "Edit link" entry
4747         * on the contextual menu in case CPUFREQ support is
...... 
4949         * This is not a good idea as it'll break things if
5050         * a new config option is added to the contextual menu.
5151         */
52        if (!app->isOpk()
52        if (app->isEditable() && (
53                !app->isOpk()
5354#if defined(ENABLE_CPUFREQ)
5455                || true
5556#endif
5657                || !app->getSelectorDir().empty()
57                ) {
58                )) {
5859            options.push_back(std::make_shared<MenuOption>(
5960                    tr.translate("Edit $1", app->getTitle().c_str(), NULL),
6061                    std::bind(&GMenu2X::editLink, &gmenu2x)));
6162        }
62        if (!app->isOpk()) {
63
64        if (app->isDeletable()) {
6365            options.push_back(std::make_shared<MenuOption>(
6466                    tr.translate("Delete $1", app->getTitle().c_str(), NULL),
6567                    std::bind(&GMenu2X::deleteLink, &gmenu2x)));
src/linkapp.cpp
8181
8282
8383#ifdef HAVE_LIBOPK
84LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile,
84LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, bool deletable,
8585            struct OPK *opk, const char *metadata_)
8686#else
87LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile)
87LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, bool deletable)
8888#endif
8989    : Link(gmenu2x_, bind(&LinkApp::start, this))
90    , deletable(deletable)
9091{
9192    manual = "";
9293    file = linkfile;
src/linkapp.h
4040    std::string sclock;
4141    int iclock;
4242    std::string exec, params, workdir, manual, selectordir, selectorfilter;
43    bool selectorbrowser, editable;
43    bool selectorbrowser, deletable, editable;
4444
4545    std::string file;
4646
...... 
6161    bool isOpk() { return isOPK; }
6262    const std::string &getOpkFile() { return opkFile; }
6363
64    LinkApp(GMenu2X *gmenu2x, const char* linkfile,
64    LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable,
6565                struct OPK *opk = NULL, const char *metadata = NULL);
6666#else
67    LinkApp(GMenu2X *gmenu2x, const char* linkfile);
67    LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable);
6868    bool isOpk() { return false; }
6969#endif
7070
...... 
9393    void showManual();
9494    void selector(int startSelection=0, const std::string &selectorDir="");
9595    bool targetExists();
96    bool isDeletable() { return deletable; }
9697    bool isEditable() { return editable; }
9798
9899    const std::string &getFile() { return file; }
src/menu.cpp
495495
496496            INFO("Section: '%s(%i)'\n", sections[isection].c_str(), isection);
497497
498            LinkApp* link = new LinkApp(gmenu2x, linkpath.c_str());
498            LinkApp* link = new LinkApp(gmenu2x, linkpath.c_str(), true);
499499            link->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]);
500500            links[isection].push_back( link );
501501        }
...... 
698698        if (!has_metadata)
699699          break;
700700
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);
702705        link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]);
703706
704707        addSection(link->getCategory());
...... 
844847          + sections[correct], linkfiles);
845848
846849        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);
849855            link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]);
850856            if (link->targetExists())
851857                links[i].push_back(link);

Archive Download the corresponding diff file



interactive