Added MedialibModels but still are disabled because they don't work.
This commit is contained in:
parent
d114edf75f
commit
02c64bf99b
9 changed files with 218 additions and 35 deletions
62
MedialibItem.h
Normal file
62
MedialibItem.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#ifndef __MEDIALIBITEM_H__
|
||||||
|
#define __MEDIALIBITEM_H__
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class MedialibItem {
|
||||||
|
public:
|
||||||
|
enum MedialibItemType {
|
||||||
|
NoneItem,
|
||||||
|
ArtistItem,
|
||||||
|
AlbumItem,
|
||||||
|
SongItem
|
||||||
|
};
|
||||||
|
|
||||||
|
MedialibItem (const QStringList &text = QStringList (), MedialibItem *parent = NULL, MedialibItemType type = NoneItem) {
|
||||||
|
m_text = text;
|
||||||
|
m_type = type;
|
||||||
|
m_parent = parent;
|
||||||
|
if (parent) {
|
||||||
|
parent->m_childs.append (this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool mayHaveChilds () const {
|
||||||
|
if (m_type == NoneItem || m_type == SongItem)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
QString data (int c) const {
|
||||||
|
if (m_text.size () > c) {
|
||||||
|
return m_text.at (c);
|
||||||
|
}
|
||||||
|
return QString ();
|
||||||
|
};
|
||||||
|
|
||||||
|
MedialibItem *child (int c) const {
|
||||||
|
return m_childs.value (c);
|
||||||
|
}
|
||||||
|
|
||||||
|
int childCount () const {
|
||||||
|
return m_childs.count ();
|
||||||
|
};
|
||||||
|
|
||||||
|
MedialibItem *parent () const {
|
||||||
|
return m_parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
int row () const {
|
||||||
|
if (m_parent)
|
||||||
|
return m_parent->m_childs.indexOf (const_cast<MedialibItem*> (this));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
MedialibItemType m_type;
|
||||||
|
QStringList m_text;
|
||||||
|
MedialibItem *m_parent;
|
||||||
|
QList<MedialibItem *> m_childs;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,33 +1,140 @@
|
||||||
#include "XMMSSocket.h"
|
#include <xmmsclient/xmmsclient++.h>
|
||||||
|
#include "XmmsQt4.h"
|
||||||
#include "MedialibTreeModel.h"
|
#include "MedialibTreeModel.h"
|
||||||
|
#include "MedialibItem.h"
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QErrorMessage>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
MedialibTreeModel::MedialibTreeModel (QObject *parent) : QAbstractTableModel (parent), m_socket ("PromoeMedialibTree")
|
MedialibTreeModel::MedialibTreeModel (QObject *parent) :
|
||||||
|
QAbstractItemModel (parent), m_client ("PromoeMedialibTree")
|
||||||
{
|
{
|
||||||
m_socket.connect (getenv ("XMMS_PATH"));
|
const char *path = getenv("XMMS_PATH");
|
||||||
|
try {
|
||||||
|
m_client.connect (path ? path : "");
|
||||||
|
}
|
||||||
|
catch (Xmms::connection_error& e) {
|
||||||
|
QErrorMessage *err = new QErrorMessage ();
|
||||||
|
err->showMessage ("Couldn't connect to XMMS2, please try again.");
|
||||||
|
err->exec ();
|
||||||
|
delete err;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_client.setMainloop (new XmmsQT4 (m_client.getConnection ()));
|
||||||
|
|
||||||
|
m_rootitem = new MedialibItem ();
|
||||||
|
|
||||||
|
using Xmms::bind;
|
||||||
|
|
||||||
|
m_client.medialib.select ("select distinct value from Media where key='artist' order by lower(value)",
|
||||||
|
bind (&MedialibTreeModel::artist_list, this));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
MedialibTreeModel::artist_list (const Xmms::List< Xmms::Dict > &artists)
|
||||||
|
{
|
||||||
|
QString s;
|
||||||
|
|
||||||
|
for (artists.first (); artists.isValid (); ++artists) {
|
||||||
|
s = QString::fromUtf8 ((*artists).get<std::string> ("value").c_str ());
|
||||||
|
new MedialibItem (QStringList (s), m_rootitem, MedialibItem::ArtistItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
reset ();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* QModel overrides */
|
/* QModel overrides */
|
||||||
|
|
||||||
|
Qt::ItemFlags
|
||||||
|
MedialibTreeModel::flags (const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return Qt::ItemIsEnabled;
|
||||||
|
|
||||||
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
MedialibTreeModel::rowCount (const QModelIndex &parent) const
|
MedialibTreeModel::rowCount (const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return 2;
|
MedialibItem *item;
|
||||||
|
|
||||||
|
if (!parent.isValid ()) {
|
||||||
|
item = m_rootitem;
|
||||||
|
} else {
|
||||||
|
item = static_cast<MedialibItem*> (parent.internalPointer ());
|
||||||
|
}
|
||||||
|
|
||||||
|
int n = item->childCount ();
|
||||||
|
|
||||||
|
if (n == 0 && item->mayHaveChilds ())
|
||||||
|
n = 1;
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex
|
||||||
|
MedialibTreeModel::parent (const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid ())
|
||||||
|
return QModelIndex ();
|
||||||
|
|
||||||
|
MedialibItem *item = static_cast<MedialibItem*> (index.internalPointer ());
|
||||||
|
MedialibItem *parent = item->parent ();
|
||||||
|
|
||||||
|
if (parent == m_rootitem) {
|
||||||
|
return QModelIndex ();
|
||||||
|
}
|
||||||
|
|
||||||
|
return createIndex (parent->row (), 0, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex
|
||||||
|
MedialibTreeModel::index (int row, int column,
|
||||||
|
const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
MedialibItem *p;
|
||||||
|
if (!parent.isValid ()) {
|
||||||
|
p = m_rootitem;
|
||||||
|
} else {
|
||||||
|
p = static_cast<MedialibItem*> (parent.internalPointer ());
|
||||||
|
}
|
||||||
|
|
||||||
|
MedialibItem *child = p->child (row);
|
||||||
|
if (child) {
|
||||||
|
return createIndex (row, column, child);
|
||||||
|
} else {
|
||||||
|
if (p->columnCount () == 0 && !p->loading ()) {
|
||||||
|
qDebug ("Loading items...");
|
||||||
|
switch (p->type ()) {
|
||||||
|
case MedialibItem::ArtistItem:
|
||||||
|
m_client.medialib.select ("select distinct m1.value as value from Media m1 join Media m2 on m1.id = m2.id and m2.key = 'artist' where m1.key='album' and m2.value = '%s' order by lower(m1.value)", MedialibTreeModel::sub_list);
|
||||||
|
|
||||||
|
return QModelIndex ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
MedialibTreeModel::columnCount (const QModelIndex &parent) const
|
MedialibTreeModel::columnCount (const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return 2;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
MedialibTreeModel::data (const QModelIndex &parent,
|
MedialibTreeModel::data (const QModelIndex &index,
|
||||||
int role) const
|
int role) const
|
||||||
{
|
{
|
||||||
if (role == Qt::DisplayRole)
|
if (!index.isValid ())
|
||||||
return QVariant("hej");
|
|
||||||
return QVariant ();
|
return QVariant ();
|
||||||
|
|
||||||
|
if (role != Qt::DisplayRole)
|
||||||
|
return QVariant ();
|
||||||
|
|
||||||
|
MedialibItem *item = static_cast<MedialibItem *> (index.internalPointer ());
|
||||||
|
return QVariant (item->data (index.column ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
|
@ -36,7 +143,7 @@ MedialibTreeModel::headerData (int section,
|
||||||
int role) const
|
int role) const
|
||||||
{
|
{
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
return QVariant("header");
|
return QVariant("Title");
|
||||||
return QVariant ();
|
return QVariant ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
#ifndef __MEDIALIBTREEMODEL_H__
|
#ifndef __MEDIALIBTREEMODEL_H__
|
||||||
#define __MEDIALIBTREEMODEL_H__
|
#define __MEDIALIBTREEMODEL_H__
|
||||||
|
|
||||||
#include "XMMSSocket.h"
|
#include <xmmsclient/xmmsclient++.h>
|
||||||
#include <QAbstractTableModel>
|
|
||||||
|
|
||||||
class MedialibTreeModel : public QAbstractTableModel
|
#include "MedialibItem.h"
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class MedialibTreeModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -14,11 +18,16 @@ class MedialibTreeModel : public QAbstractTableModel
|
||||||
/* QModel overrides */
|
/* QModel overrides */
|
||||||
int rowCount (const QModelIndex &parent) const;
|
int rowCount (const QModelIndex &parent) const;
|
||||||
int columnCount (const QModelIndex &parent) const;
|
int columnCount (const QModelIndex &parent) const;
|
||||||
QVariant data (const QModelIndex &parent, int role = Qt::DisplayRole) const;
|
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
Qt::ItemFlags flags (const QModelIndex &index) const;
|
||||||
|
QModelIndex index (int row, int column, const QModelIndex &parent) const;
|
||||||
|
QModelIndex parent (const QModelIndex &index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMMSSocket m_socket;
|
bool artist_list (const Xmms::List< Xmms::Dict > &artists);
|
||||||
|
Xmms::Client m_client;
|
||||||
|
MedialibItem *m_rootitem;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
#include "MedialibTreeModel.h"
|
||||||
#include "MedialibView.h"
|
#include "MedialibView.h"
|
||||||
|
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
|
|
||||||
MedialibView::MedialibView (QWidget *parent) : QTreeView (parent)
|
MedialibView::MedialibView (QWidget *parent) : QTreeView (parent)
|
||||||
{
|
{
|
||||||
|
setAlternatingRowColors (true);
|
||||||
|
setModel (new MedialibTreeModel (this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "XMMSSocket.h"
|
#include "XMMSSocket.h"
|
||||||
#include "MedialibWindow.h"
|
#include "MedialibWindow.h"
|
||||||
#include "MedialibView.h"
|
#include "MedialibView.h"
|
||||||
#include "MedialibTreeModel.h"
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
@ -15,7 +14,8 @@ MedialibWindow::MedialibWindow (QWidget *parent) : QMainWindow (parent)
|
||||||
setAttribute (Qt::WA_DeleteOnClose);
|
setAttribute (Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
m_view = new MedialibView (this);
|
m_view = new MedialibView (this);
|
||||||
m_view->setModel (new MedialibTreeModel (this));
|
|
||||||
|
|
||||||
setCentralWidget (m_view);
|
setCentralWidget (m_view);
|
||||||
|
|
||||||
|
resize (500, 600);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,8 +70,10 @@ TitleBar::showMenu (void)
|
||||||
void
|
void
|
||||||
TitleBar::showMlib ()
|
TitleBar::showMlib ()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
MedialibWindow *mw = new MedialibWindow (window ());
|
MedialibWindow *mw = new MedialibWindow (window ());
|
||||||
mw->show ();
|
mw->show ();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <xmmsclient/xmmsclient++.h>
|
#include <xmmsclient/xmmsclient++.h>
|
||||||
|
|
||||||
#include "XmmsQT4.h"
|
#include "XmmsQT4.h"
|
||||||
#include "XMMSSocket.h"
|
|
||||||
#include "XMMSHandler.h"
|
#include "XMMSHandler.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -30,7 +29,7 @@ XMMSHandler &XMMSHandler::getInstance ()
|
||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMMSHandler::XMMSHandler () : QObject (), XMMSSocket ()
|
XMMSHandler::XMMSHandler () : QObject (), m_client ("Prome_Main")
|
||||||
{
|
{
|
||||||
connect (std::getenv ( "XMMS_PATH" ));
|
connect (std::getenv ( "XMMS_PATH" ));
|
||||||
}
|
}
|
||||||
|
@ -38,8 +37,18 @@ XMMSHandler::XMMSHandler () : QObject (), XMMSSocket ()
|
||||||
bool
|
bool
|
||||||
XMMSHandler::connect (const char *path)
|
XMMSHandler::connect (const char *path)
|
||||||
{
|
{
|
||||||
if (!XMMSSocket::connect (path))
|
try {
|
||||||
|
m_client.connect (path ? path : "");
|
||||||
|
}
|
||||||
|
catch (Xmms::connection_error& e) {
|
||||||
|
QErrorMessage *err = new QErrorMessage ();
|
||||||
|
err->showMessage ("Couldn't connect to XMMS2, please try again.");
|
||||||
|
err->exec ();
|
||||||
|
delete err;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_client.setMainloop (new XmmsQT4 (m_client.getConnection ()));
|
||||||
|
|
||||||
using Xmms::bind;
|
using Xmms::bind;
|
||||||
m_client.playlist.list (bind (&XMMSHandler::playlist_list, this));
|
m_client.playlist.list (bind (&XMMSHandler::playlist_list, this));
|
||||||
|
|
|
@ -4,13 +4,12 @@
|
||||||
#include <xmmsclient/xmmsclient++.h>
|
#include <xmmsclient/xmmsclient++.h>
|
||||||
|
|
||||||
#include "XmmsQT4.h"
|
#include "XmmsQT4.h"
|
||||||
#include "XMMSSocket.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
class XMMSHandler : public QObject, XMMSSocket {
|
class XMMSHandler : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static XMMSHandler &getInstance ();
|
static XMMSHandler &getInstance ();
|
||||||
|
@ -91,6 +90,7 @@ class XMMSHandler : public QObject, XMMSSocket {
|
||||||
bool volume_get (const Xmms::Dict &levels);
|
bool volume_get (const Xmms::Dict &levels);
|
||||||
bool volume_error (const std::string &error);
|
bool volume_error (const std::string &error);
|
||||||
|
|
||||||
|
Xmms::Client m_client;
|
||||||
XmmsQT4 *m_qt4;
|
XmmsQT4 *m_qt4;
|
||||||
unsigned int m_currentid;
|
unsigned int m_currentid;
|
||||||
bool m_masterchan;
|
bool m_masterchan;
|
||||||
|
|
14
promoe.pro
14
promoe.pro
|
@ -10,7 +10,6 @@ SOURCES += XmmsQT4.cpp \
|
||||||
NumberDisplay.cpp \
|
NumberDisplay.cpp \
|
||||||
TimeDisplay.cpp \
|
TimeDisplay.cpp \
|
||||||
XMMSHandler.cpp \
|
XMMSHandler.cpp \
|
||||||
XMMSSocket.cpp \
|
|
||||||
SmallNumberDisplay.cpp \
|
SmallNumberDisplay.cpp \
|
||||||
StereoMono.cpp \
|
StereoMono.cpp \
|
||||||
Slider.cpp \
|
Slider.cpp \
|
||||||
|
@ -26,10 +25,7 @@ SOURCES += XmmsQT4.cpp \
|
||||||
VolumeSlider.cpp \
|
VolumeSlider.cpp \
|
||||||
ClutterBar.cpp \
|
ClutterBar.cpp \
|
||||||
Equalizer.cpp \
|
Equalizer.cpp \
|
||||||
FileDialog.cpp \
|
FileDialog.cpp
|
||||||
MedialibView.cpp \
|
|
||||||
MedialibWindow.cpp \
|
|
||||||
MedialibTreeModel.cpp
|
|
||||||
|
|
||||||
|
|
||||||
HEADERS += XmmsQT4.h \
|
HEADERS += XmmsQT4.h \
|
||||||
|
@ -44,7 +40,6 @@ HEADERS += XmmsQT4.h \
|
||||||
NumberDisplay.h \
|
NumberDisplay.h \
|
||||||
TimeDisplay.h \
|
TimeDisplay.h \
|
||||||
XMMSHandler.h \
|
XMMSHandler.h \
|
||||||
XMMSSocket.h \
|
|
||||||
SmallNumberDisplay.h \
|
SmallNumberDisplay.h \
|
||||||
StereoMono.h \
|
StereoMono.h \
|
||||||
Slider.h \
|
Slider.h \
|
||||||
|
@ -60,10 +55,7 @@ HEADERS += XmmsQT4.h \
|
||||||
VolumeSlider.h \
|
VolumeSlider.h \
|
||||||
ClutterBar.h \
|
ClutterBar.h \
|
||||||
Equalizer.h \
|
Equalizer.h \
|
||||||
FileDialog.h \
|
FileDialog.h
|
||||||
MedialibView.h \
|
|
||||||
MedialibWindow.h \
|
|
||||||
MedialibTreeModel.h
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +69,7 @@ QMAKE_LFLAGS += -L$$[QT_INSTALL_PLUGINS]/imageformats
|
||||||
|
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig
|
||||||
|
|
||||||
;QMAKE_CXXFLAGS += -g
|
QMAKE_CXXFLAGS += -g
|
||||||
;CONFIG += debug warn_on
|
;CONFIG += debug warn_on
|
||||||
QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter
|
QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter
|
||||||
PKGCONFIG += xmms2-client xmms2-client-cpp
|
PKGCONFIG += xmms2-client xmms2-client-cpp
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue