Root/src/menu.h

Source at commit ef6d378c5e401954308260d1fe3a53429fa66f4c created 5 years 5 months ago.
By Maarten ter Huurne, Removed the "Rename section" option
1/***************************************************************************
2 * Copyright (C) 2006 by Massimiliano Torromeo *
3 * massimiliano.torromeo@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#ifndef MENU_H
22#define MENU_H
23
24#include "iconbutton.h"
25#include "layer.h"
26#include "link.h"
27
28#include <functional>
29#include <memory>
30#include <string>
31#include <vector>
32
33class GMenu2X;
34class IconButton;
35class LinkApp;
36class Monitor;
37
38
39/**
40Handles the menu structure
41
42    @author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
43*/
44class Menu : public Layer {
45private:
46    class Animation {
47    public:
48        Animation();
49        bool isRunning() { return curr != 0; }
50        int currentValue() { return curr; }
51        void adjust(int delta);
52        void step();
53    private:
54        int curr;
55    };
56
57    GMenu2X& gmenu2x;
58    IconButton btnContextMenu;
59    int iSection, iLink;
60    uint iFirstDispRow;
61    std::vector<std::string> sections;
62    std::vector<std::vector<std::unique_ptr<Link>>> links;
63
64    uint linkColumns, linkRows;
65
66    Animation sectionAnimation;
67
68    /**
69     * Determine which section headers are visible.
70     * The output values are relative to the middle section at 0.
71     */
72    void calcSectionRange(int &leftSection, int &rightSection);
73
74    std::vector<std::unique_ptr<Link>> *sectionLinks(int i = -1);
75
76    void readLinks();
77    void freeLinks();
78
79    // Load all the sections of the given "sections" directory.
80    void readSections(std::string const& parentDir);
81
82#ifdef HAVE_LIBOPK
83    // Load all the .opk packages of the given directory
84    bool readPackages(std::string const& parentDir);
85#ifdef ENABLE_INOTIFY
86    std::vector<std::unique_ptr<Monitor>> monitors;
87#endif
88#endif
89
90    // Load all the links on the given section directory.
91    void readLinksOfSection(std::vector<std::unique_ptr<Link>>& links,
92                            std::string const& path, bool deletable);
93
94    /**
95     * Attempts to creates a section directory if it does not exist yet.
96     * @return The full path of the section directory, or the empty string
97     * if the directory could not be created.
98     */
99    std::string createSectionDir(std::string const& sectionName);
100
101    void decSectionIndex();
102    void incSectionIndex();
103    void linkLeft();
104    void linkRight();
105    void linkUp();
106    void linkDown();
107
108public:
109    typedef std::function<void(void)> Action;
110
111    Menu(GMenu2X& gmenu2x);
112    virtual ~Menu();
113
114#ifdef HAVE_LIBOPK
115    void openPackage(std::string const& path, bool order = true);
116    void openPackagesFromDir(std::string const& path);
117#ifdef ENABLE_INOTIFY
118    void removePackageLink(std::string const& path);
119#endif
120#endif
121
122    int selSectionIndex();
123    const std::string &selSection();
124    void setSectionIndex(int i);
125
126    void addActionLink(uint section, std::string const& title,
127            Action action, std::string const& description="",
128            std::string const& icon="");
129    bool addLink(std::string const& path, std::string const& file);
130
131    /**
132     * Looks up a section by name, adding it if it doesn't exist yet.
133     * @return The index of the section.
134     */
135    int sectionNamed(const char *sectionName);
136    /**
137     * Looks up a section by name, adding it if it doesn't exist yet.
138     * @return The index of the section.
139     */
140    int sectionNamed(std::string const& sectionName) {
141        return sectionNamed(sectionName.c_str());
142    }
143
144    void deleteSelectedLink();
145    void deleteSelectedSection();
146
147    void skinUpdated();
148    void orderLinks();
149
150    // Layer implementation:
151    virtual bool runAnimations();
152    virtual void paint(Surface &s);
153    virtual bool handleButtonPress(InputManager::Button button);
154
155    bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
156
157    int selLinkIndex();
158    Link *selLink();
159    LinkApp *selLinkApp();
160    void setLinkIndex(int i);
161
162    const std::vector<std::string> &getSections() { return sections; }
163};
164
165#endif // MENU_H
166

Archive Download this file



interactive