-rw-r--r-- | libopie/ofileselector.cc | 187 |
1 files changed, 173 insertions, 14 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index b583125..14f035e 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc | |||
@@ -46,12 +46,13 @@ | |||
46 | #include <qpe/qpeapplication.h> | 46 | #include <qpe/qpeapplication.h> |
47 | #include <qpe/fileselector.h> | 47 | #include <qpe/fileselector.h> |
48 | #include <qpe/applnk.h> | 48 | #include <qpe/applnk.h> |
49 | #include <qpe/global.h> | 49 | #include <qpe/global.h> |
50 | #include <qpe/mimetype.h> | 50 | #include <qpe/mimetype.h> |
51 | #include <qpe/resource.h> | 51 | #include <qpe/resource.h> |
52 | #include <qpe/storage.h> | ||
52 | 53 | ||
53 | #include <unistd.h> | 54 | #include <unistd.h> |
54 | #include <stdlib.h> | 55 | #include <stdlib.h> |
55 | #include <sys/stat.h> | 56 | #include <sys/stat.h> |
56 | 57 | ||
57 | #include "ofileselector.h" | 58 | #include "ofileselector.h" |
@@ -113,15 +114,19 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString | |||
113 | 114 | ||
114 | m_fnLabel = 0; | 115 | m_fnLabel = 0; |
115 | m_checkPerm = 0; | 116 | m_checkPerm = 0; |
116 | m_mimeCheck = 0; | 117 | m_mimeCheck = 0; |
117 | m_viewCheck = 0; | 118 | m_viewCheck = 0; |
118 | 119 | ||
120 | m_pseudo = 0; | ||
121 | m_pseudoLayout = 0; | ||
122 | |||
119 | m_dir = true; | 123 | m_dir = true; |
120 | m_files = true; | 124 | m_files = true; |
121 | m_custom = 0; | 125 | m_custom = 0; |
126 | m_showPopup = true; | ||
122 | 127 | ||
123 | if(m_pixmaps == 0 ) // init the pixmaps | 128 | if(m_pixmaps == 0 ) // init the pixmaps |
124 | initPics(); | 129 | initPics(); |
125 | 130 | ||
126 | m_lay = new QVBoxLayout(this); | 131 | m_lay = new QVBoxLayout(this); |
127 | init(); | 132 | init(); |
@@ -226,17 +231,25 @@ void OFileSelector::setYesCancelVisible( bool show ) | |||
226 | } | 231 | } |
227 | 232 | ||
228 | void OFileSelector::setToolbarVisible( bool show ) | 233 | void OFileSelector::setToolbarVisible( bool show ) |
229 | { | 234 | { |
230 | if ( m_shTool == show ) | 235 | if ( m_shTool == show ) |
231 | return; | 236 | return; |
232 | /* if( show ){ | 237 | if(!m_shTool ){ |
233 | 238 | delete m_boxToolbar; | |
234 | }else { | 239 | delete m_homeButton; |
235 | 240 | delete m_docButton; | |
236 | }*/ | 241 | delete m_location; |
242 | delete m_up; | ||
243 | m_boxToolbar = 0; | ||
244 | m_homeButton = 0; | ||
245 | m_docButton = 0; | ||
246 | m_location = 0; | ||
247 | m_up = 0; | ||
248 | }; | ||
249 | updateLay();// overkill fix it | ||
237 | } | 250 | } |
238 | 251 | ||
239 | void OFileSelector::setPermissionBarVisible( bool show ) | 252 | void OFileSelector::setPermissionBarVisible( bool show ) |
240 | { | 253 | { |
241 | if( show == m_shPerm ) | 254 | if( show == m_shPerm ) |
242 | return; | 255 | return; |
@@ -415,13 +428,31 @@ void OFileSelector::reparse() | |||
415 | m_mimeCheck->insertStringList(m_mimetypes ); | 428 | m_mimeCheck->insertStringList(m_mimetypes ); |
416 | // set it to the current mimetype | 429 | // set it to the current mimetype |
417 | m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currMime ) ); | 430 | m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currMime ) ); |
418 | }; | 431 | }; |
419 | QDir dir( m_currentDir ); | 432 | QDir dir( m_currentDir ); |
420 | //dir.setFilter(-1 ); | 433 | //dir.setFilter(-1 ); |
421 | dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::Reversed | QDir::IgnoreCase ); | 434 | int sort = QDir::Name | QDir::DirsFirst | QDir::Reversed; |
435 | if( m_case ) | ||
436 | sort = QDir::IgnoreCase; | ||
437 | dir.setSorting( sort ); | ||
438 | |||
439 | int filter; | ||
440 | /* if( m_dir && !m_files) | ||
441 | filter |= QDir::Dirs; | ||
442 | else if( !m_dir && m_files ) | ||
443 | filter |= QDir::Files; | ||
444 | else | ||
445 | filter |= QDir::All; | ||
446 | */ | ||
447 | if( m_selector == EXTENDED_ALL ) | ||
448 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | ||
449 | else | ||
450 | filter = QDir::Files | QDir::Dirs | QDir::All; | ||
451 | dir.setFilter( filter ); | ||
452 | |||
422 | const QFileInfoList *list = dir.entryInfoList(); | 453 | const QFileInfoList *list = dir.entryInfoList(); |
423 | QFileInfoListIterator it( *list ); | 454 | QFileInfoListIterator it( *list ); |
424 | QFileInfo *fi; | 455 | QFileInfo *fi; |
425 | while( (fi=it.current()) ){ | 456 | while( (fi=it.current()) ){ |
426 | if(fi->fileName() == ".." || fi->fileName() == "." ){ | 457 | if(fi->fileName() == ".." || fi->fileName() == "." ){ |
427 | ++it; | 458 | ++it; |
@@ -551,15 +582,31 @@ void OFileSelector::slotViewCheck(const QString &view ){ | |||
551 | qWarning("changed: show %s", view.latin1() ); | 582 | qWarning("changed: show %s", view.latin1() ); |
552 | // if the current view is the one | 583 | // if the current view is the one |
553 | QString currMime = m_mimeCheck->currentText(); | 584 | QString currMime = m_mimeCheck->currentText(); |
554 | if( view == QString::fromLatin1("Documents") ){ | 585 | if( view == QString::fromLatin1("Documents") ){ |
555 | // get the mimetype now | 586 | // get the mimetype now |
556 | // check if we're the current widget and return | 587 | // check if we're the current widget and return |
557 | if( m_View != 0) // delete 0 shouldn't crash but it did :( | 588 | if( m_View != 0) { // delete 0 shouldn't crash but it did :( |
558 | delete m_View; | 589 | delete m_View; |
590 | delete m_boxToolbar; | ||
591 | delete m_homeButton; | ||
592 | delete m_docButton; | ||
593 | delete m_location; | ||
594 | delete m_up; | ||
595 | delete m_pseudo; | ||
596 | delete m_pseudoLayout; | ||
597 | } | ||
559 | m_View = 0; | 598 | m_View = 0; |
599 | m_boxToolbar = 0; | ||
600 | m_homeButton = 0; | ||
601 | m_docButton = 0; | ||
602 | m_location = 0; | ||
603 | m_up = 0; | ||
604 | m_pseudo = 0; | ||
605 | m_pseudoLayout = 0; | ||
606 | |||
560 | delete m_select; | 607 | delete m_select; |
561 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, | 608 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, |
562 | m_stack,"fileselector", FALSE, FALSE ); | 609 | m_stack,"fileselector", FALSE, FALSE ); |
563 | m_stack->addWidget( m_select, NORMAL ); | 610 | m_stack->addWidget( m_select, NORMAL ); |
564 | m_mimeCheck->clear(); | 611 | m_mimeCheck->clear(); |
565 | m_selector = NORMAL; | 612 | m_selector = NORMAL; |
@@ -571,23 +618,54 @@ void OFileSelector::slotViewCheck(const QString &view ){ | |||
571 | }else if(view == QString::fromLatin1("Files") ){ | 618 | }else if(view == QString::fromLatin1("Files") ){ |
572 | // remove from the stack | 619 | // remove from the stack |
573 | delete m_select; | 620 | delete m_select; |
574 | m_select = 0; | 621 | m_select = 0; |
575 | delete m_View; | 622 | delete m_View; |
576 | m_View = 0; | 623 | m_View = 0; |
624 | |||
625 | delete m_boxToolbar; | ||
626 | delete m_homeButton; | ||
627 | delete m_docButton; | ||
628 | delete m_location; | ||
629 | delete m_up; | ||
630 | delete m_pseudo; | ||
631 | delete m_pseudoLayout; | ||
632 | m_boxToolbar = 0; | ||
633 | m_homeButton = 0; | ||
634 | m_docButton = 0; | ||
635 | m_location = 0; | ||
636 | m_up = 0; | ||
637 | m_pseudo = 0; | ||
638 | m_pseudoLayout = 0; | ||
639 | |||
577 | m_selector = EXTENDED; | 640 | m_selector = EXTENDED; |
578 | // create the ListView or IconView | 641 | // create the ListView or IconView |
579 | initializeListView(); | 642 | initializeListView(); |
580 | 643 | ||
581 | reparse(); | 644 | reparse(); |
582 | }else if(view == QString::fromLatin1("All Files") ) { | 645 | }else if(view == QString::fromLatin1("All Files") ) { |
583 | // remove from the stack | 646 | // remove from the stack |
584 | delete m_select; | 647 | delete m_select; |
585 | m_select = 0; | 648 | m_select = 0; |
586 | delete m_View; | 649 | delete m_View; |
587 | m_View = 0; | 650 | m_View = 0; |
651 | delete m_boxToolbar; | ||
652 | delete m_homeButton; | ||
653 | delete m_docButton; | ||
654 | delete m_location; | ||
655 | delete m_up; | ||
656 | delete m_pseudo; | ||
657 | delete m_pseudoLayout; | ||
658 | m_boxToolbar = 0; | ||
659 | m_homeButton = 0; | ||
660 | m_docButton = 0; | ||
661 | m_location = 0; | ||
662 | m_up = 0; | ||
663 | m_pseudo = 0; | ||
664 | m_pseudoLayout = 0; | ||
665 | |||
588 | m_selector = EXTENDED_ALL; | 666 | m_selector = EXTENDED_ALL; |
589 | initializeListView(); | 667 | initializeListView(); |
590 | reparse(); | 668 | reparse(); |
591 | }; | 669 | }; |
592 | }; | 670 | }; |
593 | 671 | ||
@@ -608,16 +686,75 @@ void OFileSelector::updateMimes() // lets check which mode is active | |||
608 | }else{ | 686 | }else{ |
609 | // should be allreday updatet | 687 | // should be allreday updatet |
610 | ; | 688 | ; |
611 | } | 689 | } |
612 | }; | 690 | }; |
613 | void OFileSelector::initializeListView() | 691 | void OFileSelector::initializeListView() |
614 | { | 692 | { |
615 | m_View = new QListView(m_stack, "Extended view" ); | 693 | // just to make sure but clean it up better FIXME |
616 | m_stack->addWidget( m_View, EXTENDED ); | 694 | delete m_View; |
695 | m_View = 0; | ||
696 | delete m_boxToolbar; | ||
697 | delete m_homeButton; | ||
698 | delete m_docButton; | ||
699 | delete m_location; | ||
700 | delete m_up; | ||
701 | delete m_pseudo; | ||
702 | delete m_pseudoLayout; | ||
703 | m_boxToolbar = 0; | ||
704 | m_homeButton = 0; | ||
705 | m_docButton = 0; | ||
706 | m_location = 0; | ||
707 | m_up = 0; | ||
708 | m_pseudo = 0; | ||
709 | m_pseudoLayout = 0; | ||
710 | // time for the toolbar | ||
711 | m_pseudo = new QWidget(m_stack, "Pseudo Widget"); | ||
712 | m_pseudoLayout = new QVBoxLayout(m_pseudo ); | ||
713 | if(m_shTool ){ | ||
714 | m_boxToolbar = new QHBoxLayout( ); | ||
715 | m_boxToolbar->setAutoAdd( true ); | ||
716 | m_location = new QComboBox(m_pseudo ); | ||
717 | |||
718 | m_up = new QPushButton(Resource::loadIconSet("up"),"", m_pseudo,"cdUpButton"); | ||
719 | m_up->setMinimumSize( QSize( 20, 20 ) ); | ||
720 | m_up->setMaximumSize( QSize( 20, 20 ) ); | ||
721 | connect(m_up ,SIGNAL(clicked()),this,SLOT(cdUP() ) ); | ||
722 | m_up->setFlat(TRUE); | ||
723 | |||
724 | m_homeButton = new QPushButton(Resource::loadIconSet("home") , "", m_pseudo); | ||
725 | m_homeButton->setMinimumSize( QSize( 20, 20 ) ); | ||
726 | m_homeButton->setMaximumSize( QSize( 20, 20 ) ); | ||
727 | connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotHome() ) ); | ||
728 | m_homeButton->setFlat(TRUE); | ||
729 | |||
730 | m_docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"", m_pseudo,"docsButton"); | ||
731 | m_docButton->setMinimumSize( QSize( 20, 20 ) ); | ||
732 | m_docButton->setMaximumSize( QSize( 20, 20 ) ); | ||
733 | connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotDoc() ) ); | ||
734 | m_docButton->setFlat(TRUE); | ||
735 | |||
736 | m_boxToolbar->addWidget(m_location ); | ||
737 | m_boxToolbar->addWidget(m_up ); | ||
738 | m_boxToolbar->addWidget(m_homeButton ); | ||
739 | m_boxToolbar->addWidget(m_docButton ); | ||
740 | m_pseudoLayout->addLayout(m_boxToolbar ); | ||
741 | // lets fill the combobox | ||
742 | StorageInfo storage; | ||
743 | const QList<FileSystem> &fs = storage.fileSystems(); | ||
744 | QListIterator<FileSystem> it ( fs ); | ||
745 | for( ; it.current(); ++it ){ | ||
746 | const QString disk = (*it)->name(); | ||
747 | const QString path = (*it)->path(); | ||
748 | m_location->insertItem(path+ "<-"+disk ); | ||
749 | } | ||
750 | }; | ||
751 | m_View = new QListView(m_pseudo, "Extended view" ); | ||
752 | m_stack->addWidget( m_pseudo, EXTENDED ); | ||
617 | m_stack->raiseWidget( EXTENDED ); | 753 | m_stack->raiseWidget( EXTENDED ); |
754 | m_pseudoLayout->addWidget(m_View ); | ||
618 | QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold); | 755 | QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold); |
619 | // set up the stuff | 756 | // set up the stuff |
620 | // Pixmap Name Date Size mime | 757 | // Pixmap Name Date Size mime |
621 | //(m_View->header() )->hide(); | 758 | //(m_View->header() )->hide(); |
622 | //m_View->setRootIsDecorated(false); | 759 | //m_View->setRootIsDecorated(false); |
623 | m_View->addColumn(" "); | 760 | m_View->addColumn(" "); |
@@ -632,12 +769,14 @@ void OFileSelector::initializeListView() | |||
632 | connect(m_View, SIGNAL(selectionChanged() ), this, SLOT(slotSelectionChanged() ) ); | 769 | connect(m_View, SIGNAL(selectionChanged() ), this, SLOT(slotSelectionChanged() ) ); |
633 | connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); | 770 | connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); |
634 | connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), | 771 | connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), |
635 | this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); | 772 | this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); |
636 | connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), | 773 | connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), |
637 | this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); | 774 | this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); |
775 | |||
776 | |||
638 | }; | 777 | }; |
639 | /* If a item is locked depends on the mode | 778 | /* If a item is locked depends on the mode |
640 | if we're in OPEN !isReadable is locked | 779 | if we're in OPEN !isReadable is locked |
641 | if we're in SAVE !isWriteable is locked | 780 | if we're in SAVE !isWriteable is locked |
642 | 781 | ||
643 | 782 | ||
@@ -794,24 +933,36 @@ void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint & | |||
794 | qWarning( "locked" ); | 933 | qWarning( "locked" ); |
795 | } | 934 | } |
796 | }; | 935 | }; |
797 | } | 936 | } |
798 | void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int ) | 937 | void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int ) |
799 | { | 938 | { |
939 | if (item == 0 ) | ||
940 | return; | ||
941 | |||
800 | if( button != Qt::RightButton ) | 942 | if( button != Qt::RightButton ) |
801 | return; | 943 | return; |
802 | qWarning("right button" ); | 944 | qWarning("right button" ); |
803 | slotContextMenu(item); | 945 | slotContextMenu(item); |
804 | } | 946 | } |
805 | void OFileSelector::slotContextMenu(QListViewItem *item) | 947 | void OFileSelector::slotContextMenu(QListViewItem *item) |
806 | { | 948 | { |
807 | qWarning("context menu" ); | 949 | qWarning("context menu" ); |
950 | if( item ==0 || !m_showPopup ) | ||
951 | return; | ||
952 | |||
808 | if( m_custom !=0){ | 953 | if( m_custom !=0){ |
809 | m_custom->exec(); | 954 | m_custom->exec(); |
810 | }else{ | 955 | }else{ |
811 | QPopupMenu menu; | 956 | QPopupMenu menu; |
957 | QAction up; | ||
958 | up.setText("cd up"); | ||
959 | up.addTo( &menu ); | ||
960 | connect(&up, SIGNAL(activated() ), | ||
961 | this, SLOT(cdUP() ) ); | ||
962 | |||
812 | QAction act; | 963 | QAction act; |
813 | OFileSelectorItem *sel = (OFileSelectorItem*)item; | 964 | OFileSelectorItem *sel = (OFileSelectorItem*)item; |
814 | if(sel->isDir() ){ | 965 | if(sel->isDir() ){ |
815 | act.setText( tr("Change Directory") ); | 966 | act.setText( tr("Change Directory") ); |
816 | act.addTo(&menu ); | 967 | act.addTo(&menu ); |
817 | connect(&act, SIGNAL(activated() ), | 968 | connect(&act, SIGNAL(activated() ), |
@@ -822,26 +973,26 @@ void OFileSelector::slotContextMenu(QListViewItem *item) | |||
822 | connect(&act, SIGNAL(activated() ), | 973 | connect(&act, SIGNAL(activated() ), |
823 | this, SLOT(slotOpen() ) ); | 974 | this, SLOT(slotOpen() ) ); |
824 | } | 975 | } |
825 | QAction rescan; | 976 | QAction rescan; |
826 | rescan.setText( tr("Rescan") ); | 977 | rescan.setText( tr("Rescan") ); |
827 | rescan.addTo( &menu ); | 978 | rescan.addTo( &menu ); |
828 | connect(&act, SIGNAL(activated() ), | 979 | connect(&rescan, SIGNAL(activated() ), |
829 | this, SLOT(slotRescan() ) ); | 980 | this, SLOT(slotRescan() ) ); |
830 | 981 | ||
831 | QAction rename; | 982 | QAction rename; |
832 | rename.setText( tr("Rename") ); | 983 | rename.setText( tr("Rename") ); |
833 | rename.addTo( &menu ); | 984 | rename.addTo( &menu ); |
834 | connect(&act, SIGNAL(activated() ), | 985 | connect(&rename, SIGNAL(activated() ), |
835 | this, SLOT(slotRename() ) ); | 986 | this, SLOT(slotRename() ) ); |
836 | 987 | ||
837 | menu.insertSeparator(); | 988 | menu.insertSeparator(); |
838 | QAction delItem; | 989 | QAction delItem; |
839 | delItem.setText( tr("Delete") ); | 990 | delItem.setText( tr("Delete") ); |
840 | delItem.addTo(&menu ); | 991 | delItem.addTo(&menu ); |
841 | connect(&act, SIGNAL(activated() ), | 992 | connect(&delItem, SIGNAL(activated() ), |
842 | this, SLOT(slotDelete() ) ); | 993 | this, SLOT(slotDelete() ) ); |
843 | 994 | ||
844 | menu.exec(QCursor::pos() ); | 995 | menu.exec(QCursor::pos() ); |
845 | } | 996 | } |
846 | } | 997 | } |
847 | bool OFileSelector::cd(const QString &str ) | 998 | bool OFileSelector::cd(const QString &str ) |
@@ -892,9 +1043,17 @@ void OFileSelector::slotDelete() | |||
892 | QFile::remove( list[0] ); | 1043 | QFile::remove( list[0] ); |
893 | } | 1044 | } |
894 | m_View->takeItem( sel ); | 1045 | m_View->takeItem( sel ); |
895 | delete sel; | 1046 | delete sel; |
896 | } | 1047 | } |
897 | 1048 | ||
898 | 1049 | void OFileSelector::cdUP() | |
1050 | { | ||
1051 | QDir dir( m_currentDir ); | ||
1052 | dir.cdUp(); | ||
1053 | if(dir.exists() ){ | ||
1054 | m_currentDir = dir.absPath(); | ||
1055 | reparse(); | ||
1056 | } | ||
1057 | } | ||
899 | 1058 | ||
900 | 1059 | ||