File indexing completed on 2024-05-12 16:39:40
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at> 0003 Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library 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 GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KEXIPROJECTDATA_H 0022 #define KEXIPROJECTDATA_H 0023 0024 #include "kexicore_export.h" 0025 0026 #include <KDbConnectionData> 0027 #include <KDbResult> 0028 #include <KDbObject> 0029 0030 #include <KLocalizedString> 0031 0032 #include <QDateTime> 0033 #include <QList> 0034 0035 class KexiProjectDataPrivate; 0036 0037 /** @short Kexi project core data member 0038 0039 Contains: 0040 - project name 0041 - database name 0042 - connection data 0043 - date and time of last opening 0044 0045 @todo make it value-based class 0046 */ 0047 class KEXICORE_EXPORT KexiProjectData : public QObject, public KDbObject, public KDbResultable 0048 { 0049 Q_OBJECT 0050 public: 0051 typedef QList<KexiProjectData*> List; 0052 typedef QHash<QByteArray, QString> ObjectInfo; 0053 typedef QList<ObjectInfo> AutoOpenObjects; 0054 0055 KexiProjectData(); 0056 0057 /*! Creates project data out of connection data @a cdata. 0058 @a dbname can be provided for server-based connections; it is ignored 0059 for file-based onces because in this case name is equal to database's filename 0060 (cdata.databaseName()). 0061 @a caption is for setting project's caption. */ 0062 explicit KexiProjectData(const KDbConnectionData &cdata, 0063 const QString& dbname = QString(), const QString& caption = QString()); 0064 0065 /*! Constructs a copy of \a pdata */ 0066 KexiProjectData(const KexiProjectData& pdata); 0067 0068 ~KexiProjectData(); 0069 0070 /*! Loads project data (with connection data) from @a fileName. 0071 Database name and caption can be set there but these are optional. 0072 @a groupKey, if provided will be set to a group key, 0073 so you can later use it in saveConnectionData(). 0074 @return true on success. */ 0075 bool load(const QString& fileName, QString* _groupKey = 0); 0076 0077 /*! Saves project data (with connection data) to a shortcut file @a fileName. 0078 If @a storePassword is true, password will be saved in the file, 0079 even if data.connectionData()->savePassword is false. 0080 Existing data is merged with new data. @a groupKey is reused, if specified. 0081 If @a overwriteFirstGroup is true (the default) first found group will be overwritten 0082 instead of creating of a new unique group. This mode is usable for updating .kexic files 0083 containing single connection data, what's used for storing connections repository. 0084 @return true on success. */ 0085 bool save(const QString& fileName, bool savePassword, 0086 QString* groupKey = 0, bool overwriteFirstGroup = true); 0087 0088 KexiProjectData& operator=(const KexiProjectData& pdata); 0089 0090 /*! \return true if there is the User Mode set in internal 0091 project settings. */ 0092 bool userMode() const; 0093 0094 KDbConnectionData* connectionData(); 0095 0096 const KDbConnectionData* connectionData() const; 0097 0098 /*! \return database name. 0099 In fact, this is the same as KDbObject::name() */ 0100 QString databaseName() const; 0101 0102 void setDatabaseName(const QString& dbName); 0103 0104 /*! \return user-visible string better describing the project than just databaseName(). 0105 For server-based projects returns i18n'd string: 0106 "<project name>" (connection: user\@server:port). 0107 For file-based projects returns project's filename. 0108 If \a format controls format of the message (useful for displaying in message boxes). */ 0109 KLocalizedString infoString() const; 0110 0111 //! @overload QString infoString() const; 0112 //! @todo move to KDb? 0113 static KLocalizedString infoString(const QString &databaseName, const KDbConnectionData &data); 0114 0115 QDateTime lastOpened() const; 0116 0117 void setLastOpened(const QDateTime& lastOpened); 0118 0119 QString description() const; 0120 0121 void setDescription(const QString& desc); 0122 0123 /*! If \a set is true, sets readonly flag for this data, so any connection opened for the project will 0124 be readonly. Change this flag before using this data in KexiProject instance, 0125 otherwise you will need to reopen the project. */ 0126 void setReadOnly(bool set); 0127 0128 /*! \return readonly flag. False by default. 0129 @see setReadOnly() */ 0130 bool isReadOnly() const; 0131 0132 /*! objects to open on startup (come from command line "-open" option) 0133 It's public for convenience */ 0134 AutoOpenObjects autoopenObjects; 0135 0136 /*! @internal 0137 Format version used when saving the data to a shortcut file. 0138 This is set to 0 by default what means KexiDBShortcutFile_version should be used on saving. 0139 If KexiDBShortcutFile was used to create this KexiProjectData object, 0140 the version information is retrieved from the file. */ 0141 int formatVersion; 0142 0143 private: 0144 KexiProjectDataPrivate * const d; 0145 }; 0146 0147 KEXICORE_EXPORT QDebug operator<<(QDebug dbg, const KexiProjectData& data); 0148 0149 #endif