Root/
| 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 | 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 | void readLinks(); |
| 75 | void freeLinks(); |
| 76 | |
| 77 | // Load all the sections of the given "sections" directory. |
| 78 | void readSections(std::string const& parentDir); |
| 79 | |
| 80 | #ifdef HAVE_LIBOPK |
| 81 | // Load all the .opk packages of the given directory |
| 82 | bool readPackages(std::string const& parentDir); |
| 83 | #ifdef ENABLE_INOTIFY |
| 84 | std::vector<std::unique_ptr<Monitor>> monitors; |
| 85 | #endif |
| 86 | #endif |
| 87 | |
| 88 | // Load all the links on the given section directory. |
| 89 | void readLinksOfSection(std::vector<std::unique_ptr<Link>>& links, |
| 90 | std::string const& path, bool deletable); |
| 91 | |
| 92 | /** |
| 93 | * Attempts to creates a section directory if it does not exist yet. |
| 94 | * @return The full path of the section directory, or the empty string |
| 95 | * if the directory could not be created. |
| 96 | */ |
| 97 | std::string createSectionDir(std::string const& sectionName); |
| 98 | |
| 99 | void decSectionIndex(); |
| 100 | void incSectionIndex(); |
| 101 | void linkLeft(); |
| 102 | void linkRight(); |
| 103 | void linkUp(); |
| 104 | void linkDown(); |
| 105 | |
| 106 | public: |
| 107 | typedef std::function<void(void)> Action; |
| 108 | |
| 109 | Menu(GMenu2X& gmenu2x); |
| 110 | virtual ~Menu(); |
| 111 | |
| 112 | #ifdef HAVE_LIBOPK |
| 113 | void openPackage(std::string const& path, bool order = true); |
| 114 | void openPackagesFromDir(std::string const& path); |
| 115 | #ifdef ENABLE_INOTIFY |
| 116 | void removePackageLink(std::string const& path); |
| 117 | #endif |
| 118 | #endif |
| 119 | |
| 120 | int selSectionIndex(); |
| 121 | const std::string &selSection(); |
| 122 | void setSectionIndex(int i); |
| 123 | |
| 124 | void addActionLink(uint section, std::string const& title, |
| 125 | Action action, std::string const& description="", |
| 126 | std::string const& icon=""); |
| 127 | bool addLink(std::string const& path, std::string const& file); |
| 128 | |
| 129 | /** |
| 130 | * Looks up a section by name, adding it if it doesn't exist yet. |
| 131 | * @return The index of the section. |
| 132 | */ |
| 133 | int sectionNamed(const char *sectionName); |
| 134 | /** |
| 135 | * Looks up a section by name, adding it if it doesn't exist yet. |
| 136 | * @return The index of the section. |
| 137 | */ |
| 138 | int sectionNamed(std::string const& sectionName) { |
| 139 | return sectionNamed(sectionName.c_str()); |
| 140 | } |
| 141 | |
| 142 | void deleteSelectedLink(); |
| 143 | void deleteSelectedSection(); |
| 144 | |
| 145 | bool moveSelectedLink(std::string const& newSection); |
| 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 | int selLinkIndex(); |
| 156 | Link *selLink(); |
| 157 | LinkApp *selLinkApp(); |
| 158 | void setLinkIndex(int i); |
| 159 | |
| 160 | const std::vector<std::string> &getSections() { return sections; } |
| 161 | std::vector<std::unique_ptr<Link>> *sectionLinks(int i = -1); |
| 162 | }; |
| 163 | |
| 164 | #endif // MENU_H |
| 165 |
Branches:
install_locations
master
opkrun
packages
