Finished PasswordDlg,

Added Text Export

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@56 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 18 years ago
parent 416c7d70d3
commit 6154859afc
  1. 5
      src/PwmConfig.cpp
  2. 63
      src/dialogs/PasswordDlg.cpp
  3. 24
      src/dialogs/SettingsDlg.cpp
  4. 13
      src/dialogs/SettingsDlg.h
  5. 62
      src/export/Export_Txt.cpp
  6. 31
      src/export/Export_Txt.h
  7. 11
      src/forms/MainWindow.ui
  8. 4
      src/forms/PasswordDlg.ui
  9. 2
      src/forms/SettingsDlg.ui
  10. 7
      src/lib/EntryView.cpp
  11. 1
      src/lib/EntryView.h
  12. 32
      src/mainwindow.cpp
  13. 1
      src/mainwindow.h
  14. 2
      src/src.pro

@ -41,7 +41,7 @@ ini.ReadFile();
ClipboardTimeOut=ini.GetValueI("Options","ClipboardTimeOut",20);
Toolbar=ini.GetValueB("UI","ShowToolbar",true);
EntryDetails=ini.GetValueB("UI","ShowEntryDetails",true);
OpenLast=ini.GetValueB("Options","OpenLast",true);
OpenLast=ini.GetValueB("Options","RememberLastFile",true);
LastFile=ini.GetValue("Options","LastFile","").c_str();
ParseColumnString(ini.GetValue("UI","Columns","1111100000").c_str(),Columns);
BannerColor1=ParseColorString(ini.GetValue("Options","BannerColor1","0,104,176").c_str());
@ -68,7 +68,7 @@ AlternatingRowColors=ini.GetValueB("Options","AlternatingRowColors",true);
MountDir=ini.GetValue("Options","MountDir",DEFAULT_MOUNT_DIR).c_str();
RememberLastKey=ini.GetValueB("Options","RememberLastKey",true);
LastKeyLocation=ini.GetValue("Options","LastKeyLocation","").c_str();
LastKeyType=(tKeyType)ini.GetValueI("Option","LastKeyType",(int)PASSWORD);
LastKeyType=(tKeyType)ini.GetValueI("Options","LastKeyType",(int)PASSWORD);
if(!OpenLast)RememberLastKey=false;
return true;
}
@ -77,6 +77,7 @@ bool CConfig::saveToIni(QString filename){
ini.SetValueI("Options","ClipboardTimeOut",ClipboardTimeOut);
ini.SetValueB("UI","ShowToolbar",Toolbar);
ini.SetValueB("UI","ShowEntryDetails",EntryDetails);
ini.SetValueB("Options","RememberLastFile",OpenLast);
if(OpenLast)ini.SetValue("Options","LastFile",(const char*)LastFile);
else ini.SetValue("Options","LastFile","");
ini.SetValue("UI","Columns",(const char*)CreateColumnString(),true);

@ -36,6 +36,32 @@ CPasswordDialog::CPasswordDialog(QWidget* parent, const char* name, bool modal,
{
setupUi(this);
createBanner(Banner,Icon_Key32x32,tr("Database Key"));
QDir media(config.MountDir);
if(media.exists()){
QStringList Paths;
Paths=media.entryList("*",QDir::Dirs);
Paths.erase(Paths.begin()); // delete "."
Paths.erase(Paths.begin()); // delete ".."
for(int i=0;i<Paths.count();i++)
Combo_Dirs->addItem(config.MountDir+Paths[i]);
}
Combo_Dirs->setEditText(QString());
if(config.RememberLastKey){
switch(config.LastKeyType){
case PASSWORD: setStatePasswordOnly(); break;
case KEYFILE: setStateKeyFileOnly();
Combo_Dirs->setEditText(config.LastKeyLocation);
break;
case BOTH: setStateBoth();
CheckBox_Both->setChecked(true);
Combo_Dirs->setEditText(config.LastKeyLocation);
break;
}
}
connect( Combo_Dirs, SIGNAL( editTextChanged(const QString&) ),this, SLOT( OnComboTextChanged(const QString&)));
connect( ButtonCancel, SIGNAL( clicked() ), this, SLOT( OnCancel() ) );
connect( Edit_Password, SIGNAL( textChanged(const QString&) ), this, SLOT( OnPasswordChanged(const QString&) ) );
@ -56,19 +82,6 @@ if(!ChangeKeyMode){
connect( ButtonBrowse, SIGNAL( clicked() ), this, SLOT( OnButtonBrowse_Set() ) );
}
QDir media(config.MountDir);
if(media.exists()){
QStringList Paths;
Paths=media.entryList("*",QDir::Dirs);
Paths.erase(Paths.begin()); // delete "."
Paths.erase(Paths.begin()); // delete ".."
for(int i=0;i<Paths.count();i++)
Combo_Dirs->addItem(config.MountDir+Paths[i]);
}
Combo_Dirs->setEditText(QString());
if(!config.ShowPasswords)ChangeEchoMode();
}
@ -79,6 +92,7 @@ ButtonBrowse->setEnabled(false);
Label_KeyFile->setEnabled(false);
Label_Password->setEnabled(true);
Edit_Password->setEnabled(true);
Edit_PasswordRep->setEnabled(true);
ButtonChangeEchoMode->setEnabled(true);
KeyType=PASSWORD;
}
@ -90,6 +104,7 @@ ButtonBrowse->setEnabled(true);
Label_KeyFile->setEnabled(true);
Label_Password->setEnabled(false);
Edit_Password->setEnabled(false);
Edit_PasswordRep->setEnabled(false);
ButtonChangeEchoMode->setEnabled(false);
KeyType=KEYFILE;
}
@ -101,6 +116,7 @@ ButtonBrowse->setEnabled(true);
Label_KeyFile->setEnabled(true);
Label_Password->setEnabled(true);
Edit_Password->setEnabled(true);
Edit_PasswordRep->setEnabled(true);
ButtonChangeEchoMode->setEnabled(true);
KeyType=BOTH;
}
@ -192,14 +208,22 @@ if(KeyType==BOTH || KeyType==KEYFILE){
return;}
}
}
if(config.RememberLastKey){
config.LastKeyLocation=keyfile;
config.LastKeyType=KeyType;
}
done(1);
}
void CPasswordDialog::OnOK_Set(){
password=Edit_Password->text();
if(password!=Edit_PasswordRep->text()){
QMessageBox::warning(this,tr("Warning"),tr("Password an password repetition are not equal.\nPlease check your input."),tr("OK"),"","",0,0);
return;}
keyfile=Combo_Dirs->currentText();
if(password=="" && keyfile==""){
QMessageBox::warning(this,tr("Error"),tr("Please enter a Password or select a key file."),tr("OK"),"","",0,0);
QMessageBox::warning(this,tr("Error"),tr("Please enter a password or select a key file."),tr("OK"),"","",0,0);
return;}
QFile file(keyfile);
@ -224,10 +248,15 @@ if(QFileInfo(file).isDir()){
return;}
}
}
if(config.RememberLastKey){
config.LastKeyLocation=keyfile;
config.LastKeyType=KeyType;
}
done(1);
}
void CPasswordDialog::OnPasswordChanged(const QString &txt){
Edit_PasswordRep->setText("");
if(CheckBox_Both->isChecked() || txt==QString())
setStateBoth();
else
@ -263,10 +292,12 @@ if(state==Qt::Unchecked){
}
void CPasswordDialog::ChangeEchoMode(){
if(Edit_Password->echoMode()==QLineEdit::Normal)
if(Edit_Password->echoMode()==QLineEdit::Normal){
Edit_Password->setEchoMode(QLineEdit::Password);
else
Edit_PasswordRep->setEchoMode(QLineEdit::Password);}
else{
Edit_Password->setEchoMode(QLineEdit::Normal);
Edit_PasswordRep->setEchoMode(QLineEdit::Normal);}
}

@ -31,11 +31,12 @@ CSettingsDlg::CSettingsDlg(QWidget* parent, const char* name, bool modal, Qt::WF
: QDialog(parent,name, modal,fl)
{
setupUi(this);
connect( ButtonOK, SIGNAL( clicked() ), this, SLOT( OnOK() ) );
connect( ButtonCancel, SIGNAL( clicked() ), this, SLOT( OnCancel() ) );
connect( ButtonColor1, SIGNAL( clicked() ), this, SLOT( OnColor1() ) );
connect( ButtonColor2, SIGNAL( clicked() ), this, SLOT( OnColor2() ) );
connect( ButtonTextColor, SIGNAL( clicked() ), this, SLOT( OnTextColor() ) );
connect(ButtonOK, SIGNAL( clicked() ), this, SLOT( OnOK() ) );
connect(ButtonCancel, SIGNAL( clicked() ), this, SLOT( OnCancel() ) );
connect(ButtonColor1, SIGNAL( clicked() ), this, SLOT( OnColor1() ) );
connect(ButtonColor2, SIGNAL( clicked() ), this, SLOT( OnColor2() ) );
connect(ButtonTextColor, SIGNAL( clicked() ), this, SLOT( OnTextColor() ) );
connect(CheckBox_OpenLast,SIGNAL(stateChanged(int)),this,SLOT(OnCeckBoxOpenLastChanged(int)));
createBanner(Banner,Icon_Settings32x32,tr("Settings"));
CheckBox_OpenLast->setChecked(config.OpenLast);
SpinBox_ClipboardTime->setValue(config.ClipboardTimeOut);
@ -58,13 +59,12 @@ pixmColor2->setPixmap(*px2);
color1=config.BannerColor1;
color2=config.BannerColor2;
textcolor=config.BannerTextColor;
CheckBox_ShowPasswords->setChecked(config.ShowPasswords);
Edit_BrowserCmd->setText(config.OpenUrlCommand);
CheckBox_ExpandGroupTree->setChecked(config.ExpandGroupTree);
CheckBox_AlternatingRowColors->setChecked(config.AlternatingRowColors);
Edit_MountDir->setText(config.MountDir);
CheckBox_RememberLastKey->setChecked(config.RememberLastKey);
}
CSettingsDlg::~CSettingsDlg()
@ -85,6 +85,7 @@ config.AlternatingRowColors=CheckBox_AlternatingRowColors->isChecked();
config.MountDir=Edit_MountDir->text();
if(config.MountDir!="" && config.MountDir.right(1)!="/")
config.MountDir+="/";
config.RememberLastKey=CheckBox_RememberLastKey->isChecked();
close();
}
@ -132,7 +133,14 @@ createBanner(Banner,Icon_Settings32x32,tr("Settings"),color1,color2,textcolor);
}
}
void CSettingsDlg::OnCeckBoxOpenLastChanged(int state){
if(state==Qt::Checked){
CheckBox_RememberLastKey->setEnabled(true);
}else{
CheckBox_RememberLastKey->setEnabled(false);
CheckBox_RememberLastKey->setChecked(false);
}
}
/*$SPECIALIZATION$*/

