Merge branch '1.4' into 1.4_QJSEngine

This commit is contained in:
Arin Alexander 2017-02-16 04:12:15 +03:00
commit 75c5ae65da
22 changed files with 257 additions and 64 deletions

View File

@ -37,18 +37,25 @@ class QString;
class QAbstractItemModel;
namespace LimeReport{
class IDbCredentialsProvider{
public:
virtual QString getUserName(const QString& connectionName) = 0;
virtual QString getPassword(const QString& connectionName) = 0;
};
class IDataSourceManager{
public:
virtual void setReportVariable(const QString& name, const QVariant& value)=0;
virtual void setDefaultDatabasePath(const QString &defaultDatabasePath)=0;
virtual void deleteVariable(const QString& name)=0;
virtual bool containsVariable(const QString& variableName)=0;
virtual QVariant variable(const QString& variableName)=0;
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned)=0;
virtual void removeModel(const QString& name)=0;
virtual bool containsDatasource(const QString& dataSourceName)=0;
virtual void setReportVariable(const QString& name, const QVariant& value) = 0;
virtual void setDefaultDatabasePath(const QString &defaultDatabasePath) = 0;
virtual void deleteVariable(const QString& name) = 0;
virtual bool containsVariable(const QString& variableName) = 0;
virtual QVariant variable(const QString& variableName) = 0;
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned) = 0;
virtual void removeModel(const QString& name) = 0;
virtual bool containsDatasource(const QString& dataSourceName) = 0;
virtual void clearUserVariables()=0;
virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0;
virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0;
//virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0;
};

View File

@ -102,6 +102,7 @@ public:
void setResultEditable(bool value);
bool resultIsEditable();
bool isBusy();
void setPassPharse(QString& passPharse);
signals:
void renderStarted();
void renderFinished();

View File

@ -122,6 +122,7 @@ ConnectionDesc *ConnectionDialog::uiToConnection(LimeReport::ConnectionDesc* con
result ->setPassword(ui->lePassword->text());
result ->setDatabaseName(ui->leDataBase->text());
result ->setAutoconnect(ui->cbAutoConnect->isChecked());
result->setKeepDBCredentials(!ui->cbbKeepCredentials->isChecked());
return result ;
}
@ -137,6 +138,7 @@ void ConnectionDialog::connectionToUI()
ui->lePassword->setText(m_connection->password());
ui->cbbDrivers->setCurrentIndex(ui->cbbDrivers->findText(m_connection->driver()));
ui->cbAutoConnect->setChecked(m_connection->autoconnect());
ui->cbbKeepCredentials->setChecked(!m_connection->keepDBCredentials());
}
void ConnectionDialog::on_toolButton_clicked()

View File

@ -137,6 +137,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbbKeepCredentials">
<property name="text">
<string>Dont keep credentals in lrxml</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@ -351,13 +351,13 @@ void ModelToDataSource::slotModelDestroed()
ConnectionDesc::ConnectionDesc(QSqlDatabase db, QObject *parent)
: 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_internal(false)
m_internal(false), m_keepDBCredentials(true)
{}
ConnectionDesc::ConnectionDesc(QObject *parent)
:QObject(parent),m_connectionName(""),m_connectionHost(""),m_connectionDriver(""),
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)
@ -391,6 +391,16 @@ QString ConnectionDesc::connectionNameForReport(const QString &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)
:m_queryName(queryName), m_queryText(queryText), m_connectionName(connection)
{}

View File

