File indexing completed on 2024-05-05 04:47:22

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef FILEBROWSERMKII_H
0018 #define FILEBROWSERMKII_H
0019 
0020 #include "browsers/BrowserCategory.h"
0021 
0022 #include <QUrl>
0023 
0024 class QAbstractItemView;
0025 class QModelIndex;
0026 
0027 class FileBrowser : public BrowserCategory
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     FileBrowser( const char *name, QWidget *parent );
0033     ~FileBrowser() override;
0034 
0035     void setupAddItems() override;
0036 
0037     /**
0038     * Navigate to a specific directory
0039     */
0040     void setDir( const QUrl &dir );
0041 
0042     /**
0043      * Return the path of the currently shown dir.
0044      */
0045     QString currentDir() const;
0046 
0047 public Q_SLOTS:
0048     void addItemActivated( const QString &callback );
0049 
0050 protected Q_SLOTS:
0051     void slotNavigateToDirectory( const QModelIndex &index );
0052 
0053     void reActivate() override;
0054 
0055     /**
0056      * Shows/hides the columns as selected in the context menu of the header of the
0057      * file view.
0058      * @param toggled the visibility state of a column in the context menu.
0059      */
0060     void toggleColumn( bool toggled );
0061 
0062     /**
0063      * Go backward in history
0064      */
0065     void back();
0066 
0067     /**
0068      * Go forward in history
0069      */
0070     void forward();
0071 
0072     /**
0073      * Navigates up one level in the path shown
0074      */
0075     void up();
0076 
0077     /**
0078      * Navigates to home directory
0079      */
0080     void home();
0081 
0082     /*
0083      * Refreshes current directory
0084      */
0085     void refresh();
0086 
0087     /**
0088      * Handle results of trying to setup an item in "places" that needed mounting or other
0089      * special setup.
0090      * @param index the index that we tried to setup
0091      * @param success did the setup succeed?
0092      */
0093     void setupDone( const QModelIndex &index, bool success );
0094 
0095 private Q_SLOTS:
0096     void initView();
0097     void updateHeaderState();
0098 
0099 private:
0100     class Private;
0101     Private *const d;
0102 };
0103 
0104 /**
0105  * Helper class that calls setCurrentIndex on a model view as soon as the model
0106  * adds a row and then it auto-deletes itself.
0107  */
0108 class DelayedActivator : public QObject
0109 {
0110     Q_OBJECT
0111 
0112     public:
0113         explicit DelayedActivator( QAbstractItemView *view );
0114 
0115     private Q_SLOTS:
0116         void slotRowsInserted( const QModelIndex &parent, int start );
0117 
0118     private:
0119         QAbstractItemView *m_view;
0120 };
0121 
0122 #endif // FILEBROWSERMKII_H