File indexing completed on 2024-04-21 04:44:05
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 #include "hint.h" 0019 #include "lambdahint.h" 0020 0021 using namespace Snore; 0022 0023 Hint::Hint() 0024 { 0025 } 0026 0027 void Hint::setValue(const QByteArray &key, const QVariant &value) 0028 { 0029 m_data.insert(key, value); 0030 } 0031 0032 QVariant Hint::value(const QByteArray &key) const 0033 { 0034 QVariant out = m_data.value(key); 0035 if (out.canConvert<LambdaHint>()) { 0036 return out.value<LambdaHint>()(); 0037 } 0038 return out; 0039 } 0040 0041 QVariant Hint::take(const QByteArray &key) 0042 { 0043 QVariant out = m_data.take(key); 0044 if (out.canConvert<LambdaHint>()) { 0045 return out.value<LambdaHint>()(); 0046 } 0047 return out; 0048 } 0049 0050 bool Hint::contains(const QByteArray &key) const 0051 { 0052 return m_data.contains(key); 0053 } 0054 0055 void Hint::setPrivateValue(const void *owner, const QByteArray &key, const QVariant &value) 0056 { 0057 m_privateData.insert(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key), value); 0058 } 0059 0060 QVariant Hint::privateValue(const void *owner, const QByteArray &key) const 0061 { 0062 QVariant out = m_privateData.value(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key)); 0063 if (out.canConvert<LambdaHint>()) { 0064 return out.value<LambdaHint>()(); 0065 } 0066 return out; 0067 } 0068 0069 bool Hint::containsPrivateValue(const void *owner, const QByteArray &key) const 0070 { 0071 return m_privateData.contains(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key)); 0072 } 0073 0074 QVariant Hint::takePrivateValue(const void *owner, const QByteArray &key) 0075 { 0076 QVariant out = m_privateData.take(qMakePair<const quintptr, const QByteArray>((quintptr)owner, key)); 0077 if (out.canConvert<LambdaHint>()) { 0078 return out.value<LambdaHint>()(); 0079 } 0080 return out; 0081 } 0082 0083 QDebug operator<<(QDebug debug, const Snore::Hint &hint) 0084 { 0085 debug << "Snore::Hint("; 0086 for (auto it = hint.m_data.cbegin(); it != hint.m_data.cend(); ++it) { 0087 debug << ", "; 0088 debug << "(" << it.key() << ", " << it.value(); 0089 } 0090 for (auto it = hint.m_privateData.cbegin(); it != hint.m_privateData.cend(); ++it) { 0091 debug << ", "; 0092 debug << "(" << it.key() << ", " << it.value(); 0093 } 0094 debug << ")" ; 0095 return debug.maybeSpace(); 0096 }