File indexing completed on 2024-10-13 10:08:50

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KDB_CONNECTIONOPTIONS_H
0021 #define KDB_CONNECTIONOPTIONS_H
0022 
0023 #include <QCoreApplication>
0024 #include "KDbUtils.h"
0025 
0026 class KDbConnectionPrivate;
0027 class KDbConnection;
0028 
0029 /*! @brief Generic options for a single connection.
0030     The options are accessible using key/value pairs. This enables extensibility
0031     depending on driver's type and version.
0032     @see KDbDriver::createConnection(const KDbConnectionData&, const KDbConnectionOptions&)
0033     @see KDbConnection::options()
0034 */
0035 class KDB_EXPORT KDbConnectionOptions : public KDbUtils::PropertySet
0036 {
0037     Q_DECLARE_TR_FUNCTIONS(KDbConnectionOptions)
0038 public:
0039     KDbConnectionOptions();
0040 
0041     KDbConnectionOptions(const KDbConnectionOptions &other);
0042 
0043     ~KDbConnectionOptions();
0044 
0045     KDbConnectionOptions& operator=(const KDbConnectionOptions &other);
0046 
0047     //! @return true if these options have exactly the same values as @a other
0048     //! @since 3.1
0049     bool operator==(const KDbConnectionOptions &other) const;
0050 
0051     //! @return true if these options differs in at least one value from @a other
0052     //! @since 3.1
0053     bool operator!=(const KDbConnectionOptions &other) const { return !operator==(other); }
0054 
0055     /*! @return true for read-only connection. Used especially for file-based drivers.
0056      Can be implemented in a driver to provide real read-only flag of the connection
0057      (sqlite driver does this). */
0058     bool isReadOnly() const;
0059 
0060     /*! @internal used by KDbDriver::createConnection().
0061      Only works if connection is not yet established. */
0062     void setReadOnly(bool set);
0063 
0064     //! Inserts option with a given @a name, @a value and @a caption.
0065     //! If such option exists, value is updated but caption only if existing caption is empty.
0066     //! @a name must be a valid identifier (see KDb::isIdentifier()).
0067     void insert(const QByteArray &name, const QVariant &value, const QString &caption = QString());
0068 
0069     //! Sets caption for option @a name to @a caption.
0070     //! If such option does not exist, does nothing.
0071     void setCaption(const QByteArray &name, const QString &caption);
0072 
0073     //! Sets value for option @a name to @a value.
0074     //! If such option does not exist, does nothing.
0075     //! @since 3.1
0076     void setValue(const QByteArray &name, const QVariant &value);
0077 
0078     //! Removes option with a given @a name if exists.
0079     void remove(const QByteArray &name);
0080 
0081 private:
0082     void setConnection(KDbConnection *connection);
0083 
0084     friend class KDbConnectionPrivate;
0085 
0086     class Private;
0087     Private * const d;
0088 };
0089 
0090 #endif