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