Qmmp
/usr/src/RPM/BUILD/qmmp-1.1.7/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     int columnCount() const;
00138     PlayListTrack* currentTrack() const;
00142     PlayListTrack* nextTrack() const;
00146     int indexOf(PlayListItem* item) const;
00150     PlayListItem* item(int index) const;
00154     PlayListTrack* track(int index) const;
00158     PlayListGroup* group(int index) const;
00162     int currentIndex() const;
00168     bool setCurrent (int index);
00173     bool setCurrent(PlayListTrack *item);
00178     bool isTrack(int index) const;
00183     bool isGroup(int index) const;
00187     bool isSelected(int index) const;
00193     void setSelected(int index, bool selected = true);
00199     void setSelected(QList<PlayListTrack *> tracks, bool selected = true);
00205     void setSelected(QList<PlayListItem *> items, bool selected = true);
00212     void setSelected(int first, int last, bool selected = true);
00217     bool next();
00222     bool previous();
00228     QList<PlayListItem *> mid(int pos, int count = -1) const;
00232     void moveItems(int from, int to);
00236     bool isQueued(PlayListTrack* item) const;
00240     bool isEmptyQueue()const;
00244     int queuedIndex(PlayListTrack* track) const;
00248     int queueSize() const;
00252     bool isStopAfter(PlayListItem* item) const;
00257     const SimpleSelection& getSelection(int row);
00261     QList<int> selectedIndexes() const;
00265     QList<PlayListTrack *> selectedTracks() const;
00269     QList<PlayListItem*> items() const;
00273     int firstSelectedUpper(int row);
00277     int firstSelectedLower(int row);
00281     int totalLength() const;
00285     void loadPlaylist(const QString& f_name);
00289     void savePlaylist(const QString& f_name);
00293     bool isLoaderRunning() const;
00297     bool contains(const QString &url);
00301     enum SortMode
00302     {
00303         TITLE = 0,              
00304         ALBUM,                  
00305         DISCNUMBER,             
00306         ARTIST,                 
00307         ALBUMARTIST,            
00308         FILENAME,               
00309         PATH_AND_FILENAME,      
00310         DATE,                   
00311         TRACK,                  
00312         FILE_CREATION_DATE,     
00313         FILE_MODIFICATION_DATE, 
00314         GROUP                   
00315     };
00320     int indexOfTrack(int index) const;
00325     PlayListTrack *findTrack(int track_index) const;
00329     enum UpdateFlags
00330     {
00331         STRUCTURE = 0x01,  
00332         SELECTION = 0x02,  
00333         QUEUE = 0x04,      
00334         CURRENT = 0x08,    
00335         STOP_AFTER = 0x10, 
00336         METADATA = 0x20    
00337     };
00338 
00339 signals:
00344     void listChanged(int flags);
00349     void trackAdded(PlayListTrack *track);
00354     void nameChanged(const QString& name);
00358     void loaderFinished();
00362     void currentVisibleRequest();
00368     void sortingByColumnFinished(int column, bool reverted);
00369 
00370 public slots:
00374     void add(PlayListTrack *track);
00379     void add(QList <PlayListTrack *> tracks);
00384     void add(const QString &path);
00389     void add(const QStringList &paths);
00393     void insert(int index, PlayListTrack *track);
00397     void insert(PlayListItem *before, PlayListTrack *track);
00401     void insert(int index, QList <PlayListTrack *> tracks);
00405     void insert(PlayListItem *before, QList <PlayListTrack *> tracks);
00411     void insert(int index, const QString &path);
00417     void insert(int index, const QStringList &paths);
00423     void insert(int index, const QList<QUrl> &urls);
00427     void clear();
00431     void clearSelection();
00435     void removeSelected();
00439     void removeUnselected();
00443     void removeTrack (int i);
00447     void removeTrack (PlayListItem *track);
00451     void invertSelection();
00455     void selectAll();
00460     void showDetails(QWidget *parent = 0);
00465     void showDetailsForCurrent(QWidget *parent = 0);
00469     void doCurrentVisibleRequest();
00473     void randomizeList();
00477     void reverseList();
00481     void sortSelection(int mode);
00485     void sort(int mode);
00489     void sortByColumn(int column);
00493     void addToQueue();
00497     void setQueued(PlayListTrack* item);
00501     void removeInvalidTracks();
00505     void removeDuplicates();
00509     void refresh();
00513     void clearQueue();
00517     void stopAfterSelected();
00521     void rebuildGroups();
00525     void updateMetaData();
00526 
00527 private:
00531     int topmostInSelection(int);
00535     int bottommostInSelection(int);
00540     void removeSelection(bool inverted = false);
00541 
00542     int removeTrackInternal(int i);
00543 
00544 private slots:
00548     void preparePlayState();
00552     void prepareForShufflePlaying(bool yes);
00557     void prepareGroups(bool enabled);
00558 
00559     void onTaskFinished();
00560 
00561 private:
00562     PlayListTrack* m_current_track;
00563     PlayListTrack* m_stop_track;
00564     int m_current;
00565     SimpleSelection m_selection;  
00566     QQueue <PlayListTrack*> m_queued_songs; 
00567     PlayState* m_play_state; 
00568     int m_total_length;
00569     FileLoader *m_loader;
00570     QString m_name;
00571     PlayListContainer *m_container;
00572     QmmpUiSettings *m_ui_settings;
00573     PlayListTask *m_task;
00574 };
00575 
00576 #endif
 All Classes Functions Variables Enumerations Enumerator