1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-09-06 12:10:47 +02:00

Compare commits

...

23 Commits

Author SHA1 Message Date
Dominik Schmidt
45cc0652d9 Stop crashing when changing shown collection in qml 2011-09-10 05:12:09 +02:00
Dominik Schmidt
6df1b9462f Don't load QML in an undefined state 2011-09-08 04:25:42 +02:00
Dominik Schmidt
cbb44907f4 Add possibility to start songs from QML 2011-09-08 04:12:16 +02:00
Dominik Schmidt
7185b4e778 Whoops 2011-09-08 02:54:07 +02:00
Dominik Schmidt
a0c3806da7 Expose name and isPlaying status in TreeModel 2011-09-07 09:31:53 +02:00
Dominik Schmidt
0d0f9be3f2 Expose currently selected collection to qml 2011-09-07 08:51:21 +02:00
Dominik Schmidt
048c82ac24 Add lazyload getters for models to the ViewManager. 2011-09-07 08:50:39 +02:00
Dominik Schmidt
d49ce2f242 Allow changing current view from qml 2011-09-07 07:23:46 +02:00
Dominik Schmidt
354f1f8f2e Expose DisplayRole as name in sourcesModel 2011-09-07 06:59:24 +02:00
Dominik Schmidt
2472171e8e Expose sourcesModel to QML 2011-09-07 06:13:51 +02:00
Dominik Schmidt
f5b0c35274 Share one trayIcon across all windows 2011-09-07 06:12:07 +02:00
Dominik Schmidt
5ea4b28ad4 Show artist and track in TomahawkTouchWindow title too 2011-09-07 06:02:44 +02:00
Dominik Schmidt
58f239b3a9 Rename TomahawkWindowDeclarative to TomahawkTouchWindow and make it a subclass of TomahawkWindow 2011-09-07 05:38:58 +02:00
Dominik Schmidt
769be854fa Initialize ViewManager before SourcesModel 2011-09-07 05:26:36 +02:00
Dominik Schmidt
a6013ef411 Move SourcesModel initialization to TomahawkWindow 2011-09-07 04:10:20 +02:00
Dominik Schmidt
c16528763f Fix regression where windowTitle was set empty 2011-09-07 02:58:11 +02:00
Dominik Schmidt
b8d684fed8 Split TomahawkWindow into TomahawkWindow and TomahawkDesktopWindow which now contains everything specific to the main tomahawk gui 2011-09-07 01:34:09 +02:00
Dominik Schmidt
1a2b7907d0 Fix cmake for clang 2011-09-06 23:45:09 +02:00
Dominik Schmidt
bcc5e01f8b Resolve undefined reference to play-slot in TomahawkWindowDeclarative 2011-09-06 22:53:06 +02:00
Dominik Schmidt
3e8bcabfbc Add TomahawkWindowDeclarative 2011-09-06 11:19:18 +02:00
Dominik Schmidt
c2cd281445 Expose GlobalActionManager::openLink to QML 2011-09-06 03:00:20 +02:00
Dominik Schmidt
9fdb0c9393 Expose audioEngine states to QML 2011-09-06 03:00:20 +02:00
Dominik Schmidt
fca061d9bc Add basic support for loading a qml gui 2011-09-06 03:00:19 +02:00
25 changed files with 1485 additions and 660 deletions

View File

@@ -24,6 +24,8 @@ SET( TOMAHAWK_VERSION_PATCH 99 )
# build options
option(BUILD_GUI "Build Tomahawk with GUI" ON)
option(BUILD_RELEASE "Generate TOMAHAWK_VERSION without GIT info" OFF)
option(BUILD_GUI_QML"Build Tomahawk with QML Support" OFF)
# generate version string
@@ -71,6 +73,11 @@ ELSE()
MESSAGE( STATUS "Building Tomahawk ${TOMAHAWK_VERSION} full GUI version ***" )
LIST(APPEND NEEDED_QT4_COMPONENTS "QtGui" "QtWebkit" )
ENDIF()
IF( BUILD_GUI_QML )
MESSAGE( STATUS "Building Tomahawk QML version ***" )
LIST(APPEND NEEDED_QT4_COMPONENTS "QtDeclarative" )
ENDIF()
IF( BUILD_GUI AND UNIX AND NOT APPLE )
FIND_PACKAGE( X11 )
@@ -158,9 +165,12 @@ macro_optional_find_package(KDE4Installed)
# macro_optional_find_package(KDE4)
IF(KDE4_FOUND)
#KDE4 adds and removes some compiler flags that we don't like
STRING( REPLACE "-std=iso9899:1990" "" CLEAN_C_FLAGS ${CMAKE_C_FLAGS} )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions" )
IF( CMAKE_C_FLAGS )
# KDE4 adds and removes some compiler flags that we don't like
# (only for gcc not for clang e.g.)
STRING( REPLACE "-std=iso9899:1990" "" CLEAN_C_FLAGS ${CMAKE_C_FLAGS} )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions" )
ENDIF()
ELSE()
SET( CLEAN_C_FLAGS ${CMAKE_C_FLAGS} )
ENDIF()

View File

