diff options
author | wr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-02-20 12:20:48 +0000 |
---|---|---|
committer | wr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-02-20 12:20:48 +0000 |
commit | 1f5bb22fa45cff069f7e0071f7a910daaa7d303a (patch) | |
tree | f11358535d52ca602a49d9e26f5528913adbc888 | |
parent | 825586656f62847a44329e39d0ba2684f86bdbbe (diff) | |
download | vdr-plugin-muggle-1f5bb22fa45cff069f7e0071f7a910daaa7d303a.tar.gz vdr-plugin-muggle-1f5bb22fa45cff069f7e0071f7a910daaa7d303a.tar.bz2 |
more of the same
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@495 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r-- | mg_actions.c | 20 | ||||
-rw-r--r-- | mg_db.c | 44 | ||||
-rw-r--r-- | mg_db.h | 12 | ||||
-rw-r--r-- | mg_order.c | 51 | ||||
-rw-r--r-- | mg_order.h | 4 | ||||
-rw-r--r-- | vdr_menu.c | 4 |
6 files changed, 110 insertions, 25 deletions
diff --git a/mg_actions.c b/mg_actions.c index 13cb2c7..1f80325 100644 --- a/mg_actions.c +++ b/mg_actions.c @@ -138,6 +138,8 @@ mgDoCollEntry::getTarget() result.erase(0,5); else result.erase(0,3); + string::size_type lparen = result.find(" ["); + result.erase(lparen,string::npos); return result; } @@ -159,7 +161,8 @@ void mgRemoveCollEntry::Execute() { string target = getTarget(); - osd()->Message1 ("Removed %s entries",itos (osd()->moveselection->RemoveFromCollection (target))); + int removed = osd()->moveselection->RemoveFromCollection (target); + osd()->Message1 ("Removed %s entries",ltos(removed)); osd()->CollectionChanged(target); } @@ -306,21 +309,28 @@ mgEntry::Notify() mgAction::Notify(); // only after selection is updated } + const char * mgEntry::MenuName(const unsigned int idx,const string value) { char *result; + char ct[20]; + ct[0]=0; + unsigned int selcount = selection()->valcount(value); + if (selection()->level()<selection()->ordersize()-1 || selcount>1) + sprintf(ct," [%u]",selcount); + // when changing this, also change mgDoCollEntry::getTarget() if (selection()->isCollectionlist()) { if (value == osd()->default_collection) - asprintf(&result,"-> %s",value.c_str()); + asprintf(&result,"-> %s%s",value.c_str(),ct); else - asprintf(&result," %s",value.c_str()); + asprintf(&result," %s%s",value.c_str(),ct); } else if (selection()->inCollection()) - asprintf(&result,"%4d %s",idx,value.c_str()); + asprintf(&result,"%4d %s%s",idx,value.c_str(),ct); else - result = strdup(value.c_str()); + asprintf(&result,"%s%s",value.c_str(),ct); return result; } @@ -249,8 +249,22 @@ int mgContentItem::getChannels () const mgSelection::ShuffleMode mgSelection::toggleShuffleMode () { - m_shuffle_mode = (m_shuffle_mode == SM_PARTY) ? SM_NONE : ShuffleMode (m_shuffle_mode + 1); + setShuffleMode((m_shuffle_mode == SM_PARTY) ? SM_NONE : ShuffleMode (m_shuffle_mode + 1)); + Shuffle(); + return getShuffleMode(); +} + +void +mgSelection::setShuffleMode (mgSelection::ShuffleMode mode) +{ + m_shuffle_mode = mode; +} + +void +mgSelection::Shuffle() const +{ unsigned int tracksize = getNumTracks(); + if (tracksize==0) return; switch (m_shuffle_mode) { case SM_NONE: @@ -299,7 +313,6 @@ mgSelection::ShuffleMode mgSelection::toggleShuffleMode () - add the file to the end of the list */ } - return m_shuffle_mode; } @@ -430,7 +443,7 @@ mgSelection::setPosition (unsigned int position) } void -mgSelection::setTrackPosition (unsigned int position) +mgSelection::setTrackPosition (unsigned int position) const { m_tracks_position = position; } @@ -605,6 +618,8 @@ mgSelection::tracks () const m_tracks.push_back (mgContentItem (this,row)); mysql_free_result (rows); } + if (m_shuffle_mode!=SM_NONE) + Shuffle(); return m_tracks; } @@ -746,8 +761,14 @@ void mgSelection::InitSelection() { m_position = 0; m_tracks_position = 0; m_trackid = -1; - m_shuffle_mode = ShuffleMode(the_setup.InitShuffleMode); - m_loop_mode = LoopMode(the_setup.InitLoopMode); + if (the_setup.InitShuffleMode) + m_shuffle_mode = SM_NORMAL; + else + m_shuffle_mode = SM_NONE; + if (the_setup.InitLoopMode) + m_loop_mode = LM_FULL; + else + m_loop_mode = LM_NONE; clearCache(); values.setOwner(this); } @@ -836,9 +857,9 @@ void mgSelection::InitFrom(const mgSelection* s) m_position = s->m_position; m_trackid = s->m_trackid; m_tracks_position = s->m_tracks_position; + Connect(); setShuffleMode (s->getShuffleMode ()); setLoopMode (s->getLoopMode ()); - Connect(); } unsigned int @@ -866,6 +887,12 @@ mgSelection::valindex (const string val,const bool second_try) const return valindex(val,true); } +unsigned int +mgSelection::valcount (string value) +{ + assert(m_counts.size()==values.size()); + return m_counts[valindex(value)]; +} unsigned int mgSelection::idindex (const string id,const bool second_try) const @@ -898,6 +925,7 @@ mgSelection::refreshValues () const m_current_values = p.sql_select(); values.strings.clear (); m_ids.clear (); + m_counts.clear(); MYSQL_RES *rows = exec_sql (m_current_values); if (rows) { @@ -909,17 +937,19 @@ mgSelection::refreshValues () const string r0 = row[0]; if (r0=="NULL") // there is a genre NULL! continue; - if (num_fields==2) + if (num_fields==3) { if (!row[1]) continue; string r1 = row[1]; values.strings.push_back (r0); m_ids.push_back (r1); + m_counts.push_back(atol(row[2])); } else { values.strings.push_back (value(order.Key(m_level),r0)); m_ids.push_back (r0); + m_counts.push_back(atol(row[1])); } } mysql_free_result (rows); @@ -345,10 +345,7 @@ class mgSelection } //! \brief sets the current shuffle mode - void setShuffleMode (const ShuffleMode shuffle_mode) - { - m_shuffle_mode = shuffle_mode; - } + void setShuffleMode (const ShuffleMode shuffle_mode); //! \brief returns the current loop mode LoopMode getLoopMode () const @@ -423,7 +420,7 @@ class mgSelection * last existing position * \return only if no position exists, false will be returned */ - void setTrackPosition (unsigned int position); + void setTrackPosition (unsigned int position) const; /*! \brief skip some tracks in the track list * \return false if new position does not exist @@ -459,7 +456,7 @@ class mgSelection * instead, only count the tracks. If the size differs from * m_tracks.size(), invalidate m_tracks */ - unsigned int getNumTracks () + unsigned int getNumTracks () const { return tracks ().size (); } @@ -510,6 +507,7 @@ class mgSelection 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); private: mutable map <mgKeyTypes, map<string,string> > map_values; @@ -519,12 +517,14 @@ class mgSelection //! \brief be careful when accessing this, see mgSelection::tracks() mutable vector < mgContentItem > m_tracks; mutable strvector m_ids; + mutable vector < unsigned int > m_counts; //! \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; ShuffleMode m_shuffle_mode; + void Shuffle() const; LoopMode m_loop_mode; MYSQL *m_db; void setDB(MYSQL *db); @@ -176,12 +176,31 @@ class mgKeyNormal : public mgKey { string m_value; }; +class mgKeyDate : public mgKeyNormal { + public: + mgKeyDate(mgKeyTypes kt,string table, string field) : mgKeyNormal(kt,table,field) {} +}; + class mgKeyTrack : public mgKeyNormal { public: mgKeyTrack() : mgKeyNormal(keyTrack,"tracks","tracknb") {}; mgParts Parts(bool orderby=false) const; }; +class mgKeyAlbum : public mgKeyNormal { + public: + mgKeyAlbum() : mgKeyNormal(keyAlbum,"album","title") {}; + mgParts Parts(bool orderby=false) const; +}; + +mgParts +mgKeyAlbum::Parts(bool orderby) const +{ + mgParts result = mgKeyNormal::Parts(orderby); + result.tables.push_back("tracks"); + return result; +} + class mgKeyFolder : public mgKeyNormal { public: mgKeyFolder(mgKeyTypes kt,const char *fname) @@ -402,6 +421,7 @@ mgKeyNormal::set(string value, string id) mgParts::mgParts() { + m_sql_select=""; } mgParts::~mgParts() @@ -557,16 +577,24 @@ mgParts::Prepare() string mgParts::sql_select(bool distinct) { + if (!m_sql_select.empty()) + return m_sql_select; Prepare(); - string result = ""; + string result; if (distinct) - result += sql_list("SELECT DISTINCT",fields); + { + fields.push_back("COUNT(*)"); + result = sql_list("SELECT",fields); + fields.pop_back(); + } else - result += sql_list("SELECT",fields); + result = sql_list("SELECT",fields); if (result.empty()) return result; result += sql_list("FROM",tables); result += sql_list("WHERE",clauses," AND "); + if (distinct) + result += sql_list("GROUP BY",fields); result += sql_list("ORDER BY",orders); optimize(result); return result; @@ -890,6 +918,17 @@ mgOrder::Parts(unsigned int level,bool orderby) const { assert(strlen(m_db->host)); mgParts result; + mgKeyNormal *k0 = dynamic_cast<mgKeyNormal*>(Keys[0]); + mgKeyTypes kt0 = k0->Type(); + if (level==0 && kt0==keyCollection) + { + // sql command contributed by jarny + result.m_sql_select = string("select playlist.title,playlist.id, " + "count(*) * (playlistitem.playlist is not null) from playlist " + "left join playlistitem on playlist.id = playlistitem.playlist " + "group by playlist.title"); + return result; + } for (unsigned int i=0;i<=level;i++) { if (i==Keys.size()) break; @@ -1010,7 +1049,9 @@ ktGenerate(const mgKeyTypes kt,MYSQL* db) case keyTitle: result = new mgKeyNormal(kt,"tracks","title");break; case keyTrack: result = new mgKeyTrack;break; case keyDecade: result = new mgKeyDecade;break; - case keyAlbum: result = new mgKeyNormal(kt,"album","title");break; + case keyAlbum: result = new mgKeyAlbum;break; + case keyCreated: result = new mgKeyDate(kt,"tracks","created");break; + case keyModified: result = new mgKeyDate(kt,"tracks","modified");break; case keyCollection: result = new mgKeyCollection;break; case keyCollectionItem: result = new mgKeyCollectionItem;break; case keyLanguage: result = new mgKeyLanguage;break; @@ -1040,6 +1081,8 @@ ktName(const mgKeyTypes kt) case keyTrack: result = "Track";break; case keyDecade: result = "Decade";break; case keyAlbum: result = "Album";break; + case keyCreated: result = "Created";break; + case keyModified: result = "Modified";break; case keyCollection: result = "Collection";break; case keyCollectionItem: result = "Collection item";break; case keyLanguage: result = "Language";break; @@ -38,6 +38,8 @@ enum mgKeyTypes { keyFolder2, keyFolder3, keyFolder4, + keyCreated, + keyModified, keyCollection, keyCollectionItem, }; @@ -110,6 +112,7 @@ public: strlist fields; strlist tables; strlist clauses; + strlist groupby; strlist orders; mgParts& operator+=(mgParts a); void Prepare(); @@ -118,6 +121,7 @@ public: string sql_delete_from_collection(string pid); string sql_update(strlist new_values); bool empty() const { return tables.size()==0;} + string m_sql_select; private: bool UsesTracks(); mgReferences ref; @@ -120,10 +120,8 @@ mgMainMenu::CollectionChanged(string name) else PlayQueue(); } - if (CollectionEntered(name)) - { + if (CollectionEntered(name) || selection()->isCollectionlist()) selection()->clearCache(); - } } bool |