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         m_bottom = -1;
00054         m_top = 1;
00055     }
00059     inline bool isValid()const
00060     {
00061         return (m_bottom != -1) && (m_top != -1);
00062     }
00066     inline void dump()const
00067     {
00068         qWarning("top: %d\tbotom: %d", m_top, m_bottom);
00069     }
00073     inline int count()const
00074     {
00075         return m_bottom - m_top + 1;
00076     }
00077     int m_bottom;               
00078     int m_top;                  
00079     QList<int> m_selected_indexes;  
00080 };
00101 class PlayListModel : public QObject
00102 {
00103     Q_OBJECT
00104 public:
00110     PlayListModel(const QString &name, QObject *parent = 0);
00114     ~PlayListModel();
00118     QString name() const;
00122     void setName(const QString &name);
00126     int count() const;
00130     int trackCount() const;
00134     bool isEmpty() const;
00138     int columnCount() const;
00142     PlayListTrack* currentTrack() const;
00146     PlayListTrack* nextTrack() const;
00150     int indexOf(PlayListItem* item) const;
00154     PlayListItem* item(int index) const;
00158     PlayListTrack* track(int index) const;
00162     PlayListGroup* group(int index) const;
00166     int currentIndex() const;
00172     bool setCurrent (int index);
00177     bool setCurrent(PlayListTrack *item);
00182     bool isTrack(int index) const;
00187     bool isGroup(int index) const;
00191     bool isSelected(int index) const;
00197     void setSelected(int index, bool selected = true);
00203     void setSelected(QList<PlayListTrack *> tracks, bool selected = true);
00209     void setSelected(QList<PlayListItem *> items, bool selected = true);
00216     void setSelected(int first, int last, bool selected = true);
00217 
00218 
00219     void setSelected(QList<int> indexes, bool selected = true);
00224     bool next();
00229     bool previous();
00235     QList<PlayListItem *> mid(int pos, int count = -1) const;
00239     void moveItems(int from, int to);
00243     bool isQueued(PlayListTrack* item) const;
00247     bool isEmptyQueue()const;
00251     int queuedIndex(PlayListTrack* track) const;
00255     int queueSize() const;
00259     bool isStopAfter(PlayListItem* item) const;
00264     const SimpleSelection& getSelection(int row);
00268     QList<int> selectedIndexes() const;
00272     QList<PlayListTrack *> selectedTracks() const;
00276     QList<PlayListItem*> items() const;
00280     int firstSelectedUpper(int row);
00284     int firstSelectedLower(int row);
00288     int totalLength() const;
00292     void loadPlaylist(const QString& f_name);
00293 
00294     void loadPlaylist(const QString &fmt, const QByteArray &data);
00298     void savePlaylist(const QString& f_name);
00302     bool isLoaderRunning() const;
00306     bool contains(const QString &url);
00310     enum SortMode
00311     {
00312         TITLE = 0,              
00313         ALBUM,                  
00314         DISCNUMBER,             
00315         ARTIST,                 
00316         ALBUMARTIST,            
00317         FILENAME,               
00318         PATH_AND_FILENAME,      
00319         DATE,                   
00320         TRACK,                  
00321         FILE_CREATION_DATE,     
00322         FILE_MODIFICATION_DATE, 
00323         GROUP                   
00324     };
00329     int indexOfTrack(int index) const;
00334     PlayListTrack *findTrack(int track_index) const;
00338     enum UpdateFlags
00339     {
00340         STRUCTURE = 0x01,  
00341         SELECTION = 0x02,  
00342         QUEUE = 0x04,      
00343         CURRENT = 0x08,    
00344         STOP_AFTER = 0x10, 
00345         METADATA = 0x20    
00346     };
00347 
00348 signals:
00353     void listChanged(int flags);
00358     void trackAdded(PlayListTrack *track);
00363     void nameChanged(const QString& name);
00367     void loaderFinished();
00371     void currentVisibleRequest();
00377     void sortingByColumnFinished(int column, bool reverted);
00378 
00379 public slots:
00383     void add(PlayListTrack *track);
00388     void add(QList <PlayListTrack *> tracks);
00393     void add(const QString &path);
00398     void add(const QStringList &paths);
00402     void insert(int index, PlayListTrack *track);
00406     void insert(PlayListItem *before, PlayListTrack *track);
00410     void insert(int index, QList <PlayListTrack *> tracks);
00414     void insert(PlayListItem *before, QList <PlayListTrack *> tracks);
00420     void insert(int index, const QString &path);
00426     void insert(int index, const QStringList &paths);
00432     void insert(int index, const QList<QUrl> &urls);
00436     void clear();
00440     void clearSelection();
00444     void removeSelected();
00448     void removeUnselected();
00452     void removeTrack (int i);
00456     void removeTrack (PlayListItem *track);
00460     void invertSelection();
00464     void selectAll();
00469     void showDetails(QWidget *parent = 0);
00474     void showDetailsForCurrent(QWidget *parent = 0);
00478     void doCurrentVisibleRequest();
00482     void randomizeList();
00486     void reverseList();
00490     void sortSelection(int mode);
00494     void sort(int mode);
00498     void sortByColumn(int column);
00502     void addToQueue();
00506     void setQueued(PlayListTrack* item);
00510     void removeInvalidTracks();
00514     void removeDuplicates();
00518     void refresh();
00522     void clearQueue();
00526     void stopAfterSelected();
00530     void rebuildGroups();
00534     void updateMetaData();
00535 
00536 private:
00540     int topmostInSelection(int);
00544     int bottommostInSelection(int);
00549     void removeSelection(bool inverted = false);
00550 
00551     int removeTrackInternal(int i);
00552 
00553 private slots:
00557     void preparePlayState();
00561     void prepareForShufflePlaying(bool yes);
00566     void prepareGroups(bool enabled);
00567 
00568     void onTaskFinished();
00569 
00570 private:
00571     PlayListTrack* m_current_track;
00572     PlayListTrack* m_stop_track;
00573     int m_current;
00574     SimpleSelection m_selection;  
00575     QQueue <PlayListTrack*> m_queued_songs; 
00576     PlayState* m_play_state; 
00577     int m_total_length;
00578     FileLoader *m_loader;
00579     QString m_name;
00580     PlayListContainer *m_container;
00581     QmmpUiSettings *m_ui_settings;
00582     PlayListTask *m_task;
00583 };
00584 
00585 #endif
 All Classes Functions Variables Enumerations Enumerator