@@ -78,6 +78,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
settingslistdelegate.cpp
resolversmodel.cpp
tomahawkwindow.cpp
tomahawkdesktopwindow.cpp
)
SET( tomahawkHeaders ${tomahawkHeaders}
@@ -126,10 +127,11 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
resolversmodel.h
delegateconfigwrapper.h
tomahawkwindow.h
tomahawkdesktopwindow.h
)
SET( tomahawkUI ${tomahawkUI}
tomahawkwindow.ui
tomahawkdesktopwindow.ui
diagnosticsdialog.ui
stackedsettingsdialog.ui
proxydialog.ui
@@ -238,7 +240,7 @@ IF(QCA2_FOUND)
SET(LINK_LIBRARIES ${LINK_LIBRARIES} ${QCA2_LIBRARIES} )
ENDIF(QCA2_FOUND)
TARGET_LINK_LIBRARIES( tomahawk
SET( tomahawkLinkLibraries
${LINK_LIBRARIES}
${TOMAHAWK_LIBRARIES}
${PHONON_LIBS}
@@ -251,6 +253,13 @@ TARGET_LINK_LIBRARIES( tomahawk
${TAGLIB_LIBRARIES}
)
TARGET_LINK_LIBRARIES( tomahawk ${tomahawkLinkLibraries} )
IF( BUILD_GUI_QML )
# sic! add_subdirectory would make it harder to reuse ${final_src}
INCLUDE( active/CMakeLists.txt )
ENDIF()
IF( APPLE )
IF(HAVE_SPARKLE)
MESSAGE("Sparkle Found, installing framekwork in bundle")

30
src/active/CMakeLists.txt Normal file
View File

@@ -0,0 +1,30 @@
SET( touchmahawkSources ${final_src} )
#LIST( REMOVE_ITEM touchmahawkSources "main.cpp" )
SET( touchmahawkHeaders
active/tomahawktouchwindow.h
)
SET( touchmahawkSources
${touchmahawkSources}
active/tomahawktouchwindow.cpp
# active/main.cpp
)
qt4_wrap_cpp( touchmahawkMoc ${touchmahawkHeaders} )
SET( touchmahawkFinalSources ${touchmahawkMoc} ${touchmahawkSources} )
SET( touchmahawkLinkLibraries
kdeclarative
${tomahawkLinkLibraries}
) #${QT_QTDECLARATIVE_LIBRARY}
ADD_EXECUTABLE( active-tomahawk ${touchmahawkFinalSources} )
TARGET_LINK_LIBRARIES( active-tomahawk ${touchmahawkLinkLibraries} )
SET_TARGET_PROPERTIES( active-tomahawk PROPERTIES COMPILE_FLAGS -DTOUCHMAHAWK )
INSTALL( TARGETS active-tomahawk DESTINATION bin )

View File

@@ -0,0 +1,134 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Dominik Schmidt <domme@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "active/tomahawktouchwindow.h"
#include "utils/logger.h"
#include "audio/audioengine.h"
#include "globalactionmanager.h"
#include "sourcesmodel.h"
#include "items/sourcetreeitem.h"
#include "items/collectionitem.h"
#include "viewmanager.h"
#include "libtomahawk/playlist/treeproxymodel.h"
#include <QFileSystemWatcher>
#include <QtDeclarative>
#define QMLGUI "/home/domme/dev/sources/tomahawk-qml"
TomahawkTouchWindow::TomahawkTouchWindow()
: m_view(0)
, m_currentPlaylistTreeModel(0)
{
QFileSystemWatcher* watcher = new QFileSystemWatcher;
watcher->addPath( QMLGUI );
connect( watcher, SIGNAL( directoryChanged( QString ) ), SLOT( loadQml() ));
loadQml();
setCentralWidget( m_view );
setWindowTitle("Touch-ma-hawk");
}
TomahawkTouchWindow::~TomahawkTouchWindow()
{
}
void TomahawkTouchWindow::play(const QModelIndex& index )
{
TreeModelItem* item = m_currentPlaylistTreeModel->sourceModel()->itemFromIndex( m_currentPlaylistTreeModel->mapToSource( index ) );
if ( item )
{
m_currentPlaylistTreeModel->sourceModel()->setCurrentItem( item->index );
AudioEngine::instance()->playItem( m_currentPlaylistTreeModel, item->result() );
}
}
void TomahawkTouchWindow::activateItem(const QModelIndex& index)
{
tLog() << Q_FUNC_INFO << index;
SourceTreeItem* item = qobject_cast< SourceTreeItem* >( s_sourcesModel->data( index, SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
item->activate();
CollectionItem* collectionItem = qobject_cast< CollectionItem* >( item );
if( collectionItem )
{
tLog() << "Activate collectionItem!";
Tomahawk::collection_ptr collection = collectionItem->source()->collection();
TreeModel* model = ViewManager::instance()->treeModelForCollection( collection );
TreeProxyModel* proxyModel = m_modelProxyModels.value( model );
if( !proxyModel )
{
proxyModel = new TreeProxyModel();
//m_currentPlaylistTreeModel->setDynamicSortFilter( true );
proxyModel->setSourceTreeModel( model );
proxyModel->sort(TreeModel::Name, Qt::AscendingOrder );
//m_currentPlaylistTreeModel->setShowModes( false );
//m_currentPlaylistTreeModel->setSortRole( );
}
m_currentPlaylistTreeModel = proxyModel;
emit currentTreeModelChanged();
//m_view->rootContext()->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel );
}
}
void
TomahawkTouchWindow::loadQml()
{
tLog() << Q_FUNC_INFO;
qmlRegisterType<AudioEngine>("org.tomahawkplayer.qmlcomponents", 1, 0, "AudioEngine");
qmlRegisterType<TreeProxyModel>("org.tomahawkplayer.qmlcomponents", 1, 0, "TreeProxyModel");
if( !m_view )
{
tLog()<< Q_FUNC_INFO << "create qml view";
m_view = new QDeclarativeView;
m_view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
m_view->show();
}
tLog()<< Q_FUNC_INFO << "clear component cache";
m_view->engine()->clearComponentCache();
tLog()<< Q_FUNC_INFO << "set context property";
QDeclarativeContext* context = m_view->rootContext();
tLog()<< Q_FUNC_INFO << "make objects accessible from qml";
context->setContextProperty( "touchWindow", this );
context->setContextProperty( "audioEngine", AudioEngine::instance() );
context->setContextProperty( "globalActionManager", GlobalActionManager::instance() );
context->setContextProperty( "sourcesModel", s_sourcesModel );
// don't start in an undefined state
m_currentPlaylistTreeModel = 0;
//context->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel );
tLog()<< Q_FUNC_INFO << "set source";
m_view->setSource( QUrl::fromLocalFile( QMLGUI "/main.qml" ) );
}

View File

@@ -0,0 +1,62 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Dominik Schmidt <domme@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOMAHAWKTOUCHWINDOW_H
#define TOMAHAWKTOUCHWINDOW_H
#include "tomahawkwindow.h"
#include <QtDeclarative>
class TomahawkTouchWindow;
class QFileSystemWatcher;
class TreeModel;
class TreeProxyModel;
class TomahawkTouchWindow : public TomahawkWindow
{
Q_OBJECT
Q_PROPERTY( TreeProxyModel* currentTreeModel READ currentTreeModel NOTIFY currentTreeModelChanged )
public:
TomahawkTouchWindow();
~TomahawkTouchWindow();
Q_INVOKABLE void play( const QModelIndex& index );
Q_INVOKABLE void activateItem( const QModelIndex& index );
signals:
void currentTreeModelChanged();
private slots:
void loadQml();
private:
TreeProxyModel* currentTreeModel() { return m_currentPlaylistTreeModel; }
QDeclarativeView* m_view;
QFileSystemWatcher* m_watcher;
TreeProxyModel* m_currentPlaylistTreeModel;
QHash< TreeModel*, TreeProxyModel* > m_modelProxyModels;
};
#endif // TOMAHAWKTOUCHWINDOW_H

View File

@@ -74,6 +74,12 @@ AudioEngine::AudioEngine()
connect( m_audioOutput, SIGNAL( volumeChanged( qreal ) ), this, SLOT( onVolumeChanged( qreal ) ) );
onVolumeChanged( m_audioOutput->volume() );
connect( this, SIGNAL(started(Tomahawk::result_ptr)), SIGNAL(currentTrackChanged()));
connect( this, SIGNAL(stopped()), SIGNAL(currentTrackChanged()));
#ifdef Q_OS_MAC
// On mac, phonon volume is independent from system volume, so the onVolumeChanged call above just sets our volume to 100%.
// Since it's indendent, we'll set it to 75% since that's nicer

View File

@@ -29,6 +29,8 @@
#include "infosystem/infosystem.h"
#include "result.h"
#include "album.h"
#include "artist.h"
#include "typedefs.h"
#include "dllmacro.h"
@@ -42,7 +44,12 @@ namespace Tomahawk
class DLLEXPORT AudioEngine : public QObject
{
Q_OBJECT
Q_OBJECT
Q_ENUMS( AudioState )
Q_PROPERTY(AudioState audioState READ state NOTIFY stateChanged)
Q_PROPERTY(QString currentArtist READ currentArtist NOTIFY currentTrackChanged)
Q_PROPERTY(QString currentAlbum READ currentAlbum NOTIFY currentTrackChanged)
Q_PROPERTY(QString currentTitle READ currentTitle NOTIFY currentTrackChanged)
public:
enum AudioErrorCode { StreamReadError, AudioDeviceError, DecodeError };
@@ -102,7 +109,13 @@ public slots:
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void infoSystemFinished( QString caller );
const QString currentArtist() const { return !m_currentTrack.isNull() ? m_currentTrack->artist()->name() : QString(); }
const QString currentAlbum() const { return !m_currentTrack.isNull() ? currentTrack()->album()->name() : QString(); }
const QString currentTitle() const { return !m_currentTrack.isNull() ? currentTrack()->track() : QString(); }
signals:
void currentTrackChanged();
void loading( const Tomahawk::result_ptr& track );
void started( const Tomahawk::result_ptr& track );
void finished( const Tomahawk::result_ptr& track );

View File

@@ -39,7 +39,7 @@ public:
virtual ~GlobalActionManager();
QUrl openLinkFromQuery( const Tomahawk::query_ptr& query ) const;
QUrl openLink( const QString& title, const QString& artist, const QString& album ) const;
Q_INVOKABLE QUrl openLink( const QString& title, const QString& artist, const QString& album ) const;
/// Takes a spotify link and performs the default open action on it
bool openSpotifyLink( const QString& link );

View File

@@ -49,6 +49,11 @@ TreeModel::TreeModel( QObject* parent )
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[IsPlayingRole] = "isPlaying";
setRoleNames(roles);
}
@@ -277,17 +282,25 @@ TreeModel::data( const QModelIndex& index, int role ) const
return QSize( 128, 0 );
}
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
if ( role != Qt::DisplayRole && !roleNames().contains( role ) ) // && role != Qt::ToolTipRole )
return QVariant();
if ( !entry->artist().isNull() && index.column() == Name )
if ( role == IsPlayingRole )
return entry->isPlaying();
if ( !entry->artist().isNull() && ( index.column() == Name || role == NameRole ) )
{
return entry->artist()->name();
}
else if ( !entry->album().isNull() && index.column() == Name )
else if ( !entry->album().isNull() && ( index.column() == Name || role == NameRole ) )
{
return entry->album()->name();
}
else if ( role == NameRole )
{
return entry->result()->track();
}
else
{
const result_ptr& result = entry->result();

View File

@@ -50,6 +50,11 @@ public:
AlbumPosition
};
enum Roles {
NameRole = Qt::UserRole + 1,
IsPlayingRole
};
enum ColumnStyle // Default style is AllColumns
{ AllColumns = 0, TrackOnly };

View File

@@ -246,13 +246,10 @@ ViewManager::show( const Tomahawk::collection_ptr& collection )
if ( !m_collectionViews.contains( collection ) || m_collectionViews.value( collection ).isNull() )
{
view = new CollectionView();
CollectionFlatModel* model = new CollectionFlatModel();
view->setTrackModel( model );
view->setTrackModel( flatModelForCollection( collection ) );
view->setFrameShape( QFrame::NoFrame );
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
model->addCollection( collection );
m_collectionViews.insert( collection, view );
}
else
@@ -270,13 +267,10 @@ ViewManager::show( const Tomahawk::collection_ptr& collection )
if ( !m_treeViews.contains( collection ) || m_treeViews.value( collection ).isNull() )
{
view = new ArtistView();
TreeModel* model = new TreeModel();
view->setTreeModel( model );
view->setTreeModel( treeModelForCollection( collection ) );
view->setFrameShape( QFrame::NoFrame );
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
model->addCollection( collection );
m_treeViews.insert( collection, view );
}
else
@@ -294,11 +288,9 @@ ViewManager::show( const Tomahawk::collection_ptr& collection )
if ( !m_collectionAlbumViews.contains( collection ) || m_collectionAlbumViews.value( collection ).isNull() )
{
aview = new AlbumView();
AlbumModel* amodel = new AlbumModel( aview );
aview->setAlbumModel( amodel );
aview->setAlbumModel( albumModelForCollection( collection ) );
aview->setFrameShape( QFrame::NoFrame );
aview->setAttribute( Qt::WA_MacShowFocusRect, 0 );
amodel->addCollection( collection );
m_collectionAlbumViews.insert( collection, aview );
}
@@ -864,6 +856,69 @@ ViewManager::collectionForInterface( Tomahawk::PlaylistInterface* interface ) co
}
CollectionFlatModel*
ViewManager::flatModelForCollection( const collection_ptr& collection )
{
CollectionFlatModel* model = 0;
if ( !m_collectionFlatModels.contains( collection ) || m_collectionFlatModels.value( collection ).isNull() )
{
model = new CollectionFlatModel();
model->addCollection( collection );
m_collectionFlatModels.insert( collection, QWeakPointer<CollectionFlatModel>( model ) );
}
else
{
model = m_collectionFlatModels.value( collection ).data();
}
return model;
}
TreeModel*
ViewManager::treeModelForCollection( const collection_ptr& collection )
{
TreeModel* model = 0;
if ( !m_collectionTreeModels.contains( collection ) || m_collectionTreeModels.value( collection ).isNull() )
{
model = new TreeModel();
model->addCollection( collection );
m_collectionTreeModels.insert( collection, QWeakPointer<TreeModel>( model ) );
}
else
{
model = m_collectionTreeModels.value( collection ).data();
}
return model;
}
AlbumModel*
ViewManager::albumModelForCollection( const collection_ptr& collection )
{
AlbumModel* model = 0;
if ( !m_collectionAlbumModels.contains( collection ) || m_collectionAlbumModels.value( collection ).isNull() )
{
model = new AlbumModel();
model->addCollection( collection );
m_collectionAlbumModels.insert( collection, QWeakPointer<AlbumModel>( model ) );
}
else
{
model = m_collectionAlbumModels.value( collection ).data();
}
return model;
}
bool
ViewManager::isSuperCollectionVisible() const
{

View File

@@ -104,6 +104,12 @@ public:
// linked to the sidebar. call it right after creating the playlist
PlaylistView* createPageForPlaylist( const Tomahawk::playlist_ptr& pl );
// outsource to a modelManager (?)
CollectionFlatModel* flatModelForCollection( const Tomahawk::collection_ptr& collection );
TreeModel* treeModelForCollection( const Tomahawk::collection_ptr& collection );
AlbumModel* albumModelForCollection( const Tomahawk::collection_ptr& collection );
signals:
void numSourcesChanged( unsigned int sources );
void numTracksChanged( unsigned int tracks );
@@ -202,6 +208,11 @@ private:
QHash< Tomahawk::playlist_ptr, QWeakPointer<PlaylistView> > m_playlistViews;
QHash< Tomahawk::source_ptr, QWeakPointer<SourceInfoWidget> > m_sourceViews;
QHash< Tomahawk::collection_ptr, QWeakPointer<CollectionFlatModel> > m_collectionFlatModels;
QHash< Tomahawk::collection_ptr, QWeakPointer<TreeModel> > m_collectionTreeModels;
QHash< Tomahawk::collection_ptr, QWeakPointer<AlbumModel> > m_collectionAlbumModels;
QList<Tomahawk::ViewPage*> m_pageHistory;
Tomahawk::collection_ptr m_currentCollection;

View File

@@ -42,6 +42,10 @@ main( int argc, char *argv[] )
AEInstallEventHandler( 'GURL', 'GURL', h, 0, false );
#endif
#ifdef TOUCHMAHAWK
QApplication::setGraphicsSystem( "raster" );
#endif
TomahawkApp a( argc, argv );
KDSingleApplicationGuard guard( &a, KDSingleApplicationGuard::AutoKillOtherInstances );
QObject::connect( &guard, SIGNAL( instanceStarted( KDSingleApplicationGuard::Instance ) ), &a, SLOT( instanceStarted( KDSingleApplicationGuard::Instance ) ) );

View File

@@ -30,6 +30,8 @@
#include "utils/logger.h"
#include "dropjob.h"
#include "tomahawkdesktopwindow.h"
using namespace Tomahawk;
@@ -78,7 +80,7 @@ CategoryAddItem::activate()
break;
}
case SourcesModel::StationsCategory:
APP->mainWindow()->createStation();
APP->desktopWindow()->createStation();
break;
}
}
@@ -100,7 +102,7 @@ CategoryAddItem::dialogClosed( int ret )
} else if ( playlistSelectorDlg->playlistTypeIsAuto() && ret ) {
// create Auto Playlist
APP->mainWindow()->createAutomaticPlaylist( playlistName );
APP->desktopWindow()->createAutomaticPlaylist( playlistName );
} else if ( !ret ) {
model()->viewPageActivated( ViewManager::instance()->currentPage() );
}
@@ -281,7 +283,7 @@ CategoryAddItem::parsedDroppedTracks( const QList< query_ptr >& tracks )
ViewManager::instance()->show( newpl );
// Give a shot to try to rename it. The playlist has to be created first. ugly.
QTimer::singleShot( 300, APP->mainWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
QTimer::singleShot( 300, APP->desktopWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
} else if( m_categoryType == SourcesModel::StationsCategory ) {
// seed the playlist with these song filters
QString name = tracks.isEmpty() ? tr( "New Station" ) : tr( "%1 Station" ).arg( tracks.first()->track() );
@@ -300,7 +302,7 @@ CategoryAddItem::parsedDroppedTracks( const QList< query_ptr >& tracks )
ViewManager::instance()->show( newpl );
// Give a shot to try to rename it. The playlist has to be created first. ugly.
QTimer::singleShot( 300, APP->mainWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
QTimer::singleShot( 300, APP->desktopWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
}
}

View File

@@ -55,6 +55,10 @@ SourcesModel::SourcesModel( QObject* parent )
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceRemoved( Tomahawk::source_ptr ) ) );
connect( ViewManager::instance(), SIGNAL( viewPageActivated( Tomahawk::ViewPage* ) ), this, SLOT( viewPageActivated( Tomahawk::ViewPage* ) ) );
QHash<int, QByteArray> roles;
roles[Qt::DisplayRole] = "name";
setRoleNames(roles);
}

