diff --git a/src/dialogs/EditEntryDlg.cpp b/src/dialogs/EditEntryDlg.cpp index 51a4b3b..10022ec 100755 --- a/src/dialogs/EditEntryDlg.cpp +++ b/src/dialogs/EditEntryDlg.cpp @@ -60,12 +60,12 @@ CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* paren connect(Edit_Password_w, SIGNAL(textChanged(const QString&)), this, SLOT( OnPasswordwTextChanged(const QString&))); connect(Edit_Password, SIGNAL(textChanged(const QString&)), this, SLOT( OnPasswordTextChanged(const QString&))); connect(ButtonEchoMode, SIGNAL(clicked()), this, SLOT( ChangeEchoMode())); - connect(ButtonCancel, SIGNAL(clicked()), this, SLOT( OnButtonCancel())); + connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT( OnButtonCancel())); connect(ButtonOpenAttachment, SIGNAL(clicked()), this, SLOT( OnNewAttachment())); connect(ButtonDeleteAttachment, SIGNAL(clicked()), this, SLOT( OnDeleteAttachment())); connect(ButtonSaveAttachment, SIGNAL(clicked()), this, SLOT( OnSaveAttachment())); connect(ButtonGenPw, SIGNAL(clicked()), this, SLOT( OnButtonGenPw())); - connect(ButtonOK, SIGNAL(clicked()),this,SLOT(OnButtonOK())); + connect(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),this,SLOT(OnButtonOK())); connect(CheckBox_ExpiresNever,SIGNAL(stateChanged(int)),this,SLOT(OnCheckBoxExpiresNeverChanged(int))); connect(Button_CustomIcons,SIGNAL(clicked()),this,SLOT(OnCustomIcons())); @@ -139,6 +139,7 @@ if(event->spontaneous()==false){ //Added resize event void CEditEntryDlg::resizeEvent(QResizeEvent *event){ createBanner(&BannerPixmap,Icon_Key32x32,tr("Test 2"),width()); + QDialog::resizeEvent(event); } diff --git a/src/dialogs/SimplePasswordDlg.cpp b/src/dialogs/SimplePasswordDlg.cpp index 305b6ef..aacd40e 100755 --- a/src/dialogs/SimplePasswordDlg.cpp +++ b/src/dialogs/SimplePasswordDlg.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (C) 2005 by Tarek Saidi * - * mail@tarek-saidi.de * + * Copyright (C) 2005-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 * @@ -18,46 +18,50 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include +#include +#include #include "main.h" #include "PwmConfig.h" #include "SimplePasswordDlg.h" -CSimplePasswordDialog::CSimplePasswordDialog(QWidget* parent, bool modal, Qt::WFlags fl) +SimplePasswordDialog::SimplePasswordDialog(QWidget* parent, bool modal, Qt::WFlags fl) : QDialog(parent,fl) { -setupUi(this); -if(!config.ShowPasswords)Button_HidePassword->toggle(); -connect(ButtonOK,SIGNAL(clicked()),this,SLOT(OnOK())); -connect(ButtonCancel,SIGNAL(clicked()),this,SLOT(OnCancel())); -connect(Button_HidePassword,SIGNAL(toggled(bool)),this,SLOT(OnHidePasswordToggled(bool))); + setupUi(this); + if(!config.ShowPasswords)Button_HidePassword->toggle(); + connect(buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()),this,SLOT(OnOK())); + connect(buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()),this,SLOT(OnCancel())); + connect(Button_HidePassword,SIGNAL(toggled(bool)),this,SLOT(OnHidePasswordToggled(bool))); + connect(EditPassword,SIGNAL(textChanged(const QString&)),this,SLOT(OnTextChanged(const QString&))); + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } -CSimplePasswordDialog::~CSimplePasswordDialog() +SimplePasswordDialog::~SimplePasswordDialog() { } -void CSimplePasswordDialog::OnCancel() -{ -done(0); +void SimplePasswordDialog::OnTextChanged(const QString& txt){ + if(txt==QString()) + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + else + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } - -void CSimplePasswordDialog::OnOK() +void SimplePasswordDialog::OnCancel() { -password=EditPassword->text(); -done(1); + done(0); } -void CSimplePasswordDialog::OnHidePasswordToggled(bool state) +void SimplePasswordDialog::OnOK() { -if(state)EditPassword->setEchoMode(QLineEdit::Password); -else EditPassword->setEchoMode(QLineEdit::Normal); + password=EditPassword->text(); + done(1); } -/*$SPECIALIZATION$*/ - - +void SimplePasswordDialog::OnHidePasswordToggled(bool state) +{ + if(state)EditPassword->setEchoMode(QLineEdit::Password); + else EditPassword->setEchoMode(QLineEdit::Normal); +} diff --git a/src/dialogs/SimplePasswordDlg.h b/src/dialogs/SimplePasswordDlg.h index fc88c80..7a2fa1e 100755 --- a/src/dialogs/SimplePasswordDlg.h +++ b/src/dialogs/SimplePasswordDlg.h @@ -23,31 +23,21 @@ #include "ui_SimplePasswordDlg.h" -class CSimplePasswordDialog : public QDialog, public Ui_SimplePasswordDialog +class SimplePasswordDialog : public QDialog, public Ui_SimplePasswordDialog { Q_OBJECT public: - CSimplePasswordDialog(QWidget* parent = 0, bool modal = FALSE, Qt::WFlags fl = 0 ); - ~CSimplePasswordDialog(); - /*$PUBLIC_FUNCTIONS$*/ + SimplePasswordDialog(QWidget* parent = 0, bool modal = FALSE, Qt::WFlags fl = 0 ); + ~SimplePasswordDialog(); -public slots: - /*$PUBLIC_SLOTS$*/ - -protected: - /*$PROTECTED_FUNCTIONS$*/ - -protected slots: - /*$PROTECTED_SLOTS$*/ -public: QString password; + public: QString password; public slots: virtual void OnCancel(); -public slots: virtual void OnOK(); -public slots: virtual void OnHidePasswordToggled(bool state); + virtual void OnTextChanged(const QString&); }; #endif diff --git a/src/export/Export_Txt.cpp b/src/export/Export_Txt.cpp index f4d9cd1..cb126fd 100644 --- a/src/export/Export_Txt.cpp +++ b/src/export/Export_Txt.cpp @@ -37,7 +37,9 @@ QString GroupTemplate=QString("\n\ *** Group: %1 ***\n\ "); -QString Export_Txt::exportDatabase(QWidget* GuiParent, IDatabase* db, QIODevice* file){ +bool Export_Txt::exportDatabase(QWidget* GuiParent, IDatabase* db){ + QFile *file=openFile(GuiParent,identifier(),QStringList()< groups=db->sortedGroups(); for(int g=0;gwrite(GroupTemplate.arg(groups[g]->title()).toUtf8()); @@ -54,5 +56,6 @@ QString Export_Txt::exportDatabase(QWidget* GuiParent, IDatabase* db, QIODevice* password.lock(); } } - return QString(); + delete file; + return true; } \ No newline at end of file diff --git a/src/export/Export_Txt.h b/src/export/Export_Txt.h index 12b2386..bb3f1c2 100644 --- a/src/export/Export_Txt.h +++ b/src/export/Export_Txt.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2006 by Tarek Saidi * + * Copyright (C) 2005-2007 by Tarek Saidi * * tarek.saidi@arcor.de * * * * This program is free software; you can redistribute it and/or modify * @@ -21,12 +21,13 @@ #define _EXPORT_TXT_H_ #include -#include "IExport.h" +#include "Export.h" -class Export_Txt:public QObject, public IExport{ +class Export_Txt:public IExport, public ExporterBase{ public: - virtual QString exportDatabase(QWidget* GuiParent, IDatabase* Database, QIODevice* Dest); - virtual QString name(){return QString("Txt");} + virtual bool exportDatabase(QWidget* GuiParent, IDatabase* Database); + virtual QString identifier(){return "e_txt";} + virtual QString title(){return "Text File";} }; #endif diff --git a/src/forms/EditEntryDlg.ui b/src/forms/EditEntryDlg.ui index 1960bd5..5a93995 100644 --- a/src/forms/EditEntryDlg.ui +++ b/src/forms/EditEntryDlg.ui @@ -1,7 +1,5 @@ Tarek Saidi - - EditEntryDialog @@ -48,23 +46,7 @@ 6 - - - - Qt::Vertical - - - QSizePolicy::Minimum - - - - 20 - 50 - - - - - + 0 @@ -72,22 +54,8 @@ 6 - - - - Quality: - - - - - - - Attachment: - - - - - + + 1 @@ -109,53 +77,15 @@ - ... + Ge&n. - - - Title: - - - - - - - Username: - - - - - - - Comment: - - - - - - - - - - %1 - - - - - - - - - - URL: - - + - - + + 1 @@ -177,24 +107,203 @@ - Ge&n. + ... - - - - - - Group: - - - - - + - + + + + + + + 4 + 5 + 0 + 0 + + + + Quality: + + + + + + + + 4 + 5 + 0 + 0 + + + + Attachment: + + + + + + + + 4 + 5 + 0 + 0 + + + + Title: + + + + + + + + 4 + 5 + 0 + 0 + + + + Username: + + + + + + + + 4 + 5 + 0 + 0 + + + + Comment: + + + + + + + %1 + + + + + + + + 4 + 5 + 0 + 0 + + + + URL: + + + + + + + + 4 + 5 + 0 + 0 + + + + Group: + + + + + + + + + + + + + + 4 + 5 + 0 + 0 + + + + Password Repet.: + + + + + + + + 4 + 5 + 0 + 0 + + + + Password: + + + + + + + + 4 + 5 + 0 + 0 + + + + Expires: + + + + + + + + + + QFrame::HLine + + + QFrame::Sunken + + + Qt::Horizontal + + + + + + + 0 + + + 6 + + false @@ -209,107 +318,67 @@ - - - - - + + - Password Repet.: + - - - - - - - - - - - - Password: + + - - + + - Expires: + + + + - - - - - - - QFrame::HLine + + + + - - QFrame::Sunken - - - Qt::Horizontal + + - - - - 0 - - - 6 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + 0 + + + 6 + + + - + Never - - - - %1 Bit - - - - + + + + + + 0 + + + 6 + + @@ -334,7 +403,30 @@ - + + + + %1 Bit + + + + + + + + + + + + 0 + + + 6 + + + + + Icon: @@ -344,10 +436,10 @@ - + - + > @@ -356,35 +448,28 @@ - - - - &Cancel - - - Alt+C - - - - - - - O&K + + + + Qt::Horizontal - - Alt+K + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok - + - Qt::Horizontal + Qt::Vertical + + + QSizePolicy::Minimum - 40 - 20 + 20 + 50 @@ -392,7 +477,6 @@ - Combo_Group Combo_IconPicker diff --git a/src/forms/MainWindow.ui b/src/forms/MainWindow.ui index 835973e..060109d 100644 --- a/src/forms/MainWindow.ui +++ b/src/forms/MainWindow.ui @@ -137,38 +137,6 @@ - - - &File - - - - &Import from... - - - - - - - &Export to... - - - - - - - - - - - - - - - - - - &View @@ -221,6 +189,35 @@ + + + &File + + + + &Export to... + + + + + &Import from... + + + + + + + + + + + + + + + + + @@ -262,16 +259,6 @@ E&xit - - - PwManager File (*.pwm) - - - - - KWallet XML-File (*.xml) - - Add New Group... @@ -464,11 +451,6 @@ &KeePassX Handbook... - - - Plain Text (*.txt) - - Hide @@ -526,14 +508,14 @@ - KeepassGroupView + KeepassEntryView QTreeWidget -
../../src/lib/GroupView.h
+
../../src/lib/EntryView.h
- KeepassEntryView + KeepassGroupView QTreeWidget -
../../src/lib/EntryView.h
+
../../src/lib/GroupView.h
diff --git a/src/forms/SimplePasswordDlg.ui b/src/forms/SimplePasswordDlg.ui index 46c8e26..5a52a6d 100644 --- a/src/forms/SimplePasswordDlg.ui +++ b/src/forms/SimplePasswordDlg.ui @@ -1,7 +1,4 @@ - - - SimplePasswordDialog @@ -15,7 +12,7 @@ 0 - 0 + 5 0 0 @@ -28,87 +25,92 @@ - 345 + 16777215 90 Enter your Password - - - - 10 - 20 - 60 - 20 - - - - Password: - - - - - - 170 - 60 - 80 - 23 - - - - O&K - - - Alt+K - - - - - - 257 - 60 - 80 - 23 - - - - &Cancel - - - Alt+C - - - - - - 80 - 20 - 240 - 21 - - - - - - - 320 - 20 - 20 - 21 - - - - ... - - - + + + 9 - - true + + 6 - + + + + 0 + + + 6 + + + + + + 4 + 5 + 0 + 0 + + + + Password: + + + + + + + + + + + 5 + 0 + 0 + 0 + + + + + 28 + 0 + + + + + 28 + 16777215 + + + + ... + + + + + + true + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + qPixmapFromMimeSource diff --git a/src/import/Import_KWalletXml.cpp b/src/import/Import_KWalletXml.cpp index 339afb9..b3262a1 100755 --- a/src/import/Import_KWalletXml.cpp +++ b/src/import/Import_KWalletXml.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (C) 2005 by Tarek Saidi * - * mail@tarek-saidi.de * + * Copyright (C) 2005-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 * @@ -19,11 +19,9 @@ ***************************************************************************/ #include "Import_KWalletXml.h" -#include -#include -#include -#include -using namespace std; +#include +#include + /* bool Import_KWalletXml::importFile(QString FileName,StandardDatabase* pwm,QString& err){ diff --git a/src/import/Import_PwManager.cpp b/src/import/Import_PwManager.cpp index 296c6d6..80973f7 100755 --- a/src/import/Import_PwManager.cpp +++ b/src/import/Import_PwManager.cpp @@ -18,150 +18,152 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include +#include #include -#include -//#include "crypto/blowfish.h" -//#include "crypto/sha1.h" +#include +#include +#include "crypto/blowfish.h" +#include "crypto/sha1.h" #include "Import_PwManager.h" using namespace std; - /* -bool Import_PwManager::importFile(QString filename, QString password, StandardDatabase* db, QString& err){ -database=db; -QFile file(filename); -char* buffer=NULL; -int offset=0; -int len=0; -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;} -if(len=file.size()) buffer=new char[len]; -else {err+=QObject::tr("File is empty."); return false;} -file.read(buffer,len); -file.close(); -if(QString::fromAscii(buffer,17)!="PWM_PASSWORD_FILE") - {err+=QObject::tr("File is no valid PwManager file."); return false;} -offset+=17; -if(buffer[offset]!=0x05) - {err+=QObject::tr("Unsupported file version."); return false;} -offset++; -if(buffer[offset]!=0x01) - {err+=QObject::tr("Unsupported hash algorithm."); return false;} -offset++; -if(buffer[offset]!=0x01) - {err+=QObject::tr("Unsupported hash algorithm."); return false;} -offset++; -if(buffer[offset]!=0x01) - {err+=QObject::tr("Unsupported encryption algorithm."); return false;} -offset++; -if(buffer[offset]==0x00)Compression=0; -if(buffer[offset]==0x01)Compression=1; -if(buffer[offset]==0x02)Compression=2; - ///@TODO Compression - if(buffer[offset]) - {err+=QObject::tr("Compressed files are not supported yet."); return false;} -offset++; -if(buffer[offset]==0x00)KeyFlag=true; -else KeyFlag=false; -offset++; -//Reserved Bytes (64) -offset+=64; -memcpy(KeyHash,buffer+offset,20); -offset+=20; -memcpy(DataHash,buffer+offset,20); -offset+=20; - -Blowfish blowfish; -int pwlen=password.length(); -byte* Key=new byte[pwlen]; -byte* xml=new byte[len-offset+1]; -xml[len-offset]=0; -memcpy(Key,password.toAscii(),pwlen); - char* key_hash=new char[20]; - CSHA1 sha; - sha.Update(Key,pwlen); - sha.Final(); - sha.GetHash((unsigned char*)key_hash); - if(memcmp(key_hash,KeyHash,20)){ - delete[] Key; delete [] key_hash; delete [] buffer; - err+=QObject::tr("Wrong password."); - return false; -} -delete [] key_hash; -blowfish.bf_setkey(Key,password.length()); -blowfish.bf_decrypt(xml,(byte*)buffer+offset,len-offset); -delete [] Key; -delete [] buffer; - char* content_hash=new char[20]; - sha.Reset(); - sha.Update(xml,strlen((char*)xml)-1); - sha.Final(); - sha.GetHash((unsigned char*)content_hash); - if(memcmp(content_hash,DataHash,20)){ - delete [] content_hash; delete [] xml; - err+=QObject::tr("File is damaged (hash test failed)."); - return false; -} -delete[] content_hash; - -if(!parseXmlContent((char*)xml)){ - delete [] xml; - err+=QObject::tr("Invalid XML data (see stdout for details)."); return false;} -database->CalcMasterKeyByPassword(password); -return true; +bool Import_PwManager::importDatabase(QWidget* GuiParent, IDatabase* db){ + database=db; + QFile* file=openFile(GuiParent,identifier(),QStringList()<size()) buffer=new char[len]; + else {QMessageBox::critical(GuiParent,tr("Import Failed"),tr("File is empty.")); delete file; return false;} + file->read(buffer,len); + file->close(); + delete file; + if(QString::fromAscii(buffer,17)!="PWM_PASSWORD_FILE") + {QMessageBox::critical(GuiParent,tr("Import Failed"),tr("File is no valid PwManager file.")); return false;} + offset+=17; + if(buffer[offset]!=0x05) + {QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Unsupported file version.")); return false;} + offset++; + if(buffer[offset]!=0x01) + {QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Unsupported hash algorithm.")); return false;} + offset++; + if(buffer[offset]!=0x01) + {QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Unsupported hash algorithm.")); return false;} + offset++; + if(buffer[offset]!=0x01) + {QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Unsupported encryption algorithm.")); return false;} + offset++; + if(buffer[offset]==0x00)Compression=0; + if(buffer[offset]==0x01)Compression=1; + if(buffer[offset]==0x02)Compression=2; + ///@TODO Compression + if(buffer[offset]) + {QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Compressed files are not supported yet.")); return false;} + offset++; + if(buffer[offset]==0x00)KeyFlag=true; + else KeyFlag=false; + offset++; + //Reserved Bytes (64) + offset+=64; + memcpy(KeyHash,buffer+offset,20); + offset+=20; + memcpy(DataHash,buffer+offset,20); + offset+=20; + + Blowfish blowfish; + int pwlen=password.length(); + byte* Key=new byte[pwlen]; + byte* xml=new byte[len-offset+1]; + xml[len-offset]=0; + memcpy(Key,password.toAscii(),pwlen); + char* key_hash=new char[20]; + CSHA1 sha; + sha.Update(Key,pwlen); + sha.Final(); + sha.GetHash((unsigned char*)key_hash); + if(memcmp(key_hash,KeyHash,20)){ + delete[] Key; delete [] key_hash; delete [] buffer; + QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Wrong password.")); + return false; + } + delete [] key_hash; + blowfish.bf_setkey(Key,password.length()); + blowfish.bf_decrypt(xml,(byte*)buffer+offset,len-offset); + delete [] Key; + delete [] buffer; + char* content_hash=new char[20]; + sha.Reset(); + sha.Update(xml,strlen((char*)xml)-1); + sha.Final(); + sha.GetHash((unsigned char*)content_hash); + if(memcmp(content_hash,DataHash,20)){ + delete [] content_hash; delete [] xml; + QMessageBox::critical(GuiParent,tr("Import Failed"),tr("File is damaged (hash test failed).")); + return false; + } + delete[] content_hash; + + if(!parseXmlContent((char*)xml)){ + delete [] xml; + QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML data (see stdout for details).")); return false;} + dynamic_cast(database)->authByPwd(password); + return true; } bool Import_PwManager::parseXmlContent(char* content){ -QDomDocument db; -QString err; -int col,line; -if(!db.setContent(QString::fromUtf8(content,strlen(content)-1),false,&err,&line,&col)){ - qWarning("Import_PwManager::parseXmlContent():\n"); - qWarning(((err+" (Line:%1 Column:%2)").arg(line).arg(col)+QString('\n')).toAscii()); - return false;} -QDomElement root=db.documentElement(); -if(root.tagName()!="P")return false; -//Achtung! Kommentare und Kategorien haben das selbe Tag "c" -if(!root.elementsByTagName("c").item(0).isElement())return false; -QDomElement groups=root.elementsByTagName("c").item(0).toElement(); - -int i=0; -while(1){ - QDomElement CurrGroup; - if(!groups.elementsByTagName("c"+QString::number(i)).length())break; - if(groups.elementsByTagName("c"+QString::number(i)).length()>1)return false; - if(!groups.elementsByTagName("c"+QString::number(i)).item(0).isElement())return false; - CurrGroup=groups.elementsByTagName("c"+QString::number(i)).item(0).toElement(); - if(!CurrGroup.hasAttribute("n"))return false; - IGroupHandle* NewGroup=database->addGroup(NULL); - NewGroup->Name=CurrGroup.attribute("n"); - int j=0; + QDomDocument db; + QString err; + int col,line; + if(!db.setContent(QString::fromUtf8(content,strlen(content)-1),false,&err,&line,&col)){ + qWarning("Import_PwManager::parseXmlContent():\n"); + qWarning(((err+" (Line:%1 Column:%2)").arg(line).arg(col)+QString('\n')).toAscii()); + return false;} + QDomElement root=db.documentElement(); + if(root.tagName()!="P")return false; + //Achtung! Kommentare und Kategorien haben das selbe Tag "c" + if(!root.elementsByTagName("c").item(0).isElement())return false; + QDomElement groups=root.elementsByTagName("c").item(0).toElement(); + + int i=0; while(1){ - QDomElement CurrEntry; - if(!CurrGroup.elementsByTagName("e"+QString::number(j)).length())break; - if(CurrGroup.elementsByTagName("e"+QString::number(j)).length()>1)return false; - if(!CurrGroup.elementsByTagName("e"+QString::number(j)).item(0).isElement())return false; - CurrEntry=CurrGroup.elementsByTagName("e"+QString::number(j)).item(0).toElement(); - if(!xml_parseEntryAttributes(&CurrEntry,NewGroup))return false; - j++; + QDomElement CurrGroup; + if(!groups.elementsByTagName("c"+QString::number(i)).length())break; + if(groups.elementsByTagName("c"+QString::number(i)).length()>1)return false; + if(!groups.elementsByTagName("c"+QString::number(i)).item(0).isElement())return false; + CurrGroup=groups.elementsByTagName("c"+QString::number(i)).item(0).toElement(); + if(!CurrGroup.hasAttribute("n"))return false; + IGroupHandle* NewGroup=database->addGroup(&CGroup(),NULL); + NewGroup->setTitle(CurrGroup.attribute("n")); + int j=0; + while(1){ + QDomElement CurrEntry; + if(!CurrGroup.elementsByTagName("e"+QString::number(j)).length())break; + if(CurrGroup.elementsByTagName("e"+QString::number(j)).length()>1)return false; + if(!CurrGroup.elementsByTagName("e"+QString::number(j)).item(0).isElement())return false; + CurrEntry=CurrGroup.elementsByTagName("e"+QString::number(j)).item(0).toElement(); + if(!xml_parseEntryAttributes(&CurrEntry,NewGroup))return false; + j++; + } + i++; } - i++; + + return true; } -return true; -} - -bool Import_PwManager::xml_parseEntryAttributes(QDomElement* EntryElement,IGroupHandle* NewGroup){/* -IEntryHandle* e=database->addEntry(); -e->Title=EntryElement->elementsByTagName("d").item(0).toElement().text(); -e->UserName=EntryElement->elementsByTagName("n").item(0).toElement().text(); -QString pw=EntryElement->elementsByTagName("p").item(0).toElement().text(); -e->Password.setString(pw,true); -e->Additional=EntryElement->elementsByTagName("c").item(0).toElement().text(); -e->Additional=e->Additional.replace("$>--endl--<$","\n"); -e->URL=EntryElement->elementsByTagName("u").item(0).toElement().text(); -e->GroupID=NewGroup->ID; -return true; -} - */ \ No newline at end of file +bool Import_PwManager::xml_parseEntryAttributes(QDomElement* EntryElement,IGroupHandle* NewGroup){ + IEntryHandle* e=database->newEntry(NewGroup); + e->setTitle(EntryElement->elementsByTagName("d").item(0).toElement().text()); + e->setUsername(EntryElement->elementsByTagName("n").item(0).toElement().text()); + QString pw(EntryElement->elementsByTagName("p").item(0).toElement().text()); + SecString spw; + spw.setString(pw,true); + e->setPassword(spw); + QString comment=EntryElement->elementsByTagName("c").item(0).toElement().text(); + comment.replace("$>--endl--<$","\n"); + e->setComment(comment); + e->setUrl(EntryElement->elementsByTagName("u").item(0).toElement().text()); + return true; +} \ No newline at end of file diff --git a/src/import/Import_PwManager.h b/src/import/Import_PwManager.h index d91acaf..ab3becf 100755 --- a/src/import/Import_PwManager.h +++ b/src/import/Import_PwManager.h @@ -20,23 +20,26 @@ #ifndef _IMPORT_PWMANAGER_ #define _IMPORT_PWMANAGER_ -#include -#include -#include "StandardDatabase.h" +#include +#include +#include "Database.h" +#include "Import.h" -/* -class Import_PwManager{ -public: -bool importFile(QString FileName, QString Password,StandardDatabase* db,QString& err); -private: - bool KeyFlag; // true=Password, false=Chipcard - int Compression; // 0=none, 1=gzip, 2=bzip2 - unsigned char KeyHash[20]; - unsigned char DataHash[20]; - StandardDatabase* database; - bool parseXmlContent(char* content); - bool xml_parseEntryAttributes(QDomElement* EntryTag,IGroupHandle* parent); +class Import_PwManager:public IImport, public ImporterBase{ + public: + virtual bool importDatabase(QWidget* GuiParent, IDatabase* Database); + virtual QString identifier(){return "PwManager";} + virtual QString title(){return "PwManager File (*.pwm)";} + private: + bool KeyFlag; // true=Password, false=Chipcard + int Compression; // 0=none, 1=gzip, 2=bzip2 + unsigned char KeyHash[20]; + unsigned char DataHash[20]; + IDatabase* database; + + bool parseXmlContent(char* content); + bool xml_parseEntryAttributes(QDomElement* EntryTag,IGroupHandle* parent); }; -*/ + #endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0567d14..48315eb 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -45,7 +45,9 @@ #include "lib/FileDialogs.h" #include "import/Import_PwManager.h" #include "import/Import_KWalletXml.h" +#include "import/Import_KeePassX_Xml.h" #include "export/Export_Txt.h" +#include "export/Export_KeePassX_Xml.h" #include "dialogs/AboutDlg.h" #include "dialogs/SearchDlg.h" @@ -62,6 +64,11 @@ QDBusServer* dbusServer; QDBusConnection* dbusCon; +Import_KeePassX_Xml import_KeePassX_Xml; +Import_PwManager import_PwManager; +Export_Txt export_Txt; +Export_KeePassX_Xml export_KeePassX_Xml; + KeepassMainWindow::KeepassMainWindow(const QString& ArgFile,QWidget *parent, Qt::WFlags flags):QMainWindow(parent,flags){ Start=true; @@ -115,9 +122,8 @@ void KeepassMainWindow::setupConnections(){ connect(FileSettingsAction, SIGNAL(triggered()), this, SLOT(OnFileSettings())); connect(FileChangeKeyAction, SIGNAL(triggered()), this, SLOT(OnFileChangeKey())); connect(FileExitAction, SIGNAL(triggered()), this, SLOT(OnFileExit())); - connect(FileImpPwmAction, SIGNAL(triggered()), this, SLOT(OnImportFromPwm())); - connect(FileImpKWalletXmlAction, SIGNAL(triggered()), this,SLOT(OnImportFromKWalletXml())); - connect(FileExpPlainTextAction,SIGNAL(triggered()),this,SLOT(OnExportToTxt())); + connect(menuImport,SIGNAL(triggered(QAction*)),this,SLOT(OnImport(QAction*))); + connect(menuExport,SIGNAL(triggered(QAction*)),this,SLOT(OnExport(QAction*))); connect(EditNewGroupAction, SIGNAL(triggered()), GroupView, SLOT(OnNewGroup())); connect(EditEditGroupAction, SIGNAL(triggered()), GroupView, SLOT(OnEditGroup())); @@ -274,6 +280,23 @@ void KeepassMainWindow::setupMenus(){ SysTrayMenu->addAction(FileExitAction); SysTray->setContextMenu(SysTrayMenu); + #define _add_import(name){\ + QAction* import=new QAction(this);\ + import->setData(qVariantFromValue(dynamic_cast(&name)));\ + import->setText(name.title());\ + menuImport->addAction(import);} + + #define _add_export(name){\ + QAction* Export=new QAction(this);\ + Export->setData(qVariantFromValue(dynamic_cast(&name)));\ + Export->setText(name.title());\ + menuExport->addAction(Export);} + + _add_import(import_KeePassX_Xml) + _add_import(import_PwManager) + _add_export(export_Txt); + _add_export(export_KeePassX_Xml); + //FileNewMenu->setShortcut(tr("Ctrl+N")); FileOpenAction->setShortcut(tr("Ctrl+O")); FileSaveAction->setShortcut(tr("Ctrl+S")); @@ -317,7 +340,7 @@ void KeepassMainWindow::openDatabase(QString filename,bool IsAuto){ } GroupView->db=db; EntryView->db=db; - setupDatabaseConnections(db); + setupDatabaseConnections(db); QString err; StatusBarGeneral->setText(tr("Loading Database...")); if(db->load(filename)==true){ @@ -431,8 +454,6 @@ FileSaveAsAction->setEnabled(IsOpen); FileCloseAction->setEnabled(IsOpen); FileSettingsAction->setEnabled(IsOpen); FileChangeKeyAction->setEnabled(IsOpen); -FileExpPlainTextAction->setEnabled(IsOpen); - EditSearchAction->setEnabled(IsOpen); GroupView->setEnabled(IsOpen); @@ -618,6 +639,7 @@ switch(EntrySelection){ else Q_ASSERT(false); } + bool KeepassMainWindow::OnFileSave(){ if(!db->file()) return OnFileSaveAs(); @@ -661,129 +683,31 @@ void KeepassMainWindow::OnFileExit(){ close(); } -void KeepassMainWindow::OnExportToTxt(){ - IExport* exporter=new Export_Txt(); - QStringList Filters; - Filters << tr("All Files (*)"); - Filters << tr("Text Files (*.txt)"); - exportDatabase(exporter, Filters); - delete exporter; -} - -void KeepassMainWindow::exportDatabase(IExport* exporter,QStringList Filters){ - QString filename=KpxFileDialogs::saveFile(this,"Export_"+exporter->name(),tr("Export Database"),Filters,true); - if(filename==QString())return; - QFile file(filename); - if(!file.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - QMessageBox::critical(this,tr("Export Failed"),decodeFileError(file.error())); - return; - } - QString err=exporter->exportDatabase(this,db,&file); - if(err!=QString()){ - QMessageBox::critical(this,tr("Export Failed"),err); - return; - } - file.close(); - if(file.error()!=QFile::NoError){ - QMessageBox::critical(this,tr("Export Failed"),decodeFileError(file.error())); - return; - } - -} -void KeepassMainWindow::OnImportFromPwm(){ - /* -if(FileOpen) - if(!closeDatabase())return; -QString filename=QFileDialog::getOpenFileName(this,tr("Open Database..."),QDir::homePath(),"*.pwm"); -if(filename!=QString::null){ - Q_ASSERT(!FileOpen); - db = new PwDatabase(); - db->newDatabase(); - CSimplePasswordDialog dlg(this,true); - if(!dlg.exec()){ - delete db; - db=NULL; - StatusBarGeneral->setText(tr("Ready")); - } - GroupView->db=db; - EntryView->db=db; - QString err; - StatusBarGeneral->setText(tr("Loading Database...")); - Import_PwManager import; - if(import.importFile(filename,dlg.password,db,err)==true){ - //SUCCESS - setWindowTitle(tr("KeePassX [new]")); - GroupView->updateItems(); - EntryView->updateItems(0); - setStateFileOpen(true); - setStateFileModified(true); - } - else{ - //ERROR - delete db; - StatusBarGeneral->setText(tr("Loading Failed")); - if(err=="")err=tr("Unknown error in Import_PwManager::importFile()()"); - QMessageBox::critical(this,tr("Error") - ,tr("The following error occured while opening the database:\n%1") - .arg(err),tr("OK")); - } - StatusBarGeneral->setText(tr("Ready")); - } - */ +void KeepassMainWindow::OnExport(QAction* action){ + dynamic_cast(action->data().value())->exportDatabase(this,db); } -void KeepassMainWindow::OnImportFromKWalletXml(){ - /* -if(FileOpen) - if(!closeDatabase())return; -QString filename=QFileDialog::getOpenFileName(this,tr("Open Database..."),QDir::homePath(),"*.pwm"); -if(filename!=QString::null){ - Q_ASSERT(!FileOpen); - db = new PwDatabase(); - db->newDatabase(); - GroupView->db=db; - EntryView->db=db; - QString err; - StatusBarGeneral->setText(tr("Loading Database...")); - Import_KWalletXml import; - if(import.importFile(filename,db,err)==true){ - //SUCCESS - setWindowTitle(tr("KeePassX [new]")); - GroupView->updateItems(); - EntryView->updateItems(0); - setStateFileOpen(true); - setStateFileModified(true); - } - else{ - //ERROR - delete db; - StatusBarGeneral->setText(tr("Loading Failed")); - if(err=="")err=tr("Unknown error in Import_KWalletXml::importFile()"); - QMessageBox::critical(this,tr("Error") - ,tr("The following error occured while opening the database:\n%1") - .arg(err),tr("OK")); - } - StatusBarGeneral->setText(tr("Ready")); +void KeepassMainWindow::OnImport(QAction* action){ + if(FileOpen) + if(!closeDatabase())return; + IDatabase* tmpdb=dynamic_cast(new StandardDatabase()); + tmpdb->create(); + if(dynamic_cast(action->data().value())->importDatabase(this,tmpdb)){ + db=tmpdb; + GroupView->db=db; + EntryView->db=db; + setupDatabaseConnections(db); + setWindowTitle(tr("* - KeePassX")); + GroupView->createItems(); + EntryView->showGroup(NULL); + setStateFileOpen(true); + setStateFileModified(true); } - */ -} - -/* -void KeepassMainWindow::OnEntrySelectionChanged(){ -updateDetailView(); -if(EntryView->selectedItems().size()==0) - setStateEntrySelected(NONE); -if(EntryView->selectedItems().size()==1) - setStateEntrySelected(SINGLE); -if(EntryView->selectedItems().size()>1) - setStateEntrySelected(MULTIPLE); + else + delete tmpdb; + } -*/ - - - - void KeepassMainWindow::removeFromSearchResults(int id){ @@ -958,4 +882,4 @@ void KeepassMainWindow::OnSysTrayActivated(QSystemTrayIcon::ActivationReason rea void KeepassMainWindow::OnExtrasPasswordGen(){ CGenPwDialog dlg(this,true); dlg.exec(); -} \ No newline at end of file +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 0f6241e..3fb35cf 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -43,7 +43,7 @@ #include "PwmConfig.h" #include "lib/EntryView.h" #include "lib/GroupView.h" -#include "export/IExport.h" +#include "export/Export.h" #include "ui_MainWindow.h" @@ -67,9 +67,6 @@ class KeepassMainWindow : public QMainWindow, public Ui_MainWindow{ void OnFileSettings(); void OnFileChangeKey(); void OnFileExit(); - void OnImportFromPwm(); - void OnImportFromKWalletXml(); - void OnExportToTxt(); void OnEditOpenUrl(); void OnSearch(); void OnGroupSearch(); @@ -92,6 +89,8 @@ class KeepassMainWindow : public QMainWindow, public Ui_MainWindow{ void OnShowSearchResults(); void OnEntryChanged(SelectionState); void OnSysTrayActivated(QSystemTrayIcon::ActivationReason); + void OnImport(QAction*); + void OnExport(QAction*); private: void closeEvent(QCloseEvent* event); diff --git a/src/src.pro b/src/src.pro index 2a001b3..152d007 100755 --- a/src/src.pro +++ b/src/src.pro @@ -61,8 +61,12 @@ HEADERS += lib/IniReader.h \ lib/SecString.h \ crypto/twoclass.h \ crypto/twofish.h \ + import/Import.h \ + import/Import_KeePassX_Xml.h \ import/Import_PwManager.h \ export/Export_Txt.h \ + export/Export_KeePassX_Xml.h \ + export/Export.h \ import/Import_KWalletXml.h \ PwmConfig.h \ dialogs/AboutDlg.h \ @@ -95,6 +99,8 @@ HEADERS += lib/IniReader.h \ crypto/aescpp.h \ crypto/sha256.h \ crypto/yarrow.h \ + crypto/blowfish.h \ + crypto/sha1.h \ lib/WaitAnimationWidget.h \ plugins/interfaces/IFileDialog.h \ plugins/interfaces/IKdeInit.h \ @@ -108,8 +114,14 @@ SOURCES += lib/IniReader.cpp \ lib/SecString.cpp \ crypto/twoclass.cpp \ crypto/twofish.cpp \ + crypto/blowfish.cpp \ + crypto/sha1.cpp \ + import/Import.cpp \ import/Import_PwManager.cpp \ + import/Import_KeePassX_Xml.cpp \ export/Export_Txt.cpp \ + export/Export_KeePassX_Xml.cpp \ + export/Export.cpp \ import/Import_KWalletXml.cpp \ PwmConfig.cpp \ dialogs/AboutDlg.cpp \