Ejemplo n.º 1
0
TagBrowserWidget::TagBrowserWidget(PlaydarConnection* playdar, QWidget* parent) :
	QWidget(parent), 
    m_playdar(playdar) 
{
	m_tagCloudModel = new PlaydarTagCloudModel(playdar);
    m_filter = new RelevanceFilter();
    m_filter->setSourceModel(m_tagCloudModel);

	QVBoxLayout* vlayout = new QVBoxLayout(this);
	m_history = new HistoryWidget();
	m_history->newItem("all");
	connect(m_history, SIGNAL(clicked(int, QString)),
			SLOT(onHistoryClicked(int, QString)));
    QPushButton* button = new QPushButton("filter irrelevant tags");
    connect(button, SIGNAL(clicked()), SLOT(onFilterClicked()));
    vlayout->addWidget(button);
	vlayout->addWidget(m_history);

	QWidget* w = new QWidget(this);

	m_view = new TagCloudView(w);
	m_view->setModel(m_filter);

    connect(m_tagCloudModel, SIGNAL(tagItem(BoffinTagItem)), m_view, SLOT(onTag(BoffinTagItem)));
    connect(m_tagCloudModel, SIGNAL(fetchedTags()), m_view, SLOT(onFetchedTags()));

	m_view->setItemDelegate(new TagDelegate);
	connect(m_view->selectionModel(),
			SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
			SLOT(onSelectionChanged(QItemSelection, QItemSelection)));
	vlayout->addWidget(m_view);

// not interested in the playlist widget right now:
//	m_playlistModel = new PlaylistModel(this);
//	m_playlistWidget = new PlaylistWidget(m_playdar, this);
//	m_playlistWidget->setModel(m_playlistModel);
//	vlayout->addWidget(m_playlistWidget);

	m_tagCloudModel->startGetTags();

	this->setLayout(vlayout);
}
void
PlaydarTagCloudModel::onTag(BoffinTagItem tag)
{
	if( m_loadingTimer )
		m_loadingTimer->stop();

    // check if the host is being filtered.
    if (!m_hostFilter.contains(tag.m_host)) {
        m_hosts.insert(tag.m_host);

		if( int i = m_tagListBuffer.indexOf( tag ) >= 0 )
		{
    		// merge into existing tag
			m_tagListBuffer[ i ].m_weight += tag.m_weight;
            m_tagListBuffer[ i ].m_count += tag.m_count;
			m_tagListBuffer[ i ].m_logCount = log( (float) m_tagListBuffer[i].m_count );
			m_maxWeight = qMax( m_tagListBuffer[i].m_weight, m_maxWeight);
			m_maxLogCount = qMax( m_tagListBuffer[i].m_logCount, m_maxLogCount);
        }
        else
        {
            // new tag
		    tag.m_logCount = log( (float) tag.m_count );
		    m_tagListBuffer << tag;
		    m_maxTrackCount = qMax( tag.m_count, m_maxTrackCount );
		    m_maxWeight = qMax( tag.m_weight, m_maxWeight );
		    m_maxLogCount = qMax( m_maxLogCount, tag.m_logCount );
		    m_minLogCount = qMin( m_minLogCount, tag.m_logCount );
        }
	}

    // fire onFetchedTags after 1 second of idle-ness
	if( !m_loadingTimer )
	{
		m_loadingTimer = new QTimer();
		m_loadingTimer->setSingleShot( true );
		connect( m_loadingTimer, SIGNAL( timeout()), SLOT(onFetchedTags()));
	}
    m_loadingTimer->start( 1000 );

}