TDE System Settings – easy to use control center
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 lines
3.0 KiB

  1. /**
  2. * This file is part of the System Settings package
  3. * Copyright (C) 2005 Benjamin C Meyer
  4. * <ben+systempreferences at meyerhome dot net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this library; see the file COPYING.LIB. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. */
  21. #include "kcmsearch.h"
  22. #include <tqregexp.h>
  23. #include <kdebug.h>
  24. #include "modulesview.h"
  25. #include "moduleiconitem.h"
  26. KcmSearch::KcmSearch( TQPtrList<ModulesView> *moduleViewList, TQWidget *parent, const char *name )
  27. : KIconViewSearchLine(parent, moduleViewList->at(0)->groups[0], name){
  28. this->moduleViewList = moduleViewList;
  29. }
  30. void KcmSearch::updateSearch( const TQString &search ) {
  31. TQValueList<RowIconView*>::iterator it;
  32. TQPtrListIterator<ModulesView> moduleViewListIt(*moduleViewList);
  33. ModulesView *mainView;
  34. int page = 0;
  35. int *hitArray = new int[moduleViewList->count()];
  36. for ( ; moduleViewListIt.current(); ++moduleViewListIt) {
  37. mainView = moduleViewListIt.current();
  38. int count = 0;
  39. for ( it = mainView->groups.begin(); it != mainView->groups.end(); ++it ){
  40. TQIconViewItem *item = (*it)->firstItem();
  41. while( item ) {
  42. bool hit = itemMatches(item, search);
  43. ((ModuleIconItem*)item)->loadIcon(hit);
  44. count += hit ? 1 : 0;
  45. item = item->nextItem();
  46. }
  47. }
  48. hitArray[page] = count;
  49. page++;
  50. }
  51. emit searchHits(search, hitArray, moduleViewList->count());
  52. delete[] hitArray;
  53. }
  54. bool KcmSearch::itemMatches( const KCModuleInfo &module, const TQString &search ) const
  55. {
  56. // Look in keywords
  57. TQStringList kw = module.keywords();
  58. for(TQStringList::ConstIterator it = kw.begin(); it != kw.end(); ++it) {
  59. TQString name = (*it).lower();
  60. if ( TQRegExp(search+"*", false, true).search(name) >= 0){
  61. //kdDebug() << "MATCH:" << module.moduleName().latin1()
  62. // << "keyword:" << name.latin1() << endl;
  63. return true;
  64. }
  65. }
  66. // Don't forget to check the name :)
  67. if ( TQRegExp(search+"*", false, true).search(module.moduleName()) >= 0)
  68. return true;
  69. //kdDebug() << "No MATCH:" << module.moduleName().latin1() << endl;
  70. return false;
  71. }
  72. bool KcmSearch::itemMatches( const TQIconViewItem *item, const TQString & search ) const
  73. {
  74. if( !item )
  75. return false;
  76. ModuleIconItem *mItem = (ModuleIconItem*)item;
  77. TQValueList<KCModuleInfo>::iterator it;
  78. for ( it = mItem->modules.begin(); it != mItem->modules.end(); ++it ){
  79. if( itemMatches( (*it), search ) )
  80. return true;
  81. }
  82. return false;
  83. }
  84. #include "kcmsearch.moc"