diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 43d79f943..d12311a12 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/sourcetree/items/categoryitems.cpp b/src/sourcetree/items/categoryitems.cpp index 00cd45f57..f90ee3ae6 100644 --- a/src/sourcetree/items/categoryitems.cpp +++ b/src/sourcetree/items/categoryitems.cpp @@ -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() ) ); } } diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 644aeefc8..46cdabc7b 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -64,7 +64,7 @@ #include "config.h" #ifndef TOMAHAWK_HEADLESS - #include "tomahawkwindow.h" + #include "tomahawkdesktopwindow.h" #include "settingsdialog.h" #include #endif @@ -223,7 +223,7 @@ 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" ); @@ -340,6 +340,20 @@ TomahawkApp::audioControls() { return m_mainwindow->audioControls(); } + + +TomahawkWindow* +TomahawkApp::mainWindow() const +{ + // why does static_casdt not work here?! + return (TomahawkWindow*) ( m_mainwindow ); +} + +TomahawkDesktopWindow* +TomahawkApp::desktopWindow() const +{ + return m_mainwindow; +} #endif diff --git a/src/tomahawkapp.h b/src/tomahawkapp.h index af934880b..ecfb549c8 100644 --- a/src/tomahawkapp.h +++ b/src/tomahawkapp.h @@ -65,7 +65,8 @@ namespace Tomahawk #endif #ifndef TOMAHAWK_HEADLESS -class TomahawkWindow; +class TomahawkDesktopWindow; +class AudioControls; #endif #ifdef TOUCHMAHAWK @@ -91,7 +92,8 @@ public: #ifndef TOMAHAWK_HEADLESS AudioControls* audioControls(); - TomahawkWindow* mainWindow() const { return m_mainwindow; } + TomahawkWindow* mainWindow() const; + TomahawkDesktopWindow* desktopWindow() const; #endif #ifdef TOUCHMAHAWK @@ -144,7 +146,7 @@ private: #endif #ifndef TOMAHAWK_HEADLESS - TomahawkWindow* m_mainwindow; + TomahawkDesktopWindow* m_mainwindow; #endif #ifdef TOUCHMAHAWK diff --git a/src/tomahawkdesktopwindow.cpp b/src/tomahawkdesktopwindow.cpp new file mode 100644 index 000000000..63f3d8002 --- /dev/null +++ b/src/tomahawkdesktopwindow.cpp @@ -0,0 +1,609 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "tomahawkdesktopwindow.h" +#include "ui_tomahawkdesktopwindow.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 +#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 ) ) +{ + ViewManager* vm = new ViewManager( this ); + connect( vm, SIGNAL( showQueueRequested() ), SLOT( showQueue() ) ); + connect( vm, 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(); + vm->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(); + 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() +{ + // + 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 ) ) ); + + // + 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() ) ); + + // + // 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 + + // + connect( SipHandler::instance(), SIGNAL( connected( SipPlugin* ) ), SLOT( onSipConnected() ) ); + connect( SipHandler::instance(), SIGNAL( disconnected( SipPlugin* ) ), SLOT( onSipDisconnected() ) ); + connect( SipHandler::instance(), SIGNAL( authError( SipPlugin* ) ), SLOT( onSipError() ) ); + + // + 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::onPlaybackLoading( const Tomahawk::result_ptr& result ) +{ + m_currentTrack = result; + setWindowTitle( m_windowTitle ); +} + +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( "

Tomahawk %1
(%2)

Copyright 2010, 2011
Christian Muehlhaeuser <muesli@tomahawk-player.org>