@ -110,6 +110,7 @@ class ConnectionDesc : public QObject{
Q_PROPERTY(QString password READ password WRITE setPassword)
Q_PROPERTY(QString host READ host WRITE setHost)
Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect)
Q_PROPERTY(bool keepDBCredentials READ keepDBCredentials WRITE setKeepDBCredentials)
public:
typedef QSharedPointer<ConnectionDesc> Ptr;
ConnectionDesc(QSqlDatabase db, QObject* parent=0);
@ -124,14 +125,16 @@ public:
void setDatabaseName(const QString &value){m_databaseName=value;}
QString databaseName(){return m_databaseName;}
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;}
QString password(){return m_password;}
QString password(){ return m_password; }
void setAutoconnect(bool value){m_autoconnect=value;}
bool autoconnect(){return m_autoconnect;}
bool isEqual(const QSqlDatabase& db);
bool isInternal(){ return m_internal; }
void setInternal(bool value) {m_internal = value;}
bool keepDBCredentials() const;
void setKeepDBCredentials(bool keepDBCredentials);
public:
static QString connectionNameForUser(const QString& connectionName);
static QString connectionNameForReport(const QString& connectionName);
@ -146,6 +149,7 @@ private:
QString m_password;
bool m_autoconnect;
bool m_internal;
bool m_keepDBCredentials;
};
class IConnectionController{

View File

@ -217,7 +217,7 @@ void DataSourceModel::updateModel()
}
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("SUM"),new ConstructorGroupFunctionCreator<SumGroupFunction>);
@ -324,6 +324,11 @@ ICallbackDatasource *DataSourceManager::createCallbackDatasouce(const QString& n
return ds;
}
void DataSourceManager::registerDbCredentialsProvider(IDbCredentialsProvider *provider)
{
m_dbCredentialsProvider = provider;
}
void DataSourceManager::addCallbackDatasource(ICallbackDatasource *datasource, const QString& name)
{
IDataSource* datasourceIntf = dynamic_cast<IDataSource*>(datasource);
@ -567,6 +572,11 @@ int DataSourceManager::connectionIndexByName(const QString &connectionName)
return -1;
}
QList<ConnectionDesc *>& DataSourceManager::conections()
{
return m_connections;
}
bool DataSourceManager::dataSourceIsValid(const QString &name)
{
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 connected = false;
db.setHostName(replaceVariables(connectionDesc.host()));
db.setUserName(replaceVariables(connectionDesc.userName()));
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());
if (connectionDesc.driver().compare("QSQLITE")==0){
if (!defaultDatabasePath().isEmpty()){
@ -726,7 +745,6 @@ bool DataSourceManager::initAndOpenDB(QSqlDatabase& db, ConnectionDesc& connecti
}
connected=db.open();
connectionDesc.setInternal(true);
if (!connected) setLastError(db.lastError().text());
return connected;
}
@ -758,10 +776,17 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
}
if (!QSqlDatabase::contains(connectionDesc->name())){
QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name());
connected=initAndOpenDB(db, *connectionDesc);
QString dbError;
{
QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name());
connectionDesc->setInternal(true);
connected=initAndOpenDB(db, *connectionDesc);
dbError = db.lastError().text();
}
if (!connected){
setLastError(db.lastError().text());
if (!dbError.trimmed().isEmpty())
setLastError(dbError);
QSqlDatabase::removeDatabase(connectionDesc->name());
return false;
}
} else {
@ -868,8 +893,9 @@ bool DataSourceManager::isConnection(const QString &connectionName)
bool DataSourceManager::isConnectionConnected(const QString &connectionName)
{
if (isConnection(connectionName)){
return QSqlDatabase::database(connectionName).isOpen();
if (isConnection(connectionName) && QSqlDatabase::contains(connectionName)){
QSqlDatabase db = QSqlDatabase::database(connectionName);
return db.isValid() && QSqlDatabase::database(connectionName).isOpen();
}
return false;
}
@ -893,8 +919,10 @@ void DataSourceManager::disconnectConnection(const QString& connectionName)
ConnectionDesc* connectionDesc = connectionByName(connectionName);
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);
}

View File

@ -115,6 +115,7 @@ public:
bool addModel(const QString& name, QAbstractItemModel *model, bool owned);
void removeModel(const QString& name);
ICallbackDatasource* createCallbackDatasouce(const QString &name);
void registerDbCredentialsProvider(IDbCredentialsProvider *provider);
void addCallbackDatasource(ICallbackDatasource *datasource, const QString &name);
void setReportVariable(const QString& name, const QVariant& value);
void deleteVariable(const QString& name);
@ -150,6 +151,7 @@ public:
int proxyIndexByName(const QString& dataSourceName);
int connectionIndexByName(const QString& connectionName);
QList<ConnectionDesc *> &conections();
bool dataSourceIsValid(const QString& name);
IDataSource* dataSource(const QString& name);
IDataSourceHolder* dataSourceHolder(const QString& name);
@ -250,8 +252,7 @@ private:
ReportSettings* m_reportSettings;
QHash<QString,int> m_groupFunctionsExpressionsMap;
QVector<QString> m_groupFunctionsExpressions;
IDbCredentialsProvider* m_dbCredentialsProvider;
};
}

