src/hbcore/image/hbiconloader.cpp
changeset 30 80e4d18b72f5
parent 28 b7da29130b0e
equal deleted inserted replaced
28:b7da29130b0e 30:80e4d18b72f5
    82 
    82 
    83     \internal
    83     \internal
    84 */
    84 */
    85 
    85 
    86 // Allocated dynamically so it can be deleted before the application object is destroyed.
    86 // Allocated dynamically so it can be deleted before the application object is destroyed.
    87 // Deleting it later causes segmentation fault.
    87 // Deleting it later causes segmentation fault so Q_GLOBAL_STATIC cannot be used.
    88 static HbIconLoader *theLoader = 0;
    88 static HbIconLoader *theLoader = 0;
    89 static bool loaderDestroyed = false;
    89 static bool loaderDestroyed = false;
    90 
    90 
    91 // The max consumption for the icons held by the cachekeeper, assuming that each
    91 // The max consumption for the icons held by the cachekeeper, assuming that each
    92 // icon is 32bpp. Note that the cachekeeper's content is cleared also when
    92 // icon is 32bpp. Note that the cachekeeper's content is cleared also when
    94 const int MAX_KEEPALIVE_CACHE_SIZE_BYTES = 1024 * 1024; // 1 MB
    94 const int MAX_KEEPALIVE_CACHE_SIZE_BYTES = 1024 * 1024; // 1 MB
    95 
    95 
    96 // Icons with size above a certain limit are always ignored by the cachekeeper.
    96 // Icons with size above a certain limit are always ignored by the cachekeeper.
    97 const int MAX_KEEPALIVE_ITEM_SIZE_BYTES = MAX_KEEPALIVE_CACHE_SIZE_BYTES / 2;
    97 const int MAX_KEEPALIVE_ITEM_SIZE_BYTES = MAX_KEEPALIVE_CACHE_SIZE_BYTES / 2;
    98 
    98 
       
    99 static void cleanupLoader()
       
   100 {
       
   101     if (theLoader) {
       
   102         delete theLoader;
       
   103         theLoader = 0;
       
   104     }
       
   105 }
       
   106     
    99 class HbLocalLoaderThread : public QThread
   107 class HbLocalLoaderThread : public QThread
   100 {
   108 {
   101 public:
   109 public:
   102     void run();
   110     void run();
   103 };
   111 };
   618     connect(d->mLocalLoader, SIGNAL(ready(HbIconLoadingParams, void*)), SLOT(localLoadReady(HbIconLoadingParams, void*)));
   626     connect(d->mLocalLoader, SIGNAL(ready(HbIconLoadingParams, void*)), SLOT(localLoadReady(HbIconLoadingParams, void*)));
   619 
   627 
   620     // Set default rendering mode to EHWRendering
   628     // Set default rendering mode to EHWRendering
   621     renderMode = EHWRendering;
   629     renderMode = EHWRendering;
   622 
   630 
   623     // Delete the icon loader when the application is destroyed.
   631     // Delete the icon loader during QCoreApplication destruction. Relying on
   624     connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), SLOT(destroy()));
   632     // aboutToQuit() would cause destruction to happen too early, with Q_GLOBAL_STATIC it
       
   633     // would be too late.  Recreation is forbidden so HbIconLoader::global() will return 0
       
   634     // after destroying the application instance but at least in a typical application the
       
   635     // loader will still be available e.g. in widget (and thus graphics widget, hb view,
       
   636     // etc.) destructors.
       
   637     qAddPostRoutine(cleanupLoader);
   625 
   638 
   626     connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChangeStarted()),
   639     connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChangeStarted()),
   627             this, SLOT(updateLayoutDirection()));
   640             this, SLOT(updateLayoutDirection()));
   628 
   641 
   629     HbTheme *theme = hbInstance->theme();
   642     HbTheme *theme = hbInstance->theme();
   647     // is using HbIconLoader::global() from destructors, they have to be prepared for the
   660     // is using HbIconLoader::global() from destructors, they have to be prepared for the
   648     // null ptr result too.
   661     // null ptr result too.
   649     if (!theLoader && !loaderDestroyed) {
   662     if (!theLoader && !loaderDestroyed) {
   650         theLoader = new HbIconLoader;
   663         theLoader = new HbIconLoader;
   651     }
   664     }
   652 
   665     if (!theLoader) {
       
   666         qWarning("HbIconLoader instance not present, returning null.");
       
   667     }
   653     return theLoader;
   668     return theLoader;
   654 }
   669 }
   655 
   670 
   656 QSizeF HbIconLoader::defaultSize(const QString &iconName, const QString &appName, IconLoaderOptions options)
   671 QSizeF HbIconLoader::defaultSize(const QString &iconName, const QString &appName, IconLoaderOptions options)
   657 {
   672 {
   827     d->cacheKeeper.clear();
   842     d->cacheKeeper.clear();
   828 }
   843 }
   829 
   844 
   830 void HbIconLoader::destroy()
   845 void HbIconLoader::destroy()
   831 {
   846 {
   832     if (theLoader) {
   847     cleanupLoader();
   833         delete theLoader;
       
   834         theLoader = 0;
       
   835     }
       
   836 }
   848 }
   837 
   849 
   838 void HbIconLoader::updateLayoutDirection()
   850 void HbIconLoader::updateLayoutDirection()
   839 {
   851 {
   840     // Update the new layout directionality.
   852     // Update the new layout directionality.