Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Add search functionality to pc-pkgmanager. Still need to setup the ke…
Browse files Browse the repository at this point in the history
…yboard shortcuts (ctrl-F, enter)
  • Loading branch information
Ken Moore committed Aug 16, 2013
1 parent cb8f638 commit 5fd031d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 6 deletions.
55 changes: 54 additions & 1 deletion src-qt4/pc-pkgmanager/mainWin.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -106,6 +107,58 @@ void mainWin::slotApplyClicked() {

}

void mainWin::slotSearchPackages(){
QString pkgSearch = line_search->text();
if(pkgSearch.isEmpty()){ return; }
qDebug() << "Search for package:" <<pkgSearch;
//Get the pointer to the proper treewidget
QTreeWidget *TW = treeNGPkgs;
if( stackedPkgView->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; p<TW->topLevelItemCount(); p++){
for(int c=startChild; c<TW->topLevelItem(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;
Expand Down Expand Up @@ -672,7 +725,6 @@ void mainWin::addNGItems()

catItem->addChild(pkgItem);
}

}

// Lets prompt user, and do it!
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src-qt4/pc-pkgmanager/mainWin.h
Expand Up @@ -48,6 +48,7 @@ private slots:
void slotFinishLoadingMetaPkgs();
void slotGetPackageDataOutput();
void slotApplyClicked();
void slotSearchPackages();

// Package updates
void slotRescanPkgsClicked();
Expand Down Expand Up @@ -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();
Expand Down
27 changes: 26 additions & 1 deletion src-qt4/pc-pkgmanager/mainWin.ui
Expand Up @@ -180,6 +180,27 @@
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="line_search">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tool_search">
<property name="text">
<string>Search</string>
</property>
<property name="icon">
<iconset resource="pc-pkgmanager.qrc">
<normaloff>:/search.png</normaloff>:/search.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="spacer2">
<property name="orientation">
Expand Down Expand Up @@ -385,6 +406,10 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>&amp;Close</string>
</property>
<property name="icon">
<iconset resource="pc-pkgmanager.qrc">
<normaloff>:/window-close.png</normaloff>:/window-close.png</iconset>
</property>
</widget>
</item>
</layout>
Expand All @@ -397,7 +422,7 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
Expand Down
10 changes: 6 additions & 4 deletions src-qt4/pc-pkgmanager/pc-pkgmanager.qrc
@@ -1,6 +1,8 @@
<RCC>
<qresource prefix="/">
<file>view-refresh.png</file>
<file>pkgmanager.png</file>
</qresource>
<qresource prefix="/">
<file>window-close.png</file>
<file>search.png</file>
<file>view-refresh.png</file>
<file>pkgmanager.png</file>
</qresource>
</RCC>

0 comments on commit 5fd031d

Please sign in to comment.