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