Skip to content

Commit

Permalink
playdar boffin work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dougma committed Apr 29, 2009
1 parent b21d9fe commit 245d3e0
Show file tree
Hide file tree
Showing 19 changed files with 1,008 additions and 191 deletions.
146 changes: 48 additions & 98 deletions app/boffin/App.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,34 +23,38 @@
#include "PickDirsDialog.h" #include "PickDirsDialog.h"
#include "ScanProgressWidget.h" #include "ScanProgressWidget.h"
#include "ScrobSocket.h" #include "ScrobSocket.h"
#include "app/clientplugins/localresolver/LocalContentScannerThread.h" #include "TrackSource.h"
#include "app/clientplugins/localresolver/LocalContentScanner.h" //#include "app/clientplugins/localresolver/LocalContentScannerThread.h"
#include "app/clientplugins/localresolver/LocalContentConfigurator.h" //#include "app/clientplugins/localresolver/LocalContentScanner.h"
#include "app/clientplugins/localresolver/TrackTagUpdater.h" //#include "app/clientplugins/localresolver/LocalContentConfigurator.h"
#include "app/clientplugins/localresolver/QueryError.h" //#include "app/clientplugins/localresolver/TrackTagUpdater.h"
//#include "app/clientplugins/localresolver/QueryError.h"
#include "lib/lastfm/ws/WsAccessManager.h"
#include "lib/unicorn/QMessageBoxBuilder.h" #include "lib/unicorn/QMessageBoxBuilder.h"
#include <QFileDialog> #include <QFileDialog>
#include <QMenu> #include <QMenu>
#include <QShortcut> #include <QShortcut>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <phonon/audiooutput.h> #include <phonon/audiooutput.h>
#include <phonon/backendcapabilities.h> #include <phonon/backendcapabilities.h>
#include "BoffinRqlRequest.h"



#define OUTPUT_DEVICE_KEY "OutputDevice" #define OUTPUT_DEVICE_KEY "OutputDevice"




App::App( int& argc, char** argv ) App::App( int& argc, char** argv )
: unicorn::Application( argc, argv ) : unicorn::Application( argc, argv )
, m_contentScannerThread( 0 )
, m_contentScanner( 0 )
, m_trackTagUpdater( 0 )
, m_mainwindow( 0 ) , m_mainwindow( 0 )
, m_cloud( 0 ) , m_cloud( 0 )
, m_scrobsocket( 0 ) , m_scrobsocket( 0 )
, m_pipe( 0 ) , m_pipe( 0 )
, m_audioOutput( 0 ) , m_audioOutput( 0 )
, m_playing( false ) , m_playing( false )
{} , m_api( "http://localhost:8888", "" )
{
m_wam = new WsAccessManager( this );
}




App::~App() App::~App()
Expand All @@ -64,10 +68,6 @@ App::~App()
void void
App::cleanup() App::cleanup()
{ {
if (m_contentScanner) m_contentScanner->stop();
if (m_contentScannerThread) m_contentScannerThread->wait();
delete m_contentScanner;
delete m_contentScannerThread;
} }




Expand Down Expand Up @@ -118,10 +118,10 @@ App::init( MainWindow* window ) throw( int /*exitcode*/ )
connect( m_pipe, SIGNAL(stopped()), m_scrobsocket, SLOT(stop()) ); connect( m_pipe, SIGNAL(stopped()), m_scrobsocket, SLOT(stop()) );


/// parts of the scanning stuff /// parts of the scanning stuff
m_trackTagUpdater = TrackTagUpdater::create( //m_trackTagUpdater = TrackTagUpdater::create(
"http://musiclookup.last.fm/trackresolve", // "http://musiclookup.last.fm/trackresolve",
100, // number of days track tags are good // 100, // number of days track tags are good
5); // 5 minute delay between web requests // 5); // 5 minute delay between web requests


/// connect /// connect
connect( window->ui.play, SIGNAL(triggered()), SLOT(play()) ); connect( window->ui.play, SIGNAL(triggered()), SLOT(play()) );
Expand All @@ -134,74 +134,12 @@ App::init( MainWindow* window ) throw( int /*exitcode*/ )
QShortcut* cut = new QShortcut( Qt::Key_Space, window ); QShortcut* cut = new QShortcut( Qt::Key_Space, window );
connect( cut, SIGNAL(activated()), SLOT(playPause()) ); connect( cut, SIGNAL(activated()), SLOT(playPause()) );
cut->setContext( Qt::ApplicationShortcut ); cut->setContext( Qt::ApplicationShortcut );

