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

tdecore

Skip menu "tdecore"
  • Main Page
  • 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.15.0
This website is maintained by Timothy Pearson.