src/gui/image/qicon.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 19 fcece45ef507
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   101   \value Off  Display the pixmap when the widget is in an "off" state
   101   \value Off  Display the pixmap when the widget is in an "off" state
   102   \value On  Display the pixmap when the widget is in an "on" state
   102   \value On  Display the pixmap when the widget is in an "on" state
   103 */
   103 */
   104 
   104 
   105 static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
   105 static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
       
   106 
       
   107 static void qt_cleanup_icon_cache();
       
   108 typedef QCache<QString, QIcon> IconCache;
       
   109 Q_GLOBAL_STATIC_WITH_INITIALIZER(IconCache, qtIconCache, qAddPostRoutine(qt_cleanup_icon_cache))
       
   110 
       
   111 static void qt_cleanup_icon_cache()
       
   112 {
       
   113     qtIconCache()->clear();
       
   114 }
   106 
   115 
   107 QIconPrivate::QIconPrivate()
   116 QIconPrivate::QIconPrivate()
   108     : engine(0), ref(1),
   117     : engine(0), ref(1),
   109     serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
   118     serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
   110     detach_no(0),
   119     detach_no(0),
   961 
   970 
   962     \sa themeName(), setThemeName(), themeSearchPaths()
   971     \sa themeName(), setThemeName(), themeSearchPaths()
   963 */
   972 */
   964 QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
   973 QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
   965 {
   974 {
   966     static QCache <QString, QIcon> iconCache;
       
   967 
       
   968     QIcon icon;
   975     QIcon icon;
   969 
   976 
   970     if (iconCache.contains(name)) {
   977     if (qtIconCache()->contains(name)) {
   971         icon = *iconCache.object(name);
   978         icon = *qtIconCache()->object(name);
   972     } else {
   979     } else {
   973         QIcon *cachedIcon  = new QIcon(new QIconLoaderEngine(name));
   980         QIcon *cachedIcon  = new QIcon(new QIconLoaderEngine(name));
   974         iconCache.insert(name, cachedIcon);
   981         qtIconCache()->insert(name, cachedIcon);
   975         icon = *cachedIcon;
   982         icon = *cachedIcon;
   976     }
   983     }
   977 
   984 
   978     if (icon.availableSizes().isEmpty())
   985     if (icon.availableSizes().isEmpty())
   979         return fallback;
   986         return fallback;