src/hbcore/image/hbicontheme.cpp
changeset 5 627c4a0fd0e7
parent 1 f7ac710697a9
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    39 {
    39 {
    40 public:
    40 public:
    41     HbIconThemePrivate();
    41     HbIconThemePrivate();
    42     ~HbIconThemePrivate();
    42     ~HbIconThemePrivate();
    43 
    43 
       
    44     void loadThemeDescriptionFile();
       
    45 
       
    46 public:
    44     QString m_theme;
    47     QString m_theme;
    45     QStringList m_dirList;
       
    46     QString m_description;
    48     QString m_description;
       
    49     QString m_name;
    47     bool loaded;
    50     bool loaded;
    48     void loadThemeDescriptionFile(const QString &themePath, int priority);
       
    49     void loadThemeDescriptionFiles(const QString &theme);
       
    50     bool addBaseThemePath();
       
    51 };
    51 };
    52 
       
    53 void HbIconThemePrivate::loadThemeDescriptionFiles(const QString &theme)
       
    54 {
       
    55     const QString indextheme(THEME_INDEX_FILE);
       
    56     QString pathToTheme;
       
    57     QMap<int, QString> maplist = HbThemeUtils::constructHierarchyListWithPathInfo(
       
    58         QString(), theme, Hb::IconResource);
       
    59     QMapIterator<int, QString> i(maplist);
       
    60      i.toBack();
       
    61      while (i.hasPrevious()) {
       
    62          i.previous();
       
    63          pathToTheme = HbStandardDirs::findResource(i.value() + indextheme, Hb::IconResource);
       
    64          if (!pathToTheme.isEmpty()) {
       
    65              loadThemeDescriptionFile(pathToTheme, i.key());
       
    66          }
       
    67      }
       
    68     if (!addBaseThemePath()) {
       
    69          qDebug() << "Can't find base theme";
       
    70      }
       
    71      loaded = true;
       
    72 }
       
    73 
    52 
    74 HbIconThemePrivate::HbIconThemePrivate() : loaded(false)
    53 HbIconThemePrivate::HbIconThemePrivate() : loaded(false)
    75 {
    54 {
    76 }
    55 }
    77 
    56 
    78 HbIconThemePrivate::~HbIconThemePrivate()
    57 HbIconThemePrivate::~HbIconThemePrivate()
    79 {
    58 {
    80 }
    59 }
    81 
    60 
    82 void HbIconThemePrivate::loadThemeDescriptionFile(const QString &themePath, int priority)
    61 void HbIconThemePrivate::loadThemeDescriptionFile()
    83 {
    62 {
       
    63     // TODO: index file is accessed in several places, create utility
       
    64     HbThemeIndexInfo info = HbThemeUtils::getThemeIndexInfo(ActiveTheme);
       
    65 
       
    66     QString indexFileName;
       
    67 
       
    68     indexFileName.append(info.path);
       
    69     indexFileName.append("/icons/");
       
    70     indexFileName.append(info.name);
       
    71     indexFileName.append("/" THEME_INDEX_FILE);
       
    72 
    84     HbIniParser iniParser;
    73     HbIniParser iniParser;
    85     QFile themeFile(themePath);
    74     QFile themeFile(indexFileName);
    86 
    75 
    87     if (!themeFile.open(QIODevice::ReadOnly) || !iniParser.read(&themeFile)) {
    76     if (!themeFile.open(QIODevice::ReadOnly) || !iniParser.read(&themeFile)) {
    88         qDebug() << "Can't access file : " << themePath;
    77 #ifdef HB_THEME_SERVER_TRACES 
       
    78         qDebug() << "HbIconTheme: Can't access file: " << indexFileName;
       
    79 #endif
    89         return;
    80         return;
    90     }
    81     }
    91     if (priority == HbLayeredStyleLoader::Priority_Theme) {
    82     m_description = iniParser.value("Icon Theme", "Comment");
    92         m_description = iniParser.value("Icon Theme", "Comment");
    83     m_name = iniParser.value("Icon Theme", "Name");
    93 #ifdef Q_OS_SYMBIAN
    84 #ifdef Q_OS_SYMBIAN
    94         m_description = m_description.left(m_description.indexOf("\n", 0));
    85     m_description = m_description.left(m_description.indexOf("\n", 0));
       
    86     m_name = m_name.left(m_name.indexOf("\n", 0));
    95 #endif
    87 #endif
    96     }
       
    97 
       
    98     QString directories = iniParser.value("Icon Theme", "Directories");
       
    99     QStringList dirList = directories.split( ',', QString::SkipEmptyParts );
       
   100     QString indexThemeDir(themePath);
       
   101     indexThemeDir.chop(sizeof(THEME_INDEX_FILE) - 1);
       
   102 
       
   103     foreach (const QString &str, dirList) {
       
   104         m_dirList.append(QString(indexThemeDir + str + '/'));
       
   105     }
       
   106 }
    88 }
   107 
       
   108 bool HbIconThemePrivate::addBaseThemePath()
       
   109 {
       
   110     HbIniParser iniParser;
       
   111     const HbThemeInfo &baseThemeInfo = HbThemeUtils::baseTheme();
       
   112     QString baseThemePath = baseThemeInfo.rootDir + "/themes/icons/" + baseThemeInfo.name + "/"THEME_INDEX_FILE;
       
   113 
       
   114     // Parse it
       
   115     QFile baseThemeFile(baseThemePath);
       
   116     if (!baseThemeFile.open(QIODevice::ReadOnly) || !iniParser.read(&baseThemeFile)) {
       
   117         qDebug() << "Can't access file";
       
   118         return false;
       
   119     }
       
   120 
       
   121     if (m_theme == baseThemeInfo.name) {
       
   122         m_description = iniParser.value("Icon Theme", "Comment");
       
   123 #ifdef Q_OS_SYMBIAN
       
   124         m_description = m_description.left(m_description.indexOf("\n", 0));
       
   125 #endif
       
   126     }
       
   127 
       
   128     //Read parameters
       
   129     QString directories = iniParser.value("Icon Theme", "Directories");
       
   130     QStringList dirList = directories.split(',', QString::SkipEmptyParts);
       
   131     baseThemePath.chop(sizeof(THEME_INDEX_FILE) - 1);
       
   132     // Save paths
       
   133     foreach (const QString &str, dirList) {
       
   134         m_dirList.append(QString(baseThemePath + str + '/'));
       
   135     }
       
   136 
       
   137     return true;
       
   138 }
       
   139 
       
   140 
    89 
   141 /*!
    90 /*!
   142     \class HbIconTheme
    91     \class HbIconTheme
   143     \brief HbIconTheme gives access to icon themes and stores icon theme properties 
    92     \brief HbIconTheme gives access to icon themes and stores icon theme properties
   144            according to the Freedesktop Icon Theme Specification
    93            according to the Freedesktop Icon Theme Specification
   145 */
    94 */
   146 HbIconTheme::HbIconTheme()
    95 HbIconTheme::HbIconTheme()
   147     : d(new HbIconThemePrivate())
    96     : d(new HbIconThemePrivate())
   148 {
    97 {
   153     delete d;
   102     delete d;
   154 }
   103 }
   155 
   104 
   156 void HbIconTheme::setCurrentTheme(const QString &theme)
   105 void HbIconTheme::setCurrentTheme(const QString &theme)
   157 {
   106 {
   158     if (d->m_theme != theme) {
   107     if (!theme.isEmpty()) {
   159         d->m_theme = theme;
   108         d->m_theme = theme;
   160         d->m_dirList.clear();
       
   161         d->loaded = false;
   109         d->loaded = false;
   162     }
   110     }
   163 }
   111 }
   164 
   112 
   165 /**
   113 /**
   168 QString HbIconTheme::currentTheme() const
   116 QString HbIconTheme::currentTheme() const
   169 {
   117 {
   170     return d->m_theme;
   118     return d->m_theme;
   171 }
   119 }
   172 
   120 
   173 /**
       
   174  * List of valid subdirectories of a theme
       
   175  */
       
   176 QStringList HbIconTheme::dirList() const
       
   177 { 
       
   178     if (!d->loaded) {
       
   179         d->loadThemeDescriptionFiles(d->m_theme);
       
   180     }
       
   181     return d->m_dirList;
       
   182 }
       
   183 
       
   184 QString HbIconTheme::description() const
   121 QString HbIconTheme::description() const
   185 {
   122 {
   186     if (!d->loaded) {
   123     if (!d->loaded) {
   187         d->loadThemeDescriptionFiles(d->m_theme);
   124         d->loadThemeDescriptionFile();
   188     }
   125     }
   189     return d->m_description;
   126     return d->m_description;
   190 }
   127 }
   191 
   128 
   192 void HbIconTheme::clearDirList()
   129 QString HbIconTheme::name() const
   193 {
   130 {
   194     d->m_dirList.clear();
   131     if (!d->loaded) {
   195     d->loaded = false;
   132         d->loadThemeDescriptionFile();
       
   133     }
       
   134     return d->m_name;
   196 }
   135 }
   197 
   136 
   198 void HbIconTheme::emitUpdateIcons(const QStringList &fileNames)
   137 void HbIconTheme::emitUpdateIcons(const QStringList &fileNames)
   199 {
   138 {
   200     emit iconsUpdated(fileNames);
   139     emit iconsUpdated(fileNames);