File indexing completed on 2024-12-08 07:18:23

0001 /* This file is part of the KDE project
0002    Copyright (C) 2005 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_DBPROPERTIES_H
0021 #define KDB_DBPROPERTIES_H
0022 
0023 #include "KDbResult.h"
0024 
0025 class KDbConnection;
0026 
0027 //! @todo implement KConfigBase interface here?
0028 
0029 //! A set of storable database properties.
0030 /*! This is a convenience class that allows to store global database properties without a need
0031  for creating and maintain custom table.
0032  KDbProperties object is accessible only using KDbConnection::databaseProperties() method.
0033  */
0034 class KDB_EXPORT KDbProperties : public KDbResultable
0035 {
0036     Q_DECLARE_TR_FUNCTIONS(KDbProperties)
0037 public:
0038     ~KDbProperties() override;
0039 
0040     /*! Sets @a value for property @a name. Optional caption can be also set.
0041      If there's no such property defined, it will be added. Existing value will be overwritten.
0042      Note that to execute this method, database must be opened in read-write mode.
0043      @return true on successful data. KDbConnection */
0044     bool setValue(const QString& name, const QVariant& value);
0045 
0046     /*! Sets @a caption for for property @a name.
0047      Usually it shouldn't be translated: trnaslation can be performed before displaying. */
0048     bool setCaption(const QString& name, const QString& caption);
0049 
0050     //! @return property value for @a propeName available for this driver.
0051     //! If there's no such property defined for driver, Null QVariant value is returned.
0052     QVariant value(const QString& name);
0053 
0054     //! @return translated property caption for @a name.
0055     //! If there's no such property defined for driver, empty string value is returned.
0056     QString caption(const QString& name);
0057 
0058     //! @return a list of available property names.
0059     QStringList names();
0060 
0061 protected:
0062     explicit KDbProperties(KDbConnection *conn);
0063 
0064     KDbConnection* m_conn;
0065     friend class KDbConnectionPrivate;
0066 };
0067 
0068 #endif