View File

@@ -48,7 +48,7 @@
using namespace Tomahawk;
SourceTreeView::SourceTreeView( QWidget* parent )
SourceTreeView::SourceTreeView( QWidget* parent, SourcesModel* model )
: QTreeView( parent )
, m_dragging( false )
{
@@ -85,7 +85,7 @@ SourceTreeView::SourceTreeView( QWidget* parent )
setContextMenuPolicy( Qt::CustomContextMenu );
connect( this, SIGNAL( customContextMenuRequested( QPoint ) ), SLOT( onCustomContextMenu( QPoint ) ) );
m_model = new SourcesModel( this );
m_model = model;
m_proxyModel = new SourcesProxyModel( m_model, this );
connect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( selectRequest( QPersistentModelIndex ) ) );
connect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequest( QPersistentModelIndex ) ) );

View File

@@ -37,7 +37,7 @@ class SourceTreeView : public QTreeView
Q_OBJECT
public:
explicit SourceTreeView( QWidget* parent = 0 );
explicit SourceTreeView( QWidget* parent = 0, SourcesModel* model = 0 );
public slots:
void showOfflineSources( bool offlineSourcesShown );

View File

@@ -64,11 +64,15 @@
#include "config.h"
#ifndef TOMAHAWK_HEADLESS
#include "tomahawkwindow.h"
#include "tomahawkdesktopwindow.h"
#include "settingsdialog.h"
#include <QMessageBox>
#endif
#ifdef TOUCHMAHAWK
#include "active/tomahawktouchwindow.h"
#endif
// should go to a plugin actually
#ifdef GLOOX_FOUND
#include "xmppbot/xmppbot.h"
@@ -219,10 +223,17 @@ TomahawkApp::init()
if ( !m_headless )
{
tDebug() << "Init MainWindow.";
m_mainwindow = new TomahawkWindow();
m_mainwindow = new TomahawkDesktopWindow();
m_mainwindow->setWindowTitle( "Tomahawk" );
m_mainwindow->setObjectName( "TH_Main_Window" );
#ifndef TOUCHMAHAWK
m_mainwindow->show();
#else
m_declarativeWindow = new TomahawkTouchWindow();
m_declarativeWindow->show();
#endif // TOUCHMAHAWK
}
#endif
@@ -328,6 +339,20 @@ TomahawkApp::audioControls()
{
return m_mainwindow->audioControls();
}
TomahawkWindow*
TomahawkApp::mainWindow() const
{
// why does static_casdt<TomahawkWindow*> not work here?!
return (TomahawkWindow*) ( m_mainwindow );
}
TomahawkDesktopWindow*
TomahawkApp::desktopWindow() const
{
return m_mainwindow;
}
#endif

View File

@@ -65,7 +65,12 @@ namespace Tomahawk
#endif
#ifndef TOMAHAWK_HEADLESS
class TomahawkWindow;
class TomahawkDesktopWindow;
class AudioControls;
#endif
#ifdef TOUCHMAHAWK
class TomahawkTouchWindow;
#endif
@@ -87,7 +92,12 @@ public:
#ifndef TOMAHAWK_HEADLESS
AudioControls* audioControls();
TomahawkWindow* mainWindow() const { return m_mainwindow; }
TomahawkWindow* mainWindow() const;
TomahawkDesktopWindow* desktopWindow() const;
#endif
#ifdef TOUCHMAHAWK
TomahawkTouchWindow* declarativeWindow() const { return m_declarativeWindow; }
#endif
void enableScriptResolver( const QString& scriptPath );
@@ -136,7 +146,11 @@ private:
#endif
#ifndef TOMAHAWK_HEADLESS
TomahawkWindow* m_mainwindow;
TomahawkDesktopWindow* m_mainwindow;
#endif
#ifdef TOUCHMAHAWK
TomahawkTouchWindow* m_declarativeWindow;
#endif
bool m_headless;

View File

