31 #include <QtGui/QAction>
32 #include <QtCore/QCharRef>
33 #include <QtCore/QMutableStringListIterator>
34 #include <QtCore/QMap>
35 #include <QtCore/QSet>
36 #include <QtGui/QPixmap>
37 #include <QtGui/QPixmapCache>
38 #include <QtGui/QImage>
39 #include <QtCore/QFileInfo>
40 #include <QtCore/QDir>
56 #undef KDE_QT_SVG_RENDERER_FIXED
58 class KIconTheme::KIconThemePrivate
62 QString linkOverlay, lockOverlay, zipOverlay, shareOverlay;
70 QString mDir, mName, mInternalName, mDesc;
85 bool isValid()
const {
return mbValid; }
87 QStringList iconList()
const;
88 QString dir()
const {
return mBaseDirThemeDir; }
92 int size()
const {
return mSize; }
93 int minSize()
const {
return mMinSize; }
94 int maxSize()
const {
return mMaxSize; }
95 int threshold()
const {
return mThreshold; }
101 int mSize, mMinSize, mMaxSize;
119 bool K3Icon::isValid()
const
128 :d(new KIconThemePrivate)
131 d->mInternalName =
name;
134 QStringList::ConstIterator it, itDir;
142 if (!appName.isEmpty() &&
145 for (it=icnlibs.constBegin(); it!=icnlibs.constEnd(); ++it) {
146 const QString cDir = *it + appName +
"/icons/" +
name;
147 if (QFile::exists( cDir )) {
148 themeDirs += cDir +
'/';
156 <<
"/usr/share/pixmaps/"
159 icnlibs.removeDuplicates();
162 for (it=icnlibs.constBegin(); it!=icnlibs.constEnd(); ++it) {
163 const QString cDir = *it + name +
'/';
166 if (d->mDir.isEmpty()) {
169 fileName = d->mDir +
"index.theme";
170 mainSection =
"Icon Theme";
173 fileName = d->mDir +
"index.desktop";
174 mainSection =
"KDE Icon Theme";
180 if (d->mDir.isEmpty()) {
181 kDebug(264) <<
"Icon theme" << name <<
"not found.";
192 d->mDepth = cfg.
readEntry(
"DisplayDepth", 32);
195 for (QStringList::Iterator it = d->mInherits.begin(); it != d->mInherits.end(); ++it) {
196 if (*it ==
"default" || *it ==
"hicolor") {
202 d->hidden = cfg.
readEntry(
"Hidden",
false);
207 for (it=dirs.begin(); it!=dirs.end(); ++it) {
209 for (itDir=themeDirs.constBegin(); itDir!=themeDirs.constEnd(); ++itDir) {
210 const QString currentDir(*itDir + *it +
'/');
212 addedDirs.insert(currentDir);
213 KIconThemeDir *
dir =
new KIconThemeDir(*itDir, *it, cg);
214 if (!dir->isValid()) {
218 d->mDirs.append(dir);
227 foreach(KIconThemeDir *
dir, d->mDirs) {
233 for (i=dir->minSize(); i<=dir->maxSize(); ++i) {
236 scIcons[dir->size()] = lst;
243 groups +=
"MainToolbar";
247 const int defDefSizes[] = { 32, 22, 22, 16, 32, 32 };
249 for (it=groups.constBegin(), i=0; it!=groups.constEnd(); ++it, i++) {
250 d->mDefSize[i] = cg.
readEntry(*it +
"Default", defDefSizes[i]);
254 for (it2=lst.begin(); it2!=lst.end(); ++it2) {
255 if (scIcons.contains(*it2)) {
256 exp += scIcons[*it2];
267 qDeleteAll(d->mDirs);
278 return d->mInternalName;
293 return d->screenshot;
308 return !d->mDirs.isEmpty();
324 kDebug(264) <<
"Illegal icon group: " << group <<
"\n";
327 return d->mDefSize[group];
334 kDebug(264) <<
"Illegal icon group: " << group <<
"\n";
337 return d->mSizes[group];
346 for (
int i=0; i<d->mDirs.size(); ++i) {
347 dir = d->mDirs.at(i);
351 result += dir->iconList();
355 (size >= dir->minSize()) && (size <= dir->maxSize())) {
356 result += dir->iconList();
360 (abs(size-dir->size())<dir->threshold())) {
361 result+=dir->iconList();
404 for (
int i=0;i<d->mDirs.size();++i) {
405 dir = d->mDirs.at(i);
408 dw = abs(dir->size() - size);
409 iconlist[(dw<127)?dw:127]+=dir->iconList();
413 for (
int i=0; i<128; i++) iconlistResult+=iconlist[i];
415 return iconlistResult;
420 foreach(KIconThemeDir *
dir, d->mDirs) {
432 int delta = -INT_MAX;
436 const int dirCount = d->mDirs.size();
444 for (
int i = 0; i < dirCount; ++i) {
445 dir = d->mDirs.at(i);
452 ((size < dir->minSize()) || (size > dir->maxSize()))) {
456 (abs(dir->size() - size) > dir->threshold())) {
463 dw = dir->size() - size;
465 if (size < dir->minSize()) {
466 dw = dir->minSize() - size;
467 }
else if (size > dir->maxSize()) {
468 dw = dir->maxSize() - size;
473 if (size < dir->size() - dir->threshold()) {
474 dw = dir->size() - dir->threshold() - size;
475 }
else if (size > dir->size() + dir->threshold()) {
476 dw = dir->size() + dir->threshold() - size;
487 if ((abs(dw) >= abs(delta)) && ((dw < 0) || (delta > 0))) {
492 path = dir->iconPath(name);
493 if (path.isEmpty()) {
500 #ifdef KDE_QT_SVG_RENDERER_FIXED
503 icon.size = dir->size();
505 icon.type = dir->type();
506 icon.threshold = dir->threshold();
507 icon.context = dir->context();
525 if (!_theme->isEmpty()) {
531 if ( *_theme == QLatin1String(
"hicolor") ) {
548 if (!_theme_list->isEmpty()) {
554 <<
"/usr/share/pixmaps"
558 QStringList::ConstIterator it;
559 for (it=icnlibs.begin(); it!=icnlibs.end(); ++it) {
565 QStringList::ConstIterator it2;
566 for (it2=lst.begin(); it2!=lst.end(); ++it2) {
567 if ((*it2 ==
".") || (*it2 ==
"..") || (*it2).startsWith(QLatin1String(
"default.")) ) {
578 if (!_theme_list->contains(*it2)) {
579 _theme_list->append(*it2);
590 _theme_list->clear();
596 return QLatin1String(
"oxygen");
605 enum { UndoAct, RedoAct, Separator1, CutAct, CopyAct, PasteAct, DeleteAct, ClearAct,
606 Separator2, SelectAllAct, NCountActs };
608 if ( actions.count() < NCountActs ) {
612 actions[UndoAct]->setIcon(
KIcon(
"edit-undo") );
613 actions[RedoAct]->setIcon(
KIcon(
"edit-redo") );
614 actions[CutAct]->setIcon(
KIcon(
"edit-cut") );
615 actions[CopyAct]->setIcon(
KIcon(
"edit-copy") );
616 actions[PasteAct]->setIcon(
KIcon(
"edit-paste") );
617 actions[ClearAct]->setIcon(
KIcon(
"edit-clear") );
618 actions[DeleteAct]->setIcon(
KIcon(
"edit-delete") );
619 actions[SelectAllAct]->setIcon(
KIcon(
"edit-select-all") );
623 if ( actions.count() < 1 ) {
627 actions[0]->setIcon(
KIcon(
"edit-copy") );
637 mBaseDirThemeDir = basedir + themedir;
649 if (tmp ==
"Devices")
651 else if (tmp ==
"MimeTypes")
653 else if (tmp ==
"FileSystems")
655 else if (tmp ==
"Applications")
657 else if (tmp ==
"Actions")
659 else if (tmp ==
"Animations")
661 else if (tmp ==
"Categories")
663 else if (tmp ==
"Emblems")
665 else if (tmp ==
"Emotes")
667 else if (tmp ==
"International")
669 else if (tmp ==
"Places")
671 else if (tmp ==
"Status")
673 else if (tmp ==
"Stock")
676 kDebug(264) <<
"Invalid Context=" << tmp <<
"line for icon theme: " << dir() <<
"\n";
682 else if (tmp ==
"Scalable")
684 else if (tmp ==
"Threshold")
687 kDebug(264) <<
"Invalid Type=" << tmp <<
"line for icon theme: " << dir() <<
"\n";
691 mMinSize = config.
readEntry(
"MinSize", mSize);
692 mMaxSize = config.
readEntry(
"MaxSize", mSize);
694 mThreshold = config.
readEntry(
"Threshold", 2);
716 const QDir icondir = dir();
719 const QStringList lst = icondir.entryList( formats, QDir::Files);
722 QStringList::ConstIterator it;
723 for (it=lst.begin(); it!=lst.end(); ++it) {
724 result += dir() +
'/' + *it;
static void reconfigure()
Reconfigure the theme.
QString screenshot() const
Return the name of the screenshot.
QString readPathEntry(const QString &pKey, const QString &aDefault) const
An icon that represents a mime type (or file type).
int defaultSize(KIconLoader::Group group) const
The default size of this theme for a certain icon group.
An icon that represents an event.
QString localizedFilePath(const QString &filePath) const
bool isHidden() const
The icon theme should be hidden to the user?
bool isValid() const
The icon theme exists?
An icon that expresses an emotion.
int depth() const
The minimum display depth required for this theme.
#define K_GLOBAL_STATIC(TYPE, NAME)
KIconTheme(const QString &name, const QString &appName=QString())
Load an icon theme by name.
K3Icon iconPath(const QString &name, int size, KIconLoader::MatchType match) const
Lookup an icon in the theme.
const char * name(StandardAction id)
This will return the internal name of a given standard action.
QString dir() const
Returns the toplevel theme directory.
ContextMenus
Defines the context menus that assignIconsToContextMenus is aware of.
An icon that represents a location (e.g. 'home', 'trash').
An icon that is animated.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static bool exists(const QString &fullPath)
KSharedConfigPtr config()
QList< int > querySizes(KIconLoader::Group group) const
Query available sizes for a group.
An icon that represents a country's flag.
Some icon with unknown purpose.
An icon that represents a category.
An icon that represents a file system.
A wrapper around QIcon that provides KDE icon features.
bool hasContext(KIconLoader::Context context) const
Returns true if the theme has any icons for the given context.
An action icon (e.g. 'save', 'print').
Type
The type of the icon.
QStringList inherits() const
The themes this icon theme falls back on.
QStringList queryIconsByContext(int size, KIconLoader::Context context=KIconLoader::Any) const
Query available icons for a context and preferred size.
QString example() const
Return the name of the "example" icon.
QStringList resourceDirs(const char *type) const
MatchType
The type of a match.
QStringList queryIcons(int size, KIconLoader::Context context=KIconLoader::Any) const
Query available icons for a size and context.
An icon that represents an application.
An icon that represents a device.
int access(const QString &path, int mode)
Context
Defines the context of the icon.
Only try to find an exact match.
Group
The group of the icon.
static QString defaultThemeName()
Returns the default icon theme.
QString description() const
A description for the icon theme.
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
static void assignIconsToContextMenu(ContextMenus type, QList< QAction * > actions)
Assigns standard icons to the various standard text edit context menus.
QString name() const
The stylized name of the icon theme.
T readEntry(const QString &key, const T &aDefault) const
static QString current()
Returns the current icon theme.
QString internalName() const
The internal name of the icon theme (same as the name argument passed to the constructor).
An icon that adds information to an existing icon.
static QStringList list()
List all icon themes installed on the system, global and local.