[kde-doc-english] [amarok] /: Save new playlist by dropping in browser.
Bart Cerneels
bart.cerneels at kde.org
Mon Oct 31 17:12:18 UTC 2011
Git commit 83e490ba358b5bad968e41fe94fc92ade253812b by Bart Cerneels.
Committed on 22/07/2011 at 16:36.
Pushed by shanachie into branch 'master'.
Save new playlist by dropping in browser.
GUI:Drop tracks on the empty area in Saved Playlists to create a new playlist.
M +2 -0 ChangeLog
M +18 -8 src/browsers/playlistbrowser/PlaylistBrowserModel.cpp
M +70 -0 src/core/support/Amarok.cpp
M +8 -0 src/core/support/Amarok.h
M +2 -3 src/playlist/PlaylistDock.cpp
M +0 -68 src/playlist/PlaylistModel.cpp
M +0 -1 src/playlist/PlaylistModel.h
http://commits.kde.org/amarok/83e490ba358b5bad968e41fe94fc92ade253812b
diff --git a/ChangeLog b/ChangeLog
index 50c375b..0b87f8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@ Amarok ChangeLog
Version 2.5.0-Beta 1
FEATURES:
+ * Enable dropping tracks on empty area in Saved Playlists to create new
+ playlist.
* Addded a "create new playlist" action in the empty space of the Saved
Playlists. (BR202725)
* Add new type of optional tokens in format string (Collection Organizer)
diff --git a/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp b/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp
index ce87656..e507547 100644
--- a/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp
+++ b/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp
@@ -21,6 +21,7 @@
#include "AmarokMimeData.h"
#include "playlistmanager/PlaylistManager.h"
#include "playlist/PlaylistController.h"
+#include "playlist/PlaylistModel.h"
#include "core/support/Debug.h"
#include <KIcon>
@@ -481,17 +482,26 @@ PlaylistBrowserModel::dropMimeData( const QMimeData *data, Qt::DropAction action
}
else if( data->hasFormat( AmarokMimeData::TRACK_MIME ) )
{
- debug() << "Dropped track on " << parent << " at row: " << row;
+ Meta::TrackList tracks = amarokMime->tracks();
+ if( !parent.isValid() && row == -1 )
+ {
+ debug() << "Dropped tracks on empty area: create new playlist";
+ //TODO: use Playlist::Model::generatePlaylistName()
+ The::playlistManager()->save( tracks, Amarok::generatePlaylistName( tracks ) );
+ }
+ else
+ {
+ debug() << "Dropped track on " << parent << " at row: " << row;
- Playlists::PlaylistPtr playlist = playlistFromIndex( parent );
- if( !playlist )
- return false;
+ Playlists::PlaylistPtr playlist = playlistFromIndex( parent );
+ if( !playlist )
+ return false;
- Meta::TrackList tracks = amarokMime->tracks();
- foreach( Meta::TrackPtr track, tracks )
- playlist->addTrack( track, row++ );
+ foreach( Meta::TrackPtr track, tracks )
+ playlist->addTrack( track, row++ );
- return true;
+ return true;
+ }
}
return false;
diff --git a/src/core/support/Amarok.cpp b/src/core/support/Amarok.cpp
index 8657fd1..959f7c1 100644
--- a/src/core/support/Amarok.cpp
+++ b/src/core/support/Amarok.cpp
@@ -159,6 +159,76 @@ namespace Amarok
str.truncate( newLen );
}
+ QString generatePlaylistName( const Meta::TrackList tracks )
+ {
+ QString datePart = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime(),
+ KLocale::ShortDate, true );
+ if( tracks.count() == 0 )
+ {
+ return i18nc( "A saved playlist with the current time (KLocale::Shortdate) added between \
+ the parentheses",
+ "Empty Playlist (%1)", datePart );
+ }
+
+ bool singleArtist = true;
+ bool singleAlbum = true;
+
+ Meta::ArtistPtr artist = tracks.first()->artist();
+ Meta::AlbumPtr album = tracks.first()->album();
+
+ QString artistPart;
+ QString albumPart;
+
+ foreach( const Meta::TrackPtr track, tracks )
+ {
+ if( artist != track->artist() )
+ singleArtist = false;
+
+ if( album != track->album() )
+ singleAlbum = false;
+
+ if ( !singleArtist && !singleAlbum )
+ break;
+ }
+
+ if( ( !singleArtist && !singleAlbum ) ||
+ ( !artist && !album ) )
+ return i18nc( "A saved playlist with the current time (KLocale::Shortdate) added between \
+ the parentheses",
+ "Various Tracks (%1)", datePart );
+
+ if( singleArtist )
+ {
+ if( artist )
+ artistPart = artist->prettyName();
+ else
+ artistPart = i18n( "Unknown Artist(s)" );
+ }
+ else if( album && album->hasAlbumArtist() && singleAlbum )
+ {
+ artistPart = album->albumArtist()->prettyName();
+ }
+ else
+ {
+ artistPart = i18n( "Various Artists" );
+ }
+
+ if( singleAlbum )
+ {
+ if( album )
+ albumPart = album->prettyName();
+ else
+ albumPart = i18n( "Unknown Album(s)" );
+ }
+ else
+ {
+ albumPart = i18n( "Various Albums" );
+ }
+
+ return i18nc( "A saved playlist titled <artist> - <album>", "%1 - %2",
+ artistPart, albumPart );
+ }
+
KActionCollection* actionCollection() // TODO: constify?
{
if( !actionCollectionObject )
diff --git a/src/core/support/Amarok.h b/src/core/support/Amarok.h
index 7d303a7..c985215 100644
--- a/src/core/support/Amarok.h
+++ b/src/core/support/Amarok.h
@@ -18,6 +18,8 @@
#ifndef AMAROK_H
#define AMAROK_H
+#include "core/meta/Meta.h"
+
#include "shared/amarok_export.h"
#include "shared/Version.h"
@@ -187,6 +189,12 @@ namespace Amarok
AMAROK_CORE_EXPORT void manipulateThe( QString &str, bool reverse );
/**
+ * Return a playlist name based on the artist and album info of the tracks or a string
+ * containing the creation date.
+ */
+ AMAROK_CORE_EXPORT QString generatePlaylistName( const Meta::TrackList tracks );
+
+ /**
* Creates a semi-transparent Amarok logo for suitable for painting.
* @param dim width of the logo
* @return A QPixmap of the logo
diff --git a/src/playlist/PlaylistDock.cpp b/src/playlist/PlaylistDock.cpp
index b0f3aab..b03de57 100644
--- a/src/playlist/PlaylistDock.cpp
+++ b/src/playlist/PlaylistDock.cpp
@@ -299,9 +299,8 @@ Playlist::Dock::slotSaveCurrentPlaylist()
action->data().value< QWeakPointer<Playlists::UserPlaylistProvider> >();
Playlists::UserPlaylistProvider* provider = pointer.data();
- The::playlistManager()->save( The::playlist()->tracks(),
- Playlist::ModelStack::instance()->bottom()->generatePlaylistName(),
- provider );
+ const Meta::TrackList tracks = The::playlist()->tracks();
+ The::playlistManager()->save( tracks, Amarok::generatePlaylistName( tracks ), provider );
}
void
diff --git a/src/playlist/PlaylistModel.cpp b/src/playlist/PlaylistModel.cpp
index 29c7f3e..0770689 100644
--- a/src/playlist/PlaylistModel.cpp
+++ b/src/playlist/PlaylistModel.cpp
@@ -854,74 +854,6 @@ Playlist::Model::tracks() const
}
QString
-Playlist::Model::generatePlaylistName() const
-{
- QString datePart = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime(),
- KLocale::ShortDate, true );
- Meta::TrackList trackList = tracks();
-
- if( trackList.count() == 0 )
- {
- return i18nc( "A saved playlist with the current time (KLocale::Shortdate) added between \
- the parentheses",
- "Empty Playlist (%1)", datePart );
- }
-
- bool singleArtist = true;
- bool singleAlbum = true;
-
- Meta::ArtistPtr artist = trackList.first()->artist();
- Meta::AlbumPtr album = trackList.first()->album();
-
- QString artistPart;
- QString albumPart;
-
- foreach( const Meta::TrackPtr track, trackList )
- {
- if( artist != track->artist() )
- singleArtist = false;
-
- if( album != track->album() )
- singleAlbum = false;
-
- if ( !singleArtist && !singleAlbum )
- break;
- }
-
- if( ( !singleArtist && !singleAlbum ) ||
- ( !artist && !album ) )
- return i18nc( "A saved playlist with the current time (KLocale::Shortdate) added between \
- the parentheses",
- "Various Tracks (%1)", datePart );
-
- if( singleArtist )
- {
- if( artist )
- artistPart = artist->prettyName();
- else
- artistPart = i18n( "Unknown Artist(s)" );
- }
- else if( album && album->hasAlbumArtist() && singleAlbum )
- artistPart = album->albumArtist()->prettyName();
- else
- artistPart = i18n( "Various Artists" );
-
- if( singleAlbum )
- {
- if( album )
- albumPart = album->prettyName();
- else
- albumPart = i18n( "Unknown Album(s)" );
- }
- else
- albumPart = i18n( "Various Albums" );
-
- return i18nc( "A saved playlist titled <artist> - <album>", "%1 - %2",
- artistPart, albumPart );
-
-}
-
-QString
Playlist::Model::prettyColumnName( Column index ) //static
{
switch ( index )
diff --git a/src/playlist/PlaylistModel.h b/src/playlist/PlaylistModel.h
index 488ff0f..d325ce6 100644
--- a/src/playlist/PlaylistModel.h
+++ b/src/playlist/PlaylistModel.h
@@ -94,7 +94,6 @@ class AMAROK_EXPORT Model : public QAbstractListModel, public Meta::Observer, pu
Meta::TrackPtr trackAt( int row ) const;
Meta::TrackPtr trackForId( const quint64 id ) const;
virtual Meta::TrackList tracks() const;
- virtual QString generatePlaylistName() const;
// Inherited from Meta::Observer
using Observer::metadataChanged;
More information about the kde-doc-english
mailing list