@ -20,7 +20,6 @@
#include "main.h"
#ifndef SETTINGSDLG_H
#define SETTINGSDLG_H
#include "ui_SettingsDlg.h"
#include <qcolor.h>
@ -31,24 +30,14 @@ class CSettingsDlg : public QDialog, public Ui_SettingsDialog
public:
CSettingsDlg(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, Qt::WFlags fl = 0 );
~CSettingsDlg();
/*$PUBLIC_FUNCTIONS$*/
public slots:
/*$PUBLIC_SLOTS$*/
protected:
/*$PROTECTED_FUNCTIONS$*/
protected slots:
/*$PROTECTED_SLOTS$*/
public slots:
virtual void OnCancel();
public slots:
virtual void OnOK();
virtual void OnTextColor();
virtual void OnColor2();
virtual void OnColor1();
void OnCeckBoxOpenLastChanged(int state);
private:
QColor color1,color2,textcolor;

@ -0,0 +1,62 @@
/***************************************************************************
* Copyright (C) 2005-2006 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 <QString>
#include <QFile>
#include "main.h"
#include "../lib/SecString.h"
#include "Export_Txt.h"
QString EntryTemplate=QString("\n\
Title: %1\n\
Username: %2\n\
Url: %3\n\
Password: %4\n\
Comment: %5\n\
");
QString GroupTemplate=QString("\n\
*** Group: %1 ***\n\
");
bool Export_Txt::exportFile(const QString& filename,PwDatabase* db,QString& err){
QFile file(filename);
if(!file.open(QIODevice::Truncate | QIODevice::WriteOnly)){
err+=tr("Could not open file (FileError=%1)").arg(file.error());
return false;
}
for(int g=0;g<db->Groups.size();g++){
file.write(GroupTemplate.arg(db->Groups[g].Name).utf8());
for(int e=0;e<db->Entries.size();e++){
if(db->Groups[g].ID==db->Entries[e].GroupID){
db->Entries[e].Password.unlock();
file.write(EntryTemplate.arg(db->Entries[e].Title)
.arg(db->Entries[e].UserName)
.arg(db->Entries[e].URL)
.arg(db->Entries[e].Password.string())
.arg(db->Entries[e].Additional)
.utf8());
db->Entries[e].Password.lock();
}
}
}
file.close();
}

@ -0,0 +1,31 @@
/***************************************************************************
* Copyright (C) 2005-2006 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_TXT_H_
#define _EXPORT_TXT_H_
#include <QObject>
#include "PwManager.h"
class Export_Txt:public QObject{
public:
bool exportFile(const QString& filename,PwDatabase* db,QString& err);
};
#endif

@ -79,6 +79,9 @@
<property name="rootIsDecorated" >
<bool>false</bool>
</property>
<property name="sortingEnabled" >
<bool>true</bool>
</property>
</widget>
</widget>
</item>
@ -509,16 +512,16 @@
<pixmapfunction></pixmapfunction>
<customwidgets>
<customwidget>
<class>KeepassGroupView</class>
<class>KeepassEntryView</class>
<extends>QTreeWidget</extends>
<header>../../src/lib/GroupView.h</header>
<header>../../src/lib/EntryView.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>KeepassEntryView</class>
<class>KeepassGroupView</class>
<extends>QTreeWidget</extends>
<header>../../src/lib/EntryView.h</header>
<header>../../src/lib/GroupView.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>

@ -137,7 +137,7 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<widget class="QWidget" name="" >
<widget class="QWidget" name="layoutWidget" >
<property name="geometry" >
<rect>
<x>10</x>
@ -164,7 +164,7 @@
<item row="1" column="0" >
<widget class="QLabel" name="Label_PasswordRep" >
<property name="text" >
<string>TextLabel</string>
<string>Password Repet.:</string>
</property>
</widget>
</item>

@ -509,7 +509,7 @@
<string>Alt+Ö</string>
</property>
</widget>
<widget class="QCheckBox" name="CheckBox_RememberKey" >
<widget class="QCheckBox" name="CheckBox_RememberLastKey" >
<property name="geometry" >
<rect>
<x>30</x>

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2005-2006 by Tarek Saidi *
* Copyright (C) 2005-2006 by Tarek Saidi *
* tarek.saidi@arcor.de *
* *
* This program is free software; you can redistribute it and/or modify *
@ -37,6 +37,7 @@
KeepassEntryView::KeepassEntryView(QWidget* parent):QTreeWidget(parent){
AutoResizeColumns=true;
IsSearchGroup=false;
int sum=0;
for(int i=0;i<NUM_COLUMNS;i++)
sum+=config.ColumnSizes[i];
@ -97,6 +98,7 @@ updateItems(CurrentGroup);
void KeepassEntryView::updateItems(unsigned int GroupID){
IsSearchGroup=false;
clear();
Items.clear();
if(!db)return;
@ -109,6 +111,7 @@ for(int i=0;i<db->Entries.size();i++){
}
void KeepassEntryView::showSearchResults(QList<Q_UINT32>& results){
IsSearchGroup=true;
clear();
Items.clear();
for(int j=0; j<results.size(); j++){
@ -301,6 +304,8 @@ QTreeWidget::mousePressEvent(event);
}
void KeepassEntryView::mouseMoveEvent(QMouseEvent *event){
if(IsSearchGroup)
return;
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - DragStartPos).manhattanLength() < QApplication::startDragDistance())

@ -53,6 +53,7 @@ private:
QPoint DragStartPos;
QList<QTreeWidgetItem*> DragItems;
QPixmap DragPixmap;
bool IsSearchGroup;
protected:
virtual void contextMenuEvent(QContextMenuEvent *event);
virtual void paintEvent(QPaintEvent* event);

@ -42,6 +42,7 @@
#include "lib/IniReader.h"
#include "import/Import_PwManager.h"
#include "import/Import_KWalletXml.h"
#include "export/Export_Txt.h"
#include "dialogs/AboutDlg.h"
#include "dialogs/EditGroupDlg.h"
@ -97,6 +98,7 @@ void KeepassMainWindow::setupConnections(){
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(EditNewGroupAction, SIGNAL(triggered()), this, SLOT(OnEditNewGroup()));
connect(EditEditGroupAction, SIGNAL(triggered()), this, SLOT(OnEditEditGroup()));
@ -587,6 +589,15 @@ void KeepassMainWindow::OnFileExit(){
close();
}
void KeepassMainWindow::OnExportToTxt(){
QString filename=QFileDialog::getSaveFileName(this,tr("Export To..."),QDir::homePath(),"*.txt");
if(filename==QString())return;
Export_Txt exp;
QString err;
exp.exportFile(filename,db,err);
}
void KeepassMainWindow::OnImportFromPwm(){
if(FileOpen)
if(!closeDatabase())return;
@ -669,9 +680,24 @@ if(cur){
}
void KeepassMainWindow::OnEntryItemDoubleClicked(QTreeWidgetItem* item,int column){
if(column) return;
if(!config.Columns[0]) return;
editEntry(static_cast<EntryViewItem*>(item)->pEntry);
int i=0;
int c=-1;
for(i;i<NUM_COLUMNS;i++){
if(config.Columns[i])c++;
if(c==column)break;
}
if(c==-1)return;
CEntry* entry=static_cast<EntryViewItem*>(item)->pEntry;
switch(i){
case 0: editEntry(entry);
break;
case 1: OnEditUsernameToClipboard();
break;
case 2: OnEditOpenUrl();
break;
case 3: OnEditPasswordToClipboard();
break;
}
}
void KeepassMainWindow::OnEntrySelectionChanged(){

@ -63,6 +63,7 @@ private slots:
void OnFileExit();
void OnImportFromPwm();
void OnImportFromKWalletXml();
void OnExportToTxt();
void OnEditNewGroup();
void OnEditEditGroup();
void OnEditDeleteGroup();

@ -35,6 +35,7 @@ HEADERS += lib/IniReader.h \
crypto/twoclass.h \
crypto/twofish.h \
import/Import_PwManager.h \
export/Export_Txt.h \
crypto/blowfish.h \
crypto/sha1.h \
import/Import_KWalletXml.h \
@ -68,6 +69,7 @@ SOURCES += lib/IniReader.cpp \
crypto/twoclass.cpp \
crypto/twofish.cpp \
import/Import_PwManager.cpp \
export/Export_Txt.cpp \
crypto/blowfish.cpp \
crypto/sha1.cpp \
import/Import_KWalletXml.cpp \