author | zecke <zecke> | 2002-09-15 22:19:08 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-15 22:19:08 (UTC) |
commit | aabe567e96d040c483b947f5758a1405cc312fdc (patch) (side-by-side diff) | |
tree | ceb8ebba2384f1737277c0dfb89256eaa2ac1717 | |
parent | 09561ee29b5288e02e513172fc590d27e9e09333 (diff) | |
download | opie-aabe567e96d040c483b947f5758a1405cc312fdc.zip opie-aabe567e96d040c483b947f5758a1405cc312fdc.tar.gz opie-aabe567e96d040c483b947f5758a1405cc312fdc.tar.bz2 |
add files
-rw-r--r-- | libopie/ofileselector/olister.cpp | 72 | ||||
-rw-r--r-- | libopie/ofileselector/olister.cpp~ | 64 | ||||
-rw-r--r-- | libopie/ofileselector/olister.h | 59 | ||||
-rw-r--r-- | libopie/ofileselector/olister.h~ | 57 | ||||
-rw-r--r-- | libopie/ofileselector/olister.o | bin | 0 -> 24852 bytes | |||
-rw-r--r-- | libopie/ofileselector/olocallister.cpp | 118 | ||||
-rw-r--r-- | libopie/ofileselector/olocallister.cpp~ | 97 | ||||
-rw-r--r-- | libopie/ofileselector/olocallister.h | 14 | ||||
-rw-r--r-- | libopie/ofileselector/olocallister.h~ | 14 | ||||
-rw-r--r-- | libopie/ofileselector/olocallister.o | bin | 0 -> 42280 bytes |
10 files changed, 495 insertions, 0 deletions
diff --git a/libopie/ofileselector/olister.cpp b/libopie/ofileselector/olister.cpp new file mode 100644 index 0000000..6c43043 --- a/dev/null +++ b/libopie/ofileselector/olister.cpp @@ -0,0 +1,72 @@ +#include "olister.h" +#include "ofileview.h" +#include "ofileselector.h" + + +OLister::OLister( OFileSelector* view) + : m_view( view ) +{ +} +OLister::~OLister() { +} +bool OLister::showFiles()const { + return m_view->showFiles(); +} +bool OLister::showDirs()const { + return m_view->showDirs(); +} +void OLister::addFile( const QString& mine, + QFileInfo* info, + bool isSymlink ) { + view()->currentView()->addFile( mine, + info, + isSymlink ); +} +void OLister::addFile( const QString& mine, + const QString& path, + const QString& file, + bool isSymlink ) { + view()->currentView()->addFile( mine, + path, + file, + isSymlink ); +} +void OLister::addDir( const QString& mine, + QFileInfo* info, + bool isSymlink ) { + + view()->currentView()->addDir( mine, + info, + isSymlink ); +} +void OLister::addDir( const QString& mine, + const QString& path, + const QString& dir, + bool isSymlink ) { + view()->currentView()->addDir( mine, + path, + dir, + isSymlink ); +} +void OLister::addSymlink( const QString& mine, + QFileInfo* info, + bool isSymlink ) { + view()->currentView()->addSymlink( mine, + info, + isSymlink ); +} +void OLister::addSymlink( const QString& mine, + const QString& path, + const QString& name, + bool isSymlink ) { + view()->currentView()->addSymlink( mine, + path, + name, + isSymlink ); +} +OFileSelector* OLister::view() { + return m_view; +} +bool OLister::compliesMime( const QString& mime ) { + return view()->compliesMime( mime ); +} diff --git a/libopie/ofileselector/olister.cpp~ b/libopie/ofileselector/olister.cpp~ new file mode 100644 index 0000000..180422a --- a/dev/null +++ b/libopie/ofileselector/olister.cpp~ @@ -0,0 +1,64 @@ +#include "olister.h" +#include "ofileview.h" +#include "ofileselector.h" + + +OLister::OLister( OFileSelector* view) + : m_view( view ) +{ +} +OLister::~OLister() { +} +void OLister::addFile( const QString& mine, + QFileInfo* info, + bool isSymlink ) { + view()->currentView()->addFile( mine, + info, + isSymlink ); +} +void OLister::addFile( const QString& mine, + const QString& path, + const QString& file, + bool isSymlink ) { + view()->currentView()->addFile( mine, + path, + file, + isSymlink ); +} +void OLister::addDir( const QString& mine, + QFileInfo* info, + bool isSymlink ) { + + view()->currentView()->addDir( mine, + info, + isSymlink ); +} +void OLister::addDir( const QString& mine, + const QString& path, + const QString& dir, + bool isSymlink ) { + view()->currentView()->addDir( mine, + path, + dir, + isSymlink ); +} +void OLister::addSymlink( const QString& mine, + QFileInfo* info, + bool isSymlink ) { + view()->currentView()->addSymlink( mine, + info, + isSymlink ); +} +void OLister::addSymlink( const QString& mine, + const QString& path, + const QString& name, + bool isSymlink ) { + view()->currentView()->addSymlink( mine, + path, + name, + isSymlink ); +} +OFileSelector* OLister::view() { + return m_view; +} + diff --git a/libopie/ofileselector/olister.h b/libopie/ofileselector/olister.h new file mode 100644 index 0000000..081b876 --- a/dev/null +++ b/libopie/ofileselector/olister.h @@ -0,0 +1,59 @@ +#ifndef OPIE_FILE_LISTER_H +#define OPIE_FILE_LISTER_H + +#include <qfileinfo.h> +#include <qmap.h> +#include <qstring.h> + +class OFileSelector; +/** + * lister is something like KIO but very + * very basic and currently only for + * populating our views. + * This is a base class which needs to be implemented. + * @see OLocalLister for a filesystem based implementation + */ +class OLister { +public: + OLister( OFileSelector* ); + virtual ~OLister(); + virtual void reparse(const QString& path) = 0; + + /** + * return a list of available mimetypes + */ + virtual QMap<QString, QStringList> mimeTypes( const QString& dir ) = 0; + +protected: + bool showFiles()const; + bool showDirs()const; + bool compliesMime( const QString& mime ); + void addFile( const QString& mine, + QFileInfo*, + bool isSymlink = FALSE ); + void addFile( const QString& mine, + const QString& path, + const QString& file, + bool isSymlink = FALSE ); + void addDir( const QString& mine, + QFileInfo*, + bool isSymlink = FALSE ); + void addDir( const QString& mine, + const QString& path, + const QString& dir, + bool isSymlink = FALSE ); + void addSymlink( const QString& mine, + QFileInfo* info, + bool isSymlink = FALSE); + void addSymlink( const QString& mine, + const QString& path, + const QString& name, + bool isSymlink = FALSE ); + OFileSelector* view(); +private: + OFileSelector* m_view; + + +}; + +#endif diff --git a/libopie/ofileselector/olister.h~ b/libopie/ofileselector/olister.h~ new file mode 100644 index 0000000..bb6304c --- a/dev/null +++ b/libopie/ofileselector/olister.h~ @@ -0,0 +1,57 @@ +#ifndef OPIE_FILE_LISTER_H +#define OPIE_FILE_LISTER_H + +#include <qfileinfo.h> +#include <qmap.h> +#include <qstring.h> + +class OFileSelector; +/** + * lister is something like KIO but very + * very basic and currently only for + * populating our views. + * This is a base class which needs to be implemented. + * @see OLocalLister for a filesystem based implementation + */ +class OLister { +public: + OLister( OFileSelector* ); + virtual ~OLister(); + virtual void reparse(const QString& path) = 0; + + /** + * return a list of available mimetypes + */ + virtual QMap<QString, QString> mimeTypes( const QString& dir ) = 0; + +protected: + + void addFile( const QString& mine, + QFileInfo*, + bool isSymlink = FALSE ); + void addFile( const QString& mine, + const QString& path, + const QString& file, + bool isSymlink = FALSE ); + void addDir( const QString& mine, + QFileInfo*, + bool isSymlink = FALSE ); + void addDir( const QString& mine, + const QString& path, + const QString& dir, + bool isSymlink = FALSE ); + void addSymlink( const QString& mine, + QFileInfo* info, + bool isSymlink = FALSE); + void addSymlink( const QString& mine, + const QString& path, + const QString& name, + bool isSymlink = FALSE ); + OFileSelector* view(); +private: + OFileSelector* m_view; + + +}; + +#endif diff --git a/libopie/ofileselector/olister.o b/libopie/ofileselector/olister.o Binary files differnew file mode 100644 index 0000000..ca58d6c --- a/dev/null +++ b/libopie/ofileselector/olister.o diff --git a/libopie/ofileselector/olocallister.cpp b/libopie/ofileselector/olocallister.cpp new file mode 100644 index 0000000..6ffcf1e --- a/dev/null +++ b/libopie/ofileselector/olocallister.cpp @@ -0,0 +1,118 @@ +#include <qdir.h> +#include <qfileinfo.h> +#include <qmap.h> + +#include <qpe/mimetype.h> + +#include "ofileselector.h" +#include "olocallister.h" + +OLocalLister::OLocalLister( OFileSelector* file ) + : OLister( file ) +{ +} +OLocalLister::~OLocalLister() { +} + +QMap<QString, QStringList> OLocalLister::mimeTypes( const QString& curDir ) { + QMap<QString, QStringList> mimes; + + // let's find possible mimetypes + QDir dir( curDir ); + dir.setFilter( QDir::Files | QDir::Readable ); + dir.setSorting( QDir::Size ); + + const QFileInfoList *list = dir.entryInfoList(); + QFileInfoListIterator it( *list ); + QFileInfo *fi; + + while( (fi=it.current() ) ) { + /* skip .desktop */ + if( fi->extension() == QString::fromLatin1("desktop") ){ + ++it; + continue; + } + MimeType type( fi->absFilePath() ); + + if( !mimes.contains( type.id() ) ){ + mimes.insert( type.id(), type.id() ); + } + + ++it; + } + + return mimes; +} +/* FIXME mimecheck + * use mime check for that + * filter dirs + * filter filters + * filter files + * filter mimetypes + */ +void OLocalLister::reparse( const QString& path ) { + QString currentMimeType; + QDir dir( path ); + + dir.setSorting( view()->sorting() ); + dir.setFilter( view()->filter() ); + + + const QFileInfoList *list = dir.entryInfoList(); + QFileInfoListIterator it( *list ); + QFileInfo *fi; + + while( (fi=it.current() ) ){ + + if( fi->fileName() == QString::fromLatin1("..") || + fi->fileName() == QString::fromLatin1(".") ){ + ++it; + continue; + } + if( fi->isSymLink() ){ + QString file = fi->dirPath( true ) + "/" + fi->readLink(); + /* + * 5 tries to prevent dos attack + */ + for( int i = 0; i<=4; i++) { + QFileInfo info( file ); + if( !info.exists() ){ + addSymlink( currentMimeType, fi, TRUE ); + break; + }else if( info.isDir() ){ + if (!showDirs() ) + break; + + addDir( currentMimeType, fi, + TRUE ); + break; + }else if( info.isFile() ){ + /* if not show files skip it */ + if (!showFiles() ) + break; + + /* check if we comply to the mimetype */ + MimeType type( info.absFilePath() ); + if (compliesMime( type.id() ) ) + addFile( currentMimeType, fi, TRUE ); + + break; + }else if( info.isSymLink() ){ + file = info.dirPath(true ) + "/" + info.readLink() ; + break; + }else if( i == 4){ + addSymlink( currentMimeType, fi ); + } + } + + }else if( fi->isDir() ){ + if (showDirs() ) + addDir( currentMimeType, fi ); + }else if( fi->isFile() ){ + if ( showFiles() ) + addFile( currentMimeType, fi ); + } + ++it; + } // of while loop +} + diff --git a/libopie/ofileselector/olocallister.cpp~ b/libopie/ofileselector/olocallister.cpp~ new file mode 100644 index 0000000..b0e5410 --- a/dev/null +++ b/libopie/ofileselector/olocallister.cpp~ @@ -0,0 +1,97 @@ +#include <qdir.h> +#include <qfileinfo.h> +#include <qmap.h> + +#include <qpe/mimetype.h> + +#include "ofileselector.h" +#include "olocallister.h" + +OLocalLister::OLocalLister( OFileSelector* file ) + : OLister( file ) +{ +} +OLocalLister::~OLocalLister() { +} + +QMap<QString, QString> OLocalLister::mimeTypes( const QString& curDir ) { + QMap<QString, QString> mimes; + + // let's find possible mimetypes + QDir dir( curDir ); + dir.setFilter( QDir::Files | QDir::Readable ); + dir.setSorting( QDir::Size ); + + const QFileInfoList *list = dir.entryInfoList(); + QFileInfoListIterator it( *list ); + QFileInfo *fi; + + while( (fi=it.current() ) ) { + if( fi->extension() == QString::fromLatin1("desktop") ){ + ++it; + continue; + } + MimeType type( fi->absFilePath() ); + + if( !mimes.contains( type.id() ) ){ + mimes.insert( type.id(), type.id() ); + } + + ++it; + } + + return mimes; +} +void OLocalLister::reparse( const QString& path ) { + QString currentMimeType; + QDir dir( path ); + + dir.setSorting( view()->sorting() ); + dir.setFilter( view()->filter() ); + + // now go through all files + const QFileInfoList *list = dir.entryInfoList(); + QFileInfoListIterator it( *list ); + QFileInfo *fi; + + while( (fi=it.current() ) ){ + + if( fi->fileName() == QString::fromLatin1("..") || + fi->fileName() == QString::fromLatin1(".") ){ + ++it; + continue; + } + if( fi->isSymLink() ){ + QString file = fi->dirPath( true ) + "/" + fi->readLink(); + /* + * 5 tries to prevent dos attack + */ + for( int i = 0; i<=4; i++) { + QFileInfo info( file ); + if( !info.exists() ){ + addSymlink( currentMimeType, fi, TRUE ); + break; + }else if( info.isDir() ){ + addDir( currentMimeType, fi, + TRUE ); + break; + }else if( info.isFile() ){ + addFile( currentMimeType, fi, TRUE ); + break; + }else if( info.isSymLink() ){ + file = info.dirPath(true ) + "/" + info.readLink() ; + break; + }else if( i == 4){ + addSymlink( currentMimeType, fi ); + } + } + + }else if( fi->isDir() ){ + addDir( currentMimeType, fi ); + }else if( fi->isFile() ){ + addFile( currentMimeType, fi ); + } + ++it; + } // of while loop +} + diff --git a/libopie/ofileselector/olocallister.h b/libopie/ofileselector/olocallister.h new file mode 100644 index 0000000..0a06102 --- a/dev/null +++ b/libopie/ofileselector/olocallister.h @@ -0,0 +1,14 @@ +#ifndef OPIE_LOCAL_LISTER +#define OPIE_LOCAL_LISTER + +#include "olister.h" + +class OLocalLister : public OLister { +public: + OLocalLister( OFileSelector* ); + ~OLocalLister(); + void reparse( const QString& path ); + QMap<QString, QStringList> mimeTypes(const QString& dir ); +}; + +#endif diff --git a/libopie/ofileselector/olocallister.h~ b/libopie/ofileselector/olocallister.h~ new file mode 100644 index 0000000..a284b6e --- a/dev/null +++ b/libopie/ofileselector/olocallister.h~ @@ -0,0 +1,14 @@ +#ifndef OPIE_LOCAL_LISTER +#define OPIE_LOCAL_LISTER + +#include "olister.h" + +class OLocalLister : public OLister { +public: + OLocalLister( OFileSelector* ); + ~OLocalLister(); + void reparse( const QString& path ); + QMap<QString, QString> mimeTypes(const QString& dir ); +}; + +#endif diff --git a/libopie/ofileselector/olocallister.o b/libopie/ofileselector/olocallister.o Binary files differnew file mode 100644 index 0000000..1a4685d --- a/dev/null +++ b/libopie/ofileselector/olocallister.o |