Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KIconTheme (./kdelibs/kdecore/kicontheme.h:67)
class KIconTheme
{
public:
/** Load an icon theme by name. */
KIconTheme(QString name, QString appName=QString::null);
~KIconTheme();
/** The stylized name of the icont theme. */
QString name() { return mName; }
/** A description for the icon theme. */
QString description() { return mDesc; }
/** Return the name of the "example" icon. */
QString example() { return d->example; }
/** Return the name of the screenshot. */
QString screenshot() { return d->screenshot; }
/** Returns the toplevel theme directory. */
QString dir() { return mDir; }
/** The themes this icon theme falls back on. */
QStringList inherits() { return mInherits; }
/** The icon theme exists? */
bool isValid();
/** The mimimum display depth required for this theme. This can either
* be 8 or 32 */
int depth() { return mDepth; }
/** The default size of this theme for a certain icon group.
* @param group The icon group. See @ref #KIcon::Group.
* @return The default size in pixels for the given icon group.
*/
int defaultSize(int group);
/** Query available sizes for a group. */
QValueList<int> querySizes(int group);
/** Query available icons for a size and context. */
QStringList queryIcons(int size, int context = KIcon::Any);
/** Lookup an icon in the theme.
* @param name The name of the icon, without extension.
* @param size The desired size of the icon.
* @param match The matching mode. KIcon::MatchExact returns an icon
* only if matches exactly. KIcon::MatchBest returns the best matching
* icon.
* @return A KIcon class that describes the icon. If an icon is found,
* @ref #KIcon::isValid will return true, and false otherwise.
*/
KIcon iconPath(QString name, int size, int match);
/** List all icon themes installed on the system, global and local. */
static QStringList list();
/** Returns the current icon theme. */
static QString current();
private:
int mDefSize[8];
QValueList<int> mSizes[8];
int mDepth;
QString mDir, mName, mDesc;
QStringList mInherits;
QList<KIconThemeDir> mDirs;
KIconThemePrivate *d;
};
kdelibs'KIconTheme::KIconTheme() (./kdelibs/kdecore/kicontheme.cpp:67)
KIconTheme::KIconTheme(QString name, QString appName)
{
d = new KIconThemePrivate;
bool isApp = !appName.isEmpty();
if (isApp && (name != "hicolor") && (name != "locolor"))
{
kdDebug(264) << "Only hicolor and locolor themes can be local.\n";
return;
}
QStringList icnlibs = KGlobal::dirs()->resourceDirs("icon");
QStringList::ConstIterator it;
for (it=icnlibs.begin(); it!=icnlibs.end(); it++)
{
QFileInfo fi(*it + name + "/index.desktop");
if (fi.exists())
break;
}
if (it == icnlibs.end())
{
kdDebug(264) << "Icon theme " << name << " not found.\n";
return;
}
mDir = *it + name + "/";
KConfig *cfg = new KSimpleConfig(mDir + "index.desktop");
cfg->setGroup("KDE Icon Theme");
mName = cfg->readEntry("Name");
mDesc = cfg->readEntry("Description");
mDepth = cfg->readNumEntry("DisplayDepth", 32);
mInherits = cfg->readListEntry("Inherits");
d->example = cfg->readEntry("Example");
d->screenshot = cfg->readEntry("ScreenShot");
if (isApp)
{
// We just read the global theme description file. This is intended
// for app specific themes too.
icnlibs = KGlobal::dirs()->resourceDirs("data");
for (it=icnlibs.begin(); it!=icnlibs.end(); it++)
{
QFileInfo fi(*it + appName + "/icons/" + name);
if (fi.exists())
break;
}
if (it == icnlibs.end())
return;
mDir = *it + appName + "/icons/" + name + "/";
mName += "-";
mName += appName;
}
QStringList dirs = cfg->readListEntry("Directories");
mDirs.setAutoDelete(true);
for (it=dirs.begin(); it!=dirs.end(); it++)
{
cfg->setGroup(*it);
mDirs.append(new KIconThemeDir(mDir + *it, cfg));
}
// Expand available sizes for scalable icons to their full range
int i;
QMap<int,QValueList<int> > scIcons;
for (KIconThemeDir *dir=mDirs.first(); dir!=0L; dir=mDirs.next())
{
if ((dir->type() == KIcon::Scalable) && !scIcons.contains(dir->size()))
{
QValueList<int> lst;
for (i=dir->minSize(); i<=dir->maxSize(); i++)
lst += i;
scIcons[dir->size()] = lst;
}
}
QStringList groups;
groups += "Desktop";
groups += "Toolbar";
groups += "MainToolbar";
groups += "Small";
cfg->setGroup("KDE Icon Theme");
for (it=groups.begin(), i=0; it!=groups.end(); it++, i++)
{
mDefSize[i] = cfg->readNumEntry(*it + "Default", 32);
QValueList<int> lst = cfg->readIntListEntry(*it + "Sizes"), exp;
QValueList<int>::Iterator it2;
for (it2=lst.begin(); it2!=lst.end(); it2++)
{
if (scIcons.contains(*it2))
exp += scIcons[*it2];
else
exp += *it2;
}
mSizes[i] = exp;
}
delete cfg;
}
kdelibs'KIconTheme::~KIconTheme() (./kdelibs/kdecore/kicontheme.cpp:163)
KIconTheme::~KIconTheme()
{
delete d;
}
kdelibs'KIconTheme::isValid() (./kdelibs/kdecore/kicontheme.cpp:168)
bool KIconTheme::isValid()
{
return !mDirs.isEmpty();
}
kdelibs'KIconTheme::defaultSize() (./kdelibs/kdecore/kicontheme.cpp:173)
int KIconTheme::defaultSize(int group)
{
if ((group < 0) || (group >= KIcon::LastGroup))
{
kdDebug(264) << "Illegal icon group: " << group << "\n";
return -1;
}
return mDefSize[group];
}
kdelibs'KIconTheme::querySizes() (./kdelibs/kdecore/kicontheme.cpp:183)
QValueList<int> KIconTheme::querySizes(int group)
{
QValueList<int> empty;
if ((group < 0) || (group >= KIcon::LastGroup))
{
kdDebug(264) << "Illegal icon group: " << group << "\n";
return empty;
}
return mSizes[group];
}
kdelibs'KIconTheme::queryIcons() (./kdelibs/kdecore/kicontheme.cpp:194)
QStringList KIconTheme::queryIcons(int size, int context)
{
int delta = 1000, dw;
KIconThemeDir *dir;
// Try to find exact match
for (dir=mDirs.first(); dir!=0L; dir=mDirs.next())
{
if ((context != KIcon::Any) && (context != dir->context()))
continue;
if ((dir->type() == KIcon::Fixed) && (dir->size() == size))
return dir->iconList();
if ((dir->type() == KIcon::Scalable) &&
(size >= dir->minSize()) && (size <= dir->maxSize()))
return dir->iconList();
}
// Find close match
KIconThemeDir *best = 0L;
for (dir=mDirs.first(); dir!=0L; dir=mDirs.next())
{
if ((context != KIcon::Any) && (context != dir->context()))
continue;
dw = abs(dir->size() - size);
if (dw >= QMIN(7,delta))
continue;
delta = dw;
best = dir;
}
if (best == 0L)
return QStringList();
return best->iconList();
}
kdelibs'KIconTheme::iconPath() (./kdelibs/kdecore/kicontheme.cpp:228)
KIcon KIconTheme::iconPath(QString name, int size, int match)
{
KIcon icon;
QString path;
int delta = 1000, dw;
KIconThemeDir *dir;
for (dir=mDirs.first(); dir!=0L; dir=mDirs.next())
{
if (match == KIcon::MatchExact)
{
if ((dir->type() == KIcon::Fixed) && (dir->size() != size))
continue;
if ((dir->type() == KIcon::Scalable) &&
((size < dir->minSize()) || (size > dir->maxSize())))
continue;
} else
{
dw = abs(dir->size() - size);
if (dw >= QMIN(7,delta))
continue;
}
path = dir->iconPath(name);
if (path.isEmpty())
continue;
icon.path = path;
icon.size = dir->size();
icon.type = dir->type();
icon.context = dir->context();
if (match == KIcon::MatchExact)
break;
else
delta = dw;
}
return icon;
}
// static
kdelibs'KIconTheme::current() (./kdelibs/kdecore/kicontheme.cpp:267)
QString KIconTheme::current()
{
KConfig *config = KGlobal::config();
KConfigGroupSaver saver(config, "Icons");
QString theme = config->readEntry("Theme");
if (theme.isEmpty())
{
if (QPixmap::defaultDepth() > 8)
theme = QString::fromLatin1("hicolor");
else
theme = QString::fromLatin1("locolor");
}
return theme;
}
// static
kdelibs'KIconTheme::list() (./kdelibs/kdecore/kicontheme.cpp:283)
QStringList KIconTheme::list()
{
QStringList result;
QStringList icnlibs = KGlobal::dirs()->resourceDirs("icon");
QStringList::ConstIterator it;
for (it=icnlibs.begin(); it!=icnlibs.end(); it++)
{
QDir dir(*it);
if (!dir.exists())
continue;
QStringList lst = dir.entryList(QDir::Dirs);
QStringList::ConstIterator it2;
QFileInfo fi;
for (it2=lst.begin(); it2!=lst.end(); it2++)
{
if ((*it2 == ".") || (*it2 == ".."))
continue;
fi.setFile(*it + *it2 + "/index.desktop");
if (!fi.exists())
continue;
if (!result.contains(*it2))
result += *it2;
}
}
return result;
}
/*** KIconThemeDir ***/