some work on the search function
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@31 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
parent
3d8bcf2ee8
commit
ca554494d2
|
@ -26,7 +26,7 @@
|
||||||
#include <qregexp.h>
|
#include <qregexp.h>
|
||||||
#include <qmessagebox.h>
|
#include <qmessagebox.h>
|
||||||
|
|
||||||
CSearchDlg::CSearchDlg(CGroup* pGroup,QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
|
CSearchDlg::CSearchDlg(PwDatabase* _db,CGroup* pGroup,QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
|
||||||
: QDialog(parent,name, modal,fl)
|
: QDialog(parent,name, modal,fl)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
@ -42,6 +42,9 @@ checkBox_Password->setChecked(config.SearchOptions[4]);
|
||||||
checkBox_Comment->setChecked(config.SearchOptions[5]);
|
checkBox_Comment->setChecked(config.SearchOptions[5]);
|
||||||
checkBox_URL->setChecked(config.SearchOptions[6]);
|
checkBox_URL->setChecked(config.SearchOptions[6]);
|
||||||
checkBox_Attachment->setChecked(config.SearchOptions[7]);
|
checkBox_Attachment->setChecked(config.SearchOptions[7]);
|
||||||
|
|
||||||
|
db=_db;
|
||||||
|
group=pGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSearchDlg::~CSearchDlg()
|
CSearchDlg::~CSearchDlg()
|
||||||
|
@ -63,40 +66,40 @@ done(0);
|
||||||
|
|
||||||
void CSearchDlg::OnButtonSearch()
|
void CSearchDlg::OnButtonSearch()
|
||||||
{
|
{
|
||||||
/*
|
Hits.clear();
|
||||||
txt=Edit_Search->text();
|
txt=Edit_Search->text();
|
||||||
regexp=checkBox_regExp->isChecked();
|
regexp=checkBox_regExp->isChecked();
|
||||||
if(txt==""){
|
if(txt==""){
|
||||||
QMessageBox::information(this,trUtf8("Hinweis"),trUtf8("Bitte geben Sie einen Suchbegriff ein."),"OK",0,0);
|
QMessageBox::information(this,trUtf8("Hinweis"),trUtf8("Bitte geben Sie einen Suchbegriff ein."),"OK",0,0);
|
||||||
return;}
|
return;}
|
||||||
|
|
||||||
for(int i=0;i<pw->Entries.size();i++){
|
for(int i=0;i<db->Entries.size();i++){
|
||||||
if(group){if(pw->Entries[i].GroupID != group->ID)continue;}
|
if(group){if(db->Entries[i].GroupID != group->ID)continue;}
|
||||||
bool hit=false;
|
bool hit=false;
|
||||||
if(checkBox_Title->isChecked()) hit=hit||search(pw->Entries[i].Title);
|
if(checkBox_Title->isChecked()) hit=hit||search(db->Entries[i].Title);
|
||||||
if(checkBox_Username->isChecked()) hit=hit||search(pw->Entries[i].UserName);
|
if(checkBox_Username->isChecked()) hit=hit||search(db->Entries[i].UserName);
|
||||||
if(checkBox_URL->isChecked()) hit=hit||search(pw->Entries[i].URL);
|
if(checkBox_URL->isChecked()) hit=hit||search(db->Entries[i].URL);
|
||||||
if(checkBox_Comment->isChecked()) hit=hit||search(pw->Entries[i].Additional);
|
if(checkBox_Comment->isChecked()) hit=hit||search(db->Entries[i].Additional);
|
||||||
if(checkBox_Attachment->isChecked()) hit=hit||search(pw->Entries[i].BinaryDesc);
|
if(checkBox_Attachment->isChecked()) hit=hit||search(db->Entries[i].BinaryDesc);
|
||||||
if(checkBox_Password->isChecked()) hit=hit||search(pw->Entries[i].Password.getString());
|
if(checkBox_Password->isChecked()) hit=hit||search(db->Entries[i].Password.getString());
|
||||||
pw->Entries[i].Password.delRef();
|
db->Entries[i].Password.delRef();
|
||||||
if(hit)hits.push_back(&pw->Entries[i]);
|
if(hit)Hits.push_back(db->Entries[i].sID);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
done(1);
|
done(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
bool CSearchDlg::search(QString& str){
|
bool CSearchDlg::search(QString& str){
|
||||||
|
|
||||||
if(regexp){
|
if(regexp){
|
||||||
QRegExp exp(txt,checkBox_Cs->isChecked());
|
QRegExp exp(txt,checkBox_Cs->isChecked());
|
||||||
if(str.contains(exp)==0)return false;}
|
if(str.contains(exp)==0)return false;}
|
||||||
else{
|
else{
|
||||||
if(str.contains(txt,checkBox_Cs->isChecked())==0)return false;}
|
if(str.contains(txt,checkBox_Cs->isChecked())==0)return false;}
|
||||||
return true;
|
return true;
|
||||||
}*/
|
|
||||||
|
|
||||||
/*$SPECIALIZATION$*/
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,28 +27,21 @@ class CSearchDlg : public QDialog, public Ui_Search_Dlg
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CSearchDlg(CGroup* pGroup=NULL,QWidget* parent = 0, const char* name = 0,
|
CSearchDlg(PwDatabase* _db, CGroup* pGroup=NULL,QWidget* parent = 0, const char* name = 0,
|
||||||
bool modal = FALSE, Qt::WFlags fl = 0 );
|
bool modal = FALSE, Qt::WFlags fl = 0 );
|
||||||
~CSearchDlg();
|
~CSearchDlg();
|
||||||
/*$PUBLIC_FUNCTIONS$*/
|
QList<Q_UINT32> Hits;
|
||||||
|
|
||||||
public slots:
|
|
||||||
/*$PUBLIC_SLOTS$*/
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/*$PROTECTED_FUNCTIONS$*/
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
/*$PROTECTED_SLOTS$*/
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void OnButtonClose();
|
virtual void OnButtonClose();
|
||||||
public slots:
|
|
||||||
virtual void OnButtonSearch();
|
virtual void OnButtonSearch();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString txt;
|
QString txt;
|
||||||
|
CGroup* group;
|
||||||
bool regexp;
|
bool regexp;
|
||||||
|
PwDatabase* db;
|
||||||
|
bool search(QString& str);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -84,6 +84,11 @@ for(int i=0; i<Items.size();i++){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeepassEntryView::showSearchResults(QList<Q_UINT32>& results){
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void KeepassEntryView::refreshVisibleItems(){
|
void KeepassEntryView::refreshVisibleItems(){
|
||||||
EntryViewItem *tmp=NULL;
|
EntryViewItem *tmp=NULL;
|
||||||
for(int i=0;i<Items.size();i++){
|
for(int i=0;i<Items.size();i++){
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
void refreshVisibleItems();
|
void refreshVisibleItems();
|
||||||
void setCurrentGroup(uint GroupID);
|
void setCurrentGroup(uint GroupID);
|
||||||
void updateColumns();
|
void updateColumns();
|
||||||
|
void showSearchResults(QList<Q_UINT32>& results);
|
||||||
PwDatabase* db;
|
PwDatabase* db;
|
||||||
vector<EntryViewItem*>Items;
|
vector<EntryViewItem*>Items;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -41,6 +41,7 @@ InsertionMarker=QLine();
|
||||||
db=NULL;
|
db=NULL;
|
||||||
LastHoverItem=NULL;
|
LastHoverItem=NULL;
|
||||||
setHeaderLabels(QStringList()<<tr("Gruppen"));
|
setHeaderLabels(QStringList()<<tr("Gruppen"));
|
||||||
|
ShowSearchGroup=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeepassGroupView:: dragEnterEvent ( QDragEnterEvent * event ){
|
void KeepassGroupView:: dragEnterEvent ( QDragEnterEvent * event ){
|
||||||
|
@ -197,7 +198,16 @@ Items.back()->setIcon(0,EntryIcons[db->Groups[i].ImageID]);
|
||||||
|
|
||||||
for(int i=0;i<Items.size();i++){
|
for(int i=0;i<Items.size();i++){
|
||||||
setItemExpanded(Items[i],Items[i]->pGroup->UI_ItemIsExpanded);
|
setItemExpanded(Items[i],Items[i]->pGroup->UI_ItemIsExpanded);
|
||||||
}}
|
}
|
||||||
|
if(ShowSearchGroup){
|
||||||
|
Items.push_back(new GroupViewItem(this));
|
||||||
|
Items.back()->setText(0,trUtf8("Suchergebnisse"));
|
||||||
|
Items.back()->pGroup=NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GroupViewItem* KeepassGroupView::getLastSameLevelItem(int level){
|
GroupViewItem* KeepassGroupView::getLastSameLevelItem(int level){
|
||||||
for(int i=Items.size()-1;i>=0;i--){
|
for(int i=Items.size()-1;i>=0;i--){
|
||||||
|
@ -221,6 +231,10 @@ painter.drawLine(InsertionMarker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KeepassGroupView::isSearchResultGroup(GroupViewItem* item){
|
||||||
|
if(ShowSearchGroup && (item == Items.back()))return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GroupViewItem::GroupViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){
|
GroupViewItem::GroupViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){
|
||||||
|
|
|
@ -30,6 +30,7 @@ class KeepassGroupView:public QTreeWidget{
|
||||||
public:
|
public:
|
||||||
KeepassGroupView(QWidget* parent=0);
|
KeepassGroupView(QWidget* parent=0);
|
||||||
void updateItems();
|
void updateItems();
|
||||||
|
bool isSearchResultGroup(GroupViewItem* item);
|
||||||
PwDatabase *db;
|
PwDatabase *db;
|
||||||
vector<GroupViewItem*>Items;
|
vector<GroupViewItem*>Items;
|
||||||
protected:
|
protected:
|
||||||
|
@ -49,6 +50,7 @@ private:
|
||||||
QPixmap DragPixmap;
|
QPixmap DragPixmap;
|
||||||
GroupViewItem* DragItem;
|
GroupViewItem* DragItem;
|
||||||
GroupViewItem* LastHoverItem;
|
GroupViewItem* LastHoverItem;
|
||||||
|
bool ShowSearchGroup; //needs a "updateItems()" after a change!
|
||||||
|
|
||||||
GroupViewItem* getLastSameLevelItem(int level);
|
GroupViewItem* getLastSameLevelItem(int level);
|
||||||
};
|
};
|
||||||
|
|
|
@ -376,7 +376,10 @@ void KeepassMainWindow::OnImportFromKWalletXml(){}
|
||||||
|
|
||||||
void KeepassMainWindow::OnCurrentGroupChanged(QTreeWidgetItem* cur,QTreeWidgetItem* prev){
|
void KeepassMainWindow::OnCurrentGroupChanged(QTreeWidgetItem* cur,QTreeWidgetItem* prev){
|
||||||
if(cur){
|
if(cur){
|
||||||
EntryView->setCurrentGroup(((GroupViewItem*)cur)->pGroup->ID);
|
if(GroupView->isSearchResultGroup((GroupViewItem*)cur)){
|
||||||
|
EntryView->showSearchResults(SearchResults);
|
||||||
|
}
|
||||||
|
else EntryView->setCurrentGroup(((GroupViewItem*)cur)->pGroup->ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,9 +509,9 @@ openBrowser(currentEntry()->URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeepassMainWindow::search(CGroup* group){
|
void KeepassMainWindow::search(CGroup* group){
|
||||||
CSearchDlg dlg(group,this,"SearchDialog",false);
|
CSearchDlg dlg(db,group,this,"SearchDialog",false);
|
||||||
if(dlg.exec()){
|
if(dlg.exec()){
|
||||||
|
SearchResults=dlg.Hits;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -88,6 +88,7 @@ private:
|
||||||
bool ModFlag;
|
bool ModFlag;
|
||||||
QClipboard* Clipboard;
|
QClipboard* Clipboard;
|
||||||
QTimer ClipboardTimer;
|
QTimer ClipboardTimer;
|
||||||
|
QList<Q_UINT32> SearchResults;
|
||||||
inline void setupToolbar();
|
inline void setupToolbar();
|
||||||
inline void setupIcons();
|
inline void setupIcons();
|
||||||
inline void setupConnections();
|
inline void setupConnections();
|
||||||
|
|
Loading…
Reference in New Issue