lib/Traverse.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "Traverse.h"
00023 #include <qdir.h>
00024 #include <qfileinfo.h>
00025 
00026 Traverse::Traverse (Traverse::Type t)
00027 {
00028   type = t;
00029 }
00030 
00031 Traverse::~Traverse ()
00032 {
00033 }
00034 
00035 void Traverse::traverse (QString dirname)
00036 {
00037   QDir dir(dirname);
00038   dir.setFilter(QDir::Dirs|QDir::Files);
00039 
00040   const QFileInfoList *fileinfolist = dir.entryInfoList();
00041   QFileInfoListIterator it(*fileinfolist);
00042   QFileInfo *fi;
00043   while((fi = it.current()))
00044   {
00045     if(fi->fileName() == "." || fi->fileName() == "..")
00046     {
00047       ++it;
00048       continue;
00049     }
00050 
00051     if(fi->isDir() && fi->isReadable())
00052     {
00053       if (type == Dir)
00054         list.append(fi->absFilePath());
00055       traverse(fi->absFilePath());
00056     }
00057     else
00058     {
00059       if (type == File)
00060         list.append(fi->absFilePath());
00061     }
00062 
00063     ++it;
00064   }
00065 }
00066 
00067 void Traverse::getList (QStringList &l)
00068 {
00069   l = list;
00070 }
00071 
00072 void Traverse::clear ()
00073 {
00074   list.clear();
00075 }
00076 
00077