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

Archive Download this file



interactive