Qmmp
/usr/src/RPM/BUILD/qmmp-0.11-svn/src/qmmpui/playlistmodel.h
00001 /***************************************************************************
00002  *   Copyright (C) 2006-2016 by Ilya Kotov                                 *
00003  *   forkotov02@hotmail.ru                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
00019  ***************************************************************************/
00020 #ifndef PLAYLISTMODEL_H
00021 #define PLAYLISTMODEL_H
00022 
00023 #include <QObject>
00024 #include <QString>
00025 #include <QStringList>
00026 #include <QMap>
00027 #include <QQueue>
00028 #include <QPointer>
00029 #include <QVector>
00030 #include "playlistitem.h"
00031 #include "playlisttrack.h"
00032 #include "playlistgroup.h"
00033 
00034 class FileLoader;
00035 class PlayState;
00036 class PlayListFormat;
00037 class PlayListModel;
00038 class PlayListContainer;
00039 class QmmpUiSettings;
00040 class PlayListTask;
00041 
00046 struct SimpleSelection
00047 {
00051     SimpleSelection()
00052     {
00053         ;
00054     }
00058     inline bool isValid()const
00059     {
00060         return (m_bottom != -1) && (m_top != -1);
00061     }
00065     inline void dump()const
00066     {
00067         qWarning("top: %d\tbotom: %d", m_top, m_bottom);
00068     }
00072     inline int count()const
00073     {
00074         return m_bottom - m_top + 1;
00075     }
00076     int m_bottom;               
00077     int m_top;                  
00078     QList<int> m_selected_indexes;  
00079 };
00100 class PlayListModel : public QObject
00101 {
00102     Q_OBJECT
00103 public:
00109     PlayListModel(const QString &name, QObject *parent = 0);
00113     ~PlayListModel();
00117     QString name() const;
00121     void setName(const QString &name);
00125     int count() const;
00129     int trackCount() const;
00133     int columnCount() const;
00137     PlayListTrack* currentTrack() const;
00141     PlayListTrack* nextTrack() const;
00145     int indexOf(PlayListItem* item) const;
00149     PlayListItem* item(int index) const;
00153     PlayListTrack* track(int index) const;
00157     PlayListGroup* group(int index) const;
00161     int currentIndex() const;
00167     bool setCurrent (int index);
00172     bool setCurrent(PlayListTrack *item);
00177     bool isTrack(int index) const;
00182     bool isGroup(int index) const;
00186     bool isSelected(int index) const;
00192     void setSelected(int index, bool selected = true);
00198     void setSelected(QList<PlayListTrack *> tracks, bool selected = true);
00204     void setSelected(QList<PlayListItem *> items, bool selected = true);
00211     void setSelected(int first, int last, bool selected = true);
00216     bool next();
00221     bool previous();
00227     QList<PlayListItem *> mid(int pos, int count = -1) const;
00231     void moveItems(int from, int to);
00235     bool isQueued(PlayListTrack* item) const;
00239     bool isEmptyQueue()const;
00243     int queuedIndex(PlayListTrack* track) const;
00247     int queueSize() const;
00251     bool isStopAfter(PlayListItem* item) const;
00256     const SimpleSelection& getSelection(int row);
00260     QList<int> selectedIndexes() const;
00264     QList<PlayListTrack *> selectedTracks() const;
00268     QList<PlayListItem*> items() const;
00272     int firstSelectedUpper(int row);
00276     int firstSelectedLower(int row);
00280     int totalLength() const;
00284     void loadPlaylist(const QString& f_name);
00288     void savePlaylist(const QString& f_name);
00292     bool isLoaderRunning() const;
00296     bool contains(const QString &url);
00300     enum SortMode
00301     {
00302         TITLE = 0,              
00303         ALBUM,                  
00304         DISCNUMBER,             
00305         ARTIST,                 
00306         ALBUMARTIST,            
00307         FILENAME,               
00308         PATH_AND_FILENAME,      
00309         DATE,                   
00310         TRACK,                  
00311         FILE_CREATION_DATE,     
00312         FILE_MODIFICATION_DATE, 
00313         GROUP                   
00314     };
00319     int indexOfTrack(int index) const;
00324     PlayListTrack *findTrack(int track_index) const;
00328     enum UpdateFlags
00329     {
00330         STRUCTURE = 0x01,  
00331         SELECTION = 0x02,  
00332         QUEUE = 0x04,      
00333         CURRENT = 0x08,    
00334         STOP_AFTER = 0x10, 
00335         METADATA = 0x20    
00336     };
00337 
00338 signals:
00343     void listChanged(int flags);
00348     void trackAdded(PlayListTrack *track);
00353     void nameChanged(const QString& name);
00357     void loaderFinished();
00361     void currentVisibleRequest();
00367     void sortingByColumnFinished(int column, bool reverted);
00368 
00369 public slots:
00373     void add(PlayListTrack *track);
00378     void add(QList <PlayListTrack *> tracks);
00383     void add(const QString &path);
00388     void add(const QStringList &paths);
00392     void insert(int index, PlayListTrack *track);
00396     void insert(PlayListItem *before, PlayListTrack *track);
00400     void insert(int index, QList <PlayListTrack *> tracks);
00404     void insert(PlayListItem *before, QList <PlayListTrack *> tracks);
00410     void insert(int index, const QString &path);
00416     void insert(int index, const QStringList &paths);
00422     void insert(int index, const QList<QUrl> &urls);
00426     void clear();
00430     void clearSelection();
00434     void removeSelected();
00438     void removeUnselected();
00442     void removeTrack (int i);
00446     void removeTrack (PlayListItem *track);
00450     void invertSelection();
00454     void selectAll();
00459     void showDetails(QWidget *parent = 0);
00464     void showDetailsForCurrent(QWidget *parent = 0);
00468     void doCurrentVisibleRequest();
00472     void randomizeList();
00476     void reverseList();
00480     void sortSelection(int mode);
00484     void sort(int mode);
00488     void sortByColumn(int column);
00492     void addToQueue();
00496     void setQueued(PlayListTrack* item);
00500     void removeInvalidTracks();
00504     void removeDuplicates();
00508     void refresh();
00512     void clearQueue();
00516     void stopAfterSelected();
00520     void rebuildGroups();
00524     void updateMetaData();
00525 
00526 private:
00530     int topmostInSelection(int);
00534     int bottommostInSelection(int);
00539     void removeSelection(bool inverted = false);
00540 
00541     int removeTrackInternal(int i);
00542 
00543 private slots:
00547     void preparePlayState();
00551     void prepareForShufflePlaying(bool yes);
00556     void prepareGroups(bool enabled);
00557 
00558     void onTaskFinished();
00559 
00560 private:
00561     PlayListTrack* m_current_track;
00562     PlayListTrack* m_stop_track;
00563     int m_current;
00564     SimpleSelection m_selection;  
00565     QQueue <PlayListTrack*> m_queued_songs; 
00566     PlayState* m_play_state; 
00567     int m_total_length;
00568     FileLoader *m_loader;
00569     QString m_name;
00570     PlayListContainer *m_container;
00571     QmmpUiSettings *m_ui_settings;
00572     PlayListTask *m_task;
00573 };
00574 
00575 #endif
 All Classes Functions Variables Enumerations Enumerator