KRename – powerful batch renamer
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.

krecursivelister.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /***************************************************************************
  2. krecursivelister.cpp - description
  3. -------------------
  4. begin : Fri Aug 31 2001
  5. copyright : (C) 2001 by Jonathon Sim
  6. email : jonathonsim@iname.com
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include <tqtimer.h>
  17. #include "krecursivelister.h"
  18. KRecursiveLister::KRecursiveLister(TQObject *parent, const char *name ) : TQObject(parent,name) {
  19. lister = 0L;
  20. filelist.clear();
  21. dirlist.clear();
  22. dirtree.clear();
  23. allItems.setAutoDelete( true ); // only there to delete all items
  24. m_hidden = false;
  25. m_dirs = false;
  26. m_filter = TQString();
  27. }
  28. KRecursiveLister::~KRecursiveLister(){
  29. delete lister;
  30. }
  31. void KRecursiveLister::cleanUp()
  32. {
  33. filelist.clear();
  34. dirlist.clear();
  35. }
  36. /** Starts listing the specified url */
  37. void KRecursiveLister::openURL(const KURL& url ){
  38. filelist.clear();
  39. dirlist.clear();
  40. startListing(url);
  41. }
  42. /** Returns the list of fileitems found. */
  43. const KFileItemList & KRecursiveLister::items(){
  44. return filelist;
  45. }
  46. /** handles completion of a listing. */
  47. void KRecursiveLister::slotListingComplete(){
  48. KFileItemList templist=lister->items();
  49. KFileItem * item;
  50. KFileItem * newitem;
  51. for( item = templist.first(); item != 0; item=templist.next() )
  52. {
  53. if (item->isDir()) {
  54. newitem= new KFileItem(*item);
  55. dirlist.append(newitem);//Used for recursing the directories
  56. dirtree.append(newitem);//Returned to user on request.
  57. allItems.append(newitem);
  58. }
  59. else {
  60. newitem= new KFileItem(*item);
  61. filelist.append(newitem);
  62. allItems.append(newitem);
  63. }
  64. }
  65. TQTimer::singleShot( 0, this, TQT_SLOT( listNextDirectory() ));
  66. }
  67. /** Starts listing the specified url */
  68. void KRecursiveLister::startListing(const KURL& url){
  69. if (!lister) {
  70. lister=new KDirLister(true);
  71. lister->setShowingDotFiles( m_hidden );
  72. lister->setNameFilter( m_filter );
  73. lister->setDirOnlyMode( m_dirs );
  74. connect(lister,TQT_SIGNAL(completed()), this, TQT_SLOT(slotListingComplete()) );
  75. }
  76. lister->openURL( url, false, false );
  77. }
  78. void KRecursiveLister::listNextDirectory()
  79. {
  80. if ( dirlist.isEmpty() )
  81. emit completed();
  82. else
  83. {
  84. KFileItem * nextdir=dirlist.last();
  85. KURL url = nextdir->url();
  86. dirlist.removeLast();
  87. startListing( url );
  88. }
  89. }
  90. /** Stops the listing */
  91. void KRecursiveLister::stop(){
  92. lister->stop();
  93. }
  94. /** Returns the subdirectories found by the listing */
  95. const KFileItemList& KRecursiveLister::dirs(){
  96. return dirtree;
  97. }
  98. #include "krecursivelister.moc"