qtmobility/src/publishsubscribe/gconfitem_p.h
changeset 4 90517678cc4f
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef GCONFITEM_H
       
    43 #define GCONFITEM_H
       
    44 
       
    45 #include <QVariant>
       
    46 #include <QStringList>
       
    47 #include <QObject>
       
    48 
       
    49 /*!
       
    50 
       
    51   \brief GConfItem is a simple C++ wrapper for GConf.
       
    52 
       
    53   Creating a GConfItem instance gives you access to a single GConf
       
    54   key.  You can get and set its value, and connect to its
       
    55   valueChanged() signal to be notified about changes.
       
    56 
       
    57   The value of a GConf key is returned to you as a QVariant, and you
       
    58   pass in a QVariant when setting the value.  GConfItem converts
       
    59   between a QVariant and GConf values as needed, and according to the
       
    60   following rules:
       
    61 
       
    62   - A QVariant of type QVariant::Invalid denotes an unset GConf key.
       
    63 
       
    64   - QVariant::Int, QVariant::Double, QVariant::Bool are converted to
       
    65     and from the obvious equivalents.
       
    66 
       
    67   - QVariant::String is converted to/from a GConf string and always
       
    68     uses the UTF-8 encoding.  No other encoding is supported.
       
    69 
       
    70   - QVariant::StringList is converted to a list of UTF-8 strings.
       
    71 
       
    72   - QVariant::List (which denotes a QList<QVariant>) is converted
       
    73     to/from a GConf list.  All elements of such a list must have the
       
    74     same type, and that type must be one of QVariant::Int,
       
    75     QVariant::Double, QVariant::Bool, or QVariant::String.  (A list of
       
    76     strings is returned as a QVariant::StringList, however, when you
       
    77     get it back.)
       
    78 
       
    79   - Any other QVariant or GConf value is essentially ignored.
       
    80 
       
    81   \warning GConfItem is as thread-safe as GConf.
       
    82 
       
    83 */
       
    84 
       
    85 
       
    86 class GConfItem : public QObject
       
    87 {
       
    88     Q_OBJECT
       
    89 
       
    90  public:
       
    91     /*! Initializes a GConfItem to access the GConf key denoted by
       
    92         \a key.  Key names should follow the normal GConf conventions
       
    93         like "/myapp/settings/first".
       
    94 
       
    95         \param key    The name of the key.
       
    96         \param parent Parent object
       
    97     */
       
    98     explicit GConfItem(const QString &key, bool monitor = false, QObject *parent = 0);
       
    99 
       
   100     /*! Finalizes a GConfItem.
       
   101      */
       
   102     virtual ~GConfItem();
       
   103 
       
   104     /*! Returns the key of this item, as given to the constructor.
       
   105      */
       
   106     QString key() const;
       
   107 
       
   108     /*! Returns the current value of this item, as a QVariant.
       
   109      */
       
   110     QVariant value() const;
       
   111 
       
   112     /*! Returns the current value of this item, as a QVariant.  If
       
   113      *  there is no value for this item, return \a def instead.
       
   114      */
       
   115     QVariant value(const QVariant &def) const;
       
   116 
       
   117     /*! Set the value of this item to \a val.  If \a val can not be
       
   118         represented in GConf or GConf refuses to accept it for other
       
   119         reasons, the current value is not changed and nothing happens.
       
   120 
       
   121         When the new value is different from the old value, the
       
   122         changedValue() signal is emitted on this GConfItem as part
       
   123         of calling set(), but other GConfItem:s for the same key do
       
   124         only receive a notification once the main loop runs.
       
   125 
       
   126         \param val  The new value.
       
   127     */
       
   128     void set(const QVariant &val);
       
   129 
       
   130     /*! Unset this item.  This is equivalent to
       
   131 
       
   132         \code
       
   133         item.set(QVariant(QVariant::Invalid));
       
   134         \endcode
       
   135      */
       
   136     void unset();
       
   137 
       
   138     /*! Return a list of the directories below this item.  The
       
   139         returned strings are absolute key names like
       
   140         "/myapp/settings".
       
   141 
       
   142         A directory is a key that has children.  The same key might
       
   143         also have a value, but that is confusing and best avoided.
       
   144     */
       
   145     QList<QString> listDirs() const;
       
   146 
       
   147     /*! Return a list of entries below this item.  The returned
       
   148         strings are absolute key names like "/myapp/settings/first".
       
   149 
       
   150         A entry is a key that has a value.  The same key might also
       
   151         have children, but that is confusing and is best avoided.
       
   152     */
       
   153     QList<QString> listEntries() const;
       
   154 
       
   155  signals:
       
   156     /*! Emitted when the value of this item has changed.
       
   157      */
       
   158     void valueChanged();
       
   159 
       
   160     /*! Emitted when some value in subtree of this item changes
       
   161       */
       
   162 
       
   163     void subtreeChanged(const QString& key, const QVariant& value);
       
   164 
       
   165  private:
       
   166     friend struct GConfItemPrivate;
       
   167     struct GConfItemPrivate *priv;
       
   168 
       
   169     void update_value(bool emit_signal,  const QString& key, const QVariant& value);
       
   170 };
       
   171 
       
   172 #endif // GCONFITEM_H