src/hbcore/image/hbiconloader.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include <hbiconloader_p.h>
    26 #include "hbiconloader_p.h"
    27 #include "hbthemecommon_p.h"
       
    28 
       
    29 #include <QDir>
       
    30 #include <QCoreApplication>
       
    31 #include <QDebug>
       
    32 #include <QPicture>
       
    33 #include <QPainter>
       
    34 #include <QStyleOption>
       
    35 #include <QApplication> //krazy:exclude=qclasses
       
    36 #include <QtAlgorithms>
       
    37 #include <QTime>
       
    38 #include <QSvgRenderer>
       
    39 #include <QImageReader>
       
    40 #include <QHash>
       
    41 
       
    42 #include "hbframedrawer_p.h"
    27 #include "hbframedrawer_p.h"
    43 #include "hbicontheme_p.h"
    28 #include "hbicontheme_p.h"
    44 #include "hbstandarddirs_p.h"
       
    45 #include "hblayoutdirectionnotifier_p.h"
    29 #include "hblayoutdirectionnotifier_p.h"
    46 #include "hbinstance.h"
    30 #include "hbinstance.h"
    47 #include "hbiconanimation_p.h"
    31 #include "hbiconanimation_p.h"
    48 #include "hbiconanimator.h"
    32 #include "hbiconanimator.h"
    49 #include "hbiconanimator_p.h"
    33 #include "hbiconanimator_p.h"
    58 #include "hbpixmapiconimpl_p.h"
    42 #include "hbpixmapiconimpl_p.h"
    59 #include "hbiconsource_p.h"
    43 #include "hbiconsource_p.h"
    60 #include "hbthemeindex_p.h"
    44 #include "hbthemeindex_p.h"
    61 #include "hbthemecommon_p.h"
    45 #include "hbthemecommon_p.h"
    62 #include "hbiconimplcreator_p.h"
    46 #include "hbiconimplcreator_p.h"
       
    47 #include <QDir>
       
    48 #include <QCoreApplication>
       
    49 #include <QDebug>
       
    50 #include <QPicture>
       
    51 #include <QPainter>
       
    52 #include <QStyleOption>
       
    53 #include <QApplication> //krazy:exclude=qclasses
       
    54 #include <QtAlgorithms>
       
    55 #include <QTime>
       
    56 #include <QSvgRenderer>
       
    57 #include <QImageReader>
       
    58 #include <QHash>
    63 
    59 
    64 #ifdef HB_NVG_CS_ICON
    60 #ifdef HB_NVG_CS_ICON
    65 #include "hbeglstate_p.h"
    61 #include "hbeglstate_p.h"
    66 #endif
    62 #endif
    67 
    63 
    81 
    77 
    82 // SVG animation is currently disabled because of bugs in QT's svg engine
    78 // SVG animation is currently disabled because of bugs in QT's svg engine
    83 #undef HB_SVG_ANIMATION
    79 #undef HB_SVG_ANIMATION
    84 
    80 
    85 static const char *s_unknown = "unknown";
    81 static const char *s_unknown = "unknown";
    86     // Icon name without extension
    82 // Icon name without extension
    87 
    83 
    88 /*!
    84 /*!
    89     \class HbIconLoader
    85     \class HbIconLoader
    90 
    86 
    91     \brief HbIconLoader loads icons according to the Freedesktop Icon Theme Specification
    87     \brief HbIconLoader loads icons according to the Freedesktop Icon Theme Specification
    96 // Allocated dynamically so it can be deleted before the application object is destroyed.
    92 // Allocated dynamically so it can be deleted before the application object is destroyed.
    97 // Deleting it later causes segmentation fault.
    93 // Deleting it later causes segmentation fault.
    98 static HbIconLoader *theLoader = 0;
    94 static HbIconLoader *theLoader = 0;
    99 
    95 
   100 #ifdef HB_ICONIMPL_CACHE
    96 #ifdef HB_ICONIMPL_CACHE
   101 static QHash<QByteArray, HbIconImpl*> iconImplCache;
    97 static QHash<QByteArray, HbIconImpl *> iconImplCache;
   102 #endif
    98 #endif
   103 
    99 
   104 class HbIconLoaderPrivate
   100 class HbIconLoaderPrivate
   105 {
   101 {
   106 public:
   102 public:
   109 
   105 
   110     static HbIconLoaderPrivate *global();
   106     static HbIconLoaderPrivate *global();
   111 
   107 
   112     static QString removeIconNameSuffix(const QString &iconName);
   108     static QString removeIconNameSuffix(const QString &iconName);
   113 
   109 
   114     /* This method is supposed to work the same way 
   110     /* This method is supposed to work the same way
   115        as the FindIconHelper in the Icon Theme Spec: */
   111        as the FindIconHelper in the Icon Theme Spec: */
   116     static QString findSharedResourceHelper(const QString &resourceName,
   112     static QString findSharedResourceHelper(const QString &resourceName,
   117                                   bool mirrored,
   113                                             bool mirrored,
   118                                   bool& mirroredIconFound,
   114                                             bool &mirroredIconFound,
   119                                   Hb::ResourceType itemType = Hb::IconResource,
   115                                             Hb::ResourceType itemType = Hb::IconResource,
   120                                   bool useThemeIndex = true);
   116                                             bool useThemeIndex = true);
   121 
   117 
   122     static QString findEffectHelper(const QString &effectName);
   118     static QString findEffectHelper(const QString &effectName);
   123 
   119 
   124     bool isAutomaticallyMirrored(const QString &iconName);
   120     bool isAutomaticallyMirrored(const QString &iconName);
   125 
   121 
   126     bool isLayoutMirrored();
   122     bool isLayoutMirrored();
   127     void setLayoutMirrored(bool mirrored);
   123     void setLayoutMirrored(bool mirrored);
   128 
   124 
   129 #ifdef HB_ICONIMPL_CACHE
   125 #ifdef HB_ICONIMPL_CACHE
   130     QByteArray createCacheKeyFrom( const QString &iconName, 
   126     QByteArray createCacheKeyFrom(const QString &iconName,
   131                                    const QSizeF &size,
   127                                   const QSizeF &size,
   132                                    Qt::AspectRatioMode aspectRatioMode, 
   128                                   Qt::AspectRatioMode aspectRatioMode,
   133                                    QIcon::Mode mode, 
   129                                   QIcon::Mode mode,
   134                                    bool mirrored, 
   130                                   bool mirrored,
   135                                    const QColor &color,
   131                                   const QColor &color,
   136                                    HbRenderingMode renderMode);
   132                                   HbRenderingMode renderMode);
   137 #endif
   133 #endif
   138 
   134 
   139 public: // data
   135 public:
   140     QString storedTheme;
   136     QString storedTheme;
   141 
   137 
   142     int sourceResolution;
   138     int sourceResolution;
   143     int resolution;
   139     int resolution;
   144     qreal zoom;
   140     qreal zoom;
   149     bool animationLoading;
   145     bool animationLoading;
   150     // <-- Frame-by-frame animation support ------------------------------------
   146     // <-- Frame-by-frame animation support ------------------------------------
   151 
   147 
   152     HbIconSource *lastIconSource;
   148     HbIconSource *lastIconSource;
   153 
   149 
   154 private: // data
   150 private:
   155     enum {
   151     enum {
   156         Unknown = 0,
   152         Unknown = 0,
   157         NotMirrored = 1,
   153         NotMirrored = 1,
   158         Mirrored = 2
   154         Mirrored = 2
   159     };
   155     };
   163     */
   159     */
   164     int layoutMirrored;
   160     int layoutMirrored;
   165 };
   161 };
   166 
   162 
   167 HbIconLoaderPrivate::HbIconLoaderPrivate() :
   163 HbIconLoaderPrivate::HbIconLoaderPrivate() :
   168         storedTheme(HbTheme::instance()->name()),
   164     storedTheme(HbTheme::instance()->name()),
   169         sourceResolution(144), // This is about the resolution of a Nokia N95 8GB
   165     sourceResolution(144), // This is about the resolution of a Nokia N95 8GB
   170         resolution(144),
   166     resolution(144),
   171         zoom(1.0),
   167     zoom(1.0),
   172         animationManager(HbIconAnimationManager::global()),
   168     animationManager(HbIconAnimationManager::global()),
   173         animationLoading(false),
   169     animationLoading(false),
   174         lastIconSource(0),
   170     lastIconSource(0),
   175         layoutMirrored(Unknown)
   171     layoutMirrored(Unknown)
   176 {
   172 {
   177 }
   173 }
   178 
   174 
   179 HbIconLoaderPrivate::~HbIconLoaderPrivate()
   175 HbIconLoaderPrivate::~HbIconLoaderPrivate()
   180 {
   176 {
   188 }
   184 }
   189 
   185 
   190 QString HbIconLoaderPrivate::removeIconNameSuffix(const QString &iconName)
   186 QString HbIconLoaderPrivate::removeIconNameSuffix(const QString &iconName)
   191 {
   187 {
   192     QString loweredIconName = iconName.toLower();
   188     QString loweredIconName = iconName.toLower();
   193     if (loweredIconName.endsWith(".svg")
   189     if (loweredIconName.endsWith(QLatin1String(".svg"))
   194         || loweredIconName.endsWith(".png")
   190             || loweredIconName.endsWith(QLatin1String(".png"))
   195         || loweredIconName.endsWith(".mng")
   191             || loweredIconName.endsWith(QLatin1String(".mng"))
   196         || loweredIconName.endsWith(".gif")
   192             || loweredIconName.endsWith(QLatin1String(".gif"))
   197         || loweredIconName.endsWith(".xpm")
   193             || loweredIconName.endsWith(QLatin1String(".xpm"))
   198         || loweredIconName.endsWith(".jpg")
   194             || loweredIconName.endsWith(QLatin1String(".jpg"))
   199         || loweredIconName.endsWith(".nvg")) {
   195             || loweredIconName.endsWith(QLatin1String(".nvg"))) {
   200         return iconName.left(iconName.length() - 4);
   196         return iconName.left(iconName.length() - 4);
   201     }
   197     }
   202 
   198 
   203     if (loweredIconName.endsWith(".svgz")
   199     if (loweredIconName.endsWith(QLatin1String(".svgz"))
   204         || loweredIconName.endsWith(".qpic")) {
   200             || loweredIconName.endsWith(QLatin1String(".qpic"))) {
   205         return iconName.left(iconName.length() - 5);
   201         return iconName.left(iconName.length() - 5);
   206     }
   202     }
   207 
   203 
   208     return iconName;
   204     return iconName;
   209 }
   205 }
   223         return "BLOB";
   219         return "BLOB";
   224     }
   220     }
   225     return suffix;
   221     return suffix;
   226 }
   222 }
   227 
   223 
   228 QString HbIconLoaderPrivate::findSharedResourceHelper(const QString &resourceName, bool mirrored, bool& mirroredIconFound, Hb::ResourceType itemType, bool useThemeIndex)
   224 QString HbIconLoaderPrivate::findSharedResourceHelper(const QString &resourceName, bool mirrored, bool &mirroredIconFound, Hb::ResourceType itemType, bool useThemeIndex)
   229 {
   225 {
   230     Q_UNUSED(useThemeIndex)
   226     Q_UNUSED(useThemeIndex)
   231     Q_UNUSED(itemType)
   227     Q_UNUSED(itemType)
   232 
   228 
   233     mirroredIconFound = false;
   229     mirroredIconFound = false;
   234     QString iconPath;
   230     QString iconPath;
   235 
   231 
   236     if (QDir::isRelativePath(resourceName)) {
   232     if (HbThemeUtils::isLogicalName(resourceName)) {
   237 
       
   238 #ifdef Q_OS_SYMBIAN
       
   239         // Try to get themed icon information from theme index
   233         // Try to get themed icon information from theme index
   240         HbThemeIndexResource resource(resourceName);
   234         HbThemeIndexResource resource(resourceName);
   241         if (resource.isValid()) {
   235         if (resource.isValid()) {
   242             if (mirrored) {
   236             if (mirrored) {
   243                 return resource.fullMirroredFileName();
   237                 return resource.fullMirroredFileName();
   244             } else {
   238             } else {
   245                 return resource.fullFileName();
   239                 return resource.fullFileName();
   246             }
   240             }
   247         }
   241         } else {
   248 #endif // Q_OS_SYMBIAN
   242             // Logical name not found in theme index - return empty string
   249 
   243             return QString();
   250         // If there was no theme index, search the icon in theme icon dirs (slow)
       
   251         foreach (const QString &dir, HbThemePrivate::instance()->iconDirectories()) {
       
   252             if (mirrored) {
       
   253                 // If icon is mirrored, try to find the icon in a separate "mirrored" folder used for mirrored icons
       
   254                 iconPath =  HbStandardDirs::findResource( dir + "mirrored" + '/' + resourceName, Hb::IconResource );
       
   255                 if( !iconPath.isEmpty() ) {
       
   256                     mirroredIconFound = true;
       
   257                     break;
       
   258                 }
       
   259             }
       
   260 
       
   261         iconPath =  HbStandardDirs::findResource( dir + resourceName, Hb::IconResource );
       
   262 
       
   263             // If the file was found in this dir, return the filename.
       
   264         if ( !iconPath.isEmpty() ) {
       
   265                 break;
       
   266             }
       
   267         }
   244         }
   268     } else {
   245     } else {
   269         // Absolute path. Do not scan through different theme directories.
   246         // Not a logical name. Check from file system.
   270         QString iconNameCopy(resourceName);
       
   271         if (mirrored) {
   247         if (mirrored) {
   272             // If icon is mirrored, try to find the icon in a separate "mirrored" folder used for mirrored icons
   248             // If icon is mirrored, try to find the icon in a separate "mirrored" folder used for mirrored icons
   273 
   249 
   274             // Find the directory part from the full filename
   250             // Find the directory part from the full filename
   275             int index1 = resourceName.lastIndexOf('/');
   251             int index1 = resourceName.lastIndexOf('/');
   278             int index = index1 > index2 ? index1 : index2;
   254             int index = index1 > index2 ? index1 : index2;
   279 
   255 
   280             QString iconNameCopy(resourceName);
   256             QString iconNameCopy(resourceName);
   281 
   257 
   282             if (index > 0) {
   258             if (index > 0) {
   283                 iconNameCopy.insert(index+1, QString("mirrored/"));
   259                 iconNameCopy.insert(index + 1, QString("mirrored/"));
   284             }
   260             }
   285             iconPath = HbStandardDirs::findResource(iconNameCopy, Hb::IconResource);
   261             if (QFile::exists(iconNameCopy)) {
   286 
   262                 iconPath = iconNameCopy;
   287             if( !iconPath.isEmpty() ) {
   263             }
       
   264 
       
   265             if (!iconPath.isEmpty()) {
   288                 mirroredIconFound = true;
   266                 mirroredIconFound = true;
   289                 return iconPath;
   267                 return iconPath;
   290             }
   268             }
   291         }
   269         }
   292 
   270 
   293         iconPath = HbStandardDirs::findResource(resourceName, Hb::IconResource);
   271         if (QFile::exists(resourceName)) {
       
   272             iconPath = resourceName;
       
   273         }
   294     }
   274     }
   295 
   275 
   296     return iconPath;
   276     return iconPath;
       
   277 }
       
   278 
   297 /*
   279 /*
   298 From Freedesktop.org:
   280 From Freedesktop.org:
   299 
   281 
   300  The exact algorithm (in pseudocode) for looking up an icon in a theme (if the implementation supports SVG) is:
   282  The exact algorithm (in pseudocode) for looking up an icon in a theme (if the implementation supports SVG) is:
   301 
   283 
   320     if filename != none
   302     if filename != none
   321       return filename
   303       return filename
   322   }
   304   }
   323   return none
   305   return none
   324 }
   306 }
   325      
   307 
   326 
   308 
   327 With the following helper functions:
   309 With the following helper functions:
   328 
   310 
   329 LookupIcon(iconname, size, theme) {
   311 LookupIcon(iconname, size, theme) {
   330   for each subdir in $(theme subdir list) {
   312   for each subdir in $(theme subdir list) {
   425   }
   407   }
   426   return none
   408   return none
   427 
   409 
   428     }
   410     }
   429 */
   411 */
   430 }
       
   431 
   412 
   432 bool HbIconLoaderPrivate::isAutomaticallyMirrored(const QString &iconName)
   413 bool HbIconLoaderPrivate::isAutomaticallyMirrored(const QString &iconName)
   433 {
   414 {
   434     Q_UNUSED(iconName);
       
   435     // only place to get mirroring information is from themeindex
   415     // only place to get mirroring information is from themeindex
   436 #ifdef Q_OS_SYMBIAN
   416     // Try to get themed icon information from theme index
   437         // Try to get themed icon information from theme index
   417     HbThemeIndexResource resource(iconName);
   438         HbThemeIndexResource resource(iconName);
   418     if (resource.isValid()) {
   439         if (resource.isValid()) {
   419         return resource.isAutomaticallyMirrored();
   440             return resource.isAutomaticallyMirrored();
   420     }
   441         }
       
   442 #endif
       
   443 
   421 
   444     return false;
   422     return false;
   445 }
   423 }
   446 
   424 
   447 bool HbIconLoaderPrivate::isLayoutMirrored()
   425 bool HbIconLoaderPrivate::isLayoutMirrored()
   448 {
   426 {
   449     if (layoutMirrored == Unknown) {
   427     if (layoutMirrored == Unknown) {
   450         // The layout directionality is defined by asking it from the main window.
   428         // The layout directionality is defined by asking it from the main window.
   451         QList<HbMainWindow*> allWindows = hbInstance->allMainWindows();
   429         QList<HbMainWindow *> allWindows = hbInstance->allMainWindows();
   452         HbMainWindow* primaryWindow = allWindows.value(0);
   430         HbMainWindow *primaryWindow = allWindows.value(0);
   453         if (primaryWindow) {
   431         if (primaryWindow) {
   454             layoutMirrored = primaryWindow->layoutDirection() == Qt::LeftToRight ? NotMirrored : Mirrored;
   432             layoutMirrored = primaryWindow->layoutDirection() == Qt::LeftToRight ? NotMirrored : Mirrored;
   455         } else {
   433         } else {
   456             // Do not know mirroring state yet, return not mirrored.
   434             // Do not know mirroring state yet, return not mirrored.
   457             return NotMirrored;
   435             return NotMirrored;
   464 {
   442 {
   465     layoutMirrored = mirrored ? Mirrored : NotMirrored;
   443     layoutMirrored = mirrored ? Mirrored : NotMirrored;
   466 }
   444 }
   467 
   445 
   468 #ifdef HB_ICONIMPL_CACHE
   446 #ifdef HB_ICONIMPL_CACHE
   469 QByteArray HbIconLoaderPrivate::createCacheKeyFrom(const QString &iconName, const QSizeF &size,
   447 QByteArray HbIconLoaderPrivate::createCacheKeyFrom(const QString &iconName,
   470     Qt::AspectRatioMode aspectRatioMode, QIcon::Mode mode, bool mirrored, const QColor &color,
   448         const QSizeF &size,
   471     HbRenderingMode renderMode)
   449         Qt::AspectRatioMode aspectRatioMode,
       
   450         QIcon::Mode mode,
       
   451         bool mirrored,
       
   452         const QColor &color,
       
   453         HbRenderingMode renderMode)
   472 {
   454 {
   473     static const int paramArraySize = 8;
   455     static const int paramArraySize = 8;
   474 
   456 
   475     // This uses QByteArray to improve performance compared to QString.
   457     // This uses QByteArray to improve performance compared to QString.
   476     // It allows appending stuff with less heap allocations and conversions compared to using QString.
   458     // It allows appending stuff with less heap allocations and conversions compared to using QString.
   496         temp[6] = 0;
   478         temp[6] = 0;
   497     }
   479     }
   498 
   480 
   499     // Append render mode when creating cache key
   481     // Append render mode when creating cache key
   500     temp[7] = renderMode;
   482     temp[7] = renderMode;
   501     cacheKey.append((char*)&(temp[0]), sizeof(int)*paramArraySize);
   483     cacheKey.append((char *)&(temp[0]), sizeof(int)*paramArraySize);
   502 
   484 
   503     const QChar *iconNamePtr = iconName.constData();
   485     const QChar *iconNamePtr = iconName.constData();
   504     cacheKey.append((char*)iconNamePtr, nameSize * sizeof(QChar));
   486     cacheKey.append((char *)iconNamePtr, nameSize * sizeof(QChar));
   505 
   487 
   506     if (mirrored) {
   488     if (mirrored) {
   507         cacheKey.append('M');
   489         cacheKey.append('M');
   508     }
   490     }
   509 
   491 
   510     return cacheKey;
   492     return cacheKey;
   511 }
   493 }
   512 #endif
   494 #endif
   513 
   495 
   514 HbIconLoader::HbIconLoader(const QString &appName, QObject *parent)
   496 HbIconLoader::HbIconLoader(const QString &appName, QObject *parent)
   515     : QObject( parent )
   497     : QObject(parent)
   516 {
   498 {
   517     setObjectName( appName );
   499     setObjectName(appName);
   518     d = new HbIconLoaderPrivate();
   500     d = new HbIconLoaderPrivate();
   519 
   501 
   520     // Set default rendering mode to EHWRendering    
   502     // Set default rendering mode to EHWRendering
   521     renderMode = EHWRendering;
   503     renderMode = EHWRendering;
   522 
   504 
   523     // Delete the icon loader when the application is destroyed.
   505     // Delete the icon loader when the application is destroyed.
   524     connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(destroy()));
   506     connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(destroy()));
   525 
   507 
   526     connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChangeStarted()),
   508     connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChangeStarted()),
   527         this, SLOT(updateLayoutDirection()));
   509             this, SLOT(updateLayoutDirection()));
   528 
   510 
   529 #ifdef HB_TOOL_INTERFACE
   511 #ifdef HB_TOOL_INTERFACE
   530     // This enables partial theme updates.
   512     // This enables partial theme updates.
   531     connect(&hbInstance->theme()->d_ptr->iconTheme, SIGNAL(iconsUpdated(QStringList)), this, SLOT(themeChange(QStringList)));
   513     connect(&hbInstance->theme()->d_ptr->iconTheme, SIGNAL(iconsUpdated(QStringList)), this, SLOT(themeChange(QStringList)));
   532 #endif
   514 #endif
   574             d->animationLoading = false;
   556             d->animationLoading = false;
   575             return size;
   557             return size;
   576         }
   558         }
   577     }
   559     }
   578 
   560 
   579     // Step 2: There was no animation definition, try to get default size from theme index if it is a themed icon
   561     // Step 2: There was no animation definition,
   580     
   562     // try to get default size from theme index if it is a themed icon (logical name).
   581     // TODO: change this to simpler function call in Symbian OS env
   563 
   582     if (QDir::isRelativePath(iconName)) {
   564     if (HbThemeUtils::isLogicalName(iconName)) {
   583 #ifdef Q_OS_SYMBIAN
       
   584         // Try to get themed icon information from theme index
   565         // Try to get themed icon information from theme index
   585         HbThemeIndexResource resource(iconName);
   566         HbThemeIndexResource resource(iconName);
   586         if (resource.isValid()) {
   567         if (resource.isValid()) {
   587             // Try to get themed icon default size from theme index
   568             // Try to get themed icon default size from theme index
   588             if (params.mirrored && resource.mirroredItemSize().isValid()) {
   569             if (params.mirrored && resource.mirroredItemSize().isValid()) {
   589                 size = resource.mirroredItemSize();
   570                 size = resource.mirroredItemSize();
   590             } else {
   571             } else {
   591                 size = resource.defaultItemSize();
   572                 size = resource.defaultItemSize();
   592             }
   573             }
   593             // Returns invalid size if there is a valid theme index, but the item was not found there.
   574         }
   594             return size;
   575         // Returns invalid size if the index did not provide the size
   595         } else {
   576         return size;
   596             // Step 3: Theme index was not used, try to get icon's default size from theme server's default size cache.
       
   597             params.iconFileName = resolveIconFileName(params);
       
   598         }
       
   599 #else
       
   600         params.iconFileName = resolveIconFileName(params);
       
   601 #endif
       
   602     } else { // Absolute path, use it directly without resolving anything.
   577     } else { // Absolute path, use it directly without resolving anything.
   603         params.iconFileName = iconName;
   578         params.iconFileName = iconName;
   604     }
   579     }
   605 
   580 
   606     // If icon filename could not be resolved, return
   581     // If icon filename could not be resolved, return
   608         return size;
   583         return size;
   609     }
   584     }
   610 
   585 
   611     QString format = formatFromPath(params.iconFileName);
   586     QString format = formatFromPath(params.iconFileName);
   612 
   587 
   613 // Theme server on desktop was found very slow (probably due to IPC with QLocalServer/QLocalSocket).
   588     // Step 3: Get the default size from the icon file in the client side
   614 // disabling icon sharing via theme server until theme server performance on desktop is improved
       
   615 #ifdef Q_OS_SYMBIAN
       
   616     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory)
       
   617     // Try to take data from server if parameters don't prevent it
       
   618     if (manager && format != "MNG" && format != "GIF" &&
       
   619         !iconName.startsWith(':')) { // not using server for app's own resources (iconName is a logical name for theme elements)
       
   620 #ifdef HB_ICON_TRACES
       
   621         qDebug() << "HbIconLoader::DefaultSize req to server " << params.iconFileName;
       
   622 #endif
       
   623         QSizeF sizeFromServer = HbThemeClient::global()->getSharedIconDefaultSize(params.iconFileName);
       
   624 #ifdef HB_ICON_TRACES
       
   625         qDebug() << "HbIconLoader::DefaultSize result from server" << sizeFromServer;
       
   626 #endif
       
   627         if (sizeFromServer.isValid()) {
       
   628             return sizeFromServer;
       
   629         }
       
   630     }
       
   631 #endif // Q_OS_SYMBIAN
       
   632 
       
   633     // Step 4: Get the default size from the icon file in the client side
       
   634     HbIconSource *source = getIconSource(params.iconFileName, format);
   589     HbIconSource *source = getIconSource(params.iconFileName, format);
   635     size = source->defaultSize();
   590     size = source->defaultSize();
   636 
   591 
   637 #ifdef HB_ICON_TRACES
   592 #ifdef HB_ICON_TRACES
   638     qDebug() << "HbIconLoader::DefaultSize from file" << params.iconFileName << size;
   593     qDebug() << "HbIconLoader::DefaultSize from file" << params.iconFileName << size;
   655     }
   610     }
   656 }
   611 }
   657 
   612 
   658 bool HbIconLoader::iconsExist(const QString &iconName, const QStringList &suffixList)
   613 bool HbIconLoader::iconsExist(const QString &iconName, const QStringList &suffixList)
   659 {
   614 {
   660     QString name = HbIconLoaderPrivate::removeIconNameSuffix(iconName);
       
   661     bool found = true;
   615     bool found = true;
       
   616     bool logicalName = HbThemeUtils::isLogicalName(iconName);
       
   617 
       
   618     int suffixIndex = iconName.length();
       
   619     if (!logicalName) {
       
   620         // If it is an absolute icon path, the suffix is inserted before the file extension
       
   621         int index = iconName.lastIndexOf(QChar('.'));
       
   622         if (index > 0) {
       
   623             suffixIndex = index;
       
   624         }
       
   625     }
   662 
   626 
   663     foreach (const QString &suffix, suffixList) {
   627     foreach (const QString &suffix, suffixList) {
   664         bool dummy = false;
   628         bool dummy = false;
   665 
   629 
   666         QString path = HbIconLoaderPrivate::findSharedResourceHelper(name + suffix, false, dummy);
   630         QString nameWithSuffix = iconName;
       
   631         nameWithSuffix.insert(suffixIndex, suffix);
       
   632 
       
   633         QString path = HbIconLoaderPrivate::findSharedResourceHelper(nameWithSuffix, false, dummy);
   667         if (path.isEmpty()) {
   634         if (path.isEmpty()) {
   668             found = false;
   635             found = false;
   669             break;
   636             break;
   670         }
   637         }
   671     }
   638     }
   704     return d->resolution;
   671     return d->resolution;
   705 }
   672 }
   706 
   673 
   707 void HbIconLoader::applyResolutionCorrection(QSizeF &size)
   674 void HbIconLoader::applyResolutionCorrection(QSizeF &size)
   708 {
   675 {
   709     size = size * (qreal)(d->resolution) / (qreal)(d->sourceResolution) * d->zoom; 
   676     size = size * (qreal)(d->resolution) / (qreal)(d->sourceResolution) * d->zoom;
   710 }
   677 }
   711 
   678 
   712 void HbIconLoader::themeChange(const QStringList &updatedFiles)
   679 void HbIconLoader::themeChange(const QStringList &updatedFiles)
   713 {
   680 {
   714     foreach (HbFrameDrawerPrivate *frameDrawer, this->frameDrawerInstanceList) frameDrawer->themeChange(updatedFiles);
   681     foreach(HbFrameDrawerPrivate * frameDrawer, this->frameDrawerInstanceList) frameDrawer->themeChange(updatedFiles);
   715 }
   682 }
   716 
   683 
   717 void HbIconLoader::destroy()
   684 void HbIconLoader::destroy()
   718 {
   685 {
   719     if (theLoader) {
   686     if (theLoader) {
   728     // This method is called upon the signal 'layoutDirectionChangeStarted',
   695     // This method is called upon the signal 'layoutDirectionChangeStarted',
   729     // which is emitted before the signal 'layoutDirectionChanged'. Icon
   696     // which is emitted before the signal 'layoutDirectionChanged'. Icon
   730     // classes use that signal to update their pixmaps, so the new layout
   697     // classes use that signal to update their pixmaps, so the new layout
   731     // directionality must be updated in the icon loader before that.
   698     // directionality must be updated in the icon loader before that.
   732     // Thus, there are these separate signals.
   699     // Thus, there are these separate signals.
   733     QList<HbMainWindow*> allWindows = hbInstance->allMainWindows();
   700     QList<HbMainWindow *> allWindows = hbInstance->allMainWindows();
   734     HbMainWindow* primaryWindow = allWindows.value(0);
   701     HbMainWindow *primaryWindow = allWindows.value(0);
   735 
   702 
   736     d->setLayoutMirrored(primaryWindow->layoutDirection() == Qt::RightToLeft);
   703     d->setLayoutMirrored(primaryWindow->layoutDirection() == Qt::RightToLeft);
   737 }
   704 }
   738 
   705 
   739 void HbIconLoader::handleForegroundLost()
   706 void HbIconLoader::handleForegroundLost()
   740 {
   707 {
   741 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
   708 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
   742     // Remove SGImage /NVG type of icons 
   709     // Remove SGImage /NVG type of icons
   743     freeGpuIconData();
   710     freeGpuIconData();
   744     // delete the VGImage
   711     // delete the VGImage
   745     HbEglStates *eglStateInstance = HbEglStates::global();
   712     HbEglStates *eglStateInstance = HbEglStates::global();
   746     eglStateInstance->handleForegroundLost();
   713     eglStateInstance->handleForegroundLost();
   747     // notify the server to clear the SGImage and NVG type of icons from the client's session
   714     // notify the server to clear the SGImage and NVG type of icons from the client's session
   752 /*!
   719 /*!
   753  * Removes the  IconImpl entry from the client side cache
   720  * Removes the  IconImpl entry from the client side cache
   754  */
   721  */
   755 void HbIconLoader::removeItemInCache(HbIconImpl *iconImpl)
   722 void HbIconLoader::removeItemInCache(HbIconImpl *iconImpl)
   756 {
   723 {
   757 #ifdef HB_ICONIMPL_CACHE  
   724 #ifdef HB_ICONIMPL_CACHE
   758     if ( iconImpl ) {
   725     if (iconImpl) {
   759         iconImplCache.remove(iconImplCache.key(iconImpl));
   726         iconImplCache.remove(iconImplCache.key(iconImpl));
   760     }
   727     }
   761 #else
   728 #else
   762     Q_UNUSED(iconImpl);
   729     Q_UNUSED(iconImpl);
   763 #endif
   730 #endif
   768  *  It also resets the engine's iconImpl and MaskableIcon's iconImpl
   735  *  It also resets the engine's iconImpl and MaskableIcon's iconImpl
   769  */
   736  */
   770 void HbIconLoader::freeGpuIconData()
   737 void HbIconLoader::freeGpuIconData()
   771 {
   738 {
   772 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
   739 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
   773 	for( int i = 0; i < iconEngineList.count(); i++ ) {	    
   740     for (int i = 0; i < iconEngineList.count(); i++) {
   774         HbIconEngine *engine = iconEngineList.at(i);
   741         HbIconEngine *engine = iconEngineList.at(i);
   775 	    engine->resetIconImpl();
   742         engine->resetIconImpl();
   776 	}	
   743     }
   777 	for(int i = 0; i< frameDrawerInstanceList.count(); i++) {
   744     for (int i = 0; i < frameDrawerInstanceList.count(); i++) {
   778 	    HbFrameDrawerPrivate * fd = frameDrawerInstanceList.at(i);
   745         HbFrameDrawerPrivate *fd = frameDrawerInstanceList.at(i);
   779 	    if ( (fd->iconFormatType() == SGIMAGE) || (fd->iconFormatType() == NVG) ) {
   746         if ((fd->iconFormatType() == SGIMAGE) || (fd->iconFormatType() == NVG)) {
   780 	        fd->resetMaskableIcon();            
   747             fd->resetMaskableIcon();
   781 	    }    
   748         }
   782 	}    
   749     }
   783 #endif
   750 #endif
   784 }
   751 }
   785 
   752 
   786 /*!
   753 /*!
   787   \internal
   754   \internal
   788 
   755 
   789   This is a wrapper for findSharedResourceHelper(). It is used for getting 
   756   This is a wrapper for findSharedResourceHelper(). It is used for getting
   790   resources from the themeserver.
   757   resources from the themeserver.
   791 
   758 
   792   The return value is either same as \a name, when the file is not found in the
   759   The return value is either same as \a name, when the file is not found in the
   793   theme, or the full path and name to the file found in the theme. In certain
   760   theme, or the full path and name to the file found in the theme. In certain
   794   situations the return value can also be an empty string, therefore it should
   761   situations the return value can also be an empty string, therefore it should
   802 
   769 
   803 /*!
   770 /*!
   804   This function is used to register the IconEngine instance to IconLoader
   771   This function is used to register the IconEngine instance to IconLoader
   805  */
   772  */
   806 void HbIconLoader::storeIconEngineInfo(HbIconEngine *iconEngine)
   773 void HbIconLoader::storeIconEngineInfo(HbIconEngine *iconEngine)
   807 {    
   774 {
   808     iconEngineList.append( iconEngine );
   775     iconEngineList.append(iconEngine);
   809 }
   776 }
   810 
   777 
   811 /*!
   778 /*!
   812   This function is used to unregister the Iconengine instance from Iconloader
   779   This function is used to unregister the Iconengine instance from Iconloader
   813  */
   780  */
   814 void HbIconLoader::removeIconEngineInfo(HbIconEngine *iconEngine)
   781 void HbIconLoader::removeIconEngineInfo(HbIconEngine *iconEngine)
   815 {
   782 {
   816    iconEngineList.removeOne(iconEngine); 
   783     iconEngineList.removeOne(iconEngine);
   817 }
   784 }
   818 
   785 
   819 /*!
   786 /*!
   820   This function is used to register the FrameDrawerPrivate instance to IconLoader
   787   This function is used to register the FrameDrawerPrivate instance to IconLoader
   821  */
   788  */
   822 void HbIconLoader::storeFrameDrawerInfo( HbFrameDrawerPrivate *frameDrawer )
   789 void HbIconLoader::storeFrameDrawerInfo(HbFrameDrawerPrivate *frameDrawer)
   823 {
   790 {
   824     frameDrawerInstanceList.append(frameDrawer);
   791     frameDrawerInstanceList.append(frameDrawer);
   825 }
   792 }
   826 
   793 
   827 /*!
   794 /*!
   828   This function is used to unregister the FrameDrawerPrivate instance from IconLoader
   795   This function is used to unregister the FrameDrawerPrivate instance from IconLoader
   829  */
   796  */
   830 void HbIconLoader::removeFrameDrawerInfo( HbFrameDrawerPrivate *frameDrawer )
   797 void HbIconLoader::removeFrameDrawerInfo(HbFrameDrawerPrivate *frameDrawer)
   831 {
   798 {
   832     frameDrawerInstanceList.removeOne(frameDrawer);    
   799     frameDrawerInstanceList.removeOne(frameDrawer);
   833 }
   800 }
   834 
   801 
   835 void HbIconLoader::resolveCleanIconName(HbIconLoadingParams &params) const
   802 void HbIconLoader::resolveCleanIconName(HbIconLoadingParams &params) const
   836 {
   803 {
   837     // Replace empty icon name with the "unknown" icon if needed.
   804     // Replace empty icon name with the "unknown" icon if needed.
   838     if (params.iconName.isEmpty() && params.options.testFlag(ReturnUnknownIcon)) {
   805     if (params.iconName.isEmpty() && params.options.testFlag(ReturnUnknownIcon)) {
   839         params.cleanIconName = QString(s_unknown);
   806         params.cleanIconName = QString(s_unknown);
   840     } else {
   807     } else {
   841         params.cleanIconName = params.iconName; 
   808         params.cleanIconName = params.iconName;
   842     }
   809     }
   843 }
   810 }
   844 
   811 
   845 QSizeF HbIconLoader::getAnimationDefaultSize(HbIconAnimationDefinition &def, HbIconLoadingParams &params)
   812 QSizeF HbIconLoader::getAnimationDefaultSize(HbIconAnimationDefinition &def, HbIconLoadingParams &params)
   846 {
   813 {
   847     QList<HbIconAnimationDefinition::AnimationFrame> frameDefs = def.frameList();
   814     QList<HbIconAnimationDefinition::AnimationFrame> frameDefs = def.frameList();
   848     QList<HbIconAnimationFrameSet::FrameData> frameList;
   815     QList<HbIconAnimationFrameSet::FrameData> frameList;
   849 
   816 
   850     // Get the default size from the first animation frame
   817     // Get the default size from the first animation frame
   851     params.cleanIconName = frameDefs.at(0).iconName;
   818     return HbIconLoader::defaultSize(frameDefs.at(0).iconName, QString(), params.options);
   852     params.iconFileName = resolveIconFileName(params);
       
   853     QString format = formatFromPath(params.iconFileName);
       
   854 
       
   855     // Try to get the default size from server if the icon is not such that is loaded in client side.
       
   856     if (format != "MNG"
       
   857         && format != "GIF"
       
   858         && !params.iconFileName.startsWith(':'))
       
   859     {
       
   860         QSizeF defSize = HbThemeClient::global()->getSharedIconDefaultSize(params.iconFileName);
       
   861         if (defSize.isValid()) {
       
   862             return defSize;
       
   863         }
       
   864     }
       
   865 
       
   866     // Otherwise get if by calling HbIconLoader::defaultSize for the first animation frame
       
   867     return HbIconLoader::defaultSize(params.iconFileName, QString(), params.options);
       
   868 }
   819 }
   869 
   820 
   870 void HbIconLoader::loadAnimation(HbIconAnimationDefinition &def, HbIconLoadingParams &params)
   821 void HbIconLoader::loadAnimation(HbIconAnimationDefinition &def, HbIconLoadingParams &params)
   871 {
   822 {
   872     Q_ASSERT(!def.isNull());
   823     Q_ASSERT(!def.isNull());
   873 
   824 
   874     QList<HbIconAnimationDefinition::AnimationFrame> frameDefs = def.frameList();
   825     QList<HbIconAnimationDefinition::AnimationFrame> frameDefs = def.frameList();
   875     QList<HbIconAnimationFrameSet::FrameData> frameList;
   826     QList<HbIconAnimationFrameSet::FrameData> frameList;
   876     
   827 
   877 #ifdef HB_ICON_TRACES
   828 #ifdef HB_ICON_TRACES
   878     if (!params.animator) {
   829     if (!params.animator) {
   879         qDebug() << "HbIconLoader: no animator ptr provided, loading only frame 1 out of" << frameDefs.count();
   830         qDebug() << "HbIconLoader: no animator ptr provided, loading only frame 1 out of" << frameDefs.count();
   880     } else {
   831     } else {
   881         qDebug() << "HbIconLoader: loading" << frameDefs.count() << "frames";
   832         qDebug() << "HbIconLoader: loading" << frameDefs.count() << "frames";
   906         // ...otherwise load the frame with the loader
   857         // ...otherwise load the frame with the loader
   907         if (!frameReady) {
   858         if (!frameReady) {
   908             // Frame-by-frame animations are always loaded in normal mode.
   859             // Frame-by-frame animations are always loaded in normal mode.
   909             // The mode is applied when the icon is painted.
   860             // The mode is applied when the icon is painted.
   910             newFrame.pixmap = HbIconLoader::loadIcon(
   861             newFrame.pixmap = HbIconLoader::loadIcon(
   911                 frame.iconName,
   862                                   frame.iconName,
   912                 params.purpose,
   863                                   params.purpose,
   913                 params.size,
   864                                   params.size,
   914                 params.aspectRatioMode,
   865                                   params.aspectRatioMode,
   915                 QIcon::Normal,
   866                                   QIcon::Normal,
   916                 params.options,
   867                                   params.options,
   917                 0,
   868                                   0,
   918                 params.color);
   869                                   params.color);
   919             
   870 
   920             newFrame.duration = frame.duration;
   871             newFrame.duration = frame.duration;
   921             newFrame.assignJumps(frame.jumps);
   872             newFrame.assignJumps(frame.jumps);
   922         }
   873         }
   923         // Append the frame to the animation frame list
   874         // Append the frame to the animation frame list
   924         frameList.append(newFrame);
   875         frameList.append(newFrame);
   944         }
   895         }
   945 
   896 
   946         // Take default size from the first frame
   897         // Take default size from the first frame
   947         QSizeF renderSize = QSizeF(params.canvasPixmap.size());
   898         QSizeF renderSize = QSizeF(params.canvasPixmap.size());
   948 
   899 
   949         if(!params.isDefaultSize) {
   900         if (!params.isDefaultSize) {
   950             renderSize.scale(params.size, params.aspectRatioMode);
   901             renderSize.scale(params.size, params.aspectRatioMode);
   951         } else if (params.options.testFlag(ResolutionCorrected)) {
   902         } else if (params.options.testFlag(ResolutionCorrected)) {
   952             applyResolutionCorrection(renderSize);
   903             applyResolutionCorrection(renderSize);
   953         }
   904         }
   954 
   905 
   971     QString iconPath = d->findSharedResourceHelper(params.cleanIconName, params.mirrored, params.mirroredIconFound);
   922     QString iconPath = d->findSharedResourceHelper(params.cleanIconName, params.mirrored, params.mirroredIconFound);
   972     bool iconFound = !iconPath.isEmpty();
   923     bool iconFound = !iconPath.isEmpty();
   973 #ifdef HB_ICON_TRACES
   924 #ifdef HB_ICON_TRACES
   974     qDebug() << params.cleanIconName << " => " << iconPath;
   925     qDebug() << params.cleanIconName << " => " << iconPath;
   975 #endif
   926 #endif
   976     // If not found then it can still be a normal file specified with a relative path.
       
   977     if (!iconFound) {
       
   978         iconFound = QFile(params.iconName).exists();
       
   979         if (iconFound) {
       
   980             iconPath = params.iconName;
       
   981         }
       
   982     }
       
   983     // Use the 'unknown' icon, if needed, when the queried icon was not found.
   927     // Use the 'unknown' icon, if needed, when the queried icon was not found.
   984     if (!iconFound) {
   928     if (!iconFound) {
   985         if (params.options.testFlag(ReturnUnknownIcon)) {
   929         if (params.options.testFlag(ReturnUnknownIcon)) {
   986             iconPath = d->findSharedResourceHelper(s_unknown, false, params.mirroredIconFound);
   930             iconPath = d->findSharedResourceHelper(s_unknown, false, params.mirroredIconFound);
   987         }
   931         }
   990     return iconPath;
   934     return iconPath;
   991 }
   935 }
   992 
   936 
   993 /*!
   937 /*!
   994  * \fn HbIconImpl *HbIconLoader::getIconFromServer()
   938  * \fn HbIconImpl *HbIconLoader::getIconFromServer()
   995  * 
   939  *
   996  * Initiate an IPC to themeserver to get the icon-data from the server.
   940  * Initiate an IPC to themeserver to get the icon-data from the server.
   997  * 
   941  *
   998  */
   942  */
   999 HbIconImpl *HbIconLoader::getIconFromServer(HbIconLoadingParams &params)
   943 HbIconImpl *HbIconLoader::getIconFromServer(HbIconLoadingParams &params)
  1000 {
   944 {
  1001 
       
  1002     HbIconImpl *icon = 0;
   945     HbIconImpl *icon = 0;
  1003 
   946 
  1004 #ifdef HB_ICON_TRACES
   947 #ifdef HB_ICON_TRACES
  1005     qDebug() << "HbIconLoader::getIconFromServer: req to server for" << params.iconFileName;
   948     qDebug() << "HbIconLoader::getIconFromServer: req to server for" << params.iconFileName;
  1006 #endif
   949 #endif
  1017                    params.color,
   960                    params.color,
  1018                    params.renderMode);
   961                    params.renderMode);
  1019 
   962 
  1020     //Creates HbIconImpl instance based on the type of data returned by themeserver.
   963     //Creates HbIconImpl instance based on the type of data returned by themeserver.
  1021     //HbIconImpl thus created could be any one of the following impl-types:
   964     //HbIconImpl thus created could be any one of the following impl-types:
  1022     //1. HbSgImageIconImpl 
   965     //1. HbSgImageIconImpl
  1023     //2. HbNvgIconImpl
   966     //2. HbNvgIconImpl
  1024     //3. HbPixmapIconImpl
   967     //3. HbPixmapIconImpl
  1025     icon = HbIconImplCreator::createIconImpl(iconInfo, params);
   968     icon = HbIconImplCreator::createIconImpl(iconInfo, params);
  1026 
   969 
  1027 #ifdef HB_ICON_TRACES
   970 #ifdef HB_ICON_TRACES
  1041     QSizeF renderSize;
   984     QSizeF renderSize;
  1042 
   985 
  1043     if (svgRenderer && svgRenderer->isValid()) {
   986     if (svgRenderer && svgRenderer->isValid()) {
  1044         renderSize = QSizeF(svgRenderer->defaultSize());
   987         renderSize = QSizeF(svgRenderer->defaultSize());
  1045 
   988 
  1046         if(!params.isDefaultSize) {
   989         if (!params.isDefaultSize) {
  1047             renderSize.scale(params.size, params.aspectRatioMode);
   990             renderSize.scale(params.size, params.aspectRatioMode);
  1048         } else if (params.options.testFlag(ResolutionCorrected)) {
   991         } else if (params.options.testFlag(ResolutionCorrected)) {
  1049             applyResolutionCorrection(renderSize);
   992             applyResolutionCorrection(renderSize);
  1050         }
   993         }
  1051 
   994 
  1092         QPainter painter;
  1035         QPainter painter;
  1093         painter.begin(&pm);
  1036         painter.begin(&pm);
  1094         svgRenderer->render(&painter, QRectF(QPointF(), renderSize.toSize()));
  1037         svgRenderer->render(&painter, QRectF(QPointF(), renderSize.toSize()));
  1095         painter.end();
  1038         painter.end();
  1096     }
  1039     }
  1097     
  1040 
  1098     source->releaseSvgRenderer();
  1041     source->releaseSvgRenderer();
  1099 }
  1042 }
  1100 
  1043 
  1101 void HbIconLoader::loadPictureIcon(HbIconLoadingParams &params)
  1044 void HbIconLoader::loadPictureIcon(HbIconLoadingParams &params)
  1102 {
  1045 {
  1109 
  1052 
  1110         qreal sx = 1.0;
  1053         qreal sx = 1.0;
  1111         qreal sy = 1.0;
  1054         qreal sy = 1.0;
  1112         bool scale = false;
  1055         bool scale = false;
  1113 
  1056 
  1114         if(!params.isDefaultSize) {
  1057         if (!params.isDefaultSize) {
  1115             scale = true;
  1058             scale = true;
  1116             renderSize.scale(params.size, params.aspectRatioMode);
  1059             renderSize.scale(params.size, params.aspectRatioMode);
  1117         } else if (params.options.testFlag(ResolutionCorrected)) {
  1060         } else if (params.options.testFlag(ResolutionCorrected)) {
  1118             qreal scaleFactor = (qreal)(d->resolution) / (qreal)(d->sourceResolution) * d->zoom;
  1061             qreal scaleFactor = (qreal)(d->resolution) / (qreal)(d->sourceResolution) * d->zoom;
  1119             if (!qFuzzyCompare(scaleFactor, qreal(1.0))) {
  1062             if (!qFuzzyCompare(scaleFactor, qreal(1.0))) {
  1121                 renderSize *= scaleFactor;
  1064                 renderSize *= scaleFactor;
  1122             }
  1065             }
  1123         }
  1066         }
  1124 
  1067 
  1125         if (scale) {
  1068         if (scale) {
  1126             // Determine scale factor as QPicture doesn't allow for scaling 
  1069             // Determine scale factor as QPicture doesn't allow for scaling
  1127             sx = renderSize.width() / picSize.width();
  1070             sx = renderSize.width() / picSize.width();
  1128             sy = renderSize.height() / picSize.height();
  1071             sy = renderSize.height() / picSize.height();
  1129         }
  1072         }
  1130 
  1073 
  1131         QPixmap &pm = params.canvasPixmap;
  1074         QPixmap &pm = params.canvasPixmap;
  1151     bool animationCreated = false;
  1094     bool animationCreated = false;
  1152 
  1095 
  1153     if (imgRenderer && imgRenderer->canRead()) {
  1096     if (imgRenderer && imgRenderer->canRead()) {
  1154         renderSize = QSizeF(imgRenderer->size());
  1097         renderSize = QSizeF(imgRenderer->size());
  1155 
  1098 
  1156         if(!params.isDefaultSize) {
  1099         if (!params.isDefaultSize) {
  1157             renderSize.scale(params.size, params.aspectRatioMode);
  1100             renderSize.scale(params.size, params.aspectRatioMode);
  1158         } else if (params.options.testFlag(ResolutionCorrected)) {
  1101         } else if (params.options.testFlag(ResolutionCorrected)) {
  1159             applyResolutionCorrection(renderSize);
  1102             applyResolutionCorrection(renderSize);
  1160         }
  1103         }
  1161 
  1104 
  1208         }
  1151         }
  1209 
  1152 
  1210         QImage img = imgRenderer->read();
  1153         QImage img = imgRenderer->read();
  1211         params.canvasPixmap = QPixmap::fromImage(img);
  1154         params.canvasPixmap = QPixmap::fromImage(img);
  1212     }
  1155     }
  1213     
  1156 
  1214     source->releaseImageReader();
  1157     source->releaseImageReader();
  1215 }
  1158 }
  1216 
  1159 
  1217 void HbIconLoader::loadPixmapIcon(HbIconLoadingParams &params, const QString &format)
  1160 void HbIconLoader::loadPixmapIcon(HbIconLoadingParams &params, const QString &format)
  1218 {
  1161 {
  1227         // This test implementation improves resize speed up to 5 times..
  1170         // This test implementation improves resize speed up to 5 times..
  1228         if (!params.isDefaultSize && !params.size.isEmpty()) {
  1171         if (!params.isDefaultSize && !params.size.isEmpty()) {
  1229             // Smooth scaling is very expensive (size^2). Therefore we reduce the size
  1172             // Smooth scaling is very expensive (size^2). Therefore we reduce the size
  1230             // to 1.5 of the destination size and using fast transformation.
  1173             // to 1.5 of the destination size and using fast transformation.
  1231             // Therefore we speed up but don't loose quality..
  1174             // Therefore we speed up but don't loose quality..
  1232             if ( pm.size().width() > ( 4 * params.size.toSize().width() ) ) {
  1175             if (pm.size().width() > (4 * params.size.toSize().width())) {
  1233                 // Improve scaling speed by add an intermediate fast transformation..
  1176                 // Improve scaling speed by add an intermediate fast transformation..
  1234                 QSize intermediate_size = QSize( params.size.toSize().width() * 2, params.size.toSize().height() * 2 );
  1177                 QSize intermediate_size = QSize(params.size.toSize().width() * 2, params.size.toSize().height() * 2);
  1235                 pm = pm.scaled(
  1178                 pm = pm.scaled(
  1236                     intermediate_size,
  1179                          intermediate_size,
  1237                     params.aspectRatioMode,
  1180                          params.aspectRatioMode,
  1238                     Qt::FastTransformation ); // Cheap operation!
  1181                          Qt::FastTransformation);  // Cheap operation!
  1239             }
  1182             }
  1240 #endif // ENABLE_EXPERIMENTAL_RESIZE_BOOST__
  1183 #endif // ENABLE_EXPERIMENTAL_RESIZE_BOOST__
  1241 
  1184 
  1242             pm = pm.scaled(
  1185             pm = pm.scaled(
  1243                 params.size.toSize(),
  1186                      params.size.toSize(),
  1244                 params.aspectRatioMode,
  1187                      params.aspectRatioMode,
  1245                 Qt::SmoothTransformation); // Expensive operation!
  1188                      Qt::SmoothTransformation); // Expensive operation!
  1246 
  1189 
  1247 #ifdef ENABLE_EXPERIMENTAL_RESIZE_BOOST__
  1190 #ifdef ENABLE_EXPERIMENTAL_RESIZE_BOOST__
  1248         }
  1191         }
  1249 #endif
  1192 #endif
  1250     }
  1193     }
  1253     source->deletePixmapIfLargerThan(PIXMAP_SIZE_LIMIT);
  1196     source->deletePixmapIfLargerThan(PIXMAP_SIZE_LIMIT);
  1254 }
  1197 }
  1255 
  1198 
  1256 /*!
  1199 /*!
  1257  * \fn void HbIconLoader::switchRenderingMode()
  1200  * \fn void HbIconLoader::switchRenderingMode()
  1258  * 
  1201  *
  1259  * This function gets notified when the rendering mode of the application changes e.g
  1202  * This function gets notified when the rendering mode of the application changes e.g
  1260  * ( Hardware - Software rendering or vice versa ). If the mode is changed from 
  1203  * ( Hardware - Software rendering or vice versa ). If the mode is changed from
  1261  *  Hardware to Software, all Hardware rendered icons will release the GPU resources.
  1204  *  Hardware to Software, all Hardware rendered icons will release the GPU resources.
  1262  *  This function also initiates an IPC call to ThemeServer, so that the server 
  1205  *  This function also initiates an IPC call to ThemeServer, so that the server
  1263  *  can do its part of cleanup. 
  1206  *  can do its part of cleanup.
  1264  *  \a newRenderMode new rendering mode of application 
  1207  *  \a newRenderMode new rendering mode of application
  1265  */ 
  1208  */
  1266 
  1209 
  1267 void HbIconLoader::switchRenderingMode(HbRenderingMode newRenderMode)
  1210 void HbIconLoader::switchRenderingMode(HbRenderingMode newRenderMode)
  1268 {
  1211 {
  1269 #ifndef Q_OS_SYMBIAN
  1212 #ifndef Q_OS_SYMBIAN
  1270     Q_UNUSED(newRenderMode)
  1213     Q_UNUSED(newRenderMode)
  1271 #endif
  1214 #endif
  1272 
  1215 
  1273 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
  1216 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
  1274     if (newRenderMode != renderMode) {     
  1217     if (newRenderMode != renderMode) {
  1275         if (newRenderMode == ESWRendering) {
  1218         if (newRenderMode == ESWRendering) {
  1276             // switching from HW to SW mode  
  1219             // switching from HW to SW mode
  1277             freeGpuIconData();            
  1220             freeGpuIconData();
  1278         }        
  1221         }
  1279         if (HbThemeClient::global()->switchRenderingMode(newRenderMode)) {         
  1222         if (HbThemeClient::global()->switchRenderingMode(newRenderMode)) {
  1280             renderMode = newRenderMode;
  1223             renderMode = newRenderMode;
  1281         }
  1224         }
  1282     }
  1225     }
  1283 #endif
  1226 #endif
  1284 }
  1227 }
  1292     }
  1235     }
  1293 }
  1236 }
  1294 
  1237 
  1295 /*!
  1238 /*!
  1296  * \fn HbIconImpl* HbIconLoader::loadIcon()
  1239  * \fn HbIconImpl* HbIconLoader::loadIcon()
  1297  * 
  1240  *
  1298  * This function is responsible for loading a single-piece icon .
  1241  * This function is responsible for loading a single-piece icon .
  1299  * First it checks whether the icon is present on the application (client)cache,
  1242  * First it checks whether the icon is present on the application (client)cache,
  1300  * if found it increments the ref-count of the HbIconImpl and returns. If the icon
  1243  * if found it increments the ref-count of the HbIconImpl and returns. If the icon
  1301  * is not found in the client's impl-cache, it initiates an IPC to themeserver
  1244  * is not found in the client's impl-cache, it initiates an IPC to themeserver
  1302  * to load the icon. It receives HbSharedIconInfo from themeserver, creates a HbIconImpl
  1245  * to load the icon. It receives HbSharedIconInfo from themeserver, creates a HbIconImpl
  1303  * from this data, inserts this into client's icon-impl-cache and returns.
  1246  * from this data, inserts this into client's icon-impl-cache and returns.
  1304  * 
  1247  *
  1305  */ 
  1248  */
  1306 HbIconImpl *HbIconLoader::loadIcon(
  1249 HbIconImpl *HbIconLoader::loadIcon(
  1307     const QString &iconName,
  1250     const QString &iconName,
  1308     IconDataType type, 
  1251     IconDataType type,
  1309     HbIconLoader::Purpose purpose, 
  1252     HbIconLoader::Purpose purpose,
  1310     const QSizeF &size, 
  1253     const QSizeF &size,
  1311     Qt::AspectRatioMode aspectRatioMode, 
  1254     Qt::AspectRatioMode aspectRatioMode,
  1312     QIcon::Mode mode, 
  1255     QIcon::Mode mode,
  1313     IconLoaderOptions options, 
  1256     IconLoaderOptions options,
  1314     HbIconAnimator *animator,
  1257     HbIconAnimator *animator,
  1315     const QColor &color)
  1258     const QColor &color)
  1316 {
  1259 {
  1317 #ifdef HB_ICON_TRACES
  1260 #ifdef HB_ICON_TRACES
  1318     QString debugString = "HbIconLoader::loadIcon START - ";
  1261     QString debugString = "HbIconLoader::loadIcon START - ";
  1325         debugString.append('x');
  1268         debugString.append('x');
  1326         debugString.append(QString::number(size.height()));
  1269         debugString.append(QString::number(size.height()));
  1327     }
  1270     }
  1328     qDebug() << debugString;
  1271     qDebug() << debugString;
  1329 #endif
  1272 #endif
  1330     Q_UNUSED( type )
  1273     Q_UNUSED(type)
  1331 
  1274 
  1332     HbIconImpl* icon = 0;
  1275     HbIconImpl *icon = 0;
  1333 
  1276 
  1334     if (!size.isValid()) {
  1277     if (!size.isValid()) {
  1335         return 0;
  1278         return 0;
  1336     }
  1279     }
  1337 
  1280 
  1343     params.aspectRatioMode = aspectRatioMode;
  1286     params.aspectRatioMode = aspectRatioMode;
  1344     params.mode = mode;
  1287     params.mode = mode;
  1345     params.options = options;
  1288     params.options = options;
  1346     params.animator = animator;
  1289     params.animator = animator;
  1347     params.color = color;
  1290     params.color = color;
  1348     params.isDefaultSize = ( purpose == AnyPurpose ) && size.isNull();
  1291     params.isDefaultSize = (purpose == AnyPurpose) && size.isNull();
  1349     params.mirrored = options.testFlag(HorizontallyMirrored);
  1292     params.mirrored = options.testFlag(HorizontallyMirrored);
  1350     params.mirroredIconFound = false;
  1293     params.mirroredIconFound = false;
  1351     params.canCache = true;
  1294     params.canCache = true;
  1352     params.animationCreated = false;
  1295     params.animationCreated = false;
  1353     params.mirroringHandled = false;
  1296     params.mirroringHandled = false;
  1379         }
  1322         }
  1380     }
  1323     }
  1381 
  1324 
  1382     // Step 2: There was no animation definition, try get icon from server
  1325     // Step 2: There was no animation definition, try get icon from server
  1383     if (!params.animationCreated) {
  1326     if (!params.animationCreated) {
  1384     
  1327 
  1385 #ifdef HB_ICONIMPL_CACHE
  1328 #ifdef HB_ICONIMPL_CACHE
  1386         QByteArray cacheKey = d->createCacheKeyFrom( params.iconName, params.size, params.aspectRatioMode,
  1329         QByteArray cacheKey = d->createCacheKeyFrom(params.iconName,
  1387                         params.mode, params.mirrored, params.color, params.renderMode );
  1330                               params.size,
  1388         //look up in the local iconImplCache. 
  1331                               params.aspectRatioMode,
       
  1332                               params.mode,
       
  1333                               params.mirrored,
       
  1334                               params.color,
       
  1335                               params.renderMode);
       
  1336         //look up in the local iconImplCache.
  1389         //If found return the ptr directly
  1337         //If found return the ptr directly
  1390         if (iconImplCache.contains(cacheKey)) {
  1338         if (iconImplCache.contains(cacheKey)) {
  1391             HbIconImpl * ptr = iconImplCache.value(cacheKey);
  1339             HbIconImpl *ptr = iconImplCache.value(cacheKey);
  1392             ptr->incrementRefCount();
  1340             ptr->incrementRefCount();
  1393 #ifdef HB_ICON_CACHE_DEBUG
  1341 #ifdef HB_ICON_CACHE_DEBUG
  1394             qDebug() << "HbIconLoader::loadIcon(): " << "Cache hit in iconImplCache for" << params.iconName<<params.size.height() <<"X"<< params.size.width() ;
  1342             qDebug() << "HbIconLoader::loadIcon(): " << "Cache hit in iconImplCache for" << params.iconName << params.size.height() << "X" << params.size.width() ;
  1395             qDebug() << "HbIconLoader::loadIcon(): Client RefCount now = " <<ptr->refCount();
  1343             qDebug() << "HbIconLoader::loadIcon(): Client RefCount now = " << ptr->refCount();
  1396 #endif        
  1344 #endif
  1397             return ptr;
  1345             return ptr;
  1398         }
  1346         }
  1399 #endif
  1347 #endif
  1400         if (QDir::isRelativePath(iconName)) {
  1348 
       
  1349         // Resolve used icon filename. It uses themeindex for themed icons.
       
  1350         params.iconFileName = resolveIconFileName(params);
       
  1351 
       
  1352         if (HbThemeUtils::isLogicalName(iconName)) {
  1401             params.iconFileName = resolveIconFileName(params);
  1353             params.iconFileName = resolveIconFileName(params);
  1402         } else {
       
  1403             params.iconFileName = iconName;
       
  1404         }
  1354         }
  1405 
  1355 
  1406         // If icon filename could not be resolved, return
  1356         // If icon filename could not be resolved, return
  1407         if (params.iconFileName.isEmpty()) {
  1357         if (params.iconFileName.isEmpty()) {
  1408 #ifdef HB_ICON_TRACES
  1358 #ifdef HB_ICON_TRACES
  1409             qDebug() << "HbIconLoader::loadIcon (empty icon) END";
  1359             qDebug() << "HbIconLoader::loadIcon (empty icon) END";
  1410 #endif
  1360 #endif
  1411             icon = new HbPixmapIconImpl(params.canvasPixmap);
  1361             icon = new HbPixmapIconImpl(params.canvasPixmap);
  1412             return icon;
  1362             return icon;
  1413         }
  1363         }
       
  1364 
       
  1365 #ifdef Q_OS_SYMBIAN
       
  1366         // Check whether icon is in a private directory which cannot be accessed by the theme server
       
  1367         bool privateDirectory = isInPrivateDirectory(iconName);
       
  1368 #endif // Q_OS_SYMBIAN
  1414 
  1369 
  1415         QString format = formatFromPath(params.iconFileName);
  1370         QString format = formatFromPath(params.iconFileName);
  1416 
  1371 
  1417 // Theme server on desktop was found very slow (probably due to IPC with QLocalServer/QLocalSocket).
  1372 // Theme server on desktop was found very slow (probably due to IPC with QLocalServer/QLocalSocket).
  1418 // disabling icon sharing via theme server until theme server performance on desktop is improved
  1373 // disabling icon sharing via theme server until theme server performance on desktop is improved
  1419 #ifdef Q_OS_SYMBIAN
  1374 #ifdef Q_OS_SYMBIAN
  1420         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory)
  1375         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory)
  1421         // Try to take data from server if parameters don't prevent it
  1376         // Try to take data from server if parameters don't prevent it
  1422         if (!options.testFlag(DoNotCache) 
  1377         if (!options.testFlag(DoNotCache)
  1423             && format != "MNG" 
  1378                 && format != "MNG"
  1424             && format != "GIF" 
  1379                 && format != "GIF"
  1425             && !iconName.startsWith(':') // not using server for app's own resources (iconName is a logical name for theme elements)
  1380                 && !iconName.startsWith(':') // not using server for app's own resources (iconName is a logical name for theme elements)
  1426             && manager ) {
  1381                 && !privateDirectory // server cannot load from protected private dir
       
  1382                 && manager) {
  1427 
  1383 
  1428             //Initiate an IPC to themeserver to get the icon-data from the server.
  1384             //Initiate an IPC to themeserver to get the icon-data from the server.
  1429             icon = getIconFromServer(params);
  1385             icon = getIconFromServer(params);
  1430 
  1386 
  1431             if (icon) {
  1387             if (icon) {
  1432 #ifdef HB_ICONIMPL_CACHE
  1388 #ifdef HB_ICONIMPL_CACHE
  1433                 iconImplCache.insert(cacheKey, icon);
  1389                 iconImplCache.insert(cacheKey, icon);
  1434 #ifdef HB_ICON_CACHE_DEBUG
  1390 #ifdef HB_ICON_CACHE_DEBUG
  1435                 qDebug() <<"HbIconLoader::loadIcon(): " << params.iconName << " inserted into impl-cache, ref-count now = " << icon->refCount();
  1391                 qDebug() << "HbIconLoader::loadIcon(): " << params.iconName << " inserted into impl-cache, ref-count now = " << icon->refCount();
  1436 #endif
  1392 #endif
  1437 
  1393 
  1438 #endif
  1394 #endif
  1439                 return icon;
  1395                 return icon;
  1440             }
  1396             }
  1458 
  1414 
  1459     if (!params.mirroringHandled) {
  1415     if (!params.mirroringHandled) {
  1460         // Apply mirroring if required
  1416         // Apply mirroring if required
  1461         if (params.mirrored && !params.mirroredIconFound) {
  1417         if (params.mirrored && !params.mirroredIconFound) {
  1462             QTransform t;
  1418             QTransform t;
  1463             t.scale(-1,1);
  1419             t.scale(-1, 1);
  1464             params.canvasPixmap = params.canvasPixmap.transformed(t);
  1420             params.canvasPixmap = params.canvasPixmap.transformed(t);
  1465         }
  1421         }
  1466     }
  1422     }
  1467 
  1423 
  1468     if (!params.modeHandled) {
  1424     if (!params.modeHandled) {
  1471             QStyleOption opt(0);
  1427             QStyleOption opt(0);
  1472             opt.palette = QApplication::palette();
  1428             opt.palette = QApplication::palette();
  1473             params.canvasPixmap = QApplication::style()->generatedIconPixmap(mode, params.canvasPixmap, &opt);
  1429             params.canvasPixmap = QApplication::style()->generatedIconPixmap(mode, params.canvasPixmap, &opt);
  1474         }
  1430         }
  1475     }
  1431     }
  1476     
  1432 
  1477     if ((params.color.isValid()) && (params.mode != QIcon::Disabled)) {
  1433     if ((params.color.isValid()) && (params.mode != QIcon::Disabled)) {
  1478         QPixmap &pm = params.canvasPixmap;
  1434         QPixmap &pm = params.canvasPixmap;
  1479         if(!pm.isNull()) {
  1435         if (!pm.isNull()) {
  1480             QPixmap mask = pm.alphaChannel(); 
  1436             QPixmap mask = pm.alphaChannel();
  1481             pm.fill(color);
  1437             pm.fill(color);
  1482             pm.setAlphaChannel(mask);
  1438             pm.setAlphaChannel(mask);
  1483         }
  1439         }
  1484     }
  1440     }
  1485 
  1441 
  1491     return icon;
  1447     return icon;
  1492 }
  1448 }
  1493 
  1449 
  1494 /*!
  1450 /*!
  1495  * \fn HbIconImpl* HbIconLoader::loadMultiPieceIcon()
  1451  * \fn HbIconImpl* HbIconLoader::loadMultiPieceIcon()
  1496  * 
  1452  *
  1497  * This function is responsible for loading a multi-piece icon (e.g. 3-piece or 9-piece).
  1453  * This function is responsible for loading a multi-piece icon (e.g. 3-piece or 9-piece).
  1498  * First it checks whether the consolidated (stitched) icon is present in the application (client)
  1454  * First it checks whether the consolidated (stitched) icon is present in the application (client)
  1499  * cache, if found it increments the ref-count of the HbIconImpl and returns. If the icon
  1455  * cache, if found it increments the ref-count of the HbIconImpl and returns. If the icon
  1500  * is not found in the client's impl-cache, it initiates an IPC to themeserver
  1456  * is not found in the client's impl-cache, it initiates an IPC to themeserver
  1501  * to try to load the consolidated icon. If the consolidated (stitched) icon fails in themeserver, the server
  1457  * to try to load the consolidated icon. If the consolidated (stitched) icon fails in themeserver, the server
  1502  * returns a list of icon-data for individual pieces. Each of these pieces will be painted separately
  1458  * returns a list of icon-data for individual pieces. Each of these pieces will be painted separately
  1503  * 
  1459  *
  1504  */
  1460  */
  1505 HbIconImpl* HbIconLoader::loadMultiPieceIcon(const QStringList &listOfIcons,
  1461 HbIconImpl *HbIconLoader::loadMultiPieceIcon(const QStringList &listOfIcons,
  1506                                     HbMultiPartSizeData &multiPartIconData,
  1462         HbMultiPartSizeData &multiPartIconData,
  1507                                     const QSizeF &size,
  1463         const QSizeF &size,
  1508                                     Qt::AspectRatioMode aspectRatioMode,
  1464         Qt::AspectRatioMode aspectRatioMode,
  1509                                     QIcon::Mode mode,
  1465         QIcon::Mode mode,
  1510                                     IconLoaderOptions options,
  1466         IconLoaderOptions options,
  1511                                     QVector<HbIconImpl *> &multiPieceImpls,
  1467         QVector<HbIconImpl *> &multiPieceImpls,
  1512                                     const QColor &color)
  1468         const QColor &color)
  1513 {   
  1469 {
  1514     Q_UNUSED(color);
  1470     Q_UNUSED(color);
  1515     HbIconImpl* icon = 0;
  1471     HbIconImpl *icon = 0;
  1516     if (listOfIcons.count() == 0) {
  1472     if (listOfIcons.count() == 0) {
  1517         return icon;
  1473         return icon;
  1518     }
  1474     }
  1519     
  1475 
  1520     // Whether the icon should be horizontally mirrored
  1476     // Whether the icon should be horizontally mirrored
  1521     bool mirrored = options.testFlag(HorizontallyMirrored);
  1477     bool mirrored = options.testFlag(HorizontallyMirrored);
  1522 
  1478 
  1523     // Whether mirrored version of the icon was found in the file system (otherwise it's mirrored by code).
  1479     // Whether mirrored version of the icon was found in the file system (otherwise it's mirrored by code).
  1524     bool mirroredIconFound = false;
  1480     bool mirroredIconFound = false;
  1526     // We don't want to get the consolidated icon for only NVG build, ie. without SGImage lite support.
  1482     // We don't want to get the consolidated icon for only NVG build, ie. without SGImage lite support.
  1527     // Consolidated icon will be created for NVG with SGImage lite support.
  1483     // Consolidated icon will be created for NVG with SGImage lite support.
  1528     // and when NVG is not available.
  1484     // and when NVG is not available.
  1529 #if defined(HB_ICONIMPL_CACHE)
  1485 #if defined(HB_ICONIMPL_CACHE)
  1530 
  1486 
  1531     QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconData.multiPartIconId, size,
  1487     QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconData.multiPartIconId,
  1532                           aspectRatioMode, mode, mirrored, color, renderMode);
  1488                           size,
       
  1489                           aspectRatioMode,
       
  1490                           mode,
       
  1491                           mirrored,
       
  1492                           color,
       
  1493                           renderMode);
  1533     //If consolidated icon found in the client's cache, increment ref-count and return
  1494     //If consolidated icon found in the client's cache, increment ref-count and return
  1534     if (iconImplCache.contains(cacheKey)) {
  1495     if (iconImplCache.contains(cacheKey)) {
  1535         HbIconImpl * ptr = iconImplCache.value(cacheKey);
  1496         HbIconImpl *ptr = iconImplCache.value(cacheKey);
  1536         ptr->incrementRefCount();
  1497         ptr->incrementRefCount();
  1537 #ifdef HB_ICON_CACHE_DEBUG
  1498 #ifdef HB_ICON_CACHE_DEBUG
  1538         qDebug() << "HbIconLoader::loadMultiPieceIcon()" << "Cache hit in iconImplCache " << multiPartIconData.multiPartIconId << size.height() << "X" << size.width() ;
  1499         qDebug() << "HbIconLoader::loadMultiPieceIcon()" << "Cache hit in iconImplCache " << multiPartIconData.multiPartIconId << size.height() << "X" << size.width() ;
  1539         qDebug() << "HbIconLoader::loadMultiPieceIcon : Client RefCount now = " << ptr->refCount();
  1500         qDebug() << "HbIconLoader::loadMultiPieceIcon : Client RefCount now = " << ptr->refCount();
  1540 #endif
  1501 #endif
  1558 #ifdef  Q_OS_SYMBIAN
  1519 #ifdef  Q_OS_SYMBIAN
  1559 
  1520 
  1560     //If consolidated icon was not found in the client's cache, initiate an IPC to load
  1521     //If consolidated icon was not found in the client's cache, initiate an IPC to load
  1561     //the consolidated icon on themeserver
  1522     //the consolidated icon on themeserver
  1562     iconInfo = HbThemeClient::global()->getMultiPartIconInfo(iconPathList,
  1523     iconInfo = HbThemeClient::global()->getMultiPartIconInfo(iconPathList,
  1563                                                              multiPartIconData, size, aspectRatioMode, mode,
  1524                multiPartIconData, size, aspectRatioMode, mode,
  1564                                                              (mirrored && !mirroredIconFound), options, color, renderMode);
  1525                (mirrored && !mirroredIconFound), options, color, renderMode);
  1565 
  1526 
  1566 #ifdef HB_ICON_TRACES
  1527 #ifdef HB_ICON_TRACES
  1567     qDebug() << "HbIconLoader::getMultiPartIconInfo, offset from server: " << iconInfo.pixmapData.offset << iconPathList;
  1528     qDebug() << "HbIconLoader::getMultiPartIconInfo, offset from server: " << iconInfo.pixmapData.offset << iconPathList;
  1568 #endif
  1529 #endif
  1569 
  1530 
  1609         //Since the consolidated icon-creation failed on themeserver, request loading of individual
  1570         //Since the consolidated icon-creation failed on themeserver, request loading of individual
  1610         //frame-items in a single IPC request to themeserver
  1571         //frame-items in a single IPC request to themeserver
  1611         getMultiIconImplFromServer(iconPathList, sizeList,
  1572         getMultiIconImplFromServer(iconPathList, sizeList,
  1612                                    aspectRatioMode,
  1573                                    aspectRatioMode,
  1613                                    mode,
  1574                                    mode,
  1614                                    mirrored, 
  1575                                    mirrored,
  1615                                    mirroredIconFound,
  1576                                    mirroredIconFound,
  1616                                    options,
  1577                                    options,
  1617                                    color,
  1578                                    color,
  1618                                    HbIconLoader::AnyType,
  1579                                    HbIconLoader::AnyType,
  1619                                    HbIconLoader::AnyPurpose,
  1580                                    HbIconLoader::AnyPurpose,
  1620                                    multiPieceImpls,
  1581                                    multiPieceImpls,
  1621                                    renderMode);  
  1582                                    renderMode);
  1622 #else
  1583 #else
  1623         //For OS other than Symbian, call HbIconLoader::loadIcon to individually load icons
  1584         //For OS other than Symbian, call HbIconLoader::loadIcon to individually load icons
  1624         for (int i = 0; i < count; i++) {
  1585         for (int i = 0; i < count; i++) {
  1625             HbIconImpl *impl = loadIcon(iconPathList[i], HbIconLoader::AnyType,
  1586             HbIconImpl *impl = loadIcon(iconPathList[i], HbIconLoader::AnyType,
  1626                                         HbIconLoader::AnyPurpose,
  1587                                         HbIconLoader::AnyPurpose,
  1639         return icon;
  1600         return icon;
  1640     }
  1601     }
  1641 }
  1602 }
  1642 
  1603 
  1643 // Initiates an IPC call to the ThemeServer to unload ( decrement ref count ) the icon
  1604 // Initiates an IPC call to the ThemeServer to unload ( decrement ref count ) the icon
  1644 void HbIconLoader::unLoadIcon(HbIconImpl * icon, bool unloadedByServer)
  1605 void HbIconLoader::unLoadIcon(HbIconImpl *icon, bool unloadedByServer)
  1645 {
  1606 {
  1646     if (!icon) {
  1607     if (!icon) {
  1647         return;
  1608         return;
  1648     }
  1609     }
  1649 
  1610 
  1650     icon->decrementRefCount();
  1611     icon->decrementRefCount();
  1651 
  1612 
  1652     if (icon->refCount() == 0 && icon->isCreatedOnServer()) {
  1613     if (icon->refCount() == 0 && icon->isCreatedOnServer()) {
  1653         if (!unloadedByServer) {
  1614         if (!unloadedByServer) {
  1654            HbThemeClient::global()->unloadIcon(icon->iconFileName(),
  1615             HbThemeClient::global()->unloadIcon(icon->iconFileName(),
  1655                                                icon->keySize(),
  1616                                                 icon->keySize(),
  1656                                                icon->iconAspectRatioMode(),
  1617                                                 icon->iconAspectRatioMode(),
  1657                                                icon->iconMode(),
  1618                                                 icon->iconMode(),
  1658                                                icon->isMirrored(),
  1619                                                 icon->isMirrored(),
  1659                                                icon->color(),
  1620                                                 icon->color(),
  1660                                                icon->iconRenderingMode()
  1621                                                 icon->iconRenderingMode()
  1661                                                );
  1622                                                );
  1662         }
  1623         }
  1663 #ifdef HB_ICONIMPL_CACHE
  1624 #ifdef HB_ICONIMPL_CACHE
  1664         int rem = iconImplCache.remove(iconImplCache.key(icon));
  1625         int rem = iconImplCache.remove(iconImplCache.key(icon));
  1665         if (rem > 0) {
  1626         if (rem > 0) {
  1690     return pixmap;
  1651     return pixmap;
  1691 }
  1652 }
  1692 
  1653 
  1693 /*!
  1654 /*!
  1694  * \fn void HbIconLoader::getMultiIconImplFromServer()
  1655  * \fn void HbIconLoader::getMultiIconImplFromServer()
  1695  * 
  1656  *
  1696  * This function is responsible for loading individual pieces of a multi-piece icon.
  1657  * This function is responsible for loading individual pieces of a multi-piece icon.
  1697  * This gets called if the consolidated icon-creation process on themeserver has failed.
  1658  * This gets called if the consolidated icon-creation process on themeserver has failed.
  1698  * This function initiates a single IPC to themeserver in which it sends out icon-parameters
  1659  * This function initiates a single IPC to themeserver in which it sends out icon-parameters
  1699  * for each of the frame-items and gets back a list of HbSharedIconInfo corresponding to 
  1660  * for each of the frame-items and gets back a list of HbSharedIconInfo corresponding to
  1700  * individual pieces.
  1661  * individual pieces.
  1701  * 
  1662  *
  1702  */
  1663  */
  1703 void HbIconLoader::getMultiIconImplFromServer(QStringList &multiPartIconList,                                                             
  1664 void HbIconLoader::getMultiIconImplFromServer(QStringList &multiPartIconList,
  1704                                 QVector<QSizeF> &sizeList,
  1665         QVector<QSizeF> &sizeList,
  1705                                 Qt::AspectRatioMode aspectRatioMode,
  1666         Qt::AspectRatioMode aspectRatioMode,
  1706                                 QIcon::Mode mode,
  1667         QIcon::Mode mode,
  1707                                 bool mirrored,
  1668         bool mirrored,
  1708                                 bool mirroredIconFound,
  1669         bool mirroredIconFound,
  1709                                 HbIconLoader::IconLoaderOptions options,
  1670         HbIconLoader::IconLoaderOptions options,
  1710                                 const QColor &color,
  1671         const QColor &color,
  1711                                 HbIconLoader::IconDataType type,
  1672         HbIconLoader::IconDataType type,
  1712                                 HbIconLoader::Purpose,
  1673         HbIconLoader::Purpose,
  1713                                 QVector<HbIconImpl *> & iconImplList,
  1674         QVector<HbIconImpl *> & iconImplList,
  1714                                 HbRenderingMode currRenderMode)
  1675         HbRenderingMode currRenderMode)
  1715 {
  1676 {
  1716     Q_UNUSED(type);
  1677     Q_UNUSED(type);
  1717     QVector<int> posList;
  1678     QVector<int> posList;
  1718 #ifdef HB_ICONIMPL_CACHE
  1679 #ifdef HB_ICONIMPL_CACHE
  1719     // search the client cache first before asking the server
  1680     // search the client cache first before asking the server
  1720     for(int i = 0; i < multiPartIconList.count(); i++) {
  1681     for (int i = 0; i < multiPartIconList.count(); i++) {
  1721         QByteArray cacheKey = d->createCacheKeyFrom( multiPartIconList[i], sizeList[i], aspectRatioMode,
  1682         QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconList[i],
  1722                         mode, mirrored, color, currRenderMode );
  1683                               sizeList[i],
  1723         //look up in the local iconImplCache. 
  1684                               aspectRatioMode,
       
  1685                               mode,
       
  1686                               mirrored,
       
  1687                               color,
       
  1688                               currRenderMode);
       
  1689         //look up in the local iconImplCache.
  1724         //If found return the ptr directly
  1690         //If found return the ptr directly
  1725         HbIconImpl * ptr = 0;
  1691         HbIconImpl *ptr = 0;
  1726         if (iconImplCache.contains(cacheKey)) {
  1692         if (iconImplCache.contains(cacheKey)) {
  1727             ptr = iconImplCache.value(cacheKey);
  1693             ptr = iconImplCache.value(cacheKey);
  1728             // if a specific frame-item is found in local impl-cache, 
  1694             // if a specific frame-item is found in local impl-cache,
  1729             // increment the ref count and remove the entry from the list that needs to be sent to server.
  1695             // increment the ref count and remove the entry from the list that needs to be sent to server.
  1730             ptr->incrementRefCount();
  1696             ptr->incrementRefCount();
  1731 #ifdef HB_ICON_CACHE_DEBUG
  1697 #ifdef HB_ICON_CACHE_DEBUG
  1732             qDebug() << "HbIconLoader::getMultiIconImplFromServer()" << "Cache hit in iconImplCache ";
  1698             qDebug() << "HbIconLoader::getMultiIconImplFromServer()" << "Cache hit in iconImplCache ";
  1733             qDebug() << "HbIconLoader::getMultiIconImplFromServer : Client RefCount now = " << ptr->refCount();
  1699             qDebug() << "HbIconLoader::getMultiIconImplFromServer : Client RefCount now = " << ptr->refCount();
  1751     int count = multiPartIconList.count();
  1717     int count = multiPartIconList.count();
  1752     if (count > 0) {
  1718     if (count > 0) {
  1753         HbSharedIconInfoList iconInfoList = HbThemeClient::global()->getMultiIconInfo(multiPartIconList, sizeList,
  1719         HbSharedIconInfoList iconInfoList = HbThemeClient::global()->getMultiIconInfo(multiPartIconList, sizeList,
  1754                                             aspectRatioMode, mode, mirrored, options, color, currRenderMode);
  1720                                             aspectRatioMode, mode, mirrored, options, color, currRenderMode);
  1755 
  1721 
  1756         HbIconImpl* impl = 0;
  1722         HbIconImpl *impl = 0;
  1757 
  1723 
  1758         HbIconLoadingParams params;
  1724         HbIconLoadingParams params;
  1759 
  1725 
  1760         params.aspectRatioMode = aspectRatioMode;
  1726         params.aspectRatioMode = aspectRatioMode;
  1761         params.mode = mode;
  1727         params.mode = mode;
  1769                 params.size = sizeList.at(i);
  1735                 params.size = sizeList.at(i);
  1770 
  1736 
  1771                 impl = HbIconImplCreator::createIconImpl(iconInfoList.icon[i], params);
  1737                 impl = HbIconImplCreator::createIconImpl(iconInfoList.icon[i], params);
  1772 
  1738 
  1773 #ifdef HB_ICONIMPL_CACHE
  1739 #ifdef HB_ICONIMPL_CACHE
  1774                 QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconList[i], sizeList.at(i) , aspectRatioMode,
  1740                 QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconList[i],
  1775                                       mode, mirrored, color, currRenderMode);
  1741                                       sizeList.at(i) ,
       
  1742                                       aspectRatioMode,
       
  1743                                       mode,
       
  1744                                       mirrored,
       
  1745                                       color,
       
  1746                                       currRenderMode);
  1776                 iconImplCache.insert(cacheKey, impl);
  1747                 iconImplCache.insert(cacheKey, impl);
  1777 #ifdef HB_ICON_CACHE_DEBUG
  1748 #ifdef HB_ICON_CACHE_DEBUG
  1778                 qDebug() << "HbIconLoader::getMultiIconImplFromServer(): " << params.iconName << " inserted into impl-cache, ref-count now = " << impl->refCount();
  1749                 qDebug() << "HbIconLoader::getMultiIconImplFromServer(): " << params.iconName << " inserted into impl-cache, ref-count now = " << impl->refCount();
  1779 #endif
  1750 #endif
  1780 
  1751 
  1812  */
  1783  */
  1813 void HbIconLoader::unLoadMultiIcon(QVector<HbIconImpl *> &multiPieceImpls)
  1784 void HbIconLoader::unLoadMultiIcon(QVector<HbIconImpl *> &multiPieceImpls)
  1814 {
  1785 {
  1815     QStringList iconNameList;
  1786     QStringList iconNameList;
  1816     QVector<QSizeF> sizeList;
  1787     QVector<QSizeF> sizeList;
  1817      
  1788 
  1818     // Decrement the ref count. If its zero, remove it from the client cache (if defined) and 
  1789     // Decrement the ref count. If its zero, remove it from the client cache (if defined) and
  1819     // then send to server for unload.
  1790     // then send to server for unload.
  1820     foreach(HbIconImpl* impl, multiPieceImpls) {
  1791     foreach(HbIconImpl * impl, multiPieceImpls) {
  1821         impl->decrementRefCount();
  1792         impl->decrementRefCount();
  1822         if (impl->refCount() == 0 && impl->isCreatedOnServer()) {        
  1793         if (impl->refCount() == 0 && impl->isCreatedOnServer()) {
  1823 #ifdef HB_ICONIMPL_CACHE        
  1794 #ifdef HB_ICONIMPL_CACHE
  1824             int rem = iconImplCache.remove(iconImplCache.key(impl));
  1795             int rem = iconImplCache.remove(iconImplCache.key(impl));
  1825             if (rem > 0) {
  1796             if (rem > 0) {
  1826 #ifdef HB_ICON_TRACES
  1797 #ifdef HB_ICON_TRACES
  1827             qDebug()<<"HbIconLoader::unLoadMultiIcon :Removed from HbIconImpl Cache "<<rem<< impl->iconFileName()<< impl->keySize().height()<<"X"<<impl->keySize().width() ;
  1798                 qDebug() << "HbIconLoader::unLoadMultiIcon :Removed from HbIconImpl Cache " << rem << impl->iconFileName() << impl->keySize().height() << "X" << impl->keySize().width() ;
  1828 #endif 
  1799 #endif
  1829             }
  1800             }
  1830 #endif      
  1801 #endif
  1831             // List of icons to be unloaded.
  1802             // List of icons to be unloaded.
  1832             iconNameList<<impl->iconFileName();
  1803             iconNameList << impl->iconFileName();
  1833             sizeList<<impl->keySize();
  1804             sizeList << impl->keySize();
  1834         }
  1805         }
  1835     }
  1806     }
       
  1807 
       
  1808     if (iconNameList.count() > 0) {
       
  1809         HbThemeClient::global()->unLoadMultiIcon(iconNameList,
       
  1810                 sizeList,
       
  1811                 multiPieceImpls[0]->iconAspectRatioMode(),
       
  1812                 multiPieceImpls[0]->iconMode(),
       
  1813                 multiPieceImpls[0]->isMirrored(),
       
  1814                 multiPieceImpls[0]->color(),
       
  1815                 multiPieceImpls[0]->iconRenderingMode()
       
  1816                                                 );
       
  1817     }
       
  1818 }
       
  1819 
       
  1820 bool HbIconLoader::isInPrivateDirectory(const QString &filename)
       
  1821 {
       
  1822     Q_UNUSED(filename);
       
  1823     bool isPrivate = false;
  1836     
  1824     
  1837     if(iconNameList.count() > 0) {
  1825 #ifdef Q_OS_SYMBIAN
  1838         HbThemeClient::global()->unLoadMultiIcon(iconNameList, 
  1826     if (filename.length() > 11) {
  1839                                             sizeList,
  1827         // Private dir starts with e.g. "z:/private/"
  1840                                             multiPieceImpls[0]->iconAspectRatioMode(),
  1828         if (filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\') &&
  1841                                             multiPieceImpls[0]->iconMode(),
  1829            (filename[10] == '/' || filename[10] == '\\') && filename.mid(3, 7).compare("private"), Qt::CaseInsensitive) {
  1842                                             multiPieceImpls[0]->isMirrored(),
  1830             isPrivate = true;
  1843                                             multiPieceImpls[0]->color(),
  1831         }
  1844                                             multiPieceImpls[0]->iconRenderingMode()
  1832     }
  1845                                             );
  1833 #endif
  1846     }
  1834 
       
  1835     return isPrivate;
  1847 }
  1836 }
  1848 
  1837 
  1849 // End of File
  1838 // End of File