File indexing completed on 2024-05-05 04:45:34
0001 /* 0002 SnoreNotify is a Notification Framework based on Qt 0003 Copyright (C) 2013-2015 Hannah von Reth <vonreth@kde.org> 0004 0005 SnoreNotify is free software: you can redistribute it and/or modify 0006 it under the terms of the GNU Lesser General Public License as published by 0007 the Free Software Foundation, either version 3 of the License, or 0008 (at your option) any later version. 0009 0010 SnoreNotify is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU Lesser General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public License 0016 along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #ifndef NOTIFICATION_ICON_H 0020 #define NOTIFICATION_ICON_H 0021 #include "libsnore/snore_exports.h" 0022 0023 #include <QIcon> 0024 #include <QSharedData> 0025 #include <QDebug> 0026 0027 namespace Snore 0028 { 0029 0030 /** 0031 * Icon is a convnience wrapper for QIcon. 0032 * @author Hannah von Reth \<vonreth at kde.org\> 0033 */ 0034 class SNORE_EXPORT Icon : public QIcon 0035 { 0036 public: 0037 /** 0038 * Returns the default Snore Icon. 0039 */ 0040 static Icon defaultIcon(); 0041 0042 /** 0043 * Returns an Icon from a web Url. 0044 * This function is blocking until the download is completed, failed or took longer than maxTime. 0045 * In case the function failes it will return the same as defaultIcon(). 0046 * The function caches successful downloads, a Url is only downloaded once. 0047 */ 0048 static Icon fromWebUrl(const QUrl &url, int maxTime = 5000); 0049 0050 Icon(const QPixmap &pixmap); 0051 Icon(const QIcon &other); 0052 explicit Icon(const QString &fileName); 0053 0054 /** 0055 * Returns a local Url to a file representing the Icon. 0056 */ 0057 QString localUrl(QSize size, Mode mode = Normal, State state = Off) const; 0058 0059 private: 0060 Icon() = delete; 0061 static QSet<QString> s_localImageCache; 0062 static QMap<QUrl, Icon> s_downloadImageCache; 0063 }; 0064 } 0065 0066 #endif // NOTIFICATION_ICON_H