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].Parent=&RootGroup;
|
||||||
Groups[i].Index=RootGroup.Childs.size();
|
Groups[i].Index=RootGroup.Childs.size();
|
||||||
RootGroup.Childs.append(&Groups[i]);
|
RootGroup.Childs.append(&Groups[i]);
|
||||||
continue;}
|
continue;
|
||||||
|
}
|
||||||
int j;
|
int j;
|
||||||
//the first item with a lower level is the parent
|
//the first item with a lower level is the parent
|
||||||
for(j=i-1;j>=0;j--){
|
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(CheckBox_ExpiresNever,SIGNAL(stateChanged(int)),this,SLOT(OnCheckBoxExpiresNeverChanged(int)));
|
||||||
connect(Button_Icons,SIGNAL(clicked()),this,SLOT(OnButtonIcons()));
|
connect(Button_Icons,SIGNAL(clicked()),this,SLOT(OnButtonIcons()));
|
||||||
connect(ExpirePresetsMenu,SIGNAL(triggered(QAction*)),this,SLOT(OnExpirePreset(QAction*)));
|
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()));
|
connect(this, SIGNAL(finished(int)), this, SLOT(OnClose()));
|
||||||
|
|
||||||
// QAction::data() contains the time until expiration in days.
|
// QAction::data() contains the time until expiration in days.
|
||||||
|
@ -69,7 +69,9 @@ CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* paren
|
||||||
ExpirePresetsMenu->addSeparator();
|
ExpirePresetsMenu->addSeparator();
|
||||||
ExpirePresetsMenu->addAction(tr("1 Year"))->setData(365);
|
ExpirePresetsMenu->addAction(tr("1 Year"))->setData(365);
|
||||||
ButtonExpirePresets->setMenu(ExpirePresetsMenu);
|
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();
|
IconIndex = entry->image();
|
||||||
Button_Icons->setIcon(db->icon(IconIndex));
|
Button_Icons->setIcon(db->icon(IconIndex));
|
||||||
|
@ -400,11 +402,26 @@ void CEditEntryDlg::OnButtonIcons(){
|
||||||
|
|
||||||
void CEditEntryDlg::OnExpirePreset(QAction* action){
|
void CEditEntryDlg::OnExpirePreset(QAction* action){
|
||||||
CheckBox_ExpiresNever->setChecked(false);
|
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));
|
DateTime_Expire->setTime(QTime(0,0,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEditEntryDlg::OnCalendar(){
|
void CEditEntryDlg::OnCalendar(QAction* action){
|
||||||
|
if (action->data().toInt()!=-1)
|
||||||
|
return;
|
||||||
|
|
||||||
CalendarDialog dlg(this);
|
CalendarDialog dlg(this);
|
||||||
if(dlg.exec()==QDialog::Accepted){
|
if(dlg.exec()==QDialog::Accepted){
|
||||||
CheckBox_ExpiresNever->setChecked(false);
|
CheckBox_ExpiresNever->setChecked(false);
|
||||||
|
|
|
@ -57,13 +57,13 @@ class CEditEntryDlg : public QDialog, private Ui_EditEntryDialog
|
||||||
void OnCheckBoxExpiresNeverChanged(int state);
|
void OnCheckBoxExpiresNeverChanged(int state);
|
||||||
void OnButtonIcons();
|
void OnButtonIcons();
|
||||||
void OnButtonOK();
|
void OnButtonOK();
|
||||||
void OnExpirePreset(QAction*);
|
void OnExpirePreset(QAction* action);
|
||||||
void OnCalendar();
|
void OnCalendar(QAction* action);
|
||||||
void OnClose();
|
void OnClose();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void paintEvent(QPaintEvent*);
|
virtual void paintEvent(QPaintEvent*);
|
||||||
virtual void resizeEvent(QResizeEvent *);
|
virtual void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
int IconIndex;
|
int IconIndex;
|
||||||
bool pNewEntry;
|
bool pNewEntry;
|
||||||
|
|
|
@ -493,6 +493,7 @@ void KeepassEntryView::OnColumnMoved(int LogIndex,int OldVisIndex,int NewVisInde
|
||||||
for(int i=0;i<header()->count();i++){
|
for(int i=0;i<header()->count();i++){
|
||||||
ColumnOrder[columnListIndex(header()->logicalIndex(i))]=i;
|
ColumnOrder[columnListIndex(header()->logicalIndex(i))]=i;
|
||||||
}
|
}
|
||||||
|
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
|
||||||
}
|
}
|
||||||
|
|
||||||
int KeepassEntryView::logicalColIndex(int LstIndex){
|
int KeepassEntryView::logicalColIndex(int LstIndex){
|
||||||
|
@ -645,34 +646,67 @@ EntryViewItem::EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EntryViewItem::operator<(const QTreeWidgetItem& other)const{
|
bool EntryViewItem::operator<(const QTreeWidgetItem& other) const{
|
||||||
int SortCol=treeWidget()->header()->sortIndicatorSection();
|
int SortCol = treeWidget()->header()->sortIndicatorSection();
|
||||||
int ListIndex=((KeepassEntryView*)treeWidget())->columnListIndex(SortCol);
|
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);
|
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 DateThis;
|
||||||
KpxDateTime DateOther;
|
KpxDateTime DateOther;
|
||||||
|
|
||||||
switch (ListIndex){
|
switch (index){
|
||||||
case 5: DateThis=EntryHandle->expire();
|
case 5:
|
||||||
DateOther=((EntryViewItem&)other).EntryHandle->expire();
|
DateThis=EntryHandle->expire();
|
||||||
break;
|
DateOther=((EntryViewItem&)other).EntryHandle->expire();
|
||||||
case 6: DateThis=EntryHandle->creation();
|
break;
|
||||||
DateOther=((EntryViewItem&)other).EntryHandle->creation();
|
case 6:
|
||||||
break;
|
DateThis=EntryHandle->creation();
|
||||||
case 7: DateThis=EntryHandle->lastMod();
|
DateOther=((EntryViewItem&)other).EntryHandle->creation();
|
||||||
DateOther=((EntryViewItem&)other).EntryHandle->lastMod();
|
break;
|
||||||
break;
|
case 7:
|
||||||
case 8: DateThis=EntryHandle->lastAccess();
|
DateThis=EntryHandle->lastMod();
|
||||||
DateOther=((EntryViewItem&)other).EntryHandle->lastAccess();
|
DateOther=((EntryViewItem&)other).EntryHandle->lastMod();
|
||||||
break;
|
break;
|
||||||
default:Q_ASSERT(false);
|
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){
|
void KeepassEntryView::setCurrentEntry(IEntryHandle* entry){
|
||||||
bool found=false;
|
bool found=false;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -64,11 +64,11 @@ class KeepassEntryView:public QTreeWidget{
|
||||||
QList<int> ColumnOrder;
|
QList<int> ColumnOrder;
|
||||||
float GroupColumnSize;
|
float GroupColumnSize;
|
||||||
|
|
||||||
virtual void contextMenuEvent(QContextMenuEvent *event);
|
void contextMenuEvent(QContextMenuEvent *event);
|
||||||
virtual void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
virtual void resizeEvent(QResizeEvent* event);
|
void resizeEvent(QResizeEvent* event);
|
||||||
virtual void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void OnColumnResized(int index,int OldSize, int NewSize);
|
void OnColumnResized(int index,int OldSize, int NewSize);
|
||||||
|
@ -107,7 +107,9 @@ class EntryViewItem:public QTreeWidgetItem{
|
||||||
EntryViewItem(QTreeWidgetItem *parent);
|
EntryViewItem(QTreeWidgetItem *parent);
|
||||||
EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
|
EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
|
||||||
IEntryHandle* EntryHandle;
|
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