REVIEW: 6667 svn path=/trunk/KDE/kdegraphics/okular/; revision=1230519remotes/origin/KDE/4.7
parent
d473477a5a
commit
4aa3ebe4c6
6 changed files with 147 additions and 4 deletions
@ -0,0 +1,67 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tobias Koenig <tokoe@kde.org> * |
||||
* Copyright (C) 2011 by David Palacio <dpalacio@orbitalibre.org> * |
||||
* * |
||||
* This program is free software; you can redistribute it and/or modify * |
||||
* it under the terms of the GNU General Public License as published by * |
||||
* the Free Software Foundation; either version 2 of the License, or * |
||||
* (at your option) any later version. * |
||||
***************************************************************************/ |
||||
|
||||
#include "directory.h" |
||||
|
||||
#include <QtCore/QDir> |
||||
#include <QtCore/QDirIterator> |
||||
#include <QtCore/QFile> |
||||
#include <QtCore/QFileInfo> |
||||
|
||||
#include <memory> |
||||
|
||||
Directory::Directory() |
||||
{ |
||||
} |
||||
|
||||
Directory::~Directory() |
||||
{ |
||||
} |
||||
|
||||
bool Directory::open( const QString &dirName ) |
||||
{ |
||||
mDir = dirName; |
||||
QFileInfo dirTest( dirName ); |
||||
return dirTest.isDir() && dirTest.isReadable(); |
||||
} |
||||
|
||||
QStringList Directory::recurseDir( const QString &dirPath, int curDepth ) const |
||||
{ |
||||
QDir dir( dirPath ); |
||||
dir.setFilter( QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot ); |
||||
QStringList fileList; |
||||
QDirIterator it( dir ); |
||||
QFileInfo info; |
||||
while( it.hasNext() ) { |
||||
it.next(); |
||||
info = it.fileInfo(); |
||||
if ( info.isDir() && curDepth < staticMaxDepth ) { |
||||
fileList.append( recurseDir( info.filePath(), curDepth + 1 ) ); |
||||
} else if ( info.isFile() ) { |
||||
fileList.append( info.filePath() ); |
||||
} |
||||
} |
||||
return fileList; |
||||
} |
||||
|
||||
QStringList Directory::list() const |
||||
{ |
||||
return recurseDir( mDir, 0 ); |
||||
} |
||||
|
||||
QIODevice* Directory::createDevice( const QString &path ) const |
||||
{ |
||||
std::auto_ptr<QFile> file( new QFile( path ) ); |
||||
if ( !file->open( QIODevice::ReadOnly ) ) |
||||
return 0; |
||||
|
||||
return file.release(); |
||||
} |
||||
|
||||
@ -0,0 +1,55 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tobias Koenig <tokoe@kde.org> * |
||||
* Copyright (C) 2011 by David Palacio <dpalacio@orbitalibre.org> * |
||||
* * |
||||
* This program is free software; you can redistribute it and/or modify * |
||||
* it under the terms of the GNU General Public License as published by * |
||||
* the Free Software Foundation; either version 2 of the License, or * |
||||
* (at your option) any later version. * |
||||
***************************************************************************/ |
||||
|
||||
#ifndef DIRECTORY_H |
||||
#define DIRECTORY_H |
||||
|
||||
#include <QtCore/QStringList> |
||||
|
||||
class Directory |
||||
{ |
||||
public: |
||||
/**
|
||||
* Creates a new directory object. |
||||
*/ |
||||
Directory(); |
||||
|
||||
/**
|
||||
* Destroys the directory object. |
||||
*/ |
||||
~Directory(); |
||||
|
||||
/**
|
||||
* Opens given directory. |
||||
*/ |
||||
bool open( const QString &fileName ); |
||||
|
||||
/**
|
||||
* Returns the list of files from the directory. |
||||
*/ |
||||
QStringList list() const; |
||||
|
||||
/**
|
||||
* Returns a new device for reading the file with the given path. |
||||
*/ |
||||
QIODevice* createDevice( const QString &path ) const; |
||||
|
||||
private: |
||||
/**
|
||||
* Iterates over a directory and returns a file list. |
||||
*/ |
||||
QStringList recurseDir( const QString &dir, int curDepth ) const; |
||||
|
||||
static const int staticMaxDepth = 1; |
||||
QString mDir; |
||||
}; |
||||
|
||||
#endif |
||||
|
||||
Loading…
Reference in new issue