summaryrefslogtreecommitdiff
path: root/libopie
Unidiff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofiledialog.h4
-rw-r--r--libopie/ofileselector.cpp6
2 files changed, 5 insertions, 5 deletions
diff --git a/libopie/ofiledialog.h b/libopie/ofiledialog.h
index 91e0586..3b905c0 100644
--- a/libopie/ofiledialog.h
+++ b/libopie/ofiledialog.h
@@ -1,101 +1,101 @@
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 29
30#ifndef OpieFileDialog_h 30#ifndef OpieFileDialog_h
31#define OpieFileDialog_h 31#define OpieFileDialog_h
32 32
33#include <qdialog.h> 33#include <qdialog.h>
34 34
35#include <opie/ofileselector.h> 35#include <opie/ofileselector.h>
36 36
37/** 37/**
38 * This class places a OFileSelector inside a QDialog. 38 * This class places a OFileSelector inside a QDialog.
39 * It provides static method for letting a user chose 39 * It provides static method for letting a user chose
40 * a file for either opening or saving. 40 * a file for either opening or saving.
41 * Most of the time the c'tor will not be used instead using 41 * Most of the time the c'tor will not be used instead using
42 * the static member functions is prefered. 42 * the static member functions is prefered.
43 * 43 *
44 * <pre> 44 * <pre>
45 * QMap<QString, QStringList> mimeTypes; 45 * QMap<QString, QStringList> mimeTypes;
46 * QStringList types; 46 * QStringList types;
47 * types << "text[slash]* "; 47 * types << "text@slash* ";
48 * mimeTypes.insert( tr("Text"), types ); 48 * mimeTypes.insert( tr("Text"), types );
49 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment 49 * mimeTypes.insert( tr("All"), " *@slash* " ); // remove the spaces in the 2nd comment
50 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 50 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
51 * "foo","bar", mimeTypes); 51 * "foo","bar", mimeTypes);
52 * </pre> 52 * </pre>
53 * 53 *
54 * @short A small QDialog swalloing a FileSelector 54 * @short A small QDialog swalloing a FileSelector
55 * @see QDialog 55 * @see QDialog
56 * @see OFileSelector 56 * @see OFileSelector
57 * @version 0.1-unfinished 57 * @version 0.1-unfinished
58 * @author Holger Freyther ( zecke@handhelds.org ) 58 * @author Holger Freyther ( zecke@handhelds.org )
59 */ 59 */
60class OFileDialog : public QDialog { 60class OFileDialog : public QDialog {
61 Q_OBJECT 61 Q_OBJECT
62 public: 62 public:
63 OFileDialog(const QString &caption, 63 OFileDialog(const QString &caption,
64 QWidget *, int mode, int selector, 64 QWidget *, int mode, int selector,
65 const QString &dirName, 65 const QString &dirName,
66 const QString &fileName = QString::null, 66 const QString &fileName = QString::null,
67 const MimeTypes &mimetypes = MimeTypes() ); 67 const MimeTypes &mimetypes = MimeTypes() );
68 QString mimetype() const; 68 QString mimetype() const;
69 QString fileName() const; 69 QString fileName() const;
70 DocLnk selectedDocument()const; 70 DocLnk selectedDocument()const;
71 71
72 // static methods 72 // static methods
73 static QString getOpenFileName(int selector, 73 static QString getOpenFileName(int selector,
74 const QString& startDir = QString::null, 74 const QString& startDir = QString::null,
75 const QString &fileName = QString::null, 75 const QString &fileName = QString::null,
76 const MimeTypes& mime = MimeTypes(), 76 const MimeTypes& mime = MimeTypes(),
77 QWidget *wid = 0, 77 QWidget *wid = 0,
78 const QString &caption = QString::null ); 78 const QString &caption = QString::null );
79 79
80 static QString getSaveFileName(int selector, 80 static QString getSaveFileName(int selector,
81 const QString& startDir = QString::null, 81 const QString& startDir = QString::null,
82 const QString& fileName = QString::null, 82 const QString& fileName = QString::null,
83 const MimeTypes& mimefilter = MimeTypes(), 83 const MimeTypes& mimefilter = MimeTypes(),
84 QWidget *wid = 0, 84 QWidget *wid = 0,
85 const QString &caption = QString::null ); 85 const QString &caption = QString::null );
86 86
87 //let's OFileSelector catch up first 87 //let's OFileSelector catch up first
88 //static QString getExistingDirectory(const QString& startDir = QString::null, 88 //static QString getExistingDirectory(const QString& startDir = QString::null,
89 // QWidget *parent = 0, 89 // QWidget *parent = 0,
90 // const QString& caption = QString::null ); 90 // const QString& caption = QString::null );
91 private: 91 private:
92 class OFileDialogPrivate; 92 class OFileDialogPrivate;
93 OFileDialogPrivate *d; 93 OFileDialogPrivate *d;
94 OFileSelector *file; 94 OFileSelector *file;
95 95
96 private slots: 96 private slots:
97 void slotFileSelected( const QString & ); 97 void slotFileSelected( const QString & );
98 void slotDirSelected(const QString & ); 98 void slotDirSelected(const QString & );
99 void slotSelectorOk(); 99 void slotSelectorOk();
100}; 100};
101#endif 101#endif
diff --git a/libopie/ofileselector.cpp b/libopie/ofileselector.cpp
index 9afe9c7..9ac2981 100644
--- a/libopie/ofileselector.cpp
+++ b/libopie/ofileselector.cpp
@@ -129,806 +129,806 @@ QWidget* ODocumentFileView::widget( QWidget* parent ) {
129 if (!m_selector ) { 129 if (!m_selector ) {
130 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); 130 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() );
131 QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ), 131 QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ),
132 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); 132 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) );
133 QObject::connect(m_selector, SIGNAL(closeMe() ), 133 QObject::connect(m_selector, SIGNAL(closeMe() ),
134 selector(), SIGNAL(closeMe() ) ); 134 selector(), SIGNAL(closeMe() ) );
135 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ), 135 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ),
136 selector(), SIGNAL(newSelected(const DocLnk& ) ) ); 136 selector(), SIGNAL(newSelected(const DocLnk& ) ) );
137 } 137 }
138 138
139 return m_selector; 139 return m_selector;
140} 140}
141 141
142/* 142/*
143 * This is the file system view used 143 * This is the file system view used
144 * we use a QListView + QListViewItems for it 144 * we use a QListView + QListViewItems for it
145 */ 145 */
146 146
147OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, 147OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap,
148 const QString& path, const QString& date, 148 const QString& path, const QString& date,
149 const QString& size, const QString& dir, 149 const QString& size, const QString& dir,
150 bool isLocked, bool isDir ) 150 bool isLocked, bool isDir )
151 : QListViewItem( view ) 151 : QListViewItem( view )
152{ 152{
153 setPixmap(0, pixmap ); 153 setPixmap(0, pixmap );
154 setText(1, path ); 154 setText(1, path );
155 setText(2, size ); 155 setText(2, size );
156 setText(3, date ); 156 setText(3, date );
157 m_isDir = isDir; 157 m_isDir = isDir;
158 m_dir = dir; 158 m_dir = dir;
159 m_locked = isLocked; 159 m_locked = isLocked;
160} 160}
161OFileSelectorItem::~OFileSelectorItem() { 161OFileSelectorItem::~OFileSelectorItem() {
162 162
163} 163}
164bool OFileSelectorItem::isLocked()const { 164bool OFileSelectorItem::isLocked()const {
165 return m_locked; 165 return m_locked;
166} 166}
167QString OFileSelectorItem::directory()const { 167QString OFileSelectorItem::directory()const {
168 return m_dir; 168 return m_dir;
169} 169}
170bool OFileSelectorItem::isDir()const { 170bool OFileSelectorItem::isDir()const {
171 return m_isDir; 171 return m_isDir;
172} 172}
173QString OFileSelectorItem::path()const { 173QString OFileSelectorItem::path()const {
174 return text( 1 ); 174 return text( 1 );
175} 175}
176QString OFileSelectorItem::key( int id, bool )const { 176QString OFileSelectorItem::key( int id, bool )const {
177 QString ke; 177 QString ke;
178 if( id == 0 || id == 1 ){ // name 178 if( id == 0 || id == 1 ){ // name
179 if( m_isDir ){ 179 if( m_isDir ){
180 ke.append("0" ); 180 ke.append("0" );
181 ke.append( text(1) ); 181 ke.append( text(1) );
182 }else{ 182 }else{
183 ke.append("1" ); 183 ke.append("1" );
184 ke.append( text(1) ); 184 ke.append( text(1) );
185 } 185 }
186 return ke; 186 return ke;
187 }else 187 }else
188 return text( id ); 188 return text( id );
189 189
190} 190}
191 191
192OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, 192OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir,
193 OFileSelector* sel) 193 OFileSelector* sel)
194 : QWidget( parent ), m_sel( sel ) { 194 : QWidget( parent ), m_sel( sel ) {
195 m_all = false; 195 m_all = false;
196 QVBoxLayout* lay = new QVBoxLayout( this ); 196 QVBoxLayout* lay = new QVBoxLayout( this );
197 m_currentDir = startDir; 197 m_currentDir = startDir;
198 198
199 /* 199 /*
200 * now we add a special bar 200 * now we add a special bar
201 * One Button For Up 201 * One Button For Up
202 * Home 202 * Home
203 * Doc 203 * Doc
204 * And a dropdown menu with FileSystems 204 * And a dropdown menu with FileSystems
205 * FUTURE: one to change dir with lineedit 205 * FUTURE: one to change dir with lineedit
206 * Bookmarks 206 * Bookmarks
207 * Create Dir 207 * Create Dir
208 */ 208 */
209 QHBox* box = new QHBox(this ); 209 QHBox* box = new QHBox(this );
210 box->setBackgroundMode( PaletteButton ); 210 box->setBackgroundMode( PaletteButton );
211 box->setSpacing( 0 ); 211 box->setSpacing( 0 );
212 212
213 QToolButton *btn = new QToolButton( box ); 213 QToolButton *btn = new QToolButton( box );
214 btn->setIconSet( Resource::loadIconSet("up") ); 214 btn->setIconSet( Resource::loadIconSet("up") );
215 connect(btn, SIGNAL(clicked() ), 215 connect(btn, SIGNAL(clicked() ),
216 this, SLOT( cdUP() ) ); 216 this, SLOT( cdUP() ) );
217 217
218 btn = new QToolButton( box ); 218 btn = new QToolButton( box );
219 btn->setIconSet( Resource::loadIconSet("home") ); 219 btn->setIconSet( Resource::loadIconSet("home") );
220 connect(btn, SIGNAL(clicked() ), 220 connect(btn, SIGNAL(clicked() ),
221 this, SLOT( cdHome() ) ); 221 this, SLOT( cdHome() ) );
222 222
223 btn = new QToolButton( box ); 223 btn = new QToolButton( box );
224 btn->setIconSet( Resource::loadIconSet("DocsIcon") ); 224 btn->setIconSet( Resource::loadIconSet("DocsIcon") );
225 connect(btn, SIGNAL(clicked() ), 225 connect(btn, SIGNAL(clicked() ),
226 this, SLOT(cdDoc() ) ); 226 this, SLOT(cdDoc() ) );
227 227
228 m_btnNew = new QToolButton( box ); 228 m_btnNew = new QToolButton( box );
229 m_btnNew->setIconSet( Resource::loadIconSet("new") ); 229 m_btnNew->setIconSet( Resource::loadIconSet("new") );
230 connect(m_btnNew, SIGNAL(clicked() ), 230 connect(m_btnNew, SIGNAL(clicked() ),
231 this, SLOT(slotNew() ) ); 231 this, SLOT(slotNew() ) );
232 232
233 233
234 m_btnClose = new QToolButton( box ); 234 m_btnClose = new QToolButton( box );
235 m_btnClose->setIconSet( Resource::loadIconSet("close") ); 235 m_btnClose->setIconSet( Resource::loadIconSet("close") );
236 connect(m_btnClose, SIGNAL(clicked() ), 236 connect(m_btnClose, SIGNAL(clicked() ),
237 selector(), SIGNAL(closeMe() ) ); 237 selector(), SIGNAL(closeMe() ) );
238 238
239 btn = new QToolButton( box ); 239 btn = new QToolButton( box );
240 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); 240 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") );
241 241
242 /* let's fill device parts */ 242 /* let's fill device parts */
243 QPopupMenu* pop = new QPopupMenu(this); 243 QPopupMenu* pop = new QPopupMenu(this);
244 connect(pop, SIGNAL( activated(int) ), 244 connect(pop, SIGNAL( activated(int) ),
245 this, SLOT(slotFSActivated(int) ) ); 245 this, SLOT(slotFSActivated(int) ) );
246 246
247 StorageInfo storage; 247 StorageInfo storage;
248 const QList<FileSystem> &fs = storage.fileSystems(); 248 const QList<FileSystem> &fs = storage.fileSystems();
249 QListIterator<FileSystem> it(fs); 249 QListIterator<FileSystem> it(fs);
250 for ( ; it.current(); ++it ) { 250 for ( ; it.current(); ++it ) {
251 const QString disk = (*it)->name(); 251 const QString disk = (*it)->name();
252 const QString path = (*it)->path(); 252 const QString path = (*it)->path();
253 m_dev.insert( disk, path ); 253 m_dev.insert( disk, path );
254 pop->insertItem( disk ); 254 pop->insertItem( disk );
255 } 255 }
256 m_fsPop = pop; 256 m_fsPop = pop;
257 257
258 258
259 btn->setPopup( pop ); 259 btn->setPopup( pop );
260 260
261 lay->addWidget( box ); 261 lay->addWidget( box );
262 262
263 m_view = new QListView( this ); 263 m_view = new QListView( this );
264 264
265 m_view->installEventFilter(this); 265 m_view->installEventFilter(this);
266 266
267 QPEApplication::setStylusOperation( m_view->viewport(), 267 QPEApplication::setStylusOperation( m_view->viewport(),
268 QPEApplication::RightOnHold); 268 QPEApplication::RightOnHold);
269 m_view->addColumn(" " ); 269 m_view->addColumn(" " );
270 m_view->addColumn(tr("Name"), 135 ); 270 m_view->addColumn(tr("Name"), 135 );
271 m_view->addColumn(tr("Size"), -1 ); 271 m_view->addColumn(tr("Size"), -1 );
272 m_view->addColumn(tr("Date"), 60 ); 272 m_view->addColumn(tr("Date"), 60 );
273 m_view->addColumn(tr("Mime Type"), -1 ); 273 m_view->addColumn(tr("Mime Type"), -1 );
274 274
275 275
276 m_view->setSorting( 1 ); 276 m_view->setSorting( 1 );
277 m_view->setAllColumnsShowFocus( TRUE ); 277 m_view->setAllColumnsShowFocus( TRUE );
278 278
279 lay->addWidget( m_view, 1000 ); 279 lay->addWidget( m_view, 1000 );
280 connectSlots(); 280 connectSlots();
281} 281}
282OFileViewFileListView::~OFileViewFileListView() { 282OFileViewFileListView::~OFileViewFileListView() {
283} 283}
284void OFileViewFileListView::slotNew() { 284void OFileViewFileListView::slotNew() {
285 DocLnk lnk; 285 DocLnk lnk;
286 emit selector()->newSelected( lnk ); 286 emit selector()->newSelected( lnk );
287} 287}
288OFileSelectorItem* OFileViewFileListView::currentItem()const{ 288OFileSelectorItem* OFileViewFileListView::currentItem()const{
289 QListViewItem* item = m_view->currentItem(); 289 QListViewItem* item = m_view->currentItem();
290 if (!item ) 290 if (!item )
291 return 0l; 291 return 0l;
292 292
293 return static_cast<OFileSelectorItem*>(item); 293 return static_cast<OFileSelectorItem*>(item);
294} 294}
295void OFileViewFileListView::reread( bool all ) { 295void OFileViewFileListView::reread( bool all ) {
296 m_view->clear(); 296 m_view->clear();
297 297
298 if (selector()->showClose() ) 298 if (selector()->showClose() )
299 m_btnClose->show(); 299 m_btnClose->show();
300 else 300 else
301 m_btnClose->hide(); 301 m_btnClose->hide();
302 302
303 if (selector()->showNew() ) 303 if (selector()->showNew() )
304 m_btnNew->show(); 304 m_btnNew->show();
305 else 305 else
306 m_btnNew->hide(); 306 m_btnNew->hide();
307 307
308 m_mimes = selector()->currentMimeType(); 308 m_mimes = selector()->currentMimeType();
309 m_all = all; 309 m_all = all;
310 310
311 QDir dir( m_currentDir ); 311 QDir dir( m_currentDir );
312 if (!dir.exists() ) 312 if (!dir.exists() )
313 return; 313 return;
314 314
315 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); 315 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
316 int filter; 316 int filter;
317 if (m_all ) 317 if (m_all )
318 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; 318 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
319 else 319 else
320 filter = QDir::Files | QDir::Dirs | QDir::All; 320 filter = QDir::Files | QDir::Dirs | QDir::All;
321 dir.setFilter( filter ); 321 dir.setFilter( filter );
322 322
323 // now go through all files 323 // now go through all files
324 const QFileInfoList *list = dir.entryInfoList(); 324 const QFileInfoList *list = dir.entryInfoList();
325 if (!list) { 325 if (!list) {
326 cdUP(); 326 cdUP();
327 return; 327 return;
328 } 328 }
329 QFileInfoListIterator it( *list ); 329 QFileInfoListIterator it( *list );
330 QFileInfo *fi; 330 QFileInfo *fi;
331 while( (fi=it.current() ) ){ 331 while( (fi=it.current() ) ){
332 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ 332 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){
333 ++it; 333 ++it;
334 continue; 334 continue;
335 } 335 }
336 336
337 /* 337 /*
338 * It is a symlink we try to resolve it now but don't let us attack by DOS 338 * It is a symlink we try to resolve it now but don't let us attack by DOS
339 * 339 *
340 */ 340 */
341 if( fi->isSymLink() ){ 341 if( fi->isSymLink() ){
342 QString file = fi->dirPath( true ) + "/" + fi->readLink(); 342 QString file = fi->dirPath( true ) + "/" + fi->readLink();
343 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos 343 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos
344 QFileInfo info( file ); 344 QFileInfo info( file );
345 if( !info.exists() ){ 345 if( !info.exists() ){
346 addSymlink( fi, TRUE ); 346 addSymlink( fi, TRUE );
347 break; 347 break;
348 }else if( info.isDir() ){ 348 }else if( info.isDir() ){
349 addDir( fi, TRUE ); 349 addDir( fi, TRUE );
350 break; 350 break;
351 }else if( info.isFile() ){ 351 }else if( info.isFile() ){
352 addFile( fi, TRUE ); 352 addFile( fi, TRUE );
353 break; 353 break;
354 }else if( info.isSymLink() ){ 354 }else if( info.isSymLink() ){
355 file = info.dirPath(true ) + "/" + info.readLink() ; 355 file = info.dirPath(true ) + "/" + info.readLink() ;
356 break; 356 break;
357 }else if( i == 4){ // couldn't resolve symlink add it as symlink 357 }else if( i == 4){ // couldn't resolve symlink add it as symlink
358 addSymlink( fi ); 358 addSymlink( fi );
359 } 359 }
360 } // off for loop for symlink resolving 360 } // off for loop for symlink resolving
361 }else if( fi->isDir() ) 361 }else if( fi->isDir() )
362 addDir( fi ); 362 addDir( fi );
363 else if( fi->isFile() ) 363 else if( fi->isFile() )
364 addFile( fi ); 364 addFile( fi );
365 365
366 ++it; 366 ++it;
367 } // of while loop 367 } // of while loop
368 m_view->sort(); 368 m_view->sort();
369 369
370} 370}
371int OFileViewFileListView::fileCount()const{ 371int OFileViewFileListView::fileCount()const{
372 return m_view->childCount(); 372 return m_view->childCount();
373} 373}
374QString OFileViewFileListView::currentDir()const{ 374QString OFileViewFileListView::currentDir()const{
375 return m_currentDir; 375 return m_currentDir;
376} 376}
377OFileSelector* OFileViewFileListView::selector() { 377OFileSelector* OFileViewFileListView::selector() {
378 return m_sel; 378 return m_sel;
379} 379}
380 380
381bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { 381bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) {
382 if ( e->type() == QEvent::KeyPress ) { 382 if ( e->type() == QEvent::KeyPress ) {
383 QKeyEvent *k = (QKeyEvent *)e; 383 QKeyEvent *k = (QKeyEvent *)e;
384 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { 384 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
385 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); 385 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
386 return true; 386 return true;
387 } 387 }
388 } 388 }
389 return false; 389 return false;
390} 390}
391 391
392 392
393void OFileViewFileListView::connectSlots() { 393void OFileViewFileListView::connectSlots() {
394 connect(m_view, SIGNAL(clicked(QListViewItem*) ), 394 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
395 this, SLOT(slotCurrentChanged(QListViewItem*) ) ); 395 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
396 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), 396 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ),
397 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); 397 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) );
398} 398}
399void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { 399void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) {
400 if (!item) 400 if (!item)
401 return; 401 return;
402#if 0 402#if 0
403 403
404 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 404 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
405 405
406 if (!sel->isDir() ) { 406 if (!sel->isDir() ) {
407 selector()->m_lneEdit->setText( sel->text(1) ); 407 selector()->m_lneEdit->setText( sel->text(1) );
408 // if in fileselector mode we will emit selected 408 // if in fileselector mode we will emit selected
409 if ( selector()->mode() == OFileSelector::FileSelector ) { 409 if ( selector()->mode() == OFileSelector::FileSelector ) {
410 qWarning("slot Current Changed"); 410 qWarning("slot Current Changed");
411 QStringList str = QStringList::split("->", sel->text(1) ); 411 QStringList str = QStringList::split("->", sel->text(1) );
412 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 412 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
413 emit selector()->fileSelected( path ); 413 emit selector()->fileSelected( path );
414 DocLnk lnk( path ); 414 DocLnk lnk( path );
415 emit selector()->fileSelected( lnk ); 415 emit selector()->fileSelected( lnk );
416 } 416 }
417 } 417 }
418#endif 418#endif
419} 419}
420void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { 420void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) {
421 if (!item || ( button != Qt::LeftButton) ) 421 if (!item || ( button != Qt::LeftButton) )
422 return; 422 return;
423 423
424 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 424 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
425 if (!sel->isLocked() ) { 425 if (!sel->isLocked() ) {
426 QStringList str = QStringList::split("->", sel->text(1) ); 426 QStringList str = QStringList::split("->", sel->text(1) );
427 if (sel->isDir() ) { 427 if (sel->isDir() ) {
428 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); 428 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
429 emit selector()->dirSelected( m_currentDir ); 429 emit selector()->dirSelected( m_currentDir );
430 reread( m_all ); 430 reread( m_all );
431 }else { // file 431 }else { // file
432 qWarning("slot Clicked"); 432 qWarning("slot Clicked");
433 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); 433 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
434 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 434 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
435 emit selector()->fileSelected( path ); 435 emit selector()->fileSelected( path );
436 DocLnk lnk( path ); 436 DocLnk lnk( path );
437 emit selector()->fileSelected( lnk ); 437 emit selector()->fileSelected( lnk );
438 } 438 }
439 } // not locked 439 } // not locked
440} 440}
441void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { 441void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) {
442 MimeType type( info->absFilePath() ); 442 MimeType type( info->absFilePath() );
443 if (!compliesMime( type.id() ) ) 443 if (!compliesMime( type.id() ) )
444 return; 444 return;
445 445
446 QPixmap pix = type.pixmap(); 446 QPixmap pix = type.pixmap();
447 QString dir, name; bool locked; 447 QString dir, name; bool locked;
448 if ( pix.isNull() ) { 448 if ( pix.isNull() ) {
449 QWMatrix matrix; 449 QWMatrix matrix;
450 QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); 450 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
451 matrix.scale( .4, .4 ); 451 matrix.scale( .4, .4 );
452 pix = pixer.xForm( matrix ); 452 pix = pixer.xForm( matrix );
453 } 453 }
454 dir = info->dirPath( true ); 454 dir = info->dirPath( true );
455 locked = false; 455 locked = false;
456 if ( symlink ) 456 if ( symlink )
457 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); 457 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
458 else{ 458 else{
459 name = info->fileName(); 459 name = info->fileName();
460 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || 460 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
461 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { 461 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) {
462 locked = true; pix = Resource::loadPixmap("locked"); 462 locked = true; pix = Resource::loadPixmap("locked");
463 } 463 }
464 } 464 }
465 (void)new OFileSelectorItem( m_view, pix, name, 465 (void)new OFileSelectorItem( m_view, pix, name,
466 info->lastModified().toString(), QString::number( info->size() ), 466 info->lastModified().toString(), QString::number( info->size() ),
467 dir, locked ); 467 dir, locked );
468} 468}
469void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { 469void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) {
470 bool locked = false; QString name; QPixmap pix; 470 bool locked = false; QString name; QPixmap pix;
471 471
472 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || 472 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
473 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { 473 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) {
474 locked = true; 474 locked = true;
475 if ( symlink ) 475 if ( symlink )
476 pix = Resource::loadPixmap( "opie/symlink" ); 476 pix = Resource::loadPixmap( "opie/symlink" );
477 else 477 else
478 pix = Resource::loadPixmap( "lockedfolder" ); 478 pix = Resource::loadPixmap( "lockedfolder" );
479 }else 479 }else
480 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); 480 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
481 481
482 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : 482 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
483 info->fileName(); 483 info->fileName();
484 484
485 (void)new OFileSelectorItem( m_view, pix, name, 485 (void)new OFileSelectorItem( m_view, pix, name,
486 info->lastModified().toString(), 486 info->lastModified().toString(),
487 QString::number( info->size() ), 487 QString::number( info->size() ),
488 info->dirPath( true ), locked, true ); 488 info->dirPath( true ), locked, true );
489 489
490 490
491} 491}
492void OFileViewFileListView::addSymlink( QFileInfo* , bool ) { 492void OFileViewFileListView::addSymlink( QFileInfo* , bool ) {
493 493
494} 494}
495void OFileViewFileListView::cdUP() { 495void OFileViewFileListView::cdUP() {
496 QDir dir( m_currentDir ); 496 QDir dir( m_currentDir );
497 dir.cdUp(); 497 dir.cdUp();
498 498
499 if (!dir.exists() ) 499 if (!dir.exists() )
500 m_currentDir = "/"; 500 m_currentDir = "/";
501 else 501 else
502 m_currentDir = dir.absPath(); 502 m_currentDir = dir.absPath();
503 503
504 emit selector()->dirSelected( m_currentDir ); 504 emit selector()->dirSelected( m_currentDir );
505 reread( m_all ); 505 reread( m_all );
506} 506}
507void OFileViewFileListView::cdHome() { 507void OFileViewFileListView::cdHome() {
508 m_currentDir = QDir::homeDirPath(); 508 m_currentDir = QDir::homeDirPath();
509 emit selector()->dirSelected( m_currentDir ); 509 emit selector()->dirSelected( m_currentDir );
510 reread( m_all ); 510 reread( m_all );
511} 511}
512void OFileViewFileListView::cdDoc() { 512void OFileViewFileListView::cdDoc() {
513 m_currentDir = QPEApplication::documentDir(); 513 m_currentDir = QPEApplication::documentDir();
514 emit selector()->dirSelected( m_currentDir ); 514 emit selector()->dirSelected( m_currentDir );
515 reread( m_all ); 515 reread( m_all );
516} 516}
517void OFileViewFileListView::changeDir( const QString& dir ) { 517void OFileViewFileListView::changeDir( const QString& dir ) {
518 m_currentDir = dir; 518 m_currentDir = dir;
519 emit selector()->dirSelected( m_currentDir ); 519 emit selector()->dirSelected( m_currentDir );
520 reread( m_all ); 520 reread( m_all );
521} 521}
522void OFileViewFileListView::slotFSActivated( int id ) { 522void OFileViewFileListView::slotFSActivated( int id ) {
523 changeDir ( m_dev[m_fsPop->text(id)] ); 523 changeDir ( m_dev[m_fsPop->text(id)] );
524} 524}
525 525
526/* check if the mimetype in mime 526/* check if the mimetype in mime
527 * complies with the one which is current 527 * complies with the one which is current
528 */ 528 */
529/* 529/*
530 * We've the mimetype of the file 530 * We've the mimetype of the file
531 * We need to get the stringlist of the current mimetype 531 * We need to get the stringlist of the current mimetype
532 * 532 *
533 * mime = image@slashjpeg 533 * mime = image@slashjpeg
534 * QStringList = 'image@slash*' 534 * QStringList = 'image@slash*'
535 * or QStringList = image/jpeg;image/png;application/x-ogg 535 * or QStringList = image/jpeg;image/png;application/x-ogg
536 * or QStringList = application/x-ogg;image@slash*; 536 * or QStringList = application/x-ogg;image@slash*;
537 * with all these mime filters it should get acceptes 537 * with all these mime filters it should get acceptes
538 * to do so we need to look if mime is contained inside 538 * to do so we need to look if mime is contained inside
539 * the stringlist 539 * the stringlist
540 * if it's contained return true 540 * if it's contained return true
541 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' 541 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*'
542 * is contained in the mimefilter and then we will 542 * is contained in the mimefilter and then we will
543 * look if both are equal until the '/' 543 * look if both are equal until the '/'
544 */ 544 */
545bool OFileViewFileListView::compliesMime( const QString& str) { 545bool OFileViewFileListView::compliesMime( const QString& str) {
546 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) 546 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
547 return true; 547 return true;
548 548
549 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) { 549 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) {
550 QRegExp reg( (*it) ); 550 QRegExp reg( (*it) );
551 reg.setWildcard( true ); 551 reg.setWildcard( true );
552 if ( str.find( reg ) != -1 ) 552 if ( str.find( reg ) != -1 )
553 return true; 553 return true;
554 554
555 } 555 }
556 return false; 556 return false;
557} 557}
558/* 558/*
559 * The listView giving access to the file system! 559 * The listView giving access to the file system!
560 */ 560 */
561class OFileViewFileSystem : public OFileViewInterface { 561class OFileViewFileSystem : public OFileViewInterface {
562public: 562public:
563 OFileViewFileSystem( OFileSelector* ); 563 OFileViewFileSystem( OFileSelector* );
564 ~OFileViewFileSystem(); 564 ~OFileViewFileSystem();
565 565
566 QString selectedName() const; 566 QString selectedName() const;
567 QString selectedPath() const; 567 QString selectedPath() const;
568 568
569 QString directory()const; 569 QString directory()const;
570 void reread(); 570 void reread();
571 int fileCount()const; 571 int fileCount()const;
572 572
573 QWidget* widget( QWidget* parent ); 573 QWidget* widget( QWidget* parent );
574 void activate( const QString& ); 574 void activate( const QString& );
575private: 575private:
576 OFileViewFileListView* m_view; 576 OFileViewFileListView* m_view;
577 bool m_all : 1; 577 bool m_all : 1;
578}; 578};
579OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) 579OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
580 : OFileViewInterface( sel ) { 580 : OFileViewInterface( sel ) {
581 m_view = 0; 581 m_view = 0;
582 m_all = false; 582 m_all = false;
583} 583}
584OFileViewFileSystem::~OFileViewFileSystem() { 584OFileViewFileSystem::~OFileViewFileSystem() {
585} 585}
586QString OFileViewFileSystem::selectedName()const{ 586QString OFileViewFileSystem::selectedName()const{
587 if (!m_view ) 587 if (!m_view )
588 return QString::null; 588 return QString::null;
589 589
590 QString cFN=currentFileName(); 590 QString cFN=currentFileName();
591 if (cFN.startsWith("/")) return cFN; 591 if (cFN.startsWith("/")) return cFN;
592 return m_view->currentDir() + "/" + cFN; 592 return m_view->currentDir() + "/" + cFN;
593} 593}
594QString OFileViewFileSystem::selectedPath()const{ 594QString OFileViewFileSystem::selectedPath()const{
595 return QString::null; 595 return QString::null;
596} 596}
597QString OFileViewFileSystem::directory()const{ 597QString OFileViewFileSystem::directory()const{
598 if (!m_view) 598 if (!m_view)
599 return QString::null; 599 return QString::null;
600 600
601 OFileSelectorItem* item = m_view->currentItem(); 601 OFileSelectorItem* item = m_view->currentItem();
602 if (!item ) 602 if (!item )
603 return QString::null; 603 return QString::null;
604 604
605 return QDir(item->directory() ).absPath(); 605 return QDir(item->directory() ).absPath();
606} 606}
607void OFileViewFileSystem::reread() { 607void OFileViewFileSystem::reread() {
608 if (!m_view) 608 if (!m_view)
609 return; 609 return;
610 610
611 m_view->reread( m_all ); 611 m_view->reread( m_all );
612} 612}
613int OFileViewFileSystem::fileCount()const{ 613int OFileViewFileSystem::fileCount()const{
614 if (!m_view ) 614 if (!m_view )
615 return -1; 615 return -1;
616 return m_view->fileCount(); 616 return m_view->fileCount();
617} 617}
618QWidget* OFileViewFileSystem::widget( QWidget* parent ) { 618QWidget* OFileViewFileSystem::widget( QWidget* parent ) {
619 if (!m_view ) { 619 if (!m_view ) {
620 m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); 620 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
621 } 621 }
622 return m_view; 622 return m_view;
623} 623}
624void OFileViewFileSystem::activate( const QString& str) { 624void OFileViewFileSystem::activate( const QString& str) {
625 m_all = (str != QObject::tr("Files") ); 625 m_all = (str != QObject::tr("Files") );
626 626
627 627
628} 628}
629 629
630/* Selector */ 630/* Selector */
631/** 631/**
632 * @short new and complete c'tor 632 * @short new and complete c'tor
633 * 633 *
634 * Create a OFileSelector to let the user select a file. It can 634 * Create a OFileSelector to let the user select a file. It can
635 * either be used to open a file, select a save name in a dir or 635 * either be used to open a file, select a save name in a dir or
636 * as a dropin for the FileSelector. 636 * as a dropin for the FileSelector.
637 * 637 *
638 * <pre> 638 * <pre>
639 * QMap<QString, QStringList> mimeTypes; 639 * QMap<QString, QStringList> mimeTypes;
640 * QStringList types; 640 * QStringList types;
641 * types << "text[slash]* "; 641 * types << "text@slash* ";
642 * types << "audio[slash]*"; 642 * types << "audio@slash*";
643 * mimeTypes.insert( tr("Audio and Text"), types ); 643 * mimeTypes.insert( tr("Audio and Text"), types );
644 * mimeTypes.insert( tr("All"), "*[slash]*); 644 * mimeTypes.insert( tr("All"), "*@slash*);
645 * 645 *
646 * now you could create your fileselector 646 * now you could create your fileselector
647 * </pre> 647 * </pre>
648 * 648 *
649 * 649 *
650 * @param parent the parent of this widget 650 * @param parent the parent of this widget
651 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) 651 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR)
652 * @param sel The selector to be used 652 * @param sel The selector to be used
653 * @param dirName The name of the dir to start int 653 * @param dirName The name of the dir to start int
654 * @param fileName The fileName placed in the fileselector lineedit 654 * @param fileName The fileName placed in the fileselector lineedit
655 * @param mimetypes The MimeType map of used mimetypes 655 * @param mimetypes The MimeType map of used mimetypes
656 * @param showNew Show a New Button. Most likely to be used in the FileSelector view. 656 * @param showNew Show a New Button. Most likely to be used in the FileSelector view.
657 * @param showClose Show a Close Button. Most likely to be used in FileSelector view. 657 * @param showClose Show a Close Button. Most likely to be used in FileSelector view.
658 * 658 *
659 */ 659 */
660OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, 660OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
661 const QString& dirName, const QString& fileName, 661 const QString& dirName, const QString& fileName,
662 const MimeTypes& mimetypes, 662 const MimeTypes& mimetypes,
663 bool showNew, bool showClose) 663 bool showNew, bool showClose)
664 : QWidget( parent, "OFileSelector" ) 664 : QWidget( parent, "OFileSelector" )
665{ 665{
666 m_current = 0; 666 m_current = 0;
667 m_shNew = showNew; 667 m_shNew = showNew;
668 m_shClose = showClose; 668 m_shClose = showClose;
669 m_mimeType = mimetypes; 669 m_mimeType = mimetypes;
670 m_startDir = dirName; 670 m_startDir = dirName;
671 671
672 m_mode = mode; 672 m_mode = mode;
673 m_selector = sel; 673 m_selector = sel;
674 674
675 initUI(); 675 initUI();
676 m_lneEdit->setText( fileName ); 676 m_lneEdit->setText( fileName );
677 initMime(); 677 initMime();
678 initViews(); 678 initViews();
679 679
680 QString str; 680 QString str;
681 switch ( m_selector ) { 681 switch ( m_selector ) {
682 default: 682 default:
683 case Normal: 683 case Normal:
684 str = QObject::tr("Documents"); 684 str = QObject::tr("Documents");
685 m_cmbView->setCurrentItem( 0 ); 685 m_cmbView->setCurrentItem( 0 );
686 break; 686 break;
687 case Extended: 687 case Extended:
688 str = QObject::tr("Files"); 688 str = QObject::tr("Files");
689 m_cmbView->setCurrentItem( 1 ); 689 m_cmbView->setCurrentItem( 1 );
690 break; 690 break;
691 case ExtendedAll: 691 case ExtendedAll:
692 str = QObject::tr("All Files"); 692 str = QObject::tr("All Files");
693 m_cmbView->setCurrentItem( 2 ); 693 m_cmbView->setCurrentItem( 2 );
694 break; 694 break;
695 } 695 }
696 slotViewChange( str ); 696 slotViewChange( str );
697 697
698} 698}
699 699
700/** 700/**
701 * This a convience c'tor to just substitute the use of FileSelector 701 * This a convience c'tor to just substitute the use of FileSelector
702 */ 702 */
703OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, 703OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
704 bool showNew, bool showClose ) 704 bool showNew, bool showClose )
705 : QWidget( parent, name ) 705 : QWidget( parent, name )
706{ 706{
707 m_current = 0; 707 m_current = 0;
708 m_shNew = showNew; 708 m_shNew = showNew;
709 m_shClose = showClose; 709 m_shClose = showClose;
710 m_startDir = QPEApplication::documentDir(); 710 m_startDir = QPEApplication::documentDir();
711 711
712 if (!mimeFilter.isEmpty() ) 712 if (!mimeFilter.isEmpty() )
713 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); 713 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
714 714
715 m_mode = OFileSelector::FileSelector; 715 m_mode = OFileSelector::FileSelector;
716 m_selector = OFileSelector::Normal; 716 m_selector = OFileSelector::Normal;
717 717
718 initUI(); 718 initUI();
719 initMime(); 719 initMime();
720 initViews(); 720 initViews();
721 m_cmbView->setCurrentItem( 0 ); 721 m_cmbView->setCurrentItem( 0 );
722 slotViewChange( QObject::tr("Documents") ); 722 slotViewChange( QObject::tr("Documents") );
723} 723}
724/* 724/*
725 * INIT UI will set up the basic GUI 725 * INIT UI will set up the basic GUI
726 * Layout: Simple VBoxLayout 726 * Layout: Simple VBoxLayout
727 * On top a WidgetStack containing the Views... 727 * On top a WidgetStack containing the Views...
728 * - List View 728 * - List View
729 * - Document View 729 * - Document View
730 * Below we will have a Label + LineEdit 730 * Below we will have a Label + LineEdit
731 * Below we will have two ComoBoxes one for choosing the view one for 731 * Below we will have two ComoBoxes one for choosing the view one for
732 * choosing the mimetype 732 * choosing the mimetype
733 */ 733 */
734void OFileSelector::initUI() { 734void OFileSelector::initUI() {
735 QVBoxLayout* lay = new QVBoxLayout( this ); 735 QVBoxLayout* lay = new QVBoxLayout( this );
736 736
737 m_stack = new QWidgetStack( this ); 737 m_stack = new QWidgetStack( this );
738 lay->addWidget( m_stack, 1000 ); 738 lay->addWidget( m_stack, 1000 );
739 739
740 m_nameBox = new QHBox( this ); 740 m_nameBox = new QHBox( this );
741 (void)new QLabel( tr("Name:"), m_nameBox ); 741 (void)new QLabel( tr("Name:"), m_nameBox );
742 m_lneEdit = new QLineEdit( m_nameBox ); 742 m_lneEdit = new QLineEdit( m_nameBox );
743 m_lneEdit ->installEventFilter(this); 743 m_lneEdit ->installEventFilter(this);
744 lay->addWidget( m_nameBox ); 744 lay->addWidget( m_nameBox );
745 745
746 m_cmbBox = new QHBox( this ); 746 m_cmbBox = new QHBox( this );
747 m_cmbView = new QComboBox( m_cmbBox ); 747 m_cmbView = new QComboBox( m_cmbBox );
748 m_cmbMime = new QComboBox( m_cmbBox ); 748 m_cmbMime = new QComboBox( m_cmbBox );
749 lay->addWidget( m_cmbBox ); 749 lay->addWidget( m_cmbBox );
750} 750}
751 751
752/* 752/*
753 * This will make sure that the return key in the name edit causes dialogs to close 753 * This will make sure that the return key in the name edit causes dialogs to close
754 */ 754 */
755 755
756bool OFileSelector::eventFilter (QObject *o, QEvent *e) { 756bool OFileSelector::eventFilter (QObject *o, QEvent *e) {
757 if ( e->type() == QEvent::KeyPress ) { 757 if ( e->type() == QEvent::KeyPress ) {
758 QKeyEvent *k = (QKeyEvent *)e; 758 QKeyEvent *k = (QKeyEvent *)e;
759 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { 759 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
760 emit ok(); 760 emit ok();
761 return true; 761 return true;
762 } 762 }
763 } 763 }
764 return false; 764 return false;
765} 765}
766 766
767/* 767/*
768 * This will insert the MimeTypes into the Combo Box 768 * This will insert the MimeTypes into the Combo Box
769 * And also connect the changed signal 769 * And also connect the changed signal
770 * 770 *
771 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes 771 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
772 */ 772 */
773void OFileSelector::initMime() { 773void OFileSelector::initMime() {
774 MimeTypes::Iterator it; 774 MimeTypes::Iterator it;
775 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { 775 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) {
776 m_cmbMime->insertItem( it.key() ); 776 m_cmbMime->insertItem( it.key() );
777 } 777 }
778 m_cmbMime->setCurrentItem( 0 ); 778 m_cmbMime->setCurrentItem( 0 );
779 779
780 connect( m_cmbMime, SIGNAL(activated(int) ), 780 connect( m_cmbMime, SIGNAL(activated(int) ),
781 this, SLOT(slotMimeTypeChanged() ) ); 781 this, SLOT(slotMimeTypeChanged() ) );
782 782
783} 783}
784void OFileSelector::initViews() { 784void OFileSelector::initViews() {
785 m_cmbView->insertItem( QObject::tr("Documents") ); 785 m_cmbView->insertItem( QObject::tr("Documents") );
786 m_cmbView->insertItem( QObject::tr("Files") ); 786 m_cmbView->insertItem( QObject::tr("Files") );
787 m_cmbView->insertItem( QObject::tr("All Files") ); 787 m_cmbView->insertItem( QObject::tr("All Files") );
788 connect(m_cmbView, SIGNAL(activated( const QString& ) ), 788 connect(m_cmbView, SIGNAL(activated( const QString& ) ),
789 this, SLOT(slotViewChange( const QString& ) ) ); 789 this, SLOT(slotViewChange( const QString& ) ) );
790 790
791 791
792 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); 792 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
793 793
794 /* see above why add both */ 794 /* see above why add both */
795 OFileViewInterface* in = new OFileViewFileSystem( this ); 795 OFileViewInterface* in = new OFileViewFileSystem( this );
796 m_views.insert( QObject::tr("Files"), in ); 796 m_views.insert( QObject::tr("Files"), in );
797 m_views.insert( QObject::tr("All Files"), in ); 797 m_views.insert( QObject::tr("All Files"), in );
798} 798}
799 799
800/** 800/**
801 * d'tor 801 * d'tor
802 */ 802 */
803OFileSelector::~OFileSelector() { 803OFileSelector::~OFileSelector() {
804 804
805} 805}
806 806
807/** 807/**
808 * Convience function for the fileselector 808 * Convience function for the fileselector
809 * make sure to delete the DocLnk 809 * make sure to delete the DocLnk
810 * 810 *
811 * @see DocLnk 811 * @see DocLnk
812 * @todo remove in ODP 812 * @todo remove in ODP
813 */ 813 */
814const DocLnk* OFileSelector::selected() { 814const DocLnk* OFileSelector::selected() {
815 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); 815 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
816 return lnk; 816 return lnk;
817} 817}
818 818
819/** 819/**
820 * 820 *
821 * @return the name of the selected file 821 * @return the name of the selected file
822 */ 822 */
823QString OFileSelector::selectedName()const{ 823QString OFileSelector::selectedName()const{
824 return currentView()->selectedName(); 824 return currentView()->selectedName();
825} 825}
826 826
827/** 827/**
828 * @return the selected path 828 * @return the selected path
829 */ 829 */
830QString OFileSelector::selectedPath()const { 830QString OFileSelector::selectedPath()const {
831 return currentView()->selectedPath(); 831 return currentView()->selectedPath();
832} 832}
833 833
834/** 834/**
835 * @return the directory name 835 * @return the directory name
836 */ 836 */
837QString OFileSelector::directory()const { 837QString OFileSelector::directory()const {
838 return currentView()->directory(); 838 return currentView()->directory();
839} 839}
840 840
841/** 841/**
842 * @return a DocLnk for the selected document 842 * @return a DocLnk for the selected document
843 */ 843 */
844DocLnk OFileSelector::selectedDocument()const { 844DocLnk OFileSelector::selectedDocument()const {
845 return currentView()->selectedDocument(); 845 return currentView()->selectedDocument();
846} 846}
847 847
848/** 848/**
849 * @return the number of items for the current view 849 * @return the number of items for the current view
850 */ 850 */
851int OFileSelector::fileCount()const { 851int OFileSelector::fileCount()const {
852 return currentView()->fileCount(); 852 return currentView()->fileCount();
853} 853}
854 854
855/** 855/**
856 * @return reparse the file content 856 * @return reparse the file content
857 */ 857 */
858void OFileSelector::reread() { 858void OFileSelector::reread() {
859 return currentView()->reread(); 859 return currentView()->reread();
860} 860}
861OFileViewInterface* OFileSelector::currentView()const{ 861OFileViewInterface* OFileSelector::currentView()const{
862 return m_current; 862 return m_current;
863} 863}
864bool OFileSelector::showNew()const { 864bool OFileSelector::showNew()const {
865 return m_shNew; 865 return m_shNew;
866} 866}
867bool OFileSelector::showClose()const { 867bool OFileSelector::showClose()const {
868 return m_shClose; 868 return m_shClose;
869} 869}
870MimeTypes OFileSelector::mimeTypes()const { 870MimeTypes OFileSelector::mimeTypes()const {
871 return m_mimeType; 871 return m_mimeType;
872} 872}
873 873
874/** 874/**
875 * @return the Mode of the OFileSelector 875 * @return the Mode of the OFileSelector
876 */ 876 */
877int OFileSelector::mode()const{ 877int OFileSelector::mode()const{
878 return m_mode; 878 return m_mode;
879} 879}
880 880
881/** 881/**
882 * @return the Selector of the OFileSelector 882 * @return the Selector of the OFileSelector
883 */ 883 */
884int OFileSelector::selector()const{ 884int OFileSelector::selector()const{
885 return m_selector; 885 return m_selector;
886} 886}
887QStringList OFileSelector::currentMimeType()const { 887QStringList OFileSelector::currentMimeType()const {
888 return m_mimeType[m_cmbMime->currentText()]; 888 return m_mimeType[m_cmbMime->currentText()];
889} 889}
890void OFileSelector::slotMimeTypeChanged() { 890void OFileSelector::slotMimeTypeChanged() {
891 reread(); 891 reread();
892} 892}
893void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { 893void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) {
894 m_lneEdit->setText( lnk.name() ); 894 m_lneEdit->setText( lnk.name() );
895 emit fileSelected( lnk ); 895 emit fileSelected( lnk );
896 emit fileSelected( lnk.name() ); 896 emit fileSelected( lnk.name() );
897} 897}
898void OFileSelector::slotFileBridge( const QString& str) { 898void OFileSelector::slotFileBridge( const QString& str) {
899 DocLnk lnk( str ); 899 DocLnk lnk( str );
900 emit fileSelected( lnk ); 900 emit fileSelected( lnk );
901} 901}
902void OFileSelector::slotViewChange( const QString& view ) { 902void OFileSelector::slotViewChange( const QString& view ) {
903 OFileViewInterface* interface = m_views[view]; 903 OFileViewInterface* interface = m_views[view];
904 if (!interface) 904 if (!interface)
905 return; 905 return;
906 906
907 interface->activate( view ); 907 interface->activate( view );
908 if (m_current) 908 if (m_current)
909 m_stack->removeWidget( m_current->widget( m_stack ) ); 909 m_stack->removeWidget( m_current->widget( m_stack ) );
910 910
911 static int id = 1; 911 static int id = 1;
912 912
913 m_stack->addWidget( interface->widget(m_stack), id ); 913 m_stack->addWidget( interface->widget(m_stack), id );
914 m_stack->raiseWidget( id ); 914 m_stack->raiseWidget( id );
915 915
916 interface->reread(); 916 interface->reread();
917 m_current = interface; 917 m_current = interface;
918 918
919 id++; 919 id++;
920} 920}
921void OFileSelector::setNewVisible( bool b ) { 921void OFileSelector::setNewVisible( bool b ) {
922 m_shNew = b; 922 m_shNew = b;
923 currentView()->reread(); 923 currentView()->reread();
924} 924}
925void OFileSelector::setCloseVisible( bool b ) { 925void OFileSelector::setCloseVisible( bool b ) {
926 m_shClose = b; 926 m_shClose = b;
927 currentView()->reread(); 927 currentView()->reread();
928} 928}
929void OFileSelector::setNameVisible( bool b ) { 929void OFileSelector::setNameVisible( bool b ) {
930 if ( b ) 930 if ( b )
931 m_nameBox->show(); 931 m_nameBox->show();
932 else 932 else
933 m_nameBox->hide(); 933 m_nameBox->hide();
934} 934}