src/hbcore/image/hbiconanimationmanager.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 5 627c4a0fd0e7
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    63 \internal
    63 \internal
    64 */
    64 */
    65 bool HbIconAnimationManagerPrivate::addDefinitionFile(const QString &definitionFileName)
    65 bool HbIconAnimationManagerPrivate::addDefinitionFile(const QString &definitionFileName)
    66 {
    66 {
    67     // Stop right away if the file has already been added.
    67     // Stop right away if the file has already been added.
    68     if (definitionFileNames.contains(definitionFileName)) {
    68     foreach (const QString &iconName, animations.keys()) {
    69         return true;
    69         if (animations.operator[](iconName).definitionFileName == definitionFileName) {
       
    70             return true;
       
    71         }
    70     }
    72     }
    71 
    73 
    72     // Check if there is a file with the given name in the current theme.
    74     // Check if there is a file with the given name in the current theme.
    73     QString pathInTheme = HbIconLoader::global()->findSharedResource(definitionFileName);
    75     QString pathInTheme = HbIconLoader::global()->findSharedResource(definitionFileName, Hb::AnimationResource);
    74 #ifdef HB_ICON_TRACES
    76 #ifdef HB_ICON_TRACES
    75     qDebug() << definitionFileName << " => " << pathInTheme;
    77     qDebug() << definitionFileName << " => " << pathInTheme;
    76 #endif
    78 #endif
    77 
    79 
    78     // In case of theme usage definitionFileName will just be a simple name and
    80     // In case of theme usage definitionFileName will just be a simple name and
    79     // realFileName will point to the name with the full path.
    81     // realFileName will point to the name with the full path.
    80     const QString *realFileName = pathInTheme.isEmpty() ? &definitionFileName : &pathInTheme;
    82     const QString *realFileName = pathInTheme.isEmpty() ? &definitionFileName : &pathInTheme;
    81 
    83 
    82     // Add filename in the list.
       
    83     definitionFileNames.append(definitionFileName);
       
    84     allDefNames.insert(definitionFileName);
       
    85 
       
    86     // Parse the filename and add entries in the hash table, first try the themeserver.
    84     // Parse the filename and add entries in the hash table, first try the themeserver.
    87     bool ret = parser.parseDefinitionFileShared(&definitionFileNames.last(),
    85     bool ret = parser.parseDefinitionFileShared(definitionFileName,
    88                                                 animations, *realFileName);
    86                                                 animations, *realFileName);
    89     if (!ret) {
    87     if (!ret) {
    90         // If themeserver did not return anything then try the file locally.
    88         // If themeserver did not return anything then try the file locally.
    91         ret = parser.parseDefinitionFile(&definitionFileNames.last(),
    89         ret = parser.parseDefinitionFile(definitionFileName,
    92                                          animations, *realFileName);
    90                                          animations, *realFileName);
    93     }
    91     }
    94 
    92 
    95     // If parsing failed, remove the definition filename string from the list
    93     if (ret) {
    96     if (!ret) {
    94         allDefNames.insert(definitionFileName);
    97         definitionFileNames.removeLast();
       
    98     }
    95     }
    99 
    96 
   100     return ret;
    97     return ret;
   101 }
    98 }
   102 
    99 
   109 {
   106 {
   110     // Remove old definition
   107     // Remove old definition
   111     animations.remove(iconName);
   108     animations.remove(iconName);
   112     // Add new definition
   109     // Add new definition
   113     HbIconAnimationData data;
   110     HbIconAnimationData data;
   114     data.definitionFileName = 0;
   111     data.definitionFileName.clear();
   115     data.def = definition;
   112     data.def = definition;
   116 
       
   117     animations.insert(iconName, data);
   113     animations.insert(iconName, data);
   118 }
   114 }
   119 
   115 
   120 /*!
   116 /*!
   121 \internal
   117 \internal
   123 void HbIconAnimationManagerPrivate::removeDefinitionFile(const QString &definitionFileName)
   119 void HbIconAnimationManagerPrivate::removeDefinitionFile(const QString &definitionFileName)
   124 {
   120 {
   125     AnimHash::iterator i = animations.begin();
   121     AnimHash::iterator i = animations.begin();
   126     while (i != animations.end()) {
   122     while (i != animations.end()) {
   127         const HbIconAnimationData &data = *i;
   123         const HbIconAnimationData &data = *i;
   128         if (data.definitionFileName && *(data.definitionFileName) == definitionFileName) {
   124         if (data.definitionFileName == definitionFileName) {
   129             // Remove definition from hash and move iterator to next item
   125             // Remove definition from hash and move iterator to next item
   130             i = animations.erase(i);
   126             i = animations.erase(i);
   131         } else {
   127         } else {
   132             ++i;
   128             ++i;
   133         }
   129         }
   134     }
   130     }
   135     // Remove the filename string from the list also
       
   136     definitionFileNames.removeOne(definitionFileName);
       
   137 }
   131 }
   138 
   132 
   139 /*!
   133 /*!
   140 \internal
   134 \internal
   141 */
   135 */
   148 \internal
   142 \internal
   149 */
   143 */
   150 HbIconAnimationDefinition HbIconAnimationManagerPrivate::getDefinition(const QString &iconName)
   144 HbIconAnimationDefinition HbIconAnimationManagerPrivate::getDefinition(const QString &iconName)
   151 {
   145 {
   152     // This returns default constructed list if not found in hash    
   146     // This returns default constructed list if not found in hash    
   153     return animations.value(iconName).def;
   147     return animations.operator[](iconName).def;
   154 }
   148 }
   155 
   149 
   156 /*!
   150 /*!
   157   \internal
   151   \internal
   158 */
   152 */
   210     // animation definitions (or at least try to reload; some defs may now be
   204     // animation definitions (or at least try to reload; some defs may now be
   211     // missing if they were present in the previous theme but not in the new
   205     // missing if they were present in the previous theme but not in the new
   212     // one).
   206     // one).
   213     foreach (const QString &iconName, animations.keys()) {
   207     foreach (const QString &iconName, animations.keys()) {
   214         // Do not remove animations that were not created from files.
   208         // Do not remove animations that were not created from files.
   215         if (animations.value(iconName).definitionFileName) {
   209         if (!animations.operator[](iconName).definitionFileName.isEmpty()) {
   216             animations.remove(iconName);
   210             animations.remove(iconName);
   217         }
   211         }
   218     }
   212     }
   219     definitionFileNames.clear();
   213     // Use allDefNames which contains all the names passed to
   220     //
   214     // addDefinitionFile() since the creation of this instance. This
   221     // Cannot use definitionFileNames here because it is cleared upon every
   215     // enables to work properly also in the following situation:
   222     // theme change. Use allDefNames which contains all the names passed to
       
   223     // addDefinitionFile() since the creation of this instance. This enables to
       
   224     // work properly also in the following situation:
       
   225     //
   216     //
   226     // 1. addDefinitionFile(somethingFromTheme)
   217     // 1. addDefinitionFile(somethingFromTheme)
   227     //
   218     //
   228     // 2. Theme changes to a theme that does _not_ contain somethingFromTheme.
   219     // 2. Theme changes to a theme that does _not_ contain somethingFromTheme.
   229     //
   220     //