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
This commit is contained in:
parent
70bf7f5b5d
commit
c182df6c31
|
@ -406,7 +406,8 @@ bool Kdb3Database::createGroupTree(QList<quint32>& 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--){
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -493,6 +493,7 @@ void KeepassEntryView::OnColumnMoved(int LogIndex,int OldVisIndex,int NewVisInde
|
|||
for(int i=0;i<header()->count();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; i<visibleCols; i++){
|
||||
SortCol = treeWidget()->header()->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;
|
||||
|
|
|
@ -64,11 +64,11 @@ class KeepassEntryView:public QTreeWidget{
|
|||
QList<int> 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;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue