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 KIconThemeDir *dir; 00435 00436 const int dirCount = d->mDirs.size(); 00437 00438 // Search the directory that contains the icon which matches best to the requested 00439 // size. If there is no directory which matches exactly to the requested size, the 00440 // following criterias get applied: 00441 // - Take a directory having icons with a minimum difference to the requested size. 00442 // - Prefer directories that allow a downscaling even if the difference to 00443 // the requested size is bigger than a directory where an upscaling is required. 00444 for (int i = 0; i < dirCount; ++i) { 00445 dir = d->mDirs.at(i); 00446 00447 if (match == KIconLoader::MatchExact) { 00448 if ((dir->type() == KIconLoader::Fixed) && (dir->size() != size)) { 00449 continue; 00450 } 00451 if ((dir->type() == KIconLoader::Scalable) && 00452 ((size < dir->minSize()) || (size > dir->maxSize()))) { 00453 continue; 00454 } 00455 if ((dir->type() == KIconLoader::Threshold) && 00456 (abs(dir->size() - size) > dir->threshold())) { 00457 continue; 00458 } 00459 } else { 00460 // dw < 0 means need to scale up to get an icon of the requested size. 00461 // Upscaling should only be done if no larger icon is available. 00462 if (dir->type() == KIconLoader::Fixed) { 00463 dw = dir->size() - size; 00464 } else if (dir->type() == KIconLoader::Scalable) { 00465 if (size < dir->minSize()) { 00466 dw = dir->minSize() - size; 00467 } else if (size > dir->maxSize()) { 00468 dw = dir->maxSize() - size; 00469 } else { 00470 dw = 0; 00471 } 00472 } else if (dir->type() == KIconLoader::Threshold) { 00473 if (size < dir->size() - dir->threshold()) { 00474 dw = dir->size() - dir->threshold() - size; 00475 } else if (size > dir->size() + dir->threshold()) { 00476 dw = dir->size() + dir->threshold() - size; 00477 } else { 00478 dw = 0; 00479 } 00480 } 00481 // Usually if the delta (= 'dw') of the current directory is 00482 // not smaller than the delta (= 'delta') of the currently best 00483 // matching icon, this candidate can be skipped. But skipping 00484 // the candidate may only be done, if this does not imply 00485 // in an upscaling of the icon (it is OK to use a directory with 00486 // smaller icons that what we've already found, however). 00487 if ((abs(dw) >= abs(delta)) && ((dw < 0) || (delta > 0))) { 00488 continue; 00489 } 00490 } 00491 00492 path = dir->iconPath(name); 00493 if (path.isEmpty()) { 00494 continue; 00495 } 00496 icon.path = path; 00497 // The following code has been commented out because the Qt SVG renderer needs 00498 // to be improved. If you are going to change/remove some code from this part, 00499 // please contact me before (ereslibre@kde.org), or kde-core-devel@kde.org. (ereslibre) 00500 #ifdef KDE_QT_SVG_RENDERER_FIXED 00501 icon.size = size; 00502 #else 00503 icon.size = dir->size(); 00504 #endif 00505 icon.type = dir->type(); 00506 icon.threshold = dir->threshold(); 00507 icon.context = dir->context(); 00508 00509 // if we got in MatchExact that far, we find no better 00510 if (match == KIconLoader::MatchExact) { 00511 return icon; 00512 } 00513 delta = dw; 00514 if (delta == 0) { 00515 return icon; // We won't find a better match anyway 00516 } 00517 } 00518 return icon; 00519 } 00520 00521 // static 00522 QString KIconTheme::current() 00523 { 00524 // Static pointer because of unloading problems wrt DSO's. 00525 if (!_theme->isEmpty()) { 00526 return *_theme; 00527 } 00528 00529 KConfigGroup cg(KGlobal::config(), "Icons"); 00530 *_theme = cg.readEntry("Theme", defaultThemeName()); 00531 if ( *_theme == QLatin1String("hicolor") ) { 00532 *_theme = defaultThemeName(); 00533 } 00534 /* if (_theme->isEmpty()) 00535 { 00536 if (QPixmap::defaultDepth() > 8) 00537 *_theme = defaultThemeName(); 00538 else 00539 *_theme = QLatin1String("locolor"); 00540 }*/ 00541 return *_theme; 00542 } 00543 00544 // static 00545 QStringList KIconTheme::list() 00546 { 00547 // Static pointer because of unloading problems wrt DSO's. 00548 if (!_theme_list->isEmpty()) { 00549 return *_theme_list; 00550 } 00551 00552 const QStringList icnlibs = KGlobal::dirs()->resourceDirs("icon") 00553 << KGlobal::dirs()->resourceDirs("xdgdata-icon") 00554 << "/usr/share/pixmaps" 00555 // These are not in the icon spec, but e.g. GNOME puts some icons there anyway. 00556 << KGlobal::dirs()->resourceDirs("xdgdata-pixmap"); 00557 00558 QStringList::ConstIterator it; 00559 for (it=icnlibs.begin(); it!=icnlibs.end(); ++it) { 00560 QDir dir(*it); 00561 if (!dir.exists()) { 00562 continue; 00563 } 00564 const QStringList lst = dir.entryList(QDir::Dirs); 00565 QStringList::ConstIterator it2; 00566 for (it2=lst.begin(); it2!=lst.end(); ++it2) { 00567 if ((*it2 == ".") || (*it2 == "..") || (*it2).startsWith(QLatin1String("default.")) ) { 00568 continue; 00569 } 00570 if (!KStandardDirs::exists(*it + *it2 + "/index.desktop") && !KStandardDirs::exists(*it + *it2 + "/index.theme")) { 00571 continue; 00572 } 00573 KIconTheme oink(*it2); 00574 if (!oink.isValid()) { 00575 continue; 00576 } 00577 00578 if (!_theme_list->contains(*it2)) { 00579 _theme_list->append(*it2); 00580 } 00581 } 00582 } 00583 return *_theme_list; 00584 } 00585 00586 // static 00587 void KIconTheme::reconfigure() 00588 { 00589 _theme->clear(); 00590 _theme_list->clear(); 00591 } 00592 00593 // static 00594 QString KIconTheme::defaultThemeName() 00595 { 00596 return QLatin1String("oxygen"); 00597 } 00598 00599 void KIconTheme::assignIconsToContextMenu( ContextMenus type, 00600 QList<QAction*> actions ) 00601 { 00602 switch (type) { 00603 // FIXME: This code depends on Qt's action ordering. 00604 case TextEditor: 00605 enum { UndoAct, RedoAct, Separator1, CutAct, CopyAct, PasteAct, DeleteAct, ClearAct, 00606 Separator2, SelectAllAct, NCountActs }; 00607 00608 if ( actions.count() < NCountActs ) { 00609 return; 00610 } 00611 00612 actions[UndoAct]->setIcon( KIcon("edit-undo") ); 00613 actions[RedoAct]->setIcon( KIcon("edit-redo") ); 00614 actions[CutAct]->setIcon( KIcon("edit-cut") ); 00615 actions[CopyAct]->setIcon( KIcon("edit-copy") ); 00616 actions[PasteAct]->setIcon( KIcon("edit-paste") ); 00617 actions[ClearAct]->setIcon( KIcon("edit-clear") ); 00618 actions[DeleteAct]->setIcon( KIcon("edit-delete") ); 00619 actions[SelectAllAct]->setIcon( KIcon("edit-select-all") ); 00620 break; 00621 00622 case ReadOnlyText: 00623 if ( actions.count() < 1 ) { 00624 return; 00625 } 00626 00627 actions[0]->setIcon( KIcon("edit-copy") ); 00628 break; 00629 } 00630 } 00631 00632 /*** KIconThemeDir ***/ 00633 00634 KIconThemeDir::KIconThemeDir(const QString& basedir, const QString &themedir, const KConfigGroup &config) 00635 { 00636 mbValid = false; 00637 mBaseDirThemeDir = basedir + themedir; 00638 00639 mSize = config.readEntry("Size", 0); 00640 mMinSize = 1; // just set the variables to something 00641 mMaxSize = 50; // meaningful in case someone calls minSize or maxSize 00642 mType = KIconLoader::Fixed; 00643 00644 if (mSize == 0) { 00645 return; 00646 } 00647 00648 QString tmp = config.readEntry("Context"); 00649 if (tmp == "Devices") 00650 mContext = KIconLoader::Device; 00651 else if (tmp == "MimeTypes") 00652 mContext = KIconLoader::MimeType; 00653 else if (tmp == "FileSystems") 00654 mContext = KIconLoader::FileSystem; 00655 else if (tmp == "Applications") 00656 mContext = KIconLoader::Application; 00657 else if (tmp == "Actions") 00658 mContext = KIconLoader::Action; 00659 else if (tmp == "Animations") 00660 mContext = KIconLoader::Animation; 00661 else if (tmp == "Categories") 00662 mContext = KIconLoader::Category; 00663 else if (tmp == "Emblems") 00664 mContext = KIconLoader::Emblem; 00665 else if (tmp == "Emotes") 00666 mContext = KIconLoader::Emote; 00667 else if (tmp == "International") 00668 mContext = KIconLoader::International; 00669 else if (tmp == "Places") 00670 mContext = KIconLoader::Place; 00671 else if (tmp == "Status") 00672 mContext = KIconLoader::StatusIcon; 00673 else if (tmp == "Stock") // invalid, but often present context, skip warning 00674 return; 00675 else { 00676 kDebug(264) << "Invalid Context=" << tmp << "line for icon theme: " << dir() << "\n"; 00677 return; 00678 } 00679 tmp = config.readEntry("Type"); 00680 if (tmp == "Fixed") 00681 mType = KIconLoader::Fixed; 00682 else if (tmp == "Scalable") 00683 mType = KIconLoader::Scalable; 00684 else if (tmp == "Threshold") 00685 mType = KIconLoader::Threshold; 00686 else { 00687 kDebug(264) << "Invalid Type=" << tmp << "line for icon theme: " << dir() << "\n"; 00688 return; 00689 } 00690 if (mType == KIconLoader::Scalable) { 00691 mMinSize = config.readEntry("MinSize", mSize); 00692 mMaxSize = config.readEntry("MaxSize", mSize); 00693 } else if (mType == KIconLoader::Threshold) { 00694 mThreshold = config.readEntry("Threshold", 2); 00695 } 00696 mbValid = true; 00697 } 00698 00699 QString KIconThemeDir::iconPath(const QString& name) const 00700 { 00701 if (!mbValid) { 00702 return QString(); 00703 } 00704 00705 QString file = dir() + '/' + name; 00706 00707 if (KDE::access(file, R_OK) == 0) { 00708 return KGlobal::hasLocale() ? KGlobal::locale()->localizedFilePath(file) : file; 00709 } 00710 00711 return QString(); 00712 } 00713 00714 QStringList KIconThemeDir::iconList() const 00715 { 00716 const QDir icondir = dir(); 00717 00718 const QStringList formats = QStringList() << "*.png" << "*.svg" << "*.svgz" << "*.xpm"; 00719 const QStringList lst = icondir.entryList( formats, QDir::Files); 00720 00721 QStringList result; 00722 QStringList::ConstIterator it; 00723 for (it=lst.begin(); it!=lst.end(); ++it) { 00724 result += dir() + '/' + *it; 00725 } 00726 return result; 00727 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:32:40 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:32:40 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.