summaryrefslogtreecommitdiff
path: root/libopie/ofileselector/olocallister.cpp
blob: 4d36d64e0df48d1c1849544b1d73d69421b09127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <qdir.h>
#include <qfileinfo.h>
#include <qmap.h>

#include <qpe/mimetype.h>

#include "ofileselector.h"
#include "ofileview.h"
#include "olocallister.h"

OLocalLister::OLocalLister( OFileSelector* file )
    : OLister( file )
{
    m_dir = QDir::homeDirPath();
}
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& pa ) {
    if (!pa.isEmpty() )
        m_dir = pa;

    QString currentMimeType;
    QDir dir( m_dir );

    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, QString::null, TRUE );
                    break;
                }else if( info.isDir() ){
                    if (!showDirs() )
                        break;

                    addDir( currentMimeType, fi, QString::null,
                            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, QString::null,  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
}
/* more accepting it code */
void OLocalLister::fileSelected( const QString& dir, const QString& file, const QString& ) {
    internFileSelected( dir + "/" + file );
}
void OLocalLister::changedDir( const QString& dir, const QString& file, const QString& ) {
    internChangedDir( dir + "/" + file );
}
/*
 * assemble the the Url now
 */
QString OLocalLister::selectedName()const {
    QString str = m_dir;
    QString name = lineEdit();

    if ( name.isEmpty() )
        name = view()->currentView()->selectedName();

    str += "/" + name;

    return str;
}
QStringList OLocalLister::selectedNames()const {
    QStringList list;
    list << selectedName();

    return list;
}