From c182df6c31a7c6bc9bda0655ad0b5a86ec0003ce Mon Sep 17 00:00:00 2001 From: sniperbeamer Date: Thu, 25 Sep 2008 14:29:36 +0000 Subject: [PATCH] Fixed: Predefined expire times don't work (closes #2109987) Fixed: Sorting isn't consistent (closes #2108655) git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@221 b624d157-de02-0410-bad0-e51aec6abb33 --- src/Kdb3Database.cpp | 3 +- src/dialogs/EditEntryDlg.cpp | 25 ++++++++++-- src/dialogs/EditEntryDlg.h | 6 +-- src/lib/EntryView.cpp | 76 ++++++++++++++++++++++++++---------- src/lib/EntryView.h | 14 ++++--- 5 files changed, 89 insertions(+), 35 deletions(-) diff --git a/src/Kdb3Database.cpp b/src/Kdb3Database.cpp index c2875c5..beae7bc 100644 --- a/src/Kdb3Database.cpp +++ b/src/Kdb3Database.cpp @@ -406,7 +406,8 @@ bool Kdb3Database::createGroupTree(QList& Levels){ Groups[i].Parent=&RootGroup; Groups[i].Index=RootGroup.Childs.size(); RootGroup.Childs.append(&Groups[i]); - continue;} + continue; + } int j; //the first item with a lower level is the parent for(j=i-1;j>=0;j--){ diff --git a/src/dialogs/EditEntryDlg.cpp b/src/dialogs/EditEntryDlg.cpp index 5c519c4..3da7204 100644 --- a/src/dialogs/EditEntryDlg.cpp +++ b/src/dialogs/EditEntryDlg.cpp @@ -53,7 +53,7 @@ CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* paren connect(CheckBox_ExpiresNever,SIGNAL(stateChanged(int)),this,SLOT(OnCheckBoxExpiresNeverChanged(int))); connect(Button_Icons,SIGNAL(clicked()),this,SLOT(OnButtonIcons())); connect(ExpirePresetsMenu,SIGNAL(triggered(QAction*)),this,SLOT(OnExpirePreset(QAction*))); - connect(ButtonExpirePresets,SIGNAL(triggered(QAction*)),this,SLOT(OnCalendar())); + connect(ButtonExpirePresets,SIGNAL(triggered(QAction*)),this,SLOT(OnCalendar(QAction*))); connect(this, SIGNAL(finished(int)), this, SLOT(OnClose())); // QAction::data() contains the time until expiration in days. @@ -69,7 +69,9 @@ CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* paren ExpirePresetsMenu->addSeparator(); ExpirePresetsMenu->addAction(tr("1 Year"))->setData(365); ButtonExpirePresets->setMenu(ExpirePresetsMenu); - ButtonExpirePresets->setDefaultAction(new QAction(tr("Calendar..."),ButtonExpirePresets)); + QAction* actionCalendar = new QAction(tr("Calendar..."),ButtonExpirePresets); + actionCalendar->setData(-1); + ButtonExpirePresets->setDefaultAction(actionCalendar); IconIndex = entry->image(); Button_Icons->setIcon(db->icon(IconIndex)); @@ -400,11 +402,26 @@ void CEditEntryDlg::OnButtonIcons(){ void CEditEntryDlg::OnExpirePreset(QAction* action){ CheckBox_ExpiresNever->setChecked(false); - DateTime_Expire->setDate(QDate::fromJulianDay(QDate::currentDate().toJulianDay()+action->data().toInt())); + int days = action->data().toInt(); + switch (days){ + case 30: + case 90: + case 180: + DateTime_Expire->setDate(QDate::currentDate().addMonths(days/30)); + break; + case 365: + DateTime_Expire->setDate(QDate::currentDate().addYears(1)); + break; + default: + DateTime_Expire->setDate(QDate::currentDate().addDays(days)); + } DateTime_Expire->setTime(QTime(0,0,0)); } -void CEditEntryDlg::OnCalendar(){ +void CEditEntryDlg::OnCalendar(QAction* action){ + if (action->data().toInt()!=-1) + return; + CalendarDialog dlg(this); if(dlg.exec()==QDialog::Accepted){ CheckBox_ExpiresNever->setChecked(false); diff --git a/src/dialogs/EditEntryDlg.h b/src/dialogs/EditEntryDlg.h index dc83b7c..26ae5a2 100644 --- a/src/dialogs/EditEntryDlg.h +++ b/src/dialogs/EditEntryDlg.h @@ -57,13 +57,13 @@ class CEditEntryDlg : public QDialog, private Ui_EditEntryDialog void OnCheckBoxExpiresNeverChanged(int state); void OnButtonIcons(); void OnButtonOK(); - void OnExpirePreset(QAction*); - void OnCalendar(); + void OnExpirePreset(QAction* action); + void OnCalendar(QAction* action); void OnClose(); private: virtual void paintEvent(QPaintEvent*); - virtual void resizeEvent(QResizeEvent *); + virtual void resizeEvent(QResizeEvent *); int IconIndex; bool pNewEntry; diff --git a/src/lib/EntryView.cpp b/src/lib/EntryView.cpp index 116f3b7..fb1b394 100644 --- a/src/lib/EntryView.cpp +++ b/src/lib/EntryView.cpp @@ -493,6 +493,7 @@ void KeepassEntryView::OnColumnMoved(int LogIndex,int OldVisIndex,int NewVisInde for(int i=0;icount();i++){ ColumnOrder[columnListIndex(header()->logicalIndex(i))]=i; } + sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder()); } int KeepassEntryView::logicalColIndex(int LstIndex){ @@ -645,34 +646,67 @@ EntryViewItem::EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding } -bool EntryViewItem::operator<(const QTreeWidgetItem& other)const{ - int SortCol=treeWidget()->header()->sortIndicatorSection(); - int ListIndex=((KeepassEntryView*)treeWidget())->columnListIndex(SortCol); - if(ListIndex < 5 || ListIndex > 8){ //columns with string values (Title, Username, Password, URL, Comment, Group) - return (QString::localeAwareCompare(text(SortCol),other.text(SortCol)) < 0); +bool EntryViewItem::operator<(const QTreeWidgetItem& other) const{ + int SortCol = treeWidget()->header()->sortIndicatorSection(); + int ListIndex = ((KeepassEntryView*)treeWidget())->columnListIndex(SortCol); + + int comp = compare(other, SortCol, ListIndex); + if (comp!=0) + return (comp<0); + else { + int visibleCols = treeWidget()->header()->count() - treeWidget()->header()->hiddenSectionCount(); + int ListIndexOrg = ListIndex; + for (int i=0; iheader()->logicalIndex(i); + ListIndex = ((KeepassEntryView*)treeWidget())->columnListIndex(SortCol); + if (ListIndex==ListIndexOrg || ListIndex==3) // sort or password column + continue; + + comp = compare(other, SortCol, ListIndex); + if (comp!=0) + return (comp<0); + } + return true; // entries are equal + } +} + +int EntryViewItem::compare(const QTreeWidgetItem& other, int col, int index) const{ + if (index < 5 || index > 8){ //columns with string values (Title, Username, Password, URL, Comment, Group) + return QString::localeAwareCompare(text(col),other.text(col)); } + KpxDateTime DateThis; KpxDateTime DateOther; - switch (ListIndex){ - case 5: DateThis=EntryHandle->expire(); - DateOther=((EntryViewItem&)other).EntryHandle->expire(); - break; - case 6: DateThis=EntryHandle->creation(); - DateOther=((EntryViewItem&)other).EntryHandle->creation(); - break; - case 7: DateThis=EntryHandle->lastMod(); - DateOther=((EntryViewItem&)other).EntryHandle->lastMod(); - break; - case 8: DateThis=EntryHandle->lastAccess(); - DateOther=((EntryViewItem&)other).EntryHandle->lastAccess(); - break; - default:Q_ASSERT(false); + switch (index){ + case 5: + DateThis=EntryHandle->expire(); + DateOther=((EntryViewItem&)other).EntryHandle->expire(); + break; + case 6: + DateThis=EntryHandle->creation(); + DateOther=((EntryViewItem&)other).EntryHandle->creation(); + break; + case 7: + DateThis=EntryHandle->lastMod(); + DateOther=((EntryViewItem&)other).EntryHandle->lastMod(); + break; + case 8: + DateThis=EntryHandle->lastAccess(); + DateOther=((EntryViewItem&)other).EntryHandle->lastAccess(); + break; + default: + Q_ASSERT(false); } - return DateThis < DateOther; + + if (DateThis==DateOther) + return 0; + else if (DateThis < DateOther) + return -1; + else + return 1; } - void KeepassEntryView::setCurrentEntry(IEntryHandle* entry){ bool found=false; int i; diff --git a/src/lib/EntryView.h b/src/lib/EntryView.h index f538569..6e97348 100644 --- a/src/lib/EntryView.h +++ b/src/lib/EntryView.h @@ -64,11 +64,11 @@ class KeepassEntryView:public QTreeWidget{ QList ColumnOrder; float GroupColumnSize; - virtual void contextMenuEvent(QContextMenuEvent *event); - virtual void paintEvent(QPaintEvent* event); - virtual void resizeEvent(QResizeEvent* event); - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); + void contextMenuEvent(QContextMenuEvent *event); + void paintEvent(QPaintEvent* event); + void resizeEvent(QResizeEvent* event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); private slots: void OnColumnResized(int index,int OldSize, int NewSize); @@ -107,7 +107,9 @@ class EntryViewItem:public QTreeWidgetItem{ EntryViewItem(QTreeWidgetItem *parent); EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding); IEntryHandle* EntryHandle; - virtual bool operator<(const QTreeWidgetItem& other)const; + bool operator<(const QTreeWidgetItem& other) const; + private: + int compare(const QTreeWidgetItem& other, int col, int index) const; };