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