OTHER: show playlist and selection playtimes in playlistwindow
This commit is contained in:
parent
7a0ea5a053
commit
9e1aa92d20
11 changed files with 159 additions and 15 deletions
|
@ -225,6 +225,9 @@ PlaylistModel::handle_change (const Xmms::Dict &chg)
|
|||
break;
|
||||
}
|
||||
|
||||
/* TODO: call this only for the necessary methods */
|
||||
emitTotalPlaytime ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -246,6 +249,8 @@ PlaylistModel::handle_list (const Xmms::List< unsigned int > &list)
|
|||
|
||||
endInsertRows ();
|
||||
|
||||
emitTotalPlaytime ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -284,6 +289,8 @@ PlaylistModel::entry_changed (uint32_t id)
|
|||
QModelIndex idx2 = index (pos.at (i), m_columns.size ());
|
||||
emit dataChanged(idx1, idx2);
|
||||
}
|
||||
|
||||
emitTotalPlaytime ();
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -535,6 +542,39 @@ PlaylistModel::flags (const QModelIndex &idx) const
|
|||
return f;
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistModel::emitTotalPlaytime ()
|
||||
{
|
||||
bool isExact = true;
|
||||
uint32_t time = 0;
|
||||
|
||||
foreach (uint32_t index, m_plist) {
|
||||
QHash<QString, QVariant> data = m_client->cache ()->get_info (index,
|
||||
false);
|
||||
if (!data.isEmpty ()) {
|
||||
time += data.value ("duration", 0).toInt ();
|
||||
} else {
|
||||
isExact = false;
|
||||
}
|
||||
}
|
||||
|
||||
emit totalPlaytime (time/1000, isExact);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
PlaylistModel::getPlaytimeForSelection(const QModelIndexList &index_list)
|
||||
{
|
||||
uint32_t playtime = 0;
|
||||
foreach (QModelIndex idx, index_list) {
|
||||
int id = idx.row ();
|
||||
if (id >= m_plist.size ()) continue;
|
||||
QHash<QString, QVariant> data =
|
||||
m_client->cache ()->get_info (m_plist.at (id), false);
|
||||
if (!data.isEmpty ()) playtime += data.value ("duration", 0).toInt ();
|
||||
}
|
||||
return playtime/1000;
|
||||
}
|
||||
|
||||
QList<uint32_t>
|
||||
PlaylistModel::get_all_id ()
|
||||
{
|
||||
|
|
|
@ -115,6 +115,8 @@ class PlaylistModel : public QAbstractItemModel
|
|||
|
||||
void removeRows (QModelIndexList);
|
||||
|
||||
uint32_t getPlaytimeForSelection(const QModelIndexList &index_list);
|
||||
|
||||
protected:
|
||||
XClient *m_client;
|
||||
QList < unsigned int > m_plist;
|
||||
|
@ -125,6 +127,7 @@ class PlaylistModel : public QAbstractItemModel
|
|||
signals:
|
||||
void entryMoved (const QModelIndex &, const QModelIndex &);
|
||||
void currentPosChanged (QModelIndex);
|
||||
void totalPlaytime (uint32_t seconds, bool isExact);
|
||||
|
||||
public slots:
|
||||
void got_connection (XClient *);
|
||||
|
@ -143,6 +146,8 @@ class PlaylistModel : public QAbstractItemModel
|
|||
|
||||
void getInfo (unsigned int id) const;
|
||||
|
||||
void emitTotalPlaytime ();
|
||||
|
||||
uint32_t m_current_pos;
|
||||
bool m_isactive;
|
||||
|
||||
|
|
|
@ -154,9 +154,9 @@ XClientCache::get_pixmap (uint32_t id)
|
|||
}
|
||||
|
||||
QHash<QString, QVariant>
|
||||
XClientCache::get_info (uint32_t id)
|
||||
XClientCache::get_info (uint32_t id, bool fetchFromServer)
|
||||
{
|
||||
if (!m_info.contains (id)) {
|
||||
if ((!m_info.contains (id)) && fetchFromServer) {
|
||||
m_client->medialib ()->getInfo (id) (
|
||||
Xmms::bind (&XClientCache::handle_medialib_info, this),
|
||||
boost::bind (&XClientCache::handle_medialib_info_error,
|
||||
|
@ -164,7 +164,7 @@ XClientCache::get_info (uint32_t id)
|
|||
m_info[id] = QHash<QString, QVariant> ();
|
||||
}
|
||||
|
||||
return m_info[id];
|
||||
return m_info.value(id, QHash<QString, QVariant>());
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -46,7 +46,16 @@ class XClientCache : public QObject
|
|||
public:
|
||||
XClientCache (XClient *);
|
||||
|
||||
QHash<QString, QVariant> get_info (uint32_t id);
|
||||
/* Returns the metadata of the given medialib id, if it is cached
|
||||
* locally. If the metadata is not cached, an empty QHash is returned
|
||||
* If the metadata is not cached and fetchFromServer is true, the
|
||||
* metadata is fetched from the server and a entryChanged SIGNAL is
|
||||
* emitted to notify the caller that the metadata has arrived
|
||||
* DO NOT use this function with fetchFromServer set to false if you
|
||||
* didn't understand this explanation
|
||||
*/
|
||||
QHash<QString, QVariant> get_info (uint32_t id,
|
||||
bool fetchFromServer=true);
|
||||
QVariantHash get_current_info () {return get_info (m_current_id);}
|
||||
QIcon get_icon (uint32_t id);
|
||||
QPixmap get_pixmap (uint32_t id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue