SVN commit 545481 by seb: Lazy load the playlistbrowser and super improve the startup times for amaroK. I have clocked up to an 80% improvements in startup times. Unfortunately this reintroduces the "forgetton width" issue... Being looked into atm. M +13 -6 browserbar.cpp M +1 -0 browserbar.h M +23 -53 playlistbrowser.cpp --- trunk/extragear/multimedia/amarok/src/browserbar.cpp #545480:545481 @@ -99,6 +99,17 @@ config->writeEntry( "Width", m_browserBox->width() ); } +int +BrowserBar::restoreWidth() +{ + KConfig* const config = amaroK::config( "BrowserBar" ); + const int index = indexForName( config->readEntry( "CurrentPane" ) ); + const int width = config->readNumEntry( "Width", browser( index )->sizeHint().width() ); + + m_browserBox->resize( width, height() ); + return index; +} + void BrowserBar::polish() { @@ -112,17 +123,13 @@ if( m > M ) M = m; } - KConfig* const config = amaroK::config( "BrowserBar" ); - const int index = indexForName( config->readEntry( "CurrentPane" ) ); - const int width = config->readNumEntry( "Width", browser( index )->sizeHint().width() ); - if( M > 250 ) { warning() << "Some browsers are insisting on a silly minimum size! " << M << endl; M = 250; } m_browserBox->setMinimumWidth( M ); - m_browserBox->resize( width, height() ); + const int index = restoreWidth(); if( index != -1 ) // if we did it for -1 it ruins the browserBox size @@ -266,7 +273,7 @@ adjustWidgetSizes(); } } - + emit browserActivated( index ); } --- trunk/extragear/multimedia/amarok/src/browserbar.h #545480:545481 @@ -44,6 +44,7 @@ int visibleCount() const; void addBrowser( QWidget*, const QString&, const QString& ); + int restoreWidth(); /// for internal use void mouseMovedOverSplitter( QMouseEvent* ); --- trunk/extragear/multimedia/amarok/src/playlistbrowser.cpp #545480:545481 @@ -138,45 +138,8 @@ m_infoPane = new InfoPane( this ); - // FIXME the following code moved here from polish(), until the width - // forgetting issue is fixed: - - m_polished = true; - - m_playlistCategory = loadPlaylists(); - if( !CollectionDB::instance()->isEmpty() ) { - m_smartCategory = loadSmartPlaylists(); - loadDefaultSmartPlaylists(); - } - m_dynamicCategory = loadDynamics(); - m_randomDynamic = new DynamicEntry( m_dynamicCategory, 0, i18n("Random Mix") ); - m_suggestedDynamic = new DynamicEntry( m_dynamicCategory, m_randomDynamic, i18n("Suggested Songs" ) ); - m_suggestedDynamic->setAppendType( DynamicMode::SUGGESTION ); - - m_streamsCategory = loadStreams(); - loadCoolStreams(); - - // must be loaded after streams m_podcastCategory = loadPodcasts(); - if ( amaroK::dynamicMode() ) { - - QStringList playlists = amaroK::dynamicMode()->items(); - - for( uint i=0; i < playlists.count(); i++ ) - { - QListViewItem *item = m_listview->findItem( playlists[i], 0, Qt::ExactMatch ); - if( item ) - { - m_dynamicEntries.append( item ); - if( item->rtti() == PlaylistEntry::RTTI ) - static_cast( item )->setDynamic( true ); - if( item->rtti() == SmartPlaylist::RTTI ) - static_cast( item )->setDynamic( true ); - } - } - } - setSpacing( 4 ); setFocusProxy( m_listview ); } @@ -188,47 +151,54 @@ // we make startup faster by doing the slow bits for this // only when we are shown on screen - DEBUG_BLOCK + DEBUG_FUNC_INFO -// amaroK::OverrideCursor allocate_on_stack; + amaroK::OverrideCursor cursor; +// blockSignals( true ); +// BrowserBar::instance()->restoreWidth(); +// blockSignals( false ); + QVBox::polish(); // FIXME the following code moved to the ctor, until the width forgetting // issue is fixed: -/* m_polished = true; + /// Podcasting is always initialised in the ctor because of autoscanning + m_polished = true; + KConfig *config = amaroK::config( "PlaylistBrowser" ); m_playlistCategory = loadPlaylists(); m_streamsCategory = loadStreams(); loadCoolStreams(); - if( !CollectionDB::instance()->isEmpty() ) { + if( !CollectionDB::instance()->isEmpty() ) + { m_smartCategory = loadSmartPlaylists(); loadDefaultSmartPlaylists(); m_smartCategory->setOpen( true ); } - // must be loaded after streams - m_podcastCategory = loadPodcasts(); m_dynamicCategory = loadDynamics(); m_playlistCategory->setOpen( true ); - m_podcastCategory->setOpen( true ); m_streamsCategory->setOpen( true ); m_dynamicCategory->setOpen( true ); - QStringList playlists = amaroK::dynamicMode()->items(); - - for( uint i=0; i < playlists.count(); i++ ) + if( amaroK::dynamicMode() ) { - QListViewItem *item = m_listview->findItem( playlists[i], 0, Qt::ExactMatch ); - if( item ) + QStringList playlists = amaroK::dynamicMode()->items(); + + for( uint i=0; i < playlists.count(); i++ ) { - item->setPixmap( 1, SmallIcon("favorites") ); - m_dynamicEntries.append( item ); + QListViewItem *item = m_listview->findItem( playlists[i], 0, Qt::ExactMatch ); + if( item ) + { + item->setPixmap( 1, SmallIcon("favorites") ); + m_dynamicEntries.append( item ); + } } } @@ -256,7 +226,7 @@ } ++it; } - }*/ + } } @@ -847,7 +817,7 @@ QDomDocument d; QDomElement e; - QListViewItem *after = m_streamsCategory; + QListViewItem *after = 0; if( !file.open( IO_ReadOnly ) || !d.setContent( stream.read() ) ) { /*Couldn't open the file or it had invalid content, so let's create an empty element*/