Root/src/gmenu2x.h

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 GMENU2X_H
22#define GMENU2X_H
23
24#include "contextmenu.h"
25#include "surfacecollection.h"
26#include "translator.h"
27#include "touchscreen.h"
28#include "inputmanager.h"
29#include "surface.h"
30
31#include <iostream>
32#include <memory>
33#include <string>
34#include <unordered_map>
35#include <vector>
36
37class Button;
38class Font;
39class HelpPopup;
40class IconButton;
41class Layer;
42class LinkApp;
43class MediaMonitor;
44class Menu;
45class Surface;
46
47#ifndef GMENU2X_SYSTEM_DIR
48#define GMENU2X_SYSTEM_DIR "/usr/share/gmenu2x"
49#endif
50
51const int LOOP_DELAY = 30000;
52
53extern const char *CARD_ROOT;
54
55// Note: Keep this in sync with colorNames!
56enum color {
57    COLOR_TOP_BAR_BG,
58    COLOR_BOTTOM_BAR_BG,
59    COLOR_SELECTION_BG,
60    COLOR_MESSAGE_BOX_BG,
61    COLOR_MESSAGE_BOX_BORDER,
62    COLOR_MESSAGE_BOX_SELECTION,
63
64    NUM_COLORS,
65};
66
67typedef std::unordered_map<std::string, std::string, std::hash<std::string> > ConfStrHash;
68typedef std::unordered_map<std::string, int, std::hash<std::string> > ConfIntHash;
69
70class GMenu2X {
71private:
72    Touchscreen ts;
73    std::shared_ptr<Menu> menu;
74#ifdef ENABLE_INOTIFY
75    MediaMonitor *monitor;
76#endif
77
78    LinkApp *appToLaunch;
79    std::string fileToLaunch;
80
81    std::vector<std::shared_ptr<Layer>> layers;
82
83    /*!
84    Retrieves the free disk space on the sd
85    @return String containing a human readable representation of the free disk space
86    */
87    std::string getDiskFree(const char *path);
88#ifdef ENABLE_CPUFREQ
89    unsigned cpuFreqMin; //!< Minimum CPU frequency
90    unsigned cpuFreqMax; //!< Maximum theoretical CPU frequency
91    unsigned cpuFreqSafeMax; //!< Maximum safe CPU frequency
92    unsigned cpuFreqMenuDefault; //!< Default CPU frequency for gmenu2x
93    unsigned cpuFreqAppDefault; //!< Default CPU frequency for launched apps
94    unsigned cpuFreqMultiple; //!< All valid CPU frequencies are a multiple of this
95
96    void initCPULimits();
97#endif
98    void browsePath(const std::string &path, std::vector<std::string>* directories, std::vector<std::string>* files);
99    /*!
100    Performs the actual scan in the given path and populates the files vector with the results. The creation of the links is not performed here.
101    @see scanner
102    */
103    void scanPath(std::string path, std::vector<std::string> *files);
104
105    /*!
106    Displays a selector and launches the specified executable file
107    */
108    void explorer();
109
110    bool inet, //!< Represents the configuration of the basic network services. @see readCommonIni @see usbnet @see samba @see web
111        usbnet,
112        samba,
113        web;
114
115    std::string ip, defaultgw, lastSelectorDir;
116    int lastSelectorElement;
117    void readConfig();
118    void readConfig(std::string path);
119    void readTmp();
120
121    void initServices();
122    void initFont();
123    void initMenu();
124    void initBG();
125
126public:
127    GMenu2X();
128    ~GMenu2X();
129    void quit();
130
131    /* Returns the home directory of gmenu2x, usually
132     * ~/.gmenu2x */
133    static const std::string getHome(void);
134
135    /*
136     * Variables needed for elements disposition
137     */
138    uint resX, resY, halfX, halfY;
139    uint bottomBarIconY, bottomBarTextY;
140    unsigned short cpuX; //!< Offset for displaying cpu clock information
141    unsigned short manualX; //!< Offset for displaying the manual indicator in the taskbar
142
143    /**
144     * Gets the position and height of the area between the top and bottom bars.
145     */
146    std::pair<unsigned int, unsigned int> getContentArea() {
147        const unsigned int top = skinConfInt["topBarHeight"];
148        const unsigned int bottom = skinConfInt["bottomBarHeight"];
149        return std::make_pair(top, resY - top - bottom);
150    }
151
152    InputManager input;
153
154    //Configuration hashes
155    ConfStrHash confStr, skinConfStr;
156    ConfIntHash confInt, skinConfInt;
157    RGBAColor skinConfColors[NUM_COLORS];
158
159    //Configuration settings
160    bool useSelectionPng;
161    void setSkin(const std::string &skin, bool setWallpaper = true);
162
163    SurfaceCollection sc;
164    Translator tr;
165    Surface *s, *bg;
166    Font *font;
167
168    //Status functions
169    void main();
170    /**
171     * Starts the scanning of the nand and sd filesystems, searching for dge
172     * and gpu files and creating the links in 2 dedicated sections.
173     */
174    void scanner();
175    void showContextMenu();
176    void showHelpPopup();
177    void showManual();
178    void showSettings();
179    void skinMenu();
180    void about();
181    void viewLog();
182    void changeWallpaper();
183
184#ifdef ENABLE_CPUFREQ
185    void setClock(unsigned mhz);
186    void setMenuClock() { setClock(cpuFreqMenuDefault); }
187    void setSafeMaxClock() { setClock(cpuFreqSafeMax); }
188    unsigned getDefaultAppClock() { return cpuFreqAppDefault; }
189#endif
190
191    void setInputSpeed();
192
193    /**
194     * Requests that the given application be launched.
195     * The launch won't happen immediately; it will happen after control
196     * returns to the main loop.
197     */
198    void queueLaunch(LinkApp *app, const std::string &file);
199    void saveSelection();
200    void writeConfig();
201    void writeSkinConfig();
202    void writeTmp(int selelem=-1, const std::string &selectordir="");
203
204    void addLink();
205    void editLink();
206    void deleteLink();
207    void addSection();
208    void renameSection();
209    void deleteSection();
210
211    int drawButton(IconButton *btn, int x=5, int y=-10);
212    int drawButton(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10);
213    int drawButtonRight(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10);
214    void drawScrollBar(uint pageSize, uint totalSize, uint pagePos);
215
216    void drawTopBar(Surface *s);
217    void drawBottomBar(Surface *s);
218
219    Touchscreen &getTouchscreen() { return ts; }
220};
221
222#endif // GMENU2X_H
223

Archive Download this file



interactive