From 8a5150677cd811a73a0c9a9a150a19fb80284764 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Fri, 7 Apr 2006 06:27:50 +0000 Subject: [PATCH] improved file-browser git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@122 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 18 ++ TODO | 1 + configure.in | 4 +- data/themes/default/factory_files.png | Bin 0 -> 1117 bytes include/config_mgr.h | 9 +- include/file_browser.h | 35 ++-- src/core/config_mgr.cpp | 18 +- src/core/file_browser.cpp | 229 +++++++++++++++++++------- src/core/main_window.cpp | 15 +- src/lib/project_journal.cpp | 2 +- 10 files changed, 242 insertions(+), 89 deletions(-) create mode 100644 data/themes/default/factory_files.png diff --git a/ChangeLog b/ChangeLog index d59588f9a..bcba0fb5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2006-04-06 Tobias Doerffel + + * include/config_mgr.h: + * src/core/config_mgr.cpp: + use setup-wizard only for setting working-directory + + * src/core/main_window.cpp: + when creating file-browsers, pass 2 directories: + - factory-files + - user-files + this concerns projects, presets and samples - obsoletes + copying/linking files the first time, LMMS is run (new factory files in + new versions do not cause any trouble anymore) + + * include/file_browser.h: + * src/core/file_browser.cpp: + added support for merging several directory-trees into one view + 2006-04-05 Danny McRae * include/sample_track.h: diff --git a/TODO b/TODO index dc47e7a49..0cd9c1352 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ +- replace rest of wizard by simple directory-selection-dialog for working-dir when running the first time - do REAL release in envelopes (can't be precalculated as it depends on key-press-duration/rest of envelope) - correctly load steps/dots from FLP-files - vibed-plugin: do not crash at destruction diff --git a/configure.in b/configure.in index d37b1cfb6..703b3007b 100644 --- a/configure.in +++ b/configure.in @@ -2,8 +2,8 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.50) -AC_INIT(lmms, 0.1.4-cvs20060405, tobydox/at/users/dot/sourceforge/dot/net) -AM_INIT_AUTOMAKE(lmms, 0.1.4-cvs20060405) +AC_INIT(lmms, 0.1.4-cvs20060406, tobydox/at/users/dot/sourceforge/dot/net) +AM_INIT_AUTOMAKE(lmms, 0.1.4-cvs20060406) AM_CONFIG_HEADER(config.h) diff --git a/data/themes/default/factory_files.png b/data/themes/default/factory_files.png new file mode 100644 index 0000000000000000000000000000000000000000..469e59c68a204ca57492d35d0b222bfeb8d8464e GIT binary patch literal 1117 zcmV-j1fu(iP)jzheLbF)>jFD=RAo5fM=! z??21WpTE`Cty_BoAb?oDfB(kw?%jtkzkmPx9UGg-VQp;;QZMZ2=nz|2n6G*C=mAew zR+cw1GSUpcfB$A+W@dIXH8t;h@Zgy=P+cBC05N1`Q zmzS4+2hat4009K_%P$520YQf1;xajQcJ@mgoLql^G{gJ%Um3oA{lW0>-#->}bMrq| zR(5mv_{5Ui+8UqSx^=A_sCgR@e*y>~W-&2|SX~_>VIE#C216q=ZbJiOUUp6nhHtaz3B?nxDSYbfC393fS4aVxbuNuK*UE$S&f;C zlbeAGX#1BBpBSE9z04pWA<%=E35aEc1SW*n zRP?!ed+>eVw2oof`U?Liv2ov*_6z4W(AH=E_46kKBNHQosfhujxVWs*rArr7-n@Ce z8z6v~^+3r^Omt36M@xpDp)T`>*;5z}?B2`J_VwS*2VcI}U%h(a5ho|NiaddWidget( workingdir_content ); - +/* // page for files-management m_pageFiles = new QWidget( m_contentWidget ); QHBoxLayout * files_layout = new QHBoxLayout( m_pageFiles ); @@ -502,12 +502,12 @@ void configManager::createWidgets( void ) files_layout->addWidget( files_logo_lbl ); files_layout->addWidget( files_content ); - +*/ addPage( m_pageIntro, tr( "Welcome to LMMS" ) ); addPage( m_pageWorkingDir, tr( "Select working directory" ) ); - addPage( m_pageFiles, tr( "Copy or link files" ) ); + //addPage( m_pageFiles, tr( "Copy or link files" ) ); switchPage( static_cast( 0 ) ); } @@ -595,7 +595,11 @@ void configManager::accept( void ) return; } } - processFilesRecursively( m_dataDir + "samples/", m_workingDir + + + mkPath( projectsDir() ); + mkPath( samplesDir() ); + mkPath( presetsDir() ); +/* processFilesRecursively( m_dataDir + "samples/", m_workingDir + "samples/", m_samplesCopyRB->isChecked() ? ©File : @@ -609,7 +613,7 @@ void configManager::accept( void ) "projects/", m_projectsCopyRB->isChecked() ? ©File : - &linkFile ); + &linkFile );*/ saveConfigFile(); QDialog::accept(); @@ -942,7 +946,7 @@ void configManager::saveConfigFile( void ) - +/* void configManager::processFilesRecursively( const QString & _src_dir, const QString & _dst_dir, void( * _proc_func )( const QString & _src, const QString & _dst ) ) @@ -967,7 +971,7 @@ void configManager::processFilesRecursively( const QString & _src_dir, } } } - +*/ diff --git a/src/core/file_browser.cpp b/src/core/file_browser.cpp index 6787a1bb4..925d3f3f6 100644 --- a/src/core/file_browser.cpp +++ b/src/core/file_browser.cpp @@ -61,16 +61,17 @@ #include "text_float.h" #include "string_pair_drag.h" #include "main_window.h" +#include "config_mgr.h" -fileBrowser::fileBrowser( const QString & _path, const QString & _filter, +fileBrowser::fileBrowser( const QString & _directories, const QString & _filter, const QString & _title, const QPixmap & _pm, QWidget * _parent, engine * _engine ) : sideBarWidget( _title, _pm, _parent ), engineObject( _engine ), m_contextMenuItem( NULL ), - m_path( _path ), + m_directories( _directories ), m_filter( _filter ) { setWindowTitle( tr( "Browser" ) ); @@ -112,7 +113,49 @@ fileBrowser::~fileBrowser() void fileBrowser::reloadTree( void ) { m_l->clear(); - QDir cdir( m_path ); + QStringList paths = QStringList::split( '*', m_directories ); + for( QStringList::iterator it = paths.begin(); it != paths.end(); ++it ) + { + addItems( *it ); + } + + Q3ListViewItem * item = m_l->firstChild(); + bool resort = FALSE; + + // sort merged directories + while( item != NULL ) + { + directory * d = dynamic_cast( item ); + if( d == NULL ) + { + resort = TRUE; + } + else if( resort == TRUE ) + { + Q3ListViewItem * i2 = m_l->firstChild(); + d->moveItem( i2 ); + i2->moveItem( d ); + directory * d2 = NULL; + while( ( d2 = dynamic_cast( i2 ) ) != + NULL ) + { + if( d->text( 0 ) > d2->text( 0 ) ) + { + d->moveItem( d2 ); + } + i2 = i2->nextSibling(); + } + } + item = item->nextSibling(); + } +} + + + + +void fileBrowser::addItems( const QString & _path ) +{ + QDir cdir( _path ); QStringList files = cdir.entryList( QDir::NoFilter, QDir::Name ); // TODO: after dropping qt3-support we can use QStringList's iterator @@ -123,7 +166,7 @@ void fileBrowser::reloadTree( void ) { QString cur_file = files[files.size() - i - 1]; if( cur_file[0] != '.' && - !QFileInfo( m_path + "/" + cur_file ).isDir() + !QFileInfo( _path + "/" + cur_file ).isDir() #ifdef QT4 // TBD #else @@ -131,7 +174,9 @@ void fileBrowser::reloadTree( void ) #endif ) { - (void) new fileItem( m_l, cur_file, m_path ); + // remove existing file-items + delete m_l->findItem( cur_file, 0 ); + (void) new fileItem( m_l, cur_file, _path ); } } @@ -139,9 +184,19 @@ void fileBrowser::reloadTree( void ) { QString cur_file = files[files.size() - i - 1]; if( cur_file[0] != '.' && - QFileInfo( m_path + "/" + cur_file ).isDir() ) + QFileInfo( _path + "/" + cur_file ).isDir() ) { - (void) new directory( m_l, cur_file, m_path, m_filter ); + QListViewItem * item = m_l->findItem( cur_file, 0 ); + if( item == NULL ) + { + (void) new directory( m_l, cur_file, _path, + m_filter ); + } + else if( dynamic_cast( item ) != NULL ) + { + dynamic_cast( item )-> + addDirectory( _path ); + } } } } @@ -224,7 +279,8 @@ void fileBrowser::sendToActiveInstrumentTrack( void ) // instrument-track while( w != NULL ) { - instrumentTrack * ct = dynamic_cast( w ); + instrumentTrack * ct = + dynamic_cast( w ); #endif if( ct != NULL && ct->isHidden() == FALSE ) { @@ -355,20 +411,20 @@ void listView::contentsMouseDoubleClickEvent( QMouseEvent * _me ) { // samples are per default opened in bb-editor because // they're likely drum-samples etc. - instrumentTrack * ct = dynamic_cast( + instrumentTrack * it = dynamic_cast( track::create( track::CHANNEL_TRACK, eng()->getBBEditor() ) ); #ifdef LMMS_DEBUG - assert( ct != NULL ); + assert( it != NULL ); #endif - instrument * afp = ct->loadInstrument( + instrument * afp = it->loadInstrument( "audiofileprocessor" ); if( afp != NULL ) { afp->setParameter( "samplefile", f->fullName() ); } - ct->toggledInstrumentTrackButton( TRUE ); + it->toggledInstrumentTrackButton( TRUE ); } else if( f->type() == fileItem::PRESET_FILE ) { @@ -407,6 +463,7 @@ void listView::contentsMousePressEvent( QMouseEvent * _me ) { return; } + QPoint p( contentsToViewport( _me->pos() ) ); Q3ListViewItem * i = itemAt( p ); if ( i ) @@ -421,6 +478,7 @@ void listView::contentsMousePressEvent( QMouseEvent * _me ) m_mousePressed = TRUE; } } + fileItem * f = dynamic_cast( i ); if( f != NULL ) { @@ -552,7 +610,7 @@ directory::directory( directory * _parent, const QString & _name, Q3ListViewItem( _parent, _name ), m_p( _parent ), m_pix( NULL ), - m_path( _path ), + m_directories( _path ), m_filter( _filter ) { initPixmapStuff(); @@ -566,7 +624,7 @@ directory::directory( Q3ListView * _parent, const QString & _name, Q3ListViewItem( _parent, _name ), m_p( NULL ), m_pix( NULL ), - m_path( _path ), + m_directories( _path ), m_filter( _filter ) { initPixmapStuff(); @@ -583,11 +641,13 @@ void directory::initPixmapStuff( void ) s_folderPixmap = new QPixmap( embed::getIconPixmap( "folder" ) ); } + if( s_folderOpenedPixmap == NULL ) { s_folderOpenedPixmap = new QPixmap( embed::getIconPixmap( "folder_opened" ) ); } + if( s_folderLockedPixmap == NULL ) { s_folderLockedPixmap = new QPixmap( @@ -607,7 +667,7 @@ void directory::initPixmapStuff( void ) -void directory::setPixmap( QPixmap * _px ) +void directory::setPixmap( const QPixmap * _px ) { m_pix = _px; setup(); @@ -632,57 +692,18 @@ void directory::setOpen( bool _o ) if( _o && !childCount() ) { - QString s( fullName() ); - QDir thisDir( s ); - if( !thisDir.isReadable() ) + for( QStringList::iterator it = m_directories.begin(); + it != m_directories.end(); ++it ) { - //readable = FALSE; - setExpandable( FALSE ); - return; - } - - listView()->setUpdatesEnabled( FALSE ); - - QStringList files = thisDir.entryList( QDir::NoFilter, - QDir::Name ); - for( csize i = 0; i < files.size(); ++i ) - { - QString cur_file = files[files.size()-i-1]; -#ifdef QT4 - if( cur_file[0] != '.' && !QFileInfo( - thisDir.absolutePath() + "/" + - cur_file ).isDir() && - thisDir.match( m_filter, cur_file.toLower() ) - /*QDir::match( FILE_FILTER, cur_file )*/ ) -#else - if( cur_file[0] != '.' && !QFileInfo( - thisDir.absPath() + "/" + - cur_file ).isDir() && - thisDir.match( m_filter, cur_file.lower() ) - /*QDir::match( FILE_FILTER, cur_file )*/ ) -#endif + if( addItems( fullName( *it ) ) && + ( *it ).contains( + configManager::inst()->dataDir() ) ) { - (void) new fileItem( this, cur_file, s ); + ( new QListViewItem( this, + listView::tr( "--- Factory files ---" ) ) )->setPixmap( 0, + embed::getIconPixmap( "factory_files" ) ); } } - for( csize i = 0; i < files.size(); ++i ) - { - QString cur_file = files[files.size()-i-1]; -#ifdef QT4 - if( cur_file[0] != '.' && QFileInfo( - thisDir.absolutePath() + "/" + - cur_file ).isDir() ) -#else - if( cur_file[0] != '.' && QFileInfo( - thisDir.absPath() + "/" + - cur_file ).isDir() ) -#endif - { - (void) new directory( this, cur_file, s, - m_filter ); - } - } - listView()->setUpdatesEnabled( TRUE ); } Q3ListViewItem::setOpen( _o ); } @@ -699,6 +720,90 @@ void directory::setup( void ) +bool directory::addItems( const QString & _path ) +{ + QDir thisDir( _path ); + if( !thisDir.isReadable() ) + { + //readable = FALSE; + setExpandable( FALSE ); + return( FALSE ); + } + + listView()->setUpdatesEnabled( FALSE ); + + bool added_something = FALSE; + + QStringList files = thisDir.entryList( QDir::NoFilter, QDir::Name ); + for( csize i = 0; i < files.size(); ++i ) + { + QString cur_file = files[files.size() - i - 1]; +#ifdef QT4 + if( cur_file[0] != '.' && !QFileInfo( + thisDir.absolutePath() + "/" + + cur_file ).isDir() && + thisDir.match( m_filter, cur_file.toLower() ) + /*QDir::match( FILE_FILTER, cur_file )*/ ) +#else + if( cur_file[0] != '.' && !QFileInfo( + thisDir.absPath() + "/" + + cur_file ).isDir() && + thisDir.match( m_filter, cur_file.lower() ) + /*QDir::match( FILE_FILTER, cur_file )*/ ) +#endif + { + (void) new fileItem( this, cur_file, _path ); + added_something = TRUE; + } + } + + for( csize i = 0; i < files.size(); ++i ) + { + QString cur_file = files[files.size() - i - 1]; +#ifdef QT4 + if( cur_file[0] != '.' && QFileInfo( + thisDir.absolutePath() + "/" + + cur_file ).isDir() ) +#else + if( cur_file[0] != '.' && QFileInfo( + thisDir.absPath() + "/" + + cur_file ).isDir() ) +#endif + { + new directory( this, cur_file, _path, m_filter ); + added_something = TRUE; +#if 0 + if( firstChild() == NULL ) + { + continue; + } + bool moved = FALSE; + QListViewItem * item = firstChild(); + while( item != NULL ) + { + directory * cd = + dynamic_cast( item ); + if( cd != NULL ) + { +/* if( moved == FALSE || + cd->text( 0 ) < cur_file ) + {*/ + printf( "move item %s after %s\n", d->text(0).ascii(), cd->text(0).ascii()); + d->moveItem( cd ); + moved = TRUE; + //} + } + item = item->nextSibling(); + } +#endif + } + } + + listView()->setUpdatesEnabled( TRUE ); + + return( added_something ); +} + diff --git a/src/core/main_window.cpp b/src/core/main_window.cpp index 9d604851e..550a54f6e 100644 --- a/src/core/main_window.cpp +++ b/src/core/main_window.cpp @@ -126,20 +126,27 @@ mainWindow::mainWindow( engine * _engine ) : int id = 0; QString wdir = configManager::inst()->workingDir(); side_bar->appendTab( new pluginBrowser( splitter, eng() ), ++id ); - side_bar->appendTab( new fileBrowser( wdir+"projects", + side_bar->appendTab( new fileBrowser( configManager::inst()->dataDir()+ + PROJECTS_PATH + "*" + + wdir+PROJECTS_PATH, "*.mmp *.xml *.mid *.flp", tr( "My projects" ), embed::getIconPixmap( "project_file" ), splitter, eng() ), ++id ); - side_bar->appendTab( new fileBrowser( wdir+"samples", "*.wav *.ogg *.au" + side_bar->appendTab( new fileBrowser( configManager::inst()->dataDir()+ + SAMPLES_PATH + "*" + + wdir+SAMPLES_PATH, + "*.wav *.ogg *.au" "*.voc *.aif *.aiff *.flac *.raw", tr( "My samples" ), embed::getIconPixmap( "sound_file" ), splitter, eng() ), ++id ); - side_bar->appendTab( new fileBrowser( wdir+"presets", "*.cs.xml", - tr( "My presets" ), + side_bar->appendTab( new fileBrowser( configManager::inst()->dataDir()+ + PRESETS_PATH + "*" + + wdir+PRESETS_PATH, + "*.cs.xml", tr( "My presets" ), embed::getIconPixmap( "preset_file" ), splitter, eng() ), ++id ); diff --git a/src/lib/project_journal.cpp b/src/lib/project_journal.cpp index b1381f904..e6c376a51 100644 --- a/src/lib/project_journal.cpp +++ b/src/lib/project_journal.cpp @@ -135,7 +135,7 @@ void projectJournal::reallocID( const jo_id_t _id, journallingObject * _obj ) void projectJournal::forgetAboutID( const jo_id_t _id ) { - printf("forget about %d\n", _id ); + //printf("forget about %d\n", _id ); journalEntryVector::iterator it; while( ( it = qFind( m_journalEntries.begin(), m_journalEntries.end(), _id ) ) != m_journalEntries.end() )