File indexing completed on 2024-05-12 16:39:36

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003-2014 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 KEXIDBCONNECTIONSET_H
0021 #define KEXIDBCONNECTIONSET_H
0022 
0023 #include "kexicore_export.h"
0024 
0025 #include <QObject>
0026 #include <KDbResult>
0027 #include <KDbConnectionData>
0028 
0029 class KexiDBConnectionSetPrivate;
0030 
0031 /*! Stores information about multiple connection-data items. */
0032 class KEXICORE_EXPORT KexiDBConnectionSet : public QObject, public KDbResultable
0033 {
0034     Q_OBJECT
0035 public:
0036     KexiDBConnectionSet();
0037     ~KexiDBConnectionSet();
0038 
0039     /*! Loads connection data set from storage, currently from
0040      .kexic files saved in dirs returned by
0041      QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "kexi/connections") */
0042     void load();
0043 
0044     /*! Adds \a data as connection data.
0045      \a data will be owned by a KexiDBConnectionSet object.
0046      If \a filename is not empty, it will be kept for use in saveConnectionData().
0047      saveConnectionData() is called automatically, if there's no \a filename provided
0048      or the filename is already used, a new unique will be generated.
0049      \return true on successful creating corresponding .kexic file */
0050     bool addConnectionData(KDbConnectionData *data, const QString& filename = QString());
0051 
0052     /*! Saves changes made to \a oldData to a file which name has been provided by addConnectionData().
0053      This function does nothing if \a oldData hasn't been added to this set.
0054      \return true on success (data is then copied from \a newData to \a oldData) */
0055     bool saveConnectionData(KDbConnectionData *oldData, const KDbConnectionData &newData);
0056 
0057     /*! Removes \a data from this set without deleting the object.
0058      \return true on successful removing of corresponding .kexic file */
0059     bool removeConnectionData(KDbConnectionData *data);
0060 
0061     /*! \return the list of connection data items. */
0062     QList<KDbConnectionData*> list() const;
0063 
0064     /*! \return a filename of a connection data file for \a data. */
0065     QString fileNameForConnectionData(const KDbConnectionData &data) const;
0066 
0067     /*! \return a connection data for a .kexic shortcut filename.
0068      0 is returned if the filename does not match. */
0069     KDbConnectionData* connectionDataForFileName(const QString& fileName) const;
0070 
0071     /*! \return key for connection data @a data, basically a comma-separated string with
0072      all properties serialized: "driverId,userName,...". Used in internal structures. */
0073     static QString key(const KDbConnectionData &data);
0074 
0075 private:
0076     /*! Removes all connection data items from this set. */
0077     void clear();
0078     void addConnectionDataInternal(KDbConnectionData *data, const QString& filename);
0079     void removeConnectionDataInternal(KDbConnectionData *data);
0080 
0081     KexiDBConnectionSetPrivate * const d;
0082 };
0083 
0084 #endif // KEXIDBCONNSET_H