summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.cpp35
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.h5
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp66
-rw-r--r--libopie2/opieui/fileselector/ofileselector.h3
4 files changed, 89 insertions, 20 deletions
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp
index beb4d6c..ebce0ef 100644
--- a/libopie2/opieui/fileselector/ofiledialog.cpp
+++ b/libopie2/opieui/fileselector/ofiledialog.cpp
@@ -1,222 +1,255 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29 29
30/* OPIE */ 30/* OPIE */
31#include <opie2/ofiledialog.h> 31#include <opie2/ofiledialog.h>
32#include <qpe/applnk.h> 32#include <qpe/applnk.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35 35
36/* QT */ 36/* QT */
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qstring.h> 38#include <qstring.h>
39#include <qapplication.h> 39#include <qapplication.h>
40#include <qlayout.h> 40#include <qlayout.h>
41 41
42using namespace Opie::Ui; 42using namespace Opie::Ui;
43 43
44namespace 44namespace
45{ 45{
46/* 46/*
47 * helper functions to load the start dir 47 * helper functions to load the start dir
48 * and to save it 48 * and to save it
49 * helper to extract the dir out of a file name 49 * helper to extract the dir out of a file name
50 */ 50 */
51/** 51/**
52 * This method will use Config( argv[0] ); 52 * This method will use Config( argv[0] );
53 * @param key The group key used 53 * @param key The group key used
54 */ 54 */
55QString lastUsedDir( const QString& key ) 55QString lastUsedDir( const QString& key )
56{ 56{
57 if ( qApp->argc() < 1 ) 57 if ( qApp->argc() < 1 )
58 return QString::null; 58 return QString::null;
59 59
60 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname 60 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
61 cfg.setGroup( key ); 61 cfg.setGroup( key );
62 return cfg.readEntry("LastDir", QPEApplication::documentDir() ); 62 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
63} 63}
64 64
65void saveLastDir( const QString& key, const QString& file ) 65void saveLastDir( const QString& key, const QString& file )
66{ 66{
67 if ( qApp->argc() < 1 ) 67 if ( qApp->argc() < 1 )
68 return; 68 return;
69 69
70 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); 70 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
71 cfg.setGroup( key ); 71 cfg.setGroup( key );
72 QFileInfo inf( file ); 72 QFileInfo inf( file );
73 cfg.writeEntry("LastDir", inf.dirPath( true ) ); 73 if ( inf.isFile() )
74 cfg.writeEntry("LastDir", inf.dirPath( true ) );
75 else
76 cfg.writeEntry("LastDir", file );
74} 77}
75}; 78};
76 79
77/** 80/**
78 * This constructs a modal dialog 81 * This constructs a modal dialog
79 * 82 *
80 * @param caption The caption of the dialog 83 * @param caption The caption of the dialog
81 * @param wid The parent widget 84 * @param wid The parent widget
82 * @param mode The mode of the OFileSelector @see OFileSelector 85 * @param mode The mode of the OFileSelector @see OFileSelector
83 * @param selector The selector of the OFileSelector 86 * @param selector The selector of the OFileSelector
84 * @param dirName the dir or resource to start from 87 * @param dirName the dir or resource to start from
85 * @param fileName a proposed or existing filename 88 * @param fileName a proposed or existing filename
86 * @param mimetypes The mimeTypes 89 * @param mimetypes The mimeTypes
87 */ 90 */
88OFileDialog::OFileDialog(const QString &caption, 91OFileDialog::OFileDialog(const QString &caption,
89 QWidget *wid, int mode, int selector, 92 QWidget *wid, int mode, int selector,
90 const QString &dirName, 93 const QString &dirName,
91 const QString &fileName, 94 const QString &fileName,
92 const QMap<QString,QStringList>& mimetypes ) 95 const QMap<QString,QStringList>& mimetypes )
93 : QDialog( wid, "OFileDialog", true ) 96 : QDialog( wid, "OFileDialog", true )
94{ 97{
95 // QVBoxLayout *lay = new QVBoxLayout(this); 98 // QVBoxLayout *lay = new QVBoxLayout(this);
96 //showMaximized(); 99 //showMaximized();
97 QVBoxLayout *lay = new QVBoxLayout(this ); 100 QVBoxLayout *lay = new QVBoxLayout(this );
98 file = new OFileSelector(this , mode, selector, 101 file = new OFileSelector(this , mode, selector,
99 dirName, fileName, 102 dirName, fileName,
100 mimetypes ); 103 mimetypes );
101 lay->addWidget( file ); 104 lay->addWidget( file );
102 105
103 //lay->addWidget( file ); 106 //lay->addWidget( file );
104 //showFullScreen(); 107 //showFullScreen();
105 setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); 108 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
106 connect(file, SIGNAL(fileSelected(const QString&) ), 109 connect(file, SIGNAL(fileSelected(const QString&) ),
107 this, SLOT(slotFileSelected(const QString&) ) ); 110 this, SLOT(slotFileSelected(const QString&) ) );
108 connect(file, SIGNAL(ok() ), 111 connect(file, SIGNAL(ok() ),
109 this, SLOT(slotSelectorOk()) ) ; 112 this, SLOT(slotSelectorOk()) ) ;
110 113
111 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); 114 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
112 115
113#if 0 116#if 0
114 connect(file, SIGNAL(dirSelected(const QString&) ), 117 connect(file, SIGNAL(dirSelected(const QString&) ),
115 this, SLOT(slotDirSelected(const QString&) ) ); 118 this, SLOT(slotDirSelected(const QString&) ) );
116#endif 119#endif
117} 120}
118/** 121/**
119 * @returns the mimetype of the selected 122 * @returns the mimetype of the selected
120 * currently it return QString::null 123 * currently it return QString::null
121 */ 124 */
122QString OFileDialog::mimetype()const 125QString OFileDialog::mimetype()const
123{ 126{
124 return QString::null; 127 return QString::null;
125} 128}
126 129
127/** 130/**
128 * @return the fileName 131 * @return the fileName
129 */ 132 */
130QString OFileDialog::fileName()const 133QString OFileDialog::fileName()const
131{ 134{
132 return file->selectedName(); 135 return file->selectedName();
133} 136}
134 137
135/** 138/**
136 * return a DocLnk to the current file 139 * return a DocLnk to the current file
137 */ 140 */
138DocLnk OFileDialog::selectedDocument()const 141DocLnk OFileDialog::selectedDocument()const
139{ 142{
140 return file->selectedDocument(); 143 return file->selectedDocument();
141} 144}
142 145
143/** 146/**
144 * This opens up a filedialog in Open mode 147 * This opens up a filedialog in Open mode
145 * 148 *
146 * @param selector the Selector Mode 149 * @param selector the Selector Mode
147 * @param startDir Where to start from 150 * @param startDir Where to start from
148 * @param file A proposed filename 151 * @param file A proposed filename
149 * @param mimes A list of MimeTypes 152 * @param mimes A list of MimeTypes
150 * @param wid the parent 153 * @param wid the parent
151 * @param caption of the dialog if QString::null tr("Open") will be used 154 * @param caption of the dialog if QString::null tr("Open") will be used
152 * @return the fileName or QString::null 155 * @return the fileName or QString::null
153 */ 156 */
154QString OFileDialog::getOpenFileName(int selector, 157QString OFileDialog::getOpenFileName(int selector,
155 const QString &_startDir, 158 const QString &_startDir,
156 const QString &file, 159 const QString &file,
157 const MimeTypes &mimes, 160 const MimeTypes &mimes,
158 QWidget *wid, 161 QWidget *wid,
159 const QString &caption ) 162 const QString &caption )
160{ 163{
161 QString ret; 164 QString ret;
162 QString startDir = _startDir; 165 QString startDir = _startDir;
163 if (startDir.isEmpty() ) 166 if (startDir.isEmpty() )
164 startDir = lastUsedDir( "FileDialog-OPEN" ); 167 startDir = lastUsedDir( "FileDialog-OPEN" );
165 168
166 169
167 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, 170 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
168 wid, OFileSelector::Open, selector, startDir, file, mimes); 171 wid, OFileSelector::Open, selector, startDir, file, mimes);
169 dlg.showMaximized(); 172 dlg.showMaximized();
170 if( dlg.exec() ) 173 if( dlg.exec() )
171 { 174 {
172 ret = dlg.fileName(); 175 ret = dlg.fileName();
173 saveLastDir( "FileDialog-OPEN", ret ); 176 saveLastDir( "FileDialog-OPEN", ret );
174 } 177 }
175 178
176 return ret; 179 return ret;
177} 180}
178 181
179/** 182/**
180 * This opens up a file dialog in save mode 183 * This opens up a file dialog in save mode
181 * @see getOpenFileName 184 * @see getOpenFileName
182 */ 185 */
183QString OFileDialog::getSaveFileName(int selector, 186QString OFileDialog::getSaveFileName(int selector,
184 const QString &_startDir, 187 const QString &_startDir,
185 const QString &file, 188 const QString &file,
186 const MimeTypes &mimes, 189 const MimeTypes &mimes,
187 QWidget *wid, 190 QWidget *wid,
188 const QString &caption ) 191 const QString &caption )
189{ 192{
190 QString ret; 193 QString ret;
191 QString startDir = _startDir; 194 QString startDir = _startDir;
192 if (startDir.isEmpty() ) 195 if (startDir.isEmpty() )
193 startDir = lastUsedDir( "FileDialog-SAVE" ); 196 startDir = lastUsedDir( "FileDialog-SAVE" );
194 197
195 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, 198 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
196 wid, OFileSelector::Save, selector, startDir, file, mimes); 199 wid, OFileSelector::Save, selector, startDir, file, mimes);
197 dlg.showMaximized(); 200 dlg.showMaximized();
198 if( dlg.exec() ) 201 if( dlg.exec() )
199 { 202 {
200 ret = dlg.fileName(); 203 ret = dlg.fileName();
201 saveLastDir( "FileDialog-SAVE", ret ); 204 saveLastDir( "FileDialog-SAVE", ret );
202 } 205 }
203 206
204 return ret; 207 return ret;
205} 208}
206 209
210/**
211 * This opens up a filedialog in select directory mode
212 *
213 * @param selector the Selector Mode
214 * @param startDir Where to start from
215 * @param wid the parent
216 * @param caption of the dialog if QString::null tr("Open") will be used
217 * @return the directoryName or QString::null
218 */
219QString OFileDialog::getDirectory(int selector,
220 const QString &_startDir,
221 QWidget *wid,
222 const QString &caption )
223{
224 QString ret;
225 QString startDir = _startDir;
226 if ( startDir.isEmpty() )
227 startDir = lastUsedDir( "FileDialog-SELECTDIR" );
228
229 OFileDialog dlg( caption.isEmpty() ? tr( "Select Directory" ) : caption,
230 wid, OFileSelector::DirectorySelector, selector, startDir );
231 dlg.showMaximized();
232 if ( dlg.exec() )
233 {
234 ret = dlg.fileName();
235 saveLastDir( "FileDialog-SELECTDIR", ret );
236 }
237 return ret;
238}
239
207void OFileDialog::slotFileSelected(const QString & ) 240void OFileDialog::slotFileSelected(const QString & )
208{ 241{
209 accept(); 242 accept();
210} 243}
211 244
212void OFileDialog::slotSelectorOk( ) 245void OFileDialog::slotSelectorOk( )
213{ 246{
214 accept(); 247 accept();
215} 248}
216 249
217void OFileDialog::slotDirSelected(const QString &dir ) 250void OFileDialog::slotDirSelected(const QString &dir )
218{ 251{
219 setCaption( dir ); 252 setCaption( dir );
220 // if mode 253 // if mode
221 //accept(); 254 //accept();
222} 255}
diff --git a/libopie2/opieui/fileselector/ofiledialog.h b/libopie2/opieui/fileselector/ofiledialog.h
index dfecf3d..569f45c 100644
--- a/libopie2/opieui/fileselector/ofiledialog.h
+++ b/libopie2/opieui/fileselector/ofiledialog.h
@@ -1,110 +1,115 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 zecke <zecke@handhelds.org> 3             .=l. Copyright (c) 2002 zecke <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#ifndef OFILEDIALOG_H 29#ifndef OFILEDIALOG_H
30#define OFILEDIALOG_H 30#define OFILEDIALOG_H
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/ofileselector.h> 33#include <opie2/ofileselector.h>
34 34
35/* QT */ 35/* QT */
36#include <qdialog.h> 36#include <qdialog.h>
37 37
38namespace Opie { 38namespace Opie {
39namespace Ui { 39namespace Ui {
40 40
41/** 41/**
42 * This class places a OFileSelector inside a QDialog. 42 * This class places a OFileSelector inside a QDialog.
43 * It provides static method for letting a user chose 43 * It provides static method for letting a user chose
44 * a file for either opening or saving. 44 * a file for either opening or saving.
45 * Most of the time the c'tor will not be used instead using 45 * Most of the time the c'tor will not be used instead using
46 * the static member functions is prefered. 46 * the static member functions is prefered.
47 * 47 *
48 * <pre> 48 * <pre>
49 * QMap<QString, QStringList> mimeTypes; 49 * QMap<QString, QStringList> mimeTypes;
50 * QStringList types; 50 * QStringList types;
51 * types << "text[slash]* "; 51 * types << "text[slash]* ";
52 * mimeTypes.insert( tr("Text"), types ); 52 * mimeTypes.insert( tr("Text"), types );
53 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment 53 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment
54 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 54 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
55 * "foo","bar", mimeTypes); 55 * "foo","bar", mimeTypes);
56 * </pre> 56 * </pre>
57 * 57 *
58 * @short A small QDialog swalloing a FileSelector 58 * @short A small QDialog swalloing a FileSelector
59 * @see QDialog 59 * @see QDialog
60 * @see OFileSelector 60 * @see OFileSelector
61 * @version 0.1-unfinished 61 * @version 0.1-unfinished
62 * @author Holger Freyther ( zecke@handhelds.org ) 62 * @author Holger Freyther ( zecke@handhelds.org )
63 */ 63 */
64class OFileDialog : public QDialog 64class OFileDialog : public QDialog
65{ 65{
66 Q_OBJECT 66 Q_OBJECT
67public: 67public:
68 OFileDialog(const QString &caption, 68 OFileDialog(const QString &caption,
69 QWidget *, int mode, int selector, 69 QWidget *, int mode, int selector,
70 const QString &dirName, 70 const QString &dirName,
71 const QString &fileName = QString::null, 71 const QString &fileName = QString::null,
72 const MimeTypes &mimetypes = MimeTypes() ); 72 const MimeTypes &mimetypes = MimeTypes() );
73 QString mimetype() const; 73 QString mimetype() const;
74 QString fileName() const; 74 QString fileName() const;
75 DocLnk selectedDocument()const; 75 DocLnk selectedDocument()const;
76 76
77 // static methods 77 // static methods
78 static QString getOpenFileName(int selector, 78 static QString getOpenFileName(int selector,
79 const QString& startDir = QString::null, 79 const QString& startDir = QString::null,
80 const QString &fileName = QString::null, 80 const QString &fileName = QString::null,
81 const MimeTypes& mime = MimeTypes(), 81 const MimeTypes& mime = MimeTypes(),
82 QWidget *wid = 0, 82 QWidget *wid = 0,
83 const QString &caption = QString::null ); 83 const QString &caption = QString::null );
84 84
85 static QString getSaveFileName(int selector, 85 static QString getSaveFileName(int selector,
86 const QString& startDir = QString::null, 86 const QString& startDir = QString::null,
87 const QString& fileName = QString::null, 87 const QString& fileName = QString::null,
88 const MimeTypes& mimefilter = MimeTypes(), 88 const MimeTypes& mimefilter = MimeTypes(),
89 QWidget *wid = 0, 89 QWidget *wid = 0,
90 const QString &caption = QString::null ); 90 const QString &caption = QString::null );
91 91
92 static QString getDirectory(int selector,
93 const QString &startDir = QString::null,
94 QWidget *wid = 0,
95 const QString &caption = QString::null );
96
92 //let's OFileSelector catch up first 97 //let's OFileSelector catch up first
93 //static QString getExistingDirectory(const QString& startDir = QString::null, 98 //static QString getExistingDirectory(const QString& startDir = QString::null,
94 //QWidget *parent = 0, const QString& caption = QString::null ); 99 //QWidget *parent = 0, const QString& caption = QString::null );
95 100
96private: 101private:
97 class OFileDialogPrivate; 102 class OFileDialogPrivate;
98 OFileDialogPrivate *d; 103 OFileDialogPrivate *d;
99 OFileSelector *file; 104 OFileSelector *file;
100 105
101private slots: 106private slots:
102 void slotFileSelected( const QString & ); 107 void slotFileSelected( const QString & );
103 void slotDirSelected(const QString & ); 108 void slotDirSelected(const QString & );
104 void slotSelectorOk(); 109 void slotSelectorOk();
105}; 110};
106 111
107} 112}
108} 113}
109 114
110#endif 115#endif
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp
index b06defd..346eeae 100644
--- a/libopie2/opieui/fileselector/ofileselector.cpp
+++ b/libopie2/opieui/fileselector/ofileselector.cpp
@@ -239,946 +239,976 @@ OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap,
239 bool isLocked, bool isDir ) 239 bool isLocked, bool isDir )
240 : QListViewItem( view ) 240 : QListViewItem( view )
241{ 241{
242 setPixmap(0, pixmap ); 242 setPixmap(0, pixmap );
243 setText(1, path ); 243 setText(1, path );
244 setText(2, size ); 244 setText(2, size );
245 setText(3, date ); 245 setText(3, date );
246 m_isDir = isDir; 246 m_isDir = isDir;
247 m_dir = dir; 247 m_dir = dir;
248 m_locked = isLocked; 248 m_locked = isLocked;
249} 249}
250 250
251OFileSelectorItem::~OFileSelectorItem() 251OFileSelectorItem::~OFileSelectorItem()
252{ 252{
253} 253}
254 254
255bool OFileSelectorItem::isLocked()const 255bool OFileSelectorItem::isLocked()const
256{ 256{
257 return m_locked; 257 return m_locked;
258} 258}
259 259
260QString OFileSelectorItem::directory()const 260QString OFileSelectorItem::directory()const
261{ 261{
262 return m_dir; 262 return m_dir;
263} 263}
264 264
265bool OFileSelectorItem::isDir()const 265bool OFileSelectorItem::isDir()const
266{ 266{
267 return m_isDir; 267 return m_isDir;
268} 268}
269 269
270QString OFileSelectorItem::path()const 270QString OFileSelectorItem::path()const
271{ 271{
272 return text( 1 ); 272 return text( 1 );
273} 273}
274 274
275QString OFileSelectorItem::key( int id, bool )const 275QString OFileSelectorItem::key( int id, bool )const
276{ 276{
277 QString ke; 277 QString ke;
278 if( id == 0 || id == 1 ) 278 if( id == 0 || id == 1 )
279 { // name 279 { // name
280 if( m_isDir ) 280 if( m_isDir )
281 { 281 {
282 ke.append("0" ); 282 ke.append("0" );
283 ke.append( text(1) ); 283 ke.append( text(1) );
284 } 284 }
285 else 285 else
286 { 286 {
287 ke.append("1" ); 287 ke.append("1" );
288 ke.append( text(1) ); 288 ke.append( text(1) );
289 } 289 }
290 return ke; 290 return ke;
291 } 291 }
292 else 292 else
293 return text( id ); 293 return text( id );
294 294
295} 295}
296 296
297OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) 297OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel)
298 :QWidget( parent ), m_sel( sel ) 298 :QWidget( parent ), m_sel( sel )
299{ 299{
300 m_all = false; 300 m_all = false;
301 QVBoxLayout* lay = new QVBoxLayout( this ); 301 QVBoxLayout* lay = new QVBoxLayout( this );
302 m_currentDir = startDir; 302 m_currentDir = startDir;
303 303
304 /* 304 /*
305 * now we add a special bar 305 * now we add a special bar
306 * One Button For Up 306 * One Button For Up
307 * Home 307 * Home
308 * Doc 308 * Doc
309 * And a dropdown menu with FileSystems 309 * And a dropdown menu with FileSystems
310 * FUTURE: one to change dir with lineedit 310 * FUTURE: one to change dir with lineedit
311 * Bookmarks 311 * Bookmarks
312 * Create Dir 312 * Create Dir
313 */ 313 */
314 QHBox* box = new QHBox(this ); 314 QHBox* box = new QHBox(this );
315 box->setBackgroundMode( PaletteButton ); 315 box->setBackgroundMode( PaletteButton );
316 box->setSpacing( 0 ); 316 box->setSpacing( 0 );
317 317
318 QToolButton *btn = new QToolButton( box ); 318 QToolButton *btn = new QToolButton( box );
319 btn->setIconSet( Resource::loadIconSet("up") ); 319 btn->setIconSet( Resource::loadIconSet("up") );
320 connect(btn, SIGNAL(clicked() ), 320 connect(btn, SIGNAL(clicked() ),
321 this, SLOT( cdUP() ) ); 321 this, SLOT( cdUP() ) );
322 322
323 btn = new QToolButton( box ); 323 btn = new QToolButton( box );
324 btn->setIconSet( Resource::loadIconSet("home") ); 324 btn->setIconSet( Resource::loadIconSet("home") );
325 connect(btn, SIGNAL(clicked() ), 325 connect(btn, SIGNAL(clicked() ),
326 this, SLOT( cdHome() ) ); 326 this, SLOT( cdHome() ) );
327 327
328 btn = new QToolButton( box ); 328 btn = new QToolButton( box );
329 btn->setIconSet( Resource::loadIconSet("DocsIcon") ); 329 btn->setIconSet( Resource::loadIconSet("DocsIcon") );
330 connect(btn, SIGNAL(clicked() ), 330 connect(btn, SIGNAL(clicked() ),
331 this, SLOT(cdDoc() ) ); 331 this, SLOT(cdDoc() ) );
332 332
333 m_btnNew = new QToolButton( box ); 333 m_btnNew = new QToolButton( box );
334 m_btnNew->setIconSet( Resource::loadIconSet("new") ); 334 m_btnNew->setIconSet( Resource::loadIconSet("new") );
335 connect(m_btnNew, SIGNAL(clicked() ), 335 connect(m_btnNew, SIGNAL(clicked() ),
336 this, SLOT(slotNew() ) ); 336 this, SLOT(slotNew() ) );
337 337
338 338
339 m_btnClose = new QToolButton( box ); 339 m_btnClose = new QToolButton( box );
340 m_btnClose->setIconSet( Resource::loadIconSet("close") ); 340 m_btnClose->setIconSet( Resource::loadIconSet("close") );
341 connect(m_btnClose, SIGNAL(clicked() ), 341 connect(m_btnClose, SIGNAL(clicked() ),
342 selector(), SIGNAL(closeMe() ) ); 342 selector(), SIGNAL(closeMe() ) );
343 343
344 btn = new QToolButton( box ); 344 btn = new QToolButton( box );
345 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); 345 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") );
346 346
347 /* let's fill device parts */ 347 /* let's fill device parts */
348 QPopupMenu* pop = new QPopupMenu(this); 348 QPopupMenu* pop = new QPopupMenu(this);
349 connect(pop, SIGNAL( activated(int) ), 349 connect(pop, SIGNAL( activated(int) ),
350 this, SLOT(slotFSActivated(int) ) ); 350 this, SLOT(slotFSActivated(int) ) );
351 351
352 StorageInfo storage; 352 StorageInfo storage;
353 const QList<FileSystem> &fs = storage.fileSystems(); 353 const QList<FileSystem> &fs = storage.fileSystems();
354 QListIterator<FileSystem> it(fs); 354 QListIterator<FileSystem> it(fs);
355 for ( ; it.current(); ++it ) 355 for ( ; it.current(); ++it )
356 { 356 {
357 const QString disk = (*it)->name(); 357 const QString disk = (*it)->name();
358 const QString path = (*it)->path(); 358 const QString path = (*it)->path();
359 m_dev.insert( disk, path ); 359 m_dev.insert( disk, path );
360 pop->insertItem( disk ); 360 pop->insertItem( disk );
361 } 361 }
362 m_fsPop = pop; 362 m_fsPop = pop;
363 363
364 364
365 btn->setPopup( pop ); 365 btn->setPopup( pop );
366 366
367 lay->addWidget( box ); 367 lay->addWidget( box );
368 368
369 m_view = new QListView( this ); 369 m_view = new QListView( this );
370 370
371 m_view->installEventFilter(this); 371 m_view->installEventFilter(this);
372 372
373 QPEApplication::setStylusOperation( m_view->viewport(), 373 QPEApplication::setStylusOperation( m_view->viewport(),
374 QPEApplication::RightOnHold); 374 QPEApplication::RightOnHold);
375 m_view->addColumn(" " ); 375 m_view->addColumn(" " );
376 m_view->addColumn(tr("Name"), 135 ); 376 m_view->addColumn(tr("Name"), 135 );
377 m_view->addColumn(tr("Size"), -1 ); 377 m_view->addColumn(tr("Size"), -1 );
378 m_view->addColumn(tr("Date"), 60 ); 378 m_view->addColumn(tr("Date"), 60 );
379 m_view->addColumn(tr("Mime Type"), -1 ); 379 m_view->addColumn(tr("Mime Type"), -1 );
380 380
381 381
382 m_view->setSorting( 1 ); 382 m_view->setSorting( 1 );
383 m_view->setAllColumnsShowFocus( TRUE ); 383 m_view->setAllColumnsShowFocus( TRUE );
384 384
385 lay->addWidget( m_view, 1000 ); 385 lay->addWidget( m_view, 1000 );
386 connectSlots(); 386 connectSlots();
387} 387}
388 388
389OFileViewFileListView::~OFileViewFileListView() 389OFileViewFileListView::~OFileViewFileListView()
390{ 390{
391} 391}
392 392
393void OFileViewFileListView::slotNew() 393void OFileViewFileListView::slotNew()
394{ 394{
395 DocLnk lnk; 395 DocLnk lnk;
396 emit selector()->newSelected( lnk ); 396 emit selector()->newSelected( lnk );
397} 397}
398 398
399OFileSelectorItem* OFileViewFileListView::currentItem()const 399OFileSelectorItem* OFileViewFileListView::currentItem()const
400{ 400{
401 QListViewItem* item = m_view->currentItem(); 401 QListViewItem* item = m_view->currentItem();
402 if (!item ) 402 if (!item )
403 return 0l; 403 return 0l;
404 404
405 return static_cast<OFileSelectorItem*>(item); 405 return static_cast<OFileSelectorItem*>(item);
406} 406}
407 407
408void OFileViewFileListView::reread( bool all ) 408void OFileViewFileListView::reread( bool all )
409{ 409{
410 m_view->clear(); 410 m_view->clear();
411 411
412 if (selector()->showClose() ) 412 if (selector()->showClose() )
413 m_btnClose->show(); 413 m_btnClose->show();
414 else 414 else
415 m_btnClose->hide(); 415 m_btnClose->hide();
416 416
417 if (selector()->showNew() ) 417 if (selector()->showNew() )
418 m_btnNew->show(); 418 m_btnNew->show();
419 else 419 else
420 m_btnNew->hide(); 420 m_btnNew->hide();
421 421
422 m_mimes = selector()->currentMimeType(); 422 m_mimes = selector()->currentMimeType();
423 m_all = all; 423 m_all = all;
424 424
425 QDir dir( m_currentDir ); 425 QDir dir( m_currentDir );
426 if (!dir.exists() ) 426 if (!dir.exists() )
427 return; 427 return;
428 428
429 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); 429 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
430 int filter; 430 int filter;
431 if (m_all ) 431 filter = QDir::Dirs;
432 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; 432 if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR )
433 else 433 filter = filter | QDir::Files | QDir::All;
434 filter = QDir::Files | QDir::Dirs | QDir::All; 434
435 if ( m_all )
436 filter = filter | QDir::Hidden;
437
435 dir.setFilter( filter ); 438 dir.setFilter( filter );
436 439
437 // now go through all files 440 // now go through all files
438 const QFileInfoList *list = dir.entryInfoList(); 441 const QFileInfoList *list = dir.entryInfoList();
439 if (!list) 442 if (!list)
440 { 443 {
441 cdUP(); 444 cdUP();
442 return; 445 return;
443 } 446 }
444 447
445 QFileInfoListIterator it( *list ); 448 QFileInfoListIterator it( *list );
446 QFileInfo *fi; 449 QFileInfo *fi;
447 while( (fi=it.current() ) ) 450 while( (fi=it.current() ) )
448 { 451 {
449 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) 452 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") )
450 { 453 {
451 ++it; 454 ++it;
452 continue; 455 continue;
453 } 456 }
454 457
455 /* 458 /*
456 * It is a symlink we try to resolve it now but don't let us attack by DOS 459 * It is a symlink we try to resolve it now but don't let us attack by DOS
457 * 460 *
458 */ 461 */
459 if( fi->isSymLink() ) 462 if( fi->isSymLink() )
460 { 463 {
461 QString file = fi->dirPath( true ) + "/" + fi->readLink(); 464 QString file = fi->dirPath( true ) + "/" + fi->readLink();
462 for( int i = 0; i<=4; i++) 465 for( int i = 0; i<=4; i++)
463 { // 5 tries to prevent dos 466 { // 5 tries to prevent dos
464 QFileInfo info( file ); 467 QFileInfo info( file );
465 if( !info.exists() ) 468 if( !info.exists() )
466 { 469 {
467 addSymlink( fi, TRUE ); 470 addSymlink( fi, TRUE );
468 break; 471 break;
469 } 472 }
470 else if( info.isDir() ) 473 else if( info.isDir() )
471 { 474 {
472 addDir( fi, TRUE ); 475 addDir( fi, TRUE );
473 break; 476 break;
474 } 477 }
475 else if( info.isFile() ) 478 else if( info.isFile() )
476 { 479 {
477 addFile( fi, TRUE ); 480 addFile( fi, TRUE );
478 break; 481 break;
479 } 482 }
480 else if( info.isSymLink() ) 483 else if( info.isSymLink() )
481 { 484 {
482 file = info.dirPath(true ) + "/" + info.readLink() ; 485 file = info.dirPath(true ) + "/" + info.readLink() ;
483 break; 486 break;
484 } 487 }
485 else if( i == 4) 488 else if( i == 4)
486 { // couldn't resolve symlink add it as symlink 489 { // couldn't resolve symlink add it as symlink
487 addSymlink( fi ); 490 addSymlink( fi );
488 } 491 }
489 } // off for loop for symlink resolving 492 } // off for loop for symlink resolving
490 } 493 }
491 else if( fi->isDir() ) 494 else if( fi->isDir() )
492 addDir( fi ); 495 addDir( fi );
493 else if( fi->isFile() ) 496 else if( fi->isFile() )
494 addFile( fi ); 497 addFile( fi );
495 498
496 ++it; 499 ++it;
497 } // of while loop 500 } // of while loop
498 m_view->sort(); 501 m_view->sort();
499 502
500} 503}
501int OFileViewFileListView::fileCount()const 504int OFileViewFileListView::fileCount()const
502{ 505{
503 return m_view->childCount(); 506 return m_view->childCount();
504} 507}
505 508
506QString OFileViewFileListView::currentDir()const 509QString OFileViewFileListView::currentDir()const
507{ 510{
508 return m_currentDir; 511 return m_currentDir;
509} 512}
510 513
511OFileSelector* OFileViewFileListView::selector() 514OFileSelector* OFileViewFileListView::selector()
512{ 515{
513 return m_sel; 516 return m_sel;
514} 517}
515 518
516bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) 519bool OFileViewFileListView::eventFilter (QObject *, QEvent *e)
517{ 520{
518 if ( e->type() == QEvent::KeyPress ) 521 if ( e->type() == QEvent::KeyPress )
519 { 522 {
520 QKeyEvent *k = (QKeyEvent *)e; 523 QKeyEvent *k = (QKeyEvent *)e;
521 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) 524 if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
522 { 525 {
523 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); 526 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
524 return true; 527 return true;
525 } 528 }
526 } 529 }
527 return false; 530 return false;
528} 531}
529 532
530void OFileViewFileListView::connectSlots() 533void OFileViewFileListView::connectSlots()
531{ 534{
532 connect(m_view, SIGNAL(clicked(QListViewItem*) ), 535 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
533 this, SLOT(slotCurrentChanged(QListViewItem*) ) ); 536 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
534 connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), 537 connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),
535 this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); 538 this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) );
536} 539}
537 540
538void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) 541void OFileViewFileListView::slotCurrentChanged( QListViewItem* item)
539{ 542{
540 if (!item) 543 if (!item)
541 return; 544 return;
542#if 0 545#if 0
543 546
544 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 547 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
545 548
546 if (!sel->isDir() ) 549 if (!sel->isDir() )
547 { 550 {
548 selector()->m_lneEdit->setText( sel->text(1) ); 551 selector()->m_lneEdit->setText( sel->text(1) );
549 // if in fileselector mode we will emit selected 552 // if in fileselector mode we will emit selected
550 if ( selector()->mode() == OFileSelector::FileSelector ) 553 if ( selector()->mode() == OFileSelector::FileSelector )
551 { 554 {
552 odebug << "slot Current Changed" << oendl; 555 odebug << "slot Current Changed" << oendl;
553 QStringList str = QStringList::split("->", sel->text(1) ); 556 QStringList str = QStringList::split("->", sel->text(1) );
554 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 557 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
555 emit selector()->fileSelected( path ); 558 emit selector()->fileSelected( path );
556 DocLnk lnk( path ); 559 DocLnk lnk( path );
557 emit selector()->fileSelected( lnk ); 560 emit selector()->fileSelected( lnk );
558 } 561 }
559 } 562 }
560#endif 563#endif
561} 564}
562 565
563void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) 566void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int )
564{ 567{
565 if (!item || ( button != Qt::LeftButton) ) 568 if (!item || ( button != Qt::LeftButton) )
566 return; 569 return;
567 570
568 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 571 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
569 if (!sel->isLocked() ) 572 if (!sel->isLocked() )
570 { 573 {
571 QStringList str = QStringList::split("->", sel->text(1) ); 574 QStringList str = QStringList::split("->", sel->text(1) );
572 if (sel->isDir() ) 575 if (sel->isDir() )
573 { 576 {
574 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); 577 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
575 emit selector()->dirSelected( m_currentDir ); 578 emit selector()->dirSelected( m_currentDir );
576 reread( m_all ); 579 reread( m_all );
577 } 580 }
578 else 581 else
579 { // file 582 { // file
580 odebug << "slot Clicked" << oendl; 583 odebug << "slot Clicked" << oendl;
581 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); 584 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
582 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 585 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
583 emit selector()->fileSelected( path ); 586 emit selector()->fileSelected( path );
584 DocLnk lnk( path ); 587 DocLnk lnk( path );
585 emit selector()->fileSelected( lnk ); 588 emit selector()->fileSelected( lnk );
586 } 589 }
587 } // not locked 590 } // not locked
588} 591}
589 592
590void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) 593void OFileViewFileListView::addFile( QFileInfo* info, bool symlink )
591{ 594{
592 MimeType type( info->absFilePath() ); 595 MimeType type( info->absFilePath() );
593 if (!compliesMime( type.id() ) ) 596 if (!compliesMime( type.id() ) )
594 return; 597 return;
595 598
596 QPixmap pix = type.pixmap(); 599 QPixmap pix = type.pixmap();
597 QString dir, name; bool locked; 600 QString dir, name; bool locked;
598 if ( pix.isNull() ) 601 if ( pix.isNull() )
599 { 602 {
600 QWMatrix matrix; 603 QWMatrix matrix;
601 QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); 604 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
602 matrix.scale( .4, .4 ); 605 matrix.scale( .4, .4 );
603 pix = pixer.xForm( matrix ); 606 pix = pixer.xForm( matrix );
604 } 607 }
605 dir = info->dirPath( true ); 608 dir = info->dirPath( true );
606 locked = false; 609 locked = false;
607 if ( symlink ) 610 if ( symlink )
608 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); 611 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
609 else 612 else
610 { 613 {
611 name = info->fileName(); 614 name = info->fileName();
612 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || 615 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
613 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) 616 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) )
614 { 617 {
615 locked = true; pix = Resource::loadPixmap("locked"); 618 locked = true; pix = Resource::loadPixmap("locked");
616 } 619 }
617 } 620 }
618 (void)new OFileSelectorItem( m_view, pix, name, 621 (void)new OFileSelectorItem( m_view, pix, name,
619 info->lastModified().toString(), QString::number( info->size() ), 622 info->lastModified().toString(), QString::number( info->size() ),
620 dir, locked ); 623 dir, locked );
621} 624}
622 625
623void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) 626void OFileViewFileListView::addDir( QFileInfo* info, bool symlink )
624{ 627{
625 bool locked = false; QString name; QPixmap pix; 628 bool locked = false; QString name; QPixmap pix;
626 629
627 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || 630 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
628 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) 631 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) )
629 { 632 {
630 locked = true; 633 locked = true;
631 if ( symlink ) 634 if ( symlink )
632 pix = Resource::loadPixmap( "opie/symlink" ); 635 pix = Resource::loadPixmap( "opie/symlink" );
633 else 636 else
634 pix = Resource::loadPixmap( "lockedfolder" ); 637 pix = Resource::loadPixmap( "lockedfolder" );
635 } 638 }
636 else 639 else
637 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); 640 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
638 641
639 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : 642 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
640 info->fileName(); 643 info->fileName();
641 644
642 (void)new OFileSelectorItem( m_view, pix, name, 645 (void)new OFileSelectorItem( m_view, pix, name,
643 info->lastModified().toString(), 646 info->lastModified().toString(),
644 QString::number( info->size() ), 647 QString::number( info->size() ),
645 info->dirPath( true ), locked, true ); 648 info->dirPath( true ), locked, true );
646 649
647 650
648} 651}
649 652
650void OFileViewFileListView::addSymlink( QFileInfo* , bool ) 653void OFileViewFileListView::addSymlink( QFileInfo* , bool )
651{ 654{
652} 655}
653 656
654void OFileViewFileListView::cdUP() 657void OFileViewFileListView::cdUP()
655{ 658{
656 QDir dir( m_currentDir ); 659 QDir dir( m_currentDir );
657 dir.cdUp(); 660 dir.cdUp();
658 661
659 if (!dir.exists() ) 662 if (!dir.exists() )
660 m_currentDir = "/"; 663 m_currentDir = "/";
661 else 664 else
662 m_currentDir = dir.absPath(); 665 m_currentDir = dir.absPath();
663 666
664 emit selector()->dirSelected( m_currentDir ); 667 emit selector()->dirSelected( m_currentDir );
665 reread( m_all ); 668 reread( m_all );
666} 669}
667 670
668void OFileViewFileListView::cdHome() 671void OFileViewFileListView::cdHome()
669{ 672{
670 m_currentDir = QDir::homeDirPath(); 673 m_currentDir = QDir::homeDirPath();
671 emit selector()->dirSelected( m_currentDir ); 674 emit selector()->dirSelected( m_currentDir );
672 reread( m_all ); 675 reread( m_all );
673} 676}
674 677
675void OFileViewFileListView::cdDoc() 678void OFileViewFileListView::cdDoc()
676{ 679{
677 m_currentDir = QPEApplication::documentDir(); 680 m_currentDir = QPEApplication::documentDir();
678 emit selector()->dirSelected( m_currentDir ); 681 emit selector()->dirSelected( m_currentDir );
679 reread( m_all ); 682 reread( m_all );
680} 683}
681 684
682void OFileViewFileListView::changeDir( const QString& dir ) 685void OFileViewFileListView::changeDir( const QString& dir )
683{ 686{
684 m_currentDir = dir; 687 m_currentDir = dir;
685 emit selector()->dirSelected( m_currentDir ); 688 emit selector()->dirSelected( m_currentDir );
686 reread( m_all ); 689 reread( m_all );
687} 690}
688 691
689void OFileViewFileListView::slotFSActivated( int id ) 692void OFileViewFileListView::slotFSActivated( int id )
690{ 693{
691 changeDir ( m_dev[m_fsPop->text(id)] ); 694 changeDir ( m_dev[m_fsPop->text(id)] );
692} 695}
693 696
694/* check if the mimetype in mime 697/* check if the mimetype in mime
695 * complies with the one which is current 698 * complies with the one which is current
696 */ 699 */
697/* 700/*
698 * We've the mimetype of the file 701 * We've the mimetype of the file
699 * We need to get the stringlist of the current mimetype 702 * We need to get the stringlist of the current mimetype
700 * 703 *
701 * mime = image@slashjpeg 704 * mime = image@slashjpeg
702 * QStringList = 'image@slash*' 705 * QStringList = 'image@slash*'
703 * or QStringList = image/jpeg;image/png;application/x-ogg 706 * or QStringList = image/jpeg;image/png;application/x-ogg
704 * or QStringList = application/x-ogg;image@slash*; 707 * or QStringList = application/x-ogg;image@slash*;
705 * with all these mime filters it should get acceptes 708 * with all these mime filters it should get acceptes
706 * to do so we need to look if mime is contained inside 709 * to do so we need to look if mime is contained inside
707 * the stringlist 710 * the stringlist
708 * if it's contained return true 711 * if it's contained return true
709 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' 712 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*'
710 * is contained in the mimefilter and then we will 713 * is contained in the mimefilter and then we will
711 * look if both are equal until the '/' 714 * look if both are equal until the '/'
712 */ 715 */
713 716
714bool OFileViewFileListView::compliesMime( const QString& str) 717bool OFileViewFileListView::compliesMime( const QString& str)
715{ 718{
716 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) 719 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
717 return true; 720 return true;
718 721
719 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) 722 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it )
720 { 723 {
721 QRegExp reg( (*it) ); 724 QRegExp reg( (*it) );
722 reg.setWildcard( true ); 725 reg.setWildcard( true );
723 if ( str.find( reg ) != -1 ) 726 if ( str.find( reg ) != -1 )
724 return true; 727 return true;
725 728
726 } 729 }
727 return false; 730 return false;
728} 731}
729/* 732/*
730 * The listView giving access to the file system! 733 * The listView giving access to the file system!
731 */ 734 */
732 735
733class OFileViewFileSystem : public OFileViewInterface 736class OFileViewFileSystem : public OFileViewInterface
734{ 737{
735public: 738public:
736 OFileViewFileSystem( OFileSelector* ); 739 OFileViewFileSystem( OFileSelector* );
737 ~OFileViewFileSystem(); 740 ~OFileViewFileSystem();
738 741
739 QString selectedName() const; 742 QString selectedName() const;
740 QString selectedPath() const; 743 QString selectedPath() const;
741 744
742 QString directory()const; 745 QString directory()const;
743 void reread(); 746 void reread();
744 int fileCount()const; 747 int fileCount()const;
745 748
746 QWidget* widget( QWidget* parent ); 749 QWidget* widget( QWidget* parent );
747 void activate( const QString& ); 750 void activate( const QString& );
748private: 751private:
749 OFileViewFileListView* m_view; 752 OFileViewFileListView* m_view;
750 bool m_all : 1; 753 bool m_all : 1;
751}; 754};
752 755
753OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) 756OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
754 : OFileViewInterface( sel ) 757 : OFileViewInterface( sel )
755{ 758{
756 m_view = 0; 759 m_view = 0;
757 m_all = false; 760 m_all = false;
758} 761}
759 762
760OFileViewFileSystem::~OFileViewFileSystem() 763OFileViewFileSystem::~OFileViewFileSystem()
761{ 764{
762} 765}
763 766
764QString OFileViewFileSystem::selectedName()const 767QString OFileViewFileSystem::selectedName()const
765{ 768{
766 if (!m_view ) 769 if (!m_view )
767 return QString::null; 770 return QString::null;
768 771
769 QString cFN=currentFileName(); 772 QString cFN=currentFileName();
770 if (cFN.startsWith("/")) return cFN; 773 if (cFN.startsWith("/")) return cFN;
771 return m_view->currentDir() + "/" + cFN; 774 return m_view->currentDir() + "/" + cFN;
772} 775}
773 776
774QString OFileViewFileSystem::selectedPath()const 777QString OFileViewFileSystem::selectedPath()const
775{ 778{
776 return QString::null; 779 return QString::null;
777} 780}
778 781
779QString OFileViewFileSystem::directory()const 782QString OFileViewFileSystem::directory()const
780{ 783{
781 if (!m_view) 784 if (!m_view)
782 return QString::null; 785 return QString::null;
783 786
784 OFileSelectorItem* item = m_view->currentItem(); 787 OFileSelectorItem* item = m_view->currentItem();
785 if (!item ) 788 if (!item )
786 return QString::null; 789 return QString::null;
787 790
788 return QDir(item->directory() ).absPath(); 791 return QDir(item->directory() ).absPath();
789} 792}
790 793
791void OFileViewFileSystem::reread() 794void OFileViewFileSystem::reread()
792{ 795{
793 if (!m_view) 796 if (!m_view)
794 return; 797 return;
795 798
796 m_view->reread( m_all ); 799 m_view->reread( m_all );
797} 800}
798 801
799int OFileViewFileSystem::fileCount()const 802int OFileViewFileSystem::fileCount()const
800{ 803{
801 if (!m_view ) 804 if (!m_view )
802 return -1; 805 return -1;
803 return m_view->fileCount(); 806 return m_view->fileCount();
804} 807}
805 808
806QWidget* OFileViewFileSystem::widget( QWidget* parent ) 809QWidget* OFileViewFileSystem::widget( QWidget* parent )
807{ 810{
808 if (!m_view ) 811 if (!m_view )
809 { 812 {
810 m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); 813 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
811 } 814 }
812 return m_view; 815 return m_view;
813} 816}
814 817
815void OFileViewFileSystem::activate( const QString& str) 818void OFileViewFileSystem::activate( const QString& str)
816{ 819{
817 m_all = (str != QObject::tr("Files") ); 820 m_all = ( str.find( "All" ) != -1 );
818} 821}
819 822
820 823
821} 824}
822/* Selector */ 825/* Selector */
823/** 826/**
824 * @short new and complete c'tor 827 * @short new and complete c'tor
825 * 828 *
826 * Create a OFileSelector to let the user select a file. It can 829 * Create a OFileSelector to let the user select a file. It can
827 * either be used to open a file, select a save name in a dir or 830 * either be used to open a file, select a save name in a dir or
828 * as a dropin for the FileSelector. 831 * as a dropin for the FileSelector.
829 * 832 *
830 * <pre> 833 * <pre>
831 * QMap<QString, QStringList> mimeTypes; 834 * QMap<QString, QStringList> mimeTypes;
832 * QStringList types; 835 * QStringList types;
833 * types << "text@slash* "; 836 * types << "text@slash* ";
834 * types << "audio@slash*"; 837 * types << "audio@slash*";
835 * mimeTypes.insert( tr("Audio and Text"), types ); 838 * mimeTypes.insert( tr("Audio and Text"), types );
836 * mimeTypes.insert( tr("All"), "*@slash*); 839 * mimeTypes.insert( tr("All"), "*@slash*);
837 * 840 *
838 * now you could create your fileselector 841 * now you could create your fileselector
839 * </pre> 842 * </pre>
840 * 843 *
841 * 844 *
842 * @param parent the parent of this widget 845 * @param parent the parent of this widget
843 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) 846 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR)
844 * @param sel The selector to be used 847 * @param sel The selector to be used
845 * @param dirName The name of the dir to start int 848 * @param dirName The name of the dir to start int
846 * @param fileName The fileName placed in the fileselector lineedit 849 * @param fileName The fileName placed in the fileselector lineedit
847 * @param mimetypes The MimeType map of used mimetypes 850 * @param mimetypes The MimeType map of used mimetypes
848 * @param showNew Show a New Button. Most likely to be used in the FileSelector view. 851 * @param showNew Show a New Button. Most likely to be used in the FileSelector view.
849 * @param showClose Show a Close Button. Most likely to be used in FileSelector view. 852 * @param showClose Show a Close Button. Most likely to be used in FileSelector view.
850 * 853 *
851 */ 854 */
852OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, 855OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
853 const QString& dirName, const QString& fileName, 856 const QString& dirName, const QString& fileName,
854 const MimeTypes& mimetypes, 857 const MimeTypes& mimetypes,
855 bool showNew, bool showClose) 858 bool showNew, bool showClose)
856 :QWidget( parent, "OFileSelector" ) 859 :QWidget( parent, "OFileSelector" )
857{ 860{
858 m_current = 0; 861 m_current = 0;
859 m_shNew = showNew; 862 m_shNew = showNew;
860 m_shClose = showClose; 863 m_shClose = showClose;
861 m_mimeType = mimetypes; 864 m_mimeType = mimetypes;
862 m_startDir = dirName; 865 m_startDir = dirName;
863 866
864 m_mode = mode; 867 m_mode = mode;
865 m_selector = sel; 868 m_selector = sel;
866 869
867 initUI(); 870 initUI();
868 m_lneEdit->setText( fileName ); 871 m_lneEdit->setText( fileName );
869 initMime(); 872 initMime();
870 initViews(); 873 initViews();
871 874
872 QString str; 875 QString str;
873 switch ( m_selector ) 876 switch ( m_selector )
874 { 877 {
875 default: 878 default:
876 case Normal: 879 case Normal:
877 str = QObject::tr("Documents"); 880 if ( m_mode == DIRECTORYSELECTOR )
881 str = QObject::tr("Directories");
882 else
883 str = QObject::tr("Documents");
878 m_cmbView->setCurrentItem( 0 ); 884 m_cmbView->setCurrentItem( 0 );
879 break; 885 break;
880 case Extended: 886 case Extended:
881 str = QObject::tr("Files"); 887 if ( m_mode == DIRECTORYSELECTOR )
882 m_cmbView->setCurrentItem( 1 ); 888 {
889 str = QObject::tr("Directories");
890 m_cmbView->setCurrentItem( 0 );
891 } else {
892 str = QObject::tr("Files");
893 m_cmbView->setCurrentItem( 1 );
894 }
883 break; 895 break;
884 case ExtendedAll: 896 case ExtendedAll:
885 str = QObject::tr("All Files"); 897 if ( m_mode == DIRECTORYSELECTOR )
886 m_cmbView->setCurrentItem( 2 ); 898 {
899 str = QObject::tr("All Directories");
900 m_cmbView->setCurrentItem( 1 );
901 } else {
902 str = QObject::tr("All Files");
903 m_cmbView->setCurrentItem( 2 );
904 }
887 break; 905 break;
888 } 906 }
889 slotViewChange( str ); 907 slotViewChange( str );
890 908
891} 909}
892 910
893 911
894/** 912/**
895 * This a convience c'tor to just substitute the use of FileSelector 913 * This a convience c'tor to just substitute the use of FileSelector
896 */ 914 */
897OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, 915OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
898 bool showNew, bool showClose ) 916 bool showNew, bool showClose )
899 : QWidget( parent, name ) 917 : QWidget( parent, name )
900{ 918{
901 m_current = 0; 919 m_current = 0;
902 m_shNew = showNew; 920 m_shNew = showNew;
903 m_shClose = showClose; 921 m_shClose = showClose;
904 m_startDir = QPEApplication::documentDir(); 922 m_startDir = QPEApplication::documentDir();
905 923
906 if (!mimeFilter.isEmpty() ) 924 if (!mimeFilter.isEmpty() )
907 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); 925 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
908 926
909 m_mode = OFileSelector::FileSelector; 927 m_mode = OFileSelector::FileSelector;
910 m_selector = OFileSelector::Normal; 928 m_selector = OFileSelector::Normal;
911 929
912 initUI(); 930 initUI();
913 initMime(); 931 initMime();
914 initViews(); 932 initViews();
915 m_cmbView->setCurrentItem( 0 ); 933 m_cmbView->setCurrentItem( 0 );
916 slotViewChange( QObject::tr("Documents") ); 934 slotViewChange( QObject::tr("Documents") );
917} 935}
918 936
919/* 937/*
920 * INIT UI will set up the basic GUI 938 * INIT UI will set up the basic GUI
921 * Layout: Simple VBoxLayout 939 * Layout: Simple VBoxLayout
922 * On top a WidgetStack containing the Views... 940 * On top a WidgetStack containing the Views...
923 * - List View 941 * - List View
924 * - Document View 942 * - Document View
925 * Below we will have a Label + LineEdit 943 * Below we will have a Label + LineEdit
926 * Below we will have two ComoBoxes one for choosing the view one for 944 * Below we will have two ComoBoxes one for choosing the view one for
927 * choosing the mimetype 945 * choosing the mimetype
928 */ 946 */
929void OFileSelector::initUI() 947void OFileSelector::initUI()
930{ 948{
931 QVBoxLayout* lay = new QVBoxLayout( this ); 949 QVBoxLayout* lay = new QVBoxLayout( this );
932 950
933 m_stack = new QWidgetStack( this ); 951 m_stack = new QWidgetStack( this );
934 lay->addWidget( m_stack, 1000 ); 952 lay->addWidget( m_stack, 1000 );
935 953
936 m_nameBox = new QHBox( this ); 954 m_nameBox = new QHBox( this );
937 (void)new QLabel( tr("Name:"), m_nameBox ); 955 (void)new QLabel( tr("Name:"), m_nameBox );
938 m_lneEdit = new QLineEdit( m_nameBox ); 956 m_lneEdit = new QLineEdit( m_nameBox );
939 m_lneEdit ->installEventFilter(this); 957 m_lneEdit ->installEventFilter(this);
940 lay->addWidget( m_nameBox ); 958 lay->addWidget( m_nameBox );
941 959
942 m_cmbBox = new QHBox( this ); 960 m_cmbBox = new QHBox( this );
943 m_cmbView = new QComboBox( m_cmbBox ); 961 m_cmbView = new QComboBox( m_cmbBox );
944 m_cmbMime = new QComboBox( m_cmbBox ); 962 m_cmbMime = new QComboBox( m_cmbBox );
945 lay->addWidget( m_cmbBox ); 963 lay->addWidget( m_cmbBox );
946} 964}
947 965
948/* 966/*
949 * This will make sure that the return key in the name edit causes dialogs to close 967 * This will make sure that the return key in the name edit causes dialogs to close
950 */ 968 */
951 969
952bool OFileSelector::eventFilter (QObject *, QEvent *e) 970bool OFileSelector::eventFilter (QObject *, QEvent *e)
953{ 971{
954 if ( e->type() == QEvent::KeyPress ) 972 if ( e->type() == QEvent::KeyPress )
955 { 973 {
956 QKeyEvent *k = (QKeyEvent *)e; 974 QKeyEvent *k = (QKeyEvent *)e;
957 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) 975 if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
958 { 976 {
959 emit ok(); 977 emit ok();
960 return true; 978 return true;
961 } 979 }
962 } 980 }
963 return false; 981 return false;
964} 982}
965 983
966/* 984/*
967 * This will insert the MimeTypes into the Combo Box 985 * This will insert the MimeTypes into the Combo Box
968 * And also connect the changed signal 986 * And also connect the changed signal
969 * 987 *
970 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes 988 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
971 */ 989 */
972void OFileSelector::initMime() 990void OFileSelector::initMime()
973{ 991{
974 MimeTypes::Iterator it; 992 MimeTypes::Iterator it;
975 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) 993 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it )
976 { 994 {
977 m_cmbMime->insertItem( it.key() ); 995 m_cmbMime->insertItem( it.key() );
978 } 996 }
979 m_cmbMime->setCurrentItem( 0 ); 997 m_cmbMime->setCurrentItem( 0 );
980 998
981 connect( m_cmbMime, SIGNAL(activated(int) ), 999 connect( m_cmbMime, SIGNAL(activated(int) ),
982 this, SLOT(slotMimeTypeChanged() ) ); 1000 this, SLOT(slotMimeTypeChanged() ) );
983 1001
984} 1002}
985 1003
986void OFileSelector::initViews() 1004void OFileSelector::initViews()
987{ 1005{
988 m_cmbView->insertItem( QObject::tr("Documents") ); 1006 if ( m_mode == OFileSelector::DIRECTORYSELECTOR )
989 m_cmbView->insertItem( QObject::tr("Files") ); 1007 {
990 m_cmbView->insertItem( QObject::tr("All Files") ); 1008 m_cmbView->insertItem( QObject::tr("Directories") );
1009 m_cmbView->insertItem( QObject::tr("All Directories") );
1010 } else {
1011 m_cmbView->insertItem( QObject::tr("Documents") );
1012 m_cmbView->insertItem( QObject::tr("Files") );
1013 m_cmbView->insertItem( QObject::tr("All Files") );
1014 }
1015
991 connect(m_cmbView, SIGNAL(activated(const QString&) ), 1016 connect(m_cmbView, SIGNAL(activated(const QString&) ),
992 this, SLOT(slotViewChange(const QString&) ) ); 1017 this, SLOT(slotViewChange(const QString&) ) );
993 1018
994
995 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
996
997 /* see above why add both */ 1019 /* see above why add both */
998 OFileViewInterface* in = new OFileViewFileSystem( this ); 1020 OFileViewInterface* in = new OFileViewFileSystem( this );
999 m_views.insert( QObject::tr("Files"), in ); 1021
1000 m_views.insert( QObject::tr("All Files"), in ); 1022 if ( m_mode == OFileSelector::DIRECTORYSELECTOR )
1023 {
1024 m_views.insert( QObject::tr("Directories"), in );
1025 m_views.insert( QObject::tr("All Directories"), in );
1026 } else {
1027 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
1028 m_views.insert( QObject::tr("Files"), in );
1029 m_views.insert( QObject::tr("All Files"), in );
1030 }
1001} 1031}
1002 1032
1003void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { 1033void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) {
1004 m_viewsPtr.append( iface ); 1034 m_viewsPtr.append( iface );
1005} 1035}
1006 1036
1007 1037
1008/** 1038/**
1009 * d'tor 1039 * d'tor
1010 */ 1040 */
1011OFileSelector::~OFileSelector() 1041OFileSelector::~OFileSelector()
1012{ 1042{
1013 m_viewsPtr.setAutoDelete( true ); 1043 m_viewsPtr.setAutoDelete( true );
1014 m_viewsPtr.clear(); 1044 m_viewsPtr.clear();
1015} 1045}
1016 1046
1017 1047
1018 1048
1019/** 1049/**
1020 * Convience function for the fileselector 1050 * Convience function for the fileselector
1021 * make sure to delete the DocLnk 1051 * make sure to delete the DocLnk
1022 * 1052 *
1023 * @see DocLnk 1053 * @see DocLnk
1024 * @todo remove in ODP 1054 * @todo remove in ODP
1025 */ 1055 */
1026const DocLnk* OFileSelector::selected() 1056const DocLnk* OFileSelector::selected()
1027{ 1057{
1028 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); 1058 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
1029 return lnk; 1059 return lnk;
1030} 1060}
1031 1061
1032/** 1062/**
1033 * 1063 *
1034 * @return the name of the selected file 1064 * @return the name of the selected file
1035 */ 1065 */
1036QString OFileSelector::selectedName()const 1066QString OFileSelector::selectedName()const
1037{ 1067{
1038 return currentView()->selectedName(); 1068 return currentView()->selectedName();
1039} 1069}
1040 1070
1041 1071
1042/** 1072/**
1043 * @return the selected path 1073 * @return the selected path
1044 */ 1074 */
1045QString OFileSelector::selectedPath()const 1075QString OFileSelector::selectedPath()const
1046{ 1076{
1047 return currentView()->selectedPath(); 1077 return currentView()->selectedPath();
1048} 1078}
1049 1079
1050/** 1080/**
1051 * @return the directory name 1081 * @return the directory name
1052 */ 1082 */
1053QString OFileSelector::directory()const 1083QString OFileSelector::directory()const
1054{ 1084{
1055 return currentView()->directory(); 1085 return currentView()->directory();
1056} 1086}
1057 1087
1058/** 1088/**
1059 * @return a DocLnk for the selected document 1089 * @return a DocLnk for the selected document
1060 */ 1090 */
1061DocLnk OFileSelector::selectedDocument()const 1091DocLnk OFileSelector::selectedDocument()const
1062{ 1092{
1063 return currentView()->selectedDocument(); 1093 return currentView()->selectedDocument();
1064} 1094}
1065 1095
1066/** 1096/**
1067 * @return the number of items for the current view 1097 * @return the number of items for the current view
1068 */ 1098 */
1069int OFileSelector::fileCount()const 1099int OFileSelector::fileCount()const
1070{ 1100{
1071 return currentView()->fileCount(); 1101 return currentView()->fileCount();
1072} 1102}
1073 1103
1074/** 1104/**
1075 * @return reparse the file content 1105 * @return reparse the file content
1076 */ 1106 */
1077void OFileSelector::reread() 1107void OFileSelector::reread()
1078{ 1108{
1079 return currentView()->reread(); 1109 return currentView()->reread();
1080} 1110}
1081 1111
1082OFileViewInterface* OFileSelector::currentView()const 1112OFileViewInterface* OFileSelector::currentView()const
1083{ 1113{
1084 return m_current; 1114 return m_current;
1085} 1115}
1086 1116
1087bool OFileSelector::showNew()const 1117bool OFileSelector::showNew()const
1088{ 1118{
1089 return m_shNew; 1119 return m_shNew;
1090} 1120}
1091 1121
1092bool OFileSelector::showClose()const 1122bool OFileSelector::showClose()const
1093{ 1123{
1094 return m_shClose; 1124 return m_shClose;
1095} 1125}
1096 1126
1097MimeTypes OFileSelector::mimeTypes()const 1127MimeTypes OFileSelector::mimeTypes()const
1098{ 1128{
1099 return m_mimeType; 1129 return m_mimeType;
1100} 1130}
1101 1131
1102/** 1132/**
1103 * @return the Mode of the OFileSelector 1133 * @return the Mode of the OFileSelector
1104 */ 1134 */
1105int OFileSelector::mode()const 1135int OFileSelector::mode()const
1106{ 1136{
1107 return m_mode; 1137 return m_mode;
1108} 1138}
1109 1139
1110 1140
1111/** 1141/**
1112 * @return the Selector of the OFileSelector 1142 * @return the Selector of the OFileSelector
1113 */ 1143 */
1114int OFileSelector::selector()const 1144int OFileSelector::selector()const
1115{ 1145{
1116 return m_selector; 1146 return m_selector;
1117} 1147}
1118 1148
1119QStringList OFileSelector::currentMimeType()const 1149QStringList OFileSelector::currentMimeType()const
1120{ 1150{
1121 return m_mimeType[m_cmbMime->currentText()]; 1151 return m_mimeType[m_cmbMime->currentText()];
1122} 1152}
1123 1153
1124void OFileSelector::slotMimeTypeChanged() 1154void OFileSelector::slotMimeTypeChanged()
1125{ 1155{
1126 reread(); 1156 reread();
1127} 1157}
1128 1158
1129void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) 1159void OFileSelector::slotDocLnkBridge( const DocLnk& lnk)
1130{ 1160{
1131 m_lneEdit->setText( lnk.name() ); 1161 m_lneEdit->setText( lnk.name() );
1132 emit fileSelected( lnk ); 1162 emit fileSelected( lnk );
1133 emit fileSelected( lnk.name() ); 1163 emit fileSelected( lnk.name() );
1134} 1164}
1135 1165
1136void OFileSelector::slotFileBridge( const QString& str) 1166void OFileSelector::slotFileBridge( const QString& str)
1137{ 1167{
1138 DocLnk lnk( str ); 1168 DocLnk lnk( str );
1139 emit fileSelected( lnk ); 1169 emit fileSelected( lnk );
1140} 1170}
1141 1171
1142void OFileSelector::slotViewChange( const QString& view ) 1172void OFileSelector::slotViewChange( const QString& view )
1143{ 1173{
1144 OFileViewInterface* interface = m_views[view]; 1174 OFileViewInterface* interface = m_views[view];
1145 if (!interface) 1175 if (!interface)
1146 return; 1176 return;
1147 1177
1148 interface->activate( view ); 1178 interface->activate( view );
1149 if (m_current) 1179 if (m_current)
1150 m_stack->removeWidget( m_current->widget( m_stack ) ); 1180 m_stack->removeWidget( m_current->widget( m_stack ) );
1151 1181
1152 static int id = 1; 1182 static int id = 1;
1153 1183
1154 m_stack->addWidget( interface->widget(m_stack), id ); 1184 m_stack->addWidget( interface->widget(m_stack), id );
1155 m_stack->raiseWidget( id ); 1185 m_stack->raiseWidget( id );
1156 1186
1157 interface->reread(); 1187 interface->reread();
1158 m_current = interface; 1188 m_current = interface;
1159 1189
1160 id++; 1190 id++;
1161} 1191}
1162 1192
1163void OFileSelector::setNewVisible( bool b ) 1193void OFileSelector::setNewVisible( bool b )
1164{ 1194{
1165 m_shNew = b; 1195 m_shNew = b;
1166 currentView()->reread(); 1196 currentView()->reread();
1167} 1197}
1168 1198
1169void OFileSelector::setCloseVisible( bool b ) 1199void OFileSelector::setCloseVisible( bool b )
1170{ 1200{
1171 m_shClose = b; 1201 m_shClose = b;
1172 currentView()->reread(); 1202 currentView()->reread();
1173} 1203}
1174 1204
1175void OFileSelector::setNameVisible( bool b ) 1205void OFileSelector::setNameVisible( bool b )
1176{ 1206{
1177 if ( b ) 1207 if ( b )
1178 m_nameBox->show(); 1208 m_nameBox->show();
1179 else 1209 else
1180 m_nameBox->hide(); 1210 m_nameBox->hide();
1181} 1211}
1182 1212
1183} 1213}
1184} 1214}
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h
index de2b98a..b1cd405 100644
--- a/libopie2/opieui/fileselector/ofileselector.h
+++ b/libopie2/opieui/fileselector/ofileselector.h
@@ -1,232 +1,233 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29/* 29/*
30 This is based on code and ideas of 30 This is based on code and ideas of
31 L. J. Potter ljp@llornkcor.com 31 L. J. Potter ljp@llornkcor.com
32 Thanks a lot 32 Thanks a lot
33*/ 33*/
34 34
35#ifndef OFILESELECTOR_H 35#ifndef OFILESELECTOR_H
36#define OFILESELECTOR_H 36#define OFILESELECTOR_H
37 37
38/* OPIE */ 38/* OPIE */
39#include <qpe/applnk.h> 39#include <qpe/applnk.h>
40 40
41/* QT */ 41/* QT */
42#include <qlist.h> 42#include <qlist.h>
43#include <qwidget.h> 43#include <qwidget.h>
44#include <qmap.h> 44#include <qmap.h>
45#include <qvaluelist.h> 45#include <qvaluelist.h>
46#include <qstringlist.h> 46#include <qstringlist.h>
47#include <qlist.h> 47#include <qlist.h>
48 48
49class QLineEdit; 49class QLineEdit;
50class QComboBox; 50class QComboBox;
51class QWidgetStack; 51class QWidgetStack;
52class QHBox; 52class QHBox;
53 53
54typedef QMap<QString, QStringList> MimeTypes; 54typedef QMap<QString, QStringList> MimeTypes;
55 55
56namespace Opie { 56namespace Opie {
57namespace Ui { 57namespace Ui {
58 58
59namespace Internal { 59namespace Internal {
60class OFileViewInterface; 60class OFileViewInterface;
61class OFileViewFileListView; 61class OFileViewFileListView;
62} 62}
63 63
64 64
65/** 65/**
66 * @short a dropin replacement for the FileSelector 66 * @short a dropin replacement for the FileSelector
67 * 67 *
68 * This class is first used insert the OFileDialog. 68 * This class is first used insert the OFileDialog.
69 * It supports multiple view and mimetype filtering for now. 69 * It supports multiple view and mimetype filtering for now.
70 * 70 *
71 * @see OFileDialog 71 * @see OFileDialog
72 * @see FileSelector 72 * @see FileSelector
73 * @author zecke 73 * @author zecke
74 * @version 0.1 74 * @version 0.1
75 */ 75 */
76class OFileSelector : public QWidget 76class OFileSelector : public QWidget
77{ 77{
78 Q_OBJECT 78 Q_OBJECT
79 friend class Internal::OFileViewInterface; 79 friend class Internal::OFileViewInterface;
80 friend class Internal::OFileViewFileListView; 80 friend class Internal::OFileViewFileListView;
81 81
82public: 82public:
83 /** 83 /**
84 * The Mode of the Fileselector 84 * The Mode of the Fileselector
85 * Open = Open A File 85 * Open = Open A File
86 * Save = Save a File 86 * Save = Save a File
87 * FILESELECTOR = As A GUI in a screen to select a file 87 * FILESELECTOR = As A GUI in a screen to select a file
88 * SelectDir = Select a Directory
88 */ 89 */
89 enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; 90 enum Mode { Open = 1, Save = 2, DirectorySelector = 3, FileSelector = 4, OPEN = 1, SAVE = 2, DIRECTORYSELECTOR = 3, FILESELECTOR = 4 };
90 // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; 91 // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
91 /** 92 /**
92 * Normal = The old FileSelector 93 * Normal = The old FileSelector
93 * Extended = Dir View 94 * Extended = Dir View
94 * ExtendedAll = Dir View with all hidden files 95 * ExtendedAll = Dir View with all hidden files
95 * Default = What the vendor considers best 96 * Default = What the vendor considers best
96 */ 97 */
97 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; 98 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 };
98 // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; 99 // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2};
99 100
100 OFileSelector(QWidget* parent, int mode, int selector, 101 OFileSelector(QWidget* parent, int mode, int selector,
101 const QString& dirName, 102 const QString& dirName,
102 const QString& fileName, 103 const QString& fileName,
103 const MimeTypes& mimetypes = MimeTypes(), 104 const MimeTypes& mimetypes = MimeTypes(),
104 bool newVisible = FALSE, bool closeVisible = FALSE ); 105 bool newVisible = FALSE, bool closeVisible = FALSE );
105 106
106 OFileSelector(const QString& mimeFilter, QWidget* parent, 107 OFileSelector(const QString& mimeFilter, QWidget* parent,
107 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); 108 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE );
108 ~OFileSelector(); 109 ~OFileSelector();
109 110
110 const DocLnk* selected(); 111 const DocLnk* selected();
111 112
112 QString selectedName()const; 113 QString selectedName()const;
113 QString selectedPath()const; 114 QString selectedPath()const;
114 QString directory()const; 115 QString directory()const;
115 116
116 DocLnk selectedDocument()const; 117 DocLnk selectedDocument()const;
117 118
118 int fileCount()const; 119 int fileCount()const;
119 void reread(); 120 void reread();
120 121
121 int mode()const; 122 int mode()const;
122 int selector()const; 123 int selector()const;
123 124
124 /** 125 /**
125 * Set the Icon visible 126 * Set the Icon visible
126 * @param b Show or Hide the New Button 127 * @param b Show or Hide the New Button
127 */ 128 */
128 void setNewVisible( bool b ); 129 void setNewVisible( bool b );
129 130
130 /** 131 /**
131 * Set the Icon visible 132 * Set the Icon visible
132 */ 133 */
133 void setCloseVisible( bool b ); 134 void setCloseVisible( bool b );
134 135
135 /** 136 /**
136 * Set the Name Line visible 137 * Set the Name Line visible
137 */ 138 */
138 void setNameVisible( bool b ); 139 void setNameVisible( bool b );
139 140
140signals: 141signals:
141 /** 142 /**
142 * dirSelected is emitted whenever changed into a different dir 143 * dirSelected is emitted whenever changed into a different dir
143 */ 144 */
144 void dirSelected( const QString& ); 145 void dirSelected( const QString& );
145 146
146 /** 147 /**
147 * fileSelected is emitted when a file is selected 148 * fileSelected is emitted when a file is selected
148 * it uses a DocLnk as parameter 149 * it uses a DocLnk as parameter
149 */ 150 */
150 void fileSelected( const DocLnk& ); 151 void fileSelected( const DocLnk& );
151 152
152 /** 153 /**
153 * fileSelected is emitted when a file is selected 154 * fileSelected is emitted when a file is selected
154 * the complete path is a parameter 155 * the complete path is a parameter
155 */ 156 */
156 void fileSelected( const QString& ); 157 void fileSelected( const QString& );
157 158
158 /** 159 /**
159 * Create a new File with a DocLnk 160 * Create a new File with a DocLnk
160 */ 161 */
161 void newSelected( const DocLnk& ); 162 void newSelected( const DocLnk& );
162 163
163 void closeMe(); 164 void closeMe();
164 165
165 /** 166 /**
166 * Ok is emitted on a Qt::Key_Return or Q::Key_Enter 167 * Ok is emitted on a Qt::Key_Return or Q::Key_Enter
167 * in the line edit 168 * in the line edit
168 */ 169 */
169 void ok(); 170 void ok();
170 void cancel(); 171 void cancel();
171 172
172 /* used by the ViewInterface */ 173 /* used by the ViewInterface */
173private: 174private:
174 bool showNew()const; 175 bool showNew()const;
175 bool showClose()const; 176 bool showClose()const;
176 MimeTypes mimeTypes()const; 177 MimeTypes mimeTypes()const;
177 QStringList currentMimeType()const; 178 QStringList currentMimeType()const;
178 179
179private: 180private:
180 /* inits the Widgets */ 181 /* inits the Widgets */
181 void initUI(); 182 void initUI();
182 /* inits the MimeType ComboBox content + connects signals and slots */ 183 /* inits the MimeType ComboBox content + connects signals and slots */
183 void initMime(); 184 void initMime();
184 /* init the Views :) */ 185 /* init the Views :) */
185 void initViews(); 186 void initViews();
186 187
187 188
188 /* 189 /*
189 * register a view for deletion. 190 * register a view for deletion.
190 * This happens on creation of a OFileViewInterface 191 * This happens on creation of a OFileViewInterface
191 */ 192 */
192 void registerView( const Internal::OFileViewInterface* ); 193 void registerView( const Internal::OFileViewInterface* );
193 194
194private: 195private:
195 QLineEdit* m_lneEdit; // the LineEdit for the Name 196 QLineEdit* m_lneEdit; // the LineEdit for the Name
196 QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType 197 QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType
197 QWidgetStack* m_stack; // our widget stack which will contain the views 198 QWidgetStack* m_stack; // our widget stack which will contain the views
198 Internal::OFileViewInterface* currentView() const; // returns the currentView 199 Internal::OFileViewInterface* currentView() const; // returns the currentView
199 Internal::OFileViewInterface* m_current; // here is the view saved 200 Internal::OFileViewInterface* m_current; // here is the view saved
200 bool m_shNew : 1; // should we show New? 201 bool m_shNew : 1; // should we show New?
201 bool m_shClose : 1; // should we show Close? 202 bool m_shClose : 1; // should we show Close?
202 MimeTypes m_mimeType; // list of mimetypes 203 MimeTypes m_mimeType; // list of mimetypes
203 204
204 QMap<QString, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr 205 QMap<QString, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
205 /* views register themselves automatically */ 206 /* views register themselves automatically */
206 QList<Internal::OFileViewInterface> m_viewsPtr; 207 QList<Internal::OFileViewInterface> m_viewsPtr;
207 QHBox* m_nameBox; // the LineEdit + Label is hold here 208 QHBox* m_nameBox; // the LineEdit + Label is hold here
208 QHBox* m_cmbBox; // this holds the two combo boxes 209 QHBox* m_cmbBox; // this holds the two combo boxes
209 210
210 QString m_startDir; 211 QString m_startDir;
211 int m_mode; 212 int m_mode;
212 int m_selector; 213 int m_selector;
213 214
214 struct Data; // used for future versions 215 struct Data; // used for future versions
215 Data *d; 216 Data *d;
216 217
217private slots: 218private slots:
218 void slotMimeTypeChanged(); 219 void slotMimeTypeChanged();
219 220
220 /* will set the text of the lineedit and emit a fileChanged signal */ 221 /* will set the text of the lineedit and emit a fileChanged signal */
221 void slotDocLnkBridge( const DocLnk& ); 222 void slotDocLnkBridge( const DocLnk& );
222 void slotFileBridge( const QString& ); 223 void slotFileBridge( const QString& );
223 void slotViewChange( const QString& ); 224 void slotViewChange( const QString& );
224 225
225 bool eventFilter (QObject *o, QEvent *e); 226 bool eventFilter (QObject *o, QEvent *e);
226 227
227}; 228};
228 229
229} 230}
230} 231}
231 232
232#endif 233#endif