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 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 | |
| 49 | const int MAX_VOLUME_SCALE_FACTOR = 200; |
| 50 | // Default values - going to add settings adjustment, saving, loading and such |
| 51 | const int VOLUME_SCALER_MUTE = 0; |
| 52 | const int VOLUME_SCALER_PHONES = 65; |
| 53 | const int VOLUME_SCALER_NORMAL = 100; |
| 54 | const int VOLUME_MODE_MUTE = 0; |
| 55 | const int VOLUME_MODE_PHONES = 1; |
| 56 | const int VOLUME_MODE_NORMAL = 2; |
| 57 | const int BATTERY_READS = 10; |
| 58 | |
| 59 | const int LOOP_DELAY=30000; |
| 60 | |
| 61 | extern const char *CARD_ROOT; |
| 62 | extern const int CARD_ROOT_LEN; |
| 63 | |
| 64 | extern void jz_cpuspeed(unsigned clockspeed); |
| 65 | |
| 66 | // Note: Keep this in sync with colorNames! |
| 67 | enum 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 | |
| 78 | using std::string; |
| 79 | using std::vector; |
| 80 | using fastdelegate::FastDelegate0; |
| 81 | |
| 82 | typedef FastDelegate0<> MenuAction; |
| 83 | typedef unordered_map<string, string, hash<string> > ConfStrHash; |
| 84 | typedef unordered_map<string, int, hash<string> > ConfIntHash; |
| 85 | |
| 86 | typedef struct { |
| 87 | unsigned short batt; |
| 88 | unsigned short remocon; |
| 89 | } MMSP2ADC; |
| 90 | |
| 91 | struct MenuOption { |
| 92 | string text; |
| 93 | MenuAction action; |
| 94 | }; |
| 95 | |
| 96 | class Menu; |
| 97 | |
| 98 | class GMenu2X { |
| 99 | private: |
| 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 readConfigOpen2x(); |
| 140 | void readTmp(); |
| 141 | void readCommonIni(); |
| 142 | void writeCommonIni(); |
| 143 | |
| 144 | void initServices(); |
| 145 | void initFont(); |
| 146 | void initMenu(); |
| 147 | |
| 148 | #ifdef TARGET_GP2X |
| 149 | unsigned long gp2x_mem; |
| 150 | unsigned short *gp2x_memregs; |
| 151 | volatile unsigned short *MEM_REG; |
| 152 | int cx25874; //tv-out |
| 153 | #endif |
| 154 | void gp2x_tvout_on(bool pal); |
| 155 | void gp2x_tvout_off(); |
| 156 | void gp2x_init(); |
| 157 | void gp2x_deinit(); |
| 158 | void toggleTvOut(); |
| 159 | |
| 160 | public: |
| 161 | GMenu2X(); |
| 162 | ~GMenu2X(); |
| 163 | void quit(); |
| 164 | |
| 165 | /* Returns the home directory of gmenu2x, usually |
| 166 | * ~/.gmenu2x */ |
| 167 | static const string getHome(void); |
| 168 | |
| 169 | /* |
| 170 | * Variables needed for elements disposition |
| 171 | */ |
| 172 | uint resX, resY, halfX, halfY; |
| 173 | uint bottomBarIconY, bottomBarTextY, linkColumns, linkRows; |
| 174 | |
| 175 | /*! |
| 176 | Retrieves the parent directory of GMenu2X. |
| 177 | This functions is used to initialize the "path" variable. |
| 178 | @see path |
| 179 | @return String containing the parent directory |
| 180 | */ |
| 181 | const string &getExePath(); |
| 182 | |
| 183 | InputManager input; |
| 184 | Touchscreen ts; |
| 185 | |
| 186 | //Configuration hashes |
| 187 | ConfStrHash confStr, skinConfStr; |
| 188 | ConfIntHash confInt, skinConfInt; |
| 189 | RGBAColor skinConfColors[NUM_COLORS]; |
| 190 | |
| 191 | //Configuration settings |
| 192 | bool useSelectionPng; |
| 193 | void setSkin(const string &skin, bool setWallpaper = true); |
| 194 | //firmware type and version |
| 195 | string fwType, fwVersion; |
| 196 | //gp2x type |
| 197 | bool f200; |
| 198 | |
| 199 | // Open2x settings --------------------------------------------------------- |
| 200 | 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; |
| 201 | string o2x_usb_net_ip; |
| 202 | int volumeMode, savedVolumeMode; // just use the const int scale values at top of source |
| 203 | |
| 204 | // Volume scaling values to store from config files |
| 205 | int volumeScalerPhones; |
| 206 | int volumeScalerNormal; |
| 207 | //-------------------------------------------------------------------------- |
| 208 | |
| 209 | SurfaceCollection sc; |
| 210 | Translator tr; |
| 211 | Surface *s, *bg; |
| 212 | ASFont *font; |
| 213 | |
| 214 | //Status functions |
| 215 | void main(); |
| 216 | void options(); |
| 217 | void settingsOpen2x(); |
| 218 | void skinMenu(); |
| 219 | void activateSdUsb(); |
| 220 | void activateNandUsb(); |
| 221 | void activateRootUsb(); |
| 222 | void about(); |
| 223 | void viewLog(); |
| 224 | void contextMenu(); |
| 225 | void changeWallpaper(); |
| 226 | void saveScreenshot(); |
| 227 | |
| 228 | void applyRamTimings(); |
| 229 | void applyDefaultTimings(); |
| 230 | |
| 231 | void setClock(unsigned mhz); |
| 232 | void setGamma(int gamma); |
| 233 | |
| 234 | void setVolume(int vol); |
| 235 | int getVolume(); |
| 236 | void setVolumeScaler(int scaler); |
| 237 | int getVolumeScaler(); |
| 238 | |
| 239 | void setBacklight(int val); |
| 240 | int getBackLight(); |
| 241 | |
| 242 | void setInputSpeed(); |
| 243 | |
| 244 | void writeConfig(); |
| 245 | void writeConfigOpen2x(); |
| 246 | void writeSkinConfig(); |
| 247 | void writeTmp(int selelem=-1, const string &selectordir=""); |
| 248 | |
| 249 | void ledOn(); |
| 250 | void ledOff(); |
| 251 | |
| 252 | void addLink(); |
| 253 | void editLink(); |
| 254 | void deleteLink(); |
| 255 | void addSection(); |
| 256 | void renameSection(); |
| 257 | void deleteSection(); |
| 258 | |
| 259 | void initBG(); |
| 260 | int drawButton(Button *btn, int x=5, int y=-10); |
| 261 | int drawButton(Surface *s, const string &btn, const string &text, int x=5, int y=-10); |
| 262 | int drawButtonRight(Surface *s, const string &btn, const string &text, int x=5, int y=-10); |
| 263 | void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height); |
| 264 | |
| 265 | void drawTopBar(Surface *s=NULL); |
| 266 | void drawBottomBar(Surface *s=NULL); |
| 267 | |
| 268 | Menu* menu; |
| 269 | }; |
| 270 | |
| 271 | #endif |
| 272 |
Branches:
install_locations
master
opkrun
packages
