summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-02 16:05:42 (UTC)
committer zecke <zecke>2004-02-02 16:05:42 (UTC)
commit44e49951c71b277bd05ecc9857ec39d73a61b35e (patch) (unidiff)
tree1e55939962663d1b135bc4a23f5458d9751880bc
parent63746d6ac570b5935a75556a05fe92dacbc2d6ae (diff)
downloadopie-44e49951c71b277bd05ecc9857ec39d73a61b35e.zip
opie-44e49951c71b277bd05ecc9857ec39d73a61b35e.tar.gz
opie-44e49951c71b277bd05ecc9857ec39d73a61b35e.tar.bz2
Add some API Docu
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector.cpp78
-rw-r--r--libopie/ofileselector.h62
2 files changed, 139 insertions, 1 deletions
diff --git a/libopie/ofileselector.cpp b/libopie/ofileselector.cpp
index 577e916..9afe9c7 100644
--- a/libopie/ofileselector.cpp
+++ b/libopie/ofileselector.cpp
@@ -247,610 +247,688 @@ OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& st
247 StorageInfo storage; 247 StorageInfo storage;
248 const QList<FileSystem> &fs = storage.fileSystems(); 248 const QList<FileSystem> &fs = storage.fileSystems();
249 QListIterator<FileSystem> it(fs); 249 QListIterator<FileSystem> it(fs);
250 for ( ; it.current(); ++it ) { 250 for ( ; it.current(); ++it ) {
251 const QString disk = (*it)->name(); 251 const QString disk = (*it)->name();
252 const QString path = (*it)->path(); 252 const QString path = (*it)->path();
253 m_dev.insert( disk, path ); 253 m_dev.insert( disk, path );
254 pop->insertItem( disk ); 254 pop->insertItem( disk );
255 } 255 }
256 m_fsPop = pop; 256 m_fsPop = pop;
257 257
258 258
259 btn->setPopup( pop ); 259 btn->setPopup( pop );
260 260
261 lay->addWidget( box ); 261 lay->addWidget( box );
262 262
263 m_view = new QListView( this ); 263 m_view = new QListView( this );
264 264
265 m_view->installEventFilter(this); 265 m_view->installEventFilter(this);
266 266
267 QPEApplication::setStylusOperation( m_view->viewport(), 267 QPEApplication::setStylusOperation( m_view->viewport(),
268 QPEApplication::RightOnHold); 268 QPEApplication::RightOnHold);
269 m_view->addColumn(" " ); 269 m_view->addColumn(" " );
270 m_view->addColumn(tr("Name"), 135 ); 270 m_view->addColumn(tr("Name"), 135 );
271 m_view->addColumn(tr("Size"), -1 ); 271 m_view->addColumn(tr("Size"), -1 );
272 m_view->addColumn(tr("Date"), 60 ); 272 m_view->addColumn(tr("Date"), 60 );
273 m_view->addColumn(tr("Mime Type"), -1 ); 273 m_view->addColumn(tr("Mime Type"), -1 );
274 274
275 275
276 m_view->setSorting( 1 ); 276 m_view->setSorting( 1 );
277 m_view->setAllColumnsShowFocus( TRUE ); 277 m_view->setAllColumnsShowFocus( TRUE );
278 278
279 lay->addWidget( m_view, 1000 ); 279 lay->addWidget( m_view, 1000 );
280 connectSlots(); 280 connectSlots();
281} 281}
282OFileViewFileListView::~OFileViewFileListView() { 282OFileViewFileListView::~OFileViewFileListView() {
283} 283}
284void OFileViewFileListView::slotNew() { 284void OFileViewFileListView::slotNew() {
285 DocLnk lnk; 285 DocLnk lnk;
286 emit selector()->newSelected( lnk ); 286 emit selector()->newSelected( lnk );
287} 287}
288OFileSelectorItem* OFileViewFileListView::currentItem()const{ 288OFileSelectorItem* OFileViewFileListView::currentItem()const{
289 QListViewItem* item = m_view->currentItem(); 289 QListViewItem* item = m_view->currentItem();
290 if (!item ) 290 if (!item )
291 return 0l; 291 return 0l;
292 292
293 return static_cast<OFileSelectorItem*>(item); 293 return static_cast<OFileSelectorItem*>(item);
294} 294}
295void OFileViewFileListView::reread( bool all ) { 295void OFileViewFileListView::reread( bool all ) {
296 m_view->clear(); 296 m_view->clear();
297 297
298 if (selector()->showClose() ) 298 if (selector()->showClose() )
299 m_btnClose->show(); 299 m_btnClose->show();
300 else 300 else
301 m_btnClose->hide(); 301 m_btnClose->hide();
302 302
303 if (selector()->showNew() ) 303 if (selector()->showNew() )
304 m_btnNew->show(); 304 m_btnNew->show();
305 else 305 else
306 m_btnNew->hide(); 306 m_btnNew->hide();
307 307
308 m_mimes = selector()->currentMimeType(); 308 m_mimes = selector()->currentMimeType();
309 m_all = all; 309 m_all = all;
310 310
311 QDir dir( m_currentDir ); 311 QDir dir( m_currentDir );
312 if (!dir.exists() ) 312 if (!dir.exists() )
313 return; 313 return;
314 314
315 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); 315 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
316 int filter; 316 int filter;
317 if (m_all ) 317 if (m_all )
318 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; 318 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
319 else 319 else
320 filter = QDir::Files | QDir::Dirs | QDir::All; 320 filter = QDir::Files | QDir::Dirs | QDir::All;
321 dir.setFilter( filter ); 321 dir.setFilter( filter );
322 322
323 // now go through all files 323 // now go through all files
324 const QFileInfoList *list = dir.entryInfoList(); 324 const QFileInfoList *list = dir.entryInfoList();
325 if (!list) { 325 if (!list) {
326 cdUP(); 326 cdUP();
327 return; 327 return;
328 } 328 }
329 QFileInfoListIterator it( *list ); 329 QFileInfoListIterator it( *list );
330 QFileInfo *fi; 330 QFileInfo *fi;
331 while( (fi=it.current() ) ){ 331 while( (fi=it.current() ) ){
332 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ 332 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){
333 ++it; 333 ++it;
334 continue; 334 continue;
335 } 335 }
336 336
337 /* 337 /*
338 * It is a symlink we try to resolve it now but don't let us attack by DOS 338 * It is a symlink we try to resolve it now but don't let us attack by DOS
339 * 339 *
340 */ 340 */
341 if( fi->isSymLink() ){ 341 if( fi->isSymLink() ){
342 QString file = fi->dirPath( true ) + "/" + fi->readLink(); 342 QString file = fi->dirPath( true ) + "/" + fi->readLink();
343 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos 343 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos
344 QFileInfo info( file ); 344 QFileInfo info( file );
345 if( !info.exists() ){ 345 if( !info.exists() ){
346 addSymlink( fi, TRUE ); 346 addSymlink( fi, TRUE );
347 break; 347 break;
348 }else if( info.isDir() ){ 348 }else if( info.isDir() ){
349 addDir( fi, TRUE ); 349 addDir( fi, TRUE );
350 break; 350 break;
351 }else if( info.isFile() ){ 351 }else if( info.isFile() ){
352 addFile( fi, TRUE ); 352 addFile( fi, TRUE );
353 break; 353 break;
354 }else if( info.isSymLink() ){ 354 }else if( info.isSymLink() ){
355 file = info.dirPath(true ) + "/" + info.readLink() ; 355 file = info.dirPath(true ) + "/" + info.readLink() ;
356 break; 356 break;
357 }else if( i == 4){ // couldn't resolve symlink add it as symlink 357 }else if( i == 4){ // couldn't resolve symlink add it as symlink
358 addSymlink( fi ); 358 addSymlink( fi );
359 } 359 }
360 } // off for loop for symlink resolving 360 } // off for loop for symlink resolving
361 }else if( fi->isDir() ) 361 }else if( fi->isDir() )
362 addDir( fi ); 362 addDir( fi );
363 else if( fi->isFile() ) 363 else if( fi->isFile() )
364 addFile( fi ); 364 addFile( fi );
365 365
366 ++it; 366 ++it;
367 } // of while loop 367 } // of while loop
368 m_view->sort(); 368 m_view->sort();
369 369
370} 370}
371int OFileViewFileListView::fileCount()const{ 371int OFileViewFileListView::fileCount()const{
372 return m_view->childCount(); 372 return m_view->childCount();
373} 373}
374QString OFileViewFileListView::currentDir()const{ 374QString OFileViewFileListView::currentDir()const{
375 return m_currentDir; 375 return m_currentDir;
376} 376}
377OFileSelector* OFileViewFileListView::selector() { 377OFileSelector* OFileViewFileListView::selector() {
378 return m_sel; 378 return m_sel;
379} 379}
380 380
381bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { 381bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) {
382 if ( e->type() == QEvent::KeyPress ) { 382 if ( e->type() == QEvent::KeyPress ) {
383 QKeyEvent *k = (QKeyEvent *)e; 383 QKeyEvent *k = (QKeyEvent *)e;
384 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { 384 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
385 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); 385 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
386 return true; 386 return true;
387 } 387 }
388 } 388 }
389 return false; 389 return false;
390} 390}
391 391
392 392
393void OFileViewFileListView::connectSlots() { 393void OFileViewFileListView::connectSlots() {
394 connect(m_view, SIGNAL(clicked(QListViewItem*) ), 394 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
395 this, SLOT(slotCurrentChanged(QListViewItem*) ) ); 395 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
396 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), 396 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ),
397 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); 397 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) );
398} 398}
399void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { 399void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) {
400 if (!item) 400 if (!item)
401 return; 401 return;
402#if 0 402#if 0
403 403
404 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 404 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
405 405
406 if (!sel->isDir() ) { 406 if (!sel->isDir() ) {
407 selector()->m_lneEdit->setText( sel->text(1) ); 407 selector()->m_lneEdit->setText( sel->text(1) );
408 // if in fileselector mode we will emit selected 408 // if in fileselector mode we will emit selected
409 if ( selector()->mode() == OFileSelector::FileSelector ) { 409 if ( selector()->mode() == OFileSelector::FileSelector ) {
410 qWarning("slot Current Changed"); 410 qWarning("slot Current Changed");
411 QStringList str = QStringList::split("->", sel->text(1) ); 411 QStringList str = QStringList::split("->", sel->text(1) );
412 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 412 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
413 emit selector()->fileSelected( path ); 413 emit selector()->fileSelected( path );
414 DocLnk lnk( path ); 414 DocLnk lnk( path );
415 emit selector()->fileSelected( lnk ); 415 emit selector()->fileSelected( lnk );
416 } 416 }
417 } 417 }
418#endif 418#endif
419} 419}
420void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { 420void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) {
421 if (!item || ( button != Qt::LeftButton) ) 421 if (!item || ( button != Qt::LeftButton) )
422 return; 422 return;
423 423
424 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 424 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
425 if (!sel->isLocked() ) { 425 if (!sel->isLocked() ) {
426 QStringList str = QStringList::split("->", sel->text(1) ); 426 QStringList str = QStringList::split("->", sel->text(1) );
427 if (sel->isDir() ) { 427 if (sel->isDir() ) {
428 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); 428 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
429 emit selector()->dirSelected( m_currentDir ); 429 emit selector()->dirSelected( m_currentDir );
430 reread( m_all ); 430 reread( m_all );
431 }else { // file 431 }else { // file
432 qWarning("slot Clicked"); 432 qWarning("slot Clicked");
433 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); 433 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
434 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 434 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
435 emit selector()->fileSelected( path ); 435 emit selector()->fileSelected( path );
436 DocLnk lnk( path ); 436 DocLnk lnk( path );
437 emit selector()->fileSelected( lnk ); 437 emit selector()->fileSelected( lnk );
438 } 438 }
439 } // not locked 439 } // not locked
440} 440}
441void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { 441void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) {
442 MimeType type( info->absFilePath() ); 442 MimeType type( info->absFilePath() );
443 if (!compliesMime( type.id() ) ) 443 if (!compliesMime( type.id() ) )
444 return; 444 return;
445 445
446 QPixmap pix = type.pixmap(); 446 QPixmap pix = type.pixmap();
447 QString dir, name; bool locked; 447 QString dir, name; bool locked;
448 if ( pix.isNull() ) { 448 if ( pix.isNull() ) {
449 QWMatrix matrix; 449 QWMatrix matrix;
450 QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); 450 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
451 matrix.scale( .4, .4 ); 451 matrix.scale( .4, .4 );
452 pix = pixer.xForm( matrix ); 452 pix = pixer.xForm( matrix );
453 } 453 }
454 dir = info->dirPath( true ); 454 dir = info->dirPath( true );
455 locked = false; 455 locked = false;
456 if ( symlink ) 456 if ( symlink )
457 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); 457 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
458 else{ 458 else{
459 name = info->fileName(); 459 name = info->fileName();
460 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || 460 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
461 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { 461 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) {
462 locked = true; pix = Resource::loadPixmap("locked"); 462 locked = true; pix = Resource::loadPixmap("locked");
463 } 463 }
464 } 464 }
465 (void)new OFileSelectorItem( m_view, pix, name, 465 (void)new OFileSelectorItem( m_view, pix, name,
466 info->lastModified().toString(), QString::number( info->size() ), 466 info->lastModified().toString(), QString::number( info->size() ),
467 dir, locked ); 467 dir, locked );
468} 468}
469void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { 469void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) {
470 bool locked = false; QString name; QPixmap pix; 470 bool locked = false; QString name; QPixmap pix;
471 471
472 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || 472 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
473 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { 473 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) {
474 locked = true; 474 locked = true;
475 if ( symlink ) 475 if ( symlink )
476 pix = Resource::loadPixmap( "opie/symlink" ); 476 pix = Resource::loadPixmap( "opie/symlink" );
477 else 477 else
478 pix = Resource::loadPixmap( "lockedfolder" ); 478 pix = Resource::loadPixmap( "lockedfolder" );
479 }else 479 }else
480 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); 480 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
481 481
482 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : 482 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
483 info->fileName(); 483 info->fileName();
484 484
485 (void)new OFileSelectorItem( m_view, pix, name, 485 (void)new OFileSelectorItem( m_view, pix, name,
486 info->lastModified().toString(), 486 info->lastModified().toString(),
487 QString::number( info->size() ), 487 QString::number( info->size() ),
488 info->dirPath( true ), locked, true ); 488 info->dirPath( true ), locked, true );
489 489
490 490
491} 491}
492void OFileViewFileListView::addSymlink( QFileInfo* , bool ) { 492void OFileViewFileListView::addSymlink( QFileInfo* , bool ) {
493 493
494} 494}
495void OFileViewFileListView::cdUP() { 495void OFileViewFileListView::cdUP() {
496 QDir dir( m_currentDir ); 496 QDir dir( m_currentDir );
497 dir.cdUp(); 497 dir.cdUp();
498 498
499 if (!dir.exists() ) 499 if (!dir.exists() )
500 m_currentDir = "/"; 500 m_currentDir = "/";
501 else 501 else
502 m_currentDir = dir.absPath(); 502 m_currentDir = dir.absPath();
503 503
504 emit selector()->dirSelected( m_currentDir ); 504 emit selector()->dirSelected( m_currentDir );
505 reread( m_all ); 505 reread( m_all );
506} 506}
507void OFileViewFileListView::cdHome() { 507void OFileViewFileListView::cdHome() {
508 m_currentDir = QDir::homeDirPath(); 508 m_currentDir = QDir::homeDirPath();
509 emit selector()->dirSelected( m_currentDir ); 509 emit selector()->dirSelected( m_currentDir );
510 reread( m_all ); 510 reread( m_all );
511} 511}
512void OFileViewFileListView::cdDoc() { 512void OFileViewFileListView::cdDoc() {
513 m_currentDir = QPEApplication::documentDir(); 513 m_currentDir = QPEApplication::documentDir();
514 emit selector()->dirSelected( m_currentDir ); 514 emit selector()->dirSelected( m_currentDir );
515 reread( m_all ); 515 reread( m_all );
516} 516}
517void OFileViewFileListView::changeDir( const QString& dir ) { 517void OFileViewFileListView::changeDir( const QString& dir ) {
518 m_currentDir = dir; 518 m_currentDir = dir;
519 emit selector()->dirSelected( m_currentDir ); 519 emit selector()->dirSelected( m_currentDir );
520 reread( m_all ); 520 reread( m_all );
521} 521}
522void OFileViewFileListView::slotFSActivated( int id ) { 522void OFileViewFileListView::slotFSActivated( int id ) {
523 changeDir ( m_dev[m_fsPop->text(id)] ); 523 changeDir ( m_dev[m_fsPop->text(id)] );
524} 524}
525 525
526/* check if the mimetype in mime 526/* check if the mimetype in mime
527 * complies with the one which is current 527 * complies with the one which is current
528 */ 528 */
529/* 529/*
530 * We've the mimetype of the file 530 * We've the mimetype of the file
531 * We need to get the stringlist of the current mimetype 531 * We need to get the stringlist of the current mimetype
532 * 532 *
533 * mime = image@slashjpeg 533 * mime = image@slashjpeg
534 * QStringList = 'image@slash*' 534 * QStringList = 'image@slash*'
535 * or QStringList = image/jpeg;image/png;application/x-ogg 535 * or QStringList = image/jpeg;image/png;application/x-ogg
536 * or QStringList = application/x-ogg;image@slash*; 536 * or QStringList = application/x-ogg;image@slash*;
537 * with all these mime filters it should get acceptes 537 * with all these mime filters it should get acceptes
538 * to do so we need to look if mime is contained inside 538 * to do so we need to look if mime is contained inside
539 * the stringlist 539 * the stringlist
540 * if it's contained return true 540 * if it's contained return true
541 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' 541 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*'
542 * is contained in the mimefilter and then we will 542 * is contained in the mimefilter and then we will
543 * look if both are equal until the '/' 543 * look if both are equal until the '/'
544 */ 544 */
545bool OFileViewFileListView::compliesMime( const QString& str) { 545bool OFileViewFileListView::compliesMime( const QString& str) {
546 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) 546 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
547 return true; 547 return true;
548 548
549 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) { 549 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) {
550 QRegExp reg( (*it) ); 550 QRegExp reg( (*it) );
551 reg.setWildcard( true ); 551 reg.setWildcard( true );
552 if ( str.find( reg ) != -1 ) 552 if ( str.find( reg ) != -1 )
553 return true; 553 return true;
554 554
555 } 555 }
556 return false; 556 return false;
557} 557}
558/* 558/*
559 * The listView giving access to the file system! 559 * The listView giving access to the file system!
560 */ 560 */
561class OFileViewFileSystem : public OFileViewInterface { 561class OFileViewFileSystem : public OFileViewInterface {
562public: 562public:
563 OFileViewFileSystem( OFileSelector* ); 563 OFileViewFileSystem( OFileSelector* );
564 ~OFileViewFileSystem(); 564 ~OFileViewFileSystem();
565 565
566 QString selectedName() const; 566 QString selectedName() const;
567 QString selectedPath() const; 567 QString selectedPath() const;
568 568
569 QString directory()const; 569 QString directory()const;
570 void reread(); 570 void reread();
571 int fileCount()const; 571 int fileCount()const;
572 572
573 QWidget* widget( QWidget* parent ); 573 QWidget* widget( QWidget* parent );
574 void activate( const QString& ); 574 void activate( const QString& );
575private: 575private:
576 OFileViewFileListView* m_view; 576 OFileViewFileListView* m_view;
577 bool m_all : 1; 577 bool m_all : 1;
578}; 578};
579OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) 579OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
580 : OFileViewInterface( sel ) { 580 : OFileViewInterface( sel ) {
581 m_view = 0; 581 m_view = 0;
582 m_all = false; 582 m_all = false;
583} 583}
584OFileViewFileSystem::~OFileViewFileSystem() { 584OFileViewFileSystem::~OFileViewFileSystem() {
585} 585}
586QString OFileViewFileSystem::selectedName()const{ 586QString OFileViewFileSystem::selectedName()const{
587 if (!m_view ) 587 if (!m_view )
588 return QString::null; 588 return QString::null;
589 589
590 QString cFN=currentFileName(); 590 QString cFN=currentFileName();
591 if (cFN.startsWith("/")) return cFN; 591 if (cFN.startsWith("/")) return cFN;
592 return m_view->currentDir() + "/" + cFN; 592 return m_view->currentDir() + "/" + cFN;
593} 593}
594QString OFileViewFileSystem::selectedPath()const{ 594QString OFileViewFileSystem::selectedPath()const{
595 return QString::null; 595 return QString::null;
596} 596}
597QString OFileViewFileSystem::directory()const{ 597QString OFileViewFileSystem::directory()const{
598 if (!m_view) 598 if (!m_view)
599 return QString::null; 599 return QString::null;
600 600
601 OFileSelectorItem* item = m_view->currentItem(); 601 OFileSelectorItem* item = m_view->currentItem();
602 if (!item ) 602 if (!item )
603 return QString::null; 603 return QString::null;
604 604
605 return QDir(item->directory() ).absPath(); 605 return QDir(item->directory() ).absPath();
606} 606}
607void OFileViewFileSystem::reread() { 607void OFileViewFileSystem::reread() {
608 if (!m_view) 608 if (!m_view)
609 return; 609 return;
610 610
611 m_view->reread( m_all ); 611 m_view->reread( m_all );
612} 612}
613int OFileViewFileSystem::fileCount()const{ 613int OFileViewFileSystem::fileCount()const{
614 if (!m_view ) 614 if (!m_view )
615 return -1; 615 return -1;
616 return m_view->fileCount(); 616 return m_view->fileCount();
617} 617}
618QWidget* OFileViewFileSystem::widget( QWidget* parent ) { 618QWidget* OFileViewFileSystem::widget( QWidget* parent ) {
619 if (!m_view ) { 619 if (!m_view ) {
620 m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); 620 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
621 } 621 }
622 return m_view; 622 return m_view;
623} 623}
624void OFileViewFileSystem::activate( const QString& str) { 624void OFileViewFileSystem::activate( const QString& str) {
625 m_all = (str != QObject::tr("Files") ); 625 m_all = (str != QObject::tr("Files") );
626 626
627 627
628} 628}
629 629
630/* Selector */ 630/* Selector */
631/**
632 * @short new and complete c'tor
633 *
634 * Create a OFileSelector to let the user select a file. It can
635 * either be used to open a file, select a save name in a dir or
636 * as a dropin for the FileSelector.
637 *
638 * <pre>
639 * QMap<QString, QStringList> mimeTypes;
640 * QStringList types;
641 * types << "text[slash]* ";
642 * types << "audio[slash]*";
643 * mimeTypes.insert( tr("Audio and Text"), types );
644 * mimeTypes.insert( tr("All"), "*[slash]*);
645 *
646 * now you could create your fileselector
647 * </pre>
648 *
649 *
650 * @param parent the parent of this widget
651 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR)
652 * @param sel The selector to be used
653 * @param dirName The name of the dir to start int
654 * @param fileName The fileName placed in the fileselector lineedit
655 * @param mimetypes The MimeType map of used mimetypes
656 * @param showNew Show a New Button. Most likely to be used in the FileSelector view.
657 * @param showClose Show a Close Button. Most likely to be used in FileSelector view.
658 *
659 */
631OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, 660OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
632 const QString& dirName, const QString& fileName, 661 const QString& dirName, const QString& fileName,
633 const MimeTypes& mimetypes, 662 const MimeTypes& mimetypes,
634 bool showNew, bool showClose) 663 bool showNew, bool showClose)
635 : QWidget( parent, "OFileSelector" ) 664 : QWidget( parent, "OFileSelector" )
636{ 665{
637 m_current = 0; 666 m_current = 0;
638 m_shNew = showNew; 667 m_shNew = showNew;
639 m_shClose = showClose; 668 m_shClose = showClose;
640 m_mimeType = mimetypes; 669 m_mimeType = mimetypes;
641 m_startDir = dirName; 670 m_startDir = dirName;
642 671
643 m_mode = mode; 672 m_mode = mode;
644 m_selector = sel; 673 m_selector = sel;
645 674
646 initUI(); 675 initUI();
647 m_lneEdit->setText( fileName ); 676 m_lneEdit->setText( fileName );
648 initMime(); 677 initMime();
649 initViews(); 678 initViews();
650 679
651 QString str; 680 QString str;
652 switch ( m_selector ) { 681 switch ( m_selector ) {
653 default: 682 default:
654 case Normal: 683 case Normal:
655 str = QObject::tr("Documents"); 684 str = QObject::tr("Documents");
656 m_cmbView->setCurrentItem( 0 ); 685 m_cmbView->setCurrentItem( 0 );
657 break; 686 break;
658 case Extended: 687 case Extended:
659 str = QObject::tr("Files"); 688 str = QObject::tr("Files");
660 m_cmbView->setCurrentItem( 1 ); 689 m_cmbView->setCurrentItem( 1 );
661 break; 690 break;
662 case ExtendedAll: 691 case ExtendedAll:
663 str = QObject::tr("All Files"); 692 str = QObject::tr("All Files");
664 m_cmbView->setCurrentItem( 2 ); 693 m_cmbView->setCurrentItem( 2 );
665 break; 694 break;
666 } 695 }
667 slotViewChange( str ); 696 slotViewChange( str );
668 697
669} 698}
699
700/**
701 * This a convience c'tor to just substitute the use of FileSelector
702 */
670OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, 703OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
671 bool showNew, bool showClose ) 704 bool showNew, bool showClose )
672 : QWidget( parent, name ) 705 : QWidget( parent, name )
673{ 706{
674 m_current = 0; 707 m_current = 0;
675 m_shNew = showNew; 708 m_shNew = showNew;
676 m_shClose = showClose; 709 m_shClose = showClose;
677 m_startDir = QPEApplication::documentDir(); 710 m_startDir = QPEApplication::documentDir();
678 711
679 if (!mimeFilter.isEmpty() ) 712 if (!mimeFilter.isEmpty() )
680 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); 713 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
681 714
682 m_mode = OFileSelector::FileSelector; 715 m_mode = OFileSelector::FileSelector;
683 m_selector = OFileSelector::Normal; 716 m_selector = OFileSelector::Normal;
684 717
685 initUI(); 718 initUI();
686 initMime(); 719 initMime();
687 initViews(); 720 initViews();
688 m_cmbView->setCurrentItem( 0 ); 721 m_cmbView->setCurrentItem( 0 );
689 slotViewChange( QObject::tr("Documents") ); 722 slotViewChange( QObject::tr("Documents") );
690} 723}
691/* 724/*
692 * INIT UI will set up the basic GUI 725 * INIT UI will set up the basic GUI
693 * Layout: Simple VBoxLayout 726 * Layout: Simple VBoxLayout
694 * On top a WidgetStack containing the Views... 727 * On top a WidgetStack containing the Views...
695 * - List View 728 * - List View
696 * - Document View 729 * - Document View
697 * Below we will have a Label + LineEdit 730 * Below we will have a Label + LineEdit
698 * Below we will have two ComoBoxes one for choosing the view one for 731 * Below we will have two ComoBoxes one for choosing the view one for
699 * choosing the mimetype 732 * choosing the mimetype
700 */ 733 */
701void OFileSelector::initUI() { 734void OFileSelector::initUI() {
702 QVBoxLayout* lay = new QVBoxLayout( this ); 735 QVBoxLayout* lay = new QVBoxLayout( this );
703 736
704 m_stack = new QWidgetStack( this ); 737 m_stack = new QWidgetStack( this );
705 lay->addWidget( m_stack, 1000 ); 738 lay->addWidget( m_stack, 1000 );
706 739
707 m_nameBox = new QHBox( this ); 740 m_nameBox = new QHBox( this );
708 (void)new QLabel( tr("Name:"), m_nameBox ); 741 (void)new QLabel( tr("Name:"), m_nameBox );
709 m_lneEdit = new QLineEdit( m_nameBox ); 742 m_lneEdit = new QLineEdit( m_nameBox );
710 m_lneEdit ->installEventFilter(this); 743 m_lneEdit ->installEventFilter(this);
711 lay->addWidget( m_nameBox ); 744 lay->addWidget( m_nameBox );
712 745
713 m_cmbBox = new QHBox( this ); 746 m_cmbBox = new QHBox( this );
714 m_cmbView = new QComboBox( m_cmbBox ); 747 m_cmbView = new QComboBox( m_cmbBox );
715 m_cmbMime = new QComboBox( m_cmbBox ); 748 m_cmbMime = new QComboBox( m_cmbBox );
716 lay->addWidget( m_cmbBox ); 749 lay->addWidget( m_cmbBox );
717} 750}
718 751
719/* 752/*
720 * This will make sure that the return key in the name edit causes dialogs to close 753 * This will make sure that the return key in the name edit causes dialogs to close
721 */ 754 */
722 755
723bool OFileSelector::eventFilter (QObject *o, QEvent *e) { 756bool OFileSelector::eventFilter (QObject *o, QEvent *e) {
724 if ( e->type() == QEvent::KeyPress ) { 757 if ( e->type() == QEvent::KeyPress ) {
725 QKeyEvent *k = (QKeyEvent *)e; 758 QKeyEvent *k = (QKeyEvent *)e;
726 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { 759 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
727 emit ok(); 760 emit ok();
728 return true; 761 return true;
729 } 762 }
730 } 763 }
731 return false; 764 return false;
732} 765}
733 766
734/* 767/*
735 * This will insert the MimeTypes into the Combo Box 768 * This will insert the MimeTypes into the Combo Box
736 * And also connect the changed signal 769 * And also connect the changed signal
737 * 770 *
738 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes 771 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
739 */ 772 */
740void OFileSelector::initMime() { 773void OFileSelector::initMime() {
741 MimeTypes::Iterator it; 774 MimeTypes::Iterator it;
742 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { 775 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) {
743 m_cmbMime->insertItem( it.key() ); 776 m_cmbMime->insertItem( it.key() );
744 } 777 }
745 m_cmbMime->setCurrentItem( 0 ); 778 m_cmbMime->setCurrentItem( 0 );
746 779
747 connect( m_cmbMime, SIGNAL(activated(int) ), 780 connect( m_cmbMime, SIGNAL(activated(int) ),
748 this, SLOT(slotMimeTypeChanged() ) ); 781 this, SLOT(slotMimeTypeChanged() ) );
749 782
750} 783}
751void OFileSelector::initViews() { 784void OFileSelector::initViews() {
752 m_cmbView->insertItem( QObject::tr("Documents") ); 785 m_cmbView->insertItem( QObject::tr("Documents") );
753 m_cmbView->insertItem( QObject::tr("Files") ); 786 m_cmbView->insertItem( QObject::tr("Files") );
754 m_cmbView->insertItem( QObject::tr("All Files") ); 787 m_cmbView->insertItem( QObject::tr("All Files") );
755 connect(m_cmbView, SIGNAL(activated( const QString& ) ), 788 connect(m_cmbView, SIGNAL(activated( const QString& ) ),
756 this, SLOT(slotViewChange( const QString& ) ) ); 789 this, SLOT(slotViewChange( const QString& ) ) );
757 790
758 791
759 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); 792 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
760 793
761 /* see above why add both */ 794 /* see above why add both */
762 OFileViewInterface* in = new OFileViewFileSystem( this ); 795 OFileViewInterface* in = new OFileViewFileSystem( this );
763 m_views.insert( QObject::tr("Files"), in ); 796 m_views.insert( QObject::tr("Files"), in );
764 m_views.insert( QObject::tr("All Files"), in ); 797 m_views.insert( QObject::tr("All Files"), in );
765} 798}
799
800/**
801 * d'tor
802 */
766OFileSelector::~OFileSelector() { 803OFileSelector::~OFileSelector() {
767 804
768} 805}
806
807/**
808 * Convience function for the fileselector
809 * make sure to delete the DocLnk
810 *
811 * @see DocLnk
812 * @todo remove in ODP
813 */
769const DocLnk* OFileSelector::selected() { 814const DocLnk* OFileSelector::selected() {
770 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); 815 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
771 return lnk; 816 return lnk;
772} 817}
818
819/**
820 *
821 * @return the name of the selected file
822 */
773QString OFileSelector::selectedName()const{ 823QString OFileSelector::selectedName()const{
774 return currentView()->selectedName(); 824 return currentView()->selectedName();
775} 825}
826
827/**
828 * @return the selected path
829 */
776QString OFileSelector::selectedPath()const { 830QString OFileSelector::selectedPath()const {
777 return currentView()->selectedPath(); 831 return currentView()->selectedPath();
778} 832}
833
834/**
835 * @return the directory name
836 */
779QString OFileSelector::directory()const { 837QString OFileSelector::directory()const {
780 return currentView()->directory(); 838 return currentView()->directory();
781} 839}
840
841/**
842 * @return a DocLnk for the selected document
843 */
782DocLnk OFileSelector::selectedDocument()const { 844DocLnk OFileSelector::selectedDocument()const {
783 return currentView()->selectedDocument(); 845 return currentView()->selectedDocument();
784} 846}
847
848/**
849 * @return the number of items for the current view
850 */
785int OFileSelector::fileCount()const { 851int OFileSelector::fileCount()const {
786 return currentView()->fileCount(); 852 return currentView()->fileCount();
787} 853}
854
855/**
856 * @return reparse the file content
857 */
788void OFileSelector::reread() { 858void OFileSelector::reread() {
789 return currentView()->reread(); 859 return currentView()->reread();
790} 860}
791OFileViewInterface* OFileSelector::currentView()const{ 861OFileViewInterface* OFileSelector::currentView()const{
792 return m_current; 862 return m_current;
793} 863}
794bool OFileSelector::showNew()const { 864bool OFileSelector::showNew()const {
795 return m_shNew; 865 return m_shNew;
796} 866}
797bool OFileSelector::showClose()const { 867bool OFileSelector::showClose()const {
798 return m_shClose; 868 return m_shClose;
799} 869}
800MimeTypes OFileSelector::mimeTypes()const { 870MimeTypes OFileSelector::mimeTypes()const {
801 return m_mimeType; 871 return m_mimeType;
802} 872}
873
874/**
875 * @return the Mode of the OFileSelector
876 */
803int OFileSelector::mode()const{ 877int OFileSelector::mode()const{
804 return m_mode; 878 return m_mode;
805} 879}
880
881/**
882 * @return the Selector of the OFileSelector
883 */
806int OFileSelector::selector()const{ 884int OFileSelector::selector()const{
807 return m_selector; 885 return m_selector;
808} 886}
809QStringList OFileSelector::currentMimeType()const { 887QStringList OFileSelector::currentMimeType()const {
810 return m_mimeType[m_cmbMime->currentText()]; 888 return m_mimeType[m_cmbMime->currentText()];
811} 889}
812void OFileSelector::slotMimeTypeChanged() { 890void OFileSelector::slotMimeTypeChanged() {
813 reread(); 891 reread();
814} 892}
815void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { 893void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) {
816 m_lneEdit->setText( lnk.name() ); 894 m_lneEdit->setText( lnk.name() );
817 emit fileSelected( lnk ); 895 emit fileSelected( lnk );
818 emit fileSelected( lnk.name() ); 896 emit fileSelected( lnk.name() );
819} 897}
820void OFileSelector::slotFileBridge( const QString& str) { 898void OFileSelector::slotFileBridge( const QString& str) {
821 DocLnk lnk( str ); 899 DocLnk lnk( str );
822 emit fileSelected( lnk ); 900 emit fileSelected( lnk );
823} 901}
824void OFileSelector::slotViewChange( const QString& view ) { 902void OFileSelector::slotViewChange( const QString& view ) {
825 OFileViewInterface* interface = m_views[view]; 903 OFileViewInterface* interface = m_views[view];
826 if (!interface) 904 if (!interface)
827 return; 905 return;
828 906
829 interface->activate( view ); 907 interface->activate( view );
830 if (m_current) 908 if (m_current)
831 m_stack->removeWidget( m_current->widget( m_stack ) ); 909 m_stack->removeWidget( m_current->widget( m_stack ) );
832 910
833 static int id = 1; 911 static int id = 1;
834 912
835 m_stack->addWidget( interface->widget(m_stack), id ); 913 m_stack->addWidget( interface->widget(m_stack), id );
836 m_stack->raiseWidget( id ); 914 m_stack->raiseWidget( id );
837 915
838 interface->reread(); 916 interface->reread();
839 m_current = interface; 917 m_current = interface;
840 918
841 id++; 919 id++;
842} 920}
843void OFileSelector::setNewVisible( bool b ) { 921void OFileSelector::setNewVisible( bool b ) {
844 m_shNew = b; 922 m_shNew = b;
845 currentView()->reread(); 923 currentView()->reread();
846} 924}
847void OFileSelector::setCloseVisible( bool b ) { 925void OFileSelector::setCloseVisible( bool b ) {
848 m_shClose = b; 926 m_shClose = b;
849 currentView()->reread(); 927 currentView()->reread();
850} 928}
851void OFileSelector::setNameVisible( bool b ) { 929void OFileSelector::setNameVisible( bool b ) {
852 if ( b ) 930 if ( b )
853 m_nameBox->show(); 931 m_nameBox->show();
854 else 932 else
855 m_nameBox->hide(); 933 m_nameBox->hide();
856} 934}
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h
index bdb3e56..767455c 100644
--- a/libopie/ofileselector.h
+++ b/libopie/ofileselector.h
@@ -1,150 +1,210 @@
1/* 1/*
2 This is based on code and ideas of 2 This is based on code and ideas of
3 L. J. Potter ljp@llornkcor.com 3 L. J. Potter ljp@llornkcor.com
4 Thanks a lot 4 Thanks a lot
5 5
6 6
7               =. This file is part of the OPIE Project 7               =. This file is part of the OPIE Project
8             .=l. Copyright (c) 2002,2003 Holger Freyther <zecke@handhelds.org> 8             .=l. Copyright (c) 2002,2003 Holger Freyther <zecke@handhelds.org>
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This library is free software; you can 10 _;:,     .>    :=|. This library is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This library is distributed in the hope that 17    .i_,=:_.      -<s. This library is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34 34
35#ifndef OPIE_OFILESELECTOR_FOO_H 35#ifndef OPIE_OFILESELECTOR_FOO_H
36#define OPIE_OFILESELECTOR_FOO_H 36#define OPIE_OFILESELECTOR_FOO_H
37 37
38#include <qlist.h> 38#include <qlist.h>
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qmap.h> 40#include <qmap.h>
41#include <qvaluelist.h> 41#include <qvaluelist.h>
42#include <qstringlist.h> 42#include <qstringlist.h>
43 43
44#include <qpe/applnk.h> 44#include <qpe/applnk.h>
45 45
46typedef QMap<QString, QStringList> MimeTypes; 46typedef QMap<QString, QStringList> MimeTypes;
47 47
48class OFileViewInterface; 48class OFileViewInterface;
49class OFileViewFileListView; 49class OFileViewFileListView;
50class QLineEdit; 50class QLineEdit;
51class QComboBox; 51class QComboBox;
52class QWidgetStack; 52class QWidgetStack;
53class QHBox; 53class QHBox;
54
55
56/**
57 * @short a dropin replacement for the FileSelector
58 *
59 * This class is first used insert the OFileDialog.
60 * It supports multiple view and mimetype filtering for now.
61 *
62 * @see OFileDialog
63 * @see FileSelector
64 * @author zecke
65 * @version 0.1
66 */
54class OFileSelector : public QWidget { 67class OFileSelector : public QWidget {
55 Q_OBJECT 68 Q_OBJECT
56 friend class OFileViewInterface; 69 friend class OFileViewInterface;
57 friend class OFileViewFileListView; 70 friend class OFileViewFileListView;
58public: 71public:
72 /**
73 * The Mode of the Fileselector
74 * Open = Open A File
75 * Save = Save a File
76 * FILESELECTOR = As A GUI in a screen to select a file
77 */
59 enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; 78 enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 };
60// enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; 79// enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
80 /**
81 * Normal = The old FileSelector
82 * Extended = Dir View
83 * ExtendedAll = Dir View with all hidden files
84 * Default = What the vendor considers best
85 */
61 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; 86 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 };
62// enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; 87// enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2};
63 88
89
64 OFileSelector(QWidget* parent, int mode, int selector, 90 OFileSelector(QWidget* parent, int mode, int selector,
65 const QString& dirName, 91 const QString& dirName,
66 const QString& fileName, 92 const QString& fileName,
67 const MimeTypes& mimetypes = MimeTypes(), 93 const MimeTypes& mimetypes = MimeTypes(),
68 bool newVisible = FALSE, bool closeVisible = FALSE ); 94 bool newVisible = FALSE, bool closeVisible = FALSE );
69 95
70 OFileSelector(const QString& mimeFilter, QWidget* parent, 96 OFileSelector(const QString& mimeFilter, QWidget* parent,
71 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); 97 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE );
72 ~OFileSelector(); 98 ~OFileSelector();
73 99
74 const DocLnk* selected(); 100 const DocLnk* selected();
75 101
76 QString selectedName()const; 102 QString selectedName()const;
77 QString selectedPath()const; 103 QString selectedPath()const;
78 QString directory()const; 104 QString directory()const;
79 105
80 DocLnk selectedDocument()const; 106 DocLnk selectedDocument()const;
81 107
82 int fileCount()const; 108 int fileCount()const;
83 void reread(); 109 void reread();
84 110
85 int mode()const; 111 int mode()const;
86 int selector()const; 112 int selector()const;
87 113
88 114 /**
115 * Set the Icon visible
116 * @param b Show or Hide the New Button
117 */
89 void setNewVisible( bool b ); 118 void setNewVisible( bool b );
119
120 /**
121 * Set the Icon visible
122 */
90 void setCloseVisible( bool b ); 123 void setCloseVisible( bool b );
124
125 /**
126 * Set the Name Line visible
127 */
91 void setNameVisible( bool b ); 128 void setNameVisible( bool b );
92 129
93signals: 130signals:
131 /**
132 * dirSelected is emitted whenever changed into a different dir
133 */
94 void dirSelected( const QString& ); 134 void dirSelected( const QString& );
135
136 /**
137 * fileSelected is emitted when a file is selected
138 * it uses a DocLnk as parameter
139 */
95 void fileSelected( const DocLnk& ); 140 void fileSelected( const DocLnk& );
141
142 /**
143 * fileSelected is emitted when a file is selected
144 * the complete path is a parameter
145 */
96 void fileSelected( const QString& ); 146 void fileSelected( const QString& );
147
148 /**
149 * Create a new File with a DocLnk
150 */
97 void newSelected( const DocLnk& ); 151 void newSelected( const DocLnk& );
152
98 void closeMe(); 153 void closeMe();
154
155 /**
156 * Ok is emitted on a Qt::Key_Return or Q::Key_Enter
157 * in the line edit
158 */
99 void ok(); 159 void ok();
100 void cancel(); 160 void cancel();
101 161
102/* used by the ViewInterface */ 162/* used by the ViewInterface */
103private: 163private:
104 bool showNew()const; 164 bool showNew()const;
105 bool showClose()const; 165 bool showClose()const;
106 MimeTypes mimeTypes()const; 166 MimeTypes mimeTypes()const;
107 QStringList currentMimeType()const; 167 QStringList currentMimeType()const;
108 168
109private: 169private:
110 /* inits the Widgets */ 170 /* inits the Widgets */
111 void initUI(); 171 void initUI();
112 /* inits the MimeType ComboBox content + connects signals and slots */ 172 /* inits the MimeType ComboBox content + connects signals and slots */
113 void initMime(); 173 void initMime();
114 /* init the Views :) */ 174 /* init the Views :) */
115 void initViews(); 175 void initViews();
116 176
117private: 177private:
118 QLineEdit* m_lneEdit; // the LineEdit for the Name 178 QLineEdit* m_lneEdit; // the LineEdit for the Name
119 QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType 179 QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType
120 QWidgetStack* m_stack; // our widget stack which will contain the views 180 QWidgetStack* m_stack; // our widget stack which will contain the views
121 OFileViewInterface* currentView()const; // returns the currentView 181 OFileViewInterface* currentView()const; // returns the currentView
122 OFileViewInterface* m_current; // here is the view saved 182 OFileViewInterface* m_current; // here is the view saved
123 bool m_shNew : 1; // should we show New? 183 bool m_shNew : 1; // should we show New?
124 bool m_shClose : 1; // should we show Close? 184 bool m_shClose : 1; // should we show Close?
125 MimeTypes m_mimeType; // list of mimetypes 185 MimeTypes m_mimeType; // list of mimetypes
126 186
127 QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr 187 QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
128 QHBox* m_nameBox; // the LineEdit + Label is hold here 188 QHBox* m_nameBox; // the LineEdit + Label is hold here
129 QHBox* m_cmbBox; // this holds the two combo boxes 189 QHBox* m_cmbBox; // this holds the two combo boxes
130 190
131 QString m_startDir; 191 QString m_startDir;
132 int m_mode; 192 int m_mode;
133 int m_selector; 193 int m_selector;
134 194
135 struct Data; // used for future versions 195 struct Data; // used for future versions
136 Data *d; 196 Data *d;
137 197
138private slots: 198private slots:
139 void slotMimeTypeChanged(); 199 void slotMimeTypeChanged();
140 200
141 /* will set the text of the lineedit and emit a fileChanged signal */ 201 /* will set the text of the lineedit and emit a fileChanged signal */
142 void slotDocLnkBridge( const DocLnk& ); 202 void slotDocLnkBridge( const DocLnk& );
143 void slotFileBridge( const QString& ); 203 void slotFileBridge( const QString& );
144 void slotViewChange( const QString& ); 204 void slotViewChange( const QString& );
145 205
146 bool eventFilter (QObject *o, QEvent *e); 206 bool eventFilter (QObject *o, QEvent *e);
147 207
148}; 208};
149 209
150#endif 210#endif