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())
188 if ((dir->type() ==
KIcon::Scalable) && !scIcons.contains(dir->size()))
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();
277 if ((context !=
KIcon::Any) && (context != dir->context()))
279 if ((dir->type() ==
KIcon::Fixed) && (dir->size() == size))
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();
304 if ((context !=
KIcon::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<KIconThemeDir> dirs(mDirs);
327 TQStringList iconlist[128];
332 for ( ; dirs.current(); ++dirs)
334 dir = dirs.current();
335 if ((context !=
KIcon::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<KIconThemeDir> dirs(mDirs);
352 for ( ; dirs.current(); ++dirs)
354 dir = dirs.current();
355 if ((context ==
KIcon::Any) || (context == dir->context()))
365 int delta = -1000, dw;
369 TQPtrListIterator<KIconThemeDir> dirs(mDirs);
370 for ( ; dirs.current(); ++dirs)
372 dir = dirs.current();
376 if ((dir->type() ==
KIcon::Fixed) && (dir->size() != size))
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 *KIconTheme::_theme = 0L;
441 TQStringList *KIconTheme::_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 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;
KIconTheme(const TQString &name, const TQString &appName=TQString::null)
Load an icon theme by name.
static void reconfigure()
Reconfigure the theme.
Can be used to control the lifetime of an object that has derived KShared.
int defaultSize(KIcon::Group group) const
The default size of this theme for a certain icon group.
TQStringList readPathListEntry(const TQString &pKey, char sep= ',') const
Reads a list of string paths.
bool isHidden() const
The icon theme should be hidden to the user?
Some icon with unknown purpose.
An icon that represents an event.
bool isValid() const
The icon theme exists?
Group
The group of the icon.
TQString example() const
Return the name of the "example" icon.
An icon that adds information to an existing icon.
int size
The size in pixels of the icon.
An icon that represents an application.
TQValueList< int > readIntListEntry(const TQString &pKey) const
Reads a list of Integers.
KIcon iconPath(const TQString &name, int size, KIcon::MatchType match) const
Lookup an icon in the theme.
An icon that is animated.
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
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.
TQString screenshot() const
Return the name of the screenshot.
Only try to find an exact match.
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
static KStandardDirs * dirs()
Returns the application standard dirs object.
An icon that represents a mime type (or file type).
An icon that represents a country's flag.
Context context
The context of the icon.
One icon as found by KIconTheme.
Type type
The type of the icon: Fixed, Scalable or Threshold.
bool hasContext(KIcon::Context context) const
Returns true if the theme has any icons for the given context.
Helper class to facilitate working with KConfig / KSimpleConfig groups.
KDE Configuration Management abstract base class.
An icon that represents a location (e.g. 'home', 'trash').
An icon that represents a file system.
TQString linkOverlay() const
Returns the name of this theme's link overlay.
static TQString defaultThemeName()
Returns the default icon theme.
Context
Defines the context of the icon.
int threshold
The threshold in case type == Threshold.
Type
The type of the icon.
TQStringList queryIconsByContext(int size, KIcon::Context context=KIcon::Any) const
Query available icons for a context and preferred size.
Access KDE Configuration entries.
An icon that represents a device.
int readNumEntry(const TQString &pKey, int nDefault=0) const
Reads a numerical value.
TQString path
The full path of the icon.
MatchType
The type of a match.
static TQString current()
Returns the current icon theme.
static bool exists(const TQString &fullPath)
Checks for existence and accessability of a file or directory.
TQString zipOverlay() const
Returns the name of this theme's zip overlay.
TQString lockOverlay() const
Returns the name of this theme's lock overlay.
An icon that expresses an emotion.
An icon that represents a category.
TQStringList queryIcons(int size, KIcon::Context context=KIcon::Any) const
Query available icons for a size and context.
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.
TQStringList resourceDirs(const char *type) const
This function is used internally by almost all other function as it serves and fills the directories ...
Class to use/access icon themes in KDE.
static KConfig * config()
Returns the general config object.
An action icon (e.g. 'save', 'print').
static TQStringList list()
List all icon themes installed on the system, global and local.
int readListEntry(const TQString &pKey, TQStrList &list, char sep= ',') const
Reads a list of strings.
TQValueList< int > querySizes(KIcon::Group group) const
Query available sizes for a group.
TQString shareOverlay() const
Returns the name of this theme's share overlay.