kio
kdiroperator.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KDIROPERATOR_H_
00022 #define KDIROPERATOR_H_
00023
00024 #include <qwidget.h>
00025 #include <qptrstack.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 QPopupMenu;
00035 class QTimer;
00036
00037 class KAction;
00038 class KDirLister;
00039 class KToggleAction;
00040 class KActionSeparator;
00041 class KActionMenu;
00042 class QWidgetStack;
00043 class KProgress;
00044 namespace KIO {
00045 class CopyJob;
00046 class DeleteJob;
00047 }
00048
00097 class KIO_EXPORT KDirOperator : public QWidget
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 QWidget *parent = 0, const char* name = 0);
00123 virtual ~KDirOperator();
00124
00128
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 QWidget::close( alsoDelete ); }
00142
00150 void setNameFilter(const QString& filter);
00151
00156 const QString& nameFilter() const { return dir->nameFilter(); }
00157
00175 void setMimeFilter( const QStringList& mimetypes );
00176
00180 QStringList mimeFilter() const { return dir->mimeFilters(); }
00181
00189 void clearFilter();
00190
00194 KURL url() const;
00195
00201
00202 void setURL(const KURL& url, bool clearforward);
00203
00208 void setCurrentItem( const QString& filename );
00209
00220
00221 void setView(KFileView *view);
00222
00227 KFileView * view() const { return m_fileView; }
00228
00233 QWidget * viewWidget() const { return m_fileView ? m_fileView->widget() : 0L; }
00234
00239
00240 void setView(KFile::FileView view);
00241
00245 void setSorting( QDir::SortSpec );
00246
00250 QDir::SortSpec sorting() const { return mySorting; }
00251
00255 bool isRoot() const { return url().path() == QChar('/'); }
00256
00260 KDirLister *dirLister() const { return dir; }
00261
00266 KProgress * progressBar() const;
00267
00279
00280 void setMode( KFile::Mode m );
00284 KFile::Mode mode() const;
00285
00291
00292 void setPreviewWidget(const QWidget *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
00410 void setViewConfig( KConfig *config, const QString& group );
00411
00419 KConfig *viewConfig();
00420
00428 QString viewConfigGroup() const;
00429
00443 virtual void readConfig( KConfig *, const QString& group = QString::null );
00444
00451 virtual void writeConfig( KConfig *, const QString& group = QString::null );
00452
00453
00464 void setOnlyDoubleClickSelectsFiles( bool enable );
00465
00471 bool onlyDoubleClickSelectsFiles() const;
00472
00481
00482 bool mkdir( const QString& directory, bool enterDirectory = true );
00483
00491
00492 KIO::DeleteJob * del( const KFileItemList& items,
00493 bool ask = true, bool showProgress = true );
00494
00504
00505 KIO::DeleteJob * del( const KFileItemList& items, QWidget *parent,
00506 bool ask = true, bool showProgress = true );
00507
00511 void clearHistory();
00512
00523
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
00563 void setDropOptions(int options);
00564
00574
00575 KIO::CopyJob * trash( const KFileItemList& items, QWidget *parent,
00576 bool ask = true, bool showProgress = true );
00577
00578 protected:
00593 virtual KFileView* createView( QWidget* parent, KFile::FileView view );
00597
00598 void setDirLister( KDirLister *lister );
00599
00600 virtual void resizeEvent( QResizeEvent * );
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
00648 void back();
00649
00653
00654 void forward();
00655
00659
00660 void home();
00661
00665
00666 void cdUp();
00667
00671 void updateDir();
00672
00676
00677 void rereadDir();
00678
00682
00683 void mkdir();
00684
00688
00689 void deleteSelected();
00690
00696 void updateSelectionDependentActions();
00697
00701 QString makeCompletion(const QString&);
00702
00706 QString makeDirCompletion(const QString&);
00707
00712
00713 void trashSelected(KAction::ActivationReason, Qt::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
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 QPoint& 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 QString& match);
00796
00797 signals:
00798 void urlEntered(const KURL& );
00799 void updateInformation(int files, int dirs);
00800 void completion(const QString&);
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, QDropEvent*event, const KURL::List&urls);
00827 private:
00831 QPtrStack<KURL> backStack;
00832
00836 QPtrStack<KURL> forwardStack;
00837
00838 KDirLister *dir;
00839 KURL currUrl;
00840
00841 KCompletion myCompletion;
00842 KCompletion myDirCompletion;
00843 bool myCompleteListDirty;
00844 QDir::SortSpec mySorting;
00845
00850 bool checkPreviewInternal() const;
00851
00856 void checkPath(const QString& 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
00866 int m_viewKind;
00867 int defaultView;
00868
00869 KFile::Mode myMode;
00870 KProgress *progress;
00871
00872 const QWidget *myPreview;
00873
00874
00875
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( QDir::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