summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-05 20:49:38 (UTC)
committer zecke <zecke>2002-10-05 20:49:38 (UTC)
commit19c0a4610292a95281a64655cef9c2d695a214dc (patch) (unidiff)
treedde4afda2629a6e10d545d9492ada7b43e431ee7
parentd7f9d00fcc9261db9c4af4f1b4afde9d50e8a2a2 (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector/ofilefactory.cpp40
-rw-r--r--libopie/ofileselector/ofilefactory.h32
-rw-r--r--libopie/ofileselector/ofilelistview.cpp41
-rw-r--r--libopie/ofileselector/ofilelistview.h20
-rw-r--r--libopie/ofileselector/ofileview.h22
-rw-r--r--libopie/ofileselector/olister.cpp48
-rw-r--r--libopie/ofileselector/olister.h4
-rw-r--r--libopie/ofileselector/opixmapprovider.cpp83
-rw-r--r--libopie/ofileselector/opixmapprovider.h41
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
3OFileFactory::OFileFactory() {
4}
5OFileFactory::~OFileFactory() {
6}
7QStringList 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}
15QStringList OFileFactory::views()const {
16 QStringList list;
17
18
19 return list;
20}
21OFileView* OFileFactory::view( const QString& name,
22 OFileSelector*, QWidget* ) {
23
24}
25OLister* OFileFactory::lister(const QString&, OFileSelector*) {
26
27}
28void OFileFactory::addLister( const QString&, listerFact fact ) {
29
30}
31void OFileFactory::addView( const QString&, viewFact fact ) {
32
33
34}
35void OFileFactory::removeLister( const QString& ) {
36
37}
38void 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"
6class OFileFactory {
7public:
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
25private:
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
@@ -43,18 +43,14 @@ OFileListView::~OFileListView() {
43void OFileListView::clear() { 43void OFileListView::clear() {
44 QListView::clear(); 44 QListView::clear();
45} 45}
46void OFileListView::addFile( const QString&, 46void 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 )
@@ -64,7 +60,7 @@ void OFileListView::addFile( const QString&,
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,
@@ -72,30 +68,16 @@ void OFileListView::addFile( const QString&,
72 QString::number( info->size() ), 68 QString::number( info->size() ),
73 dir, locked ); 69 dir, locked );
74} 70}
75void OFileListView::addFile( const QString& /*mime*/, const QString& /*dir*/, 71void 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}
79void OFileListView::addDir( const QString&, 76void 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
@@ -106,17 +88,20 @@ void OFileListView::addDir( const QString&,
106 true ); 88 true );
107 89
108} 90}
109void OFileListView::addDir( const QString& /*mime*/, const QString& /*dir*/, 91void 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}
113void OFileListView::addSymlink( const QString& /*mime*/, 96void OFileListView::addSymlink( const QPixmap&,
97 const QString& /*mime*/,
114 QFileInfo* /*info*/, 98 QFileInfo* /*info*/,
115 bool /*isSym*/ ) { 99 bool /*isSym*/ ) {
116 100
117} 101}
118void OFileListView::addSymlink( const QString& /*mime*/, const QString& /*path*/, 102void 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}
122void OFileListView::cd( const QString& ) { 107void OFileListView::cd( const QString& ) {
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
@@ -2,6 +2,7 @@
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
@@ -12,23 +13,30 @@ public:
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();
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
@@ -53,22 +53,30 @@ public:
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;
@@ -91,6 +99,8 @@ protected:
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
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,13 +1,20 @@
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
6OLister::OLister( OFileSelector* view) 7OLister::OLister( OFileSelector* view)
7 : m_view( view ) 8 : m_view( view )
8{ 9{
10 m_prov = new OPixmapProvider( view );
9} 11}
10OLister::~OLister() { 12OLister::~OLister() {
13 delete m_prov;
14}
15void OLister::setPixmapProvider( OPixmapProvider* prov ) {
16 delete m_prov;
17 m_prov = prov;
11} 18}
12bool OLister::showFiles()const { 19bool OLister::showFiles()const {
13 return m_view->showFiles(); 20 return m_view->showFiles();
@@ -18,7 +25,12 @@ bool OLister::showDirs()const {
18void OLister::addFile( const QString& mine, 25void 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}
@@ -26,7 +38,12 @@ 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 );
@@ -34,8 +51,11 @@ void OLister::addFile( const QString& mine,
34void OLister::addDir( const QString& mine, 51void 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}
@@ -43,7 +63,13 @@ 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 );
@@ -51,7 +77,9 @@ void OLister::addDir( const QString& mine,
51void OLister::addSymlink( const QString& mine, 77void 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}
@@ -59,7 +87,10 @@ 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 );
@@ -67,6 +98,9 @@ void OLister::addSymlink( const QString& mine,
67OFileSelector* OLister::view() { 98OFileSelector* OLister::view() {
68 return m_view; 99 return m_view;
69} 100}
101OPixmapProvider* OLister::provider() {
102 return m_prov;
103}
70bool OLister::compliesMime( const QString& mime ) { 104bool 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
@@ -6,6 +6,7 @@
6#include <qstring.h> 6#include <qstring.h>
7#include <qstringlist.h> 7#include <qstringlist.h>
8 8
9class OPixmapProvider;
9class OFileSelector; 10class OFileSelector;
10/** 11/**
11 * lister is something like KIO but very 12 * lister is something like KIO but very
@@ -24,6 +25,7 @@ public:
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
28protected: 30protected:
29 bool showFiles()const; 31 bool showFiles()const;
@@ -51,8 +53,10 @@ protected:
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();
54private: 57private:
55 OFileSelector* m_view; 58 OFileSelector* m_view;
59 OPixmapProvider* m_prov;
56 60
57 61
58}; 62};
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
10OPixmapProvider::OPixmapProvider( OFileSelector* sel )
11 : m_sel( sel ){
12}
13OPixmapProvider::~OPixmapProvider() {
14}
15QPixmap 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}
33QPixmap 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}
41OFileSelector* OPixmapProvider::selector() {
42 return m_sel;
43}
44QPixmap 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}
60QPixmap 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}
81QPixmap 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 */
13class QFileInfo;
14class OPixmapProvider {
15public:
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
29protected:
30 OFileSelector* selector();
31private:
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