" + "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(); +} diff --git a/src/tomahawkdesktopwindow.h b/src/tomahawkdesktopwindow.h new file mode 100644 index 000000000..3633116a1 --- /dev/null +++ b/src/tomahawkdesktopwindow.h @@ -0,0 +1,125 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef TOMAHAWKDESKTOPWINDOW_H +#define TOMAHAWKDESKTOPWINDOW_H + +#include "result.h" +#include "tomahawkwindow.h" + +#include +#include +#include +#include +#include + +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 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 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; + + Tomahawk::result_ptr m_currentTrack; + QString m_windowTitle; +}; + +#endif // TOMAHAWKDESKTOPWINDOW_H diff --git a/src/tomahawkdesktopwindow.ui b/src/tomahawkdesktopwindow.ui new file mode 100644 index 000000000..4397ab632 --- /dev/null +++ b/src/tomahawkdesktopwindow.ui @@ -0,0 +1,267 @@ + + + TomahawkDesktopWindow + + + + 0 + 0 + 1000 + 660 + + + + Tomahawk + + + + + + + + 16777215 + 1 + + + + QFrame::HLine + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + 1 + + + + + + + + + + 16777215 + 1 + + + + QFrame::HLine + + + QFrame::Raised + + + + + + + + + 0 + 0 + 1000 + 22 + + + + + &Settings + + + + + + &Music Player + + + + + + + + + + + + + + + &Network + + + + + + + &Window + + + + + + + &Help + + + + + + + &Playlist + + + + + + + + + + + + + + + + + &Quit + + + Ctrl+Q + + + QAction::QuitRole + + + + + Go &Online + + + + + Add &Friend... + + + + + U&pdate Collection + + + Update Collection + + + + + &Configure Tomahawk... + + + QAction::PreferencesRole + + + + + Load &XSPF... + + + + + Create &New Playlist... + + + + + About &Tomahawk... + + + QAction::AboutRole + + + + + Create New &Automatic Playlist + + + + + Create New &Station + + + + + true + + + Show Offline Sources + + + + + Hide Offline Sources + + + + + Minimize + + + Ctrl+M + + + + + Zoom + + + Meta+Ctrl+Z + + + + + Diagnostics... + + + QAction::ApplicationSpecificRole + + + + + Fully &Rescan Collection + + + Fully Rescan Collection + + + + + Play + + + Space + + + + + Previous + + + + + Next + + + + + + + + on_btnResolve_clicked() + + diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 51c6c0542..14da673c9 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -17,97 +17,29 @@ */ #include "tomahawkwindow.h" -#include "ui_tomahawkwindow.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#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" -#ifdef Q_OS_WIN32 -#include -#endif - -#include "utils/logger.h" +#include using namespace Tomahawk; 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() ) ); - - 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(); - vm->setQueue( m_queueView ); - vm->showWelcomePage(); } TomahawkWindow::~TomahawkWindow() { saveSettings(); - delete ui; } @@ -135,8 +67,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 +84,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() -{ - // - 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 ) ) ); - - // - 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() ) ); - - // - // 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 - - // - connect( SipHandler::instance(), SIGNAL( connected( SipPlugin* ) ), SLOT( onSipConnected() ) ); - connect( SipHandler::instance(), SIGNAL( disconnected( SipPlugin* ) ), SLOT( onSipDisconnected() ) ); - connect( SipHandler::instance(), SIGNAL( authError( SipPlugin* ) ), SLOT( onSipError() ) ); - - // - 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 +95,7 @@ TomahawkWindow::changeEvent( QEvent* e ) switch ( e->type() ) { case QEvent::LanguageChange: - ui->retranslateUi( this ); + retranslateUi(); break; default: @@ -388,245 +145,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 +160,6 @@ TomahawkWindow::setWindowTitle( const QString& title ) } -void -TomahawkWindow::showAboutTomahawk() -{ - QMessageBox::about( this, tr( "About Tomahawk" ), - tr( "

Tomahawk %1
(%2)

Copyright 2010, 2011
Christian Muehlhaeuser <muesli@tomahawk-player.org>

" - "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 +186,10 @@ TomahawkWindow::maximize() showMaximized(); } } + + +void +TomahawkWindow::retranslateUi() +{ + +} diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index 3ee444235..b027fbcaa 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -20,112 +20,38 @@ #define TOMAHAWKWINDOW_H #include -#include -#include -#include -#include #include "result.h" -class QSearchField; -class SipPlugin; -class SourceTreeView; -class QAction; - -class MusicScanner; -class AudioControls; 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(); - - 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 ); + virtual void minimize(); + virtual void maximize(); 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; - Tomahawk::result_ptr m_currentTrack; QString m_windowTitle; };