1 /* 2 * FileBrowser.h - include file for FileBrowser 3 * 4 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net> 5 * 6 * This file is part of LMMS - https://lmms.io 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public 19 * License along with this program (see COPYING); if not, write to the 20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301 USA. 22 * 23 */ 24 25 26 #ifndef FILE_BROWSER_H 27 #define FILE_BROWSER_H 28 29 #include <QtCore/QDir> 30 #include <QtCore/QMutex> 31 #include <QTreeWidget> 32 33 34 #include "SideBarWidget.h" 35 36 37 class QLineEdit; 38 39 class FileItem; 40 class InstrumentTrack; 41 class FileBrowserTreeWidget; 42 class PlayHandle; 43 class TrackContainer; 44 45 46 47 class FileBrowser : public SideBarWidget 48 { 49 Q_OBJECT 50 public: 51 /** 52 Create a file browser side bar widget 53 @param directories '*'-separated list of directories to search for. 54 If a directory of factory files should be in the list it 55 must be the last one (for the factory files delimiter to work) 56 @param filter Filter as used in QDir::match 57 @param recurse *to be documented* 58 */ 59 FileBrowser( const QString & directories, const QString & filter, 60 const QString & title, const QPixmap & pm, 61 QWidget * parent, bool dirs_as_items = false, bool recurse = false ); 62 virtual ~FileBrowser(); 63 64 private slots: 65 void reloadTree( void ); 66 void expandItems( QTreeWidgetItem * item=NULL ); 67 // call with item=NULL to filter the entire tree 68 bool filterItems( const QString & filter, QTreeWidgetItem * item=NULL ); 69 void giveFocusToFilter(); 70 71 private: 72 virtual void keyPressEvent( QKeyEvent * ke ); 73 74 void addItems( const QString & path ); 75 76 FileBrowserTreeWidget * m_l; 77 78 QLineEdit * m_filterEdit; 79 80 QString m_directories; //!< Directories to search, split with '*' 81 QString m_filter; //!< Filter as used in QDir::match() 82 83 bool m_dirsAsItems; 84 bool m_recurse; 85 86 } ; 87 88 89 90 91 class FileBrowserTreeWidget : public QTreeWidget 92 { 93 Q_OBJECT 94 public: 95 FileBrowserTreeWidget( QWidget * parent ); 96 virtual ~FileBrowserTreeWidget(); 97 98 99 protected: 100 virtual void contextMenuEvent( QContextMenuEvent * e ); 101 virtual void mousePressEvent( QMouseEvent * me ); 102 virtual void mouseMoveEvent( QMouseEvent * me ); 103 virtual void mouseReleaseEvent( QMouseEvent * me ); 104 105 106 private: 107 void handleFile( FileItem * fi, InstrumentTrack * it ); 108 void openInNewInstrumentTrack( TrackContainer* tc ); 109 110 111 bool m_mousePressed; 112 QPoint m_pressPos; 113 114 PlayHandle* m_previewPlayHandle; 115 QMutex m_pphMutex; 116 117 FileItem * m_contextMenuItem; 118 119 120 private slots: 121 void activateListItem( QTreeWidgetItem * item, int column ); 122 void openInNewInstrumentTrackBBE( void ); 123 void openInNewInstrumentTrackSE( void ); 124 void sendToActiveInstrumentTrack( void ); 125 void updateDirectory( QTreeWidgetItem * item ); 126 127 } ; 128 129 130 131 132 class Directory : public QTreeWidgetItem 133 { 134 public: 135 Directory( const QString & filename, const QString & path, 136 const QString & filter ); 137 138 void update( void ); 139 140 inline QString fullName( QString path = QString::null ) 141 { 142 if( path == QString::null ) 143 { 144 path = m_directories[0]; 145 } 146 if( path != QString::null ) 147 { 148 path += QDir::separator(); 149 } 150 return( QDir::cleanPath( path + text( 0 ) ) + 151 QDir::separator() ); 152 } 153 addDirectory(const QString & dir)154 inline void addDirectory( const QString & dir ) 155 { 156 m_directories.push_back( dir ); 157 } 158 159 160 private: 161 void initPixmaps( void ); 162 163 bool addItems( const QString & path ); 164 165 166 static QPixmap * s_folderPixmap; 167 static QPixmap * s_folderOpenedPixmap; 168 static QPixmap * s_folderLockedPixmap; 169 170 //! Directories that lead here 171 //! Initially, this is just set to the current path of a directory 172 //! If, however, you have e.g. 'TripleOscillator/xyz' in two of the 173 //! file browser's search directories 'a' and 'b', this will have two 174 //! entries 'a/TripleOscillator' and 'b/TripleOscillator' 175 //! and 'xyz' in the tree widget 176 QStringList m_directories; 177 //! Filter as used in QDir::match() 178 QString m_filter; 179 180 int m_dirCount; 181 182 } ; 183 184 185 186 187 class FileItem : public QTreeWidgetItem 188 { 189 public: 190 enum FileTypes 191 { 192 ProjectFile, 193 PresetFile, 194 SampleFile, 195 SoundFontFile, 196 PatchFile, 197 MidiFile, 198 VstPluginFile, 199 UnknownFile, 200 NumFileTypes 201 } ; 202 203 enum FileHandling 204 { 205 NotSupported, 206 LoadAsProject, 207 LoadAsPreset, 208 LoadByPlugin, 209 ImportAsProject 210 } ; 211 212 213 FileItem( QTreeWidget * parent, const QString & name, 214 const QString & path ); 215 FileItem( const QString & name, const QString & path ); 216 fullName()217 QString fullName() const 218 { 219 return QFileInfo(m_path, text(0)).absoluteFilePath(); 220 } 221 type(void)222 inline FileTypes type( void ) const 223 { 224 return( m_type ); 225 } 226 handling(void)227 inline FileHandling handling( void ) const 228 { 229 return( m_handling ); 230 } 231 232 QString extension( void ); 233 static QString extension( const QString & file ); 234 235 236 private: 237 void initPixmaps( void ); 238 void determineFileType( void ); 239 240 static QPixmap * s_projectFilePixmap; 241 static QPixmap * s_presetFilePixmap; 242 static QPixmap * s_sampleFilePixmap; 243 static QPixmap * s_soundfontFilePixmap; 244 static QPixmap * s_vstPluginFilePixmap; 245 static QPixmap * s_midiFilePixmap; 246 static QPixmap * s_unknownFilePixmap; 247 248 QString m_path; 249 FileTypes m_type; 250 FileHandling m_handling; 251 252 } ; 253 254 255 #endif 256