diff options
Diffstat (limited to 'mg_selection.h')
-rw-r--r-- | mg_selection.h | 140 |
1 files changed, 59 insertions, 81 deletions
diff --git a/mg_selection.h b/mg_selection.h index f9fa455..60018f6 100644 --- a/mg_selection.h +++ b/mg_selection.h @@ -29,31 +29,32 @@ typedef vector<string> strvector; * \brief the only interface to the database. * Some member functions are declared const although they can modify the inner state of mgSelection. * But they only modify variables used for caching. With const, we want to express - * the logical constness. E.g. the selected tracks can change without breaking constness: - * The selection never defines concrete tracks but only how to choose them. + * the logical constness. E.g. the selected items can change without breaking constness: + * The selection never defines concrete items but only how to choose them. */ class mgSelection { - class mgSelItems + public: + class mgListItems { public: - mgSelItems() { m_sel=0; } + mgListItems() { m_sel=0; } void setOwner(mgSelection* sel); - mgSelItem& operator[](unsigned int idx); + mgListItem& operator[](unsigned int idx); string& id(unsigned int); unsigned int count(unsigned int); - bool operator==(const mgSelItems&x) const; + bool operator==(const mgListItems&x) const; size_t size() const; unsigned int valindex (const string v) const; unsigned int idindex (const string i) const; void clear(); - void push_back(mgSelItem& item) { m_items.push_back(item); } + void push_back(mgListItem& item) { m_items.push_back(item); } private: unsigned int index (const string s,bool val,bool second_try=false) const; - vector<mgSelItem> m_items; + vector<mgListItem> m_items; mgSelection* m_sel; }; - public: + //! \brief defines an order to be used void setOrder(mgOrder *o); @@ -73,8 +74,8 @@ class mgSelection enum LoopMode { LM_NONE, //!< \brief do not loop - LM_SINGLE, //!< \brief loop a single track - LM_FULL //!< \brief loop the whole track list + LM_SINGLE, //!< \brief loop a single item + LM_FULL //!< \brief loop the whole item list }; /*! \brief the main constructor @@ -109,14 +110,14 @@ class mgSelection * small overhead for building the SQL WHERE command. The items will * be reloaded when the SQL command changes */ - mutable mgSelItems items; + mutable mgListItems listitems; /*! \brief returns the name of a key */ mgKeyTypes getKeyType (const unsigned int level) const; //! \brief return the current value of this key - mgSelItem& getKeyItem (const unsigned int level) const; + mgListItem& getKeyItem (const unsigned int level) const; /*! \brief returns the current item from the value() list */ @@ -126,7 +127,7 @@ class mgSelection map<mgKeyTypes,string> UsedKeyValues(); //! \brief the number of key fields used for the query - unsigned int ordersize (); + unsigned int ordersize () { return order.size(); } //! \brief the number of music items currently selected unsigned int count () const; @@ -139,12 +140,12 @@ class mgSelection unsigned int gotoPosition (); -//! \brief the current position in the tracks list - unsigned int getTrackPosition () const; +//! \brief the current position in the item list + unsigned int getItemPosition () const; - //! \brief go to the current track position. If it does not exist, + //! \brief go to the current item position. If it does not exist, // go to the nearest. - unsigned int gotoTrackPosition (); + unsigned int gotoItemPosition (); /*! \brief enter the the next higher level, go one up in the tree. * If fall_through (see constructor) is set to true, and the @@ -181,7 +182,7 @@ class mgSelection */ bool enter (const string value) { - return enter (items.valindex (value)); + return enter (listitems.valindex (value)); } /*! \brief like enter but if we are at the leaf level simply select @@ -189,12 +190,12 @@ class mgSelection */ bool select (const string value) { - return select (items.valindex(value)); + return select (listitems.valindex(value)); } bool selectid (const string i) { - return select(items.idindex(i)); + return select(listitems.idindex(i)); } void selectfrom(mgOrder& oldorder,mgContentItem* o); @@ -216,7 +217,7 @@ class mgSelection */ void leave_all (); -//! \brief the current level in the tree +//! \brief the current level in the tree. This is at most order.size(). unsigned int level () const { return m_level; @@ -225,31 +226,31 @@ class mgSelection //! \brief true if the selection holds no items bool empty(); -/*! \brief returns detailed info about all selected tracks. +/*! \brief returns detailed info about all selected items. * The ordering is done only by the keyfield of the current level. * This might have to be changed - suborder by keyfields of detail * levels. This list is cached so several consequent calls mean no * loss of performance. See value(), the same warning applies. - * \todo call this more seldom. See getNumTracks() + * \todo call this more seldom. See getNumItems() */ - const vector < mgContentItem > &tracks () const; + const vector < mgContentItem > &items () const; -/*! \brief returns an item from the tracks() list - * \param position the position in the tracks() list +/*! \brief returns an item from the items() list + * \param position the position in the items() list * \return returns NULL if position is out of range */ - mgContentItem* getTrack (unsigned int position); + mgContentItem* getItem (unsigned int position); -/*! \brief returns the current item from the tracks() list +/*! \brief returns the current item from the items() list */ - mgContentItem* getCurrentTrack () + mgContentItem* getCurrentItem () { - return getTrack (gotoTrackPosition()); + return getItem (gotoItemPosition()); } /*! \brief toggles the shuffle mode thru all possible values. * When a shuffle modus SM_NORMAL or SM_PARTY is selected, the - * order of the tracks in the track list will be randomly changed. + * order of the items in the item list will be randomly changed. */ ShuffleMode toggleShuffleMode (); @@ -277,13 +278,13 @@ class mgSelection m_loop_mode = loop_mode; } -/*! \brief adds the whole current track list to a collection +/*! \brief adds the whole current item list to a collection * \param Name the name of the collection. If it does not yet exist, * it will be created. */ unsigned int AddToCollection (const string Name); -/*! \brief removes the whole current track from a the collection +/*! \brief removes the whole current item from a the collection * Remember - this selection can be configured to hold exactly * one list, so this command can be used to clear a selected list. * \param Name the name of the collection @@ -299,7 +300,7 @@ class mgSelection //! \brief remove all items from the collection void ClearCollection (const string Name); -/*! generates an m3u file containing all tracks. The directory +/*! generates an m3u file containing all items. The directory * can be indicated by SetDirectory(). * The file name will be built from the list name, slashes * and spaces converted @@ -308,7 +309,7 @@ class mgSelection /*! \brief go to a position in the current level. If we are at the - * most detailled level this also sets the track position since + * most detailled level this also sets the item position since * they are identical. * \param position the wanted position. If it is too big, go to the * last existing position @@ -321,59 +322,38 @@ class mgSelection */ void setPosition (const string value) { - setPosition (items.valindex (value)); + setPosition (listitems.valindex (value)); } -/*! \brief go to a position in the track list +/*! \brief go to a position in the item list * \param position the wanted position. If it is too big, go to the - * last existing position + * last existing position. If the position is not valid, find the + * next valid one. * \return only if no position exists, false will be returned */ - void setTrackPosition (unsigned int position) const; + void GotoItemPosition (unsigned int position) const; -/*! \brief skip some tracks in the track list +/*! \brief skip some items in the item list * \return false if new position does not exist */ - bool skipTracks (int step=1); - -/*! \brief skip forward by 1 in the track list - * \return false if new position does not exist - */ - bool skipFwd () - { - return skipTracks (+1); - } + bool skipItems (int step=1) const; -/*! \brief skip back by 1 in the track list - * \return false if new position does not exist - */ - bool skipBack () - { - return skipTracks (-1); - } - -//! \brief returns the sum of the durations of all tracks +//! \brief returns the sum of the durations of all items unsigned long getLength (); -/*! \brief returns the sum of the durations of completed tracks - * those are tracks before the current track position +/*! \brief returns the sum of the durations of completed items + * those are items before the current item position */ unsigned long getCompletedLength () const; -/*! returns the number of tracks in the track list - * \todo should not call tracks () which loads all track info. - * instead, only count the tracks. If the size differs from - * m_tracks.size(), invalidate m_tracks +/*! returns the number of items in the item list + * \todo should not call items () which loads all item info. + * instead, only count the items. If the size differs from + * m_items.size(), invalidate m_items */ - unsigned int getNumTracks () const - { - return tracks ().size (); - } - -//! sets the directory for the storage of m3u file - void SetDirectory (const string directory) + unsigned int getNumItems () const { - m_Directory = directory; + return items ().size (); } /*! returns the name of the current play list. If no play list is active, @@ -407,7 +387,7 @@ class mgSelection void refreshValues() const; - //! \brief true if values and tracks need to be reloaded + //! \brief true if values and items need to be reloaded bool cacheIsEmpty() const { return (m_current_values=="" && m_current_tracks==""); @@ -419,7 +399,6 @@ class mgSelection string id(mgKey* k, string val) const; string id(mgKey* k) const; unsigned int keycount(mgKeyTypes kt); - vector <const char *> choices(mgOrder *o,unsigned int level, unsigned int *current); unsigned int valcount (string val); bool Connected() { return m_db.Connected(); } @@ -428,29 +407,28 @@ class mgSelection mutable map <mgKeyTypes, map<string,string> > map_ids; mutable string m_current_values; mutable string m_current_tracks; -//! \brief be careful when accessing this, see mgSelection::tracks() - mutable vector < mgContentItem > m_tracks; +//! \brief be careful when accessing this, see mgSelection::items() + mutable vector < mgContentItem > m_items; //! \brief initializes maps for id/value mapping in both direction bool loadvalues (mgKeyTypes kt) const; bool m_fall_through; unsigned int m_position; - mutable unsigned int m_tracks_position; + mutable unsigned int m_items_position; ShuffleMode m_shuffle_mode; void Shuffle() const; LoopMode m_loop_mode; mutable mgmySql m_db; unsigned int m_level; - long m_trackid; + long m_itemid; mgOrder order; - bool UsedBefore (mgOrder *o,const mgKeyTypes kt, unsigned int level) const; void InitSelection (); /*! \brief returns the SQL command for getting all values. * For the leaf level, all values are returned. For upper * levels, every distinct value is returned only once. * This must be so for the leaf level because otherwise * the value() entries do not correspond to the track() - * entries and the wrong tracks might be played. + * entries and the wrong items might be played. */ string sql_values (); string ListFilename (); |