Permalink
Browse files

Added ScriptCollection refresh support. Also new header.

  • Loading branch information...
1 parent 76044bd commit d7d15eda469043c47231f2e0fe1365eeb8ec1bed @teo teo committed Feb 18, 2013
View
@@ -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>
@@ -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
@@ -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 )
//{
@@ -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 );
@@ -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 );
@@ -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();
}
@@ -21,7 +21,7 @@
#include "TreeView.h"
#include "ViewPage.h"
-#include "widgets/FilterHeader.h"
+#include "widgets/ScriptCollectionHeader.h"
#include <QWidget>
@@ -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
@@ -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
@@ -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 );
+}
@@ -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.