KDEUI
kicontheme.cpp
Go to the documentation of this file.
00001 /* vi: ts=8 sts=4 sw=4 00002 * 00003 * kicontheme.cpp: Lowlevel icon theme handling. 00004 * 00005 * This file is part of the KDE project, module kdecore. 00006 * Copyright (C) 2000 Geert Jansen <jansen@kde.org> 00007 * Antonio Larrosa <larrosa@kde.org> 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Library General Public 00011 * License version 2 as published by the Free Software Foundation. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Library General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Library General Public License 00019 * along with this library; see the file COPYING.LIB. If not, write to 00020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 * Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #include "kicontheme.h" 00025 #include "k3icon_p.h" 00026 00027 #include <sys/stat.h> 00028 #include <unistd.h> 00029 #include <stdlib.h> 00030 00031 #include <QtGui/QAction> 00032 #include <QtCore/QCharRef> 00033 #include <QtCore/QMutableStringListIterator> 00034 #include <QtCore/QMap> 00035 #include <QtCore/QSet> 00036 #include <QtGui/QPixmap> 00037 #include <QtGui/QPixmapCache> 00038 #include <QtGui/QImage> 00039 #include <QtCore/QFileInfo> 00040 #include <QtCore/QDir> 00041 00042 #include <kdebug.h> 00043 #include <kicon.h> 00044 #include <kstandarddirs.h> 00045 #include <kglobal.h> 00046 #include <ksharedconfig.h> 00047 #include <kconfig.h> 00048 #include <kcomponentdata.h> 00049 #include <klocale.h> 00050 #include <kde_file.h> 00051 00052 #include <kconfiggroup.h> 00053 00054 // The following define exists because the Qt SVG renderer needs 00055 // to be improved. This will be removed soon. (ereslibre) 00056 #undef KDE_QT_SVG_RENDERER_FIXED 00057 00058 class KIconTheme::KIconThemePrivate 00059 { 00060 public: 00061 QString example, screenshot; 00062 QString linkOverlay, lockOverlay, zipOverlay, shareOverlay; 00063 bool hidden; 00064 KSharedConfig::Ptr sharedConfig; 00065 00066 int mDefSize[6]; 00067 QList<int> mSizes[6]; 00068 00069 int mDepth; 00070 QString mDir, mName, mInternalName, mDesc; 00071 QStringList mInherits; 00072 QList<KIconThemeDir *> mDirs; 00073 }; 00074 K_GLOBAL_STATIC(QString, _theme) 00075 K_GLOBAL_STATIC(QStringList, _theme_list) 00076 00080 class KIconThemeDir 00081 { 00082 public: 00083 KIconThemeDir(const QString& basedir, const QString &themedir, const KConfigGroup &config); 00084 00085 bool isValid() const { return mbValid; } 00086 QString iconPath(const QString& name) const; 00087 QStringList iconList() const; 00088 QString dir() const { return mBaseDirThemeDir; } 00089 00090 KIconLoader::Context context() const { return mContext; } 00091 KIconLoader::Type type() const { return mType; } 00092 int size() const { return mSize; } 00093 int minSize() const { return mMinSize; } 00094 int maxSize() const { return mMaxSize; } 00095 int threshold() const { return mThreshold; } 00096 00097 private: 00098 bool mbValid; 00099 KIconLoader::Type mType; 00100 KIconLoader::Context mContext; 00101 int mSize, mMinSize, mMaxSize; 00102 int mThreshold; 00103 00104 QString mBaseDirThemeDir; 00105 }; 00106 00107 00108 /*** K3Icon ***/ 00109 00110 K3Icon::K3Icon() 00111 { 00112 size = 0; 00113 } 00114 00115 K3Icon::~K3Icon() 00116 { 00117 } 00118 00119 bool K3Icon::isValid() const 00120 { 00121 return size != 0; 00122 } 00123 00124 00125 /*** KIconTheme ***/ 00126 00127 KIconTheme::KIconTheme(const QString& name, const QString& appName) 00128 :d(new KIconThemePrivate) 00129 { 00130 00131 d->mInternalName = name; 00132 00133 QStringList icnlibs; 00134 QStringList::ConstIterator it, itDir; 00135 QStringList themeDirs; 00136 QSet<QString> addedDirs; // Used for avoiding duplicates. 00137 00138 // Applications can have local additions to the global "locolor" and 00139 // "hicolor" icon themes. For these, the _global_ theme description 00140 // files are used.. 00141 00142 if (!appName.isEmpty() && 00143 ( name == defaultThemeName() || name== "hicolor" || name == "locolor" ) ) { 00144 icnlibs = KGlobal::dirs()->resourceDirs("data"); 00145 for (it=icnlibs.constBegin(); it!=icnlibs.constEnd(); ++it) { 00146 const QString cDir = *it + appName + "/icons/" + name; 00147 if (QFile::exists( cDir )) { 00148 themeDirs += cDir + '/'; 00149 } 00150 } 00151 } 00152 // Find the theme description file. These are always global. 00153 00154 icnlibs = KGlobal::dirs()->resourceDirs("icon") 00155 << KGlobal::dirs()->resourceDirs("xdgdata-icon") 00156 << "/usr/share/pixmaps/" 00157 // These are not in the icon spec, but e.g. GNOME puts some icons there anyway. 00158 << KGlobal::dirs()->resourceDirs("xdgdata-pixmap"); 00159 icnlibs.removeDuplicates(); 00160 00161 QString fileName, mainSection; 00162 for (it=icnlibs.constBegin(); it!=icnlibs.constEnd(); ++it) { 00163 const QString cDir = *it + name + '/'; 00164 if (KStandardDirs::exists(cDir)) { 00165 themeDirs += cDir; 00166 if (d->mDir.isEmpty()) { 00167 if (KStandardDirs::exists(cDir + "index.theme")) { 00168 d->mDir = cDir; 00169 fileName = d->mDir + "index.theme"; 00170 mainSection = "Icon Theme"; 00171 } else if (KStandardDirs::exists(cDir + "index.desktop")) { 00172 d->mDir = cDir; 00173 fileName = d->mDir + "index.desktop"; 00174 mainSection = "KDE Icon Theme"; 00175 } 00176 } 00177 } 00178 } 00179 00180 if (d->mDir.isEmpty()) { 00181 kDebug(264) << "Icon theme" << name << "not found."; 00182 return; 00183 } 00184 00185 // Use KSharedConfig to avoid parsing the file many times, from each kinstance. 00186 // Need to keep a ref to it to make this useful 00187 d->sharedConfig = KSharedConfig::openConfig(fileName); 00188 00189 KConfigGroup cfg(d->sharedConfig, mainSection); 00190 d->mName = cfg.readEntry("Name"); 00191 d->mDesc = cfg.readEntry("Comment"); 00192 d->mDepth = cfg.readEntry("DisplayDepth", 32); 00193 d->mInherits = cfg.readEntry("Inherits", QStringList()); 00194 if (name != defaultThemeName()) { 00195 for (QStringList::Iterator it = d->mInherits.begin(); it != d->mInherits.end(); ++it) { 00196 if (*it == "default" || *it == "hicolor") { 00197 *it = defaultThemeName(); 00198 } 00199 } 00200 } 00201 00202 d->hidden = cfg.readEntry("Hidden", false); 00203 d->example = cfg.readPathEntry("Example", QString()); 00204 d->screenshot = cfg.readPathEntry("ScreenShot", QString()); 00205 00206 const QStringList dirs = cfg.readPathEntry("Directories", QStringList()); 00207 for (it=dirs.begin(); it!=dirs.end(); ++it) { 00208 KConfigGroup cg(d->sharedConfig, *it); 00209 for (itDir=themeDirs.constBegin(); itDir!=themeDirs.constEnd(); ++itDir) { 00210 const QString currentDir(*itDir + *it + '/'); 00211 if (!addedDirs.contains(currentDir) && KStandardDirs::exists(currentDir)) { 00212 addedDirs.insert(currentDir); 00213 KIconThemeDir *dir = new KIconThemeDir(*itDir, *it, cg); 00214 if (!dir->isValid()) { 00215 delete dir; 00216 } 00217 else { 00218 d->mDirs.append(dir); 00219 } 00220 } 00221 } 00222 } 00223 00224 // Expand available sizes for scalable icons to their full range 00225 int i; 00226 QMap<int,QList<int> > scIcons; 00227 foreach(KIconThemeDir *dir, d->mDirs) { 00228 if (!dir) { 00229 break; 00230 } 00231 if ((dir->type() == KIconLoader::Scalable) && !scIcons.contains(dir->size())) { 00232 QList<int> lst; 00233 for (i=dir->minSize(); i<=dir->maxSize(); ++i) { 00234 lst += i; 00235 } 00236 scIcons[dir->size()] = lst; 00237 } 00238 } 00239 00240 QStringList groups; 00241 groups += "Desktop"; 00242 groups += "Toolbar"; 00243 groups += "MainToolbar"; 00244 groups += "Small"; 00245 groups += "Panel"; 00246 groups += "Dialog"; 00247 const int defDefSizes[] = { 32, 22, 22, 16, 32, 32 }; 00248 KConfigGroup cg(d->sharedConfig, mainSection); 00249 for (it=groups.constBegin(), i=0; it!=groups.constEnd(); ++it, i++) { 00250 d->mDefSize[i] = cg.readEntry(*it + "Default", defDefSizes[i]); 00251 const QList<int> lst = cg.readEntry(*it + "Sizes", QList<int>()); 00252 QList<int> exp; 00253 QList<int>::ConstIterator it2; 00254 for (it2=lst.begin(); it2!=lst.end(); ++it2) { 00255 if (scIcons.contains(*it2)) { 00256 exp += scIcons[*it2]; 00257 } else { 00258 exp += *it2; 00259 } 00260 } 00261 d->mSizes[i] = exp; 00262 } 00263 } 00264 00265 KIconTheme::~KIconTheme() 00266 { 00267 qDeleteAll(d->mDirs); 00268 delete d; 00269 } 00270 00271 QString KIconTheme::name() const 00272 { 00273 return d->mName; 00274 } 00275 00276 QString KIconTheme::internalName() const 00277 { 00278 return d->mInternalName; 00279 } 00280 00281 QString KIconTheme::description() const 00282 { 00283 return d->mDesc; 00284 } 00285 00286 QString KIconTheme::example() const 00287 { 00288 return d->example; 00289 } 00290 00291 QString KIconTheme::screenshot() const 00292 { 00293 return d->screenshot; 00294 } 00295 00296 QString KIconTheme::dir() const 00297 { 00298 return d->mDir; 00299 } 00300 00301 QStringList KIconTheme::inherits() const 00302 { 00303 return d->mInherits; 00304 } 00305 00306 bool KIconTheme::isValid() const 00307 { 00308 return !d->mDirs.isEmpty(); 00309 } 00310 00311 bool KIconTheme::isHidden() const 00312 { 00313 return d->hidden; 00314 } 00315 00316 int KIconTheme::depth() const 00317 { 00318 return d->mDepth; 00319 } 00320 00321 int KIconTheme::defaultSize(KIconLoader::Group group) const 00322 { 00323 if ((group < 0) || (group >= KIconLoader::LastGroup)) { 00324 kDebug(264) << "Illegal icon group: " << group << "\n"; 00325 return -1; 00326 } 00327 return d->mDefSize[group]; 00328 } 00329 00330 QList<int> KIconTheme::querySizes(KIconLoader::Group group) const 00331 { 00332 QList<int> empty; 00333 if ((group < 0) || (group >= KIconLoader::LastGroup)) { 00334 kDebug(264) << "Illegal icon group: " << group << "\n"; 00335 return empty; 00336 } 00337 return d->mSizes[group]; 00338 } 00339 00340 QStringList KIconTheme::queryIcons(int size, KIconLoader::Context context) const 00341 { 00342 KIconThemeDir *dir; 00343 00344 // Try to find exact match 00345 QStringList result; 00346 for (int i=0; i<d->mDirs.size(); ++i) { 00347 dir = d->mDirs.at(i); 00348 if ((context != KIconLoader::Any) && (context != dir->context())) 00349 continue; 00350 if ((dir->type() == KIconLoader::Fixed) && (dir->size() == size)) { 00351 result += dir->iconList(); 00352 continue; 00353 } 00354 if ((dir->type() == KIconLoader::Scalable) && 00355 (size >= dir->minSize()) && (size <= dir->maxSize())) { 00356 result += dir->iconList(); 00357 continue; 00358 } 00359 if ((dir->type() == KIconLoader::Threshold) && 00360 (abs(size-dir->size())<dir->threshold())) { 00361 result+=dir->iconList(); 00362 } 00363 } 00364 00365 return result; 00366 00367 /* 00368 int delta = 1000, dw; 00369 00370 // Find close match 00371 KIconThemeDir *best = 0L; 00372 for(int i=0; i<d->mDirs.size(); ++i) { 00373 dir = d->mDirs.at(i); 00374 if ((context != KIconLoader::Any) && (context != dir->context())) { 00375 continue; 00376 } 00377 dw = dir->size() - size; 00378 if ((dw > 6) || (abs(dw) >= abs(delta))) 00379 continue; 00380 delta = dw; 00381 best = dir; 00382 } 00383 if (best == 0L) { 00384 return QStringList(); 00385 } 00386 00387 return best->iconList(); 00388 */ 00389 } 00390 00391 QStringList KIconTheme::queryIconsByContext(int size, KIconLoader::Context context) const 00392 { 00393 int dw; 00394 KIconThemeDir *dir; 00395 00396 // We want all the icons for a given context, but we prefer icons 00397 // of size size . Note that this may (will) include duplicate icons 00398 //QStringList iconlist[34]; // 33 == 48-16+1 00399 QStringList iconlist[128]; // 33 == 48-16+1 00400 // Usually, only the 0, 6 (22-16), 10 (32-22), 16 (48-32 or 32-16), 00401 // 26 (48-22) and 32 (48-16) will be used, but who knows if someone 00402 // will make icon themes with different icon sizes. 00403 00404 for (int i=0;i<d->mDirs.size();++i) { 00405 dir = d->mDirs.at(i); 00406 if ((context != KIconLoader::Any) && (context != dir->context())) 00407 continue; 00408 dw = abs(dir->size() - size); 00409 iconlist[(dw<127)?dw:127]+=dir->iconList(); 00410 } 00411 00412 QStringList iconlistResult; 00413 for (int i=0; i<128; i++) iconlistResult+=iconlist[i]; 00414 00415 return iconlistResult; 00416 } 00417 00418 bool KIconTheme::hasContext(KIconLoader::Context context) const 00419 { 00420 foreach(KIconThemeDir *dir, d->mDirs) { 00421 if ((context == KIconLoader::Any) || (context == dir->context())) { 00422 return true; 00423 } 00424 } 00425 return false; 00426 } 00427 00428 K3Icon KIconTheme::iconPath(const QString& name, int size, KIconLoader::MatchType match) const 00429 { 00430 K3Icon icon; 00431 QString path; 00432 int delta = -INT_MAX; // current icon size delta of 'icon' 00433 int dw = INT_MAX; // icon size delta of current directory 00434 int dirSize = INT_MAX; // directory size of 'icon' 00435 KIconThemeDir *dir; 00436 00437 const int dirCount = d->mDirs.size(); 00438 00439 // Search the directory that contains the icon which matches best to the requested 00440 // size. If there is no directory which matches exactly to the requested size, the 00441 // following criterias get applied: 00442 // - Take a directory having icons with a minimum difference to the requested size. 00443 // - Prefer directories that allow a downscaling even if the difference to 00444 // the requested size is bigger than a directory where an upscaling is required. 00445 for (int i = 0; i < dirCount; ++i) { 00446 dir = d->mDirs.at(i); 00447 00448 if (match == KIconLoader::MatchExact) { 00449 if ((dir->type() == KIconLoader::Fixed) && (dir->size() != size)) { 00450 continue; 00451 } 00452 if ((dir->type() == KIconLoader::Scalable) && 00453 ((size < dir->minSize()) || (size > dir->maxSize()))) { 00454 continue; 00455 } 00456 if ((dir->type() == KIconLoader::Threshold) && 00457 (abs(dir->size() - size) > dir->threshold())) { 00458 continue; 00459 } 00460 } else { 00461 // dw < 0 means need to scale up to get an icon of the requested size. 00462 // Upscaling should only be done if no larger icon is available. 00463 if (dir->type() == KIconLoader::Fixed) { 00464 dw = dir->size() - size; 00465 } else if (dir->type() == KIconLoader::Scalable) { 00466 if (size < dir->minSize()) { 00467 dw = dir->minSize() - size; 00468 } else if (size > dir->maxSize()) { 00469 dw = dir->maxSize() - size; 00470 } else { 00471 dw = 0; 00472 } 00473 } else if (dir->type() == KIconLoader::Threshold) { 00474 if (size < dir->size() - dir->threshold()) { 00475 dw = dir->size() - dir->threshold() - size; 00476 } else if (size > dir->size() + dir->threshold()) { 00477 dw = dir->size() + dir->threshold() - size; 00478 } else { 00479 dw = 0; 00480 } 00481 } 00482 // Usually if the delta (= 'dw') of the current directory is 00483 // not smaller than the delta (= 'delta') of the currently best 00484 // matching icon, this candidate can be skipped. But skipping 00485 // the candidate may only be done, if this does not imply 00486 // in an upscaling of the icon. 00487 if ((abs(dw) >= abs(delta)) && 00488 ((dw < 0) || ((dw > 0) && (dir->size() < dirSize)))) { 00489 continue; 00490 } 00491 } 00492 00493 path = dir->iconPath(name); 00494 if (path.isEmpty()) { 00495 continue; 00496 } 00497 icon.path = path; 00498 // The following code has been commented out because the Qt SVG renderer needs 00499 // to be improved. If you are going to change/remove some code from this part, 00500 // please contact me before (ereslibre@kde.org), or kde-core-devel@kde.org. (ereslibre) 00501 #ifdef KDE_QT_SVG_RENDERER_FIXED 00502 icon.size = size; 00503 #else 00504 icon.size = dir->size(); 00505 #endif 00506 icon.type = dir->type(); 00507 icon.threshold = dir->threshold(); 00508 icon.context = dir->context(); 00509 00510 // if we got in MatchExact that far, we find no better 00511 if (match == KIconLoader::MatchExact) { 00512 return icon; 00513 } 00514 delta = dw; 00515 if (delta == 0) { 00516 return icon; // We won't find a better match anyway 00517 } 00518 dirSize = dir->size(); 00519 } 00520 return icon; 00521 } 00522 00523 // static 00524 QString KIconTheme::current() 00525 { 00526 // Static pointer because of unloading problems wrt DSO's. 00527 if (!_theme->isEmpty()) { 00528 return *_theme; 00529 } 00530 00531 KConfigGroup cg(KGlobal::config(), "Icons"); 00532 *_theme = cg.readEntry("Theme4", cg.readEntry("Theme", defaultThemeName())); 00533 if ( *_theme == QLatin1String("hicolor") ) { 00534 *_theme = defaultThemeName(); 00535 } 00536 /* if (_theme->isEmpty()) 00537 { 00538 if (QPixmap::defaultDepth() > 8) 00539 *_theme = defaultThemeName(); 00540 else 00541 *_theme = QLatin1String("locolor"); 00542 }*/ 00543 return *_theme; 00544 } 00545 00546 // static 00547 QStringList KIconTheme::list() 00548 { 00549 // Static pointer because of unloading problems wrt DSO's. 00550 if (!_theme_list->isEmpty()) { 00551 return *_theme_list; 00552 } 00553 00554 const QStringList icnlibs = KGlobal::dirs()->resourceDirs("icon") 00555 << KGlobal::dirs()->resourceDirs("xdgdata-icon") 00556 << "/usr/share/pixmaps" 00557 // These are not in the icon spec, but e.g. GNOME puts some icons there anyway. 00558 << KGlobal::dirs()->resourceDirs("xdgdata-pixmap"); 00559 00560 QStringList::ConstIterator it; 00561 for (it=icnlibs.begin(); it!=icnlibs.end(); ++it) { 00562 QDir dir(*it); 00563 if (!dir.exists()) { 00564 continue; 00565 } 00566 const QStringList lst = dir.entryList(QDir::Dirs); 00567 QStringList::ConstIterator it2; 00568 for (it2=lst.begin(); it2!=lst.end(); ++it2) { 00569 if ((*it2 == ".") || (*it2 == "..") || (*it2).startsWith(QLatin1String("default.")) ) { 00570 continue; 00571 } 00572 if (!KStandardDirs::exists(*it + *it2 + "/index.desktop") && !KStandardDirs::exists(*it + *it2 + "/index.theme")) { 00573 continue; 00574 } 00575 KIconTheme oink(*it2); 00576 if (!oink.isValid()) { 00577 continue; 00578 } 00579 00580 if (!_theme_list->contains(*it2)) { 00581 _theme_list->append(*it2); 00582 } 00583 } 00584 } 00585 return *_theme_list; 00586 } 00587 00588 // static 00589 void KIconTheme::reconfigure() 00590 { 00591 _theme->clear(); 00592 _theme_list->clear(); 00593 } 00594 00595 // static 00596 QString KIconTheme::defaultThemeName() 00597 { 00598 return QLatin1String("oxygen"); 00599 } 00600 00601 void KIconTheme::assignIconsToContextMenu( ContextMenus type, 00602 QList<QAction*> actions ) 00603 { 00604 switch (type) { 00605 // FIXME: This code depends on Qt's action ordering. 00606 case TextEditor: 00607 enum { UndoAct, RedoAct, Separator1, CutAct, CopyAct, PasteAct, DeleteAct, ClearAct, 00608 Separator2, SelectAllAct, NCountActs }; 00609 00610 if ( actions.count() < NCountActs ) { 00611 return; 00612 } 00613 00614 actions[UndoAct]->setIcon( KIcon("edit-undo") ); 00615 actions[RedoAct]->setIcon( KIcon("edit-redo") ); 00616 actions[CutAct]->setIcon( KIcon("edit-cut") ); 00617 actions[CopyAct]->setIcon( KIcon("edit-copy") ); 00618 actions[PasteAct]->setIcon( KIcon("edit-paste") ); 00619 actions[ClearAct]->setIcon( KIcon("edit-clear") ); 00620 actions[DeleteAct]->setIcon( KIcon("edit-delete") ); 00621 actions[SelectAllAct]->setIcon( KIcon("edit-select-all") ); 00622 break; 00623 00624 case ReadOnlyText: 00625 if ( actions.count() < 1 ) { 00626 return; 00627 } 00628 00629 actions[0]->setIcon( KIcon("edit-copy") ); 00630 break; 00631 } 00632 } 00633 00634 /*** KIconThemeDir ***/ 00635 00636 KIconThemeDir::KIconThemeDir(const QString& basedir, const QString &themedir, const KConfigGroup &config) 00637 { 00638 mbValid = false; 00639 mBaseDirThemeDir = basedir + themedir; 00640 00641 mSize = config.readEntry("Size", 0); 00642 mMinSize = 1; // just set the variables to something 00643 mMaxSize = 50; // meaningful in case someone calls minSize or maxSize 00644 mType = KIconLoader::Fixed; 00645 00646 if (mSize == 0) { 00647 return; 00648 } 00649 00650 QString tmp = config.readEntry("Context"); 00651 if (tmp == "Devices") 00652 mContext = KIconLoader::Device; 00653 else if (tmp == "MimeTypes") 00654 mContext = KIconLoader::MimeType; 00655 else if (tmp == "FileSystems") 00656 mContext = KIconLoader::FileSystem; 00657 else if (tmp == "Applications") 00658 mContext = KIconLoader::Application; 00659 else if (tmp == "Actions") 00660 mContext = KIconLoader::Action; 00661 else if (tmp == "Animations") 00662 mContext = KIconLoader::Animation; 00663 else if (tmp == "Categories") 00664 mContext = KIconLoader::Category; 00665 else if (tmp == "Emblems") 00666 mContext = KIconLoader::Emblem; 00667 else if (tmp == "Emotes") 00668 mContext = KIconLoader::Emote; 00669 else if (tmp == "International") 00670 mContext = KIconLoader::International; 00671 else if (tmp == "Places") 00672 mContext = KIconLoader::Place; 00673 else if (tmp == "Status") 00674 mContext = KIconLoader::StatusIcon; 00675 else if (tmp == "Stock") // invalid, but often present context, skip warning 00676 return; 00677 else { 00678 kDebug(264) << "Invalid Context=" << tmp << "line for icon theme: " << dir() << "\n"; 00679 return; 00680 } 00681 tmp = config.readEntry("Type"); 00682 if (tmp == "Fixed") 00683 mType = KIconLoader::Fixed; 00684 else if (tmp == "Scalable") 00685 mType = KIconLoader::Scalable; 00686 else if (tmp == "Threshold") 00687 mType = KIconLoader::Threshold; 00688 else { 00689 kDebug(264) << "Invalid Type=" << tmp << "line for icon theme: " << dir() << "\n"; 00690 return; 00691 } 00692 if (mType == KIconLoader::Scalable) { 00693 mMinSize = config.readEntry("MinSize", mSize); 00694 mMaxSize = config.readEntry("MaxSize", mSize); 00695 } else if (mType == KIconLoader::Threshold) { 00696 mThreshold = config.readEntry("Threshold", 2); 00697 } 00698 mbValid = true; 00699 } 00700 00701 QString KIconThemeDir::iconPath(const QString& name) const 00702 { 00703 if (!mbValid) { 00704 return QString(); 00705 } 00706 00707 QString file = dir() + '/' + name; 00708 00709 if (KDE::access(file, R_OK) == 0) { 00710 return KGlobal::hasLocale() ? KGlobal::locale()->localizedFilePath(file) : file; 00711 } 00712 00713 return QString(); 00714 } 00715 00716 QStringList KIconThemeDir::iconList() const 00717 { 00718 const QDir icondir = dir(); 00719 00720 const QStringList formats = QStringList() << "*.png" << "*.svg" << "*.svgz" << "*.xpm"; 00721 const QStringList lst = icondir.entryList( formats, QDir::Files); 00722 00723 QStringList result; 00724 QStringList::ConstIterator it; 00725 for (it=lst.begin(); it!=lst.end(); ++it) { 00726 result += dir() + '/' + *it; 00727 } 00728 return result; 00729 }
KDE 4.6 API Reference