Skip to content

Commit

Permalink
Added ScriptCollection refresh support. Also new header.
Browse files Browse the repository at this point in the history
  • Loading branch information
teo committed Feb 18, 2013
1 parent 76044bd commit d7d15ed
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 5 deletions.
1 change: 1 addition & 0 deletions resources.qrc
Expand Up @@ -149,5 +149,6 @@
<file>data/images/ok.svg</file>
<file>data/images/tweet.svg</file>
<file>data/images/widget-border.png</file>
<file>data/images/refresh.svg</file>
</qresource>
</RCC>
1 change: 1 addition & 0 deletions src/libtomahawk/CMakeLists.txt
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/libtomahawk/playlist/TreeModel.cpp
Expand Up @@ -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 )
//{
Expand Down
1 change: 1 addition & 0 deletions src/libtomahawk/playlist/TreeModel.h
Expand Up @@ -71,6 +71,7 @@ Q_OBJECT

public slots:
void addAlbums( const QModelIndex& parent, const QList<Tomahawk::album_ptr>& albums );
void reloadCollection();

signals:
void modeChanged( Tomahawk::ModelMode mode );
Expand Down
15 changes: 14 additions & 1 deletion src/libtomahawk/playlist/TreeWidget.cpp
Expand Up @@ -18,14 +18,15 @@

#include "TreeWidget.h"

#include "collection/Collection.h"
#include "utils/TomahawkUtilsGui.h"

#include <QBoxLayout>

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 );
Expand All @@ -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() ) );
}


Expand Down Expand Up @@ -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();
}


Expand Down
5 changes: 3 additions & 2 deletions src/libtomahawk/playlist/TreeWidget.h
Expand Up @@ -21,7 +21,7 @@

#include "TreeView.h"
#include "ViewPage.h"
#include "widgets/FilterHeader.h"
#include "widgets/ScriptCollectionHeader.h"

#include <QWidget>

Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/libtomahawk/widgets/FilterHeader.h
Expand Up @@ -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
56 changes: 56 additions & 0 deletions src/libtomahawk/widgets/ScriptCollectionHeader.cpp
@@ -0,0 +1,56 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "ScriptCollectionHeader.h"

#include "utils/ImageRegistry.h"
#include "widgets/ElidedLabel.h"

#include <QBoxLayout>
#include <QPushButton>

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 );
}
41 changes: 41 additions & 0 deletions src/libtomahawk/widgets/ScriptCollectionHeader.h
@@ -0,0 +1,41 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#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

0 comments on commit d7d15ed

Please sign in to comment.