kexi

keximigrate.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Adam Pigg <adam@piggz.co.uk>
00003    Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl>
00004    Copyright (C) 2005 Martin Ellis <martin.ellis@kdemail.net>
00005 
00006    This program is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this program; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KEXI_MIGRATE_H
00023 #define KEXI_MIGRATE_H
00024 
00025 
00026 #include "kexidb/tableschema.h"
00027 #include "keximigratedata.h"
00028 
00029 #include <kgenericfactory.h>
00030 #include <qstringlist.h>
00031 
00032 class KexiProject;
00033 namespace Kexi
00034 {
00035     class ObjectStatus;
00036 }
00037 
00045 #define KEXI_MIGRATION_VERSION_MAJOR 1
00046 #define KEXI_MIGRATION_VERSION_MINOR 1
00047 
00052 namespace KexiMigration 
00053 {
00054 
00056 KEXIMIGR_EXPORT int versionMajor();
00057 
00059 KEXIMIGR_EXPORT int versionMinor();
00060 
00061 
00063 
00076 class KEXIMIGR_EXPORT KexiMigrate : public QObject, public KexiDB::Object
00077 {
00078     Q_OBJECT
00079 
00080     public:
00081         virtual ~KexiMigrate();
00082 
00084         KexiMigration::Data* data() const { return m_migrateData; }
00085 
00088         void setData(KexiMigration::Data* migrateData);
00089 
00099         bool checkIfDestinationDatabaseOverwritingNeedsAccepting(Kexi::ObjectStatus* result,
00100             bool& acceptingNeeded);
00101 
00104         bool isSourceAndDestinationDataSourceTheSame() const;
00105 
00107         bool performImport(Kexi::ObjectStatus* result = 0);
00108 
00110         bool performExport(Kexi::ObjectStatus* result = 0);
00111 
00113         inline bool progressSupported() { return drv_progressSupported(); }
00114 
00115         virtual int versionMajor() const = 0;
00116         virtual int versionMinor() const = 0;
00117 
00121         virtual QVariant propertyValue( const QCString& propName );
00122 
00124         void setPropertyValue( const QCString& propName, const QVariant& value );
00125 
00129         QString propertyCaption( const QCString& propName ) const;
00130 
00133         QValueList<QCString> propertyNames() const;
00134 
00138         virtual bool isValid();
00139 
00140     signals:
00141         void progressPercent(int percent);
00142 
00143     protected:
00145         KexiMigrate(QObject *parent, const char *name, const QStringList &args = QStringList());
00146 
00148         virtual bool drv_connect() = 0;
00150         virtual bool drv_disconnect() = 0;
00151 
00153         virtual bool drv_tableNames(QStringList& tablenames) = 0;
00154 
00156         virtual bool drv_readTableSchema(
00157             const QString& originalName, KexiDB::TableSchema& tableSchema) = 0;
00158 
00160         virtual bool drv_copyTable(const QString& srcTable, KexiDB::Connection *destConn, 
00161             KexiDB::TableSchema* dstTable) = 0;
00162 
00163         virtual bool drv_progressSupported() { return false; }
00164 
00182         virtual bool drv_getTableSize(const QString&, Q_ULLONG&)
00183         { return false; }
00184 
00185         void updateProgress(Q_ULLONG step = 1ULL);
00186 
00189         KexiDB::Field::Type userType(const QString& fname);
00190 
00193         KexiMigration::Data* m_migrateData;
00194 
00195 //          // Temporary values used during import (set by driver specific methods)
00196 //          KexiDB::Field* m_f;
00197 
00201         QMap<QCString,QVariant> m_properties;
00202 
00206         QMap<QCString,QString> m_propertyCaptions;
00207 
00208     private:
00210         bool tableNames(QStringList& tablenames);
00211 
00213         KexiProject* createProject(Kexi::ObjectStatus* result);
00214 
00215 //      //Private data members
00216 //      //! Flag indicating whether data should be copied
00217 //      bool m_keepData;
00218 
00220         QPtrList<KexiDB::TableSchema> m_tableSchemas;
00221 
00223 
00226         bool progressInitialise();
00227 
00228         KexiProject *m_destPrj;
00229 
00231         Q_ULLONG m_progressTotal;
00233         Q_ULLONG m_progressDone;
00235         Q_ULLONG m_progressNextReport;
00236 
00237         friend class MigrateManager;
00238 };
00239 
00240 } //namespace KexiMigration
00241 
00244 #define KEXIMIGRATE_DRIVER_INFO( class_name, internal_name ) \
00245     int class_name::versionMajor() const { return KEXI_MIGRATION_VERSION_MAJOR; } \
00246     int class_name::versionMinor() const { return KEXI_MIGRATION_VERSION_MINOR; } \
00247     K_EXPORT_COMPONENT_FACTORY(keximigrate_ ## internal_name, \
00248       KGenericFactory<KexiMigration::class_name>( "keximigrate_" #internal_name ))
00249 
00252 #define KEXIMIGRATION_DRIVER \
00253     public: \
00254     virtual int versionMajor() const; \
00255     virtual int versionMinor() const;
00256 
00257 #endif
00258 
KDE Home | KDE Accessibility Home | Description of Access Keys