From 5fd031d1fb5e3ff0918e9108da07c07afb279ff0 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 16 Aug 2013 17:23:52 -0400 Subject: [PATCH] Add search functionality to pc-pkgmanager. Still need to setup the keyboard shortcuts (ctrl-F, enter) --- src-qt4/pc-pkgmanager/mainWin.cpp | 55 ++++++++++++++++++++++++- src-qt4/pc-pkgmanager/mainWin.h | 4 ++ src-qt4/pc-pkgmanager/mainWin.ui | 27 +++++++++++- src-qt4/pc-pkgmanager/pc-pkgmanager.qrc | 10 +++-- 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src-qt4/pc-pkgmanager/mainWin.cpp b/src-qt4/pc-pkgmanager/mainWin.cpp index dbb11e340..72ee276ad 100644 --- a/src-qt4/pc-pkgmanager/mainWin.cpp +++ b/src-qt4/pc-pkgmanager/mainWin.cpp @@ -39,6 +39,7 @@ void mainWin::ProgramInit(QString ch) connect(action_Quit, SIGNAL( triggered(bool) ), this, SLOT( slotCloseClicked() ) ); connect(action_Basic, SIGNAL( triggered(bool) ), this, SLOT( slotViewChanged() ) ); connect(action_Advanced, SIGNAL( triggered(bool) ), this, SLOT( slotViewChanged() ) ); + connect(tool_search, SIGNAL( clicked() ), this, SLOT( slotSearchPackages() ) ); // Setup the action group viewGroup = new QActionGroup(this); @@ -106,6 +107,58 @@ void mainWin::slotApplyClicked() { } +void mainWin::slotSearchPackages(){ + QString pkgSearch = line_search->text(); + if(pkgSearch.isEmpty()){ return; } + qDebug() << "Search for package:" <currentIndex() == 0 ){ TW = treeMetaPkgs; } + //Make sure the tree widget is not empty + if(TW->topLevelItemCount() < 2){ return; } + //iterate through the tree widget, starting at the current selection + QTreeWidgetItem *CI = TW->currentItem(); + bool found=false; bool atTop=false; + if(CI == 0){ CI = TW->topLevelItem(0); atTop=true; } + //Get the starting index (parent and child) + QTreeWidgetItem *PI = CI->parent(); + int startParent=0; int startChild=0; + if(PI == 0){ startParent = TW->indexOfTopLevelItem(CI); } //startchild == 0 + else{ startParent = TW->indexOfTopLevelItem(PI); startChild = PI->indexOfChild(CI) +1; } + //Now iterate over the tree, only looking at the actual packages (not categories) + found = performSearch(pkgSearch, TW, startParent, startChild); + if(!found && !atTop){ + //Ask whether to restart the search at the top + if(QMessageBox::Yes == QMessageBox::question(this,tr("No Search Results"),tr("Do you want to continue the search from the top?"),QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ){ + //Restart the search from the top + found = performSearch(pkgSearch, TW, 0, 0); + } + } + if(!found){ + QMessageBox::information(this, tr("No Search Results"), tr("No packages could be found with that search term. Please adjust it and try again.") ); + } + qDebug() << " - Search Finished"; +} + +bool mainWin::performSearch(QString pkgSearch, QTreeWidget *TW, int startParent, int startChild){ + //Iterate over the Tree + bool found=false; + for(int p=startParent; ptopLevelItemCount(); p++){ + for(int c=startChild; ctopLevelItem(p)->childCount(); c++){ + QTreeWidgetItem *CI = TW->topLevelItem(p)->child(c); + if(CI->text(0).contains(pkgSearch, Qt::CaseInsensitive)){ + TW->setCurrentItem(CI); + TW->scrollToItem(CI); + found=true; + break; + } + } + startChild=0; //reset this for the next top level item + if(found){ break; } + } + return found; +} + void mainWin::checkMPKGUpdates() { QString line, tmp, name, pkgname, pkgover, pkgnver; @@ -672,7 +725,6 @@ void mainWin::addNGItems() catItem->addChild(pkgItem); } - } // Lets prompt user, and do it! @@ -899,6 +951,7 @@ void mainWin::addTreeItems(QString parent) // Now look for any possible children addTreeItems(metaPkgList.at(z).at(0)); } + } // Check if a meta-pkg is installed diff --git a/src-qt4/pc-pkgmanager/mainWin.h b/src-qt4/pc-pkgmanager/mainWin.h index d12f9f86c..afc886a6d 100644 --- a/src-qt4/pc-pkgmanager/mainWin.h +++ b/src-qt4/pc-pkgmanager/mainWin.h @@ -48,6 +48,7 @@ private slots: void slotFinishLoadingMetaPkgs(); void slotGetPackageDataOutput(); void slotApplyClicked(); + void slotSearchPackages(); // Package updates void slotRescanPkgsClicked(); @@ -79,6 +80,9 @@ private slots: bool pkgHasFailed; QString getConflictDetailText(); + //Search Iteration + bool performSearch(QString pkgSearch, QTreeWidget *TW, int startParent, int startChild); + // Updates void doUpdates(); bool sanityCheck(); diff --git a/src-qt4/pc-pkgmanager/mainWin.ui b/src-qt4/pc-pkgmanager/mainWin.ui index 289414163..2dc19c59f 100644 --- a/src-qt4/pc-pkgmanager/mainWin.ui +++ b/src-qt4/pc-pkgmanager/mainWin.ui @@ -180,6 +180,27 @@ + + + + + 0 + 0 + + + + + + + + Search + + + + :/search.png:/search.png + + + @@ -385,6 +406,10 @@ p, li { white-space: pre-wrap; } &Close + + + :/window-close.png:/window-close.png + @@ -397,7 +422,7 @@ p, li { white-space: pre-wrap; } 0 0 800 - 21 + 20 diff --git a/src-qt4/pc-pkgmanager/pc-pkgmanager.qrc b/src-qt4/pc-pkgmanager/pc-pkgmanager.qrc index 33386ae3b..2c93a5c44 100644 --- a/src-qt4/pc-pkgmanager/pc-pkgmanager.qrc +++ b/src-qt4/pc-pkgmanager/pc-pkgmanager.qrc @@ -1,6 +1,8 @@ - - view-refresh.png - pkgmanager.png - + + window-close.png + search.png + view-refresh.png + pkgmanager.png +