View File

@ -37,18 +37,25 @@ class QString;
class QAbstractItemModel;
namespace LimeReport{
class IDbCredentialsProvider{
public:
virtual QString getUserName(const QString& connectionName) = 0;
virtual QString getPassword(const QString& connectionName) = 0;
};
class IDataSourceManager{
public:
virtual void setReportVariable(const QString& name, const QVariant& value)=0;
virtual void setDefaultDatabasePath(const QString &defaultDatabasePath)=0;
virtual void deleteVariable(const QString& name)=0;
virtual bool containsVariable(const QString& variableName)=0;
virtual QVariant variable(const QString& variableName)=0;
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned)=0;
virtual void removeModel(const QString& name)=0;
virtual bool containsDatasource(const QString& dataSourceName)=0;
virtual void setReportVariable(const QString& name, const QVariant& value) = 0;
virtual void setDefaultDatabasePath(const QString &defaultDatabasePath) = 0;
virtual void deleteVariable(const QString& name) = 0;
virtual bool containsVariable(const QString& variableName) = 0;
virtual QVariant variable(const QString& variableName) = 0;
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned) = 0;
virtual void removeModel(const QString& name) = 0;
virtual bool containsDatasource(const QString& dataSourceName) = 0;
virtual void clearUserVariables()=0;
virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0;
virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0;
//virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0;
};

View File

