Permalink
Browse files

playdar boffin work in progress

  • Loading branch information...
1 parent b21d9fe commit 245d3e0bd8937d04e601603090fb9b9b0f26dbb0 @dougma dougma committed Apr 29, 2009
View
@@ -23,34 +23,38 @@
#include "PickDirsDialog.h"
#include "ScanProgressWidget.h"
#include "ScrobSocket.h"
-#include "app/clientplugins/localresolver/LocalContentScannerThread.h"
-#include "app/clientplugins/localresolver/LocalContentScanner.h"
-#include "app/clientplugins/localresolver/LocalContentConfigurator.h"
-#include "app/clientplugins/localresolver/TrackTagUpdater.h"
-#include "app/clientplugins/localresolver/QueryError.h"
+#include "TrackSource.h"
+//#include "app/clientplugins/localresolver/LocalContentScannerThread.h"
+//#include "app/clientplugins/localresolver/LocalContentScanner.h"
+//#include "app/clientplugins/localresolver/LocalContentConfigurator.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 <QFileDialog>
#include <QMenu>
#include <QShortcut>
#include <QVBoxLayout>
#include <phonon/audiooutput.h>
#include <phonon/backendcapabilities.h>
+#include "BoffinRqlRequest.h"
+
#define OUTPUT_DEVICE_KEY "OutputDevice"
App::App( int& argc, char** argv )
: unicorn::Application( argc, argv )
- , m_contentScannerThread( 0 )
- , m_contentScanner( 0 )
- , m_trackTagUpdater( 0 )
, m_mainwindow( 0 )
, m_cloud( 0 )
, m_scrobsocket( 0 )
, m_pipe( 0 )
, m_audioOutput( 0 )
, m_playing( false )
-{}
+ , m_api( "http://localhost:8888", "" )
+{
+ m_wam = new WsAccessManager( this );
+}
App::~App()
@@ -64,10 +68,6 @@ App::~App()
void
App::cleanup()
{
- if (m_contentScanner) m_contentScanner->stop();
- if (m_contentScannerThread) m_contentScannerThread->wait();
- delete m_contentScanner;
- delete m_contentScannerThread;
}
@@ -118,10 +118,10 @@ App::init( MainWindow* window ) throw( int /*exitcode*/ )
connect( m_pipe, SIGNAL(stopped()), m_scrobsocket, SLOT(stop()) );
/// parts of the scanning stuff
- m_trackTagUpdater = TrackTagUpdater::create(
- "http://musiclookup.last.fm/trackresolve",
- 100, // number of days track tags are good
- 5); // 5 minute delay between web requests
+ //m_trackTagUpdater = TrackTagUpdater::create(
+ // "http://musiclookup.last.fm/trackresolve",
+ // 100, // number of days track tags are good
+ // 5); // 5 minute delay between web requests
/// connect
connect( window->ui.play, SIGNAL(triggered()), SLOT(play()) );
@@ -134,74 +134,12 @@ App::init( MainWindow* window ) throw( int /*exitcode*/ )
QShortcut* cut = new QShortcut( Qt::Key_Space, window );
connect( cut, SIGNAL(activated()), SLOT(playPause()) );
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;
- connect(m_contentScanner, SIGNAL(trackScanned(Track)), m_trackTagUpdater, SLOT(needsUpdate()));
- m_contentScannerThread = new LocalContentScannerThread(m_contentScanner);
-
-////// 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;
+/// go!
+ //if (!scan( false ))
+ // throw 1; //abort app
}
@@ -223,7 +161,6 @@ App::onOutputDeviceActionTriggered( QAction* a )
#include "TagCloudView.h"
#include "TagDelegate.h"
-#include "TagCloudModel.h"
#include "PlaydarTagCloudModel.h"
#include "lib/lastfm/ws/WsAccessManager.h"
@@ -237,12 +174,8 @@ App::onScanningFinished()
disconnect( sender(), 0, this, 0 ); //only once pls
- PlaydarApi api("http://localhost:8888", "67adc74f-e373-4e1f-ab5a-4c9d6ca20c3a");
- WsAccessManager* wam = new WsAccessManager(this);
- PlaydarTagCloudModel* model = new PlaydarTagCloudModel(api, wam);
-
+ PlaydarTagCloudModel* model = new PlaydarTagCloudModel(m_api, m_wam);
m_cloud = new TagCloudView;
-// m_cloud->setModel( new TagCloudModel );
m_cloud->setModel( model );
m_cloud->setItemDelegate( new TagDelegate );
m_mainwindow->setCentralWidget( m_cloud );
@@ -273,7 +206,24 @@ App::play()
.exec();
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() );
}
@@ -298,7 +248,7 @@ App::xspf()
if (path.size())
{
m_mainwindow->QMainWindow::setWindowTitle( "Resolving XSPF..." );
- m_pipe->playXspf( path );
+ // m_pipe->playXspf( path );
}
}
@@ -395,13 +345,13 @@ App::onWordle()
if(!d) {
d = new WordleDialog( m_mainwindow );
QString output;
- TagCloudModel model( this, 0 );
- for(int i = 0; i < model.rowCount(); ++i) {
- QModelIndex index = model.index( i, 0 );
- QString weight = index.data( TagCloudModel::WeightRole ).toString();
- QString tag = index.data().toString().trimmed().simplified().replace( ' ', '~' );
- output += tag + ':' + weight + '\n';
- }
+ //TagCloudModel model( this, 0 );
+ //for(int i = 0; i < model.rowCount(); ++i) {
+ // QModelIndex index = model.index( i, 0 );
+ // QString weight = index.data( TagCloudModel::WeightRole ).toString();
+ // QString tag = index.data().toString().trimmed().simplified().replace( ' ', '~' );
+ // output += tag + ':' + weight + '\n';
+ //}
d->setText( output );
}
d.show();
View
@@ -20,12 +20,17 @@
#ifndef APP_H
#define APP_H
+#include <QPointer>
#include <lastfm/global.h>
#include "lib/unicorn/UnicornApplication.h"
-#include <QPointer>
+#include "PlaydarApi.h"
+
+
namespace Phonon { class AudioOutput; }
+
class TagCloudView;
+
class App : public unicorn::Application
{
Q_OBJECT
@@ -35,20 +40,18 @@ class App : public unicorn::Application
~App();
void init( class MainWindow* ) throw( int /*exitcode*/ );
-
+ void play( class TrackSource *);
+
public slots:
void play();
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();
private slots:
void onOutputDeviceActionTriggered( class QAction* );
+ void onReadyToPlay();
void onPreparing();
void onStarted( const Track& );
void onResumed();
@@ -62,9 +65,6 @@ private slots:
private:
void cleanup();
- class LocalContentScannerThread* m_contentScannerThread;
- class LocalContentScanner* m_contentScanner;
- class TrackTagUpdater* m_trackTagUpdater;
class MainWindow* m_mainwindow;
QPointer<TagCloudView> m_cloud;
class ScrobSocket* m_scrobsocket;
@@ -73,6 +73,9 @@ private slots:
Phonon::AudioOutput* m_audioOutput;
bool m_playing;
+
+ PlaydarApi m_api;
+ class WsAccessManager* m_wam;
};
#endif //APP_H
Oops, something went wrong.

0 comments on commit 245d3e0

Please sign in to comment.