1 /***************************************************************************
2 * Copyright (C) 2006 by Brian Johnson *
3 * dev-keepassx@sherbang.com *
5 * Copyright (C) 2007 by Tarek Saidi *
6 * tarek.saidi@arcor.de *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
29 #include "Import_GnuKeyRing.h"
30 #include "lib/FileDialogs.h"
35 QString Import_GnuKeyRing::importDatabase(QWidget* GuiParent, IDatabase* Database){
36 QString FileName=KpxFileDialogs::openExistingFile(GuiParent,
38 tr("Import Database..."),
39 QStringList()<<tr("All Files (*)"));
41 if(FileName==QString())
46 return tr("File not found.");
48 if(!file.open(QIODevice::ReadOnly)){
49 return decodeFileError(file.error());
53 return tr("File is empty.");
55 QTextStream ts(&file);
58 QRegExp newEntry("^#\\d*$");
59 QMap<QString, CGroup*> categories;
61 CGroup* DefaultGroup=pwm->addGroup(NULL);
62 DefaultGroup->Name="def-group";
63 QString* field = NULL;
70 QString line = ts.readLine(400);
71 if (newEntry.exactMatch(line)){
76 if (categories.contains(category)){
77 newGroup=categories[category];
79 newGroup=pwm->addGroup(NULL);
80 newGroup->Name=category;
81 categories.insert(category, newGroup);
84 newGroup = DefaultGroup;
87 CEntry* NewEntry=pwm->addEntry();
88 NewEntry->GroupID=newGroup->ID;
90 NewEntry->UserName=account;
91 NewEntry->Password.setString(password,true);
92 NewEntry->Additional=note;
100 entryNum = line.remove(0,1).toUInt();
101 }else if(entryNum == 0){
102 //Do nothing (waiting for start of first entry)
103 }else if(line.startsWith("Category:")){
104 category = line.remove(0,10);
106 }else if(line.startsWith("Name:")){
107 name = line.remove(0,6);
109 }else if(line.startsWith("Account:")){
110 account = line.remove(0,9);
112 }else if(line.startsWith("Password:")){
113 password = line.remove(0,10);
115 }else if(line.startsWith("Notes:")){
116 note = line.remove(0,7);
118 }else if(field != NULL){
124 pwm->SearchGroupID=-1;
125 pwm->CryptoAlgorithmus=ALGO_AES;
126 pwm->KeyEncRounds=6000;