/// go!
if (!scan( false ))
throw 1; //abort app
}


void
App::startAgain()
{
scan( true );
}


bool
App::scan( bool delete_all_files_first )
{
/// content scanner
try
{
LocalContentConfigurator cfg;

QStringList const dirs = cfg.getScanDirs();
if (delete_all_files_first || dirs.isEmpty() || cfg.getFileCount() == 0)
{
PickDirsDialog picker( m_mainwindow );
picker.setDirs( dirs );
if (picker.exec() == QDialog::Rejected)
return false; // abort the whole app

if ( delete_all_files_first )
cfg.deleteAllFiles();
cfg.changeScanDirs( picker.dirs() );
}
cfg.updateVolumeAvailability();
}
catch (QueryError e)
{
// the db is probably an old version
qCritical() << "Database problem: " + e.text();

QMessageBoxBuilder( m_mainwindow )
.setTitle( "Warning" )
.setText( "Boffin suffered a database problem, consult the log for the gory details" )
.exec();
return false; // not much we can do.
}


cleanup(); onScanningFinished();


m_contentScanner = new LocalContentScanner; /// go!
connect(m_contentScanner, SIGNAL(trackScanned(Track)), m_trackTagUpdater, SLOT(needsUpdate())); //if (!scan( false ))
m_contentScannerThread = new LocalContentScannerThread(m_contentScanner); // throw 1; //abort app

////// scanning widget
ScanProgressWidget* progress = new ScanProgressWidget;
m_mainwindow->setCentralWidget( progress );
connect( m_contentScanner, SIGNAL(trackScanned( Track )), progress, SLOT(onNewTrack( Track )) );
connect( m_contentScanner, SIGNAL(dirScanStart( QString )), progress, SLOT(onNewDirectory( QString )) );
connect( m_contentScanner, SIGNAL(finished()), progress, SLOT(onFinished()) );
//queue so the progress widget can update its status label
connect( m_contentScanner, SIGNAL(finished()), SLOT(onScanningFinished()), Qt::QueuedConnection );

m_mainwindow->ui.rescan->setEnabled( false );

m_contentScannerThread->start();

return true;
} }




Expand All @@ -223,7 +161,6 @@ App::onOutputDeviceActionTriggered( QAction* a )


#include "TagCloudView.h" #include "TagCloudView.h"
#include "TagDelegate.h" #include "TagDelegate.h"
#include "TagCloudModel.h"
#include "PlaydarTagCloudModel.h" #include "PlaydarTagCloudModel.h"
#include "lib/lastfm/ws/WsAccessManager.h" #include "lib/lastfm/ws/WsAccessManager.h"


Expand All @@ -237,12 +174,8 @@ App::onScanningFinished()


disconnect( sender(), 0, this, 0 ); //only once pls disconnect( sender(), 0, this, 0 ); //only once pls


PlaydarApi api("http://localhost:8888", "67adc74f-e373-4e1f-ab5a-4c9d6ca20c3a"); PlaydarTagCloudModel* model = new PlaydarTagCloudModel(m_api, m_wam);
WsAccessManager* wam = new WsAccessManager(this);
PlaydarTagCloudModel* model = new PlaydarTagCloudModel(api, wam);

m_cloud = new TagCloudView; m_cloud = new TagCloudView;
// m_cloud->setModel( new TagCloudModel );
m_cloud->setModel( model ); m_cloud->setModel( model );
m_cloud->setItemDelegate( new TagDelegate ); m_cloud->setItemDelegate( new TagDelegate );
m_mainwindow->setCentralWidget( m_cloud ); m_mainwindow->setCentralWidget( m_cloud );
Expand Down Expand Up @@ -273,7 +206,24 @@ App::play()
.exec(); .exec();
return; return;
} }
m_pipe->playTags( m_cloud->currentTags() );
QStringList tags = m_cloud->currentTags();
for (int i = 0; i < tags.count(); ++i)
tags[i] = "tag:\"" + tags[i] + '"';

