src/hbcore/image/hbiconloader.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 5 627c4a0fd0e7
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    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"
    27 
    28 
    28 #include <QDir>
    29 #include <QDir>
    29 #include <QCoreApplication>
    30 #include <QCoreApplication>
    30 #include <QDebug>
    31 #include <QDebug>
    31 #include <QPicture>
    32 #include <QPicture>
   110 
   111 
   111     static QString removeIconNameSuffix(const QString &iconName);
   112     static QString removeIconNameSuffix(const QString &iconName);
   112 
   113 
   113     /* This method is supposed to work the same way 
   114     /* This method is supposed to work the same way 
   114        as the FindIconHelper in the Icon Theme Spec: */
   115        as the FindIconHelper in the Icon Theme Spec: */
   115     static QString findIconHelper(const QString &iconName,
   116     static QString findSharedResourceHelper(const QString &resourceName,
   116                                   bool mirrored,
   117                                   bool mirrored,
   117                                   bool& mirroredIconFound,
   118                                   bool& mirroredIconFound,
       
   119                                   Hb::ResourceType itemType = Hb::IconResource,
   118                                   bool useThemeIndex = true);
   120                                   bool useThemeIndex = true);
   119 
   121 
   120     static QString findEffectHelper(const QString &effectName);
   122     static QString findEffectHelper(const QString &effectName);
   121 
   123 
   122     bool isAutomaticallyMirrored(const QString &iconName);
   124     bool isAutomaticallyMirrored(const QString &iconName);
   128     QByteArray createCacheKeyFrom( const QString &iconName, 
   130     QByteArray createCacheKeyFrom( const QString &iconName, 
   129                                    const QSizeF &size,
   131                                    const QSizeF &size,
   130                                    Qt::AspectRatioMode aspectRatioMode, 
   132                                    Qt::AspectRatioMode aspectRatioMode, 
   131                                    QIcon::Mode mode, 
   133                                    QIcon::Mode mode, 
   132                                    bool mirrored, 
   134                                    bool mirrored, 
   133                                    const QColor &color);
   135                                    const QColor &color,
   134 #endif
   136                                    HbRenderingMode renderMode);
   135 
   137 #endif
   136 private:
       
   137     void createMirroredList();
       
   138 
   138 
   139 public: // data
   139 public: // data
   140     QString storedTheme;
   140     QString storedTheme;
   141 
   141 
   142     /*
       
   143     * List of icons that should be mirrored automatically in a mirrored layout.
       
   144     * This is initially read from a config file "mirrored.txt".
       
   145     */
       
   146     QStringList mirroredList;
       
   147     bool mirroredListCreated;
       
   148         
       
   149     int sourceResolution;
   142     int sourceResolution;
   150     int resolution;
   143     int resolution;
   151     qreal zoom;
   144     qreal zoom;
   152 
   145 
   153     // Frame-by-frame animation support -------------------------------------->
   146     // Frame-by-frame animation support -------------------------------------->
   171     int layoutMirrored;
   164     int layoutMirrored;
   172 };
   165 };
   173 
   166 
   174 HbIconLoaderPrivate::HbIconLoaderPrivate() :
   167 HbIconLoaderPrivate::HbIconLoaderPrivate() :
   175         storedTheme(HbTheme::instance()->name()),
   168         storedTheme(HbTheme::instance()->name()),
   176         mirroredListCreated(false),
       
   177         sourceResolution(144), // This is about the resolution of a Nokia N95 8GB
   169         sourceResolution(144), // This is about the resolution of a Nokia N95 8GB
   178         resolution(144),
   170         resolution(144),
   179         zoom(1.0),
   171         zoom(1.0),
   180         animationManager(HbIconAnimationManager::global()),
   172         animationManager(HbIconAnimationManager::global()),
   181         animationLoading(false),
   173         animationLoading(false),
   231         return "BLOB";
   223         return "BLOB";
   232     }
   224     }
   233     return suffix;
   225     return suffix;
   234 }
   226 }
   235 
   227 
   236 QString HbIconLoaderPrivate::findIconHelper(const QString &iconName, bool mirrored, bool& mirroredIconFound, bool useThemeIndex)
   228 QString HbIconLoaderPrivate::findSharedResourceHelper(const QString &resourceName, bool mirrored, bool& mirroredIconFound, Hb::ResourceType itemType, bool useThemeIndex)
   237 {
   229 {
   238     Q_UNUSED(useThemeIndex)
   230     Q_UNUSED(useThemeIndex)
       
   231     Q_UNUSED(itemType)
   239 
   232 
   240     mirroredIconFound = false;
   233     mirroredIconFound = false;
   241     QString iconPath;
   234     QString iconPath;
   242 
   235 
   243     if (QDir::isRelativePath(iconName)) {
   236     if (QDir::isRelativePath(resourceName)) {
   244         bool themeIndexUsed = false;
       
   245 
   237 
   246 #ifdef Q_OS_SYMBIAN
   238 #ifdef Q_OS_SYMBIAN
   247         // Try to get themed icon information from theme index
   239         // Try to get themed icon information from theme index
   248         ThemeIndexTables &themeIndex = hbInstance->theme()->d_ptr->themeIndex;
   240         HbThemeIndexResource resource(resourceName);
   249         // Check if there is a valid theme index
   241         if (resource.isValid()) {
   250         if (useThemeIndex && themeIndex.isValid()) {
   242             if (mirrored) {
   251             themeIndexUsed = true;
   243                 return resource.fullMirroredFileName();
   252         
   244             } else {
   253             int tableIndex;
   245                 return resource.fullFileName();
   254             const HbThemeIndexItem *item = themeIndex.getItem(iconName, tableIndex);
       
   255         
       
   256             if (item) {
       
   257                 const char *baseAddress = reinterpret_cast<const char *>(themeIndex.tables[tableIndex]);
       
   258 
       
   259                 QString fullfilename;
       
   260             
       
   261                 // Add drive letter of the used theme if the path does not point to a QT resource
       
   262                 if (*(baseAddress + item->folderOffset) != ':') {
       
   263                     fullfilename.append(themeIndex.drives[tableIndex]);
       
   264                     fullfilename.append(':');
       
   265                 }
       
   266                 // Add folder
       
   267                 fullfilename.append(baseAddress + item->folderOffset);
       
   268 
       
   269                 if (mirrored) {
       
   270                     if (item->mirroredExtOffset >= 0) {
       
   271                         mirroredIconFound = true;
       
   272                                         
       
   273                         fullfilename.append("mirrored\\");
       
   274                         fullfilename.append(iconName);
       
   275                         fullfilename.append(baseAddress + item->mirroredExtOffset);
       
   276 
       
   277                         #ifdef THEME_INDEX_TRACES
       
   278                         qDebug() << "ThemeIndex: Resolved icon filename:" << fullfilename.toUtf8();
       
   279                         #endif
       
   280 
       
   281                         return fullfilename;
       
   282                     } 
       
   283                 }
       
   284             
       
   285                 fullfilename.append(iconName);
       
   286                 fullfilename.append(baseAddress + item->extOffset);
       
   287 
       
   288                 #ifdef THEME_INDEX_TRACES
       
   289                 qDebug() << "ThemeIndex: Resolved icon filename:" << fullfilename.toUtf8();
       
   290                 #endif
       
   291 
       
   292                 return fullfilename;
       
   293             }
   246             }
   294         }
   247         }
   295 #endif // Q_OS_SYMBIAN
   248 #endif // Q_OS_SYMBIAN
   296 
   249 
   297         // If there was no theme index, search the icon in theme icon dirs (slow)
   250         // If there was no theme index, search the icon in theme icon dirs (slow)
   298         if (!themeIndexUsed) {
       
   299         foreach (const QString &dir, HbThemePrivate::instance()->iconDirectories()) {
   251         foreach (const QString &dir, HbThemePrivate::instance()->iconDirectories()) {
   300                 if (mirrored) {
   252             if (mirrored) {
   301                     // If icon is mirrored, try to find the icon in a separate "mirrored" folder used for mirrored icons
   253                 // If icon is mirrored, try to find the icon in a separate "mirrored" folder used for mirrored icons
   302                     iconPath =  HbStandardDirs::findResource( dir + "mirrored" + '/' + iconName, Hb::IconResource );
   254                 iconPath =  HbStandardDirs::findResource( dir + "mirrored" + '/' + resourceName, Hb::IconResource );
   303                     if( !iconPath.isEmpty() ) {
   255                 if( !iconPath.isEmpty() ) {
   304                         mirroredIconFound = true;
   256                     mirroredIconFound = true;
   305                         break;
       
   306                     }
       
   307                 }
       
   308 
       
   309             iconPath =  HbStandardDirs::findResource( dir + iconName, Hb::IconResource );
       
   310 
       
   311                 // If the file was found in this dir, return the filename.
       
   312             if ( !iconPath.isEmpty() ) {
       
   313                     break;
   257                     break;
   314                 }
   258                 }
   315             }
   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             }
   316         }
   267         }
   317     } else {
   268     } else {
   318         // Absolute path. Do not scan through different theme directories.
   269         // Absolute path. Do not scan through different theme directories.
   319         QString iconNameCopy(iconName);
   270         QString iconNameCopy(resourceName);
   320         if (mirrored) {
   271         if (mirrored) {
   321             // If icon is mirrored, try to find the icon in a separate "mirrored" folder used for mirrored icons
   272             // If icon is mirrored, try to find the icon in a separate "mirrored" folder used for mirrored icons
   322 
   273 
   323             // Find the directory part from the full filename
   274             // Find the directory part from the full filename
   324             int index1 = iconName.lastIndexOf('/');
   275             int index1 = resourceName.lastIndexOf('/');
   325             int index2 = iconName.lastIndexOf('\\');
   276             int index2 = resourceName.lastIndexOf('\\');
   326     
   277 
   327             int index = index1 > index2 ? index1 : index2;
   278             int index = index1 > index2 ? index1 : index2;
   328 
   279 
   329             QString iconNameCopy(iconName);
   280             QString iconNameCopy(resourceName);
   330 
   281 
   331             if (index > 0) {
   282             if (index > 0) {
   332                 iconNameCopy.insert(index+1, QString("mirrored\\"));
   283                 iconNameCopy.insert(index+1, QString("mirrored/"));
   333             }
   284             }
   334             iconPath = HbStandardDirs::findResource(iconNameCopy, Hb::IconResource);
   285             iconPath = HbStandardDirs::findResource(iconNameCopy, Hb::IconResource);
   335 
   286 
   336             if( !iconPath.isEmpty() ) {
   287             if( !iconPath.isEmpty() ) {
   337                 mirroredIconFound = true;
   288                 mirroredIconFound = true;
   338                 return iconPath;
   289                 return iconPath;
   339             }
   290             }
   340         }
   291         }
   341     
   292 
   342         iconPath = HbStandardDirs::findResource(iconName, Hb::IconResource);
   293         iconPath = HbStandardDirs::findResource(resourceName, Hb::IconResource);
   343     }
   294     }
   344 
   295 
   345     return iconPath;
   296     return iconPath;
   346 /*
   297 /*
   347 From Freedesktop.org:
   298 From Freedesktop.org:
   478 */
   429 */
   479 }
   430 }
   480 
   431 
   481 bool HbIconLoaderPrivate::isAutomaticallyMirrored(const QString &iconName)
   432 bool HbIconLoaderPrivate::isAutomaticallyMirrored(const QString &iconName)
   482 {
   433 {
   483     if (!mirroredListCreated) {
   434     Q_UNUSED(iconName);
   484         // Read the list of the mirrored icons from a file.
   435     // only place to get mirroring information is from themeindex
   485         createMirroredList();
   436 #ifdef Q_OS_SYMBIAN
   486         mirroredListCreated = true;
   437         // Try to get themed icon information from theme index
   487     }
   438         HbThemeIndexResource resource(iconName);
   488 
   439         if (resource.isValid()) {
   489     // Check if the given icon name is found in the list of mirrored icons
   440             return resource.isAutomaticallyMirrored();
   490     QList<QString>::const_iterator j = qBinaryFind(mirroredList, iconName);
   441         }
   491     return (j != mirroredList.constEnd());
   442 #endif
       
   443 
       
   444     return false;
   492 }
   445 }
   493 
   446 
   494 bool HbIconLoaderPrivate::isLayoutMirrored()
   447 bool HbIconLoaderPrivate::isLayoutMirrored()
   495 {
   448 {
   496     if (layoutMirrored == Unknown) {
   449     if (layoutMirrored == Unknown) {
   510 void HbIconLoaderPrivate::setLayoutMirrored(bool mirrored)
   463 void HbIconLoaderPrivate::setLayoutMirrored(bool mirrored)
   511 {
   464 {
   512     layoutMirrored = mirrored ? Mirrored : NotMirrored;
   465     layoutMirrored = mirrored ? Mirrored : NotMirrored;
   513 }
   466 }
   514 
   467 
   515 void HbIconLoaderPrivate::createMirroredList()
       
   516 {
       
   517     /* Todo: mirrored.txt will be refactored
       
   518     // Find mirrored.txt file
       
   519     QString filename = HbStandardDirs::findResource("themes/themes/mirrored.txt", Hb::ThemeResource);
       
   520     if (filename.endsWith("mirrored.txt")) {
       
   521         // Try to read file
       
   522         QFile file(filename);
       
   523         if (file.open(QIODevice::ReadOnly)) {
       
   524             QString line;
       
   525 
       
   526             while(!file.atEnd()) {        
       
   527                 QByteArray dirtyLine = file.readLine();
       
   528                 line = QString(dirtyLine).trimmed();
       
   529                 // Skip empty lines and comment lines
       
   530                 if (line.isEmpty() || line.at(0) == '#') {
       
   531                     continue; 
       
   532                 }
       
   533                 mirroredList.append(line);
       
   534             }
       
   535 
       
   536         // Sort the list
       
   537         qSort(mirroredList.begin(), mirroredList.end());
       
   538         }
       
   539     }
       
   540     */
       
   541     // button
       
   542     mirroredList << "qtg_fr_btn_normal" << "qtg_fr_btn_pressed" << "qtg_fr_btn_latched" << "qtg_fr_btn_highlight";
       
   543     mirroredList << "qtg_fr_btn_latched_highlight" << "qtg_fr_btn_disabled";
       
   544 
       
   545     // form
       
   546     mirroredList << "qtg_fr_form_value";
       
   547 
       
   548     // grid
       
   549     mirroredList << "qtg_fr_grid_normal" << "qtg_fr_grid_highlight" << "qtg_fr_grid_pressed";
       
   550 
       
   551     // list
       
   552     mirroredList << "qtg_fr_list_normal" << "qtg_fr_list_highlight" << "qtg_fr_list_pressed" << "qtg_fr_list_parent_normal";
       
   553     mirroredList << "qtg_fr_convlist_sent_normal" << "qtg_fr_convlist_sent_highlight" << "qtg_fr_convlist_sent_pressed";
       
   554     mirroredList << "qtg_fr_convlist_received_normal" << "qtg_fr_convlist_received_highlight" << "qtg_fr_convlist_received_pressed";
       
   555 
       
   556     // popup
       
   557     mirroredList << "qtg_fr_popup_list_normal" << "qtg_fr_popup_list_pressed" << "qtg_fr_popup_list_highlight" << "qtg_fr_popup_list_parent_normal";
       
   558     mirroredList << "qtg_fr_popup_grid_normal" << "qtg_fr_popup_grid_pressed" << "qtg_fr_popup_grid_highlight" << "qtg_graf_dimming_image";
       
   559     mirroredList << "qtg_fr_popup" << "qtg_fr_popup_secondary" << "qtg_fr_popup_preview";
       
   560 
       
   561     // progressive slider
       
   562     mirroredList << "qtg_fr_progslider_frame" << "qtg_fr_progslider_pressed" << "qtg_fr_progslider_loaded";
       
   563     mirroredList << "qtg_fr_progslider_played" << "qtg_graf_progslider_handle_normal" << "qtg_graf_progslider_handle_pressed";
       
   564 
       
   565     // slider
       
   566     mirroredList << "qtg_fr_slider_v_frame" << "qtg_fr_slider_v_filled" << "qtg_graf_slider_v_handle_normal" << "qtg_graf_slider_v_tick_minor";
       
   567     mirroredList << "qtg_graf_slider_v_tick_major" << "qtg_fr_slider_h_frame" << "qtg_fr_slider_h_filled" << "qtg_graf_slider_h_handle_normal";
       
   568     mirroredList << "qtg_graf_slider_h_tick_minor" << "qtg_graf_slider_h_tick_major";
       
   569 
       
   570     // tabs
       
   571     mirroredList << "qtg_fr_tab_active" << "qtg_fr_tab_passive_normal" << "qtg_fr_tab_passive_pressed" << "qtg_fr_tab_mask";
       
   572 
       
   573     // toolbar
       
   574     mirroredList << "qtg_fr_tb_h_normal" << "qtg_fr_tb_h_pressed" << "qtg_fr_tb_h_latched" << "qtg_fr_tb_h_disabled";
       
   575     mirroredList << "qtg_fr_tb_v_normal" << "qtg_fr_tb_v_pressed" << "qtg_fr_tb_v_latched" << "qtg_fr_tb_v_disabled";
       
   576 
       
   577     // toolbar extension
       
   578     mirroredList << "qtg_fr_tb_ext";
       
   579 
       
   580     // scrollbar
       
   581     mirroredList << "qtg_fr_scroll_v_handle" << "qtg_fr_scroll_v_frame" << "qtg_fr_scroll_h_handle" << "qtg_fr_scroll_h_frame";
       
   582 
       
   583     // status pane
       
   584     mirroredList << "qtg_fr_status_normal" << "qtg_fr_status_pressed" << "qtg_fr_status_latched" << "qtg_indi_status_options";
       
   585 
       
   586     qSort(mirroredList.begin(), mirroredList.end());
       
   587 }
       
   588 
       
   589 #ifdef HB_ICONIMPL_CACHE
   468 #ifdef HB_ICONIMPL_CACHE
   590 QByteArray HbIconLoaderPrivate::createCacheKeyFrom(const QString &iconName, const QSizeF &size,
   469 QByteArray HbIconLoaderPrivate::createCacheKeyFrom(const QString &iconName, const QSizeF &size,
   591     Qt::AspectRatioMode aspectRatioMode, QIcon::Mode mode, bool mirrored, const QColor &color)
   470     Qt::AspectRatioMode aspectRatioMode, QIcon::Mode mode, bool mirrored, const QColor &color,
   592 {
   471     HbRenderingMode renderMode)
   593     static const int paramArraySize = 7;
   472 {
       
   473     static const int paramArraySize = 8;
   594 
   474 
   595     // This uses QByteArray to improve performance compared to QString.
   475     // This uses QByteArray to improve performance compared to QString.
   596     // It allows appending stuff with less heap allocations and conversions compared to using QString.
   476     // It allows appending stuff with less heap allocations and conversions compared to using QString.
   597     QByteArray cacheKey;
   477     QByteArray cacheKey;
   598     int nameSize = iconName.size();
   478     int nameSize = iconName.size();
   614     } else {
   494     } else {
   615         temp[5] = 0; // flag, color is invalid
   495         temp[5] = 0; // flag, color is invalid
   616         temp[6] = 0;
   496         temp[6] = 0;
   617     }
   497     }
   618 
   498 
       
   499     // Append render mode when creating cache key
       
   500     temp[7] = renderMode;
   619     cacheKey.append((char*)&(temp[0]), sizeof(int)*paramArraySize);
   501     cacheKey.append((char*)&(temp[0]), sizeof(int)*paramArraySize);
   620 
   502 
   621     const QChar *iconNamePtr = iconName.constData();
   503     const QChar *iconNamePtr = iconName.constData();
   622     cacheKey.append((char*)iconNamePtr, nameSize * sizeof(QChar));
   504     cacheKey.append((char*)iconNamePtr, nameSize * sizeof(QChar));
   623 
   505 
   633     : QObject( parent )
   515     : QObject( parent )
   634 {
   516 {
   635     setObjectName( appName );
   517     setObjectName( appName );
   636     d = new HbIconLoaderPrivate();
   518     d = new HbIconLoaderPrivate();
   637 
   519 
       
   520     // Set default rendering mode to EHWRendering    
       
   521     renderMode = EHWRendering;
       
   522 
   638     // Delete the icon loader when the application is destroyed.
   523     // Delete the icon loader when the application is destroyed.
   639     connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(destroy()));
   524     connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(destroy()));
   640 
   525 
   641     connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChangeStarted()),
   526     connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChangeStarted()),
   642         this, SLOT(updateLayoutDirection()));
   527         this, SLOT(updateLayoutDirection()));
       
   528 
       
   529 #ifdef HB_TOOL_INTERFACE
       
   530     // This enables partial theme updates.
       
   531     connect(&hbInstance->theme()->d_ptr->iconTheme, SIGNAL(iconsUpdated(QStringList)), this, SLOT(themeChange(QStringList)));
       
   532 #endif
   643 }
   533 }
   644 
   534 
   645 HbIconLoader::~HbIconLoader()
   535 HbIconLoader::~HbIconLoader()
   646 {
   536 {
   647     delete d;
   537     delete d;
   689     // Step 2: There was no animation definition, try to get default size from theme index if it is a themed icon
   579     // Step 2: There was no animation definition, try to get default size from theme index if it is a themed icon
   690     
   580     
   691     // TODO: change this to simpler function call in Symbian OS env
   581     // TODO: change this to simpler function call in Symbian OS env
   692     if (QDir::isRelativePath(iconName)) {
   582     if (QDir::isRelativePath(iconName)) {
   693 #ifdef Q_OS_SYMBIAN
   583 #ifdef Q_OS_SYMBIAN
   694 
   584         // Try to get themed icon information from theme index
   695         // Try to get themed icon default size from theme index
   585         HbThemeIndexResource resource(iconName);
   696         ThemeIndexTables &themeIndex = hbInstance->theme()->d_ptr->themeIndex;
   586         if (resource.isValid()) {
   697         // Check if there is a valid theme index
   587             // Try to get themed icon default size from theme index
   698         if (themeIndex.isValid()) {
   588             if (params.mirrored && resource.mirroredItemSize().isValid()) {
   699             int tableIndex;
   589                 size = resource.mirroredItemSize();
   700             const HbThemeIndexItem *item = themeIndex.getItem(iconName, tableIndex);
   590             } else {
   701             if (item) {
   591                 size = resource.defaultItemSize();
   702                 if (params.mirrored && item->mirroredDefaultSize.isValid()) {
       
   703                     size = item->mirroredDefaultSize;
       
   704                 } else {
       
   705                     size = item->defaultSize;
       
   706                 }
       
   707             }
   592             }
   708             // Returns invalid size if there is a valid theme index, but the item was not found there.
   593             // Returns invalid size if there is a valid theme index, but the item was not found there.
   709             return size;
   594             return size;
   710         } else {
   595         } else {
   711     		// Step 3: Theme index was not used, try to get icon's default size from theme server's default size cache.    		
   596             // Step 3: Theme index was not used, try to get icon's default size from theme server's default size cache.
   712             params.iconFileName = resolveIconFileName(params);		
   597             params.iconFileName = resolveIconFileName(params);
   713 		}
   598         }
   714 
       
   715 #else
   599 #else
   716         params.iconFileName = resolveIconFileName(params);
   600         params.iconFileName = resolveIconFileName(params);
   717 #endif		
   601 #endif
   718     } else { // Absolute path, use it directly without resolving anything.
   602     } else { // Absolute path, use it directly without resolving anything.
   719         params.iconFileName = iconName;
   603         params.iconFileName = iconName;
   720     }
   604     }
   721 
   605 
   722     // If icon filename could not be resolved, return
   606     // If icon filename could not be resolved, return
   777     bool found = true;
   661     bool found = true;
   778 
   662 
   779     foreach (const QString &suffix, suffixList) {
   663     foreach (const QString &suffix, suffixList) {
   780         bool dummy = false;
   664         bool dummy = false;
   781 
   665 
   782         QString path = HbIconLoaderPrivate::findIconHelper(name + suffix, false, dummy);
   666         QString path = HbIconLoaderPrivate::findSharedResourceHelper(name + suffix, false, dummy);
   783         if (path.isEmpty()) {
   667         if (path.isEmpty()) {
   784             found = false;
   668             found = false;
   785             break;
   669             break;
   786         }
   670         }
   787     }
   671     }
   821 }
   705 }
   822 
   706 
   823 void HbIconLoader::applyResolutionCorrection(QSizeF &size)
   707 void HbIconLoader::applyResolutionCorrection(QSizeF &size)
   824 {
   708 {
   825     size = size * (qreal)(d->resolution) / (qreal)(d->sourceResolution) * d->zoom; 
   709     size = size * (qreal)(d->resolution) / (qreal)(d->sourceResolution) * d->zoom; 
       
   710 }
       
   711 
       
   712 void HbIconLoader::themeChange(const QStringList &updatedFiles)
       
   713 {
       
   714     foreach (HbFrameDrawerPrivate *frameDrawer, this->frameDrawerInstanceList) frameDrawer->themeChange(updatedFiles);
   826 }
   715 }
   827 
   716 
   828 void HbIconLoader::destroy()
   717 void HbIconLoader::destroy()
   829 {
   718 {
   830     if (theLoader) {
   719     if (theLoader) {
   895 }
   784 }
   896 
   785 
   897 /*!
   786 /*!
   898   \internal
   787   \internal
   899 
   788 
   900   This is a wrapper for findIconHelper() (when the resource type is
   789   This is a wrapper for findSharedResourceHelper(). It is used for getting 
   901   Hb::EffectIcon). It is used for getting AXML and other content from the
   790   resources from the themeserver.
   902   themeserver.
       
   903 
       
   904   If \a resType is Hb::EffectResource then the file is searched among the
       
   905   effects in the theme.
       
   906 
   791 
   907   The return value is either same as \a name, when the file is not found in the
   792   The return value is either same as \a name, when the file is not found in the
   908   theme, or the full path and name to the file found in the theme. In certain
   793   theme, or the full path and name to the file found in the theme. In certain
   909   situations the return value can also be an empty string, therefore it should
   794   situations the return value can also be an empty string, therefore it should
   910   not be trusted and used without any further examination.
   795   not be trusted and used without any further examination.
   911  */
   796  */
   912 QString HbIconLoader::findSharedResource(const QString &name, Hb::ResourceType resType)
   797 QString HbIconLoader::findSharedResource(const QString &name, Hb::ResourceType resType)
   913 {
   798 {
   914     bool temp;
   799     bool temp;
   915     if (resType == Hb::EffectResource) {
   800     return HbIconLoaderPrivate::findSharedResourceHelper(name, false, temp, resType);
   916         QMap<int, QString> effectHier = HbThemeUtils::constructHierarchyListWithPathInfo(
       
   917             name, HbTheme::instance()->name(), Hb::EffectResource);
       
   918         HbStandardDirs::findResourceList(effectHier, Hb::EffectResource);
       
   919 
       
   920         // Just take the first value from the map. (note that maps are sorted by the key)
       
   921         foreach (const QString &file, effectHier) {
       
   922             return file;
       
   923         }
       
   924 
       
   925         // The map was empty, return empty string.
       
   926         return QString();
       
   927     } else {
       
   928         // Assume icon case (png, svg, axml, etc.)
       
   929 
       
   930         // TODO: theme index does not support currently axmls, so setting 'useThemeIndex' parameter to false
       
   931         return HbIconLoaderPrivate::findIconHelper(name, false, temp, false);
       
   932     }
       
   933 }
   801 }
   934 
   802 
   935 /*!
   803 /*!
   936   This function is used to register the IconEngine instance to IconLoader
   804   This function is used to register the IconEngine instance to IconLoader
   937  */
   805  */
   984     params.iconFileName = resolveIconFileName(params);
   852     params.iconFileName = resolveIconFileName(params);
   985     QString format = formatFromPath(params.iconFileName);
   853     QString format = formatFromPath(params.iconFileName);
   986 
   854 
   987     // Try to get the default size from server if the icon is not such that is loaded in client side.
   855     // Try to get the default size from server if the icon is not such that is loaded in client side.
   988     if (format != "MNG"
   856     if (format != "MNG"
   989             && format != "GIF"
   857         && format != "GIF"
   990             && !params.iconName.startsWith(':')) {
   858         && !params.iconFileName.startsWith(':'))
       
   859     {
   991         QSizeF defSize = HbThemeClient::global()->getSharedIconDefaultSize(params.iconFileName);
   860         QSizeF defSize = HbThemeClient::global()->getSharedIconDefaultSize(params.iconFileName);
   992         if (defSize.isValid()) {
   861         if (defSize.isValid()) {
   993             return defSize;
   862             return defSize;
   994         }
   863         }
   995     }
   864     }
  1097 }
   966 }
  1098 
   967 
  1099 QString HbIconLoader::resolveIconFileName(HbIconLoadingParams &params)
   968 QString HbIconLoader::resolveIconFileName(HbIconLoadingParams &params)
  1100 {
   969 {
  1101     // Search in theme (assume that we received a logical icon name).
   970     // Search in theme (assume that we received a logical icon name).
  1102     QString iconPath = d->findIconHelper(params.cleanIconName, params.mirrored, params.mirroredIconFound);
   971     QString iconPath = d->findSharedResourceHelper(params.cleanIconName, params.mirrored, params.mirroredIconFound);
  1103     bool iconFound = !iconPath.isEmpty();
   972     bool iconFound = !iconPath.isEmpty();
  1104 #ifdef HB_ICON_TRACES
   973 #ifdef HB_ICON_TRACES
  1105     qDebug() << params.cleanIconName << " => " << iconPath;
   974     qDebug() << params.cleanIconName << " => " << iconPath;
  1106 #endif
   975 #endif
  1107     // If not found then it can still be a normal file specified with a relative path.
   976     // If not found then it can still be a normal file specified with a relative path.
  1112         }
   981         }
  1113     }
   982     }
  1114     // Use the 'unknown' icon, if needed, when the queried icon was not found.
   983     // Use the 'unknown' icon, if needed, when the queried icon was not found.
  1115     if (!iconFound) {
   984     if (!iconFound) {
  1116         if (params.options.testFlag(ReturnUnknownIcon)) {
   985         if (params.options.testFlag(ReturnUnknownIcon)) {
  1117             iconPath = d->findIconHelper(s_unknown, false, params.mirroredIconFound);
   986             iconPath = d->findSharedResourceHelper(s_unknown, false, params.mirroredIconFound);
  1118         }
   987         }
  1119     }
   988     }
  1120 
   989 
  1121     return iconPath;
   990     return iconPath;
  1122 }
   991 }
  1143                    params.size,
  1012                    params.size,
  1144                    params.aspectRatioMode,
  1013                    params.aspectRatioMode,
  1145                    params.mode,
  1014                    params.mode,
  1146                    (params.mirrored && !params.mirroredIconFound),
  1015                    (params.mirrored && !params.mirroredIconFound),
  1147                    params.options,
  1016                    params.options,
  1148                    params.color);
  1017                    params.color,
       
  1018                    params.renderMode);
  1149 
  1019 
  1150     //Creates HbIconImpl instance based on the type of data returned by themeserver.
  1020     //Creates HbIconImpl instance based on the type of data returned by themeserver.
  1151     //HbIconImpl thus created could be any one of the following impl-types:
  1021     //HbIconImpl thus created could be any one of the following impl-types:
  1152     //1. HbSgImageIconImpl 
  1022     //1. HbSgImageIconImpl 
  1153     //2. HbNvgIconImpl
  1023     //2. HbNvgIconImpl
  1379 #endif
  1249 #endif
  1380     }
  1250     }
  1381 
  1251 
  1382     // Delete original pixmap if its size is large
  1252     // Delete original pixmap if its size is large
  1383     source->deletePixmapIfLargerThan(PIXMAP_SIZE_LIMIT);
  1253     source->deletePixmapIfLargerThan(PIXMAP_SIZE_LIMIT);
       
  1254 }
       
  1255 
       
  1256 /*!
       
  1257  * \fn void HbIconLoader::switchRenderingMode()
       
  1258  * 
       
  1259  * 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 
       
  1261  *  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 
       
  1263  *  can do its part of cleanup. 
       
  1264  *  \a newRenderMode new rendering mode of application 
       
  1265  */ 
       
  1266 
       
  1267 void HbIconLoader::switchRenderingMode(HbRenderingMode newRenderMode)
       
  1268 {
       
  1269 #ifndef Q_OS_SYMBIAN
       
  1270     Q_UNUSED(newRenderMode)
       
  1271 #endif
       
  1272 
       
  1273 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
       
  1274     if (newRenderMode != renderMode) {     
       
  1275         if (newRenderMode == ESWRendering) {
       
  1276             // switching from HW to SW mode  
       
  1277             freeGpuIconData();            
       
  1278         }        
       
  1279         if (HbThemeClient::global()->switchRenderingMode(newRenderMode)) {         
       
  1280             renderMode = newRenderMode;
       
  1281         }
       
  1282     }
       
  1283 #endif
       
  1284 }
       
  1285 
       
  1286 void HbIconLoader::updateRenderingMode(QPaintEngine::Type type)
       
  1287 {
       
  1288     if (type == QPaintEngine::OpenVG) {
       
  1289         renderMode = EHWRendering;
       
  1290     } else {
       
  1291         renderMode = ESWRendering;
       
  1292     }
  1384 }
  1293 }
  1385 
  1294 
  1386 /*!
  1295 /*!
  1387  * \fn HbIconImpl* HbIconLoader::loadIcon()
  1296  * \fn HbIconImpl* HbIconLoader::loadIcon()
  1388  * 
  1297  * 
  1441     params.mirroredIconFound = false;
  1350     params.mirroredIconFound = false;
  1442     params.canCache = true;
  1351     params.canCache = true;
  1443     params.animationCreated = false;
  1352     params.animationCreated = false;
  1444     params.mirroringHandled = false;
  1353     params.mirroringHandled = false;
  1445     params.modeHandled = false;
  1354     params.modeHandled = false;
       
  1355     params.renderMode = renderMode;
  1446     resolveCleanIconName(params);
  1356     resolveCleanIconName(params);
  1447 
  1357 
  1448     // Step 1: Check if the icon has animation definition
  1358     // Step 1: Check if the icon has animation definition
  1449 
  1359 
  1450     // This check is to prevent animation frames from trying to load new animations
  1360     // This check is to prevent animation frames from trying to load new animations
  1472     // Step 2: There was no animation definition, try get icon from server
  1382     // Step 2: There was no animation definition, try get icon from server
  1473     if (!params.animationCreated) {
  1383     if (!params.animationCreated) {
  1474     
  1384     
  1475 #ifdef HB_ICONIMPL_CACHE
  1385 #ifdef HB_ICONIMPL_CACHE
  1476         QByteArray cacheKey = d->createCacheKeyFrom( params.iconName, params.size, params.aspectRatioMode,
  1386         QByteArray cacheKey = d->createCacheKeyFrom( params.iconName, params.size, params.aspectRatioMode,
  1477                         params.mode, params.mirrored, params.color );
  1387                         params.mode, params.mirrored, params.color, params.renderMode );
  1478         //look up in the local iconImplCache. 
  1388         //look up in the local iconImplCache. 
  1479         //If found return the ptr directly
  1389         //If found return the ptr directly
  1480         if (iconImplCache.contains(cacheKey)) {
  1390         if (iconImplCache.contains(cacheKey)) {
  1481             HbIconImpl * ptr = iconImplCache.value(cacheKey);
  1391             HbIconImpl * ptr = iconImplCache.value(cacheKey);
  1482             ptr->incrementRefCount();
  1392             ptr->incrementRefCount();
  1617     // Consolidated icon will be created for NVG with SGImage lite support.
  1527     // Consolidated icon will be created for NVG with SGImage lite support.
  1618     // and when NVG is not available.
  1528     // and when NVG is not available.
  1619 #if defined(HB_ICONIMPL_CACHE)
  1529 #if defined(HB_ICONIMPL_CACHE)
  1620 
  1530 
  1621     QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconData.multiPartIconId, size,
  1531     QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconData.multiPartIconId, size,
  1622                           aspectRatioMode, mode, mirrored, color);
  1532                           aspectRatioMode, mode, mirrored, color, renderMode);
  1623     //If consolidated icon found in the client's cache, increment ref-count and return
  1533     //If consolidated icon found in the client's cache, increment ref-count and return
  1624     if (iconImplCache.contains(cacheKey)) {
  1534     if (iconImplCache.contains(cacheKey)) {
  1625         HbIconImpl * ptr = iconImplCache.value(cacheKey);
  1535         HbIconImpl * ptr = iconImplCache.value(cacheKey);
  1626         ptr->incrementRefCount();
  1536         ptr->incrementRefCount();
  1627 #ifdef HB_ICON_CACHE_DEBUG
  1537 #ifdef HB_ICON_CACHE_DEBUG
  1633 #endif
  1543 #endif
  1634 
  1544 
  1635     QStringList iconPathList;
  1545     QStringList iconPathList;
  1636 
  1546 
  1637     for (int i = 0; i < listOfIcons.count(); i++) {
  1547     for (int i = 0; i < listOfIcons.count(); i++) {
  1638         QString path = d->findIconHelper(listOfIcons.at(i), mirrored, mirroredIconFound);
  1548         QString path = d->findSharedResourceHelper(listOfIcons.at(i), mirrored, mirroredIconFound);
  1639         if (!path.isEmpty()) {
  1549         if (!path.isEmpty()) {
  1640             iconPathList.append(path);
  1550             iconPathList.append(path);
  1641         } else {
  1551         } else {
  1642             return icon;
  1552             return icon;
  1643         }
  1553         }
  1649 
  1559 
  1650     //If consolidated icon was not found in the client's cache, initiate an IPC to load
  1560     //If consolidated icon was not found in the client's cache, initiate an IPC to load
  1651     //the consolidated icon on themeserver
  1561     //the consolidated icon on themeserver
  1652     iconInfo = HbThemeClient::global()->getMultiPartIconInfo(iconPathList,
  1562     iconInfo = HbThemeClient::global()->getMultiPartIconInfo(iconPathList,
  1653                                                              multiPartIconData, size, aspectRatioMode, mode,
  1563                                                              multiPartIconData, size, aspectRatioMode, mode,
  1654                                                              (mirrored && !mirroredIconFound), options, color);
  1564                                                              (mirrored && !mirroredIconFound), options, color, renderMode);
  1655 
  1565 
  1656 #ifdef HB_ICON_TRACES
  1566 #ifdef HB_ICON_TRACES
  1657     qDebug() << "HbIconLoader::getMultiPartIconInfo, offset from server: " << iconInfo.pixmapData.offset << iconPathList;
  1567     qDebug() << "HbIconLoader::getMultiPartIconInfo, offset from server: " << iconInfo.pixmapData.offset << iconPathList;
  1658 #endif
  1568 #endif
  1659 
  1569 
  1705                                    mirroredIconFound,
  1615                                    mirroredIconFound,
  1706                                    options,
  1616                                    options,
  1707                                    color,
  1617                                    color,
  1708                                    HbIconLoader::AnyType,
  1618                                    HbIconLoader::AnyType,
  1709                                    HbIconLoader::AnyPurpose,
  1619                                    HbIconLoader::AnyPurpose,
  1710                                    multiPieceImpls);
  1620                                    multiPieceImpls,
       
  1621                                    renderMode);  
  1711 #else
  1622 #else
  1712         //For OS other than Symbian, call HbIconLoader::loadIcon to individually load icons
  1623         //For OS other than Symbian, call HbIconLoader::loadIcon to individually load icons
  1713         for (int i = 0; i < count; i++) {
  1624         for (int i = 0; i < count; i++) {
  1714             HbIconImpl *impl = loadIcon(iconPathList[i], HbIconLoader::AnyType,
  1625             HbIconImpl *impl = loadIcon(iconPathList[i], HbIconLoader::AnyType,
  1715                                         HbIconLoader::AnyPurpose,
  1626                                         HbIconLoader::AnyPurpose,
  1743            HbThemeClient::global()->unloadIcon(icon->iconFileName(),
  1654            HbThemeClient::global()->unloadIcon(icon->iconFileName(),
  1744                                                icon->keySize(),
  1655                                                icon->keySize(),
  1745                                                icon->iconAspectRatioMode(),
  1656                                                icon->iconAspectRatioMode(),
  1746                                                icon->iconMode(),
  1657                                                icon->iconMode(),
  1747                                                icon->isMirrored(),
  1658                                                icon->isMirrored(),
  1748                                                icon->color()
  1659                                                icon->color(),
  1749                                               );
  1660                                                icon->iconRenderingMode()
       
  1661                                                );
  1750         }
  1662         }
  1751 #ifdef HB_ICONIMPL_CACHE
  1663 #ifdef HB_ICONIMPL_CACHE
  1752         int rem = iconImplCache.remove(iconImplCache.key(icon));
  1664         int rem = iconImplCache.remove(iconImplCache.key(icon));
  1753         if (rem > 0) {
  1665         if (rem > 0) {
  1754 #ifdef HB_ICON_TRACES
  1666 #ifdef HB_ICON_TRACES
  1796                                 bool mirroredIconFound,
  1708                                 bool mirroredIconFound,
  1797                                 HbIconLoader::IconLoaderOptions options,
  1709                                 HbIconLoader::IconLoaderOptions options,
  1798                                 const QColor &color,
  1710                                 const QColor &color,
  1799                                 HbIconLoader::IconDataType type,
  1711                                 HbIconLoader::IconDataType type,
  1800                                 HbIconLoader::Purpose,
  1712                                 HbIconLoader::Purpose,
  1801                                 QVector<HbIconImpl *> & iconImplList)
  1713                                 QVector<HbIconImpl *> & iconImplList,
  1802 {
  1714                                 HbRenderingMode currRenderMode)
  1803 	 Q_UNUSED(type);
  1715 {
  1804 	 QVector<int> posList;
  1716     Q_UNUSED(type);
       
  1717     QVector<int> posList;
  1805 #ifdef HB_ICONIMPL_CACHE
  1718 #ifdef HB_ICONIMPL_CACHE
  1806     // search the client cache first before asking the server
  1719     // search the client cache first before asking the server
  1807     for(int i = 0; i < multiPartIconList.count(); i++) {
  1720     for(int i = 0; i < multiPartIconList.count(); i++) {
  1808         QByteArray cacheKey = d->createCacheKeyFrom( multiPartIconList[i], sizeList[i], aspectRatioMode,
  1721         QByteArray cacheKey = d->createCacheKeyFrom( multiPartIconList[i], sizeList[i], aspectRatioMode,
  1809                         mode, mirrored, color );
  1722                         mode, mirrored, color, currRenderMode );
  1810         //look up in the local iconImplCache. 
  1723         //look up in the local iconImplCache. 
  1811         //If found return the ptr directly
  1724         //If found return the ptr directly
  1812         HbIconImpl * ptr = 0;
  1725         HbIconImpl * ptr = 0;
  1813         if (iconImplCache.contains(cacheKey)) {
  1726         if (iconImplCache.contains(cacheKey)) {
  1814             ptr = iconImplCache.value(cacheKey);
  1727             ptr = iconImplCache.value(cacheKey);
  1836 #endif
  1749 #endif
  1837     // If client-side cache is not enabled, ask server for all the pieces' information
  1750     // If client-side cache is not enabled, ask server for all the pieces' information
  1838     int count = multiPartIconList.count();
  1751     int count = multiPartIconList.count();
  1839     if (count > 0) {
  1752     if (count > 0) {
  1840         HbSharedIconInfoList iconInfoList = HbThemeClient::global()->getMultiIconInfo(multiPartIconList, sizeList,
  1753         HbSharedIconInfoList iconInfoList = HbThemeClient::global()->getMultiIconInfo(multiPartIconList, sizeList,
  1841                                             aspectRatioMode, mode, mirrored, options, color);
  1754                                             aspectRatioMode, mode, mirrored, options, color, currRenderMode);
  1842 
  1755 
  1843         HbIconImpl* impl = 0;
  1756         HbIconImpl* impl = 0;
  1844 
  1757 
  1845         HbIconLoadingParams params;
  1758         HbIconLoadingParams params;
  1846 
  1759 
  1857 
  1770 
  1858                 impl = HbIconImplCreator::createIconImpl(iconInfoList.icon[i], params);
  1771                 impl = HbIconImplCreator::createIconImpl(iconInfoList.icon[i], params);
  1859 
  1772 
  1860 #ifdef HB_ICONIMPL_CACHE
  1773 #ifdef HB_ICONIMPL_CACHE
  1861                 QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconList[i], sizeList.at(i) , aspectRatioMode,
  1774                 QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconList[i], sizeList.at(i) , aspectRatioMode,
  1862                                       mode, mirrored, color);
  1775                                       mode, mirrored, color, currRenderMode);
  1863                 iconImplCache.insert(cacheKey, impl);
  1776                 iconImplCache.insert(cacheKey, impl);
  1864 #ifdef HB_ICON_CACHE_DEBUG
  1777 #ifdef HB_ICON_CACHE_DEBUG
  1865                 qDebug() << "HbIconLoader::getMultiIconImplFromServer(): " << params.iconName << " inserted into impl-cache, ref-count now = " << impl->refCount();
  1778                 qDebug() << "HbIconLoader::getMultiIconImplFromServer(): " << params.iconName << " inserted into impl-cache, ref-count now = " << impl->refCount();
  1866 #endif
  1779 #endif
  1867 
  1780 
  1925         HbThemeClient::global()->unLoadMultiIcon(iconNameList, 
  1838         HbThemeClient::global()->unLoadMultiIcon(iconNameList, 
  1926                                             sizeList,
  1839                                             sizeList,
  1927                                             multiPieceImpls[0]->iconAspectRatioMode(),
  1840                                             multiPieceImpls[0]->iconAspectRatioMode(),
  1928                                             multiPieceImpls[0]->iconMode(),
  1841                                             multiPieceImpls[0]->iconMode(),
  1929                                             multiPieceImpls[0]->isMirrored(),
  1842                                             multiPieceImpls[0]->isMirrored(),
  1930                                             multiPieceImpls[0]->color()
  1843                                             multiPieceImpls[0]->color(),
       
  1844                                             multiPieceImpls[0]->iconRenderingMode()
  1931                                             );
  1845                                             );
  1932     }
  1846     }
  1933 }
  1847 }
  1934 
  1848 
  1935 // End of File
  1849 // End of File