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