@ -59,7 +59,7 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) :
m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false),
m_showProgressDialog(true), m_reportName(""), m_activePreview(0),
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->setReportSettings(&m_reportSettings);
@ -516,11 +516,26 @@ bool ReportEnginePrivate::loadFromFile(const QString &fileName)
clearReport();
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);
reader->setPassPhrase(m_passPhrase);
if (reader->first()){
if (reader->readItem(this)){
m_fileName=fileName;
QFileInfo 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();
return true;
};
@ -533,6 +548,7 @@ bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString &nam
clearReport();
ItemsReaderIntf::Ptr reader = ByteArrayXMLReader::create(data);
reader->setPassPhrase(m_passPhrase);
if (reader->first()){
if (reader->readItem(this)){
m_fileName = "";
@ -548,6 +564,7 @@ bool ReportEnginePrivate::loadFromString(const QString &report, const QString &n
clearReport();
ItemsReaderIntf::Ptr reader = StringXMLreader::create(report);
reader->setPassPhrase(m_passPhrase);
if (reader->first()){
if (reader->readItem(this)){
m_fileName = "";
@ -566,10 +583,35 @@ bool ReportEnginePrivate::saveToFile(const QString &fileName)
if (fi.suffix().isEmpty())
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());
writer->setPassPhrase(m_passPhrase);
writer->putItem(this);
m_fileName=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){
foreach(PageDesignIntf* page, m_pages){
page->setToSaved();
@ -581,6 +623,7 @@ bool ReportEnginePrivate::saveToFile(const QString &fileName)
QByteArray ReportEnginePrivate::saveToByteArray()
{
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
writer->setPassPhrase(m_passPhrase);
writer->putItem(this);
QByteArray result = writer->saveToByteArray();
if (!result.isEmpty()){
@ -593,6 +636,7 @@ QByteArray ReportEnginePrivate::saveToByteArray()
QString ReportEnginePrivate::saveToString(){
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
writer->setPassPhrase(m_passPhrase);
writer->putItem(this);
QString result = writer->saveToString();
if (!result.isEmpty()){
@ -629,6 +673,11 @@ QString ReportEnginePrivate::renderToString()
}else return QString();
}
void ReportEnginePrivate::setPassPhrase(const QString &passPhrase)
{
m_passPhrase = passPhrase;
}
bool ReportEnginePrivate::resultIsEditable() const
{
return m_resultIsEditable;
@ -807,6 +856,12 @@ bool ReportEngine::isBusy()
return d->isBusy();
}
void ReportEngine::setPassPharse(QString &passPharse)
{
Q_D(ReportEngine);
d->setPassPhrase(passPharse);
}
void ReportEngine::setShowProgressDialog(bool value)
{
Q_D(ReportEngine);

View File

@ -102,6 +102,7 @@ public:
void setResultEditable(bool value);
bool resultIsEditable();
bool isBusy();
void setPassPharse(QString& passPharse);
signals:
void renderStarted();
void renderFinished();

View File

@ -125,6 +125,8 @@ public:
bool resultIsEditable() const;
void setResultEditable(bool value);
void setPassPhrase(const QString &passPhrase);
signals:
void pagesLoadFinished();
void datasourceCollectionLoadFinished(const QString& collectionName);
@ -175,6 +177,7 @@ private:
ReportSettings m_reportSettings;
bool m_reportRendering;
bool m_resultIsEditable;
QString m_passPhrase;
};
}

View File

@ -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 t = 26; /* size of table S = 2*(r+1) words */
const char* passPhrase = "HjccbzHjlbyfCkjy";
WORD P = 0xb7e15163, Q = 0x9e3779b9;
#define ROTL(x,y) (((x)<<(y&(w-1))) | ((x)>>(w-(y&(w-1)))))
@ -64,11 +66,15 @@ namespace LimeReport {
class ChipperPrivate{
friend class Chipper;
public:
ChipperPrivate():m_prepared(false){}
bool isPrepared(){ return m_prepared;}
private:
void RC5_SETUP(const char *K);
void RC5_ENCRYPT(WORD *pt, WORD *ct);
void RC5_DECRYPT(WORD *ct, WORD *pt);
WORD S[26];
bool m_prepared;
};
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);
B = L[j] = ROTL(L[j]+(A+B),(A+B));
}
m_prepared = true;
}
void ChipperPrivate::RC5_ENCRYPT(WORD *pt, WORD *ct)
@ -111,7 +118,8 @@ QByteArray Chipper::cryptString(QString value)
buff += value;
WTB pt, ct, prior;
d->RC5_SETUP("HjccbzHjlbyfCkjy");
if (!d->isPrepared())
d->RC5_SETUP(passPhrase);
prior.word[0]=0;
prior.word[1]=0;
@ -144,7 +152,8 @@ QString Chipper::decryptByteArray(QByteArray value)
QByteArray result;
WTB pt, ct, prior;
d->RC5_SETUP("HjccbzHjlbyfCkjy");
if (!d->isPrepared())
d->RC5_SETUP(passPhrase);
prior.word[0] = 0;
prior.word[1] = 0;
@ -174,6 +183,14 @@ QString Chipper::decryptByteArray(QByteArray value)
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()
{
delete d;

View File

@ -42,6 +42,7 @@ public:
QByteArray cryptString(QString value);
QString decryptByteArray(QByteArray value);
Chipper();
Chipper(QString passphrase);
~Chipper();
private:
ChipperPrivate* d;

View File

@ -35,10 +35,16 @@ namespace LimeReport {
class SerializatorIntf
{
public:
virtual QVariant loadValue()=0;
virtual void save(const QVariant& value,QString name)=0;
virtual QVariant loadValue() = 0;
virtual void save(const QVariant& value,QString name) = 0;
virtual ~SerializatorIntf(){}
};
class CryptedSerializator : public virtual SerializatorIntf
{
public:
virtual void setPassPhrase(const QString& passPhrase) = 0;
};
}
#endif // LRSERIALIZATORINTF_H

View File

@ -39,18 +39,19 @@ namespace LimeReport{
class ObjectLoadingStateIntf{
public:
virtual bool isLoading()=0;
virtual void objectLoadStarted()=0;
virtual void objectLoadFinished()=0;
virtual bool isLoading() = 0;
virtual void objectLoadStarted() = 0;
virtual void objectLoadFinished() = 0;
};
class ItemsWriterIntf
{
public:
virtual void putItem(QObject* item)=0;
virtual void putItem(QObject* item) = 0;
virtual bool saveToFile(QString fileName) = 0;
virtual QString saveToString() = 0;
virtual QByteArray saveToByteArray() = 0;
virtual void setPassPhrase(const QString& passPhrase) = 0;
virtual ~ItemsWriterIntf(){}
};
@ -58,14 +59,15 @@ class ItemsReaderIntf
{
public:
typedef QSharedPointer<ItemsReaderIntf> Ptr;
virtual bool first()=0;
virtual bool next()=0;
virtual bool prior()=0;
virtual QString itemType()=0;
virtual QString itemClassName()=0;
virtual bool readItem(QObject *item)=0;
virtual int firstLevelItemsCount()=0;
virtual QString lastError()=0;
virtual bool first() = 0;
virtual bool next() = 0;
virtual bool prior() = 0;
virtual QString itemType() = 0;
virtual QString itemClassName() = 0;
virtual bool readItem(QObject *item) = 0;
virtual int firstLevelItemsCount() = 0;
virtual QString lastError() = 0;
virtual void setPassPhrase(const QString& passPhrase) = 0;
virtual ~ItemsReaderIntf(){}
};

View File

@ -109,7 +109,7 @@ void XmlQStringSerializator::save(const QVariant &value, QString name)
QDomElement _node = doc()->createElement(name);
_node.setAttribute("Type","QString");
if (name.compare("password")==0){
Chipper chipper;
Chipper chipper(passPhrase());
QByteArray ba = chipper.cryptString(value.toString());
//ba.append();
_node.setAttribute("Value",QString(ba.toBase64()));
@ -123,7 +123,7 @@ QVariant XmlQStringSerializator::loadValue()
{
if (node()->tagName().compare("password")==0){
QByteArray ba;
Chipper chipper;
Chipper chipper(passPhrase());
ba.append(node()->attribute("Value").toLatin1());
return chipper.decryptByteArray(QByteArray::fromBase64(ba));
} else

View File

@ -36,7 +36,7 @@
namespace LimeReport{
class XmlBaseSerializator : public SerializatorIntf{
class XmlBaseSerializator : public virtual SerializatorIntf{
public:
XmlBaseSerializator(QDomDocument *doc, QDomElement *node):m_doc(doc),m_node(node){}
protected:
@ -48,10 +48,21 @@ private:
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:
XmlQStringSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
XmlQStringSerializator(QDomDocument *doc, QDomElement *node):XmlCryptedSerializator(doc,node){}
private:
virtual void save(const QVariant &value,QString name);
virtual QVariant loadValue();

View File

@ -135,6 +135,11 @@ QString XMLReader::lastError()
return m_error;
}
void XMLReader::setPassPhrase(const QString &passPhrase)
{
m_passPhrase = passPhrase;
}
bool XMLReader::extractFirstNode()
{
if (m_firstNode.isNull()){
@ -166,6 +171,10 @@ QVariant XMLReader::getValue(QDomElement *node)
if (creator) {
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 QVariant();

View File

@ -44,14 +44,17 @@ public:
XMLReader();
XMLReader(QSharedPointer<QDomDocument> doc);
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);
void readItemFromNode(QObject *item, QDomElement *node);
@ -60,7 +63,7 @@ protected:
void readCollection(QObject *item, QDomElement *node);
QVariant getValue(QDomElement *node);
virtual QString lastError();
protected:
bool extractFirstNode();
QString m_error;
@ -68,6 +71,11 @@ private:
QSharedPointer<QDomDocument> m_doc;
QDomElement m_curNode;
QDomElement m_firstNode;
QString m_passPhrase;
};
class FileXMLReader : public XMLReader{

View File

@ -113,6 +113,11 @@ QByteArray XMLWriter::saveToByteArray()
return res;
}
void XMLWriter::setPassPhrase(const QString &passPhrase)
{
m_passPhrase = passPhrase;
}
QDomElement XMLWriter::putQObjectItem(QString name, QObject *item)
{
Q_UNUSED(name)
@ -158,6 +163,10 @@ void XMLWriter::saveProperty(QString name, QObject* item, QDomElement *node)
if (creator) {
QScopedPointer<SerializatorIntf> serializator(creator(m_doc.data(),node));
CryptedSerializator* cs = dynamic_cast<CryptedSerializator*>(serializator.data());
if (cs){
cs->setPassPhrase(m_passPhrase);
}
serializator->save(
item->property(name.toLatin1()),
name

View File

@ -44,10 +44,13 @@ public:
XMLWriter(QSharedPointer<QDomDocument> doc);
~XMLWriter() {}
private:
// ItemsWriterIntf interface
void putItem(QObject* item);
bool saveToFile(QString fileName);
QString saveToString();
QByteArray saveToByteArray();
void setPassPhrase(const QString &passPhrase);
void init();
QDomElement putQObjectItem(QString name, QObject* item);
void putChildQObjectItem(QString name, QObject* item, QDomElement* parentNode);
@ -66,6 +69,7 @@ private:
QSharedPointer<QDomDocument> m_doc;
QString m_fileName;
QDomElement m_rootElement;
QString m_passPhrase;
};
}