22 #include <tqstringlist.h> 23 #include <tqvaluelist.h> 26 #include <tqpixmapcache.h> 28 #include <tqfileinfo.h> 32 #include <kstandarddirs.h> 33 #include <tdeglobal.h> 34 #include <tdeconfig.h> 35 #include <ksimpleconfig.h> 36 #include <kinstance.h> 38 #include "kicontheme.h" 40 class 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];
222 TDEIconTheme::~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();
277 if ((context !=
TDEIcon::Any) && (context != dir->context()))
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();
304 if ((context !=
TDEIcon::Any) && (context != dir->context()))
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();
335 if ((context !=
TDEIcon::Any) && (context != dir->context()))
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();
355 if ((context ==
TDEIcon::Any) || (context == dir->context()))
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))
416 path = dir->iconPath(name);
420 icon.
size = dir->size();
421 icon.
type = dir->type();
431 if (delta==0)
return icon;
438 TQString *TDEIconTheme::_theme = 0L;
441 TQStringList *TDEIconTheme::_theme_list = 0L;
450 _theme =
new TQString();
453 *_theme = config->
readEntry(
"Theme",defaultThemeName());
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 TDEIconThemeDir::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";
580 TQString 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;
592 TQStringList 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;
bool isHidden() const
The icon theme should be hidden to the user?
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads a path.
Access KDE Configuration entries.
static TQString defaultThemeName()
Returns the default icon theme.
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.
TQString path
The full path of the icon.
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
Helper class to facilitate working with TDEConfig / KSimpleConfig groups.
TQValueList< int > readIntListEntry(const TQString &pKey) const
Reads a list of Integers.
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
static TQString current()
Returns the current icon theme.
TQString screenshot() const
Return the name of the screenshot.
TQString zipOverlay() const
Returns the name of this theme's zip overlay.
An action icon (e.g. 'save', 'print').
static TQStringList list()
List all icon themes installed on the system, global and local.
TQStringList queryIcons(int size, TDEIcon::Context context=TDEIcon::Any) const
Query available icons for a size and context.
int readListEntry(const TQString &pKey, TQStrList &list, char sep=',') const
Reads a list of strings.
An icon that represents a device.
An icon that is animated.
Only try to find an exact match.
KDE Configuration Management abstract base class.
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
An icon that adds information to an existing icon.
Type
The type of the icon.
An icon that represents a category.
Class to use/access icon themes in KDE.
Context
Defines the context of the icon.
MatchType
The type of a match.
One icon as found by TDEIconTheme.
An icon that represents a location (e.g. 'home', 'trash').
An icon that represents a country's flag.
An icon that represents a file system.
An icon that represents an event.
static void reconfigure()
Reconfigure the theme.
int defaultSize(TDEIcon::Group group) const
The default size of this theme for a certain icon group.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
Some icon with unknown purpose.
Type type
The type of the icon: Fixed, Scalable or Threshold.
TQStringList readPathListEntry(const TQString &pKey, char sep=',') const
Reads a list of string paths.
TQString lockOverlay() const
Returns the name of this theme's lock overlay.
TQString linkOverlay() const
Returns the name of this theme's link overlay.
bool hasContext(TDEIcon::Context context) const
Returns true if the theme has any icons for the given context.
TDEIconTheme(const TQString &name, const TQString &appName=TQString::null)
Load an icon theme by name.
Group
The group of the icon.
Context context
The context of the icon.
TQString example() const
Return the name of the "example" icon.
TQStringList queryIconsByContext(int size, TDEIcon::Context context=TDEIcon::Any) const
Query available icons for a context and preferred size.
int threshold
The threshold in case type == Threshold.
bool isValid() const
The icon theme exists?
int size
The size in pixels of the icon.
TQValueList< int > querySizes(TDEIcon::Group group) const
Query available sizes for a group.
TQString shareOverlay() const
Returns the name of this theme's share overlay.
An icon that expresses an emotion.
static TDEConfig * config()
Returns the general config object.
An icon that represents an application.
int readNumEntry(const TQString &pKey, int nDefault=0) const
Reads a numerical value.
TDEIcon iconPath(const TQString &name, int size, TDEIcon::MatchType match) const
Lookup an icon in the theme.
Can be used to control the lifetime of an object that has derived TDEShared.
An icon that represents a mime type (or file type).
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.