• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kiconloader.cpp
1/*
2 *
3 * $Id$
4 *
5 * This file is part of the KDE project, module tdecore.
6 * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
7 * Antonio Larrosa <larrosa@kde.org>
8 *
9 * This is free software; it comes under the GNU Library General
10 * Public License, version 2. See the file "COPYING.LIB" for the
11 * exact licensing terms.
12 *
13 * kiconloader.cpp: An icon loader for KDE with theming functionality.
14 */
15
16#include <tqstring.h>
17#include <tqstringlist.h>
18#include <tqptrlist.h>
19#include <tqintdict.h>
20#include <tqpixmap.h>
21#include <tqpixmapcache.h>
22#include <tqimage.h>
23#include <tqfileinfo.h>
24#include <tqdir.h>
25#include <tqiconset.h>
26#include <tqmovie.h>
27#include <tqbitmap.h>
28
29#include <tdeapplication.h>
30#include <kipc.h>
31#include <kdebug.h>
32#include <tdestandarddirs.h>
33#include <tdeglobal.h>
34#include <tdeconfig.h>
35#include <ksimpleconfig.h>
36#include <kinstance.h>
37
38#include <kicontheme.h>
39#include <kiconloader.h>
40#include <kiconeffect.h>
41
42#include <sys/types.h>
43#include <stdlib.h> //for abs
44#include <unistd.h> //for readlink
45#include <dirent.h>
46#include <config.h>
47#include <assert.h>
48
49#ifdef HAVE_LIBART
50#include "svgicons/ksvgiconengine.h"
51#include "svgicons/ksvgiconpainter.h"
52#endif
53
54#include <kimageeffect.h>
55
56#include "kiconloader_p.h"
57
58/*** TDEIconThemeNode: A node in the icon theme dependancy tree. ***/
59
60TDEIconThemeNode::TDEIconThemeNode(TDEIconTheme *_theme)
61{
62 theme = _theme;
63}
64
65TDEIconThemeNode::~TDEIconThemeNode()
66{
67 delete theme;
68}
69
70void TDEIconThemeNode::printTree(TQString& dbgString) const
71{
72 /* This method doesn't have much sense anymore, so maybe it should
73 be removed in the (near?) future */
74 dbgString += "(";
75 dbgString += theme->name();
76 dbgString += ")";
77}
78
79void TDEIconThemeNode::queryIcons(TQStringList *result,
80 int size, TDEIcon::Context context) const
81{
82 // add the icons of this theme to it
83 *result += theme->queryIcons(size, context);
84}
85
86void TDEIconThemeNode::queryIconsByContext(TQStringList *result,
87 int size, TDEIcon::Context context) const
88{
89 // add the icons of this theme to it
90 *result += theme->queryIconsByContext(size, context);
91}
92
93TDEIcon TDEIconThemeNode::findIcon(const TQString& name, int size,
94 TDEIcon::MatchType match) const
95{
96 return theme->iconPath(name, size, match);
97}
98
99
100/*** TDEIconGroup: Icon type description. ***/
101
102struct TDEIconGroup
103{
104 int size;
105 bool dblPixels;
106 bool alphaBlending;
107};
108
109// WARNING
110// Enabling this in production will cause a massive slowdown of (and a related memory leak in)
111// any application that creates and destroys large numbers of TDEIconLoader instances
112//#define TDEICONLOADER_DEBUG
113
114#ifdef TDEICONLOADER_DEBUG
115// Keep a list of recently created and destroyed TDEIconLoader instances in order
116// to detect bugs like #68528.
117struct TDEIconLoaderDebug
118 {
119 TDEIconLoaderDebug( TDEIconLoader* l, const TQString& a )
120 : loader( l ), appname( a ), valid( true )
121 {}
122 TDEIconLoaderDebug() {}; // this TQValueList feature annoys me
123 TDEIconLoader* loader;
124 TQString appname;
125 bool valid;
126 TQString delete_bt;
127 };
128
129static TQValueList< TDEIconLoaderDebug > *kiconloaders;
130#endif
131
132/*** TDEIconLoader: the icon loader ***/
133
134TDEIconLoader::TDEIconLoader(const TQString& _appname, TDEStandardDirs *_dirs)
135{
136#ifdef TDEICONLOADER_DEBUG
137 if( kiconloaders == NULL )
138 kiconloaders = new TQValueList< TDEIconLoaderDebug>();
139 // check for the (very unlikely case) that new TDEIconLoader gets allocated
140 // at exactly same address like some previous one
141 for( TQValueList< TDEIconLoaderDebug >::Iterator it = kiconloaders->begin();
142 it != kiconloaders->end();
143 )
144 {
145 if( (*it).loader == this )
146 it = kiconloaders->remove( it );
147 else
148 ++it;
149 }
150 kiconloaders->append( TDEIconLoaderDebug( this, _appname ));
151#endif
152 d = new TDEIconLoaderPrivate;
153 d->q = this;
154 d->mpGroups = 0L;
155 d->imgDict.setAutoDelete(true);
156 d->links.setAutoDelete(true);
157
158 if (tdeApp) {
159 tdeApp->addKipcEventMask(KIPC::IconChanged);
160 TQObject::connect(tdeApp, TQ_SIGNAL(updateIconLoaders()), d, TQ_SLOT(reconfigure()));
161 }
162
163 init( _appname, _dirs );
164}
165
166void TDEIconLoader::reconfigure( const TQString& _appname, TDEStandardDirs *_dirs )
167{
168 d->links.clear();
169 d->imgDict.clear();
170 d->mThemesInTree.clear();
171 d->lastImage.reset();
172 d->lastImageKey = TQString::null;
173 delete [] d->mpGroups;
174
175 init( _appname, _dirs );
176}
177
178void TDEIconLoader::init( const TQString& _appname, TDEStandardDirs *_dirs )
179{
180 // If this is unequal to 0, the iconloader is initialized
181 // successfully.
182 d->mpThemeRoot = 0L;
183
184 d->appname = _appname;
185 d->extraDesktopIconsLoaded = false;
186 d->delayedLoading = false;
187
188 if (_dirs)
189 d->mpDirs = _dirs;
190 else
191 d->mpDirs = TDEGlobal::dirs();
192
193 TQString appname = _appname;
194 if (appname.isEmpty())
195 appname = TDEGlobal::instance()->instanceName();
196
197 // Add the default theme and its base themes to the theme tree
198 TDEIconTheme *def = new TDEIconTheme(TDEIconTheme::current(), appname);
199 if (!def->isValid())
200 {
201 delete def;
202 // warn, as this is actually a small penalty hit
203 kdDebug(264) << "Couldn't find current icon theme, falling back to default." << endl;
204 def = new TDEIconTheme(TDEIconTheme::defaultThemeName(), appname);
205 if (!def->isValid())
206 {
207 kdError(264) << "Error: standard icon theme"
208 << " \"" << TDEIconTheme::defaultThemeName() << "\" "
209 << " not found!" << endl;
210 d->mpGroups=0L;
211 return;
212 }
213 }
214 d->mpThemeRoot = new TDEIconThemeNode(def);
215 d->links.append(d->mpThemeRoot);
216 d->mThemesInTree += TDEIconTheme::current();
217 addBaseThemes(d->mpThemeRoot, appname);
218
219 // These have to match the order in kicontheme.h
220 static const char * const groups[] = { "Desktop", "Toolbar", "MainToolbar", "Small", "Panel", 0L };
221 TDEConfig *config = TDEGlobal::config();
222 TDEConfigGroupSaver cs(config, "dummy");
223
224 // loading config and default sizes
225 d->mpGroups = new TDEIconGroup[(int) TDEIcon::LastGroup];
226 for (TDEIcon::Group i=TDEIcon::FirstGroup; i<TDEIcon::LastGroup; i++)
227 {
228 if (groups[i] == 0L)
229 break;
230 config->setGroup(TQString::fromLatin1(groups[i]) + "Icons");
231 d->mpGroups[i].size = config->readNumEntry("Size", 0);
232 d->mpGroups[i].dblPixels = config->readBoolEntry("DoublePixels", false);
233 if (TQPixmap::defaultDepth()>8)
234 d->mpGroups[i].alphaBlending = config->readBoolEntry("AlphaBlending", true);
235 else
236 d->mpGroups[i].alphaBlending = false;
237
238 if (!d->mpGroups[i].size)
239 d->mpGroups[i].size = d->mpThemeRoot->theme->defaultSize(i);
240 }
241
242 // Insert application specific themes at the top.
243 d->mpDirs->addResourceType("appicon", TDEStandardDirs::kde_default("data") +
244 appname + "/pics/");
245 // ################## KDE4: consider removing the toolbar directory
246 d->mpDirs->addResourceType("appicon", TDEStandardDirs::kde_default("data") +
247 appname + "/toolbar/");
248
249 // Add legacy icon dirs.
250 TQStringList dirs;
251 dirs += d->mpDirs->resourceDirs("icon");
252 dirs += d->mpDirs->resourceDirs("pixmap");
253 dirs += d->mpDirs->resourceDirs("xdgdata-icon");
254 dirs += "/usr/share/pixmaps";
255 // These are not in the icon spec, but e.g. GNOME puts some icons there anyway.
256 dirs += d->mpDirs->resourceDirs("xdgdata-pixmap");
257 for (TQStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it)
258 d->mpDirs->addResourceDir("appicon", *it);
259
260#ifndef NDEBUG
261 TQString dbgString = "Theme tree: ";
262 d->mpThemeRoot->printTree(dbgString);
263 kdDebug(264) << dbgString << endl;
264#endif
265}
266
267TDEIconLoader::~TDEIconLoader()
268{
269#ifdef TDEICONLOADER_DEBUG
270 for( TQValueList< TDEIconLoaderDebug >::Iterator it = kiconloaders->begin();
271 it != kiconloaders->end();
272 ++it )
273 {
274 if( (*it).loader == this )
275 {
276 (*it).valid = false;
277 (*it).delete_bt = kdBacktrace();
278 break;
279 }
280 }
281#endif
282 /* antlarr: There's no need to delete d->mpThemeRoot as it's already
283 deleted when the elements of d->links are deleted */
284 d->mpThemeRoot=0;
285 delete[] d->mpGroups;
286 delete d;
287}
288
289void TDEIconLoader::enableDelayedIconSetLoading( bool enable )
290{
291 d->delayedLoading = enable;
292}
293
294bool TDEIconLoader::isDelayedIconSetLoadingEnabled() const
295{
296 return d->delayedLoading;
297}
298
299void TDEIconLoader::addAppDir(const TQString& appname)
300{
301 d->mpDirs->addResourceType("appicon", TDEStandardDirs::kde_default("data") +
302 appname + "/pics/");
303 // ################## KDE4: consider removing the toolbar directory
304 d->mpDirs->addResourceType("appicon", TDEStandardDirs::kde_default("data") +
305 appname + "/toolbar/");
306 addAppThemes(appname);
307}
308
309void TDEIconLoader::addAppThemes(const TQString& appname)
310{
311 if ( TDEIconTheme::current() != TDEIconTheme::defaultThemeName() )
312 {
313 TDEIconTheme *def = new TDEIconTheme(TDEIconTheme::current(), appname);
314 if (def->isValid())
315 {
316 TDEIconThemeNode* node = new TDEIconThemeNode(def);
317 d->links.append(node);
318 addBaseThemes(node, appname);
319 }
320 else
321 delete def;
322 }
323
324 TDEIconTheme *def = new TDEIconTheme(TDEIconTheme::defaultThemeName(), appname);
325 TDEIconThemeNode* node = new TDEIconThemeNode(def);
326 d->links.append(node);
327 addBaseThemes(node, appname);
328}
329
330void TDEIconLoader::addBaseThemes(TDEIconThemeNode *node, const TQString &appname)
331{
332 TQStringList lst = node->theme->inherits();
333 TQStringList::ConstIterator it;
334
335 for (it=lst.begin(); it!=lst.end(); ++it)
336 {
337 if( d->mThemesInTree.contains(*it) && (*it) != "hicolor")
338 continue;
339 TDEIconTheme *theme = new TDEIconTheme(*it,appname);
340 if (!theme->isValid()) {
341 delete theme;
342 continue;
343 }
344 TDEIconThemeNode *n = new TDEIconThemeNode(theme);
345 d->mThemesInTree.append(*it);
346 d->links.append(n);
347 addBaseThemes(n, appname);
348 }
349}
350
351void TDEIconLoader::addExtraDesktopThemes()
352{
353 if ( d->extraDesktopIconsLoaded ) return;
354
355 TQStringList list;
356 TQStringList icnlibs = TDEGlobal::dirs()->resourceDirs("icon");
357 TQStringList::ConstIterator it;
358 char buf[1000];
359 int r;
360 for (it=icnlibs.begin(); it!=icnlibs.end(); ++it)
361 {
362 TQDir dir(*it);
363 if (!dir.exists())
364 continue;
365 TQStringList lst = dir.entryList("default.*", TQDir::Dirs);
366 TQStringList::ConstIterator it2;
367 for (it2=lst.begin(); it2!=lst.end(); ++it2)
368 {
369 if (!TDEStandardDirs::exists(*it + *it2 + "/index.desktop")
370 && !TDEStandardDirs::exists(*it + *it2 + "/index.theme"))
371 continue;
372 r=readlink( TQFile::encodeName(*it + *it2) , buf, sizeof(buf)-1);
373 if ( r>0 )
374 {
375 buf[r]=0;
376 TQDir dir2( buf );
377 TQString themeName=dir2.dirName();
378
379 if (!list.contains(themeName))
380 list.append(themeName);
381 }
382 }
383 }
384
385 for (it=list.begin(); it!=list.end(); ++it)
386 {
387 if ( d->mThemesInTree.contains(*it) )
388 continue;
389 if ( *it == TQString("default.tde") ) continue;
390
391 TDEIconTheme *def = new TDEIconTheme( *it, "" );
392 TDEIconThemeNode* node = new TDEIconThemeNode(def);
393 d->mThemesInTree.append(*it);
394 d->links.append(node);
395 addBaseThemes(node, "" );
396 }
397
398 d->extraDesktopIconsLoaded=true;
399
400}
401
402bool TDEIconLoader::extraDesktopThemesAdded() const
403{
404 return d->extraDesktopIconsLoaded;
405}
406
407TQString TDEIconLoader::removeIconExtension(const TQString &name) const
408{
409 int extensionLength=0;
410
411 TQString ext = name.right(4);
412
413 static const TQString &png_ext = TDEGlobal::staticQString(".png");
414 static const TQString &xpm_ext = TDEGlobal::staticQString(".xpm");
415 if (ext == png_ext || ext == xpm_ext)
416 extensionLength=4;
417#ifdef HAVE_LIBART
418 else
419 {
420 static const TQString &svgz_ext = TDEGlobal::staticQString(".svgz");
421 static const TQString &svg_ext = TDEGlobal::staticQString(".svg");
422
423 if (name.right(5) == svgz_ext)
424 extensionLength=5;
425 else if (ext == svg_ext)
426 extensionLength=4;
427 }
428#endif
429
430 if ( extensionLength > 0 )
431 {
432 return name.left(name.length() - extensionLength);
433 }
434 return name;
435}
436
437TQString TDEIconLoader::removeIconExtensionInternal(const TQString &name) const
438{
439 TQString name_noext = removeIconExtension(name);
440
441#ifndef NDEBUG
442 if (name != name_noext)
443 {
444 kdDebug(264) << "Application " << TDEGlobal::instance()->instanceName()
445 << " loads icon " << name << " with extension." << endl;
446 }
447#endif
448
449 return name_noext;
450}
451
452TDEIcon TDEIconLoader::findMatchingIcon(const TQString& name, int size) const
453{
454 TDEIcon icon;
455
456 const TQString *ext[4];
457 int count=0;
458 static const TQString &png_ext = TDEGlobal::staticQString(".png");
459 ext[count++]=&png_ext;
460#ifdef HAVE_LIBART
461 static const TQString &svgz_ext = TDEGlobal::staticQString(".svgz");
462 ext[count++]=&svgz_ext;
463 static const TQString &svg_ext = TDEGlobal::staticQString(".svg");
464 ext[count++]=&svg_ext;
465#endif
466 static const TQString &xpm_ext = TDEGlobal::staticQString(".xpm");
467 ext[count++]=&xpm_ext;
468
469 /* JRT: To follow the XDG spec, the order in which we look for an
470 icon 1s:
471
472 png, svgz, svg, xpm exact match
473 png, svgz, svg, xpm best match
474 next theme in inheritance tree : png, svgz, svg, xpm exact match
475 png, svgz, svg, xpm best match
476 next theme in inheritance tree : png, svgz, svg, xpm exact match
477 png, svgz, svg, xpm best match
478 and so on
479
480 */
481 for ( TDEIconThemeNode *themeNode = d->links.first() ; themeNode ;
482 themeNode = d->links.next() )
483 {
484 for (int i = 0 ; i < count ; i++)
485 {
486 icon = themeNode->theme->iconPath(name + *ext[i], size, TDEIcon::MatchExact);
487 if (icon.isValid()) goto icon_found ;
488 }
489
490 for (int i = 0 ; i < count ; i++)
491 {
492 icon = themeNode->theme->iconPath(name + *ext[i], size, TDEIcon::MatchBest);
493 if (icon.isValid()) goto icon_found;
494 }
495 }
496 icon_found:
497 return icon;
498}
499
500inline TQString TDEIconLoader::unknownIconPath( int size ) const
501{
502 static const TQString &str_unknown = TDEGlobal::staticQString("unknown");
503
504 TDEIcon icon = findMatchingIcon(str_unknown, size);
505 if (!icon.isValid())
506 {
507 kdDebug(264) << "Warning: could not find \"Unknown\" icon for size = "
508 << size << endl;
509 return TQString::null;
510 }
511 return icon.path;
512}
513
514// Finds the absolute path to an icon.
515
516TQString TDEIconLoader::iconPath(const TQString& _name, int group_or_size,
517 bool canReturnNull) const
518{
519 if (d->mpThemeRoot == 0L)
520 return TQString::null;
521
522 if (!TQDir::isRelativePath(_name))
523 return _name;
524
525 TQString name = removeIconExtensionInternal( _name );
526
527 TQString path;
528 if (group_or_size == TDEIcon::User)
529 {
530 static const TQString &png_ext = TDEGlobal::staticQString(".png");
531 static const TQString &xpm_ext = TDEGlobal::staticQString(".xpm");
532 path = d->mpDirs->findResource("appicon", name + png_ext);
533
534#ifdef HAVE_LIBART
535 static const TQString &svgz_ext = TDEGlobal::staticQString(".svgz");
536 static const TQString &svg_ext = TDEGlobal::staticQString(".svg");
537 if (path.isEmpty())
538 path = d->mpDirs->findResource("appicon", name + svgz_ext);
539 if (path.isEmpty())
540 path = d->mpDirs->findResource("appicon", name + svg_ext);
541#endif
542 if (path.isEmpty())
543 path = d->mpDirs->findResource("appicon", name + xpm_ext);
544 return path;
545 }
546
547 if (group_or_size >= TDEIcon::LastGroup)
548 {
549 kdDebug(264) << "Illegal icon group: " << group_or_size << endl;
550 return path;
551 }
552
553 int size;
554 if (group_or_size >= 0)
555 size = d->mpGroups[group_or_size].size;
556 else
557 size = -group_or_size;
558
559 if (_name.isEmpty()) {
560 if (canReturnNull)
561 return TQString::null;
562 else
563 return unknownIconPath(size);
564 }
565
566 TDEIcon icon = findMatchingIcon(name, size);
567
568 if (!icon.isValid())
569 {
570 // Try "User" group too.
571 path = iconPath(name, TDEIcon::User, true);
572 if (!path.isEmpty() || canReturnNull)
573 return path;
574
575 if (canReturnNull)
576 return TQString::null;
577 else
578 return unknownIconPath(size);
579 }
580 return icon.path;
581}
582
583TQPixmap TDEIconLoader::loadIcon(const TQString& _name, TDEIcon::Group group, int size,
584 int state, TQString *path_store, bool canReturnNull) const
585{
586 TQString name = _name;
587 TQPixmap pix;
588 TQString key;
589 bool absolutePath=false, favIconOverlay=false;
590
591 if (d->mpThemeRoot == 0L)
592 return pix;
593
594 // Special case for absolute path icons.
595 if (name.startsWith("favicons/"))
596 {
597 favIconOverlay = true;
598 name = locateLocal("cache", name+".png");
599 }
600 if (!TQDir::isRelativePath(name)) absolutePath=true;
601
602 static const TQString &str_unknown = TDEGlobal::staticQString("unknown");
603
604 // Special case for "User" icons.
605 if (group == TDEIcon::User)
606 {
607 key = "$kicou_";
608 key += TQString::number(size); key += '_';
609 key += name;
610 bool inCache = TQPixmapCache::find(key, pix);
611 if (inCache && (path_store == 0L))
612 return pix;
613
614 TQString path = (absolutePath) ? name :
615 iconPath(name, TDEIcon::User, canReturnNull);
616 if (path.isEmpty())
617 {
618 if (canReturnNull)
619 return pix;
620 // We don't know the desired size: use small
621 path = iconPath(str_unknown, TDEIcon::Small, true);
622 if (path.isEmpty())
623 {
624 kdDebug(264) << "Warning: Cannot find \"unknown\" icon." << endl;
625 return pix;
626 }
627 }
628
629 if (path_store != 0L)
630 *path_store = path;
631 if (inCache)
632 return pix;
633 TQImage img(path);
634 if (size != 0)
635 img=img.smoothScale(size,size);
636
637 pix.convertFromImage(img);
638 TQPixmapCache::insert(key, pix);
639 return pix;
640 }
641
642 // Regular case: Check parameters
643
644 if ((group < -1) || (group >= TDEIcon::LastGroup))
645 {
646 kdDebug(264) << "Illegal icon group: " << group << endl;
647 group = TDEIcon::Desktop;
648 }
649
650 int overlay = (state & TDEIcon::OverlayMask);
651 state &= ~TDEIcon::OverlayMask;
652 if ((state < 0) || (state >= TDEIcon::LastState))
653 {
654 kdDebug(264) << "Illegal icon state: " << state << endl;
655 state = TDEIcon::DefaultState;
656 }
657
658 if (size == 0 && group < 0)
659 {
660 kdDebug(264) << "Neither size nor group specified!" << endl;
661 group = TDEIcon::Desktop;
662 }
663
664 if (!absolutePath)
665 {
666 if (!canReturnNull && name.isEmpty())
667 name = str_unknown;
668 else
669 name = removeIconExtensionInternal(name);
670 }
671
672 // If size == 0, use default size for the specified group.
673 if (size == 0)
674 {
675 size = d->mpGroups[group].size;
676 }
677 favIconOverlay = favIconOverlay && size > 22;
678
679 // Generate a unique cache key for the icon.
680
681 key = "$kico_";
682 key += name; key += '_';
683 key += TQString::number(size); key += '_';
684
685 TQString overlayStr = TQString::number( overlay );
686
687 TQString noEffectKey = key + '_' + overlayStr;
688
689 if (group >= 0)
690 {
691 key += d->mpEffect.fingerprint(group, state);
692 if (d->mpGroups[group].dblPixels)
693 key += TQString::fromLatin1(":dblsize");
694 } else
695 key += TQString::fromLatin1("noeffect");
696 key += '_';
697 key += overlayStr;
698
699 // Is the icon in the cache?
700 bool inCache = TQPixmapCache::find(key, pix);
701 if (inCache && (path_store == 0L))
702 return pix;
703
704 TQImage *img = 0;
705 int iconType;
706 int iconThreshold;
707
708 if ( ( path_store != 0L ) ||
709 noEffectKey != d->lastImageKey )
710 {
711 // No? load it.
712 TDEIcon icon;
713 if (absolutePath && !favIconOverlay)
714 {
715 icon.context=TDEIcon::Any;
716 icon.type=TDEIcon::Scalable;
717 icon.path=name;
718 }
719 else
720 {
721 if (!name.isEmpty())
722 icon = findMatchingIcon(favIconOverlay ? TQString("www") : name, size);
723
724 if (!icon.isValid())
725 {
726 // Try "User" icon too. Some apps expect this.
727 if (!name.isEmpty())
728 pix = loadIcon(name, TDEIcon::User, size, state, path_store, true);
729 if (!pix.isNull() || canReturnNull) {
730 TQPixmapCache::insert(key, pix);
731 return pix;
732 }
733
734 icon = findMatchingIcon(str_unknown, size);
735 if (!icon.isValid())
736 {
737 kdDebug(264)
738 << "Warning: could not find \"Unknown\" icon for size = "
739 << size << endl;
740 return pix;
741 }
742 }
743 }
744
745 if (path_store != 0L)
746 *path_store = icon.path;
747 if (inCache)
748 return pix;
749
750 // Use the extension as the format. Works for XPM and PNG, but not for SVG
751 TQString ext = icon.path.right(3).upper();
752 if(ext != "SVG" && ext != "VGZ")
753 {
754 img = new TQImage(icon.path, ext.latin1());
755 if (img->isNull()) {
756 delete img;
757 return pix;
758 }
759 }
760 else
761 {
762#ifdef HAVE_LIBART
763 // Special stuff for SVG icons
764 KSVGIconEngine *svgEngine = new KSVGIconEngine();
765
766 if(svgEngine->load(size, size, icon.path))
767 img = svgEngine->painter()->image();
768 else
769 img = new TQImage();
770
771 delete svgEngine;
772#else
773 img = new TQImage();
774#endif
775 }
776
777 iconType = icon.type;
778 iconThreshold = icon.threshold;
779
780 d->lastImage = img->copy();
781 d->lastImageKey = noEffectKey;
782 d->lastIconType = iconType;
783 d->lastIconThreshold = iconThreshold;
784 }
785 else
786 {
787 img = new TQImage( d->lastImage.copy() );
788 iconType = d->lastIconType;
789 iconThreshold = d->lastIconThreshold;
790 }
791
792 // Blend in all overlays
793 if (overlay)
794 {
795 TQImage *ovl;
796 TDEIconTheme *theme = d->mpThemeRoot->theme;
797 if ((overlay & TDEIcon::LockOverlay) &&
798 ((ovl = loadOverlay(theme->lockOverlay(), size)) != 0L))
799 TDEIconEffect::overlay(*img, *ovl);
800 if ((overlay & TDEIcon::LinkOverlay) &&
801 ((ovl = loadOverlay(theme->linkOverlay(), size)) != 0L))
802 TDEIconEffect::overlay(*img, *ovl);
803 if ((overlay & TDEIcon::ZipOverlay) &&
804 ((ovl = loadOverlay(theme->zipOverlay(), size)) != 0L))
805 TDEIconEffect::overlay(*img, *ovl);
806 if ((overlay & TDEIcon::ShareOverlay) &&
807 ((ovl = loadOverlay(theme->shareOverlay(), size)) != 0L))
808 TDEIconEffect::overlay(*img, *ovl);
809 if (overlay & TDEIcon::HiddenOverlay)
810 {
811 if (img->depth() != 32)
812 *img = img->convertDepth(32);
813 for (int y = 0; y < img->height(); y++)
814 {
815 TQRgb *line = reinterpret_cast<TQRgb *>(img->scanLine(y));
816 for (int x = 0; x < img->width(); x++)
817 line[x] = (line[x] & 0x00ffffff) | (TQMIN(0x80, tqAlpha(line[x])) << 24);
818 }
819 }
820 }
821
822 // Scale the icon and apply effects if necessary
823 if (iconType == TDEIcon::Scalable && size != img->width())
824 {
825 *img = img->smoothScale(size, size);
826 }
827 if (iconType == TDEIcon::Threshold && size != img->width())
828 {
829 if ( abs(size-img->width())>iconThreshold )
830 *img = img->smoothScale(size, size);
831 }
832 if (group >= 0 && d->mpGroups[group].dblPixels)
833 {
834 *img = d->mpEffect.doublePixels(*img);
835 }
836 if (group >= 0)
837 {
838 *img = d->mpEffect.apply(*img, group, state);
839 }
840
841 if (favIconOverlay)
842 {
843 TQImage favIcon(name, "PNG");
844 int x = img->width() - favIcon.width() - 1,
845 y = img->height() - favIcon.height() - 1;
846 if( favIcon.depth() != 32 )
847 favIcon = favIcon.convertDepth( 32 );
848 if( img->depth() != 32 )
849 *img = img->convertDepth( 32 );
850 for( int line = 0;
851 line < favIcon.height();
852 ++line )
853 {
854 TQRgb* fpos = reinterpret_cast< TQRgb* >( favIcon.scanLine( line ));
855 TQRgb* ipos = reinterpret_cast< TQRgb* >( img->scanLine( line + y )) + x;
856 for( int i = 0;
857 i < favIcon.width();
858 ++i, ++fpos, ++ipos )
859 *ipos = tqRgba( ( tqRed( *ipos ) * ( 255 - tqAlpha( *fpos )) + tqRed( *fpos ) * tqAlpha( *fpos )) / 255,
860 ( tqGreen( *ipos ) * ( 255 - tqAlpha( *fpos )) + tqGreen( *fpos ) * tqAlpha( *fpos )) / 255,
861 ( tqBlue( *ipos ) * ( 255 - tqAlpha( *fpos )) + tqBlue( *fpos ) * tqAlpha( *fpos )) / 255,
862 ( tqAlpha( *ipos ) * ( 255 - tqAlpha( *fpos )) + tqAlpha( *fpos ) * tqAlpha( *fpos )) / 255 );
863 }
864 }
865
866 if (TQPaintDevice::x11AppDepth() == 32) pix.convertFromImage(KImageEffect::convertToPremultipliedAlpha( *img ));
867 else pix.convertFromImage(*img);
868
869 delete img;
870
871 TQPixmapCache::insert(key, pix);
872 return pix;
873}
874
875TQImage *TDEIconLoader::loadOverlay(const TQString &name, int size) const
876{
877 TQString key = name + '_' + TQString::number(size);
878 TQImage *image = d->imgDict.find(key);
879 if (image != 0L)
880 return image;
881
882 TDEIcon icon = findMatchingIcon(name, size);
883 if (!icon.isValid())
884 {
885 kdDebug(264) << "Overlay " << name << "not found." << endl;
886 return 0L;
887 }
888 image = new TQImage(icon.path);
889 // In some cases (since size in findMatchingIcon() is more a hint than a
890 // constraint) image->size can be != size. If so perform rescaling.
891 if ( size != image->width() )
892 *image = image->smoothScale( size, size );
893 d->imgDict.insert(key, image);
894 return image;
895}
896
897
898
899TQMovie TDEIconLoader::loadMovie(const TQString& name, TDEIcon::Group group, int size) const
900{
901 TQString file = moviePath( name, group, size );
902 if (file.isEmpty())
903 return TQMovie();
904 int dirLen = file.findRev('/');
905 TQString icon = iconPath(name, size ? -size : group, true);
906 if (!icon.isEmpty() && file.left(dirLen) != icon.left(dirLen))
907 return TQMovie();
908 return TQMovie(file);
909}
910
911TQString TDEIconLoader::moviePath(const TQString& name, TDEIcon::Group group, int size) const
912{
913 if (!d->mpGroups) return TQString::null;
914
915 if ( (group < -1 || group >= TDEIcon::LastGroup) && group != TDEIcon::User )
916 {
917 kdDebug(264) << "Illegal icon group: " << group << endl;
918 group = TDEIcon::Desktop;
919 }
920 if (size == 0 && group < 0)
921 {
922 kdDebug(264) << "Neither size nor group specified!" << endl;
923 group = TDEIcon::Desktop;
924 }
925
926 TQString file = name + ".mng";
927 if (group == TDEIcon::User)
928 {
929 file = d->mpDirs->findResource("appicon", file);
930 }
931 else
932 {
933 if (size == 0)
934 size = d->mpGroups[group].size;
935
936 TDEIcon icon;
937
938 for ( TDEIconThemeNode *themeNode = d->links.first() ; themeNode ;
939 themeNode = d->links.next() )
940 {
941 icon = themeNode->theme->iconPath(file, size, TDEIcon::MatchExact);
942 if (icon.isValid()) goto icon_found ;
943
944 icon = themeNode->theme->iconPath(file, size, TDEIcon::MatchBest);
945 if (icon.isValid()) goto icon_found ;
946 }
947
948 icon_found:
949 file = icon.isValid() ? icon.path : TQString::null;
950 }
951 return file;
952}
953
954
955TQStringList TDEIconLoader::loadAnimated(const TQString& name, TDEIcon::Group group, int size) const
956{
957 TQStringList lst;
958
959 if (!d->mpGroups) return lst;
960
961 if ((group < -1) || (group >= TDEIcon::LastGroup))
962 {
963 kdDebug(264) << "Illegal icon group: " << group << endl;
964 group = TDEIcon::Desktop;
965 }
966 if ((size == 0) && (group < 0))
967 {
968 kdDebug(264) << "Neither size nor group specified!" << endl;
969 group = TDEIcon::Desktop;
970 }
971
972 TQString file = name + "/0001";
973 if (group == TDEIcon::User)
974 {
975 file = d->mpDirs->findResource("appicon", file + ".png");
976 } else
977 {
978 if (size == 0)
979 size = d->mpGroups[group].size;
980 TDEIcon icon = findMatchingIcon(file, size);
981 file = icon.isValid() ? icon.path : TQString::null;
982
983 }
984 if (file.isEmpty())
985 return lst;
986
987 TQString path = file.left(file.length()-8);
988 DIR* dp = opendir( TQFile::encodeName(path) );
989 if(!dp)
990 return lst;
991
992 struct dirent* ep;
993 while( ( ep = readdir( dp ) ) != 0L )
994 {
995 TQString fn(TQFile::decodeName(ep->d_name));
996 if(!(fn.left(4)).toUInt())
997 continue;
998
999 lst += path + fn;
1000 }
1001 closedir ( dp );
1002 lst.sort();
1003 return lst;
1004}
1005
1006TDEIconTheme *TDEIconLoader::theme() const
1007{
1008 if (d->mpThemeRoot) return d->mpThemeRoot->theme;
1009 return 0L;
1010}
1011
1012int TDEIconLoader::currentSize(TDEIcon::Group group) const
1013{
1014 if (!d->mpGroups) return -1;
1015
1016 if (group < 0 || group >= TDEIcon::LastGroup)
1017 {
1018 kdDebug(264) << "Illegal icon group: " << group << endl;
1019 return -1;
1020 }
1021 return d->mpGroups[group].size;
1022}
1023
1024TQStringList TDEIconLoader::queryIconsByDir( const TQString& iconsDir ) const
1025{
1026 TQDir dir(iconsDir);
1027 TQStringList lst = dir.entryList("*.png;*.xpm", TQDir::Files);
1028 TQStringList result;
1029 TQStringList::ConstIterator it;
1030 for (it=lst.begin(); it!=lst.end(); ++it)
1031 result += iconsDir + "/" + *it;
1032 return result;
1033}
1034
1035TQStringList TDEIconLoader::queryIconsByContext(int group_or_size,
1036 TDEIcon::Context context) const
1037{
1038 TQStringList result;
1039 if (group_or_size >= TDEIcon::LastGroup)
1040 {
1041 kdDebug(264) << "Illegal icon group: " << group_or_size << endl;
1042 return result;
1043 }
1044 int size;
1045 if (group_or_size >= 0)
1046 size = d->mpGroups[group_or_size].size;
1047 else
1048 size = -group_or_size;
1049
1050 for ( TDEIconThemeNode *themeNode = d->links.first() ; themeNode ;
1051 themeNode = d->links.next() )
1052 themeNode->queryIconsByContext(&result, size, context);
1053
1054 // Eliminate duplicate entries (same icon in different directories)
1055 TQString name;
1056 TQStringList res2, entries;
1057 TQStringList::ConstIterator it;
1058 for (it=result.begin(); it!=result.end(); ++it)
1059 {
1060 int n = (*it).findRev('/');
1061 if (n == -1)
1062 name = *it;
1063 else
1064 name = (*it).mid(n+1);
1065 name = removeIconExtension(name);
1066 if (!entries.contains(name))
1067 {
1068 entries += name;
1069 res2 += *it;
1070 }
1071 }
1072 return res2;
1073
1074}
1075
1076TQStringList TDEIconLoader::queryIcons(int group_or_size, TDEIcon::Context context) const
1077{
1078 TQStringList result;
1079 if (group_or_size >= TDEIcon::LastGroup)
1080 {
1081 kdDebug(264) << "Illegal icon group: " << group_or_size << endl;
1082 return result;
1083 }
1084 int size;
1085 if (group_or_size >= 0)
1086 size = d->mpGroups[group_or_size].size;
1087 else
1088 size = -group_or_size;
1089
1090 for ( TDEIconThemeNode *themeNode = d->links.first() ; themeNode ;
1091 themeNode = d->links.next() )
1092 themeNode->queryIcons(&result, size, context);
1093
1094 // Eliminate duplicate entries (same icon in different directories)
1095 TQString name;
1096 TQStringList res2, entries;
1097 TQStringList::ConstIterator it;
1098 for (it=result.begin(); it!=result.end(); ++it)
1099 {
1100 int n = (*it).findRev('/');
1101 if (n == -1)
1102 name = *it;
1103 else
1104 name = (*it).mid(n+1);
1105 name = removeIconExtension(name);
1106 if (!entries.contains(name))
1107 {
1108 entries += name;
1109 res2 += *it;
1110 }
1111 }
1112 return res2;
1113}
1114
1115// used by TDEIconDialog to find out which contexts to offer in a combobox
1116bool TDEIconLoader::hasContext(TDEIcon::Context context) const
1117{
1118 for ( TDEIconThemeNode *themeNode = d->links.first() ; themeNode ;
1119 themeNode = d->links.next() )
1120 if( themeNode->theme->hasContext( context ))
1121 return true;
1122 return false;
1123}
1124
1125TDEIconEffect * TDEIconLoader::iconEffect() const
1126{
1127 return &d->mpEffect;
1128}
1129
1130bool TDEIconLoader::alphaBlending(TDEIcon::Group group) const
1131{
1132 if (!d->mpGroups) return false;
1133
1134 if (group < 0 || group >= TDEIcon::LastGroup)
1135 {
1136 kdDebug(264) << "Illegal icon group: " << group << endl;
1137 return false;
1138 }
1139 return d->mpGroups[group].alphaBlending;
1140}
1141
1142TQIconSet TDEIconLoader::loadIconSet(const TQString& name, TDEIcon::Group group, int size, bool canReturnNull)
1143{
1144 return loadIconSet( name, group, size, canReturnNull, true );
1145}
1146
1147TQIconSet TDEIconLoader::loadIconSet(const TQString& name, TDEIcon::Group group, int size)
1148{
1149 return loadIconSet( name, group, size, false );
1150}
1151
1152/*** class for delayed icon loading for TQIconSet ***/
1153
1154class TDEIconFactory
1155 : public TQIconFactory
1156 {
1157 public:
1158 TDEIconFactory( const TQString& iconName_P, TDEIcon::Group group_P,
1159 int size_P, TDEIconLoader* loader_P );
1160 TDEIconFactory( const TQString& iconName_P, TDEIcon::Group group_P,
1161 int size_P, TDEIconLoader* loader_P, bool canReturnNull );
1162 virtual TQPixmap* createPixmap( const TQIconSet&, TQIconSet::Size, TQIconSet::Mode, TQIconSet::State );
1163 private:
1164 TQString iconName;
1165 TDEIcon::Group group;
1166 int size;
1167 TDEIconLoader* loader;
1168 bool canReturnNull;
1169 };
1170
1171
1172TQIconSet TDEIconLoader::loadIconSet( const TQString& name, TDEIcon::Group g, int s,
1173 bool canReturnNull, bool immediateExistenceCheck)
1174{
1175 if ( !d->delayedLoading )
1176 return loadIconSetNonDelayed( name, g, s, canReturnNull );
1177
1178 if (g < -1 || g > 6) {
1179 kdDebug() << "TDEIconLoader::loadIconSet " << name << " " << (int)g << " " << s << endl;
1180 tqDebug("%s", kdBacktrace().latin1());
1181 abort();
1182 }
1183
1184 if(canReturnNull && immediateExistenceCheck)
1185 { // we need to find out if the icon actually exists
1186 TQPixmap pm = loadIcon( name, g, s, TDEIcon::DefaultState, NULL, true );
1187 if( pm.isNull())
1188 return TQIconSet();
1189
1190 TQIconSet ret( pm );
1191 ret.installIconFactory( new TDEIconFactory( name, g, s, this ));
1192 return ret;
1193 }
1194
1195 TQIconSet ret;
1196 ret.installIconFactory( new TDEIconFactory( name, g, s, this, canReturnNull ));
1197 return ret;
1198}
1199
1200TQIconSet TDEIconLoader::loadIconSetNonDelayed( const TQString& name,
1201 TDEIcon::Group g,
1202 int s, bool canReturnNull )
1203{
1204 TQIconSet iconset;
1205 TQPixmap tmp = loadIcon(name, g, s, TDEIcon::ActiveState, NULL, canReturnNull);
1206 iconset.setPixmap( tmp, TQIconSet::Small, TQIconSet::Active );
1207 // we don't use QIconSet's resizing anyway
1208 iconset.setPixmap( tmp, TQIconSet::Large, TQIconSet::Active );
1209 tmp = loadIcon(name, g, s, TDEIcon::DisabledState, NULL, canReturnNull);
1210 iconset.setPixmap( tmp, TQIconSet::Small, TQIconSet::Disabled );
1211 iconset.setPixmap( tmp, TQIconSet::Large, TQIconSet::Disabled );
1212 tmp = loadIcon(name, g, s, TDEIcon::DefaultState, NULL, canReturnNull);
1213 iconset.setPixmap( tmp, TQIconSet::Small, TQIconSet::Normal );
1214 iconset.setPixmap( tmp, TQIconSet::Large, TQIconSet::Normal );
1215 return iconset;
1216}
1217
1218TDEIconFactory::TDEIconFactory( const TQString& iconName_P, TDEIcon::Group group_P,
1219 int size_P, TDEIconLoader* loader_P )
1220 : iconName( iconName_P ), group( group_P ), size( size_P ), loader( loader_P )
1221{
1222 canReturnNull = false;
1223 setAutoDelete( true );
1224}
1225
1226TDEIconFactory::TDEIconFactory( const TQString& iconName_P, TDEIcon::Group group_P,
1227 int size_P, TDEIconLoader* loader_P, bool canReturnNull_P )
1228 : iconName( iconName_P ), group( group_P ), size( size_P ),
1229 loader( loader_P ), canReturnNull( canReturnNull_P)
1230{
1231 setAutoDelete( true );
1232}
1233
1234TQPixmap* TDEIconFactory::createPixmap( const TQIconSet&, TQIconSet::Size, TQIconSet::Mode mode_P, TQIconSet::State )
1235 {
1236#ifdef TDEICONLOADER_DEBUG
1237 bool found = false;
1238 for( TQValueList< TDEIconLoaderDebug >::Iterator it = kiconloaders->begin();
1239 it != kiconloaders->end();
1240 ++it )
1241 {
1242 if( (*it).loader == loader )
1243 {
1244 found = true;
1245 if( !(*it).valid )
1246 {
1247#ifdef NDEBUG
1248 loader = TDEGlobal::iconLoader();
1249 iconName = "no_way_man_you_will_get_broken_icon";
1250#else
1251 kdWarning() << "Using already destroyed TDEIconLoader for loading an icon!" << endl;
1252 kdWarning() << "Appname:" << (*it).appname << ", icon:" << iconName << endl;
1253 kdWarning() << "Deleted at:" << endl;
1254 kdWarning() << (*it).delete_bt << endl;
1255 kdWarning() << "Current:" << endl;
1256 kdWarning() << kdBacktrace() << endl;
1257 abort();
1258 return NULL;
1259#endif
1260 }
1261 break;
1262 }
1263 }
1264 if( !found )
1265 {
1266#ifdef NDEBUG
1267 loader = TDEGlobal::iconLoader();
1268 iconName = "no_way_man_you_will_get_broken_icon";
1269#else
1270 kdWarning() << "Using unknown TDEIconLoader for loading an icon!" << endl;
1271 kdWarning() << "Icon:" << iconName << endl;
1272 kdWarning() << kdBacktrace() << endl;
1273 abort();
1274 return NULL;
1275#endif
1276 }
1277#endif
1278 // TQIconSet::Mode to TDEIcon::State conversion
1279 static const TDEIcon::States tbl[] = { TDEIcon::DefaultState, TDEIcon::DisabledState, TDEIcon::ActiveState };
1280 int state = TDEIcon::DefaultState;
1281 if( mode_P <= TQIconSet::Active )
1282 state = tbl[ mode_P ];
1283 if( group >= 0 && state == TDEIcon::ActiveState )
1284 { // active and normal icon are usually the same
1285 if( loader->iconEffect()->fingerprint(group, TDEIcon::ActiveState )
1286 == loader->iconEffect()->fingerprint(group, TDEIcon::DefaultState ))
1287 return 0; // so let TQIconSet simply duplicate it
1288 }
1289 // ignore passed size
1290 // ignore passed state (i.e. on/off)
1291 TQPixmap pm = loader->loadIcon( iconName, group, size, state, 0, canReturnNull );
1292 return new TQPixmap( pm );
1293 }
1294
1295// Easy access functions
1296
1297TQPixmap DesktopIcon(const TQString& name, int force_size, int state,
1298 TDEInstance *instance)
1299{
1300 TDEIconLoader *loader = instance->iconLoader();
1301 return loader->loadIcon(name, TDEIcon::Desktop, force_size, state);
1302}
1303
1304TQPixmap DesktopIcon(const TQString& name, TDEInstance *instance)
1305{
1306 return DesktopIcon(name, 0, TDEIcon::DefaultState, instance);
1307}
1308
1309TQIconSet DesktopIconSet(const TQString& name, int force_size, TDEInstance *instance)
1310{
1311 TDEIconLoader *loader = instance->iconLoader();
1312 return loader->loadIconSet( name, TDEIcon::Desktop, force_size );
1313}
1314
1315TQPixmap BarIcon(const TQString& name, int force_size, int state,
1316 TDEInstance *instance)
1317{
1318 TDEIconLoader *loader = instance->iconLoader();
1319 return loader->loadIcon(name, TDEIcon::Toolbar, force_size, state);
1320}
1321
1322TQPixmap BarIcon(const TQString& name, TDEInstance *instance)
1323{
1324 return BarIcon(name, 0, TDEIcon::DefaultState, instance);
1325}
1326
1327TQIconSet BarIconSet(const TQString& name, int force_size, TDEInstance *instance)
1328{
1329 TDEIconLoader *loader = instance->iconLoader();
1330 return loader->loadIconSet( name, TDEIcon::Toolbar, force_size );
1331}
1332
1333TQPixmap SmallIcon(const TQString& name, int force_size, int state,
1334 TDEInstance *instance)
1335{
1336 TDEIconLoader *loader = instance->iconLoader();
1337 return loader->loadIcon(name, TDEIcon::Small, force_size, state);
1338}
1339
1340TQPixmap SmallIcon(const TQString& name, TDEInstance *instance)
1341{
1342 return SmallIcon(name, 0, TDEIcon::DefaultState, instance);
1343}
1344
1345TQIconSet SmallIconSet(const TQString& name, int force_size, TDEInstance *instance)
1346{
1347 TDEIconLoader *loader = instance->iconLoader();
1348 return loader->loadIconSet( name, TDEIcon::Small, force_size );
1349}
1350
1351TQPixmap MainBarIcon(const TQString& name, int force_size, int state,
1352 TDEInstance *instance)
1353{
1354 TDEIconLoader *loader = instance->iconLoader();
1355 return loader->loadIcon(name, TDEIcon::MainToolbar, force_size, state);
1356}
1357
1358TQPixmap MainBarIcon(const TQString& name, TDEInstance *instance)
1359{
1360 return MainBarIcon(name, 0, TDEIcon::DefaultState, instance);
1361}
1362
1363TQIconSet MainBarIconSet(const TQString& name, int force_size, TDEInstance *instance)
1364{
1365 TDEIconLoader *loader = instance->iconLoader();
1366 return loader->loadIconSet( name, TDEIcon::MainToolbar, force_size );
1367}
1368
1369TQPixmap UserIcon(const TQString& name, int state, TDEInstance *instance)
1370{
1371 TDEIconLoader *loader = instance->iconLoader();
1372 return loader->loadIcon(name, TDEIcon::User, 0, state);
1373}
1374
1375TQPixmap UserIcon(const TQString& name, TDEInstance *instance)
1376{
1377 return UserIcon(name, TDEIcon::DefaultState, instance);
1378}
1379
1380TQIconSet UserIconSet(const TQString& name, TDEInstance *instance)
1381{
1382 TDEIconLoader *loader = instance->iconLoader();
1383 return loader->loadIconSet( name, TDEIcon::User );
1384}
1385
1386int IconSize(TDEIcon::Group group, TDEInstance *instance)
1387{
1388 TDEIconLoader *loader = instance->iconLoader();
1389 return loader->currentSize(group);
1390}
1391
1392TQPixmap TDEIconLoader::unknown()
1393{
1394 TQPixmap pix;
1395 if ( TQPixmapCache::find("unknown", pix) )
1396 return pix;
1397
1398 TQString path = TDEGlobal::iconLoader()->iconPath("unknown", TDEIcon::Small, true);
1399 if (path.isEmpty())
1400 {
1401 kdDebug(264) << "Warning: Cannot find \"unknown\" icon." << endl;
1402 pix.resize(32,32);
1403 } else
1404 {
1405 pix.load(path);
1406 TQPixmapCache::insert("unknown", pix);
1407 }
1408
1409 return pix;
1410}
1411
1412void TDEIconLoaderPrivate::reconfigure()
1413{
1414 q->reconfigure(appname, mpDirs);
1415}
1416
1417#include "kiconloader_p.moc"
TDEConfigBase::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
Reads a numerical value.
Definition: tdeconfigbase.cpp:613
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
Definition: tdeconfigbase.cpp:748
TDEConfigBase::setGroup
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
Definition: tdeconfigbase.cpp:79
TDEConfigGroupSaver
Helper class to facilitate working with TDEConfig / KSimpleConfig groups.
Definition: tdeconfigbase.h:2083
TDEConfig
Access KDE Configuration entries.
Definition: tdeconfig.h:44
TDEGlobal::iconLoader
static TDEIconLoader * iconLoader()
Returns an iconloader object.
Definition: tdeglobal.cpp:79
TDEGlobal::config
static TDEConfig * config()
Returns the general config object.
Definition: tdeglobal.cpp:65
TDEGlobal::dirs
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
Definition: tdeglobal.cpp:58
TDEGlobal::instance
static TDEInstance * instance()
Returns the global instance.
Definition: tdeglobal.cpp:102
TDEGlobal::staticQString
static const TQString & staticQString(const char *str)
Creates a static TQString.
Definition: tdeglobal.cpp:148
TDEIconEffect
Applies effects to icons.
Definition: kiconeffect.h:35
TDEIconEffect::overlay
static void overlay(TQImage &src, TQImage &overlay)
Overlays an image with an other image.
Definition: kiconeffect.cpp:592
TDEIconLoader
Iconloader for KDE.
Definition: kiconloader.h:78
TDEIconLoader::enableDelayedIconSetLoading
void enableDelayedIconSetLoading(bool enable)
Enables on-demand icon loading for QIconSets using TQIconFactory.
Definition: kiconloader.cpp:289
TDEIconLoader::extraDesktopThemesAdded
bool extraDesktopThemesAdded() const
Returns if the default icon themes of other desktops have been added to the list of icon themes where...
Definition: kiconloader.cpp:402
TDEIconLoader::queryIcons
TQStringList queryIcons(int group_or_size, TDEIcon::Context context=TDEIcon::Any) const
Queries all available icons for a specific group, having a specific context.
Definition: kiconloader.cpp:1076
TDEIconLoader::BarIcon
TQPixmap BarIcon(const TQString &name, int size=0, int state=TDEIcon::DefaultState, TDEInstance *instance=TDEGlobal::instance())
Load a toolbar icon.
Definition: kiconloader.cpp:1315
TDEIconLoader::DesktopIcon
TQPixmap DesktopIcon(const TQString &name, int size=0, int state=TDEIcon::DefaultState, TDEInstance *instance=TDEGlobal::instance())
Load a desktop icon.
Definition: kiconloader.cpp:1297
TDEIconLoader::BarIconSet
TQIconSet BarIconSet(const TQString &name, int size=0, TDEInstance *instance=TDEGlobal::instance())
Load a toolbar icon, and apply the necessary effects to get an IconSet.
Definition: kiconloader.cpp:1327
TDEIconLoader::currentSize
int currentSize(TDEIcon::Group group) const
Returns the current size of the group.
Definition: kiconloader.cpp:1012
TDEIconLoader::queryIconsByContext
TQStringList queryIconsByContext(int group_or_size, TDEIcon::Context context=TDEIcon::Any) const
Queries all available icons for a specific context.
Definition: kiconloader.cpp:1035
TDEIconLoader::reconfigure
void reconfigure(const TQString &_appname, TDEStandardDirs *_dirs)
Called by TDEInstance::newIconLoader to reconfigure the icon loader.
Definition: kiconloader.cpp:166
TDEIconLoader::addExtraDesktopThemes
void addExtraDesktopThemes()
Adds all the default themes from other desktops at the end of the list of icon themes.
Definition: kiconloader.cpp:351
TDEIconLoader::SmallIconSet
TQIconSet SmallIconSet(const TQString &name, int size=0, TDEInstance *instance=TDEGlobal::instance())
Load a small icon, and apply the necessary effects to get an IconSet.
Definition: kiconloader.cpp:1345
TDEIconLoader::loadAnimated
TQStringList loadAnimated(const TQString &name, TDEIcon::Group group, int size=0) const
Loads an animated icon as a series of still frames.
Definition: kiconloader.cpp:955
TDEIconLoader::MainBarIconSet
TQIconSet MainBarIconSet(const TQString &name, int size=0, TDEInstance *instance=TDEGlobal::instance())
Load a main toolbar icon, and apply the effects to get an IconSet.
Definition: kiconloader.cpp:1363
TDEIconLoader::UserIconSet
TQIconSet UserIconSet(const TQString &name, TDEInstance *instance=TDEGlobal::instance())
Load a user icon, and apply the effects to get an IconSet.
Definition: kiconloader.cpp:1380
TDEIconLoader::~TDEIconLoader
~TDEIconLoader()
Cleanup.
Definition: kiconloader.cpp:267
TDEIconLoader::loadIconSet
TQIconSet loadIconSet(const TQString &name, TDEIcon::Group group, int size, bool canReturnNull, bool immediateExistenceCheck)
Creates an icon set, that will do on-demand loading of the icon.
Definition: kiconloader.cpp:1172
TDEIconLoader::IconSize
int IconSize(TDEIcon::Group group, TDEInstance *instance=TDEGlobal::instance())
Returns the current icon size for a specific group.
Definition: kiconloader.cpp:1386
TDEIconLoader::loadIcon
TQPixmap loadIcon(const TQString &name, TDEIcon::Group group, int size=0, int state=TDEIcon::DefaultState, TQString *path_store=0L, bool canReturnNull=false) const
Loads an icon.
Definition: kiconloader.cpp:583
TDEIconLoader::UserIcon
TQPixmap UserIcon(const TQString &name, int state=TDEIcon::DefaultState, TDEInstance *instance=TDEGlobal::instance())
Load a user icon.
Definition: kiconloader.cpp:1369
TDEIconLoader::MainBarIcon
TQPixmap MainBarIcon(const TQString &name, int size=0, int state=TDEIcon::DefaultState, TDEInstance *instance=TDEGlobal::instance())
Load a main toolbar icon.
Definition: kiconloader.cpp:1351
TDEIconLoader::TDEIconLoader
TDEIconLoader(const TQString &appname=TQString::null, TDEStandardDirs *dirs=0)
Constructs an iconloader.
Definition: kiconloader.cpp:134
TDEIconLoader::iconPath
TQString iconPath(const TQString &name, int group_or_size, bool canReturnNull=false) const
Returns the path of an icon.
Definition: kiconloader.cpp:516
TDEIconLoader::isDelayedIconSetLoadingEnabled
bool isDelayedIconSetLoadingEnabled() const
Checks whether delayed loading for TQIconSet is enabled.
Definition: kiconloader.cpp:294
TDEIconLoader::loadMovie
TQMovie loadMovie(const TQString &name, TDEIcon::Group group, int size=0) const
Loads an animated icon.
Definition: kiconloader.cpp:899
TDEIconLoader::DesktopIconSet
TQIconSet DesktopIconSet(const TQString &name, int size=0, TDEInstance *instance=TDEGlobal::instance())
Load a desktop icon, and apply the necessary effects to get an IconSet.
Definition: kiconloader.cpp:1309
TDEIconLoader::SmallIcon
TQPixmap SmallIcon(const TQString &name, int size=0, int state=TDEIcon::DefaultState, TDEInstance *instance=TDEGlobal::instance())
Load a small icon.
Definition: kiconloader.cpp:1333
TDEIconLoader::theme
TDEIconTheme * theme() const
Returns a pointer to the current theme.
Definition: kiconloader.cpp:1006
TDEIconLoader::iconEffect
TDEIconEffect * iconEffect() const
Returns a pointer to the TDEIconEffect object used by the icon loader.
Definition: kiconloader.cpp:1125
TDEIconLoader::addAppDir
void addAppDir(const TQString &appname)
Adds appname to the list of application specific directories.
Definition: kiconloader.cpp:299
TDEIconLoader::alphaBlending
bool alphaBlending(TDEIcon::Group group) const
Checks whether the user wants to blend the icons with the background using the alpha channel informat...
Definition: kiconloader.cpp:1130
TDEIconLoader::moviePath
TQString moviePath(const TQString &name, TDEIcon::Group group, int size=0) const
Returns the path to an animated icon.
Definition: kiconloader.cpp:911
TDEIconLoader::unknown
static TQPixmap unknown()
Returns the unknown icon.
Definition: kiconloader.cpp:1392
TDEIconLoader::queryIconsByDir
TQStringList queryIconsByDir(const TQString &iconsDir) const
Returns a list of all icons (*.png or *.xpm extension) in the given directory.
Definition: kiconloader.cpp:1024
TDEIconTheme
Class to use/access icon themes in KDE.
Definition: kicontheme.h:188
TDEIconTheme::name
TQString name() const
The stylized name of the icon theme.
Definition: kicontheme.h:203
TDEIconTheme::current
static TQString current()
Returns the current icon theme.
Definition: kicontheme.cpp:444
TDEIconTheme::linkOverlay
TQString linkOverlay() const
Returns the name of this theme's link overlay.
Definition: kicontheme.cpp:239
TDEIconTheme::shareOverlay
TQString shareOverlay() const
Returns the name of this theme's share overlay.
Definition: kicontheme.cpp:242
TDEIconTheme::isValid
bool isValid() const
The icon theme exists?
Definition: kicontheme.cpp:227
TDEIconTheme::zipOverlay
TQString zipOverlay() const
Returns the name of this theme's zip overlay.
Definition: kicontheme.cpp:241
TDEIconTheme::defaultThemeName
static TQString defaultThemeName()
Returns the default icon theme.
Definition: kicontheme.cpp:512
TDEIconTheme::lockOverlay
TQString lockOverlay() const
Returns the name of this theme's lock overlay.
Definition: kicontheme.cpp:240
TDEIcon
One icon as found by TDEIconTheme.
Definition: kicontheme.h:37
TDEIcon::States
States
Defines the possible states of an icon.
Definition: kicontheme.h:130
TDEIcon::DefaultState
@ DefaultState
The default state.
Definition: kicontheme.h:130
TDEIcon::LastState
@ LastState
Last state (last constant)
Definition: kicontheme.h:133
TDEIcon::DisabledState
@ DisabledState
Icon is disabled.
Definition: kicontheme.h:132
TDEIcon::ActiveState
@ ActiveState
Icon is active.
Definition: kicontheme.h:131
TDEIcon::context
Context context
The context of the icon.
Definition: kicontheme.h:158
TDEIcon::path
TQString path
The full path of the icon.
Definition: kicontheme.h:173
TDEIcon::Context
Context
Defines the context of the icon.
Definition: kicontheme.h:49
TDEIcon::Any
@ Any
Some icon with unknown purpose.
Definition: kicontheme.h:50
TDEIcon::Group
Group
The group of the icon.
Definition: kicontheme.h:88
TDEIcon::Toolbar
@ Toolbar
Toolbar icons.
Definition: kicontheme.h:96
TDEIcon::MainToolbar
@ MainToolbar
Main toolbar icons.
Definition: kicontheme.h:98
TDEIcon::LastGroup
@ LastGroup
Last group.
Definition: kicontheme.h:104
TDEIcon::Small
@ Small
Small icons.
Definition: kicontheme.h:100
TDEIcon::User
@ User
User icons.
Definition: kicontheme.h:106
TDEIcon::Desktop
@ Desktop
Desktop icons.
Definition: kicontheme.h:92
TDEIcon::FirstGroup
@ FirstGroup
First group.
Definition: kicontheme.h:94
TDEIcon::isValid
bool isValid() const
Return true if this icon is valid, false otherwise.
Definition: kicontheme.h:44
TDEIcon::type
Type type
The type of the icon: Fixed, Scalable or Threshold.
Definition: kicontheme.h:163
TDEIcon::ZipOverlay
@ ZipOverlay
a file is zipped
Definition: kicontheme.h:143
TDEIcon::LockOverlay
@ LockOverlay
a file is locked
Definition: kicontheme.h:142
TDEIcon::ShareOverlay
@ ShareOverlay
a file is shared
Definition: kicontheme.h:146
TDEIcon::HiddenOverlay
@ HiddenOverlay
a file is hidden
Definition: kicontheme.h:145
TDEIcon::LinkOverlay
@ LinkOverlay
a file is a link
Definition: kicontheme.h:144
TDEIcon::threshold
int threshold
The threshold in case type == Threshold.
Definition: kicontheme.h:168
TDEIcon::Scalable
@ Scalable
Scalable-size icon.
Definition: kicontheme.h:70
TDEIcon::Threshold
@ Threshold
A threshold icon.
Definition: kicontheme.h:71
TDEIcon::MatchType
MatchType
The type of a match.
Definition: kicontheme.h:77
TDEIcon::MatchBest
@ MatchBest
Take the best match if there is no exact match.
Definition: kicontheme.h:79
TDEIcon::MatchExact
@ MatchExact
Only try to find an exact match.
Definition: kicontheme.h:78
TDEInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:48
TDEInstance::instanceName
TQCString instanceName() const
Returns the name of the instance.
Definition: kinstance.cpp:342
TDEInstance::iconLoader
TDEIconLoader * iconLoader() const
Returns an iconloader object.
Definition: kinstance.cpp:276
TDEStandardDirs
Site-independent access to standard TDE directories.
Definition: tdestandarddirs.h:126
TDEStandardDirs::resourceDirs
TQStringList resourceDirs(const char *type) const
This function is used internally by almost all other function as it serves and fills the directories ...
Definition: tdestandarddirs.cpp:795
TDEStandardDirs::kde_default
static TQString kde_default(const char *type)
This returns a default relative path for the standard TDE resource types.
Definition: tdestandarddirs.cpp:1036
TDEStandardDirs::exists
static bool exists(const TQString &fullPath)
Checks for existence and accessability of a file or directory.
Definition: tdestandarddirs.cpp:450
TDEGlobal::kdBacktrace
TQString kdBacktrace(int levels=-1)
Returns a backtrace.
Definition: kdebug.cpp:805
TDEGlobal::kdWarning
kdbgstream kdWarning(int area=0)
Returns a warning stream.
Definition: kdebug.cpp:376
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
TDEGlobal::endl
kdbgstream & endl(kdbgstream &s)
Prints an "\n".
Definition: kdebug.h:430
KStdAction::name
const char * name(StdAction id)

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.