PageRenderTime 183ms CodeModel.GetById 101ms app.highlight 8ms RepoModel.GetById 72ms app.codeStats 0ms

/src/sourcetree/items/genericpageitems.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 115 lines | 72 code | 25 blank | 18 comment | 8 complexity | 3bad1a8ed22c9c1810c11213bf56838b MD5 | raw file
  1/*
  2 *    Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  3 *
  4 *    This program is free software; you can redistribute it and/or modify
  5 *    it under the terms of the GNU General Public License as published by
  6 *    the Free Software Foundation; either version 2 of the License, or
  7 *    (at your option) any later version.
  8 *
  9 *    This program is distributed in the hope that it will be useful,
 10 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 *    GNU General Public License for more details.
 13 *
 14 *    You should have received a copy of the GNU General Public License along
 15 *    with this program; if not, write to the Free Software Foundation, Inc.,
 16 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 17 */
 18
 19#include "GenericPageItems.h"
 20
 21#include "utils/TomahawkUtils.h"
 22#include "utils/Logger.h"
 23#include "ViewManager.h"
 24#include "audio/AudioEngine.h"
 25
 26using namespace Tomahawk;
 27
 28
 29/// Generic page item
 30GenericPageItem::GenericPageItem( SourcesModel* model, SourceTreeItem* parent, const QString& text, const QIcon& icon, boost::function< ViewPage* () > show, boost::function< ViewPage* () > get )
 31    : SourceTreeItem( model, parent, SourcesModel::GenericPage )
 32    , m_icon( icon )
 33    , m_text( text )
 34    , m_sortValue( 0 )
 35    , m_show( show )
 36    , m_get( get )
 37{
 38    if( ViewPage* p = m_get() )
 39        model->linkSourceItemToPage( this, p );
 40}
 41
 42
 43GenericPageItem::~GenericPageItem()
 44{
 45}
 46
 47
 48void
 49GenericPageItem::activate()
 50{
 51    ViewPage* p = m_show();
 52    model()->linkSourceItemToPage( this, p );
 53}
 54
 55
 56QString
 57GenericPageItem::text() const
 58{
 59    return m_text;
 60}
 61
 62
 63QIcon
 64GenericPageItem::icon() const
 65{
 66    return m_icon;
 67}
 68
 69
 70bool
 71GenericPageItem::willAcceptDrag(const QMimeData* data) const
 72{
 73    Q_UNUSED( data );
 74    return false;
 75}
 76
 77
 78void
 79GenericPageItem::setText( const QString &text )
 80{
 81    m_text = text;
 82    emit updated();
 83}
 84
 85bool
 86GenericPageItem::isBeingPlayed() const
 87{
 88    if ( m_get() )
 89    {
 90        if ( m_get()->isBeingPlayed() )
 91            return true;
 92
 93        if ( !m_get()->playlistInterface().isNull() && m_get()->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
 94            return true;
 95
 96        if ( !m_get()->playlistInterface().isNull() && m_get()->playlistInterface()->hasChildInterface( AudioEngine::instance()->currentTrackPlaylist() ) )
 97            return true;
 98    }
 99
100    return false;
101}
102
103
104int
105GenericPageItem::peerSortValue() const
106{
107    return m_sortValue;
108}
109
110
111void
112GenericPageItem::setSortValue(int value)
113{
114    m_sortValue = value;
115}