From 83ca3a1502c70525b32e484882041d727711e51b Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 4 Jun 2011 20:50:49 +0200 Subject: [PATCH] * Forgot to add some search widgets. --- src/libtomahawk/widgets/searchwidget.cpp | 104 +++++++++++++++++++++++ src/libtomahawk/widgets/searchwidget.h | 77 +++++++++++++++++ src/libtomahawk/widgets/searchwidget.ui | 38 +++++++++ src/searchwidget.ui | 57 +++++++++++++ 4 files changed, 276 insertions(+) create mode 100644 src/libtomahawk/widgets/searchwidget.cpp create mode 100644 src/libtomahawk/widgets/searchwidget.h create mode 100644 src/libtomahawk/widgets/searchwidget.ui create mode 100644 src/searchwidget.ui diff --git a/src/libtomahawk/widgets/searchwidget.cpp b/src/libtomahawk/widgets/searchwidget.cpp new file mode 100644 index 000000000..34350f4df --- /dev/null +++ b/src/libtomahawk/widgets/searchwidget.cpp @@ -0,0 +1,104 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 "searchwidget.h" +#include "ui_searchwidget.h" + +#include +#include + +#include "utils/tomahawkutils.h" + +#include "viewmanager.h" +#include "playlist/playlistmodel.h" + +#include "widgets/overlaywidget.h" + +#include "sourcelist.h" + + +SearchWidget::SearchWidget( const QString& search, QWidget* parent ) + : QWidget( parent ) + , ui( new Ui::SearchWidget ) + , m_search( search ) +{ + ui->setupUi( this ); + + m_resultsModel = new PlaylistModel( ui->resultsView ); + ui->resultsView->setPlaylistModel( m_resultsModel ); + ui->resultsView->overlay()->setEnabled( false ); + + m_queries << Tomahawk::Query::get( search, uuid() ); + + foreach ( const Tomahawk::query_ptr& query, m_queries ) + { + connect( query.data(), SIGNAL( resultsAdded( QList ) ), SLOT( onResultsFound( QList ) ) ); + } + + connect( ui->buttonBox, SIGNAL( rejected() ), SLOT( cancel() ) ); +} + + +SearchWidget::~SearchWidget() +{ + delete ui; +} + + +void +SearchWidget::changeEvent( QEvent* e ) +{ + QWidget::changeEvent( e ); + switch ( e->type() ) + { + case QEvent::LanguageChange: + ui->retranslateUi( this ); + break; + + default: + break; + } +} + + +void +SearchWidget::onResultsFound( const QList& results ) +{ + foreach( const Tomahawk::result_ptr& result, results ) + { + if ( !result->collection().isNull() && !result->isOnline() ) + continue; + + QList< Tomahawk::result_ptr > rl; + rl << result; + + Tomahawk::query_ptr q = result->toQuery(); + q->addResults( rl ); + qDebug() << result->toString(); + + m_resultsModel->append( q ); + } +} + + +void +SearchWidget::cancel() +{ + emit destroyed( this ); + deleteLater(); +} diff --git a/src/libtomahawk/widgets/searchwidget.h b/src/libtomahawk/widgets/searchwidget.h new file mode 100644 index 000000000..2fbea9808 --- /dev/null +++ b/src/libtomahawk/widgets/searchwidget.h @@ -0,0 +1,77 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 SEARCHWIDGET_H +#define SEARCHWIDGET_H + +#include +#include + +#include "result.h" +#include "playlistinterface.h" +#include "viewpage.h" + +#include "dllmacro.h" + +class QPushButton; +class PlaylistModel; + +namespace Ui +{ + class SearchWidget; +} + +class DLLEXPORT SearchWidget : public QWidget, public Tomahawk::ViewPage +{ +Q_OBJECT + +public: + SearchWidget( const QString& search, QWidget* parent = 0 ); + ~SearchWidget(); + + virtual QWidget* widget() { return this; } + virtual PlaylistInterface* playlistInterface() const { return 0; } + + virtual QString title() const { return tr( "Search" ); } + virtual QString description() const { return tr( "Results for '%1'" ).arg( m_search ); } + + virtual bool showStatsBar() const { return false; } + + virtual bool jumpToCurrentTrack() { return false; } + +protected: + void changeEvent( QEvent* e ); + +signals: + void destroyed( QWidget* widget ); + +private slots: + void onResultsFound( const QList& results ); + + void cancel(); + +private: + Ui::SearchWidget *ui; + + QString m_search; + + PlaylistModel* m_resultsModel; + QList< Tomahawk::query_ptr > m_queries; +}; + +#endif // NEWPLAYLISTWIDGET_H diff --git a/src/libtomahawk/widgets/searchwidget.ui b/src/libtomahawk/widgets/searchwidget.ui new file mode 100644 index 000000000..7bace8edb --- /dev/null +++ b/src/libtomahawk/widgets/searchwidget.ui @@ -0,0 +1,38 @@ + + + SearchWidget + + + + 0 + 0 + 985 + 460 + + + + Qt::TabFocus + + + + + + + + + QDialogButtonBox::Cancel + + + + + + + + PlaylistView + QTreeView +
playlist/playlistview.h
+
+
+ + +
diff --git a/src/searchwidget.ui b/src/searchwidget.ui new file mode 100644 index 000000000..52f729a4b --- /dev/null +++ b/src/searchwidget.ui @@ -0,0 +1,57 @@ + + + SearchWidget + + + + 0 + 0 + 345 + 31 + + + + Form + + + + + + Qt::Horizontal + + + + 141 + 20 + + + + + + + + + 60 + 27 + + + + + 180 + 16777215 + + + + + + + + + SearchLineEdit + QLineEdit +
libtomahawk/playlist/topbar/searchlineedit.h
+
+
+ + +