mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-24 20:44:39 +03:00
Database connections have been refactored
keepDbCredentials property has been added to Connection setPassPharse(QString& passPharse) method has been added to ReportEngine IDbCredentialsProvider interface has been added registerDbCredentialsProvider(IDbCredentialsProvider *provider) has been added to IDataSourceManager
This commit is contained in:
parent
fa985d7fb7
commit
ce3a905c55
@ -37,18 +37,25 @@ class QString;
|
|||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
namespace LimeReport{
|
namespace LimeReport{
|
||||||
|
|
||||||
|
class IDbCredentialsProvider{
|
||||||
|
public:
|
||||||
|
virtual QString getUserName(const QString& connectionName) = 0;
|
||||||
|
virtual QString getPassword(const QString& connectionName) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class IDataSourceManager{
|
class IDataSourceManager{
|
||||||
public:
|
public:
|
||||||
virtual void setReportVariable(const QString& name, const QVariant& value)=0;
|
virtual void setReportVariable(const QString& name, const QVariant& value) = 0;
|
||||||
virtual void setDefaultDatabasePath(const QString &defaultDatabasePath)=0;
|
virtual void setDefaultDatabasePath(const QString &defaultDatabasePath) = 0;
|
||||||
virtual void deleteVariable(const QString& name)=0;
|
virtual void deleteVariable(const QString& name) = 0;
|
||||||
virtual bool containsVariable(const QString& variableName)=0;
|
virtual bool containsVariable(const QString& variableName) = 0;
|
||||||
virtual QVariant variable(const QString& variableName)=0;
|
virtual QVariant variable(const QString& variableName) = 0;
|
||||||
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned)=0;
|
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned) = 0;
|
||||||
virtual void removeModel(const QString& name)=0;
|
virtual void removeModel(const QString& name) = 0;
|
||||||
virtual bool containsDatasource(const QString& dataSourceName)=0;
|
virtual bool containsDatasource(const QString& dataSourceName) = 0;
|
||||||
virtual void clearUserVariables()=0;
|
virtual void clearUserVariables()=0;
|
||||||
virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0;
|
virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0;
|
||||||
|
virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0;
|
||||||
//virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0;
|
//virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ public:
|
|||||||
void setResultEditable(bool value);
|
void setResultEditable(bool value);
|
||||||
bool resultIsEditable();
|
bool resultIsEditable();
|
||||||
bool isBusy();
|
bool isBusy();
|
||||||
|
void setPassPharse(QString& passPharse);
|
||||||
signals:
|
signals:
|
||||||
void renderStarted();
|
void renderStarted();
|
||||||
void renderFinished();
|
void renderFinished();
|
||||||
|
@ -122,6 +122,7 @@ ConnectionDesc *ConnectionDialog::uiToConnection(LimeReport::ConnectionDesc* con
|
|||||||
result ->setPassword(ui->lePassword->text());
|
result ->setPassword(ui->lePassword->text());
|
||||||
result ->setDatabaseName(ui->leDataBase->text());
|
result ->setDatabaseName(ui->leDataBase->text());
|
||||||
result ->setAutoconnect(ui->cbAutoConnect->isChecked());
|
result ->setAutoconnect(ui->cbAutoConnect->isChecked());
|
||||||
|
result->setKeepDBCredentials(!ui->cbbKeepCredentials->isChecked());
|
||||||
return result ;
|
return result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +138,7 @@ void ConnectionDialog::connectionToUI()
|
|||||||
ui->lePassword->setText(m_connection->password());
|
ui->lePassword->setText(m_connection->password());
|
||||||
ui->cbbDrivers->setCurrentIndex(ui->cbbDrivers->findText(m_connection->driver()));
|
ui->cbbDrivers->setCurrentIndex(ui->cbbDrivers->findText(m_connection->driver()));
|
||||||
ui->cbAutoConnect->setChecked(m_connection->autoconnect());
|
ui->cbAutoConnect->setChecked(m_connection->autoconnect());
|
||||||
|
ui->cbbKeepCredentials->setChecked(!m_connection->keepDBCredentials());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionDialog::on_toolButton_clicked()
|
void ConnectionDialog::on_toolButton_clicked()
|
||||||
|
@ -137,6 +137,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="cbbKeepCredentials">
|
||||||
|
<property name="text">
|
||||||
|
<string>Dont keep credentals in lrxml</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -351,13 +351,13 @@ void ModelToDataSource::slotModelDestroed()
|
|||||||
ConnectionDesc::ConnectionDesc(QSqlDatabase db, QObject *parent)
|
ConnectionDesc::ConnectionDesc(QSqlDatabase db, QObject *parent)
|
||||||
: QObject(parent), m_connectionName(db.connectionName()), m_connectionHost(db.hostName()), m_connectionDriver(db.driverName()),
|
: QObject(parent), m_connectionName(db.connectionName()), m_connectionHost(db.hostName()), m_connectionDriver(db.driverName()),
|
||||||
m_databaseName(db.databaseName()), m_user(db.userName()), m_password(db.password()), m_autoconnect(false),
|
m_databaseName(db.databaseName()), m_user(db.userName()), m_password(db.password()), m_autoconnect(false),
|
||||||
m_internal(false)
|
m_internal(false), m_keepDBCredentials(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ConnectionDesc::ConnectionDesc(QObject *parent)
|
ConnectionDesc::ConnectionDesc(QObject *parent)
|
||||||
:QObject(parent),m_connectionName(""),m_connectionHost(""),m_connectionDriver(""),
|
:QObject(parent),m_connectionName(""),m_connectionHost(""),m_connectionDriver(""),
|
||||||
m_databaseName(""), m_user(""), m_password(""), m_autoconnect(false),
|
m_databaseName(""), m_user(""), m_password(""), m_autoconnect(false),
|
||||||
m_internal(false)
|
m_internal(false), m_keepDBCredentials(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ConnectionDesc::Ptr ConnectionDesc::create(QSqlDatabase db, QObject *parent)
|
ConnectionDesc::Ptr ConnectionDesc::create(QSqlDatabase db, QObject *parent)
|
||||||
@ -391,6 +391,16 @@ QString ConnectionDesc::connectionNameForReport(const QString &connectionName)
|
|||||||
return connectionName.compare(tr("defaultConnection")) == 0 ? QSqlDatabase::defaultConnection : connectionName;
|
return connectionName.compare(tr("defaultConnection")) == 0 ? QSqlDatabase::defaultConnection : connectionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ConnectionDesc::keepDBCredentials() const
|
||||||
|
{
|
||||||
|
return m_keepDBCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionDesc::setKeepDBCredentials(bool keepDBCredentals)
|
||||||
|
{
|
||||||
|
m_keepDBCredentials = keepDBCredentals;
|
||||||
|
}
|
||||||
|
|
||||||
QueryDesc::QueryDesc(QString queryName, QString queryText, QString connection)
|
QueryDesc::QueryDesc(QString queryName, QString queryText, QString connection)
|
||||||
:m_queryName(queryName), m_queryText(queryText), m_connectionName(connection)
|
:m_queryName(queryName), m_queryText(queryText), m_connectionName(connection)
|
||||||
{}
|
{}
|
||||||
|
@ -110,6 +110,7 @@ class ConnectionDesc : public QObject{
|
|||||||
Q_PROPERTY(QString password READ password WRITE setPassword)
|
Q_PROPERTY(QString password READ password WRITE setPassword)
|
||||||
Q_PROPERTY(QString host READ host WRITE setHost)
|
Q_PROPERTY(QString host READ host WRITE setHost)
|
||||||
Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect)
|
Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect)
|
||||||
|
Q_PROPERTY(bool keepDBCredentials READ keepDBCredentials WRITE setKeepDBCredentials)
|
||||||
public:
|
public:
|
||||||
typedef QSharedPointer<ConnectionDesc> Ptr;
|
typedef QSharedPointer<ConnectionDesc> Ptr;
|
||||||
ConnectionDesc(QSqlDatabase db, QObject* parent=0);
|
ConnectionDesc(QSqlDatabase db, QObject* parent=0);
|
||||||
@ -124,14 +125,16 @@ public:
|
|||||||
void setDatabaseName(const QString &value){m_databaseName=value;}
|
void setDatabaseName(const QString &value){m_databaseName=value;}
|
||||||
QString databaseName(){return m_databaseName;}
|
QString databaseName(){return m_databaseName;}
|
||||||
void setUserName(const QString &value){m_user=value;}
|
void setUserName(const QString &value){m_user=value;}
|
||||||
QString userName(){return m_user;}
|
QString userName(){ return m_user; }
|
||||||
void setPassword(const QString &value){m_password=value;}
|
void setPassword(const QString &value){m_password=value;}
|
||||||
QString password(){return m_password;}
|
QString password(){ return m_password; }
|
||||||
void setAutoconnect(bool value){m_autoconnect=value;}
|
void setAutoconnect(bool value){m_autoconnect=value;}
|
||||||
bool autoconnect(){return m_autoconnect;}
|
bool autoconnect(){return m_autoconnect;}
|
||||||
bool isEqual(const QSqlDatabase& db);
|
bool isEqual(const QSqlDatabase& db);
|
||||||
bool isInternal(){ return m_internal; }
|
bool isInternal(){ return m_internal; }
|
||||||
void setInternal(bool value) {m_internal = value;}
|
void setInternal(bool value) {m_internal = value;}
|
||||||
|
bool keepDBCredentials() const;
|
||||||
|
void setKeepDBCredentials(bool keepDBCredentials);
|
||||||
public:
|
public:
|
||||||
static QString connectionNameForUser(const QString& connectionName);
|
static QString connectionNameForUser(const QString& connectionName);
|
||||||
static QString connectionNameForReport(const QString& connectionName);
|
static QString connectionNameForReport(const QString& connectionName);
|
||||||
@ -146,6 +149,7 @@ private:
|
|||||||
QString m_password;
|
QString m_password;
|
||||||
bool m_autoconnect;
|
bool m_autoconnect;
|
||||||
bool m_internal;
|
bool m_internal;
|
||||||
|
bool m_keepDBCredentials;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IConnectionController{
|
class IConnectionController{
|
||||||
|
@ -217,7 +217,7 @@ void DataSourceModel::updateModel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
DataSourceManager::DataSourceManager(QObject *parent) :
|
DataSourceManager::DataSourceManager(QObject *parent) :
|
||||||
QObject(parent), m_lastError(""), m_designTime(true), m_needUpdate(false)
|
QObject(parent), m_lastError(""), m_designTime(true), m_needUpdate(false), m_dbCredentialsProvider(0)
|
||||||
{
|
{
|
||||||
m_groupFunctionFactory.registerFunctionCreator(QLatin1String("COUNT"),new ConstructorGroupFunctionCreator<CountGroupFunction>);
|
m_groupFunctionFactory.registerFunctionCreator(QLatin1String("COUNT"),new ConstructorGroupFunctionCreator<CountGroupFunction>);
|
||||||
m_groupFunctionFactory.registerFunctionCreator(QLatin1String("SUM"),new ConstructorGroupFunctionCreator<SumGroupFunction>);
|
m_groupFunctionFactory.registerFunctionCreator(QLatin1String("SUM"),new ConstructorGroupFunctionCreator<SumGroupFunction>);
|
||||||
@ -324,6 +324,11 @@ ICallbackDatasource *DataSourceManager::createCallbackDatasouce(const QString& n
|
|||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataSourceManager::registerDbCredentialsProvider(IDbCredentialsProvider *provider)
|
||||||
|
{
|
||||||
|
m_dbCredentialsProvider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
void DataSourceManager::addCallbackDatasource(ICallbackDatasource *datasource, const QString& name)
|
void DataSourceManager::addCallbackDatasource(ICallbackDatasource *datasource, const QString& name)
|
||||||
{
|
{
|
||||||
IDataSource* datasourceIntf = dynamic_cast<IDataSource*>(datasource);
|
IDataSource* datasourceIntf = dynamic_cast<IDataSource*>(datasource);
|
||||||
@ -567,6 +572,11 @@ int DataSourceManager::connectionIndexByName(const QString &connectionName)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ConnectionDesc *>& DataSourceManager::conections()
|
||||||
|
{
|
||||||
|
return m_connections;
|
||||||
|
}
|
||||||
|
|
||||||
bool DataSourceManager::dataSourceIsValid(const QString &name)
|
bool DataSourceManager::dataSourceIsValid(const QString &name)
|
||||||
{
|
{
|
||||||
if (m_datasources.value(name.toLower())) return !m_datasources.value(name.toLower())->isInvalid();
|
if (m_datasources.value(name.toLower())) return !m_datasources.value(name.toLower())->isInvalid();
|
||||||
@ -704,10 +714,19 @@ void DataSourceManager::putProxyDesc(ProxyDesc *proxyDesc)
|
|||||||
bool DataSourceManager::initAndOpenDB(QSqlDatabase& db, ConnectionDesc& connectionDesc){
|
bool DataSourceManager::initAndOpenDB(QSqlDatabase& db, ConnectionDesc& connectionDesc){
|
||||||
|
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
|
|
||||||
|
|
||||||
db.setHostName(replaceVariables(connectionDesc.host()));
|
db.setHostName(replaceVariables(connectionDesc.host()));
|
||||||
db.setUserName(replaceVariables(connectionDesc.userName()));
|
db.setUserName(replaceVariables(connectionDesc.userName()));
|
||||||
db.setPassword(replaceVariables(connectionDesc.password()));
|
db.setPassword(replaceVariables(connectionDesc.password()));
|
||||||
|
|
||||||
|
if (!connectionDesc.keepDBCredentials() && m_dbCredentialsProvider){
|
||||||
|
if (!m_dbCredentialsProvider->getUserName(connectionDesc.name()).isEmpty())
|
||||||
|
db.setUserName(m_dbCredentialsProvider->getUserName(connectionDesc.name()));
|
||||||
|
if (!m_dbCredentialsProvider->getPassword(connectionDesc.name()).isEmpty())
|
||||||
|
db.setPassword(m_dbCredentialsProvider->getPassword(connectionDesc.name()));
|
||||||
|
}
|
||||||
|
|
||||||
QString dbName = replaceVariables(connectionDesc.databaseName());
|
QString dbName = replaceVariables(connectionDesc.databaseName());
|
||||||
if (connectionDesc.driver().compare("QSQLITE")==0){
|
if (connectionDesc.driver().compare("QSQLITE")==0){
|
||||||
if (!defaultDatabasePath().isEmpty()){
|
if (!defaultDatabasePath().isEmpty()){
|
||||||
@ -726,7 +745,6 @@ bool DataSourceManager::initAndOpenDB(QSqlDatabase& db, ConnectionDesc& connecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
connected=db.open();
|
connected=db.open();
|
||||||
connectionDesc.setInternal(true);
|
|
||||||
if (!connected) setLastError(db.lastError().text());
|
if (!connected) setLastError(db.lastError().text());
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
@ -758,10 +776,17 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!QSqlDatabase::contains(connectionDesc->name())){
|
if (!QSqlDatabase::contains(connectionDesc->name())){
|
||||||
QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name());
|
QString dbError;
|
||||||
connected=initAndOpenDB(db, *connectionDesc);
|
{
|
||||||
|
QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name());
|
||||||
|
connectionDesc->setInternal(true);
|
||||||
|
connected=initAndOpenDB(db, *connectionDesc);
|
||||||
|
dbError = db.lastError().text();
|
||||||
|
}
|
||||||
if (!connected){
|
if (!connected){
|
||||||
setLastError(db.lastError().text());
|
if (!dbError.trimmed().isEmpty())
|
||||||
|
setLastError(dbError);
|
||||||
|
QSqlDatabase::removeDatabase(connectionDesc->name());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -868,8 +893,9 @@ bool DataSourceManager::isConnection(const QString &connectionName)
|
|||||||
|
|
||||||
bool DataSourceManager::isConnectionConnected(const QString &connectionName)
|
bool DataSourceManager::isConnectionConnected(const QString &connectionName)
|
||||||
{
|
{
|
||||||
if (isConnection(connectionName)){
|
if (isConnection(connectionName) && QSqlDatabase::contains(connectionName)){
|
||||||
return QSqlDatabase::database(connectionName).isOpen();
|
QSqlDatabase db = QSqlDatabase::database(connectionName);
|
||||||
|
return db.isValid() && QSqlDatabase::database(connectionName).isOpen();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -893,8 +919,10 @@ void DataSourceManager::disconnectConnection(const QString& connectionName)
|
|||||||
|
|
||||||
ConnectionDesc* connectionDesc = connectionByName(connectionName);
|
ConnectionDesc* connectionDesc = connectionByName(connectionName);
|
||||||
if (connectionDesc->isInternal()){
|
if (connectionDesc->isInternal()){
|
||||||
QSqlDatabase db = QSqlDatabase::database(connectionName);
|
{
|
||||||
if (db.isOpen()) db.close();
|
QSqlDatabase db = QSqlDatabase::database(connectionName);
|
||||||
|
if (db.isOpen()) db.close();
|
||||||
|
}
|
||||||
if (QSqlDatabase::contains(connectionName)) QSqlDatabase::removeDatabase(connectionName);
|
if (QSqlDatabase::contains(connectionName)) QSqlDatabase::removeDatabase(connectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,7 @@ public:
|
|||||||
bool addModel(const QString& name, QAbstractItemModel *model, bool owned);
|
bool addModel(const QString& name, QAbstractItemModel *model, bool owned);
|
||||||
void removeModel(const QString& name);
|
void removeModel(const QString& name);
|
||||||
ICallbackDatasource* createCallbackDatasouce(const QString &name);
|
ICallbackDatasource* createCallbackDatasouce(const QString &name);
|
||||||
|
void registerDbCredentialsProvider(IDbCredentialsProvider *provider);
|
||||||
void addCallbackDatasource(ICallbackDatasource *datasource, const QString &name);
|
void addCallbackDatasource(ICallbackDatasource *datasource, const QString &name);
|
||||||
void setReportVariable(const QString& name, const QVariant& value);
|
void setReportVariable(const QString& name, const QVariant& value);
|
||||||
void deleteVariable(const QString& name);
|
void deleteVariable(const QString& name);
|
||||||
@ -150,6 +151,7 @@ public:
|
|||||||
int proxyIndexByName(const QString& dataSourceName);
|
int proxyIndexByName(const QString& dataSourceName);
|
||||||
int connectionIndexByName(const QString& connectionName);
|
int connectionIndexByName(const QString& connectionName);
|
||||||
|
|
||||||
|
QList<ConnectionDesc *> &conections();
|
||||||
bool dataSourceIsValid(const QString& name);
|
bool dataSourceIsValid(const QString& name);
|
||||||
IDataSource* dataSource(const QString& name);
|
IDataSource* dataSource(const QString& name);
|
||||||
IDataSourceHolder* dataSourceHolder(const QString& name);
|
IDataSourceHolder* dataSourceHolder(const QString& name);
|
||||||
@ -250,8 +252,7 @@ private:
|
|||||||
ReportSettings* m_reportSettings;
|
ReportSettings* m_reportSettings;
|
||||||
QHash<QString,int> m_groupFunctionsExpressionsMap;
|
QHash<QString,int> m_groupFunctionsExpressionsMap;
|
||||||
QVector<QString> m_groupFunctionsExpressions;
|
QVector<QString> m_groupFunctionsExpressions;
|
||||||
|
IDbCredentialsProvider* m_dbCredentialsProvider;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,18 +37,25 @@ class QString;
|
|||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
namespace LimeReport{
|
namespace LimeReport{
|
||||||
|
|
||||||
|
class IDbCredentialsProvider{
|
||||||
|
public:
|
||||||
|
virtual QString getUserName(const QString& connectionName) = 0;
|
||||||
|
virtual QString getPassword(const QString& connectionName) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class IDataSourceManager{
|
class IDataSourceManager{
|
||||||
public:
|
public:
|
||||||
virtual void setReportVariable(const QString& name, const QVariant& value)=0;
|
virtual void setReportVariable(const QString& name, const QVariant& value) = 0;
|
||||||
virtual void setDefaultDatabasePath(const QString &defaultDatabasePath)=0;
|
virtual void setDefaultDatabasePath(const QString &defaultDatabasePath) = 0;
|
||||||
virtual void deleteVariable(const QString& name)=0;
|
virtual void deleteVariable(const QString& name) = 0;
|
||||||
virtual bool containsVariable(const QString& variableName)=0;
|
virtual bool containsVariable(const QString& variableName) = 0;
|
||||||
virtual QVariant variable(const QString& variableName)=0;
|
virtual QVariant variable(const QString& variableName) = 0;
|
||||||
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned)=0;
|
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned) = 0;
|
||||||
virtual void removeModel(const QString& name)=0;
|
virtual void removeModel(const QString& name) = 0;
|
||||||
virtual bool containsDatasource(const QString& dataSourceName)=0;
|
virtual bool containsDatasource(const QString& dataSourceName) = 0;
|
||||||
virtual void clearUserVariables()=0;
|
virtual void clearUserVariables()=0;
|
||||||
virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0;
|
virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0;
|
||||||
|
virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0;
|
||||||
//virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0;
|
//virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) :
|
|||||||
m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false),
|
m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false),
|
||||||
m_showProgressDialog(true), m_reportName(""), m_activePreview(0),
|
m_showProgressDialog(true), m_reportName(""), m_activePreview(0),
|
||||||
m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")),
|
m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")),
|
||||||
m_reportRendering(false), m_resultIsEditable(true)
|
m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy")
|
||||||
{
|
{
|
||||||
m_datasources = new DataSourceManager(this);
|
m_datasources = new DataSourceManager(this);
|
||||||
m_datasources->setReportSettings(&m_reportSettings);
|
m_datasources->setReportSettings(&m_reportSettings);
|
||||||
@ -516,11 +516,26 @@ bool ReportEnginePrivate::loadFromFile(const QString &fileName)
|
|||||||
clearReport();
|
clearReport();
|
||||||
|
|
||||||
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);
|
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);
|
||||||
|
reader->setPassPhrase(m_passPhrase);
|
||||||
if (reader->first()){
|
if (reader->first()){
|
||||||
if (reader->readItem(this)){
|
if (reader->readItem(this)){
|
||||||
m_fileName=fileName;
|
m_fileName=fileName;
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
m_reportName = fi.fileName();
|
m_reportName = fi.fileName();
|
||||||
|
|
||||||
|
QString dbSettingFileName = fi.absolutePath()+"/"+fi.baseName()+".db";
|
||||||
|
if (QFile::exists(dbSettingFileName)){
|
||||||
|
QSettings dbcredentals(dbSettingFileName, QSettings::IniFormat);
|
||||||
|
foreach (ConnectionDesc* connection, dataManager()->conections()) {
|
||||||
|
if (!connection->keepDBCredentials()){
|
||||||
|
dbcredentals.beginGroup(connection->name());
|
||||||
|
connection->setUserName(dbcredentals.value("user").toString());
|
||||||
|
connection->setPassword(dbcredentals.value("password").toString());
|
||||||
|
dbcredentals.endGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dataManager()->connectAutoConnections();
|
dataManager()->connectAutoConnections();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -533,6 +548,7 @@ bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString &nam
|
|||||||
clearReport();
|
clearReport();
|
||||||
|
|
||||||
ItemsReaderIntf::Ptr reader = ByteArrayXMLReader::create(data);
|
ItemsReaderIntf::Ptr reader = ByteArrayXMLReader::create(data);
|
||||||
|
reader->setPassPhrase(m_passPhrase);
|
||||||
if (reader->first()){
|
if (reader->first()){
|
||||||
if (reader->readItem(this)){
|
if (reader->readItem(this)){
|
||||||
m_fileName = "";
|
m_fileName = "";
|
||||||
@ -548,6 +564,7 @@ bool ReportEnginePrivate::loadFromString(const QString &report, const QString &n
|
|||||||
clearReport();
|
clearReport();
|
||||||
|
|
||||||
ItemsReaderIntf::Ptr reader = StringXMLreader::create(report);
|
ItemsReaderIntf::Ptr reader = StringXMLreader::create(report);
|
||||||
|
reader->setPassPhrase(m_passPhrase);
|
||||||
if (reader->first()){
|
if (reader->first()){
|
||||||
if (reader->readItem(this)){
|
if (reader->readItem(this)){
|
||||||
m_fileName = "";
|
m_fileName = "";
|
||||||
@ -566,10 +583,35 @@ bool ReportEnginePrivate::saveToFile(const QString &fileName)
|
|||||||
if (fi.suffix().isEmpty())
|
if (fi.suffix().isEmpty())
|
||||||
fn+=".lrxml";
|
fn+=".lrxml";
|
||||||
|
|
||||||
|
QString dbSettingFileName = fi.absolutePath()+"/"+fi.baseName()+".db";
|
||||||
|
QSettings dbcredentals(dbSettingFileName, QSettings::IniFormat);
|
||||||
|
|
||||||
|
foreach (ConnectionDesc* connection, dataManager()->conections()) {
|
||||||
|
if (!connection->keepDBCredentials()){
|
||||||
|
dbcredentals.beginGroup(connection->name());
|
||||||
|
dbcredentals.setValue("user",connection->userName());
|
||||||
|
dbcredentals.setValue("password",connection->password());
|
||||||
|
dbcredentals.endGroup();
|
||||||
|
connection->setPassword("");
|
||||||
|
connection->setUserName("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
|
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
|
||||||
|
writer->setPassPhrase(m_passPhrase);
|
||||||
writer->putItem(this);
|
writer->putItem(this);
|
||||||
m_fileName=fn;
|
m_fileName=fn;
|
||||||
bool saved = writer->saveToFile(fn);
|
bool saved = writer->saveToFile(fn);
|
||||||
|
|
||||||
|
foreach (ConnectionDesc* connection, dataManager()->conections()) {
|
||||||
|
if (!connection->keepDBCredentials()){
|
||||||
|
dbcredentals.beginGroup(connection->name());
|
||||||
|
connection->setUserName(dbcredentals.value("user").toString());
|
||||||
|
connection->setPassword(dbcredentals.value("password").toString());
|
||||||
|
dbcredentals.endGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (saved){
|
if (saved){
|
||||||
foreach(PageDesignIntf* page, m_pages){
|
foreach(PageDesignIntf* page, m_pages){
|
||||||
page->setToSaved();
|
page->setToSaved();
|
||||||
@ -581,6 +623,7 @@ bool ReportEnginePrivate::saveToFile(const QString &fileName)
|
|||||||
QByteArray ReportEnginePrivate::saveToByteArray()
|
QByteArray ReportEnginePrivate::saveToByteArray()
|
||||||
{
|
{
|
||||||
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
|
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
|
||||||
|
writer->setPassPhrase(m_passPhrase);
|
||||||
writer->putItem(this);
|
writer->putItem(this);
|
||||||
QByteArray result = writer->saveToByteArray();
|
QByteArray result = writer->saveToByteArray();
|
||||||
if (!result.isEmpty()){
|
if (!result.isEmpty()){
|
||||||
@ -593,6 +636,7 @@ QByteArray ReportEnginePrivate::saveToByteArray()
|
|||||||
|
|
||||||
QString ReportEnginePrivate::saveToString(){
|
QString ReportEnginePrivate::saveToString(){
|
||||||
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
|
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
|
||||||
|
writer->setPassPhrase(m_passPhrase);
|
||||||
writer->putItem(this);
|
writer->putItem(this);
|
||||||
QString result = writer->saveToString();
|
QString result = writer->saveToString();
|
||||||
if (!result.isEmpty()){
|
if (!result.isEmpty()){
|
||||||
@ -629,6 +673,11 @@ QString ReportEnginePrivate::renderToString()
|
|||||||
}else return QString();
|
}else return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReportEnginePrivate::setPassPhrase(const QString &passPhrase)
|
||||||
|
{
|
||||||
|
m_passPhrase = passPhrase;
|
||||||
|
}
|
||||||
|
|
||||||
bool ReportEnginePrivate::resultIsEditable() const
|
bool ReportEnginePrivate::resultIsEditable() const
|
||||||
{
|
{
|
||||||
return m_resultIsEditable;
|
return m_resultIsEditable;
|
||||||
@ -807,6 +856,12 @@ bool ReportEngine::isBusy()
|
|||||||
return d->isBusy();
|
return d->isBusy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReportEngine::setPassPharse(QString &passPharse)
|
||||||
|
{
|
||||||
|
Q_D(ReportEngine);
|
||||||
|
d->setPassPhrase(passPharse);
|
||||||
|
}
|
||||||
|
|
||||||
void ReportEngine::setShowProgressDialog(bool value)
|
void ReportEngine::setShowProgressDialog(bool value)
|
||||||
{
|
{
|
||||||
Q_D(ReportEngine);
|
Q_D(ReportEngine);
|
||||||
|
@ -101,6 +101,7 @@ public:
|
|||||||
void setResultEditable(bool value);
|
void setResultEditable(bool value);
|
||||||
bool resultIsEditable();
|
bool resultIsEditable();
|
||||||
bool isBusy();
|
bool isBusy();
|
||||||
|
void setPassPharse(QString& passPharse);
|
||||||
signals:
|
signals:
|
||||||
void renderStarted();
|
void renderStarted();
|
||||||
void renderFinished();
|
void renderFinished();
|
||||||
|
@ -125,6 +125,8 @@ public:
|
|||||||
bool resultIsEditable() const;
|
bool resultIsEditable() const;
|
||||||
void setResultEditable(bool value);
|
void setResultEditable(bool value);
|
||||||
|
|
||||||
|
void setPassPhrase(const QString &passPhrase);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pagesLoadFinished();
|
void pagesLoadFinished();
|
||||||
void datasourceCollectionLoadFinished(const QString& collectionName);
|
void datasourceCollectionLoadFinished(const QString& collectionName);
|
||||||
@ -175,6 +177,7 @@ private:
|
|||||||
ReportSettings m_reportSettings;
|
ReportSettings m_reportSettings;
|
||||||
bool m_reportRendering;
|
bool m_reportRendering;
|
||||||
bool m_resultIsEditable;
|
bool m_resultIsEditable;
|
||||||
|
QString m_passPhrase;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,8 @@ const int b = 16; /* number of bytes in key */
|
|||||||
const int c = 4; /* number words in key = ceil(8*b/w)*/
|
const int c = 4; /* number words in key = ceil(8*b/w)*/
|
||||||
const int t = 26; /* size of table S = 2*(r+1) words */
|
const int t = 26; /* size of table S = 2*(r+1) words */
|
||||||
|
|
||||||
|
const char* passPhrase = "HjccbzHjlbyfCkjy";
|
||||||
|
|
||||||
WORD P = 0xb7e15163, Q = 0x9e3779b9;
|
WORD P = 0xb7e15163, Q = 0x9e3779b9;
|
||||||
|
|
||||||
#define ROTL(x,y) (((x)<<(y&(w-1))) | ((x)>>(w-(y&(w-1)))))
|
#define ROTL(x,y) (((x)<<(y&(w-1))) | ((x)>>(w-(y&(w-1)))))
|
||||||
@ -64,11 +66,15 @@ namespace LimeReport {
|
|||||||
|
|
||||||
class ChipperPrivate{
|
class ChipperPrivate{
|
||||||
friend class Chipper;
|
friend class Chipper;
|
||||||
|
public:
|
||||||
|
ChipperPrivate():m_prepared(false){}
|
||||||
|
bool isPrepared(){ return m_prepared;}
|
||||||
private:
|
private:
|
||||||
void RC5_SETUP(const char *K);
|
void RC5_SETUP(const char *K);
|
||||||
void RC5_ENCRYPT(WORD *pt, WORD *ct);
|
void RC5_ENCRYPT(WORD *pt, WORD *ct);
|
||||||
void RC5_DECRYPT(WORD *ct, WORD *pt);
|
void RC5_DECRYPT(WORD *ct, WORD *pt);
|
||||||
WORD S[26];
|
WORD S[26];
|
||||||
|
bool m_prepared;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ChipperPrivate::RC5_SETUP(const char *K)
|
void ChipperPrivate::RC5_SETUP(const char *K)
|
||||||
@ -82,6 +88,7 @@ void ChipperPrivate::RC5_SETUP(const char *K)
|
|||||||
A = S[i] = ROTL(S[i]+(A+B),3);
|
A = S[i] = ROTL(S[i]+(A+B),3);
|
||||||
B = L[j] = ROTL(L[j]+(A+B),(A+B));
|
B = L[j] = ROTL(L[j]+(A+B),(A+B));
|
||||||
}
|
}
|
||||||
|
m_prepared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChipperPrivate::RC5_ENCRYPT(WORD *pt, WORD *ct)
|
void ChipperPrivate::RC5_ENCRYPT(WORD *pt, WORD *ct)
|
||||||
@ -111,7 +118,8 @@ QByteArray Chipper::cryptString(QString value)
|
|||||||
buff += value;
|
buff += value;
|
||||||
WTB pt, ct, prior;
|
WTB pt, ct, prior;
|
||||||
|
|
||||||
d->RC5_SETUP("HjccbzHjlbyfCkjy");
|
if (!d->isPrepared())
|
||||||
|
d->RC5_SETUP(passPhrase);
|
||||||
|
|
||||||
prior.word[0]=0;
|
prior.word[0]=0;
|
||||||
prior.word[1]=0;
|
prior.word[1]=0;
|
||||||
@ -144,7 +152,8 @@ QString Chipper::decryptByteArray(QByteArray value)
|
|||||||
QByteArray result;
|
QByteArray result;
|
||||||
WTB pt, ct, prior;
|
WTB pt, ct, prior;
|
||||||
|
|
||||||
d->RC5_SETUP("HjccbzHjlbyfCkjy");
|
if (!d->isPrepared())
|
||||||
|
d->RC5_SETUP(passPhrase);
|
||||||
prior.word[0] = 0;
|
prior.word[0] = 0;
|
||||||
prior.word[1] = 0;
|
prior.word[1] = 0;
|
||||||
|
|
||||||
@ -174,6 +183,14 @@ QString Chipper::decryptByteArray(QByteArray value)
|
|||||||
|
|
||||||
Chipper::Chipper(): d(new ChipperPrivate()){}
|
Chipper::Chipper(): d(new ChipperPrivate()){}
|
||||||
|
|
||||||
|
Chipper::Chipper(QString passphrase): d(new ChipperPrivate())
|
||||||
|
{
|
||||||
|
if (!passphrase.trimmed().isEmpty()){
|
||||||
|
passphrase = passphrase.leftJustified(16,'#');
|
||||||
|
d->RC5_SETUP(passphrase.toLatin1().data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Chipper::~Chipper()
|
Chipper::~Chipper()
|
||||||
{
|
{
|
||||||
delete d;
|
delete d;
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
QByteArray cryptString(QString value);
|
QByteArray cryptString(QString value);
|
||||||
QString decryptByteArray(QByteArray value);
|
QString decryptByteArray(QByteArray value);
|
||||||
Chipper();
|
Chipper();
|
||||||
|
Chipper(QString passphrase);
|
||||||
~Chipper();
|
~Chipper();
|
||||||
private:
|
private:
|
||||||
ChipperPrivate* d;
|
ChipperPrivate* d;
|
||||||
|
@ -35,10 +35,16 @@ namespace LimeReport {
|
|||||||
class SerializatorIntf
|
class SerializatorIntf
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual QVariant loadValue()=0;
|
virtual QVariant loadValue() = 0;
|
||||||
virtual void save(const QVariant& value,QString name)=0;
|
virtual void save(const QVariant& value,QString name) = 0;
|
||||||
virtual ~SerializatorIntf(){}
|
virtual ~SerializatorIntf(){}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CryptedSerializator : public virtual SerializatorIntf
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void setPassPhrase(const QString& passPhrase) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // LRSERIALIZATORINTF_H
|
#endif // LRSERIALIZATORINTF_H
|
||||||
|
@ -39,18 +39,19 @@ namespace LimeReport{
|
|||||||
|
|
||||||
class ObjectLoadingStateIntf{
|
class ObjectLoadingStateIntf{
|
||||||
public:
|
public:
|
||||||
virtual bool isLoading()=0;
|
virtual bool isLoading() = 0;
|
||||||
virtual void objectLoadStarted()=0;
|
virtual void objectLoadStarted() = 0;
|
||||||
virtual void objectLoadFinished()=0;
|
virtual void objectLoadFinished() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ItemsWriterIntf
|
class ItemsWriterIntf
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void putItem(QObject* item)=0;
|
virtual void putItem(QObject* item) = 0;
|
||||||
virtual bool saveToFile(QString fileName) = 0;
|
virtual bool saveToFile(QString fileName) = 0;
|
||||||
virtual QString saveToString() = 0;
|
virtual QString saveToString() = 0;
|
||||||
virtual QByteArray saveToByteArray() = 0;
|
virtual QByteArray saveToByteArray() = 0;
|
||||||
|
virtual void setPassPhrase(const QString& passPhrase) = 0;
|
||||||
virtual ~ItemsWriterIntf(){}
|
virtual ~ItemsWriterIntf(){}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,14 +59,15 @@ class ItemsReaderIntf
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef QSharedPointer<ItemsReaderIntf> Ptr;
|
typedef QSharedPointer<ItemsReaderIntf> Ptr;
|
||||||
virtual bool first()=0;
|
virtual bool first() = 0;
|
||||||
virtual bool next()=0;
|
virtual bool next() = 0;
|
||||||
virtual bool prior()=0;
|
virtual bool prior() = 0;
|
||||||
virtual QString itemType()=0;
|
virtual QString itemType() = 0;
|
||||||
virtual QString itemClassName()=0;
|
virtual QString itemClassName() = 0;
|
||||||
virtual bool readItem(QObject *item)=0;
|
virtual bool readItem(QObject *item) = 0;
|
||||||
virtual int firstLevelItemsCount()=0;
|
virtual int firstLevelItemsCount() = 0;
|
||||||
virtual QString lastError()=0;
|
virtual QString lastError() = 0;
|
||||||
|
virtual void setPassPhrase(const QString& passPhrase) = 0;
|
||||||
virtual ~ItemsReaderIntf(){}
|
virtual ~ItemsReaderIntf(){}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ void XmlQStringSerializator::save(const QVariant &value, QString name)
|
|||||||
QDomElement _node = doc()->createElement(name);
|
QDomElement _node = doc()->createElement(name);
|
||||||
_node.setAttribute("Type","QString");
|
_node.setAttribute("Type","QString");
|
||||||
if (name.compare("password")==0){
|
if (name.compare("password")==0){
|
||||||
Chipper chipper;
|
Chipper chipper(passPhrase());
|
||||||
QByteArray ba = chipper.cryptString(value.toString());
|
QByteArray ba = chipper.cryptString(value.toString());
|
||||||
//ba.append();
|
//ba.append();
|
||||||
_node.setAttribute("Value",QString(ba.toBase64()));
|
_node.setAttribute("Value",QString(ba.toBase64()));
|
||||||
@ -123,7 +123,7 @@ QVariant XmlQStringSerializator::loadValue()
|
|||||||
{
|
{
|
||||||
if (node()->tagName().compare("password")==0){
|
if (node()->tagName().compare("password")==0){
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
Chipper chipper;
|
Chipper chipper(passPhrase());
|
||||||
ba.append(node()->attribute("Value").toLatin1());
|
ba.append(node()->attribute("Value").toLatin1());
|
||||||
return chipper.decryptByteArray(QByteArray::fromBase64(ba));
|
return chipper.decryptByteArray(QByteArray::fromBase64(ba));
|
||||||
} else
|
} else
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
namespace LimeReport{
|
namespace LimeReport{
|
||||||
|
|
||||||
class XmlBaseSerializator : public SerializatorIntf{
|
class XmlBaseSerializator : public virtual SerializatorIntf{
|
||||||
public:
|
public:
|
||||||
XmlBaseSerializator(QDomDocument *doc, QDomElement *node):m_doc(doc),m_node(node){}
|
XmlBaseSerializator(QDomDocument *doc, QDomElement *node):m_doc(doc),m_node(node){}
|
||||||
protected:
|
protected:
|
||||||
@ -48,10 +48,21 @@ private:
|
|||||||
QDomElement *m_node;
|
QDomElement *m_node;
|
||||||
};
|
};
|
||||||
|
|
||||||
class XmlQStringSerializator : public XmlBaseSerializator
|
class XmlCryptedSerializator : public XmlBaseSerializator, public virtual CryptedSerializator{
|
||||||
|
public:
|
||||||
|
XmlCryptedSerializator(QDomDocument *doc, QDomElement *node)
|
||||||
|
:XmlBaseSerializator(doc, node){}
|
||||||
|
virtual void setPassPhrase(const QString& passPhrase) {m_passPhrase = passPhrase;}
|
||||||
|
protected:
|
||||||
|
QString passPhrase(){ return m_passPhrase;}
|
||||||
|
private:
|
||||||
|
QString m_passPhrase;
|
||||||
|
};
|
||||||
|
|
||||||
|
class XmlQStringSerializator : public XmlCryptedSerializator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XmlQStringSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
XmlQStringSerializator(QDomDocument *doc, QDomElement *node):XmlCryptedSerializator(doc,node){}
|
||||||
private:
|
private:
|
||||||
virtual void save(const QVariant &value,QString name);
|
virtual void save(const QVariant &value,QString name);
|
||||||
virtual QVariant loadValue();
|
virtual QVariant loadValue();
|
||||||
|
@ -135,6 +135,11 @@ QString XMLReader::lastError()
|
|||||||
return m_error;
|
return m_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XMLReader::setPassPhrase(const QString &passPhrase)
|
||||||
|
{
|
||||||
|
m_passPhrase = passPhrase;
|
||||||
|
}
|
||||||
|
|
||||||
bool XMLReader::extractFirstNode()
|
bool XMLReader::extractFirstNode()
|
||||||
{
|
{
|
||||||
if (m_firstNode.isNull()){
|
if (m_firstNode.isNull()){
|
||||||
@ -166,6 +171,10 @@ QVariant XMLReader::getValue(QDomElement *node)
|
|||||||
|
|
||||||
if (creator) {
|
if (creator) {
|
||||||
QScopedPointer<SerializatorIntf>serializator(creator(m_doc.data(),node));
|
QScopedPointer<SerializatorIntf>serializator(creator(m_doc.data(),node));
|
||||||
|
CryptedSerializator* cs = dynamic_cast<CryptedSerializator*>(serializator.data());
|
||||||
|
if (cs){
|
||||||
|
cs->setPassPhrase(m_passPhrase);
|
||||||
|
}
|
||||||
return serializator->loadValue();
|
return serializator->loadValue();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -44,14 +44,17 @@ public:
|
|||||||
XMLReader();
|
XMLReader();
|
||||||
XMLReader(QSharedPointer<QDomDocument> doc);
|
XMLReader(QSharedPointer<QDomDocument> doc);
|
||||||
protected:
|
protected:
|
||||||
|
//ItemsReaderIntf interface
|
||||||
|
bool first();
|
||||||
|
bool next();
|
||||||
|
bool prior();
|
||||||
|
QString itemType();
|
||||||
|
QString itemClassName();
|
||||||
|
bool readItem(QObject *item);
|
||||||
|
int firstLevelItemsCount();
|
||||||
|
QString lastError();
|
||||||
|
void setPassPhrase(const QString &passPhrase);
|
||||||
|
|
||||||
virtual bool first();
|
|
||||||
virtual bool next();
|
|
||||||
virtual bool prior();
|
|
||||||
virtual QString itemType();
|
|
||||||
virtual QString itemClassName();
|
|
||||||
virtual bool readItem(QObject *item);
|
|
||||||
virtual int firstLevelItemsCount();
|
|
||||||
virtual bool prepareReader(QDomDocument *doc);
|
virtual bool prepareReader(QDomDocument *doc);
|
||||||
|
|
||||||
void readItemFromNode(QObject *item, QDomElement *node);
|
void readItemFromNode(QObject *item, QDomElement *node);
|
||||||
@ -60,7 +63,7 @@ protected:
|
|||||||
void readCollection(QObject *item, QDomElement *node);
|
void readCollection(QObject *item, QDomElement *node);
|
||||||
QVariant getValue(QDomElement *node);
|
QVariant getValue(QDomElement *node);
|
||||||
|
|
||||||
virtual QString lastError();
|
|
||||||
protected:
|
protected:
|
||||||
bool extractFirstNode();
|
bool extractFirstNode();
|
||||||
QString m_error;
|
QString m_error;
|
||||||
@ -68,6 +71,11 @@ private:
|
|||||||
QSharedPointer<QDomDocument> m_doc;
|
QSharedPointer<QDomDocument> m_doc;
|
||||||
QDomElement m_curNode;
|
QDomElement m_curNode;
|
||||||
QDomElement m_firstNode;
|
QDomElement m_firstNode;
|
||||||
|
QString m_passPhrase;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileXMLReader : public XMLReader{
|
class FileXMLReader : public XMLReader{
|
||||||
|
@ -113,6 +113,11 @@ QByteArray XMLWriter::saveToByteArray()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XMLWriter::setPassPhrase(const QString &passPhrase)
|
||||||
|
{
|
||||||
|
m_passPhrase = passPhrase;
|
||||||
|
}
|
||||||
|
|
||||||
QDomElement XMLWriter::putQObjectItem(QString name, QObject *item)
|
QDomElement XMLWriter::putQObjectItem(QString name, QObject *item)
|
||||||
{
|
{
|
||||||
Q_UNUSED(name)
|
Q_UNUSED(name)
|
||||||
@ -158,6 +163,10 @@ void XMLWriter::saveProperty(QString name, QObject* item, QDomElement *node)
|
|||||||
|
|
||||||
if (creator) {
|
if (creator) {
|
||||||
QScopedPointer<SerializatorIntf> serializator(creator(m_doc.data(),node));
|
QScopedPointer<SerializatorIntf> serializator(creator(m_doc.data(),node));
|
||||||
|
CryptedSerializator* cs = dynamic_cast<CryptedSerializator*>(serializator.data());
|
||||||
|
if (cs){
|
||||||
|
cs->setPassPhrase(m_passPhrase);
|
||||||
|
}
|
||||||
serializator->save(
|
serializator->save(
|
||||||
item->property(name.toLatin1()),
|
item->property(name.toLatin1()),
|
||||||
name
|
name
|
||||||
|
@ -44,10 +44,13 @@ public:
|
|||||||
XMLWriter(QSharedPointer<QDomDocument> doc);
|
XMLWriter(QSharedPointer<QDomDocument> doc);
|
||||||
~XMLWriter() {}
|
~XMLWriter() {}
|
||||||
private:
|
private:
|
||||||
|
// ItemsWriterIntf interface
|
||||||
void putItem(QObject* item);
|
void putItem(QObject* item);
|
||||||
bool saveToFile(QString fileName);
|
bool saveToFile(QString fileName);
|
||||||
QString saveToString();
|
QString saveToString();
|
||||||
QByteArray saveToByteArray();
|
QByteArray saveToByteArray();
|
||||||
|
void setPassPhrase(const QString &passPhrase);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
QDomElement putQObjectItem(QString name, QObject* item);
|
QDomElement putQObjectItem(QString name, QObject* item);
|
||||||
void putChildQObjectItem(QString name, QObject* item, QDomElement* parentNode);
|
void putChildQObjectItem(QString name, QObject* item, QDomElement* parentNode);
|
||||||
@ -66,6 +69,7 @@ private:
|
|||||||
QSharedPointer<QDomDocument> m_doc;
|
QSharedPointer<QDomDocument> m_doc;
|
||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
QDomElement m_rootElement;
|
QDomElement m_rootElement;
|
||||||
|
QString m_passPhrase;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user