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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: call this only for the necessary methods */
|
||||||
|
emitTotalPlaytime ();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -246,6 +249,8 @@ PlaylistModel::handle_list (const Xmms::List< unsigned int > &list)
|
||||||
|
|
||||||
endInsertRows ();
|
endInsertRows ();
|
||||||
|
|
||||||
|
emitTotalPlaytime ();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,6 +289,8 @@ PlaylistModel::entry_changed (uint32_t id)
|
||||||
QModelIndex idx2 = index (pos.at (i), m_columns.size ());
|
QModelIndex idx2 = index (pos.at (i), m_columns.size ());
|
||||||
emit dataChanged(idx1, idx2);
|
emit dataChanged(idx1, idx2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emitTotalPlaytime ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -535,6 +542,39 @@ PlaylistModel::flags (const QModelIndex &idx) const
|
||||||
return f;
|
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>
|
QList<uint32_t>
|
||||||
PlaylistModel::get_all_id ()
|
PlaylistModel::get_all_id ()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,8 @@ class PlaylistModel : public QAbstractItemModel
|
||||||
|
|
||||||
void removeRows (QModelIndexList);
|
void removeRows (QModelIndexList);
|
||||||
|
|
||||||
|
uint32_t getPlaytimeForSelection(const QModelIndexList &index_list);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
XClient *m_client;
|
XClient *m_client;
|
||||||
QList < unsigned int > m_plist;
|
QList < unsigned int > m_plist;
|
||||||
|
|
@ -125,6 +127,7 @@ class PlaylistModel : public QAbstractItemModel
|
||||||
signals:
|
signals:
|
||||||
void entryMoved (const QModelIndex &, const QModelIndex &);
|
void entryMoved (const QModelIndex &, const QModelIndex &);
|
||||||
void currentPosChanged (QModelIndex);
|
void currentPosChanged (QModelIndex);
|
||||||
|
void totalPlaytime (uint32_t seconds, bool isExact);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void got_connection (XClient *);
|
void got_connection (XClient *);
|
||||||
|
|
@ -143,6 +146,8 @@ class PlaylistModel : public QAbstractItemModel
|
||||||
|
|
||||||
void getInfo (unsigned int id) const;
|
void getInfo (unsigned int id) const;
|
||||||
|
|
||||||
|
void emitTotalPlaytime ();
|
||||||
|
|
||||||
uint32_t m_current_pos;
|
uint32_t m_current_pos;
|
||||||
bool m_isactive;
|
bool m_isactive;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,9 +154,9 @@ XClientCache::get_pixmap (uint32_t id)
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, QVariant>
|
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) (
|
m_client->medialib ()->getInfo (id) (
|
||||||
Xmms::bind (&XClientCache::handle_medialib_info, this),
|
Xmms::bind (&XClientCache::handle_medialib_info, this),
|
||||||
boost::bind (&XClientCache::handle_medialib_info_error,
|
boost::bind (&XClientCache::handle_medialib_info_error,
|
||||||
|
|
@ -164,7 +164,7 @@ XClientCache::get_info (uint32_t id)
|
||||||
m_info[id] = QHash<QString, QVariant> ();
|
m_info[id] = QHash<QString, QVariant> ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_info[id];
|
return m_info.value(id, QHash<QString, QVariant>());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,16 @@ class XClientCache : public QObject
|
||||||
public:
|
public:
|
||||||
XClientCache (XClient *);
|
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);}
|
QVariantHash get_current_info () {return get_info (m_current_id);}
|
||||||
QIcon get_icon (uint32_t id);
|
QIcon get_icon (uint32_t id);
|
||||||
QPixmap get_pixmap (uint32_t id);
|
QPixmap get_pixmap (uint32_t id);
|
||||||
|
|
|
||||||
|
|
@ -375,6 +375,7 @@ Skin::BuildLetterMap (void)
|
||||||
/* special characters */
|
/* special characters */
|
||||||
m_letterMap['"'] = letters[0][27];
|
m_letterMap['"'] = letters[0][27];
|
||||||
m_letterMap['@'] = letters[0][28];
|
m_letterMap['@'] = letters[0][28];
|
||||||
|
m_letterMap[':'] = letters[1][12];
|
||||||
m_letterMap['('] = letters[1][13];
|
m_letterMap['('] = letters[1][13];
|
||||||
m_letterMap[')'] = letters[1][14];
|
m_letterMap[')'] = letters[1][14];
|
||||||
m_letterMap['-'] = letters[1][15];
|
m_letterMap['-'] = letters[1][15];
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class Skin : public QObject
|
||||||
{ return m_backgrounds.value(item); };
|
{ return m_backgrounds.value(item); };
|
||||||
const PixmapMap getNumbers () const { return m_numbers; }
|
const PixmapMap getNumbers () const { return m_numbers; }
|
||||||
const PixmapMap getSmallNumbers () const { return m_smallNumbers; }
|
const PixmapMap getSmallNumbers () const { return m_smallNumbers; }
|
||||||
|
const PixmapMap getPixmapFont () const { return m_letterMap; }
|
||||||
|
|
||||||
const QPixmap getItem (uint part) const { return m_items.value (part); }
|
const QPixmap getItem (uint part) const { return m_items.value (part); }
|
||||||
const QPixmap getPls (uint part) const
|
const QPixmap getPls (uint part) const
|
||||||
|
|
@ -87,7 +88,7 @@ class Skin : public QObject
|
||||||
QMap<int, QPixmap> m_numbers;
|
QMap<int, QPixmap> m_numbers;
|
||||||
QMap<int, QPixmap> m_smallNumbers;
|
QMap<int, QPixmap> m_smallNumbers;
|
||||||
QMap<uint, QPixmap> m_items;
|
QMap<uint, QPixmap> m_items;
|
||||||
QMap<uint, QPixmap> m_letterMap;
|
QMap<int, QPixmap> m_letterMap;
|
||||||
QMap<uint, QPixmap> m_playlist;
|
QMap<uint, QPixmap> m_playlist;
|
||||||
|
|
||||||
QMap<QByteArray, QByteArray> m_pledit_txt;
|
QMap<QByteArray, QByteArray> m_pledit_txt;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,24 @@
|
||||||
#include "pixmapbutton.h"
|
#include "pixmapbutton.h"
|
||||||
#include "timedisplay.h"
|
#include "timedisplay.h"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
QString secondsToString (uint32_t seconds)
|
||||||
|
{
|
||||||
|
int h, m, s;
|
||||||
|
s = seconds % 60;
|
||||||
|
seconds /= 60;
|
||||||
|
m = seconds % 60;
|
||||||
|
h = seconds / 60;
|
||||||
|
|
||||||
|
QString ret = QString ("%1%2%3")
|
||||||
|
.arg (h ? QString ("%1:").arg(h) : "")
|
||||||
|
.arg (m ? QString ("%1:").arg(m) : "")
|
||||||
|
.arg (s);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PlaylistControls::PlaylistControls (QWidget *parent) : QWidget (parent)
|
PlaylistControls::PlaylistControls (QWidget *parent) : QWidget (parent)
|
||||||
{
|
{
|
||||||
setFixedSize (100, 38);
|
setFixedSize (100, 38);
|
||||||
|
|
@ -63,7 +81,30 @@ PlaylistControls::PlaylistControls (QWidget *parent) : QWidget (parent)
|
||||||
connect (this, SIGNAL (setDisplayTime (int)),
|
connect (this, SIGNAL (setDisplayTime (int)),
|
||||||
m_timedisplay, SLOT (setTime (int)));
|
m_timedisplay, SLOT (setTime (int)));
|
||||||
|
|
||||||
//TODO: playtimes
|
m_selection_playtime = 0;
|
||||||
|
m_playlist_playtime = 0;
|
||||||
|
is_playlist_playtime_exact = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistControls::paintEvent (QPaintEvent *event)
|
||||||
|
{
|
||||||
|
if (m_font.isEmpty ()) return;
|
||||||
|
|
||||||
|
int x = 8, y = 10;
|
||||||
|
QString time = QString ("%1/%2%3")
|
||||||
|
.arg (secondsToString (m_selection_playtime))
|
||||||
|
.arg (secondsToString (m_playlist_playtime))
|
||||||
|
.arg (is_playlist_playtime_exact ? "" : "+");
|
||||||
|
|
||||||
|
QPainter paint;
|
||||||
|
paint.begin (this);
|
||||||
|
foreach (QChar c, time) {
|
||||||
|
paint.drawPixmap (x, y, m_font[c.toAscii()]);
|
||||||
|
x += 5;
|
||||||
|
}
|
||||||
|
paint.end ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -73,13 +114,23 @@ PlaylistControls::setNumbers (const PixmapMap &p)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistControls::setSelectedLength (int lenght)
|
PlaylistControls::setPixmapFont (const PixmapMap &p)
|
||||||
{
|
{
|
||||||
//TODO
|
m_font = p;
|
||||||
|
update ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistControls::setPlaylistLength (int lenght)
|
PlaylistControls::setSelectionPlaytime (uint32_t playtime)
|
||||||
{
|
{
|
||||||
//TODO
|
m_selection_playtime = playtime;
|
||||||
|
update ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistControls::setPlaylistPlaytime (uint32_t playtime, bool isExact)
|
||||||
|
{
|
||||||
|
m_playlist_playtime = playtime;
|
||||||
|
is_playlist_playtime_exact = isExact;
|
||||||
|
update ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
class SmallTimeDisplay;
|
class SmallTimeDisplay;
|
||||||
|
class QPaintEvent;
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
|
|
||||||
typedef QMap<int, QPixmap> PixmapMap;
|
typedef QMap<int, QPixmap> PixmapMap;
|
||||||
|
|
@ -31,10 +32,11 @@ class PlaylistControls : public QWidget {
|
||||||
PlaylistControls (QWidget *parent);
|
PlaylistControls (QWidget *parent);
|
||||||
|
|
||||||
void setNumbers (const PixmapMap &p);
|
void setNumbers (const PixmapMap &p);
|
||||||
|
void setPixmapFont (const PixmapMap &p);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setSelectedLength (int);
|
void setSelectionPlaytime (uint32_t);
|
||||||
void setPlaylistLength (int);
|
void setPlaylistPlaytime (uint32_t, bool isExact);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// emitted when buttons are clicked
|
// emitted when buttons are clicked
|
||||||
|
|
@ -49,9 +51,14 @@ class PlaylistControls : public QWidget {
|
||||||
//connected to internal timedisplay
|
//connected to internal timedisplay
|
||||||
void setDisplayTime (int);
|
void setDisplayTime (int);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void paintEvent (QPaintEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_playlist_length;
|
uint32_t m_playlist_playtime;
|
||||||
int m_selected_length;
|
bool is_playlist_playtime_exact;
|
||||||
|
uint32_t m_selection_playtime;
|
||||||
|
PixmapMap m_font;
|
||||||
|
|
||||||
SmallTimeDisplay *m_timedisplay;
|
SmallTimeDisplay *m_timedisplay;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,21 @@ PlaylistView::PlaylistView (QWidget *parent) : QListView (parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistView::invertSelection () {
|
PlaylistView::selectionChanged (const QItemSelection &selected,
|
||||||
|
const QItemSelection &deselected)
|
||||||
|
{
|
||||||
|
/* selectedIndexes () is used here because selected only contains newly
|
||||||
|
* seleted indexes and will give a wrong result if pressing CONTROL to
|
||||||
|
* modify a selection */
|
||||||
|
uint32_t playtime = qobject_cast<PlaylistModel *> (model ())->getPlaytimeForSelection (selectedIndexes ());
|
||||||
|
emit selectionPlaytimeChanged (playtime);
|
||||||
|
|
||||||
|
QListView::selectionChanged (selected, deselected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistView::invertSelection ()
|
||||||
|
{
|
||||||
QItemSelection selection = QItemSelection (model ()->index (0, 0),
|
QItemSelection selection = QItemSelection (model ()->index (0, 0),
|
||||||
model ()->index (model ()->rowCount ()-1, 0));
|
model ()->index (model ()->rowCount ()-1, 0));
|
||||||
selectionModel ()->select (selection, QItemSelectionModel::Toggle |
|
selectionModel ()->select (selection, QItemSelectionModel::Toggle |
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,9 @@ class PlaylistView : public QListView {
|
||||||
{qWarning ("Trying to set wrong model in PlaylistView"); return;};
|
{qWarning ("Trying to set wrong model in PlaylistView"); return;};
|
||||||
void setModel (PlaylistModel *model);
|
void setModel (PlaylistModel *model);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void selectionPlaytimeChanged (uint32_t playtime);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void contextMenuEvent (QContextMenuEvent *e);
|
void contextMenuEvent (QContextMenuEvent *e);
|
||||||
|
|
||||||
|
|
@ -66,9 +69,13 @@ class PlaylistView : public QListView {
|
||||||
void settingsChanged (void);
|
void settingsChanged (void);
|
||||||
void setPixmaps (Skin *skin);
|
void setPixmaps (Skin *skin);
|
||||||
void currentPosChanged (QModelIndex);
|
void currentPosChanged (QModelIndex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseDoubleClickEvent (QMouseEvent *event);
|
void mouseDoubleClickEvent (QMouseEvent *event);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void selectionChanged (const QItemSelection &, const QItemSelection &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Xmms::Playback::Status m_status;
|
Xmms::Playback::Status m_status;
|
||||||
QFont *m_font;
|
QFont *m_font;
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,14 @@ PlaylistWidget::PlaylistWidget (PlaylistWindow *parent) : QWidget (parent)
|
||||||
connect (parent, SIGNAL (setDisplayTime (int)),
|
connect (parent, SIGNAL (setDisplayTime (int)),
|
||||||
m_controls, SIGNAL (setDisplayTime (int)));
|
m_controls, SIGNAL (setDisplayTime (int)));
|
||||||
|
|
||||||
|
|
||||||
|
connect (App->client ()->active_playlist (),
|
||||||
|
SIGNAL (totalPlaytime(uint32_t, bool)),
|
||||||
|
m_controls, SLOT (setPlaylistPlaytime (uint32_t, bool)));
|
||||||
|
|
||||||
|
connect (m_view, SIGNAL (selectionPlaytimeChanged(uint32_t)),
|
||||||
|
m_controls, SLOT (setSelectionPlaytime (uint32_t)));
|
||||||
|
|
||||||
setMinimumSize (275, 116);
|
setMinimumSize (275, 116);
|
||||||
// resize (275, 300);
|
// resize (275, 300);
|
||||||
}
|
}
|
||||||
|
|
@ -448,6 +456,7 @@ PlaylistWidget::setPixmaps (Skin *skin)
|
||||||
m_shadebtn->setIcon (skin->getIcon (Skin::BUTTON_PLS_SHADE));
|
m_shadebtn->setIcon (skin->getIcon (Skin::BUTTON_PLS_SHADE));
|
||||||
|
|
||||||
m_controls->setNumbers (skin->getSmallNumbers ());
|
m_controls->setNumbers (skin->getSmallNumbers ());
|
||||||
|
m_controls->setPixmapFont (skin->getPixmapFont ());
|
||||||
|
|
||||||
setActive (m_active);
|
setActive (m_active);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue