From 74c7b86a89b307f9320721190ff86e056df5fe48 Mon Sep 17 00:00:00 2001 From: tariq Date: Thu, 27 Apr 2006 20:00:16 +0000 Subject: [PATCH] EntryView and DetailView now also show "never" for entries which don't expire, EntryView now calls updateItems() when column config is changed, Added {TAB} template for Auto-Type, "Custom Icon" feature is not longer touching the ImageID value within the database, Fixed SegFault when enabling a new column (not in 0.2.0, only svn) git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@79 b624d157-de02-0410-bad0-e51aec6abb33 --- src/Database.cpp | 12 +++ src/Database.h | 22 ++++-- src/PwManager.cpp | 10 +-- src/PwManager.h | 2 +- src/dialogs/EditEntryDlg.cpp | 20 ++++- src/dialogs/EditEntryDlg.h | 1 + src/dialogs/EditGroupDlg.cpp | 2 + src/dialogs/EditGroupDlg.h | 1 + src/dialogs/SelectIconDlg.cpp | 6 +- src/dialogs/SelectIconDlg.h | 2 +- src/forms/EditEntryDlg.ui | 2 +- src/lib/AutoType.cpp | 133 +++++++++++++++++++++++++++++++++- src/lib/EntryView.cpp | 27 ++++--- src/mainwindow.cpp | 6 +- 14 files changed, 214 insertions(+), 32 deletions(-) diff --git a/src/Database.cpp b/src/Database.cpp index 2e43435..2ffcd6c 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -20,9 +20,20 @@ #include "Database.h" +QString KpxDateTime::toString(Qt::DateFormat format) const{ +if(*this==Date_Never)return QObject::tr("Never"); +else return QDateTime::toString(format); +} + +QString KpxDateTime::dateToString(Qt::DateFormat format) const{ +if(*this==Date_Never)return QObject::tr("Never"); +else return date().toString(format); +} + CEntry::CEntry(){ ImageID=0; +OldImgID=0; GroupID=0; Creation=QDateTime::currentDateTime(); LastMod=QDateTime::currentDateTime(); @@ -50,6 +61,7 @@ LastMod=QDateTime::currentDateTime(); Expire=QDateTime(QDate(2999,12,28),QTime(23,59,59)); Level=0; ImageID=0; +OldImgID=0; Name=""; UI_ItemIsExpanded=UI_ExpandByDefault; } diff --git a/src/Database.h b/src/Database.h index 08ca952..e0b0559 100644 --- a/src/Database.h +++ b/src/Database.h @@ -27,6 +27,17 @@ #include "lib/SecString.h" using namespace std; +extern const QDateTime Date_Never; +class KpxDateTime:public QDateTime{ +public: +KpxDateTime(){}; +KpxDateTime ( const QDate & date ):QDateTime(date){}; +KpxDateTime ( const QDate & date, const QTime & time, Qt::TimeSpec spec = Qt::LocalTime):QDateTime(date,time,spec){}; +KpxDateTime ( const QDateTime & other ):QDateTime(other){}; +virtual QString toString(Qt::DateFormat format = Qt::TextDate ) const; +QString dateToString(Qt::DateFormat format = Qt::TextDate)const; +}; + class CEntry{ public: CEntry(); @@ -35,16 +46,17 @@ Q_UINT8 ID[16]; Q_UINT32 sID; Q_UINT32 GroupID; Q_UINT32 ImageID; +quint32 OldImgID; QString Title; QString URL; QString UserName; SecString Password; QString Additional; QString BinaryDesc; -QDateTime Creation; -QDateTime LastMod; -QDateTime LastAccess; -QDateTime Expire; +KpxDateTime Creation; +KpxDateTime LastMod; +KpxDateTime LastAccess; +KpxDateTime Expire; QByteArray BinaryData; /*Q_UINT32 PasswordLength;*/ bool ReadEntryField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData); @@ -58,7 +70,7 @@ CGroup(); ~CGroup(); Q_UINT32 ID; Q_UINT32 ImageID; -/*Q_UINT32 NumEntries;*/ +quint32 OldImgID; QString Name; QDateTime Creation; QDateTime LastMod; diff --git a/src/PwManager.cpp b/src/PwManager.cpp index d774bcc..01093cb 100755 --- a/src/PwManager.cpp +++ b/src/PwManager.cpp @@ -280,6 +280,7 @@ for(int i=0;i=BUILTIN_ICONS)ImgID=0; - memcpyToLEnd32(buffer+pos, &ImgID); pos += 4; + memcpyToLEnd32(buffer+pos, &Groups[i].OldImgID); pos += 4; FieldType = 0x0008; FieldSize = 2; memcpyToLEnd16(buffer+pos, &FieldType); pos += 2; @@ -881,9 +881,7 @@ for(int i = 0; i < Entries.size(); i++){ FieldType = 0x0003; FieldSize = 4; memcpyToLEnd16(buffer+pos, &FieldType); pos += 2; memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4; - Q_UINT32 ImgID=Entries[i].ImageID; - if(ImgID>=BUILTIN_ICONS)ImgID=0; - memcpyToLEnd32(buffer+pos,&ImgID); pos += 4; + memcpyToLEnd32(buffer+pos,&Entries[i].OldImgID); pos += 4; FieldType = 0x0004; diff --git a/src/PwManager.h b/src/PwManager.h index a8ee4d7..247b792 100755 --- a/src/PwManager.h +++ b/src/PwManager.h @@ -109,7 +109,7 @@ void modified(); }; - extern const QDateTime Date_Never; + void memcpyFromLEnd32(Q_UINT32* dst,const char* src); void memcpyFromLEnd16(Q_UINT16* dst,const char* src); void memcpyToLEnd32(char* src,const Q_UINT32* dst); diff --git a/src/dialogs/EditEntryDlg.cpp b/src/dialogs/EditEntryDlg.cpp index 6ba1ef6..fd1e2ac 100755 --- a/src/dialogs/EditEntryDlg.cpp +++ b/src/dialogs/EditEntryDlg.cpp @@ -38,7 +38,7 @@ //Added by qt3to4: #include - +#include "SelectIconDlg.h" #include "PasswordGenDlg.h" #include "EditEntryDlg.h" @@ -65,6 +65,7 @@ connect(ButtonSaveAttachment, SIGNAL(clicked()), this, SLOT( OnSaveAttachment()) connect(ButtonGenPw, SIGNAL(clicked()), this, SLOT( OnButtonGenPw())); connect(ButtonOK, SIGNAL(clicked()),this,SLOT(OnButtonOK())); connect(CheckBox_ExpiresNever,SIGNAL(stateChanged(int)),this,SLOT(OnCheckBoxExpiresNeverChanged(int))); +connect(Button_CustomIcons,SIGNAL(clicked()),this,SLOT(OnCustomIcons())); ButtonOpenAttachment->setIcon(*Icon_FileOpen); ButtonDeleteAttachment->setIcon(*Icon_EditDelete); @@ -74,7 +75,7 @@ if(entry->BinaryData.isNull()){ ButtonSaveAttachment->setDisabled(true); ButtonDeleteAttachment->setDisabled(true);} setCaption(entry->Title); -setIcon(EntryIcons[entry->ImageID]); +setIcon(db->icon(entry->ImageID)); Edit_Title->setText(entry->Title); Edit_UserName->setText(entry->UserName); Edit_URL->setText(entry->URL); @@ -194,6 +195,8 @@ if(Combo_Group->currentItem()!=db->getGroupIndex(entry->GroupID)){ db->moveEntry(entry,&db->group(Combo_Group->currentItem())); EntryMoved=true; ModFlag=true; } +if(entry->ImageIDcurrentItem()>=BUILTIN_ICONS) + entry->OldImgID=entry->ImageID; entry->ImageID=Combo_IconPicker->currentItem(); if(ModFlag&&EntryMoved)done(2); @@ -359,8 +362,17 @@ else } } - - +void CEditEntryDlg::OnCustomIcons(){ +CSelectIconDlg dlg(db,Combo_IconPicker->currentItem(),this); +int r=dlg.exec(); +if(dlg.ModFlag)ModFlag=true; +if(r!=-1){ + Combo_IconPicker->clear(); + for(int i=0;inumIcons();i++) + Combo_IconPicker->insertItem(db->icon(i),"",i); + Combo_IconPicker->setCurrentItem(r); +} +} diff --git a/src/dialogs/EditEntryDlg.h b/src/dialogs/EditEntryDlg.h index bb51888..cf984c5 100755 --- a/src/dialogs/EditEntryDlg.h +++ b/src/dialogs/EditEntryDlg.h @@ -70,6 +70,7 @@ public slots: void OnSaveAttachment(); void OnButtonGenPw(); void OnCheckBoxExpiresNeverChanged(int state); + void OnCustomIcons(); }; diff --git a/src/dialogs/EditGroupDlg.cpp b/src/dialogs/EditGroupDlg.cpp index 58effb8..bd9e04f 100755 --- a/src/dialogs/EditGroupDlg.cpp +++ b/src/dialogs/EditGroupDlg.cpp @@ -36,6 +36,7 @@ IconID=0; connect( ButtonOK, SIGNAL( clicked() ), this, SLOT( OnOK() ) ); connect( ButtonCancel, SIGNAL( clicked() ), this, SLOT( OnCancel() ) ); connect( Button_Icon, SIGNAL( clicked() ), this, SLOT( OnIconDlg() )); +ModFlag=false; } CEditGroupDialog::~CEditGroupDialog() @@ -68,6 +69,7 @@ done(0); void CEditGroupDialog::OnIconDlg(){ CSelectIconDlg dlg(db,IconID,this); int r=dlg.exec(); +if(dlg.ModFlag)ModFlag=true; if(r!=-1){ ComboIconPicker->clear(); for(int i=0;inumIcons();i++) diff --git a/src/dialogs/EditGroupDlg.h b/src/dialogs/EditGroupDlg.h index 25490e2..c2679e6 100755 --- a/src/dialogs/EditGroupDlg.h +++ b/src/dialogs/EditGroupDlg.h @@ -33,6 +33,7 @@ class CEditGroupDialog : public QDialog, public Ui_EditGroupDialog public: CEditGroupDialog(Database*,QWidget* parent = 0, const char* name = 0, bool modal = FALSE, Qt::WFlags fl = 0 ); ~CEditGroupDialog(); + bool ModFlag; virtual void showEvent(QShowEvent *event); int IconID; QString GroupName; diff --git a/src/dialogs/SelectIconDlg.cpp b/src/dialogs/SelectIconDlg.cpp index f189250..ea5be8e 100644 --- a/src/dialogs/SelectIconDlg.cpp +++ b/src/dialogs/SelectIconDlg.cpp @@ -33,7 +33,6 @@ setupUi(this); db=database; CtxMenu=new QMenu(this); DeleteAction=CtxMenu->addAction(*Icon_EditDelete,tr("Delete")); -CustomIconsModified=false; connect(Button_AddIcon, SIGNAL(clicked()), this, SLOT(OnAddIcon())); connect(Button_PickIcon, SIGNAL(clicked()), this, SLOT(OnPickIcon())); connect(Button_Cancel, SIGNAL(clicked()), this, SLOT(OnCancel())); @@ -41,6 +40,7 @@ connect(DeleteAction,SIGNAL(triggered()),this,SLOT(OnDelete())); connect(List,SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this,SLOT(OnSelectionChanged(QListWidgetItem*,QListWidgetItem*))); updateView(); List->setCurrentItem(List->item(CurrentID)); +ModFlag=false; } void CSelectIconDlg::updateView(){ @@ -70,7 +70,7 @@ for(int i=0;isetCurrentItem(List->item(List->count()-1)); } @@ -89,8 +89,10 @@ CtxMenu->popup(event->globalPos()); } void CSelectIconDlg::OnDelete(){ +ModFlag=true; db->removeIcon(List->currentItem()->data(32).toInt()); updateView(); +List->setCurrentItem(List->item(0)); } void CSelectIconDlg::OnPickIcon(){ diff --git a/src/dialogs/SelectIconDlg.h b/src/dialogs/SelectIconDlg.h index e1c0914..5e6cd3a 100644 --- a/src/dialogs/SelectIconDlg.h +++ b/src/dialogs/SelectIconDlg.h @@ -32,7 +32,7 @@ class CSelectIconDlg:public QDialog, public Ui_SelectIconDlg{ Q_OBJECT public: CSelectIconDlg(Database* db,int,QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WFlags fl = 0); - bool CustomIconsModified; + bool ModFlag; public slots: void OnAddIcon(); diff --git a/src/forms/EditEntryDlg.ui b/src/forms/EditEntryDlg.ui index 6c68b40..26bce2f 100644 --- a/src/forms/EditEntryDlg.ui +++ b/src/forms/EditEntryDlg.ui @@ -383,7 +383,7 @@ - + > diff --git a/src/lib/AutoType.cpp b/src/lib/AutoType.cpp index 2d2e6b2..05e97c7 100644 --- a/src/lib/AutoType.cpp +++ b/src/lib/AutoType.cpp @@ -101,7 +101,6 @@ for(int i=0;ihide(); Display* pDisplay = XOpenDisplay( NULL ); for(int i=0;i& KeySymList){ for(int i=0; i ItemSelec=selectedItems(); +QList SelectionIDs; +for(int i=0; ipEntry->sID; IsSearchGroup=false; clear(); Items.clear(); @@ -111,6 +115,11 @@ for(int i=0;inumEntries();i++){ if(db->entry(i).GroupID==GroupID) setEntry(&db->entry(i)); } +if(SelectionIDs.size()) + for(int i=0;ipEntry->sID==SelectionIDs[j]) setItemSelected(Items[i],true);} + } } void KeepassEntryView::showSearchResults(QList& results){ @@ -149,13 +158,13 @@ void KeepassEntryView::setEntry(CEntry* entry){ if(config.Columns[4]){ tmp->setText(j++,entry->Additional.section('\n',0,0));} if(config.Columns[5]){ - tmp->setText(j++,entry->Expire.date().toString(Qt::LocalDate));} + tmp->setText(j++,entry->Expire.dateToString(Qt::LocalDate));} if(config.Columns[6]){ - tmp->setText(j++,entry->Creation.date().toString(Qt::LocalDate));} + tmp->setText(j++,entry->Creation.dateToString(Qt::LocalDate));} if(config.Columns[7]){ - tmp->setText(j++,entry->LastMod.date().toString(Qt::LocalDate));} + tmp->setText(j++,entry->LastMod.dateToString(Qt::LocalDate));} if(config.Columns[8]){ - tmp->setText(j++,entry->LastAccess.date().toString(Qt::LocalDate));} + tmp->setText(j++,entry->LastAccess.dateToString(Qt::LocalDate));} if(config.Columns[9]){ tmp->setText(j++,entry->BinaryDesc);} Items.back()->setIcon(0,db->icon(entry->ImageID)); @@ -187,13 +196,13 @@ for(int i=0;isetText(j++,entry->Additional.section('\n',0,0));} if(config.Columns[5]){ - tmp->setText(j++,entry->Expire.date().toString(Qt::LocalDate));} + tmp->setText(j++,entry->Expire.dateToString(Qt::LocalDate));} if(config.Columns[6]){ - tmp->setText(j++,entry->Creation.date().toString(Qt::LocalDate));} + tmp->setText(j++,entry->Creation.dateToString(Qt::LocalDate));} if(config.Columns[7]){ - tmp->setText(j++,entry->LastMod.date().toString(Qt::LocalDate));} + tmp->setText(j++,entry->LastMod.dateToString(Qt::LocalDate));} if(config.Columns[8]){ - tmp->setText(j++,entry->LastAccess.date().toString(Qt::LocalDate));} + tmp->setText(j++,entry->LastAccess.dateToString(Qt::LocalDate));} if(config.Columns[9]){ tmp->setText(j++,entry->BinaryDesc);} tmp->setIcon(0,db->icon(entry->ImageID)); @@ -229,8 +238,8 @@ resizeColumns(); } void KeepassEntryView::resizeColumns(){ - AutoResizeColumns=false; +if(!header()->count())return; for(int i=0;iName; dlg.IconID=pGroup->ImageID; if(!dlg.exec())return; -if((pGroup->Name != dlg.GroupName) || (pGroup->ImageID != dlg.IconID)){ +if((pGroup->Name != dlg.GroupName) || (pGroup->ImageID != dlg.IconID) || dlg.ModFlag){ setStateFileModified(true); pGroup->Name = dlg.GroupName; + if(pGroup->ImageID=BUILTIN_ICONS) + pGroup->OldImgID=pGroup->ImageID; pGroup->ImageID = dlg.IconID; GroupView->updateItems(); } @@ -942,7 +944,7 @@ config.Columns[7]=ViewColumnsLastChangeAction->isChecked(); config.Columns[8]=ViewColumnsLastAccessAction->isChecked(); config.Columns[9]=ViewColumnsAttachmentAction->isChecked(); EntryView->updateColumns(); -if(FileOpen) EntryView->refreshItems(); +if(FileOpen) EntryView->updateItems(); } void KeepassMainWindow::OnUsernPasswVisibilityChanged(bool value){