22#include <tqstringlist.h>
23#include <tqvaluelist.h>
26#include <tqpixmapcache.h>
28#include <tqfileinfo.h>
32#include <tdestandarddirs.h>
35#include <ksimpleconfig.h>
38#include "kicontheme.h"
40class TDEIconThemePrivate
43 TQString example, screenshot;
44 TQString linkOverlay, lockOverlay, zipOverlay, shareOverlay;
55 TDEIconThemeDir(
const TQString& dir,
const TDEConfigBase *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 TDEIconThemePrivate;
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";
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",
"application-vnd.tde.overlay.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 TDEIconThemeDir *
dir =
new TDEIconThemeDir(*itDir + *it, &cfg);
174 kdDebug(264) <<
"Icon directory " << *itDir <<
" group " << *it <<
" not valid.\n";
185 TQMap<int,TQValueList<int> > scIcons;
186 for (TDEIconThemeDir *
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];
222TDEIconTheme::~TDEIconTheme()
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<TDEIconThemeDir> dirs(mDirs);
270 TDEIconThemeDir *
dir;
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 TDEIconThemeDir *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<TDEIconThemeDir> dirs(mDirs);
322 TDEIconThemeDir *
dir;
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<TDEIconThemeDir> dirs(mDirs);
350 TDEIconThemeDir *
dir;
352 for ( ; dirs.current(); ++dirs)
354 dir = dirs.current();
365 int delta = -1000, dw;
366 TDEIconThemeDir *
dir;
369 TQPtrListIterator<TDEIconThemeDir> 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;
438TQString *TDEIconTheme::_theme = 0L;
441TQStringList *TDEIconTheme::_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");
519TDEIconThemeDir::TDEIconThemeDir(
const TQString& dir,
const TDEConfigBase *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";
580TQString TDEIconThemeDir::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;
592TQStringList TDEIconThemeDir::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.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
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.
TQValueList< int > readIntListEntry(const TQString &pKey) const
Reads a list of Integers.
int readListEntry(const TQString &pKey, TQStrList &list, char sep=',') const
Reads a list of strings.
TQStringList readPathListEntry(const TQString &pKey, char sep=',') const
Reads a list of string paths.
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads a path.
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
Helper class to facilitate working with TDEConfig / KSimpleConfig groups.
Access KDE Configuration entries.
static TDEConfig * config()
Returns the general config object.
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
Class to use/access icon themes in KDE.
TQString name() const
The stylized name of the icon theme.
TDEIcon iconPath(const TQString &name, int size, TDEIcon::MatchType match) const
Lookup an icon in the theme.
TQString example() const
Return the name of the "example" icon.
static TQString current()
Returns the current icon theme.
TQValueList< int > querySizes(TDEIcon::Group group) const
Query available sizes for a group.
TQString linkOverlay() const
Returns the name of this theme's link overlay.
TQString shareOverlay() const
Returns the name of this theme's share overlay.
static void reconfigure()
Reconfigure the theme.
bool isValid() const
The icon theme exists?
bool hasContext(TDEIcon::Context context) const
Returns true if the theme has any icons for the given context.
bool isHidden() const
The icon theme should be hidden to the user?
TQStringList queryIconsByContext(int size, TDEIcon::Context context=TDEIcon::Any) const
Query available icons for a context and preferred size.
TQString zipOverlay() const
Returns the name of this theme's zip overlay.
static TQString defaultThemeName()
Returns the default icon theme.
TDEIconTheme(const TQString &name, const TQString &appName=TQString::null)
Load an icon theme by name.
static TQStringList list()
List all icon themes installed on the system, global and local.
TQString lockOverlay() const
Returns the name of this theme's lock overlay.
TQString screenshot() const
Return the name of the screenshot.
int defaultSize(TDEIcon::Group group) const
The default size of this theme for a certain icon group.
TQString dir() const
Returns the toplevel theme directory.
TQStringList queryIcons(int size, TDEIcon::Context context=TDEIcon::Any) const
Query available icons for a size and context.
One icon as found by TDEIconTheme.
Context context
The context of the icon.
TQString path
The full path of the icon.
Context
Defines the context of the icon.
@ Application
An icon that represents an application.
@ Emblem
An icon that adds information to an existing icon.
@ Device
An icon that represents a device.
@ International
An icon that represents a country's flag.
@ Any
Some icon with unknown purpose.
@ Place
An icon that represents a location (e.g. 'home', 'trash').
@ FileSystem
An icon that represents a file system.
@ Action
An action icon (e.g. 'save', 'print').
@ Category
An icon that represents a category.
@ Animation
An icon that is animated.
@ StatusIcon
An icon that represents an event.
@ MimeType
An icon that represents a mime type (or file type).
@ Emote
An icon that expresses an emotion.
Group
The group of the icon.
Type type
The type of the icon: Fixed, Scalable or Threshold.
int size
The size in pixels of the icon.
int threshold
The threshold in case type == Threshold.
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 TDESharedConfig::Ptr openConfig(const TQString &fileName, bool readOnly=false, bool bUseKDEGlobals=true)
Returns a ref-counted pointer to a shared read-write config object.
TQStringList resourceDirs(const char *type) const
This function is used internally by almost all other function as it serves and fills the directories ...
static bool exists(const TQString &fullPath)
Checks for existence and accessability of a file or directory.
kdbgstream kdDebug(int area=0)
Returns a debug stream.
const char * name(StdAction id)