Qmmp
/usr/src/RPM/BUILD/qmmp-0.7-svn/src/qmmpui/playlistmodel.h
00001 /***************************************************************************
00002  *   Copyright (C) 2006-2012 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 
00032 class FileLoader;
00033 class PlayListItem;
00034 class PlayState;
00035 class PlaylistFormat;
00036 class PlayListModel;
00037 
00042 struct SimpleSelection
00043 {
00047     SimpleSelection()
00048     {
00049         ;
00050     }
00054     inline bool isValid()const
00055     {
00056         return (m_bottom != -1) && (m_anchor != -1) && (m_top != -1);
00057     }
00061     inline void dump()const
00062     {
00063         qWarning("top: %d\tbotom: %d\tanchor: %d",m_top,m_bottom,m_anchor);
00064     }
00068     inline int count()const
00069     {
00070         return m_bottom - m_top + 1;
00071     }
00072     int m_bottom;               
00073     int m_top;                  
00074     int m_anchor;               
00075     QList<int>m_selected_rows;  
00076 };
00082 class TagUpdater : public QObject
00083 {
00084     Q_OBJECT
00085     QObject* m_observable;
00086     PlayListItem* m_item;
00087 
00088 public:
00089     TagUpdater(QObject* o, PlayListItem* item);
00090 
00091 protected slots:
00092     void updateTag();
00093 };
00099 class PlayListModel : public QObject
00100 {
00101     Q_OBJECT
00102 public:
00108     PlayListModel(const QString &name, QObject *parent = 0);
00112     ~PlayListModel();
00116     QString name() const;
00120     void setName(const QString &name);
00124     int count();
00128     PlayListItem* currentItem();
00132     PlayListItem* nextItem();
00136     int row(PlayListItem* item) const
00137     {
00138         return m_items.indexOf(item);
00139     }
00143     PlayListItem* item(int row) const;
00147     int currentRow();
00153     bool setCurrent (int row);
00158     bool setCurrent(PlayListItem *item);
00162     bool isSelected(int row);
00168     void setSelected(int row, bool selected = true);
00173     bool next();
00178     bool previous();
00184     QStringList getTitles(int first,int last);
00190     QStringList getTimes(int first,int last);
00194     void moveItems(int from, int to);
00198     bool isQueued(PlayListItem* item) const;
00202     void setCurrentToQueued();
00206     bool isEmptyQueue()const;
00210     int queuedIndex(PlayListItem* item) const;
00214     int queueSize() const;
00218     bool isStopAfter(PlayListItem* item) const;
00223     const SimpleSelection& getSelection(int row);
00227     QList<int> selectedRows() const;
00231     QList<PlayListItem*> selectedItems() const;
00235     QList<PlayListItem*> items() const
00236     {
00237         return m_items;
00238     }
00242     int firstSelectedUpper(int row);
00246     int firstSelectedLower(int row);
00250     int totalLength()const
00251     {
00252         return m_total_length;
00253     }
00257     void loadPlaylist(const QString& f_name);
00261     void savePlaylist(const QString& f_name);
00265     bool isRepeatableList() const;
00269     bool isShuffle() const;
00273     bool isLoaderRunning() const;
00277     bool contains(const QString &url);
00281     enum SortMode
00282     {
00283         TITLE,             
00284         ALBUM,             
00285         DISCNUMBER,        
00286         ARTIST,            
00287         FILENAME,          
00288         PATH_AND_FILENAME, 
00289         DATE,              
00290         TRACK              
00291     };
00292 
00293 signals:
00297     void listChanged();
00301     void currentChanged();
00306     void itemAdded(PlayListItem *item);
00311     void nameChanged(const QString& name);
00315     void loaderFinished();
00316 
00317 public slots:
00321     void add(PlayListItem *item);
00326     void add(QList <PlayListItem *> items);
00331     void add(const QString &path);
00336     void add(const QStringList &paths);
00340     void clear();
00344     void clearSelection();
00348     void removeSelected();
00352     void removeUnselected();
00356     void removeAt (int i);
00360     void removeItem (PlayListItem *item);
00364     void invertSelection();
00368     void selectAll();
00373     void showDetails(QWidget *parent = 0);
00377     void doCurrentVisibleRequest();
00381     void randomizeList();
00385     void reverseList();
00389     void prepareForShufflePlaying(bool yes);
00393     void prepareForRepeatablePlaying(bool);
00397     void sortSelection(int mode);
00401     void sort(int mode);
00405     void addToQueue();
00409     void setQueued(PlayListItem* f);
00413     void removeInvalidItems();
00417     void removeDuplicates();
00421     void clearQueue();
00425     void stopAfterSelected();
00426 
00427 private:
00431     void doSort(int mode,QList<PlayListItem*>& list_to_sort);
00435     int topmostInSelection(int);
00439     int bottommostInSelection(int);
00444     void removeSelection(bool inverted = false);
00445 
00446 private slots:
00447     void preparePlayState();
00448 
00449 private:
00450     QList <PlayListItem*> m_items;
00451     QList <PlayListItem*> m_editing_items;
00452     PlayListItem* m_currentItem;
00453     PlayListItem* m_stop_item;
00454     int m_current;
00458     SimpleSelection m_selection;
00462     QQueue <PlayListItem*> m_queued_songs;
00466     bool is_repeatable_list;
00470     PlayState* m_play_state;
00471     int m_total_length;
00472     FileLoader *m_loader;
00473     bool m_shuffle;
00474     QString m_name;
00475 };
00476 
00477 
00478 #endif
 All Classes Functions Variables Enumerations Enumerator