1 /***************************************************************************
2 * Copyright (C) 2005-2007 by Tarek Saidi *
3 * tarek.saidi@arcor.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; version 2 of the License. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "Import_KWalletXml.h"
24 bool Import_KWalletXml::importDatabase(QWidget* GuiParent, IDatabase* db){
25 QFile* file=openFile(GuiParent,identifier(),QStringList()<<tr("XML Files (*.xml)")<<tr("All Files (*)"));
26 if(!file)return false;
28 quint8* buffer=new quint8[len];
29 file->read((char*)buffer,len);
35 if(!doc.setContent(QString::fromUtf8((char*)buffer,len),false,&xmlerr,&line,&col)){
36 qWarning("Import_PwManager::parseXmlContent():\n");
37 qWarning("%s (Line:%d Column:%d)\n",CSTR(xmlerr), line, col);
38 QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML data (see stdout for details)."));
42 QDomElement root=doc.documentElement();
43 if(root.tagName()!="wallet"){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
44 QDomNodeList groups=root.elementsByTagName("folder");
45 if(!groups.length()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Document does not contain data.")); return false;}
46 for(int i=0;i<groups.length();i++){
47 if(!groups.item(i).isElement()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
48 QDomElement CurrGroup=groups.item(i).toElement();
49 if(!CurrGroup.hasAttribute("name")){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
51 NewGroup.Title=CurrGroup.attribute("name");
52 IGroupHandle* NewGroupHandle=db->addGroup(&NewGroup,NULL);
53 QDomNodeList entries=CurrGroup.elementsByTagName("password");
54 for(int j=0;j<entries.length();j++){
55 if(!entries.item(j).isElement()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
56 QDomElement CurrEntry=entries.item(j).toElement();
57 if(!CurrEntry.hasAttribute("name")){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
58 IEntryHandle* NewEntry=db->newEntry(NewGroupHandle);
59 NewEntry->setTitle(CurrEntry.attribute("name"));
60 QString pw=CurrEntry.text();
62 pws.setString(pw,true);
63 NewEntry->setPassword(pws);