showing 'group' column only when search results are shown,
added KWalletImport. git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@128 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
@@ -21,59 +21,50 @@
|
||||
#include "Import_KWalletXml.h"
|
||||
#include <QFile>
|
||||
#include <QtXml>
|
||||
#include <QMessageBox>
|
||||
|
||||
/*
|
||||
|
||||
bool Import_KWalletXml::importFile(QString FileName,StandardDatabase* pwm,QString& err){
|
||||
QFile file(FileName);
|
||||
if(!file.exists()){
|
||||
err+=QObject::tr("File not found.");
|
||||
return false;}
|
||||
if(!file.open(QIODevice::ReadOnly)){
|
||||
err+=QObject::tr("Could not open file.");
|
||||
return false;}
|
||||
int len=file.size();
|
||||
if(len==0){
|
||||
err+=QObject::tr("File is empty.");
|
||||
return false;}
|
||||
quint8* buffer=new quint8[len];
|
||||
file.read((char*)buffer,len);
|
||||
file.close();
|
||||
QDomDocument doc;
|
||||
QString xmlerr;
|
||||
int col,line;
|
||||
if(!doc.setContent(QString::fromUtf8((char*)buffer,len),false,&xmlerr,&line,&col)){
|
||||
qWarning("Import_PwManager::parseXmlContent():\n");
|
||||
qWarning(((xmlerr+" (Line:%1 Column:%2)").arg(line).arg(col)+QString('\n')).toAscii());
|
||||
err+=QObject::tr("Invalid XML file (see stdout for details).");
|
||||
bool Import_KWalletXml::importDatabase(QWidget* GuiParent, IDatabase* db){
|
||||
QFile* file=openFile(GuiParent,identifier(),QStringList()<<tr("XML Files (*.xml)")<<tr("All Files (*)"));
|
||||
if(!file)return false;
|
||||
int len=file->size();
|
||||
quint8* buffer=new quint8[len];
|
||||
file->read((char*)buffer,len);
|
||||
file->close();
|
||||
delete file;
|
||||
QDomDocument doc;
|
||||
QString xmlerr;
|
||||
int col,line;
|
||||
if(!doc.setContent(QString::fromUtf8((char*)buffer,len),false,&xmlerr,&line,&col)){
|
||||
qWarning("Import_PwManager::parseXmlContent():\n");
|
||||
qWarning(((xmlerr+" (Line:%1 Column:%2)").arg(line).arg(col)+QString('\n')).toAscii());
|
||||
QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML data (see stdout for details)."));
|
||||
delete [] buffer;
|
||||
return false;}
|
||||
delete [] buffer;
|
||||
return false;}
|
||||
delete [] buffer;
|
||||
QDomElement root=doc.documentElement();
|
||||
if(root.tagName()!="wallet"){err+=QObject::tr("Invalid XML file."); return false;}
|
||||
QDomNodeList groups=root.elementsByTagName("folder");
|
||||
if(!groups.length()){err+=QObject::tr("Document does not contain data."); return false;}
|
||||
for(int i=0;i<groups.length();i++){
|
||||
if(!groups.item(i).isElement()){err+=QObject::tr("Invalid XML file."); return false;}
|
||||
QDomElement CurrGroup=groups.item(i).toElement();
|
||||
if(!CurrGroup.hasAttribute("name")){err+=QObject::tr("Invalid XML file."); return false;}
|
||||
IGroupHandle* NewGroup=pwm->addGroup(NULL);
|
||||
NewGroup->Name=CurrGroup.attribute("name");
|
||||
QDomNodeList entries=CurrGroup.elementsByTagName("password");
|
||||
for(int j=0;j<entries.length();j++){
|
||||
if(!entries.item(j).isElement()){err+=QObject::tr("Invalid XML file."); return false;}
|
||||
QDomElement CurrEntry=entries.item(j).toElement();
|
||||
if(!CurrEntry.hasAttribute("name")){err+=QObject::tr("Invalid XML file."); return false;}
|
||||
IEntryHandle* NewEntry=pwm->addEntry();
|
||||
NewEntry->Title=CurrEntry.attribute("name");
|
||||
NewEntry->GroupID=NewGroup->ID;
|
||||
QString pw=CurrEntry.text();
|
||||
NewEntry->Password.setString(pw,true);
|
||||
}
|
||||
}
|
||||
pwm->file=NULL;
|
||||
pwm->SearchGroupID=-1;
|
||||
pwm->CryptoAlgorithmus=ALGO_AES;
|
||||
pwm->KeyEncRounds=6000;
|
||||
return true;
|
||||
}*/
|
||||
QDomElement root=doc.documentElement();
|
||||
if(root.tagName()!="wallet"){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
|
||||
QDomNodeList groups=root.elementsByTagName("folder");
|
||||
if(!groups.length()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Document does not contain data.")); return false;}
|
||||
for(int i=0;i<groups.length();i++){
|
||||
if(!groups.item(i).isElement()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
|
||||
QDomElement CurrGroup=groups.item(i).toElement();
|
||||
if(!CurrGroup.hasAttribute("name")){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
|
||||
CGroup NewGroup;
|
||||
NewGroup.Title=CurrGroup.attribute("name");
|
||||
IGroupHandle* NewGroupHandle=db->addGroup(&NewGroup,NULL);
|
||||
QDomNodeList entries=CurrGroup.elementsByTagName("password");
|
||||
for(int j=0;j<entries.length();j++){
|
||||
if(!entries.item(j).isElement()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
|
||||
QDomElement CurrEntry=entries.item(j).toElement();
|
||||
if(!CurrEntry.hasAttribute("name")){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
|
||||
IEntryHandle* NewEntry=db->newEntry(NewGroupHandle);
|
||||
NewEntry->setTitle(CurrEntry.attribute("name"));
|
||||
QString pw=CurrEntry.text();
|
||||
SecString pws;
|
||||
pws.setString(pw,true);
|
||||
NewEntry->setPassword(pws);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -20,14 +20,14 @@
|
||||
|
||||
#ifndef _IMPORT_KWALLET_H_
|
||||
#define _IMPORT_KWALLET_H_
|
||||
#include <qstring.h>
|
||||
#include "StandardDatabase.h"
|
||||
|
||||
class Import_KWalletXml{
|
||||
public:
|
||||
bool importFile(QString FileName,StandardDatabase* db,QString& err);
|
||||
private:
|
||||
#include "Database.h"
|
||||
#include "Import.h"
|
||||
|
||||
class Import_KWalletXml:public IImport, public ImporterBase{
|
||||
public:
|
||||
virtual bool importDatabase(QWidget* GuiParent, IDatabase* Database);
|
||||
virtual QString identifier(){return "KWalletXml";}
|
||||
virtual QString title(){return "KWallet XML File (*.xml)";}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user