diff --git a/resources.qrc b/resources.qrc index c9cc76bcf..f22787eab 100644 --- a/resources.qrc +++ b/resources.qrc @@ -149,5 +149,6 @@ data/images/ok.svg data/images/tweet.svg data/images/widget-border.png + data/images/refresh.svg diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index bfe932f53..327217f66 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -119,6 +119,7 @@ set( libGuiSources widgets/AnimatedCounterLabel.cpp widgets/BasicHeader.cpp widgets/FilterHeader.cpp + widgets/ScriptCollectionHeader.cpp widgets/Breadcrumb.cpp widgets/BreadcrumbButton.cpp widgets/CheckDirTree.cpp diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index 59b421c37..aea9701f6 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -267,6 +267,16 @@ TreeModel::addCollection( const collection_ptr& collection ) } +void +TreeModel::reloadCollection() +{ + if ( m_collection.isNull() ) + return; + + onCollectionChanged(); +} + + //void //TreeModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order ) //{ diff --git a/src/libtomahawk/playlist/TreeModel.h b/src/libtomahawk/playlist/TreeModel.h index 591e908dc..73634887b 100644 --- a/src/libtomahawk/playlist/TreeModel.h +++ b/src/libtomahawk/playlist/TreeModel.h @@ -71,6 +71,7 @@ public: public slots: void addAlbums( const QModelIndex& parent, const QList& albums ); + void reloadCollection(); signals: void modeChanged( Tomahawk::ModelMode mode ); diff --git a/src/libtomahawk/playlist/TreeWidget.cpp b/src/libtomahawk/playlist/TreeWidget.cpp index 6ed21b2fd..593a3375b 100644 --- a/src/libtomahawk/playlist/TreeWidget.cpp +++ b/src/libtomahawk/playlist/TreeWidget.cpp @@ -18,6 +18,7 @@ #include "TreeWidget.h" +#include "collection/Collection.h" #include "utils/TomahawkUtilsGui.h" #include @@ -25,7 +26,7 @@ TreeWidget::TreeWidget( QWidget* parent ) : QWidget( parent ) , m_view( new TreeView( this ) ) - , m_header( new FilterHeader( this ) ) + , m_header( new ScriptCollectionHeader( this ) ) { QVBoxLayout* mainLayout = new QVBoxLayout; mainLayout->addWidget( m_header ); @@ -37,6 +38,8 @@ TreeWidget::TreeWidget( QWidget* parent ) this, SLOT( setFilter( QString ) ) ); connect( m_view, SIGNAL( modelChanged() ), this, SLOT( onModelChanged() ) ); + connect( m_header, SIGNAL( refreshClicked() ), + this, SLOT( onRefreshClicked() ) ); } @@ -108,6 +111,16 @@ TreeWidget::onModelChanged() m_header->setCaption( m_view->model()->title() ); m_header->setDescription( m_view->model()->description() ); m_header->setPixmap( m_view->model()->icon() ); + if ( !m_view->model()->collection().isNull() ) + m_header->setRefreshVisible( m_view->model()->collection()->backendType() != Tomahawk::Collection::DatabaseCollectionType ); +} + + +void +TreeWidget::onRefreshClicked() +{ + if ( m_view->model() && !m_view->model()->collection().isNull() ) + m_view->model()->reloadCollection(); } diff --git a/src/libtomahawk/playlist/TreeWidget.h b/src/libtomahawk/playlist/TreeWidget.h index 229282a0e..d24f0462e 100644 --- a/src/libtomahawk/playlist/TreeWidget.h +++ b/src/libtomahawk/playlist/TreeWidget.h @@ -21,7 +21,7 @@ #include "TreeView.h" #include "ViewPage.h" -#include "widgets/FilterHeader.h" +#include "widgets/ScriptCollectionHeader.h" #include @@ -51,10 +51,11 @@ public slots: private slots: void onModelChanged(); + void onRefreshClicked(); private: TreeView* m_view; - BasicHeader* m_header; + ScriptCollectionHeader* m_header; }; #endif // TREEWIDGET_H diff --git a/src/libtomahawk/widgets/FilterHeader.h b/src/libtomahawk/widgets/FilterHeader.h index 7ede2746b..603643424 100644 --- a/src/libtomahawk/widgets/FilterHeader.h +++ b/src/libtomahawk/widgets/FilterHeader.h @@ -44,11 +44,12 @@ private slots: void onFilterEdited(); void applyFilter(); +protected: + QSearchField* m_filterField; + private: QString m_filter; QTimer m_filterTimer; - - QSearchField* m_filterField; }; #endif // FILTERHEADER_H diff --git a/src/libtomahawk/widgets/ScriptCollectionHeader.cpp b/src/libtomahawk/widgets/ScriptCollectionHeader.cpp new file mode 100644 index 000000000..1012d71be --- /dev/null +++ b/src/libtomahawk/widgets/ScriptCollectionHeader.cpp @@ -0,0 +1,56 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "ScriptCollectionHeader.h" + +#include "utils/ImageRegistry.h" +#include "widgets/ElidedLabel.h" + +#include +#include + +ScriptCollectionHeader::ScriptCollectionHeader( QWidget* parent ) + : FilterHeader( parent ) +{ + m_refreshButton = new QPushButton( this ); + m_refreshButton->setFlat( true ); + QHBoxLayout* descLayout = new QHBoxLayout; + m_verticalLayout->insertLayout( m_verticalLayout->indexOf( m_descriptionLabel ), + descLayout ); + descLayout->addWidget( m_descriptionLabel ); + TomahawkUtils::unmarginLayout( descLayout ); + descLayout->addSpacing( m_descriptionLabel->fontMetrics().height() / 2 ); + descLayout->addWidget( m_refreshButton ); + descLayout->addStretch(); + + m_refreshButton->setIcon( ImageRegistry::instance()->pixmap( RESPATH "images/refresh.svg", QSize( m_descriptionLabel->fontMetrics().height(), + m_descriptionLabel->fontMetrics().height() ), TomahawkUtils::DropShadow ) ); + m_refreshButton->setFixedSize( m_descriptionLabel->fontMetrics().height() + m_descriptionLabel->margin() * 2, + m_descriptionLabel->fontMetrics().height() + m_descriptionLabel->margin() * 2 ); + + connect( m_refreshButton, SIGNAL( clicked() ), + this, SIGNAL( refreshClicked() ) ); + m_refreshButton->hide(); +} + + +void +ScriptCollectionHeader::setRefreshVisible( bool visible ) +{ + m_refreshButton->setVisible( visible ); +} diff --git a/src/libtomahawk/widgets/ScriptCollectionHeader.h b/src/libtomahawk/widgets/ScriptCollectionHeader.h new file mode 100644 index 000000000..e0fec4e39 --- /dev/null +++ b/src/libtomahawk/widgets/ScriptCollectionHeader.h @@ -0,0 +1,41 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef SCRIPTCOLLECTIONHEADER_H +#define SCRIPTCOLLECTIONHEADER_H + +#include "widgets/FilterHeader.h" + +class QPushButton; + +class DLLEXPORT ScriptCollectionHeader : public FilterHeader +{ + Q_OBJECT +public: + explicit ScriptCollectionHeader( QWidget* parent = 0 ); + + void setRefreshVisible( bool visible ); + +signals: + void refreshClicked(); + +protected: + QPushButton* m_refreshButton; +}; + +#endif // SCRIPTCOLLECTIONHEADER_H