src/hbcore/theme/hbthemeclient_p.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
child 7 923ff622b8b9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    26 #include "hbthemeclient_p.h"
    26 #include "hbthemeclient_p.h"
    27 #include "hbthemeclient_p_p.h"
    27 #include "hbthemeclient_p_p.h"
    28 #include "hbsharedmemorymanager_p.h"
    28 #include "hbsharedmemorymanager_p.h"
    29 #include "hbmemoryutils_p.h"
    29 #include "hbmemoryutils_p.h"
    30 
    30 
    31 static HbThemeClient *clientInst=0;
    31 static const QLatin1String ResourceStylePath(":/themes/style/hbdefault/");
       
    32 
       
    33 static HbThemeClient *clientInst = 0;
    32 
    34 
    33 /**
    35 /**
    34  * Constructor
    36  * Constructor
    35  */
    37  */
    36 HbThemeClient::HbThemeClient():d_ptr(new HbThemeClientPrivate)
    38 HbThemeClient::HbThemeClient():d_ptr(new HbThemeClientPrivate)
    43  */
    45  */
    44 bool HbThemeClient::connectToServer()
    46 bool HbThemeClient::connectToServer()
    45 {
    47 {
    46     Q_D(HbThemeClient);
    48     Q_D(HbThemeClient);
    47     return d->connectToServer();
    49     return d->connectToServer();
    48 }
       
    49 
       
    50 QSizeF HbThemeClient::getSharedIconDefaultSize(const QString &iconPath)
       
    51 {
       
    52     Q_D(HbThemeClient);
       
    53     return d->getSharedIconDefaultSize(iconPath);
       
    54 }
    50 }
    55 
    51 
    56 /**
    52 /**
    57  * HbThemeClient::getSharedIconInfo()
    53  * HbThemeClient::getSharedIconInfo()
    58  *
    54  *
   129 }
   125 }
   130 
   126 
   131 /**
   127 /**
   132  * HbThemeClient::getSharedStyleSheet()
   128  * HbThemeClient::getSharedStyleSheet()
   133  *
   129  *
   134  * \a fielName  css filename
   130  * \a filePath  css filepath. Only acceptable path separator is '/'.
   135  * \a priority  layer priority
   131  * \a priority  layer priority
   136  */
   132  */
   137 HbCss::StyleSheet *HbThemeClient::getSharedStyleSheet(const QString &fileName,
   133 HbCss::StyleSheet *HbThemeClient::getSharedStyleSheet(const QString &filePath,
   138                                                       HbLayeredStyleLoader::LayerPriority priority)
   134                                                       HbLayeredStyleLoader::LayerPriority priority)
   139 {
   135 {
   140     int offset = -1;
   136     const QString filePathFixed = QDir::fromNativeSeparators(filePath);
   141     if( HbLayeredStyleLoader::Priority_Core == priority ) {
   137 
   142         offset = sharedCacheItemOffset(HbSharedCache::Stylesheet, fileName);
   138     HbCss::StyleSheet *styleSheet = 0;
   143     }
   139     bool requestFromServer = true;
   144     if ( -1 != offset ) {
   140     if (filePathFixed.startsWith(QLatin1Char(':')) && !filePathFixed.startsWith(ResourceStylePath)) {
   145         HbCss::StyleSheet *styleSheet =
   141         //filePathFixed is located in application resource, parse it on client side.
   146                 HbMemoryUtils::getAddress<HbCss::StyleSheet>(HbMemoryManager::SharedMemory,
   142         requestFromServer = false;
   147                                                              offset);
   143     }
   148         return styleSheet;
   144     if (requestFromServer) {
   149     }
   145         int offset = -1;
   150     Q_D(HbThemeClient);
   146         if(HbLayeredStyleLoader::Priority_Core == priority) {
   151     return d->getSharedStyleSheet(fileName,priority);
   147             offset = sharedCacheItemOffset(HbSharedCache::Stylesheet, filePathFixed);
       
   148         }
       
   149         if ( -1 != offset ) {
       
   150             styleSheet =
       
   151                     HbMemoryUtils::getAddress<HbCss::StyleSheet>(HbMemoryManager::SharedMemory,
       
   152                                                                  offset);
       
   153         } else {
       
   154             Q_D(HbThemeClient);
       
   155             styleSheet = d->getSharedStyleSheet(filePathFixed, priority);
       
   156         }
       
   157     }
       
   158     return styleSheet;
   152 }
   159 }
   153 
   160 
   154 /**
   161 /**
   155  * HbThemeClient::getSharedLayoutDefs()
   162  * HbThemeClient::getSharedLayoutDefs()
   156  *
   163  * \a filePath  layout definition filepath. Only acceptable path separator is '/'.
   157  * \a fileName
   164  * \a layout  layout name
   158  * \a layout
   165  * \a section section name
   159  * \a section
   166  */
   160  */
   167 HbWidgetLoader::LayoutDefinition *HbThemeClient::getSharedLayoutDefs(const QString &filePath,
   161 HbWidgetLoader::LayoutDefinition *HbThemeClient::getSharedLayoutDefs(const QString &fileName,
       
   162                                                                      const QString &layout,
   168                                                                      const QString &layout,
   163                                                                      const QString &section)
   169                                                                      const QString &section)
   164 {
   170 {
   165     int offset = sharedCacheItemOffset(HbSharedCache::LayoutDefinition,
   171     const QString filePathFixed = QDir::fromNativeSeparators(filePath);
   166                                        fileName + layout + section);
   172 
   167     if ( -1 != offset ) {
   173     HbWidgetLoader::LayoutDefinition *layoutDefinition = 0;
   168        HbWidgetLoader::LayoutDefinition *layoutDefs =
   174     bool requestFromServer = true;
   169            HbMemoryUtils::getAddress<HbWidgetLoader::LayoutDefinition>(HbMemoryManager::SharedMemory,
   175     if (filePathFixed.startsWith(QLatin1Char(':')) && !filePathFixed.startsWith(ResourceStylePath)) {
   170                                                                        offset);
   176         //filePathFixed is located in application resource, parse it on client side.
   171        return layoutDefs;
   177         requestFromServer = false;
   172     }
   178     }
   173     Q_D(HbThemeClient);
   179     if (requestFromServer) {
   174     return d->getSharedLayoutDefs(fileName,layout,section);
   180         int offset = sharedCacheLayoutDefinitionOffset(filePathFixed, layout, section);
       
   181         if (offset != -1) {
       
   182            layoutDefinition =
       
   183                HbMemoryUtils::getAddress<HbWidgetLoader::LayoutDefinition>(
       
   184                        HbMemoryManager::SharedMemory, offset);
       
   185         } else {
       
   186             Q_D(HbThemeClient);
       
   187             layoutDefinition = d->getSharedLayoutDefs(filePathFixed, layout, section);
       
   188         }
       
   189     }
       
   190     return layoutDefinition;
   175 }
   191 }
   176 /**
   192 /**
   177  * HbThemeClient::deviceProfiles()
   193  * HbThemeClient::deviceProfiles()
   178  */
   194  */
   179 HbDeviceProfileList *HbThemeClient::deviceProfiles()
   195 HbDeviceProfileList *HbThemeClient::deviceProfiles()
   202 }
   218 }
   203 
   219 
   204 /**
   220 /**
   205  * HbThemeClient::getSharedEffect()
   221  * HbThemeClient::getSharedEffect()
   206  *
   222  *
   207  * \a filePath
   223  * \a filePath. Only acceptable path separator is '/'.
   208  */
   224  */
   209 HbEffectFxmlData *HbThemeClient::getSharedEffect(const QString &filePath)
   225 HbEffectFxmlData *HbThemeClient::getSharedEffect(const QString &filePath)
   210 {
   226 {
   211     int offset = sharedCacheItemOffset(HbSharedCache::Effect, filePath);
   227     const QString filePathFixed = QDir::fromNativeSeparators(filePath);
       
   228 
       
   229     int offset = sharedCacheItemOffset(HbSharedCache::Effect, filePathFixed);
   212     if ( -1 != offset ) {
   230     if ( -1 != offset ) {
   213        HbEffectFxmlData  *effectFxmlData =
   231        HbEffectFxmlData  *effectFxmlData =
   214                HbMemoryUtils::getAddress<HbEffectFxmlData>(HbMemoryManager::SharedMemory, offset);
   232                HbMemoryUtils::getAddress<HbEffectFxmlData>(HbMemoryManager::SharedMemory, offset);
   215        return effectFxmlData;
   233        return effectFxmlData;
   216     }
   234     }
   217     Q_D(HbThemeClient);
   235     Q_D(HbThemeClient);
   218     return d->getSharedEffect(filePath);
   236     return d->getSharedEffect(filePathFixed);
   219 }
   237 }
   220 
   238 
   221 /**
   239 /**
   222  * HbThemeClient::addSharedEffect()
   240  * HbThemeClient::addSharedEffect()
   223  *
   241  *
   224  * \a filePath
   242  * \a filePath. Only acceptable path separator is '/'.
   225  */
   243  */
   226 bool HbThemeClient::addSharedEffect(const QString& filePath)
   244 bool HbThemeClient::addSharedEffect(const QString& filePath)
   227 {
   245 {
   228     int offset = sharedCacheItemOffset(HbSharedCache::Effect, filePath);
   246     const QString filePathFixed = QDir::fromNativeSeparators(filePath);
       
   247 
       
   248     int offset = sharedCacheItemOffset(HbSharedCache::Effect, filePathFixed);
   229     if ( -1 != offset ) {
   249     if ( -1 != offset ) {
   230         // effect already added.
   250         // effect already added.
   231         return true;
   251         return true;
   232     }
   252     }
   233     Q_D(HbThemeClient);
   253     Q_D(HbThemeClient);
   234     return d->addSharedEffect(filePath);
   254     return d->addSharedEffect(filePathFixed);
   235 }
   255 }
   236 
   256 
   237 /**
   257 /**
   238  * HbThemeClient::unloadIcon()
   258  * HbThemeClient::unloadIcon()
   239  *
   259  *
   329     delete clientInst;
   349     delete clientInst;
   330     clientInst = 0;
   350     clientInst = 0;
   331 }
   351 }
   332 
   352 
   333 /**
   353 /**
   334  * sharedCacheItemOffset  function returns the offset of the cache item
   354  * returns the offset of the cache item for the given key
   335  * for the given key
       
   336  * \param key
   355  * \param key
   337  *
   356  *
   338  */
   357  */
   339 int HbThemeClient::sharedCacheItemOffset(HbSharedCache::ItemType type, const QString & key)
   358 int HbThemeClient::sharedCacheItemOffset(HbSharedCache::ItemType type, const QString &key)
   340 {
   359 {
   341     int offset = -1;
   360     int offset = -1;
   342     HbSharedCache *cache = HbSharedCache::instance();
   361     HbSharedCache *cache = HbSharedCache::instance();
   343     if (cache) {
   362     if (cache) {
   344         offset = cache->offset(type, key);
   363         offset = cache->offset(type, key);
       
   364     }
       
   365     return offset;
       
   366 }
       
   367 
       
   368 /**
       
   369  * returns the offset of the layout definition for the given file, layout and section.
       
   370  */
       
   371 int HbThemeClient::sharedCacheLayoutDefinitionOffset(const QString &fileName,
       
   372                                          const QString &layout,
       
   373                                          const QString &section)
       
   374 {
       
   375     int offset = -1;
       
   376     HbSharedCache *cache = HbSharedCache::instance();
       
   377     if (cache) {
       
   378         offset = cache->layoutDefinitionOffset(fileName, layout, section);
   345     }
   379     }
   346     return offset;
   380     return offset;
   347 }
   381 }
   348 
   382 
   349 #ifdef HB_THEME_SERVER_MEMORY_REPORT
   383 #ifdef HB_THEME_SERVER_MEMORY_REPORT
   413 bool HbThemeClient::switchRenderingMode(HbRenderingMode renderMode)
   447 bool HbThemeClient::switchRenderingMode(HbRenderingMode renderMode)
   414 {
   448 {
   415     Q_D(HbThemeClient);    
   449     Q_D(HbThemeClient);    
   416     return d->switchRenderingMode(renderMode);    
   450     return d->switchRenderingMode(renderMode);    
   417 }
   451 }
       
   452 
       
   453 void HbThemeClient::setTheme(const QString &theme)
       
   454 {
       
   455     Q_D(HbThemeClient);
       
   456     d->setTheme(theme);
       
   457 }