From fb06624821cf9b15d1962a064d55a32e704daa86 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Thu, 26 May 2011 19:41:47 -0400 Subject: [PATCH] Add a new "Create Playlist" dialog that is shown when the user presses New Playlist. This lets the user select between a normal playlist and an automatic playlist. Thanks for Christopher Reichert for the patch! --- src/libtomahawk/CMakeLists.txt | 3 + src/libtomahawk/widgets/newplaylistwidget.ui | 6 + .../widgets/playlisttypeselectordlg.cpp | 88 +++++++++ .../widgets/playlisttypeselectordlg.h | 55 ++++++ .../widgets/playlisttypeselectordlg.ui | 184 ++++++++++++++++++ src/sourcetree/items/categoryitems.cpp | 29 ++- src/tomahawkwindow.cpp | 27 ++- src/tomahawkwindow.h | 2 +- src/tomahawkwindow.ui | 21 +- 9 files changed, 391 insertions(+), 24 deletions(-) create mode 100644 src/libtomahawk/widgets/playlisttypeselectordlg.cpp create mode 100644 src/libtomahawk/widgets/playlisttypeselectordlg.h create mode 100644 src/libtomahawk/widgets/playlisttypeselectordlg.ui diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index e48c4769c..991daedc1 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -161,6 +161,7 @@ set( libSources utils/xspfgenerator.cpp widgets/newplaylistwidget.cpp + widgets/playlisttypeselectordlg.cpp widgets/welcomewidget.cpp widgets/welcomeplaylistmodel.cpp widgets/overlaywidget.cpp @@ -324,6 +325,7 @@ set( libHeaders utils/xspfgenerator.h widgets/newplaylistwidget.h + widgets/playlisttypeselectordlg.h widgets/welcomewidget.h widgets/welcomeplaylistmodel.h widgets/overlaywidget.h @@ -339,6 +341,7 @@ set( libHeaders_NoMOC playlist/dynamic/GeneratorInterface.h ) set( libUI ${libUI} + widgets/playlisttypeselectordlg.ui widgets/newplaylistwidget.ui widgets/welcomewidget.ui widgets/infowidgets/sourceinfowidget.ui diff --git a/src/libtomahawk/widgets/newplaylistwidget.ui b/src/libtomahawk/widgets/newplaylistwidget.ui index 6a2701ee8..e3a145050 100644 --- a/src/libtomahawk/widgets/newplaylistwidget.ui +++ b/src/libtomahawk/widgets/newplaylistwidget.ui @@ -10,6 +10,9 @@ 460 + + Qt::TabFocus + @@ -31,6 +34,9 @@ 26 + + Qt::StrongFocus + diff --git a/src/libtomahawk/widgets/playlisttypeselectordlg.cpp b/src/libtomahawk/widgets/playlisttypeselectordlg.cpp new file mode 100644 index 000000000..5f3802661 --- /dev/null +++ b/src/libtomahawk/widgets/playlisttypeselectordlg.cpp @@ -0,0 +1,88 @@ +/* === 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 "widgets/newplaylistwidget.h" +#include "viewmanager.h" +#include "viewpage.h" +#include "sourcelist.h" + +#include "playlisttypeselectordlg.h" +#include "ui_playlisttypeselectordlg.h" + + +PlaylistTypeSelectorDlg::PlaylistTypeSelectorDlg( QWidget* parent, Qt::WindowFlags f ) + : QDialog( parent, f ) + , ui( new Ui::PlaylistTypeSelectorDlg ) +{ + ui->setupUi( this ); + +#ifdef Q_WS_MAC +// ui-> + ui->horizontalLayout_2->setContentsMargins( 4, 4, 4, 4 ); + + setSizeGripEnabled( false ); + setMinimumSize( size() ); + setMaximumSize( size() ); // to remove the resize grip on osx this is the only way +#endif + + m_isAutoPlaylist = false; + m_playlistName = ""; + + connect( ui->manualPlaylistButton, SIGNAL( clicked() ), + this, SLOT( createNormalPlaylist() )); + connect( ui->autoPlaylistButton, SIGNAL( clicked() ), + this, SLOT( createAutomaticPlaylist() )); + connect( ui->autoPlaylistNameLine, SIGNAL( textChanged( const QString& )), + this, SLOT( enableAutoPlaylistButton( const QString& ))); +} + +PlaylistTypeSelectorDlg::~PlaylistTypeSelectorDlg() +{ + delete ui; +} + +void +PlaylistTypeSelectorDlg::createNormalPlaylist() +{ + m_isAutoPlaylist = false; + done( QDialog::Accepted ); // return code is used to vaidate we did not exit out of the Dialog +} + +void PlaylistTypeSelectorDlg::createAutomaticPlaylist() { m_isAutoPlaylist = true; + m_playlistName = ui->autoPlaylistNameLine->text(); + done( QDialog::Accepted ); // return code is used to vaidate we did not exit out of the Dialog successfully +} + +QString +PlaylistTypeSelectorDlg::playlistName() const +{ + return m_playlistName; +} + +bool +PlaylistTypeSelectorDlg::playlistTypeIsAuto() const +{ + return m_isAutoPlaylist; +} + +void +PlaylistTypeSelectorDlg::enableAutoPlaylistButton( const QString &text ) +{ + ui->autoPlaylistButton->setEnabled( !text.isEmpty() ); +} + diff --git a/src/libtomahawk/widgets/playlisttypeselectordlg.h b/src/libtomahawk/widgets/playlisttypeselectordlg.h new file mode 100644 index 000000000..a0331a112 --- /dev/null +++ b/src/libtomahawk/widgets/playlisttypeselectordlg.h @@ -0,0 +1,55 @@ +/* === 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 PLAYLISTTYPESELECTORDLG_H +#define PLAYLISTTYPESELECTORDLG_H + +#include + +#include "dllmacro.h" + +namespace Ui +{ + class PlaylistTypeSelectorDlg; +} + +class DLLEXPORT PlaylistTypeSelectorDlg : public QDialog +{ +Q_OBJECT + +public: + PlaylistTypeSelectorDlg( QWidget* parent = 0, Qt::WindowFlags = 0 ); + ~PlaylistTypeSelectorDlg(); + bool playlistTypeIsNormal() const; + bool playlistTypeIsAuto() const; + QString playlistName() const; + +private slots: + void createNormalPlaylist(); + void createAutomaticPlaylist(); + void enableAutoPlaylistButton( const QString& ); + +private: + bool m_isAutoPlaylist; // if not an auto playlist then its a normal playlist + + Ui::PlaylistTypeSelectorDlg *ui; + QString m_playlistName; + +}; + +#endif // PlaylistTypeSelectorDlg_H diff --git a/src/libtomahawk/widgets/playlisttypeselectordlg.ui b/src/libtomahawk/widgets/playlisttypeselectordlg.ui new file mode 100644 index 000000000..bc4cb8e32 --- /dev/null +++ b/src/libtomahawk/widgets/playlisttypeselectordlg.ui @@ -0,0 +1,184 @@ + + + PlaylistTypeSelectorDlg + + + + 0 + 0 + 554 + 169 + + + + + 0 + 0 + + + + + 482 + 145 + + + + + 10000 + 10000 + + + + New Playlist + + + false + + + + + + 0 + + + 2 + + + + + + 221 + 40 + + + + Just a regular old playlist... Give it a name, drag in some tracks, and go! + + + true + + + 2 + + + + + + + Qt::Vertical + + + + 20 + 28 + + + + + + + + Create Manual Playlist + + + + + + + + + Qt::Vertical + + + + + + + 4 + + + 1 + + + + + + 0 + 0 + + + + Don't know exactly what you want? Give Tomahawk a few pointers and let it build a playlist for you! + + + true + + + 1 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Name: + + + 1 + + + + + + + New Playlist... + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + false + + + Create Automatic Playlist + + + + + + + + + + diff --git a/src/sourcetree/items/categoryitems.cpp b/src/sourcetree/items/categoryitems.cpp index a66e54719..c51a92748 100644 --- a/src/sourcetree/items/categoryitems.cpp +++ b/src/sourcetree/items/categoryitems.cpp @@ -19,6 +19,7 @@ #include "tomahawkapp.h" #include "utils/tomahawkutils.h" #include "widgets/newplaylistwidget.h" +#include "widgets/playlisttypeselectordlg.h" #include "viewmanager.h" #include "viewpage.h" #include "sourcelist.h" @@ -59,13 +60,28 @@ CategoryAddItem::activate() { switch( m_categoryType ) { - case SourcesModel::PlaylistsCategory: - // only show if none is shown yet - if( !ViewManager::instance()->isNewPlaylistPageVisible() ) { - ViewPage* p = ViewManager::instance()->show( new NewPlaylistWidget() ); - model()->linkSourceItemToPage( this, p ); + case SourcesModel::PlaylistsCategory: { + + PlaylistTypeSelectorDlg playlistSelectorDlg( TomahawkApp::instance()->mainWindow() ); + int successfulReturn = playlistSelectorDlg.exec(); + + if ( !playlistSelectorDlg.playlistTypeIsAuto() && successfulReturn ) { + + // only show if none is shown yet + if( !ViewManager::instance()->isNewPlaylistPageVisible() ) { + //fix this namespace resolution problem, was not there before + Tomahawk::ViewPage* p = ViewManager::instance()->show( new NewPlaylistWidget() ); + model()->linkSourceItemToPage( this, p ); + } + + } else if ( playlistSelectorDlg.playlistTypeIsAuto() && successfulReturn ) { + // create Auto Playlist + QString playlistName = playlistSelectorDlg.playlistName(); + APP->mainWindow()->createAutomaticPlaylist( playlistName ); } + break; + } case SourcesModel::StationsCategory: APP->mainWindow()->createStation(); break; @@ -217,5 +233,6 @@ CategoryItem::activate() { if( m_category == SourcesModel::StationsCategory ) { // TODO activate stations page - } + } + } diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 251fc7205..173b43f03 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -50,6 +50,7 @@ #include "utils/widgetdragfilter.h" #include "utils/xspfloader.h" #include "widgets/newplaylistwidget.h" +#include "widgets/playlisttypeselectordlg.h" #include "audiocontrols.h" #include "settingsdialog.h" @@ -274,7 +275,6 @@ TomahawkWindow::setupSignals() connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( updateCollectionManually() ) ); connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() )); connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() )); - connect( ui->actionCreateAutomaticPlaylist, SIGNAL( triggered() ), SLOT( createAutomaticPlaylist() )); connect( ui->actionCreate_New_Station, SIGNAL( triggered() ), SLOT( createStation() )); connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) ); connect( ui->actionExit, SIGNAL( triggered() ), qApp, SLOT( quit() ) ); @@ -444,11 +444,11 @@ TomahawkWindow::loadSpiff() void -TomahawkWindow::createAutomaticPlaylist() +TomahawkWindow::createAutomaticPlaylist( QString playlistName ) { - bool ok; - QString name = QInputDialog::getText( this, tr( "Create New Automatic Playlist" ), tr( "Name:" ), QLineEdit::Normal, tr( "New Automatic Playlist" ), &ok ); - if ( !ok || name.isEmpty() ) + QString name = playlistName; + + if ( name.isEmpty() ) return; source_ptr author = SourceList::instance()->getLocal(); @@ -484,7 +484,22 @@ TomahawkWindow::createStation() void TomahawkWindow::createPlaylist() { - ViewManager::instance()->show( new NewPlaylistWidget() ); + PlaylistTypeSelectorDlg playlistSelectorDlg; + int successfulReturn = playlistSelectorDlg.exec(); + + qDebug() << "\n\nSTAT == " << successfulReturn; + if ( !playlistSelectorDlg.playlistTypeIsAuto() && successfulReturn ) { + + // only show if none is shown yet + if( !ViewManager::instance()->isNewPlaylistPageVisible() ) { + ViewManager::instance()->show( new NewPlaylistWidget() ); + } + + } else if ( playlistSelectorDlg.playlistTypeIsAuto() && successfulReturn ) { + // create Auto Playlist + QString playlistName = playlistSelectorDlg.playlistName(); + APP->mainWindow()->createAutomaticPlaylist( playlistName ); + } } diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index 730ba47ce..e724f7313 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -61,7 +61,7 @@ protected: void hideEvent( QHideEvent* e ); public slots: - void createAutomaticPlaylist(); + void createAutomaticPlaylist( QString ); void createStation(); void createPlaylist(); void loadSpiff(); diff --git a/src/tomahawkwindow.ui b/src/tomahawkwindow.ui index 092aea983..5e5bf7c3f 100644 --- a/src/tomahawkwindow.ui +++ b/src/tomahawkwindow.ui @@ -35,7 +35,7 @@ 0 0 1000 - 22 + 21 @@ -55,16 +55,6 @@ - - - &Playlist - - - - - - - &Network @@ -86,6 +76,15 @@ + + + &Playlist + + + + + +