diff --git a/MedialibTreeModel.cpp b/MedialibTreeModel.cpp new file mode 100644 index 0000000..4c88770 --- /dev/null +++ b/MedialibTreeModel.cpp @@ -0,0 +1,42 @@ +#include "XMMSSocket.h" +#include "MedialibTreeModel.h" + +#include + +MedialibTreeModel::MedialibTreeModel (QObject *parent) : QAbstractTableModel (parent), m_socket ("PromoeMedialibTree") +{ + m_socket.connect (getenv ("XMMS_PATH")); +} + +/* QModel overrides */ +int +MedialibTreeModel::rowCount (const QModelIndex &parent) const +{ + return 2; +} + +int +MedialibTreeModel::columnCount (const QModelIndex &parent) const +{ + return 2; +} + +QVariant +MedialibTreeModel::data (const QModelIndex &parent, + int role) const +{ + if (role == Qt::DisplayRole) + return QVariant("hej"); + return QVariant (); +} + +QVariant +MedialibTreeModel::headerData (int section, + Qt::Orientation orientation, + int role) const +{ + if (role == Qt::DisplayRole) + return QVariant("header"); + return QVariant (); +} + diff --git a/MedialibTreeModel.h b/MedialibTreeModel.h new file mode 100644 index 0000000..4b9087d --- /dev/null +++ b/MedialibTreeModel.h @@ -0,0 +1,24 @@ +#ifndef __MEDIALIBTREEMODEL_H__ +#define __MEDIALIBTREEMODEL_H__ + +#include "XMMSSocket.h" +#include + +class MedialibTreeModel : public QAbstractTableModel +{ + Q_OBJECT + public: + MedialibTreeModel (QObject *parent); + MedialibTreeModel::~MedialibTreeModel () {}; + + /* QModel overrides */ + int rowCount (const QModelIndex &parent) const; + int columnCount (const QModelIndex &parent) const; + QVariant data (const QModelIndex &parent, int role = Qt::DisplayRole) const; + QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + private: + XMMSSocket m_socket; +}; + +#endif diff --git a/MedialibView.cpp b/MedialibView.cpp new file mode 100644 index 0000000..5172385 --- /dev/null +++ b/MedialibView.cpp @@ -0,0 +1,8 @@ +#include "MedialibView.h" + +#include + + +MedialibView::MedialibView (QWidget *parent) : QTreeView (parent) +{ +} diff --git a/MedialibView.h b/MedialibView.h new file mode 100644 index 0000000..5aa1b84 --- /dev/null +++ b/MedialibView.h @@ -0,0 +1,16 @@ +#ifndef __MEDIALIBVIEW_H__ +#define __MEDIALIBVIEW_H__ + +#include "XMMSSocket.h" +#include +#include + +class MedialibView : public QTreeView +{ + Q_OBJECT + public: + MedialibView (QWidget *parent); +}; + + +#endif diff --git a/MedialibWindow.cpp b/MedialibWindow.cpp new file mode 100644 index 0000000..c484f1f --- /dev/null +++ b/MedialibWindow.cpp @@ -0,0 +1,21 @@ +#include "XMMSSocket.h" +#include "MedialibWindow.h" +#include "MedialibView.h" +#include "MedialibTreeModel.h" + +#include + +MedialibWindow::MedialibWindow (QWidget *parent) : QMainWindow (parent) +{ +#ifndef _WIN32 + setWindowIcon (QIcon (":icon.png")); +#endif + + setWindowFlags (Qt::Dialog); + setAttribute (Qt::WA_DeleteOnClose); + + m_view = new MedialibView (this); + m_view->setModel (new MedialibTreeModel (this)); + + setCentralWidget (m_view); +} diff --git a/MedialibWindow.h b/MedialibWindow.h new file mode 100644 index 0000000..579d5a1 --- /dev/null +++ b/MedialibWindow.h @@ -0,0 +1,17 @@ +#ifndef __MEDIALIBWINDOW_H__ +#define __MEDIALIBWINDOW_H__ + +#include "MedialibView.h" +#include + +class MedialibWindow : public QMainWindow +{ + Q_OBJECT + public: + MedialibWindow (QWidget *parent); + + private: + QTreeView *m_view; +}; + +#endif diff --git a/TitleBar.cpp b/TitleBar.cpp index c65f33d..b3b00a1 100644 --- a/TitleBar.cpp +++ b/TitleBar.cpp @@ -2,9 +2,7 @@ #include "TitleBar.h" #include "Display.h" #include "SkinChooser.h" -/* -#include "Medialib.h" -*/ +#include "MedialibWindow.h" #include "SettingsWindow.h" #include "Button.h" @@ -45,9 +43,7 @@ TitleBar::showMenu (void) a = new QAction (tr ("Medialib browser"), this); a->setShortcut (tr ("Alt+M")); - /* connect (a, SIGNAL (triggered ()), this, SLOT (showMlib ())); - */ qm.addAction (a); qm.addSeparator (); a = new QAction (tr ("Theme settings"), this); @@ -74,10 +70,8 @@ TitleBar::showMenu (void) void TitleBar::showMlib () { - /* MedialibWindow *mw = new MedialibWindow (window ()); mw->show (); - */ } void diff --git a/XMMSHandler.cpp b/XMMSHandler.cpp index c1b183c..2c313a0 100644 --- a/XMMSHandler.cpp +++ b/XMMSHandler.cpp @@ -1,6 +1,7 @@ #include #include "XmmsQT4.h" +#include "XMMSSocket.h" #include "XMMSHandler.h" #include @@ -29,7 +30,7 @@ XMMSHandler &XMMSHandler::getInstance () return singleton; } -XMMSHandler::XMMSHandler () : QObject (), m_client ("promoe") +XMMSHandler::XMMSHandler () : QObject (), XMMSSocket () { connect (std::getenv ( "XMMS_PATH" )); } @@ -37,17 +38,8 @@ XMMSHandler::XMMSHandler () : QObject (), m_client ("promoe") bool XMMSHandler::connect (const char *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; + if (!XMMSSocket::connect (path)) return false; - } - m_client.setMainloop (new XmmsQT4 (m_client.getConnection ())); using Xmms::bind; m_client.playlist.list (bind (&XMMSHandler::playlist_list, this)); @@ -345,6 +337,3 @@ void XMMSHandler::prev () m_client.playback.tickle (&log); } -XMMSHandler::~XMMSHandler () -{ -} diff --git a/XMMSHandler.h b/XMMSHandler.h index 08cad06..b33052e 100644 --- a/XMMSHandler.h +++ b/XMMSHandler.h @@ -4,16 +4,16 @@ #include #include "XmmsQT4.h" +#include "XMMSSocket.h" #include #include #include -class XMMSHandler : public QObject { +class XMMSHandler : public QObject, XMMSSocket { Q_OBJECT public: static XMMSHandler &getInstance (); - ~XMMSHandler (); bool connect (const char *path); @@ -76,11 +76,10 @@ class XMMSHandler : public QObject { void getVolume (uint); private: - Xmms::Client m_client; - QTimer m_playtime_timer; XMMSHandler (); + ~XMMSHandler () {}; void DictToQHash (const std::string &key, const Xmms::Dict::Variant &value, QHash &hash); diff --git a/XMMSSocket.cpp b/XMMSSocket.cpp new file mode 100644 index 0000000..fcb3e90 --- /dev/null +++ b/XMMSSocket.cpp @@ -0,0 +1,29 @@ +#include + +#include +#include "XMMSSocket.h" + +XMMSSocket::XMMSSocket (const char *name) : + m_client (name) +{ +} + +bool +XMMSSocket::connect (const char *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; + } + + m_client.setMainloop (new XmmsQT4 (m_client.getConnection ())); + + return true; +} + diff --git a/XMMSSocket.h b/XMMSSocket.h new file mode 100644 index 0000000..05a3327 --- /dev/null +++ b/XMMSSocket.h @@ -0,0 +1,20 @@ +#ifndef __XMMSSOCKET_H__ +#define __XMMSSOCKET_H__ + +#include + +#include "XmmsQT4.h" + +#include +#include + +class XMMSSocket +{ + public: + XMMSSocket (const char *name = "promoe"); + ~XMMSSocket () { qDebug("destroy"); }; + bool connect (const char *path); + Xmms::Client m_client; +}; + +#endif diff --git a/promoe.pro b/promoe.pro index 93bc7db..629eba7 100644 --- a/promoe.pro +++ b/promoe.pro @@ -10,6 +10,7 @@ SOURCES += XmmsQT4.cpp \ NumberDisplay.cpp \ TimeDisplay.cpp \ XMMSHandler.cpp \ + XMMSSocket.cpp \ SmallNumberDisplay.cpp \ StereoMono.cpp \ Slider.cpp \ @@ -25,7 +26,10 @@ SOURCES += XmmsQT4.cpp \ VolumeSlider.cpp \ ClutterBar.cpp \ Equalizer.cpp \ - FileDialog.cpp + FileDialog.cpp \ + MedialibView.cpp \ + MedialibWindow.cpp \ + MedialibTreeModel.cpp HEADERS += XmmsQT4.h \ @@ -40,6 +44,7 @@ HEADERS += XmmsQT4.h \ NumberDisplay.h \ TimeDisplay.h \ XMMSHandler.h \ + XMMSSocket.h \ SmallNumberDisplay.h \ StereoMono.h \ Slider.h \ @@ -55,7 +60,10 @@ HEADERS += XmmsQT4.h \ VolumeSlider.h \ ClutterBar.h \ Equalizer.h \ - FileDialog.h + FileDialog.h \ + MedialibView.h \ + MedialibWindow.h \ + MedialibTreeModel.h