From 6e708cc0c4d503f72d0419fe4e39f029aad8d514 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 12:18:48 +0100 Subject: [PATCH 01/12] * Made QHeaderView behave, mostly. * Removed online / offline button again. --- src/libtomahawk/playlist/collectionview.cpp | 2 +- src/libtomahawk/playlist/playlistview.cpp | 9 ++- src/libtomahawk/playlist/trackheader.cpp | 87 ++++++--------------- src/libtomahawk/playlist/trackheader.h | 12 +-- src/libtomahawk/playlist/trackmodel.cpp | 2 +- src/libtomahawk/playlist/trackview.cpp | 10 ++- src/libtomahawk/playlist/trackview.h | 2 +- src/libtomahawk/tomahawksettings.cpp | 8 +- src/libtomahawk/tomahawksettings.h | 4 +- src/libtomahawk/utils/proxystyle.cpp | 9 ++- src/tomahawkwindow.cpp | 16 ++-- 11 files changed, 62 insertions(+), 99 deletions(-) diff --git a/src/libtomahawk/playlist/collectionview.cpp b/src/libtomahawk/playlist/collectionview.cpp index 0847849e8..2df2a594e 100644 --- a/src/libtomahawk/playlist/collectionview.cpp +++ b/src/libtomahawk/playlist/collectionview.cpp @@ -13,7 +13,6 @@ using namespace Tomahawk; CollectionView::CollectionView( QWidget* parent ) : TrackView( parent ) { - setGuid( "collectionview" ); setProxyModel( new CollectionProxyModel( this ) ); setSortingEnabled( true ); @@ -37,6 +36,7 @@ void CollectionView::setModel( TrackModel* model ) { TrackView::setModel( model ); + setGuid( "collectionview" ); connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) ); } diff --git a/src/libtomahawk/playlist/playlistview.cpp b/src/libtomahawk/playlist/playlistview.cpp index b11255f2e..9e45175ab 100644 --- a/src/libtomahawk/playlist/playlistview.cpp +++ b/src/libtomahawk/playlist/playlistview.cpp @@ -14,7 +14,6 @@ using namespace Tomahawk; PlaylistView::PlaylistView( QWidget* parent ) : TrackView( parent ) { - setGuid( "playlistview" ); setProxyModel( new PlaylistProxyModel( this ) ); setContextMenuPolicy( Qt::CustomContextMenu ); @@ -31,14 +30,16 @@ PlaylistView::~PlaylistView() void PlaylistView::setModel( PlaylistModel* model ) { - if ( !model->playlist().isNull() ) - setGuid( QString( "playlistview/%1" ).arg( model->playlist()->guid() ) ); - m_model = model; TrackView::setModel( model ); setColumnHidden( 5, true ); // Hide age column per default + if ( !model->playlist().isNull() ) + setGuid( QString( "playlistview/%1" ).arg( model->playlist()->guid() ) ); + else + setGuid( "playlistview" ); + connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) ); } diff --git a/src/libtomahawk/playlist/trackheader.cpp b/src/libtomahawk/playlist/trackheader.cpp index 7df6fb8ea..3069ca66b 100644 --- a/src/libtomahawk/playlist/trackheader.cpp +++ b/src/libtomahawk/playlist/trackheader.cpp @@ -14,28 +14,27 @@ TrackHeader::TrackHeader( TrackView* parent ) , m_parent( parent ) , m_menu( new QMenu( this ) ) , m_sigmap( new QSignalMapper( this ) ) - , m_hiddenWidth( 0 ) - , m_hiddenPct( 0.0 ) , m_init( false ) { - setStretchLastSection( true ); setResizeMode( QHeaderView::Interactive ); setMinimumSectionSize( 60 ); setDefaultAlignment( Qt::AlignLeft ); setMovable( true ); + setStretchLastSection( true ); // setCascadingSectionResizes( true ); // m_menu->addAction( tr( "Resize columns to fit window" ), this, SLOT( onToggleResizeColumns() ) ); // m_menu->addSeparator(); - connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionResized( int, int, int ) ) ); +// connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionResized( int ) ) ); connect( m_sigmap, SIGNAL( mapped( int ) ), SLOT( toggleVisibility( int ) ) ); } TrackHeader::~TrackHeader() { - saveColumnsState(); + qDebug() << "Storing for:" << m_parent->guid(); + TomahawkSettings::instance()->setPlaylistColumnSizes( m_parent->guid(), saveState() ); } @@ -47,75 +46,35 @@ TrackHeader::visibleSectionCount() const void -TrackHeader::onSectionResized( int logicalidx, int oldSize, int newSize ) +TrackHeader::checkState() { - if ( !m_init ) + if ( !count() || m_init ) return; - int width = m_parent->viewport()->width(); - for ( int x = 0; x < m_columnWeights.count(); x++ ) - { - if ( sectionSize( x ) ) - { - // not hidden - m_columnWeights[x] = (double)sectionSize( x ) / (double)width; - } - } -} - - -void -TrackHeader::onResized() -{ - if ( !m_init && count() ) - restoreColumnsState(); - - m_init = false; - - int width = m_parent->viewport()->width(); - for ( int x = 0; x < m_columnWeights.count(); x++ ) - { - if ( sectionSize( x ) ) - { - // not hidden - double nw = (double)width * m_columnWeights[x]; - resizeSection( x, qMax( minimumSectionSize(), int( nw ) ) ); - } - } - + qDebug() << "Restoring for:" << m_parent->guid(); m_init = true; -} + QByteArray state = TomahawkSettings::instance()->playlistColumnSizes( m_parent->guid() ); - -void -TrackHeader::restoreColumnsState() -{ - QList list = TomahawkSettings::instance()->playlistColumnSizes( m_parent->guid() ); - - if ( list.count() != count() ) // FIXME: const - { - m_columnWeights << 0.21 << 0.22 << 0.20 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05 << 0.12; - } + if ( !state.isEmpty() ) + restoreState( state ); else { - foreach( const QVariant& v, list ) - m_columnWeights << v.toDouble(); + QList< double > m_columnWeights; + m_columnWeights << 0.21 << 0.22 << 0.20 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05; // << 0.12; + + for ( int i = 0; i < count(); i++ ) + { + if ( isSectionHidden( i ) ) + continue; + + double nw = (double)m_parent->width() * m_columnWeights.at( i ); + qDebug() << "Setting default size:" << i << nw; + resizeSection( i, qMax( minimumSectionSize(), int( nw - 0.5 ) ) ); + } } } -void -TrackHeader::saveColumnsState() -{ - QList wlist; - - foreach( double w, m_columnWeights ) - wlist << QVariant( w ); - - TomahawkSettings::instance()->setPlaylistColumnSizes( m_parent->guid(), wlist ); -} - - void TrackHeader::addColumnToMenu( int index ) { @@ -158,6 +117,4 @@ TrackHeader::toggleVisibility( int index ) showSection( index ); else hideSection( index ); - - onResized(); } diff --git a/src/libtomahawk/playlist/trackheader.h b/src/libtomahawk/playlist/trackheader.h index 75db27b0d..f541e092d 100644 --- a/src/libtomahawk/playlist/trackheader.h +++ b/src/libtomahawk/playlist/trackheader.h @@ -19,32 +19,24 @@ public: int visibleSectionCount() const; public slots: - void onResized(); void toggleVisibility( int index ); + void checkState(); protected: void contextMenuEvent( QContextMenuEvent* e ); private slots: - void onSectionResized( int logicalIndex, int oldSize, int newSize ); - +// void onSectionResized( int index ); void onToggleResizeColumns(); private: void addColumnToMenu( int index ); - void restoreColumnsState(); - void saveColumnsState(); - TrackView* m_parent; QMenu* m_menu; QSignalMapper* m_sigmap; QList m_visActions; - - QList m_columnWeights; - int m_hiddenWidth; - double m_hiddenPct; bool m_init; }; diff --git a/src/libtomahawk/playlist/trackmodel.cpp b/src/libtomahawk/playlist/trackmodel.cpp index 7cb73631b..a39eecc76 100644 --- a/src/libtomahawk/playlist/trackmodel.cpp +++ b/src/libtomahawk/playlist/trackmodel.cpp @@ -190,7 +190,7 @@ TrackModel::headerData( int section, Qt::Orientation orientation, int role ) con { QStringList headers; headers << tr( "Artist" ) << tr( "Track" ) << tr( "Album" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Age" ) << tr( "Year" ) << tr( "Size" ) << tr( "Origin" ); - if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 ) + if ( role == Qt::DisplayRole && section >= 0 ) { return headers.at( section ); } diff --git a/src/libtomahawk/playlist/trackview.cpp b/src/libtomahawk/playlist/trackview.cpp index 3317bd21b..3aefc9982 100644 --- a/src/libtomahawk/playlist/trackview.cpp +++ b/src/libtomahawk/playlist/trackview.cpp @@ -40,6 +40,7 @@ TrackView::TrackView( QWidget* parent ) setRootIsDecorated( false ); setUniformRowHeights( true ); setMinimumWidth( 300 ); + setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); setHeader( m_header ); @@ -61,6 +62,13 @@ TrackView::~TrackView() } +void +TrackView::setGuid( const QString& guid ) +{ + m_guid = guid; +} + + void TrackView::setProxyModel( TrackProxyModel* model ) { @@ -156,7 +164,7 @@ TrackView::addItemsToQueue() void TrackView::resizeEvent( QResizeEvent* event ) { - m_header->onResized(); + m_header->checkState(); } diff --git a/src/libtomahawk/playlist/trackview.h b/src/libtomahawk/playlist/trackview.h index 51207506a..337d004a5 100644 --- a/src/libtomahawk/playlist/trackview.h +++ b/src/libtomahawk/playlist/trackview.h @@ -23,7 +23,7 @@ public: ~TrackView(); virtual QString guid() const { return m_guid; } - virtual void setGuid( const QString& guid ) { m_guid = guid; } + virtual void setGuid( const QString& guid ); virtual void setModel( TrackModel* model ); void setProxyModel( TrackProxyModel* model ); diff --git a/src/libtomahawk/tomahawksettings.cpp b/src/libtomahawk/tomahawksettings.cpp index cc6f4278c..b221c1b43 100644 --- a/src/libtomahawk/tomahawksettings.cpp +++ b/src/libtomahawk/tomahawksettings.cpp @@ -184,17 +184,17 @@ TomahawkSettings::setMainWindowState( const QByteArray& state ) } -QList +QByteArray TomahawkSettings::playlistColumnSizes( const QString& playlistid ) const { - return value( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ) ).toList(); + return value( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ) ).toByteArray(); } void -TomahawkSettings::setPlaylistColumnSizes( const QString& playlistid, const QList& cols ) +TomahawkSettings::setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state ) { - setValue( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ), cols ); + setValue( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ), state ); } diff --git a/src/libtomahawk/tomahawksettings.h b/src/libtomahawk/tomahawksettings.h index 3959ec6e9..42e4cf0c9 100644 --- a/src/libtomahawk/tomahawksettings.h +++ b/src/libtomahawk/tomahawksettings.h @@ -32,8 +32,8 @@ public: void setMainWindowState( const QByteArray& state ); /// Playlist stuff - QList playlistColumnSizes( const QString& playlistid ) const; - void setPlaylistColumnSizes( const QString& playlistid, const QList& cols ); + QByteArray playlistColumnSizes( const QString& playlistid ) const; + void setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state ); QList recentlyPlayedPlaylists() const; void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist ); diff --git a/src/libtomahawk/utils/proxystyle.cpp b/src/libtomahawk/utils/proxystyle.cpp index 2778e47ee..34feb8f93 100644 --- a/src/libtomahawk/utils/proxystyle.cpp +++ b/src/libtomahawk/utils/proxystyle.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -19,8 +20,12 @@ ProxyStyle::drawControl( ControlElement ce, const QStyleOption* opt, QPainter* p { if ( ce == CE_Splitter ) { - p->setPen( QColor( 0x8c, 0x8c, 0x8c ) ); - p->drawLine( opt->rect.topLeft(), opt->rect.bottomRight() ); + const QSplitter* splitter = qobject_cast< const QSplitter* >( w ); + if ( !splitter->sizes().contains( 0 ) ) + { + p->setPen( QColor( 0x8c, 0x8c, 0x8c ) ); + p->drawLine( opt->rect.topLeft(), opt->rect.bottomRight() ); + } } else QProxyStyle::drawControl( ce, opt, p, w ); diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 7ec798e29..36e71f8e4 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -87,22 +87,22 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) sidebar->addWidget( transferView ); sidebar->hide( 1, false ); - QWidget* buttonWidget = new QWidget(); +/* QWidget* buttonWidget = new QWidget(); buttonWidget->setLayout( new QVBoxLayout() ); m_statusButton = new QPushButton(); - buttonWidget->layout()->addWidget( m_statusButton ); + buttonWidget->layout()->addWidget( m_statusButton );*/ sidebarWidget->layout()->addWidget( sidebar ); - sidebarWidget->layout()->addWidget( buttonWidget ); +// sidebarWidget->layout()->addWidget( buttonWidget ); sidebarWidget->setContentsMargins( 0, 0, 0, 0 ); sidebarWidget->layout()->setContentsMargins( 0, 0, 0, 0 ); sidebarWidget->layout()->setMargin( 0 ); sidebarWidget->layout()->setSpacing( 0 ); - buttonWidget->setContentsMargins( 0, 0, 0, 0 ); +/* buttonWidget->setContentsMargins( 0, 0, 0, 0 ); buttonWidget->layout()->setContentsMargins( 0, 0, 0, 0 ); buttonWidget->layout()->setMargin( 0 ); - buttonWidget->layout()->setSpacing( 0 ); + buttonWidget->layout()->setSpacing( 0 );*/ ui->splitter->addWidget( sidebarWidget ); ui->splitter->addWidget( PlaylistManager::instance()->widget() ); @@ -181,7 +181,7 @@ TomahawkWindow::setupSignals() connect( ui->actionCreate_New_Station, SIGNAL( triggered() ), SLOT( createStation() )); connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) ); connect( ui->actionExit, SIGNAL( triggered() ), APP, SLOT( quit() ) ); - connect( m_statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT( toggleConnect() ) ); +// connect( m_statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT( toggleConnect() ) ); // connect( APP->sipHandler(), SIGNAL( connected() ), SLOT( onSipConnected() ) ); @@ -392,14 +392,14 @@ TomahawkWindow::onPlaybackLoading( const Tomahawk::result_ptr& result ) void TomahawkWindow::onSipConnected() { - m_statusButton->setText( tr( "Online" ) ); +// m_statusButton->setText( tr( "Online" ) ); } void TomahawkWindow::onSipDisconnected() { - m_statusButton->setText( tr( "Offline" ) ); +// m_statusButton->setText( tr( "Offline" ) ); } From eebd2ed390aa65c75ac94bc25ec341bb95cf4cac Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 12:21:07 +0100 Subject: [PATCH 02/12] * Off-by-one error. --- src/libtomahawk/playlist/trackheader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/trackheader.cpp b/src/libtomahawk/playlist/trackheader.cpp index 3069ca66b..f96ab1471 100644 --- a/src/libtomahawk/playlist/trackheader.cpp +++ b/src/libtomahawk/playlist/trackheader.cpp @@ -62,7 +62,7 @@ TrackHeader::checkState() QList< double > m_columnWeights; m_columnWeights << 0.21 << 0.22 << 0.20 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05; // << 0.12; - for ( int i = 0; i < count(); i++ ) + for ( int i = 0; i < count() - 1; i++ ) { if ( isSectionHidden( i ) ) continue; From 0e5b8017f7647a3f503306579cddd509b1c06b34 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 12:45:58 +0100 Subject: [PATCH 03/12] * Helps to propagate events, doesn't it? --- src/libtomahawk/playlist/trackview.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/trackview.cpp b/src/libtomahawk/playlist/trackview.cpp index 3aefc9982..c2a972ed1 100644 --- a/src/libtomahawk/playlist/trackview.cpp +++ b/src/libtomahawk/playlist/trackview.cpp @@ -40,7 +40,7 @@ TrackView::TrackView( QWidget* parent ) setRootIsDecorated( false ); setUniformRowHeights( true ); setMinimumWidth( 300 ); - setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); +// setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); setHeader( m_header ); @@ -164,6 +164,7 @@ TrackView::addItemsToQueue() void TrackView::resizeEvent( QResizeEvent* event ) { + QTreeView::resizeEvent( event ); m_header->checkState(); } From 0141f2b57331b63901c984cf8b598b4a6e2b18ba Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 17:12:10 +0100 Subject: [PATCH 04/12] * Invoke enqueuing DbCmds in the wrong thread. * Fixed a few more TrackHeader issues. --- .../databasecommand_updatesearchindex.cpp | 1 + src/libtomahawk/database/databaseworker.cpp | 7 +++++++ src/libtomahawk/database/databaseworker.h | 5 +++-- src/libtomahawk/playlist/trackheader.cpp | 17 ++++++++++++----- src/libtomahawk/playlist/trackheader.h | 2 +- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/database/databasecommand_updatesearchindex.cpp b/src/libtomahawk/database/databasecommand_updatesearchindex.cpp index 67d9e9b60..3e461dd2c 100644 --- a/src/libtomahawk/database/databasecommand_updatesearchindex.cpp +++ b/src/libtomahawk/database/databasecommand_updatesearchindex.cpp @@ -23,6 +23,7 @@ DatabaseCommand_UpdateSearchIndex::indexTable( DatabaseImpl* db, const QString& } db->m_fuzzyIndex->appendFields( table, fields ); + qDebug() << "Building index for" << table << "finished."; } diff --git a/src/libtomahawk/database/databaseworker.cpp b/src/libtomahawk/database/databaseworker.cpp index 510d53064..2e732f085 100644 --- a/src/libtomahawk/database/databaseworker.cpp +++ b/src/libtomahawk/database/databaseworker.cpp @@ -40,6 +40,13 @@ DatabaseWorker::run() void DatabaseWorker::enqueue( const QSharedPointer& cmd ) { + if ( QThread::currentThread() != thread() ) + { +// qDebug() << Q_FUNC_INFO << "Reinvoking in correct thread."; + QMetaObject::invokeMethod( this, "enqueue", Qt::QueuedConnection, Q_ARG( QSharedPointer, cmd ) ); + return; + } + m_outstanding++; QMutexLocker lock( &m_mut ); diff --git a/src/libtomahawk/database/databaseworker.h b/src/libtomahawk/database/databaseworker.h index 83ecd1562..87073e9df 100644 --- a/src/libtomahawk/database/databaseworker.h +++ b/src/libtomahawk/database/databaseworker.h @@ -25,11 +25,12 @@ public: DatabaseWorker( DatabaseImpl*, Database*, bool mutates ); ~DatabaseWorker(); - void enqueue( const QSharedPointer& ); - bool busy() const { return m_outstanding > 0; } unsigned int outstandingJobs() const { return m_outstanding; } +public slots: + void enqueue( const QSharedPointer& ); + protected: void run(); diff --git a/src/libtomahawk/playlist/trackheader.cpp b/src/libtomahawk/playlist/trackheader.cpp index f96ab1471..42080b98b 100644 --- a/src/libtomahawk/playlist/trackheader.cpp +++ b/src/libtomahawk/playlist/trackheader.cpp @@ -26,14 +26,22 @@ TrackHeader::TrackHeader( TrackView* parent ) // m_menu->addAction( tr( "Resize columns to fit window" ), this, SLOT( onToggleResizeColumns() ) ); // m_menu->addSeparator(); -// connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionResized( int ) ) ); + connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionResized() ) ); connect( m_sigmap, SIGNAL( mapped( int ) ), SLOT( toggleVisibility( int ) ) ); } TrackHeader::~TrackHeader() { - qDebug() << "Storing for:" << m_parent->guid(); +} + + +void +TrackHeader::onSectionResized() +{ + if ( !m_init ) + return; + TomahawkSettings::instance()->setPlaylistColumnSizes( m_parent->guid(), saveState() ); } @@ -51,10 +59,7 @@ TrackHeader::checkState() if ( !count() || m_init ) return; - qDebug() << "Restoring for:" << m_parent->guid(); - m_init = true; QByteArray state = TomahawkSettings::instance()->playlistColumnSizes( m_parent->guid() ); - if ( !state.isEmpty() ) restoreState( state ); else @@ -72,6 +77,8 @@ TrackHeader::checkState() resizeSection( i, qMax( minimumSectionSize(), int( nw - 0.5 ) ) ); } } + + m_init = true; } diff --git a/src/libtomahawk/playlist/trackheader.h b/src/libtomahawk/playlist/trackheader.h index f541e092d..21b9e3243 100644 --- a/src/libtomahawk/playlist/trackheader.h +++ b/src/libtomahawk/playlist/trackheader.h @@ -26,7 +26,7 @@ protected: void contextMenuEvent( QContextMenuEvent* e ); private slots: -// void onSectionResized( int index ); + void onSectionResized(); void onToggleResizeColumns(); private: From caf8d04ca74a5529999b4e5bd2a9fa729dadf369 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 17:25:45 +0100 Subject: [PATCH 05/12] * Catch CLuceneError exceptions. --- src/libtomahawk/database/fuzzyindex.cpp | 147 ++++++++++++++---------- 1 file changed, 86 insertions(+), 61 deletions(-) diff --git a/src/libtomahawk/database/fuzzyindex.cpp b/src/libtomahawk/database/fuzzyindex.cpp index 7e1074c23..5f0c62e40 100644 --- a/src/libtomahawk/database/fuzzyindex.cpp +++ b/src/libtomahawk/database/fuzzyindex.cpp @@ -45,7 +45,16 @@ void FuzzyIndex::beginIndexing() { m_mutex.lock(); - IndexWriter luceneWriter = IndexWriter( m_luceneDir, m_analyzer, true ); + + try + { + IndexWriter luceneWriter = IndexWriter( m_luceneDir, m_analyzer, true ); + } + catch( CLuceneError& error ) + { + qDebug() << "Caught CLucene error:" << error.what(); + Q_ASSERT( false ); + } } @@ -60,39 +69,47 @@ FuzzyIndex::endIndexing() void FuzzyIndex::appendFields( const QString& table, const QMap< unsigned int, QString >& fields ) { - delete m_luceneSearcher; - delete m_luceneReader; - m_luceneSearcher = 0; - m_luceneReader = 0; - - bool create = !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ); - IndexWriter luceneWriter = IndexWriter( m_luceneDir, m_analyzer, create ); - Document doc; - - QMapIterator< unsigned int, QString > it( fields ); - while ( it.hasNext() ) + try { - it.next(); - unsigned int id = it.key(); - QString name = it.value(); + delete m_luceneSearcher; + delete m_luceneReader; + m_luceneSearcher = 0; + m_luceneReader = 0; + bool create = !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ); + IndexWriter luceneWriter = IndexWriter( m_luceneDir, m_analyzer, create ); + Document doc; + + QMapIterator< unsigned int, QString > it( fields ); + while ( it.hasNext() ) { - Field* field = _CLNEW Field( table.toStdWString().c_str(), name.toStdWString().c_str(), - Field::STORE_YES | Field::INDEX_UNTOKENIZED ); - doc.add( *field ); + it.next(); + unsigned int id = it.key(); + QString name = it.value(); + + { + Field* field = _CLNEW Field( table.toStdWString().c_str(), name.toStdWString().c_str(), + Field::STORE_YES | Field::INDEX_UNTOKENIZED ); + doc.add( *field ); + } + + { + Field* field = _CLNEW Field( _T( "id" ), QString::number( id ).toStdWString().c_str(), + Field::STORE_YES | Field::INDEX_NO ); + doc.add( *field ); + } + + luceneWriter.addDocument( &doc ); + doc.clear(); } - - { - Field* field = _CLNEW Field( _T( "id" ), QString::number( id ).toStdWString().c_str(), - Field::STORE_YES | Field::INDEX_NO ); - doc.add( *field ); - } - - luceneWriter.addDocument( &doc ); - doc.clear(); + + luceneWriter.close(); + } + catch( CLuceneError& error ) + { + qDebug() << "Caught CLucene error:" << error.what(); + Q_ASSERT( false ); } - - luceneWriter.close(); } @@ -109,47 +126,55 @@ FuzzyIndex::search( const QString& table, const QString& name ) QMutexLocker lock( &m_mutex ); QMap< int, float > resultsmap; - if ( !m_luceneReader ) + try { - if ( !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ) ) + if ( !m_luceneReader ) { - qDebug() << Q_FUNC_INFO << "index didn't exist."; + if ( !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ) ) + { + qDebug() << Q_FUNC_INFO << "index didn't exist."; + return resultsmap; + } + + m_luceneReader = IndexReader::open( m_luceneDir ); + m_luceneSearcher = _CLNEW IndexSearcher( m_luceneReader ); + } + + if ( name.isEmpty() ) return resultsmap; - } - m_luceneReader = IndexReader::open( m_luceneDir ); - m_luceneSearcher = _CLNEW IndexSearcher( m_luceneReader ); - } + SimpleAnalyzer analyzer; + QueryParser parser( table.toStdWString().c_str(), m_analyzer ); + Hits* hits = 0; - if ( name.isEmpty() ) - return resultsmap; + FuzzyQuery* qry = _CLNEW FuzzyQuery( _CLNEW Term( table.toStdWString().c_str(), name.toStdWString().c_str() ) ); + hits = m_luceneSearcher->search( qry ); - SimpleAnalyzer analyzer; - QueryParser parser( table.toStdWString().c_str(), m_analyzer ); - Hits* hits = 0; - - FuzzyQuery* qry = _CLNEW FuzzyQuery( _CLNEW Term( table.toStdWString().c_str(), name.toStdWString().c_str() ) ); - hits = m_luceneSearcher->search( qry ); - - for ( int i = 0; i < hits->length(); i++ ) - { - Document* d = &hits->doc( i ); - - float score = hits->score( i ); - int id = QString::fromWCharArray( d->get( _T( "id" ) ) ).toInt(); - QString result = QString::fromWCharArray( d->get( table.toStdWString().c_str() ) ); - - if ( result.toLower() == name.toLower() ) - score = 1.0; - else - score = qMin( score, (float)0.99 ); - - if ( score > 0.05 ) + for ( int i = 0; i < hits->length(); i++ ) { - resultsmap.insert( id, score ); -// qDebug() << "Hitres:" << result << id << score << table << name; + Document* d = &hits->doc( i ); + + float score = hits->score( i ); + int id = QString::fromWCharArray( d->get( _T( "id" ) ) ).toInt(); + QString result = QString::fromWCharArray( d->get( table.toStdWString().c_str() ) ); + + if ( result.toLower() == name.toLower() ) + score = 1.0; + else + score = qMin( score, (float)0.99 ); + + if ( score > 0.05 ) + { + resultsmap.insert( id, score ); + // qDebug() << "Hitres:" << result << id << score << table << name; + } } } + catch( CLuceneError& error ) + { + qDebug() << "Caught CLucene error:" << error.what(); + Q_ASSERT( false ); + } return resultsmap; } From 7a081128e6dccc7f7f4c48647180c1ec1d4a38f5 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 17:29:23 +0100 Subject: [PATCH 06/12] * Make it compile again for Win32. --- thirdparty/jdns/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/thirdparty/jdns/CMakeLists.txt b/thirdparty/jdns/CMakeLists.txt index 573c9e994..59f820b93 100644 --- a/thirdparty/jdns/CMakeLists.txt +++ b/thirdparty/jdns/CMakeLists.txt @@ -44,6 +44,7 @@ ADD_LIBRARY(tomahawk_jdns SHARED ${TOMAHAWK_JDNS_SOURCES} ${TOMAHAWK_JDNS_MOC}) target_link_libraries(tomahawk_jdns ${QT_LIBRARIES} + ${PLATFORM_SPECIFIC_LIBS} ) SET_TARGET_PROPERTIES( tomahawk_jdns PROPERTIES DEFINE_SYMBOL MAKE_JDNS_LIB ) From 496a09dc8161981c5b623b1e185fbf0770d5aeff Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 17:49:28 +0100 Subject: [PATCH 07/12] * Unbreak windows compile. --- src/libtomahawk/CMakeLists.txt | 2 +- src/libtomahawk/qtsingleapp/qtlockedfile_win.cpp | 2 ++ thirdparty/jdns/jdnsshared/jdnsshared.h | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index eae0c916b..db4789cea 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -364,13 +364,13 @@ target_link_libraries( tomahawklib ${QT_LIBRARIES} ${OS_SPECIFIC_LINK_LIBRARIES} ${LIBECHONEST_LIBRARY} + tomahawk_jdns portfwd qjson mad vorbisfile ogg FLAC++ - tomahawk_jdns ${CLUCENE_LIBRARY} ) diff --git a/src/libtomahawk/qtsingleapp/qtlockedfile_win.cpp b/src/libtomahawk/qtsingleapp/qtlockedfile_win.cpp index 4cd200397..8090470cd 100644 --- a/src/libtomahawk/qtsingleapp/qtlockedfile_win.cpp +++ b/src/libtomahawk/qtsingleapp/qtlockedfile_win.cpp @@ -45,6 +45,8 @@ // Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS #define MAX_READERS MAXIMUM_WAIT_OBJECTS +#define TCHAR WCHAR + Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) { if (mutexname.isEmpty()) { diff --git a/thirdparty/jdns/jdnsshared/jdnsshared.h b/thirdparty/jdns/jdnsshared/jdnsshared.h index 701c7115e..9b8acf6b6 100644 --- a/thirdparty/jdns/jdnsshared/jdnsshared.h +++ b/thirdparty/jdns/jdnsshared/jdnsshared.h @@ -23,6 +23,8 @@ #include "qjdns.h" +#include "../jdns_export.h" + class JDnsShared; class JDnsSharedPrivate; class JDnsSharedRequestPrivate; @@ -194,7 +196,7 @@ pub->publish(QJDns::Unique, rec); \sa JDnsShared */ -class JDnsSharedRequest : public QObject +class JDNS_EXPORT JDnsSharedRequest : public QObject { Q_OBJECT public: @@ -401,7 +403,7 @@ dns->addInterface(addr); \sa JDnsSharedRequest */ -class JDnsShared : public QObject +class JDNS_EXPORT JDnsShared : public QObject { Q_OBJECT public: From 76802d971d559d649b79de84a1c0ad44f5bef38d Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 17:53:39 +0100 Subject: [PATCH 08/12] * Finally builds on Win32 again. --- .../qtsingleapp/qtsingleapplication.h | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/libtomahawk/qtsingleapp/qtsingleapplication.h b/src/libtomahawk/qtsingleapp/qtsingleapplication.h index 7bf6837ae..c696d60ce 100644 --- a/src/libtomahawk/qtsingleapp/qtsingleapplication.h +++ b/src/libtomahawk/qtsingleapp/qtsingleapplication.h @@ -40,25 +40,11 @@ #include +#include "dllmacro.h" + class QtLocalPeer; -#if defined(Q_WS_WIN) -# if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) -# define QT_QTSINGLEAPPLICATION_EXPORT -# elif defined(QT_QTSINGLEAPPLICATION_IMPORT) -# if defined(QT_QTSINGLEAPPLICATION_EXPORT) -# undef QT_QTSINGLEAPPLICATION_EXPORT -# endif -# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport) -# elif defined(QT_QTSINGLEAPPLICATION_EXPORT) -# undef QT_QTSINGLEAPPLICATION_EXPORT -# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport) -# endif -#else -# define QT_QTSINGLEAPPLICATION_EXPORT -#endif - -class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication +class DLLEXPORT QtSingleApplication : public QApplication { Q_OBJECT From d9bc06a4f60ee0673c7b8d374c4f7a97a4d29c20 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 18:15:18 +0100 Subject: [PATCH 09/12] * Fixed tomahawk.nsi. Sorry for waiting on me, Domme :-). --- admin/win/revision.txt | 2 +- admin/win/tomahawk.nsi | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/win/revision.txt b/admin/win/revision.txt index 4e9e28848..b44fe09a7 100644 --- a/admin/win/revision.txt +++ b/admin/win/revision.txt @@ -1 +1 @@ -63 \ No newline at end of file +65 \ No newline at end of file diff --git a/admin/win/tomahawk.nsi b/admin/win/tomahawk.nsi index 0bc84cbaf..5a56f4327 100755 --- a/admin/win/tomahawk.nsi +++ b/admin/win/tomahawk.nsi @@ -304,6 +304,7 @@ Section "Tomahawk Player" SEC_TOMAHAWK_PLAYER File "${MING_LIB}\libclucene-core.dll" File "${QXTWEB_DLL_PATH}\libqxtweb-standalone.dll" + File "${ROOT_PATH}\build\thirdparty\jdns\libtomahawk_jdns.dll" SectionEnd SectionGroup "Shortcuts" From 0ca1212691f032e4a3c093ab90801b025392ca6a Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 13 Feb 2011 12:37:03 -0500 Subject: [PATCH 10/12] Add some mac-specific code. Tomahawk now opens spiffs from the browser or the finder. There is also commented out code for handling multimedia keys. Thanks to the Clementine project for the cocoa code :) --- admin/mac/Info.plist | 32 ++++- include/tomahawk/tomahawkapp.h | 7 +- src/CMakeLists.osx.txt | 25 ++++ src/CMakeLists.txt | 11 ++ src/config.h.in | 10 ++ src/main.cpp | 44 +++++++ src/tomahawkapp.cpp | 55 ++++++-- src/tomahawkapp_mac.h | 28 ++++ src/tomahawkapp_mac.mm | 229 +++++++++++++++++++++++++++++++++ src/tomahawkapp_macdelegate.h | 25 ++++ 10 files changed, 453 insertions(+), 13 deletions(-) create mode 100644 src/config.h.in create mode 100644 src/tomahawkapp_mac.h create mode 100644 src/tomahawkapp_mac.mm create mode 100644 src/tomahawkapp_macdelegate.h diff --git a/admin/mac/Info.plist b/admin/mac/Info.plist index 3187e4438..e1114d48c 100644 --- a/admin/mac/Info.plist +++ b/admin/mac/Info.plist @@ -23,6 +23,36 @@ CFBundleName Tomahawk LSMinimumSystemVersion - 10.5.0 + 10.5.0 + CFBundleURLTypes + + + CFBundleURLName + Tomahawk URL + CFBundleURLSchemes + + tomahawk + + + + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + xspf + + CFBundleTypeIconFile + Generic.icns + CFBundleTypeMIMETypes + + application/xspf+xml + + CFBundleTypeName + XSPF Playlist + CFBundleTypeRole + Viewer + + diff --git a/include/tomahawk/tomahawkapp.h b/include/tomahawk/tomahawkapp.h index 7f0fc2005..a7be72230 100644 --- a/include/tomahawk/tomahawkapp.h +++ b/include/tomahawk/tomahawkapp.h @@ -4,6 +4,7 @@ #define APP TomahawkApp::instance() #include "headlesscheck.h" +#include "tomahawkapp_mac.h" // for PlatforInterface #include #include @@ -47,7 +48,7 @@ class TomahawkWindow; // this also acts as a a container for important top-level objects // that other parts of the app need to find // (eg, library, pipeline, friends list) -class TomahawkApp : public TOMAHAWK_APPLICATION +class TomahawkApp : public TOMAHAWK_APPLICATION, public Tomahawk::PlatformInterface { Q_OBJECT @@ -69,6 +70,10 @@ public: void addScriptResolver( const QString& scriptPath ); void removeScriptResolver( const QString& scriptPath ); + // PlatformInterface + virtual void activate(); + virtual bool loadUrl( const QString& url ); + signals: void settingsChanged(); diff --git a/src/CMakeLists.osx.txt b/src/CMakeLists.osx.txt index 77590e8b5..256e34746 100644 --- a/src/CMakeLists.osx.txt +++ b/src/CMakeLists.osx.txt @@ -2,6 +2,31 @@ SET( OS_SPECIFIC_LINK_LIBRARIES ${OS_SPECIFIC_LINK_LIBRARIES} ${COREAUDIO_LIBRARY} ${COREFOUNDATION_LIBRARY} + + /System/Library/Frameworks/AppKit.framework + /System/Library/Frameworks/Carbon.framework + /System/Library/Frameworks/DiskArbitration.framework + /System/Library/Frameworks/Foundation.framework + /System/Library/Frameworks/IOKit.framework + rtaudio tomahawklib ) + +if (APPLE) +# find_library(GROWL Growl) +# option(ENABLE_SPARKLE "Sparkle updating" ON) +# find_library(SPARKLE Sparkle) +# if (ENABLE_SPARKLE AND SPARKLE) +# set(HAVE_SPARKLE ON) +# endif (ENABLE_SPARKLE AND SPARKLE) + # Uses Darwin kernel version. + # 9.8.0 -> 10.5/Leopard + # 10.4.0 -> 10.6/Snow Leopard + string(REGEX MATCH "[0-9]+" DARWIN_VERSION ${CMAKE_HOST_SYSTEM_VERSION}) + if (DARWIN_VERSION GREATER 9) + SET(SNOW_LEOPARD 1) + elseif (DARWIN_VERSION GREATER 8) + SET(LEOPARD 1) + endif (DARWIN_VERSION GREATER 9) +endif (APPLE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d486966e0..b3d616e0a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,6 +57,12 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui} tomahawkwindow.cpp ) + +IF( APPLE ) + SET( tomahawkHeaders ${tomahawkHeaders} tomahawkapp_mac.h ) + SET( tomahawkSources ${tomahawkSources} tomahawkapp_mac.mm ) +ENDIF( APPLE ) + SET( tomahawkHeaders ${tomahawkHeaders} "${TOMAHAWK_INC_DIR}/tomahawk/tomahawkapp.h" "${TOMAHAWK_INC_DIR}/tomahawk/infosystem.h" @@ -138,6 +144,9 @@ kde4_add_app_icon( tomahawkSources "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/to qt4_add_resources( RC_SRCS "../resources.qrc" ) qt4_wrap_cpp( tomahawkMoc ${tomahawkHeaders} ) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h) + SET( final_src ${final_src} ${tomahawkMoc} ${tomahawkSources} ${tomahawkHeaders} ) IF( "${gui}" STREQUAL "no" ) @@ -152,6 +161,8 @@ IF( UNIX AND NOT APPLE ) ENDIF( UNIX AND NOT APPLE ) IF( APPLE ) ADD_EXECUTABLE( tomahawk MACOSX_BUNDLE ${final_src} ) + SET_TARGET_PROPERTIES(tomahawk PROPERTIES MACOSX_BUNDLE_INFO_PLIST "../admin/mac/Info.plist" +) ENDIF( APPLE ) IF( WIN32 ) ADD_EXECUTABLE( tomahawk ${final_src} ) diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 000000000..a06d239a5 --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,10 @@ +#ifndef CONFIG_H_IN +#define CONFIG_H_IN + +#define CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" + +#cmakedefine SNOW_LEOPARD +#cmakedefine LEOPARD +#cmakedefine HAVE_SPARKLE + +#endif // CONFIG_H_IN diff --git a/src/main.cpp b/src/main.cpp index 4519a116e..d755703d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,24 @@ #include "tomahawk/tomahawkapp.h" +#ifdef Q_WS_MAC +#include "tomahawkapp_mac.h" +#include +static pascal OSErr appleEventHandler( const AppleEvent*, AppleEvent*, long ); +#endif + #include int main( int argc, char *argv[] ) { +#ifdef Q_WS_MAC + // Do Mac specific startup to get media keys working. + // This must go before QApplication initialisation. + Tomahawk::macMain(); + + // used for url handler + AEEventHandlerUPP h = AEEventHandlerUPP( appleEventHandler ); + AEInstallEventHandler( 'GURL', 'GURL', h, 0, false ); + +#endif try { TomahawkApp a( argc, argv ); return a.exec(); @@ -10,3 +26,31 @@ int main( int argc, char *argv[] ) return 0; } } + +#ifdef Q_WS_MAC +static pascal OSErr appleEventHandler( const AppleEvent* e, AppleEvent*, long ) +{ + OSType id = typeWildCard; + AEGetAttributePtr( e, keyEventIDAttr, typeType, 0, &id, sizeof(id), 0 ); + + switch (id) + { + case 'GURL': + { + DescType type; + Size size; + + char buf[1024]; + AEGetParamPtr( e, keyDirectObject, typeChar, &type, &buf, 1023, &size ); + buf[size] = '\0'; + + QString url = QString::fromUtf8( buf ); + static_cast(qApp)->loadUrl( url ); + return noErr; + } + + default: + return unimpErr; + } +} +#endif diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 30cba6dcc..b865d7b4d 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "artist.h" #include "album.h" @@ -31,6 +33,10 @@ #include #endif +#ifdef Q_WS_MAC + #include "tomahawkapp_mac.h" +#endif + #include #include @@ -176,6 +182,10 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) TomahawkUtils::setNam( new QNetworkAccessManager ); #endif +#ifdef Q_WS_MAC + Tomahawk::setApplicationHandler( this ); +#endif + // Set up proxy if( TomahawkSettings::instance()->proxyType() != QNetworkProxy::NoProxy && !TomahawkSettings::instance()->proxyHost().isEmpty() ) @@ -454,16 +464,20 @@ TomahawkApp::setupSIP() } } -void -TomahawkApp::messageReceived( const QString& msg ) + +void +TomahawkApp::activate() { - qDebug() << "MESSAGE RECEIVED" << msg; - if( msg.isEmpty() ) { - return; - } - - if( msg.contains( "tomahawk://" ) ) { - QString cmd = msg.mid( 11 ); +#ifndef TOMAHAWK_HEADLESS + mainWindow()->show(); +#endif +} + +bool +TomahawkApp::loadUrl( const QString& url ) +{ + if( url.contains( "tomahawk://" ) ) { + QString cmd = url.mid( 11 ); qDebug() << "tomahawk!s" << cmd; if( cmd.startsWith( "load/" ) ) { cmd = cmd.mid( 5 ); @@ -474,7 +488,26 @@ TomahawkApp::messageReceived( const QString& msg ) l->load( QUrl( cmd.mid( 5 ) ) ); } } - - } + } else { + QFile f( url ); + QFileInfo info( f ); + if( f.exists() && info.suffix() == "xspf" ) { + XSPFLoader* l = new XSPFLoader( true, this ); + qDebug() << "Loading spiff:" << url; + l->load( QUrl( url ) ); + } + } + return true; +} + +void +TomahawkApp::messageReceived( const QString& msg ) +{ + qDebug() << "MESSAGE RECEIVED" << msg; + if( msg.isEmpty() ) { + return; + } + + loadUrl( msg ); } diff --git a/src/tomahawkapp_mac.h b/src/tomahawkapp_mac.h new file mode 100644 index 000000000..ce4199677 --- /dev/null +++ b/src/tomahawkapp_mac.h @@ -0,0 +1,28 @@ +#ifndef TOMAHAWKAPP_MAC_H +#define TOMAHAWKAPP_MAC_H + +// this file and tomahawk_app.mm copied and inspired by mac_startup.* in clementine player, +// copyright David Sansome 2010 + +class QString; + +namespace Tomahawk { + +/// Interface between cocoa and tomahawk +class PlatformInterface { + public: + // Called when the application should show itself. + virtual void activate() = 0; + virtual bool loadUrl( const QString& url ) = 0; + + virtual ~PlatformInterface() {} +}; + +void macMain(); +//void setShortcutHandler(GlobalShortcuts* handler); +// used for opening files with tomahawk +void setApplicationHandler(PlatformInterface* handler); + +}; + +#endif diff --git a/src/tomahawkapp_mac.mm b/src/tomahawkapp_mac.mm new file mode 100644 index 000000000..dfc08c34b --- /dev/null +++ b/src/tomahawkapp_mac.mm @@ -0,0 +1,229 @@ +#include "tomahawkapp_mac.h" +#include "tomahawkapp_macdelegate.h" +#include + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +// Capture global media keys on Mac (Cocoa only!) +// See: http://www.rogueamoeba.com/utm/2007/09/29/apple-keyboard-media-key-event-handling/ + +@interface MacApplication :NSApplication { + // MacGlobalShortcutBackend* shortcut_handler_; + Tomahawk::PlatformInterface* application_handler_; +} + +//- (MacGlobalShortcutBackend*) shortcut_handler; +//- (void) SetShortcutHandler: (MacGlobalShortcutBackend*)handler; + +- (Tomahawk::PlatformInterface*) application_handler; +- (void) SetApplicationHandler: (Tomahawk::PlatformInterface*)handler; +- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; +//- (void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat; +@end + + +@implementation AppDelegate + +- (id) init { + if ((self = [super init])) { + application_handler_ = nil; +// dock_menu_ = nil; + } + return self; +} + +- (id) initWithHandler: (Tomahawk::PlatformInterface*)handler { + application_handler_ = handler; + return self; +} + +- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag { + if (application_handler_) { + application_handler_->activate(); + } + return YES; +} +/* +- (void) setDockMenu: (NSMenu*)menu { + dock_menu_ = menu; +} + +- (NSMenu*) applicationDockMenu: (NSApplication*)sender { + return dock_menu_; +} +*/ +- (BOOL) application: (NSApplication*)app openFile:(NSString*)filename { + qDebug() << "Wants to open:" << [filename UTF8String]; + + if (application_handler_->loadUrl(QString::fromUtf8([filename UTF8String]))) { + return YES; + } + + return NO; +} +@end + +@implementation MacApplication + +- (id) init { + if ((self = [super init])) { +// [self SetShortcutHandler:nil]; + [self SetApplicationHandler:nil]; + + NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager]; + [em + setEventHandler:self + andSelector:@selector(getUrl:withReplyEvent:) + forEventClass:kInternetEventClass + andEventID:kAEGetURL]; + [em + setEventHandler:self + andSelector:@selector(getUrl:withReplyEvent:) + forEventClass:'WWW!' + andEventID:'OURL']; + NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; + OSStatus httpResult = LSSetDefaultHandlerForURLScheme((CFStringRef)@"tomahawk", (CFStringRef)bundleID); + //TODO: Check httpResult and httpsResult for errors + } + return self; +} +/* +- (MacGlobalShortcutBackend*) shortcut_handler { + return shortcut_handler_; +} + +- (void) SetShortcutHandler: (MacGlobalShortcutBackend*)handler { + shortcut_handler_ = handler; +} +*/ +- (Tomahawk::PlatformInterface*) application_handler { + return application_handler_; +} + +- (void) SetApplicationHandler: (Tomahawk::PlatformInterface*)handler { + AppDelegate* delegate = [[AppDelegate alloc] initWithHandler:handler]; + [self setDelegate:delegate]; +} + +-(void) sendEvent: (NSEvent*)event { + if ([event type] == NSSystemDefined && [event subtype] == 8) { + int keycode = (([event data1] & 0xFFFF0000) >> 16); + int keyflags = ([event data1] & 0x0000FFFF); + int keystate = (((keyflags & 0xFF00) >> 8)) == 0xA; + int keyrepeat = (keyflags & 0x1); + + //[self mediaKeyEvent: keycode state: keystate repeat: keyrepeat]; + } + + [super sendEvent: event]; +} +/* +-(void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat { + if (!shortcut_handler_) { + return; + } + if (state == 0) { + shortcut_handler_->MacMediaKeyPressed(key); + } +} */ + +- (void)getUrl:(NSAppleEventDescriptor *)event + withReplyEvent:(NSAppleEventDescriptor *)replyEvent +{ + // Get the URL + NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject] + stringValue]; + qDebug() << "Wants to open:" << [urlStr UTF8String]; + + //TODO: Your custom URL handling code here +} + +@end + +void Tomahawk::macMain() { + [[NSAutoreleasePool alloc] init]; + // Creates and sets the magic global variable so QApplication will find it. + [MacApplication sharedApplication]; + #ifdef HAVE_SPARKLE + // Creates and sets the magic global variable for Sparkle. + [[SUUpdater sharedUpdater] setDelegate: NSApp]; + #endif +} + +/* +void setShortcutHandler(MacGlobalShortcutBackend* handler) { + [NSApp SetShortcutHandler: handler]; +} +*/ +void Tomahawk::setApplicationHandler(Tomahawk::PlatformInterface* handler) { + [NSApp SetApplicationHandler: handler]; +} + +void CheckForUpdates() { + #ifdef HAVE_SPARKLE + [[SUUpdater sharedUpdater] checkForUpdates: NSApp]; + #endif +} + +QString GetBundlePath() { + CFURLRef app_url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFStringRef mac_path = CFURLCopyFileSystemPath(app_url, kCFURLPOSIXPathStyle); + const char* path = CFStringGetCStringPtr(mac_path, CFStringGetSystemEncoding()); + QString bundle_path = QString::fromUtf8(path); + CFRelease(app_url); + CFRelease(mac_path); + return bundle_path; +} + +QString GetResourcesPath() { + QString bundle_path = GetBundlePath(); + return bundle_path + "/Contents/Resources"; +} + +QString GetApplicationSupportPath() { + NSAutoreleasePool* pool = [NSAutoreleasePool alloc]; + [pool init]; + NSArray* paths = NSSearchPathForDirectoriesInDomains( + NSApplicationSupportDirectory, + NSUserDomainMask, + YES); + QString ret; + if ([paths count] > 0) { + NSString* user_path = [paths objectAtIndex:0]; + ret = QString::fromUtf8([user_path UTF8String]); + } else { + ret = "~/Library/Application Support"; + } + [pool drain]; + return ret; +} + +QString GetMusicDirectory() { + NSAutoreleasePool* pool = [NSAutoreleasePool alloc]; + [pool init]; + NSArray* paths = NSSearchPathForDirectoriesInDomains( + NSMusicDirectory, + NSUserDomainMask, + YES); + QString ret; + if ([paths count] > 0) { + NSString* user_path = [paths objectAtIndex:0]; + ret = QString::fromUtf8([user_path UTF8String]); + } else { + ret = "~/Music"; + } + [pool drain]; + return ret; +} + diff --git a/src/tomahawkapp_macdelegate.h b/src/tomahawkapp_macdelegate.h new file mode 100644 index 000000000..a5884e225 --- /dev/null +++ b/src/tomahawkapp_macdelegate.h @@ -0,0 +1,25 @@ +#import + +#include "config.h" + +// this file copied and inspired by mac_startup.* in clementine player, +// copyright David Sansome 2010 +namespace Tomahawk { + class PlatformInterface; +} + +#ifdef SNOW_LEOPARD +@interface AppDelegate : NSObject { +#else +@interface AppDelegate : NSObject { +#endif + Tomahawk::PlatformInterface* application_handler_; + //NSMenu* dock_menu_; +} + +- (id) initWithHandler: (Tomahawk::PlatformInterface*)handler; +// NSApplicationDelegate +- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag; +//- (NSMenu*) applicationDockMenu: (NSApplication*)sender; +//- (void) setDockMenu: (NSMenu*)menu; +@end From 1647293adadd24e670bb5144d1965d34ffca1fdb Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 13 Feb 2011 23:57:25 -0500 Subject: [PATCH 11/12] Add some shortcuts for mac Fix osx shortcuts --- include/tomahawk/tomahawkapp.h | 4 +- src/CMakeLists.txt | 7 ++- src/libtomahawk/audio/audioengine.cpp | 14 ++++++ src/libtomahawk/audio/audioengine.h | 2 + src/mac/macshortcuthandler.cpp | 31 ++++++++++++ src/mac/macshortcuthandler.h | 22 ++++++++ src/{ => mac}/tomahawkapp_mac.h | 4 +- src/{ => mac}/tomahawkapp_mac.mm | 72 +++++++++------------------ src/shortcuthandler.cpp | 13 +++++ src/shortcuthandler.h | 34 +++++++++++++ src/tomahawkapp.cpp | 66 ++++++++++++++---------- 11 files changed, 192 insertions(+), 77 deletions(-) create mode 100644 src/mac/macshortcuthandler.cpp create mode 100644 src/mac/macshortcuthandler.h rename src/{ => mac}/tomahawkapp_mac.h (86%) rename src/{ => mac}/tomahawkapp_mac.mm (69%) create mode 100644 src/shortcuthandler.cpp create mode 100644 src/shortcuthandler.h diff --git a/include/tomahawk/tomahawkapp.h b/include/tomahawk/tomahawkapp.h index a7be72230..be8e7d16b 100644 --- a/include/tomahawk/tomahawkapp.h +++ b/include/tomahawk/tomahawkapp.h @@ -4,7 +4,7 @@ #define APP TomahawkApp::instance() #include "headlesscheck.h" -#include "tomahawkapp_mac.h" // for PlatforInterface +#include "mac/tomahawkapp_mac.h" // for PlatforInterface #include #include @@ -29,6 +29,7 @@ class XMPPBot; namespace Tomahawk { + class ShortcutHandler; namespace InfoSystem { class InfoSystem; @@ -99,6 +100,7 @@ private: SipHandler* m_sipHandler; Servent* m_servent; XMPPBot* m_xmppBot; + Tomahawk::ShortcutHandler* m_shortcutHandler; #ifndef NO_LIBLASTFM Scrobbler* m_scrobbler; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3d616e0a..b97f30412 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ SET( tomahawkSources ${tomahawkSources} musicscanner.cpp scriptresolver.cpp scrobbler.cpp + shortcuthandler.cpp tomahawkapp.cpp main.cpp @@ -59,8 +60,8 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui} IF( APPLE ) - SET( tomahawkHeaders ${tomahawkHeaders} tomahawkapp_mac.h ) - SET( tomahawkSources ${tomahawkSources} tomahawkapp_mac.mm ) + SET( tomahawkHeaders ${tomahawkHeaders} mac/tomahawkapp_mac.h mac/macshortcuthandler.h ) + SET( tomahawkSources ${tomahawkSources} mac/tomahawkapp_mac.mm mac/macshortcuthandler.cpp ) ENDIF( APPLE ) SET( tomahawkHeaders ${tomahawkHeaders} @@ -78,6 +79,7 @@ SET( tomahawkHeaders ${tomahawkHeaders} musicscanner.h scriptresolver.h scrobbler.h + shortcuthandler.h ) SET( tomahawkHeadersGui ${tomahawkHeadersGui} @@ -115,6 +117,7 @@ INCLUDE_DIRECTORIES( topbar utils libtomahawk + mac ../alsa-playback ../rtaudio diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index 7ebbf9197..7231e3a72 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -62,6 +62,15 @@ AudioEngine::~AudioEngine() delete m_audio; } +void +AudioEngine::playPause() +{ + if( m_audio->isPlaying() ) + pause(); + else + play(); + +} void AudioEngine::play() @@ -141,6 +150,11 @@ AudioEngine::setVolume( int percentage ) emit volumeChanged( percentage ); } +void +AudioEngine::mute() +{ + setVolume( 0 ); +} void AudioEngine::onTrackAboutToClose() diff --git a/src/libtomahawk/audio/audioengine.h b/src/libtomahawk/audio/audioengine.h index e763c9235..a94a5359b 100644 --- a/src/libtomahawk/audio/audioengine.h +++ b/src/libtomahawk/audio/audioengine.h @@ -40,6 +40,7 @@ public: PlaylistInterface* playlist() const { return m_playlist; } public slots: + void playPause(); void play(); void pause(); void stop(); @@ -51,6 +52,7 @@ public slots: void lowerVolume() { setVolume( volume() - AUDIO_VOLUME_STEP ); } void raiseVolume() { setVolume( volume() + AUDIO_VOLUME_STEP ); } void onVolumeChanged( float volume ) { emit volumeChanged( volume * 100 ); } + void mute(); void playItem( PlaylistInterface* playlist, const Tomahawk::result_ptr& result ); void setPlaylist( PlaylistInterface* playlist ) { m_playlist = playlist; } diff --git a/src/mac/macshortcuthandler.cpp b/src/mac/macshortcuthandler.cpp new file mode 100644 index 000000000..80bc64815 --- /dev/null +++ b/src/mac/macshortcuthandler.cpp @@ -0,0 +1,31 @@ +#include "macshortcuthandler.h" + +#include +#include + +using namespace Tomahawk; + +MacShortcutHandler::MacShortcutHandler(QObject *parent) : + Tomahawk::ShortcutHandler(parent) +{ + +} + +void +MacShortcutHandler::macMediaKeyPressed( int key ) +{ + switch (key) { + case NX_KEYTYPE_PLAY: + qDebug() << "emitting PlayPause pressed"; + emit playPause(); + break; + case NX_KEYTYPE_FAST: + qDebug() << "emitting next pressed"; + emit next(); + break; + case NX_KEYTYPE_REWIND: + qDebug() << "emitting prev pressed"; + emit previous(); + break; + } +} diff --git a/src/mac/macshortcuthandler.h b/src/mac/macshortcuthandler.h new file mode 100644 index 000000000..014d71421 --- /dev/null +++ b/src/mac/macshortcuthandler.h @@ -0,0 +1,22 @@ +#ifndef MACSHORTCUTHANDLER_H +#define MACSHORTCUTHANDLER_H + +#include "shortcuthandler.h" + +#include + +namespace Tomahawk { + + +class MacShortcutHandler : public ShortcutHandler +{ + Q_OBJECT +public: + explicit MacShortcutHandler(QObject *parent = 0); + + void macMediaKeyPressed( int key ); +}; + +} + +#endif // MACSHORTCUTHANDLER_H diff --git a/src/tomahawkapp_mac.h b/src/mac/tomahawkapp_mac.h similarity index 86% rename from src/tomahawkapp_mac.h rename to src/mac/tomahawkapp_mac.h index ce4199677..c242b2e0a 100644 --- a/src/tomahawkapp_mac.h +++ b/src/mac/tomahawkapp_mac.h @@ -8,6 +8,8 @@ class QString; namespace Tomahawk { +class MacShortcutHandler; + /// Interface between cocoa and tomahawk class PlatformInterface { public: @@ -19,7 +21,7 @@ class PlatformInterface { }; void macMain(); -//void setShortcutHandler(GlobalShortcuts* handler); +void setShortcutHandler(Tomahawk::MacShortcutHandler* engine); // used for opening files with tomahawk void setApplicationHandler(PlatformInterface* handler); diff --git a/src/tomahawkapp_mac.mm b/src/mac/tomahawkapp_mac.mm similarity index 69% rename from src/tomahawkapp_mac.mm rename to src/mac/tomahawkapp_mac.mm index dfc08c34b..cf60300b0 100644 --- a/src/tomahawkapp_mac.mm +++ b/src/mac/tomahawkapp_mac.mm @@ -1,5 +1,6 @@ #include "tomahawkapp_mac.h" #include "tomahawkapp_macdelegate.h" +#include "macshortcuthandler.h" #include #import @@ -19,17 +20,17 @@ // See: http://www.rogueamoeba.com/utm/2007/09/29/apple-keyboard-media-key-event-handling/ @interface MacApplication :NSApplication { - // MacGlobalShortcutBackend* shortcut_handler_; + Tomahawk::MacShortcutHandler* shortcut_handler_; Tomahawk::PlatformInterface* application_handler_; } -//- (MacGlobalShortcutBackend*) shortcut_handler; -//- (void) SetShortcutHandler: (MacGlobalShortcutBackend*)handler; +- (Tomahawk::MacShortcutHandler*) shortcutHandler; +- (void) setShortcutHandler: (Tomahawk::MacShortcutHandler*)handler; - (Tomahawk::PlatformInterface*) application_handler; -- (void) SetApplicationHandler: (Tomahawk::PlatformInterface*)handler; -- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; -//- (void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat; +- (void) setApplicationHandler: (Tomahawk::PlatformInterface*)handler; +- (void) getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; +- (void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat; @end @@ -78,40 +79,26 @@ - (id) init { if ((self = [super init])) { -// [self SetShortcutHandler:nil]; - [self SetApplicationHandler:nil]; - - NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager]; - [em - setEventHandler:self - andSelector:@selector(getUrl:withReplyEvent:) - forEventClass:kInternetEventClass - andEventID:kAEGetURL]; - [em - setEventHandler:self - andSelector:@selector(getUrl:withReplyEvent:) - forEventClass:'WWW!' - andEventID:'OURL']; - NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; - OSStatus httpResult = LSSetDefaultHandlerForURLScheme((CFStringRef)@"tomahawk", (CFStringRef)bundleID); - //TODO: Check httpResult and httpsResult for errors + [self setShortcutHandler:nil]; + [self setApplicationHandler:nil]; } return self; } -/* -- (MacGlobalShortcutBackend*) shortcut_handler { - return shortcut_handler_; + +- (Tomahawk::MacShortcutHandler*) shortcutHandler { + return shortcut_handler_; } -- (void) SetShortcutHandler: (MacGlobalShortcutBackend*)handler { +- (void) setShortcutHandler: (Tomahawk::MacShortcutHandler*)handler { + qDebug() << "Setting shortcut handler of MacAPp"; shortcut_handler_ = handler; } -*/ + - (Tomahawk::PlatformInterface*) application_handler { return application_handler_; } -- (void) SetApplicationHandler: (Tomahawk::PlatformInterface*)handler { +- (void) setApplicationHandler: (Tomahawk::PlatformInterface*)handler { AppDelegate* delegate = [[AppDelegate alloc] initWithHandler:handler]; [self setDelegate:delegate]; } @@ -123,30 +110,19 @@ int keystate = (((keyflags & 0xFF00) >> 8)) == 0xA; int keyrepeat = (keyflags & 0x1); - //[self mediaKeyEvent: keycode state: keystate repeat: keyrepeat]; + [self mediaKeyEvent: keycode state: keystate repeat: keyrepeat]; } [super sendEvent: event]; } -/* + -(void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat { if (!shortcut_handler_) { return; } if (state == 0) { - shortcut_handler_->MacMediaKeyPressed(key); + shortcut_handler_->macMediaKeyPressed(key); } -} */ - -- (void)getUrl:(NSAppleEventDescriptor *)event - withReplyEvent:(NSAppleEventDescriptor *)replyEvent -{ - // Get the URL - NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject] - stringValue]; - qDebug() << "Wants to open:" << [urlStr UTF8String]; - - //TODO: Your custom URL handling code here } @end @@ -161,13 +137,13 @@ void Tomahawk::macMain() { #endif } -/* -void setShortcutHandler(MacGlobalShortcutBackend* handler) { - [NSApp SetShortcutHandler: handler]; + +void Tomahawk::setShortcutHandler(Tomahawk::MacShortcutHandler* handler) { + [NSApp setShortcutHandler: handler]; } -*/ + void Tomahawk::setApplicationHandler(Tomahawk::PlatformInterface* handler) { - [NSApp SetApplicationHandler: handler]; + [NSApp setApplicationHandler: handler]; } void CheckForUpdates() { diff --git a/src/shortcuthandler.cpp b/src/shortcuthandler.cpp new file mode 100644 index 000000000..7709789ca --- /dev/null +++ b/src/shortcuthandler.cpp @@ -0,0 +1,13 @@ +#include "shortcuthandler.h" + +using namespace Tomahawk; + +ShortcutHandler::ShortcutHandler( QObject *parent ) + : QObject( parent ) +{ + +} + + ShortcutHandler::~ShortcutHandler() + { + } diff --git a/src/shortcuthandler.h b/src/shortcuthandler.h new file mode 100644 index 000000000..6462c0ebf --- /dev/null +++ b/src/shortcuthandler.h @@ -0,0 +1,34 @@ +#ifndef SHORTCUTHANDLER_H +#define SHORTCUTHANDLER_H + +#include + +namespace Tomahawk { +/** + Base class for various shortcut plugins on different platforms + */ +class ShortcutHandler : public QObject +{ + Q_OBJECT +public: + virtual ~ShortcutHandler(); + +signals: + // add more as needed + void playPause(); + void pause(); + void stop(); + void previous(); + void next(); + + void volumeUp(); + void volumeDown(); + void mute(); +protected: + explicit ShortcutHandler( QObject *parent = 0 ); + +}; + +} + +#endif // SHORTCUTHANDLER_H diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index b865d7b4d..1b0757389 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -24,8 +24,11 @@ #include "web/api_v1.h" #include "scriptresolver.h" #include "sourcelist.h" +#include "shortcuthandler.h" +#include "tomahawksettings.h" #include "audio/audioengine.h" +#include "utils/xspfloader.h" #ifndef TOMAHAWK_HEADLESS #include "tomahawkwindow.h" @@ -34,7 +37,7 @@ #endif #ifdef Q_WS_MAC - #include "tomahawkapp_mac.h" +#include "mac/macshortcuthandler.h" #endif #include @@ -42,8 +45,6 @@ #define LOGFILE TomahawkUtils::appDataDir().filePath( "tomahawk.log" ).toLocal8Bit() #define LOGFILE_SIZE 1024 * 512 -#include "tomahawksettings.h" -#include using namespace std; ofstream logfile; @@ -114,6 +115,7 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) , m_audioEngine( 0 ) , m_sipHandler( 0 ) , m_servent( 0 ) + , m_shortcutHandler( 0 ) , m_mainwindow( 0 ) , m_infoSystem( 0 ) { @@ -160,35 +162,49 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) qDebug() << "Init Echonest Factory."; GeneratorFactory::registerFactory( "echonest", new EchonestFactory ); -#ifndef NO_LIBLASTFM - qDebug() << "Init Scrobbler."; - m_scrobbler = new Scrobbler( this ); - qDebug() << "Setting NAM."; - TomahawkUtils::setNam( new lastfm::NetworkAccessManager( this ) ); + // Register shortcut handler for this platform +#ifdef Q_WS_MAC + m_shortcutHandler = new MacShortcutHandler( this ); + Tomahawk::setShortcutHandler( static_cast( m_shortcutHandler) ); - connect( m_audioEngine, SIGNAL( started( const Tomahawk::result_ptr& ) ), - m_scrobbler, SLOT( trackStarted( const Tomahawk::result_ptr& ) ), Qt::QueuedConnection ); - - connect( m_audioEngine, SIGNAL( paused() ), - m_scrobbler, SLOT( trackPaused() ), Qt::QueuedConnection ); - - connect( m_audioEngine, SIGNAL( resumed() ), - m_scrobbler, SLOT( trackResumed() ), Qt::QueuedConnection ); - - connect( m_audioEngine, SIGNAL( stopped() ), - m_scrobbler, SLOT( trackStopped() ), Qt::QueuedConnection ); -#else - qDebug() << "Setting NAM."; - TomahawkUtils::setNam( new QNetworkAccessManager ); + Tomahawk::setApplicationHandler( this ); #endif -#ifdef Q_WS_MAC - Tomahawk::setApplicationHandler( this ); + // Connect up shortcuts + connect( m_shortcutHandler, SIGNAL( playPause() ), m_audioEngine, SLOT( playPause() ) ); + connect( m_shortcutHandler, SIGNAL( pause() ), m_audioEngine, SLOT( pause() ) ); + connect( m_shortcutHandler, SIGNAL( stop() ), m_audioEngine, SLOT( stop() ) ); + connect( m_shortcutHandler, SIGNAL( previous() ), m_audioEngine, SLOT( previous() ) ); + connect( m_shortcutHandler, SIGNAL( next() ), m_audioEngine, SLOT( next() ) ); + connect( m_shortcutHandler, SIGNAL( volumeUp() ), m_audioEngine, SLOT( raiseVolume() ) ); + connect( m_shortcutHandler, SIGNAL( volumeDown() ), m_audioEngine, SLOT( lowerVolume() ) ); + connect( m_shortcutHandler, SIGNAL( mute() ), m_audioEngine, SLOT( mute() ) ); + +#ifndef NO_LIBLASTFM + qDebug() << "Init Scrobbler."; + m_scrobbler = new Scrobbler( this ); + qDebug() << "Setting NAM."; + TomahawkUtils::setNam( new lastfm::NetworkAccessManager( this ) ); + + connect( m_audioEngine, SIGNAL( started( const Tomahawk::result_ptr& ) ), + m_scrobbler, SLOT( trackStarted( const Tomahawk::result_ptr& ) ), Qt::QueuedConnection ); + + connect( m_audioEngine, SIGNAL( paused() ), + m_scrobbler, SLOT( trackPaused() ), Qt::QueuedConnection ); + + connect( m_audioEngine, SIGNAL( resumed() ), + m_scrobbler, SLOT( trackResumed() ), Qt::QueuedConnection ); + + connect( m_audioEngine, SIGNAL( stopped() ), + m_scrobbler, SLOT( trackStopped() ), Qt::QueuedConnection ); +#else + qDebug() << "Setting NAM."; + TomahawkUtils::setNam( new QNetworkAccessManager ); #endif // Set up proxy if( TomahawkSettings::instance()->proxyType() != QNetworkProxy::NoProxy && - !TomahawkSettings::instance()->proxyHost().isEmpty() ) + !TomahawkSettings::instance()->proxyHost().isEmpty() ) { qDebug() << "Setting proxy to saved values"; TomahawkUtils::setProxy( new QNetworkProxy( static_cast(TomahawkSettings::instance()->proxyType()), TomahawkSettings::instance()->proxyHost(), TomahawkSettings::instance()->proxyPort(), TomahawkSettings::instance()->proxyUsername(), TomahawkSettings::instance()->proxyPassword() ) ); From 6fa87ebea5c61af54bebf50f688495e9b344a8dc Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 14 Feb 2011 18:52:18 +0100 Subject: [PATCH 12/12] * This should hopefully fix CLuceneError exceptions on Win32. --- src/libtomahawk/database/fuzzyindex.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libtomahawk/database/fuzzyindex.cpp b/src/libtomahawk/database/fuzzyindex.cpp index 5f0c62e40..1a6cdb724 100644 --- a/src/libtomahawk/database/fuzzyindex.cpp +++ b/src/libtomahawk/database/fuzzyindex.cpp @@ -46,6 +46,11 @@ FuzzyIndex::beginIndexing() { m_mutex.lock(); + delete m_luceneSearcher; + delete m_luceneReader; + m_luceneSearcher = 0; + m_luceneReader = 0; + try { IndexWriter luceneWriter = IndexWriter( m_luceneDir, m_analyzer, true ); @@ -71,11 +76,6 @@ FuzzyIndex::appendFields( const QString& table, const QMap< unsigned int, QStrin { try { - delete m_luceneSearcher; - delete m_luceneReader; - m_luceneSearcher = 0; - m_luceneReader = 0; - bool create = !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ); IndexWriter luceneWriter = IndexWriter( m_luceneDir, m_analyzer, create ); Document doc;