@@ -0,0 +1,599 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tomahawkdesktopwindow.h"
#include "ui_tomahawkdesktopwindow.h"
#include <QAction>
#include <QCloseEvent>
#include <QShowEvent>
#include <QHideEvent>
#include <QInputDialog>
#include <QPixmap>
#include <QPropertyAnimation>
#include <QLineEdit>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QTimer>
#include <QToolBar>
#include "playlist.h"
#include "query.h"
#include "artist.h"
#include "audio/audioengine.h"
#include "viewmanager.h"
#include "sip/SipHandler.h"
#include "sourcetree/sourcetreeview.h"
#include "widgets/animatedsplitter.h"
#include "utils/proxystyle.h"
#include "utils/widgetdragfilter.h"
#include "utils/xspfloader.h"
#include "widgets/newplaylistwidget.h"
#include "widgets/searchwidget.h"
#include "widgets/playlisttypeselectordlg.h"
#include "audiocontrols.h"
#include "settingsdialog.h"
#include "diagnosticsdialog.h"
#include "tomahawksettings.h"
#include "sourcelist.h"
#include "PipelineStatusView.h"
#include "transferview.h"
#include "tomahawktrayicon.h"
#include "playlist/dynamic/GeneratorInterface.h"
#include "scanmanager.h"
#include "tomahawkapp.h"
#ifdef Q_OS_WIN32
#include <qtsparkle/Updater>
#endif
#include "utils/logger.h"
#include "thirdparty/Qocoa/qsearchfield.h"
using namespace Tomahawk;
TomahawkDesktopWindow::TomahawkDesktopWindow( QWidget* parent )
: TomahawkWindow( parent )
, ui( new Ui::TomahawkDesktopWindow )
, m_searchWidget( 0 )
, m_audioControls( new AudioControls( this ) )
{
connect( ViewManager::instance(), SIGNAL( showQueueRequested() ), SLOT( showQueue() ) );
connect( ViewManager::instance(), SIGNAL( hideQueueRequested() ), SLOT( hideQueue() ) );
ui->setupUi( this );
applyPlatformTweaks();
ui->centralWidget->setContentsMargins( 0, 0, 0, 0 );
TomahawkUtils::unmarginLayout( ui->centralWidget->layout() );
setupSideBar();
statusBar()->addPermanentWidget( m_audioControls, 1 );
setupUpdateCheck();
loadSettings();
setupSignals();
// set initial state
onSipDisconnected();
ViewManager::instance()->setQueue( m_queueView );
ViewManager::instance()->showWelcomePage();
}
TomahawkDesktopWindow::~TomahawkDesktopWindow()
{
delete ui;
}
void
TomahawkDesktopWindow::retranslateUi()
{
ui->retranslateUi( this );
}
void
TomahawkDesktopWindow::loadSettings()
{
TomahawkSettings* s = TomahawkSettings::instance();
if ( !s->mainWindowSplitterState().isEmpty() )
ui->splitter->restoreState( s->mainWindowSplitterState() );
TomahawkWindow::loadSettings();
}
void
TomahawkDesktopWindow::saveSettings()
{
TomahawkSettings* s = TomahawkSettings::instance();
s->setMainWindowSplitterState( ui->splitter->saveState() );
TomahawkWindow::saveSettings();
}
void
TomahawkDesktopWindow::applyPlatformTweaks()
{
// HACK QtCurve causes an infinite loop on startup. This is because setStyle calls setPalette, which calls ensureBaseStyle,
// which loads QtCurve. QtCurve calls setPalette, which creates an infinite loop. The UI will look like CRAP with QtCurve, but
// the user is asking for it explicitly... so he's gonna be stuck with an ugly UI.
if ( !QString( qApp->style()->metaObject()->className() ).toLower().contains( "qtcurve" ) )
qApp->setStyle( new ProxyStyle() );
#ifdef Q_OS_MAC
setUnifiedTitleAndToolBarOnMac( true );
delete ui->hline1;
delete ui->hline2;
#else
ui->hline1->setStyleSheet( "border: 1px solid gray;" );
ui->hline2->setStyleSheet( "border: 1px solid gray;" );
#endif
}
void
TomahawkDesktopWindow::setupSideBar()
{
// Delete fake designer widgets
delete ui->sidebarWidget;
delete ui->playlistWidget;
QWidget* sidebarWidget = new QWidget();
sidebarWidget->setLayout( new QVBoxLayout() );
m_sidebar = new AnimatedSplitter();
m_sidebar->setOrientation( Qt::Vertical );
m_sidebar->setChildrenCollapsible( false );
m_searchWidget = new QSearchField( m_sidebar );
m_searchWidget->setPlaceholderText( "Global Search..." );
connect( m_searchWidget, SIGNAL( returnPressed() ), this, SLOT( onFilterEdited() ) );
m_sourcetree = new SourceTreeView( this, s_sourcesModel );
TransferView* transferView = new TransferView( m_sidebar );
PipelineStatusView* pipelineView = new PipelineStatusView( m_sidebar );
m_queueView = new QueueView( m_sidebar );
m_queueModel = new PlaylistModel( m_queueView );
m_queueModel->setStyle( PlaylistModel::Short );
m_queueView->queue()->setPlaylistModel( m_queueModel );
m_queueView->queue()->playlistModel()->setReadOnly( false );
AudioEngine::instance()->setQueue( m_queueView->queue()->proxyModel() );
m_sidebar->addWidget( m_searchWidget );
m_sidebar->addWidget( m_sourcetree );
m_sidebar->addWidget( transferView );
m_sidebar->addWidget( pipelineView );
m_sidebar->addWidget( m_queueView );
m_sidebar->setGreedyWidget( 1 );
m_sidebar->hide( 1, false );
m_sidebar->hide( 2, false );
m_sidebar->hide( 3, false );
m_sidebar->hide( 4, false );
sidebarWidget->layout()->addWidget( m_sidebar );
sidebarWidget->setContentsMargins( 0, 0, 0, 0 );
sidebarWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
sidebarWidget->layout()->setMargin( 0 );
#ifndef Q_OS_MAC
sidebarWidget->layout()->setSpacing( 0 );
#endif
ui->splitter->addWidget( sidebarWidget );
ui->splitter->addWidget( ViewManager::instance()->widget() );
ui->splitter->setStretchFactor( 0, 1 );
ui->splitter->setStretchFactor( 1, 3 );
ui->splitter->setCollapsible( 1, false );
ui->splitter->setHandleWidth( 1 );
ui->actionShowOfflineSources->setChecked( TomahawkSettings::instance()->showOfflineSources() );
}
void
TomahawkDesktopWindow::setupUpdateCheck()
{
#ifndef Q_WS_MAC
ui->menu_Help->insertSeparator( ui->actionAboutTomahawk );
#endif
#if defined( Q_OS_DARWIN ) && defined( HAVE_SPARKLE )
QAction* checkForUpdates = ui->menu_Help->addAction( tr( "Check For Updates..." ) );
checkForUpdates->setMenuRole( QAction::ApplicationSpecificRole );
connect( checkForUpdates, SIGNAL( triggered( bool ) ), SLOT( checkForUpdates() ) );
#elif defined( WIN32 )
QUrl updaterUrl;
if ( qApp->arguments().contains( "--debug" ) )
updaterUrl.setUrl( "http://download.tomahawk-player.org/sparklewin-debug" );
else
updaterUrl.setUrl( "http://download.tomahawk-player.org/sparklewin" );
qtsparkle::Updater* updater = new qtsparkle::Updater( updaterUrl, this );
Q_ASSERT( TomahawkUtils::nam() != 0 );
updater->SetNetworkAccessManager( TomahawkUtils::nam() );
updater->SetVersion( TomahawkUtils::appFriendlyVersion() );
ui->menu_Help->addSeparator();
QAction* checkForUpdates = ui->menu_Help->addAction( tr( "Check For Updates..." ) );
connect( checkForUpdates, SIGNAL( triggered() ), updater, SLOT( CheckNow() ) );
#endif
}
void
TomahawkDesktopWindow::setupSignals()
{
// <From PlaylistManager>
connect( ViewManager::instance(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
m_audioControls, SLOT( onRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
connect( ViewManager::instance(), SIGNAL( shuffleModeChanged( bool ) ),
m_audioControls, SLOT( onShuffleModeChanged( bool ) ) );
// <From AudioEngine>
connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( audioStarted() ) );
connect( AudioEngine::instance(), SIGNAL( resumed()), SLOT( audioStarted() ) );
connect( AudioEngine::instance(), SIGNAL( paused() ), SLOT( audioStopped() ) );
connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( audioStopped() ) );
// <Menu Items>
// connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) );
connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) );
connect( ui->actionDiagnostics, SIGNAL( triggered() ), SLOT( showDiagnosticsDialog() ) );
connect( ui->actionToggleConnect, SIGNAL( triggered() ), SipHandler::instance(), SLOT( toggleConnect() ) );
connect( ui->actionUpdateCollection, SIGNAL( triggered() ), SLOT( updateCollectionManually() ) );
connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( rescanCollectionManually() ) );
connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() ));
connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() ));
connect( ui->actionCreate_New_Station, SIGNAL( triggered() ), SLOT( createStation() ));
connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) );
connect( ui->actionExit, SIGNAL( triggered() ), qApp, SLOT( quit() ) );
connect( ui->actionShowOfflineSources, SIGNAL( triggered() ), SLOT( showOfflineSources() ) );
connect( ui->actionPlay, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( playPause() ) );
connect( ui->actionNext, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( next() ) );
connect( ui->actionPrevious, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( previous() ) );
#if defined( Q_WS_MAC )
connect( ui->actionMinimize, SIGNAL( triggered() ), SLOT( minimize() ) );
connect( ui->actionZoom, SIGNAL( triggered() ), SLOT( maximize() ) );
#else
ui->menuWindow->clear();
ui->menuWindow->menuAction()->setVisible( false );
#endif
// <SipHandler>
connect( SipHandler::instance(), SIGNAL( connected( SipPlugin* ) ), SLOT( onSipConnected() ) );
connect( SipHandler::instance(), SIGNAL( disconnected( SipPlugin* ) ), SLOT( onSipDisconnected() ) );
connect( SipHandler::instance(), SIGNAL( authError( SipPlugin* ) ), SLOT( onSipError() ) );
// <SipMenu>
connect( SipHandler::instance(), SIGNAL( pluginAdded( SipPlugin* ) ), this, SLOT( onSipPluginAdded( SipPlugin* ) ) );
connect( SipHandler::instance(), SIGNAL( pluginRemoved( SipPlugin* ) ), this, SLOT( onSipPluginRemoved( SipPlugin* ) ) );
foreach( SipPlugin *plugin, SipHandler::instance()->allPlugins() )
{
connect( plugin, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
connect( plugin, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
}
}
void
TomahawkDesktopWindow::showSettingsDialog()
{
qDebug() << Q_FUNC_INFO;
SettingsDialog win;
win.exec();
}
void TomahawkDesktopWindow::showDiagnosticsDialog()
{
qDebug() << Q_FUNC_INFO;
DiagnosticsDialog win;
win.exec();
}
void
TomahawkDesktopWindow::updateCollectionManually()
{
if ( TomahawkSettings::instance()->hasScannerPaths() )
ScanManager::instance()->runScan();
}
void
TomahawkDesktopWindow::rescanCollectionManually()
{
if ( TomahawkSettings::instance()->hasScannerPaths() )
ScanManager::instance()->runScan( true );
}
void
TomahawkDesktopWindow::addPeerManually()
{
TomahawkSettings* s = TomahawkSettings::instance();
bool ok;
QString addr = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer address:" ), QLineEdit::Normal,
s->value( "connip" ).toString(), &ok ); // FIXME
if ( !ok )
return;
s->setValue( "connip", addr );
QString ports = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer port:" ), QLineEdit::Normal,
s->value( "connport", "50210" ).toString(), &ok );
if ( !ok )
return;
s->setValue( "connport", ports );
int port = ports.toInt();
QString key = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer key:" ), QLineEdit::Normal,
"whitelist", &ok );
if ( !ok )
return;
qDebug() << "Attempting to connect to" << addr;
Servent::instance()->connectToPeer( addr, port, key );
}
void
TomahawkDesktopWindow::pluginMenuAdded( QMenu* menu )
{
ui->menuNetwork->addMenu( menu );
}
void
TomahawkDesktopWindow::pluginMenuRemoved( QMenu* menu )
{
foreach( QAction* action, ui->menuNetwork->actions() )
{
if( action->menu() == menu )
{
ui->menuNetwork->removeAction( action );
return;
}
}
}
void
TomahawkDesktopWindow::showOfflineSources()
{
m_sourcetree->showOfflineSources( ui->actionShowOfflineSources->isChecked() );
TomahawkSettings::instance()->setShowOfflineSources( ui->actionShowOfflineSources->isChecked() );
}
void
TomahawkDesktopWindow::loadSpiff()
{
bool ok;
QString urlstr = QInputDialog::getText( this, tr( "Load XSPF" ), tr( "Path:" ), QLineEdit::Normal, "http://ws.audioscrobbler.com/1.0/tag/metal/toptracks.xspf", &ok );
if ( !ok || urlstr.isEmpty() )
return;
XSPFLoader* loader = new XSPFLoader;
loader->load( QUrl::fromUserInput( urlstr ) );
}
void
TomahawkDesktopWindow::createAutomaticPlaylist( QString playlistName )
{
QString name = playlistName;
if ( name.isEmpty() )
return;
source_ptr author = SourceList::instance()->getLocal();
QString id = uuid();
QString info = ""; // FIXME
QString creator = "someone"; // FIXME
dynplaylist_ptr playlist = DynamicPlaylist::create( author, id, name, info, creator, Static, false );
playlist->setMode( Static );
playlist->createNewRevision( uuid(), playlist->currentrevision(), playlist->type(), playlist->generator()->controls(), playlist->entries() );
ViewManager::instance()->show( playlist );
}
void
TomahawkDesktopWindow::createStation()
{
bool ok;
QString name = QInputDialog::getText( this, tr( "Create New Station" ), tr( "Name:" ), QLineEdit::Normal, tr( "New Station" ), &ok );
if ( !ok || name.isEmpty() )
return;
source_ptr author = SourceList::instance()->getLocal();
QString id = uuid();
QString info = ""; // FIXME
QString creator = "someone"; // FIXME
dynplaylist_ptr playlist = DynamicPlaylist::create( author, id, name, info, creator, OnDemand, false );
playlist->setMode( OnDemand );
playlist->createNewRevision( uuid(), playlist->currentrevision(), playlist->type(), playlist->generator()->controls() );
ViewManager::instance()->show( playlist );
}
void
TomahawkDesktopWindow::createPlaylist()
{
PlaylistTypeSelectorDlg* playlistSelectorDlg = new PlaylistTypeSelectorDlg( TomahawkApp::instance()->mainWindow(), Qt::Sheet );
#ifndef Q_OS_MAC
playlistSelectorDlg->setModal( true );
#endif
connect( playlistSelectorDlg, SIGNAL( finished( int ) ), this, SLOT( playlistCreateDialogFinished( int ) ) );
playlistSelectorDlg->show();
}
void TomahawkDesktopWindow::playlistCreateDialogFinished( int ret )
{
PlaylistTypeSelectorDlg* playlistSelectorDlg = qobject_cast< PlaylistTypeSelectorDlg* >( sender() );
Q_ASSERT( playlistSelectorDlg );
QString playlistName = playlistSelectorDlg->playlistName();
if ( playlistName.isEmpty() )
playlistName = tr( "New Playlist" );
if ( !playlistSelectorDlg->playlistTypeIsAuto() && ret ) {
playlist_ptr playlist = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), playlistName, "", "", false, QList< query_ptr>() );
ViewManager::instance()->show( playlist );
} else if ( playlistSelectorDlg->playlistTypeIsAuto() && ret ) {
// create Auto Playlist
createAutomaticPlaylist( playlistName );
}
playlistSelectorDlg->deleteLater();
}
void
TomahawkDesktopWindow::audioStarted()
{
ui->actionPlay->setText( tr( "Pause" ) );
}
void
TomahawkDesktopWindow::audioStopped()
{
ui->actionPlay->setText( tr( "Play" ) );
}
void
TomahawkDesktopWindow::onSipConnected()
{
ui->actionToggleConnect->setText( tr( "Go &offline" ) );
}
void
TomahawkDesktopWindow::onSipDisconnected()
{
ui->actionToggleConnect->setText( tr( "Go &online" ) );
}
void
TomahawkDesktopWindow::onSipPluginAdded( SipPlugin* p )
{
connect( p, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
connect( p, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
}
void
TomahawkDesktopWindow::onSipPluginRemoved( SipPlugin* p )
{
Q_UNUSED( p );
}
void
TomahawkDesktopWindow::onSipError()
{
onSipDisconnected();
QMessageBox::warning( this,
tr( "Authentication Error" ),
QString( "Error connecting to SIP: Authentication failed!" ),
QMessageBox::Ok );
}
void
TomahawkDesktopWindow::showAboutTomahawk()
{
QMessageBox::about( this, tr( "About Tomahawk" ),
tr( "<h2><b>Tomahawk %1<br/>(%2)</h2>Copyright 2010, 2011<br/>Christian Muehlhaeuser &lt;muesli@tomahawk-player.org&gt;<br/><br/>"
"Thanks to: Leo Franchi, Jeff Mitchell, Dominik Schmidt, Jason Herskowitz, Alejandro Wainzinger, Michael Zanetti, Harald Sitter and Steve Robertson" )
.arg( TomahawkUtils::appFriendlyVersion() )
.arg( qApp->applicationVersion() ) );
}
void
TomahawkDesktopWindow::checkForUpdates()
{
#ifdef Q_WS_MAC
Tomahawk::checkForUpdates();
#endif
}
void
TomahawkDesktopWindow::onSearch( const QString& search )
{
if ( !search.trimmed().isEmpty() )
ViewManager::instance()->show( new SearchWidget( search, this ) );
}
void
TomahawkDesktopWindow::onFilterEdited()
{
onSearch( m_searchWidget->text() );
m_searchWidget->clear();
}
void
TomahawkDesktopWindow::showQueue()
{
if ( QThread::currentThread() != thread() )
{
qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO;
QMetaObject::invokeMethod( this, "showQueue", Qt::QueuedConnection );
return;
}
m_queueView->show();
}
void
TomahawkDesktopWindow::hideQueue()
{
if ( QThread::currentThread() != thread() )
{
qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO;
QMetaObject::invokeMethod( this, "hideQueue", Qt::QueuedConnection );
return;
}
m_queueView->hide();
}

120
src/tomahawkdesktopwindow.h Normal file
View File

@@ -0,0 +1,120 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOMAHAWKDESKTOPWINDOW_H
#define TOMAHAWKDESKTOPWINDOW_H
#include "result.h"
#include "tomahawkwindow.h"
#include <QMainWindow>
#include <QVariantMap>
#include <QPushButton>
#include <QString>
#include <QStackedWidget>
class QSearchField;
class SipPlugin;
class SourceTreeView;
class QAction;
class MusicScanner;
class AudioControls;
class TomahawkTrayIcon;
class PlaylistModel;
class QueueView;
class AnimatedSplitter;
namespace Ui
{
class TomahawkDesktopWindow;
class GlobalSearchWidget;
}
class TomahawkDesktopWindow : public TomahawkWindow
{
Q_OBJECT
public:
TomahawkDesktopWindow( QWidget* parent = 0 );
~TomahawkDesktopWindow();
AudioControls* audioControls() { return m_audioControls; }
SourceTreeView* sourceTreeView() const { return m_sourcetree; }
protected:
virtual void retranslateUi();
public slots:
void createAutomaticPlaylist( QString );
void createStation();
void createPlaylist();
void loadSpiff();
void showSettingsDialog();
void showDiagnosticsDialog();
void updateCollectionManually();
void rescanCollectionManually();
void pluginMenuAdded(QMenu*);
void pluginMenuRemoved(QMenu*);
void showOfflineSources();
private slots:
void onSipConnected();
void onSipDisconnected();
void onSipError();
void addPeerManually();
void audioStarted();
void audioStopped();
void showAboutTomahawk();
void checkForUpdates();
void onSipPluginAdded( SipPlugin* p );
void onSipPluginRemoved( SipPlugin* p );
void onSearch( const QString& search );
void onFilterEdited();
void showQueue();
void hideQueue();
void playlistCreateDialogFinished( int ret );
private:
virtual void loadSettings();
virtual void saveSettings();
void applyPlatformTweaks();
void setupSignals();
void setupSideBar();
void setupUpdateCheck();
Ui::TomahawkDesktopWindow* ui;
QSearchField* m_searchWidget;
AudioControls* m_audioControls;
SourceTreeView* m_sourcetree;
QPushButton* m_statusButton;
QPushButton* m_queueButton;
PlaylistModel* m_queueModel;
QueueView* m_queueView;
AnimatedSplitter* m_sidebar;
};
#endif // TOMAHAWKDESKTOPWINDOW_H

View File

@@ -0,0 +1,267 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TomahawkDesktopWindow</class>
<widget class="QMainWindow" name="TomahawkDesktopWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1000</width>
<height>660</height>
</rect>
</property>
<property name="windowTitle">
<string>Tomahawk</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="hline1">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="handleWidth">
<number>1</number>
</property>
<widget class="QWidget" name="sidebarWidget" native="true"/>
<widget class="QWidget" name="playlistWidget" native="true"/>
</widget>
</item>
<item>
<widget class="QFrame" name="hline2">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1000</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuSettings">
<property name="title">
<string>&amp;Settings</string>
</property>
<addaction name="actionPreferences"/>
</widget>
<widget class="QMenu" name="menuApp">
<property name="title">
<string>&amp;Music Player</string>
</property>
<addaction name="actionPlay"/>
<addaction name="actionPrevious"/>
<addaction name="actionNext"/>
<addaction name="separator"/>
<addaction name="actionUpdateCollection"/>
<addaction name="actionRescanCollection"/>
<addaction name="separator"/>
<addaction name="actionShowOfflineSources"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuNetwork">
<property name="title">
<string>&amp;Network</string>
</property>
<addaction name="actionToggleConnect"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="menuWindow">
<property name="title">
<string>&amp;Window</string>
</property>
<addaction name="actionMinimize"/>
<addaction name="actionZoom"/>
</widget>
<widget class="QMenu" name="menu_Help">
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="actionDiagnostics"/>
<addaction name="actionAboutTomahawk"/>
</widget>
<widget class="QMenu" name="menuPlaylist">
<property name="title">
<string>&amp;Playlist</string>
</property>
<addaction name="actionCreatePlaylist"/>
<addaction name="actionCreate_New_Station"/>
<addaction name="separator"/>
<addaction name="actionLoadXSPF"/>
</widget>
<addaction name="menuApp"/>
<addaction name="menuPlaylist"/>
<addaction name="menuNetwork"/>
<addaction name="menuSettings"/>
<addaction name="menuWindow"/>
<addaction name="menu_Help"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionExit">
<property name="text">
<string>&amp;Quit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
<property name="menuRole">
<enum>QAction::QuitRole</enum>
</property>
</action>
<action name="actionToggleConnect">
<property name="text">
<string>Go &amp;Online</string>
</property>
</action>
<action name="actionAddFriendManually">
<property name="text">
<string>Add &amp;Friend...</string>
</property>
</action>
<action name="actionUpdateCollection">
<property name="text">
<string>U&amp;pdate Collection</string>
</property>
<property name="toolTip">
<string>Update Collection</string>
</property>
</action>
<action name="actionPreferences">
<property name="text">
<string>&amp;Configure Tomahawk...</string>
</property>
<property name="menuRole">
<enum>QAction::PreferencesRole</enum>
</property>
</action>
<action name="actionLoadXSPF">
<property name="text">
<string>Load &amp;XSPF...</string>
</property>
</action>
<action name="actionCreatePlaylist">
<property name="text">
<string>Create &amp;New Playlist...</string>
</property>
</action>
<action name="actionAboutTomahawk">
<property name="text">
<string>About &amp;Tomahawk...</string>
</property>
<property name="menuRole">
<enum>QAction::AboutRole</enum>
</property>
</action>
<action name="actionCreateAutomaticPlaylist">
<property name="text">
<string>Create New &amp;Automatic Playlist</string>
</property>
</action>
<action name="actionCreate_New_Station">
<property name="text">
<string>Create New &amp;Station</string>
</property>
</action>
<action name="actionShowOfflineSources">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show Offline Sources</string>
</property>
</action>
<action name="actionHideOfflineSources">
<property name="text">
<string>Hide Offline Sources</string>
</property>
</action>
<action name="actionMinimize">
<property name="text">
<string>Minimize</string>
</property>
<property name="shortcut">
<string>Ctrl+M</string>
</property>
</action>
<action name="actionZoom">
<property name="text">
<string>Zoom</string>
</property>
<property name="shortcut">
<string>Meta+Ctrl+Z</string>
</property>
</action>
<action name="actionDiagnostics">
<property name="text">
<string>Diagnostics...</string>
</property>
<property name="menuRole">
<enum>QAction::ApplicationSpecificRole</enum>
</property>
</action>
<action name="actionRescanCollection">
<property name="text">
<string>Fully &amp;Rescan Collection</string>
</property>
<property name="toolTip">
<string>Fully Rescan Collection</string>
</property>
</action>
<action name="actionPlay">
<property name="text">
<string>Play</string>
</property>
<property name="shortcut">
<string>Space</string>
</property>
</action>
<action name="actionPrevious">
<property name="text">
<string>Previous</string>
</property>
</action>
<action name="actionNext">
<property name="text">
<string>Next</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
<slots>
<slot>on_btnResolve_clicked()</slot>
</slots>
</ui>

View File

@@ -42,6 +42,11 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent )
m_contextMenu = new QMenu();
setContextMenu( m_contextMenu );
#ifdef TOUCHMAHAWK
connect(m_contextMenu->addAction( tr("Show Desktop Gui") ), SIGNAL( triggered() ), parent, SLOT( show() ) );
m_contextMenu->addSeparator();
#endif TOUCHMAHAWK
m_playPauseAction = m_contextMenu->addAction( tr( "Play" ) );
//m_pauseAction = m_contextMenu->addAction( tr( "Pause" ) );
m_stopAction = m_contextMenu->addAction( tr( "Stop" ) );
@@ -179,7 +184,14 @@ TomahawkTrayIcon::onActivated( QSystemTrayIcon::ActivationReason reason )
{
case QSystemTrayIcon::Trigger:
{
TomahawkWindow* mainwindow = APP->mainWindow();
QMainWindow* mainwindow = 0;
#ifndef TOUCHMAHAWK
mainwindow = APP->mainWindow();
#else
mainwindow = (QMainWindow*) APP->declarativeWindow();
#endif
if ( mainwindow->isVisible() )
{
mainwindow->hide();

View File

@@ -17,97 +17,44 @@
*/
#include "tomahawkwindow.h"
#include "ui_tomahawkwindow.h"
#include <QAction>
#include <QCloseEvent>
#include <QShowEvent>
#include <QHideEvent>
#include <QInputDialog>
#include <QPixmap>
#include <QPropertyAnimation>
#include <QLineEdit>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QTimer>
#include <QToolBar>
#include "playlist.h"
#include "query.h"
#include "artist.h"
#include "audio/audioengine.h"
#include "viewmanager.h"
#include "sip/SipHandler.h"
#include "sourcetree/sourcetreeview.h"
#include "utils/proxystyle.h"
#include "utils/xspfloader.h"
#include "widgets/animatedsplitter.h"
#include "widgets/newplaylistwidget.h"
#include "widgets/searchwidget.h"
#include "widgets/playlisttypeselectordlg.h"
#include "thirdparty/Qocoa/qsearchfield.h"
#include "audiocontrols.h"
#include "settingsdialog.h"
#include "diagnosticsdialog.h"
#include "tomahawksettings.h"
#include "sourcelist.h"
#include "PipelineStatusView.h"
#include "transferview.h"
#include "tomahawktrayicon.h"
#include "playlist/dynamic/GeneratorInterface.h"
#include "scanmanager.h"
#include "playlist/queueview.h"
#include "tomahawkapp.h"
#include "sourcetree/sourcesmodel.h"
#include "viewmanager.h"
#include "audio/audioengine.h"
#ifdef Q_OS_WIN32
#include <qtsparkle/Updater>
#endif
#include "utils/logger.h"
#include <QCloseEvent>
using namespace Tomahawk;
SourcesModel* TomahawkWindow::s_sourcesModel = 0;
TomahawkTrayIcon* TomahawkWindow::s_trayIcon = 0;
TomahawkWindow::TomahawkWindow( QWidget* parent )
: QMainWindow( parent )
, ui( new Ui::TomahawkWindow )
, m_searchWidget( 0 )
, m_audioControls( new AudioControls( this ) )
, m_trayIcon( new TomahawkTrayIcon( this ) )
{
setWindowIcon( QIcon( RESPATH "icons/tomahawk-icon-128x128.png" ) );
ViewManager* vm = new ViewManager( this );
connect( vm, SIGNAL( showQueueRequested() ), SLOT( showQueue() ) );
connect( vm, SIGNAL( hideQueueRequested() ), SLOT( hideQueue() ) );
if( !ViewManager::instance() )
new ViewManager( this );
ui->setupUi( this );
applyPlatformTweaks();
if( !s_sourcesModel )
s_sourcesModel = new SourcesModel( this );
ui->centralWidget->setContentsMargins( 0, 0, 0, 0 );
TomahawkUtils::unmarginLayout( ui->centralWidget->layout() );
if( !s_trayIcon )
s_trayIcon = new TomahawkTrayIcon( this );
setupSideBar();
statusBar()->addPermanentWidget( m_audioControls, 1 );
setupUpdateCheck();
loadSettings();
setupSignals();
// set initial state
onSipDisconnected();
vm->setQueue( m_queueView );
vm->showWelcomePage();
}
TomahawkWindow::~TomahawkWindow()
{
saveSettings();
delete ui;
}
@@ -135,8 +82,6 @@ TomahawkWindow::loadSettings()
restoreGeometry( s->mainWindowGeometry() );
if ( !s->mainWindowState().isEmpty() )
restoreState( s->mainWindowState() );
if ( !s->mainWindowSplitterState().isEmpty() )
ui->splitter->restoreState( s->mainWindowSplitterState() );
#ifdef QT_MAC_USE_COCOA
if ( workaround )
@@ -154,179 +99,6 @@ TomahawkWindow::saveSettings()
TomahawkSettings* s = TomahawkSettings::instance();
s->setMainWindowGeometry( saveGeometry() );
s->setMainWindowState( saveState() );
s->setMainWindowSplitterState( ui->splitter->saveState() );
}
void
TomahawkWindow::applyPlatformTweaks()
{
// HACK QtCurve causes an infinite loop on startup. This is because setStyle calls setPalette, which calls ensureBaseStyle,
// which loads QtCurve. QtCurve calls setPalette, which creates an infinite loop. The UI will look like CRAP with QtCurve, but
// the user is asking for it explicitly... so he's gonna be stuck with an ugly UI.
if ( !QString( qApp->style()->metaObject()->className() ).toLower().contains( "qtcurve" ) )
qApp->setStyle( new ProxyStyle() );
#ifdef Q_OS_MAC
setUnifiedTitleAndToolBarOnMac( true );
delete ui->hline1;
delete ui->hline2;
#else
ui->hline1->setStyleSheet( "border: 1px solid gray;" );
ui->hline2->setStyleSheet( "border: 1px solid gray;" );
#endif
}
void
TomahawkWindow::setupSideBar()
{
// Delete fake designer widgets
delete ui->sidebarWidget;
delete ui->playlistWidget;
QWidget* sidebarWidget = new QWidget();
sidebarWidget->setLayout( new QVBoxLayout() );
m_sidebar = new AnimatedSplitter();
m_sidebar->setOrientation( Qt::Vertical );
m_sidebar->setChildrenCollapsible( false );
m_searchWidget = new QSearchField( m_sidebar );
m_searchWidget->setPlaceholderText( tr( "Global Search..." ) );
connect( m_searchWidget, SIGNAL( returnPressed() ), this, SLOT( onFilterEdited() ) );
m_sourcetree = new SourceTreeView();
TransferView* transferView = new TransferView( m_sidebar );
PipelineStatusView* pipelineView = new PipelineStatusView( m_sidebar );
m_queueView = new QueueView( m_sidebar );
m_queueModel = new PlaylistModel( m_queueView );
m_queueModel->setStyle( PlaylistModel::Short );
m_queueView->queue()->setPlaylistModel( m_queueModel );
m_queueView->queue()->playlistModel()->setReadOnly( false );
AudioEngine::instance()->setQueue( m_queueView->queue()->proxyModel() );
m_sidebar->addWidget( m_searchWidget );
m_sidebar->addWidget( m_sourcetree );
m_sidebar->addWidget( transferView );
m_sidebar->addWidget( pipelineView );
m_sidebar->addWidget( m_queueView );
m_sidebar->setGreedyWidget( 1 );
m_sidebar->hide( 1, false );
m_sidebar->hide( 2, false );
m_sidebar->hide( 3, false );
m_sidebar->hide( 4, false );
sidebarWidget->layout()->addWidget( m_sidebar );
sidebarWidget->setContentsMargins( 0, 0, 0, 0 );
sidebarWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
sidebarWidget->layout()->setMargin( 0 );
#ifndef Q_OS_MAC
sidebarWidget->layout()->setSpacing( 0 );
#endif
ui->splitter->addWidget( sidebarWidget );
ui->splitter->addWidget( ViewManager::instance()->widget() );
ui->splitter->setStretchFactor( 0, 1 );
ui->splitter->setStretchFactor( 1, 3 );
ui->splitter->setCollapsible( 1, false );
ui->splitter->setHandleWidth( 1 );
ui->actionShowOfflineSources->setChecked( TomahawkSettings::instance()->showOfflineSources() );
}
void
TomahawkWindow::setupUpdateCheck()
{
#ifndef Q_WS_MAC
ui->menu_Help->insertSeparator( ui->actionAboutTomahawk );
#endif
#if defined( Q_OS_DARWIN ) && defined( HAVE_SPARKLE )
QAction* checkForUpdates = ui->menu_Help->addAction( tr( "Check For Updates..." ) );
checkForUpdates->setMenuRole( QAction::ApplicationSpecificRole );
connect( checkForUpdates, SIGNAL( triggered( bool ) ), SLOT( checkForUpdates() ) );
#elif defined( WIN32 )
QUrl updaterUrl;
if ( qApp->arguments().contains( "--debug" ) )
updaterUrl.setUrl( "http://download.tomahawk-player.org/sparklewin-debug" );
else
updaterUrl.setUrl( "http://download.tomahawk-player.org/sparklewin" );
qtsparkle::Updater* updater = new qtsparkle::Updater( updaterUrl, this );
Q_ASSERT( TomahawkUtils::nam() != 0 );
updater->SetNetworkAccessManager( TomahawkUtils::nam() );
updater->SetVersion( TomahawkUtils::appFriendlyVersion() );
ui->menu_Help->addSeparator();
QAction* checkForUpdates = ui->menu_Help->addAction( tr( "Check For Updates..." ) );
connect( checkForUpdates, SIGNAL( triggered() ), updater, SLOT( CheckNow() ) );
#endif
}
void
TomahawkWindow::setupSignals()
{
// <From PlaylistManager>
connect( ViewManager::instance(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
m_audioControls, SLOT( onRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
connect( ViewManager::instance(), SIGNAL( shuffleModeChanged( bool ) ),
m_audioControls, SLOT( onShuffleModeChanged( bool ) ) );
// <From AudioEngine>
connect( AudioEngine::instance(), SIGNAL( loading( const Tomahawk::result_ptr& ) ),
SLOT( onPlaybackLoading( const Tomahawk::result_ptr& ) ) );
connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( audioStarted() ) );
connect( AudioEngine::instance(), SIGNAL( resumed()), SLOT( audioStarted() ) );
connect( AudioEngine::instance(), SIGNAL( paused() ), SLOT( audioStopped() ) );
connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( audioStopped() ) );
// <Menu Items>
// connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) );
connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) );
connect( ui->actionDiagnostics, SIGNAL( triggered() ), SLOT( showDiagnosticsDialog() ) );
connect( ui->actionToggleConnect, SIGNAL( triggered() ), SipHandler::instance(), SLOT( toggleConnect() ) );
connect( ui->actionUpdateCollection, SIGNAL( triggered() ), SLOT( updateCollectionManually() ) );
connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( rescanCollectionManually() ) );
connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() ));
connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() ));
connect( ui->actionCreate_New_Station, SIGNAL( triggered() ), SLOT( createStation() ));
connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) );
connect( ui->actionExit, SIGNAL( triggered() ), qApp, SLOT( quit() ) );
connect( ui->actionShowOfflineSources, SIGNAL( triggered() ), SLOT( showOfflineSources() ) );
connect( ui->actionPlay, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( playPause() ) );
connect( ui->actionNext, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( next() ) );
connect( ui->actionPrevious, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( previous() ) );
#if defined( Q_OS_DARWIN )
connect( ui->actionMinimize, SIGNAL( triggered() ), SLOT( minimize() ) );
connect( ui->actionZoom, SIGNAL( triggered() ), SLOT( maximize() ) );
#else
ui->menuWindow->clear();
ui->menuWindow->menuAction()->setVisible( false );
#endif
// <SipHandler>
connect( SipHandler::instance(), SIGNAL( connected( SipPlugin* ) ), SLOT( onSipConnected() ) );
connect( SipHandler::instance(), SIGNAL( disconnected( SipPlugin* ) ), SLOT( onSipDisconnected() ) );
connect( SipHandler::instance(), SIGNAL( authError( SipPlugin* ) ), SLOT( onSipError() ) );
// <SipMenu>
connect( SipHandler::instance(), SIGNAL( pluginAdded( SipPlugin* ) ), this, SLOT( onSipPluginAdded( SipPlugin* ) ) );
connect( SipHandler::instance(), SIGNAL( pluginRemoved( SipPlugin* ) ), this, SLOT( onSipPluginRemoved( SipPlugin* ) ) );
foreach( SipPlugin *plugin, SipHandler::instance()->allPlugins() )
{
connect( plugin, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
connect( plugin, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
}
}
@@ -338,7 +110,7 @@ TomahawkWindow::changeEvent( QEvent* e )
switch ( e->type() )
{
case QEvent::LanguageChange:
ui->retranslateUi( this );
retranslateUi();
break;
default:
@@ -358,7 +130,7 @@ TomahawkWindow::closeEvent( QCloseEvent* e )
return;
}
#else
m_trayIcon->setShowHideWindow( false );
s_trayIcon->setShowHideWindow( false );
#endif
e->accept();
@@ -388,245 +160,6 @@ TomahawkWindow::hideEvent( QHideEvent* e )
#endif
}
void
TomahawkWindow::showSettingsDialog()
{
qDebug() << Q_FUNC_INFO;
SettingsDialog win;
win.exec();
}
void TomahawkWindow::showDiagnosticsDialog()
{
qDebug() << Q_FUNC_INFO;
DiagnosticsDialog win;
win.exec();
}
void
TomahawkWindow::updateCollectionManually()
{
if ( TomahawkSettings::instance()->hasScannerPaths() )
ScanManager::instance()->runScan();
}
void
TomahawkWindow::rescanCollectionManually()
{
if ( TomahawkSettings::instance()->hasScannerPaths() )
ScanManager::instance()->runScan( true );
}
void
TomahawkWindow::addPeerManually()
{
TomahawkSettings* s = TomahawkSettings::instance();
bool ok;
QString addr = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer address:" ), QLineEdit::Normal,
s->value( "connip" ).toString(), &ok ); // FIXME
if ( !ok )
return;
s->setValue( "connip", addr );
QString ports = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer port:" ), QLineEdit::Normal,
s->value( "connport", "50210" ).toString(), &ok );
if ( !ok )
return;
s->setValue( "connport", ports );
int port = ports.toInt();
QString key = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer key:" ), QLineEdit::Normal,
"whitelist", &ok );
if ( !ok )
return;
qDebug() << "Attempting to connect to" << addr;
Servent::instance()->connectToPeer( addr, port, key );
}
void
TomahawkWindow::pluginMenuAdded( QMenu* menu )
{
ui->menuNetwork->addMenu( menu );
}
void
TomahawkWindow::pluginMenuRemoved( QMenu* menu )
{
foreach( QAction* action, ui->menuNetwork->actions() )
{
if( action->menu() == menu )
{
ui->menuNetwork->removeAction( action );
return;
}
}
}
void
TomahawkWindow::showOfflineSources()
{
m_sourcetree->showOfflineSources( ui->actionShowOfflineSources->isChecked() );
TomahawkSettings::instance()->setShowOfflineSources( ui->actionShowOfflineSources->isChecked() );
}
void
TomahawkWindow::loadSpiff()
{
bool ok;
QString urlstr = QInputDialog::getText( this, tr( "Load XSPF" ), tr( "Path:" ), QLineEdit::Normal, "http://ws.audioscrobbler.com/1.0/tag/metal/toptracks.xspf", &ok );
if ( !ok || urlstr.isEmpty() )
return;
XSPFLoader* loader = new XSPFLoader;
loader->load( QUrl::fromUserInput( urlstr ) );
}
void
TomahawkWindow::createAutomaticPlaylist( QString playlistName )
{
QString name = playlistName;
if ( name.isEmpty() )
return;
source_ptr author = SourceList::instance()->getLocal();
QString id = uuid();
QString info = ""; // FIXME
QString creator = "someone"; // FIXME
dynplaylist_ptr playlist = DynamicPlaylist::create( author, id, name, info, creator, Static, false );
playlist->setMode( Static );
playlist->createNewRevision( uuid(), playlist->currentrevision(), playlist->type(), playlist->generator()->controls(), playlist->entries() );
ViewManager::instance()->show( playlist );
}
void
TomahawkWindow::createStation()
{
bool ok;
QString name = QInputDialog::getText( this, tr( "Create New Station" ), tr( "Name:" ), QLineEdit::Normal, tr( "New Station" ), &ok );
if ( !ok || name.isEmpty() )
return;
source_ptr author = SourceList::instance()->getLocal();
QString id = uuid();
QString info = ""; // FIXME
QString creator = "someone"; // FIXME
dynplaylist_ptr playlist = DynamicPlaylist::create( author, id, name, info, creator, OnDemand, false );
playlist->setMode( OnDemand );
playlist->createNewRevision( uuid(), playlist->currentrevision(), playlist->type(), playlist->generator()->controls() );
ViewManager::instance()->show( playlist );
}
void
TomahawkWindow::createPlaylist()
{
PlaylistTypeSelectorDlg* playlistSelectorDlg = new PlaylistTypeSelectorDlg( TomahawkApp::instance()->mainWindow(), Qt::Sheet );
#ifndef Q_OS_MAC
playlistSelectorDlg->setModal( true );
#endif
connect( playlistSelectorDlg, SIGNAL( finished( int ) ), this, SLOT( playlistCreateDialogFinished( int ) ) );
playlistSelectorDlg->show();
}
void TomahawkWindow::playlistCreateDialogFinished( int ret )
{
PlaylistTypeSelectorDlg* playlistSelectorDlg = qobject_cast< PlaylistTypeSelectorDlg* >( sender() );
Q_ASSERT( playlistSelectorDlg );
QString playlistName = playlistSelectorDlg->playlistName();
if ( playlistName.isEmpty() )
playlistName = tr( "New Playlist" );
if ( !playlistSelectorDlg->playlistTypeIsAuto() && ret ) {
playlist_ptr playlist = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), playlistName, "", "", false, QList< query_ptr>() );
ViewManager::instance()->show( playlist );
} else if ( playlistSelectorDlg->playlistTypeIsAuto() && ret ) {
// create Auto Playlist
createAutomaticPlaylist( playlistName );
}
playlistSelectorDlg->deleteLater();
}
void
TomahawkWindow::audioStarted()
{
ui->actionPlay->setText( tr( "Pause" ) );
}
void
TomahawkWindow::audioStopped()
{
ui->actionPlay->setText( tr( "Play" ) );
}
void
TomahawkWindow::onPlaybackLoading( const Tomahawk::result_ptr& result )
{
m_currentTrack = result;
setWindowTitle( m_windowTitle );
}
void
TomahawkWindow::onSipConnected()
{
ui->actionToggleConnect->setText( tr( "Go &offline" ) );
}
void
TomahawkWindow::onSipDisconnected()
{
ui->actionToggleConnect->setText( tr( "Go &online" ) );
}
void
TomahawkWindow::onSipPluginAdded( SipPlugin* p )
{
connect( p, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
connect( p, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
}
void
TomahawkWindow::onSipPluginRemoved( SipPlugin* p )
{
Q_UNUSED( p );
}
void
TomahawkWindow::onSipError()
{
onSipDisconnected();
QMessageBox::warning( this,
tr( "Authentication Error" ),
QString( "Error connecting to SIP: Authentication failed!" ),
QMessageBox::Ok );
}
void
TomahawkWindow::setWindowTitle( const QString& title )
{
@@ -642,70 +175,6 @@ TomahawkWindow::setWindowTitle( const QString& title )
}
void
TomahawkWindow::showAboutTomahawk()
{
QMessageBox::about( this, tr( "About Tomahawk" ),
tr( "<h2><b>Tomahawk %1<br/>(%2)</h2>Copyright 2010, 2011<br/>Christian Muehlhaeuser &lt;muesli@tomahawk-player.org&gt;<br/><br/>"
"Thanks to: Leo Franchi, Jeff Mitchell, Dominik Schmidt, Jason Herskowitz, Alejandro Wainzinger, Michael Zanetti, Harald Sitter and Steve Robertson" )
.arg( TomahawkUtils::appFriendlyVersion() )
.arg( qApp->applicationVersion() ) );
}
void
TomahawkWindow::checkForUpdates()
{
#ifdef Q_WS_MAC
Tomahawk::checkForUpdates();
#endif
}
void
TomahawkWindow::onSearch( const QString& search )
{
if ( !search.trimmed().isEmpty() )
ViewManager::instance()->show( new SearchWidget( search, this ) );
}
void
TomahawkWindow::onFilterEdited()
{
onSearch( m_searchWidget->text() );
m_searchWidget->clear();
}
void
TomahawkWindow::showQueue()
{
if ( QThread::currentThread() != thread() )
{
qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO;
QMetaObject::invokeMethod( this, "showQueue", Qt::QueuedConnection );
return;
}
m_queueView->show();
}
void
TomahawkWindow::hideQueue()
{
if ( QThread::currentThread() != thread() )
{
qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO;
QMetaObject::invokeMethod( this, "hideQueue", Qt::QueuedConnection );
return;
}
m_queueView->hide();
}
void
TomahawkWindow::minimize()
{
@@ -732,3 +201,29 @@ TomahawkWindow::maximize()
showMaximized();
}
}
void
TomahawkWindow::onPlaybackLoading( const Tomahawk::result_ptr& result )
{
m_currentTrack = result;
setWindowTitle( m_windowTitle );
}
void
TomahawkWindow::retranslateUi()
{
}
void
TomahawkWindow::setupSignals()
{
// <From AudioEngine>
connect( AudioEngine::instance(), SIGNAL( loading( const Tomahawk::result_ptr& ) ),
SLOT( onPlaybackLoading( const Tomahawk::result_ptr& ) ) );
}

View File

@@ -20,114 +20,49 @@
#define TOMAHAWKWINDOW_H
#include <QMainWindow>
#include <QVariantMap>
#include <QPushButton>
#include <QString>
#include <QStackedWidget>
#include "result.h"
class QSearchField;
class SipPlugin;
class SourceTreeView;
class QAction;
class MusicScanner;
class AudioControls;
class SourcesModel;
class TomahawkTrayIcon;
class PlaylistModel;
class QueueView;
class AnimatedSplitter;
namespace Ui
{
class TomahawkWindow;
class GlobalSearchWidget;
}
class TomahawkWindow : public QMainWindow
{
Q_OBJECT
Q_OBJECT
public:
TomahawkWindow( QWidget* parent = 0 );
~TomahawkWindow();
AudioControls* audioControls() { return m_audioControls; }
SourceTreeView* sourceTreeView() const { return m_sourcetree; }
void setWindowTitle( const QString& title );
virtual void setWindowTitle( const QString& title );
protected:
void changeEvent( QEvent* e );
void closeEvent( QCloseEvent* e );
void showEvent( QShowEvent* e );
void hideEvent( QHideEvent* e );
virtual void changeEvent( QEvent* e );
virtual void closeEvent( QCloseEvent* e );
virtual void showEvent( QShowEvent* e );
virtual void hideEvent( QHideEvent* e );
public slots:
void createAutomaticPlaylist( QString );
void createStation();
void createPlaylist();
void loadSpiff();
void showSettingsDialog();
void showDiagnosticsDialog();
void updateCollectionManually();
void rescanCollectionManually();
void pluginMenuAdded(QMenu*);
void pluginMenuRemoved(QMenu*);
void showOfflineSources();
virtual void retranslateUi();
virtual void loadSettings();
virtual void saveSettings();
private slots:
void onSipConnected();
void onSipDisconnected();
void onSipError();
void addPeerManually();
virtual void minimize();
virtual void maximize();
void onPlaybackLoading( const Tomahawk::result_ptr& result );
void audioStarted();
void audioStopped();
void showAboutTomahawk();
void checkForUpdates();
void onSipPluginAdded( SipPlugin* p );
void onSipPluginRemoved( SipPlugin* p );
void onSearch( const QString& search );
void onFilterEdited();
void showQueue();
void hideQueue();
void minimize();
void maximize();
void playlistCreateDialogFinished( int ret );
private:
void loadSettings();
void saveSettings();
void applyPlatformTweaks();
void setupSignals();
void setupSideBar();
void setupUpdateCheck();
Ui::TomahawkWindow* ui;
QSearchField* m_searchWidget;
AudioControls* m_audioControls;
TomahawkTrayIcon* m_trayIcon;
SourceTreeView* m_sourcetree;
QPushButton* m_statusButton;
QPushButton* m_queueButton;
PlaylistModel* m_queueModel;
QueueView* m_queueView;
AnimatedSplitter* m_sidebar;
protected:
static SourcesModel* s_sourcesModel;
static TomahawkTrayIcon* s_trayIcon;
Tomahawk::result_ptr m_currentTrack;
QString m_windowTitle;
Tomahawk::result_ptr m_currentTrack;
};
#endif // TOMAHAWKWINDOW_H