Root/
Source at commit aa45ed9a74ba5818a8000a06a0ddf61c2a2f7c32 created 8 years 11 months ago. By Maarten ter Huurne, Use const references to strings in Menu method arguments | |
---|---|
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 | |
33 | class GMenu2X; |
34 | class IconButton; |
35 | class LinkApp; |
36 | class Monitor; |
37 | |
38 | |
39 | /** |
40 | Handles the menu structure |
41 | |
42 | @author Massimiliano Torromeo <massimiliano.torromeo@gmail.com> |
43 | */ |
44 | class Menu : public Layer { |
45 | private: |
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 | Touchscreen &ts; |
59 | IconButton btnContextMenu; |
60 | int iSection, iLink; |
61 | uint iFirstDispRow; |
62 | std::vector<std::string> sections; |
63 | std::vector<std::vector<Link*>> links; |
64 | |
65 | uint linkColumns, linkRows; |
66 | |
67 | Animation sectionAnimation; |
68 | |
69 | /** |
70 | * Determine which section headers are visible. |
71 | * The output values are relative to the middle section at 0. |
72 | */ |
73 | void calcSectionRange(int &leftSection, int &rightSection); |
74 | |
75 | std::vector<Link*> *sectionLinks(int i = -1); |
76 | |
77 | void readLinks(); |
78 | void freeLinks(); |
79 | |
80 | // Load all the sections of the given "sections" directory. |
81 | void readSections(std::string const& parentDir); |
82 | |
83 | #ifdef HAVE_LIBOPK |
84 | // Load all the .opk packages of the given directory |
85 | bool readPackages(std::string const& parentDir); |
86 | #ifdef ENABLE_INOTIFY |
87 | std::vector<std::unique_ptr<Monitor>> monitors; |
88 | #endif |
89 | #endif |
90 | |
91 | // Load all the links on the given section directory. |
92 | void readLinksOfSection(std::vector<Link*>& links, |
93 | std::string const& path, bool deletable); |
94 | |
95 | /** |
96 | * Attempts to creates a section directory if it does not exist yet. |
97 | * @return The full path of the section directory, or the empty string |
98 | * if the directory could not be created. |
99 | */ |
100 | std::string createSectionDir(std::string const& sectionName); |
101 | |
102 | void decSectionIndex(); |
103 | void incSectionIndex(); |
104 | void linkLeft(); |
105 | void linkRight(); |
106 | void linkUp(); |
107 | void linkDown(); |
108 | |
109 | public: |
110 | typedef std::function<void(void)> Action; |
111 | |
112 | Menu(GMenu2X& gmenu2x, Touchscreen &ts); |
113 | virtual ~Menu(); |
114 | |
115 | #ifdef HAVE_LIBOPK |
116 | void openPackage(std::string const& path, bool order = true); |
117 | void openPackagesFromDir(std::string const& path); |
118 | #ifdef ENABLE_INOTIFY |
119 | void removePackageLink(std::string const& path); |
120 | #endif |
121 | #endif |
122 | |
123 | int selSectionIndex(); |
124 | const std::string &selSection(); |
125 | void setSectionIndex(int i); |
126 | |
127 | void addActionLink(uint section, std::string const& title, |
128 | Action action, std::string const& description="", |
129 | std::string const& icon=""); |
130 | bool addLink(std::string const& path, std::string const& file); |
131 | |
132 | /** |
133 | * Looks up a section by name, adding it if it doesn't exist yet. |
134 | * @return The index of the section. |
135 | */ |
136 | int sectionNamed(const char *sectionName); |
137 | /** |
138 | * Looks up a section by name, adding it if it doesn't exist yet. |
139 | * @return The index of the section. |
140 | */ |
141 | int sectionNamed(std::string const& sectionName) { |
142 | return sectionNamed(sectionName.c_str()); |
143 | } |
144 | |
145 | void deleteSelectedLink(); |
146 | void deleteSelectedSection(); |
147 | |
148 | void skinUpdated(); |
149 | void orderLinks(); |
150 | |
151 | // Layer implementation: |
152 | virtual bool runAnimations(); |
153 | virtual void paint(Surface &s); |
154 | virtual bool handleButtonPress(InputManager::Button button); |
155 | virtual bool handleTouchscreen(Touchscreen &ts); |
156 | |
157 | bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex); |
158 | |
159 | int selLinkIndex(); |
160 | Link *selLink(); |
161 | LinkApp *selLinkApp(); |
162 | void setLinkIndex(int i); |
163 | |
164 | const std::vector<std::string> &getSections() { return sections; } |
165 | void renameSection(int index, std::string const& name); |
166 | }; |
167 | |
168 | #endif // MENU_H |
169 |
Branches:
install_locations
master
opkrun
packages