31#include <QtGui/QAction>
32#include <QtCore/QCharRef>
33#include <QtCore/QMutableStringListIterator>
36#include <QtGui/QPixmap>
37#include <QtGui/QPixmapCache>
38#include <QtGui/QImage>
39#include <QtCore/QFileInfo>
56#undef KDE_QT_SVG_RENDERER_FIXED
58class KIconTheme::KIconThemePrivate
61 QString example, screenshot;
62 QString linkOverlay, lockOverlay, zipOverlay, shareOverlay;
70 QString mDir, mName, mInternalName, mDesc;
71 QStringList mInherits;
83 KIconThemeDir(
const QString& basedir,
const QString &themedir,
const KConfigGroup &config);
85 bool isValid()
const {
return mbValid; }
86 QString iconPath(
const QString& name)
const;
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;
104 QString mBaseDirThemeDir;
119bool K3Icon::isValid()
const
128 :d(new KIconThemePrivate)
131 d->mInternalName = name;
134 QStringList::ConstIterator it, itDir;
135 QStringList themeDirs;
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();
161 QString fileName, mainSection;
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);
193 d->mInherits = cfg.
readEntry(
"Inherits", QStringList());
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();
399 QStringList iconlist[128];
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();
412 QStringList iconlistResult;
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) {
564 const QStringList lst = dir.entryList(QDir::Dirs);
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") );
634KIconThemeDir::KIconThemeDir(
const QString& basedir,
const QString &themedir,
const KConfigGroup &config)
637 mBaseDirThemeDir = basedir + themedir;
639 mSize =
config.readEntry(
"Size", 0);
648 QString tmp =
config.readEntry(
"Context");
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";
679 tmp =
config.readEntry(
"Type");
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);
699QString KIconThemeDir::iconPath(
const QString& name)
const
705 QString file = dir() +
'/' +
name;
714QStringList KIconThemeDir::iconList()
const
716 const QDir icondir = dir();
718 const QStringList formats = QStringList() <<
"*.png" <<
"*.svg" <<
"*.svgz" <<
"*.xpm";
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;
QString readPathEntry(const char *key, const QString &aDefault) const
QString readEntry(const char *key, const char *aDefault=0) const
Group
The group of the icon.
Context
Defines the context of the icon.
@ Category
An icon that represents a category.
@ Emblem
An icon that adds information to an existing icon.
@ StatusIcon
An icon that represents an event.
@ Application
An icon that represents an application.
@ FileSystem
An icon that represents a file system.
@ Emote
An icon that expresses an emotion.
@ Any
Some icon with unknown purpose.
@ Place
An icon that represents a location (e.g. 'home', 'trash').
@ MimeType
An icon that represents a mime type (or file type).
@ Action
An action icon (e.g. 'save', 'print').
@ International
An icon that represents a country's flag.
@ Animation
An icon that is animated.
@ Device
An icon that represents a device.
Type
The type of the icon.
@ Scalable
Scalable-size icon.
@ Threshold
A threshold icon.
MatchType
The type of a match.
@ MatchExact
Only try to find an exact match.
static QStringList list()
List all icon themes installed on the system, global and local.
bool isValid() const
The icon theme exists?
QList< int > querySizes(KIconLoader::Group group) const
Query available sizes for a group.
ContextMenus
Defines the context menus that assignIconsToContextMenus is aware of.
QString internalName() const
The internal name of the icon theme (same as the name argument passed to the constructor).
QString screenshot() const
Return the name of the screenshot.
static void reconfigure()
Reconfigure the theme.
bool isHidden() const
The icon theme should be hidden to the user?
QStringList queryIconsByContext(int size, KIconLoader::Context context=KIconLoader::Any) const
Query available icons for a context and preferred size.
QString description() const
A description for the icon theme.
static QString current()
Returns the current icon theme.
QString dir() const
Returns the toplevel theme directory.
bool hasContext(KIconLoader::Context context) const
Returns true if the theme has any icons for the given context.
K3Icon iconPath(const QString &name, int size, KIconLoader::MatchType match) const
Lookup an icon in the theme.
QString name() const
The stylized name of the icon theme.
KIconTheme(const QString &name, const QString &appName=QString())
Load an icon theme by name.
QStringList inherits() const
The themes this icon theme falls back on.
QString example() const
Return the name of the "example" icon.
QStringList queryIcons(int size, KIconLoader::Context context=KIconLoader::Any) const
Query available icons for a size and context.
int defaultSize(KIconLoader::Group group) const
The default size of this theme for a certain icon group.
static void assignIconsToContextMenu(ContextMenus type, QList< QAction * > actions)
Assigns standard icons to the various standard text edit context menus.
static QString defaultThemeName()
Returns the default icon theme.
int depth() const
The minimum display depth required for this theme.
A wrapper around QIcon that provides KDE icon features.
QString localizedFilePath(const QString &filePath) const
static KSharedConfig::Ptr openConfig(const KComponentData &componentData, const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
static bool exists(const QString &fullPath)
QStringList resourceDirs(const char *type) const
#define K_GLOBAL_STATIC(TYPE, NAME)
int access(const QString &path, int mode)
KSharedConfigPtr config()
const char * name(StandardAction id)
This will return the internal name of a given standard action.