File indexing completed on 2025-01-19 04:25:18
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Peter ZHOU <peterzhoulei@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_PLAYLIST_SCRIPT_H 0018 #define AMAROK_PLAYLIST_SCRIPT_H 0019 0020 #include "core/meta/forward_declarations.h" 0021 0022 #include <QObject> 0023 #include <QMetaType> 0024 #include <QStringList> 0025 0026 class QModelIndex; 0027 class QUrl; 0028 0029 namespace AmarokScript 0030 { 0031 class AmarokScriptEngine; 0032 0033 // SCRIPTDOX: Amarok.Playlist 0034 class AmarokPlaylistScript : public QObject 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 explicit AmarokPlaylistScript( AmarokScriptEngine *engine ); 0040 0041 /** 0042 * Return the index of the currently playing track in the playlist. 0043 */ 0044 Q_INVOKABLE int activeIndex(); 0045 0046 /** 0047 * Return the number of tracks in the playlist. 0048 */ 0049 Q_INVOKABLE int totalTrackCount(); 0050 0051 /** 0052 * Save the current playlist in the default playlist path. 0053 */ 0054 Q_INVOKABLE QString saveCurrentPlaylist(); 0055 0056 /** 0057 * Load the track represented by the url and append to playlist. 0058 */ 0059 Q_INVOKABLE void addMedia( const QUrl &url ); 0060 0061 /** 0062 * Append @param track to playlist. 0063 */ 0064 Q_INVOKABLE void addTrack( const Meta::TrackPtr &track ); 0065 0066 /** 0067 * Load the list of tracks represented by the urls and append to playlist. 0068 */ 0069 Q_INVOKABLE void addMediaList( const QList<QUrl> &urls ); 0070 0071 /** 0072 * Append the list of tracks to playlist. 0073 */ 0074 Q_INVOKABLE void addTrackList( const Meta::TrackList &tracks ); 0075 0076 /** 0077 * Clear the current playlist. 0078 */ 0079 Q_INVOKABLE void clearPlaylist(); 0080 0081 /** 0082 * Play the track at the specified index in the playlist. 0083 */ 0084 Q_INVOKABLE void playByIndex( int index ); 0085 0086 /** 0087 * Prepend the track represented by the passed url and start playing it. 0088 */ 0089 Q_INVOKABLE void playMedia( const QUrl &url ); 0090 0091 /** 0092 * Prepend @param track and start playing it. 0093 */ 0094 Q_INVOKABLE void playTrack( const Meta::TrackPtr &track ); 0095 0096 /** 0097 * Prepend the tracks represented by the passed urls and start playing them. 0098 */ 0099 Q_INVOKABLE void playMediaList( const QList<QUrl> &urls ); 0100 0101 /** 0102 * Prepend tracks in @param trackList and start playing them. 0103 */ 0104 Q_INVOKABLE void playTrackList( const Meta::TrackList &trackList ); 0105 0106 /** 0107 * Remove the currently playing track from the playlist. 0108 */ 0109 Q_INVOKABLE void removeCurrentTrack(); 0110 0111 /** 0112 * Remove the track at @param index from the playlist. 0113 */ 0114 Q_INVOKABLE void removeByIndex( int index ); 0115 0116 /** 0117 * Save the current playlist at the absolute path @p path. 0118 * 0119 * @param path the absolute path. 0120 */ 0121 Q_INVOKABLE void savePlaylist( const QString& path ); 0122 0123 /** 0124 * Set whether to stop playing after the current track. 0125 * 0126 * @param on @c true if on, @c false otherwise. 0127 */ 0128 Q_INVOKABLE void setStopAfterCurrent( bool on ); 0129 0130 /* 0131 * Indicates whether will stop playing after the current track. 0132 */ 0133 Q_INVOKABLE bool stopAfterCurrent(); 0134 0135 /** 0136 * Show/ Hide the playlist. 0137 */ 0138 Q_INVOKABLE void togglePlaylist(); 0139 0140 /** 0141 * Return a list of urls representing all the tracks in the playlist. 0142 */ 0143 Q_INVOKABLE QStringList filenames(); 0144 0145 /** 0146 * Return the track at the specified position in the playlist. 0147 */ 0148 Q_INVOKABLE Meta::TrackPtr trackAt( int row ); 0149 0150 /** 0151 * Get an unsorted list of indices of the currently selected tracks in the playlist. 0152 */ 0153 Q_INVOKABLE QList<int> selectedIndexes(); 0154 0155 /** 0156 * Get an unsorted list of urls of the currently selected tracks in the playlist. 0157 */ 0158 Q_INVOKABLE QStringList selectedFilenames(); 0159 0160 Q_SIGNALS: 0161 /** 0162 * Emitted when tracks are added to the playlist. 0163 */ 0164 void trackInserted( int start, int end ); 0165 0166 /** 0167 * Emitted when tracks are removed from the playlist. 0168 */ 0169 void trackRemoved( int start, int end ); 0170 0171 private Q_SLOTS: 0172 void slotTrackInserted( const QModelIndex&, int start, int end ); 0173 void slotTrackRemoved( const QModelIndex&, int start, int end ); 0174 0175 private: 0176 AmarokScriptEngine* m_scriptEngine; 0177 }; 0178 } 0179 0180 #endif