author | zecke <zecke> | 2002-03-31 21:39:01 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-03-31 21:39:01 (UTC) |
commit | 66357a57409435e5967887af026bc1cf1d725f56 (patch) (unidiff) | |
tree | 1be99ea18dd4c693d68afe473b2676a5d0c60ba5 /libopie/ofileselector.cc | |
parent | 7208583b0b7ff339e6019b188332d8bcb8f30973 (diff) | |
download | opie-66357a57409435e5967887af026bc1cf1d725f56.zip opie-66357a57409435e5967887af026bc1cf1d725f56.tar.gz opie-66357a57409435e5967887af026bc1cf1d725f56.tar.bz2 |
more functionality
-rw-r--r-- | libopie/ofileselector.cc | 191 |
1 files changed, 187 insertions, 4 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index 128292f..b583125 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc | |||
@@ -39,6 +39,9 @@ | |||
39 | #include <qheader.h> | 39 | #include <qheader.h> |
40 | #include <qdir.h> | 40 | #include <qdir.h> |
41 | #include <qpainter.h> | 41 | #include <qpainter.h> |
42 | #include <qaction.h> | ||
43 | #include <qpopupmenu.h> | ||
44 | #include <qcursor.h> | ||
42 | 45 | ||
43 | #include <qpe/qpeapplication.h> | 46 | #include <qpe/qpeapplication.h> |
44 | #include <qpe/fileselector.h> | 47 | #include <qpe/fileselector.h> |
@@ -47,6 +50,10 @@ | |||
47 | #include <qpe/mimetype.h> | 50 | #include <qpe/mimetype.h> |
48 | #include <qpe/resource.h> | 51 | #include <qpe/resource.h> |
49 | 52 | ||
53 | #include <unistd.h> | ||
54 | #include <stdlib.h> | ||
55 | #include <sys/stat.h> | ||
56 | |||
50 | #include "ofileselector.h" | 57 | #include "ofileselector.h" |
51 | 58 | ||
52 | QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; | 59 | QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; |
@@ -111,6 +118,7 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString | |||
111 | 118 | ||
112 | m_dir = true; | 119 | m_dir = true; |
113 | m_files = true; | 120 | m_files = true; |
121 | m_custom = 0; | ||
114 | 122 | ||
115 | if(m_pixmaps == 0 ) // init the pixmaps | 123 | if(m_pixmaps == 0 ) // init the pixmaps |
116 | initPics(); | 124 | initPics(); |
@@ -178,6 +186,7 @@ void OFileSelector::init() | |||
178 | m_stack->addWidget(m_select, NORMAL ); | 186 | m_stack->addWidget(m_select, NORMAL ); |
179 | m_lay->addWidget(m_stack ); | 187 | m_lay->addWidget(m_stack ); |
180 | m_stack->raiseWidget(NORMAL ); | 188 | m_stack->raiseWidget(NORMAL ); |
189 | connect(m_select, SIGNAL(fileSelected( const DocLnk &) ), this, SLOT(slotFileBridgeSelected(const DocLnk &) ) ); | ||
181 | }else { | 190 | }else { |
182 | initializeListView(); | 191 | initializeListView(); |
183 | } | 192 | } |
@@ -277,10 +286,10 @@ void OFileSelector::setShowFiles(bool files ){ | |||
277 | m_files = files; | 286 | m_files = files; |
278 | reparse(); | 287 | reparse(); |
279 | } | 288 | } |
280 | void OFileSelector::setPopupMenu(const QPopupMenu * ) | 289 | void OFileSelector::setPopupMenu(QPopupMenu *pop ) |
281 | { | 290 | { |
282 | //delete oldpopup; | 291 | //delete oldpopup; |
283 | 292 | m_custom = pop; | |
284 | } | 293 | } |
285 | bool OFileSelector::setPermission( ) const | 294 | bool OFileSelector::setPermission( ) const |
286 | { | 295 | { |
@@ -557,7 +566,7 @@ void OFileSelector::slotViewCheck(const QString &view ){ | |||
557 | updateMimes(); | 566 | updateMimes(); |
558 | m_mimeCheck->insertStringList( m_mimetypes ); | 567 | m_mimeCheck->insertStringList( m_mimetypes ); |
559 | m_stack->raiseWidget( NORMAL ); | 568 | m_stack->raiseWidget( NORMAL ); |
560 | 569 | connect(m_select, SIGNAL(fileSelected( const DocLnk &) ), this, SLOT(slotFileBridgeSelected(const DocLnk &) ) ); | |
561 | 570 | ||
562 | }else if(view == QString::fromLatin1("Files") ){ | 571 | }else if(view == QString::fromLatin1("Files") ){ |
563 | // remove from the stack | 572 | // remove from the stack |
@@ -619,6 +628,13 @@ void OFileSelector::initializeListView() | |||
619 | QHeader *header = m_View->header(); | 628 | QHeader *header = m_View->header(); |
620 | header->hide(); | 629 | header->hide(); |
621 | m_View->setSorting(1 ); | 630 | m_View->setSorting(1 ); |
631 | // connect now | ||
632 | connect(m_View, SIGNAL(selectionChanged() ), this, SLOT(slotSelectionChanged() ) ); | ||
633 | connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); | ||
634 | connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), | ||
635 | this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); | ||
636 | connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), | ||
637 | this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); | ||
622 | }; | 638 | }; |
623 | /* If a item is locked depends on the mode | 639 | /* If a item is locked depends on the mode |
624 | if we're in OPEN !isReadable is locked | 640 | if we're in OPEN !isReadable is locked |
@@ -676,7 +692,7 @@ void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) | |||
676 | return; | 692 | return; |
677 | //if( showDirs ) | 693 | //if( showDirs ) |
678 | { | 694 | { |
679 | bool locked; | 695 | bool locked=false; |
680 | QString name; | 696 | QString name; |
681 | QPixmap pix; | 697 | QPixmap pix; |
682 | if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){ | 698 | if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){ |
@@ -713,5 +729,172 @@ void OFileSelector::setShowDirs(bool dir ) | |||
713 | reparse(); | 729 | reparse(); |
714 | } | 730 | } |
715 | 731 | ||
732 | void OFileSelector::slotFileSelected(const QString &string ) | ||
733 | { | ||
734 | if(m_shLne ) | ||
735 | m_edit->setText( string ); | ||
736 | |||
737 | emit fileSelected( string ); | ||
738 | // do AppLnk stuff | ||
739 | } | ||
740 | void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) | ||
741 | { | ||
742 | slotFileSelected(lnk.name() ); | ||
743 | emit fileSelected( lnk ); | ||
744 | } | ||
745 | void OFileSelector::slotSelectionChanged() // get the current items | ||
746 | // fixme | ||
747 | { | ||
748 | qWarning("selection changed" ); | ||
749 | } | ||
750 | void OFileSelector::slotCurrentChanged(QListViewItem *item ) | ||
751 | { | ||
752 | qWarning("current changed" ); | ||
753 | if( item == 0 ) | ||
754 | return; | ||
755 | |||
756 | if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ | ||
757 | OFileSelectorItem *sel = (OFileSelectorItem*)item; | ||
758 | if(!sel->isDir() ){ | ||
759 | qWarning("is not dir" ); | ||
760 | if(m_shLne ){ | ||
761 | m_edit->setText(sel->text(1) ); | ||
762 | qWarning("setTexy" ); | ||
763 | } | ||
764 | } | ||
765 | }else { | ||
766 | qWarning("mode not extended" ); | ||
767 | } | ||
768 | } | ||
769 | // either select or change dir | ||
770 | void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &point, int ) | ||
771 | { | ||
772 | if( item == 0 ) | ||
773 | return; | ||
774 | |||
775 | if( button != Qt::LeftButton ) | ||
776 | return; | ||
777 | |||
778 | qWarning("clicked" ); | ||
779 | if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ | ||
780 | qWarning("inside" ); | ||
781 | OFileSelectorItem *sel = (OFileSelectorItem*)item; | ||
782 | if(!sel->isLocked() ){ // not locked either changedir or open | ||
783 | QStringList str = QStringList::split("->", sel->text(1) ); | ||
784 | if(sel->isDir() ){ | ||
785 | cd( sel->directory() + "/" + str[0] ); | ||
786 | }else{ | ||
787 | qWarning("file" ); | ||
788 | if(m_shLne ) | ||
789 | m_edit->setText(str[0] ); | ||
790 | emit fileSelected(str[0] ); | ||
791 | // emit DocLnk need to do it | ||
792 | } | ||
793 | }else{ | ||
794 | qWarning( "locked" ); | ||
795 | } | ||
796 | }; | ||
797 | } | ||
798 | void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int ) | ||
799 | { | ||
800 | if( button != Qt::RightButton ) | ||
801 | return; | ||
802 | qWarning("right button" ); | ||
803 | slotContextMenu(item); | ||
804 | } | ||
805 | void OFileSelector::slotContextMenu(QListViewItem *item) | ||
806 | { | ||
807 | qWarning("context menu" ); | ||
808 | if( m_custom !=0){ | ||
809 | m_custom->exec(); | ||
810 | }else{ | ||
811 | QPopupMenu menu; | ||
812 | QAction act; | ||
813 | OFileSelectorItem *sel = (OFileSelectorItem*)item; | ||
814 | if(sel->isDir() ){ | ||
815 | act.setText( tr("Change Directory") ); | ||
816 | act.addTo(&menu ); | ||
817 | connect(&act, SIGNAL(activated() ), | ||
818 | this, SLOT(slotChangedDir() ) ); | ||
819 | }else{ | ||
820 | act.setText( tr("Open file" ) ); | ||
821 | act.addTo( &menu ); | ||
822 | connect(&act, SIGNAL(activated() ), | ||
823 | this, SLOT(slotOpen() ) ); | ||
824 | } | ||
825 | QAction rescan; | ||
826 | rescan.setText( tr("Rescan") ); | ||
827 | rescan.addTo( &menu ); | ||
828 | connect(&act, SIGNAL(activated() ), | ||
829 | this, SLOT(slotRescan() ) ); | ||
830 | |||
831 | QAction rename; | ||
832 | rename.setText( tr("Rename") ); | ||
833 | rename.addTo( &menu ); | ||
834 | connect(&act, SIGNAL(activated() ), | ||
835 | this, SLOT(slotRename() ) ); | ||
836 | |||
837 | menu.insertSeparator(); | ||
838 | QAction delItem; | ||
839 | delItem.setText( tr("Delete") ); | ||
840 | delItem.addTo(&menu ); | ||
841 | connect(&act, SIGNAL(activated() ), | ||
842 | this, SLOT(slotDelete() ) ); | ||
843 | |||
844 | menu.exec(QCursor::pos() ); | ||
845 | } | ||
846 | } | ||
847 | bool OFileSelector::cd(const QString &str ) | ||
848 | { | ||
849 | qWarning(" dir %s", str.latin1() ); | ||
850 | QDir dir( str); | ||
851 | if(dir.exists() ){ | ||
852 | m_currentDir = str; | ||
853 | reparse(); | ||
854 | return true; | ||
855 | } | ||
856 | return false; | ||
857 | } | ||
858 | |||
859 | void OFileSelector::slotChangedDir() | ||
860 | { | ||
861 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | ||
862 | if(sel->isDir() ){ | ||
863 | QStringList str = QStringList::split("->", sel->text(1) ); | ||
864 | cd( sel->directory() + "/" + str[0] ); | ||
865 | } | ||
866 | } | ||
867 | void OFileSelector::slotOpen() | ||
868 | { | ||
869 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | ||
870 | if(!sel->isDir() ){ | ||
871 | QStringList str = QStringList::split("->", sel->text(1) ); | ||
872 | slotFileSelected( str[0] ); | ||
873 | } | ||
874 | } | ||
875 | void OFileSelector::slotRescan() | ||
876 | { | ||
877 | reparse(); | ||
878 | } | ||
879 | void OFileSelector::slotRename() | ||
880 | { | ||
881 | // rename inline | ||
882 | } | ||
883 | void OFileSelector::slotDelete() | ||
884 | { | ||
885 | qWarning("delete slot" ); | ||
886 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | ||
887 | QStringList list = QStringList::split("->", sel->text(1) ); | ||
888 | if( sel->isDir() ){ | ||
889 | QString str = QString::fromLatin1("rm -rf ") + list[0]; | ||
890 | ::system(str.utf8().data() ); | ||
891 | }else{ | ||
892 | QFile::remove( list[0] ); | ||
893 | } | ||
894 | m_View->takeItem( sel ); | ||
895 | delete sel; | ||
896 | } | ||
897 | |||
898 | |||
716 | 899 | ||
717 | 900 | ||