From 859e2e4a7b74451ab8f8997d863c9622c3dc4df2 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 26 Apr 2013 06:38:48 +0200 Subject: [PATCH] * Save & restore queue across sessions. --- src/libtomahawk/playlist/QueueView.cpp | 43 +++++++++++++++++++++++++- src/libtomahawk/playlist/QueueView.h | 5 ++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/playlist/QueueView.cpp b/src/libtomahawk/playlist/QueueView.cpp index 45b1c13ba..004dfe9ef 100644 --- a/src/libtomahawk/playlist/QueueView.cpp +++ b/src/libtomahawk/playlist/QueueView.cpp @@ -26,6 +26,7 @@ #include "utils/Logger.h" #include "PlaylistView.h" #include "Source.h" +#include "TomahawkSettings.h" #include "utils/TomahawkUtilsGui.h" #include "widgets/OverlayWidget.h" @@ -62,12 +63,18 @@ QueueView::QueueView( AnimatedSplitter* parent ) ui->toggleButton->installEventFilter( this ); ui->toggleButton->setCursor( Qt::PointingHandCursor ); + + // Set initial state + onHidden( this, false ); + + restoreState(); } QueueView::~QueueView() { - qDebug() << Q_FUNC_INFO; + tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + saveState(); } @@ -193,3 +200,37 @@ QueueView::updateLabel() ui->toggleButton->setText( tr( "Close Queue" ) ); } } + + +void +QueueView::restoreState() +{ + QVariantList vl = TomahawkSettings::instance()->queueState().toList(); + QList< query_ptr > ql; + + foreach ( const QVariant& v, vl ) + { + QVariantMap map = v.toMap(); + query_ptr q = Query::get( map["artist"].toString(), map["track"].toString(), map["album"].toString() ); + ql << q; + } + + if ( !ql.isEmpty() ) + { + queue()->model()->appendQueries( ql ); + updateLabel(); + } +} + + +void +QueueView::saveState() +{ + QVariantList vl; + foreach ( const query_ptr& query, queue()->model()->queries() ) + { + vl << query->toVariant(); + } + + TomahawkSettings::instance()->setQueueState( vl ); +} diff --git a/src/libtomahawk/playlist/QueueView.h b/src/libtomahawk/playlist/QueueView.h index 10f8ec8e0..4988c81b4 100644 --- a/src/libtomahawk/playlist/QueueView.h +++ b/src/libtomahawk/playlist/QueueView.h @@ -56,12 +56,15 @@ public slots: protected: void changeEvent( QEvent* e ); - + private slots: void updateLabel(); void onAnimationFinished(); private: + void saveState(); + void restoreState(); + Ui::QueueView* ui; QTimer* m_dragTimer; };