/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "style-manager-impl.h"
// EXTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/singleton-service.h>
+#include <dali/devel-api/common/singleton-service.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/adaptor-framework/application.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
#include <dali-toolkit/internal/builder/builder-impl.h>
#include <dali-toolkit/public-api/controls/control.h>
#include <dali-toolkit/public-api/controls/control-impl.h>
const char* PORTRAIT_QUALIFIER = "portrait";
const char* FONT_SIZE_QUALIFIER = "fontsize";
-const char* DEFAULT_THEME = DALI_STYLE_DIR "dali-toolkit-default-theme.json";
+const char* DEFAULT_THEME_FILE_NAME = "dali-toolkit-default-theme.json";
const char* PACKAGE_PATH_KEY = "PACKAGE_PATH";
const char* APPLICATION_RESOURCE_PATH_KEY = "APPLICATION_RESOURCE_PATH";
-const char* DEFAULT_PACKAGE_PATH = DALI_DATA_READ_ONLY_DIR "/toolkit/";
+const char* DEFAULT_TOOLKIT_PACKAGE_PATH = "/toolkit/";
+
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_STYLE");
+#endif
} // namespace
StyleManager::StyleManager()
: mDefaultFontSize( -1 ),
mDefaultFontFamily(""),
- mFeedbackStyle( NULL )
+ mDefaultThemeFilePath(),
+ mFeedbackStyle( nullptr )
{
// Add theme builder constants
- mThemeBuilderConstants[ PACKAGE_PATH_KEY ] = DEFAULT_PACKAGE_PATH;
+ const std::string dataReadOnlyDir = AssetManager::GetDaliDataReadOnlyPath();
+ mThemeBuilderConstants[ PACKAGE_PATH_KEY ] = dataReadOnlyDir + DEFAULT_TOOLKIT_PACKAGE_PATH;
mThemeBuilderConstants[ APPLICATION_RESOURCE_PATH_KEY ] = Application::GetResourcePath();
mStyleMonitor = StyleMonitor::Get();
mDefaultFontSize = mStyleMonitor.GetDefaultFontSize();
}
+ // Set the full path for the default style theme.
+ const std::string styleDirPath = AssetManager::GetDaliStylePath();
+ mDefaultThemeFilePath = styleDirPath + DEFAULT_THEME_FILE_NAME;
+
// Sound & haptic style
mFeedbackStyle = new FeedbackStyle();
}
void StyleManager::ApplyDefaultTheme()
{
- SetTheme( DEFAULT_THEME );
+ SetTheme(mDefaultThemeFilePath);
}
const std::string& StyleManager::GetDefaultFontFamily() const
void StyleManager::SetTheme( const std::string& themeFile )
{
bool themeLoaded = false;
+ bool loading = false;
- if( mThemeFile.compare(DEFAULT_THEME) == 0 && mThemeBuilder )
- {
- // We have already loaded the default theme into mThemeBuilder
- }
- else
+ // If we haven't loaded a theme, or the stored theme file is empty, or
+ // the previously loaded theme is different to the requested theme,
+ // first reset the builder and load the default theme.
+ if( ! mThemeBuilder || mThemeFile.empty() || mThemeFile.compare( themeFile ) != 0 )
{
- // Reload the default theme
+ loading = true;
mThemeBuilder = CreateBuilder( mThemeBuilderConstants );
- themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME );
+ themeLoaded = LoadJSON( mThemeBuilder, mDefaultThemeFilePath ); // Sets themeLoaded to true if theme exists
}
- if( themeFile.compare(DEFAULT_THEME) != 0 )
+ if( themeFile.compare(mDefaultThemeFilePath) != 0 )
{
// The theme is different to the default: Merge it
- themeLoaded = LoadJSON( mThemeBuilder, themeFile );
- mThemeFile = themeFile;
+ loading = true;
+ themeLoaded |= LoadJSON( mThemeBuilder, themeFile );
}
- if( themeLoaded )
+ if( loading )
{
- if(mFeedbackStyle)
+ mThemeFile = themeFile;
+
+ if( themeLoaded )
{
- mFeedbackStyle->StyleChanged( mThemeFile, StyleChange::THEME_CHANGE );
- }
+ // We've successfully loaded the theme file
+ if(mFeedbackStyle)
+ {
+ mFeedbackStyle->StyleChanged( mThemeFile, StyleChange::THEME_CHANGE );
+ }
- EmitStyleChangeSignals(StyleChange::THEME_CHANGE);
- }
- else
- {
- mThemeBuilder.Reset();
+ EmitStyleChangeSignals(StyleChange::THEME_CHANGE);
+ }
+ else
+ {
+ // We tried to load a theme, but it failed. Ensure the builder is reset
+ mThemeBuilder.Reset();
+ mThemeFile.clear();
+ }
}
}
const Property::Map StyleManager::GetConfigurations()
{
+ DALI_LOG_STREAM( gLogFilter, Debug::Concise, "GetConfigurations()\n On entry, mThemeBuilder: " << (bool(mThemeBuilder)?"Created":"Empty") << " mThemeFile: " << mThemeFile);
+
Property::Map result;
if( mThemeBuilder )
{
}
else
{
+ DALI_LOG_STREAM( gLogFilter, Debug::Concise, "GetConfigurations() Loading default theme" );
+
bool themeLoaded = false;
mThemeBuilder = CreateBuilder( mThemeBuilderConstants );
// Load default theme because this is first try to load stylesheet.
- themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME );
- mThemeFile = DEFAULT_THEME;
+ themeLoaded = LoadJSON( mThemeBuilder, mDefaultThemeFilePath );
+ mThemeFile = mDefaultThemeFilePath;
if( themeLoaded )
{
result = mThemeBuilder.GetConfigurations();
}
+ DALI_LOG_STREAM( gLogFilter, Debug::Concise, " themeLoaded" << (themeLoaded?"success":"failure") );
}
+ DALI_LOG_STREAM( gLogFilter, Debug::Concise, "GetConfigurations()\n On exit, result Count: " << (result.Count() != 0) );
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, " result: " << result );
+
return result;
}