File indexing completed on 2025-01-05 04:26:51
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Anmol Ahuja <darthcodus@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_PLAYLISTMANAGER_SCRIPT_H 0018 #define AMAROK_PLAYLISTMANAGER_SCRIPT_H 0019 0020 #include "core/meta/forward_declarations.h" 0021 0022 #include <QObject> 0023 0024 namespace Playlists 0025 { 0026 class Playlist; 0027 class PlaylistProvider; 0028 0029 typedef AmarokSharedPointer<Playlist> PlaylistPtr; 0030 typedef QList<PlaylistPtr> PlaylistList; 0031 typedef QList<Playlists::PlaylistProvider *> PlaylistProviderList; 0032 } 0033 0034 namespace AmarokScript 0035 { 0036 class AmarokScriptEngine; 0037 0038 //ANM-TODO podcasts! 0039 // SCRIPTDOX Amarok.PlaylistManager 0040 class AmarokPlaylistManagerScript : public QObject 0041 { 0042 Q_OBJECT 0043 0044 // SCRIPTDOX ENUM Amarok.PlaylistManager.PlaylistCategory 0045 // enum PlaylistCategory { UserPlaylist, PodcastChannel }; 0046 0047 /** 0048 * @returns all available categories registered at that moment 0049 */ 0050 Q_PROPERTY( QList<int> availableCategories READ availableCategories ) 0051 0052 public: 0053 explicit AmarokPlaylistManagerScript( AmarokScriptEngine* engine ); 0054 0055 /** 0056 * @returns playlists of a certain category from all registered PlaylistProviders 0057 */ 0058 Q_INVOKABLE Playlists::PlaylistList playlistsOfCategory( int playlistCategory ); 0059 0060 /** 0061 * @returns all PlaylistProviders that provide a certain playlist category. 0062 **/ 0063 Q_INVOKABLE Playlists::PlaylistProviderList providersForCategory( int playlistCategory ); 0064 0065 // ANM-TODO synced playlists 0066 /** 0067 * Do all the work necessary to sync playlists, including the 0068 * SyncedPlaylist creation and more. This sync is persistent. 0069 * @arg playlist of the master playlist 0070 * @arg playlist of the slave playlist 0071 */ 0072 //void setupSync( const Playlists::PlaylistPtr master, const Playlists::PlaylistPtr slave ); 0073 0074 /** 0075 * Return provider with @p name and @p category. 0076 * 0077 * @param category the category. 0078 * @param name the name. 0079 */ 0080 Q_INVOKABLE Playlists::PlaylistProvider *playlistProvider( int category, QString name ); 0081 0082 /** 0083 * Saves a list of tracks to a new playlist. Used in the Playlist save button. 0084 * @arg tracks list of tracks to save 0085 * @arg name of playlist to save 0086 * @arg toProvider If 0 (default) will save to the default UserPlaylistProvider ( SQLPlaylistProvider ) 0087 */ 0088 Q_INVOKABLE bool save( Meta::TrackList tracks, const QString &name = QString(), 0089 Playlists::PlaylistProvider *toProvider = nullptr ); 0090 0091 /** 0092 * Saves a playlist from a file to the database. 0093 * @param fromLocation Saved playlist file to load 0094 */ 0095 Q_INVOKABLE bool import( const QUrl &fromLocation ); 0096 0097 /** 0098 * Rename @p playlist to @p newName, return true if renaming was successful, 0099 * false otherwise. 0100 * 0101 * @param playlist the playlist. 0102 * @param newName the new name. 0103 */ 0104 Q_INVOKABLE bool rename( Playlists::PlaylistPtr playlist, const QString &newName ); 0105 0106 Q_INVOKABLE bool deletePlaylists( Playlists::PlaylistList playlistList ); 0107 0108 /** 0109 * Retrieves the provider owning the given playlist. 0110 * Will only return multiple providers if this is a synced playlist 0111 * @arg playlist the playlist whose provider we want 0112 */ 0113 Q_INVOKABLE QList<Playlists::PlaylistProvider*> 0114 getProvidersForPlaylist( const Playlists::PlaylistPtr playlist ); 0115 0116 /** 0117 * Checks if the provider to whom this playlist belongs supports writing 0118 * @arg playlist the playlist we are testing for writability 0119 * @return whether or not the playlist is writable 0120 */ 0121 Q_INVOKABLE bool isWritable( const Playlists::PlaylistPtr &playlist ); 0122 0123 private: 0124 QList<int> availableCategories(); 0125 0126 Q_SIGNALS: 0127 void updated( int category ); 0128 void categoryAdded( int category ); 0129 void providerAdded( Playlists::PlaylistProvider *provider, int category ); 0130 void providerRemoved( Playlists::PlaylistProvider *provider, int category ); 0131 void playlistAdded( Playlists::PlaylistPtr playlist, int category ); 0132 void playlistRemoved( Playlists::PlaylistPtr playlist, int category ); 0133 void playlistUpdated( Playlists::PlaylistPtr playlist, int category ); 0134 void renamePlaylist( Playlists::PlaylistPtr playlist ); 0135 }; 0136 } 0137 0138 #endif