src/hbcore/image/hbiconengine.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
child 30 80e4d18b72f5
--- a/src/hbcore/image/hbiconengine.cpp	Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbcore/image/hbiconengine.cpp	Fri Sep 17 08:32:10 2010 +0300
@@ -315,10 +315,14 @@
     // Ignore the result of any outstanding loadIcon request. The
     // parameters here must match callback and callbackParam passed to
     // HbIconLoader::loadIcon in paintHelper().
-    loader->cancelLoadIcon(HbIconEngine::asyncLoadCallback, q);
+    if (loader) {
+        loader->cancelLoadIcon(HbIconEngine::asyncLoadCallback, q);
+    }
 
     if (icon) {
-        loader->unLoadIcon(icon, unloadedByServer);
+        if (loader) {
+            loader->unLoadIcon(icon, unloadedByServer);
+        }
         icon->dispose();
         icon = 0;
     }
@@ -544,8 +548,12 @@
 HbIconEngine::~HbIconEngine()
 {
     // Unregister the HbIconEngine Instance to HbIconLoader
+    // However it may already have been destroyed, if the app is shuting down
+    // so be prepared for null ptr too.
     HbIconLoader *loader = HbIconLoader::global();
-    loader->removeIconEngineInfo(this);
+    if (loader) {
+        loader->removeIconEngineInfo(this);
+    }
     delete d;
 }
 
@@ -554,7 +562,9 @@
     d->q = this;
     // Register the HbIconEngine Instance to HbIconLoader
     HbIconLoader *loader = HbIconLoader::global();
-    loader->storeIconEngineInfo(this);
+    if (loader) {    
+        loader->storeIconEngineInfo(this);
+    }
 }
 
 void HbIconEngine::forceFlagUpdate()
@@ -732,8 +742,8 @@
 
             if (d->icon) {
                 // Draw badges on this pixmap
-                QPainter painter(&d->pixmap);
                 if (d->badgeInfo) {
+                    QPainter painter(&d->pixmap);
                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
                 }
                 d->pixmap = d->icon->pixmap();
@@ -768,8 +778,8 @@
             if (d->icon) {
                 d->pixmap = d->icon->pixmap();
                 // Draw badges on this pixmap
-                QPainter painter(&d->pixmap);
                 if (d->badgeInfo) {
+                    QPainter painter(&d->pixmap);
                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
                 }
                 return d->pixmap;
@@ -852,12 +862,18 @@
                          QIcon::State state)
 {
     // This method is called by QIcon and it should paint the icon with the size defined by 'rect'.
+
+    HbIconLoader *loader = HbIconLoader::global();
+    if (!loader) {
+        return;
+    }
+
     HbIconImpl *icon = 0;
 
     // update the rendering mode
     QPaintEngine *paintEngine = painter->paintEngine();
     if (paintEngine) {
-        HbIconLoader::global()->updateRenderingMode(paintEngine->type());
+        loader->updateRenderingMode(paintEngine->type());
     }
 
     if (d->async) {
@@ -866,7 +882,7 @@
     icon = paintHelper(rect.size(), Qt::KeepAspectRatio, mode, state);
     if (icon) {
         icon->paint(painter, rect, Qt::AlignCenter);
-        HbIconLoader::global()->unLoadIcon(icon);
+        loader->unLoadIcon(icon);
         icon->dispose();
 
         // Now paint any necessary badges.
@@ -883,6 +899,11 @@
                          QIcon::Mode mode,
                          QIcon::State state)
 {
+    HbIconLoader *loader = HbIconLoader::global();
+    if (!loader) {
+        return;
+    }
+    
     // If loading the pixmap has failed, do not retry forever
     if (loadFailed(mode, state)) {
         return;
@@ -926,7 +947,7 @@
         // Update the rendering mode
         QPaintEngine *paintEngine = painter->paintEngine();
         if (paintEngine) {
-            HbIconLoader::global()->updateRenderingMode(paintEngine->type());
+            loader->updateRenderingMode(paintEngine->type());
         }
         d->icon = paintHelper(s, aspectRatioMode, mode, state);
         if (d->icon && d->icon->isCreatedOnServer()) {
@@ -1161,9 +1182,10 @@
     if (!d->signalConnectionsSet) {
         d->signalConnectionsSet = true;
         if (!d->flags.testFlag(HbIcon::NonThemeable)) {
-            connect(&hbInstance->theme()->d_ptr->iconTheme, SIGNAL(iconsUpdated(const QStringList &)), this, SLOT(themeChange(const QStringList &)));
+            connect(&hbInstance->theme()->d_ptr->iconTheme, SIGNAL(iconsUpdated(QStringList)),
+                SLOT(themeChange(QStringList)));
             connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChanged()),
-                    this, SLOT(handleLayoutDirectionChanged()));
+                SLOT(handleLayoutDirectionChanged()));
             // No need to worry about missed notifications because if the icon was not
             // painted before then there is nothing to clear.
         }
@@ -1268,7 +1290,7 @@
 void HbIconEngine::resetIconImpl() const
 {
 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
-    if ((d->iconType == SGIMAGE) || (d->iconType == NVG)) {
+    
         if (d->icon) {
             d->icon->decrementRefCount();
             if (d->icon->refCount() == 0 && d->icon->isCreatedOnServer()) {
@@ -1278,7 +1300,7 @@
             d->icon->dispose();
             d->icon = 0;
         }
-    }
+    
 #endif
 }