Diffstat (limited to 'libopie/ofileselector/olocallister.cpp~') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/ofileselector/olocallister.cpp~ | 97 |
1 files changed, 97 insertions, 0 deletions
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 @@ | |||
1 | #include <qdir.h> | ||
2 | #include <qfileinfo.h> | ||
3 | #include <qmap.h> | ||
4 | |||
5 | #include <qpe/mimetype.h> | ||
6 | |||
7 | #include "ofileselector.h" | ||
8 | #include "olocallister.h" | ||
9 | |||
10 | OLocalLister::OLocalLister( OFileSelector* file ) | ||
11 | : OLister( file ) | ||
12 | { | ||
13 | } | ||
14 | OLocalLister::~OLocalLister() { | ||
15 | } | ||
16 | |||
17 | QMap<QString, QString> OLocalLister::mimeTypes( const QString& curDir ) { | ||
18 | QMap<QString, QString> mimes; | ||
19 | |||
20 | // let's find possible mimetypes | ||
21 | QDir dir( curDir ); | ||
22 | dir.setFilter( QDir::Files | QDir::Readable ); | ||
23 | dir.setSorting( QDir::Size ); | ||
24 | |||
25 | const QFileInfoList *list = dir.entryInfoList(); | ||
26 | QFileInfoListIterator it( *list ); | ||
27 | QFileInfo *fi; | ||
28 | |||
29 | while( (fi=it.current() ) ) { | ||
30 | if( fi->extension() == QString::fromLatin1("desktop") ){ | ||
31 | ++it; | ||
32 | continue; | ||
33 | } | ||
34 | MimeType type( fi->absFilePath() ); | ||
35 | |||
36 | if( !mimes.contains( type.id() ) ){ | ||
37 | mimes.insert( type.id(), type.id() ); | ||
38 | } | ||
39 | |||
40 | ++it; | ||
41 | } | ||
42 | |||
43 | return mimes; | ||
44 | } | ||
45 | void OLocalLister::reparse( const QString& path ) { | ||
46 | QString currentMimeType; | ||
47 | QDir dir( path ); | ||
48 | |||
49 | dir.setSorting( view()->sorting() ); | ||
50 | dir.setFilter( view()->filter() ); | ||
51 | |||
52 | // now go through all files | ||
53 | const QFileInfoList *list = dir.entryInfoList(); | ||
54 | QFileInfoListIterator it( *list ); | ||
55 | QFileInfo *fi; | ||
56 | |||
57 | while( (fi=it.current() ) ){ | ||
58 | |||
59 | if( fi->fileName() == QString::fromLatin1("..") || | ||
60 | fi->fileName() == QString::fromLatin1(".") ){ | ||
61 | ++it; | ||
62 | continue; | ||
63 | } | ||
64 | if( fi->isSymLink() ){ | ||
65 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | ||
66 | /* | ||
67 | * 5 tries to prevent dos attack | ||
68 | */ | ||
69 | for( int i = 0; i<=4; i++) { | ||
70 | QFileInfo info( file ); | ||
71 | if( !info.exists() ){ | ||
72 | addSymlink( currentMimeType, fi, TRUE ); | ||
73 | break; | ||
74 | }else if( info.isDir() ){ | ||
75 | addDir( currentMimeType, fi, | ||
76 | TRUE ); | ||
77 | break; | ||
78 | }else if( info.isFile() ){ | ||
79 | addFile( currentMimeType, fi, TRUE ); | ||
80 | break; | ||
81 | }else if( info.isSymLink() ){ | ||
82 | file = info.dirPath(true ) + "/" + info.readLink() ; | ||
83 | break; | ||
84 | }else if( i == 4){ | ||
85 | addSymlink( currentMimeType, fi ); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | }else if( fi->isDir() ){ | ||
90 | addDir( currentMimeType, fi ); | ||
91 | }else if( fi->isFile() ){ | ||
92 | addFile( currentMimeType, fi ); | ||
93 | } | ||
94 | ++it; | ||
95 | } // of while loop | ||
96 | } | ||
97 | |||