From ca554494d2b170e3c835e9faa7e9661002a23b05 Mon Sep 17 00:00:00 2001 From: tariq Date: Tue, 31 Jan 2006 22:38:53 +0000 Subject: [PATCH] some work on the search function git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@31 b624d157-de02-0410-bad0-e51aec6abb33 --- src/dialogs/SearchDlg.cpp | 35 +++++++++++++++++++---------------- src/dialogs/SearchDlg.h | 17 +++++------------ src/lib/EntryView.cpp | 5 +++++ src/lib/EntryView.h | 1 + src/lib/GroupView.cpp | 16 +++++++++++++++- src/lib/GroupView.h | 2 ++ src/mainwindow.cpp | 9 ++++++--- src/mainwindow.h | 1 + 8 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/dialogs/SearchDlg.cpp b/src/dialogs/SearchDlg.cpp index 298b83f..afd9e83 100755 --- a/src/dialogs/SearchDlg.cpp +++ b/src/dialogs/SearchDlg.cpp @@ -26,7 +26,7 @@ #include #include -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) { setupUi(this); @@ -42,6 +42,9 @@ checkBox_Password->setChecked(config.SearchOptions[4]); checkBox_Comment->setChecked(config.SearchOptions[5]); checkBox_URL->setChecked(config.SearchOptions[6]); checkBox_Attachment->setChecked(config.SearchOptions[7]); + +db=_db; +group=pGroup; } CSearchDlg::~CSearchDlg() @@ -63,40 +66,40 @@ done(0); void CSearchDlg::OnButtonSearch() { -/* +Hits.clear(); txt=Edit_Search->text(); regexp=checkBox_regExp->isChecked(); if(txt==""){ QMessageBox::information(this,trUtf8("Hinweis"),trUtf8("Bitte geben Sie einen Suchbegriff ein."),"OK",0,0); return;} -for(int i=0;iEntries.size();i++){ - if(group){if(pw->Entries[i].GroupID != group->ID)continue;} +for(int i=0;iEntries.size();i++){ + if(group){if(db->Entries[i].GroupID != group->ID)continue;} bool hit=false; - if(checkBox_Title->isChecked()) hit=hit||search(pw->Entries[i].Title); - if(checkBox_Username->isChecked()) hit=hit||search(pw->Entries[i].UserName); - if(checkBox_URL->isChecked()) hit=hit||search(pw->Entries[i].URL); - if(checkBox_Comment->isChecked()) hit=hit||search(pw->Entries[i].Additional); - if(checkBox_Attachment->isChecked()) hit=hit||search(pw->Entries[i].BinaryDesc); - if(checkBox_Password->isChecked()) hit=hit||search(pw->Entries[i].Password.getString()); - pw->Entries[i].Password.delRef(); - if(hit)hits.push_back(&pw->Entries[i]); + if(checkBox_Title->isChecked()) hit=hit||search(db->Entries[i].Title); + if(checkBox_Username->isChecked()) hit=hit||search(db->Entries[i].UserName); + if(checkBox_URL->isChecked()) hit=hit||search(db->Entries[i].URL); + if(checkBox_Comment->isChecked()) hit=hit||search(db->Entries[i].Additional); + if(checkBox_Attachment->isChecked()) hit=hit||search(db->Entries[i].BinaryDesc); + if(checkBox_Password->isChecked()) hit=hit||search(db->Entries[i].Password.getString()); + db->Entries[i].Password.delRef(); + if(hit)Hits.push_back(db->Entries[i].sID); } -*/ + done(1); } -/* + bool CSearchDlg::search(QString& str){ + if(regexp){ QRegExp exp(txt,checkBox_Cs->isChecked()); if(str.contains(exp)==0)return false;} else{ if(str.contains(txt,checkBox_Cs->isChecked())==0)return false;} return true; -}*/ -/*$SPECIALIZATION$*/ +} diff --git a/src/dialogs/SearchDlg.h b/src/dialogs/SearchDlg.h index d3c62f1..87b3324 100755 --- a/src/dialogs/SearchDlg.h +++ b/src/dialogs/SearchDlg.h @@ -27,28 +27,21 @@ class CSearchDlg : public QDialog, public Ui_Search_Dlg { Q_OBJECT 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 ); ~CSearchDlg(); - /*$PUBLIC_FUNCTIONS$*/ - -public slots: - /*$PUBLIC_SLOTS$*/ - -protected: - /*$PROTECTED_FUNCTIONS$*/ - -protected slots: - /*$PROTECTED_SLOTS$*/ + QList Hits; public slots: virtual void OnButtonClose(); -public slots: virtual void OnButtonSearch(); private: QString txt; + CGroup* group; bool regexp; + PwDatabase* db; + bool search(QString& str); }; #endif diff --git a/src/lib/EntryView.cpp b/src/lib/EntryView.cpp index 418fc3c..2a9d2e8 100644 --- a/src/lib/EntryView.cpp +++ b/src/lib/EntryView.cpp @@ -84,6 +84,11 @@ for(int i=0; i& results){ + + +} + void KeepassEntryView::refreshVisibleItems(){ EntryViewItem *tmp=NULL; for(int i=0;i& results); PwDatabase* db; vectorItems; private: diff --git a/src/lib/GroupView.cpp b/src/lib/GroupView.cpp index 1158d8a..f7a91e6 100644 --- a/src/lib/GroupView.cpp +++ b/src/lib/GroupView.cpp @@ -41,6 +41,7 @@ InsertionMarker=QLine(); db=NULL; LastHoverItem=NULL; setHeaderLabels(QStringList()<setIcon(0,EntryIcons[db->Groups[i].ImageID]); for(int i=0;ipGroup->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){ 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){ diff --git a/src/lib/GroupView.h b/src/lib/GroupView.h index 434a82c..444a6fa 100644 --- a/src/lib/GroupView.h +++ b/src/lib/GroupView.h @@ -30,6 +30,7 @@ class KeepassGroupView:public QTreeWidget{ public: KeepassGroupView(QWidget* parent=0); void updateItems(); + bool isSearchResultGroup(GroupViewItem* item); PwDatabase *db; vectorItems; protected: @@ -49,6 +50,7 @@ private: QPixmap DragPixmap; GroupViewItem* DragItem; GroupViewItem* LastHoverItem; + bool ShowSearchGroup; //needs a "updateItems()" after a change! GroupViewItem* getLastSameLevelItem(int level); }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6975984..480151f 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -376,7 +376,10 @@ void KeepassMainWindow::OnImportFromKWalletXml(){} void KeepassMainWindow::OnCurrentGroupChanged(QTreeWidgetItem* cur,QTreeWidgetItem* prev){ 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){ -CSearchDlg dlg(group,this,"SearchDialog",false); +CSearchDlg dlg(db,group,this,"SearchDialog",false); if(dlg.exec()){ - + SearchResults=dlg.Hits; } else { diff --git a/src/mainwindow.h b/src/mainwindow.h index bd4a39a..9005538 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -88,6 +88,7 @@ private: bool ModFlag; QClipboard* Clipboard; QTimer ClipboardTimer; + QList SearchResults; inline void setupToolbar(); inline void setupIcons(); inline void setupConnections();