Root/src/gmenu2x.h

Source at commit 3d3e0fa created 7 years 3 months ago.
By Ayla, Read config file(s) present on both system and user-specific directories.
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 "surfacecollection.h"
25#include "iconbutton.h"
26#include "translator.h"
27#include "FastDelegate.h"
28#include "utilities.h"
29#include "touchscreen.h"
30#include "inputmanager.h"
31#include "asfont.h"
32#include "surface.h"
33#include "powersaver.h"
34
35#include <iostream>
36#include <string>
37#include <vector>
38#include <tr1/unordered_map>
39
40#ifndef GMENU2X_SYSTEM_DIR
41#define GMENU2X_SYSTEM_DIR "/usr/share/gmenu2x"
42#endif
43
44#ifndef DEFAULT_WALLPAPER_PATH
45#define DEFAULT_WALLPAPER_PATH \
46  GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers/default.png"
47#endif
48
49const int MAX_VOLUME_SCALE_FACTOR = 200;
50// Default values - going to add settings adjustment, saving, loading and such
51const int VOLUME_SCALER_MUTE = 0;
52const int VOLUME_SCALER_PHONES = 65;
53const int VOLUME_SCALER_NORMAL = 100;
54const int VOLUME_MODE_MUTE = 0;
55const int VOLUME_MODE_PHONES = 1;
56const int VOLUME_MODE_NORMAL = 2;
57const int BATTERY_READS = 10;
58
59const int LOOP_DELAY=30000;
60
61extern const char *CARD_ROOT;
62extern const int CARD_ROOT_LEN;
63
64extern void jz_cpuspeed(unsigned clockspeed);
65
66// Note: Keep this in sync with colorNames!
67enum color {
68    COLOR_TOP_BAR_BG,
69    COLOR_BOTTOM_BAR_BG,
70    COLOR_SELECTION_BG,
71    COLOR_MESSAGE_BOX_BG,
72    COLOR_MESSAGE_BOX_BORDER,
73    COLOR_MESSAGE_BOX_SELECTION,
74
75    NUM_COLORS,
76};
77
78using std::string;
79using std::vector;
80using fastdelegate::FastDelegate0;
81
82typedef FastDelegate0<> MenuAction;
83typedef unordered_map<string, string, hash<string> > ConfStrHash;
84typedef unordered_map<string, int, hash<string> > ConfIntHash;
85
86typedef struct {
87    unsigned short batt;
88    unsigned short remocon;
89} MMSP2ADC;
90
91struct MenuOption {
92    string text;
93    MenuAction action;
94};
95
96class Menu;
97
98class GMenu2X {
99private:
100    string path; //!< Contains the working directory of GMenu2X
101    /*!
102    Retrieves the free disk space on the sd
103    @return String containing a human readable representation of the free disk space
104    */
105    string getDiskFree();
106    unsigned short cpuX; //!< Offset for displaying cpu clock information
107    unsigned short volumeX; //!< Offset for displaying volume level
108    unsigned short manualX; //!< Offset for displaying the manual indicator in the taskbar
109    /*!
110    Reads the current battery state and returns a number representing it's level of charge
111    @return A number representing battery charge. 0 means fully discharged. 5 means fully charged. 6 represents a gp2x using AC power.
112    */
113    unsigned short getBatteryLevel();
114    FILE* batteryHandle, *backlightHandle, *usbHandle, *acHandle;
115    void browsePath(const string &path, vector<string>* directories, vector<string>* files);
116    /*!
117    Starts the scanning of the nand and sd filesystems, searching for dge and gpu files and creating the links in 2 dedicated sections.
118    */
119    void scanner();
120    /*!
121    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.
122    @see scanner
123    */
124    void scanPath(string path, vector<string> *files);
125
126    /*!
127    Displays a selector and launches the specified executable file
128    */
129    void explorer();
130
131    bool inet, //!< Represents the configuration of the basic network services. @see readCommonIni @see usbnet @see samba @see web
132        usbnet,
133        samba,
134        web;
135
136    string ip, defaultgw, lastSelectorDir;
137    int lastSelectorElement;
138    void readConfig();
139    void readConfig(string path);
140    void readTmp();
141
142    void initServices();
143    void initFont();
144    void initMenu();
145
146#ifdef PLATFORM_GP2X
147    void readConfigOpen2x();
148    void readCommonIni();
149    void writeCommonIni();
150
151    unsigned long gp2x_mem;
152    unsigned short *gp2x_memregs;
153    volatile unsigned short *MEM_REG;
154    int cx25874; //tv-out
155#endif
156
157    void tvout_on(bool pal);
158    void tvout_off();
159    void init();
160    void deinit();
161    void toggleTvOut();
162
163public:
164    GMenu2X();
165    ~GMenu2X();
166    void quit();
167
168    /* Returns the home directory of gmenu2x, usually
169     * ~/.gmenu2x */
170    static const string getHome(void);
171
172    /*
173     * Variables needed for elements disposition
174     */
175    uint resX, resY, halfX, halfY;
176    uint bottomBarIconY, bottomBarTextY, linkColumns, linkRows;
177
178    /*!
179    Retrieves the parent directory of GMenu2X.
180    This functions is used to initialize the "path" variable.
181    @see path
182    @return String containing the parent directory
183    */
184    const string &getExePath();
185
186    InputManager input;
187    Touchscreen ts;
188
189    //Configuration hashes
190    ConfStrHash confStr, skinConfStr;
191    ConfIntHash confInt, skinConfInt;
192    RGBAColor skinConfColors[NUM_COLORS];
193
194    //Configuration settings
195    bool useSelectionPng;
196    void setSkin(const string &skin, bool setWallpaper = true);
197
198#ifdef PLATFORM_GP2X
199    //firmware type and version
200    string fwType, fwVersion;
201
202    bool isF200() { return ts.initialized(); }
203
204    // Open2x settings ---------------------------------------------------------
205    bool o2x_usb_net_on_boot, o2x_ftp_on_boot, o2x_telnet_on_boot, o2x_gp2xjoy_on_boot, o2x_usb_host_on_boot, o2x_usb_hid_on_boot, o2x_usb_storage_on_boot;
206    string o2x_usb_net_ip;
207    int volumeMode, savedVolumeMode; // just use the const int scale values at top of source
208#endif
209
210    // Volume scaling values to store from config files
211    int volumeScalerPhones;
212    int volumeScalerNormal;
213    //--------------------------------------------------------------------------
214
215    SurfaceCollection sc;
216    Translator tr;
217    Surface *s, *bg;
218    ASFont *font;
219
220    //Status functions
221    void main();
222    void options();
223#ifdef PLATFORM_GP2X
224    void settingsOpen2x();
225#endif
226    void skinMenu();
227    /*
228    void activateSdUsb();
229    void activateNandUsb();
230    void activateRootUsb();
231    */
232    void about();
233    void viewLog();
234    void contextMenu();
235    void changeWallpaper();
236
237    void applyRamTimings();
238    void applyDefaultTimings();
239
240    void setClock(unsigned mhz);
241    void setGamma(int gamma);
242
243    void setVolume(int vol);
244    int getVolume();
245    void setVolumeScaler(int scaler);
246    int getVolumeScaler();
247
248    void setBacklight(int val);
249    int getBackLight();
250
251    void setInputSpeed();
252
253    void writeConfig();
254#ifdef PLATFORM_GP2X
255    void writeConfigOpen2x();
256#endif
257    void writeSkinConfig();
258    void writeTmp(int selelem=-1, const string &selectordir="");
259
260    void ledOn();
261    void ledOff();
262
263    void addLink();
264    void editLink();
265    void deleteLink();
266    void addSection();
267    void renameSection();
268    void deleteSection();
269
270    void initBG();
271    int drawButton(Button *btn, int x=5, int y=-10);
272    int drawButton(Surface *s, const string &btn, const string &text, int x=5, int y=-10);
273    int drawButtonRight(Surface *s, const string &btn, const string &text, int x=5, int y=-10);
274    void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height);
275
276    void drawTopBar(Surface *s=NULL);
277    void drawBottomBar(Surface *s=NULL);
278
279    Menu* menu;
280};
281
282#endif
283

Archive Download this file



interactive