summaryrefslogtreecommitdiff
path: root/libopie/ofileselector/opixmapprovider.cpp
blob: b363e01436f1ff6a73ad6be9b353641fab831bfd (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
#include <qfileinfo.h>

#include <qpe/mimetype.h>
#include <qpe/resource.h>

#include "opixmapprovider.h"



OPixmapProvider::OPixmapProvider( OFileSelector* sel )
    : m_sel( sel ){
}
OPixmapProvider::~OPixmapProvider() {
}
QPixmap OPixmapProvider::pixmap( int t, const QString& ,
                                 QFileInfo* info, bool isL ) {
    QPixmap pix;
    bool sy = t & Symlink ? true : false;
    switch (t ) {
    case File:
        pix = file( info, sy, isL );
        break;
    case Dir:
        pix = dir( info, sy, isL );
        break;
    case Symlink:
        pix =  sym( info, isL );
        break;
    }
    return pix;

}
QPixmap OPixmapProvider::pixmap( int t, const QString& mime,
                                 const QString& dir, const QString& file,
                                 bool isL) {
    QFileInfo *inf = new QFileInfo( dir + "/" + file );
    QPixmap pix = pixmap( t, mime, inf, isL );
    delete inf;
    return pix;
}
OFileSelector* OPixmapProvider::selector() {
    return m_sel;
}
QPixmap OPixmapProvider::file( QFileInfo* inf,  bool , bool  ) {
    MimeType type( inf->absFilePath() );
    QPixmap pix = type.pixmap();

    if ( pix.isNull() )
        pix = Resource::loadPixmap( "UnknownDocument-14");

    if ( (selector()->mode() == OFileSelector::Open &&
          !inf->isReadable() ) ||
         (selector()->mode() == OFileSelector::Save &&
          !inf->isWritable() ) ) {
        pix = Resource::loadPixmap( "locked" );
    }
    return pix;

}
QPixmap OPixmapProvider::dir( QFileInfo* inf, bool sym, bool  ) {
    QPixmap pix;
    /*
     * look at selector()->mode() and determine
     * if a dir is locked
     */
    if ( (selector()->mode() == OFileSelector::Open &&
          !inf->isReadable() ) ||
         (selector()->mode() == OFileSelector::Save &&
          !inf->isWritable() ) ) {
        if ( sym )
            pix = selector()->pixmap("symlinkedlocked");
        else
            pix = Resource::loadPixmap("lockedfolder");
    }else {
        pix = sym ? selector()->pixmap("lockedfolder") :
              Resource::loadPixmap("folder");

    }
    return pix;
}
QPixmap OPixmapProvider::sym( QFileInfo* , bool  ) {
    return Resource::loadPixmap("opie/symlink");
}