diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 295c00393..1bb1f4a26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,7 +11,7 @@ INCLUDE( ${QT_USE_FILE} ) INCLUDE( ${CMAKE_MODULE_PATH}/AddAppIconMacro.cmake ) -SET( CMAKE_BUILD_TYPE "debugfull" ) +#SET( CMAKE_BUILD_TYPE "debugfull" ) SET( CMAKE_VERBOSE_MAKEFILE ON ) SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" ) SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" ) diff --git a/src/database/databasecommand_loadplaylistentries.cpp b/src/database/databasecommand_loadplaylistentries.cpp index f29b77813..c71fe9b8f 100644 --- a/src/database/databasecommand_loadplaylistentries.cpp +++ b/src/database/databasecommand_loadplaylistentries.cpp @@ -17,9 +17,7 @@ DatabaseCommand_LoadPlaylistEntries::exec( DatabaseImpl* dbi ) "FROM playlist_revision " "WHERE guid = :guid"); query_entries.bindValue( ":guid", m_guid ); - - bool aok = query_entries.exec(); - Q_ASSERT( aok ); + query_entries.exec(); QStringList guids; QMap< QString, plentry_ptr > entrymap; diff --git a/src/database/databaseimpl.cpp b/src/database/databaseimpl.cpp index 6e3103e19..150d348ff 100644 --- a/src/database/databaseimpl.cpp +++ b/src/database/databaseimpl.cpp @@ -327,8 +327,7 @@ DatabaseImpl::searchTable( const QString& table, const QString& name_orig, uint // first check for exact matches: query.prepare( QString( "SELECT id FROM %1 WHERE sortname = ?" ).arg( table ) ); query.addBindValue( name ); - bool exactok = query.exec(); - Q_ASSERT( exactok ); + query.exec(); while( query.next() ) results.append( query.value( 0 ).toInt() ); diff --git a/src/database/databaseworker.cpp b/src/database/databaseworker.cpp index d07296ab6..699c4437a 100644 --- a/src/database/databaseworker.cpp +++ b/src/database/databaseworker.cpp @@ -66,6 +66,7 @@ DatabaseWorker::doWork( QSharedPointer cmd ) { bool transok = m_dbimpl->database().transaction(); Q_ASSERT( transok ); + Q_UNUSED( transok ); } try { diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 35c33e341..384ff435b 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -101,14 +101,14 @@ void Connection::shutdown( bool waitUntilSentAll ) { qDebug() << Q_FUNC_INFO << waitUntilSentAll; - if(m_do_shutdown) + if ( m_do_shutdown ) { //qDebug() << id() << " already shutting down"; return; } m_do_shutdown = true; - if( !waitUntilSentAll ) + if ( !waitUntilSentAll ) { qDebug() << "Shutting down immediately " << id(); actualShutdown(); @@ -255,12 +255,12 @@ Connection::socketDisconnected() << "bytesRecvd" << bytesReceived(); m_peer_disconnected = true; - emit socketClosed(); if( m_msgprocessor_in.length() == 0 && m_sock->bytesAvailable() == 0 ) { handleIncomingQueueEmpty(); + actualShutdown(); } } @@ -433,7 +433,7 @@ Connection::bytesWritten( qint64 i ) { m_tx_bytes += i; // if we are waiting to shutdown, and have sent all queued data, do actual shutdown: - if( m_do_shutdown && m_tx_bytes == m_tx_bytes_requested ) + if ( m_do_shutdown && m_tx_bytes == m_tx_bytes_requested ) actualShutdown(); } diff --git a/src/network/servent.cpp b/src/network/servent.cpp index 1ee4fd030..7e256da61 100644 --- a/src/network/servent.cpp +++ b/src/network/servent.cpp @@ -602,8 +602,7 @@ Servent::onFileTransferFinished( FileTransferConnection* ftc ) qDebug() << "FileTransfer Finished, unregistering" << ftc->id(); QMutexLocker lock( &m_ftsession_mut ); - int rem = m_ftsessions.removeAll( ftc ); - Q_ASSERT( rem == 1 ); + m_ftsessions.removeAll( ftc ); printCurrentTransfers(); emit fileTransferFinished( ftc ); diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index 1a24ac6ff..6b26da874 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -30,20 +30,19 @@ PlaylistManager::PlaylistManager( QObject* parent ) { m_stack = new QStackedWidget(); - m_queueView = new QueueView(); - m_queueModel = new PlaylistModel( m_queueView ); - m_queueView->queue()->setModel( m_queueModel ); - APP->audioEngine()->setQueue( m_queueView->queue()->proxyModel() ); - m_widget->setLayout( new QVBoxLayout() ); m_splitter = new AnimatedSplitter(); m_splitter->setOrientation( Qt::Vertical ); m_splitter->setChildrenCollapsible( false ); m_splitter->setGreedyWidget( 0 ); - m_splitter->addWidget( m_stack ); - m_splitter->addWidget( m_queueView ); + + m_queueView = new QueueView( m_splitter ); + m_queueModel = new PlaylistModel( m_queueView ); + m_queueView->queue()->setModel( m_queueModel ); + APP->audioEngine()->setQueue( m_queueView->queue()->proxyModel() ); + m_splitter->hide( 1, false ); m_widget->layout()->setMargin( 0 ); diff --git a/src/playlist/queueview.cpp b/src/playlist/queueview.cpp index e05cf08e5..c85bc7aa0 100644 --- a/src/playlist/queueview.cpp +++ b/src/playlist/queueview.cpp @@ -5,12 +5,19 @@ #include "playlist/queueproxymodel.h" +#ifdef Q_WS_MAC +#define MINIMUM_HEIGHT 38 +#else +#define MINIMUM_HEIGHT 27 +#endif + using namespace Tomahawk; -QueueView::QueueView( QWidget* parent ) - : QWidget( parent ) +QueueView::QueueView( AnimatedSplitter* parent ) + : AnimatedWidget( parent ) { + setHiddenSize( QSize( 0, MINIMUM_HEIGHT ) ); setLayout( new QVBoxLayout() ); m_queue = new PlaylistView( this ); diff --git a/src/playlist/queueview.h b/src/playlist/queueview.h index 084460761..204e63ad3 100644 --- a/src/playlist/queueview.h +++ b/src/playlist/queueview.h @@ -3,14 +3,15 @@ #include +#include "utils/animatedsplitter.h" #include "playlistview.h" -class QueueView : public QWidget +class QueueView : public AnimatedWidget { Q_OBJECT public: - explicit QueueView( QWidget* parent = 0 ); + explicit QueueView( AnimatedSplitter* parent ); ~QueueView(); PlaylistView* queue() const { return m_queue; } @@ -18,12 +19,8 @@ public: QSize sizeHint() const { return QSize( 0, 200 ); } public slots: - void onShown( QWidget* ); - void onHidden( QWidget* ); - -signals: - void showWidget(); - void hideWidget(); + virtual void onShown( QWidget* ); + virtual void onHidden( QWidget* ); private: PlaylistView* m_queue; diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 0a1c4e53d..454df55f0 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -65,8 +65,11 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) ui->splitter->setStretchFactor( 0, 1 ); ui->splitter->setStretchFactor( 1, 3 ); - ui->splitter_2->setStretchFactor( 0, 3 ); - ui->splitter_2->setStretchFactor( 1, 1 ); + ui->sidebarSplitter->setChildrenCollapsible( false ); + ui->sidebarSplitter->setGreedyWidget( 0 ); + ui->sidebarSplitter->setStretchFactor( 0, 3 ); + ui->sidebarSplitter->setStretchFactor( 1, 1 ); + ui->sidebarSplitter->hide( 1, false ); QToolBar* toolbar = addToolBar( "TomahawkToolbar" ); toolbar->setObjectName( "TomahawkToolbar" ); diff --git a/src/tomahawkwindow.ui b/src/tomahawkwindow.ui index 2f8f44e4e..c4b877598 100644 --- a/src/tomahawkwindow.ui +++ b/src/tomahawkwindow.ui @@ -20,7 +20,7 @@ Qt::Horizontal - + Qt::Vertical diff --git a/src/transferview.cpp b/src/transferview.cpp index f19324ccd..aa415260a 100644 --- a/src/transferview.cpp +++ b/src/transferview.cpp @@ -1,29 +1,40 @@ #include "transferview.h" #include +#include #include "tomahawk/tomahawkapp.h" #include "network/filetransferconnection.h" #include "network/servent.h" -TransferView::TransferView( QWidget* parent ) - : QTreeWidget( parent ) +TransferView::TransferView( AnimatedSplitter* parent ) + : AnimatedWidget( parent ) + , m_parent( parent ) { + setHiddenSize( QSize( 0, 0 ) ); + + setLayout( new QVBoxLayout() ); + m_tree = new QTreeWidget( this ); + + layout()->setMargin( 0 ); + layout()->addWidget( m_tree ); + connect( &APP->servent(), SIGNAL( fileTransferStarted( FileTransferConnection* ) ), SLOT( fileTransferRegistered( FileTransferConnection* ) ) ); connect( &APP->servent(), SIGNAL( fileTransferFinished( FileTransferConnection* ) ), SLOT( fileTransferFinished( FileTransferConnection* ) ) ); QStringList headers; headers << tr( "Peer" ) << tr( "Rate" ) << tr( "Track" ); - setHeaderLabels( headers ); + m_tree->setHeaderLabels( headers ); - setColumnCount( 3 ); - setColumnWidth( 0, 80 ); - setColumnWidth( 1, 65 ); - setColumnWidth( 2, 10 ); + m_tree->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored ); + m_tree->setColumnCount( 3 ); + m_tree->setColumnWidth( 0, 80 ); + m_tree->setColumnWidth( 1, 65 ); + m_tree->setColumnWidth( 2, 10 ); - header()->setStretchLastSection( true ); - setRootIsDecorated( false ); + m_tree->header()->setStretchLastSection( true ); + m_tree->setRootIsDecorated( false ); } @@ -40,14 +51,19 @@ TransferView::fileTransferFinished( FileTransferConnection* ftc ) if ( !m_index.contains( ftc ) ) return; -/* int i = m_index.take( ftc ); - delete invisibleRootItem()->takeChild( i ); */ + int i = m_index.take( ftc ); + delete m_tree->invisibleRootItem()->takeChild( i ); - if ( m_index.contains( ftc ) ) + if ( m_tree->invisibleRootItem()->childCount() > 0 ) + emit showWidget(); + else + emit hideWidget(); + +/* if ( m_index.contains( ftc ) ) { int i = m_index.value( ftc ); - invisibleRootItem()->child( i )->setText( 1, tr( "Finished" ) ); - } + m_tree->invisibleRootItem()->child( i )->setText( 1, tr( "Finished" ) ); + }*/ } @@ -63,15 +79,34 @@ TransferView::onTransferUpdate() if ( m_index.contains( ftc ) ) { int i = m_index.value( ftc ); - ti = invisibleRootItem()->child( i ); + ti = m_tree->invisibleRootItem()->child( i ); } else { - ti = new QTreeWidgetItem( this ); - m_index.insert( ftc, invisibleRootItem()->childCount() - 1 ); + ti = new QTreeWidgetItem( m_tree ); + m_index.insert( ftc, m_tree->invisibleRootItem()->childCount() - 1 ); } ti->setText( 0, ftc->source()->friendlyName() ); ti->setText( 1, QString( "%1 kb/s" ).arg( ftc->transferRate() / 1024 ) ); ti->setText( 2, QString( "%1 - %2" ).arg( ftc->track()->artist()->name() ).arg( ftc->track()->track() ) ); + + emit showWidget(); +} + + +QSize +TransferView::sizeHint() const +{ + unsigned int y = 0; + y += m_tree->header()->height(); + y += m_tree->contentsMargins().top() + m_tree->contentsMargins().bottom(); + + if ( m_tree->invisibleRootItem()->childCount() ) + { + unsigned int rowheight = m_tree->sizeHintForRow( 0 ); + y += rowheight * m_tree->invisibleRootItem()->childCount() + 2; + } + + return QSize( 0, y ); } diff --git a/src/transferview.h b/src/transferview.h index 9265a175c..76856cb5a 100644 --- a/src/transferview.h +++ b/src/transferview.h @@ -5,20 +5,23 @@ #include #include "tomahawk/typedefs.h" +#include "utils/animatedsplitter.h" class FileTransferConnection; -class TransferView : public QTreeWidget +class TransferView : public AnimatedWidget { Q_OBJECT public: - explicit TransferView( QWidget* parent = 0 ); + explicit TransferView( AnimatedSplitter* parent = 0 ); virtual ~TransferView() { qDebug() << Q_FUNC_INFO; } + QSize sizeHint() const; + signals: public slots: @@ -31,6 +34,8 @@ private slots: private: QHash< FileTransferConnection*, int > m_index; + QTreeWidget* m_tree; + AnimatedSplitter* m_parent; }; #endif // TRANSFERVIEW_H diff --git a/src/utils/animatedsplitter.cpp b/src/utils/animatedsplitter.cpp index b24029028..e7c367ade 100644 --- a/src/utils/animatedsplitter.cpp +++ b/src/utils/animatedsplitter.cpp @@ -1,51 +1,46 @@ #include "animatedsplitter.h" #include -#include #define ANIMATION_TIME 500 -#ifdef Q_WS_MAC -#define MINIMUM_HEIGHT 38 -#else -#define MINIMUM_HEIGHT 27 -#endif - AnimatedSplitter::AnimatedSplitter( QWidget* parent ) : QSplitter( parent ) , m_animateIndex( -1 ) - , m_greedyIndex( -1 ) - , m_greedyHeight( -1 ) + , m_greedyIndex( 0 ) { + m_timeLine = new QTimeLine( ANIMATION_TIME, this ); + m_timeLine->setUpdateInterval( 5 ); + m_timeLine->setEasingCurve( QEasingCurve::OutBack ); + + connect( m_timeLine, SIGNAL( frameChanged( int ) ), SLOT( onAnimationStep( int ) ) ); + connect( m_timeLine, SIGNAL( finished() ), SLOT( onAnimationFinished() ) ); } void AnimatedSplitter::show( int index, bool animate ) { - if ( m_greedyIndex < 0 || m_animateIndex != -1 ) - return; - m_animateIndex = index; QWidget* w = widget( index ); QSize size = w->sizeHint(); w->setMaximumHeight( QWIDGETSIZE_MAX ); + if ( w->height() == size.height() ) + return; + qDebug() << "animating to:" << size.height() << "from" << w->height(); + m_animateForward = true; if ( animate ) { - m_greedyHeight = widget( m_greedyIndex )->height(); + if ( m_timeLine->state() == QTimeLine::Running ) + m_timeLine->stop(); - QTimeLine *timeLine = new QTimeLine( ANIMATION_TIME, this ); - timeLine->setFrameRange( w->height(), size.height() ); - timeLine->setUpdateInterval( 5 ); - timeLine->setEasingCurve( QEasingCurve::OutBack ); - - connect( timeLine, SIGNAL( frameChanged( int ) ), SLOT( onAnimationStep( int ) ) ); - connect( timeLine, SIGNAL( finished() ), SLOT( onAnimationFinished() ) ); - timeLine->start(); + m_timeLine->setFrameRange( w->height(), size.height() ); + m_timeLine->setDirection( QTimeLine::Forward ); + m_timeLine->start(); } else { @@ -60,32 +55,29 @@ AnimatedSplitter::show( int index, bool animate ) void AnimatedSplitter::hide( int index, bool animate ) { - if ( m_greedyIndex < 0 || m_animateIndex != -1 ) - return; - m_animateIndex = index; QWidget* w = widget( index ); - w->setMinimumHeight( MINIMUM_HEIGHT ); - m_greedyHeight = widget( m_greedyIndex )->height(); + int minHeight = m_sizes.at( index ).height(); + w->setMinimumHeight( minHeight ); + + if ( w->height() == minHeight ) + return; + qDebug() << "animating to:" << w->height() << "from" << minHeight; m_animateForward = false; if ( animate ) { + if ( m_timeLine->state() == QTimeLine::Running ) + m_timeLine->stop(); - QTimeLine *timeLine = new QTimeLine( ANIMATION_TIME, this ); - timeLine->setFrameRange( MINIMUM_HEIGHT, w->height() ); - timeLine->setUpdateInterval( 5 ); - timeLine->setDirection( QTimeLine::Backward ); - timeLine->setEasingCurve( QEasingCurve::OutBack ); - - connect( timeLine, SIGNAL( frameChanged( int ) ), SLOT( onAnimationStep( int ) ) ); - connect( timeLine, SIGNAL( finished() ), SLOT( onAnimationFinished() ) ); - timeLine->start(); + m_timeLine->setFrameRange( minHeight, w->height() ); + m_timeLine->setDirection( QTimeLine::Backward ); + m_timeLine->start(); } else { - onAnimationStep( MINIMUM_HEIGHT ); + onAnimationStep( minHeight ); onAnimationFinished(); } @@ -97,9 +89,19 @@ void AnimatedSplitter::addWidget( QWidget* widget ) { QSplitter::addWidget( widget ); + m_sizes << widget->minimumSize(); +} + + +void +AnimatedSplitter::addWidget( AnimatedWidget* widget ) +{ + QSplitter::addWidget( widget ); + m_sizes << widget->hiddenSize(); connect( widget, SIGNAL( showWidget() ), SLOT( onShowRequest() ) ); connect( widget, SIGNAL( hideWidget() ), SLOT( onHideRequest() ) ); + connect( widget, SIGNAL( hiddenSizeChanged() ), SLOT( onHiddenSizeChanged() ) ); connect( this, SIGNAL( shown( QWidget* ) ), widget, SLOT( onShown( QWidget* ) ) ); connect( this, SIGNAL( hidden( QWidget* ) ), widget, SLOT( onHidden( QWidget* ) ) ); } @@ -122,6 +124,8 @@ AnimatedSplitter::onShowRequest() if ( j > 0 ) show( j ); + else + qDebug() << "Could not find widget:" << sender(); } @@ -142,6 +146,8 @@ AnimatedSplitter::onHideRequest() if ( j > 0 ) hide( j ); + else + qDebug() << "Could not find widget:" << sender(); } @@ -182,15 +188,28 @@ AnimatedSplitter::onAnimationFinished() QWidget* w = widget( m_animateIndex ); if ( m_animateForward ) { - w->setMinimumHeight( 100 ); + w->setMinimumHeight( w->minimumHeight() ); } else { - w->setMaximumHeight( MINIMUM_HEIGHT ); + w->setMaximumHeight( m_sizes.at( m_animateIndex ).height() ); } m_animateIndex = -1; - - if ( sender() ) - sender()->deleteLater(); +} + + +void +AnimatedSplitter::onHiddenSizeChanged() +{ + AnimatedWidget* w = (AnimatedWidget*)(sender()); + int i = indexOf( w ); + m_sizes.replace( i, w->hiddenSize() ); +} + + +AnimatedWidget::AnimatedWidget( AnimatedSplitter* parent ) + : m_parent( parent ) +{ + m_parent->addWidget( this ); } diff --git a/src/utils/animatedsplitter.h b/src/utils/animatedsplitter.h index 8809162a5..5c3b5ca77 100644 --- a/src/utils/animatedsplitter.h +++ b/src/utils/animatedsplitter.h @@ -2,6 +2,9 @@ #define ANIMATEDSPLITTER_H #include +#include + +class AnimatedWidget; class AnimatedSplitter : public QSplitter { @@ -16,6 +19,7 @@ public: void setGreedyWidget( int index ) { m_greedyIndex = index; } void addWidget( QWidget* widget ); + void addWidget( AnimatedWidget* widget ); signals: void shown( QWidget* ); @@ -28,12 +32,39 @@ private slots: void onAnimationStep( int frame ); void onAnimationFinished(); + void onHiddenSizeChanged(); + private: int m_animateIndex; bool m_animateForward; int m_greedyIndex; - int m_greedyHeight; + QList m_sizes; + QTimeLine* m_timeLine; +}; + +class AnimatedWidget : public QWidget +{ +Q_OBJECT +public: + explicit AnimatedWidget( AnimatedSplitter* parent ); + + QSize hiddenSize() const { return m_hiddenSize; } + void setHiddenSize( const QSize& size ) { m_hiddenSize = size; emit hiddenSizeChanged(); } + +public slots: + virtual void onShown( QWidget* ) {} + virtual void onHidden( QWidget* ) {} + +signals: + void showWidget(); + void hideWidget(); + + void hiddenSizeChanged(); + +private: + AnimatedSplitter* m_parent; + QSize m_hiddenSize; }; #endif //ANIMATEDSPLITTER_H