added missing files to svn.
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@126 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
37
src/export/Export.cpp
Normal file
37
src/export/Export.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi *
|
||||
* tarek.saidi@arcor.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QMessageBox>
|
||||
#include "main.h"
|
||||
#include "Export.h"
|
||||
#include "lib/FileDialogs.h"
|
||||
#include "dialogs/SimplePasswordDlg.h"
|
||||
|
||||
QFile* ExporterBase::openFile(QWidget* parent, QString id, QStringList Filters){
|
||||
QString filename=KpxFileDialogs::saveFile(parent,id,tr("Import File..."),Filters);
|
||||
if(filename==QString())return NULL;
|
||||
QFile* file=new QFile(filename);
|
||||
if(!file->open(QIODevice::ReadWrite|QIODevice::Truncate)){
|
||||
QMessageBox::critical(parent,tr("Export Failed"),decodeFileError(file->error()));
|
||||
delete file;
|
||||
return NULL;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
44
src/export/Export.h
Normal file
44
src/export/Export.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi *
|
||||
* tarek.saidi@arcor.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef _EXPORT_H_
|
||||
#define _EXPORT_H_
|
||||
|
||||
#include <QWidget>
|
||||
#include <QFile>
|
||||
|
||||
#include "Database.h"
|
||||
|
||||
class IExport{
|
||||
public:
|
||||
virtual ~IExport(){};
|
||||
virtual bool exportDatabase(QWidget* GuiParent, IDatabase* Database)=0;
|
||||
virtual QString identifier()=0;
|
||||
virtual QString title()=0;
|
||||
};
|
||||
|
||||
class ExporterBase:public QObject{
|
||||
protected:
|
||||
virtual QFile* openFile(QWidget* GuiParent,QString id,QStringList Filter);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
116
src/export/Export_KeePassX_Xml.cpp
Normal file
116
src/export/Export_KeePassX_Xml.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi *
|
||||
* tarek.saidi@arcor.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QtXml>
|
||||
#include "Export_KeePassX_Xml.h"
|
||||
|
||||
bool Export_KeePassX_Xml::exportDatabase(QWidget* GuiParent,IDatabase* database){
|
||||
db=database;
|
||||
QFile *file=openFile(GuiParent,identifier(),QStringList()<<tr("XML Files (*.xml)") << tr("All Files (*)"));
|
||||
if(!file)return false;
|
||||
QDomDocument doc("KEEPASSX_DATABASE");
|
||||
QDomElement root=doc.createElement("database");
|
||||
doc.appendChild(root);
|
||||
QList<IGroupHandle*> Groups=db->groups();
|
||||
for(int i=0;i<Groups.size();i++){
|
||||
if(Groups[i]->parent()==NULL){
|
||||
addGroup(Groups[i],root,doc);
|
||||
}
|
||||
}
|
||||
file->write(doc.toByteArray());
|
||||
file->close();
|
||||
delete file;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Export_KeePassX_Xml::addGroup(IGroupHandle* group,QDomElement& parent,QDomDocument& doc){
|
||||
QDomElement GroupElement=doc.createElement("group");
|
||||
parent.appendChild(GroupElement);
|
||||
QDomElement Title=doc.createElement("title");
|
||||
QDomElement Icon=doc.createElement("icon");
|
||||
Title.appendChild(doc.createTextNode(group->title()));
|
||||
Icon.appendChild(doc.createTextNode(QString::number(group->image())));
|
||||
GroupElement.appendChild(Title);
|
||||
GroupElement.appendChild(Icon);
|
||||
QList<IGroupHandle*> childs=group->childs();
|
||||
for(int i=0;i<childs.size();i++){
|
||||
addGroup(childs[i],GroupElement,doc);
|
||||
}
|
||||
QList<IEntryHandle*> entries=db->entries(group);
|
||||
for(int i=0;i<entries.size();i++){
|
||||
addEntry(entries[i],GroupElement,doc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Export_KeePassX_Xml::addEntry(IEntryHandle* entry,QDomElement& parent,QDomDocument& doc){
|
||||
QDomElement GroupElement=doc.createElement("entry");
|
||||
parent.appendChild(GroupElement);
|
||||
QDomElement Title=doc.createElement("title");
|
||||
QDomElement Username=doc.createElement("username");
|
||||
QDomElement Password=doc.createElement("password");
|
||||
QDomElement Url=doc.createElement("url");
|
||||
QDomElement Comment=doc.createElement("comment");
|
||||
QDomElement BinaryDesc=doc.createElement("bindesc");
|
||||
QDomElement Binary=doc.createElement("bin");
|
||||
QDomElement Icon=doc.createElement("icon");
|
||||
QDomElement Creation=doc.createElement("creation");
|
||||
QDomElement LastAccess=doc.createElement("lastaccess");
|
||||
QDomElement LastMod=doc.createElement("lastmod");
|
||||
QDomElement Expire=doc.createElement("expire");
|
||||
|
||||
Title.appendChild(doc.createTextNode(entry->title()));
|
||||
Username.appendChild(doc.createTextNode(entry->username()));
|
||||
SecString password=entry->password();
|
||||
password.unlock();
|
||||
Password.appendChild(doc.createTextNode(password.string()));
|
||||
password.lock();
|
||||
Url.appendChild(doc.createTextNode(entry->url()));
|
||||
QStringList CommentLines=entry->comment().split('\n');
|
||||
for(int i=0;i<CommentLines.size();i++){
|
||||
Comment.appendChild(doc.createTextNode(CommentLines[i]));
|
||||
if(i==CommentLines.size()-1)break;
|
||||
Comment.appendChild(doc.createElement("br"));
|
||||
}
|
||||
bool HasAttachment=!entry->binary().isNull();
|
||||
if(HasAttachment){
|
||||
BinaryDesc.appendChild(doc.createTextNode(entry->binaryDesc()));
|
||||
Binary.appendChild(doc.createTextNode(entry->binary().toBase64()));
|
||||
}
|
||||
Icon.appendChild(doc.createTextNode(QString::number(entry->image())));
|
||||
Creation.appendChild(doc.createTextNode(entry->creation().toString(Qt::ISODate)));
|
||||
LastAccess.appendChild(doc.createTextNode(entry->lastAccess().toString(Qt::ISODate)));
|
||||
LastMod.appendChild(doc.createTextNode(entry->lastMod().toString(Qt::ISODate)));
|
||||
Expire.appendChild(doc.createTextNode(entry->expire().toString(Qt::ISODate)));
|
||||
GroupElement.appendChild(Title);
|
||||
GroupElement.appendChild(Username);
|
||||
GroupElement.appendChild(Password);
|
||||
GroupElement.appendChild(Url);
|
||||
GroupElement.appendChild(Comment);
|
||||
if(HasAttachment){
|
||||
GroupElement.appendChild(BinaryDesc);
|
||||
GroupElement.appendChild(Binary);
|
||||
}
|
||||
GroupElement.appendChild(Icon);
|
||||
GroupElement.appendChild(Creation);
|
||||
GroupElement.appendChild(LastAccess);
|
||||
GroupElement.appendChild(LastMod);
|
||||
GroupElement.appendChild(Expire);
|
||||
}
|
||||
39
src/export/Export_KeePassX_Xml.h
Normal file
39
src/export/Export_KeePassX_Xml.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi *
|
||||
* tarek.saidi@arcor.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _EXPORT_KPX_XML_H_
|
||||
#define _EXPORT_KPX_XML_H_
|
||||
|
||||
#include <QObject>
|
||||
#include "Export.h"
|
||||
|
||||
class Export_KeePassX_Xml:public IExport, public ExporterBase{
|
||||
public:
|
||||
virtual bool exportDatabase(QWidget* GuiParent, IDatabase* Database);
|
||||
virtual QString identifier(){return "EXPORT_KEEPASSX_XML";}
|
||||
virtual QString title(){return "KeePassX XML File";}
|
||||
private:
|
||||
void addGroup(IGroupHandle* group,QDomElement& parent,QDomDocument& doc);
|
||||
void addEntry(IEntryHandle* group,QDomElement& parent,QDomDocument& doc);
|
||||
IDatabase* db;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user