22 #include <tqstringlist.h>
23 #include <tqvaluelist.h>
26 #include <tqpixmapcache.h>
28 #include <tqfileinfo.h>
32 #include <kstandarddirs.h>
35 #include <ksimpleconfig.h>
36 #include <kinstance.h>
38 #include "kicontheme.h"
40 class KIconThemePrivate
43 TQString example, screenshot;
44 TQString linkOverlay, lockOverlay, zipOverlay, shareOverlay;
55 KIconThemeDir(
const TQString& dir,
const KConfigBase *config);
57 bool isValid()
const {
return mbValid; }
58 TQString iconPath(
const TQString& name)
const;
59 TQStringList iconList()
const;
60 TQString dir()
const {
return mDir; }
64 int size()
const {
return mSize; }
65 int minSize()
const {
return mMinSize; }
66 int maxSize()
const {
return mMaxSize; }
67 int threshold()
const {
return mThreshold; }
73 int mSize, mMinSize, mMaxSize;
84 d =
new KIconThemePrivate;
87 TQStringList::ConstIterator it, itDir;
88 TQStringList themeDirs;
95 if (!appName.isEmpty() &&
96 (
name ==
"crystalsvg" ||
name==
"hicolor" ||
name ==
"locolor" ) )
99 for (it=icnlibs.begin(); it!=icnlibs.end(); ++it)
101 cDir = *it + appName +
"/icons/" +
name;
102 if (TQFile::exists( cDir ))
103 themeDirs += cDir +
"/";
110 icnlibs +=
"/usr/share/pixmaps";
113 for (it=icnlibs.begin(); it!=icnlibs.end(); ++it)
115 cDir = *it +
name +
"/";
127 kdDebug(264) <<
"Icon theme " <<
name <<
" not found.\n";
131 TQString fileName, mainSection;
132 if(TQFile::exists(mDir +
"index.desktop")) {
133 fileName = mDir +
"index.desktop";
134 mainSection=
"KDE Icon Theme";
136 fileName = mDir +
"index.theme";
137 mainSection=
"Icon Theme";
142 KConfig& cfg = *d->sharedConfig;
150 if (
name !=
"crystalsvg" )
151 for ( TQStringList::Iterator it = mInherits.begin(); it != mInherits.end(); ++it )
152 if ( *it ==
"default" || *it ==
"hicolor" ) *it=
"crystalsvg";
157 d->linkOverlay = cfg.
readEntry(
"LinkOverlay",
"link");
158 d->lockOverlay = cfg.
readEntry(
"LockOverlay",
"lock");
159 d->zipOverlay = cfg.
readEntry(
"ZipOverlay",
"zip");
160 d->shareOverlay = cfg.
readEntry(
"ShareOverlay",
"share");
163 mDirs.setAutoDelete(
true);
164 for (it=dirs.begin(); it!=dirs.end(); ++it)
167 for (itDir=themeDirs.begin(); itDir!=themeDirs.end(); ++itDir)
171 KIconThemeDir *
dir =
new KIconThemeDir(*itDir + *it, &cfg);
174 kdDebug(264) <<
"Icon directory " << *itDir <<
" group " << *it <<
" not valid.\n";
185 TQMap<int,TQValueList<int> > scIcons;
186 for (KIconThemeDir *
dir=mDirs.first();
dir!=0L;
dir=mDirs.next())
190 TQValueList<int> lst;
191 for (i=
dir->minSize(); i<=dir->maxSize(); i++)
193 scIcons[
dir->size()] = lst;
200 groups +=
"MainToolbar";
203 const int defDefSizes[] = { 32, 22, 22, 16, 32 };
205 for (it=groups.begin(), i=0; it!=groups.end(); ++it, i++)
207 mDefSize[i] = cfg.
readNumEntry(*it +
"Default", defDefSizes[i]);
209 TQValueList<int>::ConstIterator it2;
210 for (it2=lst.begin(); it2!=lst.end(); ++it2)
212 if (scIcons.contains(*it2))
213 exp += scIcons[*it2];
222 KIconTheme::~KIconTheme()
229 return !mDirs.isEmpty();
248 kdDebug(264) <<
"Illegal icon group: " << group <<
"\n";
251 return mDefSize[group];
256 TQValueList<int> empty;
259 kdDebug(264) <<
"Illegal icon group: " << group <<
"\n";
262 return mSizes[group];
267 int delta = 1000, dw;
269 TQPtrListIterator<KIconThemeDir> dirs(mDirs);
274 for ( ; dirs.current(); ++dirs)
276 dir = dirs.current();
281 result +=
dir->iconList();
285 (size >=
dir->minSize()) && (size <= dir->maxSize()))
287 result +=
dir->iconList();
291 (abs(size-
dir->size())<
dir->threshold()))
292 result+=
dir->iconList();
300 KIconThemeDir *best = 0L;
301 for ( ; dirs.current(); ++dirs)
303 dir = dirs.current();
306 dw =
dir->size() - size;
307 if ((dw > 6) || (abs(dw) >= abs(delta)))
313 return TQStringList();
315 return best->iconList();
320 TQPtrListIterator<KIconThemeDir> dirs(mDirs);
327 TQStringList iconlist[128];
332 for ( ; dirs.current(); ++dirs)
334 dir = dirs.current();
337 dw = abs(
dir->size() - size);
338 iconlist[(dw<127)?dw:127]+=
dir->iconList();
341 TQStringList iconlistResult;
342 for (
int i=0; i<128; i++) iconlistResult+=iconlist[i];
344 return iconlistResult;
349 TQPtrListIterator<KIconThemeDir> dirs(mDirs);
352 for ( ; dirs.current(); ++dirs)
354 dir = dirs.current();
365 int delta = -1000, dw;
369 TQPtrListIterator<KIconThemeDir> dirs(mDirs);
370 for ( ; dirs.current(); ++dirs)
372 dir = dirs.current();
379 ((size < dir->minSize()) || (size >
dir->maxSize())))
382 (abs(
dir->size()-size) >
dir->threshold()))
389 dw =
dir->size() - size;
392 if (size < dir->minSize())
393 dw =
dir->minSize() - size;
394 else if (size >
dir->maxSize())
395 dw =
dir->maxSize() - size;
400 if (size < dir->size() -
dir->threshold())
401 dw =
dir->size() -
dir->threshold() - size;
402 else if (size >
dir->size() +
dir->threshold())
403 dw =
dir->size() +
dir->threshold() - size;
412 (delta > 0 && dw < 0))
431 if (delta==0)
return icon;
438 TQString *KIconTheme::_theme = 0L;
441 TQStringList *KIconTheme::_theme_list = 0L;
450 _theme =
new TQString();
454 if ( *_theme == TQString::fromLatin1(
"hicolor") ) *_theme =
defaultThemeName();
469 if (_theme_list != 0L)
472 _theme_list =
new TQStringList();
475 icnlibs +=
"/usr/share/pixmaps";
478 TQStringList::ConstIterator it;
479 for (it=icnlibs.begin(); it!=icnlibs.end(); ++it)
484 TQStringList lst =
dir.entryList(TQDir::Dirs);
485 TQStringList::ConstIterator it2;
486 for (it2=lst.begin(); it2!=lst.end(); ++it2)
488 if ((*it2 ==
".") || (*it2 ==
"..") || (*it2).startsWith(
"default.") )
495 if (!_theme_list->contains(*it2))
496 _theme_list->append(*it2);
514 return TQString::fromLatin1(
"crystalsvg");
519 KIconThemeDir::KIconThemeDir(
const TQString& dir,
const KConfigBase *config)
531 TQString tmp = config->
readEntry(
"Context");
532 if (tmp ==
"Devices")
534 else if (tmp ==
"MimeTypes")
536 else if (tmp ==
"FileSystems")
538 else if (tmp ==
"Applications")
540 else if (tmp ==
"Actions")
542 else if (tmp ==
"Animations")
544 else if (tmp ==
"Categories")
546 else if (tmp ==
"Emblems")
548 else if (tmp ==
"Emotes")
550 else if (tmp ==
"International")
552 else if (tmp ==
"Places")
554 else if (tmp ==
"Status")
557 kdDebug(264) <<
"Invalid Context= line for icon theme: " << mDir <<
"\n";
563 else if (tmp ==
"Scalable")
565 else if (tmp ==
"Threshold")
568 kdDebug(264) <<
"Invalid Type= line for icon theme: " << mDir <<
"\n";
580 TQString KIconThemeDir::iconPath(
const TQString& name)
const
583 return TQString::null;
584 TQString file = mDir +
"/" +
name;
586 if (access(TQFile::encodeName(file), R_OK) == 0)
589 return TQString::null;
592 TQStringList KIconThemeDir::iconList()
const
596 TQStringList lst = dir.entryList(
"*.png;*.svg;*.svgz;*.xpm", TQDir::Files);
598 TQStringList lst = dir.entryList(
"*.png;*.xpm", TQDir::Files);
601 TQStringList::ConstIterator it;
602 for (it=lst.begin(); it!=lst.end(); ++it)
603 result += mDir +
"/" + *it;
KDE Configuration Management abstract base class.
int readListEntry(const TQString &pKey, TQStrList &list, char sep=',') const
Reads a list of strings.
TQValueList< int > readIntListEntry(const TQString &pKey) const
Reads a list of Integers.
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads a path.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
TQStringList readPathListEntry(const TQString &pKey, char sep=',') const
Reads a list of string paths.
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
int readNumEntry(const TQString &pKey, int nDefault=0) const
Reads a numerical value.
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
Helper class to facilitate working with KConfig / KSimpleConfig groups.
Access KDE Configuration entries.
static KStandardDirs * dirs()
Returns the application standard dirs object.
static KConfig * config()
Returns the general config object.
Class to use/access icon themes in KDE.
bool isValid() const
The icon theme exists?
TQStringList queryIcons(int size, KIcon::Context context=KIcon::Any) const
Query available icons for a size and context.
TQString shareOverlay() const
Returns the name of this theme's share overlay.
KIcon iconPath(const TQString &name, int size, KIcon::MatchType match) const
Lookup an icon in the theme.
static TQString defaultThemeName()
Returns the default icon theme.
TQString lockOverlay() const
Returns the name of this theme's lock overlay.
TQString dir() const
Returns the toplevel theme directory.
TQStringList queryIconsByContext(int size, KIcon::Context context=KIcon::Any) const
Query available icons for a context and preferred size.
static void reconfigure()
Reconfigure the theme.
int defaultSize(KIcon::Group group) const
The default size of this theme for a certain icon group.
TQString zipOverlay() const
Returns the name of this theme's zip overlay.
bool isHidden() const
The icon theme should be hidden to the user?
bool hasContext(KIcon::Context context) const
Returns true if the theme has any icons for the given context.
TQString screenshot() const
Return the name of the screenshot.
TQString example() const
Return the name of the "example" icon.
TQString linkOverlay() const
Returns the name of this theme's link overlay.
static TQStringList list()
List all icon themes installed on the system, global and local.
static TQString current()
Returns the current icon theme.
TQString name() const
The stylized name of the icon theme.
KIconTheme(const TQString &name, const TQString &appName=TQString::null)
Load an icon theme by name.
TQValueList< int > querySizes(KIcon::Group group) const
Query available sizes for a group.
One icon as found by KIconTheme.
Type type
The type of the icon: Fixed, Scalable or Threshold.
int size
The size in pixels of the icon.
Group
The group of the icon.
MatchType
The type of a match.
@ MatchExact
Only try to find an exact match.
int threshold
The threshold in case type == Threshold.
Type
The type of the icon.
@ Scalable
Scalable-size icon.
@ Threshold
A threshold icon.
TQString path
The full path of the icon.
Context
Defines the context of the icon.
@ MimeType
An icon that represents a mime type (or file type).
@ Category
An icon that represents a category.
@ Action
An action icon (e.g. 'save', 'print').
@ Place
An icon that represents a location (e.g. 'home', 'trash').
@ Emote
An icon that expresses an emotion.
@ Device
An icon that represents a device.
@ StatusIcon
An icon that represents an event.
@ International
An icon that represents a country's flag.
@ Application
An icon that represents an application.
@ Animation
An icon that is animated.
@ FileSystem
An icon that represents a file system.
@ Any
Some icon with unknown purpose.
@ Emblem
An icon that adds information to an existing icon.
Context context
The context of the icon.
static KSharedConfig::Ptr openConfig(const TQString &fileName, bool readOnly=false, bool bUseKDEGlobals=true)
Returns a ref-counted pointer to a shared read-write config object.
static bool exists(const TQString &fullPath)
Checks for existence and accessability of a file or directory.
TQStringList resourceDirs(const char *type) const
This function is used internally by almost all other function as it serves and fills the directories ...
kdbgstream kdDebug(int area=0)
Returns a debug stream.
const char * name(StdAction id)