author | zecke <zecke> | 2002-10-05 20:49:38 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-05 20:49:38 (UTC) |
commit | 19c0a4610292a95281a64655cef9c2d695a214dc (patch) (unidiff) | |
tree | dde4afda2629a6e10d545d9492ada7b43e431ee7 /libopie | |
parent | d7f9d00fcc9261db9c4af4f1b4afde9d50e8a2a2 (diff) | |
download | opie-19c0a4610292a95281a64655cef9c2d695a214dc.zip opie-19c0a4610292a95281a64655cef9c2d695a214dc.tar.gz opie-19c0a4610292a95281a64655cef9c2d695a214dc.tar.bz2 |
more steps to make ofileselector modular
We now got the API for a factory so switching should work in future
and we now got a OPixmapProvider which provides us with pixmaps....
So an ImageViewer could install a differen OPixmapProvider
and a different OFileView to make Previewing
work
-rw-r--r-- | libopie/ofileselector/ofilefactory.cpp | 40 | ||||
-rw-r--r-- | libopie/ofileselector/ofilefactory.h | 32 | ||||
-rw-r--r-- | libopie/ofileselector/ofilelistview.cpp | 41 | ||||
-rw-r--r-- | libopie/ofileselector/ofilelistview.h | 20 | ||||
-rw-r--r-- | libopie/ofileselector/ofileview.h | 22 | ||||
-rw-r--r-- | libopie/ofileselector/olister.cpp | 48 | ||||
-rw-r--r-- | libopie/ofileselector/olister.h | 4 | ||||
-rw-r--r-- | libopie/ofileselector/opixmapprovider.cpp | 83 | ||||
-rw-r--r-- | libopie/ofileselector/opixmapprovider.h | 41 |
9 files changed, 284 insertions, 47 deletions
diff --git a/libopie/ofileselector/ofilefactory.cpp b/libopie/ofileselector/ofilefactory.cpp new file mode 100644 index 0000000..f752149 --- a/dev/null +++ b/libopie/ofileselector/ofilefactory.cpp | |||
@@ -0,0 +1,40 @@ | |||
1 | #include "ofilefactory.h" | ||
2 | |||
3 | OFileFactory::OFileFactory() { | ||
4 | } | ||
5 | OFileFactory::~OFileFactory() { | ||
6 | } | ||
7 | QStringList OFileFactory::lister()const { | ||
8 | QStringList list; | ||
9 | QMap<QString, listerFact>::ConstIterator it; | ||
10 | for ( it = m_lister.begin(); it != m_lister.end(); ++it ) { | ||
11 | list << (*it); | ||
12 | } | ||
13 | return list; | ||
14 | } | ||
15 | QStringList OFileFactory::views()const { | ||
16 | QStringList list; | ||
17 | |||
18 | |||
19 | return list; | ||
20 | } | ||
21 | OFileView* OFileFactory::view( const QString& name, | ||
22 | OFileSelector*, QWidget* ) { | ||
23 | |||
24 | } | ||
25 | OLister* OFileFactory::lister(const QString&, OFileSelector*) { | ||
26 | |||
27 | } | ||
28 | void OFileFactory::addLister( const QString&, listerFact fact ) { | ||
29 | |||
30 | } | ||
31 | void OFileFactory::addView( const QString&, viewFact fact ) { | ||
32 | |||
33 | |||
34 | } | ||
35 | void OFileFactory::removeLister( const QString& ) { | ||
36 | |||
37 | } | ||
38 | void OFileFactory::removeView( const QString& ) { | ||
39 | |||
40 | } | ||
diff --git a/libopie/ofileselector/ofilefactory.h b/libopie/ofileselector/ofilefactory.h new file mode 100644 index 0000000..96fb00d --- a/dev/null +++ b/libopie/ofileselector/ofilefactory.h | |||
@@ -0,0 +1,32 @@ | |||
1 | #ifndef OFILE_FACTORY_H | ||
2 | #define OFILE_FACTORY_H | ||
3 | |||
4 | #include "olister.h" | ||
5 | #include "ofileview.h" | ||
6 | class OFileFactory { | ||
7 | public: | ||
8 | typedef OLister* (*listerFact)(OFileSelector*); | ||
9 | typedef OFileView* (*viewFact)(OFileSelector*, QWidget*); | ||
10 | OFileFactory(); | ||
11 | ~OFileFactory(); | ||
12 | |||
13 | QStringList lister()const; | ||
14 | QStringList views()const; | ||
15 | |||
16 | OFileView* view( const QString& name, OFileSelector*, QWidget* ); | ||
17 | OLister* lister( const QString& name, OFileSelector* ); | ||
18 | |||
19 | void addLister( const QString&, listerFact fact ); | ||
20 | void addView( const QString&, viewFact ); | ||
21 | |||
22 | void removeLister( const QString& ); | ||
23 | void removeView( const QString& ); | ||
24 | |||
25 | private: | ||
26 | QMap<QString, listerFact> m_lister; | ||
27 | QMap<QString, viewFact> m_view; | ||
28 | |||
29 | }; | ||
30 | |||
31 | |||
32 | #endif | ||
diff --git a/libopie/ofileselector/ofilelistview.cpp b/libopie/ofileselector/ofilelistview.cpp index bb15764..691bf42 100644 --- a/libopie/ofileselector/ofilelistview.cpp +++ b/libopie/ofileselector/ofilelistview.cpp | |||
@@ -40,86 +40,71 @@ OFileListView::OFileListView( QWidget* parent, OFileSelector* sel) | |||
40 | OFileListView::~OFileListView() { | 40 | OFileListView::~OFileListView() { |
41 | 41 | ||
42 | } | 42 | } |
43 | void OFileListView::clear() { | 43 | void OFileListView::clear() { |
44 | QListView::clear(); | 44 | QListView::clear(); |
45 | } | 45 | } |
46 | void OFileListView::addFile( const QString&, | 46 | void OFileListView::addFile( const QPixmap& pix, |
47 | const QString&, | ||
47 | QFileInfo* info, | 48 | QFileInfo* info, |
48 | bool isSymlink ) { | 49 | bool isSymlink ) { |
49 | MimeType type( info->absFilePath() ); | ||
50 | QPixmap pix = type.pixmap(); | ||
51 | QString dir; | 50 | QString dir; |
52 | QString name; | 51 | QString name; |
53 | bool locked = false; | 52 | bool locked = false; |
54 | 53 | ||
55 | if( pix.isNull() ) | ||
56 | pix = Resource::loadPixmap( "UnknownDocument-14"); | ||
57 | |||
58 | dir = info->dirPath( true ); | 54 | dir = info->dirPath( true ); |
59 | 55 | ||
60 | if( isSymlink ) | 56 | if( isSymlink ) |
61 | name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); | 57 | name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); |
62 | else { | 58 | else { |
63 | name = info->fileName(); | 59 | name = info->fileName(); |
64 | if( ( selector()->mode() == OFileSelector::Open && !info->isReadable() ) || | 60 | if( ( selector()->mode() == OFileSelector::Open && !info->isReadable() ) || |
65 | ( selector()->mode() == OFileSelector::Save && !info->isWritable() ) ){ | 61 | ( selector()->mode() == OFileSelector::Save && !info->isWritable() ) ){ |
66 | 62 | ||
67 | locked = true; pix = Resource::loadPixmap("locked"); | 63 | locked = true; |
68 | } | 64 | } |
69 | } | 65 | } |
70 | new OFileSelectorItem( this, pix, name, | 66 | new OFileSelectorItem( this, pix, name, |
71 | info->lastModified().toString(), | 67 | info->lastModified().toString(), |
72 | QString::number( info->size() ), | 68 | QString::number( info->size() ), |
73 | dir, locked ); | 69 | dir, locked ); |
74 | } | 70 | } |
75 | void OFileListView::addFile( const QString& /*mime*/, const QString& /*dir*/, | 71 | void OFileListView::addFile( const QPixmap&, |
72 | const QString& /*mime*/, const QString& /*dir*/, | ||
76 | const QString& /*file*/, bool /*isSyml*/ ) { | 73 | const QString& /*file*/, bool /*isSyml*/ ) { |
77 | 74 | ||
78 | } | 75 | } |
79 | void OFileListView::addDir( const QString&, | 76 | void OFileListView::addDir( const QPixmap& pix, const QString&, |
80 | QFileInfo* info, bool symlink ) { | 77 | QFileInfo* info, bool symlink ) { |
81 | 78 | ||
82 | bool locked = false; | 79 | bool locked = false; |
83 | QString name; | 80 | QString name; |
84 | QPixmap pix; | ||
85 | |||
86 | if( ( selector()->mode() == OFileSelector::Open && !info->isReadable() ) || | ||
87 | ( selector()->mode() == OFileSelector::Save && !info->isWritable() ) ){ | ||
88 | |||
89 | locked = true; | ||
90 | |||
91 | if( symlink ) | ||
92 | pix = selector()->pixmap("symlinkedlocked"); | ||
93 | else | ||
94 | pix = Resource::loadPixmap("lockedfolder"); | ||
95 | |||
96 | }else { // readable | ||
97 | pix = symlink ? selector()->pixmap("dirsymlink") : Resource::loadPixmap("folder") ; | ||
98 | } | ||
99 | 81 | ||
100 | name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ; | 82 | name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ; |
101 | 83 | ||
102 | new OFileSelectorItem( this, pix, name, | 84 | new OFileSelectorItem( this, pix, name, |
103 | info->lastModified().toString(), | 85 | info->lastModified().toString(), |
104 | QString::number( info->size() ), | 86 | QString::number( info->size() ), |
105 | info->dirPath( true ), locked, | 87 | info->dirPath( true ), locked, |
106 | true ); | 88 | true ); |
107 | 89 | ||
108 | } | 90 | } |
109 | void OFileListView::addDir( const QString& /*mime*/, const QString& /*dir*/, | 91 | void OFileListView::addDir( const QPixmap&, |
92 | const QString& /*mime*/, const QString& /*dir*/, | ||
110 | const QString& /*file*/, bool ) { | 93 | const QString& /*file*/, bool ) { |
111 | 94 | ||
112 | } | 95 | } |
113 | void OFileListView::addSymlink( const QString& /*mime*/, | 96 | void OFileListView::addSymlink( const QPixmap&, |
97 | const QString& /*mime*/, | ||
114 | QFileInfo* /*info*/, | 98 | QFileInfo* /*info*/, |
115 | bool /*isSym*/ ) { | 99 | bool /*isSym*/ ) { |
116 | 100 | ||
117 | } | 101 | } |
118 | void OFileListView::addSymlink( const QString& /*mime*/, const QString& /*path*/, | 102 | void OFileListView::addSymlink(const QPixmap&, |
119 | const QString& /*file*/, bool /*isSym*/ ) { | 103 | const QString& /*m*/, const QString& /*path*/, |
104 | const QString& /*file*/, bool /*isSym*/ ) { | ||
120 | 105 | ||
121 | } | 106 | } |
122 | void OFileListView::cd( const QString& ) { | 107 | void OFileListView::cd( const QString& ) { |
123 | 108 | ||
124 | } | 109 | } |
125 | QWidget* OFileListView::widget() { | 110 | QWidget* OFileListView::widget() { |
diff --git a/libopie/ofileselector/ofilelistview.h b/libopie/ofileselector/ofilelistview.h index a83d70d..c8cdfd1 100644 --- a/libopie/ofileselector/ofilelistview.h +++ b/libopie/ofileselector/ofilelistview.h | |||
@@ -1,37 +1,45 @@ | |||
1 | #ifndef OPIE_FILE_LIST_VIEW_H | 1 | #ifndef OPIE_FILE_LIST_VIEW_H |
2 | #define OPIE_FILE_LIST_VIEW_H | 2 | #define OPIE_FILE_LIST_VIEW_H |
3 | 3 | ||
4 | #include <qlistview.h> | 4 | #include <qlistview.h> |
5 | #include <qpixmap.h> | ||
5 | 6 | ||
6 | #include "ofileview.h" | 7 | #include "ofileview.h" |
7 | 8 | ||
8 | class OFileListView : public QListView, public OFileView { | 9 | class OFileListView : public QListView, public OFileView { |
9 | Q_OBJECT | 10 | Q_OBJECT |
10 | public: | 11 | public: |
11 | OFileListView( QWidget* parent, OFileSelector* ); | 12 | OFileListView( QWidget* parent, OFileSelector* ); |
12 | ~OFileListView(); | 13 | ~OFileListView(); |
13 | 14 | ||
14 | void clear(); | 15 | void clear(); |
15 | void addFile( const QString& mine, | 16 | void addFile( const QPixmap&, |
17 | const QString& mine, | ||
16 | QFileInfo* info, | 18 | QFileInfo* info, |
17 | bool isSymlink = FALSE ); | 19 | bool isSymlink = FALSE ); |
18 | 20 | ||
19 | void addFile( const QString& mime, | 21 | void addFile( const QPixmap&, |
22 | const QString& mime, | ||
20 | const QString& dir, | 23 | const QString& dir, |
21 | const QString& file, | 24 | const QString& file, |
22 | bool = false ); | 25 | bool = false ); |
23 | 26 | ||
24 | void addDir( const QString& mime, | 27 | void addDir( const QPixmap&, |
28 | const QString& mime, | ||
25 | QFileInfo* info, bool = FALSE ); | 29 | QFileInfo* info, bool = FALSE ); |
26 | void addDir( const QString& mime, const QString& dir, | 30 | |
31 | void addDir( const QPixmap&, | ||
32 | const QString& mime, const QString& dir, | ||
27 | const QString& file, bool = FALSE ); | 33 | const QString& file, bool = FALSE ); |
28 | 34 | ||
29 | void addSymlink( const QString& mime, | 35 | void addSymlink( const QPixmap&, |
36 | const QString& mime, | ||
30 | QFileInfo* info, bool = FALSE ); | 37 | QFileInfo* info, bool = FALSE ); |
31 | void addSymlink( const QString& mine, const QString& path, | 38 | void addSymlink( const QPixmap&, |
39 | const QString& mine, const QString& path, | ||
32 | const QString& file, bool isSymlink = FALSE ); | 40 | const QString& file, bool isSymlink = FALSE ); |
33 | void cd( const QString& path ); | 41 | void cd( const QString& path ); |
34 | QWidget* widget(); | 42 | QWidget* widget(); |
35 | void sort(); | 43 | void sort(); |
36 | 44 | ||
37 | QString selectedName()const ; | 45 | QString selectedName()const ; |
diff --git a/libopie/ofileselector/ofileview.h b/libopie/ofileselector/ofileview.h index a4b1748..d7ea4a2 100644 --- a/libopie/ofileselector/ofileview.h +++ b/libopie/ofileselector/ofileview.h | |||
@@ -50,28 +50,36 @@ class OFileView { | |||
50 | public: | 50 | public: |
51 | OFileView( OFileSelector* ); | 51 | OFileView( OFileSelector* ); |
52 | OFileView(); | 52 | OFileView(); |
53 | virtual ~OFileView(); | 53 | virtual ~OFileView(); |
54 | 54 | ||
55 | virtual void clear() = 0; | 55 | virtual void clear() = 0; |
56 | virtual void addFile(const QString &mine, | 56 | virtual void addFile(const QPixmap&, |
57 | const QString &mine, | ||
57 | QFileInfo *info, | 58 | QFileInfo *info, |
58 | bool isSymlink = FALSE ) = 0; | 59 | bool isSymlink = FALSE ) = 0; |
59 | virtual void addFile(const QString& mine, const QString& dir, | 60 | |
61 | virtual void addFile(const QPixmap&, | ||
62 | const QString& mine, const QString& dir, | ||
60 | const QString& file, bool = FALSE ) = 0; | 63 | const QString& file, bool = FALSE ) = 0; |
61 | 64 | ||
62 | virtual void addDir (const QString &mine, | 65 | virtual void addDir (const QPixmap&, |
66 | const QString &mine, | ||
63 | QFileInfo *info, | 67 | QFileInfo *info, |
64 | bool isSymlink = FALSE ) = 0; | 68 | bool isSymlink = FALSE ) = 0; |
65 | virtual void addDir (const QString& mine, const QString& dir, | 69 | virtual void addDir (const QPixmap&, |
70 | const QString& mine, const QString& dir, | ||
66 | const QString& file, bool = FALSE) = 0; | 71 | const QString& file, bool = FALSE) = 0; |
67 | 72 | ||
68 | virtual void addSymlink(const QString &mime, | 73 | virtual void addSymlink(const QPixmap&, |
74 | const QString &mime, | ||
69 | QFileInfo *info, | 75 | QFileInfo *info, |
70 | bool isSymlink = FALSE ) = 0; | 76 | bool isSymlink = FALSE ) = 0; |
71 | virtual void addSymlink(const QString& mine, | 77 | |
78 | virtual void addSymlink(const QPixmap&, | ||
79 | const QString& mine, | ||
72 | const QString& path, | 80 | const QString& path, |
73 | const QString& file, | 81 | const QString& file, |
74 | bool isSymlink = FALSE ) = 0; | 82 | bool isSymlink = FALSE ) = 0; |
75 | 83 | ||
76 | virtual void cd(const QString &path ) = 0; | 84 | virtual void cd(const QString &path ) = 0; |
77 | virtual QWidget* widget() = 0; | 85 | virtual QWidget* widget() = 0; |
@@ -88,12 +96,14 @@ protected: | |||
88 | 96 | ||
89 | void fileSelected(const QString &); | 97 | void fileSelected(const QString &); |
90 | void fileSelected(const DocLnk & ); | 98 | void fileSelected(const DocLnk & ); |
91 | void contextMenu(); | 99 | void contextMenu(); |
92 | void changedDir(const QString &); | 100 | void changedDir(const QString &); |
93 | void changedDir(const QDir & ); | 101 | void changedDir(const QDir & ); |
102 | |||
103 | /* updates the file name line of the FileSelector */ | ||
94 | void updateLine( const QString& ); | 104 | void updateLine( const QString& ); |
95 | OFileSelector* selector()const; | 105 | OFileSelector* selector()const; |
96 | 106 | ||
97 | private: | 107 | private: |
98 | OFileSelector* m_sel; | 108 | OFileSelector* m_sel; |
99 | }; | 109 | }; |
diff --git a/libopie/ofileselector/olister.cpp b/libopie/ofileselector/olister.cpp index 6c43043..b6b03cd 100644 --- a/libopie/ofileselector/olister.cpp +++ b/libopie/ofileselector/olister.cpp | |||
@@ -1,72 +1,106 @@ | |||
1 | #include "olister.h" | 1 | #include "olister.h" |
2 | #include "ofileview.h" | 2 | #include "ofileview.h" |
3 | #include "opixmapprovider.h" | ||
3 | #include "ofileselector.h" | 4 | #include "ofileselector.h" |
4 | 5 | ||
5 | 6 | ||
6 | OLister::OLister( OFileSelector* view) | 7 | OLister::OLister( OFileSelector* view) |
7 | : m_view( view ) | 8 | : m_view( view ) |
8 | { | 9 | { |
10 | m_prov = new OPixmapProvider( view ); | ||
9 | } | 11 | } |
10 | OLister::~OLister() { | 12 | OLister::~OLister() { |
13 | delete m_prov; | ||
14 | } | ||
15 | void OLister::setPixmapProvider( OPixmapProvider* prov ) { | ||
16 | delete m_prov; | ||
17 | m_prov = prov; | ||
11 | } | 18 | } |
12 | bool OLister::showFiles()const { | 19 | bool OLister::showFiles()const { |
13 | return m_view->showFiles(); | 20 | return m_view->showFiles(); |
14 | } | 21 | } |
15 | bool OLister::showDirs()const { | 22 | bool OLister::showDirs()const { |
16 | return m_view->showDirs(); | 23 | return m_view->showDirs(); |
17 | } | 24 | } |
18 | void OLister::addFile( const QString& mine, | 25 | void OLister::addFile( const QString& mine, |
19 | QFileInfo* info, | 26 | QFileInfo* info, |
20 | bool isSymlink ) { | 27 | bool isSymlink ) { |
21 | view()->currentView()->addFile( mine, | 28 | int t = isSymlink ? OPixmapProvider::File | OPixmapProvider::Symlink : |
29 | OPixmapProvider::File; | ||
30 | QPixmap pix = provider()->pixmap(t, mine, | ||
31 | info); | ||
32 | view()->currentView()->addFile( pix, | ||
33 | mine, | ||
22 | info, | 34 | info, |
23 | isSymlink ); | 35 | isSymlink ); |
24 | } | 36 | } |
25 | void OLister::addFile( const QString& mine, | 37 | void OLister::addFile( const QString& mine, |
26 | const QString& path, | 38 | const QString& path, |
27 | const QString& file, | 39 | const QString& file, |
28 | bool isSymlink ) { | 40 | bool isSymlink ) { |
29 | view()->currentView()->addFile( mine, | 41 | int t = isSymlink ? OPixmapProvider::File | OPixmapProvider::Symlink : |
42 | OPixmapProvider::File; | ||
43 | |||
44 | QPixmap pix = provider()->pixmap(t, mine, path, file ); | ||
45 | view()->currentView()->addFile( pix, | ||
46 | mine, | ||
30 | path, | 47 | path, |
31 | file, | 48 | file, |
32 | isSymlink ); | 49 | isSymlink ); |
33 | } | 50 | } |
34 | void OLister::addDir( const QString& mine, | 51 | void OLister::addDir( const QString& mine, |
35 | QFileInfo* info, | 52 | QFileInfo* info, |
36 | bool isSymlink ) { | 53 | bool isSymlink ) { |
37 | 54 | int t = isSymlink ? OPixmapProvider::Dir | OPixmapProvider::Symlink : | |
38 | view()->currentView()->addDir( mine, | 55 | OPixmapProvider::Dir; |
56 | QPixmap pix = provider()->pixmap(t, mine, info ); | ||
57 | view()->currentView()->addDir( pix, | ||
58 | mine, | ||
39 | info, | 59 | info, |
40 | isSymlink ); | 60 | isSymlink ); |
41 | } | 61 | } |
42 | void OLister::addDir( const QString& mine, | 62 | void OLister::addDir( const QString& mine, |
43 | const QString& path, | 63 | const QString& path, |
44 | const QString& dir, | 64 | const QString& dir, |
45 | bool isSymlink ) { | 65 | bool isSymlink ) { |
46 | view()->currentView()->addDir( mine, | 66 | |
67 | int t = isSymlink ? OPixmapProvider::Dir | OPixmapProvider::Symlink : | ||
68 | OPixmapProvider::Dir; | ||
69 | QPixmap pix = provider()->pixmap(t, mine, path, dir ); | ||
70 | |||
71 | view()->currentView()->addDir( pix, | ||
72 | mine, | ||
47 | path, | 73 | path, |
48 | dir, | 74 | dir, |
49 | isSymlink ); | 75 | isSymlink ); |
50 | } | 76 | } |
51 | void OLister::addSymlink( const QString& mine, | 77 | void OLister::addSymlink( const QString& mine, |
52 | QFileInfo* info, | 78 | QFileInfo* info, |
53 | bool isSymlink ) { | 79 | bool isSymlink ) { |
54 | view()->currentView()->addSymlink( mine, | 80 | QPixmap pix = provider()->pixmap( OPixmapProvider::Symlink, mine, info ); |
81 | view()->currentView()->addSymlink( pix, | ||
82 | mine, | ||
55 | info, | 83 | info, |
56 | isSymlink ); | 84 | isSymlink ); |
57 | } | 85 | } |
58 | void OLister::addSymlink( const QString& mine, | 86 | void OLister::addSymlink( const QString& mine, |
59 | const QString& path, | 87 | const QString& path, |
60 | const QString& name, | 88 | const QString& name, |
61 | bool isSymlink ) { | 89 | bool isSymlink ) { |
62 | view()->currentView()->addSymlink( mine, | 90 | QPixmap pix = provider()->pixmap( OPixmapProvider::Symlink, mine, |
91 | path, name ); | ||
92 | view()->currentView()->addSymlink( pix, | ||
93 | mine, | ||
63 | path, | 94 | path, |
64 | name, | 95 | name, |
65 | isSymlink ); | 96 | isSymlink ); |
66 | } | 97 | } |
67 | OFileSelector* OLister::view() { | 98 | OFileSelector* OLister::view() { |
68 | return m_view; | 99 | return m_view; |
69 | } | 100 | } |
101 | OPixmapProvider* OLister::provider() { | ||
102 | return m_prov; | ||
103 | } | ||
70 | bool OLister::compliesMime( const QString& mime ) { | 104 | bool OLister::compliesMime( const QString& mime ) { |
71 | return view()->compliesMime( mime ); | 105 | return view()->compliesMime( mime ); |
72 | } | 106 | } |
diff --git a/libopie/ofileselector/olister.h b/libopie/ofileselector/olister.h index ef61cab..0885525 100644 --- a/libopie/ofileselector/olister.h +++ b/libopie/ofileselector/olister.h | |||
@@ -3,12 +3,13 @@ | |||
3 | 3 | ||
4 | #include <qfileinfo.h> | 4 | #include <qfileinfo.h> |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qstringlist.h> | 7 | #include <qstringlist.h> |
8 | 8 | ||
9 | class OPixmapProvider; | ||
9 | class OFileSelector; | 10 | class OFileSelector; |
10 | /** | 11 | /** |
11 | * lister is something like KIO but very | 12 | * lister is something like KIO but very |
12 | * very basic and currently only for | 13 | * very basic and currently only for |
13 | * populating our views. | 14 | * populating our views. |
14 | * This is a base class which needs to be implemented. | 15 | * This is a base class which needs to be implemented. |
@@ -21,12 +22,13 @@ public: | |||
21 | virtual void reparse(const QString& path) = 0; | 22 | virtual void reparse(const QString& path) = 0; |
22 | 23 | ||
23 | /** | 24 | /** |
24 | * return a list of available mimetypes | 25 | * return a list of available mimetypes |
25 | */ | 26 | */ |
26 | virtual QMap<QString, QStringList> mimeTypes( const QString& dir ) = 0; | 27 | virtual QMap<QString, QStringList> mimeTypes( const QString& dir ) = 0; |
28 | void setPixmapProvider( OPixmapProvider* ); | ||
27 | 29 | ||
28 | protected: | 30 | protected: |
29 | bool showFiles()const; | 31 | bool showFiles()const; |
30 | bool showDirs()const; | 32 | bool showDirs()const; |
31 | bool compliesMime( const QString& mime ); | 33 | bool compliesMime( const QString& mime ); |
32 | void addFile( const QString& mine, | 34 | void addFile( const QString& mine, |
@@ -48,13 +50,15 @@ protected: | |||
48 | bool isSymlink = FALSE); | 50 | bool isSymlink = FALSE); |
49 | void addSymlink( const QString& mine, | 51 | void addSymlink( const QString& mine, |
50 | const QString& path, | 52 | const QString& path, |
51 | const QString& name, | 53 | const QString& name, |
52 | bool isSymlink = FALSE ); | 54 | bool isSymlink = FALSE ); |
53 | OFileSelector* view(); | 55 | OFileSelector* view(); |
56 | OPixmapProvider* provider(); | ||
54 | private: | 57 | private: |
55 | OFileSelector* m_view; | 58 | OFileSelector* m_view; |
59 | OPixmapProvider* m_prov; | ||
56 | 60 | ||
57 | 61 | ||
58 | }; | 62 | }; |
59 | 63 | ||
60 | #endif | 64 | #endif |
diff --git a/libopie/ofileselector/opixmapprovider.cpp b/libopie/ofileselector/opixmapprovider.cpp new file mode 100644 index 0000000..b363e01 --- a/dev/null +++ b/libopie/ofileselector/opixmapprovider.cpp | |||
@@ -0,0 +1,83 @@ | |||
1 | #include <qfileinfo.h> | ||
2 | |||
3 | #include <qpe/mimetype.h> | ||
4 | #include <qpe/resource.h> | ||
5 | |||
6 | #include "opixmapprovider.h" | ||
7 | |||
8 | |||
9 | |||
10 | OPixmapProvider::OPixmapProvider( OFileSelector* sel ) | ||
11 | : m_sel( sel ){ | ||
12 | } | ||
13 | OPixmapProvider::~OPixmapProvider() { | ||
14 | } | ||
15 | QPixmap OPixmapProvider::pixmap( int t, const QString& , | ||
16 | QFileInfo* info, bool isL ) { | ||
17 | QPixmap pix; | ||
18 | bool sy = t & Symlink ? true : false; | ||
19 | switch (t ) { | ||
20 | case File: | ||
21 | pix = file( info, sy, isL ); | ||
22 | break; | ||
23 | case Dir: | ||
24 | pix = dir( info, sy, isL ); | ||
25 | break; | ||
26 | case Symlink: | ||
27 | pix = sym( info, isL ); | ||
28 | break; | ||
29 | } | ||
30 | return pix; | ||
31 | |||
32 | } | ||
33 | QPixmap OPixmapProvider::pixmap( int t, const QString& mime, | ||
34 | const QString& dir, const QString& file, | ||
35 | bool isL) { | ||
36 | QFileInfo *inf = new QFileInfo( dir + "/" + file ); | ||
37 | QPixmap pix = pixmap( t, mime, inf, isL ); | ||
38 | delete inf; | ||
39 | return pix; | ||
40 | } | ||
41 | OFileSelector* OPixmapProvider::selector() { | ||
42 | return m_sel; | ||
43 | } | ||
44 | QPixmap OPixmapProvider::file( QFileInfo* inf, bool , bool ) { | ||
45 | MimeType type( inf->absFilePath() ); | ||
46 | QPixmap pix = type.pixmap(); | ||
47 | |||
48 | if ( pix.isNull() ) | ||
49 | pix = Resource::loadPixmap( "UnknownDocument-14"); | ||
50 | |||
51 | if ( (selector()->mode() == OFileSelector::Open && | ||
52 | !inf->isReadable() ) || | ||
53 | (selector()->mode() == OFileSelector::Save && | ||
54 | !inf->isWritable() ) ) { | ||
55 | pix = Resource::loadPixmap( "locked" ); | ||
56 | } | ||
57 | return pix; | ||
58 | |||
59 | } | ||
60 | QPixmap OPixmapProvider::dir( QFileInfo* inf, bool sym, bool ) { | ||
61 | QPixmap pix; | ||
62 | /* | ||
63 | * look at selector()->mode() and determine | ||
64 | * if a dir is locked | ||
65 | */ | ||
66 | if ( (selector()->mode() == OFileSelector::Open && | ||
67 | !inf->isReadable() ) || | ||
68 | (selector()->mode() == OFileSelector::Save && | ||
69 | !inf->isWritable() ) ) { | ||
70 | if ( sym ) | ||
71 | pix = selector()->pixmap("symlinkedlocked"); | ||
72 | else | ||
73 | pix = Resource::loadPixmap("lockedfolder"); | ||
74 | }else { | ||
75 | pix = sym ? selector()->pixmap("lockedfolder") : | ||
76 | Resource::loadPixmap("folder"); | ||
77 | |||
78 | } | ||
79 | return pix; | ||
80 | } | ||
81 | QPixmap OPixmapProvider::sym( QFileInfo* , bool ) { | ||
82 | return Resource::loadPixmap("opie/symlink"); | ||
83 | } | ||
diff --git a/libopie/ofileselector/opixmapprovider.h b/libopie/ofileselector/opixmapprovider.h new file mode 100644 index 0000000..2165fdb --- a/dev/null +++ b/libopie/ofileselector/opixmapprovider.h | |||
@@ -0,0 +1,41 @@ | |||
1 | #ifndef OPIE_PIXMPAP_PROVIDER | ||
2 | #define OPIE_PIXMPAP_PROVIDER | ||
3 | |||
4 | #include <qpixmap.h> | ||
5 | |||
6 | #include "ofileselector.h" | ||
7 | |||
8 | /** | ||
9 | * This is a basic interface for a Pixmap provider | ||
10 | * it provides pixmaps for a URL | ||
11 | * So the OLocalLister provides mimetype icons | ||
12 | */ | ||
13 | class QFileInfo; | ||
14 | class OPixmapProvider { | ||
15 | public: | ||
16 | /* you can or these | ||
17 | * but File | Dir would be insane ;) | ||
18 | */ | ||
19 | enum Type { File = 0, Dir = 1, Symlink = 2 }; | ||
20 | OPixmapProvider( OFileSelector* sel ); | ||
21 | virtual ~OPixmapProvider(); | ||
22 | |||
23 | virtual QPixmap pixmap( int t, const QString& mime, QFileInfo*, | ||
24 | bool isLocked = FALSE ); | ||
25 | virtual QPixmap pixmap( int t, const QString& mime, | ||
26 | const QString& dir, const QString& file, | ||
27 | bool isLocked = FALSE ); | ||
28 | |||
29 | protected: | ||
30 | OFileSelector* selector(); | ||
31 | private: | ||
32 | QPixmap file( QFileInfo*, | ||
33 | bool sym, bool is ); | ||
34 | QPixmap dir ( QFileInfo*, | ||
35 | bool sym, bool is ); | ||
36 | QPixmap sym ( QFileInfo*, | ||
37 | bool is ); | ||
38 | OFileSelector* m_sel; | ||
39 | }; | ||
40 | |||
41 | #endif | ||