QString rql = tags.join(" and ");
BoffinRqlRequest* req = new BoffinRqlRequest(m_wam, m_api, rql);
TrackSource* source = new TrackSource(req);
connect(source, SIGNAL(ready()), this, SLOT(onReadyToPlay()));
req->start();
onPreparing();
}


void
App::onReadyToPlay()
{
m_pipe->play( (TrackSource*) sender() );
} }




Expand All @@ -298,7 +248,7 @@ App::xspf()
if (path.size()) if (path.size())
{ {
m_mainwindow->QMainWindow::setWindowTitle( "Resolving XSPF..." ); m_mainwindow->QMainWindow::setWindowTitle( "Resolving XSPF..." );
m_pipe->playXspf( path ); // m_pipe->playXspf( path );
} }
} }


Expand Down Expand Up @@ -395,13 +345,13 @@ App::onWordle()
if(!d) { if(!d) {
d = new WordleDialog( m_mainwindow ); d = new WordleDialog( m_mainwindow );
QString output; QString output;
TagCloudModel model( this, 0 ); //TagCloudModel model( this, 0 );
for(int i = 0; i < model.rowCount(); ++i) { //for(int i = 0; i < model.rowCount(); ++i) {
QModelIndex index = model.index( i, 0 ); // QModelIndex index = model.index( i, 0 );
QString weight = index.data( TagCloudModel::WeightRole ).toString(); // QString weight = index.data( TagCloudModel::WeightRole ).toString();
QString tag = index.data().toString().trimmed().simplified().replace( ' ', '~' ); // QString tag = index.data().toString().trimmed().simplified().replace( ' ', '~' );
output += tag + ':' + weight + '\n'; // output += tag + ':' + weight + '\n';
} //}
d->setText( output ); d->setText( output );
} }
d.show(); d.show();
Expand Down
21 changes: 12 additions & 9 deletions app/boffin/App.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
#ifndef APP_H #ifndef APP_H
#define APP_H #define APP_H


#include <QPointer>
#include <lastfm/global.h> #include <lastfm/global.h>
#include "lib/unicorn/UnicornApplication.h" #include "lib/unicorn/UnicornApplication.h"
#include <QPointer> #include "PlaydarApi.h"


namespace Phonon { class AudioOutput; } namespace Phonon { class AudioOutput; }

class TagCloudView; class TagCloudView;



class App : public unicorn::Application class App : public unicorn::Application
{ {
Q_OBJECT Q_OBJECT
Expand All @@ -35,20 +40,18 @@ class App : public unicorn::Application
~App(); ~App();


void init( class MainWindow* ) throw( int /*exitcode*/ ); void init( class MainWindow* ) throw( int /*exitcode*/ );

void play( class TrackSource *);

public slots: public slots:
void play(); void play();
void xspf(); //prompts to choose a xspf to resolve void xspf(); //prompts to choose a xspf to resolve


/** returns false if user cancels the picker dialog */
bool scan( bool delete_all_files_first );
void startAgain();

void playPause(); void playPause();


private slots: private slots:
void onOutputDeviceActionTriggered( class QAction* ); void onOutputDeviceActionTriggered( class QAction* );


void onReadyToPlay();
void onPreparing(); void onPreparing();
void onStarted( const Track& ); void onStarted( const Track& );
void onResumed(); void onResumed();
Expand All @@ -62,9 +65,6 @@ private slots:
private: private:
void cleanup(); void cleanup();


class LocalContentScannerThread* m_contentScannerThread;
class LocalContentScanner* m_contentScanner;
class TrackTagUpdater* m_trackTagUpdater;
class MainWindow* m_mainwindow; class MainWindow* m_mainwindow;
QPointer<TagCloudView> m_cloud; QPointer<TagCloudView> m_cloud;
class ScrobSocket* m_scrobsocket; class ScrobSocket* m_scrobsocket;
Expand All @@ -73,6 +73,9 @@ private slots:
Phonon::AudioOutput* m_audioOutput; Phonon::AudioOutput* m_audioOutput;


bool m_playing; bool m_playing;

PlaydarApi m_api;
class WsAccessManager* m_wam;
}; };


#endif //APP_H #endif //APP_H
Loading

0 comments on commit 245d3e0

Please sign in to comment.