File indexing completed on 2024-05-19 04:48:38
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2010 Casey Link <unnamedrambler@gmail.com> * 0004 * Copyright (c) 2010 Téo Mrnjavac <teo@kde.org> * 0005 * Copyright (c) 2010 Rick W. Chen <stuffcorpse@archlinux.us> * 0006 * * 0007 * This program is free software; you can redistribute it and/or modify it under * 0008 * the terms of the GNU General Public License as published by the Free Software * 0009 * Foundation; either version 2 of the License, or (at your option) any later * 0010 * version. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0013 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0014 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License along with * 0017 * this program. If not, see <http://www.gnu.org/licenses/>. * 0018 ****************************************************************************************/ 0019 0020 #ifndef AMAROK_FILEBROWSER_P_H 0021 #define AMAROK_FILEBROWSER_P_H 0022 0023 #include "FileBrowser.h" 0024 0025 #include "browsers/BrowserBreadcrumbItem.h" 0026 0027 #include <KDirModel> 0028 #include <KFilePlacesModel> 0029 0030 #include <QApplication> 0031 #include <QFontMetrics> 0032 #include <QStack> 0033 0034 class QSortFilterProxyModel; 0035 class DirBrowserModel; 0036 class SearchWidget; 0037 class FileView; 0038 class QAction; 0039 class KFilePlacesModel; 0040 class DirPlaylistTrackFilterProxyModel; 0041 0042 template<typename T> 0043 class UniqueStack : public QStack<T> 0044 { 0045 public: 0046 inline void push( const T &t ) 0047 { 0048 if( QStack<T>::isEmpty() || t != QStack<T>::top() ) 0049 QStack<T>::push( t ); 0050 } 0051 }; 0052 0053 class FileBrowser::Private 0054 { 0055 public: 0056 Private( FileBrowser *parent ); 0057 ~Private(); 0058 0059 void readConfig(); 0060 void writeConfig(); 0061 void restoreHeaderState(); 0062 void saveHeaderState(); 0063 0064 void updateNavigateActions(); 0065 BreadcrumbSiblingList siblingsForDir( const QUrl &path ); 0066 0067 void updateHeaderState(); 0068 0069 QList<QAction *> columnActions; //!< Maintains the mapping action<->column 0070 0071 KFilePlacesModel *bottomPlacesModel; 0072 QSortFilterProxyModel *placesModel; 0073 0074 DirBrowserModel *kdirModel; 0075 DirPlaylistTrackFilterProxyModel *mimeFilterProxyModel; 0076 0077 SearchWidget *searchWidget; 0078 0079 QUrl currentPath; 0080 FileView *fileView; 0081 0082 QAction *upAction; 0083 QAction *homeAction; 0084 QAction *refreshAction; 0085 0086 QAction *backAction; 0087 QAction *forwardAction; 0088 0089 UniqueStack<QUrl> backStack; 0090 UniqueStack<QUrl> forwardStack; 0091 0092 private: 0093 void restoreDefaultHeaderState(); 0094 0095 FileBrowser *const q; 0096 }; 0097 0098 class DirBrowserModel : public KDirModel 0099 { 0100 Q_OBJECT 0101 0102 public: 0103 explicit DirBrowserModel( QObject *parent = nullptr ) : KDirModel( parent ) 0104 { 0105 } 0106 0107 ~DirBrowserModel() override {} 0108 0109 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override 0110 { 0111 if( role == Qt::SizeHintRole ) 0112 return QSize( 1, QFontMetrics( QFont() ).height() + 4 ); 0113 else 0114 return KDirModel::data( index, role ); 0115 } 0116 }; 0117 0118 class FilePlacesModel : public KFilePlacesModel 0119 { 0120 Q_OBJECT 0121 0122 public: 0123 explicit FilePlacesModel( QObject *parent = nullptr ) : KFilePlacesModel( parent ) 0124 { 0125 } 0126 0127 ~FilePlacesModel() override {} 0128 0129 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override 0130 { 0131 if( role == Qt::SizeHintRole ) 0132 return QSize( 1, QFontMetrics( QFont() ).height() + 4 ); 0133 else 0134 return KFilePlacesModel::data( index, role ); 0135 } 0136 }; 0137 0138 #endif /* AMAROK_FILEBROWSER_P_H */