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 #ifndef HINT_H
0019 #define HINT_H
0020 
0021 #include <QVariantHash>
0022 #include <QDebug>
0023 
0024 #include "snore_exports.h"
0025 
0026 namespace Snore
0027 {
0028 class Hint;
0029 }
0030 
0031 SNORE_EXPORT QDebug operator<< (QDebug, const Snore::Hint &);
0032 
0033 namespace Snore
0034 {
0035 /**
0036  * Hint contains extra information accesible by key.
0037  * The keys are case sensitive.
0038  *
0039  * @author Hannah von Reth \<vonreth at kde.org\>
0040  */
0041 
0042 class SNORE_EXPORT Hint
0043 {
0044 public:
0045     Hint();
0046 
0047     /**
0048      * Sets the value for the key
0049      * @param key the key
0050      * @param value the value
0051      */
0052     void setValue(const QByteArray &key, const QVariant &value);
0053 
0054     /**
0055      * The associated value of the key.
0056      * @param key the key
0057      */
0058     QVariant value(const QByteArray &key) const;
0059 
0060     /**
0061      * The associated value of the key.
0062      * @param key the key
0063      */
0064     QVariant take(const QByteArray &key);
0065 
0066     /**
0067      *
0068      * @param key the key
0069      * @return whether the key is set
0070      */
0071     bool contains(const QByteArray &key) const;
0072 
0073     /**
0074      * Sets the value for the key depending on the owner
0075      * @param owner the owner
0076      * @param key the key
0077      * @param value the value
0078      */
0079     void setPrivateValue(const void *owner, const QByteArray &key, const QVariant &value);
0080 
0081     /**
0082      * The associated value of the key if present.
0083      * @param owner the owner
0084      * @param key the key
0085      */
0086     QVariant privateValue(const void *owner, const QByteArray &key) const;
0087 
0088     /**
0089      *
0090      * @param owner the owner
0091      * @param key the key
0092      * @return whether the key is set
0093      */
0094     bool containsPrivateValue(const void *owner, const QByteArray &key) const;
0095 
0096     /**
0097      * The associated value of the key if present.
0098      * @param owner the owner
0099      * @param key the key
0100      * @return whether the key is set
0101      */
0102     QVariant takePrivateValue(const void *owner, const QByteArray &key);
0103 
0104 private:
0105     QHash<QByteArray, QVariant>  m_data;
0106     QHash<QPair<quintptr, QByteArray>, QVariant> m_privateData;
0107 
0108     friend SNORE_EXPORT QDebug(::operator<<)(QDebug, const Snore::Hint &);
0109 
0110 };
0111 
0112 }
0113 
0114 #endif // HINT_H