kdiroperator.h
00001 // -*- c++ -*- 00002 /* This file is part of the KDE libraries 00003 Copyright (C) 1999 Stephan Kulow <coolo@kde.org> 00004 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 #ifndef KDIROPERATOR_H_ 00022 #define KDIROPERATOR_H_ 00023 00024 #include <tqwidget.h> 00025 #include <tqptrstack.h> 00026 00027 #include <kaction.h> 00028 #include <kcompletion.h> 00029 #include <kdirlister.h> 00030 #include <kfileview.h> 00031 #include <kfileitem.h> 00032 #include <kfile.h> 00033 00034 class TQPopupMenu; 00035 class TQTimer; 00036 00037 class KAction; 00038 class KDirLister; 00039 class KToggleAction; 00040 class KActionSeparator; 00041 class KActionMenu; 00042 class TQWidgetStack; 00043 class KProgress; 00044 namespace KIO { 00045 class CopyJob; 00046 class DeleteJob; 00047 } 00048 00097 class KIO_EXPORT KDirOperator : public TQWidget 00098 { 00099 Q_OBJECT 00100 00101 public: 00106 enum ActionTypes { SortActions = 1, 00107 ViewActions = 2, 00108 NavActions = 4, 00109 FileActions = 8, 00110 AllActions = 15 }; 00118 KDirOperator(const KURL& urlName = KURL(), 00119 TQWidget *parent = 0, const char* name = 0); 00123 virtual ~KDirOperator(); 00124 00128 // ### KDE4: make virtual 00129 void setShowHiddenFiles ( bool s ) { showHiddenAction->setChecked( s ); } 00130 00134 bool showHiddenFiles () const { return showHiddenAction->isChecked(); } 00135 00139 void close(); 00141 virtual bool close( bool alsoDelete ) { return TQWidget::close( alsoDelete ); } 00142 00150 void setNameFilter(const TQString& filter); 00151 00156 const TQString& nameFilter() const { return dir->nameFilter(); } 00157 00175 void setMimeFilter( const TQStringList& mimetypes ); 00176 00180 TQStringList mimeFilter() const { return dir->mimeFilters(); } 00181 00189 void clearFilter(); 00190 00194 KURL url() const; 00195 00201 // ### KDE4: make virtual 00202 void setURL(const KURL& url, bool clearforward); 00203 00208 void setCurrentItem( const TQString& filename ); 00209 00220 // ### KDE4: make virtual 00221 void setView(KFileView *view); 00222 00227 KFileView * view() const { return m_fileView; } 00228 00233 TQWidget * viewWidget() const { return m_fileView ? m_fileView->widget() : 0L; } 00234 00239 // ### KDE4: make virtual 00240 void setView(KFile::FileView view); 00241 00245 void setSorting( TQDir::SortSpec ); 00246 00250 TQDir::SortSpec sorting() const { return mySorting; } 00251 00255 bool isRoot() const { return url().path() == TQChar('/'); } 00256 00260 KDirLister *dirLister() const { return dir; } 00261 00266 KProgress * progressBar() const; 00267 00279 // ### KDE4: make virtual 00280 void setMode( KFile::Mode m ); 00284 KFile::Mode mode() const; 00285 00291 // ### KDE4: make virtual 00292 void setPreviewWidget(const TQWidget *w); 00293 00298 const KFileItemList * selectedItems() const { 00299 return ( m_fileView ? m_fileView->selectedItems() : 0L ); 00300 } 00301 00305 inline bool isSelected( const KFileItem *item ) const { 00306 return ( m_fileView ? m_fileView->isSelected( item ) : false ); 00307 } 00308 00313 int numDirs() const; 00314 00319 int numFiles() const; 00320 00329 KCompletion * completionObject() const { 00330 return const_cast<KCompletion *>( &myCompletion ); 00331 } 00332 00341 KCompletion *dirCompletionObject() const { 00342 return const_cast<KCompletion *>( &myDirCompletion ); 00343 } 00344 00390 KActionCollection * actionCollection() const { return myActionCollection; } 00391 00409 // ### KDE4: make virtual 00410 void setViewConfig( KConfig *config, const TQString& group ); 00411 00419 KConfig *viewConfig(); 00420 00428 TQString viewConfigGroup() const; 00429 00443 virtual void readConfig( KConfig *, const TQString& group = TQString::null ); 00444 00451 virtual void writeConfig( KConfig *, const TQString& group = TQString::null ); 00452 00453 00464 void setOnlyDoubleClickSelectsFiles( bool enable ); 00465 00471 bool onlyDoubleClickSelectsFiles() const; 00472 00481 // ### KDE4: make virtual and turn TQString into KURL 00482 bool mkdir( const TQString& directory, bool enterDirectory = true ); 00483 00491 // ### KDE4: make virtual 00492 KIO::DeleteJob * del( const KFileItemList& items, 00493 bool ask = true, bool showProgress = true ); 00494 00504 // ### KDE4: make virtual 00505 KIO::DeleteJob * del( const KFileItemList& items, TQWidget *parent, 00506 bool ask = true, bool showProgress = true ); 00507 00511 void clearHistory(); 00512 00523 // ### KDE4: make virtual 00524 void setEnableDirHighlighting( bool enable ); 00525 00532 bool dirHighlighting() const; 00533 00538 bool dirOnlyMode() const { return dirOnlyMode( myMode ); } 00539 00540 static bool dirOnlyMode( uint mode ) { 00541 return ( (mode & KFile::Directory) && 00542 (mode & (KFile::File | KFile::Files)) == 0 ); 00543 } 00544 00549 void setupMenu(int whichActions); 00550 00555 virtual void setAcceptDrops(bool b); 00556 00562 // ### KDE4: make virtual 00563 void setDropOptions(int options); 00564 00574 // ### KDE4: make virtual 00575 KIO::CopyJob * trash( const KFileItemList& items, TQWidget *parent, 00576 bool ask = true, bool showProgress = true ); 00577 00578 protected: 00593 virtual KFileView* createView( TQWidget* parent, KFile::FileView view ); 00597 // ### KDE4: make virtual 00598 void setDirLister( KDirLister *lister ); 00599 00600 virtual void resizeEvent( TQResizeEvent * ); 00601 00606 void setupActions(); 00607 00612 void updateSortActions(); 00613 00618 void updateViewActions(); 00619 00625 void setupMenu(); 00626 00634 void prepareCompletionObjects(); 00635 00641 bool checkPreviewSupport(); 00642 00643 public slots: 00647 // ### KDE4: make virtual 00648 void back(); 00649 00653 // ### KDE4: make virtual 00654 void forward(); 00655 00659 // ### KDE4: make virtual 00660 void home(); 00661 00665 // ### KDE4: make virtual 00666 void cdUp(); 00667 00671 void updateDir(); 00672 00676 // ### KDE4: make virtual 00677 void rereadDir(); 00678 00682 // ### KDE4: make virtual 00683 void mkdir(); 00684 00688 // ### KDE4: make virtual 00689 void deleteSelected(); 00690 00696 void updateSelectionDependentActions(); 00697 00701 TQString makeCompletion(const TQString&); 00702 00706 TQString makeDirCompletion(const TQString&); 00707 00712 // ### KDE4: make virtual 00713 void trashSelected(KAction::ActivationReason, TQt::ButtonState); 00714 00715 protected slots: 00720 void resetCursor(); 00721 00726 void pathChanged(); 00727 00732 void insertNewFiles(const KFileItemList &newone); 00733 00738 void itemDeleted(KFileItem *); 00739 00743 // ### KDE4: make virtual 00744 void selectDir(const KFileItem *item ); 00745 00749 void selectFile(const KFileItem *item); 00750 00754 void highlightFile(const KFileItem* i) { emit fileHighlighted( i ); } 00755 00759 virtual void activatedMenu( const KFileItem *, const TQPoint& pos ); 00760 00764 void sortByName() { byNameAction->setChecked( true ); } 00765 00769 void sortBySize() { bySizeAction->setChecked( true ); } 00770 00774 void sortByDate() { byDateAction->setChecked( true ); } 00775 00779 void sortReversed() { reverseAction->setChecked( !reverseAction->isChecked() ); } 00780 00784 void toggleDirsFirst() { dirsFirstAction->setChecked( !dirsFirstAction->isChecked() ); } 00785 00789 void toggleIgnoreCase() { caseInsensitiveAction->setChecked( !caseInsensitiveAction->isChecked() ); } 00790 00795 void slotCompletionMatch(const TQString& match); 00796 00797 signals: 00798 void urlEntered(const KURL& ); 00799 void updateInformation(int files, int dirs); 00800 void completion(const TQString&); 00801 void finishedLoading(); 00802 00808 void viewChanged( KFileView * newView ); 00809 00815 void fileHighlighted( const KFileItem *item ); 00816 void dirActivated( const KFileItem *item ); 00817 void fileSelected( const KFileItem *item ); 00826 void dropped(const KFileItem *item, TQDropEvent*event, const KURL::List&urls); 00827 private: 00831 TQPtrStack<KURL> backStack; 00832 00836 TQPtrStack<KURL> forwardStack; 00837 00838 KDirLister *dir; 00839 KURL currUrl; 00840 00841 KCompletion myCompletion; 00842 KCompletion myDirCompletion; 00843 bool myCompleteListDirty; 00844 TQDir::SortSpec mySorting; 00845 00850 bool checkPreviewInternal() const; 00851 00856 void checkPath(const TQString& txt, bool takeFiles = false); 00857 00858 void connectView(KFileView *); 00859 00860 bool openURL( const KURL& url, bool keep = false, bool reload = false ); 00861 00862 KFileView *m_fileView; 00863 KFileItemList pendingMimeTypes; 00864 00865 // the enum KFile::FileView as an int 00866 int m_viewKind; 00867 int defaultView; 00868 00869 KFile::Mode myMode; 00870 KProgress *progress; 00871 00872 const TQWidget *myPreview; // temporary pointer for the preview widget 00873 00874 // actions for the popupmenus 00875 // ### clean up all those -- we have them all in the actionMenu! 00876 KActionMenu *actionMenu; 00877 00878 KAction *backAction; 00879 KAction *forwardAction; 00880 KAction *homeAction; 00881 KAction *upAction; 00882 KAction *reloadAction; 00883 KActionSeparator *actionSeparator; 00884 KAction *mkdirAction; 00885 00886 KActionMenu *sortActionMenu; 00887 KRadioAction *byNameAction; 00888 KRadioAction *byDateAction; 00889 KRadioAction *bySizeAction; 00890 KToggleAction *reverseAction; 00891 KToggleAction *dirsFirstAction; 00892 KToggleAction *caseInsensitiveAction; 00893 00894 KActionMenu *viewActionMenu; 00895 KRadioAction *shortAction; 00896 KRadioAction *detailedAction; 00897 KToggleAction *showHiddenAction; 00898 KToggleAction *separateDirsAction; 00899 00900 KActionCollection *myActionCollection; 00901 KActionCollection *viewActionCollection; 00902 00903 private slots: 00907 void slotDetailedView(); 00908 void slotSimpleView(); 00909 void slotToggleHidden( bool ); 00910 00911 void slotSeparateDirs(); 00912 void slotDefaultPreview(); 00913 void togglePreview( bool ); 00914 00915 void slotSortByName(); 00916 void slotSortBySize(); 00917 void slotSortByDate(); 00918 void slotSortReversed(); 00919 void slotToggleDirsFirst(); 00920 void slotToggleIgnoreCase(); 00921 00922 void slotStarted(); 00923 void slotProgress( int ); 00924 void slotShowProgress(); 00925 void slotIOFinished(); 00926 void slotCanceled(); 00927 void slotRedirected( const KURL& ); 00928 00929 void slotViewActionAdded( KAction * ); 00930 void slotViewActionRemoved( KAction * ); 00931 void slotViewSortingChanged( TQDir::SortSpec ); 00932 00933 void slotClearView(); 00934 void slotRefreshItems( const KFileItemList& items ); 00935 00936 void slotProperties(); 00937 00938 void insertViewDependentActions(); 00939 00940 private: 00941 static bool isReadable( const KURL& url ); 00942 00943 protected: 00944 virtual void virtual_hook( int id, void* data ); 00945 private: 00946 class KDirOperatorPrivate; 00947 KDirOperatorPrivate *d; 00948 }; 00949 00950 #endif