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