PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Src/base/settings/Settings.cpp

https://github.com/hwti/LunaSysMgr
C++ | 787 lines | 617 code | 122 blank | 48 comment | 75 complexity | 906509be2e7c5b4ad18aa96148b5fe5c MD5 | raw file
  1. /* @@@LICENSE
  2. *
  3. * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * LICENSE@@@ */
  18. #include "Common.h"
  19. #include "Settings.h"
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <glib.h>
  23. #include <math.h>
  24. #include <PContext.h>
  25. #include <PSoftContext.h>
  26. #if defined(DIRECT_RENDERING)
  27. #include <PGLESContext.h>
  28. #endif
  29. #include "Utils.h"
  30. #include "Logging.h"
  31. #if !defined(TARGET_DESKTOP)
  32. #include <lunaprefs.h>
  33. #endif
  34. static const char* kSettingsFile = "/etc/palm/luna.conf";
  35. static const char* kSettingsFilePlatform = "/etc/palm/luna-platform.conf";
  36. #if 0
  37. #define SETTINGS_TRACE(...) \
  38. do { \
  39. fprintf(stdout, "Settings:: " ); \
  40. fprintf(stdout, __VA_ARGS__); \
  41. } while (0)
  42. #else
  43. #define SETTINGS_TRACE(...) (void)0
  44. #endif
  45. unsigned long MemStringToBytes( const char* ptr );
  46. Settings* Settings::s_settings = 0;
  47. //static
  48. bool Settings::validateDownloadPath(const std::string& path) {
  49. //do not allow /../ in the path. This will avoid complicated parsing to check for valid paths
  50. if (path.find("..") != std::string::npos)
  51. return false;
  52. //the prefix /var or /media has to be anchored at 0
  53. if ((path.find("/var") == 0 ) || (path.find("/media") == 0))
  54. return true;
  55. return false;
  56. }
  57. //TODO: Time to start getting rid of "luna" in visible pathnames
  58. Settings::Settings()
  59. : lunaAppsPath( "/var/luna/applications/" )
  60. , pendingAppsPath( "/var/palm/data/com.palm.appInstallService" )
  61. , appInstallBase( "/media/cryptofs/apps" )
  62. , appInstallRelative( "usr/palm/applications" )
  63. , packageInstallBase( "/media/cryptofs/apps" )
  64. , packageInstallRelative( "usr/palm/packages" )
  65. , serviceInstallBase( "/media/cryptofs/apps" )
  66. , serviceInstallRelative( "usr/palm/services" )
  67. , packageManifestsPath("/media/cryptofs/apps/usr/lib/ipkg/info")
  68. , downloadPathMedia("/media/internal/downloads")
  69. , appInstallerTmp("/media/cryptofs/tmp")
  70. , lunaPresetLaunchPointsPath("/usr/luna/launchpoints/")
  71. , lunaLaunchPointsPath( "/var/luna/launchpoints/" )
  72. , lunaSystemPath( "/usr/lib/luna/system/luna-systemui/" )
  73. , lunaAppLauncherPath( "/usr/lib/luna/system/luna-applauncher/" )
  74. , lunaSystemResourcesPath( "/usr/palm/sysmgr/images/" )
  75. , lunaSystemLocalePath( "/usr/palm/sysmgr/localization" )
  76. , lunaCustomizationLocalePath( "/usr/palm/sysmgr-cust/localization")
  77. , lunaPrefsPath("/var/luna/preferences/")
  78. , lunaCmdHandlerPath("/usr/palm/command-resource-handlers.json")
  79. , lunaCmdHandlerSavedPath("/var/usr/palm/command-resource-handlers-active.json")
  80. , lunaQmlUiComponentsPath("/usr/palm/sysmgr/uiComponents/")
  81. , cardLimit(16)
  82. , showReticle(true)
  83. , lunaSystemSoundsPath("/usr/palm/sounds")
  84. , lunaDefaultAlertSound("alert.wav")
  85. , lunaDefaultRingtoneSound("phone.wav")
  86. , lunaSystemSoundAppClose("appclose")
  87. , lunaSystemSoundScreenCapture("shutter")
  88. , notificationSoundDuration(5000)
  89. , lightbarEnabled (false)
  90. , coreNaviScaler (75)
  91. , gestureAnimationSpeed (1000)
  92. , backlightOutdoorScale (250)
  93. , backlightDimScale (30)
  94. , backlightDarkScale (10)
  95. , displayWidth(320)
  96. , displayHeight(320)
  97. , displayNumBuffers(3)
  98. , ledPulseMaxBrightness (100)
  99. , ledPulseDarkBrightness (50)
  100. , enableAls(true)
  101. , disableLocking(false)
  102. , lockScreenTimeout(5000)
  103. , maxPenMoveFreq(30)
  104. , maxPaintLoad(6) // number of ms for paint routine
  105. , maxGestureChangeFreq(30)
  106. , maxTouchChangeFreq(30)
  107. , debug_trackInputEvents(false)
  108. , debug_enabled(false)
  109. , debug_piranhaDrawColoredOutlines(false)
  110. , debug_piranhaDisplayFps(false)
  111. , debug_showGestures(false)
  112. , debug_doVerboseCrashLogging(false)
  113. , debug_loopInCrashHandler(false)
  114. , tapRadius(12)
  115. , tapRadiusMin(5)
  116. , tapRadiusSquared(144)
  117. , tapRadiusShrinkPercent(10)
  118. , tapRadiusShrinkGranMs(50)
  119. , tapDoubleClickDuration(300)
  120. , enableTouchEventsForWebApps(false)
  121. , homeDoubleClickDuration(70)
  122. , dragRadiusSquared(64)
  123. , h_trackball_pixels_per_move(30)
  124. , v_trackball_pixels_per_move(40)
  125. , h_accel_rate1(200)
  126. , v_accel_rate1(200)
  127. , h_accel_const1(2)
  128. , v_accel_const1(1)
  129. , h_accel_rate2(500)
  130. , v_accel_rate2(500)
  131. , h_accel_const2(3)
  132. , v_accel_const2(2)
  133. , accelFastPollFreq (33)
  134. , turnOffAccelWhenDimmed(true)
  135. , logger_useSyslog(true)
  136. , logger_useTerminal(false)
  137. , logger_useColor(false)
  138. , logger_level(G_LOG_LEVEL_WARNING)
  139. , defaultLanguage("en_US")
  140. , launcherDefaultPositions("/etc/palm/default-launcher-page-layout.json")
  141. , launcherCustomPositions("/usr/lib/luna/customization/default-launcher-page-layout.json")
  142. , quicklaunchDefaultPositions("/usr/palm/default-dock-positions.json")
  143. , quicklaunchCustomPositions("/usr/lib/luna/customization/default-dock-positions.json")
  144. , quicklaunchUserPositions("/var/palm/user-dock-positions.json")
  145. , launcherScrim("/usr/lib/luna/system/luna-applauncher/images/launcher_scrim.png")
  146. , firstCardLaunch("/var/luna/preferences/used-first-card")
  147. , atlasEnabled(false)
  148. , emulatedCardWidth(320)
  149. , emulatedCardHeight(480)
  150. , cardGroupingXDistanceFactor(1.0)
  151. , atlasMemThreshold(0)
  152. , launcherAtlasStatistics(false)
  153. , launcherDumpAtlas(false)
  154. , launcherSideSwipeThreshold(1.2)
  155. , launcherUsesHwAA(false)
  156. , launcherRowSpacingAdjust(0)
  157. , launcherLabelWidthAdjust(0)
  158. , launcherLabelXPadding(12)
  159. , launcherIconReorderPositionThreshold(36.0)
  160. , statusBarTitleMaxWidth(140)
  161. , dockModePrelaunchAllApps(false)
  162. , dockModeCloseOnMinimize(true)
  163. , dockModeCloseOnExit(true)
  164. , dockModeMaxApps(3)
  165. , dockModeNightBrightness(1)
  166. , dockModeDefaultPositions("/etc/palm/default-exhibition-apps.json")
  167. , dockModeCustomPositions("/usr/lib/luna/customization/default-exhibition-apps.json")
  168. , dockModeUserPositions("/var/palm/user-exhibition-apps.json")
  169. , dockModeMenuHeight (400)
  170. , virtualKeyboardEnabled(false)
  171. , virtualCoreNaviEnabled(false)
  172. , virtualCoreNaviHeight(0)
  173. , uiType(UI_LUNA)
  174. , fontBanner("Prelude")
  175. , fontActiveBanner("Prelude")
  176. , fontLockWindow("Prelude")
  177. , fontDockMode("Prelude")
  178. , fontQuicklaunch("Prelude")
  179. , fontBootupAnimation("/usr/share/fonts/Prelude-Bold.ttf")
  180. , fontProgressAnimationBold("/usr/share/fonts/Prelude-Bold.ttf")
  181. , fontProgressAnimation("Prelude")
  182. , fontKeyboardKeys("Prelude")
  183. , fontStatusBar("Prelude")
  184. , displayUiRotates(false)
  185. , tabletUi(false)
  186. , homeButtonOrientationAngle(0)
  187. , emuModeOrientationAngle(0)
  188. , positiveSpaceTopPadding(24)
  189. , positiveSpaceBottomPadding(24)
  190. , maximumNegativeSpaceHeightRatio(0.55)
  191. , activeCardWindowRatio(0.659)
  192. , nonActiveCardWindowRatio(0.61)
  193. , ghostCardFinalRatio(0.85)
  194. , cardGroupRotFactor(90)
  195. , gapBetweenCardGroups(10)
  196. , overlayNotificationsHeight(83)
  197. , splashIconSize(128)
  198. , enableSplashBackgrounds(true)
  199. , maxDownloadManagerQueueLength(128)
  200. , maxDownloadManagerConcurrent(2)
  201. , maxDownloadManagerRecvSpeed(64 * 1024)
  202. , cesDemoBuild(false)
  203. , cesGestureRepeaterIp("10.0.0.204")
  204. , cesGestureRepeaterPort(5001)
  205. , enableGestureRepeater(false)
  206. , showAppStats(false)
  207. , collectUseStats(true)
  208. , usePartialKeywordAppSearch(true)
  209. , scanCalculatesAppSizes(false)
  210. , uiMainCpuShareLow(512)
  211. , uiOtherCpuShareLow(128)
  212. , javaCpuShareLow(128)
  213. , webCpuShareLow(64)
  214. , gameCpuShareLow(32)
  215. , cpuShareDefault(1024)
  216. , cpuShareDefaultLow(512)
  217. , allowTurboMode(true)
  218. , wifiInterfaceName("eth0")
  219. , wanInterfaceName("ppp0")
  220. , canRestartHeadlessApps(true)
  221. , forceSoftwareRendering(false)
  222. , perfTesting(false)
  223. , debug_appInstallerCleaner(3)
  224. , modalWindowWidth(320)
  225. , modalWindowHeight(480)
  226. , demoMode(false)
  227. , cardDimmPercentage(0.8f)
  228. , schemaValidationOption(0)
  229. {
  230. #if !defined(TARGET_DESKTOP)
  231. // CES -->
  232. // See if we're running on Nova-Demo.
  233. // The property to check is "com.palm.properties.buildName".
  234. char *build = NULL;
  235. LPErr e = LPSystemCopyStringValue ("com.palm.properties.buildName", &build);
  236. if (LP_ERR_NONE == e && NULL != build)
  237. {
  238. if (0 == strcmp ("Nova-Demo", build))
  239. {
  240. cesDemoBuild = true;
  241. enableGestureRepeater = true;
  242. }
  243. }
  244. // <-- CES
  245. #endif
  246. #if defined(TARGET_DESKTOP)
  247. {
  248. //redirect the manifests dir
  249. packageManifestsPath = "/tmp";
  250. }
  251. #endif
  252. load(kSettingsFile);
  253. load(kSettingsFilePlatform);
  254. postLoad();
  255. }
  256. Settings::~Settings()
  257. {
  258. }
  259. #define KEY_STRING(cat,name,var) \
  260. {\
  261. gchar* _vs;\
  262. GError* _error = 0;\
  263. _vs=g_key_file_get_string(keyfile,cat,name,&_error);\
  264. if( !_error && _vs ) { var=(const char*)_vs; g_free(_vs); }\
  265. else g_error_free(_error); \
  266. }
  267. #define KEY_MEMORY_STRING(cat,name,var) \
  268. {\
  269. gchar* _vs;\
  270. GError* _error = 0;\
  271. _vs=g_key_file_get_string(keyfile,cat,name,&_error);\
  272. if( !_error && _vs ) { var=::MemStringToBytes((const char*)_vs); g_free(_vs); }\
  273. else g_error_free(_error); \
  274. }
  275. #define KEY_BOOLEAN(cat,name,var) \
  276. {\
  277. gboolean _vb;\
  278. GError* _error = 0;\
  279. _vb=g_key_file_get_boolean(keyfile,cat,name,&_error);\
  280. if( !_error ) { var=_vb; }\
  281. else g_error_free(_error); \
  282. }
  283. #define KEY_INTEGER(cat,name,var) \
  284. {\
  285. int _v;\
  286. GError* _error = 0;\
  287. _v=g_key_file_get_integer(keyfile,cat,name,&_error);\
  288. if( !_error ) { var=_v; }\
  289. else g_error_free(_error); \
  290. }
  291. #define KEY_DOUBLE(cat,name,var) \
  292. {\
  293. double _v;\
  294. GError* _error = 0;\
  295. _v=g_key_file_get_double(keyfile,cat,name,&_error);\
  296. if( !_error ) { var=_v; }\
  297. else g_error_free(_error); \
  298. }
  299. // Parse the total RAM installed out of /proc/meminfo.
  300. static int MeasureTotalRAM()
  301. {
  302. gchar* buffer;
  303. gsize sz;
  304. int memTotal = 0;
  305. if( !g_file_get_contents( "/proc/meminfo", &buffer, &sz, 0 ) )
  306. return 0;
  307. char* ptr = strtok( buffer, ": \x0a\x0d" );
  308. while( ptr )
  309. {
  310. if( !strncmp( ptr,"MemTotal",8) )
  311. {
  312. // next token is the ram
  313. if( ( ptr = strtok( 0, ": \x0a\x0d" ) ) )
  314. {
  315. memTotal = atoi( ptr );
  316. }
  317. break;
  318. }
  319. ptr = strtok( 0, ": \x0a\x0d" );
  320. }
  321. g_free(buffer);
  322. return memTotal;
  323. }
  324. void Settings::load(const char* settingsFile)
  325. {
  326. GKeyFile* keyfile;
  327. GKeyFileFlags flags;
  328. GError* error = 0;
  329. keyfile = g_key_file_new();
  330. if(!keyfile)
  331. return;
  332. flags = GKeyFileFlags( G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS);
  333. if( !g_key_file_load_from_file( keyfile, settingsFile, flags, &error ) )
  334. {
  335. g_key_file_free( keyfile );
  336. if (error) g_error_free(error);
  337. return ;
  338. }
  339. // Fill in with the macros above.
  340. KEY_STRING("General","ApplicationPath", lunaAppsPath ); // apps path can now be multiple paths, separated by : (setenv PATH style)
  341. KEY_STRING("General","AppInstallBase", appInstallBase); // due to all the churn surrounding moving of apps around, this is now a conf option
  342. KEY_STRING("General","AppInstallRelative", appInstallRelative); // due to all the churn surrounding moving of apps around, this is now a conf option
  343. // KEY_STRING("General","PackageInstallBase", packageInstallBase);
  344. KEY_STRING("General","PackageInstallRelative", packageInstallRelative);
  345. KEY_STRING("General","DownloadPathMedia",downloadPathMedia);
  346. //validate path, reset to default if necessary
  347. if (!validateDownloadPath(downloadPathMedia)) {
  348. downloadPathMedia = "/media/internal/downloads";
  349. }
  350. KEY_STRING("General","AppInstallTemp",appInstallerTmp);
  351. KEY_STRING("General","SystemPath", lunaSystemPath );
  352. KEY_STRING("General","AppLauncherPath", lunaAppLauncherPath );
  353. KEY_STRING("General","SystemResourcesPath", lunaSystemResourcesPath );
  354. KEY_STRING("General","SystemLocalePath", lunaSystemLocalePath );
  355. KEY_STRING("General","PresetLaunchPointsPath",lunaPresetLaunchPointsPath);
  356. KEY_STRING("General","LaunchPointsPath", lunaLaunchPointsPath);
  357. KEY_STRING("General", "PreferencesPath", lunaPrefsPath);
  358. KEY_STRING("General","UiComponentsPath", lunaQmlUiComponentsPath );
  359. KEY_BOOLEAN("General", "ShowReticle", showReticle);
  360. KEY_INTEGER("General", "NotificationSoundDuration", notificationSoundDuration);
  361. KEY_INTEGER( "CoreNavi", "ThrobberBrightnessInLight", ledPulseMaxBrightness);
  362. KEY_INTEGER( "CoreNavi", "ThrobberBrightnessInDark", ledPulseDarkBrightness);
  363. KEY_BOOLEAN( "CoreNavi", "EnableLightBar", lightbarEnabled);
  364. KEY_INTEGER( "CoreNavi", "CoreNaviBrightnessScaler", coreNaviScaler);
  365. KEY_INTEGER( "CoreNavi", "GestureAnimationSpeedInMs", gestureAnimationSpeed);
  366. KEY_INTEGER( "CoreNavi", "HomeDoubleClickDuration", homeDoubleClickDuration);
  367. KEY_INTEGER( "Display", "BrightnessOutdoorScale", backlightOutdoorScale);
  368. KEY_INTEGER( "Display", "BrightnessDimScale", backlightDimScale);
  369. KEY_INTEGER( "Display", "BrightnessDarkScale", backlightDarkScale);
  370. KEY_BOOLEAN( "Display", "EnableALS", enableAls);
  371. KEY_BOOLEAN( "Display", "TurnOffAccelerometerWhenDimmed", turnOffAccelWhenDimmed);
  372. KEY_BOOLEAN( "Display", "DisableLocking", disableLocking);
  373. KEY_INTEGER( "Display", "LockScreenTimeoutMs", lockScreenTimeout);
  374. KEY_INTEGER( "Memory", "CardLimit", cardLimit );
  375. KEY_INTEGER( "General","DisplayWidth",displayWidth);
  376. KEY_INTEGER( "General","DisplayHeight",displayHeight);
  377. KEY_INTEGER( "General","DisplayNumBuffers", displayNumBuffers);
  378. KEY_INTEGER("General", "MaxPenMoveFreq", maxPenMoveFreq);
  379. KEY_INTEGER("General", "MaxPaintLoad", maxPaintLoad);
  380. KEY_INTEGER("General", "MaxGestureChangeFreq", maxGestureChangeFreq);
  381. KEY_INTEGER("General", "MaxTouchChangeFreq", maxTouchChangeFreq);
  382. KEY_BOOLEAN( "Debug", "WatchPenEvents", debug_trackInputEvents );
  383. KEY_BOOLEAN( "Debug", "EnableDebugModeByDefault", debug_enabled );
  384. KEY_BOOLEAN( "Debug", "PiranhaDrawColoredOutlines", debug_piranhaDrawColoredOutlines);
  385. KEY_BOOLEAN( "Debug", "PiranhaDisplayFps", debug_piranhaDisplayFps);
  386. KEY_BOOLEAN( "Debug", "ShowGestures", debug_showGestures);
  387. KEY_BOOLEAN( "Debug", "DoVerboseCrashLogging", debug_doVerboseCrashLogging);
  388. KEY_BOOLEAN( "Debug", "LoopInCrashHandler", debug_loopInCrashHandler);
  389. KEY_INTEGER( "Debug", "AppInstallerCleaner",debug_appInstallerCleaner );
  390. KEY_STRING( "General", "CmdResourceHandlers", lunaCmdHandlerPath );
  391. KEY_STRING( "General", "CmdResourceHandlersActiveCopy", lunaCmdHandlerSavedPath);
  392. KEY_STRING( "Fonts", "Banner", fontBanner );
  393. KEY_STRING( "Fonts", "ActiveBanner", fontActiveBanner );
  394. KEY_STRING( "Fonts", "LockWindow", fontLockWindow );
  395. KEY_STRING( "Fonts", "DockMode", fontDockMode );
  396. KEY_STRING( "Fonts", "Quicklaunch", fontQuicklaunch );
  397. KEY_STRING( "Fonts", "StatusBar", fontStatusBar );
  398. KEY_STRING( "Fonts", "KeyboardKeys", fontKeyboardKeys );
  399. KEY_STRING( "Fonts", "StatusBar", fontStatusBar );
  400. KEY_INTEGER("TouchEvents", "TapRadiusMax", tapRadius);
  401. KEY_INTEGER("TouchEvents", "TapRadiusMin", tapRadiusMin);
  402. KEY_INTEGER("TouchEvents", "TapRadiusShrinkPerc", tapRadiusShrinkPercent);
  403. KEY_INTEGER("TouchEvents", "TapRadiusShrinkGranMs", tapRadiusShrinkGranMs);
  404. KEY_BOOLEAN("TouchEvents", "EnableForWebApps", enableTouchEventsForWebApps);
  405. tapRadiusSquared = tapRadius * tapRadius;
  406. KEY_INTEGER("TouchEvents", "DoubleClickDuration", tapDoubleClickDuration);
  407. // Clamp to sensible values
  408. if (tapDoubleClickDuration < 50)
  409. tapDoubleClickDuration = 50;
  410. else if (tapDoubleClickDuration > 2000)
  411. tapDoubleClickDuration = 2000;
  412. KEY_INTEGER("VTrackBall", "PixelsPerMoveH", h_trackball_pixels_per_move );
  413. KEY_INTEGER("VTrackBall", "PixelsPerMoveV", v_trackball_pixels_per_move );
  414. KEY_INTEGER("VTrackBall", "AccelRateH1", h_accel_rate1 );
  415. KEY_INTEGER("VTrackBall", "AccelRateV1", v_accel_rate1 );
  416. KEY_INTEGER("VTrackBall", "AccelConstH1", h_accel_const1 );
  417. KEY_INTEGER("VTrackBall", "AccelConstV1", v_accel_const1 );
  418. KEY_INTEGER("VTrackBall", "AccelRateH2", h_accel_rate2 );
  419. KEY_INTEGER("VTrackBall", "AccelRateV2", v_accel_rate2 );
  420. KEY_INTEGER("VTrackBall", "AccelConstH2", h_accel_const2 );
  421. KEY_INTEGER("VTrackBall", "AccelConstV2", v_accel_const2 );
  422. KEY_STRING("General", "QuickLaunchDefaultPositions", quicklaunchDefaultPositions );
  423. #if defined(TARGET_DESKTOP)
  424. //If we don't have a home directory, we'll set it to /tmp. Otherwise, this does nothing.
  425. setenv("HOME", "/tmp", 0);
  426. const std::string homeFolder = getenv("HOME");
  427. quicklaunchUserPositions = homeFolder + "/.user-dock-positions.json";
  428. #endif
  429. KEY_STRING("General", "QuickLaunchUserPositions", quicklaunchUserPositions );
  430. KEY_INTEGER( "General", "StatusBarTitleMaxWidth", statusBarTitleMaxWidth);
  431. KEY_BOOLEAN( "DockMode", "DockModePrelaunchAllApps", dockModePrelaunchAllApps);
  432. KEY_BOOLEAN( "DockMode", "DockModeCloseAppOnMinimize", dockModeCloseOnMinimize);
  433. KEY_BOOLEAN( "DockMode", "DockModeCloseAppsOnExit", dockModeCloseOnExit);
  434. KEY_INTEGER( "DockMode", "DockModeMaxApps", dockModeMaxApps);
  435. KEY_INTEGER( "DockMode", "DockModeNightBrightness", dockModeNightBrightness);
  436. KEY_INTEGER( "DockMode", "DockModeMenuHeight", dockModeMenuHeight);
  437. KEY_STRING("DockMode", "DockModeDefaultPositions", quicklaunchDefaultPositions );
  438. #if defined(TARGET_DESKTOP)
  439. dockModeUserPositions = homeFolder + "/.user-dock-mode-launcher-positions.json";
  440. #endif
  441. KEY_STRING("DockMode", "DockModeUserPositions", quicklaunchUserPositions );
  442. KEY_BOOLEAN( "VirtualKeyboard", "VirtualKeyboardEnabled", virtualKeyboardEnabled);
  443. KEY_BOOLEAN( "VirtualCoreNavi", "VirtualCoreNaviEnabled", virtualCoreNaviEnabled);
  444. KEY_INTEGER( "VirtualCoreNavi", "VirtualCoreNaviHeight", virtualCoreNaviHeight);
  445. KEY_DOUBLE("Launcher", "CardSideScrollSwipeThreshold", launcherSideSwipeThreshold);
  446. KEY_BOOLEAN("Launcher", "UseOGLHardwareAntialias", launcherUsesHwAA);
  447. KEY_INTEGER("Launcher", "LauncherItemRowSpacingAdjust",launcherRowSpacingAdjust);
  448. KEY_INTEGER("Launcher", "LauncherLabelWidthAdjust",launcherLabelWidthAdjust);
  449. KEY_INTEGER("Launcher", "LauncherLabelXPadding",launcherLabelXPadding);
  450. KEY_DOUBLE("Launcher","LauncherIconReorderPositionThreshold",launcherIconReorderPositionThreshold);
  451. KEY_BOOLEAN("UI", "DisplayUiRotates", displayUiRotates);
  452. KEY_BOOLEAN("UI", "TabletUi", tabletUi);
  453. KEY_INTEGER("UI", "HomeButtonOrientationAngle", homeButtonOrientationAngle);
  454. KEY_INTEGER("UI", "EmuModeOrientationAngle", emuModeOrientationAngle);
  455. KEY_INTEGER("UI", "PositiveSpaceTopPadding", positiveSpaceTopPadding);
  456. KEY_INTEGER("UI", "PositiveSpaceBottomPadding", positiveSpaceBottomPadding);
  457. KEY_DOUBLE("UI", "MaximumNegativeSpaceHeightRatio", maximumNegativeSpaceHeightRatio);
  458. KEY_DOUBLE("UI", "ActiveCardWindowRatio", activeCardWindowRatio);
  459. KEY_DOUBLE("UI", "NonActiveCardWindowRatio", nonActiveCardWindowRatio);
  460. KEY_DOUBLE("UI", "GhostCardFinalRatio", ghostCardFinalRatio);
  461. KEY_INTEGER("UI", "CardGroupRotFactor", cardGroupRotFactor);
  462. KEY_INTEGER("UI", "GapBetweenCardGroups", gapBetweenCardGroups);
  463. KEY_INTEGER("UI", "OverlayNotificationsHeight", overlayNotificationsHeight);
  464. KEY_INTEGER("UI", "SplashIconSize", splashIconSize);
  465. KEY_BOOLEAN("UI", "EnableSplashBackgrounds", enableSplashBackgrounds);
  466. KEY_BOOLEAN("UI", "AtlasEnabled", atlasEnabled);
  467. KEY_INTEGER("UI", "EmulatedCardWidth", emulatedCardWidth);
  468. KEY_INTEGER("UI", "EmulatedCardHeight", emulatedCardHeight);
  469. KEY_INTEGER("UI", "ModalWindowWidth", modalWindowWidth);
  470. KEY_INTEGER("UI", "ModalWindowHeight", modalWindowHeight);
  471. KEY_DOUBLE("UI", "CardGroupingXDistanceFactor", cardGroupingXDistanceFactor);
  472. KEY_DOUBLE("UI", "CardDimmPercentage", cardDimmPercentage);
  473. KEY_INTEGER("UI", "AtlasMemThreshold", atlasMemThreshold);
  474. KEY_BOOLEAN("Debug", "LauncherAtlasStatistics", launcherAtlasStatistics);
  475. KEY_BOOLEAN("Debug", "DumpLauncherAtlas", launcherDumpAtlas);
  476. if (forceSoftwareRendering) {
  477. atlasEnabled = false;
  478. launcherAtlasStatistics = false;
  479. } else if (atlasEnabled && atlasMemThreshold > 0 && MeasureTotalRAM() < atlasMemThreshold * 1024) {
  480. g_message("Atlas disabled because physical memory below %dMB threshold\n", atlasMemThreshold);
  481. atlasEnabled = false;
  482. }
  483. KEY_INTEGER("DownloadManager", "MaxQueueLength", maxDownloadManagerQueueLength);
  484. KEY_INTEGER("DownloadManager", "MaxConcurrent", maxDownloadManagerConcurrent);
  485. KEY_INTEGER("DownloadManager", "MaxRecvSpeed", maxDownloadManagerRecvSpeed);
  486. KEY_STRING( "Demo", "GestureRepeaterIp", cesGestureRepeaterIp );
  487. KEY_INTEGER( "Demo", "GestureRepeaterPort", cesGestureRepeaterPort );
  488. KEY_BOOLEAN( "Demo", "EnableGestureRepeater", enableGestureRepeater );
  489. KEY_BOOLEAN( "Demo", "DemoMode", demoMode );
  490. KEY_BOOLEAN( "Debug", "ShowAppStats", showAppStats );
  491. KEY_BOOLEAN( "General", "CollectUseStats", collectUseStats );
  492. KEY_BOOLEAN( "General" , "UsePartialKeywordMatchForAppSearch",usePartialKeywordAppSearch);
  493. KEY_BOOLEAN( "General" , "ScanCalculatesAppSizes",scanCalculatesAppSizes);
  494. KEY_INTEGER("KeepAlive", "MaxParked", maxNumParkedApps );
  495. KEY_INTEGER("CpuShare", "UiMainLow", uiMainCpuShareLow);
  496. KEY_INTEGER("CpuShare", "UiOtherLow", uiOtherCpuShareLow);
  497. KEY_INTEGER("CpuShare", "JavaLow", javaCpuShareLow);
  498. KEY_INTEGER("CpuShare", "WebLow", webCpuShareLow);
  499. KEY_INTEGER("CpuShare", "GameLow", gameCpuShareLow);
  500. KEY_INTEGER("CpuShare", "Default", cpuShareDefault);
  501. KEY_BOOLEAN("AllowTurboMode", "General", allowTurboMode);
  502. KEY_STRING( "General", "WifiInterfaceName", wifiInterfaceName );
  503. KEY_STRING( "General", "WanInterfaceName", wanInterfaceName );
  504. KEY_BOOLEAN( "Memory", "CanRestartHeadlessApps", canRestartHeadlessApps );
  505. KEY_BOOLEAN( "Debug", "PerformanceLogs", perfTesting);
  506. KEY_INTEGER("General", "schemaValidationOption", schemaValidationOption);
  507. // apps to launch at boot time
  508. gchar** appsToLaunchAtBootStr = g_key_file_get_string_list(keyfile, "LaunchAtBoot",
  509. "Applications", NULL, NULL);
  510. if (appsToLaunchAtBootStr) {
  511. int index = 0;
  512. appsToLaunchAtBoot.clear();
  513. while (appsToLaunchAtBootStr[index]) {
  514. appsToLaunchAtBoot.insert(appsToLaunchAtBootStr[index]);
  515. SETTINGS_TRACE("App to launch at boot time: %s\n", appsToLaunchAtBootStr[index]);
  516. ++index;
  517. }
  518. g_strfreev(appsToLaunchAtBootStr);
  519. }
  520. // apps to keep alive
  521. gchar** appsToKeepAliveStr = g_key_file_get_string_list(keyfile, "KeepAlive",
  522. "Applications", NULL, NULL);
  523. if (appsToKeepAliveStr) {
  524. int index = 0;
  525. appsToKeepAlive.clear();
  526. while (appsToKeepAliveStr[index]) {
  527. appsToKeepAlive.insert(appsToKeepAliveStr[index]);
  528. SETTINGS_TRACE("App to keep alive: %s\n", appsToKeepAliveStr[index]);
  529. ++index;
  530. }
  531. g_strfreev(appsToKeepAliveStr);
  532. }
  533. // apps to keep alive forever (pinned)
  534. gchar** appsToKeepAliveForeverStr = g_key_file_get_string_list(keyfile, "KeepAliveUntilMemPressure",
  535. "Applications", NULL, NULL);
  536. if (appsToKeepAliveForeverStr) {
  537. int index = 0;
  538. appsToKeepAliveUntilMemPressure.clear();
  539. while (appsToKeepAliveForeverStr[index]) {
  540. appsToKeepAliveUntilMemPressure.insert(appsToKeepAliveForeverStr[index]);
  541. SETTINGS_TRACE("App to keep alive until memory pressure: %s\n", appsToKeepAliveForeverStr[index]);
  542. ++index;
  543. }
  544. g_strfreev(appsToKeepAliveForeverStr);
  545. }
  546. // apps to allow under low memory conditions
  547. gchar** appsToAllowInLowMemoryStr = g_key_file_get_string_list(keyfile, "Memory",
  548. "AppsToAllowInLowMemory", NULL, NULL);
  549. if (appsToAllowInLowMemoryStr) {
  550. int index = 0;
  551. appsToAllowInLowMemory.clear();
  552. while (appsToAllowInLowMemoryStr[index]) {
  553. appsToAllowInLowMemory.insert(appsToAllowInLowMemoryStr[index]);
  554. g_message("App to allow in Low memory: %s", appsToAllowInLowMemoryStr[index]);
  555. ++index;
  556. }
  557. g_strfreev(appsToAllowInLowMemoryStr);
  558. }
  559. // apps with accelerated compositing disabled
  560. gchar** appsToDisableAccelCompositingStr = g_key_file_get_string_list(keyfile, "AccelCompositingDisabled",
  561. "Applications", NULL, NULL);
  562. if (appsToDisableAccelCompositingStr) {
  563. int index = 0;
  564. appsToDisableAccelCompositing.clear();
  565. while (appsToDisableAccelCompositingStr[index]) {
  566. appsToDisableAccelCompositing.insert(appsToDisableAccelCompositingStr[index]);
  567. SETTINGS_TRACE("App with accelerated compositing disabled: %s\n", appsToDisableAccelCompositingStr[index]);
  568. ++index;
  569. }
  570. g_strfreev(appsToDisableAccelCompositingStr);
  571. }
  572. // SUC apps that have special launch privs
  573. gchar** sucAppsList = g_key_file_get_string_list(keyfile, "SUCApps",
  574. "Applications", NULL, NULL);
  575. if (sucAppsList) {
  576. int index = 0;
  577. sucApps.clear();
  578. while (sucAppsList[index]) {
  579. sucApps.insert(sucAppsList[index]);
  580. SETTINGS_TRACE("SUC App with special launch priviledge: %s\n", sucAppsList[index]);
  581. ++index;
  582. }
  583. g_strfreev(sucAppsList);
  584. }
  585. // ...
  586. g_key_file_free( keyfile );
  587. // sanity check on the homeButtonOrientationAngle value:
  588. if(homeButtonOrientationAngle >= 360)
  589. homeButtonOrientationAngle = homeButtonOrientationAngle%360;
  590. if(homeButtonOrientationAngle < -90)
  591. homeButtonOrientationAngle += 360;
  592. if((homeButtonOrientationAngle != 0) && (homeButtonOrientationAngle != 90) &&
  593. (homeButtonOrientationAngle != 180) && (homeButtonOrientationAngle != 270) &&
  594. (homeButtonOrientationAngle != -90))
  595. homeButtonOrientationAngle = 0;
  596. // sanity check on the emuModeOrientationAngle value:
  597. if(emuModeOrientationAngle >= 360)
  598. emuModeOrientationAngle = emuModeOrientationAngle%360;
  599. if(emuModeOrientationAngle < -90)
  600. emuModeOrientationAngle += 360;
  601. if((emuModeOrientationAngle != 0) && (emuModeOrientationAngle != 90) &&
  602. (emuModeOrientationAngle != 180) && (emuModeOrientationAngle != 270) &&
  603. (emuModeOrientationAngle != -90))
  604. emuModeOrientationAngle = 0;
  605. }
  606. void Settings::postLoad()
  607. {
  608. //POST-PROCESS lunaAppsPath....there may be multiple paths embedded
  609. //int splitStringOnKey(std::vector<std::string>& returnSplitSubstrings,const std::string& baseStr,const std::string& delims);
  610. int numPaths = splitStringOnKey(lunaAppsPaths,lunaAppsPath,":");
  611. g_warning("Settings::load(): %d application paths defined: ",numPaths);
  612. std::vector<std::string>::iterator iter = lunaAppsPaths.begin();
  613. while (iter != lunaAppsPaths.end()) {
  614. SETTINGS_TRACE("%s ",(*iter).c_str());
  615. ++iter;
  616. }
  617. SETTINGS_TRACE("\n");
  618. //reset the lunaAppsPath (LEGACY compatibility)
  619. lunaAppsPath = lunaAppsPaths.at(0);
  620. createNeededFolders();
  621. // packageInstallBase has to be == to appInstallBase for now (at least in version=blowfish timeframe)
  622. packageInstallBase = appInstallBase;
  623. // Piranha flags
  624. PSoftContext2D::SetGlobalAttribute(0, debug_piranhaDisplayFps);
  625. PSoftContext2D::SetGlobalAttribute(1, debug_piranhaDrawColoredOutlines);
  626. #if defined(DIRECT_RENDERING)
  627. PGLESContext2D::SetGlobalAttribute(0, debug_piranhaDisplayFps);
  628. PGLESContext2D::SetGlobalAttribute(1, debug_piranhaDrawColoredOutlines);
  629. #endif
  630. }
  631. // Expands "1MB" --> 1048576, "2k" --> 2048, etc.
  632. unsigned long MemStringToBytes( const char* ptr )
  633. {
  634. char number[32];
  635. unsigned long r = 0;
  636. const char* s= ptr;
  637. while( *ptr && !isalnum(*ptr) ) // skip whitespace
  638. ptr++;
  639. s=ptr;
  640. while( isdigit(*ptr) )
  641. ptr++;
  642. strncpy( number, s, (size_t)(ptr-s) );
  643. number[ptr-s]=0;
  644. r = (unsigned long)atol(number);
  645. switch(*ptr)
  646. {
  647. case 'M':
  648. r *= 1024 * 1024; break;
  649. case 'k':
  650. case 'K':
  651. r *= 1024 ; break;
  652. }
  653. return r;
  654. }
  655. void Settings::createNeededFolders()
  656. {
  657. g_mkdir_with_parents(lunaLaunchPointsPath.c_str(), 0755);
  658. g_mkdir_with_parents(lunaPrefsPath.c_str(), 0755);
  659. g_mkdir_with_parents(downloadPathMedia.c_str(),0755);
  660. g_mkdir_with_parents(appInstallerTmp.c_str(),0755);
  661. g_mkdir_with_parents(packageManifestsPath.c_str(),0755);
  662. g_mkdir_with_parents((appInstallBase+std::string("/")+appInstallRelative).c_str(),0755);
  663. g_mkdir_with_parents((packageInstallBase+std::string("/")+packageInstallRelative).c_str(),0755);
  664. g_mkdir_with_parents("/var/usr/palm",0755);
  665. }